[clang] [Clang] Fix ICE in SemaOpenMP with structured binding (PR #104822)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 19 10:57:51 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Yuxuan Chen (yuxuanchen1997)
<details>
<summary>Changes</summary>
Fixes https://github.com/llvm/llvm-project/issues/104810.
Clang currently crashes on the following program:
```
struct S {
int i;
};
auto [a] = S{1};
void foo() {
a;
}
```
when `-fopenmp` is enabled.
Remove the bad pattern matching and just use the virtual overrides for `Decl::getCanonicalDecl()` instead.
---
Full diff: https://github.com/llvm/llvm-project/pull/104822.diff
2 Files Affected:
- (modified) clang/lib/Sema/SemaOpenMP.cpp (+2-10)
- (added) clang/test/SemaOpenMP/gh104810.cpp (+12)
``````````diff
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index c1442b8a58eda4..74c646f64b42f2 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -1256,16 +1256,8 @@ static const ValueDecl *getCanonicalDecl(const ValueDecl *D) {
if (const auto *CED = dyn_cast<OMPCapturedExprDecl>(D))
if (const auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit())))
D = ME->getMemberDecl();
- const auto *VD = dyn_cast<VarDecl>(D);
- const auto *FD = dyn_cast<FieldDecl>(D);
- if (VD != nullptr) {
- VD = VD->getCanonicalDecl();
- D = VD;
- } else {
- assert(FD);
- FD = FD->getCanonicalDecl();
- D = FD;
- }
+
+ D = cast<ValueDecl>(D->getCanonicalDecl());
return D;
}
diff --git a/clang/test/SemaOpenMP/gh104810.cpp b/clang/test/SemaOpenMP/gh104810.cpp
new file mode 100644
index 00000000000000..92640893197760
--- /dev/null
+++ b/clang/test/SemaOpenMP/gh104810.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fopenmp -fsyntax-only %s
+
+// expected-no-diagnostics
+struct S {
+ int i;
+};
+
+auto [a] = S{1};
+
+void foo() {
+ a;
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/104822
More information about the cfe-commits
mailing list