Skip to content

Commit 831484e

Browse files
authored
[DebugInfo] Fix duplicate DIFile when main file is preprocessed (#75022)
When the main file is preprocessed and we change `MainFileName` to the original source file name (e.g. `a.i => a.c`), the source manager does not contain `a.c`, but we incorrectly associate the DIFile(a.c) with md5(a.i). This causes CGDebugInfo::emitFunctionStart to create a duplicate DIFile and leads to a spurious "inconsistent use of MD5 checksums" warning. ``` % cat a.c void f() {} % clang -c -g a.c # no warning % clang -E a.c -o a.i && clang -g -S a.i && clang -g -c a.s a.s:9:2: warning: inconsistent use of MD5 checksums .file 1 "a.c" ^ % grep DIFile a.ll !1 = !DIFile(filename: "a.c", directory: "/tmp/c", checksumkind: CSK_MD5, checksum: "c5b2e246df7d5f53e176b097a0641c3d") !11 = !DIFile(filename: "a.c", directory: "/tmp/c") % grep 'file.*a.c' a.s .file "a.c" .file 0 "/tmp/c" "a.c" md5 0x2d14ea70fee15102033eb8d899914cce .file 1 "a.c" ``` Fix #56378 by disassociating md5(a.i) with a.c.
1 parent 0e05904 commit 831484e

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -554,14 +554,16 @@ void CGDebugInfo::CreateCompileUnit() {
554554
// If the main file name provided is identical to the input file name, and
555555
// if the input file is a preprocessed source, use the module name for
556556
// debug info. The module name comes from the name specified in the first
557-
// linemarker if the input is a preprocessed source.
557+
// linemarker if the input is a preprocessed source. In this case we don't
558+
// know the content to compute a checksum.
558559
if (MainFile->getName() == MainFileName &&
559560
FrontendOptions::getInputKindForExtension(
560561
MainFile->getName().rsplit('.').second)
561-
.isPreprocessed())
562+
.isPreprocessed()) {
562563
MainFileName = CGM.getModule().getName().str();
563-
564-
CSKind = computeChecksum(SM.getMainFileID(), Checksum);
564+
} else {
565+
CSKind = computeChecksum(SM.getMainFileID(), Checksum);
566+
}
565567
}
566568

567569
llvm::dwarf::SourceLanguage LangTag;

clang/test/CodeGen/debug-info-preprocessed-file.i

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
# 1 "<built-in>" 2
77
# 1 "preprocessed-input.c" 2
88

9+
/// The main file is preprocessed. We change it to preprocessed-input.c. Since
10+
/// the content is not available, we don't compute a checksum.
911
// RUN: %clang -g -c -S -emit-llvm -o - %s | FileCheck %s
1012
// CHECK: !DICompileUnit(language: DW_LANG_C{{.*}}, file: ![[FILE:[0-9]+]]
1113
// CHECK: ![[FILE]] = !DIFile(filename: "/foo/bar/preprocessed-input.c"
14+
// CHECK-NOT: checksumkind:
15+
// CHECK-NOT: !DIFile(

0 commit comments

Comments
 (0)