ABataev created this revision.
ABataev added reviewers: jdoerfert, mibintc.
Herald added subscribers: guansong, yaxunl.
ABataev requested review of this revision.
Herald added a subscriber: sstefan1.
Herald added a project: clang.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97945

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_unknown_file.cpp


Index: clang/test/OpenMP/target_unknown_file.cpp
===================================================================
--- /dev/null
+++ 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
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===================================================================
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -1648,9 +1648,13 @@
   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();


Index: clang/test/OpenMP/target_unknown_file.cpp
===================================================================
--- /dev/null
+++ 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
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===================================================================
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -1648,9 +1648,13 @@
   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();
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to