[clang] [llvm] Tentative fix for not removing newly internal functions (PR #106146)

2024-09-19 Thread Greg Roth via cfe-commits

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

>From 1e39029007dee5825810965fa39f26996ec9b7aa Mon Sep 17 00:00:00 2001
From: Greg Roth 
Date: Sun, 25 Aug 2024 12:00:03 -0600
Subject: [PATCH] [DirectX] Remove trivially dead functions at linkage finalize

Functions are not removed even when made internal by DXILFinalizeLinkage
The removal code is called from alwaysinliner and globalopt, which are
invoked too early to remove functions made internal by this pass.

This adds a check similar to that in alwaysinliner that removes
trivially dead functions after being marked internal. It refactors
that code a bit to make it simpler including reversing what is
stored in the work queue.

Tests both the pass in isolation and the full inlining, linkage
finalization, and function removal process.

Fixes #106139
---
 .../CodeGenHLSL/remove-internal-unused.hlsl   | 47 +++
 .../Target/DirectX/DXILFinalizeLinkage.cpp| 16 ++--
 .../DirectX/finalize-linkage-remove-dead.ll   | 80 +++
 3 files changed, 135 insertions(+), 8 deletions(-)
 create mode 100644 clang/test/CodeGenHLSL/remove-internal-unused.hlsl
 create mode 100644 llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll

diff --git a/clang/test/CodeGenHLSL/remove-internal-unused.hlsl 
b/clang/test/CodeGenHLSL/remove-internal-unused.hlsl
new file mode 100644
index 00..85c114618a1e0e
--- /dev/null
+++ b/clang/test/CodeGenHLSL/remove-internal-unused.hlsl
@@ -0,0 +1,47 @@
+// RUN: %clang -target dxil-pc-shadermodel6.0-compute -S -o - %s | FileCheck %s
+// RUN: %clang -target dxil-pc-shadermodel6.3-library -S -o - %s | FileCheck %s
+
+// Verify that internal linkage unused functions are removed
+
+RWBuffer buf;
+
+// Never called functions should be removed.
+// CHECK-NOT: define{{.*}}uncalledFor
+void uncalledFor() {
+ buf[1] = 1;
+}
+
+// Never called but exported functions should remain.
+// CHECK: define void @"?exported@@YAXXZ"()
+export void exported() {
+ buf[1] = 1;
+}
+
+// Never called but noinlined functions should remain.
+// CHECK: define internal void @"?noinlined@@YAXXZ"()
+__attribute__((noinline)) void noinlined() {
+ buf[1] = 1;
+}
+
+// Called functions marked noinline should remain.
+// CHECK: define internal void @"?calledAndNoinlined@@YAXXZ"()
+__attribute__((noinline)) void calledAndNoinlined() {
+ buf[1] = 1;
+}
+
+// Called functions that get inlined by default should be removed.
+// CHECK-NOT: define{{.*}}calledAndInlined
+void calledAndInlined() {
+ buf[1] = 1;
+}
+
+
+// Entry point functions should remain.
+// CHECK: define{{.*}}main
+[numthreads(1,1,1)]
+[shader("compute")]
+void main() {
+ calledAndInlined();
+ calledAndNoinlined();
+ buf[0] = 0;
+}
\ No newline at end of file
diff --git a/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp 
b/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp
index d315d9bd16f439..59b30f965bf951 100644
--- a/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp
+++ b/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp
@@ -19,20 +19,20 @@
 using namespace llvm;
 
 static bool finalizeLinkage(Module &M) {
-  SmallPtrSet EntriesAndExports;
+  SmallPtrSet Funcs;
 
   // Find all entry points and export functions
   for (Function &EF : M.functions()) {
-if (!EF.hasFnAttribute("hlsl.shader") && !EF.hasFnAttribute("hlsl.export"))
+if (EF.hasFnAttribute("hlsl.shader") || EF.hasFnAttribute("hlsl.export"))
   continue;
-EntriesAndExports.insert(&EF);
+Funcs.insert(&EF);
   }
 
-  for (Function &F : M.functions()) {
-if (F.getLinkage() == GlobalValue::ExternalLinkage &&
-!EntriesAndExports.contains(&F)) {
-  F.setLinkage(GlobalValue::InternalLinkage);
-}
+  for (Function *F : Funcs) {
+if (F->getLinkage() == GlobalValue::ExternalLinkage)
+  F->setLinkage(GlobalValue::InternalLinkage);
+if (F->hasFnAttribute(Attribute::AlwaysInline) && F->isDefTriviallyDead())
+  M.getFunctionList().erase(F);
   }
 
   return false;
diff --git a/llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll 
b/llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll
new file mode 100644
index 00..df5934355664d1
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll
@@ -0,0 +1,80 @@
+; RUN: opt -S -dxil-finalize-linkage 
-mtriple=dxil-unknown-shadermodel6.5-compute %s | FileCheck %s
+; RUN: llc %s --filetype=asm -o - | FileCheck %s
+
+target triple = "dxilv1.5-pc-shadermodel6.5-compute"
+
+; Confirm that DXILFinalizeLinkage will remove functions that have compatible
+; linkage and are not called from anywhere. This should be any function that
+; is not explicitly marked noinline or export and is not an entry point.
+
+; Not called nor marked with any linking or inlining attributes.
+; CHECK-NOT: define {{.*}}doNothingNothing
+define void @"?doNothingNothing@@YAXXZ"() #0 {
+entry:
+  ret void
+}
+
+; Marked internal, this should be removed.
+; CHECK-NOT: def

[clang] [DebugInfo] Correct the line attribution for IF branches (PR #108300)

2024-09-19 Thread David Blaikie via cfe-commits

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

Fair enough

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


[clang] [llvm] Tentative fix for not removing newly internal functions (PR #106146)

2024-09-19 Thread Greg Roth via cfe-commits

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

>From 70d4b5de3e9a214d50560f047b334de7f0818167 Mon Sep 17 00:00:00 2001
From: Greg Roth 
Date: Sun, 25 Aug 2024 12:00:03 -0600
Subject: [PATCH] [DirectX] Remove trivially dead functions at linkage finalize

Functions are not removed even when made internal by DXILFinalizeLinkage
The removal code is called from alwaysinliner and globalopt, which are
invoked too early to remove functions made internal by this pass.

This adds a check similar to that in alwaysinliner that removes
trivially dead functions after being marked internal. It refactors
that code a bit to make it simpler including reversing what is
stored in the work queue.

Tests both the pass in isolation and the full inlining, linkage
finalization, and function removal process.

Fixes #106139
---
 .../CodeGenHLSL/remove-internal-unused.hlsl   | 47 +++
 .../Target/DirectX/DXILFinalizeLinkage.cpp| 16 ++--
 .../DirectX/finalize-linkage-remove-dead.ll   | 80 +++
 3 files changed, 135 insertions(+), 8 deletions(-)
 create mode 100644 clang/test/CodeGenHLSL/remove-internal-unused.hlsl
 create mode 100644 llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll

diff --git a/clang/test/CodeGenHLSL/remove-internal-unused.hlsl 
b/clang/test/CodeGenHLSL/remove-internal-unused.hlsl
new file mode 100644
index 00..85c114618a1e0e
--- /dev/null
+++ b/clang/test/CodeGenHLSL/remove-internal-unused.hlsl
@@ -0,0 +1,47 @@
+// RUN: %clang -target dxil-pc-shadermodel6.0-compute -S -o - %s | FileCheck %s
+// RUN: %clang -target dxil-pc-shadermodel6.3-library -S -o - %s | FileCheck %s
+
+// Verify that internal linkage unused functions are removed
+
+RWBuffer buf;
+
+// Never called functions should be removed.
+// CHECK-NOT: define{{.*}}uncalledFor
+void uncalledFor() {
+ buf[1] = 1;
+}
+
+// Never called but exported functions should remain.
+// CHECK: define void @"?exported@@YAXXZ"()
+export void exported() {
+ buf[1] = 1;
+}
+
+// Never called but noinlined functions should remain.
+// CHECK: define internal void @"?noinlined@@YAXXZ"()
+__attribute__((noinline)) void noinlined() {
+ buf[1] = 1;
+}
+
+// Called functions marked noinline should remain.
+// CHECK: define internal void @"?calledAndNoinlined@@YAXXZ"()
+__attribute__((noinline)) void calledAndNoinlined() {
+ buf[1] = 1;
+}
+
+// Called functions that get inlined by default should be removed.
+// CHECK-NOT: define{{.*}}calledAndInlined
+void calledAndInlined() {
+ buf[1] = 1;
+}
+
+
+// Entry point functions should remain.
+// CHECK: define{{.*}}main
+[numthreads(1,1,1)]
+[shader("compute")]
+void main() {
+ calledAndInlined();
+ calledAndNoinlined();
+ buf[0] = 0;
+}
\ No newline at end of file
diff --git a/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp 
b/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp
index d315d9bd16f439..59b30f965bf951 100644
--- a/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp
+++ b/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp
@@ -19,20 +19,20 @@
 using namespace llvm;
 
 static bool finalizeLinkage(Module &M) {
-  SmallPtrSet EntriesAndExports;
+  SmallPtrSet Funcs;
 
   // Find all entry points and export functions
   for (Function &EF : M.functions()) {
-if (!EF.hasFnAttribute("hlsl.shader") && !EF.hasFnAttribute("hlsl.export"))
+if (EF.hasFnAttribute("hlsl.shader") || EF.hasFnAttribute("hlsl.export"))
   continue;
-EntriesAndExports.insert(&EF);
+Funcs.insert(&EF);
   }
 
-  for (Function &F : M.functions()) {
-if (F.getLinkage() == GlobalValue::ExternalLinkage &&
-!EntriesAndExports.contains(&F)) {
-  F.setLinkage(GlobalValue::InternalLinkage);
-}
+  for (Function *F : Funcs) {
+if (F->getLinkage() == GlobalValue::ExternalLinkage)
+  F->setLinkage(GlobalValue::InternalLinkage);
+if (F->hasFnAttribute(Attribute::AlwaysInline) && F->isDefTriviallyDead())
+  M.getFunctionList().erase(F);
   }
 
   return false;
diff --git a/llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll 
b/llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll
new file mode 100644
index 00..df5934355664d1
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll
@@ -0,0 +1,80 @@
+; RUN: opt -S -dxil-finalize-linkage 
-mtriple=dxil-unknown-shadermodel6.5-compute %s | FileCheck %s
+; RUN: llc %s --filetype=asm -o - | FileCheck %s
+
+target triple = "dxilv1.5-pc-shadermodel6.5-compute"
+
+; Confirm that DXILFinalizeLinkage will remove functions that have compatible
+; linkage and are not called from anywhere. This should be any function that
+; is not explicitly marked noinline or export and is not an entry point.
+
+; Not called nor marked with any linking or inlining attributes.
+; CHECK-NOT: define {{.*}}doNothingNothing
+define void @"?doNothingNothing@@YAXXZ"() #0 {
+entry:
+  ret void
+}
+
+; Marked internal, this should be removed.
+; CHECK-NOT: def

[clang] [Clang] - Add libclangSerialization to clang driver unittests (PR #109329)

2024-09-19 Thread via cfe-commits

Prabhuk wrote:

I am holding off of on my revert PR to see if the current build bot with this 
patch goes through successfully! Thanks again Pranav.

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


[clang] 7db641a - [clang] Don't call raw_string_ostream::flush() (NFC)

2024-09-19 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2024-09-19T17:18:10-05:00
New Revision: 7db641af13670aa1f1ecd3106eda3ce447afd752

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

LOG: [clang] Don't call raw_string_ostream::flush() (NFC)

Don't call raw_string_ostream::flush(), which is essentially a no-op.
As specified in the docs, raw_string_ostream is always unbuffered

Added: 


Modified: 
clang/include/clang/AST/StmtDataCollectors.td
clang/lib/AST/DataCollection.cpp
clang/lib/AST/TemplateName.cpp
clang/lib/Basic/Module.cpp
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/CodeGen/CodeGenPGO.cpp
clang/lib/Driver/Job.cpp
clang/lib/Driver/ToolChains/HIPUtility.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaLookup.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
clang/lib/Tooling/CommonOptionsParser.cpp
clang/lib/Tooling/Core/Replacement.cpp
clang/lib/Tooling/Refactoring/AtomicChange.cpp
clang/lib/Tooling/Transformer/Stencil.cpp
clang/unittests/Basic/SarifTest.cpp
clang/unittests/Frontend/TextDiagnosticTest.cpp

Removed: 




diff  --git a/clang/include/clang/AST/StmtDataCollectors.td 
b/clang/include/clang/AST/StmtDataCollectors.td
index 922dd2a20d59c2..abf4b5f34d3491 100644
--- a/clang/include/clang/AST/StmtDataCollectors.td
+++ b/clang/include/clang/AST/StmtDataCollectors.td
@@ -55,7 +55,6 @@ class CallExpr {
   // Add a padding character so that 'foo()' != 'foo()'.
   OS << '\n';
 }
-OS.flush();
 
 addData(ArgString);
   }

diff  --git a/clang/lib/AST/DataCollection.cpp 
b/clang/lib/AST/DataCollection.cpp
index d3f2c22e9cc3a8..786821ded98c39 100644
--- a/clang/lib/AST/DataCollection.cpp
+++ b/clang/lib/AST/DataCollection.cpp
@@ -41,7 +41,6 @@ std::string getMacroStack(SourceLocation Loc, ASTContext 
&Context) {
 printMacroName(MacroStackStream, Context, Loc);
 Loc = SM.getImmediateMacroCallerLoc(Loc);
   }
-  MacroStackStream.flush();
   return MacroStack;
 }
 

diff  --git a/clang/lib/AST/TemplateName.cpp b/clang/lib/AST/TemplateName.cpp
index 044a1a92469aca..c27b07ad6c6f87 100644
--- a/clang/lib/AST/TemplateName.cpp
+++ b/clang/lib/AST/TemplateName.cpp
@@ -439,6 +439,5 @@ const StreamingDiagnostic &clang::operator<<(const 
StreamingDiagnostic &DB,
   OS << '\'';
   N.print(OS, PrintingPolicy(LO));
   OS << '\'';
-  OS.flush();
   return DB << NameStr;
 }

diff  --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp
index 90b7b0d24bb6a0..fee372bce3a367 100644
--- a/clang/lib/Basic/Module.cpp
+++ b/clang/lib/Basic/Module.cpp
@@ -252,7 +252,6 @@ std::string Module::getFullModuleName(bool 
AllowStringLiterals) const {
 
   llvm::raw_string_ostream Out(Result);
   printModuleId(Out, Names.rbegin(), Names.rend(), AllowStringLiterals);
-  Out.flush();
 
   return Result;
 }

diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 8492e5ab73e183..fa49763e312f13 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -352,7 +352,6 @@ static std::string 
flattenClangCommandLine(ArrayRef Args,
 llvm::sys::printArg(OS, Arg, /*Quote=*/true);
 PrintedOneArg = true;
   }
-  OS.flush();
   return FlatCmdLine;
 }
 

diff  --git a/clang/lib/CodeGen/CodeGenPGO.cpp 
b/clang/lib/CodeGen/CodeGenPGO.cpp
index 2bc0fe909efd14..b745ad37fc96b1 100644
--- a/clang/lib/CodeGen/CodeGenPGO.cpp
+++ b/clang/lib/CodeGen/CodeGenPGO.cpp
@@ -1134,7 +1134,6 @@ void CodeGenPGO::emitCounterRegionMapping(const Decl *D) {
   *CGM.getCoverageMapping(), CGM.getContext().getSourceManager(),
   CGM.getLangOpts(), RegionCounterMap.get(), RegionMCDCState.get());
   MappingGen.emitCounterMapping(D, OS);
-  OS.flush();
 
   if (CoverageMapping.empty())
 return;
@@ -1155,7 +1154,6 @@ CodeGenPGO::emitEmptyCounterMapping(const Decl *D, 
StringRef Name,
 CGM.getContext().getSourceManager(),
 CGM.getLangOpts());
   MappingGen.emitEmptyMapping(D, OS);
-  OS.flush();
 
   if (CoverageMapping.empty())
 return;

diff  --git a/clang/lib/Driver/Job.cpp b/clang/lib/Driver/Job.cpp
index a6c1581be79626..fe2f7242b04a51 100644
--- a/clang/lib/Driver/Job.cpp
+++ b/clang/lib/Driver/Job.cpp
@@ -343,7 +343,6 @@ int Command::Execute(ArrayRef> 
Redirects,
 writeResponseFile(SS);
 buildArgvForResponseFile(Argv);
 Argv.push_back(nullptr);
-SS.flush();
 
 // Save the response file in the appropriate encoding
 if (std::error_code EC = writeFileWithEncoding(

diff  --git a/clang/lib/Driver/ToolChains/HIPUtility.cpp 
b/clang/lib/Driver/ToolChains/HIPUtility.cpp
index 1b707376dea819..b3adfe654

[clang] [llvm] [X86] Use X86AS::GS and X86AS::FS instead of 256 and 257. NFC (PR #109342)

2024-09-19 Thread Craig Topper via cfe-commits

https://github.com/topperc created 
https://github.com/llvm/llvm-project/pull/109342

None

>From bc0a290b1e139f32225bc55fc99027b34c4f1bd6 Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Thu, 19 Sep 2024 15:13:55 -0700
Subject: [PATCH] [X86] Use X86AS::GS and X86AS::FS instead of 256 and 257. NFC

---
 clang/lib/CodeGen/CMakeLists.txt| 1 +
 llvm/lib/Target/X86/X86ISelLowering.cpp | 6 +++---
 llvm/lib/Target/X86/X86ISelLoweringCall.cpp | 5 +++--
 llvm/lib/Target/X86/X86WinEHState.cpp   | 4 ++--
 4 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/clang/lib/CodeGen/CMakeLists.txt b/clang/lib/CodeGen/CMakeLists.txt
index aa0c871c5352a8..868ec847b9634b 100644
--- a/clang/lib/CodeGen/CMakeLists.txt
+++ b/clang/lib/CodeGen/CMakeLists.txt
@@ -144,6 +144,7 @@ add_clang_library(clangCodeGen
   VarBypassDetector.cpp
 
   DEPENDS
+  vt_gen
   intrinsics_gen
   ClangDriverOptions
   # These generated headers are included transitively.
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp 
b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 9637e96c21cf52..b9c9e5703849ae 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -18925,7 +18925,7 @@ static SDValue LowerToTLSExecModel(GlobalAddressSDNode 
*GA, SelectionDAG &DAG,
 
   // Get the Thread Pointer, which is %gs:0 (32-bit) or %fs:0 (64-bit).
   Value *Ptr = Constant::getNullValue(
-  PointerType::get(*DAG.getContext(), is64Bit ? 257 : 256));
+  PointerType::get(*DAG.getContext(), is64Bit ? X86AS::FS : X86AS::GS));
 
   SDValue ThreadPointer =
   DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), DAG.getIntPtrConstant(0, dl),
@@ -19070,8 +19070,8 @@ X86TargetLowering::LowerGlobalTLSAddress(SDValue Op, 
SelectionDAG &DAG) const {
 // %gs:0x58 (64-bit). On MinGW, __tls_array is not available, so directly
 // use its literal value of 0x2C.
 Value *Ptr = Constant::getNullValue(
-Subtarget.is64Bit() ? PointerType::get(*DAG.getContext(), 256)
-: PointerType::get(*DAG.getContext(), 257));
+Subtarget.is64Bit() ? PointerType::get(*DAG.getContext(), X86AS::GS)
+: PointerType::get(*DAG.getContext(), X86AS::FS));
 
 SDValue TlsArray = Subtarget.is64Bit()
? DAG.getIntPtrConstant(0x58, dl)
diff --git a/llvm/lib/Target/X86/X86ISelLoweringCall.cpp 
b/llvm/lib/Target/X86/X86ISelLoweringCall.cpp
index 43dcaefc623bea..b9124658028da4 100644
--- a/llvm/lib/Target/X86/X86ISelLoweringCall.cpp
+++ b/llvm/lib/Target/X86/X86ISelLoweringCall.cpp
@@ -524,8 +524,9 @@ X86TargetLowering::findRepresentativeClass(const 
TargetRegisterInfo *TRI,
 
 unsigned X86TargetLowering::getAddressSpace() const {
   if (Subtarget.is64Bit())
-return (getTargetMachine().getCodeModel() == CodeModel::Kernel) ? 256 : 
257;
-  return 256;
+return (getTargetMachine().getCodeModel() == CodeModel::Kernel) ? X86AS::GS
+: 
X86AS::FS;
+  return X86AS::GS;
 }
 
 static bool hasStackGuardSlotTLS(const Triple &TargetTriple) {
diff --git a/llvm/lib/Target/X86/X86WinEHState.cpp 
b/llvm/lib/Target/X86/X86WinEHState.cpp
index 578d653c1e0ada..963d613ddbfe7d 100644
--- a/llvm/lib/Target/X86/X86WinEHState.cpp
+++ b/llvm/lib/Target/X86/X86WinEHState.cpp
@@ -423,7 +423,7 @@ void WinEHStatePass::linkExceptionRegistration(IRBuilder<> 
&Builder,
   // Handler = Handler
   Builder.CreateStore(Handler, Builder.CreateStructGEP(LinkTy, Link, 1));
   // Next = [fs:00]
-  Constant *FSZero = Constant::getNullValue(PointerType::get(C, 257));
+  Constant *FSZero = Constant::getNullValue(PointerType::get(C, X86AS::FS));
   Value *Next = Builder.CreateLoad(PointerType::getUnqual(C), FSZero);
   Builder.CreateStore(Next, Builder.CreateStructGEP(LinkTy, Link, 0));
   // [fs:00] = Link
@@ -443,7 +443,7 @@ void 
WinEHStatePass::unlinkExceptionRegistration(IRBuilder<> &Builder) {
   // [fs:00] = Link->Next
   Value *Next = Builder.CreateLoad(PointerType::getUnqual(C),
Builder.CreateStructGEP(LinkTy, Link, 0));
-  Constant *FSZero = Constant::getNullValue(PointerType::get(C, 257));
+  Constant *FSZero = Constant::getNullValue(PointerType::get(C, X86AS::FS));
   Builder.CreateStore(Next, FSZero);
 }
 

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


[clang] [llvm] [X86] Use X86AS::GS and X86AS::FS instead of 256 and 257. NFC (PR #109342)

2024-09-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-x86

Author: Craig Topper (topperc)


Changes



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


4 Files Affected:

- (modified) clang/lib/CodeGen/CMakeLists.txt (+1) 
- (modified) llvm/lib/Target/X86/X86ISelLowering.cpp (+3-3) 
- (modified) llvm/lib/Target/X86/X86ISelLoweringCall.cpp (+3-2) 
- (modified) llvm/lib/Target/X86/X86WinEHState.cpp (+2-2) 


``diff
diff --git a/clang/lib/CodeGen/CMakeLists.txt b/clang/lib/CodeGen/CMakeLists.txt
index aa0c871c5352a8..868ec847b9634b 100644
--- a/clang/lib/CodeGen/CMakeLists.txt
+++ b/clang/lib/CodeGen/CMakeLists.txt
@@ -144,6 +144,7 @@ add_clang_library(clangCodeGen
   VarBypassDetector.cpp
 
   DEPENDS
+  vt_gen
   intrinsics_gen
   ClangDriverOptions
   # These generated headers are included transitively.
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp 
b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 9637e96c21cf52..b9c9e5703849ae 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -18925,7 +18925,7 @@ static SDValue LowerToTLSExecModel(GlobalAddressSDNode 
*GA, SelectionDAG &DAG,
 
   // Get the Thread Pointer, which is %gs:0 (32-bit) or %fs:0 (64-bit).
   Value *Ptr = Constant::getNullValue(
-  PointerType::get(*DAG.getContext(), is64Bit ? 257 : 256));
+  PointerType::get(*DAG.getContext(), is64Bit ? X86AS::FS : X86AS::GS));
 
   SDValue ThreadPointer =
   DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), DAG.getIntPtrConstant(0, dl),
@@ -19070,8 +19070,8 @@ X86TargetLowering::LowerGlobalTLSAddress(SDValue Op, 
SelectionDAG &DAG) const {
 // %gs:0x58 (64-bit). On MinGW, __tls_array is not available, so directly
 // use its literal value of 0x2C.
 Value *Ptr = Constant::getNullValue(
-Subtarget.is64Bit() ? PointerType::get(*DAG.getContext(), 256)
-: PointerType::get(*DAG.getContext(), 257));
+Subtarget.is64Bit() ? PointerType::get(*DAG.getContext(), X86AS::GS)
+: PointerType::get(*DAG.getContext(), X86AS::FS));
 
 SDValue TlsArray = Subtarget.is64Bit()
? DAG.getIntPtrConstant(0x58, dl)
diff --git a/llvm/lib/Target/X86/X86ISelLoweringCall.cpp 
b/llvm/lib/Target/X86/X86ISelLoweringCall.cpp
index 43dcaefc623bea..b9124658028da4 100644
--- a/llvm/lib/Target/X86/X86ISelLoweringCall.cpp
+++ b/llvm/lib/Target/X86/X86ISelLoweringCall.cpp
@@ -524,8 +524,9 @@ X86TargetLowering::findRepresentativeClass(const 
TargetRegisterInfo *TRI,
 
 unsigned X86TargetLowering::getAddressSpace() const {
   if (Subtarget.is64Bit())
-return (getTargetMachine().getCodeModel() == CodeModel::Kernel) ? 256 : 
257;
-  return 256;
+return (getTargetMachine().getCodeModel() == CodeModel::Kernel) ? X86AS::GS
+: 
X86AS::FS;
+  return X86AS::GS;
 }
 
 static bool hasStackGuardSlotTLS(const Triple &TargetTriple) {
diff --git a/llvm/lib/Target/X86/X86WinEHState.cpp 
b/llvm/lib/Target/X86/X86WinEHState.cpp
index 578d653c1e0ada..963d613ddbfe7d 100644
--- a/llvm/lib/Target/X86/X86WinEHState.cpp
+++ b/llvm/lib/Target/X86/X86WinEHState.cpp
@@ -423,7 +423,7 @@ void WinEHStatePass::linkExceptionRegistration(IRBuilder<> 
&Builder,
   // Handler = Handler
   Builder.CreateStore(Handler, Builder.CreateStructGEP(LinkTy, Link, 1));
   // Next = [fs:00]
-  Constant *FSZero = Constant::getNullValue(PointerType::get(C, 257));
+  Constant *FSZero = Constant::getNullValue(PointerType::get(C, X86AS::FS));
   Value *Next = Builder.CreateLoad(PointerType::getUnqual(C), FSZero);
   Builder.CreateStore(Next, Builder.CreateStructGEP(LinkTy, Link, 0));
   // [fs:00] = Link
@@ -443,7 +443,7 @@ void 
WinEHStatePass::unlinkExceptionRegistration(IRBuilder<> &Builder) {
   // [fs:00] = Link->Next
   Value *Next = Builder.CreateLoad(PointerType::getUnqual(C),
Builder.CreateStructGEP(LinkTy, Link, 0));
-  Constant *FSZero = Constant::getNullValue(PointerType::get(C, 257));
+  Constant *FSZero = Constant::getNullValue(PointerType::get(C, X86AS::FS));
   Builder.CreateStore(Next, FSZero);
 }
 

``




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


[clang] [Clang] - Add libclangSerialization to clang driver unittests (PR #109329)

2024-09-19 Thread via cfe-commits

Prabhuk wrote:

It seems like we are still seeing failures: 
https://lab.llvm.org/buildbot/#/builders/190/builds/6112


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


[clang] Revert "[Driver] Add toolchain for X86_64 UEFI target" (PR #109340)

2024-09-19 Thread via cfe-commits

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


[clang] d2df2e4 - Revert "[Driver] Add toolchain for X86_64 UEFI target" (#109340)

2024-09-19 Thread via cfe-commits

Author: Prabhuk
Date: 2024-09-19T15:28:07-07:00
New Revision: d2df2e41cae1413050935d6d27094569c29c473f

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

LOG: Revert "[Driver] Add toolchain for X86_64 UEFI target" (#109340)

Reverts llvm/llvm-project#76838

Appears to be causing failures in MAC builders. First reverting the
patch and will investigate after.

Added: 


Modified: 
clang/lib/Basic/Targets.cpp
clang/lib/Basic/Targets/OSTargets.h
clang/lib/Basic/Targets/X86.h
clang/lib/Driver/CMakeLists.txt
clang/lib/Driver/Driver.cpp
clang/unittests/Driver/ToolChainTest.cpp

Removed: 
clang/lib/Driver/ToolChains/UEFI.cpp
clang/lib/Driver/ToolChains/UEFI.h
clang/test/CodeGen/X86/uefi-data-layout.c
clang/test/Driver/uefi-constructed-args.c



diff  --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index 4917ef015941be..0b8e565345b6a4 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -613,9 +613,6 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple &Triple,
 case llvm::Triple::Solaris:
   return std::make_unique>(Triple,
Opts);
-case llvm::Triple::UEFI:
-  return std::make_unique(Triple, Opts);
-
 case llvm::Triple::Win32: {
   switch (Triple.getEnvironment()) {
   case llvm::Triple::Cygnus:

diff  --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index a83d6464e789d6..0a4f06967fff5a 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -778,21 +778,6 @@ class LLVM_LIBRARY_VISIBILITY ZOSTargetInfo : public 
OSTargetInfo {
   }
 };
 
-// UEFI target
-template 
-class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo {
-protected:
-  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
-MacroBuilder &Builder) const override {}
-
-public:
-  UEFITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
-  : OSTargetInfo(Triple, Opts) {
-this->WCharType = TargetInfo::UnsignedShort;
-this->WIntType = TargetInfo::UnsignedShort;
-  }
-};
-
 void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts,
MacroBuilder &Builder);
 

diff  --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index a99ae62984c7d5..79fd5867cf6673 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -814,43 +814,6 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public 
X86TargetInfo {
   }
 };
 
-// x86-64 UEFI target
-class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo
-: public UEFITargetInfo {
-public:
-  UEFIX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
-  : UEFITargetInfo(Triple, Opts) {
-this->TheCXXABI.set(TargetCXXABI::Microsoft);
-this->MaxTLSAlign = 8192u * this->getCharWidth();
-this->resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-"
-  "i64:64-i128:128-f80:128-n8:16:32:64-S128");
-  }
-
-  void getTargetDefines(const LangOptions &Opts,
-MacroBuilder &Builder) const override {
-getOSDefines(Opts, X86TargetInfo::getTriple(), Builder);
-  }
-
-  BuiltinVaListKind getBuiltinVaListKind() const override {
-return TargetInfo::CharPtrBuiltinVaList;
-  }
-
-  CallingConvCheckResult checkCallingConvention(CallingConv CC) const override 
{
-switch (CC) {
-case CC_C:
-case CC_Win64:
-  return CCCR_OK;
-default:
-  return CCCR_Warning;
-}
-  }
-
-  TargetInfo::CallingConvKind
-  getCallingConvKind(bool ClangABICompat4) const override {
-return CCK_MicrosoftWin64;
-  }
-};
-
 // x86-64 Windows target
 class LLVM_LIBRARY_VISIBILITY WindowsX86_64TargetInfo
 : public WindowsTargetInfo {

diff  --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt
index 4fd10bf671512f..32a4378ab499fa 100644
--- a/clang/lib/Driver/CMakeLists.txt
+++ b/clang/lib/Driver/CMakeLists.txt
@@ -78,7 +78,6 @@ add_clang_library(clangDriver
   ToolChains/Solaris.cpp
   ToolChains/SPIRV.cpp
   ToolChains/TCE.cpp
-  ToolChains/UEFI.cpp
   ToolChains/VEToolchain.cpp
   ToolChains/WebAssembly.cpp
   ToolChains/XCore.cpp

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 95723b9209d125..efe398dd531da7 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -45,7 +45,6 @@
 #include "ToolChains/SPIRV.h"
 #include "ToolChains/Solaris.h"
 #include "ToolChains/TCE.h"
-#include "ToolChains/UEFI.h"
 #include "ToolChains/VEToolchain.h"
 #include "ToolChains/WebAssembly.h"
 #include "ToolChains/XCore.h"
@@ -6417,9 +6416,6 @@ const ToolChain &Driver::getToolCh

[clang] [Clang] - Add libclangSerialization to clang driver unittests (PR #109329)

2024-09-19 Thread via cfe-commits

Prabhuk wrote:

I just merged my revert PR https://github.com/llvm/llvm-project/pull/109340 
I'll investigate further on the cause for the warning that shows up in the 
build bots causing the test failure

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


[clang] Revert "[Driver] Add toolchain for X86_64 UEFI target" (PR #109340)

2024-09-19 Thread via cfe-commits

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


[clang] [llvm] [RISCV][VCIX] Add vcix_state to GNU inline assembly register set (PR #106914)

2024-09-19 Thread Craig Topper via cfe-commits


@@ -44,7 +44,7 @@ ArrayRef RISCVTargetInfo::getGCCRegNames() 
const {
   "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
 
   // CSRs
-  "fflags", "frm", "vtype", "vl", "vxsat", "vxrm"
+  "fflags", "frm", "vtype", "vl", "vxsat", "vxrm", "sf_vcix_state"

topperc wrote:

@4vtomat we should override that function for this register.

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


[clang] [RISCV][FMV] Support target_version (PR #99040)

2024-09-19 Thread Craig Topper via cfe-commits


@@ -14270,9 +14270,16 @@ void 
ASTContext::getFunctionFeatureMap(llvm::StringMap &FeatureMap,
   Target->initFeatureMap(FeatureMap, getDiagnostics(), TargetCPU, 
Features);
 }
   } else if (const auto *TV = FD->getAttr()) {
-llvm::SmallVector Feats;
-TV->getFeatures(Feats);
-std::vector Features = getFMVBackendFeaturesFor(Feats);
+std::vector Features;
+if (Target->getTriple().isRISCV()) {
+  ParsedTargetAttr ParsedAttr = Target->parseTargetAttr(TV->getName());
+  Features.insert(Features.begin(), ParsedAttr.Features.begin(),
+  ParsedAttr.Features.end());
+} else {
+  llvm::SmallVector Feats;

topperc wrote:

Add an assert here that the triple is AArch64

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


[clang] [RISCV][FMV] Support target_version (PR #99040)

2024-09-19 Thread Craig Topper via cfe-commits


@@ -15501,8 +15511,10 @@ Decl *Sema::ActOnStartOfFunctionDef(Scope 
*FnBodyScope, Decl *D,
 FD->setInvalidDecl();
   }
   if (const auto *Attr = FD->getAttr()) {
-if (!Context.getTargetInfo().hasFeature("fmv") &&
-!Attr->isDefaultVersion()) {
+if (Context.getTargetInfo().getTriple().isRISCV()) {

topperc wrote:

Should we check AArch64 in the original `if` instead?

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


[clang] [RISCV][FMV] Support target_version (PR #99040)

2024-09-19 Thread Craig Topper via cfe-commits


@@ -4268,8 +4268,12 @@ void CodeGenModule::emitMultiVersionFunctions() {
   } else if (const auto *TVA = CurFD->getAttr()) {
 if (TVA->isDefaultVersion() && IsDefined)
   ShouldEmitResolver = true;
-TVA->getFeatures(Feats);
 llvm::Function *Func = createFunction(CurFD);
+if (getTarget().getTriple().isRISCV()) {
+  Feats.push_back(TVA->getName());
+} else {
+  TVA->getFeatures(Feats);

topperc wrote:

Add an assert here that the target is AArch64

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


[clang] [RISCV][FMV] Support target_version (PR #99040)

2024-09-19 Thread Craig Topper via cfe-commits


@@ -3056,6 +3056,45 @@ bool Sema::checkTargetVersionAttr(SourceLocation 
LiteralLoc, Decl *D,
   enum SecondParam { None };
   enum ThirdParam { Target, TargetClones, TargetVersion };
   llvm::SmallVector Features;
+  if (Context.getTargetInfo().getTriple().isRISCV()) {
+
+llvm::SmallVector AttrStrs;
+AttrStr.split(AttrStrs, ';');
+
+bool IsPriority = false;

topperc wrote:

`hasPriority` is a better name than `isPriority`

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


[clang] [RISCV][FMV] Support target_version (PR #99040)

2024-09-19 Thread Craig Topper via cfe-commits


@@ -3056,6 +3056,45 @@ bool Sema::checkTargetVersionAttr(SourceLocation 
LiteralLoc, Decl *D,
   enum SecondParam { None };
   enum ThirdParam { Target, TargetClones, TargetVersion };
   llvm::SmallVector Features;
+  if (Context.getTargetInfo().getTriple().isRISCV()) {
+
+llvm::SmallVector AttrStrs;
+AttrStr.split(AttrStrs, ';');
+
+bool IsPriority = false;
+bool IsDefault = false;
+for (auto &AttrStr : AttrStrs) {
+  // Only support arch=+ext,... syntax.

topperc wrote:

What if someone writes `arch=rv64gc;default;` do we error for that?

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


[clang] [flang] [mlir] [clang][flang][mlir] Support -frecord-command-line option (PR #102975)

2024-09-19 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `flang-aarch64-latest-gcc` 
running on `linaro-flang-aarch64-latest-gcc` while building `clang,flang,mlir` 
at step 6 "test-build-unified-tree-check-flang".

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


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

```
Step 6 (test-build-unified-tree-check-flang) failure: test (failure)
 TEST 'Flang :: Driver/bbc-mlir-pass-pipeline.f90' FAILED 

Exit Code: 1

Command Output (stderr):
--
RUN: at line 3: bbc --mlir-pass-statistics 
--mlir-pass-statistics-display=pipeline 
/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/llvm-project/flang/test/Driver/bbc-mlir-pass-pipeline.f90
 2>&1 | /home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/build/bin/FileCheck 
/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/llvm-project/flang/test/Driver/bbc-mlir-pass-pipeline.f90
+ bbc --mlir-pass-statistics --mlir-pass-statistics-display=pipeline 
/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/llvm-project/flang/test/Driver/bbc-mlir-pass-pipeline.f90
+ /home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/build/bin/FileCheck 
/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/llvm-project/flang/test/Driver/bbc-mlir-pass-pipeline.f90
/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/llvm-project/flang/test/Driver/bbc-mlir-pass-pipeline.f90:9:10:
 error: CHECK: expected string not found in input
! CHECK: Pass statistics report
 ^
:1:1: note: scanning from here
: CommandLine Error: Option 'fdynamic-heap-array' registered more than once!
^
:2:14: note: possible intended match here
LLVM ERROR: inconsistency in registered CommandLine options
 ^

Input file: 
Check file: 
/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/llvm-project/flang/test/Driver/bbc-mlir-pass-pipeline.f90

-dump-input=help explains the following input dump.

Input was:
<<
   1: : CommandLine Error: Option 'fdynamic-heap-array' registered more 
than once! 
check:9'0 
X 
error: no match found
   2: LLVM ERROR: inconsistency in registered CommandLine options 
check:9'0 
check:9'1  ?   
possible intended match
>>

--




```



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


[clang] [clang][bytecode] Implement arithmetic, bitwise and compound assignment operator (PR #108949)

2024-09-19 Thread via cfe-commits

yronglin wrote:

> Does it work to _not_ discard the result of a compound operator?
> 
> ```c++
> using VI __attribute__((ext_vector_type(4))) = int;
> 
> constexpr int a() {
> VI a = {0, 0, 0, 0};
> VI b = {1,1,1,1};
> 
> VI C = (a += b);
> 
> return 0;
> }
> 
> static_assert(a() == 0);
> ```

Good catch! I've fixed this issue.

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


[clang] [llvm] [llvm][Triple] Add `Environment` members and parsing for glibc/musl parity. (PR #107664)

2024-09-19 Thread Alex Rønne Petersen via cfe-commits

alexrp wrote:

> OK. Then I will work on GCC with this support.

Thank you, much appreciated!

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


[clang] [clang][bytecode] Implement arithmetic, bitwise and compound assignment operator (PR #108949)

2024-09-19 Thread via cfe-commits

https://github.com/yronglin updated 
https://github.com/llvm/llvm-project/pull/108949

>From 3601f708847f70485fae640c5b5d96fed965e7c3 Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Tue, 17 Sep 2024 17:39:47 +0800
Subject: [PATCH 1/3] [clang][bytecode] Implement arithmetic, bitwise and
 compound assignment operator

Signed-off-by: yronglin 
---
 clang/lib/AST/ByteCode/Compiler.cpp   | 121 +++-
 clang/test/AST/ByteCode/constexpr-vectors.cpp | 519 +-
 clang/test/SemaCXX/constexpr-vectors.cpp  |   1 +
 3 files changed, 611 insertions(+), 30 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 7e0775a51aee61..e7a6df58e6f1a6 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -1267,12 +1267,8 @@ bool Compiler::VisitVectorBinOp(const 
BinaryOperator *E) {
   assert(E->getLHS()->getType()->isVectorType());
   assert(E->getRHS()->getType()->isVectorType());
 
-  // FIXME: Current only support comparison binary operator, add support for
-  // other binary operator.
-  if (!E->isComparisonOp() && !E->isLogicalOp())
-return this->emitInvalid(E);
   // Prepare storage for result.
-  if (!Initializing) {
+  if (!Initializing || E->isCompoundAssignmentOp()) {
 unsigned LocalIndex = allocateTemporary(E);
 if (!this->emitGetPtrLocal(LocalIndex, E))
   return false;
@@ -1281,26 +1277,67 @@ bool Compiler::VisitVectorBinOp(const 
BinaryOperator *E) {
   const Expr *LHS = E->getLHS();
   const Expr *RHS = E->getRHS();
   const auto *VecTy = E->getType()->getAs();
+  auto Op = E->isCompoundAssignmentOp()
+? BinaryOperator::getOpForCompoundAssignment(E->getOpcode())
+: E->getOpcode();
 
   // The LHS and RHS of a comparison operator must have the same type. So we
   // just use LHS vector element type here.
   PrimType ElemT = this->classifyVectorElementType(LHS->getType());
   PrimType ResultElemT = this->classifyVectorElementType(E->getType());
 
-  // Evaluate LHS and save value to LHSOffset.
+  // Allocate a local pointer for LHS and RHS.
   unsigned LHSOffset = this->allocateLocalPrimitive(LHS, PT_Ptr, true, false);
+  unsigned RHSOffset = this->allocateLocalPrimitive(RHS, PT_Ptr, true, false);
+
+  // C++17 onwards require that we evaluate the RHS of the compound
+  // assignment op first.
+  if (E->isCompoundAssignmentOp()) {
+// Evaluate RHS and save value to RHSOffset.
+if (!this->visit(RHS))
+  return false;
+if (!this->emitSetLocal(PT_Ptr, RHSOffset, E))
+  return false;
+
+// Evaluate LHS and save value to LHSOffset.
+if (!this->visit(LHS))
+  return false;
+if (!this->emitSetLocal(PT_Ptr, LHSOffset, E))
+  return false;
+  } else {
+// Evaluate LHS and save value to LHSOffset.
+if (!this->visit(LHS))
+  return false;
+if (!this->emitSetLocal(PT_Ptr, LHSOffset, E))
+  return false;
+
+// Evaluate RHS and save value to RHSOffset.
+if (!this->visit(RHS))
+  return false;
+if (!this->emitSetLocal(PT_Ptr, RHSOffset, E))
+  return false;
+  }
+
+  // Evaluate LHS and save value to LHSOffset.
   if (!this->visit(LHS))
 return false;
   if (!this->emitSetLocal(PT_Ptr, LHSOffset, E))
 return false;
 
   // Evaluate RHS and save value to RHSOffset.
-  unsigned RHSOffset = this->allocateLocalPrimitive(RHS, PT_Ptr, true, false);
   if (!this->visit(RHS))
 return false;
   if (!this->emitSetLocal(PT_Ptr, RHSOffset, E))
 return false;
 
+  // BitAdd/BitOr/BitXor/Shl/Shr doesn't support bool type, we need perform the
+  // integer promotion.
+  bool NeedIntPromot = ElemT == PT_Bool && (E->isBitwiseOp() || 
E->isShiftOp());
+  QualType PromotTy =
+  Ctx.getASTContext().getPromotedIntegerType(Ctx.getASTContext().BoolTy);
+  PrimType PromotT = classifyPrim(PromotTy);
+  PrimType OpT = NeedIntPromot ? PromotT : ElemT;
+
   auto getElem = [=](unsigned Offset, unsigned Index) {
 if (!this->emitGetLocal(PT_Ptr, Offset, E))
   return false;
@@ -1311,16 +1348,63 @@ bool Compiler::VisitVectorBinOp(const 
BinaryOperator *E) {
 return false;
   if (!this->emitPrimCast(PT_Bool, ResultElemT, VecTy->getElementType(), 
E))
 return false;
+} else if (NeedIntPromot) {
+  if (!this->emitPrimCast(ElemT, PromotT, PromotTy, E))
+return false;
 }
 return true;
   };
 
+#define EMIT_ARITH_OP(OP)  
\
+  {
\
+if (ElemT == PT_Float) {   
\
+  if (!this->emit##OP##f(getFPOptions(E), E))  
\
+return false;  
\
+} else {   
\
+  if (!this->emit##OP(ElemT, E)) 

[clang] [Clang][Sema] Fix templated array size calculation. (PR #96464)

2024-09-19 Thread via cfe-commits

https://github.com/awson updated https://github.com/llvm/llvm-project/pull/96464

>From 096b999120cc28844d780acbc16f8308b3a54160 Mon Sep 17 00:00:00 2001
From: awson 
Date: Mon, 24 Jun 2024 10:34:51 +0300
Subject: [PATCH 1/3] [Clang][Sema] don't handle ArraySize/AllocType early.

---
 clang/lib/Sema/SemaExprCXX.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index f3af8dee6b090c..2f79540faea009 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -2174,7 +2174,8 @@ ExprResult Sema::BuildCXXNew(SourceRange Range, bool 
UseGlobal,
 
   // Per C++0x [expr.new]p5, the type being constructed may be a
   // typedef of an array type.
-  if (!ArraySize) {
+  // Dependent case will be handled separately.
+  if (!ArraySize && !AllocType->isDependentType()) {
 if (const ConstantArrayType *Array
   = Context.getAsConstantArrayType(AllocType)) {
   ArraySize = IntegerLiteral::Create(Context, Array->getSize(),

>From 50dbd2c8dce3a70f19ea6f2f22f6f1f9bda84a1e Mon Sep 17 00:00:00 2001
From: awson 
Date: Mon, 24 Jun 2024 11:07:58 +0300
Subject: [PATCH 2/3] [clang][Sema] Tests for GH41441

I've borrowed size-calculation test from PR89036 and added another test, which 
PR89036 fails on.
---
 clang/test/SemaCXX/GH41441.cpp | 46 ++
 1 file changed, 46 insertions(+)
 create mode 100644 clang/test/SemaCXX/GH41441.cpp

diff --git a/clang/test/SemaCXX/GH41441.cpp b/clang/test/SemaCXX/GH41441.cpp
new file mode 100644
index 00..7a6260fef91b56
--- /dev/null
+++ b/clang/test/SemaCXX/GH41441.cpp
@@ -0,0 +1,46 @@
+// RUN: %clang --target=x86_64-pc-linux -S -fno-discard-value-names -emit-llvm 
-o - %s | FileCheck %s
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+
+namespace std {
+  using size_t = decltype(sizeof(int));
+};
+void* operator new[](std::size_t, void*) noexcept;
+
+// CHECK: call void @llvm.memset.p0.i64(ptr align 1 %x, i8 0, i64 8, i1 false)
+// CHECK: call void @llvm.memset.p0.i64(ptr align 16 %x, i8 0, i64 32, i1 
false)
+template 
+void f()
+{
+typedef TYPE TArray[8];
+
+TArray x;
+new(&x) TArray();
+}
+
+template 
+void f1() {
+  int (*x)[1] = new int[1][1];
+}
+template void f1();
+void f2() {
+  int (*x)[1] = new int[1][1];
+}
+
+int main()
+{
+f();
+f();
+}
+
+// expected-no-diagnostics
+template  struct unique_ptr {unique_ptr(T* p){}};
+
+template 
+unique_ptr make_unique(unsigned long long n) {
+  return unique_ptr(new T[n]());
+}
+
+auto boro(int n){
+   typedef double HistoryBuffer[4];
+   return make_unique(n);
+}

>From 81ea2f2233b769e75dc43b37933f78fe8c8f2e7d Mon Sep 17 00:00:00 2001
From: awson 
Date: Tue, 17 Sep 2024 10:22:36 +0300
Subject: [PATCH 3/3] [Clang][Sema] Update release notes on GH41441.

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

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 69b2aea52aa9d3..6708167bf8b362 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -391,6 +391,7 @@ Bug Fixes to C++ Support
 - Fixed a crash when clang tries to subtitute parameter pack while retaining 
the parameter
   pack. #GH63819, #GH107560
 - Fix a crash when a static assert declaration has an invalid close location. 
(#GH108687)
+- Fix erroneous templated array size calculation leading to crashes in 
generated code. (#GH41441)
 
 Bug Fixes to AST Handling
 ^

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


[clang] [AST] Ensure getRawCommentsForAnyRedecl() does not miss any redecl with a comment (PR #108475)

2024-09-19 Thread Younan Zhang via cfe-commits

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


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


[clang] Update ClangFormat.rst (PR #109380)

2024-09-19 Thread via cfe-commits

https://github.com/love1angel created 
https://github.com/llvm/llvm-project/pull/109380

latest vim such as 9.1 remove python and add python3 dependency

>From 1dfa78f2f5f0f873ddc41687158dc48588527035 Mon Sep 17 00:00:00 2001
From: helianthus <45203165+love1an...@users.noreply.github.com>
Date: Fri, 20 Sep 2024 14:18:57 +0800
Subject: [PATCH] Update ClangFormat.rst

pyf not work properly in vim 9.0+
---
 clang/docs/ClangFormat.rst | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ClangFormat.rst b/clang/docs/ClangFormat.rst
index dbd9c91ae508e5..41e06558e1b45c 100644
--- a/clang/docs/ClangFormat.rst
+++ b/clang/docs/ClangFormat.rst
@@ -198,9 +198,12 @@ your `.vimrc`:
 
   function! Formatonsave()
 let l:formatdiff = 1
-pyf /clang-format.py
+if has('python')
+  pyf /clang-format.py
+elseif has('python3')
+  py3f /clang-format.py
   endfunction
-  autocmd BufWritePre *.h,*.cc,*.cpp call Formatonsave()
+  autocmd BufWritePre *.h,*.cc,*.cpp,*.cppm call Formatonsave()
 
 
 Emacs Integration

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


[clang] ea57880 - [AST] Ensure getRawCommentsForAnyRedecl() does not miss any redecl with a comment (#108475)

2024-09-19 Thread via cfe-commits

Author: Nathan Ridge
Date: 2024-09-20T02:23:58-04:00
New Revision: ea578804c81bbad1f31a0c940c8f4378d6893ede

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

LOG: [AST] Ensure getRawCommentsForAnyRedecl() does not miss any redecl with a 
comment (#108475)

The previous implementation had a bug where, if it was called on a Decl
later in the redecl chain than `LastCheckedDecl`, it could incorrectly
skip and overlook a Decl with a comment.

The patch addresses this by only using `LastCheckedDecl` if the input
Decl `D` is on the path from the first (canonical) Decl to
`LastCheckedDecl`.

An alternative that was considered was to start the iteration from the
(canonical) Decl, however this ran into problems with the modelling of
explicit template specializations in the AST where the canonical Decl
can be unusual. With the current solution, if no Decls were checked yet,
we prefer to check the input Decl over the canonical one.

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

Added: 
clang/unittests/AST/RawCommentForDeclTest.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/AST/ASTContext.cpp
clang/unittests/AST/CMakeLists.txt

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b8816d7b555e87..3f146cb9247a78 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -408,6 +408,8 @@ Bug Fixes to AST Handling
 ^
 
 - Fixed a crash that occurred when dividing by zero in complex integer 
division. (#GH55390).
+- Fixed a bug in ``ASTContext::getRawCommentForAnyRedecl()`` where the 
function could
+  sometimes incorrectly return null even if a comment was present. (#GH108145)
 
 Miscellaneous Bug Fixes
 ^^^

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index ebd4a41ee6367a..85b3984940ffc2 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -440,12 +440,26 @@ const RawComment *ASTContext::getRawCommentForAnyRedecl(
   }
 
   // Any redeclarations of D that we haven't checked for comments yet?
-  // We can't use DenseMap::iterator directly since it'd get invalid.
-  auto LastCheckedRedecl = [this, CanonicalD]() -> const Decl * {
-return CommentlessRedeclChains.lookup(CanonicalD);
+  const Decl *LastCheckedRedecl = [&]() {
+const Decl *LastChecked = CommentlessRedeclChains.lookup(CanonicalD);
+bool CanUseCommentlessCache = false;
+if (LastChecked) {
+  for (auto *Redecl : CanonicalD->redecls()) {
+if (Redecl == D) {
+  CanUseCommentlessCache = true;
+  break;
+}
+if (Redecl == LastChecked)
+  break;
+  }
+}
+// FIXME: This could be improved so that even if CanUseCommentlessCache
+// is false, once we've traversed past CanonicalD we still skip ahead
+// LastChecked.
+return CanUseCommentlessCache ? LastChecked : nullptr;
   }();
 
-  for (const auto Redecl : D->redecls()) {
+  for (const Decl *Redecl : D->redecls()) {
 assert(Redecl);
 // Skip all redeclarations that have been checked previously.
 if (LastCheckedRedecl) {

diff  --git a/clang/unittests/AST/CMakeLists.txt 
b/clang/unittests/AST/CMakeLists.txt
index 40d2e1ff77a601..bfa6082a6ffa4b 100644
--- a/clang/unittests/AST/CMakeLists.txt
+++ b/clang/unittests/AST/CMakeLists.txt
@@ -34,6 +34,7 @@ add_clang_unittest(ASTTests
   NamedDeclPrinterTest.cpp
   ProfilingTest.cpp
   RandstructTest.cpp
+  RawCommentForDeclTest.cpp
   RecursiveASTVisitorTest.cpp
   SizelessTypesTest.cpp
   SourceLocationTest.cpp

diff  --git a/clang/unittests/AST/RawCommentForDeclTest.cpp 
b/clang/unittests/AST/RawCommentForDeclTest.cpp
new file mode 100644
index 00..c81e56bf7e6b0c
--- /dev/null
+++ b/clang/unittests/AST/RawCommentForDeclTest.cpp
@@ -0,0 +1,98 @@
+//===- unittests/AST/RawCommentForDeclTestTest.cpp
+//-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/DeclGroup.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/FrontendAction.h"
+#include "clang/Tooling/Tooling.h"
+
+#include "gmock/gmock-matchers.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+
+struct FoundComment {
+  std::string DeclName;
+  bool IsDefinition;
+  std::string Comment;
+
+  bool operator==(const FoundComment &RHS) const {
+return DeclName == RHS.DeclName && IsDefinition == RHS.IsDefinition &&
+   Comment == RHS.Comme

[clang] [AST] Ensure getRawCommentsForAnyRedecl() does not miss any redecl with a comment (PR #108475)

2024-09-19 Thread Nathan Ridge via cfe-commits

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


[clang] Update ClangFormat.rst (PR #109380)

2024-09-19 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


[clang] Update ClangFormat.rst (PR #109380)

2024-09-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: helianthus (love1angel)


Changes

latest vim such as 9.1 remove python and add python3 dependency

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


1 Files Affected:

- (modified) clang/docs/ClangFormat.rst (+5-2) 


``diff
diff --git a/clang/docs/ClangFormat.rst b/clang/docs/ClangFormat.rst
index dbd9c91ae508e5..41e06558e1b45c 100644
--- a/clang/docs/ClangFormat.rst
+++ b/clang/docs/ClangFormat.rst
@@ -198,9 +198,12 @@ your `.vimrc`:
 
   function! Formatonsave()
 let l:formatdiff = 1
-pyf /clang-format.py
+if has('python')
+  pyf /clang-format.py
+elseif has('python3')
+  py3f /clang-format.py
   endfunction
-  autocmd BufWritePre *.h,*.cc,*.cpp call Formatonsave()
+  autocmd BufWritePre *.h,*.cc,*.cpp,*.cppm call Formatonsave()
 
 
 Emacs Integration

``




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


[clang] [Driver][Sparc] Default to -mcpu=v9 for 32-bit Linux/sparc64 (PR #109278)

2024-09-19 Thread Sam James via cfe-commits

thesamesam wrote:

(I'm fine with maskray's idea as well.)

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


[clang] [clang-tools-extra] [clangd] Collect comments from function definitions into the index (PR #67802)

2024-09-19 Thread Nathan Ridge via cfe-commits


@@ -451,8 +451,17 @@ const RawComment *ASTContext::getRawCommentForAnyRedecl(
 if (LastCheckedRedecl) {
   if (LastCheckedRedecl == Redecl) {
 LastCheckedRedecl = nullptr;
+continue;

HighCommander4 wrote:

The fix for #108145 has merged now, so let's go ahead and drop this hunk

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


[clang] [clang-tools-extra] [clangd] Collect comments from function definitions into the index (PR #67802)

2024-09-19 Thread Nathan Ridge via cfe-commits

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


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


[clang] [Driver][Sparc] Default to -mcpu=v9 for 32-bit Linux/sparc64 (PR #109278)

2024-09-19 Thread Sam James via cfe-commits

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


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


[clang] [clang][ExprConst] Explicitly reject dependent types without diagnostic (PR #108598)

2024-09-19 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Ping

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


[clang-tools-extra] [clang-tidy] modernize-use-nullptr matches "NULL" in templates (PR #109169)

2024-09-19 Thread Florian Mayer via cfe-commits


@@ -84,6 +84,29 @@ void test_macro_expansion4() {
 #undef MY_NULL
 }
 
+template  struct pear {
+  // If you say __null (or NULL), we assume that T will always be a pointer

fmayer wrote:

why are we only testing one of those?

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


[clang-tools-extra] [clang-tidy] modernize-use-nullptr matches "NULL" in templates (PR #109169)

2024-09-19 Thread Thomas Köppe via cfe-commits


@@ -84,6 +84,29 @@ void test_macro_expansion4() {
 #undef MY_NULL
 }
 
+template  struct pear {
+  // If you say __null (or NULL), we assume that T will always be a pointer

tkoeppe wrote:

That was the whole thing we were belaboring earlier -- this test defines `NULL` 
to `0` and thus isn't caught, but in production, it's defined as `__null`, 
where the new code catches it. We don't actually have code to detect "this was 
spelled as a macro", I'm afraid (right, @zygoloid?).

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


[clang] [Driver] Add toolchain for X86_64 UEFI target (PR #76838)

2024-09-19 Thread Pranav Bhandarkar via cfe-commits

bhandarkar-pranav wrote:

> Looks like this breaks tests on Mac: http://45.33.8.238/macm1/92471/step_6.txt
> 
> Please take a look and revert for now if it takes a while to fix.
@nico 
I cannot access the link from my work VPN, but if this is the issue 
(https://github.com/llvm/llvm-project/issues/109328) then here is a fix 
(https://github.com/llvm/llvm-project/pull/109329) 

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


[clang] 221f15f - [Clang] - Add libclangSerialization to clang driver unittests (#109329)

2024-09-19 Thread via cfe-commits

Author: Pranav Bhandarkar
Date: 2024-09-19T16:51:08-05:00
New Revision: 221f15fc145d46289781206f241ae564cd9510f0

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

LOG: [Clang] - Add libclangSerialization to clang driver unittests (#109329)

This PR is a fix for issue
[#109328](https://github.com/llvm/llvm-project/issues/109328).
libclangSerializaton.so is needed for building clang driver unittests
after
https://github.com/llvm/llvm-project/pull/76838 was merged. Needed for
builds with `BUILD_SHARED_LIBS=ON`

Added: 


Modified: 
clang/unittests/Driver/CMakeLists.txt

Removed: 




diff  --git a/clang/unittests/Driver/CMakeLists.txt 
b/clang/unittests/Driver/CMakeLists.txt
index 752037f78fb147..efdd07ea238890 100644
--- a/clang/unittests/Driver/CMakeLists.txt
+++ b/clang/unittests/Driver/CMakeLists.txt
@@ -22,4 +22,5 @@ clang_target_link_libraries(ClangDriverTests
   clangDriver
   clangBasic
   clangFrontend # For TextDiagnosticPrinter.
+  clangSerialization
   )



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


[clang] [Clang] - Add libclangSerialization to clang driver unittests (PR #109329)

2024-09-19 Thread Pranav Bhandarkar via cfe-commits

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


[clang] [llvm] riscv: Support -mstack-protector-guard=tls (PR #108942)

2024-09-19 Thread Craig Topper via cfe-commits


@@ -3681,6 +3698,11 @@ static void RenderSSPOptions(const Driver &D, const 
ToolChain &TC,
   D.Diag(diag::err_drv_invalid_value) << A->getOption().getName() << Value;
   return;
 }
+if (EffectiveTriple.isRISCV() && Value != "tp") {
+  D.Diag(diag::err_drv_invalid_value_with_suggestion)

topperc wrote:

Is there a test for this error?

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


[clang] Revert "[Driver] Add toolchain for X86_64 UEFI target" (PR #109340)

2024-09-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Prabhuk (Prabhuk)


Changes

Reverts llvm/llvm-project#76838

Appears to be causing failures in MAC builders. First reverting the patch and 
will investigate after.

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


10 Files Affected:

- (modified) clang/lib/Basic/Targets.cpp (-3) 
- (modified) clang/lib/Basic/Targets/OSTargets.h (-15) 
- (modified) clang/lib/Basic/Targets/X86.h (-37) 
- (modified) clang/lib/Driver/CMakeLists.txt (-1) 
- (modified) clang/lib/Driver/Driver.cpp (-4) 
- (removed) clang/lib/Driver/ToolChains/UEFI.cpp (-88) 
- (removed) clang/lib/Driver/ToolChains/UEFI.h (-59) 
- (removed) clang/test/CodeGen/X86/uefi-data-layout.c (-3) 
- (removed) clang/test/Driver/uefi-constructed-args.c (-13) 
- (modified) clang/unittests/Driver/ToolChainTest.cpp (-21) 


``diff
diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index 4917ef015941be..0b8e565345b6a4 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -613,9 +613,6 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple &Triple,
 case llvm::Triple::Solaris:
   return std::make_unique>(Triple,
Opts);
-case llvm::Triple::UEFI:
-  return std::make_unique(Triple, Opts);
-
 case llvm::Triple::Win32: {
   switch (Triple.getEnvironment()) {
   case llvm::Triple::Cygnus:
diff --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index a83d6464e789d6..0a4f06967fff5a 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -778,21 +778,6 @@ class LLVM_LIBRARY_VISIBILITY ZOSTargetInfo : public 
OSTargetInfo {
   }
 };
 
-// UEFI target
-template 
-class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo {
-protected:
-  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
-MacroBuilder &Builder) const override {}
-
-public:
-  UEFITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
-  : OSTargetInfo(Triple, Opts) {
-this->WCharType = TargetInfo::UnsignedShort;
-this->WIntType = TargetInfo::UnsignedShort;
-  }
-};
-
 void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts,
MacroBuilder &Builder);
 
diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index a99ae62984c7d5..79fd5867cf6673 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -814,43 +814,6 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public 
X86TargetInfo {
   }
 };
 
-// x86-64 UEFI target
-class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo
-: public UEFITargetInfo {
-public:
-  UEFIX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
-  : UEFITargetInfo(Triple, Opts) {
-this->TheCXXABI.set(TargetCXXABI::Microsoft);
-this->MaxTLSAlign = 8192u * this->getCharWidth();
-this->resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-"
-  "i64:64-i128:128-f80:128-n8:16:32:64-S128");
-  }
-
-  void getTargetDefines(const LangOptions &Opts,
-MacroBuilder &Builder) const override {
-getOSDefines(Opts, X86TargetInfo::getTriple(), Builder);
-  }
-
-  BuiltinVaListKind getBuiltinVaListKind() const override {
-return TargetInfo::CharPtrBuiltinVaList;
-  }
-
-  CallingConvCheckResult checkCallingConvention(CallingConv CC) const override 
{
-switch (CC) {
-case CC_C:
-case CC_Win64:
-  return CCCR_OK;
-default:
-  return CCCR_Warning;
-}
-  }
-
-  TargetInfo::CallingConvKind
-  getCallingConvKind(bool ClangABICompat4) const override {
-return CCK_MicrosoftWin64;
-  }
-};
-
 // x86-64 Windows target
 class LLVM_LIBRARY_VISIBILITY WindowsX86_64TargetInfo
 : public WindowsTargetInfo {
diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt
index 4fd10bf671512f..32a4378ab499fa 100644
--- a/clang/lib/Driver/CMakeLists.txt
+++ b/clang/lib/Driver/CMakeLists.txt
@@ -78,7 +78,6 @@ add_clang_library(clangDriver
   ToolChains/Solaris.cpp
   ToolChains/SPIRV.cpp
   ToolChains/TCE.cpp
-  ToolChains/UEFI.cpp
   ToolChains/VEToolchain.cpp
   ToolChains/WebAssembly.cpp
   ToolChains/XCore.cpp
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 95723b9209d125..efe398dd531da7 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -45,7 +45,6 @@
 #include "ToolChains/SPIRV.h"
 #include "ToolChains/Solaris.h"
 #include "ToolChains/TCE.h"
-#include "ToolChains/UEFI.h"
 #include "ToolChains/VEToolchain.h"
 #include "ToolChains/WebAssembly.h"
 #include "ToolChains/XCore.h"
@@ -6417,9 +6416,6 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
 case llvm::Triple::Mesa3D:
   TC = std::make_unique(*this, Target, Args);
   break;
-case llvm::Tr

[clang] Revert "[Driver] Add toolchain for X86_64 UEFI target" (PR #109340)

2024-09-19 Thread via cfe-commits

https://github.com/Prabhuk created 
https://github.com/llvm/llvm-project/pull/109340

Reverts llvm/llvm-project#76838

Appears to be causing failures in MAC builders. First reverting the patch and 
will investigate after.

>From 7830c3e9d61e168a1de1fa2b33acc3fd4e22f2ed Mon Sep 17 00:00:00 2001
From: Prabhuk 
Date: Thu, 19 Sep 2024 14:53:55 -0700
Subject: [PATCH] Revert "[Driver] Add toolchain for X86_64 UEFI target
 (#76838)"

This reverts commit d1335fb86466221b0499db5fc8f158f1f64d9542.
---
 clang/lib/Basic/Targets.cpp   |  3 -
 clang/lib/Basic/Targets/OSTargets.h   | 15 
 clang/lib/Basic/Targets/X86.h | 37 --
 clang/lib/Driver/CMakeLists.txt   |  1 -
 clang/lib/Driver/Driver.cpp   |  4 --
 clang/lib/Driver/ToolChains/UEFI.cpp  | 88 ---
 clang/lib/Driver/ToolChains/UEFI.h| 59 ---
 clang/test/CodeGen/X86/uefi-data-layout.c |  3 -
 clang/test/Driver/uefi-constructed-args.c | 13 
 clang/unittests/Driver/ToolChainTest.cpp  | 21 --
 10 files changed, 244 deletions(-)
 delete mode 100644 clang/lib/Driver/ToolChains/UEFI.cpp
 delete mode 100644 clang/lib/Driver/ToolChains/UEFI.h
 delete mode 100644 clang/test/CodeGen/X86/uefi-data-layout.c
 delete mode 100644 clang/test/Driver/uefi-constructed-args.c

diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index 4917ef015941be..0b8e565345b6a4 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -613,9 +613,6 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple &Triple,
 case llvm::Triple::Solaris:
   return std::make_unique>(Triple,
Opts);
-case llvm::Triple::UEFI:
-  return std::make_unique(Triple, Opts);
-
 case llvm::Triple::Win32: {
   switch (Triple.getEnvironment()) {
   case llvm::Triple::Cygnus:
diff --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index a83d6464e789d6..0a4f06967fff5a 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -778,21 +778,6 @@ class LLVM_LIBRARY_VISIBILITY ZOSTargetInfo : public 
OSTargetInfo {
   }
 };
 
-// UEFI target
-template 
-class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo {
-protected:
-  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
-MacroBuilder &Builder) const override {}
-
-public:
-  UEFITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
-  : OSTargetInfo(Triple, Opts) {
-this->WCharType = TargetInfo::UnsignedShort;
-this->WIntType = TargetInfo::UnsignedShort;
-  }
-};
-
 void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts,
MacroBuilder &Builder);
 
diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index a99ae62984c7d5..79fd5867cf6673 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -814,43 +814,6 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public 
X86TargetInfo {
   }
 };
 
-// x86-64 UEFI target
-class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo
-: public UEFITargetInfo {
-public:
-  UEFIX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
-  : UEFITargetInfo(Triple, Opts) {
-this->TheCXXABI.set(TargetCXXABI::Microsoft);
-this->MaxTLSAlign = 8192u * this->getCharWidth();
-this->resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-"
-  "i64:64-i128:128-f80:128-n8:16:32:64-S128");
-  }
-
-  void getTargetDefines(const LangOptions &Opts,
-MacroBuilder &Builder) const override {
-getOSDefines(Opts, X86TargetInfo::getTriple(), Builder);
-  }
-
-  BuiltinVaListKind getBuiltinVaListKind() const override {
-return TargetInfo::CharPtrBuiltinVaList;
-  }
-
-  CallingConvCheckResult checkCallingConvention(CallingConv CC) const override 
{
-switch (CC) {
-case CC_C:
-case CC_Win64:
-  return CCCR_OK;
-default:
-  return CCCR_Warning;
-}
-  }
-
-  TargetInfo::CallingConvKind
-  getCallingConvKind(bool ClangABICompat4) const override {
-return CCK_MicrosoftWin64;
-  }
-};
-
 // x86-64 Windows target
 class LLVM_LIBRARY_VISIBILITY WindowsX86_64TargetInfo
 : public WindowsTargetInfo {
diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt
index 4fd10bf671512f..32a4378ab499fa 100644
--- a/clang/lib/Driver/CMakeLists.txt
+++ b/clang/lib/Driver/CMakeLists.txt
@@ -78,7 +78,6 @@ add_clang_library(clangDriver
   ToolChains/Solaris.cpp
   ToolChains/SPIRV.cpp
   ToolChains/TCE.cpp
-  ToolChains/UEFI.cpp
   ToolChains/VEToolchain.cpp
   ToolChains/WebAssembly.cpp
   ToolChains/XCore.cpp
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 95723b9209d125..efe398dd531da7 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Drive

[clang] Revert "[Driver] Add toolchain for X86_64 UEFI target" (PR #109340)

2024-09-19 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-backend-x86

Author: Prabhuk (Prabhuk)


Changes

Reverts llvm/llvm-project#76838

Appears to be causing failures in MAC builders. First reverting the patch and 
will investigate after.

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


10 Files Affected:

- (modified) clang/lib/Basic/Targets.cpp (-3) 
- (modified) clang/lib/Basic/Targets/OSTargets.h (-15) 
- (modified) clang/lib/Basic/Targets/X86.h (-37) 
- (modified) clang/lib/Driver/CMakeLists.txt (-1) 
- (modified) clang/lib/Driver/Driver.cpp (-4) 
- (removed) clang/lib/Driver/ToolChains/UEFI.cpp (-88) 
- (removed) clang/lib/Driver/ToolChains/UEFI.h (-59) 
- (removed) clang/test/CodeGen/X86/uefi-data-layout.c (-3) 
- (removed) clang/test/Driver/uefi-constructed-args.c (-13) 
- (modified) clang/unittests/Driver/ToolChainTest.cpp (-21) 


``diff
diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index 4917ef015941be..0b8e565345b6a4 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -613,9 +613,6 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple &Triple,
 case llvm::Triple::Solaris:
   return std::make_unique>(Triple,
Opts);
-case llvm::Triple::UEFI:
-  return std::make_unique(Triple, Opts);
-
 case llvm::Triple::Win32: {
   switch (Triple.getEnvironment()) {
   case llvm::Triple::Cygnus:
diff --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index a83d6464e789d6..0a4f06967fff5a 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -778,21 +778,6 @@ class LLVM_LIBRARY_VISIBILITY ZOSTargetInfo : public 
OSTargetInfo {
   }
 };
 
-// UEFI target
-template 
-class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo {
-protected:
-  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
-MacroBuilder &Builder) const override {}
-
-public:
-  UEFITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
-  : OSTargetInfo(Triple, Opts) {
-this->WCharType = TargetInfo::UnsignedShort;
-this->WIntType = TargetInfo::UnsignedShort;
-  }
-};
-
 void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts,
MacroBuilder &Builder);
 
diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index a99ae62984c7d5..79fd5867cf6673 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -814,43 +814,6 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public 
X86TargetInfo {
   }
 };
 
-// x86-64 UEFI target
-class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo
-: public UEFITargetInfo {
-public:
-  UEFIX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
-  : UEFITargetInfo(Triple, Opts) {
-this->TheCXXABI.set(TargetCXXABI::Microsoft);
-this->MaxTLSAlign = 8192u * this->getCharWidth();
-this->resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-"
-  "i64:64-i128:128-f80:128-n8:16:32:64-S128");
-  }
-
-  void getTargetDefines(const LangOptions &Opts,
-MacroBuilder &Builder) const override {
-getOSDefines(Opts, X86TargetInfo::getTriple(), Builder);
-  }
-
-  BuiltinVaListKind getBuiltinVaListKind() const override {
-return TargetInfo::CharPtrBuiltinVaList;
-  }
-
-  CallingConvCheckResult checkCallingConvention(CallingConv CC) const override 
{
-switch (CC) {
-case CC_C:
-case CC_Win64:
-  return CCCR_OK;
-default:
-  return CCCR_Warning;
-}
-  }
-
-  TargetInfo::CallingConvKind
-  getCallingConvKind(bool ClangABICompat4) const override {
-return CCK_MicrosoftWin64;
-  }
-};
-
 // x86-64 Windows target
 class LLVM_LIBRARY_VISIBILITY WindowsX86_64TargetInfo
 : public WindowsTargetInfo {
diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt
index 4fd10bf671512f..32a4378ab499fa 100644
--- a/clang/lib/Driver/CMakeLists.txt
+++ b/clang/lib/Driver/CMakeLists.txt
@@ -78,7 +78,6 @@ add_clang_library(clangDriver
   ToolChains/Solaris.cpp
   ToolChains/SPIRV.cpp
   ToolChains/TCE.cpp
-  ToolChains/UEFI.cpp
   ToolChains/VEToolchain.cpp
   ToolChains/WebAssembly.cpp
   ToolChains/XCore.cpp
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 95723b9209d125..efe398dd531da7 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -45,7 +45,6 @@
 #include "ToolChains/SPIRV.h"
 #include "ToolChains/Solaris.h"
 #include "ToolChains/TCE.h"
-#include "ToolChains/UEFI.h"
 #include "ToolChains/VEToolchain.h"
 #include "ToolChains/WebAssembly.h"
 #include "ToolChains/XCore.h"
@@ -6417,9 +6416,6 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
 case llvm::Triple::Mesa3D:
   TC = std::make_unique(*this, Target, Args);
  

[clang] [llvm] [Loads] Check context instruction for context-sensitive derefability (PR #109277)

2024-09-19 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

Please update the documentation for isSafeToSpeculativelyExecute() to specify 
the semantics in the case where the operands of the instruction don't dominate 
CtxI.

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


[clang] [lld] [llvm] [mlir] [IR] Introduce `T` to `DataLayout` to represent flat address space if a target supports it (PR #108786)

2024-09-19 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

> If DataLayout is still a good place, then it might be just about whether we 
> call it a flat address space, or optimizable address space, and nothing would 
> be different from what is done in this PR.

We've avoided putting optimization properties in the DataLayout in the past.  
The interactions with LTO mean we want the DataLayout for a given subtarget to 
be stable.

In this particular case, a target's "flat" address-space can't really ever 
change, though, so it's probably fine.

> There are cases where you need a safe (portable?) default that the target can 
> perhaps optimise, but, absent that, would at least work, and at the moment 
> there's no handy way to query that generically (or from Clang).

The use-cases currently under discussion, and LangRef itself, don't require the 
flat address-space to have any particular semantics; the only property it has 
is "operations using it are slower".  What semantics do you need, and where do 
you need them?

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


[clang] [Driver] Add toolchain for X86_64 UEFI target (PR #76838)

2024-09-19 Thread via cfe-commits

Prabhuk wrote:

I am going to revert this and check the failures after.


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


[clang] [Clang] - Add libclangSerialization to clang driver unittests (PR #109329)

2024-09-19 Thread via cfe-commits

Prabhuk wrote:

Thank you Pranav! This looks like a reasonable fix to me. I just created a 
revert PR though since I cannot test this right away locally. 

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


[clang] [llvm] riscv: Support -mstack-protector-guard=tls (PR #108942)

2024-09-19 Thread Craig Topper via cfe-commits


@@ -3644,13 +3645,28 @@ static void RenderSSPOptions(const Driver &D, const 
ToolChain &TC,
   << A->getOption().getName() << Value << "sysreg global";
   return;
 }
+if (EffectiveTriple.isRISCV()) {
+  if (Value != "tls" && Value != "global") {

topperc wrote:

Is this also enabling "global" as a value? Is that supported in the backend?

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


[clang] Revert "[Driver] Add toolchain for X86_64 UEFI target" (PR #109340)

2024-09-19 Thread via cfe-commits

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


[clang] [flang] [llvm] [mlir] Make MMIWP not have ownership over MMI + Make MMI Only Use an External MCContext (PR #105541)

2024-09-19 Thread Matin Raayai via cfe-commits

matinraayai wrote:

> sorry for the delay
> 
> after looking at MMI/MCContext, I agree that MMI shouldn't own MCContext, but 
> do we even need a reference from  MMI to MCContext? they are different layers 
> of codegen IIUC. if it's possible to completely separate them we should do 
> that (please correct me if this doesn't make sense since I haven't spent too 
> much time in codegen)

@aeubanks  It's not impossible to separate them completely. `MCContext` is 
needed during initialization and finalization of the 
`MachineModuleInfoWrapperPass` (and its new pass manager variant) to set the 
diagnostics handler. 

In theory, you can just pass the context to the wrapper pass instead. @arsenm 
any thoughts on this?

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


[clang] Revert "[Driver] Add toolchain for X86_64 UEFI target" (PR #109340)

2024-09-19 Thread via cfe-commits

Prabhuk wrote:

https://github.com/llvm/llvm-project/commit/221f15fc145d46289781206f241ae564cd9510f0
 attemps to fix the failure caused by the Driver PR. Holding off of on the 
revert to see if the fix is successful.

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


[clang] [Clang][TableGen] Add explicit symbol visibility macros to code generated (PR #109362)

2024-09-19 Thread Thomas Fransham via cfe-commits

https://github.com/fsfod updated 
https://github.com/llvm/llvm-project/pull/109362

>From 363e96ba9ed442698c134f7f716a667e65ba3dbb Mon Sep 17 00:00:00 2001
From: Thomas Fransham 
Date: Mon, 8 Jul 2024 01:48:46 +0100
Subject: [PATCH 1/2] [Clang][TableGen] Add explicit symbol visibility macros
 to code generated

Update ClangAttrEmitter tablegen to add explicit symbol visibility macros
to function declarations it creates.
Both AnnotateFunctions and Attribute example plugins require clang::AnnotateAttr
TableGen created functions to be exported from the Clang shared library.
---
 clang/utils/TableGen/ClangAttrEmitter.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 87be48c215e230..43c423eb033890 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -2762,7 +2762,7 @@ static void emitAttributes(const RecordKeeper &Records, 
raw_ostream &OS,
 }
 
 if (Header)
-  OS << "class " << R.getName() << "Attr : public " << SuperName << " {\n";
+  OS << "class CLANG_ABI " << R.getName() << "Attr : public " << SuperName 
<< " {\n";
 else
   OS << "\n// " << R.getName() << "Attr implementation\n\n";
 
@@ -3220,7 +3220,8 @@ void clang::EmitClangAttrClass(const RecordKeeper 
&Records, raw_ostream &OS) {
   emitSourceFileHeader("Attribute classes' definitions", OS, Records);
 
   OS << "#ifndef LLVM_CLANG_ATTR_CLASSES_INC\n";
-  OS << "#define LLVM_CLANG_ATTR_CLASSES_INC\n\n";
+  OS << "#define LLVM_CLANG_ATTR_CLASSES_INC\n";
+  OS << "#include \"clang/Support/Compiler.h\"\n\n";
 
   emitAttributes(Records, OS, true);
 

>From f7ca7499008e9f18ed3b38fb1a224d22ad7f Mon Sep 17 00:00:00 2001
From: Thomas Fransham 
Date: Fri, 20 Sep 2024 03:10:15 +0100
Subject: [PATCH 2/2] Fix formatting

---
 clang/utils/TableGen/ClangAttrEmitter.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 43c423eb033890..624b7d46fb535a 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -2762,7 +2762,8 @@ static void emitAttributes(const RecordKeeper &Records, 
raw_ostream &OS,
 }
 
 if (Header)
-  OS << "class CLANG_ABI " << R.getName() << "Attr : public " << SuperName 
<< " {\n";
+  OS << "class CLANG_ABI " << R.getName() << "Attr : public " << SuperName
+ << " {\n";
 else
   OS << "\n// " << R.getName() << "Attr implementation\n\n";
 

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


[clang] [C++20][Modules] Fix crash when function and lambda inside loaded from different modules (PR #109167)

2024-09-19 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

> > Would you like to explain more why this fail previously in more detail?
> 
> Original code in `ASTReader::finishPendingActions` looked like this:
> 
> ```
> for (auto ID : PendingLambdas)
>   GetDecl(ID);
> PendingLambdas.clear();
> ```
> 
> The issue here is that the code uses implicit iterators for `PendingLambdas`, 
> but `GetDecl` may insert more elements into `PendingLambdas`, which can 
> invalidate the iterators. In a good case, when there is no vector relocation, 
> the new elements will be skipped. However, in the reproducer, the insertion 
> caused the vector to relocate, resulting in a crash due to reading invalid 
> values from deallocated memory. To address this issue, I have enclosed more 
> than 5 lambdas to cause relocation in the new test cases.
> 
> In the new code, before reading the lambdas, I copy the existing lambdas to a 
> new array. Alternatively, I could use an integer index for iteration and read 
> the size of the vector on each iteration. Both approaches work fine, but I 
> decided that running other pending actions might be better before starting to 
> deserialize new lambdas. I can change it if you think iteration with an 
> integer index is better.

Thanks, it is clear.

> 
> > Also I am thinking if we can make the process more efficiently: (1) Can we 
> > avoid the visitor in the writing process? (2) Can we delay the loading of 
> > lambdas to the load of definitions of the functions?
> > I immediately expectation is that (1) is possible but (2) may not be not 
> > safe.
> > For (1), my idea is to record/register the information during the writing 
> > of LambdaExpr in ASTWriterStmt and then we can write this record after we 
> > write all the decls and types. Then we need to read this record eagerly. 
> > Maybe we can optimize it further by adding a slot in FunctionDecl to record 
> > the offset of such informations. So we can avoid the eager linear reading 
> > process.
> 
> Yeah, it will complicate things a lot, we visit statements only after 
> serializing FunctionDecl. I run some profiling and it seems that 
> `collectLambdas` inclusively takes only about 0.25% cycles own time is almost 
> 0. I'll try to reduce it even further. I think we can scopes instead of 
> statements - it should be more efficient and we do it for enumerating 
> anonymous definitions and it seems to be fast enough.

it won't be much more complicated. You only need:
(1) Add a new map in ASTWriter. 
(2) In ASTWriterDecl, when you are writing a CXXRecord you can judge if it is 
lambda and if its enclosing decl context is a first function decl. And if all 
the conditions are tree, insert the id of function decl and the record id to 
that map. (I thought we could do this in ASTWriterStmt, but it may be more 
straight forward in ASTWriterDecl)
(3) In `ASTWriter::WriteDeclAndTypes`, after we set `DoneWritingDeclsAndTypes = 
true`, there are plenty examples that we did similar things here (write the 
information recorded during writing). We can add a new logic below
(4) Convert the map to RecordData (a vector), and then we can emit the record.
(5) In the reader side, convert the readed RecordData into a map.
(6) When we reads the corresponding function (or other possible conditions), 
loads the lambdas from the map.

I think the steps here are clear enough. On the one hand, 0.3% is not too 
small, we see 0.5% as significant in middle end. On the other hand, the steps 
are pretty common in Serializations. I think it will be helpful for you to 
understand the process.

Sorry in a head that I approve the previous solution but now ask for something 
more complex. But let's try to do things better if possible.

> 
> > For (2), whether or not it is safe is, can we we load the lambdas without 
> > loading the definition of the functions? If not, we can add a code when 
> > getting the definition of the functions like:
> > ```
> > if (lambdas not loaded)
> >  getCanonicalDecl()->loadLambdas();
> > ```
> > 
> > 
> > 
> >   
> > 
> > 
> >   
> > 
> > 
> > 
> >   
> > Then we can delay the loading of the lambdas to make it more efficient.
> 
> It will be too late in my example. Without my change lambdas get loaded 
> during function body deserialization but it was too late because loading 
> template specialization caused choosing canonical record for the lambda from 
> another modules. Function itself is selected from the last loaded modules by 
> lookup (i.e. it happens in reverse order of module loading) but template 
> specialisations get loaded in direct order. I tried to change order of 
> specilization loading to opposite but in real word it not always works 
> because some modules can be loaded for example in case of 
> `-fmodule-file==`.

So in short, in my question, can I treat your answer as, we can load a lambda 
or choose a lambda as the canonical decl without deserializing the 
**corresponding** body of the function decl? And if yes, can 

[clang] [AST] Ensure getRawCommentsForAnyRedecl() does not miss any redecl with a comment (PR #108475)

2024-09-19 Thread Nathan Ridge via cfe-commits

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


[clang] [llvm] [X86] Use X86AS::GS and X86AS::FS instead of 256 and 257. NFC (PR #109342)

2024-09-19 Thread Craig Topper via cfe-commits


@@ -144,6 +144,7 @@ add_clang_library(clangCodeGen
   VarBypassDetector.cpp
 
   DEPENDS
+  vt_gen

topperc wrote:

I don't know how that got in here.

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


[clang] [AST] Ensure getRawCommentsForAnyRedecl() does not miss any redecl with a comment (PR #108475)

2024-09-19 Thread Nathan Ridge via cfe-commits

https://github.com/HighCommander4 updated 
https://github.com/llvm/llvm-project/pull/108475

>From 1df68534d086e20572f2371239826d6b3514e58b Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Tue, 10 Sep 2024 22:34:55 -0400
Subject: [PATCH] [AST] Ensure getRawCommentsForAnyRedecl() does not miss any
 redecl with a comment

The previous implementation had a bug where, if it was called on a
Decl later in the redecl chain than `LastCheckedDecl`, it could
incorrectly skip and overlook a Decl with a comment.

The patch addresses this by only using `LastCheckedDecl` if the input
Decl `D` is on the path from the first (canonical) Decl to
`LastCheckedDecl`.

An alternative that was considered was to start the iteration from
the (canonical) Decl, however this ran into problems with the
modelling of explicit template specializations in the AST where
the canonical Decl can be unusual. With the current solution, if no
Decls were checked yet, we prefer to check the input Decl over the
canonical one.
---
 clang/docs/ReleaseNotes.rst   |  2 +
 clang/lib/AST/ASTContext.cpp  | 22 -
 clang/unittests/AST/CMakeLists.txt|  1 +
 clang/unittests/AST/RawCommentForDeclTest.cpp | 98 +++
 4 files changed, 119 insertions(+), 4 deletions(-)
 create mode 100644 clang/unittests/AST/RawCommentForDeclTest.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b8816d7b555e87..3f146cb9247a78 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -408,6 +408,8 @@ Bug Fixes to AST Handling
 ^
 
 - Fixed a crash that occurred when dividing by zero in complex integer 
division. (#GH55390).
+- Fixed a bug in ``ASTContext::getRawCommentForAnyRedecl()`` where the 
function could
+  sometimes incorrectly return null even if a comment was present. (#GH108145)
 
 Miscellaneous Bug Fixes
 ^^^
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index ebd4a41ee6367a..85b3984940ffc2 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -440,12 +440,26 @@ const RawComment *ASTContext::getRawCommentForAnyRedecl(
   }
 
   // Any redeclarations of D that we haven't checked for comments yet?
-  // We can't use DenseMap::iterator directly since it'd get invalid.
-  auto LastCheckedRedecl = [this, CanonicalD]() -> const Decl * {
-return CommentlessRedeclChains.lookup(CanonicalD);
+  const Decl *LastCheckedRedecl = [&]() {
+const Decl *LastChecked = CommentlessRedeclChains.lookup(CanonicalD);
+bool CanUseCommentlessCache = false;
+if (LastChecked) {
+  for (auto *Redecl : CanonicalD->redecls()) {
+if (Redecl == D) {
+  CanUseCommentlessCache = true;
+  break;
+}
+if (Redecl == LastChecked)
+  break;
+  }
+}
+// FIXME: This could be improved so that even if CanUseCommentlessCache
+// is false, once we've traversed past CanonicalD we still skip ahead
+// LastChecked.
+return CanUseCommentlessCache ? LastChecked : nullptr;
   }();
 
-  for (const auto Redecl : D->redecls()) {
+  for (const Decl *Redecl : D->redecls()) {
 assert(Redecl);
 // Skip all redeclarations that have been checked previously.
 if (LastCheckedRedecl) {
diff --git a/clang/unittests/AST/CMakeLists.txt 
b/clang/unittests/AST/CMakeLists.txt
index 40d2e1ff77a601..bfa6082a6ffa4b 100644
--- a/clang/unittests/AST/CMakeLists.txt
+++ b/clang/unittests/AST/CMakeLists.txt
@@ -34,6 +34,7 @@ add_clang_unittest(ASTTests
   NamedDeclPrinterTest.cpp
   ProfilingTest.cpp
   RandstructTest.cpp
+  RawCommentForDeclTest.cpp
   RecursiveASTVisitorTest.cpp
   SizelessTypesTest.cpp
   SourceLocationTest.cpp
diff --git a/clang/unittests/AST/RawCommentForDeclTest.cpp 
b/clang/unittests/AST/RawCommentForDeclTest.cpp
new file mode 100644
index 00..c81e56bf7e6b0c
--- /dev/null
+++ b/clang/unittests/AST/RawCommentForDeclTest.cpp
@@ -0,0 +1,98 @@
+//===- unittests/AST/RawCommentForDeclTestTest.cpp
+//-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/DeclGroup.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/FrontendAction.h"
+#include "clang/Tooling/Tooling.h"
+
+#include "gmock/gmock-matchers.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+
+struct FoundComment {
+  std::string DeclName;
+  bool IsDefinition;
+  std::string Comment;
+
+  bool operator==(const FoundComment &RHS) const {
+return DeclName == RHS.DeclName && IsDefinition == RHS.IsDefinition &&
+   Comment == RHS.Comment;
+  }
+  friend llvm::raw_ostream &operator<<(llvm::raw_

[clang] [Driver][Sparc] Default to -mcpu=v9 for 32-bit Linux/sparc64 (PR #109278)

2024-09-19 Thread Fangrui Song via cfe-commits

MaskRay wrote:

We try to restrict distribution differences to things like default linker 
options and library paths. Affecting `-mcpu=` seems very unintuitive. There are 
many Debian derivatives. It's weird that Debian uses -mcpu=v9 while others use 
-mcpu=v8. We should not increase `IsDebian` or `IsGentoo` use.

If -mcpu=v9 seems the right thing for the majority of configurations, we can 
bump -mcpu=v9 for all Linux and ask other, older systems to use 
https://clang.llvm.org/docs/UsersManual.html#configuration-files to specify 
`-mcpu=v8`.

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


[clang] [PAC][clang] Use cc1 instead of driver in init-fini codegen test (PR #109247)

2024-09-19 Thread Daniil Kovalev via cfe-commits

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


[clang] b0e68a9 - [PAC][clang] Use cc1 instead of driver in init-fini codegen test (#109247)

2024-09-19 Thread via cfe-commits

Author: Daniil Kovalev
Date: 2024-09-20T08:53:49+03:00
New Revision: b0e68a9a53e6bc1396271ee3d79cb86c8049fe17

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

LOG: [PAC][clang] Use cc1 instead of driver in init-fini codegen test (#109247)

Added: 


Modified: 
clang/test/CodeGen/ptrauth-init-fini.c

Removed: 




diff  --git a/clang/test/CodeGen/ptrauth-init-fini.c 
b/clang/test/CodeGen/ptrauth-init-fini.c
index d51ed1d98e81eb..1e8953961d64ef 100644
--- a/clang/test/CodeGen/ptrauth-init-fini.c
+++ b/clang/test/CodeGen/ptrauth-init-fini.c
@@ -1,19 +1,19 @@
 // REQUIRES: aarch64-registered-target
 
-// RUN: %clang -target aarch64-elf -march=armv8.3-a+pauth -fptrauth-calls 
-fptrauth-init-fini\
-// RUN:   -S -emit-llvm %s -o - | FileCheck --check-prefix=SIGNED %s
+// RUN: %clang_cc1 -triple aarch64-elf -target-feature +pauth -fptrauth-calls 
-fptrauth-init-fini\
+// RUN:   -emit-llvm %s -o - | FileCheck --check-prefix=SIGNED %s
 
-// RUN: %clang -target aarch64-elf -march=armv8.3-a+pauth -fptrauth-calls 
-fptrauth-init-fini\
-// RUN:   -fptrauth-init-fini-address-discrimination -S -emit-llvm %s -o - | 
FileCheck --check-prefix=ADDRDISC %s
+// RUN: %clang_cc1 -triple aarch64-elf -target-feature +pauth -fptrauth-calls 
-fptrauth-init-fini\
+// RUN:   -fptrauth-init-fini-address-discrimination -emit-llvm %s -o - | 
FileCheck --check-prefix=ADDRDISC %s
 
-// RUN: %clang -target aarch64-elf -march=armv8.3-a+pauth -fptrauth-calls 
-fno-ptrauth-init-fini \
-// RUN:   -S -emit-llvm %s -o - | FileCheck --check-prefix=UNSIGNED %s
+// RUN: %clang_cc1 -triple aarch64-elf -target-feature +pauth -fptrauth-calls \
+// RUN:   -emit-llvm %s -o - | FileCheck --check-prefix=UNSIGNED %s
 
-// RUN: %clang -target aarch64-elf -march=armv8.3-a+pauth -fptrauth-calls 
-fptrauth-init-fini-address-discrimination \
-// RUN:   -S -emit-llvm %s -o - | FileCheck --check-prefix=UNSIGNED %s
+// RUN: %clang_cc1 -triple aarch64-elf -target-feature +pauth -fptrauth-calls 
-fptrauth-init-fini-address-discrimination \
+// RUN:   -emit-llvm %s -o - | FileCheck --check-prefix=UNSIGNED %s
 
-// RUN: %clang -target aarch64-elf -march=armv8.3-a+pauth 
-fptrauth-init-fini\
-// RUN:   -S -emit-llvm %s -o - | FileCheck --check-prefix=UNSIGNED %s
+// RUN: %clang_cc1 -triple aarch64-elf -target-feature +pauth 
-fptrauth-init-fini\
+// RUN:   -emit-llvm %s -o - | FileCheck --check-prefix=UNSIGNED %s
 
 // SIGNED: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ 
i32, ptr, ptr } { i32 65535, ptr ptrauth (ptr @foo, i32 0, i64 55764), ptr null 
}]
 // SIGNED: @llvm.global_dtors = appending global [1 x { i32, ptr, ptr }] [{ 
i32, ptr, ptr } { i32 65535, ptr ptrauth (ptr @bar, i32 0, i64 55764), ptr null 
}]



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


[clang] [AST] Ensure getRawCommentsForAnyRedecl() does not miss any redecl with a comment (PR #108475)

2024-09-19 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

Added release note. I put it under "Bug Fixes to AST Handling" which seemed 
like a good fit.

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


[clang] [lld] [llvm] [mlir] [IR] Introduce `T` to `DataLayout` to represent flat address space if a target supports it (PR #108786)

2024-09-19 Thread Johannes Doerfert via cfe-commits

jdoerfert wrote:

> > +1 to @efriedma-quic and @jdoerfert's comments. DataLayout should remain as 
> > generic as possible. Trying to encode a concept of "_the_ flat address 
> > space" in it seems way too specific to one optimization for one or two 
> > targets.
> 
> This isn't purely a nice to have optimisation aid though, is it? There are 
> cases where you need a safe (portable?) default that the target can perhaps 
> optimise, but, absent that, would at least work, and at the moment there's no 
> handy way to query that generically (or from Clang). We do handwave 0 as 
> being that safe default, and hope for the best, but as mentioned that relies 
> on targets using 0 to correspond to flat/generic/whatever we call it, which 
> they are not bound to do. To me, adding this is not entirely different from 
> encoding the Alloca AS, which we already do.

Your argument is my point 3), right? 
https://github.com/llvm/llvm-project/pull/108786#issuecomment-2357327866

Why is that a DL property and not just a target property? Or even just 
"computable" by asking query 1) for different ASs?

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


[clang] [clang] implement current direction of CWG2765 for string literal comparisons in constant evaluation (PR #109208)

2024-09-19 Thread Timm Baeder via cfe-commits


@@ -108,22 +108,16 @@ constexpr auto p2 = "test2";
 constexpr bool b1 = foo(p1) == foo(p1);
 static_assert(b1);
 
-constexpr bool b2 = foo(p1) == foo(p2); // ref-error {{must be initialized by 
a constant expression}} \
-// ref-note {{comparison of addresses 
of literals}} \
-// ref-note {{declared here}}
-static_assert(!b2); // ref-error {{not an integral constant expression}} \
-// ref-note {{not a constant expression}}
+constexpr bool b2 = foo(p1) == foo(p2);
+static_assert(!b2);
 
 constexpr auto name1() { return "name1"; }
 constexpr auto name2() { return "name2"; }
 
-constexpr auto b3 = name1() == name1();
-static_assert(b3);
-constexpr auto b4 = name1() == name2(); // ref-error {{must be initialized by 
a constant expression}} \
-// ref-note {{has unspecified value}} \
-// ref-note {{declared here}}
-static_assert(!b4); // ref-error {{not an integral constant expression}} \
-// ref-note {{not a constant expression}}
+constexpr auto b3 = name1() == name1(); // ref-error {{must be initialized by 
a constant expression}} \
+// ref-note {{comparison of addresses 
of literals}}
+constexpr auto b4 = name1() == name2();
+static_assert(!b4);

tbaederr wrote:

Just from looking at these few lines, I don't understand why `b3` warns but 
`b4` doesn't. They both compare the address of literals.

The bytecode interpreter simply creates global variables for string literals, 
so `b3` here is simply true, like it was in the current interpreter before. Is 
this behavior wrong now?

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


[clang] [clang] implement current direction of CWG2765 for string literal comparisons in constant evaluation (PR #109208)

2024-09-19 Thread Timm Baeder via cfe-commits


@@ -2142,11 +2150,91 @@ static const ValueDecl *GetLValueBaseDecl(const LValue 
&LVal) {
   return LVal.Base.dyn_cast();
 }
 
-static bool IsLiteralLValue(const LValue &Value) {
-  if (Value.getLValueCallIndex())
+// Information about an LValueBase that is some kind of string.
+struct LValueBaseString {
+  std::string ObjCEncodeStorage;
+  StringRef Bytes;
+  int CharWidth;
+};
+
+// Gets the lvalue base of LVal as a string.
+static bool GetLValueBaseAsString(const EvalInfo &Info, const LValue &LVal,
+  LValueBaseString &AsString) {
+  const auto *BaseExpr = LVal.Base.dyn_cast();
+  if (!BaseExpr)
+return false;
+
+  // For ObjCEncodeExpr, we need to compute and store the string.
+  if (const auto *EE = dyn_cast(BaseExpr)) {
+Info.Ctx.getObjCEncodingForType(EE->getEncodedType(),
+AsString.ObjCEncodeStorage);
+AsString.Bytes = AsString.ObjCEncodeStorage;
+AsString.CharWidth = 1;
+return true;
+  }
+
+  // Otherwise, we have a StringLiteral.
+  const auto *Lit = dyn_cast(BaseExpr);
+  if (const auto *PE = dyn_cast(BaseExpr))
+Lit = PE->getFunctionName();
+
+  if (!Lit)
 return false;
-  const Expr *E = Value.Base.dyn_cast();
-  return E && !isa(E);
+
+  AsString.Bytes = Lit->getBytes();
+  AsString.CharWidth = Lit->getCharByteWidth();
+  return true;
+}
+
+// Determine whether two string literals potentially overlap. This will be the
+// case if they agree on the values of all the bytes on the overlapping region
+// between them.
+//
+// The overlapping region is the portion of the two string literals that must
+// overlap in memory if the pointers actually point to the same address at
+// runtime. For example, if LHS is "abcdef" + 3 and RHS is "cdef\0gh" + 1 then
+// the overlapping region is "cdef\0", which in this case does agree, so the
+// strings are potentially overlapping. Conversely, for "foobar" + 3 versus
+// "bazbar" + 3, the overlapping region contains all of both strings, so they
+// are not potentially overlapping, even though they agree from the given
+// addresses onwards.
+//
+// See open core issue CWG2765 which is discussing the desired rule here.
+static bool ArePotentiallyOverlappingStringLiterals(const EvalInfo &Info,
+const LValue &LHS,
+const LValue &RHS) {
+  LValueBaseString LHSString, RHSString;
+  if (!GetLValueBaseAsString(Info, LHS, LHSString) ||
+  !GetLValueBaseAsString(Info, RHS, RHSString))
+return false;
+
+  // This is the byte offset to the location of the first character of LHS
+  // within RHS. We don't need to look at the characters of one string that
+  // would appear before the start of the other string if they were merged.
+  CharUnits Offset = RHS.Offset - LHS.Offset;
+  if (Offset.isNegative())
+LHSString.Bytes = LHSString.Bytes.drop_front(-Offset.getQuantity());
+  else
+RHSString.Bytes = RHSString.Bytes.drop_front(Offset.getQuantity());
+
+  bool LHSIsLonger = LHSString.Bytes.size() > RHSString.Bytes.size();
+  StringRef Longer = LHSIsLonger ? LHSString.Bytes : RHSString.Bytes;
+  StringRef Shorter = LHSIsLonger ? RHSString.Bytes : LHSString.Bytes;
+  int ShorterCharWidth = (LHSIsLonger ? RHSString : LHSString).CharWidth;
+
+  // The null terminator isn't included in the string data, so check for it
+  // manually. If the longer string doesn't have a null terminator where the
+  // shorter string ends, they aren't potentially overlapping.
+  for (int nullByte : llvm::seq(ShorterCharWidth)) {

tbaederr wrote:

```suggestion
  for (int NullByte : llvm::seq(ShorterCharWidth)) {
```

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


[clang] [Clang] prevented assertion failure by handling integral to boolean conversions for boolean vectors (PR #108657)

2024-09-19 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/108657

>From 70d1be2a2a0f2f44cdd70bfb4397e7a36f1c9f30 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sat, 14 Sep 2024 01:46:28 +0300
Subject: [PATCH 1/3] [Clang] prevented assertion failure by handling integral
 to boolean conversions for boolean vectors

---
 clang/docs/ReleaseNotes.rst| 1 +
 clang/lib/Sema/SemaExpr.cpp| 7 ++-
 clang/test/Sema/ext_vector_casts.c | 5 +
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3929a9fb599259..e9d8d1b789506d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -386,6 +386,7 @@ Bug Fixes to C++ Support
 - Fixed a crash in the typo correction of an invalid CTAD guide. (#GH107887)
 - Fixed a crash when clang tries to subtitute parameter pack while retaining 
the parameter
   pack. #GH63819, #GH107560
+- Fixed an assertion failure by adjusting integral to boolean vector 
conversions (#GH108326)
 
 
 Bug Fixes to AST Handling
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 8f3e15cc9a9bb7..15b233212b770b 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -9868,7 +9868,12 @@ static bool tryVectorConvertAndSplat(Sema &S, ExprResult 
*scalar,
   // if necessary.
   CastKind scalarCast = CK_NoOp;
 
-  if (vectorEltTy->isIntegralType(S.Context)) {
+  if (vectorEltTy->isBooleanType()) {
+if (scalarTy->isIntegralType(S.Context))
+  scalarCast = CK_IntegralToBoolean;
+else if (!scalarTy->isBooleanType())
+  return true;
+  } else if (vectorEltTy->isIntegralType(S.Context)) {
 if (S.getLangOpts().OpenCL && (scalarTy->isRealFloatingType() ||
 (scalarTy->isIntegerType() &&
  S.Context.getIntegerTypeOrder(vectorEltTy, scalarTy) < 0))) {
diff --git a/clang/test/Sema/ext_vector_casts.c 
b/clang/test/Sema/ext_vector_casts.c
index 48440735d88ea9..6338035a61aad6 100644
--- a/clang/test/Sema/ext_vector_casts.c
+++ b/clang/test/Sema/ext_vector_casts.c
@@ -11,6 +11,7 @@ typedef float t3 __attribute__ ((vector_size (16)));
 typedef __typeof__(sizeof(int)) size_t;
 typedef unsigned long ulong2 __attribute__ ((ext_vector_type(2)));
 typedef size_t stride4 __attribute__((ext_vector_type(4)));
+typedef float bool4 __attribute__(( ext_vector_type(4) ));
 
 static void test(void) {
 float2 vec2;
@@ -19,6 +20,7 @@ static void test(void) {
 int4 ivec4;
 short8 ish8;
 t3 vec4_3;
+bool4 bvec4 = 0;
 int *ptr;
 int i;
 
@@ -51,6 +53,9 @@ static void test(void) {
 ivec4 -= ivec4;
 ivec4 |= ivec4;
 ivec4 += ptr; // expected-error {{cannot convert between vector and 
non-scalar values ('int4' (vector of 4 'int' values) and 'int *')}}
+
+bvec4 != 0; // expected-warning {{inequality comparison result unused}} \
+// expected-note {{use '|=' to turn this inequality comparison 
into an or-assignment}}
 }
 
 typedef __attribute__(( ext_vector_type(2) )) float2 vecfloat2; // 
expected-error{{invalid vector element type 'float2' (vector of 2 'float' 
values)}}

>From b7dc3966847429864fc56886370833afd40e38a5 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Tue, 17 Sep 2024 13:36:52 +0300
Subject: [PATCH 2/3] eliminate redundant logic that disallows non-boolean
 scalar casts

---
 clang/lib/Sema/SemaExpr.cpp | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 15b233212b770b..17dd3aeb6e3b6f 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -9868,11 +9868,8 @@ static bool tryVectorConvertAndSplat(Sema &S, ExprResult 
*scalar,
   // if necessary.
   CastKind scalarCast = CK_NoOp;
 
-  if (vectorEltTy->isBooleanType()) {
-if (scalarTy->isIntegralType(S.Context))
-  scalarCast = CK_IntegralToBoolean;
-else if (!scalarTy->isBooleanType())
-  return true;
+  if (vectorEltTy->isBooleanType() && scalarTy->isIntegralType(S.Context)) {
+scalarCast = CK_IntegralToBoolean;
   } else if (vectorEltTy->isIntegralType(S.Context)) {
 if (S.getLangOpts().OpenCL && (scalarTy->isRealFloatingType() ||
 (scalarTy->isIntegerType() &&

>From d102f1a5db12e0066f70a3d30e467961baa6cf1f Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Thu, 19 Sep 2024 22:18:57 +0300
Subject: [PATCH 3/3] fix typo

---
 clang/test/Sema/ext_vector_casts.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Sema/ext_vector_casts.c 
b/clang/test/Sema/ext_vector_casts.c
index 6338035a61aad6..8bf2737e0bfab1 100644
--- a/clang/test/Sema/ext_vector_casts.c
+++ b/clang/test/Sema/ext_vector_casts.c
@@ -11,7 +11,7 @@ typedef float t3 __attribute__ ((vector_size (16)));
 typedef __typeof__(sizeof(int)) size_t;
 typedef unsigned long ulong2 __attribute__ ((ext_vector_type(2)));
 typedef size_t stride4 __attribute__((ext_vector_type(4)));
-typedef

[clang] [clang] implement current direction of CWG2765 for string literal comparisons in constant evaluation (PR #109208)

2024-09-19 Thread Richard Smith via cfe-commits


@@ -74,6 +74,22 @@ C++ Specific Potentially Breaking Changes
 template 
 void f();
 
+- During constant evaluation, comparisons between different evaluations of the
+  same string literal are now correctly treated as non-constant, and 
comparisons
+  between string literals that cannot possibly overlap in memory are now 
treated
+  as constant.

zygoloid wrote:

Done.

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


[clang] ac66469 - [clang] Tidy uses of raw_string_ostream (NFC)

2024-09-19 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2024-09-19T14:56:45-05:00
New Revision: ac664697c54cf2ffa9ebef0215f734bcca3b718f

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

LOG: [clang] Tidy uses of raw_string_ostream (NFC)

As specified in the docs,
1) raw_string_ostream is always unbuffered and
2) the underlying buffer may be used directly

( 65b13610a5226b84889b923bae884ba395ad084d for further reference )

* Don't call raw_string_ostream::flush(), which is essentially a no-op.
* Avoid unneeded calls to raw_string_ostream::str(), to avoid excess 
indirection.

Added: 


Modified: 
clang/lib/ExtractAPI/DeclarationFragments.cpp
clang/lib/Frontend/ChainedIncludesSource.cpp
clang/lib/Frontend/CompilerInstance.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Frontend/Rewrite/RewriteObjC.cpp
clang/lib/StaticAnalyzer/Checkers/OSObjectCStyleCast.cpp
clang/lib/StaticAnalyzer/Checkers/ObjCSuperDeallocChecker.cpp
clang/lib/StaticAnalyzer/Checkers/PointerIterationChecker.cpp
clang/lib/StaticAnalyzer/Core/BugReporter.cpp
clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp

Removed: 




diff  --git a/clang/lib/ExtractAPI/DeclarationFragments.cpp 
b/clang/lib/ExtractAPI/DeclarationFragments.cpp
index 06ce5ed6a64756..9cb45c8fbf9cbc 100644
--- a/clang/lib/ExtractAPI/DeclarationFragments.cpp
+++ b/clang/lib/ExtractAPI/DeclarationFragments.cpp
@@ -1110,7 +1110,6 @@ 
DeclarationFragmentsBuilder::getFragmentsForTemplateArguments(
   Spelling.clear();
   raw_string_ostream OutStream(Spelling);
   CTA.print(Context.getPrintingPolicy(), OutStream, false);
-  OutStream.flush();
 }
   }
 

diff  --git a/clang/lib/Frontend/ChainedIncludesSource.cpp 
b/clang/lib/Frontend/ChainedIncludesSource.cpp
index c1a9f25a8798c7..a7096e27796a0a 100644
--- a/clang/lib/Frontend/ChainedIncludesSource.cpp
+++ b/clang/lib/Frontend/ChainedIncludesSource.cpp
@@ -159,7 +159,7 @@ IntrusiveRefCntPtr 
clang::createChainedIncludesSource(
   std::string pchName = includes[i-1];
   llvm::raw_string_ostream os(pchName);
   os << ".pch" << i-1;
-  serialBufNames.push_back(os.str());
+  serialBufNames.push_back(pchName);
 
   IntrusiveRefCntPtr Reader;
   Reader = createASTReader(

diff  --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index 5a273474f1d6b6..5f2a9637e3ea46 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -1383,7 +1383,6 @@ static bool compileModule(CompilerInstance 
&ImportingInstance,
 std::string InferredModuleMapContent;
 llvm::raw_string_ostream OS(InferredModuleMapContent);
 Module->print(OS);
-OS.flush();
 
 Result = compileModuleImpl(
 ImportingInstance, ImportLoc, Module->getTopLevelModuleName(),

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 32628c5e84332d..de6776b3f9da1a 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -817,7 +817,6 @@ static bool RoundTrip(ParseFn Parse, GenerateFn Generate,
   llvm::sys::printArg(OS, Arg, /*Quote=*/true);
   OS << ' ';
 }
-OS.flush();
 return Buffer;
   };
 
@@ -1186,7 +1185,6 @@ static bool ParseAnalyzerArgs(AnalyzerOptions &Opts, 
ArgList &Args,
   os << " ";
 os << Args.getArgString(i);
   }
-  os.flush();
 
   return Diags.getNumErrors() == NumErrorsBefore;
 }
@@ -3735,7 +3733,7 @@ void CompilerInvocationBase::GenerateLangArgs(const 
LangOptions &Opts,
 llvm::interleave(
 Opts.OMPTargetTriples, OS,
 [&OS](const llvm::Triple &T) { OS << T.str(); }, ",");
-GenerateArg(Consumer, OPT_fopenmp_targets_EQ, OS.str());
+GenerateArg(Consumer, OPT_fopenmp_targets_EQ, Targets);
   }
 
   if (!Opts.OMPHostIRFile.empty())

diff  --git a/clang/lib/Frontend/Rewrite/RewriteObjC.cpp 
b/clang/lib/Frontend/Rewrite/RewriteObjC.cpp
index fd5e8dc5298950..f3afb3e5e83acd 100644
--- a/clang/lib/Frontend/Rewrite/RewriteObjC.cpp
+++ b/clang/lib/Frontend/Rewrite/RewriteObjC.cpp
@@ -221,10 +221,9 @@ namespace {
 return;
   }
   // Get the new text.
-  std::string SStr;
-  llvm::raw_string_ostream S(SStr);
+  std::string Str;
+  llvm::raw_string_ostream S(Str);
   New->printPretty(S, nullptr, PrintingPolicy(LangOpts));
-  const std::string &Str = S.str();
 
   // If replacement succeeded or warning disabled return with no warning.
   if (!Rewrite.ReplaceText(SrcRange.getBegin(), Size, Str)) {
@@ -1702,7 +1701,7 @@ Stmt 
*RewriteObjC::RewriteObjCSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
   llvm::raw_string_ostream syncExprBuf(syncExprBufS);
   assert(syncExp

[clang] [Clang] prevented assertion failure by handling integral to boolean conversions for boolean vectors (PR #108657)

2024-09-19 Thread Oleksandr T. via cfe-commits


@@ -51,6 +53,9 @@ static void test(void) {
 ivec4 -= ivec4;
 ivec4 |= ivec4;
 ivec4 += ptr; // expected-error {{cannot convert between vector and 
non-scalar values ('int4' (vector of 4 'int' values) and 'int *')}}
+
+bvec4 != 0; // expected-warning {{inequality comparison result unused}} \

a-tarasyuk wrote:

@AaronBallman Thanks for the review, and I'm sorry for the confusion. There was 
a typo — the type should be `_Bool`. I've changed it to the appropriate type 
now.

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


[clang] [clang][CodeGen] Check initializer of zero-size fields for nullptr (PR #109271)

2024-09-19 Thread Eli Friedman via cfe-commits


@@ -738,7 +738,7 @@ bool ConstStructBuilder::Build(const InitListExpr *ILE, 
bool AllowOverwrite) {
 // Zero-sized fields are not emitted, but their initializers may still
 // prevent emission of this struct as a constant.
 if (isEmptyFieldForLayout(CGM.getContext(), Field)) {
-  if (Init->HasSideEffects(CGM.getContext()))
+  if (Init && Init->HasSideEffects(CGM.getContext()))

efriedma-quic wrote:

Maybe we should look at making InitListExpr handling more consistent, though... 
it looks like we generate an implicit initializer expression for C++ classes, 
but not other cases.  But this should do the right thing.

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


[clang] [clang][CodeGen] Check initializer of zero-size fields for nullptr (PR #109271)

2024-09-19 Thread Eli Friedman via cfe-commits


@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 %s -emit-llvm -triple x86_64-linux-gnu -o - | FileCheck %s 
--check-prefixes=CHECK
+// RUN: %clang_cc1 -x c++ %s -emit-llvm -triple x86_64-linux-gnu -o - | 
FileCheck %s --check-prefixes=CHECK-CXX
+
+union Foo {
+  struct Empty {} val;
+};
+
+union Foo foo = {};
+
+// CHECK: @foo = {{.*}}global %union.Foo undef, align 1

efriedma-quic wrote:

Generated code seems okay.  I mean, it's the same thing we've always generated 
for similar constructs.  I'd prefer to integrate this into some existing 
codegen test if we can, though...

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


[clang] [C++20] [Modules] Offer -fmodules-embed-all-files option (PR #107194)

2024-09-19 Thread Chuanqi Xu via cfe-commits

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


[clang] [flang] [mlir] [clang][flang][mlir] Support -frecord-command-line option (PR #102975)

2024-09-19 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `flang-aarch64-sharedlibs` 
running on `linaro-flang-aarch64-sharedlibs` while building `clang,flang,mlir` 
at step 6 "test-build-unified-tree-check-flang".

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


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

```
Step 6 (test-build-unified-tree-check-flang) failure: test (failure)
 TEST 'Flang :: Driver/bbc-cuda-macro.cuf' FAILED 

Exit Code: 2

Command Output (stderr):
--
RUN: at line 2: bbc -fcuda -o - 
/home/tcwg-buildbot/worker/flang-aarch64-sharedlibs/llvm-project/flang/test/Driver/bbc-cuda-macro.cuf
 | /home/tcwg-buildbot/worker/flang-aarch64-sharedlibs/build/bin/FileCheck 
/home/tcwg-buildbot/worker/flang-aarch64-sharedlibs/llvm-project/flang/test/Driver/bbc-cuda-macro.cuf
+ bbc -fcuda -o - 
/home/tcwg-buildbot/worker/flang-aarch64-sharedlibs/llvm-project/flang/test/Driver/bbc-cuda-macro.cuf
+ /home/tcwg-buildbot/worker/flang-aarch64-sharedlibs/build/bin/FileCheck 
/home/tcwg-buildbot/worker/flang-aarch64-sharedlibs/llvm-project/flang/test/Driver/bbc-cuda-macro.cuf
: CommandLine Error: Option 'fdynamic-heap-array' registered more than once!
LLVM ERROR: inconsistency in registered CommandLine options
FileCheck error: '' is empty.
FileCheck command line:  
/home/tcwg-buildbot/worker/flang-aarch64-sharedlibs/build/bin/FileCheck 
/home/tcwg-buildbot/worker/flang-aarch64-sharedlibs/llvm-project/flang/test/Driver/bbc-cuda-macro.cuf

--




```



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


[clang] f41f6ea - [C++20] [Modules] Offer -fmodules-embed-all-files option (#107194)

2024-09-19 Thread via cfe-commits

Author: Chuanqi Xu
Date: 2024-09-20T09:57:46+08:00
New Revision: f41f6ea1f33c4f5e7c94f3d155e44292d1809c50

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

LOG: [C++20] [Modules] Offer -fmodules-embed-all-files option (#107194)

See

https://discourse.llvm.org/t/rfc-modules-should-we-embed-sources-to-the-bmi/81029
for details.

Close https://github.com/llvm/llvm-project/issues/72383

Added: 
clang/test/Driver/fmodules-embed-all-files.cpp

Modified: 
clang/docs/StandardCPlusPlusModules.rst
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp

Removed: 




diff  --git a/clang/docs/StandardCPlusPlusModules.rst 
b/clang/docs/StandardCPlusPlusModules.rst
index 2b757a807a0e6e..8e22adad15106e 100644
--- a/clang/docs/StandardCPlusPlusModules.rst
+++ b/clang/docs/StandardCPlusPlusModules.rst
@@ -462,6 +462,37 @@ Currently, Clang accepts the above example, though it may 
produce surprising
 results if the debugging code depends on consistent use of ``NDEBUG`` in other
 translation units.
 
+Source Files Consistency
+
+
+Clang may open the input files\ :sup:`1`` of a BMI during the compilation. 
This implies that
+when Clang consumes a BMI, all the input files need to be present in the 
original path
+and with the original contents.
+
+To overcome these requirements and simplify cases like distributed builds and 
sandboxed
+builds, users can use the ``-fmodules-embed-all-files`` flag to embed all 
input files
+into the BMI so that Clang does not need to open the corresponding file on 
disk.
+
+When the ``-fmodules-embed-all-files`` flag are enabled, Clang explicitly 
emits the source
+code into the BMI file, the contents of the BMI file contain a sufficiently 
verbose
+representation to reproduce the original source file.
+
+:sup:`1`` Input files: The source files which took part in the compilation of 
the BMI.
+For example:
+
+.. code-block:: c++
+
+  // M.cppm
+  module;
+  #include "foo.h"
+  export module M;
+
+  // foo.h
+  #pragma once
+  #include "bar.h"
+
+The ``M.cppm``, ``foo.h`` and ``bar.h`` are input files for the BMI of 
``M.cppm``.
+
 Object definition consistency
 ^
 
@@ -484,6 +515,13 @@ fragment is disabled by default. These checks can be 
enabled by specifying
 and you encounter incorrect or missing diagnostics, please report them via the
 `community issue tracker `_.
 
+Privacy Issue
+-
+
+BMIs are not and should not be treated as an information hiding mechanism.
+They should always be assumed to contain all the information that was used to
+create them, in a recoverable form.
+
 ABI Impacts
 ---
 

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 021230ceed4cb4..6c6759f19f9b34 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3177,6 +3177,12 @@ def modules_reduced_bmi : Flag<["-"], 
"fexperimental-modules-reduced-bmi">,
   HelpText<"Generate the reduced BMI">,
   MarshallingInfoFlag>;
 
+def fmodules_embed_all_files : Joined<["-"], "fmodules-embed-all-files">,
+  Visibility<[ClangOption, CC1Option, CLOption]>,
+  HelpText<"Embed the contents of all files read by this compilation into "
+   "the produced module file.">,
+  MarshallingInfoFlag>;
+
 def fmodules_prune_interval : Joined<["-"], "fmodules-prune-interval=">, 
Group,
   Visibility<[ClangOption, CC1Option]>, MetaVarName<"">,
   HelpText<"Specify the interval (in seconds) between attempts to prune the 
module cache">,
@@ -7685,10 +7691,6 @@ def fmodules_embed_file_EQ : Joined<["-"], 
"fmodules-embed-file=">,
   HelpText<"Embed the contents of the specified file into the module file "
"being compiled.">,
   MarshallingInfoStringVector>;
-def fmodules_embed_all_files : Joined<["-"], "fmodules-embed-all-files">,
-  HelpText<"Embed the contents of all files read by this compilation into "
-   "the produced module file.">,
-  MarshallingInfoFlag>;
 defm fimplicit_modules_use_lock : BoolOption<"f", "implicit-modules-use-lock",
   FrontendOpts<"BuildingImplicitModuleUsesLock">, DefaultTrue,
   NegFlag,

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 7e83ec0e70cbcf..0a2c7b67cc2f0f 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4196,6 +4196,9 @@ static bool RenderModulesOptions(Compilation &C, const 
Driver &D,
 Args.ClaimAllArgs(options::OPT_fmodule_output_EQ);
   }
 
+  if (Args.hasArg(options::OPT_fmodules_embed_all_files))
+CmdArgs.push_back("-fmodules-embed-all-files");
+
   return HaveModules;
 }
 

diff  --git a/clang/test/Driver/f

[clang] [llvm] [clang] Add cc1 --output-asm-variant= to set output syntax (PR #109360)

2024-09-19 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay created 
https://github.com/llvm/llvm-project/pull/109360

2fcaa549a824efeb56e807fcf750a56bf985296b (2010) added cc1as option
`-output-asm-variant` (untested) to set the output syntax.
`clang -cc1as -filetype asm -output-asm-variant 1` allows AT&T input and
Intel output.

This patch renames the cc1as option (to avoid collision with -o) and
makes it available for cc1 to set output syntax. This allows different
input & output syntax:

```
echo 'asm("mov $1, %eax");' | clang -xc - -S -o - -Xclang --output-asm-variant=1
```

Note: `AsmWriterFlavor` (with a misleading name), used to initialize
MCAsmInfo::AssemblerDialect, is primarily used for assembly input, not
for output.


>From 7be5f9edad29769ae5bf2a49e861afed0c984014 Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Thu, 19 Sep 2024 19:00:08 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5-bogner
---
 clang/include/clang/Basic/CodeGenOptions.def  |  1 +
 clang/include/clang/Driver/Options.td |  5 ++--
 clang/lib/CodeGen/BackendUtil.cpp |  2 ++
 .../test/CodeGen/inline-asm-output-variant.c  | 26 +++
 clang/test/Misc/cc1as-output-asm-variant.c|  8 ++
 llvm/include/llvm/MC/MCTargetOptions.h|  2 ++
 llvm/lib/CodeGen/LLVMTargetMachine.cpp|  4 ++-
 7 files changed, 45 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGen/inline-asm-output-variant.c
 create mode 100644 clang/test/Misc/cc1as-output-asm-variant.c

diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index b600198998d85b..2893377e5a38be 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -96,6 +96,7 @@ CODEGENOPT(EmulatedTLS   , 1, 0) ///< Set by default or 
-f[no-]emulated-tls.
 ENUM_CODEGENOPT(EmbedBitcode, EmbedBitcodeKind, 2, Embed_Off)
 /// Inline asm dialect, -masm=(att|intel)
 ENUM_CODEGENOPT(InlineAsmDialect, InlineAsmDialectKind, 1, IAD_ATT)
+CODEGENOPT(OutputAsmVariant, 2, 3) ///< Set the asm variant for output (3: 
unspecified).
 CODEGENOPT(ForbidGuardVariables , 1, 0) ///< Issue errors if C++ guard 
variables
 ///< are required.
 CODEGENOPT(FunctionSections  , 1, 0) ///< Set when -ffunction-sections is 
enabled.
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index aa3ae92fb6ae78..2586782f3e3181 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -7209,6 +7209,9 @@ def fuse_ctor_homing: Flag<["-"], "fuse-ctor-homing">,
 def as_secure_log_file : Separate<["-"], "as-secure-log-file">,
   HelpText<"Emit .secure_log_unique directives to this filename.">,
   MarshallingInfoString>;
+def output_asm_variant : Joined<["--"], "output-asm-variant=">,
+  HelpText<"Select the asm variant (integer) to use for output">,
+  MarshallingInfoInt>;
 
 } // let Visibility = [CC1Option, CC1AsOption]
 
@@ -8303,8 +8306,6 @@ def filetype : Separate<["-"], "filetype">,
 HelpText<"Specify the output file type ('asm', 'null', or 'obj')">;
 
 // Transliterate Options
-def output_asm_variant : Separate<["-"], "output-asm-variant">,
-HelpText<"Select the asm variant index to use for output">;
 def show_encoding : Flag<["-"], "show-encoding">,
 HelpText<"Show instruction encoding information in transliterate mode">;
 def show_inst : Flag<["-"], "show-inst">,
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index fa49763e312f13..916c92adb89309 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -509,6 +509,8 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
   Options.MCOptions.X86RelaxRelocations = CodeGenOpts.X86RelaxRelocations;
   Options.MCOptions.CompressDebugSections =
   CodeGenOpts.getCompressDebugSections();
+  if (CodeGenOpts.OutputAsmVariant != 3) // 3 (default): not specified
+Options.MCOptions.OutputAsmVariant = CodeGenOpts.OutputAsmVariant;
   Options.MCOptions.ABIName = TargetOpts.ABI;
   for (const auto &Entry : HSOpts.UserEntries)
 if (!Entry.IsFramework &&
diff --git a/clang/test/CodeGen/inline-asm-output-variant.c 
b/clang/test/CodeGen/inline-asm-output-variant.c
new file mode 100644
index 00..5fc5c1cc09b016
--- /dev/null
+++ b/clang/test/CodeGen/inline-asm-output-variant.c
@@ -0,0 +1,26 @@
+// REQUIRES: x86-registered-target
+/// AT&T input
+// RUN: %clang_cc1 -triple x86_64 -S --output-asm-variant=0 %s -o - | 
FileCheck --check-prefix=ATT %s
+// RUN: %clang_cc1 -triple x86_64 -S --output-asm-variant=1 %s -o - | 
FileCheck --check-prefix=INTEL %s
+
+/// Intel input
+// RUN: %clang_cc1 -triple x86_64 -S -D INTEL -mllvm -x86-asm-syntax=intel 
-inline-asm=intel %s -o -

[clang] [llvm] [clang] Add cc1 --output-asm-variant= to set output syntax (PR #109360)

2024-09-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Fangrui Song (MaskRay)


Changes

2fcaa549a824efeb56e807fcf750a56bf985296b (2010) added cc1as option
`-output-asm-variant` (untested) to set the output syntax.
`clang -cc1as -filetype asm -output-asm-variant 1` allows AT&T input and
Intel output.

This patch renames the cc1as option (to avoid collision with -o) and
makes it available for cc1 to set output syntax. This allows different
input & output syntax:

```
echo 'asm("mov $1, %eax");' | clang -xc - -S -o - -Xclang --output-asm-variant=1
```

Note: `AsmWriterFlavor` (with a misleading name), used to initialize
MCAsmInfo::AssemblerDialect, is primarily used for assembly input, not
for output.


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


7 Files Affected:

- (modified) clang/include/clang/Basic/CodeGenOptions.def (+1) 
- (modified) clang/include/clang/Driver/Options.td (+3-2) 
- (modified) clang/lib/CodeGen/BackendUtil.cpp (+2) 
- (added) clang/test/CodeGen/inline-asm-output-variant.c (+26) 
- (added) clang/test/Misc/cc1as-output-asm-variant.c (+8) 
- (modified) llvm/include/llvm/MC/MCTargetOptions.h (+2) 
- (modified) llvm/lib/CodeGen/LLVMTargetMachine.cpp (+3-1) 


``diff
diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index b600198998d85b..2893377e5a38be 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -96,6 +96,7 @@ CODEGENOPT(EmulatedTLS   , 1, 0) ///< Set by default or 
-f[no-]emulated-tls.
 ENUM_CODEGENOPT(EmbedBitcode, EmbedBitcodeKind, 2, Embed_Off)
 /// Inline asm dialect, -masm=(att|intel)
 ENUM_CODEGENOPT(InlineAsmDialect, InlineAsmDialectKind, 1, IAD_ATT)
+CODEGENOPT(OutputAsmVariant, 2, 3) ///< Set the asm variant for output (3: 
unspecified).
 CODEGENOPT(ForbidGuardVariables , 1, 0) ///< Issue errors if C++ guard 
variables
 ///< are required.
 CODEGENOPT(FunctionSections  , 1, 0) ///< Set when -ffunction-sections is 
enabled.
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index aa3ae92fb6ae78..2586782f3e3181 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -7209,6 +7209,9 @@ def fuse_ctor_homing: Flag<["-"], "fuse-ctor-homing">,
 def as_secure_log_file : Separate<["-"], "as-secure-log-file">,
   HelpText<"Emit .secure_log_unique directives to this filename.">,
   MarshallingInfoString>;
+def output_asm_variant : Joined<["--"], "output-asm-variant=">,
+  HelpText<"Select the asm variant (integer) to use for output">,
+  MarshallingInfoInt>;
 
 } // let Visibility = [CC1Option, CC1AsOption]
 
@@ -8303,8 +8306,6 @@ def filetype : Separate<["-"], "filetype">,
 HelpText<"Specify the output file type ('asm', 'null', or 'obj')">;
 
 // Transliterate Options
-def output_asm_variant : Separate<["-"], "output-asm-variant">,
-HelpText<"Select the asm variant index to use for output">;
 def show_encoding : Flag<["-"], "show-encoding">,
 HelpText<"Show instruction encoding information in transliterate mode">;
 def show_inst : Flag<["-"], "show-inst">,
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index fa49763e312f13..916c92adb89309 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -509,6 +509,8 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
   Options.MCOptions.X86RelaxRelocations = CodeGenOpts.X86RelaxRelocations;
   Options.MCOptions.CompressDebugSections =
   CodeGenOpts.getCompressDebugSections();
+  if (CodeGenOpts.OutputAsmVariant != 3) // 3 (default): not specified
+Options.MCOptions.OutputAsmVariant = CodeGenOpts.OutputAsmVariant;
   Options.MCOptions.ABIName = TargetOpts.ABI;
   for (const auto &Entry : HSOpts.UserEntries)
 if (!Entry.IsFramework &&
diff --git a/clang/test/CodeGen/inline-asm-output-variant.c 
b/clang/test/CodeGen/inline-asm-output-variant.c
new file mode 100644
index 00..5fc5c1cc09b016
--- /dev/null
+++ b/clang/test/CodeGen/inline-asm-output-variant.c
@@ -0,0 +1,26 @@
+// REQUIRES: x86-registered-target
+/// AT&T input
+// RUN: %clang_cc1 -triple x86_64 -S --output-asm-variant=0 %s -o - | 
FileCheck --check-prefix=ATT %s
+// RUN: %clang_cc1 -triple x86_64 -S --output-asm-variant=1 %s -o - | 
FileCheck --check-prefix=INTEL %s
+
+/// Intel input
+// RUN: %clang_cc1 -triple x86_64 -S -D INTEL -mllvm -x86-asm-syntax=intel 
-inline-asm=intel %s -o - | FileCheck --check-prefix=ATT %s
+// RUN: %clang_cc1 -triple x86_64 -S -D INTEL -mllvm -x86-asm-syntax=intel 
-inline-asm=intel --output-asm-variant=1 %s -o - | FileCheck 
--check-prefix=INTEL %s
+
+// ATT: movl $1, %eax
+// ATT: movl $2, %eax
+
+// INTEL: mov eax, 1
+// INTEL: mov eax, 2
+
+#ifdef INTEL
+asm("mov eax, 1");
+void foo() {
+  asm("mov eax, 2");
+}
+#else
+asm("mov $1, %eax");
+void foo() {
+  

[clang] [clang-format] Correctly annotate pointer/reference in range-for loop (PR #109361)

2024-09-19 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/109361

Fixes #109358.

>From d954c56f41a96ace6b507f6e6f4531c885db9f38 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Thu, 19 Sep 2024 18:56:38 -0700
Subject: [PATCH] [clang-format] Correctly annotate pointer/reference in
 range-for loop

Fixes #109358.
---
 clang/lib/Format/TokenAnnotator.cpp   | 6 ++
 clang/unittests/Format/TokenAnnotatorTest.cpp | 6 ++
 2 files changed, 12 insertions(+)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 6f09835bad3a83..3f7ac6c7776f40 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1407,6 +1407,12 @@ class AnnotatingParser {
 }
   } else if (Contexts.back().ColonIsForRangeExpr) {
 Tok->setType(TT_RangeBasedForLoopColon);
+for (auto *Prev = Tok->Previous;
+ Prev && !Prev->isOneOf(tok::semi, tok::l_paren);
+ Prev = Prev->Previous) {
+  if (Prev->isPointerOrReference())
+Prev->setFinalizedType(TT_PointerOrReference);
+}
   } else if (Contexts.back().ContextType == Context::C11GenericSelection) {
 Tok->setType(TT_GenericSelectionColon);
   } else if (CurrentToken && CurrentToken->is(tok::numeric_constant)) {
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 34c03d668a9a0a..dfb6c060d32094 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -333,6 +333,12 @@ TEST_F(TokenAnnotatorTest, UnderstandsUsesOfStarAndAmp) {
   ASSERT_EQ(Tokens.size(), 17u) << Tokens;
   EXPECT_TOKEN(Tokens[11], tok::star, TT_BinaryOperator);
 
+  Tokens = annotate("for (int i; Foo *&foo : foos)");
+  ASSERT_EQ(Tokens.size(), 13u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::star, TT_PointerOrReference);
+  EXPECT_TOKEN(Tokens[7], tok::amp, TT_PointerOrReference);
+  EXPECT_TOKEN(Tokens[9], tok::colon, TT_RangeBasedForLoopColon);
+
   Tokens = annotate("#define FOO auto Foo = [] { f(a * b); };");
   ASSERT_EQ(Tokens.size(), 19u) << Tokens;
   EXPECT_TOKEN(Tokens[12], tok::star, TT_BinaryOperator);

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


[clang] [clang-format] Correctly annotate pointer/reference in range-for loop (PR #109361)

2024-09-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes

Fixes #109358.

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


2 Files Affected:

- (modified) clang/lib/Format/TokenAnnotator.cpp (+6) 
- (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+6) 


``diff
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 6f09835bad3a83..3f7ac6c7776f40 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1407,6 +1407,12 @@ class AnnotatingParser {
 }
   } else if (Contexts.back().ColonIsForRangeExpr) {
 Tok->setType(TT_RangeBasedForLoopColon);
+for (auto *Prev = Tok->Previous;
+ Prev && !Prev->isOneOf(tok::semi, tok::l_paren);
+ Prev = Prev->Previous) {
+  if (Prev->isPointerOrReference())
+Prev->setFinalizedType(TT_PointerOrReference);
+}
   } else if (Contexts.back().ContextType == Context::C11GenericSelection) {
 Tok->setType(TT_GenericSelectionColon);
   } else if (CurrentToken && CurrentToken->is(tok::numeric_constant)) {
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 34c03d668a9a0a..dfb6c060d32094 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -333,6 +333,12 @@ TEST_F(TokenAnnotatorTest, UnderstandsUsesOfStarAndAmp) {
   ASSERT_EQ(Tokens.size(), 17u) << Tokens;
   EXPECT_TOKEN(Tokens[11], tok::star, TT_BinaryOperator);
 
+  Tokens = annotate("for (int i; Foo *&foo : foos)");
+  ASSERT_EQ(Tokens.size(), 13u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::star, TT_PointerOrReference);
+  EXPECT_TOKEN(Tokens[7], tok::amp, TT_PointerOrReference);
+  EXPECT_TOKEN(Tokens[9], tok::colon, TT_RangeBasedForLoopColon);
+
   Tokens = annotate("#define FOO auto Foo = [] { f(a * b); };");
   ASSERT_EQ(Tokens.size(), 19u) << Tokens;
   EXPECT_TOKEN(Tokens[12], tok::star, TT_BinaryOperator);

``




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


[clang] [llvm] [clang] Add cc1 --output-asm-variant= to set output syntax (PR #109360)

2024-09-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Fangrui Song (MaskRay)


Changes

2fcaa549a824efeb56e807fcf750a56bf985296b (2010) added cc1as option
`-output-asm-variant` (untested) to set the output syntax.
`clang -cc1as -filetype asm -output-asm-variant 1` allows AT&T input and
Intel output.

This patch renames the cc1as option (to avoid collision with -o) and
makes it available for cc1 to set output syntax. This allows different
input & output syntax:

```
echo 'asm("mov $1, %eax");' | clang -xc - -S -o - -Xclang --output-asm-variant=1
```

Note: `AsmWriterFlavor` (with a misleading name), used to initialize
MCAsmInfo::AssemblerDialect, is primarily used for assembly input, not
for output.


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


7 Files Affected:

- (modified) clang/include/clang/Basic/CodeGenOptions.def (+1) 
- (modified) clang/include/clang/Driver/Options.td (+3-2) 
- (modified) clang/lib/CodeGen/BackendUtil.cpp (+2) 
- (added) clang/test/CodeGen/inline-asm-output-variant.c (+26) 
- (added) clang/test/Misc/cc1as-output-asm-variant.c (+8) 
- (modified) llvm/include/llvm/MC/MCTargetOptions.h (+2) 
- (modified) llvm/lib/CodeGen/LLVMTargetMachine.cpp (+3-1) 


``diff
diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index b600198998d85b..2893377e5a38be 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -96,6 +96,7 @@ CODEGENOPT(EmulatedTLS   , 1, 0) ///< Set by default or 
-f[no-]emulated-tls.
 ENUM_CODEGENOPT(EmbedBitcode, EmbedBitcodeKind, 2, Embed_Off)
 /// Inline asm dialect, -masm=(att|intel)
 ENUM_CODEGENOPT(InlineAsmDialect, InlineAsmDialectKind, 1, IAD_ATT)
+CODEGENOPT(OutputAsmVariant, 2, 3) ///< Set the asm variant for output (3: 
unspecified).
 CODEGENOPT(ForbidGuardVariables , 1, 0) ///< Issue errors if C++ guard 
variables
 ///< are required.
 CODEGENOPT(FunctionSections  , 1, 0) ///< Set when -ffunction-sections is 
enabled.
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index aa3ae92fb6ae78..2586782f3e3181 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -7209,6 +7209,9 @@ def fuse_ctor_homing: Flag<["-"], "fuse-ctor-homing">,
 def as_secure_log_file : Separate<["-"], "as-secure-log-file">,
   HelpText<"Emit .secure_log_unique directives to this filename.">,
   MarshallingInfoString>;
+def output_asm_variant : Joined<["--"], "output-asm-variant=">,
+  HelpText<"Select the asm variant (integer) to use for output">,
+  MarshallingInfoInt>;
 
 } // let Visibility = [CC1Option, CC1AsOption]
 
@@ -8303,8 +8306,6 @@ def filetype : Separate<["-"], "filetype">,
 HelpText<"Specify the output file type ('asm', 'null', or 'obj')">;
 
 // Transliterate Options
-def output_asm_variant : Separate<["-"], "output-asm-variant">,
-HelpText<"Select the asm variant index to use for output">;
 def show_encoding : Flag<["-"], "show-encoding">,
 HelpText<"Show instruction encoding information in transliterate mode">;
 def show_inst : Flag<["-"], "show-inst">,
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index fa49763e312f13..916c92adb89309 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -509,6 +509,8 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
   Options.MCOptions.X86RelaxRelocations = CodeGenOpts.X86RelaxRelocations;
   Options.MCOptions.CompressDebugSections =
   CodeGenOpts.getCompressDebugSections();
+  if (CodeGenOpts.OutputAsmVariant != 3) // 3 (default): not specified
+Options.MCOptions.OutputAsmVariant = CodeGenOpts.OutputAsmVariant;
   Options.MCOptions.ABIName = TargetOpts.ABI;
   for (const auto &Entry : HSOpts.UserEntries)
 if (!Entry.IsFramework &&
diff --git a/clang/test/CodeGen/inline-asm-output-variant.c 
b/clang/test/CodeGen/inline-asm-output-variant.c
new file mode 100644
index 00..5fc5c1cc09b016
--- /dev/null
+++ b/clang/test/CodeGen/inline-asm-output-variant.c
@@ -0,0 +1,26 @@
+// REQUIRES: x86-registered-target
+/// AT&T input
+// RUN: %clang_cc1 -triple x86_64 -S --output-asm-variant=0 %s -o - | 
FileCheck --check-prefix=ATT %s
+// RUN: %clang_cc1 -triple x86_64 -S --output-asm-variant=1 %s -o - | 
FileCheck --check-prefix=INTEL %s
+
+/// Intel input
+// RUN: %clang_cc1 -triple x86_64 -S -D INTEL -mllvm -x86-asm-syntax=intel 
-inline-asm=intel %s -o - | FileCheck --check-prefix=ATT %s
+// RUN: %clang_cc1 -triple x86_64 -S -D INTEL -mllvm -x86-asm-syntax=intel 
-inline-asm=intel --output-asm-variant=1 %s -o - | FileCheck 
--check-prefix=INTEL %s
+
+// ATT: movl $1, %eax
+// ATT: movl $2, %eax
+
+// INTEL: mov eax, 1
+// INTEL: mov eax, 2
+
+#ifdef INTEL
+asm("mov eax, 1");
+void foo() {
+  asm("mov eax, 2");
+}
+#else
+asm("mov $1, %eax");
+void foo() {
+  asm("mov

[clang] [llvm] [clang] Add cc1 --output-asm-variant= to set output syntax (PR #109360)

2024-09-19 Thread Fangrui Song via cfe-commits

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


[clang] [Clang][TableGen] Add explicit symbol visibility macros to code generated (PR #109362)

2024-09-19 Thread Thomas Fransham via cfe-commits

https://github.com/fsfod created 
https://github.com/llvm/llvm-project/pull/109362

Update ClangAttrEmitter TableGen to add explicit symbol visibility macros to 
class declarations it creates.
Both AnnotateFunctions and Attribute example plugins require 
clang::AnnotateAttr TableGen created functions to be exported from the Clang 
shared library.

>From 363e96ba9ed442698c134f7f716a667e65ba3dbb Mon Sep 17 00:00:00 2001
From: Thomas Fransham 
Date: Mon, 8 Jul 2024 01:48:46 +0100
Subject: [PATCH] [Clang][TableGen] Add explicit symbol visibility macros to
 code generated

Update ClangAttrEmitter tablegen to add explicit symbol visibility macros
to function declarations it creates.
Both AnnotateFunctions and Attribute example plugins require clang::AnnotateAttr
TableGen created functions to be exported from the Clang shared library.
---
 clang/utils/TableGen/ClangAttrEmitter.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 87be48c215e230..43c423eb033890 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -2762,7 +2762,7 @@ static void emitAttributes(const RecordKeeper &Records, 
raw_ostream &OS,
 }
 
 if (Header)
-  OS << "class " << R.getName() << "Attr : public " << SuperName << " {\n";
+  OS << "class CLANG_ABI " << R.getName() << "Attr : public " << SuperName 
<< " {\n";
 else
   OS << "\n// " << R.getName() << "Attr implementation\n\n";
 
@@ -3220,7 +3220,8 @@ void clang::EmitClangAttrClass(const RecordKeeper 
&Records, raw_ostream &OS) {
   emitSourceFileHeader("Attribute classes' definitions", OS, Records);
 
   OS << "#ifndef LLVM_CLANG_ATTR_CLASSES_INC\n";
-  OS << "#define LLVM_CLANG_ATTR_CLASSES_INC\n\n";
+  OS << "#define LLVM_CLANG_ATTR_CLASSES_INC\n";
+  OS << "#include \"clang/Support/Compiler.h\"\n\n";
 
   emitAttributes(Records, OS, true);
 

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


[clang] [Clang][TableGen] Add explicit symbol visibility macros to code generated (PR #109362)

2024-09-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Thomas Fransham (fsfod)


Changes

Update ClangAttrEmitter TableGen to add explicit symbol visibility macros to 
class declarations it creates.
Both AnnotateFunctions and Attribute example plugins require 
clang::AnnotateAttr TableGen created functions to be exported from the Clang 
shared library.

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


1 Files Affected:

- (modified) clang/utils/TableGen/ClangAttrEmitter.cpp (+3-2) 


``diff
diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 87be48c215e230..43c423eb033890 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -2762,7 +2762,7 @@ static void emitAttributes(const RecordKeeper &Records, 
raw_ostream &OS,
 }
 
 if (Header)
-  OS << "class " << R.getName() << "Attr : public " << SuperName << " {\n";
+  OS << "class CLANG_ABI " << R.getName() << "Attr : public " << SuperName 
<< " {\n";
 else
   OS << "\n// " << R.getName() << "Attr implementation\n\n";
 
@@ -3220,7 +3220,8 @@ void clang::EmitClangAttrClass(const RecordKeeper 
&Records, raw_ostream &OS) {
   emitSourceFileHeader("Attribute classes' definitions", OS, Records);
 
   OS << "#ifndef LLVM_CLANG_ATTR_CLASSES_INC\n";
-  OS << "#define LLVM_CLANG_ATTR_CLASSES_INC\n\n";
+  OS << "#define LLVM_CLANG_ATTR_CLASSES_INC\n";
+  OS << "#include \"clang/Support/Compiler.h\"\n\n";
 
   emitAttributes(Records, OS, true);
 

``




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


[clang] [Clang][TableGen] Add explicit symbol visibility macros to code generated (PR #109362)

2024-09-19 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 3b3accb598ec87a6a30b0e18ded06071030bb78f 
363e96ba9ed442698c134f7f716a667e65ba3dbb --extensions cpp -- 
clang/utils/TableGen/ClangAttrEmitter.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 43c423eb03..624b7d46fb 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -2762,7 +2762,8 @@ static void emitAttributes(const RecordKeeper &Records, 
raw_ostream &OS,
 }
 
 if (Header)
-  OS << "class CLANG_ABI " << R.getName() << "Attr : public " << SuperName 
<< " {\n";
+  OS << "class CLANG_ABI " << R.getName() << "Attr : public " << SuperName
+ << " {\n";
 else
   OS << "\n// " << R.getName() << "Attr implementation\n\n";
 

``




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


[clang] Reland "[Driver] Add toolchain for X86_64 UEFI target" (PR #109364)

2024-09-19 Thread Petr Hosek via cfe-commits

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


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


[clang] [clang] implement current direction of CWG2765 for string literal comparisons in constant evaluation (PR #109208)

2024-09-19 Thread Richard Smith via cfe-commits

https://github.com/zygoloid updated 
https://github.com/llvm/llvm-project/pull/109208

>From 81193568c17a89f6cf42f43a82fb1fbf0f90184d Mon Sep 17 00:00:00 2001
From: Richard Smith 
Date: Wed, 18 Sep 2024 21:59:56 +
Subject: [PATCH 01/11] Implement current CWG direction for string literal
 comparisons.

Track the identity of each string literal object produced by evaluation
with a global version number. Accept comparisons between literals of the
same version, and between literals of different versions that cannot
possibly be placed in overlapping storage. Treat the remaining
comparisons as non-constant.
---
 clang/include/clang/AST/ASTContext.h  |  11 ++
 .../include/clang/Basic/DiagnosticASTKinds.td |   2 +
 clang/lib/AST/ExprConstant.cpp| 119 +++---
 clang/test/AST/ByteCode/builtin-functions.cpp |   3 +-
 clang/test/AST/ByteCode/cxx20.cpp |  20 ++-
 clang/test/SemaCXX/builtins.cpp   |   2 +-
 .../SemaCXX/constant-expression-cxx11.cpp |  36 --
 7 files changed, 154 insertions(+), 39 deletions(-)

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index b65a1f7dff5bc1..6170bcd4f15ae3 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -324,6 +324,13 @@ class ASTContext : public RefCountedBase {
   /// This is lazily created.  This is intentionally not serialized.
   mutable llvm::StringMap StringLiteralCache;
 
+  /// The next string literal "version" to allocate during constant evaluation.
+  /// This is used to distinguish between repeated evaluations of the same
+  /// string literal.
+  ///
+  /// TODO: Ensure version numbers don't collide when deserialized.
+  unsigned NextStringLiteralVersion = 0;
+
   /// MD5 hash of CUID. It is calculated when first used and cached by this
   /// data member.
   mutable std::string CUIDHash;
@@ -3278,6 +3285,10 @@ class ASTContext : public RefCountedBase {
   /// PredefinedExpr to cache evaluated results.
   StringLiteral *getPredefinedStringLiteralFromCache(StringRef Key) const;
 
+  /// Return the next version number to be used for a string literal evaluated
+  /// as part of constant evaluation.
+  unsigned getNextStringLiteralVersion() { return NextStringLiteralVersion++; }
+
   /// Return a declaration for the global GUID object representing the given
   /// GUID value.
   MSGuidDecl *getMSGuidDecl(MSGuidDeclParts Parts) const;
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index 21a307d1e89878..76e693f6b4a6ca 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -96,6 +96,8 @@ def note_constexpr_pointer_constant_comparison : Note<
   "at runtime">;
 def note_constexpr_literal_comparison : Note<
   "comparison of addresses of literals has unspecified value">;
+def note_constexpr_opaque_call_comparison : Note<
+  "comparison against opaque constant has unspecified value">;
 def note_constexpr_pointer_weak_comparison : Note<
   "comparison against address of weak declaration '%0' can only be performed "
   "at runtime">;
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 6387e375dda79c..d9384a7c125a82 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -54,8 +54,10 @@
 #include "clang/Basic/DiagnosticSema.h"
 #include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/APFixedPoint.h"
+#include "llvm/ADT/Sequence.h"
 #include "llvm/ADT/SmallBitVector.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Casting.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/SaveAndRestore.h"
 #include "llvm/Support/SipHash.h"
@@ -2061,8 +2063,8 @@ static bool EvaluateIgnoredValue(EvalInfo &Info, const 
Expr *E) {
   return true;
 }
 
-/// Should this call expression be treated as a no-op?
-static bool IsNoOpCall(const CallExpr *E) {
+/// Should this call expression be treated as forming an opaque constant?
+static bool IsOpaqueConstantCall(const CallExpr *E) {
   unsigned Builtin = E->getBuiltinCallee();
   return (Builtin == Builtin::BI__builtin___CFStringMakeConstantString ||
   Builtin == Builtin::BI__builtin___NSStringMakeConstantString ||
@@ -2070,6 +2072,12 @@ static bool IsNoOpCall(const CallExpr *E) {
   Builtin == Builtin::BI__builtin_function_start);
 }
 
+static bool IsOpaqueConstantCall(const LValue &LVal) {
+  auto *BaseExpr =
+  llvm::dyn_cast_or_null(LVal.Base.dyn_cast());
+  return BaseExpr && IsOpaqueConstantCall(BaseExpr);
+}
+
 static bool IsGlobalLValue(APValue::LValueBase B) {
   // C++11 [expr.const]p3 An address constant expression is a prvalue core
   // constant expression of pointer type that evaluates to...
@@ -2115,7 +2123,7 @@ static bool IsGlobalLValue(APValue::LValueBase B) {
   case Expr::ObjCBoxedExprClass:
 return cast(E)->isExpressibleAsConstantInitializer();
   c

[clang] 3b3accb - [SystemZ][z/OS] Propagate IsText flag continuation

2024-09-19 Thread Abhina Sreeskantharajan via cfe-commits

Author: Abhina Sreeskantharajan
Date: 2024-09-19T15:16:08-04:00
New Revision: 3b3accb598ec87a6a30b0e18ded06071030bb78f

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

LOG: [SystemZ][z/OS] Propagate IsText flag continuation

Added: 


Modified: 
clang/lib/Serialization/ASTReader.cpp
llvm/lib/Support/FileCollector.cpp

Removed: 




diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index ad0551ee117a97..a8d073dee0246e 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -5318,7 +5318,7 @@ std::string ASTReader::getOriginalSourceFile(
   // Open the AST file.
   auto Buffer = FileMgr.getBufferForFile(ASTFileName, /*IsVolatile=*/false,
  /*RequiresNullTerminator=*/false,
- /*IsText=*/true);
+ /*IsText=*/false);
   if (!Buffer) {
 Diags.Report(diag::err_fe_unable_to_read_pch_file)
 << ASTFileName << Buffer.getError().message();

diff  --git a/llvm/lib/Support/FileCollector.cpp 
b/llvm/lib/Support/FileCollector.cpp
index fd4350da7f66a6..966c5ac90e9412 100644
--- a/llvm/lib/Support/FileCollector.cpp
+++ b/llvm/lib/Support/FileCollector.cpp
@@ -268,7 +268,7 @@ class FileCollectorFileSystem : public vfs::FileSystem {
   }
 
   llvm::ErrorOr>
-  openFileForRead(const Twine &Path, bool IsText) override {
+  openFileForRead(const Twine &Path, bool IsText = true) override {
 auto Result = FS->openFileForRead(Path, IsText);
 if (Result && *Result)
   Collector->addFile(Path);



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


[clang-tools-extra] [clang-tools-extra] Fix add_clang_library usage (PR #109321)

2024-09-19 Thread Thomas Fransham via cfe-commits

https://github.com/fsfod updated 
https://github.com/llvm/llvm-project/pull/109321

>From 41cfaf1dff9b47c3bb6755290aa23bedb80c9ef2 Mon Sep 17 00:00:00 2001
From: Thomas Fransham 
Date: Thu, 19 Sep 2024 16:53:20 +0100
Subject: [PATCH] [clang-tools-extra] Fix add_clang_library usage

If a add_clang_library call doesn't specify building as STATIC or SHARED 
library they are
implicitly added to the list static libraries that is linked in to clang-cpp 
shared library.
Because the clang-tools-extra libraries targets were declared after clang-cpp 
they
by luck never got linked to clang-cpp.
This change is required for clang symbol visibility macros on windows to work
correctly for clang tools since we need to distinguish if a target being built
will be importing or exporting clang symbols from the clang-cpp DLL.
---
 clang-tools-extra/clang-apply-replacements/CMakeLists.txt | 2 +-
 clang-tools-extra/clang-change-namespace/CMakeLists.txt   | 2 +-
 clang-tools-extra/clang-doc/CMakeLists.txt| 2 +-
 clang-tools-extra/clang-include-fixer/CMakeLists.txt  | 2 +-
 .../clang-include-fixer/find-all-symbols/CMakeLists.txt   | 2 +-
 clang-tools-extra/clang-include-fixer/plugin/CMakeLists.txt   | 2 +-
 clang-tools-extra/clang-move/CMakeLists.txt   | 2 +-
 clang-tools-extra/clang-query/CMakeLists.txt  | 2 +-
 clang-tools-extra/clang-reorder-fields/CMakeLists.txt | 2 +-
 clang-tools-extra/clang-tidy/CMakeLists.txt   | 2 +-
 clang-tools-extra/clang-tidy/abseil/CMakeLists.txt| 2 +-
 clang-tools-extra/clang-tidy/altera/CMakeLists.txt| 2 +-
 clang-tools-extra/clang-tidy/android/CMakeLists.txt   | 2 +-
 clang-tools-extra/clang-tidy/boost/CMakeLists.txt | 2 +-
 clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt  | 2 +-
 clang-tools-extra/clang-tidy/cert/CMakeLists.txt  | 2 +-
 clang-tools-extra/clang-tidy/concurrency/CMakeLists.txt   | 2 +-
 clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt | 2 +-
 clang-tools-extra/clang-tidy/darwin/CMakeLists.txt| 2 +-
 clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt   | 2 +-
 clang-tools-extra/clang-tidy/google/CMakeLists.txt| 2 +-
 clang-tools-extra/clang-tidy/hicpp/CMakeLists.txt | 2 +-
 clang-tools-extra/clang-tidy/linuxkernel/CMakeLists.txt   | 2 +-
 clang-tools-extra/clang-tidy/llvm/CMakeLists.txt  | 2 +-
 clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt  | 2 +-
 clang-tools-extra/clang-tidy/misc/CMakeLists.txt  | 2 +-
 clang-tools-extra/clang-tidy/modernize/CMakeLists.txt | 2 +-
 clang-tools-extra/clang-tidy/mpi/CMakeLists.txt   | 2 +-
 clang-tools-extra/clang-tidy/objc/CMakeLists.txt  | 2 +-
 clang-tools-extra/clang-tidy/openmp/CMakeLists.txt| 2 +-
 clang-tools-extra/clang-tidy/performance/CMakeLists.txt   | 2 +-
 clang-tools-extra/clang-tidy/plugin/CMakeLists.txt| 2 +-
 clang-tools-extra/clang-tidy/portability/CMakeLists.txt   | 2 +-
 clang-tools-extra/clang-tidy/readability/CMakeLists.txt   | 2 +-
 clang-tools-extra/clang-tidy/tool/CMakeLists.txt  | 2 +-
 clang-tools-extra/clang-tidy/utils/CMakeLists.txt | 2 +-
 clang-tools-extra/clang-tidy/zircon/CMakeLists.txt| 2 +-
 clang-tools-extra/clangd/CMakeLists.txt   | 2 +-
 clang-tools-extra/clangd/index/remote/CMakeLists.txt  | 2 +-
 .../clangd/index/remote/marshalling/CMakeLists.txt| 2 +-
 .../clangd/index/remote/unimplemented/CMakeLists.txt  | 2 +-
 clang-tools-extra/clangd/support/CMakeLists.txt   | 2 +-
 clang-tools-extra/clangd/tool/CMakeLists.txt  | 2 +-
 clang-tools-extra/clangd/xpc/CMakeLists.txt   | 4 ++--
 clang-tools-extra/include-cleaner/lib/CMakeLists.txt  | 2 +-
 45 files changed, 46 insertions(+), 46 deletions(-)

diff --git a/clang-tools-extra/clang-apply-replacements/CMakeLists.txt 
b/clang-tools-extra/clang-apply-replacements/CMakeLists.txt
index 93198ccbfc406f..551ded903e88a6 100644
--- a/clang-tools-extra/clang-apply-replacements/CMakeLists.txt
+++ b/clang-tools-extra/clang-apply-replacements/CMakeLists.txt
@@ -2,7 +2,7 @@ set(LLVM_LINK_COMPONENTS
   Support
   )
 
-add_clang_library(clangApplyReplacements
+add_clang_library(clangApplyReplacements STATIC
   lib/Tooling/ApplyReplacements.cpp
 
   DEPENDS
diff --git a/clang-tools-extra/clang-change-namespace/CMakeLists.txt 
b/clang-tools-extra/clang-change-namespace/CMakeLists.txt
index ded91edb8e34f0..62289ad031cfd6 100644
--- a/clang-tools-extra/clang-change-namespace/CMakeLists.txt
+++ b/clang-tools-extra/clang-change-namespace/CMakeLists.txt
@@ -3,7 +3,7 @@ set(LLVM_LINK_COMPONENTS
   Support
   )
 
-add_clang_library(clangChangeNamespace
+add_clang_library(clangChangeNamespace STATIC
   ChangeNamespace.cpp
 

[clang] [Driver] Add toolchain for X86_64 UEFI target (PR #76838)

2024-09-19 Thread Nico Weber via cfe-commits

nico wrote:

Looks like this breaks tests on Mac: http://45.33.8.238/macm1/92471/step_6.txt

Please take a look and revert for now if it takes a while to fix.

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


[clang] [clang][wasm] Replace the target iminmax intrinsics with the equivalent generic `__builtin_elementwise_min/max` intrinsics (PR #109259)

2024-09-19 Thread Thomas Lively via cfe-commits

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

Great, thank you!

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


[clang] [clang][wasm] Replace the target integer add saturate intrinsics with the equivalent generic `__builtin_elementwise_add_sat` intrinsics (PR #109269)

2024-09-19 Thread Thomas Lively via cfe-commits

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

LGTM. FWIW, I'm not aware of any special reason why `wasm_sub_sat` should be 
any different.

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


[clang] [HLSL] Array by-value assignment (PR #109323)

2024-09-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Sarah Spall (spall)


Changes

Make Constant Arrays in HLSL assignable. 
Closes #109043 

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


6 Files Affected:

- (modified) clang/include/clang/AST/CanonicalType.h (+1) 
- (modified) clang/lib/AST/ExprClassification.cpp (+2-1) 
- (modified) clang/lib/Sema/SemaOverload.cpp (+8-3) 
- (added) clang/test/AST/HLSL/ArrayAssignable.hlsl (+80) 
- (added) clang/test/CodeGenHLSL/ArrayAssignable.hlsl (+50) 
- (added) clang/test/SemaHLSL/ArrayAssignable_errors.hlsl (+29) 


``diff
diff --git a/clang/include/clang/AST/CanonicalType.h 
b/clang/include/clang/AST/CanonicalType.h
index dde08f0394c98d..6102eb01793530 100644
--- a/clang/include/clang/AST/CanonicalType.h
+++ b/clang/include/clang/AST/CanonicalType.h
@@ -299,6 +299,7 @@ class CanProxyBase {
   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isDependentType)
   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isOverloadableType)
   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isArrayType)
+  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isConstantArrayType)
   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasPointerRepresentation)
   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasObjCPointerRepresentation)
   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasIntegerRepresentation)
diff --git a/clang/lib/AST/ExprClassification.cpp 
b/clang/lib/AST/ExprClassification.cpp
index 5dde923312698f..9d97633309ada2 100644
--- a/clang/lib/AST/ExprClassification.cpp
+++ b/clang/lib/AST/ExprClassification.cpp
@@ -704,7 +704,8 @@ static Cl::ModifiableType IsModifiable(ASTContext &Ctx, 
const Expr *E,
 return Cl::CM_ConstAddrSpace;
 
   // Arrays are not modifiable, only their elements are.
-  if (CT->isArrayType())
+  if (CT->isArrayType() &&
+  !(Ctx.getLangOpts().HLSL && CT->isConstantArrayType()))
 return Cl::CM_ArrayType;
   // Incomplete types are not modifiable.
   if (CT->isIncompleteType())
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index d304f322aced64..ce503f9c69b411 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -2232,16 +2232,21 @@ static bool IsStandardConversion(Sema &S, Expr* From, 
QualType ToType,
 // just strip the qualifiers because they don't matter.
 FromType = FromType.getUnqualifiedType();
   } else if (S.getLangOpts().HLSL && FromType->isConstantArrayType() &&
- ToType->isArrayParameterType()) {
+ ToType->isConstantArrayType()) {
 // HLSL constant array parameters do not decay, so if the argument is a
 // constant array and the parameter is an ArrayParameterType we have 
special
 // handling here.
-FromType = S.Context.getArrayParameterType(FromType);
+if (ToType->isArrayParameterType()) {
+  FromType = S.Context.getArrayParameterType(FromType);
+  SCS.First = ICK_HLSL_Array_RValue;
+} else {
+  SCS.First = ICK_Identity;
+}
+
 if (S.Context.getCanonicalType(FromType) !=
 S.Context.getCanonicalType(ToType))
   return false;
 
-SCS.First = ICK_HLSL_Array_RValue;
 SCS.setAllToTypes(ToType);
 return true;
   } else if (FromType->isArrayType()) {
diff --git a/clang/test/AST/HLSL/ArrayAssignable.hlsl 
b/clang/test/AST/HLSL/ArrayAssignable.hlsl
new file mode 100644
index 00..52c9918aa85334
--- /dev/null
+++ b/clang/test/AST/HLSL/ArrayAssignable.hlsl
@@ -0,0 +1,80 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump %s 
| FileCheck %s
+
+// CHECK-LABEL: arr_assign1
+// CHECK: CompoundStmt 0x{{[0-9a-f]+}} {{.*}}
+// CHECK: DeclStmt 0x{{[0-9a-f]+}} {{.*}}
+// CHECK: VarDecl [[A:0x[0-9a-f]+]] {{.*}} col:7 used Arr 'int[2]' cinit
+// CHECK: InitListExpr 0x{{[0-9a-f]+}} {{.*}} 'int[2]'
+// CHECK: IntegerLiteral 0x{{[0-9a-f]+}} {{.*}} 'int' 0
+// CHECK: IntegerLiteral 0x{{[0-9a-f]+}} {{.*}} 'int' 1
+// CHECK: DeclStmt 0x{{[0-9a-f]+}} {{.*}}
+// CHECK: VarDecl [[B:0x[0-9a-f]+]] {{.*}} col:7 used Arr2 'int[2]' cinit
+// CHECK: InitListExpr 0x{{[0-9a-f]+}} {{.*}} 'int[2]'
+// CHECK: IntegerLiteral 0x{{[0-9a-f]+}} {{.*}} 'int' 0
+// CHECK: IntegerLiteral 0x{{[0-9a-f]+}} {{.*}} 'int' 0
+// CHECK: BinaryOperator 0x{{[0-9a-f]+}} {{.*}} 'int[2]' lvalue '='
+// CHECK: DeclRefExpr 0x{{[0-9a-f]+}} {{.*}} 'int[2]' lvalue Var [[A]] 'Arr' 
'int[2]'
+// CHECK: DeclRefExpr 0x{{[0-9a-f]+}} {{.*}} 'int[2]' lvalue Var [[B]] 'Arr2' 
'int[2]'
+void arr_assign1() {
+  int Arr[2] = {0, 1};
+  int Arr2[2] = {0, 0};
+  Arr = Arr2;
+}
+
+// CHECK-LABEL: arr_assign2
+// CHECK: CompoundStmt 0x{{[0-9a-f]+}} {{.*}}
+// CHECK: DeclStmt 0x{{[0-9a-f]+}} {{.*}}
+// CHECK: VarDecl [[A:0x[0-9a-f]+]] {{.*}} col:7 used Arr 'int[2]' cinit
+// CHECK: InitListExpr 0x{{[0-9a-f]+}} {{.*}} 'int[2]'
+// CHECK: IntegerLiteral 0x{{[0-9a-f]+}} {{.*}} 'int' 0
+// CHECK: IntegerLiteral 0x{{[0-9a-f]+}} {{.*}} 'int' 1
+// CHECK: DeclStmt 0x{{[0-9a-f]+}} {{.*}}
+// CHECK: VarDecl [[B:0x[0-9a-f]+

[clang] [HLSL] Array by-value assignment (PR #109323)

2024-09-19 Thread Sarah Spall via cfe-commits

https://github.com/spall created 
https://github.com/llvm/llvm-project/pull/109323

Make Constant Arrays in HLSL assignable. 
Closes #109043 

>From b24aed9771a415a4dc896c48cfc0481574a0773c Mon Sep 17 00:00:00 2001
From: Sarah Spall 
Date: Wed, 18 Sep 2024 22:19:07 +
Subject: [PATCH 1/2] enable array by value assignment

---
 clang/include/clang/AST/CanonicalType.h |  1 +
 clang/lib/AST/ExprClassification.cpp|  3 ++-
 clang/lib/Sema/SemaOverload.cpp | 11 ---
 3 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/AST/CanonicalType.h 
b/clang/include/clang/AST/CanonicalType.h
index dde08f0394c98d..6102eb01793530 100644
--- a/clang/include/clang/AST/CanonicalType.h
+++ b/clang/include/clang/AST/CanonicalType.h
@@ -299,6 +299,7 @@ class CanProxyBase {
   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isDependentType)
   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isOverloadableType)
   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isArrayType)
+  LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isConstantArrayType)
   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasPointerRepresentation)
   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasObjCPointerRepresentation)
   LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasIntegerRepresentation)
diff --git a/clang/lib/AST/ExprClassification.cpp 
b/clang/lib/AST/ExprClassification.cpp
index 5dde923312698f..9d97633309ada2 100644
--- a/clang/lib/AST/ExprClassification.cpp
+++ b/clang/lib/AST/ExprClassification.cpp
@@ -704,7 +704,8 @@ static Cl::ModifiableType IsModifiable(ASTContext &Ctx, 
const Expr *E,
 return Cl::CM_ConstAddrSpace;
 
   // Arrays are not modifiable, only their elements are.
-  if (CT->isArrayType())
+  if (CT->isArrayType() &&
+  !(Ctx.getLangOpts().HLSL && CT->isConstantArrayType()))
 return Cl::CM_ArrayType;
   // Incomplete types are not modifiable.
   if (CT->isIncompleteType())
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index d304f322aced64..ce503f9c69b411 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -2232,16 +2232,21 @@ static bool IsStandardConversion(Sema &S, Expr* From, 
QualType ToType,
 // just strip the qualifiers because they don't matter.
 FromType = FromType.getUnqualifiedType();
   } else if (S.getLangOpts().HLSL && FromType->isConstantArrayType() &&
- ToType->isArrayParameterType()) {
+ ToType->isConstantArrayType()) {
 // HLSL constant array parameters do not decay, so if the argument is a
 // constant array and the parameter is an ArrayParameterType we have 
special
 // handling here.
-FromType = S.Context.getArrayParameterType(FromType);
+if (ToType->isArrayParameterType()) {
+  FromType = S.Context.getArrayParameterType(FromType);
+  SCS.First = ICK_HLSL_Array_RValue;
+} else {
+  SCS.First = ICK_Identity;
+}
+
 if (S.Context.getCanonicalType(FromType) !=
 S.Context.getCanonicalType(ToType))
   return false;
 
-SCS.First = ICK_HLSL_Array_RValue;
 SCS.setAllToTypes(ToType);
 return true;
   } else if (FromType->isArrayType()) {

>From a81247d0992a3fb2376a9b3dc60e5fbfd782ffbf Mon Sep 17 00:00:00 2001
From: Sarah Spall 
Date: Thu, 19 Sep 2024 19:33:39 +
Subject: [PATCH 2/2] test assignable arrays

---
 clang/test/AST/HLSL/ArrayAssignable.hlsl  | 80 +++
 clang/test/CodeGenHLSL/ArrayAssignable.hlsl   | 50 
 .../test/SemaHLSL/ArrayAssignable_errors.hlsl | 29 +++
 3 files changed, 159 insertions(+)
 create mode 100644 clang/test/AST/HLSL/ArrayAssignable.hlsl
 create mode 100644 clang/test/CodeGenHLSL/ArrayAssignable.hlsl
 create mode 100644 clang/test/SemaHLSL/ArrayAssignable_errors.hlsl

diff --git a/clang/test/AST/HLSL/ArrayAssignable.hlsl 
b/clang/test/AST/HLSL/ArrayAssignable.hlsl
new file mode 100644
index 00..52c9918aa85334
--- /dev/null
+++ b/clang/test/AST/HLSL/ArrayAssignable.hlsl
@@ -0,0 +1,80 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump %s 
| FileCheck %s
+
+// CHECK-LABEL: arr_assign1
+// CHECK: CompoundStmt 0x{{[0-9a-f]+}} {{.*}}
+// CHECK: DeclStmt 0x{{[0-9a-f]+}} {{.*}}
+// CHECK: VarDecl [[A:0x[0-9a-f]+]] {{.*}} col:7 used Arr 'int[2]' cinit
+// CHECK: InitListExpr 0x{{[0-9a-f]+}} {{.*}} 'int[2]'
+// CHECK: IntegerLiteral 0x{{[0-9a-f]+}} {{.*}} 'int' 0
+// CHECK: IntegerLiteral 0x{{[0-9a-f]+}} {{.*}} 'int' 1
+// CHECK: DeclStmt 0x{{[0-9a-f]+}} {{.*}}
+// CHECK: VarDecl [[B:0x[0-9a-f]+]] {{.*}} col:7 used Arr2 'int[2]' cinit
+// CHECK: InitListExpr 0x{{[0-9a-f]+}} {{.*}} 'int[2]'
+// CHECK: IntegerLiteral 0x{{[0-9a-f]+}} {{.*}} 'int' 0
+// CHECK: IntegerLiteral 0x{{[0-9a-f]+}} {{.*}} 'int' 0
+// CHECK: BinaryOperator 0x{{[0-9a-f]+}} {{.*}} 'int[2]' lvalue '='
+// CHECK: DeclRefExpr 0x{{[0-9a-f]+}} {{.*}} 'int[2]' lvalue Var [[A]] 'Arr' 
'int[2]'
+// CHECK: DeclRefExpr 0x{{[0-9a-f]+}} {{.*}} 'int[2]' lvalue Var [[B]] 'Arr2' 
'

[clang] [llvm] [clang][OpenMP] Add codegen for scope directive (PR #109197)

2024-09-19 Thread David Pagan via cfe-commits

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


[clang] [Clang] - Add libclangSerialization to clang driver unittests (PR #109329)

2024-09-19 Thread Pranav Bhandarkar via cfe-commits

https://github.com/bhandarkar-pranav created 
https://github.com/llvm/llvm-project/pull/109329

This PR is a fix for issue 
[#109328](https://github.com/llvm/llvm-project/issues/109328). 
libclangSerializaton.so is needed for building clang driver unittests after
https://github.com/llvm/llvm-project/pull/76838 was merged.

>From e81b6f5ad0ad987a8b6478d19335cc428f3fa635 Mon Sep 17 00:00:00 2001
From: Pranav Bhandarkar 
Date: Thu, 19 Sep 2024 15:16:18 -0500
Subject: [PATCH] [Clang] - Add libclangSerialization to clang driver unittests

This PR is a fix for issue #109328. libclangSerializaton.so is
needed for building clang driver unittests after
https://github.com/llvm/llvm-project/pull/76838 was merged.
---
 clang/unittests/Driver/CMakeLists.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/unittests/Driver/CMakeLists.txt 
b/clang/unittests/Driver/CMakeLists.txt
index 752037f78fb147..efdd07ea238890 100644
--- a/clang/unittests/Driver/CMakeLists.txt
+++ b/clang/unittests/Driver/CMakeLists.txt
@@ -22,4 +22,5 @@ clang_target_link_libraries(ClangDriverTests
   clangDriver
   clangBasic
   clangFrontend # For TextDiagnosticPrinter.
+  clangSerialization
   )

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


[clang] [Clang] - Add libclangSerialization to clang driver unittests (PR #109329)

2024-09-19 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-driver

Author: Pranav Bhandarkar (bhandarkar-pranav)


Changes

This PR is a fix for issue [#109328](https://github.com/llvm/llvm-project/issues/109328). 
libclangSerializaton.so is needed for building clang driver unittests after
https://github.com/llvm/llvm-project/pull/76838 was merged.

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


1 Files Affected:

- (modified) clang/unittests/Driver/CMakeLists.txt (+1) 


``diff
diff --git a/clang/unittests/Driver/CMakeLists.txt 
b/clang/unittests/Driver/CMakeLists.txt
index 752037f78fb147..efdd07ea238890 100644
--- a/clang/unittests/Driver/CMakeLists.txt
+++ b/clang/unittests/Driver/CMakeLists.txt
@@ -22,4 +22,5 @@ clang_target_link_libraries(ClangDriverTests
   clangDriver
   clangBasic
   clangFrontend # For TextDiagnosticPrinter.
+  clangSerialization
   )

``




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


[clang] [Clang] - Add libclangSerialization to clang driver unittests (PR #109329)

2024-09-19 Thread Pranav Bhandarkar via cfe-commits

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


[clang] [Driver] Add toolchain for X86_64 UEFI target (PR #76838)

2024-09-19 Thread Pranav Bhandarkar via cfe-commits

bhandarkar-pranav wrote:

Hi @Prabhuk, 
I am seeing this issue https://github.com/llvm/llvm-project/issues/109328 after 
this PR. Here is a proposed 
[fix](https://github.com/llvm/llvm-project/pull/109329). Could you please check?

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


[clang] [analyzer] [MallocChecker] Fix Store modification in `checkPreCall` (PR #109337)

2024-09-19 Thread Pavel Skripkin via cfe-commits

https://github.com/pskrgag created 
https://github.com/llvm/llvm-project/pull/109337

This is small follow-up for #106081

While trying to add sanity check for `Enviroment` and `Store` being consistent 
during `checkPostCall` and `checkPreCall` I found out that `MallocChecker` 
still violates that rule. 

The problem lies in `FreeMemAux`, which invalidates freed region while being 
called from `preGetdelim`. This invalidation was added to prevent "use of 
uninitialized memory" for malloc and friends while `unix.Malloc` is disabled.

Fix adds another bool flag to `FreeMemAux` to control invalidation from 
call-site and set it to false in `preGetdelim`



>From 2645cf0333590c6d30b93958494e6b4f60b423c4 Mon Sep 17 00:00:00 2001
From: Pavel Skripkin 
Date: Fri, 20 Sep 2024 00:21:03 +0300
Subject: [PATCH 1/2] make MallocChecker not modify state in checkPreCall

---
 .../StaticAnalyzer/Checkers/MallocChecker.cpp | 55 ++-
 1 file changed, 30 insertions(+), 25 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index 81ec8e1b516986..7a265d3bbcda47 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -668,7 +668,8 @@ class MallocChecker
   [[nodiscard]] ProgramStateRef
   FreeMemAux(CheckerContext &C, const CallEvent &Call, ProgramStateRef State,
  unsigned Num, bool Hold, bool &IsKnownToBeAllocated,
- AllocationFamily Family, bool ReturnsNullOnFailure = false) const;
+ AllocationFamily Family, bool Invalidate = true,
+ bool ReturnsNullOnFailure = false) const;
 
   /// Models memory deallocation.
   ///
@@ -694,7 +695,8 @@ class MallocChecker
   [[nodiscard]] ProgramStateRef
   FreeMemAux(CheckerContext &C, const Expr *ArgExpr, const CallEvent &Call,
  ProgramStateRef State, bool Hold, bool &IsKnownToBeAllocated,
- AllocationFamily Family, bool ReturnsNullOnFailure = false,
+ AllocationFamily Family, bool Invalidate = true,
+ bool ReturnsNullOnFailure = false,
  std::optional ArgValOpt = {}) const;
 
   // TODO: Needs some refactoring, as all other deallocation modeling
@@ -1474,9 +1476,10 @@ void MallocChecker::preGetdelim(ProgramStateRef State, 
const CallEvent &Call,
   // We do not need this value here, as FreeMemAux will take care
   // of reporting any violation of the preconditions.
   bool IsKnownToBeAllocated = false;
-  State = FreeMemAux(C, Call.getArgExpr(0), Call, State, false,
- IsKnownToBeAllocated, AllocationFamily(AF_Malloc), false,
- LinePtr);
+  State =
+  FreeMemAux(C, Call.getArgExpr(0), Call, State, false,
+ IsKnownToBeAllocated, AllocationFamily(AF_Malloc),
+ /*Invalidate=*/false, /*ReturnsNullOnFailure=*/false, 
LinePtr);
   if (State)
 C.addTransition(State);
 }
@@ -1793,6 +1796,7 @@ void MallocChecker::checkPostObjCMessage(const 
ObjCMethodCall &Call,
   ProgramStateRef State = FreeMemAux(C, Call.getArgExpr(0), Call, C.getState(),
  /*Hold=*/true, IsKnownToBeAllocatedMemory,
  AllocationFamily(AF_Malloc),
+ /*Invalidate=*/false,
  /*ReturnsNullOnFailure=*/true);
 
   C.addTransition(State);
@@ -1986,12 +1990,11 @@ ProgramStateRef 
MallocChecker::FreeMemAttr(CheckerContext &C,
   return State;
 }
 
-ProgramStateRef MallocChecker::FreeMemAux(CheckerContext &C,
-  const CallEvent &Call,
-  ProgramStateRef State, unsigned Num,
-  bool Hold, bool 
&IsKnownToBeAllocated,
-  AllocationFamily Family,
-  bool ReturnsNullOnFailure) const {
+ProgramStateRef
+MallocChecker::FreeMemAux(CheckerContext &C, const CallEvent &Call,
+  ProgramStateRef State, unsigned Num, bool Hold,
+  bool &IsKnownToBeAllocated, AllocationFamily Family,
+  bool Invalidate, bool ReturnsNullOnFailure) const {
   if (!State)
 return nullptr;
 
@@ -1999,7 +2002,8 @@ ProgramStateRef MallocChecker::FreeMemAux(CheckerContext 
&C,
 return nullptr;
 
   return FreeMemAux(C, Call.getArgExpr(Num), Call, State, Hold,
-IsKnownToBeAllocated, Family, ReturnsNullOnFailure);
+IsKnownToBeAllocated, Family, Invalidate,
+ReturnsNullOnFailure);
 }
 
 /// Checks if the previous call to free on the given symbol failed - if free
@@ -2134,12 +2138,11 @@ static void printExpectedDeallocName(raw_ostream &os, 
AllocationFamily Family) {
   }
 }
 
-ProgramStateRef
-MallocChecker::FreeMemAux(CheckerContext &C, const Expr *Arg

[clang] [llvm] [BPF] Add load-acquire and store-release instructions under -mcpu=v5 (PR #108636)

2024-09-19 Thread Peilin Ye via cfe-commits

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


[clang] Reland "[Driver] Add toolchain for X86_64 UEFI target" (PR #109364)

2024-09-19 Thread via cfe-commits

https://github.com/Prabhuk created 
https://github.com/llvm/llvm-project/pull/109364

Reverts llvm/llvm-project#109340

Addressing the failed MAC Clang unit test as part of this reland.

>From b83aea6a5853a5a532d9203cc90ee96dfedc418f Mon Sep 17 00:00:00 2001
From: Prabhuk 
Date: Thu, 19 Sep 2024 19:53:59 -0700
Subject: [PATCH] Revert "Revert "[Driver] Add toolchain for X86_64 UEFI
 target" (#109340)"

This reverts commit d2df2e41cae1413050935d6d27094569c29c473f.
---
 clang/lib/Basic/Targets.cpp   |  3 +
 clang/lib/Basic/Targets/OSTargets.h   | 15 
 clang/lib/Basic/Targets/X86.h | 37 ++
 clang/lib/Driver/CMakeLists.txt   |  1 +
 clang/lib/Driver/Driver.cpp   |  4 ++
 clang/lib/Driver/ToolChains/UEFI.cpp  | 88 +++
 clang/lib/Driver/ToolChains/UEFI.h| 59 +++
 clang/test/CodeGen/X86/uefi-data-layout.c |  3 +
 clang/test/Driver/uefi-constructed-args.c | 13 
 clang/unittests/Driver/ToolChainTest.cpp  | 21 ++
 10 files changed, 244 insertions(+)
 create mode 100644 clang/lib/Driver/ToolChains/UEFI.cpp
 create mode 100644 clang/lib/Driver/ToolChains/UEFI.h
 create mode 100644 clang/test/CodeGen/X86/uefi-data-layout.c
 create mode 100644 clang/test/Driver/uefi-constructed-args.c

diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index 0b8e565345b6a4..4917ef015941be 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -613,6 +613,9 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple &Triple,
 case llvm::Triple::Solaris:
   return std::make_unique>(Triple,
Opts);
+case llvm::Triple::UEFI:
+  return std::make_unique(Triple, Opts);
+
 case llvm::Triple::Win32: {
   switch (Triple.getEnvironment()) {
   case llvm::Triple::Cygnus:
diff --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index 0a4f06967fff5a..a83d6464e789d6 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -778,6 +778,21 @@ class LLVM_LIBRARY_VISIBILITY ZOSTargetInfo : public 
OSTargetInfo {
   }
 };
 
+// UEFI target
+template 
+class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo {
+protected:
+  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
+MacroBuilder &Builder) const override {}
+
+public:
+  UEFITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
+  : OSTargetInfo(Triple, Opts) {
+this->WCharType = TargetInfo::UnsignedShort;
+this->WIntType = TargetInfo::UnsignedShort;
+  }
+};
+
 void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts,
MacroBuilder &Builder);
 
diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index 79fd5867cf6673..a99ae62984c7d5 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -814,6 +814,43 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public 
X86TargetInfo {
   }
 };
 
+// x86-64 UEFI target
+class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo
+: public UEFITargetInfo {
+public:
+  UEFIX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
+  : UEFITargetInfo(Triple, Opts) {
+this->TheCXXABI.set(TargetCXXABI::Microsoft);
+this->MaxTLSAlign = 8192u * this->getCharWidth();
+this->resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-"
+  "i64:64-i128:128-f80:128-n8:16:32:64-S128");
+  }
+
+  void getTargetDefines(const LangOptions &Opts,
+MacroBuilder &Builder) const override {
+getOSDefines(Opts, X86TargetInfo::getTriple(), Builder);
+  }
+
+  BuiltinVaListKind getBuiltinVaListKind() const override {
+return TargetInfo::CharPtrBuiltinVaList;
+  }
+
+  CallingConvCheckResult checkCallingConvention(CallingConv CC) const override 
{
+switch (CC) {
+case CC_C:
+case CC_Win64:
+  return CCCR_OK;
+default:
+  return CCCR_Warning;
+}
+  }
+
+  TargetInfo::CallingConvKind
+  getCallingConvKind(bool ClangABICompat4) const override {
+return CCK_MicrosoftWin64;
+  }
+};
+
 // x86-64 Windows target
 class LLVM_LIBRARY_VISIBILITY WindowsX86_64TargetInfo
 : public WindowsTargetInfo {
diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt
index 32a4378ab499fa..4fd10bf671512f 100644
--- a/clang/lib/Driver/CMakeLists.txt
+++ b/clang/lib/Driver/CMakeLists.txt
@@ -78,6 +78,7 @@ add_clang_library(clangDriver
   ToolChains/Solaris.cpp
   ToolChains/SPIRV.cpp
   ToolChains/TCE.cpp
+  ToolChains/UEFI.cpp
   ToolChains/VEToolchain.cpp
   ToolChains/WebAssembly.cpp
   ToolChains/XCore.cpp
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 1c64ceabad1bf4..44548fa9d706fb 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -45,6 +45,7 @@
 

[clang] Reland "[Driver] Add toolchain for X86_64 UEFI target" (PR #109364)

2024-09-19 Thread via cfe-commits

https://github.com/Prabhuk updated 
https://github.com/llvm/llvm-project/pull/109364

>From b83aea6a5853a5a532d9203cc90ee96dfedc418f Mon Sep 17 00:00:00 2001
From: Prabhuk 
Date: Thu, 19 Sep 2024 19:53:59 -0700
Subject: [PATCH 1/2] Revert "Revert "[Driver] Add toolchain for X86_64 UEFI
 target" (#109340)"

This reverts commit d2df2e41cae1413050935d6d27094569c29c473f.
---
 clang/lib/Basic/Targets.cpp   |  3 +
 clang/lib/Basic/Targets/OSTargets.h   | 15 
 clang/lib/Basic/Targets/X86.h | 37 ++
 clang/lib/Driver/CMakeLists.txt   |  1 +
 clang/lib/Driver/Driver.cpp   |  4 ++
 clang/lib/Driver/ToolChains/UEFI.cpp  | 88 +++
 clang/lib/Driver/ToolChains/UEFI.h| 59 +++
 clang/test/CodeGen/X86/uefi-data-layout.c |  3 +
 clang/test/Driver/uefi-constructed-args.c | 13 
 clang/unittests/Driver/ToolChainTest.cpp  | 21 ++
 10 files changed, 244 insertions(+)
 create mode 100644 clang/lib/Driver/ToolChains/UEFI.cpp
 create mode 100644 clang/lib/Driver/ToolChains/UEFI.h
 create mode 100644 clang/test/CodeGen/X86/uefi-data-layout.c
 create mode 100644 clang/test/Driver/uefi-constructed-args.c

diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index 0b8e565345b6a4..4917ef015941be 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -613,6 +613,9 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple &Triple,
 case llvm::Triple::Solaris:
   return std::make_unique>(Triple,
Opts);
+case llvm::Triple::UEFI:
+  return std::make_unique(Triple, Opts);
+
 case llvm::Triple::Win32: {
   switch (Triple.getEnvironment()) {
   case llvm::Triple::Cygnus:
diff --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index 0a4f06967fff5a..a83d6464e789d6 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -778,6 +778,21 @@ class LLVM_LIBRARY_VISIBILITY ZOSTargetInfo : public 
OSTargetInfo {
   }
 };
 
+// UEFI target
+template 
+class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo {
+protected:
+  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
+MacroBuilder &Builder) const override {}
+
+public:
+  UEFITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
+  : OSTargetInfo(Triple, Opts) {
+this->WCharType = TargetInfo::UnsignedShort;
+this->WIntType = TargetInfo::UnsignedShort;
+  }
+};
+
 void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts,
MacroBuilder &Builder);
 
diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index 79fd5867cf6673..a99ae62984c7d5 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -814,6 +814,43 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public 
X86TargetInfo {
   }
 };
 
+// x86-64 UEFI target
+class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo
+: public UEFITargetInfo {
+public:
+  UEFIX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
+  : UEFITargetInfo(Triple, Opts) {
+this->TheCXXABI.set(TargetCXXABI::Microsoft);
+this->MaxTLSAlign = 8192u * this->getCharWidth();
+this->resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-"
+  "i64:64-i128:128-f80:128-n8:16:32:64-S128");
+  }
+
+  void getTargetDefines(const LangOptions &Opts,
+MacroBuilder &Builder) const override {
+getOSDefines(Opts, X86TargetInfo::getTriple(), Builder);
+  }
+
+  BuiltinVaListKind getBuiltinVaListKind() const override {
+return TargetInfo::CharPtrBuiltinVaList;
+  }
+
+  CallingConvCheckResult checkCallingConvention(CallingConv CC) const override 
{
+switch (CC) {
+case CC_C:
+case CC_Win64:
+  return CCCR_OK;
+default:
+  return CCCR_Warning;
+}
+  }
+
+  TargetInfo::CallingConvKind
+  getCallingConvKind(bool ClangABICompat4) const override {
+return CCK_MicrosoftWin64;
+  }
+};
+
 // x86-64 Windows target
 class LLVM_LIBRARY_VISIBILITY WindowsX86_64TargetInfo
 : public WindowsTargetInfo {
diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt
index 32a4378ab499fa..4fd10bf671512f 100644
--- a/clang/lib/Driver/CMakeLists.txt
+++ b/clang/lib/Driver/CMakeLists.txt
@@ -78,6 +78,7 @@ add_clang_library(clangDriver
   ToolChains/Solaris.cpp
   ToolChains/SPIRV.cpp
   ToolChains/TCE.cpp
+  ToolChains/UEFI.cpp
   ToolChains/VEToolchain.cpp
   ToolChains/WebAssembly.cpp
   ToolChains/XCore.cpp
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 1c64ceabad1bf4..44548fa9d706fb 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -45,6 +45,7 @@
 #include "ToolChains/SPIRV.h"
 #include "ToolChains/Solaris.h"
 #include "ToolChains/TCE.h"
+#inc

[clang] [llvm] [DirectX] Remove trivially dead functions at linkage finalize (PR #106146)

2024-09-19 Thread Greg Roth via cfe-commits


@@ -19,20 +19,20 @@
 using namespace llvm;
 
 static bool finalizeLinkage(Module &M) {
-  SmallPtrSet EntriesAndExports;
+  SmallPtrSet Funcs;
 
   // Find all entry points and export functions
   for (Function &EF : M.functions()) {
-if (!EF.hasFnAttribute("hlsl.shader") && !EF.hasFnAttribute("hlsl.export"))
+if (EF.hasFnAttribute("hlsl.shader") || EF.hasFnAttribute("hlsl.export"))
   continue;
-EntriesAndExports.insert(&EF);
+Funcs.insert(&EF);
   }
 
-  for (Function &F : M.functions()) {
-if (F.getLinkage() == GlobalValue::ExternalLinkage &&
-!EntriesAndExports.contains(&F)) {
-  F.setLinkage(GlobalValue::InternalLinkage);
-}
+  for (Function *F : Funcs) {
+if (F->getLinkage() == GlobalValue::ExternalLinkage)
+  F->setLinkage(GlobalValue::InternalLinkage);
+if (F->hasFnAttribute(Attribute::AlwaysInline) && F->isDefTriviallyDead())

pow2clk wrote:

Yes probably. I backed away from doing that because removing this would require 
changing a lot of unrelated tests in llvm/test/CodeGen/DirectX so their 
funcions have some reason to stick around under the new rules. That would 
generally mean creating new calls to them or explicitly marking them noinline. 
Under ordinary circumstances, I expect alwaysinline to be set on all but the 
entry function anyway. It's not a very strong reason, but that's why I did it. 

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


  1   2   3   4   5   >