Skip to content

Commit e732d1c

Browse files
[Clang] Fix ICE in SemaOpenMP with structured binding (#104822)
Fixes #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.
1 parent ff2e619 commit e732d1c

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,16 +1256,8 @@ static const ValueDecl *getCanonicalDecl(const ValueDecl *D) {
12561256
if (const auto *CED = dyn_cast<OMPCapturedExprDecl>(D))
12571257
if (const auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit())))
12581258
D = ME->getMemberDecl();
1259-
const auto *VD = dyn_cast<VarDecl>(D);
1260-
const auto *FD = dyn_cast<FieldDecl>(D);
1261-
if (VD != nullptr) {
1262-
VD = VD->getCanonicalDecl();
1263-
D = VD;
1264-
} else {
1265-
assert(FD);
1266-
FD = FD->getCanonicalDecl();
1267-
D = FD;
1268-
}
1259+
1260+
D = cast<ValueDecl>(D->getCanonicalDecl());
12691261
return D;
12701262
}
12711263

clang/test/SemaOpenMP/gh104810.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %clang_cc1 -fopenmp -fsyntax-only %s
2+
3+
// expected-no-diagnostics
4+
struct S {
5+
int i;
6+
};
7+
8+
auto [a] = S{1};
9+
10+
void foo() {
11+
a;
12+
}

0 commit comments

Comments
 (0)