Skip to content

[DebugInfo] Fix duplicate DIFile when main file is preprocessed #75022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 12, 2023
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
10 changes: 6 additions & 4 deletions clang/lib/CodeGen/CGDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,14 +554,16 @@ void CGDebugInfo::CreateCompileUnit() {
// 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
// debug info. The module name comes from the name specified in the first
// linemarker if the input is a preprocessed source.
// linemarker if the input is a preprocessed source. In this case we don't
// know the content to compute a checksum.
if (MainFile->getName() == MainFileName &&
FrontendOptions::getInputKindForExtension(
MainFile->getName().rsplit('.').second)
.isPreprocessed())
.isPreprocessed()) {
MainFileName = CGM.getModule().getName().str();

CSKind = computeChecksum(SM.getMainFileID(), Checksum);
} else {
CSKind = computeChecksum(SM.getMainFileID(), Checksum);
}
}

llvm::dwarf::SourceLanguage LangTag;
Expand Down
4 changes: 4 additions & 0 deletions clang/test/CodeGen/debug-info-preprocessed-file.i
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
# 1 "<built-in>" 2
# 1 "preprocessed-input.c" 2

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