[clang] Remove redundant assertion & fix ClearStatName error (PR #130667)

2025-03-12 Thread Ayush Pareek via cfe-commits


@@ -93,7 +93,7 @@ class CachedFileSystemEntry {
   getDirectiveTokens() const {
 assert(!isError() && "error");
 assert(!isDirectory() && "not a file");
-assert(Contents && "contents not initialized");
+// Since isError() and isDirectory() imply that Contents is nullptr, the 
last assertion is unnecessary

ayushpareek2003 wrote:

Got it, sir. i will ensure that my comments focus on the code itself rather 
than describing updates. I’ll keep them clear and concise in my future pull 
requests 

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


[clang] [Sema] Diagnose by-value copy constructors in template instantiations (PR #130866)

2025-03-12 Thread via cfe-commits

Megan0704-1 wrote:

Thanks for your feedback and review!! I’ve updated the changelog and the test 
file to include the rvalue-to-lvalue case and templated constructor scenario. 
Please let me know if there’s anything else!

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


[clang] Remove redundant assertion & fix ClearStatName error (PR #130667)

2025-03-12 Thread Ayush Pareek via cfe-commits

https://github.com/ayushpareek2003 updated 
https://github.com/llvm/llvm-project/pull/130667

>From 94b213ad0edf8295451cdb315093cd73923714bb Mon Sep 17 00:00:00 2001
From: Ayush Pareek 
Date: Tue, 11 Mar 2025 02:23:49 +0530
Subject: [PATCH 1/2] Update DependencyScanningFilesystem.h

Issue: Calling clearStatName() on an error object
The function clearStatName() is called inside constructors before checking 
whether MaybeStat contains an error. If MaybeStat is an error, calling 
copyWithNewName() can cause undefined behavior

Since isError() and isDirectory() imply that Contents is nullptr, the last 
assertion is unnecessary
---
 .../DependencyScanning/DependencyScanningFilesystem.h| 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
index d12814e7c9253..b69a99cf12bcb 100644
--- 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
+++ 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
@@ -93,7 +93,7 @@ class CachedFileSystemEntry {
   getDirectiveTokens() const {
 assert(!isError() && "error");
 assert(!isDirectory() && "not a file");
-assert(Contents && "contents not initialized");
+// Since isError() and isDirectory() imply that Contents is nullptr, the 
last assertion is unnecessary
 if (auto *Directives = Contents->DepDirectives.load()) {
   if (Directives->has_value())
 return ArrayRef(**Directives);
@@ -126,7 +126,8 @@ class CachedFileSystemEntry {
 
 private:
   void clearStatName() {
-if (MaybeStat)
+  
+if (MaybeStat && MaybeStat->getName().empty())   //If MaybeStat is an 
error, calling copyWithNewName() can cause undefined behavior
   MaybeStat = llvm::vfs::Status::copyWithNewName(*MaybeStat, "");
   }
 

>From 815393bc35d31e4e9dab6cc7c55b642f806fe34b Mon Sep 17 00:00:00 2001
From: Ayush Pareek 
Date: Wed, 12 Mar 2025 14:37:53 +0530
Subject: [PATCH 2/2] Update DependencyScanningFilesystem.h

---
 .../Tooling/DependencyScanning/DependencyScanningFilesystem.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
index b69a99cf12bcb..045da01b759e8 100644
--- 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
+++ 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
@@ -93,7 +93,7 @@ class CachedFileSystemEntry {
   getDirectiveTokens() const {
 assert(!isError() && "error");
 assert(!isDirectory() && "not a file");
-// Since isError() and isDirectory() imply that Contents is nullptr, the 
last assertion is unnecessary
+assert(Contents && "contents not initialized");
 if (auto *Directives = Contents->DepDirectives.load()) {
   if (Directives->has_value())
 return ArrayRef(**Directives);
@@ -127,7 +127,7 @@ class CachedFileSystemEntry {
 private:
   void clearStatName() {
   
-if (MaybeStat && MaybeStat->getName().empty())   //If MaybeStat is an 
error, calling copyWithNewName() can cause undefined behavior
+if (MaybeStat)
   MaybeStat = llvm::vfs::Status::copyWithNewName(*MaybeStat, "");
   }
 

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


[clang] Remove redundant assertion & fix ClearStatName error (PR #130667)

2025-03-12 Thread Ayush Pareek via cfe-commits


@@ -126,7 +126,8 @@ class CachedFileSystemEntry {
 
 private:
   void clearStatName() {
-if (MaybeStat)
+  
+if (MaybeStat && MaybeStat->getName().empty())   //If MaybeStat is an 
error, calling copyWithNewName() can cause undefined behavior

ayushpareek2003 wrote:

I initially thought it would be good to explicitly set the name to an empty 
string to ensure consistency across versions. However, since the condition is 
only updating the name, this extra check is unnecessary

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


[clang] [llvm] [MIPS] Add MIPS i6400 and i6500 processors (PR #130587)

2025-03-12 Thread Djordje Todorovic via cfe-commits


@@ -238,13 +238,10 @@ def ImplP5600 : SubtargetFeature<"p5600", "ProcImpl",
  "MipsSubtarget::CPU::P5600",
  "The P5600 Processor", [FeatureMips32r5]>;
 
+// I6500 is multicluster version of I6400. Both are based on same CPU.

djtodoro wrote:

nit: `The I6500 is the multi-cluster version of the I6400. Both are based on 
the same CPU architecture.`

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


[clang] [Sema] Diagnose by-value copy constructors in template instantiations (PR #130866)

2025-03-12 Thread via cfe-commits

Megan0704-1 wrote:

Thank you for reviewing and approving the PR!
Yes, please merge it for me. Thanks again for all your help!

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


[clang] [Sema] Diagnose by-value copy constructors in template instantiations (PR #130866)

2025-03-12 Thread via cfe-commits

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


[clang] [Sema] Diagnose by-value copy constructors in template instantiations (PR #130866)

2025-03-12 Thread via cfe-commits

https://github.com/cor3ntin commented:

Thanks for working on this 

Can you add a changelog entry in clang/docs/ReleaseNotes.rst (in the bug fixes 
to c++ section)?

Thanks

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


[clang] [clang-repl] Fix target creation in Wasm.cpp (PR #130909)

2025-03-12 Thread Anutosh Bhat via cfe-commits

https://github.com/anutosh491 created 
https://github.com/llvm/llvm-project/pull/130909

After #129868 went in, I realize some updates have been made to the Triple.

Not sure if @nikic overlooked including this change in his PR (hence I have 
having build issue when compiling clang against emscripten while building for 
wasm)

But yeah just like the change was addressed in other files, we need to make the 
change here too I think

https://github.com/llvm/llvm-project/blob/d921bf233c4fd3840953b1a4b5bb35ad594da773/clang/lib/Interpreter/DeviceOffload.cpp#L79-L86

>From 18e1f9713b34bf1f9c0e946cd915c0ae04748607 Mon Sep 17 00:00:00 2001
From: anutosh491 
Date: Wed, 12 Mar 2025 12:32:02 +0530
Subject: [PATCH] Fix target creation in Wasm.cpp

---
 clang/lib/Interpreter/Wasm.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Interpreter/Wasm.cpp b/clang/lib/Interpreter/Wasm.cpp
index aa10b160ccf84..85a62e05f6e82 100644
--- a/clang/lib/Interpreter/Wasm.cpp
+++ b/clang/lib/Interpreter/Wasm.cpp
@@ -66,7 +66,7 @@ llvm::Error 
WasmIncrementalExecutor::addModule(PartialTranslationUnit &PTU) {
   std::string ErrorString;
 
   const llvm::Target *Target = llvm::TargetRegistry::lookupTarget(
-  PTU.TheModule->getTargetTriple(), ErrorString);
+  PTU.TheModule->getTargetTriple().str(), ErrorString);
   if (!Target) {
 return llvm::make_error("Failed to create Wasm Target: 
",
llvm::inconvertibleErrorCode());
@@ -74,7 +74,7 @@ llvm::Error 
WasmIncrementalExecutor::addModule(PartialTranslationUnit &PTU) {
 
   llvm::TargetOptions TO = llvm::TargetOptions();
   llvm::TargetMachine *TargetMachine = Target->createTargetMachine(
-  PTU.TheModule->getTargetTriple(), "", "", TO, llvm::Reloc::Model::PIC_);
+  PTU.TheModule->getTargetTriple().str(), "", "", TO, 
llvm::Reloc::Model::PIC_);
   PTU.TheModule->setDataLayout(TargetMachine->createDataLayout());
   std::string ObjectFileName = PTU.TheModule->getName().str() + ".o";
   std::string BinaryFileName = PTU.TheModule->getName().str() + ".wasm";

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


[clang] [clang-repl] Fix target creation in Wasm.cpp (PR #130909)

2025-03-12 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Anutosh Bhat (anutosh491)


Changes

After #129868 went in, I realize some updates have been made to the 
Triple.

Not sure if @nikic overlooked including this change in his PR (hence I 
have having build issue when compiling clang against emscripten while building 
for wasm)

But yeah just like the change was addressed in other files, we need to make the 
change here too I think

https://github.com/llvm/llvm-project/blob/d921bf233c4fd3840953b1a4b5bb35ad594da773/clang/lib/Interpreter/DeviceOffload.cpp#L79-L86

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


1 Files Affected:

- (modified) clang/lib/Interpreter/Wasm.cpp (+2-2) 


``diff
diff --git a/clang/lib/Interpreter/Wasm.cpp b/clang/lib/Interpreter/Wasm.cpp
index aa10b160ccf84..c12412c26d6e0 100644
--- a/clang/lib/Interpreter/Wasm.cpp
+++ b/clang/lib/Interpreter/Wasm.cpp
@@ -74,7 +74,7 @@ llvm::Error 
WasmIncrementalExecutor::addModule(PartialTranslationUnit &PTU) {
 
   llvm::TargetOptions TO = llvm::TargetOptions();
   llvm::TargetMachine *TargetMachine = Target->createTargetMachine(
-  PTU.TheModule->getTargetTriple(), "", "", TO, llvm::Reloc::Model::PIC_);
+  PTU.TheModule->getTargetTriple().str(), "", "", TO, 
llvm::Reloc::Model::PIC_);
   PTU.TheModule->setDataLayout(TargetMachine->createDataLayout());
   std::string ObjectFileName = PTU.TheModule->getName().str() + ".o";
   std::string BinaryFileName = PTU.TheModule->getName().str() + ".wasm";
@@ -146,4 +146,4 @@ llvm::Error WasmIncrementalExecutor::cleanUp() {
 
 WasmIncrementalExecutor::~WasmIncrementalExecutor() = default;
 
-} // namespace clang
\ No newline at end of file
+} // namespace clang

``




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


[clang] [HLSL][NFC] Update HLSL AST tests to be more readable (PR #130910)

2025-03-12 Thread Helena Kotas via cfe-commits

https://github.com/hekota created 
https://github.com/llvm/llvm-project/pull/130910

Replacing all occurences of
- `0x{{[0-9A-Fa-f]+}} <> `
- `0x{{[0-9A-Fa-f]+}} <>`
- `0x{{[0-9A-Fa-f]+}}`
- `0x{{[0-9a-fA-F]+}} `
- `0x{{[0-9a-fA-F]+}}  col:#`

with
- `{{.*}}`

to improve readability and conciseness of the HLSL AST tests.




>From ce71279c1d28f0ce96a99a6a5aac75c2bb23e1c6 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Tue, 11 Mar 2025 23:59:05 -0700
Subject: [PATCH] [HLSL][NFC] Update HLSL AST tests to be more readable

---
 .../test/AST/HLSL/ByteAddressBuffers-AST.hlsl |  18 +-
 clang/test/AST/HLSL/HLSLControlFlowHint.hlsl  |  18 +-
 .../test/AST/HLSL/StructuredBuffers-AST.hlsl  | 238 
 clang/test/AST/HLSL/TypedBuffers-AST.hlsl | 126 -
 ...d_resource_element_compatible_concept.hlsl |  20 +-
 ...d_resource_element_compatible_concept.hlsl |  10 +-
 clang/test/AST/HLSL/packoffset.hlsl   |   4 +-
 clang/test/AST/HLSL/vector-alias.hlsl | 106 +++
 clang/test/AST/HLSL/vector-constructors.hlsl  | 266 +-
 .../hlsl_resource_handle_attrs.hlsl   |  22 +-
 10 files changed, 413 insertions(+), 415 deletions(-)

diff --git a/clang/test/AST/HLSL/ByteAddressBuffers-AST.hlsl 
b/clang/test/AST/HLSL/ByteAddressBuffers-AST.hlsl
index 909cce17e344c..12025ab998bad 100644
--- a/clang/test/AST/HLSL/ByteAddressBuffers-AST.hlsl
+++ b/clang/test/AST/HLSL/ByteAddressBuffers-AST.hlsl
@@ -22,8 +22,8 @@
 // RUN:   -DRESOURCE=RasterizerOrderedByteAddressBuffer %s | FileCheck 
-DRESOURCE=RasterizerOrderedByteAddressBuffer \
 // RUN:   -check-prefixes=CHECK,CHECK-UAV,CHECK-NOSUBSCRIPT %s
 
-// EMPTY: CXXRecordDecl 0x{{[0-9A-Fa-f]+}} <>  
implicit  class [[RESOURCE]]
-// EMPTY-NEXT: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final
+// EMPTY: CXXRecordDecl {{.*}} implicit  class 
[[RESOURCE]]
+// EMPTY-NEXT: FinalAttr {{.*}}  Implicit final
 
 // There should be no more occurrences of RESOURCE
 // EMPTY-NOT: {{[^[:alnum:]]}}[[RESOURCE]]
@@ -34,16 +34,14 @@ RESOURCE Buffer;
 
 #endif
 
-// CHECK: CXXRecordDecl 0x{{[0-9A-Fa-f]+}} <>  
implicit referenced  class [[RESOURCE]] definition
-
-
-// CHECK: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final
-// CHECK-NEXT: FieldDecl 0x{{[0-9A-Fa-f]+}} <>  
implicit __handle '__hlsl_resource_t
+// CHECK: CXXRecordDecl {{.*}} implicit referenced  class [[RESOURCE]] definition
+// CHECK: FinalAttr {{.*}}  Implicit final
+// CHECK-NEXT: FieldDecl {{.*}} implicit __handle '__hlsl_resource_t
 // CHECK-SRV-SAME{LITERAL}: [[hlsl::resource_class(SRV)]]
 // CHECK-UAV-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-NEXT: HLSLResourceAttr {{.*}}  Implicit RawBuffer
 
-// CHECK-NOSUBSCRIPT-NOT: CXXMethodDecl 0x{{[0-9A-Fa-f]+}} <> 
 operator[] 'const element_type &(unsigned int) const'
-// CHECK-NOSUBSCRIPT-NOT: CXXMethodDecl 0x{{[0-9A-Fa-f]+}} <> 
 operator[] 'element_type &(unsigned int)'
+// CHECK-NOSUBSCRIPT-NOT: CXXMethodDecl {{.*}} operator[] 'const element_type 
&(unsigned int) const'
+// CHECK-NOSUBSCRIPT-NOT: CXXMethodDecl {{.*}} operator[] 'element_type 
&(unsigned int)'
diff --git a/clang/test/AST/HLSL/HLSLControlFlowHint.hlsl 
b/clang/test/AST/HLSL/HLSLControlFlowHint.hlsl
index a36779c05fbc9..c1e6d969c8d31 100644
--- a/clang/test/AST/HLSL/HLSLControlFlowHint.hlsl
+++ b/clang/test/AST/HLSL/HLSLControlFlowHint.hlsl
@@ -1,8 +1,8 @@
 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-compute -ast-dump %s | 
FileCheck %s
 
-// CHECK: FunctionDecl 0x{{[0-9A-Fa-f]+}} <{{.*}}> {{.*}} used branch 'int 
(int)'
-// CHECK: AttributedStmt 0x{{[0-9A-Fa-f]+}} <
-// CHECK-NEXT: -HLSLControlFlowHintAttr 0x{{[0-9A-Fa-f]+}} <{{.*}}> branch
+// CHECK: FunctionDecl {{.*}} used branch 'int (int)'
+// CHECK: AttributedStmt
+// CHECK-NEXT: HLSLControlFlowHintAttr {{.*}} branch
 export int branch(int X){
 int resp;
 [branch] if (X > 0) {
@@ -14,9 +14,9 @@ export int branch(int X){
 return resp;
 }
 
-// CHECK: FunctionDecl 0x{{[0-9A-Fa-f]+}} <{{.*}}> {{.*}} used flatten 'int 
(int)'
-// CHECK: AttributedStmt 0x{{[0-9A-Fa-f]+}} <
-// CHECK-NEXT: -HLSLControlFlowHintAttr 0x{{[0-9A-Fa-f]+}} <{{.*}}> flatten
+// CHECK: FunctionDecl {{.*}} used flatten 'int (int)'
+// CHECK: AttributedStmt
+// CHECK-NEXT: HLSLControlFlowHintAttr {{.*}} flatten
 export int flatten(int X){
 int resp;
 [flatten] if (X > 0) {
@@ -28,9 +28,9 @@ export int flatten(int X){
 return resp;
 }
 
-// CHECK: FunctionDecl 0x{{[0-9A-Fa-f]+}} <{{.*}}> {{.*}} used no_attr 'int 
(int)'
-// CHECK-NOT: AttributedStmt 0x{{[0-9A-Fa-f]+}} <
-// CHECK-NOT: -HLSLControlFlowHintAttr
+// CHECK: FunctionDecl {{.*}} used no_attr 'int (int)'
+// CHECK-NOT: AttributedStmt
+// CHECK-NOT: HLSLControlFlowHintAttr
 export int no_attr(int X){
 int resp;
 if (X > 0) {
diff --git a/clang/test/AST/HLSL/S

[clang] [clang-repl] Fix target creation in Wasm.cpp (PR #130909)

2025-03-12 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 90a08fb4b7e79e79121a563ac9cd8138cfedeb3c 
ca6163e2e4cf1d0a7e3ba60feb28ede52dcd4f8d --extensions cpp -- 
clang/lib/Interpreter/Wasm.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Interpreter/Wasm.cpp b/clang/lib/Interpreter/Wasm.cpp
index c12412c26d..6f584fab52 100644
--- a/clang/lib/Interpreter/Wasm.cpp
+++ b/clang/lib/Interpreter/Wasm.cpp
@@ -73,8 +73,9 @@ llvm::Error 
WasmIncrementalExecutor::addModule(PartialTranslationUnit &PTU) {
   }
 
   llvm::TargetOptions TO = llvm::TargetOptions();
-  llvm::TargetMachine *TargetMachine = Target->createTargetMachine(
-  PTU.TheModule->getTargetTriple().str(), "", "", TO, 
llvm::Reloc::Model::PIC_);
+  llvm::TargetMachine *TargetMachine =
+  Target->createTargetMachine(PTU.TheModule->getTargetTriple().str(), "",
+  "", TO, llvm::Reloc::Model::PIC_);
   PTU.TheModule->setDataLayout(TargetMachine->createDataLayout());
   std::string ObjectFileName = PTU.TheModule->getName().str() + ".o";
   std::string BinaryFileName = PTU.TheModule->getName().str() + ".wasm";

``




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


[clang] c9563a4 - [Clang][NFC] Remove CallExpr::CreateTemporary (#130919)

2025-03-12 Thread via cfe-commits

Author: cor3ntin
Date: 2025-03-12T09:49:24+01:00
New Revision: c9563a422cea44f0b00fdcd5085666442f8f24f8

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

LOG: [Clang][NFC] Remove CallExpr::CreateTemporary (#130919)

`CallExpr::CreateTemporary` was only used to deduce a conversion
sequence from a conversion operator.

We only need a type/value category for that,
so we can use a dummy Expression such as a
`OpaqueValueExpr`.

This simplify the code and avoid partially-formed
`CallExpr` with incorrect invariants (see #130725)

Fixes #130824

Added: 


Modified: 
clang/include/clang/AST/Expr.h
clang/lib/AST/Expr.cpp
clang/lib/Sema/SemaOverload.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index cfe49acf20b77..b81f3a403baf6 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -3005,18 +3005,6 @@ class CallExpr : public Expr {
   FPOptionsOverride FPFeatures, unsigned MinNumArgs = 
0,
   ADLCallKind UsesADL = NotADL);
 
-  /// Create a temporary call expression with no arguments in the memory
-  /// pointed to by Mem. Mem must points to at least sizeof(CallExpr)
-  /// + sizeof(Stmt *) bytes of storage, aligned to alignof(CallExpr):
-  ///
-  /// \code{.cpp}
-  ///   alignas(CallExpr) char Buffer[sizeof(CallExpr) + sizeof(Stmt *)];
-  ///   CallExpr *TheCall = CallExpr::CreateTemporary(Buffer, etc);
-  /// \endcode
-  static CallExpr *CreateTemporary(void *Mem, Expr *Fn, QualType Ty,
-   ExprValueKind VK, SourceLocation RParenLoc,
-   ADLCallKind UsesADL = NotADL);
-
   /// Create an empty call expression, for deserialization.
   static CallExpr *CreateEmpty(const ASTContext &Ctx, unsigned NumArgs,
bool HasFPFeatures, EmptyShell Empty);

diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 1dde64f193dbd..901ebf9592680 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -1509,16 +1509,6 @@ CallExpr *CallExpr::Create(const ASTContext &Ctx, Expr 
*Fn,
 RParenLoc, FPFeatures, MinNumArgs, UsesADL);
 }
 
-CallExpr *CallExpr::CreateTemporary(void *Mem, Expr *Fn, QualType Ty,
-ExprValueKind VK, SourceLocation RParenLoc,
-ADLCallKind UsesADL) {
-  assert(!(reinterpret_cast(Mem) % alignof(CallExpr)) &&
- "Misaligned memory in CallExpr::CreateTemporary!");
-  return new (Mem) CallExpr(CallExprClass, Fn, /*PreArgs=*/{}, /*Args=*/{}, Ty,
-VK, RParenLoc, FPOptionsOverride(),
-/*MinNumArgs=*/0, UsesADL);
-}
-
 CallExpr *CallExpr::CreateEmpty(const ASTContext &Ctx, unsigned NumArgs,
 bool HasFPFeatures, EmptyShell Empty) {
   unsigned SizeOfTrailingObjects =
@@ -1655,14 +1645,8 @@ SourceLocation CallExpr::getBeginLoc() const {
   if (!isTypeDependent()) {
 if (const auto *Method =
 dyn_cast_if_present(getCalleeDecl());
-Method && Method->isExplicitObjectMemberFunction()) {
-  // Note: while we typically expect the call to have a first argument
-  // here, we can't assert it because in some cases it does not, e.g.
-  // calls created with CallExpr::CreateTemporary() during overload
-  // resolution.
-  if (getNumArgs() > 0 && getArg(0))
-return getArg(0)->getBeginLoc();
-}
+Method && Method->isExplicitObjectMemberFunction())
+  return getArg(0)->getBeginLoc();
   }
 
   SourceLocation begin = getCallee()->getBeginLoc();

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index d3c0534b4dd0b..990f2659eb8fa 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -8147,17 +8147,14 @@ void Sema::AddConversionCandidate(
 
   ExprValueKind VK = Expr::getValueKindForType(ConversionType);
 
-  // Note that it is safe to allocate CallExpr on the stack here because
-  // there are 0 arguments (i.e., nothing is allocated using ASTContext's
-  // allocator).
   QualType CallResultType = ConversionType.getNonLValueExprType(Context);
 
-  alignas(CallExpr) char Buffer[sizeof(CallExpr) + sizeof(Stmt *)];
-  CallExpr *TheTemporaryCall = CallExpr::CreateTemporary(
-  Buffer, &ConversionFn, CallResultType, VK, From->getBeginLoc());
+  // Introduce a temporary expression with the right type and value category
+  // that we can use for deduction purposes.
+  OpaqueValueExpr FakeCall(From->getBeginLoc(), CallResultType, VK);
 
   ImplicitConversionSequence ICS =
-  TryCopyInitialization(*this, TheTemporaryCall, ToType,
+  TryCopyInit

[clang] [Clang][NFC] Remove CallExpr::CreateTemporary (PR #130919)

2025-03-12 Thread via cfe-commits

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


[clang] [llvm] [ARM][Clang] Make `+nosimd` functional for AArch32 Targets (PR #130623)

2025-03-12 Thread Jack Styles via cfe-commits

https://github.com/Stylie777 commented:

Thanks for the comments @davemgreen. I need to do some more investigation here 
as I think there is more going wrong than I initially thought after this change 
is introduced.

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


[clang] [Sema] Diagnose by-value copy constructors in template instantiations (PR #130866)

2025-03-12 Thread via cfe-commits

https://github.com/Megan0704-1 updated 
https://github.com/llvm/llvm-project/pull/130866

>From 80e764fcfa1912e9d3771f4edb354569741010b7 Mon Sep 17 00:00:00 2001
From: Megan 
Date: Tue, 11 Mar 2025 17:09:04 -0700
Subject: [PATCH 1/3] [Sema] Diagnose by-value copy constructors in template
 instantiations
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Fixes #80963

Previously, Clang skipped diagnosing a constructor if it was implicitly
instantiated from a template class (TSK_ImplicitInstantiation). This allowed
ill-formed “copy” constructors taking the class by value (e.g. A(A)) to slip
through without a diagnostic.

However, the C++ standard mandates that copy constructors must take their
class type parameter by reference (e.g., A(const A&)). Furthermore, a
constructor template that *would* form a copy-by-value signature is not
treated as a copy constructor and should never be chosen for copying.

This patch replaces the check on TSK_ImplicitInstantiation with a check
to see if the constructor is a function template specialization (i.e.,
isFunctionTemplateSpecialization()). That ensures proper diagnosis of
non-template copy-by-value constructors, while still allowing valid
template constructors that might appear to have a copy-like signature
but should be SFINAEd out or simply not selected as a copy constructor.
---
 clang/lib/Sema/SemaDeclCXX.cpp|  4 ++--
 clang/test/SemaCXX/copy-ctor-template.cpp | 22 ++
 2 files changed, 24 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/SemaCXX/copy-ctor-template.cpp

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 96aac7871db1e..1c62a551ee732 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -10921,8 +10921,8 @@ void Sema::CheckConstructor(CXXConstructorDecl 
*Constructor) {
   //   parameters have default arguments.
   if (!Constructor->isInvalidDecl() &&
   Constructor->hasOneParamOrDefaultArgs() &&
-  Constructor->getTemplateSpecializationKind() !=
-  TSK_ImplicitInstantiation) {
+  !Constructor->isFunctionTemplateSpecialization()
+  ) {
 QualType ParamType = Constructor->getParamDecl(0)->getType();
 QualType ClassTy = Context.getTagDeclType(ClassDecl);
 if (Context.getCanonicalType(ParamType).getUnqualifiedType() == ClassTy) {
diff --git a/clang/test/SemaCXX/copy-ctor-template.cpp 
b/clang/test/SemaCXX/copy-ctor-template.cpp
new file mode 100644
index 0..a46a167038cf7
--- /dev/null
+++ b/clang/test/SemaCXX/copy-ctor-template.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template
+struct A{
+A();
+A(A&);
+A(A); // expected-error{{copy constructor must pass its first 
argument by reference}}
+};
+
+void f() {
+A a = A(); // expected-note{{in instantiation of 
template class 'A'}}
+}
+
+template
+struct B{
+B();
+template B(U); // No error (templated constructor)
+};
+
+void g() {
+B b = B(); // should use implicit copy constructor
+}

>From 4fe1d934e7a688c346d5218e213decc67b261d70 Mon Sep 17 00:00:00 2001
From: Megan 
Date: Wed, 12 Mar 2025 00:47:56 -0700
Subject: [PATCH 2/3] [Docs] Add release note for #80963 fix

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

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 004f78f22ac36..8bae0d6e99ae0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -293,6 +293,7 @@ Bug Fixes to Attribute Support
 Bug Fixes to C++ Support
 
 
+- Clang now diagnoses copy constructors taking the class by value in template 
instantiations. (#GH130866)
 - Clang is now better at keeping track of friend function template instance 
contexts. (#GH55509)
 - Clang now prints the correct instantiation context for diagnostics suppressed
   by template argument deduction.

>From 5ea66a6461de5890edd8ae7e5790278eec9aecea Mon Sep 17 00:00:00 2001
From: Megan 
Date: Wed, 12 Mar 2025 01:15:12 -0700
Subject: [PATCH 3/3] [Sema] Fix test diagnostics for copy-ctor-template

---
 clang/test/SemaCXX/copy-ctor-template.cpp | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/clang/test/SemaCXX/copy-ctor-template.cpp 
b/clang/test/SemaCXX/copy-ctor-template.cpp
index a46a167038cf7..92dea6208a167 100644
--- a/clang/test/SemaCXX/copy-ctor-template.cpp
+++ b/clang/test/SemaCXX/copy-ctor-template.cpp
@@ -2,13 +2,21 @@
 
 template
 struct A{
-A();
-A(A&);
+A(); // expected-note{{candidate constructor not viable: requires 0 
arguments, but 1 was provided}}
+A(A&); // expected-note{{candidate constructor not viable: expects an 
lvalue for 1st argument}} 
 A(A); // expected-error{{copy constructor must pass its first 
argument by reference}}
 };
 
 void f() {
-A a = A(); // expected-note{{in instantiation of 
template class 'A'}}
+A a = A(); // expected-note{{

[clang] [llvm] [ARM][Clang] Make `+nosimd` functional for AArch32 Targets (PR #130623)

2025-03-12 Thread Jack Styles via cfe-commits


@@ -334,8 +334,8 @@ ARM_CPU_NAME("cortex-r7", ARMV7R, FK_VFPV3_D16_FP16, false,
  (ARM::AEK_MP | ARM::AEK_HWDIVARM))
 ARM_CPU_NAME("cortex-r8", ARMV7R, FK_VFPV3_D16_FP16, false,
  (ARM::AEK_MP | ARM::AEK_HWDIVARM))
-ARM_CPU_NAME("cortex-r52", ARMV8R, FK_NEON_FP_ARMV8, false, ARM::AEK_NONE)
-ARM_CPU_NAME("cortex-r52plus", ARMV8R, FK_NEON_FP_ARMV8, false, ARM::AEK_NONE)
+ARM_CPU_NAME("cortex-r52", ARMV8R, FK_NEON_FP_ARMV8, false, ARM::AEK_SIMD)
+ARM_CPU_NAME("cortex-r52plus", ARMV8R, FK_NEON_FP_ARMV8, false, ARM::AEK_SIMD)

Stylie777 wrote:

We support NEON on Cortex-R52 by default, rather than as an optional feature. 
When `+simd`/`+nosimd` was linked to `+neon` and `-neon`, I found that once the 
link between `simd` and `neon` was made, it was not passing `-target-feature 
+neon` as part of the cc1 command.

Let me investigate and see if we need this change or if it can determine 
`+neon` from the FPU, if not we may need to add `AEK_SIMD` to everything that 
should support it as it may not just be cortex-r52 that is affected here.

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


[clang] [Sema] Diagnose by-value copy constructors in template instantiations (PR #130866)

2025-03-12 Thread via cfe-commits

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

LGTM. Thanks for fixing this issue!

Will you need me to merge this for you?

https://github.com/llvm/llvm-project/pull/130866
___
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)

2025-03-12 Thread Aniket Lal via cfe-commits


@@ -1582,6 +1582,26 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD, 
llvm::Function *Fn,
 // Implicit copy-assignment gets the same special treatment as implicit
 // copy-constructors.
 emitImplicitAssignmentOperatorBody(Args);
+  } else if (FD->hasAttr() &&
+ GD.getKernelReferenceKind() == KernelReferenceKind::Kernel) {
+CallArgList CallArgs;
+for (unsigned i = 0; i < Args.size(); ++i) {
+  Address ArgAddr = GetAddrOfLocalVar(Args[i]);
+  QualType ArgQualType = Args[i]->getType();
+  RValue ArgRValue = convertTempToRValue(ArgAddr, ArgQualType, Loc);

lalaniket8 wrote:

> My only concern is struct type argument passed by value, currently, they seem 
> to be handled specially
> 
> https://godbolt.org/z/bo9aveqn3
> 
> I am not sure your current approach will work for that, although it may. I 
> think you may want to add a lit test for that.


I checked few cases where struct arguments are passed by value, the call to 
device stub is emitted as expected (similar to the godbolt example). 
Littest 
[addr-space-struct-arg.cl](https://github.com/llvm/llvm-project/blob/d1e9e94a00b39de55899e6d768d35a00a5612929/clang/test/CodeGenOpenCL/addr-space-struct-arg.cl#L1266)
 covers struct arguments passed by value. Although we don't see the callsite in 
this littest since it gets inlined away. 

We can see the callsite by disabling inlining, it looks something like this:

```
define dso_local amdgpu_kernel void @KernelTwoMember(%struct.StructTwoMember 
%u.coerce){
entry:
  %u = alloca %struct.StructTwoMember, align 8, addrspace(5)
  %u1 = addrspacecast ptr addrspace(5) %u to ptr
  %0 = getelementptr inbounds nuw %struct.StructTwoMember, ptr %u1, i32 0, i32 0
  %1 = extractvalue %struct.StructTwoMember %u.coerce, 0
  store <2 x i32> %1, ptr %0, align 8
  %2 = getelementptr inbounds nuw %struct.StructTwoMember, ptr %u1, i32 0, i32 1
  %3 = extractvalue %struct.StructTwoMember %u.coerce, 1
  store <2 x i32> %3, ptr %2, align 8
  %4 = getelementptr inbounds nuw %struct.StructTwoMember, ptr %u1, i32 0, i32 0
  %5 = load <2 x i32>, ptr %4, align 8
  %6 = getelementptr inbounds nuw %struct.StructTwoMember, ptr %u1, i32 0, i32 1
  %7 = load <2 x i32>, ptr %6, align 8
  call void @__clang_ocl_kern_imp_KernelTwoMember(<2 x i32> %5, <2 x i32> %7) #4
  ret void
}

```


> Did your PR pass internal CI?

Yes, we pass all tests in internal CI. 
[Link](https://github.com/AMD-Lightning-Internal/llvm-project/pull/580)

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] fix(clang/**.py): fix invalid escape sequences (PR #94029)

2025-03-12 Thread Balazs Benics via cfe-commits

steakhal wrote:

Hi, could you explain the motivation of this patch?
I'm not an expert on Python, but to me it seemed like the `r"..."` strings are 
supposed to be used for regular expressions, and in this change you appear to 
transform those strings into plain old strings.
Could you help me understand this?

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


[clang] [Sema] Diagnose by-value copy constructors in template instantiations (PR #130866)

2025-03-12 Thread via cfe-commits

https://github.com/Megan0704-1 updated 
https://github.com/llvm/llvm-project/pull/130866

>From 80e764fcfa1912e9d3771f4edb354569741010b7 Mon Sep 17 00:00:00 2001
From: Megan 
Date: Tue, 11 Mar 2025 17:09:04 -0700
Subject: [PATCH 1/3] [Sema] Diagnose by-value copy constructors in template
 instantiations
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Fixes #80963

Previously, Clang skipped diagnosing a constructor if it was implicitly
instantiated from a template class (TSK_ImplicitInstantiation). This allowed
ill-formed “copy” constructors taking the class by value (e.g. A(A)) to slip
through without a diagnostic.

However, the C++ standard mandates that copy constructors must take their
class type parameter by reference (e.g., A(const A&)). Furthermore, a
constructor template that *would* form a copy-by-value signature is not
treated as a copy constructor and should never be chosen for copying.

This patch replaces the check on TSK_ImplicitInstantiation with a check
to see if the constructor is a function template specialization (i.e.,
isFunctionTemplateSpecialization()). That ensures proper diagnosis of
non-template copy-by-value constructors, while still allowing valid
template constructors that might appear to have a copy-like signature
but should be SFINAEd out or simply not selected as a copy constructor.
---
 clang/lib/Sema/SemaDeclCXX.cpp|  4 ++--
 clang/test/SemaCXX/copy-ctor-template.cpp | 22 ++
 2 files changed, 24 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/SemaCXX/copy-ctor-template.cpp

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 96aac7871db1e..1c62a551ee732 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -10921,8 +10921,8 @@ void Sema::CheckConstructor(CXXConstructorDecl 
*Constructor) {
   //   parameters have default arguments.
   if (!Constructor->isInvalidDecl() &&
   Constructor->hasOneParamOrDefaultArgs() &&
-  Constructor->getTemplateSpecializationKind() !=
-  TSK_ImplicitInstantiation) {
+  !Constructor->isFunctionTemplateSpecialization()
+  ) {
 QualType ParamType = Constructor->getParamDecl(0)->getType();
 QualType ClassTy = Context.getTagDeclType(ClassDecl);
 if (Context.getCanonicalType(ParamType).getUnqualifiedType() == ClassTy) {
diff --git a/clang/test/SemaCXX/copy-ctor-template.cpp 
b/clang/test/SemaCXX/copy-ctor-template.cpp
new file mode 100644
index 0..a46a167038cf7
--- /dev/null
+++ b/clang/test/SemaCXX/copy-ctor-template.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template
+struct A{
+A();
+A(A&);
+A(A); // expected-error{{copy constructor must pass its first 
argument by reference}}
+};
+
+void f() {
+A a = A(); // expected-note{{in instantiation of 
template class 'A'}}
+}
+
+template
+struct B{
+B();
+template B(U); // No error (templated constructor)
+};
+
+void g() {
+B b = B(); // should use implicit copy constructor
+}

>From 4fe1d934e7a688c346d5218e213decc67b261d70 Mon Sep 17 00:00:00 2001
From: Megan 
Date: Wed, 12 Mar 2025 00:47:56 -0700
Subject: [PATCH 2/3] [Docs] Add release note for #80963 fix

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

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 004f78f22ac36..8bae0d6e99ae0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -293,6 +293,7 @@ Bug Fixes to Attribute Support
 Bug Fixes to C++ Support
 
 
+- Clang now diagnoses copy constructors taking the class by value in template 
instantiations. (#GH130866)
 - Clang is now better at keeping track of friend function template instance 
contexts. (#GH55509)
 - Clang now prints the correct instantiation context for diagnostics suppressed
   by template argument deduction.

>From 12d9237d7a0650328f6167b1951195cd851f6234 Mon Sep 17 00:00:00 2001
From: Megan 
Date: Wed, 12 Mar 2025 01:24:35 -0700
Subject: [PATCH 3/3] [Sema] Fix test diagnostics for copy-ctor-template

---
 clang/test/SemaCXX/copy-ctor-template.cpp | 15 +++
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/clang/test/SemaCXX/copy-ctor-template.cpp 
b/clang/test/SemaCXX/copy-ctor-template.cpp
index a46a167038cf7..c58bd7c0c5e10 100644
--- a/clang/test/SemaCXX/copy-ctor-template.cpp
+++ b/clang/test/SemaCXX/copy-ctor-template.cpp
@@ -2,13 +2,20 @@
 
 template
 struct A{
-A();
-A(A&);
+A(); // expected-note{{candidate constructor not viable: requires 0 
arguments, but 1 was provided}}
+A(A&); // expected-note{{candidate constructor not viable: expects an 
lvalue for 1st argument}} 
 A(A); // expected-error{{copy constructor must pass its first 
argument by reference}}
 };
 
 void f() {
-A a = A(); // expected-note{{in instantiation of 
template class 'A'}}
+A a = A(); // expected-note{{i

[clang] [Clang][NFC] Remove CallExpr::CreateTemporary (PR #130919)

2025-03-12 Thread via cfe-commits


@@ -1655,14 +1645,8 @@ SourceLocation CallExpr::getBeginLoc() const {
   if (!isTypeDependent()) {
 if (const auto *Method =
 dyn_cast_if_present(getCalleeDecl());
-Method && Method->isExplicitObjectMemberFunction()) {
-  // Note: while we typically expect the call to have a first argument
-  // here, we can't assert it because in some cases it does not, e.g.
-  // calls created with CallExpr::CreateTemporary() during overload
-  // resolution.
-  if (getNumArgs() > 0 && getArg(0))
-return getArg(0)->getBeginLoc();
-}
+Method && Method->isExplicitObjectMemberFunction())
+  return getArg(0)->getBeginLoc();

cor3ntin wrote:

`getArg(0)` already has an assertion (and I don;t like having both an assertion 
and an if)

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


[clang-tools-extra] [clang-tidy] Add new check bugprone-capture-this-by-field (PR #130297)

2025-03-12 Thread Denis Mikhailov via cfe-commits


@@ -0,0 +1,144 @@
+// RUN: %check_clang_tidy -std=c++11-or-later %s 
bugprone-capturing-this-by-field %t -- -config="{CheckOptions: 
{bugprone-capturing-this-by-field.FunctionWrapperTypes: 
'::std::function;::Fn'}}" --
+
+namespace std {
+
+template
+class function;
+
+template
+class function {
+public:
+  function() noexcept;
+  template function(F &&);
+};
+
+} // namespace std
+
+struct Fn {
+  template Fn(F &&);
+};
+
+struct Basic {
+  Basic() : Captured([this]() { static_cast(this); }) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: using lambda expressions to 
capture 'this' and storing it in class member
+  std::function Captured;
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: note: 'std::function' that 
stores captured 'this'
+};
+
+struct AssignCapture {
+  AssignCapture() : Captured([Self = this]() { static_cast(Self); }) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: using lambda expressions to 
capture 'this' and storing it in class member
+  std::function Captured;
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: note: 'std::function' that 
stores captured 'this'
+};
+
+struct DeleteMoveAndCopy {
+  DeleteMoveAndCopy() : Captured([this]() { static_cast(this); }) {}
+  DeleteMoveAndCopy(DeleteMoveAndCopy const&) = delete;
+  DeleteMoveAndCopy(DeleteMoveAndCopy &&) = delete;
+  DeleteMoveAndCopy& operator=(DeleteMoveAndCopy const&) = delete;
+  DeleteMoveAndCopy& operator=(DeleteMoveAndCopy &&) = delete;
+  std::function Captured;
+};
+
+struct DeleteCopyImplicitDisabledMove {
+  DeleteCopyImplicitDisabledMove() : Captured([this]() { 
static_cast(this); }) {}
+  DeleteCopyImplicitDisabledMove(DeleteCopyImplicitDisabledMove const&) = 
delete;
+  DeleteCopyImplicitDisabledMove& operator=(DeleteCopyImplicitDisabledMove 
const&) = delete;

denzor200 wrote:

We don't really need to add boost headers at all, since noncopyable is simplest 
and tidy to implement by ourself:
```
namespace boost {
  class noncopyable
  {
  protected:
  noncopyable() {}
  ~noncopyable() {}
  private:
  noncopyable( const noncopyable& );
  noncopyable& operator=( const noncopyable& );
  };
}
``` 

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


[clang] fix(clang/**.py): fix invalid escape sequences (PR #94029)

2025-03-12 Thread Donát Nagy via cfe-commits

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


[clang] [HLSL] error on out of bounds vector accesses (PR #128952)

2025-03-12 Thread Hans Wennborg via cfe-commits

zmodem wrote:

This broke our builds. Here's a small repro:

```
$ cat /tmp/a.cc
#include 
__m256i parens;
int f() {
  return ((__v32qi)parens)[31];
}
$ build/bin/clang -c /tmp/a.cc
/tmp/a.cc:4:20: error: vector element index 31 is out of bounds
4 |   return ((__v32qi)parens)[31];
  |^
1 error generated.
```

`__v32qi` is a 32-element vector of char.

I'll revert to green for now.

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


[clang] [flang] [llvm] [mlir] [TargetRegistry] Accept Triple in createTargetMachine() (NFC) (PR #130940)

2025-03-12 Thread Nikita Popov via cfe-commits


@@ -116,7 +116,7 @@ body: |
 successors: %bb.2, %bb.4
 liveins: $rdi, $rsi
 
-%1:gr32 = COPY $rsi
+%1:gr64 = COPY $rsi

nikic wrote:

I believe this test was previously creating a 32-bit TM by accident.

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


[clang] [flang] [llvm] [mlir] [TargetRegistry] Accept Triple in createTargetMachine() (NFC) (PR #130940)

2025-03-12 Thread Yingwei Zheng via cfe-commits


@@ -93,7 +93,7 @@ LLVMState::LLVMState(std::unique_ptr TM,
 std::unique_ptr LLVMState::createTargetMachine() const {
   return std::unique_ptr(
   TheTargetMachine->getTarget().createTargetMachine(
-  TheTargetMachine->getTargetTriple().normalize(),
+  Triple(TheTargetMachine->getTargetTriple().normalize()),

dtcxzyw wrote:

```suggestion
  TheTargetMachine->getTargetTriple(),
```

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


[clang] [flang] [llvm] [mlir] [TargetRegistry] Accept Triple in createTargetMachine() (NFC) (PR #130940)

2025-03-12 Thread Nikita Popov via cfe-commits


@@ -93,7 +93,7 @@ LLVMState::LLVMState(std::unique_ptr TM,
 std::unique_ptr LLVMState::createTargetMachine() const {
   return std::unique_ptr(
   TheTargetMachine->getTarget().createTargetMachine(
-  TheTargetMachine->getTargetTriple().normalize(),
+  Triple(TheTargetMachine->getTargetTriple().normalize()),

nikic wrote:

I tried that initially, but this one seems to be actually important (there are 
test failures otherwise).

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


[clang] fix(clang/**.py): fix invalid escape sequences (PR #94029)

2025-03-12 Thread Donát Nagy via cfe-commits

https://github.com/NagyDonat commented:

The change in `clang/test/Analysis/check-analyzer-fixit.py` is a good step 
forward, it indeed fixes an invalid escape sequence[1].

However, I don't see any reason for the changes in 
`clang/docs/tools/dump_ast_matchers.py`: those were raw strings, so there 
cannot be "invalid escapes sequences" within them. Please elaborate the reason 
why you want to apply these changes.

[1]: For readers unfamiliar with Python: the character combination `\-` does 
not have special meaning in Python string literals; so in older Python version 
these two characters were directly included into the string. However, this 
behavior is deprecated and in the future unrecognized escape sequences will 
cause `SyntaxError` (in non-raw strings).

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


[clang] [llvm] [MIPS] Add MIPS i6400 and i6500 processors (PR #130587)

2025-03-12 Thread Mallikarjuna Gouda via cfe-commits

https://github.com/mgoudar updated 
https://github.com/llvm/llvm-project/pull/130587

>From 4f9c5b5b844a61b760a3462994c7736542c14ca4 Mon Sep 17 00:00:00 2001
From: Mallikarjuna Gouda 
Date: Mon, 10 Mar 2025 15:42:39 +0530
Subject: [PATCH 1/4] [MIPS] Add MIPS i6400 and i6500 processors

The i6400 and i6500 are high performance multi-core microprocessors
from MIPS that provide best in class power efficiency for use in
system-on-chip  (SoC) applications. i6400 and i6500 implements
Release 6 of the MIPS64 Instruction Set Architecture with full
hardware multithreading and hardware virtualization support.

Scheduling model shall be added in separate commit/PR.
---
 clang/lib/Basic/Targets/Mips.cpp  |  4 +++-
 clang/lib/Driver/ToolChains/Arch/Mips.cpp |  4 
 clang/lib/Driver/ToolChains/Gnu.cpp   |  4 +++-
 clang/test/Driver/mips-abi.c  | 24 +++
 llvm/docs/ReleaseNotes.md |  2 ++
 llvm/lib/Target/Mips/Mips.td  | 10 ++
 llvm/lib/Target/Mips/MipsSubtarget.h  |  2 +-
 7 files changed, 47 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Basic/Targets/Mips.cpp b/clang/lib/Basic/Targets/Mips.cpp
index 866be53c8a363..08f9e3c29d1ed 100644
--- a/clang/lib/Basic/Targets/Mips.cpp
+++ b/clang/lib/Basic/Targets/Mips.cpp
@@ -47,6 +47,8 @@ bool MipsTargetInfo::processorSupportsGPR64() const {
   .Case("mips64r6", true)
   .Case("octeon", true)
   .Case("octeon+", true)
+  .Case("i6400", true)
+  .Case("i6500", true)
   .Default(false);
 }
 
@@ -54,7 +56,7 @@ static constexpr llvm::StringLiteral ValidCPUNames[] = {
 {"mips1"},  {"mips2"},{"mips3"},{"mips4"},{"mips5"},
 {"mips32"}, {"mips32r2"}, {"mips32r3"}, {"mips32r5"}, {"mips32r6"},
 {"mips64"}, {"mips64r2"}, {"mips64r3"}, {"mips64r5"}, {"mips64r6"},
-{"octeon"}, {"octeon+"}, {"p5600"}};
+{"octeon"}, {"octeon+"},  {"p5600"},{"i6400"},{"i6500"}};
 
 bool MipsTargetInfo::isValidCPUName(StringRef Name) const {
   return llvm::is_contained(ValidCPUNames, Name);
diff --git a/clang/lib/Driver/ToolChains/Arch/Mips.cpp 
b/clang/lib/Driver/ToolChains/Arch/Mips.cpp
index ca0745fc2b32d..9c817f238524c 100644
--- a/clang/lib/Driver/ToolChains/Arch/Mips.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/Mips.cpp
@@ -104,6 +104,8 @@ void mips::getMipsCPUAndABI(const ArgList &Args, const 
llvm::Triple &Triple,
   .Case("mips64r6", "n64")
   .Case("octeon", "n64")
   .Case("p5600", "o32")
+  .Case("i6400", "n64")
+  .Case("i6500", "n64")
   .Default("");
   }
 
@@ -514,5 +516,7 @@ bool mips::supportsIndirectJumpHazardBarrier(StringRef 
&CPU) {
   .Case("mips64r6", true)
   .Case("octeon", true)
   .Case("p5600", true)
+  .Case("i6400", true)
+  .Case("i6500", true)
   .Default(false);
 }
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index f56eeda3cb5f6..68c288f516fba 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -1501,7 +1501,9 @@ bool clang::driver::findMIPSMultilibs(const Driver &D,
   CPUName == "mips64r5" || CPUName == "octeon" ||
   CPUName == "octeon+",
   "-march=mips64r2", Flags);
-  addMultilibFlag(CPUName == "mips64r6", "-march=mips64r6", Flags);
+  addMultilibFlag(CPUName == "mips64r6" || CPUName == "i6400" ||
+  CPUName == "i6500",
+  "-march=mips64r6", Flags);
   addMultilibFlag(isMicroMips(Args), "-mmicromips", Flags);
   addMultilibFlag(tools::mips::isUCLibc(Args), "-muclibc", Flags);
   addMultilibFlag(tools::mips::isNaN2008(D, Args, TargetTriple), "-mnan=2008",
diff --git a/clang/test/Driver/mips-abi.c b/clang/test/Driver/mips-abi.c
index 06570b50928a1..9a2180c516a61 100644
--- a/clang/test/Driver/mips-abi.c
+++ b/clang/test/Driver/mips-abi.c
@@ -121,6 +121,30 @@
 // MIPS-ARCH-P5600-N64: error: ABI 'n64' is not supported on CPU 'p5600'
 //
 // RUN: %clang --target=mips-linux-gnu -### -c %s \
+// RUN:-march=i6400 2>&1 \
+// RUN:   | FileCheck -check-prefix=MIPS-ARCH-I6400 %s
+// MIPS-ARCH-I6400: "-target-cpu" "i6400"
+// MIPS-ARCH-I6400: "-target-abi" "o32"
+//
+// RUN: %clang --target=mips-linux-gnu -### -c %s \
+// RUN:-march=i6400 -mabi=64 2>&1 \
+// RUN:   | FileCheck -check-prefix=MIPS-ARCH-I6400-N64 %s
+// MIPS-ARCH-I6400-N64: "-target-cpu" "i6400"
+// MIPS-ARCH-I6400-N64: "-target-abi" "n64"
+//
+// RUN: %clang --target=mips-linux-gnu -### -c %s \
+// RUN:-march=i6500 2>&1 \
+// RUN:   | FileCheck -check-prefix=MIPS-ARCH-I6500 %s
+// MIPS-ARCH-I6500: "-target-cpu" "i6500"
+// MIPS-ARCH-I6500: "-target-abi" "o32"
+//
+// RUN: %clang --target=mips-linux-gnu -### -c %s \
+// RUN:-march=i6500 -mabi=64 2>&1 \
+// RUN:   | FileCheck -check-prefix=MIPS-ARCH-I6500-N64 %s
+// MIPS-ARCH-I6500-N64: "-target

[clang] [clang-tools-extra] [clang] improve class type sugar preservation in pointers to members (PR #130537)

2025-03-12 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

I had already done so, it's practically no change: 
https://llvm-compile-time-tracker.com/compare.php?from=cce9f360b50ca5a95d5cb550e27a8f6757423460&to=20841e444c0f8d48c6c9d34a77fe48164f7ae728&stat=instructions:u

https://github.com/llvm/llvm-project/pull/130537
___
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] Avoid processing declarations in system headers (PR #128150)

2025-03-12 Thread Carlos Galvez via cfe-commits

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


[clang] [flang] [llvm] [mlir] [TargetRegistry] Accept Triple in createTargetMachine() (NFC) (PR #130940)

2025-03-12 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-risc-v

Author: Nikita Popov (nikic)


Changes

This avoids doing a Triple -> std::string -> Triple round trip in lots of 
places, now that the Module stores a Triple.

---

Patch is 51.13 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/130940.diff


62 Files Affected:

- (modified) bolt/lib/Passes/AsmDump.cpp (+1-1) 
- (modified) clang/lib/CodeGen/BackendUtil.cpp (+1-1) 
- (modified) clang/lib/Interpreter/DeviceOffload.cpp (+1-1) 
- (modified) clang/lib/Interpreter/Wasm.cpp (+2-3) 
- (modified) clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp (+2-2) 
- (modified) clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp (+1-1) 
- (modified) clang/tools/driver/cc1_main.cpp (+10-6) 
- (modified) flang/tools/bbc/bbc.cpp (+1-1) 
- (modified) flang/tools/flang-driver/fc1_main.cpp (+2-2) 
- (modified) llvm/examples/Kaleidoscope/Chapter8/toy.cpp (+1-1) 
- (modified) llvm/include/llvm/MC/TargetRegistry.h (+3-3) 
- (modified) llvm/lib/CodeGen/CommandFlags.cpp (+1-1) 
- (modified) llvm/lib/DWARFLinker/Classic/DWARFStreamer.cpp (+1-1) 
- (modified) llvm/lib/DWARFLinker/Parallel/DWARFEmitterImpl.cpp (+1-1) 
- (modified) llvm/lib/ExecutionEngine/Orc/JITTargetMachineBuilder.cpp (+2-3) 
- (modified) llvm/lib/ExecutionEngine/TargetSelect.cpp (+3-4) 
- (modified) llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp (+1-1) 
- (modified) llvm/lib/LTO/LTOBackend.cpp (+1-1) 
- (modified) llvm/lib/LTO/LTOCodeGenerator.cpp (+2-2) 
- (modified) llvm/lib/LTO/LTOModule.cpp (+2-2) 
- (modified) llvm/lib/LTO/ThinLTOCodeGenerator.cpp (+1-1) 
- (modified) llvm/lib/Target/SPIRV/SPIRVAPI.cpp (+1-1) 
- (modified) llvm/lib/Target/TargetMachineC.cpp (+4-4) 
- (modified) llvm/tools/llc/llc.cpp (+2-2) 
- (modified) llvm/tools/llvm-exegesis/lib/LlvmState.cpp (+2-2) 
- (modified) llvm/tools/llvm-split/llvm-split.cpp (+1-1) 
- (modified) llvm/unittests/CodeGen/AArch64SelectionDAGTest.cpp (+1-1) 
- (modified) llvm/unittests/CodeGen/AMDGPUMetadataTest.cpp (+3-2) 
- (modified) llvm/unittests/CodeGen/DroppedVariableStatsMIRTest.cpp (+2-1) 
- (modified) llvm/unittests/CodeGen/GlobalISel/GISelMITest.cpp (+4-4) 
- (modified) llvm/unittests/CodeGen/InstrRefLDVTest.cpp (+3-3) 
- (modified) llvm/unittests/CodeGen/MachineDomTreeUpdaterTest.cpp (+3-3) 
- (modified) llvm/unittests/CodeGen/PassManagerTest.cpp (+3-5) 
- (modified) llvm/unittests/CodeGen/SelectionDAGAddressAnalysisTest.cpp (+1-1) 
- (modified) llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp (+1-1) 
- (modified) llvm/unittests/CodeGen/TargetOptionsTest.cpp (+2-2) 
- (modified) llvm/unittests/CodeGen/TestAsmPrinter.cpp (+2-2) 
- (modified) llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp (+1-1) 
- (modified) llvm/unittests/MC/AMDGPU/DwarfRegMappings.cpp (+4-3) 
- (modified) llvm/unittests/MI/LiveIntervalTest.cpp (+1-1) 
- (modified) llvm/unittests/MIR/MachineMetadata.cpp (+2-1) 
- (modified) llvm/unittests/MIR/MachineStableHashTest.cpp (+2-1) 
- (modified) llvm/unittests/Target/AArch64/AArch64RegisterInfoTest.cpp (+1-1) 
- (modified) llvm/unittests/Target/AArch64/AArch64SVESchedPseudoTest.cpp (+1-1) 
- (modified) llvm/unittests/Target/AArch64/AddressingModes.cpp (+1-1) 
- (modified) llvm/unittests/Target/AArch64/Immediates.cpp (+1-1) 
- (modified) llvm/unittests/Target/AArch64/InstSizes.cpp (+1-1) 
- (modified) llvm/unittests/Target/AArch64/MatrixRegisterAliasing.cpp (+1-1) 
- (modified) llvm/unittests/Target/AMDGPU/AMDGPUUnitTests.cpp (+3-2) 
- (modified) llvm/unittests/Target/AMDGPU/PALMetadata.cpp (+3-3) 
- (modified) llvm/unittests/Target/ARM/InstSizes.cpp (+1-1) 
- (modified) llvm/unittests/Target/ARM/MachineInstrTest.cpp (+6-6) 
- (modified) llvm/unittests/Target/LoongArch/InstSizes.cpp (+1-1) 
- (modified) llvm/unittests/Target/PowerPC/AIXRelocModelTest.cpp (+1-1) 
- (modified) llvm/unittests/Target/RISCV/RISCVInstrInfoTest.cpp (+1-1) 
- (modified) llvm/unittests/Target/VE/MachineInstrTest.cpp (+1-1) 
- (modified) llvm/unittests/Target/WebAssembly/WebAssemblyExceptionInfoTest.cpp 
(+1-1) 
- (modified) llvm/unittests/Target/X86/MachineSizeOptsTest.cpp (+1-1) 
- (modified) llvm/unittests/Target/X86/TernlogTest.cpp (+1-1) 
- (modified) llvm/unittests/tools/llvm-exegesis/Common/AssemblerUtils.h (+8-9) 
- (modified) mlir/lib/Target/LLVM/ModuleToObject.cpp (+2-2) 
- (modified) offload/plugins-nextgen/common/src/JIT.cpp (+1-1) 


``diff
diff --git a/bolt/lib/Passes/AsmDump.cpp b/bolt/lib/Passes/AsmDump.cpp
index 97f985d56ce64..08191669e72f3 100644
--- a/bolt/lib/Passes/AsmDump.cpp
+++ b/bolt/lib/Passes/AsmDump.cpp
@@ -143,7 +143,7 @@ void dumpFunction(const BinaryFunction &BF) {
 std::move(MCEInstance.MCE), std::move(MAB)));
   AsmStreamer->initSections(true, *BC.STI);
   std::unique_ptr TM(BC.TheTarget->createTargetMachine(
-  BC.TripleName, "", "", TargetOptions(), std::nullopt));
+  *BC.TheTriple, "", "", TargetOptions(), std::nullopt));
   std::unique_ptr MAP(

[clang] [flang] [llvm] [mlir] [TargetRegistry] Accept Triple in createTargetMachine() (NFC) (PR #130940)

2025-03-12 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-backend-webassembly

@llvm/pr-subscribers-backend-amdgpu

Author: Nikita Popov (nikic)


Changes

This avoids doing a Triple -> std::string -> Triple round trip in lots of 
places, now that the Module stores a Triple.

---

Patch is 51.13 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/130940.diff


62 Files Affected:

- (modified) bolt/lib/Passes/AsmDump.cpp (+1-1) 
- (modified) clang/lib/CodeGen/BackendUtil.cpp (+1-1) 
- (modified) clang/lib/Interpreter/DeviceOffload.cpp (+1-1) 
- (modified) clang/lib/Interpreter/Wasm.cpp (+2-3) 
- (modified) clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp (+2-2) 
- (modified) clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp (+1-1) 
- (modified) clang/tools/driver/cc1_main.cpp (+10-6) 
- (modified) flang/tools/bbc/bbc.cpp (+1-1) 
- (modified) flang/tools/flang-driver/fc1_main.cpp (+2-2) 
- (modified) llvm/examples/Kaleidoscope/Chapter8/toy.cpp (+1-1) 
- (modified) llvm/include/llvm/MC/TargetRegistry.h (+3-3) 
- (modified) llvm/lib/CodeGen/CommandFlags.cpp (+1-1) 
- (modified) llvm/lib/DWARFLinker/Classic/DWARFStreamer.cpp (+1-1) 
- (modified) llvm/lib/DWARFLinker/Parallel/DWARFEmitterImpl.cpp (+1-1) 
- (modified) llvm/lib/ExecutionEngine/Orc/JITTargetMachineBuilder.cpp (+2-3) 
- (modified) llvm/lib/ExecutionEngine/TargetSelect.cpp (+3-4) 
- (modified) llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp (+1-1) 
- (modified) llvm/lib/LTO/LTOBackend.cpp (+1-1) 
- (modified) llvm/lib/LTO/LTOCodeGenerator.cpp (+2-2) 
- (modified) llvm/lib/LTO/LTOModule.cpp (+2-2) 
- (modified) llvm/lib/LTO/ThinLTOCodeGenerator.cpp (+1-1) 
- (modified) llvm/lib/Target/SPIRV/SPIRVAPI.cpp (+1-1) 
- (modified) llvm/lib/Target/TargetMachineC.cpp (+4-4) 
- (modified) llvm/tools/llc/llc.cpp (+2-2) 
- (modified) llvm/tools/llvm-exegesis/lib/LlvmState.cpp (+2-2) 
- (modified) llvm/tools/llvm-split/llvm-split.cpp (+1-1) 
- (modified) llvm/unittests/CodeGen/AArch64SelectionDAGTest.cpp (+1-1) 
- (modified) llvm/unittests/CodeGen/AMDGPUMetadataTest.cpp (+3-2) 
- (modified) llvm/unittests/CodeGen/DroppedVariableStatsMIRTest.cpp (+2-1) 
- (modified) llvm/unittests/CodeGen/GlobalISel/GISelMITest.cpp (+4-4) 
- (modified) llvm/unittests/CodeGen/InstrRefLDVTest.cpp (+3-3) 
- (modified) llvm/unittests/CodeGen/MachineDomTreeUpdaterTest.cpp (+3-3) 
- (modified) llvm/unittests/CodeGen/PassManagerTest.cpp (+3-5) 
- (modified) llvm/unittests/CodeGen/SelectionDAGAddressAnalysisTest.cpp (+1-1) 
- (modified) llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp (+1-1) 
- (modified) llvm/unittests/CodeGen/TargetOptionsTest.cpp (+2-2) 
- (modified) llvm/unittests/CodeGen/TestAsmPrinter.cpp (+2-2) 
- (modified) llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp (+1-1) 
- (modified) llvm/unittests/MC/AMDGPU/DwarfRegMappings.cpp (+4-3) 
- (modified) llvm/unittests/MI/LiveIntervalTest.cpp (+1-1) 
- (modified) llvm/unittests/MIR/MachineMetadata.cpp (+2-1) 
- (modified) llvm/unittests/MIR/MachineStableHashTest.cpp (+2-1) 
- (modified) llvm/unittests/Target/AArch64/AArch64RegisterInfoTest.cpp (+1-1) 
- (modified) llvm/unittests/Target/AArch64/AArch64SVESchedPseudoTest.cpp (+1-1) 
- (modified) llvm/unittests/Target/AArch64/AddressingModes.cpp (+1-1) 
- (modified) llvm/unittests/Target/AArch64/Immediates.cpp (+1-1) 
- (modified) llvm/unittests/Target/AArch64/InstSizes.cpp (+1-1) 
- (modified) llvm/unittests/Target/AArch64/MatrixRegisterAliasing.cpp (+1-1) 
- (modified) llvm/unittests/Target/AMDGPU/AMDGPUUnitTests.cpp (+3-2) 
- (modified) llvm/unittests/Target/AMDGPU/PALMetadata.cpp (+3-3) 
- (modified) llvm/unittests/Target/ARM/InstSizes.cpp (+1-1) 
- (modified) llvm/unittests/Target/ARM/MachineInstrTest.cpp (+6-6) 
- (modified) llvm/unittests/Target/LoongArch/InstSizes.cpp (+1-1) 
- (modified) llvm/unittests/Target/PowerPC/AIXRelocModelTest.cpp (+1-1) 
- (modified) llvm/unittests/Target/RISCV/RISCVInstrInfoTest.cpp (+1-1) 
- (modified) llvm/unittests/Target/VE/MachineInstrTest.cpp (+1-1) 
- (modified) llvm/unittests/Target/WebAssembly/WebAssemblyExceptionInfoTest.cpp 
(+1-1) 
- (modified) llvm/unittests/Target/X86/MachineSizeOptsTest.cpp (+1-1) 
- (modified) llvm/unittests/Target/X86/TernlogTest.cpp (+1-1) 
- (modified) llvm/unittests/tools/llvm-exegesis/Common/AssemblerUtils.h (+8-9) 
- (modified) mlir/lib/Target/LLVM/ModuleToObject.cpp (+2-2) 
- (modified) offload/plugins-nextgen/common/src/JIT.cpp (+1-1) 


``diff
diff --git a/bolt/lib/Passes/AsmDump.cpp b/bolt/lib/Passes/AsmDump.cpp
index 97f985d56ce64..08191669e72f3 100644
--- a/bolt/lib/Passes/AsmDump.cpp
+++ b/bolt/lib/Passes/AsmDump.cpp
@@ -143,7 +143,7 @@ void dumpFunction(const BinaryFunction &BF) {
 std::move(MCEInstance.MCE), std::move(MAB)));
   AsmStreamer->initSections(true, *BC.STI);
   std::unique_ptr TM(BC.TheTarget->createTargetMachine(
-  BC.TripleName, "", "", TargetOptions(), std::nullopt));
+  *BC.TheTriple, "", "", TargetOptions(),

[clang] [flang] [llvm] [mlir] [TargetRegistry] Accept Triple in createTargetMachine() (NFC) (PR #130940)

2025-03-12 Thread Nikita Popov via cfe-commits

https://github.com/nikic created 
https://github.com/llvm/llvm-project/pull/130940

This avoids doing a Triple -> std::string -> Triple round trip in lots of 
places, now that the Module stores a Triple.

>From 7aa005a4e9aa14c79a527719936824bcfe9a409c Mon Sep 17 00:00:00 2001
From: Nikita Popov 
Date: Wed, 12 Mar 2025 10:57:58 +0100
Subject: [PATCH] [TargetRegistry] Accept Triple in createTargetMachine() (NFC)

This avoids doing a Triple -> std::string -> Triple round trip
in lots of places, now that the Module stores a Triple.
---
 bolt/lib/Passes/AsmDump.cpp |  2 +-
 clang/lib/CodeGen/BackendUtil.cpp   |  2 +-
 clang/lib/Interpreter/DeviceOffload.cpp |  2 +-
 clang/lib/Interpreter/Wasm.cpp  |  5 ++---
 .../clang-fuzzer/handle-llvm/handle_llvm.cpp|  4 ++--
 .../clang-linker-wrapper/ClangLinkerWrapper.cpp |  2 +-
 clang/tools/driver/cc1_main.cpp | 16 ++--
 flang/tools/bbc/bbc.cpp |  2 +-
 flang/tools/flang-driver/fc1_main.cpp   |  4 ++--
 llvm/examples/Kaleidoscope/Chapter8/toy.cpp |  2 +-
 llvm/include/llvm/MC/TargetRegistry.h   |  6 +++---
 llvm/lib/CodeGen/CommandFlags.cpp   |  2 +-
 llvm/lib/DWARFLinker/Classic/DWARFStreamer.cpp  |  2 +-
 .../DWARFLinker/Parallel/DWARFEmitterImpl.cpp   |  2 +-
 .../Orc/JITTargetMachineBuilder.cpp |  5 ++---
 llvm/lib/ExecutionEngine/TargetSelect.cpp   |  7 +++
 llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp   |  2 +-
 llvm/lib/LTO/LTOBackend.cpp |  2 +-
 llvm/lib/LTO/LTOCodeGenerator.cpp   |  4 ++--
 llvm/lib/LTO/LTOModule.cpp  |  4 ++--
 llvm/lib/LTO/ThinLTOCodeGenerator.cpp   |  2 +-
 llvm/lib/Target/SPIRV/SPIRVAPI.cpp  |  2 +-
 llvm/lib/Target/TargetMachineC.cpp  |  8 
 llvm/tools/llc/llc.cpp  |  4 ++--
 llvm/tools/llvm-exegesis/lib/LlvmState.cpp  |  4 ++--
 llvm/tools/llvm-split/llvm-split.cpp|  2 +-
 .../CodeGen/AArch64SelectionDAGTest.cpp |  2 +-
 llvm/unittests/CodeGen/AMDGPUMetadataTest.cpp   |  5 +++--
 .../CodeGen/DroppedVariableStatsMIRTest.cpp |  3 ++-
 .../CodeGen/GlobalISel/GISelMITest.cpp  |  8 
 llvm/unittests/CodeGen/InstrRefLDVTest.cpp  |  6 +++---
 .../CodeGen/MachineDomTreeUpdaterTest.cpp   |  6 +++---
 llvm/unittests/CodeGen/PassManagerTest.cpp  |  8 +++-
 .../CodeGen/SelectionDAGAddressAnalysisTest.cpp |  2 +-
 .../CodeGen/SelectionDAGPatternMatchTest.cpp|  2 +-
 llvm/unittests/CodeGen/TargetOptionsTest.cpp|  4 ++--
 llvm/unittests/CodeGen/TestAsmPrinter.cpp   |  4 ++--
 .../DebugInfo/DWARF/DwarfGenerator.cpp  |  2 +-
 llvm/unittests/MC/AMDGPU/DwarfRegMappings.cpp   |  7 ---
 llvm/unittests/MI/LiveIntervalTest.cpp  |  2 +-
 llvm/unittests/MIR/MachineMetadata.cpp  |  3 ++-
 llvm/unittests/MIR/MachineStableHashTest.cpp|  3 ++-
 .../Target/AArch64/AArch64RegisterInfoTest.cpp  |  2 +-
 .../AArch64/AArch64SVESchedPseudoTest.cpp   |  2 +-
 .../Target/AArch64/AddressingModes.cpp  |  2 +-
 llvm/unittests/Target/AArch64/Immediates.cpp|  2 +-
 llvm/unittests/Target/AArch64/InstSizes.cpp |  2 +-
 .../Target/AArch64/MatrixRegisterAliasing.cpp   |  2 +-
 .../unittests/Target/AMDGPU/AMDGPUUnitTests.cpp |  5 +++--
 llvm/unittests/Target/AMDGPU/PALMetadata.cpp|  6 +++---
 llvm/unittests/Target/ARM/InstSizes.cpp |  2 +-
 llvm/unittests/Target/ARM/MachineInstrTest.cpp  | 12 ++--
 llvm/unittests/Target/LoongArch/InstSizes.cpp   |  2 +-
 .../Target/PowerPC/AIXRelocModelTest.cpp|  2 +-
 .../Target/RISCV/RISCVInstrInfoTest.cpp |  2 +-
 llvm/unittests/Target/VE/MachineInstrTest.cpp   |  2 +-
 .../WebAssemblyExceptionInfoTest.cpp|  2 +-
 .../Target/X86/MachineSizeOptsTest.cpp  |  2 +-
 llvm/unittests/Target/X86/TernlogTest.cpp   |  2 +-
 .../tools/llvm-exegesis/Common/AssemblerUtils.h | 17 -
 mlir/lib/Target/LLVM/ModuleToObject.cpp |  4 ++--
 offload/plugins-nextgen/common/src/JIT.cpp  |  2 +-
 62 files changed, 122 insertions(+), 118 deletions(-)

diff --git a/bolt/lib/Passes/AsmDump.cpp b/bolt/lib/Passes/AsmDump.cpp
index 97f985d56ce64..08191669e72f3 100644
--- a/bolt/lib/Passes/AsmDump.cpp
+++ b/bolt/lib/Passes/AsmDump.cpp
@@ -143,7 +143,7 @@ void dumpFunction(const BinaryFunction &BF) {
 std::move(MCEInstance.MCE), std::move(MAB)));
   AsmStreamer->initSections(true, *BC.STI);
   std::unique_ptr TM(BC.TheTarget->createTargetMachine(
-  BC.TripleName, "", "", TargetOptions(), std::nullopt));
+  *BC.TheTriple, "", "", TargetOptions(), std::nullopt));
   std::unique_ptr MAP(
   BC.TheTarget->createAsmPrinter(*TM, std::move(AsmStreamer)));
 
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 62a0e3c69bad1..7557cb84

[clang] [llvm] [ARM][Clang] Make `+nosimd` functional for AArch32 Targets (PR #130623)

2025-03-12 Thread Jack Styles via cfe-commits

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


[clang] fix(clang/**.py): fix invalid escape sequences (PR #94029)

2025-03-12 Thread Donát Nagy via cfe-commits

NagyDonat wrote:

> to me it seemed like the `r"..."` strings are supposed to be used for regular 
> expressions, and in this change you appear to transform those strings into 
> plain old strings. Could you help me understand this?

In Python the `r` string prefix stands for a _raw_ string literal where the 
escape sequences are not interpreted (see [relevant part of the language 
reference](https://docs.python.org/3/reference/lexical_analysis.html#escape-sequences)).
 
The presence or absence of the "r" prefix does not influence the _type_ of the 
object represented by the string literal -- it only influences the _contents_ 
of the string object. For example the raw string literal `r"\n+"` (three 
characters: backslash, letter "n", plus) is exactly equivalent to the plain old 
string literal `"\\n+" (where the two backslashes are interpreted as an escape 
sequence that produces a single backslash). (Note that without the `r` the 
literal `"\n+"` consists of two characters: a newline and a plus sign.)  

Raw strings are indeed frequently used for regular expressions, because a 
string that represents a regexp usually contains many backslashes and it's more 
comfortable to specify them as a raw string literal -- but there is no formal 
connection between them. (Unlike languages like Perl or shell scripts, regular 
expressions in Python are purely implemented within the standard library, there 
is no special syntax for them.)


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


[clang] [flang] [llvm] [mlir] [TargetRegistry] Accept Triple in createTargetMachine() (NFC) (PR #130940)

2025-03-12 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 553da9634dc4bae215e6c850d2de3186d09f9da5 
7aa005a4e9aa14c79a527719936824bcfe9a409c --extensions h,cpp -- 
bolt/lib/Passes/AsmDump.cpp clang/lib/CodeGen/BackendUtil.cpp 
clang/lib/Interpreter/DeviceOffload.cpp clang/lib/Interpreter/Wasm.cpp 
clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp 
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
clang/tools/driver/cc1_main.cpp flang/tools/bbc/bbc.cpp 
flang/tools/flang-driver/fc1_main.cpp 
llvm/examples/Kaleidoscope/Chapter8/toy.cpp 
llvm/include/llvm/MC/TargetRegistry.h llvm/lib/CodeGen/CommandFlags.cpp 
llvm/lib/DWARFLinker/Classic/DWARFStreamer.cpp 
llvm/lib/DWARFLinker/Parallel/DWARFEmitterImpl.cpp 
llvm/lib/ExecutionEngine/Orc/JITTargetMachineBuilder.cpp 
llvm/lib/ExecutionEngine/TargetSelect.cpp 
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp llvm/lib/LTO/LTOBackend.cpp 
llvm/lib/LTO/LTOCodeGenerator.cpp llvm/lib/LTO/LTOModule.cpp 
llvm/lib/LTO/ThinLTOCodeGenerator.cpp llvm/lib/Target/SPIRV/SPIRVAPI.cpp 
llvm/lib/Target/TargetMachineC.cpp llvm/tools/llc/llc.cpp 
llvm/tools/llvm-exegesis/lib/LlvmState.cpp llvm/tools/llvm-split/llvm-split.cpp 
llvm/unittests/CodeGen/AArch64SelectionDAGTest.cpp 
llvm/unittests/CodeGen/AMDGPUMetadataTest.cpp 
llvm/unittests/CodeGen/DroppedVariableStatsMIRTest.cpp 
llvm/unittests/CodeGen/GlobalISel/GISelMITest.cpp 
llvm/unittests/CodeGen/InstrRefLDVTest.cpp 
llvm/unittests/CodeGen/MachineDomTreeUpdaterTest.cpp 
llvm/unittests/CodeGen/PassManagerTest.cpp 
llvm/unittests/CodeGen/SelectionDAGAddressAnalysisTest.cpp 
llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp 
llvm/unittests/CodeGen/TargetOptionsTest.cpp 
llvm/unittests/CodeGen/TestAsmPrinter.cpp 
llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp 
llvm/unittests/MC/AMDGPU/DwarfRegMappings.cpp 
llvm/unittests/MI/LiveIntervalTest.cpp llvm/unittests/MIR/MachineMetadata.cpp 
llvm/unittests/MIR/MachineStableHashTest.cpp 
llvm/unittests/Target/AArch64/AArch64RegisterInfoTest.cpp 
llvm/unittests/Target/AArch64/AArch64SVESchedPseudoTest.cpp 
llvm/unittests/Target/AArch64/AddressingModes.cpp 
llvm/unittests/Target/AArch64/Immediates.cpp 
llvm/unittests/Target/AArch64/InstSizes.cpp 
llvm/unittests/Target/AArch64/MatrixRegisterAliasing.cpp 
llvm/unittests/Target/AMDGPU/AMDGPUUnitTests.cpp 
llvm/unittests/Target/AMDGPU/PALMetadata.cpp 
llvm/unittests/Target/ARM/InstSizes.cpp 
llvm/unittests/Target/ARM/MachineInstrTest.cpp 
llvm/unittests/Target/LoongArch/InstSizes.cpp 
llvm/unittests/Target/PowerPC/AIXRelocModelTest.cpp 
llvm/unittests/Target/RISCV/RISCVInstrInfoTest.cpp 
llvm/unittests/Target/VE/MachineInstrTest.cpp 
llvm/unittests/Target/WebAssembly/WebAssemblyExceptionInfoTest.cpp 
llvm/unittests/Target/X86/MachineSizeOptsTest.cpp 
llvm/unittests/Target/X86/TernlogTest.cpp 
llvm/unittests/tools/llvm-exegesis/Common/AssemblerUtils.h 
mlir/lib/Target/LLVM/ModuleToObject.cpp 
offload/plugins-nextgen/common/src/JIT.cpp
``





View the diff from clang-format here.


``diff
diff --git a/offload/plugins-nextgen/common/src/JIT.cpp 
b/offload/plugins-nextgen/common/src/JIT.cpp
index b77ce6dc6e..affedb1a33 100644
--- a/offload/plugins-nextgen/common/src/JIT.cpp
+++ b/offload/plugins-nextgen/common/src/JIT.cpp
@@ -114,9 +114,9 @@ createTargetMachine(Module &M, std::string CPU, unsigned 
OptLevel) {
 
   TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags(TT);
 
-  std::unique_ptr TM(T->createTargetMachine(
-  M.getTargetTriple(), CPU, Features.getString(), Options, RelocModel,
-  CodeModel, CGOptLevel));
+  std::unique_ptr TM(
+  T->createTargetMachine(M.getTargetTriple(), CPU, Features.getString(),
+ Options, RelocModel, CodeModel, CGOptLevel));
   if (!TM)
 return make_error("Failed to create target machine",
inconvertibleErrorCode());

``




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


[clang] [flang] [llvm] [mlir] [TargetRegistry] Accept Triple in createTargetMachine() (NFC) (PR #130940)

2025-03-12 Thread Matt Arsenault via cfe-commits


@@ -453,14 +453,14 @@ class Target {
   /// either the target triple from the module, or the target triple of the
   /// host if that does not exist.
   TargetMachine *createTargetMachine(
-  StringRef TT, StringRef CPU, StringRef Features,

arsenm wrote:

Can we keep a StringRef overload, at least for a while? As-is this is going to 
break a lot of downstream builds 

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


[clang] [llvm] [not for merge][RFC] Key Instructions front end demo (PR #130943)

2025-03-12 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-debuginfo

@llvm/pr-subscribers-clang

Author: Orlando Cazalet-Hyams (OCHyams)


Changes

This draft pull request demonstrates our proposed approach to annotating 
instructions with Key Instructions metadata. It's not fully complete but works 
as a proof of concept and I welcome and encourage feedback on the approach, as 
I'm not particularly familiar with Clang.

The Key Instructions project is introduced here 
https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668,
 which includes a "quick summary" section at the top which adds context for 
this PR.

I'll walk through the changes first, followed by some questions at the end.

Note: this PR doesn't include the LLVM parts, so you won't be able to try it 
out locally.

## Overview

We'd like Clang to annotate instructions with additional metadata (bundled 
inside DILocations) so that LLVM can make better `is_stmt` placement decisions. 
Specifically we'll add two new fields to DILocations: An "atom group" number 
for instructions that perform key functionality ("interesting" behaviour from a 
debugger-user perspective, see _Key Instructions: Solving the Code Location 
Problem for Optimized Code (C. Tice, . S. L. Graham, 2000)_); and an "atom 
rank" number which indicates precedence within a set of instructions that have 
the same atom group number.

In the project prototype we interpreted IR in a pre-optimisation pass to decide 
the metadata placement. Having Clang perform the annotation comes with several 
benefits: it allows the front end to be opinionated about stepping locations, 
it's more performant for the front end to do it, and it hopefully improves the 
chance that it can be adopted into other front ends in which the prototype 
approach isn't approprite.

First, here's an example to highlight the new metadata we'll be producing:

`$ cat -n test.cpp`
```
1.  void f(int a) {
2.int x[256] = {a};
3.  }
```
`clang++ test.cpp -gmlt -emit-llvm -S`
```
define hidden void @_Z1fi(i32 noundef %a) #0 !dbg !11 {
entry:
  %a.addr = alloca i32, align 4
  %x = alloca [256 x i32], align 16
  store i32 %a, ptr %a.addr, align 4
  call void @llvm.memset.p0.i64(ptr align 16 %x, i8 0, i64 1024, i1 
false), !dbg !14  ; atom 1, rank 1
  %arrayinit.begin = getelementptr inbounds [256 x i32], ptr %x, i64 0, i64 0, 
!dbg !15
  %0 = load i32, ptr %a.addr, align 4, !dbg !16 
  ; atom 1, rank 2
  store i32 %0, ptr %arrayinit.begin, align 4, !dbg !17 
  ; atom 1, rank 1
  ret void, !dbg !18
  ; atom 2, rank 1
}

...
!14 = !DILocation(line: 2, column: 7, scope: !11, atomGroup: 1, atomRank: 1)
!15 = !DILocation(line: 2, column: 16, scope: !11)
!16 = !DILocation(line: 2, column: 17, scope: !11, atomGroup: 1, atomRank: 2)
!17 = !DILocation(line: 2, column: 16, scope: !11, atomGroup: 1, atomRank: 1)
!18 = !DILocation(line: 3, column: 1, scope: !11, atomGroup: 2, atomRank: 1)
```
Atom 1 represents the aggregate initialization of `x`. The store and memset 
have rank 1. That gives them precedence the load of `a` with rank 2, which is 
essentially a "backup instruction" for the purposes of assigning `is_stmt`. If 
all rank 1 instructions are optimized away, we'll use that instead. Atom 2 
represents the implicit return (given the source location of the closing brace).

DWARF emission info for additional context (feel free to ignore). Not shown in this patch - During dwarf emission, for each atom group, the last instruction in a block that shares the lowest rank will be candidates for `is_stmt`. The wording is tricky, but essentially if any rank 1 instructions exist, higher rank (lower precedence) instructions won't be candidates for `is_stmt` even if they're in different blocks, but all the final rank 1 instructions in the group in different blocks will be. As an optimisation for convinience (mostly to minimise unecessary difference when the feature is enabled, but also to improve variable availability in some cases), we apply a heuristc that "floats" the `is_stmt` up to the first instruction in a contiguous block of instructions with the same line number. In the example above the `store` in atom 1 is the candidate for `is_stmt` (the `memset` comes before the `store` and the `load` is lower precedence as well as before the `store`). Because of the heuristic described above, the `is_stmt` flag floats up to the memset, as all the preceeding instructions have the same line number.
## Implementation We need to annotate assignments, conditional branches, some unconditional branches, and calls as these are instructions implementing "key functionality". The GEP used to compute the offset at which to store a value for an assignment is not interesting, but the store itself is. We also want to annotate "back

[clang] Better diagnostics when assertion fails in `consteval` (PR #130458)

2025-03-12 Thread A. Jiang via cfe-commits


@@ -107,6 +107,8 @@ def err_ice_too_large : Error<
   "integer constant expression evaluates to value %0 that cannot be "
   "represented in a %1-bit %select{signed|unsigned}2 integer type">;
 def err_expr_not_string_literal : Error<"expression is not a string literal">;
+def note_constexpr_assert_failed : Note<
+  "assertion failed in consteval context: '%0'">;

frederick-vs-ja wrote:

How about:
```suggestion
  "assertion failed in constant evaluation: '%0'">;
```
(Given that `consteval` is a C++20 keyword, while the phrase "constant 
evaluation" looks like plain English.)

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


[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-03-12 Thread Anutosh Bhat via cfe-commits

https://github.com/anutosh491 updated 
https://github.com/llvm/llvm-project/pull/127467

>From bd1b0b2a14afeb73755db3a7deb6bffd4f50778c Mon Sep 17 00:00:00 2001
From: anutosh491 
Date: Mon, 17 Feb 2025 15:33:20 +0530
Subject: [PATCH 1/2] Fix error recovery while PTU cleanup

---
 clang/lib/Interpreter/IncrementalParser.cpp |  2 +-
 clang/test/Interpreter/lambda.cpp   | 11 +--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Interpreter/IncrementalParser.cpp 
b/clang/lib/Interpreter/IncrementalParser.cpp
index 41d6304bd5f65..6343f17ed822a 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -176,7 +176,7 @@ void IncrementalParser::CleanUpPTU(TranslationUnitDecl 
*MostRecentTU) {
   // FIXME: We should de-allocate MostRecentTU
   for (Decl *D : MostRecentTU->decls()) {
 auto *ND = dyn_cast(D);
-if (!ND)
+if (!ND || ND->getDeclName().isEmpty())
   continue;
 // Check if we need to clean up the IdResolver chain.
 if (ND->getDeclName().getFETokenInfo() && !D->getLangOpts().ObjC &&
diff --git a/clang/test/Interpreter/lambda.cpp 
b/clang/test/Interpreter/lambda.cpp
index df75274a050b2..8f49f870fddb6 100644
--- a/clang/test/Interpreter/lambda.cpp
+++ b/clang/test/Interpreter/lambda.cpp
@@ -1,7 +1,8 @@
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
 // RUN: cat %s | clang-repl | FileCheck %s
-// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
+// RUN: cat %s | not clang-repl -Xcc -Xclang -Xcc -verify -Xcc -O2 | FileCheck 
%s
+
 extern "C" int printf(const char *, ...);
 
 auto l1 = []() { printf("ONE\n"); return 42; };
@@ -14,4 +15,10 @@ auto r2 = l2();
 auto r3 = l2();
 // CHECK: TWO
 
-%quit
+// Verify non-local lambda capture error is correctly reported
+int x = 42;
+
+// expected-error@+1 {{non-local lambda expression cannot have a 
capture-default}}
+auto capture = [&]() { return x * 2; };
+
+%quit
\ No newline at end of file

>From 1963cc341cd356f06a6c582235e47ac3cf144a63 Mon Sep 17 00:00:00 2001
From: anutosh491 
Date: Wed, 12 Mar 2025 16:43:45 +0530
Subject: [PATCH 2/2] Fix test as per review

---
 clang/test/Interpreter/lambda.cpp | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/test/Interpreter/lambda.cpp 
b/clang/test/Interpreter/lambda.cpp
index 8f49f870fddb6..7e8dcd61f20c8 100644
--- a/clang/test/Interpreter/lambda.cpp
+++ b/clang/test/Interpreter/lambda.cpp
@@ -1,7 +1,7 @@
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
 // RUN: cat %s | clang-repl | FileCheck %s
-// RUN: cat %s | not clang-repl -Xcc -Xclang -Xcc -verify -Xcc -O2 | FileCheck 
%s
+// RUN: cat %s | clang-repl -Xcc -Xclang -Xcc -verify -Xcc -O2 | FileCheck %s
 
 extern "C" int printf(const char *, ...);
 
@@ -21,4 +21,7 @@ int x = 42;
 // expected-error@+1 {{non-local lambda expression cannot have a 
capture-default}}
 auto capture = [&]() { return x * 2; };
 
+// Ensure valid C++ code before exiting
+x = 100;
+
 %quit
\ No newline at end of file

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


[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-03-12 Thread Vassil Vassilev via cfe-commits

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

LGTM!

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


[clang] [clang] Predefine `_CRT_USE_BUILTIN_OFFSETOF` in MS-compatible modes (PR #127568)

2025-03-12 Thread A. Jiang via cfe-commits

https://github.com/frederick-vs-ja updated 
https://github.com/llvm/llvm-project/pull/127568

>From 2c9e6e45944891af54cba9648297a996bb4d8cca Mon Sep 17 00:00:00 2001
From: "A. Jiang" 
Date: Tue, 18 Feb 2025 14:03:35 +0800
Subject: [PATCH 1/3] [clang] Predefine `_CRT_USE_BUILTIN_OFFSETOF` in
 MS-compatible modes

This patch makes Clang predefine `_CRT_USE_BUILTIN_OFFSETOF` in
MS-compatible modes. The macro can make the offsetof provided by MS
UCRT's `` to select the `__builtin_offsetof` version,
so with it Clang (Clang-cl) can directly consume UCRT's `offsetof`.

MSVC predefines the macro as `1` since at least VS 2017 19.14, but I
think it's also OK to define it in "older" compatible modes.
---
 clang/lib/Basic/Targets/OSTargets.cpp |  2 ++
 clang/test/Sema/offsetof-ucrt.c   | 17 +
 clang/test/SemaCXX/offsetof-ucrt.cpp  | 17 +
 3 files changed, 36 insertions(+)
 create mode 100644 clang/test/Sema/offsetof-ucrt.c
 create mode 100644 clang/test/SemaCXX/offsetof-ucrt.cpp

diff --git a/clang/lib/Basic/Targets/OSTargets.cpp 
b/clang/lib/Basic/Targets/OSTargets.cpp
index 8af6623e5cb15..2e57c286c9a16 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -220,6 +220,8 @@ static void addVisualCDefines(const LangOptions &Opts, 
MacroBuilder &Builder) {
 Builder.defineMacro("_MSC_FULL_VER", Twine(Opts.MSCompatibilityVersion));
 // FIXME We cannot encode the revision information into 32-bits
 Builder.defineMacro("_MSC_BUILD", Twine(1));
+// https://github.com/llvm/llvm-project/issues/59689
+Builder.defineMacro("_CRT_USE_BUILTIN_OFFSETOF", Twine(1));
 
 if (Opts.CPlusPlus11 && Opts.isCompatibleWithMSVC(LangOptions::MSVC2015))
   Builder.defineMacro("_HAS_CHAR16_T_LANGUAGE_SUPPORT", Twine(1));
diff --git a/clang/test/Sema/offsetof-ucrt.c b/clang/test/Sema/offsetof-ucrt.c
new file mode 100644
index 0..60c9ae3b5650e
--- /dev/null
+++ b/clang/test/Sema/offsetof-ucrt.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -verify 
-fms-compatibility
+// expected-no-diagnostics
+
+typedef __typeof__(sizeof(0)) size_t;
+
+#if defined _MSC_VER && !defined _CRT_USE_BUILTIN_OFFSETOF
+#ifdef __cplusplus
+#define offsetof(s,m) ((::size_t)&reinterpret_casts*)0)->m)))
+#else
+#define offsetof(s,m) ((size_t)&(((s*)0)->m))
+#endif
+#else
+#define offsetof(s,m) __builtin_offsetof(s,m)
+#endif
+
+struct S { int a; };
+_Static_assert(offsetof(struct S, a) == 0, "");
diff --git a/clang/test/SemaCXX/offsetof-ucrt.cpp 
b/clang/test/SemaCXX/offsetof-ucrt.cpp
new file mode 100644
index 0..a679fa01133f4
--- /dev/null
+++ b/clang/test/SemaCXX/offsetof-ucrt.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -verify 
-fms-compatibility
+// expected-no-diagnostics
+
+typedef __typeof__(sizeof(0)) size_t;
+
+#if defined _MSC_VER && !defined _CRT_USE_BUILTIN_OFFSETOF
+#ifdef __cplusplus
+#define offsetof(s,m) ((::size_t)&reinterpret_casts*)0)->m)))
+#else
+#define offsetof(s,m) ((size_t)&(((s*)0)->m))
+#endif
+#else
+#define offsetof(s,m) __builtin_offsetof(s,m)
+#endif
+
+struct S { int a; };
+_Static_assert(offsetof(S, a) == 0, "");

>From 4dc9bed47d7b4802e91b1774d8371e169f3f942c Mon Sep 17 00:00:00 2001
From: "A. Jiang" 
Date: Fri, 21 Feb 2025 17:00:37 +0800
Subject: [PATCH 2/3] Address @AaronBallman's review comments

---
 clang/lib/Basic/Targets/OSTargets.cpp |  2 +-
 clang/test/Sema/offsetof-ucrt.c   | 11 +++
 clang/test/SemaCXX/offsetof-ucrt.cpp  | 11 +++
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Basic/Targets/OSTargets.cpp 
b/clang/lib/Basic/Targets/OSTargets.cpp
index 2e57c286c9a16..e744e84a5b079 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -220,7 +220,7 @@ static void addVisualCDefines(const LangOptions &Opts, 
MacroBuilder &Builder) {
 Builder.defineMacro("_MSC_FULL_VER", Twine(Opts.MSCompatibilityVersion));
 // FIXME We cannot encode the revision information into 32-bits
 Builder.defineMacro("_MSC_BUILD", Twine(1));
-// https://github.com/llvm/llvm-project/issues/59689
+// Exposed by MSVC, used in their stddef.h.
 Builder.defineMacro("_CRT_USE_BUILTIN_OFFSETOF", Twine(1));
 
 if (Opts.CPlusPlus11 && Opts.isCompatibleWithMSVC(LangOptions::MSVC2015))
diff --git a/clang/test/Sema/offsetof-ucrt.c b/clang/test/Sema/offsetof-ucrt.c
index 60c9ae3b5650e..05c3d87ce66ca 100644
--- a/clang/test/Sema/offsetof-ucrt.c
+++ b/clang/test/Sema/offsetof-ucrt.c
@@ -1,8 +1,19 @@
 // RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -verify 
-fms-compatibility
+// RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -verify
 // expected-no-diagnostics
 
 typedef __typeof__(sizeof(0)) size_t;
 
+#ifdef _MSC_VER
+#ifndef _CRT_USE_BUILTIN_OFFSETOF
+#error _CRT_USE_BUILTIN_OFFSETOF should be predefined in MSVC-compatible modes.
+#endif
+#

[clang] [CIR] Don't generate ClangIR after an unrecoverable error occured (PR #130971)

2025-03-12 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Morris Hafner (mmha)


Changes



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


1 Files Affected:

- (modified) clang/lib/CIR/CodeGen/CIRGenerator.cpp (+2) 


``diff
diff --git a/clang/lib/CIR/CodeGen/CIRGenerator.cpp 
b/clang/lib/CIR/CodeGen/CIRGenerator.cpp
index 91070eda7d45a..6fa31ab707139 100644
--- a/clang/lib/CIR/CodeGen/CIRGenerator.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenerator.cpp
@@ -43,6 +43,8 @@ void CIRGenerator::Initialize(ASTContext &astContext) {
 mlir::ModuleOp CIRGenerator::getModule() const { return cgm->getModule(); }
 
 bool CIRGenerator::HandleTopLevelDecl(DeclGroupRef group) {
+  if (diags.hasUnrecoverableErrorOccurred())
+return true;
 
   for (Decl *decl : group)
 cgm->emitTopLevelDecl(decl);

``




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


[clang] [NFC][analyzer] Rename `CheckerBase::getCheckerName` to `getName` (PR #130953)

2025-03-12 Thread Balazs Benics via cfe-commits


@@ -41,19 +41,19 @@ class BugType {
 Checker(nullptr), SuppressOnSink(SuppressOnSink) {}
   BugType(const CheckerBase *Checker, StringRef Desc,
   StringRef Cat = categories::LogicError, bool SuppressOnSink = false)
-  : CheckerName(Checker->getCheckerName()), Description(Desc),
-Category(Cat), Checker(Checker), SuppressOnSink(SuppressOnSink) {}
+  : CheckerName(), Description(Desc), Category(Cat), Checker(Checker),

steakhal wrote:

Ah nvm.

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


[clang] [CIR] Don't generate ClangIR after an unrecoverable error occured (PR #130971)

2025-03-12 Thread Morris Hafner via cfe-commits


@@ -43,6 +43,8 @@ void CIRGenerator::Initialize(ASTContext &astContext) {
 mlir::ModuleOp CIRGenerator::getModule() const { return cgm->getModule(); }
 
 bool CIRGenerator::HandleTopLevelDecl(DeclGroupRef group) {
+  if (diags.hasUnrecoverableErrorOccurred())
+return true;

mmha wrote:

I chose to let parsing continue here mostly because this is what's being done 
in other ASTConsumers, but is there a reason to do so?

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


[clang] [CIR] Add transform test for cir-flatten-cfg (PR #130861)

2025-03-12 Thread Erich Keane via cfe-commits

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


[clang] [CIR] Add transform test for cir-flatten-cfg (PR #130861)

2025-03-12 Thread Erich Keane via cfe-commits


@@ -0,0 +1,58 @@
+// RUN: cir-opt %s -cir-flatten-cfg -o - | FileCheck %s
+
+module {
+  cir.func @foo() {
+cir.scope {
+  %0 = cir.alloca !cir.int, !cir.ptr>, ["a", init] 
{alignment = 4 : i64}
+  %1 = cir.const #cir.int<4> : !cir.int
+  cir.store %1, %0 : !cir.int, !cir.ptr>
+}
+cir.return
+  }
+// CHECK:  cir.func @foo() {
+// CHECK:cir.br ^bb1
+// CHECK:  ^bb1:  // pred: ^bb0
+// CHECK:%0 = cir.alloca !cir.int, !cir.ptr>, ["a", 
init] {alignment = 4 : i64}
+// CHECK:%1 = cir.const #cir.int<4> : !cir.int
+// CHECK:cir.store %1, %0 : !cir.int, !cir.ptr>
+// CHECK:cir.br ^bb2
+// CHECK:  ^bb2:  // pred: ^bb1
+// CHECK:cir.return
+// CHECK:  }
+
+  // Should drop empty scopes.
+  cir.func @empty_scope() {
+cir.scope {
+}
+cir.return
+  }
+// CHECK:  cir.func @empty_scope() {
+// CHECK:cir.return
+// CHECK:  }
+
+  cir.func @scope_with_return() -> !cir.int {
+%0 = cir.alloca !cir.int, !cir.ptr>, ["__retval"] 
{alignment = 4 : i64}
+cir.scope {
+  %2 = cir.const #cir.int<0> : !cir.int
+  cir.store %2, %0 : !cir.int, !cir.ptr>
+  %3 = cir.load %0 : !cir.ptr>, !cir.int
+  cir.return %3 : !cir.int
+}
+%1 = cir.load %0 : !cir.ptr>, !cir.int
+cir.return %1 : !cir.int
+  }
+
+// CHECK:  cir.func @scope_with_return() -> !cir.int {
+// CHECK:%0 = cir.alloca !cir.int, !cir.ptr>, 
["__retval"] {alignment = 4 : i64}
+// CHECK:cir.br ^bb1

erichkeane wrote:

This is another block that it seems to me could be removed/merged with `bb1`.  

I guess there are later passes that do these sorts of merges?  Also, removing 
`bb2` (which is an obviously `dead` block).

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


[clang] [llvm] [LLVM][SROA] Teach SROA how to "bitcast" between fixed and scalable vectors. (PR #130973)

2025-03-12 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff cd043e4fbe6125df4cb4993c625fa5e46194e478 
cb6a620c93b3809742fd067233844221e74dde4f --extensions cpp,c,h -- 
clang/test/CodeGen/RISCV/attr-riscv-rvv-vector-bits-less-8-call.c 
clang/test/CodeGen/RISCV/attr-riscv-rvv-vector-bits-less-8-cast.c 
clang/test/CodeGen/RISCV/attr-rvv-vector-bits-cast.c 
clang/test/CodeGen/attr-arm-sve-vector-bits-cast.c 
llvm/include/llvm/IR/Attributes.h llvm/include/llvm/IR/DerivedTypes.h 
llvm/lib/IR/AttributeImpl.h llvm/lib/IR/Attributes.cpp 
llvm/lib/Transforms/Scalar/SROA.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/include/llvm/IR/DerivedTypes.h 
b/llvm/include/llvm/IR/DerivedTypes.h
index 6c8f416708..f8b79eea19 100644
--- a/llvm/include/llvm/IR/DerivedTypes.h
+++ b/llvm/include/llvm/IR/DerivedTypes.h
@@ -556,7 +556,7 @@ public:
 
   /// This static method returns a VectorType with the same size-in-bits as
   /// SizeTy but with an element type that matches the scalar type of EltTy.
-  static VectorType* getWithSizeAndScalar(VectorType *SizeTy, Type *EltTy) {
+  static VectorType *getWithSizeAndScalar(VectorType *SizeTy, Type *EltTy) {
 if (SizeTy->getScalarType() == EltTy->getScalarType())
   return SizeTy;
 
diff --git a/llvm/lib/Transforms/Scalar/SROA.cpp 
b/llvm/lib/Transforms/Scalar/SROA.cpp
index 81a2b38410..2e758caa65 100644
--- a/llvm/lib/Transforms/Scalar/SROA.cpp
+++ b/llvm/lib/Transforms/Scalar/SROA.cpp
@@ -2198,8 +2198,7 @@ checkVectorTypesForPromotion(Partition &P, const 
DataLayout &DL,
  SmallVectorImpl &CandidateTys,
  bool HaveCommonEltTy, Type *CommonEltTy,
  bool HaveVecPtrTy, bool HaveCommonVecPtrTy,
- VectorType *CommonVecPtrTy,
- unsigned VScale) {
+ VectorType *CommonVecPtrTy, unsigned VScale) {
   // If we didn't find a vector type, nothing to do here.
   if (CandidateTys.empty())
 return nullptr;
@@ -2311,9 +2310,9 @@ static VectorType *createAndCheckVectorTypesForPromotion(
 }
   }
 
-  return checkVectorTypesForPromotion(P, DL, CandidateTys, HaveCommonEltTy,
-  CommonEltTy, HaveVecPtrTy,
-  HaveCommonVecPtrTy, CommonVecPtrTy, 
VScale);
+  return checkVectorTypesForPromotion(
+  P, DL, CandidateTys, HaveCommonEltTy, CommonEltTy, HaveVecPtrTy,
+  HaveCommonVecPtrTy, CommonVecPtrTy, VScale);
 }
 
 /// Test whether the given alloca partitioning and range of slices can be
@@ -2325,7 +2324,8 @@ static VectorType *createAndCheckVectorTypesForPromotion(
 /// SSA value. We only can ensure this for a limited set of operations, and we
 /// don't want to do the rewrites unless we are confident that the result will
 /// be promotable, so we have an early test here.
-static VectorType *isVectorPromotionViable(Partition &P, const DataLayout &DL, 
unsigned VScale) {
+static VectorType *isVectorPromotionViable(Partition &P, const DataLayout &DL,
+   unsigned VScale) {
   // Collect the candidate types for vector-based promotion. Also track whether
   // we have different element types.
   SmallVector CandidateTys;

``




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


[clang] [CIR] Add transform test for cir-flatten-cfg (PR #130861)

2025-03-12 Thread David Olsen via cfe-commits


@@ -0,0 +1,58 @@
+// RUN: cir-opt %s -cir-flatten-cfg -o - | FileCheck %s
+
+module {
+  cir.func @foo() {
+cir.scope {
+  %0 = cir.alloca !cir.int, !cir.ptr>, ["a", init] 
{alignment = 4 : i64}
+  %1 = cir.const #cir.int<4> : !cir.int
+  cir.store %1, %0 : !cir.int, !cir.ptr>
+}
+cir.return
+  }
+// CHECK:  cir.func @foo() {
+// CHECK:cir.br ^bb1

dkolsen-pgi wrote:

In the patch I am currently working on I am adding the Canonicalization pass, 
which merges/removes useless blocks.  So this CIR will look better after that 
is done.  (At least I think it will. The canonicalization pass runs before the 
flattening pass. I can't promise that it will also run after.)

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


[clang] [llvm] [LLVM][SROA] Teach SROA how to "bitcast" between fixed and scalable vectors. (PR #130973)

2025-03-12 Thread via cfe-commits

github-actions[bot] wrote:




:warning: undef deprecator found issues in your code. :warning:



You can test this locally with the following command:


``bash
git diff -U0 --pickaxe-regex -S 
'([^a-zA-Z0-9#_-]undef[^a-zA-Z0-9_-]|UndefValue::get)' 
cd043e4fbe6125df4cb4993c625fa5e46194e478 
cb6a620c93b3809742fd067233844221e74dde4f 
llvm/test/Transforms/SROA/scalable-vectors-with-known-vscale.ll 
clang/test/CodeGen/RISCV/attr-riscv-rvv-vector-bits-less-8-call.c 
clang/test/CodeGen/RISCV/attr-riscv-rvv-vector-bits-less-8-cast.c 
clang/test/CodeGen/RISCV/attr-rvv-vector-bits-cast.c 
clang/test/CodeGen/attr-arm-sve-vector-bits-cast.c 
llvm/include/llvm/IR/Attributes.h llvm/include/llvm/IR/DerivedTypes.h 
llvm/lib/IR/AttributeImpl.h llvm/lib/IR/Attributes.cpp 
llvm/lib/Transforms/Scalar/SROA.cpp 
llvm/test/Transforms/SROA/scalable-vectors.ll
``




The following files introduce new uses of undef:
 - llvm/test/Transforms/SROA/scalable-vectors-with-known-vscale.ll

[Undef](https://llvm.org/docs/LangRef.html#undefined-values) is now deprecated 
and should only be used in the rare cases where no replacement is possible. For 
example, a load of uninitialized memory yields `undef`. You should use `poison` 
values for placeholders instead.

In tests, avoid using `undef` and having tests that trigger undefined behavior. 
If you need an operand with some unimportant value, you can add a new argument 
to the function and use that instead.

For example, this is considered a bad practice:
```llvm
define void @fn() {
  ...
  br i1 undef, ...
}
```

Please use the following instead:
```llvm
define void @fn(i1 %cond) {
  ...
  br i1 %cond, ...
}
```

Please refer to the [Undefined Behavior 
Manual](https://llvm.org/docs/UndefinedBehavior.html) for more information.



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


[clang] [llvm] [LLVM][SROA] Teach SROA how to "bitcast" between fixed and scalable vectors. (PR #130973)

2025-03-12 Thread Paul Walker via cfe-commits

https://github.com/paulwalker-arm updated 
https://github.com/llvm/llvm-project/pull/130973

>From 487a823a9ec35df1a93109ef03630738bdc39ab1 Mon Sep 17 00:00:00 2001
From: Paul Walker 
Date: Fri, 7 Mar 2025 11:54:20 +
Subject: [PATCH] [LLVM][SROA] Teach SROA how to "bitcast" between fixed and
 scalable vectors.

For function whose vscale_range is limited to a single value we can
size scalable vectors. This aids SROA by allowing scalable vector
load and store operations to be considered for replacement whereby
bitcasts through memory can be replaced by vector insert or extract
operations.
---
 .../attr-riscv-rvv-vector-bits-less-8-call.c  |  38 ++-
 .../attr-riscv-rvv-vector-bits-less-8-cast.c  |   8 +-
 .../CodeGen/RISCV/attr-rvv-vector-bits-cast.c |  16 +-
 .../CodeGen/attr-arm-sve-vector-bits-cast.c   |  23 +-
 llvm/include/llvm/IR/Attributes.h |   4 +
 llvm/include/llvm/IR/DerivedTypes.h   |  16 ++
 llvm/lib/IR/AttributeImpl.h   |   1 +
 llvm/lib/IR/Attributes.cpp|   8 +
 llvm/lib/Transforms/Scalar/SROA.cpp   | 130 ++---
 .../scalable-vectors-with-known-vscale.ll | 248 ++
 llvm/test/Transforms/SROA/scalable-vectors.ll | 142 ++
 11 files changed, 563 insertions(+), 71 deletions(-)
 create mode 100644 
llvm/test/Transforms/SROA/scalable-vectors-with-known-vscale.ll

diff --git a/clang/test/CodeGen/RISCV/attr-riscv-rvv-vector-bits-less-8-call.c 
b/clang/test/CodeGen/RISCV/attr-riscv-rvv-vector-bits-less-8-call.c
index e2f02dc64f766..66fd466eccfef 100644
--- a/clang/test/CodeGen/RISCV/attr-riscv-rvv-vector-bits-less-8-call.c
+++ b/clang/test/CodeGen/RISCV/attr-riscv-rvv-vector-bits-less-8-call.c
@@ -26,11 +26,15 @@ typedef vbool64_t fixed_bool64_t 
__attribute__((riscv_rvv_vector_bits(__riscv_v_
 //
 // CHECK-128-LABEL: @call_bool32_ff(
 // CHECK-128-NEXT:  entry:
+// CHECK-128-NEXT:[[SAVED_VALUE:%.*]] = alloca <1 x i8>, align 1
+// CHECK-128-NEXT:[[SAVED_VALUE3:%.*]] = alloca <1 x i8>, align 1
 // CHECK-128-NEXT:[[SAVED_VALUE4:%.*]] = alloca , align 1
 // CHECK-128-NEXT:[[RETVAL_COERCE:%.*]] = alloca , align 1
-// CHECK-128-NEXT:[[TMP0:%.*]] = tail call  
@llvm.riscv.vmand.nxv2i1.i64( [[OP1_COERCE:%.*]],  [[OP2_COERCE:%.*]], i64 4)
-// CHECK-128-NEXT:store  [[TMP0]], ptr [[SAVED_VALUE4]], 
align 1, !tbaa [[TBAA6:![0-9]+]]
-// CHECK-128-NEXT:[[TMP1:%.*]] = load <1 x i8>, ptr [[SAVED_VALUE4]], 
align 1, !tbaa [[TBAA10:![0-9]+]]
+// CHECK-128-NEXT:
[[SAVED_VALUE_0_SAVED_VALUE_0_SAVED_VALUE_0_SAVED_VALUE_0_:%.*]] = load , ptr [[SAVED_VALUE]], align 1, !tbaa [[TBAA6:![0-9]+]]
+// CHECK-128-NEXT:
[[SAVED_VALUE3_0_SAVED_VALUE3_0_SAVED_VALUE3_0_SAVED_VALUE3_0_:%.*]] = load 
, ptr [[SAVED_VALUE3]], align 1, !tbaa [[TBAA6]]
+// CHECK-128-NEXT:[[TMP0:%.*]] = tail call  
@llvm.riscv.vmand.nxv2i1.i64( 
[[SAVED_VALUE_0_SAVED_VALUE_0_SAVED_VALUE_0_SAVED_VALUE_0_]],  
[[SAVED_VALUE3_0_SAVED_VALUE3_0_SAVED_VALUE3_0_SAVED_VALUE3_0_]], i64 4)
+// CHECK-128-NEXT:store  [[TMP0]], ptr [[SAVED_VALUE4]], 
align 1, !tbaa [[TBAA9:![0-9]+]]
+// CHECK-128-NEXT:[[TMP1:%.*]] = load <1 x i8>, ptr [[SAVED_VALUE4]], 
align 1, !tbaa [[TBAA6]]
 // CHECK-128-NEXT:store <1 x i8> [[TMP1]], ptr [[RETVAL_COERCE]], align 1
 // CHECK-128-NEXT:[[TMP2:%.*]] = load , ptr 
[[RETVAL_COERCE]], align 1
 // CHECK-128-NEXT:ret  [[TMP2]]
@@ -52,11 +56,15 @@ fixed_bool32_t call_bool32_ff(fixed_bool32_t op1, 
fixed_bool32_t op2) {
 //
 // CHECK-128-LABEL: @call_bool64_ff(
 // CHECK-128-NEXT:  entry:
+// CHECK-128-NEXT:[[SAVED_VALUE:%.*]] = alloca <1 x i8>, align 1
+// CHECK-128-NEXT:[[SAVED_VALUE3:%.*]] = alloca <1 x i8>, align 1
 // CHECK-128-NEXT:[[SAVED_VALUE4:%.*]] = alloca , align 1
 // CHECK-128-NEXT:[[RETVAL_COERCE:%.*]] = alloca , align 1
-// CHECK-128-NEXT:[[TMP0:%.*]] = tail call  
@llvm.riscv.vmand.nxv1i1.i64( [[OP1_COERCE:%.*]],  [[OP2_COERCE:%.*]], i64 2)
+// CHECK-128-NEXT:
[[SAVED_VALUE_0_SAVED_VALUE_0_SAVED_VALUE_0_SAVED_VALUE_0_:%.*]] = load , ptr [[SAVED_VALUE]], align 1, !tbaa [[TBAA6]]
+// CHECK-128-NEXT:
[[SAVED_VALUE3_0_SAVED_VALUE3_0_SAVED_VALUE3_0_SAVED_VALUE3_0_:%.*]] = load 
, ptr [[SAVED_VALUE3]], align 1, !tbaa [[TBAA6]]
+// CHECK-128-NEXT:[[TMP0:%.*]] = tail call  
@llvm.riscv.vmand.nxv1i1.i64( 
[[SAVED_VALUE_0_SAVED_VALUE_0_SAVED_VALUE_0_SAVED_VALUE_0_]],  
[[SAVED_VALUE3_0_SAVED_VALUE3_0_SAVED_VALUE3_0_SAVED_VALUE3_0_]], i64 2)
 // CHECK-128-NEXT:store  [[TMP0]], ptr [[SAVED_VALUE4]], 
align 1, !tbaa [[TBAA11:![0-9]+]]
-// CHECK-128-NEXT:[[TMP1:%.*]] = load <1 x i8>, ptr [[SAVED_VALUE4]], 
align 1, !tbaa [[TBAA10]]
+// CHECK-128-NEXT:[[TMP1:%.*]] = load <1 x i8>, ptr [[SAVED_VALUE4]], 
align 1, !tbaa [[TBAA6]]
 // CHECK-128-NEXT:store <1 x i8> [[TMP1]], ptr [[RETVAL_COERCE]], align 1
 // CHECK-128-NEXT:[[TMP2:%.*]] = load , ptr 
[[RETVAL_COERCE]], align 1
 // CHECK-128-NEXT:ret  [[TMP2]]
@@ -82,11 +90,13 @@ fixed_boo

[clang] [CIR] Upstream support for emitting ignored statements (PR #130869)

2025-03-12 Thread Erich Keane via cfe-commits


@@ -165,6 +165,33 @@ LValue CIRGenFunction::emitDeclRefLValue(const DeclRefExpr 
*e) {
   return LValue();
 }
 
+/// Emit code to compute the specified expression which
+/// can have any type.  The result is returned as an RValue struct.
+RValue CIRGenFunction::emitAnyExpr(const Expr *e, bool ignoreResult) {
+  switch (CIRGenFunction::getEvaluationKind(e->getType())) {
+  case cir::TEK_Scalar:
+return RValue::get(emitScalarExpr(e));
+  case cir::TEK_Complex:
+cgm.errorNYI(e->getSourceRange(), "emitAnyExpr: complex type");
+return RValue::get(nullptr);
+  case cir::TEK_Aggregate:
+cgm.errorNYI(e->getSourceRange(), "emitAnyExpr: aggregate type");
+return RValue::get(nullptr);
+  }
+  llvm_unreachable("bad evaluation kind");
+}
+
+/// Emit code to compute the specified expression, ignoring the result.
+void CIRGenFunction::emitIgnoredExpr(const Expr *e) {
+  if (e->isPRValue()) {
+assert(!cir::MissingFeatures::aggValueSlot());
+return (void)emitAnyExpr(e, true);

erichkeane wrote:

hah, this line is perhaps overly cute.

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


[clang] [CIR] Upstream support for emitting ignored statements (PR #130869)

2025-03-12 Thread Erich Keane via cfe-commits


@@ -0,0 +1,53 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value 
-fclangir -emit-cir %s -o %t.cir
+// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value 
-fclangir -emit-llvm %s -o %t.ll
+// RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM
+
+int f1(int i);
+
+int f1(int i) {
+  i;
+  return i;
+}
+
+//  CIR: module
+// CIR-NEXT: cir.func @f1(%arg0: !cir.int loc({{.*}})) -> !cir.int
+// CIR-NEXT:   %[[I_PTR:.*]] = cir.alloca !cir.int, 
!cir.ptr>, ["i", init] {alignment = 4 : i64}
+// CIR-NEXT:   cir.store %arg0, %[[I_PTR]] : !cir.int, 
!cir.ptr>
+// CIR-NEXT:   %[[I_IGNORED:.*]] = cir.load %[[I_PTR]] : !cir.ptr>, !cir.int
+// CIR-NEXT:   %[[I:.*]] = cir.load %[[I_PTR]] : !cir.ptr>, 
!cir.int
+// CIR-NEXT:   cir.return %[[I]] : !cir.int
+
+//  LLVM: define i32 @f1(i32 %[[I:.*]])

erichkeane wrote:

Is this llvm from clang itself, or via lowering from CIR? 

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


[clang] [CIR] Upstream support for emitting ignored statements (PR #130869)

2025-03-12 Thread Erich Keane via cfe-commits


@@ -55,10 +55,154 @@ mlir::LogicalResult CIRGenFunction::emitStmt(const Stmt *s,
   if (mlir::succeeded(emitSimpleStmt(s, useCurrentScope)))
 return mlir::success();
 
-  // Only a subset of simple statements are supported at the moment.  When more
-  // kinds of statements are supported, a
-  // switch (s->getStmtClass()) {
-  // will be added here.
+  switch (s->getStmtClass()) {
+
+#define STMT(Type, Base)
+#define ABSTRACT_STMT(Op)
+#define EXPR(Type, Base) case Stmt::Type##Class:
+#include "clang/AST/StmtNodes.inc"
+{
+  // Remember the block we came in on.
+  mlir::Block *incoming = builder.getInsertionBlock();
+  assert(incoming && "expression emission must have an insertion point");
+
+  emitIgnoredExpr(cast(s));

erichkeane wrote:

Can you explain what is happening here?  We are emitting EVERY expression type 
as an ignored expression?

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


[clang] [llvm] [LLVM][SROA] Teach SROA how to "bitcast" between fixed and scalable vectors. (PR #130973)

2025-03-12 Thread Paul Walker via cfe-commits

https://github.com/paulwalker-arm created 
https://github.com/llvm/llvm-project/pull/130973

For function whose vscale_range is limited to a single value we can size 
scalable vectors. This aids SROA by allowing scalable vector load and store 
operations to be considered for replacement whereby bitcasts through memory can 
be replaced by vector insert or extract operations.

>From cb6a620c93b3809742fd067233844221e74dde4f Mon Sep 17 00:00:00 2001
From: Paul Walker 
Date: Fri, 7 Mar 2025 11:54:20 +
Subject: [PATCH] [LLVM][SROA] Teach SROA how to "bitcast" between fixed and
 scalable vectors.

For function whose vscale_range is limited to a single value we can
size scalable vectors. This aids SROA by allowing scalable vector
load and store operations to be considered for replacement whereby
bitcasts through memory can be replaced by vector insert or extract
operations.
---
 .../attr-riscv-rvv-vector-bits-less-8-call.c  |  38 ++-
 .../attr-riscv-rvv-vector-bits-less-8-cast.c  |   8 +-
 .../CodeGen/RISCV/attr-rvv-vector-bits-cast.c |  16 +-
 .../CodeGen/attr-arm-sve-vector-bits-cast.c   |  23 +-
 llvm/include/llvm/IR/Attributes.h |   4 +
 llvm/include/llvm/IR/DerivedTypes.h   |  16 ++
 llvm/lib/IR/AttributeImpl.h   |   1 +
 llvm/lib/IR/Attributes.cpp|   8 +
 llvm/lib/Transforms/Scalar/SROA.cpp   | 126 ++---
 .../scalable-vectors-with-known-vscale.ll | 248 ++
 llvm/test/Transforms/SROA/scalable-vectors.ll | 142 ++
 11 files changed, 561 insertions(+), 69 deletions(-)
 create mode 100644 
llvm/test/Transforms/SROA/scalable-vectors-with-known-vscale.ll

diff --git a/clang/test/CodeGen/RISCV/attr-riscv-rvv-vector-bits-less-8-call.c 
b/clang/test/CodeGen/RISCV/attr-riscv-rvv-vector-bits-less-8-call.c
index e2f02dc64f766..66fd466eccfef 100644
--- a/clang/test/CodeGen/RISCV/attr-riscv-rvv-vector-bits-less-8-call.c
+++ b/clang/test/CodeGen/RISCV/attr-riscv-rvv-vector-bits-less-8-call.c
@@ -26,11 +26,15 @@ typedef vbool64_t fixed_bool64_t 
__attribute__((riscv_rvv_vector_bits(__riscv_v_
 //
 // CHECK-128-LABEL: @call_bool32_ff(
 // CHECK-128-NEXT:  entry:
+// CHECK-128-NEXT:[[SAVED_VALUE:%.*]] = alloca <1 x i8>, align 1
+// CHECK-128-NEXT:[[SAVED_VALUE3:%.*]] = alloca <1 x i8>, align 1
 // CHECK-128-NEXT:[[SAVED_VALUE4:%.*]] = alloca , align 1
 // CHECK-128-NEXT:[[RETVAL_COERCE:%.*]] = alloca , align 1
-// CHECK-128-NEXT:[[TMP0:%.*]] = tail call  
@llvm.riscv.vmand.nxv2i1.i64( [[OP1_COERCE:%.*]],  [[OP2_COERCE:%.*]], i64 4)
-// CHECK-128-NEXT:store  [[TMP0]], ptr [[SAVED_VALUE4]], 
align 1, !tbaa [[TBAA6:![0-9]+]]
-// CHECK-128-NEXT:[[TMP1:%.*]] = load <1 x i8>, ptr [[SAVED_VALUE4]], 
align 1, !tbaa [[TBAA10:![0-9]+]]
+// CHECK-128-NEXT:
[[SAVED_VALUE_0_SAVED_VALUE_0_SAVED_VALUE_0_SAVED_VALUE_0_:%.*]] = load , ptr [[SAVED_VALUE]], align 1, !tbaa [[TBAA6:![0-9]+]]
+// CHECK-128-NEXT:
[[SAVED_VALUE3_0_SAVED_VALUE3_0_SAVED_VALUE3_0_SAVED_VALUE3_0_:%.*]] = load 
, ptr [[SAVED_VALUE3]], align 1, !tbaa [[TBAA6]]
+// CHECK-128-NEXT:[[TMP0:%.*]] = tail call  
@llvm.riscv.vmand.nxv2i1.i64( 
[[SAVED_VALUE_0_SAVED_VALUE_0_SAVED_VALUE_0_SAVED_VALUE_0_]],  
[[SAVED_VALUE3_0_SAVED_VALUE3_0_SAVED_VALUE3_0_SAVED_VALUE3_0_]], i64 4)
+// CHECK-128-NEXT:store  [[TMP0]], ptr [[SAVED_VALUE4]], 
align 1, !tbaa [[TBAA9:![0-9]+]]
+// CHECK-128-NEXT:[[TMP1:%.*]] = load <1 x i8>, ptr [[SAVED_VALUE4]], 
align 1, !tbaa [[TBAA6]]
 // CHECK-128-NEXT:store <1 x i8> [[TMP1]], ptr [[RETVAL_COERCE]], align 1
 // CHECK-128-NEXT:[[TMP2:%.*]] = load , ptr 
[[RETVAL_COERCE]], align 1
 // CHECK-128-NEXT:ret  [[TMP2]]
@@ -52,11 +56,15 @@ fixed_bool32_t call_bool32_ff(fixed_bool32_t op1, 
fixed_bool32_t op2) {
 //
 // CHECK-128-LABEL: @call_bool64_ff(
 // CHECK-128-NEXT:  entry:
+// CHECK-128-NEXT:[[SAVED_VALUE:%.*]] = alloca <1 x i8>, align 1
+// CHECK-128-NEXT:[[SAVED_VALUE3:%.*]] = alloca <1 x i8>, align 1
 // CHECK-128-NEXT:[[SAVED_VALUE4:%.*]] = alloca , align 1
 // CHECK-128-NEXT:[[RETVAL_COERCE:%.*]] = alloca , align 1
-// CHECK-128-NEXT:[[TMP0:%.*]] = tail call  
@llvm.riscv.vmand.nxv1i1.i64( [[OP1_COERCE:%.*]],  [[OP2_COERCE:%.*]], i64 2)
+// CHECK-128-NEXT:
[[SAVED_VALUE_0_SAVED_VALUE_0_SAVED_VALUE_0_SAVED_VALUE_0_:%.*]] = load , ptr [[SAVED_VALUE]], align 1, !tbaa [[TBAA6]]
+// CHECK-128-NEXT:
[[SAVED_VALUE3_0_SAVED_VALUE3_0_SAVED_VALUE3_0_SAVED_VALUE3_0_:%.*]] = load 
, ptr [[SAVED_VALUE3]], align 1, !tbaa [[TBAA6]]
+// CHECK-128-NEXT:[[TMP0:%.*]] = tail call  
@llvm.riscv.vmand.nxv1i1.i64( 
[[SAVED_VALUE_0_SAVED_VALUE_0_SAVED_VALUE_0_SAVED_VALUE_0_]],  
[[SAVED_VALUE3_0_SAVED_VALUE3_0_SAVED_VALUE3_0_SAVED_VALUE3_0_]], i64 2)
 // CHECK-128-NEXT:store  [[TMP0]], ptr [[SAVED_VALUE4]], 
align 1, !tbaa [[TBAA11:![0-9]+]]
-// CHECK-128-NEXT:[[TMP1:%.*]] = load <1 x i8>, ptr [[SAVED_VALUE4]], 
align 1, !tbaa [[TBAA10]]
+// CHECK-128-NEXT:[[TMP1:%.*]] = 

[clang-tools-extra] [clang-tidy] support pointee mutation check in misc-const-correctness (PR #130494)

2025-03-12 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/130494

>From 353f538f425ead9ee10ca6c046a6517b9e157db4 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sun, 9 Mar 2025 15:43:37 +
Subject: [PATCH 1/8] [clang-tidy] support pointee mutation check in
 misc-const-correctness

---
 .../clang-tidy/misc/ConstCorrectnessCheck.cpp | 156 --
 .../clang-tidy/misc/ConstCorrectnessCheck.h   |   3 +
 clang-tools-extra/docs/ReleaseNotes.rst   |   3 +-
 .../checks/misc/const-correctness.rst |  44 +
 .../const-correctness-pointer-as-pointers.cpp |  50 ++
 .../const-correctness-transform-values.cpp|   1 +
 .../const-correctness-values-before-cxx23.cpp |   1 +
 .../misc/const-correctness-values.cpp |   1 +
 .../misc/const-correctness-wrong-config.cpp   |   7 +-
 9 files changed, 207 insertions(+), 59 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-pointers.cpp

diff --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
index dbe59233df699..023c834d5700f 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
@@ -13,6 +13,8 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "llvm/Support/Casting.h"
+#include 
 
 using namespace clang::ast_matchers;
 
@@ -39,34 +41,47 @@ ConstCorrectnessCheck::ConstCorrectnessCheck(StringRef Name,
 : ClangTidyCheck(Name, Context),
   AnalyzeValues(Options.get("AnalyzeValues", true)),
   AnalyzeReferences(Options.get("AnalyzeReferences", true)),
+  AnalyzePointers(Options.get("AnalyzePointers", true)),
   WarnPointersAsValues(Options.get("WarnPointersAsValues", false)),
+  WarnPointersAsPointers(Options.get("WarnPointersAsPointers", true)),
   TransformValues(Options.get("TransformValues", true)),
   TransformReferences(Options.get("TransformReferences", true)),
   TransformPointersAsValues(
   Options.get("TransformPointersAsValues", false)),
+  TransformPointersAsPointers(
+  Options.get("TransformPointersAsPointers", true)),
   AllowedTypes(
   utils::options::parseStringList(Options.get("AllowedTypes", ""))) {
-  if (AnalyzeValues == false && AnalyzeReferences == false)
+  if (AnalyzeValues == false && AnalyzeReferences == false &&
+  AnalyzePointers == false)
 this->configurationDiag(
 "The check 'misc-const-correctness' will not "
-"perform any analysis because both 'AnalyzeValues' and "
-"'AnalyzeReferences' are false.");
+"perform any analysis because both 'AnalyzeValues', "
+"'AnalyzeReferences' and 'AnalyzePointers' are false.");
 }
 
 void ConstCorrectnessCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "AnalyzeValues", AnalyzeValues);
   Options.store(Opts, "AnalyzeReferences", AnalyzeReferences);
+  Options.store(Opts, "AnalyzePointers", AnalyzePointers);
   Options.store(Opts, "WarnPointersAsValues", WarnPointersAsValues);
+  Options.store(Opts, "WarnPointersAsPointers", WarnPointersAsPointers);
 
   Options.store(Opts, "TransformValues", TransformValues);
   Options.store(Opts, "TransformReferences", TransformReferences);
   Options.store(Opts, "TransformPointersAsValues", TransformPointersAsValues);
+  Options.store(Opts, "TransformPointersAsPointers",
+TransformPointersAsPointers);
   Options.store(Opts, "AllowedTypes",
 utils::options::serializeStringList(AllowedTypes));
 }
 
 void ConstCorrectnessCheck::registerMatchers(MatchFinder *Finder) {
-  const auto ConstType = hasType(isConstQualified());
+  const auto ConstType = hasType(
+  qualType(isConstQualified(),
+   // pointee check will check the const pointer and const array
+   unless(pointerType()), unless(arrayType(;
+
   const auto ConstReference = hasType(references(isConstQualified()));
   const auto RValueReference = hasType(
   referenceType(anyOf(rValueReferenceType(), 
unless(isSpelledAsLValue();
@@ -124,6 +139,11 @@ void ConstCorrectnessCheck::check(const 
MatchFinder::MatchResult &Result) {
   const auto *LocalScope = Result.Nodes.getNodeAs("scope");
   const auto *Variable = Result.Nodes.getNodeAs("local-value");
   const auto *Function = Result.Nodes.getNodeAs("function-decl");
+  const auto *VarDeclStmt = Result.Nodes.getNodeAs("decl-stmt");
+  // It can not be guaranteed that the variable is declared isolated,
+  // therefore a transformation might effect the other variables as well and
+  // be incorrect.
+  const bool CanBeFixIt = VarDeclStmt != nullptr && 
VarDeclStmt->isSingleDecl();
 
   /// If the variable was declared in a template it might be analyzed multiple
   /// times. Only one of those ins

[clang] [CIR] Upstream CastOp and scalar conversions (PR #130690)

2025-03-12 Thread Erich Keane via cfe-commits


@@ -84,26 +96,266 @@ class ScalarExprEmitter : public 
StmtVisitor {
   }
 
   mlir::Value VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *e) {
-mlir::Type type = cgf.convertType(e->getType());
+mlir::Type type = convertType(e->getType());
 return builder.create(
 cgf.getLoc(e->getExprLoc()), type,
 builder.getCIRBoolAttr(e->getValue()));
   }
 
-  mlir::Value VisitCastExpr(CastExpr *E);
+  mlir::Value VisitCastExpr(CastExpr *e);
+
+  mlir::Value VisitExplicitCastExpr(ExplicitCastExpr *e) {
+return VisitCastExpr(e);
+  }
+
+  /// Perform a pointer to boolean conversion.
+  mlir::Value emitPointerToBoolConversion(mlir::Value v, QualType qt) {
+// TODO(cir): comparing the ptr to null is done when lowering CIR to LLVM.
+// We might want to have a separate pass for these types of conversions.
+return cgf.getBuilder().createPtrToBoolCast(v);
+  }
+
+  mlir::Value emitFloatToBoolConversion(mlir::Value src, mlir::Location loc) {
+auto boolTy = builder.getBoolTy();
+return builder.create(loc, boolTy,
+   cir::CastKind::float_to_bool, src);
+  }
+
+  mlir::Value emitIntToBoolConversion(mlir::Value srcVal, mlir::Location loc) {
+// Because of the type rules of C, we often end up computing a
+// logical value, then zero extending it to int, then wanting it
+// as a logical value again.
+// TODO: optimize this common case here or leave it for later
+// CIR passes?
+mlir::Type boolTy = convertType(cgf.getContext().BoolTy);
+return builder.create(loc, boolTy, cir::CastKind::int_to_bool,
+   srcVal);
+  }
+
+  /// Convert the specified expression value to a boolean (!cir.bool) truth
+  /// value. This is equivalent to "Val != 0".
+  mlir::Value emitConversionToBool(mlir::Value src, QualType srcType,
+   mlir::Location loc) {
+assert(srcType.isCanonical() && "EmitScalarConversion strips typedefs");
+
+if (srcType->isRealFloatingType())
+  return emitFloatToBoolConversion(src, loc);
+
+if ([[maybe_unused]] auto *mpt = 
llvm::dyn_cast(srcType))
+  cgf.getCIRGenModule().errorNYI(loc, "member pointer to bool conversion");
+
+if (srcType->isIntegerType())
+  return emitIntToBoolConversion(src, loc);
+
+assert(::mlir::isa(src.getType()));
+return emitPointerToBoolConversion(src, srcType);
+  }
+
+  // Emit a conversion from the specified type to the specified destination
+  // type, both of which are CIR scalar types.
+  struct ScalarConversionOpts {
+bool treatBooleanAsSigned;
+bool emitImplicitIntegerTruncationChecks;
+bool emitImplicitIntegerSignChangeChecks;
+
+ScalarConversionOpts()
+: treatBooleanAsSigned(false),
+  emitImplicitIntegerTruncationChecks(false),
+  emitImplicitIntegerSignChangeChecks(false) {}
+
+ScalarConversionOpts(clang::SanitizerSet sanOpts)
+: treatBooleanAsSigned(false),
+  emitImplicitIntegerTruncationChecks(
+  sanOpts.hasOneOf(SanitizerKind::ImplicitIntegerTruncation)),
+  emitImplicitIntegerSignChangeChecks(
+  sanOpts.has(SanitizerKind::ImplicitIntegerSignChange)) {}
+  };
+
+  // Conversion from bool, integral, or floating-point to integral or
+  // floating-point. Conversions involving other types are handled elsewhere.
+  // Conversion to bool is handled elsewhere because that's a comparison 
against
+  // zero, not a simple cast. This handles both individual scalars and vectors.
+  mlir::Value emitScalarCast(mlir::Value src, QualType srcType,
+ QualType dstType, mlir::Type srcTy,
+ mlir::Type dstTy, ScalarConversionOpts opts) {
+assert(!srcType->isMatrixType() && !dstType->isMatrixType() &&
+   "Internal error: matrix types not handled by this function.");
+if (mlir::isa(srcTy) ||
+mlir::isa(dstTy))
+  llvm_unreachable("Obsolete code. Don't use mlir::IntegerType with CIR.");
+
+mlir::Type fullDstTy = dstTy;
+assert(!cir::MissingFeatures::vectorType());
+
+std::optional castKind;
+
+if (mlir::isa(srcTy)) {
+  if (opts.treatBooleanAsSigned)
+cgf.getCIRGenModule().errorNYI("signed bool");
+  if (cgf.getBuilder().isInt(dstTy)) {
+castKind = cir::CastKind::bool_to_int;
+  } else if (mlir::isa(dstTy)) {
+castKind = cir::CastKind::bool_to_float;
+  } else {
+llvm_unreachable("Internal error: Cast to unexpected type");
+  }
+} else if (cgf.getBuilder().isInt(srcTy)) {
+  if (cgf.getBuilder().isInt(dstTy)) {
+castKind = cir::CastKind::integral;
+  } else if (mlir::isa(dstTy)) {
+castKind = cir::CastKind::int_to_float;
+  } else {
+llvm_unreachable("Internal error: Cast to unexpected type");
+  }
+} else if (mlir::isa(srcTy)) {
+  if (cgf.getBuilder().isInt(dstTy)) {
+/

[clang] [llvm] [RISCV] Add Qualcomn uC Xqcili (load large immediates) extension (PR #130012)

2025-03-12 Thread Sudharsan Veeravalli via cfe-commits

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

LGTM!

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


[clang] [llvm] [MIPS] Add MIPS i6400 and i6500 processors (PR #130587)

2025-03-12 Thread Mallikarjuna Gouda via cfe-commits


@@ -238,13 +238,10 @@ def ImplP5600 : SubtargetFeature<"p5600", "ProcImpl",
  "MipsSubtarget::CPU::P5600",
  "The P5600 Processor", [FeatureMips32r5]>;
 
+// I6500 is multicluster version of I6400. Both are based on same CPU.

mgoudar wrote:

updated the comments

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


[clang] [CIR] Upstream CastOp and scalar conversions (PR #130690)

2025-03-12 Thread Erich Keane via cfe-commits


@@ -121,29 +359,159 @@ mlir::Value CIRGenFunction::emitScalarExpr(const Expr 
*e) {
   return ScalarExprEmitter(*this, builder).Visit(const_cast(e));
 }
 
+[[maybe_unused]] static bool MustVisitNullValue(const Expr *e) {
+  // If a null pointer expression's type is the C++0x nullptr_t, then
+  // it's not necessarily a simple constant and it must be evaluated
+  // for its potential side effects.
+  return e->getType()->isNullPtrType();
+}
+
 // Emit code for an explicit or implicit cast.  Implicit
 // casts have to handle a more broad range of conversions than explicit
 // casts, as they handle things like function to ptr-to-function decay
 // etc.
 mlir::Value ScalarExprEmitter::VisitCastExpr(CastExpr *ce) {
-  Expr *e = ce->getSubExpr();
+  Expr *subExpr = ce->getSubExpr();
   QualType destTy = ce->getType();
   CastKind kind = ce->getCastKind();
 
+  // These cases are generally not written to ignore the result of evaluating
+  // their sub-expressions, so we clear this now.
+  ignoreResultAssign = false;
+
   switch (kind) {
+  case clang::CK_Dependent:
+llvm_unreachable("dependent cast kind in CIR gen!");
+  case clang::CK_BuiltinFnToFnPtr:
+llvm_unreachable("builtin functions are handled elsewhere");
+
+  case CK_CPointerToObjCPointerCast:
+  case CK_BlockPointerToObjCPointerCast:
+  case CK_AnyPointerToBlockPointerCast:
+  case CK_BitCast: {
+mlir::Value src = Visit(const_cast(subExpr));
+mlir::Type dstTy = cgf.convertType(destTy);
+
+assert(!cir::MissingFeatures::addressSpace());
+
+if (cgf.sanOpts.has(SanitizerKind::CFIUnrelatedCast))
+  cgf.getCIRGenModule().errorNYI(subExpr->getSourceRange(),
+ "sanitizer support");
+
+if (cgf.cgm.getCodeGenOpts().StrictVTablePointers)
+  cgf.getCIRGenModule().errorNYI(subExpr->getSourceRange(),
+ "strict vtable pointers");
+
+// Update heapallocsite metadata when there is an explicit pointer cast.
+assert(!cir::MissingFeatures::addHeapAllocSiteMetadata());
+
+// If Src is a fixed vector and Dst is a scalable vector, and both have the
+// same element type, use the llvm.vector.insert intrinsic to perform the
+// bitcast.
+assert(!cir::MissingFeatures::scalableVectors());
+
+// If Src is a scalable vector and Dst is a fixed vector, and both have the
+// same element type, use the llvm.vector.extract intrinsic to perform the
+// bitcast.
+assert(!cir::MissingFeatures::scalableVectors());
+
+// Perform VLAT <-> VLST bitcast through memory.
+// TODO: since the llvm.experimental.vector.{insert,extract} intrinsics
+//   require the element types of the vectors to be the same, we
+//   need to keep this around for bitcasts between VLAT <-> VLST where
+//   the element types of the vectors are not the same, until we figure
+//   out a better way of doing these casts.
+assert(!cir::MissingFeatures::scalableVectors());
+
+return 
cgf.getBuilder().createBitcast(cgf.getLoc(subExpr->getSourceRange()),
+  src, dstTy);
+  }
+
+  case CK_AtomicToNonAtomic:
+cgf.getCIRGenModule().errorNYI(subExpr->getSourceRange(),
+   "CastExpr: ", ce->getCastKindName());
+break;
+  case CK_NonAtomicToAtomic:
+  case CK_UserDefinedConversion:
+return Visit(const_cast(subExpr));
+  case CK_NoOp: {
+auto v = Visit(const_cast(subExpr));
+if (v) {
+  // CK_NoOp can model a pointer qualification conversion, which can remove
+  // an array bound and change the IR type.
+  // FIXME: Once pointee types are removed from IR, remove this.
+  mlir::Type t = cgf.convertType(destTy);
+  if (t != v.getType())
+cgf.getCIRGenModule().errorNYI("pointer qualification conversion");
+}
+return v;
+  }
+
+  case CK_NullToPointer: {
+if (MustVisitNullValue(subExpr))
+  cgf.getCIRGenModule().errorNYI(
+  subExpr->getSourceRange(),
+  "ignored expression on null to pointer cast");
+
+// Note that DestTy is used as the MLIR type instead of a custom
+// nullptr type.
+mlir::Type ty = cgf.convertType(destTy);
+return builder.getNullPtr(ty, cgf.getLoc(subExpr->getExprLoc()));
+  }
+
   case CK_LValueToRValue:
-assert(cgf.getContext().hasSameUnqualifiedType(e->getType(), destTy));
-assert(e->isGLValue() && "lvalue-to-rvalue applied to r-value!");
-return Visit(const_cast(e));
+assert(cgf.getContext().hasSameUnqualifiedType(subExpr->getType(), 
destTy));
+assert(subExpr->isGLValue() && "lvalue-to-rvalue applied to r-value!");
+return Visit(const_cast(subExpr));
 
   case CK_IntegralCast: {
-assert(!cir::MissingFeatures::scalarConversionOpts());
-return emitScalarConversion(Visit(e), e->getType(), destTy,
-ce->getExprLoc());
+ScalarConversionOpts opts;
+if (auto *ice = dyn_cast(c

[clang] [CIR] Upstream CastOp and scalar conversions (PR #130690)

2025-03-12 Thread Erich Keane via cfe-commits


@@ -90,20 +89,259 @@ class ScalarExprEmitter : public 
StmtVisitor {
 builder.getCIRBoolAttr(e->getValue()));
   }
 
-  mlir::Value VisitCastExpr(CastExpr *E);
+  mlir::Value VisitCastExpr(CastExpr *e);
+
+  mlir::Value VisitExplicitCastExpr(ExplicitCastExpr *e) {
+return VisitCastExpr(e);
+  }
+
+  /// Perform a pointer to boolean conversion.
+  mlir::Value emitPointerToBoolConversion(mlir::Value v, QualType qt) {
+// TODO(cir): comparing the ptr to null is done when lowering CIR to LLVM.
+// We might want to have a separate pass for these types of conversions.
+return cgf.getBuilder().createPtrToBoolCast(v);
+  }
+
+  mlir::Value emitFloatToBoolConversion(mlir::Value src, mlir::Location loc) {
+auto boolTy = builder.getBoolTy();
+return builder.create(loc, boolTy,
+   cir::CastKind::float_to_bool, src);
+  }
+
+  mlir::Value emitIntToBoolConversion(mlir::Value srcVal, mlir::Location loc) {
+// Because of the type rules of C, we often end up computing a
+// logical value, then zero extending it to int, then wanting it
+// as a logical value again.
+// TODO: optimize this common case here or leave it for later
+// CIR passes?
+mlir::Type boolTy = cgf.convertType(cgf.getContext().BoolTy);
+return builder.create(loc, boolTy, cir::CastKind::int_to_bool,
+   srcVal);
+  }
+
+  /// Convert the specified expression value to a boolean (!cir.bool) truth
+  /// value. This is equivalent to "Val != 0".
+  mlir::Value emitConversionToBool(mlir::Value src, QualType srcType,
+   mlir::Location loc) {
+assert(srcType.isCanonical() && "EmitScalarConversion strips typedefs");
+
+if (srcType->isRealFloatingType())
+  return emitFloatToBoolConversion(src, loc);
+
+if (llvm::isa(srcType))
+  cgf.getCIRGenModule().errorNYI(loc, "member pointer to bool conversion");
+
+if (srcType->isIntegerType())
+  return emitIntToBoolConversion(src, loc);
+
+assert(::mlir::isa(src.getType()));
+return emitPointerToBoolConversion(src, srcType);
+  }
+
+  // Emit a conversion from the specified type to the specified destination
+  // type, both of which are CIR scalar types.
+  struct ScalarConversionOpts {
+bool treatBooleanAsSigned;
+bool emitImplicitIntegerTruncationChecks;
+bool emitImplicitIntegerSignChangeChecks;
+
+ScalarConversionOpts()
+: treatBooleanAsSigned(false),
+  emitImplicitIntegerTruncationChecks(false),
+  emitImplicitIntegerSignChangeChecks(false) {}
+
+ScalarConversionOpts(clang::SanitizerSet sanOpts)
+: treatBooleanAsSigned(false),
+  emitImplicitIntegerTruncationChecks(
+  sanOpts.hasOneOf(SanitizerKind::ImplicitIntegerTruncation)),
+  emitImplicitIntegerSignChangeChecks(
+  sanOpts.has(SanitizerKind::ImplicitIntegerSignChange)) {}
+  };
+
+  // Conversion from bool, integral, or floating-point to integral or
+  // floating-point. Conversions involving other types are handled elsewhere.
+  // Conversion to bool is handled elsewhere because that's a comparison 
against
+  // zero, not a simple cast. This handles both individual scalars and vectors.
+  mlir::Value emitScalarCast(mlir::Value src, QualType srcType,
+ QualType dstType, mlir::Type srcTy,
+ mlir::Type dstTy, ScalarConversionOpts opts) {
+assert(!srcType->isMatrixType() && !dstType->isMatrixType() &&
+   "Internal error: matrix types not handled by this function.");
+if (mlir::isa(srcTy) ||
+mlir::isa(dstTy))
+  llvm_unreachable("Obsolete code. Don't use mlir::IntegerType with CIR.");
+
+mlir::Type fullDstTy = dstTy;
+assert(!cir::MissingFeatures::vectorType());
+
+std::optional castKind;
+
+if (mlir::isa(srcTy)) {
+  if (opts.treatBooleanAsSigned)
+cgf.getCIRGenModule().errorNYI("signed bool");
+  if (cgf.getBuilder().isInt(dstTy))
+castKind = cir::CastKind::bool_to_int;
+  else if (mlir::isa(dstTy))
+castKind = cir::CastKind::bool_to_float;
+  else
+llvm_unreachable("Internal error: Cast to unexpected type");
+} else if (cgf.getBuilder().isInt(srcTy)) {
+  if (cgf.getBuilder().isInt(dstTy))
+castKind = cir::CastKind::integral;
+  else if (mlir::isa(dstTy))
+castKind = cir::CastKind::int_to_float;
+  else
+llvm_unreachable("Internal error: Cast to unexpected type");
+} else if (mlir::isa(srcTy)) {
+  if (cgf.getBuilder().isInt(dstTy)) {
+// If we can't recognize overflow as undefined behavior, assume that
+// overflow saturates. This protects against normal optimizations if we
+// are compiling with non-standard FP semantics.
+if (!cgf.cgm.getCodeGenOpts().StrictFloatCastOverflow)
+  cgf.getCIRGenModule().errorNYI("strict f

[clang] [CIR] Upstream CastOp and scalar conversions (PR #130690)

2025-03-12 Thread Erich Keane via cfe-commits


@@ -121,29 +359,159 @@ mlir::Value CIRGenFunction::emitScalarExpr(const Expr 
*e) {
   return ScalarExprEmitter(*this, builder).Visit(const_cast(e));
 }
 
+[[maybe_unused]] static bool MustVisitNullValue(const Expr *e) {
+  // If a null pointer expression's type is the C++0x nullptr_t, then
+  // it's not necessarily a simple constant and it must be evaluated
+  // for its potential side effects.
+  return e->getType()->isNullPtrType();
+}
+
 // Emit code for an explicit or implicit cast.  Implicit
 // casts have to handle a more broad range of conversions than explicit
 // casts, as they handle things like function to ptr-to-function decay
 // etc.
 mlir::Value ScalarExprEmitter::VisitCastExpr(CastExpr *ce) {
-  Expr *e = ce->getSubExpr();
+  Expr *subExpr = ce->getSubExpr();
   QualType destTy = ce->getType();
   CastKind kind = ce->getCastKind();
 
+  // These cases are generally not written to ignore the result of evaluating
+  // their sub-expressions, so we clear this now.
+  ignoreResultAssign = false;
+
   switch (kind) {
+  case clang::CK_Dependent:
+llvm_unreachable("dependent cast kind in CIR gen!");
+  case clang::CK_BuiltinFnToFnPtr:
+llvm_unreachable("builtin functions are handled elsewhere");
+
+  case CK_CPointerToObjCPointerCast:
+  case CK_BlockPointerToObjCPointerCast:
+  case CK_AnyPointerToBlockPointerCast:
+  case CK_BitCast: {
+mlir::Value src = Visit(const_cast(subExpr));
+mlir::Type dstTy = cgf.convertType(destTy);
+
+assert(!cir::MissingFeatures::addressSpace());
+
+if (cgf.sanOpts.has(SanitizerKind::CFIUnrelatedCast))
+  cgf.getCIRGenModule().errorNYI(subExpr->getSourceRange(),
+ "sanitizer support");
+
+if (cgf.cgm.getCodeGenOpts().StrictVTablePointers)
+  cgf.getCIRGenModule().errorNYI(subExpr->getSourceRange(),
+ "strict vtable pointers");
+
+// Update heapallocsite metadata when there is an explicit pointer cast.
+assert(!cir::MissingFeatures::addHeapAllocSiteMetadata());
+
+// If Src is a fixed vector and Dst is a scalable vector, and both have the
+// same element type, use the llvm.vector.insert intrinsic to perform the
+// bitcast.
+assert(!cir::MissingFeatures::scalableVectors());
+
+// If Src is a scalable vector and Dst is a fixed vector, and both have the
+// same element type, use the llvm.vector.extract intrinsic to perform the
+// bitcast.
+assert(!cir::MissingFeatures::scalableVectors());
+
+// Perform VLAT <-> VLST bitcast through memory.
+// TODO: since the llvm.experimental.vector.{insert,extract} intrinsics
+//   require the element types of the vectors to be the same, we
+//   need to keep this around for bitcasts between VLAT <-> VLST where
+//   the element types of the vectors are not the same, until we figure
+//   out a better way of doing these casts.
+assert(!cir::MissingFeatures::scalableVectors());
+
+return 
cgf.getBuilder().createBitcast(cgf.getLoc(subExpr->getSourceRange()),
+  src, dstTy);
+  }
+
+  case CK_AtomicToNonAtomic:
+cgf.getCIRGenModule().errorNYI(subExpr->getSourceRange(),
+   "CastExpr: ", ce->getCastKindName());
+break;

erichkeane wrote:

what does this fall through to? Does it result in a sensible value?

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


[clang] [CIR] Upstream CastOp and scalar conversions (PR #130690)

2025-03-12 Thread Erich Keane via cfe-commits


@@ -84,26 +96,266 @@ class ScalarExprEmitter : public 
StmtVisitor {
   }
 
   mlir::Value VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *e) {
-mlir::Type type = cgf.convertType(e->getType());
+mlir::Type type = convertType(e->getType());
 return builder.create(
 cgf.getLoc(e->getExprLoc()), type,
 builder.getCIRBoolAttr(e->getValue()));
   }
 
-  mlir::Value VisitCastExpr(CastExpr *E);
+  mlir::Value VisitCastExpr(CastExpr *e);
+
+  mlir::Value VisitExplicitCastExpr(ExplicitCastExpr *e) {
+return VisitCastExpr(e);
+  }
+
+  /// Perform a pointer to boolean conversion.
+  mlir::Value emitPointerToBoolConversion(mlir::Value v, QualType qt) {
+// TODO(cir): comparing the ptr to null is done when lowering CIR to LLVM.
+// We might want to have a separate pass for these types of conversions.
+return cgf.getBuilder().createPtrToBoolCast(v);
+  }
+
+  mlir::Value emitFloatToBoolConversion(mlir::Value src, mlir::Location loc) {
+auto boolTy = builder.getBoolTy();
+return builder.create(loc, boolTy,
+   cir::CastKind::float_to_bool, src);
+  }
+
+  mlir::Value emitIntToBoolConversion(mlir::Value srcVal, mlir::Location loc) {
+// Because of the type rules of C, we often end up computing a
+// logical value, then zero extending it to int, then wanting it
+// as a logical value again.
+// TODO: optimize this common case here or leave it for later
+// CIR passes?
+mlir::Type boolTy = convertType(cgf.getContext().BoolTy);
+return builder.create(loc, boolTy, cir::CastKind::int_to_bool,
+   srcVal);
+  }
+
+  /// Convert the specified expression value to a boolean (!cir.bool) truth
+  /// value. This is equivalent to "Val != 0".
+  mlir::Value emitConversionToBool(mlir::Value src, QualType srcType,
+   mlir::Location loc) {
+assert(srcType.isCanonical() && "EmitScalarConversion strips typedefs");
+
+if (srcType->isRealFloatingType())
+  return emitFloatToBoolConversion(src, loc);
+
+if ([[maybe_unused]] auto *mpt = 
llvm::dyn_cast(srcType))
+  cgf.getCIRGenModule().errorNYI(loc, "member pointer to bool conversion");
+
+if (srcType->isIntegerType())
+  return emitIntToBoolConversion(src, loc);
+
+assert(::mlir::isa(src.getType()));
+return emitPointerToBoolConversion(src, srcType);
+  }
+
+  // Emit a conversion from the specified type to the specified destination
+  // type, both of which are CIR scalar types.
+  struct ScalarConversionOpts {
+bool treatBooleanAsSigned;
+bool emitImplicitIntegerTruncationChecks;
+bool emitImplicitIntegerSignChangeChecks;
+
+ScalarConversionOpts()
+: treatBooleanAsSigned(false),
+  emitImplicitIntegerTruncationChecks(false),
+  emitImplicitIntegerSignChangeChecks(false) {}
+
+ScalarConversionOpts(clang::SanitizerSet sanOpts)
+: treatBooleanAsSigned(false),
+  emitImplicitIntegerTruncationChecks(
+  sanOpts.hasOneOf(SanitizerKind::ImplicitIntegerTruncation)),
+  emitImplicitIntegerSignChangeChecks(
+  sanOpts.has(SanitizerKind::ImplicitIntegerSignChange)) {}
+  };
+
+  // Conversion from bool, integral, or floating-point to integral or
+  // floating-point. Conversions involving other types are handled elsewhere.
+  // Conversion to bool is handled elsewhere because that's a comparison 
against
+  // zero, not a simple cast. This handles both individual scalars and vectors.
+  mlir::Value emitScalarCast(mlir::Value src, QualType srcType,
+ QualType dstType, mlir::Type srcTy,
+ mlir::Type dstTy, ScalarConversionOpts opts) {
+assert(!srcType->isMatrixType() && !dstType->isMatrixType() &&
+   "Internal error: matrix types not handled by this function.");
+if (mlir::isa(srcTy) ||
+mlir::isa(dstTy))
+  llvm_unreachable("Obsolete code. Don't use mlir::IntegerType with CIR.");
+
+mlir::Type fullDstTy = dstTy;
+assert(!cir::MissingFeatures::vectorType());
+
+std::optional castKind;
+
+if (mlir::isa(srcTy)) {
+  if (opts.treatBooleanAsSigned)
+cgf.getCIRGenModule().errorNYI("signed bool");
+  if (cgf.getBuilder().isInt(dstTy)) {
+castKind = cir::CastKind::bool_to_int;
+  } else if (mlir::isa(dstTy)) {
+castKind = cir::CastKind::bool_to_float;
+  } else {
+llvm_unreachable("Internal error: Cast to unexpected type");
+  }
+} else if (cgf.getBuilder().isInt(srcTy)) {
+  if (cgf.getBuilder().isInt(dstTy)) {
+castKind = cir::CastKind::integral;
+  } else if (mlir::isa(dstTy)) {
+castKind = cir::CastKind::int_to_float;
+  } else {
+llvm_unreachable("Internal error: Cast to unexpected type");
+  }
+} else if (mlir::isa(srcTy)) {
+  if (cgf.getBuilder().isInt(dstTy)) {
+/

[clang] [CIR] Upstream CastOp and scalar conversions (PR #130690)

2025-03-12 Thread Erich Keane via cfe-commits


@@ -90,20 +89,259 @@ class ScalarExprEmitter : public 
StmtVisitor {
 builder.getCIRBoolAttr(e->getValue()));
   }
 
-  mlir::Value VisitCastExpr(CastExpr *E);
+  mlir::Value VisitCastExpr(CastExpr *e);
+
+  mlir::Value VisitExplicitCastExpr(ExplicitCastExpr *e) {
+return VisitCastExpr(e);
+  }
+
+  /// Perform a pointer to boolean conversion.
+  mlir::Value emitPointerToBoolConversion(mlir::Value v, QualType qt) {
+// TODO(cir): comparing the ptr to null is done when lowering CIR to LLVM.
+// We might want to have a separate pass for these types of conversions.
+return cgf.getBuilder().createPtrToBoolCast(v);
+  }
+
+  mlir::Value emitFloatToBoolConversion(mlir::Value src, mlir::Location loc) {
+auto boolTy = builder.getBoolTy();
+return builder.create(loc, boolTy,
+   cir::CastKind::float_to_bool, src);
+  }
+
+  mlir::Value emitIntToBoolConversion(mlir::Value srcVal, mlir::Location loc) {
+// Because of the type rules of C, we often end up computing a
+// logical value, then zero extending it to int, then wanting it
+// as a logical value again.
+// TODO: optimize this common case here or leave it for later
+// CIR passes?
+mlir::Type boolTy = cgf.convertType(cgf.getContext().BoolTy);
+return builder.create(loc, boolTy, cir::CastKind::int_to_bool,
+   srcVal);
+  }
+
+  /// Convert the specified expression value to a boolean (!cir.bool) truth
+  /// value. This is equivalent to "Val != 0".
+  mlir::Value emitConversionToBool(mlir::Value src, QualType srcType,
+   mlir::Location loc) {
+assert(srcType.isCanonical() && "EmitScalarConversion strips typedefs");
+
+if (srcType->isRealFloatingType())
+  return emitFloatToBoolConversion(src, loc);
+
+if (llvm::isa(srcType))
+  cgf.getCIRGenModule().errorNYI(loc, "member pointer to bool conversion");
+
+if (srcType->isIntegerType())
+  return emitIntToBoolConversion(src, loc);
+
+assert(::mlir::isa(src.getType()));
+return emitPointerToBoolConversion(src, srcType);
+  }
+
+  // Emit a conversion from the specified type to the specified destination
+  // type, both of which are CIR scalar types.
+  struct ScalarConversionOpts {
+bool treatBooleanAsSigned;
+bool emitImplicitIntegerTruncationChecks;
+bool emitImplicitIntegerSignChangeChecks;
+
+ScalarConversionOpts()
+: treatBooleanAsSigned(false),
+  emitImplicitIntegerTruncationChecks(false),
+  emitImplicitIntegerSignChangeChecks(false) {}
+
+ScalarConversionOpts(clang::SanitizerSet sanOpts)
+: treatBooleanAsSigned(false),
+  emitImplicitIntegerTruncationChecks(
+  sanOpts.hasOneOf(SanitizerKind::ImplicitIntegerTruncation)),
+  emitImplicitIntegerSignChangeChecks(
+  sanOpts.has(SanitizerKind::ImplicitIntegerSignChange)) {}
+  };
+
+  // Conversion from bool, integral, or floating-point to integral or
+  // floating-point. Conversions involving other types are handled elsewhere.
+  // Conversion to bool is handled elsewhere because that's a comparison 
against
+  // zero, not a simple cast. This handles both individual scalars and vectors.
+  mlir::Value emitScalarCast(mlir::Value src, QualType srcType,
+ QualType dstType, mlir::Type srcTy,
+ mlir::Type dstTy, ScalarConversionOpts opts) {
+assert(!srcType->isMatrixType() && !dstType->isMatrixType() &&
+   "Internal error: matrix types not handled by this function.");
+if (mlir::isa(srcTy) ||
+mlir::isa(dstTy))
+  llvm_unreachable("Obsolete code. Don't use mlir::IntegerType with CIR.");
+
+mlir::Type fullDstTy = dstTy;
+assert(!cir::MissingFeatures::vectorType());
+
+std::optional castKind;
+
+if (mlir::isa(srcTy)) {
+  if (opts.treatBooleanAsSigned)
+cgf.getCIRGenModule().errorNYI("signed bool");
+  if (cgf.getBuilder().isInt(dstTy))
+castKind = cir::CastKind::bool_to_int;
+  else if (mlir::isa(dstTy))
+castKind = cir::CastKind::bool_to_float;
+  else
+llvm_unreachable("Internal error: Cast to unexpected type");
+} else if (cgf.getBuilder().isInt(srcTy)) {
+  if (cgf.getBuilder().isInt(dstTy))
+castKind = cir::CastKind::integral;
+  else if (mlir::isa(dstTy))
+castKind = cir::CastKind::int_to_float;
+  else
+llvm_unreachable("Internal error: Cast to unexpected type");
+} else if (mlir::isa(srcTy)) {
+  if (cgf.getBuilder().isInt(dstTy)) {
+// If we can't recognize overflow as undefined behavior, assume that
+// overflow saturates. This protects against normal optimizations if we
+// are compiling with non-standard FP semantics.
+if (!cgf.cgm.getCodeGenOpts().StrictFloatCastOverflow)
+  cgf.getCIRGenModule().errorNYI("strict f

[clang] [CIR] Upstream CastOp and scalar conversions (PR #130690)

2025-03-12 Thread Erich Keane via cfe-commits


@@ -78,6 +78,111 @@ class LLVMLoweringInfo {
 class CIR_Op traits = []> :
 Op, LLVMLoweringInfo;
 
+//===--===//
+// CastOp
+//===--===//
+
+// The enumaration value isn't in sync with clang.

erichkeane wrote:

We'd discussed offline about trying to sync the two enums in some way, right?  
Was that not something viable?

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


[clang] [CIR] Upstream CastOp and scalar conversions (PR #130690)

2025-03-12 Thread Erich Keane via cfe-commits


@@ -90,20 +89,259 @@ class ScalarExprEmitter : public 
StmtVisitor {
 builder.getCIRBoolAttr(e->getValue()));
   }
 
-  mlir::Value VisitCastExpr(CastExpr *E);
+  mlir::Value VisitCastExpr(CastExpr *e);
+
+  mlir::Value VisitExplicitCastExpr(ExplicitCastExpr *e) {
+return VisitCastExpr(e);
+  }
+
+  /// Perform a pointer to boolean conversion.
+  mlir::Value emitPointerToBoolConversion(mlir::Value v, QualType qt) {
+// TODO(cir): comparing the ptr to null is done when lowering CIR to LLVM.
+// We might want to have a separate pass for these types of conversions.
+return cgf.getBuilder().createPtrToBoolCast(v);
+  }
+
+  mlir::Value emitFloatToBoolConversion(mlir::Value src, mlir::Location loc) {
+auto boolTy = builder.getBoolTy();
+return builder.create(loc, boolTy,
+   cir::CastKind::float_to_bool, src);
+  }
+
+  mlir::Value emitIntToBoolConversion(mlir::Value srcVal, mlir::Location loc) {
+// Because of the type rules of C, we often end up computing a
+// logical value, then zero extending it to int, then wanting it
+// as a logical value again.
+// TODO: optimize this common case here or leave it for later
+// CIR passes?
+mlir::Type boolTy = cgf.convertType(cgf.getContext().BoolTy);
+return builder.create(loc, boolTy, cir::CastKind::int_to_bool,
+   srcVal);
+  }
+
+  /// Convert the specified expression value to a boolean (!cir.bool) truth
+  /// value. This is equivalent to "Val != 0".
+  mlir::Value emitConversionToBool(mlir::Value src, QualType srcType,
+   mlir::Location loc) {
+assert(srcType.isCanonical() && "EmitScalarConversion strips typedefs");
+
+if (srcType->isRealFloatingType())
+  return emitFloatToBoolConversion(src, loc);
+
+if (llvm::isa(srcType))
+  cgf.getCIRGenModule().errorNYI(loc, "member pointer to bool conversion");
+
+if (srcType->isIntegerType())
+  return emitIntToBoolConversion(src, loc);
+
+assert(::mlir::isa(src.getType()));
+return emitPointerToBoolConversion(src, srcType);
+  }
+
+  // Emit a conversion from the specified type to the specified destination
+  // type, both of which are CIR scalar types.
+  struct ScalarConversionOpts {
+bool treatBooleanAsSigned;
+bool emitImplicitIntegerTruncationChecks;
+bool emitImplicitIntegerSignChangeChecks;
+
+ScalarConversionOpts()
+: treatBooleanAsSigned(false),
+  emitImplicitIntegerTruncationChecks(false),
+  emitImplicitIntegerSignChangeChecks(false) {}
+
+ScalarConversionOpts(clang::SanitizerSet sanOpts)
+: treatBooleanAsSigned(false),
+  emitImplicitIntegerTruncationChecks(
+  sanOpts.hasOneOf(SanitizerKind::ImplicitIntegerTruncation)),
+  emitImplicitIntegerSignChangeChecks(
+  sanOpts.has(SanitizerKind::ImplicitIntegerSignChange)) {}
+  };
+
+  // Conversion from bool, integral, or floating-point to integral or
+  // floating-point. Conversions involving other types are handled elsewhere.
+  // Conversion to bool is handled elsewhere because that's a comparison 
against
+  // zero, not a simple cast. This handles both individual scalars and vectors.
+  mlir::Value emitScalarCast(mlir::Value src, QualType srcType,
+ QualType dstType, mlir::Type srcTy,
+ mlir::Type dstTy, ScalarConversionOpts opts) {
+assert(!srcType->isMatrixType() && !dstType->isMatrixType() &&
+   "Internal error: matrix types not handled by this function.");
+if (mlir::isa(srcTy) ||
+mlir::isa(dstTy))
+  llvm_unreachable("Obsolete code. Don't use mlir::IntegerType with CIR.");
+
+mlir::Type fullDstTy = dstTy;
+assert(!cir::MissingFeatures::vectorType());
+
+std::optional castKind;
+
+if (mlir::isa(srcTy)) {
+  if (opts.treatBooleanAsSigned)
+cgf.getCIRGenModule().errorNYI("signed bool");
+  if (cgf.getBuilder().isInt(dstTy))
+castKind = cir::CastKind::bool_to_int;
+  else if (mlir::isa(dstTy))
+castKind = cir::CastKind::bool_to_float;
+  else
+llvm_unreachable("Internal error: Cast to unexpected type");
+} else if (cgf.getBuilder().isInt(srcTy)) {
+  if (cgf.getBuilder().isInt(dstTy))
+castKind = cir::CastKind::integral;
+  else if (mlir::isa(dstTy))
+castKind = cir::CastKind::int_to_float;
+  else
+llvm_unreachable("Internal error: Cast to unexpected type");
+} else if (mlir::isa(srcTy)) {
+  if (cgf.getBuilder().isInt(dstTy)) {
+// If we can't recognize overflow as undefined behavior, assume that
+// overflow saturates. This protects against normal optimizations if we
+// are compiling with non-standard FP semantics.
+if (!cgf.cgm.getCodeGenOpts().StrictFloatCastOverflow)
+  cgf.getCIRGenModule().errorNYI("strict f

[clang] [CIR] Upstream CastOp and scalar conversions (PR #130690)

2025-03-12 Thread Erich Keane via cfe-commits


@@ -90,20 +89,259 @@ class ScalarExprEmitter : public 
StmtVisitor {
 builder.getCIRBoolAttr(e->getValue()));
   }
 
-  mlir::Value VisitCastExpr(CastExpr *E);
+  mlir::Value VisitCastExpr(CastExpr *e);
+
+  mlir::Value VisitExplicitCastExpr(ExplicitCastExpr *e) {
+return VisitCastExpr(e);
+  }
+
+  /// Perform a pointer to boolean conversion.
+  mlir::Value emitPointerToBoolConversion(mlir::Value v, QualType qt) {
+// TODO(cir): comparing the ptr to null is done when lowering CIR to LLVM.
+// We might want to have a separate pass for these types of conversions.
+return cgf.getBuilder().createPtrToBoolCast(v);
+  }
+
+  mlir::Value emitFloatToBoolConversion(mlir::Value src, mlir::Location loc) {
+auto boolTy = builder.getBoolTy();
+return builder.create(loc, boolTy,
+   cir::CastKind::float_to_bool, src);
+  }
+
+  mlir::Value emitIntToBoolConversion(mlir::Value srcVal, mlir::Location loc) {
+// Because of the type rules of C, we often end up computing a
+// logical value, then zero extending it to int, then wanting it
+// as a logical value again.
+// TODO: optimize this common case here or leave it for later
+// CIR passes?
+mlir::Type boolTy = cgf.convertType(cgf.getContext().BoolTy);
+return builder.create(loc, boolTy, cir::CastKind::int_to_bool,
+   srcVal);
+  }
+
+  /// Convert the specified expression value to a boolean (!cir.bool) truth
+  /// value. This is equivalent to "Val != 0".
+  mlir::Value emitConversionToBool(mlir::Value src, QualType srcType,
+   mlir::Location loc) {
+assert(srcType.isCanonical() && "EmitScalarConversion strips typedefs");
+
+if (srcType->isRealFloatingType())
+  return emitFloatToBoolConversion(src, loc);
+
+if (llvm::isa(srcType))
+  cgf.getCIRGenModule().errorNYI(loc, "member pointer to bool conversion");

erichkeane wrote:

This branch needs to return something.

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


[clang] [Clang][Diagnostics] Update select uses in DiagnosticXKinds.td to use enum_select (PR #130868)

2025-03-12 Thread Erich Keane via cfe-commits

erichkeane wrote:

> Handles #123121
> 
> @erichkeane Hi, I’m working on converting `select` statements to 
> `enum_select` in this draft PR, specifically targeting statements with 5 or 
> more options. I have a few questions and would appreciate some clarifications:

Awesome, glad to hear it!
> 
> The patch that introduced `enum_select` focused on select statements with 5 
> or more options, which is why I’ve prioritized those. Are there any cases 
> where select statements with fewer than 5 options should also be converted? 
> Is the number of options alone a determining factor, or does the presence of 
> magic numbers also need to be considered for conversion?

5 is a pretty decent heuristic for a first-pass.  I would expect though that 
the USES of these are much more important than the count.  The point of 
`enum_select` is to make the call-sites more readable, so this is for 
situations where there are a LOT of magic-numbers being used in the callers.  
Places where we have some other logic (besides the magic numbers) to determine 
the `select` value probably doesn't really qualify here.

> By "magic numbers," I understand the patch refers to hardcoded values like /* 
> ThingIWantSelected */ 5, which lack clarity. Could you provide some concrete 
> examples from the source code where this applies? Also, I’ve yet to come 
> across any enum specifically made for a select. Could you clarify when that 
> is necessary and give an example?
> 
For example: see the ones I changed here: 
https://github.com/llvm/llvm-project/commit/bf17016a92bc8a23d2cdd2b51355dd4eb5019c68

All/most of the calls/uses of diagnostics there are just hard coded values, 
which are pretty unreadable/error-prone.

> The note about "Ones that are 'calculated' based on some other criteria 
> aren't a great" isn’t entirely clear to me. Could you elaborate on this?
> 

Sure!  Basically "not magic numbers".  That is, if the diagnostic-select is 
always called with some sort of expression that wouldn't be reasonably replaced 
with the enumerator, it doesn't make sense to change it.  BUT if it is always 
called with an integer constant (or even, passed-to-the-calling function as an 
integer, even if that integer was derived via logic elsewhere), the enum_select 
probably makes sense to use.

> Lastly, I’d appreciate it if you could review the statements I’ve converted 
> so far to ensure I’m on the right track.

They currently don't seem to build?  But the real way I'd review these is based 
on how much it improves the readability of the call sites, which you haven't 
changed.

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


[clang] [MS][clang] Add support for vector deleting destructors (PR #126240)

2025-03-12 Thread Hans Wennborg via cfe-commits

zmodem wrote:

We're hitting link errors after this change when building with sanitizer 
coverage enabled:

```
lld-link: error: relocation against symbol in discarded section: .text
>>> referenced by obj/third_party/icu/icuuc_private/filteredbrk.obj:(.SCOVP$M)
>>> referenced by obj/third_party/icu/icuuc_private/filteredbrk.obj:(.SCOVP$M)
>>> referenced by obj/third_party/icu/icuuc_private/filteredbrk.obj:(.SCOVP$M)
>>> referenced by obj/third_party/icu/icuuc_private/filteredbrk.obj:(.SCOVP$M)
>>> referenced by obj/third_party/icu/icuuc_private/filteredbrk.obj:(.SCOVP$M)
```

I've added preprocessed source and compiler invocation for filteredbrk.obj 
here: https://crbug.com/402354446#comment6 Can you take a look?

I'll revert this to unbreak things in the meantime.

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


[clang] [CIR] Add transform test for cir-flatten-cfg (PR #130861)

2025-03-12 Thread Erich Keane via cfe-commits


@@ -0,0 +1,58 @@
+// RUN: cir-opt %s -cir-flatten-cfg -o - | FileCheck %s
+
+module {
+  cir.func @foo() {
+cir.scope {
+  %0 = cir.alloca !cir.int, !cir.ptr>, ["a", init] 
{alignment = 4 : i64}
+  %1 = cir.const #cir.int<4> : !cir.int
+  cir.store %1, %0 : !cir.int, !cir.ptr>
+}
+cir.return
+  }
+// CHECK:  cir.func @foo() {
+// CHECK:cir.br ^bb1

erichkeane wrote:

This here is a touch awkward, right?  I know we did a bit of work to remove 
'empty' blocks in the pass.  I wonder if a future version of this pass should 
be checking the 'exit' of a block to see if it is a single-out (that is, no 
decisions being done, just a single `br`, and merge the two.  It seems to fit 
in well with the flatten.

That is, this function here seems like it should/could be a single block, right?

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


[clang] [CIR] Add transform test for cir-flatten-cfg (PR #130861)

2025-03-12 Thread Erich Keane via cfe-commits

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

I don't have concerns, but am not the best person whose approval should count 
here.  I have questions/comments on the scope of the flatten pass (that is, 
what 'while we are here' type stuff it should do), but I'm again not really an 
authority on these.

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


[clang] [compiler-rt] [Coverage] Fix region termination for GNU statement expressions (PR #130976)

2025-03-12 Thread Justin Cady via cfe-commits

https://github.com/justincady created 
https://github.com/llvm/llvm-project/pull/130976

Calls to __noreturn__ functions result in region termination for
coverage mapping. But this creates incorrect coverage results when
__noreturn__ functions (or other constructs that result in region
termination) occur within [GNU statement expressions][1].

In this scenario an extra gap region is introduced within VisitStmt,
such that if the following line does not introduce a new region it
is unconditionally counted as uncovered.

This change adjusts the mapping such that terminate statements
within statement expressions do not propagate that termination
state after the statement expression is processed.

[1]: https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html

Fixes #124296


>From 6f3557780d06d6a2b1a7f315c49a3ad533d821e5 Mon Sep 17 00:00:00 2001
From: Justin Cady 
Date: Wed, 12 Mar 2025 11:23:19 -0400
Subject: [PATCH] [Coverage] Fix region termination for GNU statement
 expressions

Calls to __noreturn__ functions result in region termination for
coverage mapping. But this creates incorrect coverage results when
__noreturn__ functions (or other constructs that result in region
termination) occur within [GNU statement expressions][1].

In this scenario an extra gap region is introduced within VisitStmt,
such that if the following line does not introduce a new region it
is unconditionally counted as uncovered.

This change adjusts the mapping such that terminate statements
within statement expressions do not propagate that termination
state after the statement expression is processed.

[1]: https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html

Fixes #124296
---
 clang/lib/CodeGen/CoverageMappingGen.cpp  |  8 
 .../CoverageMapping/terminate-statements.cpp  |  7 +++
 .../Linux/coverage-statement-expression.cpp   | 19 +++
 3 files changed, 34 insertions(+)
 create mode 100644 
compiler-rt/test/profile/Linux/coverage-statement-expression.cpp

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index f09157771d2b5..73811d15979d5 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1505,6 +1505,14 @@ struct CounterCoverageMappingBuilder
 handleFileExit(getEnd(S));
   }
 
+  void VisitStmtExpr(const StmtExpr *E) {
+Visit(E->getSubStmt());
+// Any region termination (such as a noreturn CallExpr) within the 
statement
+// expression has been handled by visiting the sub-statement. The visitor
+// cannot be at a terminate statement leaving the statement expression.
+HasTerminateStmt = false;
+  }
+
   void VisitDecl(const Decl *D) {
 Stmt *Body = D->getBody();
 
diff --git a/clang/test/CoverageMapping/terminate-statements.cpp 
b/clang/test/CoverageMapping/terminate-statements.cpp
index 0067185fee8e6..d03e35630b317 100644
--- a/clang/test/CoverageMapping/terminate-statements.cpp
+++ b/clang/test/CoverageMapping/terminate-statements.cpp
@@ -346,6 +346,12 @@ int elsecondnoret(void) {
   return 0;
 }
 
+// CHECK-LABEL: _Z18statementexprnoretb
+int statementexprnoret(bool crash) {
+  int rc = ({ if (crash) abort(); 0; }); // CHECK-NOT: Gap,File 0, 
[[@LINE]]:41 -> [[@LINE+1]]:3 = 0
+  return rc;
+}
+
 int main() {
   foo(0);
   foo(1);
@@ -368,5 +374,6 @@ int main() {
   ornoret();
   abstractcondnoret();
   elsecondnoret();
+  statementexprnoret(false);
   return 0;
 }
diff --git a/compiler-rt/test/profile/Linux/coverage-statement-expression.cpp 
b/compiler-rt/test/profile/Linux/coverage-statement-expression.cpp
new file mode 100644
index 0..5894275b941a2
--- /dev/null
+++ b/compiler-rt/test/profile/Linux/coverage-statement-expression.cpp
@@ -0,0 +1,19 @@
+// RUN: %clangxx_profgen -std=gnu++17 -fuse-ld=lld -fcoverage-mapping -o %t %s
+// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t
+// RUN: llvm-profdata merge -o %t.profdata %t.profraw
+// RUN: llvm-cov show %t -instr-profile=%t.profdata 2>&1 | FileCheck %s
+
+#include 
+
+__attribute__ ((__noreturn__))
+void foo(void) { while (1); }   // CHECK:  [[@LINE]]| 0|void 
foo(void)
+_Noreturn void bar(void) { while (1); } // CHECK:  [[@LINE]]| 
0|_Noreturn void bar(void)
+// CHECK:  [[@LINE]]|  |
+int main(int argc, char **argv) {   // CHECK:  [[@LINE]]| 1|int 
main(
+  int rc = ({ if (argc > 3) foo(); 0; });   // CHECK:  [[@LINE]]| 1|  int 
rc =
+  printf("coverage after foo is present\n");// CHECK:  [[@LINE]]| 1|  
printf(
+// CHECK:  [[@LINE]]|  |
+  int rc2 = ({ if (argc > 3) bar(); 0; });  // CHECK:  [[@LINE]]| 1|  int 
rc2 =
+  printf("coverage after bar is present\n");// CHECK:  [[@LINE]]| 1|  
printf(
+  return rc + rc2;  // CHECK:  [[@LINE]]| 1|  
return rc
+}   // CHECK:  [[@LINE]]| 1|}


[clang] [compiler-rt] [Coverage] Fix region termination for GNU statement expressions (PR #130976)

2025-03-12 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-pgo

Author: Justin Cady (justincady)


Changes

Calls to __noreturn__ functions result in region termination for
coverage mapping. But this creates incorrect coverage results when
__noreturn__ functions (or other constructs that result in region
termination) occur within [GNU statement expressions][1].

In this scenario an extra gap region is introduced within VisitStmt,
such that if the following line does not introduce a new region it
is unconditionally counted as uncovered.

This change adjusts the mapping such that terminate statements
within statement expressions do not propagate that termination
state after the statement expression is processed.

[1]: https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html

Fixes #124296


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


3 Files Affected:

- (modified) clang/lib/CodeGen/CoverageMappingGen.cpp (+8) 
- (modified) clang/test/CoverageMapping/terminate-statements.cpp (+7) 
- (added) compiler-rt/test/profile/Linux/coverage-statement-expression.cpp 
(+19) 


``diff
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index f09157771d2b5..73811d15979d5 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1505,6 +1505,14 @@ struct CounterCoverageMappingBuilder
 handleFileExit(getEnd(S));
   }
 
+  void VisitStmtExpr(const StmtExpr *E) {
+Visit(E->getSubStmt());
+// Any region termination (such as a noreturn CallExpr) within the 
statement
+// expression has been handled by visiting the sub-statement. The visitor
+// cannot be at a terminate statement leaving the statement expression.
+HasTerminateStmt = false;
+  }
+
   void VisitDecl(const Decl *D) {
 Stmt *Body = D->getBody();
 
diff --git a/clang/test/CoverageMapping/terminate-statements.cpp 
b/clang/test/CoverageMapping/terminate-statements.cpp
index 0067185fee8e6..d03e35630b317 100644
--- a/clang/test/CoverageMapping/terminate-statements.cpp
+++ b/clang/test/CoverageMapping/terminate-statements.cpp
@@ -346,6 +346,12 @@ int elsecondnoret(void) {
   return 0;
 }
 
+// CHECK-LABEL: _Z18statementexprnoretb
+int statementexprnoret(bool crash) {
+  int rc = ({ if (crash) abort(); 0; }); // CHECK-NOT: Gap,File 0, 
[[@LINE]]:41 -> [[@LINE+1]]:3 = 0
+  return rc;
+}
+
 int main() {
   foo(0);
   foo(1);
@@ -368,5 +374,6 @@ int main() {
   ornoret();
   abstractcondnoret();
   elsecondnoret();
+  statementexprnoret(false);
   return 0;
 }
diff --git a/compiler-rt/test/profile/Linux/coverage-statement-expression.cpp 
b/compiler-rt/test/profile/Linux/coverage-statement-expression.cpp
new file mode 100644
index 0..5894275b941a2
--- /dev/null
+++ b/compiler-rt/test/profile/Linux/coverage-statement-expression.cpp
@@ -0,0 +1,19 @@
+// RUN: %clangxx_profgen -std=gnu++17 -fuse-ld=lld -fcoverage-mapping -o %t %s
+// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t
+// RUN: llvm-profdata merge -o %t.profdata %t.profraw
+// RUN: llvm-cov show %t -instr-profile=%t.profdata 2>&1 | FileCheck %s
+
+#include 
+
+__attribute__ ((__noreturn__))
+void foo(void) { while (1); }   // CHECK:  [[@LINE]]| 0|void 
foo(void)
+_Noreturn void bar(void) { while (1); } // CHECK:  [[@LINE]]| 
0|_Noreturn void bar(void)
+// CHECK:  [[@LINE]]|  |
+int main(int argc, char **argv) {   // CHECK:  [[@LINE]]| 1|int 
main(
+  int rc = ({ if (argc > 3) foo(); 0; });   // CHECK:  [[@LINE]]| 1|  int 
rc =
+  printf("coverage after foo is present\n");// CHECK:  [[@LINE]]| 1|  
printf(
+// CHECK:  [[@LINE]]|  |
+  int rc2 = ({ if (argc > 3) bar(); 0; });  // CHECK:  [[@LINE]]| 1|  int 
rc2 =
+  printf("coverage after bar is present\n");// CHECK:  [[@LINE]]| 1|  
printf(
+  return rc + rc2;  // CHECK:  [[@LINE]]| 1|  
return rc
+}   // CHECK:  [[@LINE]]| 1|}

``




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


[clang] [llvm] [DirectX] Remove DXILResourceMDAnalysis (PR #130323)

2025-03-12 Thread Helena Kotas via cfe-commits

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


[clang] [AST] Avoid repeated hash lookups (NFC) (PR #130887)

2025-03-12 Thread Kazu Hirata via cfe-commits

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


[clang] [llvm] [HLSL] Remove old resource annotations (PR #130338)

2025-03-12 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/130338

>From 99539251dcf58aab9a88973f9162156ae6f1aa77 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Thu, 6 Mar 2025 18:22:07 -0800
Subject: [PATCH 1/3] [HLSL][NFC] Update resource metadata tests to not use
 obsolete metadata annotations

---
 clang/test/CodeGenHLSL/cbuffer.hlsl   |  78 +-
 .../DirectX/Metadata/cbuffer_metadata.ll  |  80 +++
 .../CodeGen/DirectX/Metadata/srv_metadata.ll  | 103 +
 .../CodeGen/DirectX/Metadata/uav_metadata.ll  | 135 ++
 llvm/test/CodeGen/DirectX/UAVMetadata.ll  |  77 --
 llvm/test/CodeGen/DirectX/cbuf.ll |  37 -
 .../CodeGen/DirectX/legacy_cb_layout_0.ll |  14 --
 .../CodeGen/DirectX/legacy_cb_layout_1.ll |  37 -
 .../CodeGen/DirectX/legacy_cb_layout_2.ll |  51 ---
 .../CodeGen/DirectX/legacy_cb_layout_3.ll |  81 ---
 10 files changed, 394 insertions(+), 299 deletions(-)
 create mode 100644 llvm/test/CodeGen/DirectX/Metadata/cbuffer_metadata.ll
 create mode 100644 llvm/test/CodeGen/DirectX/Metadata/srv_metadata.ll
 create mode 100644 llvm/test/CodeGen/DirectX/Metadata/uav_metadata.ll
 delete mode 100644 llvm/test/CodeGen/DirectX/UAVMetadata.ll
 delete mode 100644 llvm/test/CodeGen/DirectX/cbuf.ll
 delete mode 100644 llvm/test/CodeGen/DirectX/legacy_cb_layout_0.ll
 delete mode 100644 llvm/test/CodeGen/DirectX/legacy_cb_layout_1.ll
 delete mode 100644 llvm/test/CodeGen/DirectX/legacy_cb_layout_2.ll
 delete mode 100644 llvm/test/CodeGen/DirectX/legacy_cb_layout_3.ll

diff --git a/clang/test/CodeGenHLSL/cbuffer.hlsl 
b/clang/test/CodeGenHLSL/cbuffer.hlsl
index 38093c6dfacd7..b5e435619438f 100644
--- a/clang/test/CodeGenHLSL/cbuffer.hlsl
+++ b/clang/test/CodeGenHLSL/cbuffer.hlsl
@@ -20,6 +20,14 @@
 // CHECK: %anon = type <{ float }>
 // CHECK: %anon.0 = type <{ <2 x i32> }>
 
+// CHECK: %__cblayout_CB_A = type <{ [2 x double], [3 x <3 x float>], float, 
[3 x double], half, [1 x <2 x double>], float, [2 x <3 x half>], <3 x half> }>
+// CHECK: %__cblayout_CB_B = type <{ [3 x <3 x double>], <3 x half> }>
+// CHECK: %__cblayout_CB_C = type <{ i32, target("dx.Layout", %F, 96, 0, 16, 
28, 32, 56, 64, 80, 84, 90), half, target("dx.Layout", %G, 258, 0, 48, 64, 
256), double }>
+
+// CHECK: %F = type <{ double, <3 x float>, float, <3 x double>, half, <2 x 
double>, float, <3 x half>, <3 x half> }>
+// CHECK: %G = type <{ target("dx.Layout", %E, 36, 0, 8, 16, 20, 22, 24, 32), 
[1 x float], [2 x target("dx.Layout", %F, 96, 0, 16, 28, 32, 56, 64, 80, 84, 
90)], half }>
+// CHECK: %E = type <{ float, double, float, half, i16, i64, i32 }>
+
 cbuffer CBScalars : register(b1, space5) {
   float a1;
   double a2;
@@ -155,6 +163,64 @@ cbuffer CBMix {
 uint16_t f9;
 };  
 
+// CHECK: @CB_A.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CB_A, 188, 0, 32, 76, 80, 120, 128, 144, 160, 
182))
+
+cbuffer CB_A {
+  double B0[2];
+  float3 B1[3];
+  float B2;
+  double B3[3];
+  half B4;
+  double2 B5[1];
+  float B6;
+  half3 B7[2];
+  half3 B8;
+}
+
+// CHECK: @CB_B.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CB_B, 94, 0, 88))
+cbuffer CB_B {
+  double3 B9[3];
+  half3 B10;
+}
+
+struct E {
+  float A0;
+  double A1;
+  float A2;
+  half A3;
+  int16_t A4;
+  int64_t A5;
+  int A6;
+};
+
+struct F {
+  double B0;
+  float3 B1;
+  float B2;
+  double3 B3;
+  half B4;
+  double2 B5;
+  float B6;
+  half3 B7;
+  half3 B8;
+};
+
+struct G {
+  E C0;
+  float C1[1];
+  F C2[2];
+  half C3;
+};
+
+// CHECK: @CB_C.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CB_C, 400, 0, 16, 112, 128, 392))
+cbuffer CB_C {
+  int D0;
+  F D1;
+  half D2;
+  G D3;
+  double D4;
+}
+
 // CHECK: define internal void @_init_resource_CBScalars.cb()
 // CHECK-NEXT: entry:
 // CHECK-NEXT: %[[HANDLE1:.*]] = call target("dx.CBuffer", target("dx.Layout", 
%__cblayout_CBScalars, 56, 0, 8, 16, 24, 32, 36, 40, 48))
@@ -171,7 +237,7 @@ RWBuffer Buf;
 
 [numthreads(4,1,1)]
 void main() {
-  Buf[0] = a1 + b1.z + c1[2] + a.f1.y + f1;
+  Buf[0] = a1 + b1.z + c1[2] + a.f1.y + f1 + B1[0].x + B10.z + D1.B2;
 }
 
 // CHECK: define internal void @_GLOBAL__sub_I_cbuffer.hlsl()
@@ -179,7 +245,8 @@ void main() {
 // CHECK-NEXT: call void @_init_resource_CBScalars.cb()
 // CHECK-NEXT: call void @_init_resource_CBArrays.cb()
 
-// CHECK: !hlsl.cbs = !{![[CBSCALARS:[0-9]+]], ![[CBVECTORS:[0-9]+]], 
![[CBARRAYS:[0-9]+]], ![[CBSTRUCTS:[0-9]+]], ![[CBMIX:[0-9]+]]}
+// CHECK: !hlsl.cbs = !{![[CBSCALARS:[0-9]+]], ![[CBVECTORS:[0-9]+]], 
![[CBARRAYS:[0-9]+]], ![[CBSTRUCTS:[0-9]+]], ![[CBMIX:[0-9]+]],
+// CHECK-SAME: ![[CB_A:[0-9]+]], ![[CB_B:[0-9]+]], ![[CB_C:[0-9]+]]}
 
 // CHECK: ![[CBSCALARS]] = !{ptr @CBScalars.cb, ptr addrspace(2) @a1, ptr 
addrspace(2) @a2, ptr addrspace(2) @a3, ptr addrspace(2) @a4,
 // CHECK-SAME: ptr addrspace(2) @a5, ptr addrspace(2) @a6, ptr

[clang] bdbe8fa - [flang] Align `-x` language modes with `gfortran` (#130268)

2025-03-12 Thread via cfe-commits

Author: Iñaki Amatria Barral
Date: 2025-03-12T16:45:33+01:00
New Revision: bdbe8fa1f3dcde77f7e0741ea7fa757ce092a420

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

LOG: [flang] Align `-x` language modes with `gfortran` (#130268)

This PR addresses some of the issues described in
https://github.com/llvm/llvm-project/issues/127617. Key changes:

- Stop assuming fixed-form for `-x f95` unless the input is a `.i` file.
This change ensures compatibility with `-save-temps` workflows while
preventing unintended fixed-form assumptions.
- Ensure `-x f95-cpp-input` enables `-cpp` by default, aligning Flang's
behavior with `gfortran`.

Added: 
flang/test/Driver/dash-x-f95-cpp-input.f
flang/test/Driver/dash-x-f95-do-not-assume-fixed-form.f90

Modified: 
clang/lib/Driver/ToolChains/Flang.cpp
flang/lib/Frontend/CompilerInvocation.cpp
flang/test/Driver/input-from-stdin/input-from-stdin.f90

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index d4fea633d0edf..3ee305fc0460d 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -817,8 +817,13 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
 
   // 'flang -E' always produces output that is suitable for use as fixed form
   // Fortran. However it is only valid free form source if the original is also
-  // free form.
-  if (InputType == types::TY_PP_Fortran &&
+  // free form. Ensure this logic does not incorrectly assume fixed-form for
+  // cases where it shouldn't, such as `flang -x f95 foo.f90`.
+  bool isAtemporaryPreprocessedFile =
+  Input.isFilename() &&
+  llvm::sys::path::extension(Input.getFilename())
+  .ends_with(types::getTypeTempSuffix(InputType, /*CLStyle=*/false));
+  if (InputType == types::TY_PP_Fortran && isAtemporaryPreprocessedFile &&
   !Args.getLastArg(options::OPT_ffixed_form, options::OPT_ffree_form))
 CmdArgs.push_back("-ffixed-form");
 

diff  --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index 8b07a50824899..1537122ddced5 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -863,6 +863,12 @@ static void 
parsePreprocessorArgs(Fortran::frontend::PreprocessorOptions &opts,
 (currentArg->getOption().matches(clang::driver::options::OPT_cpp))
 ? PPMacrosFlag::Include
 : PPMacrosFlag::Exclude;
+  // Enable -cpp based on -x unless explicitly disabled with -nocpp
+  if (opts.macrosFlag != PPMacrosFlag::Exclude)
+if (const auto *dashX = args.getLastArg(clang::driver::options::OPT_x))
+  opts.macrosFlag = llvm::StringSwitch(dashX->getValue())
+.Case("f95-cpp-input", PPMacrosFlag::Include)
+.Default(opts.macrosFlag);
 
   opts.noReformat = args.hasArg(clang::driver::options::OPT_fno_reformat);
   opts.preprocessIncludeLines =

diff  --git a/flang/test/Driver/dash-x-f95-cpp-input.f 
b/flang/test/Driver/dash-x-f95-cpp-input.f
new file mode 100644
index 0..7c4689c6374d3
--- /dev/null
+++ b/flang/test/Driver/dash-x-f95-cpp-input.f
@@ -0,0 +1,35 @@
+program main
+  print *, __FILE__, __LINE__
+end
+
+! This test verifies that `flang`'s `-x` options behave like `gfortran`'s.
+! Specifically:
+! - `-x f95` should process the file based on its extension unless overridden.
+! - `-x f95-cpp-input` should behave like `-x f95` but with preprocessing
+!   (`-cpp`) enabled unless overridden.
+
+! ---
+! Ensure the file is treated as fixed-form unless explicitly set otherwise
+! ---
+! RUN: not %flang -Werror -fsyntax-only -x f95 -cpp %s 2>&1 | FileCheck 
--check-prefix=SCAN-ERROR %s
+! RUN: not %flang -Werror -fsyntax-only -x f95-cpp-input %s 2>&1 | FileCheck 
--check-prefix=SCAN-ERROR %s
+
+! SCAN-ERROR: error: Could not scan
+
+! RUN: %flang -Werror -fsyntax-only -x f95 -cpp -ffree-form %s 2>&1 | 
FileCheck --check-prefix=NO-SCAN-ERROR --allow-empty %s
+! RUN: %flang -Werror -fsyntax-only -x f95-cpp-input -ffree-form %s 2>&1 | 
FileCheck --check-prefix=NO-SCAN-ERROR --allow-empty %s
+
+! NO-SCAN-ERROR-NOT: error
+
+! ---
+! Ensure `-cpp` is not enabled by default unless explicitly requested
+! ---
+! RUN: not %flang -Werror -fsyntax-only -x f95 -ffree-form %s 2>&1 | FileCheck 
--check-prefix=SEMA-ERROR %s
+! RUN: not %flang -Werror -fsyntax-only -x f95-cpp-input -nocpp -ffree-form %s 
2>&1 | FileCheck --check-prefix=SEMA-ERROR %s
+
+! SEMA-ERROR: error: Semantic errors
+
+! RUN: %flang -Werror -fsyntax-only -x f95 -cpp -ffree-form %s 2>&1 | 
FileCheck --check-prefix=NO-SEMA-ERROR --allow-empty %s
+! RUN: %flang -Werror -fsyntax-only -x f95-cpp-input -ffree-form %s 2>&1 | 
FileChe

[clang] [llvm] [HLSL] Remove old resource annotations (PR #130338)

2025-03-12 Thread Helena Kotas via cfe-commits

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


[clang] f4d599c - [Support] Do not remove lock file on failure (#130834)

2025-03-12 Thread via cfe-commits

Author: Jan Svoboda
Date: 2025-03-12T08:51:00-07:00
New Revision: f4d599cda90aa06d1e1a95474a0ee3a4053e77dd

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

LOG: [Support] Do not remove lock file on failure (#130834)

Clients of `LockFileManager` call `unsafeRemoveLockFile()` whenever
`tryLock()` fails. However looking at the code, there are no scenarios
where this actually does something useful. This PR removes such calls.

Added: 


Modified: 
clang/lib/Frontend/CompilerInstance.cpp
llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp

Removed: 




diff  --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index e9e96683ca51f..44f4f48ef94e8 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -1491,8 +1491,6 @@ static bool compileModuleAndReadASTBehindLock(
   // related errors.
   Diags.Report(ModuleNameLoc, diag::remark_module_lock_failure)
   << Module->Name << toString(std::move(Err));
-  // Clear out any potential leftover.
-  Lock.unsafeRemoveLockFile();
   return compileModuleAndReadASTImpl(ImportingInstance, ImportLoc,
  ModuleNameLoc, Module, 
ModuleFileName);
 }

diff  --git a/llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp
index 65cbb13628301..e2e449f1c8a38 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp
@@ -1552,7 +1552,6 @@ PreservedAnalyses AMDGPUSplitModulePass::run(Module &M,
 LLVM_DEBUG(
 dbgs() << "[amdgpu-split-module] unable to acquire lockfile, debug 
"
   "output may be mangled by other processes\n");
-Lock.unsafeRemoveLockFile();
   } else if (!Owned) {
 switch (Lock.waitForUnlock()) {
 case LockFileManager::Res_Success:



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


[clang] [llvm] [Support] Do not remove lock file on failure (PR #130834)

2025-03-12 Thread Jan Svoboda via cfe-commits

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


[clang] e5aac52 - [AST] Avoid repeated hash lookups (NFC) (#130887)

2025-03-12 Thread via cfe-commits

Author: Kazu Hirata
Date: 2025-03-12T08:46:48-07:00
New Revision: e5aac528fede69ecc90958fefcfa1f26b97c9e94

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

LOG: [AST] Avoid repeated hash lookups (NFC) (#130887)

Added: 


Modified: 
clang/lib/AST/ASTContext.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 55022a4bc000a..7ed5b033d9bd8 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -11832,8 +11832,8 @@ bool ASTContext::mergeExtParameterInfo(
 }
 
 void ASTContext::ResetObjCLayout(const ObjCInterfaceDecl *D) {
-  if (ObjCLayouts.count(D)) {
-ObjCLayouts[D] = nullptr;
+  if (auto It = ObjCLayouts.find(D); It != ObjCLayouts.end()) {
+It->second = nullptr;
 for (auto *SubClass : ObjCSubClasses[D])
   ResetObjCLayout(SubClass);
   }



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


[clang] [HLSL][NFC] Update HLSL AST tests to be more readable (PR #130910)

2025-03-12 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-hlsl

@llvm/pr-subscribers-clang

Author: Helena Kotas (hekota)


Changes

Replacing all occurences of
- `0x{{[0-9A-Fa-f]+}} <> `
- `0x{{[0-9A-Fa-f]+}} <>`
- `0x{{[0-9A-Fa-f]+}}`
- `0x{{[0-9a-fA-F]+}} `
- `0x{{[0-9a-fA-F]+}}  col:#`

with
- `{{.*}}`

to improve readability and conciseness of the HLSL AST tests.




---

Patch is 64.04 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/130910.diff


10 Files Affected:

- (modified) clang/test/AST/HLSL/ByteAddressBuffers-AST.hlsl (+8-10) 
- (modified) clang/test/AST/HLSL/HLSLControlFlowHint.hlsl (+9-9) 
- (modified) clang/test/AST/HLSL/StructuredBuffers-AST.hlsl (+119-119) 
- (modified) clang/test/AST/HLSL/TypedBuffers-AST.hlsl (+63-63) 
- (modified) 
clang/test/AST/HLSL/is_structured_resource_element_compatible_concept.hlsl 
(+10-10) 
- (modified) 
clang/test/AST/HLSL/is_typed_resource_element_compatible_concept.hlsl (+5-5) 
- (modified) clang/test/AST/HLSL/packoffset.hlsl (+2-2) 
- (modified) clang/test/AST/HLSL/vector-alias.hlsl (+53-53) 
- (modified) clang/test/AST/HLSL/vector-constructors.hlsl (+133-133) 
- (modified) clang/test/ParserHLSL/hlsl_resource_handle_attrs.hlsl (+11-11) 


``diff
diff --git a/clang/test/AST/HLSL/ByteAddressBuffers-AST.hlsl 
b/clang/test/AST/HLSL/ByteAddressBuffers-AST.hlsl
index 909cce17e344c..12025ab998bad 100644
--- a/clang/test/AST/HLSL/ByteAddressBuffers-AST.hlsl
+++ b/clang/test/AST/HLSL/ByteAddressBuffers-AST.hlsl
@@ -22,8 +22,8 @@
 // RUN:   -DRESOURCE=RasterizerOrderedByteAddressBuffer %s | FileCheck 
-DRESOURCE=RasterizerOrderedByteAddressBuffer \
 // RUN:   -check-prefixes=CHECK,CHECK-UAV,CHECK-NOSUBSCRIPT %s
 
-// EMPTY: CXXRecordDecl 0x{{[0-9A-Fa-f]+}} <>  
implicit  class [[RESOURCE]]
-// EMPTY-NEXT: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final
+// EMPTY: CXXRecordDecl {{.*}} implicit  class 
[[RESOURCE]]
+// EMPTY-NEXT: FinalAttr {{.*}}  Implicit final
 
 // There should be no more occurrences of RESOURCE
 // EMPTY-NOT: {{[^[:alnum:]]}}[[RESOURCE]]
@@ -34,16 +34,14 @@ RESOURCE Buffer;
 
 #endif
 
-// CHECK: CXXRecordDecl 0x{{[0-9A-Fa-f]+}} <>  
implicit referenced  class [[RESOURCE]] definition
-
-
-// CHECK: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final
-// CHECK-NEXT: FieldDecl 0x{{[0-9A-Fa-f]+}} <>  
implicit __handle '__hlsl_resource_t
+// CHECK: CXXRecordDecl {{.*}} implicit referenced  class [[RESOURCE]] definition
+// CHECK: FinalAttr {{.*}}  Implicit final
+// CHECK-NEXT: FieldDecl {{.*}} implicit __handle '__hlsl_resource_t
 // CHECK-SRV-SAME{LITERAL}: [[hlsl::resource_class(SRV)]]
 // CHECK-UAV-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-NEXT: HLSLResourceAttr {{.*}}  Implicit RawBuffer
 
-// CHECK-NOSUBSCRIPT-NOT: CXXMethodDecl 0x{{[0-9A-Fa-f]+}} <> 
 operator[] 'const element_type &(unsigned int) const'
-// CHECK-NOSUBSCRIPT-NOT: CXXMethodDecl 0x{{[0-9A-Fa-f]+}} <> 
 operator[] 'element_type &(unsigned int)'
+// CHECK-NOSUBSCRIPT-NOT: CXXMethodDecl {{.*}} operator[] 'const element_type 
&(unsigned int) const'
+// CHECK-NOSUBSCRIPT-NOT: CXXMethodDecl {{.*}} operator[] 'element_type 
&(unsigned int)'
diff --git a/clang/test/AST/HLSL/HLSLControlFlowHint.hlsl 
b/clang/test/AST/HLSL/HLSLControlFlowHint.hlsl
index a36779c05fbc9..c1e6d969c8d31 100644
--- a/clang/test/AST/HLSL/HLSLControlFlowHint.hlsl
+++ b/clang/test/AST/HLSL/HLSLControlFlowHint.hlsl
@@ -1,8 +1,8 @@
 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-compute -ast-dump %s | 
FileCheck %s
 
-// CHECK: FunctionDecl 0x{{[0-9A-Fa-f]+}} <{{.*}}> {{.*}} used branch 'int 
(int)'
-// CHECK: AttributedStmt 0x{{[0-9A-Fa-f]+}} <
-// CHECK-NEXT: -HLSLControlFlowHintAttr 0x{{[0-9A-Fa-f]+}} <{{.*}}> branch
+// CHECK: FunctionDecl {{.*}} used branch 'int (int)'
+// CHECK: AttributedStmt
+// CHECK-NEXT: HLSLControlFlowHintAttr {{.*}} branch
 export int branch(int X){
 int resp;
 [branch] if (X > 0) {
@@ -14,9 +14,9 @@ export int branch(int X){
 return resp;
 }
 
-// CHECK: FunctionDecl 0x{{[0-9A-Fa-f]+}} <{{.*}}> {{.*}} used flatten 'int 
(int)'
-// CHECK: AttributedStmt 0x{{[0-9A-Fa-f]+}} <
-// CHECK-NEXT: -HLSLControlFlowHintAttr 0x{{[0-9A-Fa-f]+}} <{{.*}}> flatten
+// CHECK: FunctionDecl {{.*}} used flatten 'int (int)'
+// CHECK: AttributedStmt
+// CHECK-NEXT: HLSLControlFlowHintAttr {{.*}} flatten
 export int flatten(int X){
 int resp;
 [flatten] if (X > 0) {
@@ -28,9 +28,9 @@ export int flatten(int X){
 return resp;
 }
 
-// CHECK: FunctionDecl 0x{{[0-9A-Fa-f]+}} <{{.*}}> {{.*}} used no_attr 'int 
(int)'
-// CHECK-NOT: AttributedStmt 0x{{[0-9A-Fa-f]+}} <
-// CHECK-NOT: -HLSLControlFlowHintAttr
+// CHECK: FunctionDecl {{.*}} used no_attr 'int (int)'
+// CHECK-NOT: AttributedStmt
+//

[clang] [HLSL][NFC] Update HLSL AST tests to be more readable (PR #130910)

2025-03-12 Thread Helena Kotas via cfe-commits

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


[clang] [CIR] Don't generate ClangIR after an unrecoverable error occured (PR #130971)

2025-03-12 Thread Morris Hafner via cfe-commits

https://github.com/mmha created https://github.com/llvm/llvm-project/pull/130971

None

>From 92066054a6a14f2e16b7f2256bf730762ab5d5d6 Mon Sep 17 00:00:00 2001
From: Morris Hafner 
Date: Wed, 12 Mar 2025 07:28:09 -0700
Subject: [PATCH] [CIR] Don't generate ClangIR after an unrecoverable error
 occured

---
 clang/lib/CIR/CodeGen/CIRGenerator.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/lib/CIR/CodeGen/CIRGenerator.cpp 
b/clang/lib/CIR/CodeGen/CIRGenerator.cpp
index 91070eda7d45a..6fa31ab707139 100644
--- a/clang/lib/CIR/CodeGen/CIRGenerator.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenerator.cpp
@@ -43,6 +43,8 @@ void CIRGenerator::Initialize(ASTContext &astContext) {
 mlir::ModuleOp CIRGenerator::getModule() const { return cgm->getModule(); }
 
 bool CIRGenerator::HandleTopLevelDecl(DeclGroupRef group) {
+  if (diags.hasUnrecoverableErrorOccurred())
+return true;
 
   for (Decl *decl : group)
 cgm->emitTopLevelDecl(decl);

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


[clang] Reduce memory usage in AST parent map generation by lazily checking if nodes have been seen (PR #129934)

2025-03-12 Thread Aaron Ballman via cfe-commits

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

LGTM, thanks for the fix!

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


[clang] [flang] [flang] Align `-x` language modes with `gfortran` (PR #130268)

2025-03-12 Thread Tarun Prabhu via cfe-commits
=?utf-8?q?I=C3=B1aki?= Amatria Barral 
Message-ID:
In-Reply-To: 


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

Thanks for all the changes :-)

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


[clang] [flang] [flang] Add support for -f[no-]verbose-asm (PR #130788)

2025-03-12 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu commented:

Do we really want to maintain an equivalence with clang by keeping this in 
`CodeGenOptions` when it really ought to be a `TargetOption`? It looks like 
almost all of the handling of this option takes place in `flang`, so we 
probably shouldn't be bound to idiosyncracies in `clang` if we can help it.

It might make the option declaration messier unless conditional marshalling is 
possible (I don't know if it is or not). 

I don't have a very strong opinion on this. If others are ok with leaving this 
in `CodeGenOptions`, I'm happy to go along with it. What do you think?

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


[clang] [llvm] [LLVM][SROA] Teach SROA how to "bitcast" between fixed and scalable vectors. (PR #130973)

2025-03-12 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-transforms

Author: Paul Walker (paulwalker-arm)


Changes

For function whose vscale_range is limited to a single value we can size 
scalable vectors. This aids SROA by allowing scalable vector load and store 
operations to be considered for replacement whereby bitcasts through memory can 
be replaced by vector insert or extract operations.

---

Patch is 56.51 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/130973.diff


11 Files Affected:

- (modified) clang/test/CodeGen/RISCV/attr-riscv-rvv-vector-bits-less-8-call.c 
(+25-13) 
- (modified) clang/test/CodeGen/RISCV/attr-riscv-rvv-vector-bits-less-8-cast.c 
(+6-2) 
- (modified) clang/test/CodeGen/RISCV/attr-rvv-vector-bits-cast.c (+9-7) 
- (modified) clang/test/CodeGen/attr-arm-sve-vector-bits-cast.c (+10-13) 
- (modified) llvm/include/llvm/IR/Attributes.h (+4) 
- (modified) llvm/include/llvm/IR/DerivedTypes.h (+16) 
- (modified) llvm/lib/IR/AttributeImpl.h (+1) 
- (modified) llvm/lib/IR/Attributes.cpp (+8) 
- (modified) llvm/lib/Transforms/Scalar/SROA.cpp (+92-34) 
- (added) llvm/test/Transforms/SROA/scalable-vectors-with-known-vscale.ll 
(+248) 
- (modified) llvm/test/Transforms/SROA/scalable-vectors.ll (+142) 


``diff
diff --git a/clang/test/CodeGen/RISCV/attr-riscv-rvv-vector-bits-less-8-call.c 
b/clang/test/CodeGen/RISCV/attr-riscv-rvv-vector-bits-less-8-call.c
index e2f02dc64f766..66fd466eccfef 100644
--- a/clang/test/CodeGen/RISCV/attr-riscv-rvv-vector-bits-less-8-call.c
+++ b/clang/test/CodeGen/RISCV/attr-riscv-rvv-vector-bits-less-8-call.c
@@ -26,11 +26,15 @@ typedef vbool64_t fixed_bool64_t 
__attribute__((riscv_rvv_vector_bits(__riscv_v_
 //
 // CHECK-128-LABEL: @call_bool32_ff(
 // CHECK-128-NEXT:  entry:
+// CHECK-128-NEXT:[[SAVED_VALUE:%.*]] = alloca <1 x i8>, align 1
+// CHECK-128-NEXT:[[SAVED_VALUE3:%.*]] = alloca <1 x i8>, align 1
 // CHECK-128-NEXT:[[SAVED_VALUE4:%.*]] = alloca , align 1
 // CHECK-128-NEXT:[[RETVAL_COERCE:%.*]] = alloca , align 1
-// CHECK-128-NEXT:[[TMP0:%.*]] = tail call  
@llvm.riscv.vmand.nxv2i1.i64( [[OP1_COERCE:%.*]],  [[OP2_COERCE:%.*]], i64 4)
-// CHECK-128-NEXT:store  [[TMP0]], ptr [[SAVED_VALUE4]], 
align 1, !tbaa [[TBAA6:![0-9]+]]
-// CHECK-128-NEXT:[[TMP1:%.*]] = load <1 x i8>, ptr [[SAVED_VALUE4]], 
align 1, !tbaa [[TBAA10:![0-9]+]]
+// CHECK-128-NEXT:
[[SAVED_VALUE_0_SAVED_VALUE_0_SAVED_VALUE_0_SAVED_VALUE_0_:%.*]] = load , ptr [[SAVED_VALUE]], align 1, !tbaa [[TBAA6:![0-9]+]]
+// CHECK-128-NEXT:
[[SAVED_VALUE3_0_SAVED_VALUE3_0_SAVED_VALUE3_0_SAVED_VALUE3_0_:%.*]] = load 
, ptr [[SAVED_VALUE3]], align 1, !tbaa [[TBAA6]]
+// CHECK-128-NEXT:[[TMP0:%.*]] = tail call  
@llvm.riscv.vmand.nxv2i1.i64( 
[[SAVED_VALUE_0_SAVED_VALUE_0_SAVED_VALUE_0_SAVED_VALUE_0_]],  
[[SAVED_VALUE3_0_SAVED_VALUE3_0_SAVED_VALUE3_0_SAVED_VALUE3_0_]], i64 4)
+// CHECK-128-NEXT:store  [[TMP0]], ptr [[SAVED_VALUE4]], 
align 1, !tbaa [[TBAA9:![0-9]+]]
+// CHECK-128-NEXT:[[TMP1:%.*]] = load <1 x i8>, ptr [[SAVED_VALUE4]], 
align 1, !tbaa [[TBAA6]]
 // CHECK-128-NEXT:store <1 x i8> [[TMP1]], ptr [[RETVAL_COERCE]], align 1
 // CHECK-128-NEXT:[[TMP2:%.*]] = load , ptr 
[[RETVAL_COERCE]], align 1
 // CHECK-128-NEXT:ret  [[TMP2]]
@@ -52,11 +56,15 @@ fixed_bool32_t call_bool32_ff(fixed_bool32_t op1, 
fixed_bool32_t op2) {
 //
 // CHECK-128-LABEL: @call_bool64_ff(
 // CHECK-128-NEXT:  entry:
+// CHECK-128-NEXT:[[SAVED_VALUE:%.*]] = alloca <1 x i8>, align 1
+// CHECK-128-NEXT:[[SAVED_VALUE3:%.*]] = alloca <1 x i8>, align 1
 // CHECK-128-NEXT:[[SAVED_VALUE4:%.*]] = alloca , align 1
 // CHECK-128-NEXT:[[RETVAL_COERCE:%.*]] = alloca , align 1
-// CHECK-128-NEXT:[[TMP0:%.*]] = tail call  
@llvm.riscv.vmand.nxv1i1.i64( [[OP1_COERCE:%.*]],  [[OP2_COERCE:%.*]], i64 2)
+// CHECK-128-NEXT:
[[SAVED_VALUE_0_SAVED_VALUE_0_SAVED_VALUE_0_SAVED_VALUE_0_:%.*]] = load , ptr [[SAVED_VALUE]], align 1, !tbaa [[TBAA6]]
+// CHECK-128-NEXT:
[[SAVED_VALUE3_0_SAVED_VALUE3_0_SAVED_VALUE3_0_SAVED_VALUE3_0_:%.*]] = load 
, ptr [[SAVED_VALUE3]], align 1, !tbaa [[TBAA6]]
+// CHECK-128-NEXT:[[TMP0:%.*]] = tail call  
@llvm.riscv.vmand.nxv1i1.i64( 
[[SAVED_VALUE_0_SAVED_VALUE_0_SAVED_VALUE_0_SAVED_VALUE_0_]],  
[[SAVED_VALUE3_0_SAVED_VALUE3_0_SAVED_VALUE3_0_SAVED_VALUE3_0_]], i64 2)
 // CHECK-128-NEXT:store  [[TMP0]], ptr [[SAVED_VALUE4]], 
align 1, !tbaa [[TBAA11:![0-9]+]]
-// CHECK-128-NEXT:[[TMP1:%.*]] = load <1 x i8>, ptr [[SAVED_VALUE4]], 
align 1, !tbaa [[TBAA10]]
+// CHECK-128-NEXT:[[TMP1:%.*]] = load <1 x i8>, ptr [[SAVED_VALUE4]], 
align 1, !tbaa [[TBAA6]]
 // CHECK-128-NEXT:store <1 x i8> [[TMP1]], ptr [[RETVAL_COERCE]], align 1
 // CHECK-128-NEXT:[[TMP2:%.*]] = load , ptr 
[[RETVAL_COERCE]], align 1
 // CHECK-128-NEXT:ret  [[TMP2]]
@@ -82,11 +90,13 @@ fixed_bool64_t call_bool64_ff(fixed_bool64_t op1, 
fixed_bool64_t op2) {
 //
 // CHECK-128-LABEL: @call_bo

[clang] [Clang] add additional tests for -Wshift-bool (PR #130339)

2025-03-12 Thread Aaron Ballman via cfe-commits

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

LGTM!

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


[clang-tools-extra] [clang-tidy] support pointee mutation check in misc-const-correctness (PR #130494)

2025-03-12 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/130494

>From 353f538f425ead9ee10ca6c046a6517b9e157db4 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sun, 9 Mar 2025 15:43:37 +
Subject: [PATCH 1/9] [clang-tidy] support pointee mutation check in
 misc-const-correctness

---
 .../clang-tidy/misc/ConstCorrectnessCheck.cpp | 156 --
 .../clang-tidy/misc/ConstCorrectnessCheck.h   |   3 +
 clang-tools-extra/docs/ReleaseNotes.rst   |   3 +-
 .../checks/misc/const-correctness.rst |  44 +
 .../const-correctness-pointer-as-pointers.cpp |  50 ++
 .../const-correctness-transform-values.cpp|   1 +
 .../const-correctness-values-before-cxx23.cpp |   1 +
 .../misc/const-correctness-values.cpp |   1 +
 .../misc/const-correctness-wrong-config.cpp   |   7 +-
 9 files changed, 207 insertions(+), 59 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-pointers.cpp

diff --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
index dbe59233df699..023c834d5700f 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
@@ -13,6 +13,8 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "llvm/Support/Casting.h"
+#include 
 
 using namespace clang::ast_matchers;
 
@@ -39,34 +41,47 @@ ConstCorrectnessCheck::ConstCorrectnessCheck(StringRef Name,
 : ClangTidyCheck(Name, Context),
   AnalyzeValues(Options.get("AnalyzeValues", true)),
   AnalyzeReferences(Options.get("AnalyzeReferences", true)),
+  AnalyzePointers(Options.get("AnalyzePointers", true)),
   WarnPointersAsValues(Options.get("WarnPointersAsValues", false)),
+  WarnPointersAsPointers(Options.get("WarnPointersAsPointers", true)),
   TransformValues(Options.get("TransformValues", true)),
   TransformReferences(Options.get("TransformReferences", true)),
   TransformPointersAsValues(
   Options.get("TransformPointersAsValues", false)),
+  TransformPointersAsPointers(
+  Options.get("TransformPointersAsPointers", true)),
   AllowedTypes(
   utils::options::parseStringList(Options.get("AllowedTypes", ""))) {
-  if (AnalyzeValues == false && AnalyzeReferences == false)
+  if (AnalyzeValues == false && AnalyzeReferences == false &&
+  AnalyzePointers == false)
 this->configurationDiag(
 "The check 'misc-const-correctness' will not "
-"perform any analysis because both 'AnalyzeValues' and "
-"'AnalyzeReferences' are false.");
+"perform any analysis because both 'AnalyzeValues', "
+"'AnalyzeReferences' and 'AnalyzePointers' are false.");
 }
 
 void ConstCorrectnessCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "AnalyzeValues", AnalyzeValues);
   Options.store(Opts, "AnalyzeReferences", AnalyzeReferences);
+  Options.store(Opts, "AnalyzePointers", AnalyzePointers);
   Options.store(Opts, "WarnPointersAsValues", WarnPointersAsValues);
+  Options.store(Opts, "WarnPointersAsPointers", WarnPointersAsPointers);
 
   Options.store(Opts, "TransformValues", TransformValues);
   Options.store(Opts, "TransformReferences", TransformReferences);
   Options.store(Opts, "TransformPointersAsValues", TransformPointersAsValues);
+  Options.store(Opts, "TransformPointersAsPointers",
+TransformPointersAsPointers);
   Options.store(Opts, "AllowedTypes",
 utils::options::serializeStringList(AllowedTypes));
 }
 
 void ConstCorrectnessCheck::registerMatchers(MatchFinder *Finder) {
-  const auto ConstType = hasType(isConstQualified());
+  const auto ConstType = hasType(
+  qualType(isConstQualified(),
+   // pointee check will check the const pointer and const array
+   unless(pointerType()), unless(arrayType(;
+
   const auto ConstReference = hasType(references(isConstQualified()));
   const auto RValueReference = hasType(
   referenceType(anyOf(rValueReferenceType(), 
unless(isSpelledAsLValue();
@@ -124,6 +139,11 @@ void ConstCorrectnessCheck::check(const 
MatchFinder::MatchResult &Result) {
   const auto *LocalScope = Result.Nodes.getNodeAs("scope");
   const auto *Variable = Result.Nodes.getNodeAs("local-value");
   const auto *Function = Result.Nodes.getNodeAs("function-decl");
+  const auto *VarDeclStmt = Result.Nodes.getNodeAs("decl-stmt");
+  // It can not be guaranteed that the variable is declared isolated,
+  // therefore a transformation might effect the other variables as well and
+  // be incorrect.
+  const bool CanBeFixIt = VarDeclStmt != nullptr && 
VarDeclStmt->isSingleDecl();
 
   /// If the variable was declared in a template it might be analyzed multiple
   /// times. Only one of those ins

[clang] [llvm] [LLVM][SROA] Teach SROA how to "bitcast" between fixed and scalable vectors. (PR #130973)

2025-03-12 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Paul Walker (paulwalker-arm)


Changes

For function whose vscale_range is limited to a single value we can size 
scalable vectors. This aids SROA by allowing scalable vector load and store 
operations to be considered for replacement whereby bitcasts through memory can 
be replaced by vector insert or extract operations.

---

Patch is 56.51 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/130973.diff


11 Files Affected:

- (modified) clang/test/CodeGen/RISCV/attr-riscv-rvv-vector-bits-less-8-call.c 
(+25-13) 
- (modified) clang/test/CodeGen/RISCV/attr-riscv-rvv-vector-bits-less-8-cast.c 
(+6-2) 
- (modified) clang/test/CodeGen/RISCV/attr-rvv-vector-bits-cast.c (+9-7) 
- (modified) clang/test/CodeGen/attr-arm-sve-vector-bits-cast.c (+10-13) 
- (modified) llvm/include/llvm/IR/Attributes.h (+4) 
- (modified) llvm/include/llvm/IR/DerivedTypes.h (+16) 
- (modified) llvm/lib/IR/AttributeImpl.h (+1) 
- (modified) llvm/lib/IR/Attributes.cpp (+8) 
- (modified) llvm/lib/Transforms/Scalar/SROA.cpp (+92-34) 
- (added) llvm/test/Transforms/SROA/scalable-vectors-with-known-vscale.ll 
(+248) 
- (modified) llvm/test/Transforms/SROA/scalable-vectors.ll (+142) 


``diff
diff --git a/clang/test/CodeGen/RISCV/attr-riscv-rvv-vector-bits-less-8-call.c 
b/clang/test/CodeGen/RISCV/attr-riscv-rvv-vector-bits-less-8-call.c
index e2f02dc64f766..66fd466eccfef 100644
--- a/clang/test/CodeGen/RISCV/attr-riscv-rvv-vector-bits-less-8-call.c
+++ b/clang/test/CodeGen/RISCV/attr-riscv-rvv-vector-bits-less-8-call.c
@@ -26,11 +26,15 @@ typedef vbool64_t fixed_bool64_t 
__attribute__((riscv_rvv_vector_bits(__riscv_v_
 //
 // CHECK-128-LABEL: @call_bool32_ff(
 // CHECK-128-NEXT:  entry:
+// CHECK-128-NEXT:[[SAVED_VALUE:%.*]] = alloca <1 x i8>, align 1
+// CHECK-128-NEXT:[[SAVED_VALUE3:%.*]] = alloca <1 x i8>, align 1
 // CHECK-128-NEXT:[[SAVED_VALUE4:%.*]] = alloca , align 1
 // CHECK-128-NEXT:[[RETVAL_COERCE:%.*]] = alloca , align 1
-// CHECK-128-NEXT:[[TMP0:%.*]] = tail call  
@llvm.riscv.vmand.nxv2i1.i64( [[OP1_COERCE:%.*]],  [[OP2_COERCE:%.*]], i64 4)
-// CHECK-128-NEXT:store  [[TMP0]], ptr [[SAVED_VALUE4]], 
align 1, !tbaa [[TBAA6:![0-9]+]]
-// CHECK-128-NEXT:[[TMP1:%.*]] = load <1 x i8>, ptr [[SAVED_VALUE4]], 
align 1, !tbaa [[TBAA10:![0-9]+]]
+// CHECK-128-NEXT:
[[SAVED_VALUE_0_SAVED_VALUE_0_SAVED_VALUE_0_SAVED_VALUE_0_:%.*]] = load , ptr [[SAVED_VALUE]], align 1, !tbaa [[TBAA6:![0-9]+]]
+// CHECK-128-NEXT:
[[SAVED_VALUE3_0_SAVED_VALUE3_0_SAVED_VALUE3_0_SAVED_VALUE3_0_:%.*]] = load 
, ptr [[SAVED_VALUE3]], align 1, !tbaa [[TBAA6]]
+// CHECK-128-NEXT:[[TMP0:%.*]] = tail call  
@llvm.riscv.vmand.nxv2i1.i64( 
[[SAVED_VALUE_0_SAVED_VALUE_0_SAVED_VALUE_0_SAVED_VALUE_0_]],  
[[SAVED_VALUE3_0_SAVED_VALUE3_0_SAVED_VALUE3_0_SAVED_VALUE3_0_]], i64 4)
+// CHECK-128-NEXT:store  [[TMP0]], ptr [[SAVED_VALUE4]], 
align 1, !tbaa [[TBAA9:![0-9]+]]
+// CHECK-128-NEXT:[[TMP1:%.*]] = load <1 x i8>, ptr [[SAVED_VALUE4]], 
align 1, !tbaa [[TBAA6]]
 // CHECK-128-NEXT:store <1 x i8> [[TMP1]], ptr [[RETVAL_COERCE]], align 1
 // CHECK-128-NEXT:[[TMP2:%.*]] = load , ptr 
[[RETVAL_COERCE]], align 1
 // CHECK-128-NEXT:ret  [[TMP2]]
@@ -52,11 +56,15 @@ fixed_bool32_t call_bool32_ff(fixed_bool32_t op1, 
fixed_bool32_t op2) {
 //
 // CHECK-128-LABEL: @call_bool64_ff(
 // CHECK-128-NEXT:  entry:
+// CHECK-128-NEXT:[[SAVED_VALUE:%.*]] = alloca <1 x i8>, align 1
+// CHECK-128-NEXT:[[SAVED_VALUE3:%.*]] = alloca <1 x i8>, align 1
 // CHECK-128-NEXT:[[SAVED_VALUE4:%.*]] = alloca , align 1
 // CHECK-128-NEXT:[[RETVAL_COERCE:%.*]] = alloca , align 1
-// CHECK-128-NEXT:[[TMP0:%.*]] = tail call  
@llvm.riscv.vmand.nxv1i1.i64( [[OP1_COERCE:%.*]],  [[OP2_COERCE:%.*]], i64 2)
+// CHECK-128-NEXT:
[[SAVED_VALUE_0_SAVED_VALUE_0_SAVED_VALUE_0_SAVED_VALUE_0_:%.*]] = load , ptr [[SAVED_VALUE]], align 1, !tbaa [[TBAA6]]
+// CHECK-128-NEXT:
[[SAVED_VALUE3_0_SAVED_VALUE3_0_SAVED_VALUE3_0_SAVED_VALUE3_0_:%.*]] = load 
, ptr [[SAVED_VALUE3]], align 1, !tbaa [[TBAA6]]
+// CHECK-128-NEXT:[[TMP0:%.*]] = tail call  
@llvm.riscv.vmand.nxv1i1.i64( 
[[SAVED_VALUE_0_SAVED_VALUE_0_SAVED_VALUE_0_SAVED_VALUE_0_]],  
[[SAVED_VALUE3_0_SAVED_VALUE3_0_SAVED_VALUE3_0_SAVED_VALUE3_0_]], i64 2)
 // CHECK-128-NEXT:store  [[TMP0]], ptr [[SAVED_VALUE4]], 
align 1, !tbaa [[TBAA11:![0-9]+]]
-// CHECK-128-NEXT:[[TMP1:%.*]] = load <1 x i8>, ptr [[SAVED_VALUE4]], 
align 1, !tbaa [[TBAA10]]
+// CHECK-128-NEXT:[[TMP1:%.*]] = load <1 x i8>, ptr [[SAVED_VALUE4]], 
align 1, !tbaa [[TBAA6]]
 // CHECK-128-NEXT:store <1 x i8> [[TMP1]], ptr [[RETVAL_COERCE]], align 1
 // CHECK-128-NEXT:[[TMP2:%.*]] = load , ptr 
[[RETVAL_COERCE]], align 1
 // CHECK-128-NEXT:ret  [[TMP2]]
@@ -82,11 +90,13 @@ fixed_bool64_t call_bool64_ff(fixed_bool64_t op1, 
fixed_bool64_t op2) {
 //
 // CHECK-128-LABEL: @call_bool32_fs(
 

[clang] [CIR] Upstream basic support for sizeof and alignof (PR #130847)

2025-03-12 Thread Erich Keane via cfe-commits


@@ -148,3 +150,27 @@ mlir::Value ScalarExprEmitter::VisitCastExpr(CastExpr *ce) 
{
   }
   return {};
 }
+
+/// Return the size or alignment of the type of argument of the sizeof
+/// expression as an integer.
+mlir::Value ScalarExprEmitter::VisitUnaryExprOrTypeTraitExpr(
+const UnaryExprOrTypeTraitExpr *e) {
+  const QualType typeToSize = e->getTypeOfArgument();
+  if (e->getKind() == UETT_SizeOf) {
+if (const VariableArrayType *variableArrTy =
+cgf.getContext().getAsVariableArrayType(typeToSize)) {
+  cgf.getCIRGenModule().errorNYI(e->getSourceRange(),

erichkeane wrote:

I think instead that after each of these `errorNYI` diagnostics, we are better 
just returning a constant value that is reasonably sensible.  A `1` or a 
`ptr-size` both seem reasonable to me.

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


[clang] [NFC][analyzer] Rename `CheckerBase::getCheckerName` to `getName` (PR #130953)

2025-03-12 Thread Balazs Benics via cfe-commits


@@ -41,19 +41,19 @@ class BugType {
 Checker(nullptr), SuppressOnSink(SuppressOnSink) {}
   BugType(const CheckerBase *Checker, StringRef Desc,
   StringRef Cat = categories::LogicError, bool SuppressOnSink = false)
-  : CheckerName(Checker->getCheckerName()), Description(Desc),
-Category(Cat), Checker(Checker), SuppressOnSink(SuppressOnSink) {}
+  : CheckerName(), Description(Desc), Category(Cat), Checker(Checker),

steakhal wrote:

What does this `CheckerName` initialize?

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


[clang] [CIR] Upstream basic support for ArrayType (PR #130502)

2025-03-12 Thread Erich Keane via cfe-commits

https://github.com/erichkeane commented:

My concern is still not fixed, and Andy/Bruno still have comments here, so I 
don't believe this to be ready yet.

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


[clang] [CIR] Upstream basic support for ArrayType (PR #130502)

2025-03-12 Thread Erich Keane via cfe-commits

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


[clang] [CIR] Upstream basic support for ArrayType (PR #130502)

2025-03-12 Thread Erich Keane via cfe-commits


@@ -33,6 +33,14 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
   llvm_unreachable("NYI: PPC double-double format for long double");
 llvm_unreachable("Unsupported format for long double");
   }
+
+  bool isSized(mlir::Type ty) {
+if (mlir::isa(ty))
+  return true;
+assert(0 && "Unimplemented size for type");

erichkeane wrote:

Still is an assert

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


[clang-tools-extra] [clang-tidy] detect explicit casting within modernize-use-default-member-init (PR #129408)

2025-03-12 Thread via cfe-commits


@@ -158,6 +158,10 @@ Changes in existing checks
   ` check by matching
   ``constexpr`` and ``static`` values on member initialization.
 
+- Improved :doc:`modernize-use-default-member-init
+  ` check by detecting
+  explicit casting of built-in types within member list initialization.

EugeneZelenko wrote:

Please merge with previous entry.

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


[clang] [flang] [flang] Add support for -f[no-]verbose-asm (PR #130788)

2025-03-12 Thread Tom Eccles via cfe-commits

https://github.com/tblah updated 
https://github.com/llvm/llvm-project/pull/130788

>From 5d3c1cc1d40b308b93cc47c78c6c3ca677f55155 Mon Sep 17 00:00:00 2001
From: Tom Eccles 
Date: Tue, 11 Mar 2025 15:54:35 +
Subject: [PATCH 1/3] [flang] Add support for -f[no-]verbose-asm

This flag provides extra commentary in the assembly output. It is in
CodeGenOptions to match what is done in clang, even though the backend
treats it as a target option.
---
 clang/include/clang/Driver/Options.td   |  5 +++--
 clang/lib/Driver/ToolChains/Flang.cpp   |  3 ++-
 flang/include/flang/Frontend/CodeGenOptions.def |  2 ++
 flang/lib/Frontend/CompilerInvocation.cpp   |  4 
 flang/lib/Frontend/FrontendActions.cpp  |  2 ++
 flang/test/Driver/verbose-asm.f90   | 16 
 6 files changed, 29 insertions(+), 3 deletions(-)
 create mode 100644 flang/test/Driver/verbose-asm.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index e69cd6b833c3a..ac6392f92f311 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3467,7 +3467,7 @@ defm use_cxa_atexit : BoolFOption<"use-cxa-atexit",
   PosFlag>;
 def fno_unwind_tables : Flag<["-"], "fno-unwind-tables">, Group;
 def fno_verbose_asm : Flag<["-"], "fno-verbose-asm">, Group,
-  Visibility<[ClangOption, CC1Option]>,
+  Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
   MarshallingInfoNegativeFlag>;
 def fno_working_directory : Flag<["-"], "fno-working-directory">, 
Group;
 def fobjc_arc : Flag<["-"], "fobjc-arc">, Group,
@@ -4142,7 +4142,8 @@ defm use_init_array : BoolFOption<"use-init-array",
   PosFlag>;
 def fno_var_tracking : Flag<["-"], "fno-var-tracking">, 
Group;
 def fverbose_asm : Flag<["-"], "fverbose-asm">, Group,
-  HelpText<"Generate verbose assembly output">;
+  HelpText<"Generate verbose assembly output">,
+  Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>;
 def dA : Flag<["-"], "dA">, Alias;
 defm visibility_from_dllstorageclass : 
BoolFOption<"visibility-from-dllstorageclass",
   LangOpts<"VisibilityFromDLLStorageClass">, DefaultFalse,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index d4fea633d0edf..09b77b4aab03d 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -172,7 +172,8 @@ void Flang::addCodegenOptions(const ArgList &Args,
options::OPT_finit_global_zero,
options::OPT_fno_init_global_zero, 
options::OPT_ftime_report,
options::OPT_ftime_report_EQ, options::OPT_funroll_loops,
-   options::OPT_fno_unroll_loops});
+   options::OPT_fno_unroll_loops, options::OPT_fverbose_asm,
+   options::OPT_fno_verbose_asm});
 }
 
 void Flang::addPicOptions(const ArgList &Args, ArgStringList &CmdArgs) const {
diff --git a/flang/include/flang/Frontend/CodeGenOptions.def 
b/flang/include/flang/Frontend/CodeGenOptions.def
index 44cb5a2cdd497..d2ff06d5fe08a 100644
--- a/flang/include/flang/Frontend/CodeGenOptions.def
+++ b/flang/include/flang/Frontend/CodeGenOptions.def
@@ -42,5 +42,7 @@ ENUM_CODEGENOPT(DebugInfo,  
llvm::codegenoptions::DebugInfoKind, 4,  llvm::codeg
 ENUM_CODEGENOPT(VecLib, llvm::driver::VectorLibrary, 3, 
llvm::driver::VectorLibrary::NoLibrary) ///< Vector functions library to use
 ENUM_CODEGENOPT(FramePointer, llvm::FramePointerKind, 2, 
llvm::FramePointerKind::None) ///< Enable the usage of frame pointers
 
+CODEGENOPT(AsmVerbose, 1, 0)
+
 #undef CODEGENOPT
 #undef ENUM_CODEGENOPT
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index 8b07a50824899..5451006960e8b 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -254,6 +254,10 @@ static void 
parseCodeGenArgs(Fortran::frontend::CodeGenOptions &opts,
   clang::driver::options::OPT_fno_unroll_loops,
   (opts.OptimizationLevel > 1));
 
+  if (args.hasFlag(clang::driver::options::OPT_fverbose_asm,
+   clang::driver::options::OPT_fno_verbose_asm, false))
+opts.AsmVerbose = 1;
+
   opts.AliasAnalysis = opts.OptimizationLevel > 0;
 
   // -mframe-pointer=none/non-leaf/all option.
diff --git a/flang/lib/Frontend/FrontendActions.cpp 
b/flang/lib/Frontend/FrontendActions.cpp
index 94de376aaf7d6..0ef2708bb42fb 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -1284,6 +1284,8 @@ void CodeGenAction::executeAction() {
   // given on the command-line).
   llvm::TargetMachine &targetMachine = ci.getTargetMachine();
 
+  targetMachine.Options.MCOptions.AsmVerbose = codeGenOpts.AsmVerbose;
+
   const llvm::Triple &theTriple = targetMachine.getTargetTriple();
 
   if (llvmModule->getTargetTriple() != theTriple) {
diff --git a/flang/t

  1   2   3   4   5   6   >