[PATCH] D89197: [X86] Support -march=x86-64-v[234]

2020-10-11 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon requested changes to this revision.
RKSimon added a comment.
This revision now requires changes to proceed.

Please can you add an entry to the 12.00 release notes describing this? Maybe 
somewhere in the clang docs as well?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89197

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


[PATCH] D87565: [Sema] Improve const_cast conformance to N4261

2020-10-11 Thread Mark de Wever via Phabricator via cfe-commits
Mordante marked 2 inline comments as done.
Mordante added a comment.

Thanks for the additional information. I agree that the current situation seems 
a bit arbitrary.
I did some further research to see what GCC allows https://godbolt.org/. I've 
updated the patch to match that behavior.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87565

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


[PATCH] D87565: [Sema] Improve const_cast conformance to N4261

2020-10-11 Thread Mark de Wever via Phabricator via cfe-commits
Mordante updated this revision to Diff 297456.
Mordante added a comment.

Match the behavior of `const_cast` to match GCC's behavior. N4261 was proposed 
as solution to DR330. Since GCC allows the new `const_cast` behavior 
retroactively the patch also matches that behavior and no longer restricts the 
new usage to C++17.


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

https://reviews.llvm.org/D87565

Files:
  clang/lib/Sema/SemaCast.cpp
  clang/test/SemaCXX/const-cast.cpp


Index: clang/test/SemaCXX/const-cast.cpp
===
--- clang/test/SemaCXX/const-cast.cpp
+++ clang/test/SemaCXX/const-cast.cpp
@@ -1,6 +1,9 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++14 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
 
 struct A {};
 
@@ -80,3 +83,35 @@
 
 template 
 char *PR21845() { return const_cast((void)T::x); } // expected-error 
{{const_cast from 'void' to 'char *' is not allowed}}
+
+#if __cplusplus >= 201103L
+namespace N4261 {
+typedef int *A[3];
+typedef const int *const CA[3];
+
+CA &&r = A{};
+A &&r1 = const_cast(CA{}); // expected-error {{const_cast to 'N4261::A' 
(aka 'int *[3]'), which is not a reference, pointer-to-object, or 
pointer-to-data-member}}
+
+A &&r2 = const_cast(CA{});
+
+void f() {
+  typedef void (*F)();
+  F &&f = F{};
+  (void)const_cast(F{}); // expected-error {{const_cast to 'F' (aka 'void 
(*)()'), which is not a reference, pointer-to-object, or 
pointer-to-data-member}}
+  (void)const_cast(F{});
+
+  class C;
+  typedef void (C::*CF)();
+  CF &&cf = CF{};
+  (void)const_cast(CF{}); // expected-error {{const_cast to 'CF' (aka 
'void (C::*)()'), which is not a reference, pointer-to-object, or 
pointer-to-data-member}}
+  (void)const_cast(CF{});
+
+  typedef int C::*CM;
+  CM &&cm = CM{};
+  (void)const_cast(CM{});
+  (void)const_cast(CM{});
+}
+
+} // namespace N4261
+
+#endif
Index: clang/lib/Sema/SemaCast.cpp
===
--- clang/lib/Sema/SemaCast.cpp
+++ clang/lib/Sema/SemaCast.cpp
@@ -1780,7 +1780,7 @@
   QualType SrcType = SrcExpr.get()->getType();
   bool NeedToMaterializeTemporary = false;
 
-  if (const ReferenceType *DestTypeTmp =DestType->getAs()) {
+  if (const ReferenceType *DestTypeTmp = DestType->getAs()) {
 // C++11 5.2.11p4:
 //   if a pointer to T1 can be explicitly converted to the type "pointer to
 //   T2" using a const_cast, then the following conversions can also be
@@ -1801,16 +1801,29 @@
 }
 
 if (isa(DestTypeTmp) && SrcExpr.get()->isRValue()) {
-  if (!SrcType->isRecordType()) {
+  // C++17 [expr.const.cast]p3
+  // For two similar types T1 and T2, a prvalue of type T1 may be 
explicitly
+  // converted to the type T2 using a const_cast if, considering the
+  // cv-decompositions of both types, each P1i is the same as P2i for all 
i.
+  // The result of a const_cast refers to the original entity.
+  //
+  // The test for the similarity is done later in this function. Here it
+  // only avoids issuing an diagnostic for possible similar types.
+  //
+  // [expr.const.cast]p4
+  // The result of a reference const_cast refers to the original object if
+  // the operand is a glvalue and to the result of applying the temporary
+  // materialization conversion otherwise.
+  NeedToMaterializeTemporary =
+  SrcType->isRecordType() || SrcType->isArrayType() ||
+  SrcType->isFunctionPointerType() || SrcType->isMemberPointerType();
+
+  if (!NeedToMaterializeTemporary) {
 // Cannot const_cast non-class prvalue to rvalue reference type. But if
 // this is C-style, static_cast can do this.
 msg = diag::err_bad_cxx_cast_rvalue;
 return TC_NotApplicable;
   }
-
-  // Materialize the class prvalue so that the const_cast can bind a
-  // reference to it.
-  NeedToMaterializeTemporary = true;
 }
 
 // It's not completely clear under the standard whether we can


Index: clang/test/SemaCXX/const-cast.cpp
===
--- clang/test/SemaCXX/const-cast.cpp
+++ clang/test/SemaCXX/const-cast.cpp
@@ -1,6 +1,9 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++14 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
 
 struct A {};
 
@@ -80,3 +83,35 @@
 
 template 
 char *PR21845() { return const_cast((void)T::x); } // expected-error {{const_cast from 'void' to 'char *' is not allowed}}
+
+#if __cplusp

[PATCH] D88363: [CodeGen] Improve likelihood attribute branch weights

2020-10-11 Thread Mark de Wever via Phabricator via cfe-commits
Mordante added a comment.

In D88363#2319242 , @bdf wrote:

> In D88363#2319157 , @jmorse wrote:
>
>> In D88363#2317241 , @Mordante wrote:
>>
>>> Can you explain the kind of issues you're having?
>>
>> At the shallowest level, our -O1 produces different IR and fails the test, 
>> which is more or less our problem; however my understanding is that tests in 
>> the LLVM project / subprojects should aim to test as little amount of code 
>> as possible. Relying on all of -O1 makes it a brittle test -- changes to any 
>> optimisation pass enabled in -O1 could cause this test to fail spuriously.
>>
>> Instead, I believe the test should be in two parts:
>>
>> - One checking clang produces the correct /unoptimised/ IR output
>> - One or more checking that the consuming IR passes do-the-right-thing
>
> As I see, the intent of the test is not so much to verify a certain expected 
> output, but more to verify that two styles of likelihood hints in C code 
> produce the same code structure and branch weights. Theses styles are 
> likely/unlikely-annotations, and use of __builtin_expect in the if condition. 
> But the processing of these two is quite different:
>
> - for likely/unlikely annotations, branch weights are added immediately in 
> the initial CodeGen
> - __builtin_expect is first translated straightforward to an expect 
> intrinsic, then processed by a later lower-expect pass
>
> To make the test less brittle, would it be possible to explicitly select only 
> the optimization passes that are needed?

Indeed verifying the output of the likelihood attributes against 
`__builtin_expect` is exactly what's required. But I think I can make the test 
less brittle by using the following command. This only runs the lower expect 
pass, which lowers the `__builtin_expect`.
`RUN: %clang_cc1 -O1 -disable-llvm-passes -emit-llvm %s -o - 
-triple=x86_64-linux-gnu | opt --lower-expect -S | FileCheck %s`

I'll work on a patch to solve the issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88363

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


[PATCH] D89194: [clang-tidy] Fix crash in readability-function-cognitive-complexity on weak refs

2020-10-11 Thread Zinovy Nis via Phabricator via cfe-commits
zinovy.nis updated this revision to Diff 297458.

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

https://reviews.llvm.org/D89194

Files:
  clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
  clang/include/clang/ASTMatchers/ASTMatchers.h


Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4647,6 +4647,17 @@
   return Node.isDefaulted();
 }
 
+/// Matches weak function declarations.
+///
+/// Given:
+/// \code
+///   void foo() __attribute__((__weakref__("__foo")));
+///   void bar();
+/// \endcode
+/// functionDecl(isWeak())
+///   matches the weak declaration foo, but not bar.
+AST_MATCHER(FunctionDecl, isWeak) { return Node.isWeak(); }
+
 /// Matches functions that have a dynamic exception specification.
 ///
 /// Given:
Index: 
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
@@ -1013,3 +1013,5 @@
 
   templatedFunction();
 }
+
+static void pr47779_dont_crash_on_weak() 
__attribute__((__weakref__("__pr47779_dont_crash_on_weak")));
Index: 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
===
--- 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
+++ 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
@@ -501,9 +501,9 @@
 
 void FunctionCognitiveComplexityCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
-  functionDecl(
-  allOf(isDefinition(), unless(anyOf(isDefaulted(), isDeleted(),
- isImplicit(), isInstantiated()
+  functionDecl(isDefinition(),
+   unless(anyOf(isDefaulted(), isDeleted(), isImplicit(),
+isInstantiated(), isWeak(
   .bind("func"),
   this);
 }


Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4647,6 +4647,17 @@
   return Node.isDefaulted();
 }
 
+/// Matches weak function declarations.
+///
+/// Given:
+/// \code
+///   void foo() __attribute__((__weakref__("__foo")));
+///   void bar();
+/// \endcode
+/// functionDecl(isWeak())
+///   matches the weak declaration foo, but not bar.
+AST_MATCHER(FunctionDecl, isWeak) { return Node.isWeak(); }
+
 /// Matches functions that have a dynamic exception specification.
 ///
 /// Given:
Index: clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
@@ -1013,3 +1013,5 @@
 
   templatedFunction();
 }
+
+static void pr47779_dont_crash_on_weak() __attribute__((__weakref__("__pr47779_dont_crash_on_weak")));
Index: clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
@@ -501,9 +501,9 @@
 
 void FunctionCognitiveComplexityCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
-  functionDecl(
-  allOf(isDefinition(), unless(anyOf(isDefaulted(), isDeleted(),
- isImplicit(), isInstantiated()
+  functionDecl(isDefinition(),
+   unless(anyOf(isDefaulted(), isDeleted(), isImplicit(),
+isInstantiated(), isWeak(
   .bind("func"),
   this);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89204: Make likelihood lit test less brittle

2020-10-11 Thread Mark de Wever via Phabricator via cfe-commits
Mordante created this revision.
Mordante added a reviewer: jmorse.
Mordante added a project: clang.
Mordante requested review of this revision.

Jeremy Morse discovered an issue with the lit test introduced in D88363 
. The test gives different results for Sony's 
`-O1`.

The test needs to run at `-O1` otherwise the likelihood attribute will be 
ignored. Instead of running all `-O1` passes it only runs the lower-expect pass 
which is needed to lower `__builtin_expect`.

@jmorse  can you verify this fixes Sony's issue?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89204

Files:
  clang/test/CodeGenCXX/attr-likelihood-if-vs-builtin-expect.cpp

Index: clang/test/CodeGenCXX/attr-likelihood-if-vs-builtin-expect.cpp
===
--- clang/test/CodeGenCXX/attr-likelihood-if-vs-builtin-expect.cpp
+++ clang/test/CodeGenCXX/attr-likelihood-if-vs-builtin-expect.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -O1 -emit-llvm %s -o - -triple=x86_64-linux-gnu | FileCheck %s
+// RUN: %clang_cc1 -O1 -disable-llvm-passes -emit-llvm %s -o - -triple=x86_64-linux-gnu | opt --lower-expect -S | FileCheck %s
 
 // Verifies the output of __builtin_expect versus the output of the likelihood
 // attributes. They should generate the same probabilities for the branches.
@@ -9,9 +9,9 @@
 
 void ab1(int &i) {
   // CHECK-LABEL: define{{.*}}ab1
-  // CHECK: br {{.*}} !prof !2
-  // CHECK: br {{.*}} !prof !2
-  // CHECK: br {{.*}} !prof !2
+  // CHECK: br {{.*}} !prof !6
+  // CHECK: br {{.*}} !prof !6
+  // CHECK: br {{.*}} !prof !6
   if (__builtin_expect(a() && b() && a(), 1)) {
 ++i;
   } else {
@@ -21,9 +21,9 @@
 
 void al(int &i) {
   // CHECK-LABEL: define{{.*}}al
-  // CHECK: br {{.*}} !prof !2
-  // CHECK: br {{.*}} !prof !2
-  // CHECK: br {{.*}} !prof !2
+  // CHECK: br {{.*}} !prof !6
+  // CHECK: br {{.*}} !prof !6
+  // CHECK: br {{.*}} !prof !6
   if (a() && b() && c()) [[likely]] {
 ++i;
   } else {
@@ -33,9 +33,10 @@
 
 void ab0(int &i) {
   // CHECK-LABEL: define{{.*}}ab0
-  // CHECK: br {{.*}}else{{$}}
-  // CHECK: br {{.*}}else{{$}}
-  // CHECK: br {{.*}} !prof !8
+  // CHECK: br {{.*}}end{{$}}
+  // CHECK: br {{.*}}end{{$}}
+  // CHECK: br {{.*}}end{{$}}
+  // CHECK: br {{.*}} !prof !10
   if (__builtin_expect(a() && b() && c(), 0)) {
 ++i;
   } else {
@@ -47,7 +48,7 @@
   // CHECK-LABEL: define{{.*}}au
   // CHECK: br {{.*}}else{{$}}
   // CHECK: br {{.*}}else{{$}}
-  // CHECK: br {{.*}} !prof !8
+  // CHECK: br {{.*}} !prof !10
   if (a() && b() && c()) [[unlikely]] {
 ++i;
   } else {
@@ -59,7 +60,8 @@
   // CHECK-LABEL: define{{.*}}ob1
   // CHECK: br {{.*}}false{{$}}
   // CHECK: br {{.*}}rhs{{$}}
-  // CHECK: br {{.*}} !prof !2
+  // CHECK: br {{.*}}end{{$}}
+  // CHECK: br {{.*}} !prof !6
   if (__builtin_expect(a() || b() || a(), 1)) {
 i = 0;
   } else {
@@ -71,7 +73,7 @@
   // CHECK-LABEL: define{{.*}}ol
   // CHECK: br {{.*}}false{{$}}
   // CHECK: br {{.*}}false2{{$}}
-  // CHECK: br {{.*}} !prof !2
+  // CHECK: br {{.*}} !prof !6
   if (a() || b() || c()) [[likely]] {
 i = 0;
   } else {
@@ -81,9 +83,9 @@
 
 void ob0(int &i) {
   // CHECK-LABEL: define{{.*}}ob0
-  // CHECK: br {{.*}} !prof !8
-  // CHECK: br {{.*}} !prof !8
-  // CHECK: br {{.*}} !prof !8
+  // CHECK: br {{.*}} !prof !10
+  // CHECK: br {{.*}} !prof !10
+  // CHECK: br {{.*}} !prof !10
   if (__builtin_expect(a() || b() || c(), 0)) {
 i = 0;
   } else {
@@ -93,9 +95,9 @@
 
 void ou(int &i) {
   // CHECK-LABEL: define{{.*}}ou
-  // CHECK: br {{.*}} !prof !8
-  // CHECK: br {{.*}} !prof !8
-  // CHECK: br {{.*}} !prof !8
+  // CHECK: br {{.*}} !prof !10
+  // CHECK: br {{.*}} !prof !10
+  // CHECK: br {{.*}} !prof !10
   if (a() || b() || c()) [[unlikely]] {
 i = 0;
   } else {
@@ -105,7 +107,7 @@
 
 void nb1(int &i) {
   // CHECK-LABEL: define{{.*}}nb1
-  // CHECK: storemerge{{.*}} !prof !8
+  // CHECK: br {{.*}} !prof !6
   if (__builtin_expect(!a(), 1)) {
 ++i;
   } else {
@@ -115,8 +117,8 @@
 
 void nl(int &i) {
   // CHECK-LABEL: define{{.*}}nl
-  // CHECK: storemerge{{.*}} !prof !8
-  if (!a()) [[likely]] {
+  // CHECK: br {{.*}} !prof !6
+  if (bool d = !a()) [[likely]] {
 ++i;
   } else {
 --i;
@@ -125,7 +127,7 @@
 
 void nb0(int &i) {
   // CHECK-LABEL: define{{.*}}nb0
-  // CHECK: storemerge{{.*}} !prof !2
+  // CHECK: br {{.*}} !prof !10
   if (__builtin_expect(!a(), 0)) {
 ++i;
   } else {
@@ -135,8 +137,8 @@
 
 void nu(int &i) {
   // CHECK-LABEL: define{{.*}}nu
-  // CHECK: storemerge{{.*}} !prof !2
-  if (!a()) [[unlikely]] {
+  // CHECK: br {{.*}} !prof !10
+  if (bool d = !a()) [[unlikely]] {
 ++i;
   } else {
 --i;
@@ -148,7 +150,7 @@
   // CHECK: br {{.*}}false{{$}}
   // CHECK: br {{.*}}end{{$}}
   // CHECK: br {{.*}}end{{$}}
-  // CHECK: storemerge{{.*}} !prof !2
+  // CHECK: br {{.*}} !prof !6
   if (__builtin_expect(a() ? b() : c(), 1)) {
 ++i;
   } else {
@@ 

[PATCH] D88363: [CodeGen] Improve likelihood attribute branch weights

2020-10-11 Thread Mark de Wever via Phabricator via cfe-commits
Mordante added a comment.

I created D89204  which hopefully fixes Sony's 
issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88363

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


[PATCH] D89194: [clang-tidy] Fix crash in readability-function-cognitive-complexity on weak refs

2020-10-11 Thread Zinovy Nis via Phabricator via cfe-commits
zinovy.nis updated this revision to Diff 297462.
zinovy.nis added a comment.

- Updated docs on the matcher.
- Register the new matcher.


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

https://reviews.llvm.org/D89194

Files:
  clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/Dynamic/Registry.cpp


Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -433,6 +433,7 @@
   REGISTER_MATCHER(isVirtual);
   REGISTER_MATCHER(isVirtualAsWritten);
   REGISTER_MATCHER(isVolatileQualified);
+  REGISTER_MATCHER(isWeak);
   REGISTER_MATCHER(isWritten);
   REGISTER_MATCHER(lValueReferenceType);
   REGISTER_MATCHER(labelDecl);
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4647,6 +4647,17 @@
   return Node.isDefaulted();
 }
 
+/// Matches weak function declarations.
+///
+/// Given:
+/// \code
+///   void foo() __attribute__((__weakref__("__foo")));
+///   void bar();
+/// \endcode
+/// functionDecl(isWeak())
+///   matches the weak declaration foo, but not bar.
+AST_MATCHER(FunctionDecl, isWeak) { return Node.isWeak(); }
+
 /// Matches functions that have a dynamic exception specification.
 ///
 /// Given:
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -3569,6 +3569,17 @@
 
 
 
+MatcherFunctionDecl>isWeak
+Matches weak function 
declarations.
+
+Given:
+  void foo() __attribute__((__weakref__("__foo")));
+  void bar();
+functionDecl(isWeak())
+  matches the weak declaration foo, but not bar.
+
+
+
 MatcherFunctionDecl>parameterCountIsunsigned N
 Matches 
FunctionDecls and FunctionProtoTypes that have a
 specific parameter count.
Index: 
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
@@ -1013,3 +1013,5 @@
 
   templatedFunction();
 }
+
+static void pr47779_dont_crash_on_weak() 
__attribute__((__weakref__("__pr47779_dont_crash_on_weak")));
Index: 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
===
--- 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
+++ 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
@@ -501,9 +501,9 @@
 
 void FunctionCognitiveComplexityCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
-  functionDecl(
-  allOf(isDefinition(), unless(anyOf(isDefaulted(), isDeleted(),
- isImplicit(), isInstantiated()
+  functionDecl(isDefinition(),
+   unless(anyOf(isDefaulted(), isDeleted(), isImplicit(),
+isInstantiated(), isWeak(
   .bind("func"),
   this);
 }


Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -433,6 +433,7 @@
   REGISTER_MATCHER(isVirtual);
   REGISTER_MATCHER(isVirtualAsWritten);
   REGISTER_MATCHER(isVolatileQualified);
+  REGISTER_MATCHER(isWeak);
   REGISTER_MATCHER(isWritten);
   REGISTER_MATCHER(lValueReferenceType);
   REGISTER_MATCHER(labelDecl);
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4647,6 +4647,17 @@
   return Node.isDefaulted();
 }
 
+/// Matches weak function declarations.
+///
+/// Given:
+/// \code
+///   void foo() __attribute__((__weakref__("__foo")));
+///   void bar();
+/// \endcode
+/// functionDecl(isWeak())
+///   matches the weak declaration foo, but not bar.
+AST_MATCHER(FunctionDecl, isWeak) { return Node.isWeak(); }
+
 /// Matches functions that have a dynamic exception specification.
 ///
 /// Given:
Index: clang/docs/LibASTMatchersReference.html
=

[PATCH] D89194: [clang-tidy] Fix crash in readability-function-cognitive-complexity on weak refs

2020-10-11 Thread Zinovy Nis via Phabricator via cfe-commits
zinovy.nis added a comment.

Done. Any other comments/ideas?


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

https://reviews.llvm.org/D89194

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


[PATCH] D89194: [clang-tidy] Fix crash in readability-function-cognitive-complexity on weak refs

2020-10-11 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri accepted this revision.
lebedev.ri added a comment.

Since this is touching more than just a clang-tidy check
i still want someone else to sign off,
but this looks ok to me in principle.
Thanks.


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

https://reviews.llvm.org/D89194

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


[PATCH] D89194: [clang-tidy] Fix crash in readability-function-cognitive-complexity on weak refs

2020-10-11 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth accepted this revision.
JonasToth added a comment.

LGTM.
Short reminder to please use full context patches. Its not an issue right now, 
but review sometimes just needs the context to understand the changes :)


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

https://reviews.llvm.org/D89194

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


[PATCH] D89194: [clang-tidy] Fix crash in readability-function-cognitive-complexity on weak refs

2020-10-11 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added inline comments.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:4658
+/// functionDecl(isWeak())
+///   matches the weak declaration foo, but not bar.
+AST_MATCHER(FunctionDecl, isWeak) { return Node.isWeak(); }

Short oversight. Please hightlight the code and matcher to make a 
differentation in the docs.


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

https://reviews.llvm.org/D89194

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


[PATCH] D89194: [clang-tidy] Fix crash in readability-function-cognitive-complexity on weak refs

2020-10-11 Thread Zinovy Nis via Phabricator via cfe-commits
zinovy.nis updated this revision to Diff 297463.
zinovy.nis added a comment.

Full diff.


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

https://reviews.llvm.org/D89194

Files:
  clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/Dynamic/Registry.cpp


Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -433,6 +433,7 @@
   REGISTER_MATCHER(isVirtual);
   REGISTER_MATCHER(isVirtualAsWritten);
   REGISTER_MATCHER(isVolatileQualified);
+  REGISTER_MATCHER(isWeak);
   REGISTER_MATCHER(isWritten);
   REGISTER_MATCHER(lValueReferenceType);
   REGISTER_MATCHER(labelDecl);
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4647,6 +4647,17 @@
   return Node.isDefaulted();
 }
 
+/// Matches weak function declarations.
+///
+/// Given:
+/// \code
+///   void foo() __attribute__((__weakref__("__foo")));
+///   void bar();
+/// \endcode
+/// functionDecl(isWeak())
+///   matches the weak declaration foo, but not bar.
+AST_MATCHER(FunctionDecl, isWeak) { return Node.isWeak(); }
+
 /// Matches functions that have a dynamic exception specification.
 ///
 /// Given:
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -3569,6 +3569,17 @@
 
 
 
+MatcherFunctionDecl>isWeak
+Matches weak function 
declarations.
+
+Given:
+  void foo() __attribute__((__weakref__("__foo")));
+  void bar();
+functionDecl(isWeak())
+  matches the weak declaration foo, but not bar.
+
+
+
 MatcherFunctionDecl>parameterCountIsunsigned N
 Matches 
FunctionDecls and FunctionProtoTypes that have a
 specific parameter count.
Index: 
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
@@ -1013,3 +1013,5 @@
 
   templatedFunction();
 }
+
+static void pr47779_dont_crash_on_weak() 
__attribute__((__weakref__("__pr47779_dont_crash_on_weak")));
Index: 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
===
--- 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
+++ 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
@@ -501,9 +501,9 @@
 
 void FunctionCognitiveComplexityCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
-  functionDecl(
-  allOf(isDefinition(), unless(anyOf(isDefaulted(), isDeleted(),
- isImplicit(), isInstantiated()
+  functionDecl(isDefinition(),
+   unless(anyOf(isDefaulted(), isDeleted(), isImplicit(),
+isInstantiated(), isWeak(
   .bind("func"),
   this);
 }


Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -433,6 +433,7 @@
   REGISTER_MATCHER(isVirtual);
   REGISTER_MATCHER(isVirtualAsWritten);
   REGISTER_MATCHER(isVolatileQualified);
+  REGISTER_MATCHER(isWeak);
   REGISTER_MATCHER(isWritten);
   REGISTER_MATCHER(lValueReferenceType);
   REGISTER_MATCHER(labelDecl);
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4647,6 +4647,17 @@
   return Node.isDefaulted();
 }
 
+/// Matches weak function declarations.
+///
+/// Given:
+/// \code
+///   void foo() __attribute__((__weakref__("__foo")));
+///   void bar();
+/// \endcode
+/// functionDecl(isWeak())
+///   matches the weak declaration foo, but not bar.
+AST_MATCHER(FunctionDecl, isWeak) { return Node.isWeak(); }
+
 /// Matches functions that have a dynamic exception specification.
 ///
 /// Given:
Index: clang/docs/LibASTMatchersReference.html
===
--- c

[PATCH] D89194: [clang-tidy] Fix crash in readability-function-cognitive-complexity on weak refs

2020-10-11 Thread Zinovy Nis via Phabricator via cfe-commits
zinovy.nis added a comment.

In D89194#2323868 , @JonasToth wrote:

> LGTM.
> Short reminder to please use full context patches. Its not an issue right 
> now, but review sometimes just needs the context to understand the changes :)

Sorry. Done.




Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:4658
+/// functionDecl(isWeak())
+///   matches the weak declaration foo, but not bar.
+AST_MATCHER(FunctionDecl, isWeak) { return Node.isWeak(); }

JonasToth wrote:
> Short oversight. Please hightlight the code and matcher to make a 
> differentation in the docs.
Sorry, I did not fully get what you mean as I just cloned isDefaulted section.


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

https://reviews.llvm.org/D89194

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


[PATCH] D89194: [clang-tidy] Fix crash in readability-function-cognitive-complexity on weak refs

2020-10-11 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

The context thingie was not that important here, but still thanks :)




Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:4658
+/// functionDecl(isWeak())
+///   matches the weak declaration foo, but not bar.
+AST_MATCHER(FunctionDecl, isWeak) { return Node.isWeak(); }

zinovy.nis wrote:
> JonasToth wrote:
> > Short oversight. Please hightlight the code and matcher to make a 
> > differentation in the docs.
> Sorry, I did not fully get what you mean as I just cloned isDefaulted section.
Its not consistent in the docs, but e.g.
`typedefNameDecl() matches "typedef int X" and "using Y = int"` is just more 
readable in the slightly formatted docs.

my preference would be `"functionDecl(isWeak()) matches the weak declaration 
"foo", but not "bar".`
(If you do the chance don't forget to recreate the HTML)


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

https://reviews.llvm.org/D89194

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


[PATCH] D88979: [InstCombine] combineLoadToOperationType(): don't fold int<->ptr cast into load

2020-10-11 Thread Nuno Lopes via Phabricator via cfe-commits
nlopes added inline comments.



Comment at: llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp:563
 if (auto* CI = dyn_cast(LI.user_back()))
-  if (CI->isNoopCast(DL))
+  if (CI->isNoopCast(DL) && LI.getType()->isPtrOrPtrVectorTy() ==
+CI->getDestTy()->isPtrOrPtrVectorTy())

What about fixing isNoopCast() directly?
Is the impact too bad/large?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88979

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


[PATCH] D88979: [InstCombine] combineLoadToOperationType(): don't fold int<->ptr cast into load

2020-10-11 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp:563
 if (auto* CI = dyn_cast(LI.user_back()))
-  if (CI->isNoopCast(DL))
+  if (CI->isNoopCast(DL) && LI.getType()->isPtrOrPtrVectorTy() ==
+CI->getDestTy()->isPtrOrPtrVectorTy())

nlopes wrote:
> What about fixing isNoopCast() directly?
> Is the impact too bad/large?
I don't recall, actually. That is the final step, yes,
but i think we can get most of the way there with small incremental changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88979

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


[PATCH] D79113: Revert "Remove false positive in AvoidNonConstGlobalVariables."

2020-10-11 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

The issue is resolved now in the CppCoreGuidelines.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79113

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


[PATCH] D89194: [clang-tidy] Fix crash in readability-function-cognitive-complexity on weak refs

2020-10-11 Thread Zinovy Nis via Phabricator via cfe-commits
zinovy.nis updated this revision to Diff 297468.

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

https://reviews.llvm.org/D89194

Files:
  clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/Dynamic/Registry.cpp


Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -433,6 +433,7 @@
   REGISTER_MATCHER(isVirtual);
   REGISTER_MATCHER(isVirtualAsWritten);
   REGISTER_MATCHER(isVolatileQualified);
+  REGISTER_MATCHER(isWeak);
   REGISTER_MATCHER(isWritten);
   REGISTER_MATCHER(lValueReferenceType);
   REGISTER_MATCHER(labelDecl);
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4647,6 +4647,17 @@
   return Node.isDefaulted();
 }
 
+/// Matches weak function declarations.
+///
+/// Given:
+/// \code
+///   void foo() __attribute__((__weakref__("__foo")));
+///   void bar();
+/// \endcode
+/// functionDecl(isWeak())
+///   matches the weak declaration "foo", but not "bar".
+AST_MATCHER(FunctionDecl, isWeak) { return Node.isWeak(); }
+
 /// Matches functions that have a dynamic exception specification.
 ///
 /// Given:
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -3569,6 +3569,17 @@
 
 
 
+MatcherFunctionDecl>isWeak
+Matches weak function 
declarations.
+
+Given:
+  void foo() __attribute__((__weakref__("__foo")));
+  void bar();
+functionDecl(isWeak())
+  matches the weak declaration "foo", but not "bar".
+
+
+
 MatcherFunctionDecl>parameterCountIsunsigned N
 Matches 
FunctionDecls and FunctionProtoTypes that have a
 specific parameter count.
Index: 
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
@@ -1013,3 +1013,5 @@
 
   templatedFunction();
 }
+
+static void pr47779_dont_crash_on_weak() 
__attribute__((__weakref__("__pr47779_dont_crash_on_weak")));
Index: 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
===
--- 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
+++ 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
@@ -501,9 +501,9 @@
 
 void FunctionCognitiveComplexityCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
-  functionDecl(
-  allOf(isDefinition(), unless(anyOf(isDefaulted(), isDeleted(),
- isImplicit(), isInstantiated()
+  functionDecl(isDefinition(),
+   unless(anyOf(isDefaulted(), isDeleted(), isImplicit(),
+isInstantiated(), isWeak(
   .bind("func"),
   this);
 }


Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -433,6 +433,7 @@
   REGISTER_MATCHER(isVirtual);
   REGISTER_MATCHER(isVirtualAsWritten);
   REGISTER_MATCHER(isVolatileQualified);
+  REGISTER_MATCHER(isWeak);
   REGISTER_MATCHER(isWritten);
   REGISTER_MATCHER(lValueReferenceType);
   REGISTER_MATCHER(labelDecl);
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4647,6 +4647,17 @@
   return Node.isDefaulted();
 }
 
+/// Matches weak function declarations.
+///
+/// Given:
+/// \code
+///   void foo() __attribute__((__weakref__("__foo")));
+///   void bar();
+/// \endcode
+/// functionDecl(isWeak())
+///   matches the weak declaration "foo", but not "bar".
+AST_MATCHER(FunctionDecl, isWeak) { return Node.isWeak(); }
+
 /// Matches functions that have a dynamic exception specification.
 ///
 /// Given:
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersRefer

[PATCH] D89194: [clang-tidy] Fix crash in readability-function-cognitive-complexity on weak refs

2020-10-11 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth accepted this revision.
JonasToth added a comment.

I am fine now, thank you!


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

https://reviews.llvm.org/D89194

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


[PATCH] D89194: [clang-tidy] Fix crash in readability-function-cognitive-complexity on weak refs

2020-10-11 Thread Zinovy Nis via Phabricator via cfe-commits
zinovy.nis added a comment.

In D89194#2323917 , @JonasToth wrote:

> I am fine now, thank you!

Thanks! 
Is this patch ready for landing? Or should I wait for a few more approvals?


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

https://reviews.llvm.org/D89194

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


[PATCH] D89194: [clang-tidy] Fix crash in readability-function-cognitive-complexity on weak refs

2020-10-11 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

You can land it. Worst case would be post-commit comments, but this is not a 
complicated patch and should be fine!


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

https://reviews.llvm.org/D89194

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


[PATCH] D89194: [clang-tidy] Fix crash in readability-function-cognitive-complexity on weak refs

2020-10-11 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In D89194#2323920 , @JonasToth wrote:

> You can land it. Worst case would be post-commit comments, but this is not a 
> complicated patch and should be fine!

+1

@JonasToth Thanks!


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

https://reviews.llvm.org/D89194

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


[PATCH] D89197: [X86] Support -march=x86-64-v[234]

2020-10-11 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 297469.
MaskRay added a comment.

Add release note
Fix F16C and BMI of x86-64-v3


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89197

Files:
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Basic/Targets/X86.h
  clang/test/Driver/x86-march.c
  clang/test/Driver/x86-mtune.c
  clang/test/Misc/target-invalid-cpu-note.c
  clang/test/Preprocessor/predefined-arch-macros-x86.c
  clang/test/Preprocessor/predefined-arch-macros.c
  clang/test/Sema/builtin-cpu-supports.c
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/Support/X86TargetParser.h
  llvm/lib/Support/X86TargetParser.cpp
  llvm/lib/Target/X86/X86.td
  llvm/test/CodeGen/X86/cpus-other.ll

Index: llvm/test/CodeGen/X86/cpus-other.ll
===
--- llvm/test/CodeGen/X86/cpus-other.ll
+++ llvm/test/CodeGen/X86/cpus-other.ll
@@ -16,6 +16,11 @@
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=c3 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=c3-2 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 
+;; x86-64 micro-architecture levels.
+; RUN: llc %s -filetype=null -mtriple=x86_64 -mcpu=x86-64-v2
+; RUN: llc %s -filetype=null -mtriple=x86_64 -mcpu=x86-64-v3
+; RUN: llc %s -filetype=null -mtriple=x86_64 -mcpu=x86-64-v4
+
 define void @foo() {
   ret void
 }
Index: llvm/lib/Target/X86/X86.td
===
--- llvm/lib/Target/X86/X86.td
+++ llvm/lib/Target/X86/X86.td
@@ -558,18 +558,27 @@
 //===--===//
 
 def ProcessorFeatures {
+  // x86-64 and x86-64-v[234]
+  list X86_64V1Features = [
+FeatureX87, FeatureCMPXCHG8B, FeatureCMOV, FeatureMMX, FeatureSSE2,
+FeatureFXSR, FeatureNOPL, Feature64Bit
+  ];
+  list X86_64V2Features = !listconcat(
+  X86_64V1Features,
+  [FeatureCMPXCHG16B, FeatureLAHFSAHF, FeaturePOPCNT, FeatureSSE42]);
+  list X86_64V3Features = !listconcat(X86_64V2Features, [
+FeatureAVX2, FeatureBMI, FeatureBMI2, FeatureF16C, FeatureFMA, FeatureLZCNT,
+FeatureMOVBE, FeatureXSAVE
+  ]);
+  list X86_64V4Features = !listconcat(X86_64V3Features, [
+FeatureBWI,
+FeatureCDI,
+FeatureDQI,
+FeatureVLX,
+  ]);
+
   // Nehalem
-  list NHMFeatures = [FeatureX87,
-FeatureCMPXCHG8B,
-FeatureCMOV,
-FeatureMMX,
-FeatureSSE42,
-FeatureFXSR,
-FeatureNOPL,
-Feature64Bit,
-FeatureCMPXCHG16B,
-FeaturePOPCNT,
-FeatureLAHFSAHF];
+  list NHMFeatures = X86_64V2Features;
   list NHMTuning = [FeatureMacroFusion,
   FeatureInsertVZEROUPPER];
 
@@ -1350,16 +1359,7 @@
 // covers a huge swath of x86 processors. If there are specific scheduling
 // knobs which need to be tuned differently for AMD chips, we might consider
 // forming a common base for them.
-def : ProcModel<"x86-64", SandyBridgeModel, [
-  FeatureX87,
-  FeatureCMPXCHG8B,
-  FeatureCMOV,
-  FeatureMMX,
-  FeatureSSE2,
-  FeatureFXSR,
-  FeatureNOPL,
-  Feature64Bit,
-],
+def : ProcModel<"x86-64", SandyBridgeModel, ProcessorFeatures.X86_64V1Features,
 [
   FeatureSlow3OpsLEA,
   FeatureSlowDivide64,
@@ -1368,6 +1368,16 @@
   FeatureInsertVZEROUPPER
 ]>;
 
+// x86-64 micro-architecture levels.
+def : ProcModel<"x86-64-v2", SandyBridgeModel, ProcessorFeatures.X86_64V2Features,
+ProcessorFeatures.SNBTuning>;
+// Close to Haswell.
+def : ProcModel<"x86-64-v3", HaswellModel, ProcessorFeatures.X86_64V3Features,
+ProcessorFeatures.HSWTuning>;
+// Close to the AVX-512 level implemented by Xeon Scalable Processors.
+def : ProcModel<"x86-64-v4", HaswellModel, ProcessorFeatures.X86_64V4Features,
+ProcessorFeatures.SKXTuning>;
+
 //===--===//
 // Calling Conventions
 //===--===//
Index: llvm/lib/Support/X86TargetParser.cpp
===
--- llvm/lib/Support/X86TargetParser.cpp
+++ llvm/lib/Support/X86TargetParser.cpp
@@ -137,6 +137,15 @@
 
 // Basic 64-bit capable CPU.
 constexpr FeatureBitset FeaturesX86_64 = FeaturesPentium4 | Feature64BIT;
+constexpr FeatureBitset FeaturesX86_64_V2 = FeaturesX86_64 | FeatureSAHF |
+FeaturePOPCNT | FeatureSSE4_2 |
+  

[clang-tools-extra] 32d565b - [clang-tidy] Fix crash in readability-function-cognitive-complexity on weak refs

2020-10-11 Thread Zinovy Nis via cfe-commits

Author: Zinovy Nis
Date: 2020-10-11T18:52:38+03:00
New Revision: 32d565b4618d31511e79dbe77aae8d456f2bf466

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

LOG: [clang-tidy] Fix crash in readability-function-cognitive-complexity on 
weak refs

Fix for https://bugs.llvm.org/show_bug.cgi?id=47779

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

Added: 


Modified: 

clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp

clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
clang/docs/LibASTMatchersReference.html
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/lib/ASTMatchers/Dynamic/Registry.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
index 96fe9a2e29a4..96854bf2a7ab 100644
--- 
a/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
@@ -501,9 +501,9 @@ void FunctionCognitiveComplexityCheck::storeOptions(
 
 void FunctionCognitiveComplexityCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
-  functionDecl(
-  allOf(isDefinition(), unless(anyOf(isDefaulted(), isDeleted(),
- isImplicit(), isInstantiated()
+  functionDecl(isDefinition(),
+   unless(anyOf(isDefaulted(), isDeleted(), isImplicit(),
+isInstantiated(), isWeak(
   .bind("func"),
   this);
 }

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
index 431540c6ee96..0916acd8e675 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
@@ -1013,3 +1013,5 @@ void functionThatCallsTemplatedFunctions() {
 
   templatedFunction();
 }
+
+static void pr47779_dont_crash_on_weak() 
__attribute__((__weakref__("__pr47779_dont_crash_on_weak")));

diff  --git a/clang/docs/LibASTMatchersReference.html 
b/clang/docs/LibASTMatchersReference.html
index fd8b217b7bc8..e281c5d3b850 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -3569,6 +3569,17 @@ Narrowing Matchers
 
 
 
+MatcherFunctionDecl>isWeak
+Matches weak function 
declarations.
+
+Given:
+  void foo() __attribute__((__weakref__("__foo")));
+  void bar();
+functionDecl(isWeak())
+  matches the weak declaration "foo", but not "bar".
+
+
+
 MatcherFunctionDecl>parameterCountIsunsigned N
 Matches 
FunctionDecls and FunctionProtoTypes that have a
 specific parameter count.

diff  --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index fd79b176ab4b..51d51d707de4 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4647,6 +4647,17 @@ AST_MATCHER(FunctionDecl, isDefaulted) {
   return Node.isDefaulted();
 }
 
+/// Matches weak function declarations.
+///
+/// Given:
+/// \code
+///   void foo() __attribute__((__weakref__("__foo")));
+///   void bar();
+/// \endcode
+/// functionDecl(isWeak())
+///   matches the weak declaration "foo", but not "bar".
+AST_MATCHER(FunctionDecl, isWeak) { return Node.isWeak(); }
+
 /// Matches functions that have a dynamic exception specification.
 ///
 /// Given:

diff  --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp 
b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index 8e62dce4fab5..00e6abbb477b 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -433,6 +433,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(isVirtual);
   REGISTER_MATCHER(isVirtualAsWritten);
   REGISTER_MATCHER(isVolatileQualified);
+  REGISTER_MATCHER(isWeak);
   REGISTER_MATCHER(isWritten);
   REGISTER_MATCHER(lValueReferenceType);
   REGISTER_MATCHER(labelDecl);



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


[PATCH] D89194: [clang-tidy] Fix crash in readability-function-cognitive-complexity on weak refs

2020-10-11 Thread Zinovy Nis via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG32d565b4618d: [clang-tidy] Fix crash in 
readability-function-cognitive-complexity on weak refs (authored by zinovy.nis).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89194

Files:
  clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/Dynamic/Registry.cpp


Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -433,6 +433,7 @@
   REGISTER_MATCHER(isVirtual);
   REGISTER_MATCHER(isVirtualAsWritten);
   REGISTER_MATCHER(isVolatileQualified);
+  REGISTER_MATCHER(isWeak);
   REGISTER_MATCHER(isWritten);
   REGISTER_MATCHER(lValueReferenceType);
   REGISTER_MATCHER(labelDecl);
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4647,6 +4647,17 @@
   return Node.isDefaulted();
 }
 
+/// Matches weak function declarations.
+///
+/// Given:
+/// \code
+///   void foo() __attribute__((__weakref__("__foo")));
+///   void bar();
+/// \endcode
+/// functionDecl(isWeak())
+///   matches the weak declaration "foo", but not "bar".
+AST_MATCHER(FunctionDecl, isWeak) { return Node.isWeak(); }
+
 /// Matches functions that have a dynamic exception specification.
 ///
 /// Given:
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -3569,6 +3569,17 @@
 
 
 
+MatcherFunctionDecl>isWeak
+Matches weak function 
declarations.
+
+Given:
+  void foo() __attribute__((__weakref__("__foo")));
+  void bar();
+functionDecl(isWeak())
+  matches the weak declaration "foo", but not "bar".
+
+
+
 MatcherFunctionDecl>parameterCountIsunsigned N
 Matches 
FunctionDecls and FunctionProtoTypes that have a
 specific parameter count.
Index: 
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
@@ -1013,3 +1013,5 @@
 
   templatedFunction();
 }
+
+static void pr47779_dont_crash_on_weak() 
__attribute__((__weakref__("__pr47779_dont_crash_on_weak")));
Index: 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
===
--- 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
+++ 
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
@@ -501,9 +501,9 @@
 
 void FunctionCognitiveComplexityCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
-  functionDecl(
-  allOf(isDefinition(), unless(anyOf(isDefaulted(), isDeleted(),
- isImplicit(), isInstantiated()
+  functionDecl(isDefinition(),
+   unless(anyOf(isDefaulted(), isDeleted(), isImplicit(),
+isInstantiated(), isWeak(
   .bind("func"),
   this);
 }


Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -433,6 +433,7 @@
   REGISTER_MATCHER(isVirtual);
   REGISTER_MATCHER(isVirtualAsWritten);
   REGISTER_MATCHER(isVolatileQualified);
+  REGISTER_MATCHER(isWeak);
   REGISTER_MATCHER(isWritten);
   REGISTER_MATCHER(lValueReferenceType);
   REGISTER_MATCHER(labelDecl);
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4647,6 +4647,17 @@
   return Node.isDefaulted();
 }
 
+/// Matches weak function declarations.
+///
+/// Given:
+/// \code
+///   void foo() __attribute__((__weakref__("__foo")));
+///   void bar();
+/// \endcode
+/// functionDecl(isWeak())
+///   matches the weak declaration "foo", but not "bar".
+AST_MATCHER(FunctionDecl, isWeak) { return Node.isWeak(); }
+
 /// Matches functions that h

[PATCH] D88979: [InstCombine] combineLoadToOperationType(): don't fold int<->ptr cast into load

2020-10-11 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp:563
 if (auto* CI = dyn_cast(LI.user_back()))
-  if (CI->isNoopCast(DL))
+  if (CI->isNoopCast(DL) && LI.getType()->isPtrOrPtrVectorTy() ==
+CI->getDestTy()->isPtrOrPtrVectorTy())

lebedev.ri wrote:
> nlopes wrote:
> > What about fixing isNoopCast() directly?
> > Is the impact too bad/large?
> I don't recall, actually. That is the final step, yes,
> but i think we can get most of the way there with small incremental changes.
(what i mean is, if "let's just do it" is the review feedback, then i can of 
course do it all at once..)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88979

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


[PATCH] D88979: [InstCombine] combineLoadToOperationType(): don't fold int<->ptr cast into load

2020-10-11 Thread Nikita Popov via Phabricator via cfe-commits
nikic accepted this revision.
nikic added a comment.
This revision is now accepted and ready to land.

LGTM

Looking through other uses of isNoopCast(), I don't think it makes sense to 
push this change into it, as many other usages do need it to work with 
ptrtoint/inttoptr (some of them using it specifically for them). The comment 
above the function indicates that "no-op" is to be understood as "generates no 
code" here. Possibly it could do with a rename.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88979

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


[PATCH] D88979: [InstCombine] combineLoadToOperationType(): don't fold int<->ptr cast into load

2020-10-11 Thread Nikita Popov via Phabricator via cfe-commits
nikic added inline comments.



Comment at: llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp:560
   // Fold away bit casts of the loaded value by loading the desired type.
-  // We can do this for BitCastInsts as well as casts from and to pointer 
types,
-  // as long as those are noops (i.e., the source or dest type have the same
-  // bitwidth as the target's pointers).
+  // Note that we should not do this for pointer<->integer casts!
   if (LI.hasOneUse())

You might want to be a tad more explicit here, e.g. add "because they have 
different provenance" or so.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88979

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


[PATCH] D75153: [ThinLTO] Allow usage of all SMT threads in the system

2020-10-11 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

https://clang.llvm.org/docs/ThinLTO.html#controlling-backend-parallelism should 
probably be updated to mention "all".


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75153

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


[PATCH] D88979: [InstCombine] combineLoadToOperationType(): don't fold int<->ptr cast into load

2020-10-11 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In D88979#2323935 , @nikic wrote:

> LGTM

@nlopes does this look good to you?

> Looking through other uses of isNoopCast(), I don't think it makes sense to 
> push this change into it, as many other usages do need it to work with 
> ptrtoint/inttoptr (some of them using it specifically for them). The comment 
> above the function indicates that "no-op" is to be understood as "generates 
> no code" here. Possibly it could do with a rename.

I think i don't agree with you there.
I agree with @nlopes, the end goal will be to basically disallow fusing of 
`inttoptr`/`ptrtoint` into loads, 
disallow dropping inttoptr-of-ptrtoint/ptrtoint-of-inttoptr, etc.
And all that eventually boils down to updating 
`CastInst::isNoopCast()`/`CastInst::isEliminableCastPair()`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88979

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


[PATCH] D89198: [X86] Define __LAHF_SAHF__ if feature 'sahf' is set or 32-bit mode

2020-10-11 Thread Fangrui Song 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 rGcbe4d973edad: [X86] Define __LAHF_SAHF__ if feature 
'sahf' is set or 32-bit mode (authored by MaskRay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89198

Files:
  clang/lib/Basic/Targets/X86.cpp
  clang/test/Preprocessor/predefined-arch-macros.c

Index: clang/test/Preprocessor/predefined-arch-macros.c
===
--- clang/test/Preprocessor/predefined-arch-macros.c
+++ clang/test/Preprocessor/predefined-arch-macros.c
@@ -3,6 +3,7 @@
 // RUN: %clang -march=i386 -m32 -E -dM %s -o - 2>&1 \
 // RUN: -target i386-unknown-linux \
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_I386_M32
+// CHECK_I386_M32: #define __LAHF_SAHF__ 1
 // CHECK_I386_M32: #define __i386 1
 // CHECK_I386_M32: #define __i386__ 1
 // CHECK_I386_M32: #define __tune_i386__ 1
@@ -541,6 +542,7 @@
 // CHECK_CORE_AVX2_M32: #define __F16C__ 1
 // CHECK_CORE_AVX2_M32: #define __FMA__ 1
 // CHECK_CORE_AVX2_M32: #define __INVPCID__ 1
+// CHECK_CORE_AVX2_M32: #define __LAHF_SAHF__ 1
 // CHECK_CORE_AVX2_M32: #define __LZCNT__ 1
 // CHECK_CORE_AVX2_M32: #define __MMX__ 1
 // CHECK_CORE_AVX2_M32: #define __MOVBE__ 1
@@ -572,6 +574,7 @@
 // CHECK_CORE_AVX2_M64: #define __F16C__ 1
 // CHECK_CORE_AVX2_M64: #define __FMA__ 1
 // CHECK_CORE_AVX2_M64: #define __INVPCID__ 1
+// CHECK_CORE_AVX2_M64: #define __LAHF_SAHF__ 1
 // CHECK_CORE_AVX2_M64: #define __LZCNT__ 1
 // CHECK_CORE_AVX2_M64: #define __MMX__ 1
 // CHECK_CORE_AVX2_M64: #define __MOVBE__ 1
@@ -607,6 +610,7 @@
 // CHECK_BROADWELL_M32: #define __F16C__ 1
 // CHECK_BROADWELL_M32: #define __FMA__ 1
 // CHECK_BROADWELL_M32: #define __INVPCID__ 1
+// CHECK_BROADWELL_M32: #define __LAHF_SAHF__ 1
 // CHECK_BROADWELL_M32: #define __LZCNT__ 1
 // CHECK_BROADWELL_M32: #define __MMX__ 1
 // CHECK_BROADWELL_M32: #define __MOVBE__ 1
@@ -641,6 +645,7 @@
 // CHECK_BROADWELL_M64: #define __F16C__ 1
 // CHECK_BROADWELL_M64: #define __FMA__ 1
 // CHECK_BROADWELL_M64: #define __INVPCID__ 1
+// CHECK_BROADWELL_M64: #define __LAHF_SAHF__ 1
 // CHECK_BROADWELL_M64: #define __LZCNT__ 1
 // CHECK_BROADWELL_M64: #define __MMX__ 1
 // CHECK_BROADWELL_M64: #define __MOVBE__ 1
@@ -2515,6 +2520,7 @@
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_AMDFAM10_M32
 // CHECK_AMDFAM10_M32: #define __3dNOW_A__ 1
 // CHECK_AMDFAM10_M32: #define __3dNOW__ 1
+// CHECK_AMDFAM10_M32: #define __LAHF_SAHF__ 1
 // CHECK_AMDFAM10_M32: #define __LZCNT__ 1
 // CHECK_AMDFAM10_M32: #define __MMX__ 1
 // CHECK_AMDFAM10_M32: #define __POPCNT__ 1
@@ -2538,6 +2544,7 @@
 // CHECK_AMDFAM10_M64: #define __3dNOW_A__ 1
 // CHECK_AMDFAM10_M64: #define __3dNOW__ 1
 // CHECK_AMDFAM10_M64: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 1
+// CHECK_AMDFAM10_M64: #define __LAHF_SAHF__ 1
 // CHECK_AMDFAM10_M64: #define __LZCNT__ 1
 // CHECK_AMDFAM10_M64: #define __MMX__ 1
 // CHECK_AMDFAM10_M64: #define __POPCNT__ 1
@@ -2562,6 +2569,7 @@
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_BTVER1_M32
 // CHECK_BTVER1_M32-NOT: #define __3dNOW_A__ 1
 // CHECK_BTVER1_M32-NOT: #define __3dNOW__ 1
+// CHECK_BTVER1_M32: #define __LAHF_SAHF__ 1
 // CHECK_BTVER1_M32: #define __LZCNT__ 1
 // CHECK_BTVER1_M32: #define __MMX__ 1
 // CHECK_BTVER1_M32: #define __POPCNT__ 1
@@ -2584,6 +2592,7 @@
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_BTVER1_M64
 // CHECK_BTVER1_M64-NOT: #define __3dNOW_A__ 1
 // CHECK_BTVER1_M64-NOT: #define __3dNOW__ 1
+// CHECK_BTVER1_M64: #define __LAHF_SAHF__ 1
 // CHECK_BTVER1_M64: #define __LZCNT__ 1
 // CHECK_BTVER1_M64: #define __MMX__ 1
 // CHECK_BTVER1_M64: #define __POPCNT__ 1
@@ -3023,6 +3032,7 @@
 // CHECK_ZNVER1_M64-NOT: #define __FMA4__ 1
 // CHECK_ZNVER1_M64: #define __FMA__ 1
 // CHECK_ZNVER1_M64: #define __FSGSBASE__ 1
+// CHECK_ZNVER1_M64: #define __LAHF_SAHF__ 1
 // CHECK_ZNVER1_M64: #define __LZCNT__ 1
 // CHECK_ZNVER1_M64: #define __MMX__ 1
 // CHECK_ZNVER1_M64: #define __MOVBE__ 1
@@ -3073,6 +3083,7 @@
 // CHECK_ZNVER2_M32-NOT: #define __FMA4__ 1
 // CHECK_ZNVER2_M32: #define __FMA__ 1
 // CHECK_ZNVER2_M32: #define __FSGSBASE__ 1
+// CHECK_ZNVER2_M32: #define __LAHF_SAHF__ 1
 // CHECK_ZNVER2_M32: #define __LZCNT__ 1
 // CHECK_ZNVER2_M32: #define __MMX__ 1
 // CHECK_ZNVER2_M32: #define __PCLMUL__ 1
@@ -3122,6 +3133,7 @@
 // CHECK_ZNVER2_M64-NOT: #define __FMA4__ 1
 // CHECK_ZNVER2_M64: #define __FMA__ 1
 // CHECK_ZNVER2_M64: #define __FSGSBASE__ 1
+// CHECK_ZNVER2_M64: #define __LAHF_SAHF__ 1
 // CHECK_ZNVER2_M64: #define __LZCNT__ 1
 // CHECK_ZNVER2_M64: #define __MMX__ 1
 // CHECK_ZNVER2_M64: #define __PCLMUL__ 1
Index: clang/lib/Basic/Targets/X86.cpp
===
--- clang/lib/Basic/Targets/X86.cpp
+++ clang/lib/Basic/Targe

[clang] cbe4d97 - [X86] Define __LAHF_SAHF__ if feature 'sahf' is set or 32-bit mode

2020-10-11 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2020-10-11T09:46:00-07:00
New Revision: cbe4d973edadba7664ab8783770fa51742cd93b9

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

LOG: [X86] Define __LAHF_SAHF__ if feature 'sahf' is set or 32-bit mode

GCC 11 will define this macro.

In LLVM, the feature flag only applies to 64-bit mode and we always define the
macro in 32-bit mode. This is different from GCC -m32 in which -mno-sahf can
suppress the macro. The discrepancy can unlikely cause trouble.

Reviewed By: craig.topper

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

Added: 


Modified: 
clang/lib/Basic/Targets/X86.cpp
clang/test/Preprocessor/predefined-arch-macros.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 5d89894c7628..ef83703d6097 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -560,6 +560,11 @@ void X86TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   if (HasVPCLMULQDQ)
 Builder.defineMacro("__VPCLMULQDQ__");
 
+  // Note, in 32-bit mode, GCC does not define the macro if -mno-sahf. In LLVM,
+  // the feature flag only applies to 64-bit mode.
+  if (HasLAHFSAHF || getTriple().getArch() == llvm::Triple::x86)
+Builder.defineMacro("__LAHF_SAHF__");
+
   if (HasLZCNT)
 Builder.defineMacro("__LZCNT__");
 

diff  --git a/clang/test/Preprocessor/predefined-arch-macros.c 
b/clang/test/Preprocessor/predefined-arch-macros.c
index 287a7c58cdda..7993c587efcd 100644
--- a/clang/test/Preprocessor/predefined-arch-macros.c
+++ b/clang/test/Preprocessor/predefined-arch-macros.c
@@ -3,6 +3,7 @@
 // RUN: %clang -march=i386 -m32 -E -dM %s -o - 2>&1 \
 // RUN: -target i386-unknown-linux \
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_I386_M32
+// CHECK_I386_M32: #define __LAHF_SAHF__ 1
 // CHECK_I386_M32: #define __i386 1
 // CHECK_I386_M32: #define __i386__ 1
 // CHECK_I386_M32: #define __tune_i386__ 1
@@ -541,6 +542,7 @@
 // CHECK_CORE_AVX2_M32: #define __F16C__ 1
 // CHECK_CORE_AVX2_M32: #define __FMA__ 1
 // CHECK_CORE_AVX2_M32: #define __INVPCID__ 1
+// CHECK_CORE_AVX2_M32: #define __LAHF_SAHF__ 1
 // CHECK_CORE_AVX2_M32: #define __LZCNT__ 1
 // CHECK_CORE_AVX2_M32: #define __MMX__ 1
 // CHECK_CORE_AVX2_M32: #define __MOVBE__ 1
@@ -572,6 +574,7 @@
 // CHECK_CORE_AVX2_M64: #define __F16C__ 1
 // CHECK_CORE_AVX2_M64: #define __FMA__ 1
 // CHECK_CORE_AVX2_M64: #define __INVPCID__ 1
+// CHECK_CORE_AVX2_M64: #define __LAHF_SAHF__ 1
 // CHECK_CORE_AVX2_M64: #define __LZCNT__ 1
 // CHECK_CORE_AVX2_M64: #define __MMX__ 1
 // CHECK_CORE_AVX2_M64: #define __MOVBE__ 1
@@ -607,6 +610,7 @@
 // CHECK_BROADWELL_M32: #define __F16C__ 1
 // CHECK_BROADWELL_M32: #define __FMA__ 1
 // CHECK_BROADWELL_M32: #define __INVPCID__ 1
+// CHECK_BROADWELL_M32: #define __LAHF_SAHF__ 1
 // CHECK_BROADWELL_M32: #define __LZCNT__ 1
 // CHECK_BROADWELL_M32: #define __MMX__ 1
 // CHECK_BROADWELL_M32: #define __MOVBE__ 1
@@ -641,6 +645,7 @@
 // CHECK_BROADWELL_M64: #define __F16C__ 1
 // CHECK_BROADWELL_M64: #define __FMA__ 1
 // CHECK_BROADWELL_M64: #define __INVPCID__ 1
+// CHECK_BROADWELL_M64: #define __LAHF_SAHF__ 1
 // CHECK_BROADWELL_M64: #define __LZCNT__ 1
 // CHECK_BROADWELL_M64: #define __MMX__ 1
 // CHECK_BROADWELL_M64: #define __MOVBE__ 1
@@ -2515,6 +2520,7 @@
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_AMDFAM10_M32
 // CHECK_AMDFAM10_M32: #define __3dNOW_A__ 1
 // CHECK_AMDFAM10_M32: #define __3dNOW__ 1
+// CHECK_AMDFAM10_M32: #define __LAHF_SAHF__ 1
 // CHECK_AMDFAM10_M32: #define __LZCNT__ 1
 // CHECK_AMDFAM10_M32: #define __MMX__ 1
 // CHECK_AMDFAM10_M32: #define __POPCNT__ 1
@@ -2538,6 +2544,7 @@
 // CHECK_AMDFAM10_M64: #define __3dNOW_A__ 1
 // CHECK_AMDFAM10_M64: #define __3dNOW__ 1
 // CHECK_AMDFAM10_M64: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 1
+// CHECK_AMDFAM10_M64: #define __LAHF_SAHF__ 1
 // CHECK_AMDFAM10_M64: #define __LZCNT__ 1
 // CHECK_AMDFAM10_M64: #define __MMX__ 1
 // CHECK_AMDFAM10_M64: #define __POPCNT__ 1
@@ -2562,6 +2569,7 @@
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_BTVER1_M32
 // CHECK_BTVER1_M32-NOT: #define __3dNOW_A__ 1
 // CHECK_BTVER1_M32-NOT: #define __3dNOW__ 1
+// CHECK_BTVER1_M32: #define __LAHF_SAHF__ 1
 // CHECK_BTVER1_M32: #define __LZCNT__ 1
 // CHECK_BTVER1_M32: #define __MMX__ 1
 // CHECK_BTVER1_M32: #define __POPCNT__ 1
@@ -2584,6 +2592,7 @@
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_BTVER1_M64
 // CHECK_BTVER1_M64-NOT: #define __3dNOW_A__ 1
 // CHECK_BTVER1_M64-NOT: #define __3dNOW__ 1
+// CHECK_BTVER1_M64: #define __LAHF_SAHF__ 1
 // CHECK_BTVER1_M64: #define __LZCNT__ 1
 // CHECK_BTVER1_M64: #define __MMX__ 1
 // CHECK_BTVER1_M64: #define __POPCNT__ 1
@@ -3023,6 +303

[PATCH] D89197: [X86] Support -march=x86-64-v[234]

2020-10-11 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 297473.
MaskRay added a comment.

Test __LAHF_SAHF__
Update clang/docs/ReleaseNotes.rst
Update clang/test/CodeGen/attr-target-x86.c to test X86.td changes. Ideally 
"target-features" should be testable with llc to have better layering


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89197

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Basic/Targets/X86.h
  clang/test/CodeGen/attr-target-x86.c
  clang/test/Driver/x86-march.c
  clang/test/Driver/x86-mtune.c
  clang/test/Misc/target-invalid-cpu-note.c
  clang/test/Preprocessor/predefined-arch-macros-x86.c
  clang/test/Preprocessor/predefined-arch-macros.c
  clang/test/Sema/builtin-cpu-supports.c
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/Support/X86TargetParser.h
  llvm/lib/Support/X86TargetParser.cpp
  llvm/lib/Target/X86/X86.td
  llvm/test/CodeGen/X86/cpus-other.ll

Index: llvm/test/CodeGen/X86/cpus-other.ll
===
--- llvm/test/CodeGen/X86/cpus-other.ll
+++ llvm/test/CodeGen/X86/cpus-other.ll
@@ -16,6 +16,11 @@
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=c3 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=c3-2 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 
+;; x86-64 micro-architecture levels.
+; RUN: llc %s -filetype=null -mtriple=x86_64 -mcpu=x86-64-v2
+; RUN: llc %s -filetype=null -mtriple=x86_64 -mcpu=x86-64-v3
+; RUN: llc %s -filetype=null -mtriple=x86_64 -mcpu=x86-64-v4
+
 define void @foo() {
   ret void
 }
Index: llvm/lib/Target/X86/X86.td
===
--- llvm/lib/Target/X86/X86.td
+++ llvm/lib/Target/X86/X86.td
@@ -558,18 +558,27 @@
 //===--===//
 
 def ProcessorFeatures {
+  // x86-64 and x86-64-v[234]
+  list X86_64V1Features = [
+FeatureX87, FeatureCMPXCHG8B, FeatureCMOV, FeatureMMX, FeatureSSE2,
+FeatureFXSR, FeatureNOPL, Feature64Bit
+  ];
+  list X86_64V2Features = !listconcat(
+  X86_64V1Features,
+  [FeatureCMPXCHG16B, FeatureLAHFSAHF, FeaturePOPCNT, FeatureSSE42]);
+  list X86_64V3Features = !listconcat(X86_64V2Features, [
+FeatureAVX2, FeatureBMI, FeatureBMI2, FeatureF16C, FeatureFMA, FeatureLZCNT,
+FeatureMOVBE, FeatureXSAVE
+  ]);
+  list X86_64V4Features = !listconcat(X86_64V3Features, [
+FeatureBWI,
+FeatureCDI,
+FeatureDQI,
+FeatureVLX,
+  ]);
+
   // Nehalem
-  list NHMFeatures = [FeatureX87,
-FeatureCMPXCHG8B,
-FeatureCMOV,
-FeatureMMX,
-FeatureSSE42,
-FeatureFXSR,
-FeatureNOPL,
-Feature64Bit,
-FeatureCMPXCHG16B,
-FeaturePOPCNT,
-FeatureLAHFSAHF];
+  list NHMFeatures = X86_64V2Features;
   list NHMTuning = [FeatureMacroFusion,
   FeatureInsertVZEROUPPER];
 
@@ -1350,16 +1359,7 @@
 // covers a huge swath of x86 processors. If there are specific scheduling
 // knobs which need to be tuned differently for AMD chips, we might consider
 // forming a common base for them.
-def : ProcModel<"x86-64", SandyBridgeModel, [
-  FeatureX87,
-  FeatureCMPXCHG8B,
-  FeatureCMOV,
-  FeatureMMX,
-  FeatureSSE2,
-  FeatureFXSR,
-  FeatureNOPL,
-  Feature64Bit,
-],
+def : ProcModel<"x86-64", SandyBridgeModel, ProcessorFeatures.X86_64V1Features,
 [
   FeatureSlow3OpsLEA,
   FeatureSlowDivide64,
@@ -1368,6 +1368,16 @@
   FeatureInsertVZEROUPPER
 ]>;
 
+// x86-64 micro-architecture levels.
+def : ProcModel<"x86-64-v2", SandyBridgeModel, ProcessorFeatures.X86_64V2Features,
+ProcessorFeatures.SNBTuning>;
+// Close to Haswell.
+def : ProcModel<"x86-64-v3", HaswellModel, ProcessorFeatures.X86_64V3Features,
+ProcessorFeatures.HSWTuning>;
+// Close to the AVX-512 level implemented by Xeon Scalable Processors.
+def : ProcModel<"x86-64-v4", HaswellModel, ProcessorFeatures.X86_64V4Features,
+ProcessorFeatures.SKXTuning>;
+
 //===--===//
 // Calling Conventions
 //===--===//
Index: llvm/lib/Support/X86TargetParser.cpp
===
--- llvm/lib/Support/X86TargetParser.cpp
+++ llvm/lib/Support/X86TargetParser.cpp
@@ -137,6 +137,15 @@
 
 // Basic 64-bit capable CPU.
 constexpr FeatureBitset FeaturesX86

[PATCH] D88979: [InstCombine] combineLoadToOperationType(): don't fold int<->ptr cast into load

2020-10-11 Thread Nuno Lopes via Phabricator via cfe-commits
nlopes accepted this revision.
nlopes added a comment.

In D88979#2323940 , @lebedev.ri wrote:

> In D88979#2323935 , @nikic wrote:
>
>> LGTM
>
> @nlopes does this look good to you?
>
>> Looking through other uses of isNoopCast(), I don't think it makes sense to 
>> push this change into it, as many other usages do need it to work with 
>> ptrtoint/inttoptr (some of them using it specifically for them). The comment 
>> above the function indicates that "no-op" is to be understood as "generates 
>> no code" here. Possibly it could do with a rename.
>
> I think i don't agree with you there.
> I agree with @nlopes, the end goal will be to basically disallow fusing of 
> `inttoptr`/`ptrtoint` into loads, 
> disallow dropping inttoptr-of-ptrtoint/ptrtoint-of-inttoptr, etc.
> And all that eventually boils down to updating 
> `CastInst::isNoopCast()`/`CastInst::isEliminableCastPair()`.

I'm ok with this change, and I agree it's a good step forwards. Thanks!
My only concern was that it seems this code will need further changes going 
forward (maybe even revert this change?) and I wouldn't want us to forget to 
revisit this code if/when needed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88979

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


[PATCH] D88979: [InstCombine] combineLoadToOperationType(): don't fold int<->ptr cast into load

2020-10-11 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

@nlopes @nikic thank you for the review!

In D88979#2323948 , @nlopes wrote:

> In D88979#2323940 , @lebedev.ri 
> wrote:
>
>> In D88979#2323935 , @nikic wrote:
>>
>>> LGTM
>>
>> @nlopes does this look good to you?
>>
>>> Looking through other uses of isNoopCast(), I don't think it makes sense to 
>>> push this change into it, as many other usages do need it to work with 
>>> ptrtoint/inttoptr (some of them using it specifically for them). The 
>>> comment above the function indicates that "no-op" is to be understood as 
>>> "generates no code" here. Possibly it could do with a rename.
>>
>> I think i don't agree with you there.
>> I agree with @nlopes, the end goal will be to basically disallow fusing of 
>> `inttoptr`/`ptrtoint` into loads, 
>> disallow dropping inttoptr-of-ptrtoint/ptrtoint-of-inttoptr, etc.
>> And all that eventually boils down to updating 
>> `CastInst::isNoopCast()`/`CastInst::isEliminableCastPair()`.
>
> I'm ok with this change, and I agree it's a good step forwards. Thanks!
> My only concern was that it seems this code will need further changes going 
> forward (maybe even revert this change?) and I wouldn't want us to forget to 
> revisit this code if/when needed.

Once those methods are fixed, sure, the uses will need dead code cleanup.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88979

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


[PATCH] D88979: [InstCombine] combineLoadToOperationType(): don't fold int<->ptr cast into load

2020-10-11 Thread Roman Lebedev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG544a6aa2674e: [InstCombine] combineLoadToOperationType(): 
don't fold int<->ptr cast into load (authored by lebedev.ri).

Changed prior to commit:
  https://reviews.llvm.org/D88979?vs=297217&id=297475#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88979

Files:
  clang/test/CodeGen/arm64_32-vaarg.c
  llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
  llvm/test/Transforms/InstCombine/PR30597.ll
  llvm/test/Transforms/InstCombine/intptr1.ll
  llvm/test/Transforms/InstCombine/load-bitcast32.ll
  llvm/test/Transforms/InstCombine/load-bitcast64.ll
  llvm/test/Transforms/InstCombine/memset_chk-1.ll

Index: llvm/test/Transforms/InstCombine/memset_chk-1.ll
===
--- llvm/test/Transforms/InstCombine/memset_chk-1.ll
+++ llvm/test/Transforms/InstCombine/memset_chk-1.ll
@@ -79,10 +79,10 @@
 ; CHECK-NEXT:[[CALL50:%.*]] = call i8* @__memmove_chk(i8* [[B]], i8* [[A]], i64 [[ADD180]], i64 [[YO107]])
 ; CHECK-NEXT:[[STRLEN:%.*]] = call i64 @strlen(i8* nonnull dereferenceable(1) [[B]])
 ; CHECK-NEXT:[[STRCHR1:%.*]] = getelementptr i8, i8* [[B]], i64 [[STRLEN]]
-; CHECK-NEXT:[[TMP0:%.*]] = bitcast i8** [[C:%.*]] to i64*
-; CHECK-NEXT:[[D2:%.*]] = load i64, i64* [[TMP0]], align 8
+; CHECK-NEXT:[[D:%.*]] = load i8*, i8** [[C:%.*]], align 8
+; CHECK-NEXT:[[SUB182:%.*]] = ptrtoint i8* [[D]] to i64
 ; CHECK-NEXT:[[SUB183:%.*]] = ptrtoint i8* [[B]] to i64
-; CHECK-NEXT:[[SUB184:%.*]] = sub i64 [[D2]], [[SUB183]]
+; CHECK-NEXT:[[SUB184:%.*]] = sub i64 [[SUB182]], [[SUB183]]
 ; CHECK-NEXT:[[ADD52_I_I:%.*]] = add nsw i64 [[SUB184]], 1
 ; CHECK-NEXT:call void @llvm.memset.p0i8.i64(i8* align 1 [[STRCHR1]], i8 0, i64 [[ADD52_I_I]], i1 false)
 ; CHECK-NEXT:ret i32 4
Index: llvm/test/Transforms/InstCombine/load-bitcast64.ll
===
--- llvm/test/Transforms/InstCombine/load-bitcast64.ll
+++ llvm/test/Transforms/InstCombine/load-bitcast64.ll
@@ -7,9 +7,10 @@
 define i64* @test1(i8* %x) {
 ; CHECK-LABEL: @test1(
 ; CHECK-NEXT:  entry:
-; CHECK-NEXT:[[TMP0:%.*]] = bitcast i8* [[X:%.*]] to i64**
-; CHECK-NEXT:[[B1:%.*]] = load i64*, i64** [[TMP0]], align 4
-; CHECK-NEXT:ret i64* [[B1]]
+; CHECK-NEXT:[[A:%.*]] = bitcast i8* [[X:%.*]] to i64*
+; CHECK-NEXT:[[B:%.*]] = load i64, i64* [[A]], align 4
+; CHECK-NEXT:[[C:%.*]] = inttoptr i64 [[B]] to i64*
+; CHECK-NEXT:ret i64* [[C]]
 ;
 entry:
   %a = bitcast i8* %x to i64*
@@ -56,9 +57,10 @@
 define i64 @test4(i8* %x) {
 ; CHECK-LABEL: @test4(
 ; CHECK-NEXT:  entry:
-; CHECK-NEXT:[[TMP0:%.*]] = bitcast i8* [[X:%.*]] to i64*
-; CHECK-NEXT:[[B1:%.*]] = load i64, i64* [[TMP0]], align 8
-; CHECK-NEXT:ret i64 [[B1]]
+; CHECK-NEXT:[[A:%.*]] = bitcast i8* [[X:%.*]] to i64**
+; CHECK-NEXT:[[B:%.*]] = load i64*, i64** [[A]], align 8
+; CHECK-NEXT:[[C:%.*]] = ptrtoint i64* [[B]] to i64
+; CHECK-NEXT:ret i64 [[C]]
 ;
 entry:
   %a = bitcast i8* %x to i64**
@@ -71,9 +73,10 @@
 define i32 @test5(i8* %x) {
 ; CHECK-LABEL: @test5(
 ; CHECK-NEXT:  entry:
-; CHECK-NEXT:[[TMP0:%.*]] = bitcast i8* [[X:%.*]] to i64*
-; CHECK-NEXT:[[B1:%.*]] = load i64, i64* [[TMP0]], align 8
-; CHECK-NEXT:[[C:%.*]] = trunc i64 [[B1]] to i32
+; CHECK-NEXT:[[A:%.*]] = bitcast i8* [[X:%.*]] to i32**
+; CHECK-NEXT:[[B:%.*]] = load i32*, i32** [[A]], align 8
+; CHECK-NEXT:[[TMP0:%.*]] = ptrtoint i32* [[B]] to i64
+; CHECK-NEXT:[[C:%.*]] = trunc i64 [[TMP0]] to i32
 ; CHECK-NEXT:ret i32 [[C]]
 ;
 entry:
@@ -87,9 +90,10 @@
 define i64 @test6(i8* %x) {
 ; CHECK-LABEL: @test6(
 ; CHECK-NEXT:  entry:
-; CHECK-NEXT:[[TMP0:%.*]] = bitcast i8* [[X:%.*]] to i64*
-; CHECK-NEXT:[[B1:%.*]] = load i64, i64* [[TMP0]], align 8
-; CHECK-NEXT:ret i64 [[B1]]
+; CHECK-NEXT:[[A:%.*]] = bitcast i8* [[X:%.*]] to i32**
+; CHECK-NEXT:[[B:%.*]] = load i32*, i32** [[A]], align 8
+; CHECK-NEXT:[[C:%.*]] = ptrtoint i32* [[B]] to i64
+; CHECK-NEXT:ret i64 [[C]]
 ;
 entry:
   %a = bitcast i8* %x to i32**
Index: llvm/test/Transforms/InstCombine/load-bitcast32.ll
===
--- llvm/test/Transforms/InstCombine/load-bitcast32.ll
+++ llvm/test/Transforms/InstCombine/load-bitcast32.ll
@@ -24,9 +24,10 @@
 define i32* @test2(i8* %x) {
 ; CHECK-LABEL: @test2(
 ; CHECK-NEXT:  entry:
-; CHECK-NEXT:[[TMP0:%.*]] = bitcast i8* [[X:%.*]] to i32**
-; CHECK-NEXT:[[B1:%.*]] = load i32*, i32** [[TMP0]], align 4
-; CHECK-NEXT:ret i32* [[B1]]
+; CHECK-NEXT:[[A:%.*]] = bitcast i8* [[X:%.*]] to i32*
+; CHECK-NEXT:[[B:%.*]] = load i32, i32* [[A]], align 4
+; CHECK-NEXT:[[C:%.*]] = inttoptr i32 [[B]] to i32*
+; CHECK-NEXT:ret i32* [[

[clang] 544a6aa - [InstCombine] combineLoadToOperationType(): don't fold int<->ptr cast into load

2020-10-11 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2020-10-11T20:24:28+03:00
New Revision: 544a6aa2674e3875e4014eafb101a982f9296439

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

LOG: [InstCombine] combineLoadToOperationType(): don't fold int<->ptr cast into 
load

And another step towards transforms not introducing inttoptr and/or
ptrtoint casts that weren't there already.

As we've been establishing (see D88788/D88789), if there is a int<->ptr cast,
it basically must stay as-is, we can't do much with it.

I've looked, and the most source of new such casts being introduces,
as far as i can tell, is this transform, which, ironically,
tries to reduce count of casts..

On vanilla llvm test-suite + RawSpeed, @ `-O3`, this results in
-33.58% less `IntToPtr`s (19014 -> 12629)
and +76.20% more `PtrToInt`s (18589 -> 32753),
which is an increase of +20.69% in total.

However just on RawSpeed, where i know there are basically
none `IntToPtr` in the original source code,
this results in -99.27% less `IntToPtr`s (2724 -> 20)
and +82.92% more `PtrToInt`s (4513 -> 8255).
which is again an increase of 14.34% in total.

To me this does seem like the step in the right direction,
we end up with strictly less `IntToPtr`, but strictly more `PtrToInt`,
which seems like a reasonable trade-off.

See https://reviews.llvm.org/D88860 / https://reviews.llvm.org/D88995
for some more discussion on the subject.

(Eventually, `CastInst::isNoopCast()`/`CastInst::isEliminableCastPair`
should be taught about this, yes)

Reviewed By: nlopes, nikic

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

Added: 


Modified: 
clang/test/CodeGen/arm64_32-vaarg.c
llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
llvm/test/Transforms/InstCombine/PR30597.ll
llvm/test/Transforms/InstCombine/intptr1.ll
llvm/test/Transforms/InstCombine/load-bitcast32.ll
llvm/test/Transforms/InstCombine/load-bitcast64.ll
llvm/test/Transforms/InstCombine/memset_chk-1.ll

Removed: 




diff  --git a/clang/test/CodeGen/arm64_32-vaarg.c 
b/clang/test/CodeGen/arm64_32-vaarg.c
index 7ee0277a167d..0f88841c7848 100644
--- a/clang/test/CodeGen/arm64_32-vaarg.c
+++ b/clang/test/CodeGen/arm64_32-vaarg.c
@@ -27,20 +27,20 @@ typedef struct {
 
 // Minimum slot size is 4 bytes, so address needs rounding up to multiple of 8.
 long long test_longlong(OneLongLong input, va_list *mylist) {
-// CHECK-LABEL: define i64 @test_longlong(i64 %input
-// CHECK: [[STARTPTR:%.*]] = bitcast i8** %mylist to i32*
-// CHECK: [[START:%.*]] = load i32, i32* [[STARTPTR]]
-
-// CHECK: [[ALIGN_TMP:%.*]] = add i32 [[START]], 7
-// CHECK: [[ALIGNED:%.*]] = and i32 [[ALIGN_TMP]], -8
-// CHECK: [[ALIGNED_ADDR:%.*]] = inttoptr i32 [[ALIGNED]] to i8*
-// CHECK: [[NEXT:%.*]] = getelementptr inbounds i8, i8* [[ALIGNED_ADDR]], i32 8
-// CHECK: store i8* [[NEXT]], i8** %mylist
-
-// CHECK: [[ADDR_STRUCT:%.*]] = inttoptr i32 [[ALIGNED]] to 
%struct.OneLongLong*
-// CHECK: [[ADDR_I64:%.*]] = getelementptr inbounds %struct.OneLongLong, 
%struct.OneLongLong* [[ADDR_STRUCT]], i32 0, i32 0
-// CHECK: [[RES:%.*]] = load i64, i64* [[ADDR_I64]]
-// CHECK: ret i64 [[RES]]
+  // CHECK-LABEL: define i64 @test_longlong(i64 %input
+  // CHECK: [[STARTPTR:%.*]] = load i8*, i8** %mylist
+  // CHECK: [[START:%.*]] = ptrtoint i8* [[STARTPTR]] to i32
+
+  // CHECK: [[ALIGN_TMP:%.*]] = add i32 [[START]], 7
+  // CHECK: [[ALIGNED:%.*]] = and i32 [[ALIGN_TMP]], -8
+  // CHECK: [[ALIGNED_ADDR:%.*]] = inttoptr i32 [[ALIGNED]] to i8*
+  // CHECK: [[NEXT:%.*]] = getelementptr inbounds i8, i8* [[ALIGNED_ADDR]], 
i32 8
+  // CHECK: store i8* [[NEXT]], i8** %mylist
+
+  // CHECK: [[ADDR_STRUCT:%.*]] = inttoptr i32 [[ALIGNED]] to 
%struct.OneLongLong*
+  // CHECK: [[ADDR_I64:%.*]] = getelementptr inbounds %struct.OneLongLong, 
%struct.OneLongLong* [[ADDR_STRUCT]], i32 0, i32 0
+  // CHECK: [[RES:%.*]] = load i64, i64* [[ADDR_I64]]
+  // CHECK: ret i64 [[RES]]
 
   return va_arg(*mylist, OneLongLong).a;
 }

diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
index b7bb34022ecc..8050c575c1f8 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -557,12 +557,12 @@ static Instruction 
*combineLoadToOperationType(InstCombinerImpl &IC,
   const DataLayout &DL = IC.getDataLayout();
 
   // Fold away bit casts of the loaded value by loading the desired type.
-  // We can do this for BitCastInsts as well as casts from and to pointer 
types,
-  // as long as those are noops (i.e., the source or dest type have the same
-  // bitwidth as the target's pointers).
+  // Note that we should not do this for pointer<->integer casts,

[PATCH] D88979: [InstCombine] combineLoadToOperationType(): don't fold int<->ptr cast into load

2020-10-11 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.

In D88979#2323940 , @lebedev.ri wrote:

> In D88979#2323935 , @nikic wrote:
>
>> Looking through other uses of isNoopCast(), I don't think it makes sense to 
>> push this change into it, as many other usages do need it to work with 
>> ptrtoint/inttoptr (some of them using it specifically for them). The comment 
>> above the function indicates that "no-op" is to be understood as "generates 
>> no code" here. Possibly it could do with a rename.
>
> I think i don't agree with you there.
> I agree with @nlopes, the end goal will be to basically disallow fusing of 
> `inttoptr`/`ptrtoint` into loads, 
> disallow dropping inttoptr-of-ptrtoint/ptrtoint-of-inttoptr, etc.
> And all that eventually boils down to updating 
> `CastInst::isNoopCast()`/`CastInst::isEliminableCastPair()`.

I agree with the general goal -- my point here is that changing isNoopCast() 
may not be the way to achieve that, because at least some of the current usages 
do need to include ptr/int casts, and can include them safely (not all usages 
result in type punning).

In fact, we already have a way to write "isNoopCast() without ptrtoint or 
inttoptr": `isa`. This didn't quite click before You might want to 
replace `CI->isNoopCast(DL) && LI.getType()->isPtrOrPtrVectorTy() == 
CI->getDestTy()->isPtrOrPtrVectorTy())` here with just `isa(CI)`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88979

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


[PATCH] D89197: [X86] Support -march=x86-64-v[234]

2020-10-11 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

In D89197#2323946 , @MaskRay wrote:

> Test __LAHF_SAHF__
> Update clang/docs/ReleaseNotes.rst
> Update clang/test/CodeGen/attr-target-x86.c to test X86.td changes. Ideally 
> "target-features" should be testable with llc to have better layering

How does attr-target-x86.c test the X86.td changes?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89197

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


[PATCH] D89210: [Sema, CodeGen] Implement [[likely]] and [[unlikely]] in SwitchStmt

2020-10-11 Thread Mark de Wever via Phabricator via cfe-commits
Mordante created this revision.
Mordante added reviewers: aaron.ballman, rjmccall, rsmith.
Mordante added a project: clang.
Mordante requested review of this revision.

This implements the likelihood attribute for the switch statement. Based on the 
discussion in D85091  and D86559 
 it only handles the attribute when placed on 
the case labels or the default labels.

It also marks the likelihood attribute as feature complete. There are be more 
QoI patches in the pipeline.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89210

Files:
  clang/include/clang/AST/Stmt.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/AST/Stmt.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/CodeGenCXX/attr-likelihood-switch-branch-weights.cpp
  clang/test/Preprocessor/has_attribute.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -987,7 +987,7 @@
 
   [[likely]] and [[unlikely]] attributes
   https://wg21.link/p0479r5";>P0479R5
-  Clang 12 (partial)
+  Clang 12
 
 
   typename optional in more contexts
Index: clang/test/Preprocessor/has_attribute.cpp
===
--- clang/test/Preprocessor/has_attribute.cpp
+++ clang/test/Preprocessor/has_attribute.cpp
@@ -62,13 +62,13 @@
 // FIXME(201806L) CHECK: ensures: 0
 // FIXME(201806L) CHECK: expects: 0
 // CHECK: fallthrough: 201603L
-// FIXME(201803L) CHECK: likely: 2L
+// CHECK: likely: 201803L
 // CHECK: maybe_unused: 201603L
 // ITANIUM: no_unique_address: 201803L
 // WINDOWS: no_unique_address: 0
 // CHECK: nodiscard: 201907L
 // CHECK: noreturn: 200809L
-// FIXME(201803L) CHECK: unlikely: 2L
+// CHECK: unlikely: 201803L
 
 // Test for Microsoft __declspec attributes
 
Index: clang/test/CodeGenCXX/attr-likelihood-switch-branch-weights.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/attr-likelihood-switch-branch-weights.cpp
@@ -0,0 +1,173 @@
+// RUN: %clang_cc1 -O1 -disable-llvm-passes -emit-llvm %s -o - -triple=x86_64-linux-gnu | FileCheck %s
+
+extern volatile int i;
+
+void OneCaseL() {
+  // CHECK-LABEL: define{{.*}}OneCaseL
+  // CHECK: switch
+  // CHECK: {{.*}} !prof !6
+  switch (i) {
+[[likely]] case 1:
+++i;
+break;
+  }
+}
+
+void OneCaseU() {
+  // CHECK-LABEL: define{{.*}}OneCaseU
+  // CHECK: switch
+  // CHECK: {{.*}} !prof !7
+  switch (i) {
+[[unlikely]] case 1 : ++i;
+break;
+  }
+}
+
+void TwoCasesLN() {
+  // CHECK-LABEL: define{{.*}}TwoCasesLN
+  // CHECK: switch
+  // CHECK: {{.*}} !prof !8
+  switch (i) {
+[[likely]] case 1:
+i += 2;
+break;
+
+  case 2:
+i += 3;
+break;
+  }
+}
+
+void TwoCasesUN() {
+  // CHECK-LABEL: define{{.*}}TwoCasesUN
+  // CHECK: switch
+  // CHECK: {{.*}} !prof !9
+  switch (i) {
+[[unlikely]] case 1:
+i += 2;
+break;
+
+  case 2:
+i += 3;
+break;
+  }
+}
+
+void TwoCasesLU() {
+  // CHECK-LABEL: define{{.*}}TwoCasesLU
+  // CHECK: switch
+  // CHECK: {{.*}} !prof !10
+  switch (i) {
+[[likely]] case 1:
+i += 2;
+break;
+
+  [[unlikely]] case 2:
+i += 3;
+break;
+  }
+}
+
+void CasesFallthroughNNLN() {
+  // CHECK-LABEL: define{{.*}}CasesFallthroughNNLN
+  // CHECK: switch
+  // CHECK: {{.*}} !prof !11
+  switch (i) {
+case 1:
+	  ++i;
+case 2:
+[[likely]] case 3:
+case 4:
+i += 3;
+break;
+  }
+}
+
+void CasesFallthroughNNUN() {
+  // CHECK-LABEL: define{{.*}}CasesFallthroughNNUN
+  // CHECK: switch
+  // CHECK: {{.*}} !prof !12
+  switch (i) {
+case 1:
+	  ++i;
+case 2:
+[[unlikely]] case 3:
+case 4:
+  i += 3;
+break;
+  }
+}
+
+void CasesFallthroughRangeSmallLN() {
+  // CHECK-LABEL: define{{.*}}CasesFallthroughRangeSmallLN
+  // CHECK: switch
+  // CHECK: {{.*}} !prof !13
+  switch (i) {
+case 1 ... 5:
+	  ++i;
+case 102:
+[[likely]] case 103:
+case 104:
+  i += 103;
+break;
+  }
+}
+
+void CasesFallthroughRangeSmallUN() {
+  // CHECK-LABEL: define{{.*}}CasesFallthroughRangeSmallUN
+  // CHECK: switch
+  // CHECK: {{.*}} !prof !14
+  switch (i) {
+case 1 ... 5:
+	  ++i;
+case 102:
+[[unlikely]] case 103:
+case 104:
+  i += 103;
+break;
+  }
+}
+
+void CasesFallthroughRangeLargeLLN() {
+  // CHECK-LABEL: define{{.*}}CasesFallthroughRangeLargeLLN
+  // CHECK: switch
+  // CHECK: {{.*}} !prof !8
+  // CHECK: caserange
+  // CHECK: br{{.*}} !prof !15
+  switch (i) {
+  [[likely]] case 0 ... 64:
+++i;
+  [[likely]] case 1003:
+  case 104:
+i += 103;
+break;
+  }
+}
+
+void CasesFallthroughRangeLargeUUN() {
+  // CHECK-LABEL: define{{.*}}CasesFallthroughR

[PATCH] D88154: Initial support for vectorization using Libmvec (GLIBC vector math library).

2020-10-11 Thread Venkataramanan Kumar via Phabricator via cfe-commits
venkataramanan.kumar.llvm added a comment.

In D88154#2314352 , @spatel wrote:

> In D88154#2310653 , 
> @venkataramanan.kumar.llvm wrote:
>
>> In D88154#2290205 , @abique wrote:
>>
>>> Looks good to me.
>>> Regarding the tests, it seems that you check if auto-vectorization takes 
>>> advantages of libmvec?
>>> Would it be interesting to have a test which declares a vector and call the 
>>> builtin sin on it?
>>>
>>> Thank you very much for the changes! :)
>>
>> do we we have built-in support for sin that takes vector types?
>>
>> I tried
>>
>> __m128d compute_sin(__m128d x)
>> {
>>
>>   return __builtin_sin(x);
>>
>> }
>>
 error: passing '__m128d' (vector of 2 'double' values) to parameter of 
 incompatible type 'double'
>
> We have LLVM intrinsics for sin/cos that may use vector types:
> http://llvm.org/docs/LangRef.html#llvm-sin-intrinsic
> ...but I don't know of a way to produce those directly from C source.

Ok I  see intrinsic for fp128 type in LangRef.

---Snip--
declare fp128 @llvm.cos.f128(fp128)

define fp128 @test_cos(float %float, double %double, fp128 %fp128) {

  %cosfp128 = call fp128 @llvm.cos.f128(fp128 %fp128)
  ret fp128 %cosfp128

}
--Snip--

f128  is treated a long double I see call to cosl.

  vmovaps %xmm2, %xmm0
   jmp cosl   

so I am not sure how to generate vector calls via built-ins.


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

https://reviews.llvm.org/D88154

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


Re: [clang] 9dcd96f - Canonicalize declaration pointers when forming APValues.

2020-10-11 Thread Richard Smith via cfe-commits
On Fri, 9 Oct 2020 at 19:12, Arthur Eubanks  wrote:

> I think this is the cause of https://crbug.com/1134762. Can we
> speculatively revert while coming up with a repro? Or would you like a
> repro first?
>

If you're blocked on this, sure, please go ahead and revert until you have
a repro. But the revert will block ongoing development work, so a
reproducer would definitely be appreciated! Per PR47663, there are some
pretty fundamental problems with adding the 'weak' attribute "too late", so
if that's what's going on, the best approach might be to move the 'weak'
attribute to an earlier declaration.

On Sun, Sep 27, 2020 at 7:06 PM Richard Smith via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>>
>> Author: Richard Smith
>> Date: 2020-09-27T19:05:26-07:00
>> New Revision: 9dcd96f728863d40d6f5922ed52732fdd728fb5f
>>
>> URL:
>> https://github.com/llvm/llvm-project/commit/9dcd96f728863d40d6f5922ed52732fdd728fb5f
>> DIFF:
>> https://github.com/llvm/llvm-project/commit/9dcd96f728863d40d6f5922ed52732fdd728fb5f.diff
>>
>> LOG: Canonicalize declaration pointers when forming APValues.
>>
>> References to different declarations of the same entity aren't different
>> values, so shouldn't have different representations.
>>
>> Recommit of e6393ee813178e9d3306b8e3c6949a4f32f8a2cb with fixed handling
>> for weak declarations. We now look for attributes on the most recent
>> declaration when determining whether a declaration is weak. (Second
>> recommit with further fixes for mishandling of weak declarations. Our
>> behavior here is fundamentally unsound -- see PR47663 -- but this
>> approach attempts to not make things worse.)
>>
>> Added:
>>
>>
>> Modified:
>> clang/include/clang/AST/APValue.h
>> clang/lib/AST/APValue.cpp
>> clang/lib/AST/Decl.cpp
>> clang/lib/AST/DeclBase.cpp
>> clang/lib/AST/ExprConstant.cpp
>> clang/lib/CodeGen/CGExprConstant.cpp
>> clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p9.cpp
>> clang/test/CodeGenCXX/weak-external.cpp
>> clang/test/OpenMP/ordered_messages.cpp
>>
>> Removed:
>>
>>
>>
>>
>> 
>> diff  --git a/clang/include/clang/AST/APValue.h
>> b/clang/include/clang/AST/APValue.h
>> index 5103cfa8604e..6307f8a92e5a 100644
>> --- a/clang/include/clang/AST/APValue.h
>> +++ b/clang/include/clang/AST/APValue.h
>> @@ -174,6 +174,7 @@ class APValue {
>>return !(LHS == RHS);
>>  }
>>  friend llvm::hash_code hash_value(const LValueBase &Base);
>> +friend struct llvm::DenseMapInfo;
>>
>>private:
>>  PtrTy Ptr;
>> @@ -201,8 +202,7 @@ class APValue {
>>
>>public:
>>  LValuePathEntry() : Value() {}
>> -LValuePathEntry(BaseOrMemberType BaseOrMember)
>> -:
>> Value{reinterpret_cast(BaseOrMember.getOpaqueValue())} {}
>> +LValuePathEntry(BaseOrMemberType BaseOrMember);
>>  static LValuePathEntry ArrayIndex(uint64_t Index) {
>>LValuePathEntry Result;
>>Result.Value = Index;
>>
>> diff  --git a/clang/lib/AST/APValue.cpp b/clang/lib/AST/APValue.cpp
>> index 08ae0ff3c67d..32d3ff7ce1d0 100644
>> --- a/clang/lib/AST/APValue.cpp
>> +++ b/clang/lib/AST/APValue.cpp
>> @@ -38,7 +38,7 @@ static_assert(
>>  "Type is insufficiently aligned");
>>
>>  APValue::LValueBase::LValueBase(const ValueDecl *P, unsigned I, unsigned
>> V)
>> -: Ptr(P), Local{I, V} {}
>> +: Ptr(P ? cast(P->getCanonicalDecl()) : nullptr),
>> Local{I, V} {}
>>  APValue::LValueBase::LValueBase(const Expr *P, unsigned I, unsigned V)
>>  : Ptr(P), Local{I, V} {}
>>
>> @@ -82,13 +82,19 @@ bool operator==(const APValue::LValueBase &LHS,
>>  const APValue::LValueBase &RHS) {
>>if (LHS.Ptr != RHS.Ptr)
>>  return false;
>> -  if (LHS.is())
>> +  if (LHS.is() || LHS.is())
>>  return true;
>>return LHS.Local.CallIndex == RHS.Local.CallIndex &&
>>   LHS.Local.Version == RHS.Local.Version;
>>  }
>>  }
>>
>> +APValue::LValuePathEntry::LValuePathEntry(BaseOrMemberType BaseOrMember)
>> {
>> +  if (const Decl *D = BaseOrMember.getPointer())
>> +BaseOrMember.setPointer(D->getCanonicalDecl());
>> +  Value = reinterpret_cast(BaseOrMember.getOpaqueValue());
>> +}
>> +
>>  namespace {
>>struct LVBase {
>>  APValue::LValueBase Base;
>> @@ -113,14 +119,16 @@ APValue::LValueBase::operator bool () const {
>>
>>  clang::APValue::LValueBase
>>  llvm::DenseMapInfo::getEmptyKey() {
>> -  return clang::APValue::LValueBase(
>> -  DenseMapInfo::getEmptyKey());
>> +  clang::APValue::LValueBase B;
>> +  B.Ptr = DenseMapInfo::getEmptyKey();
>> +  return B;
>>  }
>>
>>  clang::APValue::LValueBase
>>  llvm::DenseMapInfo::getTombstoneKey() {
>> -  return clang::APValue::LValueBase(
>> -  DenseMapInfo::getTombstoneKey());
>> +  clang::APValue::LValueBase B;
>> +  B.Ptr = DenseMapInfo::getTombstoneKey();
>> +  return B;
>>  }
>>
>>  namespace clang {
>> @@ -773,8 +781,10 @@ void APValue::MakeMemberPointer(const ValueDecl
>> 

[PATCH] D88154: Initial support for vectorization using Libmvec (GLIBC vector math library).

2020-10-11 Thread Venkataramanan Kumar via Phabricator via cfe-commits
venkataramanan.kumar.llvm updated this revision to Diff 297480.
venkataramanan.kumar.llvm added a comment.

Changed library naming to LIBMVEC-X86 as per comments and also selected based 
on Target Tripple in clang. 
I am still working on auto generating FileCheck for the test cases.


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

https://reviews.llvm.org/D88154

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Driver/autocomplete.c
  llvm/include/llvm/Analysis/TargetLibraryInfo.h
  llvm/include/llvm/Analysis/VecFuncs.def
  llvm/lib/Analysis/TargetLibraryInfo.cpp
  llvm/test/Transforms/LoopVectorize/X86/libm-vector-calls-finite.ll
  llvm/test/Transforms/LoopVectorize/X86/libm-vector-calls.ll
  llvm/test/Transforms/Util/add-TLI-mappings.ll

Index: llvm/test/Transforms/Util/add-TLI-mappings.ll
===
--- llvm/test/Transforms/Util/add-TLI-mappings.ll
+++ llvm/test/Transforms/Util/add-TLI-mappings.ll
@@ -3,6 +3,8 @@
 ; RUN: opt -vector-library=MASSV  -inject-tli-mappings-S < %s | FileCheck %s  --check-prefixes=COMMON,MASSV
 ; RUN: opt -vector-library=MASSV  -passes=inject-tli-mappings -S < %s | FileCheck %s  --check-prefixes=COMMON,MASSV
 ; RUN: opt -vector-library=Accelerate -inject-tli-mappings-S < %s | FileCheck %s  --check-prefixes=COMMON,ACCELERATE
+; RUN: opt -vector-library=LIBMVEC-X86 -inject-tli-mappings-S < %s | FileCheck %s  --check-prefixes=COMMON,LIBMVEC-X86
+; RUN: opt -vector-library=LIBMVEC-X86 -passes=inject-tli-mappings -S < %s | FileCheck %s  --check-prefixes=COMMON,LIBMVEC-X86
 ; RUN: opt -vector-library=Accelerate -passes=inject-tli-mappings -S < %s | FileCheck %s  --check-prefixes=COMMON,ACCELERATE
 
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
@@ -21,6 +23,9 @@
 ; MASSV-SAME: i8* bitcast (<4 x float> (<4 x float>)* @__log10f4_massv to i8*)
 ; ACCELERATE-SAME:  [1 x i8*] [
 ; ACCELERATE-SAME:i8* bitcast (<4 x float> (<4 x float>)* @vlog10f to i8*)
+; LIBMVEC-X86-SAME: [2 x i8*] [
+; LIBMVEC-X86-SAME:   i8* bitcast (<2 x double> (<2 x double>)* @_ZGVbN2v_sin to i8*),
+; LIBMVEC-X86-SAME:   i8* bitcast (<4 x double> (<4 x double>)* @_ZGVdN4v_sin to i8*)
 ; COMMON-SAME:  ], section "llvm.metadata"
 
 define double @sin_f64(double %in) {
@@ -28,6 +33,7 @@
 ; SVML: call double @sin(double %{{.*}}) #[[SIN:[0-9]+]]
 ; MASSV:call double @sin(double %{{.*}}) #[[SIN:[0-9]+]]
 ; ACCELERATE:   call double @sin(double %{{.*}})
+; LIBMVEC-X86:  call double @sin(double %{{.*}}) #[[SIN:[0-9]+]]
 ; No mapping of "sin" to a vector function for Accelerate.
 ; ACCELERATE-NOT: _ZGV_LLVM_{{.*}}_sin({{.*}})
   %call = tail call double @sin(double %in)
@@ -39,10 +45,12 @@
 define float @call_llvm.log10.f32(float %in) {
 ; COMMON-LABEL: @call_llvm.log10.f32(
 ; SVML: call float @llvm.log10.f32(float %{{.*}})
+; LIBMVEC-X86:  call float @llvm.log10.f32(float %{{.*}})
 ; MASSV:call float @llvm.log10.f32(float %{{.*}}) #[[LOG10:[0-9]+]]
 ; ACCELERATE:   call float @llvm.log10.f32(float %{{.*}}) #[[LOG10:[0-9]+]]
 ; No mapping of "llvm.log10.f32" to a vector function for SVML.
 ; SVML-NOT: _ZGV_LLVM_{{.*}}_llvm.log10.f32({{.*}})
+; LIBMVEC-X86-NOT: _ZGV_LLVM_{{.*}}_llvm.log10.f32({{.*}})
   %call = tail call float @llvm.log10.f32(float %in)
   ret float %call
 }
@@ -62,3 +70,7 @@
 
 ; ACCELERATE:  attributes #[[LOG10]] = { "vector-function-abi-variant"=
 ; ACCELERATE-SAME:   "_ZGV_LLVM_N4v_llvm.log10.f32(vlog10f)" }
+
+; LIBMVEC-X86:  attributes #[[SIN]] = { "vector-function-abi-variant"=
+; LIBMVEC-X86-SAME:   "_ZGV_LLVM_N2v_sin(_ZGVbN2v_sin),
+; LIBMVEC-X86-SAME:   _ZGV_LLVM_N4v_sin(_ZGVdN4v_sin)" }
Index: llvm/test/Transforms/LoopVectorize/X86/libm-vector-calls.ll
===
--- /dev/null
+++ llvm/test/Transforms/LoopVectorize/X86/libm-vector-calls.ll
@@ -0,0 +1,325 @@
+; RUN: opt -vector-library=LIBMVEC-X86  -inject-tli-mappings -force-vector-width=4 -force-vector-interleave=1 -loop-vectorize -S < %s | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+declare double @sin(double) #0
+declare float @sinf(float) #0
+declare double @llvm.sin.f64(double) #0
+declare float @llvm.sin.f32(float) #0
+
+declare double @cos(double) #0
+declare float @cosf(float) #0
+declare double @llvm.cos.f64(double) #0
+declare float @llvm.cos.f32(float) #0
+
+define void @sin_f64(double* nocapture %varray) {
+; CHECK-LABEL: @sin_f64(
+; CHECK:[[TMP5:%.*]] = call <4 x double> @_ZGVdN4v_sin(<4 x double> [[TMP4:%.*]])
+; CHECK:ret void
+;
+entry:
+  br label %for.body
+
+for.body:
+  %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]

[PATCH] D89197: [X86] Support -march=x86-64-v[234]

2020-10-11 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D89197#2323979 , @craig.topper 
wrote:

> In D89197#2323946 , @MaskRay wrote:
>
>> Test __LAHF_SAHF__
>> Update clang/docs/ReleaseNotes.rst
>> Update clang/test/CodeGen/attr-target-x86.c to test X86.td changes. Ideally 
>> "target-features" should be testable with llc to have better layering
>
> How does attr-target-x86.c test the X86.td changes?

I was wrong. `__attribute__((target("arch=...")))` cannot test features in 
X86.td. X86TargetParser.cpp implements the feature propagation mechanism.

I have checked the introduction of cooperlake, tigerlake, sapphirerapids and 
many other commits to X86.td, these features are mostly under-tested.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89197

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


[PATCH] D89197: [X86] Support -march=x86-64-v[234]

2020-10-11 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89197

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


[PATCH] D87256: [clangd] Avoid relations being overwritten in a header shard

2020-10-11 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 297482.
nridge added a comment.

Slightly simplified test (base class does not need to be a template to trigger 
the issue)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87256

Files:
  clang-tools-extra/clangd/index/FileIndex.cpp
  clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
  clang-tools-extra/clangd/unittests/FileIndexTests.cpp

Index: clang-tools-extra/clangd/unittests/FileIndexTests.cpp
===
--- clang-tools-extra/clangd/unittests/FileIndexTests.cpp
+++ clang-tools-extra/clangd/unittests/FileIndexTests.cpp
@@ -547,6 +547,8 @@
   Sym2.CanonicalDeclaration.FileURI = BHeaderUri.c_str();
   Sym2.Definition.FileURI = BSourceUri.c_str();
 
+  auto Sym3 = symbol("3"); // not stored
+
   IndexFileIn IF;
   {
 SymbolSlab::Builder B;
@@ -562,12 +564,13 @@
   }
   {
 RelationSlab::Builder B;
-// Should be stored in a.h
+// Should be stored in a.h and b.h
 B.insert(Relation{Sym1.ID, RelationKind::BaseOf, Sym2.ID});
-// Should be stored in b.h
+// Should be stored in a.h and b.h
 B.insert(Relation{Sym2.ID, RelationKind::BaseOf, Sym1.ID});
-// Dangling relation should be dropped.
-B.insert(Relation{symbol("3").ID, RelationKind::BaseOf, Sym1.ID});
+// Should be stored in a.h (where Sym1 is stored) even though
+// the relation is dangling as Sym3 is unknown.
+B.insert(Relation{Sym3.ID, RelationKind::BaseOf, Sym1.ID});
 IF.Relations.emplace(std::move(B).build());
   }
 
@@ -605,7 +608,9 @@
 EXPECT_THAT(*Shard->Refs, IsEmpty());
 EXPECT_THAT(
 *Shard->Relations,
-UnorderedElementsAre(Relation{Sym1.ID, RelationKind::BaseOf, Sym2.ID}));
+UnorderedElementsAre(Relation{Sym1.ID, RelationKind::BaseOf, Sym2.ID},
+ Relation{Sym2.ID, RelationKind::BaseOf, Sym1.ID},
+ Relation{Sym3.ID, RelationKind::BaseOf, Sym1.ID}));
 ASSERT_THAT(Shard->Sources->keys(), UnorderedElementsAre(AHeaderUri));
 EXPECT_THAT(Shard->Sources->lookup(AHeaderUri).DirectIncludes, IsEmpty());
 EXPECT_TRUE(Shard->Cmd.hasValue());
@@ -617,7 +622,8 @@
 EXPECT_THAT(*Shard->Refs, IsEmpty());
 EXPECT_THAT(
 *Shard->Relations,
-UnorderedElementsAre(Relation{Sym2.ID, RelationKind::BaseOf, Sym1.ID}));
+UnorderedElementsAre(Relation{Sym1.ID, RelationKind::BaseOf, Sym2.ID},
+ Relation{Sym2.ID, RelationKind::BaseOf, Sym1.ID}));
 ASSERT_THAT(Shard->Sources->keys(),
 UnorderedElementsAre(BHeaderUri, AHeaderUri));
 EXPECT_THAT(Shard->Sources->lookup(BHeaderUri).DirectIncludes,
Index: clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
===
--- clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
+++ clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
@@ -229,6 +229,49 @@
FileURI("unittest:///root/B.cc")}));
 }
 
+TEST_F(BackgroundIndexTest, RelationsMultiFile) {
+  MockFS FS;
+  FS.Files[testPath("root/Base.h")] = "class Base {};";
+  FS.Files[testPath("root/A.cc")] = R"cpp(
+#include "Base.h"
+class A : public Base {};
+  )cpp";
+  FS.Files[testPath("root/B.cc")] = R"cpp(
+#include "Base.h"
+class B : public Base {};
+  )cpp";
+
+  llvm::StringMap Storage;
+  size_t CacheHits = 0;
+  MemoryShardStorage MSS(Storage, CacheHits);
+  OverlayCDB CDB(/*Base=*/nullptr);
+  BackgroundIndex Index(FS, CDB, [&](llvm::StringRef) { return &MSS; },
+/*Opts=*/{});
+
+  tooling::CompileCommand Cmd;
+  Cmd.Filename = testPath("root/A.cc");
+  Cmd.Directory = testPath("root");
+  Cmd.CommandLine = {"clang++", Cmd.Filename};
+  CDB.setCompileCommand(testPath("root/A.cc"), Cmd);
+  ASSERT_TRUE(Index.blockUntilIdleForTest());
+
+  Cmd.Filename = testPath("root/B.cc");
+  Cmd.CommandLine = {"clang++", Cmd.Filename};
+  CDB.setCompileCommand(testPath("root/B.cc"), Cmd);
+  ASSERT_TRUE(Index.blockUntilIdleForTest());
+
+  auto HeaderShard = MSS.loadShard(testPath("root/Base.h"));
+  EXPECT_NE(HeaderShard, nullptr);
+  SymbolID Base = findSymbol(*HeaderShard->Symbols, "Base").ID;
+
+  RelationsRequest Req;
+  Req.Subjects.insert(Base);
+  Req.Predicate = RelationKind::BaseOf;
+  uint32_t Results = 0;
+  Index.relations(Req, [&](const SymbolID &, const Symbol &) { ++Results; });
+  EXPECT_EQ(Results, 2u);
+}
+
 TEST_F(BackgroundIndexTest, MainFileRefs) {
   MockFS FS;
   FS.Files[testPath("root/A.h")] = R"cpp(
@@ -345,14 +388,15 @@
 EXPECT_THAT(Ref.second,
 UnorderedElementsAre(FileURI("unittest:///root/A.cc")));
 
-  // The BaseOf relationship between A_CC and B_CC is stored in the file
-  // containing the definition of the subject (A_CC)
+  // The BaseOf relationship between A_CC and B_CC is s

[PATCH] D87256: [clangd] Avoid relations being overwritten in a header shard

2020-10-11 Thread Nathan Ridge via Phabricator via cfe-commits
nridge marked an inline comment as done.
nridge added inline comments.



Comment at: clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp:232
 
+TEST_F(BackgroundIndexTest, RelationsMultiFile) {
+  MockFS FS;

kadircet wrote:
> kadircet wrote:
> > nridge wrote:
> > > kadircet wrote:
> > > > do we still need this test?
> > > I think it's still useful, yes. If someone makes a change to the way 
> > > relations are stored in the future, they could regress this use case 
> > > without a test specifically for it.
> > this one was marked as resolved but i still don't see the reasoning. can we 
> > test this in fileindextests instead?
> > 
> > we already test the sharding logic, we need to test the merging logic now. 
> > can we rather test it at FileSymbols layer directly? or is there something 
> > extra that i am misisng?
> okay, i still think it is better to test on FileSymbols layer but not that 
> important.
The reason I'd like to have a test at this layer is so that we have a test that 
closely approximates the steps to reproduce: create files with certain contents 
and inclusion relationships between them, index them, and perform a particular 
query. I feel like internal abstractions like `FileSymbols` are liable to 
change over time through refactorings, and so tests written against them are 
less robust.

Note, I don't think using `BackgroundIndex` is important for the kind of test 
I'd like; `FileIndex` would be fine too. However, I could not see how to use 
`FileIndex` with files that contain `#include` statements (didn't see a way to 
provide a `MockFS` or another way to get the includes to be resolved).

That said, I did try to write an additional test using `FileSymbols`, but I 
found that:
  * it only exercises the merging logic, not the sharding logic
  * I couldn't get the test to fail even if I omit the merging logic of this 
patch, because both `MemIndex` and `Dex` build a `DenseMap` for relations and 
therefore end up implicitly deduplicating anyways


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87256

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


[PATCH] D87256: [clangd] Avoid relations being overwritten in a header shard

2020-10-11 Thread Nathan Ridge 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 rGf82346fd7391: [clangd] Avoid relations being overwritten in 
a header shard (authored by nridge).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87256

Files:
  clang-tools-extra/clangd/index/FileIndex.cpp
  clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
  clang-tools-extra/clangd/unittests/FileIndexTests.cpp

Index: clang-tools-extra/clangd/unittests/FileIndexTests.cpp
===
--- clang-tools-extra/clangd/unittests/FileIndexTests.cpp
+++ clang-tools-extra/clangd/unittests/FileIndexTests.cpp
@@ -547,6 +547,8 @@
   Sym2.CanonicalDeclaration.FileURI = BHeaderUri.c_str();
   Sym2.Definition.FileURI = BSourceUri.c_str();
 
+  auto Sym3 = symbol("3"); // not stored
+
   IndexFileIn IF;
   {
 SymbolSlab::Builder B;
@@ -562,12 +564,13 @@
   }
   {
 RelationSlab::Builder B;
-// Should be stored in a.h
+// Should be stored in a.h and b.h
 B.insert(Relation{Sym1.ID, RelationKind::BaseOf, Sym2.ID});
-// Should be stored in b.h
+// Should be stored in a.h and b.h
 B.insert(Relation{Sym2.ID, RelationKind::BaseOf, Sym1.ID});
-// Dangling relation should be dropped.
-B.insert(Relation{symbol("3").ID, RelationKind::BaseOf, Sym1.ID});
+// Should be stored in a.h (where Sym1 is stored) even though
+// the relation is dangling as Sym3 is unknown.
+B.insert(Relation{Sym3.ID, RelationKind::BaseOf, Sym1.ID});
 IF.Relations.emplace(std::move(B).build());
   }
 
@@ -605,7 +608,9 @@
 EXPECT_THAT(*Shard->Refs, IsEmpty());
 EXPECT_THAT(
 *Shard->Relations,
-UnorderedElementsAre(Relation{Sym1.ID, RelationKind::BaseOf, Sym2.ID}));
+UnorderedElementsAre(Relation{Sym1.ID, RelationKind::BaseOf, Sym2.ID},
+ Relation{Sym2.ID, RelationKind::BaseOf, Sym1.ID},
+ Relation{Sym3.ID, RelationKind::BaseOf, Sym1.ID}));
 ASSERT_THAT(Shard->Sources->keys(), UnorderedElementsAre(AHeaderUri));
 EXPECT_THAT(Shard->Sources->lookup(AHeaderUri).DirectIncludes, IsEmpty());
 EXPECT_TRUE(Shard->Cmd.hasValue());
@@ -617,7 +622,8 @@
 EXPECT_THAT(*Shard->Refs, IsEmpty());
 EXPECT_THAT(
 *Shard->Relations,
-UnorderedElementsAre(Relation{Sym2.ID, RelationKind::BaseOf, Sym1.ID}));
+UnorderedElementsAre(Relation{Sym1.ID, RelationKind::BaseOf, Sym2.ID},
+ Relation{Sym2.ID, RelationKind::BaseOf, Sym1.ID}));
 ASSERT_THAT(Shard->Sources->keys(),
 UnorderedElementsAre(BHeaderUri, AHeaderUri));
 EXPECT_THAT(Shard->Sources->lookup(BHeaderUri).DirectIncludes,
Index: clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
===
--- clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
+++ clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
@@ -229,6 +229,49 @@
FileURI("unittest:///root/B.cc")}));
 }
 
+TEST_F(BackgroundIndexTest, RelationsMultiFile) {
+  MockFS FS;
+  FS.Files[testPath("root/Base.h")] = "class Base {};";
+  FS.Files[testPath("root/A.cc")] = R"cpp(
+#include "Base.h"
+class A : public Base {};
+  )cpp";
+  FS.Files[testPath("root/B.cc")] = R"cpp(
+#include "Base.h"
+class B : public Base {};
+  )cpp";
+
+  llvm::StringMap Storage;
+  size_t CacheHits = 0;
+  MemoryShardStorage MSS(Storage, CacheHits);
+  OverlayCDB CDB(/*Base=*/nullptr);
+  BackgroundIndex Index(FS, CDB, [&](llvm::StringRef) { return &MSS; },
+/*Opts=*/{});
+
+  tooling::CompileCommand Cmd;
+  Cmd.Filename = testPath("root/A.cc");
+  Cmd.Directory = testPath("root");
+  Cmd.CommandLine = {"clang++", Cmd.Filename};
+  CDB.setCompileCommand(testPath("root/A.cc"), Cmd);
+  ASSERT_TRUE(Index.blockUntilIdleForTest());
+
+  Cmd.Filename = testPath("root/B.cc");
+  Cmd.CommandLine = {"clang++", Cmd.Filename};
+  CDB.setCompileCommand(testPath("root/B.cc"), Cmd);
+  ASSERT_TRUE(Index.blockUntilIdleForTest());
+
+  auto HeaderShard = MSS.loadShard(testPath("root/Base.h"));
+  EXPECT_NE(HeaderShard, nullptr);
+  SymbolID Base = findSymbol(*HeaderShard->Symbols, "Base").ID;
+
+  RelationsRequest Req;
+  Req.Subjects.insert(Base);
+  Req.Predicate = RelationKind::BaseOf;
+  uint32_t Results = 0;
+  Index.relations(Req, [&](const SymbolID &, const Symbol &) { ++Results; });
+  EXPECT_EQ(Results, 2u);
+}
+
 TEST_F(BackgroundIndexTest, MainFileRefs) {
   MockFS FS;
   FS.Files[testPath("root/A.h")] = R"cpp(
@@ -345,14 +388,15 @@
 EXPECT_THAT(Ref.second,
 UnorderedElementsAre(FileURI("unittest:///root/A.cc")));
 
-  // The BaseOf relationship between A_CC and B_CC is stored in the file
-  // containing the defi

[clang-tools-extra] f82346f - [clangd] Avoid relations being overwritten in a header shard

2020-10-11 Thread Nathan Ridge via cfe-commits

Author: Nathan Ridge
Date: 2020-10-11T15:32:54-04:00
New Revision: f82346fd7391fdd15b77355deb6f7c030a89dcb5

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

LOG: [clangd] Avoid relations being overwritten in a header shard

Fixes https://github.com/clangd/clangd/issues/510

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

Added: 


Modified: 
clang-tools-extra/clangd/index/FileIndex.cpp
clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
clang-tools-extra/clangd/unittests/FileIndexTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/index/FileIndex.cpp 
b/clang-tools-extra/clangd/index/FileIndex.cpp
index 155e09ca1e97..ad55b6ad7f5d 100644
--- a/clang-tools-extra/clangd/index/FileIndex.cpp
+++ b/clang-tools-extra/clangd/index/FileIndex.cpp
@@ -34,6 +34,7 @@
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
+#include 
 #include 
 #include 
 #include 
@@ -147,13 +148,21 @@ FileShardedIndex::FileShardedIndex(IndexFileIn Input)
   }
 }
   }
-  // Attribute relations to the file declaraing their Subject as Object might
-  // not have been indexed, see SymbolCollector::processRelations for details.
+  // The Subject and/or Object shards might be part of multiple TUs. In
+  // such cases there will be a race and the last TU to write the shard
+  // will win and all the other relations will be lost. To avoid this,
+  // we store relations in both shards. A race might still happen if the
+  // same translation unit produces 
diff erent relations under 
diff erent
+  // configurations, but that's something clangd doesn't handle in general.
   if (Index.Relations) {
 for (const auto &R : *Index.Relations) {
   // FIXME: RelationSlab shouldn't contain dangling relations.
-  if (auto *File = SymbolIDToFile.lookup(R.Subject))
-File->Relations.insert(&R);
+  FileShard *SubjectFile = SymbolIDToFile.lookup(R.Subject);
+  FileShard *ObjectFile = SymbolIDToFile.lookup(R.Object);
+  if (SubjectFile)
+SubjectFile->Relations.insert(&R);
+  if (ObjectFile && ObjectFile != SubjectFile)
+ObjectFile->Relations.insert(&R);
 }
   }
   // Store only the direct includes of a file in a shard.
@@ -343,6 +352,12 @@ FileSymbols::buildIndex(IndexType Type, DuplicateHandling 
DuplicateHandle,
 for (const auto &R : *RelationSlab)
   AllRelations.push_back(R);
   }
+  // Sort relations and remove duplicates that could arise due to
+  // relations being stored in both the shards containing their
+  // subject and object.
+  llvm::sort(AllRelations);
+  AllRelations.erase(std::unique(AllRelations.begin(), AllRelations.end()),
+ AllRelations.end());
 
   size_t StorageSize =
   RefsStorage.size() * sizeof(Ref) + SymsStorage.size() * sizeof(Symbol);

diff  --git a/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp 
b/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
index f9f584e8895f..adf39a915c1a 100644
--- a/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
+++ b/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
@@ -229,6 +229,49 @@ TEST_F(BackgroundIndexTest, IndexTwoFiles) {
FileURI("unittest:///root/B.cc")}));
 }
 
+TEST_F(BackgroundIndexTest, RelationsMultiFile) {
+  MockFS FS;
+  FS.Files[testPath("root/Base.h")] = "class Base {};";
+  FS.Files[testPath("root/A.cc")] = R"cpp(
+#include "Base.h"
+class A : public Base {};
+  )cpp";
+  FS.Files[testPath("root/B.cc")] = R"cpp(
+#include "Base.h"
+class B : public Base {};
+  )cpp";
+
+  llvm::StringMap Storage;
+  size_t CacheHits = 0;
+  MemoryShardStorage MSS(Storage, CacheHits);
+  OverlayCDB CDB(/*Base=*/nullptr);
+  BackgroundIndex Index(FS, CDB, [&](llvm::StringRef) { return &MSS; },
+/*Opts=*/{});
+
+  tooling::CompileCommand Cmd;
+  Cmd.Filename = testPath("root/A.cc");
+  Cmd.Directory = testPath("root");
+  Cmd.CommandLine = {"clang++", Cmd.Filename};
+  CDB.setCompileCommand(testPath("root/A.cc"), Cmd);
+  ASSERT_TRUE(Index.blockUntilIdleForTest());
+
+  Cmd.Filename = testPath("root/B.cc");
+  Cmd.CommandLine = {"clang++", Cmd.Filename};
+  CDB.setCompileCommand(testPath("root/B.cc"), Cmd);
+  ASSERT_TRUE(Index.blockUntilIdleForTest());
+
+  auto HeaderShard = MSS.loadShard(testPath("root/Base.h"));
+  EXPECT_NE(HeaderShard, nullptr);
+  SymbolID Base = findSymbol(*HeaderShard->Symbols, "Base").ID;
+
+  RelationsRequest Req;
+  Req.Subjects.insert(Base);
+  Req.Predicate = RelationKind::BaseOf;
+  uint32_t Results = 0;
+  Index.relations(Req, [&](const SymbolID &, const Symbol &) { ++Results; });
+  EXPECT_EQ(Results, 2u);
+}
+
 TEST_F(BackgroundIndexTest, MainFileRefs) {
   

[PATCH] D88463: [clangd] Try harder to get accurate ranges for documentSymbols in macros

2020-10-11 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a reviewer: sammccall.
nridge added a comment.

Sam, perhaps you could have a look at this? It involves tricky macro location 
stuff.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88463

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


[PATCH] D89212: PR47663: Warn if an entity becomes weak after its first use.

2020-10-11 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith created this revision.
rsmith added reviewers: rjmccall, aaron.ballman.
Herald added a project: clang.
rsmith requested review of this revision.

Such code will not work in general; we might have already used the
non-weakness, for example when constant-evaluating an address comparison
Thisor when generating code for the declaration.

Modern versions of GCC reject some such cases, but silently accept
others (based, it appears, on whether the weakness of the declaration
was already inspected). It doesn't seem feasible for us to exactly
follow their behavior, and it might be problematic to start rejecting
cases that GCC accepts and that work in practice, so only warn on this
rather than rejecting, at least for now.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89212

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/DeclBase.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Sema/attr-weak.c
  clang/test/Sema/init.c

Index: clang/test/Sema/init.c
===
--- clang/test/Sema/init.c
+++ clang/test/Sema/init.c
@@ -155,7 +155,7 @@
 int PR4386_a = ((void *) PR4386_bar) != 0;
 int PR4386_b = ((void *) PR4386_foo) != 0; // expected-error{{initializer element is not a compile-time constant}}
 int PR4386_c = ((void *) PR4386_zed) != 0;
-int PR4386_zed() __attribute((weak));
+int PR4386_zed() __attribute((weak)); // expected-warning{{'PR4386_zed' declared weak after its first use}} expected-note {{attribute}}
 
 //  (derived from SPEC vortex benchmark)
 typedef char strty[10];
Index: clang/test/Sema/attr-weak.c
===
--- clang/test/Sema/attr-weak.c
+++ clang/test/Sema/attr-weak.c
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -verify -fsyntax-only %s
+// RUN: %clang_cc1 -verify -fsyntax-only %s -triple x86_64-unknown-macosx10.3.0 -DMACOS
+// RUN: %clang_cc1 -verify -fsyntax-only %s -triple x86_64-linux-gnu -DLINUX
 
 extern int f0() __attribute__((weak));
 extern int g0 __attribute__((weak));
@@ -25,3 +26,47 @@
 
 static void pr14946_f();
 void pr14946_f() __attribute__((weak)); // expected-error {{weak declaration cannot have internal linkage}}
+
+void some_function();
+
+void pr47663_a();
+void pr47663_b();
+static void pr47663_c();
+void pr47663_d();
+void pr47663_e(); // expected-warning {{declared weak after its first use}}
+void pr47663_f(); // expected-note {{possible target}}
+void pr47663_g();
+int pr47663_h;
+void pr47663_z() __attribute__((weak));
+void use() {
+  int arr_a[&pr47663_a ? 1 : -1];
+  int arr_b[&pr47663_b ? 1 : -1];
+  int arr_c[&pr47663_c ? 1 : -1];
+  int arr_d[&pr47663_d ? 1 : -1];
+  int arr_e[&pr47663_e ? 1 : -1];
+  int arr_f[&pr47663_f ? 1 : -1];
+  int arr_g[&pr47663_g ? 1 : -1];
+  int arr_h[&pr47663_h ? 1 : -1]; // expected-warning {{will always evaluate to 'true'}}
+  int arr_z[&pr47663_z ? -1 : 1];
+}
+void pr47663_a() __attribute__((weak)); // expected-warning {{declared weak after its first use}} expected-note {{'weak' attribute here}}
+void pr47663_b() __attribute__((weak_import)); // expected-warning {{declared weak after its first use}} expected-note {{'weak_import' attribute here}}
+#ifdef LINUX
+static void pr47663_c() __attribute__((weakref, alias("might_not_exist"))); // expected-warning {{declared weak after its first use}} expected-note {{'weakref' attribute here}}
+#endif
+#ifdef MACOS
+void pr47663_d() __attribute__((availability(macos, introduced=10.4))); // expected-warning {{declared weak after its first use}} expected-note {{'availability' attribute here}}
+#endif
+#pragma weak pr47663_e // expected-note {{pragma 'weak' here}}
+
+// FIXME: This should warn; see PR47796. But it actually creates a bogus
+// overload set. When this is fixed, ensure we produce the 'declared weak after
+// its first use' warning.
+#pragma weak pr47663_f = some_function // expected-note {{possible target}}
+void q() { pr47663_f; } // expected-error {{overloaded}}
+
+#pragma clang attribute push (__attribute__((weak)), apply_to = function) // expected-note {{'weak' attribute here}}
+void pr47663_g(); // expected-warning {{declared weak after its first use}}
+#pragma clang attribute pop
+int pr47663_h __attribute__((weak)); // expected-warning {{declared weak after its first use}} expected-note {{'weak' attribute here}}
+void pr47663_z() __attribute__((weak_import));
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -8151,6 +8151,9 @@
   W.setUsed(true);
   if (W.getAlias()) { // clone decl, impersonate __attribute(weak,alias(...))
 IdentifierInfo *NDId = ND->getIdentifier();
+// FIXME (PR47796): Check for a previous declaration with the target name
+// here, and build a redeclaration of it. Check whether the previous
+/

Re: [clang] 9dcd96f - Canonicalize declaration pointers when forming APValues.

2020-10-11 Thread Richard Smith via cfe-commits
Please can you try building with https://reviews.llvm.org/D89212 applied
first, and see if it produces any warnings? If so, you're probably hitting
PR47663, and should fix that by moving the 'weak' attribute earlier.

On Sun, 11 Oct 2020 at 11:18, Richard Smith  wrote:

> On Fri, 9 Oct 2020 at 19:12, Arthur Eubanks  wrote:
>
>> I think this is the cause of https://crbug.com/1134762. Can we
>> speculatively revert while coming up with a repro? Or would you like a
>> repro first?
>>
>
> If you're blocked on this, sure, please go ahead and revert until you have
> a repro. But the revert will block ongoing development work, so a
> reproducer would definitely be appreciated! Per PR47663, there are some
> pretty fundamental problems with adding the 'weak' attribute "too late", so
> if that's what's going on, the best approach might be to move the 'weak'
> attribute to an earlier declaration.
>
> On Sun, Sep 27, 2020 at 7:06 PM Richard Smith via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>>
>>> Author: Richard Smith
>>> Date: 2020-09-27T19:05:26-07:00
>>> New Revision: 9dcd96f728863d40d6f5922ed52732fdd728fb5f
>>>
>>> URL:
>>> https://github.com/llvm/llvm-project/commit/9dcd96f728863d40d6f5922ed52732fdd728fb5f
>>> DIFF:
>>> https://github.com/llvm/llvm-project/commit/9dcd96f728863d40d6f5922ed52732fdd728fb5f.diff
>>>
>>> LOG: Canonicalize declaration pointers when forming APValues.
>>>
>>> References to different declarations of the same entity aren't different
>>> values, so shouldn't have different representations.
>>>
>>> Recommit of e6393ee813178e9d3306b8e3c6949a4f32f8a2cb with fixed handling
>>> for weak declarations. We now look for attributes on the most recent
>>> declaration when determining whether a declaration is weak. (Second
>>> recommit with further fixes for mishandling of weak declarations. Our
>>> behavior here is fundamentally unsound -- see PR47663 -- but this
>>> approach attempts to not make things worse.)
>>>
>>> Added:
>>>
>>>
>>> Modified:
>>> clang/include/clang/AST/APValue.h
>>> clang/lib/AST/APValue.cpp
>>> clang/lib/AST/Decl.cpp
>>> clang/lib/AST/DeclBase.cpp
>>> clang/lib/AST/ExprConstant.cpp
>>> clang/lib/CodeGen/CGExprConstant.cpp
>>> clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p9.cpp
>>> clang/test/CodeGenCXX/weak-external.cpp
>>> clang/test/OpenMP/ordered_messages.cpp
>>>
>>> Removed:
>>>
>>>
>>>
>>>
>>> 
>>> diff  --git a/clang/include/clang/AST/APValue.h
>>> b/clang/include/clang/AST/APValue.h
>>> index 5103cfa8604e..6307f8a92e5a 100644
>>> --- a/clang/include/clang/AST/APValue.h
>>> +++ b/clang/include/clang/AST/APValue.h
>>> @@ -174,6 +174,7 @@ class APValue {
>>>return !(LHS == RHS);
>>>  }
>>>  friend llvm::hash_code hash_value(const LValueBase &Base);
>>> +friend struct llvm::DenseMapInfo;
>>>
>>>private:
>>>  PtrTy Ptr;
>>> @@ -201,8 +202,7 @@ class APValue {
>>>
>>>public:
>>>  LValuePathEntry() : Value() {}
>>> -LValuePathEntry(BaseOrMemberType BaseOrMember)
>>> -:
>>> Value{reinterpret_cast(BaseOrMember.getOpaqueValue())} {}
>>> +LValuePathEntry(BaseOrMemberType BaseOrMember);
>>>  static LValuePathEntry ArrayIndex(uint64_t Index) {
>>>LValuePathEntry Result;
>>>Result.Value = Index;
>>>
>>> diff  --git a/clang/lib/AST/APValue.cpp b/clang/lib/AST/APValue.cpp
>>> index 08ae0ff3c67d..32d3ff7ce1d0 100644
>>> --- a/clang/lib/AST/APValue.cpp
>>> +++ b/clang/lib/AST/APValue.cpp
>>> @@ -38,7 +38,7 @@ static_assert(
>>>  "Type is insufficiently aligned");
>>>
>>>  APValue::LValueBase::LValueBase(const ValueDecl *P, unsigned I,
>>> unsigned V)
>>> -: Ptr(P), Local{I, V} {}
>>> +: Ptr(P ? cast(P->getCanonicalDecl()) : nullptr),
>>> Local{I, V} {}
>>>  APValue::LValueBase::LValueBase(const Expr *P, unsigned I, unsigned V)
>>>  : Ptr(P), Local{I, V} {}
>>>
>>> @@ -82,13 +82,19 @@ bool operator==(const APValue::LValueBase &LHS,
>>>  const APValue::LValueBase &RHS) {
>>>if (LHS.Ptr != RHS.Ptr)
>>>  return false;
>>> -  if (LHS.is())
>>> +  if (LHS.is() || LHS.is())
>>>  return true;
>>>return LHS.Local.CallIndex == RHS.Local.CallIndex &&
>>>   LHS.Local.Version == RHS.Local.Version;
>>>  }
>>>  }
>>>
>>> +APValue::LValuePathEntry::LValuePathEntry(BaseOrMemberType
>>> BaseOrMember) {
>>> +  if (const Decl *D = BaseOrMember.getPointer())
>>> +BaseOrMember.setPointer(D->getCanonicalDecl());
>>> +  Value = reinterpret_cast(BaseOrMember.getOpaqueValue());
>>> +}
>>> +
>>>  namespace {
>>>struct LVBase {
>>>  APValue::LValueBase Base;
>>> @@ -113,14 +119,16 @@ APValue::LValueBase::operator bool () const {
>>>
>>>  clang::APValue::LValueBase
>>>  llvm::DenseMapInfo::getEmptyKey() {
>>> -  return clang::APValue::LValueBase(
>>> -  DenseMapInfo::getEmptyKey());
>>> +  clang::APValue::LValueBase B;
>>> +  B.Ptr = DenseMapInf

[clang] 849c605 - PR47792: Include the type of a pointer or reference non-type template

2020-10-11 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2020-10-11T15:59:49-07:00
New Revision: 849c60541b630ddf8cabf9179fa771b3f4207ec8

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

LOG: PR47792: Include the type of a pointer or reference non-type template
parameter in its notion of template argument identity.

We already did this for all the other kinds of non-type template
argument. We're still missing the type from the mangling, so we continue
to be able to see collisions at link time; that's an open ABI issue.

Added: 


Modified: 
clang/lib/AST/ASTContext.cpp
clang/lib/AST/TemplateBase.cpp
clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index a82d95461bb9..7c96038629fb 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -5890,7 +5890,7 @@ ASTContext::getCanonicalTemplateArgument(const 
TemplateArgument &Arg) const {
 
 case TemplateArgument::Declaration: {
   auto *D = cast(Arg.getAsDecl()->getCanonicalDecl());
-  return TemplateArgument(D, Arg.getParamTypeForDecl());
+  return TemplateArgument(D, getCanonicalType(Arg.getParamTypeForDecl()));
 }
 
 case TemplateArgument::NullPtr:

diff  --git a/clang/lib/AST/TemplateBase.cpp b/clang/lib/AST/TemplateBase.cpp
index a9113720fd45..e4303fdb7731 100644
--- a/clang/lib/AST/TemplateBase.cpp
+++ b/clang/lib/AST/TemplateBase.cpp
@@ -244,7 +244,8 @@ void TemplateArgument::Profile(llvm::FoldingSetNodeID &ID,
 break;
 
   case Declaration:
-ID.AddPointer(getAsDecl()? getAsDecl()->getCanonicalDecl() : nullptr);
+ID.AddPointer(getAsDecl() ? getAsDecl()->getCanonicalDecl() : nullptr);
+getParamTypeForDecl().Profile(ID);
 break;
 
   case Template:
@@ -294,7 +295,8 @@ bool TemplateArgument::structurallyEquals(const 
TemplateArgument &Other) const {
 return TypeOrValue.V == Other.TypeOrValue.V;
 
   case Declaration:
-return getAsDecl() == Other.getAsDecl();
+return getAsDecl() == Other.getAsDecl() &&
+   getParamTypeForDecl() == Other.getParamTypeForDecl();
 
   case Integral:
 return getIntegralType() == Other.getIntegralType() &&

diff  --git a/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp 
b/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
index 7538de330902..6949a2eaad48 100644
--- a/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
+++ b/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
@@ -459,3 +459,23 @@ namespace PR46637 {
   X y;
   int n = y.call(); // expected-error {{cannot initialize a variable of type 
'int' with an rvalue of type 'void *'}}
 }
+
+namespace PR47792 {
+  using I = int;
+
+  template int a;
+  const int n = 0;
+  const I n2 = 0;
+  static_assert(&a == &a<0>, "both should have type 'int'");
+  static_assert(&a == &a<0>, "both should have type 'int'");
+
+  // FIXME: We will need to mangle these cases 
diff erently too!
+  int m;
+  const int &r1 = m;
+  int &r2 = m;
+  static_assert(&a != &a, "should have 
diff erent types");
+
+  const I &r3 = m;
+  static_assert(&a == &a, "should have 
diff erent types");
+  static_assert(&a != &a, "should have 
diff erent types");
+}



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


[PATCH] D88712: [CGBuiltin] Respect asm labels and redefine_extname for builtins with specialized emitting

2020-10-11 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

What are the expected semantics in this case? Is this:

- the function is still the builtin, but if it ends up being a libcall, call a 
function with a different asm name, or
- the function is not considered to be the builtin any more, or
- something else?

I think this patch is approximately the first thing, but it's also cutting off 
emission for cases where we wouldn't emit a libcall. Should we make that 
distinction?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88712

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


Re: [clang] 849c605 - PR47792: Include the type of a pointer or reference non-type template

2020-10-11 Thread Hubert Tong via cfe-commits
The bots don't seem happy building with a Clang that incorporates this
change:
```
/b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/clang/lib/ASTMatchers/ASTMatchersInternal.cpp:943:5:
error: redefinition of 'hasAnyName' with a different type: 'const
VariadicFunction<...>' vs 'const VariadicFunction<...>'
hasAnyName = {};
^
/b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/clang/include/clang/ASTMatchers/ASTMatchers.h:2771:5:
note: previous declaration is here
hasAnyName;
^
```
(from
http://lab.llvm.org:8011/#/builders/99/builds/49/steps/2/logs/build_clang_asan
)

On Sun, Oct 11, 2020 at 7:00 PM Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

>
> Author: Richard Smith
> Date: 2020-10-11T15:59:49-07:00
> New Revision: 849c60541b630ddf8cabf9179fa771b3f4207ec8
>
> URL:
> https://github.com/llvm/llvm-project/commit/849c60541b630ddf8cabf9179fa771b3f4207ec8
> DIFF:
> https://github.com/llvm/llvm-project/commit/849c60541b630ddf8cabf9179fa771b3f4207ec8.diff
>
> LOG: PR47792: Include the type of a pointer or reference non-type template
> parameter in its notion of template argument identity.
>
> We already did this for all the other kinds of non-type template
> argument. We're still missing the type from the mangling, so we continue
> to be able to see collisions at link time; that's an open ABI issue.
>
> Added:
>
>
> Modified:
> clang/lib/AST/ASTContext.cpp
> clang/lib/AST/TemplateBase.cpp
> clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
>
> Removed:
>
>
>
>
> 
> diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
> index a82d95461bb9..7c96038629fb 100644
> --- a/clang/lib/AST/ASTContext.cpp
> +++ b/clang/lib/AST/ASTContext.cpp
> @@ -5890,7 +5890,7 @@ ASTContext::getCanonicalTemplateArgument(const
> TemplateArgument &Arg) const {
>
>  case TemplateArgument::Declaration: {
>auto *D = cast(Arg.getAsDecl()->getCanonicalDecl());
> -  return TemplateArgument(D, Arg.getParamTypeForDecl());
> +  return TemplateArgument(D,
> getCanonicalType(Arg.getParamTypeForDecl()));
>  }
>
>  case TemplateArgument::NullPtr:
>
> diff  --git a/clang/lib/AST/TemplateBase.cpp
> b/clang/lib/AST/TemplateBase.cpp
> index a9113720fd45..e4303fdb7731 100644
> --- a/clang/lib/AST/TemplateBase.cpp
> +++ b/clang/lib/AST/TemplateBase.cpp
> @@ -244,7 +244,8 @@ void TemplateArgument::Profile(llvm::FoldingSetNodeID
> &ID,
>  break;
>
>case Declaration:
> -ID.AddPointer(getAsDecl()? getAsDecl()->getCanonicalDecl() : nullptr);
> +ID.AddPointer(getAsDecl() ? getAsDecl()->getCanonicalDecl() :
> nullptr);
> +getParamTypeForDecl().Profile(ID);
>  break;
>
>case Template:
> @@ -294,7 +295,8 @@ bool TemplateArgument::structurallyEquals(const
> TemplateArgument &Other) const {
>  return TypeOrValue.V == Other.TypeOrValue.V;
>
>case Declaration:
> -return getAsDecl() == Other.getAsDecl();
> +return getAsDecl() == Other.getAsDecl() &&
> +   getParamTypeForDecl() == Other.getParamTypeForDecl();
>
>case Integral:
>  return getIntegralType() == Other.getIntegralType() &&
>
> diff  --git a/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
> b/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
> index 7538de330902..6949a2eaad48 100644
> --- a/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
> +++ b/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
> @@ -459,3 +459,23 @@ namespace PR46637 {
>X y;
>int n = y.call(); // expected-error {{cannot initialize a variable of
> type 'int' with an rvalue of type 'void *'}}
>  }
> +
> +namespace PR47792 {
> +  using I = int;
> +
> +  template int a;
> +  const int n = 0;
> +  const I n2 = 0;
> +  static_assert(&a == &a<0>, "both should have type 'int'");
> +  static_assert(&a == &a<0>, "both should have type 'int'");
> +
> +  // FIXME: We will need to mangle these cases
> diff erently too!
> +  int m;
> +  const int &r1 = m;
> +  int &r2 = m;
> +  static_assert(&a != &a, "should have
> diff erent types");
> +
> +  const I &r3 = m;
> +  static_assert(&a == &a, "should have
> diff erent types");
>
I think the text of the static_assert string here is a copy-paste error.


> +  static_assert(&a != &a, "should have
> diff erent types");
> +}
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89066: [Coroutine][Sema] Only tighten the suspend call temp lifetime for final awaiter

2020-10-11 Thread JunMa via Phabricator via cfe-commits
junparser added a comment.

why we should not do this with normal await call?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89066

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


[clang] ba2dff0 - Revert "PR47792: Include the type of a pointer or reference non-type template"

2020-10-11 Thread Jonas Devlieghere via cfe-commits

Author: Jonas Devlieghere
Date: 2020-10-11T20:16:46-07:00
New Revision: ba2dff0159fcd1d2349bc610331914618ca9bc30

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

LOG: Revert "PR47792: Include the type of a pointer or reference non-type 
template"

This reverts commit 849c60541b630ddf8cabf9179fa771b3f4207ec8 because it
results in a stage 2 build failure:

llvm-project/clang/include/clang/AST/ExternalASTSource.h:409:20: error:
definition with same mangled name
'_ZN5clang25LazyGenerationalUpdatePtrIPKNS_4DeclEPS1_XadL_ZNS_17ExternalASTSource19CompleteRedeclChainES3_EEE9makeValueERKNS_10ASTContextES4_'
as another definition

  static ValueType makeValue(const ASTContext &Ctx, T Value);

Added: 


Modified: 
clang/lib/AST/ASTContext.cpp
clang/lib/AST/TemplateBase.cpp
clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 7c96038629fb..a82d95461bb9 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -5890,7 +5890,7 @@ ASTContext::getCanonicalTemplateArgument(const 
TemplateArgument &Arg) const {
 
 case TemplateArgument::Declaration: {
   auto *D = cast(Arg.getAsDecl()->getCanonicalDecl());
-  return TemplateArgument(D, getCanonicalType(Arg.getParamTypeForDecl()));
+  return TemplateArgument(D, Arg.getParamTypeForDecl());
 }
 
 case TemplateArgument::NullPtr:

diff  --git a/clang/lib/AST/TemplateBase.cpp b/clang/lib/AST/TemplateBase.cpp
index e4303fdb7731..a9113720fd45 100644
--- a/clang/lib/AST/TemplateBase.cpp
+++ b/clang/lib/AST/TemplateBase.cpp
@@ -244,8 +244,7 @@ void TemplateArgument::Profile(llvm::FoldingSetNodeID &ID,
 break;
 
   case Declaration:
-ID.AddPointer(getAsDecl() ? getAsDecl()->getCanonicalDecl() : nullptr);
-getParamTypeForDecl().Profile(ID);
+ID.AddPointer(getAsDecl()? getAsDecl()->getCanonicalDecl() : nullptr);
 break;
 
   case Template:
@@ -295,8 +294,7 @@ bool TemplateArgument::structurallyEquals(const 
TemplateArgument &Other) const {
 return TypeOrValue.V == Other.TypeOrValue.V;
 
   case Declaration:
-return getAsDecl() == Other.getAsDecl() &&
-   getParamTypeForDecl() == Other.getParamTypeForDecl();
+return getAsDecl() == Other.getAsDecl();
 
   case Integral:
 return getIntegralType() == Other.getIntegralType() &&

diff  --git a/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp 
b/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
index 6949a2eaad48..7538de330902 100644
--- a/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
+++ b/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
@@ -459,23 +459,3 @@ namespace PR46637 {
   X y;
   int n = y.call(); // expected-error {{cannot initialize a variable of type 
'int' with an rvalue of type 'void *'}}
 }
-
-namespace PR47792 {
-  using I = int;
-
-  template int a;
-  const int n = 0;
-  const I n2 = 0;
-  static_assert(&a == &a<0>, "both should have type 'int'");
-  static_assert(&a == &a<0>, "both should have type 'int'");
-
-  // FIXME: We will need to mangle these cases 
diff erently too!
-  int m;
-  const int &r1 = m;
-  int &r2 = m;
-  static_assert(&a != &a, "should have 
diff erent types");
-
-  const I &r3 = m;
-  static_assert(&a == &a, "should have 
diff erent types");
-  static_assert(&a != &a, "should have 
diff erent types");
-}



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


Re: [clang] 849c605 - PR47792: Include the type of a pointer or reference non-type template

2020-10-11 Thread Jonas Devlieghere via cfe-commits
I've reverted this in ba2dff0159fcd1d2349bc610331914618ca9bc30 because it
also caused a build failure when building a stage 2 clang:

http://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/24177/console

FAILED: tools/clang/lib/AST/CMakeFiles/obj.clangAST.dir/ASTContext.cpp.o
/Users/buildslave/jenkins/workspace/lldb-cmake@2/host-compiler/bin/clang++
-DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools/clang/lib/AST
-I/Users/buildslave/jenkins/workspace/lldb-cmake@2/llvm-project/clang/lib/AST
-I/Users/buildslave/jenkins/workspace/lldb-cmake@2/llvm-project/clang/include
-Itools/clang/include -Iinclude
-I/Users/buildslave/jenkins/workspace/lldb-cmake@2/llvm-project/llvm/include
-Wdocumentation -fPIC -fvisibility-inlines-hidden -Werror=date-time
-Werror=unguarded-availability-new -fmodules
-fmodules-cache-path=/Users/buildslave/jenkins/workspace/lldb-cmake@2/lldb-build/module.cache
-fcxx-modules -Xclang -fmodules-local-submodule-visibility -Wall -Wextra
-Wno-unused-parameter -Wwrite-strings -Wcast-qual
-Wmissing-field-initializers -pedantic -Wno-long-long
-Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type
-Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override
-Wstring-conversion -fdiagnostics-color -fno-common -Woverloaded-virtual
-Wno-nested-anon-types -O3 -isysroot
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk
-fno-exceptions -fno-rtti -UNDEBUG -std=c++14 -MD -MT
tools/clang/lib/AST/CMakeFiles/obj.clangAST.dir/ASTContext.cpp.o -MF
tools/clang/lib/AST/CMakeFiles/obj.clangAST.dir/ASTContext.cpp.o.d -o
tools/clang/lib/AST/CMakeFiles/obj.clangAST.dir/ASTContext.cpp.o -c
'/Users/buildslave/jenkins/workspace/lldb-cmake@2/llvm-project/clang/lib/AST/ASTContext.cpp'
In module 'Clang_AST' imported from
/Users/buildslave/jenkins/workspace/lldb-cmake@2/llvm-project/clang/lib/AST/ASTContext.cpp:13:
/Users/buildslave/jenkins/workspace/lldb-cmake@2/llvm-project/clang/include/clang/AST/ExternalASTSource.h:409:20:
error: definition with same mangled name
'_ZN5clang25LazyGenerationalUpdatePtrIPKNS_4DeclEPS1_XadL_ZNS_17ExternalASTSource19CompleteRedeclChainES3_EEE9makeValueERKNS_10ASTContextES4_'
as another definition static ValueType makeValue(const ASTContext &Ctx, T
Value);



On Sun, Oct 11, 2020 at 6:27 PM Hubert Tong via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> The bots don't seem happy building with a Clang that incorporates this
> change:
> ```
> /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/clang/lib/ASTMatchers/ASTMatchersInternal.cpp:943:5:
> error: redefinition of 'hasAnyName' with a different type: 'const
> VariadicFunction<...>' vs 'const VariadicFunction<...>'
> hasAnyName = {};
> ^
> /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/clang/include/clang/ASTMatchers/ASTMatchers.h:2771:5:
> note: previous declaration is here
> hasAnyName;
> ^
> ```
> (from
> http://lab.llvm.org:8011/#/builders/99/builds/49/steps/2/logs/build_clang_asan
> )
>
> On Sun, Oct 11, 2020 at 7:00 PM Richard Smith via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>>
>> Author: Richard Smith
>> Date: 2020-10-11T15:59:49-07:00
>> New Revision: 849c60541b630ddf8cabf9179fa771b3f4207ec8
>>
>> URL:
>> https://github.com/llvm/llvm-project/commit/849c60541b630ddf8cabf9179fa771b3f4207ec8
>> DIFF:
>> https://github.com/llvm/llvm-project/commit/849c60541b630ddf8cabf9179fa771b3f4207ec8.diff
>>
>> LOG: PR47792: Include the type of a pointer or reference non-type template
>> parameter in its notion of template argument identity.
>>
>> We already did this for all the other kinds of non-type template
>> argument. We're still missing the type from the mangling, so we continue
>> to be able to see collisions at link time; that's an open ABI issue.
>>
>> Added:
>>
>>
>> Modified:
>> clang/lib/AST/ASTContext.cpp
>> clang/lib/AST/TemplateBase.cpp
>> clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
>>
>> Removed:
>>
>>
>>
>>
>> 
>> diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
>> index a82d95461bb9..7c96038629fb 100644
>> --- a/clang/lib/AST/ASTContext.cpp
>> +++ b/clang/lib/AST/ASTContext.cpp
>> @@ -5890,7 +5890,7 @@ ASTContext::getCanonicalTemplateArgument(const
>> TemplateArgument &Arg) const {
>>
>>  case TemplateArgument::Declaration: {
>>auto *D = cast(Arg.getAsDecl()->getCanonicalDecl());
>> -  return TemplateArgument(D, Arg.getParamTypeForDecl());
>> +  return TemplateArgument(D,
>> getCanonicalType(Arg.getParamTypeForDecl()));
>>  }
>>
>>  case TemplateArgument::NullPtr:
>>
>> diff  --git a/clang/lib/AST/TemplateBase.cpp
>> b/clang/lib/AST/TemplateBase.cpp
>> index a9113720fd45..e4303fdb7731 100644
>> --- a/clang/lib/AST/TemplateBase.cpp
>> +++ b/clang/lib/AST/TemplateBase.cpp
>> @@ -244,7 +244,8 @@ void Template

[PATCH] D76620: [SYCL] Implement __builtin_unique_stable_name.

2020-10-11 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.
Herald added a subscriber: yaxunl.

Richard and I just found out about this commit, and we've decided to revert it. 
 I apologize for the very late reversion, but the reality of Clang development 
is that it's very difficult for the code owners to watch literally every 
commit, and we rely on the community to follow policies and bring things to our 
attention when there's a question about the right thing to do.  This is a new 
feature that was submitted without properly following any of the guidelines for 
new features: it was neither approved by a relevant standards body, added for 
compatibility with an existing frontend, or taken through the RFC process.  If 
you had brought it to our attention as an RFC, we would've expressed serious 
concerns about the design.

Please start an RFC thread and CC Richard and me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76620

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


[PATCH] D89212: PR47663: Warn if an entity becomes weak after its first use.

2020-10-11 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

This seems like a good idea in the abstract; we'll need to figure out what the 
practical consequences are.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89212

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


[PATCH] D88979: [InstCombine] combineLoadToOperationType(): don't fold int<->ptr cast into load

2020-10-11 Thread Juneyoung Lee via Phabricator via cfe-commits
aqjune added a comment.

+1 for this patch!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88979

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


[clang] cec49a5 - Revert "[SYCL] Implement __builtin_unique_stable_name."

2020-10-11 Thread John McCall via cfe-commits

Author: John McCall
Date: 2020-10-12T01:10:09-04:00
New Revision: cec49a583693752b3984e49f9c193de07c2a7698

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

LOG: Revert "[SYCL] Implement __builtin_unique_stable_name."

This reverts commit b5a034e771d0e4d7d8e71fc545b230d98e5a1f42.

This feature was added without following the proper process.

Added: 


Modified: 
clang/docs/LanguageExtensions.rst
clang/include/clang/AST/Expr.h
clang/include/clang/AST/Mangle.h
clang/include/clang/Basic/TokenKinds.def
clang/include/clang/Parse/Parser.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/Expr.cpp
clang/lib/AST/ItaniumMangle.cpp
clang/lib/Parse/ParseExpr.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/test/Analysis/eval-predefined-exprs.cpp

Removed: 
clang/test/CodeGenSYCL/unique-stable-name.cpp
clang/test/ParserSYCL/unique-stable-name.cpp



diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 256f7e12364f..a90485d9f799 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -2218,30 +2218,6 @@ argument.
   int *pb =__builtin_preserve_access_index(&v->c[3].b);
   __builtin_preserve_access_index(v->j);
 
-``__builtin_unique_stable_name``
-
-
-``__builtin_unique_stable_name()`` is a builtin that takes a type or 
expression and
-produces a string literal containing a unique name for the type (or type of the
-expression) that is stable across split compilations.
-
-In cases where the split compilation needs to share a unique token for a type
-across the boundary (such as in an offloading situation), this name can be used
-for lookup purposes.
-
-This builtin is superior to RTTI for this purpose for two reasons.  First, this
-value is computed entirely at compile time, so it can be used in constant
-expressions. Second, this value encodes lambda functions based on line-number
-rather than the order in which it appears in a function. This is valuable
-because it is stable in cases where an unrelated lambda is introduced
-conditionally in the same function.
-
-The current implementation of this builtin uses a slightly modified Itanium
-Mangler to produce the unique name. The lambda ordinal is replaced with one or
-more line/column pairs in the format ``LINE->COL``, separated with a ``~``
-character. Typically, only one pair will be included, however in the case of
-macro expansions the entire macro expansion stack is expressed.
-
 Multiprecision Arithmetic Builtins
 --
 

diff  --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index c14143c3f336..4a8e4e483a86 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -1930,17 +1930,13 @@ class StringLiteral final
 /// [C99 6.4.2.2] - A predefined identifier such as __func__.
 class PredefinedExpr final
 : public Expr,
-  private llvm::TrailingObjects {
+  private llvm::TrailingObjects {
   friend class ASTStmtReader;
   friend TrailingObjects;
 
   // PredefinedExpr is optionally followed by a single trailing
   // "Stmt *" for the predefined identifier. It is present if and only if
   // hasFunctionName() is true and is always a "StringLiteral *".
-  // It can also be followed by a Expr* in the case of a
-  // __builtin_unique_stable_name with an expression, or TypeSourceInfo * if
-  // __builtin_unique_stable_name with a type.
 
 public:
   enum IdentKind {
@@ -1953,18 +1949,12 @@ class PredefinedExpr final
 PrettyFunction,
 /// The same as PrettyFunction, except that the
 /// 'virtual' keyword is omitted for virtual member functions.
-PrettyFunctionNoVirtual,
-UniqueStableNameType,
-UniqueStableNameExpr,
+PrettyFunctionNoVirtual
   };
 
 private:
   PredefinedExpr(SourceLocation L, QualType FNTy, IdentKind IK,
  StringLiteral *SL);
-  PredefinedExpr(SourceLocation L, QualType FNTy, IdentKind IK,
- TypeSourceInfo *Info);
-  PredefinedExpr(SourceLocation L, QualType FNTy, IdentKind IK,
- Expr *E);
 
   explicit PredefinedExpr(EmptyShell Empty, bool HasFunctionName);
 
@@ -1977,39 +1967,10 @@ class PredefinedExpr final
 *getTrailingObjects() = SL;
   }
 
-  void setTypeSourceInfo(TypeSourceInfo *Info) {
-assert(!hasFunctionName() && getIdentKind() == UniqueStableNameType &&
-   "TypeSourceInfo only valid for UniqueStableName of a Type");
-*getTrailingObjects() = Info;
-  }
-
-  void setExpr(Expr *E) {
-assert(!hasFunctionName() && getIdentKind() == UniqueStableNameExpr &&
-   "TypeSourceInfo only valid for UniqueStableName of n Expression.");
-*getTrailingObjects

[PATCH] D89066: [Coroutine][Sema] Only tighten the suspend call temp lifetime for final awaiter

2020-10-11 Thread Xun Li via Phabricator via cfe-commits
lxfind added a comment.

In D89066#2324115 , @junparser wrote:

> why we should not do this with normal await call?

To be honest, I don't know yet. My understanding of how expression cleanup and 
temp lifetime management is insufficient at the moment.
But first of all, without adding any cleanup expression here, I saw ASAN 
failures due to heap-use-after-free, because sometimes the frame have already 
been destroyed after the await_suspend call, and yet we are still writing into 
the frame due to unnecessarily cross-suspend lifetime. However, if I apply the 
cleanup to all await_suepend calls, it also causes ASAN failures as it's 
cleaning up data that's still alive.
So this patch is more of a temporary walkaround to stop bleeding without 
causing any trouble.
I plan to get back to this latter after I am done with the spilling/alloca 
issues.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89066

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


Re: [clang] 849c605 - PR47792: Include the type of a pointer or reference non-type template

2020-10-11 Thread Richard Smith via cfe-commits
On Sun, 11 Oct 2020 at 20:19, Jonas Devlieghere 
wrote:

> I've reverted this in ba2dff0159fcd1d2349bc610331914618ca9bc30 because it
> also caused a build failure when building a stage 2 clang:
>

Thanks!


> http://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/24177/console
>
> FAILED: tools/clang/lib/AST/CMakeFiles/obj.clangAST.dir/ASTContext.cpp.o
> /Users/buildslave/jenkins/workspace/lldb-cmake@2/host-compiler/bin/clang++
> -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS
> -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools/clang/lib/AST
> -I/Users/buildslave/jenkins/workspace/lldb-cmake@2/llvm-project/clang/lib/AST
> -I/Users/buildslave/jenkins/workspace/lldb-cmake@2/llvm-project/clang/include
> -Itools/clang/include -Iinclude
> -I/Users/buildslave/jenkins/workspace/lldb-cmake@2/llvm-project/llvm/include
> -Wdocumentation -fPIC -fvisibility-inlines-hidden -Werror=date-time
> -Werror=unguarded-availability-new -fmodules
> -fmodules-cache-path=/Users/buildslave/jenkins/workspace/lldb-cmake@2/lldb-build/module.cache
> -fcxx-modules -Xclang -fmodules-local-submodule-visibility -Wall -Wextra
> -Wno-unused-parameter -Wwrite-strings -Wcast-qual
> -Wmissing-field-initializers -pedantic -Wno-long-long
> -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type
> -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override
> -Wstring-conversion -fdiagnostics-color -fno-common -Woverloaded-virtual
> -Wno-nested-anon-types -O3 -isysroot
> /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk
> -fno-exceptions -fno-rtti -UNDEBUG -std=c++14 -MD -MT
> tools/clang/lib/AST/CMakeFiles/obj.clangAST.dir/ASTContext.cpp.o -MF
> tools/clang/lib/AST/CMakeFiles/obj.clangAST.dir/ASTContext.cpp.o.d -o
> tools/clang/lib/AST/CMakeFiles/obj.clangAST.dir/ASTContext.cpp.o -c
> '/Users/buildslave/jenkins/workspace/lldb-cmake@2/llvm-project/clang/lib/AST/ASTContext.cpp'
> In module 'Clang_AST' imported from
> /Users/buildslave/jenkins/workspace/lldb-cmake@2/llvm-project/clang/lib/AST/ASTContext.cpp:13:
> /Users/buildslave/jenkins/workspace/lldb-cmake@2/llvm-project/clang/include/clang/AST/ExternalASTSource.h:409:20:
> error: definition with same mangled name
> '_ZN5clang25LazyGenerationalUpdatePtrIPKNS_4DeclEPS1_XadL_ZNS_17ExternalASTSource19CompleteRedeclChainES3_EEE9makeValueERKNS_10ASTContextES4_'
> as another definition static ValueType makeValue(const ASTContext &Ctx, T
> Value);
>
>
>
> On Sun, Oct 11, 2020 at 6:27 PM Hubert Tong via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> The bots don't seem happy building with a Clang that incorporates this
>> change:
>> ```
>> /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/clang/lib/ASTMatchers/ASTMatchersInternal.cpp:943:5:
>> error: redefinition of 'hasAnyName' with a different type: 'const
>> VariadicFunction<...>' vs 'const VariadicFunction<...>'
>> hasAnyName = {};
>> ^
>> /b/sanitizer-x86_64-linux-bootstrap/build/llvm-project/clang/include/clang/ASTMatchers/ASTMatchers.h:2771:5:
>> note: previous declaration is here
>> hasAnyName;
>> ^
>> ```
>> (from
>> http://lab.llvm.org:8011/#/builders/99/builds/49/steps/2/logs/build_clang_asan
>> )
>>
>> On Sun, Oct 11, 2020 at 7:00 PM Richard Smith via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>>
>>> Author: Richard Smith
>>> Date: 2020-10-11T15:59:49-07:00
>>> New Revision: 849c60541b630ddf8cabf9179fa771b3f4207ec8
>>>
>>> URL:
>>> https://github.com/llvm/llvm-project/commit/849c60541b630ddf8cabf9179fa771b3f4207ec8
>>> DIFF:
>>> https://github.com/llvm/llvm-project/commit/849c60541b630ddf8cabf9179fa771b3f4207ec8.diff
>>>
>>> LOG: PR47792: Include the type of a pointer or reference non-type
>>> template
>>> parameter in its notion of template argument identity.
>>>
>>> We already did this for all the other kinds of non-type template
>>> argument. We're still missing the type from the mangling, so we continue
>>> to be able to see collisions at link time; that's an open ABI issue.
>>>
>>> Added:
>>>
>>>
>>> Modified:
>>> clang/lib/AST/ASTContext.cpp
>>> clang/lib/AST/TemplateBase.cpp
>>> clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
>>>
>>> Removed:
>>>
>>>
>>>
>>>
>>> 
>>> diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
>>> index a82d95461bb9..7c96038629fb 100644
>>> --- a/clang/lib/AST/ASTContext.cpp
>>> +++ b/clang/lib/AST/ASTContext.cpp
>>> @@ -5890,7 +5890,7 @@ ASTContext::getCanonicalTemplateArgument(const
>>> TemplateArgument &Arg) const {
>>>
>>>  case TemplateArgument::Declaration: {
>>>auto *D = cast(Arg.getAsDecl()->getCanonicalDecl());
>>> -  return TemplateArgument(D, Arg.getParamTypeForDecl());
>>> +  return TemplateArgument(D,
>>> getCanonicalType(Arg.getParamTypeForDecl()));
>>>  }
>>>
>>>  case TemplateArgument::NullPtr:
>>>
>>> diff  --git a/clang/li

[PATCH] D89212: PR47663: Warn if an entity becomes weak after its first use.

2020-10-11 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In D89212#2324127 , @rjmccall wrote:

> This seems like a good idea in the abstract; we'll need to figure out what 
> the practical consequences are.

Looks like it triggers warnings in Abseil at least; there, the code looks like 
this:

  // spinlock.h
  void AbslInternalSpinLockDelay();
  inline void lock(...) {
AbslInternalSpinLockDelay();
  }



  // spinlock.cc
  __attribute__((weak)) void AbslInternalSpinLockDelay() { ... }

... and adding the `weak` attribute to the declaration would change the meaning 
of the program (we want an `external` reference, not an `extern_weak` 
reference).

Perhaps we should only warn if the function is not defined in the same 
translation unit? If it is defined, then I think its address can never be null, 
and CodeGen will emit it with the correct linkage. We still have the problem 
that `==` comparisons against pointers to the function can incorrectly evaluate 
to `false`, but I think that's really a problem with aliases rather than with 
weakness. (C++ requires that `void f(), g(); bool b = f == g;` initializes `b` 
to `false` even though the only correct answer is that we don't know; we refuse 
to evaluate the comparison if either `f` or `g` is weak, but I think that's 
only really addressing the problem that they could both be null, not that they 
could have the same non-null address, since the latter problem isn't specific 
to weak declarations. I think the constant evaluator is being 
overly-conservative, and could evaluate `f == g` to `false` if `f` and `g` are 
both weak but at least one of them is defined locally, under the 
language-guaranteed assumption that distinct functions have different 
addresses. And perhaps we should have a way of declaring a function as 
potentially aliasing another function without actually defining the function as 
an alias, as a way to turn off that assumption independent of weakness?)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89212

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


[PATCH] D87449: [clang-tidy] Add new check for SEI CERT rule SIG30-C

2020-10-11 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.



Comment at: clang-tools-extra/clang-tidy/cert/SignalHandlerCheck.cpp:117-118
+FunctionCallCollector Collector{[&CalledFunctions](const CallExpr *CE) {
+  if (isa(CE->getCalleeDecl()))
+CalledFunctions.push_back(CE);
+}};

aaron.ballman wrote:
> balazske wrote:
> > aaron.ballman wrote:
> > > balazske wrote:
> > > > aaron.ballman wrote:
> > > > > aaron.ballman wrote:
> > > > > > balazske wrote:
> > > > > > > aaron.ballman wrote:
> > > > > > > > For correctness, I think you need to handle more than just 
> > > > > > > > calls to function declarations -- for instance, this should be 
> > > > > > > > just as problematic:
> > > > > > > > ```
> > > > > > > > void some_signal_handler(int sig) {
> > > > > > > >   []{ puts("this should not be an escape hatch for the check); 
> > > > > > > > }();
> > > > > > > > }
> > > > > > > > ```
> > > > > > > > even though the call expression in the signal handler doesn't 
> > > > > > > > resolve back to a function declaration. (Similar for blocks 
> > > > > > > > instead of lambdas.) WDYT?
> > > > > > > I do not know how many other cases could be there. Probably this 
> > > > > > > can be left for future  improvement, the checker is mainly usable 
> > > > > > > for C code then. There is a `clang::CallGraph` functionality that 
> > > > > > > could be used instead of `FunctionCallCollector` but the 
> > > > > > > `CallExpr` for the calls is not provided by it so it does not 
> > > > > > > work for this case. Maybe there is other similar functionality 
> > > > > > > that is usable?
> > > > > > Given that we want it in the CERT module, we should try to ensure 
> > > > > > it follows the rule as closely as we can. I went and checked what 
> > > > > > the C++ rules say about this and... it was interesting to notice 
> > > > > > that SIG30-C is not one of the C rules included by reference in C++ 
> > > > > > (https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=88046336).
> > > > > > 
> > > > > > It's not clear to me that this rule was accidentally tagged as 
> > > > > > `not-for-cpp` or not, so I'd say it's fine to ignore lambdas for 
> > > > > > the moment but we may have some follow-up work if CERT changes the 
> > > > > > rule to be included in C++. My recommendation is: make the check a 
> > > > > > C-only check for now, document it as such, and I'll ping the folks 
> > > > > > at CERT to see if this rule was mistagged or not. WDYT?
> > > > > Ah, this rule really is a C-only rule, because 
> > > > > https://wiki.sei.cmu.edu/confluence/display/cplusplus/MSC54-CPP.+A+signal+handler+must+be+a+plain+old+function
> > > > >  is the C++ rule. So I think the SIG30-C checker should be run in 
> > > > > C-only mode and we can ignore the C++isms in it.
> > > > > 
> > > > > FWIW, we have an ongoing discussion about MSC54-CPP in 
> > > > > https://reviews.llvm.org/D33825.
> > > > Probably this checker can be merged with the other in D33825. According 
> > > > to cppreference 
> > > > (https://en.cppreference.com/w/cpp/utility/program/signal) the check 
> > > > for the called functions should be present for C++ too. And the other 
> > > > checker should do a similar lookup of called functions as this checker, 
> > > > including lambdas and C++ specific things.
> > > While you would think that, it's a bit more complicated unfortunately. 
> > > The C++ committee has been moving forward with this paper 
> > > http://wg21.link/p0270 so that C++ is no longer tied to the same 
> > > constraints as C. That may suggest that separate checks are appropriate, 
> > > or it may still mean we want to merge the checks into one.
> > I think it is more convenient to merge the two checkers. The visitation of 
> > called functions goes the same way, the support for C++ constructs should 
> > not cause problems if used with C code. The handling of a detected function 
> > can be different code for C and C++ mode but if there are similar parts 
> > code can be reused.
> > Otherwise code of this checker would be a better starting point for 
> > "SignalHandlerMustBePlainOldFunctionCheck" because it handles detection of 
> > the `signal` function already better specially for C++.
> Okay, I could see that. Would you like to collaborate with the author of 
> D33825 to see if you can produce a combined check? Or would you prefer to 
> wait for that review to land for C++ and then modify it for C? (Or some other 
> approach entirely?)
For me it looks better to pull in code from the other review. I found multiple 
issues with it but the detection code is usable here. It should be better 
however to first commit a simple version of the checker, for C functions only, 
and extend it in smaller patches.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87449

___
cfe-commits mailing list
cfe-commits@list