[PATCH] D116048: [clang][CodeGen][UBSan] VLA size checking for unsigned integer parameter

John McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 11 14:01:38 PST 2022


rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

Okay, very minor requests, but otherwise LGTM; feel free to commit with these changes.



================
Comment at: clang/lib/CodeGen/CodeGenFunction.cpp:2256
+          llvm::Value *size = EmitScalarExpr(sizeExpr);
+          clang::QualType sizeExprType = sizeExpr->getType();
 
----------------
You can sink this into the `if` block.


================
Comment at: clang/lib/CodeGen/CodeGenFunction.cpp:2275
           // undefined behavior to have a negative bound.
-          entry = Builder.CreateIntCast(Size, SizeTy, /*signed*/ false);
+          MapEntry = Builder.CreateIntCast(Size, SizeTy, /*signed*/ false);
         }
----------------
AdamMagierFOSS wrote:
> rjmccall wrote:
> > This would be a different bug, but should UBSan also be doing a bounds check if the type is larger than `size_t`?
> Interesting point, I'd have to reread through the spec to give a precise/definitive answer. To keep this review focused I'll table the discussion for a separate forum.
I'm pretty sure you should, but it's fine to do it in a different patch.  Please leave a FIXME about it, though.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D116048/new/

https://reviews.llvm.org/D116048



More information about the cfe-commits mailing list