When there is any compile error, clang still tries to compile as many code as
possible, therefore `Scope` can be `nullptr` here. However, we didn't check it
beforehand, causing compiler crash.
Fix #59944.
Reviewed By: ABataev
Differential Revision: https://reviews.llvm.org/D142233
if (LangOpts.OpenMP >= 51 && CalleeFnDecl->getIdentifier() &&
CalleeFnDecl->getName().startswith_insensitive("omp_")) {
// checking for any calls inside an Order region
- if (Scope->isOpenMPOrderClauseScope())
+ if (Scope && Scope->isOpenMPOrderClauseScope())
Diag(LParenLoc, diag::err_omp_unexpected_call_to_omp_runtime_api);
}
--- /dev/null
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -x c -triple x86_64-apple-darwin10 %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK
+
+extern int omp_get_initial_device();
+extern void *omp_get_mapped_ptr(void *, int);
+
+void t() {
+ omp_get_mapped_ptr(&x, omp_get_initial_device());
+}
+
+// CHECK: error: use of undeclared identifier 'x'
+// CHECK-NOT: crash