Skip to content

Commit 316f47c

Browse files
committed
Respond to review comments.
Signed-off-by: Zahira Ammarguellat <zahira.ammarguellat@intel.com>
1 parent cfc331d commit 316f47c

File tree

4 files changed

+32
-31
lines changed

4 files changed

+32
-31
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,19 @@ Optional<StringRef> CGDebugInfo::getSource(const SourceManager &SM,
375375
return Source;
376376
}
377377

378+
// Compute valid FID for FileName.
379+
FileID ComputeValidFileID(SourceManager &SM, StringRef FileName) {
380+
FileID MainFileID = SM.getMainFileID();
381+
// Find the filename FileName and load it.
382+
llvm::Expected<FileEntryRef> ExpectedFileRef =
383+
SM.getFileManager().getFileRef(FileName);
384+
if (ExpectedFileRef) {
385+
MainFileID = SM.getOrCreateFileID(ExpectedFileRef.get(),
386+
SrcMgr::CharacteristicKind::C_User);
387+
}
388+
return MainFileID;
389+
}
390+
378391
llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
379392
SourceManager &SM = CGM.getContext().getSourceManager();
380393
StringRef FileName;
@@ -399,18 +412,6 @@ llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
399412

400413
// Cache the results.
401414
auto It = DIFileCache.find(FileName.data());
402-
if (SM.getFileEntryForID(SM.getMainFileID()) &&
403-
CGM.getCodeGenOpts().SYCLUseMainFileName && FID.isInvalid() &&
404-
llvm::sys::path::is_absolute(FileName)) {
405-
FileID MainFileID = SM.getMainFileID();
406-
auto ExpectedFileRef = SM.getFileManager().getFileRef(FileName);
407-
if (ExpectedFileRef) {
408-
MainFileID = SM.getOrCreateFileID(ExpectedFileRef.get(),
409-
SrcMgr::CharacteristicKind::C_User);
410-
FID = MainFileID;
411-
}
412-
}
413-
414415
if (It != DIFileCache.end()) {
415416
// Verify that the information still exists.
416417
if (llvm::Metadata *V = It->second)
@@ -420,15 +421,11 @@ llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
420421
SmallString<32> Checksum;
421422

422423
if (SM.getFileEntryForID(SM.getMainFileID()) &&
423-
CGM.getCodeGenOpts().SYCLUseMainFileName && FID.isInvalid()) {
424-
FileID MainFileID = SM.getMainFileID();
425-
auto ExpectedFileRef = SM.getFileManager().getFileRef(FileName);
426-
if (ExpectedFileRef) {
427-
MainFileID = SM.getOrCreateFileID(ExpectedFileRef.get(),
428-
SrcMgr::CharacteristicKind::C_User);
429-
FID = MainFileID;
430-
}
431-
}
424+
CGM.getCodeGenOpts().SYCLUseMainFileName && FID.isInvalid())
425+
// When an integration footer is involved, the main file is a temporary
426+
// file generated by the compiler. FileName is pointing to original user
427+
// source file. We use it here to properly calculate its checksum.
428+
FID = ComputeValidFileID(SM, FileName);
432429

433430
Optional<llvm::DIFile::ChecksumKind> CSKind = computeChecksum(FID, Checksum);
434431
Optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo;
@@ -560,14 +557,12 @@ void CGDebugInfo::CreateCompileUnit() {
560557
MainFileName =
561558
std::string(llvm::sys::path::remove_leading_dotslash(MainFileDirSS));
562559
} else if (CGM.getCodeGenOpts().SYCLUseMainFileName) {
563-
// When integration footer is involved, main file is a temporary file
564-
// generated by the compiler, but -main-file-name is expected to contain
565-
// an absolute path to the original user-provided source file. We use it
566-
// here to properly calculate its checksum.
567-
auto ExpectedFileRef = SM.getFileManager().getFileRef(FullMainFileName);
568-
if (ExpectedFileRef)
569-
MainFileID = SM.getOrCreateFileID(ExpectedFileRef.get(),
570-
SrcMgr::CharacteristicKind::C_User);
560+
// When an integration footer is involved, the main file is a temporary
561+
// file generated by the compiler. FullMainFileName is pointing to
562+
// original user source file. We use it here to properly calculate its
563+
// checksum.
564+
MainFileID = ComputeValidFileID(SM, FullMainFileName);
565+
// Make sure the filename points to the original user source filename.
571566
MainFileName = FullMainFileName;
572567
}
573568
// If the main file name provided is identical to the input file name, and

clang/test/CodeGenSYCL/debug-info-checksum-temp-name.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@
2626
// CHECK: ![[#FILE]] = !DIFile(filename: "{{.*}}clang{{.+}}test{{.+}}CodeGenSYCL{{.+}}Inputs{{.+}}debug-info-checksum.cpp"
2727
// CHECK-SAME: checksumkind: CSK_MD5, checksum: "f1fb5d68350b47d90a53968ac8c40529"
2828

29-
#include "Inputs/debug-info-checksum.cpp
29+
#include "Inputs/debug-info-checksum.cpp"

clang/test/CodeGenSYCL/debug-info-file-checksum.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
// This test checks that a checksum is created correctly for the compiled file,
2+
// and that the same checksum is generated for host and target compilation.
3+
// It also checks that DICompileUnit in host and target compilation is referring
4+
// to the original source file name (not the temporary file created by the
5+
// compilation process) .
6+
17
// RUN: %clang_cc1 -triple spir64-unknown-unknown -fsycl-is-device \
28
// RUN: -fsycl-int-header=%t.header.h -fsycl-int-footer=%t.footer.h \
39
// RUN: -main-file-name %S/Inputs/checksum.cpp -fsycl-use-main-file-name \

clang/test/Driver/sycl-int-footer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
// NO-FOOTER: clang{{.*}} "-include" "[[INTHEADER]]"{{.*}} "-fsycl-is-host"{{.*}} "-main-file-name" "sycl-int-footer.cpp"{{.*}} "-o"
3030

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

0 commit comments

Comments
 (0)