[clang] [Safe Buffers] Fix a small bug recently found (PR #102953)

Artem Dergachev via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 13 12:04:32 PDT 2024


================
@@ -404,7 +404,7 @@ AST_MATCHER(CXXConstructExpr, isSafeSpanTwoParamConstruct) {
 
   if (Arg0Ty->isConstantArrayType()) {
     const APSInt ConstArrSize =
-        APSInt(cast<ConstantArrayType>(Arg0Ty)->getSize());
+        APSInt(cast<ConstantArrayType>(Arg0Ty.getCanonicalType())->getSize());
----------------
haoNoQ wrote:

There's this whole `ASTContext::getAsArrayType()` thing (et al.):

> This is a member of [ASTContext](https://clang.llvm.org/doxygen/classclang_1_1ASTContext.html) because this may need to do some amount of canonicalization, e.g. to move type qualifiers into the element type.

I.e. such "canonicalization" is stronger than a simple `.getCanonicalType()` and it sounds like we're supposed to do that consistently.

So we probably should use `ASTContext::getAsConstantArrayType()` in such cases.

https://github.com/llvm/llvm-project/pull/102953


More information about the cfe-commits mailing list