[clang] 91be60b - Respect "-fdiagnostics-absolute-paths" on emit include location

Christopher Di Bella via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 5 11:08:05 PDT 2023


Author: Charalampos Mitrodimas
Date: 2023-06-05T18:07:18Z
New Revision: 91be60b34715bfe930dd1c56414c62a63cdaaa9c

URL: https://github.com/llvm/llvm-project/commit/91be60b34715bfe930dd1c56414c62a63cdaaa9c
DIFF: https://github.com/llvm/llvm-project/commit/91be60b34715bfe930dd1c56414c62a63cdaaa9c.diff

LOG: Respect "-fdiagnostics-absolute-paths" on emit include location

This commit fixes "TextDiagnostic::emitIncludeLocation" when compiling
with "-fdiagnostics-absolute-paths" flag enabled by emitting the absolute
path of the included file.

Fixes #63026

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D151833

Added: 
    clang/test/Frontend/absolute-paths-import.h

Modified: 
    clang/lib/Frontend/TextDiagnostic.cpp
    clang/test/Frontend/absolute-paths.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Frontend/TextDiagnostic.cpp b/clang/lib/Frontend/TextDiagnostic.cpp
index 01d2b10479ade..3cdf86f5c8a6e 100644
--- a/clang/lib/Frontend/TextDiagnostic.cpp
+++ b/clang/lib/Frontend/TextDiagnostic.cpp
@@ -868,10 +868,11 @@ void TextDiagnostic::emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc,
 }
 
 void TextDiagnostic::emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) {
-  if (DiagOpts->ShowLocation && PLoc.isValid())
-    OS << "In file included from " << PLoc.getFilename() << ':'
-       << PLoc.getLine() << ":\n";
-  else
+  if (DiagOpts->ShowLocation && PLoc.isValid()) {
+    OS << "In file included from ";
+    emitFilename(PLoc.getFilename(), Loc.getManager());
+    OS << ':' << PLoc.getLine() << ":\n";
+  } else
     OS << "In included file:\n";
 }
 

diff  --git a/clang/test/Frontend/absolute-paths-import.h b/clang/test/Frontend/absolute-paths-import.h
new file mode 100644
index 0000000000000..e20fb3a355f72
--- /dev/null
+++ b/clang/test/Frontend/absolute-paths-import.h
@@ -0,0 +1 @@
+#warning abc

diff  --git a/clang/test/Frontend/absolute-paths.c b/clang/test/Frontend/absolute-paths.c
index 6192213841325..8a9687195c36b 100644
--- a/clang/test/Frontend/absolute-paths.c
+++ b/clang/test/Frontend/absolute-paths.c
@@ -1,5 +1,10 @@
-// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. %s 2>&1 | FileCheck -check-prefix=NORMAL -check-prefix=CHECK %s
-// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. -fdiagnostics-absolute-paths %s 2>&1 | FileCheck -check-prefix=ABSOLUTE -check-prefix=CHECK %s
+// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. %s 2>&1 | FileCheck -DROOT_ABSOLUTE=%s -check-prefix=NORMAL -check-prefix=CHECK %s
+// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. -fdiagnostics-absolute-paths %s 2>&1 | FileCheck -DROOT_ABSOLUTE=%s -check-prefix=ABSOLUTE -check-prefix=CHECK %s
+
+#include "absolute-paths-import.h"
+// NORMAL: In file included from {{.*}}absolute-paths.c:4:
+// NORMAL-NOT: In file included from [[ROOT_ABSOLUTE]]:4:
+// ABSOLUTE: In file included from [[ROOT_ABSOLUTE]]:4:
 
 #include "absolute-paths.h"
 


        


More information about the cfe-commits mailing list