Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions clang/include/clang/Basic/CodeGenOptions.def
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,6 @@ CODEGENOPT(SkipRaxSetup, 1, 0)
ENUM_CODEGENOPT(ZeroCallUsedRegs, llvm::ZeroCallUsedRegs::ZeroCallUsedRegsKind,
5, llvm::ZeroCallUsedRegs::ZeroCallUsedRegsKind::Skip)

/// Whether to expect -main-file-name to be an absolute path to use it for
/// checksum calculations or not.
CODEGENOPT(SYCLUseMainFileName, 1, 0)


/// Modify C++ ABI to returning `this` pointer from constructors and
/// non-deleting destructors. (No effect on Microsoft ABI.)
CODEGENOPT(CtorDtorReturnThis, 1, 0)
Expand Down
3 changes: 0 additions & 3 deletions clang/include/clang/Basic/CodeGenOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,6 @@ class CodeGenOptions : public CodeGenOptionsBase {
/// file, for example with -save-temps.
std::string MainFileName;

/// The user provided name for the "main file", with its full path.
std::string FullMainFileName;

/// The name for the split debug info file used for the DW_AT_[GNU_]dwo_name
/// attribute in the skeleton CU.
std::string SplitDwarfFile;
Expand Down
8 changes: 0 additions & 8 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -8141,10 +8141,6 @@ def main_file_name : Separate<["-"], "main-file-name">,
HelpText<"Main file name to use for debug info and source if missing">,
Visibility<[CC1Option, CC1AsOption]>,
MarshallingInfoString<CodeGenOpts<"MainFileName">>;
def full_main_file_name : Separate<["-"], "full-main-file-name">,
HelpText<"File name with full path to use for debug info during host and device compile">,
Visibility<[CC1Option, CC1AsOption]>,
MarshallingInfoString<CodeGenOpts<"FullMainFileName">>;
def split_dwarf_output : Separate<["-"], "split-dwarf-output">,
HelpText<"File name to use for split dwarf debug info output">,
Visibility<[CC1Option, CC1AsOption]>,
Expand Down Expand Up @@ -8525,10 +8521,6 @@ def fenable_sycl_dae : Flag<["-"], "fenable-sycl-dae">,
def fsycl_enable_int_header_diags: Flag<["-"], "fsycl-enable-int-header-diags">,
HelpText<"Enable diagnostics that require the SYCL integration header.">,
MarshallingInfoFlag<LangOpts<"SYCLEnableIntHeaderDiags">>;
def fsycl_use_main_file_name : Flag<["-"], "fsycl-use-main-file-name">,
HelpText<"Tells compiler that -main-file-name contains an absolute path and "
"file specified there should be used for checksum calculation.">,
MarshallingInfoFlag<CodeGenOpts<"SYCLUseMainFileName">>;
def fsycl_is_native_cpu : Flag<["-"], "fsycl-is-native-cpu">,
HelpText<"Perform device compilation for Native CPU.">,
Visibility<[CC1Option]>,
Expand Down
58 changes: 7 additions & 51 deletions clang/lib/CodeGen/CGDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,40 +397,18 @@ std::optional<StringRef> CGDebugInfo::getSource(const SourceManager &SM,
return Source;
}

// Compute valid FID for FileName.
FileID ComputeValidFileID(SourceManager &SM, StringRef FileName) {
FileID MainFileID = SM.getMainFileID();
// Find the filename FileName and load it.
llvm::Expected<FileEntryRef> ExpectedFileRef =
SM.getFileManager().getFileRef(FileName);
if (ExpectedFileRef) {
MainFileID = SM.getOrCreateFileID(ExpectedFileRef.get(),
SrcMgr::CharacteristicKind::C_User);
}
return MainFileID;
}

llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
SourceManager &SM = CGM.getContext().getSourceManager();
StringRef FileName;
FileID FID;
std::optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo;

if (Loc.isInvalid()) {
if (CGM.getCodeGenOpts().SYCLUseMainFileName &&
CGM.getLangOpts().MacroPrefixMap.size() > 0) {
// When fmacro-prefix-map is used, the original source file
// file name is indicated by FullMainFileName instead of the CU.
auto &CGO = CGM.getCodeGenOpts();
FileName = CGO.FullMainFileName;
FID = ComputeValidFileID(SM, CGO.FullMainFileName);
} else {
// The DIFile used by the CU is distinct from the main source file. Call
// createFile() below for canonicalization if the source file was specified
// with an absolute path.
FileName = TheCU->getFile()->getFilename();
CSInfo = TheCU->getFile()->getChecksum();
}
// The DIFile used by the CU is distinct from the main source file. Call
// createFile() below for canonicalization if the source file was specified
// with an absolute path.
FileName = TheCU->getFile()->getFilename();
CSInfo = TheCU->getFile()->getChecksum();
} else {
PresumedLoc PLoc = SM.getPresumedLoc(Loc);
FileName = PLoc.getFilename();
Expand All @@ -449,13 +427,6 @@ llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
return cast<llvm::DIFile>(V);
}

if (SM.getFileEntryForID(SM.getMainFileID()) &&
CGM.getCodeGenOpts().SYCLUseMainFileName && FID.isInvalid())
// When an integration footer is involved, the main file is a temporary
// file generated by the compiler. FileName is pointing to original user
// source file. We use it here to properly calculate its checksum.
FID = ComputeValidFileID(SM, FileName);

// Put Checksum at a scope where it will persist past the createFile call.
SmallString<64> Checksum;
if (!CSInfo) {
Expand Down Expand Up @@ -565,25 +536,18 @@ void CGDebugInfo::CreateCompileUnit() {
auto &CGO = CGM.getCodeGenOpts();
const LangOptions &LO = CGM.getLangOpts();
std::string MainFileName = CGO.MainFileName;
std::string FullMainFileName = CGO.FullMainFileName;
if (MainFileName.empty())
MainFileName = "<stdin>";

// The main file name provided via the "-main-file-name" option contains just
// the file name itself with no path information. This file name may have had
// a relative path, so we look into the actual file entry for the main
// file to determine the real absolute path for the file.
// An exception here is workflow when integration footer is involved: in that
// case driver passes an absolute path to the original user-provided source
// file, whilst main file corresponds to a temporary file generated by the
// compiler.
std::string MainFileDir;
if (OptionalFileEntryRef MainFile =
SM.getFileEntryRefForID(SM.getMainFileID())) {
MainFileDir = std::string(MainFile->getDir().getName());
FileID MainFileID = SM.getMainFileID();
if (!llvm::sys::path::is_absolute(MainFileName) &&
!CGM.getCodeGenOpts().SYCLUseMainFileName) {
if (!llvm::sys::path::is_absolute(MainFileName)) {
llvm::SmallString<1024> MainFileDirSS(MainFileDir);
llvm::sys::path::Style Style =
LO.UseTargetPathSeparator
Expand All @@ -594,14 +558,6 @@ void CGDebugInfo::CreateCompileUnit() {
llvm::sys::path::append(MainFileDirSS, Style, MainFileName);
MainFileName = std::string(
llvm::sys::path::remove_leading_dotslash(MainFileDirSS, Style));
} else if (CGM.getCodeGenOpts().SYCLUseMainFileName) {
// When an integration footer is involved, the main file is a temporary
// file generated by the compiler. FullMainFileName is pointing to
// original user source file. We use it here to properly calculate its
// checksum.
MainFileID = ComputeValidFileID(SM, FullMainFileName);
// Make sure the filename points to the original user source filename.
MainFileName = FullMainFileName;
}
// If the main file name provided is identical to the input file name, and
// if the input file is a preprocessed source, use the module name for
Expand All @@ -614,7 +570,7 @@ void CGDebugInfo::CreateCompileUnit() {
.isPreprocessed()) {
MainFileName = CGM.getModule().getName().str();
} else {
CSKind = computeChecksum(MainFileID, Checksum);
CSKind = computeChecksum(SM.getMainFileID(), Checksum);
}
}

Expand Down
14 changes: 1 addition & 13 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6109,20 +6109,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
// Set the main file name, so that debug info works even with
// -save-temps.
CmdArgs.push_back("-main-file-name");
if (!IsSYCL || Args.hasArg(options::OPT_fno_sycl_use_footer)) {
CmdArgs.push_back(getBaseInputName(Args, Input));
} else {
SmallString<256> AbsPath = llvm::StringRef(Input.getBaseInput());
D.getVFS().makeAbsolute(AbsPath);
CmdArgs.push_back(
Args.MakeArgString(llvm::sys::path::filename(Input.getBaseInput())));
CmdArgs.push_back("-fsycl-use-main-file-name");
}
CmdArgs.push_back(getBaseInputName(Args, Input));

if (IsSYCL || Args.hasArg(options::OPT_fsycl_footer_path_EQ)) {
CmdArgs.push_back("-full-main-file-name");
CmdArgs.push_back(Input.getBaseInput());
}
// Some flags which affect the language (via preprocessor
// defines).
if (Args.hasArg(options::OPT_static))
Expand Down
9 changes: 0 additions & 9 deletions clang/test/CodeGenSYCL/Inputs/debug-info-checksum.cpp

This file was deleted.

29 changes: 0 additions & 29 deletions clang/test/CodeGenSYCL/debug-info-checksum-temp-name.cpp

This file was deleted.

33 changes: 12 additions & 21 deletions clang/test/CodeGenSYCL/debug-info-file-checksum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,28 @@
// and that the same checksum is generated for host and target compilation.
// It also checks that DICompileUnit in host and target compilation is referring
// to the original source file name (not the temporary file created by the
// compilation process) .
// compilation process) .

// RUN: %clang_cc1 -triple spir64-unknown-unknown -fsycl-is-device \
// RUN: -fsycl-int-header=%t.header.h -fsycl-int-footer=%t.footer.h \
// RUN: -main-file-name %S/Inputs/checksum.cpp -fsycl-use-main-file-name \
// RUN: -full-main-file-name "%S/Inputs/checksum.cpp" \
// RUN: -gcodeview -debug-info-kind=limited -emit-llvm -O0 -o - "%S/Inputs/checksum.cpp" \
// RUN: -main-file-name %S/Inputs/checksum.cpp \
// RUN: -gcodeview -debug-info-kind=limited -emit-llvm -O0 -o - \
// RUN: "%S/Inputs/checksum.cpp" \
// RUN: | FileCheck %s -check-prefix=COMP1

// RUN: append-file "%S/Inputs/checksum.cpp" \
// RUN: --append=%t.footer.h \
// RUN: --orig-filename="%S/Inputs/checksum.cpp" \
// RUN: --output=%t.checksum.cpp --use-include
// COMP1: !DICompileUnit({{.*}} file: ![[#FILE1:]]
// COMP1: ![[#FILE1]] = !DIFile(filename: "{{.*}}clang{{.+}}test{{.+}}CodeGenSYCL{{.+}}Inputs{{.+}}checksum.cpp"
// COMP1-SAME: checksumkind: CSK_MD5, checksum: "259269f735d83ec32c46a11352458493")

// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsycl-is-host \
// RUN: -include %t.header.h -dependency-filter %t.header.h \
// RUN: -main-file-name %S/Inputs/checksum.cpp -fsycl-use-main-file-name \
// RUN: -full-main-file-name %S/Inputs/checksum.cpp \
// RUN: -include-footer %t.footer.h -dependency-filter %t.footer.h \
// RUN: -main-file-name %S/Inputs/checksum.cpp \
// RUN: -gcodeview -debug-info-kind=limited -emit-llvm -O0 -o - \
// RUN: %t.checksum.cpp \
// RUN: | FileCheck %s -check-prefix=COMP2

// COMP1: !DICompileUnit({{.*}} file: ![[#FILE1:]]
// COMP1: ![[#FILE1]] = !DIFile(filename: "{{.*}}clang{{.+}}test{{.+}}CodeGenSYCL{{.+}}Inputs{{.+}}checksum.cpp"
// COMP1-SAME: checksumkind: CSK_MD5, checksum: "259269f735d83ec32c46a11352458493")
// RUN: "%S/Inputs/checksum.cpp" \
// RUN: | FileCheck %s -check-prefix=COMP2

// COMP2: !DICompileUnit({{.*}} file: ![[#FILE2:]]
// COMP2: ![[#FILE2]] = !DIFile(filename: "{{.*}}clang{{.+}}test{{.+}}CodeGenSYCL{{.+}}Inputs{{.+}}checksum.cpp"
// COMP2-SAME: checksumkind: CSK_MD5, checksum: "259269f735d83ec32c46a11352458493")
// COMP2-SAME: checksumkind: CSK_MD5, checksum: "259269f735d83ec32c46a11352458493"

// TODO: Fails on windows because of the use of append-file command that returns
// path with "\\" on windows. getPresumedLoc is failing with Literal String
// parser returning erroneous filename.
// XFAIL: target=x86_64-pc-windows-msvc
5 changes: 2 additions & 3 deletions clang/test/CodeGenSYCL/debug-info-file-prefix-map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

// RUN: %clang_cc1 -triple spir64-unknown-unknown -fsycl-is-device \
// RUN: -fsycl-int-header=%t.header.h -fsycl-int-footer=%t.footer.h \
// RUN: -main-file-name %s -fsycl-use-main-file-name \
// RUN: -full-main-file-name %s \
// RUN: -main-file-name %s \
// RUN: -fmacro-prefix-map=%S/= -fcoverage-prefix-map=%S/= \
// RUN: -fdebug-prefix-map=%S/= \
// RUN: -debug-info-kind=constructor -emit-llvm -O0 -o - %s \
Expand All @@ -15,7 +14,7 @@
// CHECK: distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: ![[#FILE1:]]
// CHECK-NEXT: ![[#FILE1]] = !DIFile(filename: "debug-info-file-prefix-map.cpp"
// CHECK: ![[#FILE2:]] = !DIFile(filename: "debug-info-file-prefix-map.cpp"
// CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "__builtin_va_list", file: ![[#FILE2]]
// CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "__builtin_va_list", file: ![[#FILE1]]

void a(__builtin_va_list);
using ::a;
15 changes: 6 additions & 9 deletions clang/test/Driver/sycl-int-footer-old-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
// RUN: | FileCheck -check-prefix FOOTER %s -DSRCDIR=%/S -DCMDDIR=cmdline/dir
// FOOTER: clang{{.*}} "-fsycl-is-device"{{.*}} "-fsycl-int-header=[[INTHEADER:.+\.h]]" "-fsycl-int-footer=[[INTFOOTER:.+\h]]" "-sycl-std={{.*}}"{{.*}} "-include" "dummy.h"
// FOOTER: clang{{.*}} "-include" "[[INTHEADER]]"
// FOOTER-SAME: "-dependency-filter" "[[INTHEADER]]"
// FOOTER-SAME: "-include-footer" "[[INTFOOTER]]"
// FOOTER-SAME: "-fsycl-is-host"{{.*}} "-main-file-name" "[[SRCFILE:.+\cpp]]" "-fsycl-use-main-file-name"{{.*}} "-include" "dummy.h"{{.*}} "-I" "cmdline/dir"
// FOOTER-SAME: "-dependency-filter" "[[INTFOOTER]]"
// FOOTER-SAME: "-fsycl-is-host"{{.*}} "-main-file-name" "[[SRCFILE:.+\cpp]]" {{.*}} "-include" "dummy.h"{{.*}} "-I" "cmdline/dir"

/// Preprocessed file creation with integration footer
// RUN: %clangxx -fsycl --no-offload-new-driver -E %/s -### 2>&1 \
// RUN: | FileCheck -check-prefix FOOTER_PREPROC_GEN %s
// FOOTER_PREPROC_GEN: clang{{.*}} "-fsycl-is-device"{{.*}} "-fsycl-int-header=[[INTHEADER:.+\.h]]" "-fsycl-int-footer=[[INTFOOTER:.+\h]]" "-sycl-std={{.*}}" "-o" "[[PREPROC_DEVICE:.+\.ii]]"
// FOOTER_PREPROC_GEN: clang{{.*}} "-include" "[[INTHEADER]]"
// FOOTER_PREPROC_GEN: "-dependency-filter" "[[INTHEADER]]"
// FOOTER_PREPROC_GEN-SAME: "-include-footer" "[[INTFOOTER]]"
// FOOTER_PREPROC_GEN-SAME: "-dependency-filter" "[[INTFOOTER]]"
// FOOTER_PREPROC_GEN-SAME: "-fsycl-is-host"{{.*}} "-E"{{.*}} "-o" "[[PREPROC_HOST:.+\.ii]]"


/// Preprocessed file use with integration footer
// RUN: touch %t.ii
// RUN: %clangxx -fsycl --no-offload-new-driver %t.ii -### 2>&1 \
Expand All @@ -25,17 +28,11 @@

/// Check that integration footer can be disabled
// RUN: %clangxx -fsycl --no-offload-new-driver -fno-sycl-use-footer %s -### 2>&1 \
// RUN: | FileCheck -check-prefix NO-FOOTER --implicit-check-not "-fsycl-int-footer" --implicit-check-not "-fsycl-use-main-file-name" %s
// RUN: | FileCheck -check-prefix NO-FOOTER --implicit-check-not "-fsycl-int-footer" %s
// NO-FOOTER: clang{{.*}} "-fsycl-is-device"{{.*}} "-fsycl-int-header=[[INTHEADER:.+\.h]]" "-sycl-std={{.*}}"
// NO-FOOTER-NOT: append-file
// NO-FOOTER: clang{{.*}} "-include" "[[INTHEADER]]"{{.*}} "-fsycl-is-host"

// Test that -fsycl-use-main-file-name is not passed if -fsycl --no-offload-new-driver is not passed.
// This test is located here, because -fsycl-use-main-file-name is tightly
// connected to the integration footer.
// RUN: %clangxx %s -### 2>&1 | FileCheck %s --check-prefix NO-FSYCL --implicit-check-not "-fsycl-use-main-file-name"
// NO-FSYCL: clang{{.*}} "-main-file-name" "sycl-int-footer-old-model.cpp"

/// Check phases without integration footer
// RUN: %clangxx -fsycl --no-offload-new-driver -fno-sycl-instrument-device-code -fno-sycl-device-lib=all -fno-sycl-use-footer -target x86_64-unknown-linux-gnu %s -ccc-print-phases 2>&1 \
// RUN: | FileCheck -check-prefix NO-FOOTER-PHASES -check-prefix COMMON-PHASES %s
Expand Down
13 changes: 3 additions & 10 deletions clang/test/Driver/sycl-int-footer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
// RUN: | FileCheck -check-prefix FOOTER %s -DSRCDIR=%/S -DCMDDIR=cmdline/dir
// FOOTER: clang{{.*}} "-fsycl-is-device"{{.*}} "-fsycl-int-header=[[INTHEADER:.+\.h]]" "-fsycl-int-footer=[[INTFOOTER:.+\h]]" "-sycl-std={{.*}}"{{.*}} "-include" "dummy.h"
// FOOTER: clang{{.*}} "-include" "[[INTHEADER]]"
// FOOTER-SAME: "-include-footer" "[[INTFOOTER]]"
// FOOTER-SAME: "-fsycl-is-host"{{.*}} "-main-file-name" "[[SRCFILE:.+\cpp]]" "-fsycl-use-main-file-name"{{.*}} "-include" "dummy.h"{{.*}} "-I" "cmdline/dir"
// FOOTER-SAME: "-fsycl-is-host"{{.*}} "-include" "dummy.h"{{.*}} "-I" "cmdline/dir"
// FOOTER-NOT: "-include" "[[INTHEADER]]"

/// Preprocessed file creation with integration footer
Expand All @@ -23,15 +22,9 @@

/// Check that integration footer can be disabled
// RUN: %clangxx -fsycl --offload-new-driver -fno-sycl-use-footer %s -### 2>&1 \
// RUN: | FileCheck -check-prefix NO-FOOTER --implicit-check-not "-fsycl-int-footer" --implicit-check-not "-fsycl-use-main-file-name" %s
// RUN: | FileCheck -check-prefix NO-FOOTER --implicit-check-not "-fsycl-int-footer" %s
// NO-FOOTER: clang{{.*}} "-fsycl-is-device"{{.*}} "-fsycl-int-header=[[INTHEADER:.+\.h]]" "-sycl-std={{.*}}"
// NO-FOOTER: clang{{.*}} "-include" "[[INTHEADER]]"{{.*}} "-fsycl-is-host"{{.*}} "-main-file-name" "sycl-int-footer.cpp"{{.*}} "-o"

// Test that -fsycl-use-main-file-name is not passed if -fsycl --offload-new-driver is not passed.
// This test is located here, because -fsycl-use-main-file-name is tightly
// connected to the integration footer.
// RUN: %clangxx %s -### 2>&1 | FileCheck %s --check-prefix NO-FSYCL --implicit-check-not "-fsycl-use-main-file-name"
// NO-FSYCL: clang{{.*}} "-main-file-name" "sycl-int-footer.cpp"
// NO-FOOTER: clang{{.*}} "-include" "[[INTHEADER]]"{{.*}} "-fsycl-is-host"{{.*}} "-o"

/// Check phases without integration footer
// RUN: %clangxx -fsycl --offload-new-driver -fno-sycl-instrument-device-code -fno-sycl-device-lib=all -fno-sycl-use-footer -target x86_64-unknown-linux-gnu %s -ccc-print-phases 2>&1 \
Expand Down
Loading