[PATCH] D116994: [RISCV] Add bfp and bfpw intrinsic in zbf extension

2022-01-11 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/include/clang/Basic/BuiltinsRISCV.def:36
 
+// zbf extension
+TARGET_BUILTIN(__builtin_riscv_bfp, "LiLiLi", "nc", "experimental-zbf")

Capital Z



Comment at: clang/include/clang/Basic/BuiltinsRISCV.def:37
+// zbf extension
+TARGET_BUILTIN(__builtin_riscv_bfp, "LiLiLi", "nc", "experimental-zbf")
+TARGET_BUILTIN(__builtin_riscv_bfpw, "WiWiWi", "nc", "experimental-zbf,64bit")

I think we should have `__builtin_riscv_bfp_32` and `__builtin_riscv_bfp_64`. 
It's more convenient and portable for software to be written in terms of number 
of bits being operated on rather than changing behavior based on xlen.



Comment at: llvm/include/llvm/IR/IntrinsicsRISCV.td:98
+  def int_riscv_bfp  : BitManipGPRGPRIntrinsics;
+  def int_riscv_bfpw : BitManipGPRGPRIntrinsics;
+

We only need one intrinsic. `BitManipGPRGPRIntrinsics` is type overloaded. We 
can check the type in isel patterns.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116994

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


[PATCH] D116316: [clang-format] Add an experimental option to remove optional control statement braces in LLVM C++ code

2022-01-11 Thread Owen Pan via Phabricator via cfe-commits
owenpan updated this revision to Diff 398860.
owenpan added a comment.
This revision is now accepted and ready to land.

- Removed unnecessary code and cleaned up.
- Tested on `clang` and `check-clang` again.


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

https://reviews.llvm.org/D116316

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/UnwrappedLineParser.h
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -18776,6 +18776,7 @@
   CHECK_PARSE_BOOL(ObjCSpaceBeforeProtocolList);
   CHECK_PARSE_BOOL(Cpp11BracedListStyle);
   CHECK_PARSE_BOOL(ReflowComments);
+  CHECK_PARSE_BOOL(RemoveBracesLLVM);
   CHECK_PARSE_BOOL(SortUsingDeclarations);
   CHECK_PARSE_BOOL(SpacesInParentheses);
   CHECK_PARSE_BOOL(SpacesInSquareBrackets);
@@ -23212,6 +23213,354 @@
Style);
 }
 
+TEST_F(FormatTest, RemoveBraces) {
+  FormatStyle Style = getLLVMStyle();
+  Style.RemoveBracesLLVM = true;
+
+  // The following eight test cases are fully-braced versions of the examples at
+  // "llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-
+  // statement-bodies-of-if-else-loop-statements".
+
+  // 1. Omit the braces, since the body is simple and clearly associated with
+  // the if.
+  verifyFormat("if (isa(D))\n"
+   "  handleFunctionDecl(D);\n"
+   "else if (isa(D))\n"
+   "  handleVarDecl(D);",
+   "if (isa(D)) {\n"
+   "  handleFunctionDecl(D);\n"
+   "} else if (isa(D)) {\n"
+   "  handleVarDecl(D);\n"
+   "}",
+   Style);
+
+  // 2. Here we document the condition itself and not the body.
+  verifyFormat("if (isa(D)) {\n"
+   "  // It is necessary that we explain the situation with this\n"
+   "  // surprisingly long comment, so it would be unclear\n"
+   "  // without the braces whether the following statement is in\n"
+   "  // the scope of the `if`.\n"
+   "  // Because the condition is documented, we can't really\n"
+   "  // hoist this comment that applies to the body above the\n"
+   "  // if.\n"
+   "  handleOtherDecl(D);\n"
+   "}",
+   Style);
+
+  // 3. Use braces on the outer `if` to avoid a potential dangling else
+  // situation.
+  verifyFormat("if (isa(D)) {\n"
+   "  for (auto *A : D.attrs())\n"
+   "if (shouldProcessAttr(A))\n"
+   "  handleAttr(A);\n"
+   "}",
+   "if (isa(D)) {\n"
+   "  for (auto *A : D.attrs()) {\n"
+   "if (shouldProcessAttr(A)) {\n"
+   "  handleAttr(A);\n"
+   "}\n"
+   "  }\n"
+   "}",
+   Style);
+
+  // 4. Use braces for the `if` block to keep it uniform with the else block.
+  verifyFormat("if (isa(D)) {\n"
+   "  handleFunctionDecl(D);\n"
+   "} else {\n"
+   "  // In this else case, it is necessary that we explain the\n"
+   "  // situation with this surprisingly long comment, so it\n"
+   "  // would be unclear without the braces whether the\n"
+   "  // following statement is in the scope of the `if`.\n"
+   "  handleOtherDecl(D);\n"
+   "}",
+   Style);
+
+  // 5. This should also omit braces.  The `for` loop contains only a single
+  // statement, so it shouldn't have braces.  The `if` also only contains a
+  // single simple statement (the for loop), so it also should omit braces.
+  verifyFormat("if (isa(D))\n"
+   "  for (auto *A : D.attrs())\n"
+   "handleAttr(A);",
+   "if (isa(D)) {\n"
+   "  for (auto *A : D.attrs()) {\n"
+   "handleAttr(A);\n"
+   "  }\n"
+   "}",
+   Style);
+
+  // 6. Use braces for the outer `if` since the nested `for` is braced.
+  verifyFormat("if (isa(D)) {\n"
+   "  for (auto *A : D.attrs()) {\n"
+   "// In this for loop body, it is necessary that we explain\n"
+   "// the situation with this surprisingly long comment,\n"
+   "// forcing braces on the `for` block.\n"
+   "handleAttr(A);\n"
+   "  }\n"
+   "}",
+   Style);
+
+  // 7. Use braces on the outer block because there are more than two levels of
+  // nesting.
+  verifyFormat("if (isa(D)) {\n"
+   "  for (auto *

[PATCH] D116920: [clang-format] clang-format eats space in front of attributes for operator delete

2022-01-11 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 398861.
MyDeveloperDay added a comment.

Line.MightBeFunctionDecl is not true in this case

Added new tests


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

https://reviews.llvm.org/D116920

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -9459,6 +9459,11 @@
"new 
(aa(aaa))\n"
"typename ();");
   verifyFormat("delete[] h->p;");
+
+  verifyFormat("void operator delete(void *foo) ATTRIB;");
+  verifyFormat("void operator new(void *foo) ATTRIB;");
+  verifyFormat("void operator delete[](void *foo) ATTRIB;");
+  verifyFormat("void operator delete(void* ptr ) noexcept;");
 }
 
 TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1892,6 +1892,14 @@
   return false;
 LeftOfParens = LeftOfParens->MatchingParen->Previous;
   }
+  
+  // The Condition directly below this one will see the operator arguments
+  // as a (void *foo) cast.
+  //   void operator delete(void *foo) ATTRIB;
+  if (LeftOfParens->Tok.getIdentifierInfo() &&
+  LeftOfParens->Previous &&
+  LeftOfParens->Previous->is(tok::kw_operator))
+return false;
 
   // If there is an identifier (or with a few exceptions a keyword) right
   // before the parentheses, this is unlikely to be a cast.


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -9459,6 +9459,11 @@
"new (aa(aaa))\n"
"typename ();");
   verifyFormat("delete[] h->p;");
+
+  verifyFormat("void operator delete(void *foo) ATTRIB;");
+  verifyFormat("void operator new(void *foo) ATTRIB;");
+  verifyFormat("void operator delete[](void *foo) ATTRIB;");
+  verifyFormat("void operator delete(void* ptr ) noexcept;");
 }
 
 TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1892,6 +1892,14 @@
   return false;
 LeftOfParens = LeftOfParens->MatchingParen->Previous;
   }
+  
+  // The Condition directly below this one will see the operator arguments
+  // as a (void *foo) cast.
+  //   void operator delete(void *foo) ATTRIB;
+  if (LeftOfParens->Tok.getIdentifierInfo() &&
+  LeftOfParens->Previous &&
+  LeftOfParens->Previous->is(tok::kw_operator))
+return false;
 
   // If there is an identifier (or with a few exceptions a keyword) right
   // before the parentheses, this is unlikely to be a cast.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116219: [CodeGen] Make element type in emitArrayDestroy() predictable

2022-01-11 Thread Nikita Popov 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 rG2d1b55ebea88: [CodeGen] Make element type in 
emitArrayDestroy() predictable (authored by nikic).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116219

Files:
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/test/CodeGenCXX/global-array-destruction.cpp


Index: clang/test/CodeGenCXX/global-array-destruction.cpp
===
--- clang/test/CodeGenCXX/global-array-destruction.cpp
+++ clang/test/CodeGenCXX/global-array-destruction.cpp
@@ -39,7 +39,7 @@
 T t[2][3] = { 1.0, 2, 3.0, 4, 5.0, 6, 7.0, 8, 9.0, 10, 11.0, 12 };
 
 // CHECK: call {{.*}} @__cxa_atexit
-// CHECK: getelementptr inbounds ([2 x [3 x {{.*}}]], [2 x [3 x {{.*}}]]* @t, 
i64 1, i64 0, i64 0)
+// CHECK: getelementptr inbounds ([2 x [3 x %struct.T]], [2 x [3 x 
%struct.T]]* bitcast ([2 x [3 x { double, i32 }]]* @t to [2 x [3 x 
%struct.T]]*), i64 1, i64 0, i64 0)
 // CHECK: call void @_ZN1TD1Ev
 // CHECK: icmp eq {{.*}} @t
 // CHECK: br i1 {{.*}}
@@ -47,7 +47,7 @@
 static T t2[2][3] = { 1.0, 2, 3.0, 4, 5.0, 6, 7.0, 8, 9.0, 10, 11.0, 12 };
 
 // CHECK: call {{.*}} @__cxa_atexit
-// CHECK: getelementptr inbounds ([2 x [3 x {{.*}}]], [2 x [3 x {{.*}}]]* 
@_ZL2t2, i64 1, i64 0, i64 0)
+// CHECK: getelementptr inbounds ([2 x [3 x %struct.T]], [2 x [3 x 
%struct.T]]* bitcast ([2 x [3 x { double, i32 }]]* @_ZL2t2 to [2 x [3 x 
%struct.T]]*), i64 1, i64 0, i64 0)
 // CHECK: call void @_ZN1TD1Ev
 // CHECK: icmp eq {{.*}} @_ZL2t2
 // CHECK: br i1 {{.*}}
@@ -56,7 +56,7 @@
 U &&u = U{ {{1.0, 2}, {3.0, 4}, {5.0, 6}}, {{7.0, 8}, {9.0, 10}, {11.0, 12}} };
 
 // CHECK: call {{.*}} @__cxa_atexit
-// CHECK: getelementptr inbounds ([2 x [3 x {{.*}}]], [2 x [3 x {{.*}}]]* 
@_ZGR1u_, i64 1, i64 0, i64 0)
+// CHECK: getelementptr inbounds ([2 x [3 x %struct.T]], [2 x [3 x 
%struct.T]]* @_ZGR1u_, i64 1, i64 0, i64 0)
 // CHECK: call void @_ZN1TD1Ev
 // CHECK: icmp eq {{.*}} @_ZGR1u_
 // CHECK: br i1 {{.*}}
Index: clang/lib/CodeGen/CGDeclCXX.cpp
===
--- clang/lib/CodeGen/CGDeclCXX.cpp
+++ clang/lib/CodeGen/CGDeclCXX.cpp
@@ -136,6 +136,7 @@
 }
   // Otherwise, the standard logic requires a helper function.
   } else {
+Addr = Addr.getElementBitCast(CGF.ConvertTypeForMem(Type));
 Func = CodeGenFunction(CGM)
.generateDestroyHelper(Addr, Type, CGF.getDestroyer(DtorKind),
   CGF.needsEHCleanup(DtorKind), &D);
Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -2252,16 +2252,17 @@
 
   // Shift the address back by one element.
   llvm::Value *negativeOne = llvm::ConstantInt::get(SizeTy, -1, true);
+  llvm::Type *llvmElementType = ConvertTypeForMem(elementType);
   llvm::Value *element = Builder.CreateInBoundsGEP(
-  elementPast->getType()->getPointerElementType(), elementPast, 
negativeOne,
-  "arraydestroy.element");
+  llvmElementType, elementPast, negativeOne, "arraydestroy.element");
 
   if (useEHCleanup)
 pushRegularPartialArrayCleanup(begin, element, elementType, elementAlign,
destroyer);
 
   // Perform the actual destruction there.
-  destroyer(*this, Address(element, elementAlign), elementType);
+  destroyer(*this, Address(element, llvmElementType, elementAlign),
+elementType);
 
   if (useEHCleanup)
 PopCleanupBlock();


Index: clang/test/CodeGenCXX/global-array-destruction.cpp
===
--- clang/test/CodeGenCXX/global-array-destruction.cpp
+++ clang/test/CodeGenCXX/global-array-destruction.cpp
@@ -39,7 +39,7 @@
 T t[2][3] = { 1.0, 2, 3.0, 4, 5.0, 6, 7.0, 8, 9.0, 10, 11.0, 12 };
 
 // CHECK: call {{.*}} @__cxa_atexit
-// CHECK: getelementptr inbounds ([2 x [3 x {{.*}}]], [2 x [3 x {{.*}}]]* @t, i64 1, i64 0, i64 0)
+// CHECK: getelementptr inbounds ([2 x [3 x %struct.T]], [2 x [3 x %struct.T]]* bitcast ([2 x [3 x { double, i32 }]]* @t to [2 x [3 x %struct.T]]*), i64 1, i64 0, i64 0)
 // CHECK: call void @_ZN1TD1Ev
 // CHECK: icmp eq {{.*}} @t
 // CHECK: br i1 {{.*}}
@@ -47,7 +47,7 @@
 static T t2[2][3] = { 1.0, 2, 3.0, 4, 5.0, 6, 7.0, 8, 9.0, 10, 11.0, 12 };
 
 // CHECK: call {{.*}} @__cxa_atexit
-// CHECK: getelementptr inbounds ([2 x [3 x {{.*}}]], [2 x [3 x {{.*}}]]* @_ZL2t2, i64 1, i64 0, i64 0)
+// CHECK: getelementptr inbounds ([2 x [3 x %struct.T]], [2 x [3 x %struct.T]]* bitcast ([2 x [3 x { double, i32 }]]* @_ZL2t2 to [2 x [3 x %struct.T]]*), i64 1, i64 0, i64 0)
 // CHECK: call void @_ZN1TD1Ev
 // CHECK: icmp eq {{

[clang] 2d1b55e - [CodeGen] Make element type in emitArrayDestroy() predictable

2022-01-11 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2022-01-11T09:25:29+01:00
New Revision: 2d1b55ebea88547d153fcd980b88c946cffc5ca5

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

LOG: [CodeGen] Make element type in emitArrayDestroy() predictable

When calling emitArrayDestroy(), the pointer will usually have
ConvertTypeForMem(EltType) as the element type, as one would expect.
However, globals with initializers sometimes don't use the same
types as values normally would, e.g. here the global uses
{ double, i32 } rather than %struct.T as element type.

Add an early cast to the global destruction path to avoid this
special case. The cast would happen lateron anyway, it only gets
moved to an earlier point.

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

Added: 


Modified: 
clang/lib/CodeGen/CGDecl.cpp
clang/lib/CodeGen/CGDeclCXX.cpp
clang/test/CodeGenCXX/global-array-destruction.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 36185faf942f9..18d6584360866 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -2252,16 +2252,17 @@ void CodeGenFunction::emitArrayDestroy(llvm::Value 
*begin,
 
   // Shift the address back by one element.
   llvm::Value *negativeOne = llvm::ConstantInt::get(SizeTy, -1, true);
+  llvm::Type *llvmElementType = ConvertTypeForMem(elementType);
   llvm::Value *element = Builder.CreateInBoundsGEP(
-  elementPast->getType()->getPointerElementType(), elementPast, 
negativeOne,
-  "arraydestroy.element");
+  llvmElementType, elementPast, negativeOne, "arraydestroy.element");
 
   if (useEHCleanup)
 pushRegularPartialArrayCleanup(begin, element, elementType, elementAlign,
destroyer);
 
   // Perform the actual destruction there.
-  destroyer(*this, Address(element, elementAlign), elementType);
+  destroyer(*this, Address(element, llvmElementType, elementAlign),
+elementType);
 
   if (useEHCleanup)
 PopCleanupBlock();

diff  --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index 3579761f14293..7b880c1354e19 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -136,6 +136,7 @@ static void EmitDeclDestroy(CodeGenFunction &CGF, const 
VarDecl &D,
 }
   // Otherwise, the standard logic requires a helper function.
   } else {
+Addr = Addr.getElementBitCast(CGF.ConvertTypeForMem(Type));
 Func = CodeGenFunction(CGM)
.generateDestroyHelper(Addr, Type, CGF.getDestroyer(DtorKind),
   CGF.needsEHCleanup(DtorKind), &D);

diff  --git a/clang/test/CodeGenCXX/global-array-destruction.cpp 
b/clang/test/CodeGenCXX/global-array-destruction.cpp
index 0f280e0001127..686c8a6c580ad 100644
--- a/clang/test/CodeGenCXX/global-array-destruction.cpp
+++ b/clang/test/CodeGenCXX/global-array-destruction.cpp
@@ -39,7 +39,7 @@ struct T {
 T t[2][3] = { 1.0, 2, 3.0, 4, 5.0, 6, 7.0, 8, 9.0, 10, 11.0, 12 };
 
 // CHECK: call {{.*}} @__cxa_atexit
-// CHECK: getelementptr inbounds ([2 x [3 x {{.*}}]], [2 x [3 x {{.*}}]]* @t, 
i64 1, i64 0, i64 0)
+// CHECK: getelementptr inbounds ([2 x [3 x %struct.T]], [2 x [3 x 
%struct.T]]* bitcast ([2 x [3 x { double, i32 }]]* @t to [2 x [3 x 
%struct.T]]*), i64 1, i64 0, i64 0)
 // CHECK: call void @_ZN1TD1Ev
 // CHECK: icmp eq {{.*}} @t
 // CHECK: br i1 {{.*}}
@@ -47,7 +47,7 @@ T t[2][3] = { 1.0, 2, 3.0, 4, 5.0, 6, 7.0, 8, 9.0, 10, 11.0, 
12 };
 static T t2[2][3] = { 1.0, 2, 3.0, 4, 5.0, 6, 7.0, 8, 9.0, 10, 11.0, 12 };
 
 // CHECK: call {{.*}} @__cxa_atexit
-// CHECK: getelementptr inbounds ([2 x [3 x {{.*}}]], [2 x [3 x {{.*}}]]* 
@_ZL2t2, i64 1, i64 0, i64 0)
+// CHECK: getelementptr inbounds ([2 x [3 x %struct.T]], [2 x [3 x 
%struct.T]]* bitcast ([2 x [3 x { double, i32 }]]* @_ZL2t2 to [2 x [3 x 
%struct.T]]*), i64 1, i64 0, i64 0)
 // CHECK: call void @_ZN1TD1Ev
 // CHECK: icmp eq {{.*}} @_ZL2t2
 // CHECK: br i1 {{.*}}
@@ -56,7 +56,7 @@ using U = T[2][3];
 U &&u = U{ {{1.0, 2}, {3.0, 4}, {5.0, 6}}, {{7.0, 8}, {9.0, 10}, {11.0, 12}} };
 
 // CHECK: call {{.*}} @__cxa_atexit
-// CHECK: getelementptr inbounds ([2 x [3 x {{.*}}]], [2 x [3 x {{.*}}]]* 
@_ZGR1u_, i64 1, i64 0, i64 0)
+// CHECK: getelementptr inbounds ([2 x [3 x %struct.T]], [2 x [3 x 
%struct.T]]* @_ZGR1u_, i64 1, i64 0, i64 0)
 // CHECK: call void @_ZN1TD1Ev
 // CHECK: icmp eq {{.*}} @_ZGR1u_
 // CHECK: br i1 {{.*}}



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


[PATCH] D116920: [clang-format] clang-format eats space in front of attributes for operator delete

2022-01-11 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 398863.
MyDeveloperDay added a comment.

clang-format


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

https://reviews.llvm.org/D116920

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -9459,6 +9459,11 @@
"new 
(aa(aaa))\n"
"typename ();");
   verifyFormat("delete[] h->p;");
+
+  verifyFormat("void operator delete(void *foo) ATTRIB;");
+  verifyFormat("void operator new(void *foo) ATTRIB;");
+  verifyFormat("void operator delete[](void *foo) ATTRIB;");
+  verifyFormat("void operator delete(void *ptr ) noexcept;");
 }
 
 TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1892,6 +1892,14 @@
   return false;
 LeftOfParens = LeftOfParens->MatchingParen->Previous;
   }
+  
+  // The Condition directly below this one will see the operator arguments
+  // as a (void *foo) cast.
+  //   void operator delete(void *foo) ATTRIB;
+  if (LeftOfParens->Tok.getIdentifierInfo() &&
+  LeftOfParens->Previous &&
+  LeftOfParens->Previous->is(tok::kw_operator))
+return false;
 
   // If there is an identifier (or with a few exceptions a keyword) right
   // before the parentheses, this is unlikely to be a cast.


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -9459,6 +9459,11 @@
"new (aa(aaa))\n"
"typename ();");
   verifyFormat("delete[] h->p;");
+
+  verifyFormat("void operator delete(void *foo) ATTRIB;");
+  verifyFormat("void operator new(void *foo) ATTRIB;");
+  verifyFormat("void operator delete[](void *foo) ATTRIB;");
+  verifyFormat("void operator delete(void *ptr ) noexcept;");
 }
 
 TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1892,6 +1892,14 @@
   return false;
 LeftOfParens = LeftOfParens->MatchingParen->Previous;
   }
+  
+  // The Condition directly below this one will see the operator arguments
+  // as a (void *foo) cast.
+  //   void operator delete(void *foo) ATTRIB;
+  if (LeftOfParens->Tok.getIdentifierInfo() &&
+  LeftOfParens->Previous &&
+  LeftOfParens->Previous->is(tok::kw_operator))
+return false;
 
   // If there is an identifier (or with a few exceptions a keyword) right
   // before the parentheses, this is unlikely to be a cast.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116920: [clang-format] clang-format eats space in front of attributes for operator delete

2022-01-11 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 398864.
MyDeveloperDay added a comment.

remove additional space


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

https://reviews.llvm.org/D116920

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -9459,6 +9459,11 @@
"new 
(aa(aaa))\n"
"typename ();");
   verifyFormat("delete[] h->p;");
+
+  verifyFormat("void operator delete(void *foo) ATTRIB;");
+  verifyFormat("void operator new(void *foo) ATTRIB;");
+  verifyFormat("void operator delete[](void *foo) ATTRIB;");
+  verifyFormat("void operator delete(void *ptr) noexcept;");
 }
 
 TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1892,6 +1892,14 @@
   return false;
 LeftOfParens = LeftOfParens->MatchingParen->Previous;
   }
+  
+  // The Condition directly below this one will see the operator arguments
+  // as a (void *foo) cast.
+  //   void operator delete(void *foo) ATTRIB;
+  if (LeftOfParens->Tok.getIdentifierInfo() &&
+  LeftOfParens->Previous &&
+  LeftOfParens->Previous->is(tok::kw_operator))
+return false;
 
   // If there is an identifier (or with a few exceptions a keyword) right
   // before the parentheses, this is unlikely to be a cast.


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -9459,6 +9459,11 @@
"new (aa(aaa))\n"
"typename ();");
   verifyFormat("delete[] h->p;");
+
+  verifyFormat("void operator delete(void *foo) ATTRIB;");
+  verifyFormat("void operator new(void *foo) ATTRIB;");
+  verifyFormat("void operator delete[](void *foo) ATTRIB;");
+  verifyFormat("void operator delete(void *ptr) noexcept;");
 }
 
 TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1892,6 +1892,14 @@
   return false;
 LeftOfParens = LeftOfParens->MatchingParen->Previous;
   }
+  
+  // The Condition directly below this one will see the operator arguments
+  // as a (void *foo) cast.
+  //   void operator delete(void *foo) ATTRIB;
+  if (LeftOfParens->Tok.getIdentifierInfo() &&
+  LeftOfParens->Previous &&
+  LeftOfParens->Previous->is(tok::kw_operator))
+return false;
 
   // If there is an identifier (or with a few exceptions a keyword) right
   // before the parentheses, this is unlikely to be a cast.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116935: [IRBuilder] Introduce folder using inst-simplify, use for Or fold.

2022-01-11 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

In D116935#3232763 , @craig.topper 
wrote:

> Do the programs in compile-time tracker make much use of bitfields?

I'd expect some bitfields, but nothing excessive/pathological.

> Is there any indication in rdar://7362516 what program needed this? It looks 
> like assigning a bitfield to 0 is enough to generate an or with 0 that 
> survives through fast isel at -O0 on X86. But a few assignments to 0 wouldn't 
> make for a huge problem, so I imagine there must have been something 
> pathological about some program.

I had a look at  rdar://7362516 and there is nothing in the issue & history 
that seems to indicate that the motivation was a pathological case, but just a 
very simple struct with 4 bitfields. Clang generates a lot of other redundant 
IR that doesn't get folded by IRBuilder (e.g. add or shifts of 0), which 
survive in a similar way with fast isel. AFAICT there's nothing that would 
indicate that `or X, 0` is a special case that would warrant special treatment. 
 rdar://7362516  also mentions that IRBuilder should fold shifts with 0 as 
well, but it looks like that's not happening at the moment either.

I am inclined to remove the special case from IRBuilder, which applies the 
'IRBuilder should not optimize directly, only via a specified folder' policy 
also to `CreateOr`. I don't think we should use InstSimplifyFolder in Clang, 
because Clang usually doesn't try very hard to optimize IR and 
InstructionSimplify provides a lot of folds. But if we get additional feedback 
after the commit that the `or X, 0` fold is very valuable for Clang, this can 
be provided to Clang via a custom ClangFolder.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116935

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


[clang] e26bbae - [clang] [test] Remove newly added tests that fail on Darwin

2022-01-11 Thread Martin Storsjö via cfe-commits

Author: Martin Storsjö
Date: 2022-01-11T11:06:29+02:00
New Revision: e26bbae30218a35d76a79fe90b0e41dd0f71b779

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

LOG: [clang] [test] Remove newly added tests that fail on Darwin

These tests were recently added in
50ec1306d060e46e0d53c9f5d8a052e1b0d10d3b. The clang-cl invocations
interpret the source path, %s, which begins with /Users, as a cl
option /U. Normally this is worked around by passing -- before
the arguments that must be interpreted as files, not options, but
in the current test, the -link option must be passed last, after any
file names.

Added: 


Modified: 
clang/test/Driver/diagnostics.c

Removed: 




diff  --git a/clang/test/Driver/diagnostics.c b/clang/test/Driver/diagnostics.c
index 16e00345eb51..73f427c02dcc 100644
--- a/clang/test/Driver/diagnostics.c
+++ b/clang/test/Driver/diagnostics.c
@@ -40,14 +40,4 @@
 // RUN:   --start-no-unused-arguments -fsyntax-only --end-no-unused-arguments \
 // RUN:   -lfoo -Werror %s 2>&1 | FileCheck %s
 
-// Test clang-cl warning about unused linker options.
-// RUN: not %clang_cl -fsyntax-only /WX %s \
-// RUN:   -link 2>&1 | FileCheck %s --check-prefix=CL-WARNING
-
-// Test clang-cl ignoring the warning with --start-no-unused-arguments.
-// RUN: %clang_cl -fsyntax-only /WX %s \
-// RUN:   --start-no-unused-arguments -link --end-no-unused-arguments 2>&1 | 
count 0
-
 // CHECK: -lfoo: 'linker' input unused
-
-// CL-WARNING: argument unused during compilation: '-link'



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


[clang-tools-extra] 22ac067 - [clangd] Small optimization in SelectionTree

2022-01-11 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-01-11T10:18:44+01:00
New Revision: 22ac067b2dce8c90db0bbeecb6ec926f526399df

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

LOG: [clangd] Small optimization in SelectionTree

This seems to be strictly faster in all cases. Before fixing D116978 it
was one of the hot paths, and may become one again.

Added: 


Modified: 
clang-tools-extra/clangd/Selection.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Selection.cpp 
b/clang-tools-extra/clangd/Selection.cpp
index 7c6b8b3134fe..e15308a19179 100644
--- a/clang-tools-extra/clangd/Selection.cpp
+++ b/clang-tools-extra/clangd/Selection.cpp
@@ -280,9 +280,12 @@ class SelectionTester {
 SelectionTree::Selection Result = NoTokens;
 while (!ExpandedTokens.empty()) {
   // Take consecutive tokens from the same context together for efficiency.
-  FileID FID = SM.getFileID(ExpandedTokens.front().location());
+  SourceLocation Start = ExpandedTokens.front().location();
+  FileID FID = SM.getFileID(Start);
+  // Comparing SourceLocations against bounds is cheaper than getFileID().
+  SourceLocation Limit = SM.getComposedLoc(FID, SM.getFileIDSize(FID));
   auto Batch = ExpandedTokens.take_while([&](const syntax::Token &T) {
-return SM.getFileID(T.location()) == FID;
+return T.location() >= Start && T.location() < Limit;
   });
   assert(!Batch.empty());
   ExpandedTokens = ExpandedTokens.drop_front(Batch.size());



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


[PATCH] D115521: [Templight] Don't display empty strings for names of unnamed template parameters

2022-01-11 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added inline comments.



Comment at: clang/lib/Frontend/FrontendActions.cpp:501
+
+if (const auto *Decl = dyn_cast(NamedTemplate)) {
+  if (const auto *R = dyn_cast(Decl)) {

Szelethus wrote:
> martong wrote:
> > martong wrote:
> > > Should this handle `EnumDecl`s as well? An enum declaration itself cannot 
> > > be a primary template, however, it can be 1) a member of a specialization 
> > > of a templated class 2)  an instantiation of a member enumeration of a 
> > > class template specialization.
> > > 
> > > 
> > Should this handle variable templates (VarTemplateDecl) as well? Or it  is 
> > not possible to have unnamed variable templates?
> `EnumDecl` is a subclass of `TagDecl`, unless I misunderstood what you meant?
Right now, yes, it seems to that unnamed variable templates are not a thing.



Comment at: clang/lib/Frontend/FrontendActions.cpp:501-510
+if (const auto *Decl = dyn_cast(NamedTemplate)) {
+  if (const auto *R = dyn_cast(Decl)) {
+if (R->isLambda()) {
+  OS << "lambda at ";
+  Decl->getLocation().print(OS, TheSema.getSourceManager());
+  return;
+}

martong wrote:
> martong wrote:
> > Should this handle `EnumDecl`s as well? An enum declaration itself cannot 
> > be a primary template, however, it can be 1) a member of a specialization 
> > of a templated class 2)  an instantiation of a member enumeration of a 
> > class template specialization.
> > 
> > 
> Should this handle variable templates (VarTemplateDecl) as well? Or it  is 
> not possible to have unnamed variable templates?
`EnumDecl` is a subclass of `TagDecl`, unless I misunderstood what you meant?


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

https://reviews.llvm.org/D115521

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


[PATCH] D112913: Misleading bidirectional detection

2022-01-11 Thread serge via Phabricator via cfe-commits
serge-sans-paille added a comment.

@MaskRay any blocker on that new version now that it recieved a green light 
from @upsuper?


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

https://reviews.llvm.org/D112913

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


[clang-tools-extra] 1e9b837 - [clangd] Save more getFileID in Selection

2022-01-11 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-01-11T11:01:54+01:00
New Revision: 1e9b837585cc0c8713e00d4f9c3512c867d598de

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

LOG: [clangd] Save more getFileID in Selection

This saves about 10% of SelectionVisitor::pop().

Added: 


Modified: 
clang-tools-extra/clangd/Selection.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Selection.cpp 
b/clang-tools-extra/clangd/Selection.cpp
index e15308a19179..bf9783d80cae 100644
--- a/clang-tools-extra/clangd/Selection.cpp
+++ b/clang-tools-extra/clangd/Selection.cpp
@@ -234,7 +234,9 @@ class SelectionTester {
   // The selection is offsets [SelBegin, SelEnd) in SelFile.
   SelectionTester(const syntax::TokenBuffer &Buf, FileID SelFile,
   unsigned SelBegin, unsigned SelEnd, const SourceManager &SM)
-  : SelFile(SelFile), SM(SM) {
+  : SelFile(SelFile), SelFileBounds(SM.getLocForStartOfFile(SelFile),
+SM.getLocForEndOfFile(SelFile)),
+SM(SM) {
 // Find all tokens (partially) selected in the file.
 auto AllSpelledTokens = Buf.spelledTokens(SelFile);
 const syntax::Token *SelFirst =
@@ -301,11 +303,10 @@ class SelectionTester {
   bool mayHit(SourceRange R) const {
 if (SpelledTokens.empty())
   return false;
-auto B = SM.getDecomposedLoc(R.getBegin());
-auto E = SM.getDecomposedLoc(R.getEnd());
-if (B.first == SelFile && E.first == SelFile)
-  if (E.second < SpelledTokens.front().Offset ||
-  B.second > SpelledTokens.back().Offset)
+auto B = offsetInSelFile(R.getBegin());
+auto E = offsetInSelFile(R.getEnd());
+if (B && E)
+  if (*E < SpelledTokens.front().Offset || *B > 
SpelledTokens.back().Offset)
 return false;
 return true;
   }
@@ -325,8 +326,8 @@ class SelectionTester {
 
 // Handle tokens written directly in the main file.
 if (FID == SelFile) {
-  return testTokenRange(SM.getFileOffset(Batch.front().location()),
-SM.getFileOffset(Batch.back().location()));
+  return testTokenRange(*offsetInSelFile(Batch.front().location()),
+*offsetInSelFile(Batch.back().location()));
 }
 
 // Handle tokens in another file #included into the main file.
@@ -334,9 +335,9 @@ class SelectionTester {
 if (StartLoc.isFileID()) {
   for (SourceLocation Loc = Batch.front().location(); Loc.isValid();
Loc = SM.getIncludeLoc(SM.getFileID(Loc))) {
-if (SM.getFileID(Loc) == SelFile)
+if (auto Offset = offsetInSelFile(Loc))
   // FIXME: use whole #include directive, not just the filename string.
-  return testToken(SM.getFileOffset(Loc));
+  return testToken(*Offset);
   }
   return NoTokens;
 }
@@ -344,12 +345,11 @@ class SelectionTester {
 assert(StartLoc.isMacroID());
 // Handle tokens that were passed as a macro argument.
 SourceLocation ArgStart = SM.getTopMacroCallerLoc(StartLoc);
-if (SM.getFileID(ArgStart) == SelFile) {
+if (auto ArgOffset = offsetInSelFile(ArgStart)) {
   if (isFirstExpansion(FID, ArgStart, SM)) {
 SourceLocation ArgEnd =
 SM.getTopMacroCallerLoc(Batch.back().location());
-return testTokenRange(SM.getFileOffset(ArgStart),
-  SM.getFileOffset(ArgEnd));
+return testTokenRange(*ArgOffset, *offsetInSelFile(ArgEnd));
   } else { // NOLINT(llvm-else-after-return)
 /* fall through and treat as part of the macro body */
   }
@@ -357,10 +357,9 @@ class SelectionTester {
 
 // Handle tokens produced by non-argument macro expansion.
 // Check if the macro name is selected, don't claim it exclusively.
-auto Expansion = SM.getDecomposedExpansionLoc(StartLoc);
-if (Expansion.first == SelFile)
+if (auto ExpansionOffset = offsetInSelFile(getExpansionStart(StartLoc)))
   // FIXME: also check ( and ) for function-like macros?
-  return testToken(Expansion.second);
+  return testToken(*ExpansionOffset);
 return NoTokens;
   }
 
@@ -402,12 +401,25 @@ class SelectionTester {
 return NoTokens;
   }
 
+  llvm::Optional offsetInSelFile(SourceLocation Loc) const {
+if (Loc < SelFileBounds.getBegin() || Loc >= SelFileBounds.getEnd())
+  return llvm::None;
+return Loc.getRawEncoding() - SelFileBounds.getBegin().getRawEncoding();
+  }
+
+  SourceLocation getExpansionStart(SourceLocation Loc) const {
+while (Loc.isMacroID())
+  Loc = SM.getImmediateExpansionRange(Loc).getBegin();
+return Loc;
+  }
+
   struct Tok {
 unsigned Offset;
 SelectionTree::Selection Selected;
   };
   std::vector SpelledTokens;
   FileID SelFile;
+  SourceRange SelFileBounds;
   const

[PATCH] D112913: Misleading bidirectional detection

2022-01-11 Thread Xidorn Quan via Phabricator via cfe-commits
upsuper added a comment.

I'd like to clarify that what I think is correct now is the algorithm to detect 
unclosed explicit formatting scopes in a given string.

I haven't been following very closely with the whole spoofing issue, so I can't 
say that there is no other ways to construct a spoof that this algorithm is not 
designed to detect.

As you have found, `RLM`, and `ALM` can be used to confuse code reader, but 
they are not much different than a string with other strong RTL characters 
inside, and I don't quite see how that can be linted without hurting 
potentially legitimate code. Maybe if the compiler supports treating `LRM` as 
whitespace (I'm not sure whether Clang does), a lint may be added to ask 
wrapping any string with outermost strong characters being RTL in the form of 
`{LRM}"string"{LRM}` so that the RTL characters don't affect outside. Other 
than that, I don't think there is anyway to lint against such a confusion.


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

https://reviews.llvm.org/D112913

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


[PATCH] D116978: [clangd] Selection: Prune gtest TEST()s earlier

2022-01-11 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 398876.
sammccall added a comment.

Rebase (offsetInSelFile)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116978

Files:
  clang-tools-extra/clangd/Selection.cpp


Index: clang-tools-extra/clangd/Selection.cpp
===
--- clang-tools-extra/clangd/Selection.cpp
+++ clang-tools-extra/clangd/Selection.cpp
@@ -8,7 +8,6 @@
 
 #include "Selection.h"
 #include "AST.h"
-#include "SourceCode.h"
 #include "support/Logger.h"
 #include "support/Trace.h"
 #include "clang/AST/ASTTypeTraits.h"
@@ -303,10 +302,21 @@
   bool mayHit(SourceRange R) const {
 if (SpelledTokens.empty())
   return false;
-auto B = offsetInSelFile(R.getBegin());
-auto E = offsetInSelFile(R.getEnd());
-if (B && E)
-  if (*E < SpelledTokens.front().Offset || *B > 
SpelledTokens.back().Offset)
+// If the node starts after the selection ends, it is not selected.
+// All tokens a macro location might claim are >= its expansion site.
+// So it's safe to use the expansions location for the comparison.
+// (This is particularly helpful for GTest's TEST macro).
+if (auto B = offsetInSelFile(getExpansionStart(R.getBegin(
+  if (*B > SpelledTokens.back().Offset)
+return false;
+// If the node ends before the selection begins, it is not selected.
+SourceLocation EndLoc = R.getEnd();
+while (EndLoc.isMacroID())
+  EndLoc = SM.getImmediateExpansionRange(EndLoc).getEnd();
+// In the rare case that the expansion range is a char range, EndLoc is
+// ~one token too far to the right. We may fail to prune, that's OK.
+if (auto E = offsetInSelFile(EndLoc))
+  if (*E < SpelledTokens.front().Offset)
 return false;
 return true;
   }


Index: clang-tools-extra/clangd/Selection.cpp
===
--- clang-tools-extra/clangd/Selection.cpp
+++ clang-tools-extra/clangd/Selection.cpp
@@ -8,7 +8,6 @@
 
 #include "Selection.h"
 #include "AST.h"
-#include "SourceCode.h"
 #include "support/Logger.h"
 #include "support/Trace.h"
 #include "clang/AST/ASTTypeTraits.h"
@@ -303,10 +302,21 @@
   bool mayHit(SourceRange R) const {
 if (SpelledTokens.empty())
   return false;
-auto B = offsetInSelFile(R.getBegin());
-auto E = offsetInSelFile(R.getEnd());
-if (B && E)
-  if (*E < SpelledTokens.front().Offset || *B > SpelledTokens.back().Offset)
+// If the node starts after the selection ends, it is not selected.
+// All tokens a macro location might claim are >= its expansion site.
+// So it's safe to use the expansions location for the comparison.
+// (This is particularly helpful for GTest's TEST macro).
+if (auto B = offsetInSelFile(getExpansionStart(R.getBegin(
+  if (*B > SpelledTokens.back().Offset)
+return false;
+// If the node ends before the selection begins, it is not selected.
+SourceLocation EndLoc = R.getEnd();
+while (EndLoc.isMacroID())
+  EndLoc = SM.getImmediateExpansionRange(EndLoc).getEnd();
+// In the rare case that the expansion range is a char range, EndLoc is
+// ~one token too far to the right. We may fail to prune, that's OK.
+if (auto E = offsetInSelFile(EndLoc))
+  if (*E < SpelledTokens.front().Offset)
 return false;
 return true;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 18b2385 - [clang] [test] Fix clang-cl unused argument tests on paths that start with /U

2022-01-11 Thread Martin Storsjö via cfe-commits

Author: Martin Storsjö
Date: 2022-01-11T12:28:23+02:00
New Revision: 18b2385f2b09453b5e9d26459ec9e806f5ee7f86

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

LOG: [clang] [test] Fix clang-cl unused argument tests on paths that start with 
/U

This reinstates a test that was temporarily removed in
e26bbae30218a35d76a79fe90b0e41dd0f71b779, in a form that works on
Darwin.

Use -LD instead of -link as a linker argument that is unused when
compiling, that produces warnings normally. -LD can be placed anywhere
in the command line, so that the command line ends with "-- %s", making
paths starting with /U correctly interpreted as paths, not options.

Added: 


Modified: 
clang/test/Driver/diagnostics.c

Removed: 




diff  --git a/clang/test/Driver/diagnostics.c b/clang/test/Driver/diagnostics.c
index 73f427c02dcce..b9455b0a91f57 100644
--- a/clang/test/Driver/diagnostics.c
+++ b/clang/test/Driver/diagnostics.c
@@ -40,4 +40,14 @@
 // RUN:   --start-no-unused-arguments -fsyntax-only --end-no-unused-arguments \
 // RUN:   -lfoo -Werror %s 2>&1 | FileCheck %s
 
+// Test clang-cl warning about unused linker options.
+// RUN: not %clang_cl -fsyntax-only /WX \
+// RUN:   -LD -- %s 2>&1 | FileCheck %s --check-prefix=CL-WARNING
+
+// Test clang-cl ignoring the warning with --start-no-unused-arguments.
+// RUN: %clang_cl -fsyntax-only /WX \
+// RUN:   --start-no-unused-arguments /LD --end-no-unused-arguments -- %s 2>&1 
| count 0
+
 // CHECK: -lfoo: 'linker' input unused
+
+// CL-WARNING: argument unused during compilation: '-LD'



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


[clang] c61299e - [SemaOverload] Use castAs<> instead of getAs<> to avoid dereference of nullptr

2022-01-11 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2022-01-11T10:31:25Z
New Revision: c61299e2b30627f327f5a9a198ad030092534496

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

LOG: [SemaOverload] Use castAs<> instead of getAs<> to avoid dereference of 
nullptr

The pointer is always dereferenced inside BuildSimilarlyQualifiedPointerType, 
so assert the cast is correct instead of returning nullptr

Added: 


Modified: 
clang/lib/Sema/SemaOverload.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 7b503103006d5..041fcee023a5b 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -2405,9 +2405,8 @@ bool Sema::IsPointerConversion(Expr *From, QualType 
FromType, QualType ToType,
   if (FromType->isObjCObjectPointerType() && ToPointeeType->isVoidType() &&
   !getLangOpts().ObjCAutoRefCount) {
 ConvertedType = BuildSimilarlyQualifiedPointerType(
-  FromType->getAs(),
-   ToPointeeType,
-   ToType, Context);
+FromType->castAs(), ToPointeeType, ToType,
+Context);
 return true;
   }
   const PointerType *FromTypePtr = FromType->getAs();



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


[clang] 2e52f76 - [SemaOverload] compareConversionFunctions - use castAs<> instead of getAs<> to avoid dereference of nullptr

2022-01-11 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2022-01-11T10:31:26Z
New Revision: 2e52f76a722aa3ae5d655e0f15972b4f73db0150

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

LOG: [SemaOverload] compareConversionFunctions - use castAs<> instead of 
getAs<> to avoid dereference of nullptr

The pointer is dereferenced immediately below, so assert the cast is correct 
instead of returning nullptr

Added: 


Modified: 
clang/lib/Sema/SemaOverload.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 041fcee023a5..483247aaa7c5 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -3717,8 +3717,7 @@ compareConversionFunctions(Sema &S, FunctionDecl 
*Function1,
 CallingConv Conv2CC = Conv2FuncRet->getCallConv();
 
 CXXMethodDecl *CallOp = Conv2->getParent()->getLambdaCallOperator();
-const FunctionProtoType *CallOpProto =
-CallOp->getType()->getAs();
+const auto *CallOpProto = CallOp->getType()->castAs();
 
 CallingConv CallOpCC =
 CallOp->getType()->castAs()->getCallConv();



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


[PATCH] D116960: [ADT] Add an in-place version of toHex()

2022-01-11 Thread Hans Wennborg via Phabricator via cfe-commits
hans marked 2 inline comments as done.
hans added a comment.

In D116960#3232461 , @dexonsmith 
wrote:

> Mostly LGTM, just a couple of comments on the drive-by changes to 
> `hexdigit()` (I might split that (and the new call in toHex()) into a 
> separate commit, but if you keep them here please mention them in the commit 
> message).

Thanks! I'll commit the hexdigit() change separately.




Comment at: llvm/include/llvm/ADT/StringExtras.h:37
 inline char hexdigit(unsigned X, bool LowerCase = false) {
-  const char HexChar = LowerCase ? 'a' : 'A';
-  return X < 10 ? '0' + X : HexChar + X - 10;
+  assert(X <= 16);
+  static const char *const LUT = "0123456789ABCDEF";

dexonsmith wrote:
> Should this be `X < 16`?
D'oh, yes of course. Thanks for spotting that!



Comment at: llvm/include/llvm/ADT/StringExtras.h:38
+  assert(X <= 16);
+  static const char *const LUT = "0123456789ABCDEF";
+  const uint8_t Offset = LowerCase ? 32 : 0;

dexonsmith wrote:
> Can you use `constexpr StringLiteral` here?
Yes that would work, but I think it's simpler to just use the built-in types 
here.
Actually, there's no need for this to be a pointer, it should just be an array. 
I'll fix that.


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

https://reviews.llvm.org/D116960

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


[PATCH] D116960: [ADT] Add an in-place version of toHex()

2022-01-11 Thread Hans Wennborg via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
hans marked 2 inline comments as done.
Closed by commit rG83797c03d2ee: [ADT] Use a lookup table in hexdigit() and 
call that from toHex() (authored by hans).

Changed prior to commit:
  https://reviews.llvm.org/D116960?vs=398704&id=398880#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116960

Files:
  llvm/include/llvm/ADT/StringExtras.h


Index: llvm/include/llvm/ADT/StringExtras.h
===
--- llvm/include/llvm/ADT/StringExtras.h
+++ llvm/include/llvm/ADT/StringExtras.h
@@ -35,8 +35,10 @@
 /// hexdigit - Return the hexadecimal character for the
 /// given number \p X (which should be less than 16).
 inline char hexdigit(unsigned X, bool LowerCase = false) {
-  const char HexChar = LowerCase ? 'a' : 'A';
-  return X < 10 ? '0' + X : HexChar + X - 10;
+  assert(X < 16);
+  static const char LUT[] = "0123456789ABCDEF";
+  const uint8_t Offset = LowerCase ? 32 : 0;
+  return LUT[X] | Offset;
 }
 
 /// Given an array of c-style strings terminated by a null pointer, construct
@@ -165,16 +167,14 @@
 /// Convert buffer \p Input to its hexadecimal representation.
 /// The returned string is double the size of \p Input.
 inline std::string toHex(StringRef Input, bool LowerCase = false) {
-  static const char *const LUT = "0123456789ABCDEF";
-  const uint8_t Offset = LowerCase ? 32 : 0;
   size_t Length = Input.size();
 
   std::string Output;
   Output.reserve(2 * Length);
   for (size_t i = 0; i < Length; ++i) {
 const unsigned char c = Input[i];
-Output.push_back(LUT[c >> 4] | Offset);
-Output.push_back(LUT[c & 15] | Offset);
+Output.push_back(hexdigit(c >> 4, LowerCase));
+Output.push_back(hexdigit(c & 15, LowerCase));
   }
   return Output;
 }


Index: llvm/include/llvm/ADT/StringExtras.h
===
--- llvm/include/llvm/ADT/StringExtras.h
+++ llvm/include/llvm/ADT/StringExtras.h
@@ -35,8 +35,10 @@
 /// hexdigit - Return the hexadecimal character for the
 /// given number \p X (which should be less than 16).
 inline char hexdigit(unsigned X, bool LowerCase = false) {
-  const char HexChar = LowerCase ? 'a' : 'A';
-  return X < 10 ? '0' + X : HexChar + X - 10;
+  assert(X < 16);
+  static const char LUT[] = "0123456789ABCDEF";
+  const uint8_t Offset = LowerCase ? 32 : 0;
+  return LUT[X] | Offset;
 }
 
 /// Given an array of c-style strings terminated by a null pointer, construct
@@ -165,16 +167,14 @@
 /// Convert buffer \p Input to its hexadecimal representation.
 /// The returned string is double the size of \p Input.
 inline std::string toHex(StringRef Input, bool LowerCase = false) {
-  static const char *const LUT = "0123456789ABCDEF";
-  const uint8_t Offset = LowerCase ? 32 : 0;
   size_t Length = Input.size();
 
   std::string Output;
   Output.reserve(2 * Length);
   for (size_t i = 0; i < Length; ++i) {
 const unsigned char c = Input[i];
-Output.push_back(LUT[c >> 4] | Offset);
-Output.push_back(LUT[c & 15] | Offset);
+Output.push_back(hexdigit(c >> 4, LowerCase));
+Output.push_back(hexdigit(c & 15, LowerCase));
   }
   return Output;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116748: [AArch64][ARM][Clang] PerfMon Extension Added

2022-01-11 Thread Dave Green via Phabricator via cfe-commits
dmgreen added a comment.

Hmm. This appears to be mapping pmuv3p4 to "perfmon". But "perfmon" has been 
around a long time, not a new feature related to the pmuv3p4 update. It seems 
on the AArch64 side to control access to PMCCNTR, i.e. access to the base 
FEAT_PMUv3.

On the Arm side this is altering how HasV7Ops is define in 
https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/ARM/ARM.td#L515, 
which in turn is breaking Cortex-M cpus. It's probably a bug that HasV7Ops 
includes FeaturePerfMon, it shouldn't be included in HasV8MMainlineOps or 
ARMv7m if it's reading a system register with an mrc.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116748

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


[PATCH] D112718: Add intrinsics and builtins for PTX atomics with semantic orders

2022-01-11 Thread Victor Lomuller via Phabricator via cfe-commits
Naghasan added inline comments.



Comment at: clang/include/clang/Basic/BuiltinsNVPTX.def:1057
+
+BUILTIN(__nvvm_atom_xchg_global_i, "iiD*i", "n")
+TARGET_BUILTIN(__nvvm_atom_cta_xchg_global_i, "iiD*i", "n", SM_60)

tra wrote:
> t4c1 wrote:
> > tra wrote:
> > > t4c1 wrote:
> > > > tra wrote:
> > > > > We need to figure out how address-space-specific builtins are 
> > > > > supposed to work.
> > > > > Right now two competing approaches.
> > > > > 
> > > > > This patch declares builtins with generic pointer as an argument, 
> > > > > but, according to the test, expects to be used with the AS-specific 
> > > > > pointer.
> > > > > It probably does not catch a wrong-AS pointer passed as an argument, 
> > > > > either.
> > > > > It does happen to work, but I think it's mostly due to the fact that 
> > > > > LLVM intrinsics are overloaded and we happen to end up 
> > > > > addrspacecast'ing  things correctly if the builtin gets the right 
> > > > > kind of pointer.
> > > > > 
> > > > > The other approach is to declare the pointer with the expected AS. 
> > > > > E.g:
> > > > > > TARGET_BUILTIN(__nvvm_mbarrier_init_shared, "vWi*3i", "", 
> > > > > > AND(SM_80,PTX70))
> > > > > 
> > > > > IMO, this is the correct way to do it, but it is also rather 
> > > > > inconvenient to use from CUDA code as it operates on generic pointers.
> > > > > 
> > > > > @jdoerfert - WDYT?
> > > > >TARGET_BUILTIN(__nvvm_mbarrier_init_shared, "vWi*3i", "", 
> > > > >AND(SM_80,PTX70))
> > > > >IMO, this is the correct way to do it, but it is also rather 
> > > > >inconvenient to use from CUDA code as it operates on generic pointers.
> > > > 
> > > > I tried doing this, however it is also completely unusable from OpenCL 
> > > > code (which is our use case). Trying to use it gives you errors about 
> > > > how casting pointers to different address spaces  - for example from 
> > > > local to AS3 is not allowed.
> > > Hmm. It should've worked. It would need the same explicit cast to a 
> > > pointer in AS(3) as in your tests, but it would safeguard against 
> > > attempts to pass it a generic pointer. E.g. 
> > > https://godbolt.org/z/qE6oxzheM
> > > 
> > > Explicit casting to AS(X) for AS-specific variants is annoying, but it's 
> > > probably unavoidable at the moment regardless of whether we declare the 
> > > pointer argument to be AS-specific or not.  LLVM will not always be able 
> > > to infer that a pointer is in particular AS.
> > > Using specific AS in the declaration has a minor benefit of safeguarding 
> > > at compile time against unintentional use of generic pointers.
> > > 
> > > Ideally we may want to convert generic variant of the builtin to 
> > > AS-specific one, if LLVM does know the AS. We currently do this for 
> > > loads/stores, but not for other instructions.
> > > 
> > Well, it does not work. See: https://godbolt.org/z/vM6bKncc4. Declaring the 
> > pointer to be in generic AS is the only way I got it to work. If you know a 
> > way to call a builtin declared with AS numbers in OpenCL, I am happy to do 
> > that instead.
> Could you help me understand how different address spaces are handled by 
> OpenCL in clang and LLVM?
> What exactly are `__local` or `__private` in OpenCL? Do they map to LLVM's 
> address spaces? 
> Clang does complain that we're trying to change AS, but I do not see AS used 
> in the IR: https://godbolt.org/z/soajoE991
> 
> AFAICT what happens is:
> * OpenCL does use explicit AS for pointers (`__local`, `__private` seem to 
> pop up in the error messages)
> * `__attribute__((address_space(3)))` does not match the AS of `__local` and 
> that leads to an error.
> * generic pointer argument works because we are allowed to cast any specific 
> AS to generic one.
> 
> In other words, having specific-AS arguemt works as intended, we just have a 
> mismatch between AS number used by OpenCL and AS number used by NVPTX and 
> we're not allowed to cast between two specific AS.
> 
> If that's indeed the case, then what we appear to be missing is the mapping 
> from OpenCL AS to the target-specific AS, which should, ideally, be done by 
> clang itself. So, if NVPTX-specific builtin operating on shared pointer is 
> called with a pointer in OpenCL's equivalent of CUDA's `__shared__`, it 
> should be mapped to AS(3).
> 
> Could you help me understand how different address spaces are handled by 
> OpenCL in clang and LLVM?

clang makes a strong distinction between language and target address spaces 
since ~3.6 (was more loose before). Each target in clang defines a map between 
language and target address space (e.g. 
https://github.com/llvm/llvm-project/blob/main/clang/lib/Basic/Targets/SPIR.h#L25).
 The map is used in clang codegen to lower `__local` to the right target 
address space.

> Clang does complain that we're trying to change AS, but I do not see AS used 
> in the IR: https://godbolt.org/z/soajoE991

Same code but targeting SPIR: https://godbolt.org/z/4E3brzodq (A

[clang] 0b48d0f - [ADT] Add an in-place version of toHex()

2022-01-11 Thread Hans Wennborg via cfe-commits

Author: Hans Wennborg
Date: 2022-01-11T11:51:04+01:00
New Revision: 0b48d0fe1292929f0cd61a2ca8114d794e245daa

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

LOG: [ADT] Add an in-place version of toHex()

and use that to simplify MD5's hex string code which was previously
using a string stream, as well as Clang's
CGDebugInfo::computeChecksum().

Differential revision: https://reviews.llvm.org/D116960

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
llvm/include/llvm/ADT/StringExtras.h
llvm/include/llvm/Support/MD5.h
llvm/lib/Support/MD5.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 313a927c26d3b..1a9080604a79f 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -354,13 +354,9 @@ CGDebugInfo::computeChecksum(FileID FID, SmallString<32> 
&Checksum) const {
   if (!MemBuffer)
 return None;
 
-  llvm::MD5 Hash;
-  llvm::MD5::MD5Result Result;
-
-  Hash.update(MemBuffer->getBuffer());
-  Hash.final(Result);
-
-  Hash.stringifyResult(Result, Checksum);
+  llvm::toHex(
+  llvm::MD5::hash(llvm::arrayRefFromStringRef(MemBuffer->getBuffer())),
+  /*LowerCase*/ true, Checksum);
   return llvm::DIFile::CSK_MD5;
 }
 

diff  --git a/llvm/include/llvm/ADT/StringExtras.h 
b/llvm/include/llvm/ADT/StringExtras.h
index 912b9bb53c83e..81a0954226d6a 100644
--- a/llvm/include/llvm/ADT/StringExtras.h
+++ b/llvm/include/llvm/ADT/StringExtras.h
@@ -29,7 +29,6 @@
 
 namespace llvm {
 
-template class SmallVectorImpl;
 class raw_ostream;
 
 /// hexdigit - Return the hexadecimal character for the
@@ -166,21 +165,26 @@ inline std::string utohexstr(uint64_t X, bool LowerCase = 
false) {
 
 /// Convert buffer \p Input to its hexadecimal representation.
 /// The returned string is double the size of \p Input.
-inline std::string toHex(StringRef Input, bool LowerCase = false) {
-  size_t Length = Input.size();
-
-  std::string Output;
-  Output.reserve(2 * Length);
-  for (size_t i = 0; i < Length; ++i) {
-const unsigned char c = Input[i];
-Output.push_back(hexdigit(c >> 4, LowerCase));
-Output.push_back(hexdigit(c & 15, LowerCase));
+inline void toHex(ArrayRef Input, bool LowerCase,
+  SmallVectorImpl &Output) {
+  const size_t Length = Input.size();
+  Output.resize_for_overwrite(Length * 2);
+
+  for (size_t i = 0; i < Length; i++) {
+const uint8_t c = Input[i];
+Output[i * 2] = hexdigit(c >> 4, LowerCase);
+Output[i * 2 + 1] = hexdigit(c & 15, LowerCase);
   }
-  return Output;
 }
 
 inline std::string toHex(ArrayRef Input, bool LowerCase = false) {
-  return toHex(toStringRef(Input), LowerCase);
+  SmallString<16> Output;
+  toHex(Input, LowerCase, Output);
+  return std::string(Output);
+}
+
+inline std::string toHex(StringRef Input, bool LowerCase = false) {
+  return toHex(arrayRefFromStringRef(Input), LowerCase);
 }
 
 /// Store the binary representation of the two provided values, \p MSB and

diff  --git a/llvm/include/llvm/Support/MD5.h b/llvm/include/llvm/Support/MD5.h
index 3b960cd4fd880..70d0466013461 100644
--- a/llvm/include/llvm/Support/MD5.h
+++ b/llvm/include/llvm/Support/MD5.h
@@ -88,7 +88,7 @@ class MD5 {
 
   /// Translates the bytes in \p Res to a hex string that is
   /// deposited into \p Str. The result will be of length 32.
-  static void stringifyResult(MD5Result &Result, SmallString<32> &Str);
+  static void stringifyResult(MD5Result &Result, SmallVectorImpl &Str);
 
   /// Computes the hash for a given bytes.
   static std::array hash(ArrayRef Data);

diff  --git a/llvm/lib/Support/MD5.cpp b/llvm/lib/Support/MD5.cpp
index 9dceb4d418cde..caadde3895043 100644
--- a/llvm/lib/Support/MD5.cpp
+++ b/llvm/lib/Support/MD5.cpp
@@ -40,10 +40,9 @@
 #include "llvm/Support/MD5.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Endian.h"
-#include "llvm/Support/Format.h"
-#include "llvm/Support/raw_ostream.h"
 #include 
 #include 
 #include 
@@ -281,14 +280,12 @@ StringRef MD5::result() {
 
 SmallString<32> MD5::MD5Result::digest() const {
   SmallString<32> Str;
-  raw_svector_ostream Res(Str);
-  for (int i = 0; i < 16; ++i)
-Res << format("%.2x", Bytes[i]);
+  toHex(Bytes, /*LowerCase*/ true, Str);
   return Str;
 }
 
-void MD5::stringifyResult(MD5Result &Result, SmallString<32> &Str) {
-  Str = Result.digest();
+void MD5::stringifyResult(MD5Result &Result, SmallVectorImpl &Str) {
+  toHex(Result.Bytes, /*LowerCase*/ true, Str);
 }
 
 std::array MD5::hash(ArrayRef Data) {



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org

[clang-tools-extra] 41fbdfa - Reland "[AST] Add RParen loc for decltype AutoTypeloc."

2022-01-11 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-01-11T12:06:18+01:00
New Revision: 41fbdfa4d5601cccbcdc0ded8ef35190d502f7f3

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

LOG: Reland "[AST] Add RParen loc for decltype AutoTypeloc."

Reland 55d96ac and 37ec65e with a clang-tidy fix.

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
clang-tools-extra/clangd/unittests/SelectionTests.cpp
clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
clang/include/clang/AST/TypeLoc.h
clang/lib/AST/TypeLoc.cpp
clang/lib/Parse/ParseDecl.cpp
clang/lib/Sema/SemaType.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/AST/ast-dump-template-decls-json.cpp
clang/test/AST/ast-dump-template-decls.cpp
clang/unittests/AST/SourceLocationTest.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
index d5c9fa7de811e..2b9907d162664 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
@@ -285,15 +285,12 @@ SourceRange 
UseTrailingReturnTypeCheck::findReturnTypeAndCVSourceRange(
 return {};
   }
 
-  // If the return type is a constrained 'auto' or 'decltype(auto)', we need to
-  // include the tokens after the concept. Unfortunately, the source range of 
an
-  // AutoTypeLoc, if it is constrained, does not include the 'auto' or
-  // 'decltype(auto)'. If the return type is a plain 'decltype(...)', the
-  // source range only contains the first 'decltype' token.
+  // If the return type is a constrained 'auto', we need to include the token
+  // after the concept. Unfortunately, the source range of an AutoTypeLoc, if 
it
+  // is constrained, does not include the 'auto'.
+  // FIXME: fix the AutoTypeLoc location in clang.
   auto ATL = ReturnLoc.getAs();
-  if ((ATL && (ATL.isConstrained() ||
-   ATL.getAutoKeyword() == AutoTypeKeyword::DecltypeAuto)) ||
-  ReturnLoc.getAs()) {
+  if (ATL && ATL.isConstrained() && !ATL.isDecltypeAuto()) {
 SourceLocation End =
 expandIfMacroId(ReturnLoc.getSourceRange().getEnd(), SM);
 SourceLocation BeginNameF = expandIfMacroId(F.getLocation(), SM);

diff  --git a/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp 
b/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
index 3776e1c3505d1..914564e9ae218 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
@@ -96,9 +96,7 @@ bool ExpandAutoType::prepare(const Selection& Inputs) {
   if (auto *Node = Inputs.ASTSelection.commonAncestor()) {
 if (auto *TypeNode = Node->ASTNode.get()) {
   if (const AutoTypeLoc Result = TypeNode->getAs()) {
-// Code in apply() does handle 'decltype(auto)' yet.
-if (!Result.getTypePtr()->isDecltypeAuto() &&
-!isStructuredBindingType(Node) &&
+if (!isStructuredBindingType(Node) &&
 !isDeducedAsLambda(Node, Result.getBeginLoc()) &&
 !isTemplateParam(Node))
   CachedLocation = Result;

diff  --git a/clang-tools-extra/clangd/unittests/SelectionTests.cpp 
b/clang-tools-extra/clangd/unittests/SelectionTests.cpp
index 7e19f07a2215e..0f4464122c8fb 100644
--- a/clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -391,6 +391,8 @@ TEST(SelectionTest, CommonAncestor) {
 )cpp",
   "DeclRefExpr"},
   {"[[decltype^(1)]] b;", "DecltypeTypeLoc"}, // Not the VarDecl.
+  // decltype(auto) is an AutoTypeLoc!
+  {"[[de^cltype(a^uto)]] a = 1;", "AutoTypeLoc"},
 
   // Objective-C nullability attributes.
   {

diff  --git a/clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp 
b/clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
index 96574a67b5a46..6d9d4362be7af 100644
--- a/clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
+++ b/clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
@@ -71,7 +71,8 @@ TEST_F(ExpandAutoTypeTest, Test) {
   apply("void ns::Func() { au^to x = new ns::Class::Nested{}; }"),
   "void ns::Func() { ns::Class::Nested * x = new ns::Class::Nested{}; }");
 
-  EXPECT_UNAVAILABLE("dec^ltype(au^to) x = 10;");
+  EXPECT_EQ(apply("dec^ltype(auto) x = 10;"), "int x = 10;");
+  EXPECT_EQ(apply("decltype(au^to) x = 10;"), "int x = 10;");
   // expanding types in structured bindings is syntactically invalid.
   EXPECT_UNAVAILAB

[clang] fba8ad2 - [SemaTemplateInstantiate] Use cast<> instead of dyn_cast<> to avoid dereference of nullptr

2022-01-11 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2022-01-11T11:29:38Z
New Revision: fba8ad2b719c14e971dfe16458b3d18c08e0e40d

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

LOG: [SemaTemplateInstantiate] Use cast<> instead of dyn_cast<> to avoid 
dereference of nullptr

The pointer is always dereferenced immediately below, so assert the cast is 
correct instead of returning nullptr

Added: 


Modified: 
clang/lib/Sema/SemaTemplateInstantiate.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 7d4c000e7e90..7c6bb4c8a5f8 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -2790,11 +2790,10 @@ Sema::InstantiateClass(SourceLocation 
PointOfInstantiation,
 CurrentInstantiationScope = I->Scope;
 
 // Allow 'this' within late-parsed attributes.
-NamedDecl *ND = dyn_cast(I->NewDecl);
-CXXRecordDecl *ThisContext =
-dyn_cast_or_null(ND->getDeclContext());
+auto *ND = cast(I->NewDecl);
+auto *ThisContext = dyn_cast_or_null(ND->getDeclContext());
 CXXThisScopeRAII ThisScope(*this, ThisContext, Qualifiers(),
-   ND && ND->isCXXInstanceMember());
+   ND->isCXXInstanceMember());
 
 Attr *NewAttr =
   instantiateTemplateAttribute(I->TmplAttr, Context, *this, TemplateArgs);



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


[PATCH] D116920: [clang-format] clang-format eats space in front of attributes for operator delete

2022-01-11 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius accepted this revision.
curdeius added a comment.
This revision is now accepted and ready to land.

LGTM. Don't forget to reformat.

It's a pity though that we cannot use `MightBeFunctionDecl`.


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

https://reviews.llvm.org/D116920

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


[PATCH] D116549: [OpenMP][Clang] Allow passing target features in ISA trait for metadirective clause

2022-01-11 Thread Saiyedul Islam via Phabricator via cfe-commits
saiislam updated this revision to Diff 398897.
saiislam added a comment.

1. Used a common diagnostic warning `warn_unknown_declare_variant_isa_trait` 
for ParseOpenMP and SemaOpenMP for decalre variant and metadirectives.
2. Split lit codegen tests into two files, one requiring amdgpu-registered 
target and another for host only.
3. Added warning message lit test at an appropriate place.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116549

Files:
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Parse/ParseOpenMP.cpp
  clang/test/OpenMP/metadirective_device_isa_codegen.cpp
  clang/test/OpenMP/metadirective_device_isa_codegen_amdgcn.cpp
  clang/test/OpenMP/metadirective_messages.cpp

Index: clang/test/OpenMP/metadirective_messages.cpp
===
--- clang/test/OpenMP/metadirective_messages.cpp
+++ clang/test/OpenMP/metadirective_messages.cpp
@@ -17,4 +17,6 @@
   ;
 #pragma omp metadirective when(device = {arch(nvptx)} : parallel default() // expected-error {{expected ',' or ')' in 'when' clause}} expected-error {{expected expression}}
   ;
+#pragma omp metadirective when(device = {isa("some-unsupported-feature")} : parallel) default(single) // expected-warning {{isa trait 'some-unsupported-feature' is not known to the current target; verify the spelling or consider restricting the context selector with the 'arch' selector further}}
+  ;
 }
Index: clang/test/OpenMP/metadirective_device_isa_codegen_amdgcn.cpp
===
--- /dev/null
+++ clang/test/OpenMP/metadirective_device_isa_codegen_amdgcn.cpp
@@ -0,0 +1,53 @@
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang_cc1 -fopenmp -x c++ -w -std=c++11 -triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -fopenmp -x c++ -w -std=c++11 -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -target-cpu gfx906 -o - | FileCheck %s
+// expected-no-diagnostics
+
+#ifndef HEADER
+#define HEADER
+
+int amdgcn_device_isa_selected() {
+  int threadCount = 0;
+
+#pragma omp target map(tofrom \
+   : threadCount)
+  {
+#pragma omp metadirective \
+when(device = {isa("flat-address-space")} \
+ : parallel) default(single)
+threadCount++;
+  }
+
+  return threadCount;
+}
+
+// CHECK: define weak amdgpu_kernel void @__omp_offloading_{{.*}}amdgcn_device_isa_selected
+// CHECK: user_code.entry:
+// CHECK: call void @__kmpc_parallel_51
+// CHECK-NOT: call i32 @__kmpc_single
+// CHECK: ret void
+
+int amdgcn_device_isa_not_selected() {
+  int threadCount = 0;
+
+#pragma omp target map(tofrom \
+   : threadCount)
+  {
+#pragma omp metadirective  \
+when(device = {isa("sse")} \
+ : parallel)   \
+when(device = {isa("another-unsupported-gpu-feature")} \
+ : parallel) default(single)
+threadCount++;
+  }
+
+  return threadCount;
+}
+// CHECK: define weak amdgpu_kernel void @__omp_offloading_{{.*}}amdgcn_device_isa_not_selected
+// CHECK: user_code.entry:
+// CHECK: call i32 @__kmpc_single
+// CHECK-NOT: call void @__kmpc_parallel_51
+// CHECK: ret void
+
+#endif
Index: clang/test/OpenMP/metadirective_device_isa_codegen.cpp
===
--- /dev/null
+++ clang/test/OpenMP/metadirective_device_isa_codegen.cpp
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -verify -w -fopenmp -x c++ -triple x86_64-unknown-linux -emit-llvm %s -fexceptions -fcxx-exceptions -o - -fsanitize-address-use-after-scope | FileCheck %s
+// expected-no-diagnostics
+
+#ifndef HEADER
+#define HEADER
+
+void bar();
+
+void x86_64_device_isa_selected() {
+#pragma omp metadirective when(device = {isa("sse2")} \
+   : parallel) default(single)
+  bar();
+}
+// CHECK-LABEL: void @_Z26x86_64_device_isa_selectedv()
+// CHECK: ...) @__kmpc_fork_call{{.*}}@.omp_outlined.
+// CHECK: ret void
+
+// CHECK: define internal void @.omp_outlined.(
+// CHECK: @_Z3barv
+// CHECK: ret void
+
+void x86_64_device_isa_not_selected() {
+#pragma omp metadirective when(device = {isa("some-unsupported-feature")} \
+   : parallel) default(single)
+  bar();
+}
+// CHECK-LABEL: void @_Z30x86_64_device_isa_not_selectedv()
+// CHECK: call i32 @__kmpc_single
+// CHECK:  @_Z3barv
+// CHECK: call void @__kmpc_end_single
+// CHECK: ret void
+#endif
Index: clang/lib/Parse/ParseOpenMP.cpp
===
--- clang/lib/Parse/ParseOpenMP.cpp
+++ clang/lib/Parse/ParseOpenMP.cpp

[PATCH] D117009: [AST] Fix the incorrect auto-keyword loc for constrained auto type loc.

2022-01-11 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added a subscriber: carlosgalvezp.
hokein requested review of this revision.
Herald added projects: clang, clang-tools-extra.

E.g.  `Concept auto Func();`

The nameLoc for the constained auto type loc pointed to the concept name
loc, it should be the auto token loc. This patch fixes it, and remove
a relevant hack in clang-tidy check.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117009

Files:
  clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/unittests/AST/SourceLocationTest.cpp


Index: clang/unittests/AST/SourceLocationTest.cpp
===
--- clang/unittests/AST/SourceLocationTest.cpp
+++ clang/unittests/AST/SourceLocationTest.cpp
@@ -247,6 +247,14 @@
   Verifier.expectRange(1, 1, 1, 14);
   EXPECT_TRUE(Verifier.match("decltype(auto) a = 1;", typeLoc(loc(autoType())),
  Lang_CXX14));
+
+  const char *Code =
+  R"cpp(template  concept C = true;
+C auto abc();
+)cpp";
+  // Should include "C auto" tokens.
+  Verifier.expectRange(2, 1, 2, 3); // token range.
+  EXPECT_TRUE(Verifier.match(Code, typeLoc(loc(autoType())), Lang_CXX20));
 }
 
 TEST(TypeLoc, LongDoubleRange) {
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -3582,7 +3582,7 @@
   isInvalid = DS.SetTypeSpecType(TST_decltype_auto, Loc, PrevSpec,
  DiagID, TemplateId, Policy);
 } else {
-  isInvalid = DS.SetTypeSpecType(TST_auto, Loc, PrevSpec, DiagID,
+  isInvalid = DS.SetTypeSpecType(TST_auto, AutoLoc, PrevSpec, DiagID,
  TemplateId, Policy);
 }
 break;
Index: clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
@@ -285,31 +285,6 @@
 return {};
   }
 
-  // If the return type is a constrained 'auto', we need to include the token
-  // after the concept. Unfortunately, the source range of an AutoTypeLoc, if 
it
-  // is constrained, does not include the 'auto'.
-  // FIXME: fix the AutoTypeLoc location in clang.
-  auto ATL = ReturnLoc.getAs();
-  if (ATL && ATL.isConstrained() && !ATL.isDecltypeAuto()) {
-SourceLocation End =
-expandIfMacroId(ReturnLoc.getSourceRange().getEnd(), SM);
-SourceLocation BeginNameF = expandIfMacroId(F.getLocation(), SM);
-
-// Extend the ReturnTypeRange until the last token before the function
-// name.
-std::pair Loc = SM.getDecomposedLoc(End);
-StringRef File = SM.getBufferData(Loc.first);
-const char *TokenBegin = File.data() + Loc.second;
-Lexer Lexer(SM.getLocForStartOfFile(Loc.first), LangOpts, File.begin(),
-TokenBegin, File.end());
-Token T;
-SourceLocation LastTLoc = End;
-while (!Lexer.LexFromRawLexer(T) &&
-   SM.isBeforeInTranslationUnit(T.getLocation(), BeginNameF)) {
-  LastTLoc = T.getLocation();
-}
-ReturnTypeRange.setEnd(LastTLoc);
-  }
 
   // If the return type has no local qualifiers, it's source range is accurate.
   if (!hasAnyNestedLocalQualifiers(F.getReturnType()))


Index: clang/unittests/AST/SourceLocationTest.cpp
===
--- clang/unittests/AST/SourceLocationTest.cpp
+++ clang/unittests/AST/SourceLocationTest.cpp
@@ -247,6 +247,14 @@
   Verifier.expectRange(1, 1, 1, 14);
   EXPECT_TRUE(Verifier.match("decltype(auto) a = 1;", typeLoc(loc(autoType())),
  Lang_CXX14));
+
+  const char *Code =
+  R"cpp(template  concept C = true;
+C auto abc();
+)cpp";
+  // Should include "C auto" tokens.
+  Verifier.expectRange(2, 1, 2, 3); // token range.
+  EXPECT_TRUE(Verifier.match(Code, typeLoc(loc(autoType())), Lang_CXX20));
 }
 
 TEST(TypeLoc, LongDoubleRange) {
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -3582,7 +3582,7 @@
   isInvalid = DS.SetTypeSpecType(TST_decltype_auto, Loc, PrevSpec,
  DiagID, TemplateId, Policy);
 } else {
-  isInvalid = DS.SetTypeSpecType(TST_auto, Loc, PrevSpec, DiagID,
+  isInvalid = DS.SetTypeSpecType(TST_auto, AutoLoc, PrevSpec, DiagID,
  TemplateId, Policy);
 }
 break;
Index: clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
===
--- cl

[clang] acc3987 - [CodeGen] Avoid deprecated Address constructor

2022-01-11 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2022-01-11T13:07:02+01:00
New Revision: acc39873b70eae53a0c32ca5073f08ea55bbab1c

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

LOG: [CodeGen] Avoid deprecated Address constructor

Added: 


Modified: 
clang/lib/CodeGen/CodeGenFunction.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 2d3b214ca424..640c73f1a556 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -2109,6 +2109,7 @@ llvm::Value *CodeGenFunction::emitArrayLength(const 
ArrayType *origArrayType,
 // Create the actual GEP.
 addr = Address(Builder.CreateInBoundsGEP(
 addr.getElementType(), addr.getPointer(), gepIndices, "array.begin"),
+ConvertTypeForMem(eltType),
 addr.getAlignment());
   }
 



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


[PATCH] D115501: [clang][ARM] Emit warnings when PACBTI-M is used with unsupported architectures

2022-01-11 Thread Amilendra Kodithuwakku via Phabricator via cfe-commits
amilendra updated this revision to Diff 398901.
amilendra added a comment.
Herald added subscribers: llvm-commits, dexonsmith.
Herald added a project: LLVM.

Refactor the check conditions to a single function (isArmT32)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115501

Files:
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/ARM.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/arm-branch-protection-attr-2.c
  clang/test/CodeGen/arm_acle.c
  clang/test/Driver/arm-security-options.c
  clang/test/Frontend/arm-branch-protection-default-arch.c
  clang/test/Frontend/arm-ignore-branch-protection-option.c
  clang/test/Frontend/arm-invalid-branch-protection.c
  clang/test/Sema/arm-branch-protection-attr-warn.c
  clang/test/Sema/arm-branch-protection.c
  llvm/include/llvm/ADT/Triple.h

Index: llvm/include/llvm/ADT/Triple.h
===
--- llvm/include/llvm/ADT/Triple.h
+++ llvm/include/llvm/ADT/Triple.h
@@ -721,6 +721,22 @@
isOSBinFormatELF();
   }
 
+  /// Tests whether the target is T32.
+  bool isArmT32() const {
+if (!isARM())
+  return false;
+
+if (getArch() == Triple::aarch64)
+  return true;
+
+if (isThumb())
+  return true;
+
+return (getSubArch() == Triple::ARMSubArch_v8_1m_mainline) ||
+   (getSubArch() == Triple::ARMSubArch_v8m_mainline) ||
+   (getSubArch() == Triple::ARMSubArch_v7m) ||
+   (getSubArch() == Triple::ARMSubArch_v7em);
+  }
   /// Tests whether the target is AArch64 (little and big endian).
   bool isAArch64() const {
 return getArch() == Triple::aarch64 || getArch() == Triple::aarch64_be ||
Index: clang/test/Sema/arm-branch-protection.c
===
--- /dev/null
+++ clang/test/Sema/arm-branch-protection.c
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -triple thumbv6m -verify -fsyntax-only %s
+
+// expected-no-diagnostics
+// Armv8.1-M.Main
+__attribute__((target("arch=cortex-m55,branch-protection=bti"))) void f1() {}
+__attribute__((target("arch=cortex-m55,branch-protection=pac-ret"))) void f2() {}
+__attribute__((target("arch=cortex-m55,branch-protection=bti+pac-ret"))) void f3() {}
+__attribute__((target("arch=cortex-m55,branch-protection=bti+pac-ret+leaf"))) void f4() {}
+// Armv8-M.Main
+__attribute__((target("arch=cortex-m33,branch-protection=bti"))) void f5() {}
+__attribute__((target("arch=cortex-m33,branch-protection=pac-ret"))) void f6() {}
+__attribute__((target("arch=cortex-m33,branch-protection=bti+pac-ret"))) void f7() {}
+__attribute__((target("arch=cortex-m33,branch-protection=bti+pac-ret+leaf"))) void f8() {}
+// Armv7-M
+__attribute__((target("arch=cortex-m3,branch-protection=bti"))) void f9() {}
+__attribute__((target("arch=cortex-m3,branch-protection=pac-ret"))) void f10() {}
+__attribute__((target("arch=cortex-m3,branch-protection=bti+pac-ret"))) void f11() {}
+__attribute__((target("arch=cortex-m3,branch-protection=bti+pac-ret+leaf"))) void f12() {}
+// Armv7E-M
+__attribute__((target("arch=cortex-m4,branch-protection=bti"))) void f13() {}
+__attribute__((target("arch=cortex-m4,branch-protection=pac-ret"))) void f14() {}
+__attribute__((target("arch=cortex-m4,branch-protection=bti+pac-ret"))) void f15() {}
+__attribute__((target("arch=cortex-m4,branch-protection=bti+pac-ret+leaf"))) void f16() {}
Index: clang/test/Sema/arm-branch-protection-attr-warn.c
===
--- /dev/null
+++ clang/test/Sema/arm-branch-protection-attr-warn.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple thumbv6m -verify -fsyntax-only %s
+
+// expected-warning@+1 {{unsupported 'branch-protection' in the 'target' attribute string; 'target' attribute ignored}}
+__attribute__((target("arch=cortex-m0,branch-protection=bti"))) void f1() {}
+
+// expected-warning@+1 {{unsupported 'branch-protection' in the 'target' attribute string; 'target' attribute ignored}}
+__attribute__((target("arch=cortex-m0,branch-protection=pac-ret"))) void f2() {}
+
+// expected-warning@+1 {{unsupported 'branch-protection' in the 'target' attribute string; 'target' attribute ignored}}
+__attribute__((target("arch=cortex-m0,branch-protection=bti+pac-ret"))) void f3() {}
+
+// expected-warning@+1 {{unsupported 'branch-protection' in the 'target' attribute string; 'target' attribute ignored}}
+__attribute__((target("arch=cortex-m0,branch-protection=bti+pac-ret+leaf"))) void f4() {}
Index: clang/test/Frontend/arm-invalid-branch-protection.c
===
--- clang/test/F

[PATCH] D112098: [ASan] Added stack safety support in address sanitizer.

2022-01-11 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp:1534
   } else if (StoreInst *SI = dyn_cast(I)) {
-if (!ClInstrumentWrites || ignoreAccess(SI->getPointerOperand()))
+if (!ClInstrumentWrites || ignoreAccess(LI, SI->getPointerOperand()))
   return;

@kstoimenov You're using the LI pointer for all IgnoreAccess calls which is 
causing nullptr dereference warnings in static analyzer.

Should we just be using I or the dyn_cast<> pointers in each case?

https://llvm.org/reports/scan-build/report-AddressSanitizer.cpp-ignoreAccess-21-f37ec0.html#EndPath


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112098

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


[PATCH] D117012: [clang][dataflow] Add transfer functions data members and this pointers

2022-01-11 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev created this revision.
sgatev added reviewers: ymandel, xazax.hun, gribozavr2.
Herald added a subscriber: rnkovacs.
sgatev requested review of this revision.
Herald added a project: clang.

This is part of the implementation of the dataflow analysis framework.
See "[RFC] A dataflow analysis framework for Clang AST" on cfe-dev.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117012

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/unittests/Analysis/FlowSensitive/TestingSupport.h
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -67,7 +67,7 @@
 TEST_F(TransferTest, IntVarDecl) {
   std::string Code = R"(
 void target() {
-  int foo;
+  int Foo;
   // [[p]]
 }
   )";
@@ -79,7 +79,7 @@
 ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
 const Environment &Env = Results[0].second.Env;
 
-const ValueDecl *FooDecl = findValueDecl(ASTCtx, "foo");
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
 ASSERT_THAT(FooDecl, NotNull());
 
 const StorageLocation *FooLoc =
@@ -93,12 +93,12 @@
 
 TEST_F(TransferTest, StructVarDecl) {
   std::string Code = R"(
-struct Foo {
+struct A {
   int Bar;
 };
 
 void target() {
-  Foo foo;
+  A Foo;
   // [[p]]
 }
   )";
@@ -110,7 +110,7 @@
 ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
 const Environment &Env = Results[0].second.Env;
 
-const ValueDecl *FooDecl = findValueDecl(ASTCtx, "foo");
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
 ASSERT_THAT(FooDecl, NotNull());
 
 ASSERT_TRUE(FooDecl->getType()->isStructureType());
@@ -139,12 +139,12 @@
 
 TEST_F(TransferTest, ClassVarDecl) {
   std::string Code = R"(
-class Foo {
+class A {
   int Bar;
 };
 
 void target() {
-  Foo foo;
+  A Foo;
   // [[p]]
 }
   )";
@@ -156,7 +156,7 @@
 ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
 const Environment &Env = Results[0].second.Env;
 
-const ValueDecl *FooDecl = findValueDecl(ASTCtx, "foo");
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
 ASSERT_THAT(FooDecl, NotNull());
 
 ASSERT_TRUE(FooDecl->getType()->isClassType());
@@ -185,12 +185,12 @@
 
 TEST_F(TransferTest, ReferenceVarDecl) {
   std::string Code = R"(
-struct Foo {};
+struct A {};
 
-Foo& getFoo();
+A &getA();
 
 void target() {
-  Foo& foo = getFoo();
+  A &Foo = getA();
   // [[p]]
 }
   )";
@@ -202,7 +202,7 @@
 ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
 const Environment &Env = Results[0].second.Env;
 
-const ValueDecl *FooDecl = findValueDecl(ASTCtx, "foo");
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
 ASSERT_THAT(FooDecl, NotNull());
 
 const StorageLocation *FooLoc =
@@ -221,25 +221,25 @@
 
 TEST_F(TransferTest, SelfReferentialReferenceVarDecl) {
   std::string Code = R"(
-struct Foo;
+struct A;
 
-struct Baz {};
+struct B {};
 
-struct Bar {
-  Foo& FooRef;
-  Foo* FooPtr;
-  Baz& BazRef;
-  Baz* BazPtr;
+struct C {
+  A &FooRef;
+  A *FooPtr;
+  B &BazRef;
+  B *BazPtr;
 };
 
-struct Foo {
-  Bar& Bar;
+struct A {
+  C &Bar;
 };
 
-Foo& getFoo();
+A &getA();
 
 void target() {
-  Foo& foo = getFoo();
+  A &Foo = getA();
   // [[p]]
 }
   )";
@@ -250,7 +250,7 @@
 ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
 const Environment &Env = Results[0].second.Env;
 
-const ValueDecl *FooDecl = findValueDecl(ASTCtx, "foo");
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
 ASSERT_THAT(FooDecl, NotNull());
 
 ASSERT_TRUE(FooDecl->getType()->isReferenceType());
@@ -330,12 +330,12 @@
 
 TEST_F(TransferTest, PointerVarDecl) {
   std::string Code = R"(
-struct Foo {};
+struct A {};
 
-Foo* getFoo();
+A *getA();
 
 void target() {
-  Foo* foo = getFoo();
+  A *Foo = getA();
   // [[p]]
 }
   )";
@@ -347,7 +347,7 @@
 ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
 const Environment &Env = Results[0].second.Env;
 
-const ValueDecl *FooDecl = findValueDecl(ASTCtx, "foo");
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
 ASSERT_THAT(FooDecl, NotNull());
 
 const StorageLocation *FooLoc =
@@ -365,25 +365,25 @@
 
 TEST_F(TransferTest, SelfReferent

[PATCH] D112906: [PowerPC] Emit warning for ieeelongdouble on older GNU toolchain

2022-01-11 Thread Qiu Chaofan via Phabricator via cfe-commits
qiucf updated this revision to Diff 398906.
qiucf marked 2 inline comments as done.
qiucf edited the summary of this revision.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112906

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/ToolChains/PPCLinux.cpp
  clang/lib/Driver/ToolChains/PPCLinux.h
  
clang/test/Driver/Inputs/powerpc64le-linux-gnu-tree/gcc-11.2.0/lib/gcc/powerpc64le-linux-gnu/11.2.0/.keep
  clang/test/Driver/ppc-float-abi-warning.cpp


Index: clang/test/Driver/ppc-float-abi-warning.cpp
===
--- /dev/null
+++ clang/test/Driver/ppc-float-abi-warning.cpp
@@ -0,0 +1,13 @@
+// REQUIRES: powerpc-registered-target
+// RUN: %clang -### --driver-mode=g++ -target powerpc64le-linux-gnu %s \
+// RUN:  --gcc-toolchain=%S/Inputs/powerpc64le-linux-gnu-tree/gcc-11.2.0 \
+// RUN:  -mabi=ieeelongdouble -stdlib=libstdc++ 2>&1 | FileCheck %s
+// RUN: %clang -### --driver-mode=g++ -target powerpc64le-linux-gnu %s \
+// RUN:  -mabi=ieeelongdouble -stdlib=libc++ 2>&1 | FileCheck %s
+// RUN: %clang -### --driver-mode=g++ -target powerpc64le-linux-gnu %s\
+// RUN:  -mabi=ieeelongdouble -stdlib=libc++ -Wno-unsupported-cxxlib 2>&1 | \
+// RUN:  FileCheck %s --check-prefix=NOWARN
+
+// CHECK: warning: float ABI 'ieeelongdouble' is not supported by current C++ 
stdlib
+// NOWARN-NOT: warning: float ABI 'ieeelongdouble' is not supported by current 
C++ stdlib
+long double foo(long double x) { return x;  }
Index: clang/lib/Driver/ToolChains/PPCLinux.h
===
--- clang/lib/Driver/ToolChains/PPCLinux.h
+++ clang/lib/Driver/ToolChains/PPCLinux.h
@@ -18,8 +18,7 @@
 class LLVM_LIBRARY_VISIBILITY PPCLinuxToolChain : public Linux {
 public:
   PPCLinuxToolChain(const Driver &D, const llvm::Triple &Triple,
-const llvm::opt::ArgList &Args)
-  : Linux(D, Triple, Args) {}
+const llvm::opt::ArgList &Args);
 
   void
   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
Index: clang/lib/Driver/ToolChains/PPCLinux.cpp
===
--- clang/lib/Driver/ToolChains/PPCLinux.cpp
+++ clang/lib/Driver/ToolChains/PPCLinux.cpp
@@ -8,12 +8,28 @@
 
 #include "PPCLinux.h"
 #include "clang/Driver/Driver.h"
+#include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
 #include "llvm/Support/Path.h"
 
 using namespace clang::driver::toolchains;
 using namespace llvm::opt;
 
+PPCLinuxToolChain::PPCLinuxToolChain(const Driver &D,
+ const llvm::Triple &Triple,
+ const llvm::opt::ArgList &Args)
+: Linux(D, Triple, Args) {
+  if (D.CCCIsCXX() && (ToolChain::GetCXXStdlibType(Args) == CST_Libcxx ||
+   GCCInstallation.getVersion().isOlderThan(12, 1, 0))) {
+if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) {
+  StringRef ABIName = A->getValue();
+  if (ABIName != "ibmlongdouble") {
+D.Diag(diag::warn_drv_unsupported_float_abi_by_cxxlib) << ABIName;
+  }
+}
+  }
+}
+
 void PPCLinuxToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
   ArgStringList &CC1Args) 
const {
   if (!DriverArgs.hasArg(clang::driver::options::OPT_nostdinc) &&
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -384,6 +384,9 @@
   "argument '%0' is deprecated, use '%1' instead">, InGroup;
 def warn_drv_assuming_mfloat_abi_is : Warning<
   "unknown platform, assuming -mfloat-abi=%0">;
+def warn_drv_unsupported_float_abi_by_cxxlib : Warning<
+  "float ABI '%0' is not supported by current C++ stdlib">,
+  InGroup>;
 def warn_ignoring_ftabstop_value : Warning<
   "ignoring invalid -ftabstop value '%0', using default value %1">;
 def warn_drv_overriding_flag_option : Warning<


Index: clang/test/Driver/ppc-float-abi-warning.cpp
===
--- /dev/null
+++ clang/test/Driver/ppc-float-abi-warning.cpp
@@ -0,0 +1,13 @@
+// REQUIRES: powerpc-registered-target
+// RUN: %clang -### --driver-mode=g++ -target powerpc64le-linux-gnu %s \
+// RUN:  --gcc-toolchain=%S/Inputs/powerpc64le-linux-gnu-tree/gcc-11.2.0 \
+// RUN:  -mabi=ieeelongdouble -stdlib=libstdc++ 2>&1 | FileCheck %s
+// RUN: %clang -### --driver-mode=g++ -target powerpc64le-linux-gnu %s \
+// RUN:  -mabi=ieeelongdouble -stdlib=libc++ 2>&1 | FileCheck %s
+// RUN: %clang -### --driver-mode=g++ -target powerpc64le-linux-gnu %s\
+// RUN:  -mabi=ieeelongdouble -stdlib=libc++ -Wno-unsupported-cxxlib 2>&1 | \
+// RUN:  FileCheck %s --check-prefix=NOWARN
+
+// 

[PATCH] D117012: [clang][dataflow] Add transfer functions data members and this pointers

2022-01-11 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev updated this revision to Diff 398907.
sgatev added a comment.

Add missing include.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117012

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/unittests/Analysis/FlowSensitive/TestingSupport.h
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -67,7 +67,7 @@
 TEST_F(TransferTest, IntVarDecl) {
   std::string Code = R"(
 void target() {
-  int foo;
+  int Foo;
   // [[p]]
 }
   )";
@@ -79,7 +79,7 @@
 ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
 const Environment &Env = Results[0].second.Env;
 
-const ValueDecl *FooDecl = findValueDecl(ASTCtx, "foo");
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
 ASSERT_THAT(FooDecl, NotNull());
 
 const StorageLocation *FooLoc =
@@ -93,12 +93,12 @@
 
 TEST_F(TransferTest, StructVarDecl) {
   std::string Code = R"(
-struct Foo {
+struct A {
   int Bar;
 };
 
 void target() {
-  Foo foo;
+  A Foo;
   // [[p]]
 }
   )";
@@ -110,7 +110,7 @@
 ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
 const Environment &Env = Results[0].second.Env;
 
-const ValueDecl *FooDecl = findValueDecl(ASTCtx, "foo");
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
 ASSERT_THAT(FooDecl, NotNull());
 
 ASSERT_TRUE(FooDecl->getType()->isStructureType());
@@ -139,12 +139,12 @@
 
 TEST_F(TransferTest, ClassVarDecl) {
   std::string Code = R"(
-class Foo {
+class A {
   int Bar;
 };
 
 void target() {
-  Foo foo;
+  A Foo;
   // [[p]]
 }
   )";
@@ -156,7 +156,7 @@
 ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
 const Environment &Env = Results[0].second.Env;
 
-const ValueDecl *FooDecl = findValueDecl(ASTCtx, "foo");
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
 ASSERT_THAT(FooDecl, NotNull());
 
 ASSERT_TRUE(FooDecl->getType()->isClassType());
@@ -185,12 +185,12 @@
 
 TEST_F(TransferTest, ReferenceVarDecl) {
   std::string Code = R"(
-struct Foo {};
+struct A {};
 
-Foo& getFoo();
+A &getA();
 
 void target() {
-  Foo& foo = getFoo();
+  A &Foo = getA();
   // [[p]]
 }
   )";
@@ -202,7 +202,7 @@
 ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
 const Environment &Env = Results[0].second.Env;
 
-const ValueDecl *FooDecl = findValueDecl(ASTCtx, "foo");
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
 ASSERT_THAT(FooDecl, NotNull());
 
 const StorageLocation *FooLoc =
@@ -221,25 +221,25 @@
 
 TEST_F(TransferTest, SelfReferentialReferenceVarDecl) {
   std::string Code = R"(
-struct Foo;
+struct A;
 
-struct Baz {};
+struct B {};
 
-struct Bar {
-  Foo& FooRef;
-  Foo* FooPtr;
-  Baz& BazRef;
-  Baz* BazPtr;
+struct C {
+  A &FooRef;
+  A *FooPtr;
+  B &BazRef;
+  B *BazPtr;
 };
 
-struct Foo {
-  Bar& Bar;
+struct A {
+  C &Bar;
 };
 
-Foo& getFoo();
+A &getA();
 
 void target() {
-  Foo& foo = getFoo();
+  A &Foo = getA();
   // [[p]]
 }
   )";
@@ -250,7 +250,7 @@
 ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
 const Environment &Env = Results[0].second.Env;
 
-const ValueDecl *FooDecl = findValueDecl(ASTCtx, "foo");
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
 ASSERT_THAT(FooDecl, NotNull());
 
 ASSERT_TRUE(FooDecl->getType()->isReferenceType());
@@ -330,12 +330,12 @@
 
 TEST_F(TransferTest, PointerVarDecl) {
   std::string Code = R"(
-struct Foo {};
+struct A {};
 
-Foo* getFoo();
+A *getA();
 
 void target() {
-  Foo* foo = getFoo();
+  A *Foo = getA();
   // [[p]]
 }
   )";
@@ -347,7 +347,7 @@
 ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
 const Environment &Env = Results[0].second.Env;
 
-const ValueDecl *FooDecl = findValueDecl(ASTCtx, "foo");
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
 ASSERT_THAT(FooDecl, NotNull());
 
 const StorageLocation *FooLoc =
@@ -365,25 +365,25 @@
 
 TEST_F(TransferTest, SelfReferentialPointerVarDecl) {
   std::string Code = R"(
-struct Foo;
+struct A;
 
-struct Baz {};
+struct B {};
 
-struct Bar {
-  Foo& FooRef;
-  Foo* FooPtr;

[clang] fda47db - [Clang][Sema] Fix attribute mismatch warning for ObjC class properties

2022-01-11 Thread Egor Zhdan via cfe-commits

Author: Egor Zhdan
Date: 2022-01-11T12:10:18Z
New Revision: fda47db8ee1d3eca8c42819cf1b65ab0ef7df7b8

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

LOG: [Clang][Sema] Fix attribute mismatch warning for ObjC class properties

If a class declares an instance property, and an inheritor class declares a 
class property with the same name, Clang Sema currently treats the latter as an 
overridden property, and compares the attributes of the two properties to check 
for a mismatch. The resulting diagnostics might be misleading, since neither of 
the properties actually overrides the another one.

rdar://86018435

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

Added: 
clang/test/SemaObjC/class-property-inheritance.m

Modified: 
clang/include/clang/AST/DeclObjC.h
clang/lib/AST/DeclObjC.cpp
clang/lib/Sema/SemaObjCProperty.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclObjC.h 
b/clang/include/clang/AST/DeclObjC.h
index f227561b8fcb..110b7dc0c6f2 100644
--- a/clang/include/clang/AST/DeclObjC.h
+++ b/clang/include/clang/AST/DeclObjC.h
@@ -1071,6 +1071,9 @@ class ObjCContainerDecl : public NamedDecl, public 
DeclContext {
   bool HasUserDeclaredSetterMethod(const ObjCPropertyDecl *P) const;
   ObjCIvarDecl *getIvarDecl(IdentifierInfo *Id) const;
 
+  ObjCPropertyDecl *getProperty(const IdentifierInfo *Id,
+bool IsInstance) const;
+
   ObjCPropertyDecl *
   FindPropertyDeclaration(const IdentifierInfo *PropertyId,
   ObjCPropertyQueryKind QueryKind) const;

diff  --git a/clang/lib/AST/DeclObjC.cpp b/clang/lib/AST/DeclObjC.cpp
index ba827a79c022..f15dd78929e2 100644
--- a/clang/lib/AST/DeclObjC.cpp
+++ b/clang/lib/AST/DeclObjC.cpp
@@ -232,6 +232,18 @@ ObjCPropertyDecl::getDefaultSynthIvarName(ASTContext &Ctx) 
const {
   return &Ctx.Idents.get(ivarName.str());
 }
 
+ObjCPropertyDecl *ObjCContainerDecl::getProperty(const IdentifierInfo *Id,
+ bool IsInstance) const {
+  for (auto *LookupResult : lookup(Id)) {
+if (auto *Prop = dyn_cast(LookupResult)) {
+  if (Prop->isInstanceProperty() == IsInstance) {
+return Prop;
+  }
+}
+  }
+  return nullptr;
+}
+
 /// FindPropertyDeclaration - Finds declaration of the property given its name
 /// in 'PropertyId' and returns it. It returns 0, if not found.
 ObjCPropertyDecl *ObjCContainerDecl::FindPropertyDeclaration(

diff  --git a/clang/lib/Sema/SemaObjCProperty.cpp 
b/clang/lib/Sema/SemaObjCProperty.cpp
index 74c73ace3c5f..118afb81dd72 100644
--- a/clang/lib/Sema/SemaObjCProperty.cpp
+++ b/clang/lib/Sema/SemaObjCProperty.cpp
@@ -112,8 +112,8 @@ CheckPropertyAgainstProtocol(Sema &S, ObjCPropertyDecl 
*Prop,
 return;
 
   // Look for a property with the same name.
-  if (ObjCPropertyDecl *ProtoProp =
-  Proto->lookup(Prop->getDeclName()).find_first()) {
+  if (ObjCPropertyDecl *ProtoProp = Proto->getProperty(
+  Prop->getIdentifier(), Prop->isInstanceProperty())) {
 S.DiagnosePropertyMismatch(Prop, ProtoProp, Proto->getIdentifier(), true);
 return;
   }
@@ -231,8 +231,8 @@ Decl *Sema::ActOnProperty(Scope *S, SourceLocation AtLoc,
 bool FoundInSuper = false;
 ObjCInterfaceDecl *CurrentInterfaceDecl = IFace;
 while (ObjCInterfaceDecl *Super = CurrentInterfaceDecl->getSuperClass()) {
-  if (ObjCPropertyDecl *SuperProp =
-  Super->lookup(Res->getDeclName()).find_first()) {
+  if (ObjCPropertyDecl *SuperProp = Super->getProperty(
+  Res->getIdentifier(), Res->isInstanceProperty())) {
 DiagnosePropertyMismatch(Res, SuperProp, Super->getIdentifier(), 
false);
 FoundInSuper = true;
 break;

diff  --git a/clang/test/SemaObjC/class-property-inheritance.m 
b/clang/test/SemaObjC/class-property-inheritance.m
new file mode 100644
index ..9d8a4fe44053
--- /dev/null
+++ b/clang/test/SemaObjC/class-property-inheritance.m
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+@class MyObject;
+
+
+@interface TopClassWithClassProperty0
+@property(nullable, readonly, strong, class) MyObject *foo;
+@end
+
+@interface SubClassWithClassProperty0 : TopClassWithClassProperty0
+@property(nonnull, readonly, copy, class) MyObject *foo; // expected-warning 
{{'copy' attribute on property 'foo' does not match the property inherited from 
'TopClassWithClassProperty0'}}
+@end
+
+
+
+@interface TopClassWithInstanceProperty1
+@property(nullable, readonly, strong) MyObject *foo;
+@end
+
+@interface ClassWithClassProperty1 : TopClassWithInstanceProperty1
+@property(nonnull, readonly, copy, class) MyObject *foo; // no-warning
+@end
+
+@interface SubClassWithInstanceProperty1 : ClassWithClassProperty1
+@property(nullable, re

[PATCH] D116412: [Clang][Sema] Fix attribute mismatch warning for ObjC class properties

2022-01-11 Thread Egor Zhdan 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 rGfda47db8ee1d: [Clang][Sema] Fix attribute mismatch warning 
for ObjC class properties (authored by egorzhdan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116412

Files:
  clang/include/clang/AST/DeclObjC.h
  clang/lib/AST/DeclObjC.cpp
  clang/lib/Sema/SemaObjCProperty.cpp
  clang/test/SemaObjC/class-property-inheritance.m

Index: clang/test/SemaObjC/class-property-inheritance.m
===
--- /dev/null
+++ clang/test/SemaObjC/class-property-inheritance.m
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+@class MyObject;
+
+
+@interface TopClassWithClassProperty0
+@property(nullable, readonly, strong, class) MyObject *foo;
+@end
+
+@interface SubClassWithClassProperty0 : TopClassWithClassProperty0
+@property(nonnull, readonly, copy, class) MyObject *foo; // expected-warning {{'copy' attribute on property 'foo' does not match the property inherited from 'TopClassWithClassProperty0'}}
+@end
+
+
+
+@interface TopClassWithInstanceProperty1
+@property(nullable, readonly, strong) MyObject *foo;
+@end
+
+@interface ClassWithClassProperty1 : TopClassWithInstanceProperty1
+@property(nonnull, readonly, copy, class) MyObject *foo; // no-warning
+@end
+
+@interface SubClassWithInstanceProperty1 : ClassWithClassProperty1
+@property(nullable, readonly, copy) MyObject *foo; // expected-warning {{'copy' attribute on property 'foo' does not match the property inherited from 'TopClassWithInstanceProperty1'}}
+@end
+
+
+@interface TopClassWithClassProperty2
+@property(nullable, readonly, strong, class) MyObject *foo;
+@end
+
+@interface ClassWithInstanceProperty2 : TopClassWithClassProperty2
+@property(nonnull, readonly, copy) MyObject *foo; // no-warning
+@end
+
+@interface SubClassWithClassProperty2 : ClassWithInstanceProperty2
+@property(nonnull, readonly, copy, class) MyObject *foo; // expected-warning {{'copy' attribute on property 'foo' does not match the property inherited from 'TopClassWithClassProperty2'}}
+@end
Index: clang/lib/Sema/SemaObjCProperty.cpp
===
--- clang/lib/Sema/SemaObjCProperty.cpp
+++ clang/lib/Sema/SemaObjCProperty.cpp
@@ -112,8 +112,8 @@
 return;
 
   // Look for a property with the same name.
-  if (ObjCPropertyDecl *ProtoProp =
-  Proto->lookup(Prop->getDeclName()).find_first()) {
+  if (ObjCPropertyDecl *ProtoProp = Proto->getProperty(
+  Prop->getIdentifier(), Prop->isInstanceProperty())) {
 S.DiagnosePropertyMismatch(Prop, ProtoProp, Proto->getIdentifier(), true);
 return;
   }
@@ -231,8 +231,8 @@
 bool FoundInSuper = false;
 ObjCInterfaceDecl *CurrentInterfaceDecl = IFace;
 while (ObjCInterfaceDecl *Super = CurrentInterfaceDecl->getSuperClass()) {
-  if (ObjCPropertyDecl *SuperProp =
-  Super->lookup(Res->getDeclName()).find_first()) {
+  if (ObjCPropertyDecl *SuperProp = Super->getProperty(
+  Res->getIdentifier(), Res->isInstanceProperty())) {
 DiagnosePropertyMismatch(Res, SuperProp, Super->getIdentifier(), false);
 FoundInSuper = true;
 break;
Index: clang/lib/AST/DeclObjC.cpp
===
--- clang/lib/AST/DeclObjC.cpp
+++ clang/lib/AST/DeclObjC.cpp
@@ -232,6 +232,18 @@
   return &Ctx.Idents.get(ivarName.str());
 }
 
+ObjCPropertyDecl *ObjCContainerDecl::getProperty(const IdentifierInfo *Id,
+ bool IsInstance) const {
+  for (auto *LookupResult : lookup(Id)) {
+if (auto *Prop = dyn_cast(LookupResult)) {
+  if (Prop->isInstanceProperty() == IsInstance) {
+return Prop;
+  }
+}
+  }
+  return nullptr;
+}
+
 /// FindPropertyDeclaration - Finds declaration of the property given its name
 /// in 'PropertyId' and returns it. It returns 0, if not found.
 ObjCPropertyDecl *ObjCContainerDecl::FindPropertyDeclaration(
Index: clang/include/clang/AST/DeclObjC.h
===
--- clang/include/clang/AST/DeclObjC.h
+++ clang/include/clang/AST/DeclObjC.h
@@ -1071,6 +1071,9 @@
   bool HasUserDeclaredSetterMethod(const ObjCPropertyDecl *P) const;
   ObjCIvarDecl *getIvarDecl(IdentifierInfo *Id) const;
 
+  ObjCPropertyDecl *getProperty(const IdentifierInfo *Id,
+bool IsInstance) const;
+
   ObjCPropertyDecl *
   FindPropertyDeclaration(const IdentifierInfo *PropertyId,
   ObjCPropertyQueryKind QueryKind) const;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116778: [clang-tidy][clang] Don't trigger unused-parameter warnings on naked functions

2022-01-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thanks for the fix! Can you be sure to add test coverage for both clang-tidy 
and Clang to demonstrate the behavior change?




Comment at: clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp:35
   Finder->addMatcher(
   functionDecl(isDefinition(), hasBody(stmt()), hasAnyParameter(decl()))
   .bind("function"),

Something along these lines should work instead (you'll have to reformat 
though).



Comment at: clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp:177-180
+  if (Function->hasAttrs())
+for (const clang::Attr *A : Function->getAttrs())
+  if (A->getParsedKind() == Attr::AT_Naked)
+return;

I think this should be done using matchers instead of from `check()` if 
possible so that we get better memoization. See comment above.



Comment at: clang/lib/Sema/SemaDecl.cpp:14635-14645
+bool FDHasNakedAttr{false};
+if (FD->hasAttrs())
+  for (const clang::Attr *A : FD->getAttrs())
+if (A->getParsedKind() == Attr::AT_Naked) {
+  FDHasNakedAttr = true;
+  break;
+}




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116778

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


[clang] 0c7f515 - Revert "[Clang][AArch64][ARM] PMUv3.4 Option Added"

2022-01-11 Thread David Green via cfe-commits

Author: David Green
Date: 2022-01-11T12:33:53Z
New Revision: 0c7f515f88fca39458f3b3fd9db188e48db0a7e4

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

LOG: Revert "[Clang][AArch64][ARM] PMUv3.4 Option Added"

It turns out this is conflating a few different PMU extensions. And on
Arm ended up breaking M-Profile code generation. Reverting for the
moment whilst we sort out the details.

This reverts commit d17fb46e894501568a1bf3b11a5d920817444630.

Added: 


Modified: 
llvm/include/llvm/Support/AArch64TargetParser.def
llvm/include/llvm/Support/AArch64TargetParser.h
llvm/include/llvm/Support/ARMTargetParser.def
llvm/include/llvm/Support/ARMTargetParser.h
llvm/lib/Support/AArch64TargetParser.cpp
llvm/unittests/Support/TargetParserTest.cpp

Removed: 
clang/test/Driver/aarch64-perfmon.c
clang/test/Driver/arm-perfmon.c



diff  --git a/clang/test/Driver/aarch64-perfmon.c 
b/clang/test/Driver/aarch64-perfmon.c
deleted file mode 100644
index 228e6d6f3f15..
--- a/clang/test/Driver/aarch64-perfmon.c
+++ /dev/null
@@ -1,13 +0,0 @@
-// RUN: %clang -### -target aarch64-none-none-eabi -march=armv8.4a+pmuv3p4 %s 
2>&1 | FileCheck --check-prefix=CHECK-PERFMON %s
-// RUN: %clang -### -target aarch64-none-none-eabi -march=armv8.2a+pmuv3p4 %s 
2>&1 | FileCheck --check-prefix=CHECK-PERFMON %s
-// CHECK-PERFMON: "-target-feature" "+perfmon"
-
-// RUN: %clang -### -target aarch64-none-none-eabi -march=armv8.4a+nopmuv3p4 
%s 2>&1 | FileCheck --check-prefix=CHECK-NOPERFMON %s
-// RUN: %clang -### -target aarch64-none-none-eabi -march=armv8.2a+nopmuv3p4 
%s 2>&1 | FileCheck --check-prefix=CHECK-NOPERFMON %s
-// CHECK-NOPERFMON: "-target-feature" "-perfmon"
-
-// RUN: %clang -### -target aarch64-none-none-eabi %s 2>&1 | 
FileCheck %s --check-prefix=ABSENTPERFMON
-// RUN: %clang -### -target aarch64-none-none-eabi -march=armv8.4a %s 2>&1 | 
FileCheck %s --check-prefix=ABSENTPERFMON
-// RUN: %clang -### -target aarch64-none-none-eabi -march=armv8.2a %s 2>&1 | 
FileCheck %s --check-prefix=ABSENTPERFMON
-// ABSENTPERFMON-NOT: "-target-feature" "+perfmon"
-// ABSENTPERFMON-NOT: "-target-feature" "-perfmon"
\ No newline at end of file

diff  --git a/clang/test/Driver/arm-perfmon.c b/clang/test/Driver/arm-perfmon.c
deleted file mode 100644
index 618bd9804469..
--- a/clang/test/Driver/arm-perfmon.c
+++ /dev/null
@@ -1,13 +0,0 @@
-// RUN: %clang -### -target arm-none-none-eabi -march=armv8.4a+pmuv3p4 %s 2>&1 
| FileCheck --check-prefix=CHECK-PERFMON %s
-// RUN: %clang -### -target arm-none-none-eabi -march=armv8.2a+pmuv3p4 %s 2>&1 
| FileCheck --check-prefix=CHECK-PERFMON %s
-// CHECK-PERFMON: "-target-feature" "+perfmon"
-
-// RUN: %clang -### -target arm-none-none-eabi -march=armv8.4a+nopmuv3p4 %s 
2>&1 | FileCheck --check-prefix=CHECK-NOPERFMON %s
-// RUN: %clang -### -target arm-none-none-eabi -march=armv8.2a+nopmuv3p4 %s 
2>&1 | FileCheck --check-prefix=CHECK-NOPERFMON %s
-// CHECK-NOPERFMON: "-target-feature" "-perfmon"
-
-// RUN: %clang -### -target arm-none-none-eabi %s 2>&1 | 
FileCheck %s --check-prefix=ABSENTPERFMON
-// RUN: %clang -### -target arm-none-none-eabi -march=armv8.4a %s 2>&1 | 
FileCheck %s --check-prefix=ABSENTPERFMON
-// RUN: %clang -### -target arm-none-none-eabi -march=armv8.2a %s 2>&1 | 
FileCheck %s --check-prefix=ABSENTPERFMON
-// ABSENTPERFMON-NOT: "-target-feature" "+perfmon"
-// ABSENTPERFMON-NOT: "-target-feature" "-perfmon"
\ No newline at end of file

diff  --git a/llvm/include/llvm/Support/AArch64TargetParser.def 
b/llvm/include/llvm/Support/AArch64TargetParser.def
index 6619864e7ca1..9d45f6abae6b 100644
--- a/llvm/include/llvm/Support/AArch64TargetParser.def
+++ b/llvm/include/llvm/Support/AArch64TargetParser.def
@@ -144,7 +144,6 @@ AARCH64_ARCH_EXT_NAME("flagm",AArch64::AEK_FLAGM,   
"+flagm", "-flag
 AARCH64_ARCH_EXT_NAME("sme",  AArch64::AEK_SME, "+sme",   
"-sme")
 AARCH64_ARCH_EXT_NAME("sme-f64",  AArch64::AEK_SMEF64,  "+sme-f64", 
"-sme-f64")
 AARCH64_ARCH_EXT_NAME("sme-i64",  AArch64::AEK_SMEI64,  "+sme-i64", 
"-sme-i64")
-AARCH64_ARCH_EXT_NAME("pmuv3p4",  AArch64::AEK_PERFMON, "+perfmon", 
"-perfmon")
 #undef AARCH64_ARCH_EXT_NAME
 
 #ifndef AARCH64_CPU_NAME

diff  --git a/llvm/include/llvm/Support/AArch64TargetParser.h 
b/llvm/include/llvm/Support/AArch64TargetParser.h
index 06aad515c8bd..15bb428f19bc 100644
--- a/llvm/include/llvm/Support/AArch64TargetParser.h
+++ b/llvm/include/llvm/Support/AArch64TargetParser.h
@@ -69,7 +69,6 @@ enum ArchExtKind : uint64_t {
   AEK_SME = 1ULL << 37,
   AEK_SMEF64 =  1ULL << 38,
   AEK_SMEI64 =  1ULL << 39,
-  AEK_PERFMON = 1ULL << 40,
 };
 
 enum class ArchKind {

diff  --git a/llv

[PATCH] D116518: [ast-matchers] Add hasSubstatementSequence matcher

2022-01-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a subscriber: ymandel.
aaron.ballman added inline comments.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:5435-5442
+/// Matches two consecutive statements within a compound statement.
+///
+/// Given
+/// \code
+///   { if (x > 0) return true; return false; }
+/// \endcode
+/// compoundStmt(hasSubstatementSequence(ifStmt(), returnStmt()))

LegalizeAdulthood wrote:
> LegalizeAdulthood wrote:
> > aaron.ballman wrote:
> > > LegalizeAdulthood wrote:
> > > > aaron.ballman wrote:
> > > > > LegalizeAdulthood wrote:
> > > > > > aaron.ballman wrote:
> > > > > > > How do we extend this to support testing arbitrary sequences of 
> > > > > > > statements? (If this supports two statements, someone will find a 
> > > > > > > need for three, etc).
> > > > > > Yeah, I was wondering that too.  I didn't see (but didn't look 
> > > > > > extensively) any support for variadic matchers taking a parameter 
> > > > > > pack.
> > > > > > 
> > > > > > I stopped at 2 because this suits my immediate needs with 
> > > > > > `readability-simplify-boolean-expr` where I have to manually loop 
> > > > > > over `CompoundStmt` matches in order to verify that the `if (x) 
> > > > > > return true; return false;` constructs consist of two adjacent 
> > > > > > statements.
> > > > > I don't think we have any variadic matchers yet to model on, but I 
> > > > > think if this is only needed for one check, we can add it in the 
> > > > > current form as a local matcher for that check. Whenever we figure 
> > > > > out how to give the better interface through the static and dynamic 
> > > > > matchers, then we can figure out how to lift this to the general 
> > > > > matcher interface.
> > > > > 
> > > > > WDYT?
> > > > I don't think it is harmful to make it visible to all and I think it is 
> > > > helpful.
> > > > Defining it in ASTMatchers, enables using it in `clang-query`, for 
> > > > instance.
> > > > 
> > > I contend this is not a generally useful matcher without supporting an 
> > > arbitrary number of statements. Even then, to be honest, it's 
> > > questionable whether there's sufficient need for this to be a public 
> > > matcher. Typically, we don't expose a new public matcher unless there's a 
> > > general need for it, and this one is already pretty borderline even if 
> > > it's fully generalized. This file is *very* expensive to instantiate and 
> > > it gets used in a lot of places, so that's one of the primary reasons we 
> > > don't expose matchers from here unless they're generally useful.
> > > 
> > > Unless @klimek or another AST matcher code owner thinks this is useful in 
> > > general (to multiple checks people are likely to want to write even if 
> > > they're not contributing the checks to the community), I'm opposed to 
> > > exposing this as-is. However, adding it as a private matcher for the 
> > > check that needs the limited functionality would get no opposition from 
> > > me (and this implementation looks correct as well).
> > My thoughts:
> > 
> > I'm OK with moving it as a private matcher as it would simplify a big chunk 
> > of code
> > in the simplify-boolean-expr check.
> > 
> > I agree that ASTMatchers.h is used all over the place and at a minimum 
> > causes a
> > huge amount of rebuild.
> > 
> > Regarding the general usefulness of the matcher, let me elaborate on my 
> > motivation
> > for adding this matcher.
> > 
> > I see it from the viewpoint of a developer of checks/refactorings.
> > 
> > I really want us to get to a world where a complete refactoring can be 
> > specified as
> > a script input to a refactoring tool.  Eliminating the need to write C++ 
> > that directly
> > manipulates the AST and the edits will lower the bar for entry for other 
> > people
> > writing automated changes to their codebases.
> > 
> > Since the last time I worked in the clang codebase, the transformer library 
> > has
> > been added.  With this new library, I think all we're missing is a parser 
> > that matches
> > the input script to the necessary calls to code in the transformer library. 
> >  Once we
> > do this, I think the need for more and higher-level matchers will become 
> > evident
> > and a matcher like this is the only way you can specify that a statement Y
> > immediately follows statement X purely through matchers.  Current matchers
> > don't even let you specify relative ordering of statements.  The best you 
> > can do
> > is assert that a block contains the statements of interest and then you 
> > must write
> > your own C++ code to walk the block and determine if they fit your actual
> > match criteria.
> Also, regarding a variadic version of this matcher, I'd be curious to try it 
> out
> just from a learning/programming perspective, but I'm not sure how I'd go 
> about
> it.  Suggestions on a plan of attack would be most welcome! `:)`
> 
> I'm OK with moving it as a private matcher as it would simplify a big chunk 
> of code in the s

[PATCH] D116814: [clang-tidy] Accept string literal decay in conditional operator

2022-01-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116814

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


[clang] dbb8d08 - [SPIR-V] Add linking using spirv-link.

2022-01-11 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2022-01-11T13:11:38Z
New Revision: dbb8d086377ba3a81e44c471840bdbd982c00a35

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

LOG: [SPIR-V] Add linking using spirv-link.

Add support of linking files compiled into SPIR-V objects
using spirv-link.

Command line inteface examples:

clang --target=spirv64 test1.cl test2.cl

clang  --target=spirv64 test1.cl -o test1.o
clang  --target=spirv64 test1.o test2.cl -o test_app.out

This works independently from the SPIR-V generation method
(via an external tool or an internal backend) and applies
to either approach that is being used.

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

Added: 


Modified: 
clang/docs/UsersManual.rst
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChains/SPIRV.cpp
clang/lib/Driver/ToolChains/SPIRV.h
clang/test/Driver/spirv-toolchain.cl

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 5f46322f19af2..bdb9705dac637 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -3599,6 +3599,13 @@ Converting to SPIR-V produced with the optimization 
levels other than `-O0` is
 currently available as an experimental feature and it is not guaranteed to work
 in all cases.
 
+Linking is done using ``spirv-link`` from `the SPIRV-Tools project
+`_. Similar to other 
external
+linkers, Clang will expect ``spirv-link`` to be installed separately and to be
+present in the ``PATH`` environment variable. Please refer to `the build and
+installation instructions
+`_.
+
 .. _clang-cl:
 
 clang-cl

diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index a7fd2f26478cf..3ea32a8876c91 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -116,10 +116,6 @@ def warn_drv_unsupported_option_for_target : Warning<
   "ignoring '%0' option as it is not currently supported for target '%1'">,
   InGroup;
 
-def warn_drv_spirv_linking_multiple_inputs_unsupported: Warning<
-  "Linking multiple input files is not supported for SPIR-V yet">,
-  InGroup;
-
 def err_drv_invalid_thread_model_for_target : Error<
   "invalid thread model '%0' in '%1' for this target">;
 def err_drv_invalid_linker_name : Error<

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 2c3b137554c0b..82d67a8b8b1ab 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -3804,14 +3804,6 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
 }
   }
 
-  // FIXME: Linking separate translation units for SPIR-V is not supported yet.
-  // It can be done either by LLVM IR linking before conversion of the final
-  // linked module to SPIR-V or external SPIR-V linkers can be used e.g.
-  // spirv-link.
-  if (C.getDefaultToolChain().getTriple().isSPIRV() && Inputs.size() > 1) {
-Diag(clang::diag::warn_drv_spirv_linking_multiple_inputs_unsupported);
-  }
-
   handleArguments(C, Args, Inputs, Actions);
 
   // Builder to be used to build offloading actions.
@@ -3851,15 +3843,8 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
   // Queue linker inputs.
   if (Phase == phases::Link) {
 assert(Phase == PL.back() && "linking must be final compilation 
step.");
-// Compilation phases are setup per language, however for SPIR-V the
-// final linking phase is meaningless since the compilation phase
-// produces the final binary.
-// FIXME: OpenCL - we could strip linking phase out from OpenCL
-// compilation phases if we could verify it is not needed by any 
target.
-if (!C.getDefaultToolChain().getTriple().isSPIRV()) {
-  LinkerInputs.push_back(Current);
-  Current = nullptr;
-}
+LinkerInputs.push_back(Current);
+Current = nullptr;
 break;
   }
 

diff  --git a/clang/lib/Driver/ToolChains/SPIRV.cpp 
b/clang/lib/Driver/ToolChains/SPIRV.cpp
index 50d03e79bbb08..ce6ce5e8998e5 100644
--- a/clang/lib/Driver/ToolChains/SPIRV.cpp
+++ b/clang/lib/Driver/ToolChains/SPIRV.cpp
@@ -70,3 +70,25 @@ clang::driver::Tool 
*SPIRVToolChain::getTool(Action::ActionClass AC) const {
   }
   return ToolChain::getTool(AC);
 }
+clang::driver::Tool *SPIRVToolChain::buildLinker() const {
+  return new tools::SPIRV::Linker(*this);
+}
+
+void SPIRV::Linker::ConstructJob(Compilation &C, const JobAction &JA,
+ const InputInfo &Output,
+ const InputInf

[PATCH] D116266: [SPIR-V] Add linking of separate translation units using spirv-link

2022-01-11 Thread Anastasia Stulova 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 rGdbb8d086377b: [SPIR-V] Add linking using spirv-link. 
(authored by Anastasia).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D116266?vs=396152&id=398914#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116266

Files:
  clang/docs/UsersManual.rst
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/SPIRV.cpp
  clang/lib/Driver/ToolChains/SPIRV.h
  clang/test/Driver/spirv-toolchain.cl

Index: clang/test/Driver/spirv-toolchain.cl
===
--- clang/test/Driver/spirv-toolchain.cl
+++ clang/test/Driver/spirv-toolchain.cl
@@ -59,7 +59,13 @@
 // TMP: {{llvm-spirv.*"}} [[S]] "-to-binary" "-o" {{".*o"}}
 
 //-
-// Check that warning occurs if multiple input files are passed.
-// RUN: %clang -### --target=spirv64 %s %s 2>&1 | FileCheck --check-prefix=WARN %s
+// Check linking when multiple input files are passed.
+// RUN: %clang -### -target spirv64 %s %s 2>&1 | FileCheck --check-prefix=SPLINK %s
 
-// WARN: warning: Linking multiple input files is not supported for SPIR-V yet
+// SPLINK: clang{{.*}} "-cc1" "-triple" "spirv64"
+// SPLINK-SAME: "-o" [[BC:".*bc"]]
+// SPLINK: {{llvm-spirv.*"}} [[BC]] "-o" [[SPV1:".*o"]]
+// SPLINK: clang{{.*}} "-cc1" "-triple" "spirv64"
+// SPLINK-SAME: "-o" [[BC:".*bc"]]
+// SPLINK: {{llvm-spirv.*"}} [[BC]] "-o" [[SPV2:".*o"]]
+// SPLINK: {{"spirv-link.*"}} [[SPV1]] [[SPV2]] "-o" "a.out"
Index: clang/lib/Driver/ToolChains/SPIRV.h
===
--- clang/lib/Driver/ToolChains/SPIRV.h
+++ clang/lib/Driver/ToolChains/SPIRV.h
@@ -39,6 +39,17 @@
 const char *LinkingOutput) const override;
 };
 
+class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
+public:
+  Linker(const ToolChain &TC) : Tool("SPIRV::Linker", "spirv-link", TC) {}
+  bool hasIntegratedCPP() const override { return false; }
+  bool isLinkJob() const override { return true; }
+  void ConstructJob(Compilation &C, const JobAction &JA,
+const InputInfo &Output, const InputInfoList &Inputs,
+const llvm::opt::ArgList &TCArgs,
+const char *LinkingOutput) const override;
+};
+
 } // namespace SPIRV
 } // namespace tools
 
@@ -68,6 +79,7 @@
 
 protected:
   clang::driver::Tool *getTool(Action::ActionClass AC) const override;
+  Tool *buildLinker() const override;
 
 private:
   clang::driver::Tool *getTranslator() const;
Index: clang/lib/Driver/ToolChains/SPIRV.cpp
===
--- clang/lib/Driver/ToolChains/SPIRV.cpp
+++ clang/lib/Driver/ToolChains/SPIRV.cpp
@@ -70,3 +70,25 @@
   }
   return ToolChain::getTool(AC);
 }
+clang::driver::Tool *SPIRVToolChain::buildLinker() const {
+  return new tools::SPIRV::Linker(*this);
+}
+
+void SPIRV::Linker::ConstructJob(Compilation &C, const JobAction &JA,
+ const InputInfo &Output,
+ const InputInfoList &Inputs,
+ const ArgList &Args,
+ const char *LinkingOutput) const {
+  const ToolChain &ToolChain = getToolChain();
+  const Driver &D = ToolChain.getDriver();
+  std::string Linker = ToolChain.GetProgramPath(getShortName());
+  ArgStringList CmdArgs;
+  AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
+
+  CmdArgs.push_back("-o");
+  CmdArgs.push_back(Output.getFilename());
+
+  C.addCommand(std::make_unique(JA, *this, ResponseFileSupport::None(),
+ Args.MakeArgString(Linker), CmdArgs,
+ Inputs, Output));
+}
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -3804,14 +3804,6 @@
 }
   }
 
-  // FIXME: Linking separate translation units for SPIR-V is not supported yet.
-  // It can be done either by LLVM IR linking before conversion of the final
-  // linked module to SPIR-V or external SPIR-V linkers can be used e.g.
-  // spirv-link.
-  if (C.getDefaultToolChain().getTriple().isSPIRV() && Inputs.size() > 1) {
-Diag(clang::diag::warn_drv_spirv_linking_multiple_inputs_unsupported);
-  }
-
   handleArguments(C, Args, Inputs, Actions);
 
   // Builder to be used to build offloading actions.
@@ -3851,15 +3843,8 @@
   // Queue linker inputs.
   if (Phase == phases::Link) {
 assert(Phase == PL.back() && "linking must be final compilation step.");
-// Compilation phases are setup per langu

[PATCH] D116750: [clang][lex] Keep references to `DirectoryLookup` objects up-to-date

2022-01-11 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 398917.
jansvoboda11 added a comment.

Update documentation, inline variables in test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116750

Files:
  clang/include/clang/Lex/HeaderSearch.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/unittests/Lex/CMakeLists.txt
  clang/unittests/Lex/HeaderSearchTest.cpp

Index: clang/unittests/Lex/HeaderSearchTest.cpp
===
--- clang/unittests/Lex/HeaderSearchTest.cpp
+++ clang/unittests/Lex/HeaderSearchTest.cpp
@@ -15,6 +15,7 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
+#include "clang/Frontend/Utils.h"
 #include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/HeaderSearchOptions.h"
 #include "clang/Serialization/InMemoryModuleCache.h"
@@ -24,6 +25,12 @@
 namespace clang {
 namespace {
 
+static std::shared_ptr createTargetOptions() {
+  auto TargetOpts = std::make_shared();
+  TargetOpts->Triple = "x86_64-apple-darwin11.1.0";
+  return TargetOpts;
+}
+
 // The test fixture.
 class HeaderSearchTest : public ::testing::Test {
 protected:
@@ -31,12 +38,10 @@
   : VFS(new llvm::vfs::InMemoryFileSystem), FileMgr(FileMgrOpts, VFS),
 DiagID(new DiagnosticIDs()),
 Diags(DiagID, new DiagnosticOptions, new IgnoringDiagConsumer()),
-SourceMgr(Diags, FileMgr), TargetOpts(new TargetOptions),
+SourceMgr(Diags, FileMgr), TargetOpts(createTargetOptions()),
+Target(TargetInfo::CreateTargetInfo(Diags, TargetOpts)),
 Search(std::make_shared(), SourceMgr, Diags,
-   LangOpts, Target.get()) {
-TargetOpts->Triple = "x86_64-apple-darwin11.1.0";
-Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts);
-  }
+   LangOpts, Target.get()) {}
 
   void addSearchDir(llvm::StringRef Dir) {
 VFS->addFile(Dir, 0, llvm::MemoryBuffer::getMemBuffer(""), /*User=*/None,
@@ -47,6 +52,27 @@
 Search.AddSearchPath(DL, /*isAngled=*/false);
   }
 
+  void setSearchDirs(llvm::ArrayRef QuotedDirs,
+ llvm::ArrayRef AngledDirs) {
+auto AddPath = [&](StringRef Dir, bool IsAngled) {
+  VFS->addFile(Dir, 0, llvm::MemoryBuffer::getMemBuffer(""), /*User=*/None,
+   /*Group=*/None, llvm::sys::fs::file_type::directory_file);
+  auto Group = IsAngled ? frontend::IncludeDirGroup::Angled
+: frontend::IncludeDirGroup::Quoted;
+  Search.getHeaderSearchOpts().AddPath(Dir, Group,
+   /*IsFramework=*/false,
+   /*IgnoreSysRoot=*/true);
+};
+
+for (llvm::StringRef Dir : QuotedDirs)
+  AddPath(Dir, /*IsAngled=*/false);
+for (llvm::StringRef Dir : AngledDirs)
+  AddPath(Dir, /*IsAngled=*/true);
+
+clang::ApplyHeaderSearchOptions(Search, Search.getHeaderSearchOpts(),
+LangOpts, Target->getTriple());
+  }
+
   void addHeaderMap(llvm::StringRef Filename,
 std::unique_ptr Buf,
 bool isAngled = false) {
@@ -63,6 +89,17 @@
 Search.AddSearchPath(DL, isAngled);
   }
 
+  void createModule(StringRef Mod) {
+std::string ModDir = ("/" + Mod).str();
+std::string ModHeader = (Mod + ".h").str();
+VFS->addFile(
+ModDir + "/module.modulemap", 0,
+llvm::MemoryBuffer::getMemBufferCopy(
+("module " + Mod + " { header \"" + ModHeader + "\" }").str()));
+VFS->addFile(ModDir + "/" + ModHeader, 0,
+ llvm::MemoryBuffer::getMemBuffer(""));
+  }
+
   IntrusiveRefCntPtr VFS;
   FileSystemOptions FileMgrOpts;
   FileManager FileMgr;
@@ -224,5 +261,31 @@
   EXPECT_EQ(FI->Framework.str(), "Foo");
 }
 
+TEST_F(HeaderSearchTest, SearchPathUsage) {
+  Search.getHeaderSearchOpts().ImplicitModuleMaps = true;
+
+  setSearchDirs(/*QuotedDirs=*/{"/M0"}, /*AngledDirs=*/{"/M2", "/M3"});
+  createModule("M0");
+  createModule("M2");
+  createModule("M3");
+
+  {
+Module *M2 = Search.lookupModule("M2");
+EXPECT_NE(M2, nullptr);
+EXPECT_EQ(Search.getSearchDirUsage(), (std::vector{0, 1, 0}));
+EXPECT_EQ(Search.computeUserEntryUsage(), (std::vector{0, 1, 0}));
+  }
+
+  addSearchDir("/M1");
+  createModule("M1");
+
+  {
+Module *M1 = Search.lookupModule("M1");
+EXPECT_NE(M1, nullptr);
+EXPECT_EQ(Search.getSearchDirUsage(), (std::vector{0, 1, 1, 0}));
+EXPECT_EQ(Search.computeUserEntryUsage(), (std::vector{0, 1, 0}));
+  }
+}
+
 } // namespace
 } // namespace clang
Index: clang/unittests/Lex/CMakeLists.txt
===
--- clang/unittests/Lex/CMakeLists.txt
+++ clang/unittests/Lex/CMakeLists.txt
@@ -15,6 +15,7 @@
   PRIVATE
   clangAST
   clangBasic
+  clangFrontend
   clangLex
   clangParse
   clangSema
Index: clang/lib/Lex/H

[PATCH] D116425: [clang-tidy] Improve modernize-redundant-void-arg to recognize macro uses

2022-01-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp:51
  this);
-  Finder->addMatcher(typedefNameDecl().bind(TypedefId), this);
+  Finder->addMatcher(typedefNameDecl(unless(isImplicit())).bind(TypedefId), 
this);
   auto ParenFunctionType = parenType(innerType(functionType()));

Might as well fix the clang-format issue.



Comment at: clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp:149
   Token ProtoToken;
+  IdentifierTable &Idents = Result.Context->Idents;
+  int MacroLevel = 0;

I think a safer interface to this is to use a `const IdentifierTable &` here 
and in `isMacroIdentifier()`. Then, in `isMacroIdentifier()`, instead of using 
`get()` (which has no `const` overload because it can add an identifier to the 
table), you can use `find()`. This removes any possibility of accidentally 
adding identifiers to the table (even in future refactorings).



Comment at: 
clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp:157-161
+  if (ProtoToken.is(tok::TokenKind::l_paren)) {
+State = TokenState::LeftParen;
+  } else if (isMacroIdentifier(Idents, ProtoToken)) {
+State = TokenState::MacroId;
+  }





Comment at: 
clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp:164-168
   if (ProtoToken.is(tok::TokenKind::l_paren)) {
-State = SawLeftParen;
+State = TokenState::MacroLeftParen;
+  } else {
+State = TokenState::Start;
+  }





Comment at: 
clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp:173-177
+if (isMacroIdentifier(Idents, ProtoToken)) {
+  State = TokenState::MacroId;
+} else {
+  State = TokenState::MacroArguments;
+}





Comment at: 
clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp:180-184
+if (MacroLevel == 0) {
+  State = TokenState::Start;
+} else {
+  State = TokenState::MacroId;
+}





Comment at: 
clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp:215-219
   if (ProtoToken.is(tok::TokenKind::r_paren)) {
 removeVoidToken(VoidToken, Diagnostic);
   } else if (ProtoToken.is(tok::TokenKind::l_paren)) {
-State = SawLeftParen;
+State = TokenState::LeftParen;
   }





Comment at: 
clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp:224-226
+  if (State == TokenState::Void && ProtoToken.is(tok::TokenKind::r_paren)) {
 removeVoidToken(VoidToken, Diagnostic);
   }





Comment at: 
clang-tools-extra/test/clang-tidy/checkers/modernize-redundant-void-arg.cpp:202
 // intentionally not LLVM style to check preservation of whitespace
+// clang-format off
 typedef

Unrelated change can be split out an NFC commit if you'd like, but we don't 
typically attempt to clang-format existing test files, so also not really 
necessary either.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/modernize-redundant-void-arg.cpp:561
+#define return_t(T) T
+return_t(void) func(void);
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: redundant void argument list in 
function declaration

LegalizeAdulthood wrote:
> jrtc27 wrote:
> > LegalizeAdulthood wrote:
> > > LegalizeAdulthood wrote:
> > > > aaron.ballman wrote:
> > > > > LegalizeAdulthood wrote:
> > > > > > aaron.ballman wrote:
> > > > > > > Can you also add a test for:
> > > > > > > ```
> > > > > > > void func(return_t(void));
> > > > > > > ```
> > > > > > `:-)`
> > > > > > 
> > > > > > What are you suggesting the result should be?  Honestly, looking at 
> > > > > > that, I'm not sure myself `:)`
> > > > > > 
> > > > > > IMO, if I saw this in a code review, I would flag it because you're 
> > > > > > using a macro called "return type" to specify the type of an 
> > > > > > argument.
> > > > > LoL, yeah, the name `return_t` would certainly be novel to use in a 
> > > > > parameter list, but what I was hoping to test is whether we try to 
> > > > > fix the use of the macro within the parameter list or not. I *think* 
> > > > > it probably makes sense to issue the diagnostic, but I don't think it 
> > > > > makes sense to try to fix it because the macro could be defined 
> > > > > differently for different configurations. But the diagnostic is 
> > > > > silenced as well as the fix-it, I wouldn't lose a whole lot of sleep 
> > > > > over it.
> > > > Well it could conceivably be used to declare a function pointer 
> > > > argument like this:
> > > > 
> > > > `void func(return_t(void) (*fp)(void));`
> > > > 
> > > > In that case, my expectation is that the check would fix the void arg, 
> > > >

[PATCH] D116750: [clang][lex] Keep references to `DirectoryLookup` objects up-to-date

2022-01-11 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 marked 4 inline comments as done.
jansvoboda11 added a comment.

Thanks for the feedback!




Comment at: clang/unittests/Lex/HeaderSearchTest.cpp:276
+std::vector ExpectedSearchDirUsageAfterM2{false, true, false};
+EXPECT_EQ(Search.getSearchDirUsage(), ExpectedSearchDirUsageAfterM2);
+std::vector ExpectedUserEntryUsageAfterM2{false, true, false};

ahoppen wrote:
> jansvoboda11 wrote:
> > ahoppen wrote:
> > > Wouldn’t it be cleaner to just check that `UsedSearchDirs` only contains 
> > > a single element and that it’s name is `/M2`? In that case we could also 
> > > remove `getSearchDirUsage`.
> > Maybe I'm misunderstanding you, but I don't think so. We'd still need 
> > accessor for `HeaderSearch::UsedSearchDirs` and we don't have the expected 
> > `DirectoryLookup *` lying around, making matching more cumbersome:
> > 
> > ```
> > const llvm::DenseSet &UsedSearchDirs =
> > Search.getUsedSearchDirs();
> > EXPECT_EQ(UsedSearchDirs.size(), 2);
> > EXPECT_EQ(1, llvm::count_if(UsedSearchDirs, [](const auto *SearchDir) {
> > return SearchDir->getName() == "/M1";
> >   }));
> > EXPECT_EQ(1, llvm::count_if(UsedSearchDirs, [](const auto *SearchDir) {
> > return SearchDir->getName() == "/M2";
> >   }));
> > ```
> > 
> > or
> > 
> > ```
> > llvm::DenseSet UsedSearchDirsStr;
> > for (const auto *SearchDir : Search.getUsedSearchDirs())
> >   UsedSearchDirsStr.insert(SearchDir->getName());
> > EXPECT_EQ(UsedSearchDirsStr, (llvm::DenseSet{"/M1", 
> > "/M2"}));
> > ```
> > 
> > I think having bit-vector, whose indices correspond to the directory names 
> > (`"/M{i}"`), and using `operator==` for matching is simpler.
> > 
> > Let me know if you had something else in mind.
> I just don’t like the bit-vectors and basically thought of the second option 
> you were suggesting, but maybe that’s really just personal taste. If you’d 
> like to keep the bit-vector, could you change the comment of 
> `getSearchDirUsage` to something like 
> ```
> /// Return a vector of length \c SearchDirs.size() that indicates for each 
> search directory whether it was used.
> ```
I've updated documentation for `HeaderSearch::getSearchDirUsage`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116750

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


[clang] 0eef650 - [SPIR-V] Remove unused variable

2022-01-11 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2022-01-11T13:45:59Z
New Revision: 0eef65028e8a2f3417fb19e2eb5b0cbf50600c7e

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

LOG: [SPIR-V] Remove unused variable

Added: 


Modified: 
clang/lib/Driver/ToolChains/SPIRV.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/SPIRV.cpp 
b/clang/lib/Driver/ToolChains/SPIRV.cpp
index ce6ce5e8998e..27de69550853 100644
--- a/clang/lib/Driver/ToolChains/SPIRV.cpp
+++ b/clang/lib/Driver/ToolChains/SPIRV.cpp
@@ -80,7 +80,6 @@ void SPIRV::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
  const ArgList &Args,
  const char *LinkingOutput) const {
   const ToolChain &ToolChain = getToolChain();
-  const Driver &D = ToolChain.getDriver();
   std::string Linker = ToolChain.GetProgramPath(getShortName());
   ArgStringList CmdArgs;
   AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);



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


[PATCH] D116266: [SPIR-V] Add linking of separate translation units using spirv-link

2022-01-11 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

Fix is committed to remove unused variable: 
https://github.com/llvm/llvm-project/commit/0eef65028e8a2f3417fb19e2eb5b0cbf50600c7e


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116266

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


[PATCH] D116190: Comment parsing: Don't recognize commands in single-line double quotation

2022-01-11 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added a comment.

Ping @gribozavr2.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116190

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


[clang] 8503c68 - [clang][lex] Keep references to `DirectoryLookup` objects up-to-date

2022-01-11 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2022-01-11T15:24:46+01:00
New Revision: 8503c688d555014b88849e933bf096035a351586

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

LOG: [clang][lex] Keep references to `DirectoryLookup` objects up-to-date

The elements of `SearchPath::SearchDirs` are being referenced to by their 
indices. This proved to be error-prone: `HeaderSearch::SearchDirToHSEntry` was 
accidentally not being updated in `HeaderSearch::AddSearchPath()`. This patch 
fixes that by referencing `SearchPath::SearchDirs` elements by their address 
instead, which is stable thanks to the bump-ptr-allocation strategy.

Reviewed By: ahoppen

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

Added: 


Modified: 
clang/include/clang/Lex/HeaderSearch.h
clang/lib/Lex/HeaderSearch.cpp
clang/unittests/Lex/CMakeLists.txt
clang/unittests/Lex/HeaderSearchTest.cpp

Removed: 




diff  --git a/clang/include/clang/Lex/HeaderSearch.h 
b/clang/include/clang/Lex/HeaderSearch.h
index e056f009eae9a..5507401f608a5 100644
--- a/clang/include/clang/Lex/HeaderSearch.h
+++ b/clang/include/clang/Lex/HeaderSearch.h
@@ -165,22 +165,23 @@ class HeaderSearch {
   /// Header-search options used to initialize this header search.
   std::shared_ptr HSOpts;
 
-  /// Mapping from SearchDir to HeaderSearchOptions::UserEntries indices.
-  llvm::DenseMap SearchDirToHSEntry;
-
   DiagnosticsEngine &Diags;
   FileManager &FileMgr;
 
+  /// The allocator owning search directories.
+  llvm::SpecificBumpPtrAllocator SearchDirsAlloc;
   /// \#include search path information.  Requests for \#include "x" search the
   /// directory of the \#including file first, then each directory in 
SearchDirs
   /// consecutively. Requests for  search the current dir first, then each
   /// directory in SearchDirs, starting at AngledDirIdx, consecutively.  If
   /// NoCurDirSearch is true, then the check for the file in the current
   /// directory is suppressed.
-  std::vector SearchDirs;
-  /// Whether the DirectoryLookup at the corresponding index in SearchDirs has
-  /// been successfully used to lookup a file.
-  std::vector SearchDirsUsage;
+  std::vector SearchDirs;
+  /// Set of SearchDirs that have been successfully used to lookup a file.
+  llvm::DenseSet UsedSearchDirs;
+  /// Mapping from SearchDir to HeaderSearchOptions::UserEntries indices.
+  llvm::DenseMap SearchDirToHSEntry;
+
   unsigned AngledDirIdx = 0;
   unsigned SystemDirIdx = 0;
   bool NoCurDirSearch = false;
@@ -288,8 +289,7 @@ class HeaderSearch {
 
   /// Add an additional system search path.
   void AddSystemSearchPath(const DirectoryLookup &dir) {
-SearchDirs.push_back(dir);
-SearchDirsUsage.push_back(false);
+SearchDirs.push_back(storeSearchDir(dir));
   }
 
   /// Set the list of system header prefixes.
@@ -493,7 +493,11 @@ class HeaderSearch {
 
   /// Determine which HeaderSearchOptions::UserEntries have been successfully
   /// used so far and mark their index with 'true' in the resulting bit vector.
+  // TODO: Use llvm::BitVector instead.
   std::vector computeUserEntryUsage() const;
+  /// Return a bit vector of length \c SearchDirs.size() that indicates for 
each
+  /// search directory whether it was used.
+  std::vector getSearchDirUsage() const;
 
   /// This method returns a HeaderMap for the specified
   /// FileEntry, uniquing them through the 'HeaderMaps' datastructure.
@@ -623,6 +627,11 @@ class HeaderSearch {
   void loadTopLevelSystemModules();
 
 private:
+  /// Stores the given search directory and returns a stable pointer.
+  DirectoryLookup *storeSearchDir(const DirectoryLookup &Dir) {
+return new (SearchDirsAlloc.Allocate()) DirectoryLookup(Dir);
+  }
+
   /// Lookup a module with the given module name and search-name.
   ///
   /// \param ModuleName The name of the module we're looking for.
@@ -709,8 +718,9 @@ class HeaderSearch {
   void cacheLookupSuccess(LookupFileCacheInfo &CacheLookup, unsigned HitIdx,
   SourceLocation IncludeLoc);
   /// Note that a lookup at the given include location was successful using the
-  /// search path at index `HitIdx`.
-  void noteLookupUsage(unsigned HitIdx, SourceLocation IncludeLoc);
+  /// given search path.
+  void noteLookupUsage(const DirectoryLookup *SearchDir,
+   SourceLocation IncludeLoc);
 
 public:
   /// Retrieve the module map.
@@ -733,7 +743,8 @@ class HeaderSearch {
 bool WantExternal = true) const;
 
   // Used by external tools
-  using search_dir_iterator = std::vector::const_iterator;
+  using search_dir_iterator =
+  llvm::pointee_iterator;
 
   search_dir_iterator search_dir_begin() const { return SearchDirs.begin(); }
   search_dir_iterator search_dir_end() c

[PATCH] D116750: [clang][lex] Keep references to `DirectoryLookup` objects up-to-date

2022-01-11 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
jansvoboda11 marked an inline comment as done.
Closed by commit rG8503c688d555: [clang][lex] Keep references to 
`DirectoryLookup` objects up-to-date (authored by jansvoboda11).

Changed prior to commit:
  https://reviews.llvm.org/D116750?vs=398917&id=398932#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116750

Files:
  clang/include/clang/Lex/HeaderSearch.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/unittests/Lex/CMakeLists.txt
  clang/unittests/Lex/HeaderSearchTest.cpp

Index: clang/unittests/Lex/HeaderSearchTest.cpp
===
--- clang/unittests/Lex/HeaderSearchTest.cpp
+++ clang/unittests/Lex/HeaderSearchTest.cpp
@@ -15,6 +15,7 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
+#include "clang/Frontend/Utils.h"
 #include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/HeaderSearchOptions.h"
 #include "clang/Serialization/InMemoryModuleCache.h"
@@ -24,6 +25,12 @@
 namespace clang {
 namespace {
 
+static std::shared_ptr createTargetOptions() {
+  auto TargetOpts = std::make_shared();
+  TargetOpts->Triple = "x86_64-apple-darwin11.1.0";
+  return TargetOpts;
+}
+
 // The test fixture.
 class HeaderSearchTest : public ::testing::Test {
 protected:
@@ -31,12 +38,10 @@
   : VFS(new llvm::vfs::InMemoryFileSystem), FileMgr(FileMgrOpts, VFS),
 DiagID(new DiagnosticIDs()),
 Diags(DiagID, new DiagnosticOptions, new IgnoringDiagConsumer()),
-SourceMgr(Diags, FileMgr), TargetOpts(new TargetOptions),
+SourceMgr(Diags, FileMgr), TargetOpts(createTargetOptions()),
+Target(TargetInfo::CreateTargetInfo(Diags, TargetOpts)),
 Search(std::make_shared(), SourceMgr, Diags,
-   LangOpts, Target.get()) {
-TargetOpts->Triple = "x86_64-apple-darwin11.1.0";
-Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts);
-  }
+   LangOpts, Target.get()) {}
 
   void addSearchDir(llvm::StringRef Dir) {
 VFS->addFile(Dir, 0, llvm::MemoryBuffer::getMemBuffer(""), /*User=*/None,
@@ -56,6 +61,27 @@
 Search.AddSystemSearchPath(DL);
   }
 
+  void setSearchDirs(llvm::ArrayRef QuotedDirs,
+ llvm::ArrayRef AngledDirs) {
+auto AddPath = [&](StringRef Dir, bool IsAngled) {
+  VFS->addFile(Dir, 0, llvm::MemoryBuffer::getMemBuffer(""), /*User=*/None,
+   /*Group=*/None, llvm::sys::fs::file_type::directory_file);
+  auto Group = IsAngled ? frontend::IncludeDirGroup::Angled
+: frontend::IncludeDirGroup::Quoted;
+  Search.getHeaderSearchOpts().AddPath(Dir, Group,
+   /*IsFramework=*/false,
+   /*IgnoreSysRoot=*/true);
+};
+
+for (llvm::StringRef Dir : QuotedDirs)
+  AddPath(Dir, /*IsAngled=*/false);
+for (llvm::StringRef Dir : AngledDirs)
+  AddPath(Dir, /*IsAngled=*/true);
+
+clang::ApplyHeaderSearchOptions(Search, Search.getHeaderSearchOpts(),
+LangOpts, Target->getTriple());
+  }
+
   void addHeaderMap(llvm::StringRef Filename,
 std::unique_ptr Buf,
 bool isAngled = false) {
@@ -72,6 +98,17 @@
 Search.AddSearchPath(DL, isAngled);
   }
 
+  void createModule(StringRef Mod) {
+std::string ModDir = ("/" + Mod).str();
+std::string ModHeader = (Mod + ".h").str();
+VFS->addFile(
+ModDir + "/module.modulemap", 0,
+llvm::MemoryBuffer::getMemBufferCopy(
+("module " + Mod + " { header \"" + ModHeader + "\" }").str()));
+VFS->addFile(ModDir + "/" + ModHeader, 0,
+ llvm::MemoryBuffer::getMemBuffer(""));
+  }
+
   IntrusiveRefCntPtr VFS;
   FileSystemOptions FileMgrOpts;
   FileManager FileMgr;
@@ -256,5 +293,31 @@
   EXPECT_EQ(FI->Framework.str(), "Foo");
 }
 
+TEST_F(HeaderSearchTest, SearchPathUsage) {
+  Search.getHeaderSearchOpts().ImplicitModuleMaps = true;
+
+  setSearchDirs(/*QuotedDirs=*/{"/M0"}, /*AngledDirs=*/{"/M2", "/M3"});
+  createModule("M0");
+  createModule("M2");
+  createModule("M3");
+
+  {
+Module *M2 = Search.lookupModule("M2");
+EXPECT_NE(M2, nullptr);
+EXPECT_EQ(Search.getSearchDirUsage(), (std::vector{0, 1, 0}));
+EXPECT_EQ(Search.computeUserEntryUsage(), (std::vector{0, 1, 0}));
+  }
+
+  addSearchDir("/M1");
+  createModule("M1");
+
+  {
+Module *M1 = Search.lookupModule("M1");
+EXPECT_NE(M1, nullptr);
+EXPECT_EQ(Search.getSearchDirUsage(), (std::vector{0, 1, 1, 0}));
+EXPECT_EQ(Search.computeUserEntryUsage(), (std::vector{0, 1, 0}));
+  }
+}
+
 } // namespace
 } // namespace clang
Index: clang/unittests/Lex/CMakeLists.txt
==

[PATCH] D116478: [clang-tidy] A comma-separated list of the names of functions or methods to be considered as not having side-effects

2022-01-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp:57-60
 if (const auto *FuncDecl = CExpr->getDirectCallee()) {
   if (FuncDecl->getDeclName().isIdentifier() &&
-  FuncDecl->getName() == "__builtin_expect") // exceptions come here
+  IgnoredFunctions.contains(
+  FuncDecl->getName())) // exceptions come here

This doesn't seem quite right to me (test coverage would help) in the case 
where the user is specifying a (potentially partially) qualified function name. 
e.g., imagine an `IgnoredFunctions` list of 
`my::fancy_func,::other_func,yet::another_func` where `my` is a namespace 
containing a function named `fancy_func`, and `yet` is a class with a static 
function named `another_func`. I think this code will only consider the name of 
the function itself, but not any part of its qualified name.

I think we typically implement function name exclusions via the 
`matchesAnyListedName()` AST matcher, as in: 
https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp#L92



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:149-150
+- :doc:`bugprone-assert-side-effect 
`
+  check now supports a ``IgnoredFunctions`` option to explicitly consider the 
specified
+  functions or methods as not any having side-effects.
+





Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone-assert-side-effect.rst:27
+
+   A comma-separated list of the names of functions or methods to be
+   considered as not having side-effects.

This doesn't document whether the names can be qualified or not, or whether the 
names have to have an exact match instead of a regex match.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-assert-side-effect.cpp:91
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() 
condition discarded in release builds
+  assert(mc.badButIgnoredFunc(0, 1));
   assert(mc.goodFunc(0, 1));

FWIW, I think this can be confusing in practice; the function called is 
`::MyClass:badButIgnoredFunc()`. Further, if I had a global function named 
`badButIgnoredFunc()` it would *also* be ignored and I'd have no way to 
configure to distinguish between the two.


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

https://reviews.llvm.org/D116478

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


[PATCH] D116967: [HIP] Fix device malloc/free

2022-01-11 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/lib/Headers/__clang_hip_runtime_wrapper.h:80
 
+#if HIP_VERSION_MAJOR > 4 || (HIP_VERSION_MAJOR == 4 && HIP_VERSION_MINOR >= 5)
+extern "C" __device__ unsigned long long __ockl_dm_alloc(unsigned long long 
__size);

tra wrote:
> Nit: perhaps something like this would express the intent a bit more directly:
> 
> ```
> # if HIP_VERSION_MAJOR*100+HIP_VERSION_MINOR*10 > 450
> ```
> 
> 
We had ROCm 3.10, so the minor version may be 10 or greater.

Probably use HIP_VERSION_MAJOR*100+HIP_VERSION_MINOR > 405 instead?


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

https://reviews.llvm.org/D116967

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


[PATCH] D116775: [clang][#47272] Avoid suggesting deprecated version of a declaration over another in typo correction

2022-01-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

LGTM aside from some nits, though please wait for @Quuxplusone to respond 
before landing.




Comment at: clang/lib/Sema/SemaLookup.cpp:4310-4311
   if (NamedDecl *NewND = Correction.getCorrectionDecl()) {
-std::string CorrectionStr = Correction.getAsString(SemaRef.getLangOpts());
-for (TypoResultList::iterator RI = CList.begin(), RIEnd = CList.end();
- RI != RIEnd; ++RI) {
-  // If the Correction refers to a decl already in the result list,
-  // replace the existing result if the string representation of Correction
-  // comes before the current result alphabetically, then stop as there is
-  // nothing more to be done to add Correction to the candidate set.
-  if (RI->getCorrectionDecl() == NewND) {
-if (CorrectionStr < RI->getAsString(SemaRef.getLangOpts()))
-  *RI = Correction;
-return;
-  }
+auto RI = llvm::find_if(CList, [NewND](const TypoCorrection &typoCorr) {
+  return typoCorr.getCorrectionDecl() == NewND;
+});





Comment at: clang/lib/Sema/SemaLookup.cpp:4317
+
+  auto IsDeprecated = [](Decl *decl) {
+while (decl) {

Feel free to pick a better name than `D` (other than `Decl`, please!), just 
cleaning up the coding style nit.



Comment at: clang/lib/Sema/SemaLookup.cpp:4327
+  // Prefer non deprecated Corrections over deprecated and only then
+  // sort using an alphabetical order
+  std::pair newKey = {





Comment at: clang/lib/Sema/SemaLookup.cpp:4328-4332
+  std::pair newKey = {
+  IsDeprecated(Correction.getFoundDecl()),
+  Correction.getAsString(SemaRef.getLangOpts())};
+
+  std::pair prevKey = {




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

https://reviews.llvm.org/D116775

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


[PATCH] D116750: [clang][lex] Keep references to `DirectoryLookup` objects up-to-date

2022-01-11 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

1. `which is stable thanks to the bump-ptr-allocation strategy.` I don't 
understand this. In each slab, that's true, but why is it true between objects 
allocated in different slabs?
2. This increases numbers of TUs compiled for LexTests by over 10%. Is there no 
way around that Frontend dep?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116750

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


[PATCH] D116775: [clang][#47272] Avoid suggesting deprecated version of a declaration over another in typo correction

2022-01-11 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added a comment.

LGTM % comments, but I'll take one more look.




Comment at: clang/test/SemaCXX/typo-correction.cpp:772-782
+namespace B {
+int pr47272();  // expected-note{{'B::pr47272' declared here}}
+}
+
+namespace [[deprecated]] A {
+using B::pr47272;
+}

I'd like `B` to be declared second.
```
namespace [[deprecated]] A { int pr47272; }
namespace B { using A::pr47272; } // expected-note{{'B::pr47272' declared here}}
namespace [[deprecated]] C { using A::pr47272; }

~~~
  int y = ::pr47272; // expected-error{{no member named 'pr47272' in the global 
namespace; did you mean 'B::pr47272'?}}
```
I also changed it from a function to a variable, just to get a little more 
coverage (since `Take()` was already covering functions).


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

https://reviews.llvm.org/D116775

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


[PATCH] D111566: [SYCL] Fix function pointer address space

2022-01-11 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews marked 2 inline comments as done.
eandrews added inline comments.



Comment at: clang/lib/AST/ASTContext.cpp:11496
+   .getProgramAddressSpace()
+ : getTargetAddressSpace(T.getQualifiers());
+}

rjmccall wrote:
> Oh, I'm sorry I missed this.  Parsing the data layout string into an 
> `llvm::DataLayout` is definitely not an okay thing to be doing here.  The 
> IRGen version of this had a cached `DataLayout` object which it queried, 
> which was okay, but this function is used too tightly to be doing that much 
> redundant work.
> 
> We could just cache a `DataLayout` in the `clang::TargetInfo`, but I think 
> we've been trying to avoid that as a layering violation.  Instead, 
> `TargetInfo` should just have a `getProgramAddressSpace` method or something 
> like that, and the targets with non-default address spaces for code should 
> set that manually.
> Instead, `TargetInfo` should just have a `getProgramAddressSpace` method or 
> something like that, and the targets with non-default address spaces for code 
> should set that manually.

Ok. Thanks for review! I'll make this change



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

https://reviews.llvm.org/D111566

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


[PATCH] D116750: [clang][lex] Keep references to `DirectoryLookup` objects up-to-date

2022-01-11 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

In D116750#3234261 , @thakis wrote:

> 1. `which is stable thanks to the bump-ptr-allocation strategy.` I don't 
> understand this. In each slab, that's true, but why is it true between 
> objects allocated in different slabs?

That's referring to the fact that once we allocate new `DirectoryLookup` with 
`SpecificBumpPtrAllocator`, address of that object won't change (unlike with 
`std::vector`). This means that we can take the address and use it without 
worrying about invalidation.

> 2. This increases numbers of TUs compiled for LexTests by over 10%. Is there 
> no way around that Frontend dep?

I'll look into moving `clang::ApplyHeaderSearchOptions` from `Frontend` into 
`Lex`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116750

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


[PATCH] D27800: Add overload of TransformToPotentiallyEvaluated for TypeSourceInfo

2022-01-11 Thread Paulo Matos via Phabricator via cfe-commits
pmatos updated this revision to Diff 398935.
pmatos added a comment.
Herald added a subscriber: wingo.
Herald added a project: clang.

After a long hiatus on this bug, this is still failing on HEAD so lets get it 
fixed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D27800

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/pr31042.cpp


Index: clang/test/SemaCXX/pr31042.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/pr31042.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -o - -emit-llvm -triple x86_64-unknown-linux-gnu 
-disable-free %s
+// We need to use -emit-llvm in order to trigger the error, without it 
semantic analysis
+// does not verify the used bit and there's no error.
+
+char a[1];
+
+void
+f1 (void)
+{
+  int i = 0;
+  int j = sizeof (typeof (*(char (*)[i])a));
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -4499,6 +4499,10 @@
   }
 
   // C99 6.5.3.4p4: the type (an unsigned integer type) is size_t.
+  if (ExprKind == UETT_SizeOf &&
+   TInfo->getType()->isVariablyModifiedType())
+TInfo = TransformToPotentiallyEvaluated(TInfo);
+
   return new (Context) UnaryExprOrTypeTraitExpr(
   ExprKind, TInfo, Context.getSizeType(), OpLoc, R.getEnd());
 }
@@ -16602,6 +16606,16 @@
   return TransformToPE(*this).TransformExpr(E);
 }
 
+TypeSourceInfo *Sema::TransformToPotentiallyEvaluated(TypeSourceInfo *TInfo) {
+  assert(isUnevaluatedContext() &&
+ "Should only transform unevaluated expressions");
+  ExprEvalContexts.back().Context =
+  ExprEvalContexts[ExprEvalContexts.size()-2].Context;
+  if (isUnevaluatedContext())
+return TInfo;
+  return TransformToPE(*this).TransformType(TInfo);
+}
+
 void
 Sema::PushExpressionEvaluationContext(
 ExpressionEvaluationContext NewContext, Decl *LambdaContextDecl,
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -5053,6 +5053,7 @@
   void DiscardCleanupsInEvaluationContext();
 
   ExprResult TransformToPotentiallyEvaluated(Expr *E);
+  TypeSourceInfo *TransformToPotentiallyEvaluated(TypeSourceInfo *TInfo);
   ExprResult HandleExprEvaluationContextForTypeof(Expr *E);
 
   ExprResult CheckUnevaluatedOperand(Expr *E);


Index: clang/test/SemaCXX/pr31042.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/pr31042.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -o - -emit-llvm -triple x86_64-unknown-linux-gnu -disable-free %s
+// We need to use -emit-llvm in order to trigger the error, without it semantic analysis
+// does not verify the used bit and there's no error.
+
+char a[1];
+
+void
+f1 (void)
+{
+  int i = 0;
+  int j = sizeof (typeof (*(char (*)[i])a));
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -4499,6 +4499,10 @@
   }
 
   // C99 6.5.3.4p4: the type (an unsigned integer type) is size_t.
+  if (ExprKind == UETT_SizeOf &&
+   TInfo->getType()->isVariablyModifiedType())
+TInfo = TransformToPotentiallyEvaluated(TInfo);
+
   return new (Context) UnaryExprOrTypeTraitExpr(
   ExprKind, TInfo, Context.getSizeType(), OpLoc, R.getEnd());
 }
@@ -16602,6 +16606,16 @@
   return TransformToPE(*this).TransformExpr(E);
 }
 
+TypeSourceInfo *Sema::TransformToPotentiallyEvaluated(TypeSourceInfo *TInfo) {
+  assert(isUnevaluatedContext() &&
+ "Should only transform unevaluated expressions");
+  ExprEvalContexts.back().Context =
+  ExprEvalContexts[ExprEvalContexts.size()-2].Context;
+  if (isUnevaluatedContext())
+return TInfo;
+  return TransformToPE(*this).TransformType(TInfo);
+}
+
 void
 Sema::PushExpressionEvaluationContext(
 ExpressionEvaluationContext NewContext, Decl *LambdaContextDecl,
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -5053,6 +5053,7 @@
   void DiscardCleanupsInEvaluationContext();
 
   ExprResult TransformToPotentiallyEvaluated(Expr *E);
+  TypeSourceInfo *TransformToPotentiallyEvaluated(TypeSourceInfo *TInfo);
   ExprResult HandleExprEvaluationContextForTypeof(Expr *E);
 
   ExprResult CheckUnevaluatedOperand(Expr *E);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D27800: Add overload of TransformToPotentiallyEvaluated for TypeSourceInfo

2022-01-11 Thread Paulo Matos via Phabricator via cfe-commits
pmatos added a comment.

Fixes https://github.com/llvm/llvm-project/issues/30390




Comment at: test/SemaCXX/pr31042.cpp:1
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only 
-disable-free %s
+

efriedma wrote:
> Oh, this testcase doesn't actually crash on trunk without at least -emit-llvm 
> because semantic analysis doesn't actually verify the used bit. :(  Better to 
> include that, I think.
Ah, that's why I had initially `-emit-obj`. That also triggered the problem. I 
obviously forgot about this and removed the flag without retesting to check if 
still broke trunk. Apologies for that.



Comment at: test/SemaCXX/pr31042.cpp:1
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only 
-disable-free %s
+

pmatos wrote:
> efriedma wrote:
> > Oh, this testcase doesn't actually crash on trunk without at least 
> > -emit-llvm because semantic analysis doesn't actually verify the used bit. 
> > :(  Better to include that, I think.
> Ah, that's why I had initially `-emit-obj`. That also triggered the problem. 
> I obviously forgot about this and removed the flag without retesting to check 
> if still broke trunk. Apologies for that.
And we also need to remove `-fsyntax-only`. Submitting new patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D27800

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


[PATCH] D27800: Add overload of TransformToPotentiallyEvaluated for TypeSourceInfo

2022-01-11 Thread Paulo Matos via Phabricator via cfe-commits
pmatos added a comment.

Fixes https://github.com/llvm/llvm-project/issues/30390


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D27800

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


[PATCH] D27800: Add overload of TransformToPotentiallyEvaluated for TypeSourceInfo

2022-01-11 Thread Paulo Matos via Phabricator via cfe-commits
pmatos added a comment.

@efriedma I know it has been a long time, but are you still able to review this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D27800

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


[PATCH] D116750: [clang][lex] Keep references to `DirectoryLookup` objects up-to-date

2022-01-11 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

> That's referring to the fact that once we allocate new `DirectoryLookup` with 
> `SpecificBumpPtrAllocator`, address of that object won't change (unlike with 
> `std::vector`). This means that we can take the address and use it without 
> worrying about invalidation.

Ah, "stable" made me think of iteration order, but that's not what you meant. 
Makes sense, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116750

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


[PATCH] D117024: [clang] Move `ApplyHeaderSearchOptions` from Frontend to Lex

2022-01-11 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added a reviewer: thakis.
Herald added a subscriber: mgorny.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

In D116750 , the `clangFrontend` library was 
added as a dependency of `LexTests` in order to make 
`clang::ApplyHeaderSearchOptions()` available. This increased the number of TUs 
the test depends on.

This patch moves the function into `clangLex` and removes dependency of 
`LexTests` on `clangFrontend`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117024

Files:
  clang/include/clang/Frontend/Utils.h
  clang/include/clang/Lex/HeaderSearch.h
  clang/lib/Frontend/CMakeLists.txt
  clang/lib/Frontend/InitHeaderSearch.cpp
  clang/lib/Lex/CMakeLists.txt
  clang/lib/Lex/InitHeaderSearch.cpp
  clang/unittests/Lex/CMakeLists.txt
  clang/unittests/Lex/HeaderSearchTest.cpp

Index: clang/unittests/Lex/HeaderSearchTest.cpp
===
--- clang/unittests/Lex/HeaderSearchTest.cpp
+++ clang/unittests/Lex/HeaderSearchTest.cpp
@@ -15,8 +15,6 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
-#include "clang/Frontend/Utils.h"
-#include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/HeaderSearchOptions.h"
 #include "clang/Serialization/InMemoryModuleCache.h"
 #include "llvm/Support/MemoryBuffer.h"
Index: clang/unittests/Lex/CMakeLists.txt
===
--- clang/unittests/Lex/CMakeLists.txt
+++ clang/unittests/Lex/CMakeLists.txt
@@ -15,7 +15,6 @@
   PRIVATE
   clangAST
   clangBasic
-  clangFrontend
   clangLex
   clangParse
   clangSema
Index: clang/lib/Lex/InitHeaderSearch.cpp
===
--- clang/lib/Lex/InitHeaderSearch.cpp
+++ clang/lib/Lex/InitHeaderSearch.cpp
@@ -10,13 +10,12 @@
 //
 //===--===//
 
+#include "clang/Lex/HeaderSearch.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/LangOptions.h"
+#include "clang/Basic/DiagnosticFrontend.h"
 #include "clang/Config/config.h" // C_INCLUDE_DIRS
-#include "clang/Frontend/FrontendDiagnostic.h"
-#include "clang/Frontend/Utils.h"
 #include "clang/Lex/HeaderMap.h"
-#include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/HeaderSearchOptions.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallString.h"
Index: clang/lib/Lex/CMakeLists.txt
===
--- clang/lib/Lex/CMakeLists.txt
+++ clang/lib/Lex/CMakeLists.txt
@@ -6,6 +6,7 @@
   DependencyDirectivesSourceMinimizer.cpp
   HeaderMap.cpp
   HeaderSearch.cpp
+  InitHeaderSearch.cpp
   Lexer.cpp
   LiteralSupport.cpp
   MacroArgs.cpp
Index: clang/lib/Frontend/CMakeLists.txt
===
--- clang/lib/Frontend/CMakeLists.txt
+++ clang/lib/Frontend/CMakeLists.txt
@@ -24,7 +24,6 @@
   FrontendActions.cpp
   FrontendOptions.cpp
   HeaderIncludeGen.cpp
-  InitHeaderSearch.cpp
   InitPreprocessor.cpp
   LayoutOverrideSource.cpp
   LogDiagnosticPrinter.cpp
Index: clang/include/clang/Lex/HeaderSearch.h
===
--- clang/include/clang/Lex/HeaderSearch.h
+++ clang/include/clang/Lex/HeaderSearch.h
@@ -34,6 +34,12 @@
 #include 
 #include 
 
+namespace llvm {
+
+class Triple;
+
+} // namespace llvm
+
 namespace clang {
 
 class DiagnosticsEngine;
@@ -853,6 +859,12 @@
 bool IsSystem, bool IsFramework);
 };
 
+/// Apply the header search options to get given HeaderSearch object.
+void ApplyHeaderSearchOptions(HeaderSearch &HS,
+  const HeaderSearchOptions &HSOpts,
+  const LangOptions &Lang,
+  const llvm::Triple &triple);
+
 } // namespace clang
 
 #endif // LLVM_CLANG_LEX_HEADERSEARCH_H
Index: clang/include/clang/Frontend/Utils.h
===
--- clang/include/clang/Frontend/Utils.h
+++ clang/include/clang/Frontend/Utils.h
@@ -32,12 +32,6 @@
 #include 
 #include 
 
-namespace llvm {
-
-class Triple;
-
-} // namespace llvm
-
 namespace clang {
 
 class ASTReader;
@@ -46,20 +40,11 @@
 class DiagnosticsEngine;
 class ExternalSemaSource;
 class FrontendOptions;
-class HeaderSearch;
-class HeaderSearchOptions;
-class LangOptions;
 class PCHContainerReader;
 class Preprocessor;
 class PreprocessorOptions;
 class PreprocessorOutputOptions;
 
-/// Apply the header search options to get given HeaderSearch object.
-void ApplyHeaderSearchOptions(HeaderSearch &HS,
-  const HeaderSearchOptions &HSOpts,
-  const LangOptions &Lang,
-  

[clang] a3b9edf - [ASan] Driver changes to always link-in asan_static library.

2022-01-11 Thread Kirill Stoimenov via cfe-commits

Author: Kirill Stoimenov
Date: 2022-01-11T15:31:41Z
New Revision: a3b9edf8b8c3815c1a2c200f9bc00882e1244827

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

LOG: [ASan] Driver changes to always link-in asan_static library.

This enables the changes from D116182.

Reviewed By: vitalybuka

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/Driver/sanitizer-ld.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index f25fe9ba34c4..3897f67d1fe6 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -826,6 +826,10 @@ collectSanitizerRuntimes(const ToolChain &TC, const 
ArgList &Args,
   if (SanArgs.needsStatsRt() && SanArgs.linkRuntimes())
 StaticRuntimes.push_back("stats_client");
 
+  // Always link the static runtime regardless of DSO or executable.
+  if (SanArgs.needsAsanRt())
+HelperStaticRuntimes.push_back("asan_static");
+
   // Collect static runtimes.
   if (Args.hasArg(options::OPT_shared)) {
 // Don't link static runtimes into DSOs.

diff  --git a/clang/test/Driver/sanitizer-ld.c 
b/clang/test/Driver/sanitizer-ld.c
index d62e19fd4021..ea8c49f2384a 100644
--- a/clang/test/Driver/sanitizer-ld.c
+++ b/clang/test/Driver/sanitizer-ld.c
@@ -22,7 +22,7 @@
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-ASAN-NO-LINK-RUNTIME-LINUX %s
 //
-// CHECK-ASAN-NO-LINK-RUNTIME-LINUX-NOT: libclang_rt.asan
+// CHECK-ASAN-NO-LINK-RUNTIME-LINUX-NOT: libclang_rt.asan-x86_64
 
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target i386-unknown-linux -fuse-ld=ld -fsanitize=address 
-shared-libsan \



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


[PATCH] D116670: [ASan] Driver changes to always link-in asan_static library.

2022-01-11 Thread Kirill Stoimenov 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 rGa3b9edf8b8c3: [ASan] Driver changes to always link-in 
asan_static library. (authored by kstoimenov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116670

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/sanitizer-ld.c


Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -22,7 +22,7 @@
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-ASAN-NO-LINK-RUNTIME-LINUX %s
 //
-// CHECK-ASAN-NO-LINK-RUNTIME-LINUX-NOT: libclang_rt.asan
+// CHECK-ASAN-NO-LINK-RUNTIME-LINUX-NOT: libclang_rt.asan-x86_64
 
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target i386-unknown-linux -fuse-ld=ld -fsanitize=address 
-shared-libsan \
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -826,6 +826,10 @@
   if (SanArgs.needsStatsRt() && SanArgs.linkRuntimes())
 StaticRuntimes.push_back("stats_client");
 
+  // Always link the static runtime regardless of DSO or executable.
+  if (SanArgs.needsAsanRt())
+HelperStaticRuntimes.push_back("asan_static");
+
   // Collect static runtimes.
   if (Args.hasArg(options::OPT_shared)) {
 // Don't link static runtimes into DSOs.


Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -22,7 +22,7 @@
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-ASAN-NO-LINK-RUNTIME-LINUX %s
 //
-// CHECK-ASAN-NO-LINK-RUNTIME-LINUX-NOT: libclang_rt.asan
+// CHECK-ASAN-NO-LINK-RUNTIME-LINUX-NOT: libclang_rt.asan-x86_64
 
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target i386-unknown-linux -fuse-ld=ld -fsanitize=address -shared-libsan \
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -826,6 +826,10 @@
   if (SanArgs.needsStatsRt() && SanArgs.linkRuntimes())
 StaticRuntimes.push_back("stats_client");
 
+  // Always link the static runtime regardless of DSO or executable.
+  if (SanArgs.needsAsanRt())
+HelperStaticRuntimes.push_back("asan_static");
+
   // Collect static runtimes.
   if (Args.hasArg(options::OPT_shared)) {
 // Don't link static runtimes into DSOs.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116549: [OpenMP][Clang] Allow passing target features in ISA trait for metadirective clause

2022-01-11 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert accepted this revision.
jdoerfert added a comment.
This revision is now accepted and ready to land.

LG, thanks for the adjustment. Hope you are happy with the result.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116549

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


[PATCH] D116948: [CodeGen] Treat ObjC `__unsafe_unretained` and class types as trivial when generating copy/dispose helper functions

2022-01-11 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 398948.
ahatanak marked 3 inline comments as done.
ahatanak added a comment.

Update comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116948

Files:
  clang/lib/CodeGen/CGBlocks.cpp
  clang/lib/CodeGen/CGBlocks.h
  clang/lib/CodeGen/CGObjCMac.cpp
  clang/test/CodeGenObjC/arc-blocks.m
  clang/test/CodeGenObjC/blocks.m

Index: clang/test/CodeGenObjC/blocks.m
===
--- clang/test/CodeGenObjC/blocks.m
+++ clang/test/CodeGenObjC/blocks.m
@@ -1,5 +1,14 @@
 // RUN: %clang_cc1 -triple i386-apple-darwin9 -fobjc-runtime=macosx-fragile-10.5 -emit-llvm -fblocks -o - %s | FileCheck %s
 
+// CHECK: %[[STRUCT_BLOCK_DESCRIPTOR:.*]] = type { i32, i32 }
+
+// Check that there is only one capture (20o) in the copy/dispose function
+// names.
+
+// CHECK: @[[BLOCK_DESCRIPTOR0:.*]] = linkonce_odr hidden unnamed_addr constant { i32, i32, i8*, i8*, i8*, i32 } { i32 0, i32 28, i8* bitcast (void (i8*, i8*)* @__copy_helper_block_4_20o to i8*), i8* bitcast (void (i8*)* @__destroy_helper_block_4_20o to i8*), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i32 512 },
+
+void (^gb0)(void);
+
 // test1.  All of this is somehow testing rdar://6676764
 struct S {
   void (^F)(struct S*);
@@ -132,3 +141,21 @@
 // CHECK-NEXT: [[T5:%.*]] = bitcast i8* [[T4]] to void (i8*, i32, i32, i32, i32)*
 // CHECK-NEXT: call void [[T5]](i8* [[T3]], i32 0, i32 1, i32 2, i32 3)
 // CHECK-NEXT: ret void
+
+void test5(A *a) {
+  __unsafe_unretained A *t = a;
+  gb0 = ^{ (void)a; (void)t; };
+}
+
+// CHECK-LABEL: define void @test5(
+// CHECK: %[[V0:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, {{.*}}*, {{.*}}* }>, <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, {{.*}}*, {{.*}}* }>* %{{.*}}, i32 0, i32 4
+// CHECK: store %[[STRUCT_BLOCK_DESCRIPTOR]]* bitcast ({ i32, i32, i8*, i8*, i8*, i32 }* @[[BLOCK_DESCRIPTOR0]] to %[[STRUCT_BLOCK_DESCRIPTOR]]*), %[[STRUCT_BLOCK_DESCRIPTOR]]** %[[V0]],
+
+void test6(id a, long long b) {
+  void (^block)() = ^{ (void)b; (void)a; };
+}
+
+// Check that the block literal doesn't have two fields for capture 'a'.
+
+// CHECK-LABEL: define void @test6(
+// CHECK: alloca <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i64 }>,
Index: clang/test/CodeGenObjC/arc-blocks.m
===
--- clang/test/CodeGenObjC/arc-blocks.m
+++ clang/test/CodeGenObjC/arc-blocks.m
@@ -8,6 +8,10 @@
 // CHECK-COMMON: @[[BLOCK_DESCRIPTOR_TMP46:.*]] = linkonce_odr hidden unnamed_addr constant { i64, i64, i8*, i8*, i8*, i8* } { i64 0, i64 48, i8* bitcast (void (i8*, i8*)* @__copy_helper_block_8_32s to i8*), i8* bitcast (void (i8*)* @__destroy_helper_block_8_32s to i8*), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @{{.*}}, i32 0, i32 0) }, align 8
 // CHECK-COMMON: @[[BLOCK_DESCRIPTOR_TMP48:.*]] = linkonce_odr hidden unnamed_addr constant { i64, i64, i8*, i8*, i8*, i64 } { i64 0, i64 40, i8* bitcast (void (i8*, i8*)* @__copy_helper_block_8_32b to i8*), i8* bitcast (void (i8*)* @__destroy_helper_block_8_32s to i8*), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @{{.*}}, i32 0, i32 0), i64 256 }, align 8
 
+// Check that no copy/dispose helpers are emitted for this block.
+
+// CHECK-COMMON: @[[BLOCK_DESCRIPTOR_TMP10:.*]] = linkonce_odr hidden unnamed_addr constant { i64, i64, i8*, i8* } { i64 0, i64 40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @{{.*}}, i32 0, i32 0) }, align 8
+
 // This shouldn't crash.
 void test0(id (^maker)(void)) {
   maker();
@@ -769,5 +773,20 @@
   [t m:123, ^{ (void)x; }];
 }
 
+// CHECK-COMMON-LABEL: define internal void @"\01+[Test24 m]"(
+// CHECK-COMMON: %[[BLOCK_DESCRIPTOR:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>, <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>* %{{.*}}, i32 0, i32 4
+// CHECK: store %[[STRUCT_BLOCK_DESCRIPTOR]]* bitcast ({ i64, i64, i8*, i8* }* @[[BLOCK_DESCRIPTOR_TMP10]] to %[[STRUCT_BLOCK_DESCRIPTOR]]*), %[[STRUCT_BLOCK_DESCRIPTOR]]** %[[BLOCK_DESCRIPTOR]],
+
+@interface Test24
+@property (class) void (^block)(void);
++(void)m;
+@end
+
+@implementation Test24
++(void)m {
+  self.block = ^{ (void)self; };
+}
+@end
+
 // CHECK: attributes [[NUW]] = { nounwind }
 // CHECK-UNOPT: attributes [[NUW]] = { nounwind }
Index: clang/lib/CodeGen/CGObjCMac.cpp
===
--- clang/lib/CodeGen/CGObjCMac.cpp
+++ clang/lib/CodeGen/CGObjCMac.cpp
@@ -2935,8 +2935,7 @@
 std::string CGObjCCommonMac::getRCBlockLayoutStr(CodeGenModule &CGM,
  const CGBlockInfo &blockInfo) {
   fillRunSki

[PATCH] D114235: [clang] Extend ParsedAttr to allow custom handling for type attributes

2022-01-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

First off, thank you so much for your patience while I took the time to think 
about this. I know it can be frustrating to not hear review feedback in a 
timely manner, so I'm sorry for that.

I've been sitting on this for a while because type attributes are a complex 
beast. There's the attribute parsing component to it, which is generally pretty 
straightforward and is largely what's handled here in your patch. But the 
bigger issue is the effects on the type system, which is one of the only ways 
to make a type attribute particularly useful. Unfortunately, type system 
effects are scattered all over the code base and can have drastic impact on 
compiler performance (template instantiation depth limits, memory overhead 
pressures, etc), and we tend to have quite a few assertions in the compiler to 
help users catch the places they need to update.

Given that utility from this would require significant changes in Clang itself, 
I'm not certain what a plugin buys us in terms of functionality compared to the 
risk of type attribute plugins making the compiler somewhat unstable in terms 
of performance and potentially even assertions, etc. tl;dr: type attributes 
aren't easily pluggable yet so by the time you make them useful, you basically 
have a clang fork instead of a plugin augmenting Clang. Based on that, I'm 
inclined to not ask you to do further work on it (that work would be akin to me 
asking you "please rework large parts of the type system" which would be a high 
risk activity and not a reasonable request as part of this patch). However, I 
also wanted to hear what your ideas are on how you were expecting to use the 
functionality here from the patch, as maybe there's utility that I'm not 
thinking of.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114235

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


[PATCH] D117024: [clang] Move `ApplyHeaderSearchOptions` from Frontend to Lex

2022-01-11 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 398957.
jansvoboda11 added a comment.

Re-run clang-format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117024

Files:
  clang/include/clang/Frontend/Utils.h
  clang/include/clang/Lex/HeaderSearch.h
  clang/lib/Frontend/CMakeLists.txt
  clang/lib/Frontend/InitHeaderSearch.cpp
  clang/lib/Lex/CMakeLists.txt
  clang/lib/Lex/InitHeaderSearch.cpp
  clang/unittests/Lex/CMakeLists.txt
  clang/unittests/Lex/HeaderSearchTest.cpp

Index: clang/unittests/Lex/HeaderSearchTest.cpp
===
--- clang/unittests/Lex/HeaderSearchTest.cpp
+++ clang/unittests/Lex/HeaderSearchTest.cpp
@@ -15,8 +15,6 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
-#include "clang/Frontend/Utils.h"
-#include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/HeaderSearchOptions.h"
 #include "clang/Serialization/InMemoryModuleCache.h"
 #include "llvm/Support/MemoryBuffer.h"
Index: clang/unittests/Lex/CMakeLists.txt
===
--- clang/unittests/Lex/CMakeLists.txt
+++ clang/unittests/Lex/CMakeLists.txt
@@ -15,7 +15,6 @@
   PRIVATE
   clangAST
   clangBasic
-  clangFrontend
   clangLex
   clangParse
   clangSema
Index: clang/lib/Lex/InitHeaderSearch.cpp
===
--- clang/lib/Lex/InitHeaderSearch.cpp
+++ clang/lib/Lex/InitHeaderSearch.cpp
@@ -10,11 +10,10 @@
 //
 //===--===//
 
+#include "clang/Basic/DiagnosticFrontend.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Config/config.h" // C_INCLUDE_DIRS
-#include "clang/Frontend/FrontendDiagnostic.h"
-#include "clang/Frontend/Utils.h"
 #include "clang/Lex/HeaderMap.h"
 #include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/HeaderSearchOptions.h"
Index: clang/lib/Lex/CMakeLists.txt
===
--- clang/lib/Lex/CMakeLists.txt
+++ clang/lib/Lex/CMakeLists.txt
@@ -6,6 +6,7 @@
   DependencyDirectivesSourceMinimizer.cpp
   HeaderMap.cpp
   HeaderSearch.cpp
+  InitHeaderSearch.cpp
   Lexer.cpp
   LiteralSupport.cpp
   MacroArgs.cpp
Index: clang/lib/Frontend/CMakeLists.txt
===
--- clang/lib/Frontend/CMakeLists.txt
+++ clang/lib/Frontend/CMakeLists.txt
@@ -24,7 +24,6 @@
   FrontendActions.cpp
   FrontendOptions.cpp
   HeaderIncludeGen.cpp
-  InitHeaderSearch.cpp
   InitPreprocessor.cpp
   LayoutOverrideSource.cpp
   LogDiagnosticPrinter.cpp
Index: clang/include/clang/Lex/HeaderSearch.h
===
--- clang/include/clang/Lex/HeaderSearch.h
+++ clang/include/clang/Lex/HeaderSearch.h
@@ -34,6 +34,12 @@
 #include 
 #include 
 
+namespace llvm {
+
+class Triple;
+
+} // namespace llvm
+
 namespace clang {
 
 class DiagnosticsEngine;
@@ -853,6 +859,12 @@
 bool IsSystem, bool IsFramework);
 };
 
+/// Apply the header search options to get given HeaderSearch object.
+void ApplyHeaderSearchOptions(HeaderSearch &HS,
+  const HeaderSearchOptions &HSOpts,
+  const LangOptions &Lang,
+  const llvm::Triple &triple);
+
 } // namespace clang
 
 #endif // LLVM_CLANG_LEX_HEADERSEARCH_H
Index: clang/include/clang/Frontend/Utils.h
===
--- clang/include/clang/Frontend/Utils.h
+++ clang/include/clang/Frontend/Utils.h
@@ -32,12 +32,6 @@
 #include 
 #include 
 
-namespace llvm {
-
-class Triple;
-
-} // namespace llvm
-
 namespace clang {
 
 class ASTReader;
@@ -46,20 +40,11 @@
 class DiagnosticsEngine;
 class ExternalSemaSource;
 class FrontendOptions;
-class HeaderSearch;
-class HeaderSearchOptions;
-class LangOptions;
 class PCHContainerReader;
 class Preprocessor;
 class PreprocessorOptions;
 class PreprocessorOutputOptions;
 
-/// Apply the header search options to get given HeaderSearch object.
-void ApplyHeaderSearchOptions(HeaderSearch &HS,
-  const HeaderSearchOptions &HSOpts,
-  const LangOptions &Lang,
-  const llvm::Triple &triple);
-
 /// InitializePreprocessor - Initialize the preprocessor getting it and the
 /// environment ready to process a single file.
 void InitializePreprocessor(Preprocessor &PP, const PreprocessorOptions &PPOpts,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D117024: [clang] Move `ApplyHeaderSearchOptions` from Frontend to Lex

2022-01-11 Thread Nico Weber via Phabricator via cfe-commits
thakis accepted this revision.
thakis added a comment.
This revision is now accepted and ready to land.

That was easy :) Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117024

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


[PATCH] D116775: [clang][#47272] Avoid suggesting deprecated version of a declaration over another in typo correction

2022-01-11 Thread Markus Böck via Phabricator via cfe-commits
zero9178 updated this revision to Diff 398962.
zero9178 added a comment.

Addressed reviewer nits:

- Used proper naming conventions
- Adjusted tests


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

https://reviews.llvm.org/D116775

Files:
  clang/lib/Sema/SemaLookup.cpp
  clang/test/SemaCXX/typo-correction.cpp


Index: clang/test/SemaCXX/typo-correction.cpp
===
--- clang/test/SemaCXX/typo-correction.cpp
+++ clang/test/SemaCXX/typo-correction.cpp
@@ -757,3 +757,34 @@
 b = g_volatile_uchar // expected-error {{did you mean 'g_volatile_char'}}
   };
 }
+
+namespace PR47272
+{
+
+namespace Views {
+int Take(); // expected-note{{'Views::Take' declared here}}
+}
+
+namespace [[deprecated("use Views instead")]] View {
+using Views::Take;
+}
+
+namespace [[deprecated]] A { // expected-note{{'A' has been explicitly marked 
deprecated here}}
+int pr47272;
+}
+
+namespace B {
+using A::pr47272;  // expected-note{{'B::pr47272' declared here}} 
expected-warning{{'A' is deprecated}}
+}
+
+namespace [[deprecated]] C {
+using A::pr47272;
+}
+
+void function() {
+  int x = ::Take(); // expected-error{{no member named 'Take' in the global 
namespace; did you mean 'Views::Take'?}}
+  int y = ::pr47272; // expected-error{{no member named 'pr47272' in the 
global namespace; did you mean 'B::pr47272'?}}
+}
+}
+
+
Index: clang/lib/Sema/SemaLookup.cpp
===
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -4307,18 +4307,35 @@
   if (!CList.empty() && !CList.back().isResolved())
 CList.pop_back();
   if (NamedDecl *NewND = Correction.getCorrectionDecl()) {
-std::string CorrectionStr = Correction.getAsString(SemaRef.getLangOpts());
-for (TypoResultList::iterator RI = CList.begin(), RIEnd = CList.end();
- RI != RIEnd; ++RI) {
-  // If the Correction refers to a decl already in the result list,
-  // replace the existing result if the string representation of Correction
-  // comes before the current result alphabetically, then stop as there is
-  // nothing more to be done to add Correction to the candidate set.
-  if (RI->getCorrectionDecl() == NewND) {
-if (CorrectionStr < RI->getAsString(SemaRef.getLangOpts()))
-  *RI = Correction;
-return;
-  }
+auto RI = llvm::find_if(CList, [NewND](const TypoCorrection &TypoCorr) {
+  return TypoCorr.getCorrectionDecl() == NewND;
+});
+if (RI != CList.end()) {
+  // The Correction refers to a decl already in the list. No insertion is
+  // necessary and all further cases will return.
+
+  auto IsDeprecated = [](Decl *D) {
+while (D) {
+  if (D->isDeprecated())
+return true;
+  D = llvm::dyn_cast_or_null(D->getDeclContext());
+}
+return false;
+  };
+
+  // Prefer non deprecated Corrections over deprecated and only then
+  // sort using an alphabetical order.
+  std::pair NewKey = {
+  IsDeprecated(Correction.getFoundDecl()),
+  Correction.getAsString(SemaRef.getLangOpts())};
+
+  std::pair PrevKey = {
+  IsDeprecated(RI->getFoundDecl()),
+  RI->getAsString(SemaRef.getLangOpts())};
+
+  if (NewKey < PrevKey)
+*RI = Correction;
+  return;
 }
   }
   if (CList.empty() || Correction.isResolved())


Index: clang/test/SemaCXX/typo-correction.cpp
===
--- clang/test/SemaCXX/typo-correction.cpp
+++ clang/test/SemaCXX/typo-correction.cpp
@@ -757,3 +757,34 @@
 b = g_volatile_uchar // expected-error {{did you mean 'g_volatile_char'}}
   };
 }
+
+namespace PR47272
+{
+
+namespace Views {
+int Take(); // expected-note{{'Views::Take' declared here}}
+}
+
+namespace [[deprecated("use Views instead")]] View {
+using Views::Take;
+}
+
+namespace [[deprecated]] A { // expected-note{{'A' has been explicitly marked deprecated here}}
+int pr47272;
+}
+
+namespace B {
+using A::pr47272;  // expected-note{{'B::pr47272' declared here}} expected-warning{{'A' is deprecated}}
+}
+
+namespace [[deprecated]] C {
+using A::pr47272;
+}
+
+void function() {
+  int x = ::Take(); // expected-error{{no member named 'Take' in the global namespace; did you mean 'Views::Take'?}}
+  int y = ::pr47272; // expected-error{{no member named 'pr47272' in the global namespace; did you mean 'B::pr47272'?}}
+}
+}
+
+
Index: clang/lib/Sema/SemaLookup.cpp
===
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -4307,18 +4307,35 @@
   if (!CList.empty() && !CList.back().isResolved())
 CList.pop_back();
   if (NamedDecl *NewND = Correction.getCorrectionDecl()) {
-std::string CorrectionStr = Correction.getAsString(SemaRef.getLangOpts());
-for (TypoResultList::iterator RI = CList.begin(), RIEnd = CList.

[clang] f77d115 - [clang] Move `ApplyHeaderSearchOptions` from Frontend to Lex

2022-01-11 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2022-01-11T17:57:40+01:00
New Revision: f77d115cc136585f39d30a78c741eb296f9e804d

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

LOG: [clang] Move `ApplyHeaderSearchOptions` from Frontend to Lex

In D116750, the `clangFrontend` library was added as a dependency of `LexTests` 
in order to make `clang::ApplyHeaderSearchOptions()` available. This increased 
the number of TUs the test depends on.

This patch moves the function into `clangLex` and removes dependency of 
`LexTests` on `clangFrontend`.

Reviewed By: thakis

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

Added: 
clang/lib/Lex/InitHeaderSearch.cpp

Modified: 
clang/include/clang/Frontend/Utils.h
clang/include/clang/Lex/HeaderSearch.h
clang/lib/Frontend/CMakeLists.txt
clang/lib/Lex/CMakeLists.txt
clang/unittests/Lex/CMakeLists.txt
clang/unittests/Lex/HeaderSearchTest.cpp

Removed: 
clang/lib/Frontend/InitHeaderSearch.cpp



diff  --git a/clang/include/clang/Frontend/Utils.h 
b/clang/include/clang/Frontend/Utils.h
index da2d79af2ebaa..a05584bfe5514 100644
--- a/clang/include/clang/Frontend/Utils.h
+++ b/clang/include/clang/Frontend/Utils.h
@@ -32,12 +32,6 @@
 #include 
 #include 
 
-namespace llvm {
-
-class Triple;
-
-} // namespace llvm
-
 namespace clang {
 
 class ASTReader;
@@ -46,20 +40,11 @@ class CompilerInvocation;
 class DiagnosticsEngine;
 class ExternalSemaSource;
 class FrontendOptions;
-class HeaderSearch;
-class HeaderSearchOptions;
-class LangOptions;
 class PCHContainerReader;
 class Preprocessor;
 class PreprocessorOptions;
 class PreprocessorOutputOptions;
 
-/// Apply the header search options to get given HeaderSearch object.
-void ApplyHeaderSearchOptions(HeaderSearch &HS,
-  const HeaderSearchOptions &HSOpts,
-  const LangOptions &Lang,
-  const llvm::Triple &triple);
-
 /// InitializePreprocessor - Initialize the preprocessor getting it and the
 /// environment ready to process a single file.
 void InitializePreprocessor(Preprocessor &PP, const PreprocessorOptions 
&PPOpts,

diff  --git a/clang/include/clang/Lex/HeaderSearch.h 
b/clang/include/clang/Lex/HeaderSearch.h
index 5507401f608a5..0b7ada8f9449c 100644
--- a/clang/include/clang/Lex/HeaderSearch.h
+++ b/clang/include/clang/Lex/HeaderSearch.h
@@ -34,6 +34,12 @@
 #include 
 #include 
 
+namespace llvm {
+
+class Triple;
+
+} // namespace llvm
+
 namespace clang {
 
 class DiagnosticsEngine;
@@ -853,6 +859,12 @@ class HeaderSearch {
 bool IsSystem, bool IsFramework);
 };
 
+/// Apply the header search options to get given HeaderSearch object.
+void ApplyHeaderSearchOptions(HeaderSearch &HS,
+  const HeaderSearchOptions &HSOpts,
+  const LangOptions &Lang,
+  const llvm::Triple &triple);
+
 } // namespace clang
 
 #endif // LLVM_CLANG_LEX_HEADERSEARCH_H

diff  --git a/clang/lib/Frontend/CMakeLists.txt 
b/clang/lib/Frontend/CMakeLists.txt
index 90422855bd059..ca4ad8b2dab2e 100644
--- a/clang/lib/Frontend/CMakeLists.txt
+++ b/clang/lib/Frontend/CMakeLists.txt
@@ -24,7 +24,6 @@ add_clang_library(clangFrontend
   FrontendActions.cpp
   FrontendOptions.cpp
   HeaderIncludeGen.cpp
-  InitHeaderSearch.cpp
   InitPreprocessor.cpp
   LayoutOverrideSource.cpp
   LogDiagnosticPrinter.cpp

diff  --git a/clang/lib/Lex/CMakeLists.txt b/clang/lib/Lex/CMakeLists.txt
index d77e6ddb66a07..44f0149628c88 100644
--- a/clang/lib/Lex/CMakeLists.txt
+++ b/clang/lib/Lex/CMakeLists.txt
@@ -6,6 +6,7 @@ add_clang_library(clangLex
   DependencyDirectivesSourceMinimizer.cpp
   HeaderMap.cpp
   HeaderSearch.cpp
+  InitHeaderSearch.cpp
   Lexer.cpp
   LiteralSupport.cpp
   MacroArgs.cpp

diff  --git a/clang/lib/Frontend/InitHeaderSearch.cpp 
b/clang/lib/Lex/InitHeaderSearch.cpp
similarity index 99%
rename from clang/lib/Frontend/InitHeaderSearch.cpp
rename to clang/lib/Lex/InitHeaderSearch.cpp
index 94ea7baa99c50..ec7b1505c7bf3 100644
--- a/clang/lib/Frontend/InitHeaderSearch.cpp
+++ b/clang/lib/Lex/InitHeaderSearch.cpp
@@ -10,11 +10,10 @@
 //
 
//===--===//
 
+#include "clang/Basic/DiagnosticFrontend.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Config/config.h" // C_INCLUDE_DIRS
-#include "clang/Frontend/FrontendDiagnostic.h"
-#include "clang/Frontend/Utils.h"
 #include "clang/Lex/HeaderMap.h"
 #include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/HeaderSearchOptions.h"

diff  --git a/clang/unittests/Lex/CMakeLists.txt 
b/clang/unittests/Lex/CMakeLists.txt
index 3b3e3709ab062..97a4e5e44608c 10064

[PATCH] D117024: [clang] Move `ApplyHeaderSearchOptions` from Frontend to Lex

2022-01-11 Thread Jan Svoboda 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 rGf77d115cc136: [clang] Move `ApplyHeaderSearchOptions` from 
Frontend to Lex (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117024

Files:
  clang/include/clang/Frontend/Utils.h
  clang/include/clang/Lex/HeaderSearch.h
  clang/lib/Frontend/CMakeLists.txt
  clang/lib/Frontend/InitHeaderSearch.cpp
  clang/lib/Lex/CMakeLists.txt
  clang/lib/Lex/InitHeaderSearch.cpp
  clang/unittests/Lex/CMakeLists.txt
  clang/unittests/Lex/HeaderSearchTest.cpp

Index: clang/unittests/Lex/HeaderSearchTest.cpp
===
--- clang/unittests/Lex/HeaderSearchTest.cpp
+++ clang/unittests/Lex/HeaderSearchTest.cpp
@@ -15,8 +15,6 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
-#include "clang/Frontend/Utils.h"
-#include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/HeaderSearchOptions.h"
 #include "clang/Serialization/InMemoryModuleCache.h"
 #include "llvm/Support/MemoryBuffer.h"
Index: clang/unittests/Lex/CMakeLists.txt
===
--- clang/unittests/Lex/CMakeLists.txt
+++ clang/unittests/Lex/CMakeLists.txt
@@ -15,7 +15,6 @@
   PRIVATE
   clangAST
   clangBasic
-  clangFrontend
   clangLex
   clangParse
   clangSema
Index: clang/lib/Lex/InitHeaderSearch.cpp
===
--- clang/lib/Lex/InitHeaderSearch.cpp
+++ clang/lib/Lex/InitHeaderSearch.cpp
@@ -10,11 +10,10 @@
 //
 //===--===//
 
+#include "clang/Basic/DiagnosticFrontend.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Config/config.h" // C_INCLUDE_DIRS
-#include "clang/Frontend/FrontendDiagnostic.h"
-#include "clang/Frontend/Utils.h"
 #include "clang/Lex/HeaderMap.h"
 #include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/HeaderSearchOptions.h"
Index: clang/lib/Lex/CMakeLists.txt
===
--- clang/lib/Lex/CMakeLists.txt
+++ clang/lib/Lex/CMakeLists.txt
@@ -6,6 +6,7 @@
   DependencyDirectivesSourceMinimizer.cpp
   HeaderMap.cpp
   HeaderSearch.cpp
+  InitHeaderSearch.cpp
   Lexer.cpp
   LiteralSupport.cpp
   MacroArgs.cpp
Index: clang/lib/Frontend/CMakeLists.txt
===
--- clang/lib/Frontend/CMakeLists.txt
+++ clang/lib/Frontend/CMakeLists.txt
@@ -24,7 +24,6 @@
   FrontendActions.cpp
   FrontendOptions.cpp
   HeaderIncludeGen.cpp
-  InitHeaderSearch.cpp
   InitPreprocessor.cpp
   LayoutOverrideSource.cpp
   LogDiagnosticPrinter.cpp
Index: clang/include/clang/Lex/HeaderSearch.h
===
--- clang/include/clang/Lex/HeaderSearch.h
+++ clang/include/clang/Lex/HeaderSearch.h
@@ -34,6 +34,12 @@
 #include 
 #include 
 
+namespace llvm {
+
+class Triple;
+
+} // namespace llvm
+
 namespace clang {
 
 class DiagnosticsEngine;
@@ -853,6 +859,12 @@
 bool IsSystem, bool IsFramework);
 };
 
+/// Apply the header search options to get given HeaderSearch object.
+void ApplyHeaderSearchOptions(HeaderSearch &HS,
+  const HeaderSearchOptions &HSOpts,
+  const LangOptions &Lang,
+  const llvm::Triple &triple);
+
 } // namespace clang
 
 #endif // LLVM_CLANG_LEX_HEADERSEARCH_H
Index: clang/include/clang/Frontend/Utils.h
===
--- clang/include/clang/Frontend/Utils.h
+++ clang/include/clang/Frontend/Utils.h
@@ -32,12 +32,6 @@
 #include 
 #include 
 
-namespace llvm {
-
-class Triple;
-
-} // namespace llvm
-
 namespace clang {
 
 class ASTReader;
@@ -46,20 +40,11 @@
 class DiagnosticsEngine;
 class ExternalSemaSource;
 class FrontendOptions;
-class HeaderSearch;
-class HeaderSearchOptions;
-class LangOptions;
 class PCHContainerReader;
 class Preprocessor;
 class PreprocessorOptions;
 class PreprocessorOutputOptions;
 
-/// Apply the header search options to get given HeaderSearch object.
-void ApplyHeaderSearchOptions(HeaderSearch &HS,
-  const HeaderSearchOptions &HSOpts,
-  const LangOptions &Lang,
-  const llvm::Triple &triple);
-
 /// InitializePreprocessor - Initialize the preprocessor getting it and the
 /// environment ready to process a single file.
 void InitializePreprocessor(Preprocessor &PP, const PreprocessorOptions &PPOpts,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://

[clang] 4b14fc6 - [SPIR-V] Drop double quote from test pattern

2022-01-11 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-01-11T16:58:08Z
New Revision: 4b14fc6fe5a7d01fb42a3cdede77c59f03b867af

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

LOG: [SPIR-V] Drop double quote from test pattern

When spirv-link is found, it won't match a leading `"`.  This fixes
the test added by commit dbb8d086377b ("[SPIR-V] Add linking using
spirv-link.", 2022-01-11).

Added: 


Modified: 
clang/test/Driver/spirv-toolchain.cl

Removed: 




diff  --git a/clang/test/Driver/spirv-toolchain.cl 
b/clang/test/Driver/spirv-toolchain.cl
index c2fcb3577259..5c95a5748842 100644
--- a/clang/test/Driver/spirv-toolchain.cl
+++ b/clang/test/Driver/spirv-toolchain.cl
@@ -68,4 +68,4 @@
 // SPLINK: clang{{.*}} "-cc1" "-triple" "spirv64"
 // SPLINK-SAME: "-o" [[BC:".*bc"]]
 // SPLINK: {{llvm-spirv.*"}} [[BC]] "-o" [[SPV2:".*o"]]
-// SPLINK: {{"spirv-link.*"}} [[SPV1]] [[SPV2]] "-o" "a.out"
+// SPLINK: {{spirv-link.*"}} [[SPV1]] [[SPV2]] "-o" "a.out"



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


[PATCH] D116266: [SPIR-V] Add linking of separate translation units using spirv-link

2022-01-11 Thread Alexandre Ganea via Phabricator via cfe-commits
aganea added inline comments.



Comment at: clang/test/Driver/spirv-toolchain.cl:71
+// SPLINK: {{llvm-spirv.*"}} [[BC]] "-o" [[SPV2:".*o"]]
+// SPLINK: {{"spirv-link.*"}} [[SPV1]] [[SPV2]] "-o" "a.out"

Hello @Anastasia, this line fails on my machine. It works with `// SPLINK: 
spirv-link{{.*}} [[SPV1]] [[SPV2]] "-o" "a.out"
`

See output with the error:
```
FAIL: Clang :: Driver/spirv-toolchain.cl (579 of 81682)
 TEST 'Clang :: Driver/spirv-toolchain.cl' FAILED 

Script:
--
: 'RUN: at line 2';   d:\git\llvm-project\release\bin\clang.exe -### 
--target=spirv64 -x cl -c 
D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPV64 
D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
: 'RUN: at line 3';   d:\git\llvm-project\release\bin\clang.exe -### 
--target=spirv64 D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 
| d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPV64 
D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
: 'RUN: at line 4';   d:\git\llvm-project\release\bin\clang.exe -### 
--target=spirv64 -x ir -c 
D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPV64 
D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
: 'RUN: at line 5';   d:\git\llvm-project\release\bin\clang.exe -### 
--target=spirv64 -x clcpp -c 
D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPV64 
D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
: 'RUN: at line 6';   d:\git\llvm-project\release\bin\clang.exe -### 
--target=spirv64 -x c -c 
D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPV64 
D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
: 'RUN: at line 12';   d:\git\llvm-project\release\bin\clang.exe -### 
--target=spirv32 -x cl -c 
D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPV32 
D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
: 'RUN: at line 13';   d:\git\llvm-project\release\bin\clang.exe -### 
--target=spirv32 D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 
| d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPV32 
D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
: 'RUN: at line 14';   d:\git\llvm-project\release\bin\clang.exe -### 
--target=spirv32 -x ir -c 
D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPV32 
D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
: 'RUN: at line 15';   d:\git\llvm-project\release\bin\clang.exe -### 
--target=spirv32 -x clcpp -c 
D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPV32 
D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
: 'RUN: at line 16';   d:\git\llvm-project\release\bin\clang.exe -### 
--target=spirv32 -x c -c 
D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPV32 
D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
: 'RUN: at line 24';   d:\git\llvm-project\release\bin\clang.exe -### 
--target=spirv64 -x cl -S 
D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPT64 
D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
: 'RUN: at line 25';   d:\git\llvm-project\release\bin\clang.exe -### 
--target=spirv64 -x ir -S 
D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPT64 
D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
: 'RUN: at line 26';   d:\git\llvm-project\release\bin\clang.exe -### 
--target=spirv64 -x clcpp -c 
D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPV64 
D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
: 'RUN: at line 27';   d:\git\llvm-project\release\bin\clang.exe -### 
--target=spirv64 -x c -S 
D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPT64 
D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
: 'RUN: at line 33';   d:\git\llvm-project\release\bin\clang.exe -### 
--target=spirv32 -x cl -S 
D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPT32 
D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
: 'RUN: at line 34';   d:\git\llvm-project\release\bin\clang.exe -### 
--target=spirv32 -x ir -S 
D:\git\llvm-project\clang\test\Driver\spirv-to

[PATCH] D116935: [IRBuilder] Introduce folder using inst-simplify, use for Or fold.

2022-01-11 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

In D116935#3233751 , @fhahn wrote:

> Another rebase. I am planning to land this later today, unless there are 
> additional concerns with respect to the fold in Clang after my latest 
> response.

Thanks, Florian. I have no additional concerns.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116935

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


[PATCH] D116266: [SPIR-V] Add linking of separate translation units using spirv-link

2022-01-11 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added inline comments.



Comment at: clang/test/Driver/spirv-toolchain.cl:71
+// SPLINK: {{llvm-spirv.*"}} [[BC]] "-o" [[SPV2:".*o"]]
+// SPLINK: {{"spirv-link.*"}} [[SPV1]] [[SPV2]] "-o" "a.out"

aganea wrote:
> Hello @Anastasia, this line fails on my machine. It works with `// SPLINK: 
> spirv-link{{.*}} [[SPV1]] [[SPV2]] "-o" "a.out"
> `
> 
> See output with the error:
> ```
> FAIL: Clang :: Driver/spirv-toolchain.cl (579 of 81682)
>  TEST 'Clang :: Driver/spirv-toolchain.cl' FAILED 
> 
> Script:
> --
> : 'RUN: at line 2';   d:\git\llvm-project\release\bin\clang.exe -### 
> --target=spirv64 -x cl -c 
> D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
> d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPV64 
> D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
> : 'RUN: at line 3';   d:\git\llvm-project\release\bin\clang.exe -### 
> --target=spirv64 D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 
> 2>&1 | d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPV64 
> D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
> : 'RUN: at line 4';   d:\git\llvm-project\release\bin\clang.exe -### 
> --target=spirv64 -x ir -c 
> D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
> d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPV64 
> D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
> : 'RUN: at line 5';   d:\git\llvm-project\release\bin\clang.exe -### 
> --target=spirv64 -x clcpp -c 
> D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
> d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPV64 
> D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
> : 'RUN: at line 6';   d:\git\llvm-project\release\bin\clang.exe -### 
> --target=spirv64 -x c -c 
> D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
> d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPV64 
> D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
> : 'RUN: at line 12';   d:\git\llvm-project\release\bin\clang.exe -### 
> --target=spirv32 -x cl -c 
> D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
> d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPV32 
> D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
> : 'RUN: at line 13';   d:\git\llvm-project\release\bin\clang.exe -### 
> --target=spirv32 D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 
> 2>&1 | d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPV32 
> D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
> : 'RUN: at line 14';   d:\git\llvm-project\release\bin\clang.exe -### 
> --target=spirv32 -x ir -c 
> D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
> d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPV32 
> D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
> : 'RUN: at line 15';   d:\git\llvm-project\release\bin\clang.exe -### 
> --target=spirv32 -x clcpp -c 
> D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
> d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPV32 
> D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
> : 'RUN: at line 16';   d:\git\llvm-project\release\bin\clang.exe -### 
> --target=spirv32 -x c -c 
> D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
> d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPV32 
> D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
> : 'RUN: at line 24';   d:\git\llvm-project\release\bin\clang.exe -### 
> --target=spirv64 -x cl -S 
> D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
> d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPT64 
> D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
> : 'RUN: at line 25';   d:\git\llvm-project\release\bin\clang.exe -### 
> --target=spirv64 -x ir -S 
> D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
> d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPT64 
> D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
> : 'RUN: at line 26';   d:\git\llvm-project\release\bin\clang.exe -### 
> --target=spirv64 -x clcpp -c 
> D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
> d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPV64 
> D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
> : 'RUN: at line 27';   d:\git\llvm-project\release\bin\clang.exe -### 
> --target=spirv64 -x c -S 
> D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
> d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPT64 
> D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
> : 'RUN: at line 33';   d:\git\llvm-project\release\bin\clang.exe -### 
> --target=spirv32 -x cl -S 
> D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
> d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPT32 
> D:\git\llvm-project

[PATCH] D116266: [SPIR-V] Add linking of separate translation units using spirv-link

2022-01-11 Thread Alexandre Ganea via Phabricator via cfe-commits
aganea added inline comments.



Comment at: clang/test/Driver/spirv-toolchain.cl:71
+// SPLINK: {{llvm-spirv.*"}} [[BC]] "-o" [[SPV2:".*o"]]
+// SPLINK: {{"spirv-link.*"}} [[SPV1]] [[SPV2]] "-o" "a.out"

svenvh wrote:
> aganea wrote:
> > Hello @Anastasia, this line fails on my machine. It works with `// SPLINK: 
> > spirv-link{{.*}} [[SPV1]] [[SPV2]] "-o" "a.out"
> > `
> > 
> > See output with the error:
> > ```
> > FAIL: Clang :: Driver/spirv-toolchain.cl (579 of 81682)
> >  TEST 'Clang :: Driver/spirv-toolchain.cl' FAILED 
> > 
> > Script:
> > --
> > : 'RUN: at line 2';   d:\git\llvm-project\release\bin\clang.exe -### 
> > --target=spirv64 -x cl -c 
> > D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
> > d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPV64 
> > D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
> > : 'RUN: at line 3';   d:\git\llvm-project\release\bin\clang.exe -### 
> > --target=spirv64 D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 
> > 2>&1 | d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPV64 
> > D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
> > : 'RUN: at line 4';   d:\git\llvm-project\release\bin\clang.exe -### 
> > --target=spirv64 -x ir -c 
> > D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
> > d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPV64 
> > D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
> > : 'RUN: at line 5';   d:\git\llvm-project\release\bin\clang.exe -### 
> > --target=spirv64 -x clcpp -c 
> > D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
> > d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPV64 
> > D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
> > : 'RUN: at line 6';   d:\git\llvm-project\release\bin\clang.exe -### 
> > --target=spirv64 -x c -c 
> > D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
> > d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPV64 
> > D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
> > : 'RUN: at line 12';   d:\git\llvm-project\release\bin\clang.exe -### 
> > --target=spirv32 -x cl -c 
> > D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
> > d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPV32 
> > D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
> > : 'RUN: at line 13';   d:\git\llvm-project\release\bin\clang.exe -### 
> > --target=spirv32 D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 
> > 2>&1 | d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPV32 
> > D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
> > : 'RUN: at line 14';   d:\git\llvm-project\release\bin\clang.exe -### 
> > --target=spirv32 -x ir -c 
> > D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
> > d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPV32 
> > D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
> > : 'RUN: at line 15';   d:\git\llvm-project\release\bin\clang.exe -### 
> > --target=spirv32 -x clcpp -c 
> > D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
> > d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPV32 
> > D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
> > : 'RUN: at line 16';   d:\git\llvm-project\release\bin\clang.exe -### 
> > --target=spirv32 -x c -c 
> > D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
> > d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPV32 
> > D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
> > : 'RUN: at line 24';   d:\git\llvm-project\release\bin\clang.exe -### 
> > --target=spirv64 -x cl -S 
> > D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
> > d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPT64 
> > D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
> > : 'RUN: at line 25';   d:\git\llvm-project\release\bin\clang.exe -### 
> > --target=spirv64 -x ir -S 
> > D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
> > d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPT64 
> > D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
> > : 'RUN: at line 26';   d:\git\llvm-project\release\bin\clang.exe -### 
> > --target=spirv64 -x clcpp -c 
> > D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
> > d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPV64 
> > D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
> > : 'RUN: at line 27';   d:\git\llvm-project\release\bin\clang.exe -### 
> > --target=spirv64 -x c -S 
> > D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl 2>&1 | 
> > d:\git\llvm-project\release\bin\filecheck.exe --check-prefix=SPT64 
> > D:\git\llvm-project\clang\test\Driver\spirv-toolchain.cl
> > : 'RUN: at line 33';   d:\git\llvm-project\release\bin\clang.exe -### 
> > --targe

[PATCH] D114564: Fix the use of -fno-approx-func along with -Ofast or -ffast-math

2022-01-11 Thread Masoud Ataei via Phabricator via cfe-commits
masoud.ataei added a comment.

A gentle reminder for reviewers. -- This patch will fix the bug reported here: 
https://bugs.llvm.org/show_bug.cgi?id=52565


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114564

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


[PATCH] D112913: Misleading bidirectional detection

2022-01-11 Thread serge via Phabricator via cfe-commits
serge-sans-paille added a comment.

In D112913#3233699 , @upsuper wrote:

> I'd like to clarify that what I think is correct now is the algorithm to 
> detect unclosed explicit formatting scopes in a given string.

Thanks for confirming. This check only detects unterminated bidi sequence 
within comments and string literals. Its scope limits to that aspect.

> I haven't been following very closely with the whole spoofing issue, so I 
> can't say that there is no other ways to construct a spoof that this 
> algorithm is not designed to detect.

Agreed. FYI we already have a check for RTL characters ending identfiers, and a 
pending one for confusable identifiers

> As you have found, `RLM`, and `ALM` can be used to confuse code reader, but 
> they are not much different than a string with other strong RTL characters 
> inside, and I don't quite see how that can be linted without hurting 
> potentially legitimate code. Maybe if the compiler supports treating `LRM` as 
> whitespace (I'm not sure whether Clang does), a lint may be added to ask 
> wrapping any string with outermost strong characters being RTL in the form of 
> `{LRM}"string"{LRM}` so that the RTL characters don't affect outside. Other 
> than that, I don't think there is anyway to lint against such a confusion.

I agree that allowing `LRM` is a good step forward, and that's part of the 
official recommendation, but orthogonal to that review.


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

https://reviews.llvm.org/D112913

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


[clang] ee25a32 - [clang-format] Fix SeparateDefinitionBlocks issues

2022-01-11 Thread via cfe-commits

Author: ksyx
Date: 2022-01-11T12:25:39-05:00
New Revision: ee25a327aac0eeae28f468a741b58ec7689de5f2

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

LOG: [clang-format] Fix SeparateDefinitionBlocks issues

Fixes https://github.com/llvm/llvm-project/issues/52976.

- Make no formatting for macros
- Attach comment with definition headers
- Make no change on use of empty lines at block start/end
- Fix misrecognition of keyword namespace

Differential Revision: https://reviews.llvm.org/D116663
Reviewed By: MyDeveloperDay, HazardyKnusperkeks, curdeius

Added: 


Modified: 
clang/lib/Format/DefinitionBlockSeparator.cpp
clang/unittests/Format/DefinitionBlockSeparatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/DefinitionBlockSeparator.cpp 
b/clang/lib/Format/DefinitionBlockSeparator.cpp
index 7f6a7fa1b5dfa..504392cb61422 100644
--- a/clang/lib/Format/DefinitionBlockSeparator.cpp
+++ b/clang/lib/Format/DefinitionBlockSeparator.cpp
@@ -31,15 +31,16 @@ std::pair 
DefinitionBlockSeparator::analyze(
 
 void DefinitionBlockSeparator::separateBlocks(
 SmallVectorImpl &Lines, tooling::Replacements &Result) {
+  const bool IsNeverStyle =
+  Style.SeparateDefinitionBlocks == FormatStyle::SDS_Never;
   auto LikelyDefinition = [this](const AnnotatedLine *Line) {
-if (Line->MightBeFunctionDecl && Line->mightBeFunctionDefinition())
+if ((Line->MightBeFunctionDecl && Line->mightBeFunctionDefinition()) ||
+Line->startsWithNamespace())
   return true;
 FormatToken *CurrentToken = Line->First;
 while (CurrentToken) {
-  if (CurrentToken->isOneOf(tok::kw_class, tok::kw_struct,
-tok::kw_namespace, tok::kw_enum) ||
-  (Style.Language == FormatStyle::LK_JavaScript &&
-   CurrentToken->TokenText == "function"))
+  if (CurrentToken->isOneOf(tok::kw_class, tok::kw_struct, tok::kw_enum) ||
+  (Style.isJavaScript() && CurrentToken->TokenText == "function"))
 return true;
   CurrentToken = CurrentToken->Next;
 }
@@ -54,11 +55,14 @@ void DefinitionBlockSeparator::separateBlocks(
 Env.getSourceManager().getBufferData(Env.getFileID()),
 Style.UseCRLF)
   : Style.UseCRLF);
-  for (unsigned I = 0; I < Lines.size(); I++) {
+  for (unsigned I = 0; I < Lines.size(); ++I) {
 const auto &CurrentLine = Lines[I];
+if (CurrentLine->InPPDirective)
+  continue;
 FormatToken *TargetToken = nullptr;
 AnnotatedLine *TargetLine;
 auto OpeningLineIndex = CurrentLine->MatchingOpeningBlockLineIndex;
+AnnotatedLine *OpeningLine = nullptr;
 const auto InsertReplacement = [&](const int NewlineToInsert) {
   assert(TargetLine);
   assert(TargetToken);
@@ -72,9 +76,18 @@ void DefinitionBlockSeparator::separateBlocks(
 TargetToken->SpacesRequiredBefore - 1,
 TargetToken->StartsColumn);
 };
+const auto IsPPConditional = [&](const size_t LineIndex) {
+  const auto &Line = Lines[LineIndex];
+  return Line->First->is(tok::hash) && Line->First->Next &&
+ Line->First->Next->isOneOf(tok::pp_if, tok::pp_ifdef, 
tok::pp_else,
+tok::pp_ifndef, tok::pp_elifndef,
+tok::pp_elifdef, tok::pp_elif,
+tok::pp_endif);
+};
 const auto FollowingOtherOpening = [&]() {
   return OpeningLineIndex == 0 ||
- Lines[OpeningLineIndex - 1]->Last->opensScope();
+ Lines[OpeningLineIndex - 1]->Last->opensScope() ||
+ IsPPConditional(OpeningLineIndex - 1);
 };
 const auto HasEnumOnLine = [CurrentLine]() {
   FormatToken *CurrentToken = CurrentLine->First;
@@ -87,17 +100,29 @@ void DefinitionBlockSeparator::separateBlocks(
 };
 
 bool IsDefBlock = false;
+const auto MayPrecedeDefinition = [&](const int Direction = -1) {
+  const size_t OperateIndex = OpeningLineIndex + Direction;
+  assert(OperateIndex < Lines.size());
+  const auto &OperateLine = Lines[OperateIndex];
+  return (Style.isCSharp() && OperateLine->First->is(TT_AttributeSquare)) 
||
+ OperateLine->First->is(tok::comment);
+};
 
 if (HasEnumOnLine()) {
   // We have no scope opening/closing information for enum.
   IsDefBlock = true;
   OpeningLineIndex = I;
-  TargetLine = CurrentLine;
-  TargetToken = CurrentLine->First;
+  while (OpeningLineIndex > 0 && MayPrecedeDefinition())
+--OpeningLineIndex;
+  OpeningLine = Lines[OpeningLineIndex];
+  TargetLine = OpeningLine;
+  TargetToken = TargetLine->First;
   if (!FollowingOtherOpening())

[PATCH] D116663: [clang-format] Fix SeparateDefinitionBlocks issues

2022-01-11 Thread ksyx via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGee25a327aac0: [clang-format] Fix SeparateDefinitionBlocks 
issues (authored by ksyx).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116663

Files:
  clang/lib/Format/DefinitionBlockSeparator.cpp
  clang/unittests/Format/DefinitionBlockSeparatorTest.cpp

Index: clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
===
--- clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
+++ clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
@@ -57,8 +57,9 @@
   InverseStyle.SeparateDefinitionBlocks = FormatStyle::SDS_Always;
 EXPECT_EQ(ExpectedCode.str(), separateDefinitionBlocks(ExpectedCode, Style))
 << "Expected code is not stable";
-std::string InverseResult = separateDefinitionBlocks(Code, InverseStyle);
-EXPECT_NE(Code.str(), InverseResult)
+std::string InverseResult =
+separateDefinitionBlocks(ExpectedCode, InverseStyle);
+EXPECT_NE(ExpectedCode.str(), InverseResult)
 << "Inverse formatting makes no difference";
 std::string CodeToFormat =
 HasOriginalCode ? Code.str() : removeEmptyLines(Code);
@@ -129,49 +130,166 @@
Style);
 }
 
+TEST_F(DefinitionBlockSeparatorTest, UntouchBlockStartStyle) {
+  // Returns a std::pair of two strings, with the first one for passing into
+  // Always test and the second one be the expected result of the first string.
+  auto MakeUntouchTest = [&](std::string BlockHeader, std::string BlockChanger,
+ std::string BlockFooter, bool BlockEndNewLine) {
+std::string CodePart1 = "enum Foo { FOO, BAR };\n"
+"\n"
+"/*\n"
+"test1\n"
+"test2\n"
+"*/\n"
+"int foo(int i, int j) {\n"
+"  int r = i + j;\n"
+"  return r;\n"
+"}\n";
+std::string CodePart2 = "/* Comment block in one line*/\n"
+"enum Bar { FOOBAR, BARFOO };\n"
+"\n"
+"int bar3(int j, int k) {\n"
+"  // A comment\n"
+"  int r = j % k;\n"
+"  return r;\n"
+"}\n";
+std::string CodePart3 = "int bar2(int j, int k) {\n"
+"  int r = j / k;\n"
+"  return r;\n"
+"}\n";
+std::string ConcatAll = BlockHeader + CodePart1 + BlockChanger + CodePart2 +
+BlockFooter + (BlockEndNewLine ? "\n" : "") +
+CodePart3;
+return std::make_pair(BlockHeader + removeEmptyLines(CodePart1) +
+  BlockChanger + removeEmptyLines(CodePart2) +
+  BlockFooter + removeEmptyLines(CodePart3),
+  ConcatAll);
+  };
+
+  FormatStyle AlwaysStyle = getLLVMStyle();
+  AlwaysStyle.SeparateDefinitionBlocks = FormatStyle::SDS_Always;
+
+  FormatStyle NeverStyle = getLLVMStyle();
+  NeverStyle.SeparateDefinitionBlocks = FormatStyle::SDS_Never;
+
+  auto TestKit = MakeUntouchTest("#ifdef FOO\n\n", "\n#elifndef BAR\n\n",
+ "\n#endif\n\n", false);
+  verifyFormat(TestKit.first, AlwaysStyle, TestKit.second);
+  verifyFormat(TestKit.second, NeverStyle, removeEmptyLines(TestKit.second));
+
+  TestKit =
+  MakeUntouchTest("#ifdef FOO\n", "#elifndef BAR\n", "#endif\n", false);
+  verifyFormat(TestKit.first, AlwaysStyle, TestKit.second);
+  verifyFormat(TestKit.second, NeverStyle, removeEmptyLines(TestKit.second));
+
+  TestKit = MakeUntouchTest("namespace Ns {\n\n",
+"\n} // namespace Ns\n\n"
+"namespace {\n\n",
+"\n} // namespace\n", true);
+  verifyFormat(TestKit.first, AlwaysStyle, TestKit.second);
+  verifyFormat(TestKit.second, NeverStyle, removeEmptyLines(TestKit.second));
+
+  TestKit = MakeUntouchTest("namespace Ns {\n",
+"} // namespace Ns\n\n"
+"namespace {\n",
+"} // namespace\n", true);
+  verifyFormat(TestKit.first, AlwaysStyle, TestKit.second);
+  verifyFormat(TestKit.second, NeverStyle, removeEmptyLines(TestKit.second));
+}
+
 TEST_F(DefinitionBlockSeparatorTest, Always) {
   FormatStyle Style = getLLVMStyle();
   Style.SeparateDefinitionBlocks = FormatStyle::SDS_Always;
   std::string Prefix = "namespace {\n";
-  std::string Postfix = "enum Foo { FOO, BAR };\n"
-   

[PATCH] D116635: Add warning to detect when calls passing arguments are made to functions without prototypes.

2022-01-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:5529
+def warn_call_function_without_prototype : Warning<
+  "calling function %0 with arguments when function has no prototype">, 
InGroup<
+  DiagGroup<"strict-calls-without-prototype">>, DefaultIgnore;

delcypher wrote:
> aaron.ballman wrote:
> > delcypher wrote:
> > > aaron.ballman wrote:
> > > > This diagnostic doesn't tell me what's wrong with the code (and in 
> > > > fact, there's very possibly nothing wrong with the code whatsoever). 
> > > > Further, why does calling a function *with no arguments* matter when it 
> > > > has no prototype? I would imagine this should flag any call to a 
> > > > function without a prototype given that the function without a 
> > > > prototype may still expect arguments. e.g.,
> > > > ```
> > > > // Header.h
> > > > int f();
> > > > 
> > > > // Source.c
> > > > int f(a) int a; { ... }
> > > > 
> > > > // Caller.c
> > > > #include "Header.h"
> > > > 
> > > > int main() {
> > > >   return f();
> > > > }
> > > > ```
> > > > I think the diagnostic text should be updated to something more like 
> > > > `cannot verify %0 is being called with the correct number or 
> > > > %plural{1:type|:types}1 of arguments because it was declared without a 
> > > > prototype` (or something along those lines that explains what's wrong 
> > > > with the code).
> > > @aaron.ballman  Thanks for the helpful feedback.
> > > 
> > > > This diagnostic doesn't tell me what's wrong with the code (and in 
> > > > fact, there's very possibly nothing wrong with the code whatsoever).
> > > 
> > > That's a fair criticism.  I think the diagnostic message you suggest is a 
> > > lot more helpful so I'll go for something like that.
> > > 
> > > > Further, why does calling a function *with no arguments* matter when it 
> > > > has no prototype?
> > > 
> > > The reason was to avoid the warning being noisy. E.g. I didn't the 
> > > warning to fire in this situation.
> > > 
> > > ```
> > > // Header.h
> > > int f(); // The user forgot to put `void` between parentheses
> > > 
> > > // Source.c
> > > int f(void) { ... }
> > > 
> > > // Caller.c
> > > #include "Header.h"
> > > 
> > > int main() {
> > >   return f();
> > > }
> > > ```
> > > 
> > > Forgetting to put `void` in the declaration of `f()` is a pretty common 
> > > thing to do because a lot of people read `int f()` as declaring a 
> > > function that takes no arguments (it does in C++ but not in C).
> > > 
> > > I don't want the warning to be noisy because I was planning on switching 
> > > it on by default in open source and in a downstream use-case make it an 
> > > error.
> > > 
> > > How about this as a compromise? Split the warning into two separate 
> > > warnings
> > > 
> > > * `strict-call-without-prototype` -  Warns on calls to functions without 
> > > a prototype when no arguments are passed. Not enabled by default
> > > * `call-without-prototype` -Warns on calls to functions without a 
> > > prototype when arguments are passed.  Enable this by default.
> > > 
> > > Alternatively we could enable both by default. That would still allow me 
> > > to make `call-without-prototype` an error and 
> > > `strict-call-without-prototype` not be an error for my downstream 
> > > use-case.
> > > 
> > > Thoughts?
> > > Forgetting to put void in the declaration of f() is a pretty common thing 
> > > to do because a lot of people read int f() as declaring a function that 
> > > takes no arguments (it does in C++ but not in C).
> > 
> > Yup, and this is exactly why I think we *should* be warning. That is a 
> > function without a prototype, so the code is very brittle and dangerous at 
> > the call site. The fact that the call site *currently* is correct doesn't 
> > mean it's *intentionally* correct. e.g.,
> > ```
> > // Header.h
> > int f(); // No prototype
> > 
> > // Source.c
> > int f(int a, int b) { return 0; } // Has a prototype, no diagnostic
> > 
> > // OtherSource.c
> > #include "Header.h"
> > 
> > int main() {
> >   return f(); // No diagnostic with this patch, but still have the UB.
> > }
> > ```
> > 
> > > I don't want the warning to be noisy because I was planning on switching 
> > > it on by default in open source and in a downstream use-case make it an 
> > > error.
> > 
> > Hmmm. Thinking out loud here.
> > 
> > Functions without prototypes were standardized in C89 as a deprecated 
> > feature (C89 3.9.4, 3.9.5). I'd like to get to the point where any code 
> > that doesn't pass `-ansi` is given a diagnostic (at least in pedantic mode 
> > outside of system headers) about this deprecation, though I could probably 
> > be persuaded to keep not diagnose in c89 mode if that's a massive pain 
> > point. But if in C99 or later, I definitely see no reason not to diagnose 
> > the declarations as deprecated by default.
> > 
> > However, calling a function without a prototype declaration is not itself 
> > indicative of

[PATCH] D116882: [docs] [clang] Small documentation change for compilation databases

2022-01-11 Thread Dave Butler via Phabricator via cfe-commits
croepha marked an inline comment as done.
croepha added a comment.

Hey, @joerg I don't have commit access, would you mind landing this for me?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116882

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


[PATCH] D114718: [analyzer] Implement a new checker for Strict Aliasing Rule.

2022-01-11 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov updated this revision to Diff 398986.
ASDenysPetrov added a comment.

Improved the checker. Reworked tests.


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

https://reviews.llvm.org/D114718

Files:
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/StrictAliasingChecker.cpp
  clang/test/Analysis/Checkers/StrictAliasingChecker/cv.cpp
  clang/test/Analysis/Checkers/StrictAliasingChecker/scalar-ptr-to-scalar.cpp
  clang/test/Analysis/Checkers/StrictAliasingChecker/scalar-var-to-scalar.cpp
  clang/test/Analysis/Checkers/StrictAliasingChecker/typedef.cpp

Index: clang/test/Analysis/Checkers/StrictAliasingChecker/typedef.cpp
===
--- /dev/null
+++ clang/test/Analysis/Checkers/StrictAliasingChecker/typedef.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -std=c++20 -analyze -analyzer-config eagerly-assume=false -analyzer-checker=debug.ExprInspection,alpha.core.StrictAliasing -verify %s
+// NOTE: -relaxed-aliasing flag disables StrictAliasing checker.
+
+typedef int MyInt;
+typedef MyInt MyAnotherInt;
+typedef char MyChar;
+typedef short MyShort;
+typedef MyChar *MyCharPtr;
+typedef MyShort *MyShortPtr;
+typedef MyInt *MyIntPtr;
+
+MyAnotherInt x = 42;
+
+void typedef_test() {
+  MyChar y1 = *(MyCharPtr)&x;   // no-warning
+  MyShort y2 = *(MyShortPtr)&x; // expected-warning{{Undefined behavior}}
+  MyInt y3 = *(MyIntPtr)&x; // no-warning
+}
Index: clang/test/Analysis/Checkers/StrictAliasingChecker/scalar-var-to-scalar.cpp
===
--- /dev/null
+++ clang/test/Analysis/Checkers/StrictAliasingChecker/scalar-var-to-scalar.cpp
@@ -0,0 +1,650 @@
+// RUN: %clang_cc1 -std=c++20 -analyze -analyzer-config eagerly-assume=false -analyzer-checker=debug.ExprInspection,alpha.core.StrictAliasing -verify %s
+// NOTE: -relaxed-aliasing flag disables StrictAliasing checker.
+
+#define CHECK(var, type) \
+  { auto y = *(type *)&var; }
+
+void bool_test() {
+  bool x = true;
+  CHECK(x, bool) // no-warning
+
+  CHECK(x, char)  // no-warning
+  CHECK(x, short) // expected-warning {{Undefined behavior}}
+  CHECK(x, int)   // expected-warning {{Undefined behavior}}
+  CHECK(x, long)  // expected-warning {{Undefined behavior}}
+  CHECK(x, long long) // expected-warning {{Undefined behavior}}
+
+  CHECK(x, signed char)// expected-warning {{Undefined behavior}}
+  CHECK(x, unsigned char)  // no-warning
+  CHECK(x, unsigned short) // expected-warning {{Undefined behavior}}
+  CHECK(x, unsigned int)   // expected-warning {{Undefined behavior}}
+  CHECK(x, unsigned long)  // expected-warning {{Undefined behavior}}
+  CHECK(x, unsigned long long) // expected-warning {{Undefined behavior}}
+
+  CHECK(x, float)   // expected-warning {{Undefined behavior}}
+  CHECK(x, double)  // expected-warning {{Undefined behavior}}
+  CHECK(x, long double) // expected-warning {{Undefined behavior}}
+}
+
+void char_test() {
+  char x = 42;
+  CHECK(x, bool) // expected-warning {{Undefined behavior}}
+
+  CHECK(x, char)  // no-warning
+  CHECK(x, short) // expected-warning {{Undefined behavior}}
+  CHECK(x, int)   // expected-warning {{Undefined behavior}}
+  CHECK(x, long)  // expected-warning {{Undefined behavior}}
+  CHECK(x, long long) // expected-warning {{Undefined behavior}}
+
+  CHECK(x, signed char)// expected-warning {{Undefined behavior}}
+  CHECK(x, unsigned char)  // no-warning
+  CHECK(x, unsigned short) // expected-warning {{Undefined behavior}}
+  CHECK(x, unsigned int)   // expected-warning {{Undefined behavior}}
+  CHECK(x, unsigned long)  // expected-warning {{Undefined behavior}}
+  CHECK(x, unsigned long long) // expected-warning {{Undefined behavior}}
+
+  CHECK(x, float)   // expected-warning {{Undefined behavior}}
+  CHECK(x, double)  // expected-warning {{Undefined behavior}}
+  CHECK(x, long double) // expected-warning {{Undefined behavior}}
+}
+
+void short_test() {
+  short x = 42;
+  CHECK(x, bool) // expected-warning {{Undefined behavior}}
+
+  CHECK(x, char)  // no-warning
+  CHECK(x, short) // no-warning
+  CHECK(x, int)   // expected-warning {{Undefined behavior}}
+  CHECK(x, long)  // expected-warning {{Undefined behavior}}
+  CHECK(x, long long) // expected-warning {{Undefined behavior}}
+
+  CHECK(x, signed char)// expected-warning {{Undefined behavior}}
+  CHECK(x, unsigned char)  // no-warning
+  CHECK(x, unsigned short) // no-warning
+  CHECK(x, unsigned int)   // expected-warning {{Undefined behavior}}
+  CHECK(x, unsigned long)  // expected-warning {{Undefined behavior}}
+  CHECK(x, unsigned long long) // expected-warning {{Undefined behavior}}
+
+  CHECK(x, float)   // expected-warning {{Undefined behavior}}
+  CHECK(x, double)  // expe

[PATCH] D117033: [analyzer] Added more tests for scalars and enums for StrictAliasingChecker

2022-01-11 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov created this revision.
ASDenysPetrov added reviewers: NoQ, martong, steakhal, xazax.hun.
ASDenysPetrov added a project: clang.
Herald added subscribers: manas, jeroen.dobbelaere, dkrupp, donat.nagy, 
Szelethus, mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware.
ASDenysPetrov requested review of this revision.
Herald added a subscriber: cfe-commits.

Added tests to check aliasing:

- scalars through enums;
- enums through enums;
- enums through scalars.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117033

Files:
  clang/test/Analysis/Checkers/StrictAliasingChecker/enam-ptr-to-scalar.cpp
  clang/test/Analysis/Checkers/StrictAliasingChecker/enam-var-to-scalar.cpp
  clang/test/Analysis/Checkers/StrictAliasingChecker/enum-ptr-to-enum.cpp
  clang/test/Analysis/Checkers/StrictAliasingChecker/enum-var-to-enum.cpp
  clang/test/Analysis/Checkers/StrictAliasingChecker/enums.h
  clang/test/Analysis/Checkers/StrictAliasingChecker/scalar-ptr-to-enum.cpp
  clang/test/Analysis/Checkers/StrictAliasingChecker/scalar-var-to-enum.cpp

Index: clang/test/Analysis/Checkers/StrictAliasingChecker/scalar-var-to-enum.cpp
===
--- /dev/null
+++ clang/test/Analysis/Checkers/StrictAliasingChecker/scalar-var-to-enum.cpp
@@ -0,0 +1,179 @@
+// RUN: %clang_cc1 -std=c++20 -analyze -analyzer-config eagerly-assume=false -analyzer-checker=debug.ExprInspection,alpha.core.StrictAliasing -verify %s
+// NOTE: -relaxed-aliasing flag disables StrictAliasing checker.
+
+#include "enums.h"
+
+#define CHECK(var, type) \
+  { auto y = *(type *)&var; }
+
+#define CHECKS \
+  CHECK(x, std::OtherByte) \
+  CHECK(x, ClassEnum)  \
+  CHECK(x, ClassEnumChar)  \
+  CHECK(x, ClassEnumUChar) \
+  CHECK(x, ClassEnumInt)   \
+  CHECK(x, Enum)   \
+  CHECK(x, EnumChar)   \
+  CHECK(x, EnumUChar)  \
+  CHECK(x, EnumInt)\
+  CHECK(x, decltype(E_Dummy))
+
+void bool_test() {
+  bool x = 42;
+  CHECK(x, std::byte) // no-warning
+  CHECKS  // expected-warning 10{{Undefined behavior}}
+}
+
+void char_test() {
+  char x = 42;
+  CHECK(x, std::byte) // no-warning
+  CHECKS  // expected-warning 10{{Undefined behavior}}
+}
+
+void short_test() {
+  short x = 42;
+  CHECK(x, std::byte) // no-warning
+  CHECKS  // expected-warning 10{{Undefined behavior}}
+}
+
+void int_test() {
+  int x = 42;
+  CHECK(x, std::byte) // no-warning
+  CHECKS  // expected-warning 10{{Undefined behavior}}
+}
+
+void long_test() {
+  long x = 42;
+  CHECK(x, std::byte) // no-warning
+  CHECKS  // expected-warning 10{{Undefined behavior}}
+}
+
+void long_long_test() {
+  long long x = 42;
+  CHECK(x, std::byte) // no-warning
+  CHECKS  // expected-warning 10{{Undefined behavior}}
+}
+
+void schar_test() {
+  signed char x = 42;
+  CHECK(x, std::byte) // no-warning
+  CHECKS  // expected-warning 10{{Undefined behavior}}
+}
+
+void uchar_test() {
+  unsigned char x = 42;
+  CHECK(x, std::byte) // no-warning
+  CHECKS  // expected-warning 10{{Undefined behavior}}
+}
+
+void ushort_test() {
+  unsigned short x = 42;
+  CHECK(x, std::byte) // no-warning
+  CHECKS  // expected-warning 10{{Undefined behavior}}
+}
+
+void uint_test() {
+  unsigned int x = 42;
+  CHECK(x, std::byte) // no-warning
+  CHECKS  // expected-warning 10{{Undefined behavior}}
+}
+
+void ulong_test() {
+  unsigned long x = 42;
+  CHECK(x, std::byte) // no-warning
+  CHECKS  // expected-warning 10{{Undefined behavior}}
+}
+
+void ulong_long_test() {
+  unsigned long long x = 42;
+  CHECK(x, std::byte) // no-warning
+  CHECKS  // expected-warning 10{{Undefined behavior}}
+}
+
+void float_test() {
+  float x = 42;
+  CHECK(x, std::byte) // no-warning
+  CHECKS  // expected-warning 10{{Undefined behavior}}
+}
+
+void double_test() {
+  double x = 42;
+  CHECK(x, std::byte) // no-warning
+  CHECKS  // expected-warning 10{{Undefined behavior}}
+}
+
+void long_double_test() {
+  long double x = 42;
+  CHECK(x, std::byte) // no-warning
+  CHECKS  // expected-warning 10{{Undefined behavior}}
+}
+
+void bool_test(bool x) {
+  CHECK(x, std::byte) // no-warning
+  CHECKS  // expected-warning 10{{Undefined behavior}}
+}
+
+void char_test(char x) {
+  CHECK(x, std::byte) // no-warning
+  CHECKS  // expected-warning 10{{Undefined behavior}}
+}
+
+void short_test(short x) {
+  CHECK(x, std::byte) // no-warning
+  CHECKS  // expected-warning 10{{Undefined behavior}}
+}
+
+void int_test(int x) {
+  CHECK(x, std::byte) // no-warning
+  CHECKS  // expected-warning 10{{Undefined behavior}}
+}
+
+void long_test(long x) {
+  CHECK(x, std::byte) // no-warning
+  CHECKS  // expected-warning 10{{Undefined behavior}}
+}
+
+void long_long_test(long long x) {
+  CHECK(x, std:

[PATCH] D117035: [analyzer] Added more tests for scalars, enums and records for StrictAliasingChecker

2022-01-11 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov created this revision.
ASDenysPetrov added reviewers: steakhal, xazax.hun, martong, NoQ.
Herald added subscribers: manas, jeroen.dobbelaere, dkrupp, donat.nagy, 
Szelethus, mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware.
ASDenysPetrov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Added tests to check aliasing:

- scalars through records;
- enums through records;
- records through scalars;
- records through enums;
- records through records;
- through multiple levels of aliasing
- in different syntax contexts.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117035

Files:
  clang/test/Analysis/Checkers/StrictAliasingChecker/enum-ptr-to-record.cpp
  clang/test/Analysis/Checkers/StrictAliasingChecker/enum-var-to-record.cpp
  clang/test/Analysis/Checkers/StrictAliasingChecker/multi-casts.cpp
  clang/test/Analysis/Checkers/StrictAliasingChecker/record-ptr-to-enum.cpp
  clang/test/Analysis/Checkers/StrictAliasingChecker/record-ptr-to-record.cpp
  clang/test/Analysis/Checkers/StrictAliasingChecker/record-ptr-to-scalar.cpp
  clang/test/Analysis/Checkers/StrictAliasingChecker/record-var-to-enum.cpp
  clang/test/Analysis/Checkers/StrictAliasingChecker/record-var-to-record.cpp
  clang/test/Analysis/Checkers/StrictAliasingChecker/record-var-to-scalar.cpp
  clang/test/Analysis/Checkers/StrictAliasingChecker/records.h
  clang/test/Analysis/Checkers/StrictAliasingChecker/scalar-ptr-to-record.cpp
  clang/test/Analysis/Checkers/StrictAliasingChecker/scalar-var-to-record.cpp
  clang/test/Analysis/Checkers/StrictAliasingChecker/various-indirection.cpp

Index: clang/test/Analysis/Checkers/StrictAliasingChecker/various-indirection.cpp
===
--- /dev/null
+++ clang/test/Analysis/Checkers/StrictAliasingChecker/various-indirection.cpp
@@ -0,0 +1,83 @@
+// RUN: %clang_cc1 -std=c++20 -analyze -analyzer-config eagerly-assume=false -analyzer-checker=debug.ExprInspection,alpha.core.StrictAliasing -verify %s
+// NOTE: -relaxed-aliasing flag disables StrictAliasing checker.
+
+#include "enums.h"
+#include "records.h"
+
+#define CAST(var, type) (reinterpret_cast(var))
+#define DEREF(var, type) *CAST(var, type)
+#define SUBSCRIPT(var, type) \
+  CAST(var, type)\
+  [0]
+#define DEREF_ADD(var, type) *(CAST(var, type) + 0)
+
+#define CHECK_DEREF(var, type)   \
+  { auto y = DEREF(var, type); } \
+  { DEREF(var, type) = type{}; }
+
+#define CHECK_SUBSCRIPT(var, type)   \
+  { auto y = SUBSCRIPT(var, type); } \
+  { SUBSCRIPT(var, type) = type{}; }
+
+#define CHECK_DEREF_ADD(var, type)   \
+  { auto y = DEREF_ADD(var, type); } \
+  { DEREF_ADD(var, type) = type{}; }
+
+#define CHECK_MEMBER_ARROW(var, type) \
+  { auto y = CAST(var, type)->x; }\
+  { CAST(var, type)->x = decltype(CAST(var, type)->x){}; }
+
+#define CHECK_MEMBER_DOT(var, type)  \
+  { auto y = (*CAST(var, type)).x; } \
+  { (*CAST(var, type)).x = decltype((*CAST(var, type)).x){}; }
+
+#define CHECK_SCALAR_NO_WARN(type) \
+  {\
+type x{};  \
+CHECK_DEREF(&x, type)  \
+CHECK_SUBSCRIPT(&x, type)  \
+CHECK_DEREF_ADD(&x, type)  \
+  }
+
+#define CHECK_RECORD_NO_WARN(type) \
+  {\
+CHECK_SCALAR_NO_WARN(type) \
+type x{};  \
+CHECK_MEMBER_ARROW(&x, type)   \
+CHECK_MEMBER_DOT(&x, type) \
+  }
+
+#define CHECK_NOOP_NO_WARN(type1, type2) \
+  {  \
+type1 x{};   \
+DEREF(&x, type2);\
+SUBSCRIPT(&x, type2);\
+DEREF_ADD(&x, type2);\
+  }
+
+void test_store_load() {
+  CHECK_SCALAR_NO_WARN(bool)  // no-warning
+  CHECK_SCALAR_NO_WARN(char)  // no-warning
+  CHECK_SCALAR_NO_WARN(int)   // no-warning
+  CHECK_SCALAR_NO_WARN(double)// no-warning
+  CHECK_SCALAR_NO_WARN(ClassEnum) // no-warning
+  CHECK_SCALAR_NO_WARN(Enum)  // no-warning
+
+  CHECK_RECORD_NO_WARN(StructInt)   // no-warning
+  CHECK_RECORD_NO_WARN(Base)// no-warning
+  CHECK_RECORD_NO_WARN(MostDerived) // no-warning
+  CHECK_RECORD_NO_WARN(UnionUchar)  // no-warning
+}
+
+// TODO: All should not warn.
+void test_noop() {
+  CHECK_NOOP_NO_WARN(bool, MostDerived)  // expected-warning 3{{Undefined behavior}}
+  CHECK_NOOP_NO_WARN(char, int)  // expected-warning 3{{Undefined behavior}}
+  CHECK_NOOP_NO_WARN(double, ClassEnum)  // expected-warning 3{{Undefined behavior}}
+  CHECK_NOOP_NO_WARN(ClassEnum, StructInt)   // expected-warning 3{{Undefined behavior}}
+  CHECK_NOOP_NO_WARN(Enum, UnionUchar)   // expected-warning 3{{Undefined behavior}}
+  CHECK_NOOP_NO_WARN(StructInt, std::byte)   // no-warning
+  CHECK_NOOP_NO_WARN(AnotherBase, float) // expected-warning 3{{Undefined behavi

[PATCH] D116387: [CodeCompletion][clangd] Clean __uglified parameter names in completion & hover

2022-01-11 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 398991.
sammccall added a comment.

Revert hover changes, only use for code complete


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116387

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
  clang/include/clang/AST/PrettyPrinter.h
  clang/include/clang/Basic/IdentifierTable.h
  clang/lib/AST/DeclPrinter.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/TemplateName.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/IdentifierTable.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/deuglify.cpp
  clang/unittests/AST/DeclPrinterTest.cpp
  clang/unittests/AST/StmtPrinterTest.cpp
  clang/unittests/AST/TypePrinterTest.cpp

Index: clang/unittests/AST/TypePrinterTest.cpp
===
--- clang/unittests/AST/TypePrinterTest.cpp
+++ clang/unittests/AST/TypePrinterTest.cpp
@@ -62,4 +62,21 @@
   ASSERT_TRUE(PrintedTypeMatches(
   Code, {}, Matcher, "const N::Type &",
   [](PrintingPolicy &Policy) { Policy.FullyQualifiedName = true; }));
-}
\ No newline at end of file
+}
+
+TEST(TypePrinter, ParamsUglified) {
+  llvm::StringLiteral Code = R"cpp(
+template  class __f>
+const __f<_Tp&> *A = nullptr;
+  )cpp";
+  auto Clean = [](PrintingPolicy &Policy) {
+Policy.CleanUglifiedParameters = true;
+  };
+
+  ASSERT_TRUE(PrintedTypeMatches(Code, {},
+ varDecl(hasType(qualType().bind("id"))),
+ "const __f<_Tp &> *", nullptr));
+  ASSERT_TRUE(PrintedTypeMatches(Code, {},
+ varDecl(hasType(qualType().bind("id"))),
+ "const f *", Clean));
+}
Index: clang/unittests/AST/StmtPrinterTest.cpp
===
--- clang/unittests/AST/StmtPrinterTest.cpp
+++ clang/unittests/AST/StmtPrinterTest.cpp
@@ -263,3 +263,22 @@
 
   [](PrintingPolicy &PP) { PP.TerseOutput = true; }));
 }
+
+TEST(StmtPrinter, ParamsUglified) {
+  llvm::StringLiteral Code = R"cpp(
+template  class _C>
+auto foo(int __j) {
+  return typename _C<_T>::_F(_I, __j);
+}
+  )cpp";
+  auto Clean = [](PrintingPolicy &Policy) {
+Policy.CleanUglifiedParameters = true;
+  };
+
+  ASSERT_TRUE(PrintedStmtCXXMatches(StdVer::CXX14, Code,
+returnStmt().bind("id"),
+"return typename _C<_T>::_F(_I, __j);\n"));
+  ASSERT_TRUE(
+  PrintedStmtCXXMatches(StdVer::CXX14, Code, returnStmt().bind("id"),
+"return typename C::_F(I, j);\n", Clean));
+}
Index: clang/unittests/AST/DeclPrinterTest.cpp
===
--- clang/unittests/AST/DeclPrinterTest.cpp
+++ clang/unittests/AST/DeclPrinterTest.cpp
@@ -1336,6 +1336,41 @@
   ASSERT_TRUE(PrintedDeclCXX11Matches(Code, "NT2", "int NT2 = 5"));
 }
 
+TEST(DeclPrinter, TestFunctionParamUglified) {
+  llvm::StringLiteral Code = R"cpp(
+class __c;
+void _A(__c *__param);
+  )cpp";
+  auto Clean = [](PrintingPolicy &Policy) {
+Policy.CleanUglifiedParameters = true;
+  };
+
+  ASSERT_TRUE(PrintedDeclCXX17Matches(Code, namedDecl(hasName("_A")).bind("id"),
+  "void _A(__c *__param)"));
+  ASSERT_TRUE(PrintedDeclCXX17Matches(Code, namedDecl(hasName("_A")).bind("id"),
+  "void _A(__c *param)", Clean));
+}
+
+TEST(DeclPrinter, TestTemplateParamUglified) {
+  llvm::StringLiteral Code = R"cpp(
+template  class _Container>
+struct _A{};
+  )cpp";
+  auto Clean = [](PrintingPolicy &Policy) {
+Policy.CleanUglifiedParameters = true;
+  };
+
+  ASSERT_TRUE(PrintedDeclCXX17Matches(
+  Code, classTemplateDecl(hasName("_A")).bind("id"),
+  "template  class _Container> "
+  "struct _A {}"));
+  ASSERT_TRUE(PrintedDeclCXX17Matches(
+  Code, classTemplateDecl(hasName("_A")).bind("id"),
+  "template  class Container> "
+  "struct _A {}",
+  Clean));
+}
+
 TEST(DeclPrinter, TestStaticAssert1) {
   ASSERT_TRUE(PrintedDeclCXX17Matches("static_assert(true);",
   staticAssertDecl().bind("id"),
Index: clang/test/CodeCompletion/deuglify.cpp
===
--- /dev/null
+++ clang/test/CodeCompletion/deuglify.cpp
@@ -0,0 +1,25 @@
+// Fake standard library with uglified names.
+// Parameters (including template params) get ugliness stripped.
+namespace std {
+
+template 
+class __vector_base {};
+
+template 
+class vector : private __vector_base<_Tp> {
+public:
+  _Tp &at(unsigned __index) const;
+  int __stays_ugly();
+};
+
+} // namespace std
+
+int x = std::vector{}.at(42);
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:17:14 %s -

[PATCH] D117036: [clangd] Retire --inlay-hints flag

2022-01-11 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: kadircet.
Herald added subscribers: usaxena95, arphaman.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117036

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/tool/ClangdMain.cpp


Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -23,7 +23,6 @@
 #include "index/ProjectAware.h"
 #include "index/Serialization.h"
 #include "index/remote/Client.h"
-#include "refactor/Rename.h"
 #include "support/Path.h"
 #include "support/Shutdown.h"
 #include "support/ThreadCrashReporter.h"
@@ -294,6 +293,7 @@
 RetiredFlag CollectMainFileRefs("collect-main-file-refs");
 RetiredFlag CrossFileRename("cross-file-rename");
 RetiredFlag ClangTidyChecks("clang-tidy-checks");
+RetiredFlag InlayHints("inlay-hints");
 
 opt LimitResults{
 "limit-results",
@@ -327,15 +327,6 @@
 Hidden,
 };
 
-opt InlayHints{
-"inlay-hints",
-cat(Features),
-desc("Enable InlayHints feature"),
-init(ClangdLSPServer::Options().InlayHints),
-// FIXME: allow inlayHints to be disabled in Config and remove this option.
-Hidden,
-};
-
 opt WorkerThreadsCount{
 "j",
 cat(Misc),
@@ -884,7 +875,6 @@
   }
   Opts.AsyncThreadsCount = WorkerThreadsCount;
   Opts.FoldingRanges = FoldingRanges;
-  Opts.InlayHints = InlayHints;
   Opts.MemoryCleanup = getMemoryCleanupFunction();
 
   Opts.CodeComplete.IncludeIneligibleResults = IncludeIneligibleResults;
Index: clang-tools-extra/clangd/ClangdLSPServer.h
===
--- clang-tools-extra/clangd/ClangdLSPServer.h
+++ clang-tools-extra/clangd/ClangdLSPServer.h
@@ -63,9 +63,6 @@
   return !T.hidden(); // only enable non-hidden tweaks.
 };
 
-/// Enable InlayHints feature.
-bool InlayHints = true;
-
 /// Limit the number of references returned (0 means no limit).
 size_t ReferencesLimit = 0;
   };
Index: clang-tools-extra/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -576,6 +576,7 @@
   {"compilationDatabase",// clangd extension
llvm::json::Object{{"automaticReload", true}}},
   {"callHierarchyProvider", true},
+  {"clangdInlayHintsProvider", true},
   };
 
   {
@@ -608,10 +609,6 @@
   if (Opts.FoldingRanges)
 ServerCaps["foldingRangeProvider"] = true;
 
-  // FIXME: once inlayHints can be disabled in config, always advertise.
-  if (Opts.InlayHints)
-ServerCaps["clangdInlayHintsProvider"] = true;
-
   std::vector Commands;
   for (llvm::StringRef Command : Handlers.CommandHandlers.keys())
 Commands.push_back(Command);


Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -23,7 +23,6 @@
 #include "index/ProjectAware.h"
 #include "index/Serialization.h"
 #include "index/remote/Client.h"
-#include "refactor/Rename.h"
 #include "support/Path.h"
 #include "support/Shutdown.h"
 #include "support/ThreadCrashReporter.h"
@@ -294,6 +293,7 @@
 RetiredFlag CollectMainFileRefs("collect-main-file-refs");
 RetiredFlag CrossFileRename("cross-file-rename");
 RetiredFlag ClangTidyChecks("clang-tidy-checks");
+RetiredFlag InlayHints("inlay-hints");
 
 opt LimitResults{
 "limit-results",
@@ -327,15 +327,6 @@
 Hidden,
 };
 
-opt InlayHints{
-"inlay-hints",
-cat(Features),
-desc("Enable InlayHints feature"),
-init(ClangdLSPServer::Options().InlayHints),
-// FIXME: allow inlayHints to be disabled in Config and remove this option.
-Hidden,
-};
-
 opt WorkerThreadsCount{
 "j",
 cat(Misc),
@@ -884,7 +875,6 @@
   }
   Opts.AsyncThreadsCount = WorkerThreadsCount;
   Opts.FoldingRanges = FoldingRanges;
-  Opts.InlayHints = InlayHints;
   Opts.MemoryCleanup = getMemoryCleanupFunction();
 
   Opts.CodeComplete.IncludeIneligibleResults = IncludeIneligibleResults;
Index: clang-tools-extra/clangd/ClangdLSPServer.h
===
--- clang-tools-extra/clangd/ClangdLSPServer.h
+++ clang-tools-extra/clangd/ClangdLSPServer.h
@@ -63,9 +63,6 @@
   return !T.hidden(); // only enable non-hidden tweaks.
 };
 
-/// Enable InlayHints feature.
-bool InlayHints = true;
-
 /// Limit the number of references returned (0 means no limit).
 size_t ReferencesLimit = 0;
   };
Index: clang-tools-extra/clangd/ClangdLSPSer

[PATCH] D116814: [clang-tidy] Accept string literal decay in conditional operator

2022-01-11 Thread Elvis Stansvik via Phabricator via cfe-commits
estan added a comment.

Thanks @aaron.ballman. I don't have commit/push rights, so someone please 
commit for me when you got the time.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116814

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


[PATCH] D117036: [clangd] Retire --inlay-hints flag

2022-01-11 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

nit: I'd rename the patch to `remove` rather than `retire`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117036

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


[PATCH] D117037: [clang][CodeComplete] Perform approximate member search in bases

2022-01-11 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: usaxena95, arphaman.
kadircet requested review of this revision.
Herald added projects: clang, clang-tools-extra.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117037

Files:
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang/lib/Sema/SemaCodeComplete.cpp


Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -5411,9 +5411,21 @@
   Base = Base->getPointeeType(); // could handle unique_ptr etc here?
 RecordDecl *RD = Base.isNull() ? nullptr : getAsRecordDecl(Base);
 if (RD && RD->isCompleteDefinition()) {
-  for (const auto *Member : RD->lookup(CDSME->getMember()))
-if (const ValueDecl *VD = llvm::dyn_cast(Member))
-  return VD->getType().getNonReferenceType();
+  // For c++ records perform a dependent name lookup, which also takes care
+  // of the bases.
+  if (auto *CXXRD = llvm::dyn_cast(RD)) {
+for (const auto *Member : CXXRD->lookupDependentName(
+ CDSME->getMember(), [](const NamedDecl *Member) {
+   return llvm::isa(Member);
+ })) {
+  return 
llvm::cast(Member)->getType().getNonReferenceType();
+}
+  } else {
+for (const auto *Member : RD->lookup(CDSME->getMember())) {
+  if (const ValueDecl *VD = llvm::dyn_cast(Member))
+return VD->getType().getNonReferenceType();
+}
+  }
 }
   }
   return Unresolved;
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -3453,6 +3453,19 @@
   }
 }
 
+TEST(CompletionTest, UndeducedType) {
+  clangd::CodeCompleteOptions Opts;
+  const std::string Code = R"cpp(
+struct Base { Base foo(); };
+
+template  struct Foo : Base {
+  void bar() { this->foo().^foo(); }
+};
+  )cpp";
+
+  EXPECT_THAT(completions(Code, {}, Opts).Completions,
+  Contains(Labeled("foo()")));
+}
 } // namespace
 } // namespace clangd
 } // namespace clang


Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -5411,9 +5411,21 @@
   Base = Base->getPointeeType(); // could handle unique_ptr etc here?
 RecordDecl *RD = Base.isNull() ? nullptr : getAsRecordDecl(Base);
 if (RD && RD->isCompleteDefinition()) {
-  for (const auto *Member : RD->lookup(CDSME->getMember()))
-if (const ValueDecl *VD = llvm::dyn_cast(Member))
-  return VD->getType().getNonReferenceType();
+  // For c++ records perform a dependent name lookup, which also takes care
+  // of the bases.
+  if (auto *CXXRD = llvm::dyn_cast(RD)) {
+for (const auto *Member : CXXRD->lookupDependentName(
+ CDSME->getMember(), [](const NamedDecl *Member) {
+   return llvm::isa(Member);
+ })) {
+  return llvm::cast(Member)->getType().getNonReferenceType();
+}
+  } else {
+for (const auto *Member : RD->lookup(CDSME->getMember())) {
+  if (const ValueDecl *VD = llvm::dyn_cast(Member))
+return VD->getType().getNonReferenceType();
+}
+  }
 }
   }
   return Unresolved;
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -3453,6 +3453,19 @@
   }
 }
 
+TEST(CompletionTest, UndeducedType) {
+  clangd::CodeCompleteOptions Opts;
+  const std::string Code = R"cpp(
+struct Base { Base foo(); };
+
+template  struct Foo : Base {
+  void bar() { this->foo().^foo(); }
+};
+  )cpp";
+
+  EXPECT_THAT(completions(Code, {}, Opts).Completions,
+  Contains(Labeled("foo()")));
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D117037: [clang][CodeComplete] Perform approximate member search in bases

2022-01-11 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp:3456
 
+TEST(CompletionTest, UndeducedType) {
+  clangd::CodeCompleteOptions Opts;

"undeducedtype" seems like a strange name for this test - 
MemberFromBaseOfDependent?



Comment at: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp:3456
 
+TEST(CompletionTest, UndeducedType) {
+  clangd::CodeCompleteOptions Opts;

sammccall wrote:
> "undeducedtype" seems like a strange name for this test - 
> MemberFromBaseOfDependent?
you might want this test in clang/test/CodeCompletion as well/instead.



Comment at: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp:3459
+  const std::string Code = R"cpp(
+struct Base { Base foo(); };
+

does this also work if the base is dependent (Base)?



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:5414
 if (RD && RD->isCompleteDefinition()) {
-  for (const auto *Member : RD->lookup(CDSME->getMember()))
-if (const ValueDecl *VD = llvm::dyn_cast(Member))
-  return VD->getType().getNonReferenceType();
+  // For c++ records perform a dependent name lookup, which also takes care
+  // of the bases.

could be a little more precise: "look up member heuristically, including in 
bases"



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:5423
+}
+  } else {
+for (const auto *Member : RD->lookup(CDSME->getMember())) {

This case seems very nearly dead. Technically it is possible to get a 
CXXDependentScopeMemberExpr in C using recovery expr, but I can't find a case 
where this is useful. Maybe drop it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117037

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


[PATCH] D116967: [HIP] Fix device malloc/free

2022-01-11 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: clang/lib/Headers/__clang_hip_runtime_wrapper.h:80
 
+#if HIP_VERSION_MAJOR > 4 || (HIP_VERSION_MAJOR == 4 && HIP_VERSION_MINOR >= 5)
+extern "C" __device__ unsigned long long __ockl_dm_alloc(unsigned long long 
__size);

yaxunl wrote:
> tra wrote:
> > Nit: perhaps something like this would express the intent a bit more 
> > directly:
> > 
> > ```
> > # if HIP_VERSION_MAJOR*100+HIP_VERSION_MINOR*10 > 450
> > ```
> > 
> > 
> We had ROCm 3.10, so the minor version may be 10 or greater.
> 
> Probably use HIP_VERSION_MAJOR*100+HIP_VERSION_MINOR > 405 instead?
LGTM. 




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

https://reviews.llvm.org/D116967

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


[libunwind] 0a8d15a - [libc++][libc++abi][libunwind] Dedup install path var definitions

2022-01-11 Thread John Ericson via cfe-commits

Author: John Ericson
Date: 2022-01-11T18:24:50Z
New Revision: 0a8d15ad55e344419400f037393f2208214e33e0

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

LOG: [libc++][libc++abi][libunwind] Dedup install path var definitions

In D116873 I did this for libunwind prior to defining a new install path
variable. But I think the change is good on its own, and libc++{,abi}
could also use it.

libc++ needed the base header var defined above the conditional part to
use it for the prefi+ed headers in the non-target-specific case. For
consistency, I therefore put the unconditional ones above for all 3
libs, which is why I touched the libunwind code (seeing that it had the
core change already)

Reviewed By: phosek, #libunwind, #libc, #libc_abi, ldionne

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

Added: 


Modified: 
libcxx/CMakeLists.txt
libcxxabi/CMakeLists.txt
libunwind/CMakeLists.txt

Removed: 




diff  --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index b0569a4a54ca..82a643e74eb7 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -411,44 +411,35 @@ endif ()
 
 # TODO: Projects that depend on libc++ should use LIBCXX_GENERATED_INCLUDE_DIR
 # instead of hard-coding include/c++/v1.
+
+set(LIBCXX_INSTALL_INCLUDE_DIR "include/c++/v1" CACHE PATH
+"Path where target-agnostic libc++ headers should be installed.")
+set(LIBCXX_INSTALL_RUNTIME_DIR bin CACHE PATH
+"Path where built libc++ runtime libraries should be installed.")
+
 if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
   set(LIBCXX_LIBRARY_DIR 
${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
   set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1")
   set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR 
"${LLVM_BINARY_DIR}/include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1")
   set(LIBCXX_INSTALL_LIBRARY_DIR 
lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH
   "Path where built libc++ libraries should be installed.")
-  set(LIBCXX_INSTALL_RUNTIME_DIR bin CACHE PATH
-  "Path where built libc++ runtime libraries should be installed.")
-  set(LIBCXX_INSTALL_INCLUDE_DIR "include/c++/v1" CACHE PATH
-  "Path where target-agnostic libc++ headers should be installed.")
   set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR 
"include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1" CACHE PATH
   "Path where target-specific libc++ headers should be installed.")
   if(LIBCXX_LIBDIR_SUBDIR)
 string(APPEND LIBCXX_LIBRARY_DIR /${LIBCXX_LIBDIR_SUBDIR})
 string(APPEND LIBCXX_INSTALL_LIBRARY_DIR /${LIBCXX_LIBDIR_SUBDIR})
   endif()
-elseif(LLVM_LIBRARY_OUTPUT_INTDIR)
-  set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
-  set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1")
-  set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LIBCXX_GENERATED_INCLUDE_DIR}")
-  set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX} CACHE PATH
-  "Path where built libc++ libraries should be installed.")
-  set(LIBCXX_INSTALL_RUNTIME_DIR bin CACHE PATH
-  "Path where built libc++ runtime libraries should be installed.")
-  set(LIBCXX_INSTALL_INCLUDE_DIR "include/c++/v1" CACHE PATH
-  "Path where target-agnostic libc++ headers should be installed.")
-  set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${LIBCXX_INSTALL_INCLUDE_DIR}" CACHE 
PATH
-  "Path where target-specific libc++ headers should be installed.")
 else()
-  set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX})
-  set(LIBCXX_GENERATED_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/c++/v1")
+  if(LLVM_LIBRARY_OUTPUT_INTDIR)
+set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
+set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1")
+  else()
+set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX})
+set(LIBCXX_GENERATED_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/c++/v1")
+  endif()
   set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LIBCXX_GENERATED_INCLUDE_DIR}")
   set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX} CACHE PATH
   "Path where built libc++ libraries should be installed.")
-  set(LIBCXX_INSTALL_RUNTIME_DIR bin CACHE PATH
-  "Path where built libc++ runtime libraries should be installed.")
-  set(LIBCXX_INSTALL_INCLUDE_DIR "include/c++/v1" CACHE PATH
-  "Path where target-agnostic libc++ headers should be installed.")
   set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${LIBCXX_INSTALL_INCLUDE_DIR}" CACHE 
PATH
   "Path where target-specific libc++ headers should be installed.")
 endif()

diff  --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt
index 858f5d5cfd7f..89722df0bf46 100644
--- a/libcxxabi/CMakeLists.txt
+++ b/libcxxabi/CMakeLists.txt
@@ -210,31 +210,28 @@ set(CMAKE_MODULE_PATH
   ${CMAKE_MODULE_PATH}
   )
 
+set(

[PATCH] D116948: [CodeGen] Treat ObjC `__unsafe_unretained` and class types as trivial when generating copy/dispose helper functions

2022-01-11 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

Thanks, LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116948

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


[PATCH] D99484: [cmake] Use `GNUInstallDirs` to support custom installation dirs.

2022-01-11 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 updated this revision to Diff 399020.
Ericson2314 added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99484

Files:
  clang-tools-extra/CMakeLists.txt
  clang-tools-extra/clang-doc/tool/CMakeLists.txt
  clang-tools-extra/clang-include-fixer/find-all-symbols/tool/CMakeLists.txt
  clang-tools-extra/clang-include-fixer/tool/CMakeLists.txt
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/tool/CMakeLists.txt
  clang-tools-extra/modularize/CMakeLists.txt
  clang/CMakeLists.txt
  clang/cmake/modules/AddClang.cmake
  clang/tools/c-index-test/CMakeLists.txt
  clang/tools/clang-format/CMakeLists.txt
  clang/tools/clang-nvlink-wrapper/CMakeLists.txt
  clang/tools/clang-rename/CMakeLists.txt
  clang/tools/libclang/CMakeLists.txt
  clang/tools/scan-build-py/CMakeLists.txt
  clang/tools/scan-build/CMakeLists.txt
  clang/tools/scan-view/CMakeLists.txt
  clang/utils/hmaptool/CMakeLists.txt
  compiler-rt/cmake/base-config-ix.cmake
  libc/CMakeLists.txt
  libcxx/CMakeLists.txt
  libcxx/cmake/Modules/HandleLibCXXABI.cmake
  libcxxabi/CMakeLists.txt
  libunwind/CMakeLists.txt
  llvm/cmake/modules/LLVMInstallSymlink.cmake
  mlir/CMakeLists.txt
  mlir/cmake/modules/AddMLIR.cmake
  openmp/CMakeLists.txt
  openmp/libompd/src/CMakeLists.txt
  openmp/runtime/src/CMakeLists.txt
  openmp/tools/multiplex/CMakeLists.txt
  polly/CMakeLists.txt
  polly/cmake/CMakeLists.txt
  polly/lib/External/CMakeLists.txt
  pstl/CMakeLists.txt

Index: pstl/CMakeLists.txt
===
--- pstl/CMakeLists.txt
+++ pstl/CMakeLists.txt
@@ -7,6 +7,8 @@
 #===--===##
 cmake_minimum_required(VERSION 3.13.4)
 
+include(GNUInstallDirs)
+
 set(PARALLELSTL_VERSION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/include/pstl/internal/pstl_config.h")
 file(STRINGS "${PARALLELSTL_VERSION_FILE}" PARALLELSTL_VERSION_SOURCE REGEX "#define _PSTL_VERSION .*$")
 string(REGEX REPLACE "#define _PSTL_VERSION (.*)$" "\\1" PARALLELSTL_VERSION_SOURCE "${PARALLELSTL_VERSION_SOURCE}")
@@ -90,10 +92,10 @@
   "${CMAKE_CURRENT_BINARY_DIR}/ParallelSTLConfigVersion.cmake"
 DESTINATION lib/cmake/ParallelSTL)
 install(DIRECTORY include/
-DESTINATION include
+DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
 PATTERN "*.in" EXCLUDE)
 install(FILES "${PSTL_CONFIG_SITE_PATH}"
-DESTINATION include)
+DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
 
 add_custom_target(install-pstl
   COMMAND "${CMAKE_COMMAND}" -P "${PROJECT_BINARY_DIR}/cmake_install.cmake" -DCOMPONENT=ParallelSTL)
Index: polly/lib/External/CMakeLists.txt
===
--- polly/lib/External/CMakeLists.txt
+++ polly/lib/External/CMakeLists.txt
@@ -290,7 +290,7 @@
 install(DIRECTORY
   ${ISL_SOURCE_DIR}/include/
   ${ISL_BINARY_DIR}/include/
-  DESTINATION include/polly
+  DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/polly"
   FILES_MATCHING
   PATTERN "*.h"
   PATTERN "CMakeFiles" EXCLUDE
Index: polly/cmake/CMakeLists.txt
===
--- polly/cmake/CMakeLists.txt
+++ polly/cmake/CMakeLists.txt
@@ -1,5 +1,6 @@
 # Keep this in sync with llvm/cmake/CMakeLists.txt!
 
+include(ExtendPath)
 include(FindPrefixFromConfig)
 
 set(LLVM_INSTALL_PACKAGE_DIR "lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm")
@@ -83,17 +84,18 @@
 # Generate PollyConfig.cmake for the install tree.
 unset(POLLY_EXPORTS)
 find_prefix_from_config(POLLY_CONFIG_CODE POLLY_INSTALL_PREFIX "${POLLY_INSTALL_PACKAGE_DIR}")
-set(POLLY_CONFIG_LLVM_CMAKE_DIR "\${POLLY_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}")
-set(POLLY_CONFIG_CMAKE_DIR "\${POLLY_INSTALL_PREFIX}/${POLLY_INSTALL_PACKAGE_DIR}")
-set(POLLY_CONFIG_LIBRARY_DIRS "\${POLLY_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}")
+extend_path(POLLY_CONFIG_LLVM_CMAKE_DIR "\${POLLY_INSTALL_PREFIX}" "${LLVM_INSTALL_PACKAGE_DIR}")
+extend_path(POLLY_CONFIG_CMAKE_DIR "\${POLLY_INSTALL_PREFIX}" "${POLLY_INSTALL_PACKAGE_DIR}")
+extend_path(POLLY_CONFIG_LIBRARY_DIRS "\${POLLY_INSTALL_PREFIX}" "lib${LLVM_LIBDIR_SUFFIX}")
+extend_path(base_includedir "\${POLLY_INSTALL_PREFIX}" "${CMAKE_INSTALL_INCLUDEDIR}")
 if (POLLY_BUNDLED_ISL)
   set(POLLY_CONFIG_INCLUDE_DIRS
-"\${POLLY_INSTALL_PREFIX}/include"
-"\${POLLY_INSTALL_PREFIX}/include/polly"
+"${base_includedir}"
+"${base_includedir}/polly"
 )
 else()
   set(POLLY_CONFIG_INCLUDE_DIRS
-"\${POLLY_INSTALL_PREFIX}/include"
+"${base_includedir}"
 ${ISL_INCLUDE_DIRS}
 )
 endif()
@@ -110,12 +112,12 @@
 foreach(tgt IN LISTS POLLY_CONFIG_EXPORTED_TARGETS)
   get_target_property(tgt_type ${tgt} TYPE)
   if (tgt_type STREQUAL "EXECUTABLE")
-set(tgt_prefix "bin/")
+set(tgt_prefix "${CMAKE_INSTALL_BINDIR}/")
   else(

[PATCH] D112718: Add intrinsics and builtins for PTX atomics with semantic orders

2022-01-11 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: clang/include/clang/Basic/BuiltinsNVPTX.def:1057
+
+BUILTIN(__nvvm_atom_xchg_global_i, "iiD*i", "n")
+TARGET_BUILTIN(__nvvm_atom_cta_xchg_global_i, "iiD*i", "n", SM_60)

Naghasan wrote:
> tra wrote:
> > t4c1 wrote:
> > > tra wrote:
> > > > t4c1 wrote:
> > > > > tra wrote:
> > > > > > We need to figure out how address-space-specific builtins are 
> > > > > > supposed to work.
> > > > > > Right now two competing approaches.
> > > > > > 
> > > > > > This patch declares builtins with generic pointer as an argument, 
> > > > > > but, according to the test, expects to be used with the AS-specific 
> > > > > > pointer.
> > > > > > It probably does not catch a wrong-AS pointer passed as an 
> > > > > > argument, either.
> > > > > > It does happen to work, but I think it's mostly due to the fact 
> > > > > > that LLVM intrinsics are overloaded and we happen to end up 
> > > > > > addrspacecast'ing  things correctly if the builtin gets the right 
> > > > > > kind of pointer.
> > > > > > 
> > > > > > The other approach is to declare the pointer with the expected AS. 
> > > > > > E.g:
> > > > > > > TARGET_BUILTIN(__nvvm_mbarrier_init_shared, "vWi*3i", "", 
> > > > > > > AND(SM_80,PTX70))
> > > > > > 
> > > > > > IMO, this is the correct way to do it, but it is also rather 
> > > > > > inconvenient to use from CUDA code as it operates on generic 
> > > > > > pointers.
> > > > > > 
> > > > > > @jdoerfert - WDYT?
> > > > > >TARGET_BUILTIN(__nvvm_mbarrier_init_shared, "vWi*3i", "", 
> > > > > >AND(SM_80,PTX70))
> > > > > >IMO, this is the correct way to do it, but it is also rather 
> > > > > >inconvenient to use from CUDA code as it operates on generic 
> > > > > >pointers.
> > > > > 
> > > > > I tried doing this, however it is also completely unusable from 
> > > > > OpenCL code (which is our use case). Trying to use it gives you 
> > > > > errors about how casting pointers to different address spaces  - for 
> > > > > example from local to AS3 is not allowed.
> > > > Hmm. It should've worked. It would need the same explicit cast to a 
> > > > pointer in AS(3) as in your tests, but it would safeguard against 
> > > > attempts to pass it a generic pointer. E.g. 
> > > > https://godbolt.org/z/qE6oxzheM
> > > > 
> > > > Explicit casting to AS(X) for AS-specific variants is annoying, but 
> > > > it's probably unavoidable at the moment regardless of whether we 
> > > > declare the pointer argument to be AS-specific or not.  LLVM will not 
> > > > always be able to infer that a pointer is in particular AS.
> > > > Using specific AS in the declaration has a minor benefit of 
> > > > safeguarding at compile time against unintentional use of generic 
> > > > pointers.
> > > > 
> > > > Ideally we may want to convert generic variant of the builtin to 
> > > > AS-specific one, if LLVM does know the AS. We currently do this for 
> > > > loads/stores, but not for other instructions.
> > > > 
> > > Well, it does not work. See: https://godbolt.org/z/vM6bKncc4. Declaring 
> > > the pointer to be in generic AS is the only way I got it to work. If you 
> > > know a way to call a builtin declared with AS numbers in OpenCL, I am 
> > > happy to do that instead.
> > Could you help me understand how different address spaces are handled by 
> > OpenCL in clang and LLVM?
> > What exactly are `__local` or `__private` in OpenCL? Do they map to LLVM's 
> > address spaces? 
> > Clang does complain that we're trying to change AS, but I do not see AS 
> > used in the IR: https://godbolt.org/z/soajoE991
> > 
> > AFAICT what happens is:
> > * OpenCL does use explicit AS for pointers (`__local`, `__private` seem to 
> > pop up in the error messages)
> > * `__attribute__((address_space(3)))` does not match the AS of `__local` 
> > and that leads to an error.
> > * generic pointer argument works because we are allowed to cast any 
> > specific AS to generic one.
> > 
> > In other words, having specific-AS arguemt works as intended, we just have 
> > a mismatch between AS number used by OpenCL and AS number used by NVPTX and 
> > we're not allowed to cast between two specific AS.
> > 
> > If that's indeed the case, then what we appear to be missing is the mapping 
> > from OpenCL AS to the target-specific AS, which should, ideally, be done by 
> > clang itself. So, if NVPTX-specific builtin operating on shared pointer is 
> > called with a pointer in OpenCL's equivalent of CUDA's `__shared__`, it 
> > should be mapped to AS(3).
> > 
> > Could you help me understand how different address spaces are handled by 
> > OpenCL in clang and LLVM?
> 
> clang makes a strong distinction between language and target address spaces 
> since ~3.6 (was more loose before). Each target in clang defines a map 
> between language and target address space (e.g. 
> https://github.com/llvm/llvm-project/blob/main/clang/lib/Basic/Targets/SPIR.h#L25).
>  The map is used in clang codegen to lower `__local` to

[PATCH] D116814: [clang-tidy] Accept string literal decay in conditional operator

2022-01-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D116814#3234768 , @estan wrote:

> Thanks @aaron.ballman. I don't have commit/push rights, so someone please 
> commit for me when you got the time.

Happy to! What name and email address would you like me to use for patch 
attribution?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116814

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


[PATCH] D117012: [clang][dataflow] Add transfer functions for data members and this pointers

2022-01-11 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel accepted this revision.
ymandel added a comment.
This revision is now accepted and ready to land.

Thanks!




Comment at: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp:57
+  if (const auto *MethodDecl = dyn_cast(&DeclCtx)) {
+if (!MethodDecl->isStatic()) {
+  QualType ThisPointeeType = MethodDecl->getThisObjectType();

nit: invert the if and return?



Comment at: clang/lib/Analysis/FlowSensitive/Transfer.cpp:145
+auto *BaseLoc = cast_or_null(
+Env.getStorageLocation(*S->getBase(), SkipPast::ReferenceThenPointer));
+if (BaseLoc == nullptr)

nit: maybe comment to explain why we use this setting?



Comment at: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp:834
+const ReferenceValue *FooVal =
+cast(Env.getValue(*FooLoc));
+const StorageLocation &FooPointeeLoc = FooVal->getPointeeLoc();

maybe dyn_cast with ASSERT? (or somesuch)



Comment at: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp:919
+
+EXPECT_EQ(Env.getValue(*BazDecl, SkipPast::None), BarVal);
+  });

Why EXPECT here but ASSERT (as last line) in previous tests?



Comment at: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp:1040
+const auto *ThisLoc =
+
cast(Env.getThisPointeeStorageLocation());
+

dyn_cast and ASSERT (or somesuch)? I'd think that whether or not we have a 
registered `this` in the environment is something we want to test?



Comment at: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp:1059
+
+TEST_F(TransferTest, ClassThisMember) {
+  std::string Code = R"(

why test a class distinct from a struct? Is there a meaningful difference 
between the two with regard to our model? if so, might it be worth instead 
testing explicit public vs private?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117012

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


  1   2   >