r244063 - Add missing atomic libcall support.

2015-08-05 Thread James Y Knight
Author: jyknight
Date: Wed Aug  5 11:57:36 2015
New Revision: 244063

URL: http://llvm.org/viewvc/llvm-project?rev=244063&view=rev
Log:
Add missing atomic libcall support.

Support for emitting libcalls for __atomic_fetch_nand and
__atomic_{add,sub,and,or,xor,nand}_fetch was missing; add it, and some
test cases.

Differential Revision: http://reviews.llvm.org/D10847

Modified:
cfe/trunk/docs/LanguageExtensions.rst
cfe/trunk/lib/CodeGen/CGAtomic.cpp
cfe/trunk/test/CodeGen/atomic-ops-libcall.c

Modified: cfe/trunk/docs/LanguageExtensions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LanguageExtensions.rst?rev=244063&r1=244062&r2=244063&view=diff
==
--- cfe/trunk/docs/LanguageExtensions.rst (original)
+++ cfe/trunk/docs/LanguageExtensions.rst Wed Aug  5 11:57:36 2015
@@ -1715,6 +1715,9 @@ The macros ``__ATOMIC_RELAXED``, ``__ATO
 provided, with values corresponding to the enumerators of C11's
 ``memory_order`` enumeration.
 
+(Note that Clang additionally provides GCC-compatible ``__atomic_*``
+builtins)
+
 Low-level ARM exclusive memory builtins
 ---
 

Modified: cfe/trunk/lib/CodeGen/CGAtomic.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGAtomic.cpp?rev=244063&r1=244062&r2=244063&view=diff
==
--- cfe/trunk/lib/CodeGen/CGAtomic.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGAtomic.cpp Wed Aug  5 11:57:36 2015
@@ -699,7 +699,7 @@ RValue CodeGenFunction::EmitAtomicExpr(A
 
   switch (E->getOp()) {
   case AtomicExpr::AO__c11_atomic_init:
-llvm_unreachable("Already handled!");
+llvm_unreachable("Already handled above with EmitAtomicInit!");
 
   case AtomicExpr::AO__c11_atomic_load:
   case AtomicExpr::AO__atomic_load_n:
@@ -785,20 +785,43 @@ RValue CodeGenFunction::EmitAtomicExpr(A
   if (UseLibcall) {
 bool UseOptimizedLibcall = false;
 switch (E->getOp()) {
+case AtomicExpr::AO__c11_atomic_init:
+  llvm_unreachable("Already handled above with EmitAtomicInit!");
+
 case AtomicExpr::AO__c11_atomic_fetch_add:
 case AtomicExpr::AO__atomic_fetch_add:
 case AtomicExpr::AO__c11_atomic_fetch_and:
 case AtomicExpr::AO__atomic_fetch_and:
 case AtomicExpr::AO__c11_atomic_fetch_or:
 case AtomicExpr::AO__atomic_fetch_or:
+case AtomicExpr::AO__atomic_fetch_nand:
 case AtomicExpr::AO__c11_atomic_fetch_sub:
 case AtomicExpr::AO__atomic_fetch_sub:
 case AtomicExpr::AO__c11_atomic_fetch_xor:
 case AtomicExpr::AO__atomic_fetch_xor:
+case AtomicExpr::AO__atomic_add_fetch:
+case AtomicExpr::AO__atomic_and_fetch:
+case AtomicExpr::AO__atomic_nand_fetch:
+case AtomicExpr::AO__atomic_or_fetch:
+case AtomicExpr::AO__atomic_sub_fetch:
+case AtomicExpr::AO__atomic_xor_fetch:
   // For these, only library calls for certain sizes exist.
   UseOptimizedLibcall = true;
   break;
-default:
+
+case AtomicExpr::AO__c11_atomic_load:
+case AtomicExpr::AO__c11_atomic_store:
+case AtomicExpr::AO__c11_atomic_exchange:
+case AtomicExpr::AO__c11_atomic_compare_exchange_weak:
+case AtomicExpr::AO__c11_atomic_compare_exchange_strong:
+case AtomicExpr::AO__atomic_load_n:
+case AtomicExpr::AO__atomic_load:
+case AtomicExpr::AO__atomic_store_n:
+case AtomicExpr::AO__atomic_store:
+case AtomicExpr::AO__atomic_exchange_n:
+case AtomicExpr::AO__atomic_exchange:
+case AtomicExpr::AO__atomic_compare_exchange_n:
+case AtomicExpr::AO__atomic_compare_exchange:
   // Only use optimized library calls for sizes for which they exist.
   if (Size == 1 || Size == 2 || Size == 4 || Size == 8)
 UseOptimizedLibcall = true;
@@ -820,6 +843,9 @@ RValue CodeGenFunction::EmitAtomicExpr(A
 QualType RetTy;
 bool HaveRetTy = false;
 switch (E->getOp()) {
+case AtomicExpr::AO__c11_atomic_init:
+  llvm_unreachable("Already handled!");
+
 // There is only one libcall for compare an exchange, because there is no
 // optimisation benefit possible from a libcall version of a weak compare
 // and exchange.
@@ -903,7 +929,49 @@ RValue CodeGenFunction::EmitAtomicExpr(A
   AddDirectArgument(*this, Args, UseOptimizedLibcall, Val1, MemTy,
 E->getExprLoc(), sizeChars);
   break;
-default: return EmitUnsupportedRValue(E, "atomic library call");
+// T __atomic_fetch_nand_N(T *mem, T val, int order)
+case AtomicExpr::AO__atomic_fetch_nand:
+  LibCallName = "__atomic_fetch_nand";
+  AddDirectArgument(*this, Args, UseOptimizedLibcall, Val1, MemTy,
+E->getExprLoc(), sizeChars);
+  break;
+
+// T __atomic_add_fetch_N(T *mem, T val, int order)
+case AtomicExpr::AO__atomic_add_fetch:
+  LibCallName = "__atomic_add_fetch";
+  AddDirectArgument(*this, Args, UseOptimizedLibc

Re: [PATCH] D11298: Convert a few classes over to use the new TrailingObjects helper.

2015-08-05 Thread James Y Knight
jyknight marked an inline comment as done.


Comment at: include/clang/AST/Decl.h:3620
@@ +3619,3 @@
+  public DeclContext,
+  llvm::TrailingObjects {
+protected:

rsmith wrote:
> I would prefer to see an explicit `private` access specifier here.
Done here and everywhere.


Comment at: include/clang/AST/Decl.h:3702
@@ -3691,2 +3701,3 @@
   friend class ASTDeclWriter;
+  friend class TrailingObjects;
 };

rsmith wrote:
> I predict one of our supported host compilers will choke on this.
> 
> *experiments*
> 
> That compiler is MSVC. It appears all our supported compilers provide enough 
> C++11 to allow
> 
>   friend TrailingObjects;
Done here and everywhere


Comment at: include/clang/AST/DeclTemplate.h:47
@@ -45,2 +46,3 @@
 /// derived classes.
-class LLVM_ALIGNAS(/*alignof(void*)*/ LLVM_PTR_SIZE) TemplateParameterList {
+class LLVM_ALIGNAS(/*alignof(void*)*/ LLVM_PTR_SIZE) TemplateParameterList 
final
+: llvm::TrailingObjects {

rsmith wrote:
> Can you remove the LLVM_ALIGNAS?
Nope, still needs to be provded manually. The TrailingObjects class does not 
currently adjust the alignment for you, but rather, just static_asserts that 
you've gotten it right. I'd like it to, but right now, the argument to 
LLVM_ALIGNAS apparently needs to be a literal integer for MSVC.

...although...actually, now that I think about it more, it may actually be 
possible to make it work even on VC. I don't have a way to test it, but I think 
something like the following might do the trick.

I'd like to avoid trying to add this feature to the llvm TrailingObjects class 
right now, though, and try it in a follow-up later on, OK?

```
template class AlignmentHelper {};

template<> class LLVM_ALIGNAS(1) AlignmentHelper<1> {};
template<> class LLVM_ALIGNAS(2) AlignmentHelper<2> {};
template<> class LLVM_ALIGNAS(4) AlignmentHelper<4> {};
template<> class LLVM_ALIGNAS(8) AlignmentHelper<8> {};
template<> class LLVM_ALIGNAS(16) AlignmentHelper<16> {};
template<> class LLVM_ALIGNAS(32) AlignmentHelper<32> {};

class OtherThing {
  double x;
};

class SomeThing : AlignmentHelper::Alignment> {
  char x;
};

int main() {
  static_assert(AlignOf::Alignment == 
AlignOf::Alignment, "");
}

```


Comment at: include/clang/AST/DeclTemplate.h:145
@@ -136,4 +144,3 @@
 /// derived classes. Suitable for creating on the stack.
-template
-class FixedSizeTemplateParameterList : public TemplateParameterList {
-  NamedDecl *Params[N];
+template  class FixedSizeTemplateParameterListStorage {
+  char Mem[TemplateParameterList::totalSizeToAlloc(N)];

rsmith wrote:
> This type is now underaligned.
Indeed! stupid oversight from adjusting the code at the last minute for the 
required "final". Should've inserted an alignment here too. But because of the 
constexpr issue, this goes away anyways...


Comment at: include/clang/AST/DeclTemplate.h:146
@@ -140,1 +145,3 @@
+template  class FixedSizeTemplateParameterListStorage {
+  char Mem[TemplateParameterList::totalSizeToAlloc(N)];
 

rnk wrote:
> rsmith wrote:
> > Do all of our supported compilers provide enough `constexpr` support for 
> > this to actually work? How would you feel about:
> > 
> >   TemplateParameterList List;
> >   NamedDecl *Params[N];
> > 
> > (Yeah, I don't like this either.)
> Won't this reduce the alignment of this structure to 1?
Yeah, right, no constexpr in VS2013. So, I guess that'll have to do...yuck but 
oh well.

I stuck in some asserts for the layout being as expected to assuage my 
conscience.


Comment at: include/clang/AST/DeclTemplate.h:165
@@ -151,6 +164,3 @@
   /// \brief The template argument list.
-  ///
-  /// The integer value will be non-zero to indicate that this
-  /// template argument list does own the pointer.
-  llvm::PointerIntPair Arguments;
+  const TemplateArgument *Arguments;
 

rsmith wrote:
> Please check in the removal of the `Owned` flag separately.
Acknowledged. [but still in this change as of right now]


Comment at: include/clang/AST/DeclTemplate.h:1290-1302
@@ -1262,15 +1289,15 @@
   /// pack.
   QualType getExpansionType(unsigned I) const {
 assert(I < NumExpandedTypes && "Out-of-range expansion type index");
-void * const *TypesAndInfos = reinterpret_cast(this + 1);
+void *const *TypesAndInfos = getTrailingObjects();
 return QualType::getFromOpaquePtr(TypesAndInfos[2*I]);
   }
 
   /// \brief Retrieve a particular expansion type source info within an
   /// expanded parameter pack.
   TypeSourceInfo *getExpansionTypeSourceInfo(unsigned I) const {
 assert(I < NumExpandedTypes && "Out-of-range expansion type index");
-void * const *TypesAndInfos = reinterpret_cast(this + 1);
+void *const *TypesAndInfos = getTrailingObjects();
 return static_cast(TypesAndInfos[2*I+1]);
   }
 

rsmith wrote:
> 

Re: r314373 - [NFC] Don't use C++17 standard lib variable template helper traits, instead use ::value.

2017-09-27 Thread James Y Knight via cfe-commits
This still doesn't work on some compilers, because
std::is_trivially_copyable isn't available:
http://lab.llvm.org:8011/builders/aosp-O3-polly-before-vectorizer-unprofitable/builds/265/steps/build/logs/stdio

On Wed, Sep 27, 2017 at 10:00 PM, Faisal Vali via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: faisalv
> Date: Wed Sep 27 19:00:40 2017
> New Revision: 314373
>
> URL: http://llvm.org/viewvc/llvm-project?rev=314373&view=rev
> Log:
> [NFC] Don't use C++17 standard lib variable template helper traits,
> instead use ::value.
>
> Modified:
> cfe/trunk/lib/Lex/MacroArgs.cpp
>
> Modified: cfe/trunk/lib/Lex/MacroArgs.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/
> MacroArgs.cpp?rev=314373&r1=314372&r2=314373&view=diff
> 
> ==
> --- cfe/trunk/lib/Lex/MacroArgs.cpp (original)
> +++ cfe/trunk/lib/Lex/MacroArgs.cpp Wed Sep 27 19:00:40 2017
> @@ -62,7 +62,7 @@ MacroArgs *MacroArgs::create(const Macro
>
>// Copy the actual unexpanded tokens to immediately after the result
> ptr.
>if (!UnexpArgTokens.empty()) {
> -static_assert(std::is_trivially_copyable_v,
> +static_assert(std::is_trivially_copyable::value,
>"assume trivial copyability if copying into the "
>"uninitialized array (as opposed to reusing a cached "
>"MacroArgs)");
> @@ -96,7 +96,7 @@ MacroArgs *MacroArgs::deallocate() {
>// Run the dtor to deallocate the vectors.
>this->~MacroArgs();
>// Release the memory for the object.
> -  static_assert(std::is_trivially_destructible_v,
> +  static_assert(std::is_trivially_destructible::value,
>  "assume trivially destructible and forego destructors");
>free(this);
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r314373 - [NFC] Don't use C++17 standard lib variable template helper traits, instead use ::value.

2017-09-28 Thread James Y Knight via cfe-commits
It was fixed in r314391, to use is_trivial instead of is_trivially_copyable.


On Thu, Sep 28, 2017 at 3:57 PM, Faisal Vali  wrote:

> Isn't this a C++11 feature though?
>
> I'm not sure what to make of the fact that I haven't gotten any
> complaints from the bots in over 12 hrs i think?
>
> Should I just turn it into a comment?
>
> Thanks!
>
> Faisal Vali
>
>
>
> On Wed, Sep 27, 2017 at 9:54 PM, James Y Knight 
> wrote:
> > This still doesn't work on some compilers, because
> > std::is_trivially_copyable isn't available:
> > http://lab.llvm.org:8011/builders/aosp-O3-polly-before-
> vectorizer-unprofitable/builds/265/steps/build/logs/stdio
> >
> > On Wed, Sep 27, 2017 at 10:00 PM, Faisal Vali via cfe-commits
> >  wrote:
> >>
> >> Author: faisalv
> >> Date: Wed Sep 27 19:00:40 2017
> >> New Revision: 314373
> >>
> >> URL: http://llvm.org/viewvc/llvm-project?rev=314373&view=rev
> >> Log:
> >> [NFC] Don't use C++17 standard lib variable template helper traits,
> >> instead use ::value.
> >>
> >> Modified:
> >> cfe/trunk/lib/Lex/MacroArgs.cpp
> >>
> >> Modified: cfe/trunk/lib/Lex/MacroArgs.cpp
> >> URL:
> >> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/
> MacroArgs.cpp?rev=314373&r1=314372&r2=314373&view=diff
> >>
> >> 
> ==
> >> --- cfe/trunk/lib/Lex/MacroArgs.cpp (original)
> >> +++ cfe/trunk/lib/Lex/MacroArgs.cpp Wed Sep 27 19:00:40 2017
> >> @@ -62,7 +62,7 @@ MacroArgs *MacroArgs::create(const Macro
> >>
> >>// Copy the actual unexpanded tokens to immediately after the result
> >> ptr.
> >>if (!UnexpArgTokens.empty()) {
> >> -static_assert(std::is_trivially_copyable_v,
> >> +static_assert(std::is_trivially_copyable::value,
> >>"assume trivial copyability if copying into the "
> >>"uninitialized array (as opposed to reusing a cached
> "
> >>"MacroArgs)");
> >> @@ -96,7 +96,7 @@ MacroArgs *MacroArgs::deallocate() {
> >>// Run the dtor to deallocate the vectors.
> >>this->~MacroArgs();
> >>// Release the memory for the object.
> >> -  static_assert(std::is_trivially_destructible_v,
> >> +  static_assert(std::is_trivially_destructible::value,
> >>  "assume trivially destructible and forego
> destructors");
> >>free(this);
> >>
> >>
> >>
> >> ___
> >> cfe-commits mailing list
> >> cfe-commits@lists.llvm.org
> >> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
> >
> >
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [libcxx] r337960 - [libc++] Use __int128_t to represent file_time_type.

2018-07-25 Thread James Y Knight via cfe-commits
As is the case on most modern platforms, the ability to store a high-res
file timestamp is dependent on the filesystem the file is stored on.

The HFS+ filesystem (used by default before macOS 10.13) stores timestamps
at a 1-second granularity, and APFS (now the default) at a 1 nanosecond
granularity.

1-second granularity is also the norm on many of the supported filesystems
on Linux as well.

On Wed, Jul 25, 2018 at 10:43 PM Eric Fiselier via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Looks like macOS 10.11 only supports a resolution of seconds, but I can't
> find documentation confirming that.
>
> I'll adjust the test.
>
> /Eric
>
> On Wed, Jul 25, 2018 at 8:33 PM Alex L  wrote:
>
>> Looks like 'SupportsNanosecondRoundTrip' is set to 0.
>>
>> On 25 July 2018 at 19:30, Alex L  wrote:
>>
>>> Sure,
>>>
>>> Standard Error:
>>>
>>> --
>>>
>>> PRIOR:3
>>>
>>> AFTER:0
>>>
>>>
>>> Diff:
>>>
>>>
>>> -return last_write_time(p) == ft;
>>>
>>> +std::cerr << "PRIOR:" << (long long)ft.time_since_epoch().count()
>>> << std::endl;
>>>
>>> +auto ft2 = last_write_time(p);
>>>
>>> +std::cerr << "AFTER:" << (long long)ft2.time_since_epoch().count()
>>> << std::endl;
>>>
>>> +return ft2  == ft;
>>>
>>> On 25 July 2018 at 19:20, Eric Fiselier  wrote:
>>>
 Could you tell me what the value of the initial time point, and the
 resulting one are on this line?


 https://github.com/llvm-mirror/libcxx/blob/master/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp#L224

 On Wed, Jul 25, 2018 at 8:17 PM Alex L  wrote:

> Please let me know if this information is helpful. If not, I'll mark
> the test as UNSUPPORTED for darwin for the time being and will create an
> internal issue to track the investigation into the OS-specific failure.
> Cheers,
> Alex
>
> On 25 July 2018 at 19:12, Alex L  wrote:
>
>> I got the following output on an macOS10.11 machine:
>>
>> Exit Code: 1
>>
>> Standard Error:
>>
>> --
>>
>> Test Case = file, epoch_time
>>
>> 0
>>
>> 0
>>
>> Test Case = dir, epoch_time
>>
>> 0
>>
>> 0
>>
>> Test Case = file, future_time
>>
>> In set_last_write_time_dynamic_env_test():455 Assertion
>> TEST_CHECK(CompareTime(got_time, TC.new_time)) failed.
>>
>> in file:
>> /Users/local/llvm/projects/libcxx/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp
>>
>>
>>
>> 15325819240
>>
>> 1532581924695307000
>>
>> Test Case = dir, future_time
>>
>> In set_last_write_time_dynamic_env_test():455 Assertion
>> TEST_CHECK(CompareTime(got_time, TC.new_time)) failed.
>>
>> in file:
>> /Users/local/llvm/projects/libcxx/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp
>>
>>
>>
>> 15325819240
>>
>> 1532581924695307000
>>
>> Test Case = file, past_time
>>
>> In set_last_write_time_dynamic_env_test():455 Assertion
>> TEST_CHECK(CompareTime(got_time, TC.new_time)) failed.
>>
>> in file:
>> /Users/local/llvm/projects/libcxx/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp
>>
>>
>>
>> 15325708600
>>
>> 1532570860695273000
>>
>> Test Case = dir, past_time
>>
>> In set_last_write_time_dynamic_env_test():455 Assertion
>> TEST_CHECK(CompareTime(got_time, TC.new_time)) failed.
>>
>> in file:
>> /Users/local/llvm/projects/libcxx/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp
>>
>>
>>
>> 15325708600
>>
>> 1532570860695273000
>>
>> Test Case = file, before_epoch_time
>>
>> In set_last_write_time_dynamic_env_test():455 Assertion
>> TEST_CHECK(CompareTime(got_time, TC.new_time)) failed.
>>
>> in file:
>> /Users/local/llvm/projects/libcxx/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp
>>
>>
>>
>> -2230
>>
>> -22217000
>>
>> Test Case = dir, before_epoch_time
>>
>> In set_last_write_time_dynamic_env_test():455 Assertion
>> TEST_CHECK(CompareTime(got_time, TC.new_time)) failed.
>>
>> in file:
>> /Users/local/llvm/projects/libcxx/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp
>>
>>
>>
>> -2230
>>
>> -22217000
>>
>> Test Case = file, just_before_epoch_time
>>
>> In set_last_write_time_dynamic_env_test():455 Assertion
>> TEST_CHECK(CompareTime(got_time, TC.new_time)) failed.
>>
>> in file:
>> /Users/local/llvm/projects/libcxx/test/std/experimental/filesystem/fs.o

[libcxx] r305394 - PR32476: __nop_locale_mgmt.h not needed with newlib 2.5+

2017-06-14 Thread James Y Knight via cfe-commits
Author: jyknight
Date: Wed Jun 14 11:40:03 2017
New Revision: 305394

URL: http://llvm.org/viewvc/llvm-project?rev=305394&view=rev
Log:
PR32476: __nop_locale_mgmt.h not needed with newlib 2.5+

Newlib 2.5 added the locale management functions, so it should not
include __nop_local_mgmt.h. This change adds proper guard around that
include statement.

For newlib 2.4, some releases contain these functions and some don't,
and they all have the same version numbers. This patch will work
properly with the initial "2.4.0" release which does not include these
functions and require __nop_local_mgmt.h.

This has been tested against newlib 2.2 and 2.5, and also sanity
checks against other different version numbers.

Patch by Martin J. O'Riordan and Walter Lee

Differential Revision: https://reviews.llvm.org/D32146

Modified:
libcxx/trunk/include/support/newlib/xlocale.h

Modified: libcxx/trunk/include/support/newlib/xlocale.h
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/support/newlib/xlocale.h?rev=305394&r1=305393&r2=305394&view=diff
==
--- libcxx/trunk/include/support/newlib/xlocale.h (original)
+++ libcxx/trunk/include/support/newlib/xlocale.h Wed Jun 14 11:40:03 2017
@@ -16,7 +16,10 @@
 #include 
 #include 
 #include 
+#if !defined(__NEWLIB__) || __NEWLIB__ < 2 || \
+__NEWLIB__ == 2 && __NEWLIB_MINOR__ < 5
 #include 
+#endif
 #include 
 #include 
 


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


r305399 - Define _GNU_SOURCE for rtems c++

2017-06-14 Thread James Y Knight via cfe-commits
Author: jyknight
Date: Wed Jun 14 12:01:18 2017
New Revision: 305399

URL: http://llvm.org/viewvc/llvm-project?rev=305399&view=rev
Log:
Define _GNU_SOURCE for rtems c++

This is required by the libc++ locale support.

Patch by Walter Lee.

Differential Revision: https://reviews.llvm.org/D34105

Modified:
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/test/Preprocessor/init.c

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=305399&r1=305398&r2=305399&view=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Wed Jun 14 12:01:18 2017
@@ -4734,6 +4734,9 @@ protected:
 
 Builder.defineMacro("__rtems__");
 Builder.defineMacro("__ELF__");
+// Required by the libc++ locale support.
+if (Opts.CPlusPlus)
+  Builder.defineMacro("_GNU_SOURCE");
   }
 
 public:

Modified: cfe/trunk/test/Preprocessor/init.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/init.c?rev=305399&r1=305398&r2=305399&view=diff
==
--- cfe/trunk/test/Preprocessor/init.c (original)
+++ cfe/trunk/test/Preprocessor/init.c Wed Jun 14 12:01:18 2017
@@ -8779,6 +8779,7 @@
 // KFREEBSDI686-DEFINE:#define __GLIBC__ 1
 //
 // RUN: %clang_cc1 -x c++ -triple i686-pc-linux-gnu -fobjc-runtime=gcc -E -dM 
< /dev/null | FileCheck -match-full-lines -check-prefix GNUSOURCE %s
+// RUN: %clang_cc1 -x c++ -triple sparc-rtems-elf -E -dM < /dev/null | 
FileCheck -match-full-lines -check-prefix GNUSOURCE %s
 // GNUSOURCE:#define _GNU_SOURCE 1
 //
 // RUN: %clang_cc1 -x c++ -std=c++98 -fno-rtti -E -dM < /dev/null | FileCheck 
-match-full-lines -check-prefix NORTTI %s


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


Re: r321099 - [driver][darwin] Take the OS version specified in "-target" as the target

2017-12-21 Thread James Y Knight via cfe-commits
I think if a version number isn't explicitly specified in the -target
value, the value from -m-version-min ought to still be used, as
it was before.

Currently, clang will ignore the -m-version-min version number if
the target has a particular OS specified, even if it has no version number
as part of it.

(We should be able to workaround this change backwards-compatibly by
specifying in both the -target argument and in the -m-version-min
arguments, but I do think the behavior should be fixed.)

On Thu, Dec 21, 2017 at 10:45 AM, Martin Böhme  wrote:

> This is causing problems in some internal builds that specify both
> -mios-simulator-version-min=9.0 and --target=x86_64-apple-ios
>
> My expectation would be for the code to take the minimum OS version number
> from the -mios-simulator-version-min flag. In fact, however, the code seems
> to be completely ignoring this flag.
>
> Is my expectation wrong or does the code need to be modified to take this
> situation into account?
>
>
> On 19 December 2017 at 20:05, Alex Lorenz via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: arphaman
>> Date: Tue Dec 19 11:05:04 2017
>> New Revision: 321099
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=321099&view=rev
>> Log:
>> [driver][darwin] Take the OS version specified in "-target" as the target
>> OS instead of inferring it from SDK / environment
>>
>> The OS version is specified in -target should be used instead of the one
>> in an
>> environment variable / SDK name.
>>
>> rdar://35813850
>>
>> Differential Revision: https://reviews.llvm.org/D40998
>>
>> Modified:
>> cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
>> cfe/trunk/test/Driver/darwin-version.c
>> cfe/trunk/test/Driver/objc-weak.m
>> cfe/trunk/test/Driver/pic.c
>> cfe/trunk/test/Driver/unavailable_aligned_allocation.cpp
>>
>> Modified: cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Too
>> lChains/Darwin.cpp?rev=321099&r1=321098&r2=321099&view=diff
>> 
>> ==
>> --- cfe/trunk/lib/Driver/ToolChains/Darwin.cpp (original)
>> +++ cfe/trunk/lib/Driver/ToolChains/Darwin.cpp Tue Dec 19 11:05:04 2017
>> @@ -1233,6 +1233,10 @@ struct DarwinPlatform {
>>  llvm_unreachable("Unsupported Darwin Source Kind");
>>}
>>
>> +  static DarwinPlatform createFromTarget(llvm::Triple::OSType OS,
>> + StringRef OSVersion, Arg *A) {
>> +return DarwinPlatform(TargetArg, getPlatformFromOS(OS), OSVersion,
>> A);
>> +  }
>>static DarwinPlatform createOSVersionArg(DarwinPlatformKind Platform,
>> Arg *A) {
>>  return DarwinPlatform(OSVersionArg, Platform, A);
>> @@ -1250,33 +1254,32 @@ struct DarwinPlatform {
>>}
>>static DarwinPlatform createFromArch(llvm::Triple::OSType OS,
>> StringRef Value) {
>> -DarwinPlatformKind Platform;
>> +return DarwinPlatform(InferredFromArch, getPlatformFromOS(OS),
>> Value);
>> +  }
>> +
>> +private:
>> +  DarwinPlatform(SourceKind Kind, DarwinPlatformKind Platform, Arg
>> *Argument)
>> +  : Kind(Kind), Platform(Platform), Argument(Argument) {}
>> +  DarwinPlatform(SourceKind Kind, DarwinPlatformKind Platform, StringRef
>> Value,
>> + Arg *Argument = nullptr)
>> +  : Kind(Kind), Platform(Platform), OSVersion(Value),
>> Argument(Argument) {}
>> +
>> +  static DarwinPlatformKind getPlatformFromOS(llvm::Triple::OSType OS) {
>>  switch (OS) {
>>  case llvm::Triple::Darwin:
>>  case llvm::Triple::MacOSX:
>> -  Platform = DarwinPlatformKind::MacOS;
>> -  break;
>> +  return DarwinPlatformKind::MacOS;
>>  case llvm::Triple::IOS:
>> -  Platform = DarwinPlatformKind::IPhoneOS;
>> -  break;
>> +  return DarwinPlatformKind::IPhoneOS;
>>  case llvm::Triple::TvOS:
>> -  Platform = DarwinPlatformKind::TvOS;
>> -  break;
>> +  return DarwinPlatformKind::TvOS;
>>  case llvm::Triple::WatchOS:
>> -  Platform = DarwinPlatformKind::WatchOS;
>> -  break;
>> +  return DarwinPlatformKind::WatchOS;
>>  default:
>>llvm_unreachable("Unable to infer Darwin variant");
>>  }
>> -return DarwinPlatform(InferredFromArch, Platform, Value);
>>}
>>
>> -private:
>> -  DarwinPlatform(SourceKind Kind, DarwinPlatformKind Platform, Arg
>> *Argument)
>> -  : Kind(Kind), Platform(Platform), Argument(Argument) {}
>> -  DarwinPlatform(SourceKind Kind, DarwinPlatformKind Platform, StringRef
>> Value)
>> -  : Kind(Kind), Platform(Platform), OSVersion(Value),
>> Argument(nullptr) {}
>> -
>>SourceKind Kind;
>>DarwinPlatformKind Platform;
>>std::string OSVersion;
>> @@ -1449,20 +1452,15 @@ inferDeploymentTargetFromArch(DerivedArg
>>const Driver &TheDriver) {
>>llvm::Triple::OSType OSTy = llvm::Triple::Unknow

Re: r321099 - [driver][darwin] Take the OS version specified in "-target" as the target

2017-12-21 Thread James Y Knight via cfe-commits
I totally agree with moving towards eliminating the -m-version-min
flags, it's much better to put it in the target, and will clean up a lot of
cruft in the driver, eventually.

Now -- we (or anyone else who runs into this) can simply start specifying
the version in both locations ("-target x86_64-apple-ios10
-mios-simulator-version-min=10"), so as to work with both new and old
clang, and be closer to the ultimate goal of having only -target. That's an
overall nicer workaround to suggest than switching to -darwin. But, yea,
there's no need for *temporary* patch to fix things just for us.

However, I do not understand why you're against committing the patch you
mention as option #2 -- that seems like it'd be best for all users, by
preserving compatibility with existing command-lines. So, I'd still like
that change to be committed, permanently, not temporarily. I'm sure we
can't be the only ones running clang like "-target x86_64-apple-ios
-mios-simulator-version-min=10", and it seems unfortunate and unnecessary
to break that, even if it can be worked around.

In the future, I'd hope the -m-version-min arguments can be deprecated
more and more -- warning whenever you use them to modify the platform or
version at all, rather just on specification conflict; then, warn anytime
you use them at all; then, remove them. But in the meantime, it seems
strictly better to preserve compatibility, don't you think?



On Dec 21, 2017 2:11 PM, "Alex L"  wrote:

Thanks for raising your concerns.

We decided to avoid -m-version-min flag in favor of -target to simplify
the driver logic and to encourage the adoption of -target. Now after r321145
we only warn about -m-version-min flag when the OS version specified in
it is different to the OS version specified in target, or when target has
no OS version.

There are two possible solutions here:
1) You can still use -target with -mios-simulator-version-min as before but
you'd have to use '-target=x86_64-apple-darwin' to ensure that the iOS
version specified by  '-mios-simulator-version-min' is used.
2) I also do have a patch that implements the logic that you propose (use
the OS version in -m-version-min flag if target has none). If you
believe that the first solution is not suitable for your code then I can
commit it. At the same time I believe that we would rather not use this
patch, but if it's urgent for your projects then maybe I can land it now
and then we can establish some sort of timeline for when it can be reverted?

Thanks,
Alex


On 21 December 2017 at 08:00, James Y Knight  wrote:

> I think if a version number isn't explicitly specified in the -target
> value, the value from -m-version-min ought to still be used, as
> it was before.
>
> Currently, clang will ignore the -m-version-min version number
> if the target has a particular OS specified, even if it has no version
> number as part of it.
>
> (We should be able to workaround this change backwards-compatibly by
> specifying in both the -target argument and in the -m-version-min
> arguments, but I do think the behavior should be fixed.)
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r344110 - ExprConstant: Make __builtin_object_size use EM_IgnoreSideEffects.

2018-10-09 Thread James Y Knight via cfe-commits
Author: jyknight
Date: Tue Oct  9 19:53:43 2018
New Revision: 344110

URL: http://llvm.org/viewvc/llvm-project?rev=344110&view=rev
Log:
ExprConstant: Make __builtin_object_size use EM_IgnoreSideEffects.

And, since EM_OffsetFold is now unused, remove it.

While builtin_object_size intends to ignore the presence of
side-effects in its argument, the EM_OffsetFold mode was NOT
configured to ignore side-effects. Rather it was effectively identical
to EM_ConstantFold -- its explanatory comment
notwithstanding.

However, currently, keepEvaluatingAfterSideEffect() is not always
honored -- sometimes evaluation continues despite it returning
false. Therefore, since the b_o_s code was only checking the return
value from evaluation, and not additionally checking the
HasSideEffects flag, side-effects _were_ in many cases actually being
ignored.

This change is a prerequisite cleanup towards fixing that issue.

Differential Revision: https://reviews.llvm.org/D52924

Modified:
cfe/trunk/lib/AST/ExprConstant.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=344110&r1=344109&r2=344110&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Tue Oct  9 19:53:43 2018
@@ -759,18 +759,6 @@ namespace {
   /// context we try to fold them immediately since the optimizer never
   /// gets a chance to look at it.
   EM_PotentialConstantExpressionUnevaluated,
-
-  /// Evaluate as a constant expression. In certain scenarios, if:
-  /// - we find a MemberExpr with a base that can't be evaluated, or
-  /// - we find a variable initialized with a call to a function that has
-  ///   the alloc_size attribute on it
-  /// then we may consider evaluation to have succeeded.
-  ///
-  /// In either case, the LValue returned shall have an invalid base; in 
the
-  /// former, the base will be the invalid MemberExpr, in the latter, the
-  /// base will be either the alloc_size CallExpr or a CastExpr wrapping
-  /// said CallExpr.
-  EM_OffsetFold,
 } EvalMode;
 
 /// Are we checking whether the expression is a potential constant
@@ -874,7 +862,6 @@ namespace {
   case EM_PotentialConstantExpression:
   case EM_ConstantExpressionUnevaluated:
   case EM_PotentialConstantExpressionUnevaluated:
-  case EM_OffsetFold:
 HasActiveDiagnostic = false;
 return OptionalDiagnostic();
   }
@@ -966,7 +953,6 @@ namespace {
   case EM_ConstantExpression:
   case EM_ConstantExpressionUnevaluated:
   case EM_ConstantFold:
-  case EM_OffsetFold:
 return false;
   }
   llvm_unreachable("Missed EvalMode case");
@@ -985,7 +971,6 @@ namespace {
   case EM_EvaluateForOverflow:
   case EM_IgnoreSideEffects:
   case EM_ConstantFold:
-  case EM_OffsetFold:
 return true;
 
   case EM_PotentialConstantExpression:
@@ -1021,7 +1006,6 @@ namespace {
   case EM_ConstantExpressionUnevaluated:
   case EM_ConstantFold:
   case EM_IgnoreSideEffects:
-  case EM_OffsetFold:
 return false;
   }
   llvm_unreachable("Missed EvalMode case");
@@ -1093,18 +1077,18 @@ namespace {
 }
   };
 
-  /// RAII object used to treat the current evaluation as the correct pointer
-  /// offset fold for the current EvalMode
-  struct FoldOffsetRAII {
+  /// RAII object used to set the current evaluation mode to ignore
+  /// side-effects.
+  struct IgnoreSideEffectsRAII {
 EvalInfo &Info;
 EvalInfo::EvaluationMode OldMode;
-explicit FoldOffsetRAII(EvalInfo &Info)
+explicit IgnoreSideEffectsRAII(EvalInfo &Info)
 : Info(Info), OldMode(Info.EvalMode) {
   if (!Info.checkingPotentialConstantExpression())
-Info.EvalMode = EvalInfo::EM_OffsetFold;
+Info.EvalMode = EvalInfo::EM_IgnoreSideEffects;
 }
 
-~FoldOffsetRAII() { Info.EvalMode = OldMode; }
+~IgnoreSideEffectsRAII() { Info.EvalMode = OldMode; }
   };
 
   /// RAII object used to optionally suppress diagnostics and side-effects from
@@ -8049,7 +8033,7 @@ static bool tryEvaluateBuiltinObjectSize
 // If there are any, but we can determine the pointed-to object anyway, 
then
 // ignore the side-effects.
 SpeculativeEvaluationRAII SpeculativeEval(Info);
-FoldOffsetRAII Fold(Info);
+IgnoreSideEffectsRAII Fold(Info);
 
 if (E->isGLValue()) {
   // It's possible for us to be given GLValues if we're called via
@@ -8117,7 +8101,6 @@ bool IntExprEvaluator::VisitBuiltinCallE
 case EvalInfo::EM_ConstantFold:
 case EvalInfo::EM_EvaluateForOverflow:
 case EvalInfo::EM_IgnoreSideEffects:
-case EvalInfo::EM_OffsetFold:
   // Leave it to IR generation.
   return Error(E);
 case EvalInfo::EM_ConstantExpressionUnevaluated:


_

r351200 - Remove irrelevant references to legacy git repositories from

2019-01-15 Thread James Y Knight via cfe-commits
Author: jyknight
Date: Tue Jan 15 08:18:52 2019
New Revision: 351200

URL: http://llvm.org/viewvc/llvm-project?rev=351200&view=rev
Log:
Remove irrelevant references to legacy git repositories from
compiler identification lines in test-cases.

(Doing so only because it's then easier to search for references which
are actually important and need fixing.)

Modified:

cfe/trunk/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-diagnostics-taint-test.c.sarif

Modified: 
cfe/trunk/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-diagnostics-taint-test.c.sarif
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-diagnostics-taint-test.c.sarif?rev=351200&r1=351199&r2=351200&view=diff
==
--- 
cfe/trunk/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-diagnostics-taint-test.c.sarif
 (original)
+++ 
cfe/trunk/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-diagnostics-taint-test.c.sarif
 Tue Jan 15 08:18:52 2019
@@ -106,7 +106,7 @@
 "fullName": "clang static analyzer",
 "language": "en-US",
 "name": "clang",
-"version": "clang version 8.0.0 
(https://github.com/llvm-project/clang.git 
a5ccb257a7a70928ede717a7c282f5fc8cbed310) 
(https://github.com/llvm-mirror/llvm.git 
73cebd79c512f7129eca16b0f3a7abd21d2881e8)"
+"version": "clang version 8.0.0"
   }
 }
   ],


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


[clang-tools-extra] r352514 - Adjust documentation for git migration.

2019-01-29 Thread James Y Knight via cfe-commits
Author: jyknight
Date: Tue Jan 29 08:37:27 2019
New Revision: 352514

URL: http://llvm.org/viewvc/llvm-project?rev=352514&view=rev
Log:
Adjust documentation for git migration.

This fixes most references to the paths:
 llvm.org/svn/
 llvm.org/git/
 llvm.org/viewvc/
 github.com/llvm-mirror/
 github.com/llvm-project/
 reviews.llvm.org/diffusion/

to instead point to https://github.com/llvm/llvm-project.

This is *not* a trivial substitution, because additionally, all the
checkout instructions had to be migrated to instruct users on how to
use the monorepo layout, setting LLVM_ENABLE_PROJECTS instead of
checking out various projects into various subdirectories.

I've attempted to not change any scripts here, only documentation. The
scripts will have to be addressed separately.

Additionally, I've deleted one document which appeared to be outdated
and unneeded:
  lldb/docs/building-with-debug-llvm.txt

Differential Revision: https://reviews.llvm.org/D57330

Modified:
clang-tools-extra/trunk/docs/clang-rename.rst
clang-tools-extra/trunk/docs/clang-tidy/Contributing.rst
clang-tools-extra/trunk/docs/clang-tidy/Integrations.rst

Modified: clang-tools-extra/trunk/docs/clang-rename.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-rename.rst?rev=352514&r1=352513&r2=352514&view=diff
==
--- clang-tools-extra/trunk/docs/clang-rename.rst (original)
+++ clang-tools-extra/trunk/docs/clang-rename.rst Tue Jan 29 08:37:27 2019
@@ -139,8 +139,8 @@ Vim Integration
 
 You can call :program:`clang-rename` directly from Vim! To set up
 :program:`clang-rename` integration for Vim see
-`clang-rename/tool/clang-rename.py
-`_.
+`clang/tools/clang-rename/clang-rename.py
+`_.
 
 Please note that **you have to save all buffers, in which the replacement will
 happen before running the tool**.
@@ -157,7 +157,7 @@ Emacs Integration
 You can also use :program:`clang-rename` while using Emacs! To set up
 :program:`clang-rename` integration for Emacs see
 `clang-rename/tool/clang-rename.el
-`_.
+`_.
 
 Once installed, you can point your cursor to symbols you want to rename, press
 `M-X`, type `clang-rename` and new desired name.

Modified: clang-tools-extra/trunk/docs/clang-tidy/Contributing.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/Contributing.rst?rev=352514&r1=352513&r2=352514&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/Contributing.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/Contributing.rst Tue Jan 29 
08:37:27 2019
@@ -127,7 +127,7 @@ style used in the project. For code revi
 
 Next, you need to decide which module the check belongs to. Modules
 are located in subdirectories of `clang-tidy/
-`_
+`_
 and contain checks targeting a certain aspect of code quality (performance,
 readability, etc.), certain coding style or standard (Google, LLVM, CERT, etc.)
 or a widely used API (e.g. MPI). Their names are same as user-facing check
@@ -210,7 +210,7 @@ can further inspect them and report diag
 
 (If you want to see an example of a useful check, look at
 `clang-tidy/google/ExplicitConstructorCheck.h
-`_
+`_
 and `clang-tidy/google/ExplicitConstructorCheck.cpp
 
`_).
 

Modified: clang-tools-extra/trunk/docs/clang-tidy/Integrations.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/Integrations.rst?rev=352514&r1=352513&r2=352514&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/Integrations.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/Integrations.rst Tue Jan 29 
08:37:27 2019
@@ -75,7 +75,7 @@ choose the checks to be performed in the
 .. _ReSharper C++: 
https://www.jetbrains.com/help/resharper/Clang_Tidy_Integration.html
 .. _Visual Assist: https://docs.wholetomato.com/default.asp?W761
 .. _Clang Power Tools: 
https://marketplace.visualstudio.com/items?itemName=caphyon.ClangP

r352514 - Adjust documentation for git migration.

2019-01-29 Thread James Y Knight via cfe-commits
Author: jyknight
Date: Tue Jan 29 08:37:27 2019
New Revision: 352514

URL: http://llvm.org/viewvc/llvm-project?rev=352514&view=rev
Log:
Adjust documentation for git migration.

This fixes most references to the paths:
 llvm.org/svn/
 llvm.org/git/
 llvm.org/viewvc/
 github.com/llvm-mirror/
 github.com/llvm-project/
 reviews.llvm.org/diffusion/

to instead point to https://github.com/llvm/llvm-project.

This is *not* a trivial substitution, because additionally, all the
checkout instructions had to be migrated to instruct users on how to
use the monorepo layout, setting LLVM_ENABLE_PROJECTS instead of
checking out various projects into various subdirectories.

I've attempted to not change any scripts here, only documentation. The
scripts will have to be addressed separately.

Additionally, I've deleted one document which appeared to be outdated
and unneeded:
  lldb/docs/building-with-debug-llvm.txt

Differential Revision: https://reviews.llvm.org/D57330

Modified:
cfe/trunk/.gitignore
cfe/trunk/docs/ClangPlugins.rst
cfe/trunk/docs/ClangTools.rst
cfe/trunk/docs/ControlFlowIntegrityDesign.rst
cfe/trunk/docs/InternalsManual.rst
cfe/trunk/docs/LibASTMatchersTutorial.rst
cfe/trunk/docs/LibTooling.rst
cfe/trunk/docs/Toolchain.rst
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/www/analyzer/checker_dev_manual.html
cfe/trunk/www/get_started.html
cfe/trunk/www/hacking.html
cfe/trunk/www/menu.html.incl

Modified: cfe/trunk/.gitignore
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/.gitignore?rev=352514&r1=352513&r2=352514&view=diff
==
--- cfe/trunk/.gitignore (original)
+++ cfe/trunk/.gitignore Tue Jan 29 08:37:27 2019
@@ -1,9 +1,6 @@
 
#==#
 # This file specifies intentionally untracked files that git should ignore.
 # See: http://www.kernel.org/pub/software/scm/git/docs/gitignore.html
-#
-# This file is intentionally different from the output of `git svn 
show-ignore`,
-# as most of those are useless.
 
#==#
 
 
#==#

Modified: cfe/trunk/docs/ClangPlugins.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangPlugins.rst?rev=352514&r1=352513&r2=352514&view=diff
==
--- cfe/trunk/docs/ClangPlugins.rst (original)
+++ cfe/trunk/docs/ClangPlugins.rst Tue Jan 29 08:37:27 2019
@@ -69,7 +69,7 @@ Putting it all together
 Let's look at an example plugin that prints top-level function names.  This
 example is checked into the clang repository; please take a look at
 the `latest version of PrintFunctionNames.cpp
-`_.
+`_.
 
 Running the plugin
 ==
@@ -110,7 +110,7 @@ source tree:
 -plugin -Xclang print-fns
 
 Also see the print-function-name plugin example's
-`README 
`_
+`README 
`_
 
 
 Using the clang command line

Modified: cfe/trunk/docs/ClangTools.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangTools.rst?rev=352514&r1=352513&r2=352514&view=diff
==
--- cfe/trunk/docs/ClangTools.rst (original)
+++ cfe/trunk/docs/ClangTools.rst Tue Jan 29 08:37:27 2019
@@ -9,22 +9,9 @@ functionality such as fast syntax checki
 refactoring, etc.
 
 Only a couple of the most basic and fundamental tools are kept in the
-primary Clang Subversion project. The rest of the tools are kept in a
-side-project so that developers who don't want or need to build them
-don't. If you want to get access to the extra Clang Tools repository,
-simply check it out into the tools tree of your Clang checkout and
-follow the usual process for building and working with a combined
-LLVM/Clang checkout:
-
--  With Subversion:
-
-   -  ``cd llvm/tools/clang/tools``
-   -  ``svn co https://llvm.org/svn/llvm-project/clang-tools-extra/trunk 
extra``
-
--  Or with Git:
-
-   -  ``cd llvm/tools/clang/tools``
-   -  ``git clone https://llvm.org/git/clang-tools-extra.git extra``
+primary Clang tree. The rest of the tools are kept in a separate
+directory tree, ``clang-tools-extra
+``_.
 
 This document describes a high-level overview of the organization of
 Clang Tools within the project as well as giving an introduction to some

Modified: c

[libclc] r352514 - Adjust documentation for git migration.

2019-01-29 Thread James Y Knight via cfe-commits
Author: jyknight
Date: Tue Jan 29 08:37:27 2019
New Revision: 352514

URL: http://llvm.org/viewvc/llvm-project?rev=352514&view=rev
Log:
Adjust documentation for git migration.

This fixes most references to the paths:
 llvm.org/svn/
 llvm.org/git/
 llvm.org/viewvc/
 github.com/llvm-mirror/
 github.com/llvm-project/
 reviews.llvm.org/diffusion/

to instead point to https://github.com/llvm/llvm-project.

This is *not* a trivial substitution, because additionally, all the
checkout instructions had to be migrated to instruct users on how to
use the monorepo layout, setting LLVM_ENABLE_PROJECTS instead of
checking out various projects into various subdirectories.

I've attempted to not change any scripts here, only documentation. The
scripts will have to be addressed separately.

Additionally, I've deleted one document which appeared to be outdated
and unneeded:
  lldb/docs/building-with-debug-llvm.txt

Differential Revision: https://reviews.llvm.org/D57330

Modified:
libclc/trunk/www/index.html

Modified: libclc/trunk/www/index.html
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/www/index.html?rev=352514&r1=352513&r2=352514&view=diff
==
--- libclc/trunk/www/index.html (original)
+++ libclc/trunk/www/index.html Tue Jan 29 08:37:27 2019
@@ -43,9 +43,7 @@ support for more targets is welcome.
 
 Download
 
-svn checkout http://llvm.org/svn/llvm-project/libclc/trunk libclc (http://llvm.org/viewvc/llvm-project/libclc/trunk/";>ViewVC)
-- or -
-git clone http://llvm.org/git/libclc.git
+git clone https://github.com/llvm/llvm-project.git (https://github.com/llvm/llvm-project/tree/libclc";>View sources)
 
 Mailing List
 


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


[libunwind] r352514 - Adjust documentation for git migration.

2019-01-29 Thread James Y Knight via cfe-commits
Author: jyknight
Date: Tue Jan 29 08:37:27 2019
New Revision: 352514

URL: http://llvm.org/viewvc/llvm-project?rev=352514&view=rev
Log:
Adjust documentation for git migration.

This fixes most references to the paths:
 llvm.org/svn/
 llvm.org/git/
 llvm.org/viewvc/
 github.com/llvm-mirror/
 github.com/llvm-project/
 reviews.llvm.org/diffusion/

to instead point to https://github.com/llvm/llvm-project.

This is *not* a trivial substitution, because additionally, all the
checkout instructions had to be migrated to instruct users on how to
use the monorepo layout, setting LLVM_ENABLE_PROJECTS instead of
checking out various projects into various subdirectories.

I've attempted to not change any scripts here, only documentation. The
scripts will have to be addressed separately.

Additionally, I've deleted one document which appeared to be outdated
and unneeded:
  lldb/docs/building-with-debug-llvm.txt

Differential Revision: https://reviews.llvm.org/D57330

Modified:
libunwind/trunk/docs/BuildingLibunwind.rst
libunwind/trunk/docs/index.rst

Modified: libunwind/trunk/docs/BuildingLibunwind.rst
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/docs/BuildingLibunwind.rst?rev=352514&r1=352513&r2=352514&view=diff
==
--- libunwind/trunk/docs/BuildingLibunwind.rst (original)
+++ libunwind/trunk/docs/BuildingLibunwind.rst Tue Jan 29 08:37:27 2019
@@ -18,16 +18,10 @@ edge), read on.
 
 The basic steps needed to build libc++ are:
 
-#. Checkout LLVM:
+#. Checkout LLVM, libunwind, and related projects:
 
* ``cd where-you-want-llvm-to-live``
-   * ``svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm``
-
-#. Checkout libunwind:
-
-   * ``cd where-you-want-llvm-to-live``
-   * ``cd llvm/runtimes``
-   * ``svn co http://llvm.org/svn/llvm-project/libunwind/trunk libunwind``
+   * ``git clone https://github.com/llvm/llvm-project.git``
 
 #. Configure and build libunwind:
 
@@ -38,7 +32,7 @@ The basic steps needed to build libc++ a
* ``cd where you want to build llvm``
* ``mkdir build``
* ``cd build``
-   * ``cmake -G  [options] ``
+   * ``cmake -G  -DLLVM_ENABLE_PROJECTS=libunwind [options] ``
 
For more information about configuring libunwind see :ref:`CMake Options`.
 

Modified: libunwind/trunk/docs/index.rst
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/docs/index.rst?rev=352514&r1=352513&r2=352514&view=diff
==
--- libunwind/trunk/docs/index.rst (original)
+++ libunwind/trunk/docs/index.rst Tue Jan 29 08:37:27 2019
@@ -101,5 +101,4 @@ Quick Links
 * `LLVM Bugzilla `_
 * `cfe-commits Mailing List`_
 * `cfe-dev Mailing List`_
-* `Browse libunwind -- SVN 
`_
-* `Browse libunwind -- ViewVC 
`_
+* `Browse libunwind Sources 
`_


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


r352535 - Fix the behavior of clang's -w flag.

2019-01-29 Thread James Y Knight via cfe-commits
Author: jyknight
Date: Tue Jan 29 11:33:48 2019
New Revision: 352535

URL: http://llvm.org/viewvc/llvm-project?rev=352535&view=rev
Log:
Fix the behavior of clang's -w flag.

It is intended to disable _all_ warnings, even those upgraded to
errors via `-Werror=warningname` or `#pragma clang diagnostic error'

Fixes: https://llvm.org/PR38231
Differential Revision: https://reviews.llvm.org/D53199

Added:
cfe/trunk/test/Frontend/warning-mapping-6.c
Modified:
cfe/trunk/lib/Basic/DiagnosticIDs.cpp
cfe/trunk/test/Frontend/optimization-remark.c
cfe/trunk/test/Frontend/warning-mapping-2.c
cfe/trunk/test/Frontend/warning-mapping-4.c
cfe/trunk/test/Frontend/warning-mapping-5.c
cfe/trunk/test/Modules/implementation-of-module.m

Modified: cfe/trunk/lib/Basic/DiagnosticIDs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/DiagnosticIDs.cpp?rev=352535&r1=352534&r2=352535&view=diff
==
--- cfe/trunk/lib/Basic/DiagnosticIDs.cpp (original)
+++ cfe/trunk/lib/Basic/DiagnosticIDs.cpp Tue Jan 29 11:33:48 2019
@@ -456,12 +456,17 @@ DiagnosticIDs::getDiagnosticSeverity(uns
   if (Result == diag::Severity::Ignored)
 return Result;
 
-  // Honor -w, which is lower in priority than pedantic-errors, but higher than
-  // -Werror.
-  // FIXME: Under GCC, this also suppresses warnings that have been mapped to
-  // errors by -W flags and #pragma diagnostic.
-  if (Result == diag::Severity::Warning && State->IgnoreAllWarnings)
-return diag::Severity::Ignored;
+  // Honor -w: this disables all messages which which are not Error/Fatal by
+  // default (disregarding attempts to upgrade severity from Warning to Error),
+  // as well as disabling all messages which are currently mapped to Warning
+  // (whether by default or downgraded from Error via e.g. -Wno-error or 
#pragma
+  // diagnostic.)
+  if (State->IgnoreAllWarnings) {
+if (Result == diag::Severity::Warning ||
+(Result >= diag::Severity::Error &&
+ !isDefaultMappingAsError((diag::kind)DiagID)))
+  return diag::Severity::Ignored;
+  }
 
   // If -Werror is enabled, map warnings to errors unless explicitly disabled.
   if (Result == diag::Severity::Warning) {

Modified: cfe/trunk/test/Frontend/optimization-remark.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/optimization-remark.c?rev=352535&r1=352534&r2=352535&view=diff
==
--- cfe/trunk/test/Frontend/optimization-remark.c (original)
+++ cfe/trunk/test/Frontend/optimization-remark.c Tue Jan 29 11:33:48 2019
@@ -13,6 +13,9 @@
 // RUN: %clang_cc1 %s -Rpass=inline -Rno-everything -emit-llvm -o - 2>&1 | 
FileCheck %s --check-prefix=CHECK-NO-REMARKS
 // RUN: %clang_cc1 %s -Rpass=inline -Rno-everything -Reverything -emit-llvm -o 
- 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS
 //
+// Check that -w doesn't disable remarks.
+// RUN: %clang_cc1 %s -Rpass=inline -w -emit-llvm -o - 2>&1 | FileCheck %s 
--check-prefix=CHECK-REMARKS
+//
 // FIXME: -Reverything should imply -Rpass=.*.
 // RUN: %clang_cc1 %s -Reverything -emit-llvm -o - 2>/dev/null | FileCheck %s 
--check-prefix=CHECK-NO-REMARKS
 //

Modified: cfe/trunk/test/Frontend/warning-mapping-2.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/warning-mapping-2.c?rev=352535&r1=352534&r2=352535&view=diff
==
--- cfe/trunk/test/Frontend/warning-mapping-2.c (original)
+++ cfe/trunk/test/Frontend/warning-mapping-2.c Tue Jan 29 11:33:48 2019
@@ -1,5 +1,7 @@
-// Check that -w has lower priority than -pedantic-errors.
+// Check that -w takes precedence over -pedantic-errors.
 // RUN: %clang_cc1 -verify -pedantic-errors -w %s
 
-void f0() { f1(); } // expected-error {{implicit declaration of function}}
+// Expect *not* to see a diagnostic for "implicit declaration of function"
+// expected-no-diagnostics
 
+void f0() { f1(); }

Modified: cfe/trunk/test/Frontend/warning-mapping-4.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/warning-mapping-4.c?rev=352535&r1=352534&r2=352535&view=diff
==
--- cfe/trunk/test/Frontend/warning-mapping-4.c (original)
+++ cfe/trunk/test/Frontend/warning-mapping-4.c Tue Jan 29 11:33:48 2019
@@ -1,5 +1,9 @@
+// Verify that various combinations of flags properly keep the sign-compare
+// warning disabled.
+
 // RUN: %clang_cc1 -verify -Wno-error=sign-compare %s
 // RUN: %clang_cc1 -verify -Wsign-compare -w -Wno-error=sign-compare %s
+// RUN: %clang_cc1 -verify -w -Werror=sign-compare %s
 // expected-no-diagnostics
 
 int f0(int x, unsigned y) {

Modified: cfe/trunk/test/Frontend/warning-mapping-5.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/warning-mapping-5.c?rev=352535&r1=352534&r2=352535&view=diff
=

r352595 - Cleanup: replace uses of CallSite with CallBase.

2019-01-29 Thread James Y Knight via cfe-commits
Author: jyknight
Date: Tue Jan 29 18:54:28 2019
New Revision: 352595

URL: http://llvm.org/viewvc/llvm-project?rev=352595&view=rev
Log:
Cleanup: replace uses of CallSite with CallBase.

Modified:
cfe/trunk/lib/CodeGen/CGBlocks.cpp
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/CodeGen/CGCUDANV.cpp
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/CGException.cpp
cfe/trunk/lib/CodeGen/CGExprCXX.cpp
cfe/trunk/lib/CodeGen/CGExprComplex.cpp
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
cfe/trunk/lib/CodeGen/CGObjCMac.cpp
cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
cfe/trunk/lib/CodeGen/CGStmt.cpp
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/lib/CodeGen/CGVTables.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=352595&r1=352594&r2=352595&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Tue Jan 29 18:54:28 2019
@@ -22,7 +22,6 @@
 #include "clang/AST/DeclObjC.h"
 #include "clang/CodeGen/ConstantInitBuilder.h"
 #include "llvm/ADT/SmallSet.h"
-#include "llvm/IR/CallSite.h"
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/Module.h"
 #include "llvm/Support/ScopedPrinter.h"

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=352595&r1=352594&r2=352595&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Tue Jan 29 18:54:28 2019
@@ -26,7 +26,6 @@
 #include "clang/CodeGen/CGFunctionInfo.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/StringExtras.h"
-#include "llvm/IR/CallSite.h"
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/InlineAsm.h"
 #include "llvm/IR/Intrinsics.h"
@@ -799,9 +798,9 @@ static RValue EmitMSVCRTSetJmp(CodeGenFu
   llvm::Value *Buf = CGF.Builder.CreateBitOrPointerCast(
   CGF.EmitScalarExpr(E->getArg(0)), CGF.Int8PtrTy);
   llvm::Value *Args[] = {Buf, Arg1};
-  llvm::CallSite CS = CGF.EmitRuntimeCallOrInvoke(SetJmpFn, Args);
-  CS.setAttributes(ReturnsTwiceAttr);
-  return RValue::get(CS.getInstruction());
+  llvm::CallBase *CB = CGF.EmitRuntimeCallOrInvoke(SetJmpFn, Args);
+  CB->setAttributes(ReturnsTwiceAttr);
+  return RValue::get(CB);
 }
 
 // Many of MSVC builtins are on x64, ARM and AArch64; to avoid repeating code,
@@ -1002,9 +1001,9 @@ Value *CodeGenFunction::EmitMSVCBuiltinE
 llvm::AttributeList NoReturnAttr = llvm::AttributeList::get(
 getLLVMContext(), llvm::AttributeList::FunctionIndex,
 llvm::Attribute::NoReturn);
-CallSite CS = Builder.CreateCall(IA, EmitScalarExpr(E->getArg(0)));
-CS.setAttributes(NoReturnAttr);
-return CS.getInstruction();
+llvm::CallInst *CI = Builder.CreateCall(IA, EmitScalarExpr(E->getArg(0)));
+CI->setAttributes(NoReturnAttr);
+return CI;
   }
   }
   llvm_unreachable("Incorrect MSVC intrinsic!");
@@ -11851,9 +11850,9 @@ Value *CodeGenFunction::EmitX86BuiltinEx
 llvm::AttributeList NoReturnAttr = llvm::AttributeList::get(
 getLLVMContext(), llvm::AttributeList::FunctionIndex,
 llvm::Attribute::NoReturn);
-CallSite CS = Builder.CreateCall(IA);
-CS.setAttributes(NoReturnAttr);
-return CS.getInstruction();
+llvm::CallInst *CI = Builder.CreateCall(IA);
+CI->setAttributes(NoReturnAttr);
+return CI;
   }
   case X86::BI__readfsbyte:
   case X86::BI__readfsword:

Modified: cfe/trunk/lib/CodeGen/CGCUDANV.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCUDANV.cpp?rev=352595&r1=352594&r2=352595&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCUDANV.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCUDANV.cpp Tue Jan 29 18:54:28 2019
@@ -17,7 +17,6 @@
 #include "clang/AST/Decl.h"
 #include "clang/CodeGen/ConstantInitBuilder.h"
 #include "llvm/IR/BasicBlock.h"
-#include "llvm/IR/CallSite.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/Format.h"
@@ -208,11 +207,11 @@ void CGNVCUDARuntime::emitDeviceStubBody
 llvm::ConstantInt::get(SizeTy, TyWidth.getQuantity()),
 llvm::ConstantInt::get(SizeTy, Offset.getQuantity()),
 };
-llvm::CallSite CS = CGF.EmitRuntimeCallOrInvoke(cudaSetupArgFn, Args);
+llvm::CallBase *CB = CGF.EmitRuntimeCallOrInvoke(cudaSetupArgFn, Args);
 llvm::Constant *Zero = llvm::ConstantInt::get(IntTy, 0);
-llvm::Value *CSZero = CGF.

r352791 - [opaque pointer types] Add a FunctionCallee wrapper type, and use it.

2019-01-31 Thread James Y Knight via cfe-commits
Author: jyknight
Date: Thu Jan 31 12:35:56 2019
New Revision: 352791

URL: http://llvm.org/viewvc/llvm-project?rev=352791&view=rev
Log:
[opaque pointer types] Add a FunctionCallee wrapper type, and use it.

The FunctionCallee type is effectively a {FunctionType*,Value*} pair,
and is a useful convenience to enable code to continue passing the
result of getOrInsertFunction() through to EmitCall, even once pointer
types lose their pointee-type.

Then:
- update the CallInst/InvokeInst instruction creation functions to
  take a Callee,
- modify getOrInsertFunction to return FunctionCallee, and
- update all callers appropriately.

One area of particular note is the change to the sanitizer
code. Previously, they had been casting the result of
`getOrInsertFunction` to a `Function*` via
`checkSanitizerInterfaceFunction`, and storing that. That would report
an error if someone had already inserted a function declaraction with
a mismatching signature.

However, in general, LLVM allows for such mismatches, as
`getOrInsertFunction` will automatically insert a bitcast if
needed. As part of this cleanup, cause the sanitizer code to do the
same. (It will call its functions using the expected signature,
however they may have been declared.)

Finally, in a small number of locations, callers of
`getOrInsertFunction` actually were expecting/requiring that a brand
new function was being created. In such cases, I've switched them to
Function::Create instead.

Differential Revision: https://reviews.llvm.org/D57315

Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=352791&r1=352790&r2=352791&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Thu Jan 31 12:35:56 2019
@@ -3056,7 +3056,7 @@ void CodeGenFunction::EmitCfiSlowPathChe
   bool WithDiag = !CGM.getCodeGenOpts().SanitizeTrap.has(Kind);
 
   llvm::CallInst *CheckCall;
-  llvm::Constant *SlowPathFn;
+  llvm::FunctionCallee SlowPathFn;
   if (WithDiag) {
 llvm::Constant *Info = llvm::ConstantStruct::getAnon(StaticArgs);
 auto *InfoPtr =
@@ -3078,7 +3078,8 @@ void CodeGenFunction::EmitCfiSlowPathChe
 CheckCall = Builder.CreateCall(SlowPathFn, {TypeId, Ptr});
   }
 
-  CGM.setDSOLocal(cast(SlowPathFn->stripPointerCasts()));
+  CGM.setDSOLocal(
+  cast(SlowPathFn.getCallee()->stripPointerCasts()));
   CheckCall->setDoesNotThrow();
 
   EmitBlock(Cont);


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


Re: [cfe-dev] r347339 - [clang][Parse] Diagnose useless null statements / empty init-statements

2018-12-05 Thread James Y Knight via cfe-commits
Nobody should be using "-Weverything" in their default build flags! It
should only be used as a way to find the names of interesting warning
flags. I'd note that "-Weverything" even has warnings that _conflict_ with
each-other...

It's unworkable for clang to have a policy which prevents the addition of
new warning options just because someone enables -Weverything... If people
feel like that is what's happening now, we need to fix that. If that's what
it comes to, even deleting the -Weverything flag would be better.

The question I'd ask for new warnings is a different one: is this warning
something which people could feasibly decide to *opt into*, with -Werror,
for their entire project? This does appear to meet that criteria -- the
cases where it warns do appear to be indicating potential issues, and the
code fix which silences the warning will improve the code, not make it
worse.

On Wed, Dec 5, 2018 at 2:51 PM Aaron Ballman via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> On Wed, Dec 5, 2018 at 2:14 PM Alex L via cfe-commits
>  wrote:
> >
> > We have about 100k unique occurrences of this warning across a slice of
> our software stack. It's simply not feasible to us to adopt it, so we would
> prefer for it to be reverted to avoid downstream divergence in Apple's
> clang. Granted, these occur in projects that use -Weverything but those
> projects are typically understanding of warnings that they can turn off
> when they see that they provide useful value in terms of warnings about
> unintended behavior that's sometimes caught. This warning doesn't seem to
> catch unintended bugs and it would be a heroic battle to adopt it for us in
> a way where projects are somewhat satisfied. It seems to be a better fit
> for a clang-tidy check that could suggest automatic fixits and that the
> users could run on their codebase to "modernize" if they want to.
>
> I'm not certain I agree that this does not catch unintended bugs.
> After all, it started a discussion that pointed out design issues with
> two different macros which were provided as examples of
> false-positives. I think this diagnostic points out bad code smells
> and is no more stylistic than some of the other diagnostics in
> -Weverything, like not having a previous prototype before defining a
> function. I am not sold on the idea that this diagnostic should be
> moved into clang-tidy simply because it's showing up in a lot of
> -Weverything builds.
>
> ~Aaron
>
> >
> > Cheers,
> > Alex
> >
> > On Wed, 5 Dec 2018 at 10:43, Richard Smith via cfe-dev <
> cfe-...@lists.llvm.org> wrote:
> >>
> >> On Wed, 5 Dec 2018, 10:01 George Karpenkov via cfe-commits <
> cfe-commits@lists.llvm.org wrote:
> >>>
> >>> These are the cases I get:
> >>>
> >>> #define unexpected(a) { kprintf("unexpected %s:%d\n", __FILE__,
> __LINE__); a; }
> >>>
> >>> and
> >>>
> >>> #if 0
> >>> #define DEBG(fmt, args...)  { IOLog(fmt, ## args); kprintf(fmt, ##
> args); }
> >>> #else
> >>> #define DEBG(fmt, args...)  {}
> >>> #endif
> >>>
> >>> Now calls
> >>>
> >>> `DEBG(‘x’);` and `unexpected(‘msg’);`
> >>>
> >>> cause the warning to be fired.
> >>> Of course, semicolon could be omitted, but the fact that the macro has
> braces is sort of an implementation detail.
> >>>
> >>> Greg Parker has pointed out it’s possible to rewrite the macros using
> the “do { … } while (0)”,
> >>> but that is a lot of macros to change, and the resulting code would be
> arguably less readable.
> >>
> >>
> >> That suggestion is the (or at least an) idiomatic way to write a
> "statement-like" macro that expects a semicolon. The approach taken by the
> above macros is often considered to be a macro antipattern (try putting it
> in an unbraced if and adding an else clause, for example).
> >>>
> >>> On Dec 5, 2018, at 5:10 AM, Aaron Ballman 
> wrote:
> >>>
> >>> On Wed, Dec 5, 2018 at 1:40 AM Roman Lebedev 
> wrote:
> >>>
> >>>
> >>> It is a problem in practice for us since we have projects which enable
> all available warnings and also enable “-Werror”.
> >>>
> >>> Hm, they have asked for -Weverything and they got it. Seems to be
> >>> working as intended.
> >>> When in previous discussions elsewhere i have talked about
> >>> -Weverything, i was always
> >>> been told that it isn't supposed to be used like that (admittedly, i
> >>> *do* use it like that :)).
> >>>
> >>> Could you explain how is this different from any other warning that is
> >>> considered pointless by the project?
> >>> Why not simply disable it?
> >>>
> >>>
> >>> You are right, it could be disabled. It’s just for this warning the
> noise vs. usefulness ratio seemed pretty low.
> >>>
> >>>
> >>> Would you be okay with the warning if it was only diagnosed when the
> >>> source location of the semi-colon is not immediately preceded by a
> >>> macro expansion location? e.g.,
> >>>
> >>> EMPTY_EXPANSION(12); // Not diagnosed
> >>> EMPTY_EXPANSION; // Not diagnosed
> >>> ; // Diagnosed
> >>>
> >>> This could work provided that all empty s

r355278 - Make the new SanitizerMask code added in r355190 constexpr.

2019-03-02 Thread James Y Knight via cfe-commits
Author: jyknight
Date: Sat Mar  2 12:22:48 2019
New Revision: 355278

URL: http://llvm.org/viewvc/llvm-project?rev=355278&view=rev
Log:
Make the new SanitizerMask code added in r355190 constexpr.

Then, as a consequence, remove the complex set of workarounds for
initialization order -- which are apparently not 100% reliable.

The only downside is that some of the member functions are now
specific to kNumElem == 2, and will need to be updated if that
constant is increased in the future.

Unfortunately, the current code caused an initialization-order runtime
failure for me in some compilation modes. It appears that in a
toolchain without init-array enabled, the order of initialization of
static data members of a template can be reversed w.r.t. the order
within a file.

This caused e.g. SanitizerKind::CFI to be initialized to 0.

I'm not quite sure if that is an allowable ordering variation, or
nonconforming behavior, but in any case, making everything constexpr
eliminates the possibility of such an issue.

Modified:
cfe/trunk/include/clang/Basic/Sanitizers.h
cfe/trunk/lib/Basic/Sanitizers.cpp

Modified: cfe/trunk/include/clang/Basic/Sanitizers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Sanitizers.h?rev=355278&r1=355277&r2=355278&view=diff
==
--- cfe/trunk/include/clang/Basic/Sanitizers.h (original)
+++ cfe/trunk/include/clang/Basic/Sanitizers.h Sat Mar  2 12:22:48 2019
@@ -27,6 +27,10 @@ class hash_code;
 namespace clang {
 
 class SanitizerMask {
+  // NOTE: this class assumes kNumElem == 2 in most of the constexpr functions,
+  // in order to work within the C++11 constexpr function constraints. If you
+  // change kNumElem, you'll need to update those member functions as well.
+
   /// Number of array elements.
   static constexpr unsigned kNumElem = 2;
   /// Mask value initialized to 0.
@@ -36,17 +40,22 @@ class SanitizerMask {
   /// Number of bits in a mask element.
   static constexpr unsigned kNumBitElem = sizeof(decltype(maskLoToHigh[0])) * 
8;
 
+  constexpr SanitizerMask(uint64_t mask1, uint64_t mask2)
+  : maskLoToHigh{mask1, mask2} {}
+
 public:
+  SanitizerMask() = default;
+
   static constexpr bool checkBitPos(const unsigned Pos) {
 return Pos < kNumBits;
   }
 
   /// Create a mask with a bit enabled at position Pos.
-  static SanitizerMask bitPosToMask(const unsigned Pos) {
-assert(Pos < kNumBits && "Bit position too big.");
-SanitizerMask mask;
-mask.maskLoToHigh[Pos / kNumBitElem] = 1ULL << Pos % kNumBitElem;
-return mask;
+  static constexpr SanitizerMask bitPosToMask(const unsigned Pos) {
+return SanitizerMask((Pos < kNumBitElem) ? 1ULL << Pos % kNumBitElem : 0,
+ (Pos >= kNumBitElem && Pos < kNumBitElem * 2)
+ ? 1ULL << Pos % kNumBitElem
+ : 0);
   }
 
   unsigned countPopulation() const {
@@ -67,19 +76,13 @@ public:
 
   llvm::hash_code hash_value() const;
 
-  explicit operator bool() const {
-for (const auto &Val : maskLoToHigh)
-  if (Val)
-return true;
-return false;
-  };
+  constexpr explicit operator bool() const {
+return maskLoToHigh[0] || maskLoToHigh[1];
+  }
 
-  bool operator==(const SanitizerMask &V) const {
-for (unsigned k = 0; k < kNumElem; k++) {
-  if (maskLoToHigh[k] != V.maskLoToHigh[k])
-return false;
-}
-return true;
+  constexpr bool operator==(const SanitizerMask &V) const {
+return maskLoToHigh[0] == V.maskLoToHigh[0] &&
+   maskLoToHigh[1] == V.maskLoToHigh[1];
   }
 
   SanitizerMask &operator&=(const SanitizerMask &RHS) {
@@ -94,42 +97,35 @@ public:
 return *this;
   }
 
-  bool operator!() const {
-for (const auto &Val : maskLoToHigh)
-  if (Val)
-return false;
-return true;
+  constexpr bool operator!() const { return !bool(*this); }
+
+  constexpr bool operator!=(const SanitizerMask &RHS) const {
+return !((*this) == RHS);
   }
 
-  bool operator!=(const SanitizerMask &RHS) const { return !((*this) == RHS); }
+  friend constexpr inline SanitizerMask operator~(SanitizerMask v) {
+return SanitizerMask(~v.maskLoToHigh[0], ~v.maskLoToHigh[1]);
+  }
+
+  friend constexpr inline SanitizerMask operator&(SanitizerMask a,
+  const SanitizerMask &b) {
+return SanitizerMask(a.maskLoToHigh[0] & b.maskLoToHigh[0],
+ a.maskLoToHigh[1] & b.maskLoToHigh[1]);
+  }
+
+  friend constexpr inline SanitizerMask operator|(SanitizerMask a,
+  const SanitizerMask &b) {
+return SanitizerMask(a.maskLoToHigh[0] | b.maskLoToHigh[0],
+ a.maskLoToHigh[1] | b.maskLoToHigh[1]);
+  }
 };
 
 // Declaring in clang namespace so that it can be found by ADL.
 llvm::hash_code hash_value(const clang::SanitizerMask &Arg);
 
-inline San

r355279 - Tweak r355278 for compatibility with gcc 6 and earlier.

2019-03-02 Thread James Y Knight via cfe-commits
Author: jyknight
Date: Sat Mar  2 13:20:30 2019
New Revision: 355279

URL: http://llvm.org/viewvc/llvm-project?rev=355279&view=rev
Log:
Tweak r355278 for compatibility with gcc 6 and earlier.

Modified:
cfe/trunk/lib/Basic/Sanitizers.cpp

Modified: cfe/trunk/lib/Basic/Sanitizers.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Sanitizers.cpp?rev=355279&r1=355278&r2=355279&view=diff
==
--- cfe/trunk/lib/Basic/Sanitizers.cpp (original)
+++ cfe/trunk/lib/Basic/Sanitizers.cpp Sat Mar  2 13:20:30 2019
@@ -20,8 +20,8 @@ using namespace clang;
 // won't need this.
 #define SANITIZER(NAME, ID) const SanitizerMask SanitizerKind::ID;
 #define SANITIZER_GROUP(NAME, ID, ALIAS)   
\
-  const SanitizerMask SanitizerKind::ID;   
\
-  const SanitizerMask SanitizerKind::ID##Group;
+  constexpr SanitizerMask SanitizerKind::ID;   
\
+  constexpr SanitizerMask SanitizerKind::ID##Group;
 #include "clang/Basic/Sanitizers.def"
 
 SanitizerMask clang::parseSanitizerValue(StringRef Value, bool AllowGroups) {


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


r355280 - Tweak r355278 for compatibility with gcc 6 and earlier.

2019-03-02 Thread James Y Knight via cfe-commits
Author: jyknight
Date: Sat Mar  2 13:55:36 2019
New Revision: 355280

URL: http://llvm.org/viewvc/llvm-project?rev=355280&view=rev
Log:
Tweak r355278 for compatibility with gcc 6 and earlier.

Modified:
cfe/trunk/lib/Basic/Sanitizers.cpp

Modified: cfe/trunk/lib/Basic/Sanitizers.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Sanitizers.cpp?rev=355280&r1=355279&r2=355280&view=diff
==
--- cfe/trunk/lib/Basic/Sanitizers.cpp (original)
+++ cfe/trunk/lib/Basic/Sanitizers.cpp Sat Mar  2 13:55:36 2019
@@ -18,7 +18,7 @@ using namespace clang;
 
 // Once LLVM switches to C++17, the constexpr variables can be inline and we
 // won't need this.
-#define SANITIZER(NAME, ID) const SanitizerMask SanitizerKind::ID;
+#define SANITIZER(NAME, ID) constexpr SanitizerMask SanitizerKind::ID;
 #define SANITIZER_GROUP(NAME, ID, ALIAS)   
\
   constexpr SanitizerMask SanitizerKind::ID;   
\
   constexpr SanitizerMask SanitizerKind::ID##Group;


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


Re: r355322 - Enable _rotl, _lrotl, _rotr, _lrotr on all platforms.

2019-03-07 Thread James Y Knight via cfe-commits
This patch breaks some code which is (conditionally) defining functions of
these names on certain platforms. Now, it's true that it shouldn't be doing
that, and if the claim in the commit message about GCC was true, I'd just
say "don't do that".

But, the commit message is wrong. GCC does _not_ define these as builtins,
it defines them in ia32intrin.h header (publicly via x86intrin.h) .

IMO, this commit should be reverted, and  functions defined in the header,
instead. Perhaps similar to what 2c8f9c2c23e0cafd7b85a7aec969c949349f747c

did, although I note that was reverted in
b62c5bc64dee3642884c31b8208c07a6f74b81fd
,
reportedly due to breaking mingw.

(I'd further note that even MSVC doesn't enable these builtins by default!
It implements a `#pragma intrinsic(NAME)` mechanism which you need to use
in order to enable them (and #include  will do so). But clang
doesn't really implement that pragma, and instead enables all the
MSVC-builtins unconditionally.)

On Mon, Mar 4, 2019 at 1:46 PM Erich Keane via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: erichkeane
> Date: Mon Mar  4 10:47:21 2019
> New Revision: 355322
>
> URL: http://llvm.org/viewvc/llvm-project?rev=355322&view=rev
> Log:
> Enable _rotl, _lrotl, _rotr, _lrotr on all platforms.
>
> The above builtins are currently implemented for MSVC mode, however GCC
> also implements these.  This patch enables them for all platforms.
>
> Additionally, this corrects the type for these builtins to always be
> 'long int' to match the specification in the Intel Intrinsics Guide.
>
> Change-Id: Ida34be98078709584ef5136c8761783435ec02b1
>
> Added:
> cfe/trunk/test/CodeGen/rot-intrinsics.c   (with props)
> Modified:
> cfe/trunk/include/clang/Basic/Builtins.def
> cfe/trunk/test/CodeGen/ms-intrinsics-rotations.c
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r356789 - IR: Support parsing numeric block ids, and emit them in textual output.

2019-03-22 Thread James Y Knight via cfe-commits
Author: jyknight
Date: Fri Mar 22 11:27:13 2019
New Revision: 356789

URL: http://llvm.org/viewvc/llvm-project?rev=356789&view=rev
Log:
IR: Support parsing numeric block ids, and emit them in textual output.

Just as as llvm IR supports explicitly specifying numeric value ids
for instructions, and emits them by default in textual output, now do
the same for blocks.

This is a slightly incompatible change in the textual IR format.

Previously, llvm would parse numeric labels as string names. E.g.
  define void @f() {
br label %"55"
  55:
ret void
  }
defined a label *named* "55", even without needing to be quoted, while
the reference required quoting. Now, if you intend a block label which
looks like a value number to be a name, you must quote it in the
definition too (e.g. `"55":`).

Previously, llvm would print nameless blocks only as a comment, and
would omit it if there was no predecessor. This could cause confusion
for readers of the IR, just as unnamed instructions did prior to the
addition of "%5 = " syntax, back in 2008 (PR2480).

Now, it will always print a label for an unnamed block, with the
exception of the entry block. (IMO it may be better to print it for
the entry-block as well. However, that requires updating many more
tests.)

Thus, the following is supported, and is the canonical printing:
  define i32 @f(i32, i32) {
%3 = add i32 %0, %1
br label %4

  4:
ret i32 %3
  }

New test cases covering this behavior are added, and other tests
updated as required.

Differential Revision: https://reviews.llvm.org/D58548

Modified:
cfe/trunk/test/CodeGenCXX/discard-name-values.cpp

Modified: cfe/trunk/test/CodeGenCXX/discard-name-values.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/discard-name-values.cpp?rev=356789&r1=356788&r2=356789&view=diff
==
--- cfe/trunk/test/CodeGenCXX/discard-name-values.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/discard-name-values.cpp Fri Mar 22 11:27:13 2019
@@ -10,7 +10,7 @@ bool test(bool pred) {
   // CHECK: br i1 %pred, label %if.then, label %if.end
 
   if (pred) {
-// DISCARDVALUE: ; :2:
+// DISCARDVALUE: 2:
 // DISCARDVALUE-NEXT: tail call void @branch()
 // DISCARDVALUE-NEXT: br label %3
 
@@ -20,7 +20,7 @@ bool test(bool pred) {
 branch();
   }
 
-  // DISCARDVALUE: ; :3:
+  // DISCARDVALUE: 3:
   // DISCARDVALUE-NEXT: ret i1 %0
 
   // CHECK: if.end:


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


r360084 - PR41183: Don't emit strict-prototypes warning for an implicit function

2019-05-06 Thread James Y Knight via cfe-commits
Author: jyknight
Date: Mon May  6 14:37:59 2019
New Revision: 360084

URL: http://llvm.org/viewvc/llvm-project?rev=360084&view=rev
Log:
PR41183: Don't emit strict-prototypes warning for an implicit function
declaration.

It should emit _only_ an implicit-function-declaration warning, not
both of them.

Differential Revision: https://reviews.llvm.org/D59711

Modified:
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/Sema/warn-strict-prototypes.c

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=360084&r1=360083&r2=360084&view=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Mon May  6 14:37:59 2019
@@ -5010,7 +5010,10 @@ static TypeSourceInfo *GetFullTypeForDec
 break;
   case DeclaratorChunk::Function: {
 const DeclaratorChunk::FunctionTypeInfo &FTI = DeclType.Fun;
-if (FTI.NumParams == 0 && !FTI.isVariadic)
+// We supress the warning when there's no LParen location, as this
+// indicates the declaration was an implicit declaration, which gets
+// warned about separately via -Wimplicit-function-declaration.
+if (FTI.NumParams == 0 && !FTI.isVariadic && 
FTI.getLParenLoc().isValid())
   S.Diag(DeclType.Loc, diag::warn_strict_prototypes)
   << IsBlock
   << FixItHint::CreateInsertion(FTI.getRParenLoc(), "void");

Modified: cfe/trunk/test/Sema/warn-strict-prototypes.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-strict-prototypes.c?rev=360084&r1=360083&r2=360084&view=diff
==
--- cfe/trunk/test/Sema/warn-strict-prototypes.c (original)
+++ cfe/trunk/test/Sema/warn-strict-prototypes.c Mon May  6 14:37:59 2019
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple i386-pc-unknown -fsyntax-only -Wstrict-prototypes 
-verify %s
+// RUN: %clang_cc1 -triple i386-pc-unknown -fsyntax-only -Wstrict-prototypes 
-Wno-implicit-function-declaration -verify %s
 // RUN: %clang_cc1 -triple i386-pc-unknown -fsyntax-only -Wstrict-prototypes 
-fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
 
 // function declaration with unspecified params
@@ -71,3 +71,9 @@ void __attribute__((cdecl)) foo12(d) //
 // rdar://problem/33251668
 void foo13(...) __attribute__((overloadable));
 void foo13(...) __attribute__((overloadable)) {}
+
+// We should not generate a strict-prototype warning for an implicit
+// declaration.  Leave that up to the implicit-function-declaration warning.
+void foo14(void) {
+  foo14_call(); // no-warning
+}


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


r343867 - Emit diagnostic note when calling an invalid function declaration.

2018-10-05 Thread James Y Knight via cfe-commits
Author: jyknight
Date: Fri Oct  5 10:49:48 2018
New Revision: 343867

URL: http://llvm.org/viewvc/llvm-project?rev=343867&view=rev
Log:
Emit diagnostic note when calling an invalid function declaration.

The comment said it was intentionally not emitting any diagnostic
because the declaration itself was already diagnosed. However,
everywhere else that wants to not emit a diagnostic without an extra
note emits note_invalid_subexpr_in_const_expr instead, which gets
suppressed later.

This was the only place which did not emit a diagnostic note.

Differential Revision: https://reviews.llvm.org/D52919

Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/SemaCXX/enable_if.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=343867&r1=343866&r2=343867&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Fri Oct  5 10:49:48 2018
@@ -4330,10 +4330,13 @@ static bool CheckConstexprFunction(EvalI
   Declaration->isConstexpr())
 return false;
 
-  // Bail out with no diagnostic if the function declaration itself is invalid.
-  // We will have produced a relevant diagnostic while parsing it.
-  if (Declaration->isInvalidDecl())
+  // Bail out if the function declaration itself is invalid.  We will
+  // have produced a relevant diagnostic while parsing it, so just
+  // note the problematic sub-expression.
+  if (Declaration->isInvalidDecl()) {
+Info.FFDiag(CallLoc, diag::note_invalid_subexpr_in_const_expr);
 return false;
+  }
 
   // Can we evaluate this function call?
   if (Definition && Definition->isConstexpr() &&

Modified: cfe/trunk/test/SemaCXX/enable_if.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/enable_if.cpp?rev=343867&r1=343866&r2=343867&view=diff
==
--- cfe/trunk/test/SemaCXX/enable_if.cpp (original)
+++ cfe/trunk/test/SemaCXX/enable_if.cpp Fri Oct  5 10:49:48 2018
@@ -414,7 +414,8 @@ static_assert(templated<1>() == 1, "");
 
 template  constexpr int callTemplated() { return templated(); }
 
-constexpr int B = callTemplated<0>(); // expected-error{{initialized by a 
constant expression}} expected-error@-2{{no matching function for call to 
'templated'}} expected-note{{in instantiation of function template}} 
expected-note@-9{{candidate disabled}}
+constexpr int B = 10 + // the carat for the error should be pointing to the 
problematic call (on the next line), not here.
+callTemplated<0>(); // expected-error{{initialized by a constant 
expression}} expected-error@-3{{no matching function for call to 'templated'}} 
expected-note{{in instantiation of function template}} 
expected-note@-10{{candidate disabled}}
 static_assert(callTemplated<1>() == 1, "");
 }
 


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


r343892 - Emit CK_NoOp casts in C mode, not just C++.

2018-10-05 Thread James Y Knight via cfe-commits
Author: jyknight
Date: Fri Oct  5 14:53:51 2018
New Revision: 343892

URL: http://llvm.org/viewvc/llvm-project?rev=343892&view=rev
Log:
Emit CK_NoOp casts in C mode, not just C++.

Previously, it had been using CK_BitCast even for casts that only
change const/restrict/volatile. Now it will use CK_Noop where
appropriate.

This is an alternate solution to r336746.

Differential Revision: https://reviews.llvm.org/D52918

Added:
cfe/trunk/test/Sema/c-casts.c
Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=343892&r1=343891&r2=343892&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Fri Oct  5 14:53:51 2018
@@ -5864,11 +5864,7 @@ bool PointerExprEvaluator::VisitCastExpr
 // permitted in constant expressions in C++11. Bitcasts from cv void* are
 // also static_casts, but we disallow them as a resolution to DR1312.
 if (!E->getType()->isVoidPointerType()) {
-  // If we changed anything other than cvr-qualifiers, we can't use this
-  // value for constant folding. FIXME: Qualification conversions should
-  // always be CK_NoOp, but we get this wrong in C.
-  if (!Info.Ctx.hasCvrSimilarType(E->getType(), 
E->getSubExpr()->getType()))
-Result.Designator.setInvalid();
+  Result.Designator.setInvalid();
   if (SubExpr->getType()->isVoidPointerType())
 CCEDiag(E, diag::note_constexpr_invalid_cast)
   << 3 << SubExpr->getType();

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=343892&r1=343891&r2=343892&view=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Oct  5 14:53:51 2018
@@ -5862,6 +5862,8 @@ CastKind Sema::PrepareScalarCast(ExprRes
   LangAS DestAS = DestTy->getPointeeType().getAddressSpace();
   if (SrcAS != DestAS)
 return CK_AddressSpaceConversion;
+  if (Context.hasCvrSimilarType(SrcTy, DestTy))
+return CK_NoOp;
   return CK_BitCast;
 }
 case Type::STK_BlockPointer:
@@ -7762,7 +7764,12 @@ Sema::CheckAssignmentConstraints(QualTyp
 if (isa(RHSType)) {
   LangAS AddrSpaceL = LHSPointer->getPointeeType().getAddressSpace();
   LangAS AddrSpaceR = RHSType->getPointeeType().getAddressSpace();
-  Kind = AddrSpaceL != AddrSpaceR ? CK_AddressSpaceConversion : CK_BitCast;
+  if (AddrSpaceL != AddrSpaceR)
+Kind = CK_AddressSpaceConversion;
+  else if (Context.hasCvrSimilarType(RHSType, LHSType))
+Kind = CK_NoOp;
+  else
+Kind = CK_BitCast;
   return checkPointerTypesForAssignment(*this, LHSType, RHSType);
 }
 

Added: cfe/trunk/test/Sema/c-casts.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/c-casts.c?rev=343892&view=auto
==
--- cfe/trunk/test/Sema/c-casts.c (added)
+++ cfe/trunk/test/Sema/c-casts.c Fri Oct  5 14:53:51 2018
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -w -ast-dump %s | FileCheck %s
+
+// The cast construction code both for implicit and c-style casts is very
+// different in C vs C++. This file is intended to test the C behavior.
+
+// TODO: add tests covering the rest of the code in
+// Sema::CheckAssignmentConstraints and Sema::PrepareScalarCast
+
+// CHECK-LABEL: FunctionDecl {{.*}} cast_cvr_pointer
+void cast_cvr_pointer(char volatile * __restrict * const * p) {
+  char*** x;
+  // CHECK: ImplicitCastExpr {{.*}} 'char ***' 
+  x = p;
+  // CHECK: CStyleCastExpr {{.*}} 'char ***' 
+  x = (char***)p;
+}
+
+// CHECK-LABEL: FunctionDecl {{.*}} cast_pointer_type
+void cast_pointer_type(char *p) {
+  void *x;
+  // CHECK: ImplicitCastExpr {{.*}} 'void *' 
+  x = p;
+  // CHECK: CStyleCastExpr {{.*}} 'void *' 
+  x = (void*)p;
+}


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


r352800 - Revert "[opaque pointer types] Add a FunctionCallee wrapper type, and use it."

2019-01-31 Thread James Y Knight via cfe-commits
Author: jyknight
Date: Thu Jan 31 13:51:58 2019
New Revision: 352800

URL: http://llvm.org/viewvc/llvm-project?rev=352800&view=rev
Log:
Revert "[opaque pointer types] Add a FunctionCallee wrapper type, and use it."

This reverts commit f47d6b38c7a61d50db4566b02719de05492dcef1 (r352791).

Seems to run into compilation failures with GCC (but not clang, where
I tested it). Reverting while I investigate.

Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=352800&r1=352799&r2=352800&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Thu Jan 31 13:51:58 2019
@@ -3056,7 +3056,7 @@ void CodeGenFunction::EmitCfiSlowPathChe
   bool WithDiag = !CGM.getCodeGenOpts().SanitizeTrap.has(Kind);
 
   llvm::CallInst *CheckCall;
-  llvm::FunctionCallee SlowPathFn;
+  llvm::Constant *SlowPathFn;
   if (WithDiag) {
 llvm::Constant *Info = llvm::ConstantStruct::getAnon(StaticArgs);
 auto *InfoPtr =
@@ -3078,8 +3078,7 @@ void CodeGenFunction::EmitCfiSlowPathChe
 CheckCall = Builder.CreateCall(SlowPathFn, {TypeId, Ptr});
   }
 
-  CGM.setDSOLocal(
-  cast(SlowPathFn.getCallee()->stripPointerCasts()));
+  CGM.setDSOLocal(cast(SlowPathFn->stripPointerCasts()));
   CheckCall->setDoesNotThrow();
 
   EmitBlock(Cont);


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


r352827 - [opaque pointer types] Add a FunctionCallee wrapper type, and use it.

2019-01-31 Thread James Y Knight via cfe-commits
Author: jyknight
Date: Thu Jan 31 18:28:03 2019
New Revision: 352827

URL: http://llvm.org/viewvc/llvm-project?rev=352827&view=rev
Log:
[opaque pointer types] Add a FunctionCallee wrapper type, and use it.

Recommit r352791 after tweaking DerivedTypes.h slightly, so that gcc
doesn't choke on it, hopefully.

Original Message:
The FunctionCallee type is effectively a {FunctionType*,Value*} pair,
and is a useful convenience to enable code to continue passing the
result of getOrInsertFunction() through to EmitCall, even once pointer
types lose their pointee-type.

Then:
- update the CallInst/InvokeInst instruction creation functions to
  take a Callee,
- modify getOrInsertFunction to return FunctionCallee, and
- update all callers appropriately.

One area of particular note is the change to the sanitizer
code. Previously, they had been casting the result of
`getOrInsertFunction` to a `Function*` via
`checkSanitizerInterfaceFunction`, and storing that. That would report
an error if someone had already inserted a function declaraction with
a mismatching signature.

However, in general, LLVM allows for such mismatches, as
`getOrInsertFunction` will automatically insert a bitcast if
needed. As part of this cleanup, cause the sanitizer code to do the
same. (It will call its functions using the expected signature,
however they may have been declared.)

Finally, in a small number of locations, callers of
`getOrInsertFunction` actually were expecting/requiring that a brand
new function was being created. In such cases, I've switched them to
Function::Create instead.

Differential Revision: https://reviews.llvm.org/D57315

Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=352827&r1=352826&r2=352827&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Thu Jan 31 18:28:03 2019
@@ -3056,7 +3056,7 @@ void CodeGenFunction::EmitCfiSlowPathChe
   bool WithDiag = !CGM.getCodeGenOpts().SanitizeTrap.has(Kind);
 
   llvm::CallInst *CheckCall;
-  llvm::Constant *SlowPathFn;
+  llvm::FunctionCallee SlowPathFn;
   if (WithDiag) {
 llvm::Constant *Info = llvm::ConstantStruct::getAnon(StaticArgs);
 auto *InfoPtr =
@@ -3078,7 +3078,8 @@ void CodeGenFunction::EmitCfiSlowPathChe
 CheckCall = Builder.CreateCall(SlowPathFn, {TypeId, Ptr});
   }
 
-  CGM.setDSOLocal(cast(SlowPathFn->stripPointerCasts()));
+  CGM.setDSOLocal(
+  cast(SlowPathFn.getCallee()->stripPointerCasts()));
   CheckCall->setDoesNotThrow();
 
   EmitBlock(Cont);


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


r352887 - Fix some sphinx doc errors.

2019-02-01 Thread James Y Knight via cfe-commits
Author: jyknight
Date: Fri Feb  1 09:06:41 2019
New Revision: 352887

URL: http://llvm.org/viewvc/llvm-project?rev=352887&view=rev
Log:
Fix some sphinx doc errors.

Modified:
cfe/trunk/docs/ClangTools.rst

Modified: cfe/trunk/docs/ClangTools.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangTools.rst?rev=352887&r1=352886&r2=352887&view=diff
==
--- cfe/trunk/docs/ClangTools.rst (original)
+++ cfe/trunk/docs/ClangTools.rst Fri Feb  1 09:06:41 2019
@@ -10,8 +10,8 @@ refactoring, etc.
 
 Only a couple of the most basic and fundamental tools are kept in the
 primary Clang tree. The rest of the tools are kept in a separate
-directory tree, ``clang-tools-extra
-``_.
+directory tree, `clang-tools-extra
+`_.
 
 This document describes a high-level overview of the organization of
 Clang Tools within the project as well as giving an introduction to some


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


r352946 - Remove redundant FunctionDecl argument from a couple functions.

2019-02-01 Thread James Y Knight via cfe-commits
Author: jyknight
Date: Fri Feb  1 17:48:23 2019
New Revision: 352946

URL: http://llvm.org/viewvc/llvm-project?rev=352946&view=rev
Log:
Remove redundant FunctionDecl argument from a couple functions.

This argument was added in r254554 in order to support the
pass_object_size attribute. However, in r296076, the attribute's
presence is now also represented in FunctionProtoType's
ExtParameterInfo, and thus it's unnecessary to pass along a separate
FunctionDecl.

The functions modified are:
 RequiredArgs::forPrototype{,Plus}, and
 CodeGenTypes::ConvertFunctionType.

After this, it's also (again) unnecessary to have a separate
ConvertFunctionType function ConvertType, so convert callers back to
the latter, leaving the former as an internal helper function.

Modified:
cfe/trunk/include/clang/CodeGen/CGFunctionInfo.h
cfe/trunk/include/clang/CodeGen/CodeGenABITypes.h
cfe/trunk/lib/CodeGen/CGCUDANV.cpp
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/CGExprCXX.cpp
cfe/trunk/lib/CodeGen/CGVTables.cpp
cfe/trunk/lib/CodeGen/CodeGenABITypes.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
cfe/trunk/lib/CodeGen/CodeGenTypes.h

Modified: cfe/trunk/include/clang/CodeGen/CGFunctionInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/CodeGen/CGFunctionInfo.h?rev=352946&r1=352945&r2=352946&view=diff
==
--- cfe/trunk/include/clang/CodeGen/CGFunctionInfo.h (original)
+++ cfe/trunk/include/clang/CodeGen/CGFunctionInfo.h Fri Feb  1 17:48:23 2019
@@ -440,31 +440,30 @@ public:
   ///
   /// If FD is not null, this will consider pass_object_size params in FD.
   static RequiredArgs forPrototypePlus(const FunctionProtoType *prototype,
-   unsigned additional,
-   const FunctionDecl *FD) {
+   unsigned additional) {
 if (!prototype->isVariadic()) return All;
-if (FD)
-  additional +=
-  llvm::count_if(FD->parameters(), [](const ParmVarDecl *PVD) {
-return PVD->hasAttr();
+
+if (prototype->hasExtParameterInfos())
+  additional += llvm::count_if(
+  prototype->getExtParameterInfos(),
+  [](const FunctionProtoType::ExtParameterInfo &ExtInfo) {
+return ExtInfo.hasPassObjectSize();
   });
+
 return RequiredArgs(prototype->getNumParams() + additional);
   }
 
-  static RequiredArgs forPrototype(const FunctionProtoType *prototype,
-   const FunctionDecl *FD) {
-return forPrototypePlus(prototype, 0, FD);
+  static RequiredArgs forPrototypePlus(CanQual prototype,
+   unsigned additional) {
+return forPrototypePlus(prototype.getTypePtr(), additional);
   }
 
-  static RequiredArgs forPrototype(CanQual prototype,
-   const FunctionDecl *FD) {
-return forPrototype(prototype.getTypePtr(), FD);
+  static RequiredArgs forPrototype(const FunctionProtoType *prototype) {
+return forPrototypePlus(prototype, 0);
   }
 
-  static RequiredArgs forPrototypePlus(CanQual prototype,
-   unsigned additional,
-   const FunctionDecl *FD) {
-return forPrototypePlus(prototype.getTypePtr(), additional, FD);
+  static RequiredArgs forPrototype(CanQual prototype) {
+return forPrototypePlus(prototype.getTypePtr(), 0);
   }
 
   bool allowsOptionalArgs() const { return NumRequired != ~0U; }

Modified: cfe/trunk/include/clang/CodeGen/CodeGenABITypes.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/CodeGen/CodeGenABITypes.h?rev=352946&r1=352945&r2=352946&view=diff
==
--- cfe/trunk/include/clang/CodeGen/CodeGenABITypes.h (original)
+++ cfe/trunk/include/clang/CodeGen/CodeGenABITypes.h Fri Feb  1 17:48:23 2019
@@ -54,8 +54,7 @@ const CGFunctionInfo &arrangeObjCMessage
   QualType receiverType);
 
 const CGFunctionInfo &arrangeFreeFunctionType(CodeGenModule &CGM,
-  CanQual Ty,
-  const FunctionDecl *FD);
+  CanQual Ty);
 
 const CGFunctionInfo &arrangeFreeFunctionType(CodeGenModule &CGM,
   CanQual Ty);

Modified: cfe/trunk/lib/CodeGen/CGCUDANV.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCUDANV.cpp?rev=352946&r1=352945&r2=352946&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCUDANV.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCUDANV.cpp Fri Feb  1 17:48:23 2019
@@ -278,7 +278,7 @@ void CGNVCUDARuntime::emitDeviceS

r353009 - [opaque pointer types] Trivial changes towards CallInst requiring

2019-02-03 Thread James Y Knight via cfe-commits
Author: jyknight
Date: Sun Feb  3 13:53:49 2019
New Revision: 353009

URL: http://llvm.org/viewvc/llvm-project?rev=353009&view=rev
Log:
[opaque pointer types] Trivial changes towards CallInst requiring
explicit function types.

Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/CGCoroutine.cpp
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
cfe/trunk/lib/CodeGen/CGException.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGExprCXX.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=353009&r1=353008&r2=353009&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Sun Feb  3 13:53:49 2019
@@ -305,7 +305,7 @@ static Value *emitUnaryBuiltin(CodeGenFu
unsigned IntrinsicID) {
   llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
 
-  Value *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType());
+  Function *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType());
   return CGF.Builder.CreateCall(F, Src0);
 }
 
@@ -316,7 +316,7 @@ static Value *emitBinaryBuiltin(CodeGenF
   llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
   llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1));
 
-  Value *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType());
+  Function *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType());
   return CGF.Builder.CreateCall(F, { Src0, Src1 });
 }
 
@@ -328,7 +328,7 @@ static Value *emitTernaryBuiltin(CodeGen
   llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1));
   llvm::Value *Src2 = CGF.EmitScalarExpr(E->getArg(2));
 
-  Value *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType());
+  Function *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType());
   return CGF.Builder.CreateCall(F, { Src0, Src1, Src2 });
 }
 
@@ -339,13 +339,13 @@ static Value *emitFPIntBuiltin(CodeGenFu
   llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
   llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1));
 
-  Value *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType());
+  Function *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType());
   return CGF.Builder.CreateCall(F, {Src0, Src1});
 }
 
 /// EmitFAbs - Emit a call to @llvm.fabs().
 static Value *EmitFAbs(CodeGenFunction &CGF, Value *V) {
-  Value *F = CGF.CGM.getIntrinsic(Intrinsic::fabs, V->getType());
+  Function *F = CGF.CGM.getIntrinsic(Intrinsic::fabs, V->getType());
   llvm::CallInst *Call = CGF.Builder.CreateCall(F, V);
   Call->setDoesNotAccessMemory();
   return Call;
@@ -406,7 +406,7 @@ static llvm::Value *EmitOverflowIntrinsi
  "Arguments must be the same type. (Did you forget to make sure both "
  "arguments have the same integer width?)");
 
-  llvm::Value *Callee = CGF.CGM.getIntrinsic(IntrinsicID, X->getType());
+  Function *Callee = CGF.CGM.getIntrinsic(IntrinsicID, X->getType());
   llvm::Value *Tmp = CGF.Builder.CreateCall(Callee, {X, Y});
   Carry = CGF.Builder.CreateExtractValue(Tmp, 1);
   return CGF.Builder.CreateExtractValue(Tmp, 0);
@@ -417,7 +417,7 @@ static Value *emitRangedBuiltin(CodeGenF
 int low, int high) {
 llvm::MDBuilder MDHelper(CGF.getLLVMContext());
 llvm::MDNode *RNode = MDHelper.createRange(APInt(32, low), APInt(32, 
high));
-Value *F = CGF.CGM.getIntrinsic(IntrinsicID, {});
+Function *F = CGF.CGM.getIntrinsic(IntrinsicID, {});
 llvm::Instruction *Call = CGF.Builder.CreateCall(F);
 Call->setMetadata(llvm::LLVMContext::MD_range, RNode);
 return Call;
@@ -544,7 +544,8 @@ CodeGenFunction::emitBuiltinObjectSize(c
   assert(Ptr->getType()->isPointerTy() &&
  "Non-pointer passed to __builtin_object_size?");
 
-  Value *F = CGM.getIntrinsic(Intrinsic::objectsize, {ResType, 
Ptr->getType()});
+  Function *F =
+  CGM.getIntrinsic(Intrinsic::objectsize, {ResType, Ptr->getType()});
 
   // LLVM only supports 0 and 2, make sure that we pass along that as a 
boolean.
   Value *Min = Builder.getInt1((Type & 2) != 0);
@@ -876,7 +877,7 @@ Value *CodeGenFunction::EmitMSVCBuiltinE
 Address IndexAddress = EmitPointerWithAlignment(E->getArg(0));
 
 if (BuiltinID == MSVCIntrin::_BitScanForward) {
-  Value *F = CGM.getIntrinsic(Intrinsic::cttz, ArgType);
+  Function *F = CGM.getIntrinsic(Intrinsic::cttz, ArgType);
   Value *ZeroCount = Builder.CreateCall(F, {ArgValue, Builder.getTrue()});
   ZeroCount = Builder.CreateIntCast(ZeroCount, IndexType, false);
   Builder.CreateStore(ZeroCount, IndexAddress, false);
@@ -884,7 +885,7 @@ Value *CodeGenFunction::EmitMSVCBuiltinE
   unsigned ArgWidth = cast(ArgType)->getBitWidth();
   Value *ArgTypeLastIndex = llvm::ConstantInt::g

r353181 - [opaque pointer types] Fix the CallInfo passed to EmitCall in some

2019-02-05 Thread James Y Knight via cfe-commits
Author: jyknight
Date: Tue Feb  5 08:05:50 2019
New Revision: 353181

URL: http://llvm.org/viewvc/llvm-project?rev=353181&view=rev
Log:
[opaque pointer types] Fix the CallInfo passed to EmitCall in some
edge cases.

Currently, EmitCall emits a call instruction with a function type
derived from the pointee-type of the callee. This *should* be the same
as the type created from the CallInfo parameter, but in some cases an
incorrect CallInfo was being passed.

All of these fixes were discovered by the addition of the assert in
EmitCall which verifies that the passed-in CallInfo matches the
Callee's function type.

As far as I know, these issues caused no bugs at the moment, as the
correct types were ultimately being emitted. But, some would become
problematic when pointee types are removed.

List of fixes:

* arrangeCXXConstructorCall was passing an incorrect value for the
  number of Required args, when calling an inheriting constructor
  where the inherited constructor is variadic. (The inheriting
  constructor doesn't actually get passed any of the user's args, but
  the code was calculating it as if it did).

* arrangeFreeFunctionLikeCall was not including the count of the
  pass_object_size arguments in the count of required args.

* OpenCL uses other address spaces for the "this" pointer. However,
  commonEmitCXXMemberOrOperatorCall was not annotating the address
  space on the "this" argument of the call.

* Destructor calls were being created with EmitCXXMemberOrOperatorCall
  instead of EmitCXXDestructorCall in a few places. This was a problem
  because the calling convention sometimes has destructors returning
  "this" rather than void, and the latter function knows about that,
  and sets up the types properly (through calling
  arrangeCXXStructorDeclaration), while the former does not.

* generateObjCGetterBody: the 'objc_getProperty' function returns type
  'id', but was being called as if it returned the particular
  property's type. (That is of course the *dynamic* return type, and
  there's a downcast immediately after.)

* OpenMP user-defined reduction functions (#pragma omp declare
  reduction) can be called with a subclass of the declared type. In
  such case, the call was being setup as if the function had been
  actually declared to take the subtype, rather than the base type.

Differential Revision: https://reviews.llvm.org/D57664

Modified:
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/CGExprCXX.cpp
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/lib/CodeGen/CodeGenTypes.h
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/CodeGenObjC/getter-property-mismatch.m

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=353181&r1=353180&r2=353181&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Tue Feb  5 08:05:50 2019
@@ -67,10 +67,17 @@ unsigned CodeGenTypes::ClangCallConvToLL
 }
 
 /// Derives the 'this' type for codegen purposes, i.e. ignoring method CVR
-/// qualification.
-static CanQualType GetThisType(ASTContext &Context, const CXXRecordDecl *RD,
-   const CXXMethodDecl *MD) {
-  QualType RecTy = Context.getTagDeclType(RD)->getCanonicalTypeInternal();
+/// qualification. Either or both of RD and MD may be null. A null RD indicates
+/// that there is no meaningful 'this' type, and a null MD can occur when
+/// calling a method pointer.
+CanQualType CodeGenTypes::DeriveThisType(const CXXRecordDecl *RD,
+ const CXXMethodDecl *MD) {
+  QualType RecTy;
+  if (RD)
+RecTy = Context.getTagDeclType(RD)->getCanonicalTypeInternal();
+  else
+RecTy = Context.VoidTy;
+
   if (MD)
 RecTy = Context.getAddrSpaceQualType(RecTy, 
MD->getMethodQualifiers().getAddressSpace());
   return Context.getPointerType(CanQualType::CreateUnsafe(RecTy));
@@ -235,7 +242,7 @@ static CallingConv getCallingConventionF
 
 /// Arrange the argument and result information for a call to an
 /// unknown C++ non-static member function of the given abstract type.
-/// (Zero value of RD means we don't have any meaningful "this" argument type,
+/// (A null RD means we don't have any meaningful "this" argument type,
 ///  so fall back to a generic pointer type).
 /// The member function must be an ordinary function, i.e. not a
 /// constructor or destructor.
@@ -246,10 +253,7 @@ CodeGenTypes::arrangeCXXMethodType(const
   SmallVector argTypes;
 
   // Add the 'this' pointer.
-  if (RD)
-argTypes.push_back(GetThisType(Context, RD, MD));
-  else
-argTypes.push_back(Context.VoidPtrTy);
+  argTypes.push_back(DeriveThisType(RD, MD));
 
   return ::arrangeLLVMFunctionInfo(
   *this, true, argTypes,
@@ -303,7 +307,7 @@ CodeGenTypes::arrangeCXXStructorDeclarat
 
   SmallVector argTypes;
   

r353197 - Minor cleanup: remove CGBuild::CreateConst*ByteGEP overloads taking a Value*.

2019-02-05 Thread James Y Knight via cfe-commits
Author: jyknight
Date: Tue Feb  5 11:01:33 2019
New Revision: 353197

URL: http://llvm.org/viewvc/llvm-project?rev=353197&view=rev
Log:
Minor cleanup: remove CGBuild::CreateConst*ByteGEP overloads taking a Value*.

Modified:
cfe/trunk/lib/CodeGen/CGBuilder.h
cfe/trunk/lib/CodeGen/TargetInfo.cpp

Modified: cfe/trunk/lib/CodeGen/CGBuilder.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuilder.h?rev=353197&r1=353196&r2=353197&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuilder.h (original)
+++ cfe/trunk/lib/CodeGen/CGBuilder.h Tue Feb  5 11:01:33 2019
@@ -258,17 +258,6 @@ public:
 CharUnits::fromQuantity(Offset.getSExtValue(;
   }
 
-  llvm::Value *CreateConstInBoundsByteGEP(llvm::Value *Ptr, CharUnits Offset,
-  const llvm::Twine &Name = "") {
-assert(Ptr->getType()->getPointerElementType() == TypeCache.Int8Ty);
-return CreateInBoundsGEP(Ptr, getSize(Offset), Name);
-  }
-  llvm::Value *CreateConstByteGEP(llvm::Value *Ptr, CharUnits Offset,
-  const llvm::Twine &Name = "") {
-assert(Ptr->getType()->getPointerElementType() == TypeCache.Int8Ty);
-return CreateGEP(Ptr, getSize(Offset), Name);
-  }
-
   using CGBuilderBaseTy::CreateMemCpy;
   llvm::CallInst *CreateMemCpy(Address Dest, Address Src, llvm::Value *Size,
bool IsVolatile = false) {

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=353197&r1=353196&r2=353197&view=diff
==
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Tue Feb  5 11:01:33 2019
@@ -309,10 +309,9 @@ static Address emitVoidPtrDirectVAArg(Co
 
   // Advance the pointer past the argument, then store that back.
   CharUnits FullDirectSize = DirectSize.alignTo(SlotSize);
-  llvm::Value *NextPtr =
-CGF.Builder.CreateConstInBoundsByteGEP(Addr.getPointer(), FullDirectSize,
-   "argp.next");
-  CGF.Builder.CreateStore(NextPtr, VAListAddr);
+  Address NextPtr =
+  CGF.Builder.CreateConstInBoundsByteGEP(Addr, FullDirectSize, 
"argp.next");
+  CGF.Builder.CreateStore(NextPtr.getPointer(), VAListAddr);
 
   // If the argument is smaller than a slot, and this is a big-endian
   // target, the argument will be right-adjusted in its slot.
@@ -8211,9 +8210,8 @@ Address SparcV9ABIInfo::EmitVAArg(CodeGe
   }
 
   // Update VAList.
-  llvm::Value *NextPtr =
-Builder.CreateConstInBoundsByteGEP(Addr.getPointer(), Stride, "ap.next");
-  Builder.CreateStore(NextPtr, VAListAddr);
+  Address NextPtr = Builder.CreateConstInBoundsByteGEP(Addr, Stride, 
"ap.next");
+  Builder.CreateStore(NextPtr.getPointer(), VAListAddr);
 
   return Builder.CreateBitCast(ArgAddr, ArgPtrTy, "arg.addr");
 }
@@ -8566,9 +8564,8 @@ Address XCoreABIInfo::EmitVAArg(CodeGenF
 
   // Increment the VAList.
   if (!ArgSize.isZero()) {
-llvm::Value *APN =
-  Builder.CreateConstInBoundsByteGEP(AP.getPointer(), ArgSize);
-Builder.CreateStore(APN, VAListAddr);
+Address APN = Builder.CreateConstInBoundsByteGEP(AP, ArgSize);
+Builder.CreateStore(APN.getPointer(), VAListAddr);
   }
 
   return Val;


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


r353199 - [opaque pointer types] More trivial changes to pass FunctionType to CallInst.

2019-02-05 Thread James Y Knight via cfe-commits
Author: jyknight
Date: Tue Feb  5 11:17:50 2019
New Revision: 353199

URL: http://llvm.org/viewvc/llvm-project?rev=353199&view=rev
Log:
[opaque pointer types] More trivial changes to pass FunctionType to CallInst.

Change various functions to use FunctionCallee or Function*.

Pass function type through __builtin_dump_struct's dumpRecord helper.

Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/CodeGen/CGVTables.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=353199&r1=353198&r2=353199&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Tue Feb  5 11:17:50 2019
@@ -1331,8 +1331,8 @@ EmitCheckedMixedSignMultiply(CodeGenFunc
 }
 
 static llvm::Value *dumpRecord(CodeGenFunction &CGF, QualType RType,
-   Value *&RecordPtr, CharUnits Align, Value *Func,
-   int Lvl) {
+   Value *&RecordPtr, CharUnits Align,
+   llvm::FunctionCallee Func, int Lvl) {
   const auto *RT = RType->getAs();
   ASTContext &Context = CGF.getContext();
   RecordDecl *RD = RT->getDecl()->getDefinition();
@@ -1736,6 +1736,10 @@ RValue CodeGenFunction::EmitBuiltinExpr(
   }
 
   case Builtin::BI__builtin_dump_struct: {
+llvm::Type *LLVMIntTy = getTypes().ConvertType(getContext().IntTy);
+llvm::FunctionType *LLVMFuncType = llvm::FunctionType::get(
+LLVMIntTy, {llvm::Type::getInt8PtrTy(getLLVMContext())}, true);
+
 Value *Func = EmitScalarExpr(E->getArg(1)->IgnoreImpCasts());
 CharUnits Arg0Align = 
EmitPointerWithAlignment(E->getArg(0)).getAlignment();
 
@@ -1743,7 +1747,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(
 QualType Arg0Type = Arg0->getType()->getPointeeType();
 
 Value *RecordPtr = EmitScalarExpr(Arg0);
-Value *Res = dumpRecord(*this, Arg0Type, RecordPtr, Arg0Align, Func, 0);
+Value *Res = dumpRecord(*this, Arg0Type, RecordPtr, Arg0Align,
+{LLVMFuncType, Func}, 0);
 return RValue::get(Res);
   }
 

Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=353199&r1=353198&r2=353199&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Tue Feb  5 11:17:50 2019
@@ -2201,7 +2201,7 @@ void CodeGenFunction::pushRegularPartial
 }
 
 /// Lazily declare the @llvm.lifetime.start intrinsic.
-llvm::Constant *CodeGenModule::getLLVMLifetimeStartFn() {
+llvm::Function *CodeGenModule::getLLVMLifetimeStartFn() {
   if (LifetimeStartFn)
 return LifetimeStartFn;
   LifetimeStartFn = llvm::Intrinsic::getDeclaration(&getModule(),
@@ -2210,7 +2210,7 @@ llvm::Constant *CodeGenModule::getLLVMLi
 }
 
 /// Lazily declare the @llvm.lifetime.end intrinsic.
-llvm::Constant *CodeGenModule::getLLVMLifetimeEndFn() {
+llvm::Function *CodeGenModule::getLLVMLifetimeEndFn() {
   if (LifetimeEndFn)
 return LifetimeEndFn;
   LifetimeEndFn = llvm::Intrinsic::getDeclaration(&getModule(),

Modified: cfe/trunk/lib/CodeGen/CGVTables.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVTables.cpp?rev=353199&r1=353198&r2=353199&view=diff
==
--- cfe/trunk/lib/CodeGen/CGVTables.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVTables.cpp Tue Feb  5 11:17:50 2019
@@ -278,7 +278,7 @@ void CodeGenFunction::FinishThunk() {
   FinishFunction();
 }
 
-void CodeGenFunction::EmitCallAndReturnForThunk(llvm::Constant *CalleePtr,
+void CodeGenFunction::EmitCallAndReturnForThunk(llvm::FunctionCallee Callee,
 const ThunkInfo *Thunk,
 bool IsUnprototyped) {
   assert(isa(CurGD.getDecl()) &&
@@ -303,7 +303,7 @@ void CodeGenFunction::EmitCallAndReturnF
 CGM.ErrorUnsupported(
 MD, "non-trivial argument copy for return-adjusting thunk");
 }
-EmitMustTailThunk(CurGD, AdjustedThisPtr, CalleePtr);
+EmitMustTailThunk(CurGD, AdjustedThisPtr, Callee);
 return;
   }
 
@@ -354,8 +354,8 @@ void CodeGenFunction::EmitCallAndReturnF
 
   // Now emit our call.
   llvm::CallBase *CallOrInvoke;
-  CGCallee Callee = CGCallee::forDirect(CalleePtr, CurGD);
-  RValue RV = EmitCall(*CurFnInfo, Callee, Slot, CallArgs, &CallOrInvoke);
+  RValue RV = EmitCall(*CurFnInfo, CGCallee::forDirect(Callee, CurGD), Slot,
+   CallArgs, &CallOrInvoke);
 
   // Consider return adjustment if we have ThunkInfo.
   if (Thunk && !Thunk

r353246 - Fix MSVC constructor call extension after b92d290e48e9 (r353181).

2019-02-05 Thread James Y Knight via cfe-commits
Author: jyknight
Date: Tue Feb  5 16:06:03 2019
New Revision: 353246

URL: http://llvm.org/viewvc/llvm-project?rev=353246&view=rev
Log:
Fix MSVC constructor call extension after b92d290e48e9 (r353181).

The assert added to EmitCall there was triggering in Windows Chromium
builds, due to a mismatch of the return type.

The MSVC constructor call extension (`this->Foo::Foo()`) was emitting
the constructor call from 'EmitCXXMemberOrOperatorMemberCallExpr' via
calling 'EmitCXXMemberOrOperatorCall', instead of
'EmitCXXConstructorCall'. On targets where HasThisReturn is true, that
was failing to set the proper return type in the call info.

Switching to calling EmitCXXConstructorCall also allowed removing some
code e.g. the trivial copy/move support, which is already handled in
EmitCXXConstructorCall.

Ref: https://bugs.chromium.org/p/chromium/issues/detail?id=928861
Differential Revision: https://reviews.llvm.org/D57794

Modified:
cfe/trunk/lib/CodeGen/CGExprCXX.cpp
cfe/trunk/test/CodeGenCXX/constructor-direct-call.cpp

Modified: cfe/trunk/lib/CodeGen/CGExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprCXX.cpp?rev=353246&r1=353245&r2=353246&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExprCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprCXX.cpp Tue Feb  5 16:06:03 2019
@@ -249,13 +249,25 @@ RValue CodeGenFunction::EmitCXXMemberOrO
 This = EmitLValue(Base);
   }
 
+  if (const CXXConstructorDecl *Ctor = dyn_cast(MD)) {
+// This is the MSVC p->Ctor::Ctor(...) extension. We assume that's
+// constructing a new complete object of type Ctor.
+assert(!RtlArgs);
+assert(ReturnValue.isNull() && "Constructor shouldn't have return value");
+CallArgList Args;
+commonEmitCXXMemberOrOperatorCall(
+*this, Ctor, This.getPointer(), /*ImplicitParam=*/nullptr,
+/*ImplicitParamTy=*/QualType(), CE, Args, nullptr);
+
+EmitCXXConstructorCall(Ctor, Ctor_Complete, /*ForVirtualBase=*/false,
+   /*Delegating=*/false, This.getAddress(), Args,
+   AggValueSlot::DoesNotOverlap, CE->getExprLoc(),
+   /*NewPointerIsChecked=*/false);
+return RValue::get(nullptr);
+  }
 
   if (MD->isTrivial() || (MD->isDefaulted() && MD->getParent()->isUnion())) {
 if (isa(MD)) return RValue::get(nullptr);
-if (isa(MD) &&
-cast(MD)->isDefaultConstructor())
-  return RValue::get(nullptr);
-
 if (!MD->getParent()->mayInsertExtraPadding()) {
   if (MD->isCopyAssignmentOperator() || MD->isMoveAssignmentOperator()) {
 // We don't like to generate the trivial copy/move assignment operator
@@ -268,20 +280,6 @@ RValue CodeGenFunction::EmitCXXMemberOrO
 EmitAggregateAssign(This, RHS, CE->getType());
 return RValue::get(This.getPointer());
   }
-
-  if (isa(MD) &&
-  cast(MD)->isCopyOrMoveConstructor()) {
-// Trivial move and copy ctor are the same.
-assert(CE->getNumArgs() == 1 && "unexpected argcount for trivial 
ctor");
-const Expr *Arg = *CE->arg_begin();
-LValue RHS = EmitLValue(Arg);
-LValue Dest = MakeAddrLValue(This.getAddress(), Arg->getType());
-// This is the MSVC p->Ctor::Ctor(...) extension. We assume that's
-// constructing a new complete object of type Ctor.
-EmitAggregateCopy(Dest, RHS, Arg->getType(),
-  AggValueSlot::DoesNotOverlap);
-return RValue::get(This.getPointer());
-  }
   llvm_unreachable("unknown trivial member function");
 }
   }
@@ -293,9 +291,6 @@ RValue CodeGenFunction::EmitCXXMemberOrO
   if (const auto *Dtor = dyn_cast(CalleeDecl))
 FInfo = &CGM.getTypes().arrangeCXXStructorDeclaration(
 Dtor, StructorType::Complete);
-  else if (const auto *Ctor = dyn_cast(CalleeDecl))
-FInfo = &CGM.getTypes().arrangeCXXStructorDeclaration(
-Ctor, StructorType::Complete);
   else
 FInfo = &CGM.getTypes().arrangeCXXMethodDeclaration(CalleeDecl);
 
@@ -318,11 +313,9 @@ RValue CodeGenFunction::EmitCXXMemberOrO
 if (IsImplicitObjectCXXThis || isa(IOA))
   SkippedChecks.set(SanitizerKind::Null, true);
   }
-  EmitTypeCheck(
-  isa(CalleeDecl) ? 
CodeGenFunction::TCK_ConstructorCall
-  : CodeGenFunction::TCK_MemberCall,
-  CallLoc, This.getPointer(), C.getRecordType(CalleeDecl->getParent()),
-  /*Alignment=*/CharUnits::Zero(), SkippedChecks);
+  EmitTypeCheck(CodeGenFunction::TCK_MemberCall, CallLoc, This.getPointer(),
+C.getRecordType(CalleeDecl->getParent()),
+/*Alignment=*/CharUnits::Zero(), SkippedChecks);
 
   // C++ [class.virtual]p12:
   //   Explicit qualification with the scope operator (5.1) suppresses the
@@ -366,11 +359,7 @@ RValue CodeGenFunction::EmitCXXMemberOrO
   // 'CalleeDecl' instead.
 
   CGCallee Callee;
-  if (c

r353355 - [opaque pointer types] Pass through function types for TLS

2019-02-06 Thread James Y Knight via cfe-commits
Author: jyknight
Date: Wed Feb  6 17:14:17 2019
New Revision: 353355

URL: http://llvm.org/viewvc/llvm-project?rev=353355&view=rev
Log:
[opaque pointer types] Pass through function types for TLS
initialization and global destructor calls.

Differential Revision: https://reviews.llvm.org/D57801

Modified:
cfe/trunk/lib/CodeGen/CGCXX.cpp
cfe/trunk/lib/CodeGen/CGCXXABI.h
cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp

Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=353355&r1=353354&r2=353355&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Wed Feb  6 17:14:17 2019
@@ -227,10 +227,11 @@ llvm::Function *CodeGenModule::codegenCX
   return Fn;
 }
 
-llvm::Constant *CodeGenModule::getAddrOfCXXStructor(
+llvm::FunctionCallee CodeGenModule::getAddrAndTypeOfCXXStructor(
 const CXXMethodDecl *MD, StructorType Type, const CGFunctionInfo *FnInfo,
 llvm::FunctionType *FnType, bool DontDefer,
 ForDefinition_t IsForDefinition) {
+
   GlobalDecl GD;
   if (auto *CD = dyn_cast(MD)) {
 GD = GlobalDecl(CD, toCXXCtorType(Type));
@@ -249,9 +250,10 @@ llvm::Constant *CodeGenModule::getAddrOf
 FnType = getTypes().GetFunctionType(*FnInfo);
   }
 
-  return GetOrCreateLLVMFunction(
+  llvm::Constant *Ptr = GetOrCreateLLVMFunction(
   getMangledName(GD), FnType, GD, /*ForVTable=*/false, DontDefer,
   /*isThunk=*/false, /*ExtraAttrs=*/llvm::AttributeList(), 
IsForDefinition);
+  return {FnType, Ptr};
 }
 
 static CGCallee BuildAppleKextVirtualCall(CodeGenFunction &CGF,

Modified: cfe/trunk/lib/CodeGen/CGCXXABI.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXXABI.h?rev=353355&r1=353354&r2=353355&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCXXABI.h (original)
+++ cfe/trunk/lib/CodeGen/CGCXXABI.h Wed Feb  6 17:14:17 2019
@@ -556,7 +556,7 @@ public:
   /// \param Dtor - a function taking a single pointer argument
   /// \param Addr - a pointer to pass to the destructor function.
   virtual void registerGlobalDtor(CodeGenFunction &CGF, const VarDecl &D,
-  llvm::Constant *Dtor,
+  llvm::FunctionCallee Dtor,
   llvm::Constant *Addr) = 0;
 
   /*** thread_local initialization 
/

Modified: cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDeclCXX.cpp?rev=353355&r1=353354&r2=353355&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDeclCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDeclCXX.cpp Wed Feb  6 17:14:17 2019
@@ -97,7 +97,7 @@ static void EmitDeclDestroy(CodeGenFunct
 return;
   }
 
-  llvm::Constant *Func;
+  llvm::FunctionCallee Func;
   llvm::Constant *Argument;
 
   // Special-case non-array C++ destructors, if they have the right signature.
@@ -117,7 +117,7 @@ static void EmitDeclDestroy(CodeGenFunct
 assert(!Record->hasTrivialDestructor());
 CXXDestructorDecl *Dtor = Record->getDestructor();
 
-Func = CGM.getAddrOfCXXStructor(Dtor, StructorType::Complete);
+Func = CGM.getAddrAndTypeOfCXXStructor(Dtor, StructorType::Complete);
 Argument = llvm::ConstantExpr::getBitCast(
 Addr.getPointer(), CGF.getTypes().ConvertType(Type)->getPointerTo());
 
@@ -214,8 +214,8 @@ void CodeGenFunction::EmitCXXGlobalVarDe
 
 /// Create a stub function, suitable for being passed to atexit,
 /// which passes the given address to the given destructor function.
-llvm::Constant *CodeGenFunction::createAtExitStub(const VarDecl &VD,
-  llvm::Constant *dtor,
+llvm::Function *CodeGenFunction::createAtExitStub(const VarDecl &VD,
+  llvm::FunctionCallee dtor,
   llvm::Constant *addr) {
   // Get the destructor function type, void(*)(void).
   llvm::FunctionType *ty = llvm::FunctionType::get(CGM.VoidTy, false);
@@ -238,7 +238,7 @@ llvm::Constant *CodeGenFunction::createA
 
  // Make sure the call and the callee agree on calling convention.
   if (llvm::Function *dtorFn =
-dyn_cast(dtor->stripPointerCasts()))
+  dyn_cast(dtor.getCallee()->stripPointerCasts()))
 call->setCallingConv(dtorFn->getCallingConv());
 
   CGF.FinishFunction();
@@ -248,7 +248,7 @@ llvm::Constant *CodeGenFunction::createA
 
 /// Register a global destructor using the C atexit runtime function.
 void CodeGenFunction::regist

r353356 - [opaque pointer types] Make EmitCall pass Function Types to

2019-02-06 Thread James Y Knight via cfe-commits
Author: jyknight
Date: Wed Feb  6 17:15:41 2019
New Revision: 353356

URL: http://llvm.org/viewvc/llvm-project?rev=353356&view=rev
Log:
[opaque pointer types] Make EmitCall pass Function Types to
CreateCall/Invoke.

Also, remove the getFunctionType() function from CGCallee, since it
accesses the pointee type of the value. The only use was in EmitCall,
so just inline it into the debug assertion.

This is the last of the changes for Call and Invoke in clang.

Differential Revision: https://reviews.llvm.org/D57804

Modified:
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/CGCall.h

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=353356&r1=353355&r2=353356&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Wed Feb  6 17:15:41 2019
@@ -3826,7 +3826,7 @@ RValue CodeGenFunction::EmitCall(const C
   QualType RetTy = CallInfo.getReturnType();
   const ABIArgInfo &RetAI = CallInfo.getReturnInfo();
 
-  llvm::FunctionType *IRFuncTy = Callee.getFunctionType();
+  llvm::FunctionType *IRFuncTy = getTypes().GetFunctionType(CallInfo);
 
 #ifndef NDEBUG
   if (!(CallInfo.isVariadic() && CallInfo.getArgStruct())) {
@@ -3837,8 +3837,13 @@ RValue CodeGenFunction::EmitCall(const C
 //
 // In other cases, we assert that the types match up (until pointers stop
 // having pointee types).
-llvm::FunctionType *IRFuncTyFromInfo = 
getTypes().GetFunctionType(CallInfo);
-assert(IRFuncTy == IRFuncTyFromInfo);
+llvm::Type *TypeFromVal;
+if (Callee.isVirtual())
+  TypeFromVal = Callee.getVirtualFunctionType();
+else
+  TypeFromVal =
+  Callee.getFunctionPointer()->getType()->getPointerElementType();
+assert(IRFuncTy == TypeFromVal);
   }
 #endif
 
@@ -4207,8 +4212,8 @@ RValue CodeGenFunction::EmitCall(const C
   // cases, we can't do any parameter mismatch checks.  Give up and bitcast
   // the callee.
   unsigned CalleeAS = CalleePtr->getType()->getPointerAddressSpace();
-  auto FnTy = getTypes().GetFunctionType(CallInfo)->getPointerTo(CalleeAS);
-  CalleePtr = Builder.CreateBitCast(CalleePtr, FnTy);
+  CalleePtr =
+  Builder.CreateBitCast(CalleePtr, IRFuncTy->getPointerTo(CalleeAS));
 } else {
   llvm::Type *LastParamTy =
   IRFuncTy->getParamType(IRFuncTy->getNumParams() - 1);
@@ -4240,19 +4245,20 @@ RValue CodeGenFunction::EmitCall(const C
   //
   // This makes the IR nicer, but more importantly it ensures that we
   // can inline the function at -O0 if it is marked always_inline.
-  auto simplifyVariadicCallee = [](llvm::Value *Ptr) -> llvm::Value* {
-llvm::FunctionType *CalleeFT =
-  cast(Ptr->getType()->getPointerElementType());
+  auto simplifyVariadicCallee = [](llvm::FunctionType *CalleeFT,
+   llvm::Value *Ptr) -> llvm::Function * {
 if (!CalleeFT->isVarArg())
-  return Ptr;
+  return nullptr;
 
-llvm::ConstantExpr *CE = dyn_cast(Ptr);
-if (!CE || CE->getOpcode() != llvm::Instruction::BitCast)
-  return Ptr;
+// Get underlying value if it's a bitcast
+if (llvm::ConstantExpr *CE = dyn_cast(Ptr)) {
+  if (CE->getOpcode() == llvm::Instruction::BitCast)
+Ptr = CE->getOperand(0);
+}
 
-llvm::Function *OrigFn = dyn_cast(CE->getOperand(0));
+llvm::Function *OrigFn = dyn_cast(Ptr);
 if (!OrigFn)
-  return Ptr;
+  return nullptr;
 
 llvm::FunctionType *OrigFT = OrigFn->getFunctionType();
 
@@ -4261,15 +4267,19 @@ RValue CodeGenFunction::EmitCall(const C
 if (OrigFT->isVarArg() ||
 OrigFT->getNumParams() != CalleeFT->getNumParams() ||
 OrigFT->getReturnType() != CalleeFT->getReturnType())
-  return Ptr;
+  return nullptr;
 
 for (unsigned i = 0, e = OrigFT->getNumParams(); i != e; ++i)
   if (OrigFT->getParamType(i) != CalleeFT->getParamType(i))
-return Ptr;
+return nullptr;
 
 return OrigFn;
   };
-  CalleePtr = simplifyVariadicCallee(CalleePtr);
+
+  if (llvm::Function *OrigFn = simplifyVariadicCallee(IRFuncTy, CalleePtr)) {
+CalleePtr = OrigFn;
+IRFuncTy = OrigFn->getFunctionType();
+  }
 
   // 3. Perform the actual call.
 
@@ -4364,10 +4374,10 @@ RValue CodeGenFunction::EmitCall(const C
   // Emit the actual call/invoke instruction.
   llvm::CallBase *CI;
   if (!InvokeDest) {
-CI = Builder.CreateCall(CalleePtr, IRCallArgs, BundleList);
+CI = Builder.CreateCall(IRFuncTy, CalleePtr, IRCallArgs, BundleList);
   } else {
 llvm::BasicBlock *Cont = createBasicBlock("invoke.cont");
-CI = Builder.CreateInvoke(CalleePtr, Cont, InvokeDest, IRCallArgs,
+CI = Builder.CreateInvoke(IRFuncTy, CalleePtr, Cont, InvokeDest, 
IRCallArgs,
   BundleList);
 EmitBlock(Cont);
   }
@@ -4591,7 +4601,7 @@ CGCallee CGCallee::pr

r353629 - [opaque pointer types] Cleanup CGBuilder's Create*GEP.

2019-02-09 Thread James Y Knight via cfe-commits
Author: jyknight
Date: Sat Feb  9 14:22:28 2019
New Revision: 353629

URL: http://llvm.org/viewvc/llvm-project?rev=353629&view=rev
Log:
[opaque pointer types] Cleanup CGBuilder's Create*GEP.

The various EltSize, Offset, DataLayout, and StructLayout arguments
are all computable from the Address's element type and the DataLayout
which the CGBuilder already has access to.

After having previously asserted that the computed values are the same
as those passed in, now remove the redundant arguments from
CGBuilder's Create*GEP functions.

Differential Revision: https://reviews.llvm.org/D57767

Modified:
cfe/trunk/lib/CodeGen/CGAtomic.cpp
cfe/trunk/lib/CodeGen/CGBlocks.cpp
cfe/trunk/lib/CodeGen/CGBuilder.h
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/CGCleanup.cpp
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGExprAgg.cpp
cfe/trunk/lib/CodeGen/CGExprComplex.cpp
cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
cfe/trunk/lib/CodeGen/CGObjCMac.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/CodeGen/TargetInfo.cpp

Modified: cfe/trunk/lib/CodeGen/CGAtomic.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGAtomic.cpp?rev=353629&r1=353628&r2=353629&view=diff
==
--- cfe/trunk/lib/CodeGen/CGAtomic.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGAtomic.cpp Sat Feb  9 14:22:28 2019
@@ -201,7 +201,7 @@ namespace {
   assert(LVal.isSimple());
   Address addr = getAtomicAddress();
   if (hasPadding())
-addr = CGF.Builder.CreateStructGEP(addr, 0, CharUnits());
+addr = CGF.Builder.CreateStructGEP(addr, 0);
 
   return LValue::MakeAddr(addr, getValueType(), CGF.getContext(),
   LVal.getBaseInfo(), LVal.getTBAAInfo());
@@ -1356,7 +1356,7 @@ RValue AtomicInfo::convertAtomicTempToRV
 
 // Drill into the padding structure if we have one.
 if (hasPadding())
-  addr = CGF.Builder.CreateStructGEP(addr, 0, CharUnits());
+  addr = CGF.Builder.CreateStructGEP(addr, 0);
 
 // Otherwise, just convert the temporary to an r-value using the
 // normal conversion routine.

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=353629&r1=353628&r2=353629&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Sat Feb  9 14:22:28 2019
@@ -836,9 +836,8 @@ static void enterBlockScope(CodeGenFunct
 }
 
 // GEP down to the address.
-Address addr = CGF.Builder.CreateStructGEP(blockInfo.LocalAddress,
-   capture.getIndex(),
-   capture.getOffset());
+Address addr =
+CGF.Builder.CreateStructGEP(blockInfo.LocalAddress, 
capture.getIndex());
 
 // We can use that GEP as the dominating IP.
 if (!blockInfo.DominatingIP)
@@ -975,27 +974,24 @@ llvm::Value *CodeGenFunction::EmitBlockL
   flags |= BLOCK_IS_NOESCAPE | BLOCK_IS_GLOBAL;
   }
 
-  auto projectField =
-[&](unsigned index, CharUnits offset, const Twine &name) -> Address {
-  return Builder.CreateStructGEP(blockAddr, index, offset, name);
-};
-  auto storeField =
-[&](llvm::Value *value, unsigned index, CharUnits offset,
-const Twine &name) {
-  Builder.CreateStore(value, projectField(index, offset, name));
-};
+  auto projectField = [&](unsigned index, const Twine &name) -> Address {
+return Builder.CreateStructGEP(blockAddr, index, name);
+  };
+  auto storeField = [&](llvm::Value *value, unsigned index, const Twine &name) 
{
+Builder.CreateStore(value, projectField(index, name));
+  };
 
   // Initialize the block header.
   {
 // We assume all the header fields are densely packed.
 unsigned index = 0;
 CharUnits offset;
-auto addHeaderField =
-  [&](llvm::Value *value, CharUnits size, const Twine &name) {
-storeField(value, index, offset, name);
-offset += size;
-index++;
-  };
+auto addHeaderField = [&](llvm::Value *value, CharUnits size,
+  const Twine &name) {
+  storeField(value, index, name);
+  offset += size;
+  index++;
+};
 
 if (!IsOpenCL) {
   addHeaderField(isa, getPointerSize(), "block.isa");
@@ -1031,8 +1027,8 @@ llvm::Value *CodeGenFunction::EmitBlockL
 
   // First, 'this'.
   if (blockDecl->capturesCXXThis()) {
-Address addr = projectField(blockInfo.CXXThisIndex, 
blockInfo.CXXThisOffset,
-  

r361429 - Add back --sysroot support for darwin header search.

2019-05-22 Thread James Y Knight via cfe-commits
Author: jyknight
Date: Wed May 22 13:39:51 2019
New Revision: 361429

URL: http://llvm.org/viewvc/llvm-project?rev=361429&view=rev
Log:
Add back --sysroot support for darwin header search.

Before e97b5f5cf37e ([clang][Darwin] Refactor header search path logic
into the driver), both --sysroot and -isysroot worked to specify where
to look for system and C++ headers on Darwin. However, that change
caused clang to start ignoring --sysroot.

This fixes the regression, and adds tests.

(I also note that on all other platforms, clang seems to almost
completely ignore -isysroot, but that's another issue...)

Differential Revision: https://reviews.llvm.org/D62268

Modified:
cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
cfe/trunk/lib/Driver/ToolChains/Darwin.h
cfe/trunk/test/Driver/darwin-header-search-libcxx.cpp
cfe/trunk/test/Driver/darwin-header-search-system.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Darwin.cpp?rev=361429&r1=361428&r2=361429&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Darwin.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Darwin.cpp Wed May 22 13:39:51 2019
@@ -1805,13 +1805,21 @@ void Darwin::AddDeploymentTarget(Derived
   }
 }
 
+// Returns the effective header sysroot path to use. This comes either from
+// -isysroot or --sysroot.
+llvm::StringRef DarwinClang::GetHeaderSysroot(const llvm::opt::ArgList 
&DriverArgs) const {
+  if(DriverArgs.hasArg(options::OPT_isysroot))
+return DriverArgs.getLastArgValue(options::OPT_isysroot);
+  if (!getDriver().SysRoot.empty())
+return getDriver().SysRoot;
+  return "/";
+}
+
 void DarwinClang::AddClangSystemIncludeArgs(const llvm::opt::ArgList 
&DriverArgs,
 llvm::opt::ArgStringList &CC1Args) 
const {
   const Driver &D = getDriver();
 
-  llvm::StringRef Sysroot = "/";
-  if (const Arg *A = DriverArgs.getLastArg(options::OPT_isysroot))
-Sysroot = A->getValue();
+  llvm::StringRef Sysroot = GetHeaderSysroot(DriverArgs);
 
   bool NoStdInc = DriverArgs.hasArg(options::OPT_nostdinc);
   bool NoStdlibInc = DriverArgs.hasArg(options::OPT_nostdlibinc);
@@ -1897,12 +1905,7 @@ void DarwinClang::AddClangCXXStdlibInclu
   DriverArgs.hasArg(options::OPT_nostdincxx))
 return;
 
-  llvm::SmallString<128> Sysroot;
-  if (const Arg *A = DriverArgs.getLastArg(options::OPT_isysroot)) {
-Sysroot = A->getValue();
-  } else {
-Sysroot = "/";
-  }
+  llvm::StringRef Sysroot = GetHeaderSysroot(DriverArgs);
 
   switch (GetCXXStdlibType(DriverArgs)) {
   case ToolChain::CST_Libcxx: {

Modified: cfe/trunk/lib/Driver/ToolChains/Darwin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Darwin.h?rev=361429&r1=361428&r2=361429&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Darwin.h (original)
+++ cfe/trunk/lib/Driver/ToolChains/Darwin.h Wed May 22 13:39:51 2019
@@ -539,6 +539,8 @@ private:
llvm::StringRef Version,
llvm::StringRef ArchDir,
llvm::StringRef BitDir) const;
+
+  llvm::StringRef GetHeaderSysroot(const llvm::opt::ArgList &DriverArgs) const;
 };
 
 } // end namespace toolchains

Modified: cfe/trunk/test/Driver/darwin-header-search-libcxx.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/darwin-header-search-libcxx.cpp?rev=361429&r1=361428&r2=361429&view=diff
==
--- cfe/trunk/test/Driver/darwin-header-search-libcxx.cpp (original)
+++ cfe/trunk/test/Driver/darwin-header-search-libcxx.cpp Wed May 22 13:39:51 
2019
@@ -36,6 +36,7 @@
 
 // Check with both headers in the sysroot and headers alongside the 
installation
 // (the headers in  should be added after the toolchain headers).
+// Ensure that both -isysroot and --sysroot work, and that isysroot has 
precedence.
 //
 // RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
 // RUN: -target x86_64-apple-darwin \
@@ -46,6 +47,28 @@
 // RUN:   | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr \
 // RUN:   -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain \
 // RUN:   --check-prefix=CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1 %s
+//
+// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
+// RUN: -target x86_64-apple-darwin \
+// RUN: -stdlib=libc++ \
+// RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain/usr/bin \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot %S/Inputs/basic_darwin_sdk_usr \
+// RUN:   | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr \
+// RUN:   -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain \
+// RUN:   --check-prefix=CHECK-LIBCXX-SYSROOT_AND_T

r372492 - NFC: Change ObjCQualified*TypesAreCompatible to take

2019-09-21 Thread James Y Knight via cfe-commits
Author: jyknight
Date: Sat Sep 21 15:31:28 2019
New Revision: 372492

URL: http://llvm.org/viewvc/llvm-project?rev=372492&view=rev
Log:
NFC: Change ObjCQualified*TypesAreCompatible to take
ObjCObjectPointerType arguments.

All callers already had one, just creating a QualType to pass, after
which the function cast it right back.

Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=372492&r1=372491&r2=372492&view=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Sat Sep 21 15:31:28 2019
@@ -2583,10 +2583,12 @@ public:
 return T == getObjCSelType();
   }
 
-  bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS,
+  bool ObjCQualifiedIdTypesAreCompatible(const ObjCObjectPointerType *LHS,
+ const ObjCObjectPointerType *RHS,
  bool ForCompare);
 
-  bool ObjCQualifiedClassTypesAreCompatible(QualType LHS, QualType RHS);
+  bool ObjCQualifiedClassTypesAreCompatible(const ObjCObjectPointerType *LHS,
+const ObjCObjectPointerType *RHS);
 
   // Check the safety of assignment from LHS to RHS
   bool canAssignObjCInterfaces(const ObjCObjectPointerType *LHSOPT,

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=372492&r1=372491&r2=372492&view=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Sat Sep 21 15:31:28 2019
@@ -7998,15 +7998,11 @@ ASTContext::ProtocolCompatibleWithProtoc
 
 /// ObjCQualifiedClassTypesAreCompatible - compare  Class and
 /// Class.
-bool ASTContext::ObjCQualifiedClassTypesAreCompatible(QualType lhs,
-  QualType rhs) {
-  const auto *lhsQID = lhs->getAs();
-  const auto *rhsOPT = rhs->getAs();
-  assert((lhsQID && rhsOPT) && "ObjCQualifiedClassTypesAreCompatible");
-
-  for (auto *lhsProto : lhsQID->quals()) {
+bool ASTContext::ObjCQualifiedClassTypesAreCompatible(
+const ObjCObjectPointerType *lhs, const ObjCObjectPointerType *rhs) {
+  for (auto *lhsProto : lhs->quals()) {
 bool match = false;
-for (auto *rhsProto : rhsOPT->quals()) {
+for (auto *rhsProto : rhs->quals()) {
   if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto)) {
 match = true;
 break;
@@ -8020,8 +8016,9 @@ bool ASTContext::ObjCQualifiedClassTypes
 
 /// ObjCQualifiedIdTypesAreCompatible - We know that one of lhs/rhs is an
 /// ObjCQualifiedIDType.
-bool ASTContext::ObjCQualifiedIdTypesAreCompatible(QualType lhs, QualType rhs,
-   bool compare) {
+bool ASTContext::ObjCQualifiedIdTypesAreCompatible(
+const ObjCObjectPointerType *lhs, const ObjCObjectPointerType *rhs,
+bool compare) {
   // Allow id and an 'id' or void* type in all cases.
   if (lhs->isVoidPointerType() ||
   lhs->isObjCIdType() || lhs->isObjCClassType())
@@ -8030,16 +8027,12 @@ bool ASTContext::ObjCQualifiedIdTypesAre
rhs->isObjCIdType() || rhs->isObjCClassType())
 return true;
 
-  if (const ObjCObjectPointerType *lhsQID = lhs->getAsObjCQualifiedIdType()) {
-const auto *rhsOPT = rhs->getAs();
-
-if (!rhsOPT) return false;
-
-if (rhsOPT->qual_empty()) {
+  if (lhs->isObjCQualifiedIdType()) {
+if (rhs->qual_empty()) {
   // If the RHS is a unqualified interface pointer "NSString*",
   // make sure we check the class hierarchy.
-  if (ObjCInterfaceDecl *rhsID = rhsOPT->getInterfaceDecl()) {
-for (auto *I : lhsQID->quals()) {
+  if (ObjCInterfaceDecl *rhsID = rhs->getInterfaceDecl()) {
+for (auto *I : lhs->quals()) {
   // when comparing an id on lhs with a static type on rhs,
   // see if static class implements all of id's protocols, directly or
   // through its super class and categories.
@@ -8051,13 +8044,13 @@ bool ASTContext::ObjCQualifiedIdTypesAre
   return true;
 }
 // Both the right and left sides have qualifiers.
-for (auto *lhsProto : lhsQID->quals()) {
+for (auto *lhsProto : lhs->quals()) {
   bool match = false;
 
   // when comparing an id on lhs with a static type on rhs,
   // see if static class implements all of id's protocols, directly or
   // through its super class and categories.
-  for (auto *rhsProto : rhsOPT->quals()) {
+  for (auto *rhsProto : rhs->quals()) {
 if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto) ||
 (compare && P

r375124 - [ObjC] Add some additional test cases around pointer conversions.

2019-10-17 Thread James Y Knight via cfe-commits
Author: jyknight
Date: Thu Oct 17 08:18:59 2019
New Revision: 375124

URL: http://llvm.org/viewvc/llvm-project?rev=375124&view=rev
Log:
[ObjC] Add some additional test cases around pointer conversions.

This is especially important for Objective-C++, which is entirely
missing this testing at the moment.

This annotates with "FIXME" the cases which I change in the next
patch -- I primarily wanted to document the current state of things so
that the effect of the code change is made clear.

Differential Revision: https://reviews.llvm.org/D67982

Added:
cfe/trunk/test/SemaObjCXX/class-method-self.mm
cfe/trunk/test/SemaObjCXX/comptypes-1.mm
cfe/trunk/test/SemaObjCXX/comptypes-7.mm
Modified:
cfe/trunk/test/SemaObjC/class-method-self.m
cfe/trunk/test/SemaObjC/comptypes-1.m
cfe/trunk/test/SemaObjC/comptypes-7.m
cfe/trunk/test/SemaObjCXX/instancetype.mm

Modified: cfe/trunk/test/SemaObjC/class-method-self.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/class-method-self.m?rev=375124&r1=375123&r2=375124&view=diff
==
--- cfe/trunk/test/SemaObjC/class-method-self.m (original)
+++ cfe/trunk/test/SemaObjC/class-method-self.m Thu Oct 17 08:18:59 2019
@@ -1,6 +1,5 @@
 // RUN: %clang_cc1 -verify -Wno-objc-root-class %s
 
-typedef struct objc_class *Class;
 @interface XX
 
 - (void)addObserver:(XX*)o; // expected-note 2{{passing argument to parameter 
'o' here}}
@@ -23,4 +22,3 @@ static XX *obj;
   [obj addObserver:whatever]; // expected-warning {{incompatible pointer types 
sending 'Class' to parameter of type 'XX *'}}
 }
 @end
-

Modified: cfe/trunk/test/SemaObjC/comptypes-1.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/comptypes-1.m?rev=375124&r1=375123&r2=375124&view=diff
==
--- cfe/trunk/test/SemaObjC/comptypes-1.m (original)
+++ cfe/trunk/test/SemaObjC/comptypes-1.m Thu Oct 17 08:18:59 2019
@@ -1,12 +1,12 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
 
 #define nil (void *)0;
-#define Nil (void *)0;
 
 extern void foo();
 
 @protocol MyProtocol
 - (void) foo;
++ (void) bar;
 @end
 
 @interface MyClass
@@ -22,7 +22,8 @@ int main()
   id obj_p = nil;
   MyClass *obj_c = nil;
   MyOtherClass *obj_cp = nil;
-  Class obj_C = Nil;
+  Class obj_C = nil;
+  Class obj_CP = nil;
 
   /* Assigning to an 'id' variable should never
  generate a warning.  */
@@ -30,12 +31,15 @@ int main()
   obj = obj_c;  /* Ok  */
   obj = obj_cp; /* Ok  */
   obj = obj_C;  /* Ok  */
-  
+  obj = obj_CP;  /* Ok  */
+
   /* Assigning to a 'MyClass *' variable should always generate a
  warning, unless done from an 'id'.  */
   obj_c = obj;/* Ok */
-  obj_c = obj_cp; // // expected-warning {{incompatible pointer types 
assigning to 'MyClass *' from 'MyOtherClass *'}}
+  obj_c = obj_p;  // expected-warning {{assigning to 'MyClass *' from 
incompatible type 'id'}}
+  obj_c = obj_cp; // expected-warning {{incompatible pointer types assigning 
to 'MyClass *' from 'MyOtherClass *'}}
   obj_c = obj_C;  // expected-warning {{incompatible pointer types assigning 
to 'MyClass *' from 'Class'}}
+  obj_c = obj_CP; // expected-warning {{incompatible pointer types assigning 
to 'MyClass *' from 'Class'}}
 
   /* Assigning to an 'id' variable should generate a
  warning if done from a 'MyClass *' (which doesn't implement
@@ -45,6 +49,7 @@ int main()
   obj_p = obj_c;  // expected-warning {{assigning to 'id' from 
incompatible type 'MyClass *'}}
   obj_p = obj_cp; /* Ok  */
   obj_p = obj_C;  // expected-warning {{incompatible pointer types assigning 
to 'id' from 'Class'}}
+  obj_p = obj_CP; // FIXME -- should warn {{assigning to 'id' from 
incompatible type 'Class'}}
 
   /* Assigning to a 'MyOtherClass *' variable should always generate
  a warning, unless done from an 'id' or an 'id' (since
@@ -53,37 +58,67 @@ int main()
   obj_cp = obj_c;  // expected-warning {{incompatible pointer types assigning 
to 'MyOtherClass *' from 'MyClass *'}}
   obj_cp = obj_p;  /* Ok */
   obj_cp = obj_C;  // expected-warning {{incompatible pointer types assigning 
to 'MyOtherClass *' from 'Class'}}
+  obj_cp = obj_CP; // expected-warning {{incompatible pointer types assigning 
to 'MyOtherClass *' from 'Class'}}
+
+  obj_C = obj; // Ok
+  obj_C = obj_p;   // expected-warning {{incompatible pointer types assigning 
to 'Class' from 'id'}}
+  obj_C = obj_c;   // expected-warning {{incompatible pointer types assigning 
to 'Class' from 'MyClass *'}}
+  obj_C = obj_cp;  // expected-warning {{incompatible pointer types assigning 
to 'Class' from 'MyOtherClass *'}}
+  obj_C = obj_CP;  // Ok
+
+  obj_CP = obj; // Ok
+  obj_CP = obj_p;   // expected-warning {{assigning to 'Class' 
from incompatible type 'id'}}
+  obj_CP = obj_c;   // expected-warning {{incompatible pointer types assigning 
to 'Class' from 'MyClass *}}
+  obj_CP = obj

r375125 - [ObjC] Diagnose implicit type coercion from ObjC 'Class' to object

2019-10-17 Thread James Y Knight via cfe-commits
Author: jyknight
Date: Thu Oct 17 08:27:04 2019
New Revision: 375125

URL: http://llvm.org/viewvc/llvm-project?rev=375125&view=rev
Log:
[ObjC] Diagnose implicit type coercion from ObjC 'Class' to object
pointer types.

For example, in Objective-C mode, the initialization of 'x' in:
```
  @implementation MyType
  + (void)someClassMethod {
MyType *x = self;
  }
  @end
```
is correctly diagnosed with an incompatible-pointer-types warning, but
in Objective-C++ mode, it is not diagnosed at all -- even though
incompatible pointer conversions generally become an error in C++.

This patch fixes that oversight, allowing implicit conversions
involving Class only to/from unqualified-id, and between qualified and
unqualified Class, where the protocols are compatible.

Note that this does change some behaviors in Objective-C, as well, as
shown by the modified tests.

Of particular note is that assignment from from 'Class' to
'id' now warns. (Despite appearances, those are not
compatible types. 'Class' is not expected to have instance
methods defined by 'MyProtocol', while 'id' is.)

Differential Revision: https://reviews.llvm.org/D67983

Modified:
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/SemaObjC/comptypes-1.m
cfe/trunk/test/SemaObjCXX/class-method-self.mm
cfe/trunk/test/SemaObjCXX/comptypes-1.mm
cfe/trunk/test/SemaObjCXX/comptypes-7.mm
cfe/trunk/test/SemaObjCXX/instancetype.mm

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=375125&r1=375124&r2=375125&view=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Thu Oct 17 08:27:04 2019
@@ -8025,14 +8025,15 @@ bool ASTContext::ObjCQualifiedClassTypes
 bool ASTContext::ObjCQualifiedIdTypesAreCompatible(
 const ObjCObjectPointerType *lhs, const ObjCObjectPointerType *rhs,
 bool compare) {
-  // Allow id and an 'id' or void* type in all cases.
-  if (lhs->isVoidPointerType() ||
-  lhs->isObjCIdType() || lhs->isObjCClassType())
-return true;
-  else if (rhs->isVoidPointerType() ||
-   rhs->isObjCIdType() || rhs->isObjCClassType())
+  // Allow id and an 'id' in all cases.
+  if (lhs->isObjCIdType() || rhs->isObjCIdType())
 return true;
 
+  // Don't allow id to convert to Class or Class in either direction.
+  if (lhs->isObjCClassType() || lhs->isObjCQualifiedClassType() ||
+  rhs->isObjCClassType() || rhs->isObjCQualifiedClassType())
+return false;
+
   if (lhs->isObjCQualifiedIdType()) {
 if (rhs->qual_empty()) {
   // If the RHS is a unqualified interface pointer "NSString*",
@@ -8142,9 +8143,8 @@ bool ASTContext::canAssignObjCInterfaces
   const ObjCObjectType* LHS = LHSOPT->getObjectType();
   const ObjCObjectType* RHS = RHSOPT->getObjectType();
 
-  // If either type represents the built-in 'id' or 'Class' types, return true.
-  if (LHS->isObjCUnqualifiedIdOrClass() ||
-  RHS->isObjCUnqualifiedIdOrClass())
+  // If either type represents the built-in 'id' type, return true.
+  if (LHS->isObjCUnqualifiedId() || RHS->isObjCUnqualifiedId())
 return true;
 
   // Function object that propagates a successful result or handles
@@ -8162,14 +8162,22 @@ bool ASTContext::canAssignObjCInterfaces
LHSOPT->stripObjCKindOfTypeAndQuals(*this));
   };
 
+  // Casts from or to id are allowed when the other side has compatible
+  // protocols.
   if (LHS->isObjCQualifiedId() || RHS->isObjCQualifiedId()) {
 return finish(ObjCQualifiedIdTypesAreCompatible(LHSOPT, RHSOPT, false));
   }
 
+  // Verify protocol compatibility for casts from Class to Class.
   if (LHS->isObjCQualifiedClass() && RHS->isObjCQualifiedClass()) {
 return finish(ObjCQualifiedClassTypesAreCompatible(LHSOPT, RHSOPT));
   }
 
+  // Casts from Class to Class, or vice-versa, are allowed.
+  if (LHS->isObjCClass() && RHS->isObjCClass()) {
+return true;
+  }
+
   // If we have 2 user-defined types, fall into that path.
   if (LHS->getInterface() && RHS->getInterface()) {
 return finish(canAssignObjCInterfaces(LHS, RHS));

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=375125&r1=375124&r2=375125&view=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Oct 17 08:27:04 2019
@@ -10068,8 +10068,8 @@ static bool convertPointersToCompositeTy
 
   QualType T = S.FindCompositePointerType(Loc, LHS, RHS);
   if (T.isNull()) {
-if ((LHSType->isPointerType() || LHSType->isMemberPointerType()) &&
-(RHSType->isPointerType() || RHSType->isMemberPointerType()))
+if ((LHSType->isAnyPointerType() || LHSType->isMemberPointerType()) &&
+(RHSType->isAnyPointerType() || RHSType-

[clang] aca3d06 - Fix Darwin 'constinit thread_local' variables.

2020-05-27 Thread James Y Knight via cfe-commits

Author: James Y Knight
Date: 2020-05-27T11:59:30-04:00
New Revision: aca3d067efe194539efd1e0fcf03820a2c377753

URL: 
https://github.com/llvm/llvm-project/commit/aca3d067efe194539efd1e0fcf03820a2c377753
DIFF: 
https://github.com/llvm/llvm-project/commit/aca3d067efe194539efd1e0fcf03820a2c377753.diff

LOG: Fix Darwin 'constinit thread_local' variables.

Unlike other platforms using ItaniumCXXABI, Darwin does not allow the
creation of a thread-wrapper function for a variable in the TU of
users. Because of this, it can set the linkage of the thread-local
symbol to internal, with the assumption that no TUs other than the one
defining the variable will need it.

However, constinit thread_local variables do not require the use of
the thread-wrapper call, so users reference the variable
directly. Thus, it must not be converted to internal, or users will
get a link failure.

This was a regression introduced by the optimization in
00223827a952f66e7426c9881a2a4229e59bb019.

Differential Revision: https://reviews.llvm.org/D80417

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGenCXX/cxx2a-thread-local-constinit.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index f43bc6434daf..89a95db08680 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4136,17 +4136,24 @@ void CodeGenModule::EmitGlobalVarDefinition(const 
VarDecl *D,
 
   GV->setAlignment(getContext().getDeclAlign(D).getAsAlign());
 
-  // On Darwin, if the normal linkage of a C++ thread_local variable is
-  // LinkOnce or Weak, we keep the normal linkage to prevent multiple
-  // copies within a linkage unit; otherwise, the backing variable has
-  // internal linkage and all accesses should just be calls to the
-  // Itanium-specified entry point, which has the normal linkage of the
-  // variable. This is to preserve the ability to change the implementation
-  // behind the scenes.
-  if (!D->isStaticLocal() && D->getTLSKind() == VarDecl::TLS_Dynamic &&
+  // On Darwin, unlike other Itanium C++ ABI platforms, the thread-wrapper
+  // function is only defined alongside the variable, not also alongside
+  // callers. Normally, all accesses to a thread_local go through the
+  // thread-wrapper in order to ensure initialization has occurred, underlying
+  // variable will never be used other than the thread-wrapper, so it can be
+  // converted to internal linkage.
+  //
+  // However, if the variable has the 'constinit' attribute, it _can_ be
+  // referenced directly, without calling the thread-wrapper, so the linkage
+  // must not be changed.
+  //
+  // Additionally, if the variable isn't plain external linkage, e.g. if it's
+  // weak or linkonce, the de-duplication semantics are important to preserve,
+  // so we don't change the linkage.
+  if (D->getTLSKind() == VarDecl::TLS_Dynamic &&
+  Linkage == llvm::GlobalValue::ExternalLinkage &&
   Context.getTargetInfo().getTriple().isOSDarwin() &&
-  !llvm::GlobalVariable::isLinkOnceLinkage(Linkage) &&
-  !llvm::GlobalVariable::isWeakLinkage(Linkage))
+  !D->hasAttr())
 Linkage = llvm::GlobalValue::InternalLinkage;
 
   GV->setLinkage(Linkage);

diff  --git a/clang/test/CodeGenCXX/cxx2a-thread-local-constinit.cpp 
b/clang/test/CodeGenCXX/cxx2a-thread-local-constinit.cpp
index f47707555098..99c5d721dc47 100644
--- a/clang/test/CodeGenCXX/cxx2a-thread-local-constinit.cpp
+++ b/clang/test/CodeGenCXX/cxx2a-thread-local-constinit.cpp
@@ -1,41 +1,55 @@
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++2a %s -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++2a %s -emit-llvm -o - | 
FileCheck --check-prefix=CHECK --check-prefix=LINUX %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin12  -std=c++2a %s -emit-llvm -o 
- | FileCheck --check-prefix=CHECK --check-prefix=DARWIN %s
+
+// Check variable definitions/declarations. Note that on Darwin, typically the
+// variable's symbol is marked internal, and only the _ZTW function is
+// exported. Except: constinit variables do get exported, even on darwin.
+
+// CHECK-DAG:  @a = external thread_local global i32
+// CHECK-DAG:  @b = external thread_local global i32
+// LINUX-DAG:  @c = thread_local global i32 0, align 4
+// DARWIN-DAG: @c = internal thread_local global i32 0, align 4
+// LINUX-DAG:  @d = thread_local global i32 0, align 4
+// DARWIN-DAG: @d = internal thread_local global i32 0, align 4
+// CHECK-DAG:  @e = external thread_local global %struct.Destructed, align 4
+// CHECK-DAG:  @e2 = thread_local global %struct.Destructed zeroinitializer, 
align 4
+// CHECK-DAG:  @f = thread_local global i32 4, align 4
 
-// CHECK-DAG: @a = external thread_local global i32
 extern threa

Re: [clang-tools-extra] 7e2d27b - Fix two -Wrange-loop-analysis warnings that Xcode 12 beta incorrectly complains about

2020-07-04 Thread James Y Knight via cfe-commits
Seems like we should disable the warning for this compiler instead of
making the code worse for the benefit of a temporarily broken warning?

On Sat, Jul 4, 2020, 8:42 PM Nico Weber via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

>
> Author: Nico Weber
> Date: 2020-07-04T20:41:33-04:00
> New Revision: 7e2d27bc554eb607c90e55c89d2537f5d711234c
>
> URL:
> https://github.com/llvm/llvm-project/commit/7e2d27bc554eb607c90e55c89d2537f5d711234c
> DIFF:
> https://github.com/llvm/llvm-project/commit/7e2d27bc554eb607c90e55c89d2537f5d711234c.diff
>
> LOG: Fix two -Wrange-loop-analysis warnings that Xcode 12 beta incorrectly
> complains about
>
> Xcode 12 beta apparently has the Wrange-loop-analysis changes from
> half a year ago, but it seems to lack https://reviews.llvm.org/D72212
> which made the warning usable again.
>
> Added:
>
>
> Modified:
> clang-tools-extra/clangd/XRefs.cpp
> clang-tools-extra/clangd/unittests/PreambleTests.cpp
>
> Removed:
>
>
>
>
> 
> diff  --git a/clang-tools-extra/clangd/XRefs.cpp
> b/clang-tools-extra/clangd/XRefs.cpp
> index 9b44edce95da..c208e953f2ab 100644
> --- a/clang-tools-extra/clangd/XRefs.cpp
> +++ b/clang-tools-extra/clangd/XRefs.cpp
> @@ -1049,7 +1049,7 @@ ReferencesResult findReferences(ParsedAST &AST,
> Position Pos, uint32_t Limit,
>const auto &IDToRefs = AST.getMacros().MacroRefs;
>auto Refs = IDToRefs.find(*MacroSID);
>if (Refs != IDToRefs.end()) {
> -for (const auto Ref : Refs->second) {
> +for (const auto &Ref : Refs->second) {
>Location Result;
>Result.range = Ref;
>Result.uri = URIMainFile;
>
> diff  --git a/clang-tools-extra/clangd/unittests/PreambleTests.cpp
> b/clang-tools-extra/clangd/unittests/PreambleTests.cpp
> index 5bbcb292610e..8c9669a945dd 100644
> --- a/clang-tools-extra/clangd/unittests/PreambleTests.cpp
> +++ b/clang-tools-extra/clangd/unittests/PreambleTests.cpp
> @@ -125,7 +125,7 @@ TEST(PreamblePatchTest, IncludeParsing) {
>  #/**/include )cpp",
>};
>
> -  for (const auto Case : Cases) {
> +  for (const auto &Case : Cases) {
>  Annotations Test(Case);
>  const auto Code = Test.code();
>  SCOPED_TRACE(Code);
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 381df16 - Clang Driver: Use Apple ld64's new @response-file support.

2020-06-29 Thread James Y Knight via cfe-commits

Author: James Y Knight
Date: 2020-06-29T18:26:53-04:00
New Revision: 381df1653c927efa9dac86c24a9db2b98f270de0

URL: 
https://github.com/llvm/llvm-project/commit/381df1653c927efa9dac86c24a9db2b98f270de0
DIFF: 
https://github.com/llvm/llvm-project/commit/381df1653c927efa9dac86c24a9db2b98f270de0.diff

LOG: Clang Driver: Use Apple ld64's new @response-file support.

In XCode 12, ld64 got support for @files, in addition to the old
-filelist mechanism. Response files allow passing all command-line
arguments to the linker via a file, rather than just filenames, and is
therefore preferred.

Because of the way response-file support is currently implemented as
part of the Tool class in Clang, this change requires an ugly backdoor
function to access Args. A follow-up commit fixes this, but I've
ordered this change first, for easier backportability.

I've added no tests here, because unfortunately, there don't appear to
be _any_ response-file emission automated tests, and I don't see an
obvious way to add them. I've tested that this change works as
expected locally.

Differential Revision: https://reviews.llvm.org/D82777

Added: 


Modified: 
clang/include/clang/Driver/ToolChain.h
clang/lib/Driver/ToolChains/Darwin.cpp
clang/lib/Driver/ToolChains/Darwin.h

Removed: 




diff  --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index 7495e08fe6e6..0d3727b4ab8d 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -201,6 +201,9 @@ class ToolChain {
 
   // Accessors
 
+  /// Temporary for Darwin::Linker
+  const llvm::opt::ArgList &getArgs_DO_NOT_USE() const { return Args; }
+
   const Driver &getDriver() const { return D; }
   llvm::vfs::FileSystem &getVFS() const;
   const llvm::Triple &getTriple() const { return Triple; }

diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 47bf036d24d8..81b5576096e4 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -929,7 +929,22 @@ Tool *MachO::getTool(Action::ActionClass AC) const {
   }
 }
 
-Tool *MachO::buildLinker() const { return new tools::darwin::Linker(*this); }
+Tool *MachO::buildLinker() const {
+  // Determine whether to use an @responsefile or the old -filelist mechanism.
+  bool UseAtFile = false;
+  unsigned Version[5] = {0, 0, 0, 0, 0};
+  if (Arg *A =
+  getArgs_DO_NOT_USE().getLastArg(options::OPT_mlinker_version_EQ)) {
+// We don't need to diagnose a parse error here, it'll be caught in
+// ConstructJob.
+if (Driver::GetReleaseVersion(A->getValue(), Version)) {
+  if (Version[0] >= 607)
+UseAtFile = true;
+}
+  }
+
+  return new tools::darwin::Linker(*this, UseAtFile);
+}
 
 Tool *MachO::buildAssembler() const {
   return new tools::darwin::Assembler(*this);

diff  --git a/clang/lib/Driver/ToolChains/Darwin.h 
b/clang/lib/Driver/ToolChains/Darwin.h
index 04c5bfa69a5a..5f13aa9a3087 100644
--- a/clang/lib/Driver/ToolChains/Darwin.h
+++ b/clang/lib/Driver/ToolChains/Darwin.h
@@ -69,9 +69,10 @@ class LLVM_LIBRARY_VISIBILITY Linker : public MachOTool {
const InputInfoList &Inputs) const;
 
 public:
-  Linker(const ToolChain &TC)
-  : MachOTool("darwin::Linker", "linker", TC, RF_FileList,
-  llvm::sys::WEM_UTF8, "-filelist") {}
+  Linker(const ToolChain &TC, bool UseAtFile)
+  : MachOTool("darwin::Linker", "linker", TC,
+  UseAtFile ? RF_Full : RF_FileList, llvm::sys::WEM_UTF8,
+  UseAtFile ? "@" : "-filelist") {}
 
   bool hasIntegratedCPP() const override { return false; }
   bool isLinkJob() const override { return true; }



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


[clang] 4772b99 - Clang Driver: refactor support for writing response files to be

2020-06-29 Thread James Y Knight via cfe-commits

Author: James Y Knight
Date: 2020-06-29T18:27:02-04:00
New Revision: 4772b99dffec4f87bb7bc9273495066058ac0186

URL: 
https://github.com/llvm/llvm-project/commit/4772b99dffec4f87bb7bc9273495066058ac0186
DIFF: 
https://github.com/llvm/llvm-project/commit/4772b99dffec4f87bb7bc9273495066058ac0186.diff

LOG: Clang Driver: refactor support for writing response files to be
specified at Command creation, rather than as part of the Tool.

This resolves the hack I just added to allow Darwin toolchain to vary
its level of support based on `-mlinker-version=`.

The change preserves the _current_ settings for response-file support.
Some tools look likely to be declaring that they don't support
response files in error, however I kept them as-is in order for this
change to be a simple refactoring.

Differential Revision: https://reviews.llvm.org/D82782

Added: 


Modified: 
clang/include/clang/Driver/Job.h
clang/include/clang/Driver/Tool.h
clang/include/clang/Driver/ToolChain.h
clang/lib/Driver/Driver.cpp
clang/lib/Driver/Job.cpp
clang/lib/Driver/Tool.cpp
clang/lib/Driver/ToolChains/AIX.cpp
clang/lib/Driver/ToolChains/AMDGPU.cpp
clang/lib/Driver/ToolChains/AMDGPU.h
clang/lib/Driver/ToolChains/AVR.cpp
clang/lib/Driver/ToolChains/AVR.h
clang/lib/Driver/ToolChains/Ananas.cpp
clang/lib/Driver/ToolChains/Ananas.h
clang/lib/Driver/ToolChains/BareMetal.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/Clang.h
clang/lib/Driver/ToolChains/CloudABI.cpp
clang/lib/Driver/ToolChains/CloudABI.h
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/lib/Driver/ToolChains/CrossWindows.cpp
clang/lib/Driver/ToolChains/CrossWindows.h
clang/lib/Driver/ToolChains/Cuda.cpp
clang/lib/Driver/ToolChains/Cuda.h
clang/lib/Driver/ToolChains/Darwin.cpp
clang/lib/Driver/ToolChains/Darwin.h
clang/lib/Driver/ToolChains/DragonFly.cpp
clang/lib/Driver/ToolChains/DragonFly.h
clang/lib/Driver/ToolChains/Flang.cpp
clang/lib/Driver/ToolChains/FreeBSD.cpp
clang/lib/Driver/ToolChains/FreeBSD.h
clang/lib/Driver/ToolChains/Fuchsia.cpp
clang/lib/Driver/ToolChains/Gnu.cpp
clang/lib/Driver/ToolChains/Gnu.h
clang/lib/Driver/ToolChains/HIP.cpp
clang/lib/Driver/ToolChains/Hexagon.cpp
clang/lib/Driver/ToolChains/Hexagon.h
clang/lib/Driver/ToolChains/InterfaceStubs.cpp
clang/lib/Driver/ToolChains/MSP430.cpp
clang/lib/Driver/ToolChains/MSP430.h
clang/lib/Driver/ToolChains/MSVC.cpp
clang/lib/Driver/ToolChains/MSVC.h
clang/lib/Driver/ToolChains/MinGW.cpp
clang/lib/Driver/ToolChains/MinGW.h
clang/lib/Driver/ToolChains/Minix.cpp
clang/lib/Driver/ToolChains/Minix.h
clang/lib/Driver/ToolChains/Myriad.cpp
clang/lib/Driver/ToolChains/Myriad.h
clang/lib/Driver/ToolChains/NaCl.cpp
clang/lib/Driver/ToolChains/NaCl.h
clang/lib/Driver/ToolChains/NetBSD.cpp
clang/lib/Driver/ToolChains/NetBSD.h
clang/lib/Driver/ToolChains/OpenBSD.cpp
clang/lib/Driver/ToolChains/OpenBSD.h
clang/lib/Driver/ToolChains/PS4CPU.cpp
clang/lib/Driver/ToolChains/PS4CPU.h
clang/lib/Driver/ToolChains/RISCVToolchain.cpp
clang/lib/Driver/ToolChains/RISCVToolchain.h
clang/lib/Driver/ToolChains/Solaris.cpp
clang/lib/Driver/ToolChains/WebAssembly.cpp
clang/lib/Driver/ToolChains/WebAssembly.h
clang/lib/Driver/ToolChains/XCore.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Job.h 
b/clang/include/clang/Driver/Job.h
index 1c6ea6971919..6173b9d314b4 100644
--- a/clang/include/clang/Driver/Job.h
+++ b/clang/include/clang/Driver/Job.h
@@ -16,6 +16,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/iterator.h"
 #include "llvm/Option/Option.h"
+#include "llvm/Support/Program.h"
 #include 
 #include 
 #include 
@@ -36,6 +37,69 @@ struct CrashReportInfo {
   : Filename(Filename), VFSPath(VFSPath) {}
 };
 
+// Encodes the kind of response file supported for a command invocation.
+// Response files are necessary if the command line gets too large, requiring
+// the arguments to be transferred to a file.
+struct ResponseFileSupport {
+  enum ResponseFileKind {
+// Provides full support for response files, which means we can transfer
+// all tool input arguments to a file.
+RF_Full,
+// Input file names can live in a file, but flags can't. This is a special
+// case for old versions of Apple's ld64.
+RF_FileList,
+// Does not support response files: all arguments must be passed via
+// command line.
+RF_None
+  };
+  /// The level of support for response files.
+  ResponseFileKind ResponseKind;
+
+  /// The encoding to use when writing response files on Windows. Ignored on
+  /// other host OSes.
+  ///
+  /// Windows use cases: - GCC and Binutils on mingw only accept ANSI res

[clang] [clang] Enhance handling of Apple-specific '-arch'/'-target' option values (PR #72821)

2023-12-04 Thread James Y Knight via cfe-commits

jyknight wrote:

I don't think this is a good idea.

Not only is that weird to magically switch to an apple build from a non-apple 
platform, this is also not even a particularly useful behavior for an Apple 
platform, where "darwin" is basically deprecated, and you're supposed to use a 
target of x86_64-apple-macos11 (or ios/watchos/etc).

https://github.com/llvm/llvm-project/pull/72821
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Mark -arch as TargetSpecific (PR #74365)

2023-12-04 Thread James Y Knight via cfe-commits

https://github.com/jyknight approved this pull request.


https://github.com/llvm/llvm-project/pull/74365
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] Include LLVM_VERSION_SUFFIX in the Clang version string. (PR #74469)

2023-12-05 Thread James Y Knight via cfe-commits

https://github.com/jyknight created 
https://github.com/llvm/llvm-project/pull/74469

This causes current mainline to now report "18.0.0git" instead of "18.0.0".

Fixes #53825

>From 00f710804e77ccc001025a4524ab6882377d1089 Mon Sep 17 00:00:00 2001
From: James Y Knight 
Date: Tue, 5 Dec 2023 08:41:08 -0500
Subject: [PATCH] Include LLVM_VERSION_SUFFIX in the Clang version string.

This causes current mainline to now report "18.0.0git" instead of
"18.0.0".

Fixes #53825
---
 clang/CMakeLists.txt  | 6 --
 clang/test/Frontend/sarif-diagnostics.cpp | 4 ++--
 llvm/utils/UpdateTestChecks/common.py | 2 +-
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index 9b52c58be41e7..65ed790e69c2a 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -290,8 +290,10 @@ endif()
 if(NOT DEFINED CLANG_VERSION_PATCHLEVEL)
   set(CLANG_VERSION_PATCHLEVEL ${LLVM_VERSION_PATCH})
 endif()
-# Unlike PACKAGE_VERSION, CLANG_VERSION does not include LLVM_VERSION_SUFFIX.
-set(CLANG_VERSION 
"${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}.${CLANG_VERSION_PATCHLEVEL}")
+if(NOT DEFINED CLANG_VERSION_SUFFIX)
+  set(CLANG_VERSION_SUFFIX ${LLVM_VERSION_SUFFIX})
+endif()
+set(CLANG_VERSION 
"${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}.${CLANG_VERSION_PATCHLEVEL}${LLVM_VERSION_SUFFIX}")
 message(STATUS "Clang version: ${CLANG_VERSION}")
 
 # Configure the Version.inc file.
diff --git a/clang/test/Frontend/sarif-diagnostics.cpp 
b/clang/test/Frontend/sarif-diagnostics.cpp
index 9a4e686389a2e..767c5802ca13d 100644
--- a/clang/test/Frontend/sarif-diagnostics.cpp
+++ b/clang/test/Frontend/sarif-diagnostics.cpp
@@ -64,5 +64,5 @@ void f1(t1 x, t1 y) {
 // CHECK: 
{"enabled":true,"level":"error","rank":50},"fullDescription":{"text":""},"id":"{{[0-9]+}}","name":""},{"defaultConfiguration":
 // CHECK: 
{"enabled":true,"level":"error","rank":50},"fullDescription":{"text":""},"id":"{{[0-9]+}}","name":""},{"defaultConfiguration":
 // CHECK: {"enabled":true,"level":"error","rank":50},"fullDescription":
-// CHECK: 
{"text":""},"id":"{{[0-9]+}}","name":""}],"version":"{{[0-9]+\.[0-9]+\.[0-9]+}}"}}}],"version":"2.1.0"}
-// CHECK: 2 warnings and 6 errors generated.
\ No newline at end of file
+// CHECK: 
{"text":""},"id":"{{[0-9]+}}","name":""}],"version":"{{[0-9]+\.[0-9]+\.[0-9]+[^"
 ]*}}"}}}],"version":"2.1.0"}
+// CHECK: 2 warnings and 6 errors generated.
diff --git a/llvm/utils/UpdateTestChecks/common.py 
b/llvm/utils/UpdateTestChecks/common.py
index 5c3775e3d0859..0fe0dfc506b05 100644
--- a/llvm/utils/UpdateTestChecks/common.py
+++ b/llvm/utils/UpdateTestChecks/common.py
@@ -1701,7 +1701,7 @@ def add(var):
 
 METADATA_FILTERS = [
 (
-r"(?<=\")(\w+ )?(\w+ version )[\d.]+(?: \([^)]+\))?",
+r"(?<=\")(\w+ )?(\w+ version )[\d.]+(?:[^\" ]*)(?: \([^)]+\))?",
 r"{{.*}}\2{{.*}}",
 ),  # preface with glob also, to capture optional CLANG_VENDOR
 (r'(!DIFile\(filename: ".+", directory: )".+"', r"\1{{.*}}"),

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


[llvm] [clang] Include LLVM_VERSION_SUFFIX in the Clang version string. (PR #74469)

2023-12-05 Thread James Y Knight via cfe-commits

https://github.com/jyknight updated 
https://github.com/llvm/llvm-project/pull/74469

>From 00f710804e77ccc001025a4524ab6882377d1089 Mon Sep 17 00:00:00 2001
From: James Y Knight 
Date: Tue, 5 Dec 2023 08:41:08 -0500
Subject: [PATCH 1/2] Include LLVM_VERSION_SUFFIX in the Clang version string.

This causes current mainline to now report "18.0.0git" instead of
"18.0.0".

Fixes #53825
---
 clang/CMakeLists.txt  | 6 --
 clang/test/Frontend/sarif-diagnostics.cpp | 4 ++--
 llvm/utils/UpdateTestChecks/common.py | 2 +-
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index 9b52c58be41e7..65ed790e69c2a 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -290,8 +290,10 @@ endif()
 if(NOT DEFINED CLANG_VERSION_PATCHLEVEL)
   set(CLANG_VERSION_PATCHLEVEL ${LLVM_VERSION_PATCH})
 endif()
-# Unlike PACKAGE_VERSION, CLANG_VERSION does not include LLVM_VERSION_SUFFIX.
-set(CLANG_VERSION 
"${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}.${CLANG_VERSION_PATCHLEVEL}")
+if(NOT DEFINED CLANG_VERSION_SUFFIX)
+  set(CLANG_VERSION_SUFFIX ${LLVM_VERSION_SUFFIX})
+endif()
+set(CLANG_VERSION 
"${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}.${CLANG_VERSION_PATCHLEVEL}${LLVM_VERSION_SUFFIX}")
 message(STATUS "Clang version: ${CLANG_VERSION}")
 
 # Configure the Version.inc file.
diff --git a/clang/test/Frontend/sarif-diagnostics.cpp 
b/clang/test/Frontend/sarif-diagnostics.cpp
index 9a4e686389a2e..767c5802ca13d 100644
--- a/clang/test/Frontend/sarif-diagnostics.cpp
+++ b/clang/test/Frontend/sarif-diagnostics.cpp
@@ -64,5 +64,5 @@ void f1(t1 x, t1 y) {
 // CHECK: 
{"enabled":true,"level":"error","rank":50},"fullDescription":{"text":""},"id":"{{[0-9]+}}","name":""},{"defaultConfiguration":
 // CHECK: 
{"enabled":true,"level":"error","rank":50},"fullDescription":{"text":""},"id":"{{[0-9]+}}","name":""},{"defaultConfiguration":
 // CHECK: {"enabled":true,"level":"error","rank":50},"fullDescription":
-// CHECK: 
{"text":""},"id":"{{[0-9]+}}","name":""}],"version":"{{[0-9]+\.[0-9]+\.[0-9]+}}"}}}],"version":"2.1.0"}
-// CHECK: 2 warnings and 6 errors generated.
\ No newline at end of file
+// CHECK: 
{"text":""},"id":"{{[0-9]+}}","name":""}],"version":"{{[0-9]+\.[0-9]+\.[0-9]+[^"
 ]*}}"}}}],"version":"2.1.0"}
+// CHECK: 2 warnings and 6 errors generated.
diff --git a/llvm/utils/UpdateTestChecks/common.py 
b/llvm/utils/UpdateTestChecks/common.py
index 5c3775e3d0859..0fe0dfc506b05 100644
--- a/llvm/utils/UpdateTestChecks/common.py
+++ b/llvm/utils/UpdateTestChecks/common.py
@@ -1701,7 +1701,7 @@ def add(var):
 
 METADATA_FILTERS = [
 (
-r"(?<=\")(\w+ )?(\w+ version )[\d.]+(?: \([^)]+\))?",
+r"(?<=\")(\w+ )?(\w+ version )[\d.]+(?:[^\" ]*)(?: \([^)]+\))?",
 r"{{.*}}\2{{.*}}",
 ),  # preface with glob also, to capture optional CLANG_VENDOR
 (r'(!DIFile\(filename: ".+", directory: )".+"', r"\1{{.*}}"),

>From bc27175cb8bb3a6500f1101385ad7b02badd1470 Mon Sep 17 00:00:00 2001
From: James Y Knight 
Date: Tue, 5 Dec 2023 09:00:28 -0500
Subject: [PATCH 2/2] Meant to use CLANG_VERSION_SUFFIX.

---
 clang/CMakeLists.txt | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index 65ed790e69c2a..2ca6db02e5879 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -293,7 +293,7 @@ endif()
 if(NOT DEFINED CLANG_VERSION_SUFFIX)
   set(CLANG_VERSION_SUFFIX ${LLVM_VERSION_SUFFIX})
 endif()
-set(CLANG_VERSION 
"${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}.${CLANG_VERSION_PATCHLEVEL}${LLVM_VERSION_SUFFIX}")
+set(CLANG_VERSION 
"${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}.${CLANG_VERSION_PATCHLEVEL}${CLANG_VERSION_SUFFIX}")
 message(STATUS "Clang version: ${CLANG_VERSION}")
 
 # Configure the Version.inc file.
@@ -652,6 +652,7 @@ if (CLANG_ENABLE_BOOTSTRAP)
 CLANG_VERSION_MAJOR
 CLANG_VERSION_MINOR
 CLANG_VERSION_PATCHLEVEL
+CLANG_VERSION_SUFFIX
 CLANG_VENDOR
 LLVM_VERSION_SUFFIX
 LLVM_BINUTILS_INCDIR

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


[llvm] [clang] Include LLVM_VERSION_SUFFIX in the Clang version string. (PR #74469)

2023-12-05 Thread James Y Knight via cfe-commits


@@ -650,6 +652,7 @@ if (CLANG_ENABLE_BOOTSTRAP)
 CLANG_VERSION_MAJOR
 CLANG_VERSION_MINOR
 CLANG_VERSION_PATCHLEVEL
+CLANG_VERSION_SUFFIX

jyknight wrote:

This list is of CMake variables which automatically get passed through between 
stages in a multi-stage build, so it is useful here already, if someone 
specifies a custom CLANG_VERSION_SUFFIX. See docs in 
llvm/docs/AdvancedBuilds.rst

https://github.com/llvm/llvm-project/pull/74469
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] Include LLVM_VERSION_SUFFIX in the Clang version string. (PR #74469)

2023-12-05 Thread James Y Knight via cfe-commits

https://github.com/jyknight closed 
https://github.com/llvm/llvm-project/pull/74469
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema] atomic_compare_exchange: check failure memory order (PR #74959)

2023-12-11 Thread James Y Knight via cfe-commits

https://github.com/jyknight requested changes to this pull request.


https://github.com/llvm/llvm-project/pull/74959
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema] atomic_compare_exchange: check failure memory order (PR #74959)

2023-12-11 Thread James Y Knight via cfe-commits

https://github.com/jyknight edited 
https://github.com/llvm/llvm-project/pull/74959
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema] atomic_compare_exchange: check failure memory order (PR #74959)

2023-12-11 Thread James Y Knight via cfe-commits


@@ -8728,7 +8728,13 @@ def err_atomic_op_needs_atomic_int : Error<
   "%select{|atomic }0integer (%1 invalid)">;
 def warn_atomic_op_has_invalid_memory_order : Warning<
   "memory order argument to atomic operation is invalid">,
-  InGroup>;
+  InGroup;
+def warn_atomic_op_has_invalid_failure_memory_order : Warning<

jyknight wrote:

Merge with former diagnostic by adding:
`%select{|success |failure }` to the beginning of the message, and adjusting 
callers to stream 0, 1, or 2 as the first param, for non-cmpxchg, 
cmpxchg-success, cmpxchg-failure.

https://github.com/llvm/llvm-project/pull/74959
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema] atomic_compare_exchange: check failure memory order (PR #74959)

2023-12-11 Thread James Y Knight via cfe-commits


@@ -8728,7 +8728,13 @@ def err_atomic_op_needs_atomic_int : Error<
   "%select{|atomic }0integer (%1 invalid)">;
 def warn_atomic_op_has_invalid_memory_order : Warning<
   "memory order argument to atomic operation is invalid">,
-  InGroup>;
+  InGroup;
+def warn_atomic_op_has_invalid_failure_memory_order : Warning<
+  "failure memory order argument to atomic operation is invalid">,
+  InGroup;
+def warn_atomic_op_failure_memory_order_stronger_than_success : Warning<
+  "failure memory order cannot be stronger than success memory order">,
+  InGroup;

jyknight wrote:

This isn't a requirement any more, since C++17, and we applied that to all 
language modes. So remove this diagnostic.
https://eel.is/c++draft/atomics#ref.ops-18

https://github.com/llvm/llvm-project/pull/74959
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [clang-tools-extra] [X86] Use plain load/store instead of cmpxchg16b for atomics with AVX (PR #74275)

2023-12-11 Thread James Y Knight via cfe-commits

https://github.com/jyknight updated 
https://github.com/llvm/llvm-project/pull/74275

>From 7baffd6d1f4254b1bd725ddc883a360d79267435 Mon Sep 17 00:00:00 2001
From: James Y Knight 
Date: Sat, 2 Dec 2023 23:05:26 -0500
Subject: [PATCH 1/2] [X86] Use plain load/store instead of cmpxchg16b for
 atomics with AVX

In late 2021, both Intel and AMD finally documented that every
AVX-capable CPU has always been guaranteed to execute aligned 16-byte
loads/stores atomically, and further, guaranteed that all future CPUs
with AVX will do so as well.

Therefore, we may use normal SSE 128-bit load/store instructions to
implement atomics, if AVX is enabled.

Also adjust handling of unordered atomic load/store in LegalizeIntegerTypes.cpp;
currently, it hardcodes a fallback to ATOMIC_CMP_SWAP_WITH_SUCCESS,
but we should instead fallback to ATOMIC_LOAD/ATOMIC_STORE.

Per AMD64 Architecture Programmer's manual, 7.3.2 Access Atomicity:
"""
Processors that report [AVX] extend the atomicity for cacheable,
naturally-aligned single loads or stores from a quadword to a double
quadword.
"""

Per Intel's SDM:
"""
Processors that enumerate support for Intel(R) AVX guarantee that the
16-byte memory operations performed by the following instructions will
always be carried out atomically:
- MOVAPD, MOVAPS, and MOVDQA.
- VMOVAPD, VMOVAPS, and VMOVDQA when encoded with VEX.128.
- VMOVAPD, VMOVAPS, VMOVDQA32, and VMOVDQA64 when encoded with
  EVEX.128 and k0 (masking disabled).
"""

This was also confirmed to be true for Zhaoxin CPUs with AVX, in
https://gcc.gnu.org/PR104688
---
 .../SelectionDAG/LegalizeIntegerTypes.cpp |  28 +-
 llvm/lib/Target/X86/X86ISelLowering.cpp   |  94 +--
 llvm/test/CodeGen/X86/atomic-non-integer.ll   |  24 +-
 llvm/test/CodeGen/X86/atomic-unordered.ll |  83 +-
 llvm/test/CodeGen/X86/atomic128.ll| 247 +++---
 llvm/test/CodeGen/X86/cmpxchg-i128-i1.ll  |   8 +-
 6 files changed, 256 insertions(+), 228 deletions(-)

diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp 
b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
index 54698edce7d6f8..5b496feee7a8f4 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
@@ -3831,17 +3831,14 @@ void DAGTypeLegalizer::ExpandIntRes_XROUND_XRINT(SDNode 
*N, SDValue &Lo,
 void DAGTypeLegalizer::ExpandIntRes_LOAD(LoadSDNode *N,
  SDValue &Lo, SDValue &Hi) {
   if (N->isAtomic()) {
-// It's typical to have larger CAS than atomic load instructions.
 SDLoc dl(N);
 EVT VT = N->getMemoryVT();
-SDVTList VTs = DAG.getVTList(VT, MVT::i1, MVT::Other);
-SDValue Zero = DAG.getConstant(0, dl, VT);
-SDValue Swap = DAG.getAtomicCmpSwap(
-ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS, dl,
-VT, VTs, N->getOperand(0),
-N->getOperand(1), Zero, Zero, N->getMemOperand());
-ReplaceValueWith(SDValue(N, 0), Swap.getValue(0));
-ReplaceValueWith(SDValue(N, 1), Swap.getValue(2));
+// We may support larger values in atomic_load than in a normal load
+// (without splitting), so switch over if needed.
+SDValue New = DAG.getAtomic(ISD::ATOMIC_LOAD, dl, VT, VT, N->getOperand(0),
+N->getOperand(1), N->getMemOperand());
+ReplaceValueWith(SDValue(N, 0), New.getValue(0));
+ReplaceValueWith(SDValue(N, 1), New.getValue(1));
 return;
   }
 
@@ -5399,14 +5396,13 @@ SDValue DAGTypeLegalizer::ExpandIntOp_XINT_TO_FP(SDNode 
*N) {
 
 SDValue DAGTypeLegalizer::ExpandIntOp_STORE(StoreSDNode *N, unsigned OpNo) {
   if (N->isAtomic()) {
-// It's typical to have larger CAS than atomic store instructions.
+// We may support larger values in atomic_store than in a normal store
+// (without splitting), so switch over if needed.
 SDLoc dl(N);
-SDValue Swap = DAG.getAtomic(ISD::ATOMIC_SWAP, dl,
- N->getMemoryVT(),
- N->getOperand(0), N->getOperand(2),
- N->getOperand(1),
- N->getMemOperand());
-return Swap.getValue(1);
+SDValue New =
+DAG.getAtomic(ISD::ATOMIC_STORE, dl, N->getMemoryVT(), 
N->getOperand(0),
+  N->getOperand(1), N->getOperand(2), N->getMemOperand());
+return New.getValue(0);
   }
   if (ISD::isNormalStore(N))
 return ExpandOp_NormalStore(N, OpNo);
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp 
b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 6167be7bdf84e9..1880cbc3a5bf35 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -515,6 +515,13 @@ X86TargetLowering::X86TargetLowering(const 
X86TargetMachine &TM,
   if (!Subtarget.is64Bit())
 setOpe

[clang] [Sema] atomic_compare_exchange: check failure memory order (PR #74959)

2023-12-11 Thread James Y Knight via cfe-commits

jyknight wrote:

PR description needs to be updated after changes. Otherwise LGTM.

https://github.com/llvm/llvm-project/pull/74959
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][NFC] Reorder Atomic builtins to be consistent. (PR #72718)

2023-11-21 Thread James Y Knight via cfe-commits

https://github.com/jyknight approved this pull request.


https://github.com/llvm/llvm-project/pull/72718
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][NFC] Reorder Atomic builtins to be consistent. (PR #72718)

2023-11-21 Thread James Y Knight via cfe-commits

https://github.com/jyknight closed 
https://github.com/llvm/llvm-project/pull/72718
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][sema] make sure arguments of __atomic_exchange complete type (PR #75135)

2023-12-12 Thread James Y Knight via cfe-commits

jyknight wrote:

Why only `__atomic_exchange`? Presumably we need to be doing the same with 
every other of the atomic builtins as well (unless they already have this check 
and we only missed it on exchange?)

https://github.com/llvm/llvm-project/pull/75135
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [llvm] [clang] [X86] Use plain load/store instead of cmpxchg16b for atomics with AVX (PR #74275)

2023-12-14 Thread James Y Knight via cfe-commits

jyknight wrote:

Ping!

https://github.com/llvm/llvm-project/pull/74275
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema] atomic_compare_exchange: check failure memory order (PR #74959)

2023-12-14 Thread James Y Knight via cfe-commits

https://github.com/jyknight approved this pull request.


https://github.com/llvm/llvm-project/pull/74959
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema] atomic_compare_exchange: check failure memory order (PR #74959)

2023-12-14 Thread James Y Knight via cfe-commits

jyknight wrote:

> > Did this change anything for the `scoped_atomic_compare_exchange_n` variant 
> > I added recently?

The scoped variant(s) use the same codepath here, so they'll also verify that 
the failure order is valid.

https://github.com/llvm/llvm-project/pull/74959
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libclang/python] Fix some minor typos (PR #74292)

2023-12-14 Thread James Y Knight via cfe-commits

https://github.com/jyknight closed 
https://github.com/llvm/llvm-project/pull/74292
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [clang-tools-extra] [X86] Use plain load/store instead of cmpxchg16b for atomics with AVX (PR #74275)

2023-12-16 Thread James Y Knight via cfe-commits


@@ -30095,12 +30102,16 @@ TargetLoweringBase::AtomicExpansionKind
 X86TargetLowering::shouldExpandAtomicStoreInIR(StoreInst *SI) const {
   Type *MemType = SI->getValueOperand()->getType();
 
-  bool NoImplicitFloatOps =
-  SI->getFunction()->hasFnAttribute(Attribute::NoImplicitFloat);
-  if (MemType->getPrimitiveSizeInBits() == 64 && !Subtarget.is64Bit() &&
-  !Subtarget.useSoftFloat() && !NoImplicitFloatOps &&
-  (Subtarget.hasSSE1() || Subtarget.hasX87()))
-return AtomicExpansionKind::None;
+  if (!SI->getFunction()->hasFnAttribute(Attribute::NoImplicitFloat) &&
+  !Subtarget.useSoftFloat()) {
+if (MemType->getPrimitiveSizeInBits() == 64 && !Subtarget.is64Bit() &&
+(Subtarget.hasSSE1() || Subtarget.hasX87()))

jyknight wrote:

No, misaligned atomic ops are converted to `__atomic_*` libcall before this 
function is ever called.

https://github.com/llvm/llvm-project/pull/74275
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang-tools-extra] [clang] [X86] Use plain load/store instead of cmpxchg16b for atomics with AVX (PR #74275)

2023-12-16 Thread James Y Knight via cfe-commits

https://github.com/jyknight updated 
https://github.com/llvm/llvm-project/pull/74275

>From 7baffd6d1f4254b1bd725ddc883a360d79267435 Mon Sep 17 00:00:00 2001
From: James Y Knight 
Date: Sat, 2 Dec 2023 23:05:26 -0500
Subject: [PATCH 1/3] [X86] Use plain load/store instead of cmpxchg16b for
 atomics with AVX

In late 2021, both Intel and AMD finally documented that every
AVX-capable CPU has always been guaranteed to execute aligned 16-byte
loads/stores atomically, and further, guaranteed that all future CPUs
with AVX will do so as well.

Therefore, we may use normal SSE 128-bit load/store instructions to
implement atomics, if AVX is enabled.

Also adjust handling of unordered atomic load/store in LegalizeIntegerTypes.cpp;
currently, it hardcodes a fallback to ATOMIC_CMP_SWAP_WITH_SUCCESS,
but we should instead fallback to ATOMIC_LOAD/ATOMIC_STORE.

Per AMD64 Architecture Programmer's manual, 7.3.2 Access Atomicity:
"""
Processors that report [AVX] extend the atomicity for cacheable,
naturally-aligned single loads or stores from a quadword to a double
quadword.
"""

Per Intel's SDM:
"""
Processors that enumerate support for Intel(R) AVX guarantee that the
16-byte memory operations performed by the following instructions will
always be carried out atomically:
- MOVAPD, MOVAPS, and MOVDQA.
- VMOVAPD, VMOVAPS, and VMOVDQA when encoded with VEX.128.
- VMOVAPD, VMOVAPS, VMOVDQA32, and VMOVDQA64 when encoded with
  EVEX.128 and k0 (masking disabled).
"""

This was also confirmed to be true for Zhaoxin CPUs with AVX, in
https://gcc.gnu.org/PR104688
---
 .../SelectionDAG/LegalizeIntegerTypes.cpp |  28 +-
 llvm/lib/Target/X86/X86ISelLowering.cpp   |  94 +--
 llvm/test/CodeGen/X86/atomic-non-integer.ll   |  24 +-
 llvm/test/CodeGen/X86/atomic-unordered.ll |  83 +-
 llvm/test/CodeGen/X86/atomic128.ll| 247 +++---
 llvm/test/CodeGen/X86/cmpxchg-i128-i1.ll  |   8 +-
 6 files changed, 256 insertions(+), 228 deletions(-)

diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp 
b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
index 54698edce7d6f8..5b496feee7a8f4 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
@@ -3831,17 +3831,14 @@ void DAGTypeLegalizer::ExpandIntRes_XROUND_XRINT(SDNode 
*N, SDValue &Lo,
 void DAGTypeLegalizer::ExpandIntRes_LOAD(LoadSDNode *N,
  SDValue &Lo, SDValue &Hi) {
   if (N->isAtomic()) {
-// It's typical to have larger CAS than atomic load instructions.
 SDLoc dl(N);
 EVT VT = N->getMemoryVT();
-SDVTList VTs = DAG.getVTList(VT, MVT::i1, MVT::Other);
-SDValue Zero = DAG.getConstant(0, dl, VT);
-SDValue Swap = DAG.getAtomicCmpSwap(
-ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS, dl,
-VT, VTs, N->getOperand(0),
-N->getOperand(1), Zero, Zero, N->getMemOperand());
-ReplaceValueWith(SDValue(N, 0), Swap.getValue(0));
-ReplaceValueWith(SDValue(N, 1), Swap.getValue(2));
+// We may support larger values in atomic_load than in a normal load
+// (without splitting), so switch over if needed.
+SDValue New = DAG.getAtomic(ISD::ATOMIC_LOAD, dl, VT, VT, N->getOperand(0),
+N->getOperand(1), N->getMemOperand());
+ReplaceValueWith(SDValue(N, 0), New.getValue(0));
+ReplaceValueWith(SDValue(N, 1), New.getValue(1));
 return;
   }
 
@@ -5399,14 +5396,13 @@ SDValue DAGTypeLegalizer::ExpandIntOp_XINT_TO_FP(SDNode 
*N) {
 
 SDValue DAGTypeLegalizer::ExpandIntOp_STORE(StoreSDNode *N, unsigned OpNo) {
   if (N->isAtomic()) {
-// It's typical to have larger CAS than atomic store instructions.
+// We may support larger values in atomic_store than in a normal store
+// (without splitting), so switch over if needed.
 SDLoc dl(N);
-SDValue Swap = DAG.getAtomic(ISD::ATOMIC_SWAP, dl,
- N->getMemoryVT(),
- N->getOperand(0), N->getOperand(2),
- N->getOperand(1),
- N->getMemOperand());
-return Swap.getValue(1);
+SDValue New =
+DAG.getAtomic(ISD::ATOMIC_STORE, dl, N->getMemoryVT(), 
N->getOperand(0),
+  N->getOperand(1), N->getOperand(2), N->getMemOperand());
+return New.getValue(0);
   }
   if (ISD::isNormalStore(N))
 return ExpandOp_NormalStore(N, OpNo);
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp 
b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 6167be7bdf84e9..1880cbc3a5bf35 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -515,6 +515,13 @@ X86TargetLowering::X86TargetLowering(const 
X86TargetMachine &TM,
   if (!Subtarget.is64Bit())
 setOpe

[clang-tools-extra] [clang] [llvm] [X86] Use plain load/store instead of cmpxchg16b for atomics with AVX (PR #74275)

2023-12-16 Thread James Y Knight via cfe-commits


@@ -228,87 +228,86 @@ define void @widen_broadcast_unaligned(ptr %p0, i32 %v) {
 }
 
 define i128 @load_i128(ptr %ptr) {
-; CHECK-O0-LABEL: load_i128:
-; CHECK-O0:   # %bb.0:
-; CHECK-O0-NEXT:pushq %rbx
-; CHECK-O0-NEXT:.cfi_def_cfa_offset 16
-; CHECK-O0-NEXT:.cfi_offset %rbx, -16
-; CHECK-O0-NEXT:xorl %eax, %eax
-; CHECK-O0-NEXT:movl %eax, %ebx
-; CHECK-O0-NEXT:movq %rbx, %rax
-; CHECK-O0-NEXT:movq %rbx, %rdx
-; CHECK-O0-NEXT:movq %rbx, %rcx
-; CHECK-O0-NEXT:lock cmpxchg16b (%rdi)
-; CHECK-O0-NEXT:popq %rbx
-; CHECK-O0-NEXT:.cfi_def_cfa_offset 8
-; CHECK-O0-NEXT:retq
-;
-; CHECK-O3-LABEL: load_i128:
-; CHECK-O3:   # %bb.0:
-; CHECK-O3-NEXT:pushq %rbx
-; CHECK-O3-NEXT:.cfi_def_cfa_offset 16
-; CHECK-O3-NEXT:.cfi_offset %rbx, -16
-; CHECK-O3-NEXT:xorl %eax, %eax
-; CHECK-O3-NEXT:xorl %edx, %edx
-; CHECK-O3-NEXT:xorl %ecx, %ecx
-; CHECK-O3-NEXT:xorl %ebx, %ebx
-; CHECK-O3-NEXT:lock cmpxchg16b (%rdi)
-; CHECK-O3-NEXT:popq %rbx
-; CHECK-O3-NEXT:.cfi_def_cfa_offset 8
-; CHECK-O3-NEXT:retq
+; CHECK-O0-CUR-LABEL: load_i128:

jyknight wrote:

Done.

https://github.com/llvm/llvm-project/pull/74275
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [llvm] [clang] [X86] Use plain load/store instead of cmpxchg16b for atomics with AVX (PR #74275)

2023-12-16 Thread James Y Knight via cfe-commits


@@ -31259,14 +31274,23 @@ static SDValue LowerATOMIC_STORE(SDValue Op, 
SelectionDAG &DAG,
   if (!IsSeqCst && IsTypeLegal)
 return Op;
 
-  if (VT == MVT::i64 && !IsTypeLegal) {
+  if (!IsTypeLegal && !Subtarget.useSoftFloat() &&
+  !DAG.getMachineFunction().getFunction().hasFnAttribute(
+  Attribute::NoImplicitFloat)) {
+SDValue Chain;
+// For illegal i128 atomic_store, when AVX is enabled, we can simply emit a
+// vector store.
+if (VT == MVT::i128) {
+  if (Subtarget.is64Bit() && Subtarget.hasAVX()) {
+SDValue VecVal = DAG.getBitcast(MVT::v2i64, Node->getVal());
+Chain = DAG.getStore(Node->getChain(), dl, VecVal, Node->getBasePtr(),
+ Node->getMemOperand());
+  }
+}
+
 // For illegal i64 atomic_stores, we can try to use MOVQ or MOVLPS if SSE
 // is enabled.
-bool NoImplicitFloatOps =
-DAG.getMachineFunction().getFunction().hasFnAttribute(
-Attribute::NoImplicitFloat);
-if (!Subtarget.useSoftFloat() && !NoImplicitFloatOps) {
-  SDValue Chain;
+if (VT == MVT::i64) {
   if (Subtarget.hasSSE1()) {

jyknight wrote:

This has an "else if" attached, so better not to.

https://github.com/llvm/llvm-project/pull/74275
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [clang-tools-extra] [X86] Use plain load/store instead of cmpxchg16b for atomics with AVX (PR #74275)

2023-12-16 Thread James Y Knight via cfe-commits


@@ -30115,12 +30126,16 @@ 
X86TargetLowering::shouldExpandAtomicLoadInIR(LoadInst *LI) const {
   // If this a 64 bit atomic load on a 32-bit target and SSE2 is enabled, we
   // can use movq to do the load. If we have X87 we can load into an 80-bit
   // X87 register and store it to a stack temporary.

jyknight wrote:

Done.

https://github.com/llvm/llvm-project/pull/74275
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [clang-tools-extra] [X86] Use plain load/store instead of cmpxchg16b for atomics with AVX (PR #74275)

2023-12-16 Thread James Y Knight via cfe-commits


@@ -31259,14 +31274,23 @@ static SDValue LowerATOMIC_STORE(SDValue Op, 
SelectionDAG &DAG,
   if (!IsSeqCst && IsTypeLegal)
 return Op;
 
-  if (VT == MVT::i64 && !IsTypeLegal) {
+  if (!IsTypeLegal && !Subtarget.useSoftFloat() &&
+  !DAG.getMachineFunction().getFunction().hasFnAttribute(
+  Attribute::NoImplicitFloat)) {
+SDValue Chain;
+// For illegal i128 atomic_store, when AVX is enabled, we can simply emit a
+// vector store.
+if (VT == MVT::i128) {
+  if (Subtarget.is64Bit() && Subtarget.hasAVX()) {

jyknight wrote:

Done.

https://github.com/llvm/llvm-project/pull/74275
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang] [llvm] Add out-of-line-atomics support to GlobalISel (PR #74588)

2023-12-18 Thread James Y Knight via cfe-commits

jyknight wrote:

> This sounds extremely unsound

It is completely unsound. The constraints that approximately every architecture 
has on LL/SC loops make it unsound to ever generate isolated LL and SC 
instructions at the IR level, as we are currently doing on AArch64, ARM, and 
Hexagon.

We already added the infrastructure to do this properly, and used it for RISCV, 
and it's now also being used on Loongarch. ARM/AArch64 should be updated to 
match.

See discussion in 
https://lists.llvm.org/pipermail/llvm-dev/2018-June/123993.html


https://github.com/llvm/llvm-project/pull/74588
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [libc] [clang-tools-extra] [libcxx] [llvm] [lldb] [flang] ✨ [Sema, Lex, Parse] Preprocessor embed in C and C++ (and Obj-C and Obj-C++ by-proxy) (PR #68620)

2023-11-27 Thread James Y Knight via cfe-commits

jyknight wrote:

I'm somewhat concerned about the default for `-E` being to explode `#embed` 
into the comma-separated raw integers. Even with moderately-sized embeds, I 
think it'll generate unusably-bloated output. The human-readability of a big 
list of integers is not better than embedded base64 -- and actually, seems more 
of a pain to decode.

I think the most user-friendly behavior would be:
- `-E`: convert `#embed "file"` into `#embed_base64 "base64-file-contents"`. 
This preserves the property of the output not depending on other files, but 
doesn't make it hugely-bloated.
- `-E -dE`: preserve any `#embed` directive as-is, referring to the external 
file.
- Potentially another `-d?` mode to explode `#embed` into the raw integers 
(like you had proposed for the default behavior) -- though I'm not sure that's 
really going to be useful.

https://github.com/llvm/llvm-project/pull/68620
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [libcxx] [clang] [clang-tools-extra] Mark some std::string functions noinline. (PR #72869)

2023-11-27 Thread James Y Knight via cfe-commits

https://github.com/jyknight updated 
https://github.com/llvm/llvm-project/pull/72869

>From 7c51f0cb27079c79f924ff746dccb14637641fe4 Mon Sep 17 00:00:00 2001
From: James Y Knight 
Date: Mon, 20 Nov 2023 13:43:32 +
Subject: [PATCH] Mark some std::string functions noinline.

The intent of these particular functions, since their introduction,
was to NOT be inlinable.

However, the mechanism by which this was accomplished was non-obvious,
and stopped working when string is compiled for C++20.

A longstanding behavior specified by the C++ standard is that
instantiation of the body of a template function is suppressed by an
extern template declaration -- unless the function is explicitly
marked either constexpr or inline. Of course, if the body is not
instantiated, then it cannot possibly be inlined, and thus all the
functions listed in libcxx/include/__string/extern_template_lists.h
were uninlineable.

But, in C++20 mode, string functions were annotated constexpr, which
means they _are_ instantiated, and do become inlineable. And, in fact,
they do get inlined, which has caused noticeable binary-size growth
for users.

For example, in C++17,
`std::string f(std::string *in) { return *in; }`
does not inline the copy-constructor call, and instead generates a
call to the exported function defined in the libc++ shared library.

I think we probably don't want to mark all functions that are
currently in the extern template list as noinline, as many of them
really are reasonable inlining candidates. Thus, I've restricted this
change to only the few functions that were clearly intended to be
outlined.

See commits like b019c5c0372eb08800327efb5e7955ce918b75d1 (and some
others like it) for background, in which functions were removed from
the extern template list in the unstable ABI in order to allow the
short-string case to be inlined, while moving the long-string case to
a separate function, added to the extern template list.
---
 libcxx/include/__config |  6 ++
 libcxx/include/string   | 20 ++--
 2 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/libcxx/include/__config b/libcxx/include/__config
index e8da358bb8d7cd5..267d58735e8aab3 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -1279,6 +1279,12 @@ 
__sanitizer_verify_double_ended_contiguous_container(const void*, const void*, c
 #define _LIBCPP_NO_SANITIZE(...)
 #  endif
 
+#  if __has_attribute(__noinline__)
+#define _LIBCPP_NOINLINE __attribute__((__noinline__))
+#  else
+#define _LIBCPP_NOINLINE
+#  endif
+
 // We often repeat things just for handling wide characters in the library.
 // When wide characters are disabled, it can be useful to have a quick way of
 // disabling it without having to resort to #if-#endif, which has a larger
diff --git a/libcxx/include/string b/libcxx/include/string
index 9c2efac8006bd72..fa06ac316b2d16c 100644
--- a/libcxx/include/string
+++ b/libcxx/include/string
@@ -1899,7 +1899,7 @@ private:
 // to call the __init() functions as those are marked as inline which may
 // result in over-aggressive inlining by the compiler, where our aim is
 // to only inline the fast path code directly in the ctor.
-_LIBCPP_CONSTEXPR_SINCE_CXX20 void __init_copy_ctor_external(const 
value_type* __s, size_type __sz);
+_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_NOINLINE void 
__init_copy_ctor_external(const value_type* __s, size_type __sz);
 
 template ::value, 
int> = 0>
 inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void __init(_InputIterator __first, 
_InputIterator __last);
@@ -1933,7 +1933,7 @@ private:
 // have proof that the input does not alias the current instance.
 // For example, operator=(basic_string) performs a 'self' check.
 template 
-_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& __assign_no_alias(const 
value_type* __s, size_type __n);
+_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_NOINLINE basic_string& 
__assign_no_alias(const value_type* __s, size_type __n);
 
   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void 
__erase_to_end(size_type __pos) {
 __null_terminate_at(std::__to_address(__get_pointer()), __pos);
@@ -1941,7 +1941,7 @@ private:
 
 // __erase_external_with_move is invoked for erase() invocations where
 // `n ~= npos`, likely requiring memory moves on the string data.
-_LIBCPP_CONSTEXPR_SINCE_CXX20 void __erase_external_with_move(size_type 
__pos, size_type __n);
+_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_NOINLINE void 
__erase_external_with_move(size_type __pos, size_type __n);
 
 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
 void __copy_assign_alloc(const basic_string& __str)
@@ -2013,8 +2013,8 @@ private:
 _NOEXCEPT
 {}
 
-_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& __assign_external(const 
value_type* __s);
-_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& __assign_external(const 
value_type* __s, size_type __n);
+ 

[libc] [clang] [libcxx] [flang] [compiler-rt] [lldb] [llvm] [clang-tools-extra] ✨ [Sema, Lex, Parse] Preprocessor embed in C and C++ (and Obj-C and Obj-C++ by-proxy) (PR #68620)

2023-11-27 Thread James Y Knight via cfe-commits

jyknight wrote:

I guess I'd consider the "mental model" here to be that (notionally) `#embed` 
is preprocessed by expanding to `#embed_base64`, which is handled by the 
compiler proper, not the preprocessor. Yes, that's not entirely true in the 
implementation, but it seems like a reasonable way to think about it. (similar 
in feel to `#pragma` which is also not purely preprocessor, despite starting 
with `#`.)

https://github.com/llvm/llvm-project/pull/68620
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [libcxx] [clang-tools-extra] [clang] Mark some std::string functions noinline. (PR #72869)

2023-11-28 Thread James Y Knight via cfe-commits

jyknight wrote:

Seeing no further feedback, going ahead and submitting.

https://github.com/llvm/llvm-project/pull/72869
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] [llvm] [clang-tools-extra] [clang] Mark some std::string functions noinline. (PR #72869)

2023-11-28 Thread James Y Knight via cfe-commits

https://github.com/jyknight closed 
https://github.com/llvm/llvm-project/pull/72869
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libc] [clang-tools-extra] [libcxx] [lldb] [llvm] [compiler-rt] [lld] [flang] Fix clang to recognize new C23 modifiers %w and %wf when printing (PR #71771)

2023-11-30 Thread James Y Knight via cfe-commits


@@ -286,7 +286,33 @@ 
clang::analyze_format_string::ParseLengthModifier(FormatSpecifier &FS,
   lmKind = LengthModifier::AsInt3264;
   break;
 case 'w':
-  lmKind = LengthModifier::AsWide; ++I; break;
+  ++I;
+  if (I == E) return false;
+  if (*I == 'f') {
+lmKind = LengthModifier::AsWideFast;
+++I;
+  } else {
+lmKind = LengthModifier::AsWide;
+  }
+
+  if (I == E) return false;
+  int s = 0;
+  while (unsigned(*I - '0') <= 9) {
+s = 10 * s + unsigned(*I - '0');
+++I;
+  }
+
+  // s == 0 is MSVCRT case, like l but only for c, C, s, S, or Z on windows
+  // s != 0 for b, d, i, o, u, x, or X when a size followed(like 8, 16, 32 
or 64)
+  if (s != 0) {
+std::set supported_list {8, 16, 32, 64};

jyknight wrote:

No objection from my side for removing the weird sizes from Clang's stdint.h. I 
also doubt anyone's using it at all, but if they are, they can request a revert.

https://github.com/llvm/llvm-project/pull/71771
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[compiler-rt] [lldb] [llvm] [clang-tools-extra] [libc] [libcxx] [clang] [lld] [flang] Fix clang to recognize new C23 modifiers %w and %wf when printing (PR #71771)

2023-11-30 Thread James Y Knight via cfe-commits


@@ -484,6 +484,26 @@ bool 
clang::analyze_format_string::parseFormatStringHasFormattingSpecifiers(
   return false;
 }
 
+ArgType clang::analyze_format_string::wToArgType(
+int size, bool fast, ASTContext &C) {
+  ArgType fastType = C.getTargetInfo().getTriple().isArch64Bit() ? 
C.LongLongTy : C.IntTy;

jyknight wrote:

It's actually quite a mess right now...

We currently have TargetInfo getIntTypeByWidth/getLeastIntTypeByWidth, but, no 
getFastIntTypeByWidth.

And this is a real problem...e.g. clang's stdint.h builtin-header goes through 
a ton of complexity to obfuscate that in fact it just ends up defining 
int_leastN_t and int_fastN_t as aliases to intN_t, on all platforms we support 
(which have all of 8/16/32/64-bit types available.)

But, clang's stdint.h defers to the libc's stdint.h if that exists, and e.g. on 
glibc, int_fast{16|32}_t are instead defined as int (32bit) or long (64bit). 

OK, fine...Except -- we ALSO define a bunch of preprocessor macros for the fast 
types in InitPreprocessor (e.g. `__INT_FAST16_TYPE__`. Which assume that fast 
== least. And, of course, these don't match the libc stdint.h's definitions...

And then there's the problem of which of 'long' vs 'long long' is used on 
various platforms, when both are 64-bit types.

I think we need to fix all that as a prerequisite. At that point, this code 
simply calls getFastIntTypeByWidth.

https://github.com/llvm/llvm-project/pull/71771
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Use Address for CGBuilder's CreateAtomicRMW and CreateAtomicCmpXchg. (PR #74349)

2023-12-04 Thread James Y Knight via cfe-commits

https://github.com/jyknight created 
https://github.com/llvm/llvm-project/pull/74349

Update all callers to pass through the Address.

For the older builtins such as `__sync_*` and MSVC `_Interlocked*`, natural 
alignment of the atomic access is _assumed_. This change preserves that 
behavior. It will pass through greater-than-required alignments, however.

>From 7fd7ebbf60beacb63ddfff16a7c4405e80cb62b4 Mon Sep 17 00:00:00 2001
From: James Y Knight 
Date: Mon, 4 Dec 2023 12:11:58 -0500
Subject: [PATCH] Use Address for CGBuilder's CreateAtomicRMW and
 CreateAtomicCmpXchg.

Update all callers to pass through the Address.

For the older builtins such as `__sync_*` and MSVC `_Interlocked*`,
natural alignment of the atomic memory is _assumed_. This change
preserves that behavior.
---
 clang/lib/CodeGen/CGAtomic.cpp|   8 +-
 clang/lib/CodeGen/CGBuilder.h |  17 +--
 clang/lib/CodeGen/CGBuiltin.cpp   | 130 +-
 clang/lib/CodeGen/CGExprScalar.cpp|   6 +-
 clang/lib/CodeGen/CGStmtOpenMP.cpp|   2 +-
 clang/test/CodeGen/atomic-ops.c   |   4 +-
 .../test/CodeGen/ms-intrinsics-underaligned.c | 110 +++
 clang/test/CodeGen/ms-intrinsics.c|   4 +-
 .../OpenMP/parallel_reduction_codegen.cpp |   6 +-
 9 files changed, 195 insertions(+), 92 deletions(-)
 create mode 100644 clang/test/CodeGen/ms-intrinsics-underaligned.c

diff --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp
index 6005d5c51c0e1..379c833af32a2 100644
--- a/clang/lib/CodeGen/CGAtomic.cpp
+++ b/clang/lib/CodeGen/CGAtomic.cpp
@@ -383,8 +383,7 @@ static void emitAtomicCmpXchg(CodeGenFunction &CGF, 
AtomicExpr *E, bool IsWeak,
   llvm::Value *Desired = CGF.Builder.CreateLoad(Val2);
 
   llvm::AtomicCmpXchgInst *Pair = CGF.Builder.CreateAtomicCmpXchg(
-  Ptr.getPointer(), Expected, Desired, SuccessOrder, FailureOrder,
-  Scope);
+  Ptr, Expected, Desired, SuccessOrder, FailureOrder, Scope);
   Pair->setVolatile(E->isVolatile());
   Pair->setWeak(IsWeak);
 
@@ -699,7 +698,7 @@ static void EmitAtomicOp(CodeGenFunction &CGF, AtomicExpr 
*E, Address Dest,
 
   llvm::Value *LoadVal1 = CGF.Builder.CreateLoad(Val1);
   llvm::AtomicRMWInst *RMWI =
-  CGF.Builder.CreateAtomicRMW(Op, Ptr.getPointer(), LoadVal1, Order, 
Scope);
+  CGF.Builder.CreateAtomicRMW(Op, Ptr, LoadVal1, Order, Scope);
   RMWI->setVolatile(E->isVolatile());
 
   // For __atomic_*_fetch operations, perform the operation again to
@@ -1740,8 +1739,7 @@ std::pair 
AtomicInfo::EmitAtomicCompareExchangeOp(
 llvm::AtomicOrdering Success, llvm::AtomicOrdering Failure, bool IsWeak) {
   // Do the atomic store.
   Address Addr = getAtomicAddressAsAtomicIntPointer();
-  auto *Inst = CGF.Builder.CreateAtomicCmpXchg(Addr.getPointer(),
-   ExpectedVal, DesiredVal,
+  auto *Inst = CGF.Builder.CreateAtomicCmpXchg(Addr, ExpectedVal, DesiredVal,
Success, Failure);
   // Other decoration.
   Inst->setVolatile(LVal.isVolatileQualified());
diff --git a/clang/lib/CodeGen/CGBuilder.h b/clang/lib/CodeGen/CGBuilder.h
index 68535920088c4..bf5ab171d720d 100644
--- a/clang/lib/CodeGen/CGBuilder.h
+++ b/clang/lib/CodeGen/CGBuilder.h
@@ -126,25 +126,22 @@ class CGBuilderTy : public CGBuilderBaseTy {
 return CreateAlignedStore(getInt1(Value), Addr, CharUnits::One());
   }
 
-  // Temporarily use old signature; clang will be updated to an Address 
overload
-  // in a subsequent patch.
   llvm::AtomicCmpXchgInst *
-  CreateAtomicCmpXchg(llvm::Value *Ptr, llvm::Value *Cmp, llvm::Value *New,
+  CreateAtomicCmpXchg(Address Addr, llvm::Value *Cmp, llvm::Value *New,
   llvm::AtomicOrdering SuccessOrdering,
   llvm::AtomicOrdering FailureOrdering,
   llvm::SyncScope::ID SSID = llvm::SyncScope::System) {
 return CGBuilderBaseTy::CreateAtomicCmpXchg(
-Ptr, Cmp, New, llvm::MaybeAlign(), SuccessOrdering, FailureOrdering,
-SSID);
+Addr.getPointer(), Cmp, New, Addr.getAlignment().getAsAlign(),
+SuccessOrdering, FailureOrdering, SSID);
   }
 
-  // Temporarily use old signature; clang will be updated to an Address 
overload
-  // in a subsequent patch.
   llvm::AtomicRMWInst *
-  CreateAtomicRMW(llvm::AtomicRMWInst::BinOp Op, llvm::Value *Ptr,
-  llvm::Value *Val, llvm::AtomicOrdering Ordering,
+  CreateAtomicRMW(llvm::AtomicRMWInst::BinOp Op, Address Addr, llvm::Value 
*Val,
+  llvm::AtomicOrdering Ordering,
   llvm::SyncScope::ID SSID = llvm::SyncScope::System) {
-return CGBuilderBaseTy::CreateAtomicRMW(Op, Ptr, Val, llvm::MaybeAlign(),
+return CGBuilderBaseTy::CreateAtomicRMW(Op, Addr.getPointer(), Val,
+Addr.getAlignment().getAsAlign(),
   

[clang] Use Address for CGBuilder's CreateAtomicRMW and CreateAtomicCmpXchg. (PR #74349)

2023-12-04 Thread James Y Knight via cfe-commits

https://github.com/jyknight updated 
https://github.com/llvm/llvm-project/pull/74349

>From 7fd7ebbf60beacb63ddfff16a7c4405e80cb62b4 Mon Sep 17 00:00:00 2001
From: James Y Knight 
Date: Mon, 4 Dec 2023 12:11:58 -0500
Subject: [PATCH 1/2] Use Address for CGBuilder's CreateAtomicRMW and
 CreateAtomicCmpXchg.

Update all callers to pass through the Address.

For the older builtins such as `__sync_*` and MSVC `_Interlocked*`,
natural alignment of the atomic memory is _assumed_. This change
preserves that behavior.
---
 clang/lib/CodeGen/CGAtomic.cpp|   8 +-
 clang/lib/CodeGen/CGBuilder.h |  17 +--
 clang/lib/CodeGen/CGBuiltin.cpp   | 130 +-
 clang/lib/CodeGen/CGExprScalar.cpp|   6 +-
 clang/lib/CodeGen/CGStmtOpenMP.cpp|   2 +-
 clang/test/CodeGen/atomic-ops.c   |   4 +-
 .../test/CodeGen/ms-intrinsics-underaligned.c | 110 +++
 clang/test/CodeGen/ms-intrinsics.c|   4 +-
 .../OpenMP/parallel_reduction_codegen.cpp |   6 +-
 9 files changed, 195 insertions(+), 92 deletions(-)
 create mode 100644 clang/test/CodeGen/ms-intrinsics-underaligned.c

diff --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp
index 6005d5c51c0e1..379c833af32a2 100644
--- a/clang/lib/CodeGen/CGAtomic.cpp
+++ b/clang/lib/CodeGen/CGAtomic.cpp
@@ -383,8 +383,7 @@ static void emitAtomicCmpXchg(CodeGenFunction &CGF, 
AtomicExpr *E, bool IsWeak,
   llvm::Value *Desired = CGF.Builder.CreateLoad(Val2);
 
   llvm::AtomicCmpXchgInst *Pair = CGF.Builder.CreateAtomicCmpXchg(
-  Ptr.getPointer(), Expected, Desired, SuccessOrder, FailureOrder,
-  Scope);
+  Ptr, Expected, Desired, SuccessOrder, FailureOrder, Scope);
   Pair->setVolatile(E->isVolatile());
   Pair->setWeak(IsWeak);
 
@@ -699,7 +698,7 @@ static void EmitAtomicOp(CodeGenFunction &CGF, AtomicExpr 
*E, Address Dest,
 
   llvm::Value *LoadVal1 = CGF.Builder.CreateLoad(Val1);
   llvm::AtomicRMWInst *RMWI =
-  CGF.Builder.CreateAtomicRMW(Op, Ptr.getPointer(), LoadVal1, Order, 
Scope);
+  CGF.Builder.CreateAtomicRMW(Op, Ptr, LoadVal1, Order, Scope);
   RMWI->setVolatile(E->isVolatile());
 
   // For __atomic_*_fetch operations, perform the operation again to
@@ -1740,8 +1739,7 @@ std::pair 
AtomicInfo::EmitAtomicCompareExchangeOp(
 llvm::AtomicOrdering Success, llvm::AtomicOrdering Failure, bool IsWeak) {
   // Do the atomic store.
   Address Addr = getAtomicAddressAsAtomicIntPointer();
-  auto *Inst = CGF.Builder.CreateAtomicCmpXchg(Addr.getPointer(),
-   ExpectedVal, DesiredVal,
+  auto *Inst = CGF.Builder.CreateAtomicCmpXchg(Addr, ExpectedVal, DesiredVal,
Success, Failure);
   // Other decoration.
   Inst->setVolatile(LVal.isVolatileQualified());
diff --git a/clang/lib/CodeGen/CGBuilder.h b/clang/lib/CodeGen/CGBuilder.h
index 68535920088c4..bf5ab171d720d 100644
--- a/clang/lib/CodeGen/CGBuilder.h
+++ b/clang/lib/CodeGen/CGBuilder.h
@@ -126,25 +126,22 @@ class CGBuilderTy : public CGBuilderBaseTy {
 return CreateAlignedStore(getInt1(Value), Addr, CharUnits::One());
   }
 
-  // Temporarily use old signature; clang will be updated to an Address 
overload
-  // in a subsequent patch.
   llvm::AtomicCmpXchgInst *
-  CreateAtomicCmpXchg(llvm::Value *Ptr, llvm::Value *Cmp, llvm::Value *New,
+  CreateAtomicCmpXchg(Address Addr, llvm::Value *Cmp, llvm::Value *New,
   llvm::AtomicOrdering SuccessOrdering,
   llvm::AtomicOrdering FailureOrdering,
   llvm::SyncScope::ID SSID = llvm::SyncScope::System) {
 return CGBuilderBaseTy::CreateAtomicCmpXchg(
-Ptr, Cmp, New, llvm::MaybeAlign(), SuccessOrdering, FailureOrdering,
-SSID);
+Addr.getPointer(), Cmp, New, Addr.getAlignment().getAsAlign(),
+SuccessOrdering, FailureOrdering, SSID);
   }
 
-  // Temporarily use old signature; clang will be updated to an Address 
overload
-  // in a subsequent patch.
   llvm::AtomicRMWInst *
-  CreateAtomicRMW(llvm::AtomicRMWInst::BinOp Op, llvm::Value *Ptr,
-  llvm::Value *Val, llvm::AtomicOrdering Ordering,
+  CreateAtomicRMW(llvm::AtomicRMWInst::BinOp Op, Address Addr, llvm::Value 
*Val,
+  llvm::AtomicOrdering Ordering,
   llvm::SyncScope::ID SSID = llvm::SyncScope::System) {
-return CGBuilderBaseTy::CreateAtomicRMW(Op, Ptr, Val, llvm::MaybeAlign(),
+return CGBuilderBaseTy::CreateAtomicRMW(Op, Addr.getPointer(), Val,
+Addr.getAlignment().getAsAlign(),
 Ordering, SSID);
   }
 
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 65d9862621061..14e20bf16811c 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -188,8 +

[clang] Use Address for CGBuilder's CreateAtomicRMW and CreateAtomicCmpXchg. (PR #74349)

2023-12-04 Thread James Y Knight via cfe-commits

https://github.com/jyknight closed 
https://github.com/llvm/llvm-project/pull/74349
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang] [llvm] [X86] Use plain load/store instead of cmpxchg16b for atomics with AVX (PR #74275)

2024-01-02 Thread James Y Knight via cfe-commits

jyknight wrote:

Ping!

https://github.com/llvm/llvm-project/pull/74275
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] b3d2642 - NFC: Reflow comment for readability.

2024-01-03 Thread James Y Knight via cfe-commits

Author: James Y Knight
Date: 2024-01-03T09:34:07-05:00
New Revision: b3d26426b06ee74bf79f766375a37c384aa0132b

URL: 
https://github.com/llvm/llvm-project/commit/b3d26426b06ee74bf79f766375a37c384aa0132b
DIFF: 
https://github.com/llvm/llvm-project/commit/b3d26426b06ee74bf79f766375a37c384aa0132b.diff

LOG: NFC: Reflow comment for readability.

Added: 


Modified: 
clang/lib/AST/ASTContext.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 0395b3e47ab6f8..b60dcfaabfd1a4 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -2748,21 +2748,20 @@ bool ASTContext::hasUniqueObjectRepresentations(
 QualType Ty, bool CheckIfTriviallyCopyable) const {
   // C++17 [meta.unary.prop]:
   //   The predicate condition for a template specialization
-  //   has_unique_object_representations shall be
-  //   satisfied if and only if:
+  //   has_unique_object_representations shall be satisfied if and only if:
   // (9.1) - T is trivially copyable, and
   // (9.2) - any two objects of type T with the same value have the same
-  // object representation, where two objects
-  //   of array or non-union class type are considered to have the same value
-  //   if their respective sequences of
-  //   direct subobjects have the same values, and two objects of union type
-  //   are considered to have the same
-  //   value if they have the same active member and the corresponding members
-  //   have the same value.
+  // object representation, where:
+  // - two objects of array or non-union class type are considered to have
+  //   the same value if their respective sequences of direct subobjects
+  //   have the same values, and
+  // - two objects of union type are considered to have the same value if
+  //   they have the same active member and the corresponding members have
+  //   the same value.
   //   The set of scalar types for which this condition holds is
-  //   implementation-defined. [ Note: If a type has padding
-  //   bits, the condition does not hold; otherwise, the condition holds true
-  //   for unsigned integral types. -- end note ]
+  //   implementation-defined. [ Note: If a type has padding bits, the 
condition
+  //   does not hold; otherwise, the condition holds true for unsigned integral
+  //   types. -- end note ]
   assert(!Ty.isNull() && "Null QualType sent to unique object rep check");
 
   // Arrays are unique only if their element type is unique.



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


[clang] [llvm] [clang-tools-extra] [X86] Use plain load/store instead of cmpxchg16b for atomics with AVX (PR #74275)

2024-01-08 Thread James Y Knight via cfe-commits


@@ -30113,32 +30120,40 @@ TargetLoweringBase::AtomicExpansionKind
 X86TargetLowering::shouldExpandAtomicStoreInIR(StoreInst *SI) const {
   Type *MemType = SI->getValueOperand()->getType();
 
-  bool NoImplicitFloatOps =
-  SI->getFunction()->hasFnAttribute(Attribute::NoImplicitFloat);
-  if (MemType->getPrimitiveSizeInBits() == 64 && !Subtarget.is64Bit() &&
-  !Subtarget.useSoftFloat() && !NoImplicitFloatOps &&
-  (Subtarget.hasSSE1() || Subtarget.hasX87()))
-return AtomicExpansionKind::None;
+  if (!SI->getFunction()->hasFnAttribute(Attribute::NoImplicitFloat) &&
+  !Subtarget.useSoftFloat()) {
+if (MemType->getPrimitiveSizeInBits() == 64 && !Subtarget.is64Bit() &&
+(Subtarget.hasSSE1() || Subtarget.hasX87()))
+  return AtomicExpansionKind::None;
+
+if (MemType->getPrimitiveSizeInBits() == 128 && Subtarget.is64Bit() &&
+Subtarget.hasAVX())
+  return AtomicExpansionKind::None;
+  }
 
   return needsCmpXchgNb(MemType) ? AtomicExpansionKind::Expand
  : AtomicExpansionKind::None;
 }
 
 // Note: this turns large loads into lock cmpxchg8b/16b.
-// TODO: In 32-bit mode, use MOVLPS when SSE1 is available?
 TargetLowering::AtomicExpansionKind
 X86TargetLowering::shouldExpandAtomicLoadInIR(LoadInst *LI) const {
   Type *MemType = LI->getType();
 
-  // If this a 64 bit atomic load on a 32-bit target and SSE2 is enabled, we
-  // can use movq to do the load. If we have X87 we can load into an 80-bit
-  // X87 register and store it to a stack temporary.
-  bool NoImplicitFloatOps =
-  LI->getFunction()->hasFnAttribute(Attribute::NoImplicitFloat);
-  if (MemType->getPrimitiveSizeInBits() == 64 && !Subtarget.is64Bit() &&
-  !Subtarget.useSoftFloat() && !NoImplicitFloatOps &&
-  (Subtarget.hasSSE1() || Subtarget.hasX87()))
-return AtomicExpansionKind::None;
+  if (!LI->getFunction()->hasFnAttribute(Attribute::NoImplicitFloat) &&
+  !Subtarget.useSoftFloat()) {
+// If this a 64 bit atomic load on a 32-bit target and SSE2 is enabled, we
+// can use movq to do the load. If we have X87 we can load into an 80-bit
+// X87 register and store it to a stack temporary.
+if (MemType->getPrimitiveSizeInBits() == 64 && !Subtarget.is64Bit() &&

jyknight wrote:

Yikes, that's a nasty footgun -- obvious once you think about it, but I never 
would've looked out for that issue! The API of `getPrimitiveSizeInBits` is just 
_asking_ for mistakes like this. It ought to either assert when called on a 
non-primitive, or else return an optional, rather than simply returning 0 on 
failure.

But, looking through this code and the rest of the related atomics support on 
X86, I believe there is actually _not_ a correctness impact, because (not 
coincidentally!) atomics always work "normally" on pointer-sized values. That 
is, here, getPrimitiveSizeInBits() will return 0 rather than the 
perhaps-expected `is64Bit() ? 64 : 32`. Despite being unexpected, though, the 
logic still works out fine in that case.

So, given that this is a longstanding pre-existing issue -- which appears not 
to be a correctness issue -- I'd like to leave it alone in this patch.

https://github.com/llvm/llvm-project/pull/74275
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)

2024-01-10 Thread James Y Knight via cfe-commits


@@ -1047,122 +1019,19 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) {
   Dest = Atomics.castToAtomicIntPointer(Dest);
   }
 
-  // Use a library call.  See: http://gcc.gnu.org/wiki/Atomic/GCCMM/LIbrary .
-  if (UseLibcall) {
-bool UseOptimizedLibcall = false;
-switch (E->getOp()) {
-case AtomicExpr::AO__c11_atomic_init:
-case AtomicExpr::AO__opencl_atomic_init:
-  llvm_unreachable("Already handled above with EmitAtomicInit!");
-
-case AtomicExpr::AO__atomic_fetch_add:
-case AtomicExpr::AO__atomic_fetch_and:
-case AtomicExpr::AO__atomic_fetch_max:
-case AtomicExpr::AO__atomic_fetch_min:
-case AtomicExpr::AO__atomic_fetch_nand:
-case AtomicExpr::AO__atomic_fetch_or:
-case AtomicExpr::AO__atomic_fetch_sub:
-case AtomicExpr::AO__atomic_fetch_xor:
-case AtomicExpr::AO__atomic_add_fetch:
-case AtomicExpr::AO__atomic_and_fetch:
-case AtomicExpr::AO__atomic_max_fetch:
-case AtomicExpr::AO__atomic_min_fetch:
-case AtomicExpr::AO__atomic_nand_fetch:
-case AtomicExpr::AO__atomic_or_fetch:
-case AtomicExpr::AO__atomic_sub_fetch:
-case AtomicExpr::AO__atomic_xor_fetch:
-case AtomicExpr::AO__c11_atomic_fetch_add:
-case AtomicExpr::AO__c11_atomic_fetch_and:
-case AtomicExpr::AO__c11_atomic_fetch_max:
-case AtomicExpr::AO__c11_atomic_fetch_min:
-case AtomicExpr::AO__c11_atomic_fetch_nand:
-case AtomicExpr::AO__c11_atomic_fetch_or:
-case AtomicExpr::AO__c11_atomic_fetch_sub:
-case AtomicExpr::AO__c11_atomic_fetch_xor:
-case AtomicExpr::AO__hip_atomic_fetch_add:
-case AtomicExpr::AO__hip_atomic_fetch_and:
-case AtomicExpr::AO__hip_atomic_fetch_max:
-case AtomicExpr::AO__hip_atomic_fetch_min:
-case AtomicExpr::AO__hip_atomic_fetch_or:
-case AtomicExpr::AO__hip_atomic_fetch_sub:
-case AtomicExpr::AO__hip_atomic_fetch_xor:
-case AtomicExpr::AO__opencl_atomic_fetch_add:
-case AtomicExpr::AO__opencl_atomic_fetch_and:
-case AtomicExpr::AO__opencl_atomic_fetch_max:
-case AtomicExpr::AO__opencl_atomic_fetch_min:
-case AtomicExpr::AO__opencl_atomic_fetch_or:
-case AtomicExpr::AO__opencl_atomic_fetch_sub:
-case AtomicExpr::AO__opencl_atomic_fetch_xor:
-case AtomicExpr::AO__scoped_atomic_fetch_add:
-case AtomicExpr::AO__scoped_atomic_fetch_and:
-case AtomicExpr::AO__scoped_atomic_fetch_max:
-case AtomicExpr::AO__scoped_atomic_fetch_min:
-case AtomicExpr::AO__scoped_atomic_fetch_nand:
-case AtomicExpr::AO__scoped_atomic_fetch_or:
-case AtomicExpr::AO__scoped_atomic_fetch_sub:
-case AtomicExpr::AO__scoped_atomic_fetch_xor:
-case AtomicExpr::AO__scoped_atomic_add_fetch:
-case AtomicExpr::AO__scoped_atomic_and_fetch:
-case AtomicExpr::AO__scoped_atomic_max_fetch:
-case AtomicExpr::AO__scoped_atomic_min_fetch:
-case AtomicExpr::AO__scoped_atomic_nand_fetch:
-case AtomicExpr::AO__scoped_atomic_or_fetch:
-case AtomicExpr::AO__scoped_atomic_sub_fetch:
-case AtomicExpr::AO__scoped_atomic_xor_fetch:
-  // For these, only library calls for certain sizes exist.
-  UseOptimizedLibcall = true;
-  break;
-
-case AtomicExpr::AO__atomic_load:
-case AtomicExpr::AO__atomic_store:
-case AtomicExpr::AO__atomic_exchange:
-case AtomicExpr::AO__atomic_compare_exchange:
-case AtomicExpr::AO__scoped_atomic_load:
-case AtomicExpr::AO__scoped_atomic_store:
-case AtomicExpr::AO__scoped_atomic_exchange:
-case AtomicExpr::AO__scoped_atomic_compare_exchange:
-  // Use the generic version if we don't know that the operand will be
-  // suitably aligned for the optimized version.
-  if (Misaligned)
-break;
-  [[fallthrough]];
-case AtomicExpr::AO__atomic_load_n:
-case AtomicExpr::AO__atomic_store_n:
-case AtomicExpr::AO__atomic_exchange_n:
-case AtomicExpr::AO__atomic_compare_exchange_n:
-case AtomicExpr::AO__c11_atomic_load:
-case AtomicExpr::AO__c11_atomic_store:
-case AtomicExpr::AO__c11_atomic_exchange:
-case AtomicExpr::AO__c11_atomic_compare_exchange_weak:
-case AtomicExpr::AO__c11_atomic_compare_exchange_strong:
-case AtomicExpr::AO__hip_atomic_load:
-case AtomicExpr::AO__hip_atomic_store:
-case AtomicExpr::AO__hip_atomic_exchange:
-case AtomicExpr::AO__hip_atomic_compare_exchange_weak:
-case AtomicExpr::AO__hip_atomic_compare_exchange_strong:
-case AtomicExpr::AO__opencl_atomic_load:
-case AtomicExpr::AO__opencl_atomic_store:
-case AtomicExpr::AO__opencl_atomic_exchange:
-case AtomicExpr::AO__opencl_atomic_compare_exchange_weak:
-case AtomicExpr::AO__opencl_atomic_compare_exchange_strong:
-case AtomicExpr::AO__scoped_atomic_load_n:
-case AtomicExpr::AO__scoped_atomic_store_n:
-case AtomicExpr::AO__scoped_atomic_exchange_n:
-case AtomicExpr::AO__scoped_atomic_compare_exchange_n:
-  // Only use optimized library calls for sizes for which

[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)

2024-01-10 Thread James Y Knight via cfe-commits

https://github.com/jyknight edited 
https://github.com/llvm/llvm-project/pull/73176
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)

2024-01-10 Thread James Y Knight via cfe-commits


@@ -1047,122 +1019,19 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) {
   Dest = Atomics.castToAtomicIntPointer(Dest);
   }
 
-  // Use a library call.  See: http://gcc.gnu.org/wiki/Atomic/GCCMM/LIbrary .
-  if (UseLibcall) {
-bool UseOptimizedLibcall = false;
-switch (E->getOp()) {
-case AtomicExpr::AO__c11_atomic_init:
-case AtomicExpr::AO__opencl_atomic_init:
-  llvm_unreachable("Already handled above with EmitAtomicInit!");
-
-case AtomicExpr::AO__atomic_fetch_add:
-case AtomicExpr::AO__atomic_fetch_and:
-case AtomicExpr::AO__atomic_fetch_max:
-case AtomicExpr::AO__atomic_fetch_min:
-case AtomicExpr::AO__atomic_fetch_nand:
-case AtomicExpr::AO__atomic_fetch_or:
-case AtomicExpr::AO__atomic_fetch_sub:
-case AtomicExpr::AO__atomic_fetch_xor:
-case AtomicExpr::AO__atomic_add_fetch:
-case AtomicExpr::AO__atomic_and_fetch:
-case AtomicExpr::AO__atomic_max_fetch:
-case AtomicExpr::AO__atomic_min_fetch:
-case AtomicExpr::AO__atomic_nand_fetch:
-case AtomicExpr::AO__atomic_or_fetch:
-case AtomicExpr::AO__atomic_sub_fetch:
-case AtomicExpr::AO__atomic_xor_fetch:
-case AtomicExpr::AO__c11_atomic_fetch_add:
-case AtomicExpr::AO__c11_atomic_fetch_and:
-case AtomicExpr::AO__c11_atomic_fetch_max:
-case AtomicExpr::AO__c11_atomic_fetch_min:
-case AtomicExpr::AO__c11_atomic_fetch_nand:
-case AtomicExpr::AO__c11_atomic_fetch_or:
-case AtomicExpr::AO__c11_atomic_fetch_sub:
-case AtomicExpr::AO__c11_atomic_fetch_xor:
-case AtomicExpr::AO__hip_atomic_fetch_add:
-case AtomicExpr::AO__hip_atomic_fetch_and:
-case AtomicExpr::AO__hip_atomic_fetch_max:
-case AtomicExpr::AO__hip_atomic_fetch_min:
-case AtomicExpr::AO__hip_atomic_fetch_or:
-case AtomicExpr::AO__hip_atomic_fetch_sub:
-case AtomicExpr::AO__hip_atomic_fetch_xor:
-case AtomicExpr::AO__opencl_atomic_fetch_add:
-case AtomicExpr::AO__opencl_atomic_fetch_and:
-case AtomicExpr::AO__opencl_atomic_fetch_max:
-case AtomicExpr::AO__opencl_atomic_fetch_min:
-case AtomicExpr::AO__opencl_atomic_fetch_or:
-case AtomicExpr::AO__opencl_atomic_fetch_sub:
-case AtomicExpr::AO__opencl_atomic_fetch_xor:
-case AtomicExpr::AO__scoped_atomic_fetch_add:
-case AtomicExpr::AO__scoped_atomic_fetch_and:
-case AtomicExpr::AO__scoped_atomic_fetch_max:
-case AtomicExpr::AO__scoped_atomic_fetch_min:
-case AtomicExpr::AO__scoped_atomic_fetch_nand:
-case AtomicExpr::AO__scoped_atomic_fetch_or:
-case AtomicExpr::AO__scoped_atomic_fetch_sub:
-case AtomicExpr::AO__scoped_atomic_fetch_xor:
-case AtomicExpr::AO__scoped_atomic_add_fetch:
-case AtomicExpr::AO__scoped_atomic_and_fetch:
-case AtomicExpr::AO__scoped_atomic_max_fetch:
-case AtomicExpr::AO__scoped_atomic_min_fetch:
-case AtomicExpr::AO__scoped_atomic_nand_fetch:
-case AtomicExpr::AO__scoped_atomic_or_fetch:
-case AtomicExpr::AO__scoped_atomic_sub_fetch:
-case AtomicExpr::AO__scoped_atomic_xor_fetch:
-  // For these, only library calls for certain sizes exist.
-  UseOptimizedLibcall = true;
-  break;
-
-case AtomicExpr::AO__atomic_load:
-case AtomicExpr::AO__atomic_store:
-case AtomicExpr::AO__atomic_exchange:
-case AtomicExpr::AO__atomic_compare_exchange:
-case AtomicExpr::AO__scoped_atomic_load:
-case AtomicExpr::AO__scoped_atomic_store:
-case AtomicExpr::AO__scoped_atomic_exchange:
-case AtomicExpr::AO__scoped_atomic_compare_exchange:
-  // Use the generic version if we don't know that the operand will be
-  // suitably aligned for the optimized version.
-  if (Misaligned)
-break;
-  [[fallthrough]];
-case AtomicExpr::AO__atomic_load_n:
-case AtomicExpr::AO__atomic_store_n:
-case AtomicExpr::AO__atomic_exchange_n:
-case AtomicExpr::AO__atomic_compare_exchange_n:
-case AtomicExpr::AO__c11_atomic_load:
-case AtomicExpr::AO__c11_atomic_store:
-case AtomicExpr::AO__c11_atomic_exchange:
-case AtomicExpr::AO__c11_atomic_compare_exchange_weak:
-case AtomicExpr::AO__c11_atomic_compare_exchange_strong:
-case AtomicExpr::AO__hip_atomic_load:
-case AtomicExpr::AO__hip_atomic_store:
-case AtomicExpr::AO__hip_atomic_exchange:
-case AtomicExpr::AO__hip_atomic_compare_exchange_weak:
-case AtomicExpr::AO__hip_atomic_compare_exchange_strong:
-case AtomicExpr::AO__opencl_atomic_load:
-case AtomicExpr::AO__opencl_atomic_store:
-case AtomicExpr::AO__opencl_atomic_exchange:
-case AtomicExpr::AO__opencl_atomic_compare_exchange_weak:
-case AtomicExpr::AO__opencl_atomic_compare_exchange_strong:
-case AtomicExpr::AO__scoped_atomic_load_n:
-case AtomicExpr::AO__scoped_atomic_store_n:
-case AtomicExpr::AO__scoped_atomic_exchange_n:
-case AtomicExpr::AO__scoped_atomic_compare_exchange_n:
-  // Only use optimized library calls for sizes for which

[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)

2024-01-10 Thread James Y Knight via cfe-commits


@@ -1,120 +1,147 @@
-// RUN: %clang_cc1 < %s -triple armv5e-none-linux-gnueabi -emit-llvm -O1 | 
FileCheck %s
-
-// FIXME: This file should not be checking -O1 output.
-// Ie, it is testing many IR optimizer passes as part of front-end 
verification.
+// RUN: %clang_cc1 < %s -triple armv5e-none-linux-gnueabi -emit-llvm | 
FileCheck %s

jyknight wrote:

Maybe the checks in this file should be generated with 
llvm/utils/update_cc_test_checks.py?

https://github.com/llvm/llvm-project/pull/73176
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)

2024-01-10 Thread James Y Knight via cfe-commits


@@ -7,22 +7,19 @@
 // RUN: %clang_cc1 -triple riscv64 -target-feature +a -O1 -emit-llvm %s -o - \
 // RUN:   | FileCheck %s -check-prefix=RV64IA
 
-// This test demonstrates that MaxAtomicInlineWidth is set appropriately when

jyknight wrote:

I think this test needs to be redone as a "-verify" test checking for 
diagnostics, like `clang/test/CodeGen/atomics-sema-alignment.c` does for 
aarch64, in order to continue testing what it's supposed to test.

https://github.com/llvm/llvm-project/pull/73176
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)

2024-01-10 Thread James Y Knight via cfe-commits

https://github.com/jyknight commented:

Overall, I think this is a great improvement.

And I believe it should be correct to do now, after fixing the backends' 
MaxAtomicSizeInBitsSupported in #75703 #75185 #75112 #74385 #74389, and fixing 
Clang's propagation of alignment to atomicrmw/cmpxchg in #74349.

Just a few more comments.

https://github.com/llvm/llvm-project/pull/73176
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)

2024-01-10 Thread James Y Knight via cfe-commits


@@ -23,7 +23,7 @@ typedef __int128_t int128_t;
 // PPC64-QUADWORD-ATOMICS:[[TMP3:%.*]] = load atomic i128, ptr 
[[TMP1:%.*]] acquire, align 16
 //
 // PPC64-LABEL: @test_load(
-// PPC64:call void @__atomic_load(i64 noundef 16, ptr noundef 
[[TMP3:%.*]], ptr noundef [[TMP4:%.*]], i32 noundef signext 2)
+// PPC64:[[TMP3:%.*]] = load atomic i128, ptr [[TMP1:%.*]] acquire, align 
16

jyknight wrote:

A lot of these are now redundant with PPC64-QUADWORD-ATOMICS. I'd make the 
tests use `--check-prefixes=PPC64,PPC64-QUADWORD-ATOMICS` and 
`--check-prefixes=PPC64,PPC64-NO-QUADWORD-ATOMICS` so you can share the check 
lines for the cases where it doesn't differ.

https://github.com/llvm/llvm-project/pull/73176
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)

2024-01-10 Thread James Y Knight via cfe-commits


@@ -33,9 +33,9 @@ void test_i32_atomics(_Atomic(int32_t) * a, int32_t b) {
 }
 
 void test_i64_atomics(_Atomic(int64_t) * a, int64_t b) {
-  // LA32: call i64 @__atomic_load_8
-  // LA32: call void @__atomic_store_8
-  // LA32: call i64 @__atomic_fetch_add_8
+  // LA32: load atomic i64, ptr %a seq_cst, align 8
+  // LA32: store atomic i64 %b, ptr %a seq_cst, align 8
+  // LA32: atomicrmw add ptr %a, i64 %b seq_cst

jyknight wrote:

Missing `, align 8`?

https://github.com/llvm/llvm-project/pull/73176
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] New calling convention preserve_none (PR #76868)

2024-01-10 Thread James Y Knight via cfe-commits


@@ -1056,6 +1056,23 @@ def CC_Intel_OCL_BI : CallingConv<[
   CCDelegateTo
 ]>;
 
+def CC_X86_64_Preserve_None : CallingConv<[
+  // We don't preserve general registers, so all of them can be used to pass
+  // arguments except
+  //   - RBPframe pointer
+  //   - R10'nest' parameter
+  //   - RBXbase pointer
+  //   - R16 - R31  these are not available everywhere
+  CCIfType<[i32], CCAssignToReg<[EDI, ESI, EDX, ECX, R8D, R9D,
+R11D, R12D, R13D, R14D, R15D, EAX]>>,
+
+  CCIfType<[i64], CCAssignToReg<[RDI, RSI, RDX, RCX, R8, R9,
+ R11, R12, R13, R14, R15, RAX]>>,
+
+  // Otherwise it's the same as the regular C calling convention.
+  CCDelegateTo

jyknight wrote:

This delegation seems questionable -- what about the interaction with the swift 
attributes which use dedicated registers in CC_X86_64_C, which you're now also 
using for normal parameters?

https://github.com/llvm/llvm-project/pull/76868
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] New calling convention preserve_none (PR #76868)

2024-01-11 Thread James Y Knight via cfe-commits


@@ -1056,6 +1056,23 @@ def CC_Intel_OCL_BI : CallingConv<[
   CCDelegateTo
 ]>;
 
+def CC_X86_64_Preserve_None : CallingConv<[
+  // We don't preserve general registers, so all of them can be used to pass
+  // arguments except
+  //   - RBPframe pointer
+  //   - R10'nest' parameter
+  //   - RBXbase pointer
+  //   - R16 - R31  these are not available everywhere

jyknight wrote:

They should not be used to pass arguments conditionally based on the current 
subtarget, since that creates two incompatible calling conventions.

There's no reason "preserve none" has to be read to imply "uses all possible 
registers to pass arguments.", so I don't see an issue with leaving it like it 
is.

https://github.com/llvm/llvm-project/pull/76868
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d614874 - [Clang] Implement __builtin_source_location.

2022-03-28 Thread James Y Knight via cfe-commits

Author: James Y Knight
Date: 2022-03-28T18:29:02-04:00
New Revision: d61487490022aaacc34249475fac3e208c7d767e

URL: 
https://github.com/llvm/llvm-project/commit/d61487490022aaacc34249475fac3e208c7d767e
DIFF: 
https://github.com/llvm/llvm-project/commit/d61487490022aaacc34249475fac3e208c7d767e.diff

LOG: [Clang] Implement __builtin_source_location.

This builtin returns the address of a global instance of the
`std::source_location::__impl` type, which must be defined (with an
appropriate shape) before calling the builtin.

It will be used to implement std::source_location in libc++ in a
future change. The builtin is compatible with GCC's implementation,
and libstdc++'s usage. An intentional divergence is that GCC declares
the builtin's return type to be `const void*` (for
ease-of-implementation reasons), while Clang uses the actual type,
`const std::source_location::__impl*`.

In order to support this new functionality, I've also added a new
'UnnamedGlobalConstantDecl'. This artificial Decl is modeled after
MSGuidDecl, and is used to represent a generic concept of an lvalue
constant with global scope, deduplicated by its value. It's possible
that MSGuidDecl itself, or some of the other similar sorts of things
in Clang might be able to be refactored onto this more-generic
concept, but there's enough special-case weirdness in MSGuidDecl that
I gave up attempting to share code there, at least for now.

Finally, for compatibility with libstdc++'s  header,
I've added a second exception to the "cannot cast from void* to T* in
constant evaluation" rule. This seems a bit distasteful, but feels
like the best available option.

Reviewers: aaron.ballman, erichkeane

Differential Revision: https://reviews.llvm.org/D120159

Added: 
clang/test/SemaCXX/source_location_err.cpp

Modified: 
clang/docs/LanguageExtensions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/ASTContext.h
clang/include/clang/AST/DeclCXX.h
clang/include/clang/AST/Expr.h
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/AST/Stmt.h
clang/include/clang/Basic/DeclNodes.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/TokenKinds.def
clang/include/clang/Sema/Sema.h
clang/include/clang/Serialization/ASTBitCodes.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/DeclBase.cpp
clang/lib/AST/DeclCXX.cpp
clang/lib/AST/Expr.cpp
clang/lib/AST/ExprClassification.cpp
clang/lib/AST/ExprConstant.cpp
clang/lib/CodeGen/CGDecl.cpp
clang/lib/CodeGen/CGExprConstant.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenModule.h
clang/lib/Parse/ParseExpr.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTCommon.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriterDecl.cpp
clang/test/CodeGenCXX/builtin-source-location.cpp
clang/test/SemaCXX/source_location.cpp
clang/tools/libclang/CIndex.cpp

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 45fb8efaf8b01..0391102fb222c 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -3377,10 +3377,9 @@ as the first argument to the intrinsic.
 Source location builtins
 
 
-Clang provides experimental builtins to support C++ standard library 
implementation
-of ``std::experimental::source_location`` as specified in  
http://wg21.link/N4600.
-With the exception of ``__builtin_COLUMN``, these builtins are also 
implemented by
-GCC.
+Clang provides builtins to support C++ standard library implementation
+of ``std::source_location`` as specified in C++20.  With the exception
+of ``__builtin_COLUMN``, these builtins are also implemented by GCC.
 
 **Syntax**:
 
@@ -3390,6 +3389,7 @@ GCC.
   const char *__builtin_FUNCTION();
   unsigned__builtin_LINE();
   unsigned__builtin_COLUMN(); // Clang only
+  const std::source_location::__impl *__builtin_source_location();
 
 **Example of use**:
 
@@ -3416,9 +3416,11 @@ GCC.
 
 **Description**:
 
-The builtins ``__builtin_LINE``, ``__builtin_FUNCTION``, and 
``__builtin_FILE`` return
-the values, at the "invocation point", for ``__LINE__``, ``__FUNCTION__``, and
-``__FILE__`` respectively. These builtins are constant expressions.
+The builtins ``__builtin_LINE``, ``__builtin_FUNCTION``, and ``__builtin_FILE``
+return the values, at the "invocation point", for ``__LINE__``,
+``__FUNCTION__``, and ``__FILE__`` respectively. ``__builtin_COLUMN`` similarly
+returns the column, though there is no corresponding macro. These buil

[clang] 8f66f13 - Fix memory leak in [Clang] Implement __builtin_source_location.

2022-03-29 Thread James Y Knight via cfe-commits

Author: James Y Knight
Date: 2022-03-29T17:32:59-04:00
New Revision: 8f66f1371981bda1af1ca43d505e1bc5836b3e36

URL: 
https://github.com/llvm/llvm-project/commit/8f66f1371981bda1af1ca43d505e1bc5836b3e36
DIFF: 
https://github.com/llvm/llvm-project/commit/8f66f1371981bda1af1ca43d505e1bc5836b3e36.diff

LOG: Fix memory leak in [Clang] Implement __builtin_source_location.

Fixes: d61487490022

Added: 


Modified: 
clang/include/clang/AST/DeclCXX.h
clang/lib/AST/DeclCXX.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index f5bd856fdb186..04a9daa14e05e 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -4221,7 +4221,8 @@ class UnnamedGlobalConstantDecl : public ValueDecl,
 
   void anchor() override;
 
-  UnnamedGlobalConstantDecl(DeclContext *DC, QualType T, const APValue &Val);
+  UnnamedGlobalConstantDecl(const ASTContext &C, DeclContext *DC, QualType T,
+const APValue &Val);
 
   static UnnamedGlobalConstantDecl *Create(const ASTContext &C, QualType T,
const APValue &APVal);

diff  --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index b3f3efee9931e..cb6a355f7294a 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -3365,23 +3365,30 @@ APValue &MSGuidDecl::getAsAPValue() const {
 
 void UnnamedGlobalConstantDecl::anchor() {}
 
-UnnamedGlobalConstantDecl::UnnamedGlobalConstantDecl(DeclContext *DC,
+UnnamedGlobalConstantDecl::UnnamedGlobalConstantDecl(const ASTContext &C,
+ DeclContext *DC,
  QualType Ty,
- const APValue &Value)
+ const APValue &Val)
 : ValueDecl(Decl::UnnamedGlobalConstant, DC, SourceLocation(),
 DeclarationName(), Ty),
-  Value(Value) {}
+  Value(Val) {
+  // Cleanup the embedded APValue if required (note that our destructor is 
never
+  // run)
+  if (Value.needsCleanup())
+C.addDestruction(&Value);
+}
 
 UnnamedGlobalConstantDecl *
 UnnamedGlobalConstantDecl::Create(const ASTContext &C, QualType T,
   const APValue &Value) {
   DeclContext *DC = C.getTranslationUnitDecl();
-  return new (C, DC) UnnamedGlobalConstantDecl(DC, T, Value);
+  return new (C, DC) UnnamedGlobalConstantDecl(C, DC, T, Value);
 }
 
 UnnamedGlobalConstantDecl *
 UnnamedGlobalConstantDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
-  return new (C, ID) UnnamedGlobalConstantDecl(nullptr, QualType(), APValue());
+  return new (C, ID)
+  UnnamedGlobalConstantDecl(C, nullptr, QualType(), APValue());
 }
 
 void UnnamedGlobalConstantDecl::printName(llvm::raw_ostream &OS) const {



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


[clang] caa1ebd - Don't assume that a new cleanup was added to InnermostEHScope.

2022-02-04 Thread James Y Knight via cfe-commits

Author: James Y Knight
Date: 2022-02-04T23:39:42-05:00
New Revision: caa1ebde70673ddb7124a0599ba846362a1f8b1e

URL: 
https://github.com/llvm/llvm-project/commit/caa1ebde70673ddb7124a0599ba846362a1f8b1e
DIFF: 
https://github.com/llvm/llvm-project/commit/caa1ebde70673ddb7124a0599ba846362a1f8b1e.diff

LOG: Don't assume that a new cleanup was added to InnermostEHScope.

After fa87fa97fb79, this was no longer guaranteed to be the cleanup
just added by this code, if IsEHCleanup got disabled. Instead, use
stable_begin(), which _is_ guaranteed to be the cleanup just added.

This caused a crash when a object that is callee destroyed (e.g. with the MS 
ABI) was passed in a call from a noexcept function.

Added a test to verify.

Fixes: fa87fa97fb79

Added: 


Modified: 
clang/lib/CodeGen/CGCall.cpp
clang/test/CodeGenCXX/microsoft-abi-eh-cleanups.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index a37ff8844e885..67a3f73525e35 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -4331,7 +4331,7 @@ void CodeGenFunction::EmitCallArg(CallArgList &args, 
const Expr *E,
   type);
   // This unreachable is a temporary marker which will be removed later.
   llvm::Instruction *IsActive = Builder.CreateUnreachable();
-  args.addArgCleanupDeactivation(EHStack.getInnermostEHScope(), IsActive);
+  args.addArgCleanupDeactivation(EHStack.stable_begin(), IsActive);
 }
 return;
   }

diff  --git a/clang/test/CodeGenCXX/microsoft-abi-eh-cleanups.cpp 
b/clang/test/CodeGenCXX/microsoft-abi-eh-cleanups.cpp
index 92fa17b145001..e6d602464d9b3 100644
--- a/clang/test/CodeGenCXX/microsoft-abi-eh-cleanups.cpp
+++ b/clang/test/CodeGenCXX/microsoft-abi-eh-cleanups.cpp
@@ -32,6 +32,28 @@ void HasEHCleanup() {
 // WIN32-NOT: @"??1A@@QAE@XZ"
 // WIN32: }
 
+
+// This test verifies the fix for a crash that occurred after
+// fa87fa97fb79.
+void HasEHCleanupNoexcept() noexcept {
+  TakesTwo(getA(), getA());
+}
+
+// With exceptions, we need to clean up at least one of these temporaries.
+// WIN32-LABEL: define dso_local void @"?HasEHCleanupNoexcept@@YAXXZ"() {{.*}} 
{
+// WIN32:   %[[base:.*]] = call i8* @llvm.stacksave()
+// WIN32:   invoke void @"?getA@@YA?AUA@@XZ"(%struct.A* sret(%struct.A) align 
4 %{{.*}})
+// WIN32:   invoke void @"?getA@@YA?AUA@@XZ"(%struct.A* sret(%struct.A) align 
4 %{{.*}})
+// WIN32:   invoke noundef i32 @"?TakesTwo@@YAHUA@@0@Z"
+// WIN32:   call void @llvm.stackrestore
+// WIN32:   ret void
+//
+//Since all the calls terminate, there should be no dtors on the unwind
+// WIN32:   cleanuppad
+// WIN32-NOT: @"??1A@@QAE@XZ"
+// WIN32: }
+
+
 void TakeRef(const A &a);
 int HasDeactivatedCleanups() {
   return TakesTwo((TakeRef(A()), A()), (TakeRef(A()), A()));



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


[clang] 9545976 - Revert "[Clang] Propagate guaranteed alignment for malloc and others"

2022-02-08 Thread James Y Knight via cfe-commits

Author: James Y Knight
Date: 2022-02-08T14:34:44-05:00
New Revision: 9545976ff160e19805a84a06a7e59d446f9994d9

URL: 
https://github.com/llvm/llvm-project/commit/9545976ff160e19805a84a06a7e59d446f9994d9
DIFF: 
https://github.com/llvm/llvm-project/commit/9545976ff160e19805a84a06a7e59d446f9994d9.diff

LOG: Revert "[Clang] Propagate guaranteed alignment for malloc and others"

The above change assumed that malloc (and friends) would always
allocate memory to getNewAlign(), even for allocations which have a
smaller size. This is not actually required by spec (a 1-byte
allocation may validly have 1-byte alignment).

Some real-world malloc implementations do not provide this guarantee,
and thus this optimization is breaking programs.

Fixes #53540

This reverts commit c2297544c04764237cedc523083c7be2fb3833d4.

Differential Revision: https://reviews.llvm.org/D118804

Added: 


Modified: 
clang/include/clang/Basic/TargetInfo.h
clang/lib/Sema/SemaDecl.cpp
clang/test/CodeGen/alloc-fns-alignment.c

Removed: 




diff  --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 324c123e5be72..22918f7e12e84 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -646,8 +646,8 @@ class TargetInfo : public virtual TransferrableTargetInfo,
   }
 
   /// Return the largest alignment for which a suitably-sized allocation with
-  /// '::operator new(size_t)' or 'malloc' is guaranteed to produce a
-  /// correctly-aligned pointer.
+  /// '::operator new(size_t)' is guaranteed to produce a correctly-aligned
+  /// pointer.
   unsigned getNewAlign() const {
 return NewAlign ? NewAlign : std::max(LongDoubleAlign, LongLongAlign);
   }

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index fce33991c4aa4..71c5fa5509760 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -15320,23 +15320,7 @@ void Sema::AddKnownFunctionAttributes(FunctionDecl 
*FD) {
   if (!FD->hasAttr())
 FD->addAttr(AllocAlignAttr::CreateImplicit(Context, ParamIdx(1, FD),
FD->getLocation()));
-  LLVM_FALLTHROUGH;
-case Builtin::BIcalloc:
-case Builtin::BImalloc:
-case Builtin::BIrealloc:
-case Builtin::BIstrdup:
-case Builtin::BIstrndup: {
-  if (!FD->hasAttr()) {
-unsigned NewAlign = Context.getTargetInfo().getNewAlign() /
-Context.getTargetInfo().getCharWidth();
-IntegerLiteral *Alignment = IntegerLiteral::Create(
-Context, Context.MakeIntValue(NewAlign, Context.UnsignedIntTy),
-Context.UnsignedIntTy, FD->getLocation());
-FD->addAttr(AssumeAlignedAttr::CreateImplicit(
-Context, Alignment, /*Offset=*/nullptr, FD->getLocation()));
-  }
   break;
-}
 default:
   break;
 }

diff  --git a/clang/test/CodeGen/alloc-fns-alignment.c 
b/clang/test/CodeGen/alloc-fns-alignment.c
index 29d6e9e4fb380..bbd213a2bf048 100644
--- a/clang/test/CodeGen/alloc-fns-alignment.c
+++ b/clang/test/CodeGen/alloc-fns-alignment.c
@@ -1,12 +1,9 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm < %s | 
FileCheck %s --check-prefix=ALIGN16
-// RUN: %clang_cc1 -triple x86_64-windows-msvc  -emit-llvm < %s | 
FileCheck %s --check-prefix=ALIGN16
-// RUN: %clang_cc1 -triple i386-apple-darwin-emit-llvm < %s | 
FileCheck %s --check-prefix=ALIGN16
-// RUN: %clang_cc1 -triple i386-unknown-linux-gnu   -emit-llvm < %s | 
FileCheck %s --check-prefix=ALIGN8
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-malloc  
-emit-llvm < %s  | FileCheck %s --check-prefix=NOBUILTIN-MALLOC
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-calloc  
-emit-llvm < %s  | FileCheck %s --check-prefix=NOBUILTIN-CALLOC
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-realloc 
-emit-llvm < %s  | FileCheck %s --check-prefix=NOBUILTIN-REALLOC
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-aligned_alloc 
-emit-llvm < %s  | FileCheck %s --check-prefix=NOBUILTIN-ALIGNED_ALLOC
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-memalign 
-emit-llvm < %s  | FileCheck %s --check-prefix=NOBUILTIN-MEMALIGN
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm < %s | 
FileCheck %s
+
+// Note: this test originally asserted that malloc/calloc/realloc got alignment
+// attributes on their return pointer. However, that was reverted in
+// https://reviews.llvm.org/D118804 and it now asserts that they do _NOT_ get
+// align attributes.
 
 typedef __SIZE_TYPE__ size_t;
 
@@ -49,57 +46,36 @@ void *memalign_large_constant_test(size_t n) {
 }
 
 // CHECK-LABEL: @malloc_test
-// ALIGN16: align 16 i8* 

  1   2   3   4   5   6   7   8   9   >