mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-24 19:46:07 +00:00
[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.
This commit is contained in:
parent
ff2e619dfc
commit
e732d1ce86
@ -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;
|
||||
}
|
||||
|
||||
|
12
clang/test/SemaOpenMP/gh104810.cpp
Normal file
12
clang/test/SemaOpenMP/gh104810.cpp
Normal file
@ -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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user