[clang] [Clang][Parser] Make 'T...[N]' within a function parameter a valid pack expansion prior to C++2c (PR #116332)

2024-11-15 Thread Younan Zhang via cfe-commits

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


[clang] 4163136 - [analyzer][Solver] Early return if sym is concrete on assuming (#115579)

2024-11-15 Thread via cfe-commits

Author: Ding Fei
Date: 2024-11-15T16:43:32+08:00
New Revision: 4163136e2ee121a5d7b86cb1262a524dde4a5ec4

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

LOG: [analyzer][Solver] Early return if sym is concrete on assuming (#115579)

This could deduce some complex syms derived from simple ones whose
values could be constrainted to be concrete during execution, thus
reducing some overconstrainted states.

This commit also fix `unix.StdCLibraryFunctions` crash due to these
overconstrainted states being added to the graph, which is marked as
sink node (PosteriorlyOverconstrained). The 'assume' API is used in
non-dual style so the checker should protectively test whether these
newly added nodes are actually impossible.

1. The crash: https://godbolt.org/z/8KKWeKb86
2. The solver needs to solve equivalent: https://godbolt.org/z/ed8WqsbTh

Added: 
clang/test/Analysis/solver-sym-simplification-on-assumption.c

clang/test/Analysis/std-c-library-functions-bufsize-nocrash-with-correct-solver.c

Modified: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
clang/test/Analysis/symbol-simplification-fixpoint-two-iterations.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 4f30b2a0e7e7da..5faaf9cf274531 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -1354,6 +1354,8 @@ void StdLibraryFunctionsChecker::checkPreCall(const 
CallEvent &Call,
 if (BR.isInteresting(ArgSVal))
   OS << Msg;
   }));
+  if (NewNode->isSink())
+break;
 }
   }
 }

diff  --git a/clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
index c0b3f346b654df..2b77167fab86f2 100644
--- a/clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
@@ -74,7 +74,7 @@ ConstraintManager::assumeDualImpl(ProgramStateRef &State,
   // it might happen that a Checker uncoditionally uses one of them if the
   // other is a nullptr. This may also happen with the non-dual and
   // adjacent `assume(true)` and `assume(false)` calls. By implementing
-  // assume in therms of assumeDual, we can keep our API contract there as
+  // assume in terms of assumeDual, we can keep our API contract there as
   // well.
   return ProgramStatePair(StInfeasible, StInfeasible);
 }

diff  --git a/clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
index 4bbe933be2129e..171b4c6392d2f8 100644
--- a/clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
@@ -23,7 +23,14 @@ RangedConstraintManager::~RangedConstraintManager() {}
 ProgramStateRef RangedConstraintManager::assumeSym(ProgramStateRef State,
SymbolRef Sym,
bool Assumption) {
-  Sym = simplify(State, Sym);
+  SVal SimplifiedVal = simplifyToSVal(State, Sym);
+  if (SimplifiedVal.isConstant()) {
+bool Feasible = SimplifiedVal.isZeroConstant() != Assumption;
+return Feasible ? State : nullptr;
+  }
+
+  if (SymbolRef SimplifiedSym = SimplifiedVal.getAsSymbol())
+Sym = SimplifiedSym;
 
   // Handle SymbolData.
   if (isa(Sym))

diff  --git a/clang/test/Analysis/solver-sym-simplification-on-assumption.c 
b/clang/test/Analysis/solver-sym-simplification-on-assumption.c
new file mode 100644
index 00..c2db144b8a7244
--- /dev/null
+++ b/clang/test/Analysis/solver-sym-simplification-on-assumption.c
@@ -0,0 +1,37 @@
+// RUN: %clang_analyze_cc1 -triple=x86_64-unknown-linux-gnu %s \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -verify
+
+void clang_analyzer_eval(int);
+void clang_analyzer_value(int);
+
+void test_derived_sym_simplification_on_assume(int s0, int s1) {
+  int elem = s0 + s1 + 1;
+  if (elem-- == 0)
+return;
+
+  if (elem-- == 0)
+return;
+
+  if (s0 < 1)
+return;
+  clang_analyzer_value(s0); // expected-warning{{[1, 2147483647]}}
+
+  if (s1 < 1)
+return;
+  clang_analyzer_value(s1); // expected-warning{{[1, 2147483647]}}
+
+  clang_analyzer_eval(elem); // expected-warning{{UNKNOWN}}
+  if (elem-- == 0)
+return;
+
+  if (s0 > 1)
+return;
+  clang_analyzer_eval(s0 == 1); // expected-warning{{TRUE}}
+
+  if (s1 > 1)
+return;
+  clang_analyzer_eval(s1 == 1); // expe

[clang] [analyzer][Solver] Early return if sym is concrete on assuming (PR #115579)

2024-11-15 Thread Ding Fei via cfe-commits

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


[clang] [analyzer][Solver] Early return if sym is concrete on assuming (PR #115579)

2024-11-15 Thread Ding Fei via cfe-commits

danix800 wrote:

> LGTM now. Thank you for this high quality patch. This isn't the first time, I 
> remember. Excellent track record.

Thanks for your reviews and all of your kindness! @steakhal @NagyDonat 

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


[clang] [clang][docs] Revise documentation for `__builtin_reduce_(max|min)`. (PR #114637)

2024-11-15 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-ppc64-aix` running 
on `aix-ppc64` while building `clang` at step 6 
"test-build-unified-tree-check-all".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/64/builds/1453


Here is the relevant piece of the build log for the reference

```
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
 TEST 'lit :: googletest-timeout.py' FAILED 

Exit Code: 1

Command Output (stdout):
--
# RUN: at line 9
not env -u FILECHECK_OPTS "/opt/freeware/bin/python3.9" 
/home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/llvm/utils/lit/lit.py
 -j1 --order=lexical -v Inputs/googletest-timeout--param 
gtest_filter=InfiniteLoopSubTest --timeout=1 > 
/home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/utils/lit/tests/Output/googletest-timeout.py.tmp.cmd.out
# executed command: not env -u FILECHECK_OPTS /opt/freeware/bin/python3.9 
/home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/llvm/utils/lit/lit.py
 -j1 --order=lexical -v Inputs/googletest-timeout --param 
gtest_filter=InfiniteLoopSubTest --timeout=1
# .---command stderr
# | lit.py: 
/home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 1 seconds was requested on the command line. Forcing 
timeout to be 1 seconds.
# | Traceback (most recent call last):
# |   File 
"/home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/llvm/utils/lit/lit/formats/googletest.py",
 line 304, in post_process_shard_results
# | testsuites = json.load(f)["testsuites"]
# |   File "/opt/freeware/lib64/python3.9/json/__init__.py", line 293, in load
# | return loads(fp.read(),
# |   File "/opt/freeware/lib64/python3.9/json/__init__.py", line 346, in loads
# | return _default_decoder.decode(s)
# |   File "/opt/freeware/lib64/python3.9/json/decoder.py", line 337, in decode
# | obj, end = self.raw_decode(s, idx=_w(s, 0).end())
# |   File "/opt/freeware/lib64/python3.9/json/decoder.py", line 355, in 
raw_decode
# | raise JSONDecodeError("Expecting value", s, err.value) from None
# | json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
# | 
# | During handling of the above exception, another exception occurred:
# | 
# | Traceback (most recent call last):
# |   File 
"/home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/llvm/utils/lit/lit.py",
 line 6, in 
# | main()
# |   File 
"/home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/llvm/utils/lit/lit/main.py",
 line 130, in main
# | selected_tests, discovered_tests = 
GoogleTest.post_process_shard_results(
# |   File 
"/home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/llvm/utils/lit/lit/formats/googletest.py",
 line 306, in post_process_shard_results
# | raise RuntimeError(
# | RuntimeError: Failed to parse json file: 
/home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/utils/lit/tests/Inputs/googletest-timeout/DummySubDir/OneTest.py-googletest-timeout-30998786-1-2.json
# | 
# `-
# RUN: at line 11
FileCheck --check-prefix=CHECK-INF < 
/home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/utils/lit/tests/Output/googletest-timeout.py.tmp.cmd.out
 
/home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/utils/lit/tests/googletest-timeout.py
# executed command: FileCheck --check-prefix=CHECK-INF 
/home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/utils/lit/tests/googletest-timeout.py
# .---command stderr
# | 
/home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/utils/lit/tests/googletest-timeout.py:34:14:
 error: CHECK-INF: expected string not found in input
# | # CHECK-INF: Timed Out: 1
# |  ^
# | :13:29: note: scanning from here
# | Reached timeout of 1 seconds
# | ^
# | :15:21: note: possible intended match here
# | TIMEOUT: googletest-timeout :: DummySubDir/OneTest.py/1/2 (2 of 2)
# | ^
# | 
# | Input file: 
...

```



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


[clang] [libcxx] [libcxxabi] [Fuchsia][cmake] Allow using FatLTO when building runtimes (PR #112277)

2024-11-15 Thread Petr Hosek via cfe-commits

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


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


[clang] [Clang][Parser] Make 'T...[N]' within a function parameter a valid pack expansion prior to C++2c (PR #116332)

2024-11-15 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 created 
https://github.com/llvm/llvm-project/pull/116332

This patch makes cases `void f(T... [N])` valid and adds a warning where the 
parameter is not of a pack indexing but of a pack expansion type, as per 
https://eel.is/c++draft/diff#cpp23.dcl.dcl-2.

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


>From 5973de1d4c368a26fd179954a13de94595f35575 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Fri, 15 Nov 2024 14:09:14 +0800
Subject: [PATCH] [Clang][Parser] Make 'T...[N]' within a function parameter a
 valid pack expansion prior to C++2c

---
 .../clang/Basic/DiagnosticParseKinds.td   |  5 
 clang/lib/Parse/ParseExprCXX.cpp  | 18 ++
 .../CXX/dcl.decl/dcl.meaning/dcl.fct/p13.cpp  |  5 ++--
 clang/test/Parser/cxx0x-decl.cpp  |  8 ++-
 .../SemaCXX/cxx2c-pack-indexing-ext-diags.cpp | 24 +++
 5 files changed, 52 insertions(+), 8 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 0da509280068ad..7b408f3eed5ba5 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -718,6 +718,11 @@ def warn_empty_init_statement : Warning<
   "has no effect">, InGroup, DefaultIgnore;
 def err_keyword_as_parameter : Error <
   "invalid parameter name: '%0' is a keyword">;
+def warn_pre_cxx26_ambiguous_pack_indexing_type : Warning<
+  "parameter packs without specifying a name would become a pack indexing "
+  "declaration in C++2c onwards">, InGroup;
+def note_add_a_name_to_pre_cxx26_parameter_packs : Note<
+  "add a name to disambiguate">;
 
 // C++ derived classes
 def err_dup_virtual : Error<"duplicate 'virtual' in base specifier">;
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index ce3624f366a2a1..c596785b267b5b 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -242,7 +242,25 @@ bool Parser::ParseOptionalCXXScopeSpecifier(
 SourceLocation Start = Tok.getLocation();
 DeclSpec DS(AttrFactory);
 SourceLocation CCLoc;
+TentativeParsingAction MaybePackIndexing(*this, /*Unannotated=*/true);
 SourceLocation EndLoc = ParsePackIndexingType(DS);
+// C++ [cpp23.dcl.dcl-2]:
+//   Previously, T...[n] would declare a pack of function parameters.
+//   T...[n] is now a pack-index-specifier. [...] Valid C++ 2023 code that
+//   declares a pack of parameters without specifying a declarator-id
+//   becomes ill-formed.
+if (!Tok.is(tok::coloncolon) && !getLangOpts().CPlusPlus26 &&
+getCurScope()->isFunctionDeclarationScope()) {
+  Diag(DS.getEllipsisLoc(),
+   diag::warn_pre_cxx26_ambiguous_pack_indexing_type);
+  Diag(DS.getEllipsisLoc(),
+   diag::note_add_a_name_to_pre_cxx26_parameter_packs);
+  MaybePackIndexing.Revert();
+  return false;
+}
+
+MaybePackIndexing.Commit();
+
 if (DS.getTypeSpecType() == DeclSpec::TST_error)
   return false;
 
diff --git a/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p13.cpp 
b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p13.cpp
index dbb6e60d9b93d7..0ae08da280b152 100644
--- a/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p13.cpp
+++ b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p13.cpp
@@ -58,8 +58,9 @@ void b(T[] ...);
 
 template
 void c(T ... []); // expected-error {{expected expression}} \
-  // expected-error {{'T' does not refer to the name of a 
parameter pack}} \
-  // expected-warning {{pack indexing is a C++2c extension}}
+  // expected-error {{type 'T[]' of function parameter pack 
does not contain any unexpanded parameter packs}} \
+  // expected-warning {{would become a pack indexing 
declaration in C++2c onwards}} \
+  // expected-note {{add a name to disambiguate}}
 
 template
 void d(T ... x[]); // expected-error{{type 'T[]' of function parameter pack 
does not contain any unexpanded parameter packs}}
diff --git a/clang/test/Parser/cxx0x-decl.cpp b/clang/test/Parser/cxx0x-decl.cpp
index a0b3266c738ff5..91b97df459df92 100644
--- a/clang/test/Parser/cxx0x-decl.cpp
+++ b/clang/test/Parser/cxx0x-decl.cpp
@@ -214,12 +214,8 @@ struct MemberComponentOrder : Base {
 void NoMissingSemicolonHere(struct S
 [3]);
 template void NoMissingSemicolonHereEither(struct S... [N]);
-// expected-error@-1 {{'S' does not refer to the name of a parameter pack}} \
-// expected-error@-1 {{declaration of anonymous struct must be a definition}} \
-// expected-error@-1 {{expected parameter declarator}} \
-// expected-error@-1 {{pack indexing is a C++2c extension}} \
-
-
+// expected-warning@-1 {{parameter packs without specifying a name would 
become a pack indexing declaration in C++2c onwards}} \
+// expected-note@-1 {{add a name to disambiguate}}
 
 // This must be at the end of the fil

[clang] [compiler-rt] [llvm] [X86] Support -march=diamondrapids (PR #113881)

2024-11-15 Thread Freddy Ye via cfe-commits


@@ -1155,6 +1155,34 @@ def ProcessorFeatures {
   list GNRDFeatures =
 !listconcat(GNRFeatures, GNRDAdditionalFeatures);
 
+  // Diamond Rapids
+  list DMRAdditionalFeatures = [FeatureAVX10_2_512,
+  FeatureAMXCOMPLEX,

FreddyLeaf wrote:

ab477fb

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


[clang] [compiler-rt] [llvm] [X86] Support -march=diamondrapids (PR #113881)

2024-11-15 Thread Freddy Ye via cfe-commits


@@ -381,6 +389,8 @@ constexpr ProcInfo Processors[] = {
   { {"emeraldrapids"}, CK_Emeraldrapids, FEATURE_AVX512FP16, 
FeaturesSapphireRapids, 'n', false },
   // Clearwaterforest microarchitecture based processors.
   { {"clearwaterforest"}, CK_Lunarlake, FEATURE_AVX2, 
FeaturesClearwaterforest, 'p', false },
+  // Diamond Rapids microarchitecture based processors.
+  { {"diamondrapids"}, CK_DiamondRapids, FEATURE_AVX10_2_512, 
FeaturesDiamondRapids, 'z', false },

FreddyLeaf wrote:

ab477fb

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


[clang] [compiler-rt] [llvm] [X86] Support -march=diamondrapids (PR #113881)

2024-11-15 Thread Phoebe Wang via cfe-commits

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

LGTM.

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


[clang] [analyzer][Solver] Early return if sym is concrete on assuming (PR #115579)

2024-11-15 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `llvm-clang-x86_64-sie-win` 
running on `sie-win-worker` while building `clang` at step 7 
"test-build-unified-tree-check-all".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/46/builds/7928


Here is the relevant piece of the build log for the reference

```
Step 7 (test-build-unified-tree-check-all) failure: test (failure)
 TEST 'Clang :: 
Analysis/symbol-simplification-fixpoint-two-iterations.cpp' FAILED 

Exit Code: 1

Command Output (stdout):
--
# RUN: at line 1
z:\b\llvm-clang-x86_64-sie-win\build\bin\clang.exe -cc1 -internal-isystem 
Z:\b\llvm-clang-x86_64-sie-win\build\lib\clang\20\include -nostdsysteminc 
-analyze -analyzer-constraints=range -setup-static-analyzer 
Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\Analysis\symbol-simplification-fixpoint-two-iterations.cpp
-analyzer-checker=core-analyzer-checker=debug.ExprInspection2>&1 | 
z:\b\llvm-clang-x86_64-sie-win\build\bin\filecheck.exe 
Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\Analysis\symbol-simplification-fixpoint-two-iterations.cpp
# executed command: 'z:\b\llvm-clang-x86_64-sie-win\build\bin\clang.exe' -cc1 
-internal-isystem 'Z:\b\llvm-clang-x86_64-sie-win\build\lib\clang\20\include' 
-nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer 
'Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\Analysis\symbol-simplification-fixpoint-two-iterations.cpp'
 -analyzer-checker=core -analyzer-checker=debug.ExprInspection
# executed command: 'z:\b\llvm-clang-x86_64-sie-win\build\bin\filecheck.exe' 
'Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\Analysis\symbol-simplification-fixpoint-two-iterations.cpp'
# .---command stderr
# | 
Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\Analysis\symbol-simplification-fixpoint-two-iterations.cpp:31:17:
 error: CHECK-NEXT: expected string not found in input
# |  // CHECK-NEXT: { "symbol": "((reg_$0) + (reg_$2)) != (reg_$3)", "range": "{ [0, 0] }" },
# | ^
# | :26:18: note: scanning 
from here
# |  "constraints": [
# |  ^
# | :27:2: note: possible 
intended match here
# |  { "symbol": "(reg_$0) != (reg_$3)", "range": "{ 
[0, 0] }" },
# |  ^
# | 
# | Input file: 
# | Check file: 
Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\Analysis\symbol-simplification-fixpoint-two-iterations.cpp
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
# | <<
# |    1: "program_state": { 
# |    2:  "store": null, 
# |    3:  "environment": { "pointer": 
"0x18a8bcdd400", "items": [ 
# |    4:  { "lctx_id": 1, 
"location_context": "#0 Call", "calling": "test", "location": null, "items": [ 

# |    5:  { "stmt_id": 809, "kind": 
"ImplicitCastExpr", "pretty": "clang_analyzer_printState", "value": 
"&code{clang_analyzer_printState}" } 
# |    6:  ]} 
# |    7:  ]}, 
# |    8:  "constraints": [ 
# | check:17   ^~~~
# |    9:  { "symbol": 
"(((reg_$0) + (reg_$1)) + (reg_$2)) != (reg_$3)", 
"range": "{ [0, 0] }" }, 
# | next:18
^~
# |   10:  { "symbol": 
"(reg_$2) + (reg_$1)", "range": "{ [0, 0] }" } 
# | next:19
^~~~
# |   11:  ], 

# | next:20^~
# |   12:  
"equivalence_classes": [ 
# | next:21^~~~
# |   13:  [ 
"((reg_$0) + (reg_$1)) + (reg_$2)", "reg_$3" 
] 
# | next:22
^~~~
# |   14:  ], 

# | next:23^~
# |   15:  
"disequality_info": null, 
# | next:24^
...

```



https://github.com/llvm/llvm-project/pull/115579

[clang] [TargetVersion] Only enable on RISC-V and AArch64 (PR #115991)

2024-11-15 Thread Piyou Chen via cfe-commits

https://github.com/BeMg updated https://github.com/llvm/llvm-project/pull/115991

>From 28f7a2adc055ec6f30790e1e9535c71241a08e29 Mon Sep 17 00:00:00 2001
From: Piyou Chen 
Date: Tue, 12 Nov 2024 20:56:47 -0800
Subject: [PATCH 1/5] [TargetVersion] Only enable on RISC-V and AArch64

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 ++
 clang/lib/Sema/SemaDeclAttr.cpp  | 5 +
 2 files changed, 7 insertions(+)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 509d45c0867590..6170c3c10b00ca 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3282,6 +3282,8 @@ def warn_unsupported_target_attribute
   "attribute string; 
'%select{target|target_clones|target_version}3' "
   "attribute ignored">,
   InGroup;
+def err_target_version_unsupported
+: Error<"target_version attribute is not supported in this target">;
 def err_attribute_unsupported
 : Error<"%0 attribute is not supported on targets missing %1;"
 " specify an appropriate -march= or -mcpu=">;
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index d05d326178e1b8..e2eaa00c666fc2 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -3040,6 +3040,11 @@ bool Sema::checkTargetVersionAttr(SourceLocation 
LiteralLoc, Decl *D,
   enum FirstParam { Unsupported };
   enum SecondParam { None };
   enum ThirdParam { Target, TargetClones, TargetVersion };
+
+  if (!Context.getTargetInfo().getTriple().isRISCV() &&
+  !Context.getTargetInfo().getTriple().isAArch64())
+return Diag(LiteralLoc, diag::err_target_version_unsupported);
+
   llvm::SmallVector Features;
   if (Context.getTargetInfo().getTriple().isRISCV()) {
 llvm::SmallVector AttrStrs;

>From 5355896434206bce33ff2442189aaff4d6b605ad Mon Sep 17 00:00:00 2001
From: Piyou Chen 
Date: Wed, 13 Nov 2024 22:25:05 -0800
Subject: [PATCH 2/5] Add testcase

---
 clang/test/Sema/attr-target-version-unsupported.c | 4 
 1 file changed, 4 insertions(+)
 create mode 100644 clang/test/Sema/attr-target-version-unsupported.c

diff --git a/clang/test/Sema/attr-target-version-unsupported.c 
b/clang/test/Sema/attr-target-version-unsupported.c
new file mode 100644
index 00..7a868e4085f20e
--- /dev/null
+++ b/clang/test/Sema/attr-target-version-unsupported.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown  -fsyntax-only -verify %s
+
+//expected-error@+1 {{target_version attribute is not supported in this 
target}}
+int __attribute__((target_version("aes"))) foo(void) { return 3; }

>From 659b628a12e05610ff82421dd358292c53940e93 Mon Sep 17 00:00:00 2001
From: Piyou Chen 
Date: Wed, 13 Nov 2024 22:28:30 -0800
Subject: [PATCH 3/5] in this target -> on this target

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td  | 2 +-
 clang/test/Sema/attr-target-version-unsupported.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 6170c3c10b00ca..0e3e8f90e52252 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3283,7 +3283,7 @@ def warn_unsupported_target_attribute
   "attribute ignored">,
   InGroup;
 def err_target_version_unsupported
-: Error<"target_version attribute is not supported in this target">;
+: Error<"target_version attribute is not supported on this target">;
 def err_attribute_unsupported
 : Error<"%0 attribute is not supported on targets missing %1;"
 " specify an appropriate -march= or -mcpu=">;
diff --git a/clang/test/Sema/attr-target-version-unsupported.c 
b/clang/test/Sema/attr-target-version-unsupported.c
index 7a868e4085f20e..056cbd25bd90d4 100644
--- a/clang/test/Sema/attr-target-version-unsupported.c
+++ b/clang/test/Sema/attr-target-version-unsupported.c
@@ -1,4 +1,4 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown  -fsyntax-only -verify %s
 
-//expected-error@+1 {{target_version attribute is not supported in this 
target}}
+//expected-error@+1 {{target_version attribute is not supported on this 
target}}
 int __attribute__((target_version("aes"))) foo(void) { return 3; }

>From 5f7a3ebe81f2dc6af7d558d012d8d05543fa7115 Mon Sep 17 00:00:00 2001
From: Piyou Chen 
Date: Thu, 14 Nov 2024 22:34:18 -0800
Subject: [PATCH 4/5] Using the TargetSpecificAttr instead of InheritableAttr

---
 clang/include/clang/Basic/Attr.td | 2 +-
 clang/include/clang/Basic/DiagnosticSemaKinds.td  | 2 --
 clang/lib/Sema/SemaDeclAttr.cpp   | 4 
 clang/test/Sema/attr-target-version-unsupported.c | 2 +-
 4 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index a631e81d40aa68

[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-15 Thread via cfe-commits


@@ -0,0 +1,713 @@
+//===-- Mustache.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/Mustache.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::json;
+
+namespace llvm {
+namespace mustache {
+
+class Token {
+public:
+  enum class Type {
+Text,
+Variable,
+Partial,
+SectionOpen,
+SectionClose,
+InvertSectionOpen,
+UnescapeVariable,
+Comment,
+  };
+
+  Token(StringRef Str);
+
+  Token(StringRef RawBody, StringRef Str, char Identifier);
+
+  StringRef getTokenBody() const { return TokenBody; };
+
+  StringRef getRawBody() const { return RawBody; };
+
+  void setTokenBody(StringRef NewBody) { TokenBody = NewBody.str(); };
+
+  Accessor getAccessor() const { return Accessor; };
+
+  Type getType() const { return TokenType; };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  size_t getIndentation() const { return Indentation; };
+
+  static Type getTokenType(char Identifier);
+
+private:
+  size_t Indentation;
+  Type TokenType;
+  // RawBody is the original string that was tokenized
+  SmallString<0> RawBody;
+  Accessor Accessor;
+  // TokenBody is the original string with the identifier removed
+  SmallString<0> TokenBody;
+};
+
+class ASTNode {
+public:
+  enum Type {
+Root,
+Text,
+Partial,
+Variable,
+UnescapeVariable,
+Section,
+InvertSection,
+  };
+
+  ASTNode() : T(Type::Root), ParentContext(nullptr) {};
+
+  ASTNode(StringRef Body, ASTNode *Parent)
+  : T(Type::Text), Body(Body), Parent(Parent), ParentContext(nullptr) {};
+
+  // Constructor for Section/InvertSection/Variable/UnescapeVariable
+  ASTNode(Type T, Accessor Accessor, ASTNode *Parent)
+  : T(T), Parent(Parent), Children({}), Accessor(Accessor),
+ParentContext(nullptr) {};
+
+  void addChild(ASTNode *Child) { Children.emplace_back(Child); };
+
+  void setBody(StringRef NewBody) { Body = NewBody; };
+
+  void setRawBody(StringRef NewBody) { RawBody = NewBody; };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  void render(const llvm::json::Value &Data, llvm::raw_ostream &OS);
+
+  void setUpNode(llvm::BumpPtrAllocator &Alloc, StringMap &Partials,
+ StringMap &Lambdas,
+ StringMap &SectionLambdas,
+ DenseMap &Escapes);
+
+private:
+  void renderLambdas(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ Lambda &L);
+
+  void renderSectionLambdas(const llvm::json::Value &Contexts,
+llvm::raw_ostream &OS, SectionLambda &L);
+
+  void renderPartial(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ ASTNode *Partial);
+
+  void renderChild(const llvm::json::Value &Context, llvm::raw_ostream &OS);
+
+  const llvm::json::Value *findContext();
+
+  llvm::BumpPtrAllocator *Allocator;
+  StringMap *Partials;
+  StringMap *Lambdas;
+  StringMap *SectionLambdas;
+  DenseMap *Escapes;
+  Type T;
+  size_t Indentation = 0;
+  SmallString<0> RawBody;
+  SmallString<0> Body;
+  ASTNode *Parent;
+  std::vector Children;
+  const Accessor Accessor;
+  const llvm::json::Value *ParentContext;
+};
+
+// Custom stream to escape strings
+class EscapeStringStream : public raw_ostream {
+public:
+  explicit EscapeStringStream(llvm::raw_ostream &WrappedStream,
+  DenseMap &Escape)
+  : Escape(Escape), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+for (char C : Data) {
+  auto It = Escape.find(C);
+  if (It != Escape.end())
+WrappedStream << It->getSecond();
+  else
+WrappedStream << C;
+}
+  }
+
+  uint64_t current_pos() const override { return WrappedStream.tell(); }
+
+private:
+  DenseMap &Escape;
+  llvm::raw_ostream &WrappedStream;
+};
+
+// Custom stream to add indentation used to for rendering partials
+class AddIndentationStringStream : public raw_ostream {
+public:
+  explicit AddIndentationStringStream(llvm::raw_ostream &WrappedStream,
+  size_t Indentation)
+  : Indentation(Indentation), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+std::string Indent(Indentation, ' ');
+for (char C : Data) {
+  WrappedStream << C;
+  if (C == '\n')
+WrappedStream << Indent;
+}
+

[clang] [Clang] Fix constexpr-ness on implicitly deleted destructors (PR #116359)

2024-11-15 Thread A. Jiang via cfe-commits

https://github.com/frederick-vs-ja created 
https://github.com/llvm/llvm-project/pull/116359

In C++20, a defaulted but implicitly deleted destructor is constexpr if and 
only if the class has no virtual base class. This hasn't been changed in C++23 
by P2448R2.

Constexpr-ness on a deleted destructor affects almost nothing. It seems that 
only the `__is_literal` intrinsic is related, while the corresponding 
`std::is_literal_type(_v)` has been removed in C++20.

Clang currently behaves correctly in C++23 mode, because the constexpr-ness on 
defaulted destructor is relaxed by P2448R2. But we should make similar 
relaxation for an implicitly deleted destructor.

Fixes #85550.

>From 8a3cb70e3bc4bbb3a8862a1dbf22322b4b7decc2 Mon Sep 17 00:00:00 2001
From: "A. Jiang" 
Date: Fri, 15 Nov 2024 17:06:08 +0800
Subject: [PATCH] [Clang] Fix constexpr-ness on implicitly deleted destructors

In C++20, a defaulted but implicitly deleted destructor is constexpr if
and only if the class has no virtual base class. This hasn't been
changed in C++23 by P2448R2.

Constexpr-ness on a deleted destructor affects almost nothing. It seems
that only the `__is_literal` intrinsic is related, while the
corresponding `std::is_literal_type(_v)` has been removed in C++20.

Clang currently behaves correctly in C++23 mode, because the
constexpr-ness on defaulted destructor is relaxed by P2448R2. But we
should make similar relaxation for an implicitly deleted destructor.
---
 .../clang/AST/CXXRecordDeclDefinitionBits.def |  3 ++
 clang/include/clang/AST/DeclCXX.h |  7 +++
 clang/lib/AST/DeclCXX.cpp | 24 ++---
 clang/test/SemaCXX/literal-type.cpp   | 53 +++
 4 files changed, 79 insertions(+), 8 deletions(-)

diff --git a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def 
b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
index 6620840df0ced2..7f47fb0890f50e 100644
--- a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
+++ b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
@@ -81,6 +81,9 @@ FIELD(IsStandardLayout, 1, NO_MERGE)
 ///   member.
 FIELD(IsCXX11StandardLayout, 1, NO_MERGE)
 
+/// True when the class has a virtual base class.
+FIELD(HasVBases, 1, NO_MERGE)
+
 /// True when any base class has any declared non-static data
 /// members or bit-fields.
 /// This is a helper bit of state used to implement IsStandardLayout more
diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 2693cc0e95b4b2..6aadb9794328ae 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -890,6 +890,13 @@ class CXXRecordDecl : public RecordDecl {
 needsOverloadResolutionForDestructor()) &&
"destructor should not be deleted");
 data().DefaultedDestructorIsDeleted = true;
+// C++23 [dcl.constexpr]p3.2:
+//  if the function is a constructor or destructor, its class does not have
+//  any virtual base classes.
+// C++20 [dcl.constexpr]p5:
+//   The definition of a constexpr destructor whose function-body is
+//   [not = delete] shall additionally satisfy...
+data().DefaultedDestructorIsConstexpr = !data().HasVBases;
   }
 
   /// Determine whether this class should get an implicit move
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 4394a0724b3c17..f094482eec6165 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -77,10 +77,11 @@ CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl 
*D)
 : UserDeclaredConstructor(false), UserDeclaredSpecialMembers(0),
   Aggregate(true), PlainOldData(true), Empty(true), Polymorphic(false),
   Abstract(false), IsStandardLayout(true), IsCXX11StandardLayout(true),
-  HasBasesWithFields(false), HasBasesWithNonStaticDataMembers(false),
-  HasPrivateFields(false), HasProtectedFields(false),
-  HasPublicFields(false), HasMutableFields(false), 
HasVariantMembers(false),
-  HasOnlyCMembers(true), HasInitMethod(false), 
HasInClassInitializer(false),
+  HasVBases(false), HasBasesWithFields(false),
+  HasBasesWithNonStaticDataMembers(false), HasPrivateFields(false),
+  HasProtectedFields(false), HasPublicFields(false),
+  HasMutableFields(false), HasVariantMembers(false), HasOnlyCMembers(true),
+  HasInitMethod(false), HasInClassInitializer(false),
   HasUninitializedReferenceMember(false), HasUninitializedFields(false),
   HasInheritedConstructor(false), HasInheritedDefaultConstructor(false),
   HasInheritedAssignment(false),
@@ -316,6 +317,8 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const 
*Bases,
 }
 
 if (Base->isVirtual()) {
+  data().HasVBases = true;
+
   // Add this base if it's not already in the list.
   if (SeenVBaseTypes.insert(C.getCanonicalType(BaseType)).second)
 VBases.push_back(Base);
@@ -547,9 +550,9 @@ void CXXRecordDecl::addedClassSubobject(CXXRecordDecl 
*Subobj)

[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-15 Thread via cfe-commits


@@ -0,0 +1,567 @@
+//===-- Mustache.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/Mustache.h"
+#include "llvm/Support/Error.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::json;
+using namespace llvm::mustache;
+
+SmallString<0> escapeString(StringRef Input,
+DenseMap &Escape) {
+  SmallString<0> Output;
+  Output.reserve(Input.size());
+  for (char C : Input) {
+auto It = Escape.find(C);
+if (It != Escape.end())
+  Output += It->getSecond();
+else
+  Output += C;
+  }
+  return Output;
+}
+
+Accessor split(StringRef Str, char Delimiter) {
+  Accessor Tokens;
+  if (Str == ".") {
+Tokens.emplace_back(Str);
+return Tokens;
+  }
+  StringRef Ref(Str);
+  while (!Ref.empty()) {
+StringRef Part;
+std::tie(Part, Ref) = Ref.split(Delimiter);
+Tokens.emplace_back(Part.trim());
+  }
+  return Tokens;
+}
+
+void addIndentation(llvm::SmallString<0> &PartialStr, size_t IndentationSize) {
+  std::string Indent(IndentationSize, ' ');
+  llvm::SmallString<0> Result;
+  for (size_t I = 0; I < PartialStr.size(); ++I) {
+Result.push_back(PartialStr[I]);
+if (PartialStr[I] == '\n' && I < PartialStr.size() - 1)
+  Result.append(Indent);
+  }
+  PartialStr = Result;
+}
+
+Token::Token(StringRef RawBody, StringRef InnerBody, char Identifier)
+: RawBody(RawBody), TokenBody(InnerBody), Indentation(0) {
+  TokenType = getTokenType(Identifier);
+  if (TokenType == Type::Comment)
+return;
+
+  StringRef AccessorStr =
+  TokenType == Type::Variable ? InnerBody : InnerBody.substr(1);
+
+  Accessor = split(AccessorStr.trim(), '.');
+}
+
+Token::Token(StringRef Str)
+: TokenType(Type::Text), RawBody(Str), Accessor({}), TokenBody(Str),
+  Indentation(0) {}
+
+Token::Type Token::getTokenType(char Identifier) {
+  switch (Identifier) {
+  case '#':
+return Type::SectionOpen;
+  case '/':
+return Type::SectionClose;
+  case '^':
+return Type::InvertSectionOpen;
+  case '!':
+return Type::Comment;
+  case '>':
+return Type::Partial;
+  case '&':
+return Type::UnescapeVariable;
+  default:
+return Type::Variable;
+  }
+}
+
+// Function to check if there's no meaningful text behind
+bool noTextBehind(size_t Idx, const SmallVector &Tokens) {

PeterChou1 wrote:

I'm not so sure I think the logic would stay largely the same with some 
cosmetic differences. Also I don't think you can mark a function as const in 
C++ I think only methods can be marked as const?

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


[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-15 Thread Utkarsh Saxena via cfe-commits


@@ -793,3 +806,202 @@ void test13() {
 }
 
 } // namespace GH100526
+
+namespace lifetime_capture_by {

usx95 wrote:

Done.

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


[clang] [Driver] Remove unused includes (NFC) (PR #116316)

2024-11-15 Thread Nikita Popov via cfe-commits

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


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


[clang] [NFC][Clang][AArch64]Refactor implementation of Neon vectors MFloat8… (PR #114804)

2024-11-15 Thread Paul Walker via cfe-commits

paulwalker-arm wrote:

What's the advantage of moving away from the current implementation?  From what 
I can see we're now having to add knowledge about what's essentially a target 
specific type across common code, which the current implementation avoids.

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


[clang] [Clang] Fix name lookup for dependent bases (PR #114978)

2024-11-15 Thread Krystian Stasiowski via cfe-commits

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


[clang] [llvm] [SPIR-V] DRAFT: Shader built-ins - no spec change (PR #116393)

2024-11-15 Thread Nathan Gauër via cfe-commits

https://github.com/Keenuts created 
https://github.com/llvm/llvm-project/pull/116393

Draft PR to explore adding semantics & inline SPIR-V for builtins. This PR is 
an alternative to #115187 which does not requires a spec change as we keep the 
variables as `static [const]`.

In addition, it tried to remain closer to DXIL by using a load/store builtin 
intrinsic instead of relying on an external global variable (IR level).

```
// RUN: %clang --driver-mode=dxc -T cs_6_6 -spirv %s -O3 -E main

[[vk::ext_builtin_input(/* NumWorkGroups */ 24)]]
static const uint3 input;

[[vk::ext_builtin_output(/* Random */ 25)]]
static uint3 output;

[shader("compute")]
[numthreads(32, 1, 1)]
void main(uint3 id : SV_GroupID, uint3 id2 : SV_GroupID) {
  output = input + id2 + id;
}
```

Note: this code wouldn't pass validation because the output built-in is invalid.

From b0c306dbbaf30740da23b6ba1c3291807247d6d7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Nathan=20Gau=C3=ABr?= 
Date: Fri, 15 Nov 2024 15:51:17 +0100
Subject: [PATCH] [SPIR-V] DRAFT: Shader built-ins - no spec change
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Draft PR to explore adding semantics & inline SPIR-V for builtins.
This PR is an alternative to #115187 which does not requires a spec
change as we keep the variables as `static [const]`.

In addition, it tried to remain closer to DXIL by using a load/store
builtin intrinsic instead of relying on an external global variable (IR
level).

```
// RUN: %clang --driver-mode=dxc -T cs_6_6 -spirv %s -O3 -E main

[[vk::ext_builtin_input(/* NumWorkGroups */ 24)]]
static const uint3 input;

[[vk::ext_builtin_output(/* Random */ 25)]]
static uint3 output;

[shader("compute")]
[numthreads(32, 1, 1)]
void main(uint3 id : SV_GroupID, uint3 id2 : SV_GroupID) {
  output = input + id2 + id;
}
```

Note: this code wouldn't pass validation because the output built-in is
invalid.

Signed-off-by: Nathan Gauër 
---
 clang/include/clang/Basic/AddressSpaces.h |  3 +
 clang/include/clang/Basic/Attr.td | 33 
 clang/include/clang/Basic/AttrDocs.td | 31 +++
 .../include/clang/Basic/AttributeCommonInfo.h |  2 +-
 clang/include/clang/Sema/SemaHLSL.h   |  2 +
 clang/lib/AST/Decl.cpp|  4 +
 clang/lib/AST/TypePrinter.cpp |  2 +
 clang/lib/Basic/Attributes.cpp|  3 +-
 clang/lib/Basic/TargetInfo.cpp|  1 +
 clang/lib/Basic/Targets/AArch64.h |  1 +
 clang/lib/Basic/Targets/AMDGPU.cpp|  2 +
 clang/lib/Basic/Targets/DirectX.h |  1 +
 clang/lib/Basic/Targets/NVPTX.h   |  1 +
 clang/lib/Basic/Targets/SPIR.h|  2 +
 clang/lib/Basic/Targets/SystemZ.h |  1 +
 clang/lib/Basic/Targets/TCE.h |  1 +
 clang/lib/Basic/Targets/WebAssembly.h | 41 +-
 clang/lib/Basic/Targets/X86.h |  1 +
 clang/lib/CodeGen/CGDeclCXX.cpp   | 18 -
 clang/lib/CodeGen/CGHLSLRuntime.cpp   | 74 -
 clang/lib/CodeGen/CGHLSLRuntime.h |  7 ++
 clang/lib/CodeGen/CodeGenModule.cpp   | 12 ++-
 clang/lib/Parse/ParseHLSL.cpp |  1 +
 clang/lib/Sema/SemaDecl.cpp   |  7 ++
 clang/lib/Sema/SemaDeclAttr.cpp   |  9 +++
 clang/lib/Sema/SemaHLSL.cpp   | 64 +++
 .../SemaTemplate/address_space-dependent.cpp  |  4 +-
 llvm/include/llvm/IR/IntrinsicsSPIRV.td   |  3 +
 llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp |  2 +-
 .../Target/SPIRV/SPIRVInstructionSelector.cpp | 80 ++-
 llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp  |  5 +-
 llvm/lib/Target/SPIRV/SPIRVUtils.cpp  |  4 +
 llvm/lib/Target/SPIRV/SPIRVUtils.h|  6 +-
 .../kernel-argument-pointer-addressspace.ll   | 22 -
 34 files changed, 413 insertions(+), 37 deletions(-)

diff --git a/clang/include/clang/Basic/AddressSpaces.h 
b/clang/include/clang/Basic/AddressSpaces.h
index 7b723d508fff17..2157ae488cf088 100644
--- a/clang/include/clang/Basic/AddressSpaces.h
+++ b/clang/include/clang/Basic/AddressSpaces.h
@@ -59,6 +59,9 @@ enum class LangAS : unsigned {
   // HLSL specific address spaces.
   hlsl_groupshared,
 
+  // Vulkan specific address spaces.
+  vulkan_private,
+
   // Wasm specific address spaces.
   wasm_funcref,
 
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 6035a563d5fce7..04a054c75690da 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -164,6 +164,16 @@ def HLSLBufferObj : SubsetSubject(S)}],
 "cbuffer/tbuffer">;
 
+def HLSLInputBuiltin : SubsetSubjecthasGlobalStorage() && 
S->getType().isConstQualified() &&
+   S->getStorageClass()==StorageClass::SC_Static}],
+ "static const global variables">;
+
+def HLSLOutputBuiltin : Subs

[clang] [clang] Improve diagnostic on [[nodiscard]] attribute (PR #112521)

2024-11-15 Thread Yihe Li via cfe-commits

https://github.com/Mick235711 updated 
https://github.com/llvm/llvm-project/pull/112521

>From 59f7dbdd8eed456b76e93f6260bf0e361242e9fd Mon Sep 17 00:00:00 2001
From: Yihe Li 
Date: Wed, 16 Oct 2024 18:53:04 +0800
Subject: [PATCH 1/3] [clang] Improve diagnostic on [[nodiscard]] attribute

---
 clang/docs/ReleaseNotes.rst   |   3 +
 clang/include/clang/AST/Expr.h|   8 +-
 .../clang/Basic/DiagnosticSemaKinds.td|   6 +
 clang/lib/AST/Expr.cpp|  18 +--
 clang/lib/Sema/SemaStmt.cpp   |  40 ---
 .../dcl.attr/dcl.attr.nodiscard/p2.cpp|  28 ++---
 .../dcl.attr/dcl.attr.nodiscard/p3.cpp|   2 +-
 clang/test/Sema/c2x-nodiscard.c   |   8 +-
 clang/test/SemaCXX/warn-unused-result.cpp | 111 ++
 9 files changed, 159 insertions(+), 65 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index dc5564b6db119f..5dd30569fad108 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -416,6 +416,9 @@ Improvements to Clang's diagnostics
   name was a reserved name, which we improperly allowed to suppress the
   diagnostic.
 
+- Clang now includes the return type of the function or constructor in the 
warning generated
+  when `[[nodiscard]]` is triggered by its placement on return types instead 
of function itself.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index cbe62411d11bff..592e1ef925796f 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -3181,12 +3181,14 @@ class CallExpr : public Expr {
   QualType getCallReturnType(const ASTContext &Ctx) const;
 
   /// Returns the WarnUnusedResultAttr that is either declared on the called
-  /// function, or its return type declaration.
-  const Attr *getUnusedResultAttr(const ASTContext &Ctx) const;
+  /// function, or its return type declaration, together with a NamedDecl that
+  /// refers to the declaration the attribute is attached onto.
+  std::pair
+  getUnusedResultAttr(const ASTContext &Ctx) const;
 
   /// Returns true if this call expression should warn on unused results.
   bool hasUnusedResultAttr(const ASTContext &Ctx) const {
-return getUnusedResultAttr(Ctx) != nullptr;
+return getUnusedResultAttr(Ctx).second != nullptr;
   }
 
   SourceLocation getRParenLoc() const { return RParenLoc; }
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c458a62d9be48c..d22ceb0920b2ab 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9267,6 +9267,12 @@ def warn_unused_container_subscript_expr : Warning<
 def warn_unused_call : Warning<
   "ignoring return value of function declared with %0 attribute">,
   InGroup;
+def warn_unused_return_type : Warning<
+  "ignoring %select{return value|temporary}0 of type %2 declared with %1 
attribute">,
+  InGroup;
+def warn_unused_return_type_msg : Warning<
+  "ignoring %select{return value|temporary}0 of type %2 declared with %1 
attribute: %3">,
+  InGroup;
 def warn_unused_constructor : Warning<
   "ignoring temporary created by a constructor declared with %0 attribute">,
   InGroup;
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 9ecbf121e3fc0d..bbb05ec48523f5 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -1616,22 +1616,24 @@ QualType CallExpr::getCallReturnType(const ASTContext 
&Ctx) const {
   return FnType->getReturnType();
 }
 
-const Attr *CallExpr::getUnusedResultAttr(const ASTContext &Ctx) const {
+std::pair
+CallExpr::getUnusedResultAttr(const ASTContext &Ctx) const {
+  // If the callee is marked nodiscard, return that attribute
+  const Decl *D = getCalleeDecl();
+  if (const auto *A = D->getAttr())
+return {nullptr, A};
+
   // If the return type is a struct, union, or enum that is marked nodiscard,
   // then return the return type attribute.
   if (const TagDecl *TD = getCallReturnType(Ctx)->getAsTagDecl())
 if (const auto *A = TD->getAttr())
-  return A;
+  return {TD, A};
 
   for (const auto *TD = getCallReturnType(Ctx)->getAs(); TD;
TD = TD->desugar()->getAs())
 if (const auto *A = TD->getDecl()->getAttr())
-  return A;
-
-  // Otherwise, see if the callee is marked nodiscard and return that attribute
-  // instead.
-  const Decl *D = getCalleeDecl();
-  return D ? D->getAttr() : nullptr;
+  return {TD->getDecl(), A};
+  return {nullptr, nullptr};
 }
 
 SourceLocation CallExpr::getBeginLoc() const {
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 9e235a46707cd4..5895da9daaf22d 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -204,22 +204,28 @@ static bool DiagnoseUnusedComparison(Sema &S, const Expr 
*E) {
   return true;
 }
 

[clang] [clang] Improve diagnostic on [[nodiscard]] attribute (PR #112521)

2024-11-15 Thread Yihe Li via cfe-commits


@@ -9300,6 +9300,12 @@ def warn_unused_container_subscript_expr : Warning<
 def warn_unused_call : Warning<
   "ignoring return value of function declared with %0 attribute">,
   InGroup;
+def warn_unused_return_type : Warning<
+  "ignoring %select{return value|temporary}0 of type %2 declared with %1 
attribute">,
+  InGroup;
+def warn_unused_return_type_msg : Warning<

Mick235711 wrote:

I originally wanted to do this, but existing `warn_unused_constructor` and 
`warn_unused_result` all have a separate `_msg` version... If we fold together 
the two `unused_return_type`s, should these two be folded together too?

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


[clang] [clang] Improve diagnostic on [[nodiscard]] attribute (PR #112521)

2024-11-15 Thread Erich Keane via cfe-commits


@@ -9300,6 +9300,12 @@ def warn_unused_container_subscript_expr : Warning<
 def warn_unused_call : Warning<
   "ignoring return value of function declared with %0 attribute">,
   InGroup;
+def warn_unused_return_type : Warning<
+  "ignoring %select{return value|temporary}0 of type %2 declared with %1 
attribute">,
+  InGroup;
+def warn_unused_return_type_msg : Warning<

erichkeane wrote:

I'll leave the choice up to you!  Change all of them would be my preference, 
but I'd like consistency between the three.

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


[clang] [clang] Instantiate attributes on LabelDecls (PR #115924)

2024-11-15 Thread Eric Astor via cfe-commits

https://github.com/ericastor updated 
https://github.com/llvm/llvm-project/pull/115924

>From da2e66a6a2636bf1a1ab2e25afdbd29095b6db3f Mon Sep 17 00:00:00 2001
From: Eric Astor 
Date: Tue, 12 Nov 2024 17:37:42 +
Subject: [PATCH 1/8] [clang] Instantiate attributes on other decl types

Start propagating attributes on (e.g.) labels inside of templated functions to 
their instances.
---
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 16 +---
 clang/test/SemaCXX/attr-mode-tmpl.cpp  |  4 ++--
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 5a001843e2ba46..bfc5913dbafd0f 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -990,6 +990,7 @@ Decl *
 TemplateDeclInstantiator::VisitLabelDecl(LabelDecl *D) {
   LabelDecl *Inst = LabelDecl::Create(SemaRef.Context, Owner, D->getLocation(),
   D->getIdentifier());
+  SemaRef.InstantiateAttrs(TemplateArgs, D, Inst, LateAttrs, StartingScope);
   Owner->addDecl(Inst);
   return Inst;
 }
@@ -1009,6 +1010,7 @@ 
TemplateDeclInstantiator::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
  D->getQualifierLoc(),
  D->getTargetNameLoc(),
  D->getNamespace());
+  SemaRef.InstantiateAttrs(TemplateArgs, D, Inst, LateAttrs, StartingScope);
   Owner->addDecl(Inst);
   return Inst;
 }
@@ -1095,15 +1097,21 @@ Decl 
*TemplateDeclInstantiator::InstantiateTypedefNameDecl(TypedefNameDecl *D,
 
 Decl *TemplateDeclInstantiator::VisitTypedefDecl(TypedefDecl *D) {
   Decl *Typedef = InstantiateTypedefNameDecl(D, /*IsTypeAlias=*/false);
-  if (Typedef)
+  if (Typedef) {
+SemaRef.InstantiateAttrs(TemplateArgs, D, Typedef, LateAttrs,
+ StartingScope);
 Owner->addDecl(Typedef);
+  }
   return Typedef;
 }
 
 Decl *TemplateDeclInstantiator::VisitTypeAliasDecl(TypeAliasDecl *D) {
   Decl *Typedef = InstantiateTypedefNameDecl(D, /*IsTypeAlias=*/true);
-  if (Typedef)
+  if (Typedef) {
+SemaRef.InstantiateAttrs(TemplateArgs, D, Typedef, LateAttrs,
+ StartingScope);
 Owner->addDecl(Typedef);
+  }
   return Typedef;
 }
 
@@ -1160,8 +1168,10 @@ Decl 
*TemplateDeclInstantiator::InstantiateTypeAliasTemplateDecl(
 Decl *
 TemplateDeclInstantiator::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) 
{
   Decl *Inst = InstantiateTypeAliasTemplateDecl(D);
-  if (Inst)
+  if (Inst) {
+SemaRef.InstantiateAttrs(TemplateArgs, D, Inst, LateAttrs, StartingScope);
 Owner->addDecl(Inst);
+  }
 
   return Inst;
 }
diff --git a/clang/test/SemaCXX/attr-mode-tmpl.cpp 
b/clang/test/SemaCXX/attr-mode-tmpl.cpp
index f665b1ba491237..58266f947051c5 100644
--- a/clang/test/SemaCXX/attr-mode-tmpl.cpp
+++ b/clang/test/SemaCXX/attr-mode-tmpl.cpp
@@ -9,7 +9,7 @@ void CheckEnumerations() {
   // Check that non-vector 'mode' attribute is OK with enumeration types.
   typedef T __attribute__((mode(QI))) T1;
   typedef T T2 __attribute__((mode(HI)));
-  typedef T __attribute__((mode(V8SI))) T3; // expected-error{{mode 'V8SI' is 
not supported for enumeration types}}
+  typedef T __attribute__((mode(V8SI))) T3; // expected-error2{{mode 'V8SI' is 
not supported for enumeration types}}
   // expected-warning@-1{{specifying vector types with the 'mode' attribute is 
deprecated}}
 
   typedef enum __attribute__((mode(HI))) { A4, B4 } T4;
@@ -62,7 +62,7 @@ struct TemplatedStruct {
 
   // Check typedefs.
   typedef T __attribute__((mode(DI)))   T1;
-  typedef T __attribute__((mode(V8DI))) T2;   // expected-error{{mode 'V8DI' 
is not supported for enumeration types}}
+  typedef T __attribute__((mode(V8DI))) T2;   // expected-error2{{mode 'V8DI' 
is not supported for enumeration types}}
   // 
expected-warning@-1{{deprecated}}
 
   // Check parameters.

>From eb4b3a2d1e25b9fc63048e5f2d71d62a3cbd2bde Mon Sep 17 00:00:00 2001
From: Eric Astor 
Date: Thu, 14 Nov 2024 19:24:45 +
Subject: [PATCH 2/8] Include attributes on LabelStmts (forwarding from decls)
 in AST dumps

We apply this to add a test of the new label attribute instantiation support.
---
 clang/examples/Attribute/Attribute.cpp | 6 +++---
 clang/include/clang/AST/ASTNodeTraverser.h | 5 +
 clang/test/Frontend/plugin-attribute.cpp   | 8 
 3 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/clang/examples/Attribute/Attribute.cpp 
b/clang/examples/Attribute/Attribute.cpp
index 3b90724ad22205..59446a15a6925d 100644
--- a/clang/examples/Attribute/Attribute.cpp
+++ b/clang/examples/Attribute/Attribute.cpp
@@ -41,9 +41,9 @@ struct ExampleAttrInfo : public ParsedAttrInfo {
   bool diagAppertainsToDecl(Sema &S, const ParsedAttr &Attr,
 const Decl *D) const override {
 // This 

[clang] [clang] Instantiate attributes on LabelDecls (PR #115924)

2024-11-15 Thread Eric Astor via cfe-commits

ericastor wrote:

> Test seems to have disappeared entirely!

Whoops. Apologies, missed that I'd forgotten to track the new file.

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


[clang] [clang] Instantiate attributes on LabelDecls (PR #115924)

2024-11-15 Thread Erich Keane via cfe-commits

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


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


[clang] [llvm] [Driver][SYCL] Add initial SYCL offload compilation support (PR #107493)

2024-11-15 Thread Michael Toguchi via cfe-commits

mdtoguchi wrote:

Thanks @AaronBallman.  I'll look into it.

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


[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-15 Thread Paul Kirth via cfe-commits

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


[clang] [llvm] [clang] Implement pragma clang section on COFF targets (PR #112714)

2024-11-15 Thread Reid Kleckner via cfe-commits

https://github.com/rnk commented:

This is an LLVM code change, not a clang code change. It's an important 
principle that we test LLVM at the smallest reasonable granularity. Can you 
replace the clang test with an IR test? I'm sure we already have existing IR 
carrying existing sections, we just need to test it with a new target.

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


[clang] [clang][CodeGen] `sret` args should always point to the `alloca` AS, so use that (PR #114062)

2024-11-15 Thread Alex Voicu via cfe-commits

https://github.com/AlexVlx updated 
https://github.com/llvm/llvm-project/pull/114062

>From d2d2d3d5db3f639aab178f9ca9a20db2842d2b65 Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Tue, 29 Oct 2024 14:20:44 +
Subject: [PATCH 01/10] `sret` args should always point to the `alloca` AS, so
 we can use that.

---
 clang/lib/CodeGen/CGCall.cpp   | 15 ---
 clang/test/CodeGen/partial-reinitialization2.c |  4 ++--
 clang/test/CodeGen/sret.c  | 11 +++
 3 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 8f4f5d3ed81601..56acfae7ae9e51 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1672,8 +1672,7 @@ CodeGenTypes::GetFunctionType(const CGFunctionInfo &FI) {
 
   // Add type for sret argument.
   if (IRFunctionArgs.hasSRetArg()) {
-QualType Ret = FI.getReturnType();
-unsigned AddressSpace = CGM.getTypes().getTargetAddressSpace(Ret);
+unsigned AddressSpace = CGM.getDataLayout().getAllocaAddrSpace();
 ArgTypes[IRFunctionArgs.getSRetArgNo()] =
 llvm::PointerType::get(getLLVMContext(), AddressSpace);
   }
@@ -5145,7 +5144,6 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   // If the call returns a temporary with struct return, create a temporary
   // alloca to hold the result, unless one is given to us.
   Address SRetPtr = Address::invalid();
-  RawAddress SRetAlloca = RawAddress::invalid();
   llvm::Value *UnusedReturnSizePtr = nullptr;
   if (RetAI.isIndirect() || RetAI.isInAlloca() || RetAI.isCoerceAndExpand()) {
 // For virtual function pointer thunks and musttail calls, we must always
@@ -5159,16 +5157,19 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
 } else if (!ReturnValue.isNull()) {
   SRetPtr = ReturnValue.getAddress();
 } else {
-  SRetPtr = CreateMemTemp(RetTy, "tmp", &SRetAlloca);
+  SRetPtr = CreateMemTempWithoutCast(RetTy, "tmp");
   if (HaveInsertPoint() && ReturnValue.isUnused()) {
 llvm::TypeSize size =
 CGM.getDataLayout().getTypeAllocSize(ConvertTypeForMem(RetTy));
-UnusedReturnSizePtr = EmitLifetimeStart(size, SRetAlloca.getPointer());
+UnusedReturnSizePtr = EmitLifetimeStart(size, 
SRetPtr.getBasePointer());
   }
 }
 if (IRFunctionArgs.hasSRetArg()) {
+  // If the caller allocated the return slot, it is possible that the
+  // alloca was AS casted to the default as, so we ensure the cast is
+  // stripped before binding to the sret arg, which is in the allocaAS.
   IRCallArgs[IRFunctionArgs.getSRetArgNo()] =
-  getAsNaturalPointerTo(SRetPtr, RetTy);
+  getAsNaturalPointerTo(SRetPtr, RetTy)->stripPointerCasts();
 } else if (RetAI.isInAlloca()) {
   Address Addr =
   Builder.CreateStructGEP(ArgMemory, RetAI.getInAllocaFieldIndex());
@@ -5740,7 +5741,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   // pop this cleanup later on. Being eager about this is OK, since this
   // temporary is 'invisible' outside of the callee.
   if (UnusedReturnSizePtr)
-pushFullExprCleanup(NormalEHLifetimeMarker, SRetAlloca,
+pushFullExprCleanup(NormalEHLifetimeMarker, SRetPtr,
  UnusedReturnSizePtr);
 
   llvm::BasicBlock *InvokeDest = CannotThrow ? nullptr : getInvokeDest();
diff --git a/clang/test/CodeGen/partial-reinitialization2.c 
b/clang/test/CodeGen/partial-reinitialization2.c
index e709c1d4ad1ee1..7949a69555031e 100644
--- a/clang/test/CodeGen/partial-reinitialization2.c
+++ b/clang/test/CodeGen/partial-reinitialization2.c
@@ -91,8 +91,8 @@ void test5(void)
 // CHECK-LABEL: test6
 void test6(void)
 {
-  // CHECK: [[LP:%[a-z0-9]+]] = getelementptr{{.*}}%struct.LLP2P2, ptr{{.*}}, 
i32 0, i32 0
-  // CHECK: call {{.*}}get456789(ptr {{.*}}[[LP]])
+  // CHECK: [[VAR:%[a-z0-9]+]] = alloca
+  // CHECK: call {{.*}}get456789(ptr {{.*}}sret{{.*}} [[VAR]])
 
   // CHECK: [[CALL:%[a-z0-9]+]] = call {{.*}}@get235()
   // CHECK: store{{.*}}[[CALL]], {{.*}}[[TMP0:%[a-z0-9.]+]]
diff --git a/clang/test/CodeGen/sret.c b/clang/test/CodeGen/sret.c
index 6d905e89b2c6fd..3b4914f29d2bfe 100644
--- a/clang/test/CodeGen/sret.c
+++ b/clang/test/CodeGen/sret.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -Wno-strict-prototypes -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -Wno-strict-prototypes -triple amdgcn-amd-amdhsa 
-emit-llvm -o - | FileCheck --check-prefix=NONZEROALLOCAAS %s
 
 struct abc {
  long a;
@@ -6,18 +7,28 @@ struct abc {
  long c;
  long d;
  long e;
+ long f;
+ long g;
+ long h;
+ long i;
+ long j;
 };
 
 struct abc foo1(void);
 // CHECK-DAG: declare {{.*}} @foo1(ptr dead_on_unwind writable 
sret(%struct.abc)
+// NONZEROALLOCAAS-DAG: declare {{.*}} @foo1(ptr addrspace(5) dead_on_unwind 
writable sret(%struct.abc)
 struct abc foo2();
 // CHECK-DAG: declare {{.*}} @foo2(ptr dead_on_unwind wri

[clang] [llvm] [RISCV] Add TT-Ascalon-d8 processor (PR #115100)

2024-11-15 Thread Petr Penzin via cfe-commits

ppenzin wrote:

Are there still open questions for the sync call?

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


[clang-tools-extra] [clang-tidy] Fix false positive in cppcoreguidelines-avoid-const-or-ref-data-members when detecting templated classes with inheritance (PR #115180)

2024-11-15 Thread Julian Schmidt via cfe-commits


@@ -13,79 +13,92 @@
 using namespace clang::ast_matchers;
 
 namespace clang::tidy::cppcoreguidelines {
-namespace {
 
-AST_MATCHER(FieldDecl, isMemberOfLambda) {
-  return Node.getParent()->isLambda();
+static bool hasCopyConstructor(CXXRecordDecl const &Node) {

5chmidti wrote:

You can probably use `CXXRecordDecl::defaultedCopyConstructorIsDeleted` as 
well, at least for an earlier exit. (+ move ctor)

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


[clang] [flang] [flang] Add UNSIGNED (PR #113504)

2024-11-15 Thread Peter Klausler via cfe-commits

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


[clang-tools-extra] Extend bugprone-use-after-move check to handle std::optional::reset() and std::any::reset() (PR #114255)

2024-11-15 Thread Julian Schmidt via cfe-commits

5chmidti wrote:

Thank you

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


[clang] [flang] [flang] Add UNSIGNED (PR #113504)

2024-11-15 Thread Peter Klausler via cfe-commits

klausler wrote:

I've exercised all of the operations and intrinsic procedures with end-to-end 
testing; those tests will end up in llvm-test-suite later.  So I'm turning off 
"draft" status now for this PR, and request your reviews.  Thank you in advance.

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


[clang] [clang-tools-extra] [analyzer] Remove alpha.core.IdenticalExpr Checker (PR #114715)

2024-11-15 Thread via cfe-commits

vabridgers wrote:

Thanks @5chmidti for the constructive comments. I believe those have been 
addressed. I'll follow up after this PR is approved and merged to split the LIT 
appropriately. Thanks for understanding this approach, it was the only one I 
could think of where the reviewers could transparently observe all features 
were maintained from the older checker. I'll happily make any other suggested 
improvements if I've missed something. Best

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


[clang] [llvm] [RISCV] Add TT-Ascalon-d8 processor (PR #115100)

2024-11-15 Thread Craig Topper via cfe-commits

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

LGTM

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


[clang] [flang] [flang] Add UNSIGNED (PR #113504)

2024-11-15 Thread Peter Klausler via cfe-commits

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


[clang] [clang-tools-extra] [analyzer] Remove alpha.core.IdenticalExpr Checker (PR #114715)

2024-11-15 Thread via cfe-commits

https://github.com/vabridgers updated 
https://github.com/llvm/llvm-project/pull/114715

>From 699d4b89b23c5b3c1f55223d6983c19a26cf2741 Mon Sep 17 00:00:00 2001
From: Vince Bridgers 
Date: Thu, 7 Nov 2024 01:58:21 +0100
Subject: [PATCH] [analyzer] Port alpha.core.IdenticalExpr to Tidy checks and
 remove

This change removes the alpha.core.IdenticalExpr static analysis
checker since it's checks are present in the clang-tidy checks
misc-redundant-expression and bugprone-branch-clone. This check was
implemented as a static analysis check using AST matching, and since
alpha and duplicated in 2 clang-tidy checks may be removed. The
existing LIT test was checked case by case, and the tidy checks
were improved to maintain alpha.core.IdenticalExpr features.
---
 .../clang-tidy/bugprone/BranchCloneCheck.cpp  | 219 
 .../misc/RedundantExpressionCheck.cpp |  70 ++-
 clang-tools-extra/docs/ReleaseNotes.rst   |   9 +
 .../checks/bugprone/branch-clone.rst  |  21 +-
 .../checks/misc/redundant-expression.rst  |  19 +
 .../bugprone/alpha-core-identicalexpr.cpp | 335 +++
 clang/docs/ReleaseNotes.rst   |   4 +
 clang/docs/analyzer/checkers.rst  |  30 -
 .../clang/StaticAnalyzer/Checkers/Checkers.td |   4 -
 .../StaticAnalyzer/Checkers/CMakeLists.txt|   1 -
 .../Checkers/IdenticalExprChecker.cpp | 519 --
 11 files changed, 568 insertions(+), 663 deletions(-)
 rename clang/test/Analysis/identical-expressions.cpp => 
clang-tools-extra/test/clang-tidy/checkers/bugprone/alpha-core-identicalexpr.cpp
 (57%)
 delete mode 100644 clang/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
index 356acf968db921..4bb7e0fd2f92ca 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
@@ -102,6 +102,210 @@ void BranchCloneCheck::registerMatchers(MatchFinder 
*Finder) {
   this);
   Finder->addMatcher(switchStmt().bind("switch"), this);
   Finder->addMatcher(conditionalOperator().bind("condOp"), this);
+  
Finder->addMatcher(ifStmt(hasDescendant(ifStmt())).bind("ifWithDescendantIf"),
+ this);
+}
+
+/// Determines whether two statement trees are identical regarding
+/// operators and symbols.
+///
+/// Exceptions: expressions containing macros or functions with possible side
+/// effects are never considered identical.
+/// Limitations: (t + u) and (u + t) are not considered identical.
+/// t*(u + t) and t*u + t*t are not considered identical.
+///
+static bool isIdenticalStmt(const ASTContext &Ctx, const Stmt *Stmt1,
+const Stmt *Stmt2, bool IgnoreSideEffects) {
+
+  if (!Stmt1 || !Stmt2)
+return !Stmt1 && !Stmt2;
+
+  // If Stmt1 & Stmt2 are of different class then they are not
+  // identical statements.
+  if (Stmt1->getStmtClass() != Stmt2->getStmtClass())
+return false;
+
+  const auto *Expr1 = dyn_cast(Stmt1);
+  const auto *Expr2 = dyn_cast(Stmt2);
+
+  if (Expr1 && Expr2) {
+// If Stmt1 has side effects then don't warn even if expressions
+// are identical.
+if (!IgnoreSideEffects && Expr1->HasSideEffects(Ctx))
+  return false;
+// If either expression comes from a macro then don't warn even if
+// the expressions are identical.
+if ((Expr1->getExprLoc().isMacroID()) || (Expr2->getExprLoc().isMacroID()))
+  return false;
+
+// If all children of two expressions are identical, return true.
+Expr::const_child_iterator I1 = Expr1->child_begin();
+Expr::const_child_iterator I2 = Expr2->child_begin();
+while (I1 != Expr1->child_end() && I2 != Expr2->child_end()) {
+  if (!*I1 || !*I2 || !isIdenticalStmt(Ctx, *I1, *I2, IgnoreSideEffects))
+return false;
+  ++I1;
+  ++I2;
+}
+// If there are different number of children in the statements, return
+// false.
+if (I1 != Expr1->child_end())
+  return false;
+if (I2 != Expr2->child_end())
+  return false;
+  }
+
+  switch (Stmt1->getStmtClass()) {
+  default:
+return false;
+  case Stmt::CallExprClass:
+  case Stmt::ArraySubscriptExprClass:
+  case Stmt::ArraySectionExprClass:
+  case Stmt::OMPArrayShapingExprClass:
+  case Stmt::OMPIteratorExprClass:
+  case Stmt::ImplicitCastExprClass:
+  case Stmt::ParenExprClass:
+  case Stmt::BreakStmtClass:
+  case Stmt::ContinueStmtClass:
+  case Stmt::NullStmtClass:
+return true;
+  case Stmt::CStyleCastExprClass: {
+const auto *CastExpr1 = cast(Stmt1);
+const auto *CastExpr2 = cast(Stmt2);
+
+return CastExpr1->getTypeAsWritten() == CastExpr2->getTypeAsWritten();
+  }
+  case Stmt::ReturnStmtClass: {
+const auto *ReturnStmt1 = cast(Stmt1);
+const auto *ReturnStmt2 = cast(Stmt2);
+
+return isIdenticalStmt(Ctx, ReturnStmt1->getRetValue(),
+ 

[clang] [clang] Fix a crash issue that caused by handling of fields with initializers in nested anonymous unions (PR #113049)

2024-11-15 Thread Shafik Yaghmour via cfe-commits

shafik wrote:

Just wanted to ping on this and see how it was going.

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


[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-15 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,724 @@
+//===-- Mustache.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/Mustache.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::json;
+
+namespace llvm {
+namespace mustache {
+
+class Token {
+public:
+  enum class Type {
+Text,
+Variable,
+Partial,
+SectionOpen,
+SectionClose,
+InvertSectionOpen,
+UnescapeVariable,
+Comment,
+  };
+
+  Token(StringRef Str);
+
+  Token(StringRef RawBody, StringRef Str, char Identifier);
+
+  StringRef getTokenBody() const { return TokenBody; };
+
+  StringRef getRawBody() const { return RawBody; };
+
+  void setTokenBody(StringRef NewBody) { TokenBody = NewBody.str(); };
+
+  Accessor getAccessor() const { return Accessor; };
+
+  Type getType() const { return TokenType; };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  size_t getIndentation() const { return Indentation; };
+
+  static Type getTokenType(char Identifier);
+
+private:
+  size_t Indentation;
+  Type TokenType;
+  // RawBody is the original string that was tokenized
+  std::string RawBody;
+  Accessor Accessor;
+  // TokenBody is the original string with the identifier removed
+  std::string TokenBody;
+};
+
+class ASTNode {
+public:
+  enum Type {
+Root,
+Text,
+Partial,
+Variable,
+UnescapeVariable,
+Section,
+InvertSection,
+  };
+
+  ASTNode() : T(Type::Root), ParentContext(nullptr) {};
+
+  ASTNode(StringRef Body, ASTNode *Parent)
+  : T(Type::Text), Body(Body), Parent(Parent), ParentContext(nullptr) {};
+
+  // Constructor for Section/InvertSection/Variable/UnescapeVariable
+  ASTNode(Type T, Accessor Accessor, ASTNode *Parent)
+  : T(T), Parent(Parent), Children({}), Accessor(Accessor),
+ParentContext(nullptr) {};
+
+  void addChild(ASTNode *Child) { Children.emplace_back(Child); };
+
+  void setBody(StringRef NewBody) { Body = NewBody; };
+
+  void setRawBody(StringRef NewBody) { RawBody = NewBody; };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  void render(const llvm::json::Value &Data, llvm::raw_ostream &OS);
+
+  void setUpNode(llvm::BumpPtrAllocator &Alloc, StringMap &Partials,
+ StringMap &Lambdas,
+ StringMap &SectionLambdas,
+ DenseMap &Escapes);
+
+private:
+  void renderLambdas(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ Lambda &L);
+
+  void renderSectionLambdas(const llvm::json::Value &Contexts,
+llvm::raw_ostream &OS, SectionLambda &L);
+
+  void renderPartial(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ ASTNode *Partial);
+
+  void renderChild(const llvm::json::Value &Context, llvm::raw_ostream &OS);
+
+  const llvm::json::Value *findContext();
+
+  llvm::BumpPtrAllocator *Allocator;
+  StringMap *Partials;
+  StringMap *Lambdas;
+  StringMap *SectionLambdas;
+  DenseMap *Escapes;
+  Type T;
+  size_t Indentation = 0;
+  std::string RawBody;
+  std::string Body;
+  ASTNode *Parent;
+  // TODO: switch implementation to SmallVector
+  std::vector Children;
+  const Accessor Accessor;
+  const llvm::json::Value *ParentContext;
+};
+
+// Custom stream to escape strings
+class EscapeStringStream : public raw_ostream {
+public:
+  explicit EscapeStringStream(llvm::raw_ostream &WrappedStream,
+  DenseMap &Escape)
+  : Escape(Escape), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+for (char C : Data) {
+  auto It = Escape.find(C);
+  if (It != Escape.end())
+WrappedStream << It->getSecond();
+  else
+WrappedStream << C;
+}
+  }
+
+  uint64_t current_pos() const override { return WrappedStream.tell(); }
+
+private:
+  DenseMap &Escape;
+  llvm::raw_ostream &WrappedStream;
+};
+
+// Custom stream to add indentation used to for rendering partials
+class AddIndentationStringStream : public raw_ostream {
+public:
+  explicit AddIndentationStringStream(llvm::raw_ostream &WrappedStream,
+  size_t Indentation)
+  : Indentation(Indentation), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+std::string Indent(Indentation, ' ');
+for (char C : Data) {
+  WrappedStream << C;
+  if (C == '\n')
+

[clang] [CodeGen] Remove unused includes (NFC) (PR #116459)

2024-11-15 Thread Kazu Hirata via cfe-commits

https://github.com/kazutakahirata created 
https://github.com/llvm/llvm-project/pull/116459

Identified with misc-include-cleaner.


>From f2b2c8a5119586cb5680ea097936a4fbc325089c Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Fri, 15 Nov 2024 15:58:42 -0800
Subject: [PATCH] [CodeGen] Remove unused includes (NFC)

Identified with misc-include-cleaner.
---
 clang/lib/CodeGen/BackendUtil.cpp  | 5 -
 clang/lib/CodeGen/CGAtomic.cpp | 1 -
 clang/lib/CodeGen/CGBlocks.cpp | 1 -
 clang/lib/CodeGen/CGBuiltin.cpp| 2 --
 clang/lib/CodeGen/CGCUDARuntime.cpp| 1 -
 clang/lib/CodeGen/CGCXX.cpp| 2 --
 clang/lib/CodeGen/CGCall.cpp   | 1 -
 clang/lib/CodeGen/CGClass.cpp  | 1 -
 clang/lib/CodeGen/CGDebugInfo.cpp  | 2 --
 clang/lib/CodeGen/CGDecl.cpp   | 1 -
 clang/lib/CodeGen/CGException.cpp  | 1 -
 clang/lib/CodeGen/CGExpr.cpp   | 4 
 clang/lib/CodeGen/CGExprComplex.cpp| 2 --
 clang/lib/CodeGen/CGGPUBuiltin.cpp | 1 -
 clang/lib/CodeGen/CGObjC.cpp   | 1 -
 clang/lib/CodeGen/CGObjCGNU.cpp| 1 -
 clang/lib/CodeGen/CGObjCMac.cpp| 2 --
 clang/lib/CodeGen/CGOpenMPRuntime.cpp  | 5 -
 clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp   | 1 -
 clang/lib/CodeGen/CGVTables.cpp| 1 -
 clang/lib/CodeGen/CodeGenABITypes.cpp  | 2 --
 clang/lib/CodeGen/CodeGenAction.cpp| 3 ---
 clang/lib/CodeGen/CodeGenFunction.cpp  | 1 -
 clang/lib/CodeGen/CodeGenModule.cpp| 4 
 clang/lib/CodeGen/CodeGenPGO.cpp   | 1 -
 clang/lib/CodeGen/CodeGenTBAA.cpp  | 2 --
 clang/lib/CodeGen/CoverageMappingGen.cpp   | 3 ---
 clang/lib/CodeGen/ItaniumCXXABI.cpp| 1 -
 clang/lib/CodeGen/LinkInModulesPass.cpp| 4 
 clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp | 3 ---
 clang/lib/CodeGen/SanitizerMetadata.cpp| 3 ---
 clang/lib/CodeGen/SwiftCallingConv.cpp | 1 -
 32 files changed, 64 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 70035a5e069a90..bf9b04f02e9f44 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -16,18 +16,14 @@
 #include "clang/Frontend/FrontendDiagnostic.h"
 #include "clang/Frontend/Utils.h"
 #include "clang/Lex/HeaderSearchOptions.h"
-#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSwitch.h"
-#include "llvm/Analysis/AliasAnalysis.h"
 #include "llvm/Analysis/GlobalsModRef.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/Bitcode/BitcodeReader.h"
 #include "llvm/Bitcode/BitcodeWriter.h"
 #include "llvm/Bitcode/BitcodeWriterPass.h"
-#include "llvm/CodeGen/RegAllocRegistry.h"
-#include "llvm/CodeGen/SchedulerRegistry.h"
 #include "llvm/CodeGen/TargetSubtargetInfo.h"
 #include "llvm/Frontend/Driver/CodeGenOptions.h"
 #include "llvm/IR/DataLayout.h"
@@ -39,7 +35,6 @@
 #include "llvm/IR/Verifier.h"
 #include "llvm/IRPrinter/IRPrintingPasses.h"
 #include "llvm/LTO/LTOBackend.h"
-#include "llvm/MC/MCAsmInfo.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Object/OffloadBinary.h"
 #include "llvm/Passes/PassBuilder.h"
diff --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp
index f8736695acf187..f6cb2ad421e906 100644
--- a/clang/lib/CodeGen/CGAtomic.cpp
+++ b/clang/lib/CodeGen/CGAtomic.cpp
@@ -21,7 +21,6 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/Intrinsics.h"
-#include "llvm/IR/Operator.h"
 
 using namespace clang;
 using namespace CodeGen;
diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index 1c46bac4bb232d..a7584a95c8ca7b 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -22,7 +22,6 @@
 #include "clang/AST/Attr.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/CodeGen/ConstantInitBuilder.h"
-#include "llvm/ADT/SmallSet.h"
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/Module.h"
 #include "llvm/Support/ScopedPrinter.h"
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 0f29dbb9509296..df69d188306be0 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -55,7 +55,6 @@
 #include "llvm/IR/IntrinsicsR600.h"
 #include "llvm/IR/IntrinsicsRISCV.h"
 #include "llvm/IR/IntrinsicsS390.h"
-#include "llvm/IR/IntrinsicsVE.h"
 #include "llvm/IR/IntrinsicsWebAssembly.h"
 #include "llvm/IR/IntrinsicsX86.h"
 #include "llvm/IR/MDBuilder.h"
@@ -69,7 +68,6 @@
 #include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/X86TargetParser.h"
 #include 
-#in

[clang] [Lex] Remove unused includes (NFC) (PR #116460)

2024-11-15 Thread Kazu Hirata via cfe-commits

https://github.com/kazutakahirata created 
https://github.com/llvm/llvm-project/pull/116460

Identified with misc-include-cleaner.


>From ff95c21b5a5dbc4164c26d0d1760be2aa3d4 Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Fri, 15 Nov 2024 17:34:23 -0800
Subject: [PATCH] [Lex] Remove unused includes (NFC)

Identified with misc-include-cleaner.
---
 clang/lib/Lex/HeaderMap.cpp   | 4 
 clang/lib/Lex/HeaderSearch.cpp| 1 -
 clang/lib/Lex/InitHeaderSearch.cpp| 3 ---
 clang/lib/Lex/Lexer.cpp   | 1 -
 clang/lib/Lex/MacroArgs.cpp   | 1 -
 clang/lib/Lex/MacroInfo.cpp   | 2 --
 clang/lib/Lex/ModuleMap.cpp   | 2 --
 clang/lib/Lex/PPCallbacks.cpp | 1 -
 clang/lib/Lex/PPDirectives.cpp| 4 
 clang/lib/Lex/PPExpressions.cpp   | 1 -
 clang/lib/Lex/PPLexerChange.cpp   | 1 -
 clang/lib/Lex/PPMacroExpansion.cpp| 4 
 clang/lib/Lex/Pragma.cpp  | 4 
 clang/lib/Lex/PreprocessingRecord.cpp | 3 ---
 clang/lib/Lex/Preprocessor.cpp| 3 ---
 clang/lib/Lex/PreprocessorLexer.cpp   | 1 -
 clang/lib/Lex/TokenLexer.cpp  | 1 -
 17 files changed, 37 deletions(-)

diff --git a/clang/lib/Lex/HeaderMap.cpp b/clang/lib/Lex/HeaderMap.cpp
index b04f67a4b2ed3c..f9e5b4ca0695e8 100644
--- a/clang/lib/Lex/HeaderMap.cpp
+++ b/clang/lib/Lex/HeaderMap.cpp
@@ -14,14 +14,10 @@
 #include "clang/Basic/CharInfo.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Lex/HeaderMapTypes.h"
-#include "llvm/ADT/SmallString.h"
 #include "llvm/Support/Compiler.h"
-#include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/MemoryBuffer.h"
-#include "llvm/Support/SwapByteOrder.h"
-#include "llvm/Support/SystemZ/zOSSupport.h"
 #include 
 #include 
 #include 
diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index c5614a8e0ee526..bf8fe44e4ca9ca 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -24,7 +24,6 @@
 #include "clang/Lex/ModuleMap.h"
 #include "clang/Lex/Preprocessor.h"
 #include "llvm/ADT/APInt.h"
-#include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
diff --git a/clang/lib/Lex/InitHeaderSearch.cpp 
b/clang/lib/Lex/InitHeaderSearch.cpp
index cb3941fa948211..ea02f5dfb62644 100644
--- a/clang/lib/Lex/InitHeaderSearch.cpp
+++ b/clang/lib/Lex/InitHeaderSearch.cpp
@@ -10,7 +10,6 @@
 //
 
//===--===//
 
-#include "clang/Basic/DiagnosticFrontend.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Config/config.h" // C_INCLUDE_DIRS
@@ -18,8 +17,6 @@
 #include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/HeaderSearchOptions.h"
 #include "llvm/ADT/SmallPtrSet.h"
-#include "llvm/ADT/SmallString.h"
-#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/ErrorHandling.h"
diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index 12cb46042c946b..e58c8bc72ae5b3 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -32,7 +32,6 @@
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ConvertUTF.h"
-#include "llvm/Support/MathExtras.h"
 #include "llvm/Support/MemoryBufferRef.h"
 #include "llvm/Support/NativeFormatting.h"
 #include "llvm/Support/Unicode.h"
diff --git a/clang/lib/Lex/MacroArgs.cpp b/clang/lib/Lex/MacroArgs.cpp
index c54f69bb9ead39..2f97d9e02bc117 100644
--- a/clang/lib/Lex/MacroArgs.cpp
+++ b/clang/lib/Lex/MacroArgs.cpp
@@ -14,7 +14,6 @@
 #include "clang/Lex/LexDiagnostic.h"
 #include "clang/Lex/MacroInfo.h"
 #include "clang/Lex/Preprocessor.h"
-#include "llvm/ADT/SmallString.h"
 #include "llvm/Support/SaveAndRestore.h"
 #include 
 
diff --git a/clang/lib/Lex/MacroInfo.cpp b/clang/lib/Lex/MacroInfo.cpp
index dfdf463665f3c1..c33276ea71cb7a 100644
--- a/clang/lib/Lex/MacroInfo.cpp
+++ b/clang/lib/Lex/MacroInfo.cpp
@@ -18,8 +18,6 @@
 #include "clang/Basic/TokenKinds.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/Token.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/Support/Casting.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index dc9d2bfd5629c9..ccf94f6345ff28 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -30,7 +30,6 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallPtrSet.h"
-#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
@@ -38,7 +37,6 @@
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/MemoryBuff

[clang] [clang-tools-extra] [analyzer] Remove alpha.core.IdenticalExpr Checker (PR #114715)

2024-11-15 Thread via cfe-commits

https://github.com/vabridgers updated 
https://github.com/llvm/llvm-project/pull/114715

>From 48389a341ece8546261b84de7af79cbb80829254 Mon Sep 17 00:00:00 2001
From: Vince Bridgers 
Date: Thu, 7 Nov 2024 01:58:21 +0100
Subject: [PATCH] [analyzer] Port alpha.core.IdenticalExpr to Tidy checks and
 remove

This change removes the alpha.core.IdenticalExpr static analysis
checker since it's checks are present in the clang-tidy checks
misc-redundant-expression and bugprone-branch-clone. This check was
implemented as a static analysis check using AST matching, and since
alpha and duplicated in 2 clang-tidy checks may be removed. The
existing LIT test was checked case by case, and the tidy checks
were improved to maintain alpha.core.IdenticalExpr features.
---
 .../clang-tidy/bugprone/BranchCloneCheck.cpp  | 217 
 .../misc/RedundantExpressionCheck.cpp |  70 ++-
 clang-tools-extra/docs/ReleaseNotes.rst   |   9 +
 .../checks/bugprone/branch-clone.rst  |  21 +-
 .../checks/misc/redundant-expression.rst  |  19 +
 .../bugprone/alpha-core-identicalexpr.cpp | 335 +++
 clang/docs/ReleaseNotes.rst   |   4 +
 clang/docs/analyzer/checkers.rst  |  30 -
 .../clang/StaticAnalyzer/Checkers/Checkers.td |   4 -
 .../StaticAnalyzer/Checkers/CMakeLists.txt|   1 -
 .../Checkers/IdenticalExprChecker.cpp | 519 --
 11 files changed, 566 insertions(+), 663 deletions(-)
 rename clang/test/Analysis/identical-expressions.cpp => 
clang-tools-extra/test/clang-tidy/checkers/bugprone/alpha-core-identicalexpr.cpp
 (57%)
 delete mode 100644 clang/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
index 356acf968db921..2a94279d7b48da 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
@@ -102,6 +102,208 @@ void BranchCloneCheck::registerMatchers(MatchFinder 
*Finder) {
   this);
   Finder->addMatcher(switchStmt().bind("switch"), this);
   Finder->addMatcher(conditionalOperator().bind("condOp"), this);
+  
Finder->addMatcher(ifStmt(hasDescendant(ifStmt())).bind("ifWithDescendantIf"),
+ this);
+}
+
+/// Determines whether two statement trees are identical regarding
+/// operators and symbols.
+///
+/// Exceptions: expressions containing macros or functions with possible side
+/// effects are never considered identical.
+/// Limitations: (t + u) and (u + t) are not considered identical.
+/// t*(u + t) and t*u + t*t are not considered identical.
+///
+static bool isIdenticalStmt(const ASTContext &Ctx, const Stmt *Stmt1,
+const Stmt *Stmt2, bool IgnoreSideEffects) {
+
+  if (!Stmt1 || !Stmt2)
+return !Stmt1 && !Stmt2;
+
+  // If Stmt1 & Stmt2 are of different class then they are not
+  // identical statements.
+  if (Stmt1->getStmtClass() != Stmt2->getStmtClass())
+return false;
+
+  const auto *Expr1 = dyn_cast(Stmt1);
+  const auto *Expr2 = dyn_cast(Stmt2);
+
+  if (Expr1 && Expr2) {
+// If Stmt1 has side effects then don't warn even if expressions
+// are identical.
+if (!IgnoreSideEffects && Expr1->HasSideEffects(Ctx))
+  return false;
+// If either expression comes from a macro then don't warn even if
+// the expressions are identical.
+if ((Expr1->getExprLoc().isMacroID()) || (Expr2->getExprLoc().isMacroID()))
+  return false;
+
+// If all children of two expressions are identical, return true.
+Expr::const_child_iterator I1 = Expr1->child_begin();
+Expr::const_child_iterator I2 = Expr2->child_begin();
+while (I1 != Expr1->child_end() && I2 != Expr2->child_end()) {
+  if (!*I1 || !*I2 || !isIdenticalStmt(Ctx, *I1, *I2, IgnoreSideEffects))
+return false;
+  ++I1;
+  ++I2;
+}
+// If there are different number of children in the statements, return
+// false.
+if (I1 != Expr1->child_end())
+  return false;
+if (I2 != Expr2->child_end())
+  return false;
+  }
+
+  switch (Stmt1->getStmtClass()) {
+  default:
+return false;
+  case Stmt::CallExprClass:
+  case Stmt::ArraySubscriptExprClass:
+  case Stmt::ArraySectionExprClass:
+  case Stmt::OMPArrayShapingExprClass:
+  case Stmt::OMPIteratorExprClass:
+  case Stmt::ImplicitCastExprClass:
+  case Stmt::ParenExprClass:
+  case Stmt::BreakStmtClass:
+  case Stmt::ContinueStmtClass:
+  case Stmt::NullStmtClass:
+return true;
+  case Stmt::CStyleCastExprClass: {
+const auto *CastExpr1 = cast(Stmt1);
+const auto *CastExpr2 = cast(Stmt2);
+
+return CastExpr1->getTypeAsWritten() == CastExpr2->getTypeAsWritten();
+  }
+  case Stmt::ReturnStmtClass: {
+const auto *ReturnStmt1 = cast(Stmt1);
+const auto *ReturnStmt2 = cast(Stmt2);
+
+return isIdenticalStmt(Ctx, ReturnStmt1->getRetValue(),
+ 

[clang] [analyzer] Handle [[assume(cond)]] as __builtin_assume(cond) (PR #116462)

2024-11-15 Thread Vinay Deshmukh via cfe-commits

https://github.com/vinay-deshmukh created 
https://github.com/llvm/llvm-project/pull/116462

Resolves #100762 

>From 773601ec7d87ac80b1440b0297f3f8f622c83a9b Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshm...@users.noreply.github.com>
Date: Fri, 15 Nov 2024 07:37:17 -0500
Subject: [PATCH] [analyzer] Handle `[[assume(cond)]]` as
 `__builtin_assume(cond)`

Resolves #100762
---
 .../Core/PathSensitive/ExprEngine.h   |  4 ++
 clang/lib/Analysis/CFG.cpp| 57 +++
 clang/lib/StaticAnalyzer/Core/ExprEngine.cpp  |  8 ++-
 .../lib/StaticAnalyzer/Core/ExprEngineCXX.cpp | 27 +
 clang/test/Analysis/out-of-bounds-new.cpp | 16 ++
 5 files changed, 111 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
index 8c7493e27fcaa6..078a1d840d0516 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
@@ -498,6 +498,10 @@ class ExprEngine {
   void VisitInitListExpr(const InitListExpr *E, ExplodedNode *Pred,
  ExplodedNodeSet &Dst);
 
+  /// VisitAttributedStmt - Transfer function logic for AttributedStmt
+  void VisitAttributedStmt(const AttributedStmt *A, ExplodedNode *Pred,
+   ExplodedNodeSet &Dst);
+
   /// VisitLogicalExpr - Transfer function logic for '&&', '||'
   void VisitLogicalExpr(const BinaryOperator* B, ExplodedNode *Pred,
 ExplodedNodeSet &Dst);
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index f678ac6f2ff36a..23a0170b527a86 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -456,6 +456,43 @@ reverse_children::reverse_children(Stmt *S) {
 IE->getNumInits());
   return;
 }
+case Stmt::AttributedStmtClass: {
+  AttributedStmt *attrStmt = cast(S);
+  assert(attrStmt);
+
+  {
+// for an attributed stmt, the "children()" returns only the NullStmt
+// (;) but semantically the "children" are supposed to be the
+// expressions _within_ i.e. the two square brackets i.e. [[ HERE ]]
+
+for (auto *child : attrStmt->children()) {
+  llvm::errs() << "\nchildren=";
+  child->dump();
+}
+
+for (const Attr *attr : attrStmt->getAttrs()) {
+  {
+llvm::errs() << "\nattr=";
+attr->printPretty(llvm::errs(), PrintingPolicy{LangOptions{}});
+  }
+
+  // i.e. one `assume()`
+  CXXAssumeAttr const *assumeAttr = 
llvm::dyn_cast(attr);
+  if (!assumeAttr) {
+continue;
+  }
+  // Only handles [[ assume() ]] right now
+  Expr *assumption = assumeAttr->getAssumption();
+  childrenBuf.push_back(assumption);
+}
+
+llvm::append_range(childrenBuf, attrStmt->children());
+
+// This needs to be done *after* childrenBuf has been populated.
+children = childrenBuf;
+  }
+  return;
+}
 default:
   break;
   }
@@ -465,6 +502,12 @@ reverse_children::reverse_children(Stmt *S) {
 
   // This needs to be done *after* childrenBuf has been populated.
   children = childrenBuf;
+
+  // for(auto* child : children)
+  // {
+  //   llvm::errs() << "\nchildren=";
+  //   child->dump();
+  // }
 }
 
 namespace {
@@ -2475,6 +2518,14 @@ static bool isFallthroughStatement(const AttributedStmt 
*A) {
   return isFallthrough;
 }
 
+static bool isCXXAssumeAttr(const AttributedStmt *A) {
+  bool hasAssumeAttr = hasSpecificAttr(A->getAttrs());
+
+  assert((!hasAssumeAttr || isa(A->getSubStmt())) &&
+ "expected [[assume]] not to have children");
+  return hasAssumeAttr;
+}
+
 CFGBlock *CFGBuilder::VisitAttributedStmt(AttributedStmt *A,
   AddStmtChoice asc) {
   // AttributedStmts for [[likely]] can have arbitrary statements as children,
@@ -2490,6 +2541,12 @@ CFGBlock *CFGBuilder::VisitAttributedStmt(AttributedStmt 
*A,
 appendStmt(Block, A);
   }
 
+  if (isCXXAssumeAttr(A) && asc.alwaysAdd(*this, A)) {
+// VINAY
+autoCreateBlock();
+appendStmt(Block, A);
+  }
+
   return VisitChildren(A);
 }
 
diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
index 22eab9f66418d4..cbc83f1dbda145 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1946,7 +1946,6 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred,
 // to be explicitly evaluated.
 case Stmt::PredefinedExprClass:
 case Stmt::AddrLabelExprClass:
-case Stmt::AttributedStmtClass:
 case Stmt::IntegerLiteralClass:
 case Stmt::FixedPointLiteralClass:
 case Stmt::CharacterLiteralClass:
@@ -1977,6 +1976,13 @@ void ExprEngine

[clang] [analyzer] Handle [[assume(cond)]] as __builtin_assume(cond) (PR #116462)

2024-11-15 Thread Vinay Deshmukh via cfe-commits

https://github.com/vinay-deshmukh updated 
https://github.com/llvm/llvm-project/pull/116462

>From d4ba202dc8a37f7b3d8eb91f5410410b8e191b31 Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshm...@users.noreply.github.com>
Date: Fri, 15 Nov 2024 07:37:17 -0500
Subject: [PATCH] [analyzer] Handle `[[assume(cond)]]` as
 `__builtin_assume(cond)`

Resolves #100762
---
 .../Core/PathSensitive/ExprEngine.h   |  4 ++
 clang/lib/Analysis/CFG.cpp| 54 +++
 clang/lib/StaticAnalyzer/Core/ExprEngine.cpp  |  8 ++-
 .../lib/StaticAnalyzer/Core/ExprEngineCXX.cpp | 27 ++
 clang/test/Analysis/out-of-bounds-new.cpp | 16 ++
 5 files changed, 108 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
index 8c7493e27fcaa6..078a1d840d0516 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
@@ -498,6 +498,10 @@ class ExprEngine {
   void VisitInitListExpr(const InitListExpr *E, ExplodedNode *Pred,
  ExplodedNodeSet &Dst);
 
+  /// VisitAttributedStmt - Transfer function logic for AttributedStmt
+  void VisitAttributedStmt(const AttributedStmt *A, ExplodedNode *Pred,
+   ExplodedNodeSet &Dst);
+
   /// VisitLogicalExpr - Transfer function logic for '&&', '||'
   void VisitLogicalExpr(const BinaryOperator* B, ExplodedNode *Pred,
 ExplodedNodeSet &Dst);
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index f678ac6f2ff36a..4f44d020a9b727 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -456,6 +456,45 @@ reverse_children::reverse_children(Stmt *S) {
 IE->getNumInits());
   return;
 }
+case Stmt::AttributedStmtClass: {
+  AttributedStmt *attrStmt = cast(S);
+  assert(attrStmt);
+
+  {
+// for an attributed stmt, the "children()" returns only the NullStmt
+// (;) but semantically the "children" are supposed to be the
+// expressions _within_ i.e. the two square brackets i.e. [[ HERE ]]
+// so we add the subexpressions first, _then_ add the "children"
+
+for (auto *child : attrStmt->children()) {
+  llvm::errs() << "\nchildren=";
+  child->dump();
+}
+
+for (const Attr *attr : attrStmt->getAttrs()) {
+  {
+llvm::errs() << "\nattr=";
+attr->printPretty(llvm::errs(), PrintingPolicy{LangOptions{}});
+  }
+
+  // i.e. one `assume()`
+  CXXAssumeAttr const *assumeAttr = 
llvm::dyn_cast(attr);
+  if (!assumeAttr) {
+continue;
+  }
+  // Only handles [[ assume() ]] right now
+  Expr *assumption = assumeAttr->getAssumption();
+  childrenBuf.push_back(assumption);
+}
+
+// children() for an AttributedStmt is NullStmt(;)
+llvm::append_range(childrenBuf, attrStmt->children());
+
+// This needs to be done *after* childrenBuf has been populated.
+children = childrenBuf;
+  }
+  return;
+}
 default:
   break;
   }
@@ -465,6 +504,7 @@ reverse_children::reverse_children(Stmt *S) {
 
   // This needs to be done *after* childrenBuf has been populated.
   children = childrenBuf;
+
 }
 
 namespace {
@@ -2475,6 +2515,14 @@ static bool isFallthroughStatement(const AttributedStmt 
*A) {
   return isFallthrough;
 }
 
+static bool isCXXAssumeAttr(const AttributedStmt *A) {
+  bool hasAssumeAttr = hasSpecificAttr(A->getAttrs());
+
+  assert((!hasAssumeAttr || isa(A->getSubStmt())) &&
+ "expected [[assume]] not to have children");
+  return hasAssumeAttr;
+}
+
 CFGBlock *CFGBuilder::VisitAttributedStmt(AttributedStmt *A,
   AddStmtChoice asc) {
   // AttributedStmts for [[likely]] can have arbitrary statements as children,
@@ -2490,6 +2538,12 @@ CFGBlock *CFGBuilder::VisitAttributedStmt(AttributedStmt 
*A,
 appendStmt(Block, A);
   }
 
+  if (isCXXAssumeAttr(A) && asc.alwaysAdd(*this, A)) {
+// VINAY
+autoCreateBlock();
+appendStmt(Block, A);
+  }
+
   return VisitChildren(A);
 }
 
diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
index 22eab9f66418d4..cbc83f1dbda145 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1946,7 +1946,6 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred,
 // to be explicitly evaluated.
 case Stmt::PredefinedExprClass:
 case Stmt::AddrLabelExprClass:
-case Stmt::AttributedStmtClass:
 case Stmt::IntegerLiteralClass:
 case Stmt::FixedPointLiteralClass:
 case Stmt::CharacterLiteralClass:
@@ -1977,6 +1976,13 @@ void ExprEng

[clang] Add concepts to ast (PR #116407)

2024-11-15 Thread Joshua Batista via cfe-commits

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


[clang] [analyzer] Handle [[assume(cond)]] as __builtin_assume(cond) (PR #116462)

2024-11-15 Thread Vinay Deshmukh via cfe-commits

vinay-deshmukh wrote:

@steakhal 

Can you take a look at this PR when you have a chance?
Thanks!

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


[clang] [analyzer] Handle [[assume(cond)]] as __builtin_assume(cond) (PR #116462)

2024-11-15 Thread Vinay Deshmukh via cfe-commits

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


[clang] [Clang] Add 'gpuintrin.h' to the release notes (PR #116410)

2024-11-15 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 created 
https://github.com/llvm/llvm-project/pull/116410

None

>From 872cc825e86ec1ad52a95ed5a9e532c34b27f4cb Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Fri, 15 Nov 2024 11:03:21 -0600
Subject: [PATCH] [Clang] Add 'gpuintrin.h' to the release notes

---
 clang/docs/ReleaseNotes.rst | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ba582160cf9920..bee5155d3a7e5d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -710,6 +710,17 @@ Target Specific Changes
 AMDGPU Support
 ^^
 
+- Added headers ``gpuintrin.h`` and ``amdgpuintrin.h`` that contains common
+  definitions for GPU builtin functions. This header can be included for 
OpenMP,
+  CUDA, HIP, OpenCL, and C/C++.
+
+NVPTX Support
+^^
+
+- Added headers ``gpuintrin.h`` and ``nvptxuintrin.h`` that contains common
+  definitions for GPU builtin functions. This header can be included for 
OpenMP,
+  CUDA, HIP, OpenCL, and C/C++.
+
 X86 Support
 ^^^
 

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


[clang] [clang] Instantiate attributes on LabelDecls (PR #115924)

2024-11-15 Thread Eric Astor via cfe-commits

https://github.com/ericastor updated 
https://github.com/llvm/llvm-project/pull/115924

>From da2e66a6a2636bf1a1ab2e25afdbd29095b6db3f Mon Sep 17 00:00:00 2001
From: Eric Astor 
Date: Tue, 12 Nov 2024 17:37:42 +
Subject: [PATCH 1/8] [clang] Instantiate attributes on other decl types

Start propagating attributes on (e.g.) labels inside of templated functions to 
their instances.
---
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 16 +---
 clang/test/SemaCXX/attr-mode-tmpl.cpp  |  4 ++--
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 5a001843e2ba46..bfc5913dbafd0f 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -990,6 +990,7 @@ Decl *
 TemplateDeclInstantiator::VisitLabelDecl(LabelDecl *D) {
   LabelDecl *Inst = LabelDecl::Create(SemaRef.Context, Owner, D->getLocation(),
   D->getIdentifier());
+  SemaRef.InstantiateAttrs(TemplateArgs, D, Inst, LateAttrs, StartingScope);
   Owner->addDecl(Inst);
   return Inst;
 }
@@ -1009,6 +1010,7 @@ 
TemplateDeclInstantiator::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
  D->getQualifierLoc(),
  D->getTargetNameLoc(),
  D->getNamespace());
+  SemaRef.InstantiateAttrs(TemplateArgs, D, Inst, LateAttrs, StartingScope);
   Owner->addDecl(Inst);
   return Inst;
 }
@@ -1095,15 +1097,21 @@ Decl 
*TemplateDeclInstantiator::InstantiateTypedefNameDecl(TypedefNameDecl *D,
 
 Decl *TemplateDeclInstantiator::VisitTypedefDecl(TypedefDecl *D) {
   Decl *Typedef = InstantiateTypedefNameDecl(D, /*IsTypeAlias=*/false);
-  if (Typedef)
+  if (Typedef) {
+SemaRef.InstantiateAttrs(TemplateArgs, D, Typedef, LateAttrs,
+ StartingScope);
 Owner->addDecl(Typedef);
+  }
   return Typedef;
 }
 
 Decl *TemplateDeclInstantiator::VisitTypeAliasDecl(TypeAliasDecl *D) {
   Decl *Typedef = InstantiateTypedefNameDecl(D, /*IsTypeAlias=*/true);
-  if (Typedef)
+  if (Typedef) {
+SemaRef.InstantiateAttrs(TemplateArgs, D, Typedef, LateAttrs,
+ StartingScope);
 Owner->addDecl(Typedef);
+  }
   return Typedef;
 }
 
@@ -1160,8 +1168,10 @@ Decl 
*TemplateDeclInstantiator::InstantiateTypeAliasTemplateDecl(
 Decl *
 TemplateDeclInstantiator::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) 
{
   Decl *Inst = InstantiateTypeAliasTemplateDecl(D);
-  if (Inst)
+  if (Inst) {
+SemaRef.InstantiateAttrs(TemplateArgs, D, Inst, LateAttrs, StartingScope);
 Owner->addDecl(Inst);
+  }
 
   return Inst;
 }
diff --git a/clang/test/SemaCXX/attr-mode-tmpl.cpp 
b/clang/test/SemaCXX/attr-mode-tmpl.cpp
index f665b1ba491237..58266f947051c5 100644
--- a/clang/test/SemaCXX/attr-mode-tmpl.cpp
+++ b/clang/test/SemaCXX/attr-mode-tmpl.cpp
@@ -9,7 +9,7 @@ void CheckEnumerations() {
   // Check that non-vector 'mode' attribute is OK with enumeration types.
   typedef T __attribute__((mode(QI))) T1;
   typedef T T2 __attribute__((mode(HI)));
-  typedef T __attribute__((mode(V8SI))) T3; // expected-error{{mode 'V8SI' is 
not supported for enumeration types}}
+  typedef T __attribute__((mode(V8SI))) T3; // expected-error2{{mode 'V8SI' is 
not supported for enumeration types}}
   // expected-warning@-1{{specifying vector types with the 'mode' attribute is 
deprecated}}
 
   typedef enum __attribute__((mode(HI))) { A4, B4 } T4;
@@ -62,7 +62,7 @@ struct TemplatedStruct {
 
   // Check typedefs.
   typedef T __attribute__((mode(DI)))   T1;
-  typedef T __attribute__((mode(V8DI))) T2;   // expected-error{{mode 'V8DI' 
is not supported for enumeration types}}
+  typedef T __attribute__((mode(V8DI))) T2;   // expected-error2{{mode 'V8DI' 
is not supported for enumeration types}}
   // 
expected-warning@-1{{deprecated}}
 
   // Check parameters.

>From eb4b3a2d1e25b9fc63048e5f2d71d62a3cbd2bde Mon Sep 17 00:00:00 2001
From: Eric Astor 
Date: Thu, 14 Nov 2024 19:24:45 +
Subject: [PATCH 2/8] Include attributes on LabelStmts (forwarding from decls)
 in AST dumps

We apply this to add a test of the new label attribute instantiation support.
---
 clang/examples/Attribute/Attribute.cpp | 6 +++---
 clang/include/clang/AST/ASTNodeTraverser.h | 5 +
 clang/test/Frontend/plugin-attribute.cpp   | 8 
 3 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/clang/examples/Attribute/Attribute.cpp 
b/clang/examples/Attribute/Attribute.cpp
index 3b90724ad22205..59446a15a6925d 100644
--- a/clang/examples/Attribute/Attribute.cpp
+++ b/clang/examples/Attribute/Attribute.cpp
@@ -41,9 +41,9 @@ struct ExampleAttrInfo : public ParsedAttrInfo {
   bool diagAppertainsToDecl(Sema &S, const ParsedAttr &Attr,
 const Decl *D) const override {
 // This 

[clang] [llvm] [NFC][clang][FMV][TargetInfo] Refactor API for FMV feature priority. (PR #116257)

2024-11-15 Thread Alexandros Lamprineas via cfe-commits


@@ -48,6 +48,19 @@ std::optional 
AArch64::ArchInfo::findBySubArch(StringRef SubA
   return {};
 }
 
+unsigned AArch64::getFMVPriority(ArrayRef Features) {
+  constexpr unsigned MaxFMVPriority = 1000;
+  unsigned Priority = 0;
+  unsigned NumFeatures = 0;
+  for (StringRef Feature : Features) {
+if (auto Ext = parseFMVExtension(Feature)) {
+  Priority = std::max(Priority, Ext->Priority);
+  NumFeatures++;
+}
+  }
+  return Priority + MaxFMVPriority * NumFeatures;

labrinea wrote:

You're right, that's what it does. The more specific a version is (more 
features), then higher its priority. If it's a tie, the version with the 
highest priority feature wins. Indeed this is NFC. Changing it is ABI break, 
which doesn't bother me personally. I think since FMV is not yet widely used, 
we should be free to make sensible changes to the specification.

I am not sure what the original idea was. Perhaps it makes sense a feature that 
depends on other features to have higher priorirty than them? We could use the 
runtime bitmasks for this as I tried to do here 
https://github.com/llvm/llvm-project/pull/87939/files#r1842027067. On a 
tangent, we (Arm) are discussing about potentially detecting dependent features 
at runtime, but that's for another time - slightly relevant though.

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


[clang] [llvm] [NFC][clang][FMV][TargetInfo] Refactor API for FMV feature priority. (PR #116257)

2024-11-15 Thread Alexandros Lamprineas via cfe-commits


@@ -1363,19 +1363,28 @@ static llvm::X86::ProcessorFeatures 
getFeature(StringRef Name) {
   // correct, so it asserts if the value is out of range.
 }
 
-unsigned X86TargetInfo::multiVersionSortPriority(StringRef Name) const {
-  // Valid CPUs have a 'key feature' that compares just better than its key
-  // feature.
-  using namespace llvm::X86;
-  CPUKind Kind = parseArchX86(Name);
-  if (Kind != CK_None) {
-ProcessorFeatures KeyFeature = getKeyFeature(Kind);
-return (getFeaturePriority(KeyFeature) << 1) + 1;
-  }
-
-  // Now we know we have a feature, so get its priority and shift it a few so
-  // that we have sufficient room for the CPUs (above).
-  return getFeaturePriority(getFeature(Name)) << 1;
+unsigned X86TargetInfo::getFMVPriority(ArrayRef Features) const {
+  auto getPriority = [this](StringRef Feature) -> unsigned {
+if (Feature.empty())
+  return 0;
+
+// Valid CPUs have a 'key feature' that compares just better than its key
+// feature.
+using namespace llvm::X86;
+CPUKind Kind = parseArchX86(Feature);
+if (Kind != CK_None) {
+  ProcessorFeatures KeyFeature = getKeyFeature(Kind);
+  return (getFeaturePriority(KeyFeature) << 1) + 1;
+}
+// Now we know we have a feature, so get its priority and shift it a few so
+// that we have sufficient room for the CPUs (above).
+return getFeaturePriority(getFeature(Feature)) << 1;
+  };
+
+  unsigned Priority = 0;
+  for (StringRef Feature : Features)
+Priority = std::max(Priority, getPriority(Feature));

labrinea wrote:

My aim was for this to be NFC. Does it look different from what 
TargetMVPriority did in the old code? The old multiVersionSortPriority is now 
the above lambda.

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


[clang] 3130691 - [C23] Move WG14 N2754 to the TS 18661 section

2024-11-15 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2024-11-15T12:52:18-05:00
New Revision: 3130691a6053f90e1bac8026645b7bf95d6279cc

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

LOG: [C23] Move WG14 N2754 to the TS 18661 section

This paper is about the quantum exponent of NAN, which only applies if
we support decimal floating-point types from the TS. That is why the
status changed from Unknown to No.

Added: 


Modified: 
clang/www/c_status.html

Removed: 




diff  --git a/clang/www/c_status.html b/clang/www/c_status.html
index 793e7006822cc1..ca2ca5398bb873 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -289,7 +289,7 @@ C23 implementation status
   Clang 9
 
 
-  TS 18661 Integration
+  TS 18661 Integration
 

 https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2314.pdf";>N2314
@@ -319,6 +319,10 @@ C23 implementation status
 https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2931.pdf";>N2931
 No
   
+  
+https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2754.htm";>N2754
+No
+  
 
   Preprocessor line numbers unspecified
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2322.htm";>N2322
@@ -626,11 +630,6 @@ C23 implementation status
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2701.htm";>N2701
   Yes
 
-
-  Quantum exponent of NaN (version 2)
-  https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2754.htm";>N2754
-  Unknown
-
 
   The noreturn attribute
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2764.pdf";>N2764



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


[clang] [clang-tools-extra] [clangd] Update clangDaemonTweaks to set symbol visibility macros (PR #112304)

2024-11-15 Thread Thomas Fransham via cfe-commits


@@ -114,7 +114,7 @@ macro(add_clang_library name)
 if(TARGET "obj.${name}")
   target_compile_definitions("obj.${name}" PUBLIC CLANG_BUILD_STATIC)
 endif()
-  elseif(NOT ARG_SHARED AND NOT ARG_STATIC)
+  elseif(NOT ARG_SHARED AND NOT ARG_STATIC AND NOT ARG_CLANG_IMPORT)

fsfod wrote:

 what do you mean, its only checking for the arg not being set, so it shouldn't 
change the behaviour for other libraries.

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


[clang] [clang-tools-extra] [clangd] Update clangDaemonTweaks to set symbol visibility macros (PR #112304)

2024-11-15 Thread Saleem Abdulrasool via cfe-commits


@@ -47,7 +47,7 @@ endmacro()
 
 macro(add_clang_library name)
   cmake_parse_arguments(ARG
-"SHARED;STATIC;INSTALL_WITH_TOOLCHAIN"
+"SHARED;STATIC;INSTALL_WITH_TOOLCHAIN;CLANG_IMPORT"

compnerd wrote:

It is unclear what this new option (`CLANG_IMPORT`) does.

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


[clang] Clang tooling generated visibility macros for Clang (PR #109702)

2024-11-15 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

A gentle ping on reviewing.

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


[clang] [llvm] [NFC][clang][FMV][TargetInfo] Refactor API for FMV feature priority. (PR #116257)

2024-11-15 Thread Jon Roelofs via cfe-commits

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


[clang] [llvm] [NFC][clang][FMV][TargetInfo] Refactor API for FMV feature priority. (PR #116257)

2024-11-15 Thread Jon Roelofs via cfe-commits


@@ -48,6 +48,19 @@ std::optional 
AArch64::ArchInfo::findBySubArch(StringRef SubA
   return {};
 }
 
+unsigned AArch64::getFMVPriority(ArrayRef Features) {
+  constexpr unsigned MaxFMVPriority = 1000;
+  unsigned Priority = 0;
+  unsigned NumFeatures = 0;
+  for (StringRef Feature : Features) {
+if (auto Ext = parseFMVExtension(Feature)) {
+  Priority = std::max(Priority, Ext->Priority);
+  NumFeatures++;
+}
+  }
+  return Priority + MaxFMVPriority * NumFeatures;

jroelofs wrote:

I am also not bothered by breaking ABI here, for the record.

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


[clang] [clang-tools-extra] [clangd] Update clangDaemonTweaks to set symbol visibility macros (PR #112304)

2024-11-15 Thread Saleem Abdulrasool via cfe-commits


@@ -114,7 +114,7 @@ macro(add_clang_library name)
 if(TARGET "obj.${name}")
   target_compile_definitions("obj.${name}" PUBLIC CLANG_BUILD_STATIC)
 endif()
-  elseif(NOT ARG_SHARED AND NOT ARG_STATIC)
+  elseif(NOT ARG_SHARED AND NOT ARG_STATIC AND NOT ARG_CLANG_IMPORT)

compnerd wrote:

This seems like it would change the behaviour of other libraries which were 
previously being built for shared linking (or at least were exporting their 
interfaces) to now be built for static linking (or no longer export their 
symbols).

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


[clang] [llvm] [NFC][clang][FMV][TargetInfo] Refactor API for FMV feature priority. (PR #116257)

2024-11-15 Thread Jon Roelofs via cfe-commits


@@ -48,6 +48,19 @@ std::optional 
AArch64::ArchInfo::findBySubArch(StringRef SubA
   return {};
 }
 
+unsigned AArch64::getFMVPriority(ArrayRef Features) {
+  constexpr unsigned MaxFMVPriority = 1000;
+  unsigned Priority = 0;
+  unsigned NumFeatures = 0;
+  for (StringRef Feature : Features) {
+if (auto Ext = parseFMVExtension(Feature)) {
+  Priority = std::max(Priority, Ext->Priority);
+  NumFeatures++;
+}
+  }
+  return Priority + MaxFMVPriority * NumFeatures;

jroelofs wrote:

I'm not sure it does that correctly: `simd+dotprod` is weighted higher than 
`sme` with this algorithm purely because it has more features.

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


[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-15 Thread Paul Kirth via cfe-commits

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


[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-15 Thread Paul Kirth via cfe-commits

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


[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-15 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,113 @@
+//===--- Mustache.h -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Implementation of the Mustache templating language supports version 1.4.2
+// currently relies on llvm::json::Value for data input
+// see the Mustache spec for more information
+// (https://mustache.github.io/mustache.5.html).
+//
+// Current Features Supported:
+// - Variables
+// - Sections
+// - Inverted Sections
+// - Partials
+// - Comments
+// - Lambdas
+// - Unescaped Variables
+//
+// Features Not Supported:
+// - Set Delimiter
+// - Blocks
+// - Parents
+// - Dynamic Names
+//
+// The Template class is container class outputs the Mustache template string
+// and is main class for users. It stores all the lambdas and the ASTNode Tree.
+// When the Template is instantiated it tokenize the Template String and
+// creates a vector of Tokens. Then it calls a basic recursive descent parser
+// to construct the ASTNode Tree. The ASTNodes are all stored in an arena
+// allocator which is freed once the template class goes out of scope
+//
+// Usage:
+// \code
+//   // Creating a simple template and rendering it
+//   auto Template = Template("Hello, {{name}}!");
+//   Value Data = {{"name", "World"}};
+//   StringRef Rendered = Template.render(Data);
+//   // Rendered == "Hello, World!"
+//
+//   // Creating a template with a partial and rendering it
+//   auto Template = Template("{{>partial}}");
+//   Template.registerPartial("partial", "Hello, {{name}}!");
+//   Value Data = {{"name", "World"}};
+//   StringRef Rendered = Template.render(Data);
+//   // Rendered == "Hello, World!"
+//
+//   // Creating a template with a lambda and rendering it
+//   auto Template = Template("{{#lambda}}Hello, {{name}}!{{/lambda}}");
+//   Template.registerLambda("lambda", []() { return true; });
+//   Value Data = {{"name", "World"}};
+//   StringRef Rendered = Template.render(Data);
+//   // Rendered == "Hello, World!"
+// \endcode
+//
+//===--===//
+
+#ifndef LLVM_SUPPORT_MUSTACHE
+#define LLVM_SUPPORT_MUSTACHE
+
+#include "Error.h"
+#include "llvm/ADT/StringMap.h"
+#include "llvm/Support/Allocator.h"
+#include "llvm/Support/JSON.h"
+#include "llvm/Support/StringSaver.h"
+#include 
+
+namespace llvm {
+namespace mustache {
+
+using Accessor = SmallVector>;
+using Lambda = std::function;
+using SectionLambda = std::function;
+
+class ASTNode;
+
+// A Template represents the container for the AST and the partials
+// and Lambdas that are registered with it.
+class Template {
+public:
+  Template(StringRef TemplateStr);
+
+  void render(llvm::json::Value &Data, llvm::raw_ostream &OS);
+
+  void registerPartial(StringRef Name, StringRef Partial);
+
+  void registerLambda(StringRef Name, Lambda Lambda);
+
+  void registerLambda(StringRef Name, SectionLambda Lambda);
+
+  // By default the Mustache Spec Specifies that HTML special characters
+  // should be escaped. This function allows the user to specify which
+  // characters should be escaped.
+  void registerEscape(DenseMap Escapes);
+
+private:
+  std::string Output;
+  StringMap Partials;
+  StringMap Lambdas;
+  StringMap SectionLambdas;
+  DenseMap Escapes;
+  // The allocator for the ASTNode Tree
+  llvm::BumpPtrAllocator Allocator;
+  // Allocator for each render call resets after each render
+  llvm::BumpPtrAllocator LocalAllocator;

ilovepi wrote:

```suggestion
  llvm::BumpPtrAllocator RenderAllocator;
```
Same idea as above.

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


[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-15 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,724 @@
+//===-- Mustache.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/Mustache.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::json;
+
+namespace llvm {
+namespace mustache {
+
+class Token {
+public:
+  enum class Type {
+Text,
+Variable,
+Partial,
+SectionOpen,
+SectionClose,
+InvertSectionOpen,
+UnescapeVariable,
+Comment,
+  };
+
+  Token(StringRef Str);
+
+  Token(StringRef RawBody, StringRef Str, char Identifier);
+
+  StringRef getTokenBody() const { return TokenBody; };
+
+  StringRef getRawBody() const { return RawBody; };
+
+  void setTokenBody(StringRef NewBody) { TokenBody = NewBody.str(); };
+
+  Accessor getAccessor() const { return Accessor; };
+
+  Type getType() const { return TokenType; };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  size_t getIndentation() const { return Indentation; };
+
+  static Type getTokenType(char Identifier);
+
+private:
+  size_t Indentation;
+  Type TokenType;
+  // RawBody is the original string that was tokenized
+  std::string RawBody;
+  Accessor Accessor;
+  // TokenBody is the original string with the identifier removed
+  std::string TokenBody;
+};
+
+class ASTNode {
+public:
+  enum Type {
+Root,
+Text,
+Partial,
+Variable,
+UnescapeVariable,
+Section,
+InvertSection,
+  };
+
+  ASTNode() : T(Type::Root), ParentContext(nullptr) {};
+
+  ASTNode(StringRef Body, ASTNode *Parent)
+  : T(Type::Text), Body(Body), Parent(Parent), ParentContext(nullptr) {};
+
+  // Constructor for Section/InvertSection/Variable/UnescapeVariable
+  ASTNode(Type T, Accessor Accessor, ASTNode *Parent)
+  : T(T), Parent(Parent), Children({}), Accessor(Accessor),
+ParentContext(nullptr) {};
+
+  void addChild(ASTNode *Child) { Children.emplace_back(Child); };
+
+  void setBody(StringRef NewBody) { Body = NewBody; };
+
+  void setRawBody(StringRef NewBody) { RawBody = NewBody; };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  void render(const llvm::json::Value &Data, llvm::raw_ostream &OS);
+
+  void setUpNode(llvm::BumpPtrAllocator &Alloc, StringMap &Partials,
+ StringMap &Lambdas,
+ StringMap &SectionLambdas,
+ DenseMap &Escapes);
+
+private:
+  void renderLambdas(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ Lambda &L);
+
+  void renderSectionLambdas(const llvm::json::Value &Contexts,
+llvm::raw_ostream &OS, SectionLambda &L);
+
+  void renderPartial(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ ASTNode *Partial);
+
+  void renderChild(const llvm::json::Value &Context, llvm::raw_ostream &OS);
+
+  const llvm::json::Value *findContext();
+
+  llvm::BumpPtrAllocator *Allocator;
+  StringMap *Partials;
+  StringMap *Lambdas;
+  StringMap *SectionLambdas;
+  DenseMap *Escapes;
+  Type T;
+  size_t Indentation = 0;
+  std::string RawBody;
+  std::string Body;
+  ASTNode *Parent;
+  // TODO: switch implementation to SmallVector
+  std::vector Children;
+  const Accessor Accessor;
+  const llvm::json::Value *ParentContext;
+};
+
+// Custom stream to escape strings
+class EscapeStringStream : public raw_ostream {
+public:
+  explicit EscapeStringStream(llvm::raw_ostream &WrappedStream,
+  DenseMap &Escape)
+  : Escape(Escape), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+for (char C : Data) {
+  auto It = Escape.find(C);
+  if (It != Escape.end())
+WrappedStream << It->getSecond();
+  else
+WrappedStream << C;
+}
+  }
+
+  uint64_t current_pos() const override { return WrappedStream.tell(); }
+
+private:
+  DenseMap &Escape;
+  llvm::raw_ostream &WrappedStream;
+};
+
+// Custom stream to add indentation used to for rendering partials
+class AddIndentationStringStream : public raw_ostream {
+public:
+  explicit AddIndentationStringStream(llvm::raw_ostream &WrappedStream,
+  size_t Indentation)
+  : Indentation(Indentation), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+std::string Indent(Indentation, ' ');
+for (char C : Data) {
+  WrappedStream << C;
+  if (C == '\n')
+

[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-15 Thread Nicolas van Kempen via cfe-commits


@@ -0,0 +1,724 @@
+//===-- Mustache.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/Mustache.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::json;
+
+namespace llvm {
+namespace mustache {
+
+class Token {
+public:
+  enum class Type {
+Text,
+Variable,
+Partial,
+SectionOpen,
+SectionClose,
+InvertSectionOpen,
+UnescapeVariable,
+Comment,
+  };
+
+  Token(StringRef Str);
+
+  Token(StringRef RawBody, StringRef Str, char Identifier);
+
+  StringRef getTokenBody() const { return TokenBody; };
+
+  StringRef getRawBody() const { return RawBody; };
+
+  void setTokenBody(StringRef NewBody) { TokenBody = NewBody.str(); };
+
+  Accessor getAccessor() const { return Accessor; };
+
+  Type getType() const { return TokenType; };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  size_t getIndentation() const { return Indentation; };
+
+  static Type getTokenType(char Identifier);
+
+private:
+  size_t Indentation;
+  Type TokenType;
+  // RawBody is the original string that was tokenized
+  std::string RawBody;
+  Accessor Accessor;
+  // TokenBody is the original string with the identifier removed
+  std::string TokenBody;
+};
+
+class ASTNode {
+public:
+  enum Type {
+Root,
+Text,
+Partial,
+Variable,
+UnescapeVariable,
+Section,
+InvertSection,
+  };
+
+  ASTNode() : T(Type::Root), ParentContext(nullptr) {};
+
+  ASTNode(StringRef Body, ASTNode *Parent)
+  : T(Type::Text), Body(Body), Parent(Parent), ParentContext(nullptr) {};

nicovank wrote:

```suggestion
  ASTNode(std::string Body, ASTNode *Parent)
  : T(Type::Text), Body(std::move(Body)), Parent(Parent), 
ParentContext(nullptr) {};
```

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


[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-15 Thread Nicolas van Kempen via cfe-commits


@@ -0,0 +1,724 @@
+//===-- Mustache.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/Mustache.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::json;
+
+namespace llvm {
+namespace mustache {
+
+class Token {

nicovank wrote:

IMO at least for "short" constructors / functions if not everything, 
implementations can be in the declaration, but if others prefer it this way I 
don't care.

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


[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-15 Thread Nicolas van Kempen via cfe-commits

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


[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-15 Thread Paul Kirth via cfe-commits

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


[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-15 Thread Nicolas van Kempen via cfe-commits


@@ -0,0 +1,724 @@
+//===-- Mustache.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/Mustache.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::json;
+
+namespace llvm {
+namespace mustache {
+
+class Token {
+public:
+  enum class Type {
+Text,
+Variable,
+Partial,
+SectionOpen,
+SectionClose,
+InvertSectionOpen,
+UnescapeVariable,
+Comment,
+  };
+
+  Token(StringRef Str);
+
+  Token(StringRef RawBody, StringRef Str, char Identifier);
+
+  StringRef getTokenBody() const { return TokenBody; };
+
+  StringRef getRawBody() const { return RawBody; };
+
+  void setTokenBody(StringRef NewBody) { TokenBody = NewBody.str(); };
+
+  Accessor getAccessor() const { return Accessor; };
+
+  Type getType() const { return TokenType; };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  size_t getIndentation() const { return Indentation; };
+
+  static Type getTokenType(char Identifier);
+
+private:
+  size_t Indentation;
+  Type TokenType;
+  // RawBody is the original string that was tokenized
+  std::string RawBody;
+  Accessor Accessor;
+  // TokenBody is the original string with the identifier removed
+  std::string TokenBody;
+};
+
+class ASTNode {
+public:
+  enum Type {
+Root,
+Text,
+Partial,
+Variable,
+UnescapeVariable,
+Section,
+InvertSection,
+  };
+
+  ASTNode() : T(Type::Root), ParentContext(nullptr) {};
+
+  ASTNode(StringRef Body, ASTNode *Parent)
+  : T(Type::Text), Body(Body), Parent(Parent), ParentContext(nullptr) {};
+
+  // Constructor for Section/InvertSection/Variable/UnescapeVariable
+  ASTNode(Type T, Accessor Accessor, ASTNode *Parent)
+  : T(T), Parent(Parent), Children({}), Accessor(Accessor),
+ParentContext(nullptr) {};
+
+  void addChild(ASTNode *Child) { Children.emplace_back(Child); };
+
+  void setBody(StringRef NewBody) { Body = NewBody; };
+
+  void setRawBody(StringRef NewBody) { RawBody = NewBody; };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  void render(const llvm::json::Value &Data, llvm::raw_ostream &OS);
+
+  void setUpNode(llvm::BumpPtrAllocator &Alloc, StringMap &Partials,
+ StringMap &Lambdas,
+ StringMap &SectionLambdas,
+ DenseMap &Escapes);
+
+private:
+  void renderLambdas(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ Lambda &L);
+
+  void renderSectionLambdas(const llvm::json::Value &Contexts,
+llvm::raw_ostream &OS, SectionLambda &L);
+
+  void renderPartial(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ ASTNode *Partial);
+
+  void renderChild(const llvm::json::Value &Context, llvm::raw_ostream &OS);
+
+  const llvm::json::Value *findContext();
+
+  llvm::BumpPtrAllocator *Allocator;
+  StringMap *Partials;
+  StringMap *Lambdas;
+  StringMap *SectionLambdas;
+  DenseMap *Escapes;
+  Type T;
+  size_t Indentation = 0;
+  std::string RawBody;
+  std::string Body;
+  ASTNode *Parent;
+  // TODO: switch implementation to SmallVector
+  std::vector Children;
+  const Accessor Accessor;
+  const llvm::json::Value *ParentContext;
+};
+
+// Custom stream to escape strings
+class EscapeStringStream : public raw_ostream {
+public:
+  explicit EscapeStringStream(llvm::raw_ostream &WrappedStream,
+  DenseMap &Escape)
+  : Escape(Escape), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+for (char C : Data) {
+  auto It = Escape.find(C);
+  if (It != Escape.end())
+WrappedStream << It->getSecond();
+  else
+WrappedStream << C;
+}
+  }
+
+  uint64_t current_pos() const override { return WrappedStream.tell(); }
+
+private:
+  DenseMap &Escape;
+  llvm::raw_ostream &WrappedStream;
+};
+
+// Custom stream to add indentation used to for rendering partials
+class AddIndentationStringStream : public raw_ostream {
+public:
+  explicit AddIndentationStringStream(llvm::raw_ostream &WrappedStream,
+  size_t Indentation)
+  : Indentation(Indentation), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+std::string Indent(Indentation, ' ');
+for (char C : Data) {
+  WrappedStream << C;
+  if (C == '\n')
+

[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-15 Thread Nicolas van Kempen via cfe-commits

https://github.com/nicovank commented:

I stopped halfway, but a performance tip to save copies:
If the constructor or method is going to "own" the data: pass by value and move 
(some would recommend two overloads, IMO the extra verbosity is not worth the 
insignificant performance gain).

I wrote [a 
post](https://nvankempen.com/2022/09/13/cpp-when-to-pass-by-value.html) a while 
ago if you ever want more background.

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


[clang] [llvm][ARM] Restore the default to -mstrict-align on Apple firmwares (PR #115546)

2024-11-15 Thread Ahmed Bougacha via cfe-commits

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


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


[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-15 Thread Nicolas van Kempen via cfe-commits


@@ -0,0 +1,724 @@
+//===-- Mustache.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/Mustache.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::json;
+
+namespace llvm {
+namespace mustache {
+
+class Token {
+public:
+  enum class Type {
+Text,
+Variable,
+Partial,
+SectionOpen,
+SectionClose,
+InvertSectionOpen,
+UnescapeVariable,
+Comment,
+  };
+
+  Token(StringRef Str);
+
+  Token(StringRef RawBody, StringRef Str, char Identifier);
+
+  StringRef getTokenBody() const { return TokenBody; };
+
+  StringRef getRawBody() const { return RawBody; };
+
+  void setTokenBody(StringRef NewBody) { TokenBody = NewBody.str(); };
+
+  Accessor getAccessor() const { return Accessor; };
+
+  Type getType() const { return TokenType; };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  size_t getIndentation() const { return Indentation; };
+
+  static Type getTokenType(char Identifier);
+
+private:
+  size_t Indentation;
+  Type TokenType;
+  // RawBody is the original string that was tokenized
+  std::string RawBody;
+  Accessor Accessor;
+  // TokenBody is the original string with the identifier removed
+  std::string TokenBody;
+};
+
+class ASTNode {
+public:
+  enum Type {
+Root,
+Text,
+Partial,
+Variable,
+UnescapeVariable,
+Section,
+InvertSection,
+  };
+
+  ASTNode() : T(Type::Root), ParentContext(nullptr) {};
+
+  ASTNode(StringRef Body, ASTNode *Parent)
+  : T(Type::Text), Body(Body), Parent(Parent), ParentContext(nullptr) {};
+
+  // Constructor for Section/InvertSection/Variable/UnescapeVariable
+  ASTNode(Type T, Accessor Accessor, ASTNode *Parent)
+  : T(T), Parent(Parent), Children({}), Accessor(Accessor),
+ParentContext(nullptr) {};
+
+  void addChild(ASTNode *Child) { Children.emplace_back(Child); };
+
+  void setBody(StringRef NewBody) { Body = NewBody; };
+
+  void setRawBody(StringRef NewBody) { RawBody = NewBody; };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  void render(const llvm::json::Value &Data, llvm::raw_ostream &OS);
+
+  void setUpNode(llvm::BumpPtrAllocator &Alloc, StringMap &Partials,
+ StringMap &Lambdas,
+ StringMap &SectionLambdas,
+ DenseMap &Escapes);
+
+private:
+  void renderLambdas(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ Lambda &L);
+
+  void renderSectionLambdas(const llvm::json::Value &Contexts,
+llvm::raw_ostream &OS, SectionLambda &L);
+
+  void renderPartial(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ ASTNode *Partial);
+
+  void renderChild(const llvm::json::Value &Context, llvm::raw_ostream &OS);
+
+  const llvm::json::Value *findContext();
+
+  llvm::BumpPtrAllocator *Allocator;
+  StringMap *Partials;
+  StringMap *Lambdas;
+  StringMap *SectionLambdas;
+  DenseMap *Escapes;
+  Type T;
+  size_t Indentation = 0;
+  std::string RawBody;
+  std::string Body;
+  ASTNode *Parent;
+  // TODO: switch implementation to SmallVector
+  std::vector Children;
+  const Accessor Accessor;
+  const llvm::json::Value *ParentContext;
+};
+
+// Custom stream to escape strings
+class EscapeStringStream : public raw_ostream {
+public:
+  explicit EscapeStringStream(llvm::raw_ostream &WrappedStream,
+  DenseMap &Escape)
+  : Escape(Escape), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+for (char C : Data) {
+  auto It = Escape.find(C);
+  if (It != Escape.end())
+WrappedStream << It->getSecond();
+  else
+WrappedStream << C;
+}
+  }
+
+  uint64_t current_pos() const override { return WrappedStream.tell(); }
+
+private:
+  DenseMap &Escape;
+  llvm::raw_ostream &WrappedStream;
+};
+
+// Custom stream to add indentation used to for rendering partials
+class AddIndentationStringStream : public raw_ostream {
+public:
+  explicit AddIndentationStringStream(llvm::raw_ostream &WrappedStream,
+  size_t Indentation)
+  : Indentation(Indentation), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+std::string Indent(Indentation, ' ');
+for (char C : Data) {
+  WrappedStream << C;
+  if (C == '\n')
+

[clang] [llvm][ARM] Restore the default to -mstrict-align on Apple firmwares (PR #115546)

2024-11-15 Thread Jon Roelofs via cfe-commits

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


[clang] 4b50ec4 - [Clang] Avoid Using `byval` for `ndrange_t` when emitting `__enqueue_kernel_basic` (#116435)

2024-11-15 Thread via cfe-commits

Author: Shilei Tian
Date: 2024-11-15T16:54:29-05:00
New Revision: 4b50ec43d03d9ba9b43edd9a4743951f6498b964

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

LOG: [Clang] Avoid Using `byval` for `ndrange_t` when emitting 
`__enqueue_kernel_basic` (#116435)

AMDGPU disabled the use of `byval` for struct argument passing in commit
d77c620. However, when emitting `__enqueue_kernel_basic`, Clang still
adds the
`byval` attribute by default. Emitting the `byval` attribute by default
in this
context doesn’t seem like a good idea, as argument-passing conventions
are
highly target-dependent, and assumptions here could lead to issues. This
PR
removes the addition of the `byval` attribute, aligning the behavior
with other
`__enqueue_kernel_*` functions.

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
clang/test/CodeGenOpenCL/cl20-device-side-enqueue-attributes.cl
clang/test/CodeGenOpenCL/cl20-device-side-enqueue.cl

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e03cb6e8c3c861..0f29dbb9509296 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5985,15 +5985,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   llvm::Value *Block =
   Builder.CreatePointerCast(Info.BlockArg, GenericVoidPtrTy);
 
-  AttrBuilder B(Builder.getContext());
-  B.addByValAttr(NDRangeL.getAddress().getElementType());
-  llvm::AttributeList ByValAttrSet =
-  llvm::AttributeList::get(CGM.getModule().getContext(), 3U, B);
-
-  auto RTCall =
-  EmitRuntimeCall(CGM.CreateRuntimeFunction(FTy, Name, ByValAttrSet),
-  {Queue, Flags, Range, Kernel, Block});
-  RTCall->setAttributes(ByValAttrSet);
+  auto RTCall = EmitRuntimeCall(CGM.CreateRuntimeFunction(FTy, Name),
+{Queue, Flags, Range, Kernel, Block});
   return RValue::get(RTCall);
 }
 assert(NumArgs >= 5 && "Invalid enqueue_kernel signature");

diff  --git a/clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl 
b/clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
index 2fc7f9a24b8874..62b5661da9dbd8 100644
--- a/clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
+++ b/clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
@@ -140,7 +140,7 @@ kernel void test_target_features_kernel(global int *i) {
 // NOCPU-NEXT:[[BLOCK_CAPTURED1:%.*]] = getelementptr inbounds nuw <{ i32, 
i32, ptr, ptr addrspace(1), i8 }>, ptr [[BLOCK_ASCAST]], i32 0, i32 4
 // NOCPU-NEXT:[[TMP3:%.*]] = load i8, ptr [[B_ADDR_ASCAST]], align 1
 // NOCPU-NEXT:store i8 [[TMP3]], ptr [[BLOCK_CAPTURED1]], align 8
-// NOCPU-NEXT:[[TMP4:%.*]] = call i32 @__enqueue_kernel_basic(ptr 
addrspace(1) [[TMP0]], i32 [[TMP1]], ptr byval([[STRUCT_NDRANGE_T]]) 
[[TMP_ASCAST]], ptr @__test_block_invoke_kernel, ptr [[BLOCK_ASCAST]])
+// NOCPU-NEXT:[[TMP4:%.*]] = call i32 @__enqueue_kernel_basic(ptr 
addrspace(1) [[TMP0]], i32 [[TMP1]], ptr [[TMP_ASCAST]], ptr 
@__test_block_invoke_kernel, ptr [[BLOCK_ASCAST]])
 // NOCPU-NEXT:[[TMP5:%.*]] = load ptr addrspace(1), ptr 
[[DEFAULT_QUEUE_ASCAST]], align 8
 // NOCPU-NEXT:[[TMP6:%.*]] = load i32, ptr [[FLAGS_ASCAST]], align 4
 // NOCPU-NEXT:call void @llvm.memcpy.p0.p0.i64(ptr align 4 
[[TMP2_ASCAST]], ptr align 4 [[NDRANGE_ASCAST]], i64 4, i1 false)
@@ -162,7 +162,7 @@ kernel void test_target_features_kernel(global int *i) {
 // NOCPU-NEXT:[[BLOCK_CAPTURED10:%.*]] = getelementptr inbounds nuw <{ 
i32, i32, ptr, ptr addrspace(1), ptr addrspace(1), i64, i8 }>, ptr 
[[BLOCK3_ASCAST]], i32 0, i32 5
 // NOCPU-NEXT:[[TMP10:%.*]] = load i64, ptr [[D_ADDR_ASCAST]], align 8
 // NOCPU-NEXT:store i64 [[TMP10]], ptr [[BLOCK_CAPTURED10]], align 8
-// NOCPU-NEXT:[[TMP11:%.*]] = call i32 @__enqueue_kernel_basic(ptr 
addrspace(1) [[TMP5]], i32 [[TMP6]], ptr byval([[STRUCT_NDRANGE_T]]) 
[[TMP2_ASCAST]], ptr @__test_block_invoke_2_kernel, ptr [[BLOCK3_ASCAST]])
+// NOCPU-NEXT:[[TMP11:%.*]] = call i32 @__enqueue_kernel_basic(ptr 
addrspace(1) [[TMP5]], i32 [[TMP6]], ptr [[TMP2_ASCAST]], ptr 
@__test_block_invoke_2_kernel, ptr [[BLOCK3_ASCAST]])
 // NOCPU-NEXT:[[TMP12:%.*]] = load ptr addrspace(1), ptr 
[[DEFAULT_QUEUE_ASCAST]], align 8
 // NOCPU-NEXT:[[TMP13:%.*]] = load i32, ptr [[FLAGS_ASCAST]], align 4
 // NOCPU-NEXT:call void @llvm.memcpy.p0.p0.i64(ptr align 4 
[[TMP11_ASCAST]], ptr align 4 [[NDRANGE_ASCAST]], i64 4, i1 false)
@@ -204,7 +204,7 @@ kernel void test_target_features_kernel(global int *i) {
 // NOCPU-NEXT:[[TMP23:%.*]] = load i32, ptr [[FLAGS_ASCAST]], align 4
 // NOCPU-NEXT:call void @llvm.memcpy.p0.p0.i64(p

[clang] Remove device override for operator new when the C++ standard >= 26 (PR #114056)

2024-11-15 Thread Artem Belevich via cfe-commits

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


[clang] 9204eba - Remove device override for operator new when the C++ standard >= 26 (#114056)

2024-11-15 Thread via cfe-commits

Author: Ognyan Mirev
Date: 2024-11-15T13:53:24-08:00
New Revision: 9204eba9121546c0e9c16d8a75d5735bad9dee16

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

LOG: Remove device override for operator new when the C++ standard >= 26 
(#114056)

Related to https://github.com/llvm/llvm-project/issues/114048

Added: 


Modified: 
clang/lib/Headers/cuda_wrappers/new

Removed: 




diff  --git a/clang/lib/Headers/cuda_wrappers/new 
b/clang/lib/Headers/cuda_wrappers/new
index d5fb3b7011de96..9d3e31690e677c 100644
--- a/clang/lib/Headers/cuda_wrappers/new
+++ b/clang/lib/Headers/cuda_wrappers/new
@@ -91,12 +91,14 @@ __device__ inline void operator delete[](void *ptr,
 #endif
 
 // Device overrides for placement new and delete.
+#if !(_LIBCPP_STD_VER >= 26 || __cpp_lib_constexpr_new >= 202406L)
 __device__ inline void *operator new(__SIZE_TYPE__, void *__ptr) CUDA_NOEXCEPT 
{
   return __ptr;
 }
 __device__ inline void *operator new[](__SIZE_TYPE__, void *__ptr) 
CUDA_NOEXCEPT {
   return __ptr;
 }
+#endif
 __device__ inline void operator delete(void *, void *) CUDA_NOEXCEPT {}
 __device__ inline void operator delete[](void *, void *) CUDA_NOEXCEPT {}
 



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


[clang] 34ebfab - [llvm][ARM] Restore the default to -mstrict-align on Apple firmwares (#115546)

2024-11-15 Thread via cfe-commits

Author: Jon Roelofs
Date: 2024-11-15T13:54:21-08:00
New Revision: 34ebfabc34476b73a3d65d3bd046c35ffab411c4

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

LOG: [llvm][ARM] Restore the default to -mstrict-align on Apple firmwares 
(#115546)

This is a partial revert of e314622f204a01ffeda59cbe046dd403b01f8b74

rdar://139237593

Added: 


Modified: 
clang/lib/Driver/ToolChains/Arch/ARM.cpp
clang/test/Driver/arm-alignment.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp 
b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
index 0489911ecd9dee..e6ee2317a160cc 100644
--- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -908,6 +908,10 @@ llvm::ARM::FPUKind arm::getARMTargetFeatures(const Driver 
&D,
   if (VersionNum < 6 ||
   Triple.getSubArch() == llvm::Triple::SubArchType::ARMSubArch_v6m)
 Features.push_back("+strict-align");
+} else if (Triple.getVendor() == llvm::Triple::Apple &&
+   Triple.isOSBinFormatMachO()) {
+  // Firmwares on Apple platforms are strict-align by default.
+  Features.push_back("+strict-align");
 } else if (VersionNum < 7 ||
Triple.getSubArch() ==
llvm::Triple::SubArchType::ARMSubArch_v6m ||

diff  --git a/clang/test/Driver/arm-alignment.c 
b/clang/test/Driver/arm-alignment.c
index 8c915477af9aff..b714f80a07dc12 100644
--- a/clang/test/Driver/arm-alignment.c
+++ b/clang/test/Driver/arm-alignment.c
@@ -37,6 +37,12 @@
 // RUN: %clang -target thumbv8m.base-none-gnueabi -### %s 2> %t
 // RUN: FileCheck --check-prefix CHECK-ALIGNED-ARM <%t %s
 
+// RUN: %clang -target armv7em-apple-unknown-macho -mthumb -### %s 2> %t
+// RUN: FileCheck --check-prefix CHECK-ALIGNED-ARM <%t %s
+
+// RUN: %clang -target armv7em-apple-darwin -mthumb -### %s 2> %t
+// RUN: FileCheck --check-prefix CHECK-ALIGNED-ARM <%t %s
+
 // RUN: %clang --target=aarch64 -munaligned-access -### %s 2> %t
 // RUN: FileCheck --check-prefix=CHECK-UNALIGNED-AARCH64 < %t %s
 



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


[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-15 Thread Nicolas van Kempen via cfe-commits


@@ -0,0 +1,724 @@
+//===-- Mustache.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/Mustache.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::json;
+
+namespace llvm {
+namespace mustache {
+
+class Token {
+public:
+  enum class Type {
+Text,
+Variable,
+Partial,
+SectionOpen,
+SectionClose,
+InvertSectionOpen,
+UnescapeVariable,
+Comment,
+  };
+
+  Token(StringRef Str);
+
+  Token(StringRef RawBody, StringRef Str, char Identifier);

nicovank wrote:

```suggestion
  Token(std::string RawBody, std::string Str, char Identifier);
```

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


[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-15 Thread Nicolas van Kempen via cfe-commits


@@ -0,0 +1,724 @@
+//===-- Mustache.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/Mustache.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::json;
+
+namespace llvm {
+namespace mustache {
+
+class Token {
+public:
+  enum class Type {
+Text,
+Variable,
+Partial,
+SectionOpen,
+SectionClose,
+InvertSectionOpen,
+UnescapeVariable,
+Comment,
+  };
+
+  Token(StringRef Str);
+
+  Token(StringRef RawBody, StringRef Str, char Identifier);
+
+  StringRef getTokenBody() const { return TokenBody; };
+
+  StringRef getRawBody() const { return RawBody; };
+
+  void setTokenBody(StringRef NewBody) { TokenBody = NewBody.str(); };

nicovank wrote:

```suggestion
  void setTokenBody(std::string NewBody) { TokenBody = std::move(NewBody); };
```

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


[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-15 Thread Nicolas van Kempen via cfe-commits


@@ -0,0 +1,724 @@
+//===-- Mustache.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/Mustache.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::json;
+
+namespace llvm {
+namespace mustache {
+
+class Token {
+public:
+  enum class Type {
+Text,
+Variable,
+Partial,
+SectionOpen,
+SectionClose,
+InvertSectionOpen,
+UnescapeVariable,
+Comment,
+  };
+
+  Token(StringRef Str);
+
+  Token(StringRef RawBody, StringRef Str, char Identifier);
+
+  StringRef getTokenBody() const { return TokenBody; };
+
+  StringRef getRawBody() const { return RawBody; };
+
+  void setTokenBody(StringRef NewBody) { TokenBody = NewBody.str(); };
+
+  Accessor getAccessor() const { return Accessor; };
+
+  Type getType() const { return TokenType; };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  size_t getIndentation() const { return Indentation; };
+
+  static Type getTokenType(char Identifier);
+
+private:
+  size_t Indentation;
+  Type TokenType;
+  // RawBody is the original string that was tokenized
+  std::string RawBody;
+  Accessor Accessor;
+  // TokenBody is the original string with the identifier removed
+  std::string TokenBody;
+};
+
+class ASTNode {
+public:
+  enum Type {
+Root,
+Text,
+Partial,
+Variable,
+UnescapeVariable,
+Section,
+InvertSection,
+  };
+
+  ASTNode() : T(Type::Root), ParentContext(nullptr) {};
+
+  ASTNode(StringRef Body, ASTNode *Parent)
+  : T(Type::Text), Body(Body), Parent(Parent), ParentContext(nullptr) {};
+
+  // Constructor for Section/InvertSection/Variable/UnescapeVariable
+  ASTNode(Type T, Accessor Accessor, ASTNode *Parent)
+  : T(T), Parent(Parent), Children({}), Accessor(Accessor),
+ParentContext(nullptr) {};
+
+  void addChild(ASTNode *Child) { Children.emplace_back(Child); };
+
+  void setBody(StringRef NewBody) { Body = NewBody; };
+
+  void setRawBody(StringRef NewBody) { RawBody = NewBody; };

nicovank wrote:

```suggestion
  void setRawBody(std::string NewBody) { RawBody = std::move(NewBody); };
```

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


[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-15 Thread Nicolas van Kempen via cfe-commits


@@ -0,0 +1,724 @@
+//===-- Mustache.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/Mustache.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::json;
+
+namespace llvm {
+namespace mustache {
+
+class Token {
+public:
+  enum class Type {
+Text,
+Variable,
+Partial,
+SectionOpen,
+SectionClose,
+InvertSectionOpen,
+UnescapeVariable,
+Comment,
+  };
+
+  Token(StringRef Str);
+
+  Token(StringRef RawBody, StringRef Str, char Identifier);
+
+  StringRef getTokenBody() const { return TokenBody; };
+
+  StringRef getRawBody() const { return RawBody; };
+
+  void setTokenBody(StringRef NewBody) { TokenBody = NewBody.str(); };
+
+  Accessor getAccessor() const { return Accessor; };
+
+  Type getType() const { return TokenType; };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  size_t getIndentation() const { return Indentation; };
+
+  static Type getTokenType(char Identifier);
+
+private:
+  size_t Indentation;
+  Type TokenType;
+  // RawBody is the original string that was tokenized
+  std::string RawBody;
+  Accessor Accessor;
+  // TokenBody is the original string with the identifier removed
+  std::string TokenBody;
+};
+
+class ASTNode {
+public:
+  enum Type {
+Root,
+Text,
+Partial,
+Variable,
+UnescapeVariable,
+Section,
+InvertSection,
+  };
+
+  ASTNode() : T(Type::Root), ParentContext(nullptr) {};
+
+  ASTNode(StringRef Body, ASTNode *Parent)
+  : T(Type::Text), Body(Body), Parent(Parent), ParentContext(nullptr) {};
+
+  // Constructor for Section/InvertSection/Variable/UnescapeVariable
+  ASTNode(Type T, Accessor Accessor, ASTNode *Parent)
+  : T(T), Parent(Parent), Children({}), Accessor(Accessor),
+ParentContext(nullptr) {};
+
+  void addChild(ASTNode *Child) { Children.emplace_back(Child); };
+
+  void setBody(StringRef NewBody) { Body = NewBody; };
+
+  void setRawBody(StringRef NewBody) { RawBody = NewBody; };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  void render(const llvm::json::Value &Data, llvm::raw_ostream &OS);
+
+  void setUpNode(llvm::BumpPtrAllocator &Alloc, StringMap &Partials,
+ StringMap &Lambdas,
+ StringMap &SectionLambdas,
+ DenseMap &Escapes);
+
+private:
+  void renderLambdas(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ Lambda &L);
+
+  void renderSectionLambdas(const llvm::json::Value &Contexts,
+llvm::raw_ostream &OS, SectionLambda &L);
+
+  void renderPartial(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ ASTNode *Partial);
+
+  void renderChild(const llvm::json::Value &Context, llvm::raw_ostream &OS);
+
+  const llvm::json::Value *findContext();
+
+  llvm::BumpPtrAllocator *Allocator;
+  StringMap *Partials;
+  StringMap *Lambdas;
+  StringMap *SectionLambdas;
+  DenseMap *Escapes;
+  Type T;
+  size_t Indentation = 0;
+  std::string RawBody;
+  std::string Body;
+  ASTNode *Parent;
+  // TODO: switch implementation to SmallVector
+  std::vector Children;
+  const Accessor Accessor;
+  const llvm::json::Value *ParentContext;
+};
+
+// Custom stream to escape strings
+class EscapeStringStream : public raw_ostream {
+public:
+  explicit EscapeStringStream(llvm::raw_ostream &WrappedStream,
+  DenseMap &Escape)
+  : Escape(Escape), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+for (char C : Data) {
+  auto It = Escape.find(C);
+  if (It != Escape.end())
+WrappedStream << It->getSecond();
+  else
+WrappedStream << C;
+}
+  }
+
+  uint64_t current_pos() const override { return WrappedStream.tell(); }
+
+private:
+  DenseMap &Escape;
+  llvm::raw_ostream &WrappedStream;
+};
+
+// Custom stream to add indentation used to for rendering partials
+class AddIndentationStringStream : public raw_ostream {
+public:
+  explicit AddIndentationStringStream(llvm::raw_ostream &WrappedStream,
+  size_t Indentation)
+  : Indentation(Indentation), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+std::string Indent(Indentation, ' ');
+for (char C : Data) {
+  WrappedStream << C;
+  if (C == '\n')
+

[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-15 Thread Nicolas van Kempen via cfe-commits


@@ -0,0 +1,724 @@
+//===-- Mustache.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/Mustache.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::json;
+
+namespace llvm {
+namespace mustache {
+
+class Token {
+public:
+  enum class Type {
+Text,
+Variable,
+Partial,
+SectionOpen,
+SectionClose,
+InvertSectionOpen,
+UnescapeVariable,
+Comment,
+  };
+
+  Token(StringRef Str);
+
+  Token(StringRef RawBody, StringRef Str, char Identifier);
+
+  StringRef getTokenBody() const { return TokenBody; };
+
+  StringRef getRawBody() const { return RawBody; };
+
+  void setTokenBody(StringRef NewBody) { TokenBody = NewBody.str(); };
+
+  Accessor getAccessor() const { return Accessor; };
+
+  Type getType() const { return TokenType; };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  size_t getIndentation() const { return Indentation; };
+
+  static Type getTokenType(char Identifier);

nicovank wrote:

```suggestion
 Type getTokenType(char Identifier);
```

I might have missed discussion but I don't think this needs to be static.

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


[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-15 Thread Nicolas van Kempen via cfe-commits

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


[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-15 Thread via cfe-commits


@@ -0,0 +1,724 @@
+//===-- Mustache.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/Mustache.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::json;
+
+namespace llvm {
+namespace mustache {
+
+class Token {
+public:
+  enum class Type {
+Text,
+Variable,
+Partial,
+SectionOpen,
+SectionClose,
+InvertSectionOpen,
+UnescapeVariable,
+Comment,
+  };
+
+  Token(StringRef Str);
+
+  Token(StringRef RawBody, StringRef Str, char Identifier);
+
+  StringRef getTokenBody() const { return TokenBody; };
+
+  StringRef getRawBody() const { return RawBody; };
+
+  void setTokenBody(StringRef NewBody) { TokenBody = NewBody.str(); };
+
+  Accessor getAccessor() const { return Accessor; };
+
+  Type getType() const { return TokenType; };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  size_t getIndentation() const { return Indentation; };
+
+  static Type getTokenType(char Identifier);
+
+private:
+  size_t Indentation;
+  Type TokenType;
+  // RawBody is the original string that was tokenized
+  std::string RawBody;
+  Accessor Accessor;
+  // TokenBody is the original string with the identifier removed
+  std::string TokenBody;
+};
+
+class ASTNode {
+public:
+  enum Type {
+Root,
+Text,
+Partial,
+Variable,
+UnescapeVariable,
+Section,
+InvertSection,
+  };
+
+  ASTNode() : T(Type::Root), ParentContext(nullptr) {};
+
+  ASTNode(StringRef Body, ASTNode *Parent)
+  : T(Type::Text), Body(Body), Parent(Parent), ParentContext(nullptr) {};
+
+  // Constructor for Section/InvertSection/Variable/UnescapeVariable
+  ASTNode(Type T, Accessor Accessor, ASTNode *Parent)
+  : T(T), Parent(Parent), Children({}), Accessor(Accessor),
+ParentContext(nullptr) {};
+
+  void addChild(ASTNode *Child) { Children.emplace_back(Child); };
+
+  void setBody(StringRef NewBody) { Body = NewBody; };
+
+  void setRawBody(StringRef NewBody) { RawBody = NewBody; };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  void render(const llvm::json::Value &Data, llvm::raw_ostream &OS);
+
+  void setUpNode(llvm::BumpPtrAllocator &Alloc, StringMap &Partials,
+ StringMap &Lambdas,
+ StringMap &SectionLambdas,
+ DenseMap &Escapes);
+
+private:
+  void renderLambdas(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ Lambda &L);
+
+  void renderSectionLambdas(const llvm::json::Value &Contexts,
+llvm::raw_ostream &OS, SectionLambda &L);
+
+  void renderPartial(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ ASTNode *Partial);
+
+  void renderChild(const llvm::json::Value &Context, llvm::raw_ostream &OS);
+
+  const llvm::json::Value *findContext();
+
+  llvm::BumpPtrAllocator *Allocator;
+  StringMap *Partials;
+  StringMap *Lambdas;
+  StringMap *SectionLambdas;
+  DenseMap *Escapes;
+  Type T;
+  size_t Indentation = 0;
+  std::string RawBody;
+  std::string Body;
+  ASTNode *Parent;
+  // TODO: switch implementation to SmallVector
+  std::vector Children;
+  const Accessor Accessor;
+  const llvm::json::Value *ParentContext;
+};
+
+// Custom stream to escape strings
+class EscapeStringStream : public raw_ostream {
+public:
+  explicit EscapeStringStream(llvm::raw_ostream &WrappedStream,
+  DenseMap &Escape)
+  : Escape(Escape), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+for (char C : Data) {
+  auto It = Escape.find(C);
+  if (It != Escape.end())
+WrappedStream << It->getSecond();
+  else
+WrappedStream << C;
+}
+  }
+
+  uint64_t current_pos() const override { return WrappedStream.tell(); }
+
+private:
+  DenseMap &Escape;
+  llvm::raw_ostream &WrappedStream;
+};
+
+// Custom stream to add indentation used to for rendering partials
+class AddIndentationStringStream : public raw_ostream {
+public:
+  explicit AddIndentationStringStream(llvm::raw_ostream &WrappedStream,
+  size_t Indentation)
+  : Indentation(Indentation), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+std::string Indent(Indentation, ' ');
+for (char C : Data) {
+  WrappedStream << C;
+  if (C == '\n')
+

[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-15 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,724 @@
+//===-- Mustache.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/Mustache.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::json;
+
+namespace llvm {
+namespace mustache {
+
+class Token {
+public:
+  enum class Type {
+Text,
+Variable,
+Partial,
+SectionOpen,
+SectionClose,
+InvertSectionOpen,
+UnescapeVariable,
+Comment,
+  };
+
+  Token(StringRef Str);
+
+  Token(StringRef RawBody, StringRef Str, char Identifier);
+
+  StringRef getTokenBody() const { return TokenBody; };
+
+  StringRef getRawBody() const { return RawBody; };
+
+  void setTokenBody(StringRef NewBody) { TokenBody = NewBody.str(); };
+
+  Accessor getAccessor() const { return Accessor; };
+
+  Type getType() const { return TokenType; };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  size_t getIndentation() const { return Indentation; };
+
+  static Type getTokenType(char Identifier);

ilovepi wrote:

There was a conversation earlier about using static for free functions in TU, 
per https://llvm.org/docs/CodingStandards.html#anonymous-namespaces. I don't 
think this falls under that discussion though.

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


[clang] Remove device override for operator new when the C++ standard >= 26 (PR #114056)

2024-11-15 Thread via cfe-commits

github-actions[bot] wrote:



@OgnianM Congratulations on having your first Pull Request (PR) merged into the 
LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested by our [build bots](https://lab.llvm.org/buildbot/). If there is a 
problem with a build, you may receive a report in an email or a comment on this 
PR.

Please check whether problems have been caused by your change specifically, as 
the builds can include changes from many authors. It is not uncommon for your 
change to be included in a build that fails due to someone else's changes, or 
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself. This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


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


[clang] [llvm] [HLSL] Adding Flatten and Branch if attributes (PR #116331)

2024-11-15 Thread via cfe-commits

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


[clang-tools-extra] [clang-tidy][modernize-use-starts-ends-with] Fix minor mistake in error message (PR #116132)

2024-11-15 Thread Julian Schmidt via cfe-commits




5chmidti wrote:

Please also add a test for the case you're doing this for, i.e., one without 
`[!=]= 0`, so that these don't regress in the future

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


[clang] Disable LIBCXX_INCLUDE_BENCHMARKS in Fuchsia cmake (PR #116446)

2024-11-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-libcxx

Author: Caslyn Tonelli (Caslyn)


Changes



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


2 Files Affected:

- (modified) clang/cmake/caches/Fuchsia-stage2.cmake (+1) 
- (modified) clang/cmake/caches/Fuchsia.cmake (+1) 


``diff
diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 5af98c7b3b3fba..3318b1b0e17903 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -31,6 +31,7 @@ set(LLVM_STATIC_LINK_CXX_STDLIB ON CACHE BOOL "")
 set(LLVM_USE_RELATIVE_PATHS_IN_FILES ON CACHE BOOL "")
 set(LLDB_ENABLE_CURSES OFF CACHE BOOL "")
 set(LLDB_ENABLE_LIBEDIT OFF CACHE BOOL "")
+set(LIBCXX_INCLUDE_BENCHMARKS OFF CACHE BOOL "")
 
 if(WIN32)
   set(FUCHSIA_DISABLE_DRIVER_BUILD ON)
diff --git a/clang/cmake/caches/Fuchsia.cmake b/clang/cmake/caches/Fuchsia.cmake
index 2d2dcb9ae6798d..6cfeb564ad24b4 100644
--- a/clang/cmake/caches/Fuchsia.cmake
+++ b/clang/cmake/caches/Fuchsia.cmake
@@ -21,6 +21,7 @@ set(LIBC_HDRGEN_ONLY ON CACHE BOOL "")
 set(LLVM_USE_RELATIVE_PATHS_IN_FILES ON CACHE BOOL "")
 set(LLDB_ENABLE_CURSES OFF CACHE BOOL "")
 set(LLDB_ENABLE_LIBEDIT OFF CACHE BOOL "")
+set(LIBCXX_INCLUDE_BENCHMARKS OFF CACHE BOOL "")
 
 # Passthrough stage1 flags to stage1.
 set(_FUCHSIA_BOOTSTRAP_PASSTHROUGH

``




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


[clang] [Clang][Parser] Make 'T...[N]' within a function parameter a valid pack expansion prior to C++2c (PR #116332)

2024-11-15 Thread Eli Friedman via cfe-commits


@@ -58,8 +58,9 @@ void b(T[] ...);
 
 template
 void c(T ... []); // expected-error {{expected expression}} \

efriedma-quic wrote:

To be clear, it's not a "pack-index-specifier" even in C++26: it doesn't match 
the grammar because there's no constant-expression, and the constant-expression 
is not optional in the pack-index-specifier grammar.

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


[clang] [llvm] [HLSL] Implement WaveActiveAnyTrue intrinsic (PR #115902)

2024-11-15 Thread Ashley Coleman via cfe-commits


@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -finclude-default-header -fnative-half-type -triple \
+// RUN:   dxil-pc-shadermodel6.3-compute %s -emit-llvm -disable-llvm-passes -o 
- | \
+// RUN:   FileCheck %s --check-prefixes=CHECK,CHECK-DXIL
+// RUN: %clang_cc1 -finclude-default-header -fnative-half-type -triple \
+// RUN:   spirv-pc-vulkan-compute %s -emit-llvm -disable-llvm-passes -o - | \
+// RUN:   FileCheck %s --check-prefixes=CHECK,CHECK-SPIRV
+
+// Test basic lowering to runtime function call for int values.
+
+// CHECK-LABEL: test

V-FEXrt wrote:

ah yeah, good point

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


[clang] [llvm] [HLSL] Implement WaveActiveAnyTrue intrinsic (PR #115902)

2024-11-15 Thread Ashley Coleman via cfe-commits

https://github.com/V-FEXrt updated 
https://github.com/llvm/llvm-project/pull/115902

>From 845256b2ed971a4e42f7f871e8b51e711486261a Mon Sep 17 00:00:00 2001
From: Ashley Coleman 
Date: Mon, 11 Nov 2024 16:34:23 -0700
Subject: [PATCH 01/12] [HLSL] Implement WaveActiveAnyTrue intrinsic

---
 clang/include/clang/Basic/Builtins.td |  6 +
 clang/lib/CodeGen/CGBuiltin.cpp   | 13 ++
 clang/lib/CodeGen/CGHLSLRuntime.h |  1 +
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  |  9 +++
 clang/lib/Sema/SemaHLSL.cpp   |  6 +
 .../builtins/WaveActiveAnyTrue.hlsl   | 17 +
 .../BuiltIns/WaveActiveAnyTrue-errors.hlsl| 21 
 llvm/include/llvm/IR/IntrinsicsDirectX.td |  1 +
 llvm/include/llvm/IR/IntrinsicsSPIRV.td   |  1 +
 llvm/lib/Target/DirectX/DXIL.td   | 10 
 .../Target/SPIRV/SPIRVInstructionSelector.cpp | 24 +++
 .../test/CodeGen/DirectX/WaveActiveAnyTrue.ll | 10 
 .../hlsl-intrinsics/WaveActiveAnyTrue.ll  | 17 +
 13 files changed, 136 insertions(+)
 create mode 100644 clang/test/CodeGenHLSL/builtins/WaveActiveAnyTrue.hlsl
 create mode 100644 clang/test/SemaHLSL/BuiltIns/WaveActiveAnyTrue-errors.hlsl
 create mode 100644 llvm/test/CodeGen/DirectX/WaveActiveAnyTrue.ll
 create mode 100644 llvm/test/CodeGen/SPIRV/hlsl-intrinsics/WaveActiveAnyTrue.ll

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 9bd67e0cefebc3..496b6739724295 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4744,6 +4744,12 @@ def HLSLAny : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "bool(...)";
 }
 
+def HLSLWaveActiveAnyTrue : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_wave_active_any_true"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "bool(bool)";
+}
+
 def HLSLWaveActiveCountBits : LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_wave_active_count_bits"];
   let Attributes = [NoThrow, Const];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 65d7f5c54a1913..c4a6a9abee63cc 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18960,6 +18960,19 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
 /*ReturnType=*/Op0->getType(), CGM.getHLSLRuntime().getStepIntrinsic(),
 ArrayRef{Op0, Op1}, nullptr, "hlsl.step");
   }
+  case Builtin::BI__builtin_hlsl_wave_active_any_true: {
+// Assert Op->getType() == Bool
+
+// FIXME: PR Question: Can this be simpler? Looks like Int1Ty isn't  
predefined
+IntegerType* Int1Ty = 
llvm::Type::getInt1Ty(CGM.getTypes().getLLVMContext());
+Value *Op = EmitScalarExpr(E->getArg(0));
+assert(Op->getType() == Int1Ty && "wave_active_any_true operand must be a 
bool");
+
+// FIXME: PR Question: Re Style SingleRef vs {SingleRef} vs 
ArrayRef{SingleRef}
+llvm::FunctionType *FT = llvm::FunctionType::get(Int1Ty, {Int1Ty}, 
/*isVarArg=*/false);
+llvm::StringRef Name = 
Intrinsic::getName(CGM.getHLSLRuntime().getWaveActiveAnyTrueIntrinsic());
+return EmitRuntimeCall(CGM.CreateRuntimeFunction(FT, Name, {}, 
/*Local=*/false, /*AssumeConvergent=*/true), {Op}, "hlsl.wave.activeanytrue");
+  }
   case Builtin::BI__builtin_hlsl_wave_get_lane_index: {
 // We don't define a SPIR-V intrinsic, instead it is a SPIR-V built-in
 // defined in SPIRVBuiltins.td. So instead we manually get the matching 
name
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index cd533cad84e9fb..c3b689ea44fcb8 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -89,6 +89,7 @@ class CGHLSLRuntime {
   GENERATE_HLSL_INTRINSIC_FUNCTION(FDot, fdot)
   GENERATE_HLSL_INTRINSIC_FUNCTION(SDot, sdot)
   GENERATE_HLSL_INTRINSIC_FUNCTION(UDot, udot)
+  GENERATE_HLSL_INTRINSIC_FUNCTION(WaveActiveAnyTrue, wave_activeanytrue)
   GENERATE_HLSL_INTRINSIC_FUNCTION(WaveIsFirstLane, wave_is_first_lane)
   GENERATE_HLSL_INTRINSIC_FUNCTION(WaveReadLaneAt, wave_readlane)
 
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 8ade4b27f360fb..90991e95d6565a 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -2096,6 +2096,15 @@ float4 trunc(float4);
 // Wave* builtins
 
//===--===//
 
+/// \brief Returns true if the expression is true in any active lane in the
+/// current wave.
+///
+/// \param Val The boolean expression to evaluate.
+/// \return True if the expression is true in any lane.
+_HLSL_AVAILABILITY(shadermodel, 6.0)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_any_true)
+__attribute__((convergent)) bool WaveActiveAnyTrue(bool Val);
+
 /// \brief Counts the number of boolean variables which eval

[clang] [llvm] [NFC][clang][FMV][TargetInfo] Refactor API for FMV feature priority. (PR #116257)

2024-11-15 Thread Jon Roelofs via cfe-commits


@@ -48,6 +48,19 @@ std::optional 
AArch64::ArchInfo::findBySubArch(StringRef SubA
   return {};
 }
 
+unsigned AArch64::getFMVPriority(ArrayRef Features) {
+  constexpr unsigned MaxFMVPriority = 1000;
+  unsigned Priority = 0;
+  unsigned NumFeatures = 0;
+  for (StringRef Feature : Features) {
+if (auto Ext = parseFMVExtension(Feature)) {
+  Priority = std::max(Priority, Ext->Priority);
+  NumFeatures++;
+}
+  }
+  return Priority + MaxFMVPriority * NumFeatures;

jroelofs wrote:

I don't understand the algorithm here. This seems like sorts resolvees first by 
how many conditions they've got, and _then_ by the highest priority of each in 
that group. But what we actually need is a total order on two sets. Maybe the 
API should be shaped more like a comparison operator on feature sets, rather 
than a serialized index constructed from members's priorities?

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


[clang] [llvm] [NFC][clang][FMV][TargetInfo] Refactor API for FMV feature priority. (PR #116257)

2024-11-15 Thread Alexandros Lamprineas via cfe-commits


@@ -218,8 +218,8 @@ void ABIInfo::appendAttributeMangling(StringRef AttrStr,
 // only have "+" prefixes here.
 assert(LHS.starts_with("+") && RHS.starts_with("+") &&
"Features should always have a prefix.");
-return TI.multiVersionSortPriority(LHS.substr(1)) >
-   TI.multiVersionSortPriority(RHS.substr(1));
+return TI.getFMVPriority({LHS.substr(1)}) >
+   TI.getFMVPriority({RHS.substr(1)});

labrinea wrote:

Perhaps there is value in adding another hook `getFMVPriority(StringRef 
feature)` which would be called on each feature of `ArrayRef 
Features` from the other hook, in order to avoid this inefficiency here of 
having to create a single element smallvector each time?

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


[clang] [llvm] [NFC][clang][FMV][TargetInfo] Refactor API for FMV feature priority. (PR #116257)

2024-11-15 Thread Erich Keane via cfe-commits


@@ -1363,19 +1363,28 @@ static llvm::X86::ProcessorFeatures 
getFeature(StringRef Name) {
   // correct, so it asserts if the value is out of range.
 }
 
-unsigned X86TargetInfo::multiVersionSortPriority(StringRef Name) const {
-  // Valid CPUs have a 'key feature' that compares just better than its key
-  // feature.
-  using namespace llvm::X86;
-  CPUKind Kind = parseArchX86(Name);
-  if (Kind != CK_None) {
-ProcessorFeatures KeyFeature = getKeyFeature(Kind);
-return (getFeaturePriority(KeyFeature) << 1) + 1;
-  }
-
-  // Now we know we have a feature, so get its priority and shift it a few so
-  // that we have sufficient room for the CPUs (above).
-  return getFeaturePriority(getFeature(Name)) << 1;
+unsigned X86TargetInfo::getFMVPriority(ArrayRef Features) const {
+  auto getPriority = [this](StringRef Feature) -> unsigned {
+if (Feature.empty())
+  return 0;
+
+// Valid CPUs have a 'key feature' that compares just better than its key
+// feature.
+using namespace llvm::X86;
+CPUKind Kind = parseArchX86(Feature);
+if (Kind != CK_None) {
+  ProcessorFeatures KeyFeature = getKeyFeature(Kind);
+  return (getFeaturePriority(KeyFeature) << 1) + 1;
+}
+// Now we know we have a feature, so get its priority and shift it a few so
+// that we have sufficient room for the CPUs (above).
+return getFeaturePriority(getFeature(Feature)) << 1;
+  };
+
+  unsigned Priority = 0;
+  for (StringRef Feature : Features)
+Priority = std::max(Priority, getPriority(Feature));

erichkeane wrote:

I don't think 'max' does the right thing here, does it?  The whole point was to 
put together a mask representation that matches the `cpuid` call (Best we 
could!) that is the collection of all the features.  That way you could have a 
list of features and have them be differentiated (that is, some of the FMV 
supports just a list of features, and we want to be able to differentiate 
between `high-feature, low-feature` and `high-feature, lower-feature`.

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


[clang] [llvm] [NFC][clang][FMV][TargetInfo] Refactor API for FMV feature priority. (PR #116257)

2024-11-15 Thread Jon Roelofs via cfe-commits


@@ -48,6 +48,19 @@ std::optional 
AArch64::ArchInfo::findBySubArch(StringRef SubA
   return {};
 }
 
+unsigned AArch64::getFMVPriority(ArrayRef Features) {
+  constexpr unsigned MaxFMVPriority = 1000;
+  unsigned Priority = 0;
+  unsigned NumFeatures = 0;
+  for (StringRef Feature : Features) {
+if (auto Ext = parseFMVExtension(Feature)) {
+  Priority = std::max(Priority, Ext->Priority);
+  NumFeatures++;
+}
+  }
+  return Priority + MaxFMVPriority * NumFeatures;

jroelofs wrote:

(and yeah, I see that this is just a pure refactor, so it's not "new", but 
still...)

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


[clang-tools-extra] Extend bugprone-use-after-move check to handle std::optional::reset() and std::any::reset() (PR #114255)

2024-11-15 Thread Congcong Cai via cfe-commits

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


[clang] [Clang] Add 'gpuintrin.h' to the release notes (PR #116410)

2024-11-15 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 updated 
https://github.com/llvm/llvm-project/pull/116410

>From 81f3f902a7ee16251ebf1d7b0b6aa86e11e4dc89 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Fri, 15 Nov 2024 11:03:21 -0600
Subject: [PATCH] [Clang] Add 'gpuintrin.h' to the release notes

---
 clang/docs/ReleaseNotes.rst | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ba582160cf9920..f9ab34a3f3cf3d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -710,6 +710,17 @@ Target Specific Changes
 AMDGPU Support
 ^^
 
+- Added headers ``gpuintrin.h`` and ``amdgpuintrin.h`` that contains common
+  definitions for GPU builtin functions. This header can be included for 
OpenMP,
+  CUDA, HIP, OpenCL, and C/C++.
+
+NVPTX Support
+^^
+
+- Added headers ``gpuintrin.h`` and ``nvptxintrin.h`` that contains common
+  definitions for GPU builtin functions. This header can be included for 
OpenMP,
+  CUDA, HIP, OpenCL, and C/C++.
+
 X86 Support
 ^^^
 

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


[clang] [clang][FMV] Fix crash with cpu_specific attribute. (PR #115762)

2024-11-15 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea updated 
https://github.com/llvm/llvm-project/pull/115762

>From aff962d795e56f7b41af44860feb77e656091b78 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Mon, 11 Nov 2024 20:10:01 +
Subject: [PATCH 1/3] [clang][FMV] Fix crash with cpu_specific attribute.

Raised here https://github.com/llvm/llvm-project/issues/115299.

The commit a2d3099 introduced `replaceDeclarationWith`, but it
shouldn't be called by the fallthrough code which handles the
cpu_specific attribute.
---
 clang/lib/CodeGen/CodeGenModule.cpp   |  2 --
 clang/test/CodeGen/attr-cpuspecific.c | 12 ++--
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index ba376f9ecfacde..27b1ccb8137356 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4597,8 +4597,6 @@ llvm::Constant 
*CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
   assert(isa(Resolver) &&
  "Resolver should be created for the first time");
   SetCommonAttributes(FD, cast(Resolver));
-  if (ResolverGV)
-replaceDeclarationWith(ResolverGV, Resolver);
   return Resolver;
 }
 
diff --git a/clang/test/CodeGen/attr-cpuspecific.c 
b/clang/test/CodeGen/attr-cpuspecific.c
index 628892d5809b4e..91f6c9e9e06b88 100644
--- a/clang/test/CodeGen/attr-cpuspecific.c
+++ b/clang/test/CodeGen/attr-cpuspecific.c
@@ -114,8 +114,8 @@ void ThreeVersionsSameAttr(void){}
 // CHECK: define {{.*}}void @ThreeVersionsSameAttr.Z() #[[K]]
 
 ATTR(cpu_specific(knl))
-void CpuSpecificNoDispatch(void) {}
-// CHECK: define {{.*}}void @CpuSpecificNoDispatch.Z() #[[K:[0-9]+]]
+void CpuSpecificNoDispatch(void (*f)(void)) {}
+// CHECK: define {{.*}}void @CpuSpecificNoDispatch.Z(ptr noundef %f) 
#[[K:[0-9]+]]
 
 ATTR(cpu_dispatch(knl))
 void OrderDispatchUsageSpecific(void);
@@ -151,9 +151,9 @@ void usages(void) {
   ThreeVersionsSameAttr();
   // LINUX: @ThreeVersionsSameAttr.ifunc()
   // WINDOWS: @ThreeVersionsSameAttr()
-  CpuSpecificNoDispatch();
-  // LINUX: @CpuSpecificNoDispatch.ifunc()
-  // WINDOWS: @CpuSpecificNoDispatch()
+  CpuSpecificNoDispatch((void (*)(void))CpuSpecificNoDispatch);
+  // LINUX: @CpuSpecificNoDispatch.ifunc(ptr noundef 
@CpuSpecificNoDispatch.ifunc)
+  // WINDOWS: @CpuSpecificNoDispatch(ptr noundef @CpuSpecificNoDispatch)
   OrderDispatchUsageSpecific();
   // LINUX: @OrderDispatchUsageSpecific.ifunc()
   // WINDOWS: @OrderDispatchUsageSpecific()
@@ -162,7 +162,7 @@ void usages(void) {
   // WINDOWS: @OrderSpecificUsageDispatch()
 }
 
-// LINUX: declare void @CpuSpecificNoDispatch.ifunc()
+// LINUX: declare void @CpuSpecificNoDispatch.ifunc(ptr)
 
 // has an extra config to emit!
 ATTR(cpu_dispatch(ivybridge, knl, atom))

>From 7e61a41da7f2bc58b320f88f767db8312ccc1e1a Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Fri, 15 Nov 2024 15:14:11 +
Subject: [PATCH 2/3] changes from last revision:

* changed the condition for early exit
* assert that the first lookup returned null if you are at the fallthrough
---
 clang/lib/CodeGen/CodeGenModule.cpp | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 27b1ccb8137356..f0f5f52e0eecab 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4554,6 +4554,9 @@ llvm::Constant 
*CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
 ResolverName += ".resolver";
   }
 
+  bool ShouldReturnIFunc =
+  getTarget().supportsIFunc() && !FD->isCPUSpecificMultiVersion();
+
   // If the resolver has already been created, just return it. This lookup may
   // yield a function declaration instead of a resolver on AArch64. That is
   // because we didn't know whether a resolver will be generated when we first
@@ -4561,8 +4564,7 @@ llvm::Constant 
*CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
   // targets which support ifuncs should not return here unless we actually
   // found an ifunc.
   llvm::GlobalValue *ResolverGV = GetGlobalValue(ResolverName);
-  if (ResolverGV &&
-  (isa(ResolverGV) || !getTarget().supportsIFunc()))
+  if (ResolverGV && (isa(ResolverGV) || !ShouldReturnIFunc))
 return ResolverGV;
 
   const CGFunctionInfo &FI = getTypes().arrangeGlobalDeclaration(GD);
@@ -4575,7 +4577,7 @@ llvm::Constant 
*CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
 
   // For cpu_specific, don't create an ifunc yet because we don't know if the
   // cpu_dispatch will be emitted in this translation unit.
-  if (getTarget().supportsIFunc() && !FD->isCPUSpecificMultiVersion()) {
+  if (ShouldReturnIFunc) {
 unsigned AS = getTypes().getTargetAddressSpace(FD->getType());
 llvm::Type *ResolverType =
 llvm::FunctionType::get(llvm::PointerType::get(DeclTy, AS), false);
@@ -4594,7 +4596,7 @@ llvm::Constant 
*CodeGenModule::GetOrCreateMulti

  1   2   3   4   5   >