[PATCH] D115429: [Clang] Implement the rest of __builtin_elementwise_* functions.

2021-12-09 Thread Jun Zhang via Phabricator via cfe-commits
junaire created this revision.
junaire added reviewers: fhahn, aaron.ballman.
junaire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The patch implement the rest of __builtin_elementwise_* functions
specified in D111529 , including:

- __builtin_elementwise_floor
- __builtin_elementwise_roundeven
- __builtin_elementwise_trunc

Signed-off-by: Jun 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115429

Files:
  clang/include/clang/Basic/Builtins.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-elementwise-math.c
  clang/test/Sema/builtins-elementwise-math.c

Index: clang/test/Sema/builtins-elementwise-math.c
===
--- clang/test/Sema/builtins-elementwise-math.c
+++ clang/test/Sema/builtins-elementwise-math.c
@@ -156,3 +156,66 @@
   uv = __builtin_elementwise_ceil(uv);
   // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
 }
+
+void test_builtin_elementwise_floor(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
+
+  struct Foo s = __builtin_elementwise_floor(f);
+  // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'float'}}
+
+  i = __builtin_elementwise_floor();
+  // expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
+
+  i = __builtin_elementwise_floor(i);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'int')}}
+
+  i = __builtin_elementwise_floor(f, f);
+  // expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
+
+  u = __builtin_elementwise_floor(u);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned int')}}
+
+  uv = __builtin_elementwise_floor(uv);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
+}
+
+void test_builtin_elementwise_roundeven(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
+
+  struct Foo s = __builtin_elementwise_roundeven(f);
+  // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'float'}}
+
+  i = __builtin_elementwise_roundeven();
+  // expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
+
+  i = __builtin_elementwise_roundeven(i);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'int')}}
+
+  i = __builtin_elementwise_roundeven(f, f);
+  // expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
+
+  u = __builtin_elementwise_roundeven(u);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned int')}}
+
+  uv = __builtin_elementwise_roundeven(uv);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
+}
+
+void test_builtin_elementwise_trunc(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
+
+  struct Foo s = __builtin_elementwise_trunc(f);
+  // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'float'}}
+
+  i = __builtin_elementwise_trunc();
+  // expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
+
+  i = __builtin_elementwise_trunc(i);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'int')}}
+
+  i = __builtin_elementwise_trunc(f, f);
+  // expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
+
+  u = __builtin_elementwise_trunc(u);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned int')}}
+
+  uv = __builtin_elementwise_trunc(uv);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
+}
Index: clang/test/CodeGen/builtins-elementwise-math.c
===
--- clang/test/CodeGen/builtins-elementwise-math.c
+++ clang/test/CodeGen/builtins-elementwise-math.c
@@ -205,3 +205,51 @@
   // CHECK-NEXT: call <4 x float> @llvm.ceil.v4f32(<4 x float> [[VF1]])
   vf2 = __builtin_elementwise_ceil(vf1);
 }
+
+void test_builtin_elementwise_floor(float f1, float f2, double d1, double d2,
+float4 vf1, float4 vf2) {
+  // CHECK-LABEL: define void @test_builtin_elementwise_floor(
+  // CHECK:  [[F1:%.+]] = load float, float* %f1.addr, align 4
+  // CHECK-NEXT:  call float @llvm.floor.f32(float [[F1]])
+  f2 = __builtin_elementwise_floor(f1);
+
+  // CHECK:  [[D1:%.+]] = load double, double* %d1.addr, align 8
+  // CHECK-NEXT: call double @llvm.floor.f64(double [[D1]])
+  d2 = __builtin_elementwise_floor(d1);
+
+  // CHECK:  [[VF1:%.+]] = load <4 x float>, <4 x float>* %vf1.addr, align 16
+  

[PATCH] D115231: [Clang] Add __builtin_reduce_xor

2021-12-09 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 393057.
junaire added a comment.

Fix failing CI by running: 
arc diff `git merge-base HEAD origin` --update D115231 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115231

Files:
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-reduction-math.c
  clang/test/Sema/builtins-reduction-math.c

Index: clang/test/Sema/builtins-reduction-math.c
===
--- clang/test/Sema/builtins-reduction-math.c
+++ clang/test/Sema/builtins-reduction-math.c
@@ -35,3 +35,20 @@
   i = __builtin_reduce_min(i);
   // expected-error@-1 {{1st argument must be a vector type (was 'int')}}
 }
+
+void test_builtin_reduce_xor(int i, float4 v, int3 iv) {
+  struct Foo s = __builtin_reduce_xor(iv);
+  // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'int'}}
+
+  i = __builtin_reduce_xor();
+  // expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
+
+  i = __builtin_reduce_xor(iv, iv);
+  // expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
+
+  i = __builtin_reduce_xor(i);
+  // expected-error@-1 {{1st argument must be a vector of integers (was 'int')}}
+
+  i = __builtin_reduce_xor(v);
+  // expected-error@-1 {{1st argument must be a vector of integers (was 'float4' (vector of 4 'float' values))}}
+}
Index: clang/test/CodeGen/builtins-reduction-math.c
===
--- clang/test/CodeGen/builtins-reduction-math.c
+++ clang/test/CodeGen/builtins-reduction-math.c
@@ -57,3 +57,14 @@
   const si8 cvi1 = vi1;
   unsigned long long r5 = __builtin_reduce_min(cvi1);
 }
+
+void test_builtin_reduce_xor(si8 vi1, u4 vu1) {
+
+  // CHECK:  [[VI1:%.+]] = load <8 x i16>, <8 x i16>* %vi1.addr, align 16
+  // CHECK-NEXT: call i16 @llvm.vector.reduce.xor.v8i16(<8 x i16> [[VI1]])
+  short r2 = __builtin_reduce_xor(vi1);
+
+  // CHECK:  [[VU1:%.+]] = load <4 x i32>, <4 x i32>* %vu1.addr, align 16
+  // CHECK-NEXT: call i32 @llvm.vector.reduce.xor.v4i32(<4 x i32> [[VU1]])
+  unsigned r3 = __builtin_reduce_xor(vu1);
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -2112,6 +2112,24 @@
 if (SemaBuiltinReduceMath(TheCall))
   return ExprError();
 break;
+
+  // __builtin_reduce_xor supports vector of integers only.
+  case Builtin::BI__builtin_reduce_xor: {
+if (SemaBuiltinReduceMath(TheCall))
+  return ExprError();
+
+const auto *Arg = TheCall->getArg(0);
+if (!Arg->getType()
+ ->getAs()
+ ->getElementType()
+ ->isIntegerType()) {
+  Diag(Arg->getBeginLoc(), diag::err_builtin_invalid_arg_type)
+  << 1 /* vector of integers */ << 5 << Arg->getType();
+  return ExprError();
+}
+break;
+  }
+
   case Builtin::BI__builtin_matrix_transpose:
 return SemaBuiltinMatrixTranspose(TheCall, TheCallResult);
 
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -3204,6 +3204,13 @@
 return RValue::get(Result);
   }
 
+  case Builtin::BI__builtin_reduce_xor: {
+Value *Op0 = EmitScalarExpr(E->getArg(0));
+Value *Result = Builder.CreateUnaryIntrinsic(
+llvm::Intrinsic::vector_reduce_xor, Op0, nullptr, "rdx.xor");
+return RValue::get(Result);
+  }
+
   case Builtin::BI__builtin_matrix_transpose: {
 const auto *MatrixTy = E->getArg(0)->getType()->getAs();
 Value *MatValue = EmitScalarExpr(E->getArg(0));
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11356,7 +11356,8 @@
   "%ordinal0 argument must be a "
   "%select{vector, integer or floating point type|matrix|"
"pointer to a valid matrix element type|"
-   "signed integer or floating point type|vector type}1 (was %2)">;
+   "signed integer or floating point type|vector type|"
+   "vector of integers}1 (was %2)">;
 
 def err_builtin_matrix_disabled: Error<
   "matrix types extension is disabled. Pass -fenable-matrix to enable it">;
Index: clang/include/clang/Basic/Builtins.def
===
--- clang/include/clang/Basic/Builtins.def
+++ clang/include/clang/Basic/Builtins.def
@@ -648,6 +648,7 @@
 BUILTIN(__builtin_elementwise_min, "v.", "nct")
 BUILTIN(__builtin_reduce_max, "v.", "nct")
 BUILTIN(__builtin

[PATCH] D114394: Compile-time computation of string attribute hashes

2021-12-09 Thread serge via Phabricator via cfe-commits
serge-sans-paille updated this revision to Diff 393058.
serge-sans-paille added a comment.

Use a DenseSet instead of a DenseMap to store the StringPool.

Some benchmark feedback (using a release build compiled with LTO), in number of 
instructions

|  | sqlite3.c -c -O0 | sqlite3.c -S -emit-llvm | sqlite3.ll -c |
| before patch | 6.12G| 4.68G   | 4.42G |
| after patch  | 6.06G| 4.62G   | 4.38G |
|

I also tried some micro benchmark on the C-API and C++ API, using compile-time 
known Attribute name

  #include "llvm-c/Core.h"
  #include 
  #include 
  
  int main(int argc, char** argv) {
  
int n = strlen(argv[0]);
LLVMContextRef ctx = LLVMContextCreate();
LLVMModuleRef mod = LLVMModuleCreateWithName("name");
LLVMAttributeRef Key =
LLVMCreateStringAttribute(ctx, argv[0], n, "myvalue", 7);
LLVMValueRef value = LLVMGetIntrinsicDeclaration(mod, 25, {}, 0);
LLVMDumpValue(value);
LLVMAddAttributeAtIndex(value, 0, Key);
unsigned size;
char buffer[100];
for (int i = 0; i < 1; ++i) {
  for (int j = 0; j < 1000; ++j) {
LLVMGetStringAttributeAtIndex(value, 0, argv[0], n);
size += n;
  }
}
return size;
  }

Here are the result (in seconds)

|  | C API | C++ API |
| before the patch | 0.12  | 0.12|
| after the patch  | 0.14  | 0.08|
|

So basically, the drawback of this patch is that there is a double lookup (and 
thus two calls to `strcmp`) for each dynamic attribute request.
The advantage is that there's a single lookup and no allocation for static 
attribute request. At least for clang, this seems to be the most common request.


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

https://reviews.llvm.org/D114394

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  llvm/include/llvm/Analysis/TargetLibraryInfo.h
  llvm/include/llvm/Analysis/VectorUtils.h
  llvm/include/llvm/CodeGen/CommandFlags.h
  llvm/include/llvm/IR/Assumptions.h
  llvm/include/llvm/IR/Attributes.h
  llvm/include/llvm/IR/Function.h
  llvm/include/llvm/IR/GlobalVariable.h
  llvm/include/llvm/IR/InstrTypes.h
  llvm/include/llvm/ProfileData/SampleProf.h
  llvm/lib/Analysis/InlineCost.cpp
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/CodeGen/CommandFlags.cpp
  llvm/lib/IR/AttributeImpl.h
  llvm/lib/IR/Attributes.cpp
  llvm/lib/IR/Core.cpp
  llvm/lib/IR/DiagnosticInfo.cpp
  llvm/lib/IR/Function.cpp
  llvm/lib/IR/Instructions.cpp
  llvm/lib/IR/LLVMContextImpl.h
  llvm/lib/IR/Verifier.cpp
  llvm/lib/Transforms/IPO/Attributor.cpp
  llvm/lib/Transforms/IPO/OpenMPOpt.cpp
  llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
  llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
  llvm/lib/Transforms/Utils/CodeExtractor.cpp
  llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp

Index: llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp
===
--- llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp
+++ llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp
@@ -67,11 +67,13 @@
 }
 
 static bool runOnFunction(Function &F, bool PostInlining) {
-  StringRef EntryAttr = PostInlining ? "instrument-function-entry-inlined"
- : "instrument-function-entry";
+  AttributeKey EntryAttr =
+  PostInlining ? AttributeKey("instrument-function-entry-inlined")
+   : AttributeKey("instrument-function-entry");
 
-  StringRef ExitAttr = PostInlining ? "instrument-function-exit-inlined"
-: "instrument-function-exit";
+  AttributeKey ExitAttr = PostInlining
+  ? AttributeKey("instrument-function-exit-inlined")
+  : AttributeKey("instrument-function-exit");
 
   StringRef EntryFunc = F.getFnAttribute(EntryAttr).getValueAsString();
   StringRef ExitFunc = F.getFnAttribute(ExitAttr).getValueAsString();
Index: llvm/lib/Transforms/Utils/CodeExtractor.cpp
===
--- llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -888,7 +888,7 @@
   //   attribute can not be inherited.
   for (const auto &Attr : oldFunction->getAttributes().getFnAttrs()) {
 if (Attr.isStringAttribute()) {
-  if (Attr.getKindAsString() == "thunk")
+  if (Attr.getKindAsKey() == "thunk")
 continue;
 } else
   switch (Attr.getKindAsEnum()) {
Index: llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
===
--- llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
+++ llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
@@ -1528,7 +1528,7 @@
 } // end anon

[PATCH] D115430: [RISCV] Fix upper bound of RISC-V V type in debug info

2021-12-09 Thread Haocong Lu via Phabricator via cfe-commits
Luhaocong created this revision.
Luhaocong added reviewers: craig.topper, rogfer01, frasercrmck, arcbbb, luke957.
Luhaocong added a project: clang.
Herald added subscribers: VincentWu, achieveartificialintelligence, vkmr, 
evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, 
jocewei, PkmX, the_o, brucehoult, MartinMosbeck, edward-jones, zzheng, jrtc27, 
kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, asb.
Luhaocong requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.

The UpperBound of RVV type in debug info should be elements count minus one,
as the LowerBound start from zero.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115430

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGen/RISCV/riscv-v-debuginfo.c


Index: clang/test/CodeGen/RISCV/riscv-v-debuginfo.c
===
--- clang/test/CodeGen/RISCV/riscv-v-debuginfo.c
+++ clang/test/CodeGen/RISCV/riscv-v-debuginfo.c
@@ -9,7 +9,7 @@
 }
 
 // !DISubrange(lowerBound: 0, upperBound: !DIExpression(DW_OP_bregx, 7202, 0, 
DW_OP_con
-// DEBUGINFO: stu, 2, DW_OP_div, DW_OP_constu, 2, DW_OP_mul))
+// DEBUGINFO: stu, 2, DW_OP_div, DW_OP_constu, 2, DW_OP_mul, DW_OP_constu, 1, 
DW_OP_minus))
 
 __rvv_int16mf2_t f2(__rvv_int16mf2_t arg_0, __rvv_int16mf2_t arg_1, int64_t 
arg_2) {
   __rvv_int16mf2_t ret;
@@ -17,7 +17,7 @@
 }
 
 // !DISubrange(lowerBound: 0, upperBound: !DIExpression(DW_OP_bregx, 7202, 0, 
DW_OP_con
-// DEBUGINFO: stu, 2, DW_OP_div, DW_OP_constu, 2, DW_OP_div))
+// DEBUGINFO: stu, 2, DW_OP_div, DW_OP_constu, 2, DW_OP_div, DW_OP_constu, 1, 
DW_OP_minus))
 
 __rvv_int32mf2_t f3(__rvv_int32mf2_t arg_0, __rvv_int32mf2_t arg_1, int64_t 
arg_2) {
   __rvv_int32mf2_t ret;
@@ -25,4 +25,4 @@
 }
 
 // !DISubrange(lowerBound: 0, upperBound: !DIExpression(DW_OP_bregx, 7202, 0, 
DW_OP_con
-// DEBUGINFO: stu, 4, DW_OP_div, DW_OP_constu, 2, DW_OP_div))
+// DEBUGINFO: stu, 4, DW_OP_div, DW_OP_constu, 2, DW_OP_div, DW_OP_constu, 1, 
DW_OP_minus))
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -768,7 +768,7 @@
   }
 
   // Element count = (VLENB / SEW) x LMUL
-  SmallVector Expr(
+  SmallVector Expr(
   // The DW_OP_bregx operation has two operands: a register which is
   // specified by an unsigned LEB128 number, followed by a signed 
LEB128
   // offset.
@@ -782,6 +782,8 @@
 Expr.push_back(llvm::dwarf::DW_OP_div);
   else
 Expr.push_back(llvm::dwarf::DW_OP_mul);
+  // Element max index = count - 1
+  Expr.append({llvm::dwarf::DW_OP_constu, 1, llvm::dwarf::DW_OP_minus});
 
   auto *LowerBound =
   llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(


Index: clang/test/CodeGen/RISCV/riscv-v-debuginfo.c
===
--- clang/test/CodeGen/RISCV/riscv-v-debuginfo.c
+++ clang/test/CodeGen/RISCV/riscv-v-debuginfo.c
@@ -9,7 +9,7 @@
 }
 
 // !DISubrange(lowerBound: 0, upperBound: !DIExpression(DW_OP_bregx, 7202, 0, DW_OP_con
-// DEBUGINFO: stu, 2, DW_OP_div, DW_OP_constu, 2, DW_OP_mul))
+// DEBUGINFO: stu, 2, DW_OP_div, DW_OP_constu, 2, DW_OP_mul, DW_OP_constu, 1, DW_OP_minus))
 
 __rvv_int16mf2_t f2(__rvv_int16mf2_t arg_0, __rvv_int16mf2_t arg_1, int64_t arg_2) {
   __rvv_int16mf2_t ret;
@@ -17,7 +17,7 @@
 }
 
 // !DISubrange(lowerBound: 0, upperBound: !DIExpression(DW_OP_bregx, 7202, 0, DW_OP_con
-// DEBUGINFO: stu, 2, DW_OP_div, DW_OP_constu, 2, DW_OP_div))
+// DEBUGINFO: stu, 2, DW_OP_div, DW_OP_constu, 2, DW_OP_div, DW_OP_constu, 1, DW_OP_minus))
 
 __rvv_int32mf2_t f3(__rvv_int32mf2_t arg_0, __rvv_int32mf2_t arg_1, int64_t arg_2) {
   __rvv_int32mf2_t ret;
@@ -25,4 +25,4 @@
 }
 
 // !DISubrange(lowerBound: 0, upperBound: !DIExpression(DW_OP_bregx, 7202, 0, DW_OP_con
-// DEBUGINFO: stu, 4, DW_OP_div, DW_OP_constu, 2, DW_OP_div))
+// DEBUGINFO: stu, 4, DW_OP_div, DW_OP_constu, 2, DW_OP_div, DW_OP_constu, 1, DW_OP_minus))
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -768,7 +768,7 @@
   }
 
   // Element count = (VLENB / SEW) x LMUL
-  SmallVector Expr(
+  SmallVector Expr(
   // The DW_OP_bregx operation has two operands: a register which is
   // specified by an unsigned LEB128 number, followed by a signed LEB128
   // offset.
@@ -782,6 +782,8 @@
 Expr.push_back(llvm::dwarf::DW_OP_div);
   else
 Expr.push_back(llvm::dwarf::DW_OP_mul);
+  // Element max index = count - 1
+  Expr.append({llvm::dwarf::DW_OP_constu, 1, llvm::dwarf::DW_OP_minus});
 
   auto *LowerBound =
   llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSig

[PATCH] D115050: [clang-format] PR48916 PointerAlignment not working when using C++20 init-statement in for loop

2021-12-09 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! Thanks.


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

https://reviews.llvm.org/D115050

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


[PATCH] D102669: [analyzer][ctu] Fix wrong 'multiple definitions' errors caused by space characters in lookup names when parsing the ctu index file

2021-12-09 Thread Ella Ma via Phabricator via cfe-commits
OikawaKirie added inline comments.



Comment at: clang/lib/CrossTU/CrossTranslationUnit.cpp:154-172
+  // Find the length delimiter.
+  const size_t LengthDelimiter = LineRef.find(':');
+  if (StringRef::npos == LengthDelimiter)
+return false;
+
+  // Parse the length of LookupName as USRLength.
+  size_t USRLength = 0;

steakhal wrote:
> OikawaKirie wrote:
> > steakhal wrote:
> > > OikawaKirie wrote:
> > > > steakhal wrote:
> > > > > OikawaKirie wrote:
> > > > > > steakhal wrote:
> > > > > > > 
> > > > > > The source of lookup name of the function being imported is 
> > > > > > function `CrossTranslationUnitContext::getLookupName`. Keeping the 
> > > > > > length in the mapping can avoid parsing the lookup name during 
> > > > > > importing.
> > > > > Okay; you can copy the original StringRef to have that. But by 
> > > > > consuming it on one path makes the code much more readable.
> > > > > 
> > > > The `getAsInterger` call can also check whether the content before the 
> > > > first colon is an integer. Therefore, a sub-string operation is 
> > > > required here.
> > > I don't doubt that your proposed way of doing this works and is efficient.
> > > What I say is that I think there is room for improvement in the 
> > > non-functional aspects, in the readability. However, it's not really a 
> > > blocking issue, more of a personal taste.
> > I know what you are considering, it is clearer and more readable by 
> > consuming the length, then the USR. However, to correctly separate the USR 
> > and file path, the length of `USR-Length` is also required, which makes it 
> > impossible to just *consume* the length at the beginning.
> > 
> > Another way of solving this problem is to re-create the string with the 
> > USR-Length and the USR after parsing, but I think it is not a good solution.
> > 
> > BTW, is it necessary to assert the `USR-Length` to be greater than zero? I 
> > think it is more reasonable to report *invalid format* rather than assert 
> > the value, as it can be provided by the user.
> I think what causes the misunderstanding is the definition of //consume// in 
> the context of `StringRef`.
> ```lang=C++
> const StringRef Copy = Line;
> Line.consumeInteger(...); // Line advances forward by the number of 
> characters that were parsed as an integral value.
> // Copy still refers to the unmodified, original characters.
> // I can use it however I want.
> 
> // `Line` is a suffix of `Copy`, and the `.end()` should be the same, only 
> `.begin()` should differ.
> ```
> 
> I hope that caused the miscommunication.
> 
> ---
> > BTW, is it necessary to assert the USR-Length to be greater than zero? I 
> > think it is more reasonable to report *invalid format* rather than assert 
> > the value, as it can be provided by the user.
> Yeah, sure!
I think I have figured out what have been misunderstood.

In the current patch, I just modify function 
`CrossTranslationUnitContext::getLookupName` by adding a length at the 
beginning. Therefore, the lookup name for the CTU query will have the length 
part. And for the sake of simplicity and efficiency, the length together with 
the USR is stored in the mapping as the key.

To correctly parse the `:` part, I cannot just consume the 
`` at the beginning. Otherwise, I cannot know the length of 
`:` part, which makes it impossible to parse the entire 
`:` part, even though the original `Line` is copied.

I will update the approach of adding the length part. Since the length is only 
used during parsing the CTU index, I will modify function 
`createCrossTUIndexString` to add the length and revert the changes to function 
`CrossTranslationUnitContext::getLookupName` to keep the lookup name for CTU 
query unchanged.



Comment at: clang/test/Analysis/Inputs/ctu-lookup-name-with-space.cpp:12-14
+int importee(int X) {
+  return 1 / X;
+}

steakhal wrote:
> Also fixup the return type in the declaration within the main TU. Also add 
> the `// expected-no-diagnostics` comment to the primary TU.
Yes, you are right.
I was misled by myself.


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

https://reviews.llvm.org/D102669

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


[PATCH] D102669: [analyzer][ctu] Fix wrong 'multiple definitions' errors caused by space characters in lookup names when parsing the ctu index file

2021-12-09 Thread Ella Ma via Phabricator via cfe-commits
OikawaKirie updated this revision to Diff 393064.
OikawaKirie added a comment.

1. Revert function `CrossTranslationUnitContext::getLookupName`
2. Add length when dumping the CTU index mapping via function 
`createCrossTUIndexString`
3. Remove the assertions during CTU map query process
4. Make function `parseCrossTUIndexItem` more readable


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

https://reviews.llvm.org/D102669

Files:
  clang/docs/analyzer/user-docs/CrossTranslationUnit.rst
  clang/include/clang/Basic/DiagnosticCrossTUKinds.td
  clang/lib/CrossTU/CrossTranslationUnit.cpp
  clang/test/Analysis/Inputs/ctu-import.c.externalDefMap.ast-dump.txt
  clang/test/Analysis/Inputs/ctu-lookup-name-with-space.cpp
  clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.ast-dump.txt
  clang/test/Analysis/Inputs/ctu-other.cpp.externalDefMap.ast-dump.txt
  
clang/test/Analysis/Inputs/plist-macros-with-expansion-ctu.c.externalDefMap.txt
  clang/test/Analysis/ctu-inherited-default-ctor.cpp
  clang/test/Analysis/ctu-lookup-name-with-space.cpp
  clang/test/Analysis/func-mapping-test.cpp
  clang/unittests/CrossTU/CrossTranslationUnitTest.cpp

Index: clang/unittests/CrossTU/CrossTranslationUnitTest.cpp
===
--- clang/unittests/CrossTU/CrossTranslationUnitTest.cpp
+++ clang/unittests/CrossTU/CrossTranslationUnitTest.cpp
@@ -61,7 +61,7 @@
 ASSERT_FALSE(llvm::sys::fs::createTemporaryFile("index", "txt", IndexFD,
 IndexFileName));
 llvm::ToolOutputFile IndexFile(IndexFileName, IndexFD);
-IndexFile.os() << "c:@F@f#I# " << ASTFileName << "\n";
+IndexFile.os() << "9:c:@F@f#I# " << ASTFileName << "\n";
 IndexFile.os().flush();
 EXPECT_TRUE(llvm::sys::fs::exists(IndexFileName));
 
Index: clang/test/Analysis/func-mapping-test.cpp
===
--- clang/test/Analysis/func-mapping-test.cpp
+++ clang/test/Analysis/func-mapping-test.cpp
@@ -3,10 +3,10 @@
 int f(int) {
   return 0;
 }
-// CHECK-DAG: c:@F@f#I#
+// CHECK-DAG: 9:c:@F@f#I#
 
 extern const int x = 5;
-// CHECK-DAG: c:@x
+// CHECK-DAG: 4:c:@x
 
 // Non-const variables should not be collected.
 int y = 5;
@@ -18,29 +18,29 @@
   int a;
 };
 extern S const s = {.a = 2};
-// CHECK-DAG: c:@s
+// CHECK-DAG: 4:c:@s
 
 struct SF {
   const int a;
 };
 SF sf = {.a = 2};
-// CHECK-DAG: c:@sf
+// CHECK-DAG: 5:c:@sf
 
 struct SStatic {
   static const int a = 4;
 };
 const int SStatic::a;
-// CHECK-DAG: c:@S@SStatic@a
+// CHECK-DAG: 14:c:@S@SStatic@a
 
 extern int const arr[5] = { 0, 1 };
-// CHECK-DAG: c:@arr
+// CHECK-DAG: 6:c:@arr
 
 union U {
   const int a;
   const unsigned int b;
 };
 U u = {.a = 6};
-// CHECK-DAG: c:@u
+// CHECK-DAG: 4:c:@u
 
 // No USR can be generated for this.
 // Check for no crash in this case.
@@ -48,3 +48,15 @@
   float uf;
   const int ui;
 };
+
+void f(int (*)(char));
+void f(bool (*)(char));
+
+struct G {
+  G() {
+f([](char) -> int { return 42; });
+// CHECK-DAG: 41:c:@S@G@F@G#@Sa@F@operator int (*)(char)#1
+f([](char) -> bool { return true; });
+// CHECK-DAG: 42:c:@S@G@F@G#@Sa@F@operator bool (*)(char)#1
+  }
+};
Index: clang/test/Analysis/ctu-lookup-name-with-space.cpp
===
--- /dev/null
+++ clang/test/Analysis/ctu-lookup-name-with-space.cpp
@@ -0,0 +1,25 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+
+// RUN: cp %s %t/trigger.cpp
+// RUN: cp %S/Inputs/ctu-lookup-name-with-space.cpp %t/importee.cpp
+// RUN: echo '"%t/importee.cpp" : ["g++", "-c", "%t/importee.cpp"]' > %t/invocations.yaml
+// RUN: echo '[{"directory": "%t", "command": "g++ -c %t/importee.cpp", "file": "%t/importee.cpp"}, {"directory": "%t", "command": "g++ -c %t/trigger.cpp", "file": "%t/trigger.cpp"}]' > %t/compile_commands.json
+
+// RUN: %clang_extdef_map -p %t %t/importee.cpp > %t/externalDefMap.txt
+
+// RUN: cd %t && %clang_cc1 -fsyntax-only -analyze \
+// RUN:   -analyzer-checker=core,debug.ExprInspection \
+// RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \
+// RUN:   -analyzer-config ctu-dir=. \
+// RUN:   -analyzer-config ctu-invocation-list=invocations.yaml \
+// RUN:   -verify trigger.cpp
+
+void importee();
+
+void trigger() {
+  // Call an external function to trigger the parsing process of CTU index.
+  // Refer to file Inputs/ctu-lookup-name-with-space.cpp for more details.
+
+  importee(); // expected-no-diagnostics
+}
Index: clang/test/Analysis/ctu-inherited-default-ctor.cpp
===
--- clang/test/Analysis/ctu-inherited-default-ctor.cpp
+++ clang/test/Analysis/ctu-inherited-default-ctor.cpp
@@ -4,7 +4,7 @@
 // RUN: %clang_cc1 -std=c++14 -triple x86_64-pc-linux-gnu \
 // RUN:   -emit-pch -o %t/ctudir/ctu-inherited-default-ctor-other.cpp.ast \
 // RUN:%S/Inputs/ctu-inherited-default-ctor-other.cpp
-/

[PATCH] D102090: [CMake][ELF] Link libLLVM.so and libclang-cpp.so with -Bsymbolic-functions

2021-12-09 Thread Evgeniy via Phabricator via cfe-commits
ebrevnov added a comment.

> ! In D102090#3174187 , @rnk wrote:
>  In any case, -Bsymbolic is not a good default for the project because of 
> issues like this.

I see. Thank you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102090

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


[PATCH] D115149: [analyzer][solver] Fix assertion on (NonLoc, Op, Loc) expressions

2021-12-09 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

@steakhal
 @NoQ wrote:

> I'm confident that there's a way to get it right, simply because the program 
> under analysis is type-correct. If it's the simplifier, let's fix the 
> simplifier.

I agree with your main thought. But I also believe there definitely are thing 
to improve everywhere. And this one could wait until we find the root cause and 
correct it somewhere before.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115149

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


[PATCH] D115149: [analyzer][solver] Fix assertion on (NonLoc, Op, Loc) expressions

2021-12-09 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp:463
+  if (const Optional RV = rhs.getAs()) {
+const auto IsCommutative = [](BinaryOperatorKind Op) {
+  return Op == BO_Mul || Op == BO_Add || Op == BO_And || Op == BO_Xor ||

steakhal wrote:
> ASDenysPetrov wrote:
> > IMO it should be in a family of `BinaryOperator::is..` methods.
> It isn't as easy as it might seem at first glance. I've considered doing it 
> that way.
> In our context, we don't really deal with floating-point numbers, but in the 
> generic implementation, we should have the type in addition to the OpKind. We 
> don't need that complexity, so I sticked to inlining them here.
I see your concerns about floats but the operators don't stop to be commutative 
themselves. Yes, it may not work with some types but it will still be 
commutative. Leave the context for a user outside the function. It may bother 
you only a few operators from the set and you just check whether they belong to 
the set or not.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115149

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


[clang] 5882283 - [clang][deps] Use lock_guard instead of unique_lock

2021-12-09 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2021-12-09T10:42:50+01:00
New Revision: 58822837cd53cdbe9c1b878c705b288f17a52f98

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

LOG: [clang][deps] Use lock_guard instead of unique_lock

This patch changes uses of `std::unique_lock` to `std::lock_guard`.

The `std::unique_lock` template provides some advanced capabilities (deferred 
locking, time-constrained locking attempts, etc.) we don't use in the caching 
filesystem. Plain `std::lock_guard` will do here.

Reviewed By: dexonsmith

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

Added: 


Modified: 
clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp

Removed: 




diff  --git 
a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp 
b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
index f7c711690d7ea..8a85f5971f4b2 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -113,7 +113,7 @@ 
DependencyScanningFilesystemSharedCache::SingleCache::SingleCache() {
 DependencyScanningFilesystemSharedCache::SharedFileSystemEntry &
 DependencyScanningFilesystemSharedCache::SingleCache::get(StringRef Key) {
   CacheShard &Shard = CacheShards[llvm::hash_value(Key) % NumShards];
-  std::unique_lock LockGuard(Shard.CacheLock);
+  std::lock_guard LockGuard(Shard.CacheLock);
   auto It = Shard.Cache.try_emplace(Key);
   return It.first->getValue();
 }
@@ -195,7 +195,7 @@ 
DependencyScanningWorkerFilesystem::getOrCreateFileSystemEntry(
   &SharedCacheEntry = SharedCache.get(Filename, ShouldMinimize);
   const CachedFileSystemEntry *Result;
   {
-std::unique_lock LockGuard(SharedCacheEntry.ValueLock);
+std::lock_guard LockGuard(SharedCacheEntry.ValueLock);
 CachedFileSystemEntry &CacheEntry = SharedCacheEntry.Value;
 
 if (!CacheEntry.isValid()) {



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


[PATCH] D115332: [clang][deps] Use lock_guard instead of unique_lock

2021-12-09 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG58822837cd53: [clang][deps] Use lock_guard instead of 
unique_lock (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115332

Files:
  clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp


Index: clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -113,7 +113,7 @@
 DependencyScanningFilesystemSharedCache::SharedFileSystemEntry &
 DependencyScanningFilesystemSharedCache::SingleCache::get(StringRef Key) {
   CacheShard &Shard = CacheShards[llvm::hash_value(Key) % NumShards];
-  std::unique_lock LockGuard(Shard.CacheLock);
+  std::lock_guard LockGuard(Shard.CacheLock);
   auto It = Shard.Cache.try_emplace(Key);
   return It.first->getValue();
 }
@@ -195,7 +195,7 @@
   &SharedCacheEntry = SharedCache.get(Filename, ShouldMinimize);
   const CachedFileSystemEntry *Result;
   {
-std::unique_lock LockGuard(SharedCacheEntry.ValueLock);
+std::lock_guard LockGuard(SharedCacheEntry.ValueLock);
 CachedFileSystemEntry &CacheEntry = SharedCacheEntry.Value;
 
 if (!CacheEntry.isValid()) {


Index: clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -113,7 +113,7 @@
 DependencyScanningFilesystemSharedCache::SharedFileSystemEntry &
 DependencyScanningFilesystemSharedCache::SingleCache::get(StringRef Key) {
   CacheShard &Shard = CacheShards[llvm::hash_value(Key) % NumShards];
-  std::unique_lock LockGuard(Shard.CacheLock);
+  std::lock_guard LockGuard(Shard.CacheLock);
   auto It = Shard.Cache.try_emplace(Key);
   return It.first->getValue();
 }
@@ -195,7 +195,7 @@
   &SharedCacheEntry = SharedCache.get(Filename, ShouldMinimize);
   const CachedFileSystemEntry *Result;
   {
-std::unique_lock LockGuard(SharedCacheEntry.ValueLock);
+std::lock_guard LockGuard(SharedCacheEntry.ValueLock);
 CachedFileSystemEntry &CacheEntry = SharedCacheEntry.Value;
 
 if (!CacheEntry.isValid()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113254: [clang] Fix a misadjusted path style comparison in a unittest

2021-12-09 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

Yeah I guess I should have just committed this as trivial. Anyway, it doesn't 
seem to have had any notable impact on anything - luckily.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113254

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


[clang] 120d44d - [clang] Fix a misadjusted path style comparison in a unittest

2021-12-09 Thread Martin Storsjö via cfe-commits

Author: Martin Storsjö
Date: 2021-12-09T11:47:43+02:00
New Revision: 120d44d1a00b12b79057420eb1d89277522348b1

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

LOG: [clang] Fix a misadjusted path style comparison in a unittest

This was changed incorrectly by accident in
99023627010bbfefb71e25a2b4d056de1cbd354e.

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

Added: 


Modified: 
clang/unittests/Driver/ToolChainTest.cpp

Removed: 




diff  --git a/clang/unittests/Driver/ToolChainTest.cpp 
b/clang/unittests/Driver/ToolChainTest.cpp
index 62ad6f7d53714..286ad84e92d67 100644
--- a/clang/unittests/Driver/ToolChainTest.cpp
+++ b/clang/unittests/Driver/ToolChainTest.cpp
@@ -151,7 +151,7 @@ TEST(ToolChainTest, VFSGCCInstallationRelativeDir) {
 llvm::raw_string_ostream OS(S);
 C->getDefaultToolChain().printVerboseInfo(OS);
   }
-  if (is_style_windows(llvm::sys::path::Style::windows))
+  if (is_style_windows(llvm::sys::path::Style::native))
 std::replace(S.begin(), S.end(), '\\', '/');
   EXPECT_EQ("Found candidate GCC installation: "
 "/home/test/bin/../lib/gcc/arm-linux-gnueabi/4.6.1\n"



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


[PATCH] D113254: [clang] Fix a misadjusted path style comparison in a unittest

2021-12-09 Thread Martin Storsjö via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG120d44d1a00b: [clang] Fix a misadjusted path style 
comparison in a unittest (authored by mstorsjo).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113254

Files:
  clang/unittests/Driver/ToolChainTest.cpp


Index: clang/unittests/Driver/ToolChainTest.cpp
===
--- clang/unittests/Driver/ToolChainTest.cpp
+++ clang/unittests/Driver/ToolChainTest.cpp
@@ -151,7 +151,7 @@
 llvm::raw_string_ostream OS(S);
 C->getDefaultToolChain().printVerboseInfo(OS);
   }
-  if (is_style_windows(llvm::sys::path::Style::windows))
+  if (is_style_windows(llvm::sys::path::Style::native))
 std::replace(S.begin(), S.end(), '\\', '/');
   EXPECT_EQ("Found candidate GCC installation: "
 "/home/test/bin/../lib/gcc/arm-linux-gnueabi/4.6.1\n"


Index: clang/unittests/Driver/ToolChainTest.cpp
===
--- clang/unittests/Driver/ToolChainTest.cpp
+++ clang/unittests/Driver/ToolChainTest.cpp
@@ -151,7 +151,7 @@
 llvm::raw_string_ostream OS(S);
 C->getDefaultToolChain().printVerboseInfo(OS);
   }
-  if (is_style_windows(llvm::sys::path::Style::windows))
+  if (is_style_windows(llvm::sys::path::Style::native))
 std::replace(S.begin(), S.end(), '\\', '/');
   EXPECT_EQ("Found candidate GCC installation: "
 "/home/test/bin/../lib/gcc/arm-linux-gnueabi/4.6.1\n"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115106: [clang-tidy] Fix `readability-static-accessed-through-instance` false negative for static methods

2021-12-09 Thread Simon Giesecke via Phabricator via cfe-commits
simon.giesecke added a comment.

In D115106#3180439 , @aaron.ballman 
wrote:

> In D115106#3172949 , 
> @simon.giesecke wrote:
>
>> Thanks a lot for addressing this issue! I am just trying it on our codebase.
>>
>>> The problem actually has nothing to do with the out-of-line definition 
>>> being inline; the problem is that hasDeclaration() of the memberExpr() will 
>>> match the out-of-line definition, which obviously isn't marked static, so 
>>> isStaticStorageClass() won't match.
>>
>> Hm, an out-of-line definition *cannot* have the `static` keyword. I wonder 
>> if it's actually a bug (in the AST? or just the matcher?) that 
>> `isStaticStorageClass` doesn't match here? I guess that other checks that 
>> use `isStaticStorageClass` might be affected by this too?
>
> `isStaticStorageClass()` calls through to `FunctionDecl::getStorageClass()` 
> which reports the storage as written on that declaration in source. So this 
> isn't a bug in the AST, it's a more of a misunderstanding of whether we're 
> querying the storage duration/linkage for the method or whether we're 
> querying whether it was written with the static keyword.

I see, makes sense.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115106

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


[PATCH] D115106: [clang-tidy] Fix `readability-static-accessed-through-instance` false negative for static methods

2021-12-09 Thread Simon Giesecke via Phabricator via cfe-commits
simon.giesecke added inline comments.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:6017
+/// cxxMethodDecl(isStatic()) matches A::foo() but not A::bar()
+AST_MATCHER(CXXMethodDecl, isStatic) { return Node.isStatic(); }
+

aaron.ballman wrote:
> I would prefer we not expose this AST matcher as a public one. There's 
> sufficient confusion around "as written in source" vs "computed" vs "linkage" 
> in this area that I think we should be careful when introducing matchers 
> around storage classes and storage durations. Then again, the water is 
> already pretty muddy here, so maybe this ship sailed...
> 
> Other potential solutions to this issue would be to expose an AST matcher to 
> traverse to the canonical decl or only matches the canonical decl, then we 
> could use that to wrap the existing call to `isStaticStorageClass()`. (Of 
> course, we could make this matcher local to just that source file, as well.)
> 
> Thoughts?
I think if we have a `isStaticStorageClass` matcher, then we can also have 
`isStatic` matcher.

But maybe we shouldn't have either of those in the public header, but maybe add 
a different one as you suggested, under a suitable name with as little 
ambiguity as possible.

And maybe keep the `isStaticStorageClass` matcher but rename it to reduce the 
chance of misunderstanding?

Then, as mentioned in my original top-level comment, I can imagine that there 
are more uses of the `isStaticStorageClass` matcher in clang-tidy rules (and 
maybe elsewhere) that actually should use the new matcher.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115106

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


[clang] d0262c2 - [llvm] Add null-termination capability to SmallVectorMemoryBuffer

2021-12-09 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2021-12-09T11:32:13+01:00
New Revision: d0262c2394f46bb7da2a75529413d625c70908e5

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

LOG: [llvm] Add null-termination capability to SmallVectorMemoryBuffer

Most of `MemoryBuffer` interfaces expose a `RequiresNullTerminator` parameter 
that's being used to:
* determine how to open a file (`mmap` vs `open`),
* assert newly initialized buffer indeed has an implicit null terminator.

This patch adds the paramater to the `SmallVectorMemoryBuffer` constructors, 
meaning:
* null terminator can now be added to `SmallVector`s that didn't have one 
before,
* `SmallVectors` that had a null terminator before keep it even after the move.

In line with existing code, the new parameter is defaulted to `true`. This 
patch makes sure all calls to the `SmallVectorMemoryBuffer` constructor set it 
to `false` to preserve the current semantics.

Reviewed By: dexonsmith

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

Added: 


Modified: 
clang/unittests/AST/ASTImporterTest.cpp
clang/unittests/Frontend/TextDiagnosticTest.cpp
llvm/include/llvm/Support/SmallVectorMemoryBuffer.h
llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp
llvm/lib/ExecutionEngine/Orc/CompileUtils.cpp
llvm/lib/LTO/ThinLTOCodeGenerator.cpp
llvm/lib/Object/ArchiveWriter.cpp
llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp
llvm/tools/llvm-objcopy/llvm-objcopy.cpp
llvm/unittests/Support/MemoryBufferTest.cpp

Removed: 




diff  --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 83ccdb5caeaff..9e8bee9c10b3b 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -6452,8 +6452,8 @@ TEST_P(ImportSourceLocations, OverwrittenFileBuffer) {
 
 llvm::SmallVector Buffer;
 Buffer.append(Contents.begin(), Contents.end());
-auto FileContents =
-std::make_unique(std::move(Buffer), 
Path);
+auto FileContents = std::make_unique(
+std::move(Buffer), Path, /*RequiresNullTerminator=*/false);
 FromSM.overrideFileContents(&FE, std::move(FileContents));
 
 // Import the VarDecl to trigger the importing of the FileID.

diff  --git a/clang/unittests/Frontend/TextDiagnosticTest.cpp 
b/clang/unittests/Frontend/TextDiagnosticTest.cpp
index 220cff6643d50..3acd89a985ab8 100644
--- a/clang/unittests/Frontend/TextDiagnosticTest.cpp
+++ b/clang/unittests/Frontend/TextDiagnosticTest.cpp
@@ -54,7 +54,7 @@ TEST(TextDiagnostic, ShowLine) {
   llvm::SmallVector buffer;
   buffer.append(main_file_contents.begin(), main_file_contents.end());
   auto file_contents = std::make_unique(
-  std::move(buffer), file_path);
+  std::move(buffer), file_path, /*RequiresNullTerminator=*/false);
   SrcMgr.overrideFileContents(fe, std::move(file_contents));
 
   // Create the actual file id and use it as the main file.

diff  --git a/llvm/include/llvm/Support/SmallVectorMemoryBuffer.h 
b/llvm/include/llvm/Support/SmallVectorMemoryBuffer.h
index af748cf962b00..f7f2d4e54e705 100644
--- a/llvm/include/llvm/Support/SmallVectorMemoryBuffer.h
+++ b/llvm/include/llvm/Support/SmallVectorMemoryBuffer.h
@@ -28,17 +28,21 @@ namespace llvm {
 /// MemoryBuffer).
 class SmallVectorMemoryBuffer : public MemoryBuffer {
 public:
-  /// Construct an SmallVectorMemoryBuffer from the given SmallVector
-  /// r-value.
-  SmallVectorMemoryBuffer(SmallVectorImpl &&SV)
-  : SV(std::move(SV)), BufferName("") {
-init(this->SV.begin(), this->SV.end(), false);
-  }
-
-  /// Construct a named SmallVectorMemoryBuffer from the given
-  /// SmallVector r-value and StringRef.
-  SmallVectorMemoryBuffer(SmallVectorImpl &&SV, StringRef Name)
+  /// Construct a SmallVectorMemoryBuffer from the given SmallVector r-value.
+  SmallVectorMemoryBuffer(SmallVectorImpl &&SV,
+  bool RequiresNullTerminator = true)
+  : SmallVectorMemoryBuffer(std::move(SV), "",
+RequiresNullTerminator) {}
+
+  /// Construct a named SmallVectorMemoryBuffer from the given SmallVector
+  /// r-value and StringRef.
+  SmallVectorMemoryBuffer(SmallVectorImpl &&SV, StringRef Name,
+  bool RequiresNullTerminator = true)
   : SV(std::move(SV)), BufferName(std::string(Name)) {
+if (RequiresNullTerminator) {
+  this->SV.push_back('\0');
+  this->SV.pop_back();
+}
 init(this->SV.begin(), this->SV.end(), false);
   }
 

diff  --git a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp 
b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp
index 200f42aec067a..ed912280ac826 100644
--- a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp
+++ b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp
@@ -170,8 +170,8 @@ std::unique_ptr MCJIT::emitObje

[clang] 13a351e - [clang][deps] Use MemoryBuffer in minimizing FS

2021-12-09 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2021-12-09T11:32:13+01:00
New Revision: 13a351e862ba3f443b31fac57863625a5c43e43b

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

LOG: [clang][deps] Use MemoryBuffer in minimizing FS

This patch avoids unnecessarily copying contents of `mmap`-ed files into 
`CachedFileSystemEntry` by storing `MemoryBuffer` instead. The change leads to 
~50% reduction of peak memory footprint when scanning LLVM+Clang via 
`clang-scan-deps`.

Depends on D115331.

Reviewed By: dexonsmith

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

Added: 


Modified: 

clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp

Removed: 




diff  --git 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
index af02fa2e7e876..25a7d57583691 100644
--- 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
+++ 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
@@ -43,9 +43,7 @@ class CachedFileSystemEntry {
   ///
   /// The filesystem opens the file even for `stat` calls open to avoid the
   /// issues with stat + open of minimized files that might lead to a
-  /// mismatching size of the file. If file is not minimized, the full file is
-  /// read and copied into memory to ensure that it's not memory mapped to 
avoid
-  /// running out of file descriptors.
+  /// mismatching size of the file.
   static CachedFileSystemEntry createFileEntry(StringRef Filename,
llvm::vfs::FileSystem &FS,
bool Minimize = true);
@@ -65,7 +63,7 @@ class CachedFileSystemEntry {
   return MaybeStat.getError();
 assert(!MaybeStat->isDirectory() && "not a file");
 assert(isValid() && "not initialized");
-return Contents.str();
+return Contents->getBuffer();
   }
 
   /// \returns The error or the status of the entry.
@@ -94,11 +92,7 @@ class CachedFileSystemEntry {
 
 private:
   llvm::ErrorOr MaybeStat;
-  // Store the contents in a small string to allow a
-  // move from the small string for the minimized contents.
-  // Note: small size of 1 allows us to store an empty string with an implicit
-  // null terminator without any allocations.
-  llvm::SmallString<1> Contents;
+  std::unique_ptr Contents;
   PreprocessorSkippedRangeMapping PPSkippedRangeMapping;
 };
 

diff  --git 
a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp 
b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
index 8a85f5971f4b2..367989f436d37 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -9,6 +9,7 @@
 #include "clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h"
 #include "clang/Lex/DependencyDirectivesSourceMinimizer.h"
 #include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/SmallVectorMemoryBuffer.h"
 #include "llvm/Support/Threading.h"
 
 using namespace clang;
@@ -43,11 +44,7 @@ CachedFileSystemEntry CachedFileSystemEntry::createFileEntry(
 // FIXME: Propage the diagnostic if desired by the client.
 CachedFileSystemEntry Result;
 Result.MaybeStat = std::move(*Stat);
-Result.Contents.reserve(Buffer->getBufferSize() + 1);
-Result.Contents.append(Buffer->getBufferStart(), Buffer->getBufferEnd());
-// Implicitly null terminate the contents for Clang's lexer.
-Result.Contents.push_back('\0');
-Result.Contents.pop_back();
+Result.Contents = std::move(*MaybeBuffer);
 return Result;
   }
 
@@ -60,15 +57,8 @@ CachedFileSystemEntry CachedFileSystemEntry::createFileEntry(
   // The contents produced by the minimizer must be null terminated.
   assert(MinimizedFileContents.data()[MinimizedFileContents.size()] == '\0' &&
  "not null terminated contents");
-  // Even though there's an implicit null terminator in the minimized contents,
-  // we want to temporarily make it explicit. This will ensure that the
-  // std::move will preserve it even if it needs to do a copy if the
-  // SmallString still has the small capacity.
-  MinimizedFileContents.push_back('\0');
-  Result.Contents = std::move(MinimizedFileContents);
-  // Now make the null terminator implicit again, so that Clang's lexer can 
find
-  // it right where the buffer ends.
-  Result.Contents.pop_back();
+  Result.Contents = std::make_unique(
+  std::move(MinimizedFileContents));
 
   // Compute the skipped PP ranges that speedup skipping over inactive
   // preprocessor blocks.


[PATCH] D115331: [llvm] Add null-termination capability to SmallVectorMemoryBuffer

2021-12-09 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 rGd0262c2394f4: [llvm] Add null-termination capability to 
SmallVectorMemoryBuffer (authored by jansvoboda11).

Changed prior to commit:
  https://reviews.llvm.org/D115331?vs=392716&id=393080#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115331

Files:
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/Frontend/TextDiagnosticTest.cpp
  llvm/include/llvm/Support/SmallVectorMemoryBuffer.h
  llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp
  llvm/lib/ExecutionEngine/Orc/CompileUtils.cpp
  llvm/lib/LTO/ThinLTOCodeGenerator.cpp
  llvm/lib/Object/ArchiveWriter.cpp
  llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp
  llvm/tools/llvm-objcopy/llvm-objcopy.cpp
  llvm/unittests/Support/MemoryBufferTest.cpp

Index: llvm/unittests/Support/MemoryBufferTest.cpp
===
--- llvm/unittests/Support/MemoryBufferTest.cpp
+++ llvm/unittests/Support/MemoryBufferTest.cpp
@@ -11,6 +11,7 @@
 //===--===//
 
 #include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/SmallVectorMemoryBuffer.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/FileUtilities.h"
@@ -408,4 +409,27 @@
   EXPECT_EQ(MB->getBufferSize(), std::size_t(FileWrites * 8));
   EXPECT_TRUE(MB->getBuffer().startswith("01234567"));
 }
+
+// Test that SmallVector without a null terminator gets one.
+TEST(SmallVectorMemoryBufferTest, WithoutNullTerminatorRequiresNullTerminator) {
+  SmallString<0> Data("some data");
+
+  SmallVectorMemoryBuffer MB(std::move(Data),
+ /*RequiresNullTerminator=*/true);
+  EXPECT_EQ(MB.getBufferSize(), 9u);
+  EXPECT_EQ(MB.getBufferEnd()[0], '\0');
+}
+
+// Test that SmallVector with a null terminator keeps it.
+TEST(SmallVectorMemoryBufferTest, WithNullTerminatorRequiresNullTerminator) {
+  SmallString<0> Data("some data");
+  Data.push_back('\0');
+  Data.pop_back();
+
+  SmallVectorMemoryBuffer MB(std::move(Data),
+ /*RequiresNullTerminator=*/true);
+  EXPECT_EQ(MB.getBufferSize(), 9u);
+  EXPECT_EQ(MB.getBufferEnd()[0], '\0');
 }
+
+} // namespace
Index: llvm/tools/llvm-objcopy/llvm-objcopy.cpp
===
--- llvm/tools/llvm-objcopy/llvm-objcopy.cpp
+++ llvm/tools/llvm-objcopy/llvm-objcopy.cpp
@@ -236,7 +236,8 @@
   return createFileError(Ar.getFileName(), Member.takeError());
 
 Member->Buf = std::make_unique(
-std::move(Buffer), ChildNameOrErr.get());
+std::move(Buffer), ChildNameOrErr.get(),
+/*RequiresNullTerminator=*/false);
 Member->MemberName = Member->Buf->getBufferIdentifier();
 NewArchiveMembers.push_back(std::move(*Member));
   }
Index: llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp
===
--- llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp
+++ llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp
@@ -476,9 +476,8 @@
  **ObjOrErr, MemStream))
   return E;
 
-std::unique_ptr MB =
-std::make_unique(std::move(Buffer),
-  ArchFlagName);
+auto MB = std::make_unique(
+std::move(Buffer), ArchFlagName, /*RequiresNullTerminator=*/false);
 Expected> BinaryOrErr = object::createBinary(*MB);
 if (!BinaryOrErr)
   return BinaryOrErr.takeError();
Index: llvm/lib/Object/ArchiveWriter.cpp
===
--- llvm/lib/Object/ArchiveWriter.cpp
+++ llvm/lib/Object/ArchiveWriter.cpp
@@ -696,7 +696,7 @@
 return std::move(E);
 
   return std::make_unique(
-  std::move(ArchiveBufferVector));
+  std::move(ArchiveBufferVector), /*RequiresNullTerminator=*/false);
 }
 
 } // namespace llvm
Index: llvm/lib/LTO/ThinLTOCodeGenerator.cpp
===
--- llvm/lib/LTO/ThinLTOCodeGenerator.cpp
+++ llvm/lib/LTO/ThinLTOCodeGenerator.cpp
@@ -378,7 +378,8 @@
 // Run codegen now. resulting binary is in OutputBuffer.
 PM.run(TheModule);
   }
-  return std::make_unique(std::move(OutputBuffer));
+  return std::make_unique(
+  std::move(OutputBuffer), /*RequiresNullTerminator=*/false);
 }
 
 /// Manage caching for a single Module.
@@ -541,7 +542,8 @@
   auto Index = buildModuleSummaryIndex(TheModule, nullptr, &PSI);
   WriteBitcodeToFile(TheModule, OS, true, &Index);
 }
-return std::make_unique(std::move(OutputBuffer));
+return std::make_unique(
+std::move(OutputBuffer), /*RequiresNullTerminator=*/false);
   }
 
   return codegenModule(TheModule, TM);
Index: llvm/lib/Execution

[PATCH] D115043: [clang][deps] Use MemoryBuffer in minimizing FS

2021-12-09 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG13a351e862ba: [clang][deps] Use MemoryBuffer in minimizing 
FS (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115043

Files:
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
  clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp


Index: clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -9,6 +9,7 @@
 #include "clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h"
 #include "clang/Lex/DependencyDirectivesSourceMinimizer.h"
 #include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/SmallVectorMemoryBuffer.h"
 #include "llvm/Support/Threading.h"
 
 using namespace clang;
@@ -43,11 +44,7 @@
 // FIXME: Propage the diagnostic if desired by the client.
 CachedFileSystemEntry Result;
 Result.MaybeStat = std::move(*Stat);
-Result.Contents.reserve(Buffer->getBufferSize() + 1);
-Result.Contents.append(Buffer->getBufferStart(), Buffer->getBufferEnd());
-// Implicitly null terminate the contents for Clang's lexer.
-Result.Contents.push_back('\0');
-Result.Contents.pop_back();
+Result.Contents = std::move(*MaybeBuffer);
 return Result;
   }
 
@@ -60,15 +57,8 @@
   // The contents produced by the minimizer must be null terminated.
   assert(MinimizedFileContents.data()[MinimizedFileContents.size()] == '\0' &&
  "not null terminated contents");
-  // Even though there's an implicit null terminator in the minimized contents,
-  // we want to temporarily make it explicit. This will ensure that the
-  // std::move will preserve it even if it needs to do a copy if the
-  // SmallString still has the small capacity.
-  MinimizedFileContents.push_back('\0');
-  Result.Contents = std::move(MinimizedFileContents);
-  // Now make the null terminator implicit again, so that Clang's lexer can 
find
-  // it right where the buffer ends.
-  Result.Contents.pop_back();
+  Result.Contents = std::make_unique(
+  std::move(MinimizedFileContents));
 
   // Compute the skipped PP ranges that speedup skipping over inactive
   // preprocessor blocks.
Index: 
clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
===
--- 
clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
+++ 
clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
@@ -43,9 +43,7 @@
   ///
   /// The filesystem opens the file even for `stat` calls open to avoid the
   /// issues with stat + open of minimized files that might lead to a
-  /// mismatching size of the file. If file is not minimized, the full file is
-  /// read and copied into memory to ensure that it's not memory mapped to 
avoid
-  /// running out of file descriptors.
+  /// mismatching size of the file.
   static CachedFileSystemEntry createFileEntry(StringRef Filename,
llvm::vfs::FileSystem &FS,
bool Minimize = true);
@@ -65,7 +63,7 @@
   return MaybeStat.getError();
 assert(!MaybeStat->isDirectory() && "not a file");
 assert(isValid() && "not initialized");
-return Contents.str();
+return Contents->getBuffer();
   }
 
   /// \returns The error or the status of the entry.
@@ -94,11 +92,7 @@
 
 private:
   llvm::ErrorOr MaybeStat;
-  // Store the contents in a small string to allow a
-  // move from the small string for the minimized contents.
-  // Note: small size of 1 allows us to store an empty string with an implicit
-  // null terminator without any allocations.
-  llvm::SmallString<1> Contents;
+  std::unique_ptr Contents;
   PreprocessorSkippedRangeMapping PPSkippedRangeMapping;
 };
 


Index: clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -9,6 +9,7 @@
 #include "clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h"
 #include "clang/Lex/DependencyDirectivesSourceMinimizer.h"
 #include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/SmallVectorMemoryBuffer.h"
 #include "llvm/Support/Threading.h"
 
 using namespace clang;
@@ -43,11 +44,7 @@
 // FIXME: Propage the diagnostic if desired by the client.
 CachedFileSystemEntry Result;
 Result.MaybeStat = std::move(*Stat);
-Result.Contents.reserve(Buffer->getBufferSize() + 1);
-Result.Con

[PATCH] D115050: [clang-format] PR48916 PointerAlignment not working when using C++20 init-statement in for loop

2021-12-09 Thread MyDeveloperDay via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2a73a1ac57f0: [clang-format] PR48916 PointerAlignment not 
working when using C++20 init… (authored by MyDeveloperDay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115050

Files:
  clang/lib/Format/FormatToken.cpp
  clang/lib/Format/FormatToken.h
  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
@@ -1924,6 +1924,22 @@
   verifyFormat("int *a = f1();", Style);
   verifyFormat("int &b = f2();", Style);
   verifyFormat("int &&c = f3();", Style);
+  verifyFormat("for (auto a = 0, b = 0; const auto &c : {1, 2, 3})", Style);
+  verifyFormat("for (auto a = 0, b = 0; const int &c : {1, 2, 3})", Style);
+  verifyFormat("for (auto a = 0, b = 0; const Foo &c : {1, 2, 3})", Style);
+  verifyFormat("for (auto a = 0, b = 0; const Foo *c : {1, 2, 3})", Style);
+  verifyFormat("for (int a = 0, b = 0; const auto &c : {1, 2, 3})", Style);
+  verifyFormat("for (int a = 0, b = 0; const int &c : {1, 2, 3})", Style);
+  verifyFormat("for (int a = 0, b = 0; const Foo &c : {1, 2, 3})", Style);
+  verifyFormat("for (int a = 0, b++; const auto &c : {1, 2, 3})", Style);
+  verifyFormat("for (int a = 0, b++; const int &c : {1, 2, 3})", Style);
+  verifyFormat("for (int a = 0, b++; const Foo &c : {1, 2, 3})", Style);
+  verifyFormat("for (auto x = 0; auto &c : {1, 2, 3})", Style);
+  verifyFormat("for (auto x = 0; int &c : {1, 2, 3})", Style);
+  verifyFormat("for (int x = 0; auto &c : {1, 2, 3})", Style);
+  verifyFormat("for (int x = 0; int &c : {1, 2, 3})", Style);
+  verifyFormat("for (f(); auto &c : {1, 2, 3})", Style);
+  verifyFormat("for (f(); int &c : {1, 2, 3})", Style);
 
   Style.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive;
   verifyFormat("Const unsigned int *c;\n"
@@ -1943,6 +1959,24 @@
   verifyFormat("int* a = f1();", Style);
   verifyFormat("int& b = f2();", Style);
   verifyFormat("int&& c = f3();", Style);
+  verifyFormat("for (auto a = 0, b = 0; const auto& c : {1, 2, 3})", Style);
+  verifyFormat("for (auto a = 0, b = 0; const int& c : {1, 2, 3})", Style);
+  verifyFormat("for (auto a = 0, b = 0; const Foo& c : {1, 2, 3})", Style);
+  verifyFormat("for (auto a = 0, b = 0; const Foo* c : {1, 2, 3})", Style);
+  verifyFormat("for (int a = 0, b = 0; const auto& c : {1, 2, 3})", Style);
+  verifyFormat("for (int a = 0, b = 0; const int& c : {1, 2, 3})", Style);
+  verifyFormat("for (int a = 0, b = 0; const Foo& c : {1, 2, 3})", Style);
+  verifyFormat("for (int a = 0, b = 0; const Foo* c : {1, 2, 3})", Style);
+  verifyFormat("for (int a = 0, b++; const auto& c : {1, 2, 3})", Style);
+  verifyFormat("for (int a = 0, b++; const int& c : {1, 2, 3})", Style);
+  verifyFormat("for (int a = 0, b++; const Foo& c : {1, 2, 3})", Style);
+  verifyFormat("for (int a = 0, b++; const Foo* c : {1, 2, 3})", Style);
+  verifyFormat("for (auto x = 0; auto& c : {1, 2, 3})", Style);
+  verifyFormat("for (auto x = 0; int& c : {1, 2, 3})", Style);
+  verifyFormat("for (int x = 0; auto& c : {1, 2, 3})", Style);
+  verifyFormat("for (int x = 0; int& c : {1, 2, 3})", Style);
+  verifyFormat("for (f(); auto& c : {1, 2, 3})", Style);
+  verifyFormat("for (f(); int& c : {1, 2, 3})", Style);
 
   Style.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive;
   verifyFormat("Const unsigned int* c;\n"
@@ -1961,6 +1995,9 @@
   verifyFormat("int *a = f1();", Style);
   verifyFormat("int& b = f2();", Style);
   verifyFormat("int&& c = f3();", Style);
+  verifyFormat("for (auto a = 0, b = 0; const Foo *c : {1, 2, 3})", Style);
+  verifyFormat("for (int a = 0, b = 0; const Foo *c : {1, 2, 3})", Style);
+  verifyFormat("for (int a = 0, b++; const Foo *c : {1, 2, 3})", Style);
 
   Style.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive;
   verifyFormat("Const unsigned int *c;\n"
@@ -1979,6 +2016,20 @@
   verifyFormat("int* a = f1();", Style);
   verifyFormat("int & b = f2();", Style);
   verifyFormat("int && c = f3();", Style);
+  verifyFormat("for (auto a = 0, b = 0; const auto & c : {1, 2, 3})", Style);
+  verifyFormat("for (auto a = 0, b = 0; const int & c : {1, 2, 3})", Style);
+  verifyFormat("for (auto a = 0, b = 0; const Foo & c : {1, 2, 3})", Style);
+  verifyFormat("for (auto a = 0, b = 0; const Foo* c : {1, 2, 3})", Style);
+  verifyFormat("for (int a = 0, b++; const auto & c : {1, 2, 3})", Style);
+  verifyFormat("for (int a = 0, b++; const int & c : {1, 2, 3})", Style);
+  verifyFormat("for (int a = 0, b++; const Foo & c : {1, 2, 3})", Style);
+  verifyFormat("for (int a = 0, b++; const Foo* c : {1, 2, 3})", Style);
+  verifyFormat("for (auto x = 0; auto & c : {1, 2, 3})", Style);
+  verifyFormat("for (auto x 

[clang] 2a73a1a - [clang-format] PR48916 PointerAlignment not working when using C++20 init-statement in for loop

2021-12-09 Thread via cfe-commits

Author: mydeveloperday
Date: 2021-12-09T10:37:02Z
New Revision: 2a73a1ac57f0b7f95d3e75ef8f3dafb174ef5ccc

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

LOG: [clang-format] PR48916 PointerAlignment not working when using C++20 
init-statement in for loop

https://bugs.llvm.org/show_bug.cgi?id=48916

Left and Right Alignment inside a loop is misaligned.

Reviewed By: HazardyKnusperkeks, curdeius

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

Added: 


Modified: 
clang/lib/Format/FormatToken.cpp
clang/lib/Format/FormatToken.h
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/FormatToken.cpp 
b/clang/lib/Format/FormatToken.cpp
index 6768f041135c7..57f8a5a45cbb0 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -70,6 +70,10 @@ bool FormatToken::isSimpleTypeSpecifier() const {
   }
 }
 
+bool FormatToken::isTypeOrIdentifier() const {
+  return isSimpleTypeSpecifier() || Tok.isOneOf(tok::kw_auto, tok::identifier);
+}
+
 TokenRole::~TokenRole() {}
 
 void TokenRole::precomputeFormattingInfos(const FormatToken *Token) {}

diff  --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 1a2858018fde5..d410ede32240d 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -521,7 +521,9 @@ struct FormatToken {
   }
 
   /// Determine whether the token is a simple-type-specifier.
-  bool isSimpleTypeSpecifier() const;
+  LLVM_NODISCARD bool isSimpleTypeSpecifier() const;
+
+  LLVM_NODISCARD bool isTypeOrIdentifier() const;
 
   bool isObjCAccessSpecifier() const {
 return is(tok::at) && Next &&

diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 6b7f135e32136..c0d030379ff0a 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3021,8 +3021,14 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine &Line,
  Style.SpaceAroundPointerQualifiers == FormatStyle::SAPQ_Both) &&
 (Left.is(TT_AttributeParen) || 
Left.canBePointerOrReferenceQualifier()))
   return true;
+if (Left.Tok.isLiteral())
+  return true;
+// for (auto a = 0, b = 0; const auto & c : {1, 2, 3})
+if (Left.isTypeOrIdentifier() && Right.Next && Right.Next->Next &&
+Right.Next->Next->is(TT_RangeBasedForLoopColon))
+  return getTokenPointerOrReferenceAlignment(Right) !=
+ FormatStyle::PAS_Left;
 return (
-Left.Tok.isLiteral() ||
 (!Left.isOneOf(TT_PointerOrReference, tok::l_paren) &&
  (getTokenPointerOrReferenceAlignment(Right) != FormatStyle::PAS_Left 
||
   (Line.IsMultiVariableDeclStmt &&
@@ -3041,18 +3047,32 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine &Line,
  Style.SpaceAroundPointerQualifiers == FormatStyle::SAPQ_Both) &&
 Right.canBePointerOrReferenceQualifier())
   return true;
-return Right.Tok.isLiteral() || Right.is(TT_BlockComment) ||
-   (Right.isOneOf(Keywords.kw_override, Keywords.kw_final) &&
-!Right.is(TT_StartOfName)) ||
-   (Right.is(tok::l_brace) && Right.is(BK_Block)) ||
-   (!Right.isOneOf(TT_PointerOrReference, TT_ArraySubscriptLSquare,
-   tok::l_paren) &&
-(getTokenPointerOrReferenceAlignment(Left) !=
- FormatStyle::PAS_Right &&
- !Line.IsMultiVariableDeclStmt) &&
-Left.Previous &&
-!Left.Previous->isOneOf(tok::l_paren, tok::coloncolon,
-tok::l_square));
+// & 1
+if (Right.Tok.isLiteral())
+  return true;
+// & /* comment
+if (Right.is(TT_BlockComment))
+  return true;
+// foo() -> const Bar * override/final
+if (Right.isOneOf(Keywords.kw_override, Keywords.kw_final) &&
+!Right.is(TT_StartOfName))
+  return true;
+// & {
+if (Right.is(tok::l_brace) && Right.is(BK_Block))
+  return true;
+// for (auto a = 0, b = 0; const auto& c : {1, 2, 3})
+if (Left.Previous && Left.Previous->isTypeOrIdentifier() && Right.Next &&
+Right.Next->is(TT_RangeBasedForLoopColon))
+  return getTokenPointerOrReferenceAlignment(Left) !=
+ FormatStyle::PAS_Right;
+return !Right.isOneOf(TT_PointerOrReference, TT_ArraySubscriptLSquare,
+  tok::l_paren) &&
+   (getTokenPointerOrReferenceAlignment(Left) !=
+FormatStyle::PAS_Right &&
+!Line.IsMultiVariableDeclStmt) &&
+   Left.Previous &&
+   !Left.Previous->isOneOf(tok::l_paren, tok::coloncolon,
+   tok::l_square);
   }
  

[clang] e32b818 - [ARM][clang] Define feature test macro for the PACBTI-M extension

2021-12-09 Thread Ties Stuij via cfe-commits

Author: Ties Stuij
Date: 2021-12-09T10:39:06Z
New Revision: e32b818db187a6519ee5eba47e8d7dae1d58a723

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

LOG: [ARM][clang] Define feature test macro for the PACBTI-M extension

If the extension string "+pacbti" was given in -march=... or -mcpu=... options 
the compiler shall define the following preprocessor macros:

__ARM_FEATURE_PAUTH with value 1.
__ARM_FEATURE_BTI with value 1.

This patch is part of a series that adds support for the PACBTI-M extension of
the Armv8.1-M architecture, as detailed here:

https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/armv8-1-m-pointer-authentication-and-branch-target-identification-extension

The PACBTI-M specification can be found in the Armv8-M Architecture Reference
Manual:

https://developer.arm.com/documentation/ddi0553/latest

The following people contributed to this patch:

- Momchil Velikov
- Ties Stuij

Reviewed By: miyuki

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

Added: 


Modified: 
clang/lib/Basic/Targets/ARM.cpp
clang/lib/Basic/Targets/ARM.h
clang/test/Preprocessor/arm-target-features.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp
index f330780300f29..81b79cfe19e47 100644
--- a/clang/lib/Basic/Targets/ARM.cpp
+++ b/clang/lib/Basic/Targets/ARM.cpp
@@ -465,6 +465,8 @@ bool 
ARMTargetInfo::handleTargetFeatures(std::vector &Features,
   HWDiv = 0;
   DotProd = 0;
   HasMatMul = 0;
+  HasPAC = 0;
+  HasBTI = 0;
   HasFloat16 = true;
   ARMCDECoprocMask = 0;
   HasBFloat16 = false;
@@ -547,6 +549,9 @@ bool 
ARMTargetInfo::handleTargetFeatures(std::vector &Features,
   HasBFloat16 = true;
 } else if (Feature == "-fpregs") {
   FPRegsDisabled = true;
+} else if (Feature == "+pacbti") {
+  HasPAC = 1;
+  HasBTI = 1;
 }
   }
 
@@ -890,6 +895,12 @@ void ARMTargetInfo::getTargetDefines(const LangOptions 
&Opts,
   if (HasMatMul)
 Builder.defineMacro("__ARM_FEATURE_MATMUL_INT8", "1");
 
+  if (HasPAC)
+Builder.defineMacro("__ARM_FEATURE_PAUTH", "1");
+
+  if (HasBTI)
+Builder.defineMacro("__ARM_FEATURE_BTI", "1");
+
   if (HasBFloat16) {
 Builder.defineMacro("__ARM_FEATURE_BF16", "1");
 Builder.defineMacro("__ARM_FEATURE_BF16_VECTOR_ARITHMETIC", "1");

diff  --git a/clang/lib/Basic/Targets/ARM.h b/clang/lib/Basic/Targets/ARM.h
index f939904f8d8c5..40c658f3f40e2 100644
--- a/clang/lib/Basic/Targets/ARM.h
+++ b/clang/lib/Basic/Targets/ARM.h
@@ -79,6 +79,8 @@ class LLVM_LIBRARY_VISIBILITY ARMTargetInfo : public 
TargetInfo {
   unsigned DotProd : 1;
   unsigned HasMatMul : 1;
   unsigned FPRegsDisabled : 1;
+  unsigned HasPAC : 1;
+  unsigned HasBTI : 1;
 
   enum {
 LDREX_B = (1 << 0), /// byte (8-bit)

diff  --git a/clang/test/Preprocessor/arm-target-features.c 
b/clang/test/Preprocessor/arm-target-features.c
index 7fb3323cd4092..49a5516e15d0d 100644
--- a/clang/test/Preprocessor/arm-target-features.c
+++ b/clang/test/Preprocessor/arm-target-features.c
@@ -896,6 +896,13 @@
 // CHECK-PAC-LEAF: #define __ARM_FEATURE_PAC_DEFAULT 5
 // CHECK-PAC-BKEY-LEAF: #define __ARM_FEATURE_PAC_DEFAULT 6
 
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -x c -E -dM %s 
-o - | FileCheck --check-prefixes=CHECK-NOBTI-EXT,CHECK-NOPAC-EXT %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv7-m+pacbti -x c -E -dM %s 
-o - | FileCheck --check-prefixes=CHECK-PACBTI-EXT %s
+// CHECK-NOBTI-EXT-NOT: #define __ARM_FEATURE_BTI 1
+// CHECK-NOPAC-EXT-NOT: #define __ARM_FEATURE_PAUTH 1
+// CHECK-PACBTI-EXT: #define __ARM_FEATURE_BTI 1
+// CHECK-PACBTI-EXT: #define __ARM_FEATURE_PAUTH 1
+
 // == Check BFloat16 Extensions.
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.6-a+bf16 -x c -E -dM %s 
-o - 2>&1 | FileCheck -check-prefix=CHECK-BFLOAT %s
 // CHECK-BFLOAT: #define __ARM_BF16_FORMAT_ALTERNATIVE 1



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


[PATCH] D112431: [ARM][clang] Define feature test macro for the PACBTI-M extension

2021-12-09 Thread Ties Stuij via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe32b818db187: [ARM][clang] Define feature test macro for the 
PACBTI-M extension (authored by stuij).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112431

Files:
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/ARM.h
  clang/test/Preprocessor/arm-target-features.c


Index: clang/test/Preprocessor/arm-target-features.c
===
--- clang/test/Preprocessor/arm-target-features.c
+++ clang/test/Preprocessor/arm-target-features.c
@@ -896,6 +896,13 @@
 // CHECK-PAC-LEAF: #define __ARM_FEATURE_PAC_DEFAULT 5
 // CHECK-PAC-BKEY-LEAF: #define __ARM_FEATURE_PAC_DEFAULT 6
 
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -x c -E -dM %s 
-o - | FileCheck --check-prefixes=CHECK-NOBTI-EXT,CHECK-NOPAC-EXT %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv7-m+pacbti -x c -E -dM %s 
-o - | FileCheck --check-prefixes=CHECK-PACBTI-EXT %s
+// CHECK-NOBTI-EXT-NOT: #define __ARM_FEATURE_BTI 1
+// CHECK-NOPAC-EXT-NOT: #define __ARM_FEATURE_PAUTH 1
+// CHECK-PACBTI-EXT: #define __ARM_FEATURE_BTI 1
+// CHECK-PACBTI-EXT: #define __ARM_FEATURE_PAUTH 1
+
 // == Check BFloat16 Extensions.
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.6-a+bf16 -x c -E -dM %s 
-o - 2>&1 | FileCheck -check-prefix=CHECK-BFLOAT %s
 // CHECK-BFLOAT: #define __ARM_BF16_FORMAT_ALTERNATIVE 1
Index: clang/lib/Basic/Targets/ARM.h
===
--- clang/lib/Basic/Targets/ARM.h
+++ clang/lib/Basic/Targets/ARM.h
@@ -79,6 +79,8 @@
   unsigned DotProd : 1;
   unsigned HasMatMul : 1;
   unsigned FPRegsDisabled : 1;
+  unsigned HasPAC : 1;
+  unsigned HasBTI : 1;
 
   enum {
 LDREX_B = (1 << 0), /// byte (8-bit)
Index: clang/lib/Basic/Targets/ARM.cpp
===
--- clang/lib/Basic/Targets/ARM.cpp
+++ clang/lib/Basic/Targets/ARM.cpp
@@ -465,6 +465,8 @@
   HWDiv = 0;
   DotProd = 0;
   HasMatMul = 0;
+  HasPAC = 0;
+  HasBTI = 0;
   HasFloat16 = true;
   ARMCDECoprocMask = 0;
   HasBFloat16 = false;
@@ -547,6 +549,9 @@
   HasBFloat16 = true;
 } else if (Feature == "-fpregs") {
   FPRegsDisabled = true;
+} else if (Feature == "+pacbti") {
+  HasPAC = 1;
+  HasBTI = 1;
 }
   }
 
@@ -890,6 +895,12 @@
   if (HasMatMul)
 Builder.defineMacro("__ARM_FEATURE_MATMUL_INT8", "1");
 
+  if (HasPAC)
+Builder.defineMacro("__ARM_FEATURE_PAUTH", "1");
+
+  if (HasBTI)
+Builder.defineMacro("__ARM_FEATURE_BTI", "1");
+
   if (HasBFloat16) {
 Builder.defineMacro("__ARM_FEATURE_BF16", "1");
 Builder.defineMacro("__ARM_FEATURE_BF16_VECTOR_ARITHMETIC", "1");


Index: clang/test/Preprocessor/arm-target-features.c
===
--- clang/test/Preprocessor/arm-target-features.c
+++ clang/test/Preprocessor/arm-target-features.c
@@ -896,6 +896,13 @@
 // CHECK-PAC-LEAF: #define __ARM_FEATURE_PAC_DEFAULT 5
 // CHECK-PAC-BKEY-LEAF: #define __ARM_FEATURE_PAC_DEFAULT 6
 
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -x c -E -dM %s -o - | FileCheck --check-prefixes=CHECK-NOBTI-EXT,CHECK-NOPAC-EXT %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv7-m+pacbti -x c -E -dM %s -o - | FileCheck --check-prefixes=CHECK-PACBTI-EXT %s
+// CHECK-NOBTI-EXT-NOT: #define __ARM_FEATURE_BTI 1
+// CHECK-NOPAC-EXT-NOT: #define __ARM_FEATURE_PAUTH 1
+// CHECK-PACBTI-EXT: #define __ARM_FEATURE_BTI 1
+// CHECK-PACBTI-EXT: #define __ARM_FEATURE_PAUTH 1
+
 // == Check BFloat16 Extensions.
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.6-a+bf16 -x c -E -dM %s -o - 2>&1 | FileCheck -check-prefix=CHECK-BFLOAT %s
 // CHECK-BFLOAT: #define __ARM_BF16_FORMAT_ALTERNATIVE 1
Index: clang/lib/Basic/Targets/ARM.h
===
--- clang/lib/Basic/Targets/ARM.h
+++ clang/lib/Basic/Targets/ARM.h
@@ -79,6 +79,8 @@
   unsigned DotProd : 1;
   unsigned HasMatMul : 1;
   unsigned FPRegsDisabled : 1;
+  unsigned HasPAC : 1;
+  unsigned HasBTI : 1;
 
   enum {
 LDREX_B = (1 << 0), /// byte (8-bit)
Index: clang/lib/Basic/Targets/ARM.cpp
===
--- clang/lib/Basic/Targets/ARM.cpp
+++ clang/lib/Basic/Targets/ARM.cpp
@@ -465,6 +465,8 @@
   HWDiv = 0;
   DotProd = 0;
   HasMatMul = 0;
+  HasPAC = 0;
+  HasBTI = 0;
   HasFloat16 = true;
   ARMCDECoprocMask = 0;
   HasBFloat16 = false;
@@ -547,6 +549,9 @@
   HasBFloat16 = true;
 } else if (Feature == "-fpregs") {
   FPRegsDisabled = true;
+} else if (Feature == "+pacbti") {
+  HasPAC = 1;
+  HasBTI = 1;
 }
   }
 
@@ -890,6 +895,12 @@
   if (HasMatMul)
 Builder.defineMacro("__ARM_FEATURE_MATMUL_INT8", "

[PATCH] D115438: [lldb] Remove unused lldb.cpp

2021-12-09 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: labath.
hokein requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

lldb.cpp is unused after 
https://github.com/llvm/llvm-project/commit/ccf1469a4cdb03cb2bc7868f76164e85d90ebee1


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115438

Files:
  lldb/source/lldb.cpp


Index: lldb/source/lldb.cpp
===
--- lldb/source/lldb.cpp
+++ /dev/null
@@ -1,77 +0,0 @@
-//===-- lldb.cpp 
--===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#include "VCSVersion.inc"
-#include "lldb/lldb-private.h"
-#include "clang/Basic/Version.h"
-
-using namespace lldb;
-using namespace lldb_private;
-
-// LLDB_VERSION_STRING is set through a define so unlike the other defines
-// expanded with CMake, it lacks the double quotes.
-#define QUOTE(str) #str
-#define EXPAND_AND_QUOTE(str) QUOTE(str)
-
-static const char *GetLLDBVersion() {
-#ifdef LLDB_VERSION_STRING
-  return EXPAND_AND_QUOTE(LLDB_VERSION_STRING);
-#else
-  return "lldb version " CLANG_VERSION_STRING;
-#endif
-}
-
-static const char *GetLLDBRevision() {
-#ifdef LLDB_REVISION
-  return LLDB_REVISION;
-#else
-  return NULL;
-#endif
-}
-
-static const char *GetLLDBRepository() {
-#ifdef LLDB_REPOSITORY
-  return LLDB_REPOSITORY;
-#else
-  return NULL;
-#endif
-}
-
-const char *lldb_private::GetVersion() {
-  static std::string g_version_str;
-  if (g_version_str.empty()) {
-const char *lldb_version = GetLLDBVersion();
-const char *lldb_repo = GetLLDBRepository();
-const char *lldb_rev = GetLLDBRevision();
-g_version_str += lldb_version;
-if (lldb_repo || lldb_rev) {
-  g_version_str += " (";
-  if (lldb_repo)
-g_version_str += lldb_repo;
-  if (lldb_repo && lldb_rev)
-g_version_str += " ";
-  if (lldb_rev) {
-g_version_str += "revision ";
-g_version_str += lldb_rev;
-  }
-  g_version_str += ")";
-}
-
-std::string clang_rev(clang::getClangRevision());
-if (clang_rev.length() > 0) {
-  g_version_str += "\n  clang revision ";
-  g_version_str += clang_rev;
-}
-std::string llvm_rev(clang::getLLVMRevision());
-if (llvm_rev.length() > 0) {
-  g_version_str += "\n  llvm revision ";
-  g_version_str += llvm_rev;
-}
-  }
-  return g_version_str.c_str();
-}


Index: lldb/source/lldb.cpp
===
--- lldb/source/lldb.cpp
+++ /dev/null
@@ -1,77 +0,0 @@
-//===-- lldb.cpp --===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#include "VCSVersion.inc"
-#include "lldb/lldb-private.h"
-#include "clang/Basic/Version.h"
-
-using namespace lldb;
-using namespace lldb_private;
-
-// LLDB_VERSION_STRING is set through a define so unlike the other defines
-// expanded with CMake, it lacks the double quotes.
-#define QUOTE(str) #str
-#define EXPAND_AND_QUOTE(str) QUOTE(str)
-
-static const char *GetLLDBVersion() {
-#ifdef LLDB_VERSION_STRING
-  return EXPAND_AND_QUOTE(LLDB_VERSION_STRING);
-#else
-  return "lldb version " CLANG_VERSION_STRING;
-#endif
-}
-
-static const char *GetLLDBRevision() {
-#ifdef LLDB_REVISION
-  return LLDB_REVISION;
-#else
-  return NULL;
-#endif
-}
-
-static const char *GetLLDBRepository() {
-#ifdef LLDB_REPOSITORY
-  return LLDB_REPOSITORY;
-#else
-  return NULL;
-#endif
-}
-
-const char *lldb_private::GetVersion() {
-  static std::string g_version_str;
-  if (g_version_str.empty()) {
-const char *lldb_version = GetLLDBVersion();
-const char *lldb_repo = GetLLDBRepository();
-const char *lldb_rev = GetLLDBRevision();
-g_version_str += lldb_version;
-if (lldb_repo || lldb_rev) {
-  g_version_str += " (";
-  if (lldb_repo)
-g_version_str += lldb_repo;
-  if (lldb_repo && lldb_rev)
-g_version_str += " ";
-  if (lldb_rev) {
-g_version_str += "revision ";
-g_version_str += lldb_rev;
-  }
-  g_version_str += ")";
-}
-
-std::string clang_rev(clang::getClangRevision());
-if (clang_rev.length() > 0) {
-  g_version_str += "\n  clang revision ";
-  g_version_str += clang_rev;
-}
-std::string llvm_rev(clang::getLLVMRevision());
-if (llvm_rev.length() > 0) {
-  g_version_str += "\n  llvm revision ";
-  g_v

[PATCH] D115225: [X86][MS-InlineAsm] Make the constraint *m to be simple place holder

2021-12-09 Thread Kan Shengchen via Phabricator via cfe-commits
skan added inline comments.



Comment at: clang/test/CodeGen/ms-inline-asm-functions.c:42
   __asm mov eax, k;
-  // CHECK: movl_k, %eax
+  // CHECK: movlk, %eax
   __asm mov eax, kptr;

This change is strange here. Others looks good to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115225

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


[PATCH] D115140: [ARM][clang] Option b-key must not affect __ARM_FEATURE_PAC_DEFAULT

2021-12-09 Thread Ties Stuij via Phabricator via cfe-commits
stuij updated this revision to Diff 393096.
stuij added a comment.

rebasing


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115140

Files:
  clang/lib/Basic/Targets/ARM.cpp
  clang/test/Preprocessor/arm-target-features.c


Index: clang/test/Preprocessor/arm-target-features.c
===
--- clang/test/Preprocessor/arm-target-features.c
+++ clang/test/Preprocessor/arm-target-features.c
@@ -881,20 +881,18 @@
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -x c -E -dM %s 
-o - | FileCheck --check-prefixes=CHECK-NOBTI,CHECK-NOPAC %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=bti -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-BTI,CHECK-NOPAC %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=pac-ret -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC,CHECK-NOBTI %s
-// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=pac-ret+b-key -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC-BKEY,CHECK-NOBTI %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=pac-ret+b-key -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC,CHECK-NOBTI %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=pac-ret+leaf -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC-LEAF,CHECK-NOBTI %s
-// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=pac-ret+b-key+leaf -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC-BKEY-LEAF,CHECK-NOBTI %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=pac-ret+b-key+leaf -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC-LEAF,CHECK-NOBTI %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=bti+pac-ret -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC,CHECK-BTI %s
-// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=bti+pac-ret+b-key -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC-BKEY,CHECK-BTI %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=bti+pac-ret+b-key -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC,CHECK-BTI %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=bti+pac-ret+leaf -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC-LEAF,CHECK-BTI %s
-// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=bti+pac-ret+b-key+leaf -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC-BKEY-LEAF,CHECK-BTI %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=bti+pac-ret+b-key+leaf -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC-LEAF,CHECK-BTI %s
 // CHECK-NOBTI-NOT: #define __ARM_FEATURE_BTI_DEFAULT
 // CHECK-NOPAC-NOT: #define __ARM_FEATURE_PAC_DEFAULT
 // CHECK-BTI: #define __ARM_FEATURE_BTI_DEFAULT 1
 // CHECK-PAC: #define __ARM_FEATURE_PAC_DEFAULT 1
-// CHECK-PAC-BKEY: #define __ARM_FEATURE_PAC_DEFAULT 2
 // CHECK-PAC-LEAF: #define __ARM_FEATURE_PAC_DEFAULT 5
-// CHECK-PAC-BKEY-LEAF: #define __ARM_FEATURE_PAC_DEFAULT 6
 
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -x c -E -dM %s 
-o - | FileCheck --check-prefixes=CHECK-NOBTI-EXT,CHECK-NOPAC-EXT %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv7-m+pacbti -x c -E -dM %s 
-o - | FileCheck --check-prefixes=CHECK-PACBTI-EXT %s
Index: clang/lib/Basic/Targets/ARM.cpp
===
--- clang/lib/Basic/Targets/ARM.cpp
+++ clang/lib/Basic/Targets/ARM.cpp
@@ -911,7 +911,7 @@
 Builder.defineMacro("__ARM_FEATURE_BTI_DEFAULT", "1");
 
   if (Opts.hasSignReturnAddress()) {
-unsigned Value = Opts.isSignReturnAddressWithAKey() ? 1 : 2;
+unsigned Value = 1;
 if (Opts.isSignReturnAddressScopeAll())
   Value |= 1 << 2;
 Builder.defineMacro("__ARM_FEATURE_PAC_DEFAULT", Twine(Value));


Index: clang/test/Preprocessor/arm-target-features.c
===
--- clang/test/Preprocessor/arm-target-features.c
+++ clang/test/Preprocessor/arm-target-features.c
@@ -881,20 +881,18 @@
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -x c -E -dM %s -o - | FileCheck --check-prefixes=CHECK-NOBTI,CHECK-NOPAC %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -mbranch-protection=bti -x c -E -dM %s -o - | FileCheck --check-prefixes=CHECK-BTI,CHECK-NOPAC %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -mbranch-protection=pac-ret -x c -E -dM %s -o - | FileCheck --check-prefixes=CHECK-PAC,CHECK-NOBTI %s
-// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -mbranch-p

[PATCH] D107450: [clang-tidy] Fix wrong FixIt in performance-move-const-arg

2021-12-09 Thread gehry via Phabricator via cfe-commits
Sockke added a comment.

Kindly ping. @aaron.ballman


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

https://reviews.llvm.org/D107450

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


[PATCH] D113545: [C++20] [Module] Support reachable definition initially/partially

2021-12-09 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu planned changes to this revision.
ChuanqiXu added a comment.

I think it would be better to resent this when it is more complete.


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

https://reviews.llvm.org/D113545

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


[PATCH] D115225: [X86][MS-InlineAsm] Make the constraint *m to be simple place holder

2021-12-09 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added inline comments.



Comment at: clang/test/CodeGen/ms-inline-asm-functions.c:42
   __asm mov eax, k;
-  // CHECK: movl_k, %eax
+  // CHECK: movlk, %eax
   __asm mov eax, kptr;

skan wrote:
> This change is strange here. Others looks good to me.
Yeah, but we can't roll back all the constraint added D113096 unless we add a 
separate flag to record it.
In fact, using the symbol won't result in any functionality issue. And in this 
case, I checked the built binary is the same as the one before this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115225

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


[clang-tools-extra] 5321900 - [clang][clangd] Desugar array type.

2021-12-09 Thread via cfe-commits

Author: lh123
Date: 2021-12-09T20:12:48+08:00
New Revision: 53219009aaebd2c26028c1df05550183a94c489c

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

LOG: [clang][clangd] Desugar array type.

Desugar array type.

Reviewed By: sammccall

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

Added: 


Modified: 
clang-tools-extra/clangd/unittests/HoverTests.cpp
clang/lib/AST/ASTDiagnostic.cpp
clang/test/Misc/diag-aka-types.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp 
b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 7ec69d5d00ac7..740c907d7e4e4 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -914,7 +914,7 @@ class Foo {})cpp";
[](HoverInfo &HI) {
  HI.Name = "arr";
  HI.Kind = index::SymbolKind::Variable;
- HI.Type = "m_int[Size]";
+ HI.Type = {"m_int[Size]", "int[Size]"};
  HI.NamespaceScope = "";
  HI.Definition = "template  m_int arr[Size]";
  HI.TemplateParameters = {{{"int"}, {"Size"}, llvm::None}};
@@ -930,7 +930,7 @@ class Foo {})cpp";
[](HoverInfo &HI) {
  HI.Name = "arr<4>";
  HI.Kind = index::SymbolKind::Variable;
- HI.Type = "m_int[4]";
+ HI.Type = {"m_int[4]", "int[4]"};
  HI.NamespaceScope = "";
  HI.Definition = "m_int arr[4]";
}},
@@ -998,6 +998,52 @@ class Foo {})cpp";
  HI.Definition = "template  using AA = A";
  HI.Type = {"A", "type-parameter-0-0"}; // FIXME: should be 'T'
  HI.TemplateParameters = {{{"typename"}, std::string("T"), 
llvm::None}};
+   }},
+  {// Constant array
+   R"cpp(
+  using m_int = int;
+
+  m_int ^[[arr]][10];
+ )cpp",
+   [](HoverInfo &HI) {
+ HI.Name = "arr";
+ HI.NamespaceScope = "";
+ HI.LocalScope = "";
+ HI.Kind = index::SymbolKind::Variable;
+ HI.Definition = "m_int arr[10]";
+ HI.Type = {"m_int[10]", "int[10]"};
+   }},
+  {// Incomplete array
+   R"cpp(
+  using m_int = int;
+
+  extern m_int ^[[arr]][];
+ )cpp",
+   [](HoverInfo &HI) {
+ HI.Name = "arr";
+ HI.NamespaceScope = "";
+ HI.LocalScope = "";
+ HI.Kind = index::SymbolKind::Variable;
+ HI.Definition = "extern m_int arr[]";
+ HI.Type = {"m_int[]", "int[]"};
+   }},
+  {// Dependent size array
+   R"cpp(
+  using m_int = int;
+
+  template
+  struct Test {
+m_int ^[[arr]][Size];
+  };
+ )cpp",
+   [](HoverInfo &HI) {
+ HI.Name = "arr";
+ HI.NamespaceScope = "";
+ HI.LocalScope = "Test::";
+ HI.AccessSpecifier = "public";
+ HI.Kind = index::SymbolKind::Field;
+ HI.Definition = "m_int arr[Size]";
+ HI.Type = {"m_int[Size]", "int[Size]"};
}}};
   for (const auto &Case : Cases) {
 SCOPED_TRACE(Case.Code);

diff  --git a/clang/lib/AST/ASTDiagnostic.cpp b/clang/lib/AST/ASTDiagnostic.cpp
index e1b517db28ac9..4865f3f706b3f 100644
--- a/clang/lib/AST/ASTDiagnostic.cpp
+++ b/clang/lib/AST/ASTDiagnostic.cpp
@@ -131,6 +131,29 @@ QualType clang::desugarForDiagnostic(ASTContext &Context, 
QualType QT,
   }
 }
 
+if (const auto *AT = dyn_cast(Ty)) {
+  QualType ElementTy =
+  desugarForDiagnostic(Context, AT->getElementType(), ShouldAKA);
+  if (const auto *CAT = dyn_cast(AT))
+QT = Context.getConstantArrayType(
+ElementTy, CAT->getSize(), CAT->getSizeExpr(),
+CAT->getSizeModifier(), CAT->getIndexTypeCVRQualifiers());
+  else if (const auto *VAT = dyn_cast(AT))
+QT = Context.getVariableArrayType(
+ElementTy, VAT->getSizeExpr(), VAT->getSizeModifier(),
+VAT->getIndexTypeCVRQualifiers(), VAT->getBracketsRange());
+  else if (const auto *DSAT = dyn_cast(AT))
+QT = Context.getDependentSizedArrayType(
+ElementTy, DSAT->getSizeExpr(), DSAT->getSizeModifier(),
+DSAT->getIndexTypeCVRQualifiers(), DSAT->getBracketsRange());
+  else if (const auto *IAT = dyn_cast(AT))
+QT = Context.getIncompleteArrayType(ElementTy, IAT->getSizeModifier(),
+IAT->getIndexTypeCVRQualifiers());
+  else
+llvm_unreachable("Unhandled array type");
+  break;
+}
+
 // Don't desugar magic Objective-C types.
 if (QualType(Ty,0) == Context.getObjCIdType() ||
 QualType(Ty,0) == Context.getObjCClassType() ||

diff  --git a/clang/test/Misc/diag-aka-types.cpp 
b/clang/test/Misc/diag-aka-types.cpp
index 3e051bdddec66..493038d

[PATCH] D115107: [clang][clangd] Desugar array type.

2021-12-09 Thread liu hui via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG53219009aaeb: [clang][clangd] Desugar array type. (authored 
by lh123).

Changed prior to commit:
  https://reviews.llvm.org/D115107?vs=391884&id=393110#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115107

Files:
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang/lib/AST/ASTDiagnostic.cpp
  clang/test/Misc/diag-aka-types.cpp

Index: clang/test/Misc/diag-aka-types.cpp
===
--- clang/test/Misc/diag-aka-types.cpp
+++ clang/test/Misc/diag-aka-types.cpp
@@ -62,3 +62,9 @@
 void (&f3)(decltype(1 + 2)) = 0; // expected-error{{non-const lvalue reference to type 'void (decltype(1 + 2))' (aka 'void (int)') cannot bind to a temporary of type 'int'}}
 decltype(1+2) (&f4)(double, decltype(1 + 2)) = 0; // expected-error{{non-const lvalue reference to type 'decltype(1 + 2) (double, decltype(1 + 2))' (aka 'int (double, int)') cannot bind to a temporary of type 'int'}}
 auto (&f5)() -> decltype(1+2) = 0; // expected-error{{non-const lvalue reference to type 'auto () -> decltype(1 + 2)' (aka 'auto () -> int') cannot bind to a temporary of type 'int'}}
+
+using C = decltype(1+2);;
+C a6[10];
+extern C a8[];
+int a9 = a6; // expected-error{{cannot initialize a variable of type 'int' with an lvalue of type 'C[10]' (aka 'int[10]')}}
+int a10 = a8; // expected-error{{cannot initialize a variable of type 'int' with an lvalue of type 'C[]' (aka 'int[]')}}
Index: clang/lib/AST/ASTDiagnostic.cpp
===
--- clang/lib/AST/ASTDiagnostic.cpp
+++ clang/lib/AST/ASTDiagnostic.cpp
@@ -131,6 +131,29 @@
   }
 }
 
+if (const auto *AT = dyn_cast(Ty)) {
+  QualType ElementTy =
+  desugarForDiagnostic(Context, AT->getElementType(), ShouldAKA);
+  if (const auto *CAT = dyn_cast(AT))
+QT = Context.getConstantArrayType(
+ElementTy, CAT->getSize(), CAT->getSizeExpr(),
+CAT->getSizeModifier(), CAT->getIndexTypeCVRQualifiers());
+  else if (const auto *VAT = dyn_cast(AT))
+QT = Context.getVariableArrayType(
+ElementTy, VAT->getSizeExpr(), VAT->getSizeModifier(),
+VAT->getIndexTypeCVRQualifiers(), VAT->getBracketsRange());
+  else if (const auto *DSAT = dyn_cast(AT))
+QT = Context.getDependentSizedArrayType(
+ElementTy, DSAT->getSizeExpr(), DSAT->getSizeModifier(),
+DSAT->getIndexTypeCVRQualifiers(), DSAT->getBracketsRange());
+  else if (const auto *IAT = dyn_cast(AT))
+QT = Context.getIncompleteArrayType(ElementTy, IAT->getSizeModifier(),
+IAT->getIndexTypeCVRQualifiers());
+  else
+llvm_unreachable("Unhandled array type");
+  break;
+}
+
 // Don't desugar magic Objective-C types.
 if (QualType(Ty,0) == Context.getObjCIdType() ||
 QualType(Ty,0) == Context.getObjCClassType() ||
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -914,7 +914,7 @@
[](HoverInfo &HI) {
  HI.Name = "arr";
  HI.Kind = index::SymbolKind::Variable;
- HI.Type = "m_int[Size]";
+ HI.Type = {"m_int[Size]", "int[Size]"};
  HI.NamespaceScope = "";
  HI.Definition = "template  m_int arr[Size]";
  HI.TemplateParameters = {{{"int"}, {"Size"}, llvm::None}};
@@ -930,7 +930,7 @@
[](HoverInfo &HI) {
  HI.Name = "arr<4>";
  HI.Kind = index::SymbolKind::Variable;
- HI.Type = "m_int[4]";
+ HI.Type = {"m_int[4]", "int[4]"};
  HI.NamespaceScope = "";
  HI.Definition = "m_int arr[4]";
}},
@@ -998,6 +998,52 @@
  HI.Definition = "template  using AA = A";
  HI.Type = {"A", "type-parameter-0-0"}; // FIXME: should be 'T'
  HI.TemplateParameters = {{{"typename"}, std::string("T"), llvm::None}};
+   }},
+  {// Constant array
+   R"cpp(
+  using m_int = int;
+
+  m_int ^[[arr]][10];
+ )cpp",
+   [](HoverInfo &HI) {
+ HI.Name = "arr";
+ HI.NamespaceScope = "";
+ HI.LocalScope = "";
+ HI.Kind = index::SymbolKind::Variable;
+ HI.Definition = "m_int arr[10]";
+ HI.Type = {"m_int[10]", "int[10]"};
+   }},
+  {// Incomplete array
+   R"cpp(
+  using m_int = int;
+
+  extern m_int ^[[arr]][];
+ )cpp",
+   [](HoverInfo &HI) {
+ HI.Name = "arr";
+ HI.NamespaceScope = "";
+ HI.LocalScope = "";
+ HI.Kind = index::SymbolKind::Variable;
+ HI.Definition = "extern m_int arr[]";
+ HI.T

[PATCH] D114439: [Annotation] Allow parameter pack expansions in annotate attribute

2021-12-09 Thread Steffen Larsen via Phabricator via cfe-commits
steffenlarsen added inline comments.



Comment at: clang/lib/Parse/ParseDecl.cpp:447
 Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression()));
+
+if (Tok.is(tok::ellipsis)) {

erichkeane wrote:
> steffenlarsen wrote:
> > erichkeane wrote:
> > > So I was thinking about this overnight... I wonder if this logic is 
> > > inverted here?  Aaron can better answer, but I wonder if we should be 
> > > instead detecting when we are on the 'last' parameter and it is one of 
> > > these `VariadicExprArgument` things (that accept a pack), then dropping 
> > > the parser into a loop of:
> > > 
> > > while (Tok.is(tok::comma)){
> > >   Tok.Consume();
> > >   ArgExpr = CorrectTypos(ParseAssignmentExpr(...));
> > > }
> > > // finally, consume the closing paren.
> > > 
> > > WDYT?
> > The parsing of attribute arguments is already this lenient. It does not 
> > actually care how many arguments the attribute says it takes (unless it 
> > takes a type and then it will only currently supply _one_ argument). It 
> > simply consumes as many expressions it can before reaching the end 
> > parenthesis, then leaves the attributes to consume them in 
> > `clang/lib/Sema/SemaDeclAttr.cpp`.
> > As a result we do not need any additional work here to handle variadic 
> > arguments, but it also means that we have to introduce the restrictions 
> > that we can only allow packs in the last argument and allow only that 
> > argument to be variadic, as otherwise we have no way of knowing when and 
> > where the packs pass between argument boundaries.
> My point is, I don't think THIS function should be handling the ellipsis, the 
> expression parsing functions we send the parsing of each component off to 
> should do that.
> 
> We unfortunately cannot move the entirety of this parsing section to do that, 
> since 'identifier'/'type', and 'Function' argument types end up needing 
> special handling, but it would be nice if our 'expr' types would all be able 
> to do this, and I suggested earlier that we could start with the 
> `VariadicExprArgument` to make this an easier patch that didn't have to deal 
> with the issues that come with that.
> 
> That said, it would be nice if we could get CLOSE to that.
Sorry. I am still not sure I am following. Do you mean the consumption of pack 
expressions should be moved into the expression parsing so other places (not 
just attributes) would accept it? If so, I am not opposed to the idea though I 
have no idea which expressions these would be nor the full implications of such 
a change. For these we at least have the isolation of having to explicitly 
support the packs in the given attributes.


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

https://reviews.llvm.org/D114439

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


[PATCH] D115440: [clang][auto-init] Provide __builtin_alloca_uninitialized

2021-12-09 Thread Marco Elver via Phabricator via cfe-commits
melver created this revision.
melver added reviewers: jfb, pcc, glider.
melver requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When `-ftrivial-auto-var-init=` is enabled, allocas unconditionally
receive auto-initialization since [1].

In certain cases, it turns out, this is causing problems. For example,
when using alloca to add a random stack offset, as the Linux kernel does
on syscall entry [2]. In this case, none of the alloca'd stack memory is
ever used, and initializing it should be controllable; furthermore, it
is not always possible to safely call memset (see [2]).

Introduce `__builtin_alloca_uninitialized()`, which never performs
initialization when `-ftrivial-auto-var-init=` is enabled.

[1] https://reviews.llvm.org/D60548
[2] https://lkml.kernel.org/r/ybhtkujeejzcl...@elver.google.com


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115440

Files:
  clang/include/clang/Basic/Builtins.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGenCXX/trivial-auto-var-init.cpp
  clang/test/Sema/warn-alloca.c


Index: clang/test/Sema/warn-alloca.c
===
--- clang/test/Sema/warn-alloca.c
+++ clang/test/Sema/warn-alloca.c
@@ -18,3 +18,10 @@
   // expected-warning@-2 {{use of function '__builtin_alloca_with_align' is 
discouraged; there is no way to check for failure but failure may still occur, 
resulting in a possibly exploitable security vulnerability}}
 #endif
 }
+
+void test3(int a) {
+  __builtin_alloca_uninitialized(a);
+#ifndef SILENCE
+  // expected-warning@-2 {{use of function '__builtin_alloca_uninitialized' is 
discouraged; there is no way to check for failure but failure may still occur, 
resulting in a possibly exploitable security vulnerability}}
+#endif
+}
Index: clang/test/CodeGenCXX/trivial-auto-var-init.cpp
===
--- clang/test/CodeGenCXX/trivial-auto-var-init.cpp
+++ clang/test/CodeGenCXX/trivial-auto-var-init.cpp
@@ -201,6 +201,20 @@
   used(ptr);
 }
 
+// UNINIT-LABEL:  test_alloca_uninitialized(
+// ZERO-LABEL:test_alloca_uninitialized(
+// ZERO:  %[[SIZE:[a-z0-9]+]] = sext i32 %{{.*}} to i64
+// ZERO-NEXT: %[[ALLOCA:[a-z0-9]+]] = alloca i8, i64 %[[SIZE]], align 
[[ALIGN:[0-9]+]]
+// ZERO-NOT:  call void @llvm.memset
+// PATTERN-LABEL: test_alloca_uninitialized(
+// PATTERN:   %[[SIZE:[a-z0-9]+]] = sext i32 %{{.*}} to i64
+// PATTERN-NEXT:  %[[ALLOCA:[a-z0-9]+]] = alloca i8, i64 %[[SIZE]], align 
[[ALIGN:[0-9]+]]
+// PATTERN-NOT:   call void @llvm.memset
+void test_alloca_uninitialized(int size) {
+  void *ptr = __builtin_alloca_uninitialized(size);
+  used(ptr);
+}
+
 // UNINIT-LABEL:  test_struct_vla(
 // ZERO-LABEL:test_struct_vla(
 // ZERO:  %[[SIZE:[0-9]+]] = mul nuw i64 %{{.*}}, 16
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -1686,6 +1686,7 @@
 if (SemaBuiltinAllocaWithAlign(TheCall))
   return ExprError();
 LLVM_FALLTHROUGH;
+  case Builtin::BI__builtin_alloca_uninitialized:
   case Builtin::BI__builtin_alloca:
 Diag(TheCall->getBeginLoc(), diag::warn_alloca)
 << TheCall->getDirectCallee();
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -3417,6 +3417,7 @@
 
   case Builtin::BIalloca:
   case Builtin::BI_alloca:
+  case Builtin::BI__builtin_alloca_uninitialized:
   case Builtin::BI__builtin_alloca: {
 Value *Size = EmitScalarExpr(E->getArg(0));
 const TargetInfo &TI = getContext().getTargetInfo();
@@ -3427,7 +3428,8 @@
 .getAsAlign();
 AllocaInst *AI = Builder.CreateAlloca(Builder.getInt8Ty(), Size);
 AI->setAlignment(SuitableAlignmentInBytes);
-initializeAlloca(*this, AI, Size, SuitableAlignmentInBytes);
+if (BuiltinID != Builtin::BI__builtin_alloca_uninitialized)
+  initializeAlloca(*this, AI, Size, SuitableAlignmentInBytes);
 return RValue::get(AI);
   }
 
Index: clang/include/clang/Basic/Builtins.def
===
--- clang/include/clang/Basic/Builtins.def
+++ clang/include/clang/Basic/Builtins.def
@@ -640,6 +640,7 @@
 BUILTIN(__builtin_shufflevector, "v."   , "nct")
 BUILTIN(__builtin_convertvector, "v."   , "nct")
 BUILTIN(__builtin_alloca, "v*z"   , "Fn")
+BUILTIN(__builtin_alloca_uninitialized, "v*z", "Fn")
 BUILTIN(__builtin_alloca_with_align, "v*zIz", "Fn")
 BUILTIN(__builtin_call_with_static_chain, "v.", "nt")
 


Index: clang/test/Sema/warn-alloca.c
===
--- clang/test/Sema/warn-alloca.c
+++ clang/test/Sema/warn-alloca.c
@@ -18,3 +18,10 @@
   // expected-warn

[PATCH] D115250: switch to emulated TLV on macOS before 10.7

2021-12-09 Thread Kirill A. Korinsky via Phabricator via cfe-commits
catap added a comment.

I have a green light from build and this changes are ready for review.


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

https://reviews.llvm.org/D115250

___
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.

2021-12-09 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StrictAliasingChecker.cpp:113
+  QualType getOriginalType(CheckerContext &C, SVal V, QualType T) const {
+assert(V.getAs() && "Location shall be a Loc.");
+V = C.getState()->getSVal(V.castAs(), T);

ASDenysPetrov wrote:
> NoQ wrote:
> > I suspect it might also be `UnknownVal` (?) It usually makes sense to 
> > protect against such scenarios with an early return.
> I'll try to add some tests to model this.
'ExprEngine::evalLocation' has an early check for //unknown//, so `Location` is 
never be //unknown//.


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

https://reviews.llvm.org/D114718

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


[PATCH] D115441: [X86][MS] Add 80bit long double support for Windows

2021-12-09 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei created this revision.
pengfei added reviewers: rnk, andrew.w.kaylor, erichkeane, craig.topper.
Herald added a subscriber: hiraditya.
pengfei requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

MSVC currently doesn't support 80 bits long double. But ICC does support
it on Windows. Besides, there're also some users asked for this feature.
We can find the discussions from stackoverflow, msdn etc.

Given Clang has already support `-mlong-double-80`, extending it to
support for Windows seems worthwhile.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115441

Files:
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Basic/Targets/X86.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/X86/long-double-config-size.c
  clang/test/CodeGen/target-data.c
  llvm/lib/Target/X86/X86TargetMachine.cpp
  llvm/test/CodeGen/X86/scalar-fp-to-i32.ll
  llvm/test/CodeGen/X86/scalar-fp-to-i64.ll

Index: llvm/test/CodeGen/X86/scalar-fp-to-i64.ll
===
--- llvm/test/CodeGen/X86/scalar-fp-to-i64.ll
+++ llvm/test/CodeGen/X86/scalar-fp-to-i64.ll
@@ -909,8 +909,8 @@
 ; X86-AVX512-WIN:   # %bb.0:
 ; X86-AVX512-WIN-NEXT:pushl %ebp
 ; X86-AVX512-WIN-NEXT:movl %esp, %ebp
-; X86-AVX512-WIN-NEXT:andl $-8, %esp
-; X86-AVX512-WIN-NEXT:subl $8, %esp
+; X86-AVX512-WIN-NEXT:andl $-16, %esp
+; X86-AVX512-WIN-NEXT:subl $16, %esp
 ; X86-AVX512-WIN-NEXT:fldt 8(%ebp)
 ; X86-AVX512-WIN-NEXT:flds __real@5f00
 ; X86-AVX512-WIN-NEXT:xorl %edx, %edx
@@ -985,8 +985,8 @@
 ; X86-SSE3-WIN:   # %bb.0:
 ; X86-SSE3-WIN-NEXT:pushl %ebp
 ; X86-SSE3-WIN-NEXT:movl %esp, %ebp
-; X86-SSE3-WIN-NEXT:andl $-8, %esp
-; X86-SSE3-WIN-NEXT:subl $8, %esp
+; X86-SSE3-WIN-NEXT:andl $-16, %esp
+; X86-SSE3-WIN-NEXT:subl $16, %esp
 ; X86-SSE3-WIN-NEXT:fldt 8(%ebp)
 ; X86-SSE3-WIN-NEXT:flds __real@5f00
 ; X86-SSE3-WIN-NEXT:xorl %edx, %edx
@@ -1061,8 +1061,8 @@
 ; X86-SSE2-WIN:   # %bb.0:
 ; X86-SSE2-WIN-NEXT:pushl %ebp
 ; X86-SSE2-WIN-NEXT:movl %esp, %ebp
-; X86-SSE2-WIN-NEXT:andl $-8, %esp
-; X86-SSE2-WIN-NEXT:subl $16, %esp
+; X86-SSE2-WIN-NEXT:andl $-16, %esp
+; X86-SSE2-WIN-NEXT:subl $32, %esp
 ; X86-SSE2-WIN-NEXT:fldt 8(%ebp)
 ; X86-SSE2-WIN-NEXT:flds __real@5f00
 ; X86-SSE2-WIN-NEXT:xorl %edx, %edx
@@ -1161,8 +1161,8 @@
 ; X87-WIN:   # %bb.0:
 ; X87-WIN-NEXT:pushl %ebp
 ; X87-WIN-NEXT:movl %esp, %ebp
-; X87-WIN-NEXT:andl $-8, %esp
-; X87-WIN-NEXT:subl $16, %esp
+; X87-WIN-NEXT:andl $-16, %esp
+; X87-WIN-NEXT:subl $32, %esp
 ; X87-WIN-NEXT:fldt 8(%ebp)
 ; X87-WIN-NEXT:flds __real@5f00
 ; X87-WIN-NEXT:fucom %st(1)
@@ -1235,8 +1235,8 @@
 ; X86-AVX512-WIN:   # %bb.0:
 ; X86-AVX512-WIN-NEXT:pushl %ebp
 ; X86-AVX512-WIN-NEXT:movl %esp, %ebp
-; X86-AVX512-WIN-NEXT:andl $-8, %esp
-; X86-AVX512-WIN-NEXT:subl $8, %esp
+; X86-AVX512-WIN-NEXT:andl $-16, %esp
+; X86-AVX512-WIN-NEXT:subl $16, %esp
 ; X86-AVX512-WIN-NEXT:fldt 8(%ebp)
 ; X86-AVX512-WIN-NEXT:fisttpll (%esp)
 ; X86-AVX512-WIN-NEXT:movl (%esp), %eax
@@ -1275,8 +1275,8 @@
 ; X86-SSE3-WIN:   # %bb.0:
 ; X86-SSE3-WIN-NEXT:pushl %ebp
 ; X86-SSE3-WIN-NEXT:movl %esp, %ebp
-; X86-SSE3-WIN-NEXT:andl $-8, %esp
-; X86-SSE3-WIN-NEXT:subl $8, %esp
+; X86-SSE3-WIN-NEXT:andl $-16, %esp
+; X86-SSE3-WIN-NEXT:subl $16, %esp
 ; X86-SSE3-WIN-NEXT:fldt 8(%ebp)
 ; X86-SSE3-WIN-NEXT:fisttpll (%esp)
 ; X86-SSE3-WIN-NEXT:movl (%esp), %eax
@@ -1315,8 +1315,8 @@
 ; X86-SSE2-WIN:   # %bb.0:
 ; X86-SSE2-WIN-NEXT:pushl %ebp
 ; X86-SSE2-WIN-NEXT:movl %esp, %ebp
-; X86-SSE2-WIN-NEXT:andl $-8, %esp
-; X86-SSE2-WIN-NEXT:subl $16, %esp
+; X86-SSE2-WIN-NEXT:andl $-16, %esp
+; X86-SSE2-WIN-NEXT:subl $32, %esp
 ; X86-SSE2-WIN-NEXT:fldt 8(%ebp)
 ; X86-SSE2-WIN-NEXT:fnstcw {{[0-9]+}}(%esp)
 ; X86-SSE2-WIN-NEXT:movzwl {{[0-9]+}}(%esp), %eax
@@ -1379,8 +1379,8 @@
 ; X87-WIN:   # %bb.0:
 ; X87-WIN-NEXT:pushl %ebp
 ; X87-WIN-NEXT:movl %esp, %ebp
-; X87-WIN-NEXT:andl $-8, %esp
-; X87-WIN-NEXT:subl $16, %esp
+; X87-WIN-NEXT:andl $-16, %esp
+; X87-WIN-NEXT:subl $32, %esp
 ; X87-WIN-NEXT:fldt 8(%ebp)
 ; X87-WIN-NEXT:fnstcw {{[0-9]+}}(%esp)
 ; X87-WIN-NEXT:movzwl {{[0-9]+}}(%esp), %eax
Index: llvm/test/CodeGen/X86/scalar-fp-to-i32.ll
===
--- llvm/test/CodeGen/X86/scalar-fp-to-i32.ll
+++ llvm/test/CodeGen/X86/scalar-fp-to-i32.ll
@@ -344,8 +344,8 @@
 ; X86-AVX512-WIN:   # %bb.0:
 ; X86-AVX512-WIN-NEXT:pushl %ebp
 ; X86-AVX512-WIN-NEXT:movl %esp, %ebp
-; X86-AVX512-WIN-NEXT:andl $-8, %esp
-; X86-AVX512-WIN-NEXT:subl $8, %esp
+; X86-AVX512-WIN-NEXT:andl $-16, %esp
+; X86-AVX512-WIN-NEXT:subl 

[PATCH] D113237: [RISCV] Support I extension version 2.1

2021-12-09 Thread Alex Bradbury via Phabricator via cfe-commits
asb added a comment.

In D113237#3172492 , 
@achieveartificialintelligence wrote:

> In D113237#3124232 , @luismarques 
> wrote:
>
>> In D113237#3124188 , @luismarques 
>> wrote:
>>
>>> Should we also support `fence.i` with RVI 2.0, without zifencei?
>>
>> Here's a proposed path forwards:
>>
>> - Patch 1: Add support for RVI 2.1 and related changes. Keep RVI 2.0 as the 
>> default.
>> - Patch 2: Add warnings for uses of the removed `fence.i`, CSRs and counters 
>> when using RVI 2.0 (at least when doing so by default; arguably this should 
>> error out instead when explicitly specifying version 2.0.)
>> - Patch 3: Start defaulting to RVI 2.1. IMO this should only be committed 
>> after patch 2 being in effect for a while.
>
> I tried to make I-ext imply `zifencei`, `zicsr`, and `zihintpause` 
> automatically. BTW `zihintpause` is implemented in D93019 
> .

It's a fairly minor detail, but I think implying zihintpause automatically is 
semantically different to what Luis proposed (as zihintpause wasn't in RVI 2.0, 
it shouldn't be implied by default like zifencei and zicsr should).

Luis' proposed series of patches makes a lot of sense to me, but a complicating 
factor is I'm not sure we have a super clean way to support different versions 
of an extension at the same time.

For instance, to make this patch match Luis' suggested "patch 1" you'd need to 
be able to specify rvi2.1 and then have it not automatically included zifencei 
and zicsr. Ideally the version emitted in build attributes would stay as 2.0 
unless you explicitly selected 2.1 as well. This patch would then also not need 
to update test cases to include +zifencei and +zicsr.

We should discuss this in the RISC-V LLVM call today.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113237

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


[PATCH] D115440: [clang][auto-init] Provide __builtin_alloca_uninitialized

2021-12-09 Thread Alexander Potapenko via Phabricator via cfe-commits
glider added a comment.

I second this proposal.
https://reviews.llvm.org/D60548 suggests to handle this case using a pragma, 
but the required change seems to be more intrusive.




Comment at: clang/lib/CodeGen/CGBuiltin.cpp:3436
 
   case Builtin::BI__builtin_alloca_with_align: {
 Value *Size = EmitScalarExpr(E->getArg(0));

For the sake of completeness, shall we also implement an uninitialized version 
of __builtin_alloca_with_align()?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115440

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


[PATCH] D115320: Avoid setting tbaa information on store of return type of call to inline assember

2021-12-09 Thread Jeroen Dobbelaere via Phabricator via cfe-commits
jeroen.dobbelaere added a comment.

When I try out the example on llvm-13, I get a 'omnipotent char' tbaa 
description. That should be ok in general. When I replace the 'float _Complex' 
with 'double', I do get the 'double' tbaa. That might be a better example for 
the testcase ?


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

https://reviews.llvm.org/D115320

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


[PATCH] D115440: [clang][auto-init] Provide __builtin_alloca_uninitialized

2021-12-09 Thread Marco Elver via Phabricator via cfe-commits
melver added inline comments.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:3436
 
   case Builtin::BI__builtin_alloca_with_align: {
 Value *Size = EmitScalarExpr(E->getArg(0));

glider wrote:
> For the sake of completeness, shall we also implement an uninitialized 
> version of __builtin_alloca_with_align()?
You are right, I've added that, too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115440

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


[PATCH] D115440: [clang][auto-init] Provide __builtin_alloca_uninitialized

2021-12-09 Thread Marco Elver via Phabricator via cfe-commits
melver updated this revision to Diff 393122.
melver marked an inline comment as done.
melver added a comment.

For completeness, also provide __builtin_alloca_with_align_uninitialized().


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115440

Files:
  clang/include/clang/Basic/Builtins.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGenCXX/trivial-auto-var-init.cpp
  clang/test/Sema/warn-alloca.c

Index: clang/test/Sema/warn-alloca.c
===
--- clang/test/Sema/warn-alloca.c
+++ clang/test/Sema/warn-alloca.c
@@ -18,3 +18,17 @@
   // expected-warning@-2 {{use of function '__builtin_alloca_with_align' is discouraged; there is no way to check for failure but failure may still occur, resulting in a possibly exploitable security vulnerability}}
 #endif
 }
+
+void test3(int a) {
+  __builtin_alloca_uninitialized(a);
+#ifndef SILENCE
+  // expected-warning@-2 {{use of function '__builtin_alloca_uninitialized' is discouraged; there is no way to check for failure but failure may still occur, resulting in a possibly exploitable security vulnerability}}
+#endif
+}
+
+void test4(int a) {
+  __builtin_alloca_with_align_uninitialized(a, 32);
+#ifndef SILENCE
+  // expected-warning@-2 {{use of function '__builtin_alloca_with_align_uninitialized' is discouraged; there is no way to check for failure but failure may still occur, resulting in a possibly exploitable security vulnerability}}
+#endif
+}
Index: clang/test/CodeGenCXX/trivial-auto-var-init.cpp
===
--- clang/test/CodeGenCXX/trivial-auto-var-init.cpp
+++ clang/test/CodeGenCXX/trivial-auto-var-init.cpp
@@ -201,6 +201,34 @@
   used(ptr);
 }
 
+// UNINIT-LABEL:  test_alloca_uninitialized(
+// ZERO-LABEL:test_alloca_uninitialized(
+// ZERO:  %[[SIZE:[a-z0-9]+]] = sext i32 %{{.*}} to i64
+// ZERO-NEXT: %[[ALLOCA:[a-z0-9]+]] = alloca i8, i64 %[[SIZE]], align [[ALIGN:[0-9]+]]
+// ZERO-NOT:  call void @llvm.memset
+// PATTERN-LABEL: test_alloca_uninitialized(
+// PATTERN:   %[[SIZE:[a-z0-9]+]] = sext i32 %{{.*}} to i64
+// PATTERN-NEXT:  %[[ALLOCA:[a-z0-9]+]] = alloca i8, i64 %[[SIZE]], align [[ALIGN:[0-9]+]]
+// PATTERN-NOT:   call void @llvm.memset
+void test_alloca_uninitialized(int size) {
+  void *ptr = __builtin_alloca_uninitialized(size);
+  used(ptr);
+}
+
+// UNINIT-LABEL:  test_alloca_with_align_uninitialized(
+// ZERO-LABEL:test_alloca_with_align_uninitialized(
+// ZERO:  %[[SIZE:[a-z0-9]+]] = sext i32 %{{.*}} to i64
+// ZERO-NEXT: %[[ALLOCA:[a-z0-9]+]] = alloca i8, i64 %[[SIZE]], align 128
+// ZERO-NOT:  call void @llvm.memset
+// PATTERN-LABEL: test_alloca_with_align_uninitialized(
+// PATTERN:   %[[SIZE:[a-z0-9]+]] = sext i32 %{{.*}} to i64
+// PATTERN-NEXT:  %[[ALLOCA:[a-z0-9]+]] = alloca i8, i64 %[[SIZE]], align 128
+// PATTERN-NOT:   call void @llvm.memset
+void test_alloca_with_align_uninitialized(int size) {
+  void *ptr = __builtin_alloca_with_align_uninitialized(size, 1024);
+  used(ptr);
+}
+
 // UNINIT-LABEL:  test_struct_vla(
 // ZERO-LABEL:test_struct_vla(
 // ZERO:  %[[SIZE:[0-9]+]] = mul nuw i64 %{{.*}}, 16
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -1683,10 +1683,12 @@
   return ExprError();
 break;
   case Builtin::BI__builtin_alloca_with_align:
+  case Builtin::BI__builtin_alloca_with_align_uninitialized:
 if (SemaBuiltinAllocaWithAlign(TheCall))
   return ExprError();
 LLVM_FALLTHROUGH;
   case Builtin::BI__builtin_alloca:
+  case Builtin::BI__builtin_alloca_uninitialized:
 Diag(TheCall->getBeginLoc(), diag::warn_alloca)
 << TheCall->getDirectCallee();
 break;
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -3417,6 +3417,7 @@
 
   case Builtin::BIalloca:
   case Builtin::BI_alloca:
+  case Builtin::BI__builtin_alloca_uninitialized:
   case Builtin::BI__builtin_alloca: {
 Value *Size = EmitScalarExpr(E->getArg(0));
 const TargetInfo &TI = getContext().getTargetInfo();
@@ -3427,10 +3428,12 @@
 .getAsAlign();
 AllocaInst *AI = Builder.CreateAlloca(Builder.getInt8Ty(), Size);
 AI->setAlignment(SuitableAlignmentInBytes);
-initializeAlloca(*this, AI, Size, SuitableAlignmentInBytes);
+if (BuiltinID != Builtin::BI__builtin_alloca_uninitialized)
+  initializeAlloca(*this, AI, Size, SuitableAlignmentInBytes);
 return RValue::get(AI);
   }
 
+  case Builtin::BI__builtin_alloca_with_align_uninitialized:
   case Builtin::BI__builtin_alloca_with_align: {
 Value *Size = EmitScalarExpr(E->getArg(0));
 Value 

[clang] bfe0719 - [ARM][clang] Option b-key must not affect __ARM_FEATURE_PAC_DEFAULT

2021-12-09 Thread Ties Stuij via cfe-commits

Author: Ties Stuij
Date: 2021-12-09T13:37:52Z
New Revision: bfe07195bb1f517b2809107098b91767ad8c9460

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

LOG: [ARM][clang] Option b-key must not affect __ARM_FEATURE_PAC_DEFAULT

When using -mbranch-protection=pac-ret+b-key, macro __ARM_FEATURE_PAC_DEFAULT
should still have the value corresponding to a-key, because b-key is only valid
for AArch64.

This patch is part of a series that adds support for the PACBTI-M extension of
the Armv8.1-M architecture, as detailed here:

https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/armv8-1-m-pointer-authentication-and-branch-target-identification-extension

The PACBTI-M specification can be found in the Armv8-M Architecture Reference
Manual:

https://developer.arm.com/documentation/ddi0553/latest

The following people contributed to this patch:

- Victor Campos

Reviewed By: danielkiss

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

Added: 


Modified: 
clang/lib/Basic/Targets/ARM.cpp
clang/test/Preprocessor/arm-target-features.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp
index 81b79cfe19e47..c619d6cde41df 100644
--- a/clang/lib/Basic/Targets/ARM.cpp
+++ b/clang/lib/Basic/Targets/ARM.cpp
@@ -911,7 +911,7 @@ void ARMTargetInfo::getTargetDefines(const LangOptions 
&Opts,
 Builder.defineMacro("__ARM_FEATURE_BTI_DEFAULT", "1");
 
   if (Opts.hasSignReturnAddress()) {
-unsigned Value = Opts.isSignReturnAddressWithAKey() ? 1 : 2;
+unsigned Value = 1;
 if (Opts.isSignReturnAddressScopeAll())
   Value |= 1 << 2;
 Builder.defineMacro("__ARM_FEATURE_PAC_DEFAULT", Twine(Value));

diff  --git a/clang/test/Preprocessor/arm-target-features.c 
b/clang/test/Preprocessor/arm-target-features.c
index 49a5516e15d0d..bf4e7c41e3e23 100644
--- a/clang/test/Preprocessor/arm-target-features.c
+++ b/clang/test/Preprocessor/arm-target-features.c
@@ -881,20 +881,18 @@
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -x c -E -dM %s 
-o - | FileCheck --check-prefixes=CHECK-NOBTI,CHECK-NOPAC %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=bti -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-BTI,CHECK-NOPAC %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=pac-ret -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC,CHECK-NOBTI %s
-// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=pac-ret+b-key -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC-BKEY,CHECK-NOBTI %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=pac-ret+b-key -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC,CHECK-NOBTI %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=pac-ret+leaf -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC-LEAF,CHECK-NOBTI %s
-// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=pac-ret+b-key+leaf -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC-BKEY-LEAF,CHECK-NOBTI %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=pac-ret+b-key+leaf -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC-LEAF,CHECK-NOBTI %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=bti+pac-ret -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC,CHECK-BTI %s
-// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=bti+pac-ret+b-key -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC-BKEY,CHECK-BTI %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=bti+pac-ret+b-key -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC,CHECK-BTI %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=bti+pac-ret+leaf -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC-LEAF,CHECK-BTI %s
-// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=bti+pac-ret+b-key+leaf -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC-BKEY-LEAF,CHECK-BTI %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=bti+pac-ret+b-key+leaf -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC-LEAF,CHECK-BTI %s
 // CHECK-NOBTI-NOT: #define __ARM_FEATURE_BTI_DEFAULT
 // CHECK-NOPAC-NOT: #define __ARM_FEATURE_PAC_DEFAULT
 // CHECK-BTI: #define __ARM_FEATURE_BTI_DEFAULT 1
 // CHECK-PAC: #define __ARM_FEATURE_PAC_DEFAULT 1
-// CHECK-PAC-BKEY: #define __ARM_FEATURE_PAC_DEFAULT 2
 // CHECK-PAC-LEAF: #define __ARM_FEATURE_PAC_DEFAUL

[PATCH] D115140: [ARM][clang] Option b-key must not affect __ARM_FEATURE_PAC_DEFAULT

2021-12-09 Thread Ties Stuij via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbfe07195bb1f: [ARM][clang] Option b-key must not affect 
__ARM_FEATURE_PAC_DEFAULT (authored by stuij).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115140

Files:
  clang/lib/Basic/Targets/ARM.cpp
  clang/test/Preprocessor/arm-target-features.c


Index: clang/test/Preprocessor/arm-target-features.c
===
--- clang/test/Preprocessor/arm-target-features.c
+++ clang/test/Preprocessor/arm-target-features.c
@@ -881,20 +881,18 @@
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -x c -E -dM %s 
-o - | FileCheck --check-prefixes=CHECK-NOBTI,CHECK-NOPAC %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=bti -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-BTI,CHECK-NOPAC %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=pac-ret -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC,CHECK-NOBTI %s
-// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=pac-ret+b-key -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC-BKEY,CHECK-NOBTI %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=pac-ret+b-key -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC,CHECK-NOBTI %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=pac-ret+leaf -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC-LEAF,CHECK-NOBTI %s
-// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=pac-ret+b-key+leaf -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC-BKEY-LEAF,CHECK-NOBTI %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=pac-ret+b-key+leaf -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC-LEAF,CHECK-NOBTI %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=bti+pac-ret -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC,CHECK-BTI %s
-// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=bti+pac-ret+b-key -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC-BKEY,CHECK-BTI %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=bti+pac-ret+b-key -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC,CHECK-BTI %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=bti+pac-ret+leaf -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC-LEAF,CHECK-BTI %s
-// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=bti+pac-ret+b-key+leaf -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC-BKEY-LEAF,CHECK-BTI %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=bti+pac-ret+b-key+leaf -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC-LEAF,CHECK-BTI %s
 // CHECK-NOBTI-NOT: #define __ARM_FEATURE_BTI_DEFAULT
 // CHECK-NOPAC-NOT: #define __ARM_FEATURE_PAC_DEFAULT
 // CHECK-BTI: #define __ARM_FEATURE_BTI_DEFAULT 1
 // CHECK-PAC: #define __ARM_FEATURE_PAC_DEFAULT 1
-// CHECK-PAC-BKEY: #define __ARM_FEATURE_PAC_DEFAULT 2
 // CHECK-PAC-LEAF: #define __ARM_FEATURE_PAC_DEFAULT 5
-// CHECK-PAC-BKEY-LEAF: #define __ARM_FEATURE_PAC_DEFAULT 6
 
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -x c -E -dM %s 
-o - | FileCheck --check-prefixes=CHECK-NOBTI-EXT,CHECK-NOPAC-EXT %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv7-m+pacbti -x c -E -dM %s 
-o - | FileCheck --check-prefixes=CHECK-PACBTI-EXT %s
Index: clang/lib/Basic/Targets/ARM.cpp
===
--- clang/lib/Basic/Targets/ARM.cpp
+++ clang/lib/Basic/Targets/ARM.cpp
@@ -911,7 +911,7 @@
 Builder.defineMacro("__ARM_FEATURE_BTI_DEFAULT", "1");
 
   if (Opts.hasSignReturnAddress()) {
-unsigned Value = Opts.isSignReturnAddressWithAKey() ? 1 : 2;
+unsigned Value = 1;
 if (Opts.isSignReturnAddressScopeAll())
   Value |= 1 << 2;
 Builder.defineMacro("__ARM_FEATURE_PAC_DEFAULT", Twine(Value));


Index: clang/test/Preprocessor/arm-target-features.c
===
--- clang/test/Preprocessor/arm-target-features.c
+++ clang/test/Preprocessor/arm-target-features.c
@@ -881,20 +881,18 @@
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -x c -E -dM %s -o - | FileCheck --check-prefixes=CHECK-NOBTI,CHECK-NOPAC %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -mbranch-protection=bti -x c -E -dM %s -o - | FileCheck --check-prefixes=CHECK-BTI,CHECK-NOPAC %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -mbranch-protection=pac-ret -x c -E -dM %s -o - | FileChe

[clang] 543a9ad - [xray] add support for hexagon

2021-12-09 Thread Brian Cain via cfe-commits

Author: Brian Cain
Date: 2021-12-09T05:47:53-08:00
New Revision: 543a9ad7c460bb8d641b1b7c67bbc032c9bfdb45

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

LOG: [xray] add support for hexagon

Adds x-ray support for hexagon to llvm codegen, clang driver,
compiler-rt libs.

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

Added: 
compiler-rt/lib/xray/xray_hexagon.cpp
compiler-rt/lib/xray/xray_trampoline_hexagon.S
llvm/test/CodeGen/Hexagon/xray-pred-ret.ll
llvm/test/CodeGen/Hexagon/xray.ll

Modified: 
clang/lib/Driver/ToolChains/Hexagon.cpp
clang/lib/Driver/XRayArgs.cpp
compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
compiler-rt/lib/xray/CMakeLists.txt
compiler-rt/lib/xray/xray_interface.cpp
compiler-rt/lib/xray/xray_tsc.h
llvm/lib/CodeGen/XRayInstrumentation.cpp
llvm/lib/Target/Hexagon/HexagonAsmPrinter.cpp
llvm/lib/Target/Hexagon/HexagonAsmPrinter.h
llvm/lib/Target/Hexagon/HexagonInstrInfo.cpp
llvm/lib/Target/Hexagon/HexagonInstrInfo.h
llvm/lib/Target/Hexagon/HexagonMCInstLower.cpp
llvm/lib/Target/Hexagon/HexagonSubtarget.h
llvm/lib/Target/Hexagon/HexagonVLIWPacketizer.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Hexagon.cpp 
b/clang/lib/Driver/ToolChains/Hexagon.cpp
index 18270818d1589..2ce7904ecc40d 100644
--- a/clang/lib/Driver/ToolChains/Hexagon.cpp
+++ b/clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -226,6 +226,7 @@ constructHexagonLinkArgs(Compilation &C, const JobAction 
&JA,
   StringRef CpuVer = toolchains::HexagonToolChain::GetTargetCPUVersion(Args);
 
   bool NeedsSanitizerDeps = addSanitizerRuntimes(HTC, Args, CmdArgs);
+  bool NeedsXRayDeps = addXRayRuntime(HTC, Args, CmdArgs);
 
   
//
   // Silence warnings for various options
@@ -297,6 +298,8 @@ constructHexagonLinkArgs(Compilation &C, const JobAction 
&JA,
 
 CmdArgs.push_back("-lunwind");
   }
+  if (NeedsXRayDeps)
+linkXRayRuntimeDeps(HTC, CmdArgs);
 
   CmdArgs.push_back("-lclang_rt.builtins-hexagon");
   CmdArgs.push_back("-lc");

diff  --git a/clang/lib/Driver/XRayArgs.cpp b/clang/lib/Driver/XRayArgs.cpp
index b44509ad3b881..63b575178bd12 100644
--- a/clang/lib/Driver/XRayArgs.cpp
+++ b/clang/lib/Driver/XRayArgs.cpp
@@ -40,6 +40,7 @@ XRayArgs::XRayArgs(const ToolChain &TC, const ArgList &Args) {
 case llvm::Triple::x86_64:
 case llvm::Triple::arm:
 case llvm::Triple::aarch64:
+case llvm::Triple::hexagon:
 case llvm::Triple::ppc64le:
 case llvm::Triple::mips:
 case llvm::Triple::mipsel:

diff  --git a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake 
b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
index 45226b4158d74..3e86cf63c789b 100644
--- a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
+++ b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
@@ -73,7 +73,8 @@ set(ALL_SCUDO_STANDALONE_SUPPORTED_ARCH ${X86} ${X86_64} 
${ARM32} ${ARM64}
 if(APPLE)
 set(ALL_XRAY_SUPPORTED_ARCH ${X86_64})
 else()
-set(ALL_XRAY_SUPPORTED_ARCH ${X86_64} ${ARM32} ${ARM64} ${MIPS32} ${MIPS64} 
powerpc64le)
+set(ALL_XRAY_SUPPORTED_ARCH ${X86_64} ${ARM32} ${ARM64} ${MIPS32} ${MIPS64}
+   powerpc64le ${HEXAGON})
 endif()
 set(ALL_SHADOWCALLSTACK_SUPPORTED_ARCH ${ARM64})
 

diff  --git a/compiler-rt/lib/xray/CMakeLists.txt 
b/compiler-rt/lib/xray/CMakeLists.txt
index 204e5b17c7970..ca9389747a5ee 100644
--- a/compiler-rt/lib/xray/CMakeLists.txt
+++ b/compiler-rt/lib/xray/CMakeLists.txt
@@ -73,6 +73,11 @@ set(powerpc64le_SOURCES
   xray_trampoline_powerpc64_asm.S
   )
 
+set(hexagon_SOURCES
+  xray_hexagon.cpp
+  xray_trampoline_hexagon.S
+  )
+
 set(XRAY_IMPL_HEADERS
   xray_allocator.h
   xray_basic_flags.h
@@ -111,6 +116,7 @@ set(XRAY_ALL_SOURCE_FILES
   ${x86_64_SOURCES}
   ${arm_SOURCES}
   ${armhf_SOURCES}
+  ${hexagon_SOURCES}
   ${mips_SOURCES}
   ${mipsel_SOURCES}
   ${mips64_SOURCES}

diff  --git a/compiler-rt/lib/xray/xray_hexagon.cpp 
b/compiler-rt/lib/xray/xray_hexagon.cpp
new file mode 100644
index 0..7f127b2b499cd
--- /dev/null
+++ b/compiler-rt/lib/xray/xray_hexagon.cpp
@@ -0,0 +1,168 @@
+//===-- xray_hexagon.cpp --*- C++ 
---*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file is a part of XRay, a dynamic runtime instrumentation system.
+//
+// Implementation of hexagon-specific routines (32-bit).
+//
+//===

[PATCH] D113638: [xray] Add support for hexagon architecture

2021-12-09 Thread Brian Cain 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 rG543a9ad7c460: [xray] add support for hexagon (authored by 
androm3da).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113638

Files:
  clang/lib/Driver/ToolChains/Hexagon.cpp
  clang/lib/Driver/XRayArgs.cpp
  compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
  compiler-rt/lib/xray/CMakeLists.txt
  compiler-rt/lib/xray/xray_hexagon.cpp
  compiler-rt/lib/xray/xray_interface.cpp
  compiler-rt/lib/xray/xray_trampoline_hexagon.S
  compiler-rt/lib/xray/xray_tsc.h
  llvm/lib/CodeGen/XRayInstrumentation.cpp
  llvm/lib/Target/Hexagon/HexagonAsmPrinter.cpp
  llvm/lib/Target/Hexagon/HexagonAsmPrinter.h
  llvm/lib/Target/Hexagon/HexagonInstrInfo.cpp
  llvm/lib/Target/Hexagon/HexagonInstrInfo.h
  llvm/lib/Target/Hexagon/HexagonMCInstLower.cpp
  llvm/lib/Target/Hexagon/HexagonSubtarget.h
  llvm/lib/Target/Hexagon/HexagonVLIWPacketizer.cpp
  llvm/test/CodeGen/Hexagon/xray-pred-ret.ll
  llvm/test/CodeGen/Hexagon/xray.ll

Index: llvm/test/CodeGen/Hexagon/xray.ll
===
--- /dev/null
+++ llvm/test/CodeGen/Hexagon/xray.ll
@@ -0,0 +1,29 @@
+; RUN: llc -filetype=asm -o - -mtriple=hexagon-unknown-elf < %s | FileCheck %s
+; RUN: llc -filetype=asm -o - -mtriple=hexagon-unknown-linux-musl  < %s | FileCheck %s
+
+define i32 @foo() nounwind noinline uwtable "function-instrument"="xray-always" {
+; CHECK-LABEL: .Lxray_sled_0:
+; CHECK:   jump .Ltmp0
+; CHECK: nop
+; CHECK: nop
+; CHECK: nop
+; CHECK: nop
+; CHECK-LABEL: .Ltmp0:
+  ret i32 0
+; CHECK-LABEL: .Lxray_sled_1:
+; CHECK:   jump .Ltmp1
+; CHECK: nop
+; CHECK: nop
+; CHECK: nop
+; CHECK: nop
+; CHECK-LABEL: .Ltmp1:
+; CHECK:   jumpr r31
+}
+; CHECK-LABEL: xray_instr_map
+; CHECK-LABEL: .Lxray_sleds_start0:
+; CHECK:   .word {{.*}}Lxray_sled_0
+; CHECK:   .word {{.*}}Lxray_sled_1
+; CHECK-LABEL: .Lxray_sleds_end0:
+; CHECK-LABEL: xray_fn_idx
+; CHECK:   .word {{.*}}Lxray_sleds_start0
+; CHECK-NEXT:  .word {{.*}}Lxray_sleds_end0
Index: llvm/test/CodeGen/Hexagon/xray-pred-ret.ll
===
--- /dev/null
+++ llvm/test/CodeGen/Hexagon/xray-pred-ret.ll
@@ -0,0 +1,27 @@
+; RUN: llc -filetype=asm -o - -mtriple=hexagon-unknown-linux-musl < %s | FileCheck %s
+
+define void @Foo(i32 signext %a, i32 signext %b) #0 {
+; CHECK-LABEL: @Foo
+; CHECK-LABEL: .Lxray_sled_0:
+; CHECK:jump .Ltmp0
+; CHECK-COUNT-4: nop
+entry:
+  %cmp = icmp sgt i32 %a, %b
+  br i1 %cmp, label %return, label %if.end
+
+; CHECK-LABEL: .Lxray_sled_1:
+; CHECK:jump .Ltmp1
+; CHECK-COUNT-4: nop
+; CHECK-LABEL: .Ltmp1:
+; CHECK:   if (p0) jumpr:nt r31
+if.end:
+  tail call void @Bar()
+  br label %return
+
+return:
+  ret void
+}
+
+declare void @Bar()
+
+attributes #0 = { "function-instrument"="xray-always" }
Index: llvm/lib/Target/Hexagon/HexagonVLIWPacketizer.cpp
===
--- llvm/lib/Target/Hexagon/HexagonVLIWPacketizer.cpp
+++ llvm/lib/Target/Hexagon/HexagonVLIWPacketizer.cpp
@@ -1082,6 +1082,11 @@
   if (HII->isSolo(MI))
 return true;
 
+  if (MI.getOpcode() == Hexagon::PATCHABLE_FUNCTION_ENTER ||
+  MI.getOpcode() == Hexagon::PATCHABLE_FUNCTION_EXIT ||
+  MI.getOpcode() == Hexagon::PATCHABLE_TAIL_CALL)
+return true;
+
   if (MI.getOpcode() == Hexagon::A2_nop)
 return true;
 
Index: llvm/lib/Target/Hexagon/HexagonSubtarget.h
===
--- llvm/lib/Target/Hexagon/HexagonSubtarget.h
+++ llvm/lib/Target/Hexagon/HexagonSubtarget.h
@@ -138,6 +138,8 @@
   /// subtarget options.  Definition of function is auto generated by tblgen.
   void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
 
+  bool isXRaySupported() const override { return true; }
+
   bool hasV5Ops() const {
 return getHexagonArchVersion() >= Hexagon::ArchEnum::V5;
   }
Index: llvm/lib/Target/Hexagon/HexagonMCInstLower.cpp
===
--- llvm/lib/Target/Hexagon/HexagonMCInstLower.cpp
+++ llvm/lib/Target/Hexagon/HexagonMCInstLower.cpp
@@ -104,6 +104,19 @@
 HexagonMCInstrInfo::setOuterLoop(MCB);
 return;
   }
+  if (MI->getOpcode() == Hexagon::PATCHABLE_FUNCTION_ENTER) {
+AP.EmitSled(*MI, HexagonAsmPrinter::SledKind::FUNCTION_ENTER);
+return;
+  }
+  if (MI->getOpcode() == Hexagon::PATCHABLE_FUNCTION_EXIT) {
+AP.EmitSled(*MI, HexagonAsmPrinter::SledKind::FUNCTION_EXIT);
+return;
+  }
+  if (MI->getOpcode() == Hexagon::PATCHABLE_TAIL_CALL) {
+AP.EmitSled(*MI, HexagonAsmPrinter::SledKind::TAIL_CALL);
+return;
+  }
+
   MCInst *MCI = AP.OutContext.createMC

[PATCH] D87279: [clang] Fix handling of physical registers in inline assembly operands.

2021-12-09 Thread James Y Knight via Phabricator via cfe-commits
jyknight added a comment.

This change seems like it's done in the wrong layer -- why do we add a 
special-case in Clang to emit "={r11},{r11}", instead of fixing LLVM to not 
break when given the previously-output "={r11},0"?

Furthermore, since earlyclobber was exempted from this change, doesn't the same 
TwoAddressInstructionPass bug still affect earlyclobber uses?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87279

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


[PATCH] D115441: [X86][MS] Add 80bit long double support for Windows

2021-12-09 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.
This revision is now accepted and ready to land.

This looks good to me, and mirrors something I implemented in our downstream a 
few years ago.  Please don't submit for another day or two to give others a 
chance to review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115441

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


[PATCH] D114439: [Annotation] Allow parameter pack expansions in annotate attribute

2021-12-09 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Parse/ParseDecl.cpp:447
 Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression()));
+
+if (Tok.is(tok::ellipsis)) {

steffenlarsen wrote:
> erichkeane wrote:
> > steffenlarsen wrote:
> > > erichkeane wrote:
> > > > So I was thinking about this overnight... I wonder if this logic is 
> > > > inverted here?  Aaron can better answer, but I wonder if we should be 
> > > > instead detecting when we are on the 'last' parameter and it is one of 
> > > > these `VariadicExprArgument` things (that accept a pack), then dropping 
> > > > the parser into a loop of:
> > > > 
> > > > while (Tok.is(tok::comma)){
> > > >   Tok.Consume();
> > > >   ArgExpr = CorrectTypos(ParseAssignmentExpr(...));
> > > > }
> > > > // finally, consume the closing paren.
> > > > 
> > > > WDYT?
> > > The parsing of attribute arguments is already this lenient. It does not 
> > > actually care how many arguments the attribute says it takes (unless it 
> > > takes a type and then it will only currently supply _one_ argument). It 
> > > simply consumes as many expressions it can before reaching the end 
> > > parenthesis, then leaves the attributes to consume them in 
> > > `clang/lib/Sema/SemaDeclAttr.cpp`.
> > > As a result we do not need any additional work here to handle variadic 
> > > arguments, but it also means that we have to introduce the restrictions 
> > > that we can only allow packs in the last argument and allow only that 
> > > argument to be variadic, as otherwise we have no way of knowing when and 
> > > where the packs pass between argument boundaries.
> > My point is, I don't think THIS function should be handling the ellipsis, 
> > the expression parsing functions we send the parsing of each component off 
> > to should do that.
> > 
> > We unfortunately cannot move the entirety of this parsing section to do 
> > that, since 'identifier'/'type', and 'Function' argument types end up 
> > needing special handling, but it would be nice if our 'expr' types would 
> > all be able to do this, and I suggested earlier that we could start with 
> > the `VariadicExprArgument` to make this an easier patch that didn't have to 
> > deal with the issues that come with that.
> > 
> > That said, it would be nice if we could get CLOSE to that.
> Sorry. I am still not sure I am following. Do you mean the consumption of 
> pack expressions should be moved into the expression parsing so other places 
> (not just attributes) would accept it? If so, I am not opposed to the idea 
> though I have no idea which expressions these would be nor the full 
> implications of such a change. For these we at least have the isolation of 
> having to explicitly support the packs in the given attributes.
I'm saying the other expression parsers should ALREADY properly handle packs, 
and we should just use those.


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

https://reviews.llvm.org/D114439

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


[PATCH] D115442: [clangd] Provide documentation as MarkupContent in signaturehelp

2021-12-09 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 subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

This unifies the behaviour we have in code completion item
documentations and signaturehelp. Providing better line wrapping and detection
of inline code blocks in comments to be renedered appropriately in markdown.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115442

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/CodeComplete.h
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Protocol.h
  clang-tools-extra/clangd/test/signature-help-doc-md.test
  clang-tools-extra/clangd/test/signature-help-doc-pt.test
  clang-tools-extra/clangd/test/signature-help.test
  clang-tools-extra/clangd/unittests/ClangdTests.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang-tools-extra/clangd/unittests/SyncAPI.cpp
  clang-tools-extra/clangd/unittests/SyncAPI.h

Index: clang-tools-extra/clangd/unittests/SyncAPI.h
===
--- clang-tools-extra/clangd/unittests/SyncAPI.h
+++ clang-tools-extra/clangd/unittests/SyncAPI.h
@@ -16,6 +16,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_SYNCAPI_H
 
 #include "ClangdServer.h"
+#include "Protocol.h"
 #include "index/Index.h"
 
 namespace clang {
@@ -32,7 +33,8 @@
 clangd::CodeCompleteOptions Opts);
 
 llvm::Expected runSignatureHelp(ClangdServer &Server,
-   PathRef File, Position Pos);
+   PathRef File, Position Pos,
+   MarkupKind DocumentationFormat);
 
 llvm::Expected>
 runLocateSymbolAt(ClangdServer &Server, PathRef File, Position Pos);
Index: clang-tools-extra/clangd/unittests/SyncAPI.cpp
===
--- clang-tools-extra/clangd/unittests/SyncAPI.cpp
+++ clang-tools-extra/clangd/unittests/SyncAPI.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "SyncAPI.h"
+#include "Protocol.h"
 #include "index/Index.h"
 
 namespace clang {
@@ -77,9 +78,10 @@
 }
 
 llvm::Expected runSignatureHelp(ClangdServer &Server,
-   PathRef File, Position Pos) {
+   PathRef File, Position Pos,
+   MarkupKind DocumentationFormat) {
   llvm::Optional> Result;
-  Server.signatureHelp(File, Pos, capture(Result));
+  Server.signatureHelp(File, Pos, DocumentationFormat, capture(Result));
   return std::move(*Result);
 }
 
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -24,6 +24,7 @@
 #include "support/Threading.h"
 #include "clang/Sema/CodeCompleteConsumer.h"
 #include "clang/Tooling/CompilationDatabase.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Testing/Support/Annotations.h"
@@ -1171,8 +1172,10 @@
 MainFileRefs(0u), ScopeRefs(3u;
 }
 
-SignatureHelp signatures(llvm::StringRef Text, Position Point,
- std::vector IndexSymbols = {}) {
+SignatureHelp
+signatures(llvm::StringRef Text, Position Point,
+   std::vector IndexSymbols = {},
+   MarkupKind DocumentationFormat = MarkupKind::PlainText) {
   std::unique_ptr Index;
   if (!IndexSymbols.empty())
 Index = memIndex(IndexSymbols);
@@ -1193,13 +1196,16 @@
 ADD_FAILURE() << "Couldn't build Preamble";
 return {};
   }
-  return signatureHelp(testPath(TU.Filename), Point, *Preamble, Inputs);
+  return signatureHelp(testPath(TU.Filename), Point, *Preamble, Inputs,
+   DocumentationFormat);
 }
 
-SignatureHelp signatures(llvm::StringRef Text,
- std::vector IndexSymbols = {}) {
+SignatureHelp
+signatures(llvm::StringRef Text, std::vector IndexSymbols = {},
+   MarkupKind DocumentationFormat = MarkupKind::PlainText) {
   Annotations Test(Text);
-  return signatures(Test.code(), Test.point(), std::move(IndexSymbols));
+  return signatures(Test.code(), Test.point(), std::move(IndexSymbols),
+DocumentationFormat);
 }
 
 struct ExpectedParameter {
@@ -1216,7 +1222,7 @@
   }
   return true;
 }
-MATCHER_P(SigDoc, Doc, "") { return arg.documentation == Doc; }
+MATCHER_P(Si

[PATCH] D115442: [clangd] Provide documentation as MarkupContent in signaturehelp

2021-12-09 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

I am thinking about a follow-up which will actually change 
`formatDocumentation` to return a `Markup::Document` instead to make sure we 
will have a single way of representing documents throughout features in future.
But that's also what we store in the index, hence will require some 
serialization/deserialization story around it, hence pending some more 
discussions/thinking :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115442

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


Re: RFC: proposing to relax standardization requirements for Clang extensions

2021-12-09 Thread Aaron Ballman via cfe-commits
On Wed, Dec 8, 2021 at 3:48 PM Richard Smith  wrote:
>
> On Tue, 7 Dec 2021 at 13:22, Aaron Ballman via cfe-commits 
>  wrote:
>>
>> tl;dr: our Clang "get involved" page implies that proposed extensions
>> to Clang must also be proposed to a standards committee
>> (https://clang.llvm.org/get_involved.html#criteria). This is a good
>> goal, but is not inclusive or something we enforce with any
>> consistency. I'm proposing to clarify our goals in this space and to
>> better reflect existing practice.
>>
>> Inclusivity Issues:
>> Participating in a standards body is not always free. In fact, it can
>> be quite expensive depending on where you live and which committee you
>> want to join. People who wish to join the C or C++ standards committee
>> as a US national body member have yearly dues in excess of $2000/yr.
>> Each national body sets their membership fees individually and the
>> prices range anywhere from free to $7500+/yr. Also, a standards
>> proposal is not a "one and done" activity and often takes multiple
>> meetings to see even a trivial proposal adopted, but may require
>> multiple years for larger proposals. For example, the [[]] attributes
>> proposal took three years, and _BitInt took over two years with
>> multiple senior-level engineers working on it. Further, there are
>> associated travel costs (in non-pandemic times, anyway) with attending
>> meetings. This is a very significant financial and time burden that I
>> don't think we should require community members to take on.
>>
>> Consistency Issues:
>> We have never been consistent at enforcing this requirement. Here are
>> some examples off the top of my head:
>>
>> * Nullability qualifiers -- never proposed to WG14
>> * VLAs in C++ -- never proposed to WG21
>> * [[]] attributes in C -- proposed to WG14, accepted
>> * _ExtInt -- proposed to WG14, accepted as _BitInt
>> * enums with a fixed underlying type in C -- proposed to WG14 (not by
>> a Clang community member), still not accepted yet
>> * (This list is not intended to be exhaustive.)
>
>
> VLAs in C++, [[]] in C, and enums with a fixed underlying type are all 
> instances of accepting a feature from one language mode in another. For those 
> cases, we do have a relevant standard on which to base our behaviour, so I 
> think those meet the current policy.

I am less convinced of that, but understand where you're coming from.
VLAs in C++ are a great example -- the C standard says what VLAs mean,
but that doesn't cover very important topics like what happens with a
VLA in a constant expression in C++. And the presence of our extension
in this space can constrain WG21 from making future changes in the
area because of fear of breaking our users of the extension.

> Nullability qualifiers are part of the Mac OS language platform's SDK. In 
> this instance, Apple as a platform vendor decided to add an extension, and we 
> as vendors of a compiler that intends to support that platform, implement 
> that extension. I don't think this is all that different from our supporting, 
> say,  to support intel platforms. Or our supporting MS 
> extensions to support the MS platform.

And yet, they impact standardization nonetheless. There was a recent
RFC about nonnull attributes that someone wishes to propose to WG14
and the nullability attributes were a part of that discussion. If a
platform vendor needs to add an extension and that extension is
sufficiently general enough to be standardized, I read the existing
documentation as requiring them to bring it to a standards body.
(Also, it seems to me that platform vendors are the one entity in the
community that generally has the resources necessary for successful
standardization -- it strikes me as odd to make it easier to exempt
them from a requirement here.)

That said, I definitely take your point that there are extensions
vendors need to add for platform support which are not appropriate for
standardization. (e.g., adding new intrinsics to support the platform,
hooks required by the platform, attributes, etc.)

> For _ExtInt, I specifically asked that this be proposed to WG14, and it was 
> (https://reviews.llvm.org/D59105#1422089).
>
> So, I think we may be missing some detail from the policy:
> -- sometimes the relevant organization may be the owner of a platform or 
> architecture we care about supporting, rather than a language

+1

> -- features supported for one language mode or platform are allowed to be 
> supported in other configurations too; if we're paying the cost of supporting 
> a feature, we should get as much benefit from it as we can

I agree with this up to a point. I definitely agree we want to stretch
our value where we can, but I would argue that support in one language
mode is insufficient for automatic inclusion as an extension in
another language mode unless it has a written specification for the
behavior in that other language mode. For example, we don't document
VLA support in C++ in any meaningful way
(https://clang.

[PATCH] D115440: [clang][auto-init] Provide __builtin_alloca_uninitialized

2021-12-09 Thread Alexander Potapenko via Phabricator via cfe-commits
glider added a comment.

In D115440#3182585 , @melver wrote:

> For completeness, also provide __builtin_alloca_with_align_uninitialized().

Please make sure to update the patch description.
(You may have done already, but arc doesn't pull them automatically)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115440

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


[PATCH] D114439: [Annotation] Allow parameter pack expansions in annotate attribute

2021-12-09 Thread Steffen Larsen via Phabricator via cfe-commits
steffenlarsen added inline comments.



Comment at: clang/lib/Parse/ParseDecl.cpp:447
 Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression()));
+
+if (Tok.is(tok::ellipsis)) {

erichkeane wrote:
> steffenlarsen wrote:
> > erichkeane wrote:
> > > steffenlarsen wrote:
> > > > erichkeane wrote:
> > > > > So I was thinking about this overnight... I wonder if this logic is 
> > > > > inverted here?  Aaron can better answer, but I wonder if we should be 
> > > > > instead detecting when we are on the 'last' parameter and it is one 
> > > > > of these `VariadicExprArgument` things (that accept a pack), then 
> > > > > dropping the parser into a loop of:
> > > > > 
> > > > > while (Tok.is(tok::comma)){
> > > > >   Tok.Consume();
> > > > >   ArgExpr = CorrectTypos(ParseAssignmentExpr(...));
> > > > > }
> > > > > // finally, consume the closing paren.
> > > > > 
> > > > > WDYT?
> > > > The parsing of attribute arguments is already this lenient. It does not 
> > > > actually care how many arguments the attribute says it takes (unless it 
> > > > takes a type and then it will only currently supply _one_ argument). It 
> > > > simply consumes as many expressions it can before reaching the end 
> > > > parenthesis, then leaves the attributes to consume them in 
> > > > `clang/lib/Sema/SemaDeclAttr.cpp`.
> > > > As a result we do not need any additional work here to handle variadic 
> > > > arguments, but it also means that we have to introduce the restrictions 
> > > > that we can only allow packs in the last argument and allow only that 
> > > > argument to be variadic, as otherwise we have no way of knowing when 
> > > > and where the packs pass between argument boundaries.
> > > My point is, I don't think THIS function should be handling the ellipsis, 
> > > the expression parsing functions we send the parsing of each component 
> > > off to should do that.
> > > 
> > > We unfortunately cannot move the entirety of this parsing section to do 
> > > that, since 'identifier'/'type', and 'Function' argument types end up 
> > > needing special handling, but it would be nice if our 'expr' types would 
> > > all be able to do this, and I suggested earlier that we could start with 
> > > the `VariadicExprArgument` to make this an easier patch that didn't have 
> > > to deal with the issues that come with that.
> > > 
> > > That said, it would be nice if we could get CLOSE to that.
> > Sorry. I am still not sure I am following. Do you mean the consumption of 
> > pack expressions should be moved into the expression parsing so other 
> > places (not just attributes) would accept it? If so, I am not opposed to 
> > the idea though I have no idea which expressions these would be nor the 
> > full implications of such a change. For these we at least have the 
> > isolation of having to explicitly support the packs in the given attributes.
> I'm saying the other expression parsers should ALREADY properly handle packs, 
> and we should just use those.
I think I see what you mean. There is the `Parser::ParseExpressionList` which 
may fit the bill, though it seems to also accept initializer lists. But since 
it is an expression the attributes can decide if it is a valid expression for 
them, so maybe that is not a problem?


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

https://reviews.llvm.org/D114439

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


[PATCH] D114439: [Annotation] Allow parameter pack expansions in annotate attribute

2021-12-09 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Parse/ParseDecl.cpp:447
 Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression()));
+
+if (Tok.is(tok::ellipsis)) {

steffenlarsen wrote:
> erichkeane wrote:
> > steffenlarsen wrote:
> > > erichkeane wrote:
> > > > steffenlarsen wrote:
> > > > > erichkeane wrote:
> > > > > > So I was thinking about this overnight... I wonder if this logic is 
> > > > > > inverted here?  Aaron can better answer, but I wonder if we should 
> > > > > > be instead detecting when we are on the 'last' parameter and it is 
> > > > > > one of these `VariadicExprArgument` things (that accept a pack), 
> > > > > > then dropping the parser into a loop of:
> > > > > > 
> > > > > > while (Tok.is(tok::comma)){
> > > > > >   Tok.Consume();
> > > > > >   ArgExpr = CorrectTypos(ParseAssignmentExpr(...));
> > > > > > }
> > > > > > // finally, consume the closing paren.
> > > > > > 
> > > > > > WDYT?
> > > > > The parsing of attribute arguments is already this lenient. It does 
> > > > > not actually care how many arguments the attribute says it takes 
> > > > > (unless it takes a type and then it will only currently supply _one_ 
> > > > > argument). It simply consumes as many expressions it can before 
> > > > > reaching the end parenthesis, then leaves the attributes to consume 
> > > > > them in `clang/lib/Sema/SemaDeclAttr.cpp`.
> > > > > As a result we do not need any additional work here to handle 
> > > > > variadic arguments, but it also means that we have to introduce the 
> > > > > restrictions that we can only allow packs in the last argument and 
> > > > > allow only that argument to be variadic, as otherwise we have no way 
> > > > > of knowing when and where the packs pass between argument boundaries.
> > > > My point is, I don't think THIS function should be handling the 
> > > > ellipsis, the expression parsing functions we send the parsing of each 
> > > > component off to should do that.
> > > > 
> > > > We unfortunately cannot move the entirety of this parsing section to do 
> > > > that, since 'identifier'/'type', and 'Function' argument types end up 
> > > > needing special handling, but it would be nice if our 'expr' types 
> > > > would all be able to do this, and I suggested earlier that we could 
> > > > start with the `VariadicExprArgument` to make this an easier patch that 
> > > > didn't have to deal with the issues that come with that.
> > > > 
> > > > That said, it would be nice if we could get CLOSE to that.
> > > Sorry. I am still not sure I am following. Do you mean the consumption of 
> > > pack expressions should be moved into the expression parsing so other 
> > > places (not just attributes) would accept it? If so, I am not opposed to 
> > > the idea though I have no idea which expressions these would be nor the 
> > > full implications of such a change. For these we at least have the 
> > > isolation of having to explicitly support the packs in the given 
> > > attributes.
> > I'm saying the other expression parsers should ALREADY properly handle 
> > packs, and we should just use those.
> I think I see what you mean. There is the `Parser::ParseExpressionList` which 
> may fit the bill, though it seems to also accept initializer lists. But since 
> it is an expression the attributes can decide if it is a valid expression for 
> them, so maybe that is not a problem?
Hmm... I don't have a good idea of that, Aaron has better visibility into that 
sort of thing.

Part of the advantage to doing it the way I suggest is that it ends up being a 
single call (that is, the parser should parse the commas!), so we should only 
have to consume the closing paren.


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

https://reviews.llvm.org/D114439

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


[PATCH] D115225: [X86][MS-InlineAsm] Make the constraint *m to be simple place holder

2021-12-09 Thread Kan Shengchen via Phabricator via cfe-commits
skan accepted this revision.
skan added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115225

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


[PATCH] D115231: [Clang] Add __builtin_reduce_xor

2021-12-09 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 393142.
junaire added a comment.

Fix wrong code logic.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115231

Files:
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-reduction-math.c
  clang/test/Sema/builtins-reduction-math.c

Index: clang/test/Sema/builtins-reduction-math.c
===
--- clang/test/Sema/builtins-reduction-math.c
+++ clang/test/Sema/builtins-reduction-math.c
@@ -35,3 +35,20 @@
   i = __builtin_reduce_min(i);
   // expected-error@-1 {{1st argument must be a vector type (was 'int')}}
 }
+
+void test_builtin_reduce_xor(int i, float4 v, int3 iv) {
+  struct Foo s = __builtin_reduce_xor(iv);
+  // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'int'}}
+
+  i = __builtin_reduce_xor();
+  // expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
+
+  i = __builtin_reduce_xor(iv, iv);
+  // expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
+
+  i = __builtin_reduce_xor(i);
+  // expected-error@-1 {{1st argument must be a vector of integers (was 'int')}}
+
+  i = __builtin_reduce_xor(v);
+  // expected-error@-1 {{1st argument must be a vector of integers (was 'float4' (vector of 4 'float' values))}}
+}
Index: clang/test/CodeGen/builtins-reduction-math.c
===
--- clang/test/CodeGen/builtins-reduction-math.c
+++ clang/test/CodeGen/builtins-reduction-math.c
@@ -57,3 +57,14 @@
   const si8 cvi1 = vi1;
   unsigned long long r5 = __builtin_reduce_min(cvi1);
 }
+
+void test_builtin_reduce_xor(si8 vi1, u4 vu1) {
+
+  // CHECK:  [[VI1:%.+]] = load <8 x i16>, <8 x i16>* %vi1.addr, align 16
+  // CHECK-NEXT: call i16 @llvm.vector.reduce.xor.v8i16(<8 x i16> [[VI1]])
+  short r2 = __builtin_reduce_xor(vi1);
+
+  // CHECK:  [[VU1:%.+]] = load <4 x i32>, <4 x i32>* %vu1.addr, align 16
+  // CHECK-NEXT: call i32 @llvm.vector.reduce.xor.v4i32(<4 x i32> [[VU1]])
+  unsigned r3 = __builtin_reduce_xor(vu1);
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -2108,10 +2108,38 @@
   return ExprError();
 break;
   case Builtin::BI__builtin_reduce_max:
-  case Builtin::BI__builtin_reduce_min:
-if (SemaBuiltinReduceMath(TheCall))
+  case Builtin::BI__builtin_reduce_min: {
+if (SemaBuiltinReduceMathPreCheck(TheCall))
   return ExprError();
+
+const auto *Arg = TheCall->getArg(0);
+const VectorType *TyA = Arg->getType()->getAs();
+if (!TyA) {
+  Diag(Arg->getBeginLoc(), diag::err_builtin_invalid_arg_type)
+  << 1 << /* vector ty*/ 4 << Arg->getType();
+  return ExprError();
+}
+
+TheCall->setType(TyA->getElementType());
+break;
+  }
+
+  // __builtin_reduce_xor supports vector of integers only.
+  case Builtin::BI__builtin_reduce_xor: {
+if (SemaBuiltinReduceMathPreCheck(TheCall))
+  return ExprError();
+
+const auto *Arg = TheCall->getArg(0);
+const VectorType *TyA = Arg->getType()->getAs();
+if (!TyA || !TyA->getElementType()->isIntegerType()) {
+  Diag(Arg->getBeginLoc(), diag::err_builtin_invalid_arg_type)
+  << 1 /* vector of integers */ << 5 << Arg->getType();
+  return ExprError();
+}
+TheCall->setType(TyA->getElementType());
 break;
+  }
+
   case Builtin::BI__builtin_matrix_transpose:
 return SemaBuiltinMatrixTranspose(TheCall, TheCallResult);
 
@@ -16752,7 +16780,7 @@
   return false;
 }
 
-bool Sema::SemaBuiltinReduceMath(CallExpr *TheCall) {
+bool Sema::SemaBuiltinReduceMathPreCheck(CallExpr *TheCall) {
   if (checkArgCount(*this, TheCall, 1))
 return true;
 
@@ -16761,14 +16789,6 @@
 return true;
 
   TheCall->setArg(0, A.get());
-  const VectorType *TyA = A.get()->getType()->getAs();
-  if (!TyA) {
-SourceLocation ArgLoc = TheCall->getArg(0)->getBeginLoc();
-return Diag(ArgLoc, diag::err_builtin_invalid_arg_type)
-   << 1 << /* vector ty*/ 4 << A.get()->getType();
-  }
-
-  TheCall->setType(TyA->getElementType());
   return false;
 }
 
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -3204,6 +3204,13 @@
 return RValue::get(Result);
   }
 
+  case Builtin::BI__builtin_reduce_xor: {
+Value *Op0 = EmitScalarExpr(E->getArg(0));
+Value *Result = Builder.CreateUnaryIntrinsic(
+llvm::Intrinsic::vector_reduce_xor, Op0, nullptr, "rdx.xor");
+return RValue::get(Result);
+  }
+
   case Builtin

[PATCH] D115235: [clang][dataflow] Implement a basic algorithm for dataflow analysis

2021-12-09 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev updated this revision to Diff 393156.
sgatev added a comment.

Declare transferBlock in the header.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115235

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/include/clang/Analysis/FlowSensitive/DataflowWorklist.h
  clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
  clang/unittests/Analysis/CMakeLists.txt
  clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
  clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- /dev/null
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -0,0 +1,148 @@
+//===- unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/AST/Decl.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Analysis/CFG.h"
+#include "clang/Analysis/FlowSensitive/DataflowAnalysis.h"
+#include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
+#include "clang/Analysis/FlowSensitive/DataflowLattice.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/StringRef.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+
+using namespace clang;
+using namespace dataflow;
+
+template 
+class AnalysisCallback : public ast_matchers::MatchFinder::MatchCallback {
+public:
+  void run(const ast_matchers::MatchFinder::MatchResult &Result) override {
+assert(BlockStates.empty());
+
+const auto *Func = Result.Nodes.getNodeAs("func");
+assert(Func != nullptr);
+
+Stmt *Body = Func->getBody();
+assert(Body != nullptr);
+
+// FIXME: Consider providing a utility that returns a `CFG::BuildOptions`
+// which is a good default for most clients or a utility that directly
+// builds the `CFG` using default `CFG::BuildOptions`.
+CFG::BuildOptions Options;
+Options.AddImplicitDtors = true;
+Options.AddTemporaryDtors = true;
+Options.setAllAlwaysAdd();
+
+std::unique_ptr Cfg =
+CFG::buildCFG(nullptr, Body, Result.Context, Options);
+assert(Cfg != nullptr);
+
+AnalysisT Analysis(*Result.Context);
+Environment Env;
+BlockStates = runDataflowAnalysis(*Cfg, Analysis, Env);
+  }
+
+  std::vector<
+  llvm::Optional>>
+  BlockStates;
+};
+
+template 
+std::vector>>
+runAnalysis(llvm::StringRef Code) {
+  std::unique_ptr AST =
+  tooling::buildASTFromCodeWithArgs(Code, {"-std=c++11"});
+
+  AnalysisCallback Callback;
+  ast_matchers::MatchFinder Finder;
+  Finder.addMatcher(
+  ast_matchers::functionDecl(ast_matchers::hasName("target")).bind("func"),
+  &Callback);
+  Finder.matchAST(AST->getASTContext());
+
+  return Callback.BlockStates;
+}
+
+class NoopLattice {
+public:
+  bool operator==(const NoopLattice &) const { return true; }
+
+  LatticeJoinEffect join(const NoopLattice &) {
+return LatticeJoinEffect::Unchanged;
+  }
+};
+
+class NoopAnalysis : public DataflowAnalysis {
+public:
+  NoopAnalysis(ASTContext &Context)
+  : DataflowAnalysis(Context) {}
+
+  static NoopLattice initialElement() { return {}; }
+
+  NoopLattice transfer(const Stmt *S, const NoopLattice &E, Environment &Env) {
+return {};
+  }
+};
+
+TEST(DataflowAnalysisTest, NoopAnalysis) {
+  auto BlockStates = runAnalysis(R"(
+void target() {}
+  )");
+  EXPECT_EQ(BlockStates.size(), 2u);
+  EXPECT_TRUE(BlockStates[0].hasValue());
+  EXPECT_TRUE(BlockStates[1].hasValue());
+}
+
+struct NonConvergingLattice {
+  int State;
+
+  bool operator==(const NonConvergingLattice &Other) const {
+return State == Other.State;
+  }
+
+  LatticeJoinEffect join(const NonConvergingLattice &Other) {
+if (Other.State == 0)
+  return LatticeJoinEffect::Unchanged;
+State += Other.State;
+return LatticeJoinEffect::Changed;
+  }
+};
+
+class NonConvergingAnalysis
+: public DataflowAnalysis {
+public:
+  explicit NonConvergingAnalysis(ASTContext &Context)
+  : DataflowAnalysis(Context) {
+  }
+
+  static NonConvergingLattice initialElement() { return {0}; }
+
+  NonConvergingLattice transfer(const Stmt *S, const NonConvergingLattice &E,
+Environment &Env) {
+return {E.State + 1};
+  }
+};
+
+TEST(DataflowAnalysisTest, NonConvergingAnalysis) {
+  auto BlockStates = runAnalysis(R"(
+void target() {
+  while(true) {}
+}
+  )"

[PATCH] D115235: [clang][dataflow] Implement a basic algorithm for dataflow analysis

2021-12-09 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev marked 4 inline comments as done.
sgatev added inline comments.



Comment at: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp:31
+/// states of its predecessor basic blocks.
+TypeErasedDataflowAnalysisState computeBlockInputState(
+std::vector> &BlockStates,

ymandel wrote:
> should this be declared in the header? If not, please mark static.
Marked it as static.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115235

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


[PATCH] D114413: [OpenMPIRBuilder] Implement static-chunked workshare-loop schedules.

2021-12-09 Thread Peixin Qiao via Phabricator via cfe-commits
peixin added a comment.

Can you check the following example by applying this patch on fir-dev?

  program main
integer :: i, N = 10
real :: x = 0
  
!$omp do schedule(static, 2)
do i = 3, N
  x = x + i
end do
!$omp end do
  
print *, x
  end

Test running result:

  $ gfortran test.f90 -fopenmp && ./a.out
 52.000
  $ bbc -fopenmp -emit-fir test.f90
  $ tco test.mlir -o test.ll
  $ clang++ -lFortran_main -lFortranRuntime -lFortranDecimal -lomp -o a.out 
test.ll
  $ ./a.out
   7.

When you change "schedule(static, 2)" into "schedule(static, 1)", the running 
result is 3.0.




Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:1676
+  Value *SrcLoc = getOrCreateIdent(getOrCreateSrcLocStr(DL));
+  Value *ThreadNum = getOrCreateThreadID(SrcLoc);
+  Constant *SchedulingType = ConstantInt::get(

Can you move "Value *ThreadNum = getOrCreateThreadID(SrcLoc);" after 
"Builder.CreateStore(One, PStride);" in order that the "kmpc_global_thread_num" 
call is right before the "kmpc_static_init" call to keep consistence with 
others?



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:1765
+  switch (SchedKind) {
+  case llvm::omp::ScheduleKind ::OMP_SCHEDULE_Default:
+assert(!ChunkSize && "No chunk size with default schedule (which for clang 
"

Please remove the space between "ScheduleKind" and "OMP_SCHEDULE_Default"? Also 
for the following switch cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114413

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


[PATCH] D115346: [clang][deps] Squash caches for original and minimized files

2021-12-09 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 393159.
jansvoboda11 added a comment.

Introduce `EntryRef`, handle delayed minimization.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115346

Files:
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
  clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
  clang/unittests/Tooling/DependencyScannerTest.cpp
  llvm/include/llvm/Support/VirtualFileSystem.h
  llvm/lib/Support/VirtualFileSystem.cpp

Index: llvm/lib/Support/VirtualFileSystem.cpp
===
--- llvm/lib/Support/VirtualFileSystem.cpp
+++ llvm/lib/Support/VirtualFileSystem.cpp
@@ -75,6 +75,12 @@
 : Name(Name.str()), UID(UID), MTime(MTime), User(User), Group(Group),
   Size(Size), Type(Type), Perms(Perms) {}
 
+Status Status::copyWithNewSize(const Status &In, uint64_t NewSize) {
+  return Status(In.getName(), In.getUniqueID(), In.getLastModificationTime(),
+In.getUser(), In.getGroup(), NewSize, In.getType(),
+In.getPermissions());
+}
+
 Status Status::copyWithNewName(const Status &In, const Twine &NewName) {
   return Status(NewName, In.getUniqueID(), In.getLastModificationTime(),
 In.getUser(), In.getGroup(), In.getSize(), In.getType(),
Index: llvm/include/llvm/Support/VirtualFileSystem.h
===
--- llvm/include/llvm/Support/VirtualFileSystem.h
+++ llvm/include/llvm/Support/VirtualFileSystem.h
@@ -64,6 +64,8 @@
  uint64_t Size, llvm::sys::fs::file_type Type,
  llvm::sys::fs::perms Perms);
 
+  /// Get a copy of a Status with a different size.
+  static Status copyWithNewSize(const Status &In, uint64_t NewSize);
   /// Get a copy of a Status with a different name.
   static Status copyWithNewName(const Status &In, const Twine &NewName);
   static Status copyWithNewName(const llvm::sys::fs::file_status &In,
Index: clang/unittests/Tooling/DependencyScannerTest.cpp
===
--- clang/unittests/Tooling/DependencyScannerTest.cpp
+++ clang/unittests/Tooling/DependencyScannerTest.cpp
@@ -205,32 +205,46 @@
 }
 
 namespace dependencies {
-TEST(DependencyScanningFilesystem, IgnoredFilesHaveSeparateCache) {
+TEST(DependencyScanningFilesystem, IgnoredFilesAreCachedSeparately1) {
   auto VFS = llvm::makeIntrusiveRefCnt();
-  VFS->addFile("/mod.h", 0, llvm::MemoryBuffer::getMemBuffer("// hi there!\n"));
+  VFS->addFile("/mod.h", 0,
+   llvm::MemoryBuffer::getMemBuffer("#include \n"
+"// hi there!\n"));
 
   DependencyScanningFilesystemSharedCache SharedCache;
   auto Mappings = std::make_unique();
   DependencyScanningWorkerFilesystem DepFS(SharedCache, VFS, Mappings.get());
 
+  DepFS.enableMinimizationOfAllFiles(); // Let's be explicit for clarity.
   auto StatusMinimized0 = DepFS.status("/mod.h");
   DepFS.disableMinimization("/mod.h");
   auto StatusFull1 = DepFS.status("/mod.h");
-  DepFS.enableMinimizationOfAllFiles();
-
-  auto StatusMinimized2 = DepFS.status("/mod.h");
-  DepFS.disableMinimization("/mod.h");
-  auto StatusFull3 = DepFS.status("/mod.h");
 
   EXPECT_TRUE(StatusMinimized0);
-  EXPECT_EQ(StatusMinimized0->getSize(), 0u);
   EXPECT_TRUE(StatusFull1);
-  EXPECT_EQ(StatusFull1->getSize(), 13u);
+  EXPECT_EQ(StatusMinimized0->getSize(), 17u);
+  EXPECT_EQ(StatusFull1->getSize(), 30u);
+}
+
+TEST(DependencyScanningFilesystem, IgnoredFilesAreCachedSeparately2) {
+  auto VFS = llvm::makeIntrusiveRefCnt();
+  VFS->addFile("/mod.h", 0,
+   llvm::MemoryBuffer::getMemBuffer("#include \n"
+"// hi there!\n"));
+
+  DependencyScanningFilesystemSharedCache SharedCache;
+  auto Mappings = std::make_unique();
+  DependencyScanningWorkerFilesystem DepFS(SharedCache, VFS, Mappings.get());
+
+  DepFS.disableMinimization("/mod.h");
+  auto StatusFull0 = DepFS.status("/mod.h");
+  DepFS.enableMinimizationOfAllFiles();
+  auto StatusMinimized1 = DepFS.status("/mod.h");
 
-  EXPECT_TRUE(StatusMinimized2);
-  EXPECT_EQ(StatusMinimized2->getSize(), 0u);
-  EXPECT_TRUE(StatusFull3);
-  EXPECT_EQ(StatusFull3->getSize(), 13u);
+  EXPECT_TRUE(StatusFull0);
+  EXPECT_TRUE(StatusMinimized1);
+  EXPECT_EQ(StatusFull0->getSize(), 30u);
+  EXPECT_EQ(StatusMinimized1->getSize(), 17u);
 }
 
 } // end namespace dependencies
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -16,8 +16,9 @@
 using namespace tooling;
 using namespace dependencies;
 
-CachedFileSystemEntry CachedFileSystemEntry::createFile

[PATCH] D115283: [AMDGPU] Set "amdgpu_hostcall" module flag if an AMDGPU function has calls to device lib functions that use hostcalls.

2021-12-09 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In D115283#3181128 , @JonChesterfield 
wrote:

> Not exactly that. The weak symbol isn't the function name, as that gets 
> renamed or inlined.

We discussed this before. As code object ABI use runtime metadata to represent 
hostcall_buffer, we need to check whether hostcall is needed by IR.

This approach will require checking asm instructions inside a function to 
determine whether this function requires hostcall. It is hacking for IR 
representation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115283

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


[PATCH] D115346: [clang][deps] Squash caches for original and minimized files

2021-12-09 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 393162.
jansvoboda11 added a comment.

Prevent potential data races by wrapping access to 
`Entry.getPPSkippedRangeMapping()` in `if (Entry.isMinimized())`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115346

Files:
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
  clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
  clang/unittests/Tooling/DependencyScannerTest.cpp
  llvm/include/llvm/Support/VirtualFileSystem.h
  llvm/lib/Support/VirtualFileSystem.cpp

Index: llvm/lib/Support/VirtualFileSystem.cpp
===
--- llvm/lib/Support/VirtualFileSystem.cpp
+++ llvm/lib/Support/VirtualFileSystem.cpp
@@ -75,6 +75,12 @@
 : Name(Name.str()), UID(UID), MTime(MTime), User(User), Group(Group),
   Size(Size), Type(Type), Perms(Perms) {}
 
+Status Status::copyWithNewSize(const Status &In, uint64_t NewSize) {
+  return Status(In.getName(), In.getUniqueID(), In.getLastModificationTime(),
+In.getUser(), In.getGroup(), NewSize, In.getType(),
+In.getPermissions());
+}
+
 Status Status::copyWithNewName(const Status &In, const Twine &NewName) {
   return Status(NewName, In.getUniqueID(), In.getLastModificationTime(),
 In.getUser(), In.getGroup(), In.getSize(), In.getType(),
Index: llvm/include/llvm/Support/VirtualFileSystem.h
===
--- llvm/include/llvm/Support/VirtualFileSystem.h
+++ llvm/include/llvm/Support/VirtualFileSystem.h
@@ -64,6 +64,8 @@
  uint64_t Size, llvm::sys::fs::file_type Type,
  llvm::sys::fs::perms Perms);
 
+  /// Get a copy of a Status with a different size.
+  static Status copyWithNewSize(const Status &In, uint64_t NewSize);
   /// Get a copy of a Status with a different name.
   static Status copyWithNewName(const Status &In, const Twine &NewName);
   static Status copyWithNewName(const llvm::sys::fs::file_status &In,
Index: clang/unittests/Tooling/DependencyScannerTest.cpp
===
--- clang/unittests/Tooling/DependencyScannerTest.cpp
+++ clang/unittests/Tooling/DependencyScannerTest.cpp
@@ -205,32 +205,46 @@
 }
 
 namespace dependencies {
-TEST(DependencyScanningFilesystem, IgnoredFilesHaveSeparateCache) {
+TEST(DependencyScanningFilesystem, IgnoredFilesAreCachedSeparately1) {
   auto VFS = llvm::makeIntrusiveRefCnt();
-  VFS->addFile("/mod.h", 0, llvm::MemoryBuffer::getMemBuffer("// hi there!\n"));
+  VFS->addFile("/mod.h", 0,
+   llvm::MemoryBuffer::getMemBuffer("#include \n"
+"// hi there!\n"));
 
   DependencyScanningFilesystemSharedCache SharedCache;
   auto Mappings = std::make_unique();
   DependencyScanningWorkerFilesystem DepFS(SharedCache, VFS, Mappings.get());
 
+  DepFS.enableMinimizationOfAllFiles(); // Let's be explicit for clarity.
   auto StatusMinimized0 = DepFS.status("/mod.h");
   DepFS.disableMinimization("/mod.h");
   auto StatusFull1 = DepFS.status("/mod.h");
-  DepFS.enableMinimizationOfAllFiles();
-
-  auto StatusMinimized2 = DepFS.status("/mod.h");
-  DepFS.disableMinimization("/mod.h");
-  auto StatusFull3 = DepFS.status("/mod.h");
 
   EXPECT_TRUE(StatusMinimized0);
-  EXPECT_EQ(StatusMinimized0->getSize(), 0u);
   EXPECT_TRUE(StatusFull1);
-  EXPECT_EQ(StatusFull1->getSize(), 13u);
+  EXPECT_EQ(StatusMinimized0->getSize(), 17u);
+  EXPECT_EQ(StatusFull1->getSize(), 30u);
+}
+
+TEST(DependencyScanningFilesystem, IgnoredFilesAreCachedSeparately2) {
+  auto VFS = llvm::makeIntrusiveRefCnt();
+  VFS->addFile("/mod.h", 0,
+   llvm::MemoryBuffer::getMemBuffer("#include \n"
+"// hi there!\n"));
+
+  DependencyScanningFilesystemSharedCache SharedCache;
+  auto Mappings = std::make_unique();
+  DependencyScanningWorkerFilesystem DepFS(SharedCache, VFS, Mappings.get());
+
+  DepFS.disableMinimization("/mod.h");
+  auto StatusFull0 = DepFS.status("/mod.h");
+  DepFS.enableMinimizationOfAllFiles();
+  auto StatusMinimized1 = DepFS.status("/mod.h");
 
-  EXPECT_TRUE(StatusMinimized2);
-  EXPECT_EQ(StatusMinimized2->getSize(), 0u);
-  EXPECT_TRUE(StatusFull3);
-  EXPECT_EQ(StatusFull3->getSize(), 13u);
+  EXPECT_TRUE(StatusFull0);
+  EXPECT_TRUE(StatusMinimized1);
+  EXPECT_EQ(StatusFull0->getSize(), 30u);
+  EXPECT_EQ(StatusMinimized1->getSize(), 17u);
 }
 
 } // end namespace dependencies
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -16,8 +16,9 @@
 using namespace tooling;
 using namespace depen

[clang] ab28cb1 - Revert "[xray] add support for hexagon"

2021-12-09 Thread Brian Cain via cfe-commits

Author: Brian Cain
Date: 2021-12-09T07:30:40-08:00
New Revision: ab28cb1c5c4dc7181fae3d47f0601982996739db

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

LOG: Revert "[xray] add support for hexagon"

This reverts commit 543a9ad7c460bb8d641b1b7c67bbc032c9bfdb45.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Hexagon.cpp
clang/lib/Driver/XRayArgs.cpp
compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
compiler-rt/lib/xray/CMakeLists.txt
compiler-rt/lib/xray/xray_interface.cpp
compiler-rt/lib/xray/xray_tsc.h
llvm/lib/CodeGen/XRayInstrumentation.cpp
llvm/lib/Target/Hexagon/HexagonAsmPrinter.cpp
llvm/lib/Target/Hexagon/HexagonAsmPrinter.h
llvm/lib/Target/Hexagon/HexagonInstrInfo.cpp
llvm/lib/Target/Hexagon/HexagonInstrInfo.h
llvm/lib/Target/Hexagon/HexagonMCInstLower.cpp
llvm/lib/Target/Hexagon/HexagonSubtarget.h
llvm/lib/Target/Hexagon/HexagonVLIWPacketizer.cpp

Removed: 
compiler-rt/lib/xray/xray_hexagon.cpp
compiler-rt/lib/xray/xray_trampoline_hexagon.S
llvm/test/CodeGen/Hexagon/xray-pred-ret.ll
llvm/test/CodeGen/Hexagon/xray.ll



diff  --git a/clang/lib/Driver/ToolChains/Hexagon.cpp 
b/clang/lib/Driver/ToolChains/Hexagon.cpp
index 2ce7904ecc40d..18270818d1589 100644
--- a/clang/lib/Driver/ToolChains/Hexagon.cpp
+++ b/clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -226,7 +226,6 @@ constructHexagonLinkArgs(Compilation &C, const JobAction 
&JA,
   StringRef CpuVer = toolchains::HexagonToolChain::GetTargetCPUVersion(Args);
 
   bool NeedsSanitizerDeps = addSanitizerRuntimes(HTC, Args, CmdArgs);
-  bool NeedsXRayDeps = addXRayRuntime(HTC, Args, CmdArgs);
 
   
//
   // Silence warnings for various options
@@ -298,8 +297,6 @@ constructHexagonLinkArgs(Compilation &C, const JobAction 
&JA,
 
 CmdArgs.push_back("-lunwind");
   }
-  if (NeedsXRayDeps)
-linkXRayRuntimeDeps(HTC, CmdArgs);
 
   CmdArgs.push_back("-lclang_rt.builtins-hexagon");
   CmdArgs.push_back("-lc");

diff  --git a/clang/lib/Driver/XRayArgs.cpp b/clang/lib/Driver/XRayArgs.cpp
index 63b575178bd12..b44509ad3b881 100644
--- a/clang/lib/Driver/XRayArgs.cpp
+++ b/clang/lib/Driver/XRayArgs.cpp
@@ -40,7 +40,6 @@ XRayArgs::XRayArgs(const ToolChain &TC, const ArgList &Args) {
 case llvm::Triple::x86_64:
 case llvm::Triple::arm:
 case llvm::Triple::aarch64:
-case llvm::Triple::hexagon:
 case llvm::Triple::ppc64le:
 case llvm::Triple::mips:
 case llvm::Triple::mipsel:

diff  --git a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake 
b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
index 3e86cf63c789b..45226b4158d74 100644
--- a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
+++ b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
@@ -73,8 +73,7 @@ set(ALL_SCUDO_STANDALONE_SUPPORTED_ARCH ${X86} ${X86_64} 
${ARM32} ${ARM64}
 if(APPLE)
 set(ALL_XRAY_SUPPORTED_ARCH ${X86_64})
 else()
-set(ALL_XRAY_SUPPORTED_ARCH ${X86_64} ${ARM32} ${ARM64} ${MIPS32} ${MIPS64}
-   powerpc64le ${HEXAGON})
+set(ALL_XRAY_SUPPORTED_ARCH ${X86_64} ${ARM32} ${ARM64} ${MIPS32} ${MIPS64} 
powerpc64le)
 endif()
 set(ALL_SHADOWCALLSTACK_SUPPORTED_ARCH ${ARM64})
 

diff  --git a/compiler-rt/lib/xray/CMakeLists.txt 
b/compiler-rt/lib/xray/CMakeLists.txt
index ca9389747a5ee..204e5b17c7970 100644
--- a/compiler-rt/lib/xray/CMakeLists.txt
+++ b/compiler-rt/lib/xray/CMakeLists.txt
@@ -73,11 +73,6 @@ set(powerpc64le_SOURCES
   xray_trampoline_powerpc64_asm.S
   )
 
-set(hexagon_SOURCES
-  xray_hexagon.cpp
-  xray_trampoline_hexagon.S
-  )
-
 set(XRAY_IMPL_HEADERS
   xray_allocator.h
   xray_basic_flags.h
@@ -116,7 +111,6 @@ set(XRAY_ALL_SOURCE_FILES
   ${x86_64_SOURCES}
   ${arm_SOURCES}
   ${armhf_SOURCES}
-  ${hexagon_SOURCES}
   ${mips_SOURCES}
   ${mipsel_SOURCES}
   ${mips64_SOURCES}

diff  --git a/compiler-rt/lib/xray/xray_hexagon.cpp 
b/compiler-rt/lib/xray/xray_hexagon.cpp
deleted file mode 100644
index 7f127b2b499cd..0
--- a/compiler-rt/lib/xray/xray_hexagon.cpp
+++ /dev/null
@@ -1,168 +0,0 @@
-//===-- xray_hexagon.cpp --*- C++ 
---*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-//
-// This file is a part of XRay, a dynamic runtime instrumentation system.
-//
-// Implementation of hexagon-specific routines (32-bit).
-//
-//===--===//
-#include "sanitizer_common/saniti

[PATCH] D115346: [clang][deps] Squash caches for original and minimized files

2021-12-09 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

In D115346#3181198 , @dexonsmith 
wrote:

> This looks really nice.
>
> One problem is that it's subtle to confirm whether it's thread-safe. The 
> local cache access parts of CachedFileSystemEntry lock-free, but the 
> CachedFileSystemEntry might get changed later (i.e., filled in with minimized 
> content). Are accessed fields guaranteed by context not to be the ones that 
> mutate later?

I believe the latest revision is thread-safe (albeit with benign data-races on 
`needsMinimization`). Once a `CachedFileSystemEntry` has been created, only the 
`MinimizedContents` and `PPSkippedRangeMapping` members can be modified (at 
most once, under a lock). Access to those fields only happens in "minimizing" 
contexts.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115346

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


[PATCH] D115283: [AMDGPU] Set "amdgpu_hostcall" module flag if an AMDGPU function has calls to device lib functions that use hostcalls.

2021-12-09 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In D115283#3181109 , @kpyzhov wrote:

> In D115283#3180836 , @yaxunl wrote:
>
>> If we only need to check whether `__ockl_hostcall_internal` exists in the 
>> final module in LLVM codegen to determine whether we need the hostcall 
>> metadata, probably we don't even need a function attribute or even module 
>> flag.
>
> Right, we used to do exactly that (just check at the CodeGen phase if 
> 'ockl_hostcall_internal()' is present in the module), but then it turned out 
> that it does not work with -fgpu-rdc since IPO may rename the 
> 'ockl_hostcall_internal()'.

Sorry I forgot that.

Then I agree that a function attribute seems a better way to represent hostcall 
requirement in IR. It is needed in both source and IR. This avoids checking 
hostcall requirements by function names. It works for all frontends as long as 
they use device libs or mark their own hostcall function with the attribute. It 
also can result in more efficient code object if useless hostcall functions are 
removed by optimizers. Overall it will result in a cleaner IR representation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115283

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


[PATCH] D107275: [Sema] a[x] has type T when a has type T* or T[], even when T is dependent

2021-12-09 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

Sorry for leaving this without any replies, I think the summary you have is 
already of our offline discussion. Let me raise my final concerns, if you think 
we're covered for those and others don't chime in this week I suppose we can 
consider this as good to go.

---

I think 2nd case is fine, as we're unlikely to regress anything by handling 
just LHS. The rare case just won't get the benefits.

---

I am more worried about creating "incorrect" nodes in some cases. I think it 
isn't valid in C/C++ for both LHS && RHS to be pointers/arrays in a subscript 
expression, but I've got no idea about when it's diagnosed in clang and what is 
put into the AST.

If that detection happens before creating any SubscriptExprs (i.e. hitting 
changes in this patch), I guess we're all fine (i.e. we won't generate a node 
with an incorrect `ResultType`).
If it happens after creating these exprs though, now we'll have a bunch of 
expressions with erroneous `ResultType` info which might trip over some things. 
(Worst case scenario, detection completely fails and some code that should've 
been diagnosed as being broken will miscompile instead.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107275

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


[PATCH] D115442: [clangd] Provide documentation as MarkupContent in signaturehelp

2021-12-09 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

Also some related discussions in https://github.com/clangd/clangd/issues/945


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115442

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


[PATCH] D111617: [RISCV] Lazily add RVV C intrinsics.

2021-12-09 Thread Hsiangkai Wang via Phabricator via cfe-commits
HsiangKai added a comment.

In D111617#3175167 , @craig.topper 
wrote:

> In D111617#3060377 , @HsiangKai 
> wrote:
>
>> Although it reduces the header size, this patch will increase the binary 
>> size of clang.
>>
>> Debug build:
>> Before this patch:
>>
>>   textdatabss dec hex
>>  filename
>>   263892591   10838284500232  275231107   1067b183   
>>  clang-14
>>
>> After this patch:
>>
>>   textdatabss dec hex
>>  filename
>>   263909721   12085116500232  276495069   107afadd   
>>  clang-14
>>
>> Release build:
>> Before this patch;
>>
>>   textdatabss dec hex
>>  filename
>>   382952171   8802976410264736481246671   1caf3dcf   
>>  clang-14
>>
>> After this patch:
>>
>>   textdatabss dec hex
>>  filename
>>   387629483   9465258210264736492546801   1d5baaf1   
>>  clang-14
>
> These number indicate the release build is larger than debug. That seems 
> wrong. Am I misreading these numbers?

Indeed, it is strange. The data is got from the first draft version. I have no 
such environment now. I could collect the clang size using the latest 
implementation.
After removing the global static constructor, there is no build time problem 
now.
So, in the latest implementation, we can get the better compile time, smaller 
clang size and acceptable build time.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111617

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


[PATCH] D115153: clang/AMDGPU: Don't set implicit arg attribute to default size

2021-12-09 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield accepted this revision.
JonChesterfield added a comment.
This revision is now accepted and ready to land.

Great, thanks!


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

https://reviews.llvm.org/D115153

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


[PATCH] D115346: [clang][deps] Squash caches for original and minimized files

2021-12-09 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 marked 3 inline comments as done.
jansvoboda11 added inline comments.



Comment at: 
clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h:50-51
+
+  /// Minimize contents of the file.
+  static void minimize(CachedFileSystemEntry &Entry);
 

dexonsmith wrote:
> Might be more natural as a non-static:
> ```
> lang=c++
> void minimize();
> ```
> 
Agreed. I originally wanted to minimize diff of the implementation (by being 
able to refer to `Result` as before), but I'm happy making this an instance 
method.



Comment at: 
clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h:69-75
+  llvm::ErrorOr getContents(bool Minimized) const {
+assert(isValid() && "not initialized");
 if (!MaybeStat)
   return MaybeStat.getError();
 assert(!MaybeStat->isDirectory() && "not a file");
-assert(isValid() && "not initialized");
-return Contents->getBuffer();
+return (Minimized ? MinimizedContents : OriginalContents)->getBuffer();
   }

dexonsmith wrote:
> I *think* this is thread-safe -- since `Minimized` should be the same as when 
> the local cache entry was created -- but it's a bit subtle.
> 
> The problematic case I am worried about:
> - First use in local cache is non-minimized.
> - Creates shared cache entry that's not minimized.
> - Some other local cache wants it to be minimized.
> - Later use in local cache is minimized.
> - Accessing `Minimized` pointer races with the other thread setting it.
> 
> If the local cache is guaranteed to always pass the same value for 
> `Minimized` as when it fist accessed it, then there shouldn't be a problem...
> 
> I wonder if there's a way to make it less subtle?
I extracted the logic into `EntryRef` which now gets returned from the main 
function. It carries the `bool Minimized` bit and makes reasoning about this 
more local. WDYT?



Comment at: 
clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h:106-108
+  std::unique_ptr OriginalContents;
+  std::unique_ptr MinimizedContents;
   PreprocessorSkippedRangeMapping PPSkippedRangeMapping;

dexonsmith wrote:
> I'm finding it a bit subtle detecting if there are races on access / setting 
> of these, but I think it's correct.
> - I think I verified that they are "set once".
> - All the setters are guarded by locks.
> - The first getter per "local" cache is guarded by a lock.
> - Subsequent getters are not.
> 
> The key question: are the subsequent getters ONLY used when the first getter 
> was successful?
> 
> One way to make it more obvious:
> ```
> lang=c++
>   struct ContentWithPPRanges {
> std::unique_ptr Content;
> PreprocessorSkippedRangeMapping PPSkippedRangeMapping;
>   };
> 
> private:
>   // Always accessed,mutated under a lock. Not mutated after they escape.
>   std::unique_ptr Original;
>   std::unique_ptr Minimized;
>   PreprocessorSkippedRangeMapping PPSkippedRangeMapping;
> 
>   // Used in getters. Pointed-at memory immutable after these are set.
>   std::atomic OriginalAccess;
>   std::atomic MinimizedAccess;
>   std::atomic PPRangesAccess;
> ```
> I don't think this is the only approach though.
> 
I think there are no races on the original contents. The pointer is 
unconditionally set on creation of `CachedFileSystemEntry` under a lock that no 
threads get past without having set the pointer (or failing and never accessing 
the pointer).

For minimized contents, the latest revision adds check at the beginning of the 
main function (`needsMinimization`) outside the critical section. There are 
three paths I can think of:
* The check returns `true` in thread A (pointer is `null`), thread A enters 
critical section, minimizes the contents and initializes the pointer.
* The check returns `true` in thread A, but thread B entered the critical 
section, minimized contents and initialized the pointer. When thread A enters 
the critical section, it performs the check again, figures that out and skips 
minimization.
* The check returns `false` and the local cache entry is returned.

So there definitely is a race here, but I believe it's benign. Do you agree? Do 
you think it's worth addressing?



Comment at: 
clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp:253
+  if (Entry.isMinimized()) {
+if (!Entry.getPPSkippedRangeMapping().empty() && PPSkipMappings)
+  (*PPSkipMappings)[Result->Buffer->getBufferStart()] =

Maybe the `isMinimized()` check should be performed internally in `EntryRef` 
when accessing `getPPSkippedRangeMapping()` to make the race avoidance more 
local...



Comment at: 
clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp:189-191
+if (ShouldBeMinimized && CacheEntry.hasOriginalContents() &&
+!CacheEntry.hasMinimizedContents())
+  CachedFileSystemEntry::minimize(CacheEntry);
-

[PATCH] D114421: [asan] Add support for disable_sanitizer_instrumentation attribute

2021-12-09 Thread Alexander Potapenko via Phabricator via cfe-commits
glider updated this revision to Diff 393168.
glider added a comment.

Rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114421

Files:
  clang/docs/AddressSanitizer.rst
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/SanitizerMetadata.cpp
  clang/test/CodeGen/address-safety-attr-flavors.cpp
  clang/test/CodeGen/asan-globals.cpp
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  
llvm/test/Instrumentation/AddressSanitizer/asan-disable-sanitizer-instrumentation.ll

Index: llvm/test/Instrumentation/AddressSanitizer/asan-disable-sanitizer-instrumentation.ll
===
--- /dev/null
+++ llvm/test/Instrumentation/AddressSanitizer/asan-disable-sanitizer-instrumentation.ll
@@ -0,0 +1,47 @@
+; This test checks that we are not instrumenting sanitizer code.
+; RUN: opt < %s -passes='asan-pipeline' -S | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; Function with sanitize_address is instrumented.
+; Function Attrs: nounwind uwtable
+define void @instr_sa(i32* %a) sanitize_address {
+entry:
+  %tmp1 = load i32, i32* %a, align 4
+  %tmp2 = add i32 %tmp1,  1
+  store i32 %tmp2, i32* %a, align 4
+  ret void
+}
+
+; CHECK-LABEL: @instr_sa
+; CHECK: call void @__asan_report_load
+
+
+; Function with disable_sanitizer_instrumentation is not instrumented.
+; Function Attrs: nounwind uwtable
+define void @noinstr_dsi(i32* %a) disable_sanitizer_instrumentation {
+entry:
+  %tmp1 = load i32, i32* %a, align 4
+  %tmp2 = add i32 %tmp1,  1
+  store i32 %tmp2, i32* %a, align 4
+  ret void
+}
+
+; CHECK-LABEL: @noinstr_dsi
+; CHECK-NOT: call void @__asan_report_load
+
+
+; disable_sanitizer_instrumentation takes precedence over sanitize_address.
+; Function Attrs: nounwind uwtable
+define void @noinstr_dsi_sa(i32* %a) disable_sanitizer_instrumentation sanitize_address {
+entry:
+  %tmp1 = load i32, i32* %a, align 4
+  %tmp2 = add i32 %tmp1,  1
+  store i32 %tmp2, i32* %a, align 4
+  ret void
+}
+
+; CHECK-LABEL: @noinstr_dsi_sa
+; CHECK-NOT: call void @__asan_report_load
+
Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -2890,6 +2890,9 @@
   // Leave if the function doesn't need instrumentation.
   if (!F.hasFnAttribute(Attribute::SanitizeAddress)) return FunctionModified;
 
+  if (F.hasFnAttribute(Attribute::DisableSanitizerInstrumentation))
+return FunctionModified;
+
   LLVM_DEBUG(dbgs() << "ASAN instrumenting:\n" << F << "\n");
 
   initializeCallbacks(*F.getParent());
Index: clang/test/CodeGen/asan-globals.cpp
===
--- clang/test/CodeGen/asan-globals.cpp
+++ clang/test/CodeGen/asan-globals.cpp
@@ -10,6 +10,7 @@
 int global;
 int dyn_init_global = global;
 int __attribute__((no_sanitize("address"))) attributed_global;
+int __attribute__((disable_sanitizer_instrumentation)) disable_instrumentation_global;
 int ignorelisted_global;
 
 int __attribute__((section("__DATA, __common"))) sectioned_global; // KASAN - ignore globals in a section
@@ -50,31 +51,33 @@
 // UWTABLE: attributes #[[#ATTR]] = { nounwind uwtable }
 // UWTABLE: ![[#]] = !{i32 7, !"uwtable", i32 1}
 
-// CHECK: !llvm.asan.globals = !{![[EXTRA_GLOBAL:[0-9]+]], ![[GLOBAL:[0-9]+]], ![[DYN_INIT_GLOBAL:[0-9]+]], ![[ATTR_GLOBAL:[0-9]+]], ![[IGNORELISTED_GLOBAL:[0-9]+]], ![[SECTIONED_GLOBAL:[0-9]+]], ![[SPECIAL_GLOBAL:[0-9]+]], ![[STATIC_VAR:[0-9]+]], ![[LITERAL:[0-9]+]]}
+// CHECK: !llvm.asan.globals = !{![[EXTRA_GLOBAL:[0-9]+]], ![[GLOBAL:[0-9]+]], ![[DYN_INIT_GLOBAL:[0-9]+]], ![[ATTR_GLOBAL:[0-9]+]], ![[DISABLE_INSTR_GLOBAL:[0-9]+]], ![[IGNORELISTED_GLOBAL:[0-9]+]], ![[SECTIONED_GLOBAL:[0-9]+]], ![[SPECIAL_GLOBAL:[0-9]+]], ![[STATIC_VAR:[0-9]+]], ![[LITERAL:[0-9]+]]}
 // CHECK: ![[EXTRA_GLOBAL]] = !{{{.*}} ![[EXTRA_GLOBAL_LOC:[0-9]+]], !"extra_global", i1 false, i1 false}
 // CHECK: ![[EXTRA_GLOBAL_LOC]] = !{!"{{.*}}extra-source.cpp", i32 1, i32 5}
 // CHECK: ![[GLOBAL]] = !{{{.*}} ![[GLOBAL_LOC:[0-9]+]], !"global", i1 false, i1 false}
 // CHECK: ![[GLOBAL_LOC]] = !{!"{{.*}}asan-globals.cpp", i32 10, i32 5}
 // CHECK: ![[DYN_INIT_GLOBAL]] = !{{{.*}} ![[DYN_INIT_LOC:[0-9]+]], !"dyn_init_global", i1 true, i1 false}
 // CHECK: ![[DYN_INIT_LOC]] = !{!"{{.*}}asan-globals.cpp", i32 11, i32 5}
-// CHECK: ![[ATTR_GLOBAL]] = !{{{.*}}, null, null, i1 false, i1 true}
-// CHECK: ![[IGNORELISTED_GLOBAL]] = !{{{.*}}, null, null, i1 false, i1 true}
+// CHECK: ![[ATTR_GLOBAL]] = !{{{.*@attributed_global.*}}, null, null, i1 false, i1 true}
+// CHECK: ![[DISABLE_INSTR_GLOBAL]] = !{{{.*@disable_instrumentation_global.*}}, null, null, i1 false, i1 true}
+// CHECK: ![[IGNOREL

[PATCH] D115441: [X86][MS] Add 80bit long double support for Windows

2021-12-09 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

Doesn’t icc also emit code into main to change the FPCW precision control 
field? Is making long double 80 bits useful if you don’t increase the precision 
in hardware?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115441

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


[PATCH] D109215: [RISCV] Fix arch string parsing for multi-character extensions

2021-12-09 Thread Yueh-Ting Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 393174.
eopXD added a comment.

One last rebase before landing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109215

Files:
  clang/test/Driver/riscv-arch.c
  llvm/lib/Support/RISCVISAInfo.cpp


Index: llvm/lib/Support/RISCVISAInfo.cpp
===
--- llvm/lib/Support/RISCVISAInfo.cpp
+++ llvm/lib/Support/RISCVISAInfo.cpp
@@ -72,6 +72,28 @@
   return Ext.consume_front("experimental-");
 }
 
+// This function finds the first character that doesn't belong to a version
+// (e.g. zbe0p93 is extension 'zbe' of version '0p93'). So the function will
+// consume [0-9]*p[0-9]* starting from the backward. An extension name will not
+// end with a digit or the letter 'p', so this function will parse correctly.
+// NOTE: This function is NOT able to take empty strings or strings that only
+// have version numbers and no extension name. It assumes the extension name
+// will be at least more than one character.
+static size_t findFirstNonVersionCharacter(const StringRef &Ext) {
+  if (Ext.size() == 0)
+llvm_unreachable("Already guarded by if-statement in ::parseArchString");
+
+  int Pos = Ext.size() - 1;
+  while (Pos > 0 && isDigit(Ext[Pos]))
+Pos--;
+  if (Pos > 0 && Ext[Pos] == 'p' && isDigit(Ext[Pos - 1])) {
+Pos--;
+while (Pos > 0 && isDigit(Ext[Pos]))
+  Pos--;
+  }
+  return Pos;
+}
+
 struct FindByName {
   FindByName(StringRef Ext) : Ext(Ext){};
   StringRef Ext;
@@ -638,7 +660,7 @@
 
 StringRef Type = getExtensionType(Ext);
 StringRef Desc = getExtensionTypeDesc(Ext);
-auto Pos = Ext.find_if(isDigit);
+size_t Pos = findFirstNonVersionCharacter(Ext) + 1;
 StringRef Name(Ext.substr(0, Pos));
 StringRef Vers(Ext.substr(Pos));
 
Index: clang/test/Driver/riscv-arch.c
===
--- clang/test/Driver/riscv-arch.c
+++ clang/test/Driver/riscv-arch.c
@@ -392,7 +392,7 @@
 
 // RUN: %clang -target riscv32-unknown-elf -march=rv32izbb1p0zbp0p93 
-menable-experimental-extensions -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck 
-check-prefix=RV32-EXPERIMENTAL-ZBB-ZBP-UNDERSCORE %s
-// RV32-EXPERIMENTAL-ZBB-ZBP-UNDERSCORE: error: invalid arch name 
'rv32izbb1p0zbp0p93', multi-character extensions must be separated by 
underscores
+// RV32-EXPERIMENTAL-ZBB-ZBP-UNDERSCORE: error: invalid arch name 
'rv32izbb1p0zbp0p93', unsupported version number 0.93 for extension 'zbb1p0zbp'
 
 // RUN: %clang -target riscv32-unknown-elf -march=rv32izba1p0 
-menable-experimental-extensions -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-ZBA %s


Index: llvm/lib/Support/RISCVISAInfo.cpp
===
--- llvm/lib/Support/RISCVISAInfo.cpp
+++ llvm/lib/Support/RISCVISAInfo.cpp
@@ -72,6 +72,28 @@
   return Ext.consume_front("experimental-");
 }
 
+// This function finds the first character that doesn't belong to a version
+// (e.g. zbe0p93 is extension 'zbe' of version '0p93'). So the function will
+// consume [0-9]*p[0-9]* starting from the backward. An extension name will not
+// end with a digit or the letter 'p', so this function will parse correctly.
+// NOTE: This function is NOT able to take empty strings or strings that only
+// have version numbers and no extension name. It assumes the extension name
+// will be at least more than one character.
+static size_t findFirstNonVersionCharacter(const StringRef &Ext) {
+  if (Ext.size() == 0)
+llvm_unreachable("Already guarded by if-statement in ::parseArchString");
+
+  int Pos = Ext.size() - 1;
+  while (Pos > 0 && isDigit(Ext[Pos]))
+Pos--;
+  if (Pos > 0 && Ext[Pos] == 'p' && isDigit(Ext[Pos - 1])) {
+Pos--;
+while (Pos > 0 && isDigit(Ext[Pos]))
+  Pos--;
+  }
+  return Pos;
+}
+
 struct FindByName {
   FindByName(StringRef Ext) : Ext(Ext){};
   StringRef Ext;
@@ -638,7 +660,7 @@
 
 StringRef Type = getExtensionType(Ext);
 StringRef Desc = getExtensionTypeDesc(Ext);
-auto Pos = Ext.find_if(isDigit);
+size_t Pos = findFirstNonVersionCharacter(Ext) + 1;
 StringRef Name(Ext.substr(0, Pos));
 StringRef Vers(Ext.substr(Pos));
 
Index: clang/test/Driver/riscv-arch.c
===
--- clang/test/Driver/riscv-arch.c
+++ clang/test/Driver/riscv-arch.c
@@ -392,7 +392,7 @@
 
 // RUN: %clang -target riscv32-unknown-elf -march=rv32izbb1p0zbp0p93 -menable-experimental-extensions -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-ZBB-ZBP-UNDERSCORE %s
-// RV32-EXPERIMENTAL-ZBB-ZBP-UNDERSCORE: error: invalid arch name 'rv32izbb1p0zbp0p93', multi-character extensions must be separated by underscores
+// RV32-EXPERIMENTAL-ZBB-ZBP-UNDERSCORE: error: invalid arch name 'rv32izbb1p0zbp0p93', unsupported version number 0

[PATCH] D115283: [AMDGPU] Set "amdgpu_hostcall" module flag if an AMDGPU function has calls to device lib functions that use hostcalls.

2021-12-09 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield added a comment.

In D115283#3182879 , @yaxunl wrote:

> In D115283#3181128 , 
> @JonChesterfield wrote:
>
>> Not exactly that. The weak symbol isn't the function name, as that gets 
>> renamed or inlined.
>
> We discussed this before. As code object ABI use runtime metadata to 
> represent hostcall_buffer, we need to check whether hostcall is needed by IR.
>
> This approach will require checking asm instructions inside a function to 
> determine whether this function requires hostcall. It is hacky for IR 
> representation.

There are two approaches here:
1/ Tag the function using inline asm and totally ignore it in the compiler. 
HSA/etc tests per-code-object if the symbol is present
2/ Tag the function (in source or in compiler), propagate information to llc, 
embed it in msgpack data, HSA/etc tests per-function if the field is present

2/ is somewhat useful if we elide the 8 byte slot of kernarg memory for 
functions that don't use it, otherwise it just increases work done by the 
runtime. Instead of checking for presence of one symbol (a hashtable lookup), 
it's a linear scan through msgpack data. We don't currently elide those 8 
bytes, so right now this is making the compiler more complicated in exchange 
for making the runtime slower.

1/ has the benefit of being dead simple and totally compiler agnostic, and the 
cost of passing the 8 byte hostcall thing to every function in a code object 
that asked for it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115283

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


[PATCH] D112359: [RISCV] Unify depedency check and extension implication parsing logics

2021-12-09 Thread Yueh-Ting Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 393181.
eopXD added a comment.

One last rebase before landing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112359

Files:
  clang/test/CodeGen/RISCV/riscv-metadata.c
  clang/test/CodeGen/RISCV/riscv32-ilp32-ilp32f-ilp32d-abi.c
  clang/test/CodeGen/RISCV/riscv32-ilp32d-abi.c
  clang/test/CodeGen/RISCV/riscv32-ilp32f-ilp32d-abi.c
  clang/test/CodeGen/RISCV/riscv64-lp64-lp64f-lp64d-abi.c
  clang/test/CodeGen/RISCV/riscv64-lp64d-abi.c
  clang/test/CodeGen/RISCV/riscv64-lp64f-lp64d-abi.c
  clang/test/CodeGen/riscv32-ilp32d-abi.cpp
  llvm/include/llvm/Support/RISCVISAInfo.h
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/test/MC/RISCV/attribute-arch-invalid.s
  llvm/test/MC/RISCV/attribute-arch.s

Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -33,47 +33,46 @@
 .attribute arch, "rv32ima2p0_fdc"
 # CHECK: attribute  5, "rv32i2p0_m2p0_a2p0_f2p0_d2p0_c2p0"
 
-.attribute arch, "rv32iv"
+## Experimental extensions require version string to be explicitly specified
+
+.attribute arch, "rv32iv0p10"
 # CHECK: attribute  5, "rv32i2p0_v0p10_zvlsseg0p10"
 
-.attribute arch, "rv32izba"
+.attribute arch, "rv32izba1p0"
 # CHECK: attribute  5, "rv32i2p0_zba1p0"
 
-.attribute arch, "rv32izbb"
+.attribute arch, "rv32izbb1p0"
 # CHECK: attribute  5, "rv32i2p0_zbb1p0"
 
-.attribute arch, "rv32izbc"
+.attribute arch, "rv32izbc1p0"
 # CHECK: attribute  5, "rv32i2p0_zbc1p0"
 
-.attribute arch, "rv32izbe"
+.attribute arch, "rv32izbe0p93"
 # CHECK: attribute  5, "rv32i2p0_zbe0p93"
 
-.attribute arch, "rv32izbf"
+.attribute arch, "rv32izbf0p93"
 # CHECK: attribute  5, "rv32i2p0_zbf0p93"
 
-.attribute arch, "rv32izbm"
+.attribute arch, "rv32izbm0p93"
 # CHECK: attribute  5, "rv32i2p0_zbm0p93"
 
-.attribute arch, "rv32izbp"
+.attribute arch, "rv32izbp0p93"
 # CHECK: attribute  5, "rv32i2p0_zbp0p93"
 
-.attribute arch, "rv32izbr"
+.attribute arch, "rv32izbr0p93"
 # CHECK: attribute  5, "rv32i2p0_zbr0p93"
 
-.attribute arch, "rv32izbs"
+.attribute arch, "rv32izbs1p0"
 # CHECK: attribute  5, "rv32i2p0_zbs1p0"
 
-.attribute arch, "rv32izbt"
+.attribute arch, "rv32izbt0p93"
 # CHECK: attribute  5, "rv32i2p0_zbt0p93"
 
-.attribute arch, "rv32ifzfhmin"
+.attribute arch, "rv32ifzfhmin0p1"
 # CHECK: attribute  5, "rv32i2p0_f2p0_zfhmin0p1"
 
-.attribute arch, "rv32ifzfh"
+.attribute arch, "rv32ifzfh0p1"
 # CHECK: attribute  5, "rv32i2p0_f2p0_zfh0p1_zfhmin0p1"
 
-.attribute arch, "rv32ivzvamo_zvlsseg"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvlsseg0p10"
-
-.attribute arch, "rv32iv_zvamo0p10_zvlsseg"
+.attribute arch, "rv32iv0p10zvamo0p10_zvlsseg0p10"
 # CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvlsseg0p10"
Index: llvm/test/MC/RISCV/attribute-arch-invalid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/attribute-arch-invalid.s
@@ -0,0 +1,48 @@
+## Invalid arch string
+
+# RUN: not llvm-mc -triple riscv32 < %s 2>&1 | FileCheck %s
+# RUN: not llvm-mc -triple riscv64 < %s 2>&1 | FileCheck %s
+
+## Version strings are required for experimental extensions
+
+.attribute arch, "rv32iv"
+# CHECK: error: invalid arch name 'rv32iv', experimental extension requires explicit version number `v`
+
+.attribute arch, "rv32izba"
+# CHECK: error: invalid arch name 'rv32izba', experimental extension requires explicit version number `zba`
+
+.attribute arch, "rv32izbb"
+# CHECK: error: invalid arch name 'rv32izbb', experimental extension requires explicit version number `zbb`
+
+.attribute arch, "rv32izbc"
+# CHECK: error: invalid arch name 'rv32izbc', experimental extension requires explicit version number `zbc`
+
+.attribute arch, "rv32izbe"
+# CHECK:  error: invalid arch name 'rv32izbe', experimental extension requires explicit version number `zbe`
+
+.attribute arch, "rv32izbf"
+# CHECK: error: invalid arch name 'rv32izbf', experimental extension requires explicit version number `zbf`
+
+.attribute arch, "rv32izbm"
+# CHECK: error: invalid arch name 'rv32izbm', experimental extension requires explicit version number `zbm`
+
+.attribute arch, "rv32izbp"
+# CHECK: error: invalid arch name 'rv32izbp', experimental extension requires explicit version number `zbp`
+
+.attribute arch, "rv32izbr"
+# CHECK: error: invalid arch name 'rv32izbr', experimental extension requires explicit version number `zbr`
+
+.attribute arch, "rv32izbs"
+# CHECK: error: invalid arch name 'rv32izbs', experimental extension requires explicit version number `zbs`
+
+.attribute arch, "rv32izbt"
+# CHECK: error: invalid arch name 'rv32izbt', experimental extension requires explicit version number `zbt`
+
+.attribute arch, "rv32ifzfhmin"
+# CHECK:

[PATCH] D108694: [RISCV] Add the zvl extension according to the v1.0 spec

2021-12-09 Thread Yueh-Ting Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 393185.
eopXD added a comment.

Rebase now since the preceeding patches are accepted.
This patch is ready for review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108694

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/test/Driver/riscv-arch.c
  clang/test/Preprocessor/riscv-target-features.c
  llvm/include/llvm/Support/RISCVISAInfo.h
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVSubtarget.cpp
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s

Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -36,7 +36,7 @@
 ## Experimental extensions require version string to be explicitly specified
 
 .attribute arch, "rv32iv0p10"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
 
 .attribute arch, "rv32izba1p0"
 # CHECK: attribute  5, "rv32i2p0_zba1p0"
@@ -75,4 +75,40 @@
 # CHECK: attribute  5, "rv32i2p0_f2p0_zfh0p1_zfhmin0p1"
 
 .attribute arch, "rv32iv0p10zvamo0p10_zvlsseg0p10"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv0p10zvl32b0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv0p10zvl64b0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv0p10zvl128b0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv0p10zvl256b0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv0p10zvl512b0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv0p10zvl1024b0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv0p10zvl2048b0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv0p10zvl4096b0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv0p10zvl8192b0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv0p10zvl16384b0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv0p10zvl32768b0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32768b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv0p10zvl65536b0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32768b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl65536b0p10_zvl8192b0p10_zvlsseg0p10"
Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -18,7 +18,7 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbr %s -o - | FileCheck --check-prefix=RV32ZBR %s
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbs %s -o - | FileCheck --check-prefix=RV32ZBS %s
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbt %s -o - | FileCheck --check-prefix=RV32ZBT %s
-; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbb,+experimental-zfh,+experimental-zvamo,+experimental-v,+f,+experimental-zvlsseg %s -o - | FileCheck --check-prefix=RV32COMBINED %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbb,+experimental-zfh,+experimental-zvamo,+experimental-v,+experimental-zvlsseg %s -o - | FileCheck --check-prefix=RV32COMBINED %s
 ; RUN: llc -mtriple=riscv64 -mattr=+m %s -o - | FileCheck --check-prefix=RV64M %s
 ; RUN: llc -mtriple=riscv64 -mattr=+a %s -o - | FileCheck --check-prefix=RV64A %s
 ; RUN: llc -mtriple=riscv64 -mattr=+f %s -o - | FileCheck --check-prefix=RV64F %s
@@ -37,14 +37,14 @@
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-zbr %s -o - | FileCheck --check-prefix=RV64ZBR %s
 

[PATCH] D115438: [lldb] Remove unused lldb.cpp

2021-12-09 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGeaf4f60507fd: [lldb] Remove unused lldb.cpp (authored by 
hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115438

Files:
  lldb/source/lldb.cpp


Index: lldb/source/lldb.cpp
===
--- lldb/source/lldb.cpp
+++ /dev/null
@@ -1,77 +0,0 @@
-//===-- lldb.cpp 
--===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#include "VCSVersion.inc"
-#include "lldb/lldb-private.h"
-#include "clang/Basic/Version.h"
-
-using namespace lldb;
-using namespace lldb_private;
-
-// LLDB_VERSION_STRING is set through a define so unlike the other defines
-// expanded with CMake, it lacks the double quotes.
-#define QUOTE(str) #str
-#define EXPAND_AND_QUOTE(str) QUOTE(str)
-
-static const char *GetLLDBVersion() {
-#ifdef LLDB_VERSION_STRING
-  return EXPAND_AND_QUOTE(LLDB_VERSION_STRING);
-#else
-  return "lldb version " CLANG_VERSION_STRING;
-#endif
-}
-
-static const char *GetLLDBRevision() {
-#ifdef LLDB_REVISION
-  return LLDB_REVISION;
-#else
-  return NULL;
-#endif
-}
-
-static const char *GetLLDBRepository() {
-#ifdef LLDB_REPOSITORY
-  return LLDB_REPOSITORY;
-#else
-  return NULL;
-#endif
-}
-
-const char *lldb_private::GetVersion() {
-  static std::string g_version_str;
-  if (g_version_str.empty()) {
-const char *lldb_version = GetLLDBVersion();
-const char *lldb_repo = GetLLDBRepository();
-const char *lldb_rev = GetLLDBRevision();
-g_version_str += lldb_version;
-if (lldb_repo || lldb_rev) {
-  g_version_str += " (";
-  if (lldb_repo)
-g_version_str += lldb_repo;
-  if (lldb_repo && lldb_rev)
-g_version_str += " ";
-  if (lldb_rev) {
-g_version_str += "revision ";
-g_version_str += lldb_rev;
-  }
-  g_version_str += ")";
-}
-
-std::string clang_rev(clang::getClangRevision());
-if (clang_rev.length() > 0) {
-  g_version_str += "\n  clang revision ";
-  g_version_str += clang_rev;
-}
-std::string llvm_rev(clang::getLLVMRevision());
-if (llvm_rev.length() > 0) {
-  g_version_str += "\n  llvm revision ";
-  g_version_str += llvm_rev;
-}
-  }
-  return g_version_str.c_str();
-}


Index: lldb/source/lldb.cpp
===
--- lldb/source/lldb.cpp
+++ /dev/null
@@ -1,77 +0,0 @@
-//===-- lldb.cpp --===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#include "VCSVersion.inc"
-#include "lldb/lldb-private.h"
-#include "clang/Basic/Version.h"
-
-using namespace lldb;
-using namespace lldb_private;
-
-// LLDB_VERSION_STRING is set through a define so unlike the other defines
-// expanded with CMake, it lacks the double quotes.
-#define QUOTE(str) #str
-#define EXPAND_AND_QUOTE(str) QUOTE(str)
-
-static const char *GetLLDBVersion() {
-#ifdef LLDB_VERSION_STRING
-  return EXPAND_AND_QUOTE(LLDB_VERSION_STRING);
-#else
-  return "lldb version " CLANG_VERSION_STRING;
-#endif
-}
-
-static const char *GetLLDBRevision() {
-#ifdef LLDB_REVISION
-  return LLDB_REVISION;
-#else
-  return NULL;
-#endif
-}
-
-static const char *GetLLDBRepository() {
-#ifdef LLDB_REPOSITORY
-  return LLDB_REPOSITORY;
-#else
-  return NULL;
-#endif
-}
-
-const char *lldb_private::GetVersion() {
-  static std::string g_version_str;
-  if (g_version_str.empty()) {
-const char *lldb_version = GetLLDBVersion();
-const char *lldb_repo = GetLLDBRepository();
-const char *lldb_rev = GetLLDBRevision();
-g_version_str += lldb_version;
-if (lldb_repo || lldb_rev) {
-  g_version_str += " (";
-  if (lldb_repo)
-g_version_str += lldb_repo;
-  if (lldb_repo && lldb_rev)
-g_version_str += " ";
-  if (lldb_rev) {
-g_version_str += "revision ";
-g_version_str += lldb_rev;
-  }
-  g_version_str += ")";
-}
-
-std::string clang_rev(clang::getClangRevision());
-if (clang_rev.length() > 0) {
-  g_version_str += "\n  clang revision ";
-  g_version_str += clang_rev;
-}
-std::string llvm_rev(clang::getLLVMRevision());
-if (llvm_rev.length() > 0) {
-  g_version_str += "\n  llvm revision ";
-  g_version_str += llvm_rev;
-}
-  }
-  return g_version_str.c_

[PATCH] D114421: [asan] Add support for disable_sanitizer_instrumentation attribute

2021-12-09 Thread Alexander Potapenko via Phabricator via cfe-commits
glider updated this revision to Diff 393187.
glider added a comment.

Fix a windows test failure: 
https://buildkite.com/llvm-project/premerge-checks/builds/69318#0b873cc6-bf07-482a-ac37-e960566ac8a3


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114421

Files:
  clang/docs/AddressSanitizer.rst
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/SanitizerMetadata.cpp
  clang/test/CodeGen/address-safety-attr-flavors.cpp
  clang/test/CodeGen/asan-globals.cpp
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  
llvm/test/Instrumentation/AddressSanitizer/asan-disable-sanitizer-instrumentation.ll

Index: llvm/test/Instrumentation/AddressSanitizer/asan-disable-sanitizer-instrumentation.ll
===
--- /dev/null
+++ llvm/test/Instrumentation/AddressSanitizer/asan-disable-sanitizer-instrumentation.ll
@@ -0,0 +1,47 @@
+; This test checks that we are not instrumenting sanitizer code.
+; RUN: opt < %s -passes='asan-pipeline' -S | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; Function with sanitize_address is instrumented.
+; Function Attrs: nounwind uwtable
+define void @instr_sa(i32* %a) sanitize_address {
+entry:
+  %tmp1 = load i32, i32* %a, align 4
+  %tmp2 = add i32 %tmp1,  1
+  store i32 %tmp2, i32* %a, align 4
+  ret void
+}
+
+; CHECK-LABEL: @instr_sa
+; CHECK: call void @__asan_report_load
+
+
+; Function with disable_sanitizer_instrumentation is not instrumented.
+; Function Attrs: nounwind uwtable
+define void @noinstr_dsi(i32* %a) disable_sanitizer_instrumentation {
+entry:
+  %tmp1 = load i32, i32* %a, align 4
+  %tmp2 = add i32 %tmp1,  1
+  store i32 %tmp2, i32* %a, align 4
+  ret void
+}
+
+; CHECK-LABEL: @noinstr_dsi
+; CHECK-NOT: call void @__asan_report_load
+
+
+; disable_sanitizer_instrumentation takes precedence over sanitize_address.
+; Function Attrs: nounwind uwtable
+define void @noinstr_dsi_sa(i32* %a) disable_sanitizer_instrumentation sanitize_address {
+entry:
+  %tmp1 = load i32, i32* %a, align 4
+  %tmp2 = add i32 %tmp1,  1
+  store i32 %tmp2, i32* %a, align 4
+  ret void
+}
+
+; CHECK-LABEL: @noinstr_dsi_sa
+; CHECK-NOT: call void @__asan_report_load
+
Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -2890,6 +2890,9 @@
   // Leave if the function doesn't need instrumentation.
   if (!F.hasFnAttribute(Attribute::SanitizeAddress)) return FunctionModified;
 
+  if (F.hasFnAttribute(Attribute::DisableSanitizerInstrumentation))
+return FunctionModified;
+
   LLVM_DEBUG(dbgs() << "ASAN instrumenting:\n" << F << "\n");
 
   initializeCallbacks(*F.getParent());
Index: clang/test/CodeGen/asan-globals.cpp
===
--- clang/test/CodeGen/asan-globals.cpp
+++ clang/test/CodeGen/asan-globals.cpp
@@ -10,6 +10,7 @@
 int global;
 int dyn_init_global = global;
 int __attribute__((no_sanitize("address"))) attributed_global;
+int __attribute__((disable_sanitizer_instrumentation)) disable_instrumentation_global;
 int ignorelisted_global;
 
 int __attribute__((section("__DATA, __common"))) sectioned_global; // KASAN - ignore globals in a section
@@ -50,31 +51,33 @@
 // UWTABLE: attributes #[[#ATTR]] = { nounwind uwtable }
 // UWTABLE: ![[#]] = !{i32 7, !"uwtable", i32 1}
 
-// CHECK: !llvm.asan.globals = !{![[EXTRA_GLOBAL:[0-9]+]], ![[GLOBAL:[0-9]+]], ![[DYN_INIT_GLOBAL:[0-9]+]], ![[ATTR_GLOBAL:[0-9]+]], ![[IGNORELISTED_GLOBAL:[0-9]+]], ![[SECTIONED_GLOBAL:[0-9]+]], ![[SPECIAL_GLOBAL:[0-9]+]], ![[STATIC_VAR:[0-9]+]], ![[LITERAL:[0-9]+]]}
+// CHECK: !llvm.asan.globals = !{![[EXTRA_GLOBAL:[0-9]+]], ![[GLOBAL:[0-9]+]], ![[DYN_INIT_GLOBAL:[0-9]+]], ![[ATTR_GLOBAL:[0-9]+]], ![[DISABLE_INSTR_GLOBAL:[0-9]+]], ![[IGNORELISTED_GLOBAL:[0-9]+]], ![[SECTIONED_GLOBAL:[0-9]+]], ![[SPECIAL_GLOBAL:[0-9]+]], ![[STATIC_VAR:[0-9]+]], ![[LITERAL:[0-9]+]]}
 // CHECK: ![[EXTRA_GLOBAL]] = !{{{.*}} ![[EXTRA_GLOBAL_LOC:[0-9]+]], !"extra_global", i1 false, i1 false}
 // CHECK: ![[EXTRA_GLOBAL_LOC]] = !{!"{{.*}}extra-source.cpp", i32 1, i32 5}
 // CHECK: ![[GLOBAL]] = !{{{.*}} ![[GLOBAL_LOC:[0-9]+]], !"global", i1 false, i1 false}
 // CHECK: ![[GLOBAL_LOC]] = !{!"{{.*}}asan-globals.cpp", i32 10, i32 5}
 // CHECK: ![[DYN_INIT_GLOBAL]] = !{{{.*}} ![[DYN_INIT_LOC:[0-9]+]], !"dyn_init_global", i1 true, i1 false}
 // CHECK: ![[DYN_INIT_LOC]] = !{!"{{.*}}asan-globals.cpp", i32 11, i32 5}
-// CHECK: ![[ATTR_GLOBAL]] = !{{{.*}}, null, null, i1 false, i1 true}
-// CHECK: ![[IGNORELISTED_GLOBAL]] = !{{{.*}}, null, null, i1 false, i1 true}
+// CHECK: ![[ATTR_GLOBAL]] = !{{{.*attributed_global.*}}, null, null, i1 false, i1 true}
+// CHECK: ![

[PATCH] D115442: [clangd] Provide documentation as MarkupContent in signaturehelp

2021-12-09 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

MarkupContent was introduced in 3.12 in 2018.
We could continue to support older clients by rendering plaintext as string 
instead of the MarkupContent struct but it doesn't seem worth it.




Comment at: clang-tools-extra/clangd/Protocol.h:495
+  /// textDocument.signatureHelp.signatureInformation.documentationFormat
+  MarkupKind SignatureHelpDocumentationFormat = MarkupKind::PlainText;
 };

move next to other sighelp caps?



Comment at: clang-tools-extra/clangd/test/signature-help.test:1
 # RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s
 # Start a session.

I definitely don't think we need three copies of this test.

I'd personally probably only keep one, and have it specify markdown explicitly 
(plaintext is the default).
Keeping a test for both plain and markdown is more coverage, copied tests are a 
maintenance hazard, up to you.
Keeping both plain-explicitly-specified and plain-by-default seems gratuitous.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115442

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


[PATCH] D111617: [RISCV] Lazily add RVV C intrinsics.

2021-12-09 Thread Hsiangkai Wang via Phabricator via cfe-commits
HsiangKai added a comment.

Release build:
Before this patch:

 text data bssdec hex
  115471733   7987112  443760 123902605   7629a8d ./bin/clang

After this patch:

 text data bssdec hex
  117568981   7996376  443760 126009117   782bf1d ./bin/clang  (+1.7%)

Debug build:
Before this patch:

 text data bssdec hex
  265437945   9544132  494152 275476229   106b6f05./bin/clang

After this patch:

 text data bssdec hex
  272133359   9553380  494152 282180891   10d1bd1b./bin/clang. 
(+2.4%)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111617

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


[PATCH] D115168: [clang-format] [PR49298] Sort includes pass will sort inside raw strings

2021-12-09 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 393188.
MyDeveloperDay added a comment.

Add a suitable amount of C++ madness, (to the limit of what I could coax the 
regex to accept)


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

https://reviews.llvm.org/D115168

Files:
  clang/lib/Format/Format.cpp
  clang/unittests/Format/SortIncludesTest.cpp

Index: clang/unittests/Format/SortIncludesTest.cpp
===
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -1045,6 +1045,122 @@
   EXPECT_EQ(Unsorted, sort(Unsorted, "input.cpp", 0));
 }
 
+TEST_F(SortIncludesTest, DisableRawStringLiteralSorting) {
+
+  EXPECT_EQ("const char *t = R\"(\n"
+"#include \n"
+"#include \n"
+")\";",
+sort("const char *t = R\"(\n"
+ "#include \n"
+ "#include \n"
+ ")\";",
+ "test.cxx", 0));
+  EXPECT_EQ("const char *t = R\"x(\n"
+"#include \n"
+"#include \n"
+")x\";",
+sort("const char *t = R\"x(\n"
+ "#include \n"
+ "#include \n"
+ ")x\";",
+ "test.cxx", 0));
+  EXPECT_EQ("const char *t = R\"xyz(\n"
+"#include \n"
+"#include \n"
+")xyz\";",
+sort("const char *t = R\"xyz(\n"
+ "#include \n"
+ "#include \n"
+ ")xyz\";",
+ "test.cxx", 0));
+
+  EXPECT_EQ("#include \n"
+"#include \n"
+"const char *t = R\"(\n"
+"#include \n"
+"#include \n"
+")\";\n"
+"#include \n"
+"#include \n"
+"const char *t = R\"x(\n"
+"#include \n"
+"#include \n"
+")x\";\n"
+"#include \n"
+"#include \n"
+"const char *t = R\"xyz(\n"
+"#include \n"
+"#include \n"
+")xyz\";\n"
+"#include \n"
+"#include ",
+sort("#include \n"
+ "#include \n"
+ "const char *t = R\"(\n"
+ "#include \n"
+ "#include \n"
+ ")\";\n"
+ "#include \n"
+ "#include \n"
+ "const char *t = R\"x(\n"
+ "#include \n"
+ "#include \n"
+ ")x\";\n"
+ "#include \n"
+ "#include \n"
+ "const char *t = R\"xyz(\n"
+ "#include \n"
+ "#include \n"
+ ")xyz\";\n"
+ "#include \n"
+ "#include ",
+ "test.cc", 4));
+
+  EXPECT_EQ("const char *t = R\"AMZ029amz(\n"
+"#include \n"
+"#include \n"
+")AMZ029amz\";",
+sort("const char *t = R\"AMZ029amz(\n"
+ "#include \n"
+ "#include \n"
+ ")AMZ029amz\";",
+ "test.cxx", 0));
+
+  EXPECT_EQ("const char *t = R\"-AMZ029amz(\n"
+"#include \n"
+"#include \n"
+")-AMZ029amz\";",
+sort("const char *t = R\"-AMZ029amz(\n"
+ "#include \n"
+ "#include \n"
+ ")-AMZ029amz\";",
+ "test.cxx", 0));
+
+  EXPECT_EQ("const char *t = R\"AMZ029amz-(\n"
+"#include \n"
+"#include \n"
+")AMZ029amz-\";",
+sort("const char *t = R\"AMZ029amz-(\n"
+ "#include \n"
+ "#include \n"
+ ")AMZ029amz-\";",
+ "test.cxx", 0));
+
+  // Missing |`
+#define X "AMZ029amz{}+!%*=_:;',.<>/?#~-$"
+
+  EXPECT_EQ("const char *t = R\"" X "(\n"
+"#include \n"
+"#include \n"
+")" X "\";",
+sort("const char *t = R\"" X "(\n"
+ "#include \n"
+ "#include \n"
+ ")" X "\";",
+ "test.cxx", 0));
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -2586,12 +2586,31 @@
   bool MainIncludeFound = false;
   bool FormattingOff = false;
 
+  llvm::Regex RawStringRegex(
+  "R\"([A-Za-z0-9_{}#<>%:;.?*+/^&\\$|~!=,'\\-]*)\\(");
+  SmallVector RawStringMatches;
+  std::string RawStringTermination = ")\"";
+
   for (;;) {
 auto Pos = Code.find('\n', SearchFrom);
 StringRef Line =
 Code.substr(Prev, (Pos != StringRef::npos ? Pos : Code.size()) - Prev);
 
 StringRef Trimmed = Line.trim();
+
+// #includes inside raw string literals need to be ignored.
+// or we will sort the contents 

[PATCH] D115452: Prevent abseil-cleanup-ctad check from stomping on surrounding context

2021-12-09 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson created this revision.
CJ-Johnson added a reviewer: ymandel.
Herald added a subscriber: carlosgalvezp.
CJ-Johnson requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

This change applies two fixes to the abseil-cleanup-ctad check. It uses 
hasSingleDecl() to ensure only declStmt()s with one varDecl() are matched 
(leaving compount declStmt()s unchanged). It also addresses a bug in the 
handling of comments that surround the absl::MakeCleanup() calls by switching 
to the callArgs() combinator from Clang Transformer.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115452

Files:
  clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/abseil-cleanup-ctad.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/abseil-cleanup-ctad.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/abseil-cleanup-ctad.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/abseil-cleanup-ctad.cpp
@@ -81,35 +81,25 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup's class 
template argument deduction pattern in C++17 and higher
   // CHECK-FIXES: {{^}}  absl::Cleanup a = [] {};{{$}}
 
-  // Removes extra parens
-  auto b = absl::MakeCleanup(([] {}));
+  auto b = absl::MakeCleanup(std::function([] {}));
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup{{.*}}C++17 
and higher
-  // CHECK-FIXES: {{^}}  absl::Cleanup b = [] {};{{$}}
+  // CHECK-FIXES: {{^}}  absl::Cleanup b = std::function([] {});{{$}}
 
-  auto c = absl::MakeCleanup(std::function([] {}));
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup{{.*}}C++17 
and higher
-  // CHECK-FIXES: {{^}}  absl::Cleanup c = std::function([] {});{{$}}
-
-  // Removes extra parens
-  auto d = absl::MakeCleanup((std::function([] {})));
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup{{.*}}C++17 
and higher
-  // CHECK-FIXES: {{^}}  absl::Cleanup d = std::function([] {});{{$}}
-
-  const auto e = absl::MakeCleanup([] {});
+  const auto c = absl::MakeCleanup([] {});
   // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup{{.*}}C++17 
and higher
-  // CHECK-FIXES: {{^}}  const absl::Cleanup e = [] {};{{$}}
+  // CHECK-FIXES: {{^}}  const absl::Cleanup c = [] {};{{$}}
 
-  // Removes extra parens
-  const auto f = absl::MakeCleanup(([] {}));
+  const auto d = absl::MakeCleanup(std::function([] {}));
   // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup{{.*}}C++17 
and higher
-  // CHECK-FIXES: {{^}}  const absl::Cleanup f = [] {};{{$}}
+  // CHECK-FIXES: {{^}}  const absl::Cleanup d = std::function([] 
{});{{$}}
 
-  const auto g = absl::MakeCleanup(std::function([] {}));
-  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup{{.*}}C++17 
and higher
-  // CHECK-FIXES: {{^}}  const absl::Cleanup g = std::function([] 
{});{{$}}
+  // Preserves extra parens
+  auto e = absl::MakeCleanup(([] {}));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup{{.*}}C++17 
and higher
+  // CHECK-FIXES: {{^}}  absl::Cleanup e = ([] {});{{$}}
 
-  // Removes extra parens
-  const auto h = absl::MakeCleanup((std::function([] {})));
-  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup{{.*}}C++17 
and higher
-  // CHECK-FIXES: {{^}}  const absl::Cleanup h = std::function([] 
{});{{$}}
+  // Preserves comments
+  auto f = /* a */ absl::MakeCleanup(/* b */ [] { /* c */ } /* d */) /* e */;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup{{.*}}C++17 
and higher
+  // CHECK-FIXES: {{^}}  absl::Cleanup f = /* a */ /* b */ [] { /* c */ } /* d 
*/ /* e */;{{$}}
 }
Index: clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.cpp
===
--- clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.cpp
+++ clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.cpp
@@ -28,16 +28,14 @@
  "deduction pattern in C++17 and higher");
 
   return makeRule(
-  declStmt(has(varDecl(
+  declStmt(hasSingleDecl(varDecl(
   hasType(autoType()), hasTypeLoc(typeLoc().bind("auto_type_loc")),
-  hasInitializer(traverse(
-  clang::TK_IgnoreUnlessSpelledInSource,
+  hasInitializer(hasDescendant(
   callExpr(callee(functionDecl(hasName("absl::MakeCleanup"))),
-   argumentCountIs(1),
-   hasArgument(0, expr().bind("make_cleanup_argument")))
+   argumentCountIs(1))
   .bind("make_cleanup_call")),
   {changeTo(node("auto_type_loc"), cat("absl::Cleanup")),
-   changeTo(node("make_cleanup_call"), 
cat(node("make_cleanup_argument")))},
+   changeTo(node("make_cleanup_call"), 
cat(callArgs("make_cleanup_call")))},
   warning_message);
 }
 


Index: clang-tools-ex

[PATCH] D115452: Prevent abseil-cleanup-ctad check from stomping on surrounding context

2021-12-09 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.

Nice!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115452

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


[PATCH] D115438: [lldb] Remove unused lldb.cpp

2021-12-09 Thread Jonas Devlieghere via Phabricator via cfe-commits
JDevlieghere added a comment.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115438

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


[clang-tools-extra] a1968d5 - Prevent abseil-cleanup-ctad check from stomping on surrounding context

2021-12-09 Thread Yitzhak Mandelbaum via cfe-commits

Author: CJ Johnson
Date: 2021-12-09T17:41:12Z
New Revision: a1968d5341d7b1ec7889955f230d0375548d165b

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

LOG: Prevent abseil-cleanup-ctad check from stomping on surrounding context

This change applies two fixes to the abseil-cleanup-ctad check. It uses 
hasSingleDecl() to ensure only declStmt()s with one varDecl() are matched 
(leaving compount declStmt()s unchanged). It also addresses a bug in the 
handling of comments that surround the absl::MakeCleanup() calls by switching 
to the callArgs() combinator from Clang Transformer.

Reviewed By: ymandel

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/abseil-cleanup-ctad.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.cpp 
b/clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.cpp
index bc152f1dafa7..bbf860342fee 100644
--- a/clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.cpp
@@ -28,16 +28,14 @@ RewriteRule CleanupCtadCheckImpl() {
  "deduction pattern in C++17 and higher");
 
   return makeRule(
-  declStmt(has(varDecl(
+  declStmt(hasSingleDecl(varDecl(
   hasType(autoType()), hasTypeLoc(typeLoc().bind("auto_type_loc")),
-  hasInitializer(traverse(
-  clang::TK_IgnoreUnlessSpelledInSource,
+  hasInitializer(hasDescendant(
   callExpr(callee(functionDecl(hasName("absl::MakeCleanup"))),
-   argumentCountIs(1),
-   hasArgument(0, expr().bind("make_cleanup_argument")))
+   argumentCountIs(1))
   .bind("make_cleanup_call")),
   {changeTo(node("auto_type_loc"), cat("absl::Cleanup")),
-   changeTo(node("make_cleanup_call"), 
cat(node("make_cleanup_argument")))},
+   changeTo(node("make_cleanup_call"), 
cat(callArgs("make_cleanup_call")))},
   warning_message);
 }
 

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/abseil-cleanup-ctad.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/abseil-cleanup-ctad.cpp
index c023521bb261..c2b5e4df985d 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/abseil-cleanup-ctad.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/abseil-cleanup-ctad.cpp
@@ -81,35 +81,25 @@ void test() {
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup's class 
template argument deduction pattern in C++17 and higher
   // CHECK-FIXES: {{^}}  absl::Cleanup a = [] {};{{$}}
 
-  // Removes extra parens
-  auto b = absl::MakeCleanup(([] {}));
+  auto b = absl::MakeCleanup(std::function([] {}));
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup{{.*}}C++17 
and higher
-  // CHECK-FIXES: {{^}}  absl::Cleanup b = [] {};{{$}}
+  // CHECK-FIXES: {{^}}  absl::Cleanup b = std::function([] {});{{$}}
 
-  auto c = absl::MakeCleanup(std::function([] {}));
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup{{.*}}C++17 
and higher
-  // CHECK-FIXES: {{^}}  absl::Cleanup c = std::function([] {});{{$}}
-
-  // Removes extra parens
-  auto d = absl::MakeCleanup((std::function([] {})));
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup{{.*}}C++17 
and higher
-  // CHECK-FIXES: {{^}}  absl::Cleanup d = std::function([] {});{{$}}
-
-  const auto e = absl::MakeCleanup([] {});
+  const auto c = absl::MakeCleanup([] {});
   // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup{{.*}}C++17 
and higher
-  // CHECK-FIXES: {{^}}  const absl::Cleanup e = [] {};{{$}}
+  // CHECK-FIXES: {{^}}  const absl::Cleanup c = [] {};{{$}}
 
-  // Removes extra parens
-  const auto f = absl::MakeCleanup(([] {}));
+  const auto d = absl::MakeCleanup(std::function([] {}));
   // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup{{.*}}C++17 
and higher
-  // CHECK-FIXES: {{^}}  const absl::Cleanup f = [] {};{{$}}
+  // CHECK-FIXES: {{^}}  const absl::Cleanup d = std::function([] 
{});{{$}}
 
-  const auto g = absl::MakeCleanup(std::function([] {}));
-  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup{{.*}}C++17 
and higher
-  // CHECK-FIXES: {{^}}  const absl::Cleanup g = std::function([] 
{});{{$}}
+  // Preserves extra parens
+  auto e = absl::MakeCleanup(([] {}));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup{{.*}}C++17 
and higher
+  // CHECK-FIXES: {{^}}  absl::Cleanup e = ([] {});{{$}}
 
-  // Removes extra parens
-  const auto h = absl::MakeCleanup((std::function([] {})));
-  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup{{.*}}C++17 
and higher

[PATCH] D115452: Prevent abseil-cleanup-ctad check from stomping on surrounding context

2021-12-09 Thread Yitzhak Mandelbaum 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 rGa1968d5341d7: Prevent abseil-cleanup-ctad check from 
stomping on surrounding context (authored by CJ-Johnson, committed by ymandel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115452

Files:
  clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/abseil-cleanup-ctad.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/abseil-cleanup-ctad.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/abseil-cleanup-ctad.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/abseil-cleanup-ctad.cpp
@@ -81,35 +81,25 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup's class 
template argument deduction pattern in C++17 and higher
   // CHECK-FIXES: {{^}}  absl::Cleanup a = [] {};{{$}}
 
-  // Removes extra parens
-  auto b = absl::MakeCleanup(([] {}));
+  auto b = absl::MakeCleanup(std::function([] {}));
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup{{.*}}C++17 
and higher
-  // CHECK-FIXES: {{^}}  absl::Cleanup b = [] {};{{$}}
+  // CHECK-FIXES: {{^}}  absl::Cleanup b = std::function([] {});{{$}}
 
-  auto c = absl::MakeCleanup(std::function([] {}));
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup{{.*}}C++17 
and higher
-  // CHECK-FIXES: {{^}}  absl::Cleanup c = std::function([] {});{{$}}
-
-  // Removes extra parens
-  auto d = absl::MakeCleanup((std::function([] {})));
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup{{.*}}C++17 
and higher
-  // CHECK-FIXES: {{^}}  absl::Cleanup d = std::function([] {});{{$}}
-
-  const auto e = absl::MakeCleanup([] {});
+  const auto c = absl::MakeCleanup([] {});
   // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup{{.*}}C++17 
and higher
-  // CHECK-FIXES: {{^}}  const absl::Cleanup e = [] {};{{$}}
+  // CHECK-FIXES: {{^}}  const absl::Cleanup c = [] {};{{$}}
 
-  // Removes extra parens
-  const auto f = absl::MakeCleanup(([] {}));
+  const auto d = absl::MakeCleanup(std::function([] {}));
   // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup{{.*}}C++17 
and higher
-  // CHECK-FIXES: {{^}}  const absl::Cleanup f = [] {};{{$}}
+  // CHECK-FIXES: {{^}}  const absl::Cleanup d = std::function([] 
{});{{$}}
 
-  const auto g = absl::MakeCleanup(std::function([] {}));
-  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup{{.*}}C++17 
and higher
-  // CHECK-FIXES: {{^}}  const absl::Cleanup g = std::function([] 
{});{{$}}
+  // Preserves extra parens
+  auto e = absl::MakeCleanup(([] {}));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup{{.*}}C++17 
and higher
+  // CHECK-FIXES: {{^}}  absl::Cleanup e = ([] {});{{$}}
 
-  // Removes extra parens
-  const auto h = absl::MakeCleanup((std::function([] {})));
-  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup{{.*}}C++17 
and higher
-  // CHECK-FIXES: {{^}}  const absl::Cleanup h = std::function([] 
{});{{$}}
+  // Preserves comments
+  auto f = /* a */ absl::MakeCleanup(/* b */ [] { /* c */ } /* d */) /* e */;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup{{.*}}C++17 
and higher
+  // CHECK-FIXES: {{^}}  absl::Cleanup f = /* a */ /* b */ [] { /* c */ } /* d 
*/ /* e */;{{$}}
 }
Index: clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.cpp
===
--- clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.cpp
+++ clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.cpp
@@ -28,16 +28,14 @@
  "deduction pattern in C++17 and higher");
 
   return makeRule(
-  declStmt(has(varDecl(
+  declStmt(hasSingleDecl(varDecl(
   hasType(autoType()), hasTypeLoc(typeLoc().bind("auto_type_loc")),
-  hasInitializer(traverse(
-  clang::TK_IgnoreUnlessSpelledInSource,
+  hasInitializer(hasDescendant(
   callExpr(callee(functionDecl(hasName("absl::MakeCleanup"))),
-   argumentCountIs(1),
-   hasArgument(0, expr().bind("make_cleanup_argument")))
+   argumentCountIs(1))
   .bind("make_cleanup_call")),
   {changeTo(node("auto_type_loc"), cat("absl::Cleanup")),
-   changeTo(node("make_cleanup_call"), 
cat(node("make_cleanup_argument")))},
+   changeTo(node("make_cleanup_call"), 
cat(callArgs("make_cleanup_call")))},
   warning_message);
 }
 


Index: clang-tools-extra/test/clang-tidy/checkers/abseil-cleanup-ctad.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/abseil-cleanup-ctad.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/abseil-cle

[PATCH] D114995: clang-tidy: improve the 'modernize-use-default-member-init'

2021-12-09 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons added a comment.

In D114995#3180475 , @aaron.ballman 
wrote:

> was there a reason we didn't cover that case originally or was it an 
> oversight/left for future work?

It was left for future work - by only considering the initializer list of the 
default constructor, clang-tidy did not have to work out what to do when the 
constructors don't agree on what value the member init should have.
The next step towards the full solution is to handle classes with only one 
non-special constructor.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114995

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


[PATCH] D114639: Raise the minimum Visual Studio version to VS2019

2021-12-09 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur added a comment.

ping?

@erichkeane Since you are pushing for upgrade the gcc/clang requirement as 
well, would you take care of that?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114639

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


[clang] 4c7de4f - Thread safety analysis: Remove unused variable. NFC.

2021-12-09 Thread Benjamin Kramer via cfe-commits

Author: Benjamin Kramer
Date: 2021-12-09T18:57:43+01:00
New Revision: 4c7de4fbda03f38514c4aebed34dc2bbfb7e62a5

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

LOG: Thread safety analysis: Remove unused variable. NFC.

Added: 


Modified: 
clang/lib/Analysis/ThreadSafety.cpp

Removed: 




diff  --git a/clang/lib/Analysis/ThreadSafety.cpp 
b/clang/lib/Analysis/ThreadSafety.cpp
index b196ffa73cbfb..9cc990bd35a3f 100644
--- a/clang/lib/Analysis/ThreadSafety.cpp
+++ b/clang/lib/Analysis/ThreadSafety.cpp
@@ -418,7 +418,6 @@ class LocalVariableMap {
 private:
   Context::Factory ContextFactory;
   std::vector VarDefinitions;
-  std::vector CtxIndices;
   std::vector> SavedContexts;
 
 public:
@@ -731,8 +730,6 @@ void LocalVariableMap::traverseCFG(CFG *CFGraph,
std::vector &BlockInfo) {
   PostOrderCFGView::CFGBlockSet VisitedBlocks(CFGraph);
 
-  CtxIndices.resize(CFGraph->getNumBlockIDs());
-
   for (const auto *CurrBlock : *SortedGraph) {
 unsigned CurrBlockID = CurrBlock->getBlockID();
 CFGBlockInfo *CurrBlockInfo = &BlockInfo[CurrBlockID];



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


[PATCH] D115456: Implement on-demand TLS initialization for Microsoft CXX ABI

2021-12-09 Thread Maurice Heumann via Phabricator via cfe-commits
momo5502 created this revision.
momo5502 added reviewers: rnk, eugenis.
momo5502 added a project: clang.
momo5502 requested review of this revision.
Herald added a subscriber: cfe-commits.

TLS initializers, for example constructors of thread-local variables, don't 
necessarily get called. If for example a thread was created before a module is 
loaded, the module's TLS initializers are not executed for this particular 
thread.

This is why Microsoft added support for dynamic TLS initialization. Before 
every use of thread-local variables, a check is added that runs the module's 
TLS initializers on-demand.

To do this, the method `__dyn_tls_on_demand_init` gets called. Internally, it 
simply calls `__dyn_tls_init`.
To prevent calling initializers again, a guard variable called `__tls_guard` is 
checked and set before executing the call.

No additional TLS initializer that sets the guard needs to be emitted, as the 
guard always gets set by `__dyn_tls_init`.
The guard is also checked again within `__dyn_tls_init`. This makes our check 
redundant, however, as Microsoft's compiler also emits this check, the 
behaviour is adopted here.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115456

Files:
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/test/CodeGenCXX/ms-thread_local.cpp

Index: clang/test/CodeGenCXX/ms-thread_local.cpp
===
--- clang/test/CodeGenCXX/ms-thread_local.cpp
+++ clang/test/CodeGenCXX/ms-thread_local.cpp
@@ -17,10 +17,20 @@
 
 // CHECK-DAG: @"?b@@3UA@@A" = dso_local thread_local global %struct.A zeroinitializer, align 1
 // CHECK-DAG: @"__tls_init$initializer$" = internal constant void ()* @__tls_init, section ".CRT$XDU"
+// CHECK-DAG: @__tls_guard = external dso_local thread_local global i8
 // CHECK-LD-DAG: @"?b@@3UA@@A" = dso_local thread_local(localdynamic) global %struct.A zeroinitializer, align 1
 // CHECK-LD-DAG: @"__tls_init$initializer$" = internal constant void ()* @__tls_init, section ".CRT$XDU"
+// CHECK-LD-DAG: @__tls_guard = external dso_local thread_local global i8
 thread_local A b;
 
+// CHECK-LABEL: declare dso_local void @__dyn_tls_on_demand_init()
+// CHECK-LD-LABEL: declare dso_local void @__dyn_tls_on_demand_init()
+
+// CHECK-LABEL: define dso_local void @"?f@@YA?AUA@@XZ"(%struct.A* noalias sret(%struct.A) align 1 %agg.result)
+// CHECK: call void @__dyn_tls_on_demand_init()
+// CHECK-LD-LABEL: define dso_local void @"?f@@YA?AUA@@XZ"(%struct.A* noalias sret(%struct.A) align 1 %agg.result)
+// CHECK-LD: call void @__dyn_tls_on_demand_init()
+
 // CHECK-LABEL: define internal void @__tls_init()
 // CHECK: call void @"??__Eb@@YAXXZ"
 // CHECK-LD-LABEL: define internal void @__tls_init()
Index: clang/lib/CodeGen/MicrosoftCXXABI.cpp
===
--- clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -401,7 +401,7 @@
   ArrayRef CXXThreadLocalInitVars) override;
 
   bool usesThreadWrapperFunction(const VarDecl *VD) const override {
-return false;
+return true;
   }
   LValue EmitThreadLocalVarDeclLValue(CodeGenFunction &CGF, const VarDecl *VD,
   QualType LValType) override;
@@ -2397,11 +2397,87 @@
   }
 }
 
+static llvm::GlobalValue *getTlsGuardVar(CodeGenModule &CGM) {
+  llvm::Type *VTy = llvm::Type::getInt8Ty(CGM.getLLVMContext());
+  llvm::Constant *TlsGuardConstant =
+  CGM.CreateRuntimeVariable(VTy, "__tls_guard");
+  llvm::GlobalValue *TlsGuard = cast(TlsGuardConstant);
+
+  TlsGuard->setThreadLocal(true);
+
+  return TlsGuard;
+}
+
+static llvm::FunctionCallee getDynTlsOnDemandInitFn(CodeGenModule &CGM) {
+  llvm::FunctionType *FTy =
+  llvm::FunctionType::get(llvm::Type::getVoidTy(CGM.getLLVMContext()), {},
+  /*isVarArg=*/false);
+  return CGM.CreateRuntimeFunction(
+  FTy, "__dyn_tls_on_demand_init",
+  llvm::AttributeList::get(CGM.getLLVMContext(),
+   llvm::AttributeList::FunctionIndex,
+   llvm::Attribute::NoUnwind),
+  /*Local=*/true);
+}
+
+static void emitTlsGuardCheck(CodeGenFunction &CGF, llvm::GlobalValue *TlsGuard,
+  llvm::BasicBlock *DynInitBB,
+  llvm::BasicBlock *ContinueBB) {
+  llvm::LoadInst *TlsGuardValue =
+  CGF.Builder.CreateLoad(Address(TlsGuard, CharUnits::One()));
+  llvm::Value *CmpResult =
+  CGF.Builder.CreateICmpEQ(TlsGuardValue, CGF.Builder.getInt8(0));
+  CGF.Builder.CreateCondBr(CmpResult, DynInitBB, ContinueBB);
+}
+
+static void emitDynamicTlsInitialization(CodeGenFunction &CGF,
+ llvm::GlobalValue *TlsGuard,
+ llvm::BasicBlock *ContinueBB) {
+  CGF.Builder.CreateStore(CGF.Builder.getInt8(1),
+  Address(TlsGuard, CharUnits::One()));
+
+  llvm::Funct

[PATCH] D115341: [clang][dataflow] Add framework for testing analyses.

2021-12-09 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 393218.
ymandel added a comment.

responding to review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115341

Files:
  clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
  clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
  clang/unittests/Analysis/FlowSensitive/TestingSupport.cpp
  clang/unittests/Analysis/FlowSensitive/TestingSupport.h
  clang/unittests/Analysis/FlowSensitive/TestingSupportTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TestingSupportTest.cpp
===
--- /dev/null
+++ clang/unittests/Analysis/FlowSensitive/TestingSupportTest.cpp
@@ -0,0 +1,174 @@
+#include "TestingSupport.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Tooling/Tooling.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+using namespace dataflow;
+
+namespace {
+
+using ::clang::ast_matchers::functionDecl;
+using ::clang::ast_matchers::hasName;
+using ::clang::ast_matchers::isDefinition;
+using ::testing::_;
+using ::testing::IsEmpty;
+using ::testing::Pair;
+using ::testing::UnorderedElementsAre;
+
+class NoopLattice {
+public:
+  bool operator==(const NoopLattice &) const { return true; }
+
+  LatticeJoinEffect join(const NoopLattice &) {
+return LatticeJoinEffect::Unchanged;
+  }
+};
+
+class NoopAnalysis : public DataflowAnalysis {
+public:
+  NoopAnalysis(ASTContext &Context)
+  : DataflowAnalysis(Context) {}
+
+  static NoopLattice initialElement() { return {}; }
+
+  NoopLattice transfer(const Stmt *S, const NoopLattice &E, Environment &Env) {
+return {};
+  }
+};
+
+template 
+const FunctionDecl *findTargetFunc(ASTContext &Context, T FunctionMatcher) {
+  auto TargetMatcher =
+  functionDecl(FunctionMatcher, isDefinition()).bind("target");
+  for (const auto &Node : ast_matchers::match(TargetMatcher, Context)) {
+const auto *Func = Node.template getNodeAs("target");
+if (Func == nullptr)
+  continue;
+if (Func->isTemplated())
+  continue;
+return Func;
+  }
+  return nullptr;
+}
+
+class BuildStatementToAnnotationMappingTest : public ::testing::Test {
+public:
+  void
+  runTest(llvm::StringRef Code, llvm::StringRef TargetName,
+  std::function &)>
+  RunChecks) {
+llvm::Annotations AnnotatedCode(Code);
+auto Unit = tooling::buildASTFromCodeWithArgs(
+AnnotatedCode.code(), {"-fsyntax-only", "-std=c++17"});
+auto &Context = Unit->getASTContext();
+const FunctionDecl *Func = findTargetFunc(Context, hasName(TargetName));
+ASSERT_NE(Func, nullptr);
+
+llvm::Expected> Mapping =
+clang::dataflow::testing::buildStatementToAnnotationMapping(
+Func, AnnotatedCode);
+ASSERT_TRUE(static_cast(Mapping));
+
+RunChecks(Mapping.get());
+  }
+};
+
+TEST_F(BuildStatementToAnnotationMappingTest, ReturnStmt) {
+  runTest(R"(
+int target() {
+  return 42;
+  /*[[ok]]*/
+}
+  )",
+  "target",
+  [](const llvm::DenseMap &Annotations) {
+ASSERT_EQ(Annotations.size(), static_cast(1));
+EXPECT_TRUE(isa(Annotations.begin()->first));
+EXPECT_EQ(Annotations.begin()->second, "ok");
+  });
+}
+
+void checkDataflow(
+llvm::StringRef Code, llvm::StringRef Target,
+std::function>>,
+   ASTContext &)>
+Expectations) {
+  clang::dataflow::testing::checkDataflow(
+  Code, Target,
+  [](ASTContext &Context, Environment &) { return NoopAnalysis(Context); },
+  std::move(Expectations), {"-fsyntax-only", "-std=c++17"});
+}
+
+TEST(ProgramPointAnnotations, NoAnnotations) {
+  ::testing::MockFunction>>,
+  ASTContext &)>
+  Expectations;
+
+  EXPECT_CALL(Expectations, Call(IsEmpty(), _)).Times(1);
+
+  checkDataflow("void target() {}", "target", Expectations.AsStdFunction());
+}
+
+TEST(ProgramPointAnnotations, NoAnnotationsDifferentTarget) {
+  ::testing::MockFunction>>,
+  ASTContext &)>
+  Expectations;
+
+  EXPECT_CALL(Expectations, Call(IsEmpty(), _)).Times(1);
+
+  checkDataflow("void fun() {}", "fun", Expectations.AsStdFunction());
+}
+
+TEST(ProgramPointAnnotations, WithCodepoint) {
+  ::testing::MockFunction>>,
+  ASTContext &)>
+  Expectations;
+
+  EXPECT_CALL(Expectations,
+  Call(UnorderedElementsAre(Pair("program-point", _)), _))
+  .Times(1);
+
+  checkDataflow(R"cc(void target() {
+ int n;
+ // [[program-point]]
+   })cc",
+"target", Expectations.AsStdFunction());
+}
+
+TEST(ProgramPointAnnotations, MultipleCodepoints) {
+  ::testing::MockFunction>>,
+  ASTContext &)>
+  

[PATCH] D115168: [clang-format] [PR49298] Sort includes pass will sort inside raw strings

2021-12-09 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added inline comments.



Comment at: clang/unittests/Format/SortIncludesTest.cpp:1162
+ "test.cxx", 0));
+}
+

You should add a `#undef X`.


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

https://reviews.llvm.org/D115168

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


[PATCH] D115341: [clang][dataflow] Add framework for testing analyses.

2021-12-09 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel marked 2 inline comments as done.
ymandel added a comment.

Thanks for the great comments and the fast response time!




Comment at: clang/unittests/Analysis/FlowSensitive/TestingSupport.h:134
+
+transferBlock(
+BlockStates, *Block, Env, Analysis,

I've inlined `buildAnnotationToOutputStateMapping`, since it is only intended 
for use here anyhow and factoring it out didn't save anything because we still 
need to translate to typed state.



Comment at: clang/unittests/Analysis/FlowSensitive/TestingSupport.h:48
+  << std::declval())>
+std::ostream &operator<<(std::ostream &OS,
+ const DataflowAnalysisState &S) {

xazax.hun wrote:
> This would also be useful for debugging. I wonder whether utilities not 
> strictly related to testing should be closer to the actual code, so someone 
> wanting to use this for debugging does not need to include the header that is 
> dedicated to the tests.
Agreed. Added a FIXME.



Comment at: clang/unittests/Analysis/FlowSensitive/TestingSupport.h:77
+// the files provided in `VirtualMappedFiles`.
+bool runOnCode(llvm::StringRef Code,
+   const std::function &Operation,

xazax.hun wrote:
> I feel like some of our tests keep recreating lightweight versions of the 
> LibTooling. Not really an action item for this PR, just a rant :) I hope we 
> will have some more centralized stuff at some point. 
No, I agree! I missed this -- there's no good reason for runOnCode to exist. 
I've removed it and like the result a lot more. :)



Comment at: clang/unittests/Analysis/FlowSensitive/TestingSupport.h:94
+template 
+void runDataflow(
+llvm::StringRef Code,

xazax.hun wrote:
> Since this function is actually matching the dataflow results against 
> expectations, I wonder if something like `checkDataflow` would better 
> describe its function. But feel free to keep the current name.
Agreed.



Comment at: clang/unittests/Analysis/FlowSensitive/TestingSupport.h:137
+TypeErasedBlockStates =
+runTypeErasedDataflowAnalysis(*cfg, Analysis, Env);
+

xazax.hun wrote:
> Wouldn't users end up calling the template (not the type erased) version of 
> this function? I wonder if we should mimic how users would interact with the 
> framework in the tests.
I see your point and tried to move in that direction. However, it makes this 
code a lot messier because of the need to iterate again over each block with 
`transferBlock` to recoved statement level state. Since `transferBlock` is part 
of the type-erased engine, interacting with it would require mapping all of the 
state to untyped before using it, which somewhat defeats the whole purpose of 
using the typed version.

We should consider reporting statement level information from our 
`run...DataflowAnalysis` functions, which would make this iteration 
unnecessary, at which point moving to the typed version would make a lot of 
sense.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115341

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


[PATCH] D115341: [clang][dataflow] Add framework for testing analyses.

2021-12-09 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 393221.
ymandel marked 2 inline comments as done.
ymandel added a comment.

rebasing onto latest version of parent patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115341

Files:
  clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
  clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
  clang/unittests/Analysis/FlowSensitive/TestingSupport.cpp
  clang/unittests/Analysis/FlowSensitive/TestingSupport.h
  clang/unittests/Analysis/FlowSensitive/TestingSupportTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TestingSupportTest.cpp
===
--- /dev/null
+++ clang/unittests/Analysis/FlowSensitive/TestingSupportTest.cpp
@@ -0,0 +1,174 @@
+#include "TestingSupport.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Tooling/Tooling.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+using namespace dataflow;
+
+namespace {
+
+using ::clang::ast_matchers::functionDecl;
+using ::clang::ast_matchers::hasName;
+using ::clang::ast_matchers::isDefinition;
+using ::testing::_;
+using ::testing::IsEmpty;
+using ::testing::Pair;
+using ::testing::UnorderedElementsAre;
+
+class NoopLattice {
+public:
+  bool operator==(const NoopLattice &) const { return true; }
+
+  LatticeJoinEffect join(const NoopLattice &) {
+return LatticeJoinEffect::Unchanged;
+  }
+};
+
+class NoopAnalysis : public DataflowAnalysis {
+public:
+  NoopAnalysis(ASTContext &Context)
+  : DataflowAnalysis(Context) {}
+
+  static NoopLattice initialElement() { return {}; }
+
+  NoopLattice transfer(const Stmt *S, const NoopLattice &E, Environment &Env) {
+return {};
+  }
+};
+
+template 
+const FunctionDecl *findTargetFunc(ASTContext &Context, T FunctionMatcher) {
+  auto TargetMatcher =
+  functionDecl(FunctionMatcher, isDefinition()).bind("target");
+  for (const auto &Node : ast_matchers::match(TargetMatcher, Context)) {
+const auto *Func = Node.template getNodeAs("target");
+if (Func == nullptr)
+  continue;
+if (Func->isTemplated())
+  continue;
+return Func;
+  }
+  return nullptr;
+}
+
+class BuildStatementToAnnotationMappingTest : public ::testing::Test {
+public:
+  void
+  runTest(llvm::StringRef Code, llvm::StringRef TargetName,
+  std::function &)>
+  RunChecks) {
+llvm::Annotations AnnotatedCode(Code);
+auto Unit = tooling::buildASTFromCodeWithArgs(
+AnnotatedCode.code(), {"-fsyntax-only", "-std=c++17"});
+auto &Context = Unit->getASTContext();
+const FunctionDecl *Func = findTargetFunc(Context, hasName(TargetName));
+ASSERT_NE(Func, nullptr);
+
+llvm::Expected> Mapping =
+clang::dataflow::testing::buildStatementToAnnotationMapping(
+Func, AnnotatedCode);
+ASSERT_TRUE(static_cast(Mapping));
+
+RunChecks(Mapping.get());
+  }
+};
+
+TEST_F(BuildStatementToAnnotationMappingTest, ReturnStmt) {
+  runTest(R"(
+int target() {
+  return 42;
+  /*[[ok]]*/
+}
+  )",
+  "target",
+  [](const llvm::DenseMap &Annotations) {
+ASSERT_EQ(Annotations.size(), static_cast(1));
+EXPECT_TRUE(isa(Annotations.begin()->first));
+EXPECT_EQ(Annotations.begin()->second, "ok");
+  });
+}
+
+void checkDataflow(
+llvm::StringRef Code, llvm::StringRef Target,
+std::function>>,
+   ASTContext &)>
+Expectations) {
+  clang::dataflow::testing::checkDataflow(
+  Code, Target,
+  [](ASTContext &Context, Environment &) { return NoopAnalysis(Context); },
+  std::move(Expectations), {"-fsyntax-only", "-std=c++17"});
+}
+
+TEST(ProgramPointAnnotations, NoAnnotations) {
+  ::testing::MockFunction>>,
+  ASTContext &)>
+  Expectations;
+
+  EXPECT_CALL(Expectations, Call(IsEmpty(), _)).Times(1);
+
+  checkDataflow("void target() {}", "target", Expectations.AsStdFunction());
+}
+
+TEST(ProgramPointAnnotations, NoAnnotationsDifferentTarget) {
+  ::testing::MockFunction>>,
+  ASTContext &)>
+  Expectations;
+
+  EXPECT_CALL(Expectations, Call(IsEmpty(), _)).Times(1);
+
+  checkDataflow("void fun() {}", "fun", Expectations.AsStdFunction());
+}
+
+TEST(ProgramPointAnnotations, WithCodepoint) {
+  ::testing::MockFunction>>,
+  ASTContext &)>
+  Expectations;
+
+  EXPECT_CALL(Expectations,
+  Call(UnorderedElementsAre(Pair("program-point", _)), _))
+  .Times(1);
+
+  checkDataflow(R"cc(void target() {
+ int n;
+ // [[program-point]]
+   })cc",
+"target", Expectations.AsStdFunction());
+}
+
+TEST(ProgramPointAnnotations, MultipleCodepoints) {
+ 

[PATCH] D115341: [clang][dataflow] Add framework for testing analyses.

2021-12-09 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun accepted this revision.
xazax.hun added a comment.
This revision is now accepted and ready to land.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115341

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


[PATCH] D114639: Raise the minimum Visual Studio version to VS2019

2021-12-09 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

> I still don't see a need for them to be updated in lock step, especially for 
> Visual Studio which tends to be quite different from other toolchains, but I 
> can see the use of the bumps occurring within the same release version of 
> llvm if its feasible.

It's better to be in separate patches.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114639

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


[PATCH] D112024: [clang] diagnose_as attribute for Fortify diagnosing like builtins.

2021-12-09 Thread Michael Benfield via Phabricator via cfe-commits
mbenfield updated this revision to Diff 393226.
mbenfield added a comment.

Remove late parsing.

Switch dyn_cast to cast.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112024

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/ParsedAttr.h
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Sema/attr-diagnose-as-builtin.c

Index: clang/test/Sema/attr-diagnose-as-builtin.c
===
--- /dev/null
+++ clang/test/Sema/attr-diagnose-as-builtin.c
@@ -0,0 +1,118 @@
+// RUN: %clang_cc1 -Wfortify-source -triple x86_64-apple-macosx10.14.0 %s -verify
+// RUN: %clang_cc1 -Wfortify-source -xc++ -triple x86_64-apple-macosx10.14.0 %s -verify
+
+typedef unsigned long size_t;
+
+__attribute__((diagnose_as_builtin(__builtin_memcpy, 3, 1, 2))) int x; // expected-warning {{'diagnose_as_builtin' attribute only applies to functions}}
+
+void *test_memcpy(const void *src, size_t c, void *dst) __attribute__((diagnose_as_builtin(__builtin_memcpy, 3, 1, 2))) {
+  return __builtin_memcpy(dst, src, c);
+}
+
+void call_test_memcpy() {
+  char bufferA[10];
+  char bufferB[11];
+  test_memcpy(bufferB, 10, bufferA);
+  test_memcpy(bufferB, 11, bufferA); // expected-warning {{'memcpy' will always overflow; destination buffer has size 10, but size argument is 11}}
+}
+
+void failure_function_doesnt_exist() __attribute__((diagnose_as_builtin(__function_that_doesnt_exist))) {} // expected-error {{use of undeclared identifier '__function_that_doesnt_exist'}}
+
+void not_a_builtin() {}
+
+void failure_not_a_builtin() __attribute__((diagnose_as_builtin(not_a_builtin))) {} // expected-error {{'diagnose_as_builtin' attribute requires parameter 1 to be a builtin function}}
+
+void failure_too_many_parameters(void *dst, const void *src, size_t count, size_t nothing) __attribute__((diagnose_as_builtin(__builtin_memcpy, 1, 2, 3, 4))) {} // expected-error {{'diagnose_as_builtin' attribute references function '__builtin_memcpy', which takes exactly 3 arguments}}
+
+void failure_too_few_parameters(void *dst, const void *src) __attribute__((diagnose_as_builtin(__builtin_memcpy, 1, 2))) {} // expected-error{{'diagnose_as_builtin' attribute references function '__builtin_memcpy', which takes exactly 3 arguments}}
+
+void failure_not_an_integer(void *dst, const void *src, size_t count) __attribute__((diagnose_as_builtin(__builtin_memcpy, "abc", 2, 3))) {} // expected-error{{'diagnose_as_builtin' attribute requires parameter 2 to be an integer constant}}
+
+void failure_not_a_builtin2() __attribute__((diagnose_as_builtin("abc"))) {} // expected-error{{'diagnose_as_builtin' attribute requires parameter 1 to be a builtin function}}
+
+void failure_parameter_index_bounds(void *dst, const void *src) __attribute__((diagnose_as_builtin(__builtin_memcpy, 1, 2, 3))) {} // expected-error{{'diagnose_as_builtin' attribute references parameter 3, but the function 'failure_parameter_index_bounds' has only 2 parameters}}
+
+void failure_parameter_types(double dst, const void *src, size_t count) __attribute__((diagnose_as_builtin(__builtin_memcpy, 1, 2, 3))) {} // expected-error{{'diagnose_as_builtin' attribute parameter types do not match: parameter 1 of function 'failure_parameter_types' has type 'double', but parameter 1 of function '__builtin_memcpy' has type 'void *'}}
+
+void to_redeclare(void *dst, const void *src, size_t count);
+
+void use_to_redeclare() {
+  char src[10];
+  char dst[9];
+  // We shouldn't get an error yet.
+  to_redeclare(dst, src, 10);
+}
+
+void to_redeclare(void *dst, const void *src, size_t count) __attribute((diagnose_as_builtin(__builtin_memcpy, 1, 2, 3)));
+
+void error_to_redeclare() {
+  char src[10];
+  char dst[9];
+  // Now we get an error.
+  to_redeclare(dst, src, 10); // expected-warning {{'memcpy' will always overflow; destination buffer has size 9, but size argument is 10}}
+}
+
+// Make sure this works even with extra qualifiers and the pass_object_size attribute.
+void *memcpy2(void *const dst __attribute__((pass_object_size(0))), const void *src, size_t copy_amount) __attribute((diagnose_as_builtin(__builtin_memcpy, 1, 2, 3)));
+
+void call_memcpy2() {
+  char buf1[10];
+  char buf2[11];
+  memcpy2(buf1, buf2, 11); // expected-warning {{'memcpy' will always overflow; destination buffer has size 10, but size argument is 11}}
+}
+
+// We require the types to be identical, modulo canonicalization and qualifiers.
+// Maybe this could be relaxed if it proves too restrictive.
+void failure_type(void *dest, char val, size_t n) __attribute__((diagnose_as_builtin(__builtin_memset, 1, 2, 3))) {} // expected-error {{'diagnose_as_builtin' attribute parameter types do not match: parameter 2 of function 'failure_type' has type 'char', but parameter 2 of func

[PATCH] D115386: AST: Avoid using SmallVector::set_size() in UnresolvedSet

2021-12-09 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added a comment.
This revision is now accepted and ready to land.

Looks good.




Comment at: clang/lib/Sema/SemaLookup.cpp:623
 
-  Decls.set_size(N);
+  Decls.truncate(N);
 

dexonsmith wrote:
> Two things to confirm here.
> 
> First is that the destructors are trivial. From 
> clang/include/clang/AST/DeclAccessPair.h:
> ```
> lang=c++
> class DeclAccessPair {
>   uintptr_t Ptr; // we'd use llvm::PointerUnion, but it isn't trivial
> ```
> (If they hadn't been trivial, then hypothetically there could been other code 
> somewhere that ran the destructors later...)
> 
> Second is that `set_size()` was only used for truncation. I confirmed that 
> that three ways:
> - Looking backward, `N` starts as `Decls.size()` and the only changes are 
> decrement operatoers.
> - Looking forward, there's no code that would initialize / assign to the new 
> member (so if it increased size, it would likely have led to problems 
> elsewhere).
> - Tests pass.
Thanks for the details!


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

https://reviews.llvm.org/D115386

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


  1   2   >