From abfe348e6b4c50c750d70adcf0b99fd3d8d4132e Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sun, 10 Jan 2021 12:24:49 -0800 Subject: [PATCH] [test] Improve CodeGenCXX/difile_entry.cpp The test added in D87147 did not actually test PR47391. Use an absolute path to test the canonicalization. --- clang/lib/CodeGen/CGDebugInfo.cpp | 3 +++ clang/test/CodeGenCXX/difile_entry.cpp | 17 +++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 8bc28b2..5bdda26 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -409,6 +409,9 @@ llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) { FileID FID; if (Loc.isInvalid()) { + // The DIFile used by the CU is distinct from the main source file. Call + // createFile() below for canonicalization if the source file was specified + // with an absolute path. FileName = TheCU->getFile()->getFilename(); } else { PresumedLoc PLoc = SM.getPresumedLoc(Loc); diff --git a/clang/test/CodeGenCXX/difile_entry.cpp b/clang/test/CodeGenCXX/difile_entry.cpp index 1ae36e4..8bf6dc3 100644 --- a/clang/test/CodeGenCXX/difile_entry.cpp +++ b/clang/test/CodeGenCXX/difile_entry.cpp @@ -1,12 +1,13 @@ -// RUN: rm -rf %t/test_dir -// RUN: mkdir -p %t/test_dir -// RUN: cd %t/test_dir +/// PR47391: if the filename is absolute and starts with current working +/// directory, there may be two ways describing the filename field of DIFile. +/// Test that we canonicalize the DIFile. +// RUN: rm -rf %t && mkdir %t && cd %t // RUN: cp %s . -// RUN: %clang_cc1 -triple %itanium_abi_triple -main-file-name difile_entry.cpp -debug-info-kind=limited ../test_dir/difile_entry.cpp -std=c++11 -emit-llvm -o - | FileCheck ../test_dir/difile_entry.cpp +// RUN: %clang_cc1 -triple %itanium_abi_triple -main-file-name difile_entry.cpp -debug-info-kind=limited %t/difile_entry.cpp -std=c++11 -emit-llvm -o - | FileCheck %s int x(); static int i = x(); -// CHECK: [[FILE: *]] = !DIFile(filename: "{{.*}}difile_entry.cpp", -// CHECK: {{.*}} = distinct !DISubprogram(name: "__cxx_global_var_init", scope: {{.*}}, file: [[FILE]] -// CHECK: {{.*}} = distinct !DISubprogram(linkageName: "_GLOBAL__sub_I_difile_entry.cpp", scope: {{.*}}, file: [[FILE]] - +// CHECK: distinct !DIGlobalVariable(name: "i", {{.*}}, file: ![[#FILE:]], +// CHECK: ![[#FILE]] = !DIFile(filename: "difile_entry.cpp", directory: +// CHECK: distinct !DISubprogram(name: "__cxx_global_var_init", {{.*}}, file: ![[#FILE]], +// CHECK: distinct !DISubprogram(linkageName: "_GLOBAL__sub_I_difile_entry.cpp", {{.*}}, file: ![[#FILE]] -- 2.7.4