[clang] e732d1c - [Clang] Fix ICE in SemaOpenMP with structured binding (#104822)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 19 14:06:14 PDT 2024
Author: Yuxuan Chen
Date: 2024-08-19T14:06:10-07:00
New Revision: e732d1ce86783b1d7fe30645fcb30434109505b9
URL: https://github.com/llvm/llvm-project/commit/e732d1ce86783b1d7fe30645fcb30434109505b9
DIFF: https://github.com/llvm/llvm-project/commit/e732d1ce86783b1d7fe30645fcb30434109505b9.diff
LOG: [Clang] Fix ICE in SemaOpenMP with structured binding (#104822)
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.
Because `a` is neither `VarDecl` nor `FieldDecl`. It's a `BindingDecl`
that's not handled in `SemaOpenMP.cpp`'s `getCanonicalDecl`. It appears
to me that this pattern matching is merely just for a refined return
type of the overrides. It can also be achieved with just using the
virtual `Decl::getCanonicalDecl()` instead. Do the final casting should
be safe for `ValueDecl`s.
Added:
clang/test/SemaOpenMP/gh104810.cpp
Modified:
clang/lib/Sema/SemaOpenMP.cpp
Removed:
################################################################################
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;
+}
More information about the cfe-commits
mailing list