aganea updated this revision to Diff 196321.
aganea retitled this revision from "[clang-cl] Don't emit checksums when
compiling a preprocessed CPP" to "[DebugInfo] Don't emit checksums when
compiling a preprocessed CPP".
aganea added a comment.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Steal one bit from `PresumedLoc::Column` as suggested by @rnk.
Ping @rsmith !
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D60283/new/
https://reviews.llvm.org/D60283
Files:
include/clang/Basic/SourceLocation.h
lib/Basic/SourceManager.cpp
lib/CodeGen/CGDebugInfo.cpp
test/CodeGen/Inputs/debug-info-file-checksum-pre.cpp
test/CodeGen/debug-info-file-checksum.c
Index: test/CodeGen/debug-info-file-checksum.c
===================================================================
--- test/CodeGen/debug-info-file-checksum.c
+++ test/CodeGen/debug-info-file-checksum.c
@@ -4,3 +4,11 @@
// Check that "checksum" is created correctly for the compiled file.
// CHECK: !DIFile(filename:{{.*}}, directory:{{.*}}, checksumkind: CSK_MD5, checksum: "a3b7d27af071accdeccaa933fc603608")
+
+// Ensure #line directives (in already pre-processed files) do not emit checksums
+
+// RUN: %clang -emit-llvm -S -g -gcodeview -x c %S/Inputs/debug-info-file-checksum-pre.cpp -o - | FileCheck %s --check-prefix NOCHECKSUM
+
+// NOCHECKSUM-LABEL: !DIFile(filename: "{{.*}}code-coverage-filter1.h", directory: "{{[^"]*}}")
+// NOCHECKSUM-LABEL: !DIFile(filename: "{{.*}}code-coverage-filter2.h", directory: "{{[^"]*}}")
+// NOCHECKSUM-LABEL: !DIFile(filename: "{{.*}}debug-info-file-checksum.c", directory: "{{[^"]*}}")
Index: test/CodeGen/Inputs/debug-info-file-checksum-pre.cpp
===================================================================
--- test/CodeGen/Inputs/debug-info-file-checksum-pre.cpp
+++ test/CodeGen/Inputs/debug-info-file-checksum-pre.cpp
@@ -0,0 +1,10 @@
+#line 1 "F:\\svn\\clang\\test\\CodeGen\\Inputs\\debug-info-file-checksum.c"
+#line 1 "f:\\svn\\clang\\test\\codegen\\inputs\\code-coverage-filter1.h"
+void test1() {}
+#line 2 "F:\\svn\\clang\\test\\CodeGen\\Inputs\\debug-info-file-checksum.c"
+#line 1 "f:\\svn\\clang\\test\\codegen\\inputs\\code-coverage-filter2.h"
+void test2() {}
+#line 3 "F:\\svn\\clang\\test\\CodeGen\\Inputs\\debug-info-file-checksum.c"
+int foo(int x) {
+ return x+1;
+}
Index: lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -422,11 +422,18 @@
}
SmallString<32> Checksum;
- Optional<llvm::DIFile::ChecksumKind> CSKind =
- computeChecksum(SM.getFileID(Loc), Checksum);
Optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo;
- if (CSKind)
- CSInfo.emplace(*CSKind, Checksum);
+
+ // Don't compute checksums if the location is affected by a #line directive.
+ // We would otherwise end up with the same checksum for all the files referred
+ // by #line. Instead the checksum remains empty, leaving to the debugger to
+ // open the file without checksum validation.
+ if (!PLoc.isAffectedByLineDirective()) {
+ Optional<llvm::DIFile::ChecksumKind> CSKind =
+ computeChecksum(SM.getFileID(Loc), Checksum);
+ if (CSKind)
+ CSInfo.emplace(*CSKind, Checksum);
+ }
return createFile(FileName, CSInfo, getSource(SM, SM.getFileID(Loc)));
}
Index: lib/Basic/SourceManager.cpp
===================================================================
--- lib/Basic/SourceManager.cpp
+++ lib/Basic/SourceManager.cpp
@@ -1444,6 +1444,7 @@
return PresumedLoc();
SourceLocation IncludeLoc = FI.getIncludeLoc();
+ bool LineDirective = false;
// If we have #line directives in this file, update and overwrite the physical
// location info if appropriate.
@@ -1470,10 +1471,11 @@
IncludeLoc = getLocForStartOfFile(LocInfo.first);
IncludeLoc = IncludeLoc.getLocWithOffset(Entry->IncludeOffset);
}
+ LineDirective = true;
}
}
- return PresumedLoc(Filename.data(), LineNo, ColNo, IncludeLoc);
+ return PresumedLoc(Filename.data(), LineNo, ColNo, IncludeLoc, LineDirective);
}
/// Returns whether the PresumedLoc for a given SourceLocation is
Index: include/clang/Basic/SourceLocation.h
===================================================================
--- include/clang/Basic/SourceLocation.h
+++ include/clang/Basic/SourceLocation.h
@@ -282,13 +282,17 @@
/// You can get a PresumedLoc from a SourceLocation with SourceManager.
class PresumedLoc {
const char *Filename = nullptr;
- unsigned Line, Col;
+ unsigned Line;
+ unsigned Col : 31;
+ unsigned InLineDirective : 1;
SourceLocation IncludeLoc;
public:
PresumedLoc() = default;
- PresumedLoc(const char *FN, unsigned Ln, unsigned Co, SourceLocation IL)
- : Filename(FN), Line(Ln), Col(Co), IncludeLoc(IL) {}
+ PresumedLoc(const char *FN, unsigned Ln, unsigned Co, SourceLocation IL,
+ bool InLine)
+ : Filename(FN), Line(Ln), Col(Co), InLineDirective(InLine),
+ IncludeLoc(IL) {}
/// Return true if this object is invalid or uninitialized.
///
@@ -328,6 +332,12 @@
assert(isValid());
return IncludeLoc;
}
+
+ /// Tells if the current location is affected by GNU linemarker directives.
+ bool isAffectedByLineDirective() const {
+ assert(isValid());
+ return InLineDirective;
+ }
};
class FileEntry;
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits