diff options
author | Sergei Barannikov <barannikov88@gmail.com> | 2023-07-08 22:42:36 +0300 |
---|---|---|
committer | Sergei Barannikov <barannikov88@gmail.com> | 2023-09-05 19:14:09 +0300 |
commit | 18a628ec4ef72bcc005e2e9d5757445c31c6e2f8 (patch) | |
tree | b73c5abf58e0bd095001b91b7dd4ad65cfd6d0d8 /clang/lib/AST/ExprConstant.cpp | |
parent | b9f24033f7f2d3485fbabbc56e3b31b5bc90e874 (diff) | |
download | llvm-18a628ec4ef72bcc005e2e9d5757445c31c6e2f8.zip llvm-18a628ec4ef72bcc005e2e9d5757445c31c6e2f8.tar.gz llvm-18a628ec4ef72bcc005e2e9d5757445c31c6e2f8.tar.bz2 |
[AST] Use correct APSInt width when evaluating string literals
The width of the APSInt values should be the width of an element.
getCharByteWidth returns the size of an element in _host_ bytes, which
makes the width N times greater, where N is the ratio between target's
CHAR_BIT and host's CHAR_BIT.
This is NFC for in-tree targets because all of them have CHAR_BIT == 8.
Reviewed By: cor3ntin, aaron.ballman
Differential Revision: https://reviews.llvm.org/D154773
Diffstat (limited to 'clang/lib/AST/ExprConstant.cpp')
-rw-r--r-- | clang/lib/AST/ExprConstant.cpp | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 0f37bcf..d8632f5 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -3463,8 +3463,7 @@ static APSInt extractStringLiteralCharacter(EvalInfo &Info, const Expr *Lit, assert(CAT && "string literal isn't an array"); QualType CharType = CAT->getElementType(); assert(CharType->isIntegerType() && "unexpected character type"); - - APSInt Value(S->getCharByteWidth() * Info.Ctx.getCharWidth(), + APSInt Value(Info.Ctx.getTypeSize(CharType), CharType->isUnsignedIntegerType()); if (Index < S->getLength()) Value = S->getCodeUnit(Index); @@ -3487,7 +3486,7 @@ static void expandStringLiteral(EvalInfo &Info, const StringLiteral *S, unsigned Elts = CAT->getSize().getZExtValue(); Result = APValue(APValue::UninitArray(), std::min(S->getLength(), Elts), Elts); - APSInt Value(S->getCharByteWidth() * Info.Ctx.getCharWidth(), + APSInt Value(Info.Ctx.getTypeSize(CharType), CharType->isUnsignedIntegerType()); if (Result.hasArrayFiller()) Result.getArrayFiller() = APValue(Value); |