[clang] [FixIt] Improve Source Ranges and Fix-It Hints for Unused Lambda Captures #106445 (PR #117953)

2024-11-27 Thread via cfe-commits

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


[clang] [Serialization] Downgrade error to warning for inconsistent language flags (PR #117840)

2024-11-27 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

> > I don't think the discussion here has run its course
> > #115416
> 
> Yeah, I had explicitly asked for a review from @Bigcheese before that landed, 
> so I was surprised to see that get merged.

I misread it. I thought it wasn't message to me. It would be clear if you ask 
me for waiting more time for @Bigcheese 

> 
> > I don't think we should force users for our too conservative decisions. As 
> > I said there are many false positive error messages which doesn't affect 
> > the process actually.
> 
> False positive _error_ diagnostics? Warnings can have false positives; errors 
> are not allowed to and that suggests we have some serious issues elsewhere to 
> address first.

Yes. This was my point. Maybe I didn't make it clear. All the `LANGOPT` in 
https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/LangOptions.def
 now are not allowed to be inconsistent in different TUs when importing. But 
actually some of these flags won't affect things. We changed some of them, 
e.g., VisibilityMode 
(https://github.com/llvm/llvm-project/blob/700d9ac9ef82fa5aa6b2972e8656ab5055a90d15/clang/include/clang/Basic/LangOptions.def#L380-L381).
 But giving the amount of options, there must be a lot of too-conservative 
`LANGOPT`.  

> 
> > I feel it is really wishful thinking to ban this and hope we can be in a 
> > more safe world. I think it may only stop more people using modules and 
> > change nothing else. Again, please give users a chance to choose what they 
> > like.
> 
> Maybe I'm misunderstanding something but that sounds like the exact opposite 
> of how we usually operate. We typically do aim for improved safety and if 
> that means people don't use modules as much, that's fine -- it's better for 
> us to be too restrictive and then relax those restrictions in the future than 
> to be too permissive and have to support that forever due to users relying on 
> it.

Maybe the above paragraph can explain  it better. The point is false-positive 
diagnostics. And I fully agree safe is good and ODR violation is bad. I just 
thought we can transfer the right to the users. People who want it can have 
`-Werror` or `-Werror=`. People who don't want it can have `-Wno-error=`. And 
if people use `-Wno-`. They get what they get. I don't think we need to teach 
users on this topic. And I feel it is not good to drag other users leg by 
saying "we're considering the safety of the last kind of people".


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


[clang] [clang] Don't warn if the capturing object is also temporary. (PR #117733)

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

usx95 wrote:

I considered this during implementation. This is a little controversial.

It is possible that the temporary capturing object uses the captured entity in 
its destructor. In principle, we can always detect the order of destructions of 
the temporaries and choose to suppress cases when captured temporary outlives 
capturing temporary. But it would be a very confusing behaviour for the user, 
eg: switching order of params suppresses the warning.

I would be in favour of not doing this and always diagnosing this for 
simplicity until we see a strong need or practical false positives. WDYT ? 


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


[clang] [libcxx] [C++20] [Modules] Convert '-fexperimental-modules-reduced-bmi' to '-fmodules-reduced-bmi' (PR #114382)

2024-11-27 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

Oh, I didn't notice libcxx will test with clang17 and clang18 too. Where we 
didn't introduce reduced bmi.  We can't use `-Wno-missing-reduced-bmi` since it 
won't be recognized by clang17 and clang18.

@ldionne @mordante do you think how can we proceed on this?

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


[clang] [llvm] [LoongArch] Support sc.q instruction for 128bit cmpxchg operation (PR #116771)

2024-11-27 Thread via cfe-commits

https://github.com/tangaac updated 
https://github.com/llvm/llvm-project/pull/116771

>From ee422d26ad2695d34b0bf471f6d4fa2c3bef8ca8 Mon Sep 17 00:00:00 2001
From: tangaac 
Date: Tue, 19 Nov 2024 17:43:31 +0800
Subject: [PATCH] [LoongArch] Support sc.q instruction for 128bit cmpxchg
 operation

---
 clang/include/clang/Driver/Options.td |   4 +
 clang/lib/Basic/Targets/LoongArch.cpp |   7 +-
 clang/lib/Basic/Targets/LoongArch.h   |   2 +
 .../lib/Driver/ToolChains/Arch/LoongArch.cpp  |   8 +
 clang/test/Driver/loongarch-march.c   |   8 +-
 clang/test/Driver/loongarch-mscq.c|  30 ++
 clang/test/Preprocessor/init-loongarch.c  |  31 +-
 .../TargetParser/LoongArchTargetParser.def|   3 +-
 .../llvm/TargetParser/LoongArchTargetParser.h |   3 +
 llvm/lib/Target/LoongArch/LoongArch.td|   9 +-
 .../LoongArchExpandAtomicPseudoInsts.cpp  | 107 +++
 .../LoongArch/LoongArchISelLowering.cpp   |  46 +++
 .../Target/LoongArch/LoongArchInstrInfo.td|  14 +
 .../TargetParser/LoongArchTargetParser.cpp|   1 +
 .../ir-instruction/atomic-cmpxchg-128.ll  | 287 ++
 15 files changed, 542 insertions(+), 18 deletions(-)
 create mode 100644 clang/test/Driver/loongarch-mscq.c
 create mode 100644 
llvm/test/CodeGen/LoongArch/ir-instruction/atomic-cmpxchg-128.ll

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 808f089914c9bb..96cef360bd5251 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5425,6 +5425,10 @@ def mdiv32 : Flag<["-"], "mdiv32">, 
Group,
   HelpText<"Use div.w[u] and mod.w[u] instructions with input not 
sign-extended.">;
 def mno_div32 : Flag<["-"], "mno-div32">, Group,
   HelpText<"Do not use div.w[u] and mod.w[u] instructions with input not 
sign-extended.">;
+def mscq : Flag<["-"], "mscq">, Group,
+  HelpText<"Enable sc.q instruction.">;
+def mno_scq : Flag<["-"], "mno-scq">, Group,
+  HelpText<"Disable sc.q instruction.">;
 def mannotate_tablejump : Flag<["-"], "mannotate-tablejump">, 
Group,
   HelpText<"Enable annotate table jump instruction to correlate it with the 
jump table.">;
 def mno_annotate_tablejump : Flag<["-"], "mno-annotate-tablejump">, 
Group,
diff --git a/clang/lib/Basic/Targets/LoongArch.cpp 
b/clang/lib/Basic/Targets/LoongArch.cpp
index d36186aa9c2fbf..bb0d0b68cfcb0a 100644
--- a/clang/lib/Basic/Targets/LoongArch.cpp
+++ b/clang/lib/Basic/Targets/LoongArch.cpp
@@ -206,7 +206,7 @@ void LoongArchTargetInfo::getTargetDefines(const 
LangOptions &Opts,
   // arch feature set will be used to include all sub-features belonging to
   // the V1.1 ISA version.
   if (HasFeatureFrecipe && HasFeatureLAM_BH && HasFeatureLAMCAS &&
-  HasFeatureLD_SEQ_SA && HasFeatureDiv32)
+  HasFeatureLD_SEQ_SA && HasFeatureDiv32 && HasFeatureSCQ)
 Builder.defineMacro("__loongarch_arch",
 Twine('"') + "la64v1.1" + Twine('"'));
   else
@@ -249,6 +249,9 @@ void LoongArchTargetInfo::getTargetDefines(const 
LangOptions &Opts,
   if (HasFeatureDiv32)
 Builder.defineMacro("__loongarch_div32", Twine(1));
 
+  if (HasFeatureSCQ)
+Builder.defineMacro("__loongarch_scq", Twine(1));
+
   StringRef ABI = getABI();
   if (ABI == "lp64d" || ABI == "lp64f" || ABI == "lp64s")
 Builder.defineMacro("__loongarch_lp64");
@@ -333,6 +336,8 @@ bool LoongArchTargetInfo::handleTargetFeatures(
   HasFeatureLD_SEQ_SA = true;
 else if (Feature == "+div32")
   HasFeatureDiv32 = true;
+else if (Feature == "+scq")
+  HasFeatureSCQ = true;
   }
   return true;
 }
diff --git a/clang/lib/Basic/Targets/LoongArch.h 
b/clang/lib/Basic/Targets/LoongArch.h
index abaa05aa42d438..5c34c84ff8d3e8 100644
--- a/clang/lib/Basic/Targets/LoongArch.h
+++ b/clang/lib/Basic/Targets/LoongArch.h
@@ -34,6 +34,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public 
TargetInfo {
   bool HasFeatureLAMCAS;
   bool HasFeatureLD_SEQ_SA;
   bool HasFeatureDiv32;
+  bool HasFeatureSCQ;
 
 public:
   LoongArchTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
@@ -47,6 +48,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public 
TargetInfo {
 HasFeatureLAMCAS = false;
 HasFeatureLD_SEQ_SA = false;
 HasFeatureDiv32 = false;
+HasFeatureSCQ = false;
 LongDoubleWidth = 128;
 LongDoubleAlign = 128;
 LongDoubleFormat = &llvm::APFloat::IEEEquad();
diff --git a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp 
b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
index bbd9397aa2378a..4dd07f25bab0fb 100644
--- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -301,6 +301,14 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
 else
   Features.push_back("-div32");
   }
+
+  // Select scq feature determined by -m[no-]scq.
+  if (const Arg *A = Args.getLastArg(options::OPT_mscq, options::O

[clang] [FixIt] Improve Source Ranges and Fix-It Hints for Unused Lambda Captures (PR #117953)

2024-11-27 Thread via cfe-commits

https://github.com/charan-003 created 
https://github.com/llvm/llvm-project/pull/117953

**Key Changes**
**Enhancements in SemaLambda.cpp:**

Updated the ExplicitCaptureRanges logic to compute more precise source ranges 
for unused lambda captures.

- Fixed the handling of edge cases, including:
- Trailing and leading whitespace in captures.
- Redundant commas.
- Mixed captures (e.g., [=, &a, b]).
- 

**Test Improvements in fixit-unused-lambda-capture.cpp:**

- Added new tests to validate correct Fix-It suggestions for edge cases:
- Redundant commas like [a, , b].
- Leading/trailing whitespace in capture lists.
- Mixed capture styles (e.g., [=, &a]).
- Single and multiple unused captures in different scenarios.

>From b886394f3aca3ea53f2c97d85a8e963d192c122f Mon Sep 17 00:00:00 2001
From: charan-003 <85248228+charan-...@users.noreply.github.com>
Date: Wed, 27 Nov 2024 18:43:38 -0700
Subject: [PATCH 1/2] Update SemaLambda.cpp

This patch refines how Clang handles source ranges for unused lambda captures. 
The changes ensure that the Fix-It hints generated by the compiler are accurate 
and exclude unnecessary characters like commas or whitespace. Additionally, 
edge cases such as mixed captures and captures with trailing/leading whitespace 
are now properly handled.
---
 clang/lib/Sema/SemaLambda.cpp | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index a67c0b2b367d1a..e7417d1a884dcd 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -1164,8 +1164,11 @@ void 
Sema::ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro,
   /*FunctionScopeIndexToStopAtPtr*/ nullptr,
   C->Kind == LCK_StarThis);
   if (!LSI->Captures.empty())
-LSI->ExplicitCaptureRanges[LSI->Captures.size() - 1] = 
C->ExplicitRange;
-  continue;
+  {
+  SourceRange TrimmedRange = Lexer::makeFileCharRange(
+  C->ExplicitRange, SM, LangOpts);
+  LSI->ExplicitCaptureRanges[LSI->Captures.size() - 1] = TrimmedRange;
+  }
 }
 
 assert(C->Id && "missing identifier for capture");
@@ -1329,7 +1332,11 @@ void 
Sema::ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro,
   tryCaptureVariable(Var, C->Loc, Kind, EllipsisLoc);
 }
 if (!LSI->Captures.empty())
-  LSI->ExplicitCaptureRanges[LSI->Captures.size() - 1] = C->ExplicitRange;
+  {
+SourceRange TrimmedRange = Lexer::makeFileCharRange(
+C->ExplicitRange, SM, LangOpts);
+LSI->ExplicitCaptureRanges[LSI->Captures.size() - 1] = TrimmedRange;
+}
   }
   finishLambdaExplicitCaptures(LSI);
   LSI->ContainsUnexpandedParameterPack |= ContainsUnexpandedParameterPack;

>From ccb39521d4e246bb2b1fd2c9f3727d2332b9a6df Mon Sep 17 00:00:00 2001
From: charan-003 <85248228+charan-...@users.noreply.github.com>
Date: Wed, 27 Nov 2024 18:48:37 -0700
Subject: [PATCH 2/2] Update fixit-unused-lambda-capture.cpp

This patch extends the existing test coverage in 
fixit-unused-lambda-capture.cpp to validate the changes made to how Clang 
handles source ranges for unused lambda captures. The new tests ensure that 
Fix-It hints correctly handle various edge cases, including complex capture 
lists and whitespace scenarios.
---
 .../FixIt/fixit-unused-lambda-capture.cpp | 32 +++
 1 file changed, 32 insertions(+)

diff --git a/clang/test/FixIt/fixit-unused-lambda-capture.cpp 
b/clang/test/FixIt/fixit-unused-lambda-capture.cpp
index ce0c78d677099a..ae43d4ebbdf821 100644
--- a/clang/test/FixIt/fixit-unused-lambda-capture.cpp
+++ b/clang/test/FixIt/fixit-unused-lambda-capture.cpp
@@ -66,6 +66,38 @@ void test() {
   // CHECK: [z = (n = i)] {};
   [j,z = (n = i)] {};
   // CHECK: [z = (n = i)] {};
+
+  // New Edge Cases
+
+  // Test 1: Leading and trailing whitespace
+  [i,j] { return i; };
+  // CHECK: [i] { return i; };
+  [i ,j] { return j; };
+  // CHECK: [j] { return j; };
+  [i  ,  j ,  k] { return j + k; };
+  // CHECK: [j,k] { return j + k; };
+
+  // Test 2: Single unused capture
+  [i] {};
+  // CHECK: [] {};
+  [&i] {};
+  // CHECK: [] {};
+
+  // Test 3: Multiple commas
+  [i,,j] { return j; };
+  // CHECK: [j] { return j; };
+  [,i,j,,k] { return k; };
+  // CHECK: [k] { return k; };
+
+  // Test 4: Mixed captures
+  [=, &i, j] { return i; };
+  // CHECK: [&i] { return i; };
+  [&, i] {};
+  // CHECK: [&] {};
+
+  // Test 5: Capture with comments
+  [/*capture*/ i, j] { return j; };
+  // CHECK: [/*capture*/ j] { return j; };
 }
 
 class ThisTest {

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


[clang] [FixIt] Improve Source Ranges and Fix-It Hints for Unused Lambda Captures (PR #117953)

2024-11-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (charan-003)


Changes

**Key Changes**
**Enhancements in SemaLambda.cpp:**

Updated the ExplicitCaptureRanges logic to compute more precise source ranges 
for unused lambda captures.

- Fixed the handling of edge cases, including:
- Trailing and leading whitespace in captures.
- Redundant commas.
- Mixed captures (e.g., [=, &a, b]).
- 

**Test Improvements in fixit-unused-lambda-capture.cpp:**

- Added new tests to validate correct Fix-It suggestions for edge cases:
- Redundant commas like [a, , b].
- Leading/trailing whitespace in capture lists.
- Mixed capture styles (e.g., [=, &a]).
- Single and multiple unused captures in different scenarios.

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaLambda.cpp (+10-3) 
- (modified) clang/test/FixIt/fixit-unused-lambda-capture.cpp (+32) 


``diff
diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index a67c0b2b367d1a..e7417d1a884dcd 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -1164,8 +1164,11 @@ void 
Sema::ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro,
   /*FunctionScopeIndexToStopAtPtr*/ nullptr,
   C->Kind == LCK_StarThis);
   if (!LSI->Captures.empty())
-LSI->ExplicitCaptureRanges[LSI->Captures.size() - 1] = 
C->ExplicitRange;
-  continue;
+  {
+  SourceRange TrimmedRange = Lexer::makeFileCharRange(
+  C->ExplicitRange, SM, LangOpts);
+  LSI->ExplicitCaptureRanges[LSI->Captures.size() - 1] = TrimmedRange;
+  }
 }
 
 assert(C->Id && "missing identifier for capture");
@@ -1329,7 +1332,11 @@ void 
Sema::ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro,
   tryCaptureVariable(Var, C->Loc, Kind, EllipsisLoc);
 }
 if (!LSI->Captures.empty())
-  LSI->ExplicitCaptureRanges[LSI->Captures.size() - 1] = C->ExplicitRange;
+  {
+SourceRange TrimmedRange = Lexer::makeFileCharRange(
+C->ExplicitRange, SM, LangOpts);
+LSI->ExplicitCaptureRanges[LSI->Captures.size() - 1] = TrimmedRange;
+}
   }
   finishLambdaExplicitCaptures(LSI);
   LSI->ContainsUnexpandedParameterPack |= ContainsUnexpandedParameterPack;
diff --git a/clang/test/FixIt/fixit-unused-lambda-capture.cpp 
b/clang/test/FixIt/fixit-unused-lambda-capture.cpp
index ce0c78d677099a..ae43d4ebbdf821 100644
--- a/clang/test/FixIt/fixit-unused-lambda-capture.cpp
+++ b/clang/test/FixIt/fixit-unused-lambda-capture.cpp
@@ -66,6 +66,38 @@ void test() {
   // CHECK: [z = (n = i)] {};
   [j,z = (n = i)] {};
   // CHECK: [z = (n = i)] {};
+
+  // New Edge Cases
+
+  // Test 1: Leading and trailing whitespace
+  [i,j] { return i; };
+  // CHECK: [i] { return i; };
+  [i ,j] { return j; };
+  // CHECK: [j] { return j; };
+  [i  ,  j ,  k] { return j + k; };
+  // CHECK: [j,k] { return j + k; };
+
+  // Test 2: Single unused capture
+  [i] {};
+  // CHECK: [] {};
+  [&i] {};
+  // CHECK: [] {};
+
+  // Test 3: Multiple commas
+  [i,,j] { return j; };
+  // CHECK: [j] { return j; };
+  [,i,j,,k] { return k; };
+  // CHECK: [k] { return k; };
+
+  // Test 4: Mixed captures
+  [=, &i, j] { return i; };
+  // CHECK: [&i] { return i; };
+  [&, i] {};
+  // CHECK: [&] {};
+
+  // Test 5: Capture with comments
+  [/*capture*/ i, j] { return j; };
+  // CHECK: [/*capture*/ j] { return j; };
 }
 
 class ThisTest {

``




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


[clang] [FixIt] Improve Source Ranges and Fix-It Hints for Unused Lambda Captures (PR #117953)

2024-11-27 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write 
permissions for the repository. In which case you can instead tag reviewers by 
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a 
review by "ping"ing the PR by adding a comment “Ping”. The common courtesy 
"ping" rate is once a week. Please remember that you are asking for valuable 
time from other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang] [Driver] Do not add gno-column-info when using sampling PGO (PR #117954)

2024-11-27 Thread Haohai Wen via cfe-commits

https://github.com/HaohaiWen created 
https://github.com/llvm/llvm-project/pull/117954

Column info is important for sampling PGO to generate/load profile file.
On windows, it will be automatically added when using -gdwarf to generate
profile file. It should also be generated when fprofile-sample-use= is used.

>From 2307a8441a97fe5d436945c5826302d3e4c10147 Mon Sep 17 00:00:00 2001
From: Haohai Wen 
Date: Fri, 22 Nov 2024 13:21:24 +0800
Subject: [PATCH] [Driver] Do not add gno-column-info when using sampling PGO

Column info is important for sampling PGO to generate/load profile file.
On windows, it will be automatically added when using -gdwarf to generate
profile file. It should also be generated when fprofile-sample-use= is
used.
---
 clang/lib/Driver/ToolChains/Clang.cpp| 12 ++--
 clang/test/Driver/codeview-column-info.c |  1 +
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 217c1a845f0a47..b6d39a5186b794 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4690,15 +4690,15 @@ renderDebugOptions(const ToolChain &TC, const Driver 
&D, const llvm::Triple &T,
   Args.ClaimAllArgs(options::OPT_g_flags_Group);
 
   // Column info is included by default for everything except SCE and
-  // CodeView. Clang doesn't track end columns, just starting columns, which,
-  // in theory, is fine for CodeView (and PDB).  In practice, however, the
-  // Microsoft debuggers don't handle missing end columns well, and the AIX
-  // debugger DBX also doesn't handle the columns well, so it's better not to
-  // include any column info.
+  // CodeView if not use sampling PGO. Clang doesn't track end columns, just
+  // starting columns, which, in theory, is fine for CodeView (and PDB).  In
+  // practice, however, the Microsoft debuggers don't handle missing end 
columns
+  // well, and the AIX debugger DBX also doesn't handle the columns well, so
+  // it's better not to include any column info.
   if (const Arg *A = Args.getLastArg(options::OPT_gcolumn_info))
 (void)checkDebugInfoOption(A, Args, D, TC);
   if (!Args.hasFlag(options::OPT_gcolumn_info, options::OPT_gno_column_info,
-!EmitCodeView &&
+!(EmitCodeView && !getLastProfileSampleUseArg(Args)) &&
 (DebuggerTuning != llvm::DebuggerKind::SCE &&
  DebuggerTuning != llvm::DebuggerKind::DBX)))
 CmdArgs.push_back("-gno-column-info");
diff --git a/clang/test/Driver/codeview-column-info.c 
b/clang/test/Driver/codeview-column-info.c
index 4cabefac06e648..99b1d1d9f94689 100644
--- a/clang/test/Driver/codeview-column-info.c
+++ b/clang/test/Driver/codeview-column-info.c
@@ -14,5 +14,6 @@
 // CHECK: "-gno-column-info"
 
 // RUN: %clang_cl -### /Z7 -gcolumn-info -- %s 2>&1 | FileCheck 
--check-prefix=COLUMN %s
+// RUN: %clang_cl -### --target=x86_64-windows-msvc /Z7 
/fprofile-sample-use=%S/Inputs/file.prof -- %s 2>&1 | FileCheck 
--check-prefix=COLUMN %s
 
 // COLUMN-NOT: "-gno-column-info"

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


[clang] [Driver] Do not add gno-column-info when using sampling PGO (PR #117954)

2024-11-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Haohai Wen (HaohaiWen)


Changes

Column info is important for sampling PGO to generate/load profile file.
On windows, it will be automatically added when using -gdwarf to generate
profile file. It should also be generated when fprofile-sample-use= is used.

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


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+6-6) 
- (modified) clang/test/Driver/codeview-column-info.c (+1) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 217c1a845f0a47..b6d39a5186b794 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4690,15 +4690,15 @@ renderDebugOptions(const ToolChain &TC, const Driver 
&D, const llvm::Triple &T,
   Args.ClaimAllArgs(options::OPT_g_flags_Group);
 
   // Column info is included by default for everything except SCE and
-  // CodeView. Clang doesn't track end columns, just starting columns, which,
-  // in theory, is fine for CodeView (and PDB).  In practice, however, the
-  // Microsoft debuggers don't handle missing end columns well, and the AIX
-  // debugger DBX also doesn't handle the columns well, so it's better not to
-  // include any column info.
+  // CodeView if not use sampling PGO. Clang doesn't track end columns, just
+  // starting columns, which, in theory, is fine for CodeView (and PDB).  In
+  // practice, however, the Microsoft debuggers don't handle missing end 
columns
+  // well, and the AIX debugger DBX also doesn't handle the columns well, so
+  // it's better not to include any column info.
   if (const Arg *A = Args.getLastArg(options::OPT_gcolumn_info))
 (void)checkDebugInfoOption(A, Args, D, TC);
   if (!Args.hasFlag(options::OPT_gcolumn_info, options::OPT_gno_column_info,
-!EmitCodeView &&
+!(EmitCodeView && !getLastProfileSampleUseArg(Args)) &&
 (DebuggerTuning != llvm::DebuggerKind::SCE &&
  DebuggerTuning != llvm::DebuggerKind::DBX)))
 CmdArgs.push_back("-gno-column-info");
diff --git a/clang/test/Driver/codeview-column-info.c 
b/clang/test/Driver/codeview-column-info.c
index 4cabefac06e648..99b1d1d9f94689 100644
--- a/clang/test/Driver/codeview-column-info.c
+++ b/clang/test/Driver/codeview-column-info.c
@@ -14,5 +14,6 @@
 // CHECK: "-gno-column-info"
 
 // RUN: %clang_cl -### /Z7 -gcolumn-info -- %s 2>&1 | FileCheck 
--check-prefix=COLUMN %s
+// RUN: %clang_cl -### --target=x86_64-windows-msvc /Z7 
/fprofile-sample-use=%S/Inputs/file.prof -- %s 2>&1 | FileCheck 
--check-prefix=COLUMN %s
 
 // COLUMN-NOT: "-gno-column-info"

``




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


[clang] [llvm] [LoongArch] Support sc.q instruction for 128bit cmpxchg operation (PR #116771)

2024-11-27 Thread via cfe-commits

https://github.com/tangaac updated 
https://github.com/llvm/llvm-project/pull/116771

>From ee422d26ad2695d34b0bf471f6d4fa2c3bef8ca8 Mon Sep 17 00:00:00 2001
From: tangaac 
Date: Tue, 19 Nov 2024 17:43:31 +0800
Subject: [PATCH 1/2] [LoongArch] Support sc.q instruction for 128bit cmpxchg
 operation

---
 clang/include/clang/Driver/Options.td |   4 +
 clang/lib/Basic/Targets/LoongArch.cpp |   7 +-
 clang/lib/Basic/Targets/LoongArch.h   |   2 +
 .../lib/Driver/ToolChains/Arch/LoongArch.cpp  |   8 +
 clang/test/Driver/loongarch-march.c   |   8 +-
 clang/test/Driver/loongarch-mscq.c|  30 ++
 clang/test/Preprocessor/init-loongarch.c  |  31 +-
 .../TargetParser/LoongArchTargetParser.def|   3 +-
 .../llvm/TargetParser/LoongArchTargetParser.h |   3 +
 llvm/lib/Target/LoongArch/LoongArch.td|   9 +-
 .../LoongArchExpandAtomicPseudoInsts.cpp  | 107 +++
 .../LoongArch/LoongArchISelLowering.cpp   |  46 +++
 .../Target/LoongArch/LoongArchInstrInfo.td|  14 +
 .../TargetParser/LoongArchTargetParser.cpp|   1 +
 .../ir-instruction/atomic-cmpxchg-128.ll  | 287 ++
 15 files changed, 542 insertions(+), 18 deletions(-)
 create mode 100644 clang/test/Driver/loongarch-mscq.c
 create mode 100644 
llvm/test/CodeGen/LoongArch/ir-instruction/atomic-cmpxchg-128.ll

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 808f089914c9bb..96cef360bd5251 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5425,6 +5425,10 @@ def mdiv32 : Flag<["-"], "mdiv32">, 
Group,
   HelpText<"Use div.w[u] and mod.w[u] instructions with input not 
sign-extended.">;
 def mno_div32 : Flag<["-"], "mno-div32">, Group,
   HelpText<"Do not use div.w[u] and mod.w[u] instructions with input not 
sign-extended.">;
+def mscq : Flag<["-"], "mscq">, Group,
+  HelpText<"Enable sc.q instruction.">;
+def mno_scq : Flag<["-"], "mno-scq">, Group,
+  HelpText<"Disable sc.q instruction.">;
 def mannotate_tablejump : Flag<["-"], "mannotate-tablejump">, 
Group,
   HelpText<"Enable annotate table jump instruction to correlate it with the 
jump table.">;
 def mno_annotate_tablejump : Flag<["-"], "mno-annotate-tablejump">, 
Group,
diff --git a/clang/lib/Basic/Targets/LoongArch.cpp 
b/clang/lib/Basic/Targets/LoongArch.cpp
index d36186aa9c2fbf..bb0d0b68cfcb0a 100644
--- a/clang/lib/Basic/Targets/LoongArch.cpp
+++ b/clang/lib/Basic/Targets/LoongArch.cpp
@@ -206,7 +206,7 @@ void LoongArchTargetInfo::getTargetDefines(const 
LangOptions &Opts,
   // arch feature set will be used to include all sub-features belonging to
   // the V1.1 ISA version.
   if (HasFeatureFrecipe && HasFeatureLAM_BH && HasFeatureLAMCAS &&
-  HasFeatureLD_SEQ_SA && HasFeatureDiv32)
+  HasFeatureLD_SEQ_SA && HasFeatureDiv32 && HasFeatureSCQ)
 Builder.defineMacro("__loongarch_arch",
 Twine('"') + "la64v1.1" + Twine('"'));
   else
@@ -249,6 +249,9 @@ void LoongArchTargetInfo::getTargetDefines(const 
LangOptions &Opts,
   if (HasFeatureDiv32)
 Builder.defineMacro("__loongarch_div32", Twine(1));
 
+  if (HasFeatureSCQ)
+Builder.defineMacro("__loongarch_scq", Twine(1));
+
   StringRef ABI = getABI();
   if (ABI == "lp64d" || ABI == "lp64f" || ABI == "lp64s")
 Builder.defineMacro("__loongarch_lp64");
@@ -333,6 +336,8 @@ bool LoongArchTargetInfo::handleTargetFeatures(
   HasFeatureLD_SEQ_SA = true;
 else if (Feature == "+div32")
   HasFeatureDiv32 = true;
+else if (Feature == "+scq")
+  HasFeatureSCQ = true;
   }
   return true;
 }
diff --git a/clang/lib/Basic/Targets/LoongArch.h 
b/clang/lib/Basic/Targets/LoongArch.h
index abaa05aa42d438..5c34c84ff8d3e8 100644
--- a/clang/lib/Basic/Targets/LoongArch.h
+++ b/clang/lib/Basic/Targets/LoongArch.h
@@ -34,6 +34,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public 
TargetInfo {
   bool HasFeatureLAMCAS;
   bool HasFeatureLD_SEQ_SA;
   bool HasFeatureDiv32;
+  bool HasFeatureSCQ;
 
 public:
   LoongArchTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
@@ -47,6 +48,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public 
TargetInfo {
 HasFeatureLAMCAS = false;
 HasFeatureLD_SEQ_SA = false;
 HasFeatureDiv32 = false;
+HasFeatureSCQ = false;
 LongDoubleWidth = 128;
 LongDoubleAlign = 128;
 LongDoubleFormat = &llvm::APFloat::IEEEquad();
diff --git a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp 
b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
index bbd9397aa2378a..4dd07f25bab0fb 100644
--- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -301,6 +301,14 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
 else
   Features.push_back("-div32");
   }
+
+  // Select scq feature determined by -m[no-]scq.
+  if (const Arg *A = Args.getLastArg(options::OPT_mscq, option

[clang] [llvm] [RISCV] Add Qualcomm uC Xqcicsr (CSR) extension (PR #117169)

2024-11-27 Thread Sudharsan Veeravalli via cfe-commits

https://github.com/svs-quic updated 
https://github.com/llvm/llvm-project/pull/117169

>From 92a3e2e9c44c03093e6050b92b938fd2a0d6886c Mon Sep 17 00:00:00 2001
From: Sudharsan Veeravalli 
Date: Wed, 20 Nov 2024 13:24:07 +0530
Subject: [PATCH 1/4] [RISCV] Add Qualcomm uC Xqcicsr (CSR) extension

The Qualcomm uC Xqcicsr extension adds 2 instructions that can read
and write CSRs.

The current spec can be found at:
https://github.com/quic/riscv-unified-db/releases/latest

This patch adds assembler only support.
---
 .../Driver/print-supported-extensions-riscv.c |  1 +
 llvm/docs/RISCVUsage.rst  |  3 ++
 llvm/docs/ReleaseNotes.md |  3 +-
 .../RISCV/Disassembler/RISCVDisassembler.cpp  |  2 +
 llvm/lib/Target/RISCV/RISCVFeatures.td| 10 +
 llvm/lib/Target/RISCV/RISCVInstrInfo.td   |  1 +
 llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td   | 44 +++
 llvm/lib/TargetParser/RISCVISAInfo.cpp|  4 ++
 llvm/test/CodeGen/RISCV/attributes.ll |  2 +
 llvm/test/MC/RISCV/xqcicsr-invalid.s  | 27 
 llvm/test/MC/RISCV/xqcicsr-valid.s| 19 
 .../TargetParser/RISCVISAInfoTest.cpp |  1 +
 12 files changed, 116 insertions(+), 1 deletion(-)
 create mode 100644 llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td
 create mode 100644 llvm/test/MC/RISCV/xqcicsr-invalid.s
 create mode 100644 llvm/test/MC/RISCV/xqcicsr-valid.s

diff --git a/clang/test/Driver/print-supported-extensions-riscv.c 
b/clang/test/Driver/print-supported-extensions-riscv.c
index 774dc3a4e1e756..a0b93621d2fcdc 100644
--- a/clang/test/Driver/print-supported-extensions-riscv.c
+++ b/clang/test/Driver/print-supported-extensions-riscv.c
@@ -187,6 +187,7 @@
 // CHECK-NEXT: zvkgs0.7   'Zvkgs' (Vector-Scalar GCM 
instructions for Cryptography)
 // CHECK-NEXT: smctr1.0   'Smctr' (Control Transfer 
Records Machine Level)
 // CHECK-NEXT: ssctr1.0   'Ssctr' (Control Transfer 
Records Supervisor Level)
+// CHECK-NEXT: xqcicsr  0.2   'Xqcicsr' (Qualcomm uC CSR 
Extension)
 // CHECK-EMPTY:
 // CHECK-NEXT: Supported Profiles
 // CHECK-NEXT: rva20s64
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 1317221448ea5b..a656ccd00ed482 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -329,6 +329,9 @@ The primary goal of experimental support is to assist in 
the process of ratifica
 ``experimental-smctr``, ``experimental-ssctr``
   LLVM implements the `1.0-rc3 specification 
`__.
 
+``experimental-xqcicsr``
+  LLVM implements the `0.2 extension specification 
`__.
+
 To use an experimental extension from `clang`, you must add 
`-menable-experimental-extensions` to the command line, and specify the exact 
version of the experimental extension you are using.  To use an experimental 
extension with LLVM's internal developer tools (e.g. `llc`, `llvm-objdump`, 
`llvm-mc`), you must prefix the extension name with `experimental-`.  Note that 
you don't need to specify the version with internal tools, and shouldn't 
include the `experimental-` prefix with `clang`.
 
 Vendor Extensions
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index 1ba3672baeed88..89e7c048592f34 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -211,7 +211,8 @@ Changes to the RISC-V Backend
 * `f` and `cf` inline assembly constraints, when using F-/D-/H-in-X extensions,
   will use the relevant GPR rather than FPR. This makes inline assembly 
portable
   between e.g. F and Zfinx code.
-
+* Adds experimental assembler support for the Qualcomm uC 'Xqcicsr` (CSR)
+  extension.
 
 Changes to the WebAssembly Backend
 --
diff --git a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp 
b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
index cf8e337810d83b..e4f7ee323cf20b 100644
--- a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
+++ b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
@@ -682,6 +682,8 @@ DecodeStatus RISCVDisassembler::getInstruction32(MCInst 
&MI, uint64_t &Size,
 "CORE-V SIMD extensions custom opcode table");
   TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXCVbi, DecoderTableXCVbi32,
 "CORE-V Immediate Branching custom opcode table");
+  TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXqcicsr, DecoderTableXqcicsr32,
+"Qualcomm uC CSR custom opcode table");
   TRY_TO_DECODE(true, DecoderTable32, "RISCV32 table");
 
   return MCDisassembler::Fail;
diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td 
b/llvm/lib/Target/RISCV/RISCVFeatures.td
index 3977816ebdd49c..ed87c9604f38b1 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RI

[clang] [llvm] [RISCV] Add Qualcomm uC Xqcicsr (CSR) extension (PR #117169)

2024-11-27 Thread Sudharsan Veeravalli via cfe-commits


@@ -771,6 +771,10 @@ Error RISCVISAInfo::checkDependency() {
   return getIncompatibleError("xwchc", "zcb");
   }
 
+  if (Exts.count("xqcicsr") != 0 && (XLen != 32)) {
+return getError("'xqcicsr' is only supported in 'rv32'");

svs-quic wrote:

Done

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


[clang] [llvm] [RISCV] Add Qualcomm uC Xqcicsr (CSR) extension (PR #117169)

2024-11-27 Thread Sudharsan Veeravalli via cfe-commits


@@ -0,0 +1,19 @@
+# Xqcicsr - Qualcomm uC CSR Extension
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-xqcicsr 
-riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ENC,CHECK-INST %s
+# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+experimental-xqcicsr < %s 
\
+# RUN: | llvm-objdump --mattr=+experimental-xqcicsr -M no-aliases 
--no-print-imm-hex -d - \
+# RUN: | FileCheck -check-prefix=CHECK-INST %s
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-xqcicsr -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ENC,CHECK-INST %s
+# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+experimental-xqcicsr < %s 
\
+# RUN: | llvm-objdump --mattr=+experimental-xqcicsr --no-print-imm-hex -d 
- \
+# RUN: | FileCheck -check-prefix=CHECK-INST %s
+
+# CHECK-INST: qc.csrrwr  a0, t0, s4
+# CHECK-ENC: encoding: [0x73,0x85,0x42,0x8d]
+qc.csrrwr  x10, x5, x20
+
+# CHECK-INST: qc.csrrwri s4, 31, a2
+# CHECK-ENC: encoding: [0x73,0x8a,0xcf,0x8e]
+qc.csrrwri x20, 31, x12

svs-quic wrote:

Done

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


[clang] [llvm] [RISCV] Add stack clash protection (PR #117612)

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


@@ -610,22 +610,134 @@ static MCCFIInstruction createDefCFAOffset(const 
TargetRegisterInfo &TRI,
 Comment.str());
 }
 
+// Allocate stack space and probe it if necessary.
 void RISCVFrameLowering::allocateStack(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MBBI,
-   StackOffset Offset, bool EmitCFI,
-   unsigned CFIIndex) const {
+   MachineFunction &MF, uint64_t Offset,
+   uint64_t RealStackSize, bool EmitCFI,
+   bool NeedProbe,
+   uint64_t ProbeSize) const {
   DebugLoc DL;
   const RISCVRegisterInfo *RI = STI.getRegisterInfo();
   const RISCVInstrInfo *TII = STI.getInstrInfo();
 
-  RI->adjustReg(MBB, MBBI, DL, SPReg, SPReg, Offset, MachineInstr::FrameSetup,
+  // Simply allocate the stack if it's not big enough to require a probe.
+  if (!NeedProbe || Offset <= ProbeSize) {
+RI->adjustReg(MBB, MBBI, DL, SPReg, SPReg, StackOffset::getFixed(-Offset),
+  MachineInstr::FrameSetup, getStackAlign());
+
+if (EmitCFI) {
+  // Emit ".cfi_def_cfa_offset RealStackSize"
+  unsigned CFIIndex = MF.addFrameInst(
+  MCCFIInstruction::cfiDefCfaOffset(nullptr, RealStackSize));
+  BuildMI(MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
+  .addCFIIndex(CFIIndex)
+  .setMIFlag(MachineInstr::FrameSetup);
+}
+
+return;
+  }
+
+  // Unroll the probe loop depending on the number of iterations.
+  if (Offset < ProbeSize * 5) {
+uint64_t CurrentOffset = 0;
+bool IsRV64 = STI.is64Bit();
+while (CurrentOffset + ProbeSize <= Offset) {
+  RI->adjustReg(MBB, MBBI, DL, SPReg, SPReg,
+StackOffset::getFixed(-ProbeSize), 
MachineInstr::FrameSetup,
+getStackAlign());
+  // s[d|w] zero, 0(sp)
+  BuildMI(MBB, MBBI, DL, TII->get(IsRV64 ? RISCV::SD : RISCV::SW))
+  .addReg(RISCV::X0)
+  .addReg(SPReg)
+  .addImm(0)
+  .setMIFlags(MachineInstr::FrameSetup);
+
+  CurrentOffset += ProbeSize;
+  if (EmitCFI) {
+// Emit ".cfi_def_cfa_offset CurrentOffset"
+unsigned CFIIndex = MF.addFrameInst(
+MCCFIInstruction::cfiDefCfaOffset(nullptr, CurrentOffset));
+BuildMI(MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
+.addCFIIndex(CFIIndex)
+.setMIFlag(MachineInstr::FrameSetup);
+  }
+}
+
+uint64_t Residual = Offset - CurrentOffset;
+if (Residual) {
+  RI->adjustReg(MBB, MBBI, DL, SPReg, SPReg,
+StackOffset::getFixed(-Residual), MachineInstr::FrameSetup,
+getStackAlign());
+  if (EmitCFI) {
+// Emit ".cfi_def_cfa_offset Offset"
+unsigned CFIIndex =
+MF.addFrameInst(MCCFIInstruction::cfiDefCfaOffset(nullptr, 
Offset));
+BuildMI(MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
+.addCFIIndex(CFIIndex)
+.setMIFlag(MachineInstr::FrameSetup);
+  }
+}
+
+return;
+  }
+
+  // Emit a variable-length allocation probing loop.
+  uint64_t RoundedSize = (Offset / ProbeSize) * ProbeSize;
+  uint64_t Residual = Offset - RoundedSize;
+
+  Register TargetReg = RISCV::X6;
+  // SUB TargetReg, SP, RoundedSize
+  RI->adjustReg(MBB, MBBI, DL, TargetReg, SPReg,
+StackOffset::getFixed(-RoundedSize), MachineInstr::FrameSetup,
 getStackAlign());
 
   if (EmitCFI) {
-// Emit ".cfi_def_cfa_offset StackSize"
+// Set the CFA register to TargetReg.
+unsigned Reg = STI.getRegisterInfo()->getDwarfRegNum(TargetReg, true);
+unsigned CFIIndex =
+MF.addFrameInst(MCCFIInstruction::cfiDefCfa(nullptr, Reg, 
RoundedSize));
 BuildMI(MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
 .addCFIIndex(CFIIndex)
-.setMIFlag(MachineInstr::FrameSetup);
+.setMIFlags(MachineInstr::FrameSetup);
+  }
+
+  // It will be expanded to a probe loop in `inlineStackProbe`.
+  BuildMI(MBB, MBBI, DL, TII->get(RISCV::PROBED_STACKALLOC))
+  .addReg(SPReg)
+  .addReg(TargetReg);
+
+  if (EmitCFI) {
+// Set the CFA register back to SP.
+unsigned Reg = STI.getRegisterInfo()->getDwarfRegNum(SPReg, true);
+unsigned CFIIndex =
+MF.addFrameInst(MCCFIInstruction::createDefCfaRegister(nullptr, Reg));
+BuildMI(MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
+.addCFIIndex(CFIIndex)
+.setMIFlags(MachineInstr::FrameSetup);
+  }
+
+  if (Residual) {
+RI->adjustReg(MBB, MBBI, DL, SPReg, SPReg, 
StackOffset::getFixed(-Residual),
+  MachineInstr::FrameSetup, getStackAlign());
+if (Residual > ProbeSize) {
+  // s[d|w] zero, 0(sp)
+  bool IsRV64 = STI.hasFeature(

[clang] [llvm] [X86] Enhance kCFI type IDs with a 3-bit arity indicator. (PR #117121)

2024-11-27 Thread Scott Constable via cfe-commits

scottconstable wrote:

This PR is intended to improve security for X86 kernels, as the title suggests. 
I think that we can and should incorporate feedback from the other 
participants, several of whom have recommended that this new behavior should be 
explicitly enabled with a flag, rather than implicitly enabled by examining the 
target triple. So, for example, I could update the PR to introduce a new flag 
such as `-fsanitize-cfi-icall-experimental-arity-x86`. If the community would 
like to adopt a similar approach that is tuned to benefit Arm64 kernels, then 
that approach could be enabled with a different flag.

Flag-based enabling would also help to address the concerns about compiler 
compatibility. For instance, if an x86 kernel is being built with both C and 
Rust code, then Kconfig could check whether the local clang and rustc compilers 
support the KCFI arity enhancement; if one or the other does not support KCFI 
arity then Kconfig would fall back to the default 32-bit hash.

@rcvalle I don't see any evidence that this approach will require a plethora of 
implementations for different arch/ABI combinations. As far as I am aware, the 
vast majority of x86-64 Linux kernel code (including eBPF code) uses the 
standard ABI. Even if some kernel code does not conform to the standard ABI, 
this should not break compatibility with the arity enhancement because the 
arity enhancement's implementation derives the arity tag from the function 
type, not from the ABI. Hence, a valid function call that uses a non-standard 
ABI would still experience a matching KCFI type ID at both the call site and 
the call target. The downside is that call sites/targets with a non-standard 
ABI might be tagged with an inaccurate arity, which could matter if the 
function type's 29-bit hash collides with another function type's 29-bit hash, 
and that other function's arity tag is the same but the two functions' actual 
arities differ. IMO this seems very unlikely.

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


[clang] [compiler-rt] [llvm] [openmp] [PGO][Offload] Profile profraw generation for GPU instrumentation #76587 (PR #93365)

2024-11-27 Thread Joel E. Denny via cfe-commits


@@ -1311,4 +1314,96 @@ COMPILER_RT_VISIBILITY int 
__llvm_profile_set_file_object(FILE *File,
   return 0;
 }
 
+int __llvm_write_custom_profile(const char *Target,
+const __llvm_profile_data *DataBegin,
+const __llvm_profile_data *DataEnd,
+const char *CountersBegin,
+const char *CountersEnd, const char 
*NamesBegin,
+const char *NamesEnd) {
+  int ReturnValue = 0, FilenameLength, TargetLength;
+  char *FilenameBuf, *TargetFilename;
+  const char *Filename;
+
+  /* Save old profile data */
+  FILE *oldFile = getProfileFile();
+
+  // Temporarily suspend getting SIGKILL when the parent exits.
+  int PDeathSig = lprofSuspendSigKill();
+
+  if (lprofProfileDumped() || __llvm_profile_is_continuous_mode_enabled()) {
+PROF_NOTE("Profile data not written to file: %s.\n", "already written");
+if (PDeathSig == 1)
+  lprofRestoreSigKill();
+return 0;
+  }
+
+  /* Get current filename */
+  FilenameLength = getCurFilenameLength();
+  FilenameBuf = (char *)COMPILER_RT_ALLOCA(FilenameLength + 1);
+  Filename = getCurFilename(FilenameBuf, 0);
+
+  /* Check the filename. */
+  if (!Filename) {
+PROF_ERR("Failed to write file : %s\n", "Filename not set");
+if (PDeathSig == 1)
+  lprofRestoreSigKill();
+return -1;
+  }
+
+  /* Allocate new space for our target-specific PGO filename */
+  TargetLength = strlen(Target);
+  TargetFilename =
+  (char *)COMPILER_RT_ALLOCA(FilenameLength + TargetLength + 2);
+
+  /* Prepend "TARGET." to current filename */

jdenny-ornl wrote:

Seems to be fixed now.  Thanks.

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


[clang] [compiler-rt] [llvm] [XRay][RISCV] RISCV support for XRay (PR #117368)

2024-11-27 Thread Min-Yih Hsu via cfe-commits


@@ -57,6 +57,10 @@ static const int16_t cSledLength = 64;
 static const int16_t cSledLength = 8;
 #elif defined(__hexagon__)
 static const int16_t cSledLength = 20;
+#elif SANITIZER_RISCV64
+static const int16_t cSledLength = 76;
+#elif defined(__riscv) && (__riscv_xlen == 32)

mshockwave wrote:

We don't have `SANITIZER_RISCV32` I believe, if that's what you meant

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


[clang] [compiler-rt] [llvm] [openmp] [PGO][Offload] Add GPU profiling flags to driver (PR #94268)

2024-11-27 Thread Ethan Luis McDonough via cfe-commits

EthanLuisMcDonough wrote:

> > > For some codes, I get the following error for a gfx906:
> > > ```
> > > LLVM ERROR: Relocation for CG Profile could not be created: unknown 
> > > relocation name 
> > > ```
> 
> > Not sure if this is still relevant, but I think #114617 should fix this 
> > issue. The ASM builder was trying to create a reloc directive with the kind 
> > `BFD_RELOC_NONE`, which isn't defined in `getFixupKind` for AMDGPU.
> 
> Thanks, it does seem to fix it.
> 
> If possible, would you please keep this PR in sync with PR #93365? That 
> should bring in the above fix and generally help me to review against my use 
> cases.

Sure, I'll sync this branch with my changes in the other PR.

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


[clang] [analyzer] Modernize, improve and promote chroot checker (PR #117791)

2024-11-27 Thread via cfe-commits


@@ -80,19 +88,53 @@ bool ChrootChecker::evalCall(const CallEvent &Call, 
CheckerContext &C) const {
 void ChrootChecker::evalChroot(const CallEvent &Call, CheckerContext &C) const 
{
   ProgramStateRef state = C.getState();
   ProgramStateManager &Mgr = state->getStateManager();
+  const TargetInfo &TI = C.getASTContext().getTargetInfo();
+  SValBuilder &SVB = C.getSValBuilder();
+  BasicValueFactory &BVF = SVB.getBasicValueFactory();
+  ConstraintManager &CM = Mgr.getConstraintManager();
 
-  // Once encouter a chroot(), set the enum value ROOT_CHANGED directly in
-  // the GDM.
-  state = Mgr.addGDM(state, ChrootChecker::getTag(), (void*) ROOT_CHANGED);
-  C.addTransition(state);
+  const QualType sIntTy = C.getASTContext().getIntTypeForBitwidth(
+  /*DestWidth=*/TI.getIntWidth(), /*Signed=*/true);
+
+  const Expr *ChrootCE = Call.getOriginExpr();
+  if (!ChrootCE)
+return;
+  const auto *CE = cast(Call.getOriginExpr());

vabridgers wrote:

Will address

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


[clang] [compiler-rt] [llvm] [XRay][RISCV] RISCV support for XRay (PR #117368)

2024-11-27 Thread Min-Yih Hsu via cfe-commits

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


[clang] [analyzer] Modernize, improve and promote chroot checker (PR #117791)

2024-11-27 Thread via cfe-commits


@@ -98,9 +98,9 @@ void ChrootChecker::evalChroot(const CallEvent &Call, 
CheckerContext &C) const {
   const auto *CE = cast(Call.getOriginExpr());
 
   const LocationContext *LCtx = C.getLocationContext();
-  NonLoc RetVal =
-  SVB.conjureSymbolVal(/*SymbolTag=*/nullptr, ChrootCE, LCtx, IntTy, 
C.blockCount())
-  .castAs();
+  NonLoc RetVal = SVB.conjureSymbolVal(/*SymbolTag=*/nullptr, ChrootCE, LCtx,
+   IntTy, C.blockCount())
+  .castAs();

vabridgers wrote:

Will address. Thanks

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


[clang] [compiler-rt] [llvm] [SystemZ] Add support for half (fp16) (PR #109164)

2024-11-27 Thread Jonas Paulsson via cfe-commits


@@ -1883,6 +1931,10 @@ void SystemZInstrInfo::getLoadStoreOpcodes(const 
TargetRegisterClass *RC,
   } else if (RC == &SystemZ::FP128BitRegClass) {
 LoadOpcode = SystemZ::LX;
 StoreOpcode = SystemZ::STX;
+  } else if (RC == &SystemZ::FP16BitRegClass ||
+ RC == &SystemZ::VR16BitRegClass) {
+LoadOpcode = SystemZ::VL16;

JonPsson1 wrote:

Yes, for instance in spill-half-01.mir.


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


[clang] [llvm] [X86] Enhance kCFI type IDs with a 3-bit arity indicator. (PR #117121)

2024-11-27 Thread Matthew Maurer via cfe-commits

maurer wrote:

This is not a Rust concern, but re-reading the initial post, it *looks* like 
your own statistics suggest that consuming 3 bits for arity costs more than it 
buys you. As stated, (didn't check your math, just going off what you said) 
prior to your change, we expect 0.01383765 collisions in your sample 
environment. After your change, we expect to have the *sum* of your right hand 
column in collisions, which comes out to 0.0266774 - nearly double the rate of 
collisions we have with the basic implementation. In fact, I think that any 
scheme like this will always going to increase the number of overall 
collisions, given that the arity is implicitly hashed into the representation 
already.

The main reason I could see to consider this is if for some reason a 
cross-arity collision is more dangerous than a same-arity collision in terms of 
exploitability, which I can't immediately argue, but perhaps you have something 
for this that was just assumed in the initial post?

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


[clang] [compiler-rt] [llvm] [openmp] [PGO][Offload] Profile profraw generation for GPU instrumentation #76587 (PR #93365)

2024-11-27 Thread Joel E. Denny via cfe-commits


@@ -1,12 +1,17 @@
-// RUN: %libomptarget-compile-generic -fprofile-instr-generate \
-// RUN: -Xclang "-fprofile-instrument=clang"
-// RUN: %libomptarget-run-generic 2>&1 | %fcheck-generic \
-// RUN: --check-prefix="CLANG-PGO"
 // RUN: %libomptarget-compile-generic -fprofile-generate \
 // RUN: -Xclang "-fprofile-instrument=llvm"
-// RUN: %libomptarget-run-generic 2>&1 | %fcheck-generic \
+// RUN: env LLVM_PROFILE_FILE=llvm.profraw %libomptarget-run-generic 2>&1
+// RUN: llvm-profdata show --all-functions --counts \

jdenny-ornl wrote:

Seems to be fixed now.  Thanks.

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


[clang] [analyzer] Modernize, improve and promote chroot checker (PR #117791)

2024-11-27 Thread via cfe-commits


@@ -121,17 +183,40 @@ void ChrootChecker::checkPreCall(const CallEvent &Call,
 return;
 
   // If jail state is ROOT_CHANGED, generate BugReport.
-  void *const* k = C.getState()->FindGDM(ChrootChecker::getTag());
-  if (k)
-if (isRootChanged((intptr_t) *k))
-  if (ExplodedNode *N = C.generateNonFatalErrorNode()) {
-constexpr llvm::StringLiteral Msg =
-"No call of chdir(\"/\") immediately after chroot";
-C.emitReport(
-std::make_unique(BT_BreakJail, Msg, N));
-  }
+  const ChrootKind k = C.getState()->get();
+  if (k == ROOT_CHANGED) {
+ExplodedNode *Err =
+C.generateNonFatalErrorNode(C.getState(), C.getPredecessor());
+if (!Err)
+  return;
+const Expr *ChrootExpr = C.getState()->get();
+
+const ExplodedNode *ChrootCallNode = getAcquisitionSite(Err, C);
+assert(ChrootCallNode && "Could not find place of stream opening.");
+
+PathDiagnosticLocation LocUsedForUniqueing;
+if (const Stmt *ChrootStmt = ChrootCallNode->getStmtForDiagnostics())
+  LocUsedForUniqueing = PathDiagnosticLocation::createBegin(
+  ChrootStmt, C.getSourceManager(),
+  ChrootCallNode->getLocationContext());

vabridgers wrote:

Got it now. This comment will be addressed in the next update.

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


[clang] [llvm] [X86] Enhance kCFI type IDs with a 3-bit arity indicator. (PR #117121)

2024-11-27 Thread Scott Constable via cfe-commits

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


[clang] [analyzer] Modernize, improve and promote chroot checker (PR #117791)

2024-11-27 Thread via cfe-commits

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

>From ed174c8b52880d4f89415eb3a72da13f355438d7 Mon Sep 17 00:00:00 2001
From: einvbri 
Date: Mon, 25 Nov 2024 10:31:57 +0100
Subject: [PATCH 1/4] [analyzer] Modernize, improve and promote chroot checker

This change modernizes, improves and promotes the chroot checker from
alpha to the Unix family of checkers. This checker covers the POS05
recommendations for use of chroot.

The improvements included modeling of a success or failure from chroot
and not falsely reporting a warning along an error path. This was made
possible through modernizing the checker to be flow sensitive.
---
 clang/docs/ReleaseNotes.rst   |   3 +
 clang/docs/analyzer/checkers.rst  |  30 ++--
 .../clang/StaticAnalyzer/Checkers/Checkers.td |   8 +-
 .../StaticAnalyzer/Checkers/ChrootChecker.cpp | 149 ++
 .../test/Analysis/analyzer-enabled-checkers.c |   1 +
 clang/test/Analysis/chroot.c  |  36 -
 clang/test/Analysis/show-checker-list.c   |   9 --
 ...c-library-functions-arg-enabled-checkers.c |   1 +
 8 files changed, 174 insertions(+), 63 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6c40e48e2f49b3..292a41e127bfd0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -985,6 +985,9 @@ Moved checkers
   original checkers were implemented only using AST matching and make more
   sense as a single clang-tidy check.
 
+- The checker ``alpha.unix.Chroot`` was modernized, improved and moved from
+  alpha to a main Unix family checker.
+
 .. _release-notes-sanitizers:
 
 Sanitizers
diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index f34b25cd04bd18..5149faa50f72cf 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -1750,6 +1750,21 @@ Critical section handling functions modeled by this 
checker:
}
  }
 
+.. _unix-Chroot:
+
+unix.Chroot (C)
+"
+Check improper use of chroot.
+
+.. code-block:: c
+
+ void f();
+
+ void test() {
+   chroot("/usr/local");
+   f(); // warn: no call of chdir("/") immediately after chroot
+ }
+
 .. _unix-Errno:
 
 unix.Errno (C)
@@ -3275,21 +3290,6 @@ SEI CERT checkers which tries to find errors based on 
their `C coding rules ,
   HelpText<"Check for proper usage of vfork">,
   Documentation;
 
-} // end "unix"
-
-let ParentPackage = UnixAlpha in {
-
 def ChrootChecker : Checker<"Chroot">,
   HelpText<"Check improper use of chroot">,
   Documentation;
 
+} // end "unix"
+
+let ParentPackage = UnixAlpha in {
+
 def PthreadLockChecker : Checker<"PthreadLock">,
   HelpText<"Simple lock -> unlock checker">,
   Dependencies<[PthreadLockBase]>,
diff --git a/clang/lib/StaticAnalyzer/Checkers/ChrootChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/ChrootChecker.cpp
index 3a0a01c23de03e..d957ce9ed2ffc7 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ChrootChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ChrootChecker.cpp
@@ -10,6 +10,8 @@
 //
 
//===--===//
 
+#include "clang/AST/ASTContext.h"
+#include "clang/Basic/TargetInfo.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
@@ -24,21 +26,30 @@
 using namespace clang;
 using namespace ento;
 
-namespace {
-
 // enum value that represent the jail state
-enum Kind { NO_CHROOT, ROOT_CHANGED, JAIL_ENTERED };
+enum ChrootKind { NO_CHROOT, ROOT_CHANGED, ROOT_CHANGE_FAILED, JAIL_ENTERED };
 
-bool isRootChanged(intptr_t k) { return k == ROOT_CHANGED; }
-//bool isJailEntered(intptr_t k) { return k == JAIL_ENTERED; }
+// Track chroot state changes for success, failure, state change
+// and "jail"
+REGISTER_TRAIT_WITH_PROGRAMSTATE(ChrootState, ChrootKind)
+
+// Track the call expression to chroot for accurate
+// warning messages
+REGISTER_TRAIT_WITH_PROGRAMSTATE(ChrootCall, const Expr *)
+
+namespace {
 
 // This checker checks improper use of chroot.
-// The state transition:
+// The state transitions
+//
+//  -> ROOT_CHANGE_FAILED
+//  |
 // NO_CHROOT ---chroot(path)--> ROOT_CHANGED ---chdir(/) --> JAIL_ENTERED
 //  |   |
 // ROOT_CHANGED<--chdir(..)--  JAIL_ENTERED<--chdir(..)--
 //  |   |
 //  bug<--foo()--  JAIL_ENTERED<--foo()--
+//
 class ChrootChecker : public Checker {
   // This bug refers to possibly break out of a chroot() jail.
   const BugType BT_BreakJail{this, "Break out of jail"};
@@ -49,20 +60,17 @@ class ChrootChecker : public Checker {
 public:
   ChrootChecker() {}
 
-  static void *getTag() {
-static int x;
-return &x;
-  }
-
   bool eval

[clang] [llvm] [X86] Enhance kCFI type IDs with a 3-bit arity indicator. (PR #117121)

2024-11-27 Thread Scott Constable via cfe-commits

https://github.com/scottconstable edited 
https://github.com/llvm/llvm-project/pull/117121
___
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-27 Thread Vladislav Belov via cfe-commits

vbe-sc wrote:

Such an example causes a failure in my patch

```c++
template  
class X {
public:
  X() = default;
  virtual ~X() = default;

  virtual int foo(int x, int y, T &entry) = 0;

  void bar() {
struct Processor : public X {
  Processor() : X() {}

  int foo(int, int, T &) override {
return 42;
  }
};
  }
};
```

The output 
```
llvm-project/clang/lib/AST/DeclCXX.cpp:2508: void 
clang::CXXMethodDecl::addOverriddenMethod(const CXXMethodDecl *): Assertion 
`!MD->getParent()->isDependentContext() && "Can't add an overridden method to a 
class template!"' failed.
```

The problem case is class definition nested to the method. 
I'm working on investigation and fixing this issue  

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] [clang] Improve the lifetime_capture_by diagnostic on the constructor. (PR #117792)

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


@@ -535,6 +535,9 @@ static void visitFunctionCallArguments(IndirectLocalPath 
&Path, Expr *Call,
 
   bool EnableGSLAnalysis = !Callee->getASTContext().getDiagnostics().isIgnored(
   diag::warn_dangling_lifetime_pointer, SourceLocation());
+  bool EnableDanglingCapture =
+  !Callee->getASTContext().getDiagnostics().isIgnored(
+  diag::warn_dangling_reference_captured, SourceLocation());

usx95 wrote:

I would not disable this based on new warning because:
1. This is not the warning that is triggered in this path.
2. We are considering both annotations as aliases in case of constructors. It 
would be better to do this unconditionally.

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


[clang] [clang] Improve the lifetime_capture_by diagnostic on the constructor. (PR #117792)

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


@@ -411,3 +411,22 @@ void use() {
 }
 } // namespace with_span
 } // namespace inferred_capture_by
+
+namespace on_constructor {
+struct T {
+  T(const int& t [[clang::lifetime_capture_by(this)]]);
+};
+struct T2 {
+  T2(const int& t [[clang::lifetime_capture_by(x)]], int& x);
+};
+int foo(const T& t);

usx95 wrote:

could you also add
```cpp
int bar(const T& t[[clang::lifetimebound]]);
auto y = bar(T(1));
```
```cpp
struct T3 {
T3(const T& t [[clang::lifetime_capture_by(this));
};
T3 t3(T(1));
```

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


[clang] [llvm] [LoongArch] Support sc.q instruction for 128bit cmpxchg operation (PR #116771)

2024-11-27 Thread via cfe-commits

https://github.com/tangaac updated 
https://github.com/llvm/llvm-project/pull/116771

>From ee422d26ad2695d34b0bf471f6d4fa2c3bef8ca8 Mon Sep 17 00:00:00 2001
From: tangaac 
Date: Tue, 19 Nov 2024 17:43:31 +0800
Subject: [PATCH 1/2] [LoongArch] Support sc.q instruction for 128bit cmpxchg
 operation

---
 clang/include/clang/Driver/Options.td |   4 +
 clang/lib/Basic/Targets/LoongArch.cpp |   7 +-
 clang/lib/Basic/Targets/LoongArch.h   |   2 +
 .../lib/Driver/ToolChains/Arch/LoongArch.cpp  |   8 +
 clang/test/Driver/loongarch-march.c   |   8 +-
 clang/test/Driver/loongarch-mscq.c|  30 ++
 clang/test/Preprocessor/init-loongarch.c  |  31 +-
 .../TargetParser/LoongArchTargetParser.def|   3 +-
 .../llvm/TargetParser/LoongArchTargetParser.h |   3 +
 llvm/lib/Target/LoongArch/LoongArch.td|   9 +-
 .../LoongArchExpandAtomicPseudoInsts.cpp  | 107 +++
 .../LoongArch/LoongArchISelLowering.cpp   |  46 +++
 .../Target/LoongArch/LoongArchInstrInfo.td|  14 +
 .../TargetParser/LoongArchTargetParser.cpp|   1 +
 .../ir-instruction/atomic-cmpxchg-128.ll  | 287 ++
 15 files changed, 542 insertions(+), 18 deletions(-)
 create mode 100644 clang/test/Driver/loongarch-mscq.c
 create mode 100644 
llvm/test/CodeGen/LoongArch/ir-instruction/atomic-cmpxchg-128.ll

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 808f089914c9bb..96cef360bd5251 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5425,6 +5425,10 @@ def mdiv32 : Flag<["-"], "mdiv32">, 
Group,
   HelpText<"Use div.w[u] and mod.w[u] instructions with input not 
sign-extended.">;
 def mno_div32 : Flag<["-"], "mno-div32">, Group,
   HelpText<"Do not use div.w[u] and mod.w[u] instructions with input not 
sign-extended.">;
+def mscq : Flag<["-"], "mscq">, Group,
+  HelpText<"Enable sc.q instruction.">;
+def mno_scq : Flag<["-"], "mno-scq">, Group,
+  HelpText<"Disable sc.q instruction.">;
 def mannotate_tablejump : Flag<["-"], "mannotate-tablejump">, 
Group,
   HelpText<"Enable annotate table jump instruction to correlate it with the 
jump table.">;
 def mno_annotate_tablejump : Flag<["-"], "mno-annotate-tablejump">, 
Group,
diff --git a/clang/lib/Basic/Targets/LoongArch.cpp 
b/clang/lib/Basic/Targets/LoongArch.cpp
index d36186aa9c2fbf..bb0d0b68cfcb0a 100644
--- a/clang/lib/Basic/Targets/LoongArch.cpp
+++ b/clang/lib/Basic/Targets/LoongArch.cpp
@@ -206,7 +206,7 @@ void LoongArchTargetInfo::getTargetDefines(const 
LangOptions &Opts,
   // arch feature set will be used to include all sub-features belonging to
   // the V1.1 ISA version.
   if (HasFeatureFrecipe && HasFeatureLAM_BH && HasFeatureLAMCAS &&
-  HasFeatureLD_SEQ_SA && HasFeatureDiv32)
+  HasFeatureLD_SEQ_SA && HasFeatureDiv32 && HasFeatureSCQ)
 Builder.defineMacro("__loongarch_arch",
 Twine('"') + "la64v1.1" + Twine('"'));
   else
@@ -249,6 +249,9 @@ void LoongArchTargetInfo::getTargetDefines(const 
LangOptions &Opts,
   if (HasFeatureDiv32)
 Builder.defineMacro("__loongarch_div32", Twine(1));
 
+  if (HasFeatureSCQ)
+Builder.defineMacro("__loongarch_scq", Twine(1));
+
   StringRef ABI = getABI();
   if (ABI == "lp64d" || ABI == "lp64f" || ABI == "lp64s")
 Builder.defineMacro("__loongarch_lp64");
@@ -333,6 +336,8 @@ bool LoongArchTargetInfo::handleTargetFeatures(
   HasFeatureLD_SEQ_SA = true;
 else if (Feature == "+div32")
   HasFeatureDiv32 = true;
+else if (Feature == "+scq")
+  HasFeatureSCQ = true;
   }
   return true;
 }
diff --git a/clang/lib/Basic/Targets/LoongArch.h 
b/clang/lib/Basic/Targets/LoongArch.h
index abaa05aa42d438..5c34c84ff8d3e8 100644
--- a/clang/lib/Basic/Targets/LoongArch.h
+++ b/clang/lib/Basic/Targets/LoongArch.h
@@ -34,6 +34,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public 
TargetInfo {
   bool HasFeatureLAMCAS;
   bool HasFeatureLD_SEQ_SA;
   bool HasFeatureDiv32;
+  bool HasFeatureSCQ;
 
 public:
   LoongArchTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
@@ -47,6 +48,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public 
TargetInfo {
 HasFeatureLAMCAS = false;
 HasFeatureLD_SEQ_SA = false;
 HasFeatureDiv32 = false;
+HasFeatureSCQ = false;
 LongDoubleWidth = 128;
 LongDoubleAlign = 128;
 LongDoubleFormat = &llvm::APFloat::IEEEquad();
diff --git a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp 
b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
index bbd9397aa2378a..4dd07f25bab0fb 100644
--- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -301,6 +301,14 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
 else
   Features.push_back("-div32");
   }
+
+  // Select scq feature determined by -m[no-]scq.
+  if (const Arg *A = Args.getLastArg(options::OPT_mscq, option

[clang] [Driver] Support fprofile-sample-use= for CL (PR #117282)

2024-11-27 Thread Fangrui Song via cfe-commits

MaskRay wrote:

Adding CLOption to -fprofile-sample-use= suffices.
We don't need these CLJoined aliases. They are for MSVC options that are ported 
to clang.
For clang-specific options, we don't want to add unneeded aliases.

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


[clang] [llvm] [RISCV] Add Qualcomm uC Xqcicsr (CSR) extension (PR #117169)

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


@@ -0,0 +1,44 @@
+//=== RISCVInstrInfoXQci.td *- tablegen 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file describes the vendor extensions defined by QUALCOMM.
+//
+//===--===//
+
+//===--===//
+// Operand and SDNode transformation definitions.
+//===--===//
+
+//===--===//
+// Instruction Formats
+//===--===//
+
+//===--===//
+// Instruction Class Templates
+//===--===//
+
+//===--===//
+// Instructions
+//===--===//
+
+let Predicates = [HasVendorXqcicsr, IsRV32], DecoderNamespace = "Xqcicsr" in {
+let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in {
+  def QC_CSRRWR : RVInstR<0b1000110, 0b000, OPC_SYSTEM, (outs GPR:$rd),
+  (ins GPR:$rs1, GPRNoX0:$rs2), "qc.csrrwr",
+  "$rd, $rs1, $rs2">;
+
+  def QC_CSRRWRI : RVInstRBase<0b000, OPC_SYSTEM, (outs GPR:$rd),

topperc wrote:

I think you can just use `RVInstR` if you use `uimm5:$rs1`. It's what `CSR_ii` 
does for the standard CSR instructions.

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


[clang] [llvm] [RISCV] Add Qualcomm uC Xqcicsr (CSR) extension (PR #117169)

2024-11-27 Thread Sudharsan Veeravalli via cfe-commits

https://github.com/svs-quic updated 
https://github.com/llvm/llvm-project/pull/117169

>From 92a3e2e9c44c03093e6050b92b938fd2a0d6886c Mon Sep 17 00:00:00 2001
From: Sudharsan Veeravalli 
Date: Wed, 20 Nov 2024 13:24:07 +0530
Subject: [PATCH 1/3] [RISCV] Add Qualcomm uC Xqcicsr (CSR) extension

The Qualcomm uC Xqcicsr extension adds 2 instructions that can read
and write CSRs.

The current spec can be found at:
https://github.com/quic/riscv-unified-db/releases/latest

This patch adds assembler only support.
---
 .../Driver/print-supported-extensions-riscv.c |  1 +
 llvm/docs/RISCVUsage.rst  |  3 ++
 llvm/docs/ReleaseNotes.md |  3 +-
 .../RISCV/Disassembler/RISCVDisassembler.cpp  |  2 +
 llvm/lib/Target/RISCV/RISCVFeatures.td| 10 +
 llvm/lib/Target/RISCV/RISCVInstrInfo.td   |  1 +
 llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td   | 44 +++
 llvm/lib/TargetParser/RISCVISAInfo.cpp|  4 ++
 llvm/test/CodeGen/RISCV/attributes.ll |  2 +
 llvm/test/MC/RISCV/xqcicsr-invalid.s  | 27 
 llvm/test/MC/RISCV/xqcicsr-valid.s| 19 
 .../TargetParser/RISCVISAInfoTest.cpp |  1 +
 12 files changed, 116 insertions(+), 1 deletion(-)
 create mode 100644 llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td
 create mode 100644 llvm/test/MC/RISCV/xqcicsr-invalid.s
 create mode 100644 llvm/test/MC/RISCV/xqcicsr-valid.s

diff --git a/clang/test/Driver/print-supported-extensions-riscv.c 
b/clang/test/Driver/print-supported-extensions-riscv.c
index 774dc3a4e1e756..a0b93621d2fcdc 100644
--- a/clang/test/Driver/print-supported-extensions-riscv.c
+++ b/clang/test/Driver/print-supported-extensions-riscv.c
@@ -187,6 +187,7 @@
 // CHECK-NEXT: zvkgs0.7   'Zvkgs' (Vector-Scalar GCM 
instructions for Cryptography)
 // CHECK-NEXT: smctr1.0   'Smctr' (Control Transfer 
Records Machine Level)
 // CHECK-NEXT: ssctr1.0   'Ssctr' (Control Transfer 
Records Supervisor Level)
+// CHECK-NEXT: xqcicsr  0.2   'Xqcicsr' (Qualcomm uC CSR 
Extension)
 // CHECK-EMPTY:
 // CHECK-NEXT: Supported Profiles
 // CHECK-NEXT: rva20s64
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 1317221448ea5b..a656ccd00ed482 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -329,6 +329,9 @@ The primary goal of experimental support is to assist in 
the process of ratifica
 ``experimental-smctr``, ``experimental-ssctr``
   LLVM implements the `1.0-rc3 specification 
`__.
 
+``experimental-xqcicsr``
+  LLVM implements the `0.2 extension specification 
`__.
+
 To use an experimental extension from `clang`, you must add 
`-menable-experimental-extensions` to the command line, and specify the exact 
version of the experimental extension you are using.  To use an experimental 
extension with LLVM's internal developer tools (e.g. `llc`, `llvm-objdump`, 
`llvm-mc`), you must prefix the extension name with `experimental-`.  Note that 
you don't need to specify the version with internal tools, and shouldn't 
include the `experimental-` prefix with `clang`.
 
 Vendor Extensions
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index 1ba3672baeed88..89e7c048592f34 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -211,7 +211,8 @@ Changes to the RISC-V Backend
 * `f` and `cf` inline assembly constraints, when using F-/D-/H-in-X extensions,
   will use the relevant GPR rather than FPR. This makes inline assembly 
portable
   between e.g. F and Zfinx code.
-
+* Adds experimental assembler support for the Qualcomm uC 'Xqcicsr` (CSR)
+  extension.
 
 Changes to the WebAssembly Backend
 --
diff --git a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp 
b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
index cf8e337810d83b..e4f7ee323cf20b 100644
--- a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
+++ b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
@@ -682,6 +682,8 @@ DecodeStatus RISCVDisassembler::getInstruction32(MCInst 
&MI, uint64_t &Size,
 "CORE-V SIMD extensions custom opcode table");
   TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXCVbi, DecoderTableXCVbi32,
 "CORE-V Immediate Branching custom opcode table");
+  TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXqcicsr, DecoderTableXqcicsr32,
+"Qualcomm uC CSR custom opcode table");
   TRY_TO_DECODE(true, DecoderTable32, "RISCV32 table");
 
   return MCDisassembler::Fail;
diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td 
b/llvm/lib/Target/RISCV/RISCVFeatures.td
index 3977816ebdd49c..ed87c9604f38b1 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RI

[clang] [llvm] [RISCV] Add Qualcomm uC Xqcicsr (CSR) extension (PR #117169)

2024-11-27 Thread Sudharsan Veeravalli via cfe-commits

https://github.com/svs-quic updated 
https://github.com/llvm/llvm-project/pull/117169

>From 92a3e2e9c44c03093e6050b92b938fd2a0d6886c Mon Sep 17 00:00:00 2001
From: Sudharsan Veeravalli 
Date: Wed, 20 Nov 2024 13:24:07 +0530
Subject: [PATCH 1/5] [RISCV] Add Qualcomm uC Xqcicsr (CSR) extension

The Qualcomm uC Xqcicsr extension adds 2 instructions that can read
and write CSRs.

The current spec can be found at:
https://github.com/quic/riscv-unified-db/releases/latest

This patch adds assembler only support.
---
 .../Driver/print-supported-extensions-riscv.c |  1 +
 llvm/docs/RISCVUsage.rst  |  3 ++
 llvm/docs/ReleaseNotes.md |  3 +-
 .../RISCV/Disassembler/RISCVDisassembler.cpp  |  2 +
 llvm/lib/Target/RISCV/RISCVFeatures.td| 10 +
 llvm/lib/Target/RISCV/RISCVInstrInfo.td   |  1 +
 llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td   | 44 +++
 llvm/lib/TargetParser/RISCVISAInfo.cpp|  4 ++
 llvm/test/CodeGen/RISCV/attributes.ll |  2 +
 llvm/test/MC/RISCV/xqcicsr-invalid.s  | 27 
 llvm/test/MC/RISCV/xqcicsr-valid.s| 19 
 .../TargetParser/RISCVISAInfoTest.cpp |  1 +
 12 files changed, 116 insertions(+), 1 deletion(-)
 create mode 100644 llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td
 create mode 100644 llvm/test/MC/RISCV/xqcicsr-invalid.s
 create mode 100644 llvm/test/MC/RISCV/xqcicsr-valid.s

diff --git a/clang/test/Driver/print-supported-extensions-riscv.c 
b/clang/test/Driver/print-supported-extensions-riscv.c
index 774dc3a4e1e756..a0b93621d2fcdc 100644
--- a/clang/test/Driver/print-supported-extensions-riscv.c
+++ b/clang/test/Driver/print-supported-extensions-riscv.c
@@ -187,6 +187,7 @@
 // CHECK-NEXT: zvkgs0.7   'Zvkgs' (Vector-Scalar GCM 
instructions for Cryptography)
 // CHECK-NEXT: smctr1.0   'Smctr' (Control Transfer 
Records Machine Level)
 // CHECK-NEXT: ssctr1.0   'Ssctr' (Control Transfer 
Records Supervisor Level)
+// CHECK-NEXT: xqcicsr  0.2   'Xqcicsr' (Qualcomm uC CSR 
Extension)
 // CHECK-EMPTY:
 // CHECK-NEXT: Supported Profiles
 // CHECK-NEXT: rva20s64
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 1317221448ea5b..a656ccd00ed482 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -329,6 +329,9 @@ The primary goal of experimental support is to assist in 
the process of ratifica
 ``experimental-smctr``, ``experimental-ssctr``
   LLVM implements the `1.0-rc3 specification 
`__.
 
+``experimental-xqcicsr``
+  LLVM implements the `0.2 extension specification 
`__.
+
 To use an experimental extension from `clang`, you must add 
`-menable-experimental-extensions` to the command line, and specify the exact 
version of the experimental extension you are using.  To use an experimental 
extension with LLVM's internal developer tools (e.g. `llc`, `llvm-objdump`, 
`llvm-mc`), you must prefix the extension name with `experimental-`.  Note that 
you don't need to specify the version with internal tools, and shouldn't 
include the `experimental-` prefix with `clang`.
 
 Vendor Extensions
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index 1ba3672baeed88..89e7c048592f34 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -211,7 +211,8 @@ Changes to the RISC-V Backend
 * `f` and `cf` inline assembly constraints, when using F-/D-/H-in-X extensions,
   will use the relevant GPR rather than FPR. This makes inline assembly 
portable
   between e.g. F and Zfinx code.
-
+* Adds experimental assembler support for the Qualcomm uC 'Xqcicsr` (CSR)
+  extension.
 
 Changes to the WebAssembly Backend
 --
diff --git a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp 
b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
index cf8e337810d83b..e4f7ee323cf20b 100644
--- a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
+++ b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
@@ -682,6 +682,8 @@ DecodeStatus RISCVDisassembler::getInstruction32(MCInst 
&MI, uint64_t &Size,
 "CORE-V SIMD extensions custom opcode table");
   TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXCVbi, DecoderTableXCVbi32,
 "CORE-V Immediate Branching custom opcode table");
+  TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXqcicsr, DecoderTableXqcicsr32,
+"Qualcomm uC CSR custom opcode table");
   TRY_TO_DECODE(true, DecoderTable32, "RISCV32 table");
 
   return MCDisassembler::Fail;
diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td 
b/llvm/lib/Target/RISCV/RISCVFeatures.td
index 3977816ebdd49c..ed87c9604f38b1 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RI

[clang] [llvm] [RISCV] Add Qualcomm uC Xqcicsr (CSR) extension (PR #117169)

2024-11-27 Thread Sudharsan Veeravalli via cfe-commits


@@ -0,0 +1,44 @@
+//=== RISCVInstrInfoXQci.td *- tablegen 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file describes the vendor extensions defined by QUALCOMM.
+//
+//===--===//
+
+//===--===//
+// Operand and SDNode transformation definitions.
+//===--===//
+
+//===--===//
+// Instruction Formats
+//===--===//
+
+//===--===//
+// Instruction Class Templates
+//===--===//
+
+//===--===//
+// Instructions
+//===--===//
+
+let Predicates = [HasVendorXqcicsr, IsRV32], DecoderNamespace = "Xqcicsr" in {
+let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in {
+  def QC_CSRRWR : RVInstR<0b1000110, 0b000, OPC_SYSTEM, (outs GPR:$rd),
+  (ins GPR:$rs1, GPRNoX0:$rs2), "qc.csrrwr",
+  "$rd, $rs1, $rs2">;
+
+  def QC_CSRRWRI : RVInstRBase<0b000, OPC_SYSTEM, (outs GPR:$rd),

svs-quic wrote:

Done

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


[clang] [clang-tools-extra] [clang] Avoid re-evaluating field bitwidth (PR #117732)

2024-11-27 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


tbaederr wrote:

Most recent result: 
http://llvm-compile-time-tracker.com/compare.php?from=6f16a8bf17ac9a171b5435ee53c3d2bef657bdad&to=65e10089b0ca8e2103e6fcf6b082d2bebd3ef458&stat=instructions%3Au



> The idea is that you'd store an `Expr` like we do elsewhere, and then upon 
> instantiating it/evaluating it, we'd replace it with a `ConstantExpr`. So you 
> don't need separate storage, just replace the current thing.

I was more thinking about other consumers of clang as as a library, e.g. 
`FieldDecl::setBitWidth()` ensuring that the bitwidth expression is a 
`ConstantExpr`, but that doesn't work properly because of the reasons above. 
I'm now asserting the type in `getBitWidthValue()` instead.

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


[clang] [clang] recognize hexagon-*-ld.lld variants (PR #117338)

2024-11-27 Thread Fangrui Song via cfe-commits

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


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


[clang] [Driver] Support fprofile-sample-use= for CL (PR #117282)

2024-11-27 Thread Haohai Wen via cfe-commits

HaohaiWen wrote:

> Adding CLOption to -fprofile-sample-use= suffices. We don't need these 
> CLJoined aliases. They are for MSVC options that are ported to clang. For 
> clang-specific options, we don't want to add unneeded aliases.

Got it. I checked CL flags with MSVC. You're right.
Let me revert those SLASH flags.

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


[clang] [Driver] Remove non MSVC CL flags /fprofile-sample-use (PR #117970)

2024-11-27 Thread Haohai Wen via cfe-commits

https://github.com/HaohaiWen created 
https://github.com/llvm/llvm-project/pull/117970

Those flags are introduced in #117282. They are not supported by MSVC.

>From 9809cd44885c43e879056db32fb2dcd8da580019 Mon Sep 17 00:00:00 2001
From: Haohai Wen 
Date: Thu, 28 Nov 2024 15:08:44 +0800
Subject: [PATCH] [Driver] Remove non MSVC CL flags /fprofile-sample-use

Those flags are introduced in #117282. They are not supported by MSVC.
---
 clang/include/clang/Driver/Options.td | 2 --
 clang/test/Driver/cl-options.c| 6 +-
 2 files changed, 1 insertion(+), 7 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d3142fbdb06e69..9c356c9d2ea4ef 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8506,8 +8506,6 @@ def _SLASH_fp_strict : CLFlag<"fp:strict">, HelpText<"">, 
Alias, A
 def _SLASH_fsanitize_EQ_address : CLFlag<"fsanitize=address">,
   HelpText<"Enable AddressSanitizer">,
   Alias, AliasArgs<["address"]>;
-def : CLJoined<"fprofile-sample-use:">, Alias;
-def : CLJoined<"fprofile-sample-use=">, Alias;
 def _SLASH_GA : CLFlag<"GA">, Alias, AliasArgs<["local-exec"]>,
   HelpText<"Assume thread-local variables are defined in the executable">;
 def _SLASH_GR : CLFlag<"GR">, HelpText<"Emit RTTI data (default)">;
diff --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index 695c0cfacd4b44..477e8489e74280 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -101,11 +101,6 @@
 // CHECK-PROFILE-USE: "-fprofile-instrument-use-path=default.profdata"
 // CHECK-PROFILE-USE-FILE: "-fprofile-instrument-use-path=/tmp/somefile.prof"
 
-// RUN: %clang_cl -### /FA -fprofile-sample-use=%S/Inputs/file.prof -- %s 2>&1 
| FileCheck --check-prefix=CHECK-PROFILE-SAMPLE-USE %s
-// RUN: %clang_cl -### /FA /fprofile-sample-use=%S/Inputs/file.prof -- %s 2>&1 
| FileCheck --check-prefix=CHECK-PROFILE-SAMPLE-USE %s
-// RUN: %clang_cl -### /FA /fprofile-sample-use:%S/Inputs/file.prof -- %s 2>&1 
| FileCheck --check-prefix=CHECK-PROFILE-SAMPLE-USE %s
-// CHECK-PROFILE-SAMPLE-USE: "-fprofile-sample-use={{.*}}/file.prof"
-
 // RUN: %clang_cl /GA -### -- %s 2>&1 | FileCheck -check-prefix=GA %s
 // GA: -ftls-model=local-exec
 
@@ -718,6 +713,7 @@
 // RUN: -fbracket-depth=123 \
 // RUN: -fprofile-generate \
 // RUN: -fprofile-generate=dir \
+// RUN: -fprofile-sample-use=%S/Inputs/file.prof \
 // RUN: -fno-profile-generate \
 // RUN: -fno-profile-instr-generate \
 // RUN: -fno-profile-instr-use \

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


[clang] [Driver] Remove non MSVC CL flags /fprofile-sample-use (PR #117970)

2024-11-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Haohai Wen (HaohaiWen)


Changes

Those flags are introduced in #117282. They are not supported by MSVC.

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


2 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (-2) 
- (modified) clang/test/Driver/cl-options.c (+1-5) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d3142fbdb06e69..9c356c9d2ea4ef 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8506,8 +8506,6 @@ def _SLASH_fp_strict : CLFlag<"fp:strict">, HelpText<"">, 
Alias, A
 def _SLASH_fsanitize_EQ_address : CLFlag<"fsanitize=address">,
   HelpText<"Enable AddressSanitizer">,
   Alias, AliasArgs<["address"]>;
-def : CLJoined<"fprofile-sample-use:">, Alias;
-def : CLJoined<"fprofile-sample-use=">, Alias;
 def _SLASH_GA : CLFlag<"GA">, Alias, AliasArgs<["local-exec"]>,
   HelpText<"Assume thread-local variables are defined in the executable">;
 def _SLASH_GR : CLFlag<"GR">, HelpText<"Emit RTTI data (default)">;
diff --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index 695c0cfacd4b44..477e8489e74280 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -101,11 +101,6 @@
 // CHECK-PROFILE-USE: "-fprofile-instrument-use-path=default.profdata"
 // CHECK-PROFILE-USE-FILE: "-fprofile-instrument-use-path=/tmp/somefile.prof"
 
-// RUN: %clang_cl -### /FA -fprofile-sample-use=%S/Inputs/file.prof -- %s 2>&1 
| FileCheck --check-prefix=CHECK-PROFILE-SAMPLE-USE %s
-// RUN: %clang_cl -### /FA /fprofile-sample-use=%S/Inputs/file.prof -- %s 2>&1 
| FileCheck --check-prefix=CHECK-PROFILE-SAMPLE-USE %s
-// RUN: %clang_cl -### /FA /fprofile-sample-use:%S/Inputs/file.prof -- %s 2>&1 
| FileCheck --check-prefix=CHECK-PROFILE-SAMPLE-USE %s
-// CHECK-PROFILE-SAMPLE-USE: "-fprofile-sample-use={{.*}}/file.prof"
-
 // RUN: %clang_cl /GA -### -- %s 2>&1 | FileCheck -check-prefix=GA %s
 // GA: -ftls-model=local-exec
 
@@ -718,6 +713,7 @@
 // RUN: -fbracket-depth=123 \
 // RUN: -fprofile-generate \
 // RUN: -fprofile-generate=dir \
+// RUN: -fprofile-sample-use=%S/Inputs/file.prof \
 // RUN: -fno-profile-generate \
 // RUN: -fno-profile-instr-generate \
 // RUN: -fno-profile-instr-use \

``




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


[clang] [Driver] Remove non MSVC CL flags /fprofile-sample-use (PR #117970)

2024-11-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Haohai Wen (HaohaiWen)


Changes

Those flags are introduced in #117282. They are not supported by MSVC.

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


2 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (-2) 
- (modified) clang/test/Driver/cl-options.c (+1-5) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d3142fbdb06e69..9c356c9d2ea4ef 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8506,8 +8506,6 @@ def _SLASH_fp_strict : CLFlag<"fp:strict">, HelpText<"">, 
Alias, A
 def _SLASH_fsanitize_EQ_address : CLFlag<"fsanitize=address">,
   HelpText<"Enable AddressSanitizer">,
   Alias, AliasArgs<["address"]>;
-def : CLJoined<"fprofile-sample-use:">, Alias;
-def : CLJoined<"fprofile-sample-use=">, Alias;
 def _SLASH_GA : CLFlag<"GA">, Alias, AliasArgs<["local-exec"]>,
   HelpText<"Assume thread-local variables are defined in the executable">;
 def _SLASH_GR : CLFlag<"GR">, HelpText<"Emit RTTI data (default)">;
diff --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index 695c0cfacd4b44..477e8489e74280 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -101,11 +101,6 @@
 // CHECK-PROFILE-USE: "-fprofile-instrument-use-path=default.profdata"
 // CHECK-PROFILE-USE-FILE: "-fprofile-instrument-use-path=/tmp/somefile.prof"
 
-// RUN: %clang_cl -### /FA -fprofile-sample-use=%S/Inputs/file.prof -- %s 2>&1 
| FileCheck --check-prefix=CHECK-PROFILE-SAMPLE-USE %s
-// RUN: %clang_cl -### /FA /fprofile-sample-use=%S/Inputs/file.prof -- %s 2>&1 
| FileCheck --check-prefix=CHECK-PROFILE-SAMPLE-USE %s
-// RUN: %clang_cl -### /FA /fprofile-sample-use:%S/Inputs/file.prof -- %s 2>&1 
| FileCheck --check-prefix=CHECK-PROFILE-SAMPLE-USE %s
-// CHECK-PROFILE-SAMPLE-USE: "-fprofile-sample-use={{.*}}/file.prof"
-
 // RUN: %clang_cl /GA -### -- %s 2>&1 | FileCheck -check-prefix=GA %s
 // GA: -ftls-model=local-exec
 
@@ -718,6 +713,7 @@
 // RUN: -fbracket-depth=123 \
 // RUN: -fprofile-generate \
 // RUN: -fprofile-generate=dir \
+// RUN: -fprofile-sample-use=%S/Inputs/file.prof \
 // RUN: -fno-profile-generate \
 // RUN: -fno-profile-instr-generate \
 // RUN: -fno-profile-instr-use \

``




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


[clang] [llvm] [RISCV] Add Qualcomm uC Xqcicsr (CSR) extension (PR #117169)

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

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

LGTM

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


[clang] c4645ff - [RISCV] Add Qualcomm uC Xqcicsr (CSR) extension (#117169)

2024-11-27 Thread via cfe-commits

Author: Sudharsan Veeravalli
Date: 2024-11-28T12:46:15+05:30
New Revision: c4645ffedacad18e4cd1dd372288aa55178b1c44

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

LOG: [RISCV] Add Qualcomm uC Xqcicsr (CSR) extension (#117169)

The Qualcomm uC Xqcicsr extension adds 2 instructions that can read and
write CSRs.

The current spec can be found at:
https://github.com/quic/riscv-unified-db/releases/latest

This patch adds assembler only support.

Added: 
llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td
llvm/test/MC/RISCV/xqcicsr-invalid.s
llvm/test/MC/RISCV/xqcicsr-valid.s

Modified: 
clang/test/Driver/print-supported-extensions-riscv.c
llvm/docs/RISCVUsage.rst
llvm/docs/ReleaseNotes.md
llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
llvm/lib/Target/RISCV/RISCVFeatures.td
llvm/lib/Target/RISCV/RISCVInstrInfo.td
llvm/lib/TargetParser/RISCVISAInfo.cpp
llvm/test/CodeGen/RISCV/attributes.ll
llvm/unittests/TargetParser/RISCVISAInfoTest.cpp

Removed: 




diff  --git a/clang/test/Driver/print-supported-extensions-riscv.c 
b/clang/test/Driver/print-supported-extensions-riscv.c
index 151e4701a1da84..02edfc03e59cac 100644
--- a/clang/test/Driver/print-supported-extensions-riscv.c
+++ b/clang/test/Driver/print-supported-extensions-riscv.c
@@ -188,6 +188,7 @@
 // CHECK-NEXT: smctr1.0   'Smctr' (Control Transfer 
Records Machine Level)
 // CHECK-NEXT: ssctr1.0   'Ssctr' (Control Transfer 
Records Supervisor Level)
 // CHECK-NEXT: svukte   0.3   'Svukte' 
(Address-Independent Latency of User-Mode Faults to Supervisor Addresses)
+// CHECK-NEXT: xqcicsr  0.2   'Xqcicsr' (Qualcomm uC CSR 
Extension)
 // CHECK-EMPTY:
 // CHECK-NEXT: Supported Profiles
 // CHECK-NEXT: rva20s64

diff  --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index bac267591e0152..a7000baa69d806 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -426,6 +426,9 @@ The current vendor extensions supported are:
 ``Xwchc``
   LLVM implements `the custom compressed opcodes present in some QingKe cores` 
by WCH / Nanjing Qinheng Microelectronics. The vendor refers to these opcodes 
by the name "XW".
 
+``experimental-Xqcicsr``
+  LLVM implements `version 0.2 of the Qualcomm uC CSR extension specification 
`__ by Qualcomm.  All 
instructions are prefixed with `qc.` as described in the specification. These 
instructions are only available for riscv32.
+
 Experimental C Intrinsics
 =
 

diff  --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index dd68d5296376f6..8b155d77bbb397 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -211,7 +211,8 @@ Changes to the RISC-V Backend
 * `f` and `cf` inline assembly constraints, when using F-/D-/H-in-X extensions,
   will use the relevant GPR rather than FPR. This makes inline assembly 
portable
   between e.g. F and Zfinx code.
-
+* Adds experimental assembler support for the Qualcomm uC 'Xqcicsr` (CSR)
+  extension.
 
 Changes to the WebAssembly Backend
 --

diff  --git a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp 
b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
index cf8e337810d83b..e4f7ee323cf20b 100644
--- a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
+++ b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
@@ -682,6 +682,8 @@ DecodeStatus RISCVDisassembler::getInstruction32(MCInst 
&MI, uint64_t &Size,
 "CORE-V SIMD extensions custom opcode table");
   TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXCVbi, DecoderTableXCVbi32,
 "CORE-V Immediate Branching custom opcode table");
+  TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXqcicsr, DecoderTableXqcicsr32,
+"Qualcomm uC CSR custom opcode table");
   TRY_TO_DECODE(true, DecoderTable32, "RISCV32 table");
 
   return MCDisassembler::Fail;

diff  --git a/llvm/lib/Target/RISCV/RISCVFeatures.td 
b/llvm/lib/Target/RISCV/RISCVFeatures.td
index 3fb76c77e32fd7..a579d9d0282d52 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -1341,6 +1341,16 @@ def HasVendorXwchc
   AssemblerPredicate<(all_of FeatureVendorXwchc),
  "'Xwchc' (WCH/QingKe additional compressed opcodes)">;
 
+// Qualcomm Extension(s)
+
+def FeatureVendorXqcicsr
+: RISCVExperimentalExtension<"xqcicsr", 0, 2,
+ "'Xqcicsr' (Qualcomm uC CSR Extension)">;
+def HasVendorXqcicsr
+: Predicate<"Subtarget->hasVendorXqcicsr()">,
+  AssemblerPredicate<(all_of Featu

[clang] [llvm] [RISCV] Add Qualcomm uC Xqcicsr (CSR) extension (PR #117169)

2024-11-27 Thread Sudharsan Veeravalli via cfe-commits

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


[clang] 8358437 - [clang-repl]: Print stack-trace on crash (#117896)

2024-11-27 Thread via cfe-commits

Author: Mészáros Gergely
Date: 2024-11-27T17:42:17+01:00
New Revision: 8358437bbb5b06d9aebc2940475a5a4d86c091c9

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

LOG: [clang-repl]: Print stack-trace on crash (#117896)

Call `llvm::sys::PrintStackTraceOnErrorSignal` at the start of main to
1. Print a strack trace on crash
2. Disable the assertion failed popup in Windows Debug Builds

Other tools (for example clang-check or clang-query) already do this.

This fixes debug build bots on windows hanging (waiting for the popup to
be dismissed) and ultimately getting terminated due to timeout.

Added: 


Modified: 
clang/tools/clang-repl/ClangRepl.cpp

Removed: 




diff  --git a/clang/tools/clang-repl/ClangRepl.cpp 
b/clang/tools/clang-repl/ClangRepl.cpp
index 08c54e6cafa901..7af8e4f25d99e7 100644
--- a/clang/tools/clang-repl/ClangRepl.cpp
+++ b/clang/tools/clang-repl/ClangRepl.cpp
@@ -139,6 +139,8 @@ ReplListCompleter::operator()(llvm::StringRef Buffer, 
size_t Pos,
 
 llvm::ExitOnError ExitOnErr;
 int main(int argc, const char **argv) {
+  llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
+
   ExitOnErr.setBanner("clang-repl: ");
   llvm::cl::ParseCommandLineOptions(argc, argv);
 



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


[clang-tools-extra] Covrt issue (PR #117769)

2024-11-27 Thread Zahira Ammarguellat via cfe-commits

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


[clang] [clang] Implement statement printer for EmbedExpr (PR #117770)

2024-11-27 Thread via cfe-commits


@@ -3902,6 +3902,8 @@ void Preprocessor::HandleEmbedDirectiveImpl(
   }
 
   EmbedAnnotationData *Data = new (BP) EmbedAnnotationData;
+  Data->Filename = Filename;
+  Data->IsAngled = IsAngled;
   Data->BinaryData = BinaryContents;

circl-lastname wrote:

What if it's something like a flexible array member and the EmbedAnnotationData 
is allocated to the right size the first time?

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


[clang] [llvm] Support for dispatch construct (Sema & Codegen) support. (PR #117904)

2024-11-27 Thread Alexey Bataev via cfe-commits


@@ -5965,6 +5967,244 @@ static bool teamsLoopCanBeParallelFor(Stmt *AStmt, Sema 
&SemaRef) {
   return Checker.teamsLoopCanBeParallelFor();
 }
 
+static Expr *getInitialExprFromCapturedExpr(Expr *Cond) {
+
+  Expr *SubExpr = Cond->IgnoreParenImpCasts();
+
+  if (auto *DeclRef = dyn_cast(SubExpr)) {
+if (auto *CapturedExprDecl =
+dyn_cast(DeclRef->getDecl())) {
+
+  // Retrieve the initial expression from the captured expression
+  return CapturedExprDecl->getInit();
+}
+  }
+  return nullptr;
+}
+
+static Expr *copy_removePseudoObjectExpr(const ASTContext &Context, Expr *E,
+ SemaOpenMP *SemaPtr, bool NoContext) {
+
+  BinaryOperator *BinaryCopyOpr = NULL;
+  bool BinaryOp = false;
+  if (E->getStmtClass() == Stmt::BinaryOperatorClass) {

alexey-bataev wrote:

I rather doubt this is a good check, better to use dyn_cast

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


[clang] [lldb] [Clang] Improve Sema diagnostic performance for __builtin_counted_by_ref (PR #116719)

2024-11-27 Thread Bill Wendling via cfe-commits

https://github.com/bwendling updated 
https://github.com/llvm/llvm-project/pull/116719

>From 2dcf18163de2ccce959f46bf82df1fa40e3fd1fc Mon Sep 17 00:00:00 2001
From: Bill Wendling 
Date: Fri, 15 Nov 2024 15:41:48 -0800
Subject: [PATCH 1/9] [Clang] Improve Sema diagnostic performance for
 __builtin_counted_by_ref

Implement the sema checks with a placeholder. We then check for that
placeholder in all of the places we care to emit a diagnostic.
---
 clang/include/clang/AST/ASTContext.h  |   1 +
 clang/include/clang/AST/BuiltinTypes.def  |   3 +
 .../clang/Basic/DiagnosticSemaKinds.td|   2 +-
 .../include/clang/Serialization/ASTBitCodes.h |   5 +-
 clang/lib/AST/ASTContext.cpp  |   4 +
 clang/lib/AST/NSAPI.cpp   |   1 +
 clang/lib/AST/Type.cpp|   3 +
 clang/lib/AST/TypeLoc.cpp |   1 +
 clang/lib/Sema/SemaChecking.cpp   |   1 +
 clang/lib/Sema/SemaDecl.cpp   |  11 ++
 clang/lib/Sema/SemaExpr.cpp   | 138 +-
 clang/lib/Sema/SemaStmt.cpp   |  10 ++
 clang/lib/Serialization/ASTCommon.cpp |   3 +
 clang/lib/Serialization/ASTReader.cpp |   3 +
 clang/test/Modules/no-external-type-id.cppm   |   2 +-
 clang/test/Sema/builtin-counted-by-ref.c  |  77 +-
 .../TypeSystem/Clang/TypeSystemClang.cpp  |   2 +
 17 files changed, 154 insertions(+), 113 deletions(-)

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 89fcb6789d880a..39cad95d911a33 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1184,6 +1184,7 @@ class ASTContext : public RefCountedBase {
   CanQualType DependentTy, OverloadTy, BoundMemberTy, UnresolvedTemplateTy,
   UnknownAnyTy;
   CanQualType BuiltinFnTy;
+  CanQualType BuiltinCountedByRefTy;
   CanQualType PseudoObjectTy, ARCUnbridgedCastTy;
   CanQualType ObjCBuiltinIdTy, ObjCBuiltinClassTy, ObjCBuiltinSelTy;
   CanQualType ObjCBuiltinBoolTy;
diff --git a/clang/include/clang/AST/BuiltinTypes.def 
b/clang/include/clang/AST/BuiltinTypes.def
index 444be4311a7431..4eae6962a46de6 100644
--- a/clang/include/clang/AST/BuiltinTypes.def
+++ b/clang/include/clang/AST/BuiltinTypes.def
@@ -314,6 +314,9 @@ PLACEHOLDER_TYPE(UnknownAny, UnknownAnyTy)
 
 PLACEHOLDER_TYPE(BuiltinFn, BuiltinFnTy)
 
+// A placeholder type for __builtin_counted_by_ref.
+PLACEHOLDER_TYPE(BuiltinCountedByRef, BuiltinCountedByRefTy)
+
 // The type of a cast which, in ARC, would normally require a
 // __bridge, but which might be okay depending on the immediate
 // context.
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 3caf471d3037f9..37fb44d4bf74cd 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6673,7 +6673,7 @@ def err_builtin_counted_by_ref_must_be_flex_array_member 
: Error<
 def err_builtin_counted_by_ref_cannot_leak_reference : Error<
   "value returned by '__builtin_counted_by_ref' cannot be assigned to a "
   "variable, have its address taken, or passed into or returned from a 
function">;
-def err_builtin_counted_by_ref_invalid_lhs_use : Error<
+def err_builtin_counted_by_ref_invalid_use : Error<
   "value returned by '__builtin_counted_by_ref' cannot be used in "
   "%select{an array subscript|a binary}0 expression">;
 def err_builtin_counted_by_ref_has_side_effects : Error<
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index fd834c14ce790f..f4b71861968e77 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -,6 +,9 @@ enum PredefinedTypeIDs {
   /// \brief The '__ibm128' type
   PREDEF_TYPE_IBM128_ID = 74,
 
+  /// \brief The placeholder type for __builtin_counted_by_ref.
+  PREDEF_TYPE_BUILTIN_COUNTED_BY_REF = 75,
+
 /// OpenCL image types with auto numeration
 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix)   
\
   PREDEF_TYPE_##Id##_ID,
@@ -1148,7 +1151,7 @@ enum PredefinedTypeIDs {
 ///
 /// Type IDs for non-predefined types will start at
 /// NUM_PREDEF_TYPE_IDs.
-const unsigned NUM_PREDEF_TYPE_IDS = 513;
+const unsigned NUM_PREDEF_TYPE_IDS = 514;
 
 // Ensure we do not overrun the predefined types we reserved
 // in the enum PredefinedTypeIDs above.
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 14fbadbc35ae5d..06226afaf23aab 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1390,6 +1390,10 @@ void ASTContext::InitBuiltinTypes(const TargetInfo 
&Target,
   if (LangOpts.MatrixTypes)
 InitBuiltinType(IncompleteMatrixIdxTy, BuiltinType::IncompleteMatrixIdx);
 
+  // Placeholder for __builtin_counted_by_ref().
+  if (!LangOpts.CPlusPlus)
+InitBuiltinType(

[clang] [lldb] [Clang] Improve Sema diagnostic performance for __builtin_counted_by_ref (PR #116719)

2024-11-27 Thread Bill Wendling via cfe-commits

bwendling wrote:

Fine.

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


[clang] b185b85 - [Clang] Improve Sema diagnostic performance for __builtin_counted_by_ref (#116719)

2024-11-27 Thread via cfe-commits

Author: Bill Wendling
Date: 2024-11-27T17:42:32Z
New Revision: b185b8512b2c7bf92ba87ea260a7b94d71dec4ee

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

LOG: [Clang] Improve Sema diagnostic performance for __builtin_counted_by_ref 
(#116719)

Implement the sema checks with a placeholder. We then check for that
placeholder in all of the places we care to emit a diagnostic.

Fixes: #115520

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaStmt.cpp
clang/test/Sema/builtin-counted-by-ref.c

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c1cdd811db446d..1d777f670097b5 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6670,14 +6670,15 @@ def warn_counted_by_attr_elt_type_unknown_size :
 // __builtin_counted_by_ref diagnostics:
 def err_builtin_counted_by_ref_must_be_flex_array_member : Error<
   "'__builtin_counted_by_ref' argument must reference a flexible array 
member">;
+def err_builtin_counted_by_ref_has_side_effects : Error<
+  "'__builtin_counted_by_ref' argument cannot have side-effects">;
+
 def err_builtin_counted_by_ref_cannot_leak_reference : Error<
-  "value returned by '__builtin_counted_by_ref' cannot be assigned to a "
-  "variable, have its address taken, or passed into or returned from a 
function">;
-def err_builtin_counted_by_ref_invalid_lhs_use : Error<
+  "value returned by '__builtin_counted_by_ref' cannot be %select{assigned to 
a "
+  "variable|passed into a function|returned from a function}0">;
+def err_builtin_counted_by_ref_invalid_use : Error<
   "value returned by '__builtin_counted_by_ref' cannot be used in "
   "%select{an array subscript|a binary}0 expression">;
-def err_builtin_counted_by_ref_has_side_effects : Error<
-  "'__builtin_counted_by_ref' argument cannot have side-effects">;
 
 let CategoryName = "ARC Semantic Issue" in {
 

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 24abd5d95dd844..b8684d11460eda 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2524,6 +2524,17 @@ class Sema final : public SemaBase {
 
   bool BuiltinNonDeterministicValue(CallExpr *TheCall);
 
+  enum BuiltinCountedByRefKind {
+AssignmentKind,
+InitializerKind,
+FunctionArgKind,
+ReturnArgKind,
+ArraySubscriptKind,
+BinaryExprKind,
+  };
+
+  bool CheckInvalidBuiltinCountedByRef(const Expr *E,
+   BuiltinCountedByRefKind K);
   bool BuiltinCountedByRef(CallExpr *TheCall);
 
   // Matrix builtin handling.

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index a49605e4867651..e071e2b7f33500 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5664,6 +5664,45 @@ bool Sema::BuiltinCountedByRef(CallExpr *TheCall) {
   return false;
 }
 
+/// The result of __builtin_counted_by_ref cannot be assigned to a variable.
+/// It allows leaking and modification of bounds safety information.
+bool Sema::CheckInvalidBuiltinCountedByRef(const Expr *E,
+   BuiltinCountedByRefKind K) {
+  const CallExpr *CE =
+  E ? dyn_cast(E->IgnoreParenImpCasts()) : nullptr;
+  if (!CE || CE->getBuiltinCallee() != Builtin::BI__builtin_counted_by_ref)
+return false;
+
+  switch (K) {
+  case AssignmentKind:
+  case InitializerKind:
+Diag(E->getExprLoc(),
+ diag::err_builtin_counted_by_ref_cannot_leak_reference)
+<< 0 << E->getSourceRange();
+break;
+  case FunctionArgKind:
+Diag(E->getExprLoc(),
+ diag::err_builtin_counted_by_ref_cannot_leak_reference)
+<< 1 << E->getSourceRange();
+break;
+  case ReturnArgKind:
+Diag(E->getExprLoc(),
+ diag::err_builtin_counted_by_ref_cannot_leak_reference)
+<< 2 << E->getSourceRange();
+break;
+  case ArraySubscriptKind:
+Diag(E->getExprLoc(), diag::err_builtin_counted_by_ref_invalid_use)
+<< 0 << E->getSourceRange();
+break;
+  case BinaryExprKind:
+Diag(E->getExprLoc(), diag::err_builtin_counted_by_ref_invalid_use)
+<< 1 << E->getSourceRange();
+break;
+  }
+
+  return true;
+}
+
 namespace {
 
 class UncoveredArgHandler {

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 63897dd7a319c2..c33701c0157714 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -14699,6 +14699,8 @@ void Sema::FinalizeDeclaration(Decl *ThisDecl) {
   

[clang] [lldb] [Clang] Improve Sema diagnostic performance for __builtin_counted_by_ref (PR #116719)

2024-11-27 Thread Bill Wendling via cfe-commits

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


[clang] [clang-tools-extra] [clang-tidy][use-internal-linkage]fix false positives for ExportDecl (PR #117901)

2024-11-27 Thread Piotr Zegar via cfe-commits

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

Documentation & Test for matcher is missing.
Except that everything looks ok.

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


[clang] [clang-tools-extra] [clang-tidy][use-internal-linkage]fix false positives for ExportDecl (PR #117901)

2024-11-27 Thread Piotr Zegar via cfe-commits


@@ -1236,6 +1236,17 @@ AST_MATCHER_P(TemplateArgument, equalsIntegralValue,
 extern const internal::VariadicDynCastAllOfMatcher autoreleasePoolStmt;
 
+/// Matches any export declaration.
+///
+/// Example matches following declarations.
+/// \code
+///   export void foo();
+///   export { void foo(); }
+///   export namespace { void foo(); }
+///   export int v;
+/// \endcode
+extern const internal::VariadicDynCastAllOfMatcher 
exportDecl;

PiotrZSL wrote:

Documentation for this matcher need to be updated so it would be visible on 
https://clang.llvm.org/docs/LibASTMatchersReference.html

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


[clang] [clang-tools-extra] [clang-tidy][use-internal-linkage]fix false positives for ExportDecl (PR #117901)

2024-11-27 Thread Piotr Zegar via cfe-commits


@@ -1236,6 +1236,17 @@ AST_MATCHER_P(TemplateArgument, equalsIntegralValue,
 extern const internal::VariadicDynCastAllOfMatcher autoreleasePoolStmt;
 
+/// Matches any export declaration.
+///
+/// Example matches following declarations.
+/// \code
+///   export void foo();
+///   export { void foo(); }
+///   export namespace { void foo(); }
+///   export int v;
+/// \endcode
+extern const internal::VariadicDynCastAllOfMatcher 
exportDecl;

PiotrZSL wrote:

Test for this matcher should be added (outside clang-tidy).

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


[clang] [Clang] Add "extend lifetime" flags and release note (PR #110000)

2024-11-27 Thread Stephen Tozer via cfe-commits


@@ -2217,6 +2217,11 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions 
&Opts, ArgList &Args,
   Args.getAllArgValues(OPT_fsanitize_trap_EQ), Diags,
   Opts.SanitizeTrap);
 
+  Opts.ExtendThisPtr =
+  Opts.OptimizationLevel > 0 && Args.hasArg(OPT_fextend_this_ptr);

SLTozer wrote:

I'm currently looking into this to see if there would be any notable negative 
consequences, but for now I'm at least happy to move this to the [next patch 
along](https://github.com/llvm/llvm-project/pull/110102): in that patch, we 
emit fake uses for functions when `OptimizationLevel != 0` and _or_ we've 
passed `-disable-O0-optnone` - that at least gives the ability to pass `-O0 
-fextend-lifetimes` together if desired.

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


[clang] [HLSL] Add ByteAddressBuffer definition to HLSLExternalSemaSource #113477 (PR #116699)

2024-11-27 Thread via cfe-commits

https://github.com/joaosaffran updated 
https://github.com/llvm/llvm-project/pull/116699

>From 7210fcc7de181be6cad451ce1e885498c90c55fe Mon Sep 17 00:00:00 2001
From: Joao Saffran 
Date: Sat, 9 Nov 2024 01:34:16 +
Subject: [PATCH 01/15] adding definition

---
 clang/lib/Sema/HLSLExternalSemaSource.cpp | 10 +
 .../test/AST/HLSL/ByteAddressBuffer-AST.hlsl  | 41 +++
 2 files changed, 51 insertions(+)
 create mode 100644 clang/test/AST/HLSL/ByteAddressBuffer-AST.hlsl

diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp 
b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index 822202fd81dc89..100d5be5516767 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -710,6 +710,16 @@ void 
HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
 .addArraySubscriptOperators()
 .completeDefinition();
   });
+
+  Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "ByteAddressBuffer")
+ .Record;
+  onCompletion(Decl, [this](CXXRecordDecl *Decl) {
+setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, 
ResourceKind::RawBuffer,
+/*IsROV=*/true,
+/*RawBuffer=*/true)
+.addArraySubscriptOperators()
+.completeDefinition();
+  });
 }
 
 void HLSLExternalSemaSource::onCompletion(CXXRecordDecl *Record,
diff --git a/clang/test/AST/HLSL/ByteAddressBuffer-AST.hlsl 
b/clang/test/AST/HLSL/ByteAddressBuffer-AST.hlsl
new file mode 100644
index 00..013974369d033a
--- /dev/null
+++ b/clang/test/AST/HLSL/ByteAddressBuffer-AST.hlsl
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump 
-DEMPTY %s | FileCheck -check-prefix=EMPTY %s
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump %s 
| FileCheck %s
+
+
+// EMPTY: CXXRecordDecl 0x{{[0-9A-Fa-f]+}} <>  
implicit  class ByteAddressBuffer
+// EMPTY-NEXT: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final
+
+// There should be no more occurrences of ByteAddressBuffer
+// EMPTY-NOT: {{[^[:alnum:]]}}ByteAddressBuffer
+
+#ifndef EMPTY
+
+ByteAddressBuffer Buffer;
+
+#endif
+
+// CHECK: CXXRecordDecl 0x{{[0-9A-Fa-f]+}} <>  
implicit referenced  class ByteAddressBuffer 
definition
+
+
+// CHECK: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final
+// CHECK-NEXT: FieldDecl 0x{{[0-9A-Fa-f]+}} <>  
implicit h '__hlsl_resource_t
+// CHECK-SAME{LITERAL}: [[hlsl::resource_class(UAV)]]
+// CHECK-SAME{LITERAL}: [[hlsl::raw_buffer]]
+// CHECK-SAME{LITERAL}: [[hlsl::contained_type(char8_t)]]
+// CHECK-NEXT: HLSLResourceAttr 0x{{[0-9A-Fa-f]+}} <> Implicit 
RawBuffer
+
+// CHECK: CXXMethodDecl 0x{{[0-9A-Fa-f]+}} <>  
operator[] 'char8_t &const (unsigned int) const'
+// CHECK-NEXT: ParmVarDecl 0x{{[0-9A-Fa-f]+}} <>  
Idx 'unsigned int'
+// CHECK-NEXT: CompoundStmt 0x{{[0-9A-Fa-f]+}} <>
+// CHECK-NEXT: ReturnStmt 0x{{[0-9A-Fa-f]+}} <>
+// CHECK-NEXT: MemberExpr 0x{{[0-9A-Fa-f]+}} <> 'char8_t' lvalue 
.e 0x{{[0-9A-Fa-f]+}}
+// CHECK-NEXT: CXXThisExpr 0x{{[0-9A-Fa-f]+}} <> 'const 
hlsl::ByteAddressBuffer' lvalue implicit this
+// CHECK-NEXT: AlwaysInlineAttr 0x{{[0-9A-Fa-f]+}} <> Implicit 
always_inline
+
+// CHECK-NEXT: CXXMethodDecl 0x{{[0-9A-Fa-f]+}} <>  operator[] 'char8_t &(unsigned int)'
+// CHECK-NEXT: ParmVarDecl 0x{{[0-9A-Fa-f]+}} <>  
Idx 'unsigned int'
+// CHECK-NEXT: CompoundStmt 0x{{[0-9A-Fa-f]+}} <>
+// CHECK-NEXT: ReturnStmt 0x{{[0-9A-Fa-f]+}} <>
+// CHECK-NEXT: MemberExpr 0x{{[0-9A-Fa-f]+}} <> 'char8_t' lvalue 
.e 0x{{[0-9A-Fa-f]+}}
+// CHECK-NEXT: CXXThisExpr 0x{{[0-9A-Fa-f]+}} <> 
'hlsl::ByteAddressBuffer' lvalue implicit this
+// CHECK-NEXT: AlwaysInlineAttr 0x{{[0-9A-Fa-f]+}} <> Implicit 
always_inline

>From b1f6a9468e01619d38ae3c5283381c566c130108 Mon Sep 17 00:00:00 2001
From: Joao Saffran 
Date: Mon, 18 Nov 2024 21:11:47 +
Subject: [PATCH 02/15] adding tests

---
 clang/test/AST/HLSL/ByteAddressBuffer-AST.ll| 13 +
 .../CodeGenHLSL/builtins/ByteAddressBuffer.hlsl |  8 
 2 files changed, 21 insertions(+)
 create mode 100644 clang/test/AST/HLSL/ByteAddressBuffer-AST.ll
 create mode 100644 clang/test/CodeGenHLSL/builtins/ByteAddressBuffer.hlsl

diff --git a/clang/test/AST/HLSL/ByteAddressBuffer-AST.ll 
b/clang/test/AST/HLSL/ByteAddressBuffer-AST.ll
new file mode 100644
index 00..7df06100d69fe5
--- /dev/null
+++ b/clang/test/AST/HLSL/ByteAddressBuffer-AST.ll
@@ -0,0 +1,13 @@
+; ModuleID = 
'/workspace/llvm-project/clang/test/AST/HLSL/ByteAddressBuffer-AST.hlsl'
+source_filename = 
"/workspace/llvm-project/clang/test/AST/HLSL/ByteAddressBuffer-AST.hlsl"
+target datalayout = 
"e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:32-f64:64-n8:16:32:64"
+target triple = "dxilv1.0-pc-shadermodel6.0-library"
+
+!llvm.module.flags = !{!0, !1}
+!dx.valver = !{!2}
+!llvm.ident = !{!3}
+
+!0 = !{i32 1, !"wchar_size", i32 4}
+!1 = !{i32 4, !"dx.disable_optimizations", i32 1}
+!2 = !{i32 1, i32 8}
+!3 = !{!"clang v

[clang] [clang] Add source range to 'use of undeclared identifier' diagnostics (PR #117671)

2024-11-27 Thread Aaron Ballman via cfe-commits
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


AaronBallman wrote:

> but this is not a bug introduced by the changes, rather, the newly supplied 
> (valid!) source ranges now get taken into account in 
> `checkRangesForMacroArgExpansion()` in `Frontend/DiagnosticRenderer.cpp`.

Yeah, I think we need to solve that before moving forward with the changes, 
which is why this keeps not being improved. (It always seems to come back to 
bite us when we decide that invalid source locations are an in-band indicator 
of anything.)

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


[clang] [lldb] [Clang] Improve Sema diagnostic performance for __builtin_counted_by_ref (PR #116719)

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


@@ -14690,6 +14690,13 @@ void Sema::FinalizeDeclaration(Decl *ThisDecl) {
 }
   }
 
+  // The result of __builtin_counted_by_ref cannot be assigned to a variable.
+  // It allows leaking and modification of bounds safety information.
+  if (IsBuiltinCountedByRef(VD->getInit()))
+Diag(VD->getInit()->getExprLoc(),
+ diag::err_builtin_counted_by_ref_cannot_leak_reference)
+<< VD->getInit()->getSourceRange();

AaronBallman wrote:

It is the same in every case. Each time, the logic is:
```
if (IsBuiltinCountedByRef(SomeExpr))
  Diag(SomeExpr->getExprLoc(), 
diag::err_builtin_counted_by_ref_cannot_leak_reference) << 
SomeExpr->getSourceRange();
```
This would require changing some later to this equivalent:
```
  auto CheckBuiltinCountedByRef = [&](const Expr *E) {
if (BinaryOperator::isAssignmentOp(Opc))
  CheckInvalidBuiltinCountedByRef(E);
else if (IsBuiltinCountedByRef(E))
Diag(E->getExprLoc(), diag::err_builtin_counted_by_ref_invalid_use)
<< 1 << E->getSourceRange();
  };
```

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


[clang] [llvm] [RISCV] Add stack clash protection (PR #117612)

2024-11-27 Thread Raphael Moreira Zinsly via cfe-commits


@@ -610,22 +610,134 @@ static MCCFIInstruction createDefCFAOffset(const 
TargetRegisterInfo &TRI,
 Comment.str());
 }
 
+// Allocate stack space and probe it if necessary.
 void RISCVFrameLowering::allocateStack(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MBBI,
-   StackOffset Offset, bool EmitCFI,
-   unsigned CFIIndex) const {

rzinsly wrote:

Ok, I created a opened a new one: 
https://github.com/llvm/llvm-project/pull/117871

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


[clang] [lldb] [Clang] Improve Sema diagnostic performance for __builtin_counted_by_ref (PR #116719)

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

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

LGTM modulo the request for a helper function (that two reviewers asked for the 
same thing is a pretty reasonable indication that we should probably have the 
helper, but if you feel strongly about it, I won't block the PR over it).

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


[clang] [Clang] Add [[clang::no_specializations]] (PR #101469)

2024-11-27 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

@AaronBallman @cor3ntin are you happy as well?

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


[clang] [analyzer] Modernize, improve and promote chroot checker (PR #117791)

2024-11-27 Thread via cfe-commits


@@ -104,15 +146,35 @@ void ChrootChecker::evalChdir(const CallEvent &Call, 
CheckerContext &C) const {
 R = R->StripCasts();
 if (const StringRegion* StrRegion= dyn_cast(R)) {
   const StringLiteral* Str = StrRegion->getStringLiteral();
-  if (Str->getString() == "/")
-state = Mgr.addGDM(state, ChrootChecker::getTag(),
-   (void*) JAIL_ENTERED);
+  if (Str->getString() == "/") {

vabridgers wrote:

Understood, will address. 

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


[clang] [analyzer] Modernize, improve and promote chroot checker (PR #117791)

2024-11-27 Thread via cfe-commits


@@ -121,17 +183,40 @@ void ChrootChecker::checkPreCall(const CallEvent &Call,
 return;
 
   // If jail state is ROOT_CHANGED, generate BugReport.
-  void *const* k = C.getState()->FindGDM(ChrootChecker::getTag());
-  if (k)
-if (isRootChanged((intptr_t) *k))
-  if (ExplodedNode *N = C.generateNonFatalErrorNode()) {
-constexpr llvm::StringLiteral Msg =
-"No call of chdir(\"/\") immediately after chroot";
-C.emitReport(
-std::make_unique(BT_BreakJail, Msg, N));
-  }
+  const ChrootKind k = C.getState()->get();
+  if (k == ROOT_CHANGED) {

vabridgers wrote:

Understood. Will address.

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


[clang] [analyzer] Modernize, improve and promote chroot checker (PR #117791)

2024-11-27 Thread via cfe-commits


@@ -121,17 +183,40 @@ void ChrootChecker::checkPreCall(const CallEvent &Call,
 return;
 
   // If jail state is ROOT_CHANGED, generate BugReport.
-  void *const* k = C.getState()->FindGDM(ChrootChecker::getTag());
-  if (k)
-if (isRootChanged((intptr_t) *k))
-  if (ExplodedNode *N = C.generateNonFatalErrorNode()) {
-constexpr llvm::StringLiteral Msg =
-"No call of chdir(\"/\") immediately after chroot";
-C.emitReport(
-std::make_unique(BT_BreakJail, Msg, N));
-  }
+  const ChrootKind k = C.getState()->get();

vabridgers wrote:

Understood, will address. 

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


[clang] f67ba58 - [Clang] replace 'bitfield' with 'bit-field' for consistency (#117881)

2024-11-27 Thread via cfe-commits

Author: Oleksandr T.
Date: 2024-11-27T17:09:41+02:00
New Revision: f67ba5855278401728413431216dda5d370ac2e0

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

LOG: [Clang] replace 'bitfield' with 'bit-field' for consistency (#117881)

Fixes #117711

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticASTKinds.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/test/Modules/compare-record.c
clang/test/Modules/odr_hash.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index 6a658cf14356f5..f630698757c5fb 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -782,8 +782,8 @@ def err_module_odr_violation_field : Error<
   "%select{"
   "field %4|"
   "field %4 with type %5|"
-  "%select{non-|}5bitfield %4|"
-  "bitfield %4 with one width expression|"
+  "%select{non-|}5bit-field %4|"
+  "bit-field %4 with one width expression|"
   "%select{non-|}5mutable field %4|"
   "field %4 with %select{no|an}5 initializer|"
   "field %4 with an initializer"
@@ -793,8 +793,8 @@ def note_module_odr_violation_field : Note<
   "%select{"
   "field %3|"
   "field %3 with type %4|"
-  "%select{non-|}4bitfield %3|"
-  "bitfield %3 with 
diff erent width expression|"
+  "%select{non-|}4bit-field %3|"
+  "bit-field %3 with 
diff erent width expression|"
   "%select{non-|}4mutable field %3|"
   "field %3 with %select{no|an}4 initializer|"
   "field %3 with a 
diff erent initializer"

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 3317c4e93199b0..c1cdd811db446d 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6417,7 +6417,7 @@ def warn_signed_bitfield_enum_conversion : Warning<
   "enumerators of %1">,
   InGroup, DefaultIgnore;
 def note_change_bitfield_sign : Note<
-  "consider making the bitfield type %select{unsigned|signed}0">;
+  "consider making the bit-field type %select{unsigned|signed}0">;
 
 def warn_missing_braces : Warning<
   "suggest braces around initialization of subobject">,

diff  --git a/clang/test/Modules/compare-record.c 
b/clang/test/Modules/compare-record.c
index 60998696969e12..ef4a3a5b0e90db 100644
--- a/clang/test/Modules/compare-record.c
+++ b/clang/test/Modules/compare-record.c
@@ -226,17 +226,17 @@ struct CompareBitfieldWidthExpression {
 #else
 struct CompareMatchingBitfields compareMatchingBitfields;
 struct CompareBitfieldPresence1 compareBitfieldPresence1;
-// expected-error@first.h:* {{'CompareBitfieldPresence1' has 
diff erent definitions in 
diff erent modules; first 
diff erence is definition in module 'First.Hidden' found bitfield 
'bitfieldPresence1'}}
-// expected-note@second.h:* {{but in 'Second' found non-bitfield 
'bitfieldPresence1'}}
+// expected-error@first.h:* {{'CompareBitfieldPresence1' has 
diff erent definitions in 
diff erent modules; first 
diff erence is definition in module 'First.Hidden' found bit-field 
'bitfieldPresence1'}}
+// expected-note@second.h:* {{but in 'Second' found non-bit-field 
'bitfieldPresence1'}}
 struct CompareBitfieldPresence2 compareBitfieldPresence2;
-// expected-error@first.h:* {{'CompareBitfieldPresence2' has 
diff erent definitions in 
diff erent modules; first 
diff erence is definition in module 'First.Hidden' found non-bitfield 
'bitfieldPresence2'}}
-// expected-note@second.h:* {{but in 'Second' found bitfield 
'bitfieldPresence2'}}
+// expected-error@first.h:* {{'CompareBitfieldPresence2' has 
diff erent definitions in 
diff erent modules; first 
diff erence is definition in module 'First.Hidden' found non-bit-field 
'bitfieldPresence2'}}
+// expected-note@second.h:* {{but in 'Second' found bit-field 
'bitfieldPresence2'}}
 struct CompareBitfieldWidth compareBitfieldWidth;
-// expected-error@first.h:* {{'CompareBitfieldWidth' has 
diff erent definitions in 
diff erent modules; first 
diff erence is definition in module 'First.Hidden' found bitfield 
'bitfieldWidth' with one width expression}}
-// expected-note@second.h:* {{but in 'Second' found bitfield 'bitfieldWidth' 
with 
diff erent width expression}}
+// expected-error@first.h:* {{'CompareBitfieldWidth' has 
diff erent definitions in 
diff erent modules; first 
diff erence is definition in module 'First.Hidden' found bit-field 
'bitfieldWidth' with one width expression}}
+// expected-note@second.h:* {{but in 'Second' found bit-field 'bitfieldWidth' 
with 
diff erent width expression}}
 struct CompareBitfieldWidthExpression compareBitfieldWidthExpression;
-// expected-error@first.h:* {{'CompareBitfieldWidthExpression' has 
diff erent definitions in 
diff er

[clang] [clang] Allow delayed function instantiation at TU end if initial instantiation fails (PR #117167)

2024-11-27 Thread via cfe-commits

StefanPaulet wrote:

> I have a draft which implements the capture rule for deferred lambda 
> instantiation #105953 I've been too busy lately and haven't continued working 
> on this Pull Request.If you're interested,you can take a look at it.

Will look there, thanks

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


[clang] [analyzer] Modernize, improve and promote chroot checker (PR #117791)

2024-11-27 Thread via cfe-commits


@@ -121,17 +183,40 @@ void ChrootChecker::checkPreCall(const CallEvent &Call,
 return;
 
   // If jail state is ROOT_CHANGED, generate BugReport.
-  void *const* k = C.getState()->FindGDM(ChrootChecker::getTag());
-  if (k)
-if (isRootChanged((intptr_t) *k))
-  if (ExplodedNode *N = C.generateNonFatalErrorNode()) {
-constexpr llvm::StringLiteral Msg =
-"No call of chdir(\"/\") immediately after chroot";
-C.emitReport(
-std::make_unique(BT_BreakJail, Msg, N));
-  }
+  const ChrootKind k = C.getState()->get();
+  if (k == ROOT_CHANGED) {
+ExplodedNode *Err =
+C.generateNonFatalErrorNode(C.getState(), C.getPredecessor());
+if (!Err)
+  return;
+const Expr *ChrootExpr = C.getState()->get();
+
+const ExplodedNode *ChrootCallNode = getAcquisitionSite(Err, C);
+assert(ChrootCallNode && "Could not find place of stream opening.");
+
+PathDiagnosticLocation LocUsedForUniqueing;
+if (const Stmt *ChrootStmt = ChrootCallNode->getStmtForDiagnostics())
+  LocUsedForUniqueing = PathDiagnosticLocation::createBegin(
+  ChrootStmt, C.getSourceManager(),
+  ChrootCallNode->getLocationContext());

vabridgers wrote:

I took this pattern from the stream checker, I think. I'm wanting to create a 
more detailed warning message. The checker determines if chdir() was used in an 
unexpected way and the warning message needs to include information about a 
prior call to chroot() as a note and warning referring to chdir(). Now that I 
think about this, maybe this can be simplified. I'll work on it.

https://github.com/llvm/llvm-project/pull/117791
___
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-27 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea 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] [RISC-V] Add support for MIPS P8700 CPU (PR #117865)

2024-11-27 Thread Jessica Clarke via cfe-commits


@@ -0,0 +1,158 @@
+//===--- RISCVRemoveBackToBackBranches.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 "RISCV.h"
+#include "RISCVInstrInfo.h"
+#include "RISCVSubtarget.h"
+#include "llvm/ADT/Statistic.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/CodeGen/MachineBasicBlock.h"
+#include "llvm/CodeGen/MachineFunction.h"
+#include "llvm/CodeGen/MachineFunctionPass.h"
+#include "llvm/CodeGen/MachineInstr.h"
+#include "llvm/CodeGen/TargetSubtargetInfo.h"
+#include "llvm/Target/TargetMachine.h"
+
+using namespace llvm;
+
+#define DEBUG_TYPE "riscv-remove-back-to-back-branches"
+
+STATISTIC(NumInsertedAligments, "Number of aligments set");
+
+namespace {
+
+// According to the MIPS specification, there shouldn't be two conditional
+// branches in the same 8-byte aligned region of code.

jrtc27 wrote:

Thanks, that's reassuring and rather more palatable

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


[clang] [Clang] Add "extend lifetime" flags and release note (PR #110000)

2024-11-27 Thread Stephen Tozer via cfe-commits

SLTozer wrote:

This patch has been changed as a result of some other patches that have removed 
the need for the attribute that this patch once added. Since this patch does 
not emit fake uses (the actual emission of fake uses is added in the [next 
patch](https://github.com/llvm/llvm-project/pull/110102)), that leaves this 
patch in the awkward position of adding flags and a release note but not 
actually doing anything. I'd prefer to leave this patch separate though, 
because the next patch is already tricky to review - adding more to that patch 
would probably slow things down a bit.

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


[clang] [clang][sema] Add support and documentation for `__has_extension(c_fixed_enum)` (PR #117507)

2024-11-27 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/117507

>From a6c9b5ca52f35fe451a52c590ce93584c2b4f3ac Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Fri, 22 Nov 2024 19:06:29 -0500
Subject: [PATCH 1/8] Update LanguageExtensions.rst

---
 clang/docs/LanguageExtensions.rst | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 3c9078bcdf8118..1c400d87c4948b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1986,7 +1986,7 @@ Enumerations with a fixed underlying type
 -
 
 Clang provides support for C++11 enumerations with a fixed underlying type
-within Objective-C.  For example, one can write an enumeration type as:
+within Objective-C and C `prior to C23 
`_.  For example, one 
can write an enumeration type as:
 
 .. code-block:: c++
 
@@ -1998,6 +1998,9 @@ value, is ``unsigned char``.
 Use ``__has_feature(objc_fixed_enum)`` to determine whether support for fixed
 underlying types is available in Objective-C.
 
+Use ``__has_extension(c_fixed_enum)`` to determine whether support for fixed
+underlying types is available in C.
+
 Interoperability with C++11 lambdas
 ---
 

>From d9e06150893a723cfeee0e08a7b8e652f2facf5c Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 15:09:02 -0500
Subject: [PATCH 2/8] Updated Features.def to include c_fixed_enum. Updated
 enum.c test to check for support of enums with a fixed underlying type in C23
 and https://github.com/llvm/llvm-project/issues/116880
+#if __STDC_VERSION__ >= 202311L
+typedef enum : unsigned char { Pink, Black, Cyan } Color;
+#else
+_Static_assert(__has_extension(c_fixed_enum), "Ensure language extension 
support for enumerations with a fixed underlying type in = 202311L
 // FIXME: GCC picks __uint128_t as the underlying type for the enumeration
 // value and Clang picks unsigned long long.

>From 9fd4a259bea6df7c1e9db8e2c8fe79654937dc9a Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 15:57:31 -0500
Subject: [PATCH 3/8] Added c_fixed_enum as an extension. Cleaned up enum.c

---
 clang/include/clang/Basic/Features.def | 5 -
 clang/test/Sema/enum.c | 1 -
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index c63f4ab75deda2..ab963a876db342 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -131,7 +131,6 @@ FEATURE(objc_arc_fields, true)
 FEATURE(objc_arc_weak, LangOpts.ObjCWeak)
 FEATURE(objc_default_synthesize_properties, LangOpts.ObjC)
 FEATURE(objc_fixed_enum, LangOpts.ObjC)
-FEATURE(c_fixed_enum, true)
 FEATURE(objc_instancetype, LangOpts.ObjC)
 FEATURE(objc_kindof, LangOpts.ObjC)
 FEATURE(objc_modules, LangOpts.ObjC && LangOpts.Modules)
@@ -309,6 +308,10 @@ EXTENSION(datasizeof, LangOpts.CPlusPlus)
 
 FEATURE(cxx_abi_relative_vtable, LangOpts.CPlusPlus && 
LangOpts.RelativeCXXABIVTables)
 
+//Fixed enum feature and extension, to be relocated in this file
+FEATURE(c_fixed_enum, true)
+EXTENSION(c_fixed_enum, true)  
+
 // CUDA/HIP Features
 FEATURE(cuda_noinline_keyword, LangOpts.CUDA)
 EXTENSION(cuda_implicit_host_device_templates, LangOpts.CUDA && 
LangOpts.OffloadImplicitHostDeviceTemplates)
diff --git a/clang/test/Sema/enum.c b/clang/test/Sema/enum.c
index 053053192e4ad5..3b30b24a6c13f1 100644
--- a/clang/test/Sema/enum.c
+++ b/clang/test/Sema/enum.c
@@ -185,7 +185,6 @@ enum IncOverflow {
   V3 // pre-c23-warning {{incremented enumerator value which exceeds the range 
of 'int' is a C23 extension}}
 };
 
-
 #if __STDC_VERSION__ >= 202311L
 // FIXME: GCC picks __uint128_t as the underlying type for the enumeration
 // value and Clang picks unsigned long long.

>From 53ba18d1453b310fd778e0095b75faddf68ec75b Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 16:27:04 -0500
Subject: [PATCH 4/8] formatting changes

---
 clang/test/Sema/enum.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/clang/test/Sema/enum.c b/clang/test/Sema/enum.c
index 3b30b24a6c13f1..7b3f7d30e91d82 100644
--- a/clang/test/Sema/enum.c
+++ b/clang/test/Sema/enum.c
@@ -130,8 +130,6 @@ typedef struct Color NewColor; // expected-error {{use of 
'Color' with tag type
 typedef enum : unsigned char { Pink, Black, Cyan } Color; // 
expected-warning {{enumeration types with a fixed underlying type are a C23 
extension}}
 #endif
 
-
-
 // PR28903
 // In C it is valid to define tags inside enums.
 struct PR28903 {

>From 8722c53336e6073e3b521140a07c4c9c0aa18fdc Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Mon, 25 Nov 2024 11:14:02 -0500
Subject: [PATCH 5/8] fixed enum.c typed enum logic

---
 clang/test/Sema/enum.c | 7 ---
 1 

[clang] [clang][sema] Add support and documentation for `__has_extension(c_fixed_enum)` (PR #117507)

2024-11-27 Thread Aidan Goldfarb via cfe-commits


@@ -121,6 +121,14 @@ int NegativeShortTest[NegativeShort == -1 ? 1 : -1];
 enum Color { Red, Green, Blue }; // expected-note{{previous use is here}}
 typedef struct Color NewColor; // expected-error {{use of 'Color' with tag 
type that does not match previous declaration}}
 
+// Enumerations with a fixed underlying type. 
+// https://github.com/llvm/llvm-project/issues/116880
+#if __STDC_VERSION__ >= 202311L && !__has_extension(c_fixed_enum)

AidanGoldfarb wrote:

Updated this, my thought process was to check for `__has_extension()` when 
=C23. 
Previously I had only checked for `__has_extension()` when >=C23, which in my 
mind was both incomplete (`__has_feature()` missing) and incorrect 
(`__has_extension()` should be associated with >C23 not >=C23).

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


[clang] 1e3e199 - [Sema] Migrate away from PointerUnion::{is,get} (NFC) (#117498)

2024-11-27 Thread via cfe-commits

Author: Kazu Hirata
Date: 2024-11-27T09:13:28-08:00
New Revision: 1e3e199ed9f214594e358eb0c7892cdedc703f7a

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

LOG: [Sema] Migrate away from PointerUnion::{is,get} (NFC) (#117498)

Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //isa, cast and the llvm::dyn_cast

I'm not touching PointerUnion::dyn_cast for now because it's a bit
complicated; we could blindly migrate it to dyn_cast_if_present, but
we should probably use dyn_cast when the operand is known to be
non-null.

Added: 


Modified: 
clang/lib/Sema/SemaAPINotes.cpp
clang/lib/Sema/SemaCodeComplete.cpp
clang/lib/Sema/SemaConcept.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaDeclObjC.cpp
clang/lib/Sema/SemaFunctionEffects.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/lib/Sema/SemaTemplateVariadic.cpp
clang/lib/Sema/TreeTransform.h

Removed: 




diff  --git a/clang/lib/Sema/SemaAPINotes.cpp b/clang/lib/Sema/SemaAPINotes.cpp
index 028bf82f3e8040..0dedfc490c86fd 100644
--- a/clang/lib/Sema/SemaAPINotes.cpp
+++ b/clang/lib/Sema/SemaAPINotes.cpp
@@ -482,7 +482,7 @@ static void ProcessAPINotes(Sema &S, FunctionOrMethod 
AnyFunc,
   Decl *D = FD;
   ObjCMethodDecl *MD = nullptr;
   if (!D) {
-MD = AnyFunc.get();
+MD = cast(AnyFunc);
 D = MD;
   }
 

diff  --git a/clang/lib/Sema/SemaCodeComplete.cpp 
b/clang/lib/Sema/SemaCodeComplete.cpp
index 60ea1383b2a6ee..1f398bb004fa30 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -131,8 +131,8 @@ class ResultBuilder {
   }
 
   // Add the new element to the end of the vector.
-  DeclOrVector.get()->push_back(
-  DeclIndexPair(ND, Index));
+  cast(DeclOrVector)
+  ->push_back(DeclIndexPair(ND, Index));
 }
 
 ~ShadowMapEntry() {
@@ -659,13 +659,13 @@ class ResultBuilder::ShadowMapEntry::iterator {
   : DeclOrIterator(Iterator), SingleDeclIndex(0) {}
 
   iterator &operator++() {
-if (DeclOrIterator.is()) {
+if (isa(DeclOrIterator)) {
   DeclOrIterator = (NamedDecl *)nullptr;
   SingleDeclIndex = 0;
   return *this;
 }
 
-const DeclIndexPair *I = DeclOrIterator.get();
+const DeclIndexPair *I = cast(DeclOrIterator);
 ++I;
 DeclOrIterator = I;
 return *this;
@@ -681,7 +681,7 @@ class ResultBuilder::ShadowMapEntry::iterator {
 if (const NamedDecl *ND = DeclOrIterator.dyn_cast())
   return reference(ND, SingleDeclIndex);
 
-return *DeclOrIterator.get();
+return *cast(DeclOrIterator);
   }
 
   pointer operator->() const { return pointer(**this); }
@@ -705,15 +705,15 @@ ResultBuilder::ShadowMapEntry::begin() const {
   if (const NamedDecl *ND = DeclOrVector.dyn_cast())
 return iterator(ND, SingleDeclIndex);
 
-  return iterator(DeclOrVector.get()->begin());
+  return iterator(cast(DeclOrVector)->begin());
 }
 
 ResultBuilder::ShadowMapEntry::iterator
 ResultBuilder::ShadowMapEntry::end() const {
-  if (DeclOrVector.is() || DeclOrVector.isNull())
+  if (isa(DeclOrVector) || DeclOrVector.isNull())
 return iterator();
 
-  return iterator(DeclOrVector.get()->end());
+  return iterator(cast(DeclOrVector)->end());
 }
 
 /// Compute the qualification required to get from the current context

diff  --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 1bdf3a02b2924a..ff1df7b71b1a4f 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -1384,8 +1384,7 @@ static void diagnoseUnsatisfiedConstraintExpr(
 return;
   }
 
-  diagnoseWellFormedUnsatisfiedConstraintExpr(S,
-  Record.template get(), First);
+  diagnoseWellFormedUnsatisfiedConstraintExpr(S, cast(Record), First);
 }
 
 void
@@ -1557,12 +1556,12 @@ NormalizedConstraint::NormalizedConstraint(ASTContext 
&C,
 
 NormalizedConstraint &NormalizedConstraint::getLHS() const {
   assert(isCompound() && "getLHS called on a non-compound constraint.");
-  return Constraint.get().getPointer()->LHS;
+  return cast(Constraint).getPointer()->LHS;
 }
 
 NormalizedConstraint &NormalizedConstraint::getRHS() const {
   assert(isCompound() && "getRHS called on a non-compound constraint.");
-  return Constraint.get().getPointer()->RHS;
+  return cast(Constraint).getPointer()->RHS;
 }
 
 std::optional

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 74b0e5ad23bd48..63897dd7a319c2 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -17276,7 +172

[clang] [clang-tools-extra] [clang] Avoid re-evaluating field bitwidth (PR #117732)

2024-11-27 Thread Erich Keane via cfe-commits
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


erichkeane wrote:

> Meh, saving a `ConstantExpr` in the `FieldDecl` doesn't work properly, since 
> we need to support having arbitrary exprs in case the bitwidth is dependent.

The idea is that you'd store an `Expr` like we do elsewhere, and then upon 
instantiating it/evaluating it, we'd replace it with a `ConstantExpr`.  So you 
don't need separate storage, just replace the current thing.

The instantiation of a `ConstantExpr` is to just return it, so you don't end up 
losing anything as a side effect.

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


[clang] [Sema] Migrate away from PointerUnion::{is, get} (NFC) (PR #117498)

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

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


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

2024-11-27 Thread via cfe-commits

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

LGTM

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


[clang] [clang][sema] Add support and documentation for `__has_extension(c_fixed_enum)` (PR #117507)

2024-11-27 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang][sema] Add support and documentation for `__has_extension(c_fixed_enum)` (PR #117507)

2024-11-27 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang][sema] Add support and documentation for `__has_extension(c_fixed_enum)` (PR #117507)

2024-11-27 Thread Aidan Goldfarb via cfe-commits

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


[clang] [llvm] Support for dispatch construct (Sema & Codegen) support. (PR #117904)

2024-11-27 Thread Alexey Bataev via cfe-commits

https://github.com/alexey-bataev commented:

Please, reformat your changes, follow coding standard, use nullptr instead of 
NULL, etc.

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


[clang] [llvm] Support for dispatch construct (Sema & Codegen) support. (PR #117904)

2024-11-27 Thread Alexey Bataev via cfe-commits


@@ -417,7 +417,8 @@ void CodeGenFunction::EmitStmt(const Stmt *S, 
ArrayRef Attrs) {
 EmitOMPInteropDirective(cast(*S));
 break;
   case Stmt::OMPDispatchDirectiveClass:
-CGM.ErrorUnsupported(S, "OpenMP dispatch directive");
+// CGM.ErrorUnsupported(S, "OpenMP dispatch directive");

alexey-bataev wrote:

Must be removed

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


[clang] [llvm] Support for dispatch construct (Sema & Codegen) support. (PR #117904)

2024-11-27 Thread Alexey Bataev via cfe-commits


@@ -5965,6 +5967,244 @@ static bool teamsLoopCanBeParallelFor(Stmt *AStmt, Sema 
&SemaRef) {
   return Checker.teamsLoopCanBeParallelFor();
 }
 
+static Expr *getInitialExprFromCapturedExpr(Expr *Cond) {
+
+  Expr *SubExpr = Cond->IgnoreParenImpCasts();
+
+  if (auto *DeclRef = dyn_cast(SubExpr)) {
+if (auto *CapturedExprDecl =
+dyn_cast(DeclRef->getDecl())) {
+
+  // Retrieve the initial expression from the captured expression
+  return CapturedExprDecl->getInit();
+}
+  }
+  return nullptr;
+}
+
+static Expr *copy_removePseudoObjectExpr(const ASTContext &Context, Expr *E,

alexey-bataev wrote:

function name does not match the LLVM coding standard

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


[clang] [llvm] Support for dispatch construct (Sema & Codegen) support. (PR #117904)

2024-11-27 Thread Alexey Bataev via cfe-commits


@@ -5965,6 +5967,244 @@ static bool teamsLoopCanBeParallelFor(Stmt *AStmt, Sema 
&SemaRef) {
   return Checker.teamsLoopCanBeParallelFor();
 }
 
+static Expr *getInitialExprFromCapturedExpr(Expr *Cond) {
+
+  Expr *SubExpr = Cond->IgnoreParenImpCasts();
+
+  if (auto *DeclRef = dyn_cast(SubExpr)) {
+if (auto *CapturedExprDecl =
+dyn_cast(DeclRef->getDecl())) {
+
+  // Retrieve the initial expression from the captured expression
+  return CapturedExprDecl->getInit();
+}
+  }
+  return nullptr;
+}
+
+static Expr *copy_removePseudoObjectExpr(const ASTContext &Context, Expr *E,
+ SemaOpenMP *SemaPtr, bool NoContext) {
+
+  BinaryOperator *BinaryCopyOpr = NULL;
+  bool BinaryOp = false;
+  if (E->getStmtClass() == Stmt::BinaryOperatorClass) {
+BinaryOp = true;
+BinaryOperator *E_BinOpr = static_cast(E);
+BinaryCopyOpr = BinaryOperator::Create(
+Context, E_BinOpr->getLHS(), E_BinOpr->getRHS(), E_BinOpr->getOpcode(),
+E_BinOpr->getType(), E_BinOpr->getValueKind(),
+E_BinOpr->getObjectKind(), E_BinOpr->getOperatorLoc(),
+FPOptionsOverride());
+E = BinaryCopyOpr->getRHS();
+  }
+
+  // Change PseudoObjectExpr to a direct call
+  if (PseudoObjectExpr *PO = dyn_cast(E))
+E = *((PO->semantics_begin()) - 1);
+
+  // Add new Traits to direct call to convert it to new PseudoObjectExpr
+  // This converts Traits for the function call from under "dispatch" to traits
+  // of direct function call not under "dispatch".
+  if (NoContext) {
+// Convert StmtResult to a CallExpr before calling ActOnOpenMPCall()
+CallExpr *CallExprWithinStmt = dyn_cast(E);
+int NumArgs = CallExprWithinStmt->getNumArgs();
+clang::Expr **Args = CallExprWithinStmt->getArgs();
+ExprResult er = SemaPtr->ActOnOpenMPCall(
+CallExprWithinStmt, SemaPtr->SemaRef.getCurScope(),
+CallExprWithinStmt->getBeginLoc(), MultiExprArg(Args, NumArgs),
+CallExprWithinStmt->getRParenLoc(), static_cast(nullptr));
+E = er.get();
+  }
+
+  if (BinaryOp) {
+BinaryCopyOpr->setRHS(E);
+return BinaryCopyOpr;
+  }
+
+  return E;
+}
+
+static StmtResult combine2Stmts(ASTContext &context, Stmt *first,
+Stmt *second) {
+
+  llvm::SmallVector newCombinedStmts;
+  newCombinedStmts.push_back(first);
+  newCombinedStmts.push_back(second); // Adding foo();
+  llvm::ArrayRef ar(newCombinedStmts);
+  CompoundStmt *CombinedStmt = CompoundStmt::Create(
+  context, ar, FPOptionsOverride(), SourceLocation(), SourceLocation());
+  StmtResult FinalStmts(CombinedStmt);
+  return FinalStmts;
+}
+
+template 
+static bool hasClausesOfKind(ArrayRef Clauses) {
+  auto ClausesOfKind =
+  OMPExecutableDirective::getClausesOfKind(Clauses);
+  return ClausesOfKind.begin() != ClausesOfKind.end();
+}
+
+// Get a CapturedStmt with direct call to function.
+// If there is a PseudoObjectExpr under the CapturedDecl
+// choose the first call under it for the direct call to function
+static StmtResult CloneNewCapturedStmtForDirectCall(const ASTContext &Context,
+Stmt *StmtP,
+SemaOpenMP *SemaPtr,
+bool NoContext) {
+  if (StmtP->getStmtClass() == Stmt::CapturedStmtClass) {
+CapturedStmt *AStmt = static_cast(StmtP);
+CapturedDecl *CDecl = AStmt->getCapturedDecl();
+Stmt *S = cast(AStmt)->getCapturedStmt();
+auto *E = dyn_cast(S);
+E = copy_removePseudoObjectExpr(Context, E, SemaPtr, NoContext);
+
+// Copy Current Captured Decl to a New Captured Decl for noting the
+// Annotation
+CapturedDecl *NewDecl =
+CapturedDecl::Create(const_cast(Context),
+ CDecl->getDeclContext(), CDecl->getNumParams());
+NewDecl->setBody(static_cast(E));
+for (unsigned i = 0; i < CDecl->getNumParams(); ++i) {
+  if (i != CDecl->getContextParamPosition())
+NewDecl->setParam(i, CDecl->getParam(i));
+  else
+NewDecl->setContextParam(i, CDecl->getContextParam());
+}
+
+// Create a New Captured Stmt containing the New Captured Decl
+SmallVector Captures;
+SmallVector CaptureInits;
+for (auto capture : AStmt->captures())
+  Captures.push_back(capture);
+for (auto capture_init : AStmt->capture_inits())
+  CaptureInits.push_back(capture_init);
+CapturedStmt *NewStmt = CapturedStmt::Create(
+Context, AStmt->getCapturedStmt(), AStmt->getCapturedRegionKind(),
+Captures, CaptureInits, NewDecl,
+const_cast(AStmt->getCapturedRecordDecl()));
+
+return NewStmt;
+  }
+  return static_cast(NULL);
+}
+
+StmtResult SemaOpenMP::transformDispatchDirective(
+OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName,
+OpenMPDirectiveKind CancelRegion, ArrayRef Clauses,
+Stmt *AStmt, SourceLocation Sta

[clang] [llvm] Support for dispatch construct (Sema & Codegen) support. (PR #117904)

2024-11-27 Thread Alexey Bataev via cfe-commits


@@ -5965,6 +5967,244 @@ static bool teamsLoopCanBeParallelFor(Stmt *AStmt, Sema 
&SemaRef) {
   return Checker.teamsLoopCanBeParallelFor();
 }
 
+static Expr *getInitialExprFromCapturedExpr(Expr *Cond) {
+
+  Expr *SubExpr = Cond->IgnoreParenImpCasts();
+
+  if (auto *DeclRef = dyn_cast(SubExpr)) {
+if (auto *CapturedExprDecl =
+dyn_cast(DeclRef->getDecl())) {
+
+  // Retrieve the initial expression from the captured expression
+  return CapturedExprDecl->getInit();
+}
+  }
+  return nullptr;
+}
+
+static Expr *copy_removePseudoObjectExpr(const ASTContext &Context, Expr *E,
+ SemaOpenMP *SemaPtr, bool NoContext) {
+
+  BinaryOperator *BinaryCopyOpr = NULL;
+  bool BinaryOp = false;

alexey-bataev wrote:

IsBinaryOp

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


[clang] [llvm] Support for dispatch construct (Sema & Codegen) support. (PR #117904)

2024-11-27 Thread Alexey Bataev via cfe-commits

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


[clang] [llvm] Support for dispatch construct (Sema & Codegen) support. (PR #117904)

2024-11-27 Thread Alexey Bataev via cfe-commits


@@ -5965,6 +5967,244 @@ static bool teamsLoopCanBeParallelFor(Stmt *AStmt, Sema 
&SemaRef) {
   return Checker.teamsLoopCanBeParallelFor();
 }
 
+static Expr *getInitialExprFromCapturedExpr(Expr *Cond) {
+
+  Expr *SubExpr = Cond->IgnoreParenImpCasts();
+
+  if (auto *DeclRef = dyn_cast(SubExpr)) {
+if (auto *CapturedExprDecl =
+dyn_cast(DeclRef->getDecl())) {
+
+  // Retrieve the initial expression from the captured expression
+  return CapturedExprDecl->getInit();
+}
+  }
+  return nullptr;
+}
+
+static Expr *copy_removePseudoObjectExpr(const ASTContext &Context, Expr *E,
+ SemaOpenMP *SemaPtr, bool NoContext) {
+
+  BinaryOperator *BinaryCopyOpr = NULL;
+  bool BinaryOp = false;
+  if (E->getStmtClass() == Stmt::BinaryOperatorClass) {
+BinaryOp = true;
+BinaryOperator *E_BinOpr = static_cast(E);
+BinaryCopyOpr = BinaryOperator::Create(
+Context, E_BinOpr->getLHS(), E_BinOpr->getRHS(), E_BinOpr->getOpcode(),
+E_BinOpr->getType(), E_BinOpr->getValueKind(),
+E_BinOpr->getObjectKind(), E_BinOpr->getOperatorLoc(),
+FPOptionsOverride());
+E = BinaryCopyOpr->getRHS();
+  }
+
+  // Change PseudoObjectExpr to a direct call
+  if (PseudoObjectExpr *PO = dyn_cast(E))
+E = *((PO->semantics_begin()) - 1);
+
+  // Add new Traits to direct call to convert it to new PseudoObjectExpr
+  // This converts Traits for the function call from under "dispatch" to traits
+  // of direct function call not under "dispatch".
+  if (NoContext) {
+// Convert StmtResult to a CallExpr before calling ActOnOpenMPCall()
+CallExpr *CallExprWithinStmt = dyn_cast(E);
+int NumArgs = CallExprWithinStmt->getNumArgs();
+clang::Expr **Args = CallExprWithinStmt->getArgs();
+ExprResult er = SemaPtr->ActOnOpenMPCall(
+CallExprWithinStmt, SemaPtr->SemaRef.getCurScope(),
+CallExprWithinStmt->getBeginLoc(), MultiExprArg(Args, NumArgs),
+CallExprWithinStmt->getRParenLoc(), static_cast(nullptr));
+E = er.get();
+  }
+
+  if (BinaryOp) {
+BinaryCopyOpr->setRHS(E);
+return BinaryCopyOpr;
+  }
+
+  return E;
+}
+
+static StmtResult combine2Stmts(ASTContext &context, Stmt *first,
+Stmt *second) {
+
+  llvm::SmallVector newCombinedStmts;
+  newCombinedStmts.push_back(first);
+  newCombinedStmts.push_back(second); // Adding foo();
+  llvm::ArrayRef ar(newCombinedStmts);
+  CompoundStmt *CombinedStmt = CompoundStmt::Create(
+  context, ar, FPOptionsOverride(), SourceLocation(), SourceLocation());
+  StmtResult FinalStmts(CombinedStmt);
+  return FinalStmts;
+}
+
+template 
+static bool hasClausesOfKind(ArrayRef Clauses) {
+  auto ClausesOfKind =
+  OMPExecutableDirective::getClausesOfKind(Clauses);
+  return ClausesOfKind.begin() != ClausesOfKind.end();
+}
+
+// Get a CapturedStmt with direct call to function.
+// If there is a PseudoObjectExpr under the CapturedDecl
+// choose the first call under it for the direct call to function
+static StmtResult CloneNewCapturedStmtForDirectCall(const ASTContext &Context,
+Stmt *StmtP,
+SemaOpenMP *SemaPtr,
+bool NoContext) {
+  if (StmtP->getStmtClass() == Stmt::CapturedStmtClass) {
+CapturedStmt *AStmt = static_cast(StmtP);

alexey-bataev wrote:

Use isa/dyn_cast

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


[clang] [llvm] Support for dispatch construct (Sema & Codegen) support. (PR #117904)

2024-11-27 Thread Alexey Bataev via cfe-commits


@@ -4452,6 +4452,11 @@ void CodeGenFunction::EmitOMPMasterDirective(const 
OMPMasterDirective &S) {
   emitMaster(*this, S);
 }
 
+void CodeGenFunction::EmitOMPDispatchDirective(const OMPDispatchDirective &S) {
+

alexey-bataev wrote:

Drop empty line

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


[clang] [llvm] Support for dispatch construct (Sema & Codegen) support. (PR #117904)

2024-11-27 Thread Alexey Bataev via cfe-commits


@@ -5965,6 +5967,244 @@ static bool teamsLoopCanBeParallelFor(Stmt *AStmt, Sema 
&SemaRef) {
   return Checker.teamsLoopCanBeParallelFor();
 }
 
+static Expr *getInitialExprFromCapturedExpr(Expr *Cond) {
+
+  Expr *SubExpr = Cond->IgnoreParenImpCasts();
+
+  if (auto *DeclRef = dyn_cast(SubExpr)) {
+if (auto *CapturedExprDecl =
+dyn_cast(DeclRef->getDecl())) {
+
+  // Retrieve the initial expression from the captured expression
+  return CapturedExprDecl->getInit();
+}
+  }
+  return nullptr;
+}
+
+static Expr *copy_removePseudoObjectExpr(const ASTContext &Context, Expr *E,
+ SemaOpenMP *SemaPtr, bool NoContext) {
+

alexey-bataev wrote:

Drop empty line

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


[clang] [llvm] Support for dispatch construct (Sema & Codegen) support. (PR #117904)

2024-11-27 Thread Alexey Bataev via cfe-commits


@@ -5965,6 +5967,244 @@ static bool teamsLoopCanBeParallelFor(Stmt *AStmt, Sema 
&SemaRef) {
   return Checker.teamsLoopCanBeParallelFor();
 }
 
+static Expr *getInitialExprFromCapturedExpr(Expr *Cond) {
+
+  Expr *SubExpr = Cond->IgnoreParenImpCasts();
+
+  if (auto *DeclRef = dyn_cast(SubExpr)) {
+if (auto *CapturedExprDecl =
+dyn_cast(DeclRef->getDecl())) {
+
+  // Retrieve the initial expression from the captured expression
+  return CapturedExprDecl->getInit();
+}
+  }
+  return nullptr;
+}
+
+static Expr *copy_removePseudoObjectExpr(const ASTContext &Context, Expr *E,
+ SemaOpenMP *SemaPtr, bool NoContext) {
+
+  BinaryOperator *BinaryCopyOpr = NULL;

alexey-bataev wrote:

Use nullptr

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


[clang] [llvm] Support for dispatch construct (Sema & Codegen) support. (PR #117904)

2024-11-27 Thread Alexey Bataev via cfe-commits


@@ -5965,6 +5967,244 @@ static bool teamsLoopCanBeParallelFor(Stmt *AStmt, Sema 
&SemaRef) {
   return Checker.teamsLoopCanBeParallelFor();
 }
 
+static Expr *getInitialExprFromCapturedExpr(Expr *Cond) {
+
+  Expr *SubExpr = Cond->IgnoreParenImpCasts();
+
+  if (auto *DeclRef = dyn_cast(SubExpr)) {
+if (auto *CapturedExprDecl =
+dyn_cast(DeclRef->getDecl())) {
+
+  // Retrieve the initial expression from the captured expression
+  return CapturedExprDecl->getInit();
+}
+  }
+  return nullptr;
+}
+
+static Expr *copy_removePseudoObjectExpr(const ASTContext &Context, Expr *E,
+ SemaOpenMP *SemaPtr, bool NoContext) {
+
+  BinaryOperator *BinaryCopyOpr = NULL;
+  bool BinaryOp = false;
+  if (E->getStmtClass() == Stmt::BinaryOperatorClass) {
+BinaryOp = true;
+BinaryOperator *E_BinOpr = static_cast(E);
+BinaryCopyOpr = BinaryOperator::Create(
+Context, E_BinOpr->getLHS(), E_BinOpr->getRHS(), E_BinOpr->getOpcode(),
+E_BinOpr->getType(), E_BinOpr->getValueKind(),
+E_BinOpr->getObjectKind(), E_BinOpr->getOperatorLoc(),
+FPOptionsOverride());
+E = BinaryCopyOpr->getRHS();
+  }
+
+  // Change PseudoObjectExpr to a direct call
+  if (PseudoObjectExpr *PO = dyn_cast(E))
+E = *((PO->semantics_begin()) - 1);
+
+  // Add new Traits to direct call to convert it to new PseudoObjectExpr
+  // This converts Traits for the function call from under "dispatch" to traits
+  // of direct function call not under "dispatch".
+  if (NoContext) {
+// Convert StmtResult to a CallExpr before calling ActOnOpenMPCall()
+CallExpr *CallExprWithinStmt = dyn_cast(E);
+int NumArgs = CallExprWithinStmt->getNumArgs();
+clang::Expr **Args = CallExprWithinStmt->getArgs();
+ExprResult er = SemaPtr->ActOnOpenMPCall(
+CallExprWithinStmt, SemaPtr->SemaRef.getCurScope(),
+CallExprWithinStmt->getBeginLoc(), MultiExprArg(Args, NumArgs),
+CallExprWithinStmt->getRParenLoc(), static_cast(nullptr));
+E = er.get();
+  }
+
+  if (BinaryOp) {
+BinaryCopyOpr->setRHS(E);
+return BinaryCopyOpr;
+  }
+
+  return E;
+}
+
+static StmtResult combine2Stmts(ASTContext &context, Stmt *first,
+Stmt *second) {

alexey-bataev wrote:

Variable names do not match coding standard

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


[clang] [llvm] Support for dispatch construct (Sema & Codegen) support. (PR #117904)

2024-11-27 Thread Alexey Bataev via cfe-commits


@@ -5965,6 +5967,244 @@ static bool teamsLoopCanBeParallelFor(Stmt *AStmt, Sema 
&SemaRef) {
   return Checker.teamsLoopCanBeParallelFor();
 }
 
+static Expr *getInitialExprFromCapturedExpr(Expr *Cond) {
+
+  Expr *SubExpr = Cond->IgnoreParenImpCasts();
+
+  if (auto *DeclRef = dyn_cast(SubExpr)) {
+if (auto *CapturedExprDecl =
+dyn_cast(DeclRef->getDecl())) {
+
+  // Retrieve the initial expression from the captured expression
+  return CapturedExprDecl->getInit();
+}
+  }
+  return nullptr;
+}
+
+static Expr *copy_removePseudoObjectExpr(const ASTContext &Context, Expr *E,
+ SemaOpenMP *SemaPtr, bool NoContext) {
+
+  BinaryOperator *BinaryCopyOpr = NULL;
+  bool BinaryOp = false;
+  if (E->getStmtClass() == Stmt::BinaryOperatorClass) {
+BinaryOp = true;
+BinaryOperator *E_BinOpr = static_cast(E);
+BinaryCopyOpr = BinaryOperator::Create(
+Context, E_BinOpr->getLHS(), E_BinOpr->getRHS(), E_BinOpr->getOpcode(),
+E_BinOpr->getType(), E_BinOpr->getValueKind(),
+E_BinOpr->getObjectKind(), E_BinOpr->getOperatorLoc(),
+FPOptionsOverride());
+E = BinaryCopyOpr->getRHS();
+  }
+
+  // Change PseudoObjectExpr to a direct call
+  if (PseudoObjectExpr *PO = dyn_cast(E))
+E = *((PO->semantics_begin()) - 1);
+
+  // Add new Traits to direct call to convert it to new PseudoObjectExpr
+  // This converts Traits for the function call from under "dispatch" to traits
+  // of direct function call not under "dispatch".
+  if (NoContext) {
+// Convert StmtResult to a CallExpr before calling ActOnOpenMPCall()
+CallExpr *CallExprWithinStmt = dyn_cast(E);
+int NumArgs = CallExprWithinStmt->getNumArgs();
+clang::Expr **Args = CallExprWithinStmt->getArgs();
+ExprResult er = SemaPtr->ActOnOpenMPCall(

alexey-bataev wrote:

Er or ER

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


[clang] [llvm] Support for dispatch construct (Sema & Codegen) support. (PR #117904)

2024-11-27 Thread Alexey Bataev via cfe-commits


@@ -11769,6 +11769,8 @@ def err_omp_clause_requires_dispatch_construct : Error<
   "'%0' clause requires 'dispatch' context selector">;
 def err_omp_append_args_with_varargs : Error<
   "'append_args' is not allowed with varargs functions">;
+def warn_omp_dispatch_clause_novariants_nocontext : Warning<
+  "only 'novariants' clause is supported when 'novariants' & 'nocontext' 
clauses occur on the same dispatch construct">;

alexey-bataev wrote:

Each warning should belong to at least one of the warning groups

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


[clang] [llvm] Support for dispatch construct (Sema & Codegen) support. (PR #117904)

2024-11-27 Thread Alexey Bataev via cfe-commits


@@ -5965,6 +5967,244 @@ static bool teamsLoopCanBeParallelFor(Stmt *AStmt, Sema 
&SemaRef) {
   return Checker.teamsLoopCanBeParallelFor();
 }
 
+static Expr *getInitialExprFromCapturedExpr(Expr *Cond) {
+
+  Expr *SubExpr = Cond->IgnoreParenImpCasts();
+
+  if (auto *DeclRef = dyn_cast(SubExpr)) {
+if (auto *CapturedExprDecl =
+dyn_cast(DeclRef->getDecl())) {
+
+  // Retrieve the initial expression from the captured expression
+  return CapturedExprDecl->getInit();
+}
+  }
+  return nullptr;
+}
+
+static Expr *copy_removePseudoObjectExpr(const ASTContext &Context, Expr *E,
+ SemaOpenMP *SemaPtr, bool NoContext) {
+
+  BinaryOperator *BinaryCopyOpr = NULL;
+  bool BinaryOp = false;
+  if (E->getStmtClass() == Stmt::BinaryOperatorClass) {
+BinaryOp = true;
+BinaryOperator *E_BinOpr = static_cast(E);
+BinaryCopyOpr = BinaryOperator::Create(
+Context, E_BinOpr->getLHS(), E_BinOpr->getRHS(), E_BinOpr->getOpcode(),
+E_BinOpr->getType(), E_BinOpr->getValueKind(),
+E_BinOpr->getObjectKind(), E_BinOpr->getOperatorLoc(),
+FPOptionsOverride());
+E = BinaryCopyOpr->getRHS();
+  }
+
+  // Change PseudoObjectExpr to a direct call
+  if (PseudoObjectExpr *PO = dyn_cast(E))
+E = *((PO->semantics_begin()) - 1);

alexey-bataev wrote:

Why do you need this?

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


[clang] [Clang][OpenCL][AMDGPU] Allow a kernel to call another kernel (PR #115821)

2024-11-27 Thread Shilei Tian via cfe-commits


@@ -1780,6 +1786,15 @@ void CXXNameMangler::mangleDeviceStubName(const 
IdentifierInfo *II) {
   << II->getName();
 }
 
+void CXXNameMangler::mangleOCLDeviceStubName(const IdentifierInfo *II) {
+  //  ::=  __clang_ocl_kern_imp_
+  //   ::= [n]  
+  // ::= 
+  StringRef OCLDeviceStubNamePrefix = "__clang_ocl_kern_imp_";

shiltian wrote:

I'd suggest using some symbols that a regular user-defined function can't be 
named to avoid conflict.

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


[clang] [Clang][AArch64]Refactor typespec handling in SveEmitter.cpp (PR #117717)

2024-11-27 Thread via cfe-commits


@@ -423,131 +434,143 @@ const std::array 
SVEEmitter::Reinterprets =
 // Type implementation
 
//===--===//
 
-std::string SVEType::builtin_str() const {
-  std::string S;
-  if (isVoid())
+std::string SVEType::builtinBaseType() const {
+  switch (Kind) {
+  case TypeKind::Void:
 return "v";
-
-  if (isScalarPredicate())
-return "b";
-
-  if (isSvcount())
+  case TypeKind::Svcount:
 return "Qa";
-
-  if (isVoidPointer())
-S += "v";
-  else if (!isFloatingPoint())
+  case TypeKind::BFloat16:
+assert(ElementBitwidth == 16 && "Invalid BFloat16!");
+return "y";
+  case TypeKind::MFloat8:
+assert(ElementBitwidth == 8 && "Invalid MFloat8!");
+return "c";
+  case TypeKind::Float:
 switch (ElementBitwidth) {
-case 1: S += "b"; break;
-case 8: S += "c"; break;
-case 16: S += "s"; break;
-case 32: S += "i"; break;
-case 64: S += "Wi"; break;
-case 128: S += "LLLi"; break;
-default: llvm_unreachable("Unhandled case!");
+case 16:
+  return "h";
+case 32:
+  return "f";
+case 64:
+  return "d";
+default:
+  llvm_unreachable("Unhandled float width!");
 }
-  else if (isFloat())
+  case TypeKind::Predicate:
+if (isScalar())
+  return "b";
+[[fallthrough]];
+  // SInt/UInt, PredicatePattern, PrefetchOp.
+  default:
 switch (ElementBitwidth) {
-case 16: S += "h"; break;
-case 32: S += "f"; break;
-case 64: S += "d"; break;
-default: llvm_unreachable("Unhandled case!");
+case 1:
+  return "b";
+case 8:
+  return "c";
+case 16:
+  return "s";
+case 32:
+  return "i";
+case 64:
+  return "Wi";
+case 128:
+  return "LLLi";
+default:
+  llvm_unreachable("Unhandled bitwidth!");
 }
-  else if (isBFloat()) {
-assert(ElementBitwidth == 16 && "Not a valid BFloat.");
-S += "y";
-  } else if (isMFloat()) {
-assert(ElementBitwidth == 8 && "Not a valid MFloat.");
-S += "m";
   }
+}
 
-  if (!isFloatingPoint()) {
-if ((isChar() || isPointer()) && !isVoidPointer()) {
-  // Make chars and typed pointers explicitly signed.
-  if (Signed)
-S = "S" + S;
-  else if (!Signed)
-S = "U" + S;
-} else if (!isVoidPointer() && !Signed) {
-  S = "U" + S;
-}
-  }
+std::string SVEType::builtin_str() const {
 
-  // Constant indices are "int", but have the "constant expression" modifier.
-  if (isImmediate()) {
-assert(!isFloat() && "fp immediates are not supported");
-S = "I" + S;
-  }
+  std::string Prefix;
 
-  if (isScalar()) {
-if (Constant) S += "C";
-if (Pointer) S += "*";
-return S;
+  if (isScalableVector())
+Prefix = "q" + llvm::utostr(getNumElements() * NumVectors);
+  else if (isFixedLengthVector())
+Prefix = "V" + llvm::utostr(getNumElements() * NumVectors);
+  else if (isImmediate()) {
+assert(!isFloatingPoint() && "fp immediates are not supported");
+Prefix = "I";
   }
 
-  if (isFixedLengthVector())
-return "V" + utostr(getNumElements() * NumVectors) + S;
-  return "q" + utostr(getNumElements() * NumVectors) + S;
+  // Make chars and integer pointers explicitly signed.
+  if ((ElementBitwidth == 8 || isPointer()) && isSignedInteger())

SpencerAbson wrote:

Before this patch, the code that performed `// Make chars explicitly typed` 
deduced that a type was a `char` from `!isFloatingPoint()` and `ElementBitWidth 
== 8`. One effect of this is that the builtin string for a the type `Pc` would 
be `q16Sc` (vector of signed chars). The change that I have made here will 
ignore sign information for predicates. @sdesmalen-arm do you know if this was 
the intent of the original code?

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


[clang] [analyzer] Modernize, improve and promote chroot checker (PR #117791)

2024-11-27 Thread via cfe-commits

vabridgers wrote:

> @vabridgers Please avoid force pushes. 
I understand and will abide by this request. I had tried rebasing and pushing 
at one time and found I needed to force a push upload my newest changes and 
thought that was the default flow. 


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


  1   2   3   4   5   >