Skip to content

Commit 0fb5b78

Browse files
committed
Use the file name from linemarker for debug info if an input is preprocessed source.
Summary: Even in the case of the input file is a preprocessed source, clang uses the file name of the preprocesses source for debug info (DW_AT_name attribute for DW_TAG_compile_unit). However, gcc uses the file name specified in the first linemarker instead. This makes more sense because the one specified in the linemarker represents the "actual" source file name. Clang already uses the file name specified in the first linemarker for Module name (https://github.com/llvm-mirror/clang/blob/master/lib/Frontend/FrontendAction.cpp#L779) if the input is preprocessed. This patch makes clang to use the same value for debug info as well. Reviewers: compnerd, rnk, dblaikie, rsmith Reviewed By: rnk Subscribers: aprantl, cfe-commits Differential Revision: https://reviews.llvm.org/D36474 llvm-svn: 311037
1 parent ad00bd6 commit 0fb5b78

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "clang/Basic/SourceManager.h"
3030
#include "clang/Basic/Version.h"
3131
#include "clang/Frontend/CodeGenOptions.h"
32+
#include "clang/Frontend/FrontendOptions.h"
3233
#include "clang/Lex/HeaderSearchOptions.h"
3334
#include "clang/Lex/ModuleMap.h"
3435
#include "clang/Lex/PreprocessorOptions.h"
@@ -495,6 +496,16 @@ void CGDebugInfo::CreateCompileUnit() {
495496
llvm::sys::path::append(MainFileDirSS, MainFileName);
496497
MainFileName = MainFileDirSS.str();
497498
}
499+
// If the main file name provided is identical to the input file name, and
500+
// if the input file is a preprocessed source, use the module name for
501+
// debug info. The module name comes from the name specified in the first
502+
// linemarker if the input is a preprocessed source.
503+
if (MainFile->getName() == MainFileName &&
504+
FrontendOptions::getInputKindForExtension(
505+
MainFile->getName().rsplit('.').second)
506+
.isPreprocessed())
507+
MainFileName = CGM.getModule().getName().str();
508+
498509
CSKind = computeChecksum(SM.getMainFileID(), Checksum);
499510
}
500511

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# 1 "/foo/bar/preprocessed-input.c"
2+
# 1 "<built-in>" 1
3+
# 1 "<built-in>" 3
4+
# 318 "<built-in>" 3
5+
# 1 "<command line>" 1
6+
# 1 "<built-in>" 2
7+
# 1 "preprocessed-input.c" 2
8+
9+
// RUN: %clang -g -c -S -emit-llvm -o - %s | FileCheck %s
10+
// CHECK: !DICompileUnit(language: DW_LANG_C99, file: ![[FILE:[0-9]+]]
11+
// CHECK: ![[FILE]] = !DIFile(filename: "/foo/bar/preprocessed-input.c"

0 commit comments

Comments
 (0)