[clang] 711179b - [OPENMP]Fix PR48759: "fatal error" when compile with preprocessed file.

Alexey Bataev via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 4 07:29:13 PST 2021


Author: Alexey Bataev
Date: 2021-03-04T07:26:57-08:00
New Revision: 711179b5816a65eccad22a7111494d609b899fb2

URL: https://github.com/llvm/llvm-project/commit/711179b5816a65eccad22a7111494d609b899fb2
DIFF: https://github.com/llvm/llvm-project/commit/711179b5816a65eccad22a7111494d609b899fb2.diff

LOG: [OPENMP]Fix PR48759:  "fatal error" when compile with preprocessed file.

If the file in line directive does not exist on the system we need, to
use the original file to get its file id.

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

Added: 
    clang/test/OpenMP/target_unknown_file.cpp

Modified: 
    clang/lib/CodeGen/CGOpenMPRuntime.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index d0876056268d..f9c79e6c95f5 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -1648,9 +1648,13 @@ static void getTargetEntryUniqueInfo(ASTContext &C, SourceLocation Loc,
   assert(PLoc.isValid() && "Source location is expected to be always valid.");
 
   llvm::sys::fs::UniqueID ID;
-  if (auto EC = llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID))
-    SM.getDiagnostics().Report(diag::err_cannot_open_file)
-        << PLoc.getFilename() << EC.message();
+  if (auto EC = llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID)) {
+    PLoc = SM.getPresumedLoc(Loc, /*UseLineDirectives=*/false);
+    assert(PLoc.isValid() && "Source location is expected to be always valid.");
+    if (auto EC = llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID))
+      SM.getDiagnostics().Report(diag::err_cannot_open_file)
+          << PLoc.getFilename() << EC.message();
+  }
 
   DeviceID = ID.getDevice();
   FileID = ID.getFile();

diff  --git a/clang/test/OpenMP/target_unknown_file.cpp b/clang/test/OpenMP/target_unknown_file.cpp
new file mode 100644
index 000000000000..8700c74ea5de
--- /dev/null
+++ b/clang/test/OpenMP/target_unknown_file.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-apple-darwin10.6.0 -emit-llvm -o - %s 2>&1 | FileCheck %s
+// expected-no-diagnostics
+
+// CHECK-NOT: fatal error: cannot open file
+
+// CHECK: call void @__omp_offloading_{{.+}}()
+# 1 "unknown.xxxxxxxx"
+void a() {
+#pragma omp target
+  ;
+}
+
+// CHECK-NOT: fatal error: cannot open file


        


More information about the cfe-commits mailing list