llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Zahira Ammarguellat (zahiraam)

<details>
<summary>Changes</summary>

Fixes a null pointer dereference when analyzing OpenMP collapsed loops where 
the induction variable is an extern reference type.
See crash here: https://godbolt.org/z/4f5rM1Kf8. 

---
Full diff: https://github.com/llvm/llvm-project/pull/203252.diff


2 Files Affected:

- (modified) clang/lib/Sema/SemaOpenMP.cpp (+1-1) 
- (added) clang/test/OpenMP/collapse_extern_ref_crash.cpp (+18) 


``````````diff
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 113c8f3cb3016..79a0c396f787e 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -8044,7 +8044,7 @@ class ForSubExprChecker : public 
DynamicRecursiveASTVisitor {
     VarDecl *V = VD->getPotentiallyDecomposedVarDecl();
     if (V->getType()->isReferenceType()) {
       VarDecl *VD = V->getDefinition();
-      if (VD->hasInit()) {
+      if (VD && VD->hasInit()) {
         Expr *I = VD->getInit();
         DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(I);
         if (!DRE)
diff --git a/clang/test/OpenMP/collapse_extern_ref_crash.cpp 
b/clang/test/OpenMP/collapse_extern_ref_crash.cpp
new file mode 100644
index 0000000000000..432fd91ef5852
--- /dev/null
+++ b/clang/test/OpenMP/collapse_extern_ref_crash.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=51 %s
+// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=51 %s
+
+// expected-no-diagnostics
+
+// Verify no crash when collapsing a loop nest where the induction variable
+// is an extern reference type. PR/issue: null dereference in getInitLCDecl
+// when VarDecl::getDefinition() returns nullptr.
+
+extern int &dim;
+auto test() {
+#pragma omp parallel for collapse(2)
+  for (int i = 0; i < dim; ++i) {
+    for (i = 0; i < 10; i++) {
+      int dummy;
+    }
+  }
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/203252
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to