MitalAshok marked an inline comment as not done.
MitalAshok added inline comments.


================
Comment at: clang/test/SemaCXX/varargs.cpp:34
   enum Unscoped1 { One = 0x7FFFFFFF };
-  (void)__builtin_va_arg(ap, Unscoped1); // ok
+  (void)__builtin_va_arg(ap, Unscoped1); // expected-warning {{second argument 
to 'va_arg' is of promotable type 'Unscoped1'; this va_arg has undefined 
behavior because arguments will be promoted to 'int'}}
 
----------------
MitalAshok wrote:
> Unscoped1 is promoted to int when passed to a variadic function.
> 
> The underlying type for Unscoped1 is unsigned int, so only Unscoped1 and 
> unsigned int are compatible, not Unscoped1 and int. An Unscoped1 passed to a 
> variadic function must be retrieved via va_arg(ap, int).
> 
Although I guess the warning is now wrong because even though `void f(int x, 
...) { std::va_list ap; va_start(ap, x); va_arg(ap, Unscoped1); }` `f(0, 
Unscoped1{2})` would be UB, `f(0, 2u)` would not be UB.

The user still should be warned about it, so I could create a new warning 
"second argument to 'va_arg' is of promotable enumeration type 'Unscoped1'; 
this va_arg may have undefined behavior because arguments of this enumeration 
type will be promoted to 'int', not the underlying type 'unsigned int'", and 
maybe suggest a fix `Unscoped1{va_arg(ap, unsigned)}`.

Or we could ignore it and pretend that int and enums with underlying types 
unsigned are compatible for the purposes of va_arg


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156054

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to