-
Notifications
You must be signed in to change notification settings - Fork 11.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Clang] [C++] Anonymous unions can cause crash when the name of their type escapes #90751
Comments
@llvm/issue-subscribers-clang-frontend Author: Mital Ashok (MitalAshok)
Small example <https://godbolt.org/z/eEYzYxd9x>:
void g();
template<typename T>
struct Capture;
template<typename T>
struct Capture<T*> {
friend void g() {
&T::a;
}
};
struct X;
void f() {
union {
int a = sizeof(Capture<decltype(this)>);
};
g();
}
It seems like Making this comment wrong: llvm-project/clang/lib/Sema/SemaDeclCXX.cpp Lines 9787 to 9792 in 477c705
This function dubious: llvm-project/clang/lib/Sema/SemaAccess.cpp Lines 66 to 78 in 477c705
And this loop cause the above crash: llvm-project/clang/lib/Sema/SemaExpr.cpp Lines 14654 to 14655 in 477c705
It seems like this could be fixed by checking if the anonymous struct or union is ultimately a field of a named RecordDecl vs. a function-local/namespace-scope anonymous union |
Note GCC also ICEs on this testcase, filed as https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114911 . |
Small example https://godbolt.org/z/eEYzYxd9x:
It seems like
RecordDecl::isAnonymousStructOrUnion
is sometimes used as "Is this an anonymous union (or GNU extension anonymous struct) inside of another class", when it's not guaranteed to be inside another class.Making this comment wrong:
llvm-project/clang/lib/Sema/SemaDeclCXX.cpp
Lines 9787 to 9792 in 477c705
This function dubious:
llvm-project/clang/lib/Sema/SemaAccess.cpp
Lines 66 to 78 in 477c705
And this loop cause the above crash:
llvm-project/clang/lib/Sema/SemaExpr.cpp
Lines 14654 to 14655 in 477c705
It seems like this could be fixed by checking if the anonymous struct or union is ultimately a field of a named RecordDecl vs. a function-local/namespace-scope anonymous union
The text was updated successfully, but these errors were encountered: