[clang] [StaticAnalyzer] Fix non decimal macro values in tryExpandAsInteger (PR #168632)
Colin Kinloch via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 24 10:44:41 PST 2025
================
@@ -142,19 +142,25 @@ std::optional<int> tryExpandAsInteger(StringRef Macro, const Preprocessor &PP) {
if (InvalidSpelling)
return std::nullopt;
- llvm::APInt IntValue;
+ llvm::APSInt IntValue(0, true);
constexpr unsigned AutoSenseRadix = 0;
- if (ValueStr.getAsInteger(AutoSenseRadix, IntValue))
+ if (ValueStr.getAsInteger(AutoSenseRadix,
+ static_cast<llvm::APInt &>(IntValue)))
----------------
ColinKinloch wrote:
`StringRef::getAsInteger` has two definitions, in one the `Result` argument is a `APInt &`, the other is a template. Without the `static_cast` the compilation fails with:
```
llvm-project/llvm/include/llvm/ADT/StringRef.h:485:13: error: invalid ‘static_cast’ from type ‘llvm::APSInt’ to type ‘long long unsigned int’
```
https://github.com/llvm/llvm-project/pull/168632
More information about the cfe-commits
mailing list