[PATCH] D48040: Implement constexpr __builtin_*_overflow

Erich Keane via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 11 13:57:47 PDT 2018


erichkeane added inline comments.


================
Comment at: lib/Sema/SemaChecking.cpp:210
+    Arg = S.PerformCopyInitialization(Entity, SourceLocation(), Arg);
+    TheCall->setArg(I, Arg.get());
   }
----------------
efriedma wrote:
> erichkeane wrote:
> > efriedma wrote:
> > > Can you split this change into a separate patch?  Testcase:
> > > 
> > > ```
> > > int a() {
> > >   const int x = 3;
> > >   static int z;
> > >   constexpr int * y = &z;
> > >   return []() { return __builtin_sub_overflow(x,x,y); }();
> > > }```
> > Can you clarify what you mean?  That above testcase (with added captures) seems to work currently.  What difference in behavior should I be expecting?
> The testcase should type-check as-is, without adding any captures.  Reading the value of a constexpr variable, or a const variable of integer type, isn't an odr-use.  This doesn't work correctly at the moment because the lvalue-to-rvalue conversions are missing from the AST. Compare to the following:
> 
> ```
> int a() {
>   const int x = 3;
>   static int z;
>   constexpr int * y = &z;
>   return []() { return __builtin_sub_overflow((int)x,(int)x,(int*)y); }();
> }
> ```
Ah, got it! I 'll split that off into a separate patch with those test cases now.  Look for the review soon!


https://reviews.llvm.org/D48040





More information about the cfe-commits mailing list