[clang] [Clang] Introduce 'clang-nvlink-wrapper' to work around 'nvlink' (PR #96561)

2024-07-22 Thread Fangrui Song via cfe-commits

MaskRay wrote:

clang/test/CMakeLists.txt CLANG_TEST_DEPS also needs an update. `

The test might fail due to `/tmp/Rel/bin/clang-nvlink-wrapper: error: Unable to 
find 'nvlink' in path`

https://github.com/llvm/llvm-project/pull/96561
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AArch64][PAC] Sign block addresses used in indirectbr. (PR #97647)

2024-07-22 Thread Eli Friedman via cfe-commits


@@ -10909,6 +10909,14 @@ QualType Sema::CheckAdditionOperands(ExprResult &LHS, 
ExprResult &RHS,
   if (isObjCPointer && checkArithmeticOnObjCPointer(*this, Loc, PExp))
 return QualType();
 
+  // Arithmetic on label addresses is normally allowed, except when we add
+  // a ptrauth signature to the addresses.
+  if (isa(PExp) && getLangOpts().PointerAuthIndirectGotos) {

efriedma-quic wrote:

I don't think this catches all the relevant cases: there are various ways you 
could "hide" an address-of-label from this check.  Parentheses, a conditional 
operator, a constexpr variable, etc.

Maybe the check should be in IntExprEvaluator::VisitBinaryOperator.

https://github.com/llvm/llvm-project/pull/97647
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Correct confusing header in HLSLDocs (PR #100017)

2024-07-22 Thread Greg Roth via cfe-commits

https://github.com/pow2clk updated 
https://github.com/llvm/llvm-project/pull/100017

>From f325499de6336807b0d56696356a3e11c7a26ac3 Mon Sep 17 00:00:00 2001
From: Greg Roth 
Date: Mon, 22 Jul 2024 17:39:47 -0600
Subject: [PATCH 1/2] Correct confusing header in HLSLDocs

Because AvailabilityDiagnostics.rst mistakenly overlined the "Examples"
section, it was included in the generated HLSLDocs page.
By demoting it to a subheader, it shouldn't show up as a top-level
HLSLDocs page.
---
 clang/docs/HLSL/AvailabilityDiagnostics.rst | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/docs/HLSL/AvailabilityDiagnostics.rst 
b/clang/docs/HLSL/AvailabilityDiagnostics.rst
index bb9d02f21dde6..7ce82c1946b87 100644
--- a/clang/docs/HLSL/AvailabilityDiagnostics.rst
+++ b/clang/docs/HLSL/AvailabilityDiagnostics.rst
@@ -52,7 +52,6 @@ If the compilation target is a shader library, only 
availability based on shader
 
 As a result, availability based on specific shader stage will only be 
diagnosed in code that is reachable from a shader entry point or library export 
function. It also means that function bodies might be scanned multiple time. 
When that happens, care should be taken not to produce duplicated diagnostics.
 
-
 Examples
 
 

>From 9351ea72d247c8f5db513e3ea18116e4df9aad93 Mon Sep 17 00:00:00 2001
From: Greg Roth 
Date: Mon, 22 Jul 2024 17:57:35 -0600
Subject: [PATCH 2/2] Add another case with multiple top-level headers

ExpectedDifference sections were bleeding into the top page too
---
 clang/docs/HLSL/ExpectedDifferences.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/HLSL/ExpectedDifferences.rst 
b/clang/docs/HLSL/ExpectedDifferences.rst
index a29b6348e0b8e..4782eb3cda754 100644
--- a/clang/docs/HLSL/ExpectedDifferences.rst
+++ b/clang/docs/HLSL/ExpectedDifferences.rst
@@ -1,4 +1,4 @@
-
+===
 Expected Differences vs DXC and FXC
 ===
 

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


[clang] 624d322 - [Clang] Fix 'clang-nvlink-wrapper' not working w/o CUDA

2024-07-22 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2024-07-22T18:57:54-05:00
New Revision: 624d3221d1159bff98964d77c1b76e04a367d9d4

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

LOG: [Clang] Fix 'clang-nvlink-wrapper' not working w/o CUDA

Summary:
This would try to find `nvlink` and then fail even in `dry-run` mode.
We now just let it continue and pretend like we found it. Also add it to
the depends.

Added: 


Modified: 
clang/test/CMakeLists.txt
clang/tools/clang-nvlink-wrapper/ClangNVLinkWrapper.cpp

Removed: 




diff  --git a/clang/test/CMakeLists.txt b/clang/test/CMakeLists.txt
index 8303269a9ad07..299a35723b59d 100644
--- a/clang/test/CMakeLists.txt
+++ b/clang/test/CMakeLists.txt
@@ -78,6 +78,7 @@ list(APPEND CLANG_TEST_DEPS
   clang-installapi
   clang-scan-deps
   clang-linker-wrapper
+  clang-nvlink-wrapper
   clang-offload-bundler
   clang-offload-packager
   diagtool

diff  --git a/clang/tools/clang-nvlink-wrapper/ClangNVLinkWrapper.cpp 
b/clang/tools/clang-nvlink-wrapper/ClangNVLinkWrapper.cpp
index c56486b54a339..c71873160a5a0 100644
--- a/clang/tools/clang-nvlink-wrapper/ClangNVLinkWrapper.cpp
+++ b/clang/tools/clang-nvlink-wrapper/ClangNVLinkWrapper.cpp
@@ -190,7 +190,10 @@ Expected createTempFile(const ArgList &Args, 
const Twine &Prefix,
   return TempFiles.back();
 }
 
-Expected findProgram(StringRef Name, ArrayRef Paths) {
+Expected findProgram(const ArgList &Args, StringRef Name,
+  ArrayRef Paths) {
+  if (Args.hasArg(OPT_dry_run))
+return Name.str();
   ErrorOr Path = sys::findProgramByName(Name, Paths);
   if (!Path)
 Path = sys::findProgramByName(Name);
@@ -294,10 +297,9 @@ struct Symbol {
 
 Expected runPTXAs(StringRef File, const ArgList &Args) {
   std::string CudaPath = Args.getLastArgValue(OPT_cuda_path_EQ).str();
+  std::string GivenPath = Args.getLastArgValue(OPT_ptxas_path_EQ).str();
   Expected PTXAsPath =
-  Args.getLastArgValue(OPT_ptxas_path_EQ).str();
-  if (PTXAsPath->empty())
-PTXAsPath = findProgram("ptxas", {CudaPath + "/bin"});
+  findProgram(Args, "ptxas", {CudaPath + "/bin", GivenPath});
   if (!PTXAsPath)
 return PTXAsPath.takeError();
 
@@ -686,7 +688,8 @@ Error runNVLink(ArrayRef Files, const ArgList 
&Args) {
 return Error::success();
 
   std::string CudaPath = Args.getLastArgValue(OPT_cuda_path_EQ).str();
-  Expected NVLinkPath = findProgram("nvlink", {CudaPath + 
"/bin"});
+  Expected NVLinkPath =
+  findProgram(Args, "nvlink", {CudaPath + "/bin"});
   if (!NVLinkPath)
 return NVLinkPath.takeError();
 



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


[clang] Correct confusing headers in HLSLDocs (PR #100017)

2024-07-22 Thread Greg Roth via cfe-commits

https://github.com/pow2clk edited 
https://github.com/llvm/llvm-project/pull/100017
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Introduce 'clang-nvlink-wrapper' to work around 'nvlink' (PR #96561)

2024-07-22 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

> clang/test/CMakeLists.txt CLANG_TEST_DEPS also needs an update. `
> 
> The test might fail due to `/tmp/Rel/bin/clang-nvlink-wrapper: error: Unable 
> to find 'nvlink' in path`

Also noticed that one, just pushed a fix a minute ago. Sorry for the mess.

https://github.com/llvm/llvm-project/pull/96561
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 9147147 - [AIX] Detect `#pragma mc_func` (#99888)

2024-07-22 Thread via cfe-commits

Author: Qiongsi Wu
Date: 2024-07-22T20:47:53-04:00
New Revision: 9147147b5c191c22a740f8e596e62a6de1fc4f70

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

LOG: [AIX] Detect `#pragma mc_func` (#99888)

`#pragma mc_func` is an IBM XL feature that should be replaced by inline
assembly. This PR adds an option `-ferr-pragma-mc-func-aix` to detect
uses of `#pragma mc_func` and reports an error if the option is in
effect. If `-fno-err-pragma-mc-func-aix` is in effect, `#pragma mc_func`
is ignored even if `-Werror=unknown-pragmas` is in effect.

Added: 
clang/test/Preprocessor/pragma_mc_func.c

Modified: 
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Driver/Options.td
clang/include/clang/Lex/PreprocessorOptions.h
clang/include/clang/Parse/Parser.h
clang/lib/Driver/ToolChains/AIX.cpp
clang/lib/Parse/ParsePragma.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 12aab09f28556..f8d50d12bb935 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1260,6 +1260,9 @@ def warn_pragma_intrinsic_builtin : Warning<
 def warn_pragma_unused_expected_var : Warning<
   "expected '#pragma unused' argument to be a variable name">,
   InGroup;
+// - #pragma mc_func
+def err_pragma_mc_func_not_supported :
+   Error<"#pragma mc_func is not supported">;
 // - #pragma init_seg
 def warn_pragma_init_seg_unsupported_target : Warning<
   "'#pragma init_seg' is only supported when targeting a "

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 70dab1b16094d..5989a3b7ef693 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8084,6 +8084,13 @@ def source_date_epoch : Separate<["-"], 
"source-date-epoch">,
 
 } // let Visibility = [CC1Option]
 
+defm err_pragma_mc_func_aix : BoolFOption<"err-pragma-mc-func-aix",
+  PreprocessorOpts<"ErrorOnPragmaMcfuncOnAIX">, DefaultFalse,
+  PosFlag,
+  NegFlag>;
+
 
//===--===//
 // CUDA Options
 
//===--===//

diff  --git a/clang/include/clang/Lex/PreprocessorOptions.h 
b/clang/include/clang/Lex/PreprocessorOptions.h
index c2e3d68333024..3f7dd9db18ba7 100644
--- a/clang/include/clang/Lex/PreprocessorOptions.h
+++ b/clang/include/clang/Lex/PreprocessorOptions.h
@@ -211,6 +211,10 @@ class PreprocessorOptions {
   /// If set, the UNIX timestamp specified by SOURCE_DATE_EPOCH.
   std::optional SourceDateEpoch;
 
+  /// If set, the preprocessor reports an error when processing #pragma mc_func
+  /// on AIX.
+  bool ErrorOnPragmaMcfuncOnAIX = false;
+
 public:
   PreprocessorOptions() : PrecompiledPreambleBytes(0, false) {}
 
@@ -248,6 +252,7 @@ class PreprocessorOptions {
 PrecompiledPreambleBytes.first = 0;
 PrecompiledPreambleBytes.second = false;
 RetainExcludedConditionalBlocks = false;
+ErrorOnPragmaMcfuncOnAIX = false;
   }
 };
 

diff  --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 93e60be512aae..613bab9120dfc 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -221,6 +221,7 @@ class Parser : public CodeCompletionHandler {
   std::unique_ptr MaxTokensHerePragmaHandler;
   std::unique_ptr MaxTokensTotalPragmaHandler;
   std::unique_ptr RISCVPragmaHandler;
+  std::unique_ptr MCFuncPragmaHandler;
 
   std::unique_ptr CommentSemaHandler;
 

diff  --git a/clang/lib/Driver/ToolChains/AIX.cpp 
b/clang/lib/Driver/ToolChains/AIX.cpp
index b04502a57a9f7..fb780fb75651d 100644
--- a/clang/lib/Driver/ToolChains/AIX.cpp
+++ b/clang/lib/Driver/ToolChains/AIX.cpp
@@ -557,6 +557,12 @@ void AIX::addClangTargetOptions(
   if (!Args.getLastArgNoClaim(options::OPT_fsized_deallocation,
   options::OPT_fno_sized_deallocation))
 CC1Args.push_back("-fno-sized-deallocation");
+
+  if (Args.hasFlag(options::OPT_ferr_pragma_mc_func_aix,
+   options::OPT_fno_err_pragma_mc_func_aix, false))
+CC1Args.push_back("-ferr-pragma-mc-func-aix");
+  else
+CC1Args.push_back("-fno-err-pragma-mc-func-aix");
 }
 
 void AIX::addProfileRTLibs(const llvm::opt::ArgList &Args,

diff  --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp
index cc6f18b5b319f..aef4ddb758816 100644
--- a/clang/lib/Parse/ParsePragma.cpp
+++ b/clang/lib/Parse/ParsePragma.cpp
@@ -14,6 +14,7 @@
 #include "clang/Basic/PragmaKinds.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/PreprocessorOptions.h"
 

[clang] [AIX] Detect `#pragma mc_func` (PR #99888)

2024-07-22 Thread Qiongsi Wu via cfe-commits

https://github.com/qiongsiwu closed 
https://github.com/llvm/llvm-project/pull/99888
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Introduce 'clang-nvlink-wrapper' to work around 'nvlink' (PR #96561)

2024-07-22 Thread Justin Bogner via cfe-commits


@@ -0,0 +1,44 @@
+set(LLVM_LINK_COMPONENTS
+  ${LLVM_TARGETS_TO_BUILD}
+  BitWriter
+  Core
+  BinaryFormat
+  MC
+  Target
+  TransformUtils
+  Analysis
+  Passes
+  IRReader
+  Object
+  Option
+  Support
+  TargetParser
+  CodeGen
+  LTO
+  )
+
+set(LLVM_TARGET_DEFINITIONS NVLinkOpts.td)
+tablegen(LLVM NVLinkOpts.inc -gen-opt-parser-defs)
+add_public_tablegen_target(NVLinkWrapperOpts)
+
+if(NOT CLANG_BUILT_STANDALONE)
+  set(tablegen_deps intrinsics_gen NVLinkWrapperOpts)
+endif()
+
+add_clang_tool(clang-nvlink-wrapper
+  ClangNVLinkWrapper.cpp
+
+  DEPENDS
+  ${tablegen_deps}
+  )
+
+set(CLANG_NVLINK_WRAPPER_LIB_DEPS
+  clangBasic
+  )
+
+target_compile_options(clang-nvlink-wrapper PRIVATE "-g" "-O0")

bogner wrote:

This looks suspicious. Do we actually want to build this with `-g -O0` all the 
time or was this left in from debugging or something like that? In the unlikely 
event that we do want this for some reason, it won't work as is on windows 
anyway.

https://github.com/llvm/llvm-project/pull/96561
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-scan-deps] Ignore import/include directives with missing filenames (PR #99520)

2024-07-22 Thread Michael Spencer via cfe-commits

https://github.com/Bigcheese approved this pull request.


https://github.com/llvm/llvm-project/pull/99520
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lldb] [llvm] [BOLT][DWARF][NFC] Split processUnitDIE into two lambdas (PR #99957)

2024-07-22 Thread Sayhaan Siddiqui via cfe-commits

https://github.com/sayhaan updated 
https://github.com/llvm/llvm-project/pull/99957

>From 11fff0b2d1868f1e8fce988b2b41a38de42dff61 Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Tue, 1 Jun 2021 11:37:41 -0700
Subject: [PATCH 1/4] Rebase: [Facebook] Add clang driver options to test debug
 info and BOLT

Summary:
This is an essential piece of infrastructure for us to be
continuously testing debug info with BOLT. We can't only make changes
to a test repo because we need to change debuginfo tests to call BOLT,
hence, this diff needs to sit in our opensource repo. But when upstreaming
to LLVM, this should be kept BOLT-only outside of LLVM. When upstreaming,
we need to git diff and check all folders that are being modified by our
commits and discard this one (and leave as an internal diff).

To test BOLT in debuginfo tests, configure it with -DLLVM_TEST_BOLT=ON.
Then run check-lldb and check-debuginfo.

Manual rebase conflict history:
https://phabricator.intern.facebook.com/D29205224
https://phabricator.intern.facebook.com/D29564078
https://phabricator.intern.facebook.com/D33289118
https://phabricator.intern.facebook.com/D34957174
https://phabricator.intern.facebook.com/D35317341

Test Plan:
tested locally
Configured with:
-DLLVM_ENABLE_PROJECTS="clang;lld;lldb;compiler-rt;bolt;debuginfo-tests"
-DLLVM_TEST_BOLT=ON
Ran test suite with:
ninja check-debuginfo
ninja check-lldb

Reviewers: maks, #llvm-bolt

Reviewed By: maks

Subscribers: ayermolo, phabricatorlinter

Differential Revision: https://phabricator.intern.facebook.com/D46256657

Tasks: T92898286
---
 clang/include/clang/Driver/Options.td  |  4 
 clang/lib/Driver/ToolChains/Gnu.cpp| 29 ++
 cross-project-tests/lit.cfg.py | 14 -
 cross-project-tests/lit.site.cfg.py.in |  4 
 lldb/test/API/lit.cfg.py   |  5 +
 lldb/test/API/lit.site.cfg.py.in   |  8 +++
 lldb/test/Shell/helper/toolchain.py|  5 +
 lldb/test/Shell/lit.site.cfg.py.in |  9 
 llvm/CMakeLists.txt|  4 
 9 files changed, 81 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 9c6cebd77ff0a..8ccbc4b372ba3 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5553,6 +5553,10 @@ def pg : Flag<["-"], "pg">, HelpText<"Enable mcount 
instrumentation">,
   MarshallingInfoFlag>;
 def pipe : Flag<["-", "--"], "pipe">,
   HelpText<"Use pipes between commands, when possible">;
+// Facebook T92898286
+def post_link_optimize : Flag<["--"], "post-link-optimize">,
+  HelpText<"Apply post-link optimizations using BOLT">;
+// End Facebook T92898286
 def prebind__all__twolevel__modules : Flag<["-"], 
"prebind_all_twolevel_modules">;
 def prebind : Flag<["-"], "prebind">;
 def preload : Flag<["-"], "preload">;
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 52c2ee90b1b28..ff20deb9c4f86 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -672,12 +672,41 @@ void tools::gnutools::Linker::ConstructJob(Compilation 
&C, const JobAction &JA,
 }
   }
 
+  // Facebook T92898286
+  if (Args.hasArg(options::OPT_post_link_optimize))
+CmdArgs.push_back("-q");
+  // End Facebook T92898286
+
   Args.AddAllArgs(CmdArgs, options::OPT_T);
 
   const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath());
   C.addCommand(std::make_unique(JA, *this,
  ResponseFileSupport::AtFileCurCP(),
  Exec, CmdArgs, Inputs, Output));
+  // Facebook T92898286
+  if (!Args.hasArg(options::OPT_post_link_optimize) || !Output.isFilename())
+return;
+
+  const char *MvExec = Args.MakeArgString(ToolChain.GetProgramPath("mv"));
+  ArgStringList MoveCmdArgs;
+  MoveCmdArgs.push_back(Output.getFilename());
+  const char *PreBoltBin =
+  Args.MakeArgString(Twine(Output.getFilename()) + ".pre-bolt");
+  MoveCmdArgs.push_back(PreBoltBin);
+  C.addCommand(std::make_unique(JA, *this, 
ResponseFileSupport::None(),
+ MvExec, MoveCmdArgs, std::nullopt));
+
+  ArgStringList BoltCmdArgs;
+  const char *BoltExec =
+  Args.MakeArgString(ToolChain.GetProgramPath("llvm-bolt"));
+  BoltCmdArgs.push_back(PreBoltBin);
+  BoltCmdArgs.push_back("-reorder-blocks=reverse");
+  BoltCmdArgs.push_back("-update-debug-sections");
+  BoltCmdArgs.push_back("-o");
+  BoltCmdArgs.push_back(Output.getFilename());
+  C.addCommand(std::make_unique(JA, *this, 
ResponseFileSupport::None(),
+ BoltExec, BoltCmdArgs, std::nullopt));
+  // End Facebook T92898286
 }
 
 void tools::gnutools::Assembler::ConstructJob(Compilation &C,
diff --git a/cross-project-tests/lit.cfg.py b/cross-project-tests/lit.cfg.py
index 774c4eaf4d976..619634578dfe6 100644
--- a/cross-project-tests/lit.cfg.py
+++ b/c

[clang] Add _MM_FROUND_TO_NEAREST_TIES_EVEN to avx512fintrin.h (PR #99691)

2024-07-22 Thread Shengchen Kan via cfe-commits

https://github.com/KanRobert commented:

Update the tests for `m512_maskz_cvt_roundepu64_ps` e.t.c (in 
avx512dq-builtins.c )?

https://github.com/llvm/llvm-project/pull/99691
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Implement P2582R1: CTAD from inherited constructors (PR #98788)

2024-07-22 Thread via cfe-commits


@@ -0,0 +1,260 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++23 -verify %s

antangelo wrote:

Thanks, fixed

https://github.com/llvm/llvm-project/pull/98788
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)

2024-07-22 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov edited 
https://github.com/llvm/llvm-project/pull/99833
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Implement P2582R1: CTAD from inherited constructors (PR #98788)

2024-07-22 Thread via cfe-commits


@@ -0,0 +1,260 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++23 -verify %s
+

antangelo wrote:

Thanks for catching this, I've fixed this case and added a test

https://github.com/llvm/llvm-project/pull/98788
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Implement P2582R1: CTAD from inherited constructors (PR #98788)

2024-07-22 Thread via cfe-commits


@@ -1957,17 +1957,26 @@ class CXXDeductionGuideDecl : public FunctionDecl {
 ExplicitSpecifier ES,
 const DeclarationNameInfo &NameInfo, QualType T,
 TypeSourceInfo *TInfo, SourceLocation EndLocation,
-CXXConstructorDecl *Ctor, DeductionCandidate Kind)
+CXXConstructorDecl *Ctor, DeductionCandidate Kind,
+CXXDeductionGuideDecl *GeneratedFrom,
+bool IsGeneratedFromInheritedConstructor)
   : FunctionDecl(CXXDeductionGuide, C, DC, StartLoc, NameInfo, T, TInfo,
  SC_None, false, false, ConstexprSpecKind::Unspecified),
-Ctor(Ctor), ExplicitSpec(ES) {
+Ctor(Ctor), ExplicitSpec(ES),
+SourceDeductionGuide(GeneratedFrom,
+ IsGeneratedFromInheritedConstructor) {
 if (EndLocation.isValid())
   setRangeEnd(EndLocation);
 setDeductionCandidateKind(Kind);
   }
 
   CXXConstructorDecl *Ctor;
   ExplicitSpecifier ExplicitSpec;
+  // The deduction guide, if any, that this deduction guide was generated from,
+  // in the case of alias template deduction or CTAD from inherited
+  // constructors. The bool member indicates whether this deduction guide is
+  // generated from an inherited constructor.

antangelo wrote:

Thanks for the suggestion, I've updated it to use an enum here.

https://github.com/llvm/llvm-project/pull/98788
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Implement P2582R1: CTAD from inherited constructors (PR #98788)

2024-07-22 Thread via cfe-commits


@@ -980,19 +986,69 @@ getRHSTemplateDeclAndArgs(Sema &SemaRef, 
TypeAliasTemplateDecl *AliasTemplate) {
   return {Template, AliasRhsTemplateArgs};
 }
 
+// Build the type for a deduction guide generated from an inherited constructor
+// [over.match.class.deduct]p1.10:
+// ... the set contains the guides of A with the return type R
+// of each guide replaced with `typename CC::type` ...
+std::pair
+buildInheritedConstructorDeductionGuideType(
+Sema &SemaRef, TypeSourceInfo *DerivedClassMapperType,
+TemplateDecl *DeducingTemplate, TypeSourceInfo *SourceGuideTSI) {
+  auto &Context = SemaRef.Context;
+  const auto *FPT = SourceGuideTSI->getType()->getAs();
+  assert(FPT && "Source Guide type should be a FunctionProtoType");
+
+  // This substitution can fail in cases where the source return type
+  // is not dependent and the derived class is not deducible
+  Sema::SFINAETrap Trap(SemaRef);
+
+  MultiLevelTemplateArgumentList Args;
+  Args.addOuterTemplateArguments(DeducingTemplate,
+ TemplateArgument(FPT->getReturnType()), 
false);
+  Args.addOuterRetainedLevels(DeducingTemplate->getTemplateDepth());
+  TypeSourceInfo *ReturnTypeTSI =
+  SemaRef.SubstType(DerivedClassMapperType, Args,
+DeducingTemplate->getBeginLoc(), DeclarationName());
+  if (!ReturnTypeTSI || Trap.hasErrorOccurred())
+return {nullptr, QualType()};
+  QualType ReturnType = ReturnTypeTSI->getType();
+
+  TypeLocBuilder TLB;
+  TLB.pushFullCopy(ReturnTypeTSI->getTypeLoc());
+
+  QualType FT = Context.getFunctionType(ReturnType, FPT->getParamTypes(),
+FPT->getExtProtoInfo());
+  FunctionProtoTypeLoc NewTL = TLB.push(FT);
+  const auto &TL = SourceGuideTSI->getTypeLoc().getAs();
+  NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
+  NewTL.setLParenLoc(TL.getLParenLoc());
+  NewTL.setRParenLoc(TL.getRParenLoc());
+  NewTL.setExceptionSpecRange(TL.getExceptionSpecRange());
+  NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
+  for (unsigned I = 0, E = NewTL.getNumParams(); I != E; ++I)
+NewTL.setParam(I, TL.getParam(I));
+
+  TypeSourceInfo *TSI = TLB.getTypeSourceInfo(Context, FT);
+  return {TSI, ReturnType};
+}
+
 // Build deduction guides for a type alias template from the given underlying
 // deduction guide F.
-FunctionTemplateDecl *
-BuildDeductionGuideForTypeAlias(Sema &SemaRef,
-TypeAliasTemplateDecl *AliasTemplate,
-FunctionTemplateDecl *F, SourceLocation Loc) {
+FunctionTemplateDecl *BuildDeductionGuideForTypeAlias(
+Sema &SemaRef, TypeAliasTemplateDecl *AliasTemplate,
+FunctionTemplateDecl *F, SourceLocation Loc,
+TemplateDecl *DeducingTemplate = nullptr,
+TypeSourceInfo *DerivedClassMapperType = nullptr) {
   LocalInstantiationScope Scope(SemaRef);
   Sema::InstantiatingTemplate BuildingDeductionGuides(
   SemaRef, AliasTemplate->getLocation(), F,
   Sema::InstantiatingTemplate::BuildingDeductionGuidesTag{});
   if (BuildingDeductionGuides.isInvalid())
 return nullptr;
 
+  if (!DeducingTemplate)
+DeducingTemplate = AliasTemplate;

antangelo wrote:

Done

https://github.com/llvm/llvm-project/pull/98788
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Implement P2582R1: CTAD from inherited constructors (PR #98788)

2024-07-22 Thread via cfe-commits


@@ -980,19 +986,69 @@ getRHSTemplateDeclAndArgs(Sema &SemaRef, 
TypeAliasTemplateDecl *AliasTemplate) {
   return {Template, AliasRhsTemplateArgs};
 }
 
+// Build the type for a deduction guide generated from an inherited constructor
+// [over.match.class.deduct]p1.10:
+// ... the set contains the guides of A with the return type R
+// of each guide replaced with `typename CC::type` ...
+std::pair
+buildInheritedConstructorDeductionGuideType(
+Sema &SemaRef, TypeSourceInfo *DerivedClassMapperType,
+TemplateDecl *DeducingTemplate, TypeSourceInfo *SourceGuideTSI) {
+  auto &Context = SemaRef.Context;
+  const auto *FPT = SourceGuideTSI->getType()->getAs();
+  assert(FPT && "Source Guide type should be a FunctionProtoType");
+
+  // This substitution can fail in cases where the source return type
+  // is not dependent and the derived class is not deducible
+  Sema::SFINAETrap Trap(SemaRef);
+
+  MultiLevelTemplateArgumentList Args;
+  Args.addOuterTemplateArguments(DeducingTemplate,
+ TemplateArgument(FPT->getReturnType()), 
false);
+  Args.addOuterRetainedLevels(DeducingTemplate->getTemplateDepth());
+  TypeSourceInfo *ReturnTypeTSI =
+  SemaRef.SubstType(DerivedClassMapperType, Args,
+DeducingTemplate->getBeginLoc(), DeclarationName());
+  if (!ReturnTypeTSI || Trap.hasErrorOccurred())
+return {nullptr, QualType()};
+  QualType ReturnType = ReturnTypeTSI->getType();
+
+  TypeLocBuilder TLB;
+  TLB.pushFullCopy(ReturnTypeTSI->getTypeLoc());
+
+  QualType FT = Context.getFunctionType(ReturnType, FPT->getParamTypes(),
+FPT->getExtProtoInfo());
+  FunctionProtoTypeLoc NewTL = TLB.push(FT);
+  const auto &TL = SourceGuideTSI->getTypeLoc().getAs();
+  NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
+  NewTL.setLParenLoc(TL.getLParenLoc());
+  NewTL.setRParenLoc(TL.getRParenLoc());
+  NewTL.setExceptionSpecRange(TL.getExceptionSpecRange());
+  NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
+  for (unsigned I = 0, E = NewTL.getNumParams(); I != E; ++I)
+NewTL.setParam(I, TL.getParam(I));
+
+  TypeSourceInfo *TSI = TLB.getTypeSourceInfo(Context, FT);
+  return {TSI, ReturnType};
+}
+
 // Build deduction guides for a type alias template from the given underlying
 // deduction guide F.
-FunctionTemplateDecl *
-BuildDeductionGuideForTypeAlias(Sema &SemaRef,
-TypeAliasTemplateDecl *AliasTemplate,
-FunctionTemplateDecl *F, SourceLocation Loc) {
+FunctionTemplateDecl *BuildDeductionGuideForTypeAlias(

antangelo wrote:

Done, updated to add mention of the new parameters for the inherited 
constructors case

https://github.com/llvm/llvm-project/pull/98788
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Implement P2582R1: CTAD from inherited constructors (PR #98788)

2024-07-22 Thread via cfe-commits


@@ -1426,6 +1727,34 @@ void Sema::DeclareImplicitDeductionGuides(TemplateDecl 
*Template,
   if (!AddedAny)
 Transform.buildSimpleDeductionGuide(std::nullopt);
 
+  // FIXME: Handle explicit deduction guides from inherited constructors
+  // when the base deduction guides are declared after this has first run
+  if (getLangOpts().CPlusPlus23 &&
+  Pattern->getTemplatedDecl()->hasDefinition()) {
+unsigned BaseIdx = 0;
+for (const auto &Base : Pattern->getTemplatedDecl()->bases()) {
+  ++BaseIdx;
+  if (!Base.getType()->isDependentType())

antangelo wrote:

I've updated the method of looking up inherited constructors to use the 
`UnresolvedUsingValueDecl`s on the pattern directly instead of finding them 
through the list of bases. It will now create generic deduction guides for 
`B` in your example, which will work in the case of `B` but fail after 
instantiation if `T2` is not `int`.

https://github.com/llvm/llvm-project/pull/98788
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Implement P2582R1: CTAD from inherited constructors (PR #98788)

2024-07-22 Thread via cfe-commits


@@ -0,0 +1,260 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++23 -verify %s
+
+namespace test1 {
+  template struct Base {
+template requires true
+Base(T);
+  };
+
+  template struct InheritsCtors : public Base {
+using Base::Base;
+  };
+
+  InheritsCtors inheritsCtors(1);
+  using IC = InheritsCtors;
+  using IC = decltype(inheritsCtors);

antangelo wrote:

Done

https://github.com/llvm/llvm-project/pull/98788
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Clang: don't unnecessarily convert inline-asm operands to x86mmx in IR. (PR #98273)

2024-07-22 Thread Phoebe Wang via cfe-commits


@@ -58173,8 +58173,8 @@ X86TargetLowering::getSingleConstraintMatchWeight(
   return CW_Invalid;
 // Any MMX reg
 case 'm':
-  if (Ty->isX86_MMXTy() && Subtarget.hasMMX())
-return Wt;
+  if (Ty->getPrimitiveSizeInBits() == 64 && Subtarget.hasMMX())

phoebewang wrote:

Add a test case for "Ym"?

https://github.com/llvm/llvm-project/pull/98273
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [PowerPC] Add support for -mcpu=pwr11 / -mtune=pwr11 (PR #99511)

2024-07-22 Thread Chen Zheng via cfe-commits

https://github.com/chenzheng1030 edited 
https://github.com/llvm/llvm-project/pull/99511
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [PowerPC] Add support for -mcpu=pwr11 / -mtune=pwr11 (PR #99511)

2024-07-22 Thread Chen Zheng via cfe-commits

https://github.com/chenzheng1030 approved this pull request.

LGTM except one nit. Thanks very much for adding this support.

https://github.com/llvm/llvm-project/pull/99511
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [PowerPC] Add support for -mcpu=pwr11 / -mtune=pwr11 (PR #99511)

2024-07-22 Thread Chen Zheng via cfe-commits


@@ -3485,9 +3485,11 @@ unsigned PPCInstrInfo::getSpillTarget() const {
   // With P10, we may need to spill paired vector registers or accumulator
   // registers. MMA implies paired vectors, so we can just check that.
   bool IsP10Variant = Subtarget.isISA3_1() || Subtarget.pairedVectorMemops();
-  return Subtarget.isISAFuture() ? 3 : IsP10Variant ?
-   2 : Subtarget.hasP9Vector() ?
-   1 : 0;
+  // P11 uses the P10 target.
+  return Subtarget.isISAFuture()   ? 3

chenzheng1030 wrote:

nit: is this formatted by clang-format? Maybe we should not change these lines 
as you are not changing them.

https://github.com/llvm/llvm-project/pull/99511
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SPARC][clang] Add -m(no-)v8plus flags handling (PR #98713)

2024-07-22 Thread via cfe-commits


@@ -179,6 +179,13 @@ void sparc::getSparcTargetFeatures(const Driver &D, const 
ArgList &Args,
   Features.push_back("-hard-quad-float");
   }
 
+  if (Arg *A = Args.getLastArg(options::OPT_mv8plus, options::OPT_mno_v8plus)) 
{
+if (A->getOption().matches(options::OPT_mv8plus))

koachan wrote:

It is off by default, but we also want it to override features enabled 
implicitly by `-mcpu` flags.
For example if I pass `-mcpu=v9 -mno-v8plus` then I want the compilation to be 
done with `v9` turned off.
So I think it is needed... unless there's other ways to do this?

https://github.com/llvm/llvm-project/pull/98713
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Introduce 'clang-nvlink-wrapper' to work around 'nvlink' (PR #96561)

2024-07-22 Thread Vladimir Vereschaka via cfe-commits

vvereschaka wrote:

@jhuber6 ,
there is still few failed bot because of these changes
* https://lab.llvm.org/buildbot/#/builders/193/builds/1224
* https://lab.llvm.org/buildbot/#/builders/2/builds/2790

would you fix the problem or revert the changes?


https://github.com/llvm/llvm-project/pull/96561
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [LoongArch] Enable 128-bits vector by default (PR #100056)

2024-07-22 Thread via cfe-commits

https://github.com/Ami-zhang created 
https://github.com/llvm/llvm-project/pull/100056

This commit is to enable 128 vector feature by default, in order to be 
consistent with gcc.

>From d6e0e004d46194008a73d2de510a706932d11776 Mon Sep 17 00:00:00 2001
From: Ami-zhang 
Date: Thu, 18 Jul 2024 09:33:35 +0800
Subject: [PATCH] [LoongArch] Enable 128-bits vector by default

This commit is to enable 128 vector feature by default, in
order to be consistent with gcc.
---
 .../lib/Driver/ToolChains/Arch/LoongArch.cpp  | 76 +++
 clang/test/Driver/loongarch-features.c|  2 +-
 clang/test/Driver/loongarch-mlasx.c   |  6 +-
 clang/test/Driver/loongarch-msimd.c   |  4 +-
 clang/test/Driver/loongarch-msingle-float.c   |  4 +-
 clang/test/Driver/loongarch-msoft-float.c |  4 +-
 clang/test/Preprocessor/init-loongarch.c  |  8 +-
 7 files changed, 60 insertions(+), 44 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp 
b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
index 4a2b9efc9ffad..b0756c42a6e4c 100644
--- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -127,6 +127,11 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
const llvm::Triple &Triple,
const ArgList &Args,
std::vector &Features) {
+  // Enable the `lsx` feature on 64-bit LoongArch by default.
+  if (Triple.isLoongArch64() &&
+  (!Args.hasArg(clang::driver::options::OPT_march_EQ)))
+Features.push_back("+lsx");
+
   std::string ArchName;
   if (const Arg *A = Args.getLastArg(options::OPT_march_EQ))
 ArchName = A->getValue();
@@ -145,9 +150,11 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
 } else if (A->getOption().matches(options::OPT_msingle_float)) {
   Features.push_back("+f");
   Features.push_back("-d");
+  Features.push_back("-lsx");
 } else /*Soft-float*/ {
   Features.push_back("-f");
   Features.push_back("-d");
+  Features.push_back("-lsx");
 }
   } else if (const Arg *A = Args.getLastArg(options::OPT_mfpu_EQ)) {
 StringRef FPU = A->getValue();
@@ -157,9 +164,11 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
 } else if (FPU == "32") {
   Features.push_back("+f");
   Features.push_back("-d");
+  Features.push_back("-lsx");
 } else if (FPU == "0" || FPU == "none") {
   Features.push_back("-f");
   Features.push_back("-d");
+  Features.push_back("-lsx");
 } else {
   D.Diag(diag::err_drv_loongarch_invalid_mfpu_EQ) << FPU;
 }
@@ -174,6 +183,42 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
 A->ignoreTargetSpecific();
   if (Arg *A = Args.getLastArgNoClaim(options::OPT_mfpu_EQ))
 A->ignoreTargetSpecific();
+  if (Arg *A = Args.getLastArgNoClaim(options::OPT_msimd_EQ))
+A->ignoreTargetSpecific();
+
+  // Select lsx/lasx feature determined by -msimd=.
+  // Option -msimd= precedes -m[no-]lsx and -m[no-]lasx.
+  if (const Arg *A = Args.getLastArg(options::OPT_msimd_EQ)) {
+StringRef MSIMD = A->getValue();
+if (MSIMD == "lsx") {
+  // Option -msimd=lsx depends on 64-bit FPU.
+  // -m*-float and -mfpu=none/0/32 conflict with -msimd=lsx.
+  if (llvm::find(Features, "-d") != Features.end())
+D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LSX*/ 0;
+  else
+Features.push_back("+lsx");
+} else if (MSIMD == "lasx") {
+  // Option -msimd=lasx depends on 64-bit FPU and LSX.
+  // -m*-float, -mfpu=none/0/32 and -mno-lsx conflict with -msimd=lasx.
+  if (llvm::find(Features, "-d") != Features.end())
+D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LASX*/ 1;
+  else if (llvm::find(Features, "-lsx") != Features.end())
+D.Diag(diag::err_drv_loongarch_invalid_simd_option_combination);
+
+  // The command options do not contain -mno-lasx.
+  if (!Args.getLastArg(options::OPT_mno_lasx)) {
+Features.push_back("+lsx");
+Features.push_back("+lasx");
+  }
+} else if (MSIMD == "none") {
+  if (llvm::find(Features, "+lsx") != Features.end())
+Features.push_back("-lsx");
+  if (llvm::find(Features, "+lasx") != Features.end())
+Features.push_back("-lasx");
+} else {
+  D.Diag(diag::err_drv_loongarch_invalid_msimd_EQ) << MSIMD;
+}
+  }
 
   // Select lsx feature determined by -m[no-]lsx.
   if (const Arg *A = Args.getLastArg(options::OPT_mlsx, options::OPT_mno_lsx)) 
{
@@ -197,8 +242,6 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
 if (A->getOption().matches(options::OPT_mlasx)) {
   if (llvm::find(Features, "-d") != Features.end())
 D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LASX*/ 1;
-  else if (llvm::find(Features, "-lsx") != Features.end())
-D.Diag(diag:

[clang] [LoongArch] Enable 128-bits vector by default (PR #100056)

2024-07-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-loongarch

Author: None (Ami-zhang)


Changes

This commit is to enable 128 vector feature by default, in order to be 
consistent with gcc.

---
Full diff: https://github.com/llvm/llvm-project/pull/100056.diff


7 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Arch/LoongArch.cpp (+45-31) 
- (modified) clang/test/Driver/loongarch-features.c (+1-1) 
- (modified) clang/test/Driver/loongarch-mlasx.c (+4-2) 
- (modified) clang/test/Driver/loongarch-msimd.c (+2-2) 
- (modified) clang/test/Driver/loongarch-msingle-float.c (+2-2) 
- (modified) clang/test/Driver/loongarch-msoft-float.c (+2-2) 
- (modified) clang/test/Preprocessor/init-loongarch.c (+4-4) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp 
b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
index 4a2b9efc9ffad..b0756c42a6e4c 100644
--- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -127,6 +127,11 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
const llvm::Triple &Triple,
const ArgList &Args,
std::vector &Features) {
+  // Enable the `lsx` feature on 64-bit LoongArch by default.
+  if (Triple.isLoongArch64() &&
+  (!Args.hasArg(clang::driver::options::OPT_march_EQ)))
+Features.push_back("+lsx");
+
   std::string ArchName;
   if (const Arg *A = Args.getLastArg(options::OPT_march_EQ))
 ArchName = A->getValue();
@@ -145,9 +150,11 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
 } else if (A->getOption().matches(options::OPT_msingle_float)) {
   Features.push_back("+f");
   Features.push_back("-d");
+  Features.push_back("-lsx");
 } else /*Soft-float*/ {
   Features.push_back("-f");
   Features.push_back("-d");
+  Features.push_back("-lsx");
 }
   } else if (const Arg *A = Args.getLastArg(options::OPT_mfpu_EQ)) {
 StringRef FPU = A->getValue();
@@ -157,9 +164,11 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
 } else if (FPU == "32") {
   Features.push_back("+f");
   Features.push_back("-d");
+  Features.push_back("-lsx");
 } else if (FPU == "0" || FPU == "none") {
   Features.push_back("-f");
   Features.push_back("-d");
+  Features.push_back("-lsx");
 } else {
   D.Diag(diag::err_drv_loongarch_invalid_mfpu_EQ) << FPU;
 }
@@ -174,6 +183,42 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
 A->ignoreTargetSpecific();
   if (Arg *A = Args.getLastArgNoClaim(options::OPT_mfpu_EQ))
 A->ignoreTargetSpecific();
+  if (Arg *A = Args.getLastArgNoClaim(options::OPT_msimd_EQ))
+A->ignoreTargetSpecific();
+
+  // Select lsx/lasx feature determined by -msimd=.
+  // Option -msimd= precedes -m[no-]lsx and -m[no-]lasx.
+  if (const Arg *A = Args.getLastArg(options::OPT_msimd_EQ)) {
+StringRef MSIMD = A->getValue();
+if (MSIMD == "lsx") {
+  // Option -msimd=lsx depends on 64-bit FPU.
+  // -m*-float and -mfpu=none/0/32 conflict with -msimd=lsx.
+  if (llvm::find(Features, "-d") != Features.end())
+D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LSX*/ 0;
+  else
+Features.push_back("+lsx");
+} else if (MSIMD == "lasx") {
+  // Option -msimd=lasx depends on 64-bit FPU and LSX.
+  // -m*-float, -mfpu=none/0/32 and -mno-lsx conflict with -msimd=lasx.
+  if (llvm::find(Features, "-d") != Features.end())
+D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LASX*/ 1;
+  else if (llvm::find(Features, "-lsx") != Features.end())
+D.Diag(diag::err_drv_loongarch_invalid_simd_option_combination);
+
+  // The command options do not contain -mno-lasx.
+  if (!Args.getLastArg(options::OPT_mno_lasx)) {
+Features.push_back("+lsx");
+Features.push_back("+lasx");
+  }
+} else if (MSIMD == "none") {
+  if (llvm::find(Features, "+lsx") != Features.end())
+Features.push_back("-lsx");
+  if (llvm::find(Features, "+lasx") != Features.end())
+Features.push_back("-lasx");
+} else {
+  D.Diag(diag::err_drv_loongarch_invalid_msimd_EQ) << MSIMD;
+}
+  }
 
   // Select lsx feature determined by -m[no-]lsx.
   if (const Arg *A = Args.getLastArg(options::OPT_mlsx, options::OPT_mno_lsx)) 
{
@@ -197,8 +242,6 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
 if (A->getOption().matches(options::OPT_mlasx)) {
   if (llvm::find(Features, "-d") != Features.end())
 D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LASX*/ 1;
-  else if (llvm::find(Features, "-lsx") != Features.end())
-D.Diag(diag::err_drv_loongarch_invalid_simd_option_combination);
   else { /*-mlasx*/
 Features.push_back("+lsx");
 Features.push_back("+lasx");
@@ -206,35 +249,6 @@ void loongarch::getL

[clang] [llvm] [LoongArch] Support -march=la64v1.0 and -march=la64v1.1 (PR #100057)

2024-07-22 Thread via cfe-commits

https://github.com/Ami-zhang created 
https://github.com/llvm/llvm-project/pull/100057

The newly added strings `la64v1.0` and `la64v1.1` in `-march` are as described 
in LoongArch toolchains conventions (see [1]).

The target-cpu/feature attributes are forwarded to compiler when specifying 
particular `-march` parameter. The default cpu `loongarch64` is returned when 
archname is `la64v1.0` or `la64v1.1`.

In addition, this commit adds `la64v1.0`/`la64v1.1` to "__loongarch_arch" and 
adds definition for macro "__loongarch_frecipe".

[1]: https://github.com/loongson/la-toolchain-conventions

>From 12205c317a1bbd29792939186d67d8470c7c16af Mon Sep 17 00:00:00 2001
From: Ami-zhang 
Date: Tue, 25 Jun 2024 17:18:20 +0800
Subject: [PATCH] [LoongArch] Support -march=la64v1.0 and -march=la64v1.1

The newly added strings `la64v1.0` and `la64v1.1` in `-march`
are as described in LoongArch toolchains conventions (see [1]).

The target-cpu/feature attributes are forwarded to compiler when
specifying particular `-march` parameter. The default cpu `loongarch64`
is returned when archname is `la64v1.0` or `la64v1.1`.

In addition, this commit adds `la64v1.0`/`la64v1.1` to "__loongarch_arch"
and adds definition for macro "__loongarch_frecipe".

[1]: https://github.com/loongson/la-toolchain-conventions
---
 clang/lib/Basic/Targets/LoongArch.cpp | 23 +++-
 clang/lib/Basic/Targets/LoongArch.h   |  2 ++
 .../lib/Driver/ToolChains/Arch/LoongArch.cpp  | 10 +--
 clang/test/Driver/loongarch-march.c   | 22 +++
 clang/test/Preprocessor/init-loongarch.c  | 27 ---
 .../TargetParser/LoongArchTargetParser.cpp| 11 
 6 files changed, 88 insertions(+), 7 deletions(-)

diff --git a/clang/lib/Basic/Targets/LoongArch.cpp 
b/clang/lib/Basic/Targets/LoongArch.cpp
index 75f71a337b7a4..cb3fd12c48ddb 100644
--- a/clang/lib/Basic/Targets/LoongArch.cpp
+++ b/clang/lib/Basic/Targets/LoongArch.cpp
@@ -200,7 +200,24 @@ void LoongArchTargetInfo::getTargetDefines(const 
LangOptions &Opts,
 
   // Define __loongarch_arch.
   StringRef ArchName = getCPU();
-  Builder.defineMacro("__loongarch_arch", Twine('"') + ArchName + Twine('"'));
+  if (ArchName == "loongarch64") {
+if (HasFeatureLSX) {
+  // TODO: As more features of the V1.1 ISA are supported, a unified "v1.1"
+  // arch feature set will be used to include all sub-features belonging to
+  // the V1.1 ISA version.
+  if (HasFeatureFrecipe)
+Builder.defineMacro("__loongarch_arch",
+Twine('"') + "la64v1.1" + Twine('"'));
+  else
+Builder.defineMacro("__loongarch_arch",
+Twine('"') + "la64v1.0" + Twine('"'));
+} else {
+  Builder.defineMacro("__loongarch_arch",
+  Twine('"') + ArchName + Twine('"'));
+}
+  } else {
+Builder.defineMacro("__loongarch_arch", Twine('"') + ArchName + 
Twine('"'));
+  }
 
   // Define __loongarch_tune.
   StringRef TuneCPU = getTargetOpts().TuneCPU;
@@ -216,6 +233,8 @@ void LoongArchTargetInfo::getTargetDefines(const 
LangOptions &Opts,
 Builder.defineMacro("__loongarch_simd_width", "128");
 Builder.defineMacro("__loongarch_sx", Twine(1));
   }
+  if (HasFeatureFrecipe)
+Builder.defineMacro("__loongarch_frecipe", Twine(1));
 
   StringRef ABI = getABI();
   if (ABI == "lp64d" || ABI == "lp64f" || ABI == "lp64s")
@@ -291,6 +310,8 @@ bool LoongArchTargetInfo::handleTargetFeatures(
   HasFeatureLASX = true;
 else if (Feature == "-ual")
   HasUnalignedAccess = false;
+else if (Feature == "+frecipe")
+  HasFeatureFrecipe = true;
   }
   return true;
 }
diff --git a/clang/lib/Basic/Targets/LoongArch.h 
b/clang/lib/Basic/Targets/LoongArch.h
index 5fc223483951e..c668ca7eca047 100644
--- a/clang/lib/Basic/Targets/LoongArch.h
+++ b/clang/lib/Basic/Targets/LoongArch.h
@@ -29,6 +29,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public 
TargetInfo {
   bool HasFeatureF;
   bool HasFeatureLSX;
   bool HasFeatureLASX;
+  bool HasFeatureFrecipe;
 
 public:
   LoongArchTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
@@ -37,6 +38,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public 
TargetInfo {
 HasFeatureF = false;
 HasFeatureLSX = false;
 HasFeatureLASX = false;
+HasFeatureFrecipe = false;
 LongDoubleWidth = 128;
 LongDoubleAlign = 128;
 LongDoubleFormat = &llvm::APFloat::IEEEquad();
diff --git a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp 
b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
index 4a2b9efc9ffad..b149d48d97fe8 100644
--- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -253,8 +253,14 @@ std::string loongarch::postProcessTargetCPUString(const 
std::string &CPU,
 std::string loongarch::getLoongArchTargetCPU(const llvm::opt::ArgList &Args,
  const llvm::Triple &Triple) 

[clang] [llvm] [LoongArch] Support -march=la64v1.0 and -march=la64v1.1 (PR #100057)

2024-07-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-loongarch

Author: None (Ami-zhang)


Changes

The newly added strings `la64v1.0` and `la64v1.1` in `-march` are as described 
in LoongArch toolchains conventions (see [1]).

The target-cpu/feature attributes are forwarded to compiler when specifying 
particular `-march` parameter. The default cpu `loongarch64` is returned when 
archname is `la64v1.0` or `la64v1.1`.

In addition, this commit adds `la64v1.0`/`la64v1.1` to "__loongarch_arch" and 
adds definition for macro "__loongarch_frecipe".

[1]: https://github.com/loongson/la-toolchain-conventions

---
Full diff: https://github.com/llvm/llvm-project/pull/100057.diff


6 Files Affected:

- (modified) clang/lib/Basic/Targets/LoongArch.cpp (+22-1) 
- (modified) clang/lib/Basic/Targets/LoongArch.h (+2) 
- (modified) clang/lib/Driver/ToolChains/Arch/LoongArch.cpp (+8-2) 
- (modified) clang/test/Driver/loongarch-march.c (+22) 
- (modified) clang/test/Preprocessor/init-loongarch.c (+23-4) 
- (modified) llvm/lib/TargetParser/LoongArchTargetParser.cpp (+11) 


``diff
diff --git a/clang/lib/Basic/Targets/LoongArch.cpp 
b/clang/lib/Basic/Targets/LoongArch.cpp
index 75f71a337b7a4..cb3fd12c48ddb 100644
--- a/clang/lib/Basic/Targets/LoongArch.cpp
+++ b/clang/lib/Basic/Targets/LoongArch.cpp
@@ -200,7 +200,24 @@ void LoongArchTargetInfo::getTargetDefines(const 
LangOptions &Opts,
 
   // Define __loongarch_arch.
   StringRef ArchName = getCPU();
-  Builder.defineMacro("__loongarch_arch", Twine('"') + ArchName + Twine('"'));
+  if (ArchName == "loongarch64") {
+if (HasFeatureLSX) {
+  // TODO: As more features of the V1.1 ISA are supported, a unified "v1.1"
+  // arch feature set will be used to include all sub-features belonging to
+  // the V1.1 ISA version.
+  if (HasFeatureFrecipe)
+Builder.defineMacro("__loongarch_arch",
+Twine('"') + "la64v1.1" + Twine('"'));
+  else
+Builder.defineMacro("__loongarch_arch",
+Twine('"') + "la64v1.0" + Twine('"'));
+} else {
+  Builder.defineMacro("__loongarch_arch",
+  Twine('"') + ArchName + Twine('"'));
+}
+  } else {
+Builder.defineMacro("__loongarch_arch", Twine('"') + ArchName + 
Twine('"'));
+  }
 
   // Define __loongarch_tune.
   StringRef TuneCPU = getTargetOpts().TuneCPU;
@@ -216,6 +233,8 @@ void LoongArchTargetInfo::getTargetDefines(const 
LangOptions &Opts,
 Builder.defineMacro("__loongarch_simd_width", "128");
 Builder.defineMacro("__loongarch_sx", Twine(1));
   }
+  if (HasFeatureFrecipe)
+Builder.defineMacro("__loongarch_frecipe", Twine(1));
 
   StringRef ABI = getABI();
   if (ABI == "lp64d" || ABI == "lp64f" || ABI == "lp64s")
@@ -291,6 +310,8 @@ bool LoongArchTargetInfo::handleTargetFeatures(
   HasFeatureLASX = true;
 else if (Feature == "-ual")
   HasUnalignedAccess = false;
+else if (Feature == "+frecipe")
+  HasFeatureFrecipe = true;
   }
   return true;
 }
diff --git a/clang/lib/Basic/Targets/LoongArch.h 
b/clang/lib/Basic/Targets/LoongArch.h
index 5fc223483951e..c668ca7eca047 100644
--- a/clang/lib/Basic/Targets/LoongArch.h
+++ b/clang/lib/Basic/Targets/LoongArch.h
@@ -29,6 +29,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public 
TargetInfo {
   bool HasFeatureF;
   bool HasFeatureLSX;
   bool HasFeatureLASX;
+  bool HasFeatureFrecipe;
 
 public:
   LoongArchTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
@@ -37,6 +38,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public 
TargetInfo {
 HasFeatureF = false;
 HasFeatureLSX = false;
 HasFeatureLASX = false;
+HasFeatureFrecipe = false;
 LongDoubleWidth = 128;
 LongDoubleAlign = 128;
 LongDoubleFormat = &llvm::APFloat::IEEEquad();
diff --git a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp 
b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
index 4a2b9efc9ffad..b149d48d97fe8 100644
--- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -253,8 +253,14 @@ std::string loongarch::postProcessTargetCPUString(const 
std::string &CPU,
 std::string loongarch::getLoongArchTargetCPU(const llvm::opt::ArgList &Args,
  const llvm::Triple &Triple) {
   std::string CPU;
+  std::string Arch;
   // If we have -march, use that.
-  if (const Arg *A = Args.getLastArg(options::OPT_march_EQ))
-CPU = A->getValue();
+  if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
+Arch = A->getValue();
+if (Arch == "la64v1.0" || Arch == "la64v1.1")
+  CPU = llvm::LoongArch::getDefaultArch(Triple.isLoongArch64());
+else
+  CPU = Arch;
+  }
   return postProcessTargetCPUString(CPU, Triple);
 }
diff --git a/clang/test/Driver/loongarch-march.c 
b/clang/test/Driver/loongarch-march.c
index 9214130cd034f..d06da72a755cb 100644
--- a/clang/test/Driver/loongarch-march.c
+++ b/clang/test/Driver/lo

[clang] [Clang] Introduce 'clang-nvlink-wrapper' to work around 'nvlink' (PR #96561)

2024-07-22 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

> @jhuber6 , there is still few failed bot because of these changes
> 
> * https://lab.llvm.org/buildbot/#/builders/193/builds/1224
> 
> * https://lab.llvm.org/buildbot/#/builders/2/builds/2790
> 
> 
> would you fix the problem or revert the changes?

Looks like it's complaining about the const-ness of the value decomposition? 
It's fine one my end so I don't know if it's a Windows thing, I'll just try 
putting `const` there and seeing if that fixes it.

https://github.com/llvm/llvm-project/pull/96561
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Ignore empty FieldDecls when asking for the field number (PR #100040)

2024-07-22 Thread Eli Friedman via cfe-commits

https://github.com/efriedma-quic approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/100040
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 34ab855 - [clang][deps] Ignore import/include directives with missing filenames (#99520)

2024-07-22 Thread via cfe-commits

Author: Cyndy Ishida
Date: 2024-07-22T21:10:05-07:00
New Revision: 34ab855826b8cb0c3b46c770b83390bd1fe95c64

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

LOG: [clang][deps] Ignore import/include directives with missing filenames 
(#99520)

Previously source input like `#import ` resulted in infinite calls
append the same token into `CurDirTokens`. This patch now ignores those
directive lines if they won't actually end up being compiled. (e.g.
macro guarded)

resolves: rdar://121247565

Added: 


Modified: 
clang/lib/Lex/DependencyDirectivesScanner.cpp
clang/unittests/Lex/DependencyDirectivesScannerTest.cpp

Removed: 




diff  --git a/clang/lib/Lex/DependencyDirectivesScanner.cpp 
b/clang/lib/Lex/DependencyDirectivesScanner.cpp
index 8a020d0e95fe3..31a4c0f52b465 100644
--- a/clang/lib/Lex/DependencyDirectivesScanner.cpp
+++ b/clang/lib/Lex/DependencyDirectivesScanner.cpp
@@ -88,8 +88,8 @@ struct Scanner {
   [[nodiscard]] dependency_directives_scan::Token &
   lexToken(const char *&First, const char *const End);
 
-  dependency_directives_scan::Token &lexIncludeFilename(const char *&First,
-const char *const End);
+  [[nodiscard]] 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);
@@ -544,7 +544,7 @@ Scanner::lexIncludeFilename(const char *&First, const char 
*const End) {
 void Scanner::lexPPDirectiveBody(const char *&First, const char *const End) {
   while (true) {
 const dependency_directives_scan::Token &Tok = lexToken(First, End);
-if (Tok.is(tok::eod))
+if (Tok.is(tok::eod) || Tok.is(tok::eof))
   break;
   }
 }
@@ -912,7 +912,11 @@ bool Scanner::lexPPLine(const char *&First, const char 
*const End) {
   case pp___include_macros:
   case pp_include_next:
   case pp_import:
-lexIncludeFilename(First, End);
+// Ignore missing filenames in include or import directives.
+if (lexIncludeFilename(First, End).is(tok::eod)) {
+  skipDirective(Id, First, End);
+  return true;
+}
 break;
   default:
 break;

diff  --git a/clang/unittests/Lex/DependencyDirectivesScannerTest.cpp 
b/clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
index 23304fff950eb..513e184be09ec 100644
--- a/clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
+++ b/clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
@@ -650,6 +650,17 @@ TEST(MinimizeSourceToDependencyDirectivesTest, AtImport) {
   EXPECT_STREQ("@import A.B;\n", Out.data());
 }
 
+TEST(MinimizeSourceToDependencyDirectivesTest, EmptyIncludesAndImports) {
+  SmallVector Out;
+
+  ASSERT_TRUE(minimizeSourceToDependencyDirectives("#import\n", Out));
+  ASSERT_TRUE(minimizeSourceToDependencyDirectives("#include\n", Out));
+  ASSERT_TRUE(minimizeSourceToDependencyDirectives("#ifdef A\n"
+   "#import \n"
+   "#endif\n",
+   Out));
+}
+
 TEST(MinimizeSourceToDependencyDirectivesTest, AtImportFailures) {
   SmallVector Out;
 



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


[clang] [clang-scan-deps] Ignore import/include directives with missing filenames (PR #99520)

2024-07-22 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida closed 
https://github.com/llvm/llvm-project/pull/99520
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][CodeGen] Don't crash on sizeless output. (PR #99849)

2024-07-22 Thread Eli Friedman via cfe-commits


@@ -2751,7 +2751,10 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
 
   if (RequiresCast) {
 unsigned Size = getContext().getTypeSize(QTy);
-Ty = llvm::IntegerType::get(getLLVMContext(), Size);
+if (Size)
+  Ty = llvm::IntegerType::get(getLLVMContext(), Size);
+else
+  CGM.Error(S.getAsmLoc(), "Output operand is sizeless!");

efriedma-quic wrote:

Can we use the SourceLocation of the specific operand in question, instead of 
using `S.getAsmLoc()`, which points at the beginning of the asm statement?

Diagnostics aren't capitalized, and don't end in punctuation.

Maybe say "size zero" instead of "sizeless".

https://github.com/llvm/llvm-project/pull/99849
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][CodeGen] Don't crash on sizeless output. (PR #99849)

2024-07-22 Thread Eli Friedman via cfe-commits


@@ -0,0 +1,7 @@
+// RUN: not %clang_cc1 -S %s -o /dev/null 2>&1 | FileCheck %s

efriedma-quic wrote:

Please use "-verify" to check clang diagnostics, not FileCheck.

Is there any existing file with inline asm diagnostics this can be added to?

https://github.com/llvm/llvm-project/pull/99849
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [LoongArch] Enable 128-bits vector by default (PR #100056)

2024-07-22 Thread Fangrui Song via cfe-commits


@@ -127,6 +127,11 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
const llvm::Triple &Triple,
const ArgList &Args,
std::vector &Features) {
+  // Enable the `lsx` feature on 64-bit LoongArch by default.
+  if (Triple.isLoongArch64() &&
+  (!Args.hasArg(clang::driver::options::OPT_march_EQ)))

MaskRay wrote:

Prefer `hasArgNoClaim` to have a single place to claim the option.
Unclaimed options will lead to an unused argument warning.

https://github.com/llvm/llvm-project/pull/100056
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] b8721fa - [AArch64][PAC] Sign block addresses used in indirectbr. (#97647)

2024-07-22 Thread via cfe-commits

Author: Ahmed Bougacha
Date: 2024-07-22T21:24:39-07:00
New Revision: b8721fa0afa65e8e44d7f264712499d24f3cc68b

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

LOG: [AArch64][PAC] Sign block addresses used in indirectbr. (#97647)

Enabled in clang using:
-fptrauth-indirect-gotos

and at the IR level using function attribute:
"ptrauth-indirect-gotos"

Signing uses IA and a per-function integer discriminator. The
discriminator isn't ABI-visible, and is currently:
ptrauth_string_discriminator(" blockaddress")

A sufficiently sophisticated frontend could benefit from per-indirectbr
discrimination, which would need additional machinery, such as allowing
"ptrauth" bundles on indirectbr. For our purposes, the simple scheme
above is sufficient.

This approach doesn't support subtracting label addresses and using
the result as offsets, because each label address is signed.
Pointer arithmetic on signed pointers corrupts the signature bits,
and because label address expressions aren't typed beyond void*,
we can't do anything reliably intelligent on the arithmetic exprs.
Not signing addresses when used to form offsets would allow
easily hijacking control flow by overwriting the offset.

This diagnoses the basic cases (`&&lbl2 - &&lbl1`) in the frontend,
while we evaluate either alternative implementations (e.g., lowering
blockaddress to a bb number, and indirectbr to a checked jump-table),
or better diagnostics (both at the frontend level and on unencodable
IR constants).

Added: 
clang/test/Sema/ptrauth-indirect-goto.c
llvm/test/CodeGen/AArch64/ptrauth-indirectbr.ll

Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/Features.def
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Basic/PointerAuthOptions.h
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/CodeGen/ptrauth-function-attributes.c
llvm/docs/PointerAuth.md
llvm/include/llvm/CodeGen/AsmPrinter.h
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
llvm/lib/Target/AArch64/AArch64FastISel.cpp
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
llvm/lib/Target/AArch64/AArch64ISelLowering.h
llvm/lib/Target/AArch64/AArch64InstrInfo.td
llvm/lib/Target/AArch64/AArch64Subtarget.cpp
llvm/lib/Target/AArch64/AArch64Subtarget.h
llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c4a4e8064fac2..b8d97a6b14fe6 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -949,6 +949,9 @@ def 
note_ptrauth_virtual_function_pointer_incomplete_arg_ret :
 def note_ptrauth_virtual_function_incomplete_arg_ret_type :
   Note<"%0 is incomplete">;
 
+def err_ptrauth_indirect_goto_addrlabel_arithmetic : Error<
+  "%select{subtraction|addition}0 of address-of-label expressions is not "
+  "supported with ptrauth indirect gotos">;
 
 /// main()
 // static main() is not an error in C, just in C++.

diff  --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index 14572bc0407fc..dc71ef8f98692 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -112,6 +112,7 @@ FEATURE(ptrauth_type_info_vtable_pointer_discrimination, 
LangOpts.PointerAuthTyp
 FEATURE(ptrauth_member_function_pointer_type_discrimination, 
LangOpts.PointerAuthCalls)
 FEATURE(ptrauth_init_fini, LangOpts.PointerAuthInitFini)
 FEATURE(ptrauth_function_pointer_type_discrimination, 
LangOpts.PointerAuthFunctionTypeDiscrimination)
+FEATURE(ptrauth_indirect_gotos, LangOpts.PointerAuthIndirectGotos)
 EXTENSION(swiftcc,
   PP.getTargetInfo().checkCallingConvention(CC_Swift) ==
   clang::TargetInfo::CCCR_OK)

diff  --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 8b09049b5cb97..834a6f6cd43e3 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -165,6 +165,7 @@ LANGOPT(ExperimentalLibrary, 1, 0, "enable unstable and 
experimental library fea
 LANGOPT(PointerAuthIntrinsics, 1, 0, "pointer authentication intrinsics")
 LANGOPT(PointerAuthCalls  , 1, 0, "function pointer authentication")
 LANGOPT(PointerAuthReturns, 1, 0, "return pointer authentication")
+LANGOPT(PointerAuthIndirectGotos, 1, 0, "indirect gotos pointer 
authentication")
 LANGOPT(PointerAuthAuthTraps, 1, 0, "pointer authentication failure traps")
 

[clang] [llvm] [AArch64][PAC] Sign block addresses used in indirectbr. (PR #97647)

2024-07-22 Thread Ahmed Bougacha via cfe-commits

https://github.com/ahmedbougacha closed 
https://github.com/llvm/llvm-project/pull/97647
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ExprConstant] Handle shift overflow the same way as other kinds of overflow (PR #99579)

2024-07-22 Thread Eli Friedman via cfe-commits

https://github.com/efriedma-quic updated 
https://github.com/llvm/llvm-project/pull/99579

>From 1137011c51285b083cab6c15de670e64337d3de0 Mon Sep 17 00:00:00 2001
From: Eli Friedman 
Date: Thu, 18 Jul 2024 14:51:13 -0700
Subject: [PATCH 1/6] [ExprConstant] Handle shift overflow the same way as
 other kinds of overflow

We have a mechanism to allow folding expressions that aren't ICEs as an
extension; use it more consistently.

This ends up causing bad effects on diagnostics in a few cases, but
that's not specific to shifts; it's a general issue with the way those
uses handle overflow diagnostics.
---
 clang/lib/AST/ExprConstant.cpp   | 24 +++-
 clang/lib/AST/Interp/Interp.h| 21 +
 clang/test/AST/Interp/shifts.cpp | 13 +++--
 clang/test/CXX/basic/basic.types/p10.cpp |  2 +-
 clang/test/Sema/constant-builtins-2.c| 12 
 clang/test/Sema/shift-count-negative.c   | 15 ---
 clang/test/Sema/shift-count-overflow.c   | 13 +++--
 clang/test/Sema/shift-negative-value.c   | 18 --
 8 files changed, 59 insertions(+), 59 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 0aeac9d03eed3..bd69dc54a93dc 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -2849,19 +2849,23 @@ static bool handleIntIntBinOp(EvalInfo &Info, const 
BinaryOperator *E,
 if (SA != RHS) {
   Info.CCEDiag(E, diag::note_constexpr_large_shift)
 << RHS << E->getType() << LHS.getBitWidth();
+  if (!Info.noteUndefinedBehavior())
+return false;
 } else if (LHS.isSigned() && !Info.getLangOpts().CPlusPlus20) {
   // C++11 [expr.shift]p2: A signed left shift must have a non-negative
   // operand, and must not overflow the corresponding unsigned type.
   // C++2a [expr.shift]p2: E1 << E2 is the unique value congruent to
   // E1 x 2^E2 module 2^N.
-  if (LHS.isNegative())
+  if (LHS.isNegative()) {
 Info.CCEDiag(E, diag::note_constexpr_lshift_of_negative) << LHS;
-  else if (LHS.countl_zero() < SA)
+if (!Info.noteUndefinedBehavior())
+  return false;
+  } else if (LHS.countl_zero() < SA) {
 Info.CCEDiag(E, diag::note_constexpr_lshift_discards);
+if (!Info.noteUndefinedBehavior())
+  return false;
+  }
 }
-if (Info.EvalStatus.Diag && !Info.EvalStatus.Diag->empty() &&
-Info.getLangOpts().CPlusPlus11)
-  return false;
 Result = LHS << SA;
 return true;
   }
@@ -2875,6 +2879,8 @@ static bool handleIntIntBinOp(EvalInfo &Info, const 
BinaryOperator *E,
   // During constant-folding, a negative shift is an opposite shift. Such a
   // shift is not a constant expression.
   Info.CCEDiag(E, diag::note_constexpr_negative_shift) << RHS;
+  if (!Info.noteUndefinedBehavior())
+return false;
   RHS = -RHS;
   goto shift_left;
 }
@@ -2882,13 +2888,13 @@ static bool handleIntIntBinOp(EvalInfo &Info, const 
BinaryOperator *E,
 // C++11 [expr.shift]p1: Shift width must be less than the bit width of the
 // shifted type.
 unsigned SA = (unsigned) RHS.getLimitedValue(LHS.getBitWidth()-1);
-if (SA != RHS)
+if (SA != RHS) {
   Info.CCEDiag(E, diag::note_constexpr_large_shift)
 << RHS << E->getType() << LHS.getBitWidth();
+  if (!Info.noteUndefinedBehavior())
+return false;
+}
 
-if (Info.EvalStatus.Diag && !Info.EvalStatus.Diag->empty() &&
-Info.getLangOpts().CPlusPlus11)
-  return false;
 Result = LHS >> SA;
 return true;
   }
diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index c7d8604c7dc2a..1b17db61d7bac 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -137,7 +137,8 @@ bool CheckShift(InterpState &S, CodePtr OpPC, const LT 
&LHS, const RT &RHS,
   if (RHS.isNegative()) {
 const SourceInfo &Loc = S.Current->getSource(OpPC);
 S.CCEDiag(Loc, diag::note_constexpr_negative_shift) << RHS.toAPSInt();
-return false;
+if (!S.noteUndefinedBehavior())
+  return false;
   }
 
   // C++11 [expr.shift]p1: Shift width must be less than the bit width of
@@ -147,17 +148,23 @@ bool CheckShift(InterpState &S, CodePtr OpPC, const LT 
&LHS, const RT &RHS,
 const APSInt Val = RHS.toAPSInt();
 QualType Ty = E->getType();
 S.CCEDiag(E, diag::note_constexpr_large_shift) << Val << Ty << Bits;
-return !(S.getEvalStatus().Diag && !S.getEvalStatus().Diag->empty() && 
S.getLangOpts().CPlusPlus11);
+if (!S.noteUndefinedBehavior())
+  return false;
   }
 
   if (LHS.isSigned() && !S.getLangOpts().CPlusPlus20) {
 const Expr *E = S.Current->getExpr(OpPC);
 // C++11 [expr.shift]p2: A signed left shift must have a non-negative
 // operand, and must not overflow the corresponding unsigned type.
-if (LHS.isNegative())
+if (LHS.isNegative()) {

[clang] [ExprConstant] Handle shift overflow the same way as other kinds of overflow (PR #99579)

2024-07-22 Thread Eli Friedman via cfe-commits

https://github.com/efriedma-quic updated 
https://github.com/llvm/llvm-project/pull/99579

>From 1137011c51285b083cab6c15de670e64337d3de0 Mon Sep 17 00:00:00 2001
From: Eli Friedman 
Date: Thu, 18 Jul 2024 14:51:13 -0700
Subject: [PATCH 1/6] [ExprConstant] Handle shift overflow the same way as
 other kinds of overflow

We have a mechanism to allow folding expressions that aren't ICEs as an
extension; use it more consistently.

This ends up causing bad effects on diagnostics in a few cases, but
that's not specific to shifts; it's a general issue with the way those
uses handle overflow diagnostics.
---
 clang/lib/AST/ExprConstant.cpp   | 24 +++-
 clang/lib/AST/Interp/Interp.h| 21 +
 clang/test/AST/Interp/shifts.cpp | 13 +++--
 clang/test/CXX/basic/basic.types/p10.cpp |  2 +-
 clang/test/Sema/constant-builtins-2.c| 12 
 clang/test/Sema/shift-count-negative.c   | 15 ---
 clang/test/Sema/shift-count-overflow.c   | 13 +++--
 clang/test/Sema/shift-negative-value.c   | 18 --
 8 files changed, 59 insertions(+), 59 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 0aeac9d03eed3..bd69dc54a93dc 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -2849,19 +2849,23 @@ static bool handleIntIntBinOp(EvalInfo &Info, const 
BinaryOperator *E,
 if (SA != RHS) {
   Info.CCEDiag(E, diag::note_constexpr_large_shift)
 << RHS << E->getType() << LHS.getBitWidth();
+  if (!Info.noteUndefinedBehavior())
+return false;
 } else if (LHS.isSigned() && !Info.getLangOpts().CPlusPlus20) {
   // C++11 [expr.shift]p2: A signed left shift must have a non-negative
   // operand, and must not overflow the corresponding unsigned type.
   // C++2a [expr.shift]p2: E1 << E2 is the unique value congruent to
   // E1 x 2^E2 module 2^N.
-  if (LHS.isNegative())
+  if (LHS.isNegative()) {
 Info.CCEDiag(E, diag::note_constexpr_lshift_of_negative) << LHS;
-  else if (LHS.countl_zero() < SA)
+if (!Info.noteUndefinedBehavior())
+  return false;
+  } else if (LHS.countl_zero() < SA) {
 Info.CCEDiag(E, diag::note_constexpr_lshift_discards);
+if (!Info.noteUndefinedBehavior())
+  return false;
+  }
 }
-if (Info.EvalStatus.Diag && !Info.EvalStatus.Diag->empty() &&
-Info.getLangOpts().CPlusPlus11)
-  return false;
 Result = LHS << SA;
 return true;
   }
@@ -2875,6 +2879,8 @@ static bool handleIntIntBinOp(EvalInfo &Info, const 
BinaryOperator *E,
   // During constant-folding, a negative shift is an opposite shift. Such a
   // shift is not a constant expression.
   Info.CCEDiag(E, diag::note_constexpr_negative_shift) << RHS;
+  if (!Info.noteUndefinedBehavior())
+return false;
   RHS = -RHS;
   goto shift_left;
 }
@@ -2882,13 +2888,13 @@ static bool handleIntIntBinOp(EvalInfo &Info, const 
BinaryOperator *E,
 // C++11 [expr.shift]p1: Shift width must be less than the bit width of the
 // shifted type.
 unsigned SA = (unsigned) RHS.getLimitedValue(LHS.getBitWidth()-1);
-if (SA != RHS)
+if (SA != RHS) {
   Info.CCEDiag(E, diag::note_constexpr_large_shift)
 << RHS << E->getType() << LHS.getBitWidth();
+  if (!Info.noteUndefinedBehavior())
+return false;
+}
 
-if (Info.EvalStatus.Diag && !Info.EvalStatus.Diag->empty() &&
-Info.getLangOpts().CPlusPlus11)
-  return false;
 Result = LHS >> SA;
 return true;
   }
diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index c7d8604c7dc2a..1b17db61d7bac 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -137,7 +137,8 @@ bool CheckShift(InterpState &S, CodePtr OpPC, const LT 
&LHS, const RT &RHS,
   if (RHS.isNegative()) {
 const SourceInfo &Loc = S.Current->getSource(OpPC);
 S.CCEDiag(Loc, diag::note_constexpr_negative_shift) << RHS.toAPSInt();
-return false;
+if (!S.noteUndefinedBehavior())
+  return false;
   }
 
   // C++11 [expr.shift]p1: Shift width must be less than the bit width of
@@ -147,17 +148,23 @@ bool CheckShift(InterpState &S, CodePtr OpPC, const LT 
&LHS, const RT &RHS,
 const APSInt Val = RHS.toAPSInt();
 QualType Ty = E->getType();
 S.CCEDiag(E, diag::note_constexpr_large_shift) << Val << Ty << Bits;
-return !(S.getEvalStatus().Diag && !S.getEvalStatus().Diag->empty() && 
S.getLangOpts().CPlusPlus11);
+if (!S.noteUndefinedBehavior())
+  return false;
   }
 
   if (LHS.isSigned() && !S.getLangOpts().CPlusPlus20) {
 const Expr *E = S.Current->getExpr(OpPC);
 // C++11 [expr.shift]p2: A signed left shift must have a non-negative
 // operand, and must not overflow the corresponding unsigned type.
-if (LHS.isNegative())
+if (LHS.isNegative()) {

[clang] [ExprConstant] Handle shift overflow the same way as other kinds of overflow (PR #99579)

2024-07-22 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

There's some existing coverage of the affected diagnostics, which shows we 
continue to produce those diagnostics... but I added a few more tests for 
in-class static member variables.

https://github.com/llvm/llvm-project/pull/99579
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [clang] Support -Wa, options -mmsa and -mno-msa (PR #99615)

2024-07-22 Thread Fangrui Song via cfe-commits


@@ -5337,9 +5337,13 @@ def mmadd4 : Flag<["-"], "mmadd4">, 
Group,
 def mno_madd4 : Flag<["-"], "mno-madd4">, Group,
   HelpText<"Disable the generation of 4-operand madd.s, madd.d and related 
instructions.">;
 def mmsa : Flag<["-"], "mmsa">, Group,
-  HelpText<"Enable MSA ASE (MIPS only)">;
+  Visibility<[ClangOption, CC1AsOption]>,

MaskRay wrote:

See how --crel --no-crel is handled. Add a bool variable and only add `-mmsa` 
when the variable is true.

https://github.com/llvm/llvm-project/pull/99615
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Define ATOMIC_FLAG_INIT correctly for C++. (PR #97534)

2024-07-22 Thread Chris Copeland via cfe-commits

https://github.com/chrisnc updated 
https://github.com/llvm/llvm-project/pull/97534

>From 1b39c59e0ec3cbe1f2cabc650b983883439dde31 Mon Sep 17 00:00:00 2001
From: Chris Copeland 
Date: Wed, 3 Jul 2024 00:11:39 -0700
Subject: [PATCH] [clang] Define `ATOMIC_FLAG_INIT` correctly for C++.

---
 clang/docs/ReleaseNotes.rst| 3 +++
 clang/lib/Headers/stdatomic.h  | 4 
 clang/test/Headers/stdatomic.c | 5 +
 3 files changed, 12 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d03459f7cc42c..587921850798b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -891,6 +891,9 @@ Bug Fixes in This Version
 - Fixed an assertion failure when a template non-type parameter contains
   an invalid expression.
 
+- Fixed the definition of ``ATOMIC_FLAG_INIT`` in  so it can
+  be used in C++.
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/Headers/stdatomic.h b/clang/lib/Headers/stdatomic.h
index 2027055f38796..1991351f9e9ef 100644
--- a/clang/lib/Headers/stdatomic.h
+++ b/clang/lib/Headers/stdatomic.h
@@ -172,7 +172,11 @@ typedef _Atomic(uintmax_t)  atomic_uintmax_t;
 
 typedef struct atomic_flag { atomic_bool _Value; } atomic_flag;
 
+#ifdef __cplusplus
+#define ATOMIC_FLAG_INIT {false}
+#else
 #define ATOMIC_FLAG_INIT { 0 }
+#endif
 
 /* These should be provided by the libc implementation. */
 #ifdef __cplusplus
diff --git a/clang/test/Headers/stdatomic.c b/clang/test/Headers/stdatomic.c
index 3643fd4245b31..9afd531a9ed9b 100644
--- a/clang/test/Headers/stdatomic.c
+++ b/clang/test/Headers/stdatomic.c
@@ -1,5 +1,8 @@
 // RUN: %clang_cc1 -std=c11 -E %s | FileCheck %s
 // RUN: %clang_cc1 -std=c11 -fms-compatibility -E %s | FileCheck %s
+// RUN: %clang_cc1 -std=c11 %s -verify
+// RUN: %clang_cc1 -x c++ -std=c++11 %s -verify
+// expected-no-diagnostics
 #include 
 
 int bool_lock_free = ATOMIC_BOOL_LOCK_FREE;
@@ -31,3 +34,5 @@ int llong_lock_free = ATOMIC_LLONG_LOCK_FREE;
 
 int pointer_lock_free = ATOMIC_POINTER_LOCK_FREE;
 // CHECK: pointer_lock_free = {{ *[012] *;}}
+
+atomic_flag f = ATOMIC_FLAG_INIT;

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


[clang] [clang] Define ATOMIC_FLAG_INIT correctly for C++. (PR #97534)

2024-07-22 Thread Chris Copeland via cfe-commits


@@ -750,6 +750,8 @@ Bug Fixes in This Version
 
 - Fixed `static_cast` to array of unknown bound. Fixes (#GH62863).
 
+- Fixed the definition of ATOMIC_FLAG_INIT in stdatomic.h so it can be used in 
C++.

chrisnc wrote:

Done.

https://github.com/llvm/llvm-project/pull/97534
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Define ATOMIC_FLAG_INIT correctly for C++. (PR #97534)

2024-07-22 Thread Chris Copeland via cfe-commits

chrisnc wrote:

Rebased and added a test case. I confirmed that the test fails using the 
current definition of `ATOMIC_FLAG_INIT`:

```
error: 'expected-error' diagnostics seen but not expected:
  Line 38: non-constant-expression cannot be narrowed from type 'int' to 
'atomic_bool' (aka '_Atomic(bool)') in initializer list
error: 'expected-note' diagnostics seen but not expected:
  Line 38: insert an explicit cast to silence this issue
2 errors generated.
```

https://github.com/llvm/llvm-project/pull/97534
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [LoongArch] Enable 128-bits vector by default (PR #100056)

2024-07-22 Thread via cfe-commits

https://github.com/Ami-zhang updated 
https://github.com/llvm/llvm-project/pull/100056

>From d6e0e004d46194008a73d2de510a706932d11776 Mon Sep 17 00:00:00 2001
From: Ami-zhang 
Date: Thu, 18 Jul 2024 09:33:35 +0800
Subject: [PATCH] [LoongArch] Enable 128-bits vector by default

This commit is to enable 128 vector feature by default, in
order to be consistent with gcc.
---
 .../lib/Driver/ToolChains/Arch/LoongArch.cpp  | 76 +++
 clang/test/Driver/loongarch-features.c|  2 +-
 clang/test/Driver/loongarch-mlasx.c   |  6 +-
 clang/test/Driver/loongarch-msimd.c   |  4 +-
 clang/test/Driver/loongarch-msingle-float.c   |  4 +-
 clang/test/Driver/loongarch-msoft-float.c |  4 +-
 clang/test/Preprocessor/init-loongarch.c  |  8 +-
 7 files changed, 60 insertions(+), 44 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp 
b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
index 4a2b9efc9ffad..b0756c42a6e4c 100644
--- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -127,6 +127,11 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
const llvm::Triple &Triple,
const ArgList &Args,
std::vector &Features) {
+  // Enable the `lsx` feature on 64-bit LoongArch by default.
+  if (Triple.isLoongArch64() &&
+  (!Args.hasArg(clang::driver::options::OPT_march_EQ)))
+Features.push_back("+lsx");
+
   std::string ArchName;
   if (const Arg *A = Args.getLastArg(options::OPT_march_EQ))
 ArchName = A->getValue();
@@ -145,9 +150,11 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
 } else if (A->getOption().matches(options::OPT_msingle_float)) {
   Features.push_back("+f");
   Features.push_back("-d");
+  Features.push_back("-lsx");
 } else /*Soft-float*/ {
   Features.push_back("-f");
   Features.push_back("-d");
+  Features.push_back("-lsx");
 }
   } else if (const Arg *A = Args.getLastArg(options::OPT_mfpu_EQ)) {
 StringRef FPU = A->getValue();
@@ -157,9 +164,11 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
 } else if (FPU == "32") {
   Features.push_back("+f");
   Features.push_back("-d");
+  Features.push_back("-lsx");
 } else if (FPU == "0" || FPU == "none") {
   Features.push_back("-f");
   Features.push_back("-d");
+  Features.push_back("-lsx");
 } else {
   D.Diag(diag::err_drv_loongarch_invalid_mfpu_EQ) << FPU;
 }
@@ -174,6 +183,42 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
 A->ignoreTargetSpecific();
   if (Arg *A = Args.getLastArgNoClaim(options::OPT_mfpu_EQ))
 A->ignoreTargetSpecific();
+  if (Arg *A = Args.getLastArgNoClaim(options::OPT_msimd_EQ))
+A->ignoreTargetSpecific();
+
+  // Select lsx/lasx feature determined by -msimd=.
+  // Option -msimd= precedes -m[no-]lsx and -m[no-]lasx.
+  if (const Arg *A = Args.getLastArg(options::OPT_msimd_EQ)) {
+StringRef MSIMD = A->getValue();
+if (MSIMD == "lsx") {
+  // Option -msimd=lsx depends on 64-bit FPU.
+  // -m*-float and -mfpu=none/0/32 conflict with -msimd=lsx.
+  if (llvm::find(Features, "-d") != Features.end())
+D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LSX*/ 0;
+  else
+Features.push_back("+lsx");
+} else if (MSIMD == "lasx") {
+  // Option -msimd=lasx depends on 64-bit FPU and LSX.
+  // -m*-float, -mfpu=none/0/32 and -mno-lsx conflict with -msimd=lasx.
+  if (llvm::find(Features, "-d") != Features.end())
+D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LASX*/ 1;
+  else if (llvm::find(Features, "-lsx") != Features.end())
+D.Diag(diag::err_drv_loongarch_invalid_simd_option_combination);
+
+  // The command options do not contain -mno-lasx.
+  if (!Args.getLastArg(options::OPT_mno_lasx)) {
+Features.push_back("+lsx");
+Features.push_back("+lasx");
+  }
+} else if (MSIMD == "none") {
+  if (llvm::find(Features, "+lsx") != Features.end())
+Features.push_back("-lsx");
+  if (llvm::find(Features, "+lasx") != Features.end())
+Features.push_back("-lasx");
+} else {
+  D.Diag(diag::err_drv_loongarch_invalid_msimd_EQ) << MSIMD;
+}
+  }
 
   // Select lsx feature determined by -m[no-]lsx.
   if (const Arg *A = Args.getLastArg(options::OPT_mlsx, options::OPT_mno_lsx)) 
{
@@ -197,8 +242,6 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
 if (A->getOption().matches(options::OPT_mlasx)) {
   if (llvm::find(Features, "-d") != Features.end())
 D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LASX*/ 1;
-  else if (llvm::find(Features, "-lsx") != Features.end())
-D.Diag(diag::err_drv_loongarch_invalid_simd_option_combination);
   else { /*-mlasx*/
 Feature

[clang] [Driver] Clean up fp-contract handling in clang driver (PR #99723)

2024-07-22 Thread Fangrui Song via cfe-commits


@@ -81,6 +81,20 @@
 // RUN:   | FileCheck --check-prefix=WARN13 %s
 // WARN13: warning: overriding '-ffp-model=strict' option with '-fapprox-func' 
[-Woverriding-option]
 
+// RUN: %clang -### -ffp-model=precise -ffp-contract=off -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=WARN14 %s
+// WARN14: warning: overriding '-ffp-model=precise' option with 
'-ffp-contract=off' [-Woverriding-option]
+
+// RUN: %clang -### -ffp-model=precise -ffp-contract=fast -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=WARN15 %s
+// WARN15: warning: overriding '-ffp-model=precise' option with 
'-ffp-contract=fast' [-Woverriding-option]
+
+// RUN: %clang -### -ffp-model=strict -fassociative-math -ffp-contract=on \
+// RUN:   -c %s 2>&1 | FileCheck --check-prefix=WARN16 %s
+// WARN16: warning: overriding '-ffp-model=strict' option with 
'-fassociative-math' [-Woverriding-option]
+// WARN16: warning: overriding '-ffp-model=strict' option with 
'-ffp-contract=on' [-Woverriding-option]
+
+

MaskRay wrote:

unneeded blank line

https://github.com/llvm/llvm-project/pull/99723
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Clean up fp-contract handling in clang driver (PR #99723)

2024-07-22 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay approved this pull request.

The logic is complex and difficult to follow, but the test updates looks good!

https://github.com/llvm/llvm-project/pull/99723
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [LoongArch] Enable 128-bits vector by default (PR #100056)

2024-07-22 Thread via cfe-commits

https://github.com/Ami-zhang updated 
https://github.com/llvm/llvm-project/pull/100056

>From ff41190a23df6014511d0183e409e9f5b54cf287 Mon Sep 17 00:00:00 2001
From: Ami-zhang 
Date: Thu, 18 Jul 2024 09:33:35 +0800
Subject: [PATCH] [LoongArch] Enable 128-bits vector by default

This commit is to enable 128 vector feature by default, in
order to be consistent with gcc.
---
 .../lib/Driver/ToolChains/Arch/LoongArch.cpp  | 76 +++
 clang/test/Driver/loongarch-features.c|  2 +-
 clang/test/Driver/loongarch-mlasx.c   |  6 +-
 clang/test/Driver/loongarch-msimd.c   |  4 +-
 clang/test/Driver/loongarch-msingle-float.c   |  4 +-
 clang/test/Driver/loongarch-msoft-float.c |  4 +-
 clang/test/Preprocessor/init-loongarch.c  |  8 +-
 7 files changed, 60 insertions(+), 44 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp 
b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
index 4a2b9efc9ffad..562aa2499e5e4 100644
--- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -127,6 +127,11 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
const llvm::Triple &Triple,
const ArgList &Args,
std::vector &Features) {
+  // Enable the `lsx` feature on 64-bit LoongArch by default.
+  if (Triple.isLoongArch64() &&
+  (!Args.hasArgNoClaim(clang::driver::options::OPT_march_EQ)))
+Features.push_back("+lsx");
+
   std::string ArchName;
   if (const Arg *A = Args.getLastArg(options::OPT_march_EQ))
 ArchName = A->getValue();
@@ -145,9 +150,11 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
 } else if (A->getOption().matches(options::OPT_msingle_float)) {
   Features.push_back("+f");
   Features.push_back("-d");
+  Features.push_back("-lsx");
 } else /*Soft-float*/ {
   Features.push_back("-f");
   Features.push_back("-d");
+  Features.push_back("-lsx");
 }
   } else if (const Arg *A = Args.getLastArg(options::OPT_mfpu_EQ)) {
 StringRef FPU = A->getValue();
@@ -157,9 +164,11 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
 } else if (FPU == "32") {
   Features.push_back("+f");
   Features.push_back("-d");
+  Features.push_back("-lsx");
 } else if (FPU == "0" || FPU == "none") {
   Features.push_back("-f");
   Features.push_back("-d");
+  Features.push_back("-lsx");
 } else {
   D.Diag(diag::err_drv_loongarch_invalid_mfpu_EQ) << FPU;
 }
@@ -174,6 +183,42 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
 A->ignoreTargetSpecific();
   if (Arg *A = Args.getLastArgNoClaim(options::OPT_mfpu_EQ))
 A->ignoreTargetSpecific();
+  if (Arg *A = Args.getLastArgNoClaim(options::OPT_msimd_EQ))
+A->ignoreTargetSpecific();
+
+  // Select lsx/lasx feature determined by -msimd=.
+  // Option -msimd= precedes -m[no-]lsx and -m[no-]lasx.
+  if (const Arg *A = Args.getLastArg(options::OPT_msimd_EQ)) {
+StringRef MSIMD = A->getValue();
+if (MSIMD == "lsx") {
+  // Option -msimd=lsx depends on 64-bit FPU.
+  // -m*-float and -mfpu=none/0/32 conflict with -msimd=lsx.
+  if (llvm::find(Features, "-d") != Features.end())
+D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LSX*/ 0;
+  else
+Features.push_back("+lsx");
+} else if (MSIMD == "lasx") {
+  // Option -msimd=lasx depends on 64-bit FPU and LSX.
+  // -m*-float, -mfpu=none/0/32 and -mno-lsx conflict with -msimd=lasx.
+  if (llvm::find(Features, "-d") != Features.end())
+D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LASX*/ 1;
+  else if (llvm::find(Features, "-lsx") != Features.end())
+D.Diag(diag::err_drv_loongarch_invalid_simd_option_combination);
+
+  // The command options do not contain -mno-lasx.
+  if (!Args.getLastArg(options::OPT_mno_lasx)) {
+Features.push_back("+lsx");
+Features.push_back("+lasx");
+  }
+} else if (MSIMD == "none") {
+  if (llvm::find(Features, "+lsx") != Features.end())
+Features.push_back("-lsx");
+  if (llvm::find(Features, "+lasx") != Features.end())
+Features.push_back("-lasx");
+} else {
+  D.Diag(diag::err_drv_loongarch_invalid_msimd_EQ) << MSIMD;
+}
+  }
 
   // Select lsx feature determined by -m[no-]lsx.
   if (const Arg *A = Args.getLastArg(options::OPT_mlsx, options::OPT_mno_lsx)) 
{
@@ -197,8 +242,6 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
 if (A->getOption().matches(options::OPT_mlasx)) {
   if (llvm::find(Features, "-d") != Features.end())
 D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LASX*/ 1;
-  else if (llvm::find(Features, "-lsx") != Features.end())
-D.Diag(diag::err_drv_loongarch_invalid_simd_option_combination);
   else { /*-mlasx*/
 

[clang] ee07547 - [NFC] make the case only require frontend

2024-07-22 Thread Chen Zheng via cfe-commits

Author: Chen Zheng
Date: 2024-07-23T01:53:21-04:00
New Revision: ee07547487a3502f7436968bbfc243b054c14071

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

LOG: [NFC] make the case only require frontend

Fixes buildbot failure like: 
https://lab.llvm.org/buildbot/#/builders/144/builds/2931
  caused by https://github.com/llvm/llvm-project/pull/99888

Added: 


Modified: 
clang/test/Preprocessor/pragma_mc_func.c

Removed: 




diff  --git a/clang/test/Preprocessor/pragma_mc_func.c 
b/clang/test/Preprocessor/pragma_mc_func.c
index e5f362f10e41a..506ba05e02843 100644
--- a/clang/test/Preprocessor/pragma_mc_func.c
+++ b/clang/test/Preprocessor/pragma_mc_func.c
@@ -1,4 +1,4 @@
-// RUN: not %clang --target=powerpc64-ibm-aix -ferr-pragma-mc-func-aix -c -S \
+// RUN: not %clang --target=powerpc64-ibm-aix -ferr-pragma-mc-func-aix 
-fsyntax-only \
 // RUN:   %s 2>&1 | FileCheck %s
 #pragma mc_func asm_barrier {"6000"}
 



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


[clang] [AIX] Detect `#pragma mc_func` (PR #99888)

2024-07-22 Thread Chen Zheng via cfe-commits

chenzheng1030 wrote:

ee07547487a3502f7436968bbfc243b054c14071 should be able to fix the `No 
available targets are compatible with triple "powerpc64-ibm-aix"` error.

https://github.com/llvm/llvm-project/pull/99888
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add _MM_FROUND_TO_NEAREST_TIES_EVEN to avx512fintrin.h (PR #99691)

2024-07-22 Thread Craig Topper via cfe-commits

topperc wrote:

I happened to find this document from Intel 
https://www.intel.com/content/www/us/en/content-details/669773/intel-avx-512-fp16-instruction-set-for-intel-xeon-processor-based-products-technology-guide.html
 that contains this text

"The C intrinsic constant selector name _MM_FROUND_TO_NEAREST_INT is not ideal, 
but that name has been historically used for so long in all common compilers 
that it is difficult to change to something more meaningful."

https://github.com/llvm/llvm-project/pull/99691
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][test] Add function type discrimination tests to static destructor tests (PR #99604)

2024-07-22 Thread Oliver Hunt via cfe-commits

https://github.com/ojhunt updated 
https://github.com/llvm/llvm-project/pull/99604

>From 640779f0327c3b3773ff055923c59a82ae6c7f30 Mon Sep 17 00:00:00 2001
From: Oliver Hunt 
Date: Thu, 18 Jul 2024 21:08:12 -0700
Subject: [PATCH 1/2] [clang][test] Add function type discrimination tests to
 ptrauth-static-destructors

I accidentally did not include tests for the setting up runtime calls
when compiling with -fptrauth-function-pointer-type-discrimination
---
 clang/test/CodeGenCXX/ptrauth-static-destructors.cpp | 12 
 1 file changed, 12 insertions(+)

diff --git a/clang/test/CodeGenCXX/ptrauth-static-destructors.cpp 
b/clang/test/CodeGenCXX/ptrauth-static-destructors.cpp
index cad43dc0746df..92daf6bbea8b7 100644
--- a/clang/test/CodeGenCXX/ptrauth-static-destructors.cpp
+++ b/clang/test/CodeGenCXX/ptrauth-static-destructors.cpp
@@ -5,6 +5,13 @@
 // RUN:-fno-use-cxa-atexit \
 // RUN:  | FileCheck %s --check-prefix=ATEXIT
 
+// RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-calls -emit-llvm 
-std=c++11 %s \
+// RUN:  -fptrauth-function-pointer-type-discrimination  -o - | FileCheck %s 
--check-prefix=CXAATEXIT_DISC
+
+// RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-calls -emit-llvm 
-std=c++11 %s -o - \
+// RUN:   -fptrauth-function-pointer-type-discrimination  -fno-use-cxa-atexit \
+// RUN:  | FileCheck %s --check-prefix=ATEXIT_DISC
+
 class Foo {
  public:
   ~Foo() {
@@ -16,9 +23,14 @@ Foo global;
 // CXAATEXIT: define internal void @__cxx_global_var_init()
 // CXAATEXIT:   call i32 @__cxa_atexit(ptr ptrauth (ptr @_ZN3FooD1Ev, i32 0), 
ptr @global, ptr @__dso_handle)
 
+// CXAATEXIT_DISC: define internal void @__cxx_global_var_init()
+// CXAATEXIT_DISC:   call i32 @__cxa_atexit(ptr ptrauth (ptr @_ZN3FooD1Ev, i32 
0, i64 10942), ptr @global, ptr @__dso_handle)
 
 // ATEXIT: define internal void @__cxx_global_var_init()
 // ATEXIT:   %{{.*}} = call i32 @atexit(ptr ptrauth (ptr @__dtor_global, i32 
0))
 
 // ATEXIT: define internal void @__dtor_global() {{.*}} section 
"__TEXT,__StaticInit,regular,pure_instructions" {
 // ATEXIT:   %{{.*}} = call ptr @_ZN3FooD1Ev(ptr @global)
+
+// ATEXIT_DISC: define internal void @__cxx_global_var_init()
+// ATEXIT_DISC:   %{{.*}} = call i32 @atexit(ptr ptrauth (ptr @__dtor_global, 
i32 0, i64 10942))

>From 890a3183ed32fd5f5629368d9249b108d97adfee Mon Sep 17 00:00:00 2001
From: Oliver Hunt 
Date: Mon, 22 Jul 2024 22:58:58 -0700
Subject: [PATCH 2/2] Update for trunk, include elf tests

---
 .../CodeGenCXX/ptrauth-static-destructors.cpp | 30 ---
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/clang/test/CodeGenCXX/ptrauth-static-destructors.cpp 
b/clang/test/CodeGenCXX/ptrauth-static-destructors.cpp
index 4b5eef55d38b1..634450bf62ea9 100644
--- a/clang/test/CodeGenCXX/ptrauth-static-destructors.cpp
+++ b/clang/test/CodeGenCXX/ptrauth-static-destructors.cpp
@@ -2,20 +2,27 @@
 // RUN:  | FileCheck %s --check-prefix=CXAATEXIT
 
 // RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-calls -emit-llvm 
-std=c++11 %s -o - \
-// RUN:-fno-use-cxa-atexit | FileCheck %s --check-prefixes=ATEXIT,DARWIN
+// RUN:-fno-use-cxa-atexit | FileCheck %s 
--check-prefixes=ATEXIT,ATEXIT_DARWIN
 
 // RUN: %clang_cc1 -triple aarch64-linux-gnu -fptrauth-calls -emit-llvm 
-std=c++11 %s -o - \
 // RUN:  | FileCheck %s --check-prefix=CXAATEXIT
 
 // RUN: %clang_cc1 -triple aarch64-linux-gnu -fptrauth-calls -emit-llvm 
-std=c++11 %s -o - \
-// RUN:-fno-use-cxa-atexit | FileCheck %s --check-prefixes=ATEXIT,ELF
+// RUN:-fno-use-cxa-atexit | FileCheck %s 
--check-prefixes=ATEXIT,ATEXIT_ELF
 
 // RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-calls -emit-llvm 
-std=c++11 %s \
 // RUN:  -fptrauth-function-pointer-type-discrimination  -o - | FileCheck %s 
--check-prefix=CXAATEXIT_DISC
 
 // RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-calls -emit-llvm 
-std=c++11 %s -o - \
 // RUN:   -fptrauth-function-pointer-type-discrimination  -fno-use-cxa-atexit \
-// RUN:  | FileCheck %s --check-prefix=ATEXIT_DISC
+// RUN:  | FileCheck %s --check-prefixes=ATEXIT_DISC,ATEXIT_DISC_DARWIN
+
+// RUN: %clang_cc1 -triple aarch64-linux-gnu -fptrauth-calls -emit-llvm 
-std=c++11 %s \
+// RUN:  -fptrauth-function-pointer-type-discrimination  -o - | FileCheck %s 
--check-prefix=CXAATEXIT_DISC
+
+// RUN: %clang_cc1 -triple aarch64-linux-gnu -fptrauth-calls -emit-llvm 
-std=c++11 %s -o - \
+// RUN:   -fptrauth-function-pointer-type-discrimination -fno-use-cxa-atexit \
+// RUN:  | FileCheck %s --check-prefixes=ATEXIT_DISC,ATEXIT_DISC_ELF
 
 class Foo {
  public:
@@ -34,13 +41,16 @@ Foo global;
 // ATEXIT: define internal void @__cxx_global_var_init()
 // ATEXIT:   %{{.*}} = call i32 @atexit(ptr ptrauth (ptr @__dtor_global, i32 
0))
 
-// DARWIN: define internal void @__dtor_global() {{.*}} section 
"__TEXT,__StaticInit,regular,pure_instructions" {
-// ELF:define internal void @__dtor_global() {{.*}} section 
".text.startup" {
-// DARWIN:   %{{.*}} = call

[clang] b830790 - [NFC] changes all run lines

2024-07-22 Thread Chen Zheng via cfe-commits

Author: Chen Zheng
Date: 2024-07-23T02:00:28-04:00
New Revision: b830790547c304aa2a771ce0706b337ea5ec7a02

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

LOG: [NFC] changes all run lines

Fix https://github.com/llvm/llvm-project/pull/99888

Added: 


Modified: 
clang/test/Preprocessor/pragma_mc_func.c

Removed: 




diff  --git a/clang/test/Preprocessor/pragma_mc_func.c 
b/clang/test/Preprocessor/pragma_mc_func.c
index 506ba05e02843..f0d3e49e5dddc 100644
--- a/clang/test/Preprocessor/pragma_mc_func.c
+++ b/clang/test/Preprocessor/pragma_mc_func.c
@@ -5,19 +5,19 @@
 // CHECK:  error: #pragma mc_func is not supported
 
 // Cases where no errors occur.
-// RUN: %clang --target=powerpc64-ibm-aix -fno-err-pragma-mc-func-aix -c -S %s
-// RUN: %clang --target=powerpc64-ibm-aix -ferr-pragma-mc-func-aix -c -S \
+// RUN: %clang --target=powerpc64-ibm-aix -fno-err-pragma-mc-func-aix 
-fsyntax-only %s
+// RUN: %clang --target=powerpc64-ibm-aix -ferr-pragma-mc-func-aix 
-fsyntax-only \
 // RUN:-fno-err-pragma-mc-func-aix %s
-// RUN: %clang --target=powerpc64-ibm-aix -c -S %s
+// RUN: %clang --target=powerpc64-ibm-aix -fsyntax-only %s
 // RUN: %clang --target=powerpc64-ibm-aix -Werror=unknown-pragmas \
-// RUN:   -fno-err-pragma-mc-func-aix -c -S %s
+// RUN:   -fno-err-pragma-mc-func-aix -fsyntax-only %s
 
 // Cases where we have errors or warnings.
 // RUN: not %clang --target=powerpc64le-unknown-linux-gnu \
-// RUN:   -Werror=unknown-pragmas -fno-err-pragma-mc-func-aix -c -S %s 2>&1 | \
+// RUN:   -Werror=unknown-pragmas -fno-err-pragma-mc-func-aix -fsyntax-only %s 
2>&1 | \
 // RUN:   FileCheck --check-prefix=UNUSED %s
 // RUN: %clang --target=powerpc64le-unknown-linux-gnu \
-// RUN:   -fno-err-pragma-mc-func-aix -c -S %s 2>&1 | \
+// RUN:   -fno-err-pragma-mc-func-aix -fsyntax-only %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=UNUSED %s
 
 // UNUSED: clang: warning: argument unused during compilation: 
'-fno-err-pragma-mc-func-aix' [-Wunused-command-line-argument]



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


[clang] b4ef0ba - [LoongArch] Enable 128-bits vector by default (#100056)

2024-07-22 Thread via cfe-commits

Author: Ami-zhang
Date: 2024-07-23T14:02:04+08:00
New Revision: b4ef0ba244899a64a1b1e6448eca942cfa5eda18

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

LOG: [LoongArch] Enable 128-bits vector by default (#100056)

This commit is to enable 128 vector feature by default, in order to be
consistent with gcc.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
clang/test/Driver/loongarch-features.c
clang/test/Driver/loongarch-mlasx.c
clang/test/Driver/loongarch-msimd.c
clang/test/Driver/loongarch-msingle-float.c
clang/test/Driver/loongarch-msoft-float.c
clang/test/Preprocessor/init-loongarch.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp 
b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
index 4a2b9efc9ffad..562aa2499e5e4 100644
--- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -127,6 +127,11 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
const llvm::Triple &Triple,
const ArgList &Args,
std::vector &Features) {
+  // Enable the `lsx` feature on 64-bit LoongArch by default.
+  if (Triple.isLoongArch64() &&
+  (!Args.hasArgNoClaim(clang::driver::options::OPT_march_EQ)))
+Features.push_back("+lsx");
+
   std::string ArchName;
   if (const Arg *A = Args.getLastArg(options::OPT_march_EQ))
 ArchName = A->getValue();
@@ -145,9 +150,11 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
 } else if (A->getOption().matches(options::OPT_msingle_float)) {
   Features.push_back("+f");
   Features.push_back("-d");
+  Features.push_back("-lsx");
 } else /*Soft-float*/ {
   Features.push_back("-f");
   Features.push_back("-d");
+  Features.push_back("-lsx");
 }
   } else if (const Arg *A = Args.getLastArg(options::OPT_mfpu_EQ)) {
 StringRef FPU = A->getValue();
@@ -157,9 +164,11 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
 } else if (FPU == "32") {
   Features.push_back("+f");
   Features.push_back("-d");
+  Features.push_back("-lsx");
 } else if (FPU == "0" || FPU == "none") {
   Features.push_back("-f");
   Features.push_back("-d");
+  Features.push_back("-lsx");
 } else {
   D.Diag(diag::err_drv_loongarch_invalid_mfpu_EQ) << FPU;
 }
@@ -174,6 +183,42 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
 A->ignoreTargetSpecific();
   if (Arg *A = Args.getLastArgNoClaim(options::OPT_mfpu_EQ))
 A->ignoreTargetSpecific();
+  if (Arg *A = Args.getLastArgNoClaim(options::OPT_msimd_EQ))
+A->ignoreTargetSpecific();
+
+  // Select lsx/lasx feature determined by -msimd=.
+  // Option -msimd= precedes -m[no-]lsx and -m[no-]lasx.
+  if (const Arg *A = Args.getLastArg(options::OPT_msimd_EQ)) {
+StringRef MSIMD = A->getValue();
+if (MSIMD == "lsx") {
+  // Option -msimd=lsx depends on 64-bit FPU.
+  // -m*-float and -mfpu=none/0/32 conflict with -msimd=lsx.
+  if (llvm::find(Features, "-d") != Features.end())
+D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LSX*/ 0;
+  else
+Features.push_back("+lsx");
+} else if (MSIMD == "lasx") {
+  // Option -msimd=lasx depends on 64-bit FPU and LSX.
+  // -m*-float, -mfpu=none/0/32 and -mno-lsx conflict with -msimd=lasx.
+  if (llvm::find(Features, "-d") != Features.end())
+D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LASX*/ 1;
+  else if (llvm::find(Features, "-lsx") != Features.end())
+D.Diag(diag::err_drv_loongarch_invalid_simd_option_combination);
+
+  // The command options do not contain -mno-lasx.
+  if (!Args.getLastArg(options::OPT_mno_lasx)) {
+Features.push_back("+lsx");
+Features.push_back("+lasx");
+  }
+} else if (MSIMD == "none") {
+  if (llvm::find(Features, "+lsx") != Features.end())
+Features.push_back("-lsx");
+  if (llvm::find(Features, "+lasx") != Features.end())
+Features.push_back("-lasx");
+} else {
+  D.Diag(diag::err_drv_loongarch_invalid_msimd_EQ) << MSIMD;
+}
+  }
 
   // Select lsx feature determined by -m[no-]lsx.
   if (const Arg *A = Args.getLastArg(options::OPT_mlsx, options::OPT_mno_lsx)) 
{
@@ -197,8 +242,6 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
 if (A->getOption().matches(options::OPT_mlasx)) {
   if (llvm::find(Features, "-d") != Features.end())
 D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LASX*/ 1;
-  else if (llvm::find(Features, "-lsx") != Features.end())
-D.Diag(diag::err_drv_loongarch_invalid_si

[clang] [LoongArch] Enable 128-bits vector by default (PR #100056)

2024-07-22 Thread Lu Weining via cfe-commits

https://github.com/SixWeining closed 
https://github.com/llvm/llvm-project/pull/100056
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [LoongArch] Support -march=la64v1.0 and -march=la64v1.1 (PR #100057)

2024-07-22 Thread Lu Weining via cfe-commits

https://github.com/SixWeining approved this pull request.


https://github.com/llvm/llvm-project/pull/100057
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 5a1b989 - [LoongArch] Support -march=la64v1.0 and -march=la64v1.1 (#100057)

2024-07-22 Thread via cfe-commits

Author: Ami-zhang
Date: 2024-07-23T14:03:28+08:00
New Revision: 5a1b9896ad5a7dcd25a1cc7a4d3fd44155e4b22d

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

LOG: [LoongArch] Support -march=la64v1.0 and -march=la64v1.1 (#100057)

The newly added strings `la64v1.0` and `la64v1.1` in `-march` are as
described in LoongArch toolchains conventions (see [1]).

The target-cpu/feature attributes are forwarded to compiler when
specifying particular `-march` parameter. The default cpu `loongarch64`
is returned when archname is `la64v1.0` or `la64v1.1`.

In addition, this commit adds `la64v1.0`/`la64v1.1` to
"__loongarch_arch" and adds definition for macro "__loongarch_frecipe".

[1]: https://github.com/loongson/la-toolchain-conventions

Added: 


Modified: 
clang/lib/Basic/Targets/LoongArch.cpp
clang/lib/Basic/Targets/LoongArch.h
clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
clang/test/Driver/loongarch-march.c
clang/test/Preprocessor/init-loongarch.c
llvm/lib/TargetParser/LoongArchTargetParser.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/LoongArch.cpp 
b/clang/lib/Basic/Targets/LoongArch.cpp
index 75f71a337b7a4..cb3fd12c48ddb 100644
--- a/clang/lib/Basic/Targets/LoongArch.cpp
+++ b/clang/lib/Basic/Targets/LoongArch.cpp
@@ -200,7 +200,24 @@ void LoongArchTargetInfo::getTargetDefines(const 
LangOptions &Opts,
 
   // Define __loongarch_arch.
   StringRef ArchName = getCPU();
-  Builder.defineMacro("__loongarch_arch", Twine('"') + ArchName + Twine('"'));
+  if (ArchName == "loongarch64") {
+if (HasFeatureLSX) {
+  // TODO: As more features of the V1.1 ISA are supported, a unified "v1.1"
+  // arch feature set will be used to include all sub-features belonging to
+  // the V1.1 ISA version.
+  if (HasFeatureFrecipe)
+Builder.defineMacro("__loongarch_arch",
+Twine('"') + "la64v1.1" + Twine('"'));
+  else
+Builder.defineMacro("__loongarch_arch",
+Twine('"') + "la64v1.0" + Twine('"'));
+} else {
+  Builder.defineMacro("__loongarch_arch",
+  Twine('"') + ArchName + Twine('"'));
+}
+  } else {
+Builder.defineMacro("__loongarch_arch", Twine('"') + ArchName + 
Twine('"'));
+  }
 
   // Define __loongarch_tune.
   StringRef TuneCPU = getTargetOpts().TuneCPU;
@@ -216,6 +233,8 @@ void LoongArchTargetInfo::getTargetDefines(const 
LangOptions &Opts,
 Builder.defineMacro("__loongarch_simd_width", "128");
 Builder.defineMacro("__loongarch_sx", Twine(1));
   }
+  if (HasFeatureFrecipe)
+Builder.defineMacro("__loongarch_frecipe", Twine(1));
 
   StringRef ABI = getABI();
   if (ABI == "lp64d" || ABI == "lp64f" || ABI == "lp64s")
@@ -291,6 +310,8 @@ bool LoongArchTargetInfo::handleTargetFeatures(
   HasFeatureLASX = true;
 else if (Feature == "-ual")
   HasUnalignedAccess = false;
+else if (Feature == "+frecipe")
+  HasFeatureFrecipe = true;
   }
   return true;
 }

diff  --git a/clang/lib/Basic/Targets/LoongArch.h 
b/clang/lib/Basic/Targets/LoongArch.h
index 5fc223483951e..c668ca7eca047 100644
--- a/clang/lib/Basic/Targets/LoongArch.h
+++ b/clang/lib/Basic/Targets/LoongArch.h
@@ -29,6 +29,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public 
TargetInfo {
   bool HasFeatureF;
   bool HasFeatureLSX;
   bool HasFeatureLASX;
+  bool HasFeatureFrecipe;
 
 public:
   LoongArchTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
@@ -37,6 +38,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public 
TargetInfo {
 HasFeatureF = false;
 HasFeatureLSX = false;
 HasFeatureLASX = false;
+HasFeatureFrecipe = false;
 LongDoubleWidth = 128;
 LongDoubleAlign = 128;
 LongDoubleFormat = &llvm::APFloat::IEEEquad();

diff  --git a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp 
b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
index 562aa2499e5e4..1e8aac71dc9ba 100644
--- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -267,8 +267,14 @@ std::string loongarch::postProcessTargetCPUString(const 
std::string &CPU,
 std::string loongarch::getLoongArchTargetCPU(const llvm::opt::ArgList &Args,
  const llvm::Triple &Triple) {
   std::string CPU;
+  std::string Arch;
   // If we have -march, use that.
-  if (const Arg *A = Args.getLastArg(options::OPT_march_EQ))
-CPU = A->getValue();
+  if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
+Arch = A->getValue();
+if (Arch == "la64v1.0" || Arch == "la64v1.1")
+  CPU = llvm::LoongArch::getDefaultArch(Triple.isLoongArch64());
+else
+  CPU = Arch;
+  }
   return postProcessTargetCPUString(CPU, Triple);
 }

diff  -

[clang] [llvm] [LoongArch] Support -march=la64v1.0 and -march=la64v1.1 (PR #100057)

2024-07-22 Thread Lu Weining via cfe-commits

https://github.com/SixWeining closed 
https://github.com/llvm/llvm-project/pull/100057
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Revert "[clang-tidy] fix misc-const-correctness to work with function-try-blocks" (PR #100069)

2024-07-22 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL created 
https://github.com/llvm/llvm-project/pull/100069

Reverts llvm/llvm-project#99925

>From a96af6c18ea45269c4d2e1fd762a14d763be0358 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Tue, 23 Jul 2024 08:46:14 +0200
Subject: [PATCH] =?UTF-8?q?Revert=20"[clang-tidy]=20fix=20misc-const-corre?=
 =?UTF-8?q?ctness=20to=20work=20with=20function-try-blo=E2=80=A6"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This reverts commit cd9e42cb0f2fdf1834e2e6ad2befdba0d7cc84b5.
---
 .../clang-tidy/misc/ConstCorrectnessCheck.cpp   | 17 +
 .../clang-tidy/misc/ConstCorrectnessCheck.h |  4 ++--
 clang-tools-extra/docs/ReleaseNotes.rst |  3 +--
 .../checkers/misc/const-correctness-values.cpp  |  9 -
 4 files changed, 12 insertions(+), 21 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
index e20cf6fbcb55a..8b500de0c028c 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
@@ -93,12 +93,13 @@ void ConstCorrectnessCheck::registerMatchers(MatchFinder 
*Finder) {
   // shall be run.
   const auto FunctionScope =
   functionDecl(
-  hasBody(stmt(forEachDescendant(
-   declStmt(containsAnyDeclaration(
-LocalValDecl.bind("local-value")),
-unless(has(decompositionDecl(
-   .bind("decl-stmt")))
-  .bind("scope")))
+  hasBody(
+  compoundStmt(forEachDescendant(
+   declStmt(containsAnyDeclaration(
+LocalValDecl.bind("local-value")),
+unless(has(decompositionDecl(
+   .bind("decl-stmt")))
+  .bind("scope")))
   .bind("function-decl");
 
   Finder->addMatcher(FunctionScope, this);
@@ -108,7 +109,7 @@ void ConstCorrectnessCheck::registerMatchers(MatchFinder 
*Finder) {
 enum class VariableCategory { Value, Reference, Pointer };
 
 void ConstCorrectnessCheck::check(const MatchFinder::MatchResult &Result) {
-  const auto *LocalScope = Result.Nodes.getNodeAs("scope");
+  const auto *LocalScope = Result.Nodes.getNodeAs("scope");
   const auto *Variable = Result.Nodes.getNodeAs("local-value");
   const auto *Function = Result.Nodes.getNodeAs("function-decl");
 
@@ -197,7 +198,7 @@ void ConstCorrectnessCheck::check(const 
MatchFinder::MatchResult &Result) {
   }
 }
 
-void ConstCorrectnessCheck::registerScope(const Stmt *LocalScope,
+void ConstCorrectnessCheck::registerScope(const CompoundStmt *LocalScope,
   ASTContext *Context) {
   auto &Analyzer = ScopesCache[LocalScope];
   if (!Analyzer)
diff --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h 
b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h
index bba060e555d00..08ffde524522a 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h
@@ -32,10 +32,10 @@ class ConstCorrectnessCheck : public ClangTidyCheck {
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
 
 private:
-  void registerScope(const Stmt *LocalScope, ASTContext *Context);
+  void registerScope(const CompoundStmt *LocalScope, ASTContext *Context);
 
   using MutationAnalyzer = std::unique_ptr;
-  llvm::DenseMap ScopesCache;
+  llvm::DenseMap ScopesCache;
   llvm::DenseSet TemplateDiagnosticsCache;
 
   const bool AnalyzeValues;
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 083b098d05d4a..0b2c04c23761c 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -381,8 +381,7 @@ Changes in existing checks
 - Improved :doc:`misc-const-correctness
   ` check by avoiding infinite 
recursion
   for recursive functions with forwarding reference parameters and reference
-  variables which refer to themselves. Also adapted the check to work with
-  function-try-blocks.
+  variables which refer to themselves.
 
 - Improved :doc:`misc-definitions-in-headers
   ` check by replacing the local
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
index 2af4bfb0bd449..cb6bfcc1dccba 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
@@ -56,15 +56,6 @@ void some_function(double np_arg0, wchar_t np_arg1) {
   np_local6--;
 }
 
-int function_try_block() try {
-  int p_local0 = 0;
-  // CHECK-MESSAGES:

[clang-tools-extra] f0fad9f - Revert "[clang-tidy] fix misc-const-correctness to work with function-try-blocks" (#100069)

2024-07-22 Thread via cfe-commits

Author: Piotr Zegar
Date: 2024-07-23T08:46:40+02:00
New Revision: f0fad9f3e00dbe8e58024d1c98e36b7b9b1b17a9

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

LOG: Revert "[clang-tidy] fix misc-const-correctness to work with 
function-try-blocks" (#100069)

Reverts llvm/llvm-project#99925

Added: 


Modified: 
clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
index e20cf6fbcb55a..8b500de0c028c 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
@@ -93,12 +93,13 @@ void ConstCorrectnessCheck::registerMatchers(MatchFinder 
*Finder) {
   // shall be run.
   const auto FunctionScope =
   functionDecl(
-  hasBody(stmt(forEachDescendant(
-   declStmt(containsAnyDeclaration(
-LocalValDecl.bind("local-value")),
-unless(has(decompositionDecl(
-   .bind("decl-stmt")))
-  .bind("scope")))
+  hasBody(
+  compoundStmt(forEachDescendant(
+   declStmt(containsAnyDeclaration(
+LocalValDecl.bind("local-value")),
+unless(has(decompositionDecl(
+   .bind("decl-stmt")))
+  .bind("scope")))
   .bind("function-decl");
 
   Finder->addMatcher(FunctionScope, this);
@@ -108,7 +109,7 @@ void ConstCorrectnessCheck::registerMatchers(MatchFinder 
*Finder) {
 enum class VariableCategory { Value, Reference, Pointer };
 
 void ConstCorrectnessCheck::check(const MatchFinder::MatchResult &Result) {
-  const auto *LocalScope = Result.Nodes.getNodeAs("scope");
+  const auto *LocalScope = Result.Nodes.getNodeAs("scope");
   const auto *Variable = Result.Nodes.getNodeAs("local-value");
   const auto *Function = Result.Nodes.getNodeAs("function-decl");
 
@@ -197,7 +198,7 @@ void ConstCorrectnessCheck::check(const 
MatchFinder::MatchResult &Result) {
   }
 }
 
-void ConstCorrectnessCheck::registerScope(const Stmt *LocalScope,
+void ConstCorrectnessCheck::registerScope(const CompoundStmt *LocalScope,
   ASTContext *Context) {
   auto &Analyzer = ScopesCache[LocalScope];
   if (!Analyzer)

diff  --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h 
b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h
index bba060e555d00..08ffde524522a 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h
@@ -32,10 +32,10 @@ class ConstCorrectnessCheck : public ClangTidyCheck {
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
 
 private:
-  void registerScope(const Stmt *LocalScope, ASTContext *Context);
+  void registerScope(const CompoundStmt *LocalScope, ASTContext *Context);
 
   using MutationAnalyzer = std::unique_ptr;
-  llvm::DenseMap ScopesCache;
+  llvm::DenseMap ScopesCache;
   llvm::DenseSet TemplateDiagnosticsCache;
 
   const bool AnalyzeValues;

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 083b098d05d4a..0b2c04c23761c 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -381,8 +381,7 @@ Changes in existing checks
 - Improved :doc:`misc-const-correctness
   ` check by avoiding infinite 
recursion
   for recursive functions with forwarding reference parameters and reference
-  variables which refer to themselves. Also adapted the check to work with
-  function-try-blocks.
+  variables which refer to themselves.
 
 - Improved :doc:`misc-definitions-in-headers
   ` check by replacing the local

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
index 2af4bfb0bd449..cb6bfcc1dccba 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
@@ -56,15 +56,6 @@ void some_function(double np_arg0, wchar_t np_arg1) {
   np_local6--;
 }
 
-int function_try_block() try {
-  int p_local0 = 0;
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' o

[clang-tools-extra] Revert "[clang-tidy] fix misc-const-correctness to work with function-try-blocks" (PR #100069)

2024-07-22 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL closed 
https://github.com/llvm/llvm-project/pull/100069
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Revert "[clang-tidy] fix misc-const-correctness to work with function-try-blocks" (PR #100069)

2024-07-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Piotr Zegar (PiotrZSL)


Changes

Reverts llvm/llvm-project#99925

---
Full diff: https://github.com/llvm/llvm-project/pull/100069.diff


4 Files Affected:

- (modified) clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp (+9-8) 
- (modified) clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h (+2-2) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+1-2) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp 
(-9) 


``diff
diff --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
index e20cf6fbcb55a..8b500de0c028c 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
@@ -93,12 +93,13 @@ void ConstCorrectnessCheck::registerMatchers(MatchFinder 
*Finder) {
   // shall be run.
   const auto FunctionScope =
   functionDecl(
-  hasBody(stmt(forEachDescendant(
-   declStmt(containsAnyDeclaration(
-LocalValDecl.bind("local-value")),
-unless(has(decompositionDecl(
-   .bind("decl-stmt")))
-  .bind("scope")))
+  hasBody(
+  compoundStmt(forEachDescendant(
+   declStmt(containsAnyDeclaration(
+LocalValDecl.bind("local-value")),
+unless(has(decompositionDecl(
+   .bind("decl-stmt")))
+  .bind("scope")))
   .bind("function-decl");
 
   Finder->addMatcher(FunctionScope, this);
@@ -108,7 +109,7 @@ void ConstCorrectnessCheck::registerMatchers(MatchFinder 
*Finder) {
 enum class VariableCategory { Value, Reference, Pointer };
 
 void ConstCorrectnessCheck::check(const MatchFinder::MatchResult &Result) {
-  const auto *LocalScope = Result.Nodes.getNodeAs("scope");
+  const auto *LocalScope = Result.Nodes.getNodeAs("scope");
   const auto *Variable = Result.Nodes.getNodeAs("local-value");
   const auto *Function = Result.Nodes.getNodeAs("function-decl");
 
@@ -197,7 +198,7 @@ void ConstCorrectnessCheck::check(const 
MatchFinder::MatchResult &Result) {
   }
 }
 
-void ConstCorrectnessCheck::registerScope(const Stmt *LocalScope,
+void ConstCorrectnessCheck::registerScope(const CompoundStmt *LocalScope,
   ASTContext *Context) {
   auto &Analyzer = ScopesCache[LocalScope];
   if (!Analyzer)
diff --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h 
b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h
index bba060e555d00..08ffde524522a 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h
@@ -32,10 +32,10 @@ class ConstCorrectnessCheck : public ClangTidyCheck {
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
 
 private:
-  void registerScope(const Stmt *LocalScope, ASTContext *Context);
+  void registerScope(const CompoundStmt *LocalScope, ASTContext *Context);
 
   using MutationAnalyzer = std::unique_ptr;
-  llvm::DenseMap ScopesCache;
+  llvm::DenseMap ScopesCache;
   llvm::DenseSet TemplateDiagnosticsCache;
 
   const bool AnalyzeValues;
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 083b098d05d4a..0b2c04c23761c 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -381,8 +381,7 @@ Changes in existing checks
 - Improved :doc:`misc-const-correctness
   ` check by avoiding infinite 
recursion
   for recursive functions with forwarding reference parameters and reference
-  variables which refer to themselves. Also adapted the check to work with
-  function-try-blocks.
+  variables which refer to themselves.
 
 - Improved :doc:`misc-definitions-in-headers
   ` check by replacing the local
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
index 2af4bfb0bd449..cb6bfcc1dccba 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
@@ -56,15 +56,6 @@ void some_function(double np_arg0, wchar_t np_arg1) {
   np_local6--;
 }
 
-int function_try_block() try {
-  int p_local0 = 0;
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int' 
can be declared 'const'
-  // CHECK-FIXES: int const p_local0
-  return p_local0;
-} catch (...) {
-  return 0;
-}
-
 void nested_scopes() {
   int p_local0 = 2;
   // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int' 
c

[clang-tools-extra] [clang-tidy] fix misc-const-correctness to work with function-try-blocks (PR #99925)

2024-07-22 Thread Piotr Zegar via cfe-commits

PiotrZSL wrote:

Looks like missing -fexceptions

https://github.com/llvm/llvm-project/pull/99925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][CodeGen] Add metadata for load from reference (PR #98746)

2024-07-22 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw edited 
https://github.com/llvm/llvm-project/pull/98746
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [LoongArch] Support la664 (PR #100068)

2024-07-22 Thread Lu Weining via cfe-commits

https://github.com/SixWeining approved this pull request.


https://github.com/llvm/llvm-project/pull/100068
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Improve BlockIndent at ColumnLimit (PR #93140)

2024-07-22 Thread Owen Pan via cfe-commits

owenca wrote:

You can annotate the lambda l_paren:
```
$ git diff FormatToken.h
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index cc45d5a8c5c1..abcedb66b57c 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -102,6 +102,7 @@ namespace format {
   TYPE(JsTypeColon)
\
   TYPE(JsTypeOperator) 
\
   TYPE(JsTypeOptionalQuestion) 
\
+  TYPE(LambdaDefinitionLParen) 
\
   TYPE(LambdaLBrace)   
\
   TYPE(LambdaLSquare)  
\
   TYPE(LeadingJavaAnnotation)  
\
$ git diff TokenAnnotator.cpp
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index fe8a126e2547..fa1489402559 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -62,6 +62,7 @@ static bool canBeObjCSelectorComponent(const FormatToken 
&Tok) {
 
 /// With `Left` being '(', check if we're at either `[...](` or
 /// `[...]<...>(`, where the [ opens a lambda capture list.
+// FIXME: this doesn't cover attributes/constraints before the l_paren.
 static bool isLambdaParameterList(const FormatToken *Left) {
   // Skip <...> if present.
   if (Left->Previous && Left->Previous->is(tok::greater) &&
@@ -365,6 +366,7 @@ private:
   Contexts.back().IsExpression = false;
 } else if (isLambdaParameterList(&OpeningParen)) {
   // This is a parameter list of a lambda expression.
+  OpeningParen.setType(TT_LambdaDefinitionLParen);
   Contexts.back().IsExpression = false;
 } else if (OpeningParen.is(TT_RequiresExpressionLParen)) {
   Contexts.back().IsExpression = false;
$ 
```

https://github.com/llvm/llvm-project/pull/93140
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Interp] Diagnose use sizeless vector type as the argument of `__builtin_vectorelements` (PR #99794)

2024-07-22 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr approved this pull request.

LGTM, thanks!

https://github.com/llvm/llvm-project/pull/99794
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Improve BlockIndent at ColumnLimit (PR #93140)

2024-07-22 Thread Owen Pan via cfe-commits


@@ -803,6 +803,51 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
&State, bool DryRun,
 return !Tok.Previous->isOneOf(TT_CastRParen, tok::kw_for, tok::kw_while,
   tok::kw_switch);
   };
+  auto IsLambdaParameterList = [](const FormatToken *Tok) {
+// adapted from TokenAnnotator.cpp:isLambdaParameterList()
+// Skip <...> if present.
+if (Tok->Previous && Tok->Previous->is(tok::greater) &&
+Tok->Previous->MatchingParen &&
+Tok->Previous->MatchingParen->is(TT_TemplateOpener)) {
+  Tok = Tok->Previous->MatchingParen;
+}
+
+// Check for `[...]`.
+return Tok->Previous && Tok->Previous->is(tok::r_square) &&
+   Tok->Previous->MatchingParen &&
+   Tok->Previous->MatchingParen->is(TT_LambdaLSquare);
+  };

owenca wrote:

Delete.

https://github.com/llvm/llvm-project/pull/93140
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Improve BlockIndent at ColumnLimit (PR #93140)

2024-07-22 Thread Owen Pan via cfe-commits


@@ -813,10 +858,10 @@ void 
ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
   //   cll(
   //   cll(
   //   caaall(aa, 
a;
-  Current.FakeLParens.size() > 0 &&
-  Current.FakeLParens.back() > prec::Unknown) {
+  IsNotSimpleFunction(Current)) {

owenca wrote:

```suggestion
  !IsSimpleFunctionCall(Current)) {
```

https://github.com/llvm/llvm-project/pull/93140
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Improve BlockIndent at ColumnLimit (PR #93140)

2024-07-22 Thread Owen Pan via cfe-commits


@@ -803,6 +803,51 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
&State, bool DryRun,
 return !Tok.Previous->isOneOf(TT_CastRParen, tok::kw_for, tok::kw_while,
   tok::kw_switch);
   };
+  auto IsLambdaParameterList = [](const FormatToken *Tok) {
+// adapted from TokenAnnotator.cpp:isLambdaParameterList()
+// Skip <...> if present.
+if (Tok->Previous && Tok->Previous->is(tok::greater) &&
+Tok->Previous->MatchingParen &&
+Tok->Previous->MatchingParen->is(TT_TemplateOpener)) {
+  Tok = Tok->Previous->MatchingParen;
+}
+
+// Check for `[...]`.
+return Tok->Previous && Tok->Previous->is(tok::r_square) &&
+   Tok->Previous->MatchingParen &&
+   Tok->Previous->MatchingParen->is(TT_LambdaLSquare);
+  };
+  auto IsFunctionCallParen = [&](const FormatToken &Tok) {

owenca wrote:

You don't need to capture anything.

https://github.com/llvm/llvm-project/pull/93140
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Improve BlockIndent at ColumnLimit (PR #93140)

2024-07-22 Thread Owen Pan via cfe-commits


@@ -803,6 +803,51 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
&State, bool DryRun,
 return !Tok.Previous->isOneOf(TT_CastRParen, tok::kw_for, tok::kw_while,
   tok::kw_switch);
   };
+  auto IsLambdaParameterList = [](const FormatToken *Tok) {
+// adapted from TokenAnnotator.cpp:isLambdaParameterList()
+// Skip <...> if present.
+if (Tok->Previous && Tok->Previous->is(tok::greater) &&
+Tok->Previous->MatchingParen &&
+Tok->Previous->MatchingParen->is(TT_TemplateOpener)) {
+  Tok = Tok->Previous->MatchingParen;
+}
+
+// Check for `[...]`.
+return Tok->Previous && Tok->Previous->is(tok::r_square) &&
+   Tok->Previous->MatchingParen &&
+   Tok->Previous->MatchingParen->is(TT_LambdaLSquare);
+  };
+  auto IsFunctionCallParen = [&](const FormatToken &Tok) {
+return Tok.is(tok::l_paren) && Tok.ParameterCount > 0 && Tok.Previous &&
+   Tok.Previous->is(tok::identifier);
+  };
+  const auto IsInTemplateString = [&](const FormatToken &Tok) {
+if (!Style.isJavaScript())
+  return false;
+for (const FormatToken *Prev = &Tok; Prev; Prev = Prev->Previous) {

owenca wrote:

```suggestion
for (const auto *Prev = &Tok; Prev; Prev = Prev->Previous) {
```

https://github.com/llvm/llvm-project/pull/93140
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Improve BlockIndent at ColumnLimit (PR #93140)

2024-07-22 Thread Owen Pan via cfe-commits


@@ -803,6 +803,51 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
&State, bool DryRun,
 return !Tok.Previous->isOneOf(TT_CastRParen, tok::kw_for, tok::kw_while,
   tok::kw_switch);
   };
+  auto IsLambdaParameterList = [](const FormatToken *Tok) {
+// adapted from TokenAnnotator.cpp:isLambdaParameterList()
+// Skip <...> if present.
+if (Tok->Previous && Tok->Previous->is(tok::greater) &&
+Tok->Previous->MatchingParen &&
+Tok->Previous->MatchingParen->is(TT_TemplateOpener)) {
+  Tok = Tok->Previous->MatchingParen;
+}
+
+// Check for `[...]`.
+return Tok->Previous && Tok->Previous->is(tok::r_square) &&
+   Tok->Previous->MatchingParen &&
+   Tok->Previous->MatchingParen->is(TT_LambdaLSquare);
+  };
+  auto IsFunctionCallParen = [&](const FormatToken &Tok) {
+return Tok.is(tok::l_paren) && Tok.ParameterCount > 0 && Tok.Previous &&
+   Tok.Previous->is(tok::identifier);
+  };
+  const auto IsInTemplateString = [&](const FormatToken &Tok) {
+if (!Style.isJavaScript())
+  return false;
+for (const FormatToken *Prev = &Tok; Prev; Prev = Prev->Previous) {
+  if (Prev->is(TT_TemplateString) && Prev->opensScope())
+return true;
+  if (Prev->is(TT_TemplateString) && Prev->closesScope())
+break;
+}
+return false;
+  };
+  // Identifies simple (no expression) one-argument function calls.
+  const auto IsNotSimpleFunction = [&](const FormatToken &Tok) {
+const auto *Previous = Tok.Previous;
+const auto *Next = Tok.Next;
+if (Tok.FakeLParens.size() > 0 && Tok.FakeLParens.back() > prec::Unknown)
+  return true;
+if (Previous &&
+(Previous->is(TT_FunctionDeclarationLParen) ||
+ IsFunctionCallParen(*Previous) || IsLambdaParameterList(Previous))) {
+  return !IsOpeningBracket(Tok) && Next && !Next->isMemberAccess() &&
+ !IsInTemplateString(Tok) &&
+ !Next->is(TT_FunctionDeclarationLParen) &&
+ !IsFunctionCallParen(*Next);
+}
+return false;
+  };

owenca wrote:

I'd drop the `Not` and rewrite it as something like below:
```
   // Identifies simple (no expression) one-argument function calls.
-  const auto IsNotSimpleFunction = [&](const FormatToken &Tok) {
+  const auto IsSimpleFunctionCall = [&](const FormatToken &Tok) {
+if (!Tok.FakeLParens.empty() && Tok.FakeLParens.back() > prec::Unknown)
+  return false;
 const auto *Previous = Tok.Previous;
-const auto *Next = Tok.Next;
-if (Tok.FakeLParens.size() > 0 && Tok.FakeLParens.back() > prec::Unknown)
+if (!Previous || (!Previous->isOneOf(TT_FunctionDeclarationLParen,
+ TT_LambdaDefinitionLParen) &&
+  !IsFunctionCallParen(*Previous))) {
   return true;
-if (Previous &&
-(Previous->is(TT_FunctionDeclarationLParen) ||
- IsFunctionCallParen(*Previous) || IsLambdaParameterList(Previous))) {
-  return !IsOpeningBracket(Tok) && Next && !Next->isMemberAccess() &&
- !IsInTemplateString(Tok) &&
- !Next->is(TT_FunctionDeclarationLParen) &&
- !IsFunctionCallParen(*Next);
 }
-return false;
+if (IsOpeningBracket(Tok) || IsInTemplateString(Tok))
+  return true;
+const auto *Next = Tok.Next;
+return !Next || Next->isMemberAccess() ||
+   Next->is(TT_FunctionDeclarationLParen) || 
IsFunctionCallParen(*Next);
   };
```

https://github.com/llvm/llvm-project/pull/93140
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Improve BlockIndent at ColumnLimit (PR #93140)

2024-07-22 Thread Owen Pan via cfe-commits


@@ -803,6 +803,51 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
&State, bool DryRun,
 return !Tok.Previous->isOneOf(TT_CastRParen, tok::kw_for, tok::kw_while,
   tok::kw_switch);
   };
+  auto IsLambdaParameterList = [](const FormatToken *Tok) {
+// adapted from TokenAnnotator.cpp:isLambdaParameterList()
+// Skip <...> if present.
+if (Tok->Previous && Tok->Previous->is(tok::greater) &&
+Tok->Previous->MatchingParen &&
+Tok->Previous->MatchingParen->is(TT_TemplateOpener)) {
+  Tok = Tok->Previous->MatchingParen;
+}
+
+// Check for `[...]`.
+return Tok->Previous && Tok->Previous->is(tok::r_square) &&
+   Tok->Previous->MatchingParen &&
+   Tok->Previous->MatchingParen->is(TT_LambdaLSquare);
+  };
+  auto IsFunctionCallParen = [&](const FormatToken &Tok) {
+return Tok.is(tok::l_paren) && Tok.ParameterCount > 0 && Tok.Previous &&
+   Tok.Previous->is(tok::identifier);
+  };
+  const auto IsInTemplateString = [&](const FormatToken &Tok) {

owenca wrote:

You only need to capture `this`.

https://github.com/llvm/llvm-project/pull/93140
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][test] Add function type discrimination tests to static destructor tests (PR #99604)

2024-07-22 Thread Anton Korobeynikov via cfe-commits

asl wrote:

@ojhunt Close or rebase?

https://github.com/llvm/llvm-project/pull/99604
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] [WIP] Added builtin_alloca right Address Space for OpenCL (PR #95750)

2024-07-22 Thread Vikash Gupta via cfe-commits

https://github.com/vg0204 updated 
https://github.com/llvm/llvm-project/pull/95750

>From cbe656fa6db50319e74c0fab166538518506974e Mon Sep 17 00:00:00 2001
From: vg0204 
Date: Mon, 17 Jun 2024 11:20:02 +0530
Subject: [PATCH 1/7] [Clang] [WIP] Added builtin_alloca support for OpenCL1.2
 and below

The __builtin_alloca was returning a flat pointer with no address
space when compiled using openCL1.2 or below but worked fine with
openCL2.0 and above. This accounts to the fact that later uses the
concept of generic address space which supports cast to other address
space(i.e to private address space which is used for stack allocation)
.

So, in  case of openCL1.2 and below __built_alloca is supposed to
return pointer to private address space to eliminate the need of
casting as not supported here. Thus,it requires redefintion of the
builtin function with appropraite return pointer to appropriate
address space.
---
 clang/lib/Sema/SemaExpr.cpp | 23 +-
 clang/test/CodeGenOpenCL/builtins-alloca.cl | 86 +
 clang/test/CodeGenOpenCL/memcpy.cl  |  0
 3 files changed, 106 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGenOpenCL/builtins-alloca.cl
 mode change 100644 => 100755 clang/test/CodeGenOpenCL/memcpy.cl

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 4db8b4130c3c7..bb63020dadb83 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6231,7 +6231,10 @@ bool Sema::CheckArgsForPlaceholders(MultiExprArg args) {
 ///  it does not contain any pointer arguments without
 ///  an address space qualifer.  Otherwise the rewritten
 ///  FunctionDecl is returned.
-/// TODO: Handle pointer return types.
+///
+/// Pointer return type with no explicit address space is assigned the
+/// default address space where pointer points to based on the language
+/// option used to compile it.
 static FunctionDecl *rewriteBuiltinFunctionDecl(Sema *Sema, ASTContext 
&Context,
 FunctionDecl *FDecl,
 MultiExprArg ArgExprs) {
@@ -6275,13 +6278,27 @@ static FunctionDecl *rewriteBuiltinFunctionDecl(Sema 
*Sema, ASTContext &Context,
 OverloadParams.push_back(Context.getPointerType(PointeeType));
   }
 
+  QualType ReturnTy = FT->getReturnType();
+  QualType OverloadReturnTy = ReturnTy;
+  if (ReturnTy->isPointerType() &&
+  !ReturnTy->getPointeeType().hasAddressSpace()) {
+if (Sema->getLangOpts().OpenCL) {
+  NeedsNewDecl = true;
+
+  QualType ReturnPtTy = ReturnTy->getPointeeType();
+  LangAS defClAS = Context.getDefaultOpenCLPointeeAddrSpace();
+  ReturnPtTy = Context.getAddrSpaceQualType(ReturnPtTy, defClAS);
+  OverloadReturnTy = Context.getPointerType(ReturnPtTy);
+}
+  }
+
   if (!NeedsNewDecl)
 return nullptr;
 
   FunctionProtoType::ExtProtoInfo EPI;
   EPI.Variadic = FT->isVariadic();
-  QualType OverloadTy = Context.getFunctionType(FT->getReturnType(),
-OverloadParams, EPI);
+  QualType OverloadTy =
+  Context.getFunctionType(OverloadReturnTy, OverloadParams, EPI);
   DeclContext *Parent = FDecl->getParent();
   FunctionDecl *OverloadDecl = FunctionDecl::Create(
   Context, Parent, FDecl->getLocation(), FDecl->getLocation(),
diff --git a/clang/test/CodeGenOpenCL/builtins-alloca.cl 
b/clang/test/CodeGenOpenCL/builtins-alloca.cl
new file mode 100644
index 0..74a86955f2e4f
--- /dev/null
+++ b/clang/test/CodeGenOpenCL/builtins-alloca.cl
@@ -0,0 +1,86 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL1.2 -emit-llvm 
-o - | FileCheck --check-prefix=OPENCL12 %s
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL2.0 -emit-llvm 
-o - | FileCheck --check-prefix=OPENCL20 %s
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL3.0 -emit-llvm 
-o - | FileCheck --check-prefix=OPENCL30 %s
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL3.0 
-cl-ext=+__opencl_c_generic_address_space -emit-llvm -o - | FileCheck 
--check-prefix=OPENCL30-EXT %s
+
+// OPENCL12-LABEL: define dso_local ptr addrspace(5) @test1(
+// OPENCL12-SAME: ) #[[ATTR0:[0-9]+]] {
+// OPENCL12-NEXT:  [[ENTRY:.*:]]
+// OPENCL12-NEXT:[[ALLOC_PTR:%.*]] = alloca ptr addrspace(5), align 4, 
addrspace(5)
+// OPENCL12-NEXT:[[TMP0:%.*]] = alloca i8, i64 128, align 8, addrspace(5)
+// OPENCL12-NEXT:store ptr addrspace(5) [[TMP0]], ptr addrspace(5) 
[[ALLOC_PTR]], align 4
+// OPENCL12-NEXT:[[TMP1:%.*]] = load ptr addrspace(5), ptr addrspace(5) 
[[ALLOC_PTR]], align 4
+// OPENCL12-NEXT:ret ptr addrspace(5) [[TMP1]]
+//
+// OPENCL20-LABEL: define dso_local ptr @test1(
+// OPENCL20-SAME: ) #[[ATTR0:[0-9]+]] {
+// OPENCL20-NEXT:  [[ENTRY:.*:]]
+// OPENCL20-NEXT:  

[clang] [Clang] [WIP] Added builtin_alloca right Address Space for OpenCL (PR #95750)

2024-07-22 Thread Vikash Gupta via cfe-commits

vg0204 wrote:

@arsenm, updated with needed reviewed changes!

https://github.com/llvm/llvm-project/pull/95750
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][NFCI] Prefer non-canonical template arguments for synthesized CTAD guides (PR #99840)

2024-07-22 Thread Haojian Wu via cfe-commits

https://github.com/hokein commented:

Thanks, the diagnostics in the test look much better.

There is an ambiguous case that I'm a little concerned about: if the alias 
template parameter and the underlying template parameter have the same name, 
the synthesized deduction guide may end up with two template parameters with 
the same name. For instance, see [this 
example](https://godbolt.org/z/q1n7Edzcz). In such cases, we cannot distinguish 
between the `T1` parameters from the function signature `auto (T1, T1) -> X`.

However, the diagnostic improvement looks promising, and this seems like the 
right tradeoff.

https://github.com/llvm/llvm-project/pull/99840
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][NFCI] Prefer non-canonical template arguments for synthesized CTAD guides (PR #99840)

2024-07-22 Thread Haojian Wu via cfe-commits

https://github.com/hokein approved this pull request.


https://github.com/llvm/llvm-project/pull/99840
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Interp] Diagnose use sizeless vector type as the argument of `__builtin_vectorelements` (PR #99794)

2024-07-22 Thread via cfe-commits

https://github.com/yronglin closed 
https://github.com/llvm/llvm-project/pull/99794
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 12762b8 - [Clang][Interp] Diagnose use sizeless vector type as the argument of `__builtin_vectorelements` (#99794)

2024-07-22 Thread via cfe-commits

Author: yronglin
Date: 2024-07-22T15:37:17+08:00
New Revision: 12762b8648d88e6823aedc82f663a596fa2eef76

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

LOG: [Clang][Interp] Diagnose use sizeless vector type as the argument of 
`__builtin_vectorelements` (#99794)

This PR implement an opcode to diagnose use sizeless vector type as the
argument of `__builtin_vectorelements`.

-

Signed-off-by: yronglin 

Added: 


Modified: 
clang/lib/AST/Interp/Compiler.cpp
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/Opcodes.td
clang/test/SemaCXX/builtin_vectorelements.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index ef579bc5d8972..0fc93c14131e6 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -1698,10 +1698,8 @@ bool Compiler::VisitUnaryExprOrTypeTraitExpr(
   if (Kind == UETT_VectorElements) {
 if (const auto *VT = E->getTypeOfArgument()->getAs())
   return this->emitConst(VT->getNumElements(), E);
-
-// FIXME: Apparently we need to catch the fact that a sizeless vector type
-// has been passed and diagnose that (at run time).
 assert(E->getTypeOfArgument()->isSizelessVectorType());
+return this->emitSizelessVectorElementSize(E);
   }
 
   if (Kind == UETT_VecStep) {

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index b2581b5f7b5d0..b8e4432004e99 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -2736,6 +2736,15 @@ inline bool InvalidDeclRef(InterpState &S, CodePtr OpPC,
   return CheckDeclRef(S, OpPC, DR);
 }
 
+inline bool SizelessVectorElementSize(InterpState &S, CodePtr OpPC) {
+  if (S.inConstantContext()) {
+const SourceRange &ArgRange = S.Current->getRange(OpPC);
+const Expr *E = S.Current->getExpr(OpPC);
+S.CCEDiag(E, diag::note_constexpr_non_const_vectorelements) << ArgRange;
+  }
+  return false;
+}
+
 inline bool Assume(InterpState &S, CodePtr OpPC) {
   const auto Val = S.Stk.pop();
 

diff  --git a/clang/lib/AST/Interp/Opcodes.td b/clang/lib/AST/Interp/Opcodes.td
index 49ebb156ab2fb..9f29fa9272711 100644
--- a/clang/lib/AST/Interp/Opcodes.td
+++ b/clang/lib/AST/Interp/Opcodes.td
@@ -733,6 +733,8 @@ def InvalidDeclRef : Opcode {
   let Args = [ArgDeclRef];
 }
 
+def SizelessVectorElementSize : Opcode;
+
 def Assume : Opcode;
 
 def ArrayDecay : Opcode;

diff  --git a/clang/test/SemaCXX/builtin_vectorelements.cpp 
b/clang/test/SemaCXX/builtin_vectorelements.cpp
index 59ff09ac72e42..b23675ea0ac6a 100644
--- a/clang/test/SemaCXX/builtin_vectorelements.cpp
+++ b/clang/test/SemaCXX/builtin_vectorelements.cpp
@@ -1,7 +1,9 @@
 // RUN: %clang_cc1 -triple x86_64   -std=c++20 
-fsyntax-only -verify -disable-llvm-passes %s
+// RUN: %clang_cc1 -triple x86_64   -std=c++20 
-fsyntax-only -verify -disable-llvm-passes 
-fexperimental-new-constant-interpreter %s
 
 // REQUIRES: aarch64-registered-target
 // RUN: %clang_cc1 -triple aarch64 -target-feature +sve -std=c++20 
-fsyntax-only -verify -disable-llvm-passes %s
+// RUN: %clang_cc1 -triple aarch64 -target-feature +sve -std=c++20 
-fsyntax-only -verify -disable-llvm-passes 
-fexperimental-new-constant-interpreter %s
 
 template 
 using VecT __attribute__((vector_size(16))) = T;



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


[libclc] libclc: add half version of 'sign' (PR #99841)

2024-07-22 Thread Romaric Jodin via cfe-commits

https://github.com/rjodinchr created 
https://github.com/llvm/llvm-project/pull/99841

None

>From 009987936213d404a7dd28b5f1551ce85e6c8560 Mon Sep 17 00:00:00 2001
From: Romaric Jodin 
Date: Mon, 22 Jul 2024 09:44:01 +0200
Subject: [PATCH] libclc: add half version of 'sign'

---
 libclc/generic/lib/common/sign.cl | 9 +
 1 file changed, 9 insertions(+)

diff --git a/libclc/generic/lib/common/sign.cl 
b/libclc/generic/lib/common/sign.cl
index 25832e0b4f8b9..7b6b793be79c1 100644
--- a/libclc/generic/lib/common/sign.cl
+++ b/libclc/generic/lib/common/sign.cl
@@ -26,3 +26,12 @@ SIGN(double, )
 _CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, sign, double)
 
 #endif
+
+#ifdef cl_khr_fp16
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+SIGN(half,)
+_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, half, sign, half)
+
+#endif

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


[libclc] libclc: increase fp16 support (PR #98149)

2024-07-22 Thread Romaric Jodin via cfe-commits

rjodinchr wrote:

@mgorny thank you for the report. It should be fixed with: 
https://github.com/llvm/llvm-project/pull/99841

https://github.com/llvm/llvm-project/pull/98149
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] libclc: add half version of 'sign' (PR #99841)

2024-07-22 Thread Romaric Jodin via cfe-commits

rjodinchr wrote:

@frasercrmck could you review please?

https://github.com/llvm/llvm-project/pull/99841
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] libclc: add half version of 'sign' (PR #99841)

2024-07-22 Thread Michał Górny via cfe-commits

mgorny wrote:

Thanks. I can confirm that the tests pass for me with this change applied.

https://github.com/llvm/llvm-project/pull/99841
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][ASTImporter] Fix import of anonymous enums if multiple are present (PR #99281)

2024-07-22 Thread Donát Nagy via cfe-commits

https://github.com/NagyDonat approved this pull request.

LGTM as far as I can judge this tricky situation.

https://github.com/llvm/llvm-project/pull/99281
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Improve BlockIndent at ColumnLimit (PR #93140)

2024-07-22 Thread Owen Pan via cfe-commits

owenca wrote:

Please also add the following:
```
$ git diff TokenAnnotatorTest.cpp
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index c5e8aa72cd2c..4994498c389b 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1645,38 +1645,45 @@ TEST_F(TokenAnnotatorTest, UnderstandsLambdas) {
   auto Tokens = annotate("[]() constexpr {}");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
   EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_LambdaDefinitionLParen);
   EXPECT_TOKEN(Tokens[5], tok::l_brace, TT_LambdaLBrace);
 
   Tokens = annotate("[]() consteval {}");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
   EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_LambdaDefinitionLParen);
   EXPECT_TOKEN(Tokens[5], tok::l_brace, TT_LambdaLBrace);
 
   Tokens = annotate("[]() mutable {}");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
   EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_LambdaDefinitionLParen);
   EXPECT_TOKEN(Tokens[5], tok::l_brace, TT_LambdaLBrace);
 
   Tokens = annotate("[]() static {}");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
   EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_LambdaDefinitionLParen);
   EXPECT_TOKEN(Tokens[5], tok::l_brace, TT_LambdaLBrace);
 
   Tokens = annotate("[]() -> auto {}");
   ASSERT_EQ(Tokens.size(), 9u) << Tokens;
   EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_LambdaDefinitionLParen);
   EXPECT_TOKEN(Tokens[4], tok::arrow, TT_TrailingReturnArrow);
   EXPECT_TOKEN(Tokens[6], tok::l_brace, TT_LambdaLBrace);
 
   Tokens = annotate("[]() -> auto & {}");
   ASSERT_EQ(Tokens.size(), 10u) << Tokens;
   EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_LambdaDefinitionLParen);
   EXPECT_TOKEN(Tokens[4], tok::arrow, TT_TrailingReturnArrow);
   EXPECT_TOKEN(Tokens[7], tok::l_brace, TT_LambdaLBrace);
 
   Tokens = annotate("[]() -> auto * {}");
   ASSERT_EQ(Tokens.size(), 10u) << Tokens;
   EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_LambdaDefinitionLParen);
   EXPECT_TOKEN(Tokens[4], tok::arrow, TT_TrailingReturnArrow);
   EXPECT_TOKEN(Tokens[7], tok::l_brace, TT_LambdaLBrace);
 
@@ -1705,6 +1712,7 @@ TEST_F(TokenAnnotatorTest, UnderstandsLambdas) {
   Tokens = annotate("foo([&](u32 bar) __attribute__((attr)) -> void {});");
   ASSERT_EQ(Tokens.size(), 22u) << Tokens;
   EXPECT_TOKEN(Tokens[2], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_LambdaDefinitionLParen);
   EXPECT_TOKEN(Tokens[15], tok::arrow, TT_TrailingReturnArrow);
   EXPECT_TOKEN(Tokens[17], tok::l_brace, TT_LambdaLBrace);
 
@@ -1712,6 +1720,7 @@ TEST_F(TokenAnnotatorTest, UnderstandsLambdas) {
   ASSERT_EQ(Tokens.size(), 11u) << Tokens;
   EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
   EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_LambdaDefinitionLParen);
   EXPECT_TOKEN(Tokens[8], tok::l_brace, TT_LambdaLBrace);
 
   Tokens = annotate("[]  {}");
@@ -1724,6 +1733,7 @@ TEST_F(TokenAnnotatorTest, UnderstandsLambdas) {
   ASSERT_EQ(Tokens.size(), 12u) << Tokens;
   EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
   EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[7], tok::l_paren, TT_LambdaDefinitionLParen);
   EXPECT_TOKEN(Tokens[9], tok::l_brace, TT_LambdaLBrace);
 
   Tokens = annotate("[]  {}");
@@ -1736,6 +1746,7 @@ TEST_F(TokenAnnotatorTest, UnderstandsLambdas) {
   ASSERT_EQ(Tokens.size(), 12u) << Tokens;
   EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
   EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[7], tok::l_paren, TT_LambdaDefinitionLParen);
   EXPECT_TOKEN(Tokens[9], tok::l_brace, TT_LambdaLBrace);
 
   Tokens = annotate("[]  {}");
@@ -1748,6 +1759,7 @@ TEST_F(TokenAnnotatorTest, UnderstandsLambdas) {
   ASSERT_EQ(Tokens.size(), 12u) << Tokens;
   EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
   EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[7], tok::l_paren, TT_LambdaDefinitionLParen);
   EXPECT_TOKEN(Tokens[9], tok::l_brace, TT_LambdaLBrace);
 
   Tokens = annotate("[]  {}");
@@ -1761,6 +1773,7 @@ TEST_F(TokenAnnotatorTest, UnderstandsLambdas) {
   ASSERT_EQ(Tokens.size(), 18u) << Tokens;
   EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
   EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_LambdaDefinitionLParen);
   EXPECT_TOKEN(Tokens[10], tok::kw_requires, TT_RequiresClause);
   EXPECT_TRUE(Tokens[14]->ClosesRequiresClause);
   EXP

[clang-tools-extra] [IncludeCleaner] Also check for spellings of physical headers (PR #99843)

2024-07-22 Thread kadir çetinkaya via cfe-commits

https://github.com/kadircet created 
https://github.com/llvm/llvm-project/pull/99843

Some physical headers can have "conflicting" spellings, when same
filename exists under two different include search paths. e.g. 
can be provided by both standard library and underlying libc headers. In
such scenarios if the usage is from the latter include-search path,
users can't spell it directly.

This patch ensures we also consider spellings of such includes, in
addition to their physical files to prevent conflicting suggestions.


From e60ab4acfbb1b177e30618b0d4ce6a795a067cbc Mon Sep 17 00:00:00 2001
From: Kadir Cetinkaya 
Date: Mon, 22 Jul 2024 10:07:08 +0200
Subject: [PATCH] [IncludeCleaner] Also check for spellings of physical headers

Some physical headers can have "conflicting" spellings, when same
filename exists under two different include search paths. e.g. 
can be provided by both standard library and underlying libc headers. In
such scenarios if the usage is from the latter include-search path,
users can't spell it directly.

This patch ensures we also consider spellings of such includes, in
addition to their physical files to prevent conflicting suggestions.
---
 clang-tools-extra/clangd/IncludeCleaner.cpp   | 20 ++
 .../clangd/unittests/IncludeCleanerTests.cpp  | 22 
 .../include-cleaner/lib/Analysis.cpp  | 17 +---
 .../unittests/AnalysisTest.cpp| 26 +++
 4 files changed, 82 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clangd/IncludeCleaner.cpp 
b/clang-tools-extra/clangd/IncludeCleaner.cpp
index dc5b7ec95db5f..e34706172f0bf 100644
--- a/clang-tools-extra/clangd/IncludeCleaner.cpp
+++ b/clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -401,6 +401,26 @@ computeIncludeCleanerFindings(ParsedAST &AST, bool 
AnalyzeAngledIncludes) {
 Ref.RT != include_cleaner::RefType::Explicit)
   return;
 
+// Check if we have any headers with the same spelling, in edge cases
+// like `#include_next "foo.h"`, the user can't ever include the
+// physical foo.h, but can have a spelling that refers to it.
+// We postpone this check because spelling a header for every usage is
+// expensive.
+std::string Spelling = include_cleaner::spellHeader(
+{Providers.front(), AST.getPreprocessor().getHeaderSearchInfo(),
+ MainFile});
+for (auto *Inc :
+ ConvertedIncludes.match(include_cleaner::Header{Spelling})) {
+  Satisfied = true;
+  auto HeaderID =
+  AST.getIncludeStructure().getID(&Inc->Resolved->getFileEntry());
+  assert(HeaderID.has_value() &&
+ "ConvertedIncludes only contains resolved includes.");
+  Used.insert(*HeaderID);
+}
+if (Satisfied)
+  return;
+
 // We actually always want to map usages to their spellings, but
 // spelling locations can point into preamble section. Using these
 // offsets could lead into crashes in presence of stale preambles. 
Hence
diff --git a/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp 
b/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
index 7027232460354..0ee748c1ed2d0 100644
--- a/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ b/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -644,6 +644,28 @@ TEST(IncludeCleaner, ResourceDirIsIgnored) {
   EXPECT_THAT(Findings.MissingIncludes, IsEmpty());
 }
 
+TEST(IncludeCleaner, DifferentHeaderSameSpelling) {
+  // `foo` is declared in foo_inner/foo.h, but there's no way to spell it
+  // directly. Make sure we don't generate unusued/missing include findings in
+  // such cases.
+  auto TU = TestTU::withCode(R"cpp(
+#include 
+void baz() {
+  foo();
+}
+  )cpp");
+  TU.AdditionalFiles["foo/foo.h"] = guard("#include_next ");
+  TU.AdditionalFiles["foo_inner/foo.h"] = guard(R"cpp(
+void foo();
+  )cpp");
+  TU.ExtraArgs.push_back("-Ifoo");
+  TU.ExtraArgs.push_back("-Ifoo_inner");
+
+  auto AST = TU.build();
+  auto Findings = computeIncludeCleanerFindings(AST);
+  EXPECT_THAT(Findings.UnusedIncludes, IsEmpty());
+  EXPECT_THAT(Findings.MissingIncludes, IsEmpty());
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
diff --git a/clang-tools-extra/include-cleaner/lib/Analysis.cpp 
b/clang-tools-extra/include-cleaner/lib/Analysis.cpp
index f1cd72f877ca2..68fe79d6929f6 100644
--- a/clang-tools-extra/include-cleaner/lib/Analysis.cpp
+++ b/clang-tools-extra/include-cleaner/lib/Analysis.cpp
@@ -105,9 +105,20 @@ analyze(llvm::ArrayRef ASTRoots,
  }
  if (!Satisfied && !Providers.empty() &&
  Ref.RT == RefType::Explicit &&
- !HeaderFilter(Providers.front().resolvedPath()))
-   Missing.insert(spellHeader(
-   {Providers.front(), PP.getHeaderSearchInfo(), MainFile}));
+ !HeaderF

[clang-tools-extra] [IncludeCleaner] Also check for spellings of physical headers (PR #99843)

2024-07-22 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clangd

@llvm/pr-subscribers-clang-tools-extra

Author: kadir çetinkaya (kadircet)


Changes

Some physical headers can have "conflicting" spellings, when same
filename exists under two different include search paths. e.g. 
can be provided by both standard library and underlying libc headers. In
such scenarios if the usage is from the latter include-search path,
users can't spell it directly.

This patch ensures we also consider spellings of such includes, in
addition to their physical files to prevent conflicting suggestions.


---
Full diff: https://github.com/llvm/llvm-project/pull/99843.diff


4 Files Affected:

- (modified) clang-tools-extra/clangd/IncludeCleaner.cpp (+20) 
- (modified) clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp (+22) 
- (modified) clang-tools-extra/include-cleaner/lib/Analysis.cpp (+14-3) 
- (modified) clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp (+26) 


``diff
diff --git a/clang-tools-extra/clangd/IncludeCleaner.cpp 
b/clang-tools-extra/clangd/IncludeCleaner.cpp
index dc5b7ec95db5f..e34706172f0bf 100644
--- a/clang-tools-extra/clangd/IncludeCleaner.cpp
+++ b/clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -401,6 +401,26 @@ computeIncludeCleanerFindings(ParsedAST &AST, bool 
AnalyzeAngledIncludes) {
 Ref.RT != include_cleaner::RefType::Explicit)
   return;
 
+// Check if we have any headers with the same spelling, in edge cases
+// like `#include_next "foo.h"`, the user can't ever include the
+// physical foo.h, but can have a spelling that refers to it.
+// We postpone this check because spelling a header for every usage is
+// expensive.
+std::string Spelling = include_cleaner::spellHeader(
+{Providers.front(), AST.getPreprocessor().getHeaderSearchInfo(),
+ MainFile});
+for (auto *Inc :
+ ConvertedIncludes.match(include_cleaner::Header{Spelling})) {
+  Satisfied = true;
+  auto HeaderID =
+  AST.getIncludeStructure().getID(&Inc->Resolved->getFileEntry());
+  assert(HeaderID.has_value() &&
+ "ConvertedIncludes only contains resolved includes.");
+  Used.insert(*HeaderID);
+}
+if (Satisfied)
+  return;
+
 // We actually always want to map usages to their spellings, but
 // spelling locations can point into preamble section. Using these
 // offsets could lead into crashes in presence of stale preambles. 
Hence
diff --git a/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp 
b/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
index 7027232460354..0ee748c1ed2d0 100644
--- a/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ b/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -644,6 +644,28 @@ TEST(IncludeCleaner, ResourceDirIsIgnored) {
   EXPECT_THAT(Findings.MissingIncludes, IsEmpty());
 }
 
+TEST(IncludeCleaner, DifferentHeaderSameSpelling) {
+  // `foo` is declared in foo_inner/foo.h, but there's no way to spell it
+  // directly. Make sure we don't generate unusued/missing include findings in
+  // such cases.
+  auto TU = TestTU::withCode(R"cpp(
+#include 
+void baz() {
+  foo();
+}
+  )cpp");
+  TU.AdditionalFiles["foo/foo.h"] = guard("#include_next ");
+  TU.AdditionalFiles["foo_inner/foo.h"] = guard(R"cpp(
+void foo();
+  )cpp");
+  TU.ExtraArgs.push_back("-Ifoo");
+  TU.ExtraArgs.push_back("-Ifoo_inner");
+
+  auto AST = TU.build();
+  auto Findings = computeIncludeCleanerFindings(AST);
+  EXPECT_THAT(Findings.UnusedIncludes, IsEmpty());
+  EXPECT_THAT(Findings.MissingIncludes, IsEmpty());
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
diff --git a/clang-tools-extra/include-cleaner/lib/Analysis.cpp 
b/clang-tools-extra/include-cleaner/lib/Analysis.cpp
index f1cd72f877ca2..68fe79d6929f6 100644
--- a/clang-tools-extra/include-cleaner/lib/Analysis.cpp
+++ b/clang-tools-extra/include-cleaner/lib/Analysis.cpp
@@ -105,9 +105,20 @@ analyze(llvm::ArrayRef ASTRoots,
  }
  if (!Satisfied && !Providers.empty() &&
  Ref.RT == RefType::Explicit &&
- !HeaderFilter(Providers.front().resolvedPath()))
-   Missing.insert(spellHeader(
-   {Providers.front(), PP.getHeaderSearchInfo(), MainFile}));
+ !HeaderFilter(Providers.front().resolvedPath())) {
+   // Check if we have any headers with the same spelling, in edge
+   // cases like `#include_next "foo.h"`, the user can't ever
+   // include the physical foo.h, but can have a spelling that
+   // refers to it.
+   auto Spelling = spellHeader(
+   {Providers.front(), PP.getHeaderSearchInfo(), MainFile});
+   for (const Include *I : Inc.match(Header{Spelling})) {
+ U

[clang] [clang][dataflow] Handle CXXInheritedCtorInitExpr in ResultObjectVisitor. (PR #99616)

2024-07-22 Thread via cfe-commits

https://github.com/martinboehme edited 
https://github.com/llvm/llvm-project/pull/99616
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][dataflow] Handle CXXInheritedCtorInitExpr in ResultObjectVisitor. (PR #99616)

2024-07-22 Thread via cfe-commits

https://github.com/martinboehme requested changes to this pull request.

Thanks for taking this on!

Looks good apart from the fact that the test should be in a different file (and 
done slightly differently, see detailed comment in the code).

https://github.com/llvm/llvm-project/pull/99616
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][dataflow] Handle CXXInheritedCtorInitExpr in ResultObjectVisitor. (PR #99616)

2024-07-22 Thread via cfe-commits


@@ -442,6 +442,46 @@ TEST_F(EnvironmentTest, 
CXXDefaultInitExprResultObjIsWrappedExprResultObj) {
 &Env.getResultObjectLocation(*DefaultInit->getExpr()));
 }
 
+TEST_F(EnvironmentTest, ResultObjectLocationForInheritedCtorInitExpr) {

martinboehme wrote:

We tend to put tests for `getResultObjectLocation()` in TransferTest. See an 
example for `AtomicExpr` 
[here](https://github.com/llvm/llvm-project/blob/56ad7cc0126f9899fd884391cfa10b6359206c01/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp#L3391),
 which you can also use as a model for a test for `CXXInheritedCtorInitExpr`.

Doing this in TransferTest.cpp has the benefit that the test is smaller, plus 
you can make the assertion stronger (see the test for `AtomicExpr` linked above 
which checks the exact value returned by `getResultObjectLocation()` instead of 
just testing that it is non-null).

https://github.com/llvm/llvm-project/pull/99616
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Improve bug report hashing, merge similar reports (PR #98621)

2024-07-22 Thread Donát Nagy via cfe-commits

NagyDonat wrote:

I'm back from the vacation, so I would like to restart and conclude this review 
process. @steakhal or anybody else please review when it's convenient for you.

https://github.com/llvm/llvm-project/pull/98621
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Improve bug report hashing, merge similar reports (PR #98621)

2024-07-22 Thread Donát Nagy via cfe-commits

https://github.com/NagyDonat unassigned 
https://github.com/llvm/llvm-project/pull/98621
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Improve bug report hashing, merge similar reports (PR #98621)

2024-07-22 Thread Donát Nagy via cfe-commits

https://github.com/NagyDonat unassigned 
https://github.com/llvm/llvm-project/pull/98621
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Improve bug report hashing, merge similar reports (PR #98621)

2024-07-22 Thread Donát Nagy via cfe-commits

https://github.com/NagyDonat unassigned 
https://github.com/llvm/llvm-project/pull/98621
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Improve bug report hashing, merge similar reports (PR #98621)

2024-07-22 Thread Donát Nagy via cfe-commits

NagyDonat wrote:

(Btw it seems that I accidentally added everyone as an "assignee" instead of a 
reviewer...)

https://github.com/llvm/llvm-project/pull/98621
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [mlir] Remove the `x86_mmx` IR type. (PR #98505)

2024-07-22 Thread Christian Ulmann via cfe-commits

Dinistro wrote:

The MLIR side is looking good, but I cannot say something about the rest.

https://github.com/llvm/llvm-project/pull/98505
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Clang] C++20 Coroutines: Introduce Frontend Attribute [[clang::coro_await_elidable]] (PR #99282)

2024-07-22 Thread Adrian Vogelsgesang via cfe-commits


@@ -1217,6 +1217,14 @@ def CoroDisableLifetimeBound : InheritableAttr {
   let SimpleHandler = 1;
 }
 
+def CoroAwaitElidable : InheritableAttr {

vogelsgesang wrote:

does this also warrant an entry in `clang/docs/ReleaseNotes.rst`?

https://github.com/llvm/llvm-project/pull/99282
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   4   5   6   7   >