[PATCH] D157331: [clang] Implement C23 <stdckdint.h>

Zijun Zhao via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 21 17:46:55 PDT 2023


ZijunZhao added inline comments.


================
Comment at: clang/test/C/C2x/n2683.c:16
+
+    bool flag_add = ckd_add(&result, a33, char_var);
+    bool flag_sub = ckd_sub(&result, bool_var, day);
----------------
aaron.ballman wrote:
> It looks like the builtins are missing some checks that are required by the C standard.
> 
> 7.20p3: Both type2 and type3 shall be any integer type other than "plain" char, bool, a bit-precise integer type, or an enumerated type, and they need not be the same.  ...
> 
> So we should get a (warning?) diagnostic on all of these uses.
> 
> We should also add a test when the result type is not suitable for the given operand types. e.g.,
> ```
> void func(int one, int two) {
>   short result;
>   ckd_add(&result, one, two); // `short` may not be suitable to hold the result of adding two `int`s
> 
>   const int other_result = 0;
>   ckd_add(&other_result, one, two); // `const int` is definitely not suitable because it's not a modifiable lvalue
> }
> ```
> This is because of:
> 
> 7.20.1p4: It is recommended to produce a diagnostic message if type2 or type3 are not suitable integer types, or if *result is not a modifiable lvalue of a suitable integer type.
yes, I am trying to add the tests about `short` type and `const` variable but there is no warning about inappropriate type 😢 and for const one I get ```result argument to overflow builtin must be a pointer to a non-const integer ('const int *' invalid)``` error 😂 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157331



More information about the cfe-commits mailing list