We did not evaluate such expressions, just returned unknown for such cases.
After this patch, we will be able to access a unique value identifying a template instantiation.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
clang/lib/StaticAnalyzer/Core/SValBuilder.cpp | ||
---|---|---|
311 | I'm not super familiar with predefined expressions, but it looks like it this commit doesn't cover all kinds of those. And for some this can return nullptr. Can you, please, add tests for other kinds as well? |
- Added tests for Microsoft extensions.
- Added an assert requiring the PredefinedExpression to have a function name.
I don't know how could a PredefinedExpression lack the function name, probably @riccibruno or @rjmccall can help with this - according to D53605.
clang/test/Analysis/eval-predefined-exprs.cpp | ||
---|---|---|
7–21 | This could be like: clang_analyzer_dump(__FUNCDNAME__); // \ // expected-warning@-4 {{&Element{"??$func@UClass@?1??foo@@YAXXZ@$0CK@D@@YAXD@Z",0 S64b,char}}} clang_analyzer_dump(L__FUNCTION__); // \ // expected-warning@-4 {{&Element{L"func",0 S64b,wchar_t}}} ... So, this way you can keep the line limit, I think this is what @Szelethus refers to. |
clang/test/Analysis/eval-predefined-exprs.cpp | ||
---|---|---|
7–21 |
There is no need for the @-4 of course with that approach. |
I don't know how could a PredefinedExpression lack the function name, probably @riccibruno or @rjmccall can help with this - according to D53605.
A PredefinedExpr whose declaration context is dependent has no name (see Sema::BuildPredefinedExpr). Example:
void f0() { __func__; } -PredefinedExpr 0x6a76ba8 <col:13> 'const char [3]' lvalue __func__ `-StringLiteral 0x6a76b88 <col:13> 'const char [3]' lvalue "f0" template <typename> void f1() { __func__; } `-PredefinedExpr 0x6a76e78 <col:35> '<dependent type>' lvalue __func__ template void f1<int>(); -PredefinedExpr 0x6a77060 <col:35> 'const char [3]' lvalue __func__ `-StringLiteral 0x6a77040 <col:35> 'const char [3]' lvalue "f1"
clang/test/Analysis/eval-predefined-exprs.cpp | ||
---|---|---|
7–21 | There is no column limit in test/. |
We only analyze instantiated functions, which are not dependently typed.
Safe to assume that every encountered PredefinedExpression has a defined (non-null) function name.
Just to be sure I added a clang_analyzer_warnIfReached in a test-case.
clang/test/Analysis/eval-predefined-exprs.cpp | ||
---|---|---|
7–21 | Do you think it would be more readable that way? I'm still not convinced. |
clang/test/Analysis/eval-predefined-exprs.cpp | ||
---|---|---|
102 | Also can you please add // no-warning as a matter of conventions? |
clang/test/Analysis/eval-predefined-exprs.cpp | ||
---|---|---|
7–21 | I have no opinion on whether it is more readable. I was just saying that test/ is an exception to the column limit policy, and indeed that *many* tests have lines longer that the limit. |
Thank you all for the comments!
clang/test/Analysis/eval-predefined-exprs.cpp | ||
---|---|---|
102 | Sure, thanks. |
I'm not super familiar with predefined expressions, but it looks like it this commit doesn't cover all kinds of those. And for some this can return nullptr.
Can you, please, add tests for other kinds as well?