[clang] [Analyzer] support parenthesized list initialization (PR #148988)
Arseniy Zaostrovnykh via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 15 23:51:59 PDT 2025
================
@@ -1233,3 +1233,34 @@ void ExprEngine::VisitAttributedStmt(const AttributedStmt *A,
getCheckerManager().runCheckersForPostStmt(Dst, EvalSet, A, *this);
}
+
+void ExprEngine::VisitCXXParenListInitExpr(const CXXParenListInitExpr *E,
+ ExplodedNode *Pred,
+ ExplodedNodeSet &Dst) {
----------------
necto wrote:
Well spotted. In fact, there is [exact same issue with the init list](https://compiler-explorer.com/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:c%2B%2B,selection:(endColumn:1,endLineNumber:24,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:24,startColumn:1,startLineNumber:1),source:'struct+Storage+%7B%0A++int+x%3B%0A%7D%3B%0A%0Astruct+Wrapper1+%7B%0A++Storage+s%3B%0A++Wrapper1(int+a)+:+s(a)+%7B%7D%0A%7D%3B%0A%0Astruct+Wrapper2+%7B%0A++Storage+s%3B%0A++Wrapper2(int+a)+:+s%7Ba%7D+%7B%7D%0A%7D%3B%0A%0Aint+t1()+%7B%0A++++Wrapper1+w+%3D+32%3B%0A++++return+1+/+(w.s.x+-+32)%3B%0A%7D%0A%0Aint+t2()+%7B%0A++++Wrapper2+w+%3D+32%3B%0A++++return+1+/+(w.s.x+-+32)%3B%0A%7D%0A'),l:'5',n:'0',o:'C%2B%2B+source+%231',t:'0')),k:51.701121955375044,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((g:!((h:compiler,i:(compiler:clang201assert,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:1,lang:c%2B%2B,libs:!(),options:'--analyze+-std%3Dc%2B%2B20',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+x86-64+clang+20.1.0+(assertions)+(Editor+%231)',t:'0')),header:(),k:48.29887804462494,l:'4',m:16.754631264495075,n:'0',o:'',s:0,t:'0'),(g:!((h:output,i:(compilerName:'x86-64+clang+20.1.0',editorid:1,fontScale:14,fontUsePx:'0',j:1,wrap:'1'),l:'5',n:'0',o:'Output+of+x86-64+clang+20.1.0+(assertions)+(Compiler+%231)',t:'0')),header:(),l:'4',m:83.24536873550493,n:'0',o:'',s:0,t:'0')),k:48.29887804462494,l:'3',n:'0',o:'',t:'0')),l:'2',n:'0',o:'',t:'0')),version:4):
``` C++
struct Storage {
int x;
};
struct Wrapper1 {
Storage s;
Wrapper1(int a) : s(a) {}
};
struct Wrapper2 {
Storage s;
Wrapper2(int a) : s{a} {}
};
int t1() {
Wrapper1 w = 32;
return 1 / (w.s.x - 32); // false negative
}
int t2() {
Wrapper2 w = 32;
return 1 / (w.s.x - 32); // division by zero
}
```
https://github.com/llvm/llvm-project/pull/148988
More information about the cfe-commits
mailing list