vabridgers created this revision. vabridgers added reviewers: martong, steakhal. Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun. Herald added a reviewer: NoQ. Herald added a project: All. vabridgers requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
CStringChecker is using getByteLength to get the length of a string literal. For targets where a "char" is 8-bits, getByteLength() and getLength() will be equal for a C string, but for targets where a "char" is 16-bits getByteLength() returns the size in octets. This is verified in our downstream target, but we have no way to add a test case for this case since there is no target supporting 16-bit "char" upstream. Since this cannot have a test case, I'm asserted this change is "correct by construction", and visually inspected to be correct by way of the following example where this was found. The case that shows this fails using a target with 16-bit chars is here. getByteLength() for the string literal returns 4, which fails when checked against "char x[4]". With the change, the string literal is evaluated to a size of 2 which is a correct number of "char"'s for a 16-bit target. void strcpy_no_overflow_2(char *y) { char x[4]; strcpy(x, "12"); // with getByteLength(), returns 4 using 16-bit chars } Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D129269 Files: clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp Index: clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp +++ clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp @@ -848,7 +848,7 @@ SValBuilder &svalBuilder = C.getSValBuilder(); QualType sizeTy = svalBuilder.getContext().getSizeType(); const StringLiteral *strLit = cast<StringRegion>(MR)->getStringLiteral(); - return svalBuilder.makeIntVal(strLit->getByteLength(), sizeTy); + return svalBuilder.makeIntVal(strLit->getLength(), sizeTy); } case MemRegion::SymbolicRegionKind: case MemRegion::AllocaRegionKind:
Index: clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp +++ clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp @@ -848,7 +848,7 @@ SValBuilder &svalBuilder = C.getSValBuilder(); QualType sizeTy = svalBuilder.getContext().getSizeType(); const StringLiteral *strLit = cast<StringRegion>(MR)->getStringLiteral(); - return svalBuilder.makeIntVal(strLit->getByteLength(), sizeTy); + return svalBuilder.makeIntVal(strLit->getLength(), sizeTy); } case MemRegion::SymbolicRegionKind: case MemRegion::AllocaRegionKind:
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits