[PATCH] D133289: [C2X] N3007 Type inference for object definitions

2022-09-07 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

In D133289#3773708 , @to268 wrote:

> Also @aaron.ballman said me that he was thinking about maybe adding an 
> extension to add support for `auto` in a function return or in a parameter 
> list.

I think extensions are best left to a separate pr, if at all.
Supporting deduced return type sounds fine, with a warning.
Supporting auto template parameters... Not so much, as it would in effect bring 
function templates, overloading and mangling into C... I don't think we want to 
go there.

I think we should consider supporting auto in older language modes though.

Or at least, improving the diagnostics for auto in older language modes.

> type specifier missing, defaults to 'int'.

The probability that someone tries to use auto as a storage specifier and want 
an implicit int at the same time is about 0.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133289

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


[PATCH] D132918: [clang] Fix a crash in constant evaluation

2022-09-07 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

> This is helpful information but I am not sure this convinces me that 
> EvaluateVarDecl is the correct place to check. Why not in EvaluateDecl or 
> EvaluateStmt? Both locations we could also check.

I have done the check inside `EvaluateVarDecl` because the invalid evaluation 
happens when we try to analyze type of an invalid var decl.  
I don't know if it would be safe to say we shouldn't evaluate any invalid decl. 
e.g. `EvaluateDecl` returns true for any non-vardecl today, without checking 
for anything at all. I don't know if changing the contract there, let alone at 
the statement level, would be correct. but doing it inside the vardecl 
evaluation is **at least** correct, but might be redundant.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132918

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


[PATCH] D131465: C++/ObjC++: switch to gnu++17 as the default standard

2022-09-07 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Thanks for doing this, clangd change LGTM.




Comment at: clang-tools-extra/clangd/unittests/SelectionTests.cpp:726
   EXPECT_EQ("CXXConstructExpr", nodeKind(Str->Parent->Parent));
   EXPECT_EQ(Str, &Str->Parent->Parent->ignoreImplicit())
   << "Didn't unwrap " << nodeKind(&Str->Parent->Parent->ignoreImplicit());

Huh, i actually think something is wrong here (ignoreImplicit and outerImplicit 
seem to disagree on whether the CXXConstructExpr is implicit).

In any case, this is already wrong today in C++17 mode.
Would you mind adding `// FIXME: is CXXConstructExpr implicit or not` and I'll 
look at it later?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131465

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


[PATCH] D133405: [Linux] Hack around Linux/sparc

2022-09-07 Thread Rainer Orth via Phabricator via cfe-commits
ro created this revision.
ro added reviewers: glaubitz, MaskRay.
Herald added subscribers: StephenFan, fedor.sergeev, jyknight.
Herald added a project: All.
ro requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

I've been using this hack to work around the Linux/sparc64 compile failure 
described in Issue #47994 , 
especially since the underlying glibc PR build/27558 
 doesn't seem to be 
making progress and some fix is required to have LLVM build on 
`sparc64-unknown-linux-gnu` at all, as evidenced on the buildbot.

I don't expect this patch to be commited, just posting for reference.

Tested on `sparc64-unknown-linux-gnu`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133405

Files:
  clang/lib/Basic/Targets/OSTargets.h


Index: clang/lib/Basic/Targets/OSTargets.h
===
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -388,6 +388,8 @@
 } else {
 Builder.defineMacro("__gnu_linux__");
 }
+if (Triple.isSPARC())
+  Builder.defineMacro("__NO_INLINE__");
 if (Opts.POSIXThreads)
   Builder.defineMacro("_REENTRANT");
 if (Opts.CPlusPlus)


Index: clang/lib/Basic/Targets/OSTargets.h
===
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -388,6 +388,8 @@
 } else {
 Builder.defineMacro("__gnu_linux__");
 }
+if (Triple.isSPARC())
+  Builder.defineMacro("__NO_INLINE__");
 if (Opts.POSIXThreads)
   Builder.defineMacro("_REENTRANT");
 if (Opts.CPlusPlus)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D132918: [clang] Fix a crash in constant evaluation

2022-09-07 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision as: ilya-biryukov.
ilya-biryukov added a comment.

In D132918#3773237 , @shafik wrote:

> This is helpful information but I am not sure this convinces me that 
> `EvaluateVarDecl` is the correct place to check. Why not in `EvaluateDecl` or 
> `EvaluateStmt`? Both locations we could also check.

So the options are:

1. `assert(Decl->isValid())` in `EvaluateVarDecl` and checks at call sites in 
`EvaluateDecl` and `EvaluateStmt`.
2. a single check in `EvaluateVarDecl`.

The actual observable behavior of the compiler seems equivalent (`EvaluateDecl` 
can only fail inside `EvaluateVarDecl` anyway).
I think either is fine, neither of the approaches seems to be a big win over 
the other.

I will stamp this as I'm already in the reviewers list, think this change is ok 
and believe that Aaron's comments were addressed.
However, I still suggest to give time for @shafik to respond before landing 
this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132918

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


[PATCH] D133407: [Driver] Support non-canonical triples with new runtime lib layout

2022-09-07 Thread Rainer Orth via Phabricator via cfe-commits
ro created this revision.
ro added a reviewer: MaskRay.
ro added a project: clang.
Herald added subscribers: StephenFan, abidh, jrtc27, fedor.sergeev, 
kristof.beyls, jyknight.
Herald added a project: All.
ro requested review of this revision.

This is the companion patch to D133406 , 
intended to get the ideas of `clang` of `compiler-rt` where runtime libs are 
located with `-DLLVM_ENABLE_RUNTIMES` in sync.  Both patches were necessary to 
run the release builds/tests for Solaris/amd64 and Linux/sparc64.

Tested on `amd64-pc-solaris2.11` and `sparc64-unknown-linux-gnu`.

This patch is **not** ready for prime time: right now it causes two regressions:

  Clang :: Driver/baremetal.cpp
  Clang :: Driver/print-libgcc-file-name-clangrt.c

where the patched driver uses `-triple thumbv7m-vendor-none-eabi` instead of 
the expected `armv7m-vendor-none-eabi`.  I have not yet tried to investigate 
this in detail, just wanted to get the patch out for reference.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133407

Files:
  clang/lib/Driver/ToolChain.cpp
  clang/test/Driver/Inputs/debian_sparc64_tree/lib/sparc64-linux-gnu/Scrt1.o
  clang/test/Driver/Inputs/debian_sparc64_tree/lib/sparc64-linux-gnu/crti.o
  clang/test/Driver/Inputs/debian_sparc64_tree/lib/sparc64-linux-gnu/crtn.o
  
clang/test/Driver/Inputs/debian_sparc64_tree/usr/lib/gcc/sparc64-linux-gnu/12/crtbeginS.o
  
clang/test/Driver/Inputs/debian_sparc64_tree/usr/lib/gcc/sparc64-linux-gnu/12/crtendS.o
  
clang/test/Driver/Inputs/debian_sparc64_tree/usr/lib/gcc/sparc64-linux-gnu/12/libgcc.a
  
clang/test/Driver/Inputs/debian_sparc64_tree/usr/lib/gcc/sparc64-linux-gnu/12/libgcc_s.so
  clang/test/Driver/Inputs/debian_sparc64_tree/usr/lib/sparc64-linux-gnu/libc.so
  
clang/test/Driver/Inputs/debian_sparc64_tree/usr/lib/sparc64-linux-gnu/libdl.so
  clang/test/Driver/Inputs/debian_sparc64_tree/usr/lib/sparc64-linux-gnu/libm.so
  
clang/test/Driver/Inputs/debian_sparc64_tree/usr/lib/sparc64-linux-gnu/libpthread.so
  
clang/test/Driver/Inputs/debian_sparc64_tree/usr/lib/sparc64-linux-gnu/libresolv.so
  
clang/test/Driver/Inputs/debian_sparc64_tree/usr/lib/sparc64-linux-gnu/librt.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/sparcv9-unknown-linux-gnu/libclang_rt.ubsan_standalone.a
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-pc-solaris2.11/libclang_rt.ubsan_standalone.a
  clang/test/Driver/noncanon-per-target-runtime-dir.c
  clang/test/Driver/runtime-layout.c

Index: clang/test/Driver/runtime-layout.c
===
--- /dev/null
+++ clang/test/Driver/runtime-layout.c
@@ -0,0 +1,56 @@
+/// Check that clang's idea of runtime dir layout matches e.g. compiler-rt's.
+
+/// Classical runtime layout.
+// RUN: mkdir -p %t-classic/lib/sunos
+
+/// Canonical triple, 64-bit.
+// RUN: %clang -print-runtime-dir --target=x86_64-pc-solaris2.11 \
+// RUN:   -resource-dir=%t-classic \
+// RUN:   | FileCheck --check-prefix=RUNTIME-DIR-CLASSIC %s
+
+/// Non-canonical triple, 64-bit.
+// RUN: %clang -print-runtime-dir --target=amd64-pc-solaris2.11 \
+// RUN:   -resource-dir=%t-classic \
+// RUN:   | FileCheck --check-prefix=RUNTIME-DIR-CLASSIC %s
+
+/// Canonical triple, 32-bit.
+// RUN: %clang -print-runtime-dir --target=i386-pc-solaris2.11 \
+// RUN:   -resource-dir=%t-classic \
+// RUN:   | FileCheck --check-prefix=RUNTIME-DIR-CLASSIC %s
+
+/// Non-canonical triple, 32-bit.
+// RUN: %clang -print-runtime-dir --target=i686-pc-solaris2.11 \
+// RUN:   -resource-dir=%t-classic \
+// RUN:   | FileCheck --check-prefix=RUNTIME-DIR-CLASSIC %s
+
+// RUNTIME-DIR-CLASSIC: {{.*}}/lib/sunos
+
+/// New runtime layout.
+
+// RUN: mkdir -p %t-runtime/lib/x86_64-pc-solaris2.11
+
+/// Canonical triple, 64-bit.
+// RUN: %clang -print-runtime-dir --target=x86_64-pc-solaris2.11 \
+// RUN:   -resource-dir=%t-runtime \
+// RUN:   | FileCheck --check-prefix=RUNTIME-DIR-X86_64 %s
+
+/// Non-canonical triple, 64-bit.
+// RUN: %clang -print-runtime-dir --target=amd64-pc-solaris2.11 \
+// RUN:   -resource-dir=%t-runtime \
+// RUN:   | FileCheck --check-prefix=RUNTIME-DIR-X86_64 %s
+
+// RUNTIME-DIR-X86_64: {{.*}}/lib/x86_64-pc-solaris2.11
+
+// RUN: mkdir -p %t-runtime/lib/i386-pc-solaris2.11
+
+/// Canonical triple, 32-bit.
+// RUN: %clang -print-runtime-dir --target=i386-pc-solaris2.11 \
+// RUN:   -resource-dir=%t-runtime \
+// RUN:   | FileCheck --check-prefix=RUNTIME-DIR-I386 %s
+
+/// Non-canonical triple, 32-bit.
+// RUN: %clang -print-runtime-dir --target=i686-pc-solaris2.11 \
+// RUN:   -resource-dir=%t-runtime \
+// RUN:   | FileCheck --check-prefix=RUNTIME-DIR-I386 %s
+
+// RUNTIME-DIR-I386: {{.*}}/lib/i386-pc-solaris2.11
Index: clang/test/Driver/noncanon-per-target-runtime-dir.c
===
--- /dev/null
+++ clang/test/Driver/noncanon-per-target-runtime-dir.c
@@ -0,0 +1,20 @@
+/// Che

[PATCH] D133405: [Linux] Hack around Linux/sparc

2022-09-07 Thread John Paul Adrian Glaubitz via Phabricator via cfe-commits
glaubitz added a comment.

Thanks, this is definitely very useful. I have pinged glibc upstream and asked 
them about the progress about this change. Let' see.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133405

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


[PATCH] D132810: [clang][MinGW] Add `-mguard=cf` and `-mguard=cf-nochecks`

2022-09-07 Thread Alvin Wong via Phabricator via cfe-commits
alvinhochun updated this revision to Diff 458392.
alvinhochun added a comment.

Fixed `--target=` option for test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132810

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/MinGW.cpp
  clang/lib/Driver/ToolChains/MinGW.h
  clang/test/Driver/mingw-cfguard.c

Index: clang/test/Driver/mingw-cfguard.c
===
--- /dev/null
+++ clang/test/Driver/mingw-cfguard.c
@@ -0,0 +1,28 @@
+// RUN: %clang --target=x86_64-w64-windows-gnu -### %s 2>&1 | FileCheck -check-prefixes=NO_CF,DEFAULT %s
+// RUN: %clang --target=x86_64-w64-windows-gnu -### %s -mguard=none 2>&1 | FileCheck -check-prefixes=NO_CF,GUARD_NONE %s
+// NO_CF: "-cc1"
+// NO_CF-NOT: "-cfguard"
+// NO_CF-NOT: "-cfguard-no-checks"
+// NO_CF-NEXT: ld"
+// NO_CF-NOT: "--guard-cf"
+// DEFAULT-NOT: "--no-guard-cf"
+// GUARD_NONE-SAME: "--no-guard-cf"
+
+// RUN: %clang --target=x86_64-w64-windows-gnu -### %s -mguard=cf 2>&1 | FileCheck -check-prefix=GUARD_CF %s
+// GUARD_CF: "-cc1"
+// GUARD_CF-SAME: "-cfguard"
+// GUARD_CF-NEXT: ld"
+// GUARD_CF-SAME: "--guard-cf"
+// GUARD_CF-NOT: "--no-guard-cf"
+
+// RUN: %clang --target=x86_64-w64-windows-gnu -### %s -mguard=cf-nochecks 2>&1 | FileCheck -check-prefix=GUARD_NOCHECKS %s
+// GUARD_NOCHECKS: "-cc1"
+// GUARD_NOCHECKS-NOT: "-cfguard"
+// GUARD_NOCHECKS-SAME: "-cfguard-no-checks"
+// GUARD_NOCHECKS-NOT: "-cfguard"
+// GUARD_NOCHECKS-NEXT: ld"
+// GUARD_NOCHECKS-SAME: "--guard-cf"
+// GUARD_NOCHECKS-NOT: "--no-guard-cf"
+
+// RUN: %clang --target=x86_64-w64-windows-gnu -### %s -mguard=xxx 2>&1 | FileCheck -check-prefix=GUARD_UNKNOWN %s
+// GUARD_UNKNOWN: error: unsupported argument 'xxx' to option '--mguard='
Index: clang/lib/Driver/ToolChains/MinGW.h
===
--- clang/lib/Driver/ToolChains/MinGW.h
+++ clang/lib/Driver/ToolChains/MinGW.h
@@ -79,6 +79,10 @@
   void
   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
 llvm::opt::ArgStringList &CC1Args) const override;
+  void
+  addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
+llvm::opt::ArgStringList &CC1Args,
+Action::OffloadKind DeviceOffloadKind) const override;
   void AddClangCXXStdlibIncludeArgs(
   const llvm::opt::ArgList &DriverArgs,
   llvm::opt::ArgStringList &CC1Args) const override;
Index: clang/lib/Driver/ToolChains/MinGW.cpp
===
--- clang/lib/Driver/ToolChains/MinGW.cpp
+++ clang/lib/Driver/ToolChains/MinGW.cpp
@@ -169,6 +169,17 @@
   if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle))
 CmdArgs.push_back("--no-demangle");
 
+  if (Arg *A = Args.getLastArg(options::OPT_mguard_EQ)) {
+StringRef GuardArgs = A->getValue();
+if (GuardArgs == "none")
+  CmdArgs.push_back("--no-guard-cf");
+else if (GuardArgs == "cf" || GuardArgs == "cf-nochecks")
+  CmdArgs.push_back("--guard-cf");
+else
+  D.Diag(diag::err_drv_unsupported_option_argument)
+  << A->getSpelling() << GuardArgs;
+  }
+
   CmdArgs.push_back("-o");
   const char *OutputFile = Output.getFilename();
   // GCC implicitly adds an .exe extension if it is given an output file name
@@ -607,6 +618,26 @@
   addSystemInclude(DriverArgs, CC1Args, Base + "include");
 }
 
+void toolchains::MinGW::addClangTargetOptions(
+const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
+Action::OffloadKind DeviceOffloadKind) const {
+  if (Arg *A = DriverArgs.getLastArg(options::OPT_mguard_EQ)) {
+StringRef GuardArgs = A->getValue();
+if (GuardArgs == "none") {
+  // Do nothing.
+} else if (GuardArgs == "cf") {
+  // Emit CFG instrumentation and the table of address-taken functions.
+  CC1Args.push_back("-cfguard");
+} else if (GuardArgs == "cf-nochecks") {
+  // Emit only the table of address-taken functions.
+  CC1Args.push_back("-cfguard-no-checks");
+} else {
+  getDriver().Diag(diag::err_drv_unsupported_option_argument)
+  << A->getSpelling() << GuardArgs;
+}
+  }
+}
+
 void toolchains::MinGW::AddClangCXXStdlibIncludeArgs(
 const ArgList &DriverArgs, ArgStringList &CC1Args) const {
   if (DriverArgs.hasArg(options::OPT_nostdlibinc) ||
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3360,6 +3360,9 @@
 def mdll : Joined<["-"], "mdll">, Group, Flags<[NoXarchOption]>;
 def municode : Joined<["-"], "municode">, Group, Flags<[NoXarchOption]>;
 def mthreads : Joined<["-"], "mthreads">, Group, Flags<[NoXarchOption]>;
+def mguard_EQ : Joined<["-"], "mguard=">, Group, Flags<[No

[clang] 98a3a34 - [ConstantExpr] Don't create fneg expressions

2022-09-07 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2022-09-07T11:27:25+02:00
New Revision: 98a3a340c3612c06c51d7bb36bfc5857ab06a951

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

LOG: [ConstantExpr] Don't create fneg expressions

Don't create fneg expressions unless explicitly requested by IR or
bitcode.

Added: 


Modified: 
clang/test/CodeGen/constantexpr-fneg.c
llvm/include/llvm/Analysis/TargetFolder.h
llvm/include/llvm/IR/ConstantFolder.h
llvm/lib/Analysis/ConstantFolding.cpp
llvm/test/Transforms/InstCombine/fmul.ll
llvm/test/Transforms/InstCombine/fneg.ll
llvm/test/Transforms/Reassociate/crash2.ll

Removed: 




diff  --git a/clang/test/CodeGen/constantexpr-fneg.c 
b/clang/test/CodeGen/constantexpr-fneg.c
index 17873345daee7..7fc78cfebf8f3 100644
--- a/clang/test/CodeGen/constantexpr-fneg.c
+++ b/clang/test/CodeGen/constantexpr-fneg.c
@@ -2,8 +2,7 @@
 // RUN: llvm-dis %t.bc -o - | FileCheck %s
 
 // Test case for PR45426. Make sure we do not crash while writing bitcode
-// containing a simplify-able fneg constant expression. Check that the created
-// bitcode file can be disassembled and has the constant expressions 
simplified.
+// containing a simplify-able fneg constant expression.
 //
 // CHECK-LABEL define i32 @main()
 // CHECK:  entry:
@@ -11,7 +10,9 @@
 // CHECK-NEXT:   store i32 0, i32* %retval
 // CHECK-NEXT:   [[LV:%.*]] = load float*, float** @c
 // CHECK-NEXT:   store float 1.00e+00, float* [[LV]], align 4
-// CHECK-NEXT:   ret i32 -1
+// CHECK-NEXT:   [[FNEG:%.*]] = fneg float 1.00e+00
+// CHECK-NEXT:   [[CONV:%.*]] = fptosi float [[FNEG]] to i32
+// CHECK-NEXT:   ret i32 [[CONV]]
 
 int a[], b;
 float *c;

diff  --git a/llvm/include/llvm/Analysis/TargetFolder.h 
b/llvm/include/llvm/Analysis/TargetFolder.h
index c42577330e9b4..db7eda54b5c45 100644
--- a/llvm/include/llvm/Analysis/TargetFolder.h
+++ b/llvm/include/llvm/Analysis/TargetFolder.h
@@ -110,7 +110,7 @@ class TargetFolder final : public IRBuilderFolder {
   Value *FoldUnOpFMF(Instruction::UnaryOps Opc, Value *V,
   FastMathFlags FMF) const override {
 if (Constant *C = dyn_cast(V))
-  return Fold(ConstantExpr::get(Opc, C));
+  return ConstantFoldUnaryOpOperand(Opc, C, DL);
 return nullptr;
   }
 

diff  --git a/llvm/include/llvm/IR/ConstantFolder.h 
b/llvm/include/llvm/IR/ConstantFolder.h
index bd28ff87965dd..82c07d47a1930 100644
--- a/llvm/include/llvm/IR/ConstantFolder.h
+++ b/llvm/include/llvm/IR/ConstantFolder.h
@@ -91,7 +91,7 @@ class ConstantFolder final : public IRBuilderFolder {
   Value *FoldUnOpFMF(Instruction::UnaryOps Opc, Value *V,
   FastMathFlags FMF) const override {
 if (Constant *C = dyn_cast(V))
-  return ConstantExpr::get(Opc, C);
+  return ConstantFoldUnaryInstruction(Opc, C);
 return nullptr;
   }
 

diff  --git a/llvm/lib/Analysis/ConstantFolding.cpp 
b/llvm/lib/Analysis/ConstantFolding.cpp
index 9187d49ca7a5a..df1a9bfa3da27 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -1333,7 +1333,7 @@ Constant *llvm::ConstantFoldUnaryOpOperand(unsigned 
Opcode, Constant *Op,
const DataLayout &DL) {
   assert(Instruction::isUnaryOp(Opcode));
 
-  return ConstantExpr::get(Opcode, Op);
+  return ConstantFoldUnaryInstruction(Opcode, Op);
 }
 
 Constant *llvm::ConstantFoldBinaryOpOperands(unsigned Opcode, Constant *LHS,

diff  --git a/llvm/test/Transforms/InstCombine/fmul.ll 
b/llvm/test/Transforms/InstCombine/fmul.ll
index 10c8bdd532817..981e26c4912bf 100644
--- a/llvm/test/Transforms/InstCombine/fmul.ll
+++ b/llvm/test/Transforms/InstCombine/fmul.ll
@@ -1057,7 +1057,8 @@ define float @fmul_fdiv_factor_extra_use(float %x, float 
%y) {
 
 define double @fmul_negated_constant_expression(double %x) {
 ; CHECK-LABEL: @fmul_negated_constant_expression(
-; CHECK-NEXT:[[R:%.*]] = fmul double [[X:%.*]], fneg (double bitcast (i64 
ptrtoint (i8** getelementptr inbounds ({ [2 x i8*] }, { [2 x i8*] }* @g, i64 0, 
inrange i32 0, i64 2) to i64) to double))
+; CHECK-NEXT:[[FSUB:%.*]] = fneg double bitcast (i64 ptrtoint (i8** 
getelementptr inbounds ({ [2 x i8*] }, { [2 x i8*] }* @g, i64 0, inrange i32 0, 
i64 2) to i64) to double)
+; CHECK-NEXT:[[R:%.*]] = fmul double [[FSUB]], [[X:%.*]]
 ; CHECK-NEXT:ret double [[R]]
 ;
   %fsub = fsub double -0.00e+00, bitcast (i64 ptrtoint (i8** getelementptr 
inbounds ({ [2 x i8*] }, { [2 x i8*] }* @g, i64 0, inrange i32 0, i64 2) to 
i64) to double)

diff  --git a/llvm/test/Transforms/InstCombine/fneg.ll 
b/llvm/test/Transforms/InstCombine/fneg.ll
index c08ac44e34130..08ced4018483b 100644
--- a/llvm/test/Transforms/InstCombine/fneg.ll
+++ b/llvm/test/Transforms/InstCombine/

[PATCH] D132003: [clang][ARM][NFC] Clean up signed conversion and undefined macros in builtin header

2022-09-07 Thread Tomas Matheson via Phabricator via cfe-commits
tmatheson added inline comments.



Comment at: clang/lib/Headers/arm_acle.h:219
 __revsh(int16_t __t) {
-  return __builtin_bswap16(__t);
+  return (int16_t)__builtin_bswap16((int16_t)__t);
 }

Should the second cast be (uint16_t)__t?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132003

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


[PATCH] D132797: [clangd] Support renaming virtual methods

2022-09-07 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

A few more NITs from me, but please wait for @sammccall for another round of 
reviews.




Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:550
+// method.
+void recursivelyInsertOverrides(SymbolID Base, llvm::DenseSet &IDs,
+const SymbolIndex &Index) {

NIT: maybe rename to `insertTransitiveOverrides`?
This function is not recursive anymore and "transitive" seems to be a more 
precise term for describing the results of running this function.



Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:561-562
+Index.relations(Req, [&](const SymbolID &, const Symbol &Override) {
+  IDs.insert(Override.ID);
+  Pending.insert(Override.ID);
+});

This should protect against infinite loop in case of broken/stale index.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132797

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


[PATCH] D133202: [Clang] Avoid __builtin_assume_aligned crash when the 1st arg is array type

2022-09-07 Thread Lin Yurong via Phabricator via cfe-commits
yronglin updated this revision to Diff 458403.
yronglin retitled this revision from "[Clang][CodeGen] Avoid 
__builtin_assume_aligned crash when the 1st arg is array type" to "[Clang] 
Avoid __builtin_assume_aligned crash when the 1st arg is array type".

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133202

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/catch-alignment-assumption-array.c
  clang/test/CodeGen/catch-alignment-assumption-ignorelist.c
  clang/test/Sema/builtin-assume-aligned.c

Index: clang/test/Sema/builtin-assume-aligned.c
===
--- clang/test/Sema/builtin-assume-aligned.c
+++ clang/test/Sema/builtin-assume-aligned.c
@@ -66,6 +66,11 @@
 }
 #endif
 
+int test13(int *a) {
+  a = (int *)__builtin_assume_aligned(a, 2 * 2.0); // expected-error {{argument to '__builtin_assume_aligned' must be a constant integer}}
+  return a[0];
+}
+
 void test_void_assume_aligned(void) __attribute__((assume_aligned(32))); // expected-warning {{'assume_aligned' attribute only applies to return values that are pointers}}
 int test_int_assume_aligned(void) __attribute__((assume_aligned(16))); // expected-warning {{'assume_aligned' attribute only applies to return values that are pointers}}
 void *test_ptr_assume_aligned(void) __attribute__((assume_aligned(64))); // no-warning
Index: clang/test/CodeGen/catch-alignment-assumption-ignorelist.c
===
--- clang/test/CodeGen/catch-alignment-assumption-ignorelist.c
+++ clang/test/CodeGen/catch-alignment-assumption-ignorelist.c
@@ -26,3 +26,9 @@
 void *ignore_volatiles(volatile void * x) {
   return __builtin_assume_aligned(x, 1);
 }
+
+// CHECK-LABEL: ignore_array_volatiles
+void *ignore_array_volatiles() {
+  volatile int arr[] = {1};
+  return __builtin_assume_aligned(arr, 4);
+}
Index: clang/test/CodeGen/catch-alignment-assumption-array.c
===
--- /dev/null
+++ clang/test/CodeGen/catch-alignment-assumption-array.c
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -no-opaque-pointers -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s
+// RUN: %clang_cc1 -no-opaque-pointers -fsanitize=alignment -fno-sanitize-recover=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-ANYRECOVER,CHECK-SANITIZE-NORECOVER,CHECK-SANITIZE-UNREACHABLE
+// RUN: %clang_cc1 -no-opaque-pointers -fsanitize=alignment -fsanitize-recover=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-ANYRECOVER,CHECK-SANITIZE-RECOVER
+// RUN: %clang_cc1 -no-opaque-pointers -fsanitize=alignment -fsanitize-trap=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-TRAP,CHECK-SANITIZE-UNREACHABLE
+
+// CHECK-SANITIZE-ANYRECOVER: @[[CHAR:.*]] = {{.*}} c"'char *'\00" }
+// CHECK-SANITIZE-ANYRECOVER: @[[ALIGNMENT_ASSUMPTION:.*]] = {{.*}}, i32 31, i32 35 }, {{.*}}* @[[CHAR]] }
+
+void *caller(void) {
+  char str[] = "";
+  // CHECK:   define{{.*}}
+  // CHECK-NEXT:  entry:
+  // CHECK-NEXT:%[[STR:.*]] = alloca [1 x i8], align 1
+  // CHECK-NEXT:%[[BITCAST:.*]] = bitcast [1 x i8]* %[[STR]] to i8*
+  // CHECK-NEXT:call void @llvm.memset.p0i8.i64(i8* align 1 %[[BITCAST]], i8 0, i64 1, i1 false)
+  // CHECK-NEXT:%[[ARRAYDECAY:.*]] = getelementptr inbounds [1 x i8], [1 x i8]* %[[STR]], i64 0, i64 0
+  // CHECK-SANITIZE-NEXT:   %[[PTRINT:.*]] = ptrtoint i8* %[[ARRAYDECAY]] to i64
+  // CHECK-SANITIZE-NEXT:   %[[MASKEDPTR:.*]] = and i64 %[[PTRINT]], 0
+  // CHECK-SANITIZE-NEXT:   %[[MASKCOND:.*]] = icmp eq i64 %[[MASKEDPTR]], 0
+  // CHECK-SANITIZE-NEXT:   %[[PTRINT_DUP:.*]] = ptrtoint i8* %[[ARRAYDECAY]] to i64, !nosanitize
+  // CHECK-SANITIZE-NEXT:   br i1 %[[MASKCOND]], label %[[CONT:.*]], label %[[HANDLER_ALIGNMENT_ASSUMPTION:[^,]+]],{{.*}} !nosanitize
+  // CHECK-SANITIZE:  [[HANDLER_ALIGNMENT_ASSUMPTION]]:
+  // CHECK-SANITIZE-NORECOVER-NEXT: call void @__ubsan_handle_alignment_assumption_abort(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 1, i64 0){{.*}}, !nosanitize
+  // CHECK-SANITIZE-RECOVER-NEXT:   call void @__ubsan_handle_alignment_assumption(i8

[PATCH] D113779: [Clang] Add mfp16, mfp16fml and mdotprod flags for ARM target features.

2022-09-07 Thread Florian Hahn via Phabricator via cfe-commits
fhahn updated this revision to Diff 458407.
fhahn added a comment.

Rebase and ping :)

The potential benefit of having -m flags is also mentioned in this recent bug 
report: https://github.com/llvm/llvm-project/issues/57588


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113779

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  clang/lib/Driver/ToolChains/Arch/ARM.cpp
  clang/test/Preprocessor/aarch64-target-features.c
  clang/test/Preprocessor/arm-target-features.c

Index: clang/test/Preprocessor/arm-target-features.c
===
--- clang/test/Preprocessor/arm-target-features.c
+++ clang/test/Preprocessor/arm-target-features.c
@@ -25,6 +25,7 @@
 // CHECK-V8A-ALLOW-FP-INSTR-V8A-NOT: #define __ARM_FEATURE_DOTPROD
 
 // RUN: %clang -target arm-none-linux-gnueabi -march=armv8.2-a+nofp16fml+fp16 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s
+// RUN: %clang -target arm-none-linux-gnueabi -march=armv8.2-a -mnofp16fml -mfp16 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s
 // RUN: %clang -target arm-none-linux-gnueabi -march=armv8.2-a+nofp16+fp16fml -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s
 // RUN: %clang -target arm-none-linux-gnueabi -march=armv8.2-a+fp16+nofp16fml -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s
 // RUN: %clang -target arm-none-linux-gnueabi -march=armv8-a+fp16fml -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s
@@ -77,6 +78,7 @@
 // CHECK-FULLFP16-SOFT-NOT: #define __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
 
 // RUN: %clang -target arm-none-linux-gnueabi -march=armv8.2a+dotprod -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-DOTPROD %s
+// RUN: %clang -target arm-none-linux-gnueabi -march=armv8.2a -mdotprod -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-DOTPROD %s
 // CHECK-DOTPROD: #define __ARM_FEATURE_DOTPROD 1
 
 // RUN: %clang -target armv8r-none-linux-gnu -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V8R %s
Index: clang/test/Preprocessor/aarch64-target-features.c
===
--- clang/test/Preprocessor/aarch64-target-features.c
+++ clang/test/Preprocessor/aarch64-target-features.c
@@ -200,20 +200,29 @@
 // CHECK-SVE2BITPERM: __ARM_FEATURE_SVE2_BITPERM 1
 
 // RUN: %clang -target aarch64-none-linux-gnu -march=armv8.2a+dotprod -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-DOTPROD %s
+// RUN: %clang -target aarch64-none-linux-gnu -march=armv8.2a -mdotprod -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-DOTPROD %s
 // CHECK-DOTPROD: __ARM_FEATURE_DOTPROD 1
 
 // On ARMv8.2-A and above, +fp16fml implies +fp16.
 // On ARMv8.4-A and above, +fp16 implies +fp16fml.
 // RUN: %clang -target aarch64-none-linux-gnueabi -march=armv8.2-a+nofp16fml+fp16 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-NOFML --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s
+// RUN: %clang -target aarch64-none-linux-gnueabi -march=armv8.2-a -mnofp16fml -mfp16 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-NOFML --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s
 // RUN: %clang -target aarch64-none-linux-gnueabi -march=armv8.2-a+nofp16+fp16fml -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-FML --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s
+// RUN: %clang -target aarch64-none-linux-gnueabi -march=armv8.2-a -mnofp16 -mfp16fml -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-FML --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s
 // RUN: %clang -target aarch64-none-linux-gnueabi -march=armv8.2-a+fp16+nofp16fml -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-NOFML --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s
+// RUN: %clang -target aarch64-none-linux-gnueabi -march=armv8.2-a -mfp16 -mnofp16fml -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-NOFML --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s
 // RUN: %clang -target aarch64-none-linux-gnueabi -march=armv8-a+fp16fml -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-FML --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s
+// RUN: %clang -target aarch64-none-linux-gnueabi -march=armv8-a -mfp16fml -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-FML --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s
 // RUN: %clang -target aarch64-none-linux-gnueabi -march=armv8-a+fp16 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-NOFML --check-prefix=CHECK-FULLFP1

[PATCH] D133102: [clang-tidy] Extend simplify-boolean-expr check

2022-09-07 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh requested changes to this revision.
alexfh added a comment.
This revision now requires changes to proceed.

FWIW, I'm not sure this will usually be a simplification of the code. Splitting 
the condition and using early return is quite a frequent recommendation in code 
reviews, and I would expect a strong pushback to automated suggestions going in 
the opposite direction.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133102

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


[PATCH] D132797: [clangd] Support renaming virtual methods

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

LG

IIRC Tom doesn't have commit access, so I'll apply the last trivial changes and 
commit to avoid another round trip.
(Please LMK if i'm wrong about this!)




Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:561-562
+Index.relations(Req, [&](const SymbolID &, const Symbol &Override) {
+  IDs.insert(Override.ID);
+  Pending.insert(Override.ID);
+});

ilya-biryukov wrote:
> This should protect against infinite loop in case of broken/stale index.
Good catch!



Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:245
   trace::Span Tracer("FindOccurrencesWithinFile");
   assert(canonicalRenameDecl(&ND) == &ND &&
  "ND should be already canonicalized.");

tom-anders wrote:
> sammccall wrote:
> > Unfortunately we've uncovered a bug: this assertion fires (after this 
> > patch) on the following code:
> > 
> > ```
> > template  class Foo { virtual void m(); };
> > class Bar : Foo { void ^m() override; };
> > ```
> > 
> > `canonicalRenameDecl` is supposed to be idempotent. 
> > However:`canonicalRenameDecl(Bar::m)` is `Foo::m`, but 
> > `canonicalRenameDecl(Foo::m)` is `Foo::m`.
> > 
> > I think this is because the `getInstantiatedFromMemberFunction` check comes 
> > before the `overridden_methods` check, so if the override points to a 
> > member of an instantiation then it's too late to map it back to the member 
> > of the template.
> > 
> > Probably the best fix is to change line 103 to a recursive `return 
> > canonicalRenameDecl(...)`, as is done elsewhere in the function.
> > 
> > (Can you please add this case to the tests?)
> I added the test case for this. However, your suggested fix doesn't seem to 
> stop the assertion from being triggered. I'd be grateful if you can take a 
> closer look at this in a separate review - Should I leave the test case in 
> anyway? Is it okay if the test fails for a while until you found the fix?
Thanks for adding the test, and sorry about the bad guess at a fix. We can't 
turn the buildbots red, so I'll comment out the test and fix+enable it 
separately.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132797

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


[clang-tools-extra] 8019b46 - [clangd] Support renaming virtual methods

2022-09-07 Thread Sam McCall via cfe-commits

Author: Tom Praschan
Date: 2022-09-07T13:15:50+02:00
New Revision: 8019b46bc70b15cf5551ffcf494c6df17d1e7437

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

LOG: [clangd] Support renaming virtual methods

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

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

Added: 


Modified: 
clang-tools-extra/clangd/refactor/Rename.cpp
clang-tools-extra/clangd/unittests/RenameTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/refactor/Rename.cpp 
b/clang-tools-extra/clangd/refactor/Rename.cpp
index af454f0a372b..6358a05667bd 100644
--- a/clang-tools-extra/clangd/refactor/Rename.cpp
+++ b/clang-tools-extra/clangd/refactor/Rename.cpp
@@ -214,13 +214,6 @@ llvm::Optional renameable(const NamedDecl 
&RenameDecl,
   IsMainFileOnly))
 return ReasonToReject::NonIndexable;
 
-
-  // FIXME: Renaming virtual methods requires to rename all overridens in
-  // subclasses, our index doesn't have this information.
-  if (const auto *S = llvm::dyn_cast(&RenameDecl)) {
-if (S->isVirtual())
-  return ReasonToReject::UnsupportedSymbol;
-  }
   return None;
 }
 
@@ -551,6 +544,26 @@ Range toRange(const SymbolLocation &L) {
   return R;
 }
 
+// Walk down from a virtual method to overriding methods, we rename them as a
+// group. Note that canonicalRenameDecl() ensures we're starting from the base
+// method.
+void insertTransitiveOverrides(SymbolID Base, llvm::DenseSet &IDs,
+   const SymbolIndex &Index) {
+  RelationsRequest Req;
+  Req.Predicate = RelationKind::OverriddenBy;
+
+  llvm::DenseSet Pending = {Base};
+  while (!Pending.empty()) {
+Req.Subjects = std::move(Pending);
+Pending.clear();
+
+Index.relations(Req, [&](const SymbolID &, const Symbol &Override) {
+  if (IDs.insert(Override.ID).second)
+Pending.insert(Override.ID);
+});
+  }
+}
+
 // Return all rename occurrences (using the index) outside of the main file,
 // grouped by the absolute file path.
 llvm::Expected>>
@@ -561,6 +574,10 @@ findOccurrencesOutsideFile(const NamedDecl &RenameDecl,
   RefsRequest RQuest;
   RQuest.IDs.insert(getSymbolID(&RenameDecl));
 
+  if (const auto *MethodDecl = llvm::dyn_cast(&RenameDecl))
+if (MethodDecl->isVirtual())
+  insertTransitiveOverrides(*RQuest.IDs.begin(), RQuest.IDs, Index);
+
   // Absolute file path => rename occurrences in that file.
   llvm::StringMap> AffectedFiles;
   bool HasMore = Index.refs(RQuest, [&](const Ref &R) {

diff  --git a/clang-tools-extra/clangd/unittests/RenameTests.cpp 
b/clang-tools-extra/clangd/unittests/RenameTests.cpp
index 70b0bbc8f073..451ec3723469 100644
--- a/clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ b/clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -886,12 +886,6 @@ TEST(RenameTest, Renameable) {
  @end
)cpp",
"not a supported kind", HeaderFile},
-  {R"cpp(// FIXME: rename virtual/override methods is not supported yet.
- struct A {
-  virtual void f^oo() {}
- };
-  )cpp",
-   "not a supported kind", !HeaderFile},
   {R"cpp(
  void foo(int);
  void foo(char);
@@ -1490,6 +1484,48 @@ TEST(CrossFileRenameTests, WithUpToDateIndex) {
 }
   )cpp",
   },
+  {
+  // virtual methods.
+  R"cpp(
+class Base {
+  virtual void [[foo]]();
+};
+class Derived1 : public Base {
+  void [[f^oo]]() override;
+};
+class NotDerived {
+  void foo() {};
+}
+  )cpp",
+  R"cpp(
+#include "foo.h"
+void Base::[[foo]]() {}
+void Derived1::[[foo]]() {}
+
+class Derived2 : public Derived1 {
+  void [[foo]]() override {};
+};
+
+void func(Base* b, Derived1* d1, 
+  Derived2* d2, NotDerived* nd) {
+  b->[[foo]]();
+  d1->[[foo]]();
+  d2->[[foo]]();
+  nd->foo();
+}
+  )cpp",
+  },
+  // FIXME: triggers an assertion failure due to a bug in canonicalization.
+  // See https://reviews.llvm.org/D132797
+#if 0
+  {
+  // virtual templated method
+  R"cpp(
+template  class Foo { virtual void [[m]](); };
+class Bar : Foo { void [[^m]]() override; };
+  )cpp", ""
+  },
+#endif
   {
   // rename on constructor and destructor.
   R"cpp(



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


[PATCH] D132797: [clangd] Support renaming virtual methods

2022-09-07 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.
Closed by commit rG8019b46bc70b: [clangd] Support renaming virtual methods 
(authored by tom-anders, committed by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D132797?vs=458270&id=458415#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132797

Files:
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/unittests/RenameTests.cpp

Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -886,12 +886,6 @@
  @end
)cpp",
"not a supported kind", HeaderFile},
-  {R"cpp(// FIXME: rename virtual/override methods is not supported yet.
- struct A {
-  virtual void f^oo() {}
- };
-  )cpp",
-   "not a supported kind", !HeaderFile},
   {R"cpp(
  void foo(int);
  void foo(char);
@@ -1490,6 +1484,48 @@
 }
   )cpp",
   },
+  {
+  // virtual methods.
+  R"cpp(
+class Base {
+  virtual void [[foo]]();
+};
+class Derived1 : public Base {
+  void [[f^oo]]() override;
+};
+class NotDerived {
+  void foo() {};
+}
+  )cpp",
+  R"cpp(
+#include "foo.h"
+void Base::[[foo]]() {}
+void Derived1::[[foo]]() {}
+
+class Derived2 : public Derived1 {
+  void [[foo]]() override {};
+};
+
+void func(Base* b, Derived1* d1, 
+  Derived2* d2, NotDerived* nd) {
+  b->[[foo]]();
+  d1->[[foo]]();
+  d2->[[foo]]();
+  nd->foo();
+}
+  )cpp",
+  },
+  // FIXME: triggers an assertion failure due to a bug in canonicalization.
+  // See https://reviews.llvm.org/D132797
+#if 0
+  {
+  // virtual templated method
+  R"cpp(
+template  class Foo { virtual void [[m]](); };
+class Bar : Foo { void [[^m]]() override; };
+  )cpp", ""
+  },
+#endif
   {
   // rename on constructor and destructor.
   R"cpp(
Index: clang-tools-extra/clangd/refactor/Rename.cpp
===
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -214,13 +214,6 @@
   IsMainFileOnly))
 return ReasonToReject::NonIndexable;
 
-
-  // FIXME: Renaming virtual methods requires to rename all overridens in
-  // subclasses, our index doesn't have this information.
-  if (const auto *S = llvm::dyn_cast(&RenameDecl)) {
-if (S->isVirtual())
-  return ReasonToReject::UnsupportedSymbol;
-  }
   return None;
 }
 
@@ -551,6 +544,26 @@
   return R;
 }
 
+// Walk down from a virtual method to overriding methods, we rename them as a
+// group. Note that canonicalRenameDecl() ensures we're starting from the base
+// method.
+void insertTransitiveOverrides(SymbolID Base, llvm::DenseSet &IDs,
+   const SymbolIndex &Index) {
+  RelationsRequest Req;
+  Req.Predicate = RelationKind::OverriddenBy;
+
+  llvm::DenseSet Pending = {Base};
+  while (!Pending.empty()) {
+Req.Subjects = std::move(Pending);
+Pending.clear();
+
+Index.relations(Req, [&](const SymbolID &, const Symbol &Override) {
+  if (IDs.insert(Override.ID).second)
+Pending.insert(Override.ID);
+});
+  }
+}
+
 // Return all rename occurrences (using the index) outside of the main file,
 // grouped by the absolute file path.
 llvm::Expected>>
@@ -561,6 +574,10 @@
   RefsRequest RQuest;
   RQuest.IDs.insert(getSymbolID(&RenameDecl));
 
+  if (const auto *MethodDecl = llvm::dyn_cast(&RenameDecl))
+if (MethodDecl->isVirtual())
+  insertTransitiveOverrides(*RQuest.IDs.begin(), RQuest.IDs, Index);
+
   // Absolute file path => rename occurrences in that file.
   llvm::StringMap> AffectedFiles;
   bool HasMore = Index.refs(RQuest, [&](const Ref &R) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133102: [clang-tidy] Extend simplify-boolean-expr check

2022-09-07 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

For example, LLVM coding standards recommends using early exits: 
https://llvm.org/docs/CodingStandards.html#use-early-exits-and-continue-to-simplify-code


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133102

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


[PATCH] D132797: [clangd] Support renaming virtual methods

2022-09-07 Thread Tom Praschan via Phabricator via cfe-commits
tom-anders added a comment.

In D132797#3774138 , @sammccall wrote:

> LG
>
> IIRC Tom doesn't have commit access, so I'll apply the last trivial changes 
> and commit to avoid another round trip.
> (Please LMK if i'm wrong about this!)

I actually have commit access now, but thanks :) looking forward to your 
follow-up


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132797

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


[PATCH] D133413: [clang-tidy] Fix crashes on `if consteval` in readability checks

2022-09-07 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel created this revision.
rymiel added reviewers: njames93, LegalizeAdulthood, aaron.ballman, gribozavr2.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a project: All.
rymiel requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

The `readability-braces-around-statement` check tries to look at the
closing parens of the if condition to determine where to insert braces,
however, "consteval if" statements don't have a condition, and always
have braces regardless, so the skip can be checked.

The `readability-simplify-boolean-expr` check looks at the condition
of the if statement to determine what could be simplified, but as
"consteval if" statements do not have a condition that could be
simplified, they can also be skipped here.

There may still be more checks that try to look at the conditions of
`if`s that aren't included here

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133413

Files:
  clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
  clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability/braces-around-statements-consteval-if.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability/simplify-bool-expr-cxx23.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/simplify-bool-expr-cxx23.cpp
===
--- /dev/null
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/simplify-bool-expr-cxx23.cpp
@@ -0,0 +1,13 @@
+// RUN: clang-tidy %s -checks='-*,readability-simplify-boolean-expr' -- 
-std=c++2b | count 0
+template 
+constexpr int foo() {
+  if consteval {
+if constexpr (Cond) {
+  return 0;
+} else {
+  return 1;
+}
+  } else {
+return 2;
+  }
+}
Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/braces-around-statements-consteval-if.cpp
===
--- /dev/null
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/braces-around-statements-consteval-if.cpp
@@ -0,0 +1,31 @@
+// RUN: clang-tidy %s -checks='-*,readability-braces-around-statements' -- 
-std=c++2b | count 0
+
+constexpr void handle(bool) {}
+
+constexpr void shouldPass() {
+  if consteval {
+handle(true);
+  } else {
+handle(false);
+  }
+}
+
+constexpr void shouldPassNegated() {
+  if !consteval {
+handle(false);
+  } else {
+handle(true);
+  }
+}
+
+constexpr void shouldPassSimple() {
+  if consteval {
+handle(true);
+  }
+}
+
+void run() {
+shouldPass();
+shouldPassNegated();
+shouldPassSimple();
+}
Index: clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
@@ -354,8 +354,9 @@
   }
 
   bool VisitIfStmt(IfStmt *If) {
-// Skip any if's that have a condition var or an init statement.
-if (If->hasInitStorage() || If->hasVarStorage())
+// Skip any if's that have a condition var or an init statement, or are
+// "if consteval" statements.
+if (If->hasInitStorage() || If->hasVarStorage() || If->isConsteval())
   return true;
 /*
  * if (true) ThenStmt(); -> ThenStmt();
Index: clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
@@ -131,6 +131,10 @@
   return;
 checkStmt(Result, S->getBody(), StartLoc);
   } else if (const auto *S = Result.Nodes.getNodeAs("if")) {
+// "if consteval" always has braces.
+if (S->isConsteval())
+  return;
+
 SourceLocation StartLoc = findRParenLoc(S, SM, Context);
 if (StartLoc.isInvalid())
   return;


Index: clang-tools-extra/test/clang-tidy/checkers/readability/simplify-bool-expr-cxx23.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability/simplify-bool-expr-cxx23.cpp
@@ -0,0 +1,13 @@
+// RUN: clang-tidy %s -checks='-*,readability-simplify-boolean-expr' -- -std=c++2b | count 0
+template 
+constexpr int foo() {
+  if consteval {
+if constexpr (Cond) {
+  return 0;
+} else {
+  return 1;
+}
+  } else {
+return 2;
+  }
+}
Index: clang-tools-extra/test/clang-tidy/checkers/readability/braces-around-statements-consteval-if.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability/braces-around-statements-consteval-if.cpp
@@ -0,

[PATCH] D53847: [C++2a] P0634r3: Down with typename!

2022-09-07 Thread James Y Knight via Phabricator via cfe-commits
jyknight added a comment.

>> Also, do you know if having posted this patch is agreement for licensing 
>> this code? Or do we need to get explicit agreement from the original author 
>> before committing a version of this?
>
> I've never seen that be an issue before, and I don't see enough in 
> https://llvm.org/docs/DeveloperPolicy.html#copyright-license-and-patents to 
> be clear about the answer to that.  @tstellar could perhaps answer.

Contributing the patch to phab was agreement to contribute to llvm under the 
llvm license, you do not need further permission to take over and finish and 
commit a patch from phab. Per the standard apache2 terms in the llvm license, 
"Unless You explicitly state otherwise, any Contribution intentionally 
submitted for inclusion in the Work by You to the Licensor shall be under the 
terms and conditions of this License, without any additional terms or 
conditions."


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D53847

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


[PATCH] D133413: [clang-tidy] Fix crashes on `if consteval` in readability checks

2022-09-07 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel added a comment.

Note for reviewing:

- The C++ standard, from what I could tell, seems to imply the the else clause 
of a consteval if clause could be written without braces, however it seems that 
both GCC and Clang don't allow for this, so both clauses of constexpr if 
statements should be skipped in readability-braces-around-statement
- I was really unsure what to do with the tests. Since consteval if is a C++23 
feature, I felt like they needed to be in their own files, but these files are 
also super minimal, as they really only make sure that using them doesn't crash.
- The tests use the flag `-std=c++2b`. Seeing as that flag will probably be 
renamed once 2023 actually rolls around, is that okay?
- I cannot commit this patch myself, please commit as `Emilia Dreamer 
`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133413

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


[PATCH] D133415: [clangd] Fix non-idempotent cases of canonicalRenameDecl()

2022-09-07 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added reviewers: ilya-biryukov, tom-anders.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang-tools-extra.

The simplest way to ensure full canonicalization is to canonicalize
recursively in most cases.

This fixes an assertion failure and presumably correctness bugs.

It does show up that D132797 's index-based 
virtual method renames doesn't handle
templates well (the AST behavior is different and IMO better).
We could choose to disable in this case or change the index behavior,
but this patch doesn't do either.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133415

Files:
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/unittests/RenameTests.cpp


Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -1515,17 +1515,21 @@
 }
   )cpp",
   },
-  // FIXME: triggers an assertion failure due to a bug in canonicalization.
-  // See https://reviews.llvm.org/D132797
-#if 0
   {
   // virtual templated method
   R"cpp(
 template  class Foo { virtual void [[m]](); };
 class Bar : Foo { void [[^m]]() override; };
-  )cpp", ""
+  )cpp",
+  R"cpp(
+  #include "foo.h"
+
+  template void Foo::[[m]]() {}
+  // FIXME: not renamed as the index doesn't see this as an override of
+  // the canonical Foo::m(), rather it overrides Foo::m().
+  class Baz : Foo { void m() override; };
+)cpp"
   },
-#endif
   {
   // rename on constructor and destructor.
   R"cpp(
Index: clang-tools-extra/clangd/refactor/Rename.cpp
===
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -100,14 +100,13 @@
   return canonicalRenameDecl(Method->getParent());
 if (const FunctionDecl *InstantiatedMethod =
 Method->getInstantiatedFromMemberFunction())
-  Method = cast(InstantiatedMethod);
+  return canonicalRenameDecl(InstantiatedMethod);
 // FIXME(kirillbobyrev): For virtual methods with
 // size_overridden_methods() > 1, this will not rename all functions it
 // overrides, because this code assumes there is a single canonical
 // declaration.
-while (Method->isVirtual() && Method->size_overridden_methods())
-  Method = *Method->overridden_methods().begin();
-return Method->getCanonicalDecl();
+if (Method->isVirtual() && Method->size_overridden_methods())
+  return canonicalRenameDecl(*Method->overridden_methods().begin());
   }
   if (const auto *Function = dyn_cast(D))
 if (const FunctionTemplateDecl *Template = Function->getPrimaryTemplate())
@@ -132,8 +131,7 @@
   }
   if (const auto *VD = dyn_cast(D)) {
 if (const VarDecl *OriginalVD = VD->getInstantiatedFromStaticDataMember())
-  VD = OriginalVD;
-return VD->getCanonicalDecl();
+  return canonicalRenameDecl(OriginalVD);
   }
   return dyn_cast(D->getCanonicalDecl());
 }


Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -1515,17 +1515,21 @@
 }
   )cpp",
   },
-  // FIXME: triggers an assertion failure due to a bug in canonicalization.
-  // See https://reviews.llvm.org/D132797
-#if 0
   {
   // virtual templated method
   R"cpp(
 template  class Foo { virtual void [[m]](); };
 class Bar : Foo { void [[^m]]() override; };
-  )cpp", ""
+  )cpp",
+  R"cpp(
+  #include "foo.h"
+
+  template void Foo::[[m]]() {}
+  // FIXME: not renamed as the index doesn't see this as an override of
+  // the canonical Foo::m(), rather it overrides Foo::m().
+  class Baz : Foo { void m() override; };
+)cpp"
   },
-#endif
   {
   // rename on constructor and destructor.
   R"cpp(
Index: clang-tools-extra/clangd/refactor/Rename.cpp
===
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -100,14 +100,13 @@
   return canonicalRenameDecl(Method->getParent());
 if (const FunctionDecl *InstantiatedMethod =
 Method->getInstantiatedFromMemberFunction())
-  Method = cast(InstantiatedMethod);
+  return canonicalRenameDecl(InstantiatedMethod);
 // FIXME(kirillbobyrev)

[PATCH] D131465: C++/ObjC++: switch to gnu++17 as the default standard

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

In D131465#3772803 , @MaskRay wrote:

> Update clang-tools-extra/clangd/unittests/SelectionTests.cpp @sammccall

This one looks to still be failing on Windows according to precommit CI.

Otherwise, the changes LGTM




Comment at: clang/test/lit.site.cfg.py.in:27
 config.clang_enable_opaque_pointers = @CLANG_ENABLE_OPAQUE_POINTERS_INTERNAL@
+config.clang_default_std_cxx = "@CLANG_DEFAULT_STD_CXX@"
 config.clang_default_cxx_stdlib = "@CLANG_DEFAULT_CXX_STDLIB@"

MaskRay wrote:
> aaron.ballman wrote:
> > MaskRay wrote:
> > > aaron.ballman wrote:
> > > > Should we add some documentation for this in a follow-up? (I know 
> > > > `CLANG_DEFAULT_STD_CXX` already exists, but it seems like it'd be 
> > > > helpful to tell users about it too.)
> > > Where shall we place the documentation? My understanding is that we don't 
> > > document lit.* config changes.
> > > 
> > > Personally I think we probably should get rid of `CLANG_DEFAULT_STD_CXX` 
> > > (D34365 @mgorny), which may require improvements to Clang configuration 
> > > file (https://discourse.llvm.org/t/configuration-files/42529 
> > > https://clang.llvm.org/docs/UsersManual.html#configuration-files).
> > Oh, I thought this was a CMake variable that users could set, so I was 
> > thinking it would have gone into 
> > https://llvm.org/docs/CMake.html#rarely-used-cmake-variables. Is this not 
> > something users set to try test out in a different language standard mode 
> > than the default?
> AIUI we currently document none of `CLANG_*` cmake variables, because we 
> don't have a Clang counterpart of  `llvm/docs/CMake.rst`.
> 
> For `CLANG_DEFAULT_STD_CXX`, I decide to remove it in D133375. But this patch 
> has to add minimum test support to make tests pass when it is still present.
> AIUI we currently document none of CLANG_* cmake variables, because we don't 
> have a Clang counterpart of llvm/docs/CMake.rst.

Yup, we should definitely address that at some point (not part of this patch).

> For CLANG_DEFAULT_STD_CXX, I decide to remove it in D133375. But this patch 
> has to add minimum test support to make tests pass when it is still present.

Okay, we can discuss the removal over there, thanks for the info!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131465

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


[PATCH] D133375: [CMake] Remove CLANG_DEFAULT_STD_C/CLANG_DEFAULT_STD_CXX

2022-09-07 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

So the basic idea here is that the default can be specified by a configuration 
file and thus we don't need any configure-time variable for it? But then why do 
we need other configuration macros like default stdlib or default linker? 
Mostly trying to understand what the rule of thumb is for when something should 
be a configure macro and when something should be left to a configuration file 
instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133375

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


[PATCH] D133338: [clang][PowerPC] PPC64 VAArg use coerced integer type for direct aggregate fits in register

2022-09-07 Thread Ulrich Weigand via Phabricator via cfe-commits
uweigand added a comment.

I think it is correct to implement this in Clang.   Note that on SystemZ 
(another big-endian platform), we also implement this in `EmitVAArg`.   Of 
course the details are different since we're not using `emitVoidPtrVAArg` on 
that platform.

However, I'm not sure if the implementation itself is quite correct, in 
particular if it is right to just replace the type.  Note that looking into 
`emitVoidPtrVAArg` I see this:

  // If the argument is smaller than a slot, and this is a big-endian
  // target, the argument will be right-adjusted in its slot.
  if (DirectSize < SlotSize && CGF.CGM.getDataLayout().isBigEndian() &&
  !DirectTy->isStructTy()) {
Addr = CGF.Builder.CreateConstInBoundsByteGEP(Addr, SlotSize - DirectSize);
  }

which seems to implement exactly the same logic, but *without* modifying the 
type as seen in the IR.It looks like the only change needed for ppc would 
be to remove the `!DirectTy->isStructTy()` check here?   (I guess to avoid 
inadvertently change other targets, this might need to be triggered by a flag 
passed as argument.  On the other hand, maybe there is no other big-endian 
platform using `emitVoidPtrVAArg` anyway?)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D18

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


[PATCH] D132131: [clang-format] Adds a formatter for aligning trailing comments over empty lines

2022-09-07 Thread Yusuke Kadowaki via Phabricator via cfe-commits
yusuke-kadowaki marked 3 inline comments as done.
yusuke-kadowaki added inline comments.



Comment at: clang/docs/ClangFormatStyleOptions.rst:865
+
+  * ``TCAS_DontAlign`` (in configuration: ``DontAlign``)
+Don't align trailing comments.

MyDeveloperDay wrote:
> Is Don'tAlign the same as Leave that other options support  (for options it 
> best if we try and use the same terminiology
> 
> Always,Never,Leave (if that fits)
IMHO, `Leave` probably fits but `DontAlign`  is more straightforward. Also 
`DontAlign` is used for other alignment styles like `BracketAlignmentStyle` so 
it would be more natural.



Comment at: clang/include/clang/Format/Format.h:373
+  /// Different styles for aligning trailing comments.
+  enum TrailingCommentsAlignmentStyle : int8_t {
+/// Don't align trailing comments.

MyDeveloperDay wrote:
> all options have a life cycle
> 
> bool -> enum -> struct
> 
> One of the thing I ask you before, would we want to align across N empty 
> lines, if ever so they I think
> we should go straight to a struct
> all options have a life cycle

I see your point. But we are checking `Style.MaxEmptyLinesToKeep` to determine 
how many consecutive lines to align. So currently no need to specify it from 
the option. You'll find the implementation below.



Comment at: clang/unittests/Format/FormatTestComments.cpp:2930
+  Style.ColumnLimit = 15;
+  EXPECT_EQ("int ab; // line\n"
+"int a;  // long\n"

MyDeveloperDay wrote:
> yusuke-kadowaki wrote:
> > MyDeveloperDay wrote:
> > > Why not verifyFormat here too and below?
> > To test the ColumnLimit behavior.
> pretty sure you can pass in a style
Style isn't a problem here. But when testing column limit, you want to see 
before and after the line split into multiple lines. Original test cases of 
AlignTrailingComments also use this EXPECT_EQ style not verifyFormat.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132131

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


[PATCH] D113779: [Clang] Add mfp16, mfp16fml and mdotprod flags for ARM target features.

2022-09-07 Thread Steve Canon via Phabricator via cfe-commits
scanon added a comment.

Wearing my compiler user hat, I would much rather use additive -mfeature than 
have to specify these as -march+feature, even when using a build system that 
nominally handles this stuff, because I frequently want to be able to compile 
one specific file with "whatever the prevailing options are, but also enable 
this one feature." Most build systems make this possible somehow (track down 
the arch variable, append +feature to it, etc), but it's considerably simpler 
if you can just append -mfeature to the list of flags and call it a day.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113779

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


[PATCH] D129883: [HLSL] Support cbuffer/tbuffer for hlsl.

2022-09-07 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thanks for the update, this is heading in a good direction! I think there's 
still a lot of test coverage missing. Consider:

  namespace Name {
  cbuffer a {
int x;
  }
  }
  
  struct S {
cbuffer what {
  int y;
}
  };
  
  void func() {
tbuffer derp {
  int z;
}
  
decltype(derp) another {
  int a;
}
  }




Comment at: clang/include/clang/AST/Decl.h:4690-4693
+  static HLSLBufferDecl *Create(ASTContext &C, DeclContext *LexicalParent,
+bool CBuffer, SourceLocation KwLoc,
+IdentifierInfo *ID, SourceLocation IDLoc,
+SourceLocation LBrace);

aaron.ballman wrote:
> Speculative question: would it make more sense to add `CreateCBuffer` and 
> `CreateTBuffer` static methods rather than use a `bool` parameter?
I'm still on the fence about this. On the one hand, being explicit is far 
better than hoping the reader understand the bool argument at the call site. On 
the other hand, using the bool parameter means less branching at the call 
sites. So I'm leaning towards leaving this as-is, but if @beanz has other 
opinions, I don't yet have a strong feeling.



Comment at: clang/include/clang/Basic/DiagnosticParseKinds.td:1608
   "expected HLSL Semantic identifier">;
+def err_invalid_declaration_in_hlsl_buffer : Error<"invalid declaration inside 
cbuffer/tbuffer">;
 def err_unknown_hlsl_semantic : Error<"unknown HLSL semantic %0">;

You know what kind of buffer it's within so we can be more precise.



Comment at: clang/lib/AST/JSONNodeDumper.cpp:904
+  VisitNamedDecl(D);
+  JOS.attribute("buffer_kind", D->isCBuffer() ? "cbuffer" : "tbuffer");
+}

Matches the naming style for most everything else in the file.



Comment at: clang/lib/Parse/ParseHLSL.cpp:20-21
 
+Decl *Parser::ParseHLSLBuffer(SourceLocation &DeclEnd,
+  SourceLocation InlineLoc) {
+  assert((Tok.is(tok::kw_cbuffer) || Tok.is(tok::kw_tbuffer)) &&

Parameter is unused, I presume that's intentional rather than accidental?



Comment at: clang/lib/Parse/ParseHLSL.cpp:25
+  bool IsCBuffer = Tok.is(tok::kw_cbuffer);
+  SourceLocation BufferLoc = ConsumeToken(); // eat the 'cbuffer or tbuffer'.
+





Comment at: clang/lib/Parse/ParseHLSL.cpp:33
+  IdentifierInfo *Identifier = Tok.getIdentifierInfo();
+  SourceLocation IdentifierLoc = ConsumeToken(); // consume identifier
+





Comment at: clang/lib/Parse/ParseHLSL.cpp:50-54
+// FIXME: support attribute on constants inside cbuffer/tbuffer.
+ParsedAttributes Attrs(AttrFactory);
+ParsedAttributes DeclSpecAttrs(AttrFactory);
+
+if (PP.isCodeCompletionReached()) {





Comment at: clang/lib/Parse/ParseHLSL.cpp:59
+
+switch (Tok.getKind()) {
+case tok::kw_namespace:

The approach of using a switch and handling individual keywords specially 
strikes me as being quite fragile. I think a better approach is to split this 
loop out into its own function and model it (at least somewhat) after 
`ParseStructUnionBody()`.

The current approach worries me because I have no idea why there's a giant 
block of invalid things or what should be added to that as we add new 
declarations to the compiler (and certainly nobody is going to think to come 
update this function when adding support for new kinds of declarations.



Comment at: clang/lib/Parse/ParseHLSL.cpp:64-65
+  T.skipToEnd();
+  return nullptr;
+  break;
+case tok::kw_cbuffer:





Comment at: clang/lib/Parse/ParseHLSL.cpp:71-74
+  return nullptr;
+
+  [[fallthrough]];
+case tok::annot_pragma_vis:

There's no way to reach this, so we shouldn't need the `[[fallthrough]]` here, 
right?



Comment at: clang/lib/Parse/ParseHLSL.cpp:103-104
+case tok::kw_export:
+case tok::kw_using:
+case tok::kw_typedef:
+case tok::kw_template:

Why are type aliases prohibited?



Comment at: clang/lib/Parse/ParseHLSL.cpp:106-107
+case tok::kw_template:
+case tok::kw_static_assert:
+case tok::kw__Static_assert:
+case tok::kw_inline:

Why are static assertions prohibited?



Comment at: clang/lib/Parse/ParseHLSL.cpp:122-123
+case tok::kw_static:
+  // Parse (then ignore) 'static' prior to a template instantiation. This
+  // is a GCC extension that we intentionally do not support.
+  if (getLangOpts().CPlusPlus && NextToken().is(tok::kw_template)) {

1) GCC supports HLSL?

2) This seems wrong because it will result in:
```
static template  Ty Val{}; // Prohibited
static void func(); // 

[PATCH] D132136: [clang] Perform implicit lvalue-to-rvalue cast with new interpreter

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

LGTM, this wasn't quite what I had in mind, but I can see how my suggestion was 
going to be far too tricky to try to implement as a lit test. Thanks for adding 
the unit test coverage!


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

https://reviews.llvm.org/D132136

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


[PATCH] D131469: [Clang] change default storing path of `-ftime-trace`

2022-09-07 Thread dongjunduo via Phabricator via cfe-commits
dongjunduo updated this revision to Diff 458440.
dongjunduo added a comment.

fix windows path-check error


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131469

Files:
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/check-time-trace.cpp
  clang/tools/driver/cc1_main.cpp

Index: clang/tools/driver/cc1_main.cpp
===
--- clang/tools/driver/cc1_main.cpp
+++ clang/tools/driver/cc1_main.cpp
@@ -256,17 +256,10 @@
   llvm::TimerGroup::clearAll();
 
   if (llvm::timeTraceProfilerEnabled()) {
-SmallString<128> Path(Clang->getFrontendOpts().OutputFile);
-llvm::sys::path::replace_extension(Path, "json");
-if (!Clang->getFrontendOpts().TimeTracePath.empty()) {
-  // replace the suffix to '.json' directly
-  SmallString<128> TracePath(Clang->getFrontendOpts().TimeTracePath);
-  if (llvm::sys::fs::is_directory(TracePath))
-llvm::sys::path::append(TracePath, llvm::sys::path::filename(Path));
-  Path.assign(TracePath);
-}
+SmallString<128> TracePath(Clang->getFrontendOpts().TimeTracePath);
+assert(!TracePath.empty() && "`-ftime-trace=` is empty");
 if (auto profilerOutput = Clang->createOutputFile(
-Path.str(), /*Binary=*/false, /*RemoveFileOnSignal=*/false,
+TracePath.str(), /*Binary=*/false, /*RemoveFileOnSignal=*/false,
 /*useTemporary=*/false)) {
   llvm::timeTraceProfilerWrite(*profilerOutput);
   profilerOutput.reset();
Index: clang/test/Driver/check-time-trace.cpp
===
--- clang/test/Driver/check-time-trace.cpp
+++ clang/test/Driver/check-time-trace.cpp
@@ -1,3 +1,6 @@
+// RUN: rm -rf %T/exe && mkdir %T/exe
+// RUN: %clangxx -### -ftime-trace -ftime-trace-granularity=0 -o %T/exe/check-time-trace %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-OPT %s
 // RUN: %clangxx -S -ftime-trace -ftime-trace-granularity=0 -o %T/check-time-trace %s
 // RUN: cat %T/check-time-trace.json \
 // RUN:   | %python -c 'import json, sys; json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \
@@ -17,6 +20,7 @@
 // RUN:   | %python -c 'import json, sys; json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \
 // RUN:   | FileCheck %s
 
+// CHECK-OPT:  "-ftime-trace={{.*}}{{/|}}exe{{/|}}check-time-trace{{.*}}.json"
 // CHECK:  "beginningOfTime": {{[0-9]{16},}}
 // CHECK-NEXT: "traceEvents": [
 // CHECK:  "args":
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -4510,6 +4510,102 @@
   llvm_unreachable("invalid phase in ConstructPhaseAction");
 }
 
+// Infer data storing path of the options `-ftime-trace`, `-ftime-trace=`
+void InferTimeTracePath(Compilation &C) {
+  bool HasTimeTrace =
+  C.getArgs().getLastArg(options::OPT_ftime_trace) != nullptr;
+  bool HasTimeTraceFile =
+  C.getArgs().getLastArg(options::OPT_ftime_trace_EQ) != nullptr;
+  // Whether `-ftime-trace` or `-ftime-trace=` are specified
+  if (!HasTimeTrace && !HasTimeTraceFile)
+return;
+
+  // If `-ftime-trace=` is specified, TracePath is the .
+  // Else if there is a linking job, TracePath is the parent path of .exe,
+  // then the OutputFile's name may be appended to it.
+  // Else, TracePath is "",
+  // then the full OutputFile's path may be appended to it.
+  SmallString<128> TracePath("");
+
+  if (HasTimeTraceFile) {
+TracePath = SmallString<128>(
+C.getArgs().getLastArg(options::OPT_ftime_trace_EQ)->getValue());
+  } else {
+// Get linking executable file's parent path as TracePath's parent path,
+// default is ".". Filename may be determined and added into TracePath then.
+//
+// e.g. executable file's path: /usr/local/a.out
+//  its parent's path:  /usr/local
+for (auto &J : C.getJobs()) {
+  if (J.getSource().getKind() == Action::LinkJobClass) {
+assert(!J.getOutputFilenames().empty() &&
+   "linking output filename is empty");
+auto OutputFilePath =
+SmallString<128>(J.getOutputFilenames()[0].c_str());
+if (llvm::sys::path::has_parent_path(OutputFilePath)) {
+  TracePath = llvm::sys::path::parent_path(OutputFilePath);
+} else {
+  TracePath = SmallString<128>(".");
+}
+break;
+  }
+}
+  }
+
+  // Add or replace the modified -ftime-trace=` to all clang jobs
+  for (auto &J : C.getJobs()) {
+if (J.getSource().getKind() == Action::AssembleJobClass ||
+J.getSource().getKind() == Action::BackendJobClass ||
+J.getSource().getKind() == Action::CompileJobClass) {
+  SmallString<128> TracePathReal = TracePath;
+  SmallString<128> OutputPath(J.getOutputFilenames()[0].c_str());
+ 

[PATCH] D123630: Remove connection between 'ffast-math' and 'ffp-contract'.

2022-09-07 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added a comment.

@fhahn @aaron.ballman would you mind taking time for a review for this patch? 
Thanks.


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

https://reviews.llvm.org/D123630

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


[PATCH] D113779: [Clang] Add mfp16, mfp16fml and mdotprod flags for ARM target features.

2022-09-07 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer added a comment.

In D113779#3496589 , @fhahn wrote:

> In D113779#3207936 , @SjoerdMeijer 
> wrote:
>
>>> If anybody has contacts to GCC that would be very helpful. Unfortunately I 
>>> don't think I will be able to drive this.
>>
>> Ok, I will bring this up internally first with some folks that work on GCC 
>> and see what happens. To be continued...
>
> Hi, did you get an update by any chance?

Sorry for the delay. I have just left a message for our GNU toolchain guys with 
an invitation to add comments here.
I know there are strong opinions that -march should be the only way to set 
extensions, but personally I am open to use case that it might be difficult to 
override -march, so I am not blocking this.
I am still of the opinion that options are already an enormous mess, and 
introducing another way is not making things necessarily better. But if we 
document this, and add -m options for existing extensions, it may not be worse. 
So that will be my request for this patch, that we document this somewhere in 
the Clang docs, and then ideally we see the patches for existing extensions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113779

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


[PATCH] D131153: AArch64: disable asynchronous unwind by default for MachO.

2022-09-07 Thread Tim Northover via Phabricator via cfe-commits
t.p.northover added a comment.

> I don't think this is quite correct though? It'll turn off unwind tables for 
> AArch64 entirely, whereas we want to keep sync unwind tables.

You're right, sorry about that. Hopefully this refactoring with MaskRay's 
suggestion gets it right.




Comment at: clang/include/clang/Driver/ToolChain.h:501
+  /// IsAsyncUnwindTablesDefault - Does this tool chain use
+  /// -fasync-unwind-tables by default.
+  virtual bool

MaskRay wrote:
> smeenai wrote:
> > I believe the option is spelled `-fasynchronous-unwind-tables`.
> Changing `IsUnwindTablesDefault` to `unwindTablesDefaultLevel` may be 
> cleaner. 
I prefer it, though the Clang.cpp logic is unavoidably weird.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131153

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


[PATCH] D131153: AArch64: disable asynchronous unwind by default for MachO.

2022-09-07 Thread Tim Northover via Phabricator via cfe-commits
t.p.northover updated this revision to Diff 458443.
Herald added subscribers: abrachet, mstorsjo, emaste.

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

https://reviews.llvm.org/D131153

Files:
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CrossWindows.cpp
  clang/lib/Driver/ToolChains/CrossWindows.h
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Driver/ToolChains/Darwin.h
  clang/lib/Driver/ToolChains/FreeBSD.cpp
  clang/lib/Driver/ToolChains/FreeBSD.h
  clang/lib/Driver/ToolChains/Fuchsia.h
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Gnu.h
  clang/lib/Driver/ToolChains/MSVC.cpp
  clang/lib/Driver/ToolChains/MSVC.h
  clang/lib/Driver/ToolChains/MinGW.cpp
  clang/lib/Driver/ToolChains/MinGW.h
  clang/lib/Driver/ToolChains/NetBSD.h
  clang/lib/Driver/ToolChains/OpenBSD.cpp
  clang/lib/Driver/ToolChains/OpenBSD.h
  clang/test/Driver/clang-translation.c

Index: clang/test/Driver/clang-translation.c
===
--- clang/test/Driver/clang-translation.c
+++ clang/test/Driver/clang-translation.c
@@ -77,7 +77,11 @@
 
 // RUN: %clang -target arm64-apple-ios10 -### -S %s -arch arm64 2>&1 | \
 // RUN: FileCheck -check-prefix=ARM64-APPLE %s
-// ARM64-APPLE: -funwind-tables=2
+// ARM64-APPLE: -funwind-tables=1
+
+// RUN: %clang -target arm64-apple-ios10 -funwind-tables -### -S %s -arch arm64 2>&1 | \
+// RUN: FileCheck -check-prefix=ARM64-APPLE-UNWIND %s
+// ARM64-APPLE-UNWIND: -funwind-tables=1
 
 // RUN: %clang -target arm64-apple-ios10 -### -ffreestanding -S %s -arch arm64 2>&1 | \
 // RUN: FileCheck -check-prefix=ARM64-FREESTANDING-APPLE %s
Index: clang/lib/Driver/ToolChains/OpenBSD.h
===
--- clang/lib/Driver/ToolChains/OpenBSD.h
+++ clang/lib/Driver/ToolChains/OpenBSD.h
@@ -82,7 +82,8 @@
   std::string getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component,
 FileType Type = ToolChain::FT_Static) const override;
 
-  bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const override;
+  UnwindTableLevel
+  getUnwindTableDefaultLevel(const llvm::opt::ArgList &Args) const override;
 
   LangOptions::StackProtectorMode
   GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
Index: clang/lib/Driver/ToolChains/OpenBSD.cpp
===
--- clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -363,11 +363,12 @@
 
 bool OpenBSD::HasNativeLLVMSupport() const { return true; }
 
-bool OpenBSD::IsUnwindTablesDefault(const ArgList &Args) const {
-switch (getArch()) {
-  case llvm::Triple::arm:
-return false;
-  default:
-return true;
-}
+ToolChain::UnwindTableLevel
+OpenBSD::getUnwindTableDefaultLevel(const ArgList &Args) const {
+  switch (getArch()) {
+  case llvm::Triple::arm:
+return UTL_None;
+  default:
+return UTL_Asynchronous;
+  }
 }
Index: clang/lib/Driver/ToolChains/NetBSD.h
===
--- clang/lib/Driver/ToolChains/NetBSD.h
+++ clang/lib/Driver/ToolChains/NetBSD.h
@@ -65,8 +65,9 @@
   const llvm::opt::ArgList &DriverArgs,
   llvm::opt::ArgStringList &CC1Args) const override;
 
-  bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const override {
-return true;
+  UnwindTableLevel
+  getUnwindTableDefaultLevel(const llvm::opt::ArgList &Args) const override {
+return UTL_Asynchronous;
   }
 
   llvm::ExceptionHandling GetExceptionModel(
Index: clang/lib/Driver/ToolChains/MinGW.h
===
--- clang/lib/Driver/ToolChains/MinGW.h
+++ clang/lib/Driver/ToolChains/MinGW.h
@@ -66,7 +66,8 @@
   bool HasNativeLLVMSupport() const override;
 
   bool IsIntegratedAssemblerDefault() const override;
-  bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const override;
+  UnwindTableLevel
+  getUnwindTableDefaultLevel(const llvm::opt::ArgList &Args) const override;
   bool isPICDefault() const override;
   bool isPIEDefault(const llvm::opt::ArgList &Args) const override;
   bool isPICDefaultForced() const override;
Index: clang/lib/Driver/ToolChains/MinGW.cpp
===
--- clang/lib/Driver/ToolChains/MinGW.cpp
+++ clang/lib/Driver/ToolChains/MinGW.cpp
@@ -482,15 +482,19 @@
   return NativeLLVMSupport;
 }
 
-bool toolchains::MinGW::IsUnwindTablesDefault(const ArgList &Args) const {
+ToolChain::UnwindTableLevel
+toolchains::MinGW::getUnwindTableDefaultLevel(const ArgList &Args) const {
   Arg *ExceptionArg = Args.getLastArg(options::OPT_fsjlj_exceptions,
   options::OPT_fseh_exceptions,
   options::OPT_fdwarf_ex

[PATCH] D131153: AArch64: disable asynchronous unwind by default for MachO.

2022-09-07 Thread Tim Northover via Phabricator via cfe-commits
t.p.northover updated this revision to Diff 458444.
t.p.northover added a comment.
Herald added subscribers: bzcheeseman, sdasgup3, wenzhicui, wrengr, cota, 
teijeong, rdzhabarov, tatianashp, msifontes, jurahul, Kayjukh, grosul1, 
Joonsoo, stephenneuendorffer, liufengdb, aartbik, mgester, arpith-jacob, 
nicolasvasilache, antiagainst, shauheen, rriddle, mehdi_amini.
Herald added a project: MLIR.

Quick rename of new method to flow better.


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

https://reviews.llvm.org/D131153

Files:
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CrossWindows.cpp
  clang/lib/Driver/ToolChains/CrossWindows.h
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Driver/ToolChains/Darwin.h
  clang/lib/Driver/ToolChains/FreeBSD.cpp
  clang/lib/Driver/ToolChains/FreeBSD.h
  clang/lib/Driver/ToolChains/Fuchsia.h
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Gnu.h
  clang/lib/Driver/ToolChains/MSVC.cpp
  clang/lib/Driver/ToolChains/MSVC.h
  clang/lib/Driver/ToolChains/MinGW.cpp
  clang/lib/Driver/ToolChains/MinGW.h
  clang/lib/Driver/ToolChains/NetBSD.h
  clang/lib/Driver/ToolChains/OpenBSD.cpp
  clang/lib/Driver/ToolChains/OpenBSD.h
  clang/test/Driver/clang-translation.c
  mlir/lib/Dialect/Math/IR/MathOps.cpp

Index: mlir/lib/Dialect/Math/IR/MathOps.cpp
===
--- mlir/lib/Dialect/Math/IR/MathOps.cpp
+++ mlir/lib/Dialect/Math/IR/MathOps.cpp
@@ -420,17 +420,11 @@
 //===--===//
 
 OpFoldResult math::RoundEvenOp::fold(ArrayRef operands) {
-  return constFoldUnaryOpConditional(
-  operands, [](const APFloat &a) -> Optional {
-switch (a.getSizeInBits(a.getSemantics())) {
-case 64:
-  return APFloat(roundeven(a.convertToDouble()));
-case 32:
-  return APFloat(roundevenf(a.convertToFloat()));
-default:
-  return {};
-}
-  });
+  return constFoldUnaryOp(operands, [](const APFloat &a) {
+APFloat result(a);
+result.roundToIntegral(llvm::RoundingMode::NearestTiesToEven);
+return result;
+  });
 }
 
 /// Materialize an integer or floating point constant.
Index: clang/test/Driver/clang-translation.c
===
--- clang/test/Driver/clang-translation.c
+++ clang/test/Driver/clang-translation.c
@@ -77,7 +77,11 @@
 
 // RUN: %clang -target arm64-apple-ios10 -### -S %s -arch arm64 2>&1 | \
 // RUN: FileCheck -check-prefix=ARM64-APPLE %s
-// ARM64-APPLE: -funwind-tables=2
+// ARM64-APPLE: -funwind-tables=1
+
+// RUN: %clang -target arm64-apple-ios10 -funwind-tables -### -S %s -arch arm64 2>&1 | \
+// RUN: FileCheck -check-prefix=ARM64-APPLE-UNWIND %s
+// ARM64-APPLE-UNWIND: -funwind-tables=1
 
 // RUN: %clang -target arm64-apple-ios10 -### -ffreestanding -S %s -arch arm64 2>&1 | \
 // RUN: FileCheck -check-prefix=ARM64-FREESTANDING-APPLE %s
Index: clang/lib/Driver/ToolChains/OpenBSD.h
===
--- clang/lib/Driver/ToolChains/OpenBSD.h
+++ clang/lib/Driver/ToolChains/OpenBSD.h
@@ -82,7 +82,8 @@
   std::string getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component,
 FileType Type = ToolChain::FT_Static) const override;
 
-  bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const override;
+  UnwindTableLevel
+  getUnwindTableDefaultLevel(const llvm::opt::ArgList &Args) const override;
 
   LangOptions::StackProtectorMode
   GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
Index: clang/lib/Driver/ToolChains/OpenBSD.cpp
===
--- clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -363,11 +363,12 @@
 
 bool OpenBSD::HasNativeLLVMSupport() const { return true; }
 
-bool OpenBSD::IsUnwindTablesDefault(const ArgList &Args) const {
-switch (getArch()) {
-  case llvm::Triple::arm:
-return false;
-  default:
-return true;
-}
+ToolChain::UnwindTableLevel
+OpenBSD::getUnwindTableDefaultLevel(const ArgList &Args) const {
+  switch (getArch()) {
+  case llvm::Triple::arm:
+return UTL_None;
+  default:
+return UTL_Asynchronous;
+  }
 }
Index: clang/lib/Driver/ToolChains/NetBSD.h
===
--- clang/lib/Driver/ToolChains/NetBSD.h
+++ clang/lib/Driver/ToolChains/NetBSD.h
@@ -65,8 +65,9 @@
   const llvm::opt::ArgList &DriverArgs,
   llvm::opt::ArgStringList &CC1Args) const override;
 
-  bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const override {
-return true;
+  UnwindTableLevel
+  getUnwindTableDefaultLevel(const llvm::opt::ArgList &Args) const override {
+return UTL_Asynchr

[PATCH] D133423: [clangd] Improve Selection testcase, pin to C++17

2022-09-07 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.

17 vs 14 have different ASTs, this causes D131465 
 to have to touch this test.
While here, make sure we're being clear about *which* nodes we're matching.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133423

Files:
  clang-tools-extra/clangd/unittests/SelectionTests.cpp


Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp
===
--- clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -716,17 +716,23 @@
 int f(S);
 int x = f("^");
   )cpp";
-  auto AST = TestTU::withCode(Annotations(Test).code()).build();
+  auto TU = TestTU::withCode(Annotations(Test).code());
+  // C++14 AST contains some temporaries that C++17 elides.
+  TU.ExtraArgs.push_back("-std=c++17");
+  auto AST = TU.build();
   auto T = makeSelectionTree(Test, AST);
 
   const SelectionTree::Node *Str = T.commonAncestor();
   EXPECT_EQ("StringLiteral", nodeKind(Str)) << "Implicit selected?";
   EXPECT_EQ("ImplicitCastExpr", nodeKind(Str->Parent));
   EXPECT_EQ("CXXConstructExpr", nodeKind(Str->Parent->Parent));
-  EXPECT_EQ(Str, &Str->Parent->Parent->ignoreImplicit())
-  << "Didn't unwrap " << nodeKind(&Str->Parent->Parent->ignoreImplicit());
+  EXPECT_EQ("ImplicitCastExpr", nodeKind(Str->Parent->Parent->Parent));
+  const SelectionTree::Node *ICE = Str->Parent->Parent->Parent;
+  EXPECT_EQ("CallExpr", nodeKind(ICE->Parent));
+  EXPECT_EQ(Str, &ICE->ignoreImplicit())
+  << "Didn't unwrap " << nodeKind(&ICE->ignoreImplicit());
 
-  EXPECT_EQ("CXXConstructExpr", nodeKind(&Str->outerImplicit()));
+  EXPECT_EQ(ICE, &Str->outerImplicit());
 }
 
 TEST(SelectionTest, CreateAll) {


Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp
===
--- clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -716,17 +716,23 @@
 int f(S);
 int x = f("^");
   )cpp";
-  auto AST = TestTU::withCode(Annotations(Test).code()).build();
+  auto TU = TestTU::withCode(Annotations(Test).code());
+  // C++14 AST contains some temporaries that C++17 elides.
+  TU.ExtraArgs.push_back("-std=c++17");
+  auto AST = TU.build();
   auto T = makeSelectionTree(Test, AST);
 
   const SelectionTree::Node *Str = T.commonAncestor();
   EXPECT_EQ("StringLiteral", nodeKind(Str)) << "Implicit selected?";
   EXPECT_EQ("ImplicitCastExpr", nodeKind(Str->Parent));
   EXPECT_EQ("CXXConstructExpr", nodeKind(Str->Parent->Parent));
-  EXPECT_EQ(Str, &Str->Parent->Parent->ignoreImplicit())
-  << "Didn't unwrap " << nodeKind(&Str->Parent->Parent->ignoreImplicit());
+  EXPECT_EQ("ImplicitCastExpr", nodeKind(Str->Parent->Parent->Parent));
+  const SelectionTree::Node *ICE = Str->Parent->Parent->Parent;
+  EXPECT_EQ("CallExpr", nodeKind(ICE->Parent));
+  EXPECT_EQ(Str, &ICE->ignoreImplicit())
+  << "Didn't unwrap " << nodeKind(&ICE->ignoreImplicit());
 
-  EXPECT_EQ("CXXConstructExpr", nodeKind(&Str->outerImplicit()));
+  EXPECT_EQ(ICE, &Str->outerImplicit());
 }
 
 TEST(SelectionTest, CreateAll) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129683: [Sema] Move Diags.isIgnored() checks off hot paths, it's not free. NFC

2022-09-07 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.
Closed by commit rG897f3ddc6154: [Sema] Move Diags.isIgnored() checks off hot 
paths, it's not free. NFC (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D129683?vs=444375&id=458448#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129683

Files:
  clang/lib/Sema/Sema.cpp


Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -575,10 +575,7 @@
   Diag(Loc, diag::warn_nullability_lost) << SrcType << DstType;
 }
 
-void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, const Expr* E) {
-  if (Diags.isIgnored(diag::warn_zero_as_null_pointer_constant,
-  E->getBeginLoc()))
-return;
+void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, const Expr *E) {
   // nullptr only exists from C++11 on, so don't warn on its absence earlier.
   if (!getLangOpts().CPlusPlus11)
 return;
@@ -588,6 +585,10 @@
   if (E->IgnoreParenImpCasts()->getType()->isNullPtrType())
 return;
 
+  if (Diags.isIgnored(diag::warn_zero_as_null_pointer_constant,
+  E->getBeginLoc()))
+return;
+
   // Don't diagnose the conversion from a 0 literal to a null pointer argument
   // in a synthesized call to operator<=>.
   if (!CodeSynthesisContexts.empty() &&


Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -575,10 +575,7 @@
   Diag(Loc, diag::warn_nullability_lost) << SrcType << DstType;
 }
 
-void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, const Expr* E) {
-  if (Diags.isIgnored(diag::warn_zero_as_null_pointer_constant,
-  E->getBeginLoc()))
-return;
+void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, const Expr *E) {
   // nullptr only exists from C++11 on, so don't warn on its absence earlier.
   if (!getLangOpts().CPlusPlus11)
 return;
@@ -588,6 +585,10 @@
   if (E->IgnoreParenImpCasts()->getType()->isNullPtrType())
 return;
 
+  if (Diags.isIgnored(diag::warn_zero_as_null_pointer_constant,
+  E->getBeginLoc()))
+return;
+
   // Don't diagnose the conversion from a 0 literal to a null pointer argument
   // in a synthesized call to operator<=>.
   if (!CodeSynthesisContexts.empty() &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 897f3dd - [Sema] Move Diags.isIgnored() checks off hot paths, it's not free. NFC

2022-09-07 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-09-07T16:18:31+02:00
New Revision: 897f3ddc6154fee9bc072f800ceab8202b236b0a

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

LOG: [Sema] Move Diags.isIgnored() checks off hot paths, it's not free. NFC

This speeds up clangd's buildAST() (i.e. parsing with a preamble) by 5% on
clangd/AST.cpp, by avoiding filling up the diagnostic state map with entries for
all the files where templates are being instantiated from.

(I would assume it has a similar effect on PCH and modules compiles).

This approach is obviously pretty fragile, and we should find ways to make
isIgnored() cheaper instead. But these changes in particular don't seem to make
the code worse in any case.

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

Added: 


Modified: 
clang/lib/Sema/Sema.cpp

Removed: 




diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 5215b60defe8a..7ccf6330b49b8 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -575,10 +575,7 @@ void Sema::diagnoseNullableToNonnullConversion(QualType 
DstType,
   Diag(Loc, diag::warn_nullability_lost) << SrcType << DstType;
 }
 
-void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, const Expr* E) {
-  if (Diags.isIgnored(diag::warn_zero_as_null_pointer_constant,
-  E->getBeginLoc()))
-return;
+void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, const Expr *E) {
   // nullptr only exists from C++11 on, so don't warn on its absence earlier.
   if (!getLangOpts().CPlusPlus11)
 return;
@@ -588,6 +585,10 @@ void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, 
const Expr* E) {
   if (E->IgnoreParenImpCasts()->getType()->isNullPtrType())
 return;
 
+  if (Diags.isIgnored(diag::warn_zero_as_null_pointer_constant,
+  E->getBeginLoc()))
+return;
+
   // Don't diagnose the conversion from a 0 literal to a null pointer argument
   // in a synthesized call to operator<=>.
   if (!CodeSynthesisContexts.empty() &&



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


[PATCH] D133423: [clangd] Improve Selection testcase, pin to C++17

2022-09-07 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.

can you wait for premerge checks to finish (especially for windows)?




Comment at: clang-tools-extra/clangd/unittests/SelectionTests.cpp:729-730
   EXPECT_EQ("CXXConstructExpr", nodeKind(Str->Parent->Parent));
-  EXPECT_EQ(Str, &Str->Parent->Parent->ignoreImplicit())
-  << "Didn't unwrap " << nodeKind(&Str->Parent->Parent->ignoreImplicit());
+  EXPECT_EQ("ImplicitCastExpr", nodeKind(Str->Parent->Parent->Parent));
+  const SelectionTree::Node *ICE = Str->Parent->Parent->Parent;
+  EXPECT_EQ("CallExpr", nodeKind(ICE->Parent));




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133423

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


[clang-tools-extra] 8af74da - [clangd] Improve Selection testcase, pin to C++17

2022-09-07 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-09-07T16:32:04+02:00
New Revision: 8af74da5bdbdccf13de84a4610ef75cd3dbac09e

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

LOG: [clangd] Improve Selection testcase, pin to C++17

17 vs 14 have different ASTs, this causes D131465 to have to touch this test.
While here, make sure we're being clear about *which* nodes we're matching.

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

Added: 


Modified: 
clang-tools-extra/clangd/unittests/SelectionTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/SelectionTests.cpp 
b/clang-tools-extra/clangd/unittests/SelectionTests.cpp
index f7a518f3e995..b44d9a6afe7a 100644
--- a/clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -716,17 +716,23 @@ TEST(SelectionTest, Implicit) {
 int f(S);
 int x = f("^");
   )cpp";
-  auto AST = TestTU::withCode(Annotations(Test).code()).build();
+  auto TU = TestTU::withCode(Annotations(Test).code());
+  // C++14 AST contains some temporaries that C++17 elides.
+  TU.ExtraArgs.push_back("-std=c++17");
+  auto AST = TU.build();
   auto T = makeSelectionTree(Test, AST);
 
   const SelectionTree::Node *Str = T.commonAncestor();
   EXPECT_EQ("StringLiteral", nodeKind(Str)) << "Implicit selected?";
   EXPECT_EQ("ImplicitCastExpr", nodeKind(Str->Parent));
   EXPECT_EQ("CXXConstructExpr", nodeKind(Str->Parent->Parent));
-  EXPECT_EQ(Str, &Str->Parent->Parent->ignoreImplicit())
-  << "Didn't unwrap " << nodeKind(&Str->Parent->Parent->ignoreImplicit());
+  const SelectionTree::Node *ICE = Str->Parent->Parent->Parent;
+  EXPECT_EQ("ImplicitCastExpr", nodeKind(ICE));
+  EXPECT_EQ("CallExpr", nodeKind(ICE->Parent));
+  EXPECT_EQ(Str, &ICE->ignoreImplicit())
+  << "Didn't unwrap " << nodeKind(&ICE->ignoreImplicit());
 
-  EXPECT_EQ("CXXConstructExpr", nodeKind(&Str->outerImplicit()));
+  EXPECT_EQ(ICE, &Str->outerImplicit());
 }
 
 TEST(SelectionTest, CreateAll) {



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


[PATCH] D133423: [clangd] Improve Selection testcase, pin to C++17

2022-09-07 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8af74da5bdbd: [clangd] Improve Selection testcase, pin to 
C++17 (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D133423?vs=458445&id=458450#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133423

Files:
  clang-tools-extra/clangd/unittests/SelectionTests.cpp


Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp
===
--- clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -716,17 +716,23 @@
 int f(S);
 int x = f("^");
   )cpp";
-  auto AST = TestTU::withCode(Annotations(Test).code()).build();
+  auto TU = TestTU::withCode(Annotations(Test).code());
+  // C++14 AST contains some temporaries that C++17 elides.
+  TU.ExtraArgs.push_back("-std=c++17");
+  auto AST = TU.build();
   auto T = makeSelectionTree(Test, AST);
 
   const SelectionTree::Node *Str = T.commonAncestor();
   EXPECT_EQ("StringLiteral", nodeKind(Str)) << "Implicit selected?";
   EXPECT_EQ("ImplicitCastExpr", nodeKind(Str->Parent));
   EXPECT_EQ("CXXConstructExpr", nodeKind(Str->Parent->Parent));
-  EXPECT_EQ(Str, &Str->Parent->Parent->ignoreImplicit())
-  << "Didn't unwrap " << nodeKind(&Str->Parent->Parent->ignoreImplicit());
+  const SelectionTree::Node *ICE = Str->Parent->Parent->Parent;
+  EXPECT_EQ("ImplicitCastExpr", nodeKind(ICE));
+  EXPECT_EQ("CallExpr", nodeKind(ICE->Parent));
+  EXPECT_EQ(Str, &ICE->ignoreImplicit())
+  << "Didn't unwrap " << nodeKind(&ICE->ignoreImplicit());
 
-  EXPECT_EQ("CXXConstructExpr", nodeKind(&Str->outerImplicit()));
+  EXPECT_EQ(ICE, &Str->outerImplicit());
 }
 
 TEST(SelectionTest, CreateAll) {


Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp
===
--- clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -716,17 +716,23 @@
 int f(S);
 int x = f("^");
   )cpp";
-  auto AST = TestTU::withCode(Annotations(Test).code()).build();
+  auto TU = TestTU::withCode(Annotations(Test).code());
+  // C++14 AST contains some temporaries that C++17 elides.
+  TU.ExtraArgs.push_back("-std=c++17");
+  auto AST = TU.build();
   auto T = makeSelectionTree(Test, AST);
 
   const SelectionTree::Node *Str = T.commonAncestor();
   EXPECT_EQ("StringLiteral", nodeKind(Str)) << "Implicit selected?";
   EXPECT_EQ("ImplicitCastExpr", nodeKind(Str->Parent));
   EXPECT_EQ("CXXConstructExpr", nodeKind(Str->Parent->Parent));
-  EXPECT_EQ(Str, &Str->Parent->Parent->ignoreImplicit())
-  << "Didn't unwrap " << nodeKind(&Str->Parent->Parent->ignoreImplicit());
+  const SelectionTree::Node *ICE = Str->Parent->Parent->Parent;
+  EXPECT_EQ("ImplicitCastExpr", nodeKind(ICE));
+  EXPECT_EQ("CallExpr", nodeKind(ICE->Parent));
+  EXPECT_EQ(Str, &ICE->ignoreImplicit())
+  << "Didn't unwrap " << nodeKind(&ICE->ignoreImplicit());
 
-  EXPECT_EQ("CXXConstructExpr", nodeKind(&Str->outerImplicit()));
+  EXPECT_EQ(ICE, &Str->outerImplicit());
 }
 
 TEST(SelectionTest, CreateAll) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131465: C++/ObjC++: switch to gnu++17 as the default standard

2022-09-07 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D131465#3774276 , @aaron.ballman 
wrote:

> In D131465#3772803 , @MaskRay wrote:
>
>> Update clang-tools-extra/clangd/unittests/SelectionTests.cpp @sammccall
>
> This one looks to still be failing on Windows according to precommit CI.

I've improved the test and pinned it to C++17 in 
8af74da5bdbdccf13de84a4610ef75cd3dbac09e 
, you can 
just revert the changes to it in this patch.
(Sorry for the conflict, but seemed better than Ray having to debug 
windows-only failures)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131465

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


[PATCH] D133425: Silence -Wctad-maybe-unsupported stemming from system headers

2022-09-07 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman created this revision.
aaron.ballman added reviewers: dblaikie, ldionne, clang-language-wg, libc++.
Herald added a project: All.
aaron.ballman requested review of this revision.
Herald added a project: clang.

Currently, this diagnostic fires on system header code that the user has no 
control over, such as `std::lock_guard` from `` in both libc++ and 
libstdc++. I believe the diagnostic should be silenced when the class template 
exists in a system header, for two reasons: 1) the user can't fix that code 
anyway, so their only recourse is to disable the diagnostic, 2) system headers 
(especially STL headers) have had time to add the CTAD guides where necessary, 
and so the warning is more likely to be a false positive in those cases.

This issue was observed by a customer in Intel's downstream and is also related 
to Issue #44202.

(Adding libc++ reviewers as an FYI for the diagnostic firing in their headers 
and as a sounding board for whether they agree we should disable this 
diagnostic in system headers by default.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133425

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaInit.cpp
  clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp


Index: clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp
===
--- clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp
+++ clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp
@@ -519,6 +519,18 @@
 TestSuppression ta("abc");
 static_assert(__is_same(decltype(ta), TestSuppression), "");
 }
+
+// Test that the diagnostic is suppressed if within a system header.
+# 2 "test.h" 1 3
+template 
+struct SysHeaderObj {
+  SysHeaderObj(T) {}
+  SysHeaderObj(T, int) {}
+};
+# 6 "test.h" 2
+
+SysHeaderObj sho(42); // Okay because SysHeaderObj is from a system header.
+
 #pragma clang diagnostic pop
 
 namespace PR41549 {
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -10295,16 +10295,16 @@
   //  by overload resolution for class template deduction.
   QualType DeducedType =
   SubstAutoType(TSInfo->getType(), Best->Function->getReturnType());
-  Diag(TSInfo->getTypeLoc().getBeginLoc(),
-   diag::warn_cxx14_compat_class_template_argument_deduction)
+  SourceLocation TyLoc = TSInfo->getTypeLoc().getBeginLoc();
+  Diag(TyLoc, diag::warn_cxx14_compat_class_template_argument_deduction)
   << TSInfo->getTypeLoc().getSourceRange() << 1 << DeducedType;
 
   // Warn if CTAD was used on a type that does not have any user-defined
-  // deduction guides.
-  if (!HasAnyDeductionGuide) {
-Diag(TSInfo->getTypeLoc().getBeginLoc(),
- diag::warn_ctad_maybe_unsupported)
-<< TemplateName;
+  // deduction guides, but do not warn if the deduction guide is in a system
+  // header on the assumption that the support is intentional there.
+  if (!HasAnyDeductionGuide &&
+  !SourceMgr.isInSystemHeader(Template->getLocation())) {
+Diag(TyLoc, diag::warn_ctad_maybe_unsupported) << TemplateName;
 Diag(Template->getLocation(), diag::note_suppress_ctad_maybe_unsupported);
   }
 
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2470,7 +2470,7 @@
   InGroup, DefaultIgnore;
 def warn_ctad_maybe_unsupported : Warning<
   "%0 may not intend to support class template argument deduction">,
-  InGroup, DefaultIgnore;
+  InGroup>, DefaultIgnore;
 def note_suppress_ctad_maybe_unsupported : Note<
   "add a deduction guide to suppress this warning">;
 
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -1329,8 +1329,6 @@
 // A group for cross translation unit static analysis related warnings.
 def CrossTU : DiagGroup<"ctu">;
 
-def CTADMaybeUnsupported : DiagGroup<"ctad-maybe-unsupported">;
-
 def FortifySource : DiagGroup<"fortify-source">;
 
 def MaxTokens : DiagGroup<"max-tokens"> {
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -132,6 +132,9 @@
 - no_sanitize("...") on a global variable for known but not relevant sanitizers
   is now just a warning. It now says that this will be ignored instead of
   incorrectly saying no_sanitize only applies to functions and methods.
+- No longer issue ``-Wctad-maybe-unsupported`` warnings when the template which
+  might not support CTAD is defined in a syst

[PATCH] D133357: [Lex/DependencyDirectivesScanner] Keep track of the presence of tokens between the last scanned directive and EOF

2022-09-07 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir accepted this revision.
benlangmuir added a comment.
This revision is now accepted and ready to land.

You forgot to remove the ` \param PrintMarkerForTokensBeforeEOF ...` from the 
doc comment.  Otherwise LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133357

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


[PATCH] D132867: [Clang] Use virtual FS in processing config files

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

Thanks!




Comment at: clang/docs/ReleaseNotes.rst:87-88
   `Issue 57387 `_.
+- Fix clang not properly handling configuration files if virtual file system
+  other than RealFS is used.
 

Because this is changing behavior that people might be relying on, I think it's 
important to call out precisely what the change is. Suggested a tweak.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132867

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


[PATCH] D133425: Silence -Wctad-maybe-unsupported stemming from system headers

2022-09-07 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Sema/SemaInit.cpp:10303
   // Warn if CTAD was used on a type that does not have any user-defined
-  // deduction guides.
-  if (!HasAnyDeductionGuide) {
-Diag(TSInfo->getTypeLoc().getBeginLoc(),
- diag::warn_ctad_maybe_unsupported)
-<< TemplateName;
+  // deduction guides, but do not warn if the deduction guide is in a system
+  // header on the assumption that the support is intentional there.

"but do not warn if the type without a deduction guide is in a system..."


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133425

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


[clang-tools-extra] 72142fb - [clangd] Fix hover crashing on integral or enumeral casts

2022-09-07 Thread Sam McCall via cfe-commits

Author: Georg Kotheimer
Date: 2022-09-07T16:43:22+02:00
New Revision: 72142fbac496a66769e16c80b076216d7c449ab2

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

LOG: [clangd] Fix hover crashing on integral or enumeral casts

When pretty printing the value of an expression, we cannot infer from
the type of the expression the type of the constant that the expression
evaluates to, as the expression might contain a type cast.

Added: 


Modified: 
clang-tools-extra/clangd/Hover.cpp
clang-tools-extra/clangd/unittests/HoverTests.cpp
clang-tools-extra/clangd/unittests/TestTU.cpp
clang-tools-extra/clangd/unittests/TestTU.h

Removed: 




diff  --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index eb44d1e915af..61c4d0658c91 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -430,7 +430,8 @@ llvm::Optional printExprValue(const Expr *E,
 return llvm::None;
 
   // Show enums symbolically, not numerically like APValue::printPretty().
-  if (T->isEnumeralType() && Constant.Val.getInt().getMinSignedBits() <= 64) {
+  if (T->isEnumeralType() && Constant.Val.isInt() &&
+  Constant.Val.getInt().getMinSignedBits() <= 64) {
 // Compare to int64_t to avoid bit-width match requirements.
 int64_t Val = Constant.Val.getInt().getExtValue();
 for (const EnumConstantDecl *ECD :
@@ -441,7 +442,7 @@ llvm::Optional printExprValue(const Expr *E,
 .str();
   }
   // Show hex value of integers if they're at least 10 (or negative!)
-  if (T->isIntegralOrEnumerationType() &&
+  if (T->isIntegralOrEnumerationType() && Constant.Val.isInt() &&
   Constant.Val.getInt().getMinSignedBits() <= 64 &&
   Constant.Val.getInt().uge(10))
 return llvm::formatv("{0} ({1})", Constant.Val.getAsString(Ctx, T),

diff  --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp 
b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 997b761e6a69..d9596dc7e693 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -3234,6 +3234,41 @@ TEST(Hover, HideBigInitializers) {
   EXPECT_EQ(H->Definition, "int arr[]");
 }
 
+TEST(Hover, GlobalVarEnumeralCastNoCrash) {
+  Annotations T(R"cpp(
+using uintptr_t = __UINTPTR_TYPE__;
+enum Test : uintptr_t {};
+unsigned global_var;
+void foo() {
+  Test v^al = static_cast(reinterpret_cast(&global_var));
+}
+  )cpp");
+
+  TestTU TU = TestTU::withCode(T.code());
+  TU.PredefineMacros = true;
+  auto AST = TU.build();
+  auto HI = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
+  ASSERT_TRUE(HI);
+  EXPECT_EQ(*HI->Value, "&global_var");
+}
+
+TEST(Hover, GlobalVarIntCastNoCrash) {
+  Annotations T(R"cpp(
+using uintptr_t = __UINTPTR_TYPE__;
+unsigned global_var;
+void foo() {
+  uintptr_t a^ddress = reinterpret_cast(&global_var);
+}
+  )cpp");
+
+  TestTU TU = TestTU::withCode(T.code());
+  TU.PredefineMacros = true;
+  auto AST = TU.build();
+  auto HI = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
+  ASSERT_TRUE(HI);
+  EXPECT_EQ(*HI->Value, "&global_var");
+}
+
 TEST(Hover, Typedefs) {
   Annotations T(R"cpp(
   template 

diff  --git a/clang-tools-extra/clangd/unittests/TestTU.cpp 
b/clang-tools-extra/clangd/unittests/TestTU.cpp
index 3da108682960..f7d294ca2c26 100644
--- a/clang-tools-extra/clangd/unittests/TestTU.cpp
+++ b/clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -40,9 +40,12 @@ ParseInputs TestTU::inputs(MockFS &FS) const {
   ParseInputs Inputs;
   Inputs.FeatureModules = FeatureModules;
   auto &Argv = Inputs.CompileCommand.CommandLine;
-  // In tests, omit predefined macros (__GNUC__ etc) for a 25% speedup.
-  // There are hundreds, and we'd generate, parse, serialize, and re-parse 
them!
-  Argv = {"clang", "-Xclang", "-undef"};
+  Argv = {"clang", "-Xclang"};
+  // In tests, unless explicitly specified otherwise, omit predefined macros
+  // (__GNUC__ etc) for a 25% speedup. There are hundreds, and we'd generate,
+  // parse, serialize, and re-parse them!
+  if (!PredefineMacros)
+Argv.push_back("-undef");
   // FIXME: this shouldn't need to be conditional, but it breaks a
   // GoToDefinition test for some reason (getMacroArgExpandedLocation fails).
   if (!HeaderCode.empty()) {

diff  --git a/clang-tools-extra/clangd/unittests/TestTU.h 
b/clang-tools-extra/clangd/unittests/TestTU.h
index b045efb727c7..9346d19e0407 100644
--- a/clang-tools-extra/clangd/unittests/TestTU.h
+++ b/clang-tools-extra/clangd/unittests/TestTU.h
@@ -59,6 +59,9 @@ struct TestTU {
   // Extra arguments for the compiler invocation.
   std::vector ExtraArgs;
 
+  // Predefine macros such as __UINTPTR_TYPE__.
+  bool PredefineMacros = false;

[PATCH] D132991: [Clang] Give error message for invalid profile path when compiling IR

2022-09-07 Thread Mircea Trofin via Phabricator via cfe-commits
mtrofin added a comment.

In D132991#3764877 , @aidengrossman 
wrote:

> @xur I've modified the patch slightly (mainly fixing tests and changing the 
> error message printing in `CodeGenModule` to an assert as we should be 
> capturing everything in `CompilerInvocation`. Do you mind looking over these 
> changes, specifically making sure that going through CompilerInvocation is 
> always guaranteed if we end up hitting `CodeGenModule`?

How come the old error checking in CodeGenModule wasn't tripped before?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132991

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


[PATCH] D133428: [WebAssembly] Prototype `f32x4.relaxed_dot_bf16x8_add_f32`

2022-09-07 Thread Thomas Lively via Phabricator via cfe-commits
tlively created this revision.
tlively added a reviewer: aheejin.
Herald added subscribers: pmatos, asb, wingo, ecnelises, sunfish, hiraditya, 
jgravelle-google, sbc100, dschuff.
Herald added a project: All.
tlively requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

As proposed in https://github.com/WebAssembly/relaxed-simd/issues/77. Only an
LLVM intrinsic and a clang builtin are implemented. Since there is no bfloat16
type, use u16 to represent the bfloats in the builtin function arguments.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133428

Files:
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-wasm.c
  llvm/include/llvm/IR/IntrinsicsWebAssembly.td
  llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
  llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll

Index: llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
===
--- llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
+++ llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
@@ -786,6 +786,20 @@
   ret <4 x float> %v
 }
 
+; CHECK-LABEL: relaxed_dot_bf16x8_add_f32:
+; CHECK-NEXT: .functype relaxed_dot_bf16x8_add_f32 (v128, v128, v128) -> (v128){{$}}
+; CHECK-NEXT: f32x4.relaxed_dot_bf16x8_add_f32 $push[[R:[0-9]+]]=, $0, $1, $2{{$}}
+; CHECK-NEXT: return $pop[[R]]{{$}}
+declare <4 x float> @llvm.wasm.relaxed.dot.bf16x8.add.f32(<8 x i16>, <8 x i16>,
+  <4 x float>)
+define <4 x float> @relaxed_dot_bf16x8_add_f32(<8 x i16> %a, <8 x i16> %b,
+   <4 x float> %c) {
+  %v = call <4 x float> @llvm.wasm.relaxed.dot.bf16x8.add.f32(
+<8 x i16> %a, <8 x i16> %b, <4 x float> %c
+  )
+  ret <4 x float> %v
+}
+
 ; ==
 ; 2 x f64
 ; ==
Index: llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
===
--- llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
+++ llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
@@ -1466,3 +1466,15 @@
(v16i8 V128:$lhs), (v16i8 V128:$rhs), (v4i32 V128:$acc)))],
 "i32x4.dot_i8x16_i7x16_add_s\t$dst, $lhs, $rhs, $acc",
 "i32x4.dot_i8x16_i7x16_add_s", 0x113>;
+
+//===--===//
+// Relaxed BFloat16 dot product
+//===--===//
+
+defm RELAXED_DOT_BFLOAT :
+  RELAXED_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs, V128:$acc),
+(outs), (ins),
+[(set (v4f32 V128:$dst), (int_wasm_relaxed_dot_bf16x8_add_f32
+   (v8i16 V128:$lhs), (v8i16 V128:$rhs), (v4f32 V128:$acc)))],
+"f32x4.relaxed_dot_bf16x8_add_f32\t$dst, $lhs, $rhs, $acc",
+"f32x4.relaxed_dot_bf16x8_add_f32", 0x114>;
Index: llvm/include/llvm/IR/IntrinsicsWebAssembly.td
===
--- llvm/include/llvm/IR/IntrinsicsWebAssembly.td
+++ llvm/include/llvm/IR/IntrinsicsWebAssembly.td
@@ -285,6 +285,12 @@
 [llvm_v16i8_ty, llvm_v16i8_ty, llvm_v4i32_ty],
 [IntrNoMem, IntrSpeculatable]>;
 
+def int_wasm_relaxed_dot_bf16x8_add_f32:
+  Intrinsic<[llvm_v4f32_ty],
+[llvm_v8i16_ty, llvm_v8i16_ty, llvm_v4f32_ty],
+[IntrNoMem, IntrSpeculatable]>;
+
+
 //===--===//
 // Thread-local storage intrinsics
 //===--===//
Index: clang/test/CodeGen/builtins-wasm.c
===
--- clang/test/CodeGen/builtins-wasm.c
+++ clang/test/CodeGen/builtins-wasm.c
@@ -794,3 +794,10 @@
   // WEBASSEMBLY-SAME: <16 x i8> %a, <16 x i8> %b, <4 x i32> %c)
   // WEBASSEMBLY-NEXT: ret
 }
+
+f32x4 relaxed_dot_bf16x8_add_f32_f32x4(u16x8 a, u16x8 b, f32x4 c) {
+  return __builtin_wasm_relaxed_dot_bf16x8_add_f32_f32x4(a, b, c);
+  // WEBASSEMBLY: call <4 x float> @llvm.wasm.relaxed.dot.bf16x8.add.f32
+  // WEBASSEMBLY-SAME: <8 x i16> %a, <8 x i16> %b, <4 x float> %c)
+  // WEBASSEMBLY-NEXT: ret
+}
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -18868,6 +18868,14 @@
 CGM.getIntrinsic(Intrinsic::wasm_dot_i8x16_i7x16_add_signed);
 return Builder.CreateCall(Callee, {LHS, RHS, Acc});
   }
+  case WebAssembly::BI__builtin_wasm_relaxed_dot_bf16x8_add_f32_f32x4: {
+Value *LHS = EmitScalarExpr(E->getArg(0));
+Value *RHS = EmitScalarExpr(E->getArg(1));
+

[PATCH] D123630: Remove connection between 'ffast-math' and 'ffp-contract'.

2022-09-07 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a reviewer: jcranmer-intel.
aaron.ballman added a comment.

I made some suggested documentation changes, but would love to hear more from 
folks heavily into floating-point options.




Comment at: clang/docs/UsersManual.rst:1409-1410
+   Disable fast-math mode.  This options disables unsafe floating-point
+   optimizations by preventing the compiler to make any tranformations that
+   could affect the results.
+





Comment at: clang/docs/UsersManual.rst:1432-1435
+   There is ambiguity about what value should ``ffp-contract`` has, when
+   options ``-ffp-contract``, ``-ffast-math`` and ``-fno-fast-math`` are
+   combined. To keep the value of ``ffp-contract`` consistent, we define this
+   set of rules:





Comment at: clang/docs/UsersManual.rst:1441-1443
+   * If ``-ffast-math`` and ``-ffp-contract`` are both seen, but
+ ``-fno-fast-math`` has not been seen after the last instance of
+ ``-ffast-math``, the ``ffp-contract`` will get the value of whichever 
option





Comment at: clang/docs/UsersManual.rst:1450-1452
+   * If ``-fno-fast-math`` is seen and ``-ffp-contract`` has not been seen, the
+ ``ffp-contract`` setting is determined by the default value of
+ ``ffp-contract``.




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

https://reviews.llvm.org/D123630

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


[clang-tools-extra] 44bbf20 - [clangd] Add Macro Expansion to Hover

2022-09-07 Thread Sam McCall via cfe-commits

Author: Qingyuan Zheng
Date: 2022-09-07T17:49:45+02:00
New Revision: 44bbf20965d2c1e00bb805343ad80dbb7758bf3d

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

LOG: [clangd] Add Macro Expansion to Hover

This patch adds macro expansion preview to hover info. Basically, the refactor 
infrastructure for expanding macro is used for this purpose. The following 
steps are added to getHoverContents for macros:
1. calling AST.getTokens().expansionStartingAt(...) to get expanded tokens
2. calling reformat(...) to format expanded tokens

Some opinions are wanted:
1. Should we present macro expansion before definition in the hover card?
2. Should we truncate/ignore macro expansion if it's too long? For performance 
and presentation reason, it might not be a good idea to expand pages worth of 
tokens in hover card. If so, what's the preferred threshold?

Also, some limitation applies:
1. Expansion isn't available in macro definition/arguments as the refactor code 
action isn't either.

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

Added: 


Modified: 
clang-tools-extra/clangd/Hover.cpp
clang-tools-extra/clangd/unittests/HoverTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index 61c4d0658c91..2ef6104e3a43 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -666,7 +666,8 @@ getPredefinedExprHoverContents(const PredefinedExpr &PE, 
ASTContext &Ctx,
 }
 
 /// Generate a \p Hover object given the macro \p MacroDecl.
-HoverInfo getHoverContents(const DefinedMacro &Macro, ParsedAST &AST) {
+HoverInfo getHoverContents(const DefinedMacro &Macro, const syntax::Token &Tok,
+   ParsedAST &AST) {
   HoverInfo HI;
   SourceManager &SM = AST.getSourceManager();
   HI.Name = std::string(Macro.Name);
@@ -697,6 +698,29 @@ HoverInfo getHoverContents(const DefinedMacro &Macro, 
ParsedAST &AST) {
 .str();
 }
   }
+
+  if (auto Expansion = AST.getTokens().expansionStartingAt(&Tok)) {
+// We drop expansion that's longer than the threshold.
+// For extremely long expansion text, it's not readable from hover card
+// anyway.
+std::string ExpansionText;
+for (const auto &ExpandedTok : Expansion->Expanded) {
+  ExpansionText += ExpandedTok.text(SM);
+  ExpansionText += " ";
+  if (ExpansionText.size() > 2048) {
+ExpansionText.clear();
+break;
+  }
+}
+
+if (!ExpansionText.empty()) {
+  if (!HI.Definition.empty()) {
+HI.Definition += "\n\n";
+  }
+  HI.Definition += "// Expands to\n";
+  HI.Definition += ExpansionText;
+}
+  }
   return HI;
 }
 
@@ -1028,7 +1052,7 @@ llvm::Optional getHover(ParsedAST &AST, 
Position Pos,
   // Prefer the identifier token as a fallback highlighting range.
   HighlightRange = Tok.range(SM).toCharRange(SM);
   if (auto M = locateMacroAt(Tok, AST.getPreprocessor())) {
-HI = getHoverContents(*M, AST);
+HI = getHoverContents(*M, Tok, AST);
 break;
   }
 } else if (Tok.kind() == tok::kw_auto || Tok.kind() == tok::kw_decltype) {
@@ -1079,11 +1103,15 @@ llvm::Optional getHover(ParsedAST &AST, 
Position Pos,
   if (!HI)
 return llvm::None;
 
-  auto Replacements = format::reformat(
-  Style, HI->Definition, tooling::Range(0, HI->Definition.size()));
-  if (auto Formatted =
-  tooling::applyAllReplacements(HI->Definition, Replacements))
-HI->Definition = *Formatted;
+  // Reformat Definition
+  if (!HI->Definition.empty()) {
+auto Replacements = format::reformat(
+Style, HI->Definition, tooling::Range(0, HI->Definition.size()));
+if (auto Formatted =
+tooling::applyAllReplacements(HI->Definition, Replacements))
+  HI->Definition = *Formatted;
+  }
+
   HI->DefinitionLanguage = getMarkdownLanguage(AST.getASTContext());
   HI->SymRange = halfOpenToRange(SM, HighlightRange);
 
@@ -1178,25 +1206,31 @@ markup::Document HoverInfo::present() const {
 
   if (!Definition.empty()) {
 Output.addRuler();
-std::string ScopeComment;
-// Drop trailing "::".
-if (!LocalScope.empty()) {
-  // Container name, e.g. class, method, function.
-  // We might want to propagate some info about container type to print
-  // function foo, class X, method X::bar, etc.
-  ScopeComment =
-  "// In " + llvm::StringRef(LocalScope).rtrim(':').str() + '\n';
-} else if (NamespaceScope && !NamespaceScope->empty()) {
-  ScopeComment = "// In namespace " +
- llvm::StringRef(*NamespaceScope).rtrim(':').str() + '\n';
+std::string Buffer;
+
+if (!Definition.empty()) {
+  // Append scope comment, dropping trailing 

[PATCH] D127082: [clangd] Add Macro Expansion to Hover

2022-09-07 Thread Sam McCall via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG44bbf20965d2: [clangd] Add Macro Expansion to Hover 
(authored by daiyousei-qz, committed by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D127082?vs=447962&id=458468#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127082

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp

Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -505,15 +505,60 @@
  HI.Definition = "Foo";
}},
 
-  // macro
+  // empty macro
+  {R"cpp(
+#define MACRO
+[[MAC^RO]]
+)cpp",
+   [](HoverInfo &HI) {
+ HI.Name = "MACRO";
+ HI.Kind = index::SymbolKind::Macro;
+ HI.Definition = "#define MACRO";
+   }},
+
+  // object-like macro
+  {R"cpp(
+#define MACRO 41
+int x = [[MAC^RO]];
+)cpp",
+   [](HoverInfo &HI) {
+ HI.Name = "MACRO";
+ HI.Kind = index::SymbolKind::Macro;
+ HI.Definition = "#define MACRO 41\n\n"
+ "// Expands to\n"
+ "41";
+   }},
+
+  // function-like macro
   {R"cpp(
 // Best MACRO ever.
-#define MACRO(x,y,z) void foo(x, y, z);
+#define MACRO(x,y,z) void foo(x, y, z)
 [[MAC^RO]](int, double d, bool z = false);
 )cpp",
[](HoverInfo &HI) {
- HI.Name = "MACRO", HI.Kind = index::SymbolKind::Macro,
- HI.Definition = "#define MACRO(x, y, z) void foo(x, y, z);";
+ HI.Name = "MACRO";
+ HI.Kind = index::SymbolKind::Macro;
+ HI.Definition = "#define MACRO(x, y, z) void foo(x, y, z)\n\n"
+ "// Expands to\n"
+ "void foo(int, double d, bool z = false)";
+   }},
+
+  // nested macro
+  {R"cpp(
+#define STRINGIFY_AUX(s) #s
+#define STRINGIFY(s) STRINGIFY_AUX(s)
+#define DECL_STR(NAME, VALUE) const char *v_##NAME = STRINGIFY(VALUE)
+#define FOO 41
+
+[[DECL^_STR]](foo, FOO);
+)cpp",
+   [](HoverInfo &HI) {
+ HI.Name = "DECL_STR";
+ HI.Kind = index::SymbolKind::Macro;
+ HI.Definition = "#define DECL_STR(NAME, VALUE) const char *v_##NAME = "
+ "STRINGIFY(VALUE)\n\n"
+ "// Expands to\n"
+ "const char *v_foo = \"41\"";
}},
 
   // constexprs
@@ -1593,7 +1638,9 @@
   [](HoverInfo &HI) {
 HI.Name = "MACRO";
 HI.Kind = index::SymbolKind::Macro;
-HI.Definition = "#define MACRO 0";
+HI.Definition = "#define MACRO 0\n\n"
+"// Expands to\n"
+"0";
   }},
   {
   R"cpp(// Macro
@@ -1604,6 +1651,8 @@
 HI.Name = "MACRO";
 HI.Kind = index::SymbolKind::Macro;
 HI.Definition = "#define MACRO 0";
+// NOTE MACRO doesn't have expansion since it technically isn't
+// expanded here
   }},
   {
   R"cpp(// Macro
@@ -1617,7 +1666,10 @@
 HI.Kind = index::SymbolKind::Macro;
 HI.Definition =
 R"cpp(#define MACRO  \
-  { return 0; })cpp";
+  { return 0; }
+
+// Expands to
+{ return 0; })cpp";
   }},
   {
   R"cpp(// Forward class declaration
@@ -2988,6 +3040,21 @@
 
 // In test::Bar
 int foo = 3)",
+  },
+  {
+  [](HoverInfo &HI) {
+HI.Kind = index::SymbolKind::Macro;
+HI.Name = "PLUS_ONE";
+HI.Definition = "#define PLUS_ONE(X) (X+1)\n\n"
+"// Expands to\n"
+"(1 + 1)";
+  },
+  R"(macro PLUS_ONE
+
+#define PLUS_ONE(X) (X+1)
+
+// Expands to
+(1 + 1))",
   },
   {
   [](HoverInfo &HI) {
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -666,7 +666,8 @@
 }
 
 /// Generate a \p Hover object given the macro \p MacroDecl.
-HoverInfo getHoverContents(const DefinedMacro &Macro, ParsedAST &AST) {
+HoverInfo getHoverContents(const DefinedMacro &Macro, const syntax::Token &Tok,
+   ParsedAST &AST) {
   HoverInfo HI;
   SourceManager &SM = AST.getSourceManager();
   HI.Name = std::string(Macro.Name);
@@ -697,6 +698,29 @@
 .str();

[PATCH] D131858: [clang] Track the templated entity in type substitution.

2022-09-07 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/lib/Serialization/ASTWriterDecl.cpp:623-626
+  VisitDeclaratorDecl(D);
+  Record.AddDeclarationNameLoc(D->DNLoc, D->getDeclName());
+  Record.push_back(D->getIdentifierNamespace());
+

ChuanqiXu wrote:
> ChuanqiXu wrote:
> > ChuanqiXu wrote:
> > > mizvekov wrote:
> > > > ChuanqiXu wrote:
> > > > > I still don't get the reason for the move. What's the benefit? Or why 
> > > > > is it necessary?
> > > > Yeah, now the type can reference the template decl, so without moving 
> > > > this, it can happen during import of the type that we try to read this 
> > > > function template bits without having imported them yet.
> > > Oh, I guess I met the problem before (D129748 ) and I made a workaround 
> > > for it (https://reviews.llvm.org/D130331). If I understood right, the 
> > > patch will solve that problem. I'll check it out later.
> > > 
> > > (This kind of code move looks dangerous you know and I'll take a double 
> > > check)
> > After looking into the detailed change for the serialization part, I feel 
> > it is a not-so-good workaround indeed.. It looks like we need a better 
> > method to delay reading the type in the serializer. And I'm looking at it. 
> > @mizvekov would you like to rebase the series of patches to the main branch 
> > so that I can test it actually.
> Or would it be simpler to rebase and squash them into a draft revision?
I had given this some thought, and it made sense to me that we should deal with 
the template bits first, since these are closer to the introducer for these 
declarations, and so that it would be harder to have a dependence the other way 
around.

But I would like to hear your thoughts on this after you have taken a better 
look.
I am working on a bunch of things right now, I should be able to rebase this on 
the next few days, but otherwise
I last rebased about 4 days ago, so you can also check that out at 
https://github.com/mizvekov/llvm-project/tree/resugar
That link has the whole stack, you probably should check out just the commit 
for this patch, as you are probably going to encounter issues with the 
resugarer if you try it on substantial code bases.
It will carry other changes with it, but I think those should be safe.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131858

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


[PATCH] D132810: [clang][MinGW] Add `-mguard=cf` and `-mguard=cf-nochecks`

2022-09-07 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk 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/D132810/new/

https://reviews.llvm.org/D132810

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


[PATCH] D133392: [MTE] Add AArch64GlobalsTagging Pass

2022-09-07 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 458472.
hctim marked 3 inline comments as done.
hctim added a comment.

Update from Florian's comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133392

Files:
  clang/test/CodeGen/memtag-globals-asm.cpp
  llvm/lib/CodeGen/GlobalMerge.cpp
  llvm/lib/MC/ELFObjectWriter.cpp
  llvm/lib/Target/AArch64/AArch64.h
  llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp
  llvm/lib/Target/AArch64/AArch64Subtarget.cpp
  llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
  llvm/lib/Target/AArch64/CMakeLists.txt
  llvm/test/CodeGen/AArch64/O0-pipeline.ll
  llvm/test/CodeGen/AArch64/O3-pipeline.ll

Index: llvm/test/CodeGen/AArch64/O3-pipeline.ll
===
--- llvm/test/CodeGen/AArch64/O3-pipeline.ll
+++ llvm/test/CodeGen/AArch64/O3-pipeline.ll
@@ -74,6 +74,7 @@
 ; CHECK-NEXT:   Expand reduction intrinsics
 ; CHECK-NEXT:   Natural Loop Information
 ; CHECK-NEXT:   TLS Variable Hoist
+; CHECK-NEXT: AArch64 Globals Tagging
 ; CHECK-NEXT: Stack Safety Analysis
 ; CHECK-NEXT:   FunctionPass Manager
 ; CHECK-NEXT: Dominator Tree Construction
Index: llvm/test/CodeGen/AArch64/O0-pipeline.ll
===
--- llvm/test/CodeGen/AArch64/O0-pipeline.ll
+++ llvm/test/CodeGen/AArch64/O0-pipeline.ll
@@ -24,6 +24,8 @@
 ; CHECK-NEXT:   Expand vector predication intrinsics
 ; CHECK-NEXT:   Scalarize Masked Memory Intrinsics
 ; CHECK-NEXT:   Expand reduction intrinsics
+; CHECK-NEXT: AArch64 Globals Tagging
+; CHECK-NEXT: FunctionPass Manager
 ; CHECK-NEXT:   AArch64 Stack Tagging
 ; CHECK-NEXT:   Exception handling preparation
 ; CHECK-NEXT:   Safe Stack instrumentation pass
Index: llvm/lib/Target/AArch64/CMakeLists.txt
===
--- llvm/lib/Target/AArch64/CMakeLists.txt
+++ llvm/lib/Target/AArch64/CMakeLists.txt
@@ -56,6 +56,7 @@
   AArch64FastISel.cpp
   AArch64A53Fix835769.cpp
   AArch64FrameLowering.cpp
+  AArch64GlobalsTagging.cpp
   AArch64CompressJumpTables.cpp
   AArch64ConditionOptimizer.cpp
   AArch64RedundantCopyElimination.cpp
Index: llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
===
--- llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
+++ llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
@@ -230,6 +230,7 @@
   initializeAArch64StackTaggingPass(*PR);
   initializeAArch64StackTaggingPreRAPass(*PR);
   initializeAArch64LowerHomogeneousPrologEpilogPass(*PR);
+  initializeAArch64GlobalsTaggingPass(*PR);
 }
 
 //===--===//
@@ -579,6 +580,7 @@
 
   TargetPassConfig::addIRPasses();
 
+  addPass(createAArch64GlobalsTaggingPass());
   addPass(createAArch64StackTaggingPass(
   /*IsOptNone=*/TM->getOptLevel() == CodeGenOpt::None));
 
Index: llvm/lib/Target/AArch64/AArch64Subtarget.cpp
===
--- llvm/lib/Target/AArch64/AArch64Subtarget.cpp
+++ llvm/lib/Target/AArch64/AArch64Subtarget.cpp
@@ -319,6 +319,13 @@
   if (TM.getCodeModel() == CodeModel::Large && isTargetMachO())
 return AArch64II::MO_GOT;
 
+  // All globals dynamically protected by MTE must have their address tags
+  // synthesized. This is done by having the loader stash the tag in the GOT
+  // entry. Force all tagged globals (even ones with internal linkage) through
+  // the GOT.
+  if (GV->isTagged())
+return AArch64II::MO_GOT;
+
   if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV)) {
 if (GV->hasDLLImportStorageClass())
   return AArch64II::MO_GOT | AArch64II::MO_DLLIMPORT;
Index: llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp
===
--- /dev/null
+++ llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp
@@ -0,0 +1,146 @@
+//===- AArch64GlobalsTagging.cpp - Global tagging in IR ---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//===--===//
+
+#include "AArch64.h"
+#include "llvm/BinaryFormat/ELF.h"
+#include "llvm/IR/Attributes.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/GlobalValue.h"
+#include "llvm/IR/GlobalVariable.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Pass.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include 
+#include 
+
+using namespace llvm;
+
+static const Align kTagGranuleSize = Align(16);
+
+namespace {
+
+class AArch64GlobalsTagging : public ModulePass {
+public:
+  static char I

[PATCH] D133392: [MTE] Add AArch64GlobalsTagging Pass

2022-09-07 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added inline comments.



Comment at: llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp:60
+  // gadgets.
+  if (G.getName().startswith("llvm.") || G.isThreadLocal() || G.isConstant()) {
+Meta.Memtag = false;

fmayer wrote:
> not necessarily in this CL: do we want some attribute to turn off 
> instrumentation?
memtag sanitization is not-implicit (i.e. it's opt-in rather than opt-out): 
https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/IR/GlobalValue.h#L327,
 so a turn-off attribute should be unnecessary



Comment at: llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp:108
+
+Value *Indices2[2];
+IRBuilder<> IRB(M.getContext());

fmayer wrote:
> what does this do?
dead code, thanks, removed


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133392

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


[PATCH] D133202: [Clang] Avoid __builtin_assume_aligned crash when the 1st arg is array type

2022-09-07 Thread Lin Yurong via Phabricator via cfe-commits
yronglin added a comment.

ping~


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133202

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


[PATCH] D133392: [MTE] Add AArch64GlobalsTagging Pass

2022-09-07 Thread Thorsten via Phabricator via cfe-commits
tschuett added inline comments.



Comment at: llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp:93
+
+  uint64_t NewSize = alignTo(SizeInBytes, 16);
+  if (SizeInBytes != NewSize) {

If the `16` is the size of the granule, then it deserves to be named constant. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133392

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


[PATCH] D131469: [Clang] change default storing path of `-ftime-trace`

2022-09-07 Thread Steven Wu via Phabricator via cfe-commits
steven_wu accepted this revision.
steven_wu added a comment.

Thanks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131469

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


[clang] a4a2943 - [RISCV][MC] Add minimal support for Ztso extension

2022-09-07 Thread Philip Reames via cfe-commits

Author: Philip Reames
Date: 2022-09-07T09:30:57-07:00
New Revision: a4a29438f451370ed241dde30bfcaab0fdf2ab71

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

LOG: [RISCV][MC] Add minimal support for Ztso extension

This is a minimalist implementation which simply adds the extension (in the 
experimental namespace since its not ratified), and wires up the setting of the 
required ELF header flag. Future changes will include codegen changes to 
exploit the stronger memory model.

This is intended to implement v0.1 of the proposed specification which can be 
found in Chapter 25 of 
https://github.com/riscv/riscv-isa-manual/releases/download/draft-20220723-10eea63/riscv-spec.pdf.

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

Added: 


Modified: 
clang/test/Preprocessor/riscv-target-features.c
llvm/lib/Support/RISCVISAInfo.cpp
llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
llvm/lib/Target/RISCV/RISCV.td
llvm/lib/Target/RISCV/RISCVSubtarget.h
llvm/test/CodeGen/RISCV/attributes.ll
llvm/test/MC/RISCV/attribute-arch.s
llvm/test/MC/RISCV/elf-flags.s

Removed: 




diff  --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index deb333c46dedd..9ec91171e8f05 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -462,3 +462,11 @@
 // RUN: %clang -target riscv64 -march=rv64izicbop -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZICBOP-EXT %s
 // CHECK-ZICBOP-EXT: __riscv_zicbop 100{{$}}
+
+// RUN: %clang -target riscv32-unknown-linux-gnu 
-menable-experimental-extensions \
+// RUN: -march=rv32iztso0p1 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZTSO-EXT %s
+// RUN: %clang -target riscv64-unknown-linux-gnu 
-menable-experimental-extensions \
+// RUN: -march=rv64iztso0p1 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZTSO-EXT %s
+// CHECK-ZTSO-EXT: __riscv_ztso 1000{{$}}

diff  --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index a666337ee5619..8deedfb8c8fd7 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -114,6 +114,7 @@ static const RISCVSupportedExtension 
SupportedExperimentalExtensions[] = {
 {"zbt", RISCVExtensionVersion{0, 93}},
 {"zca", RISCVExtensionVersion{0, 70}},
 {"zvfh", RISCVExtensionVersion{0, 1}},
+{"ztso", RISCVExtensionVersion{0, 1}},
 };
 
 static bool stripExperimentalPrefix(StringRef &Ext) {

diff  --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp 
b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
index c5f8a42bab6a5..fef8cb2798a39 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
@@ -157,6 +157,8 @@ void RISCVTargetELFStreamer::finish() {
 
   if (Features[RISCV::FeatureStdExtC])
 EFlags |= ELF::EF_RISCV_RVC;
+  if (Features[RISCV::FeatureStdExtZtso])
+EFlags |= ELF::EF_RISCV_TSO;
 
   switch (ABI) {
   case RISCVABI::ABI_ILP32:

diff  --git a/llvm/lib/Target/RISCV/RISCV.td b/llvm/lib/Target/RISCV/RISCV.td
index 6d9836f28a1bd..b4f3416857749 100644
--- a/llvm/lib/Target/RISCV/RISCV.td
+++ b/llvm/lib/Target/RISCV/RISCV.td
@@ -454,6 +454,13 @@ def HasStdExtZicbop : 
Predicate<"Subtarget->hasStdExtZicbop()">,
 AssemblerPredicate<(all_of 
FeatureStdExtZicbop),
 "'Zicbop' (Cache-Block Prefetch 
Instructions)">;
 
+def FeatureStdExtZtso
+: SubtargetFeature<"experimental-ztso", "HasStdExtZtso", "true",
+   "'Ztso' (Memory Model - Total Store Order)">;
+def HasStdExtZtso : Predicate<"Subtarget->hasStdExtZTso()">,
+   AssemblerPredicate<(all_of FeatureStdExtZtso),
+   "'Ztso' (Memory Model - Total Store Order)">;
+
 // Feature32Bit exists to mark CPUs that support RV32 to distinquish them from
 // tuning CPU names.
 def Feature32Bit

diff  --git a/llvm/lib/Target/RISCV/RISCVSubtarget.h 
b/llvm/lib/Target/RISCV/RISCVSubtarget.h
index 461968d40311f..3c95e062a13d5 100644
--- a/llvm/lib/Target/RISCV/RISCVSubtarget.h
+++ b/llvm/lib/Target/RISCV/RISCVSubtarget.h
@@ -92,6 +92,7 @@ class RISCVSubtarget : public RISCVGenSubtargetInfo {
   bool HasStdExtZicboz = false;
   bool HasStdExtZicbop = false;
   bool HasStdExtZmmul = false;
+  bool HasStdExtZtso = false;
   bool HasRV32 = false;
   bool HasRV64 = false;
   bool IsRV32E = false;
@@ -192,6 +193,7 @@ class RISCVSubtarget : public RISCVGenSubtargetInfo {
   bool hasStdExtZicboz() const { return HasStdExtZicboz; }
   bool hasStdExtZicbop() const { return HasStdExtZicbop; }
   bool hasS

[PATCH] D133239: [RISCV][MC] Add minimal support for Ztso extension

2022-09-07 Thread Philip Reames via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa4a29438f451: [RISCV][MC] Add minimal support for Ztso 
extension (authored by reames).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133239

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/elf-flags.s

Index: llvm/test/MC/RISCV/elf-flags.s
===
--- llvm/test/MC/RISCV/elf-flags.s
+++ llvm/test/MC/RISCV/elf-flags.s
@@ -5,6 +5,8 @@
 # RUN: llvm-mc -triple=riscv32 -mattr=+e -filetype=obj < %s \
 # RUN:   | llvm-readobj --file-headers - \
 # RUN:   | FileCheck -check-prefix=CHECK-RVE %s
+# RUN: llvm-mc -triple=riscv32 -mattr=+experimental-ztso -filetype=obj < %s | llvm-readobj --file-headers - | FileCheck -check-prefixes=CHECK-TSO %s
+# RUN: llvm-mc -triple=riscv64 -mattr=+experimental-ztso -filetype=obj < %s | llvm-readobj --file-headers - | FileCheck -check-prefixes=CHECK-TSO %s
 
 # CHECK-RVI:   Flags [ (0x0)
 # CHECK-RVI-NEXT:  ]
@@ -17,4 +19,8 @@
 # CHECK-RVE-NEXT: EF_RISCV_RVE (0x8)
 # CHECK-RVE-NEXT:   ]
 
+# CHECK-TSO:Flags [ (0x10)
+# CHECK-NEXT-TSO  EF_RISCV_TSO (0x10)
+# CHECK-NEXT-TSO]
+
 nop
Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -196,3 +196,6 @@
 
 .attribute arch, "rv32izca0p70"
 # CHECK: attribute  5, "rv32i2p0_zca0p70"
+
+.attribute arch, "rv32iztso0p1"
+# CHECK: attribute  5, "rv32i2p0_ztso0p1"
Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -84,6 +84,7 @@
 ; RUN: llc -mtriple=riscv64 -mattr=+zicbom %s -o - | FileCheck --check-prefix=RV64ZICBOM %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zicboz %s -o - | FileCheck --check-prefix=RV64ZICBOZ %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zicbop %s -o - | FileCheck --check-prefix=RV64ZICBOP %s
+; RUN: llc -mtriple=riscv64 -mattr=+experimental-ztso %s -o - | FileCheck --check-prefix=RV64ZTSO %s
 
 ; RV32M: .attribute 5, "rv32i2p0_m2p0"
 ; RV32ZMMUL: .attribute 5, "rv32i2p0_zmmul1p0"
@@ -170,6 +171,7 @@
 ; RV64ZICBOM: .attribute 5, "rv64i2p0_zicbom1p0"
 ; RV64ZICBOZ: .attribute 5, "rv64i2p0_zicboz1p0"
 ; RV64ZICBOP: .attribute 5, "rv64i2p0_zicbop1p0"
+; RV64ZTSO: .attribute 5, "rv64i2p0_ztso0p1"
 
 define i32 @addi(i32 %a) {
   %1 = add i32 %a, 1
Index: llvm/lib/Target/RISCV/RISCVSubtarget.h
===
--- llvm/lib/Target/RISCV/RISCVSubtarget.h
+++ llvm/lib/Target/RISCV/RISCVSubtarget.h
@@ -92,6 +92,7 @@
   bool HasStdExtZicboz = false;
   bool HasStdExtZicbop = false;
   bool HasStdExtZmmul = false;
+  bool HasStdExtZtso = false;
   bool HasRV32 = false;
   bool HasRV64 = false;
   bool IsRV32E = false;
@@ -192,6 +193,7 @@
   bool hasStdExtZicboz() const { return HasStdExtZicboz; }
   bool hasStdExtZicbop() const { return HasStdExtZicbop; }
   bool hasStdExtZmmul() const { return HasStdExtZmmul; }
+  bool hasStdExtZtso() const { return HasStdExtZtso; }
   bool is64Bit() const { return HasRV64; }
   bool isRV32E() const { return IsRV32E; }
   bool enableLinkerRelax() const { return EnableLinkerRelax; }
Index: llvm/lib/Target/RISCV/RISCV.td
===
--- llvm/lib/Target/RISCV/RISCV.td
+++ llvm/lib/Target/RISCV/RISCV.td
@@ -454,6 +454,13 @@
 AssemblerPredicate<(all_of FeatureStdExtZicbop),
 "'Zicbop' (Cache-Block Prefetch Instructions)">;
 
+def FeatureStdExtZtso
+: SubtargetFeature<"experimental-ztso", "HasStdExtZtso", "true",
+   "'Ztso' (Memory Model - Total Store Order)">;
+def HasStdExtZtso : Predicate<"Subtarget->hasStdExtZTso()">,
+   AssemblerPredicate<(all_of FeatureStdExtZtso),
+   "'Ztso' (Memory Model - Total Store Order)">;
+
 // Feature32Bit exists to mark CPUs that support RV32 to distinquish them from
 // tuning CPU names.
 def Feature32Bit
Index: llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
===
--- llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
+++ llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
@@ -157,6 +157,8 @@
 
   if (Features[RISCV::FeatureStdExtC])
 EFlags |= ELF::EF_RISCV_RVC;
+  if 

[clang] 6ed21fc - Avoid __builtin_assume_aligned crash when the 1st arg is array type

2022-09-07 Thread Aaron Ballman via cfe-commits

Author: yronglin
Date: 2022-09-07T12:46:20-04:00
New Revision: 6ed21fc515230ac2ea459d8aa90566e9a467bbb0

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

LOG: Avoid __builtin_assume_aligned crash when the 1st arg is array type

Avoid __builtin_assume_aligned crash when the 1st arg is array type (or
string literal).

Fixes Issue #57169

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

Added: 
clang/test/CodeGen/catch-alignment-assumption-array.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/Sema/SemaChecking.cpp
clang/test/CodeGen/catch-alignment-assumption-ignorelist.c
clang/test/Sema/builtin-assume-aligned.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 882d42d550409..b370d23856c21 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -91,6 +91,8 @@ Bug Fixes
   `Issue 57431 `_
 - Fix a crash where we attempt to define a deleted destructor. This fixes
   `Issue 57516 `_
+- Fix ``__builtin_assume_aligned`` crash when the 1st arg is array type. This 
fixes
+  `Issue 57169 `_
 
 
 Improvements to Clang's diagnostics

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index d5b5049494470..5af3811988e1c 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -2781,6 +2781,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   case Builtin::BI__builtin_assume_aligned: {
 const Expr *Ptr = E->getArg(0);
 Value *PtrValue = EmitScalarExpr(Ptr);
+if (PtrValue->getType() != VoidPtrTy)
+  PtrValue = EmitCastToVoidPtr(PtrValue);
 Value *OffsetValue =
   (E->getNumArgs() > 2) ? EmitScalarExpr(E->getArg(2)) : nullptr;
 

diff  --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index caf14868078ec..35a8f1dc6a2f8 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -2443,8 +2443,6 @@ void CodeGenFunction::emitAlignmentAssumption(llvm::Value 
*PtrValue,
   SourceLocation AssumptionLoc,
   llvm::Value *Alignment,
   llvm::Value *OffsetValue) {
-  if (auto *CE = dyn_cast(E))
-E = CE->getSubExprAsWritten();
   QualType Ty = E->getType();
   SourceLocation Loc = E->getExprLoc();
 

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index fcdc866e6947a..53c108356316e 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -128,6 +128,19 @@ static bool checkArgCountAtLeast(Sema &S, CallExpr *Call,
  << Call->getSourceRange();
 }
 
+/// Checks that a call expression's argument count is at most the desired
+/// number. This is useful when doing custom type-checking on a variadic
+/// function. Returns true on error.
+static bool checkArgCountAtMost(Sema &S, CallExpr *Call, unsigned MaxArgCount) 
{
+  unsigned ArgCount = Call->getNumArgs();
+  if (ArgCount <= MaxArgCount)
+return false;
+  return S.Diag(Call->getEndLoc(),
+diag::err_typecheck_call_too_many_args_at_most)
+ << 0 /*function call*/ << MaxArgCount << ArgCount
+ << Call->getSourceRange();
+}
+
 /// Checks that a call expression's argument count is the desired number.
 /// This is useful when doing custom type-checking.  Returns true on error.
 static bool checkArgCount(Sema &S, CallExpr *Call, unsigned DesiredArgCount) {
@@ -148,6 +161,20 @@ static bool checkArgCount(Sema &S, CallExpr *Call, 
unsigned DesiredArgCount) {
  << Call->getArg(1)->getSourceRange();
 }
 
+static bool convertArgumentToType(Sema &S, Expr *&Value, QualType Ty) {
+  if (Value->isTypeDependent())
+return false;
+
+  InitializedEntity Entity =
+  InitializedEntity::InitializeParameter(S.Context, Ty, false);
+  ExprResult Result =
+  S.PerformCopyInitialization(Entity, SourceLocation(), Value);
+  if (Result.isInvalid())
+return true;
+  Value = Result.get();
+  return false;
+}
+
 /// Check that the first argument to __builtin_annotation is an integer
 /// and the second argument is a non-wide string literal.
 static bool SemaBuiltinAnnotation(Sema &S, CallExpr *TheCall) {
@@ -7616,38 +7643,45 @@ bool Sema::SemaBuiltinAllocaWithAlign(CallExpr 
*TheCall) {
 /// Handle __builtin_assume_aligned. This is declared
 /// as (const void*, size_t, ...) and can take one optional constant int arg.
 bool Sema::

[PATCH] D133202: [Clang] Avoid __builtin_assume_aligned crash when the 1st arg is array type

2022-09-07 Thread Aaron Ballman 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 rG6ed21fc51523: Avoid __builtin_assume_aligned crash when the 
1st arg is array type (authored by yronglin, committed by aaron.ballman).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133202

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/catch-alignment-assumption-array.c
  clang/test/CodeGen/catch-alignment-assumption-ignorelist.c
  clang/test/Sema/builtin-assume-aligned.c

Index: clang/test/Sema/builtin-assume-aligned.c
===
--- clang/test/Sema/builtin-assume-aligned.c
+++ clang/test/Sema/builtin-assume-aligned.c
@@ -66,6 +66,11 @@
 }
 #endif
 
+int test13(int *a) {
+  a = (int *)__builtin_assume_aligned(a, 2 * 2.0); // expected-error {{argument to '__builtin_assume_aligned' must be a constant integer}}
+  return a[0];
+}
+
 void test_void_assume_aligned(void) __attribute__((assume_aligned(32))); // expected-warning {{'assume_aligned' attribute only applies to return values that are pointers}}
 int test_int_assume_aligned(void) __attribute__((assume_aligned(16))); // expected-warning {{'assume_aligned' attribute only applies to return values that are pointers}}
 void *test_ptr_assume_aligned(void) __attribute__((assume_aligned(64))); // no-warning
Index: clang/test/CodeGen/catch-alignment-assumption-ignorelist.c
===
--- clang/test/CodeGen/catch-alignment-assumption-ignorelist.c
+++ clang/test/CodeGen/catch-alignment-assumption-ignorelist.c
@@ -26,3 +26,9 @@
 void *ignore_volatiles(volatile void * x) {
   return __builtin_assume_aligned(x, 1);
 }
+
+// CHECK-LABEL: ignore_array_volatiles
+void *ignore_array_volatiles() {
+  volatile int arr[] = {1};
+  return __builtin_assume_aligned(arr, 4);
+}
Index: clang/test/CodeGen/catch-alignment-assumption-array.c
===
--- /dev/null
+++ clang/test/CodeGen/catch-alignment-assumption-array.c
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -no-opaque-pointers -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s
+// RUN: %clang_cc1 -no-opaque-pointers -fsanitize=alignment -fno-sanitize-recover=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-ANYRECOVER,CHECK-SANITIZE-NORECOVER,CHECK-SANITIZE-UNREACHABLE
+// RUN: %clang_cc1 -no-opaque-pointers -fsanitize=alignment -fsanitize-recover=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-ANYRECOVER,CHECK-SANITIZE-RECOVER
+// RUN: %clang_cc1 -no-opaque-pointers -fsanitize=alignment -fsanitize-trap=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-TRAP,CHECK-SANITIZE-UNREACHABLE
+
+// CHECK-SANITIZE-ANYRECOVER: @[[CHAR:.*]] = {{.*}} c"'char *'\00" }
+// CHECK-SANITIZE-ANYRECOVER: @[[ALIGNMENT_ASSUMPTION:.*]] = {{.*}}, i32 31, i32 35 }, {{.*}}* @[[CHAR]] }
+
+void *caller(void) {
+  char str[] = "";
+  // CHECK:   define{{.*}}
+  // CHECK-NEXT:  entry:
+  // CHECK-NEXT:%[[STR:.*]] = alloca [1 x i8], align 1
+  // CHECK-NEXT:%[[BITCAST:.*]] = bitcast [1 x i8]* %[[STR]] to i8*
+  // CHECK-NEXT:call void @llvm.memset.p0i8.i64(i8* align 1 %[[BITCAST]], i8 0, i64 1, i1 false)
+  // CHECK-NEXT:%[[ARRAYDECAY:.*]] = getelementptr inbounds [1 x i8], [1 x i8]* %[[STR]], i64 0, i64 0
+  // CHECK-SANITIZE-NEXT:   %[[PTRINT:.*]] = ptrtoint i8* %[[ARRAYDECAY]] to i64
+  // CHECK-SANITIZE-NEXT:   %[[MASKEDPTR:.*]] = and i64 %[[PTRINT]], 0
+  // CHECK-SANITIZE-NEXT:   %[[MASKCOND:.*]] = icmp eq i64 %[[MASKEDPTR]], 0
+  // CHECK-SANITIZE-NEXT:   %[[PTRINT_DUP:.*]] = ptrtoint i8* %[[ARRAYDECAY]] to i64, !nosanitize
+  // CHECK-SANITIZE-NEXT:   br i1 %[[MASKCOND]], label %[[CONT:.*]], label %[[HANDLER_ALIGNMENT_ASSUMPTION:[^,]+]],{{.*}} !nosanitize
+  // CHECK-SANITIZE:  [[HANDLER_ALIGNMENT_ASSUMPTION]]:
+  // CHECK-SANITIZE-NORECOVER-NEXT: call void @__ubsan_handle_alignment_assumption_abort(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 1, i64 0){{.*}}, !nosanitize
+  // CHECK-SANITIZE-RECOVER-NEXT:   call void @__ubsan_h

[PATCH] D133202: [Clang] Avoid __builtin_assume_aligned crash when the 1st arg is array type

2022-09-07 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

I've pushed the changes up for you, thanks!

In D133202#3774801 , @yronglin wrote:

> ping~

Something to keep in mind for the future: we typically only "ping" a review 
after about a week of no activity on it (just because folks end up being busy, 
taking vacation, want to contemplate the review for a while, etc).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133202

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


[PATCH] D133392: [MTE] Add AArch64GlobalsTagging Pass

2022-09-07 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 458487.
hctim marked an inline comment as done.
hctim added a comment.

Update inlined constants to use named constant.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133392

Files:
  clang/test/CodeGen/memtag-globals-asm.cpp
  llvm/lib/CodeGen/GlobalMerge.cpp
  llvm/lib/MC/ELFObjectWriter.cpp
  llvm/lib/Target/AArch64/AArch64.h
  llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp
  llvm/lib/Target/AArch64/AArch64Subtarget.cpp
  llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
  llvm/lib/Target/AArch64/CMakeLists.txt
  llvm/test/CodeGen/AArch64/O0-pipeline.ll
  llvm/test/CodeGen/AArch64/O3-pipeline.ll

Index: llvm/test/CodeGen/AArch64/O3-pipeline.ll
===
--- llvm/test/CodeGen/AArch64/O3-pipeline.ll
+++ llvm/test/CodeGen/AArch64/O3-pipeline.ll
@@ -74,6 +74,7 @@
 ; CHECK-NEXT:   Expand reduction intrinsics
 ; CHECK-NEXT:   Natural Loop Information
 ; CHECK-NEXT:   TLS Variable Hoist
+; CHECK-NEXT: AArch64 Globals Tagging
 ; CHECK-NEXT: Stack Safety Analysis
 ; CHECK-NEXT:   FunctionPass Manager
 ; CHECK-NEXT: Dominator Tree Construction
Index: llvm/test/CodeGen/AArch64/O0-pipeline.ll
===
--- llvm/test/CodeGen/AArch64/O0-pipeline.ll
+++ llvm/test/CodeGen/AArch64/O0-pipeline.ll
@@ -24,6 +24,8 @@
 ; CHECK-NEXT:   Expand vector predication intrinsics
 ; CHECK-NEXT:   Scalarize Masked Memory Intrinsics
 ; CHECK-NEXT:   Expand reduction intrinsics
+; CHECK-NEXT: AArch64 Globals Tagging
+; CHECK-NEXT: FunctionPass Manager
 ; CHECK-NEXT:   AArch64 Stack Tagging
 ; CHECK-NEXT:   Exception handling preparation
 ; CHECK-NEXT:   Safe Stack instrumentation pass
Index: llvm/lib/Target/AArch64/CMakeLists.txt
===
--- llvm/lib/Target/AArch64/CMakeLists.txt
+++ llvm/lib/Target/AArch64/CMakeLists.txt
@@ -56,6 +56,7 @@
   AArch64FastISel.cpp
   AArch64A53Fix835769.cpp
   AArch64FrameLowering.cpp
+  AArch64GlobalsTagging.cpp
   AArch64CompressJumpTables.cpp
   AArch64ConditionOptimizer.cpp
   AArch64RedundantCopyElimination.cpp
Index: llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
===
--- llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
+++ llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
@@ -230,6 +230,7 @@
   initializeAArch64StackTaggingPass(*PR);
   initializeAArch64StackTaggingPreRAPass(*PR);
   initializeAArch64LowerHomogeneousPrologEpilogPass(*PR);
+  initializeAArch64GlobalsTaggingPass(*PR);
 }
 
 //===--===//
@@ -579,6 +580,7 @@
 
   TargetPassConfig::addIRPasses();
 
+  addPass(createAArch64GlobalsTaggingPass());
   addPass(createAArch64StackTaggingPass(
   /*IsOptNone=*/TM->getOptLevel() == CodeGenOpt::None));
 
Index: llvm/lib/Target/AArch64/AArch64Subtarget.cpp
===
--- llvm/lib/Target/AArch64/AArch64Subtarget.cpp
+++ llvm/lib/Target/AArch64/AArch64Subtarget.cpp
@@ -319,6 +319,13 @@
   if (TM.getCodeModel() == CodeModel::Large && isTargetMachO())
 return AArch64II::MO_GOT;
 
+  // All globals dynamically protected by MTE must have their address tags
+  // synthesized. This is done by having the loader stash the tag in the GOT
+  // entry. Force all tagged globals (even ones with internal linkage) through
+  // the GOT.
+  if (GV->isTagged())
+return AArch64II::MO_GOT;
+
   if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV)) {
 if (GV->hasDLLImportStorageClass())
   return AArch64II::MO_GOT | AArch64II::MO_DLLIMPORT;
Index: llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp
===
--- /dev/null
+++ llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp
@@ -0,0 +1,146 @@
+//===- AArch64GlobalsTagging.cpp - Global tagging in IR ---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//===--===//
+
+#include "AArch64.h"
+#include "llvm/BinaryFormat/ELF.h"
+#include "llvm/IR/Attributes.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/GlobalValue.h"
+#include "llvm/IR/GlobalVariable.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Pass.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include 
+#include 
+
+using namespace llvm;
+
+static const Align kTagGranuleSize = Align(16);
+
+namespace {
+
+class AArch64GlobalsTagging : public ModulePass {
+public:

[PATCH] D133202: [Clang] Avoid __builtin_assume_aligned crash when the 1st arg is array type

2022-09-07 Thread Lin Yurong via Phabricator via cfe-commits
yronglin added a comment.

In D133202#3774905 , @aaron.ballman 
wrote:

> I've pushed the changes up for you, thanks!
>
> In D133202#3774801 , @yronglin 
> wrote:
>
>> ping~
>
> Something to keep in mind for the future: we typically only "ping" a review 
> after about a week of no activity on it (just because folks end up being 
> busy, taking vacation, want to contemplate the review for a while, etc).

Thanks a lot Aaron, I will remember what you said.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133202

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


[PATCH] D133436: Ground work for cuda-related checks in clang-tidy

2022-09-07 Thread Bartłomiej Cieślar via Phabricator via cfe-commits
barcisz created this revision.
Herald added subscribers: mattd, carlosgalvezp, yaxunl, mgorny.
Herald added a project: All.
barcisz requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Signed-off-by: bcieslar 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133436

Files:
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
  clang-tools-extra/clang-tidy/cuda/CMakeLists.txt
  clang-tools-extra/clang-tidy/cuda/CudaTidyModule.cpp
  clang-tools-extra/test/clang-tidy/check_clang_tidy.py
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/cuda/cuda-initializers.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/cuda/cuda.h
  clang-tools-extra/test/clang-tidy/checkers/cuda/.keep
  clang-tools-extra/test/lit.cfg.py

Index: clang-tools-extra/test/lit.cfg.py
===
--- clang-tools-extra/test/lit.cfg.py
+++ clang-tools-extra/test/lit.cfg.py
@@ -16,7 +16,7 @@
 config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
 
 # suffixes: A list of file extensions to treat as test files.
-config.suffixes = ['.c', '.cpp', '.hpp', '.m', '.mm', '.cu', '.ll', '.cl', '.s',
+config.suffixes = ['.c', '.cpp', '.cu', '.hpp', '.m', '.mm', '.cu', '.ll', '.cl', '.s',
   '.modularize', '.module-map-checker', '.test']
 
 # Test-time dependencies located in directories called 'Inputs' are excluded
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/cuda/cuda.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/cuda/cuda.h
@@ -0,0 +1,28 @@
+/* Minimal declarations for CUDA support.  Testing purposes only. */
+
+#include 
+
+#define __constant__ __attribute__((constant))
+#define __device__ __attribute__((device))
+#define __global__ __attribute__((global))
+#define __host__ __attribute__((host))
+#define __shared__ __attribute__((shared))
+
+struct dim3 {
+  unsigned x, y, z;
+  __host__ __device__ dim3(unsigned x, unsigned y = 1, unsigned z = 1) : x(x), y(y), z(z) {}
+};
+
+typedef struct cudaStream *cudaStream_t;
+typedef enum cudaError {} cudaError_t;
+extern "C" int cudaConfigureCall(dim3 gridSize, dim3 blockSize,
+ size_t sharedSize = 0,
+ cudaStream_t stream = 0);
+extern "C" int __cudaPushCallConfiguration(dim3 gridSize, dim3 blockSize,
+   size_t sharedSize = 0,
+   cudaStream_t stream = 0);
+extern "C" cudaError_t cudaLaunchKernel(const void *func, dim3 gridDim,
+dim3 blockDim, void **args,
+size_t sharedMem, cudaStream_t stream);
+
+extern "C" __device__ int printf(const char*, ...);
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/cuda/cuda-initializers.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/cuda/cuda-initializers.h
@@ -0,0 +1,145 @@
+// CUDA struct types with interesting initialization properties.
+// Keep in sync with clang/test/SemaCUDA/Inputs/cuda-initializers.h.
+
+// Base classes with different initializer variants.
+
+// trivial constructor -- allowed
+struct T {
+  int t;
+};
+
+// empty constructor
+struct EC {
+  int ec;
+  __device__ EC() {} // -- allowed
+  __device__ EC(int) {}  // -- not allowed
+};
+
+// empty destructor
+struct ED {
+  __device__ ~ED() {} // -- allowed
+};
+
+struct ECD {
+  __device__ ECD() {} // -- allowed
+  __device__ ~ECD() {}// -- allowed
+};
+
+// empty templated constructor -- allowed with no arguments
+struct ETC {
+  template  __device__ ETC(T...) {}
+};
+
+// undefined constructor -- not allowed
+struct UC {
+  int uc;
+  __device__ UC();
+};
+
+// undefined destructor -- not allowed
+struct UD {
+  int ud;
+  __device__ ~UD();
+};
+
+// empty constructor w/ initializer list -- not allowed
+struct ECI {
+  int eci;
+  __device__ ECI() : eci(1) {}
+};
+
+// non-empty constructor -- not allowed
+struct NEC {
+  int nec;
+  __device__ NEC() { nec = 1; }
+};
+
+// non-empty destructor -- not allowed
+struct NED {
+  int ned;
+  __device__ ~NED() { ned = 1; }
+};
+
+// no-constructor,  virtual method -- not allowed
+struct NCV {
+  int ncv;
+  __device__ virtual void vm() {}
+};
+
+// virtual destructor -- not allowed.
+struct VD {
+  __device__ virtual ~VD() {}
+};
+
+// dynamic in-class field initializer -- not allowed
+__device__ int f();
+struct NCF {
+  int ncf = f();
+};
+
+// static in-class field initializer.  NVCC does not allow it, but
+// clang generates static initializer for this, so we'll accept it.
+// We still can't use it on __shared__ vars as they don't allow *any*
+// initializers.
+struct 

[PATCH] D133436: Ground work for cuda-related checks in clang-tidy

2022-09-07 Thread Thorsten via Phabricator via cfe-commits
tschuett added inline comments.



Comment at: clang-tools-extra/clang-tidy/cuda/CudaTidyModule.cpp:25
+
+// Register the GoogleTidyModule using this statically initialized variable.
+static ClangTidyModuleRegistry::Add

Is Google a copy and paste error?



Comment at: clang-tools-extra/clang-tidy/cuda/CudaTidyModule.cpp:32
+// This anchor is used to force the linker to link in the generated object file
+// and thus register the GoogleModule.
+volatile int CudaModuleAnchorSource = 0;

Is Google a copy and paste error?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133436

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


[PATCH] D133357: [Lex/DependencyDirectivesScanner] Keep track of the presence of tokens between the last scanned directive and EOF

2022-09-07 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi updated this revision to Diff 458499.
akyrtzi added a comment.

Remove leftover doc-comment parameter.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133357

Files:
  clang/include/clang/Lex/DependencyDirectivesScanner.h
  clang/lib/Lex/DependencyDirectivesScanner.cpp
  clang/lib/Lex/Lexer.cpp
  clang/unittests/Lex/CMakeLists.txt
  clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
  clang/unittests/Lex/PPDependencyDirectivesTest.cpp

Index: clang/unittests/Lex/PPDependencyDirectivesTest.cpp
===
--- /dev/null
+++ clang/unittests/Lex/PPDependencyDirectivesTest.cpp
@@ -0,0 +1,148 @@
+//===- unittests/Lex/PPDependencyDirectivesTest.cpp -=//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/Basic/TargetOptions.h"
+#include "clang/Lex/DependencyDirectivesScanner.h"
+#include "clang/Lex/HeaderSearch.h"
+#include "clang/Lex/HeaderSearchOptions.h"
+#include "clang/Lex/ModuleLoader.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/PreprocessorOptions.h"
+#include "llvm/Testing/Support/Error.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+
+namespace {
+
+// The test fixture.
+class PPDependencyDirectivesTest : public ::testing::Test {
+protected:
+  PPDependencyDirectivesTest()
+  : FileMgr(FileMgrOpts), DiagID(new DiagnosticIDs()),
+Diags(DiagID, new DiagnosticOptions, new IgnoringDiagConsumer()),
+SourceMgr(Diags, FileMgr), TargetOpts(new TargetOptions) {
+TargetOpts->Triple = "x86_64-apple-macos12";
+Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts);
+  }
+
+  FileSystemOptions FileMgrOpts;
+  FileManager FileMgr;
+  IntrusiveRefCntPtr DiagID;
+  DiagnosticsEngine Diags;
+  SourceManager SourceMgr;
+  LangOptions LangOpts;
+  std::shared_ptr TargetOpts;
+  IntrusiveRefCntPtr Target;
+};
+
+class IncludeCollector : public PPCallbacks {
+public:
+  Preprocessor &PP;
+  SmallVectorImpl &IncludedFiles;
+
+  IncludeCollector(Preprocessor &PP, SmallVectorImpl &IncludedFiles)
+  : PP(PP), IncludedFiles(IncludedFiles) {}
+
+  void LexedFileChanged(FileID FID, LexedFileChangeReason Reason,
+SrcMgr::CharacteristicKind FileType, FileID PrevFID,
+SourceLocation Loc) override {
+if (Reason != LexedFileChangeReason::EnterFile)
+  return;
+if (FID == PP.getPredefinesFileID())
+  return;
+StringRef Filename =
+PP.getSourceManager().getSLocEntry(FID).getFile().getName();
+IncludedFiles.push_back(Filename);
+  }
+};
+
+TEST_F(PPDependencyDirectivesTest, MacroGuard) {
+  // "head1.h" has a macro guard and should only be included once.
+  // "head2.h" and "head3.h" have tokens following the macro check, they should
+  // be included multiple times.
+
+  auto VFS = new llvm::vfs::InMemoryFileSystem();
+  VFS->addFile(
+  "head1.h", 0,
+  llvm::MemoryBuffer::getMemBuffer("#ifndef H1_H\n#define H1_H\n#endif\n"));
+  VFS->addFile(
+  "head2.h", 0,
+  llvm::MemoryBuffer::getMemBuffer("#ifndef H2_H\n#define H2_H\n#endif\n\n"
+   "extern int foo;\n"));
+  VFS->addFile("head3.h", 0,
+   llvm::MemoryBuffer::getMemBuffer(
+   "#ifndef H3_H\n#define H3_H\n#endif\n\n"
+   "#ifdef SOMEMAC\nextern int foo;\n#endif\n"));
+  VFS->addFile("main.c", 0,
+   llvm::MemoryBuffer::getMemBuffer(
+   "#include \"head1.h\"\n#include \"head1.h\"\n"
+   "#include \"head2.h\"\n#include \"head2.h\"\n"
+   "#include \"head3.h\"\n#include \"head3.h\"\n"));
+  FileMgr.setVirtualFileSystem(VFS);
+
+  Optional FE;
+  ASSERT_THAT_ERROR(FileMgr.getFileRef("main.c").moveInto(FE),
+llvm::Succeeded());
+  SourceMgr.setMainFileID(
+  SourceMgr.createFileID(*FE, SourceLocation(), SrcMgr::C_User));
+
+  struct DepDirectives {
+SmallVector Tokens;
+SmallVector Directives;
+  };
+  SmallVector> DepDirectivesObjects;
+
+  auto getDependencyDirectives = [&](FileEntryRef File)
+  -> Optional> {
+DepDirectivesObjects.push_back(std::make_unique());
+StringRef Input = (*FileMgr.getBufferForFile(File))->getBuffer();
+bool Err = scanSourceForDependencyDirectives(
+Input, DepDirectivesObjects.back()->Tokens,
+DepDirectivesObjects.back()->Directives);
+EXPECT

[PATCH] D133436: Ground work for cuda-related checks in clang-tidy

2022-09-07 Thread Ivan Murashko via Phabricator via cfe-commits
ivanmurashko added inline comments.



Comment at: clang-tools-extra/test/lit.cfg.py:19
 # suffixes: A list of file extensions to treat as test files.
-config.suffixes = ['.c', '.cpp', '.hpp', '.m', '.mm', '.cu', '.ll', '.cl', 
'.s',
+config.suffixes = ['.c', '.cpp', '.cu', '.hpp', '.m', '.mm', '.cu', '.ll', 
'.cl', '.s',
   '.modularize', '.module-map-checker', '.test']

`.cu` is specified several times there. It looks like the change is not 
necessary at the line


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133436

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


[PATCH] D133436: Ground work for cuda-related checks in clang-tidy

2022-09-07 Thread Bartłomiej Cieślar via Phabricator via cfe-commits
barcisz updated this revision to Diff 458502.
barcisz added a comment.

Fixed a copy-paste error with Google->Cuda in CudaTidyModule.cpp


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133436

Files:
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
  clang-tools-extra/clang-tidy/cuda/CMakeLists.txt
  clang-tools-extra/clang-tidy/cuda/CudaTidyModule.cpp
  clang-tools-extra/test/clang-tidy/check_clang_tidy.py
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/cuda/cuda-initializers.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/cuda/cuda.h
  clang-tools-extra/test/clang-tidy/checkers/cuda/.keep
  clang-tools-extra/test/lit.cfg.py

Index: clang-tools-extra/test/lit.cfg.py
===
--- clang-tools-extra/test/lit.cfg.py
+++ clang-tools-extra/test/lit.cfg.py
@@ -16,7 +16,7 @@
 config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
 
 # suffixes: A list of file extensions to treat as test files.
-config.suffixes = ['.c', '.cpp', '.hpp', '.m', '.mm', '.cu', '.ll', '.cl', '.s',
+config.suffixes = ['.c', '.cpp', '.cu', '.hpp', '.m', '.mm', '.cu', '.ll', '.cl', '.s',
   '.modularize', '.module-map-checker', '.test']
 
 # Test-time dependencies located in directories called 'Inputs' are excluded
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/cuda/cuda.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/cuda/cuda.h
@@ -0,0 +1,28 @@
+/* Minimal declarations for CUDA support.  Testing purposes only. */
+
+#include 
+
+#define __constant__ __attribute__((constant))
+#define __device__ __attribute__((device))
+#define __global__ __attribute__((global))
+#define __host__ __attribute__((host))
+#define __shared__ __attribute__((shared))
+
+struct dim3 {
+  unsigned x, y, z;
+  __host__ __device__ dim3(unsigned x, unsigned y = 1, unsigned z = 1) : x(x), y(y), z(z) {}
+};
+
+typedef struct cudaStream *cudaStream_t;
+typedef enum cudaError {} cudaError_t;
+extern "C" int cudaConfigureCall(dim3 gridSize, dim3 blockSize,
+ size_t sharedSize = 0,
+ cudaStream_t stream = 0);
+extern "C" int __cudaPushCallConfiguration(dim3 gridSize, dim3 blockSize,
+   size_t sharedSize = 0,
+   cudaStream_t stream = 0);
+extern "C" cudaError_t cudaLaunchKernel(const void *func, dim3 gridDim,
+dim3 blockDim, void **args,
+size_t sharedMem, cudaStream_t stream);
+
+extern "C" __device__ int printf(const char*, ...);
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/cuda/cuda-initializers.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/cuda/cuda-initializers.h
@@ -0,0 +1,145 @@
+// CUDA struct types with interesting initialization properties.
+// Keep in sync with clang/test/SemaCUDA/Inputs/cuda-initializers.h.
+
+// Base classes with different initializer variants.
+
+// trivial constructor -- allowed
+struct T {
+  int t;
+};
+
+// empty constructor
+struct EC {
+  int ec;
+  __device__ EC() {} // -- allowed
+  __device__ EC(int) {}  // -- not allowed
+};
+
+// empty destructor
+struct ED {
+  __device__ ~ED() {} // -- allowed
+};
+
+struct ECD {
+  __device__ ECD() {} // -- allowed
+  __device__ ~ECD() {}// -- allowed
+};
+
+// empty templated constructor -- allowed with no arguments
+struct ETC {
+  template  __device__ ETC(T...) {}
+};
+
+// undefined constructor -- not allowed
+struct UC {
+  int uc;
+  __device__ UC();
+};
+
+// undefined destructor -- not allowed
+struct UD {
+  int ud;
+  __device__ ~UD();
+};
+
+// empty constructor w/ initializer list -- not allowed
+struct ECI {
+  int eci;
+  __device__ ECI() : eci(1) {}
+};
+
+// non-empty constructor -- not allowed
+struct NEC {
+  int nec;
+  __device__ NEC() { nec = 1; }
+};
+
+// non-empty destructor -- not allowed
+struct NED {
+  int ned;
+  __device__ ~NED() { ned = 1; }
+};
+
+// no-constructor,  virtual method -- not allowed
+struct NCV {
+  int ncv;
+  __device__ virtual void vm() {}
+};
+
+// virtual destructor -- not allowed.
+struct VD {
+  __device__ virtual ~VD() {}
+};
+
+// dynamic in-class field initializer -- not allowed
+__device__ int f();
+struct NCF {
+  int ncf = f();
+};
+
+// static in-class field initializer.  NVCC does not allow it, but
+// clang generates static initializer for this, so we'll accept it.
+// We still can't use it on __shared__ vars as they don't allow *any*
+// initializers.
+struct NCFS {
+  int ncfs = 3;
+};
+
+// undefined templated constructor -- not

[clang] aa484c9 - [Lex/DependencyDirectivesScanner] Keep track of the presence of tokens between the last scanned directive and EOF

2022-09-07 Thread Argyrios Kyrtzidis via cfe-commits

Author: Argyrios Kyrtzidis
Date: 2022-09-07T10:31:29-07:00
New Revision: aa484c90cf5902042cec0f6a4f3bf2a460eea307

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

LOG: [Lex/DependencyDirectivesScanner] Keep track of the presence of tokens 
between the last scanned directive and EOF

Directive `dependency_directives_scan::tokens_present_before_eof` is introduced 
to indicate there were tokens present before
the last scanned dependency directive and EOF.
This is useful to ensure we correctly identify the macro guards when lexing 
using the dependency directives.

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

Added: 
clang/unittests/Lex/PPDependencyDirectivesTest.cpp

Modified: 
clang/include/clang/Lex/DependencyDirectivesScanner.h
clang/lib/Lex/DependencyDirectivesScanner.cpp
clang/lib/Lex/Lexer.cpp
clang/unittests/Lex/CMakeLists.txt
clang/unittests/Lex/DependencyDirectivesScannerTest.cpp

Removed: 




diff  --git a/clang/include/clang/Lex/DependencyDirectivesScanner.h 
b/clang/include/clang/Lex/DependencyDirectivesScanner.h
index ec6ac6173e855..529b93aa0ffbf 100644
--- a/clang/include/clang/Lex/DependencyDirectivesScanner.h
+++ b/clang/include/clang/Lex/DependencyDirectivesScanner.h
@@ -82,6 +82,9 @@ enum DirectiveKind : uint8_t {
   cxx_import_decl,
   cxx_export_module_decl,
   cxx_export_import_decl,
+  /// Indicates that there are tokens present between the last scanned 
directive
+  /// and eof. The \p Directive::Tokens array will be empty for this kind.
+  tokens_present_before_eof,
   pp_eof,
 };
 

diff  --git a/clang/lib/Lex/DependencyDirectivesScanner.cpp 
b/clang/lib/Lex/DependencyDirectivesScanner.cpp
index 0efcc352f0883..c0b1687b2847f 100644
--- a/clang/lib/Lex/DependencyDirectivesScanner.cpp
+++ b/clang/lib/Lex/DependencyDirectivesScanner.cpp
@@ -87,6 +87,9 @@ struct Scanner {
   dependency_directives_scan::Token &lexIncludeFilename(const char *&First,
 const char *const End);
 
+  void skipLine(const char *&First, const char *const End);
+  void skipDirective(StringRef Name, const char *&First, const char *const 
End);
+
   /// Lexes next token and if it is identifier returns its string, otherwise
   /// it skips the current line and returns \p None.
   ///
@@ -150,6 +153,7 @@ struct Scanner {
   DiagnosticsEngine *Diags;
   SourceLocation InputSourceLoc;
 
+  const char *LastTokenPtr = nullptr;
   /// Keeps track of the tokens for the currently lexed directive. Once a
   /// directive is fully lexed and "committed" then the tokens get appended to
   /// \p Tokens and \p CurDirToks is cleared for the next directive.
@@ -364,7 +368,7 @@ static bool isQuoteCppDigitSeparator(const char *const 
Start,
   return (Cur + 1) < End && isAsciiIdentifierContinue(*(Cur + 1));
 }
 
-static void skipLine(const char *&First, const char *const End) {
+void Scanner::skipLine(const char *&First, const char *const End) {
   for (;;) {
 assert(First <= End);
 if (First == End)
@@ -379,6 +383,7 @@ static void skipLine(const char *&First, const char *const 
End) {
   // Iterate over strings correctly to avoid comments and newlines.
   if (*First == '"' ||
   (*First == '\'' && !isQuoteCppDigitSeparator(Start, First, End))) {
+LastTokenPtr = First;
 if (isRawStringLiteral(Start, First))
   skipRawString(First, End);
 else
@@ -388,6 +393,7 @@ static void skipLine(const char *&First, const char *const 
End) {
 
   // Iterate over comments correctly.
   if (*First != '/' || End - First < 2) {
+LastTokenPtr = First;
 ++First;
 continue;
   }
@@ -399,6 +405,7 @@ static void skipLine(const char *&First, const char *const 
End) {
   }
 
   if (First[1] != '*') {
+LastTokenPtr = First;
 ++First;
 continue;
   }
@@ -416,8 +423,8 @@ static void skipLine(const char *&First, const char *const 
End) {
   }
 }
 
-static void skipDirective(StringRef Name, const char *&First,
-  const char *const End) {
+void Scanner::skipDirective(StringRef Name, const char *&First,
+const char *const End) {
   if (llvm::StringSwitch(Name)
   .Case("warning", true)
   .Case("error", true)
@@ -710,6 +717,8 @@ bool Scanner::lexPPLine(const char *&First, const char 
*const End) {
 return false;
   }
 
+  LastTokenPtr = First;
+
   TheLexer.seek(getOffsetAt(First), /*IsAtStartOfLine*/ true);
 
   auto ScEx1 = make_scope_exit([&]() {
@@ -803,6 +812,9 @@ bool Scanner::scan(SmallVectorImpl &Directives) {
 
   if (!Error) {
 // Add an EOF on success.
+if (LastTokenPtr &&
+(Tokens.empty() || LastTokenPtr > Input.begin() + 
Tokens.b

[PATCH] D133357: [Lex/DependencyDirectivesScanner] Keep track of the presence of tokens between the last scanned directive and EOF

2022-09-07 Thread Argyrios Kyrtzidis 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 rGaa484c90cf59: [Lex/DependencyDirectivesScanner] Keep track 
of the presence of tokens between… (authored by akyrtzi).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133357

Files:
  clang/include/clang/Lex/DependencyDirectivesScanner.h
  clang/lib/Lex/DependencyDirectivesScanner.cpp
  clang/lib/Lex/Lexer.cpp
  clang/unittests/Lex/CMakeLists.txt
  clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
  clang/unittests/Lex/PPDependencyDirectivesTest.cpp

Index: clang/unittests/Lex/PPDependencyDirectivesTest.cpp
===
--- /dev/null
+++ clang/unittests/Lex/PPDependencyDirectivesTest.cpp
@@ -0,0 +1,148 @@
+//===- unittests/Lex/PPDependencyDirectivesTest.cpp -=//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/Basic/TargetOptions.h"
+#include "clang/Lex/DependencyDirectivesScanner.h"
+#include "clang/Lex/HeaderSearch.h"
+#include "clang/Lex/HeaderSearchOptions.h"
+#include "clang/Lex/ModuleLoader.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/PreprocessorOptions.h"
+#include "llvm/Testing/Support/Error.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+
+namespace {
+
+// The test fixture.
+class PPDependencyDirectivesTest : public ::testing::Test {
+protected:
+  PPDependencyDirectivesTest()
+  : FileMgr(FileMgrOpts), DiagID(new DiagnosticIDs()),
+Diags(DiagID, new DiagnosticOptions, new IgnoringDiagConsumer()),
+SourceMgr(Diags, FileMgr), TargetOpts(new TargetOptions) {
+TargetOpts->Triple = "x86_64-apple-macos12";
+Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts);
+  }
+
+  FileSystemOptions FileMgrOpts;
+  FileManager FileMgr;
+  IntrusiveRefCntPtr DiagID;
+  DiagnosticsEngine Diags;
+  SourceManager SourceMgr;
+  LangOptions LangOpts;
+  std::shared_ptr TargetOpts;
+  IntrusiveRefCntPtr Target;
+};
+
+class IncludeCollector : public PPCallbacks {
+public:
+  Preprocessor &PP;
+  SmallVectorImpl &IncludedFiles;
+
+  IncludeCollector(Preprocessor &PP, SmallVectorImpl &IncludedFiles)
+  : PP(PP), IncludedFiles(IncludedFiles) {}
+
+  void LexedFileChanged(FileID FID, LexedFileChangeReason Reason,
+SrcMgr::CharacteristicKind FileType, FileID PrevFID,
+SourceLocation Loc) override {
+if (Reason != LexedFileChangeReason::EnterFile)
+  return;
+if (FID == PP.getPredefinesFileID())
+  return;
+StringRef Filename =
+PP.getSourceManager().getSLocEntry(FID).getFile().getName();
+IncludedFiles.push_back(Filename);
+  }
+};
+
+TEST_F(PPDependencyDirectivesTest, MacroGuard) {
+  // "head1.h" has a macro guard and should only be included once.
+  // "head2.h" and "head3.h" have tokens following the macro check, they should
+  // be included multiple times.
+
+  auto VFS = new llvm::vfs::InMemoryFileSystem();
+  VFS->addFile(
+  "head1.h", 0,
+  llvm::MemoryBuffer::getMemBuffer("#ifndef H1_H\n#define H1_H\n#endif\n"));
+  VFS->addFile(
+  "head2.h", 0,
+  llvm::MemoryBuffer::getMemBuffer("#ifndef H2_H\n#define H2_H\n#endif\n\n"
+   "extern int foo;\n"));
+  VFS->addFile("head3.h", 0,
+   llvm::MemoryBuffer::getMemBuffer(
+   "#ifndef H3_H\n#define H3_H\n#endif\n\n"
+   "#ifdef SOMEMAC\nextern int foo;\n#endif\n"));
+  VFS->addFile("main.c", 0,
+   llvm::MemoryBuffer::getMemBuffer(
+   "#include \"head1.h\"\n#include \"head1.h\"\n"
+   "#include \"head2.h\"\n#include \"head2.h\"\n"
+   "#include \"head3.h\"\n#include \"head3.h\"\n"));
+  FileMgr.setVirtualFileSystem(VFS);
+
+  Optional FE;
+  ASSERT_THAT_ERROR(FileMgr.getFileRef("main.c").moveInto(FE),
+llvm::Succeeded());
+  SourceMgr.setMainFileID(
+  SourceMgr.createFileID(*FE, SourceLocation(), SrcMgr::C_User));
+
+  struct DepDirectives {
+SmallVector Tokens;
+SmallVector Directives;
+  };
+  SmallVector> DepDirectivesObjects;
+
+  auto getDependencyDirectives = [&](FileEntryRef File)
+  -> Optional> {
+DepDirectivesObjects.push_back(std::make_unique());
+StringRef Input = (*FileMgr.getBufferForFile(File))->getBuffer();
+bool E

[PATCH] D133436: Ground work for cuda-related checks in clang-tidy

2022-09-07 Thread Bartłomiej Cieślar via Phabricator via cfe-commits
barcisz updated this revision to Diff 458504.
barcisz added a comment.

removed duplication of '.cu' in the lit config for clang-tidy tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133436

Files:
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
  clang-tools-extra/clang-tidy/cuda/CMakeLists.txt
  clang-tools-extra/clang-tidy/cuda/CudaTidyModule.cpp
  clang-tools-extra/test/clang-tidy/check_clang_tidy.py
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/cuda/cuda-initializers.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/cuda/cuda.h
  clang-tools-extra/test/clang-tidy/checkers/cuda/.keep

Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/cuda/cuda.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/cuda/cuda.h
@@ -0,0 +1,28 @@
+/* Minimal declarations for CUDA support.  Testing purposes only. */
+
+#include 
+
+#define __constant__ __attribute__((constant))
+#define __device__ __attribute__((device))
+#define __global__ __attribute__((global))
+#define __host__ __attribute__((host))
+#define __shared__ __attribute__((shared))
+
+struct dim3 {
+  unsigned x, y, z;
+  __host__ __device__ dim3(unsigned x, unsigned y = 1, unsigned z = 1) : x(x), y(y), z(z) {}
+};
+
+typedef struct cudaStream *cudaStream_t;
+typedef enum cudaError {} cudaError_t;
+extern "C" int cudaConfigureCall(dim3 gridSize, dim3 blockSize,
+ size_t sharedSize = 0,
+ cudaStream_t stream = 0);
+extern "C" int __cudaPushCallConfiguration(dim3 gridSize, dim3 blockSize,
+   size_t sharedSize = 0,
+   cudaStream_t stream = 0);
+extern "C" cudaError_t cudaLaunchKernel(const void *func, dim3 gridDim,
+dim3 blockDim, void **args,
+size_t sharedMem, cudaStream_t stream);
+
+extern "C" __device__ int printf(const char*, ...);
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/cuda/cuda-initializers.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/cuda/cuda-initializers.h
@@ -0,0 +1,145 @@
+// CUDA struct types with interesting initialization properties.
+// Keep in sync with clang/test/SemaCUDA/Inputs/cuda-initializers.h.
+
+// Base classes with different initializer variants.
+
+// trivial constructor -- allowed
+struct T {
+  int t;
+};
+
+// empty constructor
+struct EC {
+  int ec;
+  __device__ EC() {} // -- allowed
+  __device__ EC(int) {}  // -- not allowed
+};
+
+// empty destructor
+struct ED {
+  __device__ ~ED() {} // -- allowed
+};
+
+struct ECD {
+  __device__ ECD() {} // -- allowed
+  __device__ ~ECD() {}// -- allowed
+};
+
+// empty templated constructor -- allowed with no arguments
+struct ETC {
+  template  __device__ ETC(T...) {}
+};
+
+// undefined constructor -- not allowed
+struct UC {
+  int uc;
+  __device__ UC();
+};
+
+// undefined destructor -- not allowed
+struct UD {
+  int ud;
+  __device__ ~UD();
+};
+
+// empty constructor w/ initializer list -- not allowed
+struct ECI {
+  int eci;
+  __device__ ECI() : eci(1) {}
+};
+
+// non-empty constructor -- not allowed
+struct NEC {
+  int nec;
+  __device__ NEC() { nec = 1; }
+};
+
+// non-empty destructor -- not allowed
+struct NED {
+  int ned;
+  __device__ ~NED() { ned = 1; }
+};
+
+// no-constructor,  virtual method -- not allowed
+struct NCV {
+  int ncv;
+  __device__ virtual void vm() {}
+};
+
+// virtual destructor -- not allowed.
+struct VD {
+  __device__ virtual ~VD() {}
+};
+
+// dynamic in-class field initializer -- not allowed
+__device__ int f();
+struct NCF {
+  int ncf = f();
+};
+
+// static in-class field initializer.  NVCC does not allow it, but
+// clang generates static initializer for this, so we'll accept it.
+// We still can't use it on __shared__ vars as they don't allow *any*
+// initializers.
+struct NCFS {
+  int ncfs = 3;
+};
+
+// undefined templated constructor -- not allowed
+struct UTC {
+  template  __device__ UTC(T...);
+};
+
+// non-empty templated constructor -- not allowed
+struct NETC {
+  int netc;
+  template  __device__ NETC(T...) { netc = 1; }
+};
+
+// Regular base class -- allowed
+struct T_B_T : T {};
+
+// Incapsulated object of allowed class -- allowed
+struct T_F_T {
+  T t;
+};
+
+// array of allowed objects -- allowed
+struct T_FA_T {
+  T t[2];
+};
+
+
+// Calling empty base class initializer is OK
+struct EC_I_EC : EC {
+  __device__ EC_I_EC() : EC() {}
+};
+
+// .. though passing arguments is not allowed.
+struct EC_I_EC1 : EC {
+  __device__ EC_I_EC1() : EC(1) {}
+};
+
+// Virtual base class -- not allowe

[clang] 9ea7e4f - [RISCV] Remove unnecessary word from error message.

2022-09-07 Thread Craig Topper via cfe-commits

Author: Craig Topper
Date: 2022-09-07T10:31:48-07:00
New Revision: 9ea7e4f7c14267ada92aa6e04d7f460d2562bf19

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

LOG: [RISCV] Remove unnecessary word from error message.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb-error.c
clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkb-error.c
clang/test/CodeGen/RISCV/rvv-intrinsics/rvv-error.c

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 15a4e2aefdb79..43e70ece8c54c 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11636,7 +11636,7 @@ def warn_tcb_enforcement_violation : Warning<
 
 // RISC-V builtin required extension warning
 def err_riscv_builtin_requires_extension : Error<
-  "builtin requires at least one of the following extensions support to be 
enabled : %0">;
+  "builtin requires at least one of the following extensions to be enabled : 
%0">;
 def err_riscv_builtin_invalid_lmul : Error<
   "LMUL argument must be in the range [0,3] or [5,7]">;
 

diff  --git a/clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb-error.c 
b/clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb-error.c
index a544434105c8b..778141311b41f 100644
--- a/clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb-error.c
+++ b/clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb-error.c
@@ -2,5 +2,5 @@
 // RUN: %clang_cc1 -triple riscv32 -target-feature +zbb -verify %s -o -
 
 int orc_b_64(int a) {
-  return __builtin_riscv_orc_b_64(a); // expected-error {{builtin requires at 
least one of the following extensions support to be enabled : 'RV64'}}
+  return __builtin_riscv_orc_b_64(a); // expected-error {{builtin requires at 
least one of the following extensions to be enabled : 'RV64'}}
 }

diff  --git a/clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkb-error.c 
b/clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkb-error.c
index d372435b5d1f5..a932d56595b26 100644
--- a/clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkb-error.c
+++ b/clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkb-error.c
@@ -3,10 +3,10 @@
 
 int zip(int rs1)
 {
-  return __builtin_riscv_zip_32(rs1); // expected-error {{builtin requires at 
least one of the following extensions support to be enabled : 'RV32'}}
+  return __builtin_riscv_zip_32(rs1); // expected-error {{builtin requires at 
least one of the following extensions to be enabled : 'RV32'}}
 }
 
 int unzip(int rs1)
 {
-  return __builtin_riscv_unzip_32(rs1); // expected-error {{builtin requires 
at least one of the following extensions support to be enabled : 'RV32'}}
+  return __builtin_riscv_unzip_32(rs1); // expected-error {{builtin requires 
at least one of the following extensions to be enabled : 'RV32'}}
 }

diff  --git a/clang/test/CodeGen/RISCV/rvv-intrinsics/rvv-error.c 
b/clang/test/CodeGen/RISCV/rvv-intrinsics/rvv-error.c
index 4436744a3c26d..67f188e469867 100644
--- a/clang/test/CodeGen/RISCV/rvv-intrinsics/rvv-error.c
+++ b/clang/test/CodeGen/RISCV/rvv-intrinsics/rvv-error.c
@@ -11,7 +11,7 @@
 // CHECK-RV64V-NEXT:ret i32 [[CONV]]
 //
 
-// CHECK-RV64-ERR: error: builtin requires at least one of the following 
extensions support to be enabled : 'Zve32x'
+// CHECK-RV64-ERR: error: builtin requires at least one of the following 
extensions to be enabled : 'Zve32x'
 
 int test() {
   return __builtin_rvv_vsetvli(1, 0, 0);



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


[PATCH] D133436: Ground work for cuda-related checks in clang-tidy

2022-09-07 Thread Bartłomiej Cieślar via Phabricator via cfe-commits
barcisz added inline comments.



Comment at: clang-tools-extra/clang-tidy/cuda/CudaTidyModule.cpp:25
+
+// Register the GoogleTidyModule using this statically initialized variable.
+static ClangTidyModuleRegistry::Add

tschuett wrote:
> Is Google a copy and paste error?
Done



Comment at: clang-tools-extra/clang-tidy/cuda/CudaTidyModule.cpp:32
+// This anchor is used to force the linker to link in the generated object file
+// and thus register the GoogleModule.
+volatile int CudaModuleAnchorSource = 0;

tschuett wrote:
> Is Google a copy and paste error?
Done



Comment at: clang-tools-extra/test/lit.cfg.py:19
 # suffixes: A list of file extensions to treat as test files.
-config.suffixes = ['.c', '.cpp', '.hpp', '.m', '.mm', '.cu', '.ll', '.cl', 
'.s',
+config.suffixes = ['.c', '.cpp', '.cu', '.hpp', '.m', '.mm', '.cu', '.ll', 
'.cl', '.s',
   '.modularize', '.module-map-checker', '.test']

ivanmurashko wrote:
> `.cu` is specified several times there. It looks like the change is not 
> necessary at the line
Done


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133436

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


[PATCH] D123630: Remove connection between 'ffast-math' and 'ffp-contract'.

2022-09-07 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam updated this revision to Diff 458506.
zahiraam marked 4 inline comments as done.

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

https://reviews.llvm.org/D123630

Files:
  clang/docs/UsersManual.rst
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/ffp-contract-option.c
  clang/test/Driver/fp-contract.c

Index: clang/test/Driver/fp-contract.c
===
--- /dev/null
+++ clang/test/Driver/fp-contract.c
@@ -0,0 +1,114 @@
+// Test that -ffp-contract is set to the right value when combined with
+// the options -ffast-math and -fno-fast-math.
+
+// RUN: %clang -### -ffast-math -c %s 2>&1  \
+// RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
+// CHECK-FPC-FAST: "-ffp-contract=fast"
+
+// RUN: %clang -### -fno-fast-math -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FPC-ON %s
+
+// RUN: %clang -### -ffast-math -ffp-contract=on -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FPC-ON %s
+// CHECK-FPC-ON:   "-ffp-contract=on"
+
+// RUN: %clang -### -ffast-math -ffp-contract=off -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FPC-OFF %s
+// CHECK-FPC-OFF:  "-ffp-contract=off"
+
+// RUN: %clang -### -ffast-math -ffp-contract=fast -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
+
+// RUN: %clang -### -ffp-contract=fast -ffast-math -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
+// RUN: %clang -### -ffp-contract=on -ffast-math -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
+// RUN: %clang -### -ffp-contract=off -ffast-math -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
+
+// RUN: %clang -### -ffp-contract=fast -fno-fast-math -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
+// RUN: %clang -### -ffp-contract=on -fno-fast-math -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FPC-ON %s
+// RUN: %clang -### -ffp-contract=off -fno-fast-math -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FPC-OFF %s
+
+
+// RUN: %clang -### -ffast-math -ffp-contract=fast -ffp-contract=on -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FPC-ON %s
+
+// RUN: %clang -### -ffast-math -ffp-contract=on -ffp-contract=off -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FPC-OFF %s
+
+// RUN: %clang -### -ffast-math -ffp-contract=on -ffp-contract=fast -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
+
+// RUN: %clang -### -ffast-math -ffp-contract=off -ffp-contract=on -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FPC-ON %s
+
+// RUN: %clang -### -ffast-math -ffp-contract=off -ffp-contract=fast \
+// RUN: -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-FAST %s
+
+// RUN: %clang -### -ffast-math -ffp-contract=on -fno-fast-math -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FPC-ON %s
+
+// RUN: %clang -### -ffast-math -ffp-contract=off -fno-fast-math -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FPC-OFF %s
+
+// RUN: %clang -### -ffast-math -ffp-contract=fast -fno-fast-math -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
+
+// RUN: %clang -### -ffast-math -fno-fast-math -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FPC-ON %s
+
+// RUN: %clang -### -fno-fast-math -ffast-math -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
+
+// RUN: %clang -### -fno-fast-math -ffp-contract=on -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FPC-ON %s
+
+// RUN: %clang -### -fno-fast-math -ffp-contract=off -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FPC-OFF %s
+
+// RUN: %clang -### -fno-fast-math -ffp-contract=fast -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
+
+// RUN: %clang -### -ffp-contract=fast -fno-fast-math -ffp-contract=on \
+// RUN: -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-ON %s
+
+// RUN: %clang -### -ffp-contract=fast -fno-fast-math -ffp-contract=off \
+// RUN: -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-OFF %s
+
+// RUN: %clang -### -ffp-contract=off -fno-fast-math -ffp-contract=fast \
+// RUN: -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-FAST %s
+
+// RUN: %clang -### -ffp-contract=off -fno-fast-math -ffp-contract=on \
+// RUN: -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-ON %s
+
+// RUN: %clang -### -ffp-contract=on -ffast-math -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
+
+// RUN: %clang -### -ffp-contract=off -ffast-math -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
+
+// RUN: %clang -### -ffp-contract=fast -ffast-math -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FPC-FAST %s
+
+// RUN: %clang -### -ffp-contract=on -ffast-math -fno-fast-math -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FPC-ON %s
+
+// RUN: %clang -### -ffp-contract=off -ffast-math -fno-fast-math -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FPC-OFF %s
+
+// RUN: %clan

[PATCH] D123630: Remove connection between 'ffast-math' and 'ffp-contract'.

2022-09-07 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added a comment.

Thanks @aaron.ballman!


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

https://reviews.llvm.org/D123630

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


[PATCH] D133438: change SM target to 6.2, that's when fnative-half-type was introduced

2022-09-07 Thread Joshua Batista via Phabricator via cfe-commits
bob80905 created this revision.
Herald added a project: All.
bob80905 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/D133438

Files:
  clang/test/CodeGenHLSL/builtins/sqrt.hlsl


Index: clang/test/CodeGenHLSL/builtins/sqrt.hlsl
===
--- clang/test/CodeGenHLSL/builtins/sqrt.hlsl
+++ clang/test/CodeGenHLSL/builtins/sqrt.hlsl
@@ -1,8 +1,8 @@
 // RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
-// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN:   dxil-pc-shadermodel6.2-library %s -fnative-half-type \
 // RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s
 // RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
-// RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
+// RUN:   dxil-pc-shadermodel6.2-library %s -emit-llvm -disable-llvm-passes \
 // RUN:   -o - | FileCheck %s --check-prefix=NO_HALF
 
 double sqrt_d(double x)


Index: clang/test/CodeGenHLSL/builtins/sqrt.hlsl
===
--- clang/test/CodeGenHLSL/builtins/sqrt.hlsl
+++ clang/test/CodeGenHLSL/builtins/sqrt.hlsl
@@ -1,8 +1,8 @@
 // RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
-// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN:   dxil-pc-shadermodel6.2-library %s -fnative-half-type \
 // RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s
 // RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
-// RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
+// RUN:   dxil-pc-shadermodel6.2-library %s -emit-llvm -disable-llvm-passes \
 // RUN:   -o - | FileCheck %s --check-prefix=NO_HALF
 
 double sqrt_d(double x)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D132918: [clang] Fix a crash in constant evaluation

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

LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132918

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


[PATCH] D132711: [HLSL] add sqrt library function

2022-09-07 Thread Joshua Batista via Phabricator via cfe-commits
bob80905 updated this revision to Diff 458513.
bob80905 added a comment.

Shader Model target update
Change the shader model target to 6.2, because that is when fnative-half-type 
was introduced.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132711

Files:
  clang/test/CodeGenHLSL/builtins/sqrt.hlsl


Index: clang/test/CodeGenHLSL/builtins/sqrt.hlsl
===
--- clang/test/CodeGenHLSL/builtins/sqrt.hlsl
+++ clang/test/CodeGenHLSL/builtins/sqrt.hlsl
@@ -1,8 +1,8 @@
 // RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
-// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN:   dxil-pc-shadermodel6.2-library %s -fnative-half-type \
 // RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s
 // RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
-// RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
+// RUN:   dxil-pc-shadermodel6.2-library %s -emit-llvm -disable-llvm-passes \
 // RUN:   -o - | FileCheck %s --check-prefix=NO_HALF
 
 double sqrt_d(double x)


Index: clang/test/CodeGenHLSL/builtins/sqrt.hlsl
===
--- clang/test/CodeGenHLSL/builtins/sqrt.hlsl
+++ clang/test/CodeGenHLSL/builtins/sqrt.hlsl
@@ -1,8 +1,8 @@
 // RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
-// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN:   dxil-pc-shadermodel6.2-library %s -fnative-half-type \
 // RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s
 // RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
-// RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
+// RUN:   dxil-pc-shadermodel6.2-library %s -emit-llvm -disable-llvm-passes \
 // RUN:   -o - | FileCheck %s --check-prefix=NO_HALF
 
 double sqrt_d(double x)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D132918: [clang] Fix a crash in constant evaluation

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

LGTM, I spent some time debugging this and I don't see an obvious alternative.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132918

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


[PATCH] D128372: [Clang-Tidy] Empty Check

2022-09-07 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added a comment.

Ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128372

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


[PATCH] D133440: [clangd] Allow programmatically disabling rename of virtual method hierarchies.

2022-09-07 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.

This feature relies on Relations in the index being complete.
An out-of-tree index implementation is missing some override relations, so
such renames end up breaking the code.
We plan to fix it, but this flag is a cheap band-aid for now.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133440

Files:
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/refactor/Rename.h


Index: clang-tools-extra/clangd/refactor/Rename.h
===
--- clang-tools-extra/clangd/refactor/Rename.h
+++ clang-tools-extra/clangd/refactor/Rename.h
@@ -26,6 +26,8 @@
   size_t LimitFiles = 50;
   /// If true, format the rename edits, only meaningful in ClangdServer layer.
   bool WantFormat = false;
+  /// Allow rename of virtual method hierarchies.
+  bool RenameVirtual = true;
 };
 
 struct RenameInputs {
Index: clang-tools-extra/clangd/refactor/Rename.cpp
===
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -181,7 +181,8 @@
 
 llvm::Optional renameable(const NamedDecl &RenameDecl,
   StringRef MainFilePath,
-  const SymbolIndex *Index) {
+  const SymbolIndex *Index,
+  const RenameOptions& Opts) {
   trace::Span Tracer("Renameable");
   // Filter out symbols that are unsupported in both rename modes.
   if (llvm::isa(&RenameDecl))
@@ -213,6 +214,12 @@
   RenameDecl, RenameDecl.getASTContext(), SymbolCollector::Options(),
   IsMainFileOnly))
 return ReasonToReject::NonIndexable;
+  if (!Opts.RenameVirtual) {
+if (const auto *S = llvm::dyn_cast(&RenameDecl)) {
+  if (S->isVirtual())
+return ReasonToReject::UnsupportedSymbol;
+}
+  }
 
   return None;
 }


Index: clang-tools-extra/clangd/refactor/Rename.h
===
--- clang-tools-extra/clangd/refactor/Rename.h
+++ clang-tools-extra/clangd/refactor/Rename.h
@@ -26,6 +26,8 @@
   size_t LimitFiles = 50;
   /// If true, format the rename edits, only meaningful in ClangdServer layer.
   bool WantFormat = false;
+  /// Allow rename of virtual method hierarchies.
+  bool RenameVirtual = true;
 };
 
 struct RenameInputs {
Index: clang-tools-extra/clangd/refactor/Rename.cpp
===
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -181,7 +181,8 @@
 
 llvm::Optional renameable(const NamedDecl &RenameDecl,
   StringRef MainFilePath,
-  const SymbolIndex *Index) {
+  const SymbolIndex *Index,
+  const RenameOptions& Opts) {
   trace::Span Tracer("Renameable");
   // Filter out symbols that are unsupported in both rename modes.
   if (llvm::isa(&RenameDecl))
@@ -213,6 +214,12 @@
   RenameDecl, RenameDecl.getASTContext(), SymbolCollector::Options(),
   IsMainFileOnly))
 return ReasonToReject::NonIndexable;
+  if (!Opts.RenameVirtual) {
+if (const auto *S = llvm::dyn_cast(&RenameDecl)) {
+  if (S->isVirtual())
+return ReasonToReject::UnsupportedSymbol;
+}
+  }
 
   return None;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133392: [MTE] Add AArch64GlobalsTagging Pass

2022-09-07 Thread Florian Mayer via Phabricator via cfe-commits
fmayer added inline comments.



Comment at: llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp:25
+
+using namespace llvm;
+

why don't we put this into the llvm namespace rather than using?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133392

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


[PATCH] D132997: [clang][Interp] Handle DeclRefExpr of reference types

2022-09-07 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D132997#3763367 , @tbaeder wrote:

> In D132997#3763094 , @shafik wrote:
>
>> I think like @aaron.ballman was saying in another PR you should aim for as 
>> complete set of tests as possible even if you have to comment one that can't 
>> work yet. For example cases that would involve `MemberExpr` or `UsingShadow` 
>> for example as well as the cases you mentioned not implemented in your 
>> description.
>
> I get it for the `MaterializeTemporaryExpr`s, but I don't understand why I 
> would add tests using `MemberExpr` now and not when I work on record types 
> (and references have already landed).

The test case I was thinking of for that is:

  struct S {
int i, j;
  };
  
  constexpr int test() {
S s{1, 2};
  
int &j = s.i;
j += 10;
  
return j;
  }
  
  static_assert(test() == 11, "");

where the reference is a `DeclRefExpr`. Even if structures don't work yet, 
capturing it as a test case now means we don't have to remember to think about 
"what if there's a reference to this member" when structures are implemented.




Comment at: clang/test/AST/Interp/references.cpp:13
+  int a = 20;
+  int &b =a;
+




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

https://reviews.llvm.org/D132997

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


[PATCH] D133392: [MTE] Add AArch64GlobalsTagging Pass

2022-09-07 Thread Thorsten via Phabricator via cfe-commits
tschuett added inline comments.



Comment at: llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp:29
+
+namespace {
+

I believe you are going too far with the anonymous namespace. There is no need 
for static functions in anonymous namespaces.

https://llvm.org/docs/CodingStandards.html#anonymous-namespaces


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133392

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


[PATCH] D133339: [clangd] Isolate logic for setting LSPServer options

2022-09-07 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

I like the change to initialize() a lot.




Comment at: clang-tools-extra/clangd/ClangdLSPServer.h:64
+
+/// Options used for diagnostics.
+ClangdDiagnosticOptions DiagOpts;

I don't really like making these options part of this struct.

Currently this struct is largely used to send data from main->ClangdLSPServer.
After this patch, half of the fields are for that and half of them are scratch 
space for ClangdLSPServer to use itself. Worse, they *look* like things that 
can/should be set beforehand, but will in fact the passed values are ignored.
(Admittedly, some of the *inherited* fields are used in the same way, sigh).

Additionally, these options are publicly exposed when they don't need to be - 
these are internals leaking into API without a use case.

---

Having updateServerOptions be a hidden helper rather than a member is nice, but 
I think not as important as the actual public interface.

Grouping the options is also nice. Having the members be consecutive seems 
enough to me (they're almost grouped: background queue state is in the wrong 
place). Adding a second struct also seems like an option though?



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D19

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


[PATCH] D132991: [Clang] Give error message for invalid profile path when compiling IR

2022-09-07 Thread Aiden Grossman via Phabricator via cfe-commits
aidengrossman added a comment.

`CodeGenModule` doesn't get invoked when compiling IR. The error would trip 
when compiling other languages (eg c), but when passing IR to clang, the 
function doing error checking would never get called so no error was ever 
thrown.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132991

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


[PATCH] D133325: [Driver] Allow search of included response files as configuration files

2022-09-07 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/docs/UsersManual.rst:947-949
+Option `--search-config-dirs` changes the search algorith if the included
+file is specified without a directory separator. In this case the file is 
looked
+for in the same directories as configuration files.





Comment at: llvm/lib/Support/CommandLine.cpp:1188-1194
+  if (InConfigFile) {
+if (std::find_if(NewArgv.begin(), NewArgv.end(),
+ [](const char *Arg) -> bool {
+   return StringRef("--search-config-dirs") == Arg;
+ }) != NewArgv.end())
+  setSearchAsConfig(true);
+  }





Comment at: llvm/lib/Support/CommandLine.cpp:1384-1387
+if (llvm::sys::path::is_relative(FileName)) {
+  if (FS->makeAbsolute(CfgFilePath))
+return false;
+}




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133325

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


[clang] cc14e19 - [RISCV] Remove space before colon in error message.

2022-09-07 Thread Craig Topper via cfe-commits

Author: Craig Topper
Date: 2022-09-07T11:34:33-07:00
New Revision: cc14e195e79d0c1eca2190acffbddd53d0898317

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

LOG: [RISCV] Remove space before colon in error message.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb-error.c
clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkb-error.c
clang/test/CodeGen/RISCV/rvv-intrinsics/rvv-error.c

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 43e70ece8c54..a59eeda85bc0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11636,7 +11636,7 @@ def warn_tcb_enforcement_violation : Warning<
 
 // RISC-V builtin required extension warning
 def err_riscv_builtin_requires_extension : Error<
-  "builtin requires at least one of the following extensions to be enabled : 
%0">;
+  "builtin requires at least one of the following extensions to be enabled: 
%0">;
 def err_riscv_builtin_invalid_lmul : Error<
   "LMUL argument must be in the range [0,3] or [5,7]">;
 

diff  --git a/clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb-error.c 
b/clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb-error.c
index 778141311b41..5952443b0944 100644
--- a/clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb-error.c
+++ b/clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb-error.c
@@ -2,5 +2,5 @@
 // RUN: %clang_cc1 -triple riscv32 -target-feature +zbb -verify %s -o -
 
 int orc_b_64(int a) {
-  return __builtin_riscv_orc_b_64(a); // expected-error {{builtin requires at 
least one of the following extensions to be enabled : 'RV64'}}
+  return __builtin_riscv_orc_b_64(a); // expected-error {{builtin requires at 
least one of the following extensions to be enabled: 'RV64'}}
 }

diff  --git a/clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkb-error.c 
b/clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkb-error.c
index a932d56595b2..b783a3546acc 100644
--- a/clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkb-error.c
+++ b/clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkb-error.c
@@ -3,10 +3,10 @@
 
 int zip(int rs1)
 {
-  return __builtin_riscv_zip_32(rs1); // expected-error {{builtin requires at 
least one of the following extensions to be enabled : 'RV32'}}
+  return __builtin_riscv_zip_32(rs1); // expected-error {{builtin requires at 
least one of the following extensions to be enabled: 'RV32'}}
 }
 
 int unzip(int rs1)
 {
-  return __builtin_riscv_unzip_32(rs1); // expected-error {{builtin requires 
at least one of the following extensions to be enabled : 'RV32'}}
+  return __builtin_riscv_unzip_32(rs1); // expected-error {{builtin requires 
at least one of the following extensions to be enabled: 'RV32'}}
 }

diff  --git a/clang/test/CodeGen/RISCV/rvv-intrinsics/rvv-error.c 
b/clang/test/CodeGen/RISCV/rvv-intrinsics/rvv-error.c
index 67f188e46986..93a406f86bd5 100644
--- a/clang/test/CodeGen/RISCV/rvv-intrinsics/rvv-error.c
+++ b/clang/test/CodeGen/RISCV/rvv-intrinsics/rvv-error.c
@@ -11,7 +11,7 @@
 // CHECK-RV64V-NEXT:ret i32 [[CONV]]
 //
 
-// CHECK-RV64-ERR: error: builtin requires at least one of the following 
extensions to be enabled : 'Zve32x'
+// CHECK-RV64-ERR: error: builtin requires at least one of the following 
extensions to be enabled: 'Zve32x'
 
 int test() {
   return __builtin_rvv_vsetvli(1, 0, 0);



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


[PATCH] D133266: [MinGW] Reject explicit non-default visibility applied to dllexport/dllimport declaration

2022-09-07 Thread ben via Phabricator via cfe-commits
bd1976llvm added a comment.

This approach doesn't account for the implementation of 
-fvisibility-global-new-delete-hidden. The following case now fails after this 
change:

> type new_del.cpp

namespace std {

  typedef __typeof__(sizeof(int)) size_t;
  struct nothrow_t {};
  struct align_val_t {};

}
__declspec(dllexport) void operator delete(void* ptr) throw() {return;}

> clang.exe --target=x86_64-pc-windows-gnu new_del.cpp 
> -fvisibility-global-new-delete-hidden -c

new_del.cpp:8:28: error: non-default visibility cannot be applied to 
'dllexport' declaration
__declspec(dllexport) void operator delete(void* ptr) throw() {return;}

  ^

1 error generated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133266

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


[PATCH] D133443: [RISCV][MC] Add support for experimental Zawrs extension

2022-09-07 Thread Philip Reames via Phabricator via cfe-commits
reames created this revision.
reames added reviewers: palmer-dabbelt, sunshaoce, craig.topper, kito-cheng, 
jrtc27, frasercrmck, asb, luismarques.
Herald added subscribers: VincentWu, luke957, StephenFan, vkmr, jdoerfert, 
evandro, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, 
the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, shiva0217, 
niosHD, sabuasal, bollu, simoncook, johnrusso, rbar, hiraditya, arichardson, 
mcrosier.
Herald added a project: All.
reames requested review of this revision.
Herald added subscribers: cfe-commits, pcwang-thead, eopXD, MaskRay.
Herald added projects: clang, LLVM.

This implements the Zawrs specification as specified here: 
https://github.com/riscv/riscv-zawrs/releases/download/V1.0-rc3/Zawrs.pdf.  
Despite the 1.0 version name, this does not appear to have been ratified, so 
putting it under experimental for the moment.  I have been told that the 
current version is near final, and unlikely to change (again), but have nothing 
to cite on that.

This change adds assembly support, but does not include C language or IR 
intrinsics.  We can decide if we want them, and handle that in a separate patch.

There were two prior attempts at implementing this.

D128235  by @palmer-dabbelt implements a 
prior version of this extension.  Very annoyingly, the specification appears to 
have changed *without* a change in version number.  This patch also didn't make 
the extension experimental.

D129462  by @sunshaoce implements the current 
version, but was abandoned due to confusion with the prior.  Additionally, it's 
missing a few tests.  I took the .td file change and the valid assembly test 
from that change.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133443

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

Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -197,5 +197,8 @@
 .attribute arch, "rv32izca0p70"
 # CHECK: attribute  5, "rv32i2p0_zca0p70"
 
+.attribute arch, "rv32izawrs1p0"
+# CHECK: attribute  5, "rv32i2p0_zawrs1p0"
+
 .attribute arch, "rv32iztso0p1"
 # CHECK: attribute  5, "rv32i2p0_ztso0p1"
Index: llvm/test/MC/RISCV/Zawrs-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/Zawrs-valid.s
@@ -0,0 +1,18 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-zawrs -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+experimental-zawrs -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+experimental-zawrs < %s \
+# RUN: | llvm-objdump --mattr=+experimental-zawrs -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+experimental-zawrs < %s \
+# RUN: | llvm-objdump --mattr=+experimental-zawrs -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
+
+# CHECK-ASM-AND-OBJ: wrs.nto
+# CHECK-ASM: encoding: [0x73,0x00,0xd0,0x00]
+wrs.nto
+
+# CHECK-ASM-AND-OBJ: wrs.sto
+# CHECK-ASM: encoding: [0x73,0x00,0xd0,0x01]
+wrs.sto
Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -84,6 +84,7 @@
 ; RUN: llc -mtriple=riscv64 -mattr=+zicbom %s -o - | FileCheck --check-prefix=RV64ZICBOM %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zicboz %s -o - | FileCheck --check-prefix=RV64ZICBOZ %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zicbop %s -o - | FileCheck --check-prefix=RV64ZICBOP %s
+; RUN: llc -mtriple=riscv64 -mattr=+experimental-zawrs %s -o - | FileCheck --check-prefix=RV64ZAWRS %s
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-ztso %s -o - | FileCheck --check-prefix=RV64ZTSO %s
 
 ; RV32M: .attribute 5, "rv32i2p0_m2p0"
@@ -170,6 +171,7 @@
 ; RV64COMBINEINTOZKS: .attribute 5, "rv64i2p0_zbkb1p0_zbkc1p0_zbkx1p0_zks1p0_zksed1p0_zksh1p0"
 ; RV64ZICBOM: .attribute 5, "rv64i2p0_zicbom1p0"
 ; RV64ZICBOZ: .attribute 5, "rv64i2p0_zicboz1p0"
+; RV64ZAWRS: .attribute 5, "rv64i2p0_zawrs1p0"
 ; RV64ZICBOP: .attribute 5, "rv64i2p0_zicbop1p0"
 ; RV64ZTSO: .attribute 5, "rv64i2p0_ztso0p1"
 
Index: llvm/lib/Target/RISCV/RISCVSubtarget.h
===
--- llvm/lib/Target/RISCV/RISCVSub

[PATCH] D133443: [RISCV][MC] Add support for experimental Zawrs extension

2022-09-07 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added inline comments.



Comment at: llvm/lib/Target/RISCV/RISCVInstrInfo.td:709
+
+let Predicates = [HasStdExtZawrs] in {
+def WRS_NTO : RVInstI<0b000, OPC_SYSTEM, (outs), (ins), "wrs.nto", "">,

This doesn't really belong here, but a separate RISCVInstrInfoZawrs.td also 
seems a little overkill... hmm



Comment at: llvm/lib/Target/RISCV/RISCVSubtarget.h:95
   bool HasStdExtZmmul = false;
+  bool HasStdExtZawrs = false;
   bool HasStdExtZtso = false;

I would say keep these sorted but this seems to be a bit of a mess...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133443

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


[PATCH] D133444: [RISCV] Update error message to not call 'RV32' and 'RV64' an extension.

2022-09-07 Thread Craig Topper via Phabricator via cfe-commits
craig.topper created this revision.
craig.topper added reviewers: reames, luismarques, asb, kito-cheng.
Herald added subscribers: sunshaoce, VincentWu, luke957, StephenFan, vkmr, 
frasercrmck, evandro, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, 
jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, 
zzheng, jrtc27, shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, 
arichardson.
Herald added a project: All.
craig.topper requested review of this revision.
Herald added subscribers: pcwang-thead, eopXD, MaskRay.
Herald added a project: clang.

I used RV32 so I didn't have to write RV32I and RV32E. Ideally
these builtins will be wrapped in a header someday so long term I don't
expect users to see these errors.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133444

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb-error.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkb-error.c


Index: clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkb-error.c
===
--- clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkb-error.c
+++ clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkb-error.c
@@ -3,10 +3,10 @@
 
 int zip(int rs1)
 {
-  return __builtin_riscv_zip_32(rs1); // expected-error {{builtin requires at 
least one of the following extensions to be enabled: 'RV32'}}
+  return __builtin_riscv_zip_32(rs1); // expected-error {{builtin requires: 
'RV32'}}
 }
 
 int unzip(int rs1)
 {
-  return __builtin_riscv_unzip_32(rs1); // expected-error {{builtin requires 
at least one of the following extensions to be enabled: 'RV32'}}
+  return __builtin_riscv_unzip_32(rs1); // expected-error {{builtin requires: 
'RV32'}}
 }
Index: clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb-error.c
===
--- clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb-error.c
+++ clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb-error.c
@@ -2,5 +2,5 @@
 // RUN: %clang_cc1 -triple riscv32 -target-feature +zbb -verify %s -o -
 
 int orc_b_64(int a) {
-  return __builtin_riscv_orc_b_64(a); // expected-error {{builtin requires at 
least one of the following extensions to be enabled: 'RV64'}}
+  return __builtin_riscv_orc_b_64(a); // expected-error {{builtin requires: 
'RV64'}}
 }
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -4369,13 +4369,20 @@
 if (llvm::none_of(ReqOpFeatures,
   [&TI](StringRef OF) { return TI.hasFeature(OF); })) {
   std::string FeatureStrs;
+  bool IsExtension = true;
   for (StringRef OF : ReqOpFeatures) {
 // If the feature is 64bit, alter the string so it will print better in
 // the diagnostic.
-if (OF == "64bit")
+if (OF == "64bit") {
+  assert(ReqOpFeatures.size() == 1 && "Expected '64bit' to be alone");
   OF = "RV64";
-if (OF == "32bit")
+  IsExtension = false;
+}
+if (OF == "32bit") {
+  assert(ReqOpFeatures.size() == 1 && "Expected '32bit' to be alone");
   OF = "RV32";
+  IsExtension = false;
+}
 
 // Convert features like "zbr" and "experimental-zbr" to "Zbr".
 OF.consume_front("experimental-");
@@ -4390,6 +4397,7 @@
   // Error message
   FeatureMissing = true;
   Diag(TheCall->getBeginLoc(), diag::err_riscv_builtin_requires_extension)
+  << IsExtension
   << TheCall->getSourceRange() << StringRef(FeatureStrs);
 }
   }
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11636,7 +11636,7 @@
 
 // RISC-V builtin required extension warning
 def err_riscv_builtin_requires_extension : Error<
-  "builtin requires at least one of the following extensions to be enabled: 
%0">;
+  "builtin requires%select{| at least one of the following extensions to be 
enabled}0: %1">;
 def err_riscv_builtin_invalid_lmul : Error<
   "LMUL argument must be in the range [0,3] or [5,7]">;
 


Index: clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkb-error.c
===
--- clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkb-error.c
+++ clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkb-error.c
@@ -3,10 +3,10 @@
 
 int zip(int rs1)
 {
-  return __builtin_riscv_zip_32(rs1); // expected-error {{builtin requires at least one of the following extensions to be enabled: 'RV32'}}
+  return __builtin_riscv_zip_32(rs1); // expected-error {{builtin requires: 'RV32'}}
 }
 
 int unzip(int rs1)
 {
-  return __builti

[PATCH] D133443: [RISCV][MC] Add support for experimental Zawrs extension

2022-09-07 Thread Philip Reames via Phabricator via cfe-commits
reames added inline comments.



Comment at: llvm/lib/Target/RISCV/RISCVInstrInfo.td:709
+
+let Predicates = [HasStdExtZawrs] in {
+def WRS_NTO : RVInstI<0b000, OPC_SYSTEM, (outs), (ins), "wrs.nto", "">,

jrtc27 wrote:
> This doesn't really belong here, but a separate RISCVInstrInfoZawrs.td also 
> seems a little overkill... hmm
I had the same thoughts.  I'm happy to defer to reviewers' preference.  



Comment at: llvm/lib/Target/RISCV/RISCVSubtarget.h:95
   bool HasStdExtZmmul = false;
+  bool HasStdExtZawrs = false;
   bool HasStdExtZtso = false;

jrtc27 wrote:
> I would say keep these sorted but this seems to be a bit of a mess...
I'm happy to sort in a separate change if you'd like.  Preferably after this 
lands.  :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133443

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


[PATCH] D132727: [clang][Interp] Implement array initializers and subscript expressions

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

LGTM!


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

https://reviews.llvm.org/D132727

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


[clang] c4842bb - [Clang] Introduce -fexperimental-sanitize-metadata=

2022-09-07 Thread Marco Elver via cfe-commits

Author: Marco Elver
Date: 2022-09-07T21:25:40+02:00
New Revision: c4842bb2e98e2f1ee23bb3bc753752816927b7b3

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

LOG: [Clang] Introduce -fexperimental-sanitize-metadata=

Introduces the frontend flag -fexperimental-sanitize-metadata=, which
enables SanitizerBinaryMetadata instrumentation.

The first intended user of the binary metadata emitted will be a variant
of GWP-TSan [1]. The plan is to open source a stable and production
quality version of GWP-TSan. The development of which, however, requires
upstream compiler support.

[1] https://llvm.org/devmtg/2020-09/slides/Morehouse-GWP-Tsan.pdf

Until the tool has been open sourced, we mark this kind of
instrumentation as "experimental", and reserve the option to change
binary format, remove features, and similar.

Reviewed By: vitalybuka, MaskRay

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

Added: 
clang/test/CodeGen/sanitize-metadata.c
clang/test/Driver/fsanitize-metadata.c

Modified: 
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Basic/CodeGenOptions.h
clang/include/clang/Driver/Options.td
clang/include/clang/Driver/SanitizerArgs.h
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/Driver/SanitizerArgs.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 55c6940fb34c1..ca2aa0d09aaf9 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -286,6 +286,8 @@ CODEGENOPT(SanitizeCoverageNoPrune, 1, 0) ///< Disable 
coverage pruning.
 CODEGENOPT(SanitizeCoverageStackDepth, 1, 0) ///< Enable max stack depth 
tracing
 CODEGENOPT(SanitizeCoverageTraceLoads, 1, 0) ///< Enable tracing of loads.
 CODEGENOPT(SanitizeCoverageTraceStores, 1, 0) ///< Enable tracing of stores.
+CODEGENOPT(SanitizeBinaryMetadataCovered, 1, 0) ///< Emit PCs for covered 
functions.
+CODEGENOPT(SanitizeBinaryMetadataAtomics, 1, 0) ///< Emit PCs for atomic 
operations.
 CODEGENOPT(SanitizeStats , 1, 0) ///< Collect statistics for sanitizers.
 CODEGENOPT(SimplifyLibCalls  , 1, 1) ///< Set when -fbuiltin is enabled.
 CODEGENOPT(SoftFloat , 1, 0) ///< -soft-float.

diff  --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 7fffb38338889..0504012badb04 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -485,6 +485,11 @@ class CodeGenOptions : public CodeGenOptionsBase {
SanitizeCoverageTraceCmp || SanitizeCoverageTraceLoads ||
SanitizeCoverageTraceStores;
   }
+
+  // Check if any one of SanitizeBinaryMetadata* is enabled.
+  bool hasSanitizeBinaryMetadata() const {
+return SanitizeBinaryMetadataCovered || SanitizeBinaryMetadataAtomics;
+  }
 };
 
 }  // end namespace clang

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index f9dfb8104395e..cfc0994d69d4e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1673,6 +1673,12 @@ def fsanitize_coverage_ignorelist : Joined<["-"], 
"fsanitize-coverage-ignorelist
 HelpText<"Disable sanitizer coverage instrumentation for modules and 
functions "
  "that match the provided special case list, even the allowed 
ones">,
 
MarshallingInfoStringVector>;
+def fexperimental_sanitize_metadata_EQ : CommaJoined<["-"], 
"fexperimental-sanitize-metadata=">,
+  Group,
+  HelpText<"Specify the type of metadata to emit for binary analysis 
sanitizers">;
+def fno_experimental_sanitize_metadata_EQ : CommaJoined<["-"], 
"fno-experimental-sanitize-metadata=">,
+  Group, Flags<[CoreOption]>,
+  HelpText<"Disable emitting metadata for binary analysis sanitizers">;
 def fsanitize_memory_track_origins_EQ : Joined<["-"], 
"fsanitize-memory-track-origins=">,
 Group,
 HelpText<"Enable origins tracking in 
MemorySanitizer">,
@@ -5497,6 +5503,14 @@ def fsanitize_coverage_trace_stores
 : Flag<["-"], "fsanitize-coverage-trace-stores">,
   HelpText<"Enable tracing of stores">,
   MarshallingInfoFlag>;
+def fexperimental_sanitize_metadata_EQ_covered
+: Flag<["-"], "fexperimental-sanitize-metadata=covered">,
+  HelpText<"Emit PCs for code covered with binary analysis sanitizers">,
+  MarshallingInfoFlag>;
+def fexperimental_sanitize_metadata_EQ_atomics
+: Flag<["-"], "fexperimental-sanitize-metadata=atomics">,
+  HelpText<"Emit PCs for atomic operations used by binary analysis 
sanitizers">,
+  MarshallingInfoFlag>;
 def fpatchable_function_entry_offset_EQ
 : Joined<

[PATCH] D130888: [Clang] Introduce -fexperimental-sanitize-metadata=

2022-09-07 Thread Marco Elver 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 rGc4842bb2e98e: [Clang] Introduce 
-fexperimental-sanitize-metadata= (authored by melver).

Changed prior to commit:
  https://reviews.llvm.org/D130888?vs=457779&id=458532#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130888

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/CodeGen/sanitize-metadata.c
  clang/test/Driver/fsanitize-metadata.c

Index: clang/test/Driver/fsanitize-metadata.c
===
--- /dev/null
+++ clang/test/Driver/fsanitize-metadata.c
@@ -0,0 +1,23 @@
+// RUN: %clang --target=x86_64-linux-gnu -fexperimental-sanitize-metadata=all -fno-experimental-sanitize-metadata=all %s -### 2>&1 | FileCheck %s
+// CHECK-NOT: -fexperimental-sanitize-metadata
+
+// RUN: %clang --target=x86_64-linux-gnu -fexperimental-sanitize-metadata=bad_arg %s -### 2>&1 | FileCheck -check-prefix=CHECK-INVALID %s
+// CHECK-INVALID: error: unsupported argument 'bad_arg' to option '-fexperimental-sanitize-metadata='
+
+// RUN: %clang --target=x86_64-linux-gnu -fexperimental-sanitize-metadata=covered %s -### 2>&1 | FileCheck -check-prefix=CHECK-COVERED %s
+// RUN: %clang --target=x86_64-linux-gnu -fexperimental-sanitize-metadata=atomics -fno-experimental-sanitize-metadata=atomics -fexperimental-sanitize-metadata=covered %s -### 2>&1 | FileCheck -check-prefix=CHECK-COVERED %s
+// RUN: %clang --target=x86_64-linux-gnu -fexperimental-sanitize-metadata=all -fno-experimental-sanitize-metadata=atomics %s -### 2>&1 | FileCheck -check-prefix=CHECK-COVERED %s
+// CHECK-COVERED: "-fexperimental-sanitize-metadata=covered"
+// CHECK-COVERED-NOT: "-fexperimental-sanitize-metadata=atomics"
+
+// RUN: %clang --target=x86_64-linux-gnu -fexperimental-sanitize-metadata=atomics %s -### 2>&1 | FileCheck -check-prefix=CHECK-ATOMICS %s
+// RUN: %clang --target=x86_64-linux-gnu -fexperimental-sanitize-metadata=covered -fno-experimental-sanitize-metadata=covered -fexperimental-sanitize-metadata=atomics %s -### 2>&1 | FileCheck -check-prefix=CHECK-ATOMICS %s
+// RUN: %clang --target=x86_64-linux-gnu -fexperimental-sanitize-metadata=all -fno-experimental-sanitize-metadata=covered %s -### 2>&1 | FileCheck -check-prefix=CHECK-ATOMICS %s
+// CHECK-ATOMICS: "-fexperimental-sanitize-metadata=atomics"
+// CHECK-ATOMICS-NOT: "-fexperimental-sanitize-metadata=covered"
+
+// RUN: %clang --target=x86_64-linux-gnu -fexperimental-sanitize-metadata=covered,atomics %s -### 2>&1 | FileCheck -check-prefix=CHECK-ALL %s
+// RUN: %clang --target=x86_64-linux-gnu -fexperimental-sanitize-metadata=covered -fexperimental-sanitize-metadata=atomics %s -### 2>&1 | FileCheck -check-prefix=CHECK-ALL %s
+// RUN: %clang --target=x86_64-linux-gnu -fexperimental-sanitize-metadata=all %s -### 2>&1 | FileCheck -check-prefix=CHECK-ALL %s
+// CHECK-ALL: "-fexperimental-sanitize-metadata=covered"
+// CHECK-ALL: "-fexperimental-sanitize-metadata=atomics"
Index: clang/test/CodeGen/sanitize-metadata.c
===
--- /dev/null
+++ clang/test/CodeGen/sanitize-metadata.c
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -O -fexperimental-sanitize-metadata=atomics -triple x86_64-gnu-linux -x c -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,ATOMICS
+// RUN: %clang_cc1 -O -fexperimental-sanitize-metadata=atomics -triple aarch64-gnu-linux -x c -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,ATOMICS
+
+int x, y;
+
+void empty() {
+// CHECK-NOT: define dso_local void @empty() {{.*}} !pcsections
+}
+
+int atomics() {
+// ATOMICS-LABEL: define dso_local i32 @atomics()
+// ATOMICS-SAME:  !pcsections ![[ATOMICS_COVERED:[0-9]+]]
+// ATOMICS-NEXT:  entry:
+// ATOMICS-NEXT:atomicrmw add {{.*}} !pcsections ![[ATOMIC_OP:[0-9]+]]
+// ATOMICS-NOT: load {{.*}} !pcsections
+  __atomic_fetch_add(&x, 1, __ATOMIC_RELAXED);
+  return y;
+}
+// ATOMICS-LABEL: __sanitizer_metadata_atomics.module_ctor
+// ATOMICS: call void @__sanitizer_metadata_atomics_add(i32 1, ptr @__start_sanmd_atomics, ptr @__stop_sanmd_atomics)
+// ATOMICS-LABEL: __sanitizer_metadata_atomics.module_dtor
+// ATOMICS: call void @__sanitizer_metadata_atomics_del(i32 1, ptr @__start_sanmd_atomics, ptr @__stop_sanmd_atomics)
+
+// CHECK-LABEL: __sanitizer_metadata_covered.module_ctor
+// CHECK: call void @__sanitizer_metadata_covered_add(i32 1, ptr @__start_sanmd_covered, ptr @__stop_sanmd_covered)
+// CHECK-LABEL: __sanitizer_metadata_covered.module_dtor
+// CHECK: call void @__sanitizer_metadata_covered_del(i32 1, ptr @__start_sanm

  1   2   >