Open eaeltsin opened 2 months ago
Apparently, this doesn't compile when we remove the warning flag:
crash97171.cpp:35:8: error: functions cannot be declared in an anonymous struct
35 | void foo() {
| ^
crash97171.cpp:38:30: error: anonymous struct can only contain non-static data members
38 | template <typename> struct RV {
| ^
crash97171.cpp:41:10: error: types cannot be declared in an anonymous struct
41 | struct R {
| ^
crash97171.cpp:44:5: error: functions cannot be declared in an anonymous struct
44 | R bar();
| ^
crash97171.cpp:34:1: error: anonymous structs and classes must be class members
34 | struct {
| ^
I'm surprised that we run the Thread Safety Analysis at all in this context. My understanding was that we don't run it if there are any errors. In this case, it's actually the function that we crash on:
CXXMethodDecl 0x5574fcd86998 <line:35:3, line:37:3> line:35:8 foo 'void ()' implicit-inline
`-CompoundStmt 0x5574fcd90c60 <col:14, line:37:3>
`-ExprWithCleanups 0x5574fcd90c48 <line:36:5, col:21> '<dependent type>' contains-errors
`-CXXOperatorCallExpr 0x5574fcd90c10 <col:5, col:21> '<dependent type>' contains-errors '!='
|-UnresolvedLookupExpr 0x5574fcd90bc8 <col:18> '<overloaded function type>' lvalue (ADL) = 'operator!=' 0x5574fcd866c8
|-RecoveryExpr 0x5574fcd90b80 <col:5, col:16> '<dependent type>' contains-errors lvalue
| `-MemberExpr 0x5574fcd90b50 <col:5, col:11> 'RV<int>' xvalue .type 0x5574fcd881c0
| `-MaterializeTemporaryExpr 0x5574fcd90b38 <col:5, col:9> 'R' xvalue
| `-CXXMemberCallExpr 0x5574fcd90890 <col:5, col:9> 'R'
| `-MemberExpr 0x5574fcd90830 <col:5> '<bound member function type>' ->bar 0x5574fcd882e8
| `-CXXThisExpr 0x5574fcd90820 <col:5> '(anonymous struct at crash97171.cpp:34:1) *' implicit this
`-IntegerLiteral 0x5574fcd90ba8 <col:21> 'int' 0
We could quickly fix this particular bug by changing isa
to isa_and_nonnull
, but that doesn't sound right. If we only look at fully-instantiated functions without errors, a CXXOperatorCallExpr
should always have a direct callee. (Unless I'm overlooking something.)
So we should find out why the analysis runs on a function with errors and how we can prevent that.
This is where we should exit:
void clang::sema::AnalysisBasedWarnings::IssueWarnings(
sema::AnalysisBasedWarnings::Policy P, sema::FunctionScopeInfo *fscope,
const Decl *D, QualType BlockType) {
// ...
if (S.hasUncompilableErrorOccurred()) {
// Flush out any possibly unreachable diagnostics.
flushDiagnostics(S, fscope);
return;
}
Which happens before we run the analysis. Why doesn't this return true?
https://godbolt.org/z/Yn3M74cKa
Flags
Code
Output: