[PATCH] D151696: [x86] Remove CPU_SPECIFIC* MACROs and add getManglingForCPU

2023-06-14 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe added a comment.

This patch means to remove `CPU_SPECIFIC*` MACROs in X86TargetParser.def and 
move that part of functionality into X86TargetParser.cpp.
Since these two files **both** maintain a table with `cpuname`, `features of 
this cpu supported`, ... This move can reduce the codes.

CPU_SPECIFIC* has some different and specific information maintained. This 
patch dealt with them in these ways when moving:

1. mangling This is now moved to `Mangling` in `ProcInfo` and directly 
initialized at array of `Processors`. CPUs don't support cpu_dispatch/specific 
are assigned '\0' as mangling. This patch also supports some of new intel cpus 
for cpu_dispatch/specific feature.
2. alias relationship The alias cpu will also be initialized in array of 
`Processors`, its attributes will be same as its alias target cpu. Same feature 
list, same mangling.
3. TUNE_NAME Before my change, some cpu names support cpu_dispatch/specific are 
not supported in X86.td, which means optimizer/backend doesn't recognize them. 
So they use a different TUNE_NAME to generate in IR. In this patch, I added 
these missing cpu support at X86.td by utilize existing Features and 
XXXTunings. So that each cpu name can directly use its own name as TUNE_NAME to 
be supported by optimizer/backend.
4. Feature list The feature list of one CPU maintained in X86TargetParser.def 
is not same as the one in X86TargetParser.cpp. It only maintains part of 
features of one CPU(Features defined by X86_FEATURE_COMPAT). While 
X86TargetParser.cpp maintains a complete one. This patch abandons the feature 
list maintained in X86TargetParser.def because assigning a CPU with a complete 
feature list in X86TargetParser.cpp doesn't affect the functionality of 
cpu_dispatch/specific. See the implement of llvm::X86::getCpuSupportsMask, it 
already masked out the features not defined by X86_FEATURE_COMPAT.

Beyond these four information, since some of CPUs supported by 
cpu_dispatch/specific doesn's support clang options like `-march`, `-mtune` 
before, this patch also kept this behavior still by adding another member 
`OnlyForCPUSpecificDispath` in `ProcInfo`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151696/new/

https://reviews.llvm.org/D151696

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


[PATCH] D151696: [x86] Remove CPU_SPECIFIC* MACROs and add getManglingForCPU

2023-06-14 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe updated this revision to Diff 531615.
FreddyYe added a comment.

misc refine.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151696/new/

https://reviews.llvm.org/D151696

Files:
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/attr-cpuspecific-avx-abi.c
  clang/test/CodeGen/attr-cpuspecific.c
  llvm/include/llvm/TargetParser/X86TargetParser.def
  llvm/include/llvm/TargetParser/X86TargetParser.h
  llvm/lib/Target/X86/X86.td
  llvm/lib/TargetParser/X86TargetParser.cpp
  llvm/test/CodeGen/X86/cpus-intel.ll

Index: llvm/test/CodeGen/X86/cpus-intel.ll
===
--- llvm/test/CodeGen/X86/cpus-intel.ll
+++ llvm/test/CodeGen/X86/cpus-intel.ll
@@ -23,6 +23,32 @@
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=grandridge 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=graniterapids 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=emeraldrapids 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=generic 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_ii 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_iii 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_iii_no_xmm_regs 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_m 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_mmx 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_pro 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_4 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_4_sse3 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=core_2_duo_ssse3 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=core_2_duo_sse4_1 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=atom_sse4_2 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=atom_sse4_2_movbe 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=goldmont_plus 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=core_i7_sse4_2 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=core_aes_pclmulqdq 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=core_2nd_gen_avx 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=core_3rd_gen_avx 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=core_4th_gen_avx 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=core_4th_gen_avx_tsx 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=core_5th_gen_avx 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=core_5th_gen_avx_tsx 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=skylake_avx512 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=icelake_client 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=icelake_server 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=mic_avx512 2>&1 | 

[PATCH] D148697: [clang-tidy] Add more checks for functions which should be noexcept

2023-06-14 Thread Christian Ulmann via Phabricator via cfe-commits
Dinistro added a comment.

Sorry for the noise. I didn't pull in between the different runs and was still 
on the broken version.
Thanks for fixing this issue :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148697/new/

https://reviews.llvm.org/D148697

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


[PATCH] D152782: [CodeGen] Remove unused declaration/function GetOrCreateRTTIProxyGlobalVariable

2023-06-14 Thread Kazu Hirata via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8fd80d1d1366: [CodeGen] Remove unused function 
GetOrCreateRTTIProxyGlobalVariable (authored by kazu).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152782/new/

https://reviews.llvm.org/D152782

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h


Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -590,8 +590,6 @@
   MetadataTypeMap VirtualMetadataIdMap;
   MetadataTypeMap GeneralizedMetadataIdMap;
 
-  llvm::DenseMap RTTIProxyMap;
-
   // Helps squashing blocks of TopLevelStmtDecl into a single llvm::Function
   // when used with -fincremental-extensions.
   std::pair, const TopLevelStmtDecl *>
@@ -1503,9 +1501,6 @@
   std::vector
   getMostBaseClasses(const CXXRecordDecl *RD);
 
-  llvm::GlobalVariable *
-  GetOrCreateRTTIProxyGlobalVariable(llvm::Constant *Addr);
-
   /// Get the declaration of std::terminate for the platform.
   llvm::FunctionCallee getTerminateFn();
 
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -2028,22 +2028,6 @@
   return MostBases.takeVector();
 }
 
-llvm::GlobalVariable *
-CodeGenModule::GetOrCreateRTTIProxyGlobalVariable(llvm::Constant *Addr) {
-  auto It = RTTIProxyMap.find(Addr);
-  if (It != RTTIProxyMap.end())
-return It->second;
-
-  auto *FTRTTIProxy = new llvm::GlobalVariable(
-  TheModule, Addr->getType(),
-  /*isConstant=*/true, llvm::GlobalValue::PrivateLinkage, Addr,
-  "__llvm_rtti_proxy");
-  FTRTTIProxy->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
-
-  RTTIProxyMap[Addr] = FTRTTIProxy;
-  return FTRTTIProxy;
-}
-
 void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
llvm::Function *F) {
   llvm::AttrBuilder B(F->getContext());


Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -590,8 +590,6 @@
   MetadataTypeMap VirtualMetadataIdMap;
   MetadataTypeMap GeneralizedMetadataIdMap;
 
-  llvm::DenseMap RTTIProxyMap;
-
   // Helps squashing blocks of TopLevelStmtDecl into a single llvm::Function
   // when used with -fincremental-extensions.
   std::pair, const TopLevelStmtDecl *>
@@ -1503,9 +1501,6 @@
   std::vector
   getMostBaseClasses(const CXXRecordDecl *RD);
 
-  llvm::GlobalVariable *
-  GetOrCreateRTTIProxyGlobalVariable(llvm::Constant *Addr);
-
   /// Get the declaration of std::terminate for the platform.
   llvm::FunctionCallee getTerminateFn();
 
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -2028,22 +2028,6 @@
   return MostBases.takeVector();
 }
 
-llvm::GlobalVariable *
-CodeGenModule::GetOrCreateRTTIProxyGlobalVariable(llvm::Constant *Addr) {
-  auto It = RTTIProxyMap.find(Addr);
-  if (It != RTTIProxyMap.end())
-return It->second;
-
-  auto *FTRTTIProxy = new llvm::GlobalVariable(
-  TheModule, Addr->getType(),
-  /*isConstant=*/true, llvm::GlobalValue::PrivateLinkage, Addr,
-  "__llvm_rtti_proxy");
-  FTRTTIProxy->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
-
-  RTTIProxyMap[Addr] = FTRTTIProxy;
-  return FTRTTIProxy;
-}
-
 void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
llvm::Function *F) {
   llvm::AttrBuilder B(F->getContext());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 8fd80d1 - [CodeGen] Remove unused function GetOrCreateRTTIProxyGlobalVariable

2023-06-14 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-06-14T22:04:40-07:00
New Revision: 8fd80d1d136685688ff49c9d80552bbb7addbda4

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

LOG: [CodeGen] Remove unused function GetOrCreateRTTIProxyGlobalVariable

The last use was removed by:

  commit 46f366494f3ca8cc98daa6fb4f29c7c446c176b6
  Author: Fangrui Song 
  Date:   Sat May 20 08:24:20 2023 -0700

This patch also removes RTTIProxyMap, which becomes unused once I
remove GetOrCreateRTTIProxyGlobalVariable.

Differential Revision: https://reviews.llvm.org/D152782

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenModule.h

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index dd8c384d13171..8b2fa5eaf5ba1 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -2028,22 +2028,6 @@ CodeGenModule::getMostBaseClasses(const CXXRecordDecl 
*RD) {
   return MostBases.takeVector();
 }
 
-llvm::GlobalVariable *
-CodeGenModule::GetOrCreateRTTIProxyGlobalVariable(llvm::Constant *Addr) {
-  auto It = RTTIProxyMap.find(Addr);
-  if (It != RTTIProxyMap.end())
-return It->second;
-
-  auto *FTRTTIProxy = new llvm::GlobalVariable(
-  TheModule, Addr->getType(),
-  /*isConstant=*/true, llvm::GlobalValue::PrivateLinkage, Addr,
-  "__llvm_rtti_proxy");
-  FTRTTIProxy->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
-
-  RTTIProxyMap[Addr] = FTRTTIProxy;
-  return FTRTTIProxy;
-}
-
 void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
llvm::Function *F) {
   llvm::AttrBuilder B(F->getContext());

diff  --git a/clang/lib/CodeGen/CodeGenModule.h 
b/clang/lib/CodeGen/CodeGenModule.h
index 43d61b40f76b4..2d2cce8337195 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -590,8 +590,6 @@ class CodeGenModule : public CodeGenTypeCache {
   MetadataTypeMap VirtualMetadataIdMap;
   MetadataTypeMap GeneralizedMetadataIdMap;
 
-  llvm::DenseMap RTTIProxyMap;
-
   // Helps squashing blocks of TopLevelStmtDecl into a single llvm::Function
   // when used with -fincremental-extensions.
   std::pair, const TopLevelStmtDecl *>
@@ -1503,9 +1501,6 @@ class CodeGenModule : public CodeGenTypeCache {
   std::vector
   getMostBaseClasses(const CXXRecordDecl *RD);
 
-  llvm::GlobalVariable *
-  GetOrCreateRTTIProxyGlobalVariable(llvm::Constant *Addr);
-
   /// Get the declaration of std::terminate for the platform.
   llvm::FunctionCallee getTerminateFn();
 



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


[PATCH] D152321: [clang] Replace use of Type::getPointerTo() (NFC)

2023-06-14 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 added a comment.

I guess you need to rebase onto 066fb7a5 
 at least.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152321/new/

https://reviews.llvm.org/D152321

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


[PATCH] D152696: Prevent deadlocks in death tests.

2023-06-14 Thread Martin Böhme via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdfbcee286b9b: Prevent deadlocks in death tests. (authored by 
mboehme).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152696/new/

https://reviews.llvm.org/D152696

Files:
  third-party/unittest/UnitTestMain/TestMain.cpp


Index: third-party/unittest/UnitTestMain/TestMain.cpp
===
--- third-party/unittest/UnitTestMain/TestMain.cpp
+++ third-party/unittest/UnitTestMain/TestMain.cpp
@@ -29,6 +29,10 @@
 true /* Disable crash reporting 
*/);
   }
 
+  // Use the "threadsafe" test style for death tests -- the "fast" test style
+  // can cause deadlocks.
+  testing::GTEST_FLAG(death_test_style) = "threadsafe";
+
   // Initialize both gmock and gtest.
   testing::InitGoogleMock(, argv);
 


Index: third-party/unittest/UnitTestMain/TestMain.cpp
===
--- third-party/unittest/UnitTestMain/TestMain.cpp
+++ third-party/unittest/UnitTestMain/TestMain.cpp
@@ -29,6 +29,10 @@
 true /* Disable crash reporting */);
   }
 
+  // Use the "threadsafe" test style for death tests -- the "fast" test style
+  // can cause deadlocks.
+  testing::GTEST_FLAG(death_test_style) = "threadsafe";
+
   // Initialize both gmock and gtest.
   testing::InitGoogleMock(, argv);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137524: clang/AMDGPU: Emit atomicrmw for atomic_inc/dec builtins

2023-06-14 Thread Pravin Jagtap via Phabricator via cfe-commits
pravinjagtap accepted this revision as: pravinjagtap.
pravinjagtap added a comment.

LGTM, In the context of atomic optimizer, when we extend the support for 
`atomicInc` and `atomicDec`, I think, the visitor of AtomicRMWInst will find 
the potential candidate for optimization now instead of visitor of 
IntrinsicInst because of this change. Right ?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137524/new/

https://reviews.llvm.org/D137524

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


[PATCH] D152321: [clang] Replace use of Type::getPointerTo() (NFC)

2023-06-14 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 accepted this revision.
barannikov88 added a comment.
This revision is now accepted and ready to land.

LGTM with CI fixed, thanks.
I'd like @nikic to also take a look though.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152321/new/

https://reviews.llvm.org/D152321

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


[PATCH] D152880: [clang][NFC] Add a notice to desugarForDiagnostic

2023-06-14 Thread Younan Zhang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0e08374abb2c: [clang][NFC] Add a notice to 
desugarForDiagnostic (authored by zyounan).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152880/new/

https://reviews.llvm.org/D152880

Files:
  clang/include/clang/AST/ASTDiagnostic.h
  clang/lib/AST/ASTDiagnostic.cpp


Index: clang/lib/AST/ASTDiagnostic.cpp
===
--- clang/lib/AST/ASTDiagnostic.cpp
+++ clang/lib/AST/ASTDiagnostic.cpp
@@ -25,7 +25,8 @@
 using namespace clang;
 
 // Returns a desugared version of the QualType, and marks ShouldAKA as true
-// whenever we remove significant sugar from the type.
+// whenever we remove significant sugar from the type. Make sure ShouldAKA
+// is initialized before passing it in.
 QualType clang::desugarForDiagnostic(ASTContext , QualType QT,
  bool ) {
   QualifierCollector QC;
Index: clang/include/clang/AST/ASTDiagnostic.h
===
--- clang/include/clang/AST/ASTDiagnostic.h
+++ clang/include/clang/AST/ASTDiagnostic.h
@@ -34,7 +34,8 @@
   ArrayRef QualTypeVals);
 
   /// Returns a desugared version of the QualType, and marks ShouldAKA as true
-  /// whenever we remove significant sugar from the type.
+  /// whenever we remove significant sugar from the type. Make sure ShouldAKA
+  /// is initialized before passing it in.
   QualType desugarForDiagnostic(ASTContext , QualType QT,
 bool );
 }  // end namespace clang


Index: clang/lib/AST/ASTDiagnostic.cpp
===
--- clang/lib/AST/ASTDiagnostic.cpp
+++ clang/lib/AST/ASTDiagnostic.cpp
@@ -25,7 +25,8 @@
 using namespace clang;
 
 // Returns a desugared version of the QualType, and marks ShouldAKA as true
-// whenever we remove significant sugar from the type.
+// whenever we remove significant sugar from the type. Make sure ShouldAKA
+// is initialized before passing it in.
 QualType clang::desugarForDiagnostic(ASTContext , QualType QT,
  bool ) {
   QualifierCollector QC;
Index: clang/include/clang/AST/ASTDiagnostic.h
===
--- clang/include/clang/AST/ASTDiagnostic.h
+++ clang/include/clang/AST/ASTDiagnostic.h
@@ -34,7 +34,8 @@
   ArrayRef QualTypeVals);
 
   /// Returns a desugared version of the QualType, and marks ShouldAKA as true
-  /// whenever we remove significant sugar from the type.
+  /// whenever we remove significant sugar from the type. Make sure ShouldAKA
+  /// is initialized before passing it in.
   QualType desugarForDiagnostic(ASTContext , QualType QT,
 bool );
 }  // end namespace clang
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 0e08374 - [clang][NFC] Add a notice to desugarForDiagnostic

2023-06-14 Thread Younan Zhang via cfe-commits

Author: Younan Zhang
Date: 2023-06-15T11:55:06+08:00
New Revision: 0e08374abb2c61a3ae5c24d5f60be3b548da9778

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

LOG: [clang][NFC] Add a notice to desugarForDiagnostic

`desugarForDiagnostic` only sets ShouldAKA to true if desugaring
happens, otherwise ShouldAKA is left intact and might be uninitialized.

Victims (including me):

https://github.com/llvm/llvm-project/commit/25bf8cb3c0e3c41231289a6ff0a37b6d49b24011

https://github.com/llvm/llvm-project/commit/0e8384a0fe4f03d60cd92aba1cae074512481ca2

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D152880

Added: 


Modified: 
clang/include/clang/AST/ASTDiagnostic.h
clang/lib/AST/ASTDiagnostic.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTDiagnostic.h 
b/clang/include/clang/AST/ASTDiagnostic.h
index 4cd9097517258..ef22249828629 100644
--- a/clang/include/clang/AST/ASTDiagnostic.h
+++ b/clang/include/clang/AST/ASTDiagnostic.h
@@ -34,7 +34,8 @@ namespace clang {
   ArrayRef QualTypeVals);
 
   /// Returns a desugared version of the QualType, and marks ShouldAKA as true
-  /// whenever we remove significant sugar from the type.
+  /// whenever we remove significant sugar from the type. Make sure ShouldAKA
+  /// is initialized before passing it in.
   QualType desugarForDiagnostic(ASTContext , QualType QT,
 bool );
 }  // end namespace clang

diff  --git a/clang/lib/AST/ASTDiagnostic.cpp b/clang/lib/AST/ASTDiagnostic.cpp
index 08877aa12c024..f96a4fa3c35b0 100644
--- a/clang/lib/AST/ASTDiagnostic.cpp
+++ b/clang/lib/AST/ASTDiagnostic.cpp
@@ -25,7 +25,8 @@
 using namespace clang;
 
 // Returns a desugared version of the QualType, and marks ShouldAKA as true
-// whenever we remove significant sugar from the type.
+// whenever we remove significant sugar from the type. Make sure ShouldAKA
+// is initialized before passing it in.
 QualType clang::desugarForDiagnostic(ASTContext , QualType QT,
  bool ) {
   QualifierCollector QC;



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


[PATCH] D152279: [Driver] Default -msmall-data-limit= to 0

2023-06-14 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Thank you for chiming in. I disagree that we keep default=8 for embedded 
without understanding (a) why 8 provides values and (b) justifying that the 
value is significant enough for embedded to be different.

I think Alex's argument "I think we can generally expect more willingness for 
people targeting embedded systems to explore different compiler flags" is 
actually a +1 to decrease the complexity here.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152279/new/

https://reviews.llvm.org/D152279

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


[PATCH] D152279: [Driver] Default -msmall-data-limit= to 0

2023-06-14 Thread Shiva Chen via Phabricator via cfe-commits
shiva0217 added a comment.

In D152279#4422887 , @MaskRay wrote:

> In D152279#4420312 , @asb wrote:
>
>> In D152279#4415974 , @MaskRay 
>> wrote:
>>
>>> However, RISC-V `-msmall-data-limit=` is probably a case warranting a 
>>> difference.
>>> The global pointer relaxation has a very limited value (benchmarked by 
>>> multiple parties, including a party which implemented this feature in the 
>>> GNU toolchain: even they can only say the optimization only applies to very 
>>> specific projects).
>>> The default value is confusing: as explained by the summary.
>>>
>>> I suspect that `-msmall-data-limit=8` is too conservative, maybe 16 would 
>>> be better, I don't know. I think global pointer relaxation users should 
>>> toggle this by themselves, not relying on `0` or `8` default decided by a 
>>> bunch of strange conditions.
>>
>> I don't disagree that the small data limit being 8 rather than something 
>> else doesn't seem to be particularly well motivated, but I understand that 
>> the case where the option does make a difference is on embedded targets (I 
>> think the data that was shared before was for SPEC, but could be wrong?). I 
>> think we can generally expect more willingness for people targeting embedded 
>> systems to explore different compiler flags,
>
> Agree.
>
>> but just matching gcc does feel like a better default. What do you think 
>> about keeping the default for bare metal targets?
>
> I am unsure we want to add the complexity and refrain from changing the 
> default for bare metal targets due to haunted graveyards 
> https://www.usenix.org/sites/default/files/conference/protected-files/srecon17americas_slides_reese.pdf
>
> We are already different from GCC in a number of ways:
>
> - for `-fpie`, we may emit `.sdata`/`.sbss` but GCC won't
> - we accept `-G` while GCC doesn't.
> - we don't emit `.srodata`.
>
> I made a comment on https://lists.riscv.org/g/sig-toolchains/message/619 and 
> informed GCC folks in case they can change the default as well.
> If they don't, I think we made a good choice for not following this 
> particular behavior.
>
> (I feel sad that I did not see D57497  and 
> it landed with a blocked review. If we started from scratch, we would 
> probably run into a cleaner state.)

Hi MaskRay,

-fpie is an oversight. Thanks for pointing out. For D57497 
, I thought it behave as good community 
citizen that trying to address all the comments.
Is there unaddressing comment? If there is, that might not be intended.

The patch tries to mimic the GCC to enable the relaxation. It generally put the 
data smaller than the threshold to the small data section which near gp and has 
higher possibility to transfer to gp based load/store.

Relaxation is less useful for large scale software. In previous time, most 
developers focus on embedded worlds. Now the flags become less friendly for the 
OS world.
I agree to change the default to make the OS world life easier.

I also agree with Alex. Should we preserve the threshold for embedded usage? 
Should we try to sync with GCC as possible?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152279/new/

https://reviews.llvm.org/D152279

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


[PATCH] D152924: [libLTO][AIX] Respect `-f[no]-integrated-as` on AIX

2023-06-14 Thread ChenZheng via Phabricator via cfe-commits
shchenz added a comment.

@qiongsiwu1 Hi, thanks for the patch. Almost good to me, except one small nit.




Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:700
+CmdArgs.push_back(Args.MakeArgString(
+Twine(PluginOptPrefix) + "-no-integrated-as=" + NoIntegratedAs));
+  else if (!UseIntegratedAs) {

Seems other options leverage the default value in the back end, for example the 
default value for `DisableIntegratedAS` in backend is false, so when the front 
end requires integrated-as, maybe we can save the option here?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152924/new/

https://reviews.llvm.org/D152924

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


[PATCH] D151349: [HIP] emit macro `__HIP_NO_IMAGE_SUPPORT`

2023-06-14 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc0f0d50653e1: [HIP] emit macro `__HIP_NO_IMAGE_SUPPORT` 
(authored by yaxunl).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D151349?vs=529644=531597#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151349/new/

https://reviews.llvm.org/D151349

Files:
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Basic/Targets/AMDGPU.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/test/Driver/hip-macros.hip
  llvm/lib/TargetParser/TargetParser.cpp

Index: llvm/lib/TargetParser/TargetParser.cpp
===
--- llvm/lib/TargetParser/TargetParser.cpp
+++ llvm/lib/TargetParser/TargetParser.cpp
@@ -279,6 +279,7 @@
   Features["gfx10-3-insts"] = true;
   Features["gfx11-insts"] = true;
   Features["atomic-fadd-rtn-insts"] = true;
+  Features["image-insts"] = true;
   break;
 case GK_GFX1036:
 case GK_GFX1035:
@@ -301,6 +302,7 @@
   Features["gfx9-insts"] = true;
   Features["gfx10-insts"] = true;
   Features["gfx10-3-insts"] = true;
+  Features["image-insts"] = true;
   Features["s-memrealtime"] = true;
   Features["s-memtime-inst"] = true;
   break;
@@ -322,6 +324,7 @@
   Features["gfx8-insts"] = true;
   Features["gfx9-insts"] = true;
   Features["gfx10-insts"] = true;
+  Features["image-insts"] = true;
   Features["s-memrealtime"] = true;
   Features["s-memtime-inst"] = true;
   break;
@@ -333,7 +336,27 @@
   Features["atomic-ds-pk-add-16-insts"] = true;
   Features["atomic-flat-pk-add-16-insts"] = true;
   Features["atomic-global-pk-add-bf16-inst"] = true;
-  [[fallthrough]];
+  Features["gfx90a-insts"] = true;
+  Features["atomic-buffer-global-pk-add-f16-insts"] = true;
+  Features["atomic-fadd-rtn-insts"] = true;
+  Features["dot3-insts"] = true;
+  Features["dot4-insts"] = true;
+  Features["dot5-insts"] = true;
+  Features["dot6-insts"] = true;
+  Features["mai-insts"] = true;
+  Features["dl-insts"] = true;
+  Features["dot1-insts"] = true;
+  Features["dot2-insts"] = true;
+  Features["dot7-insts"] = true;
+  Features["dot10-insts"] = true;
+  Features["gfx9-insts"] = true;
+  Features["gfx8-insts"] = true;
+  Features["16-bit-insts"] = true;
+  Features["dpp"] = true;
+  Features["s-memrealtime"] = true;
+  Features["ci-insts"] = true;
+  Features["s-memtime-inst"] = true;
+  break;
 case GK_GFX90A:
   Features["gfx90a-insts"] = true;
   Features["atomic-buffer-global-pk-add-f16-insts"] = true;
@@ -381,6 +404,7 @@
 case GK_GFX602:
 case GK_GFX601:
 case GK_GFX600:
+  Features["image-insts"] = true;
   Features["s-memtime-inst"] = true;
   break;
 case GK_NONE:
Index: clang/test/Driver/hip-macros.hip
===
--- clang/test/Driver/hip-macros.hip
+++ clang/test/Driver/hip-macros.hip
@@ -42,3 +42,22 @@
 // WARN-CUMODE-NOT: warning: ignoring '-mno-cumode' option as it is not currently supported for processor 'gfx906' [-Woption-ignored]
 // CUMODE-ON-DAG: #define __AMDGCN_CUMODE__ 1
 // CUMODE-OFF-DAG: #define __AMDGCN_CUMODE__ 0
+
+// RUN: %clang -E -dM --offload-arch=gfx90a --cuda-device-only -nogpuinc -nogpulib \
+// RUN:   %s 2>&1 | FileCheck --check-prefixes=IMAGE,NOWARN %s
+// RUN: %clang -E -dM --offload-arch=gfx1100 --cuda-device-only -nogpuinc -nogpulib \
+// RUN:   %s 2>&1 | FileCheck --check-prefixes=IMAGE,NOWARN %s
+// RUN: %clang -E -dM --offload-arch=gfx940 --cuda-device-only -nogpuinc -nogpulib \
+// RUN:   %s 2>&1 | FileCheck --check-prefixes=NOIMAGE,NOWARN %s
+// RUN: %clang -E -dM --offload-arch=gfx941 --cuda-device-only -nogpuinc -nogpulib \
+// RUN:   %s 2>&1 | FileCheck --check-prefixes=NOIMAGE,NOWARN %s
+// RUN: %clang -E -dM --offload-arch=gfx942 --cuda-device-only -nogpuinc -nogpulib \
+// RUN:   %s 2>&1 | FileCheck --check-prefixes=NOIMAGE,NOWARN %s
+// RUN: %clang -E -dM --offload-arch=gfx1100 --cuda-device-only -nogpuinc -nogpulib \
+// RUN:   -Xclang -target-feature -Xclang "-image-insts" %s 2>&1 | FileCheck --check-prefixes=IMAGE,WARN %s
+// RUN: %clang -E -dM --offload-arch=gfx940 --cuda-device-only -nogpuinc -nogpulib \
+// RUN:   -Xclang -target-feature -Xclang "+image-insts" %s 2>&1 | FileCheck --check-prefixes=NOIMAGE,WARN %s
+// NOWARN-NOT: warning
+// WARN: warning: feature flag '{{[+|-]}}image-insts' is ignored since the feature is read only [-Winvalid-command-line-argument]
+// IMAGE-NOT: #define __HIP_NO_IMAGE_SUPPORT
+// NOIMAGE: #define 

[clang] c0f0d50 - [HIP] emit macro `__HIP_NO_IMAGE_SUPPORT`

2023-06-14 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2023-06-14T22:53:41-04:00
New Revision: c0f0d50653e16145beee474a3d0d602596502dde

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

LOG: [HIP] emit macro `__HIP_NO_IMAGE_SUPPORT`

HIP texture/image support is optional as some devices
do not have image instructions. A macro __HIP_NO_IMAGE_SUPPORT
is defined for device not supporting images 
(https://github.com/ROCm-Developer-Tools/HIP/blob/d0448aa4c4dd0f4b29ccf6a663b7f5ad9f5183e0/docs/reference/kernel_language.md?plain=1#L426
 )

Currently the macro is defined by HIP header based on predefined macros
for GPU, e.g __gfx*__ , which is error prone. This patch let clang
emit the predefined macro.

Reviewed by: Matt Arsenault, Artem Belevich

Differential Revision: https://reviews.llvm.org/D151349

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticFrontendKinds.td
clang/include/clang/Basic/TargetInfo.h
clang/lib/Basic/TargetInfo.cpp
clang/lib/Basic/Targets/AMDGPU.cpp
clang/lib/Basic/Targets/AMDGPU.h
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Frontend/InitPreprocessor.cpp
clang/test/Driver/hip-macros.hip
llvm/lib/TargetParser/TargetParser.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 3a71d67d72792..9ed9a88fa3d62 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -55,6 +55,9 @@ def warn_fe_backend_unsupported_fp_exceptions : Warning<
 def warn_fe_backend_invalid_feature_flag : Warning<
 "feature flag '%0' must start with either '+' to enable the feature or '-'"
 " to disable it; flag ignored">, InGroup;
+def warn_fe_backend_readonly_feature_flag : Warning<
+"feature flag '%0' is ignored since the feature is read only">,
+InGroup;
 
 def err_incompatible_fp_eval_method_options : Error<
 "option 'ffp-eval-method' cannot be used with option "

diff  --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 2f59a79a8c64a..41ef47eb565b1 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -29,6 +29,7 @@
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSet.h"
 #include "llvm/Frontend/OpenMP/OMPGridValues.h"
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
@@ -267,6 +268,12 @@ class TargetInfo : public TransferrableTargetInfo,
   // as a DataLayout object.
   void resetDataLayout(StringRef DL, const char *UserLabelPrefix = "");
 
+  // Target features that are read-only and should not be disabled/enabled
+  // by command line options. Such features are for emitting predefined
+  // macros or checking availability of builtin functions and can be omitted
+  // in function attributes in IR.
+  llvm::StringSet<> ReadOnlyFeatures;
+
 public:
   /// Construct a target for the given options.
   ///
@@ -1394,6 +1401,11 @@ class TargetInfo : public TransferrableTargetInfo,
 return false;
   }
 
+  /// Determine whether the given target feature is read only.
+  bool isReadOnlyFeature(StringRef Feature) const {
+return ReadOnlyFeatures.count(Feature);
+  }
+
   /// Identify whether this target supports multiversioning of functions,
   /// which requires support for cpu_supports and cpu_is functionality.
   bool supportsMultiVersioning() const {
@@ -1711,6 +1723,9 @@ class TargetInfo : public TransferrableTargetInfo,
: std::optional();
   }
 
+  /// Whether to support HIP image/texture API's.
+  virtual bool hasHIPImageSupport() const { return true; }
+
 protected:
   /// Copy type and layout related info.
   void copyAuxTarget(const TargetInfo *Aux);

diff  --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index 6cd5d618a4aca..3f0c9d672f718 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -528,6 +528,8 @@ bool TargetInfo::initFeatureMap(
 // Apply the feature via the target.
 if (Name[0] != '+' && Name[0] != '-')
   Diags.Report(diag::warn_fe_backend_invalid_feature_flag) << Name;
+else if (isReadOnlyFeature(Name.substr(1)))
+  Diags.Report(diag::warn_fe_backend_readonly_feature_flag) << Name;
 else
   setFeatureEnabled(Features, Name.substr(1), Name[0] == '+');
   }

diff  --git a/clang/lib/Basic/Targets/AMDGPU.cpp 
b/clang/lib/Basic/Targets/AMDGPU.cpp
index 1a85a5675cf1e..7025c7c484001 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -244,6 +244,7 @@ AMDGPUTargetInfo::AMDGPUTargetInfo(const llvm::Triple 
,
 
   MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 

[PATCH] D151696: [WIP] Remove CPU_SPECIFIC* MACROs and use unified getManglingForCPU

2023-06-14 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe updated this revision to Diff 531596.
FreddyYe added a comment.

Update to a more conservative change.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151696/new/

https://reviews.llvm.org/D151696

Files:
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/attr-cpuspecific-avx-abi.c
  clang/test/CodeGen/attr-cpuspecific.c
  llvm/include/llvm/TargetParser/X86TargetParser.def
  llvm/include/llvm/TargetParser/X86TargetParser.h
  llvm/lib/Target/X86/X86.td
  llvm/lib/TargetParser/X86TargetParser.cpp
  llvm/test/CodeGen/X86/cpus-intel.ll

Index: llvm/test/CodeGen/X86/cpus-intel.ll
===
--- llvm/test/CodeGen/X86/cpus-intel.ll
+++ llvm/test/CodeGen/X86/cpus-intel.ll
@@ -23,6 +23,32 @@
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=grandridge 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=graniterapids 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=emeraldrapids 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=generic 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_ii 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_iii 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_iii_no_xmm_regs 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_m 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_mmx 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_pro 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_4 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_4_sse3 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=core_2_duo_ssse3 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=core_2_duo_sse4_1 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=atom_sse4_2 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=atom_sse4_2_movbe 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=goldmont_plus 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=core_i7_sse4_2 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=core_aes_pclmulqdq 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=core_2nd_gen_avx 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=core_3rd_gen_avx 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=core_4th_gen_avx 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=core_4th_gen_avx_tsx 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=core_5th_gen_avx 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=core_5th_gen_avx_tsx 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=skylake_avx512 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=icelake_client 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=icelake_server 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null 

[PATCH] D152989: Pre-commit test for D151696.

2023-06-14 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe created this revision.
Herald added a project: All.
FreddyYe requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Meanwhile this patch added missing tests for supported CPU names
of cpu_dispatch/specific attribute.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152989

Files:
  clang/test/CodeGen/attr-cpuspecific-cpus.c

Index: clang/test/CodeGen/attr-cpuspecific-cpus.c
===
--- /dev/null
+++ clang/test/CodeGen/attr-cpuspecific-cpus.c
@@ -0,0 +1,240 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s
+// RUN: %clang_cc1 -triple x86_64-windows-pc -fms-compatibility -emit-llvm -o - %s
+
+#ifdef _WIN64
+#define ATTR(X) __declspec(X)
+#else
+#define ATTR(X) __attribute__((X))
+#endif // _MSC_VER
+
+ATTR(cpu_dispatch(generic, pentium))
+void Version1(void);
+ATTR(cpu_specific(generic))
+void Version1(void){}
+ATTR(cpu_specific(pentium))
+void Version1(void){}
+
+ATTR(cpu_dispatch(generic, pentium_pro))
+void Version2(void);
+ATTR(cpu_specific(generic))
+void Version2(void){}
+ATTR(cpu_specific(pentium_pro))
+void Version2(void){}
+
+ATTR(cpu_dispatch(generic, pentium_mmx))
+void Version3(void);
+ATTR(cpu_specific(generic))
+void Version3(void){}
+ATTR(cpu_specific(pentium_mmx))
+void Version3(void){}
+
+ATTR(cpu_dispatch(generic, pentium_ii))
+void Version4(void);
+ATTR(cpu_specific(generic))
+void Version4(void){}
+ATTR(cpu_specific(pentium_ii))
+void Version4(void){}
+
+ATTR(cpu_dispatch(generic, pentium_iii))
+void Version5(void);
+ATTR(cpu_specific(generic))
+void Version5(void){}
+ATTR(cpu_specific(pentium_iii))
+void Version5(void){}
+
+ATTR(cpu_dispatch(generic, pentium_iii_no_xmm_regs))
+void Version6(void);
+ATTR(cpu_specific(generic))
+void Version6(void){}
+ATTR(cpu_specific(pentium_iii_no_xmm_regs))
+void Version6(void){}
+
+ATTR(cpu_dispatch(generic, pentium_4))
+void Version7(void);
+ATTR(cpu_specific(generic))
+void Version7(void){}
+ATTR(cpu_specific(pentium_4))
+void Version7(void){}
+
+ATTR(cpu_dispatch(generic, pentium_m))
+void Version8(void);
+ATTR(cpu_specific(generic))
+void Version8(void){}
+ATTR(cpu_specific(pentium_m))
+void Version8(void){}
+
+ATTR(cpu_dispatch(generic, pentium_4_sse3))
+void Version9(void);
+ATTR(cpu_specific(generic))
+void Version9(void){}
+ATTR(cpu_specific(pentium_4_sse3))
+void Version9(void){}
+
+ATTR(cpu_dispatch(generic, core_2_duo_ssse3))
+void Version10(void);
+ATTR(cpu_specific(generic))
+void Version10(void){}
+ATTR(cpu_specific(core_2_duo_ssse3))
+void Version10(void){}
+
+ATTR(cpu_dispatch(generic, core_2_duo_sse4_1))
+void Version11(void);
+ATTR(cpu_specific(generic))
+void Version11(void){}
+ATTR(cpu_specific(core_2_duo_sse4_1))
+void Version11(void){}
+
+ATTR(cpu_dispatch(generic, atom))
+void Version12(void);
+ATTR(cpu_specific(generic))
+void Version12(void){}
+ATTR(cpu_specific(atom))
+void Version12(void){}
+
+ATTR(cpu_dispatch(generic, atom_sse4_2))
+void Version13(void);
+ATTR(cpu_specific(generic))
+void Version13(void){}
+ATTR(cpu_specific(atom_sse4_2))
+void Version13(void){}
+
+ATTR(cpu_dispatch(generic, core_i7_sse4_2))
+void Version14(void);
+ATTR(cpu_specific(generic))
+void Version14(void){}
+ATTR(cpu_specific(core_i7_sse4_2))
+void Version14(void){}
+
+ATTR(cpu_dispatch(generic, core_aes_pclmulqdq))
+void Version15(void);
+ATTR(cpu_specific(generic))
+void Version15(void){}
+ATTR(cpu_specific(core_aes_pclmulqdq))
+void Version15(void){}
+
+ATTR(cpu_dispatch(generic, atom_sse4_2_movbe))
+void Version16(void);
+ATTR(cpu_specific(generic))
+void Version16(void){}
+ATTR(cpu_specific(atom_sse4_2_movbe))
+void Version16(void){}
+
+ATTR(cpu_dispatch(generic, goldmont))
+void Version17(void);
+ATTR(cpu_specific(generic))
+void Version17(void){}
+ATTR(cpu_specific(goldmont))
+void Version17(void){}
+
+ATTR(cpu_dispatch(generic, sandybridge))
+void Version18(void);
+ATTR(cpu_specific(generic))
+void Version18(void){}
+ATTR(cpu_specific(sandybridge))
+void Version18(void){}
+
+ATTR(cpu_dispatch(generic, core_2nd_gen_avx))
+void Version19(void);
+ATTR(cpu_specific(generic))
+void Version19(void){}
+ATTR(cpu_specific(core_2nd_gen_avx))
+void Version19(void){}
+
+ATTR(cpu_dispatch(generic, ivybridge))
+void Version20(void);
+ATTR(cpu_specific(generic))
+void Version20(void){}
+ATTR(cpu_specific(ivybridge))
+void Version20(void){}
+
+ATTR(cpu_dispatch(generic, core_3rd_gen_avx))
+void Version21(void);
+ATTR(cpu_specific(generic))
+void Version21(void){}
+ATTR(cpu_specific(core_3rd_gen_avx))
+void Version21(void){}
+
+ATTR(cpu_dispatch(generic, haswell))
+void Version22(void);
+ATTR(cpu_specific(generic))
+void Version22(void){}
+ATTR(cpu_specific(haswell))
+void Version22(void){}
+
+ATTR(cpu_dispatch(generic, core_4th_gen_avx))
+void Version23(void);
+ATTR(cpu_specific(generic))
+void Version23(void){}
+ATTR(cpu_specific(core_4th_gen_avx))
+void Version23(void){}
+

[PATCH] D152321: [clang] Replace use of Type::getPointerTo() (NFC)

2023-06-14 Thread Youngsuk Kim via Phabricator via cfe-commits
JOE1994 added inline comments.



Comment at: clang/lib/CodeGen/CGBuilder.h:170
   Address CreateElementBitCast(Address Addr, llvm::Type *Ty,
const llvm::Twine  = "") {
+return Address(Addr.getPointer(), Ty,

barannikov88 wrote:
> The argument can be removed.
> 
> Idea for a follow-up: I would also consider removing this method because it 
> does not do what its name says.
> Maybe replace it with `Address::withElementType` analagous to 
> `Address::withPointer` / `Address::withAlignment`?
> 
Thank you for the suggestion.

I have a follow-up reivision for removing the `Name` parameter. 
(https://reviews.llvm.org/D152551)

After this revision gets merged, I can update the follow-up revision to replace 
`CreateElementBitCast` also.



Comment at: clang/lib/CodeGen/CGCUDANV.cpp:238-240
   CharPtrTy = llvm::PointerType::getUnqual(Types.ConvertType(Ctx.CharTy));
   VoidPtrTy = cast(Types.ConvertType(Ctx.VoidPtrTy));
+  VoidPtrPtrTy = llvm::PointerType::get(CGM.getLLVMContext(), 0);

barannikov88 wrote:
> These are all the same types. Replace the variables with single `PtrTy`?
> 
Thank you for the suggestion.

Unifying them to a single `PtrTy` adds a lot of diff,
so I think it deserves to be in a separate standalone commit.
(I can create a follow-up revision after this gets merged).



Comment at: clang/lib/CodeGen/CGCXX.cpp:175
   // Create the alias with no name.
+  llvm::Type *AliasValueType = getTypes().GetFunctionType(AliasDecl);
   auto *Alias = llvm::GlobalAlias::create(AliasValueType, 0, Linkage, "",

barannikov88 wrote:
> This looks wrong. It used to be `GetFunctionType(TargetDecl)`.
> 
I've simply moved the line defining `AliasValueType` closer to its use.
I think `AliasValueType` is right to be initialized with 
`getFunctionType(AliasDecl)`.

Moving the line to below isn't necessary, and it's rather causing confusion.
I'll move it back to where it was.



Comment at: clang/lib/CodeGen/CGCXX.cpp:184
   if (Entry) {
-assert(Entry->getType() == AliasType &&
+assert(Entry->getValueType() == AliasValueType &&
+   Entry->getAddressSpace() == Alias->getAddressSpace() &&

barannikov88 wrote:
> What's the reason for this change?
Since `AliasType` got removed above, the assert condition needs to be updated 
one way or another.

[The assert was written in 2010 (before opaque 
pointers)](https://github.com/llvm/llvm-project/commit/aea181de04d8be743db1629e0c054abff68500c6),
and it's checking equality of two pointer types (which was equivalent to 
checking equality of pointee type & address space).

With opaque pointers enabled, I thought the assert needs to be updated to check 
equality of both the pointee types & address spaces separately in order to 
preserve the original intent.



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152321/new/

https://reviews.llvm.org/D152321

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


[PATCH] D152321: [clang] Replace use of Type::getPointerTo() (NFC)

2023-06-14 Thread Youngsuk Kim via Phabricator via cfe-commits
JOE1994 updated this revision to Diff 531593.
JOE1994 added a comment.

- Apply suggestions from barannikov88
- Used `git clang-format` to tidy up code format

Thank you for your feedback!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152321/new/

https://reviews.llvm.org/D152321

Files:
  clang/lib/CodeGen/Address.h
  clang/lib/CodeGen/CGAtomic.cpp
  clang/lib/CodeGen/CGBlocks.cpp
  clang/lib/CodeGen/CGBuilder.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGCUDANV.cpp
  clang/lib/CodeGen/CGCXX.cpp
  clang/lib/CodeGen/CGCXXABI.cpp
  clang/lib/CodeGen/CGClass.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CGException.cpp
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/lib/CodeGen/CGObjCRuntime.cpp
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/TargetInfo.cpp

Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -402,7 +402,7 @@
   llvm::Type *DirectTy = CGF.ConvertTypeForMem(ValueTy), *ElementTy = DirectTy;
   if (IsIndirect) {
 unsigned AllocaAS = CGF.CGM.getDataLayout().getAllocaAddrSpace();
-DirectTy = DirectTy->getPointerTo(AllocaAS);
+DirectTy = llvm::PointerType::get(CGF.getLLVMContext(), AllocaAS);
   }
 
   Address Addr = emitVoidPtrDirectVAArg(CGF, VAListAddr, DirectTy, DirectSize,
@@ -2042,7 +2042,7 @@
   Info = ABIArgInfo::getInAlloca(FrameFields.size(), IsIndirect);
   llvm::Type *LLTy = CGT.ConvertTypeForMem(Type);
   if (IsIndirect)
-LLTy = LLTy->getPointerTo(0);
+LLTy = llvm::PointerType::get(getVMContext(), 0);
   FrameFields.push_back(LLTy);
   StackOffset += IsIndirect ? WordSize : getContext().getTypeSizeInChars(Type);
 
@@ -4851,7 +4851,8 @@
   Builder.CreateCondBr(CC, UsingRegs, UsingOverflow);
 
   llvm::Type *DirectTy = CGF.ConvertType(Ty), *ElementTy = DirectTy;
-  if (isIndirect) DirectTy = DirectTy->getPointerTo(0);
+  if (isIndirect)
+DirectTy = llvm::PointerType::get(CGF.getLLVMContext(), 0);
 
   // Case 1: consume registers.
   Address RegAddr = Address::invalid();
Index: clang/lib/CodeGen/ItaniumCXXABI.cpp
===
--- clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -584,9 +584,6 @@
   auto *RD =
   cast(MPT->getClass()->castAs()->getDecl());
 
-  llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType(
-  CGM.getTypes().arrangeCXXMethodType(RD, FPT, /*FD=*/nullptr));
-
   llvm::Constant *ptrdiff_1 = llvm::ConstantInt::get(CGM.PtrDiffTy, 1);
 
   llvm::BasicBlock *FnVirtual = CGF.createBasicBlock("memptr.virtual");
@@ -687,8 +684,6 @@
   {VFPAddr, llvm::ConstantInt::get(CGM.Int32Ty, 0), TypeId});
   CheckResult = Builder.CreateExtractValue(CheckedLoad, 1);
   VirtualFn = Builder.CreateExtractValue(CheckedLoad, 0);
-  VirtualFn = Builder.CreateBitCast(VirtualFn, FTy->getPointerTo(),
-"memptr.virtualfn");
 } else {
   // When not doing VFE, emit a normal load, as it allows more
   // optimisations than type.checked.load.
@@ -709,15 +704,12 @@
 CGM.getIntrinsic(llvm::Intrinsic::load_relative,
  {VTableOffset->getType()}),
 {VTable, VTableOffset});
-VirtualFn = CGF.Builder.CreateBitCast(VirtualFn, FTy->getPointerTo());
   } else {
 llvm::Value *VFPAddr =
 CGF.Builder.CreateGEP(CGF.Int8Ty, VTable, VTableOffset);
-VFPAddr = CGF.Builder.CreateBitCast(
-VFPAddr, FTy->getPointerTo()->getPointerTo());
 VirtualFn = CGF.Builder.CreateAlignedLoad(
-FTy->getPointerTo(), VFPAddr, CGF.getPointerAlign(),
-"memptr.virtualfn");
+llvm::PointerType::get(CGF.getLLVMContext(), 0), VFPAddr,
+CGF.getPointerAlign(), "memptr.virtualfn");
   }
 }
 assert(VirtualFn && "Virtual fuction pointer not created!");
@@ -757,8 +749,9 @@
   // In the non-virtual path, the function pointer is actually a
   // function pointer.
   CGF.EmitBlock(FnNonVirtual);
-  llvm::Value *NonVirtualFn =
-Builder.CreateIntToPtr(FnAsInt, FTy->getPointerTo(), "memptr.nonvirtualfn");
+  llvm::Value *NonVirtualFn = Builder.CreateIntToPtr(
+  FnAsInt, llvm::PointerType::get(CGF.getLLVMContext(), 0),
+  "memptr.nonvirtualfn");
 
   // Check the function pointer if CFI on member function pointers is enabled.
   if (ShouldEmitCFICheck) {
@@ -799,7 +792,8 @@
 
   // We're done.
   CGF.EmitBlock(FnEnd);
-  llvm::PHINode *CalleePtr = Builder.CreatePHI(FTy->getPointerTo(), 2);
+  llvm::PHINode *CalleePtr =
+  Builder.CreatePHI(llvm::PointerType::get(CGF.getLLVMContext(), 0), 2);
   CalleePtr->addIncoming(VirtualFn, FnVirtual);
   

[clang] dc895d0 - [RISCV] Remove redundant line `NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py` from riscv64-zknd-zkne.c

2023-06-14 Thread Jim Lin via cfe-commits

Author: Jim Lin
Date: 2023-06-15T10:22:06+08:00
New Revision: dc895d023e63fd9276fe493eded776e101015c86

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

LOG: [RISCV] Remove redundant line `NOTE: Assertions have been autogenerated by 
utils/update_cc_test_checks.py` from riscv64-zknd-zkne.c

Added: 


Modified: 
clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zknd-zkne.c

Removed: 




diff  --git a/clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zknd-zkne.c 
b/clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zknd-zkne.c
index 9b9ce9d33dd5e..1132c98ef595f 100644
--- a/clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zknd-zkne.c
+++ b/clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zknd-zkne.c
@@ -1,7 +1,6 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
 // RUN: %clang_cc1 -triple riscv64 -target-feature +zknd -emit-llvm %s -o - \
 // RUN: | FileCheck %s  -check-prefix=RV64ZKND-ZKNE
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
 // RUN: %clang_cc1 -triple riscv64 -target-feature +zkne -emit-llvm %s -o - \
 // RUN: | FileCheck %s  -check-prefix=RV64ZKND-ZKNE
 



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


[PATCH] D152965: [OpenMP] Correctly diagnose conflicting target identifierers for AMDGPU

2023-06-14 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl accepted this revision.
yaxunl added a comment.

LGTM. Thanks.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152965/new/

https://reviews.llvm.org/D152965

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


[PATCH] D150023: [ABI] [C++20] [Modules] Don't generate vtable if the class is defined in other module unit

2023-06-14 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

Thanks for keeping the bot green. I see the failure comes from an ABI 
difference showed up in the test case. I'll try to address it and land it again 
later.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150023/new/

https://reviews.llvm.org/D150023

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


[PATCH] D152914: [Draft] Make __builtin_cpu builtins target-independent

2023-06-14 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: llvm/include/llvm/IR/Intrinsics.td:903-907
+// Load of a value provided by the system library at a fixed address. Used for
+// accessing things like HWCAP word provided by GLIBC.
+def int_fixed_addr_ld
+: DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i32_ty],
+[IntrInaccessibleMemOnly, ImmArg>]>;

From this description I don't understand what this is supposed to do. What does 
the input mean? Why does this use an i32 immarg and not a pointer? Why is the 
result only i32?



Comment at: llvm/include/llvm/IR/Intrinsics.td:905
+// accessing things like HWCAP word provided by GLIBC.
+def int_fixed_addr_ld
+: DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i32_ty],

I think a new intrinsic should be in a separate commit 



Comment at: llvm/include/llvm/Support/TargetOpcodes.def:148
 
+/// This pseudo-instruction loads a value provided by libc at afixed address.
+/// For example, GLIBC provides HWCAP, HWCAP2 and CPUID at a fixed address

Typo afixed


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152914/new/

https://reviews.llvm.org/D152914

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


[PATCH] D152764: [clang-tidy] Reserved-identifier: Improved AllowedIdentifiers option to support regular expressions

2023-06-14 Thread Félix-Antoine Constantin via Phabricator via cfe-commits
felix642 updated this revision to Diff 531590.
felix642 added a comment.

Renamed allowedIdentifiers to allowedIdentifiersRaw
Moved regex parsing to a new method
Moved entry in releaseNotes.rst


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152764/new/

https://reviews.llvm.org/D152764

Files:
  clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/reserved-identifier.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/reserved-identifier-invert.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/reserved-identifier-invert.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/reserved-identifier-invert.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/reserved-identifier-invert.cpp
@@ -1,7 +1,7 @@
 // RUN: %check_clang_tidy %s bugprone-reserved-identifier %t -- \
 // RUN:   -config='{CheckOptions: [ \
 // RUN: {key: bugprone-reserved-identifier.Invert, value: true}, \
-// RUN: {key: bugprone-reserved-identifier.AllowedIdentifiers, value: std;reference_wrapper;ref;cref;type;get}, \
+// RUN: {key: bugprone-reserved-identifier.AllowedIdentifiers, value: "std;reference_wrapper;^c?ref;type;get"}, \
 // RUN:   ]}' -- \
 // RUN:   -I%S/Inputs/reserved-identifier \
 // RUN:   -isystem %S/Inputs/reserved-identifier/system
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/reserved-identifier.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/bugprone/reserved-identifier.rst
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/reserved-identifier.rst
@@ -53,5 +53,5 @@
 
 .. option:: AllowedIdentifiers
 
-   Semicolon-separated list of names that the check ignores. Default is an
+   Semicolon-separated list of regular expressions that the check ignores. Default is an
empty list.
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -243,6 +243,10 @@
   ` check by adding support for
   other floating point representations in float constant like ``0.5L``.
 
+- Improved option `AllowedIdentifiers` from :doc:`bugprone-reserved-identifier
+  ` to support regular
+  expressions.
+
 - Deprecated check-local options `HeaderFileExtensions` and `ImplementationFileExtensions`
   in :doc:`bugprone-suspicious-include
   ` check.
Index: clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.h
@@ -30,7 +30,8 @@
 /// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/reserved-identifier.html
 class ReservedIdentifierCheck final : public RenamerClangTidyCheck {
   const bool Invert;
-  const std::vector AllowedIdentifiers;
+  const std::vector AllowedIdentifiersRaw;
+  const llvm::SmallVector AllowedIdentifiers;
 
 public:
   ReservedIdentifierCheck(StringRef Name, ClangTidyContext *Context);
@@ -46,6 +47,7 @@
   const SourceManager ) const override;
   DiagInfo getDiagInfo(const NamingCheckId ,
const NamingCheckFailure ) const override;
+  llvm::SmallVector parseAllowedIdentifiers() const;
 };
 
 } // namespace clang::tidy::bugprone
Index: clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp
@@ -39,18 +39,33 @@
   return 0;
 }
 
+llvm::SmallVector
+ReservedIdentifierCheck::parseAllowedIdentifiers() const {
+  llvm::SmallVector AllowedIdentifiers;
+  AllowedIdentifiers.reserve(AllowedIdentifiersRaw.size());
+
+  for (const auto  : AllowedIdentifiersRaw) {
+AllowedIdentifiers.emplace_back(Identifier.str());
+if (!AllowedIdentifiers.back().isValid())
+  configurationDiag("Invalid allowed identifier regex '%0'") << Identifier;
+  }
+
+  return AllowedIdentifiers;
+}
+
 ReservedIdentifierCheck::ReservedIdentifierCheck(StringRef Name,
  ClangTidyContext *Context)
 : RenamerClangTidyCheck(Name, Context),
   Invert(Options.get("Invert", false)),
-  AllowedIdentifiers(utils::options::parseStringList(
-  Options.get("AllowedIdentifiers", ""))) {}
+  AllowedIdentifiersRaw(utils::options::parseStringList(
+  Options.get("AllowedIdentifiers", ""))),
+  AllowedIdentifiers(parseAllowedIdentifiers()) {}
 
 void 

[PATCH] D137872: Implement lambdas with inalloca parameters by forwarding to function without inalloca calling convention.

2023-06-14 Thread Amy Huang via Phabricator via cfe-commits
akhuang updated this revision to Diff 531571.
akhuang added a comment.

update test case


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137872/new/

https://reviews.llvm.org/D137872

Files:
  clang/include/clang/CodeGen/CGFunctionInfo.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGCall.h
  clang/lib/CodeGen/CGClass.cpp
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CodeGenABITypes.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/CodeGenTypes.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGenCXX/inalloca-lambda.cpp

Index: clang/test/CodeGenCXX/inalloca-lambda.cpp
===
--- clang/test/CodeGenCXX/inalloca-lambda.cpp
+++ clang/test/CodeGenCXX/inalloca-lambda.cpp
@@ -1,11 +1,50 @@
-// RUN: not %clang_cc1 -triple i686-windows-msvc -emit-llvm -o /dev/null %s  2>&1 | FileCheck %s
+// RUN: %clang_cc1 -triple i686-windows-msvc -emit-llvm -o - %s  2>&1 | FileCheck %s
 
-// PR28299
-// CHECK: error: cannot compile this forwarded non-trivially copyable parameter yet
-
-class A {
+struct A {
+  A();
   A(const A &);
+  int x;
 };
-typedef void (*fptr_t)(A);
-fptr_t fn1() { return [](A) {}; }
+void decayToFp(int (*f)(A));
+void test() {
+  auto ld = [](A a) {
+static int calls = 0;
+++calls;
+return a.x + calls;
+  };
+  decayToFp(ld);
+  ld(A{});
+}
+
+// CHECK: define internal x86_thiscallcc noundef i32 
+// CHECK-SAME: @"??R@?0??test@@YAXXZ@QBE?A?@@UA@@@Z"
+// CHECK-SAME: (ptr noundef %this, ptr inalloca(<{ %struct.A }>) %[[ARG:.*]])
+// CHECK: %[[V:.*]] = getelementptr inbounds <{ %struct.A }>, ptr %[[ARG]], i32 0, i32 0
+// CHECK: %call = call x86_thiscallcc noundef i32 
+// CHECK-SAME: @"?__impl@@?0??test@@YAXXZ@QBE?A?@@UA@@@Z"
+// CHECK-SAME: (ptr noundef %this, ptr noundef %[[V]])
+
+// CHECK: define internal noundef i32
+// CHECK-SAME: @"?__invoke@@?0??test@@YAXXZ@CA?A?@@UA@@@Z"
+// CHECK-SAME: (ptr inalloca(<{ %struct.A }>) %[[ARG:.*]])
+// CHECK: %unused.capture = alloca %class.anon, align 1
+// CHECK: %[[VAR:.*]] = getelementptr inbounds <{ %struct.A }>, ptr %[[ARG]], i32 0, i32 0
+// CHECK: %call = call x86_thiscallcc noundef i32
+// CHECK-SAME: @"?__impl@@?0??test@@YAXXZ@QBE?A?@@UA@@@Z"
+// CHECK-SAME: (ptr noundef %unused.capture, ptr noundef %[[VAR]])
+// CHECK: ret i32 %call 
 
+// CHECK: define internal x86_thiscallcc noundef i32
+// CHECK-SAME: @"?__impl@@?0??test@@YAXXZ@QBE?A?@@UA@@@Z"
+// CHECK-SAME: (ptr noundef %this, ptr noundef %[[ARG:.*]])
+// CHECK: %this.addr = alloca ptr, align 4
+// CHECK: store ptr %this, ptr %this.addr, align 4
+// CHECK: %this1 = load ptr, ptr %this.addr, align 4
+// CHECK: %{{.*}} = load i32, ptr @"?calls@?1???R
+// CHECK: %inc = add nsw i32 %{{.*}}, 1
+// CHECK: store i32 %inc, ptr @"?calls@?1???R
+// CHECK: %{{.*}} = getelementptr inbounds %struct.A, ptr %{{.*}}, i32 0, i32 0
+// CHECK: %{{.*}} = load i32, ptr %{{.*}}, align 4
+// CHECK: %{{.*}} = load i32, ptr @"?calls@?1???R
+// CHECK: %add = add nsw i32 %{{.*}}, %{{.*}}
+// CHECK: ret i32 %add
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -1197,7 +1197,8 @@
 
   Class classify(QualType Ty) const;
   ABIArgInfo classifyReturnType(QualType RetTy, CCState ) const;
-  ABIArgInfo classifyArgumentType(QualType RetTy, CCState ) const;
+  ABIArgInfo classifyArgumentType(QualType RetTy, CCState ,
+  bool isDelegateCall) const;
 
   /// Updates the number of available free registers, returns
   /// true if any registers were allocated.
@@ -1824,8 +1825,8 @@
   }
 }
 
-ABIArgInfo X86_32ABIInfo::classifyArgumentType(QualType Ty,
-   CCState ) const {
+ABIArgInfo X86_32ABIInfo::classifyArgumentType(QualType Ty, CCState ,
+   bool isDelegateCall) const {
   // FIXME: Set alignment on indirect arguments.
   bool IsFastCall = State.CC == llvm::CallingConv::X86_FastCall;
   bool IsRegCall = State.CC == llvm::CallingConv::X86_RegCall;
@@ -1838,7 +1839,7 @@
   const RecordType *RT = Ty->getAs();
   if (RT) {
 CGCXXABI::RecordArgABI RAA = getRecordArgABI(RT, getCXXABI());
-if (RAA == CGCXXABI::RAA_Indirect) {
+if (RAA == CGCXXABI::RAA_Indirect || isDelegateCall) {
   return getIndirectResult(Ty, false, State);
 } else if (RAA == CGCXXABI::RAA_DirectInMemory) {
   // The field index doesn't matter, we'll fix it up later.
@@ -2027,7 +2028,8 @@
 if (State.IsPreassigned.test(I))
   continue;
 
-Args[I].info = classifyArgumentType(Args[I].type, State);
+Args[I].info =
+classifyArgumentType(Args[I].type, State, FI.isDelegateCall());
 UsedInAlloca |= (Args[I].info.getKind() == ABIArgInfo::InAlloca);
   }
 
Index: 

[PATCH] D137872: Implement lambdas with inalloca parameters by forwarding to function without inalloca calling convention.

2023-06-14 Thread Amy Huang via Phabricator via cfe-commits
akhuang added inline comments.



Comment at: clang/lib/CodeGen/CodeGenFunction.cpp:1472
+// the call operator body.
+EmitLambdaStaticInvokeBody(cast(FD));
   } else if (FD->isDefaulted() && isa(FD) &&

efriedma wrote:
> akhuang wrote:
> > efriedma wrote:
> > > Does this pass the correct value of "this"?  EmitLambdaStaticInvokeBody 
> > > creates a new alloca to represent "this", but it's already an argument to 
> > > the function.
> > > 
> > > Granted, it only matters in really obscure cases, but still.
> > That's true, the "this" won't be passed correctly.
> > 
> > Actually, would it be fine to just emit the original call op body? (so that 
> > the same function body is emitted twice -- once in the call op and once in 
> > __impl). 
> Not completely sure what you're asking... but as I've mentioned, we can't 
> EmitFunctionBody() the body of a function more than once.
Oh, nevermind then. I think this version passes "this" from the call op. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137872/new/

https://reviews.llvm.org/D137872

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


[PATCH] D137872: Implement lambdas with inalloca parameters by forwarding to function without inalloca calling convention.

2023-06-14 Thread Amy Huang via Phabricator via cfe-commits
akhuang updated this revision to Diff 531569.
akhuang added a comment.

Emit call op which forwards %this argument


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137872/new/

https://reviews.llvm.org/D137872

Files:
  clang/include/clang/CodeGen/CGFunctionInfo.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGCall.h
  clang/lib/CodeGen/CGClass.cpp
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CodeGenABITypes.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/CodeGenTypes.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGenCXX/inalloca-lambda.cpp

Index: clang/test/CodeGenCXX/inalloca-lambda.cpp
===
--- clang/test/CodeGenCXX/inalloca-lambda.cpp
+++ clang/test/CodeGenCXX/inalloca-lambda.cpp
@@ -1,11 +1,50 @@
-// RUN: not %clang_cc1 -triple i686-windows-msvc -emit-llvm -o /dev/null %s  2>&1 | FileCheck %s
+// RUN: %clang_cc1 -triple i686-windows-msvc -emit-llvm -o - %s  2>&1 | FileCheck %s
 
-// PR28299
-// CHECK: error: cannot compile this forwarded non-trivially copyable parameter yet
-
-class A {
+struct A {
+  A();
   A(const A &);
+  int x;
 };
-typedef void (*fptr_t)(A);
-fptr_t fn1() { return [](A) {}; }
+void decayToFp(int (*f)(A));
+void test() {
+  auto ld = [](A a) {
+static int calls = 0;
+++calls;
+return a.x + calls;
+  };
+  decayToFp(ld);
+  ld(A{});
+}
+
+// CHECK: define internal x86_thiscallcc noundef i32 
+// CHECK-SAME: @"??R@?0??test@@YAXXZ@QBE?A?@@UA@@@Z"
+// CHECK-SAME: (ptr noundef %this, ptr inalloca(<{ %struct.A }>) %[[ARG:.*]])
+// CHECK: %[[V:.*]] = getelementptr inbounds <{ %struct.A }>, ptr %[[ARG]], i32 0, i32 0
+// CHECK: %call = call x86_thiscallcc noundef i32 
+// CHECK-SAME: @"?__impl@@?0??test@@YAXXZ@QBE?A?@@UA@@@Z"
+// CHECK-SAME: (ptr noundef %unused.capture, ptr noundef %[[V]])
+
+// CHECK: define internal noundef i32
+// CHECK-SAME: @"?__invoke@@?0??test@@YAXXZ@CA?A?@@UA@@@Z"
+// CHECK-SAME: (ptr inalloca(<{ %struct.A }>) %[[ARG:.*]])
+// CHECK: %unused.capture = alloca %class.anon, align 1
+// CHECK: %[[VAR:.*]] = getelementptr inbounds <{ %struct.A }>, ptr %[[ARG]], i32 0, i32 0
+// CHECK: %call = call x86_thiscallcc noundef i32
+// CHECK-SAME: @"?__impl@@?0??test@@YAXXZ@QBE?A?@@UA@@@Z"
+// CHECK-SAME: (ptr noundef %unused.capture, ptr noundef %[[VAR]])
+// CHECK: ret i32 %call 
 
+// CHECK: define internal x86_thiscallcc noundef i32
+// CHECK-SAME: @"?__impl@@?0??test@@YAXXZ@QBE?A?@@UA@@@Z"
+// CHECK-SAME: (ptr noundef %this, ptr noundef %[[ARG:.*]])
+// CHECK: %this.addr = alloca ptr, align 4
+// CHECK: store ptr %this, ptr %this.addr, align 4
+// CHECK: %this1 = load ptr, ptr %this.addr, align 4
+// CHECK: %{{.*}} = load i32, ptr @"?calls@?1???R
+// CHECK: %inc = add nsw i32 %{{.*}}, 1
+// CHECK: store i32 %inc, ptr @"?calls@?1???R
+// CHECK: %{{.*}} = getelementptr inbounds %struct.A, ptr %{{.*}}, i32 0, i32 0
+// CHECK: %{{.*}} = load i32, ptr %{{.*}}, align 4
+// CHECK: %{{.*}} = load i32, ptr @"?calls@?1???R
+// CHECK: %add = add nsw i32 %{{.*}}, %{{.*}}
+// CHECK: ret i32 %add
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -1197,7 +1197,8 @@
 
   Class classify(QualType Ty) const;
   ABIArgInfo classifyReturnType(QualType RetTy, CCState ) const;
-  ABIArgInfo classifyArgumentType(QualType RetTy, CCState ) const;
+  ABIArgInfo classifyArgumentType(QualType RetTy, CCState ,
+  bool isDelegateCall) const;
 
   /// Updates the number of available free registers, returns
   /// true if any registers were allocated.
@@ -1824,8 +1825,8 @@
   }
 }
 
-ABIArgInfo X86_32ABIInfo::classifyArgumentType(QualType Ty,
-   CCState ) const {
+ABIArgInfo X86_32ABIInfo::classifyArgumentType(QualType Ty, CCState ,
+   bool isDelegateCall) const {
   // FIXME: Set alignment on indirect arguments.
   bool IsFastCall = State.CC == llvm::CallingConv::X86_FastCall;
   bool IsRegCall = State.CC == llvm::CallingConv::X86_RegCall;
@@ -1838,7 +1839,7 @@
   const RecordType *RT = Ty->getAs();
   if (RT) {
 CGCXXABI::RecordArgABI RAA = getRecordArgABI(RT, getCXXABI());
-if (RAA == CGCXXABI::RAA_Indirect) {
+if (RAA == CGCXXABI::RAA_Indirect || isDelegateCall) {
   return getIndirectResult(Ty, false, State);
 } else if (RAA == CGCXXABI::RAA_DirectInMemory) {
   // The field index doesn't matter, we'll fix it up later.
@@ -2027,7 +2028,8 @@
 if (State.IsPreassigned.test(I))
   continue;
 
-Args[I].info = classifyArgumentType(Args[I].type, State);
+Args[I].info =
+classifyArgumentType(Args[I].type, State, FI.isDelegateCall());
 UsedInAlloca |= (Args[I].info.getKind() == ABIArgInfo::InAlloca);
   }
 

[PATCH] D152472: [Clang][MS] Remove assertion on BaseOffset can't be smaller than Size.

2023-06-14 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Also on http://45.33.8.238/win/79874/step_7.txt

Reverted in 9c560350dd57d0dcb849c5915fa7c50b139ce671 for now.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152472/new/

https://reviews.llvm.org/D152472

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


[clang] 9c56035 - Revert "[Clang][MS] Remove assertion on BaseOffset can't be smaller than Size."

2023-06-14 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2023-06-14T16:19:48-07:00
New Revision: 9c560350dd57d0dcb849c5915fa7c50b139ce671

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

LOG: Revert "[Clang][MS] Remove assertion on BaseOffset can't be smaller than 
Size."

This reverts commit 5d54213ee557a86fae82af0f75498adf02f24e82.

Breaks check-clang on Windows, see https://reviews.llvm.org/D152472#4422913

Added: 


Modified: 
clang/include/clang/Frontend/LayoutOverrideSource.h
clang/lib/AST/RecordLayoutBuilder.cpp
clang/lib/Frontend/LayoutOverrideSource.cpp

Removed: 
clang/test/CodeGenCXX/Inputs/override-layout-ms.layout
clang/test/CodeGenCXX/override-layout-ms.cpp



diff  --git a/clang/include/clang/Frontend/LayoutOverrideSource.h 
b/clang/include/clang/Frontend/LayoutOverrideSource.h
index c6e2d73111833..ea1611470a76a 100644
--- a/clang/include/clang/Frontend/LayoutOverrideSource.h
+++ b/clang/include/clang/Frontend/LayoutOverrideSource.h
@@ -30,12 +30,6 @@ namespace clang {
   /// The alignment of the record.
   uint64_t Align;
 
-  /// The offsets of non-virtual base classes in the record.
-  SmallVector BaseOffsets;
-
-  /// The offsets of virtual base classes in the record.
-  SmallVector VBaseOffsets;
-
   /// The offsets of the fields, in source order.
   SmallVector FieldOffsets;
 };

diff  --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index 3f836cb96be57..aca50912dceac 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -2926,7 +2926,8 @@ void MicrosoftRecordLayoutBuilder::layoutNonVirtualBase(
   bool FoundBase = false;
   if (UseExternalLayout) {
 FoundBase = External.getExternalNVBaseOffset(BaseDecl, BaseOffset);
-if (BaseOffset > Size) {
+if (FoundBase) {
+  assert(BaseOffset >= Size && "base offset already allocated");
   Size = BaseOffset;
 }
   }
@@ -3722,28 +3723,6 @@ void ASTContext::DumpRecordLayout(const RecordDecl *RD, 
raw_ostream ,
   if (Target->defaultsToAIXPowerAlignment())
 OS << "  PreferredAlignment:" << toBits(Info.getPreferredAlignment())
<< "\n";
-  if (const CXXRecordDecl *CXXRD = dyn_cast(RD)) {
-OS << "  BaseOffsets: [";
-const CXXRecordDecl *Base = nullptr;
-for (auto I : CXXRD->bases()) {
-  if (I.isVirtual())
-continue;
-  if (Base)
-OS << ", ";
-  Base = I.getType()->getAsCXXRecordDecl();
-  OS << Info.CXXInfo->BaseOffsets[Base].getQuantity();
-}
-OS << "]>\n";
-OS << "  VBaseOffsets: [";
-const CXXRecordDecl *VBase = nullptr;
-for (auto I : CXXRD->vbases()) {
-  if (VBase)
-OS << ", ";
-  VBase = I.getType()->getAsCXXRecordDecl();
-  OS << Info.CXXInfo->VBaseOffsets[VBase].VBaseOffset.getQuantity();
-}
-OS << "]>\n";
-  }
   OS << "  FieldOffsets: [";
   for (unsigned i = 0, e = Info.getFieldCount(); i != e; ++i) {
 if (i)

diff  --git a/clang/lib/Frontend/LayoutOverrideSource.cpp 
b/clang/lib/Frontend/LayoutOverrideSource.cpp
index f09444deb8d38..0d288db0632fd 100644
--- a/clang/lib/Frontend/LayoutOverrideSource.cpp
+++ b/clang/lib/Frontend/LayoutOverrideSource.cpp
@@ -7,7 +7,6 @@
 
//===--===//
 #include "clang/Frontend/LayoutOverrideSource.h"
 #include "clang/AST/Decl.h"
-#include "clang/AST/DeclCXX.h"
 #include "clang/Basic/CharInfo.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
@@ -27,18 +26,6 @@ static std::string parseName(StringRef S) {
   return S.substr(0, Offset).str();
 }
 
-/// Parse an unsigned integer and move S to the next non-digit character.
-static bool parseUnsigned(StringRef , unsigned long long ) {
-  if (S.empty() || !isDigit(S[0]))
-return false;
-  unsigned Idx = 1;
-  while (Idx < S.size() && isDigit(S[Idx]))
-++Idx;
-  (void)S.substr(0, Idx).getAsInteger(10, ULL);
-  S = S.substr(Idx);
-  return true;
-}
-
 LayoutOverrideSource::LayoutOverrideSource(StringRef Filename) {
   std::ifstream Input(Filename.str().c_str());
   if (!Input.is_open())
@@ -93,8 +80,8 @@ LayoutOverrideSource::LayoutOverrideSource(StringRef 
Filename) {
   LineStr = LineStr.substr(Pos + strlen(" Size:"));
 
   unsigned long long Size = 0;
-  if (parseUnsigned(LineStr, Size))
-CurrentLayout.Size = Size;
+  (void)LineStr.getAsInteger(10, Size);
+  CurrentLayout.Size = Size;
   continue;
 }
 
@@ -105,13 +92,12 @@ LayoutOverrideSource::LayoutOverrideSource(StringRef 
Filename) {
   LineStr = LineStr.substr(Pos + strlen("Alignment:"));
 
   unsigned long long Alignment = 0;
-  if (parseUnsigned(LineStr, Alignment))
-CurrentLayout.Align = Alignment;
+  

[PATCH] D150023: [ABI] [C++20] [Modules] Don't generate vtable if the class is defined in other module unit

2023-06-14 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Reverted in dbdd6372b7af2f6df5f41d19d966e6bac1b30208 
 for now.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150023/new/

https://reviews.llvm.org/D150023

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


[clang] dbdd637 - Revert "[ABI] [C++20] [Modules] Don't generate vtable if the class is defined in other module unit"

2023-06-14 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2023-06-14T16:17:42-07:00
New Revision: dbdd6372b7af2f6df5f41d19d966e6bac1b30208

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

LOG: Revert "[ABI] [C++20] [Modules] Don't generate vtable if the class is 
defined in other module unit"

Breaks check-clang on win and mac, see comments on 
https://reviews.llvm.org/D150023

This reverts commit d8a36b00d198fdc2ea866ea5da449628db07070f.

Also revert follow-up "[NFC] skip the test modules-vtable.cppm on windows"
This reverts commit baf0b12ca6c624b2a59aa6f2fd0310c72d35ac56.

Added: 


Modified: 
clang/lib/CodeGen/CGVTables.cpp

Removed: 
clang/test/CodeGenCXX/modules-vtable.cppm



diff  --git a/clang/lib/CodeGen/CGVTables.cpp b/clang/lib/CodeGen/CGVTables.cpp
index fb0276af57b25..32259d1e4cbff 100644
--- a/clang/lib/CodeGen/CGVTables.cpp
+++ b/clang/lib/CodeGen/CGVTables.cpp
@@ -1172,16 +1172,9 @@ bool CodeGenVTables::isVTableExternal(const 
CXXRecordDecl *RD) {
   if (!keyFunction)
 return false;
 
-  const FunctionDecl *Def;
   // Otherwise, if we don't have a definition of the key function, the
   // vtable must be defined somewhere else.
-  if (!keyFunction->hasBody(Def))
-return true;
-
-  assert(Def && "The body of the key function is not assigned to Def?");
-  // If the non-inline key function comes from another module unit, the vtable
-  // must be defined there.
-  return Def->isInAnotherModuleUnit() && !Def->isInlineSpecified();
+  return !keyFunction->hasBody();
 }
 
 /// Given that we're currently at the end of the translation unit, and

diff  --git a/clang/test/CodeGenCXX/modules-vtable.cppm 
b/clang/test/CodeGenCXX/modules-vtable.cppm
deleted file mode 100644
index 5662f40515cd6..0
--- a/clang/test/CodeGenCXX/modules-vtable.cppm
+++ /dev/null
@@ -1,98 +0,0 @@
-// REQUIRES: !system-windows
-
-// RUN: rm -rf %t
-// RUN: split-file %s %t
-// RUN: cd %t
-//
-// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 
-emit-module-interface \
-// RUN: %t/Mod.cppm -o %t/Mod.pcm
-//
-// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 %t/Mod.pcm \
-// RUN: -emit-llvm -o - | FileCheck %t/Mod.cppm
-// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 
-fmodule-file=Mod=%t/Mod.pcm \
-// RUN: %t/Use.cpp  -emit-llvm -o - | FileCheck %t/Use.cpp
-//
-// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 
-emit-module-interface \
-// RUN: %t/Mod.cppm -o %t/Mod.pcm -DKEY_FUNCTION_INLINE
-//
-// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 %t/Mod.pcm \
-// RUN: -emit-llvm -o - | FileCheck %t/Mod.cppm -check-prefix=CHECK-INLINE
-// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 
-fmodule-file=Mod=%t/Mod.pcm \
-// RUN: %t/Use.cpp  -emit-llvm -o - | FileCheck %t/Use.cpp 
-check-prefix=CHECK-INLINE
-//
-// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 
-emit-module-interface \
-// RUN: %t/M-A.cppm -o %t/M-A.pcm
-// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 
-fmodule-file=M:A=%t/M-A.pcm \
-// RUN: %t/M-B.cppm  -emit-llvm -o - | FileCheck %t/M-B.cppm
-
-//--- Mod.cppm
-export module Mod;
-
-export class Base {
-public:
-virtual ~Base();
-};
-#ifdef KEY_FUNCTION_INLINE
-inline
-#endif
-Base::~Base() {}
-
-// CHECK: @_ZTVW3Mod4Base = unnamed_addr constant
-// CHECK: @_ZTSW3Mod4Base = constant
-// CHECK: @_ZTIW3Mod4Base = constant
-
-// CHECK-INLINE: @_ZTVW3Mod4Base = linkonce_odr unnamed_addr constant
-// CHECK-INLINE: @_ZTSW3Mod4Base = linkonce_odr constant
-// CHECK-INLINE: @_ZTIW3Mod4Base = linkonce_odr constant
-
-module :private;
-int private_use() {
-Base base;
-return 43;
-}
-
-//--- Use.cpp
-import Mod;
-int use() {
-Base* base = new Base();
-return 43;
-}
-
-// CHECK-NOT: @_ZTSW3Mod4Base = constant
-// CHECK-NOT: @_ZTIW3Mod4Base = constant
-// CHECK: @_ZTVW3Mod4Base = external unnamed_addr
-
-// CHECK-INLINE: @_ZTVW3Mod4Base = linkonce_odr unnamed_addr constant
-// CHECK-INLINE: @_ZTSW3Mod4Base = linkonce_odr constant
-// CHECK-INLINE: @_ZTIW3Mod4Base = linkonce_odr constant
-
-// Check the case that the declaration of the key function comes from another
-// module unit but the definition of the key function comes from the current
-// mdoule unit.
-
-//--- M-A.cppm
-export module M:A;
-export class C {
-public:
-virtual ~C();
-};
-
-int a_use() {
-C c;
-return 43;
-}
-
-//--- M-B.cppm
-export module M:B;
-import :A;
-
-C::~C() {}
-
-int b_use() {
-C c;
-return 43;
-}
-
-// CHECK: @_ZTVW1M1C = unnamed_addr constant
-// CHECK: @_ZTSW1M1C = constant
-// CHECK: @_ZTIW1M1C = constant



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


[PATCH] D152975: [clang-format] Allow break after return keyword

2023-06-14 Thread Gedare Bloom via Phabricator via cfe-commits
gedare updated this revision to Diff 531561.
gedare added a comment.

- Regenerate ClangFormatStyleOptions.rst


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152975/new/

https://reviews.llvm.org/D152975

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -8916,6 +8916,9 @@
   verifyFormat("return aaa(\n"
"   aa) &&\n"
"   aaa;");
+  verifyFormat("return\n"
+   "aaa"
+   "();");
   verifyFormat("return\n"
"// true if code is one of a or b.\n"
"code == a || code == b;");
@@ -22179,9 +22182,9 @@
   verifyFormat("FctWithLongLineInLambda_SLS_All(\n"
"[]()\n"
"{\n"
-   "  return "
-   "HereAVeryLongLineThatWillBeFormattedOnMultipleLineAndShouldNotB"
-   "eConsiderAsInline;\n"
+   "  return\n"
+   "  HereAVeryLongLineThatWillBeFormattedOnMultipleLineAnd"
+   "ShouldNotBeConsiderAsInline;\n"
"});",
LLVMWithBeforeLambdaBody);
   verifyFormat(
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3525,6 +3525,8 @@
 }
   }
 
+  if (Left.is(tok::kw_return))
+return Style.PenaltyBreakReturn;
   if (Left.is(tok::coloncolon))
 return 500;
   if (Right.isOneOf(TT_StartOfName, TT_FunctionDeclarationName) ||
@@ -5526,7 +5528,8 @@
   }
 
   return Left.isOneOf(tok::comma, tok::coloncolon, tok::semi, tok::l_brace,
-  tok::kw_class, tok::kw_struct, tok::comment) ||
+  tok::kw_class, tok::kw_struct, tok::comment,
+  tok::kw_return) ||
  Right.isMemberAccess() ||
  Right.isOneOf(TT_TrailingReturnArrow, TT_LambdaArrow, tok::lessless,
tok::colon, tok::l_square, tok::at) ||
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -967,6 +967,7 @@
Style.PenaltyBreakFirstLessLess);
 IO.mapOptional("PenaltyBreakOpenParenthesis",
Style.PenaltyBreakOpenParenthesis);
+IO.mapOptional("PenaltyBreakReturn", Style.PenaltyBreakReturn);
 IO.mapOptional("PenaltyBreakString", Style.PenaltyBreakString);
 IO.mapOptional("PenaltyBreakTemplateDeclaration",
Style.PenaltyBreakTemplateDeclaration);
@@ -1480,6 +1481,7 @@
   LLVMStyle.PenaltyBreakAssignment = prec::Assignment;
   LLVMStyle.PenaltyBreakComment = 300;
   LLVMStyle.PenaltyBreakFirstLessLess = 120;
+  LLVMStyle.PenaltyBreakReturn = 100;
   LLVMStyle.PenaltyBreakString = 1000;
   LLVMStyle.PenaltyExcessCharacter = 100;
   LLVMStyle.PenaltyReturnTypeOnItsOwnLine = 60;
Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -3082,6 +3082,10 @@
   /// \version 14
   unsigned PenaltyBreakOpenParenthesis;
 
+  /// The penalty for breaking after ``return``.
+  /// \version 18
+  unsigned PenaltyBreakReturn;
+
   /// The penalty for each line break introduced inside a string literal.
   /// \version 3.7
   unsigned PenaltyBreakString;
@@ -4391,6 +4395,7 @@
PenaltyBreakComment == R.PenaltyBreakComment &&
PenaltyBreakFirstLessLess == R.PenaltyBreakFirstLessLess &&
PenaltyBreakOpenParenthesis == R.PenaltyBreakOpenParenthesis &&
+   PenaltyBreakReturn == R.PenaltyBreakReturn &&
PenaltyBreakString == R.PenaltyBreakString &&
PenaltyBreakTemplateDeclaration ==
R.PenaltyBreakTemplateDeclaration &&
Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -4048,6 +4048,11 @@
 **PenaltyBreakOpenParenthesis** (``Unsigned``) :versionbadge:`clang-format 14` :ref:`¶ `
   The penalty for breaking after ``(``.
 
+.. _PenaltyBreakReturn:
+
+**PenaltyBreakReturn** (``Unsigned``) :versionbadge:`clang-format 18` :ref:`¶ `
+  The penalty for breaking after ``return``.
+
 .. 

[PATCH] D152924: [libLTO][AIX] Respect `-f[no]-integrated-as` on AIX

2023-06-14 Thread Steven Wu via Phabricator via cfe-commits
steven_wu accepted this revision.
steven_wu added a comment.
This revision is now accepted and ready to land.

I see. Sounds fine to me.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152924/new/

https://reviews.llvm.org/D152924

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


[PATCH] D152804: [clang-format] Propose a new solution to - Fix overlapping replacements before PPDirectives

2023-06-14 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

I've updated D151954 . If that doesn't work, 
we should land this patch and continue to work on a more general solution.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152804/new/

https://reviews.llvm.org/D152804

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


[PATCH] D152977: [NFC] Fix potential dereferencing of null return value.

2023-06-14 Thread Sindhu Chittireddy via Phabricator via cfe-commits
schittir created this revision.
schittir added reviewers: aaron.ballman, tahonermann, erichkeane.
Herald added subscribers: steakhal, martong.
Herald added a reviewer: NoQ.
Herald added a project: All.
schittir requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Replace getAs with castAs and add assert if needed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152977

Files:
  clang/lib/AST/ASTContext.cpp
  clang/lib/Frontend/FrontendActions.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
  clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp


Index: clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
@@ -291,8 +291,8 @@
   // Existence in DestroyRetVal ensures existence in LockMap.
   // Existence in Destroyed also ensures that the lock state for lockR is 
either
   // UntouchedAndPossiblyDestroyed or UnlockedAndPossiblyDestroyed.
-  assert(lstate->isUntouchedAndPossiblyDestroyed() ||
- lstate->isUnlockedAndPossiblyDestroyed());
+  assert(lstate && (lstate->isUntouchedAndPossiblyDestroyed() ||
+lstate->isUnlockedAndPossiblyDestroyed()));
 
   ConstraintManager  = state->getConstraintManager();
   ConditionTruthVal retZero = CMgr.isNull(state, *sym);
Index: clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
+++ clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
@@ -321,7 +321,9 @@
   if (!IvarRegion)
 return nullptr;
 
-  return IvarRegion->getSymbolicBase()->getSymbol();
+  const SymbolicRegion *SR = IvarRegion->getSymbolicBase();
+  assert(SR && "Symbolic base should not be nullptr");
+  return SR->getSymbol();
 }
 
 /// If we are in -dealloc or -dealloc is on the stack, handle the call if it is
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2790,7 +2790,7 @@
 
   // Only support _BitInt elements with byte-sized power of 2 NumBits.
   if (T->isBitIntType()) {
-unsigned NumBits = T->getAs()->getNumBits();
+unsigned NumBits = T->castAs()->getNumBits();
 if (!llvm::isPowerOf2_32(NumBits) || NumBits < 8) {
   Diag(AttrLoc, diag::err_attribute_invalid_bitint_vector_type)
   << (NumBits < 8);
Index: clang/lib/Frontend/FrontendActions.cpp
===
--- clang/lib/Frontend/FrontendActions.cpp
+++ clang/lib/Frontend/FrontendActions.cpp
@@ -458,6 +458,8 @@
   return;
 }
 
+assert(NamedCtx, "NamedCtx cannot be null");
+
 if (const auto *Decl = dyn_cast(NamedTemplate)) {
   OS << "unnamed function parameter " << Decl->getFunctionScopeIndex()
  << " ";
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -4141,8 +4141,8 @@
   assert(vecType->isBuiltinType() || vecType->isDependentType() ||
  (vecType->isBitIntType() &&
   // Only support _BitInt elements with byte-sized power of 2 NumBits.
-  llvm::isPowerOf2_32(vecType->getAs()->getNumBits()) &&
-  vecType->getAs()->getNumBits() >= 8));
+  llvm::isPowerOf2_32(vecType->castAs()->getNumBits()) &&
+  vecType->castAs()->getNumBits() >= 8));
 
   // Check if we've already instantiated a vector of this type.
   llvm::FoldingSetNodeID ID;


Index: clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
@@ -291,8 +291,8 @@
   // Existence in DestroyRetVal ensures existence in LockMap.
   // Existence in Destroyed also ensures that the lock state for lockR is either
   // UntouchedAndPossiblyDestroyed or UnlockedAndPossiblyDestroyed.
-  assert(lstate->isUntouchedAndPossiblyDestroyed() ||
- lstate->isUnlockedAndPossiblyDestroyed());
+  assert(lstate && (lstate->isUntouchedAndPossiblyDestroyed() ||
+lstate->isUnlockedAndPossiblyDestroyed()));
 
   ConstraintManager  = state->getConstraintManager();
   ConditionTruthVal retZero = CMgr.isNull(state, *sym);
Index: clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
+++ clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
@@ -321,7 +321,9 @@
   if (!IvarRegion)
 return nullptr;
 
-  return 

[PATCH] D152975: [clang-format] Allow break after return keyword

2023-06-14 Thread Gedare Bloom via Phabricator via cfe-commits
gedare updated this revision to Diff 531557.
gedare added a comment.

Regenerate docs


Herald added a comment.

NOTE: Clang-Format Team Automated Review Comment

Your review contains a change to ClangFormatStyleOptions.rst but not a change 
to clang/include/clang/Format/Format.h

ClangFormatStyleOptions.rst is auto generated from Format.h via 
clang/docs/tools/dump_format_style.py,  please run this to regenerate the .rst

You can validate that the rst is valid by running.

  ./docs/tools/dump_format_style.py
  mkdir -p html
  /usr/bin/sphinx-build -n ./docs ./html


Herald added a comment.

NOTE: Clang-Format Team Automated Review Comment

It looks like your clang-format review does not contain any unit tests, please 
try to ensure all code changes have a unit test (unless this is an `NFC` or 
refactoring, adding documentation etc..)

Add your unit tests in `clang/unittests/Format` and you can build with `ninja 
FormatTests`.  We recommend using the `verifyFormat(xxx)` format of unit tests 
rather than `EXPECT_EQ` as this will ensure you change is tolerant to random 
whitespace changes (see FormatTest.cpp as an example)

For situations where your change is altering the TokenAnnotator.cpp which can 
happen if you are trying to improve the annotation phase to ensure we are 
correctly identifying the type of a token, please add a token annotator test in 
`TokenAnnotatorTest.cpp`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152975/new/

https://reviews.llvm.org/D152975

Files:
  clang/docs/ClangFormatStyleOptions.rst


Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -4048,6 +4048,11 @@
 **PenaltyBreakOpenParenthesis** (``Unsigned``) :versionbadge:`clang-format 14` 
:ref:`¶ `
   The penalty for breaking after ``(``.
 
+.. _PenaltyBreakReturn:
+
+**PenaltyBreakReturn** (``Unsigned``) :versionbadge:`clang-format 18` :ref:`¶ 
`
+  The penalty for breaking after ``return``.
+
 .. _PenaltyBreakString:
 
 **PenaltyBreakString** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ 
`


Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -4048,6 +4048,11 @@
 **PenaltyBreakOpenParenthesis** (``Unsigned``) :versionbadge:`clang-format 14` :ref:`¶ `
   The penalty for breaking after ``(``.
 
+.. _PenaltyBreakReturn:
+
+**PenaltyBreakReturn** (``Unsigned``) :versionbadge:`clang-format 18` :ref:`¶ `
+  The penalty for breaking after ``return``.
+
 .. _PenaltyBreakString:
 
 **PenaltyBreakString** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ `
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152976: Regenerate ClangFormatStyleOptions.rst

2023-06-14 Thread Gedare Bloom via Phabricator via cfe-commits
gedare created this revision.
Herald added a project: All.
Herald added a comment.
gedare requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

NOTE: Clang-Format Team Automated Review Comment

Your review contains a change to ClangFormatStyleOptions.rst but not a change 
to clang/include/clang/Format/Format.h

ClangFormatStyleOptions.rst is auto generated from Format.h via 
clang/docs/tools/dump_format_style.py,  please run this to regenerate the .rst

You can validate that the rst is valid by running.

  ./docs/tools/dump_format_style.py
  mkdir -p html
  /usr/bin/sphinx-build -n ./docs ./html


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152976

Files:
  clang/docs/ClangFormatStyleOptions.rst


Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -4048,6 +4048,11 @@
 **PenaltyBreakOpenParenthesis** (``Unsigned``) :versionbadge:`clang-format 14` 
:ref:`¶ `
   The penalty for breaking after ``(``.
 
+.. _PenaltyBreakReturn:
+
+**PenaltyBreakReturn** (``Unsigned``) :versionbadge:`clang-format 18` :ref:`¶ 
`
+  The penalty for breaking after ``return``.
+
 .. _PenaltyBreakString:
 
 **PenaltyBreakString** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ 
`


Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -4048,6 +4048,11 @@
 **PenaltyBreakOpenParenthesis** (``Unsigned``) :versionbadge:`clang-format 14` :ref:`¶ `
   The penalty for breaking after ``(``.
 
+.. _PenaltyBreakReturn:
+
+**PenaltyBreakReturn** (``Unsigned``) :versionbadge:`clang-format 18` :ref:`¶ `
+  The penalty for breaking after ``return``.
+
 .. _PenaltyBreakString:
 
 **PenaltyBreakString** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ `
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148385: [RISCV] Implement KCFI operand bundle lowering

2023-06-14 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

Will be good to wait a few days to give regular RISC-V backend developers a 
chance to leave any final comments.




Comment at: llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp:332
+  continue;
+while (!isRegAvailable(NextReg))
+  ++NextReg;

samitolvanen wrote:
> MaskRay wrote:
> > As a minor optimization to skip one redundant `isRegAvailable` call: `while 
> > (!isRegAvailable(++NextReg));`
> `Reg` != `NextReg` here, and using `while (!isRegAvailable(++NextReg))` would 
> always skip the first alternative register by first incrementing `NextReg` 
> before calling `isRegsAvailable`. What am I missing?
Ah you are right. Didn't notice the Reg/nextReg difference.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148385/new/

https://reviews.llvm.org/D148385

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


[PATCH] D152975: [clang-format] Allow break after return keyword

2023-06-14 Thread Gedare Bloom via Phabricator via cfe-commits
gedare created this revision.
Herald added projects: All, clang, clang-format.
Herald added a subscriber: cfe-commits.
Herald added reviewers: rymiel, HazardyKnusperkeks, owenpan, MyDeveloperDay.
gedare requested review of this revision.
Herald added a comment.

NOTE: Clang-Format Team Automated Review Comment

Your review contains a change to clang/include/clang/Format/Format.h but does 
not contain an update to ClangFormatStyleOptions.rst

ClangFormatStyleOptions.rst is generated via 
clang/docs/tools/dump_format_style.py,  please run this to regenerate the .rst

You can validate that the rst is valid by running.

  ./docs/tools/dump_format_style.py
  mkdir -p html
  /usr/bin/sphinx-build -n ./docs ./html


Currently new line breaks are not added between the `return` keyword
and the return value. With long, singleton return values, it can be
preferred to break before the return value. An example of this would be
a lengthy string return value.

Adds a new style option PenaltyBreakReturn to control when breaks are
preferred. With the current setting of 100, most existing unit tests pass.
One unit test needed to be tweaked, as it assumes very long return values
do not get broken from the return keyword. Added a new unit test to exercise
the long return value.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152975

Files:
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -8916,6 +8916,9 @@
   verifyFormat("return aaa(\n"
"   aa) 
&&\n"
"   aaa;");
+  verifyFormat("return\n"
+   "
aaa"
+   "();");
   verifyFormat("return\n"
"// true if code is one of a or b.\n"
"code == a || code == b;");
@@ -22179,9 +22182,9 @@
   verifyFormat("FctWithLongLineInLambda_SLS_All(\n"
"[]()\n"
"{\n"
-   "  return "
-   
"HereAVeryLongLineThatWillBeFormattedOnMultipleLineAndShouldNotB"
-   "eConsiderAsInline;\n"
+   "  return\n"
+   "  
HereAVeryLongLineThatWillBeFormattedOnMultipleLineAnd"
+   "ShouldNotBeConsiderAsInline;\n"
"});",
LLVMWithBeforeLambdaBody);
   verifyFormat(
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3525,6 +3525,8 @@
 }
   }
 
+  if (Left.is(tok::kw_return))
+return Style.PenaltyBreakReturn;
   if (Left.is(tok::coloncolon))
 return 500;
   if (Right.isOneOf(TT_StartOfName, TT_FunctionDeclarationName) ||
@@ -5526,7 +5528,8 @@
   }
 
   return Left.isOneOf(tok::comma, tok::coloncolon, tok::semi, tok::l_brace,
-  tok::kw_class, tok::kw_struct, tok::comment) ||
+  tok::kw_class, tok::kw_struct, tok::comment,
+  tok::kw_return) ||
  Right.isMemberAccess() ||
  Right.isOneOf(TT_TrailingReturnArrow, TT_LambdaArrow, tok::lessless,
tok::colon, tok::l_square, tok::at) ||
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -967,6 +967,7 @@
Style.PenaltyBreakFirstLessLess);
 IO.mapOptional("PenaltyBreakOpenParenthesis",
Style.PenaltyBreakOpenParenthesis);
+IO.mapOptional("PenaltyBreakReturn", Style.PenaltyBreakReturn);
 IO.mapOptional("PenaltyBreakString", Style.PenaltyBreakString);
 IO.mapOptional("PenaltyBreakTemplateDeclaration",
Style.PenaltyBreakTemplateDeclaration);
@@ -1480,6 +1481,7 @@
   LLVMStyle.PenaltyBreakAssignment = prec::Assignment;
   LLVMStyle.PenaltyBreakComment = 300;
   LLVMStyle.PenaltyBreakFirstLessLess = 120;
+  LLVMStyle.PenaltyBreakReturn = 100;
   LLVMStyle.PenaltyBreakString = 1000;
   LLVMStyle.PenaltyExcessCharacter = 100;
   LLVMStyle.PenaltyReturnTypeOnItsOwnLine = 60;
Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -3082,6 +3082,10 @@
   /// \version 14
   unsigned PenaltyBreakOpenParenthesis;
 
+  /// The penalty for breaking after ``return``.
+  /// \version 18
+  unsigned PenaltyBreakReturn;
+
   /// The penalty for each 

[PATCH] D151954: [clang-format] Fix overlapping whitespace replacements before PPDirective

2023-06-14 Thread Owen Pan via Phabricator via cfe-commits
owenpan updated this revision to Diff 531538.
owenpan edited the summary of this revision.
owenpan added a reviewer: paulkirth.
owenpan removed a subscriber: paulkirth.
owenpan added a comment.

Add a member `Newlines` to `struct FormatToken` and compute it only once in 
`UnwrappedLineFormatter::formatFirstToken()`.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151954/new/

https://reviews.llvm.org/D151954

Files:
  clang/lib/Format/FormatToken.h
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -12856,6 +12856,71 @@
"  void f() {}\n"
"};\n",
Style);
+  verifyFormat("struct foo {\n"
+   "#ifdef FOO\n"
+   "#else\n"
+   "private:\n"
+   "\n"
+   "#endif\n"
+   "};",
+   "struct foo {\n"
+   "#ifdef FOO\n"
+   "#else\n"
+   "private:\n"
+   "\n"
+   "#endif\n"
+   "};",
+   Style);
+  verifyFormat("struct foo {\n"
+   "#ifdef FOO\n"
+   "#else\n"
+   "private:\n"
+   "\n"
+   "#endif\n"
+   "};",
+   "struct foo {\n"
+   "#ifdef FOO\n"
+   "#else\n"
+   "private:\n"
+   "\n"
+   "\n"
+   "#endif\n"
+   "};",
+   Style);
+  verifyFormat("struct foo {\n"
+   "#ifdef FOO\n"
+   "private:\n"
+   "#else\n"
+   "#endif\n"
+   "};",
+   "struct foo {\n"
+   "#ifdef FOO\n"
+   "private:\n"
+   "\n"
+   "\n"
+   "#else\n"
+   "#endif\n"
+   "};",
+   Style);
+  verifyFormat("struct foo {\n"
+   "#if 0\n"
+   "#else\n"
+   "#endif\n"
+   "#ifdef FOO\n"
+   "private:\n"
+   "#endif\n"
+   "};",
+   "struct foo {\n"
+   "#if 0\n"
+   "#else\n"
+   "#endif\n"
+   "#ifdef FOO\n"
+   "private:\n"
+   "\n"
+   "\n"
+   "#endif\n"
+   "};",
+   Style);
 
   Style.EmptyLineAfterAccessModifier = FormatStyle::ELAAMS_Always;
   verifyFormat("struct foo {\n"
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1418,22 +1418,13 @@
   return Penalty;
 }
 
-void UnwrappedLineFormatter::formatFirstToken(
-const AnnotatedLine , const AnnotatedLine *PreviousLine,
-const AnnotatedLine *PrevPrevLine,
-const SmallVectorImpl , unsigned Indent,
-unsigned NewlineIndent) {
-  FormatToken  = *Line.First;
-  if (RootToken.is(tok::eof)) {
-unsigned Newlines =
-std::min(RootToken.NewlinesBefore,
- Style.KeepEmptyLinesAtEOF ? Style.MaxEmptyLinesToKeep + 1 : 1);
-unsigned TokenIndent = Newlines ? NewlineIndent : 0;
-Whitespaces->replaceWhitespace(RootToken, Newlines, TokenIndent,
-   TokenIndent);
-return;
-  }
-  unsigned Newlines =
+static auto computeNewlines(const AnnotatedLine ,
+const AnnotatedLine *PreviousLine,
+const AnnotatedLine *PrevPrevLine,
+const SmallVectorImpl ,
+const FormatStyle ) {
+  const auto  = *Line.First;
+  auto Newlines =
   std::min(RootToken.NewlinesBefore, Style.MaxEmptyLinesToKeep + 1);
   // Remove empty lines before "}" where applicable.
   if (RootToken.is(tok::r_brace) &&
@@ -1512,7 +1503,32 @@
 }
   }
 
-  if (Newlines)
+  return Newlines;
+}
+
+void UnwrappedLineFormatter::formatFirstToken(
+const AnnotatedLine , const AnnotatedLine *PreviousLine,
+const AnnotatedLine *PrevPrevLine,
+const SmallVectorImpl , unsigned Indent,
+unsigned NewlineIndent) {
+  FormatToken  = *Line.First;
+  if (RootToken.is(tok::eof)) {
+unsigned Newlines =
+std::min(RootToken.NewlinesBefore,
+ Style.KeepEmptyLinesAtEOF ? Style.MaxEmptyLinesToKeep + 1 : 1);
+unsigned TokenIndent = Newlines ? NewlineIndent : 0;
+Whitespaces->replaceWhitespace(RootToken, Newlines, TokenIndent,
+   TokenIndent);
+return;
+  }
+
+  if (RootToken.Newlines < 0) {
+RootToken.Newlines =
+computeNewlines(Line, PreviousLine, PrevPrevLine, Lines, Style);
+assert(RootToken.Newlines >= 

[clang] fc60bf2 - [DebugInfo] Always emit `.debug_names` with DWARF 5 for Apple platforms

2023-06-14 Thread Jonas Devlieghere via cfe-commits

Author: Jonas Devlieghere
Date: 2023-06-14T15:28:33-07:00
New Revision: fc60bf2de11149d2c027d63e7ad5a98afa6fab80

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

LOG: [DebugInfo] Always emit `.debug_names` with DWARF 5 for Apple platforms

On Apple platforms, we generate .apple_names, .apple_types,
.apple_namespaces and .apple_objc Apple accelerator tables for DWARF 4
and earlier. For DWARF 5 we should generate .debug_names, but instead we
get no accelerator tables at all.

In the backend we are correctly determining that we should be emitting
.debug_names instead of .apple_names. However, when we get to the point
of emitting the section, if the CU debug name table kind is not
"default", the accelerator table emission is skipped.

This patch sets the DebugNameTableKind to Apple in the frontend when
target an Apple target. That way we know that the CU was compiled with
the intent of emitting accelerator tables. For DWARF 4 and earlier, that
means Apple accelerator tables. For DWARF 5 and later, that means .debug
names.

Differential revision: https://reviews.llvm.org/D118754

Added: 
llvm/test/DebugInfo/Inputs/name-table-kind-apple-4.ll
llvm/test/DebugInfo/Inputs/name-table-kind-apple-5.ll
llvm/test/DebugInfo/accel-tables-apple.ll

Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGen/debug-info-names.c
llvm/include/llvm/IR/DebugInfoMetadata.h
llvm/lib/AsmParser/LLLexer.cpp
llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
llvm/lib/IR/DebugInfoMetadata.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index edef27bdf377c..2fd2227720a2a 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -637,17 +637,21 @@ void CGDebugInfo::CreateCompileUnit() {
   SDK = *It;
   }
 
+  llvm::DICompileUnit::DebugNameTableKind NameTableKind =
+  static_cast(
+  CGOpts.DebugNameTable);
+  if (CGM.getTarget().getTriple().isNVPTX())
+NameTableKind = llvm::DICompileUnit::DebugNameTableKind::None;
+  else if (CGM.getTarget().getTriple().getVendor() == llvm::Triple::Apple)
+NameTableKind = llvm::DICompileUnit::DebugNameTableKind::Apple;
+
   // Create new compile unit.
   TheCU = DBuilder.createCompileUnit(
   LangTag, CUFile, CGOpts.EmitVersionIdentMetadata ? Producer : "",
   LO.Optimize || CGOpts.PrepareForLTO || CGOpts.PrepareForThinLTO,
   CGOpts.DwarfDebugFlags, RuntimeVers, CGOpts.SplitDwarfFile, EmissionKind,
   DwoId, CGOpts.SplitDwarfInlining, CGOpts.DebugInfoForProfiling,
-  CGM.getTarget().getTriple().isNVPTX()
-  ? llvm::DICompileUnit::DebugNameTableKind::None
-  : static_cast(
-CGOpts.DebugNameTable),
-  CGOpts.DebugRangesBaseAddress, remapDIPath(Sysroot), SDK);
+  NameTableKind, CGOpts.DebugRangesBaseAddress, remapDIPath(Sysroot), SDK);
 }
 
 llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {

diff  --git a/clang/test/CodeGen/debug-info-names.c 
b/clang/test/CodeGen/debug-info-names.c
index 841387d50fd44..a807fb8c06696 100644
--- a/clang/test/CodeGen/debug-info-names.c
+++ b/clang/test/CodeGen/debug-info-names.c
@@ -1,10 +1,12 @@
-// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s
-// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - -gpubnames | 
FileCheck --check-prefix=DEFAULT %s
-// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - -ggnu-pubnames 
| FileCheck --check-prefix=GNU %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -emit-llvm 
-debug-info-kind=limited %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.10.0 -emit-llvm 
-debug-info-kind=limited %s -o - | FileCheck --check-prefix=APPLE %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -emit-llvm 
-debug-info-kind=limited %s -o - -gpubnames | FileCheck --check-prefix=DEFAULT 
%s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -emit-llvm 
-debug-info-kind=limited %s -o - -ggnu-pubnames | FileCheck --check-prefix=GNU 
%s
 
 // CHECK: !DICompileUnit({{.*}}, nameTableKind: None
 // DEFAULT-NOT: !DICompileUnit({{.*}}, nameTableKind:
 // GNU: !DICompileUnit({{.*}}, nameTableKind: GNU
+// APPLE: !DICompileUnit({{.*}}, nameTableKind: Apple
 
 void f1(void) {
 }

diff  --git a/llvm/include/llvm/IR/DebugInfoMetadata.h 
b/llvm/include/llvm/IR/DebugInfoMetadata.h
index defd1d5c2a1ea..6561224052097 100644
--- a/llvm/include/llvm/IR/DebugInfoMetadata.h
+++ b/llvm/include/llvm/IR/DebugInfoMetadata.h
@@ -1377,7 +1377,8 @@ class DICompileUnit : public DIScope {
 Default = 0,
 GNU = 1,
 None = 2,
-LastDebugNameTableKind = None
+Apple = 3,
+LastDebugNameTableKind = Apple
   };
 
   

[PATCH] D152472: [Clang][MS] Remove assertion on BaseOffset can't be smaller than Size.

2023-06-14 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added a comment.

Hi. I think this caused the override-layout.cpp test to fail on our windows 
builder 
(https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket/8778279637538184401/+/u/clang/test/stdout?format=raw):

  FAIL: Clang :: CodeGenCXX/override-layout.cpp (7816 of 18732)
   TEST 'Clang :: CodeGenCXX/override-layout.cpp' FAILED 

  Script:
  --
  : 'RUN: at line 1';   c:\b\s\w\ir\x\w\staging\llvm_build\bin\clang.exe -cc1 
-internal-isystem c:\b\s\w\ir\x\w\staging\llvm_build\lib\clang\17\include 
-nostdsysteminc -std=c++14 -w -fdump-record-layouts-simple 
C:\b\s\w\ir\x\w\llvm-llvm-project\clang\test\CodeGenCXX\override-layout.cpp > 
C:\b\s\w\ir\x\w\staging\llvm_build\tools\clang\test\CodeGenCXX\Output\override-layout.cpp.tmp.layouts
  : 'RUN: at line 2';   c:\b\s\w\ir\x\w\staging\llvm_build\bin\clang.exe -cc1 
-internal-isystem c:\b\s\w\ir\x\w\staging\llvm_build\lib\clang\17\include 
-nostdsysteminc -std=c++14 -w -fdump-record-layouts-simple 
C:\b\s\w\ir\x\w\llvm-llvm-project\clang\test\CodeGenCXX\override-layout.cpp > 
C:\b\s\w\ir\x\w\staging\llvm_build\tools\clang\test\CodeGenCXX\Output\override-layout.cpp.tmp.before
  : 'RUN: at line 3';   c:\b\s\w\ir\x\w\staging\llvm_build\bin\clang.exe -cc1 
-internal-isystem c:\b\s\w\ir\x\w\staging\llvm_build\lib\clang\17\include 
-nostdsysteminc -std=c++14 -w -DPACKED= -DALIGNED16= 
-fdump-record-layouts-simple 
-foverride-record-layout=C:\b\s\w\ir\x\w\staging\llvm_build\tools\clang\test\CodeGenCXX\Output\override-layout.cpp.tmp.layouts
 C:\b\s\w\ir\x\w\llvm-llvm-project\clang\test\CodeGenCXX\override-layout.cpp > 
C:\b\s\w\ir\x\w\staging\llvm_build\tools\clang\test\CodeGenCXX\Output\override-layout.cpp.tmp.after
  : 'RUN: at line 4';   diff -u 
C:\b\s\w\ir\x\w\staging\llvm_build\tools\clang\test\CodeGenCXX\Output\override-layout.cpp.tmp.before
 
C:\b\s\w\ir\x\w\staging\llvm_build\tools\clang\test\CodeGenCXX\Output\override-layout.cpp.tmp.after
  : 'RUN: at line 5';   c:\b\s\w\ir\x\w\staging\llvm_build\bin\filecheck.exe 
--check-prefixes=CHECK,PRE17 
C:\b\s\w\ir\x\w\llvm-llvm-project\clang\test\CodeGenCXX\override-layout.cpp < 
C:\b\s\w\ir\x\w\staging\llvm_build\tools\clang\test\CodeGenCXX\Output\override-layout.cpp.tmp.after
  : 'RUN: at line 7';   c:\b\s\w\ir\x\w\staging\llvm_build\bin\clang.exe -cc1 
-internal-isystem c:\b\s\w\ir\x\w\staging\llvm_build\lib\clang\17\include 
-nostdsysteminc -std=c++17 -w -fdump-record-layouts-simple 
C:\b\s\w\ir\x\w\llvm-llvm-project\clang\test\CodeGenCXX\override-layout.cpp > 
C:\b\s\w\ir\x\w\staging\llvm_build\tools\clang\test\CodeGenCXX\Output\override-layout.cpp.tmp.layouts
  : 'RUN: at line 8';   c:\b\s\w\ir\x\w\staging\llvm_build\bin\clang.exe -cc1 
-internal-isystem c:\b\s\w\ir\x\w\staging\llvm_build\lib\clang\17\include 
-nostdsysteminc -std=c++17 -w -fdump-record-layouts-simple 
C:\b\s\w\ir\x\w\llvm-llvm-project\clang\test\CodeGenCXX\override-layout.cpp > 
C:\b\s\w\ir\x\w\staging\llvm_build\tools\clang\test\CodeGenCXX\Output\override-layout.cpp.tmp.before
  : 'RUN: at line 9';   c:\b\s\w\ir\x\w\staging\llvm_build\bin\clang.exe -cc1 
-internal-isystem c:\b\s\w\ir\x\w\staging\llvm_build\lib\clang\17\include 
-nostdsysteminc -std=c++17 -w -DPACKED= -DALIGNED16= 
-fdump-record-layouts-simple 
-foverride-record-layout=C:\b\s\w\ir\x\w\staging\llvm_build\tools\clang\test\CodeGenCXX\Output\override-layout.cpp.tmp.layouts
 C:\b\s\w\ir\x\w\llvm-llvm-project\clang\test\CodeGenCXX\override-layout.cpp > 
C:\b\s\w\ir\x\w\staging\llvm_build\tools\clang\test\CodeGenCXX\Output\override-layout.cpp.tmp.after
  : 'RUN: at line 10';   diff -u 
C:\b\s\w\ir\x\w\staging\llvm_build\tools\clang\test\CodeGenCXX\Output\override-layout.cpp.tmp.before
 
C:\b\s\w\ir\x\w\staging\llvm_build\tools\clang\test\CodeGenCXX\Output\override-layout.cpp.tmp.after
  : 'RUN: at line 11';   c:\b\s\w\ir\x\w\staging\llvm_build\bin\filecheck.exe 
--check-prefixes=CHECK,CXX17 
C:\b\s\w\ir\x\w\llvm-llvm-project\clang\test\CodeGenCXX\override-layout.cpp < 
C:\b\s\w\ir\x\w\staging\llvm_build\tools\clang\test\CodeGenCXX\Output\override-layout.cpp.tmp.after
  --
  Exit Code: 1
  
  Command Output (stdout):
  --
  $ ":" "RUN: at line 1"
  $ "c:\b\s\w\ir\x\w\staging\llvm_build\bin\clang.exe" "-cc1" 
"-internal-isystem" "c:\b\s\w\ir\x\w\staging\llvm_build\lib\clang\17\include" 
"-nostdsysteminc" "-std=c++14" "-w" "-fdump-record-layouts-simple" 
"C:\b\s\w\ir\x\w\llvm-llvm-project\clang\test\CodeGenCXX\override-layout.cpp"
  $ ":" "RUN: at line 2"
  $ "c:\b\s\w\ir\x\w\staging\llvm_build\bin\clang.exe" "-cc1" 
"-internal-isystem" "c:\b\s\w\ir\x\w\staging\llvm_build\lib\clang\17\include" 
"-nostdsysteminc" "-std=c++14" "-w" "-fdump-record-layouts-simple" 
"C:\b\s\w\ir\x\w\llvm-llvm-project\clang\test\CodeGenCXX\override-layout.cpp"
  $ ":" "RUN: at line 3"
  $ "c:\b\s\w\ir\x\w\staging\llvm_build\bin\clang.exe" "-cc1" 
"-internal-isystem" "c:\b\s\w\ir\x\w\staging\llvm_build\lib\clang\17\include" 
"-nostdsysteminc" 

[PATCH] D152279: [Driver] Default -msmall-data-limit= to 0

2023-06-14 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D152279#4420312 , @asb wrote:

> In D152279#4415974 , @MaskRay wrote:
>
>> However, RISC-V `-msmall-data-limit=` is probably a case warranting a 
>> difference.
>> The global pointer relaxation has a very limited value (benchmarked by 
>> multiple parties, including a party which implemented this feature in the 
>> GNU toolchain: even they can only say the optimization only applies to very 
>> specific projects).
>> The default value is confusing: as explained by the summary.
>>
>> I suspect that `-msmall-data-limit=8` is too conservative, maybe 16 would be 
>> better, I don't know. I think global pointer relaxation users should toggle 
>> this by themselves, not relying on `0` or `8` default decided by a bunch of 
>> strange conditions.
>
> I don't disagree that the small data limit being 8 rather than something else 
> doesn't seem to be particularly well motivated, but I understand that the 
> case where the option does make a difference is on embedded targets (I think 
> the data that was shared before was for SPEC, but could be wrong?). I think 
> we can generally expect more willingness for people targeting embedded 
> systems to explore different compiler flags,

Agree.

> but just matching gcc does feel like a better default. What do you think 
> about keeping the default for bare metal targets?

I am unsure we want to add the complexity and refrain from changing the default 
for bare metal targets due to haunted graveyards 
https://www.usenix.org/sites/default/files/conference/protected-files/srecon17americas_slides_reese.pdf

We are already different from GCC in a number of ways:

- for `-fpie`, we may emit `.sdata`/`.sbss` but GCC won't
- we accept `-G` while GCC doesn't.
- we don't emit `.srodata`.

I made a comment on https://lists.riscv.org/g/sig-toolchains/message/619 and 
informed GCC folks in case they can change the default as well.
If they don't, I think we made a good choice for not following this particular 
behavior.

(I feel sad that I did not see D57497  and it 
landed with a blocked review. If we started from scratch, we would probably run 
into a cleaner state.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152279/new/

https://reviews.llvm.org/D152279

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


[PATCH] D146777: [clang] Preliminary fat-lto-object support

2023-06-14 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth updated this revision to Diff 531534.
paulkirth added a comment.

Rebase and pass fat-lto-objects to LLD from clang.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146777/new/

https://reviews.llvm.org/D146777

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/CodeGen/embed-lto-fatlto.c
  clang/test/Driver/clang_f_opts.c
  clang/test/Driver/fatlto-objects.c

Index: clang/test/Driver/fatlto-objects.c
===
--- /dev/null
+++ clang/test/Driver/fatlto-objects.c
@@ -0,0 +1,10 @@
+// REQUIRES: x86_64-linux
+// RUN: %clang -target x86_64-unknown-linux-gnu -flto -ffat-lto-objects -fintegrated-as -### %s -c 2>&1 | FileCheck %s -check-prefix=CHECK-CC
+// CHECK-CC: -cc1
+// CHECK-CC: -emit-obj
+// CHECK-CC: -ffat-lto-objects
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -ffat-lto-objects -fintegrated-as -### %s -c 2>&1 | FileCheck %s -check-prefix=CHECK-CC-NOLTO
+// CHECK-CC-NOLTO: -cc1
+// CHECK-CC-NOLTO: -emit-obj
+// CHECK-CC-NOLTO-NOT: -ffat-lto-objects
Index: clang/test/Driver/clang_f_opts.c
===
--- clang/test/Driver/clang_f_opts.c
+++ clang/test/Driver/clang_f_opts.c
@@ -425,7 +425,6 @@
 // CHECK-WARNING-DAG: optimization flag '-fwhole-program' is not supported
 // CHECK-WARNING-DAG: optimization flag '-fcaller-saves' is not supported
 // CHECK-WARNING-DAG: optimization flag '-freorder-blocks' is not supported
-// CHECK-WARNING-DAG: optimization flag '-ffat-lto-objects' is not supported
 // CHECK-WARNING-DAG: optimization flag '-fmerge-constants' is not supported
 // CHECK-WARNING-DAG: optimization flag '-finline-small-functions' is not supported
 // CHECK-WARNING-DAG: optimization flag '-ftree-dce' is not supported
Index: clang/test/CodeGen/embed-lto-fatlto.c
===
--- /dev/null
+++ clang/test/CodeGen/embed-lto-fatlto.c
@@ -0,0 +1,9 @@
+// RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -S -flto=full -ffat-lto-objects -emit-llvm < %s  | FileCheck %s
+// RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -S -flto=full -ffat-lto-objects -emit-llvm < %s  | FileCheck %s
+//
+// CHECK: !{{[0-9]+}} = !{i32 1, !"ThinLTO", i32 0}
+// CHECK: !{{[0-9]+}} = !{i32 1, !"EnableSplitLTOUnit", i32 1}
+
+int test(void) {
+  return 0xabcd;
+}
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -619,6 +619,10 @@
 PluginName + Suffix,
 Plugin);
 CmdArgs.push_back(Args.MakeArgString(Twine(PluginPrefix) + Plugin));
+  }else{
+// For LLD we need to enable fat object support
+if (Args.hasArg(options::OPT_ffat_lto_objects))
+  CmdArgs.push_back("-fat-lto-objects");
   }
 
   const char *PluginOptPrefix = IsOSAIX ? "-bplugin_opt:" : "-plugin-opt=";
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -7294,6 +7294,14 @@
 }
   }
 
+  if (IsUsingLTO && Args.getLastArg(options::OPT_ffat_lto_objects)) {
+assert(LTOMode == LTOK_Full || LTOMode == LTOK_Thin);
+CmdArgs.push_back(Args.MakeArgString(
+Twine("-flto=") + (LTOMode == LTOK_Thin ? "thin" : "full")));
+CmdArgs.push_back("-flto-unit");
+CmdArgs.push_back("-ffat-lto-objects");
+  }
+
   if (Args.hasArg(options::OPT_forder_file_instrumentation)) {
  CmdArgs.push_back("-forder-file-instrumentation");
  // Enable order file instrumentation when ThinLTO is not on. When ThinLTO is
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -4654,8 +4654,13 @@
   }
   case phases::Backend: {
 if (isUsingLTO() && TargetDeviceOffloadKind == Action::OFK_None) {
-  types::ID Output =
-  Args.hasArg(options::OPT_S) ? types::TY_LTO_IR : types::TY_LTO_BC;
+  types::ID Output;
+  if (Args.hasArg(options::OPT_S))
+Output = types::TY_LTO_IR;
+  else if (Args.hasArg(options::OPT_ffat_lto_objects))
+Output = types::TY_PP_Asm;
+  else
+Output = types::TY_LTO_BC;
   return C.MakeAction(Input, Output);
 }
 if (isUsingLTO(/* IsOffload */ true) &&
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -24,6 

[PATCH] D148827: -fsanitize=function: support C

2023-06-14 Thread Mike Hommey via Phabricator via cfe-commits
glandium added a comment.

In D148827#4422794 , @MaskRay wrote:

> 6.3.2.3.1 is about a pointer casting rule, which is different from type 
> compatibility.

Pointer _conversion_ rule. Specifically, these are implicit conversions that 
require no casting. That doesn't invalidate that the rule from 6.2.7.2 still 
applies, and I don't see how the conversions can be non-UB without the types 
being compatible.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148827/new/

https://reviews.llvm.org/D148827

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


[PATCH] D150226: [Clang] Remove ability to downgrade warning on the diagnostic for setting a non fixed enum to a value outside the range of the enumeration values

2023-06-14 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D150226#4417539 , @aaron.ballman 
wrote:

> In D150226#4408980 , @dblaikie 
> wrote:
>
>> In D150226#4408563 , @erichkeane 
>> wrote:
>>
>>> In D150226#4408381 , 
>>> @aaron.ballman wrote:
>>>
 In D150226#4404808 , @rupprecht 
 wrote:

> I suppose including this warning in `ShowInSystemHeader` with your diff 
> above would be a good first step anyway, right? If we're about to make it 
> a hard error anyway, then making it a `ShowInSystemHeader` error first 
> would ease that transition.

 Yes and no.

 If we're going to turn something into a hard error, letting folks 
 implementing system headers know about it is important, so from that 
 perspective, it makes sense to enable the diagnostic in system headers. 
 However, *users* have no choice in their system headers (oftentimes) which 
 makes the diagnostic unactionable for them as they're not going to (and 
 shouldn't have to) modify system headers, so from that perspective, 
 enabling the diagnostic in a system header introduces friction.

 If this diagnostic is showing up in system headers, I think we would 
 likely need to consider adding a compatibility hack to allow Clang to 
 still consume that system header while erroring when outside of that 
 system header (we've done this before to keep STL implementations working, 
 for example). Between this need and the friction it causes users to have 
 an unactionable diagnostic, I think we probably should not enable 
 `ShowInSystemHeader`.
>>>
>>> It seems to me that if our concern is breaking system headers, we need to 
>>> do that with better testing.  Some sort of 'diagnostic group' for "This is 
>>> going to become an error *SOON*" mixed with us/vendors running that on 
>>> platforms we consider significant enough to not break.  But just diagnosing 
>>> on arbitrary users with no choice on how to fix the headers doesn't seem 
>>> appropriate.
>>
>> I think that's the request here: 
>> https://github.com/llvm/llvm-project/issues/63180
>
> +1, I think that request is a reasonable idea to help maintainers of system 
> headers.
>
> It sounds like we're in agreement that we should not enable 
> `ShowInSystemHeaders` for this, but it's not clear whether we've got 
> agreement yet that we can land this change right now. I think it's acceptable 
> to kick the can down the road by another release or so if we feel we need to, 
> but there is a hard stop to that at some point (some folks won't fix their 
> code until they're forced to do so, and there's not much we can do about 
> those cases).

FWIW, I still think it might be reasonable to `ShowInSystemHeaders` before 
turning something into an unconditional/hard error - `ShowInSystemHeaders` is 
strictly less intrusive than a hard error, and more intrusive than the warning 
as-is, so seems like a reasonable part of transitioning to a feature removal. 
(warning -> default-error -> show in system headers -> hard error) I don't have 
enough of an investment in this area to suggest that this /must/ be the way 
such a transition is done, but I have a hard time seeing why it would be better 
to avoid that intermediate step.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150226/new/

https://reviews.llvm.org/D150226

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


[PATCH] D152965: [OpenMP] Correctly diagnose conflicting target identifierers for AMDGPU

2023-06-14 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 531531.
jhuber6 added a comment.

Clang format


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152965/new/

https://reviews.llvm.org/D152965

Files:
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/amdgpu-openmp-toolchain.c


Index: clang/test/Driver/amdgpu-openmp-toolchain.c
===
--- clang/test/Driver/amdgpu-openmp-toolchain.c
+++ clang/test/Driver/amdgpu-openmp-toolchain.c
@@ -66,3 +66,7 @@
 // RUN: %clang -### -target x86_64-pc-linux-gnu -fopenmp 
--offload-arch=gfx90a:sramecc-:xnack+ \
 // RUN:   -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-TARGET-ID
 // CHECK-TARGET-ID: 
clang-offload-packager{{.*}}arch=gfx90a,kind=openmp,feature=-sramecc,feature=+xnack
+
+// RUN: not %clang -### -target x86_64-pc-linux-gnu -fopenmp 
--offload-arch=gfx90a,gfx90a:xnack+ \
+// RUN:   -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-TARGET-ID-ERROR
+// CHECK-TARGET-ID-ERROR: error: invalid offload arch combinations: 'gfx90a' 
and 'gfx90a:xnack+'
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -4313,8 +4313,8 @@
 /// incompatible pair if a conflict occurs.
 static std::optional>
 getConflictOffloadArchCombination(const llvm::DenseSet ,
-  Action::OffloadKind Kind) {
-  if (Kind != Action::OFK_HIP)
+  llvm::Triple Triple) {
+  if (!Triple.isAMDGPU())
 return std::nullopt;
 
   std::set ArchSet;
@@ -4399,7 +4399,8 @@
 }
   }
 
-  if (auto ConflictingArchs = getConflictOffloadArchCombination(Archs, Kind)) {
+  if (auto ConflictingArchs =
+  getConflictOffloadArchCombination(Archs, TC->getTriple())) {
 C.getDriver().Diag(clang::diag::err_drv_bad_offload_arch_combo)
 << ConflictingArchs->first << ConflictingArchs->second;
 C.setContainsError();


Index: clang/test/Driver/amdgpu-openmp-toolchain.c
===
--- clang/test/Driver/amdgpu-openmp-toolchain.c
+++ clang/test/Driver/amdgpu-openmp-toolchain.c
@@ -66,3 +66,7 @@
 // RUN: %clang -### -target x86_64-pc-linux-gnu -fopenmp --offload-arch=gfx90a:sramecc-:xnack+ \
 // RUN:   -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-TARGET-ID
 // CHECK-TARGET-ID: clang-offload-packager{{.*}}arch=gfx90a,kind=openmp,feature=-sramecc,feature=+xnack
+
+// RUN: not %clang -### -target x86_64-pc-linux-gnu -fopenmp --offload-arch=gfx90a,gfx90a:xnack+ \
+// RUN:   -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-TARGET-ID-ERROR
+// CHECK-TARGET-ID-ERROR: error: invalid offload arch combinations: 'gfx90a' and 'gfx90a:xnack+'
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -4313,8 +4313,8 @@
 /// incompatible pair if a conflict occurs.
 static std::optional>
 getConflictOffloadArchCombination(const llvm::DenseSet ,
-  Action::OffloadKind Kind) {
-  if (Kind != Action::OFK_HIP)
+  llvm::Triple Triple) {
+  if (!Triple.isAMDGPU())
 return std::nullopt;
 
   std::set ArchSet;
@@ -4399,7 +4399,8 @@
 }
   }
 
-  if (auto ConflictingArchs = getConflictOffloadArchCombination(Archs, Kind)) {
+  if (auto ConflictingArchs =
+  getConflictOffloadArchCombination(Archs, TC->getTriple())) {
 C.getDriver().Diag(clang::diag::err_drv_bad_offload_arch_combo)
 << ConflictingArchs->first << ConflictingArchs->second;
 C.setContainsError();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152965: [OpenMP] Correctly diagnose conflicting target identifierers for AMDGPU

2023-06-14 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added reviewers: JonChesterfield, yaxunl, jdoerfert.
Herald added subscribers: sunshaoce, kerbowa, guansong, tpr, dstuttard, 
jvesely, kzhuravl.
Herald added a project: All.
jhuber6 requested review of this revision.
Herald added subscribers: cfe-commits, jplehr, sstefan1, MaskRay, wdng.
Herald added a project: clang.

There are static checks on the target identifiers allowed in a single
TU. Previously theses checks were only applied to HIP even though they
should be the same for OpenMP targeting AMDGPU. Simply enable these
checks for OpenMP.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152965

Files:
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/amdgpu-openmp-toolchain.c


Index: clang/test/Driver/amdgpu-openmp-toolchain.c
===
--- clang/test/Driver/amdgpu-openmp-toolchain.c
+++ clang/test/Driver/amdgpu-openmp-toolchain.c
@@ -66,3 +66,7 @@
 // RUN: %clang -### -target x86_64-pc-linux-gnu -fopenmp 
--offload-arch=gfx90a:sramecc-:xnack+ \
 // RUN:   -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-TARGET-ID
 // CHECK-TARGET-ID: 
clang-offload-packager{{.*}}arch=gfx90a:sramecc-:xnack+,kind=openmp,feature=-sramecc,feature=+xnack
+
+// RUN: not %clang -### -target x86_64-pc-linux-gnu -fopenmp 
--offload-arch=gfx90a,gfx90a:xnack+ \
+// RUN:   -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-TARGET-ID-ERROR
+// CHECK-TARGET-ID-ERROR: error: invalid offload arch combinations: 'gfx90a' 
and 'gfx90a:xnack+'
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -4313,8 +4313,8 @@
 /// incompatible pair if a conflict occurs.
 static std::optional>
 getConflictOffloadArchCombination(const llvm::DenseSet ,
-  Action::OffloadKind Kind) {
-  if (Kind != Action::OFK_HIP)
+  llvm::Triple Triple) {
+  if (!Triple.isAMDGPU())
 return std::nullopt;
 
   std::set ArchSet;
@@ -4399,7 +4399,8 @@
 }
   }
 
-  if (auto ConflictingArchs = getConflictOffloadArchCombination(Archs, Kind)) {
+  if (auto ConflictingArchs = getConflictOffloadArchCombination(Archs,
+TC->getTriple())) {
 C.getDriver().Diag(clang::diag::err_drv_bad_offload_arch_combo)
 << ConflictingArchs->first << ConflictingArchs->second;
 C.setContainsError();


Index: clang/test/Driver/amdgpu-openmp-toolchain.c
===
--- clang/test/Driver/amdgpu-openmp-toolchain.c
+++ clang/test/Driver/amdgpu-openmp-toolchain.c
@@ -66,3 +66,7 @@
 // RUN: %clang -### -target x86_64-pc-linux-gnu -fopenmp --offload-arch=gfx90a:sramecc-:xnack+ \
 // RUN:   -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-TARGET-ID
 // CHECK-TARGET-ID: clang-offload-packager{{.*}}arch=gfx90a:sramecc-:xnack+,kind=openmp,feature=-sramecc,feature=+xnack
+
+// RUN: not %clang -### -target x86_64-pc-linux-gnu -fopenmp --offload-arch=gfx90a,gfx90a:xnack+ \
+// RUN:   -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-TARGET-ID-ERROR
+// CHECK-TARGET-ID-ERROR: error: invalid offload arch combinations: 'gfx90a' and 'gfx90a:xnack+'
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -4313,8 +4313,8 @@
 /// incompatible pair if a conflict occurs.
 static std::optional>
 getConflictOffloadArchCombination(const llvm::DenseSet ,
-  Action::OffloadKind Kind) {
-  if (Kind != Action::OFK_HIP)
+  llvm::Triple Triple) {
+  if (!Triple.isAMDGPU())
 return std::nullopt;
 
   std::set ArchSet;
@@ -4399,7 +4399,8 @@
 }
   }
 
-  if (auto ConflictingArchs = getConflictOffloadArchCombination(Archs, Kind)) {
+  if (auto ConflictingArchs = getConflictOffloadArchCombination(Archs,
+TC->getTriple())) {
 C.getDriver().Diag(clang::diag::err_drv_bad_offload_arch_combo)
 << ConflictingArchs->first << ConflictingArchs->second;
 C.setContainsError();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152882: [LinkerWrapper] Support device binaries in multiple link jobs

2023-06-14 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

In D152882#4422797 , @yaxunl wrote:

> In D152882#4422788 , @jhuber6 wrote:
>
>> In D152882#4421138 , @yaxunl wrote:
>>
>>> However, bitcode of  target ID gfx90a:xnack+ is allowed to link in bitcode 
>>> of target ID gfx90a as long as they are from different containers. So there 
>>> are two rules about target ID: 1. compatibility rules for objects/bitcode 
>>> in the same container 2. compatibility rules for linking bitcode of 
>>> different target ID's.
>>>
>>> we need tests for both rules.
>>
>> So I'm wondering why I'm allowed to do 
>> `--offload-arch=gfx90a,gfx90a:xnack+`. Shouldn't that be caught by 
>> `getConflictTargetIDCombination`? That seems like the proper place to 
>> diagnose this.
>
> clang --offload-arch=gfx90a,gfx90a:xnack+ -c a.hip
> clang: error: invalid offload arch combinations: 'gfx90a' and 'gfx90a:xnack+' 
> (for a specific processor, a feature should either exist in all offload 
> archs, or not exist in any offload archs)
>
> At least it is caught for HIP. OpenMP may not check that.



  if (Kind != Action::OFK_HIP)
return std::nullopt;

Yes, this would be the culprit. Guessing we shouldn't do that?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152882/new/

https://reviews.llvm.org/D152882

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


[PATCH] D152882: [LinkerWrapper] Support device binaries in multiple link jobs

2023-06-14 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In D152882#4422788 , @jhuber6 wrote:

> In D152882#4421138 , @yaxunl wrote:
>
>> However, bitcode of  target ID gfx90a:xnack+ is allowed to link in bitcode 
>> of target ID gfx90a as long as they are from different containers. So there 
>> are two rules about target ID: 1. compatibility rules for objects/bitcode in 
>> the same container 2. compatibility rules for linking bitcode of different 
>> target ID's.
>>
>> we need tests for both rules.
>
> So I'm wondering why I'm allowed to do `--offload-arch=gfx90a,gfx90a:xnack+`. 
> Shouldn't that be caught by `getConflictTargetIDCombination`? That seems like 
> the proper place to diagnose this.

clang --offload-arch=gfx90a,gfx90a:xnack+ -c a.hip
clang: error: invalid offload arch combinations: 'gfx90a' and 'gfx90a:xnack+' 
(for a specific processor, a feature should either exist in all offload archs, 
or not exist in any offload archs)

At least it is caught for HIP. OpenMP may not check that.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152882/new/

https://reviews.llvm.org/D152882

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


[PATCH] D148827: -fsanitize=function: support C

2023-06-14 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D148827#4422709 , @glandium wrote:

> OTOH. 6.2.7.3:
>
>> A composite type can be constructed from two types that are compatible; it 
>> is a type that is compatible with both of the two types (...)
>
> 6.2.7.5:
>
>> EXAMPLE Given the following two file scope declarations:
>> int f(int (*)(), double (*)[3]);
>> int f(int (*)(char *), double (*)[]);
>> The resulting composite type for the function is:
>> int f(int (*)(char *), double (*)[3]);
>
> This suggests that `int(*)()` and `int(*)(char*)` are compatible.

Yes, I mentioned this in my previous comment. This fragment is overly strict 
but I think it should be fine in practice. This mismatching is uncommon and 
old-style (parameter-less) definitions will be unsupported in C2x anyway.
The other direction is worked around by this patch (see 
`!isa(PointeeType)`).

  int foo() { return 42; } // old-style (parameter-less) definition, warned by 
-Wstrict-prototypes unless -std=c2x
  
  int main(void) {
//int (*qux)(int) = (int (*)(int))foo;
//qux(42);  // rejected by -fsanitize=function
  ...



> 6.2.7.2:
>
>> All declarations that refer to the same object or function shall have 
>> compatible type; otherwise, the behavior is undefined.
>
> 6.3.2.3.1:
>
>> A pointer to void may be converted to or from a pointer to any object type. 
>> A pointer to any object type may be converted to a pointer to void and back 
>> again; the result shall compare equal to the original pointer.
>
> These are either contradicting, making 6.3.2.3.1 UB, or void* is compatible 
> with other pointer types.

6.3.2.3.1 is about a pointer casting rule, which is different from type 
compatibility.
In C++, there is no C type compatibility rule, but we can still cast pointers.

To elaborate my previous comment about working around C projects, you can use 
the following to suppress instrumentation for all `.c` files (but not `.cc` or 
`.cpp`)

  # -fsanitize=undefined -fsanitize-ignorelist=a.ignorelist
  % cat a.ignorelist
  [function]
  src:*\.c


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148827/new/

https://reviews.llvm.org/D148827

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


[PATCH] D152473: [clang-format] Add test case for issue 63170

2023-06-14 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

In D152473#4410030 , @paulkirth wrote:

> In D152473#4409975 , 
> @MyDeveloperDay wrote:
>
>> In D152473#4409146 , @paulkirth 
>> wrote:
>>
>>> The point of this patch was to show a regression. I'm not trying to fix 
>>> anything per se. I'd like https://reviews.llvm.org/D151954  and anything 
>>> that depends on it reverted, since it breaks `clang-format`.
>>
>> I think its respectful to wait a little for the code owners to give you a LG 
>> unless the patch is breaking the unit tests.
>
> So first, no one here is trying to be disrespectful, we're all here to make 
> the compiler and surrounding tools better for everyone. That said, it's also 
> normally respectful to revert changes when others report that your patch has 
> a serious regression.  
> https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy
>
> I'm not sure how common this is, but in this case we found a test case that 
> was missing from the unit tests, otherwise the patches that were reverted 
> would never have landed. So, while I understand your point, reverting here is 
> in line w/ the communities policies. If there is a different interpretation I 
> should have on the policy, I'm happy to hear it, but as I read it, our 
> response here is in line w/ our typical developer expectations. My apologies 
> if any of this comes off as rude (being nuanced in text is hard) but I'm 
> trying to be very clear about my interpretation and rationale.

Please note the following from the patch reversion policy you linked above:

> If you are asked to revert by another contributor, please revert and discuss 
> the merits of the request offline (unless doing so would further destabilize 
> tip of tree).

and

> Reverts should be reasonably timely. ... If you are unsure, we encourage you 
> to reply to the commit thread, give the author a bit to respond, and then 
> proceed with the revert if the author doesn’t seem to be actively responding.

The revert 94e75469597f 
 was wrong 
as it destabilized the tip of the tree by breaking clang-format unit tests. 
(See D151954#4404731 .) Then another 
revert (i.e. this patch) accompanied with a test case irrelevant to D152305 
 that it was reverting was rushed in in order 
to "fix" the unit tests that 94e75469597f 
 had 
broken. Also, the regression was triggered by trailing whitespaces in your 
files. Although reverting D151954  solves the 
regression for you, it would leave other users in a limb as a few patches prior 
to and depending on it might have to be reverted as well. Maybe you could have 
temporarily worked around the regression (e.g. by removing the trailing spaces) 
while we were investigating the issue?

> As a last point we've had our CI broken by this since the initial patch 
> landed, and it's been several days since we first reported the issue. We're 
> certainly not trying to be discourteous w/ our actions, but it I also don't 
> think it's reasonable to expect that when community members report a serious 
> regression, file an issue, and provide a reproducer that they be expected to 
> wait days for a revert or forward fix.

Please review the timestamps. You first reported the issue in 
https://reviews.llvm.org/D151954#4403921, and the revert 94e75469597f 
 occurred 
less than 6 hours later.

Anyway, I've relanded D152305  using exactly 
the same diff and am working on a better solution than D151954 
. I will add you to the review list to make 
sure that it won't break your CI.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152473/new/

https://reviews.llvm.org/D152473

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


[PATCH] D152882: [LinkerWrapper] Support device binaries in multiple link jobs

2023-06-14 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

In D152882#4421138 , @yaxunl wrote:

> However, bitcode of  target ID gfx90a:xnack+ is allowed to link in bitcode of 
> target ID gfx90a as long as they are from different containers. So there are 
> two rules about target ID: 1. compatibility rules for objects/bitcode in the 
> same container 2. compatibility rules for linking bitcode of different target 
> ID's.
>
> we need tests for both rules.

So I'm wondering why I'm allowed to do `--offload-arch=gfx90a,gfx90a:xnack+`. 
Shouldn't that be caught by `getConflictTargetIDCombination`? That seems like 
the proper place to diagnose this.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152882/new/

https://reviews.llvm.org/D152882

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


[PATCH] D152882: [LinkerWrapper] Support device binaries in multiple link jobs

2023-06-14 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 531520.
jhuber6 added a comment.
Herald added subscribers: kerbowa, jvesely.

Adjusting test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152882/new/

https://reviews.llvm.org/D152882

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/amdgpu-openmp-toolchain.c
  clang/test/Driver/linker-wrapper.c
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
  clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
  llvm/include/llvm/Object/OffloadBinary.h

Index: llvm/include/llvm/Object/OffloadBinary.h
===
--- llvm/include/llvm/Object/OffloadBinary.h
+++ llvm/include/llvm/Object/OffloadBinary.h
@@ -17,6 +17,7 @@
 #ifndef LLVM_OBJECT_OFFLOADBINARY_H
 #define LLVM_OBJECT_OFFLOADBINARY_H
 
+#include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Object/Binary.h"
@@ -155,12 +156,22 @@
 /// owns its memory.
 class OffloadFile : public OwningBinary {
 public:
+  /// An ordered pair of the target triple and the architecture.
   using TargetID = std::pair;
 
   OffloadFile(std::unique_ptr Binary,
   std::unique_ptr Buffer)
   : OwningBinary(std::move(Binary), std::move(Buffer)) {}
 
+  Expected copy() const {
+std::unique_ptr Buffer = MemoryBuffer::getMemBufferCopy(
+getBinary()->getMemoryBufferRef().getBuffer());
+auto NewBinaryOrErr = OffloadBinary::create(*Buffer);
+if (!NewBinaryOrErr)
+  return NewBinaryOrErr.takeError();
+return OffloadFile(std::move(*NewBinaryOrErr), std::move(Buffer));
+  }
+
   /// We use the Triple and Architecture pair to group linker inputs together.
   /// This conversion function lets us use these inputs in a hash-map.
   operator TargetID() const {
@@ -168,6 +179,28 @@
   }
 };
 
+/// Queries if the target \p LHS is compatible with \p RHS for linking purposes.
+inline bool areTargetsCompatible(const OffloadFile::TargetID LHS,
+ const OffloadFile::TargetID RHS) {
+  if (LHS == RHS)
+return true;
+
+  // If the target is AMD we check the target IDs for compatibility. A target id
+  // is a string conforming to the folowing BNF syntax:
+  //
+  //  target-id ::= ' ( :  ( '+' | '-' ) )*'
+  //
+  // This is used to link mutually compatible architectures together.
+  llvm::Triple T(LHS.first);
+  if (!T.isAMDGPU())
+return false;
+
+  // The targets are compatible if the architecture is a subset of the other.
+  if (RHS.second.contains(LHS.second))
+return true;
+  return false;
+}
+
 /// Extracts embedded device offloading code from a memory \p Buffer to a list
 /// of \p Binaries.
 Error extractOffloadBinaries(MemoryBufferRef Buffer,
Index: clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
===
--- clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
+++ clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
@@ -67,6 +67,9 @@
 def arch_EQ : Joined<["--"], "arch=">,
   Flags<[DeviceOnlyOption, HelpHidden]>, MetaVarName<"">,
   HelpText<"The device subarchitecture">;
+def full_arch_EQ : Joined<["--"], "full-arch=">,
+  Flags<[DeviceOnlyOption, HelpHidden]>, MetaVarName<"">,
+  HelpText<"The fully qualifier device subarchitecture for AMD's target ID">;
 def triple_EQ : Joined<["--"], "triple=">,
   Flags<[DeviceOnlyOption, HelpHidden]>, MetaVarName<"">,
   HelpText<"The device target triple">;
Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -969,9 +969,13 @@
   for (Arg *A : Args)
 DAL.append(A);
 
-  // Set the subarchitecture and target triple for this compilation.
+  // Set the subarchitecture and target triple for this compilation. The input
+  // may be an AMDGPU target-id so we split off anything before the colon.
   const OptTable  = getOptTable();
   DAL.AddJoinedArg(nullptr, Tbl.getOption(OPT_arch_EQ),
+   Args.MakeArgString(
+   Input.front().getBinary()->getArch().split(':').first));
+  DAL.AddJoinedArg(nullptr, Tbl.getOption(OPT_full_arch_EQ),
Args.MakeArgString(Input.front().getBinary()->getArch()));
   DAL.AddJoinedArg(nullptr, Tbl.getOption(OPT_triple_EQ),
Args.MakeArgString(Input.front().getBinary()->getTriple()));
@@ -1001,23 +1005,13 @@
 /// Transforms all the extracted offloading input files into an image that can
 /// be registered by the runtime.
 Expected>
-linkAndWrapDeviceFiles(SmallVectorImpl ,
+linkAndWrapDeviceFiles(SmallVector> ,
const InputArgList , char **Argv, int Argc) {
   llvm::TimeTraceScope TimeScope("Handle all device input");
 
-  DenseMap> InputMap;
-  for (auto  : 

[clang-tools-extra] cf1c6da - [clang-tidy][NFC] Update ReleaseNotes to mention some performance changes in checks

2023-06-14 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-06-14T21:20:37Z
New Revision: cf1c6dae84320ca0a50da34c4e9bff89d2d82286

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

LOG: [clang-tidy][NFC] Update ReleaseNotes to mention some performance changes 
in checks

Included a note in the release documentation about the improved
performance of certain checks, allowing users who had previously
disabled them due to slowness to reconsider their decision.

Added: 


Modified: 
clang-tools-extra/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6e69b6019c548..32864fc13d834 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -268,6 +268,9 @@ Changes in existing checks
   ` check by adding support for
   other floating point representations in float constant like ``0.5L``.
 
+- Improved the performance of the :doc:`bugprone-reserved-identifier
+  ` check through 
optimizations.
+
 - Deprecated check-local options `HeaderFileExtensions` and 
`ImplementationFileExtensions`
   in :doc:`bugprone-suspicious-include
   ` check.
@@ -322,6 +325,9 @@ Changes in existing checks
   ` check.
   Global options of the same name should be used instead.
 
+- Improved the performance of the :doc:`misc-confusable-identifiers
+  ` check through optimizations.
+
 - Deprecated check-local options `HeaderFileExtensions`
   in :doc:`misc-definitions-in-headers
   ` check.
@@ -413,6 +419,9 @@ Changes in existing checks
   string for ``Prefix`` or ``Suffix`` options could result in the style not
   being used.
 
+- Improved the performance of the :doc:`readability-identifier-naming
+  ` check through 
optimizations.
+
 - Fixed a false positive in :doc:`readability-implicit-bool-conversion
   ` check warning would
   be unnecessarily emitted for explicit cast using direct list initialization.



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


[PATCH] D148827: -fsanitize=function: support C

2023-06-14 Thread Mike Hommey via Phabricator via cfe-commits
glandium added a comment.

OTOH. 6.2.7.3:

> A composite type can be constructed from two types that are compatible; it is 
> a type that is compatible with both of the two types (...)

6.2.7.5:

> EXAMPLE Given the following two file scope declarations:
> int f(int (*)(), double (*)[3]);
> int f(int (*)(char *), double (*)[]);
> The resulting composite type for the function is:
> int f(int (*)(char *), double (*)[3]);

This suggests that `int(*)()` and `int(*)(char*)` are compatible.

6.2.7.2:

> All declarations that refer to the same object or function shall have 
> compatible type; otherwise, the behavior is undefined.

6.3.2.3.1:

> A pointer to void may be converted to or from a pointer to any object type. A 
> pointer to any object type may be converted to a pointer to void and back 
> again; the result shall compare equal to the original pointer.

These are either contradicting, making 6.3.2.3.1 UB, or void* is compatible 
with other pointer types.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148827/new/

https://reviews.llvm.org/D148827

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


[clang] 04c0161 - Revert "[DebugInfo] Always emit `.debug_names` with DWARF 5 for Apple platforms"

2023-06-14 Thread Jonas Devlieghere via cfe-commits

Author: Jonas Devlieghere
Date: 2023-06-14T14:16:16-07:00
New Revision: 04c0161c027676119fdc617f5b883dbda97c8549

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

LOG: Revert "[DebugInfo] Always emit `.debug_names` with DWARF 5 for Apple 
platforms"

This reverts commit e0d57295bf6a3c04f2901d9c70f529d570f48b65 because the
accel-tables-apple.ll test is failing on a few buildbots.

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGen/debug-info-names.c
llvm/include/llvm/IR/DebugInfoMetadata.h
llvm/lib/AsmParser/LLLexer.cpp
llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
llvm/lib/IR/DebugInfoMetadata.cpp

Removed: 
llvm/test/DebugInfo/Inputs/name-table-kind-apple-4.ll
llvm/test/DebugInfo/Inputs/name-table-kind-apple-5.ll
llvm/test/DebugInfo/accel-tables-apple.ll



diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 2fd2227720a2a..edef27bdf377c 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -637,21 +637,17 @@ void CGDebugInfo::CreateCompileUnit() {
   SDK = *It;
   }
 
-  llvm::DICompileUnit::DebugNameTableKind NameTableKind =
-  static_cast(
-  CGOpts.DebugNameTable);
-  if (CGM.getTarget().getTriple().isNVPTX())
-NameTableKind = llvm::DICompileUnit::DebugNameTableKind::None;
-  else if (CGM.getTarget().getTriple().getVendor() == llvm::Triple::Apple)
-NameTableKind = llvm::DICompileUnit::DebugNameTableKind::Apple;
-
   // Create new compile unit.
   TheCU = DBuilder.createCompileUnit(
   LangTag, CUFile, CGOpts.EmitVersionIdentMetadata ? Producer : "",
   LO.Optimize || CGOpts.PrepareForLTO || CGOpts.PrepareForThinLTO,
   CGOpts.DwarfDebugFlags, RuntimeVers, CGOpts.SplitDwarfFile, EmissionKind,
   DwoId, CGOpts.SplitDwarfInlining, CGOpts.DebugInfoForProfiling,
-  NameTableKind, CGOpts.DebugRangesBaseAddress, remapDIPath(Sysroot), SDK);
+  CGM.getTarget().getTriple().isNVPTX()
+  ? llvm::DICompileUnit::DebugNameTableKind::None
+  : static_cast(
+CGOpts.DebugNameTable),
+  CGOpts.DebugRangesBaseAddress, remapDIPath(Sysroot), SDK);
 }
 
 llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {

diff  --git a/clang/test/CodeGen/debug-info-names.c 
b/clang/test/CodeGen/debug-info-names.c
index a807fb8c06696..841387d50fd44 100644
--- a/clang/test/CodeGen/debug-info-names.c
+++ b/clang/test/CodeGen/debug-info-names.c
@@ -1,12 +1,10 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-linux -emit-llvm 
-debug-info-kind=limited %s -o - | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-apple-macosx10.10.0 -emit-llvm 
-debug-info-kind=limited %s -o - | FileCheck --check-prefix=APPLE %s
-// RUN: %clang_cc1 -triple x86_64-unknown-linux -emit-llvm 
-debug-info-kind=limited %s -o - -gpubnames | FileCheck --check-prefix=DEFAULT 
%s
-// RUN: %clang_cc1 -triple x86_64-unknown-linux -emit-llvm 
-debug-info-kind=limited %s -o - -ggnu-pubnames | FileCheck --check-prefix=GNU 
%s
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - -gpubnames | 
FileCheck --check-prefix=DEFAULT %s
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - -ggnu-pubnames 
| FileCheck --check-prefix=GNU %s
 
 // CHECK: !DICompileUnit({{.*}}, nameTableKind: None
 // DEFAULT-NOT: !DICompileUnit({{.*}}, nameTableKind:
 // GNU: !DICompileUnit({{.*}}, nameTableKind: GNU
-// APPLE: !DICompileUnit({{.*}}, nameTableKind: Apple
 
 void f1(void) {
 }

diff  --git a/llvm/include/llvm/IR/DebugInfoMetadata.h 
b/llvm/include/llvm/IR/DebugInfoMetadata.h
index 6561224052097..defd1d5c2a1ea 100644
--- a/llvm/include/llvm/IR/DebugInfoMetadata.h
+++ b/llvm/include/llvm/IR/DebugInfoMetadata.h
@@ -1377,8 +1377,7 @@ class DICompileUnit : public DIScope {
 Default = 0,
 GNU = 1,
 None = 2,
-Apple = 3,
-LastDebugNameTableKind = Apple
+LastDebugNameTableKind = None
   };
 
   static std::optional getEmissionKind(StringRef Str);

diff  --git a/llvm/lib/AsmParser/LLLexer.cpp b/llvm/lib/AsmParser/LLLexer.cpp
index 7568fd43e1d08..23a7b4481110c 100644
--- a/llvm/lib/AsmParser/LLLexer.cpp
+++ b/llvm/lib/AsmParser/LLLexer.cpp
@@ -944,8 +944,7 @@ lltok::Kind LLLexer::LexIdentifier() {
 return lltok::EmissionKind;
   }
 
-  if (Keyword == "GNU" || Keyword == "Apple" || Keyword == "None" ||
-  Keyword == "Default") {
+  if (Keyword == "GNU" || Keyword == "None" || Keyword == "Default") {
 StrVal.assign(Keyword.begin(), Keyword.end());
 return lltok::NameTableKind;
   }

diff  --git a/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp 

[PATCH] D148697: [clang-tidy] Add more checks for functions which should be noexcept

2023-06-14 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai added a comment.

In D148697#4422642 , @PiotrZSL wrote:

> In D148697#4422629 , @nemanjai 
> wrote:
>
>> It was also causing PPC bots to break. I fixed it in 
>> https://reviews.llvm.org/rGffd7a200fdfbd01ef296101647d2f2da91ddfd41
>
> O, thank you. Thats explain a lot. Because when I look into cmake, 
> clangTidyPerformanceModule were already there because you already added it.

Yeah, sorry. I saw that Phabricator automatically added the mention into the 
Diffusion link but I forgot that it won't add it to the Differential and that I 
need to add it manually.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148697/new/

https://reviews.llvm.org/D148697

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


[PATCH] D148697: [clang-tidy] Add more checks for functions which should be noexcept

2023-06-14 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.

In D148697#4422629 , @nemanjai wrote:

> It was also causing PPC bots to break. I fixed it in 
> https://reviews.llvm.org/rGffd7a200fdfbd01ef296101647d2f2da91ddfd41

O, thank you. Thats explain a lot. Because when I look into cmake, 
clangTidyPerformanceModule were already there because you already added it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148697/new/

https://reviews.llvm.org/D148697

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


[PATCH] D148827: -fsanitize=function: support C

2023-06-14 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D148827#4422498 , @glandium wrote:

> In D148827#4379764 , @MaskRay wrote:
>
>> These cases are UB and should be caught. It's not an excuse that they use C.
>
> Are they really though?

They are.

>   struct A {
> int a;
>   };
>   
>   int foo(struct A *a) { return 42; }
>   
>   int bar(void *a) { return foo(a); }
>   
>   int main(void) {
> struct A a;
> bar();
> int (*qux)(void *) = (int (*)(void *))foo;
> qux(); // If this is UB, why isn't the call to foo from bar?
> return 0;
>   }
>
> Likewise for `int foo()` and `int bar(void)`/`int (*qux)(void)`.
> Likewise for `struct A* foo(void)` and `void *bar(void)`/`void *(*qux)(void)` 
> (surprisingly, clang doesn't emit this error for `struct A* foo()` and `void* 
> bar()`/`void*(*qux)()`)

C11 6.5.2.2p9 (as mentioned in the patch summary)

> If the function is defined with a type that is not compatible with the type 
> (of the expression) pointed to by the expression that denotes the called 
> function, the behavior is undefined.

`void *` and `struct A*` are not compatible per 6.7..6.1p2

> For two pointer types to be compatible, both shall be identically qualified 
> and both shall be pointers to compatible types.

For old-style (parameter-less) definitions (warned by `-Wstrict-prototypes` 
unless `-std=c2x`), we have the following behaviors:

  int foo() { return 42; } // old-style (parameter-less) definition, warned by 
-Wstrict-prototypes unless -std=c2x
  int bar(int a) { return 42; }
  
  int main(void) {
//int (*qux)(int) = (int (*)(int))foo;
//qux(42);  // rejected by -fsanitize=function
int (*qux)() = (int (*)())foo;
qux(); // not rejected by -fsanitize=function
return 0;
  }

If you enable `-fsanitize=undefined` for some C proijects with the UB, you can 
consider suppressing them with `ubsan_ignorelist.txt` or enabling 
`-fno-sanitize=function` for the C files.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148827/new/

https://reviews.llvm.org/D148827

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


[PATCH] D148697: [clang-tidy] Add more checks for functions which should be noexcept

2023-06-14 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai added a comment.

In D148697#4421739 , @Dinistro wrote:

> In D148697#4421643 , @PiotrZSL 
> wrote:
>
>> @Dinistro It compiles & links with clang 16 also (shared libs). So I'm 
>> unable to reproduce.
>
> I used the following command to build:
>
>   cmake -S/home/christianu/repos/llvm-project/llvm 
> -B/home/christianu/repos/llvm-project/build-clang-tidy -GNinja 
> -DLLVM_ENABLE_LLD=ON -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" 
> -DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_ENABLE_ASSERTIONS=ON 
> -DBUILD_SHARED_LIBS=ON -DLLVM_INCLUDE_UTILS=ON -DLLVM_INSTALL_UTILS=ON 
> -DLLVM_BUILD_EXAMPLES=OFF -DLLVM_CCACHE_BUILD=ON -DLLVM_OPTIMIZED_TABLEGEN=ON 
> -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=clang 
> -DCMAKE_CXX_COMPILER=clang++ -DLLVM_ENABLE_RUNTIMES=openmp

It was also causing PPC bots to break. I fixed it in 
https://reviews.llvm.org/rGffd7a200fdfbd01ef296101647d2f2da91ddfd41


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148697/new/

https://reviews.llvm.org/D148697

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


[clang] 5d54213 - [Clang][MS] Remove assertion on BaseOffset can't be smaller than Size.

2023-06-14 Thread Zequan Wu via cfe-commits

Author: Zequan Wu
Date: 2023-06-14T16:48:26-04:00
New Revision: 5d54213ee557a86fae82af0f75498adf02f24e82

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

LOG: [Clang][MS] Remove assertion on BaseOffset can't be smaller than Size.

This assertion triggered when we have two base classes sharing the same offset
and the first base is empty and the second class is non-empty.
Remove it for correctness.

I can't add a test case for this because -foverride-record-layout doesn't read
base class info at all. I can add that support later for testing if needed.

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D152472

Added: 
clang/test/CodeGenCXX/Inputs/override-layout-ms.layout
clang/test/CodeGenCXX/override-layout-ms.cpp

Modified: 
clang/include/clang/Frontend/LayoutOverrideSource.h
clang/lib/AST/RecordLayoutBuilder.cpp
clang/lib/Frontend/LayoutOverrideSource.cpp

Removed: 




diff  --git a/clang/include/clang/Frontend/LayoutOverrideSource.h 
b/clang/include/clang/Frontend/LayoutOverrideSource.h
index ea1611470a76a..c6e2d73111833 100644
--- a/clang/include/clang/Frontend/LayoutOverrideSource.h
+++ b/clang/include/clang/Frontend/LayoutOverrideSource.h
@@ -30,6 +30,12 @@ namespace clang {
   /// The alignment of the record.
   uint64_t Align;
 
+  /// The offsets of non-virtual base classes in the record.
+  SmallVector BaseOffsets;
+
+  /// The offsets of virtual base classes in the record.
+  SmallVector VBaseOffsets;
+
   /// The offsets of the fields, in source order.
   SmallVector FieldOffsets;
 };

diff  --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index aca50912dceac..3f836cb96be57 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -2926,8 +2926,7 @@ void MicrosoftRecordLayoutBuilder::layoutNonVirtualBase(
   bool FoundBase = false;
   if (UseExternalLayout) {
 FoundBase = External.getExternalNVBaseOffset(BaseDecl, BaseOffset);
-if (FoundBase) {
-  assert(BaseOffset >= Size && "base offset already allocated");
+if (BaseOffset > Size) {
   Size = BaseOffset;
 }
   }
@@ -3723,6 +3722,28 @@ void ASTContext::DumpRecordLayout(const RecordDecl *RD, 
raw_ostream ,
   if (Target->defaultsToAIXPowerAlignment())
 OS << "  PreferredAlignment:" << toBits(Info.getPreferredAlignment())
<< "\n";
+  if (const CXXRecordDecl *CXXRD = dyn_cast(RD)) {
+OS << "  BaseOffsets: [";
+const CXXRecordDecl *Base = nullptr;
+for (auto I : CXXRD->bases()) {
+  if (I.isVirtual())
+continue;
+  if (Base)
+OS << ", ";
+  Base = I.getType()->getAsCXXRecordDecl();
+  OS << Info.CXXInfo->BaseOffsets[Base].getQuantity();
+}
+OS << "]>\n";
+OS << "  VBaseOffsets: [";
+const CXXRecordDecl *VBase = nullptr;
+for (auto I : CXXRD->vbases()) {
+  if (VBase)
+OS << ", ";
+  VBase = I.getType()->getAsCXXRecordDecl();
+  OS << Info.CXXInfo->VBaseOffsets[VBase].VBaseOffset.getQuantity();
+}
+OS << "]>\n";
+  }
   OS << "  FieldOffsets: [";
   for (unsigned i = 0, e = Info.getFieldCount(); i != e; ++i) {
 if (i)

diff  --git a/clang/lib/Frontend/LayoutOverrideSource.cpp 
b/clang/lib/Frontend/LayoutOverrideSource.cpp
index 0d288db0632fd..f09444deb8d38 100644
--- a/clang/lib/Frontend/LayoutOverrideSource.cpp
+++ b/clang/lib/Frontend/LayoutOverrideSource.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 #include "clang/Frontend/LayoutOverrideSource.h"
 #include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/Basic/CharInfo.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
@@ -26,6 +27,18 @@ static std::string parseName(StringRef S) {
   return S.substr(0, Offset).str();
 }
 
+/// Parse an unsigned integer and move S to the next non-digit character.
+static bool parseUnsigned(StringRef , unsigned long long ) {
+  if (S.empty() || !isDigit(S[0]))
+return false;
+  unsigned Idx = 1;
+  while (Idx < S.size() && isDigit(S[Idx]))
+++Idx;
+  (void)S.substr(0, Idx).getAsInteger(10, ULL);
+  S = S.substr(Idx);
+  return true;
+}
+
 LayoutOverrideSource::LayoutOverrideSource(StringRef Filename) {
   std::ifstream Input(Filename.str().c_str());
   if (!Input.is_open())
@@ -80,8 +93,8 @@ LayoutOverrideSource::LayoutOverrideSource(StringRef 
Filename) {
   LineStr = LineStr.substr(Pos + strlen(" Size:"));
 
   unsigned long long Size = 0;
-  (void)LineStr.getAsInteger(10, Size);
-  CurrentLayout.Size = Size;
+  if (parseUnsigned(LineStr, Size))
+CurrentLayout.Size = Size;
   continue;
 }
 
@@ -92,12 +105,13 @@ 

[PATCH] D152472: [Clang][MS] Remove assertion on BaseOffset can't be smaller than Size.

2023-06-14 Thread Zequan Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5d54213ee557: [Clang][MS] Remove assertion on BaseOffset 
cant be smaller than Size. (authored by zequanwu).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152472/new/

https://reviews.llvm.org/D152472

Files:
  clang/include/clang/Frontend/LayoutOverrideSource.h
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/lib/Frontend/LayoutOverrideSource.cpp
  clang/test/CodeGenCXX/Inputs/override-layout-ms.layout
  clang/test/CodeGenCXX/override-layout-ms.cpp

Index: clang/test/CodeGenCXX/override-layout-ms.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/override-layout-ms.cpp
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -w -triple=x86_64-pc-win32 -fms-compatibility -fdump-record-layouts -foverride-record-layout=%S/Inputs/override-layout-ms.layout %s | FileCheck  %s
+// RUN: %clang_cc1 -w -triple=x86_64-pc-win32 -fms-compatibility -fdump-record-layouts %s | FileCheck  %s
+
+// CHECK: *** Dumping AST Record Layout
+// CHECK:  0 | struct E1 (empty)
+// CHECK:| [sizeof=1, align=1,
+// CHECK:|  nvsize=0, nvalign=1]
+// CHECK: *** Dumping AST Record Layout
+// CHECK:  0 | struct Mid
+// CHECK:  0 |   void * p
+// CHECK:| [sizeof=8, align=8,
+// CHECK:|  nvsize=8, nvalign=8]
+// CHECK: *** Dumping AST Record Layout
+// CHECK:  0 | struct E2 (empty)
+// CHECK:| [sizeof=1, align=1,
+// CHECK:|  nvsize=0, nvalign=1]
+// CHECK: *** Dumping AST Record Layout
+// CHECK:  0 | struct Combine
+// CHECK:  0 |   struct E1 (base) (empty)
+// CHECK:  0 |   struct Mid (base)
+// CHECK:  0 | void * p
+// CHECK:  0 |   struct E2 (base) (empty)
+// CHECK:| [sizeof=8, align=8,
+// CHECK:|  nvsize=8, nvalign=8]
+// CHECK: *** Dumping AST Record Layout
+// CHECK:  0 | struct Combine2
+// CHECK:  0 |   struct VB1 (primary base)
+// CHECK:  0 | (VB1 vftable pointer)
+// CHECK:  8 |   struct VB2 (base)
+// CHECK:  8 | (VB2 vftable pointer)
+// CHECK:| [sizeof=16, align=8,
+// CHECK:|  nvsize=16, nvalign=8]
+
+
+struct E1 {};
+struct E2 {};
+struct Mid {void *p; };
+struct __declspec(empty_bases) Combine : E1, Mid, E2 {};
+struct VB1 { virtual void foo() {}};
+struct VB2 { virtual void bar() {}};
+struct Combine2: VB1, VB2 {};
+Combine g;
+Combine2 f;
\ No newline at end of file
Index: clang/test/CodeGenCXX/Inputs/override-layout-ms.layout
===
--- /dev/null
+++ clang/test/CodeGenCXX/Inputs/override-layout-ms.layout
@@ -0,0 +1,49 @@
+*** Dumping AST Record Layout
+Type: struct E1
+
+Layout: 
+  VBaseOffsets: []>
+  FieldOffsets: []>
+
+*** Dumping AST Record Layout
+Type: struct Mid
+
+Layout: 
+  VBaseOffsets: []>
+  FieldOffsets: [0]>
+
+*** Dumping AST Record Layout
+Type: struct E2
+
+Layout: 
+  VBaseOffsets: []>
+  FieldOffsets: []>
+
+*** Dumping AST Record Layout
+Type: struct Combine
+
+Layout: 
+  VBaseOffsets: []>
+  FieldOffsets: []>
+
+*** Dumping AST Record Layout
+Type: struct Combine2
+
+Layout: 
+  VBaseOffsets: []>
+  FieldOffsets: []>
Index: clang/lib/Frontend/LayoutOverrideSource.cpp
===
--- clang/lib/Frontend/LayoutOverrideSource.cpp
+++ clang/lib/Frontend/LayoutOverrideSource.cpp
@@ -7,6 +7,7 @@
 //===--===//
 #include "clang/Frontend/LayoutOverrideSource.h"
 #include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/Basic/CharInfo.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
@@ -26,6 +27,18 @@
   return S.substr(0, Offset).str();
 }
 
+/// Parse an unsigned integer and move S to the next non-digit character.
+static bool parseUnsigned(StringRef , unsigned long long ) {
+  if (S.empty() || !isDigit(S[0]))
+return false;
+  unsigned Idx = 1;
+  while (Idx < S.size() && isDigit(S[Idx]))
+++Idx;
+  (void)S.substr(0, Idx).getAsInteger(10, ULL);
+  S = S.substr(Idx);
+  return true;
+}
+
 LayoutOverrideSource::LayoutOverrideSource(StringRef Filename) {
   std::ifstream Input(Filename.str().c_str());
   if (!Input.is_open())
@@ -80,8 +93,8 @@
   LineStr = LineStr.substr(Pos + strlen(" Size:"));
 
   unsigned long long Size = 0;
-  (void)LineStr.getAsInteger(10, Size);
-  CurrentLayout.Size = Size;
+  if (parseUnsigned(LineStr, Size))
+CurrentLayout.Size = Size;
   continue;
 }
 
@@ -92,12 +105,13 @@
   LineStr = LineStr.substr(Pos + strlen("Alignment:"));
 
   unsigned long long Alignment = 0;
-  (void)LineStr.getAsInteger(10, Alignment);
-  CurrentLayout.Align = 

[clang] 8193b29 - Revert "[HIP] Allow std::malloc in device function"

2023-06-14 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2023-06-14T16:33:30-04:00
New Revision: 8193b291cefa732dd37fc917bd2921385e639d21

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

LOG: Revert "[HIP] Allow std::malloc in device function"

This reverts commit f5033c37025db46df95a7859d7189d09b5e3433e.

revert this patch since it causes regressions for Tensile. A
reduced test case is:

int main()
{
std::shared_ptr a;
a = std::shared_ptr(
(float*)std::malloc(sizeof(float) * 100),
std::free
);
return 0;
}

Will fix the issue then re-commit.

Fixes: SWDEV-405317

Added: 


Modified: 
clang/lib/Headers/__clang_hip_runtime_wrapper.h
clang/test/Headers/Inputs/include/cstdlib
clang/test/Headers/Inputs/include/math.h
clang/test/Headers/hip-header.hip

Removed: 
clang/test/Headers/Inputs/include/sstream
clang/test/Headers/Inputs/include/stdexcept



diff  --git a/clang/lib/Headers/__clang_hip_runtime_wrapper.h 
b/clang/lib/Headers/__clang_hip_runtime_wrapper.h
index ed1550038e63e..e8817073efdbc 100644
--- a/clang/lib/Headers/__clang_hip_runtime_wrapper.h
+++ b/clang/lib/Headers/__clang_hip_runtime_wrapper.h
@@ -47,9 +47,28 @@ extern "C" {
 #endif //__cplusplus
 
 #if !defined(__HIPCC_RTC__)
+#include 
+#include 
+#include 
 #if __has_include("hip/hip_version.h")
 #include "hip/hip_version.h"
 #endif // __has_include("hip/hip_version.h")
+#else
+typedef __SIZE_TYPE__ size_t;
+// Define macros which are needed to declare HIP device API's without standard
+// C/C++ headers. This is for readability so that these API's can be written
+// the same way as non-hipRTC use case. These macros need to be popped so that
+// they do not pollute users' name space.
+#pragma push_macro("NULL")
+#pragma push_macro("uint32_t")
+#pragma push_macro("uint64_t")
+#pragma push_macro("CHAR_BIT")
+#pragma push_macro("INT_MAX")
+#define NULL (void *)0
+#define uint32_t __UINT32_TYPE__
+#define uint64_t __UINT64_TYPE__
+#define CHAR_BIT __CHAR_BIT__
+#define INT_MAX __INTMAX_MAX__
 #endif // __HIPCC_RTC__
 
 typedef __SIZE_TYPE__ __hip_size_t;
@@ -59,13 +78,11 @@ extern "C" {
 #endif //__cplusplus
 
 #if HIP_VERSION_MAJOR * 100 + HIP_VERSION_MINOR >= 405
-__device__ unsigned long long __ockl_dm_alloc(unsigned long long __size);
-__device__ void __ockl_dm_dealloc(unsigned long long __addr);
+extern "C" __device__ unsigned long long __ockl_dm_alloc(unsigned long long 
__size);
+extern "C" __device__ void __ockl_dm_dealloc(unsigned long long __addr);
 #if __has_feature(address_sanitizer)
-__device__ unsigned long long __asan_malloc_impl(unsigned long long __size,
- unsigned long long __pc);
-__device__ void __asan_free_impl(unsigned long long __addr,
- unsigned long long __pc);
+extern "C" __device__ unsigned long long __asan_malloc_impl(unsigned long long 
__size, unsigned long long __pc);
+extern "C" __device__ void __asan_free_impl(unsigned long long __addr, 
unsigned long long __pc);
 __attribute__((noinline, weak)) __device__ void *malloc(__hip_size_t __size) {
   unsigned long long __pc = (unsigned long long)__builtin_return_address(0);
   return (void *)__asan_malloc_impl(__size, __pc);
@@ -74,7 +91,7 @@ __attribute__((noinline, weak)) __device__ void free(void 
*__ptr) {
   unsigned long long __pc = (unsigned long long)__builtin_return_address(0);
   __asan_free_impl((unsigned long long)__ptr, __pc);
 }
-#else // __has_feature(address_sanitizer)
+#else
 __attribute__((weak)) inline __device__ void *malloc(__hip_size_t __size) {
   return (void *) __ockl_dm_alloc(__size);
 }
@@ -92,7 +109,7 @@ __attribute__((weak)) inline __device__ void 
*malloc(__hip_size_t __size) {
 __attribute__((weak)) inline __device__ void free(void *__ptr) {
   __hip_free(__ptr);
 }
-#else  // __HIP_ENABLE_DEVICE_MALLOC__
+#else
 __attribute__((weak)) inline __device__ void *malloc(__hip_size_t __size) {
   __builtin_trap();
   return (void *)0;
@@ -100,38 +117,13 @@ __attribute__((weak)) inline __device__ void 
*malloc(__hip_size_t __size) {
 __attribute__((weak)) inline __device__ void free(void *__ptr) {
   __builtin_trap();
 }
-#endif // __HIP_ENABLE_DEVICE_MALLOC__
+#endif
 #endif // HIP version check
 
 #ifdef __cplusplus
 } // extern "C"
 #endif //__cplusplus
 
-#if !defined(__HIPCC_RTC__)
-#include 
-#include 
-#include 
-#if __has_include("hip/hip_version.h")
-#include "hip/hip_version.h"
-#endif // __has_include("hip/hip_version.h")
-#else
-typedef __SIZE_TYPE__ size_t;
-// Define macros which are needed to declare HIP device API's without standard
-// C/C++ headers. This is for readability so that these API's can be written
-// the same way as non-hipRTC use case. These macros need to be popped so that
-// they do not 

[PATCH] D152818: [Clang] Fix assertion when pragma FENV_ACCESS is used with a throw function.

2023-06-14 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added a comment.

In D152818#4421064 , @nicolerabjohn 
wrote:

> I've opened an issue (https://github.com/llvm/llvm-project/issues/63063) 
> where we hit the same assertion. There's a smaller test case, and we've done 
> enough investigation that we understand the problem. I'd be happy to discuss 
> over on the issue as well.

Thanks. That sounds good!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152818/new/

https://reviews.llvm.org/D152818

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


[PATCH] D148827: -fsanitize=function: support C

2023-06-14 Thread Mike Hommey via Phabricator via cfe-commits
glandium added a comment.

In D148827#4379764 , @MaskRay wrote:

> These cases are UB and should be caught. It's not an excuse that they use C.

Are they really though?

  struct A {
int a;
  };
  
  int foo(struct A *a) { return 42; }
  
  int bar(void *a) { return foo(a); }
  
  int main(void) {
struct A a;
bar();
int (*qux)(void *) = (int (*)(void *))foo;
qux(); // If this is UB, why isn't the call to foo from bar?
return 0;
  }

Likewise for `int foo()` and `int bar(void)`/`int (*qux)(void)`.
Likewise for `struct A* foo(void)` and `void *bar(void)`/`void *(*qux)(void)` 
(surprisingly, clang doesn't emit this error for `struct A* foo()` and `void* 
bar()`/`void*(*qux)()`)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148827/new/

https://reviews.llvm.org/D148827

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


[PATCH] D59528: [clang-tidy] Expand modular headers for PPCallbacks

2023-06-14 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.
Herald added subscribers: carlosgalvezp, shchenz.
Herald added a project: All.

Looks like this change is responsible for 
https://github.com/llvm/llvm-project/issues/59807 and 
https://github.com/llvm/llvm-project/issues/62337 issues.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59528/new/

https://reviews.llvm.org/D59528

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


[PATCH] D152741: [WPD] implement -fskip-vtable-filepaths

2023-06-14 Thread Di Mo via Phabricator via cfe-commits
modimo added a comment.

In D152741#4421067 , @tejohnson wrote:

> In D152741#4419366 , @modimo wrote:
>
>> In D152741#4419324 , @tejohnson 
>> wrote:
>>
>>> In D152741#4419265 , @modimo 
>>> wrote:
>>>
 In D152741#4418831 , @tejohnson 
 wrote:

> I think I understand the motivation, but not sure I agree this is the 
> right approach - can you simply not pass -flto-unit and 
> -fwhole-program-vtables for these files?

 For our third-party libraries, they're pre-built into native files by GCC 
 so that's unfortunately not an option.
>>>
>>> I'm confused - how would you pass this new option then? I was assuming you 
>>> were passing this option to some LLVM built files at the interface of those 
>>> libraries. In which case not passing -flto-unit and 
>>> -fwhole-program-visibility should have a similar effect (suppress the type 
>>> metadata).
>>
>> Oh I see, I misunderstood. Yes this is being passed to LLVM built files. We 
>> want to avoid manual allowlists/blocklists because code changes make it less 
>> flexible and scalable than an automatic option.
>
> It seems like you need allowlists or blocklists in either case - either it is 
> passed as a regex via the option proposed here, or the build system modifies 
> the options for that set of files.
>
>> This can also be pretty tricky to do correctly since we can get type 
>> metadata from multiple TUs and all of them would need to be opted out for 
>> WPD to not kick in.
>
> But clang is presumably compiling a single TU at a time, so your regex needs 
> to cover them all anyway? I'm not sure I understand the distinction between 
> doing something like -fskip-vtable-filepaths=third-party/.* vs something like 
> applying -funknown-vtable-visibility to each third-party/*.cc compile.

The blocklists need to be enforced on internal files that interact with native 
libraries and those live in many different areas:

  ; /third-party/include/boost.h
  
  class A {}
  
  ; /internal-source/a.cpp
  #include "boost.h"
  
  class B : public A
  
  ; /third-party/lib/boost.a
  #include "boost.h"
  
  class C : public A

That being said, this is something the build system can detect and mark.

> I really think the logic for which files to apply this option to belongs in 
> the build system, not in the clang driver - just like any other clang option. 
> It isn't clear to me why this particular option should be applied based on a 
> file regex.

The big advantage of doing this in the FE is that we know which types are 
actually coming from the native headers. Blocking all types in the TU is overly 
conservative and also less stable as header changes can effectively turn on/off 
unrelated large chunks of WPD.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152741/new/

https://reviews.llvm.org/D152741

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


[PATCH] D148385: [RISCV] Implement KCFI operand bundle lowering

2023-06-14 Thread Sami Tolvanen via Phabricator via cfe-commits
samitolvanen added a comment.

> Needs some thoughts to merge the above paragraphs with the existing one

Great points. I updated the commit message and tried to capture most of these, 
PTAL.




Comment at: llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp:332
+  continue;
+while (!isRegAvailable(NextReg))
+  ++NextReg;

MaskRay wrote:
> As a minor optimization to skip one redundant `isRegAvailable` call: `while 
> (!isRegAvailable(++NextReg));`
`Reg` != `NextReg` here, and using `while (!isRegAvailable(++NextReg))` would 
always skip the first alternative register by first incrementing `NextReg` 
before calling `isRegsAvailable`. What am I missing?



Comment at: llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp:368
+  // Load the expected type hash.
+  const int64_t Type = MI.getOperand(1).getImm();
+  const int64_t Hi20 = ((Type + 0x800) >> 12) & 0xF;

MaskRay wrote:
> `int64_t` is the return type of `getImm`, not the original `KCFI_CHECK` 
> operand type. Casting this to a `uint32_t` is perhaps clearer.
I don't think casting this to `uint32_t` make sense since we'd have to cast it 
back to a larger type immediately below (to prevent `+ 0x800` from 
overflowing). I changed the comment to indicate this is a 32-bit value though.



Comment at: llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp:375
+MCInstBuilder(RISCV::LUI).addReg(ScratchRegs[1]).addImm(Hi20));
+  if (Lo12 || Hi20 == 0)
+EmitToStreamer(*OutStreamer,

MaskRay wrote:
> Is `Hi20 == 0` tested?
Good catch, added a test.



Comment at: llvm/lib/Target/RISCV/RISCVISelLowering.cpp:14427
   SDValue Callee = CLI.Callee;
+  bool IsCFICall = CLI.CB && CLI.CB->isIndirectCall() && CLI.CFIType;
   bool  = CLI.IsTailCall;

MaskRay wrote:
> If `CLI.CFIType != 0`, is `CLI.CB->isIndirectCall()` possible? If not, add an 
> assert?
> This is  an opportunity to save a redundant check.
Sure. `CFIType` should be set only for indirect calls when we reach this point.



Comment at: llvm/test/CodeGen/RISCV/kcfi-patchable-function-prefix.ll:4
+
+; NOC:.p2align 2
+; C:  .p2align 1

MaskRay wrote:
> f1/f2/f3/f4 have the same shape. Without increasing the number of functions, 
> we can make some disturbance (e.g. add one extra indirect call, use inline 
> asm to clobber some registers) to check various cases without using .mir 
> tests. `.mir` tests are fine, but the signal-to-noise ratio is not great and 
> readers can be lost in the paramemters...
There are four functions because we're testing type hash locations in relation 
to patchable-function-prefix nops in four different cases, in addition to the 
code generated for KCFI checks. I'm not sure there's a way to do this with 
fewer functions.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148385/new/

https://reviews.llvm.org/D148385

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


[PATCH] D148385: [RISCV] Implement KCFI operand bundle lowering

2023-06-14 Thread Sami Tolvanen via Phabricator via cfe-commits
samitolvanen updated this revision to Diff 531476.
samitolvanen marked 9 inline comments as done.
samitolvanen added a comment.

Addressed feedback.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148385/new/

https://reviews.llvm.org/D148385

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
  llvm/lib/Target/RISCV/RISCVISelLowering.cpp
  llvm/lib/Target/RISCV/RISCVISelLowering.h
  llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
  llvm/lib/Target/RISCV/RISCVInstrInfo.h
  llvm/lib/Target/RISCV/RISCVInstrInfo.td
  llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
  llvm/test/CodeGen/RISCV/O0-pipeline.ll
  llvm/test/CodeGen/RISCV/O3-pipeline.ll
  llvm/test/CodeGen/RISCV/kcfi-isel.mir
  llvm/test/CodeGen/RISCV/kcfi-patchable-function-prefix.ll
  llvm/test/CodeGen/RISCV/kcfi.ll
  llvm/test/CodeGen/RISCV/kcfi.mir

Index: llvm/test/CodeGen/RISCV/kcfi.mir
===
--- /dev/null
+++ llvm/test/CodeGen/RISCV/kcfi.mir
@@ -0,0 +1,185 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 2
+# RUN: llc -mtriple=riscv64 -stop-after=kcfi -o - %s | FileCheck %s
+--- |
+  ; ModuleID = ''
+  source_filename = ""
+  target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"
+  target triple = "riscv64"
+
+  define void @f1(ptr noundef %x) !kcfi_type !1 {
+call void %x() [ "kcfi"(i32 12345678) ]
+ret void
+  }
+
+  define void @f2(ptr noundef %x) #0 {
+tail call void %x() [ "kcfi"(i32 12345678) ]
+ret void
+  }
+
+  attributes #0 = { "patchable-function-entry"="2" }
+
+  !llvm.module.flags = !{!0}
+
+  !0 = !{i32 4, !"kcfi", i32 1}
+  !1 = !{i32 12345678}
+
+...
+---
+name:f1
+alignment:   4
+exposesReturnsTwice: false
+legalized:   false
+regBankSelected: false
+selected:false
+failedISel:  false
+tracksRegLiveness: true
+hasWinCFI:   false
+callsEHReturn:   false
+callsUnwindInit: false
+hasEHCatchret:   false
+hasEHScopes: false
+hasEHFunclets:   false
+isOutlined:  false
+debugInstrRef:   false
+failsVerification: false
+tracksDebugUserValues: true
+registers:   []
+liveins:
+  - { reg: '$x10', virtual-reg: '' }
+frameInfo:
+  isFrameAddressTaken: false
+  isReturnAddressTaken: false
+  hasStackMap: false
+  hasPatchPoint:   false
+  stackSize:   16
+  offsetAdjustment: 0
+  maxAlignment:8
+  adjustsStack:true
+  hasCalls:true
+  stackProtector:  ''
+  functionContext: ''
+  maxCallFrameSize: 0
+  cvBytesOfCalleeSavedRegisters: 0
+  hasOpaqueSPAdjustment: false
+  hasVAStart:  false
+  hasMustTailInVarArgFunc: false
+  hasTailCall: false
+  localFrameSize:  0
+  savePoint:   ''
+  restorePoint:''
+fixedStack:  []
+stack:
+  - { id: 0, name: '', type: spill-slot, offset: -8, size: 8, alignment: 8,
+  stack-id: default, callee-saved-register: '$x1', callee-saved-restored: true,
+  debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
+callSites:   []
+debugValueSubstitutions: []
+constants:   []
+machineFunctionInfo:
+  varArgsFrameIndex: 0
+  varArgsSaveSize: 0
+body: |
+  bb.0 (%ir-block.0):
+liveins: $x10, $x1
+
+; CHECK-LABEL: name: f1
+; CHECK: liveins: $x1, $x10
+; CHECK-NEXT: {{  $}}
+; CHECK-NEXT: $x2 = frame-setup ADDI $x2, -16
+; CHECK-NEXT: frame-setup CFI_INSTRUCTION def_cfa_offset 16
+; CHECK-NEXT: SD $x1, $x2, 8 :: (store (s64) into %stack.1)
+; CHECK-NEXT: frame-setup CFI_INSTRUCTION offset $x1, -8
+; CHECK-NEXT: $x2 = frame-setup ADDI $x2, -16
+; CHECK-NEXT: frame-setup CFI_INSTRUCTION def_cfa_offset 16
+; CHECK-NEXT: SD $x1, $x2, 8 :: (store (s64) into %stack.0)
+; CHECK-NEXT: frame-setup CFI_INSTRUCTION offset $x1, -8
+; CHECK-NEXT: BUNDLE implicit-def dead $x6, implicit-def dead $x7, implicit-def dead $x28, implicit-def dead $x29, implicit-def dead $x30, implicit-def dead $x31, implicit-def dead $x1, implicit-def $x2, implicit $x10 {
+; CHECK-NEXT:   KCFI_CHECK $x10, 12345678, implicit-def $x6, implicit-def $x7, implicit-def $x28, implicit-def $x29, implicit-def $x30, implicit-def $x31
+; CHECK-NEXT:   PseudoCALLIndirect $x10, csr_ilp32_lp64, implicit-def dead $x1, implicit-def $x2
+; CHECK-NEXT: }
+; CHECK-NEXT: dead $x1 = LD $x2, 8 :: (load (s64) from %stack.0)
+; CHECK-NEXT: $x2 = frame-destroy ADDI $x2, 16
+; CHECK-NEXT: $x1 = LD $x2, 8 :: (load (s64) from %stack.1)
+; CHECK-NEXT: $x2 = frame-destroy ADDI $x2, 16
+; CHECK-NEXT: PseudoRET
+$x2 = frame-setup ADDI $x2, -16
+frame-setup CFI_INSTRUCTION def_cfa_offset 16
+SD killed $x1, $x2, 8 :: (store (s64) into %stack.0)
+frame-setup CFI_INSTRUCTION offset $x1, -8
+BUNDLE implicit-def $x6, implicit-def $x7, implicit-def $x28, implicit-def $x29, implicit-def $x30, implicit-def $x31, implicit-def dead $x1, 

[PATCH] D152856: [Driver] Allow warning for unclaimed TargetSpecific options

2023-06-14 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added inline comments.



Comment at: llvm/include/llvm/Option/Arg.h:53
+  /// This is used for generating an "argument unused" warning (without
+  /// clang::driver::options::TargetSpecific) or "unsupported option" error
+  /// (with TargetSpecific).

MaskRay wrote:
> mstorsjo wrote:
> > Technically, as this is a llvm level API, talking about clang specific 
> > behaviours here is a bit at the wrong level.
> Yes. LLVMOption was originally part of Clang and was moved to llvm/.
> 
> The "argument unused" string is also quite Clang-specific. There are other 
> stuff talking about Clang behaviors, e.g.  suggestValueCompletions, `Alias` 
> (`-finput-charset=utf-8`). I wish that this is not too bad.
Ok, fair enough - consider this remark withdrawn then. Even if mislayered, 
detailed comments explaining the reason for the field is better than no 
explanations.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152856/new/

https://reviews.llvm.org/D152856

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


[PATCH] D118754: [DebugInfo] Always emit `.debug_names` with dwarf 5 for Apple platforms

2023-06-14 Thread Jonas Devlieghere via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe0d57295bf6a: [DebugInfo] Always emit `.debug_names` with 
DWARF 5 for Apple platforms (authored by JDevlieghere).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D118754/new/

https://reviews.llvm.org/D118754

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGen/debug-info-names.c
  llvm/include/llvm/IR/DebugInfoMetadata.h
  llvm/lib/AsmParser/LLLexer.cpp
  llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
  llvm/lib/IR/DebugInfoMetadata.cpp
  llvm/test/DebugInfo/Inputs/name-table-kind-apple-4.ll
  llvm/test/DebugInfo/Inputs/name-table-kind-apple-5.ll
  llvm/test/DebugInfo/accel-tables-apple.ll

Index: llvm/test/DebugInfo/accel-tables-apple.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/accel-tables-apple.ll
@@ -0,0 +1,55 @@
+; Verify the emission of accelerator tables for nameTableKind: Apple
+
+; Darwin has the apple tables unless we specifically tune for gdb
+; RUN: llc -mtriple=x86_64-apple-darwin12 -filetype=obj < %S/Inputs/name-table-kind-apple-5.ll \
+; RUN:   | llvm-readobj --sections - | FileCheck --check-prefix=DEBUG_NAMES %s
+; RUN: llc -mtriple=x86_64-apple-darwin12 -filetype=obj < %S/Inputs/name-table-kind-apple-4.ll \
+; RUN:   | llvm-readobj --sections - | FileCheck --check-prefix=APPLE %s
+
+; APPLE-NOT: debug_names
+; APPLE-NOT: debug{{.*}}pub
+; APPLE: apple_names
+; APPLE-NOT: debug_names
+; APPLE-NOT: debug{{.*}}pub
+
+; DEBUG_NAMES-NOT: apple_names
+; DEBUG_NAMES-NOT: pubnames
+; DEBUG_NAMES: debug_names
+; DEBUG_NAMES-NOT: apple_names
+; DEBUG_NAMES-NOT: pubnames
+
+@var = thread_local global i32 0, align 4, !dbg !0
+
+; Function Attrs: norecurse nounwind readnone uwtable
+define void @_Z3funv() local_unnamed_addr #0 !dbg !11 {
+  ret void, !dbg !14
+}
+
+; Function Attrs: norecurse uwtable
+define weak_odr hidden ptr @_ZTW3var() local_unnamed_addr #1 {
+  ret ptr @var
+}
+
+attributes #0 = { norecurse nounwind readnone uwtable }
+attributes #1 = { norecurse uwtable }
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!7, !8, !9}
+!llvm.ident = !{!10}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "var", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true)
+!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 7.0.0 (trunk 322268) (llvm/trunk 322267)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, nameTableKind: Apple)
+!3 = !DIFile(filename: "debugger-tune.cpp", directory: "/tmp")
+!4 = !{}
+!5 = !{!0}
+!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!7 = !{i32 2, !"Dwarf Version", i32 4}
+!8 = !{i32 2, !"Debug Info Version", i32 3}
+!9 = !{i32 1, !"wchar_size", i32 4}
+!10 = !{!"clang version 7.0.0 (trunk 322268) (llvm/trunk 322267)"}
+!11 = distinct !DISubprogram(name: "fun", linkageName: "_Z3funv", scope: !3, file: !3, line: 2, type: !12, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: true, unit: !2, retainedNodes: !4)
+!12 = !DISubroutineType(types: !13)
+!13 = !{null}
+!14 = !DILocation(line: 2, column: 13, scope: !11)
+
Index: llvm/test/DebugInfo/Inputs/name-table-kind-apple-5.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/Inputs/name-table-kind-apple-5.ll
@@ -0,0 +1,35 @@
+@var = thread_local global i32 0, align 4, !dbg !0
+
+; Function Attrs: norecurse nounwind readnone uwtable
+define void @_Z3funv() local_unnamed_addr #0 !dbg !11 {
+  ret void, !dbg !14
+}
+
+; Function Attrs: norecurse uwtable
+define weak_odr hidden ptr @_ZTW3var() local_unnamed_addr #1 {
+  ret ptr @var
+}
+
+attributes #0 = { norecurse nounwind readnone uwtable }
+attributes #1 = { norecurse uwtable }
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!7, !8, !9}
+!llvm.ident = !{!10}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "var", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true)
+!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 7.0.0 (trunk 322268) (llvm/trunk 322267)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, nameTableKind: Apple)
+!3 = !DIFile(filename: "debugger-tune.cpp", directory: "/tmp")
+!4 = !{}
+!5 = !{!0}
+!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!7 = !{i32 2, !"Dwarf Version", i32 5}
+!8 = !{i32 2, !"Debug Info Version", i32 3}
+!9 = !{i32 1, !"wchar_size", i32 4}
+!10 = !{!"clang version 7.0.0 (trunk 322268) (llvm/trunk 322267)"}
+!11 = distinct !DISubprogram(name: "fun", linkageName: 

[clang] e0d5729 - [DebugInfo] Always emit `.debug_names` with DWARF 5 for Apple platforms

2023-06-14 Thread Jonas Devlieghere via cfe-commits

Author: Jonas Devlieghere
Date: 2023-06-14T13:03:31-07:00
New Revision: e0d57295bf6a3c04f2901d9c70f529d570f48b65

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

LOG: [DebugInfo] Always emit `.debug_names` with DWARF 5 for Apple platforms

On Apple platforms, we generate .apple_names, .apple_types,
.apple_namespaces and .apple_objc Apple accelerator tables for DWARF 4
and earlier. For DWARF 5 we should generate .debug_names, but instead we
get no accelerator tables at all.

In the backend we are correctly determining that we should be emitting
.debug_names instead of .apple_names. However, when we get to the point
of emitting the section, if the CU debug name table kind is not
"default", the accelerator table emission is skipped.

This patch sets the DebugNameTableKind to Apple in the frontend when
target an Apple target. That way we know that the CU was compiled with
the intent of emitting accelerator tables. For DWARF 4 and earlier, that
means Apple accelerator tables. For DWARF 5 and later, that means .debug
names.

Differential revision: https://reviews.llvm.org/D118754

Added: 
llvm/test/DebugInfo/Inputs/name-table-kind-apple-4.ll
llvm/test/DebugInfo/Inputs/name-table-kind-apple-5.ll
llvm/test/DebugInfo/accel-tables-apple.ll

Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGen/debug-info-names.c
llvm/include/llvm/IR/DebugInfoMetadata.h
llvm/lib/AsmParser/LLLexer.cpp
llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
llvm/lib/IR/DebugInfoMetadata.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index edef27bdf377c..2fd2227720a2a 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -637,17 +637,21 @@ void CGDebugInfo::CreateCompileUnit() {
   SDK = *It;
   }
 
+  llvm::DICompileUnit::DebugNameTableKind NameTableKind =
+  static_cast(
+  CGOpts.DebugNameTable);
+  if (CGM.getTarget().getTriple().isNVPTX())
+NameTableKind = llvm::DICompileUnit::DebugNameTableKind::None;
+  else if (CGM.getTarget().getTriple().getVendor() == llvm::Triple::Apple)
+NameTableKind = llvm::DICompileUnit::DebugNameTableKind::Apple;
+
   // Create new compile unit.
   TheCU = DBuilder.createCompileUnit(
   LangTag, CUFile, CGOpts.EmitVersionIdentMetadata ? Producer : "",
   LO.Optimize || CGOpts.PrepareForLTO || CGOpts.PrepareForThinLTO,
   CGOpts.DwarfDebugFlags, RuntimeVers, CGOpts.SplitDwarfFile, EmissionKind,
   DwoId, CGOpts.SplitDwarfInlining, CGOpts.DebugInfoForProfiling,
-  CGM.getTarget().getTriple().isNVPTX()
-  ? llvm::DICompileUnit::DebugNameTableKind::None
-  : static_cast(
-CGOpts.DebugNameTable),
-  CGOpts.DebugRangesBaseAddress, remapDIPath(Sysroot), SDK);
+  NameTableKind, CGOpts.DebugRangesBaseAddress, remapDIPath(Sysroot), SDK);
 }
 
 llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {

diff  --git a/clang/test/CodeGen/debug-info-names.c 
b/clang/test/CodeGen/debug-info-names.c
index 841387d50fd44..a807fb8c06696 100644
--- a/clang/test/CodeGen/debug-info-names.c
+++ b/clang/test/CodeGen/debug-info-names.c
@@ -1,10 +1,12 @@
-// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s
-// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - -gpubnames | 
FileCheck --check-prefix=DEFAULT %s
-// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - -ggnu-pubnames 
| FileCheck --check-prefix=GNU %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -emit-llvm 
-debug-info-kind=limited %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.10.0 -emit-llvm 
-debug-info-kind=limited %s -o - | FileCheck --check-prefix=APPLE %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -emit-llvm 
-debug-info-kind=limited %s -o - -gpubnames | FileCheck --check-prefix=DEFAULT 
%s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -emit-llvm 
-debug-info-kind=limited %s -o - -ggnu-pubnames | FileCheck --check-prefix=GNU 
%s
 
 // CHECK: !DICompileUnit({{.*}}, nameTableKind: None
 // DEFAULT-NOT: !DICompileUnit({{.*}}, nameTableKind:
 // GNU: !DICompileUnit({{.*}}, nameTableKind: GNU
+// APPLE: !DICompileUnit({{.*}}, nameTableKind: Apple
 
 void f1(void) {
 }

diff  --git a/llvm/include/llvm/IR/DebugInfoMetadata.h 
b/llvm/include/llvm/IR/DebugInfoMetadata.h
index defd1d5c2a1ea..6561224052097 100644
--- a/llvm/include/llvm/IR/DebugInfoMetadata.h
+++ b/llvm/include/llvm/IR/DebugInfoMetadata.h
@@ -1377,7 +1377,8 @@ class DICompileUnit : public DIScope {
 Default = 0,
 GNU = 1,
 None = 2,
-LastDebugNameTableKind = None
+Apple = 3,
+LastDebugNameTableKind = Apple
   };
 
   

[PATCH] D152856: [Driver] Allow warning for unclaimed TargetSpecific options

2023-06-14 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: llvm/include/llvm/Option/Arg.h:53
+  /// This is used for generating an "argument unused" warning (without
+  /// clang::driver::options::TargetSpecific) or "unsupported option" error
+  /// (with TargetSpecific).

mstorsjo wrote:
> Technically, as this is a llvm level API, talking about clang specific 
> behaviours here is a bit at the wrong level.
Yes. LLVMOption was originally part of Clang and was moved to llvm/.

The "argument unused" string is also quite Clang-specific. There are other 
stuff talking about Clang behaviors, e.g.  suggestValueCompletions, `Alias` 
(`-finput-charset=utf-8`). I wish that this is not too bad.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152856/new/

https://reviews.llvm.org/D152856

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


[PATCH] D152472: [Clang][MS] Remove assertion on BaseOffset can't be smaller than Size.

2023-06-14 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm, thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152472/new/

https://reviews.llvm.org/D152472

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


[PATCH] D151587: [clang][ConstantEmitter] have tryEmitPrivate[ForVarInit] try ConstExprEmitter fast-path first

2023-06-14 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/lib/CodeGen/CGExprConstant.cpp:917
+  bool VisitArraySubscriptExpr(const ArraySubscriptExpr *A) {
+return Visit(A->getBase()) || Visit(A->getIdx());
+  }

Should only need to visit base, not idx.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151587/new/

https://reviews.llvm.org/D151587

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


[PATCH] D152946: [C++20][Modules] Implement P2615R1 revised export diagnostics.

2023-06-14 Thread Iain Sandoe via Phabricator via cfe-commits
iains created this revision.
Herald added a subscriber: ChuanqiXu.
Herald added a project: All.
iains added a reviewer: ChuanqiXu.
iains added a subscriber: clang-modules.
iains edited the summary of this revision.
iains published this revision for review.
iains added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

thanks to Daniela Engert for reporting this and helping identify the current 
WG21 status on the topic.


It has been reported that the current clang  errors for, specifically,
static_assert in export contexts are a serious blocker to adoption of
modules in some cases.

There is also implementation divergence with GCC and MSVC allowing the
constructs mentioned below where clang currently rejects them with an
error.

The category of errors [for declarations in an exported context] is:
(unnamed, static_assert, empty and asm decls). These are now permitted
after P2615R1 which was approved by WG21 as a DR (and thus should be
applied to C++20 as well).

This patch removes these diagnostics and amends the testsuite accordingly.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152946

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaModule.cpp
  clang/test/CXX/module/module.interface/p3.cpp
  clang/test/Modules/cxx20-10-2-ex1.cpp
  clang/test/Modules/cxx20-10-2-ex7.cpp
  clang/test/SemaCXX/modules.cppm

Index: clang/test/SemaCXX/modules.cppm
===
--- clang/test/SemaCXX/modules.cppm
+++ clang/test/SemaCXX/modules.cppm
@@ -34,11 +34,11 @@
 import foo; // expected-error {{imports must immediately follow the module declaration}}
 
 export {}
-export {  // expected-note {{begins here}}
-  ;   // expected-warning {{ISO C++20 does not permit an empty declaration to appear in an export block}}
+export {
+  ;   // No diagnostic after P2615R1 DR
 }
-export {   // expected-note {{begins here}}
-  static_assert(true); // expected-warning {{ISO C++20 does not permit a static_assert declaration to appear in an export block}}
+export {
+  static_assert(true); // No diagnostic after P2615R1 DR
 }
 
 int use_b = b; // expected-error{{use of undeclared identifier 'b'}}
Index: clang/test/Modules/cxx20-10-2-ex7.cpp
===
--- clang/test/Modules/cxx20-10-2-ex7.cpp
+++ clang/test/Modules/cxx20-10-2-ex7.cpp
@@ -2,8 +2,10 @@
 
 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %s -verify -o %t
 
+// expected-no-diagnostics
+
 export module M;
 export namespace N {
 int x; // OK
-static_assert(1 == 1); // expected-error {{static_assert declaration cannot be exported}}
+static_assert(1 == 1); // No diagnostic after P2615R1 DR
 } // namespace N
Index: clang/test/Modules/cxx20-10-2-ex1.cpp
===
--- clang/test/Modules/cxx20-10-2-ex1.cpp
+++ clang/test/Modules/cxx20-10-2-ex1.cpp
@@ -17,9 +17,9 @@
 // expected-error@std-10-2-ex1.h:* {{export declaration can only be used within a module purview}}
 
 export module M1;
-export namespace {} // expected-error {{declaration does not introduce any names to be exported}}
-export namespace {
-int a1; // expected-error {{declaration of 'a1' with internal linkage cannot be exported}}
+export namespace {} // expected-error {{anonymous namespaces cannot be exported}}
+export namespace { // expected-error {{anonymous namespaces cannot be exported}}
+int a1;
 }
 namespace {// expected-note {{anonymous namespace begins here}}
 export int a2; // expected-error {{export declaration appears within anonymous namespace}}
@@ -28,4 +28,4 @@
 export int f();  // OK
 
 export namespace N {} // namespace N
-export using namespace N; // expected-error {{ISO C++20 does not permit using directive to be exported}}
+export using namespace N; // No diagnostic after P2615R1 DR
Index: clang/test/CXX/module/module.interface/p3.cpp
===
--- clang/test/CXX/module/module.interface/p3.cpp
+++ clang/test/CXX/module/module.interface/p3.cpp
@@ -1,18 +1,19 @@
-// RUN: %clang_cc1 -std=c++2a %s -verify -pedantic-errors
+// RUN: %clang_cc1 -std=c++20 %s -verify -pedantic-errors
 
+// As amended by P2615R1 applied as a DR against C++20.
 export module p3;
 
 namespace A { int ns_mem; } // expected-note 2{{target}}
 
 // An exported declaration shall declare at least one name.
-export; // expected-error {{empty declaration cannot be exported}}
-export static_assert(true); // expected-error {{static_assert declaration cannot be exported}}
-export using namespace A;   // expected-error {{ISO C++20 does not permit using directive to be exported}}
+export; // No diagnostic after P2615R1 DR
+export static_assert(true); // No diagnostic after P2615R1 DR
+export using namespace A;   // No diagnostic after P2615R1 DR
 
-export { // expected-note 3{{export 

[PATCH] D137872: Implement lambdas with inalloca parameters by forwarding to function without inalloca calling convention.

2023-06-14 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/lib/CodeGen/CodeGenFunction.cpp:1472
+// the call operator body.
+EmitLambdaStaticInvokeBody(cast(FD));
   } else if (FD->isDefaulted() && isa(FD) &&

akhuang wrote:
> efriedma wrote:
> > Does this pass the correct value of "this"?  EmitLambdaStaticInvokeBody 
> > creates a new alloca to represent "this", but it's already an argument to 
> > the function.
> > 
> > Granted, it only matters in really obscure cases, but still.
> That's true, the "this" won't be passed correctly.
> 
> Actually, would it be fine to just emit the original call op body? (so that 
> the same function body is emitted twice -- once in the call op and once in 
> __impl). 
Not completely sure what you're asking... but as I've mentioned, we can't 
EmitFunctionBody() the body of a function more than once.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137872/new/

https://reviews.llvm.org/D137872

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


[clang-tools-extra] dc4359f - [clang-tidy] Fix wrong code generation for `modernize-loop-convert` with structured bindings.

2023-06-14 Thread Piotr Zegar via cfe-commits

Author: AMS21
Date: 2023-06-14T18:57:29Z
New Revision: dc4359fecf02f4230b4a5b900077c29d1b90f4ab

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

LOG: [clang-tidy] Fix wrong code generation for `modernize-loop-convert` with 
structured bindings.

Fixes llvm#62951

Reviewed By: PiotrZSL

Differential Revision: https://reviews.llvm.org/D152852

Added: 

clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-structured-binding.cpp

Modified: 
clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
index 87504e93ca240..618d1860ff8bd 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -533,32 +533,48 @@ void LoopConvertCheck::doConversion(
 const ValueDecl *MaybeContainer, const UsageResult ,
 const DeclStmt *AliasDecl, bool AliasUseRequired, bool AliasFromForInit,
 const ForStmt *Loop, RangeDescriptor Descriptor) {
-  std::string VarName;
+  std::string VarNameOrStructuredBinding;
   bool VarNameFromAlias = (Usages.size() == 1) && AliasDecl;
   bool AliasVarIsRef = false;
   bool CanCopy = true;
   std::vector FixIts;
   if (VarNameFromAlias) {
 const auto *AliasVar = cast(AliasDecl->getSingleDecl());
-VarName = AliasVar->getName().str();
-
-// Use the type of the alias if it's not the same
-QualType AliasVarType = AliasVar->getType();
-assert(!AliasVarType.isNull() && "Type in VarDecl is null");
-if (AliasVarType->isReferenceType()) {
-  AliasVarType = AliasVarType.getNonReferenceType();
-  AliasVarIsRef = true;
+
+// Handle structured bindings
+if (const auto *AliasDecompositionDecl =
+dyn_cast(AliasDecl->getSingleDecl())) {
+  VarNameOrStructuredBinding = "[";
+
+  assert(!AliasDecompositionDecl->bindings().empty() && "No bindings");
+  for (const BindingDecl *Binding : AliasDecompositionDecl->bindings()) {
+VarNameOrStructuredBinding += Binding->getName().str() + ", ";
+  }
+
+  VarNameOrStructuredBinding.erase(VarNameOrStructuredBinding.size() - 2,
+   2);
+  VarNameOrStructuredBinding += "]";
+} else {
+  VarNameOrStructuredBinding = AliasVar->getName().str();
+
+  // Use the type of the alias if it's not the same
+  QualType AliasVarType = AliasVar->getType();
+  assert(!AliasVarType.isNull() && "Type in VarDecl is null");
+  if (AliasVarType->isReferenceType()) {
+AliasVarType = AliasVarType.getNonReferenceType();
+AliasVarIsRef = true;
+  }
+  if (Descriptor.ElemType.isNull() ||
+  !Context->hasSameUnqualifiedType(AliasVarType, Descriptor.ElemType))
+Descriptor.ElemType = AliasVarType;
 }
-if (Descriptor.ElemType.isNull() ||
-!Context->hasSameUnqualifiedType(AliasVarType, Descriptor.ElemType))
-  Descriptor.ElemType = AliasVarType;
 
 // We keep along the entire DeclStmt to keep the correct range here.
 SourceRange ReplaceRange = AliasDecl->getSourceRange();
 
 std::string ReplacementText;
 if (AliasUseRequired) {
-  ReplacementText = VarName;
+  ReplacementText = VarNameOrStructuredBinding;
 } else if (AliasFromForInit) {
   // FIXME: Clang includes the location of the ';' but only for DeclStmt's
   // in a for loop's init clause. Need to put this ';' back while removing
@@ -577,7 +593,7 @@ void LoopConvertCheck::doConversion(
 VariableNamer Namer(>getGeneratedDecls(),
 >getParentFinder().getStmtToParentStmtMap(),
 Loop, IndexVar, MaybeContainer, Context, NamingStyle);
-VarName = Namer.createIndexName();
+VarNameOrStructuredBinding = Namer.createIndexName();
 // First, replace all usages of the array subscript expression with our new
 // variable.
 for (const auto  : Usages) {
@@ -586,8 +602,9 @@ void LoopConvertCheck::doConversion(
   if (Usage.Expression) {
 // If this is an access to a member through the arrow operator, after
 // the replacement it must be accessed through the '.' operator.
-ReplaceText = Usage.Kind == Usage::UK_MemberThroughArrow ? VarName + 
"."
- : VarName;
+ReplaceText = Usage.Kind == Usage::UK_MemberThroughArrow
+  ? VarNameOrStructuredBinding + "."
+  : VarNameOrStructuredBinding;
 auto Parents = Context->getParents(*Usage.Expression);
 if (Parents.size() == 1) {
 

[PATCH] D152852: [clang-tidy] Fix wrong code generation for `modernize-loop-convert` with structured bindings.

2023-06-14 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdc4359fecf02: [clang-tidy] Fix wrong code generation for 
`modernize-loop-convert` with… (authored by AMS21, committed by PiotrZSL).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152852/new/

https://reviews.llvm.org/D152852

Files:
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-structured-binding.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-structured-binding.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-structured-binding.cpp
@@ -0,0 +1,49 @@
+// RUN: %check_clang_tidy -std=c++17-or-later %s modernize-loop-convert %t
+
+struct S {
+  int a{0};
+  int b{1};
+};
+
+template 
+struct array {
+
+  T *begin() { return data; }
+  const T* cbegin() const { return data; }
+  T *end() { return data + Size; }
+  const T *cend() const { return data + Size; }
+
+  T data[Size];
+};
+
+const int N = 6;
+S Arr[N];
+
+void f() {
+  int Sum = 0;
+
+  for (int I = 0; I < N; ++I) {
+auto [a, b] = Arr[I];
+Sum += a + b;
+  }
+  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead [modernize-loop-convert]
+  // CHECK-FIXES: for (auto [a, b] : Arr) {
+  // CHECK-FIXES-NEXT: Sum += a + b;
+
+  array arr;
+  for (auto* It = arr.begin(); It != arr.end(); ++It) {
+auto [a, b] = *It;
+Sum = a + b;
+  }
+  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead [modernize-loop-convert]
+  // CHECK-FIXES: for (auto [a, b] : arr) {
+  // CHECK-FIXES-NEXT: Sum = a + b;
+
+  for (auto* It = arr.cbegin(); It != arr.cend(); ++It) {
+auto [a, b] = *It;
+Sum = a + b;
+  }
+  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead [modernize-loop-convert]
+  // CHECK-FIXES: for (auto [a, b] : arr) {
+  // CHECK-FIXES-NEXT: Sum = a + b;
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -345,6 +345,10 @@
   using macro between namespace declarations, to fix false positive when using namespace
   with attributes and to support nested inline namespace introduced in c++20.
 
+- Fixed an issue in `modernize-loop-convert
+  ` generating wrong code
+  when using structured bindings.
+
 - In :doc:`modernize-use-default-member-init
   ` count template
   constructors toward hand written constructors so that they are skipped if more
Index: clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -533,32 +533,48 @@
 const ValueDecl *MaybeContainer, const UsageResult ,
 const DeclStmt *AliasDecl, bool AliasUseRequired, bool AliasFromForInit,
 const ForStmt *Loop, RangeDescriptor Descriptor) {
-  std::string VarName;
+  std::string VarNameOrStructuredBinding;
   bool VarNameFromAlias = (Usages.size() == 1) && AliasDecl;
   bool AliasVarIsRef = false;
   bool CanCopy = true;
   std::vector FixIts;
   if (VarNameFromAlias) {
 const auto *AliasVar = cast(AliasDecl->getSingleDecl());
-VarName = AliasVar->getName().str();
-
-// Use the type of the alias if it's not the same
-QualType AliasVarType = AliasVar->getType();
-assert(!AliasVarType.isNull() && "Type in VarDecl is null");
-if (AliasVarType->isReferenceType()) {
-  AliasVarType = AliasVarType.getNonReferenceType();
-  AliasVarIsRef = true;
+
+// Handle structured bindings
+if (const auto *AliasDecompositionDecl =
+dyn_cast(AliasDecl->getSingleDecl())) {
+  VarNameOrStructuredBinding = "[";
+
+  assert(!AliasDecompositionDecl->bindings().empty() && "No bindings");
+  for (const BindingDecl *Binding : AliasDecompositionDecl->bindings()) {
+VarNameOrStructuredBinding += Binding->getName().str() + ", ";
+  }
+
+  VarNameOrStructuredBinding.erase(VarNameOrStructuredBinding.size() - 2,
+   2);
+  VarNameOrStructuredBinding += "]";
+} else {
+  VarNameOrStructuredBinding = AliasVar->getName().str();
+
+  // Use the type of the alias if it's not the same
+  QualType AliasVarType = AliasVar->getType();
+  assert(!AliasVarType.isNull() && "Type in VarDecl is null");
+  if (AliasVarType->isReferenceType()) {
+AliasVarType = AliasVarType.getNonReferenceType();
+AliasVarIsRef = true;
+  }
+  if (Descriptor.ElemType.isNull() ||
+  !Context->hasSameUnqualifiedType(AliasVarType, 

[PATCH] D142994: [UsersManual] Add llvm-progen as an alternative tool for AutoFDO profile generation.

2023-06-14 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added a comment.



In D142994#4094193 , @wenlei wrote:

> Given llvm-profgen is in llvm tree, I'm wondering if it makes sense to treat 
> it first option instead of alternative to out of tree create_llvm_prof. wdyt 
> @davidxl

@davidxl any thought on this? Thanks.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142994/new/

https://reviews.llvm.org/D142994

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


[PATCH] D152226: [FunctionAttrs] Propagate some func/arg/ret attributes from caller to callsite (WIP)

2023-06-14 Thread Noah Goldstein via Phabricator via cfe-commits
goldstein.w.n added inline comments.



Comment at: llvm/lib/Transforms/Utils/InferCallsiteAttrs.cpp:597
+  // callsite violating the constraint.
+  if (checkCallerDoesNotAccessMemory() && !CB->doesNotAccessMemory()) {
+// Wait until we know we actually need it to do potentially expensive

goldstein.w.n wrote:
> nikic wrote:
> > For these you generally want to query `getMemoryEffects()` on the 
> > caller/callee once and then work on that representation, instead of doing 
> > separate queries for everything. This may allow more precise handling and 
> > likely reduces the compile-time impact, as doing these attribute lookups is 
> > quite expensive.
> Re-running compile time checks, will post revised numbers tomorrow.
No real impact on compile time.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152226/new/

https://reviews.llvm.org/D152226

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


[PATCH] D152396: [clang][doc] Rescue some deleted bits of the command-line reference.

2023-06-14 Thread Eli Friedman via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf51924d124bd: [clang docs] Rescue some deleted bits of the 
command-line reference. (authored by efriedma).

Changed prior to commit:
  https://reviews.llvm.org/D152396?vs=529422=531448#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152396/new/

https://reviews.llvm.org/D152396

Files:
  clang/include/clang/Driver/Options.td

Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1436,7 +1436,8 @@
 HelpText<"Generate instrumented code to collect order file into default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env var)">;
 def fprofile_list_EQ : Joined<["-"], "fprofile-list=">,
 Group, Flags<[CC1Option, CoreOption]>,
-HelpText<"Filename defining the list of functions/files to instrument">,
+HelpText<"Filename defining the list of functions/files to instrument. "
+ "The file uses the sanitizer special case list format.">,
 MarshallingInfoStringVector>;
 def fprofile_function_groups : Joined<["-"], "fprofile-function-groups=">,
   Group, Flags<[CC1Option]>, MetaVarName<"">,
@@ -1492,6 +1493,13 @@
 def fparse_all_comments : Flag<["-"], "fparse-all-comments">, Group, Flags<[CC1Option]>,
   MarshallingInfoFlag>;
 def frecord_command_line : Flag<["-"], "frecord-command-line">,
+  DocBrief<[{Generate a section named ".GCC.command.line" containing the clang
+driver command-line. After linking, the section may contain multiple command
+lines, which will be individually terminated by null bytes. Separate arguments
+within a command line are combined with spaces; spaces and backslashes within an
+argument are escaped with backslashes. This format differs from the format of
+the equivalent section produced by GCC with the -frecord-gcc-switches flag.
+This option is currently only supported on ELF targets.}]>,
   Group;
 def fno_record_command_line : Flag<["-"], "fno-record-command-line">,
   Group;
@@ -1499,7 +1507,10 @@
 def : Flag<["-"], "fno-record-gcc-switches">, Alias;
 def fcommon : Flag<["-"], "fcommon">, Group,
   Flags<[CoreOption, CC1Option]>, HelpText<"Place uninitialized global variables in a common block">,
-  MarshallingInfoNegativeFlag>;
+  MarshallingInfoNegativeFlag>,
+  DocBrief<[{Place definitions of variables with no storage class and no initializer
+(tentative definitions) in a common block, instead of generating individual
+zero-initialized definitions (default -fno-common).}]>;
 def fcompile_resource_EQ : Joined<["-"], "fcompile-resource=">, Group;
 defm complete_member_pointers : BoolOption<"f", "complete-member-pointers",
   LangOpts<"CompleteMemberPointers">, DefaultFalse,
@@ -1738,7 +1749,7 @@
 defm keep_static_consts : BoolFOption<"keep-static-consts",
   CodeGenOpts<"KeepStaticConsts">, DefaultFalse,
   PosFlag, NegFlag,
-  BothFlags<[NoXarchOption], " static const variables if unused">>;
+  BothFlags<[NoXarchOption], " static const variables even if unused">>;
 defm fixed_point : BoolFOption<"fixed-point",
   LangOpts<"FixedPoint">, DefaultFalse,
   PosFlag, NegFlag,
@@ -1869,6 +1880,17 @@
   CodeGenOpts<"SanitizeAddressPoisonCustomArrayCookie">, DefaultFalse,
   PosFlag, NegFlag,
   BothFlags<[], " poisoning array cookies when using custom operator new[] in AddressSanitizer">>,
+  DocBrief<[{Enable "poisoning" array cookies when allocating arrays with a
+custom operator new\[\] in Address Sanitizer, preventing accesses to the
+cookies from user code. An array cookie is a small implementation-defined
+header added to certain array allocations to record metadata such as the
+length of the array. Accesses to array cookies from user code are technically
+allowed by the standard but are more likely to be the result of an
+out-of-bounds array access.
+
+An operator new\[\] is "custom" if it is not one of the allocation functions
+provided by the C++ standard library. Array cookies from non-custom allocation
+functions are always poisoned.}]>,
   Group;
 defm sanitize_address_globals_dead_stripping : BoolOption<"f", "sanitize-address-globals-dead-stripping",
   CodeGenOpts<"SanitizeAddressGlobalsDeadStripping">, DefaultFalse,
@@ -1884,7 +1906,10 @@
 def sanitize_address_destructor_EQ
 : Joined<["-"], "fsanitize-address-destructor=">,
   Flags<[CC1Option]>,
-  HelpText<"Set destructor type used in ASan instrumentation">,
+  HelpText<"Set the kind of module destructors emitted by "
+   "AddressSanitizer instrumentation. These destructors are "
+   "emitted to unregister instrumented global variables when "
+   "code is unloaded (e.g. via `dlclose()`).">,
   Group,
   Values<"none,global">,
   NormalizedValuesScope<"llvm::AsanDtorKind">,
@@ -2020,16 +2045,24 @@
NegFlag>;
 defm 

[clang] f51924d - [clang docs] Rescue some deleted bits of the command-line reference.

2023-06-14 Thread Eli Friedman via cfe-commits

Author: Eli Friedman
Date: 2023-06-14T11:44:02-07:00
New Revision: f51924d124bdd0e089cd28756578cec13ede1a8c

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

LOG: [clang docs] Rescue some deleted bits of the command-line reference.

Back when the command-line reference rst was in-tree, a lot of people missed
the "DO NOT EDIT" comment at the top, and then changes were
effectively reverted when the file was regenerated. I went through the
changes, and rescued the interesting bits of documentation that were
destroyed.

Additional notes:

- I'm intentionally leaving out D73459 because I'm not sure how to port
  the changes to -march.
- Some options have help text in Options.td, but that text doesn't make
  it into the reference. Incomplete list of such options:
  -fc++-static-destructors, -frtti-data, -fplt, -fstrict-return,
  -funique-section-names, -fuse-init-array.  Not sure what's happening.

Differential Revision: https://reviews.llvm.org/D152396

Added: 


Modified: 
clang/include/clang/Driver/Options.td

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index cc6ee3c5d5c18..750b6ab343852 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1436,7 +1436,8 @@ def forder_file_instrumentation : Flag<["-"], 
"forder-file-instrumentation">,
 HelpText<"Generate instrumented code to collect order file into 
default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env 
var)">;
 def fprofile_list_EQ : Joined<["-"], "fprofile-list=">,
 Group, Flags<[CC1Option, CoreOption]>,
-HelpText<"Filename defining the list of functions/files to instrument">,
+HelpText<"Filename defining the list of functions/files to instrument. "
+ "The file uses the sanitizer special case list format.">,
 MarshallingInfoStringVector>;
 def fprofile_function_groups : Joined<["-"], "fprofile-function-groups=">,
   Group, Flags<[CC1Option]>, MetaVarName<"">,
@@ -1492,6 +1493,13 @@ def fcomment_block_commands : CommaJoined<["-"], 
"fcomment-block-commands=">, Gr
 def fparse_all_comments : Flag<["-"], "fparse-all-comments">, 
Group, Flags<[CC1Option]>,
   MarshallingInfoFlag>;
 def frecord_command_line : Flag<["-"], "frecord-command-line">,
+  DocBrief<[{Generate a section named ".GCC.command.line" containing the clang
+driver command-line. After linking, the section may contain multiple command
+lines, which will be individually terminated by null bytes. Separate arguments
+within a command line are combined with spaces; spaces and backslashes within 
an
+argument are escaped with backslashes. This format 
diff ers from the format of
+the equivalent section produced by GCC with the -frecord-gcc-switches flag.
+This option is currently only supported on ELF targets.}]>,
   Group;
 def fno_record_command_line : Flag<["-"], "fno-record-command-line">,
   Group;
@@ -1499,7 +1507,10 @@ def : Flag<["-"], "frecord-gcc-switches">, 
Alias;
 def : Flag<["-"], "fno-record-gcc-switches">, Alias;
 def fcommon : Flag<["-"], "fcommon">, Group,
   Flags<[CoreOption, CC1Option]>, HelpText<"Place uninitialized global 
variables in a common block">,
-  MarshallingInfoNegativeFlag>;
+  MarshallingInfoNegativeFlag>,
+  DocBrief<[{Place definitions of variables with no storage class and no 
initializer
+(tentative definitions) in a common block, instead of generating individual
+zero-initialized definitions (default -fno-common).}]>;
 def fcompile_resource_EQ : Joined<["-"], "fcompile-resource=">, Group;
 defm complete_member_pointers : BoolOption<"f", "complete-member-pointers",
   LangOpts<"CompleteMemberPointers">, DefaultFalse,
@@ -1738,7 +1749,7 @@ defm force_enable_int128 : 
BoolFOption<"force-enable-int128",
 defm keep_static_consts : BoolFOption<"keep-static-consts",
   CodeGenOpts<"KeepStaticConsts">, DefaultFalse,
   PosFlag, NegFlag,
-  BothFlags<[NoXarchOption], " static const variables if unused">>;
+  BothFlags<[NoXarchOption], " static const variables even if unused">>;
 defm fixed_point : BoolFOption<"fixed-point",
   LangOpts<"FixedPoint">, DefaultFalse,
   PosFlag, NegFlag,
@@ -1869,6 +1880,17 @@ defm sanitize_address_poison_custom_array_cookie : 
BoolOption<"f", "sanitize-add
   CodeGenOpts<"SanitizeAddressPoisonCustomArrayCookie">, DefaultFalse,
   PosFlag, NegFlag,
   BothFlags<[], " poisoning array cookies when using custom operator new[] in 
AddressSanitizer">>,
+  DocBrief<[{Enable "poisoning" array cookies when allocating arrays with a
+custom operator new\[\] in Address Sanitizer, preventing accesses to the
+cookies from user code. An array cookie is a small implementation-defined
+header added to certain array allocations to record metadata such as the

[PATCH] D148697: [clang-tidy] Add more checks for functions which should be noexcept

2023-06-14 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.

In D148697#4421739 , @Dinistro wrote:

> In D148697#4421643 , @PiotrZSL 
> wrote:
>
>> @Dinistro It compiles & links with clang 16 also (shared libs). So I'm 
>> unable to reproduce.
>
> I used the following command to build:
>
>   cmake -S/home/christianu/repos/llvm-project/llvm 
> -B/home/christianu/repos/llvm-project/build-clang-tidy -GNinja 
> -DLLVM_ENABLE_LLD=ON -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" 
> -DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_ENABLE_ASSERTIONS=ON 
> -DBUILD_SHARED_LIBS=ON -DLLVM_INCLUDE_UTILS=ON -DLLVM_INSTALL_UTILS=ON 
> -DLLVM_BUILD_EXAMPLES=OFF -DLLVM_CCACHE_BUILD=ON -DLLVM_OPTIMIZED_TABLEGEN=ON 
> -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=clang 
> -DCMAKE_CXX_COMPILER=clang++ -DLLVM_ENABLE_RUNTIMES=openmp

Still no issue on my side. Try cleaning up ccache and directory. Also by 
looking into code, everything looks fine, dependencies are correctly set.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148697/new/

https://reviews.llvm.org/D148697

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


[PATCH] D152788: [Clang] Show type in enum out of range diagnostic

2023-06-14 Thread Dimitry Andric via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG69d42eef4bec: [Clang] Show type in enum out of range 
diagnostic (authored by dim).

Changed prior to commit:
  https://reviews.llvm.org/D152788?vs=531013=531441#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152788/new/

https://reviews.llvm.org/D152788

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticASTKinds.td
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/constant-expression-cxx11.cpp
  clang/test/SemaCXX/cxx2a-consteval.cpp

Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -900,7 +900,7 @@
 namespace GH50055 {
 enum E {e1=0, e2=1};
 consteval int testDefaultArgForParam(E eParam = (E)-1) {
-// expected-error@-1 {{integer value -1 is outside the valid range of values [0, 1] for this enumeration type}}
+// expected-error@-1 {{integer value -1 is outside the valid range of values [0, 1] for the enumeration type 'E'}}
   return (int)eParam;
 }
 
Index: clang/test/SemaCXX/constant-expression-cxx11.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -2440,42 +2440,51 @@
 void testValueInRangeOfEnumerationValues() {
   constexpr E1 x1 = static_cast(-8);
   constexpr E1 x2 = static_cast(8);
-  // expected-error@-1 {{integer value 8 is outside the valid range of values [-8, 7] for this enumeration type}}
+  // expected-error@-1 {{integer value 8 is outside the valid range of values [-8, 7] for the enumeration type 'E1'}}
   E1 x2b = static_cast(8); // ok, not a constant expression context
 
   constexpr E2 x3 = static_cast(-8);
-  // expected-error@-1 {{integer value -8 is outside the valid range of values [0, 7] for this enumeration type}}
+  // expected-error@-1 {{integer value -8 is outside the valid range of values [0, 7] for the enumeration type 'E2'}}
   constexpr E2 x4 = static_cast(0);
   constexpr E2 x5 = static_cast(8);
-  // expected-error@-1 {{integer value 8 is outside the valid range of values [0, 7] for this enumeration type}}
+  // expected-error@-1 {{integer value 8 is outside the valid range of values [0, 7] for the enumeration type 'E2'}}
 
   constexpr E3 x6 = static_cast(-2048);
   constexpr E3 x7 = static_cast(-8);
   constexpr E3 x8 = static_cast(0);
   constexpr E3 x9 = static_cast(8);
   constexpr E3 x10 = static_cast(2048);
-  // expected-error@-1 {{integer value 2048 is outside the valid range of values [-2048, 2047] for this enumeration type}}
+  // expected-error@-1 {{integer value 2048 is outside the valid range of values [-2048, 2047] for the enumeration type 'E3'}}
 
   constexpr E4 x11 = static_cast(0);
   constexpr E4 x12 = static_cast(1);
   constexpr E4 x13 = static_cast(2);
-  // expected-error@-1 {{integer value 2 is outside the valid range of values [0, 1] for this enumeration type}}
+  // expected-error@-1 {{integer value 2 is outside the valid range of values [0, 1] for the enumeration type 'E4'}}
 
   constexpr EEmpty x14 = static_cast(0);
   constexpr EEmpty x15 = static_cast(1);
   constexpr EEmpty x16 = static_cast(2);
-  // expected-error@-1 {{integer value 2 is outside the valid range of values [0, 1] for this enumeration type}}
+  // expected-error@-1 {{integer value 2 is outside the valid range of values [0, 1] for the enumeration type 'EEmpty'}}
 
   constexpr EFixed x17 = static_cast(100);
   constexpr EScoped x18 = static_cast(100);
 
   constexpr EMaxInt x19 = static_cast(__INT_MAX__-1);
   constexpr EMaxInt x20 = static_cast((long)__INT_MAX__+1);
-  // expected-error@-1 {{integer value 2147483648 is outside the valid range of values [-2147483648, 2147483647] for this enumeration type}}
+  // expected-error@-1 {{integer value 2147483648 is outside the valid range of values [-2147483648, 2147483647] for the enumeration type 'EMaxInt'}}
 
   const NumberType neg_one = (NumberType) ((NumberType) 0 - (NumberType) 1); // ok, not a constant expression context
 }
 
+template struct Bitfield {
+  static constexpr T max = static_cast((1 << size) - 1); // #enum
+};
+
+void testValueInRangeOfEnumerationValuesViaTemplate() {
+  Bitfield good;
+  Bitfield bad; // cxx11-error@#enum {{integer value 15 is outside the valid range of values [0, 7] for the enumeration type 'E2'}}
+}
+
 enum SortOrder {
   AscendingOrder,
   DescendingOrder
@@ -2494,4 +2503,4 @@
 GH50055::E2 GlobalInitNotCE1 = (GH50055::E2)-1; // ok, not a constant expression context
 GH50055::E2 GlobalInitNotCE2 = GH50055::testDefaultArgForParam(); // ok, not a constant expression context
 constexpr GH50055::E2 GlobalInitCE = (GH50055::E2)-1;
-// expected-error@-1 {{integer value -1 is outside the 

[clang] 69d42ee - [Clang] Show type in enum out of range diagnostic

2023-06-14 Thread Dimitry Andric via cfe-commits

Author: Dimitry Andric
Date: 2023-06-14T20:34:19+02:00
New Revision: 69d42eef4bec208a2312bfa0d2194013817eeba0

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

LOG: [Clang] Show type in enum out of range diagnostic

When the diagnostic for an out of range enum value is printed, it
currently does not show the actual enum type in question, for example:

v8/src/base/bit-field.h:43:29: error: integer value 7 is outside the valid 
range of values [0, 3] for this enumeration type [-Wenum-constexpr-conversion]
  static constexpr T kMax = static_cast(kNumValues - 1);
^

This can make it cumbersome to find the cause for the problem. Add the
enum type to the diagnostic message, to make it easier.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D152788

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticASTKinds.td
clang/lib/AST/ExprConstant.cpp
clang/test/SemaCXX/constant-expression-cxx11.cpp
clang/test/SemaCXX/cxx2a-consteval.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 32cc7c94a3252..3cfacb07bbaa1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -344,6 +344,9 @@ Improvements to Clang's diagnostics
   (`#42992: `_)
 - Clang now diagnoses unused const-qualified variable template as
   "unused variable template" rather than "unused variable".
+- When diagnosing a constant expression where an enum without a fixed 
underlying
+  type is set to a value outside the range of the enum's values, clang will now
+  print the name of the enum in question.
 
 Bug Fixes in This Version
 -

diff  --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index eb13467317963..73118891c1899 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -395,8 +395,8 @@ def warn_fixedpoint_constant_overflow : Warning<
   "overflow in expression; result is %0 with type %1">,
   InGroup>;
 def warn_constexpr_unscoped_enum_out_of_range : Warning<
-  "integer value %0 is outside the valid range of values [%1, %2] for this "
-  "enumeration type">, DefaultError, 
InGroup>;
+  "integer value %0 is outside the valid range of values [%1, %2] for the "
+  "enumeration type %3">, DefaultError, 
InGroup>;
 
 // This is a temporary diagnostic, and shall be removed once our
 // implementation is complete, and like the preceding constexpr notes belongs

diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index b88b84a44af0e..5578dfc8f8743 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -13708,12 +13708,13 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr 
*E) {
   Info.Ctx.getDiagnostics().Report(
   E->getExprLoc(), diag::warn_constexpr_unscoped_enum_out_of_range)
   << llvm::toString(Result.getInt(), 10) << Min.getSExtValue()
-  << Max.getSExtValue();
+  << Max.getSExtValue() << ED;
 else if (!ED->getNumNegativeBits() && ConstexprVar &&
  Max.ult(Result.getInt().getZExtValue()))
-  Info.Ctx.getDiagnostics().Report(E->getExprLoc(),
-   
diag::warn_constexpr_unscoped_enum_out_of_range)
-   << llvm::toString(Result.getInt(),10) << Min.getZExtValue() << 
Max.getZExtValue();
+  Info.Ctx.getDiagnostics().Report(
+  E->getExprLoc(), diag::warn_constexpr_unscoped_enum_out_of_range)
+  << llvm::toString(Result.getInt(), 10) << Min.getZExtValue()
+  << Max.getZExtValue() << ED;
   }
 }
 

diff  --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp 
b/clang/test/SemaCXX/constant-expression-cxx11.cpp
index fa9ad786b289e..f454bba5afd8c 100644
--- a/clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -2440,42 +2440,51 @@ E2 testDefaultArgForParam(E2 e2Param = (E2)-1) { // ok, 
not a constant expressio
 void testValueInRangeOfEnumerationValues() {
   constexpr E1 x1 = static_cast(-8);
   constexpr E1 x2 = static_cast(8);
-  // expected-error@-1 {{integer value 8 is outside the valid range of values 
[-8, 7] for this enumeration type}}
+  // expected-error@-1 {{integer value 8 is outside the valid range of values 
[-8, 7] for the enumeration type 'E1'}}
   E1 x2b = static_cast(8); // ok, not a constant expression context
 
   constexpr E2 x3 = static_cast(-8);
-  // expected-error@-1 {{integer value -8 is outside the valid range of values 
[0, 7] for this 

[PATCH] D147218: [OpenMP][Flang][MLIR] Lowering of OpenMP requires directive from parse tree to MLIR

2023-06-14 Thread Sergio Afonso via Phabricator via cfe-commits
skatrak requested review of this revision.
skatrak added a comment.

Changing status to "Request Review" again due to some significant changes to 
the approach.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147218/new/

https://reviews.llvm.org/D147218

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


[PATCH] D152720: [clangd][ObjC] Support ObjC class rename from implementation decls

2023-06-14 Thread David Goldman via Phabricator via cfe-commits
dgoldman updated this revision to Diff 531439.
dgoldman added a comment.

- Implement discussed fixes + category support


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152720/new/

https://reviews.llvm.org/D152720

Files:
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/unittests/RenameTests.cpp

Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -840,6 +840,30 @@
   foo('x');
 }
   )cpp",
+
+  // ObjC class with a category.
+  R"cpp(
+@interface [[Fo^o]]
+@end
+@implementation [[F^oo]]
+@end
+@interface [[Fo^o]] (Category)
+@end
+@implementation [[F^oo]] (Category)
+@end
+
+void func([[Fo^o]] *f) {}
+  )cpp",
+
+  // ObjC category.
+  R"cpp(
+@interface Foo
+@end
+@interface Foo ([[Cate^gory]])
+@end
+@implementation Foo ([[Cate^gory]])
+@end
+  )cpp",
   };
   llvm::StringRef NewName = "NewName";
   for (llvm::StringRef T : Tests) {
@@ -1468,7 +1492,7 @@
 
 TEST(CrossFileRenameTests, WithUpToDateIndex) {
   MockCompilationDatabase CDB;
-  CDB.ExtraClangFlags = {"-xc++"};
+  CDB.ExtraClangFlags = {"-xobjective-c++"};
   // rename is runnning on all "^" points in FooH, and "[[]]" ranges are the
   // expected rename occurrences.
   struct Case {
@@ -1557,13 +1581,12 @@
 }
   )cpp",
   },
-  {
-  // virtual templated method
-  R"cpp(
+  {// virtual templated method
+   R"cpp(
 template  class Foo { virtual void [[m]](); };
 class Bar : Foo { void [[^m]]() override; };
   )cpp",
-  R"cpp(
+   R"cpp(
   #include "foo.h"
 
   template void Foo::[[m]]() {}
@@ -1571,8 +1594,7 @@
   // the canonical Foo::m().
   // https://github.com/clangd/clangd/issues/1325
   class Baz : Foo { void m() override; };
-)cpp"
-  },
+)cpp"},
   {
   // rename on constructor and destructor.
   R"cpp(
@@ -1677,6 +1699,20 @@
 }
   )cpp",
   },
+  {
+  // Objective-C classes.
+  R"cpp(
+@interface [[Fo^o]]
+@end
+  )cpp",
+  R"cpp(
+#include "foo.h"
+@implementation [[F^oo]]
+@end
+
+void func([[Foo]] *f) {}
+  )cpp",
+  },
   };
 
   trace::TestTracer Tracer;
Index: clang-tools-extra/clangd/refactor/Rename.cpp
===
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -19,6 +19,7 @@
 #include "clang/AST/ASTTypeTraits.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclObjC.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/ParentMapContext.h"
 #include "clang/AST/Stmt.h"
@@ -137,6 +138,14 @@
 if (const auto *TargetDecl = UD->getTargetDecl())
   return canonicalRenameDecl(TargetDecl);
   }
+  if (const auto *ID = dyn_cast(D)) {
+if (const auto CI = ID->getClassInterface())
+  return canonicalRenameDecl(CI);
+  }
+  if (const auto *CID = dyn_cast(D)) {
+if (const auto CD = CID->getCategoryDecl())
+  return canonicalRenameDecl(CD);
+  }
   return dyn_cast(D->getCanonicalDecl());
 }
 
@@ -156,6 +165,16 @@
targetDecl(SelectedNode->ASTNode,
   DeclRelation::Alias | DeclRelation::TemplatePattern,
   AST.getHeuristicResolver())) {
+// If we select the interface name in `@interface Class (CategoryName)` or
+// the implementation, the decl to rename is actually the interface, not
+// the category.
+if (const auto *C = dyn_cast(D)) {
+  if (C->getLocation() == TokenStartLoc)
+D = C->getClassInterface();
+  else if (const auto *I = C->getImplementation())
+if (I->getLocation() == TokenStartLoc)
+  D = C->getClassInterface();
+}
 Result.insert(canonicalRenameDecl(D));
   }
   return Result;
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -128,7 +128,7 @@
 return HighlightingKind::Class;
   if (isa(D))
 return HighlightingKind::Interface;
-  if (isa(D))
+  if (isa(D))
 return HighlightingKind::Namespace;
   if (auto *MD = dyn_cast(D))
 return MD->isStatic() ? HighlightingKind::StaticMethod
Index: clang-tools-extra/clangd/FindTarget.cpp
===
--- 

[PATCH] D93829: [clangd] Support outgoing calls in call hierarchy

2023-06-14 Thread Quentin Chateau via Phabricator via cfe-commits
qchateau added a comment.

I'm interested but I don't have enough free time these days. So if anyone wants 
to take it from there, feel free to reuse my commits (or not).
If I find myself with some free time and nobody else is working on this, I'll 
give it a shot


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93829/new/

https://reviews.llvm.org/D93829

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


[PATCH] D152472: [Clang][MS] Remove assertion on BaseOffset can't be smaller than Size.

2023-06-14 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 531438.
zequanwu marked 5 inline comments as done.
zequanwu added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152472/new/

https://reviews.llvm.org/D152472

Files:
  clang/include/clang/Frontend/LayoutOverrideSource.h
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/lib/Frontend/LayoutOverrideSource.cpp
  clang/test/CodeGenCXX/Inputs/override-layout-ms.layout
  clang/test/CodeGenCXX/override-layout-ms.cpp

Index: clang/test/CodeGenCXX/override-layout-ms.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/override-layout-ms.cpp
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -w -triple=x86_64-pc-win32 -fms-compatibility -fdump-record-layouts -foverride-record-layout=%S/Inputs/override-layout-ms.layout %s | FileCheck  %s
+// RUN: %clang_cc1 -w -triple=x86_64-pc-win32 -fms-compatibility -fdump-record-layouts %s | FileCheck  %s
+
+// CHECK: *** Dumping AST Record Layout
+// CHECK:  0 | struct E1 (empty)
+// CHECK:| [sizeof=1, align=1,
+// CHECK:|  nvsize=0, nvalign=1]
+// CHECK: *** Dumping AST Record Layout
+// CHECK:  0 | struct Mid
+// CHECK:  0 |   void * p
+// CHECK:| [sizeof=8, align=8,
+// CHECK:|  nvsize=8, nvalign=8]
+// CHECK: *** Dumping AST Record Layout
+// CHECK:  0 | struct E2 (empty)
+// CHECK:| [sizeof=1, align=1,
+// CHECK:|  nvsize=0, nvalign=1]
+// CHECK: *** Dumping AST Record Layout
+// CHECK:  0 | struct Combine
+// CHECK:  0 |   struct E1 (base) (empty)
+// CHECK:  0 |   struct Mid (base)
+// CHECK:  0 | void * p
+// CHECK:  0 |   struct E2 (base) (empty)
+// CHECK:| [sizeof=8, align=8,
+// CHECK:|  nvsize=8, nvalign=8]
+// CHECK: *** Dumping AST Record Layout
+// CHECK:  0 | struct Combine2
+// CHECK:  0 |   struct VB1 (primary base)
+// CHECK:  0 | (VB1 vftable pointer)
+// CHECK:  8 |   struct VB2 (base)
+// CHECK:  8 | (VB2 vftable pointer)
+// CHECK:| [sizeof=16, align=8,
+// CHECK:|  nvsize=16, nvalign=8]
+
+
+struct E1 {};
+struct E2 {};
+struct Mid {void *p; };
+struct __declspec(empty_bases) Combine : E1, Mid, E2 {};
+struct VB1 { virtual void foo() {}};
+struct VB2 { virtual void bar() {}};
+struct Combine2: VB1, VB2 {};
+Combine g;
+Combine2 f;
\ No newline at end of file
Index: clang/test/CodeGenCXX/Inputs/override-layout-ms.layout
===
--- /dev/null
+++ clang/test/CodeGenCXX/Inputs/override-layout-ms.layout
@@ -0,0 +1,49 @@
+*** Dumping AST Record Layout
+Type: struct E1
+
+Layout: 
+  VBaseOffsets: []>
+  FieldOffsets: []>
+
+*** Dumping AST Record Layout
+Type: struct Mid
+
+Layout: 
+  VBaseOffsets: []>
+  FieldOffsets: [0]>
+
+*** Dumping AST Record Layout
+Type: struct E2
+
+Layout: 
+  VBaseOffsets: []>
+  FieldOffsets: []>
+
+*** Dumping AST Record Layout
+Type: struct Combine
+
+Layout: 
+  VBaseOffsets: []>
+  FieldOffsets: []>
+
+*** Dumping AST Record Layout
+Type: struct Combine2
+
+Layout: 
+  VBaseOffsets: []>
+  FieldOffsets: []>
Index: clang/lib/Frontend/LayoutOverrideSource.cpp
===
--- clang/lib/Frontend/LayoutOverrideSource.cpp
+++ clang/lib/Frontend/LayoutOverrideSource.cpp
@@ -7,6 +7,7 @@
 //===--===//
 #include "clang/Frontend/LayoutOverrideSource.h"
 #include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/Basic/CharInfo.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
@@ -26,6 +27,18 @@
   return S.substr(0, Offset).str();
 }
 
+/// Parse an unsigned integer and move S to the next non-digit character.
+static bool parseUnsigned(StringRef , unsigned long long ) {
+  if (S.empty() || !isDigit(S[0]))
+return false;
+  unsigned Idx = 1;
+  while (Idx < S.size() && isDigit(S[Idx]))
+++Idx;
+  (void)S.substr(0, Idx).getAsInteger(10, ULL);
+  S = S.substr(Idx);
+  return true;
+}
+
 LayoutOverrideSource::LayoutOverrideSource(StringRef Filename) {
   std::ifstream Input(Filename.str().c_str());
   if (!Input.is_open())
@@ -80,8 +93,8 @@
   LineStr = LineStr.substr(Pos + strlen(" Size:"));
 
   unsigned long long Size = 0;
-  (void)LineStr.getAsInteger(10, Size);
-  CurrentLayout.Size = Size;
+  if (parseUnsigned(LineStr, Size))
+CurrentLayout.Size = Size;
   continue;
 }
 
@@ -92,12 +105,13 @@
   LineStr = LineStr.substr(Pos + strlen("Alignment:"));
 
   unsigned long long Alignment = 0;
-  (void)LineStr.getAsInteger(10, Alignment);
-  CurrentLayout.Align = Alignment;
+  if (parseUnsigned(LineStr, Alignment))
+CurrentLayout.Align = Alignment;
   continue;
 }
 

[PATCH] D147218: [OpenMP][Flang][MLIR] Lowering of OpenMP requires directive from parse tree to MLIR

2023-06-14 Thread Sergio Afonso via Phabricator via cfe-commits
skatrak updated this revision to Diff 531437.
skatrak added a comment.

Update patch to integrate with related patch D149337 
 and address reviewer's comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147218/new/

https://reviews.llvm.org/D147218

Files:
  flang/include/flang/Lower/OpenMP.h
  flang/lib/Lower/Bridge.cpp
  flang/lib/Lower/OpenMP.cpp
  flang/test/Lower/OpenMP/requires-notarget.f90
  flang/test/Lower/OpenMP/requires.f90

Index: flang/test/Lower/OpenMP/requires.f90
===
--- /dev/null
+++ flang/test/Lower/OpenMP/requires.f90
@@ -0,0 +1,13 @@
+! RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s
+
+! This test checks the lowering of requires into MLIR
+
+!CHECK:  module attributes {
+!CHECK-SAME: omp.requires = #omp
+program requires
+  !$omp requires unified_shared_memory reverse_offload atomic_default_mem_order(seq_cst)
+end program requires
+
+subroutine f
+  !$omp declare target
+end subroutine f
Index: flang/test/Lower/OpenMP/requires-notarget.f90
===
--- /dev/null
+++ flang/test/Lower/OpenMP/requires-notarget.f90
@@ -0,0 +1,11 @@
+! RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s
+
+! This test checks that requires lowering into MLIR skips creating the
+! omp.requires attribute with target-related clauses if there are no device
+! functions in the compilation unit
+
+!CHECK:  module attributes {
+!CHECK-NOT:  omp.requires
+program requires
+  !$omp requires unified_shared_memory reverse_offload atomic_default_mem_order(seq_cst)
+end program requires
Index: flang/lib/Lower/OpenMP.cpp
===
--- flang/lib/Lower/OpenMP.cpp
+++ flang/lib/Lower/OpenMP.cpp
@@ -2594,16 +2594,14 @@
   converter.bindSymbol(sym, symThreadprivateExv);
 }
 
-void handleDeclareTarget(Fortran::lower::AbstractConverter ,
- Fortran::lower::pft::Evaluation ,
- const Fortran::parser::OpenMPDeclareTargetConstruct
- ) {
-  llvm::SmallVector,
-0>
-  symbolAndClause;
-  mlir::ModuleOp mod = converter.getFirOpBuilder().getModule();
-
+/// Extract the list of function and variable symbols affected by the given
+/// 'declare target' directive and return the intended device type for them.
+static mlir::omp::DeclareTargetDeviceType getDeclareTargetInfo(
+Fortran::lower::pft::Evaluation ,
+const Fortran::parser::OpenMPDeclareTargetConstruct ,
+SmallVectorImpl> ) {
+  // Gather the symbols and clauses
   auto findFuncAndVarSyms = [&](const Fortran::parser::OmpObjectList ,
 mlir::omp::DeclareTargetCaptureClause clause) {
 for (const Fortran::parser::OmpObject  : objList.v) {
@@ -2628,6 +2626,7 @@
   Fortran::parser::OmpDeviceTypeClause::Type::Any;
   const auto  = std::get(
   declareTargetConstruct.t);
+
   if (const auto *objectList{
   Fortran::parser::Unwrap(spec.u)}) {
 // Case: declare target(func, var1, var2)
@@ -2662,6 +2661,28 @@
 }
   }
 
+  switch (deviceType) {
+  case Fortran::parser::OmpDeviceTypeClause::Type::Any:
+return mlir::omp::DeclareTargetDeviceType::any;
+  case Fortran::parser::OmpDeviceTypeClause::Type::Host:
+return mlir::omp::DeclareTargetDeviceType::host;
+  case Fortran::parser::OmpDeviceTypeClause::Type::Nohost:
+return mlir::omp::DeclareTargetDeviceType::nohost;
+  }
+}
+
+void genDeclareTarget(Fortran::lower::AbstractConverter ,
+  Fortran::lower::pft::Evaluation ,
+  const Fortran::parser::OpenMPDeclareTargetConstruct
+  ) {
+  llvm::SmallVector,
+0>
+  symbolAndClause;
+  mlir::ModuleOp mod = converter.getFirOpBuilder().getModule();
+  mlir::omp::DeclareTargetDeviceType deviceType =
+  getDeclareTargetInfo(eval, declareTargetConstruct, symbolAndClause);
+
   for (std::pair
symClause : symbolAndClause) {
@@ -2688,35 +2709,44 @@
   converter.getCurrentLocation(),
   "Attempt to apply declare target on unsupported operation");
 
-mlir::omp::DeclareTargetDeviceType newDeviceType;
-switch (deviceType) {
-case Fortran::parser::OmpDeviceTypeClause::Type::Nohost:
-  newDeviceType = mlir::omp::DeclareTargetDeviceType::nohost;
-  break;
-case Fortran::parser::OmpDeviceTypeClause::Type::Host:
-  newDeviceType = mlir::omp::DeclareTargetDeviceType::host;
-  break;
-case Fortran::parser::OmpDeviceTypeClause::Type::Any:
-  newDeviceType = mlir::omp::DeclareTargetDeviceType::any;
-  break;
-}
-
 // The function or global already has a declare target applied to it,
 // very likely through implicit capture (usage in another declare
 // target function/subroutine). It 

[PATCH] D152882: [LinkerWrapper] Support device binaries in multiple link jobs

2023-06-14 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

In D152882#4421138 , @yaxunl wrote:

> The design of target ID put constraints on target ID's that can be embedded 
> into one executable 
> https://clang.llvm.org/docs/ClangOffloadBundler.html#bundle-entry-id . For 
> example, gfx90a and gfx90a:xnack+ cannot be embedded into one executable 
> since this will cause difficulty for runtime to choose device binary to run, 
> especially when there are multiple target ID features. clang does not allow 
> --offload-arch=gfx90a and --offload-arch=gfx90a:xnack+ to be used together to 
> compile HIP programs. It would be preferred for offloack-packager to enforce 
> this constraint too.
>
> However, bitcode of  target ID gfx90a:xnack+ is allowed to link in bitcode of 
> target ID gfx90a as long as they are from different containers. So there are 
> two rules about target ID: 1. compatibility rules for objects/bitcode in the 
> same container 2. compatibility rules for linking bitcode of different target 
> ID's.
>
> we need tests for both rules.

Should that be a follow-up patch? Or one included here. It definitely 
influences the test so I can change that.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152882/new/

https://reviews.llvm.org/D152882

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


[PATCH] D137872: Implement lambdas with inalloca parameters by forwarding to function without inalloca calling convention.

2023-06-14 Thread Amy Huang via Phabricator via cfe-commits
akhuang updated this revision to Diff 531435.
akhuang added a comment.

Call GenerateCode to emit __impl function body


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137872/new/

https://reviews.llvm.org/D137872

Files:
  clang/include/clang/CodeGen/CGFunctionInfo.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGCall.h
  clang/lib/CodeGen/CGClass.cpp
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CodeGenABITypes.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/CodeGenTypes.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGenCXX/inalloca-lambda.cpp

Index: clang/test/CodeGenCXX/inalloca-lambda.cpp
===
--- clang/test/CodeGenCXX/inalloca-lambda.cpp
+++ clang/test/CodeGenCXX/inalloca-lambda.cpp
@@ -1,11 +1,50 @@
-// RUN: not %clang_cc1 -triple i686-windows-msvc -emit-llvm -o /dev/null %s  2>&1 | FileCheck %s
+// RUN: %clang_cc1 -triple i686-windows-msvc -emit-llvm -o - %s  2>&1 | FileCheck %s
 
-// PR28299
-// CHECK: error: cannot compile this forwarded non-trivially copyable parameter yet
-
-class A {
+struct A {
+  A();
   A(const A &);
+  int x;
 };
-typedef void (*fptr_t)(A);
-fptr_t fn1() { return [](A) {}; }
+void decayToFp(int (*f)(A));
+void test() {
+  auto ld = [](A a) {
+static int calls = 0;
+++calls;
+return a.x + calls;
+  };
+  decayToFp(ld);
+  ld(A{});
+}
+
+// CHECK: define internal x86_thiscallcc noundef i32 
+// CHECK-SAME: @"??R@?0??test@@YAXXZ@QBE?A?@@UA@@@Z"
+// CHECK-SAME: (ptr noundef %this, ptr inalloca(<{ %struct.A }>) %[[ARG:.*]])
+// CHECK: %[[V:.*]] = getelementptr inbounds <{ %struct.A }>, ptr %[[ARG]], i32 0, i32 0
+// CHECK: %call = call x86_thiscallcc noundef i32 
+// CHECK-SAME: @"?__impl@@?0??test@@YAXXZ@QBE?A?@@UA@@@Z"
+// CHECK-SAME: (ptr noundef %unused.capture, ptr noundef %[[V]])
+
+// CHECK: define internal noundef i32
+// CHECK-SAME: @"?__invoke@@?0??test@@YAXXZ@CA?A?@@UA@@@Z"
+// CHECK-SAME: (ptr inalloca(<{ %struct.A }>) %[[ARG:.*]])
+// CHECK: %unused.capture = alloca %class.anon, align 1
+// CHECK: %[[VAR:.*]] = getelementptr inbounds <{ %struct.A }>, ptr %[[ARG]], i32 0, i32 0
+// CHECK: %call = call x86_thiscallcc noundef i32
+// CHECK-SAME: @"?__impl@@?0??test@@YAXXZ@QBE?A?@@UA@@@Z"
+// CHECK-SAME: (ptr noundef %unused.capture, ptr noundef %[[VAR]])
+// CHECK: ret i32 %call 
 
+// CHECK: define internal x86_thiscallcc noundef i32
+// CHECK-SAME: @"?__impl@@?0??test@@YAXXZ@QBE?A?@@UA@@@Z"
+// CHECK-SAME: (ptr noundef %this, ptr noundef %[[ARG:.*]])
+// CHECK: %this.addr = alloca ptr, align 4
+// CHECK: store ptr %this, ptr %this.addr, align 4
+// CHECK: %this1 = load ptr, ptr %this.addr, align 4
+// CHECK: %{{.*}} = load i32, ptr @"?calls@?1???R
+// CHECK: %inc = add nsw i32 %{{.*}}, 1
+// CHECK: store i32 %inc, ptr @"?calls@?1???R
+// CHECK: %{{.*}} = getelementptr inbounds %struct.A, ptr %{{.*}}, i32 0, i32 0
+// CHECK: %{{.*}} = load i32, ptr %{{.*}}, align 4
+// CHECK: %{{.*}} = load i32, ptr @"?calls@?1???R
+// CHECK: %add = add nsw i32 %{{.*}}, %{{.*}}
+// CHECK: ret i32 %add
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -1197,7 +1197,8 @@
 
   Class classify(QualType Ty) const;
   ABIArgInfo classifyReturnType(QualType RetTy, CCState ) const;
-  ABIArgInfo classifyArgumentType(QualType RetTy, CCState ) const;
+  ABIArgInfo classifyArgumentType(QualType RetTy, CCState ,
+  bool isDelegateCall) const;
 
   /// Updates the number of available free registers, returns
   /// true if any registers were allocated.
@@ -1824,8 +1825,8 @@
   }
 }
 
-ABIArgInfo X86_32ABIInfo::classifyArgumentType(QualType Ty,
-   CCState ) const {
+ABIArgInfo X86_32ABIInfo::classifyArgumentType(QualType Ty, CCState ,
+   bool isDelegateCall) const {
   // FIXME: Set alignment on indirect arguments.
   bool IsFastCall = State.CC == llvm::CallingConv::X86_FastCall;
   bool IsRegCall = State.CC == llvm::CallingConv::X86_RegCall;
@@ -1838,7 +1839,7 @@
   const RecordType *RT = Ty->getAs();
   if (RT) {
 CGCXXABI::RecordArgABI RAA = getRecordArgABI(RT, getCXXABI());
-if (RAA == CGCXXABI::RAA_Indirect) {
+if (RAA == CGCXXABI::RAA_Indirect || isDelegateCall) {
   return getIndirectResult(Ty, false, State);
 } else if (RAA == CGCXXABI::RAA_DirectInMemory) {
   // The field index doesn't matter, we'll fix it up later.
@@ -2027,7 +2028,8 @@
 if (State.IsPreassigned.test(I))
   continue;
 
-Args[I].info = classifyArgumentType(Args[I].type, State);
+Args[I].info =
+classifyArgumentType(Args[I].type, State, FI.isDelegateCall());
 UsedInAlloca |= (Args[I].info.getKind() == ABIArgInfo::InAlloca);
   

[PATCH] D137872: Implement lambdas with inalloca parameters by forwarding to function without inalloca calling convention.

2023-06-14 Thread Amy Huang via Phabricator via cfe-commits
akhuang added inline comments.



Comment at: clang/lib/CodeGen/CGClass.cpp:3097
+  FD->getLocation(), FD->getLocation());
+CGF.EmitFunctionBody(FD->getBody());
+CGF.FinishFunction();

efriedma wrote:
> Is there any way we can use GenerateCode as the entrypoint here, instead of 
> calling EmitFunctionBody directly?  Without this patch, EmitFunctionBody has 
> exactly one caller, so this makes the control flow and special cases more 
> complicated to reason about.  For example, there's some special coroutine 
> handling in GenerateCode.
Changed to using GenerateCode -- had to add another case to the path in 
GenerateCode to make sure we emit different things for the call op body inside 
__impl and the call op body inside the call op function.



Comment at: clang/lib/CodeGen/CodeGenFunction.cpp:1472
+// the call operator body.
+EmitLambdaStaticInvokeBody(cast(FD));
   } else if (FD->isDefaulted() && isa(FD) &&

efriedma wrote:
> Does this pass the correct value of "this"?  EmitLambdaStaticInvokeBody 
> creates a new alloca to represent "this", but it's already an argument to the 
> function.
> 
> Granted, it only matters in really obscure cases, but still.
That's true, the "this" won't be passed correctly.

Actually, would it be fine to just emit the original call op body? (so that the 
same function body is emitted twice -- once in the call op and once in __impl). 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137872/new/

https://reviews.llvm.org/D137872

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


[PATCH] D93829: [clangd] Support outgoing calls in call hierarchy

2023-06-14 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

Thank you Sam for the suggested performance improvements, and outlining a way 
forward.

@qchateau, are you interested in updating the patch to implement some of the 
described optimizations / address other comments?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93829/new/

https://reviews.llvm.org/D93829

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


[PATCH] D152788: [Clang] Show type in enum out of range diagnostic

2023-06-14 Thread Dimitry Andric via Phabricator via cfe-commits
dim added inline comments.



Comment at: clang/test/SemaCXX/constant-expression-cxx11.cpp:2479-2486
+template struct Bitfield {
+  static constexpr T max = static_cast((1 << size) - 1);
+};
+
+void testValueInRangeOfEnumerationValuesViaTemplate() {
+  Bitfield good;
+  Bitfield bad;

aaron.ballman wrote:
> Equivalent but a bit easier to tell where the diagnostic is expected to 
> happen at.
> 
> Perhaps a good follow-up would be to find out why we're not printing an 
> "instantiated from here" note for this case (CC @shafik), but no need to do 
> that for this patch.
Ah, I didn't know that syntax. At first I had the `cxx11-error@` just below the 
`static_cast` in the `Bitfield` class, but it seemed clearer to do it the way I 
did.

That said, you are right that it would probably be handy to show where the 
instantiation is coming from (if there is a template involved), because 
currently it does not point you to the exact source line where the problem is: 
in this case the `bad` declaration.



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152788/new/

https://reviews.llvm.org/D152788

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


[PATCH] D152500: [clangd] Unwrap type sugar in HeuristicResolver::resolveTypeToRecordDecl()

2023-06-14 Thread Nathan Ridge via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG19c9af81b1c5: [clangd] Unwrap type sugar in 
HeuristicResolver::resolveTypeToRecordDecl() (authored by nridge).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152500/new/

https://reviews.llvm.org/D152500

Files:
  clang-tools-extra/clangd/HeuristicResolver.cpp
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp


Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -863,6 +863,20 @@
   )cpp";
   EXPECT_DECLS("CXXDependentScopeMemberExpr",
"template  T convert() const");
+
+  Code = R"cpp(
+template 
+struct Waldo {
+  void find();
+};
+template 
+using Wally = Waldo;
+template 
+void foo(Wally w) {
+  w.[[find]]();
+}
+  )cpp";
+  EXPECT_DECLS("CXXDependentScopeMemberExpr", "void find()");
 }
 
 TEST_F(TargetDeclTest, DependentTypes) {
Index: clang-tools-extra/clangd/HeuristicResolver.cpp
===
--- clang-tools-extra/clangd/HeuristicResolver.cpp
+++ clang-tools-extra/clangd/HeuristicResolver.cpp
@@ -35,6 +35,9 @@
 CXXRecordDecl *resolveTypeToRecordDecl(const Type *T) {
   assert(T);
 
+  // Unwrap type sugar such as type aliases.
+  T = T->getCanonicalTypeInternal().getTypePtr();
+
   if (const auto *RT = T->getAs())
 return dyn_cast(RT->getDecl());
 


Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -863,6 +863,20 @@
   )cpp";
   EXPECT_DECLS("CXXDependentScopeMemberExpr",
"template  T convert() const");
+
+  Code = R"cpp(
+template 
+struct Waldo {
+  void find();
+};
+template 
+using Wally = Waldo;
+template 
+void foo(Wally w) {
+  w.[[find]]();
+}
+  )cpp";
+  EXPECT_DECLS("CXXDependentScopeMemberExpr", "void find()");
 }
 
 TEST_F(TargetDeclTest, DependentTypes) {
Index: clang-tools-extra/clangd/HeuristicResolver.cpp
===
--- clang-tools-extra/clangd/HeuristicResolver.cpp
+++ clang-tools-extra/clangd/HeuristicResolver.cpp
@@ -35,6 +35,9 @@
 CXXRecordDecl *resolveTypeToRecordDecl(const Type *T) {
   assert(T);
 
+  // Unwrap type sugar such as type aliases.
+  T = T->getCanonicalTypeInternal().getTypePtr();
+
   if (const auto *RT = T->getAs())
 return dyn_cast(RT->getDecl());
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 19c9af8 - [clangd] Unwrap type sugar in HeuristicResolver::resolveTypeToRecordDecl()

2023-06-14 Thread Nathan Ridge via cfe-commits

Author: Nathan Ridge
Date: 2023-06-14T13:51:00-04:00
New Revision: 19c9af81b1c5dd7b3d11d235a77b7181b9368a28

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

LOG: [clangd] Unwrap type sugar in HeuristicResolver::resolveTypeToRecordDecl()

Fixes https://github.com/clangd/clangd/issues/1663

Differential Revision: https://reviews.llvm.org/D152500

Added: 


Modified: 
clang-tools-extra/clangd/HeuristicResolver.cpp
clang-tools-extra/clangd/unittests/FindTargetTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/HeuristicResolver.cpp 
b/clang-tools-extra/clangd/HeuristicResolver.cpp
index 460b9be592baa..e91bd0e87a8b7 100644
--- a/clang-tools-extra/clangd/HeuristicResolver.cpp
+++ b/clang-tools-extra/clangd/HeuristicResolver.cpp
@@ -35,6 +35,9 @@ const auto TemplateFilter = [](const NamedDecl *D) {
 CXXRecordDecl *resolveTypeToRecordDecl(const Type *T) {
   assert(T);
 
+  // Unwrap type sugar such as type aliases.
+  T = T->getCanonicalTypeInternal().getTypePtr();
+
   if (const auto *RT = T->getAs())
 return dyn_cast(RT->getDecl());
 

diff  --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp 
b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
index fe87e4be3940e..d54539b53badd 100644
--- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -863,6 +863,20 @@ TEST_F(TargetDeclTest, DependentExprs) {
   )cpp";
   EXPECT_DECLS("CXXDependentScopeMemberExpr",
"template  T convert() const");
+
+  Code = R"cpp(
+template 
+struct Waldo {
+  void find();
+};
+template 
+using Wally = Waldo;
+template 
+void foo(Wally w) {
+  w.[[find]]();
+}
+  )cpp";
+  EXPECT_DECLS("CXXDependentScopeMemberExpr", "void find()");
 }
 
 TEST_F(TargetDeclTest, DependentTypes) {



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


  1   2   3   >