[PATCH] D36474: Use the file name from linemarker for debug info if an input is preprocessed source.
This revision was automatically updated to reflect the committed changes. Closed by commit rL311037: Use the file name from linemarker for debug info if an input is preprocessed… (authored by twoh). Repository: rL LLVM https://reviews.llvm.org/D36474 Files: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp cfe/trunk/test/CodeGen/debug-info-preprocessed-file.i Index: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp === --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp @@ -29,6 +29,7 @@ #include "clang/Basic/SourceManager.h" #include "clang/Basic/Version.h" #include "clang/Frontend/CodeGenOptions.h" +#include "clang/Frontend/FrontendOptions.h" #include "clang/Lex/HeaderSearchOptions.h" #include "clang/Lex/ModuleMap.h" #include "clang/Lex/PreprocessorOptions.h" @@ -495,6 +496,16 @@ llvm::sys::path::append(MainFileDirSS, MainFileName); MainFileName = MainFileDirSS.str(); } +// 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. +if (MainFile->getName() == MainFileName && +FrontendOptions::getInputKindForExtension( +MainFile->getName().rsplit('.').second) +.isPreprocessed()) + MainFileName = CGM.getModule().getName().str(); + CSKind = computeChecksum(SM.getMainFileID(), Checksum); } Index: cfe/trunk/test/CodeGen/debug-info-preprocessed-file.i === --- cfe/trunk/test/CodeGen/debug-info-preprocessed-file.i +++ cfe/trunk/test/CodeGen/debug-info-preprocessed-file.i @@ -0,0 +1,11 @@ +# 1 "/foo/bar/preprocessed-input.c" +# 1 "" 1 +# 1 "" 3 +# 318 "" 3 +# 1 "" 1 +# 1 "" 2 +# 1 "preprocessed-input.c" 2 + +// RUN: %clang -g -c -S -emit-llvm -o - %s | FileCheck %s +// CHECK: !DICompileUnit(language: DW_LANG_C99, file: ![[FILE:[0-9]+]] +// CHECK: ![[FILE]] = !DIFile(filename: "/foo/bar/preprocessed-input.c" Index: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp === --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp @@ -29,6 +29,7 @@ #include "clang/Basic/SourceManager.h" #include "clang/Basic/Version.h" #include "clang/Frontend/CodeGenOptions.h" +#include "clang/Frontend/FrontendOptions.h" #include "clang/Lex/HeaderSearchOptions.h" #include "clang/Lex/ModuleMap.h" #include "clang/Lex/PreprocessorOptions.h" @@ -495,6 +496,16 @@ llvm::sys::path::append(MainFileDirSS, MainFileName); MainFileName = MainFileDirSS.str(); } +// 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. +if (MainFile->getName() == MainFileName && +FrontendOptions::getInputKindForExtension( +MainFile->getName().rsplit('.').second) +.isPreprocessed()) + MainFileName = CGM.getModule().getName().str(); + CSKind = computeChecksum(SM.getMainFileID(), Checksum); } Index: cfe/trunk/test/CodeGen/debug-info-preprocessed-file.i === --- cfe/trunk/test/CodeGen/debug-info-preprocessed-file.i +++ cfe/trunk/test/CodeGen/debug-info-preprocessed-file.i @@ -0,0 +1,11 @@ +# 1 "/foo/bar/preprocessed-input.c" +# 1 "" 1 +# 1 "" 3 +# 318 "" 3 +# 1 "" 1 +# 1 "" 2 +# 1 "preprocessed-input.c" 2 + +// RUN: %clang -g -c -S -emit-llvm -o - %s | FileCheck %s +// CHECK: !DICompileUnit(language: DW_LANG_C99, file: ![[FILE:[0-9]+]] +// CHECK: ![[FILE]] = !DIFile(filename: "/foo/bar/preprocessed-input.c" ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D36474: Use the file name from linemarker for debug info if an input is preprocessed source.
rnk accepted this revision. rnk added a comment. This revision is now accepted and ready to land. lgtm https://reviews.llvm.org/D36474 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D36474: Use the file name from linemarker for debug info if an input is preprocessed source.
twoh added a comment. Ping. Thanks! https://reviews.llvm.org/D36474 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D36474: Use the file name from linemarker for debug info if an input is preprocessed source.
twoh updated this revision to Diff 110237. twoh added a comment. Addressing dblaikie's comments. Thanks! https://reviews.llvm.org/D36474 Files: lib/CodeGen/CGDebugInfo.cpp test/CodeGen/debug-info-preprocessed-file.i Index: test/CodeGen/debug-info-preprocessed-file.i === --- /dev/null +++ test/CodeGen/debug-info-preprocessed-file.i @@ -0,0 +1,11 @@ +# 1 "/foo/bar/preprocessed-input.c" +# 1 "" 1 +# 1 "" 3 +# 318 "" 3 +# 1 "" 1 +# 1 "" 2 +# 1 "preprocessed-input.c" 2 + +// RUN: %clang -g -c -S -emit-llvm -o - %s | FileCheck %s +// CHECK: !DICompileUnit(language: DW_LANG_C99, file: ![[FILE:[0-9]+]] +// CHECK: ![[FILE]] = !DIFile(filename: "/foo/bar/preprocessed-input.c" Index: lib/CodeGen/CGDebugInfo.cpp === --- lib/CodeGen/CGDebugInfo.cpp +++ lib/CodeGen/CGDebugInfo.cpp @@ -28,6 +28,7 @@ #include "clang/Basic/SourceManager.h" #include "clang/Basic/Version.h" #include "clang/Frontend/CodeGenOptions.h" +#include "clang/Frontend/FrontendOptions.h" #include "clang/Lex/HeaderSearchOptions.h" #include "clang/Lex/ModuleMap.h" #include "clang/Lex/PreprocessorOptions.h" @@ -483,6 +484,16 @@ llvm::sys::path::append(MainFileDirSS, MainFileName); MainFileName = MainFileDirSS.str(); } +// 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. +if (MainFile->getName() == MainFileName && +FrontendOptions::getInputKindForExtension( +MainFile->getName().rsplit('.').second) +.isPreprocessed()) + MainFileName = CGM.getModule().getName().str(); + CSKind = computeChecksum(SM.getMainFileID(), Checksum); } Index: test/CodeGen/debug-info-preprocessed-file.i === --- /dev/null +++ test/CodeGen/debug-info-preprocessed-file.i @@ -0,0 +1,11 @@ +# 1 "/foo/bar/preprocessed-input.c" +# 1 "" 1 +# 1 "" 3 +# 318 "" 3 +# 1 "" 1 +# 1 "" 2 +# 1 "preprocessed-input.c" 2 + +// RUN: %clang -g -c -S -emit-llvm -o - %s | FileCheck %s +// CHECK: !DICompileUnit(language: DW_LANG_C99, file: ![[FILE:[0-9]+]] +// CHECK: ![[FILE]] = !DIFile(filename: "/foo/bar/preprocessed-input.c" Index: lib/CodeGen/CGDebugInfo.cpp === --- lib/CodeGen/CGDebugInfo.cpp +++ lib/CodeGen/CGDebugInfo.cpp @@ -28,6 +28,7 @@ #include "clang/Basic/SourceManager.h" #include "clang/Basic/Version.h" #include "clang/Frontend/CodeGenOptions.h" +#include "clang/Frontend/FrontendOptions.h" #include "clang/Lex/HeaderSearchOptions.h" #include "clang/Lex/ModuleMap.h" #include "clang/Lex/PreprocessorOptions.h" @@ -483,6 +484,16 @@ llvm::sys::path::append(MainFileDirSS, MainFileName); MainFileName = MainFileDirSS.str(); } +// 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. +if (MainFile->getName() == MainFileName && +FrontendOptions::getInputKindForExtension( +MainFile->getName().rsplit('.').second) +.isPreprocessed()) + MainFileName = CGM.getModule().getName().str(); + CSKind = computeChecksum(SM.getMainFileID(), Checksum); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D36474: Use the file name from linemarker for debug info if an input is preprocessed source.
dblaikie added a comment. Looks plausible (not sure how nice it is to use the llvm::Module itself to communicate the file name to this bit of logic - I'll leave that to Richard Smith to judge, I think) Comment at: test/CodeGen/debug-info-preprocessed-file.i:10 +// RUN: %clang -g -c -S -emit-llvm -o - %s | FileCheck %s +// CHECK: !DIFile(filename: "/foo/bar/preprocessed-input.c" Should probably be a bit more specific in the check - verifying that the DICompileUnit's DIFile is the one you're checking here. (not that there's any other DI* that would have a DIFile here, but still) https://reviews.llvm.org/D36474 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D36474: Use the file name from linemarker for debug info if an input is preprocessed source.
twoh updated this revision to Diff 110230. twoh added a comment. Relocate. https://reviews.llvm.org/D36474 Files: lib/CodeGen/CGDebugInfo.cpp test/CodeGen/debug-info-preprocessed-file.i Index: test/CodeGen/debug-info-preprocessed-file.i === --- /dev/null +++ test/CodeGen/debug-info-preprocessed-file.i @@ -0,0 +1,10 @@ +# 1 "/foo/bar/preprocessed-input.c" +# 1 "" 1 +# 1 "" 3 +# 318 "" 3 +# 1 "" 1 +# 1 "" 2 +# 1 "preprocessed-input.c" 2 + +// RUN: %clang -g -c -S -emit-llvm -o - %s | FileCheck %s +// CHECK: !DIFile(filename: "/foo/bar/preprocessed-input.c" Index: lib/CodeGen/CGDebugInfo.cpp === --- lib/CodeGen/CGDebugInfo.cpp +++ lib/CodeGen/CGDebugInfo.cpp @@ -28,6 +28,7 @@ #include "clang/Basic/SourceManager.h" #include "clang/Basic/Version.h" #include "clang/Frontend/CodeGenOptions.h" +#include "clang/Frontend/FrontendOptions.h" #include "clang/Lex/HeaderSearchOptions.h" #include "clang/Lex/ModuleMap.h" #include "clang/Lex/PreprocessorOptions.h" @@ -483,6 +484,16 @@ llvm::sys::path::append(MainFileDirSS, MainFileName); MainFileName = MainFileDirSS.str(); } +// 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. +if (MainFile->getName() == MainFileName && +FrontendOptions::getInputKindForExtension( +MainFile->getName().rsplit('.').second) +.isPreprocessed()) + MainFileName = CGM.getModule().getName().str(); + CSKind = computeChecksum(SM.getMainFileID(), Checksum); } Index: test/CodeGen/debug-info-preprocessed-file.i === --- /dev/null +++ test/CodeGen/debug-info-preprocessed-file.i @@ -0,0 +1,10 @@ +# 1 "/foo/bar/preprocessed-input.c" +# 1 "" 1 +# 1 "" 3 +# 318 "" 3 +# 1 "" 1 +# 1 "" 2 +# 1 "preprocessed-input.c" 2 + +// RUN: %clang -g -c -S -emit-llvm -o - %s | FileCheck %s +// CHECK: !DIFile(filename: "/foo/bar/preprocessed-input.c" Index: lib/CodeGen/CGDebugInfo.cpp === --- lib/CodeGen/CGDebugInfo.cpp +++ lib/CodeGen/CGDebugInfo.cpp @@ -28,6 +28,7 @@ #include "clang/Basic/SourceManager.h" #include "clang/Basic/Version.h" #include "clang/Frontend/CodeGenOptions.h" +#include "clang/Frontend/FrontendOptions.h" #include "clang/Lex/HeaderSearchOptions.h" #include "clang/Lex/ModuleMap.h" #include "clang/Lex/PreprocessorOptions.h" @@ -483,6 +484,16 @@ llvm::sys::path::append(MainFileDirSS, MainFileName); MainFileName = MainFileDirSS.str(); } +// 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. +if (MainFile->getName() == MainFileName && +FrontendOptions::getInputKindForExtension( +MainFile->getName().rsplit('.').second) +.isPreprocessed()) + MainFileName = CGM.getModule().getName().str(); + CSKind = computeChecksum(SM.getMainFileID(), Checksum); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D36474: Use the file name from linemarker for debug info if an input is preprocessed source.
twoh created this revision. Herald added a subscriber: aprantl. 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. https://reviews.llvm.org/D36474 Files: lib/CodeGen/CGDebugInfo.cpp test/CodeGen/debug-info-preprocessed-file.i Index: test/CodeGen/debug-info-preprocessed-file.i === --- /dev/null +++ test/CodeGen/debug-info-preprocessed-file.i @@ -0,0 +1,10 @@ +# 1 "/foo/bar/preprocessed-input.c" +# 1 "" 1 +# 1 "" 3 +# 318 "" 3 +# 1 "" 1 +# 1 "" 2 +# 1 "preprocessed-input.c" 2 + +// RUN: %clang -g -c -S -emit-llvm -o - %s | FileCheck %s +// CHECK: !DIFile(filename: "/foo/bar/preprocessed-input.c" Index: lib/CodeGen/CGDebugInfo.cpp === --- lib/CodeGen/CGDebugInfo.cpp +++ lib/CodeGen/CGDebugInfo.cpp @@ -28,6 +28,7 @@ #include "clang/Basic/SourceManager.h" #include "clang/Basic/Version.h" #include "clang/Frontend/CodeGenOptions.h" +#include "clang/Frontend/FrontendOptions.h" #include "clang/Lex/HeaderSearchOptions.h" #include "clang/Lex/ModuleMap.h" #include "clang/Lex/PreprocessorOptions.h" @@ -484,6 +485,16 @@ MainFileName = MainFileDirSS.str(); } CSKind = computeChecksum(SM.getMainFileID(), Checksum); + +// 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. +if (MainFile->getName() == MainFileName && +FrontendOptions::getInputKindForExtension( +MainFile->getName().rsplit('.').second) +.isPreprocessed()) + MainFileName = CGM.getModule().getName().str(); } llvm::dwarf::SourceLanguage LangTag; Index: test/CodeGen/debug-info-preprocessed-file.i === --- /dev/null +++ test/CodeGen/debug-info-preprocessed-file.i @@ -0,0 +1,10 @@ +# 1 "/foo/bar/preprocessed-input.c" +# 1 "" 1 +# 1 "" 3 +# 318 "" 3 +# 1 "" 1 +# 1 "" 2 +# 1 "preprocessed-input.c" 2 + +// RUN: %clang -g -c -S -emit-llvm -o - %s | FileCheck %s +// CHECK: !DIFile(filename: "/foo/bar/preprocessed-input.c" Index: lib/CodeGen/CGDebugInfo.cpp === --- lib/CodeGen/CGDebugInfo.cpp +++ lib/CodeGen/CGDebugInfo.cpp @@ -28,6 +28,7 @@ #include "clang/Basic/SourceManager.h" #include "clang/Basic/Version.h" #include "clang/Frontend/CodeGenOptions.h" +#include "clang/Frontend/FrontendOptions.h" #include "clang/Lex/HeaderSearchOptions.h" #include "clang/Lex/ModuleMap.h" #include "clang/Lex/PreprocessorOptions.h" @@ -484,6 +485,16 @@ MainFileName = MainFileDirSS.str(); } CSKind = computeChecksum(SM.getMainFileID(), Checksum); + +// 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. +if (MainFile->getName() == MainFileName && +FrontendOptions::getInputKindForExtension( +MainFile->getName().rsplit('.').second) +.isPreprocessed()) + MainFileName = CGM.getModule().getName().str(); } llvm::dwarf::SourceLanguage LangTag; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits