[PATCH] D140527: [LoongArch] Add intrinsics for CACOP instruction

2022-12-21 Thread Xiaodong Liu via Phabricator via cfe-commits
XiaodongLoong created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
XiaodongLoong requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

The CACOP instruction is mainly used for cache initialization
and cache-consistency maintenance.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140527

Files:
  clang/include/clang/Basic/BuiltinsLoongArch.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/Targets/LoongArch.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Headers/larchintrin.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/LoongArch/intrinsic-la32-error.c
  clang/test/CodeGen/LoongArch/intrinsic-la32.c
  clang/test/CodeGen/LoongArch/intrinsic-la64.c
  clang/test/Driver/loongarch-default-features.c
  llvm/include/llvm/IR/IntrinsicsLoongArch.td
  llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
  llvm/lib/Target/LoongArch/LoongArchISelLowering.h
  llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
  llvm/test/CodeGen/LoongArch/intrinsic-la32-error.ll
  llvm/test/CodeGen/LoongArch/intrinsic-la32.ll
  llvm/test/CodeGen/LoongArch/intrinsic-la64-error.ll
  llvm/test/CodeGen/LoongArch/intrinsic-la64.ll

Index: llvm/test/CodeGen/LoongArch/intrinsic-la64.ll
===
--- llvm/test/CodeGen/LoongArch/intrinsic-la64.ll
+++ llvm/test/CodeGen/LoongArch/intrinsic-la64.ll
@@ -1,6 +1,7 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
 ; RUN: llc --mtriple=loongarch64 < %s | FileCheck %s
 
+declare void @llvm.loongarch.cacop.d(i64, i64, i64)
 declare i32 @llvm.loongarch.crc.w.b.w(i32, i32)
 declare i32 @llvm.loongarch.crc.w.h.w(i32, i32)
 declare i32 @llvm.loongarch.crc.w.w.w(i32, i32)
@@ -42,6 +43,15 @@
   ret i32 %res
 }
 
+define void @cacop_d(i64 %a) nounwind {
+; CHECK-LABEL: cacop_d:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:cacop 1, $a0, 4
+; CHECK-NEXT:ret
+  call void @llvm.loongarch.cacop.d(i64 1, i64 %a, i64 4)
+  ret void
+}
+
 define i32 @crc_w_d_w(i64 %a, i32 %b) nounwind {
 ; CHECK-LABEL: crc_w_d_w:
 ; CHECK:   # %bb.0:
Index: llvm/test/CodeGen/LoongArch/intrinsic-la64-error.ll
===
--- llvm/test/CodeGen/LoongArch/intrinsic-la64-error.ll
+++ llvm/test/CodeGen/LoongArch/intrinsic-la64-error.ll
@@ -1,6 +1,8 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
 ; RUN: not llc --mtriple=loongarch64 < %s 2>&1 | FileCheck %s
 
+declare void @llvm.loongarch.cacop.w(i32, i32, i32)
+declare void @llvm.loongarch.cacop.d(i64, i64, i64)
 declare i64 @llvm.loongarch.csrrd.d(i32 immarg)
 declare i64 @llvm.loongarch.csrwr.d(i64, i32 immarg)
 declare i64 @llvm.loongarch.csrxchg.d(i64, i64, i32 immarg)
@@ -46,3 +48,37 @@
   %0 = call i64 @llvm.loongarch.csrxchg.d(i64 %a, i64 %b, i32 -1)
   ret i64 %0
 }
+
+define void @cacop_w(i32 %a) nounwind {
+; CHECK: llvm.loongarch.cacop.w requires target: loongarch32
+  call void @llvm.loongarch.cacop.w(i32 1, i32 %a, i32 4)
+  ret void
+}
+
+define void @cacop_arg0_out_of_hi_range(i64 %a) nounwind {
+; CHECK: argument to 'llvm.loongarch.cacop.d' out of range
+entry:
+  call void @llvm.loongarch.cacop.d(i64 32, i64 %a, i64 1024)
+  ret void
+}
+
+define void @cacop_arg0_out_of_lo_range(i64 %a) nounwind {
+; CHECK: argument to 'llvm.loongarch.cacop.d' out of range
+entry:
+  call void @llvm.loongarch.cacop.d(i64 -1, i64 %a, i64 1024)
+  ret void
+}
+
+define void @cacop_arg2_out_of_hi_range(i64 %a) nounwind {
+; CHECK: argument to 'llvm.loongarch.cacop.d' out of range
+entry:
+  call void @llvm.loongarch.cacop.d(i64 1, i64 %a, i64 4096)
+  ret void
+}
+
+define void @cacop_arg2_out_of_lo_range(i64 %a) nounwind {
+; CHECK: argument to 'llvm.loongarch.cacop.d' out of range
+entry:
+  call void @llvm.loongarch.cacop.d(i64 1, i64 %a, i64 -4096)
+  ret void
+}
Index: llvm/test/CodeGen/LoongArch/intrinsic-la32.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/intrinsic-la32.ll
@@ -0,0 +1,13 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc --mtriple=loongarch32 < %s | FileCheck %s
+
+declare void @llvm.loongarch.cacop.w(i32, i32, i32)
+
+define void @cacop_w(i32 %a) nounwind {
+; CHECK-LABEL: cacop_w:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:cacop 1, $a0, 4
+; CHECK-NEXT:ret
+  call void @llvm.loongarch.cacop.w(i32 1, i32 %a, i32 4)
+  ret void
+}
Index: llvm/test/CodeGen/LoongArch/intrinsic-la32-error.ll
===
--- llvm/test/CodeGen/LoongArch/intrinsic-la32-error.ll
+++ llvm/test/CodeGen/LoongArch/intrinsic-la32-error.ll
@@ -1,5 +1,6 @@
 ; RUN: not llc --mtriple=loongarch32 --disable-verify < %s 2>&1 | FileCheck %s
 
+declare void @llvm.loongarch.cacop.w(i32, i32, i32)
 

[clang] 3b186db - [clang][C++20] Add test for crash in NestedRequirement.

2022-12-21 Thread Utkarsh Saxena via cfe-commits

Author: Utkarsh Saxena
Date: 2022-12-22T06:52:44+01:00
New Revision: 3b186db5a97c8392bdbb0446e84353497870551e

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

LOG: [clang][C++20] Add test for crash in NestedRequirement.

Added: 


Modified: 
clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp

Removed: 




diff  --git 
a/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp 
b/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
index c494117056105..3abff0bb32e1c 100644
--- a/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
+++ b/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
@@ -163,3 +163,20 @@ void func() {
 }
 }
 }
+
+namespace no_crash_D138914 {
+// https://reviews.llvm.org/D138914
+template  struct b;
+template  using d = b;
+template  using f = d<__is_same(a, e)>;
+template 
+concept g = f::h;
+template 
+concept i = g;
+template  class j { // expected-note {{candidate template ignored}}
+  template 
+  requires requires { requires i; }
+  j(); // expected-note {{candidate template ignored}}
+};
+template <> j(); // expected-error {{deduction guide declaration without 
trailing return type}} // expected-error {{no function template}}
+}



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


[PATCH] D138914: Make evaluation of nested requirement consistent with requires expr.

2022-12-21 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:2339
+Req->getConstraintExpr()->getSourceRange(), Satisfaction))
+  TransConstraint = Result[0];
+assert(!Trap.hasErrorOccurred() && "Substitution failures must be handled "

usaxena95 wrote:
> rtrieu wrote:
> > I have found a crash here when it access vector `Result` without checking 
> > the size first, leading to out of bounds memory access.  CReduce gave the 
> > following testcase:
> > 
> > ```
> > template  struct b;
> > template  using d = b;
> > template  using f = d<__is_same(a, e)>;
> > template 
> > concept g = f::h;
> > template 
> > concept i = g;
> > template  class j {
> >   template 
> >   requires requires { requires i; }
> >   j();
> > };
> > template <> j();
> > ```
> > 
> > `clang reduce.ii --std=c++20`
> > 
> > ```
> > assertion failed at llvm/include/llvm/ADT/SmallVector.h:294 in reference 
> > llvm::SmallVectorTemplateCommon::operator[](size_type) [T = 
> > clang::Expr *]: idx < size()
> > ...
> > ...
> > (anonymous 
> > namespace)::TemplateInstantiator::TransformNestedRequirement(clang::concepts::NestedRequirement*)
> >  clang/lib/Sema/SemaTemplateInstantiate.cpp:2339:25
> > ...
> > ...
> > ```
> Thanks for noticing and sorry for the trouble. I have fixed this forward in 
> https://github.com/llvm/llvm-project/commit/8c0aa53b07caa604d58a0d83dc571d8fcb004972.
Can you add a test case as well so if we regress we will catch it, thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138914

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


[PATCH] D140361: [RISCV] Merge Masked and unMasked RVV manual codegen

2022-12-21 Thread Piyou Chen 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 rG5370255ff18a: [RISCV] Merge Masked and unMasked RVV manual 
codegen (authored by BeMg).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140361

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/utils/TableGen/RISCVVEmitter.cpp

Index: clang/utils/TableGen/RISCVVEmitter.cpp
===
--- clang/utils/TableGen/RISCVVEmitter.cpp
+++ clang/utils/TableGen/RISCVVEmitter.cpp
@@ -171,6 +171,10 @@
 
   if (RVVI->hasManualCodegen()) {
 OS << "  DefaultPolicy = " << RVVI->getDefaultPolicyBits() << ";\n";
+if (RVVI->isMasked())
+  OS << "IsMasked = true;\n";
+else
+  OS << "IsMasked = false;\n";
 OS << RVVI->getManualCodegen();
 OS << "break;\n";
 return;
@@ -517,7 +521,6 @@
 bool SupportOverloading = R->getValueAsBit("SupportOverloading");
 bool HasBuiltinAlias = R->getValueAsBit("HasBuiltinAlias");
 StringRef ManualCodegen = R->getValueAsString("ManualCodegen");
-StringRef MaskedManualCodegen = R->getValueAsString("MaskedManualCodegen");
 std::vector IntrinsicTypes =
 R->getValueAsListOfInts("IntrinsicTypes");
 std::vector RequiredFeatures =
@@ -598,7 +601,7 @@
 Out.push_back(std::make_unique(
 Name, SuffixStr, OverloadedName, OverloadedSuffixStr, MaskedIRName,
 /*IsMasked=*/true, HasMaskedOffOperand, HasVL, MaskedPolicyScheme,
-SupportOverloading, HasBuiltinAlias, MaskedManualCodegen,
+SupportOverloading, HasBuiltinAlias, ManualCodegen,
 *MaskTypes, IntrinsicTypes, RequiredFeatures, NF,
 Policy(), IsPrototypeDefaultTU));
 if (MaskedPolicyScheme == PolicyScheme::SchemeNone)
@@ -614,7 +617,7 @@
   Name, SuffixStr, OverloadedName, OverloadedSuffixStr,
   MaskedIRName, /*IsMasked=*/true, HasMaskedOffOperand, HasVL,
   MaskedPolicyScheme, SupportOverloading, HasBuiltinAlias,
-  MaskedManualCodegen, *PolicyTypes, IntrinsicTypes,
+  ManualCodegen, *PolicyTypes, IntrinsicTypes,
   RequiredFeatures, NF, P, IsPrototypeDefaultTU));
 }
   } // End for Log2LMULList
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -19442,6 +19442,7 @@
   constexpr unsigned TAIL_AGNOSTIC = 1;
   constexpr unsigned TAIL_AGNOSTIC_MASK_AGNOSTIC = 3;
   int DefaultPolicy = TAIL_UNDISTURBED;
+  bool IsMasked = false;
 
   // Required for overloaded intrinsics.
   llvm::SmallVector IntrinsicTypes;
Index: clang/include/clang/Basic/riscv_vector.td
===
--- clang/include/clang/Basic/riscv_vector.td
+++ clang/include/clang/Basic/riscv_vector.td
@@ -217,7 +217,6 @@
 
   // Manual code in clang codegen riscv_vector_builtin_cg.inc
   code ManualCodegen = [{}];
-  code MaskedManualCodegen = [{}];
 
   // When emit the automatic clang codegen, it describes what types we have to use
   // to obtain the specific LLVM intrinsic. -1 means the return type, otherwise,
@@ -627,31 +626,18 @@
   UnMaskedPolicyScheme = HasPassthruOperand,
   ManualCodegen = [{
   {
-if (DefaultPolicy == TAIL_AGNOSTIC)
-  Ops.insert(Ops.begin(), llvm::PoisonValue::get(ResultType));
-IntrinsicTypes = {ResultType, Ops[3]->getType()};
-Ops[1] = Builder.CreateBitCast(Ops[1], ResultType->getPointerTo());
-Value *NewVL = Ops[2];
-Ops.erase(Ops.begin() + 2);
-llvm::Function *F = CGM.getIntrinsic(ID, IntrinsicTypes);
-llvm::Value *LoadValue = Builder.CreateCall(F, Ops, "");
-llvm::Value *V = Builder.CreateExtractValue(LoadValue, {0});
-// Store new_vl.
-clang::CharUnits Align =
-CGM.getNaturalPointeeTypeAlignment(E->getArg(1)->getType());
-llvm::Value *Val = Builder.CreateExtractValue(LoadValue, {1});
-Builder.CreateStore(Val, Address(NewVL, Val->getType(), Align));
-return V;
-  }
-  }],
-  MaskedManualCodegen = [{
-  {
-// Move mask to right before vl.
-std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end() - 1);
-if (DefaultPolicy == TAIL_AGNOSTIC_MASK_AGNOSTIC)
-  Ops.insert(Ops.begin(), llvm::PoisonValue::get(ResultType));
-Ops.push_back(ConstantInt::get(Ops.back()->getType(), DefaultPolicy));
-IntrinsicTypes = {ResultType, Ops[4]->getType()};
+if (IsMasked) {
+  // Move mask to right before vl.
+  std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end() - 1);
+  if (DefaultPolicy == TAIL_AGNOSTIC_MASK_AGNOSTIC)
+   

[clang] 5370255 - [RISCV] Merge Masked and unMasked RVV manual codegen

2022-12-21 Thread Piyou Chen via cfe-commits

Author: Piyou Chen
Date: 2022-12-21T20:28:12-08:00
New Revision: 5370255ff18ac101a73685b77615148142ee7552

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

LOG: [RISCV] Merge Masked and unMasked RVV manual codegen

RVV intrinsic function will generate riscv_vector_builtin_cg.inc for 
CGBuiltin.cpp to produce the corresponding RVV intrinsic LLVM IR.

In this stage, riscv_vector.td will describe the bunch of manual codegen C++ 
code to tell CGBuiltin how to handle these instructions.

In this patch, we merge the masked RVV manual codegen and unmasked RVV manual 
codegen to reduce the number of manual codegen, and make more policy addition 
easier in the future.

This is a clean-up job that will not affect the RVV intrinsic functionality.

Reviewed By: kito-cheng

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

Added: 


Modified: 
clang/include/clang/Basic/riscv_vector.td
clang/lib/CodeGen/CGBuiltin.cpp
clang/utils/TableGen/RISCVVEmitter.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/riscv_vector.td 
b/clang/include/clang/Basic/riscv_vector.td
index 90e18df0403e0..7dbd331b2c5ec 100644
--- a/clang/include/clang/Basic/riscv_vector.td
+++ b/clang/include/clang/Basic/riscv_vector.td
@@ -217,7 +217,6 @@ class RVVBuiltin types> {
   UnMaskedPolicyScheme = HasPassthruOperand,
   ManualCodegen = [{
   {
-if (DefaultPolicy == TAIL_AGNOSTIC)
-  Ops.insert(Ops.begin(), llvm::PoisonValue::get(ResultType));
-IntrinsicTypes = {ResultType, Ops[3]->getType()};
-Ops[1] = Builder.CreateBitCast(Ops[1], ResultType->getPointerTo());
-Value *NewVL = Ops[2];
-Ops.erase(Ops.begin() + 2);
-llvm::Function *F = CGM.getIntrinsic(ID, IntrinsicTypes);
-llvm::Value *LoadValue = Builder.CreateCall(F, Ops, "");
-llvm::Value *V = Builder.CreateExtractValue(LoadValue, {0});
-// Store new_vl.
-clang::CharUnits Align =
-CGM.getNaturalPointeeTypeAlignment(E->getArg(1)->getType());
-llvm::Value *Val = Builder.CreateExtractValue(LoadValue, {1});
-Builder.CreateStore(Val, Address(NewVL, Val->getType(), Align));
-return V;
-  }
-  }],
-  MaskedManualCodegen = [{
-  {
-// Move mask to right before vl.
-std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end() - 1);
-if (DefaultPolicy == TAIL_AGNOSTIC_MASK_AGNOSTIC)
-  Ops.insert(Ops.begin(), llvm::PoisonValue::get(ResultType));
-Ops.push_back(ConstantInt::get(Ops.back()->getType(), DefaultPolicy));
-IntrinsicTypes = {ResultType, Ops[4]->getType()};
+if (IsMasked) {
+  // Move mask to right before vl.
+  std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end() - 1);
+  if (DefaultPolicy == TAIL_AGNOSTIC_MASK_AGNOSTIC)
+Ops.insert(Ops.begin(), llvm::PoisonValue::get(ResultType));
+  Ops.push_back(ConstantInt::get(Ops.back()->getType(), 
DefaultPolicy));
+  IntrinsicTypes = {ResultType, Ops[4]->getType()};
+} else {
+  if (DefaultPolicy == TAIL_AGNOSTIC)
+Ops.insert(Ops.begin(), llvm::PoisonValue::get(ResultType));
+  IntrinsicTypes = {ResultType, Ops[3]->getType()};
+}
 Ops[1] = Builder.CreateBitCast(Ops[1], ResultType->getPointerTo());
 Value *NewVL = Ops[2];
 Ops.erase(Ops.begin() + 2);
@@ -659,8 +645,11 @@ multiclass RVVVLEFFBuiltin types> {
 llvm::Value *LoadValue = Builder.CreateCall(F, Ops, "");
 llvm::Value *V = Builder.CreateExtractValue(LoadValue, {0});
 // Store new_vl.
-clang::CharUnits Align = CGM.getNaturalPointeeTypeAlignment(
-E->getArg(E->getNumArgs()-2)->getType());
+clang::CharUnits Align;
+if (IsMasked)
+  Align = 
CGM.getNaturalPointeeTypeAlignment(E->getArg(E->getNumArgs()-2)->getType());
+else
+  Align = CGM.getNaturalPointeeTypeAlignment(E->getArg(1)->getType());
 llvm::Value *Val = Builder.CreateExtractValue(LoadValue, {1});
 Builder.CreateStore(Val, Address(NewVL, Val->getType(), Align));
 return V;
@@ -720,16 +709,18 @@ multiclass RVVIndexedLoad {
 let HasMaskedOffOperand = false,
 MaskedPolicyScheme = NonePolicy,
 ManualCodegen = [{
-  // Builtin: (ptr, value, vl). Intrinsic: (value, ptr, vl)
-  std::swap(Ops[0], Ops[1]);
-  Ops[1] = Builder.CreateBitCast(Ops[1], 
Ops[0]->getType()->getPointerTo());
-  IntrinsicTypes = {Ops[0]->getType(), Ops[2]->getType()};
-}],
-MaskedManualCodegen= [{
-  // Builtin: (mask, ptr, value, vl). Intrinsic: (value, ptr, mask, vl)
-  std::swap(Ops[0], Ops[2]);
+  if (IsMasked) {
+// Builtin: (mask, ptr, value, vl). 

[PATCH] D140011: [clang][compiler-rt] Support LLVM_ENABLE_PER_TARGET_RUNTIME_DIR on Arm Linux and BSD

2022-12-21 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay 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/D140011/new/

https://reviews.llvm.org/D140011

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


[PATCH] D138914: Make evaluation of nested requirement consistent with requires expr.

2022-12-21 Thread Utkarsh Saxena via Phabricator via cfe-commits
usaxena95 marked an inline comment as done.
usaxena95 added inline comments.



Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:2339
+Req->getConstraintExpr()->getSourceRange(), Satisfaction))
+  TransConstraint = Result[0];
+assert(!Trap.hasErrorOccurred() && "Substitution failures must be handled "

rtrieu wrote:
> I have found a crash here when it access vector `Result` without checking the 
> size first, leading to out of bounds memory access.  CReduce gave the 
> following testcase:
> 
> ```
> template  struct b;
> template  using d = b;
> template  using f = d<__is_same(a, e)>;
> template 
> concept g = f::h;
> template 
> concept i = g;
> template  class j {
>   template 
>   requires requires { requires i; }
>   j();
> };
> template <> j();
> ```
> 
> `clang reduce.ii --std=c++20`
> 
> ```
> assertion failed at llvm/include/llvm/ADT/SmallVector.h:294 in reference 
> llvm::SmallVectorTemplateCommon::operator[](size_type) [T = 
> clang::Expr *]: idx < size()
> ...
> ...
> (anonymous 
> namespace)::TemplateInstantiator::TransformNestedRequirement(clang::concepts::NestedRequirement*)
>  clang/lib/Sema/SemaTemplateInstantiate.cpp:2339:25
> ...
> ...
> ```
Thanks for noticing and sorry for the trouble. I have fixed this forward in 
https://github.com/llvm/llvm-project/commit/8c0aa53b07caa604d58a0d83dc571d8fcb004972.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138914

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


[clang] 8c0aa53 - Fix out-of-bound access in TransformNestedRequirement.

2022-12-21 Thread Utkarsh Saxena via cfe-commits

Author: Utkarsh Saxena
Date: 2022-12-22T05:20:31+01:00
New Revision: 8c0aa53b07caa604d58a0d83dc571d8fcb004972

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

LOG: Fix out-of-bound access in TransformNestedRequirement.

Added: 


Modified: 
clang/lib/Sema/SemaTemplateInstantiate.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index b23ae5c83d9e6..c4531470119bd 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -2335,7 +2335,8 @@ TemplateInstantiator::TransformNestedRequirement(
 llvm::SmallVector Result;
 if (!SemaRef.CheckConstraintSatisfaction(
 nullptr, {Req->getConstraintExpr()}, Result, TemplateArgs,
-Req->getConstraintExpr()->getSourceRange(), Satisfaction))
+Req->getConstraintExpr()->getSourceRange(), Satisfaction) &&
+!Result.empty())
   TransConstraint = Result[0];
 assert(!Trap.hasErrorOccurred() && "Substitution failures must be handled "
"by CheckConstraintSatisfaction.");



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


[PATCH] D137517: [TargetParser] Generate the defs for RISCV CPUs using llvm-tblgen.

2022-12-21 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

In D137517#4012298 , @pcwang-thead 
wrote:

> In D137517#4009175 , @fpetrogalli 
> wrote:
>
>> @pcwang-thead, I addressed some of your comments.
>>
>> The value of `EnumFeatures` is now computed dynamicaly from the
>> `Features` field of the `Processor` class.
>
> Thanks! That sounds great to me!
>
>> As for generating `MArch` out of the `Features` field, @craig.topper
>> pointed me at
>> https://github.com/riscv-non-isa/riscv-toolchain-conventions/issues/11. From
>> the reading of it, it seems that the alphabetical order is enough to
>> build the string that carries `MArch`. Am I missing something?
>
> Currently, I think the alphabetical order is OK. If we relax the checking of 
> arch string someday, there is no doubt that we should change the 
> implementation here too.

The currently accepted order isn’t alphabetical. The single letter extensions 
have a specific order. The z extensions are ordered by looking up the second 
letter in the single letter order. If we alphabetize here i don’t think it will 
be accepted by the frontend.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137517

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


[PATCH] D137517: [TargetParser] Generate the defs for RISCV CPUs using llvm-tblgen.

2022-12-21 Thread Wang Pengcheng via Phabricator via cfe-commits
pcwang-thead added a comment.

In D137517#4009175 , @fpetrogalli 
wrote:

> @pcwang-thead, I addressed some of your comments.
>
> The value of `EnumFeatures` is now computed dynamicaly from the
> `Features` field of the `Processor` class.

Thanks! That sounds great to me!

> As for generating `MArch` out of the `Features` field, @craig.topper
> pointed me at
> https://github.com/riscv-non-isa/riscv-toolchain-conventions/issues/11. From
> the reading of it, it seems that the alphabetical order is enough to
> build the string that carries `MArch`. Am I missing something?

Currently, I think the alphabetical order is OK. If we relax the checking of 
arch string someday, there is no doubt that we should change the implementation 
here too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137517

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


[PATCH] D127812: [AArch64] FMV support and necessary target features dependencies.

2022-12-21 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D127812#4011437 , @hctim wrote:

> LDFLAGS="$LDFLAGS -Wl,--rpath=/tmp/2/lib" # < use the instrumented libcxx 
> from step 2

I think -Wl,-rpath and -isystem are somewhat different.

  sanitizer_ldflags="-Wl,--rpath=$libcxx_out/lib/x86_64-unknown-linux-gnu 
-L$libcxx_out/lib/x86_64-unknown-linux-gnu -lc++abi"
  sanitizer_cflags="-nostdinc++ 
-isystem$libcxx_out/include/x86_64-unknown-linux-gnu/c++/v1 
-isystem$libcxx_out/include/c++/v1"

I use:

  ninja -C ~/llvm/out/stable llvm-ar clang lld msan compiler-rt-headers
  
  LLVM_COMMON=(-GNinja -DCMAKE_CXX_COMPILER=$HOME/llvm/out/stable/bin/clang++ 
-DCMAKE_C_COMPILER=$HOME/llvm/out/stable/bin/clang 
-DCMAKE_CXX_ARCHIVE_CREATE="$HOME/llvm/out/stable/bin/llvm-ar qcS --thin 
 " -DCMAKE_CXX_ARCHIVE_FINISH=: -DLLVM_APPEND_VC_REV=OFF 
-DLLVM_ENABLE_LLD=On -DLLVM_TARGETS_TO_BUILD=host 
-DLLVM_TABLEGEN=/tmp/Rel/bin/llvm-tblgen -DCLANG_ENABLE_ARCMT=off 
-DCLANG_ENABLE_STATIC_ANALYZER=off -DCLANG_TABLEGEN=/tmp/Rel/bin/clang-tblgen)
  
  libcxx_out=$HOME/llvm/out/msan-libcxx
  cmake -Sruntimes -B$libcxx_out $LLVM_COMMON -DCMAKE_BUILD_TYPE=Release 
-DLLVM_ENABLE_RUNTIMES='libcxx;libcxxabi' 
-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=on -DLLVM_USE_SANITIZER=Memory
  ninja -C $libcxx_out cxx cxxabi
  
  sanitizer_ldflags="-Wl,--rpath=$libcxx_out/lib/x86_64-unknown-linux-gnu 
-L$libcxx_out/lib/x86_64-unknown-linux-gnu -lc++abi"
  sanitizer_cflags="-nostdinc++ 
-isystem$libcxx_out/include/x86_64-unknown-linux-gnu/c++/v1 
-isystem$libcxx_out/include/c++/v1"
  # See http://llvm.org/bugs/show_bug.cgi?id=19071, 
http://www.cmake.org/Bug/view.php?id=15264
  sanitizer_cflags="$sanitizer_cflags $sanitizer_ldflags -fsanitize=memory -w"
  cmake -Hllvm -B/tmp/out/msan ${LLVM_COMMON} -DCMAKE_BUILD_TYPE=Release 
-DLLVM_ENABLE_PROJECTS='clang;lld' -DCMAKE_C_FLAGS=$sanitizer_cflags 
-DCMAKE_CXX_FLAGS=$sanitizer_cflags -DCMAKE_EXE_LINKER_FLAGS=$sanitizer_ldflags 
-DCMAKE_SHARED_LINKER_FLAGS=$sanitizer_ldflags -DLLVM_ENABLE_LIBCXX=On 
-DLLVM_USE_SPLIT_DWARF=On -DLLVM_USE_SANITIZER=Memory


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127812

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


[PATCH] D127812: [AArch64] FMV support and necessary target features dependencies.

2022-12-21 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

In D127812#4012276 , @ilinpv wrote:

> I've managed to reproduce "MemorySanitizer: use-of-uninitialized-value" error 
> locally, thank you @hctim for help!
> If I understand it right, it seems **MSan didn't handle correctly 
> SmallVector** - a variable-sized array with some number of elements in-place 
> and heap allocation for additional elements if needed:
>
>   clang/lib/Sema/SemaDeclAttr.cpp:3615 SmallVector, 2> 
> StringsBuffer;
>
> There were 2 elements in-placed for StringsBuffer and tests which require 3 
> failed with MSan use-of-uninitialized-value error. 
> With number of StringsBuffer in-placed elements set to 3
>
>   SmallVector, 3> StringsBuffer;
>
> all use-of-uninitialized-value errors have gone.

I'm not sure "MSan didn't handle correctly SmallVector" is the case. Given your 
diagnosis of 3-elements-vs-2, I'm guessing the root cause is that 
`clang/lib/Sema/SemaDecl.cpp:11369` is wrong:

  !std::equal(CurClones->featuresStrs_begin(),
  CurClones->featuresStrs_end(),
  NewClones->featuresStrs_begin( {

This construction of `std::equal` is very error-prone, as if `NewClones.size() 
< CurClones.size()`, then this invariable leads to buffer-overflow. I'm 
wondering if that's the underlying cause, it would seem entirely possible that 
expanding the in-place elements are always "initialized" from MSan's 
perspective and so the current code has a false-negative, and your new code 
made it so that the vector is now heap-based, which is revealing the underlying 
issue. Maybe worth trying one more thing and adding an 
`assert(CurClones->size() <= NewClones->size());` to double check?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127812

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


[PATCH] D138914: Make evaluation of nested requirement consistent with requires expr.

2022-12-21 Thread Richard Trieu via Phabricator via cfe-commits
rtrieu added inline comments.



Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:2339
+Req->getConstraintExpr()->getSourceRange(), Satisfaction))
+  TransConstraint = Result[0];
+assert(!Trap.hasErrorOccurred() && "Substitution failures must be handled "

I have found a crash here when it access vector `Result` without checking the 
size first, leading to out of bounds memory access.  CReduce gave the following 
testcase:

```
template  struct b;
template  using d = b;
template  using f = d<__is_same(a, e)>;
template 
concept g = f::h;
template 
concept i = g;
template  class j {
  template 
  requires requires { requires i; }
  j();
};
template <> j();
```

`clang reduce.ii --std=c++20`

```
assertion failed at llvm/include/llvm/ADT/SmallVector.h:294 in reference 
llvm::SmallVectorTemplateCommon::operator[](size_type) [T = 
clang::Expr *]: idx < size()
...
...
(anonymous 
namespace)::TemplateInstantiator::TransformNestedRequirement(clang::concepts::NestedRequirement*)
 clang/lib/Sema/SemaTemplateInstantiate.cpp:2339:25
...
...
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138914

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


[PATCH] D127812: [AArch64] FMV support and necessary target features dependencies.

2022-12-21 Thread Pavel Iliin via Phabricator via cfe-commits
ilinpv added a comment.

I've managed to reproduce "MemorySanitizer: use-of-uninitialized-value" error 
locally, thank you @hctim for help!
If I understand it right, it seems **MSan didn't handle correctly SmallVector** 
- a variable-sized array with some number of elements in-place and heap 
allocation for additional elements if needed:

  clang/lib/Sema/SemaDeclAttr.cpp:3615 SmallVector, 2> 
StringsBuffer;

There were 2 elements in-placed for StringsBuffer and tests which require 3 
failed with MSan use-of-uninitialized-value error. 
With number of StringsBuffer in-placed elements set to 3

  SmallVector, 3> StringsBuffer;

all use-of-uninitialized-value errors have gone.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127812

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


[PATCH] D137415: [clang][Interp] Implement switch statements

2022-12-21 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeStmtGen.cpp:405
+  const Expr *Cond = S->getCond();
+  PrimType CondT = this->classifyPrim(Cond->getType());
+

The condition could be a class type w/ a conversion operator, this does not 
seem like it will handle this case. Maybe b/c you don't handle conversion 
operators yet but might be worth a `FIXME` or `TODO`.


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

https://reviews.llvm.org/D137415

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


[PATCH] D136694: [clang][Interp] Check that constructor calls initialize all record fields

2022-12-21 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik accepted this revision.
shafik added a comment.

LGTM




Comment at: clang/lib/AST/Interp/Interp.cpp:1
 //===--- Interpcpp - Interpreter for the constexpr VM --*- C++ -*-===//
 //

One more time :-)


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

https://reviews.llvm.org/D136694

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


[PATCH] D139496: [CMake] Add perf profiling for clang-bolt

2022-12-21 Thread Amir Ayupov via Phabricator via cfe-commits
Amir updated this revision to Diff 484727.
Amir added a comment.

Convert perf profile using perf2bolt (aggregate-only mode)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139496

Files:
  clang/CMakeLists.txt
  clang/cmake/caches/BOLT.cmake
  llvm/docs/AdvancedBuilds.rst

Index: llvm/docs/AdvancedBuilds.rst
===
--- llvm/docs/AdvancedBuilds.rst
+++ llvm/docs/AdvancedBuilds.rst
@@ -241,6 +241,62 @@
 
   $ ninja stage2-clang-bolt
 
+BOLT profile
+
+BOLT uses the profile collected by either Linux `perf` or via BOLT's own
+instrumentation. Both modes are supported by CMake automation, with
+instrumentation being the default (`-DCLANG_BOLT=INSTRUMENT`).
+
+It's strongly recommended to use `perf` if host system supports it as it
+is a significantly faster and potentially more reliable method:
+
+.. code-block:: console
+
+  $ cmake <...> -DCLANG_BOLT=perf \
+  -C /clang/cmake/caches/BOLT.cmake
+
+If the host system supports profiling branch stacks (e.g. AMD or Intel LBR
+(Last Branch Record), Armv9-A BRBE (Branch Record Buffer Extension)), it can be
+enabled with `-DCLANG_BOLT=LBR` to further improve the profile quality:
+
+.. code-block:: console
+
+  $ cmake <...> -DCLANG_BOLT=LBR \
+  -C /clang/cmake/caches/BOLT.cmake
+
+The following matrix describes supported profiling methods. Note that Linux/ELF
+is the only supported platform.
+
+ ===
+Architecture `-DCLANG_BOLT` value
+  -- ---
+ `Instrument` `perf` `LBR`
+  == ===
+x86_64   Yes  YesYes
+AArch64  No   YesNo HW exist
+  == ===
+
+Profiling variables
+---
+BOLT profile is collected from building one of in-tree projects/targets with
+Clang as a workload. The following configuration options can be used to change
+the profiling build and profiling mechanism:
+
+**CLANG_BOLT**
+  Profiling mechanism to be used. Supported values: `Instrument` (default),
+  `perf` (requires OS support), `LBR` (requires hardware support).
+
+**CLANG_BOLT_PROJECTS**
+  Projects to enable in profiling build. Defaults to `llvm`.
+
+**CLANG_BOLT_TARGETS**
+  Targets to build in profiling build. Defaults to `count` in instrumentation
+  build and `FileCheck` in perf-build.
+
+**CLANG_BOLT_EXTRA_CMAKE_FLAGS**
+  Extra CMake flags to pass to profiling build at configuration time.
+
+
 3-Stage Non-Determinism
 ===
 
Index: clang/cmake/caches/BOLT.cmake
===
--- clang/cmake/caches/BOLT.cmake
+++ clang/cmake/caches/BOLT.cmake
@@ -1,15 +1,17 @@
 set(CMAKE_BUILD_TYPE Release CACHE STRING "")
-set(CLANG_BOLT_INSTRUMENT ON CACHE BOOL "")
-set(CLANG_BOLT_INSTRUMENT_PROJECTS "llvm" CACHE STRING "")
-set(CLANG_BOLT_INSTRUMENT_TARGETS "count" CACHE STRING "")
+set(CLANG_BOLT "INSTRUMENT" CACHE STRING "Apply BOLT optimization to Clang. \
+  May be specified as Instrument or Perf or LBR to use a particular profiling \
+  mechanism.")
+
+set(CLANG_BOLT_PROJECTS "llvm" CACHE STRING "")
+string(TOUPPER "${CLANG_BOLT}" uppercase_CLANG_BOLT)
+if (uppercase_CLANG_BOLT STREQUAL "INSTRUMENT")
+  set(CLANG_BOLT_TARGETS "count" CACHE STRING "")
+else()
+  set(CLANG_BOLT_TARGETS "FileCheck" CACHE STRING "")
+endif()
 set(CMAKE_EXE_LINKER_FLAGS "-Wl,--emit-relocs,-znow" CACHE STRING "")
-set(CLANG_BOLT_INSTRUMENT_EXTRA_CMAKE_FLAGS "" CACHE STRING "")
+set(CLANG_BOLT_EXTRA_CMAKE_FLAGS "" CACHE STRING "")
 
 set(LLVM_ENABLE_PROJECTS "bolt;clang" CACHE STRING "")
 set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
-
-# Disable function splitting enabled by default in GCC8+
-if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
-  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-reorder-blocks-and-partition")
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-reorder-blocks-and-partition")
-endif()
Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -869,67 +869,106 @@
   endforeach()
 endif()
 
-if (CLANG_BOLT_INSTRUMENT AND NOT LLVM_BUILD_INSTRUMENTED)
+if (CLANG_BOLT AND NOT LLVM_BUILD_INSTRUMENTED)
   set(CLANG_PATH ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang)
   set(CLANGXX_PATH ${CLANG_PATH}++)
-  set(CLANG_INSTRUMENTED ${CLANG_PATH}-bolt.inst)
-  set(CLANGXX_INSTRUMENTED ${CLANGXX_PATH}-bolt.inst)
   set(CLANG_OPTIMIZED ${CLANG_PATH}-bolt)
   set(CLANGXX_OPTIMIZED ${CLANGXX_PATH}-bolt)
 
-  # Instrument clang with BOLT
-  add_custom_target(clang-instrumented
-DEPENDS ${CLANG_INSTRUMENTED}
-  )
-  add_custom_command(OUTPUT ${CLANG_INSTRUMENTED}
-DEPENDS clang llvm-bolt
-COMMAND llvm-bolt ${CLANG_PATH} -o ${CLANG_INSTRUMENTED}
-  -instrument 

[PATCH] D139168: [C++20] [Modules] [ClangScanDeps] Enable to print make-style dependency file within P1689 format (4/4)

2022-12-21 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

@Bigcheese @jansvoboda11 gentle ping~


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

https://reviews.llvm.org/D139168

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


[PATCH] D140433: [Clang] Add `nvptx-arch` tool to query installed NVIDIA GPUs

2022-12-21 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 accepted this revision.
tianshilei1992 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/D140433/new/

https://reviews.llvm.org/D140433

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


[PATCH] D127812: [AArch64] FMV support and necessary target features dependencies.

2022-12-21 Thread Pavel Iliin via Phabricator via cfe-commits
ilinpv added a comment.

In D127812#4011437 , @hctim wrote:

> 2. Build a sanitizer libcxx.
>
>   $ cd /tmp/2
>   $ cmake \
>   -DCMAKE_C_COMPILER=/tmp/1/bin/clang \
>   -DCMAKE_CXX_COMPILER=/tmp/1/bin/clang++ \
>   -GNinja \
>   -DLLVM_USE_SANITIZER=Memory \
>   -DCMAKE_BUILD_TYPE=Release \
>   -DLLVM_ENABLE_ASSERTIONS=ON \
>   -DLLVM_ENABLE_RUNTIMES="'libcxx;libcxxabi'" \
>   -DLLVM_USE_LINKER="'lld'" \
>   /path/to/llvm/runtimes/ # < Make sure this is *runtimes*, not llvm.
>   $ ninja cxx cxxabi

Thank you for help! On second step pointing to llvm-project/llvm/runtimes/ I 
got:

  CMake Error at CMakeLists.txt:29 (include):   

include could not find requested file:  



  LLVMExternalProjectUtils 
  ...
  CMake Error at CMakeLists.txt:379 (if):
if given arguments:
  
  "openmp" "IN_LIST" "LLVM_ENABLE_RUNTIMES"
  
Unknown arguments specified

   


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127812

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


[PATCH] D140508: [clang] fix -Wuninitialized for asm goto outputs on indirect edges.

2022-12-21 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 484699.
nickdesaulniers edited the summary of this revision.
nickdesaulniers added a comment.

- reference 3a604fdbcd5f 
 in commit 
message as well


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140508

Files:
  clang/lib/Analysis/UninitializedValues.cpp
  clang/test/Analysis/uninit-asm-goto.cpp

Index: clang/test/Analysis/uninit-asm-goto.cpp
===
--- clang/test/Analysis/uninit-asm-goto.cpp
+++ clang/test/Analysis/uninit-asm-goto.cpp
@@ -9,9 +9,9 @@
 return -1;
 }
 
+// test2: Expect no diagnostics
 int test2(int x) {
-  int y; // expected-warning {{variable 'y' is used uninitialized whenever its declaration is reached}}
- // expected-note@-1 {{initialize the variable}}
+  int y;
   if (x < 42)
 asm goto("" : "+S"(x), "+D"(y) : "r"(x) :: indirect_1, indirect_2);
   else
@@ -20,29 +20,29 @@
 indirect_1:
   return -42;
 indirect_2:
-  return y; // expected-note {{uninitialized use occurs here}}
+  return y;
 }
 
+// test3: Expect no diagnostics
 int test3(int x) {
-  int y; // expected-warning {{variable 'y' is used uninitialized whenever its declaration is reached}}
- // expected-note@-1 {{initialize the variable}}
+  int y;
   asm goto("" : "="(y) : "r"(x) : : fail);
 normal:
   y += x;
   return y;
   if (x) {
 fail:
-return y; // expected-note {{uninitialized use occurs here}}
+return y;
   }
   return 0;
 }
 
+// test4: Expect no diagnostics
 int test4(int x) {
-  int y; // expected-warning {{variable 'y' is used uninitialized whenever its declaration is reached}}
- // expected-note@-1 {{initialize the variable}}
+  int y;
   goto forward;
 backward:
-  return y; // expected-note {{uninitialized use occurs here}}
+  return y;
 forward:
   asm goto("" : "=r"(y) : "r"(x) : : backward);
   return y;
@@ -70,23 +70,40 @@
   return -1;
 }
 
+// test7: Expect no diagnostics.
 int test7(int z) {
-int x; // expected-warning {{variable 'x' is used uninitialized whenever its declaration is reached}}
-   // expected-note@-1 {{initialize the variable 'x' to silence this warning}}
+int x;
 if (z)
   asm goto ("":"=r"(x):::A1,A2);
 return 0;
 A1:
 A2:
-return x; // expected-note {{uninitialized use occurs here}}
+return x;
 }
 
+// test8: Expect no diagnostics
 int test8() {
-int x = 0; // expected-warning {{variable 'x' is used uninitialized whenever its declaration is reached}}
-   // expected-note@-1 {{variable 'x' is declared here}}
+int x = 0;
 asm goto ("":"=r"(x):::A1,A2);
 return 0;
 A1:
 A2:
-return x; // expected-note {{uninitialized use occurs here}}
+return x;
+}
+
+// test9: Expect no diagnostics
+int test9 (int x) {
+int y;
+asm goto("": "=r"(y) :::out);
+return 42;
+out:
+return y;
+}
+
+int test10() {
+  int y; // expected-note {{initialize the variable 'y' to silence this warning}}
+  asm goto(""out);
+  return 42;
+out:
+  return y; // expected-warning {{variable 'y' is uninitialized when used here}}
 }
Index: clang/lib/Analysis/UninitializedValues.cpp
===
--- clang/lib/Analysis/UninitializedValues.cpp
+++ clang/lib/Analysis/UninitializedValues.cpp
@@ -586,28 +586,6 @@
   continue;
 }
 
-if (AtPredExit == MayUninitialized) {
-  // If the predecessor's terminator is an "asm goto" that initializes
-  // the variable, then don't count it as "initialized" on the indirect
-  // paths.
-  CFGTerminator term = Pred->getTerminator();
-  if (const auto *as = dyn_cast_or_null(term.getStmt())) {
-const CFGBlock *fallthrough = *Pred->succ_begin();
-if (as->isAsmGoto() &&
-llvm::any_of(as->outputs(), [&](const Expr *output) {
-return vd == findVar(output).getDecl() &&
-llvm::any_of(as->labels(),
- [&](const AddrLabelExpr *label) {
-  return label->getLabel()->getStmt() == B->Label &&
-  B != fallthrough;
-});
-})) {
-  Use.setUninitAfterDecl();
-  continue;
-}
-  }
-}
-
 unsigned  = SuccsVisited[Pred->getBlockID()];
 if (!SV) {
   // When visiting the first successor of a block, mark all NULL
@@ -820,7 +798,8 @@
 // it's used on an indirect path, where it's not guaranteed to be
 // defined.
 if (const VarDecl *VD = findVar(Ex).getDecl())
-  vals[VD] = MayUninitialized;
+  if (vals[VD] != Initialized)
+vals[VD] = MayUninitialized;
   }
 }
 

[PATCH] D140508: [clang] fix -Wuninitialized for asm goto outputs on indirect edges.

2022-12-21 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers created this revision.
Herald added a reviewer: NoQ.
Herald added a project: All.
nickdesaulniers requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Now that we support outputs from asm goto along indirect edges, we can
remove/revert some code that was added to help warn about the previous
limitation that outputs were not supported along indirect edges.

Reverts code added in:
commit 72aa619a7fe0 
 ("Warn of 
uninitialized variables on asm goto's indirect branch")
But keeps+updates the tests.

Link: https://github.com/llvm/llvm-project/issues/53562


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140508

Files:
  clang/lib/Analysis/UninitializedValues.cpp
  clang/test/Analysis/uninit-asm-goto.cpp

Index: clang/test/Analysis/uninit-asm-goto.cpp
===
--- clang/test/Analysis/uninit-asm-goto.cpp
+++ clang/test/Analysis/uninit-asm-goto.cpp
@@ -9,9 +9,9 @@
 return -1;
 }
 
+// test2: Expect no diagnostics
 int test2(int x) {
-  int y; // expected-warning {{variable 'y' is used uninitialized whenever its declaration is reached}}
- // expected-note@-1 {{initialize the variable}}
+  int y;
   if (x < 42)
 asm goto("" : "+S"(x), "+D"(y) : "r"(x) :: indirect_1, indirect_2);
   else
@@ -20,29 +20,29 @@
 indirect_1:
   return -42;
 indirect_2:
-  return y; // expected-note {{uninitialized use occurs here}}
+  return y;
 }
 
+// test3: Expect no diagnostics
 int test3(int x) {
-  int y; // expected-warning {{variable 'y' is used uninitialized whenever its declaration is reached}}
- // expected-note@-1 {{initialize the variable}}
+  int y;
   asm goto("" : "="(y) : "r"(x) : : fail);
 normal:
   y += x;
   return y;
   if (x) {
 fail:
-return y; // expected-note {{uninitialized use occurs here}}
+return y;
   }
   return 0;
 }
 
+// test4: Expect no diagnostics
 int test4(int x) {
-  int y; // expected-warning {{variable 'y' is used uninitialized whenever its declaration is reached}}
- // expected-note@-1 {{initialize the variable}}
+  int y;
   goto forward;
 backward:
-  return y; // expected-note {{uninitialized use occurs here}}
+  return y;
 forward:
   asm goto("" : "=r"(y) : "r"(x) : : backward);
   return y;
@@ -70,23 +70,40 @@
   return -1;
 }
 
+// test7: Expect no diagnostics.
 int test7(int z) {
-int x; // expected-warning {{variable 'x' is used uninitialized whenever its declaration is reached}}
-   // expected-note@-1 {{initialize the variable 'x' to silence this warning}}
+int x;
 if (z)
   asm goto ("":"=r"(x):::A1,A2);
 return 0;
 A1:
 A2:
-return x; // expected-note {{uninitialized use occurs here}}
+return x;
 }
 
+// test8: Expect no diagnostics
 int test8() {
-int x = 0; // expected-warning {{variable 'x' is used uninitialized whenever its declaration is reached}}
-   // expected-note@-1 {{variable 'x' is declared here}}
+int x = 0;
 asm goto ("":"=r"(x):::A1,A2);
 return 0;
 A1:
 A2:
-return x; // expected-note {{uninitialized use occurs here}}
+return x;
+}
+
+// test9: Expect no diagnostics
+int test9 (int x) {
+int y;
+asm goto("": "=r"(y) :::out);
+return 42;
+out:
+return y;
+}
+
+int test10() {
+  int y; // expected-note {{initialize the variable 'y' to silence this warning}}
+  asm goto(""out);
+  return 42;
+out:
+  return y; // expected-warning {{variable 'y' is uninitialized when used here}}
 }
Index: clang/lib/Analysis/UninitializedValues.cpp
===
--- clang/lib/Analysis/UninitializedValues.cpp
+++ clang/lib/Analysis/UninitializedValues.cpp
@@ -586,28 +586,6 @@
   continue;
 }
 
-if (AtPredExit == MayUninitialized) {
-  // If the predecessor's terminator is an "asm goto" that initializes
-  // the variable, then don't count it as "initialized" on the indirect
-  // paths.
-  CFGTerminator term = Pred->getTerminator();
-  if (const auto *as = dyn_cast_or_null(term.getStmt())) {
-const CFGBlock *fallthrough = *Pred->succ_begin();
-if (as->isAsmGoto() &&
-llvm::any_of(as->outputs(), [&](const Expr *output) {
-return vd == findVar(output).getDecl() &&
-llvm::any_of(as->labels(),
- [&](const AddrLabelExpr *label) {
-  return label->getLabel()->getStmt() == B->Label &&
-  B != fallthrough;
-});
-})) {
-  Use.setUninitAfterDecl();
-  continue;
-}
-  }
-}
-
 unsigned  = SuccsVisited[Pred->getBlockID()];
 if (!SV) {
   // When 

[PATCH] D135488: [codegen] Add a remarks based Stack Layout Analysis pass

2022-12-21 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth updated this revision to Diff 484694.
paulkirth retitled this revision from "[codegen] Display stack layouts in 
console" to "[codegen] Add a remarks based Stack Layout Analysis pass".
paulkirth edited the summary of this revision.
paulkirth added a comment.
Herald added subscribers: pcwang-thead, frasercrmck, luismarques, apazos, 
sameer.abuasal, s.egerton, Jim, jocewei, PkmX, the_o, brucehoult, 
MartinMosbeck, rogfer01, edward-jones, zzheng, MaskRay, jrtc27, niosHD, 
sabuasal, simoncook, johnrusso, rbar, asb.

Refactor implementation to use remarks infrastructure

- Simplify interfaces
- Add tests in Clang
- Update pipeline tests
- Rename pass and test files


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135488

Files:
  clang/test/Frontend/stack-layout-remark.c
  llvm/include/llvm/CodeGen/Passes.h
  llvm/include/llvm/InitializePasses.h
  llvm/lib/CodeGen/CMakeLists.txt
  llvm/lib/CodeGen/CodeGen.cpp
  llvm/lib/CodeGen/StackFrameLayoutAnalysisPass.cpp
  llvm/lib/CodeGen/TargetPassConfig.cpp
  llvm/test/CodeGen/AArch64/O0-pipeline.ll
  llvm/test/CodeGen/AArch64/O3-pipeline.ll
  llvm/test/CodeGen/AArch64/arm64-opt-remarks-lazy-bfi.ll
  llvm/test/CodeGen/ARM/O3-pipeline.ll
  llvm/test/CodeGen/ARM/stack-frame-layout-remarks.ll
  llvm/test/CodeGen/Generic/llc-start-stop.ll
  llvm/test/CodeGen/RISCV/O0-pipeline.ll
  llvm/test/CodeGen/RISCV/O3-pipeline.ll
  llvm/test/CodeGen/X86/O0-pipeline.ll
  llvm/test/CodeGen/X86/opt-pipeline.ll
  llvm/test/CodeGen/X86/stack-frame-layout-remarks.ll

Index: llvm/test/CodeGen/X86/stack-frame-layout-remarks.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/stack-frame-layout-remarks.ll
@@ -0,0 +1,303 @@
+; Test remark output for stack-frame-layout
+
+; ensure basic output works
+; RUN: llc -mcpu=corei7 -O1 -pass-remarks-analysis=stack-frame-layout < %s 2>&1 >/dev/null | FileCheck %s
+
+; check additional slots are displayed when stack is not optimized
+; RUN: llc -mcpu=corei7 -O0 -pass-remarks-analysis=stack-frame-layout < %s 2>&1 >/dev/null | FileCheck %s --check-prefix=NO_COLORING
+
+; check more complex cases
+; RUN: llc %s -pass-remarks-analysis=stack-frame-layout -o /dev/null --march=x86 -mcpu=i386 2>&1 | FileCheck %s --check-prefix=BOTH --check-prefix=DEBUG
+
+; check output without debug info
+; RUN: opt %s -passes=strip -S | llc  -pass-remarks-analysis=stack-frame-layout -o /dev/null --march=x86 -mcpu=i386 2>&1 | FileCheck %s --check-prefix=BOTH --check-prefix=STRIPPED
+
+target triple = "x86_64-unknown-linux-gnu"
+
+; CHECK: FunctionName: stackSizeWarning
+; CHECK: Offset{{.*}}Align{{.*}}Size
+; CHECK: [SP-88]{{.*}}16{{.*}}80
+; CHECK:buffer @ frame-diags.c:30
+; NO_COLORING: [SP-168]{{.*}}16{{.*}}80
+; CHECK:buffer2 @ frame-diags.c:33
+define void @stackSizeWarning() {
+entry:
+  %buffer = alloca [80 x i8], align 16
+  %buffer2 = alloca [80 x i8], align 16
+  call void @llvm.dbg.declare(metadata ptr %buffer, metadata !25, metadata !DIExpression()), !dbg !39
+  call void @llvm.dbg.declare(metadata ptr %buffer2, metadata !31, metadata !DIExpression()), !dbg !40
+  ret void
+}
+
+; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
+
+; BOTH: FunctionName: cleanup_array
+; BOTH:  Offset{{.*}}Align{{.*}}Size
+; BOTH:  [SP+4]{{.+}}16{{.+}}4
+; DEBUG: a @ dot.c:13
+; STRIPPED-NOT: a @ dot.c:13
+; BOTH:  [SP-4]{{.+}}Spill 8{{.+}}4
+define void @cleanup_array(ptr %0) #1 {
+  %2 = alloca ptr, align 8
+  store ptr %0, ptr %2, align 8
+  call void @llvm.dbg.declare(metadata ptr %2, metadata !41, metadata !DIExpression()), !dbg !46
+  ret void
+}
+
+; BOTH: FunctionName: cleanup_result
+; BOTH:  Offset{{.+}}Align{{.+}}Size
+; BOTH:  [SP+4]{{.+}}16{{.+}}4
+; DEBUG: res @ dot.c:21
+; STRIPPED-NOT: res @ dot.c:21
+; BOTH:  [SP-4]{{.+}}Spill 8{{.+}}4
+define void @cleanup_result(ptr %0) #1 {
+  %2 = alloca ptr, align 8
+  store ptr %0, ptr %2, align 8
+  call void @llvm.dbg.declare(metadata ptr %2, metadata !47, metadata !DIExpression()), !dbg !51
+  ret void
+}
+
+; BOTH: FunctionName: do_work
+; BOTH:  Offset{{.+}}Align{{.+}}Size
+; BOTH:  [SP+12]{{.+}}8{{.+}}4
+; DEBUG: out @ dot.c:32
+; STRIPPED-NOT: out @ dot.c:32
+; BOTH:  [SP+8]{{.+}}4{{.+}}4
+; BOTH:  [SP+4]{{.+}}16{{.+}}4
+; DEBUG: A @ dot.c:32
+; STRIPPED-NOT: A @ dot.c:32
+; BOTH:  [SP-4]{{.+}}Spill 8{{.+}}4
+; BOTH:  [SP-12]{{.+}}8{{.+}}4
+; DEBUG: AB @ dot.c:38
+; STRIPPED-NOT: AB @ dot.c:38
+; BOTH:  [SP-16]{{.+}}4{{.+}}4
+; DEBUG: i @ dot.c:55
+; STRIPPED-NOT: i @ dot.c:55
+; BOTH:  [SP-20]{{.+}}8{{.+}}4
+; DEBUG: B @ dot.c:32
+; STRIPPED-NOT: B @ dot.c:32
+; BOTH:  [SP-24]{{.+}}4{{.+}}4
+; DEBUG: len @ dot.c:37
+; STRIPPED-NOT: len @ dot.c:37
+; BOTH:  [SP-28]{{.+}}4{{.+}}4
+; BOTH:  [SP-32]{{.+}}4{{.+}}4
+; DEBUG: sum @ dot.c:54
+; STRIPPED-NOT: sum @ 

[PATCH] D140507: Parse: handle another case of invalid handling for attributes

2022-12-21 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd created this revision.
compnerd added a reviewer: aaron.ballman.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
compnerd requested review of this revision.
Herald added a project: clang.

clang would improperly disallow GNU attributes before C++ standard
attributes when a declaration had a linkage specifier.  Handle this
similarly to the previous case of invalid parsing.  We now better match
the parsing rules from GCC.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140507

Files:
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/test/Parser/cxx-attributes.cpp


Index: clang/test/Parser/cxx-attributes.cpp
===
--- clang/test/Parser/cxx-attributes.cpp
+++ clang/test/Parser/cxx-attributes.cpp
@@ -3,6 +3,8 @@
 // GH#58229 - rejects-valid
 __attribute__((__visibility__("default"))) [[nodiscard]] int f();
 [[nodiscard]] __attribute__((__visibility__("default"))) int f();
+extern "C" __attribute__((__visibility__("default"))) [[nodiscard]]
+int g() { return 32; }
 
 class c {
   virtual void f1(const char* a, ...)
Index: clang/lib/Parse/ParseDeclCXX.cpp
===
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -359,8 +359,11 @@
 Tok.is(tok::l_brace) ? Tok.getLocation() : SourceLocation());
 
   ParsedAttributes DeclAttrs(AttrFactory);
-  MaybeParseCXX11Attributes(DeclAttrs);
-  ParsedAttributes EmptyDeclSpecAttrs(AttrFactory);
+  ParsedAttributes DeclSpecAttrs(AttrFactory);
+
+  while (MaybeParseCXX11Attributes(DeclAttrs) ||
+ MaybeParseGNUAttributes(DeclSpecAttrs))
+;
 
   if (Tok.isNot(tok::l_brace)) {
 // Reset the source range in DS, as the leading "extern"
@@ -369,7 +372,7 @@
 DS.SetRangeEnd(SourceLocation());
 // ... but anyway remember that such an "extern" was seen.
 DS.setExternInLinkageSpec(true);
-ParseExternalDeclaration(DeclAttrs, EmptyDeclSpecAttrs, );
+ParseExternalDeclaration(DeclAttrs, DeclSpecAttrs, );
 return LinkageSpec ? Actions.ActOnFinishLinkageSpecification(
  getCurScope(), LinkageSpec, SourceLocation())
: nullptr;
@@ -411,7 +414,7 @@
 default:
   ParsedAttributes DeclAttrs(AttrFactory);
   MaybeParseCXX11Attributes(DeclAttrs);
-  ParseExternalDeclaration(DeclAttrs, EmptyDeclSpecAttrs);
+  ParseExternalDeclaration(DeclAttrs, DeclSpecAttrs);
   continue;
 }
 


Index: clang/test/Parser/cxx-attributes.cpp
===
--- clang/test/Parser/cxx-attributes.cpp
+++ clang/test/Parser/cxx-attributes.cpp
@@ -3,6 +3,8 @@
 // GH#58229 - rejects-valid
 __attribute__((__visibility__("default"))) [[nodiscard]] int f();
 [[nodiscard]] __attribute__((__visibility__("default"))) int f();
+extern "C" __attribute__((__visibility__("default"))) [[nodiscard]]
+int g() { return 32; }
 
 class c {
   virtual void f1(const char* a, ...)
Index: clang/lib/Parse/ParseDeclCXX.cpp
===
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -359,8 +359,11 @@
 Tok.is(tok::l_brace) ? Tok.getLocation() : SourceLocation());
 
   ParsedAttributes DeclAttrs(AttrFactory);
-  MaybeParseCXX11Attributes(DeclAttrs);
-  ParsedAttributes EmptyDeclSpecAttrs(AttrFactory);
+  ParsedAttributes DeclSpecAttrs(AttrFactory);
+
+  while (MaybeParseCXX11Attributes(DeclAttrs) ||
+ MaybeParseGNUAttributes(DeclSpecAttrs))
+;
 
   if (Tok.isNot(tok::l_brace)) {
 // Reset the source range in DS, as the leading "extern"
@@ -369,7 +372,7 @@
 DS.SetRangeEnd(SourceLocation());
 // ... but anyway remember that such an "extern" was seen.
 DS.setExternInLinkageSpec(true);
-ParseExternalDeclaration(DeclAttrs, EmptyDeclSpecAttrs, );
+ParseExternalDeclaration(DeclAttrs, DeclSpecAttrs, );
 return LinkageSpec ? Actions.ActOnFinishLinkageSpecification(
  getCurScope(), LinkageSpec, SourceLocation())
: nullptr;
@@ -411,7 +414,7 @@
 default:
   ParsedAttributes DeclAttrs(AttrFactory);
   MaybeParseCXX11Attributes(DeclAttrs);
-  ParseExternalDeclaration(DeclAttrs, EmptyDeclSpecAttrs);
+  ParseExternalDeclaration(DeclAttrs, DeclSpecAttrs);
   continue;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139640: clang: Add __builtin_elementwise canonicalize and copysign

2022-12-21 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm closed this revision.
arsenm added a comment.

437346abe18ec4fc982ae36f6821487dafc1a06e 





Comment at: clang/docs/LanguageExtensions.rst:644
  magnitude than x
+ T__builtin_elementwise_canonicalize(T x)  return the platform specific 
canonical encoding of a floating-point number floating point types
+

fhahn wrote:
> arsenm wrote:
> > fhahn wrote:
> > > I think this needs re-flowing , otherwise the table won't be rendered 
> > > properly? Same for the next line
> > I'm not really sure what's going on with the formatting or how this works. 
> > It looks worse on Phabricator than in the editor 
> I just tried this locally and the entries seem to be mis-aligned, which gets 
> rejected by `sphinx`:
> 
> ```
> Warning, treated as error:
> ../tools/clang/docs/LanguageExtensions.rst:644:Malformed table.
> Text in column margin in table line 16.
> ```
It builds for me (although the line wrapping for these and the others are 
awkward, splitting the parameter names). Probably need to specifically widen 
the name column


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

https://reviews.llvm.org/D139640

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


[clang] 437346a - clang: Add __builtin_elementwise canonicalize and copysign

2022-12-21 Thread Matt Arsenault via cfe-commits

Author: Matt Arsenault
Date: 2022-12-21T18:01:42-05:00
New Revision: 437346abe18ec4fc982ae36f6821487dafc1a06e

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

LOG: clang: Add __builtin_elementwise canonicalize and copysign

Just copy paste from the other functions. I also need fma, but
the current code seems to assume 1 or 2 arguments.

Added: 


Modified: 
clang/docs/LanguageExtensions.rst
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

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index ad6e10cf9c6c2..9b39dc23e0a5c 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -639,8 +639,11 @@ Unless specified otherwise operation(±0) = ±0 and 
operation(±infinity) = ±in
  rounding halfway cases to even 
(that is, to the nearest value
  that is an even integer), 
regardless of the current rounding
  direction.
- T__builtin_elementwise_trunc(T x)   return the integral value nearest 
to but no larger infloating point types
+ T __builtin_elementwise_trunc(T x)  return the integral value nearest 
to but no larger infloating point types
  magnitude than x
+ T __builtin_elementwise_canonicalize(T x)   return the platform specific 
canonical encoding  floating point types
+ of a floating-point number
+ T __builtin_elementwise_copysign(T x, T y)  return the magnitude of x with 
the sign of y.floating point types
  T __builtin_elementwise_max(T x, T y)   return x or y, whichever is 
larger   integer and floating point types
  T __builtin_elementwise_min(T x, T y)   return x or y, whichever is 
smaller  integer and floating point types
  T __builtin_elementwise_add_sat(T x, T y)   return the sum of x and y, 
clamped to the range of   integer types
@@ -4203,7 +4206,7 @@ these values is same as for `constrained floating point 
intrinsics getArg(0));

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 68ae9896554bd..d009d55c1c2c7 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -2577,7 +2577,8 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
   case Builtin::BI__builtin_elementwise_floor:
   case Builtin::BI__builtin_elementwise_roundeven:
   case Builtin::BI__builtin_elementwise_sin:
-  case Builtin::BI__builtin_elementwise_trunc: {
+  case Builtin::BI__builtin_elementwise_trunc:
+  case 

[PATCH] D140506: [clang][dataflow] Simplify handling of nullopt-optionals.

2022-12-21 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel created this revision.
ymandel added reviewers: xazax.hun, gribozavr2.
Herald added subscribers: martong, rnkovacs.
Herald added a reviewer: NoQ.
Herald added a project: All.
ymandel requested review of this revision.
Herald added a project: clang.

Previously, in the case of an optional constructed from `nullopt`, we relied on
the value constructed for the `nullopt`. This complicates the implementation and
exposes it to bugs (indeed, one such was found), yet doesn't improve the
engine. Instead, this patch constructs a fresh optional representation, rather
than relying on the underlying nullopt representation.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140506

Files:
  clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
  clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -1273,7 +1273,6 @@
 ExpectDiagnosticsFor(SourceCode, ast_matchers::hasName("target"));
   }
 
-private:
   template 
   void ExpectDiagnosticsFor(std::string SourceCode,
 FuncDeclMatcher FuncMatcher) {
@@ -2939,6 +2938,38 @@
   )");
 }
 
+TEST_P(UncheckedOptionalAccessTest, CtorInitializerNullopt) {
+  using namespace ast_matchers;
+  ExpectDiagnosticsFor(
+  R"(
+#include "unchecked_optional_access_test.h"
+
+struct Target {
+  Target(): opt($ns::nullopt) {
+opt.value(); // [[unsafe]]
+  }
+  $ns::$optional opt;
+};
+  )",
+  cxxConstructorDecl(ofClass(hasName("Target";
+}
+
+TEST_P(UncheckedOptionalAccessTest, CtorInitializerValue) {
+  using namespace ast_matchers;
+  ExpectDiagnosticsFor(
+  R"(
+#include "unchecked_optional_access_test.h"
+
+struct Target {
+  Target(): opt(3) {
+opt.value();
+  }
+  $ns::$optional opt;
+};
+  )",
+  cxxConstructorDecl(ofClass(hasName("Target";
+}
+
 // FIXME: Add support for:
 // - constructors (copy, move)
 // - assignment operators (default, copy, move)
Index: clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
===
--- clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
+++ clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
@@ -438,12 +438,11 @@
   Loc, createOptionalValue(State.Env, State.Env.makeAtomicBoolValue()));
 }
 
-void assignOptionalValue(const Expr , LatticeTransferState ,
+void assignOptionalValue(const Expr , Environment ,
  BoolValue ) {
   if (auto *OptionalLoc =
-  State.Env.getStorageLocation(E, SkipPast::ReferenceThenPointer)) {
-State.Env.setValue(*OptionalLoc,
-   createOptionalValue(State.Env, HasValueVal));
+  Env.getStorageLocation(E, SkipPast::ReferenceThenPointer)) {
+Env.setValue(*OptionalLoc, createOptionalValue(Env, HasValueVal));
   }
 }
 
@@ -479,7 +478,7 @@
 LatticeTransferState ) {
   assert(E->getNumArgs() > 0);
 
-  assignOptionalValue(*E, State,
+  assignOptionalValue(*E, State.Env,
   valueOrConversionHasValue(*E->getConstructor(),
 *E->getArg(0), MatchRes,
 State));
@@ -647,35 +646,35 @@
   // make_optional
   .CaseOfCFGStmt(isMakeOptionalCall(), transferMakeOptionalCall)
 
-  // optional::optional
+  // optional::optional (in place)
   .CaseOfCFGStmt(
   isOptionalInPlaceConstructor(),
   [](const CXXConstructExpr *E, const MatchFinder::MatchResult &,
  LatticeTransferState ) {
-assignOptionalValue(*E, State, State.Env.getBoolLiteralValue(true));
+assignOptionalValue(*E, State.Env,
+State.Env.getBoolLiteralValue(true));
   })
+  // nullopt_t::nullopt_t
   .CaseOfCFGStmt(
   isNulloptConstructor(),
   [](const CXXConstructExpr *E, const MatchFinder::MatchResult &,
  LatticeTransferState ) {
-assignOptionalValue(*E, State,
+assignOptionalValue(*E, State.Env,
 State.Env.getBoolLiteralValue(false));
   })
+  // optional::optional(nullopt_t)
   .CaseOfCFGStmt(
   isOptionalNulloptConstructor(),
   [](const CXXConstructExpr *E, const MatchFinder::MatchResult &,
  LatticeTransferState ) {
-// Shares a temporary with the underlying `nullopt_t` instance.
-if (auto *OptionalLoc =
-State.Env.getStorageLocation(*E, SkipPast::None)) {
-  State.Env.setValue(

[PATCH] D140486: [clangd] Fix crashing race in ClangdServer shutdown with stdlib indexing

2022-12-21 Thread Sam McCall via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
sammccall marked an inline comment as done.
Closed by commit rGb494f67f6796: [clangd] Fix crashing race in ClangdServer 
shutdown with stdlib indexing (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D140486?vs=484612=484683#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140486

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


Index: clang-tools-extra/clangd/ClangdServer.cpp
===
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -63,7 +63,7 @@
ClangdServer::Callbacks *ServerCallbacks,
const ThreadsafeFS , AsyncTaskRunner *Tasks)
   : FIndex(FIndex), ServerCallbacks(ServerCallbacks), TFS(TFS),
-Tasks(Tasks) {}
+Stdlib{std::make_shared()}, Tasks(Tasks) {}
 
   void onPreambleAST(PathRef Path, llvm::StringRef Version,
  const CompilerInvocation , ASTContext ,
@@ -71,7 +71,7 @@
  const CanonicalIncludes ) override {
 // If this preamble uses a standard library we haven't seen yet, index it.
 if (FIndex)
-  if (auto Loc = Stdlib.add(*CI.getLangOpts(), PP.getHeaderSearchInfo()))
+  if (auto Loc = Stdlib->add(*CI.getLangOpts(), PP.getHeaderSearchInfo()))
 indexStdlib(CI, std::move(*Loc));
 
 if (FIndex)
@@ -79,11 +79,20 @@
   }
 
   void indexStdlib(const CompilerInvocation , StdLibLocation Loc) {
-auto Task = [this, LO(*CI.getLangOpts()), Loc(std::move(Loc)),
- CI(std::make_unique(CI))]() mutable {
+// This task is owned by Tasks, which outlives the TUScheduler and
+// therefore the UpdateIndexCallbacks.
+// We must be careful that the references we capture outlive TUScheduler.
+auto Task = [LO(*CI.getLangOpts()), Loc(std::move(Loc)),
+ CI(std::make_unique(CI)),
+ // External values that outlive ClangdServer
+ TFS(),
+ // Index outlives TUScheduler (declared first)
+ FIndex(FIndex),
+ // shared_ptr extends lifetime
+ Stdlib(Stdlib)]() mutable {
   IndexFileIn IF;
-  IF.Symbols = indexStandardLibrary(std::move(CI), Loc, TFS);
-  if (Stdlib.isBest(LO))
+  IF.Symbols = indexStandardLibrary(std::move(CI), Loc, *TFS);
+  if (Stdlib->isBest(LO))
 FIndex->updatePreamble(std::move(IF));
 };
 if (Tasks)
@@ -128,7 +137,7 @@
   FileIndex *FIndex;
   ClangdServer::Callbacks *ServerCallbacks;
   const ThreadsafeFS 
-  StdLibSet Stdlib;
+  std::shared_ptr Stdlib;
   AsyncTaskRunner *Tasks;
 };
 


Index: clang-tools-extra/clangd/ClangdServer.cpp
===
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -63,7 +63,7 @@
ClangdServer::Callbacks *ServerCallbacks,
const ThreadsafeFS , AsyncTaskRunner *Tasks)
   : FIndex(FIndex), ServerCallbacks(ServerCallbacks), TFS(TFS),
-Tasks(Tasks) {}
+Stdlib{std::make_shared()}, Tasks(Tasks) {}
 
   void onPreambleAST(PathRef Path, llvm::StringRef Version,
  const CompilerInvocation , ASTContext ,
@@ -71,7 +71,7 @@
  const CanonicalIncludes ) override {
 // If this preamble uses a standard library we haven't seen yet, index it.
 if (FIndex)
-  if (auto Loc = Stdlib.add(*CI.getLangOpts(), PP.getHeaderSearchInfo()))
+  if (auto Loc = Stdlib->add(*CI.getLangOpts(), PP.getHeaderSearchInfo()))
 indexStdlib(CI, std::move(*Loc));
 
 if (FIndex)
@@ -79,11 +79,20 @@
   }
 
   void indexStdlib(const CompilerInvocation , StdLibLocation Loc) {
-auto Task = [this, LO(*CI.getLangOpts()), Loc(std::move(Loc)),
- CI(std::make_unique(CI))]() mutable {
+// This task is owned by Tasks, which outlives the TUScheduler and
+// therefore the UpdateIndexCallbacks.
+// We must be careful that the references we capture outlive TUScheduler.
+auto Task = [LO(*CI.getLangOpts()), Loc(std::move(Loc)),
+ CI(std::make_unique(CI)),
+ // External values that outlive ClangdServer
+ TFS(),
+ // Index outlives TUScheduler (declared first)
+ FIndex(FIndex),
+ // shared_ptr extends lifetime
+ Stdlib(Stdlib)]() mutable {
   IndexFileIn IF;
-  IF.Symbols = indexStandardLibrary(std::move(CI), Loc, TFS);
-  if (Stdlib.isBest(LO))
+  IF.Symbols = indexStandardLibrary(std::move(CI), Loc, *TFS);
+  if (Stdlib->isBest(LO))
 FIndex->updatePreamble(std::move(IF));
  

[clang-tools-extra] b494f67 - [clangd] Fix crashing race in ClangdServer shutdown with stdlib indexing

2022-12-21 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-12-21T23:35:48+01:00
New Revision: b494f67f67968c50289148fb423a108607be83e9

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

LOG: [clangd] Fix crashing race in ClangdServer shutdown with stdlib indexing

In principle it's OK for stdlib-indexing tasks to run after the TUScheduler is
destroyed, as mostly they just update the dynamic index. We do drain the
stdlib-indexing queue before destroying the index.

However the task captures references to the PreambleCallbacks object, which is
owned by the TUScheduler. Once this is destroyed (explicitly, early in
~ClangdServer) an outstanding stdlib-indexing task may use-after-free.

The fix here is to avoid capturing references to the PreambleCallbacks.
Alternatives would be to have TUScheduler (exclusively) not own its callbacks
so they could live longer, or explicitly stopping the TUScheduler instead of
early-destroying it. These both seem more invasive.

See https://reviews.llvm.org/D115232 for some more context.

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

Added: 


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

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdServer.cpp 
b/clang-tools-extra/clangd/ClangdServer.cpp
index 9c8803bbfb1ce..349a53d4dc14e 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -63,7 +63,7 @@ struct UpdateIndexCallbacks : public ParsingCallbacks {
ClangdServer::Callbacks *ServerCallbacks,
const ThreadsafeFS , AsyncTaskRunner *Tasks)
   : FIndex(FIndex), ServerCallbacks(ServerCallbacks), TFS(TFS),
-Tasks(Tasks) {}
+Stdlib{std::make_shared()}, Tasks(Tasks) {}
 
   void onPreambleAST(PathRef Path, llvm::StringRef Version,
  const CompilerInvocation , ASTContext ,
@@ -71,7 +71,7 @@ struct UpdateIndexCallbacks : public ParsingCallbacks {
  const CanonicalIncludes ) override {
 // If this preamble uses a standard library we haven't seen yet, index it.
 if (FIndex)
-  if (auto Loc = Stdlib.add(*CI.getLangOpts(), PP.getHeaderSearchInfo()))
+  if (auto Loc = Stdlib->add(*CI.getLangOpts(), PP.getHeaderSearchInfo()))
 indexStdlib(CI, std::move(*Loc));
 
 if (FIndex)
@@ -79,11 +79,20 @@ struct UpdateIndexCallbacks : public ParsingCallbacks {
   }
 
   void indexStdlib(const CompilerInvocation , StdLibLocation Loc) {
-auto Task = [this, LO(*CI.getLangOpts()), Loc(std::move(Loc)),
- CI(std::make_unique(CI))]() mutable {
+// This task is owned by Tasks, which outlives the TUScheduler and
+// therefore the UpdateIndexCallbacks.
+// We must be careful that the references we capture outlive TUScheduler.
+auto Task = [LO(*CI.getLangOpts()), Loc(std::move(Loc)),
+ CI(std::make_unique(CI)),
+ // External values that outlive ClangdServer
+ TFS(),
+ // Index outlives TUScheduler (declared first)
+ FIndex(FIndex),
+ // shared_ptr extends lifetime
+ Stdlib(Stdlib)]() mutable {
   IndexFileIn IF;
-  IF.Symbols = indexStandardLibrary(std::move(CI), Loc, TFS);
-  if (Stdlib.isBest(LO))
+  IF.Symbols = indexStandardLibrary(std::move(CI), Loc, *TFS);
+  if (Stdlib->isBest(LO))
 FIndex->updatePreamble(std::move(IF));
 };
 if (Tasks)
@@ -128,7 +137,7 @@ struct UpdateIndexCallbacks : public ParsingCallbacks {
   FileIndex *FIndex;
   ClangdServer::Callbacks *ServerCallbacks;
   const ThreadsafeFS 
-  StdLibSet Stdlib;
+  std::shared_ptr Stdlib;
   AsyncTaskRunner *Tasks;
 };
 



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


[PATCH] D137838: [Support] Move TargetParsers to new component

2022-12-21 Thread Sam Elliott via Phabricator via cfe-commits
lenary added a comment.

In D137838#4010987 , @dblaikie wrote:

> This has introduced a circular dependency due to the forwarding header 
> (forwarding header depends on new lib, new lib depends on support, where the 
> forwarding header is). Generally this wouldn't be acceptable (& I'd suggest 
> the patch be reverted on that basis) though I understand this is a 
> complicated migration - what's the timeline for correcting this issue?

A commit was landed to add TargetParser to the module map so it looks like part 
of Support, which solves the circular dependency issue in the short term, I 
believe.

https://reviews.llvm.org/D140420 is a proposed fix which should more clearly 
split the TargetParser from Support, but I'm not super familiar with modules 
and my linux dev environment does not work with a modules build. I'd appreciate 
any comments or guidance though I also know it needs an update.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137838

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


[PATCH] D136497: [Clang] support for outputs along indirect edges of asm goto

2022-12-21 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

Ready for review:

1. https://reviews.llvm.org/D135997
2. https://reviews.llvm.org/D140166
3. https://reviews.llvm.org/D139861
4. https://reviews.llvm.org/D139872
5. https://reviews.llvm.org/D139883
6. https://reviews.llvm.org/D139970
7. https://reviews.llvm.org/D140160
8. https://reviews.llvm.org/D137113
9. https://reviews.llvm.org/D136497


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136497

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


[PATCH] D140486: [clangd] Fix crashing race in ClangdServer shutdown with stdlib indexing

2022-12-21 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

thanks, lgtm!




Comment at: clang-tools-extra/clangd/ClangdServer.cpp:86
+auto Task = [
+// Captured by value
+LO(*CI.getLangOpts()), Loc(std::move(Loc)),

formatting seems to be off here (looks like clang-format can't deal with this 
leading comment. do you mind dropping it? the comment above makes it clear that 
we shouldn't be keeping references already.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140486

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


[PATCH] D140501: [clang][dataflow] Account for global variables in constructor initializers.

2022-12-21 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 accepted this revision.
gribozavr2 added inline comments.
This revision is now accepted and ready to land.



Comment at: 
clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp:112
+  const auto *Var = selectFirst("global", Results);
+  ASSERT_TRUE(Fun != nullptr);
+  ASSERT_THAT(Var, NotNull());





Comment at: 
clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp:144
+  const auto *Var = selectFirst("global", Results);
+  ASSERT_TRUE(Ctor != nullptr);
+  ASSERT_THAT(Var, NotNull());




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140501

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


[PATCH] D136497: [Clang] support for outputs along indirect edges of asm goto

2022-12-21 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 484678.
nickdesaulniers added a comment.

- add clang release notes from D138078  and 
new one for new feature.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136497

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/CGStmt.cpp
  clang/test/CodeGen/asm-goto.c
  clang/test/CodeGen/asm-goto2.c
  clang/test/Modules/asm-goto.c

Index: clang/test/Modules/asm-goto.c
===
--- clang/test/Modules/asm-goto.c
+++ clang/test/Modules/asm-goto.c
@@ -5,7 +5,7 @@
 
 // CHECK-LABEL: define {{.*}} @foo(
 // CHECK: callbr {{.*}} "=r,!i{{.*}}()
-// CHECK-NEXT: to label %asm.fallthrough [label %indirect]
+// CHECK-NEXT: to label %asm.fallthrough [label %indirect.split]
 
 int bar(void) {
   return foo();
Index: clang/test/CodeGen/asm-goto2.c
===
--- /dev/null
+++ clang/test/CodeGen/asm-goto2.c
@@ -0,0 +1,156 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: x86-registered-target
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -O0 -emit-llvm %s -o - | FileCheck %s
+
+// CHECK-LABEL: @test0(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[RET:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[TMP0:%.*]] = callbr i32 asm "", "=r,!i,~{dirflag},~{fpsr},~{flags}"() #[[ATTR1:[0-9]+]]
+// CHECK-NEXT:to label [[ASM_FALLTHROUGH:%.*]] [label %z.split], !srcloc !2
+// CHECK:   asm.fallthrough:
+// CHECK-NEXT:store i32 [[TMP0]], ptr [[RET]], align 4
+// CHECK-NEXT:store i32 42, ptr [[RET]], align 4
+// CHECK-NEXT:br label [[Z:%.*]]
+// CHECK:   z:
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, ptr [[RET]], align 4
+// CHECK-NEXT:ret i32 [[TMP1]]
+// CHECK:   z.split:
+// CHECK-NEXT:store i32 [[TMP0]], ptr [[RET]], align 4
+// CHECK-NEXT:br label [[Z]]
+//
+int test0 (void) {
+  int ret;
+  asm goto ("" : "=r"(ret):::z);
+  ret = 42;
+z:
+  return ret;
+}
+
+// CHECK-LABEL: @test1(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[RET:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[B:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[TMP0:%.*]] = callbr { i32, i32 } asm "", "=r,=r,!i,~{dirflag},~{fpsr},~{flags}"() #[[ATTR1]]
+// CHECK-NEXT:to label [[ASM_FALLTHROUGH:%.*]] [label %z.split], !srcloc !3
+// CHECK:   asm.fallthrough:
+// CHECK-NEXT:[[ASMRESULT:%.*]] = extractvalue { i32, i32 } [[TMP0]], 0
+// CHECK-NEXT:[[ASMRESULT1:%.*]] = extractvalue { i32, i32 } [[TMP0]], 1
+// CHECK-NEXT:store i32 [[ASMRESULT]], ptr [[RET]], align 4
+// CHECK-NEXT:store i32 [[ASMRESULT1]], ptr [[B]], align 4
+// CHECK-NEXT:store i32 42, ptr [[RET]], align 4
+// CHECK-NEXT:br label [[Z:%.*]]
+// CHECK:   z:
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, ptr [[RET]], align 4
+// CHECK-NEXT:ret i32 [[TMP1]]
+// CHECK:   z.split:
+// CHECK-NEXT:[[ASMRESULT2:%.*]] = extractvalue { i32, i32 } [[TMP0]], 0
+// CHECK-NEXT:[[ASMRESULT3:%.*]] = extractvalue { i32, i32 } [[TMP0]], 1
+// CHECK-NEXT:store i32 [[ASMRESULT2]], ptr [[RET]], align 4
+// CHECK-NEXT:store i32 [[ASMRESULT3]], ptr [[B]], align 4
+// CHECK-NEXT:br label [[Z]]
+//
+int test1 (void) {
+  int ret, b;
+  asm goto ("" : "=r"(ret), "=r"(b):::z);
+  ret = 42;
+z:
+  return ret;
+}
+
+// CHECK-LABEL: @test2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[RET:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[B:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[TMP0:%.*]] = callbr { i32, i32 } asm "", "=r,=r,!i,~{dirflag},~{fpsr},~{flags}"() #[[ATTR1]]
+// CHECK-NEXT:to label [[ASM_FALLTHROUGH:%.*]] [label %z.split], !srcloc !4
+// CHECK:   asm.fallthrough:
+// CHECK-NEXT:[[ASMRESULT:%.*]] = extractvalue { i32, i32 } [[TMP0]], 0
+// CHECK-NEXT:[[ASMRESULT1:%.*]] = extractvalue { i32, i32 } [[TMP0]], 1
+// CHECK-NEXT:store i32 [[ASMRESULT]], ptr [[RET]], align 4
+// CHECK-NEXT:store i32 [[ASMRESULT1]], ptr [[B]], align 4
+// CHECK-NEXT:[[TMP1:%.*]] = callbr { i32, i32 } asm "", "=r,=r,!i,~{dirflag},~{fpsr},~{flags}"() #[[ATTR1]]
+// CHECK-NEXT:to label [[ASM_FALLTHROUGH4:%.*]] [label %z.split9], !srcloc !5
+// CHECK:   asm.fallthrough4:
+// CHECK-NEXT:[[ASMRESULT5:%.*]] = extractvalue { i32, i32 } [[TMP1]], 0
+// CHECK-NEXT:[[ASMRESULT6:%.*]] = extractvalue { i32, i32 } [[TMP1]], 1
+// CHECK-NEXT:store i32 [[ASMRESULT5]], ptr [[RET]], align 4
+// CHECK-NEXT:store i32 [[ASMRESULT6]], ptr [[B]], align 4
+// CHECK-NEXT:br label [[Z:%.*]]
+// CHECK:   z:
+// CHECK-NEXT:[[TMP2:%.*]] = load i32, ptr [[RET]], align 4
+// CHECK-NEXT:ret i32 [[TMP2]]
+// CHECK:   z.split:
+// CHECK-NEXT:[[ASMRESULT2:%.*]] = extractvalue { i32, i32 } [[TMP0]], 0
+// CHECK-NEXT:[[ASMRESULT3:%.*]] = 

[PATCH] D140501: [clang][dataflow] Account for global variables in constructor initializers.

2022-12-21 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel created this revision.
ymandel added reviewers: xazax.hun, gribozavr2.
Herald added subscribers: martong, rnkovacs.
Herald added a reviewer: NoQ.
Herald added a project: All.
ymandel requested review of this revision.
Herald added a project: clang.

Previously, the analysis modeled global variables appearing in the _body_ of
any function (including constructors). But, that misses those appearing in
constructor _initializers_. This patch adds the initializers to the set of
expressions used to determine which globals to model.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140501

Files:
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
@@ -8,6 +8,8 @@
 
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
 #include "TestingSupport.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Analysis/FlowSensitive/DataflowAnalysisContext.h"
 #include "clang/Analysis/FlowSensitive/NoopAnalysis.h"
 #include "clang/Analysis/FlowSensitive/Value.h"
@@ -21,19 +23,19 @@
 using namespace clang;
 using namespace dataflow;
 using ::testing::ElementsAre;
+using ::testing::NotNull;
 using ::testing::Pair;
 
 class EnvironmentTest : public ::testing::Test {
-  DataflowAnalysisContext Context;
-
 protected:
-  EnvironmentTest()
-  : Context(std::make_unique()), Env(Context) {}
+  EnvironmentTest() : DAContext(std::make_unique()) {}
 
-  Environment Env;
+  DataflowAnalysisContext DAContext;
 };
 
 TEST_F(EnvironmentTest, FlowCondition) {
+  Environment Env(DAContext);
+
   EXPECT_TRUE(Env.flowConditionImplies(Env.getBoolLiteralValue(true)));
   EXPECT_FALSE(Env.flowConditionImplies(Env.getBoolLiteralValue(false)));
 
@@ -76,6 +78,7 @@
 
   // Verify that the struct and the field (`R`) with first appearance of the
   // type is created successfully.
+  Environment Env(DAContext);
   Value *Val = Env.createValue(*Ty);
   ASSERT_NE(Val, nullptr);
   StructValue *SVal = clang::dyn_cast(Val);
@@ -86,4 +89,64 @@
   EXPECT_NE(PV, nullptr);
 }
 
+TEST_F(EnvironmentTest, InitGlobalVarsFun) {
+  using namespace ast_matchers;
+
+  std::string Code = R"cc(
+ int Global = 0;
+ int Target () { return Global; }
+  )cc";
+
+  auto Unit =
+  tooling::buildASTFromCodeWithArgs(Code, {"-fsyntax-only", "-std=c++11"});
+  auto  = Unit->getASTContext();
+
+  ASSERT_EQ(Context.getDiagnostics().getClient()->getNumErrors(), 0U);
+
+  auto Results =
+  match(decl(anyOf(varDecl(hasName("Global")).bind("global"),
+   functionDecl(hasName("Target")).bind("target"))),
+Context);
+  const auto *Fun = selectFirst("target", Results);
+  const auto *Var = selectFirst("global", Results);
+  ASSERT_TRUE(Fun != nullptr);
+  ASSERT_THAT(Var, NotNull());
+
+  // Verify the global variable is populated when we analyze `Target`.
+  Environment Env(DAContext, *Fun);
+  EXPECT_THAT(Env.getValue(*Var, SkipPast::None), NotNull());
+}
+
+TEST_F(EnvironmentTest, InitGlobalVarsConstructor) {
+  using namespace ast_matchers;
+
+  std::string Code = R"cc(
+ int Global = 0;
+ struct Target {
+   Target() : Field(Global) {}
+   int Field;
+ };
+  )cc";
+
+  auto Unit =
+  tooling::buildASTFromCodeWithArgs(Code, {"-fsyntax-only", "-std=c++11"});
+  auto  = Unit->getASTContext();
+
+  ASSERT_EQ(Context.getDiagnostics().getClient()->getNumErrors(), 0U);
+
+  auto Results =
+  match(decl(anyOf(
+varDecl(hasName("Global")).bind("global"),
+cxxConstructorDecl(ofClass(hasName("Target"))).bind("target"))),
+Context);
+  const auto *Ctor = selectFirst("target", Results);
+  const auto *Var = selectFirst("global", Results);
+  ASSERT_TRUE(Ctor != nullptr);
+  ASSERT_THAT(Var, NotNull());
+
+  // Verify the global variable is populated when we analyze `Target`.
+  Environment Env(DAContext, *Ctor);
+  EXPECT_THAT(Env.getValue(*Var, SkipPast::None), NotNull());
+}
+
 } // namespace
Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -233,6 +233,15 @@
   }
 }
   }
+
+  // Look for global variable references in the constructor-initializers.
+  if (const auto *CtorDecl = dyn_cast()) {
+for (const auto *Init : CtorDecl->inits()) {
+  const Expr *E = Init->getInit();
+  assert(E != nullptr);
+  initGlobalVars(*E, *this);
+}
+  }
 }
 
 bool Environment::canDescend(unsigned MaxDepth,

[PATCH] D137113: [Clang] refactor CodeGenFunction::EmitAsmStmt NFC

2022-12-21 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 484672.
nickdesaulniers added a comment.

- rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137113

Files:
  clang/lib/CodeGen/CGStmt.cpp

Index: clang/lib/CodeGen/CGStmt.cpp
===
--- clang/lib/CodeGen/CGStmt.cpp
+++ clang/lib/CodeGen/CGStmt.cpp
@@ -24,6 +24,7 @@
 #include "clang/Basic/PrettyStackTrace.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/IR/Assumptions.h"
@@ -2326,6 +2327,93 @@
   }
 }
 
+static void
+EmitAsmStores(CodeGenFunction , const AsmStmt ,
+  const llvm::ArrayRef RegResults,
+  const llvm::ArrayRef ResultRegTypes,
+  const llvm::ArrayRef ResultTruncRegTypes,
+  const llvm::ArrayRef ResultRegDests,
+  const llvm::ArrayRef ResultRegQualTys,
+  const llvm::BitVector ,
+  const llvm::BitVector ) {
+  CGBuilderTy  = CGF.Builder;
+  CodeGenModule  = CGF.CGM;
+  llvm::LLVMContext  = CGF.getLLVMContext();
+
+  assert(RegResults.size() == ResultRegTypes.size());
+  assert(RegResults.size() == ResultTruncRegTypes.size());
+  assert(RegResults.size() == ResultRegDests.size());
+  // ResultRegDests can be also populated by addReturnRegisterOutputs() above,
+  // in which case its size may grow.
+  assert(ResultTypeRequiresCast.size() <= ResultRegDests.size());
+  assert(ResultRegIsFlagReg.size() <= ResultRegDests.size());
+
+  for (unsigned i = 0, e = RegResults.size(); i != e; ++i) {
+llvm::Value *Tmp = RegResults[i];
+llvm::Type *TruncTy = ResultTruncRegTypes[i];
+
+if ((i < ResultRegIsFlagReg.size()) && ResultRegIsFlagReg[i]) {
+  // Target must guarantee the Value `Tmp` here is lowered to a boolean
+  // value.
+  llvm::Constant *Two = llvm::ConstantInt::get(Tmp->getType(), 2);
+  llvm::Value *IsBooleanValue =
+  Builder.CreateCmp(llvm::CmpInst::ICMP_ULT, Tmp, Two);
+  llvm::Function *FnAssume = CGM.getIntrinsic(llvm::Intrinsic::assume);
+  Builder.CreateCall(FnAssume, IsBooleanValue);
+}
+
+// If the result type of the LLVM IR asm doesn't match the result type of
+// the expression, do the conversion.
+if (ResultRegTypes[i] != TruncTy) {
+
+  // Truncate the integer result to the right size, note that TruncTy can be
+  // a pointer.
+  if (TruncTy->isFloatingPointTy())
+Tmp = Builder.CreateFPTrunc(Tmp, TruncTy);
+  else if (TruncTy->isPointerTy() && Tmp->getType()->isIntegerTy()) {
+uint64_t ResSize = CGM.getDataLayout().getTypeSizeInBits(TruncTy);
+Tmp = Builder.CreateTrunc(
+Tmp, llvm::IntegerType::get(CTX, (unsigned)ResSize));
+Tmp = Builder.CreateIntToPtr(Tmp, TruncTy);
+  } else if (Tmp->getType()->isPointerTy() && TruncTy->isIntegerTy()) {
+uint64_t TmpSize =
+CGM.getDataLayout().getTypeSizeInBits(Tmp->getType());
+Tmp = Builder.CreatePtrToInt(
+Tmp, llvm::IntegerType::get(CTX, (unsigned)TmpSize));
+Tmp = Builder.CreateTrunc(Tmp, TruncTy);
+  } else if (TruncTy->isIntegerTy()) {
+Tmp = Builder.CreateZExtOrTrunc(Tmp, TruncTy);
+  } else if (TruncTy->isVectorTy()) {
+Tmp = Builder.CreateBitCast(Tmp, TruncTy);
+  }
+}
+
+LValue Dest = ResultRegDests[i];
+// ResultTypeRequiresCast elements correspond to the first
+// ResultTypeRequiresCast.size() elements of RegResults.
+if ((i < ResultTypeRequiresCast.size()) && ResultTypeRequiresCast[i]) {
+  unsigned Size = CGF.getContext().getTypeSize(ResultRegQualTys[i]);
+  Address A =
+  Builder.CreateElementBitCast(Dest.getAddress(CGF), ResultRegTypes[i]);
+  if (CGF.getTargetHooks().isScalarizableAsmOperand(CGF, TruncTy)) {
+Builder.CreateStore(Tmp, A);
+continue;
+  }
+
+  QualType Ty =
+  CGF.getContext().getIntTypeForBitwidth(Size, /*Signed*/ false);
+  if (Ty.isNull()) {
+const Expr *OutExpr = S.getOutputExpr(i);
+CGM.getDiags().Report(OutExpr->getExprLoc(),
+  diag::err_store_value_to_reg);
+return;
+  }
+  Dest = CGF.MakeAddrLValue(A, Ty);
+}
+CGF.EmitStoreThroughLValue(RValue::get(Tmp), Dest);
+  }
+}
+
 void CodeGenFunction::EmitAsmStmt(const AsmStmt ) {
   // Pop all cleanup blocks at the end of the asm statement.
   CodeGenFunction::RunCleanupsScope Cleanups(*this);
@@ -2626,7 +2714,7 @@
   SmallVector Transfer;
   llvm::BasicBlock *Fallthrough = nullptr;
   bool IsGCCAsmGoto = false;
-  if (const auto *GS =  dyn_cast()) {
+  if (const auto *GS = dyn_cast()) {
 IsGCCAsmGoto = GS->isAsmGoto();
 if (IsGCCAsmGoto) {
   for (const auto *E : GS->labels()) {
@@ -2724,9 

[PATCH] D136497: [Clang] support for outputs along indirect edges of asm goto

2022-12-21 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 484671.
nickdesaulniers edited the summary of this revision.
nickdesaulniers added a comment.

- rebase, drop callbrpad inst


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136497

Files:
  clang/docs/LanguageExtensions.rst
  clang/lib/CodeGen/CGStmt.cpp
  clang/test/CodeGen/asm-goto.c
  clang/test/CodeGen/asm-goto2.c
  clang/test/Modules/asm-goto.c

Index: clang/test/Modules/asm-goto.c
===
--- clang/test/Modules/asm-goto.c
+++ clang/test/Modules/asm-goto.c
@@ -5,7 +5,7 @@
 
 // CHECK-LABEL: define {{.*}} @foo(
 // CHECK: callbr {{.*}} "=r,!i{{.*}}()
-// CHECK-NEXT: to label %asm.fallthrough [label %indirect]
+// CHECK-NEXT: to label %asm.fallthrough [label %indirect.split]
 
 int bar(void) {
   return foo();
Index: clang/test/CodeGen/asm-goto2.c
===
--- /dev/null
+++ clang/test/CodeGen/asm-goto2.c
@@ -0,0 +1,156 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: x86-registered-target
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -O0 -emit-llvm %s -o - | FileCheck %s
+
+// CHECK-LABEL: @test0(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[RET:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[TMP0:%.*]] = callbr i32 asm "", "=r,!i,~{dirflag},~{fpsr},~{flags}"() #[[ATTR1:[0-9]+]]
+// CHECK-NEXT:to label [[ASM_FALLTHROUGH:%.*]] [label %z.split], !srcloc !2
+// CHECK:   asm.fallthrough:
+// CHECK-NEXT:store i32 [[TMP0]], ptr [[RET]], align 4
+// CHECK-NEXT:store i32 42, ptr [[RET]], align 4
+// CHECK-NEXT:br label [[Z:%.*]]
+// CHECK:   z:
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, ptr [[RET]], align 4
+// CHECK-NEXT:ret i32 [[TMP1]]
+// CHECK:   z.split:
+// CHECK-NEXT:store i32 [[TMP0]], ptr [[RET]], align 4
+// CHECK-NEXT:br label [[Z]]
+//
+int test0 (void) {
+  int ret;
+  asm goto ("" : "=r"(ret):::z);
+  ret = 42;
+z:
+  return ret;
+}
+
+// CHECK-LABEL: @test1(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[RET:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[B:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[TMP0:%.*]] = callbr { i32, i32 } asm "", "=r,=r,!i,~{dirflag},~{fpsr},~{flags}"() #[[ATTR1]]
+// CHECK-NEXT:to label [[ASM_FALLTHROUGH:%.*]] [label %z.split], !srcloc !3
+// CHECK:   asm.fallthrough:
+// CHECK-NEXT:[[ASMRESULT:%.*]] = extractvalue { i32, i32 } [[TMP0]], 0
+// CHECK-NEXT:[[ASMRESULT1:%.*]] = extractvalue { i32, i32 } [[TMP0]], 1
+// CHECK-NEXT:store i32 [[ASMRESULT]], ptr [[RET]], align 4
+// CHECK-NEXT:store i32 [[ASMRESULT1]], ptr [[B]], align 4
+// CHECK-NEXT:store i32 42, ptr [[RET]], align 4
+// CHECK-NEXT:br label [[Z:%.*]]
+// CHECK:   z:
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, ptr [[RET]], align 4
+// CHECK-NEXT:ret i32 [[TMP1]]
+// CHECK:   z.split:
+// CHECK-NEXT:[[ASMRESULT2:%.*]] = extractvalue { i32, i32 } [[TMP0]], 0
+// CHECK-NEXT:[[ASMRESULT3:%.*]] = extractvalue { i32, i32 } [[TMP0]], 1
+// CHECK-NEXT:store i32 [[ASMRESULT2]], ptr [[RET]], align 4
+// CHECK-NEXT:store i32 [[ASMRESULT3]], ptr [[B]], align 4
+// CHECK-NEXT:br label [[Z]]
+//
+int test1 (void) {
+  int ret, b;
+  asm goto ("" : "=r"(ret), "=r"(b):::z);
+  ret = 42;
+z:
+  return ret;
+}
+
+// CHECK-LABEL: @test2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[RET:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[B:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[TMP0:%.*]] = callbr { i32, i32 } asm "", "=r,=r,!i,~{dirflag},~{fpsr},~{flags}"() #[[ATTR1]]
+// CHECK-NEXT:to label [[ASM_FALLTHROUGH:%.*]] [label %z.split], !srcloc !4
+// CHECK:   asm.fallthrough:
+// CHECK-NEXT:[[ASMRESULT:%.*]] = extractvalue { i32, i32 } [[TMP0]], 0
+// CHECK-NEXT:[[ASMRESULT1:%.*]] = extractvalue { i32, i32 } [[TMP0]], 1
+// CHECK-NEXT:store i32 [[ASMRESULT]], ptr [[RET]], align 4
+// CHECK-NEXT:store i32 [[ASMRESULT1]], ptr [[B]], align 4
+// CHECK-NEXT:[[TMP1:%.*]] = callbr { i32, i32 } asm "", "=r,=r,!i,~{dirflag},~{fpsr},~{flags}"() #[[ATTR1]]
+// CHECK-NEXT:to label [[ASM_FALLTHROUGH4:%.*]] [label %z.split9], !srcloc !5
+// CHECK:   asm.fallthrough4:
+// CHECK-NEXT:[[ASMRESULT5:%.*]] = extractvalue { i32, i32 } [[TMP1]], 0
+// CHECK-NEXT:[[ASMRESULT6:%.*]] = extractvalue { i32, i32 } [[TMP1]], 1
+// CHECK-NEXT:store i32 [[ASMRESULT5]], ptr [[RET]], align 4
+// CHECK-NEXT:store i32 [[ASMRESULT6]], ptr [[B]], align 4
+// CHECK-NEXT:br label [[Z:%.*]]
+// CHECK:   z:
+// CHECK-NEXT:[[TMP2:%.*]] = load i32, ptr [[RET]], align 4
+// CHECK-NEXT:ret i32 [[TMP2]]
+// CHECK:   z.split:
+// CHECK-NEXT:[[ASMRESULT2:%.*]] = extractvalue { i32, i32 } [[TMP0]], 0
+// CHECK-NEXT:[[ASMRESULT3:%.*]] = extractvalue { i32, i32 } [[TMP0]], 1
+// 

[PATCH] D137107: Allow MS extension: support of constexpr with __declspec(dllimport).

2022-12-21 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added inline comments.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:5006
+if (NeedsGlobalCtor || NeedsGlobalDtor)
+  DelayedCXXInitPosition[D] = ~0U;
+  } else {

efriedma wrote:
> zahiraam wrote:
> > efriedma wrote:
> > > zahiraam wrote:
> > > > Do you agree this should be done only when one of those flags is on?
> > > Yes, that's fine; I wasn't really paying close attention to the exact 
> > > code.  Just wanted to make the point about the structure of the if 
> > > statements, and code was the easiest way to explain it.
> > > 
> > > Maybe the outer if statement should actually be `if (isStaticInit(D, 
> > > getLangOpts()) && NeedsGlobalCtor) {`.
> > > 
> > > On a related note, we might want to avoid the name "ctor", in case that 
> > > accidentally conflicts with some user code; an "__"-prefixed name would 
> > > be appropriate.
> > >> Maybe the outer if statement should actually be if (isStaticInit(D, 
> > >> getLangOpts()) && NeedsGlobalCtor) {
> > Not sure about that! There are cases where (isStaticInit(D, getLangOpts())) 
> > = true and NeedsGlobalCtor=false, but NeedsGlobalDtor=true. In which case a 
> > __dtor needs to be emitted, no?
> > 
> > Writing the condition as you are proposing would actually not get me into 
> > the body to emit the __dtor. Is that what we want?
> EmitCXXGlobalVarDeclInitFunc should be able to handle that case.
> 
> Looking again, I'm a little concerned that in the isStaticInit() case, we're 
> skipping a bunch of the logic in EmitCXXGlobalVarDeclInitFunc. 
> EmitCXXCtorInit handles the basic cases correctly, but there are a lot of 
> special cases in EmitCXXGlobalVarDeclInitFunc.
I have left the condition as it was to make sure no cases are left. What other 
cases are you thinking of? 



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

https://reviews.llvm.org/D137107

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


[PATCH] D137107: Allow MS extension: support of constexpr with __declspec(dllimport).

2022-12-21 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam updated this revision to Diff 484665.
zahiraam marked an inline comment as done.
Herald added a subscriber: aheejin.

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

https://reviews.llvm.org/D137107

Files:
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/CodeGenCXX/PR19955.cpp
  clang/test/CodeGenCXX/aix-static-init.cpp
  clang/test/CodeGenCXX/call-conv-thru-alias.cpp
  clang/test/CodeGenCXX/const-init-cxx11.cpp
  clang/test/CodeGenCXX/ctor-dtor-alias.cpp
  clang/test/CodeGenCXX/cxx11-thread-local.cpp
  clang/test/CodeGenCXX/cxx1z-initializer-aggregate.cpp
  clang/test/CodeGenCXX/cxx2a-thread-local-constinit.cpp
  clang/test/CodeGenCXX/dllimport.cpp
  clang/test/CodeGenCXX/dso-handle-custom.cpp
  clang/test/CodeGenCXX/funcattrs-global-ctor-dtor.cpp
  clang/test/CodeGenCXX/no_destroy.cpp
  clang/test/CodeGenCXX/non-const-init-cxx2a.cpp
  clang/test/CodeGenCXX/runtime-dllstorage.cpp
  clang/test/CodeGenCXX/static-destructor.cpp
  clang/test/CodeGenOpenCLCXX/atexit.clcpp
  clang/test/SemaCXX/PR19955.cpp
  clang/test/SemaCXX/constant-expression-cxx11.cpp
  clang/test/SemaCXX/dllimport-constexpr.cpp

Index: clang/test/SemaCXX/dllimport-constexpr.cpp
===
--- clang/test/SemaCXX/dllimport-constexpr.cpp
+++ clang/test/SemaCXX/dllimport-constexpr.cpp
@@ -40,7 +40,6 @@
 // constexpr initialization doesn't work for dllimport things.
 // expected-error@+1{{must be initialized by a constant expression}}
 constexpr void (*constexpr_import_func)() = _func;
-// expected-error@+1{{must be initialized by a constant expression}}
 constexpr int *constexpr_import_int = _int;
 // expected-error@+1{{must be initialized by a constant expression}}
 constexpr void (Foo::*constexpr_memptr)() = ::imported_method;
@@ -60,3 +59,11 @@
   // expected-note@+1 {{requested here}}
   StaticConstexpr::g_fp();
 }
+
+extern int __declspec(dllimport) val;
+constexpr int& val_ref = val;
+
+void assigndllimporttoconst () {
+  extern int _declspec(dllimport) val;
+  constexpr int& val_ref = val;
+}
Index: clang/test/SemaCXX/constant-expression-cxx11.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -1595,7 +1595,7 @@
   void f(int k) { // expected-note {{here}}
 int arr[k]; // expected-warning {{C99}} expected-note {{function parameter 'k'}}
 constexpr int n = 1 +
-sizeof(arr) // expected-error {{constant expression}}
+sizeof(arr) // expected-error{{constexpr variable 'n' must be initialized by a constant expression}}
 * 3;
   }
 }
Index: clang/test/SemaCXX/PR19955.cpp
===
--- clang/test/SemaCXX/PR19955.cpp
+++ clang/test/SemaCXX/PR19955.cpp
@@ -2,7 +2,7 @@
 // RUN: %clang_cc1 -triple i686-mingw32 -verify -std=c++11 %s
 
 extern int __attribute__((dllimport)) var;
-constexpr int *varp =  // expected-error {{must be initialized by a constant expression}}
+constexpr int *varp = 
 
 extern __attribute__((dllimport)) void fun();
 constexpr void (*funp)(void) =  // expected-error {{must be initialized by a constant expression}}
Index: clang/test/CodeGenOpenCLCXX/atexit.clcpp
===
--- clang/test/CodeGenOpenCLCXX/atexit.clcpp
+++ clang/test/CodeGenOpenCLCXX/atexit.clcpp
@@ -5,7 +5,7 @@
 };
 S s;
 
-//CHECK-LABEL: define internal spir_func void @__cxx_global_var_init()
+//CHECK-LABEL: define internal spir_func void @__dtor()
 //CHECK: call spir_func i32 @__cxa_atexit(void (i8*)* bitcast (void (%struct.S addrspace(4)*)* @_ZNU3AS41SD1Ev to void (i8*)*), i8* null, i8 addrspace(1)* @__dso_handle)
 
 //CHECK: declare spir_func i32 @__cxa_atexit(void (i8*)*, i8*, i8 addrspace(1)*)
Index: clang/test/CodeGenCXX/static-destructor.cpp
===
--- clang/test/CodeGenCXX/static-destructor.cpp
+++ clang/test/CodeGenCXX/static-destructor.cpp
@@ -16,17 +16,17 @@
 Foo global;
 
 // X86 destructors have void return, and are registered directly with __cxa_atexit.
-// X86: define internal void @__cxx_global_var_init()
+// X86-LABEL: define internal void @__dtor()
 // X86:   call i32 @__cxa_atexit(ptr @_ZN3FooD1Ev, ptr @global, ptr @__dso_handle)
 
 // ARM destructors return this, but can be registered directly with __cxa_atexit
 // because the calling conventions tolerate the mismatch.
-// ARM: define internal void @__cxx_global_var_init()
+// ARM-LABEL: define internal void @__dtor()
 // ARM:   call i32 @__cxa_atexit(ptr @_ZN3FooD1Ev, ptr @global, ptr @__dso_handle)
 
 // Wasm destructors return this, and use 

[PATCH] D137517: [TargetParser] Generate the defs for RISCV CPUs using llvm-tblgen.

2022-12-21 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli added inline comments.



Comment at: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:52
+  for (auto  : Map) {
+const auto  = Def.second;
+if (Record->isSubClassOf("RISCVProcessorModelTUNE_PROC"))

barannikov88 wrote:
> fpetrogalli wrote:
> > barannikov88 wrote:
> > > Same for the loop above.
> > ```
> > /Users/fpetrogalli/projects/cpu-defs/upstream/llvm-project/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:38:17:
> >  error: variable 'Record' with type 'const auto *' has incompatible 
> > initializer of type 'const std::unique_ptr'
> > const auto *Record = Def.second;
> > ```
> Whoops, my bad, sorry.
> Never liked these 'auto's... Never know what is behind them. Looks like a raw 
> pointer, but it is not.
> 
I am not a fan either of `auto`. Removed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137517

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


[PATCH] D137517: [TargetParser] Generate the defs for RISCV CPUs using llvm-tblgen.

2022-12-21 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli updated this revision to Diff 484664.
fpetrogalli marked an inline comment as done.
fpetrogalli added a comment.

Remove all `auto` types in the emitter.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137517

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  llvm/include/llvm/TargetParser/RISCVTargetParser.def
  llvm/include/llvm/TargetParser/RISCVTargetParser.h
  llvm/include/llvm/TargetParser/TargetParser.h
  llvm/include/llvm/module.modulemap
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVISelLowering.h
  llvm/lib/TargetParser/CMakeLists.txt
  llvm/lib/TargetParser/RISCVTargetParser.cpp
  llvm/lib/TargetParser/TargetParser.cpp
  llvm/utils/TableGen/CMakeLists.txt
  llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
  llvm/utils/TableGen/TableGen.cpp
  llvm/utils/TableGen/TableGenBackends.h

Index: llvm/utils/TableGen/TableGenBackends.h
===
--- llvm/utils/TableGen/TableGenBackends.h
+++ llvm/utils/TableGen/TableGenBackends.h
@@ -94,7 +94,7 @@
 void EmitDirectivesDecl(RecordKeeper , raw_ostream );
 void EmitDirectivesImpl(RecordKeeper , raw_ostream );
 void EmitDXILOperation(RecordKeeper , raw_ostream );
-
+void EmitRISCVTargetDef(const RecordKeeper , raw_ostream );
 } // End llvm namespace
 
 #endif
Index: llvm/utils/TableGen/TableGen.cpp
===
--- llvm/utils/TableGen/TableGen.cpp
+++ llvm/utils/TableGen/TableGen.cpp
@@ -58,6 +58,7 @@
   GenDirectivesEnumDecl,
   GenDirectivesEnumImpl,
   GenDXILOperation,
+  GenRISCVTargetDef,
 };
 
 namespace llvm {
@@ -141,8 +142,9 @@
 clEnumValN(GenDirectivesEnumImpl, "gen-directive-impl",
"Generate directive related implementation code"),
 clEnumValN(GenDXILOperation, "gen-dxil-operation",
-   "Generate DXIL operation information")));
-
+   "Generate DXIL operation information"),
+clEnumValN(GenRISCVTargetDef, "gen-riscv-target-def",
+   "Generate the list of CPU for RISCV")));
 cl::OptionCategory PrintEnumsCat("Options for -print-enums");
 cl::opt Class("class", cl::desc("Print Enum list for this class"),
cl::value_desc("class name"),
@@ -278,6 +280,9 @@
   case GenDXILOperation:
 EmitDXILOperation(Records, OS);
 break;
+  case GenRISCVTargetDef:
+EmitRISCVTargetDef(Records, OS);
+break;
   }
 
   return false;
Index: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
===
--- /dev/null
+++ llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
@@ -0,0 +1,62 @@
+//===- RISCVTargetDefEmitter.cpp - Generate lists of RISCV CPUs ---===//
+//
+// 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 tablegen backend emits the include file needed by the target
+// parser to parse the RISC-V CPUs.
+//
+//===--===//
+
+#include "TableGenBackends.h"
+#include "llvm/TableGen/Record.h"
+
+using namespace llvm;
+
+static std::string getEnumFeatures(const Record ) {
+  std::vector Features = Rec.getValueAsListOfDefs("Features");
+  if (find_if(Features, [](const Record *R) {
+return R->getName() == "Feature64Bit";
+  }) != Features.end())
+return "FK_64BIT";
+
+  return "FK_NONE";
+}
+
+void llvm::EmitRISCVTargetDef(const RecordKeeper , raw_ostream ) {
+  using MapTy = std::pair>;
+  using RecordMap = std::map, std::less<>>;
+  const RecordMap  = RK.getDefs();
+
+  OS << "#ifndef PROC\n"
+ << "#define PROC(ENUM, NAME, FEATURES, DEFAULT_MARCH)\n"
+ << "#endif\n\n";
+
+  OS << "PROC(INVALID, {\"invalid\"}, FK_INVALID, {\"\"})\n";
+  // Iterate on all definition records.
+  for (const MapTy  : Map) {
+const Record  = *(Def.second);
+if (Rec.isSubClassOf("RISCVProcessorModelPROC"))
+  OS << "PROC(" << Rec.getName() << ", "
+ << "{\"" << Rec.getValueAsString("Name") << "\"},"
+ << getEnumFeatures(Rec) << ", "
+ << "{\"" << Rec.getValueAsString("DefaultMarch") << "\"})\n";
+  }
+  OS << "\n#undef PROC\n";
+  OS << "\n";
+  OS << "#ifndef TUNE_PROC\n"
+ << "#define TUNE_PROC(ENUM, NAME)\n"
+ << "#endif\n\n";
+  OS << "TUNE_PROC(GENERIC, \"generic\")\n";
+  for (const MapTy  : Map) {
+const Record  = *(Def.second);
+if (Rec.isSubClassOf("RISCVProcessorModelTUNE_PROC"))
+  OS << "TUNE_PROC(" << Rec.getName() << ", "
+ << "\"" << Rec.getValueAsString("Name") << "\")\n";
+  }
+
+  OS << "\n#undef TUNE_PROC\n";
+}
Index: 

[PATCH] D137517: [TargetParser] Generate the defs for RISCV CPUs using llvm-tblgen.

2022-12-21 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli added a comment.

In D137517#4009328 , @jrtc27 wrote:

> Hm, this means that llvm/lib/Target/$TARGET/$TARGET.td needs to remain 
> working (or at least mostly working, things like ISel patterns can fail to 
> type check) in order for Clang to build, since we're now introducing a 
> dependency on llvm/lib/Target/$TARGET in Clang where there didn't used to be 
> (regardless of whether you care about that target). That's probably fine but 
> worth pointing out, especially in the context of experimental targets that 
> are supposed to be mostly ignorable.

Yes,`llvm/lib/Target/$TARGET/$TARGET.td` need to remain working. But this is 
true only for those targets that have an auto generative process of the list of 
CPUs and features needed by the target parser. Right now the only target having 
this is RISCV. Any target do not need to worry about the dependencies 
introduced by this patch , until they introduce their own custom generator.




Comment at: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:16
+#include 
+namespace llvm {
+

barannikov88 wrote:
> fpetrogalli wrote:
> > barannikov88 wrote:
> > > This [[ 
> > > https://llvm.org/docs/CodingStandards.html#use-namespace-qualifiers-to-implement-previously-declared-functions
> > >  | should be ]] `using namespace llvm;`
> > Hum, if I do this, I get:
> > 
> > ```
> > Undefined symbols for architecture arm64:
> >   "llvm::EmitRISCVTargetDef(llvm::RecordKeeper&, llvm::raw_ostream&)", 
> > referenced from:
> >   (anonymous namespace)::LLVMTableGenMain(llvm::raw_ostream&, 
> > llvm::RecordKeeper&) in TableGen.cpp.o
> > ld: symbol(s) not found for architecture arm64
> > ```
> > 
> > It is a bit surprising because the linking command has 
> > `utils/TableGen/CMakeFiles/llvm-tblgen.dir/RISCVTargetDefEmitter.cpp.o` 
> > into it... Some of the files in this folder do not use the convention you 
> > pointed at, it it OK if I live it as it is?
> Right, after `using namespace llvm` you have to write
> `llvm::EmitRISCVTargetDef` with explicit `llvm::` qualification. This is the 
> whole point of this guideline :)
> Please see the [[ 
> https://llvm.org/docs/CodingStandards.html#use-namespace-qualifiers-to-implement-previously-declared-functions
>  | link ]].
> 
Yeah, I did that, I just missed adding the declaration via header file 
inclusion...

```
@@ -12,8 +12,8 @@
 
//===--===//

 #include "llvm/TableGen/Record.h"
-
-namespace llvm {
+#include "TableGenBackends.h"
+using namespace llvm;

 static std::string getEnumFeatures(Record ) {
   std::vector Features = Rec.getValueAsListOfDefs("Features");
@@ -25,7 +25,7 @@ static std::string getEnumFeatures(Record ) {
   return "FK_NONE";
 }

-void EmitRISCVTargetDef(const RecordKeeper , raw_ostream ) {
+void llvm::EmitRISCVTargetDef(const RecordKeeper , raw_ostream ) {
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137517

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


[PATCH] D137517: [TargetParser] Generate the defs for RISCV CPUs using llvm-tblgen.

2022-12-21 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 added inline comments.



Comment at: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:52
+  for (auto  : Map) {
+const auto  = Def.second;
+if (Record->isSubClassOf("RISCVProcessorModelTUNE_PROC"))

fpetrogalli wrote:
> barannikov88 wrote:
> > Same for the loop above.
> ```
> /Users/fpetrogalli/projects/cpu-defs/upstream/llvm-project/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:38:17:
>  error: variable 'Record' with type 'const auto *' has incompatible 
> initializer of type 'const std::unique_ptr'
> const auto *Record = Def.second;
> ```
Whoops, my bad, sorry.
Never liked these 'auto's... Never know what is behind them. Looks like a raw 
pointer, but it is not.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137517

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


[PATCH] D137517: [TargetParser] Generate the defs for RISCV CPUs using llvm-tblgen.

2022-12-21 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli updated this revision to Diff 484658.
fpetrogalli marked an inline comment as done.
fpetrogalli added a comment.

Remove `RISCVTargetParser.def` from the module map.

Follow the guidelines on  using namespace llvm 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137517

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  llvm/include/llvm/TargetParser/RISCVTargetParser.def
  llvm/include/llvm/TargetParser/RISCVTargetParser.h
  llvm/include/llvm/TargetParser/TargetParser.h
  llvm/include/llvm/module.modulemap
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVISelLowering.h
  llvm/lib/TargetParser/CMakeLists.txt
  llvm/lib/TargetParser/RISCVTargetParser.cpp
  llvm/lib/TargetParser/TargetParser.cpp
  llvm/utils/TableGen/CMakeLists.txt
  llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
  llvm/utils/TableGen/TableGen.cpp
  llvm/utils/TableGen/TableGenBackends.h

Index: llvm/utils/TableGen/TableGenBackends.h
===
--- llvm/utils/TableGen/TableGenBackends.h
+++ llvm/utils/TableGen/TableGenBackends.h
@@ -94,7 +94,7 @@
 void EmitDirectivesDecl(RecordKeeper , raw_ostream );
 void EmitDirectivesImpl(RecordKeeper , raw_ostream );
 void EmitDXILOperation(RecordKeeper , raw_ostream );
-
+void EmitRISCVTargetDef(const RecordKeeper , raw_ostream );
 } // End llvm namespace
 
 #endif
Index: llvm/utils/TableGen/TableGen.cpp
===
--- llvm/utils/TableGen/TableGen.cpp
+++ llvm/utils/TableGen/TableGen.cpp
@@ -58,6 +58,7 @@
   GenDirectivesEnumDecl,
   GenDirectivesEnumImpl,
   GenDXILOperation,
+  GenRISCVTargetDef,
 };
 
 namespace llvm {
@@ -141,8 +142,9 @@
 clEnumValN(GenDirectivesEnumImpl, "gen-directive-impl",
"Generate directive related implementation code"),
 clEnumValN(GenDXILOperation, "gen-dxil-operation",
-   "Generate DXIL operation information")));
-
+   "Generate DXIL operation information"),
+clEnumValN(GenRISCVTargetDef, "gen-riscv-target-def",
+   "Generate the list of CPU for RISCV")));
 cl::OptionCategory PrintEnumsCat("Options for -print-enums");
 cl::opt Class("class", cl::desc("Print Enum list for this class"),
cl::value_desc("class name"),
@@ -278,6 +280,9 @@
   case GenDXILOperation:
 EmitDXILOperation(Records, OS);
 break;
+  case GenRISCVTargetDef:
+EmitRISCVTargetDef(Records, OS);
+break;
   }
 
   return false;
Index: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
===
--- /dev/null
+++ llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
@@ -0,0 +1,60 @@
+//===- RISCVTargetDefEmitter.cpp - Generate lists of RISCV CPUs ---===//
+//
+// 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 tablegen backend emits the include file needed by the target
+// parser to parse the RISC-V CPUs.
+//
+//===--===//
+
+#include "TableGenBackends.h"
+#include "llvm/TableGen/Record.h"
+
+using namespace llvm;
+
+static std::string getEnumFeatures(Record ) {
+  std::vector Features = Rec.getValueAsListOfDefs("Features");
+  if (find_if(Features, [](Record *R) {
+return R->getName() == "Feature64Bit";
+  }) != Features.end())
+return "FK_64BIT";
+
+  return "FK_NONE";
+}
+
+void llvm::EmitRISCVTargetDef(const RecordKeeper , raw_ostream ) {
+  const auto  = RK.getDefs();
+
+  OS << "#ifndef PROC\n"
+ << "#define PROC(ENUM, NAME, FEATURES, DEFAULT_MARCH)\n"
+ << "#endif\n\n";
+
+  OS << "PROC(INVALID, {\"invalid\"}, FK_INVALID, {\"\"})\n";
+  // Iterate on all definition records.
+  for (const auto  : Map) {
+const auto  = Def.second;
+if (Record->isSubClassOf("RISCVProcessorModelPROC"))
+  OS << "PROC(" << Record->getName() << ", "
+ << "{\"" << Record->getValueAsString("Name") << "\"},"
+ << getEnumFeatures(*Record) << ", "
+ << "{\"" << Record->getValueAsString("DefaultMarch") << "\"})\n";
+  }
+  OS << "\n#undef PROC\n";
+  OS << "\n";
+  OS << "#ifndef TUNE_PROC\n"
+ << "#define TUNE_PROC(ENUM, NAME)\n"
+ << "#endif\n\n";
+  OS << "TUNE_PROC(GENERIC, \"generic\")\n";
+  for (const auto  : Map) {
+const auto  = Def.second;
+if (Record->isSubClassOf("RISCVProcessorModelTUNE_PROC"))
+  OS << "TUNE_PROC(" << Record->getName() << ", "
+ << "\"" << 

[PATCH] D138392: clang/HIP: Fix broken implementations of __make_mantissa* functions

2022-12-21 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl accepted this revision.
yaxunl added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks.

It seems gcc assumes the argument to nan is nonnull 
(https://godbolt.org/z/xzb8T6Gon), so we can assume that too.


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

https://reviews.llvm.org/D138392

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


[PATCH] D137070: [clang][Interp] Support destructors

2022-12-21 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik accepted this revision.
shafik added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D137070

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


[PATCH] D135750: [clang][Interp] Track initialization state of local variables

2022-12-21 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/lib/AST/Interp/Interp.h:918
 return false;
+  if (!Ptr.isRoot())
+Ptr.initialize();

tbaeder wrote:
> shafik wrote:
> > Can you explain what is going on here? Why do we need to initialize if it 
> > is not root?
> Root means that `Base == 0`, so it cannot have a `InlineDescriptor` before 
> the `Base` offset. That is mainly the case for global variables.
Can we add a comment that explains this a little better? I still don't get the 
significance, so I definitely missing something.

Also, why do we initialized before the store? 


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

https://reviews.llvm.org/D135750

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


[PATCH] D137517: [TargetParser] Generate the defs for RISCV CPUs using llvm-tblgen.

2022-12-21 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli updated this revision to Diff 484655.
fpetrogalli added a comment.

Restore the following...

  -const auto *Record = Def.second;
  +const auto  = Def.second;

... to prevent this error:

  /<...>/llvm-project/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:38:17: 
error: variable 'Record' with type 'const auto *' has incompatible initializer 
of type 'const std::unique_ptr'
  const auto *Record = Def.second;


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137517

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  llvm/include/llvm/TargetParser/RISCVTargetParser.def
  llvm/include/llvm/TargetParser/RISCVTargetParser.h
  llvm/include/llvm/TargetParser/TargetParser.h
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVISelLowering.h
  llvm/lib/TargetParser/CMakeLists.txt
  llvm/lib/TargetParser/RISCVTargetParser.cpp
  llvm/lib/TargetParser/TargetParser.cpp
  llvm/utils/TableGen/CMakeLists.txt
  llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
  llvm/utils/TableGen/TableGen.cpp
  llvm/utils/TableGen/TableGenBackends.h

Index: llvm/utils/TableGen/TableGenBackends.h
===
--- llvm/utils/TableGen/TableGenBackends.h
+++ llvm/utils/TableGen/TableGenBackends.h
@@ -94,7 +94,7 @@
 void EmitDirectivesDecl(RecordKeeper , raw_ostream );
 void EmitDirectivesImpl(RecordKeeper , raw_ostream );
 void EmitDXILOperation(RecordKeeper , raw_ostream );
-
+void EmitRISCVTargetDef(const RecordKeeper , raw_ostream );
 } // End llvm namespace
 
 #endif
Index: llvm/utils/TableGen/TableGen.cpp
===
--- llvm/utils/TableGen/TableGen.cpp
+++ llvm/utils/TableGen/TableGen.cpp
@@ -58,6 +58,7 @@
   GenDirectivesEnumDecl,
   GenDirectivesEnumImpl,
   GenDXILOperation,
+  GenRISCVTargetDef,
 };
 
 namespace llvm {
@@ -141,8 +142,9 @@
 clEnumValN(GenDirectivesEnumImpl, "gen-directive-impl",
"Generate directive related implementation code"),
 clEnumValN(GenDXILOperation, "gen-dxil-operation",
-   "Generate DXIL operation information")));
-
+   "Generate DXIL operation information"),
+clEnumValN(GenRISCVTargetDef, "gen-riscv-target-def",
+   "Generate the list of CPU for RISCV")));
 cl::OptionCategory PrintEnumsCat("Options for -print-enums");
 cl::opt Class("class", cl::desc("Print Enum list for this class"),
cl::value_desc("class name"),
@@ -278,6 +280,9 @@
   case GenDXILOperation:
 EmitDXILOperation(Records, OS);
 break;
+  case GenRISCVTargetDef:
+EmitRISCVTargetDef(Records, OS);
+break;
   }
 
   return false;
Index: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
===
--- /dev/null
+++ llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
@@ -0,0 +1,61 @@
+//===- RISCVTargetDefEmitter.cpp - Generate lists of RISCV CPUs ---===//
+//
+// 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 tablegen backend emits the include file needed by the target
+// parser to parse the RISC-V CPUs.
+//
+//===--===//
+
+#include "llvm/TableGen/Record.h"
+
+namespace llvm {
+
+static std::string getEnumFeatures(Record ) {
+  std::vector Features = Rec.getValueAsListOfDefs("Features");
+  if (find_if(Features, [](Record *R) {
+return R->getName() == "Feature64Bit";
+  }) != Features.end())
+return "FK_64BIT";
+
+  return "FK_NONE";
+}
+
+void EmitRISCVTargetDef(const RecordKeeper , raw_ostream ) {
+  const auto  = RK.getDefs();
+
+  OS << "#ifndef PROC\n"
+ << "#define PROC(ENUM, NAME, FEATURES, DEFAULT_MARCH)\n"
+ << "#endif\n\n";
+
+  OS << "PROC(INVALID, {\"invalid\"}, FK_INVALID, {\"\"})\n";
+  // Iterate on all definition records.
+  for (const auto  : Map) {
+const auto  = Def.second;
+if (Record->isSubClassOf("RISCVProcessorModelPROC"))
+  OS << "PROC(" << Record->getName() << ", "
+ << "{\"" << Record->getValueAsString("Name") << "\"},"
+ << getEnumFeatures(*Record) << ", "
+ << "{\"" << Record->getValueAsString("DefaultMarch") << "\"})\n";
+  }
+  OS << "\n#undef PROC\n";
+  OS << "\n";
+  OS << "#ifndef TUNE_PROC\n"
+ << "#define TUNE_PROC(ENUM, NAME)\n"
+ << "#endif\n\n";
+  OS << "TUNE_PROC(GENERIC, \"generic\")\n";
+  for (const auto  : Map) {
+const auto  = Def.second;
+if (Record->isSubClassOf("RISCVProcessorModelTUNE_PROC"))
+  OS << "TUNE_PROC(" << Record->getName() << ", "
+ << 

[PATCH] D137517: [TargetParser] Generate the defs for RISCV CPUs using llvm-tblgen.

2022-12-21 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli updated this revision to Diff 484654.
fpetrogalli marked an inline comment as done.
fpetrogalli added a comment.

ops - this was wrong:

  
/Users/fpetrogalli/projects/cpu-defs/upstream/llvm-project/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:38:17:
 error: variable 'Record' with type 'const auto *' has incompatible initializer 
of type 'const std::unique_ptr'
  const auto *Record = Def.second;

I'll revert it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137517

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  llvm/include/llvm/TargetParser/RISCVTargetParser.def
  llvm/include/llvm/TargetParser/RISCVTargetParser.h
  llvm/include/llvm/TargetParser/TargetParser.h
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVISelLowering.h
  llvm/lib/TargetParser/CMakeLists.txt
  llvm/lib/TargetParser/RISCVTargetParser.cpp
  llvm/lib/TargetParser/TargetParser.cpp
  llvm/utils/TableGen/CMakeLists.txt
  llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
  llvm/utils/TableGen/TableGen.cpp
  llvm/utils/TableGen/TableGenBackends.h

Index: llvm/utils/TableGen/TableGenBackends.h
===
--- llvm/utils/TableGen/TableGenBackends.h
+++ llvm/utils/TableGen/TableGenBackends.h
@@ -94,7 +94,7 @@
 void EmitDirectivesDecl(RecordKeeper , raw_ostream );
 void EmitDirectivesImpl(RecordKeeper , raw_ostream );
 void EmitDXILOperation(RecordKeeper , raw_ostream );
-
+void EmitRISCVTargetDef(const RecordKeeper , raw_ostream );
 } // End llvm namespace
 
 #endif
Index: llvm/utils/TableGen/TableGen.cpp
===
--- llvm/utils/TableGen/TableGen.cpp
+++ llvm/utils/TableGen/TableGen.cpp
@@ -58,6 +58,7 @@
   GenDirectivesEnumDecl,
   GenDirectivesEnumImpl,
   GenDXILOperation,
+  GenRISCVTargetDef,
 };
 
 namespace llvm {
@@ -141,8 +142,9 @@
 clEnumValN(GenDirectivesEnumImpl, "gen-directive-impl",
"Generate directive related implementation code"),
 clEnumValN(GenDXILOperation, "gen-dxil-operation",
-   "Generate DXIL operation information")));
-
+   "Generate DXIL operation information"),
+clEnumValN(GenRISCVTargetDef, "gen-riscv-target-def",
+   "Generate the list of CPU for RISCV")));
 cl::OptionCategory PrintEnumsCat("Options for -print-enums");
 cl::opt Class("class", cl::desc("Print Enum list for this class"),
cl::value_desc("class name"),
@@ -278,6 +280,9 @@
   case GenDXILOperation:
 EmitDXILOperation(Records, OS);
 break;
+  case GenRISCVTargetDef:
+EmitRISCVTargetDef(Records, OS);
+break;
   }
 
   return false;
Index: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
===
--- /dev/null
+++ llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
@@ -0,0 +1,61 @@
+//===- RISCVTargetDefEmitter.cpp - Generate lists of RISCV CPUs ---===//
+//
+// 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 tablegen backend emits the include file needed by the target
+// parser to parse the RISC-V CPUs.
+//
+//===--===//
+
+#include "llvm/TableGen/Record.h"
+
+namespace llvm {
+
+static std::string getEnumFeatures(Record ) {
+  std::vector Features = Rec.getValueAsListOfDefs("Features");
+  if (find_if(Features, [](Record *R) {
+return R->getName() == "Feature64Bit";
+  }) != Features.end())
+return "FK_64BIT";
+
+  return "FK_NONE";
+}
+
+void EmitRISCVTargetDef(const RecordKeeper , raw_ostream ) {
+  const auto  = RK.getDefs();
+
+  OS << "#ifndef PROC\n"
+ << "#define PROC(ENUM, NAME, FEATURES, DEFAULT_MARCH)\n"
+ << "#endif\n\n";
+
+  OS << "PROC(INVALID, {\"invalid\"}, FK_INVALID, {\"\"})\n";
+  // Iterate on all definition records.
+  for (const auto  : Map) {
+const auto *Record = Def.second;
+if (Record->isSubClassOf("RISCVProcessorModelPROC"))
+  OS << "PROC(" << Record->getName() << ", "
+ << "{\"" << Record->getValueAsString("Name") << "\"},"
+ << getEnumFeatures(*Record) << ", "
+ << "{\"" << Record->getValueAsString("DefaultMarch") << "\"})\n";
+  }
+  OS << "\n#undef PROC\n";
+  OS << "\n";
+  OS << "#ifndef TUNE_PROC\n"
+ << "#define TUNE_PROC(ENUM, NAME)\n"
+ << "#endif\n\n";
+  OS << "TUNE_PROC(GENERIC, \"generic\")\n";
+  for (const auto  : Map) {
+const auto *Record = Def.second;
+if (Record->isSubClassOf("RISCVProcessorModelTUNE_PROC"))
+  OS << "TUNE_PROC(" << Record->getName() << ", "

[PATCH] D137517: [TargetParser] Generate the defs for RISCV CPUs using llvm-tblgen.

2022-12-21 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli marked an inline comment as done.
fpetrogalli added inline comments.



Comment at: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:52
+  for (auto  : Map) {
+const auto  = Def.second;
+if (Record->isSubClassOf("RISCVProcessorModelTUNE_PROC"))

barannikov88 wrote:
> Same for the loop above.
```
/Users/fpetrogalli/projects/cpu-defs/upstream/llvm-project/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:38:17:
 error: variable 'Record' with type 'const auto *' has incompatible initializer 
of type 'const std::unique_ptr'
const auto *Record = Def.second;
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137517

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


[PATCH] D137232: [clang][Interp] Support inc/dec operators on pointers

2022-12-21 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik accepted this revision.
shafik added a comment.

LGTM


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

https://reviews.llvm.org/D137232

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


[PATCH] D137517: [TargetParser] Generate the defs for RISCV CPUs using llvm-tblgen.

2022-12-21 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli marked an inline comment as done.
fpetrogalli added inline comments.



Comment at: llvm/lib/TargetParser/CMakeLists.txt:29
+# LLVMTargetParser. See https://stackoverflow.com/a/25681179
+target_include_directories(LLVMTargetParser PUBLIC 
$)

barannikov88 wrote:
> Will it work if RISC-V target is not compiled-in?
> This does not strictly add a cyclic dependency, but it would still be nice to 
> avoid dependency on higher-level components.
> Is it possible / reasonable to extract the part of the RISCV.td that relates 
> to this component and put it separate td file in this directory? Or is it 
> tightly coupled with the rest of the target description?
> 
> Will it work if RISC-V target is not compiled-in?

This line worked, so yes

```
cmake ../llvm-project/llvm -DLLVM_ENABLE_PROJECTS=clang 
-DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -GNinja 
-DLLVM_TARGETS_TO_BUILD="AArch64;AMDGPU;ARM;AVR;BPF;Hexagon;Lanai;Mips;MSP430;NVPTX;PowerPC;Sparc;SystemZ;VE;WebAssembly;X86;XCore"
```


> This does not strictly add a cyclic dependency, but it would still be nice to 
> avoid dependency on higher-level components.
> Is it possible / reasonable to extract the part of the RISCV.td that relates 
> to this component and put it separate td file in this directory? Or is it 
> tightly coupled with the rest of the target description?
> 

Hum - the content of RISCV.td is central in `llvm/lib/Target/RISCV/`. The only 
way I can see we can put a td file in this folder is by duplicating the content 
that we use from `RISCV.td`... That however would mean missing the point of 
this patch though, as the idea is to have centralised unique source of 
information.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137517

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


[PATCH] D137517: [TargetParser] Generate the defs for RISCV CPUs using llvm-tblgen.

2022-12-21 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 added inline comments.



Comment at: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:16
+#include 
+namespace llvm {
+

fpetrogalli wrote:
> barannikov88 wrote:
> > This [[ 
> > https://llvm.org/docs/CodingStandards.html#use-namespace-qualifiers-to-implement-previously-declared-functions
> >  | should be ]] `using namespace llvm;`
> Hum, if I do this, I get:
> 
> ```
> Undefined symbols for architecture arm64:
>   "llvm::EmitRISCVTargetDef(llvm::RecordKeeper&, llvm::raw_ostream&)", 
> referenced from:
>   (anonymous namespace)::LLVMTableGenMain(llvm::raw_ostream&, 
> llvm::RecordKeeper&) in TableGen.cpp.o
> ld: symbol(s) not found for architecture arm64
> ```
> 
> It is a bit surprising because the linking command has 
> `utils/TableGen/CMakeFiles/llvm-tblgen.dir/RISCVTargetDefEmitter.cpp.o` into 
> it... Some of the files in this folder do not use the convention you pointed 
> at, it it OK if I live it as it is?
Right, after `using namespace llvm` you have to write
`llvm::EmitRISCVTargetDef` with explicit `llvm::` qualification. This is the 
whole point of this guideline :)
Please see the [[ 
https://llvm.org/docs/CodingStandards.html#use-namespace-qualifiers-to-implement-previously-declared-functions
 | link ]].



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137517

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


[PATCH] D140315: [AMDGCN] Update search path for device libraries

2022-12-21 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

files under 
clang/test/Driver/Inputs/rocm_resource_dir/lib/amdgcn/bitcode-no-abi-ver seem 
not used.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140315

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


[PATCH] D127812: [AArch64] FMV support and necessary target features dependencies.

2022-12-21 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

In D127812#4011372 , @ilinpv wrote:

> Regular builds works fine for me, pthreads located here 
> "/lib/x86_64-linux-gnu/libpthread.so" 
> "/usr/lib/x86_64-linux-gnu/libpthread.so". Enabling 
> "-DLLVM_USE_SANITIZER=Memory" resulted in many "WARNING: MemorySanitizer: 
> use-of-uninitialized-value" on tblgen like:
>
>   cd /data/ReleasesToCommit/llvm-project/build && 
> /data/ReleasesToCommit/llvm-project/build/bin/llvm-tblgen 
> -gen-intrinsic-enums -intrinsic-prefix=s390 -I 
> /data/ReleasesToCommit/llvm-project/llvm/include/llvm/IR 
> -I/data/ReleasesToCommit/llvm-project/build/include 
> -I/data/ReleasesToCommit/llvm-project/llvm/include 
> /data/ReleasesToCommit/llvm-project/llvm/include/llvm/IR/Intrinsics.td 
> --write-if-changed -o include/llvm/IR/IntrinsicsS390.h -d 
> include/llvm/IR/IntrinsicsS390.h.d
>   [build] ==2441251==WARNING: MemorySanitizer: use-of-uninitialized-value

Yeah that's a false-positive because of bad-ordering. MSan is much tricker 
because it requires an instrumented libcxx. If you can't use the buildscript, 
an MVP for the right ordering should be something like:

1. Build a new clang.

  $ cd /tmp/1/
  $ cmake \
  -DLLVM_ENABLE_PROJECTS="clang;compiler-rt;lld" \
  -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \
  -DCMAKE_C_COMPILER=clang \
  -DCMAKE_CXX_COMPILER=clang++ \
  -GNinja \
  -DCMAKE_BUILD_TYPE=Release \
  -DLLVM_USE_LINKER=lld \
  -DCMAKE_C_FLAGS="-Wall" \
  -DCMAKE_CXX_FLAGS="-Wall" \
  /path/to/llvm/llvm
  $ ninja clang lld compiler-rt llvm-symbolizer



2. Build a sanitizer libcxx.

  $ cd /tmp/2
  $ cmake \
  -DCMAKE_C_COMPILER=/tmp/1/bin/clang \
  -DCMAKE_CXX_COMPILER=/tmp/1/bin/clang++ \
  -GNinja \
  -DLLVM_USE_SANITIZER=Memory \
  -DCMAKE_BUILD_TYPE=Release \
  -DLLVM_ENABLE_ASSERTIONS=ON \
  -DLLVM_ENABLE_RUNTIMES="'libcxx;libcxxabi'" \
  -DLLVM_USE_LINKER="'lld'" \
  /path/to/llvm/runtimes/ # < Make sure this is *runtimes*, not llvm.
  $ ninja cxx cxxabi



3. Build a msan-ified clang, and use the libcxx from step 2.

  $ cd /tmp/3
  $ cat .cmake_script.sh
  #!/bin/bash -e
  
  LDFLAGS="-lc++abi"
  LDFLAGS="$LDFLAGS -Wl,--rpath=/tmp/2/lib" # < use the instrumented libcxx 
from step 2
  LDFLAGS="$LDFLAGS -L/tmp/2/lib"
  
  CFLAGS="$LDFLAGS"
  CFLAGS="$CFLAGS -fsanitize=memory"
  CFLAGS="$CFLAGS -nostdinc++"
  CFLAGS="$CFLAGS -isystem /tmp/2/include" # < use the instrumented libcxx 
from step 2
  CFLAGS="$CFLAGS -isystem /tmp/2/include/c++/v1"
  CFLAGS="$CFLAGS -w"
  CFLAGS="$CFLAGS -fsanitize-memory-use-after-dtor 
-fsanitize-memory-param-retval"
  
  USE_SANITIZER="Memory"
  # USE_SANITIZER="MemoryWithOrigins"  # <---+-- uncomment 
these and comment the USE_SANITIZER="Memory" above to get track-origins.
  # CFLAGS="$CFLAGS -fsanitize-memory-track-origins=2"  # <--+
  
  cmake \
  -DCMAKE_C_COMPILER=/tmp/1/bin/clang \
  -DCMAKE_CXX_COMPILER=/tmp/1/bin/clang++ \
  -DLLVM_ENABLE_LIBCXX=ON \
  -GNinja \
  -DLLVM_USE_SANITIZER="$USE_SANITIZER" \
  -DCMAKE_BUILD_TYPE=Release \
  -DLLVM_ENABLE_ASSERTIONS=ON \
  -DCMAKE_C_FLAGS="$CFLAGS" \
  -DCMAKE_CXX_FLAGS="$CFLAGS" \
  -DCMAKE_EXE_LINKER_FLAGS="$LDFLAGS" \
  -DLLVM_ENABLE_PROJECTS="clang;lld;clang-tools-extra" \
  -DLLVM_USE_LINKER="lld" \
  /path/to/llvm/llvm
  $ . .cmake_script.sh
  $ ninja clang lld
  $ ninja check-clang check-llvm # <- finally, run your tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127812

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


[PATCH] D137517: [TargetParser] Generate the defs for RISCV CPUs using llvm-tblgen.

2022-12-21 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli added inline comments.



Comment at: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:15
+#include "llvm/TableGen/Record.h"
+#include 
+namespace llvm {

barannikov88 wrote:
>  [[ 
> https://llvm.org/docs/CodingStandards.html#include-iostream-is-forbidden | is 
> forbidden ]] by the coding standards.
> 
Ops - that was a leftover for my nasty debugging session :)



Comment at: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:16
+#include 
+namespace llvm {
+

barannikov88 wrote:
> This [[ 
> https://llvm.org/docs/CodingStandards.html#use-namespace-qualifiers-to-implement-previously-declared-functions
>  | should be ]] `using namespace llvm;`
Hum, if I do this, I get:

```
Undefined symbols for architecture arm64:
  "llvm::EmitRISCVTargetDef(llvm::RecordKeeper&, llvm::raw_ostream&)", 
referenced from:
  (anonymous namespace)::LLVMTableGenMain(llvm::raw_ostream&, 
llvm::RecordKeeper&) in TableGen.cpp.o
ld: symbol(s) not found for architecture arm64
```

It is a bit surprising because the linking command has 
`utils/TableGen/CMakeFiles/llvm-tblgen.dir/RISCVTargetDefEmitter.cpp.o` into 
it... Some of the files in this folder do not use the convention you pointed 
at, it it OK if I live it as it is?



Comment at: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:28
+
+void EmitRISCVTargetDef(RecordKeeper , raw_ostream ) {
+  const auto  = RK.getDefs();

barannikov88 wrote:
> This function does not seem to mutate RecordKeeper, so it should be `const`.
Done, however none of the other "emitters" in `TableGenBackends.h` mark the 
record keeper as const...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137517

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


[PATCH] D137517: [TargetParser] Generate the defs for RISCV CPUs using llvm-tblgen.

2022-12-21 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli updated this revision to Diff 484649.
fpetrogalli marked 5 inline comments as done.
fpetrogalli added a comment.

I submitted some of the cleanup suggested by @barannikov88 - thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137517

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  llvm/include/llvm/TargetParser/RISCVTargetParser.def
  llvm/include/llvm/TargetParser/RISCVTargetParser.h
  llvm/include/llvm/TargetParser/TargetParser.h
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVISelLowering.h
  llvm/lib/TargetParser/CMakeLists.txt
  llvm/lib/TargetParser/RISCVTargetParser.cpp
  llvm/lib/TargetParser/TargetParser.cpp
  llvm/utils/TableGen/CMakeLists.txt
  llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
  llvm/utils/TableGen/TableGen.cpp
  llvm/utils/TableGen/TableGenBackends.h

Index: llvm/utils/TableGen/TableGenBackends.h
===
--- llvm/utils/TableGen/TableGenBackends.h
+++ llvm/utils/TableGen/TableGenBackends.h
@@ -94,7 +94,7 @@
 void EmitDirectivesDecl(RecordKeeper , raw_ostream );
 void EmitDirectivesImpl(RecordKeeper , raw_ostream );
 void EmitDXILOperation(RecordKeeper , raw_ostream );
-
+void EmitRISCVTargetDef(const RecordKeeper , raw_ostream );
 } // End llvm namespace
 
 #endif
Index: llvm/utils/TableGen/TableGen.cpp
===
--- llvm/utils/TableGen/TableGen.cpp
+++ llvm/utils/TableGen/TableGen.cpp
@@ -58,6 +58,7 @@
   GenDirectivesEnumDecl,
   GenDirectivesEnumImpl,
   GenDXILOperation,
+  GenRISCVTargetDef,
 };
 
 namespace llvm {
@@ -141,8 +142,9 @@
 clEnumValN(GenDirectivesEnumImpl, "gen-directive-impl",
"Generate directive related implementation code"),
 clEnumValN(GenDXILOperation, "gen-dxil-operation",
-   "Generate DXIL operation information")));
-
+   "Generate DXIL operation information"),
+clEnumValN(GenRISCVTargetDef, "gen-riscv-target-def",
+   "Generate the list of CPU for RISCV")));
 cl::OptionCategory PrintEnumsCat("Options for -print-enums");
 cl::opt Class("class", cl::desc("Print Enum list for this class"),
cl::value_desc("class name"),
@@ -278,6 +280,9 @@
   case GenDXILOperation:
 EmitDXILOperation(Records, OS);
 break;
+  case GenRISCVTargetDef:
+EmitRISCVTargetDef(Records, OS);
+break;
   }
 
   return false;
Index: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
===
--- /dev/null
+++ llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
@@ -0,0 +1,61 @@
+//===- RISCVTargetDefEmitter.cpp - Generate lists of RISCV CPUs ---===//
+//
+// 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 tablegen backend emits the include file needed by the target
+// parser to parse the RISC-V CPUs.
+//
+//===--===//
+
+#include "llvm/TableGen/Record.h"
+
+namespace llvm {
+
+static std::string getEnumFeatures(Record ) {
+  std::vector Features = Rec.getValueAsListOfDefs("Features");
+  if (find_if(Features, [](Record *R) {
+return R->getName() == "Feature64Bit";
+  }) != Features.end())
+return "FK_64BIT";
+
+  return "FK_NONE";
+}
+
+void EmitRISCVTargetDef(const RecordKeeper , raw_ostream ) {
+  const auto  = RK.getDefs();
+
+  OS << "#ifndef PROC\n"
+ << "#define PROC(ENUM, NAME, FEATURES, DEFAULT_MARCH)\n"
+ << "#endif\n\n";
+
+  OS << "PROC(INVALID, {\"invalid\"}, FK_INVALID, {\"\"})\n";
+  // Iterate on all definition records.
+  for (const auto  : Map) {
+const auto  = Def.second;
+if (Record->isSubClassOf("RISCVProcessorModelPROC"))
+  OS << "PROC(" << Record->getName() << ", "
+ << "{\"" << Record->getValueAsString("Name") << "\"},"
+ << getEnumFeatures(*Record) << ", "
+ << "{\"" << Record->getValueAsString("DefaultMarch") << "\"})\n";
+  }
+  OS << "\n#undef PROC\n";
+  OS << "\n";
+  OS << "#ifndef TUNE_PROC\n"
+ << "#define TUNE_PROC(ENUM, NAME)\n"
+ << "#endif\n\n";
+  OS << "TUNE_PROC(GENERIC, \"generic\")\n";
+  for (const auto  : Map) {
+const auto  = Def.second;
+if (Record->isSubClassOf("RISCVProcessorModelTUNE_PROC"))
+  OS << "TUNE_PROC(" << Record->getName() << ", "
+ << "\"" << Record->getValueAsString("Name") << "\")\n";
+  }
+
+  OS << "\n#undef TUNE_PROC\n";
+}
+
+} // namespace llvm
Index: llvm/utils/TableGen/CMakeLists.txt
===
--- 

[PATCH] D138655: [clang-tidy] Fix `cppcoreguidelines-init-variables` for invalid vardecl

2022-12-21 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

In D138655#4007822 , @carlosgalvezp 
wrote:

> Now that I think a bit better about this I wonder - does it really make sense 
> that we increase the complexity of the check to cover for cases where code 
> does not compile? If it fails to include a header, there's many other things 
> that can possibly go wrong - should clang-tidy checks in general really be 
> defensive against that? @njames93 WDYT?

It's not a hard rule that we should be defensive against clang-tidy emitting 
false positives due to a previous compilation error. However for simple cases, 
like this, where its just ensuring a declaration is valid before we try to emit 
diagnostic, It does make sense to handle this.
With this change the main thing would be a little less noise while trying to 
debug the cause of the compilation error which is always a good thing.




Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp:4-13
+// Header file error causes stl container variable to be invalid int vardecl
+#include "unknown.h" 
+// CHECK-MESSAGES: :[[@LINE-1]]:10: error: 'unknown.h' file not found 
[clang-diagnostic-error]
+
+namespace std {
+template 
+struct vector {

All this is unnecessary there is a much nicer way to test this, see below



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp:139-141
+  int a;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variable 'a' is not initialized 
[cppcoreguidelines-init-variables]
+  // CHECK-FIXES: {{^}}  int a = 0;{{$}}

This test line is not testing the behaviour described in this patch and can be 
removed.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp:144
+  // The stl object has been initialized
+  std::vector arr;
+  // CHECK-FIXES-NOT: {{^}}  std::vector arr = 0;{{$}}

Just use this and the declaration will be invalid and you can test the expected 
behaviour


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

https://reviews.llvm.org/D138655

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


[PATCH] D127812: [AArch64] FMV support and necessary target features dependencies.

2022-12-21 Thread Pavel Iliin via Phabricator via cfe-commits
ilinpv added a comment.

In D127812#4010993 , @hctim wrote:

> Hmm, not exactly sure what's going on with the `could NOT find Threads` 
> there. A quick googling seems to point to pthreads.so not being in the right 
> places, but I don't think the buildbot does anything special. Do your regular 
> builds with `-DLLVM_ENABLE_PROJECTS="compiler_rt;clang;lld"` work?
>
> When you say that it looks fine locally, is that from your own checkout but 
> using `-DLLVM_USE_SANITIZER=Memory`? First thing to check is that you do end 
> up with MSan in the test (in particular the clang binary that's being 
> produced), which you can do by `nm bin/clang-16 | grep __msan_init`.

Regular builds works fine for me, pthreads located here 
"/lib/x86_64-linux-gnu/libpthread.so" 
"/usr/lib/x86_64-linux-gnu/libpthread.so". Enabling 
"-DLLVM_USE_SANITIZER=Memory" resulted in many "WARNING: MemorySanitizer: 
use-of-uninitialized-value" on tblgen like:

  cd /data/ReleasesToCommit/llvm-project/build && 
/data/ReleasesToCommit/llvm-project/build/bin/llvm-tblgen -gen-intrinsic-enums 
-intrinsic-prefix=s390 -I 
/data/ReleasesToCommit/llvm-project/llvm/include/llvm/IR 
-I/data/ReleasesToCommit/llvm-project/build/include 
-I/data/ReleasesToCommit/llvm-project/llvm/include 
/data/ReleasesToCommit/llvm-project/llvm/include/llvm/IR/Intrinsics.td 
--write-if-changed -o include/llvm/IR/IntrinsicsS390.h -d 
include/llvm/IR/IntrinsicsS390.h.d
  [build] ==2441251==WARNING: MemorySanitizer: use-of-uninitialized-value


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127812

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


[PATCH] D137838: [Support] Move TargetParsers to new component

2022-12-21 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli added a comment.

In D137838#4010987 , @dblaikie wrote:

> This has introduced a circular dependency due to the forwarding header 
> (forwarding header depends on new lib, new lib depends on support, where the 
> forwarding header is). Generally this wouldn't be acceptable (& I'd suggest 
> the patch be reverted on that basis) though I understand this is a 
> complicated migration - what's the timeline for correcting this issue?

IIUC, the fix here would be to remove the forwarding headers, right?

Francesco


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137838

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


[PATCH] D137107: Allow MS extension: support of constexpr with __declspec(dllimport).

2022-12-21 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:5006
+if (NeedsGlobalCtor || NeedsGlobalDtor)
+  DelayedCXXInitPosition[D] = ~0U;
+  } else {

zahiraam wrote:
> efriedma wrote:
> > zahiraam wrote:
> > > Do you agree this should be done only when one of those flags is on?
> > Yes, that's fine; I wasn't really paying close attention to the exact code. 
> >  Just wanted to make the point about the structure of the if statements, 
> > and code was the easiest way to explain it.
> > 
> > Maybe the outer if statement should actually be `if (isStaticInit(D, 
> > getLangOpts()) && NeedsGlobalCtor) {`.
> > 
> > On a related note, we might want to avoid the name "ctor", in case that 
> > accidentally conflicts with some user code; an "__"-prefixed name would be 
> > appropriate.
> >> Maybe the outer if statement should actually be if (isStaticInit(D, 
> >> getLangOpts()) && NeedsGlobalCtor) {
> Not sure about that! There are cases where (isStaticInit(D, getLangOpts())) = 
> true and NeedsGlobalCtor=false, but NeedsGlobalDtor=true. In which case a 
> __dtor needs to be emitted, no?
> 
> Writing the condition as you are proposing would actually not get me into the 
> body to emit the __dtor. Is that what we want?
EmitCXXGlobalVarDeclInitFunc should be able to handle that case.

Looking again, I'm a little concerned that in the isStaticInit() case, we're 
skipping a bunch of the logic in EmitCXXGlobalVarDeclInitFunc. EmitCXXCtorInit 
handles the basic cases correctly, but there are a lot of special cases in 
EmitCXXGlobalVarDeclInitFunc.


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

https://reviews.llvm.org/D137107

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


[PATCH] D140433: [Clang] Add `nvptx-arch` tool to query installed NVIDIA GPUs

2022-12-21 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 484637.
jhuber6 added a comment.

Print to `stderr` and only return `1` if thre was an actual error. A lack of 
devices is considered a success and we print nothing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140433

Files:
  clang/tools/CMakeLists.txt
  clang/tools/nvptx-arch/CMakeLists.txt
  clang/tools/nvptx-arch/NVPTXArch.cpp

Index: clang/tools/nvptx-arch/NVPTXArch.cpp
===
--- /dev/null
+++ clang/tools/nvptx-arch/NVPTXArch.cpp
@@ -0,0 +1,72 @@
+//===- NVPTXArch.cpp - list installed NVPTX devies --*- 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 implements a tool for detecting name of CUDA gpus installed in the
+// system.
+//
+//===--===//
+
+#if defined(__has_include)
+#if __has_include("cuda.h")
+#include "cuda.h"
+#define CUDA_HEADER_FOUND 1
+#else
+#define CUDA_HEADER_FOUND 0
+#endif
+#else
+#define CUDA_HEADER_FOUND 0
+#endif
+
+#if !CUDA_HEADER_FOUND
+int main() { return 1; }
+#else
+
+#include 
+#include 
+
+static int handleError(CUresult Err) {
+  const char *ErrStr = nullptr;
+  CUresult Result = cuGetErrorString(Err, );
+  if (Result != CUDA_SUCCESS)
+return EXIT_FAILURE;
+  fprintf(stderr, "CUDA error: %s\n", ErrStr);
+  return EXIT_FAILURE;
+}
+
+int main() {
+  if (CUresult Err = cuInit(0)) {
+if (Err == CUDA_ERROR_NO_DEVICE)
+  return EXIT_SUCCESS;
+else
+  return handleError(Err);
+  }
+
+  int Count = 0;
+  if (CUresult Err = cuDeviceGetCount())
+return handleError(Err);
+  if (Count == 0)
+return EXIT_SUCCESS;
+  for (int DeviceId = 0; DeviceId < Count; ++DeviceId) {
+CUdevice Device;
+if (CUresult Err = cuDeviceGet(, DeviceId))
+  return handleError(Err);
+
+int32_t Major, Minor;
+if (CUresult Err = cuDeviceGetAttribute(
+, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, Device))
+  return handleError(Err);
+if (CUresult Err = cuDeviceGetAttribute(
+, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, Device))
+  return handleError(Err);
+
+printf("sm_%d%d\n", Major, Minor);
+  }
+  return EXIT_SUCCESS;
+}
+
+#endif
Index: clang/tools/nvptx-arch/CMakeLists.txt
===
--- /dev/null
+++ clang/tools/nvptx-arch/CMakeLists.txt
@@ -0,0 +1,28 @@
+# //======//
+# //
+# // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# // See https://llvm.org/LICENSE.txt for details.
+# // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+# //
+# //======//
+
+
+# TODO: This is deprecated. Since CMake 3.17 we can use FindCUDAToolkit instead.
+find_package(CUDA QUIET)
+find_library(cuda-library NAMES cuda PATHS /lib64)
+if (NOT cuda-library AND CUDA_FOUND)
+  get_filename_component(CUDA_LIBDIR "${CUDA_cudart_static_LIBRARY}" DIRECTORY)
+  find_library(cuda-library NAMES cuda HINTS "${CUDA_LIBDIR}/stubs")
+endif()
+
+if (NOT CUDA_FOUND OR NOT cuda-library)
+  message(STATUS "Not building nvptx-arch: cuda runtime not found")
+  return()
+endif()
+
+add_clang_tool(nvptx-arch NVPTXArch.cpp)
+
+set_target_properties(nvptx-arch PROPERTIES INSTALL_RPATH_USE_LINK_PATH ON)
+target_include_directories(nvptx-arch PRIVATE ${CUDA_INCLUDE_DIRS})
+
+clang_target_link_libraries(nvptx-arch PRIVATE ${cuda-library})
Index: clang/tools/CMakeLists.txt
===
--- clang/tools/CMakeLists.txt
+++ clang/tools/CMakeLists.txt
@@ -50,3 +50,4 @@
 add_clang_subdirectory(libclang)
 
 add_clang_subdirectory(amdgpu-arch)
+add_clang_subdirectory(nvptx-arch)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140489: Add builtin_elementwise_log

2022-12-21 Thread Joshua Batista via Phabricator via cfe-commits
bob80905 updated this revision to Diff 484633.
bob80905 added a comment.
Herald added subscribers: pcwang-thead, frasercrmck, luismarques, apazos, 
sameer.abuasal, s.egerton, Jim, jocewei, PkmX, the_o, brucehoult, 
MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, niosHD, sabuasal, 
simoncook, johnrusso, rbar, asb.

add both commits


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140489

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  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/aarch64-sve-vector-log-ops.c
  clang/test/Sema/builtins-elementwise-math.c
  clang/test/Sema/riscv-sve-vector-log-ops.c
  clang/test/SemaCXX/builtins-elementwise-math.cpp

Index: clang/test/SemaCXX/builtins-elementwise-math.cpp
===
--- clang/test/SemaCXX/builtins-elementwise-math.cpp
+++ clang/test/SemaCXX/builtins-elementwise-math.cpp
@@ -73,3 +73,10 @@
   static_assert(!is_const::value);
   static_assert(!is_const::value);
 }
+
+void test_builtin_elementwise_log() {
+  const float a = 42.0;
+  float b = 42.3;
+  static_assert(!is_const::value);
+  static_assert(!is_const::value);
+}
Index: clang/test/Sema/riscv-sve-vector-log-ops.c
===
--- /dev/null
+++ clang/test/Sema/riscv-sve-vector-log-ops.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-feature +d \
+// RUN:   -target-feature +v -target-feature +zfh -target-feature +experimental-zvfh \
+// RUN:   -disable-O0-optnone -o - -fsyntax-only %s -verify 
+// REQUIRES: riscv-registered-target
+
+#include 
+
+
+vfloat32mf2_t test_sin_vv_i8mf8(vfloat32mf2_t v) {
+
+  return __builtin_elementwise_sin(v);
+  // expected-error@-1 {{1st argument must be a vector, integer or floating point type}}
+}
Index: clang/test/Sema/builtins-elementwise-math.c
===
--- clang/test/Sema/builtins-elementwise-math.c
+++ clang/test/Sema/builtins-elementwise-math.c
@@ -322,6 +322,27 @@
   // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
 }
 
+void test_builtin_elementwise_log(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
+
+  struct Foo s = __builtin_elementwise_log(f);
+  // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'float'}}
+
+  i = __builtin_elementwise_log();
+  // expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
+
+  i = __builtin_elementwise_log(i);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'int')}}
+
+  i = __builtin_elementwise_log(f, f);
+  // expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
+
+  u = __builtin_elementwise_log(u);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned int')}}
+
+  uv = __builtin_elementwise_log(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);
Index: clang/test/Sema/aarch64-sve-vector-log-ops.c
===
--- /dev/null
+++ clang/test/Sema/aarch64-sve-vector-log-ops.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple aarch64 -target-feature +f -target-feature +d \
+// RUN:   -target-feature +v -target-feature +zfh  -target-feature +sve -target-feature +experimental-zvfh \
+// RUN:   -disable-O0-optnone -o - -fsyntax-only %s -verify 
+// REQUIRES: aarch64-registered-target
+
+#include 
+
+svfloat32_t test_log_vv_i8mf8(svfloat32_t v) {
+
+  return __builtin_elementwise_log(v);
+  // expected-error@-1 {{1st argument must be a vector, integer or floating point type}}
+}
Index: clang/test/CodeGen/builtins-elementwise-math.c
===
--- clang/test/CodeGen/builtins-elementwise-math.c
+++ clang/test/CodeGen/builtins-elementwise-math.c
@@ -365,6 +365,22 @@
   vf2 = __builtin_elementwise_floor(vf1);
 }
 
+void test_builtin_elementwise_log(float f1, float f2, double d1, double d2,
+  float4 vf1, float4 vf2) {
+  // CHECK-LABEL: define void @test_builtin_elementwise_log(
+  // CHECK:  [[F1:%.+]] = load float, ptr %f1.addr, align 4
+  // CHECK-NEXT:  call float @llvm.log.f32(float [[F1]])
+  f2 = __builtin_elementwise_log(f1);
+
+  // CHECK:  [[D1:%.+]] = load double, ptr %d1.addr, align 8
+  // CHECK-NEXT: call double @llvm.log.f64(double [[D1]])
+  d2 = 

[PATCH] D140489: Add builtin_elementwise_log

2022-12-21 Thread Joshua Batista via Phabricator via cfe-commits
bob80905 created this revision.
bob80905 added reviewers: python3kgae, beanz.
Herald added a subscriber: Anastasia.
Herald added a project: All.
bob80905 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add codegen for llvm log elementwise builtin
The log elementwise builtin is necessary for HLSL codegen.
Tests were added to make sure that the expected errors are encountered when 
these functions are given inputs of incompatible types.
The new builtin is restricted to floating point types only.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140489

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -845,6 +845,7 @@
   unsafe floating-point optimizations use ``-funsafe-math-optimizations`` or
   ``-ffast-math`` instead.
 - Add ``__builtin_elementwise_sin`` and ``__builtin_elementwise_cos`` builtins 
for floating point types only.
+- Add ``__builtin_elementwise_log``builtin for floating point types only.
 
 Internal API Changes
 
Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -635,6 +635,7 @@
  T __builtin_elementwise_sin(T x)return the sine of x interpreted 
as an angle in radians  floating point types
  T __builtin_elementwise_cos(T x)return the cosine of x 
interpreted as an angle in radiansfloating point types
  T __builtin_elementwise_floor(T x)  return the largest integral value 
less than or equal to xfloating point types
+ T __builtin_elementwise_log(T x)return the natural logarithm of x 
   floating point types
  T __builtin_elementwise_roundeven(T x)  round x to the nearest integer 
value in floating point format,   floating point types
  rounding halfway cases to even 
(that is, to the nearest value
  that is an even integer), 
regardless of the current rounding


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -845,6 +845,7 @@
   unsafe floating-point optimizations use ``-funsafe-math-optimizations`` or
   ``-ffast-math`` instead.
 - Add ``__builtin_elementwise_sin`` and ``__builtin_elementwise_cos`` builtins for floating point types only.
+- Add ``__builtin_elementwise_log``builtin for floating point types only.
 
 Internal API Changes
 
Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -635,6 +635,7 @@
  T __builtin_elementwise_sin(T x)return the sine of x interpreted as an angle in radians  floating point types
  T __builtin_elementwise_cos(T x)return the cosine of x interpreted as an angle in radiansfloating point types
  T __builtin_elementwise_floor(T x)  return the largest integral value less than or equal to xfloating point types
+ T __builtin_elementwise_log(T x)return the natural logarithm of xfloating point types
  T __builtin_elementwise_roundeven(T x)  round x to the nearest integer value in floating point format,   floating point types
  rounding halfway cases to even (that is, to the nearest value
  that is an even integer), regardless of the current rounding
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 6c3a290 - Headers: further refine the `stdatomic.h` MSVC inclusion

2022-12-21 Thread Saleem Abdulrasool via cfe-commits

Author: Saleem Abdulrasool
Date: 2022-12-21T19:09:10Z
New Revision: 6c3a2902f1f8d102aa5b3cd37def4f1420ac0c80

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

LOG: Headers: further refine the `stdatomic.h` MSVC inclusion

The `stdatomic.h` header cannot be included under MSVC when in C++ mode
as the toolsets prior to 17.5.0 Preview 2 do not support the C11
atomics.  However, some toolsets prior to the aforementioned version
support the atomics under the C++ mode.  In these versions the MSVC
toolset protects against the contamination by entirely eliding the
declarations, resulting in build failures in some cases.  Unfortunately,
e0c3142af075e2ef89395dbed5939071345eb622 accidentally regressed the C
case when fixing the C++ support.

Unfortunately, we cannot test this reliably as we need to inject a
header after the resource path as a system header path, which we do not
have a reliable means of doing.

Fixes: #59640

Added: 


Modified: 
clang/lib/Headers/stdatomic.h

Removed: 




diff  --git a/clang/lib/Headers/stdatomic.h b/clang/lib/Headers/stdatomic.h
index 9093851b76cfc..0f893beea6ca2 100644
--- a/clang/lib/Headers/stdatomic.h
+++ b/clang/lib/Headers/stdatomic.h
@@ -20,7 +20,7 @@
  */
 #if __STDC_HOSTED__ && 
\
 __has_include_next() &&   
\
-!(defined(_MSC_VER) && defined(__cplusplus) && __cplusplus < 202002L)
+(!defined(_MSC_VER) || (defined(__cplusplus) && __cplusplus >= 202002L))
 # include_next 
 #else
 



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


[PATCH] D115232: [clangd] Indexing of standard library

2022-12-21 Thread Ben Barham via Phabricator via cfe-commits
bnbarham added inline comments.



Comment at: clang-tools-extra/clangd/ClangdServer.cpp:1008-1010
+  // TUScheduler is the only thing that starts background indexing work.
+  if (IndexTasks && !IndexTasks->wait(timeoutSeconds(TimeoutSeconds)))
+return false;

sammccall wrote:
> bnbarham wrote:
> > sammccall wrote:
> > > bnbarham wrote:
> > > > @sammccall shouldn't we also be waiting for this to finish when 
> > > > `ClangdServer` is destroyed? IIUC right now the both `FileIndex` itself 
> > > > (stored in `ClangdServer`) and the actual `UpdateIndexCallbacks` 
> > > > (stored in `TUScheduler`) can be freed while `indexStdlib` is running 
> > > > asynchronously, resulting in a use-after-free on eg. 
> > > > `FIndex->updatePreamble(std::move(IF))`. I was confused as to why this 
> > > > wasn't happening in the tests, but these lines would explain it  
> > > > 
> > > > Adding a `IndexTasks->wait()` to `~ClangdServer` fixes the crash I'm 
> > > > seeing in the sourcekit-lsp tests (see 
> > > > https://github.com/apple/llvm-project/pull/5837), though ideally we 
> > > > (sourcekit-lsp) wouldn't be running any indexing at all. As far as I 
> > > > can tell there's no way to turn off dynamic indexing now though, except 
> > > > for `StandardLibrary` indexing through the config file (but not from 
> > > > clangd args)?
> > > Thanks for flagging this!
> > > 
> > > We *almost* have the sequencing we need in ~ClangdServer:
> > >  - when we fall off the end of ~ClangdServer it destroys all its members
> > >  - `ClangdServer::IndexTasks` is declared after `FIndex`, so is destroyed 
> > > first
> > >  - ~AsyncTaskRunner calls `wait()`
> > > 
> > > But the task we schedule on `IndexTasks` captures a ref to 
> > > `UpdateIndexCallbacks`, which is owned by the `TUScheduler`, which we 
> > > explicitly destroy at the beginning of `~ClangdServer`.
> > > 
> > > However I think your patch is *also* not quite correct: we can wait for 
> > > the tasks to be empty, but then the TUScheduler could fill it up again 
> > > before we destroy TUScheduler.
> > > 
> > > Options include adding an explicit stop() to TUScheduler, changing 
> > > TUScheduler to not (exclusively) own UpdateIndexCallbacks, or have the 
> > > task not capture the callbacks by reference.
> > > I'll try the latter first, which seems least invasive.
> > > 
> > > ---
> > > 
> > > > ideally we (sourcekit-lsp) wouldn't be running any indexing at all. As 
> > > > far as I can tell there's no way to turn off dynamic indexing now 
> > > > though, except for StandardLibrary indexing through the config file 
> > > > (but not from clangd args)?
> > > 
> > > Clangd won't provide any top-level/namespace-level completions at all 
> > > without dynamic index (index of preambles), and various other features 
> > > won't work (docs on hover, include-fixer, type/call-hierarchy). We 
> > > dropped support for disabling this at some point, as it didn't really 
> > > seem usable and made features more complex if we tried to accommodate it. 
> > > At a technical level it would be possible to disable I think, but I'd be 
> > > really surprised if completion worked well, or if a language server 
> > > without completion was useful.
> > > 
> > > > `StandardLibrary` indexing through the config file (but not from clangd 
> > > > args)
> > > 
> > > We've tried to move away from flags for options that are interesting to 
> > > users, as config files are more flexible, more forgiving on errors, and 
> > > allow different settings per-project in a consistent way. (We don't own 
> > > the editors, so cross-editor consistency is important to being able to 
> > > support users at all...)
> > > 
> > > I can see how requiring config to be materialized on disk could be 
> > > inconvenient for IDEs though. I think we could add a general-purpose 
> > > `--config-inline=` flag, and/or the ability to set 
> > > config over LSP (this can be dynamic, accordingly bigger design space 
> > > that might be hard to get right).
> > Ah, I didn't actually check `AsyncTaskRunner`. Makes sense it would wait 
> > though :). Thanks for looking into this in detail!
> > 
> > > or have the task not capture the callbacks by reference. I'll try the 
> > > latter first, which seems least invasive.
> > 
> > This + moving `FIndex` after `IndexTasks` seems reasonable to me.
> > 
> > > Clangd won't provide any top-level/namespace-level completions at all 
> > > without dynamic index (index of preambles), and various other features 
> > > won't work (docs on hover, include-fixer, type/call-hierarchy).
> > 
> > That's good to know - I assume this extends to indexing the stdlib as well, 
> > ie. the stdlib would be missing from top/namespace level completion if not 
> > indexed? Does the dynamic index grow with every opened file, or is it just 
> > the currently opened file? If disabling breaks everything it's not 
> > something we'd want to do, we just don't need it for find refs/etc.
> > 

[PATCH] D140432: [AArch64] Guard {vmull_p64, vmull_high_p64} with 'aes' target guard.

2022-12-21 Thread Mingming Liu 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 rGc847e22db33e: [AArch64] Guard {vmull_p64, vmull_high_p64} 
with aes target guard. (authored by mingmingl).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140432

Files:
  clang/include/clang/Basic/arm_neon.td
  clang/test/CodeGen/aarch64-poly128.c
  clang/test/Sema/aarch64-neon-target.c

Index: clang/test/Sema/aarch64-neon-target.c
===
--- clang/test/Sema/aarch64-neon-target.c
+++ clang/test/Sema/aarch64-neon-target.c
@@ -60,7 +60,7 @@
   vrnd32xq_f32(v4f32);
 }
 
-void undefined(uint32x2_t v2i32, uint32x4_t v4i32, uint16x8_t v8i16, uint8x16_t v16i8, uint8x8_t v8i8, float32x2_t v2f32, float32x4_t v4f32, float16x4_t v4f16, float64x2_t v2f64, bfloat16x4_t v4bf16, __bf16 bf16) {
+void undefined(uint32x2_t v2i32, uint32x4_t v4i32, uint16x8_t v8i16, uint8x16_t v16i8, uint8x8_t v8i8, float32x2_t v2f32, float32x4_t v4f32, float16x4_t v4f16, float64x2_t v2f64, bfloat16x4_t v4bf16, __bf16 bf16, poly64_t poly64, poly64x2_t poly64x2) {
   // dotprod
   vdot_u32(v2i32, v8i8, v8i8); // expected-error {{always_inline function 'vdot_u32' requires target feature 'dotprod'}}
   vdot_laneq_u32(v2i32, v8i8, v16i8, 1); // expected-error {{always_inline function 'vdot_u32' requires target feature 'dotprod'}}
@@ -92,4 +92,8 @@
   vcmlaq_rot270_laneq_f64(v2f64, v2f64, v2f64, 1); // expected-error {{always_inline function 'vcmlaq_rot270_f64' requires target feature 'v8.3a'}}
   // 8.5 - frint
   vrnd32xq_f32(v4f32); // expected-error {{always_inline function 'vrnd32xq_f32' requires target feature 'v8.5a'}}
+
+  vmull_p64(poly64, poly64);  // expected-error {{always_inline function 'vmull_p64' requires target feature 'aes'}}
+  vmull_high_p64(poly64x2, poly64x2);  // expected-error {{always_inline function 'vmull_high_p64' requires target feature 'aes'}}
+
 }
Index: clang/test/CodeGen/aarch64-poly128.c
===
--- clang/test/CodeGen/aarch64-poly128.c
+++ clang/test/CodeGen/aarch64-poly128.c
@@ -28,8 +28,8 @@
 // CHECK-LABEL: define {{[^@]+}}@test_vldrq_p128
 // CHECK-SAME: (ptr noundef [[PTR:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP2:%.*]] = load i128, ptr [[PTR]], align 16
-// CHECK-NEXT:ret i128 [[TMP2]]
+// CHECK-NEXT:[[TMP0:%.*]] = load i128, ptr [[PTR]], align 16
+// CHECK-NEXT:ret i128 [[TMP0]]
 //
 poly128_t test_vldrq_p128(poly128_t * ptr) {
   return vldrq_p128(ptr);
@@ -39,9 +39,9 @@
 // CHECK-LABEL: define {{[^@]+}}@test_ld_st_p128
 // CHECK-SAME: (ptr noundef [[PTR:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP2:%.*]] = load i128, ptr [[PTR]], align 16
+// CHECK-NEXT:[[TMP0:%.*]] = load i128, ptr [[PTR]], align 16
 // CHECK-NEXT:[[ADD_PTR:%.*]] = getelementptr inbounds i128, ptr [[PTR]], i64 1
-// CHECK-NEXT:store i128 [[TMP2]], ptr [[ADD_PTR]], align 16
+// CHECK-NEXT:store i128 [[TMP0]], ptr [[ADD_PTR]], align 16
 // CHECK-NEXT:ret void
 //
 void test_ld_st_p128(poly128_t * ptr) {
@@ -50,18 +50,18 @@
 }
 
 // CHECK-LABEL: define {{[^@]+}}@test_vmull_p64
-// CHECK-SAME: (i64 noundef [[A:%.*]], i64 noundef [[B:%.*]]) #[[ATTR0]] {
+// CHECK-SAME: (i64 noundef [[A:%.*]], i64 noundef [[B:%.*]]) #[[ATTR1:[0-9]+]] {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[VMULL_P64_I:%.*]] = call <16 x i8> @llvm.aarch64.neon.pmull64(i64 [[A]], i64 [[B]])
 // CHECK-NEXT:[[VMULL_P641_I:%.*]] = bitcast <16 x i8> [[VMULL_P64_I]] to i128
 // CHECK-NEXT:ret i128 [[VMULL_P641_I]]
 //
-poly128_t test_vmull_p64(poly64_t a, poly64_t b) {
+__attribute__((target("aes"))) poly128_t test_vmull_p64(poly64_t a, poly64_t b) {
   return vmull_p64(a, b);
 }
 
 // CHECK-LABEL: define {{[^@]+}}@test_vmull_high_p64
-// CHECK-SAME: (<2 x i64> noundef [[A:%.*]], <2 x i64> noundef [[B:%.*]]) #[[ATTR1:[0-9]+]] {
+// CHECK-SAME: (<2 x i64> noundef [[A:%.*]], <2 x i64> noundef [[B:%.*]]) #[[ATTR2:[0-9]+]] {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[SHUFFLE_I5:%.*]] = shufflevector <2 x i64> [[A]], <2 x i64> [[A]], <1 x i32> 
 // CHECK-NEXT:[[TMP0:%.*]] = bitcast <1 x i64> [[SHUFFLE_I5]] to i64
@@ -71,12 +71,12 @@
 // CHECK-NEXT:[[VMULL_P641_I_I:%.*]] = bitcast <16 x i8> [[VMULL_P64_I_I]] to i128
 // CHECK-NEXT:ret i128 [[VMULL_P641_I_I]]
 //
-poly128_t test_vmull_high_p64(poly64x2_t a, poly64x2_t b) {
+__attribute__((target("aes"))) poly128_t test_vmull_high_p64(poly64x2_t a, poly64x2_t b) {
   return vmull_high_p64(a, b);
 }
 
 // CHECK-LABEL: define {{[^@]+}}@test_vreinterpretq_p128_s8
-// CHECK-SAME: (<16 x i8> noundef [[A:%.*]]) #[[ATTR1]] {
+// CHECK-SAME: (<16 x i8> noundef [[A:%.*]]) #[[ATTR3:[0-9]+]] {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = bitcast <16 x i8> [[A]] to i128
 // 

[clang] c847e22 - [AArch64] Guard {vmull_p64, vmull_high_p64} with 'aes' target guard.

2022-12-21 Thread Mingming Liu via cfe-commits

Author: Mingming Liu
Date: 2022-12-21T11:02:27-08:00
New Revision: c847e22db33e4625b1ad58b631f57d7d1e1944ca

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

LOG: [AArch64] Guard {vmull_p64, vmull_high_p64} with 'aes' target guard.

The 'aes' target guard includes both FEAT_AES and FEAT_PMULL currently.

In this way, cpp code that uses these intrinsics without specifying the 
required extension gets better hint.
- Before, compile crashes with LLVM ISel internal message (see issue [[ 
https://github.com/llvm/llvm-project/issues/59599 | 59599 ]]).
- After, clang hints that target 'aes' is required in the command.

Reviewed By: dmgreen

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

Added: 


Modified: 
clang/include/clang/Basic/arm_neon.td
clang/test/CodeGen/aarch64-poly128.c
clang/test/Sema/aarch64-neon-target.c

Removed: 




diff  --git a/clang/include/clang/Basic/arm_neon.td 
b/clang/include/clang/Basic/arm_neon.td
index 4288e9eb69d07..94dfe80acc358 100644
--- a/clang/include/clang/Basic/arm_neon.td
+++ b/clang/include/clang/Basic/arm_neon.td
@@ -957,8 +957,10 @@ def VQDMLAL_HIGH : SOpInst<"vqdmlal_high", "(>Q)(>Q)QQ", 
"si", OP_QDMLALHi>;
 def VQDMLAL_HIGH_N : SOpInst<"vqdmlal_high_n", "(>Q)(>Q)Q1", "si", 
OP_QDMLALHi_N>;
 def VQDMLSL_HIGH : SOpInst<"vqdmlsl_high", "(>Q)(>Q)QQ", "si", OP_QDMLSLHi>;
 def VQDMLSL_HIGH_N : SOpInst<"vqdmlsl_high_n", "(>Q)(>Q)Q1", "si", 
OP_QDMLSLHi_N>;
-def VMULL_P64: SInst<"vmull", "(1>)11", "Pl">;
-def VMULL_HIGH_P64 : SOpInst<"vmull_high", "(1>)..", "HPl", OP_MULLHi_P64>;
+let TargetGuard = "aes" in {
+  def VMULL_P64: SInst<"vmull", "(1>)11", "Pl">;
+  def VMULL_HIGH_P64 : SOpInst<"vmull_high", "(1>)..", "HPl", OP_MULLHi_P64>;
+}
 
 
 


diff  --git a/clang/test/CodeGen/aarch64-poly128.c 
b/clang/test/CodeGen/aarch64-poly128.c
index d73390c7f6aa1..f188632468fc8 100644
--- a/clang/test/CodeGen/aarch64-poly128.c
+++ b/clang/test/CodeGen/aarch64-poly128.c
@@ -28,8 +28,8 @@ void test_vstrq_p128(poly128_t * ptr, poly128_t val) {
 // CHECK-LABEL: define {{[^@]+}}@test_vldrq_p128
 // CHECK-SAME: (ptr noundef [[PTR:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP2:%.*]] = load i128, ptr [[PTR]], align 16
-// CHECK-NEXT:ret i128 [[TMP2]]
+// CHECK-NEXT:[[TMP0:%.*]] = load i128, ptr [[PTR]], align 16
+// CHECK-NEXT:ret i128 [[TMP0]]
 //
 poly128_t test_vldrq_p128(poly128_t * ptr) {
   return vldrq_p128(ptr);
@@ -39,9 +39,9 @@ poly128_t test_vldrq_p128(poly128_t * ptr) {
 // CHECK-LABEL: define {{[^@]+}}@test_ld_st_p128
 // CHECK-SAME: (ptr noundef [[PTR:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP2:%.*]] = load i128, ptr [[PTR]], align 16
+// CHECK-NEXT:[[TMP0:%.*]] = load i128, ptr [[PTR]], align 16
 // CHECK-NEXT:[[ADD_PTR:%.*]] = getelementptr inbounds i128, ptr [[PTR]], 
i64 1
-// CHECK-NEXT:store i128 [[TMP2]], ptr [[ADD_PTR]], align 16
+// CHECK-NEXT:store i128 [[TMP0]], ptr [[ADD_PTR]], align 16
 // CHECK-NEXT:ret void
 //
 void test_ld_st_p128(poly128_t * ptr) {
@@ -50,18 +50,18 @@ void test_ld_st_p128(poly128_t * ptr) {
 }
 
 // CHECK-LABEL: define {{[^@]+}}@test_vmull_p64
-// CHECK-SAME: (i64 noundef [[A:%.*]], i64 noundef [[B:%.*]]) #[[ATTR0]] {
+// CHECK-SAME: (i64 noundef [[A:%.*]], i64 noundef [[B:%.*]]) 
#[[ATTR1:[0-9]+]] {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[VMULL_P64_I:%.*]] = call <16 x i8> 
@llvm.aarch64.neon.pmull64(i64 [[A]], i64 [[B]])
 // CHECK-NEXT:[[VMULL_P641_I:%.*]] = bitcast <16 x i8> [[VMULL_P64_I]] to 
i128
 // CHECK-NEXT:ret i128 [[VMULL_P641_I]]
 //
-poly128_t test_vmull_p64(poly64_t a, poly64_t b) {
+__attribute__((target("aes"))) poly128_t test_vmull_p64(poly64_t a, poly64_t 
b) {
   return vmull_p64(a, b);
 }
 
 // CHECK-LABEL: define {{[^@]+}}@test_vmull_high_p64
-// CHECK-SAME: (<2 x i64> noundef [[A:%.*]], <2 x i64> noundef [[B:%.*]]) 
#[[ATTR1:[0-9]+]] {
+// CHECK-SAME: (<2 x i64> noundef [[A:%.*]], <2 x i64> noundef [[B:%.*]]) 
#[[ATTR2:[0-9]+]] {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[SHUFFLE_I5:%.*]] = shufflevector <2 x i64> [[A]], <2 x 
i64> [[A]], <1 x i32> 
 // CHECK-NEXT:[[TMP0:%.*]] = bitcast <1 x i64> [[SHUFFLE_I5]] to i64
@@ -71,12 +71,12 @@ poly128_t test_vmull_p64(poly64_t a, poly64_t b) {
 // CHECK-NEXT:[[VMULL_P641_I_I:%.*]] = bitcast <16 x i8> [[VMULL_P64_I_I]] 
to i128
 // CHECK-NEXT:ret i128 [[VMULL_P641_I_I]]
 //
-poly128_t test_vmull_high_p64(poly64x2_t a, poly64x2_t b) {
+__attribute__((target("aes"))) poly128_t test_vmull_high_p64(poly64x2_t a, 
poly64x2_t b) {
   return vmull_high_p64(a, b);
 }
 
 // CHECK-LABEL: define {{[^@]+}}@test_vreinterpretq_p128_s8
-// CHECK-SAME: (<16 

[PATCH] D115232: [clangd] Indexing of standard library

2022-12-21 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/ClangdServer.cpp:1008-1010
+  // TUScheduler is the only thing that starts background indexing work.
+  if (IndexTasks && !IndexTasks->wait(timeoutSeconds(TimeoutSeconds)))
+return false;

bnbarham wrote:
> sammccall wrote:
> > bnbarham wrote:
> > > @sammccall shouldn't we also be waiting for this to finish when 
> > > `ClangdServer` is destroyed? IIUC right now the both `FileIndex` itself 
> > > (stored in `ClangdServer`) and the actual `UpdateIndexCallbacks` (stored 
> > > in `TUScheduler`) can be freed while `indexStdlib` is running 
> > > asynchronously, resulting in a use-after-free on eg. 
> > > `FIndex->updatePreamble(std::move(IF))`. I was confused as to why this 
> > > wasn't happening in the tests, but these lines would explain it  
> > > 
> > > Adding a `IndexTasks->wait()` to `~ClangdServer` fixes the crash I'm 
> > > seeing in the sourcekit-lsp tests (see 
> > > https://github.com/apple/llvm-project/pull/5837), though ideally we 
> > > (sourcekit-lsp) wouldn't be running any indexing at all. As far as I can 
> > > tell there's no way to turn off dynamic indexing now though, except for 
> > > `StandardLibrary` indexing through the config file (but not from clangd 
> > > args)?
> > Thanks for flagging this!
> > 
> > We *almost* have the sequencing we need in ~ClangdServer:
> >  - when we fall off the end of ~ClangdServer it destroys all its members
> >  - `ClangdServer::IndexTasks` is declared after `FIndex`, so is destroyed 
> > first
> >  - ~AsyncTaskRunner calls `wait()`
> > 
> > But the task we schedule on `IndexTasks` captures a ref to 
> > `UpdateIndexCallbacks`, which is owned by the `TUScheduler`, which we 
> > explicitly destroy at the beginning of `~ClangdServer`.
> > 
> > However I think your patch is *also* not quite correct: we can wait for the 
> > tasks to be empty, but then the TUScheduler could fill it up again before 
> > we destroy TUScheduler.
> > 
> > Options include adding an explicit stop() to TUScheduler, changing 
> > TUScheduler to not (exclusively) own UpdateIndexCallbacks, or have the task 
> > not capture the callbacks by reference.
> > I'll try the latter first, which seems least invasive.
> > 
> > ---
> > 
> > > ideally we (sourcekit-lsp) wouldn't be running any indexing at all. As 
> > > far as I can tell there's no way to turn off dynamic indexing now though, 
> > > except for StandardLibrary indexing through the config file (but not from 
> > > clangd args)?
> > 
> > Clangd won't provide any top-level/namespace-level completions at all 
> > without dynamic index (index of preambles), and various other features 
> > won't work (docs on hover, include-fixer, type/call-hierarchy). We dropped 
> > support for disabling this at some point, as it didn't really seem usable 
> > and made features more complex if we tried to accommodate it. At a 
> > technical level it would be possible to disable I think, but I'd be really 
> > surprised if completion worked well, or if a language server without 
> > completion was useful.
> > 
> > > `StandardLibrary` indexing through the config file (but not from clangd 
> > > args)
> > 
> > We've tried to move away from flags for options that are interesting to 
> > users, as config files are more flexible, more forgiving on errors, and 
> > allow different settings per-project in a consistent way. (We don't own the 
> > editors, so cross-editor consistency is important to being able to support 
> > users at all...)
> > 
> > I can see how requiring config to be materialized on disk could be 
> > inconvenient for IDEs though. I think we could add a general-purpose 
> > `--config-inline=` flag, and/or the ability to set 
> > config over LSP (this can be dynamic, accordingly bigger design space that 
> > might be hard to get right).
> Ah, I didn't actually check `AsyncTaskRunner`. Makes sense it would wait 
> though :). Thanks for looking into this in detail!
> 
> > or have the task not capture the callbacks by reference. I'll try the 
> > latter first, which seems least invasive.
> 
> This + moving `FIndex` after `IndexTasks` seems reasonable to me.
> 
> > Clangd won't provide any top-level/namespace-level completions at all 
> > without dynamic index (index of preambles), and various other features 
> > won't work (docs on hover, include-fixer, type/call-hierarchy).
> 
> That's good to know - I assume this extends to indexing the stdlib as well, 
> ie. the stdlib would be missing from top/namespace level completion if not 
> indexed? Does the dynamic index grow with every opened file, or is it just 
> the currently opened file? If disabling breaks everything it's not something 
> we'd want to do, we just don't need it for find refs/etc.
> This + moving FIndex after IndexTasks seems reasonable to me.

I sent D140486. FIndex should be **before** IndexTasks in order to outlive it, 
unless I'm missing something.

> I assume this 

[PATCH] D140433: [Clang] Add `nvptx-arch` tool to query installed NVIDIA GPUs

2022-12-21 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/tools/nvptx-arch/NVPTXArch.cpp:37
+return 1;
+  printf("CUDA error: %s\n", ErrStr);
+  return 1;

stderr?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140433

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


[PATCH] D139261: [Clang] Modify sanity check assert in AggExprEmitter::VisitInitListExpr to cover anonymous struct in a union GNU extension

2022-12-21 Thread Shafik Yaghmour 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 rG475cc44a2cba: [Clang] Modify sanity check assert in 
AggExprEmitter::VisitInitListExpr to… (authored by shafik).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139261

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/test/SemaCXX/anonymous-struct.cpp


Index: clang/test/SemaCXX/anonymous-struct.cpp
===
--- clang/test/SemaCXX/anonymous-struct.cpp
+++ clang/test/SemaCXX/anonymous-struct.cpp
@@ -189,3 +189,20 @@
   }
 } A; // expected-note {{given name 'A' for linkage purposes by this typedef}}
 }
+
+#if __cplusplus > 201103L
+namespace GH58800 {
+struct A {
+  union {
+struct {
+  float red = 0.0f;
+};
+  };
+};
+
+A GetA() {
+  A result{};
+  return result;
+}
+}
+#endif
Index: clang/lib/CodeGen/CGExprAgg.cpp
===
--- clang/lib/CodeGen/CGExprAgg.cpp
+++ clang/lib/CodeGen/CGExprAgg.cpp
@@ -1724,7 +1724,7 @@
   // Make sure that it's really an empty and not a failure of
   // semantic analysis.
   for (const auto *Field : record->fields())
-assert(Field->isUnnamedBitfield() && "Only unnamed bitfields allowed");
+assert((Field->isUnnamedBitfield() || 
Field->isAnonymousStructOrUnion()) && "Only unnamed bitfields or ananymous 
class allowed");
 #endif
   return;
 }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -326,6 +326,9 @@
 - Fix bug where constant evaluation treated a pointer to member that points to
   a weak member as never being null. Such comparisons are now treated as
   non-constant.
+- Fix sanity check when value initializing an empty union so that it takes into
+  account anonymous structs which is a GNU extension. This fixes
+  `Issue 58800 `_
 
 Improvements to Clang's diagnostics
 ^^^


Index: clang/test/SemaCXX/anonymous-struct.cpp
===
--- clang/test/SemaCXX/anonymous-struct.cpp
+++ clang/test/SemaCXX/anonymous-struct.cpp
@@ -189,3 +189,20 @@
   }
 } A; // expected-note {{given name 'A' for linkage purposes by this typedef}}
 }
+
+#if __cplusplus > 201103L
+namespace GH58800 {
+struct A {
+  union {
+struct {
+  float red = 0.0f;
+};
+  };
+};
+
+A GetA() {
+  A result{};
+  return result;
+}
+}
+#endif
Index: clang/lib/CodeGen/CGExprAgg.cpp
===
--- clang/lib/CodeGen/CGExprAgg.cpp
+++ clang/lib/CodeGen/CGExprAgg.cpp
@@ -1724,7 +1724,7 @@
   // Make sure that it's really an empty and not a failure of
   // semantic analysis.
   for (const auto *Field : record->fields())
-assert(Field->isUnnamedBitfield() && "Only unnamed bitfields allowed");
+assert((Field->isUnnamedBitfield() || Field->isAnonymousStructOrUnion()) && "Only unnamed bitfields or ananymous class allowed");
 #endif
   return;
 }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -326,6 +326,9 @@
 - Fix bug where constant evaluation treated a pointer to member that points to
   a weak member as never being null. Such comparisons are now treated as
   non-constant.
+- Fix sanity check when value initializing an empty union so that it takes into
+  account anonymous structs which is a GNU extension. This fixes
+  `Issue 58800 `_
 
 Improvements to Clang's diagnostics
 ^^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 475cc44 - [Clang] Modify sanity check assert in AggExprEmitter::VisitInitListExpr to cover anonymous struct in a union GNU extension

2022-12-21 Thread Shafik Yaghmour via cfe-commits

Author: Shafik Yaghmour
Date: 2022-12-21T10:50:05-08:00
New Revision: 475cc44a2cba45c5449a323c6b331ddc593bd8de

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

LOG: [Clang] Modify sanity check assert in AggExprEmitter::VisitInitListExpr to 
cover anonymous struct in a union GNU extension

AggExprEmitter::VisitInitListExpr sanity checks that an empty union is really
empty and not a semantic analysis failure. The assert is missing that we allow
anonymous structs as a GNU extension. I have updated the assert to take that 
into account.

This fixes: https://github.com/llvm/llvm-project/issues/58800

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/CodeGen/CGExprAgg.cpp
clang/test/SemaCXX/anonymous-struct.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 09705a6b5b571..4ba28f5df5dc1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -326,6 +326,9 @@ Bug Fixes
 - Fix bug where constant evaluation treated a pointer to member that points to
   a weak member as never being null. Such comparisons are now treated as
   non-constant.
+- Fix sanity check when value initializing an empty union so that it takes into
+  account anonymous structs which is a GNU extension. This fixes
+  `Issue 58800 `_
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index 8ba21f8fc0046..303bcc89f671c 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -1724,7 +1724,7 @@ void AggExprEmitter::VisitCXXParenListOrInitListExpr(
   // Make sure that it's really an empty and not a failure of
   // semantic analysis.
   for (const auto *Field : record->fields())
-assert(Field->isUnnamedBitfield() && "Only unnamed bitfields allowed");
+assert((Field->isUnnamedBitfield() || 
Field->isAnonymousStructOrUnion()) && "Only unnamed bitfields or ananymous 
class allowed");
 #endif
   return;
 }

diff  --git a/clang/test/SemaCXX/anonymous-struct.cpp 
b/clang/test/SemaCXX/anonymous-struct.cpp
index 7cf05ee3c49ae..e46bdc28d5059 100644
--- a/clang/test/SemaCXX/anonymous-struct.cpp
+++ b/clang/test/SemaCXX/anonymous-struct.cpp
@@ -189,3 +189,20 @@ typedef struct { // expected-warning {{anonymous 
non-C-compatible type}}
   }
 } A; // expected-note {{given name 'A' for linkage purposes by this typedef}}
 }
+
+#if __cplusplus > 201103L
+namespace GH58800 {
+struct A {
+  union {
+struct {
+  float red = 0.0f;
+};
+  };
+};
+
+A GetA() {
+  A result{};
+  return result;
+}
+}
+#endif



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


[PATCH] D115232: [clangd] Indexing of standard library

2022-12-21 Thread Ben Barham via Phabricator via cfe-commits
bnbarham added inline comments.



Comment at: clang-tools-extra/clangd/ClangdServer.cpp:1008-1010
+  // TUScheduler is the only thing that starts background indexing work.
+  if (IndexTasks && !IndexTasks->wait(timeoutSeconds(TimeoutSeconds)))
+return false;

sammccall wrote:
> bnbarham wrote:
> > @sammccall shouldn't we also be waiting for this to finish when 
> > `ClangdServer` is destroyed? IIUC right now the both `FileIndex` itself 
> > (stored in `ClangdServer`) and the actual `UpdateIndexCallbacks` (stored in 
> > `TUScheduler`) can be freed while `indexStdlib` is running asynchronously, 
> > resulting in a use-after-free on eg. 
> > `FIndex->updatePreamble(std::move(IF))`. I was confused as to why this 
> > wasn't happening in the tests, but these lines would explain it  
> > 
> > Adding a `IndexTasks->wait()` to `~ClangdServer` fixes the crash I'm seeing 
> > in the sourcekit-lsp tests (see 
> > https://github.com/apple/llvm-project/pull/5837), though ideally we 
> > (sourcekit-lsp) wouldn't be running any indexing at all. As far as I can 
> > tell there's no way to turn off dynamic indexing now though, except for 
> > `StandardLibrary` indexing through the config file (but not from clangd 
> > args)?
> Thanks for flagging this!
> 
> We *almost* have the sequencing we need in ~ClangdServer:
>  - when we fall off the end of ~ClangdServer it destroys all its members
>  - `ClangdServer::IndexTasks` is declared after `FIndex`, so is destroyed 
> first
>  - ~AsyncTaskRunner calls `wait()`
> 
> But the task we schedule on `IndexTasks` captures a ref to 
> `UpdateIndexCallbacks`, which is owned by the `TUScheduler`, which we 
> explicitly destroy at the beginning of `~ClangdServer`.
> 
> However I think your patch is *also* not quite correct: we can wait for the 
> tasks to be empty, but then the TUScheduler could fill it up again before we 
> destroy TUScheduler.
> 
> Options include adding an explicit stop() to TUScheduler, changing 
> TUScheduler to not (exclusively) own UpdateIndexCallbacks, or have the task 
> not capture the callbacks by reference.
> I'll try the latter first, which seems least invasive.
> 
> ---
> 
> > ideally we (sourcekit-lsp) wouldn't be running any indexing at all. As far 
> > as I can tell there's no way to turn off dynamic indexing now though, 
> > except for StandardLibrary indexing through the config file (but not from 
> > clangd args)?
> 
> Clangd won't provide any top-level/namespace-level completions at all without 
> dynamic index (index of preambles), and various other features won't work 
> (docs on hover, include-fixer, type/call-hierarchy). We dropped support for 
> disabling this at some point, as it didn't really seem usable and made 
> features more complex if we tried to accommodate it. At a technical level it 
> would be possible to disable I think, but I'd be really surprised if 
> completion worked well, or if a language server without completion was useful.
> 
> > `StandardLibrary` indexing through the config file (but not from clangd 
> > args)
> 
> We've tried to move away from flags for options that are interesting to 
> users, as config files are more flexible, more forgiving on errors, and allow 
> different settings per-project in a consistent way. (We don't own the 
> editors, so cross-editor consistency is important to being able to support 
> users at all...)
> 
> I can see how requiring config to be materialized on disk could be 
> inconvenient for IDEs though. I think we could add a general-purpose 
> `--config-inline=` flag, and/or the ability to set 
> config over LSP (this can be dynamic, accordingly bigger design space that 
> might be hard to get right).
Ah, I didn't actually check `AsyncTaskRunner`. Makes sense it would wait though 
:). Thanks for looking into this in detail!

> or have the task not capture the callbacks by reference. I'll try the latter 
> first, which seems least invasive.

This + moving `FIndex` after `IndexTasks` seems reasonable to me.

> Clangd won't provide any top-level/namespace-level completions at all without 
> dynamic index (index of preambles), and various other features won't work 
> (docs on hover, include-fixer, type/call-hierarchy).

That's good to know - I assume this extends to indexing the stdlib as well, ie. 
the stdlib would be missing from top/namespace level completion if not indexed? 
Does the dynamic index grow with every opened file, or is it just the currently 
opened file? If disabling breaks everything it's not something we'd want to do, 
we just don't need it for find refs/etc.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115232

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


[PATCH] D139261: [Clang] Modify sanity check assert in AggExprEmitter::VisitInitListExpr to cover anonymous struct in a union GNU extension

2022-12-21 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/lib/CodeGen/CGExprAgg.cpp:1688
   for (const auto *Field : record->fields())
-assert(Field->isUnnamedBitfield() && "Only unnamed bitfields allowed");
+assert((Field->isUnnamedBitfield() || 
Field->isAnonymousStructOrUnion()) && "Only unnamed bitfields or ananymous 
class allowed");
 #endif

aaron.ballman wrote:
> Guessing at the way to solve the 80-col limit issue, but do whatever 
> clang-format says.
This is what clang-format likes.


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

https://reviews.llvm.org/D139261

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


[PATCH] D139261: [Clang] Modify sanity check assert in AggExprEmitter::VisitInitListExpr to cover anonymous struct in a union GNU extension

2022-12-21 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik updated this revision to Diff 484613.
shafik added a comment.

- Add Release note


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

https://reviews.llvm.org/D139261

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/test/SemaCXX/anonymous-struct.cpp


Index: clang/test/SemaCXX/anonymous-struct.cpp
===
--- clang/test/SemaCXX/anonymous-struct.cpp
+++ clang/test/SemaCXX/anonymous-struct.cpp
@@ -189,3 +189,20 @@
   }
 } A; // expected-note {{given name 'A' for linkage purposes by this typedef}}
 }
+
+#if __cplusplus > 201103L
+namespace GH58800 {
+struct A {
+  union {
+struct {
+  float red = 0.0f;
+};
+  };
+};
+
+A GetA() {
+  A result{};
+  return result;
+}
+}
+#endif
Index: clang/lib/CodeGen/CGExprAgg.cpp
===
--- clang/lib/CodeGen/CGExprAgg.cpp
+++ clang/lib/CodeGen/CGExprAgg.cpp
@@ -1724,7 +1724,7 @@
   // Make sure that it's really an empty and not a failure of
   // semantic analysis.
   for (const auto *Field : record->fields())
-assert(Field->isUnnamedBitfield() && "Only unnamed bitfields allowed");
+assert((Field->isUnnamedBitfield() || 
Field->isAnonymousStructOrUnion()) && "Only unnamed bitfields or ananymous 
class allowed");
 #endif
   return;
 }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -326,6 +326,9 @@
 - Fix bug where constant evaluation treated a pointer to member that points to
   a weak member as never being null. Such comparisons are now treated as
   non-constant.
+- Fix sanity check when value initializing an empty union so that it takes into
+  account anonymous structs which is a GNU extension. This fixes
+  `Issue 58800 `_
 
 Improvements to Clang's diagnostics
 ^^^


Index: clang/test/SemaCXX/anonymous-struct.cpp
===
--- clang/test/SemaCXX/anonymous-struct.cpp
+++ clang/test/SemaCXX/anonymous-struct.cpp
@@ -189,3 +189,20 @@
   }
 } A; // expected-note {{given name 'A' for linkage purposes by this typedef}}
 }
+
+#if __cplusplus > 201103L
+namespace GH58800 {
+struct A {
+  union {
+struct {
+  float red = 0.0f;
+};
+  };
+};
+
+A GetA() {
+  A result{};
+  return result;
+}
+}
+#endif
Index: clang/lib/CodeGen/CGExprAgg.cpp
===
--- clang/lib/CodeGen/CGExprAgg.cpp
+++ clang/lib/CodeGen/CGExprAgg.cpp
@@ -1724,7 +1724,7 @@
   // Make sure that it's really an empty and not a failure of
   // semantic analysis.
   for (const auto *Field : record->fields())
-assert(Field->isUnnamedBitfield() && "Only unnamed bitfields allowed");
+assert((Field->isUnnamedBitfield() || Field->isAnonymousStructOrUnion()) && "Only unnamed bitfields or ananymous class allowed");
 #endif
   return;
 }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -326,6 +326,9 @@
 - Fix bug where constant evaluation treated a pointer to member that points to
   a weak member as never being null. Such comparisons are now treated as
   non-constant.
+- Fix sanity check when value initializing an empty union so that it takes into
+  account anonymous structs which is a GNU extension. This fixes
+  `Issue 58800 `_
 
 Improvements to Clang's diagnostics
 ^^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139701: [Clang] Emit "min-legal-vector-width" attribute for X86 only

2022-12-21 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: llvm/docs/LangRef.rst:2235-2241
-``"min-legal-vector-width"=""``
-This attribute indicates the minimum legal vector width required by the
-calling convension. It is the maximum width of vector arguments and
-returnings in the function and functions called by this function. Because
-all the vectors are supposed to be legal type for compatibility.
-Backends are free to ignore the attribute if they don't need to support
-different maximum legal vector types or such information can be inferred by

This still should be documented somewhere. I don't know if we document any 
target attributes specifically in the langref


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139701

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


[PATCH] D140486: [clangd] Fix crashing race in ClangdServer shutdown with stdlib indexing

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

In principle it's OK for stdlib-indexing tasks to run after the TUScheduler is
destroyed, as mostly they just update the dynamic index. We do drain the
stdlib-indexing queue before destroying the index.

However the task captures references to the PreambleCallbacks object, which is
owned by the TUScheduler. Once this is destroyed (explicitly, early in
~ClangdServer) an outstanding stdlib-indexing task may use-after-free.

The fix here is to avoid capturing references to the PreambleCallbacks.
Alternatives would be to have TUScheduler (exclusively) not own its callbacks
so they could live longer, or explicitly stopping the TUScheduler instead of
early-destroying it. These both seem more invasive.

See https://reviews.llvm.org/D115232 for some more context.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140486

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


Index: clang-tools-extra/clangd/ClangdServer.cpp
===
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -63,7 +63,7 @@
ClangdServer::Callbacks *ServerCallbacks,
const ThreadsafeFS , AsyncTaskRunner *Tasks)
   : FIndex(FIndex), ServerCallbacks(ServerCallbacks), TFS(TFS),
-Tasks(Tasks) {}
+Stdlib{std::make_shared()}, Tasks(Tasks) {}
 
   void onPreambleAST(PathRef Path, llvm::StringRef Version,
  const CompilerInvocation , ASTContext ,
@@ -71,7 +71,7 @@
  const CanonicalIncludes ) override {
 // If this preamble uses a standard library we haven't seen yet, index it.
 if (FIndex)
-  if (auto Loc = Stdlib.add(*CI.getLangOpts(), PP.getHeaderSearchInfo()))
+  if (auto Loc = Stdlib->add(*CI.getLangOpts(), PP.getHeaderSearchInfo()))
 indexStdlib(CI, std::move(*Loc));
 
 if (FIndex)
@@ -79,11 +79,22 @@
   }
 
   void indexStdlib(const CompilerInvocation , StdLibLocation Loc) {
-auto Task = [this, LO(*CI.getLangOpts()), Loc(std::move(Loc)),
- CI(std::make_unique(CI))]() mutable {
+// This task is owned by Tasks, which outlives the TUScheduler and
+// therefore the UpdateIndexCallbacks.
+// We must be careful that the references we capture outlive TUScheduler.
+auto Task = [
+// Captured by value
+LO(*CI.getLangOpts()), Loc(std::move(Loc)),
+CI(std::make_unique(CI)),
+// External values that outlive ClangdServer
+TFS(),
+// Index outlives TUScheduler (declared first)
+FIndex(FIndex),
+// shared_ptr extends lifetime
+Stdlib(Stdlib)]() mutable {
   IndexFileIn IF;
-  IF.Symbols = indexStandardLibrary(std::move(CI), Loc, TFS);
-  if (Stdlib.isBest(LO))
+  IF.Symbols = indexStandardLibrary(std::move(CI), Loc, *TFS);
+  if (Stdlib->isBest(LO))
 FIndex->updatePreamble(std::move(IF));
 };
 if (Tasks)
@@ -128,7 +139,7 @@
   FileIndex *FIndex;
   ClangdServer::Callbacks *ServerCallbacks;
   const ThreadsafeFS 
-  StdLibSet Stdlib;
+  std::shared_ptr Stdlib;
   AsyncTaskRunner *Tasks;
 };
 


Index: clang-tools-extra/clangd/ClangdServer.cpp
===
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -63,7 +63,7 @@
ClangdServer::Callbacks *ServerCallbacks,
const ThreadsafeFS , AsyncTaskRunner *Tasks)
   : FIndex(FIndex), ServerCallbacks(ServerCallbacks), TFS(TFS),
-Tasks(Tasks) {}
+Stdlib{std::make_shared()}, Tasks(Tasks) {}
 
   void onPreambleAST(PathRef Path, llvm::StringRef Version,
  const CompilerInvocation , ASTContext ,
@@ -71,7 +71,7 @@
  const CanonicalIncludes ) override {
 // If this preamble uses a standard library we haven't seen yet, index it.
 if (FIndex)
-  if (auto Loc = Stdlib.add(*CI.getLangOpts(), PP.getHeaderSearchInfo()))
+  if (auto Loc = Stdlib->add(*CI.getLangOpts(), PP.getHeaderSearchInfo()))
 indexStdlib(CI, std::move(*Loc));
 
 if (FIndex)
@@ -79,11 +79,22 @@
   }
 
   void indexStdlib(const CompilerInvocation , StdLibLocation Loc) {
-auto Task = [this, LO(*CI.getLangOpts()), Loc(std::move(Loc)),
- CI(std::make_unique(CI))]() mutable {
+// This task is owned by Tasks, which outlives the TUScheduler and
+// therefore the UpdateIndexCallbacks.
+// We must be careful that the references we 

[PATCH] D115232: [clangd] Indexing of standard library

2022-12-21 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/ClangdServer.cpp:1008-1010
+  // TUScheduler is the only thing that starts background indexing work.
+  if (IndexTasks && !IndexTasks->wait(timeoutSeconds(TimeoutSeconds)))
+return false;

bnbarham wrote:
> @sammccall shouldn't we also be waiting for this to finish when 
> `ClangdServer` is destroyed? IIUC right now the both `FileIndex` itself 
> (stored in `ClangdServer`) and the actual `UpdateIndexCallbacks` (stored in 
> `TUScheduler`) can be freed while `indexStdlib` is running asynchronously, 
> resulting in a use-after-free on eg. `FIndex->updatePreamble(std::move(IF))`. 
> I was confused as to why this wasn't happening in the tests, but these lines 
> would explain it  
> 
> Adding a `IndexTasks->wait()` to `~ClangdServer` fixes the crash I'm seeing 
> in the sourcekit-lsp tests (see 
> https://github.com/apple/llvm-project/pull/5837), though ideally we 
> (sourcekit-lsp) wouldn't be running any indexing at all. As far as I can tell 
> there's no way to turn off dynamic indexing now though, except for 
> `StandardLibrary` indexing through the config file (but not from clangd args)?
Thanks for flagging this!

We *almost* have the sequencing we need in ~ClangdServer:
 - when we fall off the end of ~ClangdServer it destroys all its members
 - `ClangdServer::IndexTasks` is declared after `FIndex`, so is destroyed first
 - ~AsyncTaskRunner calls `wait()`

But the task we schedule on `IndexTasks` captures a ref to 
`UpdateIndexCallbacks`, which is owned by the `TUScheduler`, which we 
explicitly destroy at the beginning of `~ClangdServer`.

However I think your patch is *also* not quite correct: we can wait for the 
tasks to be empty, but then the TUScheduler could fill it up again before we 
destroy TUScheduler.

Options include adding an explicit stop() to TUScheduler, changing TUScheduler 
to not (exclusively) own UpdateIndexCallbacks, or have the task not capture the 
callbacks by reference.
I'll try the latter first, which seems least invasive.

---

> ideally we (sourcekit-lsp) wouldn't be running any indexing at all. As far as 
> I can tell there's no way to turn off dynamic indexing now though, except for 
> StandardLibrary indexing through the config file (but not from clangd args)?

Clangd won't provide any top-level/namespace-level completions at all without 
dynamic index (index of preambles), and various other features won't work (docs 
on hover, include-fixer, type/call-hierarchy). We dropped support for disabling 
this at some point, as it didn't really seem usable and made features more 
complex if we tried to accommodate it. At a technical level it would be 
possible to disable I think, but I'd be really surprised if completion worked 
well, or if a language server without completion was useful.

> `StandardLibrary` indexing through the config file (but not from clangd args)

We've tried to move away from flags for options that are interesting to users, 
as config files are more flexible, more forgiving on errors, and allow 
different settings per-project in a consistent way. (We don't own the editors, 
so cross-editor consistency is important to being able to support users at 
all...)

I can see how requiring config to be materialized on disk could be inconvenient 
for IDEs though. I think we could add a general-purpose 
`--config-inline=` flag, and/or the ability to set config 
over LSP (this can be dynamic, accordingly bigger design space that might be 
hard to get right).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115232

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


[PATCH] D140432: [AArch64] Guard {vmull_p64, vmull_high_p64} with 'aes' target guard.

2022-12-21 Thread Mingming Liu via Phabricator via cfe-commits
mingmingl added a comment.

In D140432#4010143 , @dmgreen wrote:

> Thanks for putting together the patch. It may be worth mentioning in the 
> commit message that aes currently includes both FEAT_AES and FEAT_PMULL.
> Otherwise LGTM.

Thanks for reviews! Made the change in commit message and phab summary. Going 
to submit this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140432

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


[PATCH] D140432: [AArch64] Guard {vmull_p64, vmull_high_p64} with 'aes' target guard.

2022-12-21 Thread Mingming Liu via Phabricator via cfe-commits
mingmingl updated this revision to Diff 484608.
mingmingl added a comment.

update commit message to mention target guard 'aes' includes both FEAT_AES and 
FEAT_PMULL currently.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140432

Files:
  clang/include/clang/Basic/arm_neon.td
  clang/test/CodeGen/aarch64-poly128.c
  clang/test/Sema/aarch64-neon-target.c

Index: clang/test/Sema/aarch64-neon-target.c
===
--- clang/test/Sema/aarch64-neon-target.c
+++ clang/test/Sema/aarch64-neon-target.c
@@ -60,7 +60,7 @@
   vrnd32xq_f32(v4f32);
 }
 
-void undefined(uint32x2_t v2i32, uint32x4_t v4i32, uint16x8_t v8i16, uint8x16_t v16i8, uint8x8_t v8i8, float32x2_t v2f32, float32x4_t v4f32, float16x4_t v4f16, float64x2_t v2f64, bfloat16x4_t v4bf16, __bf16 bf16) {
+void undefined(uint32x2_t v2i32, uint32x4_t v4i32, uint16x8_t v8i16, uint8x16_t v16i8, uint8x8_t v8i8, float32x2_t v2f32, float32x4_t v4f32, float16x4_t v4f16, float64x2_t v2f64, bfloat16x4_t v4bf16, __bf16 bf16, poly64_t poly64, poly64x2_t poly64x2) {
   // dotprod
   vdot_u32(v2i32, v8i8, v8i8); // expected-error {{always_inline function 'vdot_u32' requires target feature 'dotprod'}}
   vdot_laneq_u32(v2i32, v8i8, v16i8, 1); // expected-error {{always_inline function 'vdot_u32' requires target feature 'dotprod'}}
@@ -92,4 +92,8 @@
   vcmlaq_rot270_laneq_f64(v2f64, v2f64, v2f64, 1); // expected-error {{always_inline function 'vcmlaq_rot270_f64' requires target feature 'v8.3a'}}
   // 8.5 - frint
   vrnd32xq_f32(v4f32); // expected-error {{always_inline function 'vrnd32xq_f32' requires target feature 'v8.5a'}}
+
+  vmull_p64(poly64, poly64);  // expected-error {{always_inline function 'vmull_p64' requires target feature 'aes'}}
+  vmull_high_p64(poly64x2, poly64x2);  // expected-error {{always_inline function 'vmull_high_p64' requires target feature 'aes'}}
+
 }
Index: clang/test/CodeGen/aarch64-poly128.c
===
--- clang/test/CodeGen/aarch64-poly128.c
+++ clang/test/CodeGen/aarch64-poly128.c
@@ -28,8 +28,8 @@
 // CHECK-LABEL: define {{[^@]+}}@test_vldrq_p128
 // CHECK-SAME: (ptr noundef [[PTR:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP2:%.*]] = load i128, ptr [[PTR]], align 16
-// CHECK-NEXT:ret i128 [[TMP2]]
+// CHECK-NEXT:[[TMP0:%.*]] = load i128, ptr [[PTR]], align 16
+// CHECK-NEXT:ret i128 [[TMP0]]
 //
 poly128_t test_vldrq_p128(poly128_t * ptr) {
   return vldrq_p128(ptr);
@@ -39,9 +39,9 @@
 // CHECK-LABEL: define {{[^@]+}}@test_ld_st_p128
 // CHECK-SAME: (ptr noundef [[PTR:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP2:%.*]] = load i128, ptr [[PTR]], align 16
+// CHECK-NEXT:[[TMP0:%.*]] = load i128, ptr [[PTR]], align 16
 // CHECK-NEXT:[[ADD_PTR:%.*]] = getelementptr inbounds i128, ptr [[PTR]], i64 1
-// CHECK-NEXT:store i128 [[TMP2]], ptr [[ADD_PTR]], align 16
+// CHECK-NEXT:store i128 [[TMP0]], ptr [[ADD_PTR]], align 16
 // CHECK-NEXT:ret void
 //
 void test_ld_st_p128(poly128_t * ptr) {
@@ -50,18 +50,18 @@
 }
 
 // CHECK-LABEL: define {{[^@]+}}@test_vmull_p64
-// CHECK-SAME: (i64 noundef [[A:%.*]], i64 noundef [[B:%.*]]) #[[ATTR0]] {
+// CHECK-SAME: (i64 noundef [[A:%.*]], i64 noundef [[B:%.*]]) #[[ATTR1:[0-9]+]] {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[VMULL_P64_I:%.*]] = call <16 x i8> @llvm.aarch64.neon.pmull64(i64 [[A]], i64 [[B]])
 // CHECK-NEXT:[[VMULL_P641_I:%.*]] = bitcast <16 x i8> [[VMULL_P64_I]] to i128
 // CHECK-NEXT:ret i128 [[VMULL_P641_I]]
 //
-poly128_t test_vmull_p64(poly64_t a, poly64_t b) {
+__attribute__((target("aes"))) poly128_t test_vmull_p64(poly64_t a, poly64_t b) {
   return vmull_p64(a, b);
 }
 
 // CHECK-LABEL: define {{[^@]+}}@test_vmull_high_p64
-// CHECK-SAME: (<2 x i64> noundef [[A:%.*]], <2 x i64> noundef [[B:%.*]]) #[[ATTR1:[0-9]+]] {
+// CHECK-SAME: (<2 x i64> noundef [[A:%.*]], <2 x i64> noundef [[B:%.*]]) #[[ATTR2:[0-9]+]] {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[SHUFFLE_I5:%.*]] = shufflevector <2 x i64> [[A]], <2 x i64> [[A]], <1 x i32> 
 // CHECK-NEXT:[[TMP0:%.*]] = bitcast <1 x i64> [[SHUFFLE_I5]] to i64
@@ -71,12 +71,12 @@
 // CHECK-NEXT:[[VMULL_P641_I_I:%.*]] = bitcast <16 x i8> [[VMULL_P64_I_I]] to i128
 // CHECK-NEXT:ret i128 [[VMULL_P641_I_I]]
 //
-poly128_t test_vmull_high_p64(poly64x2_t a, poly64x2_t b) {
+__attribute__((target("aes"))) poly128_t test_vmull_high_p64(poly64x2_t a, poly64x2_t b) {
   return vmull_high_p64(a, b);
 }
 
 // CHECK-LABEL: define {{[^@]+}}@test_vreinterpretq_p128_s8
-// CHECK-SAME: (<16 x i8> noundef [[A:%.*]]) #[[ATTR1]] {
+// CHECK-SAME: (<16 x i8> noundef [[A:%.*]]) #[[ATTR3:[0-9]+]] {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = bitcast <16 x i8> [[A]] to i128
 // CHECK-NEXT:ret i128 [[TMP0]]
@@ -86,7 +86,7 @@
 }
 
 // CHECK-LABEL: define 

[PATCH] D127812: [AArch64] FMV support and necessary target features dependencies.

2022-12-21 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

In D127812#4010856 , @ilinpv wrote:

> It would be great to have more details how to setup up your bot, using 
> buildbot_fast.sh on x86_64 Ubuntu 22.04 LTS leads to error ( pthreads 
> installed ):
>
>   CMake Error at 
> /usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:230 
> (message):
> Could NOT find Threads (missing: Threads_FOUND)
>   Call Stack (most recent call first):
> /usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:594 
> (_FPHSA_FAILURE_MESSAGE)
> /usr/share/cmake-3.22/Modules/FindThreads.cmake:238 
> (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
> cmake/config-ix.cmake:114 (find_package)
> CMakeLists.txt:776 (include)
>
> Also MemorySanitizer: use-of-uninitialized-value cases from 
> https://lab.llvm.org/buildbot/#/builders/5/builds/30139 looks fine locally, 
> all values initialized, could MSAN produce false positive results?

MSan can find false positives, but that's only if code ends up in your binary 
that isn't built with MSan. The buildscripts are written so that everything 
gets instrumented.

Hmm, not exactly sure what's going on with the `could NOT find Threads` there. 
A quick googling seems to point to pthreads.so not being in the right places, 
but I don't think the buildbot does anything special. Do your regular builds 
with `-DLLVM_ENABLE_PROJECTS="compiler_rt;clang;lld"` work?

When you say that it looks fine locally, is that from your own checkout but 
using `-DLLVM_USE_SANITIZER=Memory`? First thing to check is that you do end up 
with MSan in the test (in particular the clang binary that's being produced), 
which you can do by `nm bin/clang-16 | grep __msan_init`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127812

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


[PATCH] D137838: [Support] Move TargetParsers to new component

2022-12-21 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

This has introduced a circular dependency due to the forwarding header 
(forwarding header depends on new lib, new lib depends on support, where the 
forwarding header is). Generally this wouldn't be acceptable (& I'd suggest the 
patch be reverted on that basis) though I understand this is a complicated 
migration - what's the timeline for correcting this issue?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137838

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


[clang] d4959b5 - [Driver] Fix tests not to fail randomly on Windows

2022-12-21 Thread Paul Robinson via cfe-commits

Author: Paul Robinson
Date: 2022-12-21T09:37:12-08:00
New Revision: d4959b5a4bb888789f99a952a1304ce915dfee2f

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

LOG: [Driver] Fix tests not to fail randomly on Windows

These used a regex that didn't guard against backslashes, so
getting "lucky" with a temp dir name could make them fail.

Added: 


Modified: 
clang/test/Driver/freebsd.c
clang/test/Driver/fuchsia.c
clang/test/Driver/netbsd.c
clang/test/Driver/openbsd.c

Removed: 




diff  --git a/clang/test/Driver/freebsd.c b/clang/test/Driver/freebsd.c
index 87ce46d1c1c6e..a9afff22ae848 100644
--- a/clang/test/Driver/freebsd.c
+++ b/clang/test/Driver/freebsd.c
@@ -212,5 +212,5 @@
 // RELOCATABLE: "-r"
 // RELOCATABLE-NOT: "-dynamic-linker"
 // RELOCATABLE-NOT: "-l
-// RELOCATABLE-NOT: crt{{[^./]+}}.o
+// RELOCATABLE-NOT: crt{{[^./\\]+}}.o
 

diff  --git a/clang/test/Driver/fuchsia.c b/clang/test/Driver/fuchsia.c
index 339fd92309796..9c023329edb5f 100644
--- a/clang/test/Driver/fuchsia.c
+++ b/clang/test/Driver/fuchsia.c
@@ -89,7 +89,7 @@
 // CHECK-RELOCATABLE-NOT "-dynamic-linker"
 // CHECK-RELOCATABLE: "-r"
 // CHECK-RELOCATABLE-NOT: "-l
-// CHECK-RELOCATABLE-NOT: crt{{[^./]+}}.o
+// CHECK-RELOCATABLE-NOT: crt{{[^./\\]+}}.o
 
 // RUN: %clang -### %s --target=x86_64-unknown-fuchsia -nodefaultlibs 
-fuse-ld=lld 2>&1 \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \

diff  --git a/clang/test/Driver/netbsd.c b/clang/test/Driver/netbsd.c
index 436772ab99795..52f3a33198059 100644
--- a/clang/test/Driver/netbsd.c
+++ b/clang/test/Driver/netbsd.c
@@ -476,4 +476,4 @@
 // RELOCATABLE-NOT: "-pie"
 // RELOCATABLE-NOT: "-dynamic-linker"
 // RELOCATABLE-NOT: "-l
-// RELOCATABLE-NOT: crt{{[^./]+}}.o
+// RELOCATABLE-NOT: crt{{[^./\\]+}}.o

diff  --git a/clang/test/Driver/openbsd.c b/clang/test/Driver/openbsd.c
index 3ba8a315f6e16..05d290a309c40 100644
--- a/clang/test/Driver/openbsd.c
+++ b/clang/test/Driver/openbsd.c
@@ -39,7 +39,7 @@
 // CHECK-LD-R: "-r"
 // CHECK-LD-R-NOT: "-dynamic-linker"
 // CHECK-LD-R-NOT: "-l
-// CHECK-LD-R-NOT: crt{{[^./]+}}.o
+// CHECK-LD-R-NOT: crt{{[^./\\]+}}.o
 // CHECK-LD-S: "-cc1" "-triple" "i686-pc-openbsd"
 // CHECK-LD-S: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" 
"-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" 
"-L{{.*}}" "-s" "{{.*}}.o" "-lcompiler_rt" "-lc" "-lcompiler_rt" 
"{{.*}}crtend.o"
 // CHECK-LD-T: "-cc1" "-triple" "i686-pc-openbsd"



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


[PATCH] D139534: [analyzer] Don't escape local static memregions on bind

2022-12-21 Thread Balázs Benics via Phabricator via cfe-commits
steakhal updated this revision to Diff 484600.
steakhal added a comment.

- Add two test cases demonstrating the false-positives this patch will 
introduce. These are semantically equivalent to the one mentioned in the 
comments by @NoQ.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139534

Files:
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/test/Analysis/malloc-static-storage.cpp


Index: clang/test/Analysis/malloc-static-storage.cpp
===
--- /dev/null
+++ clang/test/Analysis/malloc-static-storage.cpp
@@ -0,0 +1,77 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.Malloc -verify %s
+
+typedef __typeof(sizeof(int)) size_t;
+void* malloc(size_t size);
+void *calloc(size_t num, size_t size);
+void free(void * ptr);
+
+void escape(void *);
+void next_statement();
+
+void conditional_malloc(bool coin) {
+  static int *p;
+
+  if (coin) {
+p = (int *)malloc(sizeof(int));
+  }
+  p = 0; // Pointee of 'p' dies, which is recognized at the next statement.
+  next_statement(); // expected-warning {{Potential memory leak}}
+}
+
+void malloc_twice() {
+  static int *p;
+  p = (int *)malloc(sizeof(int));
+  next_statement();
+  p = (int *)malloc(sizeof(int));
+  next_statement(); // expected-warning {{Potential memory leak}}
+  p = 0;
+  next_statement(); // expected-warning {{Potential memory leak}}
+}
+
+void malloc_escape() {
+  static int *p;
+  p = (int *)malloc(sizeof(int));
+  escape(p); // no-leak
+  p = 0; // no-leak
+}
+
+void free_whatever_escaped();
+void malloc_escape_reversed() {
+  static int *p;
+  escape();
+  p = (int *)malloc(sizeof(int));
+  free_whatever_escaped();
+  p = 0; // FIXME: We should not report a leak here.
+  next_statement(); // expected-warning {{Potential memory leak}}
+}
+
+int *malloc_return_static() {
+  static int *p = (int *)malloc(sizeof(int));
+  return p; // no-leak
+}
+
+int malloc_unreachable(int rng) {
+  // 'p' does not escape and never freed :(
+  static int *p;
+
+  // For the second invocation of this function, we leak the previous pointer.
+  // FIXME: We should catch this at some point.
+  p = (int *)malloc(sizeof(int));
+  *p = 0;
+
+  if (rng > 0)
+*p = rng;
+
+  return *p; // FIXME: We just leaked 'p'. We should warn about this.
+}
+
+void malloc_cond(bool cond) {
+  static int *p;
+  if (cond) {
+p = (int*)malloc(sizeof(int));
+free_whatever_escaped();
+p = 0; // FIXME: We should not report a leak here.
+next_statement(); // expected-warning {{Potential memory leak}}
+  }
+  escape();
+}
Index: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -3462,7 +3462,8 @@
   for (const std::pair  : LocAndVals) {
 // Cases (1) and (2).
 const MemRegion *MR = LocAndVal.first.getAsRegion();
-if (!MR || !MR->hasStackStorage()) {
+if (!MR ||
+!isa(MR->getMemorySpace())) 
{
   Escaped.push_back(LocAndVal.second);
   continue;
 }


Index: clang/test/Analysis/malloc-static-storage.cpp
===
--- /dev/null
+++ clang/test/Analysis/malloc-static-storage.cpp
@@ -0,0 +1,77 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.Malloc -verify %s
+
+typedef __typeof(sizeof(int)) size_t;
+void* malloc(size_t size);
+void *calloc(size_t num, size_t size);
+void free(void * ptr);
+
+void escape(void *);
+void next_statement();
+
+void conditional_malloc(bool coin) {
+  static int *p;
+
+  if (coin) {
+p = (int *)malloc(sizeof(int));
+  }
+  p = 0; // Pointee of 'p' dies, which is recognized at the next statement.
+  next_statement(); // expected-warning {{Potential memory leak}}
+}
+
+void malloc_twice() {
+  static int *p;
+  p = (int *)malloc(sizeof(int));
+  next_statement();
+  p = (int *)malloc(sizeof(int));
+  next_statement(); // expected-warning {{Potential memory leak}}
+  p = 0;
+  next_statement(); // expected-warning {{Potential memory leak}}
+}
+
+void malloc_escape() {
+  static int *p;
+  p = (int *)malloc(sizeof(int));
+  escape(p); // no-leak
+  p = 0; // no-leak
+}
+
+void free_whatever_escaped();
+void malloc_escape_reversed() {
+  static int *p;
+  escape();
+  p = (int *)malloc(sizeof(int));
+  free_whatever_escaped();
+  p = 0; // FIXME: We should not report a leak here.
+  next_statement(); // expected-warning {{Potential memory leak}}
+}
+
+int *malloc_return_static() {
+  static int *p = (int *)malloc(sizeof(int));
+  return p; // no-leak
+}
+
+int malloc_unreachable(int rng) {
+  // 'p' does not escape and never freed :(
+  static int *p;
+
+  // For the second invocation of this function, we leak the previous pointer.
+  // FIXME: We should catch this at some point.
+  p = (int *)malloc(sizeof(int));
+  *p = 

[PATCH] D139534: [analyzer] Don't escape local static memregions on bind

2022-12-21 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

Finally, I had some time to come back to this.
Thanks for taking the time for such a detailed response, kudos! @NoQ

In D139534#3999455 , @NoQ wrote:

> Ok screw it, my static example is still broken. There's technically still a 
> leak in it because there's no time for the other code to kick in between `p = 
> (int *)malloc(sizeof(int));` and `p = 0;` to read the value from `p`.
>
> But in practice there could be a lot of things going on in between, that with 
> your patch might not trigger enough escapes. Let me disconnect from the 
> original test case and try to build a few examples more carefully.
>
>   void foo() {
> static int *p;
> escape();
> p = malloc(sizeof(int));
> free_whatever_escaped();
> p = 0; // no-leak
>   }
>
> This isn't a leak, regardless of whether the variable is static or not. 
> Currently we display a leak when the variable is non-static (bad) but don't 
> display a leak when the variable is static (good). IIUC your patch might 
> break this. The important part is that in this case there's no direct 
> connection between the tracked pointer `p` and the escaped region `` 
> because `p` isn't stored in `` until the next line. So if you remove 
> invalidation of `p` on `free_whatever_escaped();`, it'll cause a new false 
> positive in the static case.

Yes, I'd introduce FP for this case.

>   void foo(cond) {
> static int *p;
> if (cond) {
>   p = malloc(sizeof(int));
>   free_whatever_escaped();
>   p = 0; // no-leak
> }
> escape();
>   }
>
> In this case there's no leak as long as the first invocation of the function 
> always has `cond` set to false. In this case, again, there's no direct 
> connection between `` and the return value of `malloc()` when direct escape 
> of `` happens. On top of that, the direct escape of `` isn't observed at 
> all until much later in the analysis. But just because the local is static, 
> and the function can be called multiple times, the escape at the end of the 
> analysis may "affect" our decision-making at the beginning of the analysis. I 
> suspect your patch breaks this example as well.

Yes, we will report a FP there with my patch.

> So basically in order to do the right thing here, you need to make sure there 
> are no direct escapes of that static variable *anywhere* in the function. But 
> as long as there's no direct escapes, you're probably good to go. With 
> non-static locals you only need to observe escapes *before* the leak (but 
> possibly before the allocation as well), which we currently don't do a good 
> job at anyway.

I agree that we could improve escape handling of static variables by checking 
if that could have escaped *anywhere*. Although, I don't plan to invest time 
there.

> Then, again, it's possible that your patch improves FP rates than what we 
> currently have, just by being a different trade-off, given how artificial my 
> examples are, but we'll need some data to figure it out.

According to my differential analysis, I saw only 2 new issues and 1 
disappearing issue.
The test corpus includes roughly 170 projects, including really big ones; 
windows, Linux, old, new, C and C++ projects as well.
Also, note that we are not using the default set of checks, nor the cc1 driver.

The two new issues were both TPs, for memory leaks. I'll elaborate on these 
later.
I haven't investigated the single disappearing issue, which was about `The 
right operand of '<' is a garbage value`. In the context, I could see some 
local static variables though.

---

Here is the gist of one *new* TP:

  // OpenJDK src/java.base/unix/native/libjava/java_props_md.c
  #define NULL ((void*)0)
  typedef unsigned int uid_t;
  extern struct passwd *getpwuid(uid_t uid);
  extern uid_t getuid();
  extern char *strdup(const char *s);
  extern char *getenv(const char *name);
  struct passwd {
char *pw_dir;
  };
  
  typedef struct {
char *user_home;
  } java_props_t;
  
  java_props_t *GetJavaProperties(struct JNIEnv *env) {
static java_props_t sprops;
  
struct passwd *pwent = getpwuid(getuid());
sprops.user_home = pwent ? strdup(pwent->pw_dir) : NULL; // taking 'true' 
branch; allocating memory by 'strdup'
if (sprops.user_home == NULL || sprops.user_home[0] == '\0' ||
sprops.user_home[1] == '\0') {
  char *user_home = getenv("HOME");
  if ((user_home != NULL) && (user_home[0] != '\0'))
sprops.user_home = user_home; // leaking previous `sprops.user_home` !
}
  }

The other TP in the Samba project looks quite similar but involves a loop 
complicating things.

---

By looking at the results, I think my patch helps more than hinders, and I'm 
also not expecting many users severely impacted by this change.




Comment at: clang/test/Analysis/malloc-static-storage.cpp:33-38
+void malloc_escape() {
+  static int *p;
+  p = (int *)malloc(sizeof(int));
+  escape(p); // 

[PATCH] D137817: [clangd] Improve action `RemoveUsingNamespace` for user-defined literals

2022-12-21 Thread Vincent Hong via Phabricator via cfe-commits
v1nh1shungry abandoned this revision.
v1nh1shungry added a comment.

Abandon because of the terrible implementation.

- The cost seems to be higher than the value.

- The place to insert isn't good enough.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137817

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


[PATCH] D105584: [MLIR][OpenMP] Distribute Construct Operation

2022-12-21 Thread Abid via Phabricator via cfe-commits
abidmalikwaterloo marked 5 inline comments as done.
abidmalikwaterloo added inline comments.



Comment at: mlir/test/Dialect/OpenMP/ops.mlir:124
 
+// CHECK-LABEL: omp_DistributeOp
+func.func @omp_DistributeOp(%lb : index, %ub : index, %step : index, %data_var 
: memref, %chunk_var : i32) -> () {

kiranchandramohan wrote:
> kiranchandramohan wrote:
> > Add a pretty-print test as well.
> Nit: please add a pretty-print test.
Just need clarification. Do you mean something similar to the following:

```
// CHECK-LABEL: omp_wsloop_pretty
func.func @omp_wsloop_pretty(%lb : index, %ub : index, %step : index, %data_var 
: memref, %linear_var : i32, %chunk_var : i32, %chunk_var2 : i16) -> () {

  // CHECK: omp.wsloop ordered(2)
  // CHECK-SAME: for (%{{.*}}) : index = (%{{.*}}) to (%{{.*}}) step (%{{.*}})
  omp.wsloop ordered(2)
  for (%iv) : index = (%lb) to (%ub) step (%step) {
omp.yield
  }

  // CHECK: omp.wsloop linear(%{{.*}} = %{{.*}} : memref) schedule(static)
  // CHECK-SAME: for (%{{.*}}) : index = (%{{.*}}) to (%{{.*}}) step (%{{.*}})
  omp.wsloop schedule(static) linear(%data_var = %linear_var : memref)
  for (%iv) : index = (%lb) to (%ub) step (%step) {
omp.yield
  }

  // CHECK: omp.wsloop linear(%{{.*}} = %{{.*}} : memref) schedule(static 
= %{{.*}} : i32) ordered(2)
  // CHECK-SAME: for (%{{.*}}) : index = (%{{.*}}) to (%{{.*}}) step (%{{.*}})
  omp.wsloop ordered(2) linear(%data_var = %linear_var : memref) 
schedule(static = %chunk_var : i32)
  for (%iv) : index = (%lb) to (%ub) step (%step) {
omp.yield
  }

  // CHECK: omp.wsloop linear(%{{.*}} = %{{.*}} : memref) schedule(dynamic 
= %{{.*}} : i32, nonmonotonic) ordered(2)
  // CHECK-SAME: for (%{{.*}}) : index = (%{{.*}}) to (%{{.*}}) step (%{{.*}})
  omp.wsloop ordered(2) linear(%data_var = %linear_var : memref) 
schedule(dynamic = %chunk_var : i32, nonmonotonic)
  for (%iv) : index = (%lb) to (%ub) step (%step)  {
omp.yield
  }

  // CHECK: omp.wsloop linear(%{{.*}} = %{{.*}} : memref) schedule(dynamic 
= %{{.*}} : i16, monotonic) ordered(2)
  // CHECK-SAME: for (%{{.*}}) : index = (%{{.*}}) to (%{{.*}}) step (%{{.*}})
  omp.wsloop ordered(2) linear(%data_var = %linear_var : memref) 
schedule(dynamic = %chunk_var2 : i16, monotonic)
  for (%iv) : index = (%lb) to (%ub) step (%step) {
omp.yield
  }

  // CHECK: omp.wsloop for (%{{.*}}) : index = (%{{.*}}) to (%{{.*}}) step 
(%{{.*}})
  omp.wsloop for (%iv) : index = (%lb) to (%ub) step (%step) {
omp.yield
  }

  // CHECK: omp.wsloop for (%{{.*}}) : index = (%{{.*}}) to (%{{.*}}) inclusive 
step (%{{.*}})
  omp.wsloop for (%iv) : index = (%lb) to (%ub) inclusive step (%step) {
omp.yield
  }

  // CHECK: omp.wsloop nowait
  // CHECK-SAME: for (%{{.*}}) : index = (%{{.*}}) to (%{{.*}}) step (%{{.*}})
  omp.wsloop nowait
  for (%iv) : index = (%lb) to (%ub) step (%step) {
omp.yield
  }

  // CHECK: omp.wsloop nowait order(concurrent)
  // CHECK-SAME: for (%{{.*}}) : index = (%{{.*}}) to (%{{.*}}) step (%{{.*}})
  omp.wsloop order(concurrent) nowait
  for (%iv) : index = (%lb) to (%ub) step (%step) {
omp.yield
  }

  return
}
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105584

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


[PATCH] D140433: [Clang] Add `nvptx-arch` tool to query installed NVIDIA GPUs

2022-12-21 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 484594.
jhuber6 added a comment.

Change header I copied from the AMD implementation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140433

Files:
  clang/tools/CMakeLists.txt
  clang/tools/nvptx-arch/CMakeLists.txt
  clang/tools/nvptx-arch/NVPTXArch.cpp

Index: clang/tools/nvptx-arch/NVPTXArch.cpp
===
--- /dev/null
+++ clang/tools/nvptx-arch/NVPTXArch.cpp
@@ -0,0 +1,67 @@
+//===- NVPTXArch.cpp - list installed NVPTX devies --*- 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 implements a tool for detecting name of CUDA gpus installed in the
+// system.
+//
+//===--===//
+
+#if defined(__has_include)
+#if __has_include("cuda.h")
+#include "cuda.h"
+#define CUDA_HEADER_FOUND 1
+#else
+#define CUDA_HEADER_FOUND 0
+#endif
+#else
+#define CUDA_HEADER_FOUND 0
+#endif
+
+#if !CUDA_HEADER_FOUND
+int main() { return 1; }
+#else
+
+#include 
+#include 
+
+static int handleError(CUresult Err) {
+  const char *ErrStr = nullptr;
+  CUresult Result = cuGetErrorString(Err, );
+  if (Result != CUDA_SUCCESS)
+return 1;
+  printf("CUDA error: %s\n", ErrStr);
+  return 1;
+}
+
+int main() {
+  if (CUresult Err = cuInit(0))
+return 1;
+
+  int Count = 0;
+  if (cuDeviceGetCount())
+return 1;
+  if (Count == 0)
+return 0;
+  for (int DeviceId = 0; DeviceId < Count; ++DeviceId) {
+CUdevice Device;
+if (CUresult Err = cuDeviceGet(, DeviceId))
+  return handleError(Err);
+
+int32_t Major, Minor;
+if (CUresult Err = cuDeviceGetAttribute(
+, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, Device))
+  return handleError(Err);
+if (CUresult Err = cuDeviceGetAttribute(
+, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, Device))
+  return handleError(Err);
+
+printf("sm_%d%d\n", Major, Minor);
+  }
+  return 0;
+}
+#endif
Index: clang/tools/nvptx-arch/CMakeLists.txt
===
--- /dev/null
+++ clang/tools/nvptx-arch/CMakeLists.txt
@@ -0,0 +1,28 @@
+# //======//
+# //
+# // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# // See https://llvm.org/LICENSE.txt for details.
+# // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+# //
+# //======//
+
+
+# TODO: This is deprecated. Since CMake 3.17 we can use FindCUDAToolkit instead.
+find_package(CUDA QUIET)
+find_library(cuda-library NAMES cuda PATHS /lib64)
+if (NOT cuda-library AND CUDA_FOUND)
+  get_filename_component(CUDA_LIBDIR "${CUDA_cudart_static_LIBRARY}" DIRECTORY)
+  find_library(cuda-library NAMES cuda HINTS "${CUDA_LIBDIR}/stubs")
+endif()
+
+if (NOT CUDA_FOUND OR NOT cuda-library)
+  message(STATUS "Not building nvptx-arch: cuda runtime not found")
+  return()
+endif()
+
+add_clang_tool(nvptx-arch NVPTXArch.cpp)
+
+set_target_properties(nvptx-arch PROPERTIES INSTALL_RPATH_USE_LINK_PATH ON)
+target_include_directories(nvptx-arch PRIVATE ${CUDA_INCLUDE_DIRS})
+
+clang_target_link_libraries(nvptx-arch PRIVATE ${cuda-library})
Index: clang/tools/CMakeLists.txt
===
--- clang/tools/CMakeLists.txt
+++ clang/tools/CMakeLists.txt
@@ -50,3 +50,4 @@
 add_clang_subdirectory(libclang)
 
 add_clang_subdirectory(amdgpu-arch)
+add_clang_subdirectory(nvptx-arch)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140327: [clang] Remove overly restrictive aggregate paren init logic

2022-12-21 Thread Alan Zhao via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc77a91bb7ba7: [clang] Remove overly restrictive aggregate 
paren init logic (authored by ayzhao).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140327

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/test/CodeGen/paren-list-agg-init.cpp


Index: clang/test/CodeGen/paren-list-agg-init.cpp
===
--- clang/test/CodeGen/paren-list-agg-init.cpp
+++ clang/test/CodeGen/paren-list-agg-init.cpp
@@ -1,9 +1,25 @@
 // RUN: %clang_cc1 -std=c++20 %s -emit-llvm -triple x86_64-unknown-linux-gnu 
-o - | FileCheck %s
 
+template 
+struct IsChar {
+  constexpr operator bool() const { return false; }
+};
+
+template<>
+struct IsChar {
+  constexpr operator bool() const { return true; }
+};
+
+template 
+concept SameAsChar = (bool)IsInt();
+
 // CHECK-DAG: [[STRUCT_A:%.*]] = type { i8, double }
 struct A {
   char i;
   double j;
+
+  template 
+  operator T() const { return i; };
 };
 
 // CHECK-DAG: [[STRUCT_B:%.*]] = type { [[STRUCT_A]], i32 }
@@ -29,6 +45,7 @@
 struct E {
   int a;
   const char* fn = __builtin_FUNCTION();
+  ~E() {};
 };
 
 // CHECK-DAG: [[STRUCT_F:%.*]] = type { i8 }
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5930,25 +5930,6 @@
   return false;
 }
 
-static bool onlyHasDefaultedCtors(OverloadCandidateSet ) {
-  if (OCS.size() != 3)
-return false;
-
-  bool HasDefaultCtor = false, HasCopyCtor = false, HasMoveCtor = false;
-  for (const auto  : OCS) {
-if (auto *Ctor = dyn_cast_or_null(Candidate.Function);
-Ctor != nullptr && Ctor->isDefaulted()) {
-  if (Ctor->isDefaultConstructor())
-HasDefaultCtor = true;
-  else if (Ctor->isCopyConstructor())
-HasCopyCtor = true;
-  else if (Ctor->isMoveConstructor())
-HasMoveCtor = true;
-}
-  }
-  return HasDefaultCtor && HasCopyCtor && HasMoveCtor;
-}
-
 void InitializationSequence::InitializeFrom(Sema ,
 const InitializedEntity ,
 const InitializationKind ,
@@ -6196,8 +6177,7 @@
   if (const auto *RD =
   
dyn_cast(DestType->getAs()->getDecl());
   S.getLangOpts().CPlusPlus20 && RD && RD->isAggregate() && Failed() &&
-  getFailureKind() == FK_ConstructorOverloadFailed &&
-  onlyHasDefaultedCtors(getFailedCandidateSet())) {
+  getFailureKind() == FK_ConstructorOverloadFailed) {
 // C++20 [dcl.init] 17.6.2.2:
 //   - Otherwise, if no constructor is viable, the destination type is
 //   an


Index: clang/test/CodeGen/paren-list-agg-init.cpp
===
--- clang/test/CodeGen/paren-list-agg-init.cpp
+++ clang/test/CodeGen/paren-list-agg-init.cpp
@@ -1,9 +1,25 @@
 // RUN: %clang_cc1 -std=c++20 %s -emit-llvm -triple x86_64-unknown-linux-gnu -o - | FileCheck %s
 
+template 
+struct IsChar {
+  constexpr operator bool() const { return false; }
+};
+
+template<>
+struct IsChar {
+  constexpr operator bool() const { return true; }
+};
+
+template 
+concept SameAsChar = (bool)IsInt();
+
 // CHECK-DAG: [[STRUCT_A:%.*]] = type { i8, double }
 struct A {
   char i;
   double j;
+
+  template 
+  operator T() const { return i; };
 };
 
 // CHECK-DAG: [[STRUCT_B:%.*]] = type { [[STRUCT_A]], i32 }
@@ -29,6 +45,7 @@
 struct E {
   int a;
   const char* fn = __builtin_FUNCTION();
+  ~E() {};
 };
 
 // CHECK-DAG: [[STRUCT_F:%.*]] = type { i8 }
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5930,25 +5930,6 @@
   return false;
 }
 
-static bool onlyHasDefaultedCtors(OverloadCandidateSet ) {
-  if (OCS.size() != 3)
-return false;
-
-  bool HasDefaultCtor = false, HasCopyCtor = false, HasMoveCtor = false;
-  for (const auto  : OCS) {
-if (auto *Ctor = dyn_cast_or_null(Candidate.Function);
-Ctor != nullptr && Ctor->isDefaulted()) {
-  if (Ctor->isDefaultConstructor())
-HasDefaultCtor = true;
-  else if (Ctor->isCopyConstructor())
-HasCopyCtor = true;
-  else if (Ctor->isMoveConstructor())
-HasMoveCtor = true;
-}
-  }
-  return HasDefaultCtor && HasCopyCtor && HasMoveCtor;
-}
-
 void InitializationSequence::InitializeFrom(Sema ,
 const InitializedEntity ,
 const InitializationKind ,
@@ -6196,8 +6177,7 @@
   if (const auto *RD =
   dyn_cast(DestType->getAs()->getDecl());
   S.getLangOpts().CPlusPlus20 && RD && RD->isAggregate() && Failed() &&
-  getFailureKind() == 

[clang] c77a91b - [clang] Remove overly restrictive aggregate paren init logic

2022-12-21 Thread Alan Zhao via cfe-commits

Author: Alan Zhao
Date: 2022-12-21T08:21:05-08:00
New Revision: c77a91bb7ba793ec3a6a5da3743ed55056291658

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

LOG: [clang] Remove overly restrictive aggregate paren init logic

Previously, we would only attempt to perform a parenthesized aggregate
initialization if constructor initialization failed for only the default
constructor, default copy constructor, and default move constructor. The
original intent of this logic was to reject initializing objects that
have failed resolving a user-defined constructor. However, this check is
redundant because we check for isAggregate() before attempting to
perform a parenthesized aggregate initialization, and classes that have
user-defined or user-declared constructors are not aggregates.
Furthermore, this check is too restrictive - the following valid
examples fail:
* Aggregate class with user-defined destructor - fails because default
  move constructors are not generated for classes with user-defined
  destructors
  (https://github.com/llvm/llvm-project/issues/54040#issuecomment-1356926048)
* Concept-guarded conversion operator on an aggregate's member:
  (https://github.com/llvm/llvm-project/issues/54040#issuecomment-1356931745)

The solution therefore is to remove this logic; existing tests still
pass, and the previously failing examples now compile.

Reviewed By: ilya-biryukov

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

Added: 


Modified: 
clang/lib/Sema/SemaInit.cpp
clang/test/CodeGen/paren-list-agg-init.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index de419cae490ff..103986521f76e 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -5930,25 +5930,6 @@ static bool canPerformArrayCopy(const InitializedEntity 
) {
   return false;
 }
 
-static bool onlyHasDefaultedCtors(OverloadCandidateSet ) {
-  if (OCS.size() != 3)
-return false;
-
-  bool HasDefaultCtor = false, HasCopyCtor = false, HasMoveCtor = false;
-  for (const auto  : OCS) {
-if (auto *Ctor = dyn_cast_or_null(Candidate.Function);
-Ctor != nullptr && Ctor->isDefaulted()) {
-  if (Ctor->isDefaultConstructor())
-HasDefaultCtor = true;
-  else if (Ctor->isCopyConstructor())
-HasCopyCtor = true;
-  else if (Ctor->isMoveConstructor())
-HasMoveCtor = true;
-}
-  }
-  return HasDefaultCtor && HasCopyCtor && HasMoveCtor;
-}
-
 void InitializationSequence::InitializeFrom(Sema ,
 const InitializedEntity ,
 const InitializationKind ,
@@ -6196,8 +6177,7 @@ void InitializationSequence::InitializeFrom(Sema ,
   if (const auto *RD =
   
dyn_cast(DestType->getAs()->getDecl());
   S.getLangOpts().CPlusPlus20 && RD && RD->isAggregate() && Failed() &&
-  getFailureKind() == FK_ConstructorOverloadFailed &&
-  onlyHasDefaultedCtors(getFailedCandidateSet())) {
+  getFailureKind() == FK_ConstructorOverloadFailed) {
 // C++20 [dcl.init] 17.6.2.2:
 //   - Otherwise, if no constructor is viable, the destination type is
 //   an

diff  --git a/clang/test/CodeGen/paren-list-agg-init.cpp 
b/clang/test/CodeGen/paren-list-agg-init.cpp
index 991cb4950b187..a7534fb907d2b 100644
--- a/clang/test/CodeGen/paren-list-agg-init.cpp
+++ b/clang/test/CodeGen/paren-list-agg-init.cpp
@@ -1,9 +1,25 @@
 // RUN: %clang_cc1 -std=c++20 %s -emit-llvm -triple x86_64-unknown-linux-gnu 
-o - | FileCheck %s
 
+template 
+struct IsChar {
+  constexpr operator bool() const { return false; }
+};
+
+template<>
+struct IsChar {
+  constexpr operator bool() const { return true; }
+};
+
+template 
+concept SameAsChar = (bool)IsInt();
+
 // CHECK-DAG: [[STRUCT_A:%.*]] = type { i8, double }
 struct A {
   char i;
   double j;
+
+  template 
+  operator T() const { return i; };
 };
 
 // CHECK-DAG: [[STRUCT_B:%.*]] = type { [[STRUCT_A]], i32 }
@@ -29,6 +45,7 @@ struct D {
 struct E {
   int a;
   const char* fn = __builtin_FUNCTION();
+  ~E() {};
 };
 
 // CHECK-DAG: [[STRUCT_F:%.*]] = type { i8 }



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


[PATCH] D140327: [clang] Remove overly restrictive aggregate paren init logic

2022-12-21 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov 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/D140327/new/

https://reviews.llvm.org/D140327

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


[PATCH] D127812: [AArch64] FMV support and necessary target features dependencies.

2022-12-21 Thread Pavel Iliin via Phabricator via cfe-commits
ilinpv added a comment.



In D127812#4009577 , @hctim wrote:

> In D127812#4009447 , @hctim wrote:
>
>> Hi, this looks like a candidate for breaking the MSan bot: 
>> https://lab.llvm.org/buildbot/#/builders/5/builds/30139
>>
>> Still looking into it and bisecting, will let you know when I have more 
>> info. To reproduce the bots, the best way (because MSan setup is tricky 
>> because it requires an instrumented libcxx) is to use the scripts from 
>> https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild 
>> (buildbot_fast.sh is the right one).
>
> Yeah, unfortunately I did track this failure down to this commit and reverted 
> it upstream. If you need help figuring it out, please let me know. You may 
> find that adding `-fsanitize-memory-track-origins=2` useful to add to the 
> buildscript as well (which can be done by changing `check_stage2_msan` to 
> `check_stage2_msan_track_origins` in `buildbot_fast.sh`.

It would be great to have more details how to setup up your bot, using 
buildbot_fast.sh on x86_64 Ubuntu 22.04 LTS leads to error ( pthreads installed 
):

  CMake Error at 
/usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find Threads (missing: Threads_FOUND)
  Call Stack (most recent call first):
/usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:594 
(_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.22/Modules/FindThreads.cmake:238 
(FIND_PACKAGE_HANDLE_STANDARD_ARGS)
cmake/config-ix.cmake:114 (find_package)
CMakeLists.txt:776 (include)

Also MemorySanitizer: use-of-uninitialized-value cases from 
https://lab.llvm.org/buildbot/#/builders/5/builds/30139 looks fine locally, all 
values initialized, could MSAN produce false positive results?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127812

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


[PATCH] D137517: [TargetParser] Generate the defs for RISCV CPUs using llvm-tblgen.

2022-12-21 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 added inline comments.



Comment at: llvm/lib/TargetParser/CMakeLists.txt:29
+# LLVMTargetParser. See https://stackoverflow.com/a/25681179
+target_include_directories(LLVMTargetParser PUBLIC 
$)

Will it work if RISC-V target is not compiled-in?
This does not strictly add a cyclic dependency, but it would still be nice to 
avoid dependency on higher-level components.
Is it possible / reasonable to extract the part of the RISCV.td that relates to 
this component and put it separate td file in this directory? Or is it tightly 
coupled with the rest of the target description?




Comment at: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:15
+#include "llvm/TableGen/Record.h"
+#include 
+namespace llvm {

 [[ 
https://llvm.org/docs/CodingStandards.html#include-iostream-is-forbidden | is 
forbidden ]] by the coding standards.




Comment at: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:16
+#include 
+namespace llvm {
+

This [[ 
https://llvm.org/docs/CodingStandards.html#use-namespace-qualifiers-to-implement-previously-declared-functions
 | should be ]] `using namespace llvm;`



Comment at: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:18
+
+std::string getEnumFeatures(Record ) {
+  std::vector Features = Rec.getValueAsListOfDefs("Features");

This should be `static`.



Comment at: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:20
+  std::vector Features = Rec.getValueAsListOfDefs("Features");
+  if (std::find_if(Features.begin(), Features.end(), [](Record *R) {
+return R->getName() == "Feature64Bit";

(suggestion) LLVM's version of find_if accepts ranges, which is a bit shorter.



Comment at: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:28
+
+void EmitRISCVTargetDef(RecordKeeper , raw_ostream ) {
+  const auto  = RK.getDefs();

This function does not seem to mutate RecordKeeper, so it should be `const`.



Comment at: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:37
+  // Iterate on all definition records.
+  for (auto  : Map) {
+const auto  = Def.second;

Should also `const`, same for the loop below.



Comment at: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:52
+  for (auto  : Map) {
+const auto  = Def.second;
+if (Record->isSubClassOf("RISCVProcessorModelTUNE_PROC"))

Same for the loop above.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137517

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


[PATCH] D140433: [Clang] Add `nvptx-arch` tool to query installed NVIDIA GPUs

2022-12-21 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added inline comments.



Comment at: clang/tools/nvptx-arch/NVPTXArch.cpp:63
+
+printf("sm_%d%d\n", Major, Minor);
+  }

tianshilei1992 wrote:
> Do we want to include device number here?
For `amdgpu-arch` and here we just have it implicitly in the order, so the n-th 
line is the n-th device, i.e.
```
sm_70 // device 0
sm_80 // device 1
sm_70 // device 2
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140433

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


[PATCH] D140433: [Clang] Add `nvptx-arch` tool to query installed NVIDIA GPUs

2022-12-21 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added inline comments.



Comment at: clang/tools/nvptx-arch/NVPTXArch.cpp:63
+
+printf("sm_%d%d\n", Major, Minor);
+  }

Do we want to include device number here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140433

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


[PATCH] D139266: Headers: tweak inclusion condition for stdatomic.h

2022-12-21 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd added a comment.

@thakis and https://github.com/llvm/llvm-project/issues/59640


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139266

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


[PATCH] D140483: Remove empty header file.

2022-12-21 Thread Dani Ferreira Franco Moura via Phabricator via cfe-commits
merrymeerkat created this revision.
Herald added a reviewer: NoQ.
Herald added a project: All.
merrymeerkat requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140483

Files:
  clang/docs/tools/clang-formatted-files.txt
  clang/include/clang/Analysis/AnalysisDiagnostic.h
  clang/include/clang/module.modulemap


Index: clang/include/clang/module.modulemap
===
--- clang/include/clang/module.modulemap
+++ clang/include/clang/module.modulemap
@@ -94,7 +94,6 @@
   requires cplusplus
 
   module All { header "Basic/AllDiagnostics.h" export * }
-  module Analysis { header "Analysis/AnalysisDiagnostic.h" export * }
   module AST { header "AST/ASTDiagnostic.h" export * }
   module Comment { header "AST/CommentDiagnostic.h" export * }
   module Driver { header "Driver/DriverDiagnostic.h" export * }
Index: clang/include/clang/Analysis/AnalysisDiagnostic.h
===
--- clang/include/clang/Analysis/AnalysisDiagnostic.h
+++ /dev/null
@@ -1,14 +0,0 @@
-//===--- DiagnosticAnalysis.h - Diagnostics for libanalysis -*- 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
-//
-//===--===//
-
-#ifndef LLVM_CLANG_ANALYSIS_ANALYSISDIAGNOSTIC_H
-#define LLVM_CLANG_ANALYSIS_ANALYSISDIAGNOSTIC_H
-
-#include "clang/Basic/DiagnosticAnalysis.h"
-
-#endif
Index: clang/docs/tools/clang-formatted-files.txt
===
--- clang/docs/tools/clang-formatted-files.txt
+++ clang/docs/tools/clang-formatted-files.txt
@@ -116,7 +116,6 @@
 clang/examples/Attribute/Attribute.cpp
 clang/examples/CallSuperAttribute/CallSuperAttrInfo.cpp
 clang/examples/PluginsOrder/PluginsOrder.cpp
-clang/include/clang/Analysis/AnalysisDiagnostic.h
 clang/include/clang/Analysis/BodyFarm.h
 clang/include/clang/Analysis/IssueHash.h
 clang/include/clang/Analysis/MacroExpansionContext.h


Index: clang/include/clang/module.modulemap
===
--- clang/include/clang/module.modulemap
+++ clang/include/clang/module.modulemap
@@ -94,7 +94,6 @@
   requires cplusplus
 
   module All { header "Basic/AllDiagnostics.h" export * }
-  module Analysis { header "Analysis/AnalysisDiagnostic.h" export * }
   module AST { header "AST/ASTDiagnostic.h" export * }
   module Comment { header "AST/CommentDiagnostic.h" export * }
   module Driver { header "Driver/DriverDiagnostic.h" export * }
Index: clang/include/clang/Analysis/AnalysisDiagnostic.h
===
--- clang/include/clang/Analysis/AnalysisDiagnostic.h
+++ /dev/null
@@ -1,14 +0,0 @@
-//===--- DiagnosticAnalysis.h - Diagnostics for libanalysis -*- 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
-//
-//===--===//
-
-#ifndef LLVM_CLANG_ANALYSIS_ANALYSISDIAGNOSTIC_H
-#define LLVM_CLANG_ANALYSIS_ANALYSISDIAGNOSTIC_H
-
-#include "clang/Basic/DiagnosticAnalysis.h"
-
-#endif
Index: clang/docs/tools/clang-formatted-files.txt
===
--- clang/docs/tools/clang-formatted-files.txt
+++ clang/docs/tools/clang-formatted-files.txt
@@ -116,7 +116,6 @@
 clang/examples/Attribute/Attribute.cpp
 clang/examples/CallSuperAttribute/CallSuperAttrInfo.cpp
 clang/examples/PluginsOrder/PluginsOrder.cpp
-clang/include/clang/Analysis/AnalysisDiagnostic.h
 clang/include/clang/Analysis/BodyFarm.h
 clang/include/clang/Analysis/IssueHash.h
 clang/include/clang/Analysis/MacroExpansionContext.h
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140467: [X86][Reduce] Preserve fast math flags when change it. NFCI

2022-12-21 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

In D140467#4010675 , @pengfei wrote:

> As I have explained, users are not suggested to use these builtins given we 
> have provided the more stable, well documented corresponding intrinsics. The 
> only case user has to use it is the intrinsic is missing. In that case, we do 
> need test case for it.

Tests don't exist for users, they exist for compiler developers. We shouldn't 
have frail infrastructure that depends on people not using things that are 
available. I'm not asking to test every builtin in this change, but this does 
need a test that shows a case where fast math flags were incorrectly applied. 
The broader issue of missing builtin coverage is a separate problem.

> In a word, as titled, it is NFC from the perspective of intrinsics. So I 
> think we don't need test cases for them.

This is not NFC. This changes codegen.

>> This test amounts to a builtin header test for immintrin.h. This should move 
>> to clang/test/Headers and replaced with a builtin test directly checking the 
>> builtin handling
>
> Not get your point. But currently no builtin tests under 
> `clang/test/Headers/`.

These "builtin tests" are checking wrappers implemented in a builtin header, 
not builtins. These are two levels of functionality that should be 
independently tested


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140467

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


[PATCH] D137107: Allow MS extension: support of constexpr with __declspec(dllimport).

2022-12-21 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam marked 3 inline comments as done.
zahiraam added inline comments.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:5006
+if (NeedsGlobalCtor || NeedsGlobalDtor)
+  DelayedCXXInitPosition[D] = ~0U;
+  } else {

efriedma wrote:
> zahiraam wrote:
> > Do you agree this should be done only when one of those flags is on?
> Yes, that's fine; I wasn't really paying close attention to the exact code.  
> Just wanted to make the point about the structure of the if statements, and 
> code was the easiest way to explain it.
> 
> Maybe the outer if statement should actually be `if (isStaticInit(D, 
> getLangOpts()) && NeedsGlobalCtor) {`.
> 
> On a related note, we might want to avoid the name "ctor", in case that 
> accidentally conflicts with some user code; an "__"-prefixed name would be 
> appropriate.
>> Maybe the outer if statement should actually be if (isStaticInit(D, 
>> getLangOpts()) && NeedsGlobalCtor) {
Not sure about that! There are cases where (isStaticInit(D, getLangOpts())) = 
true and NeedsGlobalCtor=false, but NeedsGlobalDtor=true. In which case a 
__dtor needs to be emitted, no?

Writing the condition as you are proposing would actually not get me into the 
body to emit the __dtor. Is that what we want?


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

https://reviews.llvm.org/D137107

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


[PATCH] D139266: Headers: tweak inclusion condition for stdatomic.h

2022-12-21 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

(and https://bugs.chromium.org/p/chromium/issues/detail?id=1402885#c3)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139266

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


  1   2   >