[PATCH] D156821: [CodeGen] [ubsan] Respect integer overflow handling in abs builtin

Artem Labazov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 21 03:52:55 PDT 2023


artem added inline comments.


================
Comment at: clang/lib/CodeGen/CGBuiltin.cpp:1787
+    if (!VCI->isMinSignedValue()) {
+      return EmitAbs(CGF, ArgValue, true);
+    }
----------------
MaskRay wrote:
> MaskRay wrote:
> > nit: we delete braces in this cascading case
> > 
> > https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements
> Thanks. I think the coding standard omits the outer braces as well.
Coding standard says "Use braces on the outer `if`"


================
Comment at: compiler-rt/test/ubsan/TestCases/Misc/abs.cpp:11
+int main() {
+  // ABORT: abs.cpp:[[@LINE+3]]:17: runtime error: negation of -{{[0-9]+}} cannot be represented in type 'int'; cast to an unsigned type to negate this value to itself
+  // RECOVER: abs.cpp:[[@LINE+2]]:17: runtime error: negation of -{{[0-9]+}} cannot be represented in type 'int'; cast to an unsigned type to negate this value to itself
----------------
MaskRay wrote:
> FYI: `[[@LINE+3]]` is deprecated lit syntax https://llvm.org/docs/CommandGuide/FileCheck.html#filecheck-pseudo-numeric-variables. New code should use `[[#@LINE+3]]`
> 
> `{{[0-9]+}}` can be simplified as `[[#]]`
Thanks! Fixed


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

https://reviews.llvm.org/D156821



More information about the cfe-commits mailing list