[PATCH] D154503: [Sema] Fix handling of functions that hide classes

2023-08-18 Thread John Brawn via Phabricator via cfe-commits
john.brawn added a comment.

I've committed an updated version of this that checks for invalid decls when 
deciding if a decl has been hidden. This stops the assertion failure happening.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154503

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


[PATCH] D154503: [Sema] Fix handling of functions that hide classes

2023-08-17 Thread John Brawn via Phabricator via cfe-commits
john.brawn added a comment.

I've committed a test for the behaviour when we have invalid decls in 
https://reviews.llvm.org/rG6244e3840694.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154503

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


[PATCH] D154503: [Sema] Fix handling of functions that hide classes

2023-07-25 Thread John Brawn via Phabricator via cfe-commits
john.brawn added a comment.

The first version of this that I committed caused a failure in  
clang/test/Modules/stress1.cpp so I reverted it. I've now committed a new 
version that handles the removal of existing decl when isPreferredLookupResult 
is true in a slightly different way, which should fix that failure.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154503

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


[PATCH] D154503: [Sema] Fix handling of functions that hide classes

2023-07-24 Thread John Brawn via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdfca88341794: [Sema] Fix handling of functions that hide 
classes (authored by john.brawn).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154503

Files:
  clang/lib/Sema/SemaLookup.cpp
  clang/test/SemaCXX/using-hiding.cpp

Index: clang/test/SemaCXX/using-hiding.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/using-hiding.cpp
@@ -0,0 +1,373 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+namespace A {
+  class X { }; // expected-note{{candidate found by name lookup is 'A::X'}}
+   // expected-note@-1{{candidate found by name lookup is 'A::X'}}
+}
+namespace B {
+  void X(int); // expected-note{{candidate found by name lookup is 'B::X'}}
+   // expected-note@-1{{candidate found by name lookup is 'B::X'}}
+}
+
+// Using directive doesn't cause A::X to be hidden, so X is ambiguous.
+namespace Test1a {
+  using namespace A;
+  using namespace B;
+
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
+
+namespace Test1b {
+  using namespace B;
+  using namespace A;
+
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
+
+// The behaviour here should be the same as using namespaces A and B directly
+namespace Test2a {
+  namespace C {
+using A::X; // expected-note{{candidate found by name lookup is 'Test2a::C::X'}}
+  }
+  namespace D {
+using B::X; // expected-note{{candidate found by name lookup is 'Test2a::D::X'}}
+  }
+  using namespace C;
+  using namespace D;
+
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
+
+namespace Test2b {
+  namespace C {
+using A::X; // expected-note{{candidate found by name lookup is 'Test2b::C::X'}}
+  }
+  namespace D {
+using B::X; // expected-note{{candidate found by name lookup is 'Test2b::D::X'}}
+  }
+  using namespace D;
+  using namespace C;
+
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
+
+// Defining a function X inside C should hide using A::X in C but not D, so the result is ambiguous.
+namespace Test3a {
+  namespace C {
+using A::X;
+void X(int); // expected-note{{candidate found by name lookup is 'Test3a::C::X'}}
+  }
+  namespace D {
+using A::X; // expected-note{{candidate found by name lookup is 'Test3a::D::X'}}
+  }
+  using namespace C;
+  using namespace D;
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
+
+namespace Test3b {
+  namespace C {
+using A::X;
+void X(int); // expected-note{{candidate found by name lookup is 'Test3b::C::X'}}
+  }
+  namespace D {
+using A::X; // expected-note{{candidate found by name lookup is 'Test3b::D::X'}}
+  }
+  using namespace D;
+  using namespace C;
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
+
+namespace Test3c {
+  namespace C {
+void X(int); // expected-note{{candidate found by name lookup is 'Test3c::C::X'}}
+using A::X;
+  }
+  namespace D {
+using A::X; // expected-note{{candidate found by name lookup is 'Test3c::D::X'}}
+  }
+  using namespace C;
+  using namespace D;
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
+
+namespace Test3d {
+  namespace C {
+void X(int); // expected-note{{candidate found by name lookup is 'Test3d::C::X'}}
+using A::X;
+  }
+  namespace D {
+using A::X; // expected-note{{candidate found by name lookup is 'Test3d::D::X'}}
+  }
+  using namespace D;
+  using namespace C;
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
+
+// A::X hidden in both C and D by overloaded function, so the result is not ambiguous.
+namespace Test4a {
+  namespace C {
+using A::X;
+void X(int);
+  }
+  namespace D {
+using A::X;
+void X(int, int);
+  }
+  using namespace C;
+  using namespace D;
+  void f() {
+X(1);
+  }
+}
+
+namespace Test4b {
+  namespace C {
+using A::X;
+void X(int);
+  }
+  namespace D {
+using A::X;
+void X(int, int);
+  }
+  using namespace D;
+  using namespace C;
+  void f() {
+X(1);
+  }
+}
+
+namespace Test4c {
+  namespace C {
+void X(int);
+using A::X;
+  }
+  namespace D {
+void X(int, int);
+using A::X;
+  }
+  using namespace C;
+  using namespace D;
+  void f() {
+X(1);
+  }
+}
+
+namespace Test4d {
+  namespace C {
+void X(int);
+using A::X;
+  }
+  namespace D {
+void X(int, int);
+using A::X;
+  }
+  using namespace D;
+  using namespace C;
+  void f() {
+X(1);
+  }
+}
+
+// B::X hides class X in C, so the the result is not ambiguous
+namespace Test5a {
+  namespace C {
+using B::X;
+class X { };
+  }
+  namespace D {
+

[PATCH] D154503: [Sema] Fix handling of functions that hide classes

2023-07-21 Thread John Brawn via Phabricator via cfe-commits
john.brawn updated this revision to Diff 542893.
john.brawn edited the summary of this revision.
john.brawn added a comment.

Restructured to check for hidden tags in the main loop. Also add a bunch of 
extra tests.


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

https://reviews.llvm.org/D154503

Files:
  clang/lib/Sema/SemaLookup.cpp
  clang/test/SemaCXX/using-hiding.cpp

Index: clang/test/SemaCXX/using-hiding.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/using-hiding.cpp
@@ -0,0 +1,373 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+namespace A {
+  class X { }; // expected-note{{candidate found by name lookup is 'A::X'}}
+   // expected-note@-1{{candidate found by name lookup is 'A::X'}}
+}
+namespace B {
+  void X(int); // expected-note{{candidate found by name lookup is 'B::X'}}
+   // expected-note@-1{{candidate found by name lookup is 'B::X'}}
+}
+
+// Using directive doesn't cause A::X to be hidden, so X is ambiguous.
+namespace Test1a {
+  using namespace A;
+  using namespace B;
+
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
+
+namespace Test1b {
+  using namespace B;
+  using namespace A;
+
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
+
+// The behaviour here should be the same as using namespaces A and B directly
+namespace Test2a {
+  namespace C {
+using A::X; // expected-note{{candidate found by name lookup is 'Test2a::C::X'}}
+  }
+  namespace D {
+using B::X; // expected-note{{candidate found by name lookup is 'Test2a::D::X'}}
+  }
+  using namespace C;
+  using namespace D;
+
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
+
+namespace Test2b {
+  namespace C {
+using A::X; // expected-note{{candidate found by name lookup is 'Test2b::C::X'}}
+  }
+  namespace D {
+using B::X; // expected-note{{candidate found by name lookup is 'Test2b::D::X'}}
+  }
+  using namespace D;
+  using namespace C;
+
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
+
+// Defining a function X inside C should hide using A::X in C but not D, so the result is ambiguous.
+namespace Test3a {
+  namespace C {
+using A::X;
+void X(int); // expected-note{{candidate found by name lookup is 'Test3a::C::X'}}
+  }
+  namespace D {
+using A::X; // expected-note{{candidate found by name lookup is 'Test3a::D::X'}}
+  }
+  using namespace C;
+  using namespace D;
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
+
+namespace Test3b {
+  namespace C {
+using A::X;
+void X(int); // expected-note{{candidate found by name lookup is 'Test3b::C::X'}}
+  }
+  namespace D {
+using A::X; // expected-note{{candidate found by name lookup is 'Test3b::D::X'}}
+  }
+  using namespace D;
+  using namespace C;
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
+
+namespace Test3c {
+  namespace C {
+void X(int); // expected-note{{candidate found by name lookup is 'Test3c::C::X'}}
+using A::X;
+  }
+  namespace D {
+using A::X; // expected-note{{candidate found by name lookup is 'Test3c::D::X'}}
+  }
+  using namespace C;
+  using namespace D;
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
+
+namespace Test3d {
+  namespace C {
+void X(int); // expected-note{{candidate found by name lookup is 'Test3d::C::X'}}
+using A::X;
+  }
+  namespace D {
+using A::X; // expected-note{{candidate found by name lookup is 'Test3d::D::X'}}
+  }
+  using namespace D;
+  using namespace C;
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
+
+// A::X hidden in both C and D by overloaded function, so the result is not ambiguous.
+namespace Test4a {
+  namespace C {
+using A::X;
+void X(int);
+  }
+  namespace D {
+using A::X;
+void X(int, int);
+  }
+  using namespace C;
+  using namespace D;
+  void f() {
+X(1);
+  }
+}
+
+namespace Test4b {
+  namespace C {
+using A::X;
+void X(int);
+  }
+  namespace D {
+using A::X;
+void X(int, int);
+  }
+  using namespace D;
+  using namespace C;
+  void f() {
+X(1);
+  }
+}
+
+namespace Test4c {
+  namespace C {
+void X(int);
+using A::X;
+  }
+  namespace D {
+void X(int, int);
+using A::X;
+  }
+  using namespace C;
+  using namespace D;
+  void f() {
+X(1);
+  }
+}
+
+namespace Test4d {
+  namespace C {
+void X(int);
+using A::X;
+  }
+  namespace D {
+void X(int, int);
+using A::X;
+  }
+  using namespace D;
+  using namespace C;
+  void f() {
+X(1);
+  }
+}
+
+// B::X hides class X in C, so the the result is not ambiguous
+namespace Test5a {
+  namespace C {
+using B::X;
+class X { };
+  }
+  namespace D {
+using B::X;
+  }
+  using namespace C;
+  using namespace D;
+  

[PATCH] D154503: [Sema] Fix handling of functions that hide classes

2023-07-19 Thread John Brawn via Phabricator via cfe-commits
john.brawn added inline comments.



Comment at: clang/lib/Sema/SemaLookup.cpp:542
+N = Decls.size();
+  }
+

rjmccall wrote:
> dexonsmith wrote:
> > john.brawn wrote:
> > > rjmccall wrote:
> > > > john.brawn wrote:
> > > > > rjmccall wrote:
> > > > > > This is going to fire on every single ordinary lookup that finds 
> > > > > > multiple declarations, right?  I haven't fully internalized the 
> > > > > > issue you're solving here, but this is a very performance-sensitive 
> > > > > > path in the compiler; there's a reason this code is written to very 
> > > > > > carefully only do extra work when we've detected in the loop below 
> > > > > > that we're in a hidden-declarations situation.  Is there any way we 
> > > > > > can restore that basic structure?
> > > > > Test4 in the added tests is an example of why we can't wait until 
> > > > > after the main loop. The `using A::X` in namespace D is eliminated by 
> > > > > the UniqueResult check, so the check for a declaration being hidden 
> > > > > can only see the using declarations in namespace C. We also can't do 
> > > > > it in the loop itself, as then we can't handle Test5: at the time we 
> > > > > process the `using A::X` in namespace D it looks like it may cause 
> > > > > ambiguity, but it's later hidden by the `using B::X` in the same 
> > > > > namespace which we haven't yet processed.
> > > > > 
> > > > > I have adjusted it though so the nested loop and erasing of decls 
> > > > > only happens when we both have things that hide and things that can 
> > > > > be hidden. Doing some quick testing of compiling SemaOpenMP.cpp (the 
> > > > > largest file in clang), LookupResult::resolveKind is called 75318 
> > > > > times, of which 75283 calls have HideTags=true, of which 56 meet this 
> > > > > condition, i.e. 0.07%.
> > > > Okay, I can see why you need to not mix tag-hiding with the removal of 
> > > > duplicates.  However, I think you can maintain the current structure by 
> > > > delaying the actual removal of declarations until after the main loop; 
> > > > have the loop build up a set of indices to remove instead.  (Also, you 
> > > > can keep this set as a bitset instead of a `std::set`.)
> > > > 
> > > > It's a shame that the hiding algorithm has to check every other 
> > > > declaration in the lookup in case they're from different scopes.  I 
> > > > guess to avoid that we'd have to do the filtering immediately when we 
> > > > collect the declarations from a particular DC.
> > > I think that delaying the removal until after the main loop would just 
> > > complicate things, as then in the main loop we would have to check each 
> > > index to see if it's something we're going to later remove. I can adjust 
> > > it to do the erasing more like it's done in the main loop though, i.e. 
> > > move the erased element to the end and decrement N, so the call to 
> > > Decls.truncate will remove it. We can't use bitset though, as that takes 
> > > the size of the bitset (which in this case would be the number of decls) 
> > > as a template parameter.
> > llvm::BitVector should work for this. 
> Why would the main loop need to check indices to see if it's something we're 
> going to remove?  You just need to check whether a tag is hidden before you 
> add it to `UniqueTypes`.
That seems to be the same thing I said, but phrased in a different way? It's 
not entirely clear to me what exactly you want the code to look like. It sound 
like you'd want it to be something like
```
llvm::BitVector HiddenDecls(N);
if (HideTags) {
  // Add hidden decls to HiddenDecls
}
while (I < N) {
  if (HiddenDecls[I]) // Ignore hidden decls
continue;
  // Existing code in main loop
}
for (I : HiddenDecls)
  // remove this decl
```
I don't see how this would be better. Why delay the removal when we can just do 
it right away?


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

https://reviews.llvm.org/D154503

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


[PATCH] D154503: [Sema] Fix handling of functions that hide classes

2023-07-11 Thread John Brawn via Phabricator via cfe-commits
john.brawn updated this revision to Diff 539142.
john.brawn added a comment.

Use BitVector, change how Decls are deleted, adjust test to avoid 
potentially-conflicting using-declarations.


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

https://reviews.llvm.org/D154503

Files:
  clang/lib/Sema/SemaLookup.cpp
  clang/test/SemaCXX/using-hiding.cpp

Index: clang/test/SemaCXX/using-hiding.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/using-hiding.cpp
@@ -0,0 +1,100 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+namespace A {
+  class X { }; // expected-note{{candidate found by name lookup is 'A::X'}}
+}
+namespace B {
+  void X(int); // expected-note{{candidate found by name lookup is 'B::X'}}
+}
+
+// Using directive doesn't cause A::X to be hidden, so X is ambiguous.
+namespace Test1 {
+  using namespace A;
+  using namespace B;
+
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
+
+// The behaviour here should be the same as using namespaces A and B directly
+namespace Test2 {
+  namespace C {
+using A::X; // expected-note{{candidate found by name lookup is 'Test2::C::X'}}
+  }
+  namespace D {
+using B::X; // expected-note{{candidate found by name lookup is 'Test2::D::X'}}
+  }
+  using namespace C;
+  using namespace D;
+
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
+
+// Defining a function X inside C should hide using A::X in C but not D, so the result is ambiguous.
+namespace Test3 {
+  namespace C {
+using A::X;
+void X(int); // expected-note{{candidate found by name lookup is 'Test3::C::X'}}
+  }
+  namespace D {
+using A::X; // expected-note{{candidate found by name lookup is 'Test3::D::X'}}
+  }
+  using namespace C;
+  using namespace D;
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
+
+// A::X hidden in both C and D by overloaded function, so the result is not ambiguous.
+namespace Test4 {
+  namespace C {
+using A::X;
+void X(int);
+  }
+  namespace D {
+using A::X;
+void X(int, int);
+  }
+  using namespace C;
+  using namespace D;
+  void f() {
+X(1);
+  }
+}
+
+// C and D declare a class X, but it's hidden so the result is not ambiguous.
+namespace Test5 {
+  namespace C {
+class X { };
+using B::X;
+  }
+  namespace D {
+class X { };
+using B::X;
+  }
+  using namespace C;
+  using namespace D;
+  void f() {
+X(1);
+  }
+}
+
+// function X inside C should hide class X in C but not D.
+namespace Test6 {
+  namespace C {
+class X;
+void X(int); // expected-note{{candidate found by name lookup is 'Test6::C::X'}}
+  }
+  namespace D {
+class X; // expected-note{{candidate found by name lookup is 'Test6::D::X'}}
+  }
+  using namespace C;
+  using namespace D;
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
Index: clang/lib/Sema/SemaLookup.cpp
===
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -504,6 +504,48 @@
   // Don't do any extra resolution if we've already resolved as ambiguous.
   if (ResultKind == Ambiguous) return;
 
+  // C++ [basic.scope.hiding]p2:
+  //   A class name or enumeration name can be hidden by the name of
+  //   an object, function, or enumerator declared in the same
+  //   scope. If a class or enumeration name and an object, function,
+  //   or enumerator are declared in the same scope (in any order)
+  //   with the same name, the class or enumeration name is hidden
+  //   wherever the object, function, or enumerator name is visible.
+  if (HideTags) {
+// First collect all decls that can hide others and those that can be hidden
+llvm::BitVector CanHideOther(N), CanBeHidden(N);
+for (unsigned I = 0; I < N; ++I) {
+  const NamedDecl *D = Decls[I]->getUnderlyingDecl();
+  D = cast(D->getCanonicalDecl());
+  if (isa(D))
+CanBeHidden.set(I);
+  else if (canHideTag(D))
+CanHideOther.set(I);
+}
+
+if (!CanBeHidden.empty() && !CanHideOther.empty()) {
+  // Collect those decls that will be hidden
+  llvm::BitVector HiddenDecls(N);
+  for (unsigned HiddenI : CanBeHidden.set_bits()) {
+for (unsigned HiderI : CanHideOther.set_bits()) {
+  if (getContextForScopeMatching(Decls[HiderI])
+  ->Equals(getContextForScopeMatching(Decls[HiddenI]))) {
+HiddenDecls.set(HiddenI);
+break;
+  }
+}
+  }
+
+  // Erase hidden decls by replacing them with decls from the end (which
+  // means that we need to iterate from the end). N is adjusted so we don't
+  // see the extra copies at the end, and they're removed when we call
+  // truncate at the end.
+  for (int I = HiddenDecls.find_last(); I >= 0;
+   I = HiddenDecls.find_prev(I))
+

[PATCH] D154503: [Sema] Fix handling of functions that hide classes

2023-07-11 Thread John Brawn via Phabricator via cfe-commits
john.brawn added inline comments.



Comment at: clang/lib/Sema/SemaLookup.cpp:542
+N = Decls.size();
+  }
+

rjmccall wrote:
> john.brawn wrote:
> > rjmccall wrote:
> > > This is going to fire on every single ordinary lookup that finds multiple 
> > > declarations, right?  I haven't fully internalized the issue you're 
> > > solving here, but this is a very performance-sensitive path in the 
> > > compiler; there's a reason this code is written to very carefully only do 
> > > extra work when we've detected in the loop below that we're in a 
> > > hidden-declarations situation.  Is there any way we can restore that 
> > > basic structure?
> > Test4 in the added tests is an example of why we can't wait until after the 
> > main loop. The `using A::X` in namespace D is eliminated by the 
> > UniqueResult check, so the check for a declaration being hidden can only 
> > see the using declarations in namespace C. We also can't do it in the loop 
> > itself, as then we can't handle Test5: at the time we process the `using 
> > A::X` in namespace D it looks like it may cause ambiguity, but it's later 
> > hidden by the `using B::X` in the same namespace which we haven't yet 
> > processed.
> > 
> > I have adjusted it though so the nested loop and erasing of decls only 
> > happens when we both have things that hide and things that can be hidden. 
> > Doing some quick testing of compiling SemaOpenMP.cpp (the largest file in 
> > clang), LookupResult::resolveKind is called 75318 times, of which 75283 
> > calls have HideTags=true, of which 56 meet this condition, i.e. 0.07%.
> Okay, I can see why you need to not mix tag-hiding with the removal of 
> duplicates.  However, I think you can maintain the current structure by 
> delaying the actual removal of declarations until after the main loop; have 
> the loop build up a set of indices to remove instead.  (Also, you can keep 
> this set as a bitset instead of a `std::set`.)
> 
> It's a shame that the hiding algorithm has to check every other declaration 
> in the lookup in case they're from different scopes.  I guess to avoid that 
> we'd have to do the filtering immediately when we collect the declarations 
> from a particular DC.
I think that delaying the removal until after the main loop would just 
complicate things, as then in the main loop we would have to check each index 
to see if it's something we're going to later remove. I can adjust it to do the 
erasing more like it's done in the main loop though, i.e. move the erased 
element to the end and decrement N, so the call to Decls.truncate will remove 
it. We can't use bitset though, as that takes the size of the bitset (which in 
this case would be the number of decls) as a template parameter.


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

https://reviews.llvm.org/D154503

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


[PATCH] D154503: [Sema] Fix handling of functions that hide classes

2023-07-11 Thread John Brawn via Phabricator via cfe-commits
john.brawn added inline comments.



Comment at: clang/lib/Sema/SemaLookup.cpp:507
 
+  // C++ [basic.scope.hiding]p2:
+  //   A class name or enumeration name can be hidden by the name of

shafik wrote:
> This section does not exist anymore, it was replaced in 
> [p1787](https://wg21.link/p1787) which resolved a very large number of DRs 
> and reflector discussions. I have not fully digested the paper myself but 
> this change should reflect the new wording as it exists in the current draft. 
It looks like https://eel.is/c++draft/basic.lookup#general-4 is the same thing 
but worded differently. That draft hasn't gone into a published standard 
though, and could change before it gets published, and the same section is 
referenced elsewhere in this file (and there are probably other references in 
this file to parts of the standard that will get changed in the next version), 
so I think it would make more sense to change all such comments at once when 
that change has gone into a published version of the standard.



Comment at: clang/test/SemaCXX/using-hiding.cpp:20
+
+// Using declaration causes A::X to be hidden, so X is not ambiguous.
+namespace Test2 {

shafik wrote:
> I think [namespace.udecl p10](https://eel.is/c++draft/namespace.udecl#10) 
> disagrees, specifically:
> 
> ```
>  using A::g;   // error: conflicts with B​::​g
> ```
> 
> but I may be misreading CC @Endill who has been looking at p1787r6 in details 
> where a lot of this wording changed.
I think that would mean that the using-declaration is ill-formed (i.e. we would 
give an error before we even arrived at looking up the name X). I'll try to 
adjust these tests so that they won't fail due to this when clang implements 
this behaviour.


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

https://reviews.llvm.org/D154503

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


[PATCH] D154503: [Sema] Fix handling of functions that hide classes

2023-07-06 Thread John Brawn via Phabricator via cfe-commits
john.brawn updated this revision to Diff 537731.
john.brawn added a comment.

Same patch as previous, but with full context.


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

https://reviews.llvm.org/D154503

Files:
  clang/lib/Sema/SemaLookup.cpp
  clang/test/SemaCXX/using-hiding.cpp

Index: clang/test/SemaCXX/using-hiding.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/using-hiding.cpp
@@ -0,0 +1,110 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+namespace A {
+  class X { }; // expected-note{{candidate found by name lookup is 'A::X'}}
+}
+namespace B {
+  void X(int); // expected-note{{candidate found by name lookup is 'B::X'}}
+}
+
+// Using directive doesn't cause A::X to be hidden, so X is ambiguous.
+namespace Test1 {
+  using namespace A;
+  using namespace B;
+
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
+
+// Using declaration causes A::X to be hidden, so X is not ambiguous.
+namespace Test2 {
+  using A::X;
+  using B::X;
+
+  void f() {
+X(1);
+  }
+}
+
+// Behaviour here should be the same as including A and B directly.
+namespace Test3 {
+  namespace C {
+using A::X; // expected-note{{candidate found by name lookup is 'Test3::C::X'}}
+  }
+  namespace D {
+using B::X; // expected-note{{candidate found by name lookup is 'Test3::D::X'}}
+  }
+  using namespace C;
+  using namespace D;
+
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
+
+// using B::X inside C should hide using A::X in C but not D, so the result is ambiguous.
+namespace Test4 {
+  namespace C {
+using A::X;
+using B::X; // expected-note{{candidate found by name lookup is 'Test4::C::X'}}
+  }
+  namespace D {
+using A::X; // expected-note{{candidate found by name lookup is 'Test4::D::X'}}
+  }
+  using namespace C;
+  using namespace D;
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
+
+// A::X hidden in both C and D, so the result is not ambiguous.
+namespace Test5 {
+  namespace C {
+using A::X;
+using B::X;
+  }
+  namespace D {
+using A::X;
+using B::X;
+  }
+  using namespace C;
+  using namespace D;
+  void f() {
+X(1);
+  }
+}
+
+// D declares a different class X, but it's hidden so the result is not ambiguous.
+namespace Test6 {
+  namespace C {
+using A::X;
+using B::X;
+  }
+  namespace D {
+class X { };
+using B::X;
+  }
+  using namespace C;
+  using namespace D;
+  void f() {
+X(1);
+  }
+}
+
+// X inside C should hide X in C but not D.
+namespace Test7 {
+  namespace C {
+class X;
+void X(int); // expected-note{{candidate found by name lookup is 'Test7::C::X'}}
+  }
+  namespace D {
+class X; // expected-note{{candidate found by name lookup is 'Test7::D::X'}}
+  }
+  using namespace C;
+  using namespace D;
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
Index: clang/lib/Sema/SemaLookup.cpp
===
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -504,6 +504,45 @@
   // Don't do any extra resolution if we've already resolved as ambiguous.
   if (ResultKind == Ambiguous) return;
 
+  // C++ [basic.scope.hiding]p2:
+  //   A class name or enumeration name can be hidden by the name of
+  //   an object, function, or enumerator declared in the same
+  //   scope. If a class or enumeration name and an object, function,
+  //   or enumerator are declared in the same scope (in any order)
+  //   with the same name, the class or enumeration name is hidden
+  //   wherever the object, function, or enumerator name is visible.
+  if (HideTags) {
+// First collect all decls that can hide others and those that can be hidden
+std::set CanHideOther, CanBeHidden;
+for (unsigned I = 0; I < N; ++I) {
+  const NamedDecl *D = Decls[I]->getUnderlyingDecl();
+  D = cast(D->getCanonicalDecl());
+  if (isa(D))
+CanBeHidden.insert(I);
+  else if (canHideTag(D))
+CanHideOther.insert(I);
+}
+
+if (!CanBeHidden.empty() && !CanHideOther.empty()) {
+  // Collect those decls that will be hidden
+  std::set> HiddenDecls;
+  for (unsigned HiddenI : CanBeHidden) {
+for (unsigned HiderI : CanHideOther) {
+  if (getContextForScopeMatching(Decls[HiderI])
+  ->Equals(getContextForScopeMatching(Decls[HiddenI]))) {
+HiddenDecls.insert(HiddenI);
+break;
+  }
+}
+  }
+
+  // Now erase those decls that were hidden
+  for (auto I : HiddenDecls)
+Decls.erase(I);
+  N = Decls.size();
+}
+  }
+
   llvm::SmallDenseMap Unique;
   llvm::SmallDenseMap UniqueTypes;
 
@@ -514,8 +553,6 @@
 
   llvm::SmallVector EquivalentNonFunctions;
 
-  unsigned UniqueTagIndex = 0;
-
   unsigned I = 0;
   while (I < N) {
 const NamedDecl 

[PATCH] D154503: [Sema] Fix handling of functions that hide classes

2023-07-06 Thread John Brawn via Phabricator via cfe-commits
john.brawn added inline comments.



Comment at: clang/lib/Sema/SemaLookup.cpp:542
+N = Decls.size();
+  }
+

rjmccall wrote:
> This is going to fire on every single ordinary lookup that finds multiple 
> declarations, right?  I haven't fully internalized the issue you're solving 
> here, but this is a very performance-sensitive path in the compiler; there's 
> a reason this code is written to very carefully only do extra work when we've 
> detected in the loop below that we're in a hidden-declarations situation.  Is 
> there any way we can restore that basic structure?
Test4 in the added tests is an example of why we can't wait until after the 
main loop. The `using A::X` in namespace D is eliminated by the UniqueResult 
check, so the check for a declaration being hidden can only see the using 
declarations in namespace C. We also can't do it in the loop itself, as then we 
can't handle Test5: at the time we process the `using A::X` in namespace D it 
looks like it may cause ambiguity, but it's later hidden by the `using B::X` in 
the same namespace which we haven't yet processed.

I have adjusted it though so the nested loop and erasing of decls only happens 
when we both have things that hide and things that can be hidden. Doing some 
quick testing of compiling SemaOpenMP.cpp (the largest file in clang), 
LookupResult::resolveKind is called 75318 times, of which 75283 calls have 
HideTags=true, of which 56 meet this condition, i.e. 0.07%.


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

https://reviews.llvm.org/D154503

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


[PATCH] D154503: [Sema] Fix handling of functions that hide classes

2023-07-06 Thread John Brawn via Phabricator via cfe-commits
john.brawn updated this revision to Diff 537721.
john.brawn added a comment.

Avoid doing work when we don't have both decls that can hide and decls that can 
be hidden.


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

https://reviews.llvm.org/D154503

Files:
  clang/lib/Sema/SemaLookup.cpp
  clang/test/SemaCXX/using-hiding.cpp

Index: clang/test/SemaCXX/using-hiding.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/using-hiding.cpp
@@ -0,0 +1,110 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+namespace A {
+  class X { }; // expected-note{{candidate found by name lookup is 'A::X'}}
+}
+namespace B {
+  void X(int); // expected-note{{candidate found by name lookup is 'B::X'}}
+}
+
+// Using directive doesn't cause A::X to be hidden, so X is ambiguous.
+namespace Test1 {
+  using namespace A;
+  using namespace B;
+
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
+
+// Using declaration causes A::X to be hidden, so X is not ambiguous.
+namespace Test2 {
+  using A::X;
+  using B::X;
+
+  void f() {
+X(1);
+  }
+}
+
+// Behaviour here should be the same as including A and B directly.
+namespace Test3 {
+  namespace C {
+using A::X; // expected-note{{candidate found by name lookup is 'Test3::C::X'}}
+  }
+  namespace D {
+using B::X; // expected-note{{candidate found by name lookup is 'Test3::D::X'}}
+  }
+  using namespace C;
+  using namespace D;
+
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
+
+// using B::X inside C should hide using A::X in C but not D, so the result is ambiguous.
+namespace Test4 {
+  namespace C {
+using A::X;
+using B::X; // expected-note{{candidate found by name lookup is 'Test4::C::X'}}
+  }
+  namespace D {
+using A::X; // expected-note{{candidate found by name lookup is 'Test4::D::X'}}
+  }
+  using namespace C;
+  using namespace D;
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
+
+// A::X hidden in both C and D, so the result is not ambiguous.
+namespace Test5 {
+  namespace C {
+using A::X;
+using B::X;
+  }
+  namespace D {
+using A::X;
+using B::X;
+  }
+  using namespace C;
+  using namespace D;
+  void f() {
+X(1);
+  }
+}
+
+// D declares a different class X, but it's hidden so the result is not ambiguous.
+namespace Test6 {
+  namespace C {
+using A::X;
+using B::X;
+  }
+  namespace D {
+class X { };
+using B::X;
+  }
+  using namespace C;
+  using namespace D;
+  void f() {
+X(1);
+  }
+}
+
+// X inside C should hide X in C but not D.
+namespace Test7 {
+  namespace C {
+class X;
+void X(int); // expected-note{{candidate found by name lookup is 'Test7::C::X'}}
+  }
+  namespace D {
+class X; // expected-note{{candidate found by name lookup is 'Test7::D::X'}}
+  }
+  using namespace C;
+  using namespace D;
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
Index: clang/lib/Sema/SemaLookup.cpp
===
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -504,6 +504,45 @@
   // Don't do any extra resolution if we've already resolved as ambiguous.
   if (ResultKind == Ambiguous) return;
 
+  // C++ [basic.scope.hiding]p2:
+  //   A class name or enumeration name can be hidden by the name of
+  //   an object, function, or enumerator declared in the same
+  //   scope. If a class or enumeration name and an object, function,
+  //   or enumerator are declared in the same scope (in any order)
+  //   with the same name, the class or enumeration name is hidden
+  //   wherever the object, function, or enumerator name is visible.
+  if (HideTags) {
+// First collect all decls that can hide others and those that can be hidden
+std::set CanHideOther, CanBeHidden;
+for (unsigned I = 0; I < N; ++I) {
+  const NamedDecl *D = Decls[I]->getUnderlyingDecl();
+  D = cast(D->getCanonicalDecl());
+  if (isa(D))
+CanBeHidden.insert(I);
+  else if (canHideTag(D))
+CanHideOther.insert(I);
+}
+
+if (!CanBeHidden.empty() && !CanHideOther.empty()) {
+  // Collect those decls that will be hidden
+  std::set> HiddenDecls;
+  for (unsigned HiddenI : CanBeHidden) {
+for (unsigned HiderI : CanHideOther) {
+  if (getContextForScopeMatching(Decls[HiderI])
+  ->Equals(getContextForScopeMatching(Decls[HiddenI]))) {
+HiddenDecls.insert(HiddenI);
+break;
+  }
+}
+  }
+
+  // Now erase those decls that were hidden
+  for (auto I : HiddenDecls)
+Decls.erase(I);
+  N = Decls.size();
+}
+  }
+
   llvm::SmallDenseMap Unique;
   llvm::SmallDenseMap UniqueTypes;
 
@@ -514,8 +553,6 @@
 
   llvm::SmallVector EquivalentNonFunctions;
 
-  unsigned UniqueTagIndex = 0;
-
   unsigned I 

[PATCH] D154502: [AST] Fix bug in UnresolvedSet::erase of last element

2023-07-06 Thread John Brawn via Phabricator via cfe-commits
john.brawn added inline comments.



Comment at: clang/unittests/AST/UnresolvedSetTest.cpp:11
+};
+} // namespace clang
+

jroelofs wrote:
> jroelofs wrote:
> > This ODR violation broke the build for me because it's picking up the 
> > definition from Decl.h instead of this one.
> > 
> > ```
> > /Users/jonathan_roelofs/llvm-upstream/clang/unittests/AST/UnresolvedSetTest.cpp:30:1:
> >  error: call to implicitly-deleted default constructor of 
> > 'UnresolvedSetTest'
> > TEST_F(UnresolvedSetTest, Size) { EXPECT_EQ(set.size(), 4u); }
> > ^
> > /Users/jonathan_roelofs/llvm-upstream/third-party/unittest/googletest/include/gtest/gtest.h:2368:3:
> >  note: expanded from macro 'TEST_F'
> >   GTEST_TEST_(test_fixture, test_name, test_fixture, \
> >   ^
> > /Users/jonathan_roelofs/llvm-upstream/third-party/unittest/googletest/include/gtest/internal/gtest-internal.h:1362:5:
> >  note: expanded from macro 'GTEST_TEST_'
> > GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() {} 
> >   \
> > ^
> > /Users/jonathan_roelofs/llvm-upstream/third-party/unittest/googletest/include/gtest/internal/gtest-internal.h:1351:3:
> >  note: expanded from macro 'GTEST_TEST_CLASS_NAME_'
> >   test_suite_name##_##test_name##_Test
> >   ^
> > :30:1: note: expanded from here
> > UnresolvedSetTest_Size_Test
> > ^
> > /Users/jonathan_roelofs/llvm-upstream/clang/unittests/AST/UnresolvedSetTest.cpp:19:13:
> >  note: default constructor of 'UnresolvedSetTest' is implicitly deleted 
> > because field 'n0' has no default constructor
> >   NamedDecl n0, n1, n2, n3;
> > ^
> > ```
> > 
> > Maybe it needs to be something like this instead?
> > 
> > ```
> > diff --git a/clang/unittests/AST/UnresolvedSetTest.cpp 
> > b/clang/unittests/AST/UnresolvedSetTest.cpp
> > index ada857e0e382..3c9077ddc3ec 100644
> > --- a/clang/unittests/AST/UnresolvedSetTest.cpp
> > +++ b/clang/unittests/AST/UnresolvedSetTest.cpp
> > @@ -1,22 +1,23 @@
> >  #include "clang/AST/UnresolvedSet.h"
> > +#include "clang/AST/Decl.h"
> >  #include "gtest/gtest.h"
> >  
> > -namespace clang {
> > -class NamedDecl {
> > +namespace dummy {
> > +class NamedDecl : public clang::NamedDecl {
> >// DeclAccessPair assumes that NamedDecl is at least 4-byte aligned, so 
> > we
> >// we need to have a dummy value to make this dummy NamedDecl also be 
> > aligned.
> >[[maybe_unused]] int dummy;
> >  
> >  public:
> > -  NamedDecl() {}
> > +  NamedDecl() : clang::NamedDecl(clang::NamedDecl::Kind(0), nullptr, 
> > clang::SourceLocation::getFromRawEncoding(0), clang::DeclarationName()) {}
> >  };
> > -} // namespace clang
> > +} // namespace dummy
> >  
> >  using namespace clang;
> >  
> >  class UnresolvedSetTest : public ::testing::Test {
> >  protected:
> > -  NamedDecl n0, n1, n2, n3;
> > +  dummy::NamedDecl n0, n1, n2, n3;
> >UnresolvedSet<2> set;
> >  
> >void SetUp() override {
> > 
> > ```
> You might need to build with `-DLLVM_ENABLE_MODULES=On` to see this.
https://reviews.llvm.org/rG626c789d92bc should fix this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154502

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


[PATCH] D154502: [AST] Fix bug in UnresolvedSet::erase of last element

2023-07-05 Thread John Brawn via Phabricator via cfe-commits
john.brawn added a comment.

Unfortunately my fix then broke builds using MSVC. Hopefully fixed for real in 
https://reviews.llvm.org/rG25784cd6a962.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154502

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


[PATCH] D154502: [AST] Fix bug in UnresolvedSet::erase of last element

2023-07-05 Thread John Brawn via Phabricator via cfe-commits
john.brawn added a comment.

The test I added here caused failures in buildbots that build with -Wall 
-Werror, fixed in https://reviews.llvm.org/rG258322105892.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154502

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


[PATCH] D154502: [AST] Fix bug in UnresolvedSet::erase of last element

2023-07-05 Thread John Brawn via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4ade8b7ed997: [AST] Fix bug in UnresolvedSet::erase of last 
element (authored by john.brawn).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154502

Files:
  clang/include/clang/AST/UnresolvedSet.h
  clang/unittests/AST/CMakeLists.txt
  clang/unittests/AST/UnresolvedSetTest.cpp

Index: clang/unittests/AST/UnresolvedSetTest.cpp
===
--- /dev/null
+++ clang/unittests/AST/UnresolvedSetTest.cpp
@@ -0,0 +1,115 @@
+#include "clang/AST/UnresolvedSet.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+class NamedDecl {
+  int dummy;
+
+public:
+  NamedDecl() {}
+};
+} // namespace clang
+
+using namespace clang;
+
+class UnresolvedSetTest : public ::testing::Test {
+protected:
+  NamedDecl n0, n1, n2, n3;
+  UnresolvedSet<2> set;
+
+  void SetUp() override {
+set.addDecl();
+set.addDecl();
+set.addDecl();
+set.addDecl();
+  }
+};
+
+TEST_F(UnresolvedSetTest, Size) { EXPECT_EQ(set.size(), 4u); }
+
+TEST_F(UnresolvedSetTest, ArrayOperator) {
+  EXPECT_EQ(set[0].getDecl(), );
+  EXPECT_EQ(set[1].getDecl(), );
+  EXPECT_EQ(set[2].getDecl(), );
+  EXPECT_EQ(set[3].getDecl(), );
+}
+
+TEST_F(UnresolvedSetTest, EraseIntegerFromStart) {
+  set.erase(0);
+  EXPECT_EQ(set.size(), 3u);
+  EXPECT_EQ(set[0].getDecl(), );
+  EXPECT_EQ(set[1].getDecl(), );
+  EXPECT_EQ(set[2].getDecl(), );
+
+  set.erase(0);
+  EXPECT_EQ(set.size(), 2u);
+  EXPECT_EQ(set[0].getDecl(), );
+  EXPECT_EQ(set[1].getDecl(), );
+
+  set.erase(0);
+  EXPECT_EQ(set.size(), 1u);
+  EXPECT_EQ(set[0].getDecl(), );
+
+  set.erase(0);
+  EXPECT_EQ(set.size(), 0u);
+}
+
+TEST_F(UnresolvedSetTest, EraseIntegerFromEnd) {
+  set.erase(3);
+  EXPECT_EQ(set.size(), 3u);
+  EXPECT_EQ(set[0].getDecl(), );
+  EXPECT_EQ(set[1].getDecl(), );
+  EXPECT_EQ(set[2].getDecl(), );
+
+  set.erase(2);
+  EXPECT_EQ(set.size(), 2u);
+  EXPECT_EQ(set[0].getDecl(), );
+  EXPECT_EQ(set[1].getDecl(), );
+
+  set.erase(1);
+  EXPECT_EQ(set.size(), 1u);
+  EXPECT_EQ(set[0].getDecl(), );
+
+  set.erase(0);
+  EXPECT_EQ(set.size(), 0u);
+}
+
+TEST_F(UnresolvedSetTest, EraseIteratorFromStart) {
+  set.erase(set.begin());
+  EXPECT_EQ(set.size(), 3u);
+  EXPECT_EQ(set[0].getDecl(), );
+  EXPECT_EQ(set[1].getDecl(), );
+  EXPECT_EQ(set[2].getDecl(), );
+
+  set.erase(set.begin());
+  EXPECT_EQ(set.size(), 2u);
+  EXPECT_EQ(set[0].getDecl(), );
+  EXPECT_EQ(set[1].getDecl(), );
+
+  set.erase(set.begin());
+  EXPECT_EQ(set.size(), 1u);
+  EXPECT_EQ(set[0].getDecl(), );
+
+  set.erase(set.begin());
+  EXPECT_EQ(set.size(), 0u);
+}
+
+TEST_F(UnresolvedSetTest, EraseIteratorFromEnd) {
+  set.erase(--set.end());
+  EXPECT_EQ(set.size(), 3u);
+  EXPECT_EQ(set[0].getDecl(), );
+  EXPECT_EQ(set[1].getDecl(), );
+  EXPECT_EQ(set[2].getDecl(), );
+
+  set.erase(--set.end());
+  EXPECT_EQ(set.size(), 2u);
+  EXPECT_EQ(set[0].getDecl(), );
+  EXPECT_EQ(set[1].getDecl(), );
+
+  set.erase(--set.end());
+  EXPECT_EQ(set.size(), 1u);
+  EXPECT_EQ(set[0].getDecl(), );
+
+  set.erase(--set.end());
+  EXPECT_EQ(set.size(), 0u);
+}
Index: clang/unittests/AST/CMakeLists.txt
===
--- clang/unittests/AST/CMakeLists.txt
+++ clang/unittests/AST/CMakeLists.txt
@@ -35,6 +35,7 @@
   StructuralEquivalenceTest.cpp
   TemplateNameTest.cpp
   TypePrinterTest.cpp
+  UnresolvedSetTest.cpp
   )
 
 clang_target_link_libraries(ASTTests
Index: clang/include/clang/AST/UnresolvedSet.h
===
--- clang/include/clang/AST/UnresolvedSet.h
+++ clang/include/clang/AST/UnresolvedSet.h
@@ -114,9 +114,17 @@
 I.I->set(New, AS);
   }
 
-  void erase(unsigned I) { decls()[I] = decls().pop_back_val(); }
+  void erase(unsigned I) {
+auto val = decls().pop_back_val();
+if (I < size())
+  decls()[I] = val;
+  }
 
-  void erase(iterator I) { *I.I = decls().pop_back_val(); }
+  void erase(iterator I) {
+auto val = decls().pop_back_val();
+if (I != end())
+  *I.I = val;
+  }
 
   void setAccess(iterator I, AccessSpecifier AS) { I.I->setAccess(AS); }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154503: [Sema] Fix handling of functions that hide classes

2023-07-05 Thread John Brawn via Phabricator via cfe-commits
john.brawn created this revision.
john.brawn added reviewers: dexonsmith, rsmith, rjmccall.
Herald added a project: All.
john.brawn requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When a function is declared in the same scope as a class with the same name 
then the function hides that class. Currently this is done by a single check 
after the main loop in LookupResult::resolveKind, but this can give the wrong 
result when we have a using declaration in multiple namespace scopes in two 
different ways:

- When the using declaration is hidden in one namespace but not the other we 
can end up considering only the hidden one when deciding if the result is 
ambiguous, causing an incorrect "not ambiguous" result.
- When two classes with the same name in different namespace scopes are both 
hidden by using declarations this can result in incorrectly deciding the result 
is ambiguous. There's currently a comment saying this is expected, but I don't 
think that's correct.

Solve this by having a separate loop before the main loop to eliminate classes 
that have been hidden by functions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154503

Files:
  clang/lib/Sema/SemaLookup.cpp
  clang/test/SemaCXX/using-hiding.cpp

Index: clang/test/SemaCXX/using-hiding.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/using-hiding.cpp
@@ -0,0 +1,110 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+namespace A {
+  class X { }; // expected-note{{candidate found by name lookup is 'A::X'}}
+}
+namespace B {
+  void X(int); // expected-note{{candidate found by name lookup is 'B::X'}}
+}
+
+// Using directive doesn't cause A::X to be hidden, so X is ambiguous.
+namespace Test1 {
+  using namespace A;
+  using namespace B;
+
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
+
+// Using declaration causes A::X to be hidden, so X is not ambiguous.
+namespace Test2 {
+  using A::X;
+  using B::X;
+
+  void f() {
+X(1);
+  }
+}
+
+// Behaviour here should be the same as including A and B directly.
+namespace Test3 {
+  namespace C {
+using A::X; // expected-note{{candidate found by name lookup is 'Test3::C::X'}}
+  }
+  namespace D {
+using B::X; // expected-note{{candidate found by name lookup is 'Test3::D::X'}}
+  }
+  using namespace C;
+  using namespace D;
+
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
+
+// using B::X inside C should hide using A::X in C but not D, so the result is ambiguous.
+namespace Test4 {
+  namespace C {
+using A::X;
+using B::X; // expected-note{{candidate found by name lookup is 'Test4::C::X'}}
+  }
+  namespace D {
+using A::X; // expected-note{{candidate found by name lookup is 'Test4::D::X'}}
+  }
+  using namespace C;
+  using namespace D;
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
+
+// A::X hidden in both C and D, so the result is not ambiguous.
+namespace Test5 {
+  namespace C {
+using A::X;
+using B::X;
+  }
+  namespace D {
+using A::X;
+using B::X;
+  }
+  using namespace C;
+  using namespace D;
+  void f() {
+X(1);
+  }
+}
+
+// D declares a different class X, but it's hidden so the result is not ambiguous.
+namespace Test6 {
+  namespace C {
+using A::X;
+using B::X;
+  }
+  namespace D {
+class X { };
+using B::X;
+  }
+  using namespace C;
+  using namespace D;
+  void f() {
+X(1);
+  }
+}
+
+// X inside C should hide X in C but not D.
+namespace Test7 {
+  namespace C {
+class X;
+void X(int); // expected-note{{candidate found by name lookup is 'Test7::C::X'}}
+  }
+  namespace D {
+class X; // expected-note{{candidate found by name lookup is 'Test7::D::X'}}
+  }
+  using namespace C;
+  using namespace D;
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
Index: clang/lib/Sema/SemaLookup.cpp
===
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -504,6 +504,43 @@
   // Don't do any extra resolution if we've already resolved as ambiguous.
   if (ResultKind == Ambiguous) return;
 
+  // C++ [basic.scope.hiding]p2:
+  //   A class name or enumeration name can be hidden by the name of
+  //   an object, function, or enumerator declared in the same
+  //   scope. If a class or enumeration name and an object, function,
+  //   or enumerator are declared in the same scope (in any order)
+  //   with the same name, the class or enumeration name is hidden
+  //   wherever the object, function, or enumerator name is visible.
+  if (HideTags) {
+// First collect all decls that can hide others and those that can be hidden
+std::set CanHideOther, CanBeHidden;
+for (unsigned I = 0; I < N; ++I) {
+  const NamedDecl *D = 

[PATCH] D154502: [AST] Fix bug in UnresolvedSet::erase of last element

2023-07-05 Thread John Brawn via Phabricator via cfe-commits
john.brawn created this revision.
john.brawn added reviewers: dexonsmith, rsmith, rjmccall.
Herald added a project: All.
john.brawn requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

UnresolvedSet::erase works by popping the last element then replacing the 
element to be erased with that element. When the element to be erased is itself 
the last element this leads to writing past the end of the set, causing an 
assertion failure.

Fix this by making erase of the last element just pop that element.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154502

Files:
  clang/include/clang/AST/UnresolvedSet.h
  clang/unittests/AST/CMakeLists.txt
  clang/unittests/AST/UnresolvedSetTest.cpp

Index: clang/unittests/AST/UnresolvedSetTest.cpp
===
--- /dev/null
+++ clang/unittests/AST/UnresolvedSetTest.cpp
@@ -0,0 +1,115 @@
+#include "clang/AST/UnresolvedSet.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+class NamedDecl {
+  int dummy;
+
+public:
+  NamedDecl() {}
+};
+} // namespace clang
+
+using namespace clang;
+
+class UnresolvedSetTest : public ::testing::Test {
+protected:
+  NamedDecl n0, n1, n2, n3;
+  UnresolvedSet<2> set;
+
+  void SetUp() override {
+set.addDecl();
+set.addDecl();
+set.addDecl();
+set.addDecl();
+  }
+};
+
+TEST_F(UnresolvedSetTest, Size) { EXPECT_EQ(set.size(), 4u); }
+
+TEST_F(UnresolvedSetTest, ArrayOperator) {
+  EXPECT_EQ(set[0].getDecl(), );
+  EXPECT_EQ(set[1].getDecl(), );
+  EXPECT_EQ(set[2].getDecl(), );
+  EXPECT_EQ(set[3].getDecl(), );
+}
+
+TEST_F(UnresolvedSetTest, EraseIntegerFromStart) {
+  set.erase(0);
+  EXPECT_EQ(set.size(), 3u);
+  EXPECT_EQ(set[0].getDecl(), );
+  EXPECT_EQ(set[1].getDecl(), );
+  EXPECT_EQ(set[2].getDecl(), );
+
+  set.erase(0);
+  EXPECT_EQ(set.size(), 2u);
+  EXPECT_EQ(set[0].getDecl(), );
+  EXPECT_EQ(set[1].getDecl(), );
+
+  set.erase(0);
+  EXPECT_EQ(set.size(), 1u);
+  EXPECT_EQ(set[0].getDecl(), );
+
+  set.erase(0);
+  EXPECT_EQ(set.size(), 0u);
+}
+
+TEST_F(UnresolvedSetTest, EraseIntegerFromEnd) {
+  set.erase(3);
+  EXPECT_EQ(set.size(), 3u);
+  EXPECT_EQ(set[0].getDecl(), );
+  EXPECT_EQ(set[1].getDecl(), );
+  EXPECT_EQ(set[2].getDecl(), );
+
+  set.erase(2);
+  EXPECT_EQ(set.size(), 2u);
+  EXPECT_EQ(set[0].getDecl(), );
+  EXPECT_EQ(set[1].getDecl(), );
+
+  set.erase(1);
+  EXPECT_EQ(set.size(), 1u);
+  EXPECT_EQ(set[0].getDecl(), );
+
+  set.erase(0);
+  EXPECT_EQ(set.size(), 0u);
+}
+
+TEST_F(UnresolvedSetTest, EraseIteratorFromStart) {
+  set.erase(set.begin());
+  EXPECT_EQ(set.size(), 3u);
+  EXPECT_EQ(set[0].getDecl(), );
+  EXPECT_EQ(set[1].getDecl(), );
+  EXPECT_EQ(set[2].getDecl(), );
+
+  set.erase(set.begin());
+  EXPECT_EQ(set.size(), 2u);
+  EXPECT_EQ(set[0].getDecl(), );
+  EXPECT_EQ(set[1].getDecl(), );
+
+  set.erase(set.begin());
+  EXPECT_EQ(set.size(), 1u);
+  EXPECT_EQ(set[0].getDecl(), );
+
+  set.erase(set.begin());
+  EXPECT_EQ(set.size(), 0u);
+}
+
+TEST_F(UnresolvedSetTest, EraseIteratorFromEnd) {
+  set.erase(--set.end());
+  EXPECT_EQ(set.size(), 3u);
+  EXPECT_EQ(set[0].getDecl(), );
+  EXPECT_EQ(set[1].getDecl(), );
+  EXPECT_EQ(set[2].getDecl(), );
+
+  set.erase(--set.end());
+  EXPECT_EQ(set.size(), 2u);
+  EXPECT_EQ(set[0].getDecl(), );
+  EXPECT_EQ(set[1].getDecl(), );
+
+  set.erase(--set.end());
+  EXPECT_EQ(set.size(), 1u);
+  EXPECT_EQ(set[0].getDecl(), );
+
+  set.erase(--set.end());
+  EXPECT_EQ(set.size(), 0u);
+}
Index: clang/unittests/AST/CMakeLists.txt
===
--- clang/unittests/AST/CMakeLists.txt
+++ clang/unittests/AST/CMakeLists.txt
@@ -35,6 +35,7 @@
   StructuralEquivalenceTest.cpp
   TemplateNameTest.cpp
   TypePrinterTest.cpp
+  UnresolvedSetTest.cpp
   )
 
 clang_target_link_libraries(ASTTests
Index: clang/include/clang/AST/UnresolvedSet.h
===
--- clang/include/clang/AST/UnresolvedSet.h
+++ clang/include/clang/AST/UnresolvedSet.h
@@ -114,9 +114,17 @@
 I.I->set(New, AS);
   }
 
-  void erase(unsigned I) { decls()[I] = decls().pop_back_val(); }
+  void erase(unsigned I) {
+auto val = decls().pop_back_val();
+if (I < size())
+  decls()[I] = val;
+  }
 
-  void erase(iterator I) { *I.I = decls().pop_back_val(); }
+  void erase(iterator I) {
+auto val = decls().pop_back_val();
+if (I != end())
+  *I.I = val;
+  }
 
   void setAccess(iterator I, AccessSpecifier AS) { I.I->setAccess(AS); }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149443: [ARM] add Thumb-1 8-bit movs/adds relocations to LLVM

2023-06-16 Thread John Brawn via Phabricator via cfe-commits
john.brawn accepted this revision.
john.brawn added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149443

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


[PATCH] D151741: [Lex] Only warn on defining or undefining language-defined builtins

2023-06-01 Thread John Brawn via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG844e9534c6d9: [Lex] Only warn on defining or undefining 
language-defined builtins (authored by john.brawn).

Changed prior to commit:
  https://reviews.llvm.org/D151741?vs=527432=527461#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151741

Files:
  clang/lib/Lex/PPDirectives.cpp
  clang/test/Preprocessor/macro-reserved.c
  clang/test/Preprocessor/undef-x86.c

Index: clang/test/Preprocessor/undef-x86.c
===
--- /dev/null
+++ clang/test/Preprocessor/undef-x86.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple=i386-none-none -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple=x86_64-none-none -fsyntax-only -verify %s
+
+// Check that we can undefine triple-specific defines without warning
+// expected-no-diagnostics
+#undef __i386
+#undef __i386__
+#undef i386
+#undef __amd64
+#undef __amd64__
+#undef __x86_64
+#undef __x86_64__
Index: clang/test/Preprocessor/macro-reserved.c
===
--- clang/test/Preprocessor/macro-reserved.c
+++ clang/test/Preprocessor/macro-reserved.c
@@ -7,6 +7,7 @@
 #define _HAVE_X 0
 #define X__Y
 #define __STDC__ 1 // expected-warning {{redefining builtin macro}}
+#define __clang__ 1
 
 #undef for
 #undef final
@@ -15,6 +16,12 @@
 #undef _HAVE_X
 #undef X__Y
 #undef __STDC_HOSTED__ // expected-warning {{undefining builtin macro}}
+#undef __INT32_TYPE__
+#undef __UINT32_TYPE__
+#undef __UINTPTR_TYPE__
+#undef __UINT64_TYPE__
+#undef __INT64_TYPE__
+#undef __OPTIMIZE__
 
 // allowlisted definitions
 #define while while
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -150,6 +150,30 @@
 MacroName);
 }
 
+static bool isLanguageDefinedBuiltin(const SourceManager ,
+ const MacroInfo *MI,
+ const StringRef MacroName) {
+  // If this is a macro with special handling (like __LINE__) then it's language
+  // defined.
+  if (MI->isBuiltinMacro())
+return true;
+  // Builtin macros are defined in the builtin file
+  if (!SourceMgr.isWrittenInBuiltinFile(MI->getDefinitionLoc()))
+return false;
+  // C defines macros starting with __STDC, and C++ defines macros starting with
+  // __STDCPP
+  if (MacroName.startswith("__STDC"))
+return true;
+  // C++ defines the __cplusplus macro
+  if (MacroName == "__cplusplus")
+return true;
+  // C++ defines various feature-test macros starting with __cpp
+  if (MacroName.startswith("__cpp"))
+return true;
+  // Anything else isn't language-defined
+  return false;
+}
+
 static MacroDiag shouldWarnOnMacroDef(Preprocessor , IdentifierInfo *II) {
   const LangOptions  = PP.getLangOpts();
   StringRef Text = II->getName();
@@ -3107,9 +3131,7 @@
 
   // Warn if defining "__LINE__" and other builtins, per C99 6.10.8/4 and
   // C++ [cpp.predefined]p4, but allow it as an extension.
-  if (OtherMI->isBuiltinMacro() ||
-  (SourceMgr.isWrittenInBuiltinFile(OtherMI->getDefinitionLoc()) &&
-   !isFeatureTestMacro(MacroNameTok.getIdentifierInfo()->getName(
+  if (isLanguageDefinedBuiltin(SourceMgr, OtherMI, II->getName()))
 Diag(MacroNameTok, diag::ext_pp_redef_builtin_macro);
   // Macros must be identical.  This means all tokens and whitespace
   // separation must be the same.  C99 6.10.3p2.
@@ -3190,11 +3212,8 @@
   Diag(MI->getDefinitionLoc(), diag::pp_macro_not_used);
 
 // Warn if undefining "__LINE__" and other builtins, per C99 6.10.8/4 and
-// C++ [cpp.predefined]p4, but allow it as an extension. Don't warn if this
-// is an Objective-C builtin macro though.
-if ((MI->isBuiltinMacro() ||
- SourceMgr.isWrittenInBuiltinFile(MI->getDefinitionLoc())) &&
-!(getLangOpts().ObjC && isObjCProtectedMacro(II)))
+// C++ [cpp.predefined]p4, but allow it as an extension.
+if (isLanguageDefinedBuiltin(SourceMgr, MI, II->getName()))
   Diag(MacroNameTok, diag::ext_pp_undef_builtin_macro);
 
 if (MI->isWarnIfUnused())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151741: [Lex] Only warn on defining or undefining language-defined builtins

2023-06-01 Thread John Brawn via Phabricator via cfe-commits
john.brawn updated this revision to Diff 527432.
john.brawn added a comment.

Put x86 tests in undef-x86.c.


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

https://reviews.llvm.org/D151741

Files:
  clang/lib/Lex/PPDirectives.cpp
  clang/test/Preprocessor/macro-reserved.c
  clang/test/Preprocessor/undef-x86.c

Index: clang/test/Preprocessor/undef-x86.c
===
--- /dev/null
+++ clang/test/Preprocessor/undef-x86.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple=i386-none-none -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple=i686-none-none -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple=x86_64-none-none -fsyntax-only -verify %s
+
+// Check that we can undefine triple-specific defines without warning
+// expected-no-diagnostics
+#undef __i386
+#undef __i386__
+#undef i386
+#undef __amd64
+#undef __amd64__
+#undef __x86_64
+#undef __x86_64__
Index: clang/test/Preprocessor/macro-reserved.c
===
--- clang/test/Preprocessor/macro-reserved.c
+++ clang/test/Preprocessor/macro-reserved.c
@@ -7,6 +7,7 @@
 #define _HAVE_X 0
 #define X__Y
 #define __STDC__ 1 // expected-warning {{redefining builtin macro}}
+#define __clang__ 1
 
 #undef for
 #undef final
@@ -15,6 +16,12 @@
 #undef _HAVE_X
 #undef X__Y
 #undef __STDC_HOSTED__ // expected-warning {{undefining builtin macro}}
+#undef __INT32_TYPE__
+#undef __UINT32_TYPE__
+#undef __UINTPTR_TYPE__
+#undef __UINT64_TYPE__
+#undef __INT64_TYPE__
+#undef __OPTIMIZE__
 
 // allowlisted definitions
 #define while while
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -150,6 +150,30 @@
 MacroName);
 }
 
+static bool isLanguageDefinedBuiltin(const SourceManager ,
+ const MacroInfo *MI,
+ const StringRef MacroName) {
+  // If this is a macro with special handling (like __LINE__) then it's language
+  // defined.
+  if (MI->isBuiltinMacro())
+return true;
+  // Builtin macros are defined in the builtin file
+  if (!SourceMgr.isWrittenInBuiltinFile(MI->getDefinitionLoc()))
+return false;
+  // C defines macros starting with __STDC, and C++ defines macros starting with
+  // __STDCPP
+  if (MacroName.startswith("__STDC"))
+return true;
+  // C++ defines the __cplusplus macro
+  if (MacroName == "__cplusplus")
+return true;
+  // C++ defines various feature-test macros starting with __cpp
+  if (MacroName.startswith("__cpp"))
+return true;
+  // Anything else isn't language-defined
+  return false;
+}
+
 static MacroDiag shouldWarnOnMacroDef(Preprocessor , IdentifierInfo *II) {
   const LangOptions  = PP.getLangOpts();
   StringRef Text = II->getName();
@@ -3107,9 +3131,7 @@
 
   // Warn if defining "__LINE__" and other builtins, per C99 6.10.8/4 and
   // C++ [cpp.predefined]p4, but allow it as an extension.
-  if (OtherMI->isBuiltinMacro() ||
-  (SourceMgr.isWrittenInBuiltinFile(OtherMI->getDefinitionLoc()) &&
-   !isFeatureTestMacro(MacroNameTok.getIdentifierInfo()->getName(
+  if (isLanguageDefinedBuiltin(SourceMgr, OtherMI, II->getName()))
 Diag(MacroNameTok, diag::ext_pp_redef_builtin_macro);
   // Macros must be identical.  This means all tokens and whitespace
   // separation must be the same.  C99 6.10.3p2.
@@ -3190,11 +3212,8 @@
   Diag(MI->getDefinitionLoc(), diag::pp_macro_not_used);
 
 // Warn if undefining "__LINE__" and other builtins, per C99 6.10.8/4 and
-// C++ [cpp.predefined]p4, but allow it as an extension. Don't warn if this
-// is an Objective-C builtin macro though.
-if ((MI->isBuiltinMacro() ||
- SourceMgr.isWrittenInBuiltinFile(MI->getDefinitionLoc())) &&
-!(getLangOpts().ObjC && isObjCProtectedMacro(II)))
+// C++ [cpp.predefined]p4, but allow it as an extension.
+if (isLanguageDefinedBuiltin(SourceMgr, MI, II->getName()))
   Diag(MacroNameTok, diag::ext_pp_undef_builtin_macro);
 
 if (MI->isWarnIfUnused())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151741: [Lex] Only warn on defining or undefining language-defined builtins

2023-05-31 Thread John Brawn via Phabricator via cfe-commits
john.brawn updated this revision to Diff 527164.
john.brawn added a comment.

Move some of the testing to init-x86.c


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

https://reviews.llvm.org/D151741

Files:
  clang/lib/Lex/PPDirectives.cpp
  clang/test/Preprocessor/init-x86.c
  clang/test/Preprocessor/macro-reserved.c

Index: clang/test/Preprocessor/macro-reserved.c
===
--- clang/test/Preprocessor/macro-reserved.c
+++ clang/test/Preprocessor/macro-reserved.c
@@ -7,6 +7,7 @@
 #define _HAVE_X 0
 #define X__Y
 #define __STDC__ 1 // expected-warning {{redefining builtin macro}}
+#define __clang__ 1
 
 #undef for
 #undef final
@@ -15,6 +16,11 @@
 #undef _HAVE_X
 #undef X__Y
 #undef __STDC_HOSTED__ // expected-warning {{undefining builtin macro}}
+#undef __INT32_TYPE__
+#undef __UINT32_TYPE__
+#undef __UINTPTR_TYPE__
+#undef __UINT64_TYPE__
+#undef __INT64_TYPE__
 
 // allowlisted definitions
 #define while while
Index: clang/test/Preprocessor/init-x86.c
===
--- clang/test/Preprocessor/init-x86.c
+++ clang/test/Preprocessor/init-x86.c
@@ -1724,3 +1724,18 @@
 
 // RUN: %clang_cc1 -E -dM -triple=i386-unknown-openbsd -x c++ < /dev/null | FileCheck -match-full-lines -check-prefix I386-OPENBSD-CXX %s
 // I386-OPENBSD-CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL
+
+// RUN: %clang_cc1 -triple=i386-none-none -fsyntax-only -verify -DUNDEF %s
+// RUN: %clang_cc1 -triple=i686-none-none -fsyntax-only -verify -DUNDEF %s
+// RUN: %clang_cc1 -triple=x86_64-none-none -fsyntax-only -verify -DUNDEF %s
+#ifdef UNDEF
+// Check that we can undefine triple-specific defines without warning
+// expected-no-diagnostics
+#undef __i386
+#undef __i386__
+#undef i386
+#undef __amd64
+#undef __amd64__
+#undef __x86_64
+#undef __x86_64__
+#endif
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -150,6 +150,30 @@
 MacroName);
 }
 
+static bool isLanguageDefinedBuiltin(const SourceManager ,
+ const MacroInfo *MI,
+ const StringRef MacroName) {
+  // If this is a macro with special handling (like __LINE__) then it's language
+  // defined.
+  if (MI->isBuiltinMacro())
+return true;
+  // Builtin macros are defined in the builtin file
+  if (!SourceMgr.isWrittenInBuiltinFile(MI->getDefinitionLoc()))
+return false;
+  // C defines macros starting with __STDC, and C++ defines macros starting with
+  // __STDCPP
+  if (MacroName.startswith("__STDC"))
+return true;
+  // C++ defines the __cplusplus macro
+  if (MacroName == "__cplusplus")
+return true;
+  // C++ defines various feature-test macros starting with __cpp
+  if (MacroName.startswith("__cpp"))
+return true;
+  // Anything else isn't language-defined
+  return false;
+}
+
 static MacroDiag shouldWarnOnMacroDef(Preprocessor , IdentifierInfo *II) {
   const LangOptions  = PP.getLangOpts();
   StringRef Text = II->getName();
@@ -3107,9 +3131,7 @@
 
   // Warn if defining "__LINE__" and other builtins, per C99 6.10.8/4 and
   // C++ [cpp.predefined]p4, but allow it as an extension.
-  if (OtherMI->isBuiltinMacro() ||
-  (SourceMgr.isWrittenInBuiltinFile(OtherMI->getDefinitionLoc()) &&
-   !isFeatureTestMacro(MacroNameTok.getIdentifierInfo()->getName(
+  if (isLanguageDefinedBuiltin(SourceMgr, OtherMI, II->getName()))
 Diag(MacroNameTok, diag::ext_pp_redef_builtin_macro);
   // Macros must be identical.  This means all tokens and whitespace
   // separation must be the same.  C99 6.10.3p2.
@@ -3190,11 +3212,8 @@
   Diag(MI->getDefinitionLoc(), diag::pp_macro_not_used);
 
 // Warn if undefining "__LINE__" and other builtins, per C99 6.10.8/4 and
-// C++ [cpp.predefined]p4, but allow it as an extension. Don't warn if this
-// is an Objective-C builtin macro though.
-if ((MI->isBuiltinMacro() ||
- SourceMgr.isWrittenInBuiltinFile(MI->getDefinitionLoc())) &&
-!(getLangOpts().ObjC && isObjCProtectedMacro(II)))
+// C++ [cpp.predefined]p4, but allow it as an extension.
+if (isLanguageDefinedBuiltin(SourceMgr, MI, II->getName()))
   Diag(MacroNameTok, diag::ext_pp_undef_builtin_macro);
 
 if (MI->isWarnIfUnused())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151741: [Lex] Only warn on defining or undefining language-defined builtins

2023-05-31 Thread John Brawn via Phabricator via cfe-commits
john.brawn marked an inline comment as done.
john.brawn added inline comments.



Comment at: clang/lib/Lex/PPDirectives.cpp:163-172
+  // C defines macros starting with __STDC, and C++ defines macros starting 
with
+  // __STDCPP
+  if (MacroName.startswith("__STDC"))
+return true;
+  // C++ defines the __cplusplus macro
+  if (MacroName == "__cplusplus")
+return true;

nickdesaulniers wrote:
> Should these depend on LangOpt?
I don't think so. If we're e.g. not compiling C++ then __cplusplus won't be 
defined so it doesn't matter if we check for it.


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

https://reviews.llvm.org/D151741

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


[PATCH] D151741: [Lex] Only warn on defining or undefining language-defined builtins

2023-05-31 Thread John Brawn via Phabricator via cfe-commits
john.brawn updated this revision to Diff 527024.
john.brawn added a comment.

Add more testing.


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

https://reviews.llvm.org/D151741

Files:
  clang/lib/Lex/PPDirectives.cpp
  clang/test/Preprocessor/macro-reserved.c


Index: clang/test/Preprocessor/macro-reserved.c
===
--- clang/test/Preprocessor/macro-reserved.c
+++ clang/test/Preprocessor/macro-reserved.c
@@ -7,6 +7,7 @@
 #define _HAVE_X 0
 #define X__Y
 #define __STDC__ 1 // expected-warning {{redefining builtin macro}}
+#define __clang__ 1
 
 #undef for
 #undef final
@@ -15,6 +16,12 @@
 #undef _HAVE_X
 #undef X__Y
 #undef __STDC_HOSTED__ // expected-warning {{undefining builtin macro}}
+#undef __INT32_TYPE__
+#undef __UINT32_TYPE__
+#undef __UINTPTR_TYPE__
+#undef __i386__
+#undef __UINT64_TYPE__
+#undef __INT64_TYPE__
 
 // allowlisted definitions
 #define while while
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -150,6 +150,30 @@
 MacroName);
 }
 
+static bool isLanguageDefinedBuiltin(const SourceManager ,
+ const MacroInfo *MI,
+ const StringRef MacroName) {
+  // If this is a macro with special handling (like __LINE__) then it's 
language
+  // defined.
+  if (MI->isBuiltinMacro())
+return true;
+  // Builtin macros are defined in the builtin file
+  if (!SourceMgr.isWrittenInBuiltinFile(MI->getDefinitionLoc()))
+return false;
+  // C defines macros starting with __STDC, and C++ defines macros starting 
with
+  // __STDCPP
+  if (MacroName.startswith("__STDC"))
+return true;
+  // C++ defines the __cplusplus macro
+  if (MacroName == "__cplusplus")
+return true;
+  // C++ defines various feature-test macros starting with __cpp
+  if (MacroName.startswith("__cpp"))
+return true;
+  // Anything else isn't language-defined
+  return false;
+}
+
 static MacroDiag shouldWarnOnMacroDef(Preprocessor , IdentifierInfo *II) {
   const LangOptions  = PP.getLangOpts();
   StringRef Text = II->getName();
@@ -3107,9 +3131,7 @@
 
   // Warn if defining "__LINE__" and other builtins, per C99 6.10.8/4 and
   // C++ [cpp.predefined]p4, but allow it as an extension.
-  if (OtherMI->isBuiltinMacro() ||
-  (SourceMgr.isWrittenInBuiltinFile(OtherMI->getDefinitionLoc()) &&
-   !isFeatureTestMacro(MacroNameTok.getIdentifierInfo()->getName(
+  if (isLanguageDefinedBuiltin(SourceMgr, OtherMI, II->getName()))
 Diag(MacroNameTok, diag::ext_pp_redef_builtin_macro);
   // Macros must be identical.  This means all tokens and whitespace
   // separation must be the same.  C99 6.10.3p2.
@@ -3190,11 +3212,8 @@
   Diag(MI->getDefinitionLoc(), diag::pp_macro_not_used);
 
 // Warn if undefining "__LINE__" and other builtins, per C99 6.10.8/4 and
-// C++ [cpp.predefined]p4, but allow it as an extension. Don't warn if this
-// is an Objective-C builtin macro though.
-if ((MI->isBuiltinMacro() ||
- SourceMgr.isWrittenInBuiltinFile(MI->getDefinitionLoc())) &&
-!(getLangOpts().ObjC && isObjCProtectedMacro(II)))
+// C++ [cpp.predefined]p4, but allow it as an extension.
+if (isLanguageDefinedBuiltin(SourceMgr, MI, II->getName()))
   Diag(MacroNameTok, diag::ext_pp_undef_builtin_macro);
 
 if (MI->isWarnIfUnused())


Index: clang/test/Preprocessor/macro-reserved.c
===
--- clang/test/Preprocessor/macro-reserved.c
+++ clang/test/Preprocessor/macro-reserved.c
@@ -7,6 +7,7 @@
 #define _HAVE_X 0
 #define X__Y
 #define __STDC__ 1 // expected-warning {{redefining builtin macro}}
+#define __clang__ 1
 
 #undef for
 #undef final
@@ -15,6 +16,12 @@
 #undef _HAVE_X
 #undef X__Y
 #undef __STDC_HOSTED__ // expected-warning {{undefining builtin macro}}
+#undef __INT32_TYPE__
+#undef __UINT32_TYPE__
+#undef __UINTPTR_TYPE__
+#undef __i386__
+#undef __UINT64_TYPE__
+#undef __INT64_TYPE__
 
 // allowlisted definitions
 #define while while
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -150,6 +150,30 @@
 MacroName);
 }
 
+static bool isLanguageDefinedBuiltin(const SourceManager ,
+ const MacroInfo *MI,
+ const StringRef MacroName) {
+  // If this is a macro with special handling (like __LINE__) then it's language
+  // defined.
+  if (MI->isBuiltinMacro())
+return true;
+  // Builtin macros are defined in the builtin file
+  if (!SourceMgr.isWrittenInBuiltinFile(MI->getDefinitionLoc()))
+return false;
+  // C defines macros starting 

[PATCH] D151741: [Lex] Only warn on defining or undefining language-defined builtins

2023-05-30 Thread John Brawn via Phabricator via cfe-commits
john.brawn created this revision.
john.brawn added reviewers: aaron.ballman, nathanchance, mstorsjo.
Herald added a project: All.
john.brawn requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

D144654  made it so that we warn on any 
defining or undefining of builtin macros. However the C and C++ standards only 
forbid the defining or undefining of macros defined in the language standard 
itself, but clang defines more macros than those and warning on those may not 
be helpful.

Resolve this by only warning if the builtin macro name is the name of a macro 
defined by the language. This is done in a way that removes some of the 
existing checks, as those were made redundant by restricting the warning in 
this way.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151741

Files:
  clang/lib/Lex/PPDirectives.cpp
  clang/test/Preprocessor/macro-reserved.c


Index: clang/test/Preprocessor/macro-reserved.c
===
--- clang/test/Preprocessor/macro-reserved.c
+++ clang/test/Preprocessor/macro-reserved.c
@@ -7,6 +7,7 @@
 #define _HAVE_X 0
 #define X__Y
 #define __STDC__ 1 // expected-warning {{redefining builtin macro}}
+#define __clang__ 1
 
 #undef for
 #undef final
@@ -15,6 +16,7 @@
 #undef _HAVE_X
 #undef X__Y
 #undef __STDC_HOSTED__ // expected-warning {{undefining builtin macro}}
+#undef __INT32_TYPE__
 
 // allowlisted definitions
 #define while while
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -150,6 +150,30 @@
 MacroName);
 }
 
+static bool isLanguageDefinedBuiltin(const SourceManager ,
+ const MacroInfo *MI,
+ const StringRef MacroName) {
+  // If this is a macro with special handling (like __LINE__) then it's 
language
+  // defined.
+  if (MI->isBuiltinMacro())
+return true;
+  // Builtin macros are defined in the builtin file
+  if (!SourceMgr.isWrittenInBuiltinFile(MI->getDefinitionLoc()))
+return false;
+  // C defines macros starting with __STDC, and C++ defines macros starting 
with
+  // __STDCPP
+  if (MacroName.startswith("__STDC"))
+return true;
+  // C++ defines the __cplusplus macro
+  if (MacroName == "__cplusplus")
+return true;
+  // C++ defines various feature-test macros starting with __cpp
+  if (MacroName.startswith("__cpp"))
+return true;
+  // Anything else isn't language-defined
+  return false;
+}
+
 static MacroDiag shouldWarnOnMacroDef(Preprocessor , IdentifierInfo *II) {
   const LangOptions  = PP.getLangOpts();
   StringRef Text = II->getName();
@@ -3106,9 +3130,7 @@
 
   // Warn if defining "__LINE__" and other builtins, per C99 6.10.8/4 and
   // C++ [cpp.predefined]p4, but allow it as an extension.
-  if (OtherMI->isBuiltinMacro() ||
-  (SourceMgr.isWrittenInBuiltinFile(OtherMI->getDefinitionLoc()) &&
-   !isFeatureTestMacro(MacroNameTok.getIdentifierInfo()->getName(
+  if (isLanguageDefinedBuiltin(SourceMgr, OtherMI, II->getName()))
 Diag(MacroNameTok, diag::ext_pp_redef_builtin_macro);
   // Macros must be identical.  This means all tokens and whitespace
   // separation must be the same.  C99 6.10.3p2.
@@ -3189,11 +3211,8 @@
   Diag(MI->getDefinitionLoc(), diag::pp_macro_not_used);
 
 // Warn if undefining "__LINE__" and other builtins, per C99 6.10.8/4 and
-// C++ [cpp.predefined]p4, but allow it as an extension. Don't warn if this
-// is an Objective-C builtin macro though.
-if ((MI->isBuiltinMacro() ||
- SourceMgr.isWrittenInBuiltinFile(MI->getDefinitionLoc())) &&
-!(getLangOpts().ObjC && isObjCProtectedMacro(II)))
+// C++ [cpp.predefined]p4, but allow it as an extension.
+if (isLanguageDefinedBuiltin(SourceMgr, MI, II->getName()))
   Diag(MacroNameTok, diag::ext_pp_undef_builtin_macro);
 
 if (MI->isWarnIfUnused())


Index: clang/test/Preprocessor/macro-reserved.c
===
--- clang/test/Preprocessor/macro-reserved.c
+++ clang/test/Preprocessor/macro-reserved.c
@@ -7,6 +7,7 @@
 #define _HAVE_X 0
 #define X__Y
 #define __STDC__ 1 // expected-warning {{redefining builtin macro}}
+#define __clang__ 1
 
 #undef for
 #undef final
@@ -15,6 +16,7 @@
 #undef _HAVE_X
 #undef X__Y
 #undef __STDC_HOSTED__ // expected-warning {{undefining builtin macro}}
+#undef __INT32_TYPE__
 
 // allowlisted definitions
 #define while while
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -150,6 +150,30 @@
 MacroName);
 }
 
+static bool 

[PATCH] D144654: [Lex] Warn when defining or undefining any builtin macro

2023-05-30 Thread John Brawn via Phabricator via cfe-commits
john.brawn added a comment.

gcc has the same warning so I wasn't expecting this cause to change problems, 
but looking more closely at gcc's behaviour it looks like it only warns for 
some builtin macros and not others (though glancing over the gcc source code 
it's not clear which macros and for what reason).

I'll look at this some more and see if I can improve the behaviour.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144654

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


[PATCH] D144654: [Lex] Warn when defining or undefining any builtin macro

2023-05-25 Thread John Brawn via Phabricator via cfe-commits
john.brawn added a comment.

D150966  should fix the failure that was seen 
in buildbots, so I've now re-committed this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144654

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


[PATCH] D150966: [clang] Don't define predefined macros multiple times

2023-05-24 Thread John Brawn via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG78bf8a0a2212: [clang] Dont define predefined macros 
multiple times (authored by john.brawn).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150966

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/AVR.cpp
  clang/lib/Basic/Targets/CSKY.cpp
  clang/lib/Basic/Targets/Hexagon.cpp
  clang/lib/Basic/Targets/Le64.cpp
  clang/lib/Basic/Targets/MSP430.cpp
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Basic/Targets/VE.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/test/Preprocessor/init-ve.c
  clang/test/Preprocessor/predefined-macros-no-warnings.c

Index: clang/test/Preprocessor/predefined-macros-no-warnings.c
===
--- /dev/null
+++ clang/test/Preprocessor/predefined-macros-no-warnings.c
@@ -0,0 +1,199 @@
+// Check that the predefined macros don't contain anything that causes a
+// warning, which needs -Wsystem-headers to detect as the predefined macros
+// are in the  file which is treated as a system header and so has
+// warnings suppressed by default.
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arc
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple xcore
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple hexagon
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple hexagon-linux
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple lanai
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64_32-darwin
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-darwin
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-cloudabi
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-freebsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-fuchsia
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-linux
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-linux-openhos
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-netbsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-openbsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-win32-gnu
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-win32-msvc
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64_be
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64_be-freebsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64_be-fuchsia
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64_be-linux
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64_be-netbsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-darwin
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-cloudabi
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-freebsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-fuchsia
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-linux
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-linux-openhos
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-liteos
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-netbsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-openbsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-rtems
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-nacl
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-win32-cygnus
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-win32-gnu
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-win32-itanium
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-win32-msvc
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple armeb
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple armeb-linux
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple armeb-freebsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple armeb-netbsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple armeb-openbsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple armeb-rtems
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple avr
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple bpfeb
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple bpfel
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple msp430
+// 

[PATCH] D150966: [clang] Don't define predefined macros multiple times

2023-05-24 Thread John Brawn via Phabricator via cfe-commits
john.brawn updated this revision to Diff 525165.
john.brawn added a comment.

Use -Eonly in test.


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

https://reviews.llvm.org/D150966

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/AVR.cpp
  clang/lib/Basic/Targets/CSKY.cpp
  clang/lib/Basic/Targets/Hexagon.cpp
  clang/lib/Basic/Targets/Le64.cpp
  clang/lib/Basic/Targets/MSP430.cpp
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Basic/Targets/VE.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/test/Preprocessor/init-ve.c
  clang/test/Preprocessor/predefined-macros-no-warnings.c

Index: clang/test/Preprocessor/predefined-macros-no-warnings.c
===
--- /dev/null
+++ clang/test/Preprocessor/predefined-macros-no-warnings.c
@@ -0,0 +1,199 @@
+// Check that the predefined macros don't contain anything that causes a
+// warning, which needs -Wsystem-headers to detect as the predefined macros
+// are in the  file which is treated as a system header and so has
+// warnings suppressed by default.
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arc
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple xcore
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple hexagon
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple hexagon-linux
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple lanai
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64_32-darwin
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-darwin
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-cloudabi
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-freebsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-fuchsia
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-linux
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-linux-openhos
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-netbsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-openbsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-win32-gnu
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-win32-msvc
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64_be
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64_be-freebsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64_be-fuchsia
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64_be-linux
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64_be-netbsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-darwin
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-cloudabi
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-freebsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-fuchsia
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-linux
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-linux-openhos
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-liteos
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-netbsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-openbsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-rtems
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-nacl
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-win32-cygnus
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-win32-gnu
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-win32-itanium
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-win32-msvc
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple armeb
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple armeb-linux
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple armeb-freebsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple armeb-netbsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple armeb-openbsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple armeb-rtems
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple avr
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple bpfeb
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple bpfel
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple msp430
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple mips
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple mips-linux
+// RUN: %clang_cc1 %s -Eonly 

[PATCH] D150966: [clang] Don't define predefined macros multiple times

2023-05-24 Thread John Brawn via Phabricator via cfe-commits
john.brawn added inline comments.



Comment at: clang/lib/Basic/Targets/AArch64.cpp:241-242
   Builder.defineMacro("__ARM_FEATURE_QRDMX", "1");
-  Builder.defineMacro("__ARM_FEATURE_ATOMICS", "1");
-  Builder.defineMacro("__ARM_FEATURE_CRC32", "1");
 }

aaron.ballman wrote:
> john.brawn wrote:
> > aaron.ballman wrote:
> > > john.brawn wrote:
> > > > aaron.ballman wrote:
> > > > > Hmm, is this correct?
> > > > > 
> > > > > `__ARM_FEATURE_ATOMICS` is defined in one other place, but it's 
> > > > > conditionally defined: 
> > > > > https://github.com/llvm/llvm-project/blob/11926e6149d2a68ecb0652b248efe6890c163846/clang/lib/Basic/Targets/AArch64.cpp#L475
> > > > > 
> > > > > and `__ARM_FEATURE_CRC32` is defined in two places, both conditional: 
> > > > > https://github.com/llvm/llvm-project/blob/11926e6149d2a68ecb0652b248efe6890c163846/clang/lib/Basic/Targets/AArch64.cpp#L422
> > > > >  and 
> > > > > https://github.com/llvm/llvm-project/blob/11926e6149d2a68ecb0652b248efe6890c163846/clang/lib/Basic/Targets/ARM.cpp#L747
> > > > > 
> > > > > 
> > > > AArch64TargetInfo::setArchFeatures sets HasCRC and HasLSE to true for 
> > > > >= 8.1. This does mean that if you do `-march=armv8.1-a+nocrc` then the 
> > > > current behaviour is that __ARM_FEATURE_CRC32 is defined but the 
> > > > behaviour with this patch is that it's not defined, but the new 
> > > > behaviour is correct as we shouldn't be defining it in that case.
> > > Ah, okay! I think it's worth adding a test case for that scenario to show 
> > > we've made a bugfix here, not just an NFC change.
> > Actually I went and double-checked and I'm wrong, 
> > `-march=armv8.N+nowhatever` doesn't cause __ARM_FEATURE_WHATEVER to be 
> > undefined. Which seems wrong, but it's beyond the scope of this patch.
> Yeah, that does seem wrong. Agreed it's not in scope for this patch, but if 
> you would file an issue in GitHub so we don't lose track of it, that'd be 
> appreciated.
https://github.com/llvm/llvm-project/issues/62919



Comment at: clang/test/Preprocessor/predefined-macros-no-warnings.c:5
+// warnings suppressed by default.
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arc
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple xcore

aaron.ballman wrote:
> So the expectation is that any warnings that are emitted would be upgraded to 
> an error and the test would be flagged as a failure because %clang_cc1 would 
> return nonzero in that case?
> 
> (I was thrown for a loop by not using `-verify` and `// 
> expected-no-diagnostics`)
> 
> Pretty sure `-Eonly` is equivalent (it runs the preprocessor without emitting 
> output, so no extra overhead from piping to /dev/null).
Yes the intent is for the test to fail on any warning. Using `-Werror` and not 
`-verify` means that on failure you get which macro caused the error:
```
Exit Code: 1

Command Output (stderr):
--
:351:9: error: redefining builtin macro 
[-Werror,-Wbuiltin-macro-redefined]
#define __LITTLE_ENDIAN__ 1
^
1 error generated.

--
```
whereas `-verify` just outputs
```
Exit Code: 1

Command Output (stderr):
--
error: 'error' diagnostics seen but not expected:
  Line 351: redefining builtin macro
1 error generated.

--
```

Using `-Eonly` makes sense, I'll do that.


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

https://reviews.llvm.org/D150966

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


[PATCH] D150966: [clang] Don't define predefined macros multiple times

2023-05-23 Thread John Brawn via Phabricator via cfe-commits
john.brawn marked an inline comment as done.
john.brawn added inline comments.



Comment at: clang/lib/Basic/Targets/AArch64.cpp:241-242
   Builder.defineMacro("__ARM_FEATURE_QRDMX", "1");
-  Builder.defineMacro("__ARM_FEATURE_ATOMICS", "1");
-  Builder.defineMacro("__ARM_FEATURE_CRC32", "1");
 }

aaron.ballman wrote:
> john.brawn wrote:
> > aaron.ballman wrote:
> > > Hmm, is this correct?
> > > 
> > > `__ARM_FEATURE_ATOMICS` is defined in one other place, but it's 
> > > conditionally defined: 
> > > https://github.com/llvm/llvm-project/blob/11926e6149d2a68ecb0652b248efe6890c163846/clang/lib/Basic/Targets/AArch64.cpp#L475
> > > 
> > > and `__ARM_FEATURE_CRC32` is defined in two places, both conditional: 
> > > https://github.com/llvm/llvm-project/blob/11926e6149d2a68ecb0652b248efe6890c163846/clang/lib/Basic/Targets/AArch64.cpp#L422
> > >  and 
> > > https://github.com/llvm/llvm-project/blob/11926e6149d2a68ecb0652b248efe6890c163846/clang/lib/Basic/Targets/ARM.cpp#L747
> > > 
> > > 
> > AArch64TargetInfo::setArchFeatures sets HasCRC and HasLSE to true for >= 
> > 8.1. This does mean that if you do `-march=armv8.1-a+nocrc` then the 
> > current behaviour is that __ARM_FEATURE_CRC32 is defined but the behaviour 
> > with this patch is that it's not defined, but the new behaviour is correct 
> > as we shouldn't be defining it in that case.
> Ah, okay! I think it's worth adding a test case for that scenario to show 
> we've made a bugfix here, not just an NFC change.
Actually I went and double-checked and I'm wrong, `-march=armv8.N+nowhatever` 
doesn't cause __ARM_FEATURE_WHATEVER to be undefined. Which seems wrong, but 
it's beyond the scope of this patch.



Comment at: clang/lib/Basic/Targets/VE.cpp:30-32
-  Builder.defineMacro("unix", "1");
-  Builder.defineMacro("__unix__", "1");
-  Builder.defineMacro("__linux__", "1");

aaron.ballman wrote:
> john.brawn wrote:
> > aaron.ballman wrote:
> > > Shouldn't this be calling `DefineStd(Builder, "unix", Opts);` like all 
> > > the others?
> > Only the OS target should be defining OS-related macros, and in 
> > AllocateTarget in Targets.cpp VETargetInfo is hardcoded to always use 
> > LinuxTargetInfo, which calls `DefineStd(Builder, "unix", Opts);`.
> Hmmm, we still have calls to this outside of `getOSDefines()` though?
> 
> https://github.com/llvm/llvm-project/blob/main/clang/lib/Basic/Targets/ARM.cpp#L1400
> https://github.com/llvm/llvm-project/blob/main/clang/lib/Basic/Targets/Le64.cpp#L28
> https://github.com/llvm/llvm-project/blob/main/clang/lib/Basic/Targets/X86.h#L634
> https://github.com/llvm/llvm-project/blob/main/clang/lib/Basic/Targets/X86.h#L907
> 
> should those also be changing (perhaps in a follow-up)?
Most of these are TargetInfos that combine OS plus target, e.g. 
CygwinARMTargetInfo is both Cygwin OS and ARM Target. The only exception is 
Le64, and I have no idea if it's correct or not for it to be doing that.


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

https://reviews.llvm.org/D150966

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


[PATCH] D150966: [clang] Don't define predefined macros multiple times

2023-05-23 Thread John Brawn via Phabricator via cfe-commits
john.brawn updated this revision to Diff 524686.
john.brawn added a comment.

Add VE test.


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

https://reviews.llvm.org/D150966

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/AVR.cpp
  clang/lib/Basic/Targets/CSKY.cpp
  clang/lib/Basic/Targets/Hexagon.cpp
  clang/lib/Basic/Targets/Le64.cpp
  clang/lib/Basic/Targets/MSP430.cpp
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Basic/Targets/VE.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/test/Preprocessor/init-ve.c
  clang/test/Preprocessor/predefined-macros-no-warnings.c

Index: clang/test/Preprocessor/predefined-macros-no-warnings.c
===
--- /dev/null
+++ clang/test/Preprocessor/predefined-macros-no-warnings.c
@@ -0,0 +1,199 @@
+// Check that the predefined macros don't contain anything that causes a
+// warning, which needs -Wsystem-headers to detect as the predefined macros
+// are in the  file which is treated as a system header and so has
+// warnings suppressed by default.
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arc
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple xcore
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple hexagon
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple hexagon-linux
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple lanai
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64_32-darwin
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64-darwin
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64-cloudabi
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64-freebsd
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64-fuchsia
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64-linux
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64-linux-openhos
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64-netbsd
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64-openbsd
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64-win32-gnu
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64-win32-msvc
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64_be
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64_be-freebsd
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64_be-fuchsia
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64_be-linux
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64_be-netbsd
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-darwin
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-cloudabi
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-freebsd
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-fuchsia
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-linux
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-linux-openhos
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-liteos
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-netbsd
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-openbsd
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-rtems
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-nacl
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-win32-cygnus
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-win32-gnu
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-win32-itanium
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-win32-msvc
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple armeb
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple armeb-linux
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple armeb-freebsd
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple armeb-netbsd
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple armeb-openbsd
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple armeb-rtems
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple 

[PATCH] D150966: [clang] Don't define predefined macros multiple times

2023-05-22 Thread John Brawn via Phabricator via cfe-commits
john.brawn added inline comments.



Comment at: clang/lib/Basic/Targets/AArch64.cpp:241-242
   Builder.defineMacro("__ARM_FEATURE_QRDMX", "1");
-  Builder.defineMacro("__ARM_FEATURE_ATOMICS", "1");
-  Builder.defineMacro("__ARM_FEATURE_CRC32", "1");
 }

aaron.ballman wrote:
> Hmm, is this correct?
> 
> `__ARM_FEATURE_ATOMICS` is defined in one other place, but it's conditionally 
> defined: 
> https://github.com/llvm/llvm-project/blob/11926e6149d2a68ecb0652b248efe6890c163846/clang/lib/Basic/Targets/AArch64.cpp#L475
> 
> and `__ARM_FEATURE_CRC32` is defined in two places, both conditional: 
> https://github.com/llvm/llvm-project/blob/11926e6149d2a68ecb0652b248efe6890c163846/clang/lib/Basic/Targets/AArch64.cpp#L422
>  and 
> https://github.com/llvm/llvm-project/blob/11926e6149d2a68ecb0652b248efe6890c163846/clang/lib/Basic/Targets/ARM.cpp#L747
> 
> 
AArch64TargetInfo::setArchFeatures sets HasCRC and HasLSE to true for >= 8.1. 
This does mean that if you do `-march=armv8.1-a+nocrc` then the current 
behaviour is that __ARM_FEATURE_CRC32 is defined but the behaviour with this 
patch is that it's not defined, but the new behaviour is correct as we 
shouldn't be defining it in that case.



Comment at: clang/lib/Basic/Targets/VE.cpp:30-32
-  Builder.defineMacro("unix", "1");
-  Builder.defineMacro("__unix__", "1");
-  Builder.defineMacro("__linux__", "1");

aaron.ballman wrote:
> Shouldn't this be calling `DefineStd(Builder, "unix", Opts);` like all the 
> others?
Only the OS target should be defining OS-related macros, and in AllocateTarget 
in Targets.cpp VETargetInfo is hardcoded to always use LinuxTargetInfo, which 
calls `DefineStd(Builder, "unix", Opts);`.


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

https://reviews.llvm.org/D150966

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


[PATCH] D150966: [clang] Don't define predefined macros multiple times

2023-05-22 Thread John Brawn via Phabricator via cfe-commits
john.brawn added a comment.

In D150966#4356779 , @barannikov88 
wrote:

>   Check that the predefined macros don't contain anything that causes a 
> warning
>
> What is 'anything', exactly? Does it include duplicate predefined macros, or 
> it tests something else?
> Sorry for the silly question.

D144654  caused a failure 
http://45.33.8.238/macm1/60903/step_7.txt that caused it to be reverted. The 
failure was in tests that use -Wsystem-headers and was because the host that 
clang was built on (aarch64 macos) had duplicate predefines and those tests 
don't specify a target and so the default (i.e. host) target is used. This test 
is mainly so that we have a test that uses -Wsystem-headers that doesn't depend 
on the host machine so that I know D144654  
won't cause further problems when I re-commit it.


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

https://reviews.llvm.org/D150966

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


[PATCH] D150966: [clang] Don't define predefined macros multiple times

2023-05-19 Thread John Brawn via Phabricator via cfe-commits
john.brawn added a comment.

In D150966#4356403 , @barannikov88 
wrote:

> Is it possible/worth to add an assertion to Builder.defineMacro to enforce 
> this one definition rule?

It just appends a string to a raw_ostream, so it's not possible to check what's 
previously been written.

In D150966#4356470 , @barannikov88 
wrote:

> Q: What is it the -Wsystem-header can warn about? I mean, no system header is 
> included by the test, what can go wrong?

The  buffer is treated as a system header. I've expanded on the 
comment to explain this more.


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

https://reviews.llvm.org/D150966

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


[PATCH] D150966: [clang] Don't define predefined macros multiple times

2023-05-19 Thread John Brawn via Phabricator via cfe-commits
john.brawn updated this revision to Diff 523803.
john.brawn marked 2 inline comments as done.
john.brawn added a comment.

Send test output to /dev/null


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

https://reviews.llvm.org/D150966

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/AVR.cpp
  clang/lib/Basic/Targets/CSKY.cpp
  clang/lib/Basic/Targets/Hexagon.cpp
  clang/lib/Basic/Targets/Le64.cpp
  clang/lib/Basic/Targets/MSP430.cpp
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Basic/Targets/VE.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/test/Preprocessor/predefined-macros-no-warnings.c

Index: clang/test/Preprocessor/predefined-macros-no-warnings.c
===
--- /dev/null
+++ clang/test/Preprocessor/predefined-macros-no-warnings.c
@@ -0,0 +1,199 @@
+// Check that the predefined macros don't contain anything that causes a
+// warning, which needs -Wsystem-headers to detect as the predefined macros
+// are in the  file which is treated as a system header and so has
+// warnings suppressed by default.
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arc
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple xcore
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple hexagon
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple hexagon-linux
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple lanai
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64_32-darwin
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64-darwin
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64-cloudabi
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64-freebsd
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64-fuchsia
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64-linux
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64-linux-openhos
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64-netbsd
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64-openbsd
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64-win32-gnu
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64-win32-msvc
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64_be
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64_be-freebsd
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64_be-fuchsia
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64_be-linux
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple aarch64_be-netbsd
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-darwin
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-cloudabi
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-freebsd
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-fuchsia
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-linux
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-linux-openhos
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-liteos
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-netbsd
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-openbsd
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-rtems
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-nacl
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-win32-cygnus
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-win32-gnu
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-win32-itanium
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arm-win32-msvc
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple armeb
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple armeb-linux
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple armeb-freebsd
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple armeb-netbsd
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple armeb-openbsd
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple armeb-rtems
+// RUN: %clang_cc1 %s -E -o /dev/null 

[PATCH] D150966: [clang] Don't define predefined macros multiple times

2023-05-19 Thread John Brawn via Phabricator via cfe-commits
john.brawn updated this revision to Diff 523785.
john.brawn added a comment.

Remove redundant braces, explain more in test comment.


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

https://reviews.llvm.org/D150966

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/AVR.cpp
  clang/lib/Basic/Targets/CSKY.cpp
  clang/lib/Basic/Targets/Hexagon.cpp
  clang/lib/Basic/Targets/Le64.cpp
  clang/lib/Basic/Targets/MSP430.cpp
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Basic/Targets/VE.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/test/Preprocessor/predefined-macros-no-warnings.c

Index: clang/test/Preprocessor/predefined-macros-no-warnings.c
===
--- /dev/null
+++ clang/test/Preprocessor/predefined-macros-no-warnings.c
@@ -0,0 +1,199 @@
+// Check that the predefined macros don't contain anything that causes a
+// warning, which needs -Wsystem-headers to detect as the predefined macros
+// are in the  file which is treated as a system header and so has
+// warnings suppressed by default.
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple arc
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple xcore
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple hexagon
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple hexagon-linux
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple lanai
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple aarch64_32-darwin
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple aarch64
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple aarch64-darwin
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple aarch64-cloudabi
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple aarch64-freebsd
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple aarch64-fuchsia
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple aarch64-linux
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple aarch64-linux-openhos
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple aarch64-netbsd
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple aarch64-openbsd
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple aarch64-win32-gnu
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple aarch64-win32-msvc
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple aarch64_be
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple aarch64_be-freebsd
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple aarch64_be-fuchsia
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple aarch64_be-linux
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple aarch64_be-netbsd
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple arm
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple arm-darwin
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple arm-cloudabi
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple arm-freebsd
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple arm-fuchsia
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple arm-linux
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple arm-linux-openhos
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple arm-liteos
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple arm-netbsd
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple arm-openbsd
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple arm-rtems
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple arm-nacl
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple arm-win32-cygnus
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple arm-win32-gnu
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple arm-win32-itanium
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple arm-win32-msvc
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple armeb
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple armeb-linux
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple armeb-freebsd
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple armeb-netbsd
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple armeb-openbsd
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple armeb-rtems
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple avr
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple bpfeb
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple bpfel
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple msp430
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple mips
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple 

[PATCH] D150966: [clang] Don't define predefined macros multiple times

2023-05-19 Thread John Brawn via Phabricator via cfe-commits
john.brawn created this revision.
john.brawn added reviewers: aaron.ballman, thakis, arichardson, pratlucas.
Herald added subscribers: luke, abrachet, frasercrmck, phosek, luismarques, 
apazos, sameer.abuasal, s.egerton, Jim, jocewei, PkmX, the_o, brucehoult, 
MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, niosHD, sabuasal, 
simoncook, johnrusso, rbar, asb, fedor.sergeev, kristof.beyls, krytarowski, 
dylanmckay, dschuff.
Herald added a project: All.
john.brawn requested review of this revision.
Herald added subscribers: cfe-commits, pcwang-thead, MaskRay, aheejin.
Herald added a project: clang.

Fix several instances of macros being defined multiple times in several 
targets. Most of these are just simple duplication in a TargetInfo or 
OSTargetInfo of things already defined in InitializePredefinedMacros or 
InitializeStandardPredefinedMacros, but there are a few that aren't:

- AArch64 defines a couple of feature macros for armv8.1a that are handled 
generically by getTargetDefines.
- CSKY needs to take care when CPUName and ArchName are the same.
- Many os/target combinations result in __ELF__ being defined twice. Instead 
define __ELF__ just once in InitPreprocessor based on the Triple, which already 
knows what the object format is based on os and target.

These changes shouldn't change the final result of which macros are defined, 
with the exception of the changes to __ELF__ where if you explicitly specify 
the object type in the triple then this affects if __ELF__ is defined, e.g. 
--target=i686-windows-elf results in it being defined where it wasn't before, 
but this is more accurate as an ELF file is in fact generated.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150966

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/AVR.cpp
  clang/lib/Basic/Targets/CSKY.cpp
  clang/lib/Basic/Targets/Hexagon.cpp
  clang/lib/Basic/Targets/Le64.cpp
  clang/lib/Basic/Targets/MSP430.cpp
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Basic/Targets/VE.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/test/Preprocessor/predefined-macros-no-warnings.c

Index: clang/test/Preprocessor/predefined-macros-no-warnings.c
===
--- /dev/null
+++ clang/test/Preprocessor/predefined-macros-no-warnings.c
@@ -0,0 +1,196 @@
+// Check that the predefined macros don't contain anything that causes a warning with -Wsystem-headers
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple arc
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple xcore
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple hexagon
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple hexagon-linux
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple lanai
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple aarch64_32-darwin
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple aarch64
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple aarch64-darwin
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple aarch64-cloudabi
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple aarch64-freebsd
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple aarch64-fuchsia
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple aarch64-linux
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple aarch64-linux-openhos
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple aarch64-netbsd
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple aarch64-openbsd
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple aarch64-win32-gnu
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple aarch64-win32-msvc
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple aarch64_be
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple aarch64_be-freebsd
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple aarch64_be-fuchsia
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple aarch64_be-linux
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple aarch64_be-netbsd
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple arm
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple arm-darwin
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple arm-cloudabi
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple arm-freebsd
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple arm-fuchsia
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple arm-linux
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple arm-linux-openhos
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple arm-liteos
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple arm-netbsd
+// RUN: %clang_cc1 %s -E -o - -Wsystem-headers -Werror -triple 

[PATCH] D144654: [Lex] Warn when defining or undefining any builtin macro

2023-05-17 Thread John Brawn via Phabricator via cfe-commits
john.brawn added a comment.

This patch caused a failure in AArch64 buildbots due to 
AArch64TargetInfo::getTargetDefines redefining _LP64 and __LP64__. Fixed in 
https://reviews.llvm.org/rGe55d52cd34fb7a6a6617639d147b9d0abaceeeab.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144654

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


[PATCH] D144654: [Lex] Warn when defining or undefining any builtin macro

2023-05-17 Thread John Brawn via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG22e3f587fd1f: [Lex] Warn when defining or undefining any 
builtin macro (authored by john.brawn).

Changed prior to commit:
  https://reviews.llvm.org/D144654?vs=522683=522989#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144654

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Lex/PPDirectives.cpp
  clang/test/Lexer/builtin_redef.c
  clang/test/Preprocessor/macro-reserved.c
  clang/test/Preprocessor/macro-reserved.cpp

Index: clang/test/Preprocessor/macro-reserved.cpp
===
--- clang/test/Preprocessor/macro-reserved.cpp
+++ clang/test/Preprocessor/macro-reserved.cpp
@@ -12,7 +12,7 @@
 #undef _HAVE_X
 #undef X__Y
 
-#undef __cplusplus
+#undef __cplusplus // expected-warning {{undefining builtin macro}}
 #define __cplusplus
 
 // allowlisted definitions
Index: clang/test/Preprocessor/macro-reserved.c
===
--- clang/test/Preprocessor/macro-reserved.c
+++ clang/test/Preprocessor/macro-reserved.c
@@ -6,6 +6,7 @@
 #define __cplusplus
 #define _HAVE_X 0
 #define X__Y
+#define __STDC__ 1 // expected-warning {{redefining builtin macro}}
 
 #undef for
 #undef final
@@ -13,6 +14,7 @@
 #undef __cplusplus
 #undef _HAVE_X
 #undef X__Y
+#undef __STDC_HOSTED__ // expected-warning {{undefining builtin macro}}
 
 // allowlisted definitions
 #define while while
Index: clang/test/Lexer/builtin_redef.c
===
--- clang/test/Lexer/builtin_redef.c
+++ clang/test/Lexer/builtin_redef.c
@@ -1,12 +1,24 @@
-// RUN: %clang_cc1 %s -D__TIME__=1234 -U__DATE__ -E 2>&1 | FileCheck %s --check-prefix=CHECK-OUT
-// RUN: %clang_cc1 %s -D__TIME__=1234 -U__DATE__ -E 2>&1 | FileCheck %s --check-prefix=CHECK-WARN
-// RUN: not %clang_cc1 %s -D__TIME__=1234 -U__DATE__ -E 2>&1 -pedantic-errors | FileCheck %s --check-prefix=CHECK-ERR
+// RUN: %clang_cc1 %s -D__TIME__=1234 -U__DATE__ -D__STDC__=1 -U__STDC_HOSTED__ -E 2>&1 | FileCheck %s --check-prefix=CHECK-OUT
+// RUN: %clang_cc1 %s -D__TIME__=1234 -U__DATE__ -D__STDC__=1 -U__STDC_HOSTED__ -E 2>&1 | FileCheck %s --check-prefix=CHECK-WARN
+// RUN: not %clang_cc1 %s -D__TIME__=1234 -U__DATE__ -D__STDC__=1 -U__STDC_HOSTED__ -E 2>&1 -pedantic-errors | FileCheck %s --check-prefix=CHECK-ERR
 
 // CHECK-WARN: :{{.*}} warning: redefining builtin macro
+// CHECK-WARN-NEXT: #define __TIME__ 1234
 // CHECK-WARN: :{{.*}} warning: undefining builtin macro
+// CHECK-WARN-NEXT: #undef __DATE__
+// CHECK-WARN: :{{.*}} warning: redefining builtin macro
+// CHECK-WARN-NEXT: #define __STDC__ 1
+// CHECK-WARN: :{{.*}} warning: undefining builtin macro
+// CHECK-WARN-NEXT: #undef __STDC_HOSTED__
 
 // CHECK-ERR: :{{.*}} error: redefining builtin macro
+// CHECK-ERR-NEXT: #define __TIME__ 1234
+// CHECK-ERR: :{{.*}} error: undefining builtin macro
+// CHECK-ERR-NEXT: #undef __DATE__
+// CHECK-ERR: :{{.*}} error: redefining builtin macro
+// CHECK-ERR-NEXT: #define __STDC__ 1
 // CHECK-ERR: :{{.*}} error: undefining builtin macro
+// CHECK-ERR-NEXT: #undef __STDC_HOSTED__
 
 int n = __TIME__;
 __DATE__
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -109,52 +109,52 @@
   PED_Elifndef
 };
 
+static bool isFeatureTestMacro(StringRef MacroName) {
+  // list from:
+  // * https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_macros.html
+  // * https://docs.microsoft.com/en-us/cpp/c-runtime-library/security-features-in-the-crt?view=msvc-160
+  // * man 7 feature_test_macros
+  // The list must be sorted for correct binary search.
+  static constexpr StringRef ReservedMacro[] = {
+  "_ATFILE_SOURCE",
+  "_BSD_SOURCE",
+  "_CRT_NONSTDC_NO_WARNINGS",
+  "_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES",
+  "_CRT_SECURE_NO_WARNINGS",
+  "_FILE_OFFSET_BITS",
+  "_FORTIFY_SOURCE",
+  "_GLIBCXX_ASSERTIONS",
+  "_GLIBCXX_CONCEPT_CHECKS",
+  "_GLIBCXX_DEBUG",
+  "_GLIBCXX_DEBUG_PEDANTIC",
+  "_GLIBCXX_PARALLEL",
+  "_GLIBCXX_PARALLEL_ASSERTIONS",
+  "_GLIBCXX_SANITIZE_VECTOR",
+  "_GLIBCXX_USE_CXX11_ABI",
+  "_GLIBCXX_USE_DEPRECATED",
+  "_GNU_SOURCE",
+  "_ISOC11_SOURCE",
+  "_ISOC95_SOURCE",
+  "_ISOC99_SOURCE",
+  "_LARGEFILE64_SOURCE",
+  "_POSIX_C_SOURCE",
+  "_REENTRANT",
+  "_SVID_SOURCE",
+  "_THREAD_SAFE",
+  "_XOPEN_SOURCE",
+  "_XOPEN_SOURCE_EXTENDED",
+  "__STDCPP_WANT_MATH_SPEC_FUNCS__",
+  "__STDC_FORMAT_MACROS",
+  };
+  return std::binary_search(std::begin(ReservedMacro), std::end(ReservedMacro),
+MacroName);
+}
+
 static MacroDiag 

[PATCH] D144654: [Lex] Warn when defining or undefining any builtin macro

2023-05-16 Thread John Brawn via Phabricator via cfe-commits
john.brawn added inline comments.



Comment at: clang/test/Preprocessor/macro-reserved.cpp:15
 
-#undef __cplusplus
+#undef __cplusplus // expected-warning {{undefining builtin macro}}
 #define __cplusplus

aaron.ballman wrote:
> Why do we diagnose the undef but not the define?
After the undef the builtin macro definition no longer exists, so when 
Preprocessor::HandleDefineDirective checks for an existing definition to see if 
it's a builtin it doesn't find one.


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

https://reviews.llvm.org/D144654

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


[PATCH] D144654: [Lex] Warn when defining or undefining any builtin macro

2023-05-16 Thread John Brawn via Phabricator via cfe-commits
john.brawn updated this revision to Diff 522683.
john.brawn added a comment.

Adjusted in order to make clang-format happy.


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

https://reviews.llvm.org/D144654

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Lex/PPDirectives.cpp
  clang/test/Lexer/builtin_redef.c
  clang/test/Preprocessor/macro-reserved.c
  clang/test/Preprocessor/macro-reserved.cpp

Index: clang/test/Preprocessor/macro-reserved.cpp
===
--- clang/test/Preprocessor/macro-reserved.cpp
+++ clang/test/Preprocessor/macro-reserved.cpp
@@ -12,7 +12,7 @@
 #undef _HAVE_X
 #undef X__Y
 
-#undef __cplusplus
+#undef __cplusplus // expected-warning {{undefining builtin macro}}
 #define __cplusplus
 
 // allowlisted definitions
Index: clang/test/Preprocessor/macro-reserved.c
===
--- clang/test/Preprocessor/macro-reserved.c
+++ clang/test/Preprocessor/macro-reserved.c
@@ -6,6 +6,7 @@
 #define __cplusplus
 #define _HAVE_X 0
 #define X__Y
+#define __STDC__ 1 // expected-warning {{redefining builtin macro}}
 
 #undef for
 #undef final
@@ -13,6 +14,7 @@
 #undef __cplusplus
 #undef _HAVE_X
 #undef X__Y
+#undef __STDC_HOSTED__ // expected-warning {{undefining builtin macro}}
 
 // allowlisted definitions
 #define while while
Index: clang/test/Lexer/builtin_redef.c
===
--- clang/test/Lexer/builtin_redef.c
+++ clang/test/Lexer/builtin_redef.c
@@ -1,12 +1,24 @@
-// RUN: %clang_cc1 %s -D__TIME__=1234 -U__DATE__ -E 2>&1 | FileCheck %s --check-prefix=CHECK-OUT
-// RUN: %clang_cc1 %s -D__TIME__=1234 -U__DATE__ -E 2>&1 | FileCheck %s --check-prefix=CHECK-WARN
-// RUN: not %clang_cc1 %s -D__TIME__=1234 -U__DATE__ -E 2>&1 -pedantic-errors | FileCheck %s --check-prefix=CHECK-ERR
+// RUN: %clang_cc1 %s -D__TIME__=1234 -U__DATE__ -D__STDC__=1 -U__STDC_HOSTED__ -E 2>&1 | FileCheck %s --check-prefix=CHECK-OUT
+// RUN: %clang_cc1 %s -D__TIME__=1234 -U__DATE__ -D__STDC__=1 -U__STDC_HOSTED__ -E 2>&1 | FileCheck %s --check-prefix=CHECK-WARN
+// RUN: not %clang_cc1 %s -D__TIME__=1234 -U__DATE__ -D__STDC__=1 -U__STDC_HOSTED__ -E 2>&1 -pedantic-errors | FileCheck %s --check-prefix=CHECK-ERR
 
 // CHECK-WARN: :{{.*}} warning: redefining builtin macro
+// CHECK-WARN-NEXT: #define __TIME__ 1234
 // CHECK-WARN: :{{.*}} warning: undefining builtin macro
+// CHECK-WARN-NEXT: #undef __DATE__
+// CHECK-WARN: :{{.*}} warning: redefining builtin macro
+// CHECK-WARN-NEXT: #define __STDC__ 1
+// CHECK-WARN: :{{.*}} warning: undefining builtin macro
+// CHECK-WARN-NEXT: #undef __STDC_HOSTED__
 
 // CHECK-ERR: :{{.*}} error: redefining builtin macro
+// CHECK-ERR-NEXT: #define __TIME__ 1234
+// CHECK-ERR: :{{.*}} error: undefining builtin macro
+// CHECK-ERR-NEXT: #undef __DATE__
+// CHECK-ERR: :{{.*}} error: redefining builtin macro
+// CHECK-ERR-NEXT: #define __STDC__ 1
 // CHECK-ERR: :{{.*}} error: undefining builtin macro
+// CHECK-ERR-NEXT: #undef __STDC_HOSTED__
 
 int n = __TIME__;
 __DATE__
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -109,52 +109,52 @@
   PED_Elifndef
 };
 
+static bool isFeatureTestMacro(StringRef MacroName) {
+  // list from:
+  // * https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_macros.html
+  // * https://docs.microsoft.com/en-us/cpp/c-runtime-library/security-features-in-the-crt?view=msvc-160
+  // * man 7 feature_test_macros
+  // The list must be sorted for correct binary search.
+  static constexpr StringRef ReservedMacro[] = {
+  "_ATFILE_SOURCE",
+  "_BSD_SOURCE",
+  "_CRT_NONSTDC_NO_WARNINGS",
+  "_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES",
+  "_CRT_SECURE_NO_WARNINGS",
+  "_FILE_OFFSET_BITS",
+  "_FORTIFY_SOURCE",
+  "_GLIBCXX_ASSERTIONS",
+  "_GLIBCXX_CONCEPT_CHECKS",
+  "_GLIBCXX_DEBUG",
+  "_GLIBCXX_DEBUG_PEDANTIC",
+  "_GLIBCXX_PARALLEL",
+  "_GLIBCXX_PARALLEL_ASSERTIONS",
+  "_GLIBCXX_SANITIZE_VECTOR",
+  "_GLIBCXX_USE_CXX11_ABI",
+  "_GLIBCXX_USE_DEPRECATED",
+  "_GNU_SOURCE",
+  "_ISOC11_SOURCE",
+  "_ISOC95_SOURCE",
+  "_ISOC99_SOURCE",
+  "_LARGEFILE64_SOURCE",
+  "_POSIX_C_SOURCE",
+  "_REENTRANT",
+  "_SVID_SOURCE",
+  "_THREAD_SAFE",
+  "_XOPEN_SOURCE",
+  "_XOPEN_SOURCE_EXTENDED",
+  "__STDCPP_WANT_MATH_SPEC_FUNCS__",
+  "__STDC_FORMAT_MACROS",
+  };
+  return std::binary_search(std::begin(ReservedMacro), std::end(ReservedMacro),
+MacroName);
+}
+
 static MacroDiag shouldWarnOnMacroDef(Preprocessor , IdentifierInfo *II) {
   const LangOptions  = PP.getLangOpts();
-  if (isReservedInAllContexts(II->isReserved(Lang))) {
-// list from:
-// - https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_macros.html

[PATCH] D144654: [Lex] Warn when defining or undefining any builtin macro

2023-05-15 Thread John Brawn via Phabricator via cfe-commits
john.brawn updated this revision to Diff 522215.
john.brawn edited the summary of this revision.
john.brawn added a comment.

I've gone with handling the _GNU_SOURCE problem in the clang-tidy tests by 
re-using the list of feature test macros in shouldWarnOnMacroDef, and not 
warning if there's a match.


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

https://reviews.llvm.org/D144654

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Lex/PPDirectives.cpp
  clang/test/Lexer/builtin_redef.c
  clang/test/Preprocessor/macro-reserved.c
  clang/test/Preprocessor/macro-reserved.cpp

Index: clang/test/Preprocessor/macro-reserved.cpp
===
--- clang/test/Preprocessor/macro-reserved.cpp
+++ clang/test/Preprocessor/macro-reserved.cpp
@@ -12,7 +12,7 @@
 #undef _HAVE_X
 #undef X__Y
 
-#undef __cplusplus
+#undef __cplusplus // expected-warning {{undefining builtin macro}}
 #define __cplusplus
 
 // allowlisted definitions
Index: clang/test/Preprocessor/macro-reserved.c
===
--- clang/test/Preprocessor/macro-reserved.c
+++ clang/test/Preprocessor/macro-reserved.c
@@ -6,6 +6,7 @@
 #define __cplusplus
 #define _HAVE_X 0
 #define X__Y
+#define __STDC__ 1 // expected-warning {{redefining builtin macro}}
 
 #undef for
 #undef final
@@ -13,6 +14,7 @@
 #undef __cplusplus
 #undef _HAVE_X
 #undef X__Y
+#undef __STDC_HOSTED__ // expected-warning {{undefining builtin macro}}
 
 // allowlisted definitions
 #define while while
Index: clang/test/Lexer/builtin_redef.c
===
--- clang/test/Lexer/builtin_redef.c
+++ clang/test/Lexer/builtin_redef.c
@@ -1,12 +1,24 @@
-// RUN: %clang_cc1 %s -D__TIME__=1234 -U__DATE__ -E 2>&1 | FileCheck %s --check-prefix=CHECK-OUT
-// RUN: %clang_cc1 %s -D__TIME__=1234 -U__DATE__ -E 2>&1 | FileCheck %s --check-prefix=CHECK-WARN
-// RUN: not %clang_cc1 %s -D__TIME__=1234 -U__DATE__ -E 2>&1 -pedantic-errors | FileCheck %s --check-prefix=CHECK-ERR
+// RUN: %clang_cc1 %s -D__TIME__=1234 -U__DATE__ -D__STDC__=1 -U__STDC_HOSTED__ -E 2>&1 | FileCheck %s --check-prefix=CHECK-OUT
+// RUN: %clang_cc1 %s -D__TIME__=1234 -U__DATE__ -D__STDC__=1 -U__STDC_HOSTED__ -E 2>&1 | FileCheck %s --check-prefix=CHECK-WARN
+// RUN: not %clang_cc1 %s -D__TIME__=1234 -U__DATE__ -D__STDC__=1 -U__STDC_HOSTED__ -E 2>&1 -pedantic-errors | FileCheck %s --check-prefix=CHECK-ERR
 
 // CHECK-WARN: :{{.*}} warning: redefining builtin macro
+// CHECK-WARN-NEXT: #define __TIME__ 1234
 // CHECK-WARN: :{{.*}} warning: undefining builtin macro
+// CHECK-WARN-NEXT: #undef __DATE__
+// CHECK-WARN: :{{.*}} warning: redefining builtin macro
+// CHECK-WARN-NEXT: #define __STDC__ 1
+// CHECK-WARN: :{{.*}} warning: undefining builtin macro
+// CHECK-WARN-NEXT: #undef __STDC_HOSTED__
 
 // CHECK-ERR: :{{.*}} error: redefining builtin macro
+// CHECK-ERR-NEXT: #define __TIME__ 1234
+// CHECK-ERR: :{{.*}} error: undefining builtin macro
+// CHECK-ERR-NEXT: #undef __DATE__
+// CHECK-ERR: :{{.*}} error: redefining builtin macro
+// CHECK-ERR-NEXT: #define __STDC__ 1
 // CHECK-ERR: :{{.*}} error: undefining builtin macro
+// CHECK-ERR-NEXT: #undef __STDC_HOSTED__
 
 int n = __TIME__;
 __DATE__
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -109,52 +109,52 @@
   PED_Elifndef
 };
 
+static bool isFeatureTestMacro(StringRef MacroName) {
+  // list from:
+  // - https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_macros.html
+  // - https://docs.microsoft.com/en-us/cpp/c-runtime-library/security-features-in-the-crt?view=msvc-160
+  // - man 7 feature_test_macros
+  // The list must be sorted for correct binary search.
+  static constexpr StringRef ReservedMacro[] = {
+  "_ATFILE_SOURCE",
+  "_BSD_SOURCE",
+  "_CRT_NONSTDC_NO_WARNINGS",
+  "_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES",
+  "_CRT_SECURE_NO_WARNINGS",
+  "_FILE_OFFSET_BITS",
+  "_FORTIFY_SOURCE",
+  "_GLIBCXX_ASSERTIONS",
+  "_GLIBCXX_CONCEPT_CHECKS",
+  "_GLIBCXX_DEBUG",
+  "_GLIBCXX_DEBUG_PEDANTIC",
+  "_GLIBCXX_PARALLEL",
+  "_GLIBCXX_PARALLEL_ASSERTIONS",
+  "_GLIBCXX_SANITIZE_VECTOR",
+  "_GLIBCXX_USE_CXX11_ABI",
+  "_GLIBCXX_USE_DEPRECATED",
+  "_GNU_SOURCE",
+  "_ISOC11_SOURCE",
+  "_ISOC95_SOURCE",
+  "_ISOC99_SOURCE",
+  "_LARGEFILE64_SOURCE",
+  "_POSIX_C_SOURCE",
+  "_REENTRANT",
+  "_SVID_SOURCE",
+  "_THREAD_SAFE",
+  "_XOPEN_SOURCE",
+  "_XOPEN_SOURCE_EXTENDED",
+  "__STDCPP_WANT_MATH_SPEC_FUNCS__",
+  "__STDC_FORMAT_MACROS",
+  };
+  return std::binary_search(std::begin(ReservedMacro), std::end(ReservedMacro),
+MacroName);
+}
+
 static MacroDiag shouldWarnOnMacroDef(Preprocessor , IdentifierInfo *II) {
   const 

[PATCH] D144654: [Lex] Warn when defining or undefining any builtin macro

2023-05-12 Thread John Brawn via Phabricator via cfe-commits
john.brawn planned changes to this revision.
john.brawn added a comment.

The clang-tidy failures in pre-merge are because

- clang-tidy tests use the compile database from building llvm (though you have 
to manually copy it otherwise the tests silently pass without actually running 
the test, which is why I wasn't seeing this locally)
- this has -D_GNU_SOURCE because llvm/cmake/config-ix.cmake adds it to the 
defines
- clang predefines _GNU_SOURCE when compiling C++ (for certain targets)
- therefore we get the warning for a redefined builtin

I'm not sure yet what the best fix is here. gcc has the same behaviour of 
defining _GNU_SOURCE for C++, but does it by adding -D_GNU_SOURCE to the cc1 
command line so it doesn't give a warning on redefine, but it doesn't look like 
copying this behaviour in clang would be easy. I'll think about this some more.


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

https://reviews.llvm.org/D144654

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


[PATCH] D144654: [Lex] Warn when defining or undefining any builtin macro

2023-05-11 Thread John Brawn via Phabricator via cfe-commits
john.brawn updated this revision to Diff 521263.
john.brawn added a comment.

Rebasing now that the patches this depends on have been committed.


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

https://reviews.llvm.org/D144654

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Lex/PPDirectives.cpp
  clang/test/Lexer/builtin_redef.c
  clang/test/Preprocessor/macro-reserved.c
  clang/test/Preprocessor/macro-reserved.cpp

Index: clang/test/Preprocessor/macro-reserved.cpp
===
--- clang/test/Preprocessor/macro-reserved.cpp
+++ clang/test/Preprocessor/macro-reserved.cpp
@@ -12,7 +12,7 @@
 #undef _HAVE_X
 #undef X__Y
 
-#undef __cplusplus
+#undef __cplusplus // expected-warning {{undefining builtin macro}}
 #define __cplusplus
 
 // allowlisted definitions
Index: clang/test/Preprocessor/macro-reserved.c
===
--- clang/test/Preprocessor/macro-reserved.c
+++ clang/test/Preprocessor/macro-reserved.c
@@ -6,6 +6,7 @@
 #define __cplusplus
 #define _HAVE_X 0
 #define X__Y
+#define __STDC__ 1 // expected-warning {{redefining builtin macro}}
 
 #undef for
 #undef final
@@ -13,6 +14,7 @@
 #undef __cplusplus
 #undef _HAVE_X
 #undef X__Y
+#undef __STDC_HOSTED__ // expected-warning {{undefining builtin macro}}
 
 // allowlisted definitions
 #define while while
Index: clang/test/Lexer/builtin_redef.c
===
--- clang/test/Lexer/builtin_redef.c
+++ clang/test/Lexer/builtin_redef.c
@@ -1,12 +1,24 @@
-// RUN: %clang_cc1 %s -D__TIME__=1234 -U__DATE__ -E 2>&1 | FileCheck %s --check-prefix=CHECK-OUT
-// RUN: %clang_cc1 %s -D__TIME__=1234 -U__DATE__ -E 2>&1 | FileCheck %s --check-prefix=CHECK-WARN
-// RUN: not %clang_cc1 %s -D__TIME__=1234 -U__DATE__ -E 2>&1 -pedantic-errors | FileCheck %s --check-prefix=CHECK-ERR
+// RUN: %clang_cc1 %s -D__TIME__=1234 -U__DATE__ -D__STDC__=1 -U__STDC_HOSTED__ -E 2>&1 | FileCheck %s --check-prefix=CHECK-OUT
+// RUN: %clang_cc1 %s -D__TIME__=1234 -U__DATE__ -D__STDC__=1 -U__STDC_HOSTED__ -E 2>&1 | FileCheck %s --check-prefix=CHECK-WARN
+// RUN: not %clang_cc1 %s -D__TIME__=1234 -U__DATE__ -D__STDC__=1 -U__STDC_HOSTED__ -E 2>&1 -pedantic-errors | FileCheck %s --check-prefix=CHECK-ERR
 
 // CHECK-WARN: :{{.*}} warning: redefining builtin macro
+// CHECK-WARN-NEXT: #define __TIME__ 1234
 // CHECK-WARN: :{{.*}} warning: undefining builtin macro
+// CHECK-WARN-NEXT: #undef __DATE__
+// CHECK-WARN: :{{.*}} warning: redefining builtin macro
+// CHECK-WARN-NEXT: #define __STDC__ 1
+// CHECK-WARN: :{{.*}} warning: undefining builtin macro
+// CHECK-WARN-NEXT: #undef __STDC_HOSTED__
 
 // CHECK-ERR: :{{.*}} error: redefining builtin macro
+// CHECK-ERR-NEXT: #define __TIME__ 1234
+// CHECK-ERR: :{{.*}} error: undefining builtin macro
+// CHECK-ERR-NEXT: #undef __DATE__
+// CHECK-ERR: :{{.*}} error: redefining builtin macro
+// CHECK-ERR-NEXT: #define __STDC__ 1
 // CHECK-ERR: :{{.*}} error: undefining builtin macro
+// CHECK-ERR-NEXT: #undef __STDC_HOSTED__
 
 int n = __TIME__;
 __DATE__
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -319,15 +319,6 @@
 return Diag(MacroNameTok, diag::err_defined_macro_name);
   }
 
-  if (isDefineUndef == MU_Undef) {
-auto *MI = getMacroInfo(II);
-if (MI && MI->isBuiltinMacro()) {
-  // Warn if undefining "__LINE__" and other builtins, per C99 6.10.8/4
-  // and C++ [cpp.predefined]p4], but allow it as an extension.
-  Diag(MacroNameTok, diag::ext_pp_undef_builtin_macro);
-}
-  }
-
   // If defining/undefining reserved identifier or a keyword, we need to issue
   // a warning.
   SourceLocation MacroNameLoc = MacroNameTok.getLocation();
@@ -3012,6 +3003,12 @@
   MI->setTokens(Tokens, BP);
   return MI;
 }
+
+static bool isObjCProtectedMacro(const IdentifierInfo *II) {
+  return II->isStr("__strong") || II->isStr("__weak") ||
+ II->isStr("__unsafe_unretained") || II->isStr("__autoreleasing");
+}
+
 /// HandleDefineDirective - Implements \#define.  This consumes the entire macro
 /// line then lets the caller lex the next real token.
 void Preprocessor::HandleDefineDirective(
@@ -3083,15 +3080,9 @@
 // In Objective-C, ignore attempts to directly redefine the builtin
 // definitions of the ownership qualifiers.  It's still possible to
 // #undef them.
-auto isObjCProtectedMacro = [](const IdentifierInfo *II) -> bool {
-  return II->isStr("__strong") ||
- II->isStr("__weak") ||
- II->isStr("__unsafe_unretained") ||
- II->isStr("__autoreleasing");
-};
-   if (getLangOpts().ObjC &&
-SourceMgr.getFileID(OtherMI->getDefinitionLoc())
-  == getPredefinesFileID() &&
+if (getLangOpts().ObjC &&
+

[PATCH] D144651: [Serialization] Place command line defines in the correct file

2023-04-24 Thread John Brawn via Phabricator via cfe-commits
john.brawn added a comment.

I accidentally pushed the old version of this patch in rG524ed4b1ba51 
, I've 
pushed a change to match what was reviewed here in rG78086af43ade 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144651

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


[PATCH] D144651: [Serialization] Place command line defines in the correct file

2023-04-24 Thread John Brawn via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG524ed4b1ba51: [Serialization] Place command line defines in 
the correct file (authored by john.brawn).

Changed prior to commit:
  https://reviews.llvm.org/D144651?vs=511153=516377#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144651

Files:
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang/docs/ReleaseNotes.rst
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/PCH/macro-cmdline.c
  clang/test/PCH/ms-pch-macro.c

Index: clang/test/PCH/ms-pch-macro.c
===
--- clang/test/PCH/ms-pch-macro.c
+++ clang/test/PCH/ms-pch-macro.c
@@ -36,4 +36,4 @@
 // CHECK-FOO: definition of macro 'FOO' differs between the precompiled header ('1') and the command line ('blah')
 // CHECK-NOFOO: macro 'FOO' was defined in the precompiled header but undef'd on the command line
 
-// expected-warning@1 {{definition of macro 'BAR' does not match definition in precompiled header}}
+// expected-warning@2 {{definition of macro 'BAR' does not match definition in precompiled header}}
Index: clang/test/PCH/macro-cmdline.c
===
--- /dev/null
+++ clang/test/PCH/macro-cmdline.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 %s -emit-pch -o %t1.pch -DMACRO1=1
+// RUN: %clang_cc1 -fsyntax-only %s -include-pch %t1.pch -DMACRO2=1 2>&1 | FileCheck %s
+
+#ifndef HEADER
+#define HEADER
+#else
+#define MACRO1 2
+// CHECK: macro-cmdline.c{{.*}}'MACRO1' macro redefined
+// CHECK: {{.*}}previous definition is here
+#define MACRO2 2
+// CHECK: macro-cmdline.c{{.*}}'MACRO2' macro redefined
+// CHECK: {{.*}}previous definition is here
+#endif
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -4441,6 +4441,11 @@
 bool ASTWriter::PreparePathForOutput(SmallVectorImpl ) {
   assert(Context && "should have context when outputting path");
 
+  // Leave special file names as they are.
+  StringRef PathStr(Path.data(), Path.size());
+  if (PathStr == "" || PathStr == "")
+return false;
+
   bool Changed =
   cleanPathForOutput(Context->getSourceManager().getFileManager(), Path);
 
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -654,6 +654,10 @@
   SmallVector ExistingMacroNames;
   collectMacroDefinitions(ExistingPPOpts, ExistingMacros, );
 
+  // Use a line marker to enter the  file, as the defines and
+  // undefines here will have come from the command line.
+  SuggestedPredefines += "# 1 \"\" 1\n";
+
   for (unsigned I = 0, N = ExistingMacroNames.size(); I != N; ++I) {
 // Dig out the macro definition in the existing preprocessor options.
 StringRef MacroName = ExistingMacroNames[I];
@@ -713,6 +717,10 @@
 }
 return true;
   }
+
+  // Leave the  file and return to .
+  SuggestedPredefines += "# 1 \"\" 2\n";
+
   if (Validation == OptionValidateStrictMatches) {
 // If strict matches are requested, don't tolerate any extra defines in
 // the AST file that are missing on the command line.
@@ -1579,8 +1587,13 @@
 auto Buffer = ReadBuffer(SLocEntryCursor, Name);
 if (!Buffer)
   return true;
-SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID,
-   BaseOffset + Offset, IncludeLoc);
+FileID FID = SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID,
+BaseOffset + Offset, IncludeLoc);
+if (Record[3]) {
+  auto  =
+  const_cast(SourceMgr.getSLocEntry(FID).getFile());
+  FileInfo.setHasLineDirectives();
+}
 break;
   }
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -207,8 +207,8 @@
 - Diagnostic notes and fix-its are now generated for ``ifunc``/``alias`` attributes
   which point to functions whose names are mangled.
 - Diagnostics relating to macros on the command line of a preprocessed assembly
-  file are now reported as coming from the file  instead of
-  .
+  file or precompiled header are now reported as coming from the file
+   instead of .
 - Clang constexpr evaluator now provides a more concise diagnostic when calling
   function pointer that is known to be null.
 - Clang now avoids duplicate warnings on unreachable ``[[fallthrough]];`` statements
Index: clang-tools-extra/clangd/index/SymbolCollector.cpp

[PATCH] D144651: [Serialization] Place command line defines in the correct file

2023-04-21 Thread John Brawn via Phabricator via cfe-commits
john.brawn added a comment.

Ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144651

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


[PATCH] D144651: [Serialization] Place command line defines in the correct file

2023-04-05 Thread John Brawn via Phabricator via cfe-commits
john.brawn updated this revision to Diff 511153.
john.brawn edited the summary of this revision.
john.brawn added a comment.

New version that checks for special filenames in ResolveImportedPath. I spent a 
while trying to come up with a test using just clang where not doing this 
fails, but couldn't as it looks like the failure is specific to objective-c 
module handing in lldb.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144651

Files:
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang/docs/ReleaseNotes.rst
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/PCH/macro-cmdline.c
  clang/test/PCH/ms-pch-macro.c

Index: clang/test/PCH/ms-pch-macro.c
===
--- clang/test/PCH/ms-pch-macro.c
+++ clang/test/PCH/ms-pch-macro.c
@@ -36,4 +36,4 @@
 // CHECK-FOO: definition of macro 'FOO' differs between the precompiled header ('1') and the command line ('blah')
 // CHECK-NOFOO: macro 'FOO' was defined in the precompiled header but undef'd on the command line
 
-// expected-warning@1 {{definition of macro 'BAR' does not match definition in precompiled header}}
+// expected-warning@2 {{definition of macro 'BAR' does not match definition in precompiled header}}
Index: clang/test/PCH/macro-cmdline.c
===
--- /dev/null
+++ clang/test/PCH/macro-cmdline.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 %s -emit-pch -o %t1.pch -DMACRO1=1
+// RUN: %clang_cc1 -fsyntax-only %s -include-pch %t1.pch -DMACRO2=1 2>&1 | FileCheck %s
+
+#ifndef HEADER
+#define HEADER
+#else
+#define MACRO1 2
+// CHECK: macro-cmdline.c{{.*}}'MACRO1' macro redefined
+// CHECK: {{.*}}previous definition is here
+#define MACRO2 2
+// CHECK: macro-cmdline.c{{.*}}'MACRO2' macro redefined
+// CHECK: {{.*}}previous definition is here
+#endif
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -,6 +,11 @@
 bool ASTWriter::PreparePathForOutput(SmallVectorImpl ) {
   assert(Context && "should have context when outputting path");
 
+  // Leave special file names as they are.
+  StringRef PathStr(Path.data(), Path.size());
+  if (PathStr == "" || PathStr == "")
+return false;
+
   bool Changed =
   cleanPathForOutput(Context->getSourceManager().getFileManager(), Path);
 
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -654,6 +654,10 @@
   SmallVector ExistingMacroNames;
   collectMacroDefinitions(ExistingPPOpts, ExistingMacros, );
 
+  // Use a line marker to enter the  file, as the defines and
+  // undefines here will have come from the command line.
+  SuggestedPredefines += "# 1 \"\" 1\n";
+
   for (unsigned I = 0, N = ExistingMacroNames.size(); I != N; ++I) {
 // Dig out the macro definition in the existing preprocessor options.
 StringRef MacroName = ExistingMacroNames[I];
@@ -713,6 +717,10 @@
 }
 return true;
   }
+
+  // Leave the  file and return to .
+  SuggestedPredefines += "# 1 \"\" 2\n";
+
   if (Validation == OptionValidateStrictMatches) {
 // If strict matches are requested, don't tolerate any extra defines in
 // the AST file that are missing on the command line.
@@ -1579,8 +1587,13 @@
 auto Buffer = ReadBuffer(SLocEntryCursor, Name);
 if (!Buffer)
   return true;
-SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID,
-   BaseOffset + Offset, IncludeLoc);
+FileID FID = SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID,
+BaseOffset + Offset, IncludeLoc);
+if (Record[3]) {
+  auto  =
+  const_cast(SourceMgr.getSLocEntry(FID).getFile());
+  FileInfo.setHasLineDirectives();
+}
 break;
   }
 
@@ -2510,7 +2523,8 @@
 }
 
 void ASTReader::ResolveImportedPath(std::string , StringRef Prefix) {
-  if (Filename.empty() || llvm::sys::path::is_absolute(Filename))
+  if (Filename.empty() || llvm::sys::path::is_absolute(Filename) ||
+  Filename == "" || Filename == "")
 return;
 
   SmallString<128> Buffer;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -198,8 +198,8 @@
 - Diagnostic notes and fix-its are now generated for ``ifunc``/``alias`` attributes
   which point to functions whose names are mangled.
 - Diagnostics relating to macros on the command line of a preprocessed assembly
-  file are now reported as coming from the file  instead of
-  .
+  file or precompiled header are now reported as coming from 

[PATCH] D144651: [Serialization] Place command line defines in the correct file

2023-03-23 Thread John Brawn via Phabricator via cfe-commits
john.brawn added a comment.

Unfortunately I still can't reproduce this even using exactly the same cmake 
command as you gave. Looking at above cmake log some possible causes of 
difference are:

- I'm doing this on an M1  macbook with host 
triple arm64-apple-darwin21.6.0 but the host triple on that bot is 
x86_64-apple-darwin20.6.0
- I'm using python 3.9, bot is using python 3.10
- I'm doing a build from clean whereas the bot is doing an incremental build

Also if I try to run the simpler reproducer you give then I get the error

  error: expression failed to parse:
  error: Header search couldn't locate module Cocoa

I'm now on holiday, I won't be able to get back to this until 2023-04-03.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144651

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


[PATCH] D144651: [Serialization] Place command line defines in the correct file

2023-03-22 Thread John Brawn via Phabricator via cfe-commits
john.brawn added a comment.

In D144651#4210787 , @fdeazeve wrote:

> According to git-bisect, this patch is causing the LLDB bots to crash.
> https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/52690/console
>
> (They were failing for other reasons before, which is why it took a while for 
> this to be identified)
>
> Clang is crashing with: `Assertion failed: (0 && "Invalid SLocOffset or bad 
> function choice"`
>
> In particular, this is true for the test `lldb-api :: 
> commands/expression/import_builtin_fileid/TestImportBuiltinFileID.py`
> I'm currently investigating the other failures reported by the bot, but we've 
> also seen this assert fire internally in some other flows.

It looks like green.lab.llvm.org is down, so can't look at that log, but doing 
a local build and test of lldb (on a macbook, as this test is only enabled on 
macos) I don't see this failure, or any other tests failing with this assertion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144651

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


[PATCH] D144651: [Serialization] Place command line defines in the correct file

2023-03-20 Thread John Brawn via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG72073fc95cd4: [Serialization] Place command line defines in 
the correct file (authored by john.brawn).

Changed prior to commit:
  https://reviews.llvm.org/D144651?vs=502977=506642#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144651

Files:
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang/docs/ReleaseNotes.rst
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/PCH/macro-cmdline.c
  clang/test/PCH/ms-pch-macro.c

Index: clang/test/PCH/ms-pch-macro.c
===
--- clang/test/PCH/ms-pch-macro.c
+++ clang/test/PCH/ms-pch-macro.c
@@ -36,4 +36,4 @@
 // CHECK-FOO: definition of macro 'FOO' differs between the precompiled header ('1') and the command line ('blah')
 // CHECK-NOFOO: macro 'FOO' was defined in the precompiled header but undef'd on the command line
 
-// expected-warning@1 {{definition of macro 'BAR' does not match definition in precompiled header}}
+// expected-warning@2 {{definition of macro 'BAR' does not match definition in precompiled header}}
Index: clang/test/PCH/macro-cmdline.c
===
--- /dev/null
+++ clang/test/PCH/macro-cmdline.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 %s -emit-pch -o %t1.pch -DMACRO1=1
+// RUN: %clang_cc1 -fsyntax-only %s -include-pch %t1.pch -DMACRO2=1 2>&1 | FileCheck %s
+
+#ifndef HEADER
+#define HEADER
+#else
+#define MACRO1 2
+// CHECK: macro-cmdline.c{{.*}}'MACRO1' macro redefined
+// CHECK: {{.*}}previous definition is here
+#define MACRO2 2
+// CHECK: macro-cmdline.c{{.*}}'MACRO2' macro redefined
+// CHECK: {{.*}}previous definition is here
+#endif
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -,6 +,11 @@
 bool ASTWriter::PreparePathForOutput(SmallVectorImpl ) {
   assert(Context && "should have context when outputting path");
 
+  // Leave special file names as they are.
+  StringRef PathStr(Path.data(), Path.size());
+  if (PathStr == "" || PathStr == "")
+return false;
+
   bool Changed =
   cleanPathForOutput(Context->getSourceManager().getFileManager(), Path);
 
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -654,6 +654,10 @@
   SmallVector ExistingMacroNames;
   collectMacroDefinitions(ExistingPPOpts, ExistingMacros, );
 
+  // Use a line marker to enter the  file, as the defines and
+  // undefines here will have come from the command line.
+  SuggestedPredefines += "# 1 \"\" 1\n";
+
   for (unsigned I = 0, N = ExistingMacroNames.size(); I != N; ++I) {
 // Dig out the macro definition in the existing preprocessor options.
 StringRef MacroName = ExistingMacroNames[I];
@@ -713,6 +717,10 @@
 }
 return true;
   }
+
+  // Leave the  file and return to .
+  SuggestedPredefines += "# 1 \"\" 2\n";
+
   if (Validation == OptionValidateStrictMatches) {
 // If strict matches are requested, don't tolerate any extra defines in
 // the AST file that are missing on the command line.
@@ -1579,8 +1587,13 @@
 auto Buffer = ReadBuffer(SLocEntryCursor, Name);
 if (!Buffer)
   return true;
-SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID,
-   BaseOffset + Offset, IncludeLoc);
+FileID FID = SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID,
+BaseOffset + Offset, IncludeLoc);
+if (Record[3]) {
+  auto  =
+  const_cast(SourceMgr.getSLocEntry(FID).getFile());
+  FileInfo.setHasLineDirectives();
+}
 break;
   }
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -172,8 +172,8 @@
 - Diagnostic notes and fix-its are now generated for ``ifunc``/``alias`` attributes
   which point to functions whose names are mangled.
 - Diagnostics relating to macros on the command line of a preprocessed assembly
-  file are now reported as coming from the file  instead of
-  .
+  file or precompiled header are now reported as coming from the file
+   instead of .
 - Clang constexpr evaluator now provides a more concise diagnostic when calling
   function pointer that is known to be null.
 - Clang now avoids duplicate warnings on unreachable ``[[fallthrough]];`` statements
Index: clang-tools-extra/clangd/index/SymbolCollector.cpp
===
--- 

[PATCH] D145563: [AArch64] Assembly Support for FEAT_GCS/FEAT_CHK

2023-03-14 Thread John Brawn via Phabricator via cfe-commits
john.brawn accepted this revision.
john.brawn added a comment.
This revision is now accepted and ready to land.

LGTM, with one minor nitpick.




Comment at: llvm/lib/Target/AArch64/AArch64InstrInfo.td:1106
+
+def : TokenAlias<"DSYNC", "dsync">;
+

It would make more sense to put this immediately after GCSB_DSYNC.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145563

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


[PATCH] D144651: [Serialization] Place command line defines in the correct file

2023-03-14 Thread John Brawn via Phabricator via cfe-commits
john.brawn added a comment.

Ping.


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

https://reviews.llvm.org/D144651

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


[PATCH] D144654: [Lex] Warn when defining or undefining any builtin macro

2023-03-13 Thread John Brawn via Phabricator via cfe-commits
john.brawn added inline comments.



Comment at: clang/lib/Lex/PPDirectives.cpp:3189-3192
+if ((MI->isBuiltinMacro() ||
+ SourceMgr.isWrittenInBuiltinFile(MI->getDefinitionLoc())) &&
+!(getLangOpts().ObjC && isObjCProtectedMacro(II)))
+  Diag(MacroNameTok, diag::ext_pp_undef_builtin_macro);

aaron.ballman wrote:
> Should this diagnostic be suppressed in a system header on the assumption 
> that system headers are part of the implementation and thus free to 
> undefine/redefine macros at will?
It's already suppressed. ShowInSystemHeader in the Diagnostic tablegen class 
determines if a diagnostic is shown when it happens in a system header, and 
it's false by default for warnings.


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

https://reviews.llvm.org/D144654

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


[PATCH] D144654: [Lex] Warn when defining or undefining any builtin macro

2023-03-09 Thread John Brawn via Phabricator via cfe-commits
john.brawn added a comment.

D145691  should fix the libc++ CI failures.


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

https://reviews.llvm.org/D144654

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


[PATCH] D144654: [Lex] Warn when defining or undefining any builtin macro

2023-03-08 Thread John Brawn via Phabricator via cfe-commits
john.brawn updated this revision to Diff 503305.
john.brawn added a comment.

Add command line test and release note, and run clang-format.


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

https://reviews.llvm.org/D144654

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Lex/PPDirectives.cpp
  clang/test/Lexer/builtin_redef.c
  clang/test/Preprocessor/macro-reserved.c
  clang/test/Preprocessor/macro-reserved.cpp

Index: clang/test/Preprocessor/macro-reserved.cpp
===
--- clang/test/Preprocessor/macro-reserved.cpp
+++ clang/test/Preprocessor/macro-reserved.cpp
@@ -12,7 +12,7 @@
 #undef _HAVE_X
 #undef X__Y
 
-#undef __cplusplus
+#undef __cplusplus // expected-warning {{undefining builtin macro}}
 #define __cplusplus
 
 // allowlisted definitions
Index: clang/test/Preprocessor/macro-reserved.c
===
--- clang/test/Preprocessor/macro-reserved.c
+++ clang/test/Preprocessor/macro-reserved.c
@@ -6,6 +6,7 @@
 #define __cplusplus
 #define _HAVE_X 0
 #define X__Y
+#define __STDC__ 1 // expected-warning {{redefining builtin macro}}
 
 #undef for
 #undef final
@@ -13,6 +14,7 @@
 #undef __cplusplus
 #undef _HAVE_X
 #undef X__Y
+#undef __STDC_HOSTED__ // expected-warning {{undefining builtin macro}}
 
 // allowlisted definitions
 #define while while
Index: clang/test/Lexer/builtin_redef.c
===
--- clang/test/Lexer/builtin_redef.c
+++ clang/test/Lexer/builtin_redef.c
@@ -1,12 +1,24 @@
-// RUN: %clang_cc1 %s -D__TIME__=1234 -U__DATE__ -E 2>&1 | FileCheck %s --check-prefix=CHECK-OUT
-// RUN: %clang_cc1 %s -D__TIME__=1234 -U__DATE__ -E 2>&1 | FileCheck %s --check-prefix=CHECK-WARN
-// RUN: not %clang_cc1 %s -D__TIME__=1234 -U__DATE__ -E 2>&1 -pedantic-errors | FileCheck %s --check-prefix=CHECK-ERR
+// RUN: %clang_cc1 %s -D__TIME__=1234 -U__DATE__ -D__STDC__=1 -U__STDC_HOSTED__ -E 2>&1 | FileCheck %s --check-prefix=CHECK-OUT
+// RUN: %clang_cc1 %s -D__TIME__=1234 -U__DATE__ -D__STDC__=1 -U__STDC_HOSTED__ -E 2>&1 | FileCheck %s --check-prefix=CHECK-WARN
+// RUN: not %clang_cc1 %s -D__TIME__=1234 -U__DATE__ -D__STDC__=1 -U__STDC_HOSTED__ -E 2>&1 -pedantic-errors | FileCheck %s --check-prefix=CHECK-ERR
 
 // CHECK-WARN: :{{.*}} warning: redefining builtin macro
+// CHECK-WARN-NEXT: #define __TIME__ 1234
 // CHECK-WARN: :{{.*}} warning: undefining builtin macro
+// CHECK-WARN-NEXT: #undef __DATE__
+// CHECK-WARN: :{{.*}} warning: redefining builtin macro
+// CHECK-WARN-NEXT: #define __STDC__ 1
+// CHECK-WARN: :{{.*}} warning: undefining builtin macro
+// CHECK-WARN-NEXT: #undef __STDC_HOSTED__
 
 // CHECK-ERR: :{{.*}} error: redefining builtin macro
+// CHECK-ERR-NEXT: #define __TIME__ 1234
+// CHECK-ERR: :{{.*}} error: undefining builtin macro
+// CHECK-ERR-NEXT: #undef __DATE__
+// CHECK-ERR: :{{.*}} error: redefining builtin macro
+// CHECK-ERR-NEXT: #define __STDC__ 1
 // CHECK-ERR: :{{.*}} error: undefining builtin macro
+// CHECK-ERR-NEXT: #undef __STDC_HOSTED__
 
 int n = __TIME__;
 __DATE__
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -319,15 +319,6 @@
 return Diag(MacroNameTok, diag::err_defined_macro_name);
   }
 
-  if (isDefineUndef == MU_Undef) {
-auto *MI = getMacroInfo(II);
-if (MI && MI->isBuiltinMacro()) {
-  // Warn if undefining "__LINE__" and other builtins, per C99 6.10.8/4
-  // and C++ [cpp.predefined]p4], but allow it as an extension.
-  Diag(MacroNameTok, diag::ext_pp_undef_builtin_macro);
-}
-  }
-
   // If defining/undefining reserved identifier or a keyword, we need to issue
   // a warning.
   SourceLocation MacroNameLoc = MacroNameTok.getLocation();
@@ -3008,6 +2999,12 @@
   MI->setTokens(Tokens, BP);
   return MI;
 }
+
+static bool isObjCProtectedMacro(const IdentifierInfo *II) {
+  return II->isStr("__strong") || II->isStr("__weak") ||
+ II->isStr("__unsafe_unretained") || II->isStr("__autoreleasing");
+}
+
 /// HandleDefineDirective - Implements \#define.  This consumes the entire macro
 /// line then lets the caller lex the next real token.
 void Preprocessor::HandleDefineDirective(
@@ -3079,15 +3076,9 @@
 // In Objective-C, ignore attempts to directly redefine the builtin
 // definitions of the ownership qualifiers.  It's still possible to
 // #undef them.
-auto isObjCProtectedMacro = [](const IdentifierInfo *II) -> bool {
-  return II->isStr("__strong") ||
- II->isStr("__weak") ||
- II->isStr("__unsafe_unretained") ||
- II->isStr("__autoreleasing");
-};
-   if (getLangOpts().ObjC &&
-SourceMgr.getFileID(OtherMI->getDefinitionLoc())
-  == getPredefinesFileID() &&
+if (getLangOpts().ObjC &&
+

[PATCH] D145397: [Lex] Use line markers in preprocessed assembly predefines file

2023-03-07 Thread John Brawn via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG128f7dac82ea: [Lex] Use line markers in preprocessed 
assembly predefines file (authored by john.brawn).

Changed prior to commit:
  https://reviews.llvm.org/D145397?vs=502680=503058#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145397

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Lex/PPDirectives.cpp
  clang/test/Preprocessor/directives_asm.S
  clang/test/Preprocessor/macro_redefined.S

Index: clang/test/Preprocessor/macro_redefined.S
===
--- /dev/null
+++ clang/test/Preprocessor/macro_redefined.S
@@ -0,0 +1,10 @@
+// RUN: %clang %s -E -DCLI_MACRO=1 2>&1 | FileCheck %s
+
+#define CLI_MACRO
+// CHECK: macro_redefined.S{{.+}}: warning: 'CLI_MACRO' macro redefined
+// CHECK: {{.+}}: note: previous definition is here
+
+#define REGULAR_MACRO
+#define REGULAR_MACRO 1
+// CHECK: macro_redefined.S{{.+}}: warning: 'REGULAR_MACRO' macro redefined
+// CHECK: macro_redefined.S{{.+}}: note: previous definition is here
Index: clang/test/Preprocessor/directives_asm.S
===
--- /dev/null
+++ clang/test/Preprocessor/directives_asm.S
@@ -0,0 +1,25 @@
+// RUN: %clang -c %s -o /dev/null 2>&1 | FileCheck %s
+
+// Check that preprocessor directives are recognised as such, but lines starting
+// with a # that aren't directives are instead treated as comments.
+
+#define MACRO .warning "This is a macro"
+MACRO
+
+// CHECK: directives_asm.S:7:9: warning: This is a macro
+
+#not a preprocessing directive
+
+// CHECK-NOT: error: invalid preprocessing directive
+
+# 100
+
+.warning "line number should not change"
+
+// CHECK: directives_asm.S:17:9: warning: line number should not change
+
+#line 100
+
+.warning "line number should change"
+
+// CHECK: directives_asm.S:101:9: warning: line number should change
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -1185,8 +1185,12 @@
 CurPPLexer->getConditionalStackDepth() > 0);
 return;
   case tok::numeric_constant:  // # 7  GNU line marker directive.
-if (getLangOpts().AsmPreprocessor)
-  break;  // # 4 is not a preprocessor directive in .S files.
+// In a .S file "# 4" may be a comment so don't treat it as a preprocessor
+// directive. However do permit it in the predefines file, as we use line
+// markers to mark the builtin macros as being in a system header.
+if (getLangOpts().AsmPreprocessor &&
+SourceMgr.getFileID(SavedHash.getLocation()) != getPredefinesFileID())
+  break;
 return HandleDigitDirective(Result);
   default:
 IdentifierInfo *II = Result.getIdentifierInfo();
Index: clang/lib/Frontend/InitPreprocessor.cpp
===
--- clang/lib/Frontend/InitPreprocessor.cpp
+++ clang/lib/Frontend/InitPreprocessor.cpp
@@ -1317,11 +1317,10 @@
   llvm::raw_string_ostream Predefines(PredefineBuffer);
   MacroBuilder Builder(Predefines);
 
-  // Emit line markers for various builtin sections of the file.  We don't do
-  // this in asm preprocessor mode, because "# 4" is not a line marker directive
-  // in this mode.
-  if (!PP.getLangOpts().AsmPreprocessor)
-Builder.append("# 1 \"\" 3");
+  // Emit line markers for various builtin sections of the file. The 3 here
+  // marks  as being a system header, which suppresses warnings when
+  // the same macro is defined multiple times.
+  Builder.append("# 1 \"\" 3");
 
   // Install things like __POWERPC__, __GNUC__, etc into the macro table.
   if (InitOpts.UsePredefines) {
@@ -1359,8 +1358,7 @@
 
   // Add on the predefines from the driver.  Wrap in a #line directive to report
   // that they come from the command line.
-  if (!PP.getLangOpts().AsmPreprocessor)
-Builder.append("# 1 \"\" 1");
+  Builder.append("# 1 \"\" 1");
 
   // Process #define's and #undef's in the order they are given.
   for (unsigned i = 0, e = InitOpts.Macros.size(); i != e; ++i) {
@@ -1372,8 +1370,7 @@
   }
 
   // Exit the command line and go back to  (2 is LC_LEAVE).
-  if (!PP.getLangOpts().AsmPreprocessor)
-Builder.append("# 1 \"\" 2");
+  Builder.append("# 1 \"\" 2");
 
   // If -imacros are specified, include them now.  These are processed before
   // any -include directives.
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -159,6 +159,9 @@
   class if that class was first introduced with a forward declaration.
 - Diagnostic notes and fix-its are now generated for ``ifunc``/``alias`` 

[PATCH] D144651: [Serialization] Place command line defines in the correct file

2023-03-07 Thread John Brawn via Phabricator via cfe-commits
john.brawn updated this revision to Diff 502977.
john.brawn added a comment.

Ran clang-format.


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

https://reviews.llvm.org/D144651

Files:
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/PCH/macro-cmdline.c
  clang/test/PCH/ms-pch-macro.c

Index: clang/test/PCH/ms-pch-macro.c
===
--- clang/test/PCH/ms-pch-macro.c
+++ clang/test/PCH/ms-pch-macro.c
@@ -36,4 +36,4 @@
 // CHECK-FOO: definition of macro 'FOO' differs between the precompiled header ('1') and the command line ('blah')
 // CHECK-NOFOO: macro 'FOO' was defined in the precompiled header but undef'd on the command line
 
-// expected-warning@1 {{definition of macro 'BAR' does not match definition in precompiled header}}
+// expected-warning@2 {{definition of macro 'BAR' does not match definition in precompiled header}}
Index: clang/test/PCH/macro-cmdline.c
===
--- /dev/null
+++ clang/test/PCH/macro-cmdline.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 %s -emit-pch -o %t1.pch -DMACRO1=1
+// RUN: %clang_cc1 -fsyntax-only %s -include-pch %t1.pch -DMACRO2=1 2>&1 | FileCheck %s
+
+#ifndef HEADER
+#define HEADER
+#else
+#define MACRO1 2
+// CHECK: macro-cmdline.c{{.*}}'MACRO1' macro redefined
+// CHECK: {{.*}}previous definition is here
+#define MACRO2 2
+// CHECK: macro-cmdline.c{{.*}}'MACRO2' macro redefined
+// CHECK: {{.*}}previous definition is here
+#endif
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -,6 +,11 @@
 bool ASTWriter::PreparePathForOutput(SmallVectorImpl ) {
   assert(Context && "should have context when outputting path");
 
+  // Leave special file names as they are.
+  StringRef PathStr(Path.data(), Path.size());
+  if (PathStr == "" || PathStr == "")
+return false;
+
   bool Changed =
   cleanPathForOutput(Context->getSourceManager().getFileManager(), Path);
 
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -654,6 +654,10 @@
   SmallVector ExistingMacroNames;
   collectMacroDefinitions(ExistingPPOpts, ExistingMacros, );
 
+  // Use a line marker to enter the  file, as the defines and
+  // undefines here will have come from the command line.
+  SuggestedPredefines += "# 1 \"\" 1\n";
+
   for (unsigned I = 0, N = ExistingMacroNames.size(); I != N; ++I) {
 // Dig out the macro definition in the existing preprocessor options.
 StringRef MacroName = ExistingMacroNames[I];
@@ -713,6 +717,10 @@
 }
 return true;
   }
+
+  // Leave the  file and return to .
+  SuggestedPredefines += "# 1 \"\" 2\n";
+
   if (Validation == OptionValidateStrictMatches) {
 // If strict matches are requested, don't tolerate any extra defines in
 // the AST file that are missing on the command line.
@@ -1579,8 +1587,13 @@
 auto Buffer = ReadBuffer(SLocEntryCursor, Name);
 if (!Buffer)
   return true;
-SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID,
-   BaseOffset + Offset, IncludeLoc);
+FileID FID = SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID,
+BaseOffset + Offset, IncludeLoc);
+if (Record[3]) {
+  SrcMgr::FileInfo  =
+  const_cast(SourceMgr.getSLocEntry(FID).getFile());
+  FileInfo.setHasLineDirectives();
+}
 break;
   }
 
Index: clang-tools-extra/clangd/index/SymbolCollector.cpp
===
--- clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -687,8 +687,10 @@
 
   const auto  = PP->getSourceManager();
   auto DefLoc = MI->getDefinitionLoc();
-  // Also avoid storing predefined macros like __DBL_MIN__.
+  // Also avoid storing macros that aren't defined in any file, i.e. predefined
+  // macros like __DBL_MIN__ and those defined on the command line.
   if (SM.isWrittenInBuiltinFile(DefLoc) ||
+  SM.isWrittenInCommandLineFile(DefLoc) ||
   Name->getName() == "__GCC_HAVE_DWARF2_CFI_ASM")
 return true;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144654: [Lex] Warn when defining or undefining any builtin macro

2023-03-06 Thread John Brawn via Phabricator via cfe-commits
john.brawn added a comment.

In D144654#4156430 , @aaron.ballman 
wrote:

> This seems to cause precommit CI failures that should be addressed, and it 
> should also have a release note about the fix.

Failures in CI should be fixed by D145397  
and D144651 . I'll also add a release note.

> Also, should this cover things like `clang -U__cplusplus -D__STDC__=1 
> foo.cpp` as well?

Yes, and I'll add tests for this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144654

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


[PATCH] D144651: [Serialization] Place command line defines in the correct file

2023-03-06 Thread John Brawn via Phabricator via cfe-commits
john.brawn updated this revision to Diff 502683.
john.brawn edited the summary of this revision.
john.brawn added a comment.
Herald added subscribers: kadircet, arphaman, ilya-biryukov.
Herald added a project: clang-tools-extra.

Fixed a couple of things causing failures in clangd tests (path being prepended 
in front of , and a bit of code assuming that command-line macros 
were builtin).


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

https://reviews.llvm.org/D144651

Files:
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/PCH/macro-cmdline.c
  clang/test/PCH/ms-pch-macro.c

Index: clang/test/PCH/ms-pch-macro.c
===
--- clang/test/PCH/ms-pch-macro.c
+++ clang/test/PCH/ms-pch-macro.c
@@ -36,4 +36,4 @@
 // CHECK-FOO: definition of macro 'FOO' differs between the precompiled header ('1') and the command line ('blah')
 // CHECK-NOFOO: macro 'FOO' was defined in the precompiled header but undef'd on the command line
 
-// expected-warning@1 {{definition of macro 'BAR' does not match definition in precompiled header}}
+// expected-warning@2 {{definition of macro 'BAR' does not match definition in precompiled header}}
Index: clang/test/PCH/macro-cmdline.c
===
--- /dev/null
+++ clang/test/PCH/macro-cmdline.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 %s -emit-pch -o %t1.pch -DMACRO1=1
+// RUN: %clang_cc1 -fsyntax-only %s -include-pch %t1.pch -DMACRO2=1 2>&1 | FileCheck %s
+
+#ifndef HEADER
+#define HEADER
+#else
+#define MACRO1 2
+// CHECK: macro-cmdline.c{{.*}}'MACRO1' macro redefined
+// CHECK: {{.*}}previous definition is here
+#define MACRO2 2
+// CHECK: macro-cmdline.c{{.*}}'MACRO2' macro redefined
+// CHECK: {{.*}}previous definition is here
+#endif
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -,6 +,11 @@
 bool ASTWriter::PreparePathForOutput(SmallVectorImpl ) {
   assert(Context && "should have context when outputting path");
 
+  // Leave special file names as they are.
+  StringRef PathStr(Path.data(), Path.size());
+  if (PathStr == "" || PathStr == "")
+return false;
+
   bool Changed =
   cleanPathForOutput(Context->getSourceManager().getFileManager(), Path);
 
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -654,6 +654,10 @@
   SmallVector ExistingMacroNames;
   collectMacroDefinitions(ExistingPPOpts, ExistingMacros, );
 
+  // Use a line marker to enter the  file, as the defines and
+  // undefines here will have come from the command line.
+  SuggestedPredefines += "# 1 \"\" 1\n";
+
   for (unsigned I = 0, N = ExistingMacroNames.size(); I != N; ++I) {
 // Dig out the macro definition in the existing preprocessor options.
 StringRef MacroName = ExistingMacroNames[I];
@@ -713,6 +717,10 @@
 }
 return true;
   }
+
+  // Leave the  file and return to .
+  SuggestedPredefines += "# 1 \"\" 2\n";
+
   if (Validation == OptionValidateStrictMatches) {
 // If strict matches are requested, don't tolerate any extra defines in
 // the AST file that are missing on the command line.
@@ -1579,8 +1587,13 @@
 auto Buffer = ReadBuffer(SLocEntryCursor, Name);
 if (!Buffer)
   return true;
-SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID,
-   BaseOffset + Offset, IncludeLoc);
+FileID FID = SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID,
+BaseOffset + Offset, IncludeLoc);
+if (Record[3]) {
+  SrcMgr::FileInfo  =
+const_cast(SourceMgr.getSLocEntry(FID).getFile());
+  FileInfo.setHasLineDirectives();
+}
 break;
   }
 
Index: clang-tools-extra/clangd/index/SymbolCollector.cpp
===
--- clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -687,8 +687,10 @@
 
   const auto  = PP->getSourceManager();
   auto DefLoc = MI->getDefinitionLoc();
-  // Also avoid storing predefined macros like __DBL_MIN__.
+  // Also avoid storing macros that aren't defined in any file, i.e. predefined
+  // macros like __DBL_MIN__ and those defined on the command line.
   if (SM.isWrittenInBuiltinFile(DefLoc) ||
+  SM.isWrittenInCommandLineFile(DefLoc) ||
   Name->getName() == "__GCC_HAVE_DWARF2_CFI_ASM")
 return true;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145397: [Lex] Use line markers in preprocessed assembly predefines file

2023-03-06 Thread John Brawn via Phabricator via cfe-commits
john.brawn created this revision.
john.brawn added reviewers: aaron.ballman, rsmith, jansvoboda11, rjmccall.
Herald added a project: All.
john.brawn requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

GNU line marker directives are not recognised when preprocessing assembly 
files, meaning they can't be used in the predefines file meaning macros defined 
on the command line are reported as being built-in.

Change this to permit line markers but only in the predefines file, so we can 
correctly report command line macros as coming from the command line.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145397

Files:
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Lex/PPDirectives.cpp
  clang/test/Preprocessor/directives_asm.S
  clang/test/Preprocessor/macro_redefined.S

Index: clang/test/Preprocessor/macro_redefined.S
===
--- /dev/null
+++ clang/test/Preprocessor/macro_redefined.S
@@ -0,0 +1,10 @@
+// RUN: %clang %s -E -DCLI_MACRO=1 2>&1 | FileCheck %s
+
+#define CLI_MACRO
+// CHECK: macro_redefined.S{{.+}}: warning: 'CLI_MACRO' macro redefined
+// CHECK: {{.+}}: note: previous definition is here
+
+#define REGULAR_MACRO
+#define REGULAR_MACRO 1
+// CHECK: macro_redefined.S{{.+}}: warning: 'REGULAR_MACRO' macro redefined
+// CHECK: macro_redefined.S{{.+}}: note: previous definition is here
Index: clang/test/Preprocessor/directives_asm.S
===
--- /dev/null
+++ clang/test/Preprocessor/directives_asm.S
@@ -0,0 +1,25 @@
+// RUN: %clang -c %s -o /dev/null 2>&1 | FileCheck %s
+
+// Check that preprocessor directives are recognised as such, but lines starting
+// with a # that aren't directives are instead treated as comments.
+
+#define MACRO .warning "This is a macro"
+MACRO
+
+// CHECK: directives_asm.S:7:9: warning: This is a macro
+
+#not a preprocessing directive
+
+// CHECK-NOT: error: invalid preprocessing directive
+
+# 100
+
+.warning "line number should not change"
+
+// CHECK: directives_asm.S:17:9: warning: line number should not change
+
+#line 100
+
+.warning "line number should change"
+
+// CHECK: directives_asm.S:101:9: warning: line number should change
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -1185,8 +1185,12 @@
 CurPPLexer->getConditionalStackDepth() > 0);
 return;
   case tok::numeric_constant:  // # 7  GNU line marker directive.
-if (getLangOpts().AsmPreprocessor)
-  break;  // # 4 is not a preprocessor directive in .S files.
+// In a .S file "# 4" may be a comment so don't treat it as a preprocessor
+// directive. However do permit it in the predefines file, as we use line
+// markers to mark the builtin macros as being in a system header.
+if (getLangOpts().AsmPreprocessor &&
+SourceMgr.getFileID(SavedHash.getLocation()) != getPredefinesFileID())
+  break;
 return HandleDigitDirective(Result);
   default:
 IdentifierInfo *II = Result.getIdentifierInfo();
Index: clang/lib/Frontend/InitPreprocessor.cpp
===
--- clang/lib/Frontend/InitPreprocessor.cpp
+++ clang/lib/Frontend/InitPreprocessor.cpp
@@ -1317,11 +1317,10 @@
   llvm::raw_string_ostream Predefines(PredefineBuffer);
   MacroBuilder Builder(Predefines);
 
-  // Emit line markers for various builtin sections of the file.  We don't do
-  // this in asm preprocessor mode, because "# 4" is not a line marker directive
-  // in this mode.
-  if (!PP.getLangOpts().AsmPreprocessor)
-Builder.append("# 1 \"\" 3");
+  // Emit line markers for various builtin sections of the file. The 3 here
+  // marks  as being a system header, which suppresses warnings when
+  // the same macro is defined multiple times.
+  Builder.append("# 1 \"\" 3");
 
   // Install things like __POWERPC__, __GNUC__, etc into the macro table.
   if (InitOpts.UsePredefines) {
@@ -1359,8 +1358,7 @@
 
   // Add on the predefines from the driver.  Wrap in a #line directive to report
   // that they come from the command line.
-  if (!PP.getLangOpts().AsmPreprocessor)
-Builder.append("# 1 \"\" 1");
+  Builder.append("# 1 \"\" 1");
 
   // Process #define's and #undef's in the order they are given.
   for (unsigned i = 0, e = InitOpts.Macros.size(); i != e; ++i) {
@@ -1372,8 +1370,7 @@
   }
 
   // Exit the command line and go back to  (2 is LC_LEAVE).
-  if (!PP.getLangOpts().AsmPreprocessor)
-Builder.append("# 1 \"\" 2");
+  Builder.append("# 1 \"\" 2");
 
   // If -imacros are specified, include them now.  These are processed before
   // any -include directives.
___
cfe-commits mailing list

[PATCH] D144654: [Lex] Warn when defining or undefining any builtin macro

2023-02-23 Thread John Brawn via Phabricator via cfe-commits
john.brawn created this revision.
john.brawn added reviewers: rsmith, jansvoboda11, rjmccall.
Herald added a project: All.
john.brawn requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Currently we warn when MI->isBuiltinMacro, but this is only true for builtin 
macros that require processing when expanding. Checking 
SourceMgr.isWrittenInBuiltinFile in addition to this will mean that we catch 
all builtin macros.

As part of doing this I've also moved the handling of undefining from 
CheckMacroName to HandleUndefDirective, as it doesn't really make sense to 
handle undefining in CheckMacroName but defining in HandleDefineDirective. It 
would be nice to instead handle both in CheckMacroName, but that isn't possible 
as the handling of defines requires looking at what the name is being defined 
to.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144654

Files:
  clang/lib/Lex/PPDirectives.cpp
  clang/test/Preprocessor/macro-reserved.c
  clang/test/Preprocessor/macro-reserved.cpp

Index: clang/test/Preprocessor/macro-reserved.cpp
===
--- clang/test/Preprocessor/macro-reserved.cpp
+++ clang/test/Preprocessor/macro-reserved.cpp
@@ -12,7 +12,7 @@
 #undef _HAVE_X
 #undef X__Y
 
-#undef __cplusplus
+#undef __cplusplus // expected-warning {{undefining builtin macro}}
 #define __cplusplus
 
 // allowlisted definitions
Index: clang/test/Preprocessor/macro-reserved.c
===
--- clang/test/Preprocessor/macro-reserved.c
+++ clang/test/Preprocessor/macro-reserved.c
@@ -6,6 +6,7 @@
 #define __cplusplus
 #define _HAVE_X 0
 #define X__Y
+#define __STDC__ 1 // expected-warning {{redefining builtin macro}}
 
 #undef for
 #undef final
@@ -13,6 +14,7 @@
 #undef __cplusplus
 #undef _HAVE_X
 #undef X__Y
+#undef __STDC_HOSTED__ // expected-warning {{undefining builtin macro}}
 
 // allowlisted definitions
 #define while while
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -319,15 +319,6 @@
 return Diag(MacroNameTok, diag::err_defined_macro_name);
   }
 
-  if (isDefineUndef == MU_Undef) {
-auto *MI = getMacroInfo(II);
-if (MI && MI->isBuiltinMacro()) {
-  // Warn if undefining "__LINE__" and other builtins, per C99 6.10.8/4
-  // and C++ [cpp.predefined]p4], but allow it as an extension.
-  Diag(MacroNameTok, diag::ext_pp_undef_builtin_macro);
-}
-  }
-
   // If defining/undefining reserved identifier or a keyword, we need to issue
   // a warning.
   SourceLocation MacroNameLoc = MacroNameTok.getLocation();
@@ -3004,6 +2995,14 @@
   MI->setTokens(Tokens, BP);
   return MI;
 }
+
+static bool isObjCProtectedMacro(const IdentifierInfo *II) {
+  return II->isStr("__strong") ||
+ II->isStr("__weak") ||
+ II->isStr("__unsafe_unretained") ||
+ II->isStr("__autoreleasing");
+}
+
 /// HandleDefineDirective - Implements \#define.  This consumes the entire macro
 /// line then lets the caller lex the next real token.
 void Preprocessor::HandleDefineDirective(
@@ -3075,13 +3074,7 @@
 // In Objective-C, ignore attempts to directly redefine the builtin
 // definitions of the ownership qualifiers.  It's still possible to
 // #undef them.
-auto isObjCProtectedMacro = [](const IdentifierInfo *II) -> bool {
-  return II->isStr("__strong") ||
- II->isStr("__weak") ||
- II->isStr("__unsafe_unretained") ||
- II->isStr("__autoreleasing");
-};
-   if (getLangOpts().ObjC &&
+if (getLangOpts().ObjC &&
 SourceMgr.getFileID(OtherMI->getDefinitionLoc())
   == getPredefinesFileID() &&
 isObjCProtectedMacro(MacroNameTok.getIdentifierInfo())) {
@@ -3107,7 +3100,8 @@
 
   // Warn if defining "__LINE__" and other builtins, per C99 6.10.8/4 and
   // C++ [cpp.predefined]p4, but allow it as an extension.
-  if (OtherMI->isBuiltinMacro())
+  if (OtherMI->isBuiltinMacro() ||
+  SourceMgr.isWrittenInBuiltinFile(OtherMI->getDefinitionLoc()))
 Diag(MacroNameTok, diag::ext_pp_redef_builtin_macro);
   // Macros must be identical.  This means all tokens and whitespace
   // separation must be the same.  C99 6.10.3p2.
@@ -3187,6 +3181,14 @@
 if (!MI->isUsed() && MI->isWarnIfUnused())
   Diag(MI->getDefinitionLoc(), diag::pp_macro_not_used);
 
+// Warn if undefining "__LINE__" and other builtins, per C99 6.10.8/4 and
+// C++ [cpp.predefined]p4, but allow it as an extension. Don't warn if this
+// is an Objective-C builtin macro though.
+if ((MI->isBuiltinMacro() ||
+ SourceMgr.isWrittenInBuiltinFile(MI->getDefinitionLoc())) &&
+!(getLangOpts().ObjC && isObjCProtectedMacro(II)))
+  Diag(MacroNameTok, 

[PATCH] D144651: [Serialization] Place command line defines in the correct file

2023-02-23 Thread John Brawn via Phabricator via cfe-commits
john.brawn created this revision.
john.brawn added reviewers: mstorsjo, jansvoboda11, DHowett-MSFT, sammccall.
Herald added a project: All.
john.brawn requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fix two problems happening during deserialization causing command line defines 
to be reported as being built-in defines:

- When deserializing SM_SLOC_BUFFER_ENTRY we need to call setHasLineDirectives 
in the same way as we do for SM_SLOC_FILE_ENTRY.
- When created suggested predefines based on the current command line options 
we need to add line markers in the same way that InitializePreprocessor does.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144651

Files:
  clang/lib/Serialization/ASTReader.cpp
  clang/test/PCH/macro-cmdline.c
  clang/test/PCH/ms-pch-macro.c


Index: clang/test/PCH/ms-pch-macro.c
===
--- clang/test/PCH/ms-pch-macro.c
+++ clang/test/PCH/ms-pch-macro.c
@@ -36,4 +36,4 @@
 // CHECK-FOO: definition of macro 'FOO' differs between the precompiled header 
('1') and the command line ('blah')
 // CHECK-NOFOO: macro 'FOO' was defined in the precompiled header but undef'd 
on the command line
 
-// expected-warning@1 {{definition of macro 'BAR' does not match definition in 
precompiled header}}
+// expected-warning@2 {{definition of macro 'BAR' does not match definition in 
precompiled header}}
Index: clang/test/PCH/macro-cmdline.c
===
--- /dev/null
+++ clang/test/PCH/macro-cmdline.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 %s -emit-pch -o %t1.pch -DMACRO1=1
+// RUN: %clang_cc1 -fsyntax-only %s -include-pch %t1.pch -DMACRO2=1 2>&1 | 
FileCheck %s
+
+#ifndef HEADER
+#define HEADER
+#else
+#define MACRO1 2
+// CHECK: macro-cmdline.c{{.*}}'MACRO1' macro redefined
+// CHECK: {{.*}}previous definition is here
+#define MACRO2 2
+// CHECK: macro-cmdline.c{{.*}}'MACRO2' macro redefined
+// CHECK: {{.*}}previous definition is here
+#endif
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -654,6 +654,10 @@
   SmallVector ExistingMacroNames;
   collectMacroDefinitions(ExistingPPOpts, ExistingMacros, );
 
+  // Use a line marker to enter the  file, as the defines and
+  // undefines here will have come from the command line.
+  SuggestedPredefines += "# 1 \"\" 1\n";
+
   for (unsigned I = 0, N = ExistingMacroNames.size(); I != N; ++I) {
 // Dig out the macro definition in the existing preprocessor options.
 StringRef MacroName = ExistingMacroNames[I];
@@ -713,6 +717,10 @@
 }
 return true;
   }
+
+  // Leave the  file and return to .
+  SuggestedPredefines += "# 1 \"\" 2\n";
+
   if (Validation == OptionValidateStrictMatches) {
 // If strict matches are requested, don't tolerate any extra defines in
 // the AST file that are missing on the command line.
@@ -1579,8 +1587,13 @@
 auto Buffer = ReadBuffer(SLocEntryCursor, Name);
 if (!Buffer)
   return true;
-SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID,
-   BaseOffset + Offset, IncludeLoc);
+FileID FID = SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID,
+BaseOffset + Offset, IncludeLoc);
+if (Record[3]) {
+  SrcMgr::FileInfo  =
+const_cast(SourceMgr.getSLocEntry(FID).getFile());
+  FileInfo.setHasLineDirectives();
+}
 break;
   }
 


Index: clang/test/PCH/ms-pch-macro.c
===
--- clang/test/PCH/ms-pch-macro.c
+++ clang/test/PCH/ms-pch-macro.c
@@ -36,4 +36,4 @@
 // CHECK-FOO: definition of macro 'FOO' differs between the precompiled header ('1') and the command line ('blah')
 // CHECK-NOFOO: macro 'FOO' was defined in the precompiled header but undef'd on the command line
 
-// expected-warning@1 {{definition of macro 'BAR' does not match definition in precompiled header}}
+// expected-warning@2 {{definition of macro 'BAR' does not match definition in precompiled header}}
Index: clang/test/PCH/macro-cmdline.c
===
--- /dev/null
+++ clang/test/PCH/macro-cmdline.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 %s -emit-pch -o %t1.pch -DMACRO1=1
+// RUN: %clang_cc1 -fsyntax-only %s -include-pch %t1.pch -DMACRO2=1 2>&1 | FileCheck %s
+
+#ifndef HEADER
+#define HEADER
+#else
+#define MACRO1 2
+// CHECK: macro-cmdline.c{{.*}}'MACRO1' macro redefined
+// CHECK: {{.*}}previous definition is here
+#define MACRO2 2
+// CHECK: macro-cmdline.c{{.*}}'MACRO2' macro redefined
+// CHECK: {{.*}}previous definition is here
+#endif
Index: clang/lib/Serialization/ASTReader.cpp
===
--- 

[PATCH] D138679: [clang][CodeGen] Add default attributes to __clang_call_terminate

2022-11-29 Thread John Brawn via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6b8900f7f91d: [clang][CodeGen] Add default attributes to 
__clang_call_terminate (authored by john.brawn).

Changed prior to commit:
  https://reviews.llvm.org/D138679?vs=477799=478536#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138679

Files:
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/arm-generated-fn-attr.cpp
  clang/test/CodeGenCXX/dllimport-runtime-fns.cpp
  clang/test/CodeGenCXX/exceptions.cpp
  clang/test/CodeGenCXX/runtime-dllstorage.cpp
  clang/test/OpenMP/distribute_parallel_for_num_threads_codegen.cpp
  clang/test/OpenMP/parallel_codegen.cpp
  clang/test/OpenMP/parallel_for_codegen.cpp
  clang/test/OpenMP/parallel_master_codegen.cpp
  clang/test/OpenMP/parallel_sections_codegen.cpp
  clang/test/OpenMP/single_codegen.cpp
  clang/test/OpenMP/taskgroup_codegen.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_num_threads_codegen.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_simd_num_threads_codegen.cpp

Index: clang/test/OpenMP/teams_distribute_parallel_for_simd_num_threads_codegen.cpp
===
--- clang/test/OpenMP/teams_distribute_parallel_for_simd_num_threads_codegen.cpp
+++ clang/test/OpenMP/teams_distribute_parallel_for_simd_num_threads_codegen.cpp
@@ -381,7 +381,7 @@
 //
 //
 // CHECK1-LABEL: define {{[^@]+}}@__clang_call_terminate
-// CHECK1-SAME: (ptr [[TMP0:%.*]]) #[[ATTR5:[0-9]+]] comdat {
+// CHECK1-SAME: (ptr noundef [[TMP0:%.*]]) #[[ATTR5:[0-9]+]] comdat {
 // CHECK1-NEXT:[[TMP2:%.*]] = call ptr @__cxa_begin_catch(ptr [[TMP0]]) #[[ATTR6]]
 // CHECK1-NEXT:call void @_ZSt9terminatev() #[[ATTR9]]
 // CHECK1-NEXT:unreachable
@@ -1549,7 +1549,7 @@
 //
 //
 // CHECK3-LABEL: define {{[^@]+}}@__clang_call_terminate
-// CHECK3-SAME: (ptr [[TMP0:%.*]]) #[[ATTR4:[0-9]+]] comdat {
+// CHECK3-SAME: (ptr noundef [[TMP0:%.*]]) #[[ATTR4:[0-9]+]] comdat {
 // CHECK3-NEXT:[[TMP2:%.*]] = call ptr @__cxa_begin_catch(ptr [[TMP0]]) #[[ATTR6]]
 // CHECK3-NEXT:call void @_ZSt9terminatev() #[[ATTR7]]
 // CHECK3-NEXT:unreachable
@@ -2058,7 +2058,7 @@
 //
 //
 // CHECK5-LABEL: define {{[^@]+}}@__clang_call_terminate
-// CHECK5-SAME: (ptr [[TMP0:%.*]]) #[[ATTR5:[0-9]+]] comdat {
+// CHECK5-SAME: (ptr noundef [[TMP0:%.*]]) #[[ATTR5:[0-9]+]] comdat {
 // CHECK5-NEXT:[[TMP2:%.*]] = call ptr @__cxa_begin_catch(ptr [[TMP0]]) #[[ATTR6]]
 // CHECK5-NEXT:call void @_ZSt9terminatev() #[[ATTR9]]
 // CHECK5-NEXT:unreachable
Index: clang/test/OpenMP/teams_distribute_parallel_for_num_threads_codegen.cpp
===
--- clang/test/OpenMP/teams_distribute_parallel_for_num_threads_codegen.cpp
+++ clang/test/OpenMP/teams_distribute_parallel_for_num_threads_codegen.cpp
@@ -365,7 +365,7 @@
 //
 //
 // CHECK1-LABEL: define {{[^@]+}}@__clang_call_terminate
-// CHECK1-SAME: (ptr [[TMP0:%.*]]) #[[ATTR5:[0-9]+]] comdat {
+// CHECK1-SAME: (ptr noundef [[TMP0:%.*]]) #[[ATTR5:[0-9]+]] comdat {
 // CHECK1-NEXT:[[TMP2:%.*]] = call ptr @__cxa_begin_catch(ptr [[TMP0]]) #[[ATTR6]]
 // CHECK1-NEXT:call void @_ZSt9terminatev() #[[ATTR9]]
 // CHECK1-NEXT:unreachable
@@ -1609,7 +1609,7 @@
 //
 //
 // CHECK5-LABEL: define {{[^@]+}}@__clang_call_terminate
-// CHECK5-SAME: (ptr [[TMP0:%.*]]) #[[ATTR5:[0-9]+]] comdat {
+// CHECK5-SAME: (ptr noundef [[TMP0:%.*]]) #[[ATTR5:[0-9]+]] comdat {
 // CHECK5-NEXT:[[TMP2:%.*]] = call ptr @__cxa_begin_catch(ptr [[TMP0]]) #[[ATTR6]]
 // CHECK5-NEXT:call void @_ZSt9terminatev() #[[ATTR9]]
 // CHECK5-NEXT:unreachable
Index: clang/test/OpenMP/taskgroup_codegen.cpp
===
--- clang/test/OpenMP/taskgroup_codegen.cpp
+++ clang/test/OpenMP/taskgroup_codegen.cpp
@@ -66,7 +66,7 @@
 //
 //
 // CHECK1-LABEL: define {{[^@]+}}@__clang_call_terminate
-// CHECK1-SAME: (ptr [[TMP0:%.*]]) #[[ATTR5:[0-9]+]] comdat {
+// CHECK1-SAME: (ptr noundef [[TMP0:%.*]]) #[[ATTR5:[0-9]+]] comdat {
 // CHECK1-NEXT:[[TMP2:%.*]] = call ptr @__cxa_begin_catch(ptr [[TMP0]]) #[[ATTR3:[0-9]+]]
 // CHECK1-NEXT:call void @_ZSt9terminatev() #[[ATTR8]]
 // CHECK1-NEXT:unreachable
@@ -136,7 +136,7 @@
 //
 //
 // DEBUG1-LABEL: define {{[^@]+}}@__clang_call_terminate
-// DEBUG1-SAME: (ptr [[TMP0:%.*]]) #[[ATTR5:[0-9]+]] {
+// DEBUG1-SAME: (ptr noundef [[TMP0:%.*]]) #[[ATTR5:[0-9]+]] {
 // DEBUG1-NEXT:[[TMP2:%.*]] = call ptr @__cxa_begin_catch(ptr [[TMP0]]) #[[ATTR3:[0-9]+]]
 // DEBUG1-NEXT:call void @_ZSt9terminatev() #[[ATTR8]]
 // DEBUG1-NEXT:unreachable
Index: clang/test/OpenMP/single_codegen.cpp
===
--- clang/test/OpenMP/single_codegen.cpp
+++ 

[PATCH] D138679: [clang][CodeGen] Add default attributes to __clang_call_terminate

2022-11-24 Thread John Brawn via Phabricator via cfe-commits
john.brawn created this revision.
john.brawn added reviewers: rsmith, rjmccall, lebedev.ri, miyuki.
Herald added a project: All.
john.brawn requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When generating __clang_call_terminate use SetLLVMFunctionAttributes to set the 
default function attributes, like we do for all the other functions generated 
by clang. This fixes a problem where target features from the command line 
weren't being applied to this function.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138679

Files:
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/arm-generated-fn-attr.cpp
  clang/test/CodeGenCXX/dllimport-runtime-fns.cpp
  clang/test/CodeGenCXX/exceptions.cpp
  clang/test/CodeGenCXX/runtime-dllstorage.cpp

Index: clang/test/CodeGenCXX/runtime-dllstorage.cpp
===
--- clang/test/CodeGenCXX/runtime-dllstorage.cpp
+++ clang/test/CodeGenCXX/runtime-dllstorage.cpp
@@ -116,7 +116,7 @@
 
 // CHECK-IA-DAG: @_ZTH1t = dso_local alias void (), ptr @__tls_init
 // CHECK-IA-DAG: declare dso_local i32 @__gxx_personality_v0(...)
-// CHECK-IA-DAG: define linkonce_odr hidden void @__clang_call_terminate(ptr %0)
+// CHECK-IA-DAG: define linkonce_odr hidden void @__clang_call_terminate(ptr noundef %0)
 
 // CHECK-DYNAMIC-IA-DAG: declare dllimport i32 @__cxa_thread_atexit(ptr, ptr, ptr)
 // CHECK-DYNAMIC-IA-DAG: declare dllimport i32 @__cxa_atexit(ptr, ptr, ptr)
Index: clang/test/CodeGenCXX/exceptions.cpp
===
--- clang/test/CodeGenCXX/exceptions.cpp
+++ clang/test/CodeGenCXX/exceptions.cpp
@@ -633,4 +633,4 @@
 
 }
 
-// CHECK98: attributes [[NI_NR_NUW]] = { noinline noreturn nounwind }
+// CHECK98: attributes [[NI_NR_NUW]] = { noinline noreturn nounwind {{.*}} }
Index: clang/test/CodeGenCXX/dllimport-runtime-fns.cpp
===
--- clang/test/CodeGenCXX/dllimport-runtime-fns.cpp
+++ clang/test/CodeGenCXX/dllimport-runtime-fns.cpp
@@ -28,14 +28,14 @@
 // MSVC: declare dso_local void @__std_terminate()
 
 // _ZSt9terminatev and __cxa_begin_catch should be marked dllimport.
-// ITANIUM-LABEL: define linkonce_odr hidden void @__clang_call_terminate(ptr %0)
+// ITANIUM-LABEL: define linkonce_odr hidden void @__clang_call_terminate(ptr noundef %0)
 // ITANIUM: call ptr @__cxa_begin_catch({{.*}})
 // ITANIUM: call void @_ZSt9terminatev()
 // ITANIUM: declare dllimport ptr @__cxa_begin_catch(ptr)
 // ITANIUM: declare dllimport void @_ZSt9terminatev()
 
 // .. not for mingw.
-// GNU-LABEL: define linkonce_odr hidden void @__clang_call_terminate(ptr %0)
+// GNU-LABEL: define linkonce_odr hidden void @__clang_call_terminate(ptr noundef %0)
 // GNU: call ptr @__cxa_begin_catch({{.*}})
 // GNU: call void @_ZSt9terminatev()
 // GNU: declare dso_local ptr @__cxa_begin_catch(ptr)
Index: clang/test/CodeGenCXX/arm-generated-fn-attr.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/arm-generated-fn-attr.cpp
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -triple thumbv8.1m.main-none-eabi -target-feature +pacbti -fcxx-exceptions -fexceptions -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-PACBTI
+// RUN: %clang_cc1 -triple thumbv8.1m.main-none-eabi -target-feature -pacbti -fcxx-exceptions -fexceptions -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NOPACBTI
+
+// Check that functions generated by clang have the correct attributes
+
+class Example {
+public:
+  Example();
+  int fn();
+};
+
+// Initialization of var1 causes __cxx_global_var_init and __tls_init to be generated
+thread_local Example var1;
+extern thread_local Example var2;
+extern void fn();
+
+int testfn() noexcept {
+  // Calling fn in a noexcept function causes __clang_call_terminate to be generated
+  fn();
+  // Use of var1 and var2 causes TLS wrapper functions to be generated
+  return var1.fn() + var2.fn();
+}
+
+// CHECK: define {{.*}} @__cxx_global_var_init() [[ATTR1:#[0-9]+]]
+// CHECK: define {{.*}} @__clang_call_terminate({{.*}}) [[ATTR2:#[0-9]+]]
+// CHECK: define {{.*}} @_ZTW4var1() [[ATTR3:#[0-9]+]]
+// CHECK: define {{.*}} @_ZTW4var2() [[ATTR3]]
+// CHECK: define {{.*}} @__tls_init() [[ATTR1]]
+
+// CHECK-PACBTI: attributes [[ATTR1]] = { {{.*}}"target-features"="+armv8.1-m.main,+pacbti,+thumb-mode"{{.*}} }
+// CHECK-PACBTI: attributes [[ATTR2]] = { {{.*}}"target-features"="+armv8.1-m.main,+pacbti,+thumb-mode"{{.*}} }
+// CHECK-PACBTI: attributes [[ATTR3]] = { {{.*}}"target-features"="+armv8.1-m.main,+pacbti,+thumb-mode"{{.*}} }
+
+// CHECK-NOPACBTI: attributes [[ATTR1]] = { {{.*}}"target-features"="+armv8.1-m.main,+thumb-mode,-pacbti"{{.*}} }
+// CHECK-NOPACBTI: attributes [[ATTR2]] = { {{.*}}"target-features"="+armv8.1-m.main,+thumb-mode,-pacbti"{{.*}} }
+// CHECK-NOPACBTI: attributes [[ATTR3]] 

[PATCH] D138143: [FPEnv] Enable strict fp for AArch64 in clang

2022-11-21 Thread John Brawn via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9e3264ab2021: [FPEnv] Enable strict fp for AArch64 in clang 
(authored by john.brawn).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138143

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Basic/Targets/AArch64.cpp
  clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
  clang/test/CodeGen/aarch64-neon-misc-constrained.c
  clang/test/CodeGen/aarch64-neon-scalar-x-indexed-elem-constrained.c
  clang/test/CodeGen/aarch64-strictfp-builtins.c
  clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics-constrained.c
  clang/test/CodeGen/aarch64-v8.2a-neon-intrinsics-constrained.c
  clang/test/CodeGen/arm-neon-directed-rounding-constrained.c
  clang/test/CodeGen/arm64-vrnd-constrained.c
  clang/test/CodeGen/fp16-ops-strictfp.c
  clang/test/Parser/pragma-fp-warn.c

Index: clang/test/Parser/pragma-fp-warn.c
===
--- clang/test/Parser/pragma-fp-warn.c
+++ clang/test/Parser/pragma-fp-warn.c
@@ -1,7 +1,7 @@
 
 // RUN: %clang_cc1 -triple wasm32 -fsyntax-only -Wno-unknown-pragmas -Wignored-pragmas -verify %s
 // RUN: %clang_cc1 -triple thumbv7 -fsyntax-only -Wno-unknown-pragmas -Wignored-pragmas -verify %s
-// RUN: %clang_cc1 -triple aarch64 -fsyntax-only -Wno-unknown-pragmas -Wignored-pragmas -verify %s
+// RUN: %clang_cc1 -DEXPOK -triple aarch64 -fsyntax-only -Wno-unknown-pragmas -Wignored-pragmas -verify %s
 // RUN: %clang_cc1 -DEXPOK -triple x86_64 -fsyntax-only -Wno-unknown-pragmas -Wignored-pragmas -verify %s
 // RUN: %clang_cc1 -DEXPOK -triple systemz -fsyntax-only -Wno-unknown-pragmas -Wignored-pragmas -verify %s
 // RUN: %clang_cc1 -DEXPOK -triple powerpc -fsyntax-only -Wno-unknown-pragmas -Wignored-pragmas -verify %s
Index: clang/test/CodeGen/fp16-ops-strictfp.c
===
--- clang/test/CodeGen/fp16-ops-strictfp.c
+++ clang/test/CodeGen/fp16-ops-strictfp.c
@@ -1,10 +1,10 @@
 // REQUIRES: arm-registered-target
 // RUN: %clang_cc1 -ffp-exception-behavior=maytrap -fexperimental-strict-floating-point -emit-llvm -o - -triple arm-none-linux-gnueabi %s | FileCheck %s --check-prefix=NOTNATIVE --check-prefix=CHECK -vv -dump-input=fail
-// RUN: %clang_cc1 -ffp-exception-behavior=maytrap -fexperimental-strict-floating-point -emit-llvm -o - -triple aarch64-none-linux-gnueabi %s | FileCheck %s --check-prefix=NOTNATIVE --check-prefix=CHECK
+// RUN: %clang_cc1 -ffp-exception-behavior=maytrap -emit-llvm -o - -triple aarch64-none-linux-gnueabi %s | FileCheck %s --check-prefix=NOTNATIVE --check-prefix=CHECK
 // RUN: %clang_cc1 -ffp-exception-behavior=maytrap -fexperimental-strict-floating-point -emit-llvm -o - -triple x86_64-linux-gnu %s | FileCheck %s --check-prefix=NOTNATIVE --check-prefix=CHECK
 // RUN: %clang_cc1 -ffp-exception-behavior=maytrap -fexperimental-strict-floating-point -emit-llvm -o - -triple arm-none-linux-gnueabi -fnative-half-type %s \
 // RUN:   | FileCheck %s --check-prefix=NATIVE-HALF --check-prefix=CHECK
-// RUN: %clang_cc1 -ffp-exception-behavior=maytrap -fexperimental-strict-floating-point -emit-llvm -o - -triple aarch64-none-linux-gnueabi -fnative-half-type %s \
+// RUN: %clang_cc1 -ffp-exception-behavior=maytrap -emit-llvm -o - -triple aarch64-none-linux-gnueabi -fnative-half-type %s \
 // RUN:   | FileCheck %s --check-prefix=NATIVE-HALF --check-prefix=CHECK
 //
 // Test that the constrained intrinsics are picking up the exception
Index: clang/test/CodeGen/arm64-vrnd-constrained.c
===
--- clang/test/CodeGen/arm64-vrnd-constrained.c
+++ clang/test/CodeGen/arm64-vrnd-constrained.c
@@ -1,10 +1,10 @@
 // RUN: %clang_cc1 -triple arm64-apple-ios7 -target-feature +neon -ffreestanding -flax-vector-conversions=none -emit-llvm -o - %s \
 // RUN: | FileCheck --check-prefix=COMMON --check-prefix=UNCONSTRAINED %s
-// RUN: %clang_cc1 -triple arm64-apple-ios7 -target-feature +neon -ffreestanding -flax-vector-conversions=none -fexperimental-strict-floating-point -ffp-exception-behavior=strict -emit-llvm -o - %s \
+// RUN: %clang_cc1 -triple arm64-apple-ios7 -target-feature +neon -ffreestanding -flax-vector-conversions=none -ffp-exception-behavior=strict -emit-llvm -o - %s \
 // RUN: | FileCheck --check-prefix=COMMON --check-prefix=CONSTRAINED %s
 // RUN: %clang_cc1 -triple arm64-apple-ios7 -target-feature +neon -ffreestanding -flax-vector-conversions=none -emit-llvm -o - %s | llc -o=- - \
 // RUN: | FileCheck --check-prefix=COMMON --check-prefix=CHECK-ASM %s
-// RUN: %clang_cc1 -triple arm64-apple-ios7 -target-feature +neon -ffreestanding -flax-vector-conversions=none -fexperimental-strict-floating-point -ffp-exception-behavior=strict -emit-llvm -o - %s | llc -o=- - \
+// RUN: %clang_cc1 -triple arm64-apple-ios7 -target-feature +neon -ffreestanding 

[PATCH] D138143: [FPEnv] Enable strict fp for AArch64 in clang

2022-11-18 Thread John Brawn via Phabricator via cfe-commits
john.brawn added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:760
+- Strict floating point has been enabled for AArch64, which means that
+  ``-ftrapping-math``, ``-frounding-math``, ``-ffp-model=strict``, and
+  ``-ffp-exception-behaviour=`` are now accepted.

ostannard wrote:
> Do we need tests for these command-line options? I only see tests for 
> -ffp-exception-behavior= in this patch.
-ftrapping-math and -ffp-model=strict are both driver-only options that are 
converted into other cc1 options and tested in Driver/fp-model.c. 
-frounding-math is tested in a target-independent way in the 
CodeGen/fpconstrained* tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138143

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


[PATCH] D137980: [ARM] Pretend atomics are always lock-free for small widths.

2022-11-17 Thread John Brawn via Phabricator via cfe-commits
john.brawn added a comment.

Looking at GCC it looks like there (for cortex-m0 at least) the behaviour is 
that loads and stores are generated inline, but more complex operations go to 
the atomic library calls (not the sync library calls). e.g. for

  int x, y;
  int fn() {
return __atomic_load_n(, __ATOMIC_SEQ_CST);
  }
  int fn2() {
return __atomic_compare_exchange_n(, , 0, 0, 0, __ATOMIC_SEQ_CST);
  }

I get with `arm-none-eabi-gcc tmp.c -O1 -mcpu=cortex-m0`

  fn:
  ldr r3, .L2
  dmb ish
  ldr r0, [r3]
  dmb ish
  bx  lr
  
  fn2:
  push{lr}
  sub sp, sp, #12
  ldr r0, .L5
  addsr1, r0, #4
  movsr3, #5
  str r3, [sp]
  movsr3, #0
  movsr2, #0
  bl  __atomic_compare_exchange_4
  add sp, sp, #12
  pop {pc}

so if we're doing this for compatibility with GCC we should do the same.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137980

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


[PATCH] D138143: [FPEnv] Enable strict fp for AArch64 in clang

2022-11-16 Thread John Brawn via Phabricator via cfe-commits
john.brawn created this revision.
john.brawn added reviewers: t.p.northover, fhahn, umesh.kalappa0.
Herald added subscribers: arphaman, kristof.beyls.
Herald added a project: All.
john.brawn requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The AArch64 target now has the necessary support for strict fp, so enable it in 
clang.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138143

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Basic/Targets/AArch64.cpp
  clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
  clang/test/CodeGen/aarch64-neon-misc-constrained.c
  clang/test/CodeGen/aarch64-neon-scalar-x-indexed-elem-constrained.c
  clang/test/CodeGen/aarch64-strictfp-builtins.c
  clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics-constrained.c
  clang/test/CodeGen/aarch64-v8.2a-neon-intrinsics-constrained.c
  clang/test/CodeGen/arm-neon-directed-rounding-constrained.c
  clang/test/CodeGen/arm64-vrnd-constrained.c
  clang/test/CodeGen/fp16-ops-strictfp.c
  clang/test/Parser/pragma-fp-warn.c

Index: clang/test/Parser/pragma-fp-warn.c
===
--- clang/test/Parser/pragma-fp-warn.c
+++ clang/test/Parser/pragma-fp-warn.c
@@ -1,7 +1,7 @@
 
 // RUN: %clang_cc1 -triple wasm32 -fsyntax-only -Wno-unknown-pragmas -Wignored-pragmas -verify %s
 // RUN: %clang_cc1 -triple thumbv7 -fsyntax-only -Wno-unknown-pragmas -Wignored-pragmas -verify %s
-// RUN: %clang_cc1 -triple aarch64 -fsyntax-only -Wno-unknown-pragmas -Wignored-pragmas -verify %s
+// RUN: %clang_cc1 -DEXPOK -triple aarch64 -fsyntax-only -Wno-unknown-pragmas -Wignored-pragmas -verify %s
 // RUN: %clang_cc1 -DEXPOK -triple x86_64 -fsyntax-only -Wno-unknown-pragmas -Wignored-pragmas -verify %s
 // RUN: %clang_cc1 -DEXPOK -triple systemz -fsyntax-only -Wno-unknown-pragmas -Wignored-pragmas -verify %s
 // RUN: %clang_cc1 -DEXPOK -triple powerpc -fsyntax-only -Wno-unknown-pragmas -Wignored-pragmas -verify %s
Index: clang/test/CodeGen/fp16-ops-strictfp.c
===
--- clang/test/CodeGen/fp16-ops-strictfp.c
+++ clang/test/CodeGen/fp16-ops-strictfp.c
@@ -1,10 +1,10 @@
 // REQUIRES: arm-registered-target
 // RUN: %clang_cc1 -ffp-exception-behavior=maytrap -fexperimental-strict-floating-point -emit-llvm -o - -triple arm-none-linux-gnueabi %s | FileCheck %s --check-prefix=NOTNATIVE --check-prefix=CHECK -vv -dump-input=fail
-// RUN: %clang_cc1 -ffp-exception-behavior=maytrap -fexperimental-strict-floating-point -emit-llvm -o - -triple aarch64-none-linux-gnueabi %s | FileCheck %s --check-prefix=NOTNATIVE --check-prefix=CHECK
+// RUN: %clang_cc1 -ffp-exception-behavior=maytrap -emit-llvm -o - -triple aarch64-none-linux-gnueabi %s | FileCheck %s --check-prefix=NOTNATIVE --check-prefix=CHECK
 // RUN: %clang_cc1 -ffp-exception-behavior=maytrap -fexperimental-strict-floating-point -emit-llvm -o - -triple x86_64-linux-gnu %s | FileCheck %s --check-prefix=NOTNATIVE --check-prefix=CHECK
 // RUN: %clang_cc1 -ffp-exception-behavior=maytrap -fexperimental-strict-floating-point -emit-llvm -o - -triple arm-none-linux-gnueabi -fnative-half-type %s \
 // RUN:   | FileCheck %s --check-prefix=NATIVE-HALF --check-prefix=CHECK
-// RUN: %clang_cc1 -ffp-exception-behavior=maytrap -fexperimental-strict-floating-point -emit-llvm -o - -triple aarch64-none-linux-gnueabi -fnative-half-type %s \
+// RUN: %clang_cc1 -ffp-exception-behavior=maytrap -emit-llvm -o - -triple aarch64-none-linux-gnueabi -fnative-half-type %s \
 // RUN:   | FileCheck %s --check-prefix=NATIVE-HALF --check-prefix=CHECK
 //
 // Test that the constrained intrinsics are picking up the exception
Index: clang/test/CodeGen/arm64-vrnd-constrained.c
===
--- clang/test/CodeGen/arm64-vrnd-constrained.c
+++ clang/test/CodeGen/arm64-vrnd-constrained.c
@@ -1,10 +1,10 @@
 // RUN: %clang_cc1 -triple arm64-apple-ios7 -target-feature +neon -ffreestanding -flax-vector-conversions=none -emit-llvm -o - %s \
 // RUN: | FileCheck --check-prefix=COMMON --check-prefix=UNCONSTRAINED %s
-// RUN: %clang_cc1 -triple arm64-apple-ios7 -target-feature +neon -ffreestanding -flax-vector-conversions=none -fexperimental-strict-floating-point -ffp-exception-behavior=strict -emit-llvm -o - %s \
+// RUN: %clang_cc1 -triple arm64-apple-ios7 -target-feature +neon -ffreestanding -flax-vector-conversions=none -ffp-exception-behavior=strict -emit-llvm -o - %s \
 // RUN: | FileCheck --check-prefix=COMMON --check-prefix=CONSTRAINED %s
 // RUN: %clang_cc1 -triple arm64-apple-ios7 -target-feature +neon -ffreestanding -flax-vector-conversions=none -emit-llvm -o - %s | llc -o=- - \
 // RUN: | FileCheck --check-prefix=COMMON --check-prefix=CHECK-ASM %s
-// RUN: %clang_cc1 -triple arm64-apple-ios7 -target-feature +neon -ffreestanding -flax-vector-conversions=none -fexperimental-strict-floating-point 

[PATCH] D129231: [Builtins] Do not claim all libfuncs are readnone with trapping math.

2022-08-08 Thread John Brawn via Phabricator via cfe-commits
john.brawn added inline comments.



Comment at: clang/include/clang/Basic/Builtins.def:1409
 
-LIBBUILTIN(round, "dd", "fnc", "math.h", ALL_LANGUAGES)
-LIBBUILTIN(roundf, "ff", "fnc", "math.h", ALL_LANGUAGES)
-LIBBUILTIN(roundl, "LdLd", "fnc", "math.h", ALL_LANGUAGES)
+LIBBUILTIN(round, "dd", "fng", "math.h", ALL_LANGUAGES)
+LIBBUILTIN(roundf, "ff", "fng", "math.h", ALL_LANGUAGES)

scanon wrote:
> `round` is just like `trunc` or `floor` or `ceil`, and should be "fnc" if 
> they are.
I think they all should be the same, but I'm note sure if they should all be 
"fnc" or "fng".

Looking at the C17 standard, in section F.10.6 (IEE754/IEC60559 behaviour of 
nearest integer functions) round, trunc, floor, and ceil are all described in 
the same way: "The xyz functions may, but are not required to, raise the 
"inexact" floating-point exception for finite non-integer arguments". I don't 
know if our policy should be "These functions may raise an exception, therefore 
we should assume they do and treat that as a side-effect", or "These functions 
are not required to raise an exception, therefore a program can't rely on it 
and so we don't need to treat it as a side-effect".

Looking at implementations of these functions, it looks like GNU libm doesn't 
raise inexact, but the bionic libm does. I think I'm leaning towards marking 
all of them as "fng" as it's the more cautious of the two.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129231

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


[PATCH] D129231: [Builtins] Do not claim all libfuncs are readnone with trapping math.

2022-08-05 Thread John Brawn via Phabricator via cfe-commits
john.brawn accepted this revision.
john.brawn added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129231

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


[PATCH] D129231: [Builtins] Do not claim all libfuncs are readnone with trapping math.

2022-07-08 Thread John Brawn via Phabricator via cfe-commits
john.brawn added a comment.

Looking at the descriptions of maths functions in C99 (and I expect C11 will be 
the same) it looks like there are three kinds:

- Those that can report error by errno and floating-point exeption, and may 
also raise the inexact exception
- Those that don't set errno, but may raise the inexact exception
- Those that neither set errno or raise an exception

Looking at this patch and the attributes of the various function intrinsics it 
looks like you have:

- Marked "e": Can set errno, can't raise exception
- Marked "eg": Can set errno and raise exception
- Marked "cg": Can't set errno, can raise an exception
- Marked "c": Can't set errno or raise an exception

Given that the functions that set errno also raise exceptions I think it would 
make sense to have the "e" attribute cover both errno and exceptions, and have 
"g" just for those that can only raise exceptions. Also "cg" looks like it's 
probably wrong and should be "g" (given that "c" means "always const" and "g" 
means "const only when we don't have exceptions", and that's also how "e" is 
used in that we don't have functions with "cg").


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129231

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


[PATCH] D125775: [ARM] Don't Enable AES Pass for Generic Cores

2022-05-18 Thread John Brawn via Phabricator via cfe-commits
john.brawn accepted this revision.
john.brawn added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125775

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


[PATCH] D124255: [libc++] Make check_assertion.h use setjmp/longjmp instead of fork

2022-04-22 Thread John Brawn via Phabricator via cfe-commits
john.brawn created this revision.
john.brawn added reviewers: ldionne, Mordante, michaelplatings.
Herald added a project: All.
john.brawn requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

Currently check_assertion.h checks an assertion by forking and checking the 
exit code of the child process, but this means such tests don't work on targets 
where fork doesn't exist (e.g. bare metal targets).

Instead call setjmp just before we call the function we want to test, then 
longjmp out of __libcpp_assertion_handler with a return value indicating 
whether the assert happened as expected.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124255

Files:
  libcxx/test/support/check_assertion.h
  libcxx/test/support/test.support/test_check_assertion.pass.cpp

Index: libcxx/test/support/test.support/test_check_assertion.pass.cpp
===
--- libcxx/test/support/test.support/test_check_assertion.pass.cpp
+++ libcxx/test/support/test.support/test_check_assertion.pass.cpp
@@ -22,12 +22,6 @@
   DeathTest::ResultKind RK = DT.Run(func);
   auto OnFailure = [&](std::string msg) {
 std::fprintf(stderr, "EXPECT_DEATH( %s ) failed! (%s)\n\n", stmt, msg.c_str());
-if (!DT.getChildStdErr().empty()) {
-  std::fprintf(stderr, "-- standard err --\n%s\n", DT.getChildStdErr().c_str());
-}
-if (!DT.getChildStdOut().empty()) {
-  std::fprintf(stderr, "-- standard out --\n%s\n", DT.getChildStdOut().c_str());
-}
 return false;
   };
   if (RK != ExpectResult)
Index: libcxx/test/support/check_assertion.h
===
--- libcxx/test/support/check_assertion.h
+++ libcxx/test/support/check_assertion.h
@@ -17,9 +17,8 @@
 #include 
 #include 
 
-#include 
 #include 
-#include 
+#include 
 #include "test_macros.h"
 #include "test_allocator.h"
 
@@ -108,9 +107,16 @@
   return GMatch;
 }
 
+static jmp_buf& GetJmpBuf() {
+  static jmp_buf env;
+  return env;
+}
+
 struct DeathTest {
   enum ResultKind {
-RK_DidNotDie, RK_MatchFound, RK_MatchFailure, RK_SetupFailure, RK_Unknown
+// This enum starts from 1 and not 0 as we want to return the ResultKind
+// through setjmp/longjmp, which doesn't permit 0.
+RK_DidNotDie = 1, RK_MatchFound, RK_MatchFailure, RK_Unknown
   };
 
   static const char* ResultKindToString(ResultKind RK) {
@@ -118,7 +124,6 @@
 switch (RK) {
 CASE(RK_MatchFailure);
 CASE(RK_DidNotDie);
-CASE(RK_SetupFailure);
 CASE(RK_MatchFound);
 CASE(RK_Unknown);
 }
@@ -133,114 +138,30 @@
 
   template 
   ResultKind Run(Func&& f) {
-int pipe_res = pipe(stdout_pipe_fd_);
-assert(pipe_res != -1 && "failed to create pipe");
-pipe_res = pipe(stderr_pipe_fd_);
-assert(pipe_res != -1 && "failed to create pipe");
-pid_t child_pid = fork();
-assert(child_pid != -1 &&
-"failed to fork a process to perform a death test");
-child_pid_ = child_pid;
-if (child_pid_ == 0) {
-  RunForChild(std::forward(f));
-  assert(false && "unreachable");
-}
-return RunForParent();
-  }
-
-  int getChildExitCode() const { return exit_code_; }
-  std::string const& getChildStdOut() const { return stdout_from_child_; }
-  std::string const& getChildStdErr() const { return stderr_from_child_; }
-private:
-  template 
-  TEST_NORETURN void RunForChild(Func&& f) {
-close(GetStdOutReadFD()); // don't need to read from the pipe in the child.
-close(GetStdErrReadFD());
-auto DupFD = [](int DestFD, int TargetFD) {
-  int dup_result = dup2(DestFD, TargetFD);
-  if (dup_result == -1)
-std::exit(RK_SetupFailure);
-};
-DupFD(GetStdOutWriteFD(), STDOUT_FILENO);
-DupFD(GetStdErrWriteFD(), STDERR_FILENO);
-
 GlobalMatcher() = matcher_;
-f();
-std::exit(RK_DidNotDie);
-  }
-
-  static std::string ReadChildIOUntilEnd(int FD) {
-std::string error_msg;
-char buffer[256];
-int num_read;
-do {
-  while ((num_read = read(FD, buffer, 255)) > 0) {
-buffer[num_read] = '\0';
-error_msg += buffer;
-  }
-} while (num_read == -1 && errno == EINTR);
-return error_msg;
-  }
-
-  void CaptureIOFromChild() {
-close(GetStdOutWriteFD()); // no need to write from the parent process
-close(GetStdErrWriteFD());
-stdout_from_child_ = ReadChildIOUntilEnd(GetStdOutReadFD());
-stderr_from_child_ = ReadChildIOUntilEnd(GetStdErrReadFD());
-close(GetStdOutReadFD());
-close(GetStdErrReadFD());
-  }
-
-  ResultKind RunForParent() {
-CaptureIOFromChild();
-
-int status_value;
-pid_t result = waitpid(child_pid_, _value, 0);
-assert(result != -1 && "there is no child process to wait for");
-
-if (WIFEXITED(status_value)) {
-  exit_code_ = WEXITSTATUS(status_value);
-  if 

[PATCH] D118259: [AArch64] Adjust aarch64 constrained intrinsics tests and un-XFAIL

2022-04-14 Thread John Brawn via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1b1466c34669: [AArch64] Adjust aarch64 constrained 
intrinsics tests and un-XFAIL (authored by john.brawn).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118259

Files:
  clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
  clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics-constrained.c

Index: clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics-constrained.c
===
--- clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics-constrained.c
+++ clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics-constrained.c
@@ -1,31 +1,19 @@
 // RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +fullfp16 \
 // RUN: -fallow-half-arguments-and-returns -S -disable-O0-optnone \
 // RUN: -emit-llvm -o - %s | opt -S -mem2reg \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=COMMONIR --check-prefix=UNCONSTRAINED %s
+// RUN: | FileCheck --check-prefixes=COMMON,COMMONIR,UNCONSTRAINED %s
 // RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +fullfp16 \
 // RUN: -fallow-half-arguments-and-returns -S -disable-O0-optnone \
-// RUN: -ffp-exception-behavior=strict -emit-llvm -o - %s | opt -S -mem2reg \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=COMMONIR --check-prefix=CONSTRAINED %s
-// RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +fullfp16 \
-// RUN: -fallow-half-arguments-and-returns -S -disable-O0-optnone -o - %s \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=CHECK-ASM %s
-// RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +fullfp16 \
-// RUN: -ffp-exception-behavior=strict \
-// RUN: -fallow-half-arguments-and-returns -S -disable-O0-optnone -o - %s \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=CHECK-ASM %s
+// RUN: -ffp-exception-behavior=strict -fexperimental-strict-floating-point -emit-llvm -o - %s | opt -S -mem2reg \
+// RUN: | FileCheck --check-prefixes=COMMON,COMMONIR,CONSTRAINED %s
 
 // REQUIRES: aarch64-registered-target
 
-// "Lowering of strict fp16 not yet implemented"
-// XFAIL: *
-
 #include 
 
 // COMMON-LABEL: test_vceqzh_f16
 // UNCONSTRAINED:  [[TMP1:%.*]] = fcmp oeq half %a, 0xH
 // CONSTRAINED:[[TMP1:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f16(half %a, half 0xH, metadata !"oeq", metadata !"fpexcept.strict")
-// CHECK-ASM:  fcmp
-// CHECK-ASM:  cset {{w[0-9]+}}, eq
 // COMMONIR:   [[TMP2:%.*]] = sext i1 [[TMP1]] to i16
 // COMMONIR:   ret i16 [[TMP2]]
 uint16_t test_vceqzh_f16(float16_t a) {
@@ -34,9 +22,7 @@
 
 // COMMON-LABEL: test_vcgezh_f16
 // UNCONSTRAINED:  [[TMP1:%.*]] = fcmp oge half %a, 0xH
-// CONSTRAINED:[[TMP1:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f16(half %a, half 0xH, metadata !"oge", metadata !"fpexcept.strict")
-// CHECK-ASM:  fcmp
-// CHECK-ASM:  cset {{w[0-9]+}}, ge
+// CONSTRAINED:[[TMP1:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f16(half %a, half 0xH, metadata !"oge", metadata !"fpexcept.strict")
 // COMMONIR:   [[TMP2:%.*]] = sext i1 [[TMP1]] to i16
 // COMMONIR:   ret i16 [[TMP2]]
 uint16_t test_vcgezh_f16(float16_t a) {
@@ -45,9 +31,7 @@
 
 // COMMON-LABEL: test_vcgtzh_f16
 // UNCONSTRAINED:  [[TMP1:%.*]] = fcmp ogt half %a, 0xH
-// CONSTRAINED:[[TMP1:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f16(half %a, half 0xH, metadata !"ogt", metadata !"fpexcept.strict")
-// CHECK-ASM:  fcmp
-// CHECK-ASM:  cset {{w[0-9]+}}, gt
+// CONSTRAINED:[[TMP1:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f16(half %a, half 0xH, metadata !"ogt", metadata !"fpexcept.strict")
 // COMMONIR:   [[TMP2:%.*]] = sext i1 [[TMP1]] to i16
 // COMMONIR:   ret i16 [[TMP2]]
 uint16_t test_vcgtzh_f16(float16_t a) {
@@ -56,9 +40,7 @@
 
 // COMMON-LABEL: test_vclezh_f16
 // UNCONSTRAINED:  [[TMP1:%.*]] = fcmp ole half %a, 0xH
-// CONSTRAINED:[[TMP1:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f16(half %a, half 0xH, metadata !"ole", metadata !"fpexcept.strict")
-// CHECK-ASM:  fcmp
-// CHECK-ASM:  cset {{w[0-9]+}}, ls
+// CONSTRAINED:[[TMP1:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f16(half %a, half 0xH, metadata !"ole", metadata !"fpexcept.strict")
 // COMMONIR:   [[TMP2:%.*]] = sext i1 [[TMP1]] to i16
 // COMMONIR:   ret i16 [[TMP2]]
 uint16_t test_vclezh_f16(float16_t a) {
@@ -67,9 +49,7 @@
 
 // COMMON-LABEL: test_vcltzh_f16
 // UNCONSTRAINED:  [[TMP1:%.*]] = fcmp olt half %a, 0xH
-// CONSTRAINED:[[TMP1:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f16(half %a, half 0xH, metadata !"olt", metadata !"fpexcept.strict")
-// CHECK-ASM:  fcmp
-// CHECK-ASM:  cset {{w[0-9]+}}, mi
+// CONSTRAINED:[[TMP1:%.*]] = call 

[PATCH] D115620: [AArch64] Lowering and legalization of strict FP16

2022-04-14 Thread John Brawn via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG12c1022679d4: [AArch64] Lowering and legalization of strict 
FP16 (authored by john.brawn).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115620

Files:
  llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/test/CodeGen/AArch64/fp-intrinsics-fp16.ll
  llvm/test/CodeGen/AArch64/fp-intrinsics.ll

Index: llvm/test/CodeGen/AArch64/fp-intrinsics.ll
===
--- llvm/test/CodeGen/AArch64/fp-intrinsics.ll
+++ llvm/test/CodeGen/AArch64/fp-intrinsics.ll
@@ -1,5 +1,5 @@
-; RUN: llc -mtriple=aarch64-none-eabi %s -disable-strictnode-mutation -o - | FileCheck %s
-; RUN: llc -mtriple=aarch64-none-eabi -global-isel=true -global-isel-abort=2 -disable-strictnode-mutation %s -o - | FileCheck %s
+; RUN: llc -mtriple=aarch64-none-eabi %s -o - | FileCheck %s
+; RUN: llc -mtriple=aarch64-none-eabi -global-isel=true -global-isel-abort=2 %s -o - | FileCheck %s
 
 ; Check that constrained fp intrinsics are correctly lowered.
 
Index: llvm/test/CodeGen/AArch64/fp-intrinsics-fp16.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/fp-intrinsics-fp16.ll
@@ -0,0 +1,1173 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=aarch64-none-eabi %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NOFP16
+; RUN: llc -mtriple=aarch64-none-eabi -mattr=+fullfp16 %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-FP16
+; RUN: llc -mtriple=aarch64-none-eabi -global-isel=true -global-isel-abort=2 %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NOFP16
+; RUN: llc -mtriple=aarch64-none-eabi -global-isel=true -global-isel-abort=2 -mattr=+fullfp16 %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-FP16
+
+; Check that constrained fp intrinsics are correctly lowered.
+
+
+; Half-precision intrinsics
+
+define half @add_f16(half %x, half %y) #0 {
+; CHECK-NOFP16-LABEL: add_f16:
+; CHECK-NOFP16:   // %bb.0:
+; CHECK-NOFP16-NEXT:fcvt s1, h1
+; CHECK-NOFP16-NEXT:fcvt s0, h0
+; CHECK-NOFP16-NEXT:fadd s0, s0, s1
+; CHECK-NOFP16-NEXT:fcvt h0, s0
+; CHECK-NOFP16-NEXT:ret
+;
+; CHECK-FP16-LABEL: add_f16:
+; CHECK-FP16:   // %bb.0:
+; CHECK-FP16-NEXT:fadd h0, h0, h1
+; CHECK-FP16-NEXT:ret
+  %val = call half @llvm.experimental.constrained.fadd.f16(half %x, half %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret half %val
+}
+
+define half @sub_f16(half %x, half %y) #0 {
+; CHECK-NOFP16-LABEL: sub_f16:
+; CHECK-NOFP16:   // %bb.0:
+; CHECK-NOFP16-NEXT:fcvt s1, h1
+; CHECK-NOFP16-NEXT:fcvt s0, h0
+; CHECK-NOFP16-NEXT:fsub s0, s0, s1
+; CHECK-NOFP16-NEXT:fcvt h0, s0
+; CHECK-NOFP16-NEXT:ret
+;
+; CHECK-FP16-LABEL: sub_f16:
+; CHECK-FP16:   // %bb.0:
+; CHECK-FP16-NEXT:fsub h0, h0, h1
+; CHECK-FP16-NEXT:ret
+  %val = call half @llvm.experimental.constrained.fsub.f16(half %x, half %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret half %val
+}
+
+define half @mul_f16(half %x, half %y) #0 {
+; CHECK-NOFP16-LABEL: mul_f16:
+; CHECK-NOFP16:   // %bb.0:
+; CHECK-NOFP16-NEXT:fcvt s1, h1
+; CHECK-NOFP16-NEXT:fcvt s0, h0
+; CHECK-NOFP16-NEXT:fmul s0, s0, s1
+; CHECK-NOFP16-NEXT:fcvt h0, s0
+; CHECK-NOFP16-NEXT:ret
+;
+; CHECK-FP16-LABEL: mul_f16:
+; CHECK-FP16:   // %bb.0:
+; CHECK-FP16-NEXT:fmul h0, h0, h1
+; CHECK-FP16-NEXT:ret
+  %val = call half @llvm.experimental.constrained.fmul.f16(half %x, half %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret half %val
+}
+
+define half @div_f16(half %x, half %y) #0 {
+; CHECK-NOFP16-LABEL: div_f16:
+; CHECK-NOFP16:   // %bb.0:
+; CHECK-NOFP16-NEXT:fcvt s1, h1
+; CHECK-NOFP16-NEXT:fcvt s0, h0
+; CHECK-NOFP16-NEXT:fdiv s0, s0, s1
+; CHECK-NOFP16-NEXT:fcvt h0, s0
+; CHECK-NOFP16-NEXT:ret
+;
+; CHECK-FP16-LABEL: div_f16:
+; CHECK-FP16:   // %bb.0:
+; CHECK-FP16-NEXT:fdiv h0, h0, h1
+; CHECK-FP16-NEXT:ret
+  %val = call half @llvm.experimental.constrained.fdiv.f16(half %x, half %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret half %val
+}
+
+define half @frem_f16(half %x, half %y) #0 {
+; CHECK-LABEL: frem_f16:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:str x30, [sp, #-16]! // 8-byte Folded Spill
+; CHECK-NEXT:.cfi_def_cfa_offset 16
+; CHECK-NEXT:.cfi_offset w30, -16
+; CHECK-NEXT:fcvt s1, h1
+; CHECK-NEXT:fcvt s0, h0
+; CHECK-NEXT:bl fmodf
+; CHECK-NEXT:fcvt h0, s0
+; CHECK-NEXT:ldr x30, [sp], #16 // 8-byte Folded Reload
+; CHECK-NEXT:ret
+  %val = call half @llvm.experimental.constrained.frem.f16(half %x, half %y, 

[PATCH] D118259: [AArch64] Adjust aarch64 constrained intrinsics tests and un-XFAIL

2022-04-12 Thread John Brawn via Phabricator via cfe-commits
john.brawn updated this revision to Diff 422285.
john.brawn retitled this revision from "[AArch64] Adjust 
aarch64-neon-intrinsics-constrained test and un-XFAIL" to "[AArch64] Adjust 
aarch64 constrained intrinsics tests and un-XFAIL".
john.brawn edited the summary of this revision.
john.brawn added a comment.

Also adjust aarch64-v8.2a-fp16-intrinsics-constrained.c in this patch (was 
previously done in   
D115620 ) and remove the checks of the 
generated asm.


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

https://reviews.llvm.org/D118259

Files:
  clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
  clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics-constrained.c

Index: clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics-constrained.c
===
--- clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics-constrained.c
+++ clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics-constrained.c
@@ -1,31 +1,19 @@
 // RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +fullfp16 \
 // RUN: -fallow-half-arguments-and-returns -S -disable-O0-optnone \
 // RUN: -emit-llvm -o - %s | opt -S -mem2reg \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=COMMONIR --check-prefix=UNCONSTRAINED %s
+// RUN: | FileCheck --check-prefixes=COMMON,COMMONIR,UNCONSTRAINED %s
 // RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +fullfp16 \
 // RUN: -fallow-half-arguments-and-returns -S -disable-O0-optnone \
-// RUN: -ffp-exception-behavior=strict -emit-llvm -o - %s | opt -S -mem2reg \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=COMMONIR --check-prefix=CONSTRAINED %s
-// RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +fullfp16 \
-// RUN: -fallow-half-arguments-and-returns -S -disable-O0-optnone -o - %s \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=CHECK-ASM %s
-// RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +fullfp16 \
-// RUN: -ffp-exception-behavior=strict \
-// RUN: -fallow-half-arguments-and-returns -S -disable-O0-optnone -o - %s \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=CHECK-ASM %s
+// RUN: -ffp-exception-behavior=strict -fexperimental-strict-floating-point -emit-llvm -o - %s | opt -S -mem2reg \
+// RUN: | FileCheck --check-prefixes=COMMON,COMMONIR,CONSTRAINED %s
 
 // REQUIRES: aarch64-registered-target
 
-// "Lowering of strict fp16 not yet implemented"
-// XFAIL: *
-
 #include 
 
 // COMMON-LABEL: test_vceqzh_f16
 // UNCONSTRAINED:  [[TMP1:%.*]] = fcmp oeq half %a, 0xH
 // CONSTRAINED:[[TMP1:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f16(half %a, half 0xH, metadata !"oeq", metadata !"fpexcept.strict")
-// CHECK-ASM:  fcmp
-// CHECK-ASM:  cset {{w[0-9]+}}, eq
 // COMMONIR:   [[TMP2:%.*]] = sext i1 [[TMP1]] to i16
 // COMMONIR:   ret i16 [[TMP2]]
 uint16_t test_vceqzh_f16(float16_t a) {
@@ -34,9 +22,7 @@
 
 // COMMON-LABEL: test_vcgezh_f16
 // UNCONSTRAINED:  [[TMP1:%.*]] = fcmp oge half %a, 0xH
-// CONSTRAINED:[[TMP1:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f16(half %a, half 0xH, metadata !"oge", metadata !"fpexcept.strict")
-// CHECK-ASM:  fcmp
-// CHECK-ASM:  cset {{w[0-9]+}}, ge
+// CONSTRAINED:[[TMP1:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f16(half %a, half 0xH, metadata !"oge", metadata !"fpexcept.strict")
 // COMMONIR:   [[TMP2:%.*]] = sext i1 [[TMP1]] to i16
 // COMMONIR:   ret i16 [[TMP2]]
 uint16_t test_vcgezh_f16(float16_t a) {
@@ -45,9 +31,7 @@
 
 // COMMON-LABEL: test_vcgtzh_f16
 // UNCONSTRAINED:  [[TMP1:%.*]] = fcmp ogt half %a, 0xH
-// CONSTRAINED:[[TMP1:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f16(half %a, half 0xH, metadata !"ogt", metadata !"fpexcept.strict")
-// CHECK-ASM:  fcmp
-// CHECK-ASM:  cset {{w[0-9]+}}, gt
+// CONSTRAINED:[[TMP1:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f16(half %a, half 0xH, metadata !"ogt", metadata !"fpexcept.strict")
 // COMMONIR:   [[TMP2:%.*]] = sext i1 [[TMP1]] to i16
 // COMMONIR:   ret i16 [[TMP2]]
 uint16_t test_vcgtzh_f16(float16_t a) {
@@ -56,9 +40,7 @@
 
 // COMMON-LABEL: test_vclezh_f16
 // UNCONSTRAINED:  [[TMP1:%.*]] = fcmp ole half %a, 0xH
-// CONSTRAINED:[[TMP1:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f16(half %a, half 0xH, metadata !"ole", metadata !"fpexcept.strict")
-// CHECK-ASM:  fcmp
-// CHECK-ASM:  cset {{w[0-9]+}}, ls
+// CONSTRAINED:[[TMP1:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f16(half %a, half 0xH, metadata !"ole", metadata !"fpexcept.strict")
 // COMMONIR:   [[TMP2:%.*]] = sext i1 [[TMP1]] to i16
 // COMMONIR:   ret i16 [[TMP2]]
 uint16_t test_vclezh_f16(float16_t a) {
@@ -67,9 +49,7 @@
 
 // COMMON-LABEL: test_vcltzh_f16
 // UNCONSTRAINED:  [[TMP1:%.*]] = fcmp olt half %a, 0xH
-// CONSTRAINED:[[TMP1:%.*]] = call i1 

[PATCH] D115620: [AArch64] Lowering and legalization of strict FP16

2022-04-12 Thread John Brawn via Phabricator via cfe-commits
john.brawn added inline comments.



Comment at: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp:1386
+
+  IsStrictFPEnabled = true;
 }

dmgreen wrote:
> What are the ramifications of setting this to true?
The behaviour with IsStrictFPEnabled = false is that strict fp nodes are 
mutated into their non-strict equivalent at the start of ISel (in 
SelectionDAGISel::DoInstructionSelection). Setting it to true means that this 
mutation doesn't happen, so strict nodes are preserved all the way through to 
the actual instruction selection.


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

https://reviews.llvm.org/D115620

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


[PATCH] D115620: [AArch64] Lowering and legalization of strict FP16

2022-04-12 Thread John Brawn via Phabricator via cfe-commits
john.brawn updated this revision to Diff 422257.
john.brawn added a comment.

Removed clang test changes.


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

https://reviews.llvm.org/D115620

Files:
  llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/test/CodeGen/AArch64/fp-intrinsics-fp16.ll
  llvm/test/CodeGen/AArch64/fp-intrinsics.ll

Index: llvm/test/CodeGen/AArch64/fp-intrinsics.ll
===
--- llvm/test/CodeGen/AArch64/fp-intrinsics.ll
+++ llvm/test/CodeGen/AArch64/fp-intrinsics.ll
@@ -1,5 +1,5 @@
-; RUN: llc -mtriple=aarch64-none-eabi %s -disable-strictnode-mutation -o - | FileCheck %s
-; RUN: llc -mtriple=aarch64-none-eabi -global-isel=true -global-isel-abort=2 -disable-strictnode-mutation %s -o - | FileCheck %s
+; RUN: llc -mtriple=aarch64-none-eabi %s -o - | FileCheck %s
+; RUN: llc -mtriple=aarch64-none-eabi -global-isel=true -global-isel-abort=2 %s -o - | FileCheck %s
 
 ; Check that constrained fp intrinsics are correctly lowered.
 
Index: llvm/test/CodeGen/AArch64/fp-intrinsics-fp16.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/fp-intrinsics-fp16.ll
@@ -0,0 +1,1173 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=aarch64-none-eabi %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NOFP16
+; RUN: llc -mtriple=aarch64-none-eabi -mattr=+fullfp16 %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-FP16
+; RUN: llc -mtriple=aarch64-none-eabi -global-isel=true -global-isel-abort=2 %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NOFP16
+; RUN: llc -mtriple=aarch64-none-eabi -global-isel=true -global-isel-abort=2 -mattr=+fullfp16 %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-FP16
+
+; Check that constrained fp intrinsics are correctly lowered.
+
+
+; Half-precision intrinsics
+
+define half @add_f16(half %x, half %y) #0 {
+; CHECK-NOFP16-LABEL: add_f16:
+; CHECK-NOFP16:   // %bb.0:
+; CHECK-NOFP16-NEXT:fcvt s1, h1
+; CHECK-NOFP16-NEXT:fcvt s0, h0
+; CHECK-NOFP16-NEXT:fadd s0, s0, s1
+; CHECK-NOFP16-NEXT:fcvt h0, s0
+; CHECK-NOFP16-NEXT:ret
+;
+; CHECK-FP16-LABEL: add_f16:
+; CHECK-FP16:   // %bb.0:
+; CHECK-FP16-NEXT:fadd h0, h0, h1
+; CHECK-FP16-NEXT:ret
+  %val = call half @llvm.experimental.constrained.fadd.f16(half %x, half %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret half %val
+}
+
+define half @sub_f16(half %x, half %y) #0 {
+; CHECK-NOFP16-LABEL: sub_f16:
+; CHECK-NOFP16:   // %bb.0:
+; CHECK-NOFP16-NEXT:fcvt s1, h1
+; CHECK-NOFP16-NEXT:fcvt s0, h0
+; CHECK-NOFP16-NEXT:fsub s0, s0, s1
+; CHECK-NOFP16-NEXT:fcvt h0, s0
+; CHECK-NOFP16-NEXT:ret
+;
+; CHECK-FP16-LABEL: sub_f16:
+; CHECK-FP16:   // %bb.0:
+; CHECK-FP16-NEXT:fsub h0, h0, h1
+; CHECK-FP16-NEXT:ret
+  %val = call half @llvm.experimental.constrained.fsub.f16(half %x, half %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret half %val
+}
+
+define half @mul_f16(half %x, half %y) #0 {
+; CHECK-NOFP16-LABEL: mul_f16:
+; CHECK-NOFP16:   // %bb.0:
+; CHECK-NOFP16-NEXT:fcvt s1, h1
+; CHECK-NOFP16-NEXT:fcvt s0, h0
+; CHECK-NOFP16-NEXT:fmul s0, s0, s1
+; CHECK-NOFP16-NEXT:fcvt h0, s0
+; CHECK-NOFP16-NEXT:ret
+;
+; CHECK-FP16-LABEL: mul_f16:
+; CHECK-FP16:   // %bb.0:
+; CHECK-FP16-NEXT:fmul h0, h0, h1
+; CHECK-FP16-NEXT:ret
+  %val = call half @llvm.experimental.constrained.fmul.f16(half %x, half %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret half %val
+}
+
+define half @div_f16(half %x, half %y) #0 {
+; CHECK-NOFP16-LABEL: div_f16:
+; CHECK-NOFP16:   // %bb.0:
+; CHECK-NOFP16-NEXT:fcvt s1, h1
+; CHECK-NOFP16-NEXT:fcvt s0, h0
+; CHECK-NOFP16-NEXT:fdiv s0, s0, s1
+; CHECK-NOFP16-NEXT:fcvt h0, s0
+; CHECK-NOFP16-NEXT:ret
+;
+; CHECK-FP16-LABEL: div_f16:
+; CHECK-FP16:   // %bb.0:
+; CHECK-FP16-NEXT:fdiv h0, h0, h1
+; CHECK-FP16-NEXT:ret
+  %val = call half @llvm.experimental.constrained.fdiv.f16(half %x, half %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret half %val
+}
+
+define half @frem_f16(half %x, half %y) #0 {
+; CHECK-LABEL: frem_f16:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:str x30, [sp, #-16]! // 8-byte Folded Spill
+; CHECK-NEXT:.cfi_def_cfa_offset 16
+; CHECK-NEXT:.cfi_offset w30, -16
+; CHECK-NEXT:fcvt s1, h1
+; CHECK-NEXT:fcvt s0, h0
+; CHECK-NEXT:bl fmodf
+; CHECK-NEXT:fcvt h0, s0
+; CHECK-NEXT:ldr x30, [sp], #16 // 8-byte Folded Reload
+; CHECK-NEXT:ret
+  %val = call half @llvm.experimental.constrained.frem.f16(half %x, half %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret half %val
+}
+
+define half @fma_f16(half %x, half %y, half %z) #0 {
+; CHECK-NOFP16-LABEL: fma_f16:
+; 

[PATCH] D115620: [AArch64] Lowering and legalization of strict FP16

2022-04-11 Thread John Brawn via Phabricator via cfe-commits
john.brawn added a comment.

Ping.


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

https://reviews.llvm.org/D115620

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


[PATCH] D115620: [AArch64] Lowering and legalization of strict FP16

2022-03-31 Thread John Brawn via Phabricator via cfe-commits
john.brawn updated this revision to Diff 419494.
john.brawn added a comment.

Adjusted formatting slightly.


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

https://reviews.llvm.org/D115620

Files:
  clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics-constrained.c
  llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/test/CodeGen/AArch64/fp-intrinsics-fp16.ll
  llvm/test/CodeGen/AArch64/fp-intrinsics.ll

Index: llvm/test/CodeGen/AArch64/fp-intrinsics.ll
===
--- llvm/test/CodeGen/AArch64/fp-intrinsics.ll
+++ llvm/test/CodeGen/AArch64/fp-intrinsics.ll
@@ -1,5 +1,5 @@
-; RUN: llc -mtriple=aarch64-none-eabi %s -disable-strictnode-mutation -o - | FileCheck %s
-; RUN: llc -mtriple=aarch64-none-eabi -global-isel=true -global-isel-abort=2 -disable-strictnode-mutation %s -o - | FileCheck %s
+; RUN: llc -mtriple=aarch64-none-eabi %s -o - | FileCheck %s
+; RUN: llc -mtriple=aarch64-none-eabi -global-isel=true -global-isel-abort=2 %s -o - | FileCheck %s
 
 ; Check that constrained fp intrinsics are correctly lowered.
 
Index: llvm/test/CodeGen/AArch64/fp-intrinsics-fp16.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/fp-intrinsics-fp16.ll
@@ -0,0 +1,1173 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=aarch64-none-eabi %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NOFP16
+; RUN: llc -mtriple=aarch64-none-eabi -mattr=+fullfp16 %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-FP16
+; RUN: llc -mtriple=aarch64-none-eabi -global-isel=true -global-isel-abort=2 %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NOFP16
+; RUN: llc -mtriple=aarch64-none-eabi -global-isel=true -global-isel-abort=2 -mattr=+fullfp16 %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-FP16
+
+; Check that constrained fp intrinsics are correctly lowered.
+
+
+; Half-precision intrinsics
+
+define half @add_f16(half %x, half %y) #0 {
+; CHECK-NOFP16-LABEL: add_f16:
+; CHECK-NOFP16:   // %bb.0:
+; CHECK-NOFP16-NEXT:fcvt s1, h1
+; CHECK-NOFP16-NEXT:fcvt s0, h0
+; CHECK-NOFP16-NEXT:fadd s0, s0, s1
+; CHECK-NOFP16-NEXT:fcvt h0, s0
+; CHECK-NOFP16-NEXT:ret
+;
+; CHECK-FP16-LABEL: add_f16:
+; CHECK-FP16:   // %bb.0:
+; CHECK-FP16-NEXT:fadd h0, h0, h1
+; CHECK-FP16-NEXT:ret
+  %val = call half @llvm.experimental.constrained.fadd.f16(half %x, half %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret half %val
+}
+
+define half @sub_f16(half %x, half %y) #0 {
+; CHECK-NOFP16-LABEL: sub_f16:
+; CHECK-NOFP16:   // %bb.0:
+; CHECK-NOFP16-NEXT:fcvt s1, h1
+; CHECK-NOFP16-NEXT:fcvt s0, h0
+; CHECK-NOFP16-NEXT:fsub s0, s0, s1
+; CHECK-NOFP16-NEXT:fcvt h0, s0
+; CHECK-NOFP16-NEXT:ret
+;
+; CHECK-FP16-LABEL: sub_f16:
+; CHECK-FP16:   // %bb.0:
+; CHECK-FP16-NEXT:fsub h0, h0, h1
+; CHECK-FP16-NEXT:ret
+  %val = call half @llvm.experimental.constrained.fsub.f16(half %x, half %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret half %val
+}
+
+define half @mul_f16(half %x, half %y) #0 {
+; CHECK-NOFP16-LABEL: mul_f16:
+; CHECK-NOFP16:   // %bb.0:
+; CHECK-NOFP16-NEXT:fcvt s1, h1
+; CHECK-NOFP16-NEXT:fcvt s0, h0
+; CHECK-NOFP16-NEXT:fmul s0, s0, s1
+; CHECK-NOFP16-NEXT:fcvt h0, s0
+; CHECK-NOFP16-NEXT:ret
+;
+; CHECK-FP16-LABEL: mul_f16:
+; CHECK-FP16:   // %bb.0:
+; CHECK-FP16-NEXT:fmul h0, h0, h1
+; CHECK-FP16-NEXT:ret
+  %val = call half @llvm.experimental.constrained.fmul.f16(half %x, half %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret half %val
+}
+
+define half @div_f16(half %x, half %y) #0 {
+; CHECK-NOFP16-LABEL: div_f16:
+; CHECK-NOFP16:   // %bb.0:
+; CHECK-NOFP16-NEXT:fcvt s1, h1
+; CHECK-NOFP16-NEXT:fcvt s0, h0
+; CHECK-NOFP16-NEXT:fdiv s0, s0, s1
+; CHECK-NOFP16-NEXT:fcvt h0, s0
+; CHECK-NOFP16-NEXT:ret
+;
+; CHECK-FP16-LABEL: div_f16:
+; CHECK-FP16:   // %bb.0:
+; CHECK-FP16-NEXT:fdiv h0, h0, h1
+; CHECK-FP16-NEXT:ret
+  %val = call half @llvm.experimental.constrained.fdiv.f16(half %x, half %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret half %val
+}
+
+define half @frem_f16(half %x, half %y) #0 {
+; CHECK-LABEL: frem_f16:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:str x30, [sp, #-16]! // 8-byte Folded Spill
+; CHECK-NEXT:.cfi_def_cfa_offset 16
+; CHECK-NEXT:.cfi_offset w30, -16
+; CHECK-NEXT:fcvt s1, h1
+; CHECK-NEXT:fcvt s0, h0
+; CHECK-NEXT:bl fmodf
+; CHECK-NEXT:fcvt h0, s0
+; CHECK-NEXT:ldr x30, [sp], #16 // 8-byte Folded Reload
+; CHECK-NEXT:ret
+  %val = call half @llvm.experimental.constrained.frem.f16(half %x, half %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret half %val
+}
+
+define half @fma_f16(half 

[PATCH] D118259: [AArch64] Adjust aarch64-neon-intrinsics-constrained test and un-XFAIL

2022-03-17 Thread John Brawn via Phabricator via cfe-commits
john.brawn added a comment.

llvm/test/CodeGen/AArch64/fp-intrinsics-vector.ll is testing the asm 
generation, so it probably is fine to remove that here so I will. This test is 
specifically testing arm_neon.h intrinsics though, so wouldn't make sense 
unifying with other architectures.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118259

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


[PATCH] D115620: [AArch64] Lowering and legalization of strict FP16

2022-03-17 Thread John Brawn via Phabricator via cfe-commits
john.brawn updated this revision to Diff 416141.
john.brawn set the repository for this revision to rG LLVM Github Monorepo.
john.brawn added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Rebase and ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115620

Files:
  clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics-constrained.c
  llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/test/CodeGen/AArch64/fp-intrinsics-fp16.ll
  llvm/test/CodeGen/AArch64/fp-intrinsics.ll

Index: llvm/test/CodeGen/AArch64/fp-intrinsics.ll
===
--- llvm/test/CodeGen/AArch64/fp-intrinsics.ll
+++ llvm/test/CodeGen/AArch64/fp-intrinsics.ll
@@ -1,5 +1,5 @@
-; RUN: llc -mtriple=aarch64-none-eabi %s -disable-strictnode-mutation -o - | FileCheck %s
-; RUN: llc -mtriple=aarch64-none-eabi -global-isel=true -global-isel-abort=2 -disable-strictnode-mutation %s -o - | FileCheck %s
+; RUN: llc -mtriple=aarch64-none-eabi %s -o - | FileCheck %s
+; RUN: llc -mtriple=aarch64-none-eabi -global-isel=true -global-isel-abort=2 %s -o - | FileCheck %s
 
 ; Check that constrained fp intrinsics are correctly lowered.
 
Index: llvm/test/CodeGen/AArch64/fp-intrinsics-fp16.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/fp-intrinsics-fp16.ll
@@ -0,0 +1,1173 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=aarch64-none-eabi %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NOFP16
+; RUN: llc -mtriple=aarch64-none-eabi -mattr=+fullfp16 %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-FP16
+; RUN: llc -mtriple=aarch64-none-eabi -global-isel=true -global-isel-abort=2 %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NOFP16
+; RUN: llc -mtriple=aarch64-none-eabi -global-isel=true -global-isel-abort=2 -mattr=+fullfp16 %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-FP16
+
+; Check that constrained fp intrinsics are correctly lowered.
+
+
+; Half-precision intrinsics
+
+define half @add_f16(half %x, half %y) #0 {
+; CHECK-NOFP16-LABEL: add_f16:
+; CHECK-NOFP16:   // %bb.0:
+; CHECK-NOFP16-NEXT:fcvt s1, h1
+; CHECK-NOFP16-NEXT:fcvt s0, h0
+; CHECK-NOFP16-NEXT:fadd s0, s0, s1
+; CHECK-NOFP16-NEXT:fcvt h0, s0
+; CHECK-NOFP16-NEXT:ret
+;
+; CHECK-FP16-LABEL: add_f16:
+; CHECK-FP16:   // %bb.0:
+; CHECK-FP16-NEXT:fadd h0, h0, h1
+; CHECK-FP16-NEXT:ret
+  %val = call half @llvm.experimental.constrained.fadd.f16(half %x, half %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret half %val
+}
+
+define half @sub_f16(half %x, half %y) #0 {
+; CHECK-NOFP16-LABEL: sub_f16:
+; CHECK-NOFP16:   // %bb.0:
+; CHECK-NOFP16-NEXT:fcvt s1, h1
+; CHECK-NOFP16-NEXT:fcvt s0, h0
+; CHECK-NOFP16-NEXT:fsub s0, s0, s1
+; CHECK-NOFP16-NEXT:fcvt h0, s0
+; CHECK-NOFP16-NEXT:ret
+;
+; CHECK-FP16-LABEL: sub_f16:
+; CHECK-FP16:   // %bb.0:
+; CHECK-FP16-NEXT:fsub h0, h0, h1
+; CHECK-FP16-NEXT:ret
+  %val = call half @llvm.experimental.constrained.fsub.f16(half %x, half %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret half %val
+}
+
+define half @mul_f16(half %x, half %y) #0 {
+; CHECK-NOFP16-LABEL: mul_f16:
+; CHECK-NOFP16:   // %bb.0:
+; CHECK-NOFP16-NEXT:fcvt s1, h1
+; CHECK-NOFP16-NEXT:fcvt s0, h0
+; CHECK-NOFP16-NEXT:fmul s0, s0, s1
+; CHECK-NOFP16-NEXT:fcvt h0, s0
+; CHECK-NOFP16-NEXT:ret
+;
+; CHECK-FP16-LABEL: mul_f16:
+; CHECK-FP16:   // %bb.0:
+; CHECK-FP16-NEXT:fmul h0, h0, h1
+; CHECK-FP16-NEXT:ret
+  %val = call half @llvm.experimental.constrained.fmul.f16(half %x, half %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret half %val
+}
+
+define half @div_f16(half %x, half %y) #0 {
+; CHECK-NOFP16-LABEL: div_f16:
+; CHECK-NOFP16:   // %bb.0:
+; CHECK-NOFP16-NEXT:fcvt s1, h1
+; CHECK-NOFP16-NEXT:fcvt s0, h0
+; CHECK-NOFP16-NEXT:fdiv s0, s0, s1
+; CHECK-NOFP16-NEXT:fcvt h0, s0
+; CHECK-NOFP16-NEXT:ret
+;
+; CHECK-FP16-LABEL: div_f16:
+; CHECK-FP16:   // %bb.0:
+; CHECK-FP16-NEXT:fdiv h0, h0, h1
+; CHECK-FP16-NEXT:ret
+  %val = call half @llvm.experimental.constrained.fdiv.f16(half %x, half %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret half %val
+}
+
+define half @frem_f16(half %x, half %y) #0 {
+; CHECK-LABEL: frem_f16:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:str x30, [sp, #-16]! // 8-byte Folded Spill
+; CHECK-NEXT:.cfi_def_cfa_offset 16
+; CHECK-NEXT:.cfi_offset w30, -16
+; CHECK-NEXT:fcvt s1, h1
+; CHECK-NEXT:fcvt s0, h0
+; CHECK-NEXT:bl fmodf
+; CHECK-NEXT:fcvt h0, s0
+; CHECK-NEXT:ldr x30, [sp], #16 // 8-byte Folded Reload
+; CHECK-NEXT:ret
+  %val = call 

[PATCH] D118259: [AArch64] Adjust aarch64-neon-intrinsics-constrained test and un-XFAIL

2022-03-17 Thread John Brawn via Phabricator via cfe-commits
john.brawn added a comment.

Ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118259

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


[PATCH] D118259: [AArch64] Adjust aarch64-neon-intrinsics-constrained test and un-XFAIL

2022-03-07 Thread John Brawn via Phabricator via cfe-commits
john.brawn added a comment.
Herald added a project: All.

Ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118259

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


[PATCH] D118259: [AArch64] Adjust aarch64-neon-intrinsics-constrained test and un-XFAIL

2022-02-24 Thread John Brawn via Phabricator via cfe-commits
john.brawn added a comment.

In D118259#3275297 , @fhahn wrote:

> Does this clang test actually need to check the generated assembly? Shouldn't 
> it be enough to check that the correct intrinsics are generated?

I could remove the CHECK-ASM checks, but the other xyz-constrained.c tests 
(including non-aarch64 ones) all do this and it feels a bit weird to just do 
that to this test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118259

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


[PATCH] D117795: [AArch64] Add some missing strict FP vector lowering

2022-02-17 Thread John Brawn via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8e17c9613f36: [AArch64] Add some missing strict FP vector 
lowering (authored by john.brawn).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117795

Files:
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/test/CodeGen/AArch64/fp-intrinsics-vector.ll

Index: llvm/test/CodeGen/AArch64/fp-intrinsics-vector.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/fp-intrinsics-vector.ll
@@ -0,0 +1,886 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=aarch64-none-eabi %s -disable-strictnode-mutation -o - | FileCheck %s
+; RUN: llc -mtriple=aarch64-none-eabi -global-isel=true -global-isel-abort=2 -disable-strictnode-mutation %s -o - | FileCheck %s
+
+; Check that constrained fp vector intrinsics are correctly lowered.
+
+
+; Single-precision intrinsics
+
+define <4 x float> @add_v4f32(<4 x float> %x, <4 x float> %y) #0 {
+; CHECK-LABEL: add_v4f32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:fadd v0.4s, v0.4s, v1.4s
+; CHECK-NEXT:ret
+  %val = call <4 x float> @llvm.experimental.constrained.fadd.v4f32(<4 x float> %x, <4 x float> %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret <4 x float> %val
+}
+
+define <4 x float> @sub_v4f32(<4 x float> %x, <4 x float> %y) #0 {
+; CHECK-LABEL: sub_v4f32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:fsub v0.4s, v0.4s, v1.4s
+; CHECK-NEXT:ret
+  %val = call <4 x float> @llvm.experimental.constrained.fsub.v4f32(<4 x float> %x, <4 x float> %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret <4 x float> %val
+}
+
+define <4 x float> @mul_v4f32(<4 x float> %x, <4 x float> %y) #0 {
+; CHECK-LABEL: mul_v4f32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:fmul v0.4s, v0.4s, v1.4s
+; CHECK-NEXT:ret
+  %val = call <4 x float> @llvm.experimental.constrained.fmul.v4f32(<4 x float> %x, <4 x float> %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret <4 x float> %val
+}
+
+define <4 x float> @div_v4f32(<4 x float> %x, <4 x float> %y) #0 {
+; CHECK-LABEL: div_v4f32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:fdiv v0.4s, v0.4s, v1.4s
+; CHECK-NEXT:ret
+  %val = call <4 x float> @llvm.experimental.constrained.fdiv.v4f32(<4 x float> %x, <4 x float> %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret <4 x float> %val
+}
+
+define <4 x float> @fma_v4f32(<4 x float> %x, <4 x float> %y, <4 x float> %z) #0 {
+; CHECK-LABEL: fma_v4f32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:fmla v2.4s, v1.4s, v0.4s
+; CHECK-NEXT:mov v0.16b, v2.16b
+; CHECK-NEXT:ret
+  %val = call <4 x float> @llvm.experimental.constrained.fma.v4f32(<4 x float> %x, <4 x float> %y, <4 x float> %z, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret <4 x float> %val
+}
+
+define <4 x i32> @fptosi_v4i32_v4f32(<4 x float> %x) #0 {
+; CHECK-LABEL: fptosi_v4i32_v4f32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:fcvtzs v0.4s, v0.4s
+; CHECK-NEXT:ret
+  %val = call <4 x i32> @llvm.experimental.constrained.fptosi.v4i32.v4f32(<4 x float> %x, metadata !"fpexcept.strict") #0
+  ret <4 x i32> %val
+}
+
+define <4 x i32> @fptoui_v4i32_v4f32(<4 x float> %x) #0 {
+; CHECK-LABEL: fptoui_v4i32_v4f32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:fcvtzu v0.4s, v0.4s
+; CHECK-NEXT:ret
+  %val = call <4 x i32> @llvm.experimental.constrained.fptoui.v4i32.v4f32(<4 x float> %x, metadata !"fpexcept.strict") #0
+  ret <4 x i32> %val
+}
+
+define <4 x i64> @fptosi_v4i64_v4f32(<4 x float> %x) #0 {
+; CHECK-LABEL: fptosi_v4i64_v4f32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:ext v1.16b, v0.16b, v0.16b, #8
+; CHECK-NEXT:fcvtl v0.2d, v0.2s
+; CHECK-NEXT:fcvtl v1.2d, v1.2s
+; CHECK-NEXT:fcvtzs v0.2d, v0.2d
+; CHECK-NEXT:fcvtzs v1.2d, v1.2d
+; CHECK-NEXT:ret
+  %val = call <4 x i64> @llvm.experimental.constrained.fptosi.v4i64.v4f32(<4 x float> %x, metadata !"fpexcept.strict") #0
+  ret <4 x i64> %val
+}
+
+define <4 x i64> @fptoui_v4i64_v4f32(<4 x float> %x) #0 {
+; CHECK-LABEL: fptoui_v4i64_v4f32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:ext v1.16b, v0.16b, v0.16b, #8
+; CHECK-NEXT:fcvtl v0.2d, v0.2s
+; CHECK-NEXT:fcvtl v1.2d, v1.2s
+; CHECK-NEXT:fcvtzu v0.2d, v0.2d
+; CHECK-NEXT:fcvtzu v1.2d, v1.2d
+; CHECK-NEXT:ret
+  %val = call <4 x i64> @llvm.experimental.constrained.fptoui.v4i64.v4f32(<4 x float> %x, metadata !"fpexcept.strict") #0
+  ret <4 x i64> %val
+}
+
+define <4 x float> @sitofp_v4f32_v4i32(<4 x i32> %x) #0 {
+; CHECK-LABEL: sitofp_v4f32_v4i32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:scvtf v0.4s, v0.4s
+; CHECK-NEXT:ret
+  %val = call <4 x float> @llvm.experimental.constrained.sitofp.v4f32.v4i32(<4 x i32> %x, metadata 

[PATCH] D118257: [AArch64] Generate fcmps when appropriate for neon intrinsics

2022-02-04 Thread John Brawn via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbca998ed3c9a: [AArch64] Generate fcmps when appropriate for 
neon intrinsics (authored by john.brawn).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118257

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c

Index: clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
===
--- clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
+++ clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
@@ -585,7 +585,7 @@
 
 // COMMON-LABEL: test_vcges_f32
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp oge float %a, %b
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f32(float %a, float %b, metadata !"oge", metadata !"fpexcept.strict")
+// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f32(float %a, float %b, metadata !"oge", metadata !"fpexcept.strict")
 // CHECK-ASM: fcmp s{{[0-9]+}}, s{{[0-9]+}}
 // CHECK-ASM-NEXT:cset {{w[0-9]+}}, ge
 // COMMONIR:  [[VCMPD_I:%.*]] = sext i1 [[TMP0]] to i32
@@ -596,7 +596,7 @@
 
 // COMMON-LABEL: test_vcged_f64
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp oge double %a, %b
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f64(double %a, double %b, metadata !"oge", metadata !"fpexcept.strict")
+// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f64(double %a, double %b, metadata !"oge", metadata !"fpexcept.strict")
 // CHECK-ASM: fcmp d{{[0-9]+}}, d{{[0-9]+}}
 // CHECK-ASM-NEXT:cset {{w[0-9]+}}, ge
 // COMMONIR:  [[VCMPD_I:%.*]] = sext i1 [[TMP0]] to i64
@@ -607,7 +607,7 @@
 
 // COMMON-LABEL: test_vcgezs_f32
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp oge float %a, 0.00e+00
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f32(float %a, float 0.00e+00, metadata !"oge", metadata !"fpexcept.strict")
+// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f32(float %a, float 0.00e+00, metadata !"oge", metadata !"fpexcept.strict")
 // CHECK-ASM: fcmp s{{[0-9]+}}, #0.0
 // CHECK-ASM-NEXT:cset {{w[0-9]+}}, ge
 // COMMONIR:  [[VCGEZ_I:%.*]] = sext i1 [[TMP0]] to i32
@@ -618,7 +618,7 @@
 
 // COMMON-LABEL: test_vcgezd_f64
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp oge double %a, 0.00e+00
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f64(double %a, double 0.00e+00, metadata !"oge", metadata !"fpexcept.strict")
+// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f64(double %a, double 0.00e+00, metadata !"oge", metadata !"fpexcept.strict")
 // CHECK-ASM: fcmp d{{[0-9]+}}, #0.0
 // CHECK-ASM-NEXT:cset {{w[0-9]+}}, ge
 // COMMONIR:  [[VCGEZ_I:%.*]] = sext i1 [[TMP0]] to i64
@@ -629,7 +629,7 @@
 
 // COMMON-LABEL: test_vcgts_f32
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp ogt float %a, %b
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f32(float %a, float %b, metadata !"ogt", metadata !"fpexcept.strict")
+// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f32(float %a, float %b, metadata !"ogt", metadata !"fpexcept.strict")
 // CHECK-ASM: fcmp s{{[0-9]+}}, s{{[0-9]+}}
 // CHECK-ASM-NEXT:cset {{w[0-9]+}}, gt
 // COMMONIR:  [[VCMPD_I:%.*]] = sext i1 [[TMP0]] to i32
@@ -640,7 +640,7 @@
 
 // COMMON-LABEL: test_vcgtd_f64
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp ogt double %a, %b
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f64(double %a, double %b, metadata !"ogt", metadata !"fpexcept.strict")
+// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f64(double %a, double %b, metadata !"ogt", metadata !"fpexcept.strict")
 // CHECK-ASM: fcmp d{{[0-9]+}}, d{{[0-9]+}}
 // CHECK-ASM-NEXT:cset {{w[0-9]+}}, gt
 // COMMONIR:  [[VCMPD_I:%.*]] = sext i1 [[TMP0]] to i64
@@ -651,7 +651,7 @@
 
 // COMMON-LABEL: test_vcgtzs_f32
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp ogt float %a, 0.00e+00
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f32(float %a, float 0.00e+00, metadata !"ogt", metadata !"fpexcept.strict")
+// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f32(float %a, float 0.00e+00, metadata !"ogt", metadata !"fpexcept.strict")
 // CHECK-ASM: fcmp s{{[0-9]+}}, #0.0
 // CHECK-ASM-NEXT:cset {{w[0-9]+}}, gt
 // COMMONIR:  [[VCGTZ_I:%.*]] = sext i1 [[TMP0]] to i32
@@ -662,7 +662,7 @@
 
 // COMMON-LABEL: test_vcgtzd_f64
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp ogt double %a, 0.00e+00
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f64(double %a, double 0.00e+00, metadata !"ogt", 

[PATCH] D117795: [AArch64] Add some missing strict FP vector lowering

2022-02-02 Thread John Brawn via Phabricator via cfe-commits
john.brawn updated this revision to Diff 405213.
john.brawn added a comment.

Update based on review comments and adjust formatting.


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

https://reviews.llvm.org/D117795

Files:
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/test/CodeGen/AArch64/fp-intrinsics-vector.ll

Index: llvm/test/CodeGen/AArch64/fp-intrinsics-vector.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/fp-intrinsics-vector.ll
@@ -0,0 +1,886 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=aarch64-none-eabi %s -disable-strictnode-mutation -o - | FileCheck %s
+; RUN: llc -mtriple=aarch64-none-eabi -global-isel=true -global-isel-abort=2 -disable-strictnode-mutation %s -o - | FileCheck %s
+
+; Check that constrained fp vector intrinsics are correctly lowered.
+
+
+; Single-precision intrinsics
+
+define <4 x float> @add_v4f32(<4 x float> %x, <4 x float> %y) #0 {
+; CHECK-LABEL: add_v4f32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:fadd v0.4s, v0.4s, v1.4s
+; CHECK-NEXT:ret
+  %val = call <4 x float> @llvm.experimental.constrained.fadd.v4f32(<4 x float> %x, <4 x float> %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret <4 x float> %val
+}
+
+define <4 x float> @sub_v4f32(<4 x float> %x, <4 x float> %y) #0 {
+; CHECK-LABEL: sub_v4f32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:fsub v0.4s, v0.4s, v1.4s
+; CHECK-NEXT:ret
+  %val = call <4 x float> @llvm.experimental.constrained.fsub.v4f32(<4 x float> %x, <4 x float> %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret <4 x float> %val
+}
+
+define <4 x float> @mul_v4f32(<4 x float> %x, <4 x float> %y) #0 {
+; CHECK-LABEL: mul_v4f32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:fmul v0.4s, v0.4s, v1.4s
+; CHECK-NEXT:ret
+  %val = call <4 x float> @llvm.experimental.constrained.fmul.v4f32(<4 x float> %x, <4 x float> %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret <4 x float> %val
+}
+
+define <4 x float> @div_v4f32(<4 x float> %x, <4 x float> %y) #0 {
+; CHECK-LABEL: div_v4f32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:fdiv v0.4s, v0.4s, v1.4s
+; CHECK-NEXT:ret
+  %val = call <4 x float> @llvm.experimental.constrained.fdiv.v4f32(<4 x float> %x, <4 x float> %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret <4 x float> %val
+}
+
+define <4 x float> @fma_v4f32(<4 x float> %x, <4 x float> %y, <4 x float> %z) #0 {
+; CHECK-LABEL: fma_v4f32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:fmla v2.4s, v1.4s, v0.4s
+; CHECK-NEXT:mov v0.16b, v2.16b
+; CHECK-NEXT:ret
+  %val = call <4 x float> @llvm.experimental.constrained.fma.v4f32(<4 x float> %x, <4 x float> %y, <4 x float> %z, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret <4 x float> %val
+}
+
+define <4 x i32> @fptosi_v4i32_v4f32(<4 x float> %x) #0 {
+; CHECK-LABEL: fptosi_v4i32_v4f32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:fcvtzs v0.4s, v0.4s
+; CHECK-NEXT:ret
+  %val = call <4 x i32> @llvm.experimental.constrained.fptosi.v4i32.v4f32(<4 x float> %x, metadata !"fpexcept.strict") #0
+  ret <4 x i32> %val
+}
+
+define <4 x i32> @fptoui_v4i32_v4f32(<4 x float> %x) #0 {
+; CHECK-LABEL: fptoui_v4i32_v4f32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:fcvtzu v0.4s, v0.4s
+; CHECK-NEXT:ret
+  %val = call <4 x i32> @llvm.experimental.constrained.fptoui.v4i32.v4f32(<4 x float> %x, metadata !"fpexcept.strict") #0
+  ret <4 x i32> %val
+}
+
+define <4 x i64> @fptosi_v4i64_v4f32(<4 x float> %x) #0 {
+; CHECK-LABEL: fptosi_v4i64_v4f32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:ext v1.16b, v0.16b, v0.16b, #8
+; CHECK-NEXT:fcvtl v0.2d, v0.2s
+; CHECK-NEXT:fcvtl v1.2d, v1.2s
+; CHECK-NEXT:fcvtzs v0.2d, v0.2d
+; CHECK-NEXT:fcvtzs v1.2d, v1.2d
+; CHECK-NEXT:ret
+  %val = call <4 x i64> @llvm.experimental.constrained.fptosi.v4i64.v4f32(<4 x float> %x, metadata !"fpexcept.strict") #0
+  ret <4 x i64> %val
+}
+
+define <4 x i64> @fptoui_v4i64_v4f32(<4 x float> %x) #0 {
+; CHECK-LABEL: fptoui_v4i64_v4f32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:ext v1.16b, v0.16b, v0.16b, #8
+; CHECK-NEXT:fcvtl v0.2d, v0.2s
+; CHECK-NEXT:fcvtl v1.2d, v1.2s
+; CHECK-NEXT:fcvtzu v0.2d, v0.2d
+; CHECK-NEXT:fcvtzu v1.2d, v1.2d
+; CHECK-NEXT:ret
+  %val = call <4 x i64> @llvm.experimental.constrained.fptoui.v4i64.v4f32(<4 x float> %x, metadata !"fpexcept.strict") #0
+  ret <4 x i64> %val
+}
+
+define <4 x float> @sitofp_v4f32_v4i32(<4 x i32> %x) #0 {
+; CHECK-LABEL: sitofp_v4f32_v4i32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:scvtf v0.4s, v0.4s
+; CHECK-NEXT:ret
+  %val = call <4 x float> @llvm.experimental.constrained.sitofp.v4f32.v4i32(<4 x i32> %x, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret <4 x float> %val
+}
+
+define <4 x float> @uitofp_v4f32_v4i32(<4 x i32> %x) #0 {
+; 

[PATCH] D117795: [AArch64] Add some missing strict FP vector lowering

2022-02-02 Thread John Brawn via Phabricator via cfe-commits
john.brawn planned changes to this revision.
john.brawn added inline comments.



Comment at: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp:1484
+  // of the vector comparison instructions.
+  setOperationAction(ISD::STRICT_FSETCCS, VT, Expand);
+  // FIXME: We could potentially make use of the vector comparison instructions

dmgreen wrote:
> john.brawn wrote:
> > dmgreen wrote:
> > > Can you split this into a separate patch? I know I sound like a broken 
> > > record, but it doesn't seem to be related to the converts below.
> > > 
> > > Also pre-committing as much of the test that works as possible would cut 
> > > it down from this patch quite a bit.
> > Instead of a separate patch just for these two, it would probably make more 
> > sense to move them into D114946 with the rest of the setOperationAction 
> > lines.
> > 
> > On the test, without the changes in this patch it hits an assertion failure 
> > so as a separate commit before this it wouldn't be able to test anything.
> D114946 is already pretty big :)
> 
> What about the add_v4f32 test (for example) requires the changes in this 
> patch? That's what I meant by "precommit as much as possible".
> 
> My other question about this was going to be - why can't we use the vector 
> instructions for STRICT_FSETCCS? The FCMGE and FCMGT look like they would set 
> exception flags to me, but I may be misunderstanding some part of it.
> D114946 is already pretty big :)
A bit, though only in terms of number of lines. Conceptually it fairly simple, 
as it's almost all "strict_xyz can be handled the same as (non-strict) xyz".

> What about the add_v4f32 test (for example) requires the changes in this 
> patch? That's what I meant by "precommit as much as possible".
I _could_ try and disentangle the parts that compile without this patch, but it 
seems like more work than it's worth.

> My other question about this was going to be - why can't we use the vector 
> instructions for STRICT_FSETCCS? The FCMGE and FCMGT look like they would set 
> exception flags to me, but I may be misunderstanding some part of it.

Hmm, it looks like the FCMXY instructions are inconsistent in their handling of 
NaNs. FCMEQ performs a quiet comparison (only signalling NaNs raise an 
exception) like FCMP and STRICT_FSETCC, FCMGT etc. performs a signalling 
comparison (all NaNs raise an exception) like FCMPE and STRICT_FSETCCS. I'll 
adjust the comments (and also move this to D114946).


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

https://reviews.llvm.org/D117795

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


[PATCH] D117795: [AArch64] Add some missing strict FP vector lowering

2022-02-01 Thread John Brawn via Phabricator via cfe-commits
john.brawn added inline comments.



Comment at: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp:1484
+  // of the vector comparison instructions.
+  setOperationAction(ISD::STRICT_FSETCCS, VT, Expand);
+  // FIXME: We could potentially make use of the vector comparison instructions

dmgreen wrote:
> Can you split this into a separate patch? I know I sound like a broken 
> record, but it doesn't seem to be related to the converts below.
> 
> Also pre-committing as much of the test that works as possible would cut it 
> down from this patch quite a bit.
Instead of a separate patch just for these two, it would probably make more 
sense to move them into D114946 with the rest of the setOperationAction lines.

On the test, without the changes in this patch it hits an assertion failure so 
as a separate commit before this it wouldn't be able to test anything.


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

https://reviews.llvm.org/D117795

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


[PATCH] D118044: [ARM] Undeprecate complex IT blocks

2022-01-27 Thread John Brawn via Phabricator via cfe-commits
john.brawn added inline comments.



Comment at: llvm/test/CodeGen/ARM/2013-05-05-IfConvertBug.ll:1-4
 ; RUN: llc < %s -mtriple=thumbv7-apple-ios -mcpu=cortex-a8 | FileCheck %s
 ; RUN: llc < %s -mtriple=thumbv8 | FileCheck -check-prefix=CHECK-V8 %s
-; RUN: llc < %s -mtriple=thumbv7 -arm-restrict-it | FileCheck 
-check-prefix=CHECK-V8 %s
+; RUN: llc < %s -mtriple=thumbv8 -arm-restrict-it | FileCheck 
-check-prefix=CHECK-RESTRICT-IT %s
+; RUN: llc < %s -mtriple=thumbv7 -arm-restrict-it | FileCheck 
-check-prefix=CHECK-RESTRICT-IT %s

The code generated for -mtriple=thumbv7-apple-ios and -mtriple=thumbv8 is 
almost the same, so instead of changing the CHECK-V8 lines and adding new 
CHECK-RESTRICT-IT lines, you could instead rename all of the current CHECK-V8 
lines to CHECK-RESTRICT-IT and instead have -mtriple=thumbv8 check the CHECK 
lines, i.e.
; RUN: llc < %s -mtriple=thumbv8 | FileCheck %s




Comment at: llvm/test/CodeGen/ARM/arm-and-tst-peephole.ll:42-62
 ; V8-LABEL: %tailrecurse.switch
 ; V8: cmp
+; V8-NEXT: it ne
+; V8-NEXT: bxne lr
+; V8-NEXT: @
+; V8-NEXT: @
+; V8-NEXT: orr.w

The checks here are kind of a mess, in that if we look at the generated code it 
looks like

```
.LBB0_1:@ %tailrecurse.switch
@   in Loop: Header=BB0_3 Depth=1
cmp r3, #1
it  ne
bxnelr
.LBB0_2:@ %sw.bb
@   in Loop: Header=BB0_3 Depth=1
orr.w   r1, r3, r1, lsl #1
addsr2, #4
add.w   r12, r12, #1
.LBB0_3:@ %tailrecurse
@ =>This Inner Loop Header: Depth=1
ldr r3, [r2, #-4]
andsr3, r3, #3
beq .LBB0_2
@ %bb.4:@ %tailrecurse.switch
@   in Loop: Header=BB0_3 Depth=1
cmp r3, #3
itt eq
moveq   r0, r2
bxeqlr
.LBB0_5:@ %tailrecurse.switch
@   in Loop: Header=BB0_3 Depth=1
cmp r3, #2
bne .LBB0_1
@ %bb.6:@ %sw.bb8
add r1, r12
add.w   r0, r0, r1
```
We have a load of V8-NEXT lines where it's variously: checking the instruction 
opcode; checking the entire instruction; checking for some text that appears in 
a comment (e.g. V8-NEXT: %tailrecurse.switch); checking that a comment appears 
but not what's in it (e.g. V8-NEXT: @).

I think it would make more sense to restructure so it's a sequence of
```
; V8-LABEL: @ %llvm_ir_name_in_a_comment
; V8: first_instruction_in_block
; V8-NEXT: next_instruction
; v8-NEXT: etc.
```



Comment at: llvm/test/CodeGen/ARM/arm-bf16-pcs.ll:190
 ; BASE-THUMB-NEXT:strh.w r0, [sp, #6]
+; BASE-THUMB-NEXT:uxth r1, r0
 ; BASE-THUMB-NEXT:mov r0, r5

This, and the cases in other tests where we have a uxth/uxtb that moves, looks 
rather strange and not something I'd expect given that there's no IT here. Do 
you know what's going on here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118044

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


[PATCH] D117795: [AArch64] Add some missing strict FP vector lowering

2022-01-27 Thread John Brawn via Phabricator via cfe-commits
john.brawn updated this revision to Diff 403614.
john.brawn retitled this revision from "[AArch64] Fixes for strict FP vector 
instructions" to "[AArch64] Add some missing strict FP vector lowering".
john.brawn edited the summary of this revision.
john.brawn added a comment.

The other parts of this have been split off into D118257 
, D118258 , 
and D118259 . I've also added some extra 
testing, as the clang test aarch64-neon-intrinsics-constrained wasn't actually 
testing all of the changes here.


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

https://reviews.llvm.org/D117795

Files:
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/test/CodeGen/AArch64/fp-intrinsics-vector.ll

Index: llvm/test/CodeGen/AArch64/fp-intrinsics-vector.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/fp-intrinsics-vector.ll
@@ -0,0 +1,886 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=aarch64-none-eabi %s -disable-strictnode-mutation -o - | FileCheck %s
+; RUN: llc -mtriple=aarch64-none-eabi -global-isel=true -global-isel-abort=2 -disable-strictnode-mutation %s -o - | FileCheck %s
+
+; Check that constrained fp vector intrinsics are correctly lowered.
+
+
+; Single-precision intrinsics
+
+define <4 x float> @add_v4f32(<4 x float> %x, <4 x float> %y) #0 {
+; CHECK-LABEL: add_v4f32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:fadd v0.4s, v0.4s, v1.4s
+; CHECK-NEXT:ret
+  %val = call <4 x float> @llvm.experimental.constrained.fadd.v4f32(<4 x float> %x, <4 x float> %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret <4 x float> %val
+}
+
+define <4 x float> @sub_v4f32(<4 x float> %x, <4 x float> %y) #0 {
+; CHECK-LABEL: sub_v4f32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:fsub v0.4s, v0.4s, v1.4s
+; CHECK-NEXT:ret
+  %val = call <4 x float> @llvm.experimental.constrained.fsub.v4f32(<4 x float> %x, <4 x float> %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret <4 x float> %val
+}
+
+define <4 x float> @mul_v4f32(<4 x float> %x, <4 x float> %y) #0 {
+; CHECK-LABEL: mul_v4f32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:fmul v0.4s, v0.4s, v1.4s
+; CHECK-NEXT:ret
+  %val = call <4 x float> @llvm.experimental.constrained.fmul.v4f32(<4 x float> %x, <4 x float> %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret <4 x float> %val
+}
+
+define <4 x float> @div_v4f32(<4 x float> %x, <4 x float> %y) #0 {
+; CHECK-LABEL: div_v4f32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:fdiv v0.4s, v0.4s, v1.4s
+; CHECK-NEXT:ret
+  %val = call <4 x float> @llvm.experimental.constrained.fdiv.v4f32(<4 x float> %x, <4 x float> %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret <4 x float> %val
+}
+
+define <4 x float> @fma_v4f32(<4 x float> %x, <4 x float> %y, <4 x float> %z) #0 {
+; CHECK-LABEL: fma_v4f32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:fmla v2.4s, v1.4s, v0.4s
+; CHECK-NEXT:mov v0.16b, v2.16b
+; CHECK-NEXT:ret
+  %val = call <4 x float> @llvm.experimental.constrained.fma.v4f32(<4 x float> %x, <4 x float> %y, <4 x float> %z, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret <4 x float> %val
+}
+
+define <4 x i32> @fptosi_v4i32_v4f32(<4 x float> %x) #0 {
+; CHECK-LABEL: fptosi_v4i32_v4f32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:fcvtzs v0.4s, v0.4s
+; CHECK-NEXT:ret
+  %val = call <4 x i32> @llvm.experimental.constrained.fptosi.v4i32.v4f32(<4 x float> %x, metadata !"fpexcept.strict") #0
+  ret <4 x i32> %val
+}
+
+define <4 x i32> @fptoui_v4i32_v4f32(<4 x float> %x) #0 {
+; CHECK-LABEL: fptoui_v4i32_v4f32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:fcvtzu v0.4s, v0.4s
+; CHECK-NEXT:ret
+  %val = call <4 x i32> @llvm.experimental.constrained.fptoui.v4i32.v4f32(<4 x float> %x, metadata !"fpexcept.strict") #0
+  ret <4 x i32> %val
+}
+
+define <4 x i64> @fptosi_v4i64_v4f32(<4 x float> %x) #0 {
+; CHECK-LABEL: fptosi_v4i64_v4f32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:ext v1.16b, v0.16b, v0.16b, #8
+; CHECK-NEXT:fcvtl v0.2d, v0.2s
+; CHECK-NEXT:fcvtl v1.2d, v1.2s
+; CHECK-NEXT:fcvtzs v0.2d, v0.2d
+; CHECK-NEXT:fcvtzs v1.2d, v1.2d
+; CHECK-NEXT:ret
+  %val = call <4 x i64> @llvm.experimental.constrained.fptosi.v4i64.v4f32(<4 x float> %x, metadata !"fpexcept.strict") #0
+  ret <4 x i64> %val
+}
+
+define <4 x i64> @fptoui_v4i64_v4f32(<4 x float> %x) #0 {
+; CHECK-LABEL: fptoui_v4i64_v4f32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:ext v1.16b, v0.16b, v0.16b, #8
+; CHECK-NEXT:fcvtl v0.2d, v0.2s
+; CHECK-NEXT:fcvtl v1.2d, v1.2s
+; CHECK-NEXT:fcvtzu v0.2d, v0.2d
+; CHECK-NEXT:fcvtzu v1.2d, v1.2d
+; CHECK-NEXT:ret
+  %val = call <4 x i64> @llvm.experimental.constrained.fptoui.v4i64.v4f32(<4 x float> %x, metadata 

[PATCH] D118259: [AArch64] Adjust aarch64-neon-intrinsics-constrained test and un-XFAIL

2022-01-26 Thread John Brawn via Phabricator via cfe-commits
john.brawn created this revision.
john.brawn added reviewers: kpn, cameron.mcinally, dmgreen, t.p.northover.
Herald added a subscriber: kristof.beyls.
john.brawn requested review of this revision.
Herald added a project: clang.

This test no longer fails during isel, but does need the expected output to be 
adjusted to match the actual output.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118259

Files:
  clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c

Index: clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
===
--- clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
+++ clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
@@ -1,27 +1,24 @@
 // RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +neon \
 // RUN: -fallow-half-arguments-and-returns -S -disable-O0-optnone \
 // RUN:  -flax-vector-conversions=none -emit-llvm -o - %s | opt -S -mem2reg \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=COMMONIR --check-prefix=UNCONSTRAINED %s
+// RUN: | FileCheck --check-prefixes=COMMON,COMMONIR,UNCONSTRAINED %s
 // RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +neon \
 // RUN: -fallow-half-arguments-and-returns -S -disable-O0-optnone \
-// RUN:  -ffp-exception-behavior=strict \
+// RUN:  -ffp-exception-behavior=strict -fexperimental-strict-floating-point \
 // RUN:  -flax-vector-conversions=none -emit-llvm -o - %s | opt -S -mem2reg \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=COMMONIR --check-prefix=CONSTRAINED %s
+// RUN: | FileCheck --check-prefixes=COMMON,COMMONIR,CONSTRAINED %s
 // RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +neon \
 // RUN: -fallow-half-arguments-and-returns -S -disable-O0-optnone \
 // RUN:  -flax-vector-conversions=none -o - %s \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=CHECK-ASM %s
+// RUN: | FileCheck --check-prefixes=COMMON,CHECK-ASM,CHECK-ASM-UNCONSTRAINED %s
 // RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +neon \
 // RUN: -fallow-half-arguments-and-returns -S -disable-O0-optnone \
-// RUN:  -ffp-exception-behavior=strict \
+// RUN:  -ffp-exception-behavior=strict -fexperimental-strict-floating-point \
 // RUN:  -flax-vector-conversions=none -o - %s \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=CHECK-ASM %s
+// RUN: | FileCheck --check-prefixes=COMMON,CHECK-ASM,CHECK-ASM-CONSTRAINED %s
 
 // REQUIRES: aarch64-registered-target
 
-// Fails during instruction selection:
-// XFAIL: *
-
 // Test new aarch64 intrinsics and types but constrained
 
 #include 
@@ -278,7 +275,9 @@
 // COMMON-LABEL: test_vceq_f32
 // UNCONSTRAINED: [[CMP_I:%.*]] = fcmp oeq <2 x float> %v1, %v2
 // CONSTRAINED:   [[CMP_I:%.*]] = call <2 x i1> @llvm.experimental.constrained.fcmp.v2f32(<2 x float> %v1, <2 x float> %v2, metadata !"oeq", metadata !"fpexcept.strict")
-// CHECK-ASM: fcmeq v{{[0-9]+}}.2s, v{{[0-9]+}}.2s, v{{[0-9]+}}.2s
+// CHECK-ASM-UNCONSTRAINED: fcmeq v{{[0-9]+}}.2s, v{{[0-9]+}}.2s, v{{[0-9]+}}.2s
+// CHECK-ASM-CONSTRAINED: fcmp s{{[0-9]+}}, s{{[0-9]+}}
+// CHECK-ASM-CONSTRAINED: fcmp s{{[0-9]+}}, s{{[0-9]+}}
 // COMMONIR:  [[SEXT_I:%.*]] = sext <2 x i1> [[CMP_I]] to <2 x i32>
 // COMMONIR:  ret <2 x i32> [[SEXT_I]]
 uint32x2_t test_vceq_f32(float32x2_t v1, float32x2_t v2) {
@@ -299,7 +298,11 @@
 // COMMON-LABEL: test_vceqq_f32
 // UNCONSTRAINED: [[CMP_I:%.*]] = fcmp oeq <4 x float> %v1, %v2
 // CONSTRAINED:   [[CMP_I:%.*]] = call <4 x i1> @llvm.experimental.constrained.fcmp.v4f32(<4 x float> %v1, <4 x float> %v2, metadata !"oeq", metadata !"fpexcept.strict")
-// CHECK-ASM: fcmeq v{{[0-9]+}}.4s, v{{[0-9]+}}.4s, v{{[0-9]+}}.4s
+// CHECK-ASM-UNCONSTRAINED: fcmeq v{{[0-9]+}}.4s, v{{[0-9]+}}.4s, v{{[0-9]+}}.4s
+// CHECK-ASM-CONSTRAINED: fcmp s{{[0-9]+}}, s{{[0-9]+}}
+// CHECK-ASM-CONSTRAINED: fcmp s{{[0-9]+}}, s{{[0-9]+}}
+// CHECK-ASM-CONSTRAINED: fcmp s{{[0-9]+}}, s{{[0-9]+}}
+// CHECK-ASM-CONSTRAINED: fcmp s{{[0-9]+}}, s{{[0-9]+}}
 // COMMONIR:  [[SEXT_I:%.*]] = sext <4 x i1> [[CMP_I]] to <4 x i32>
 // COMMONIR:  ret <4 x i32> [[SEXT_I]]
 uint32x4_t test_vceqq_f32(float32x4_t v1, float32x4_t v2) {
@@ -309,7 +312,9 @@
 // COMMON-LABEL: test_vceqq_f64
 // UNCONSTRAINED: [[CMP_I:%.*]] = fcmp oeq <2 x double> %v1, %v2
 // CONSTRAINED:   [[CMP_I:%.*]] = call <2 x i1> @llvm.experimental.constrained.fcmp.v2f64(<2 x double> %v1, <2 x double> %v2, metadata !"oeq", metadata !"fpexcept.strict")
-// CHECK-ASM: fcmeq v{{[0-9]+}}.2d, v{{[0-9]+}}.2d, v{{[0-9]+}}.2d
+// CHECK-ASM-UNCONSTRAINED: fcmeq v{{[0-9]+}}.2d, v{{[0-9]+}}.2d, v{{[0-9]+}}.2d
+// CHECK-ASM-CONSTRAINED: fcmp d{{[0-9]+}}, d{{[0-9]+}}
+// CHECK-ASM-CONSTRAINED: fcmp d{{[0-9]+}}, d{{[0-9]+}}
 // COMMONIR:  [[SEXT_I:%.*]] = sext <2 x i1> [[CMP_I]] to <2 x i64>
 // COMMONIR:  ret <2 x i64> [[SEXT_I]]
 uint64x2_t test_vceqq_f64(float64x2_t v1, float64x2_t v2) {
@@ -319,7 +324,9 @@

[PATCH] D118257: [AArch64] Generate fcmps when appropriate for neon intrinsics

2022-01-26 Thread John Brawn via Phabricator via cfe-commits
john.brawn created this revision.
john.brawn added reviewers: kpn, cameron.mcinally, dmgreen, t.p.northover.
Herald added a subscriber: kristof.beyls.
john.brawn requested review of this revision.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118257

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c

Index: clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
===
--- clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
+++ clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
@@ -585,7 +585,7 @@
 
 // COMMON-LABEL: test_vcges_f32
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp oge float %a, %b
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f32(float %a, float %b, metadata !"oge", metadata !"fpexcept.strict")
+// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f32(float %a, float %b, metadata !"oge", metadata !"fpexcept.strict")
 // CHECK-ASM: fcmp s{{[0-9]+}}, s{{[0-9]+}}
 // CHECK-ASM-NEXT:cset {{w[0-9]+}}, ge
 // COMMONIR:  [[VCMPD_I:%.*]] = sext i1 [[TMP0]] to i32
@@ -596,7 +596,7 @@
 
 // COMMON-LABEL: test_vcged_f64
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp oge double %a, %b
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f64(double %a, double %b, metadata !"oge", metadata !"fpexcept.strict")
+// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f64(double %a, double %b, metadata !"oge", metadata !"fpexcept.strict")
 // CHECK-ASM: fcmp d{{[0-9]+}}, d{{[0-9]+}}
 // CHECK-ASM-NEXT:cset {{w[0-9]+}}, ge
 // COMMONIR:  [[VCMPD_I:%.*]] = sext i1 [[TMP0]] to i64
@@ -607,7 +607,7 @@
 
 // COMMON-LABEL: test_vcgezs_f32
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp oge float %a, 0.00e+00
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f32(float %a, float 0.00e+00, metadata !"oge", metadata !"fpexcept.strict")
+// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f32(float %a, float 0.00e+00, metadata !"oge", metadata !"fpexcept.strict")
 // CHECK-ASM: fcmp s{{[0-9]+}}, #0.0
 // CHECK-ASM-NEXT:cset {{w[0-9]+}}, ge
 // COMMONIR:  [[VCGEZ_I:%.*]] = sext i1 [[TMP0]] to i32
@@ -618,7 +618,7 @@
 
 // COMMON-LABEL: test_vcgezd_f64
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp oge double %a, 0.00e+00
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f64(double %a, double 0.00e+00, metadata !"oge", metadata !"fpexcept.strict")
+// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f64(double %a, double 0.00e+00, metadata !"oge", metadata !"fpexcept.strict")
 // CHECK-ASM: fcmp d{{[0-9]+}}, #0.0
 // CHECK-ASM-NEXT:cset {{w[0-9]+}}, ge
 // COMMONIR:  [[VCGEZ_I:%.*]] = sext i1 [[TMP0]] to i64
@@ -629,7 +629,7 @@
 
 // COMMON-LABEL: test_vcgts_f32
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp ogt float %a, %b
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f32(float %a, float %b, metadata !"ogt", metadata !"fpexcept.strict")
+// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f32(float %a, float %b, metadata !"ogt", metadata !"fpexcept.strict")
 // CHECK-ASM: fcmp s{{[0-9]+}}, s{{[0-9]+}}
 // CHECK-ASM-NEXT:cset {{w[0-9]+}}, gt
 // COMMONIR:  [[VCMPD_I:%.*]] = sext i1 [[TMP0]] to i32
@@ -640,7 +640,7 @@
 
 // COMMON-LABEL: test_vcgtd_f64
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp ogt double %a, %b
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f64(double %a, double %b, metadata !"ogt", metadata !"fpexcept.strict")
+// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f64(double %a, double %b, metadata !"ogt", metadata !"fpexcept.strict")
 // CHECK-ASM: fcmp d{{[0-9]+}}, d{{[0-9]+}}
 // CHECK-ASM-NEXT:cset {{w[0-9]+}}, gt
 // COMMONIR:  [[VCMPD_I:%.*]] = sext i1 [[TMP0]] to i64
@@ -651,7 +651,7 @@
 
 // COMMON-LABEL: test_vcgtzs_f32
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp ogt float %a, 0.00e+00
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f32(float %a, float 0.00e+00, metadata !"ogt", metadata !"fpexcept.strict")
+// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f32(float %a, float 0.00e+00, metadata !"ogt", metadata !"fpexcept.strict")
 // CHECK-ASM: fcmp s{{[0-9]+}}, #0.0
 // CHECK-ASM-NEXT:cset {{w[0-9]+}}, gt
 // COMMONIR:  [[VCGTZ_I:%.*]] = sext i1 [[TMP0]] to i32
@@ -662,7 +662,7 @@
 
 // COMMON-LABEL: test_vcgtzd_f64
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp ogt double %a, 0.00e+00
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f64(double %a, double 0.00e+00, metadata !"ogt", metadata !"fpexcept.strict")
+// CONSTRAINED:   [[TMP0:%.*]] = call i1 

[PATCH] D117795: [AArch64] Fixes for strict FP vector instructions

2022-01-20 Thread John Brawn via Phabricator via cfe-commits
john.brawn created this revision.
john.brawn added reviewers: kpn, cameron.mcinally, dmgreen, t.p.northover.
Herald added subscribers: hiraditya, kristof.beyls.
john.brawn requested review of this revision.
Herald added projects: clang, LLVM.
Herald added a subscriber: cfe-commits.

Fix several things so that vector instructions work correctly with strict FP:

- In clang generate fcmps when appropriate for neon intrinsics
- Fix legalization of scalarized strict FP vector operations
- Add some missing strict FP handling to AArch64TargetLowering
- Adjust the aarch64-neon-intrinsics-constrained.c clang test to expect the 
right output and un-XFAIL it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117795

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
  llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Index: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
===
--- llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -1477,6 +1477,17 @@
   if (VT.isFloatingPoint() && VT.getScalarSizeInBits() != 64)
 setOperationAction(ISD::STRICT_FP_ROUND, VT, Legal);
 
+  // Signalling comparison has to be expanded as there's no signalling version
+  // of the vector comparison instructions.
+  setOperationAction(ISD::STRICT_FSETCCS, VT, Expand);
+  // FIXME: We could potentially make use of the vector comparison instructions
+  // for STRICT_FSETCC, but some kinds of comparison require more than one
+  // FCM instruction which wouldn't be valid so would need to get expanded
+  // instead. The lowering also involves target-specific ISD nodes so we would
+  // likely need to add strict versions of all of them and handle them
+  // appropriately.
+  setOperationAction(ISD::STRICT_FSETCC, VT, Expand);
+
   if (Subtarget->isLittleEndian()) {
 for (unsigned im = (unsigned)ISD::PRE_INC;
  im != (unsigned)ISD::LAST_INDEXED_MODE; ++im) {
@@ -3377,7 +3388,8 @@
   // Warning: We maintain cost tables in AArch64TargetTransformInfo.cpp.
   // Any additional optimization in this function should be recorded
   // in the cost tables.
-  EVT InVT = Op.getOperand(0).getValueType();
+  bool IsStrict = Op->isStrictFPOpcode();
+  EVT InVT = Op.getOperand(IsStrict ? 1 : 0).getValueType();
   EVT VT = Op.getValueType();
 
   if (VT.isScalableVector()) {
@@ -3397,6 +3409,13 @@
   !Subtarget->hasFullFP16()) {
 MVT NewVT = MVT::getVectorVT(MVT::f32, NumElts);
 SDLoc dl(Op);
+if (IsStrict) {
+  SDValue Ext = DAG.getNode(ISD::STRICT_FP_EXTEND, dl,
+{NewVT, MVT::Other},
+{Op.getOperand(0), Op.getOperand(1)});
+  return DAG.getNode(Op.getOpcode(), dl, {VT, MVT::Other},
+ {Ext.getValue(1), Ext.getValue(0)});
+}
 return DAG.getNode(
 Op.getOpcode(), dl, Op.getValueType(),
 DAG.getNode(ISD::FP_EXTEND, dl, NewVT, Op.getOperand(0)));
@@ -3406,6 +3425,13 @@
   uint64_t InVTSize = InVT.getFixedSizeInBits();
   if (VTSize < InVTSize) {
 SDLoc dl(Op);
+if (IsStrict ) {
+  InVT = InVT.changeVectorElementTypeToInteger();
+  SDValue Cv = DAG.getNode(Op.getOpcode(), dl, {InVT, MVT::Other},
+   {Op.getOperand(0), Op.getOperand(1)});
+  SDValue Trunc = DAG.getNode(ISD::TRUNCATE, dl, VT, Cv);
+  return DAG.getMergeValues({Trunc, Cv.getValue(1)}, dl);
+}
 SDValue Cv =
 DAG.getNode(Op.getOpcode(), dl, InVT.changeVectorElementTypeToInteger(),
 Op.getOperand(0));
@@ -3417,10 +3443,33 @@
 MVT ExtVT =
 MVT::getVectorVT(MVT::getFloatingPointVT(VT.getScalarSizeInBits()),
  VT.getVectorNumElements());
+if (IsStrict) {
+  SDValue Ext = DAG.getNode(ISD::STRICT_FP_EXTEND, dl,
+{ExtVT, MVT::Other},
+{Op.getOperand(0), Op.getOperand(1)});
+  return DAG.getNode(Op.getOpcode(), dl, {VT, MVT::Other},
+ {Ext.getValue(1), Ext.getValue(0)});
+}
 SDValue Ext = DAG.getNode(ISD::FP_EXTEND, dl, ExtVT, Op.getOperand(0));
 return DAG.getNode(Op.getOpcode(), dl, VT, Ext);
   }
 
+  // Use a scalar operation for conversions between single-element vectors of
+  // the same size.
+  if (NumElts == 1) {
+SDLoc dl(Op);
+SDValue Extract = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl,
+  InVT.getScalarType(),
+  Op.getOperand(IsStrict ? 1 : 0),
+  DAG.getConstant(0, dl, MVT::i64));
+EVT ScalarVT = VT.getScalarType();
+SDValue ScalarCvt;
+if (IsStrict)
+  return DAG.getNode(Op.getOpcode(), dl, {ScalarVT, MVT::Other},
+ {Op.getOperand(0), Extract});
+ 

[PATCH] D110065: [AArch64] Add support for the 'R' architecture profile.

2021-10-27 Thread John Brawn via Phabricator via cfe-commits
john.brawn accepted this revision.
john.brawn added a comment.

LGTM.


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

https://reviews.llvm.org/D110065

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


[PATCH] D110065: [AArch64] Add support for the 'R' architecture profile.

2021-10-26 Thread John Brawn via Phabricator via cfe-commits
john.brawn added a comment.

In D110065#3087330 , @labrinea wrote:

> Added v8.1a_ops on AppleA10. However, the target parser lists it as v8.0a, 
> which seems odd. Out of the scope of this patch anyway.

Looking at the definition of A10 in target parser it doesn't have LSE, and 
that's required in 8.1-a. So it looks like it should have HasV8_0aOps.


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

https://reviews.llvm.org/D110065

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


[PATCH] D110065: [AArch64] Add support for the 'R' architecture profile.

2021-10-25 Thread John Brawn via Phabricator via cfe-commits
john.brawn accepted this revision.
john.brawn added a comment.
This revision is now accepted and ready to land.

I have one small comment, but otherwise LGTM.




Comment at: llvm/lib/Target/AArch64/MCTargetDesc/AArch64InstPrinter.cpp:1558
+
+  if (Reg && !isValidSysReg(Reg, Read, STI))
+Reg = AArch64SysReg::lookupSysRegByName(Reg->AltName);

It would be good to have a comment here explaining what's going on.


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

https://reviews.llvm.org/D110065

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


  1   2   >