[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-01-23 Thread via cfe-commits

dyung wrote:

Hi @ChuanqiXu9, the test you added is failing on the PS4 bot because for the 
PS4 target, it requires an external linker which is not present/available. Can 
the test be rewritten to not require linking?

https://lab.llvm.org/buildbot/#/builders/139/builds/57928
```
clang: error: unable to execute command: Executable "orbis-ld" doesn't exist!
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```

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


[clang] [llvm] [KMSAN] Enable on PowerPC64 (PR #73611)

2024-01-23 Thread Fangrui Song via cfe-commits

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


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


[clang] [clang][PowerPC] Add flag to enable compatibility with GNU for complex arguments (PR #77732)

2024-01-23 Thread Kishan Parmar via cfe-commits

https://github.com/Long5hot updated 
https://github.com/llvm/llvm-project/pull/77732

>From 6a209fb25b7923228a7f4e2a8e2accbc31988622 Mon Sep 17 00:00:00 2001
From: Kishan Parmar 
Date: Wed, 24 Jan 2024 13:14:03 +0530
Subject: [PATCH] [clang][PowerPC] Add flag to enable compatibility with GNU
 for complex arguments

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

https://godbolt.org/z/1bsW1sKMs

newFlag : -fcomplex-ppc-gnu-abi

GNU uses GPRs for complex parameters and return values storing for 
PowerPC-32bit,
which can be enabled which above flag.
Intent of this patch is to make clang compatible with GNU libraries of complex.
---
 clang/include/clang/Basic/CodeGenOptions.def  |   2 +
 clang/include/clang/Basic/CodeGenOptions.h|   7 +
 clang/include/clang/Driver/Options.td |   4 +
 clang/lib/CodeGen/CodeGenModule.cpp   |   6 +-
 clang/lib/CodeGen/TargetInfo.h|   3 +-
 clang/lib/CodeGen/Targets/PPC.cpp | 110 +--
 clang/lib/Driver/ToolChains/Clang.cpp |   9 ++
 clang/lib/Frontend/CompilerInvocation.cpp |   8 ++
 .../CodeGen/PowerPC/ppc32-complex-gnu-abi.c   | 132 ++
 9 files changed, 266 insertions(+), 15 deletions(-)
 create mode 100644 clang/test/CodeGen/PowerPC/ppc32-complex-gnu-abi.c

diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 2f2e45d5cf63dfa..5bafcab086bb409 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -223,6 +223,8 @@ CODEGENOPT(MCDCCoverage , 1, 0) ///< Enable MC/DC code 
coverage criteria.
 
   /// If -fpcc-struct-return or -freg-struct-return is specified.
 ENUM_CODEGENOPT(StructReturnConvention, StructReturnConventionKind, 2, 
SRCK_Default)
+  /// If -fcomplex-ppc-gnu-abi for ppc32
+ENUM_CODEGENOPT(ComplexInRegABI, ComplexArgumentConventionKind, 2, 
CMPLX_Default)
 
 CODEGENOPT(RelaxAll  , 1, 0) ///< Relax all machine code instructions.
 CODEGENOPT(RelaxedAliasing   , 1, 0) ///< Set when -fno-strict-aliasing is 
enabled.
diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 3f8fe385fef3dff..670b009e4138c1d 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -78,6 +78,13 @@ class CodeGenOptions : public CodeGenOptionsBase {
 SRCK_InRegs// Small structs in registers (-freg-struct-return).
   };
 
+  enum ComplexArgumentConventionKind {
+CMPLX_Default,
+CMPLX_OnStack,
+CMPLX_OnGPR, // if ppc32 -fcomplex-ppc-gnu-abi
+CMPLX_OnFPR
+  };
+
   enum ProfileInstrKind {
 ProfileNone,   // Profile instrumentation is turned off.
 ProfileClangInstr, // Clang instrumentation to generate execution counts
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7f4fa33748facaf..38e351e38037249 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2540,6 +2540,10 @@ def ffp_contract : Joined<["-"], "ffp-contract=">, 
Group,
   HelpText<"Form fused FP ops (e.g. FMAs)">,
   Values<"fast,on,off,fast-honor-pragmas">;
 
+def fcomplex_ppc_gnu_abi : Flag<["-"], "fcomplex-ppc-gnu-abi">, 
Group, Visibility<[ClangOption, CC1Option]>,
+  DocBrief<"Follow the GNU ABI, store Complex values in GPR instead of stack 
for PowerPC-32">,
+  HelpText<"Store Complex values in GPR instead of stack for PowerPC-32">;
+
 defm strict_float_cast_overflow : BoolFOption<"strict-float-cast-overflow",
   CodeGenOpts<"StrictFloatCastOverflow">, DefaultTrue,
   NegFlag
 createAIXTargetCodeGenInfo(CodeGenModule &CGM, bool Is64Bit);
 
 std::unique_ptr
-createPPC32TargetCodeGenInfo(CodeGenModule &CGM, bool SoftFloatABI);
+createPPC32TargetCodeGenInfo(CodeGenModule &CGM, bool SoftFloatABI,
+ unsigned RLen);
 
 std::unique_ptr
 createPPC64TargetCodeGenInfo(CodeGenModule &CGM);
diff --git a/clang/lib/CodeGen/Targets/PPC.cpp 
b/clang/lib/CodeGen/Targets/PPC.cpp
index 40e508c1772..f514f2e25a48f92 100644
--- a/clang/lib/CodeGen/Targets/PPC.cpp
+++ b/clang/lib/CodeGen/Targets/PPC.cpp
@@ -271,22 +271,33 @@ namespace {
 class PPC32_SVR4_ABIInfo : public DefaultABIInfo {
   bool IsSoftFloatABI;
   bool IsRetSmallStructInRegABI;
+  bool isComplexInRegABI;
+  // Size of GPR in bits
+  unsigned RLen;
+  static const int NumArgGPRs = 8;
 
   CharUnits getParamTypeAlignment(QualType Ty) const;
+  ABIArgInfo handleComplex(QualType Ty, uint64_t &TypeSize) const;
 
 public:
   PPC32_SVR4_ABIInfo(CodeGen::CodeGenTypes &CGT, bool SoftFloatABI,
- bool RetSmallStructInRegABI)
+ bool RetSmallStructInRegABI, unsigned RLen,
+ bool ComplexInRegABI)
   : DefaultABIInfo(CGT), IsSoftFloatABI(SoftFloatABI),
-IsRetSmallStructInRegABI(RetSmallStructInRegABI) {}
+IsRetSmallStructInRegABI(RetSmallStructInRegAB

[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-01-23 Thread Chuanqi Xu via cfe-commits

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


[clang] dd3e6c8 - Support C++20 Modules in clang-repl (#79261)

2024-01-23 Thread via cfe-commits

Author: Chuanqi Xu
Date: 2024-01-24T15:45:05+08:00
New Revision: dd3e6c87f3f4affd17d05a4d25fa77d224a98d94

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

LOG: Support C++20 Modules in clang-repl (#79261)

This comes from when I playing around clang-repl with moduels : )

I succeeded to import std with https://libcxx.llvm.org/Modules.html and
calling `std::printf` after this patch.

I want to put the documentation part to
https://clang.llvm.org/docs/StandardCPlusPlusModules.html in a separate
commit.

Added: 
clang/test/Interpreter/cxx20-modules.cppm

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/LangOptions.def
clang/lib/Serialization/ASTReaderDecl.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index fc7511e9136734c..db3d74e124e7d1d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -191,6 +191,8 @@ Crash and bug fixes
 Improvements
 
 
+- Support importing C++20 modules in clang-repl.
+
 Moved checkers
 ^^
 

diff  --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 8fc75e1cca0399f..1e671a7c4601638 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -485,7 +485,7 @@ VALUE_LANGOPT(FuchsiaAPILevel, 32, 0, "Fuchsia API level")
 // on large _BitInts.
 BENIGN_VALUE_LANGOPT(MaxBitIntWidth, 32, 128, "Maximum width of a _BitInt")
 
-LANGOPT(IncrementalExtensions, 1, 0, " True if we want to process statements"
+COMPATIBLE_LANGOPT(IncrementalExtensions, 1, 0, " True if we want to process 
statements"
 "on the global scope, ignore EOF token and continue later on (thus "
 "avoid tearing the Lexer and etc. down). Controlled by "
 "-fincremental-extensions.")

diff  --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index a149d82153037f8..867f4c47eaeceb7 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -3286,10 +3286,10 @@ DeclContext 
*ASTDeclReader::getPrimaryContextForMerging(ASTReader &Reader,
   if (auto *OID = dyn_cast(DC))
 return OID->getDefinition();
 
-  // We can see the TU here only if we have no Sema object. In that case,
-  // there's no TU scope to look in, so using the DC alone is sufficient.
+  // We can see the TU here only if we have no Sema object. It is possible
+  // we're in clang-repl so we still need to get the primary context.
   if (auto *TU = dyn_cast(DC))
-return TU;
+return TU->getPrimaryContext();
 
   return nullptr;
 }

diff  --git a/clang/test/Interpreter/cxx20-modules.cppm 
b/clang/test/Interpreter/cxx20-modules.cppm
new file mode 100644
index 000..bc2b722f6b5197e
--- /dev/null
+++ b/clang/test/Interpreter/cxx20-modules.cppm
@@ -0,0 +1,31 @@
+// UNSUPPORTED: system-aix
+//
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang -std=c++20 %t/mod.cppm --precompile \
+// RUN: -o %t/mod.pcm
+// RUN: %clang %t/mod.pcm -c -o %t/mod.o
+// RUN: %clang -shared %t/mod.o -o %t/libmod.so
+//
+// RUN: cat %t/import.cpp | env LD_LIBRARY_PATH=%t:$LD_LIBRARY_PATH \
+// RUN: clang-repl -Xcc=-std=c++20 -Xcc=-fmodule-file=M=%t/mod.pcm \
+// RUN: | FileCheck %t/import.cpp
+
+//--- mod.cppm
+export module M;
+export const char* Hello() {
+return "Hello Interpreter for Modules!";
+}
+
+//--- import.cpp
+
+%lib libmod.so
+
+import M;
+
+extern "C" int printf(const char *, ...);
+printf("%s\n", Hello());
+
+// CHECK: Hello Interpreter for Modules!



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


[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-01-23 Thread Vassil Vassilev via cfe-commits

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

Lgtm! Thank you @ChuanqiXu9!

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


[clang] [clang] Make sure the same UsingType is searched and inserted (PR #79182)

2024-01-23 Thread Wei Wang via cfe-commits

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


[clang-tools-extra] [clang] [llvm] [clang] support Wold-style-declaration (PR #78837)

2024-01-23 Thread via cfe-commits

SihangZhu wrote:

ping

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


[clang] [llvm] [CMake][PGO] Add option for using an external project to generate profile data (PR #78879)

2024-01-23 Thread Petr Hosek via cfe-commits

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


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


[clang] [clang] Make sure the same UsingType is searched and inserted (PR #79182)

2024-01-23 Thread Wei Wang via cfe-commits

apolloww wrote:

Thanks. Added test case.

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


[clang] [clang] Make sure the same UsingType is searched and inserted (PR #79182)

2024-01-23 Thread Wei Wang via cfe-commits

https://github.com/apolloww updated 
https://github.com/llvm/llvm-project/pull/79182

>From a542d63f472d799eb2d041c82cac402cfb8dec1a Mon Sep 17 00:00:00 2001
From: Wei Wang 
Date: Tue, 23 Jan 2024 10:01:57 -0800
Subject: [PATCH 1/3] [clang] Make sure the same UsingType is searched and
 inserted

---
 clang/lib/AST/ASTContext.cpp | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 5eb7aa3664569dd..d312ef61fb15d4a 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -4672,12 +4672,6 @@ QualType ASTContext::getTypedefType(const 
TypedefNameDecl *Decl,
 QualType ASTContext::getUsingType(const UsingShadowDecl *Found,
   QualType Underlying) const {
   llvm::FoldingSetNodeID ID;
-  UsingType::Profile(ID, Found, Underlying);
-
-  void *InsertPos = nullptr;
-  if (UsingType *T = UsingTypes.FindNodeOrInsertPos(ID, InsertPos))
-return QualType(T, 0);
-
   const Type *TypeForDecl =
   cast(Found->getTargetDecl())->getTypeForDecl();
 
@@ -4687,6 +4681,13 @@ QualType ASTContext::getUsingType(const UsingShadowDecl 
*Found,
 
   if (Underlying.getTypePtr() == TypeForDecl)
 Underlying = QualType();
+  UsingType::Profile(ID, Found, Underlying);
+
+  void *InsertPos = nullptr;
+  if (UsingType *T = UsingTypes.FindNodeOrInsertPos(ID, InsertPos)) {
+return QualType(T, 0);
+  }
+
   void *Mem =
   Allocate(UsingType::totalSizeToAlloc(!Underlying.isNull()),
alignof(UsingType));

>From 6dba099a2e1f06feb65248678a57bd00a3d4d0ae Mon Sep 17 00:00:00 2001
From: Wei Wang 
Date: Tue, 23 Jan 2024 19:58:24 -0800
Subject: [PATCH 2/3] update UsingType profile implementation

---
 clang/include/clang/AST/Type.h |  5 ++---
 clang/lib/AST/ASTContext.cpp   | 13 ++---
 2 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index ea425791fc97f05..3d411051084c71b 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -4729,13 +4729,12 @@ class UsingType final : public Type,
   bool typeMatchesDecl() const { return !UsingBits.hasTypeDifferentFromDecl; }
 
   void Profile(llvm::FoldingSetNodeID &ID) {
-Profile(ID, Found, typeMatchesDecl() ? QualType() : getUnderlyingType());
+Profile(ID, Found, getUnderlyingType());
   }
   static void Profile(llvm::FoldingSetNodeID &ID, const UsingShadowDecl *Found,
   QualType Underlying) {
 ID.AddPointer(Found);
-if (!Underlying.isNull())
-  Underlying.Profile(ID);
+Underlying.Profile(ID);
   }
   static bool classof(const Type *T) { return T->getTypeClass() == Using; }
 };
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index d312ef61fb15d4a..5eb7aa3664569dd 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -4672,6 +4672,12 @@ QualType ASTContext::getTypedefType(const 
TypedefNameDecl *Decl,
 QualType ASTContext::getUsingType(const UsingShadowDecl *Found,
   QualType Underlying) const {
   llvm::FoldingSetNodeID ID;
+  UsingType::Profile(ID, Found, Underlying);
+
+  void *InsertPos = nullptr;
+  if (UsingType *T = UsingTypes.FindNodeOrInsertPos(ID, InsertPos))
+return QualType(T, 0);
+
   const Type *TypeForDecl =
   cast(Found->getTargetDecl())->getTypeForDecl();
 
@@ -4681,13 +4687,6 @@ QualType ASTContext::getUsingType(const UsingShadowDecl 
*Found,
 
   if (Underlying.getTypePtr() == TypeForDecl)
 Underlying = QualType();
-  UsingType::Profile(ID, Found, Underlying);
-
-  void *InsertPos = nullptr;
-  if (UsingType *T = UsingTypes.FindNodeOrInsertPos(ID, InsertPos)) {
-return QualType(T, 0);
-  }
-
   void *Mem =
   Allocate(UsingType::totalSizeToAlloc(!Underlying.isNull()),
alignof(UsingType));

>From 4c1fc38bd8d7967afa2c557c4f8ec2a6019779d4 Mon Sep 17 00:00:00 2001
From: Wei Wang 
Date: Tue, 23 Jan 2024 23:14:06 -0800
Subject: [PATCH 3/3] add test case

---
 clang/test/AST/ast-dump-using.cpp | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/clang/test/AST/ast-dump-using.cpp 
b/clang/test/AST/ast-dump-using.cpp
index c007ecd8bda5839..5a4e910ffb8654e 100644
--- a/clang/test/AST/ast-dump-using.cpp
+++ b/clang/test/AST/ast-dump-using.cpp
@@ -12,7 +12,13 @@ using a::S;
 typedef S f; // to dump the introduced type
 // CHECK:  TypedefDecl
 // CHECK-NEXT: `-ElaboratedType {{.*}} 'S' sugar
-// CHECK-NEXT:   `-UsingType {{.*}} 'a::S' sugar
-// CHECK-NEXT: |-UsingShadow {{.*}} 'S'
+// CHECK-NEXT:   `-UsingType [[TYPE_ADDR:.*]] 'a::S' sugar
+// CHECK-NEXT: |-UsingShadow [[SHADOW_ADDR:.*]] 'S'
+// CHECK-NEXT: `-RecordType {{.*}} 'a::S'
+typedef S e; // check the same UsingType is reused.
+// CHECK:  TypedefDecl
+// CHECK-NEXT: `-ElaboratedType {{.*}} 'S' sugar
+// CHECK-NEXT:   `-UsingType [[TYPE_ADDR]] 'a::S'

[clang] [clang][dataflow] Eliminate two uses of `RecordValue::getLoc()`. (PR #79163)

2024-01-23 Thread via cfe-commits

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


[clang] 7a6c262 - [clang][dataflow] Eliminate two uses of `RecordValue::getLoc()`. (#79163)

2024-01-23 Thread via cfe-commits

Author: martinboehme
Date: 2024-01-24T08:06:32+01:00
New Revision: 7a6c2628e99f70edf6ee46a6b4b4d3d7301353c6

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

LOG: [clang][dataflow] Eliminate two uses of `RecordValue::getLoc()`. (#79163)

This is a small step towards eventually eliminating `RecordValue`
entirely.

Added: 


Modified: 
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp

Removed: 




diff  --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index 196a1360a7750a..acb38e57647453 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -412,13 +412,13 @@ void Environment::initialize() {
   QualType ThisPointeeType =
   SurroundingMethodDecl->getFunctionObjectParameterType();
   setThisPointeeStorageLocation(
-  cast(createValue(ThisPointeeType))->getLoc());
+  cast(createObject(ThisPointeeType)));
 }
   }
 } else if (MethodDecl->isImplicitObjectMemberFunction()) {
   QualType ThisPointeeType = MethodDecl->getFunctionObjectParameterType();
   setThisPointeeStorageLocation(
-  cast(createValue(ThisPointeeType))->getLoc());
+  cast(createObject(ThisPointeeType)));
 }
   }
 }



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


[lld] [mlir] [flang] [lldb] [clang-tools-extra] [llvm] [compiler-rt] [clang] [libcxx] [clang-format] Add ShortReturnTypeColumn option. (PR #78011)

2024-01-23 Thread via cfe-commits

rmarker wrote:

Merged main and fixed conflicts.
Also updated version badge to 19 with the recent branching for 18.
Keeping things up to date whilst discussion about the underlying issue 
continues on #78010.

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


[clang] 5355857 - [Clang][NFC] Optimize isAsciiIdentifierContinue (#78699)

2024-01-23 Thread via cfe-commits

Author: cor3ntin
Date: 2024-01-24T07:45:50+01:00
New Revision: 5355857038cf6f9e3831504804e973508ffc2d01

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

LOG: [Clang][NFC] Optimize isAsciiIdentifierContinue (#78699)

Precompute the isAsciiIdentifierContinue table which is on the hot path.


https://llvm-compile-time-tracker.com/compare.php?from=30da0f5a359ab4a684c5fdf0f4dbed20bae10f99&to=cb0e48db2b8193d2ee59c2a6e998317cb220d513&stat=instructions:u

Added: 


Modified: 
clang/include/clang/Basic/CharInfo.h

Removed: 




diff  --git a/clang/include/clang/Basic/CharInfo.h 
b/clang/include/clang/Basic/CharInfo.h
index 7d41193835089a6..d80795531182871 100644
--- a/clang/include/clang/Basic/CharInfo.h
+++ b/clang/include/clang/Basic/CharInfo.h
@@ -59,12 +59,28 @@ LLVM_READONLY inline bool isAsciiIdentifierStart(unsigned 
char c,
   return AllowDollar && c == '$';
 }
 
+LLVM_READONLY inline bool isAsciiIdentifierContinue(unsigned char c) {
+  // Precomputed CHAR_UPPER|CHAR_LOWER|CHAR_DIGIT|CHAR_UNDER
+  static constexpr unsigned char IDContinue[256] = {
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1,
+  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
+  0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+  1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+  return IDContinue[c];
+}
+
 /// Returns true if this is a body character of a C identifier,
 /// which is [a-zA-Z0-9_].
 LLVM_READONLY inline bool isAsciiIdentifierContinue(unsigned char c,
-bool AllowDollar = false) {
-  using namespace charinfo;
-  if (InfoTable[c] & (CHAR_UPPER|CHAR_LOWER|CHAR_DIGIT|CHAR_UNDER))
+bool AllowDollar) {
+  if (isAsciiIdentifierContinue(c))
 return true;
   return AllowDollar && c == '$';
 }



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


[clang] [Clang][NFC] Optimize isAsciiIdentifierContinue (PR #78699)

2024-01-23 Thread via cfe-commits

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


[clang] [llvm] [CMake][PGO] Add option for using an external project to generate profile data (PR #78879)

2024-01-23 Thread Tom Stellard via cfe-commits

https://github.com/tstellar updated 
https://github.com/llvm/llvm-project/pull/78879

>From 0719f49ecc6dd69ae4698c3e84dbf175a1bf2ed3 Mon Sep 17 00:00:00 2001
From: Tom Stellard 
Date: Sun, 21 Jan 2024 00:25:47 +
Subject: [PATCH 1/4] [CMake][PGO] Add libunwind to list of stage1 runtimes

This fixes the build since 8f90e6937a1fac80873bb2dab5f382c82ba1ba4e
which made libcxxabi use llvm's libunwind by default.
---
 clang/cmake/caches/PGO.cmake | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/cmake/caches/PGO.cmake b/clang/cmake/caches/PGO.cmake
index e1d0585e453f825..15bc755d110d19a 100644
--- a/clang/cmake/caches/PGO.cmake
+++ b/clang/cmake/caches/PGO.cmake
@@ -2,7 +2,7 @@ set(CMAKE_BUILD_TYPE RELEASE CACHE STRING "")
 set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
 
 set(LLVM_ENABLE_PROJECTS "clang;lld" CACHE STRING "")
-set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi" CACHE STRING "")
+set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING 
"")
 
 set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
 set(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED ON CACHE BOOL "")

>From 5c602233ef4e54e850f6c8a17c25968bc706b898 Mon Sep 17 00:00:00 2001
From: Tom Stellard 
Date: Sat, 6 Jan 2024 07:46:01 +
Subject: [PATCH 2/4] [CMake][PGO] Add option for using an external project to
 generate profile data.

The new CLANG_PGO_TRAINING_DATA_SOURCE_DIR allows users to specify a CMake
project to use for generating the profile data.

For example, to use the llvm-test-suite to generate profile data you
would do:

$ cmake -G Ninja -B build -S llvm -C /clang/cmake/caches/PGO.cmake \
-DBOOTSTRAP_CLANG_PGO_TRAINING_DATA_SOURCE_DIR= \
-DBOOTSTRAP_CLANG_PERF_TRAINING_DEPS=runtimes
---
 clang/utils/perf-training/CMakeLists.txt | 13 +++--
 clang/utils/perf-training/perf-helper.py | 16 +---
 llvm/docs/AdvancedBuilds.rst | 23 +++
 3 files changed, 43 insertions(+), 9 deletions(-)

diff --git a/clang/utils/perf-training/CMakeLists.txt 
b/clang/utils/perf-training/CMakeLists.txt
index c6d51863fb1b5c2..f9d673b2e92e775 100644
--- a/clang/utils/perf-training/CMakeLists.txt
+++ b/clang/utils/perf-training/CMakeLists.txt
@@ -1,6 +1,10 @@
+include(LLVMExternalProjectUtils)
+
 set(CLANG_PGO_TRAINING_DATA "${CMAKE_CURRENT_SOURCE_DIR}" CACHE PATH
   "The path to a lit testsuite containing samples for PGO and order file 
generation"
   )
+set(CLANG_PGO_TRAINING_DATA_SOURCE_DIR OFF CACHE STRING "Path to source 
directory containing cmake project with source files to use for generating pgo 
data")
+set(CLANG_PERF_TRAINING_DEPS "" CACHE STRING "Extra dependencies needed to 
build the PGO training data.")
 
 if(LLVM_BUILD_INSTRUMENTED)
   configure_lit_site_cfg(
@@ -15,7 +19,7 @@ if(LLVM_BUILD_INSTRUMENTED)
 )
 
   add_custom_target(clear-profraw
-COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py 
clean ${CMAKE_CURRENT_BINARY_DIR} profraw
+COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py 
clean ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_BINARY_DIR}/profiles/ profraw
 COMMENT "Clearing old profraw data")
 
   if(NOT LLVM_PROFDATA)
@@ -26,9 +30,14 @@ if(LLVM_BUILD_INSTRUMENTED)
 message(STATUS "To enable merging PGO data LLVM_PROFDATA has to point to 
llvm-profdata")
   else()
 add_custom_target(generate-profdata
-  COMMAND "${Python3_EXECUTABLE}" 
${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py merge ${LLVM_PROFDATA} 
${CMAKE_CURRENT_BINARY_DIR}/clang.profdata ${CMAKE_CURRENT_BINARY_DIR}
+  COMMAND "${Python3_EXECUTABLE}" 
${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py merge ${LLVM_PROFDATA} 
${CMAKE_CURRENT_BINARY_DIR}/clang.profdata ${CMAKE_CURRENT_BINARY_DIR} 
${CMAKE_BINARY_DIR}/profiles/
   COMMENT "Merging profdata"
   DEPENDS generate-profraw)
+if (CLANG_PGO_TRAINING_DATA_SOURCE_DIR)
+  llvm_ExternalProject_Add(generate-profraw-external 
${CLANG_PGO_TRAINING_DATA_SOURCE_DIR}
+  USE_TOOLCHAIN EXLUDE_FROM_ALL NO_INSTALL DEPENDS 
generate-profraw)
+  add_dependencies(generate-profdata generate-profraw-external)
+endif()
   endif()
 endif()
 
diff --git a/clang/utils/perf-training/perf-helper.py 
b/clang/utils/perf-training/perf-helper.py
index 99d6ab6ef08..844aa274f049aaa 100644
--- a/clang/utils/perf-training/perf-helper.py
+++ b/clang/utils/perf-training/perf-helper.py
@@ -30,26 +30,28 @@ def findFilesWithExtension(path, extension):
 
 
 def clean(args):
-if len(args) != 2:
+if len(args) < 2:
 print(
-"Usage: %s clean  \n" % __file__
+"Usage: %s clean  \n" % __file__
 + "\tRemoves all files with extension from ."
 )
 return 1
-for filename in findFilesWithExtension(args[0], args[1]):
-os.remove(filename)
+for path in args[1:-1]:
+for filename in findFilesWithExtension(path, args[-1]):
+os.remove(filename)
 return 0
 
 
 def 

[lld] [mlir] [flang] [lldb] [clang-tools-extra] [llvm] [compiler-rt] [clang] [libcxx] [clang-format] Add ShortReturnTypeColumn option. (PR #78011)

2024-01-23 Thread via cfe-commits

https://github.com/rmarker updated 
https://github.com/llvm/llvm-project/pull/78011

>From c4d28f82e108f9f12ccd0375e2a3502025b8c1e8 Mon Sep 17 00:00:00 2001
From: rmarker 
Date: Thu, 11 Jan 2024 15:01:18 +1030
Subject: [PATCH 1/4] [clang-format] Add ShortReturnTypeLength option.

---
 clang/docs/ClangFormatStyleOptions.rst |  8 
 clang/docs/ReleaseNotes.rst|  1 +
 clang/include/clang/Format/Format.h|  8 
 clang/lib/Format/ContinuationIndenter.cpp  |  3 +-
 clang/lib/Format/Format.cpp|  2 +
 clang/unittests/Format/ConfigParseTest.cpp |  1 +
 clang/unittests/Format/FormatTest.cpp  | 44 ++
 7 files changed, 66 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index ac9a0b70ed5daa4..3255ceb0aba75b4 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -4994,6 +4994,14 @@ the configuration (without a prefix: ``Auto``).
int bar;   int bar;
  } // namespace b   } // namespace b
 
+.. _ShortReturnTypeLength:
+
+**ShortReturnTypeLength** (``Unsigned``) :versionbadge:`clang-format 18` 
:ref:`¶ `
+  When AlwaysBreakAfterReturnType is None, line breaks are prevented after
+  short return types. This configures the character limit for a type to be
+  regarded as short. Note that this isn't the length of the type itself,
+  but the column where it finishes. I.e. it includes indentation, etc.
+
 .. _SortIncludes:
 
 **SortIncludes** (``SortIncludesOptions``) :versionbadge:`clang-format 3.8` 
:ref:`¶ `
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3cbce1be1594376..04bf5cd4e768f34 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1131,6 +1131,7 @@ clang-format
 - Add ``BreakAdjacentStringLiterals`` option.
 - Add ``ObjCPropertyAttributeOrder`` which can be used to sort ObjC property
   attributes (like ``nonatomic, strong, nullable``).
+- Add ``ShortReturnTypeLength`` option.
 - Add ``.clang-format-ignore`` files.
 - Add ``AlignFunctionPointers`` sub-option for 
``AlignConsecutiveDeclarations``.
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 5ffd63ee73fc361..f94d68f2cf2a853 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3928,6 +3928,13 @@ struct FormatStyle {
   /// \version 13
   unsigned ShortNamespaceLines;
 
+  /// When AlwaysBreakAfterReturnType is None, line breaks are prevented after
+  /// short return types. This configures the character limit for a type to be
+  /// regarded as short. Note that this isn't the length of the type itself,
+  /// but the column where it finishes. I.e. it includes indentation, etc.
+  /// \version 18
+  unsigned ShortReturnTypeLength;
+
   /// Include sorting options.
   enum SortIncludesOptions : int8_t {
 /// Includes are never sorted.
@@ -4890,6 +4897,7 @@ struct FormatStyle {
RequiresExpressionIndentation == R.RequiresExpressionIndentation &&
SeparateDefinitionBlocks == R.SeparateDefinitionBlocks &&
ShortNamespaceLines == R.ShortNamespaceLines &&
+   ShortReturnTypeLength == R.ShortReturnTypeLength &&
SortIncludes == R.SortIncludes &&
SortJavaStaticImport == R.SortJavaStaticImport &&
SpaceAfterCStyleCast == R.SpaceAfterCStyleCast &&
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 102504182c4505b..bc0748ec52e6769 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -328,7 +328,8 @@ bool ContinuationIndenter::canBreak(const LineState &State) 
{
 
   // Don't break after very short return types (e.g. "void") as that is often
   // unexpected.
-  if (Current.is(TT_FunctionDeclarationName) && State.Column < 6) {
+  if (Current.is(TT_FunctionDeclarationName) &&
+  State.Column <= Style.ShortReturnTypeLength) {
 if (Style.AlwaysBreakAfterReturnType == FormatStyle::RTBS_None)
   return false;
   }
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index ff5ed6c306f383b..20ffbeef7e9a6e9 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1083,6 +1083,7 @@ template <> struct MappingTraits {
Style.RequiresExpressionIndentation);
 IO.mapOptional("SeparateDefinitionBlocks", Style.SeparateDefinitionBlocks);
 IO.mapOptional("ShortNamespaceLines", Style.ShortNamespaceLines);
+IO.mapOptional("ShortReturnTypeLength", Style.ShortReturnTypeLength);
 IO.mapOptional("SortIncludes", Style.SortIncludes);
 IO.mapOptional("SortJavaStaticImport", Style.SortJavaStaticImport);
 IO.mapOptional("SortUsingDeclarations", Style.SortUsingDeclarations);
@@ -1554,6 +1555,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 

[clang-tools-extra] 7e3fb37 - [include-cleaner] Check emptiness instead of occurences (#79154)

2024-01-23 Thread via cfe-commits

Author: kadir çetinkaya
Date: 2024-01-24T07:26:00+01:00
New Revision: 7e3fb372b0e8899958ec7e9241797e7e136a7a23

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

LOG: [include-cleaner] Check emptiness instead of occurences (#79154)

Our internal integration relies on injecting some default values to
ignore/keep lists.
That means we can have filters, despite of not having occurences
for the flag.

Added: 


Modified: 
clang-tools-extra/include-cleaner/test/tool.cpp
clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp

Removed: 




diff  --git a/clang-tools-extra/include-cleaner/test/tool.cpp 
b/clang-tools-extra/include-cleaner/test/tool.cpp
index de47b2a3f3778c..2155eec189d186 100644
--- a/clang-tools-extra/include-cleaner/test/tool.cpp
+++ b/clang-tools-extra/include-cleaner/test/tool.cpp
@@ -22,10 +22,18 @@ int x = foo();
 // IGNORE2-NOT: - "foobar.h"
 // IGNORE2: + "foo.h"
 
+//RUN: clang-include-cleaner -print=changes %s --ignore-headers= -- 
-I%S/Inputs/ | FileCheck --allow-empty --check-prefix=IGNORE3 %s
+//IGNORE3: - "foobar.h"
+//IGNORE3: + "foo.h"
+
 //RUN: clang-include-cleaner -print=changes %s --only-headers="foo\.h" 
-- -I%S/Inputs/ | FileCheck --match-full-lines --allow-empty 
--check-prefix=ONLY %s
 //   ONLY-NOT: - "foobar.h"
 //   ONLY: + "foo.h"
 
+//RUN: clang-include-cleaner -print=changes %s --only-headers= -- 
-I%S/Inputs/ | FileCheck --allow-empty --check-prefix=ONLY2 %s
+//  ONLY2: - "foobar.h"
+//  ONLY2: + "foo.h"
+
 //RUN: clang-include-cleaner -print %s -- -I%S/Inputs/ | FileCheck 
--match-full-lines --check-prefix=PRINT %s
 //  PRINT: #include "foo.h"
 //  PRINT-NOT: {{^}}#include "foobar.h"{{$}}

diff  --git a/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp 
b/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
index 132ad25411509d..3bc449b0152bba 100644
--- a/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
+++ b/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
@@ -262,9 +262,9 @@ std::function headerFilter() {
 return nullptr;
 
   return [OnlyMatches, IgnoreMatches](llvm::StringRef Header) {
-if (OnlyHeaders.getNumOccurrences() && !OnlyMatches(Header))
+if (!OnlyHeaders.empty() && !OnlyMatches(Header))
   return true;
-if (IgnoreHeaders.getNumOccurrences() && IgnoreMatches(Header))
+if (!IgnoreHeaders.empty() && IgnoreMatches(Header))
   return true;
 return false;
   };



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


[clang-tools-extra] [include-cleaner] Check emptiness instead of occurences (PR #79154)

2024-01-23 Thread kadir çetinkaya via cfe-commits

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


[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-01-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-modules

Author: Chuanqi Xu (ChuanqiXu9)


Changes

This comes from when I playing around clang-repl with moduels : )

I succeeded to import std with https://libcxx.llvm.org/Modules.html and calling 
`std::printf` after this patch.

I want to put the documentation part to 
https://clang.llvm.org/docs/StandardCPlusPlusModules.html in a separate commit.

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


4 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/include/clang/Basic/LangOptions.def (+1-1) 
- (modified) clang/lib/Serialization/ASTReaderDecl.cpp (+3-3) 
- (added) clang/test/Interpreter/cxx20-modules.cppm (+31) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index fc7511e9136734..db3d74e124e7d1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -191,6 +191,8 @@ Crash and bug fixes
 Improvements
 
 
+- Support importing C++20 modules in clang-repl.
+
 Moved checkers
 ^^
 
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 8fc75e1cca0399..1e671a7c460163 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -485,7 +485,7 @@ VALUE_LANGOPT(FuchsiaAPILevel, 32, 0, "Fuchsia API level")
 // on large _BitInts.
 BENIGN_VALUE_LANGOPT(MaxBitIntWidth, 32, 128, "Maximum width of a _BitInt")
 
-LANGOPT(IncrementalExtensions, 1, 0, " True if we want to process statements"
+COMPATIBLE_LANGOPT(IncrementalExtensions, 1, 0, " True if we want to process 
statements"
 "on the global scope, ignore EOF token and continue later on (thus "
 "avoid tearing the Lexer and etc. down). Controlled by "
 "-fincremental-extensions.")
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index a149d82153037f..867f4c47eaeceb 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -3286,10 +3286,10 @@ DeclContext 
*ASTDeclReader::getPrimaryContextForMerging(ASTReader &Reader,
   if (auto *OID = dyn_cast(DC))
 return OID->getDefinition();
 
-  // We can see the TU here only if we have no Sema object. In that case,
-  // there's no TU scope to look in, so using the DC alone is sufficient.
+  // We can see the TU here only if we have no Sema object. It is possible
+  // we're in clang-repl so we still need to get the primary context.
   if (auto *TU = dyn_cast(DC))
-return TU;
+return TU->getPrimaryContext();
 
   return nullptr;
 }
diff --git a/clang/test/Interpreter/cxx20-modules.cppm 
b/clang/test/Interpreter/cxx20-modules.cppm
new file mode 100644
index 00..bc2b722f6b5197
--- /dev/null
+++ b/clang/test/Interpreter/cxx20-modules.cppm
@@ -0,0 +1,31 @@
+// UNSUPPORTED: system-aix
+//
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang -std=c++20 %t/mod.cppm --precompile \
+// RUN: -o %t/mod.pcm
+// RUN: %clang %t/mod.pcm -c -o %t/mod.o
+// RUN: %clang -shared %t/mod.o -o %t/libmod.so
+//
+// RUN: cat %t/import.cpp | env LD_LIBRARY_PATH=%t:$LD_LIBRARY_PATH \
+// RUN: clang-repl -Xcc=-std=c++20 -Xcc=-fmodule-file=M=%t/mod.pcm \
+// RUN: | FileCheck %t/import.cpp
+
+//--- mod.cppm
+export module M;
+export const char* Hello() {
+return "Hello Interpreter for Modules!";
+}
+
+//--- import.cpp
+
+%lib libmod.so
+
+import M;
+
+extern "C" int printf(const char *, ...);
+printf("%s\n", Hello());
+
+// CHECK: Hello Interpreter for Modules!

``




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


[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-01-23 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 created 
https://github.com/llvm/llvm-project/pull/79261

This comes from when I playing around clang-repl with moduels : )

I succeeded to import std with https://libcxx.llvm.org/Modules.html and calling 
`std::printf` after this patch.

I want to put the documentation part to 
https://clang.llvm.org/docs/StandardCPlusPlusModules.html in a separate commit.

>From 70cb9ac882605c3557dc41ea13a4b8945c59e9c2 Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Wed, 24 Jan 2024 14:21:25 +0800
Subject: [PATCH] Support C++20 Modules in clang-repl

---
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/include/clang/Basic/LangOptions.def |  2 +-
 clang/lib/Serialization/ASTReaderDecl.cpp |  6 ++---
 clang/test/Interpreter/cxx20-modules.cppm | 31 +++
 4 files changed, 37 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/Interpreter/cxx20-modules.cppm

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index fc7511e9136734..db3d74e124e7d1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -191,6 +191,8 @@ Crash and bug fixes
 Improvements
 
 
+- Support importing C++20 modules in clang-repl.
+
 Moved checkers
 ^^
 
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 8fc75e1cca0399..1e671a7c460163 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -485,7 +485,7 @@ VALUE_LANGOPT(FuchsiaAPILevel, 32, 0, "Fuchsia API level")
 // on large _BitInts.
 BENIGN_VALUE_LANGOPT(MaxBitIntWidth, 32, 128, "Maximum width of a _BitInt")
 
-LANGOPT(IncrementalExtensions, 1, 0, " True if we want to process statements"
+COMPATIBLE_LANGOPT(IncrementalExtensions, 1, 0, " True if we want to process 
statements"
 "on the global scope, ignore EOF token and continue later on (thus "
 "avoid tearing the Lexer and etc. down). Controlled by "
 "-fincremental-extensions.")
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index a149d82153037f..867f4c47eaeceb 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -3286,10 +3286,10 @@ DeclContext 
*ASTDeclReader::getPrimaryContextForMerging(ASTReader &Reader,
   if (auto *OID = dyn_cast(DC))
 return OID->getDefinition();
 
-  // We can see the TU here only if we have no Sema object. In that case,
-  // there's no TU scope to look in, so using the DC alone is sufficient.
+  // We can see the TU here only if we have no Sema object. It is possible
+  // we're in clang-repl so we still need to get the primary context.
   if (auto *TU = dyn_cast(DC))
-return TU;
+return TU->getPrimaryContext();
 
   return nullptr;
 }
diff --git a/clang/test/Interpreter/cxx20-modules.cppm 
b/clang/test/Interpreter/cxx20-modules.cppm
new file mode 100644
index 00..bc2b722f6b5197
--- /dev/null
+++ b/clang/test/Interpreter/cxx20-modules.cppm
@@ -0,0 +1,31 @@
+// UNSUPPORTED: system-aix
+//
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang -std=c++20 %t/mod.cppm --precompile \
+// RUN: -o %t/mod.pcm
+// RUN: %clang %t/mod.pcm -c -o %t/mod.o
+// RUN: %clang -shared %t/mod.o -o %t/libmod.so
+//
+// RUN: cat %t/import.cpp | env LD_LIBRARY_PATH=%t:$LD_LIBRARY_PATH \
+// RUN: clang-repl -Xcc=-std=c++20 -Xcc=-fmodule-file=M=%t/mod.pcm \
+// RUN: | FileCheck %t/import.cpp
+
+//--- mod.cppm
+export module M;
+export const char* Hello() {
+return "Hello Interpreter for Modules!";
+}
+
+//--- import.cpp
+
+%lib libmod.so
+
+import M;
+
+extern "C" int printf(const char *, ...);
+printf("%s\n", Hello());
+
+// CHECK: Hello Interpreter for Modules!

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


[clang] [Driver,CodeGen] Support -mtls-dialect= (PR #79256)

2024-01-23 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay updated 
https://github.com/llvm/llvm-project/pull/79256

>From be08e64c2c1f433b017185ce78525ad097e609be Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Tue, 23 Jan 2024 21:37:04 -0800
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 clang/include/clang/Basic/CodeGenOptions.def |  3 +++
 clang/include/clang/Driver/Options.td|  5 +
 clang/lib/CodeGen/BackendUtil.cpp|  1 +
 clang/lib/Driver/ToolChains/Clang.cpp| 23 
 clang/test/CodeGen/RISCV/tls-dialect.c   | 13 +++
 clang/test/Driver/tls-dialect.c  | 19 
 6 files changed, 64 insertions(+)
 create mode 100644 clang/test/CodeGen/RISCV/tls-dialect.c
 create mode 100644 clang/test/Driver/tls-dialect.c

diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 2f2e45d5cf63dfa..7c0bfe328496147 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -369,6 +369,9 @@ ENUM_CODEGENOPT(VecLib, llvm::driver::VectorLibrary, 3, 
llvm::driver::VectorLibr
 /// The default TLS model to use.
 ENUM_CODEGENOPT(DefaultTLSModel, TLSModel, 2, GeneralDynamicTLSModel)
 
+/// Whether to enable TLSDESC. AArch64 enables TLSDESC regardless of this 
value.
+CODEGENOPT(EnableTLSDESC, 1, 0)
+
 /// Bit size of immediate TLS offsets (0 == use the default).
 VALUE_CODEGENOPT(TLSSize, 8, 0)
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7f4fa33748facaf..773bc1dcda01d5c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4419,6 +4419,8 @@ def mtls_size_EQ : Joined<["-"], "mtls-size=">, 
Group,
   HelpText<"Specify bit size of immediate TLS offsets (AArch64 ELF only): "
"12 (for 4KB) | 24 (for 16MB, default) | 32 (for 4GB) | 48 (for 
256TB, needs -mcmodel=large)">,
   MarshallingInfoInt>;
+def mtls_dialect_EQ : Joined<["-"], "mtls-dialect=">, Group,
+  Flags<[TargetSpecific]>, HelpText<"Which thread-local storage dialect to use 
for dynamic accesses of TLS variables">;
 def mimplicit_it_EQ : Joined<["-"], "mimplicit-it=">, Group;
 def mdefault_build_attributes : Joined<["-"], "mdefault-build-attributes">, 
Group;
 def mno_default_build_attributes : Joined<["-"], 
"mno-default-build-attributes">, Group;
@@ -7066,6 +7068,9 @@ def fexperimental_assignment_tracking_EQ : Joined<["-"], 
"fexperimental-assignme
   Values<"disabled,enabled,forced">, 
NormalizedValues<["Disabled","Enabled","Forced"]>,
   MarshallingInfoEnum, "Enabled">;
 
+def enable_tlsdesc : Flag<["-"], "enable-tlsdesc">,
+  MarshallingInfoFlag>;
+
 } // let Visibility = [CC1Option]
 
 
//===--===//
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index ec203f6f28bc173..7877e20d77f7724 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -401,6 +401,7 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
   Options.UniqueBasicBlockSectionNames =
   CodeGenOpts.UniqueBasicBlockSectionNames;
   Options.TLSSize = CodeGenOpts.TLSSize;
+  Options.EnableTLSDESC = CodeGenOpts.EnableTLSDESC;
   Options.EmulatedTLS = CodeGenOpts.EmulatedTLS;
   Options.DebuggerTuning = CodeGenOpts.getDebuggerTuning();
   Options.EmitStackSizeSection = CodeGenOpts.StackSizeSection;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 5dc614e11aab599..93fd579eb92ba50 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5822,6 +5822,29 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 Args.AddLastArg(CmdArgs, options::OPT_mtls_size_EQ);
   }
 
+  if (Arg *A = Args.getLastArg(options::OPT_mtls_dialect_EQ)) {
+StringRef V = A->getValue();
+bool SupportedArgument = false, EnableTLSDESC = false;
+bool Unsupported = !Triple.isOSBinFormatELF();
+if (Triple.isRISCV()) {
+  SupportedArgument = V == "desc" || V == "trad";
+  EnableTLSDESC = V == "desc";
+} else if (Triple.isX86()) {
+  SupportedArgument = V == "gnu";
+} else {
+  Unsupported = true;
+}
+if (Unsupported) {
+  D.Diag(diag::err_drv_unsupported_opt_for_target)
+  << A->getSpelling() << TripleStr;
+} else if (!SupportedArgument) {
+  D.Diag(diag::err_drv_unsupported_option_argument_for_target)
+  << A->getSpelling() << V << TripleStr;
+} else if (EnableTLSDESC) {
+  CmdArgs.push_back("-enable-tlsdesc");
+}
+  }
+
   // Add the target cpu
   std::string CPU = getCPUName(D, Args, Triple, /*FromAs*/ false);
   if (!CPU.empty()) {
diff --git a/clang/test/CodeG

[clang] [clang][driver] Add -mtls-dialect option (PR #79031)

2024-01-23 Thread Fangrui Song via cfe-commits

MaskRay wrote:

Since TLSDialect only has 2 values and it's unlikely a future change will add 
new, I think sticking with a boolean codegenopt suffices.
For x86, we can probably support "gnu" as "gnu2" (TLSDESC) is a desired 
feature. (I added lld support, but I did not know codegen well enough to add 
LLVM part...)

I think #79256 is a more complete patch, with these ideas taken into account..
It may be a good candidate for the `release/18.x` branch.

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


[clang] [Driver,CodeGen] Support -mtls-dialect= (PR #79256)

2024-01-23 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-clang

Author: Fangrui Song (MaskRay)


Changes

GCC supports -mtls-dialect= for several architectures to select TLSDESC.
This patch supports the following values

* x86: "gnu". "gnu2" (TLSDESC) is not supported yet.
* RISC-V: "trad" (general dynamic), "desc" (TLSDESC, see #66915)

AArch64 toolchains seem to support TLSDESC from the beginning, and the
general dynamic model has poor support. Nobody seems to use the option
-mtls-dialect= at all, so we don't bother with it.
There also seems very little interest in AArch32's TLSDESC support.

Co-authored-by: Paul Kirth 


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


6 Files Affected:

- (modified) clang/include/clang/Basic/CodeGenOptions.def (+3) 
- (modified) clang/include/clang/Driver/Options.td (+5) 
- (modified) clang/lib/CodeGen/BackendUtil.cpp (+1) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+23) 
- (added) clang/test/CodeGen/RISCV/tls-dialect.c (+13) 
- (added) clang/test/Driver/tls-dialect.c (+19) 


``diff
diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 2f2e45d5cf63dfa..7c0bfe328496147 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -369,6 +369,9 @@ ENUM_CODEGENOPT(VecLib, llvm::driver::VectorLibrary, 3, 
llvm::driver::VectorLibr
 /// The default TLS model to use.
 ENUM_CODEGENOPT(DefaultTLSModel, TLSModel, 2, GeneralDynamicTLSModel)
 
+/// Whether to enable TLSDESC. AArch64 enables TLSDESC regardless of this 
value.
+CODEGENOPT(EnableTLSDESC, 1, 0)
+
 /// Bit size of immediate TLS offsets (0 == use the default).
 VALUE_CODEGENOPT(TLSSize, 8, 0)
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7f4fa33748facaf..773bc1dcda01d5c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4419,6 +4419,8 @@ def mtls_size_EQ : Joined<["-"], "mtls-size=">, 
Group,
   HelpText<"Specify bit size of immediate TLS offsets (AArch64 ELF only): "
"12 (for 4KB) | 24 (for 16MB, default) | 32 (for 4GB) | 48 (for 
256TB, needs -mcmodel=large)">,
   MarshallingInfoInt>;
+def mtls_dialect_EQ : Joined<["-"], "mtls-dialect=">, Group,
+  Flags<[TargetSpecific]>, HelpText<"Which thread-local storage dialect to use 
for dynamic accesses of TLS variables">;
 def mimplicit_it_EQ : Joined<["-"], "mimplicit-it=">, Group;
 def mdefault_build_attributes : Joined<["-"], "mdefault-build-attributes">, 
Group;
 def mno_default_build_attributes : Joined<["-"], 
"mno-default-build-attributes">, Group;
@@ -7066,6 +7068,9 @@ def fexperimental_assignment_tracking_EQ : Joined<["-"], 
"fexperimental-assignme
   Values<"disabled,enabled,forced">, 
NormalizedValues<["Disabled","Enabled","Forced"]>,
   MarshallingInfoEnum, "Enabled">;
 
+def enable_tlsdesc : Flag<["-"], "enable-tlsdesc">,
+  MarshallingInfoFlag>;
+
 } // let Visibility = [CC1Option]
 
 
//===--===//
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index ec203f6f28bc173..7877e20d77f7724 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -401,6 +401,7 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
   Options.UniqueBasicBlockSectionNames =
   CodeGenOpts.UniqueBasicBlockSectionNames;
   Options.TLSSize = CodeGenOpts.TLSSize;
+  Options.EnableTLSDESC = CodeGenOpts.EnableTLSDESC;
   Options.EmulatedTLS = CodeGenOpts.EmulatedTLS;
   Options.DebuggerTuning = CodeGenOpts.getDebuggerTuning();
   Options.EmitStackSizeSection = CodeGenOpts.StackSizeSection;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 5dc614e11aab599..93fd579eb92ba50 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5822,6 +5822,29 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 Args.AddLastArg(CmdArgs, options::OPT_mtls_size_EQ);
   }
 
+  if (Arg *A = Args.getLastArg(options::OPT_mtls_dialect_EQ)) {
+StringRef V = A->getValue();
+bool SupportedArgument = false, EnableTLSDESC = false;
+bool Unsupported = !Triple.isOSBinFormatELF();
+if (Triple.isRISCV()) {
+  SupportedArgument = V == "desc" || V == "trad";
+  EnableTLSDESC = V == "desc";
+} else if (Triple.isX86()) {
+  SupportedArgument = V == "gnu";
+} else {
+  Unsupported = true;
+}
+if (Unsupported) {
+  D.Diag(diag::err_drv_unsupported_opt_for_target)
+  << A->getSpelling() << TripleStr;
+} else if (!SupportedArgument) {
+  D.Diag(diag::err_drv_unsupported_option_argument_for_target)
+  << A->getSpelling() << V << TripleStr;
+} else if (EnableTLSDESC) {
+  CmdArgs.push_back("-enable-tlsdesc");

[clang] [Driver,CodeGen] Support -mtls-dialect= (PR #79256)

2024-01-23 Thread Fangrui Song via cfe-commits

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

GCC supports -mtls-dialect= for several architectures to select TLSDESC.
This patch supports the following values

* x86: "gnu". "gnu2" (TLSDESC) is not supported yet.
* RISC-V: "trad" (general dynamic), "desc" (TLSDESC, see #66915)

AArch64 toolchains seem to support TLSDESC from the beginning, and the
general dynamic model has poor support. Nobody seems to use the option
-mtls-dialect= at all, so we don't bother with it.
There also seems very little interest in AArch32's TLSDESC support.

Co-authored-by: Paul Kirth 


>From be08e64c2c1f433b017185ce78525ad097e609be Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Tue, 23 Jan 2024 21:37:04 -0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 clang/include/clang/Basic/CodeGenOptions.def |  3 +++
 clang/include/clang/Driver/Options.td|  5 +
 clang/lib/CodeGen/BackendUtil.cpp|  1 +
 clang/lib/Driver/ToolChains/Clang.cpp| 23 
 clang/test/CodeGen/RISCV/tls-dialect.c   | 13 +++
 clang/test/Driver/tls-dialect.c  | 19 
 6 files changed, 64 insertions(+)
 create mode 100644 clang/test/CodeGen/RISCV/tls-dialect.c
 create mode 100644 clang/test/Driver/tls-dialect.c

diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 2f2e45d5cf63dfa..7c0bfe328496147 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -369,6 +369,9 @@ ENUM_CODEGENOPT(VecLib, llvm::driver::VectorLibrary, 3, 
llvm::driver::VectorLibr
 /// The default TLS model to use.
 ENUM_CODEGENOPT(DefaultTLSModel, TLSModel, 2, GeneralDynamicTLSModel)
 
+/// Whether to enable TLSDESC. AArch64 enables TLSDESC regardless of this 
value.
+CODEGENOPT(EnableTLSDESC, 1, 0)
+
 /// Bit size of immediate TLS offsets (0 == use the default).
 VALUE_CODEGENOPT(TLSSize, 8, 0)
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7f4fa33748facaf..773bc1dcda01d5c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4419,6 +4419,8 @@ def mtls_size_EQ : Joined<["-"], "mtls-size=">, 
Group,
   HelpText<"Specify bit size of immediate TLS offsets (AArch64 ELF only): "
"12 (for 4KB) | 24 (for 16MB, default) | 32 (for 4GB) | 48 (for 
256TB, needs -mcmodel=large)">,
   MarshallingInfoInt>;
+def mtls_dialect_EQ : Joined<["-"], "mtls-dialect=">, Group,
+  Flags<[TargetSpecific]>, HelpText<"Which thread-local storage dialect to use 
for dynamic accesses of TLS variables">;
 def mimplicit_it_EQ : Joined<["-"], "mimplicit-it=">, Group;
 def mdefault_build_attributes : Joined<["-"], "mdefault-build-attributes">, 
Group;
 def mno_default_build_attributes : Joined<["-"], 
"mno-default-build-attributes">, Group;
@@ -7066,6 +7068,9 @@ def fexperimental_assignment_tracking_EQ : Joined<["-"], 
"fexperimental-assignme
   Values<"disabled,enabled,forced">, 
NormalizedValues<["Disabled","Enabled","Forced"]>,
   MarshallingInfoEnum, "Enabled">;
 
+def enable_tlsdesc : Flag<["-"], "enable-tlsdesc">,
+  MarshallingInfoFlag>;
+
 } // let Visibility = [CC1Option]
 
 
//===--===//
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index ec203f6f28bc173..7877e20d77f7724 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -401,6 +401,7 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
   Options.UniqueBasicBlockSectionNames =
   CodeGenOpts.UniqueBasicBlockSectionNames;
   Options.TLSSize = CodeGenOpts.TLSSize;
+  Options.EnableTLSDESC = CodeGenOpts.EnableTLSDESC;
   Options.EmulatedTLS = CodeGenOpts.EmulatedTLS;
   Options.DebuggerTuning = CodeGenOpts.getDebuggerTuning();
   Options.EmitStackSizeSection = CodeGenOpts.StackSizeSection;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 5dc614e11aab599..93fd579eb92ba50 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5822,6 +5822,29 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 Args.AddLastArg(CmdArgs, options::OPT_mtls_size_EQ);
   }
 
+  if (Arg *A = Args.getLastArg(options::OPT_mtls_dialect_EQ)) {
+StringRef V = A->getValue();
+bool SupportedArgument = false, EnableTLSDESC = false;
+bool Unsupported = !Triple.isOSBinFormatELF();
+if (Triple.isRISCV()) {
+  SupportedArgument = V == "desc" || V == "trad";
+  EnableTLSDESC = V == "desc";
+} else if (Triple.isX86()) {
+  SupportedArgument = V == "gnu";
+} else {
+  Unsupported = true;
+  

[clang] [LoongArch] Check lsx/lasx features when running builtin tests (PR #79250)

2024-01-23 Thread via cfe-commits

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


[clang] [clang] Make sure the same UsingType is searched and inserted (PR #79182)

2024-01-23 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

> Wonder what test should I add here. This only affects the content of the 
> internal folding set so we always create new types but result is still 
> correct.

One possibility is doing an AST test, there are some examples in there that 
show how you can test two different AST nodes have the same address.

The best here would be some kind of performance regression test. We don't have 
anything like that per-se in the test suite unfortunately.
But if you can isolate a good test case, you can make it a normal regression 
test, which with the fix is still within CI limits of time and space, but which 
pushes much farther out without the fix. This would not be without precedent, 
there already exists tests like that.

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


[clang] [LoongArch][test] Add tests reporting error if lsx/lasx feature is missing when lsx/lasx builtins are called (PR #79250)

2024-01-23 Thread Lu Weining via cfe-commits

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


[clang] 4c3de45 - [LoongArch][test] Add tests reporting error if lsx/lasx feature is missing when lsx/lasx builtins are called (#79250)

2024-01-23 Thread via cfe-commits

Author: leecheechen
Date: 2024-01-24T13:19:19+08:00
New Revision: 4c3de45ecf9eea6b4ad850a042706f7865a2aab2

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

LOG: [LoongArch][test] Add tests reporting error if lsx/lasx feature is missing 
when lsx/lasx builtins are called (#79250)

Added: 


Modified: 
clang/test/CodeGen/LoongArch/lasx/builtin-error.c
clang/test/CodeGen/LoongArch/lsx/builtin-error.c

Removed: 




diff  --git a/clang/test/CodeGen/LoongArch/lasx/builtin-error.c 
b/clang/test/CodeGen/LoongArch/lasx/builtin-error.c
index 724484465769e0e..dabf34368ea3e13 100644
--- a/clang/test/CodeGen/LoongArch/lasx/builtin-error.c
+++ b/clang/test/CodeGen/LoongArch/lasx/builtin-error.c
@@ -1,4 +1,6 @@
 // RUN: %clang_cc1 -triple loongarch64 -target-feature +lasx -verify %s
+// RUN: not %clang_cc1 -triple loongarch64 -DFEATURE_CHECK -emit-llvm %s -o 
/dev/null 2>&1 \
+// RUN:   | FileCheck %s
 
 typedef signed char v32i8 __attribute__((vector_size(32), aligned(32)));
 typedef signed char v32i8_b __attribute__((vector_size(32), aligned(1)));
@@ -21,6 +23,13 @@ typedef float v8f32_w __attribute__((vector_size(32), 
aligned(4)));
 typedef double v4f64 __attribute__((vector_size(32), aligned(32)));
 typedef double v4f64_d __attribute__((vector_size(32), aligned(8)));
 
+#ifdef FEATURE_CHECK
+void test_feature(v32i8 _1) {
+// CHECK: error: '__builtin_lasx_xvslli_b' needs target feature lasx
+  (void)__builtin_lasx_xvslli_b(_1, 1);
+}
+#endif
+
 v32i8 xvslli_b(v32i8 _1, int var) {
   v32i8 res = __builtin_lasx_xvslli_b(_1, -1); // expected-error {{argument 
value 4294967295 is outside the valid range [0, 7]}}
   res |= __builtin_lasx_xvslli_b(_1, 8); // expected-error {{argument value 8 
is outside the valid range [0, 7]}}

diff  --git a/clang/test/CodeGen/LoongArch/lsx/builtin-error.c 
b/clang/test/CodeGen/LoongArch/lsx/builtin-error.c
index 3fc5f73f11934e6..722ba7fe8cd20e4 100644
--- a/clang/test/CodeGen/LoongArch/lsx/builtin-error.c
+++ b/clang/test/CodeGen/LoongArch/lsx/builtin-error.c
@@ -1,4 +1,6 @@
 // RUN: %clang_cc1 -triple loongarch64 -target-feature +lsx -verify %s
+// RUN: not %clang_cc1 -triple loongarch64 -DFEATURE_CHECK -emit-llvm %s -o 
/dev/null 2>&1 \
+// RUN:   | FileCheck %s
 
 typedef signed char v16i8 __attribute__((vector_size(16), aligned(16)));
 typedef signed char v16i8_b __attribute__((vector_size(16), aligned(1)));
@@ -25,6 +27,13 @@ typedef long long __m128i 
__attribute__((__vector_size__(16), __may_alias__));
 typedef float __m128 __attribute__((__vector_size__(16), __may_alias__));
 typedef double __m128d __attribute__((__vector_size__(16), __may_alias__));
 
+#ifdef FEATURE_CHECK
+void test_feature(v16i8 _1) {
+// CHECK: error: '__builtin_lsx_vslli_b' needs target feature lsx
+  (void)__builtin_lsx_vslli_b(_1, 1);
+}
+#endif
+
 v16i8 vslli_b(v16i8 _1, int var) {
   v16i8 res = __builtin_lsx_vslli_b(_1, -1); // expected-error {{argument 
value 4294967295 is outside the valid range [0, 7]}}
   res |= __builtin_lsx_vslli_b(_1, 8); // expected-error {{argument value 8 is 
outside the valid range [0, 7]}}



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


[clang] [LoongArch][test] Add tests reporting error if lsx/lasx feature is missing when lsx/lasx builtins are called (PR #79250)

2024-01-23 Thread Lu Weining via cfe-commits

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


[clang] Check lsx/lasx features when running builtin tests (PR #79250)

2024-01-23 Thread Lu Weining via cfe-commits

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


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


[clang] [llvm] [CMake][PGO] Add option for using an external project to generate profile data (PR #78879)

2024-01-23 Thread Tom Stellard via cfe-commits

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


[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)

2024-01-23 Thread via cfe-commits

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


[libc] [clang] [openmp] [lld] [clang-tools-extra] [lldb] [libcxx] [compiler-rt] [mlir] [llvm] [pstl] [Driver] Test ignored target-specific options for AMDGPU/NVPTX (PR #79222)

2024-01-23 Thread Joseph Huber via cfe-commits

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


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


[llvm] [clang] [AIX][TLS] Disallow the use of -maix-small-local-exec-tls and -fno-data-sections (PR #79252)

2024-01-23 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: Amy Kwan (amy-kwan)


Changes



This patch disallows the use of the -maix-small-local-exec-tls and 
-fno-data-sections options within clang, and also disallows the use of the 
aix-small-local-exec-tls attribute with the -data-sections=false option in llc.

This is because having data sections off when using the 
aix-small-local-exec-tls feature is not ideal for performance. As the 
small-local-exec-tls region is a limited resource, this space should not used 
for variables that may be replaced.

Note, that on AIX, data sections is turned on by default, so this patch makes 
it so that a diagnostic is emitted when users explicitly turn off data sections 
while using the aix-small-local-exec-tls feature.

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


5 Files Affected:

- (modified) clang/lib/Basic/Targets/PPC.cpp (-8) 
- (modified) clang/lib/Driver/ToolChains/Arch/PPC.cpp (+19) 
- (modified) clang/test/Driver/aix-small-local-exec-tls.c (+7) 
- (modified) llvm/lib/Target/PowerPC/PPCSubtarget.cpp (+17-4) 
- (modified) 
llvm/test/CodeGen/PowerPC/check-aix-small-local-exec-tls-opt-IRattribute.ll 
(+7) 


``diff
diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 41935abfb65d3b9..911b80c98f7ad62 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -646,14 +646,6 @@ bool PPCTargetInfo::initFeatureMap(
 return false;
   }
 
-  if (llvm::is_contained(FeaturesVec, "+aix-small-local-exec-tls")) {
-if (!getTriple().isOSAIX() || !getTriple().isArch64Bit()) {
-  Diags.Report(diag::err_opt_not_valid_on_target)
- << "-maix-small-local-exec-tls";
-  return false;
-}
-  }
-
   return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
 }
 
diff --git a/clang/lib/Driver/ToolChains/Arch/PPC.cpp 
b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
index ab24d14992cd7a1..5ffe73236205d3b 100644
--- a/clang/lib/Driver/ToolChains/Arch/PPC.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
@@ -122,6 +122,25 @@ void ppc::getPPCTargetFeatures(const Driver &D, const 
llvm::Triple &Triple,
   ppc::ReadGOTPtrMode ReadGOT = ppc::getPPCReadGOTPtrMode(D, Triple, Args);
   if (ReadGOT == ppc::ReadGOTPtrMode::SecurePlt)
 Features.push_back("+secure-plt");
+
+  bool UseSeparateSections = isUseSeparateSections(Triple);
+  bool HasDefaultDataSections = Triple.isOSBinFormatXCOFF();
+  if (Args.hasArg(options::OPT_maix_small_local_exec_tls)) {
+if (!Triple.isOSAIX() || !Triple.isArch64Bit())
+  D.Diag(diag::err_opt_not_valid_on_target) << 
"-maix-small-local-exec-tls";
+
+// The -maix-small-local-exec-tls option should only be used with
+// -fdata-sections, as having data sections turned off with this option
+// is not ideal for performance. Moreover, the small-local-exec-tls region
+// is a limited resource, and should not be used for variables that may
+// be replaced.
+if (!Args.hasFlag(options::OPT_fdata_sections,
+  options::OPT_fno_data_sections,
+  UseSeparateSections || HasDefaultDataSections))
+  D.Diag(diag::err_drv_argument_only_allowed_with)
+  << "-maix-small-local-exec-tls"
+  << "-fdata-sections";
+  }
 }
 
 ppc::ReadGOTPtrMode ppc::getPPCReadGOTPtrMode(const Driver &D, const 
llvm::Triple &Triple,
diff --git a/clang/test/Driver/aix-small-local-exec-tls.c 
b/clang/test/Driver/aix-small-local-exec-tls.c
index 7a2eec6989eef89..e6719502a3babc3 100644
--- a/clang/test/Driver/aix-small-local-exec-tls.c
+++ b/clang/test/Driver/aix-small-local-exec-tls.c
@@ -12,6 +12,12 @@
 // RUN:-fsyntax-only %s 2>&1 | FileCheck 
--check-prefix=CHECK-UNSUPPORTED-LINUX %s
 // RUN: not %clang -target powerpc64-unknown-linux-gnu 
-maix-small-local-exec-tls \
 // RUN:-fsyntax-only %s 2>&1 | FileCheck 
--check-prefix=CHECK-UNSUPPORTED-LINUX %s
+// RUN: not %clang -target powerpc64-unknown-aix -maix-small-local-exec-tls \
+// RUN:-fsyntax-only -fno-data-sections %s 2>&1 | \
+// RUN:FileCheck --check-prefix=CHECK-UNSUPPORTED-NO-DATASEC %s
+// RUN: not %clang -target powerpc64-unknown-linux-gnu 
-maix-small-local-exec-tls \
+// RUN:-fsyntax-only -fno-data-sections %s 2>&1 | \
+// RUN:FileCheck --check-prefix=CHECK-UNSUPPORTED-NO-DATASEC %s
 
 int test(void) {
   return 0;
@@ -23,6 +29,7 @@ int test(void) {
 
 // CHECK-UNSUPPORTED-AIX32: option '-maix-small-local-exec-tls' cannot be 
specified on this target
 // CHECK-UNSUPPORTED-LINUX: option '-maix-small-local-exec-tls' cannot be 
specified on this target
+// CHECK-UNSUPPORTED-NO-DATASEC: invalid argument '-maix-small-local-exec-tls' 
only allowed with '-fdata-sections'
 
 // CHECK-AIX_SMALL_LOCALEXEC_TLS: test() #0 {
 // CHECK-AIX_SMALL_LOCALEXEC_TLS: attributes #0 = {
diff --git a/llvm/lib/Target/PowerPC/PPCSubtarget.cpp 
b/llvm/lib/Target/PowerPC/PPCSubtarget.cpp
index c974081

[clang] [llvm] [AIX][TLS] Disallow the use of -maix-small-local-exec-tls and -fno-data-sections (PR #79252)

2024-01-23 Thread Amy Kwan via cfe-commits

https://github.com/amy-kwan created 
https://github.com/llvm/llvm-project/pull/79252



This patch disallows the use of the -maix-small-local-exec-tls and 
-fno-data-sections options within clang, and also disallows the use of the 
aix-small-local-exec-tls attribute with the -data-sections=false option in llc.

This is because having data sections off when using the 
aix-small-local-exec-tls feature is not ideal for performance. As the 
small-local-exec-tls region is a limited resource, this space should not used 
for variables that may be replaced.

Note, that on AIX, data sections is turned on by default, so this patch makes 
it so that a diagnostic is emitted when users explicitly turn off data sections 
while using the aix-small-local-exec-tls feature.

>From c6fb2a4e1bc329bbebe930feebf462fa0d502df0 Mon Sep 17 00:00:00 2001
From: Amy Kwan 
Date: Tue, 23 Jan 2024 22:19:49 -0600
Subject: [PATCH] [AIX][TLS] Disallow the use of -maix-small-local-exec-tls and
 -fno-data-sections

This patch disallows the use of the -maix-small-local-exec-tls and
-fno-data-sections options within clang, and also disallows the use of the
aix-small-local-exec-tls attribute with the -data-sections=false option in llc.

This is because having data sections off when using the aix-small-local-exec-tls
feature is not ideal for performance. As the small-local-exec-tls region is a
limited resource, this space should not used for variables that may be replaced.

Note, that on AIX, data sections is turned on by default, so this patch makes it
so that a diagnostic is emitted when users explicitly turn off data sections
while using the aix-small-local-exec-tls feature.
---
 clang/lib/Basic/Targets/PPC.cpp   |  8 ---
 clang/lib/Driver/ToolChains/Arch/PPC.cpp  | 19 +
 clang/test/Driver/aix-small-local-exec-tls.c  |  7 +++
 llvm/lib/Target/PowerPC/PPCSubtarget.cpp  | 21 +++
 ...ix-small-local-exec-tls-opt-IRattribute.ll |  7 +++
 5 files changed, 50 insertions(+), 12 deletions(-)

diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 41935abfb65d3b9..911b80c98f7ad62 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -646,14 +646,6 @@ bool PPCTargetInfo::initFeatureMap(
 return false;
   }
 
-  if (llvm::is_contained(FeaturesVec, "+aix-small-local-exec-tls")) {
-if (!getTriple().isOSAIX() || !getTriple().isArch64Bit()) {
-  Diags.Report(diag::err_opt_not_valid_on_target)
- << "-maix-small-local-exec-tls";
-  return false;
-}
-  }
-
   return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
 }
 
diff --git a/clang/lib/Driver/ToolChains/Arch/PPC.cpp 
b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
index ab24d14992cd7a1..5ffe73236205d3b 100644
--- a/clang/lib/Driver/ToolChains/Arch/PPC.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
@@ -122,6 +122,25 @@ void ppc::getPPCTargetFeatures(const Driver &D, const 
llvm::Triple &Triple,
   ppc::ReadGOTPtrMode ReadGOT = ppc::getPPCReadGOTPtrMode(D, Triple, Args);
   if (ReadGOT == ppc::ReadGOTPtrMode::SecurePlt)
 Features.push_back("+secure-plt");
+
+  bool UseSeparateSections = isUseSeparateSections(Triple);
+  bool HasDefaultDataSections = Triple.isOSBinFormatXCOFF();
+  if (Args.hasArg(options::OPT_maix_small_local_exec_tls)) {
+if (!Triple.isOSAIX() || !Triple.isArch64Bit())
+  D.Diag(diag::err_opt_not_valid_on_target) << 
"-maix-small-local-exec-tls";
+
+// The -maix-small-local-exec-tls option should only be used with
+// -fdata-sections, as having data sections turned off with this option
+// is not ideal for performance. Moreover, the small-local-exec-tls region
+// is a limited resource, and should not be used for variables that may
+// be replaced.
+if (!Args.hasFlag(options::OPT_fdata_sections,
+  options::OPT_fno_data_sections,
+  UseSeparateSections || HasDefaultDataSections))
+  D.Diag(diag::err_drv_argument_only_allowed_with)
+  << "-maix-small-local-exec-tls"
+  << "-fdata-sections";
+  }
 }
 
 ppc::ReadGOTPtrMode ppc::getPPCReadGOTPtrMode(const Driver &D, const 
llvm::Triple &Triple,
diff --git a/clang/test/Driver/aix-small-local-exec-tls.c 
b/clang/test/Driver/aix-small-local-exec-tls.c
index 7a2eec6989eef89..e6719502a3babc3 100644
--- a/clang/test/Driver/aix-small-local-exec-tls.c
+++ b/clang/test/Driver/aix-small-local-exec-tls.c
@@ -12,6 +12,12 @@
 // RUN:-fsyntax-only %s 2>&1 | FileCheck 
--check-prefix=CHECK-UNSUPPORTED-LINUX %s
 // RUN: not %clang -target powerpc64-unknown-linux-gnu 
-maix-small-local-exec-tls \
 // RUN:-fsyntax-only %s 2>&1 | FileCheck 
--check-prefix=CHECK-UNSUPPORTED-LINUX %s
+// RUN: not %clang -target powerpc64-unknown-aix -maix-small-local-exec-tls \
+// RUN:-fsyntax-only -fno-data-sections %s 2>&1 | \
+// RUN:FileCheck --check-prefix=CHECK-UNSUPPORTED-NO-DATASEC %s
+// RUN: not 

[clang] [Docs] Mention RISC-V in the introductory paragraph in ShadowCallStack.rst. (PR #79241)

2024-01-23 Thread Paul Kirth via cfe-commits

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

LGTM 

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


[lldb] [clang] [clang-tools-extra] [openmp] [lld] [libc] [libcxx] [mlir] [pstl] [compiler-rt] [llvm] [Driver] Test ignored target-specific options for AMDGPU/NVPTX (PR #79222)

2024-01-23 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,7 @@
+/// Some target-specific options are ignored for GPU, so %clang exits with 
code 0.
+// DEFINE: %{gpu_opts} = --cuda-gpu-arch=sm_60 
--cuda-path=%S/Inputs/CUDA/usr/local/cuda --no-cuda-version-check
+// DEFINE: %{check} = %clang -### -c %{gpu_opts} -mcmodel=medium %s
+// RUN: %{check} -fbasic-block-sections=all
+
+// REDEFINE: %{gpu_opts} = -x hip --rocm-path=%S/Inputs/rocm -nogpulib

MaskRay wrote:

Added!

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


[libcxx] [clang] [openmp] [lldb] [lld] [compiler-rt] [clang-tools-extra] [pstl] [mlir] [llvm] [libc] [Driver] Test ignored target-specific options for AMDGPU/NVPTX (PR #79222)

2024-01-23 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay updated 
https://github.com/llvm/llvm-project/pull/79222

>From 3a2b2a1110e7b3348a12a6476ab014a469891062 Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Tue, 23 Jan 2024 15:13:49 -0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 clang/test/Driver/unsupported-option-gpu.c | 7 +++
 1 file changed, 7 insertions(+)
 create mode 100644 clang/test/Driver/unsupported-option-gpu.c

diff --git a/clang/test/Driver/unsupported-option-gpu.c 
b/clang/test/Driver/unsupported-option-gpu.c
new file mode 100644
index 00..5713dbbfc7ae4d
--- /dev/null
+++ b/clang/test/Driver/unsupported-option-gpu.c
@@ -0,0 +1,7 @@
+/// Some target-specific options are ignored for GPU, so %clang exits with 
code 0.
+// DEFINE: %{gpu_opts} = --cuda-gpu-arch=sm_60 
--cuda-path=%S/Inputs/CUDA/usr/local/cuda --no-cuda-version-check
+// DEFINE: %{check} = %clang -### -c %{gpu_opts} -mcmodel=medium %s
+// RUN: %{check} -fbasic-block-sections=all
+
+// REDEFINE: %{gpu_opts} = -x hip --rocm-path=%S/Inputs/rocm -nogpulib
+// RUN: %{check}

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


[clang] [clang] Make sure the same UsingType is searched and inserted (PR #79182)

2024-01-23 Thread Wei Wang via cfe-commits

apolloww wrote:

> The change is correct. The problem is subtle though. It comes from the 
> difference in behavior between the member and non-member Profile functions.
> 
> I think we could do better instead with a change which makes it harder to 
> trip on this.
> 
> I think a simplification like this should work (untested):
> 
> ```
> diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
> index ea425791fc97..3d411051084c 100644
> --- a/clang/include/clang/AST/Type.h
> +++ b/clang/include/clang/AST/Type.h
> @@ -4729,13 +4729,12 @@ public:
>bool typeMatchesDecl() const { return !UsingBits.hasTypeDifferentFromDecl; 
> }
> 
>void Profile(llvm::FoldingSetNodeID &ID) {
> -Profile(ID, Found, typeMatchesDecl() ? QualType() : getUnderlyingType());
> +Profile(ID, Found, getUnderlyingType());
>}
>static void Profile(llvm::FoldingSetNodeID &ID, const UsingShadowDecl 
> *Found,
>QualType Underlying) {
>  ID.AddPointer(Found);
> -if (!Underlying.isNull())
> -  Underlying.Profile(ID);
> +Underlying.Profile(ID);
>}
>static bool classof(const Type *T) { return T->getTypeClass() == Using; }
>  };
> ```

Thanks. This works and looks better. 

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


[clang] Check lsx/lasx features when running builtin tests (PR #79250)

2024-01-23 Thread via cfe-commits

leecheechen wrote:

cc @SixWeining 

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


[clang] [clang] Make sure the same UsingType is searched and inserted (PR #79182)

2024-01-23 Thread Wei Wang via cfe-commits

https://github.com/apolloww updated 
https://github.com/llvm/llvm-project/pull/79182

>From a542d63f472d799eb2d041c82cac402cfb8dec1a Mon Sep 17 00:00:00 2001
From: Wei Wang 
Date: Tue, 23 Jan 2024 10:01:57 -0800
Subject: [PATCH 1/2] [clang] Make sure the same UsingType is searched and
 inserted

---
 clang/lib/AST/ASTContext.cpp | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 5eb7aa3664569dd..d312ef61fb15d4a 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -4672,12 +4672,6 @@ QualType ASTContext::getTypedefType(const 
TypedefNameDecl *Decl,
 QualType ASTContext::getUsingType(const UsingShadowDecl *Found,
   QualType Underlying) const {
   llvm::FoldingSetNodeID ID;
-  UsingType::Profile(ID, Found, Underlying);
-
-  void *InsertPos = nullptr;
-  if (UsingType *T = UsingTypes.FindNodeOrInsertPos(ID, InsertPos))
-return QualType(T, 0);
-
   const Type *TypeForDecl =
   cast(Found->getTargetDecl())->getTypeForDecl();
 
@@ -4687,6 +4681,13 @@ QualType ASTContext::getUsingType(const UsingShadowDecl 
*Found,
 
   if (Underlying.getTypePtr() == TypeForDecl)
 Underlying = QualType();
+  UsingType::Profile(ID, Found, Underlying);
+
+  void *InsertPos = nullptr;
+  if (UsingType *T = UsingTypes.FindNodeOrInsertPos(ID, InsertPos)) {
+return QualType(T, 0);
+  }
+
   void *Mem =
   Allocate(UsingType::totalSizeToAlloc(!Underlying.isNull()),
alignof(UsingType));

>From 6dba099a2e1f06feb65248678a57bd00a3d4d0ae Mon Sep 17 00:00:00 2001
From: Wei Wang 
Date: Tue, 23 Jan 2024 19:58:24 -0800
Subject: [PATCH 2/2] update UsingType profile implementation

---
 clang/include/clang/AST/Type.h |  5 ++---
 clang/lib/AST/ASTContext.cpp   | 13 ++---
 2 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index ea425791fc97f05..3d411051084c71b 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -4729,13 +4729,12 @@ class UsingType final : public Type,
   bool typeMatchesDecl() const { return !UsingBits.hasTypeDifferentFromDecl; }
 
   void Profile(llvm::FoldingSetNodeID &ID) {
-Profile(ID, Found, typeMatchesDecl() ? QualType() : getUnderlyingType());
+Profile(ID, Found, getUnderlyingType());
   }
   static void Profile(llvm::FoldingSetNodeID &ID, const UsingShadowDecl *Found,
   QualType Underlying) {
 ID.AddPointer(Found);
-if (!Underlying.isNull())
-  Underlying.Profile(ID);
+Underlying.Profile(ID);
   }
   static bool classof(const Type *T) { return T->getTypeClass() == Using; }
 };
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index d312ef61fb15d4a..5eb7aa3664569dd 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -4672,6 +4672,12 @@ QualType ASTContext::getTypedefType(const 
TypedefNameDecl *Decl,
 QualType ASTContext::getUsingType(const UsingShadowDecl *Found,
   QualType Underlying) const {
   llvm::FoldingSetNodeID ID;
+  UsingType::Profile(ID, Found, Underlying);
+
+  void *InsertPos = nullptr;
+  if (UsingType *T = UsingTypes.FindNodeOrInsertPos(ID, InsertPos))
+return QualType(T, 0);
+
   const Type *TypeForDecl =
   cast(Found->getTargetDecl())->getTypeForDecl();
 
@@ -4681,13 +4687,6 @@ QualType ASTContext::getUsingType(const UsingShadowDecl 
*Found,
 
   if (Underlying.getTypePtr() == TypeForDecl)
 Underlying = QualType();
-  UsingType::Profile(ID, Found, Underlying);
-
-  void *InsertPos = nullptr;
-  if (UsingType *T = UsingTypes.FindNodeOrInsertPos(ID, InsertPos)) {
-return QualType(T, 0);
-  }
-
   void *Mem =
   Allocate(UsingType::totalSizeToAlloc(!Underlying.isNull()),
alignof(UsingType));

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


[clang] Check lsx/lasx features when running builtin tests (PR #79250)

2024-01-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (leecheechen)


Changes

This patch refers to the following test:
clang/test/CodeGen/LoongArch/intrinsic-la32-error.c

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


2 Files Affected:

- (modified) clang/test/CodeGen/LoongArch/lasx/builtin-error.c (+9) 
- (modified) clang/test/CodeGen/LoongArch/lsx/builtin-error.c (+9) 


``diff
diff --git a/clang/test/CodeGen/LoongArch/lasx/builtin-error.c 
b/clang/test/CodeGen/LoongArch/lasx/builtin-error.c
index 724484465769e0e..dabf34368ea3e13 100644
--- a/clang/test/CodeGen/LoongArch/lasx/builtin-error.c
+++ b/clang/test/CodeGen/LoongArch/lasx/builtin-error.c
@@ -1,4 +1,6 @@
 // RUN: %clang_cc1 -triple loongarch64 -target-feature +lasx -verify %s
+// RUN: not %clang_cc1 -triple loongarch64 -DFEATURE_CHECK -emit-llvm %s -o 
/dev/null 2>&1 \
+// RUN:   | FileCheck %s
 
 typedef signed char v32i8 __attribute__((vector_size(32), aligned(32)));
 typedef signed char v32i8_b __attribute__((vector_size(32), aligned(1)));
@@ -21,6 +23,13 @@ typedef float v8f32_w __attribute__((vector_size(32), 
aligned(4)));
 typedef double v4f64 __attribute__((vector_size(32), aligned(32)));
 typedef double v4f64_d __attribute__((vector_size(32), aligned(8)));
 
+#ifdef FEATURE_CHECK
+void test_feature(v32i8 _1) {
+// CHECK: error: '__builtin_lasx_xvslli_b' needs target feature lasx
+  (void)__builtin_lasx_xvslli_b(_1, 1);
+}
+#endif
+
 v32i8 xvslli_b(v32i8 _1, int var) {
   v32i8 res = __builtin_lasx_xvslli_b(_1, -1); // expected-error {{argument 
value 4294967295 is outside the valid range [0, 7]}}
   res |= __builtin_lasx_xvslli_b(_1, 8); // expected-error {{argument value 8 
is outside the valid range [0, 7]}}
diff --git a/clang/test/CodeGen/LoongArch/lsx/builtin-error.c 
b/clang/test/CodeGen/LoongArch/lsx/builtin-error.c
index 3fc5f73f11934e6..722ba7fe8cd20e4 100644
--- a/clang/test/CodeGen/LoongArch/lsx/builtin-error.c
+++ b/clang/test/CodeGen/LoongArch/lsx/builtin-error.c
@@ -1,4 +1,6 @@
 // RUN: %clang_cc1 -triple loongarch64 -target-feature +lsx -verify %s
+// RUN: not %clang_cc1 -triple loongarch64 -DFEATURE_CHECK -emit-llvm %s -o 
/dev/null 2>&1 \
+// RUN:   | FileCheck %s
 
 typedef signed char v16i8 __attribute__((vector_size(16), aligned(16)));
 typedef signed char v16i8_b __attribute__((vector_size(16), aligned(1)));
@@ -25,6 +27,13 @@ typedef long long __m128i 
__attribute__((__vector_size__(16), __may_alias__));
 typedef float __m128 __attribute__((__vector_size__(16), __may_alias__));
 typedef double __m128d __attribute__((__vector_size__(16), __may_alias__));
 
+#ifdef FEATURE_CHECK
+void test_feature(v16i8 _1) {
+// CHECK: error: '__builtin_lsx_vslli_b' needs target feature lsx
+  (void)__builtin_lsx_vslli_b(_1, 1);
+}
+#endif
+
 v16i8 vslli_b(v16i8 _1, int var) {
   v16i8 res = __builtin_lsx_vslli_b(_1, -1); // expected-error {{argument 
value 4294967295 is outside the valid range [0, 7]}}
   res |= __builtin_lsx_vslli_b(_1, 8); // expected-error {{argument value 8 is 
outside the valid range [0, 7]}}

``




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


[clang] Check lsx/lasx features when running builtin tests (PR #79250)

2024-01-23 Thread via cfe-commits

https://github.com/leecheechen created 
https://github.com/llvm/llvm-project/pull/79250

This patch refers to the following test:
clang/test/CodeGen/LoongArch/intrinsic-la32-error.c

>From db292af78d92c01582acbd0c0d4549d90ac5f10b Mon Sep 17 00:00:00 2001
From: chenli 
Date: Wed, 24 Jan 2024 11:56:05 +0800
Subject: [PATCH] Check lsx/lasx features when running builtin tests

This patch refers to the following test:
clang/test/CodeGen/LoongArch/intrinsic-la32-error.c
---
 clang/test/CodeGen/LoongArch/lasx/builtin-error.c | 9 +
 clang/test/CodeGen/LoongArch/lsx/builtin-error.c  | 9 +
 2 files changed, 18 insertions(+)

diff --git a/clang/test/CodeGen/LoongArch/lasx/builtin-error.c 
b/clang/test/CodeGen/LoongArch/lasx/builtin-error.c
index 724484465769e0e..dabf34368ea3e13 100644
--- a/clang/test/CodeGen/LoongArch/lasx/builtin-error.c
+++ b/clang/test/CodeGen/LoongArch/lasx/builtin-error.c
@@ -1,4 +1,6 @@
 // RUN: %clang_cc1 -triple loongarch64 -target-feature +lasx -verify %s
+// RUN: not %clang_cc1 -triple loongarch64 -DFEATURE_CHECK -emit-llvm %s -o 
/dev/null 2>&1 \
+// RUN:   | FileCheck %s
 
 typedef signed char v32i8 __attribute__((vector_size(32), aligned(32)));
 typedef signed char v32i8_b __attribute__((vector_size(32), aligned(1)));
@@ -21,6 +23,13 @@ typedef float v8f32_w __attribute__((vector_size(32), 
aligned(4)));
 typedef double v4f64 __attribute__((vector_size(32), aligned(32)));
 typedef double v4f64_d __attribute__((vector_size(32), aligned(8)));
 
+#ifdef FEATURE_CHECK
+void test_feature(v32i8 _1) {
+// CHECK: error: '__builtin_lasx_xvslli_b' needs target feature lasx
+  (void)__builtin_lasx_xvslli_b(_1, 1);
+}
+#endif
+
 v32i8 xvslli_b(v32i8 _1, int var) {
   v32i8 res = __builtin_lasx_xvslli_b(_1, -1); // expected-error {{argument 
value 4294967295 is outside the valid range [0, 7]}}
   res |= __builtin_lasx_xvslli_b(_1, 8); // expected-error {{argument value 8 
is outside the valid range [0, 7]}}
diff --git a/clang/test/CodeGen/LoongArch/lsx/builtin-error.c 
b/clang/test/CodeGen/LoongArch/lsx/builtin-error.c
index 3fc5f73f11934e6..722ba7fe8cd20e4 100644
--- a/clang/test/CodeGen/LoongArch/lsx/builtin-error.c
+++ b/clang/test/CodeGen/LoongArch/lsx/builtin-error.c
@@ -1,4 +1,6 @@
 // RUN: %clang_cc1 -triple loongarch64 -target-feature +lsx -verify %s
+// RUN: not %clang_cc1 -triple loongarch64 -DFEATURE_CHECK -emit-llvm %s -o 
/dev/null 2>&1 \
+// RUN:   | FileCheck %s
 
 typedef signed char v16i8 __attribute__((vector_size(16), aligned(16)));
 typedef signed char v16i8_b __attribute__((vector_size(16), aligned(1)));
@@ -25,6 +27,13 @@ typedef long long __m128i 
__attribute__((__vector_size__(16), __may_alias__));
 typedef float __m128 __attribute__((__vector_size__(16), __may_alias__));
 typedef double __m128d __attribute__((__vector_size__(16), __may_alias__));
 
+#ifdef FEATURE_CHECK
+void test_feature(v16i8 _1) {
+// CHECK: error: '__builtin_lsx_vslli_b' needs target feature lsx
+  (void)__builtin_lsx_vslli_b(_1, 1);
+}
+#endif
+
 v16i8 vslli_b(v16i8 _1, int var) {
   v16i8 res = __builtin_lsx_vslli_b(_1, -1); // expected-error {{argument 
value 4294967295 is outside the valid range [0, 7]}}
   res |= __builtin_lsx_vslli_b(_1, 8); // expected-error {{argument value 8 is 
outside the valid range [0, 7]}}

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


[llvm] [lldb] [lld] [compiler-rt] [clang] [mlir] [libc] [libcxx] [Driver] Test ignored target-specific options for AMDGPU/NVPTX (PR #79222)

2024-01-23 Thread Joseph Huber via cfe-commits


@@ -0,0 +1,7 @@
+/// Some target-specific options are ignored for GPU, so %clang exits with 
code 0.
+// DEFINE: %{gpu_opts} = --cuda-gpu-arch=sm_60 
--cuda-path=%S/Inputs/CUDA/usr/local/cuda --no-cuda-version-check
+// DEFINE: %{check} = %clang -### -c %{gpu_opts} -mcmodel=medium %s
+// RUN: %{check} -fbasic-block-sections=all
+
+// REDEFINE: %{gpu_opts} = -x hip --rocm-path=%S/Inputs/rocm -nogpulib

jhuber6 wrote:

Should probably include `-nogpuinc` as well. Best way to avoid spurious 
failures due to lack of a local CUDA / ROCm installation. Maybe in the future 
LLVM based offloading won't depend on so much external stuff.

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


[clang-tools-extra] [clang] [llvm] [flang] [compiler-rt] [RISCV][MC] Add experimental support of Zaamo and Zalrsc (PR #78970)

2024-01-23 Thread Wang Pengcheng via cfe-commits

https://github.com/wangpc-pp updated 
https://github.com/llvm/llvm-project/pull/78970

>From 8cc71cb7ddb2e6691d31138ae2ef683a0690e171 Mon Sep 17 00:00:00 2001
From: wangpc 
Date: Mon, 22 Jan 2024 21:11:42 +0800
Subject: [PATCH 1/5] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 clang/lib/Basic/Targets/RISCV.cpp |   2 +-
 .../test/Preprocessor/riscv-target-features.c |  18 ++
 llvm/docs/RISCVUsage.rst  |   2 +
 llvm/lib/Support/RISCVISAInfo.cpp |   2 +
 llvm/lib/Target/RISCV/RISCVFeatures.td|  26 ++-
 llvm/test/CodeGen/RISCV/attributes.ll |   8 +
 llvm/test/MC/RISCV/rv32i-invalid.s|   2 +-
 llvm/test/MC/RISCV/rv32zaamo-invalid.s|  11 ++
 llvm/test/MC/RISCV/rv32zaamo-valid.s  | 122 ++
 llvm/test/MC/RISCV/rv32zalrsc-invalid.s   |   7 +
 llvm/test/MC/RISCV/rv32zalrsc-valid.s |  36 
 llvm/test/MC/RISCV/rv64zaamo-invalid.s|  11 ++
 llvm/test/MC/RISCV/rv64zaamo-valid.s  | 157 ++
 llvm/test/MC/RISCV/rv64zalrsc-invalid.s   |   7 +
 llvm/test/MC/RISCV/rv64zalrsc-valid.s |  42 +
 llvm/unittests/Support/RISCVISAInfoTest.cpp   |   2 +
 16 files changed, 452 insertions(+), 3 deletions(-)
 create mode 100644 llvm/test/MC/RISCV/rv32zaamo-invalid.s
 create mode 100644 llvm/test/MC/RISCV/rv32zaamo-valid.s
 create mode 100644 llvm/test/MC/RISCV/rv32zalrsc-invalid.s
 create mode 100644 llvm/test/MC/RISCV/rv32zalrsc-valid.s
 create mode 100644 llvm/test/MC/RISCV/rv64zaamo-invalid.s
 create mode 100644 llvm/test/MC/RISCV/rv64zaamo-valid.s
 create mode 100644 llvm/test/MC/RISCV/rv64zalrsc-invalid.s
 create mode 100644 llvm/test/MC/RISCV/rv64zalrsc-valid.s

diff --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index c71b2e9eeb6c17..9af9bdd1d74e9d 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -175,7 +175,7 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions 
&Opts,
 Builder.defineMacro("__riscv_muldiv");
   }
 
-  if (ISAInfo->hasExtension("a")) {
+  if (ISAInfo->hasExtension("a") || ISAInfo->hasExtension("zaamo")) {
 Builder.defineMacro("__riscv_atomic");
 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 5fde5ccdbeacfb..38473d07004a57 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -141,7 +141,9 @@
 
 // Experimental extensions
 
+// CHECK-NOT: __riscv_zaamo {{.*$}}
 // CHECK-NOT: __riscv_zacas {{.*$}}
+// CHECK-NOT: __riscv_zalrsc {{.*$}}
 // CHECK-NOT: __riscv_zcmop {{.*$}}
 // CHECK-NOT: __riscv_zfbfmin {{.*$}}
 // CHECK-NOT: __riscv_zicfilp {{.*$}}
@@ -1307,6 +1309,14 @@
 // CHECK-ZVKT-EXT: __riscv_zvkt 100{{$}}
 
 // Experimental extensions
+// RUN: %clang --target=riscv32 -menable-experimental-extensions \
+// RUN: -march=rv32i_zaamo0p1 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZAAMO-EXT %s
+// RUN: %clang --target=riscv64 -menable-experimental-extensions \
+// RUN: -march=rv64i_zaamo0p1 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZAAMO-EXT %s
+// CHECK-ZAAMO-EXT: __riscv_atomic 1
+// CHECK-ZAAMO-EXT: __riscv_zaamo 1000{{$}}
 
 // RUN: %clang --target=riscv32 -menable-experimental-extensions \
 // RUN: -march=rv32i_zacas1p0 -x c -E -dM %s \
@@ -1316,6 +1326,14 @@
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZACAS-EXT %s
 // CHECK-ZACAS-EXT: __riscv_zacas 100{{$}}
 
+// RUN: %clang --target=riscv32 -menable-experimental-extensions \
+// RUN: -march=rv32i_zalrsc0p1 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZALRSC-EXT %s
+// RUN: %clang --target=riscv64 -menable-experimental-extensions \
+// RUN: -march=rv64i_zalrsc0p1 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZALRSC-EXT %s
+// CHECK-ZALRSC-EXT: __riscv_zalrsc 1000{{$}}
+
 // RUN: %clang --target=riscv32 -menable-experimental-extensions \
 // RUN: -march=rv32izfbfmin1p0 -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZFBFMIN-EXT %s
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 6fdc945ad27078..005e9f1d732444 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -100,6 +100,8 @@ on support follow.
  ``V``Supported
  ``Za128rs``  Supported (`See note 
<#riscv-profiles-extensions-note>`__)
  ``Za64rs``   Supported (`See note 
<#riscv-profiles-extensions-note>`__)
+ ``Zaamo``Supported
+ ``Zalrsc``   Supported
  ``Zawrs``Assembly Support
  ``Zba``  Supported
  ``Zbb``  Supported

[clang] [clang-tools-extra] [llvm] [LoongArch] Insert nops and emit align reloc when handle alignment directive (PR #72962)

2024-01-23 Thread Lu Weining via cfe-commits

SixWeining wrote:

Should be fixed by baba7e4175b6.

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


[clang] [libc] [lldb] [llvm] [mlir] [compiler-rt] [lld] [libcxx] [Driver] Test ignored target-specific options for AMDGPU/NVPTX (PR #79222)

2024-01-23 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,7 @@
+/// Some target-specific options are ignored for GPU, so %clang exits with 
code 0.
+// DEFINE: %{gpu_opts} = --cuda-gpu-arch=sm_60 
--cuda-path=%S/Inputs/CUDA/usr/local/cuda --no-cuda-version-check

MaskRay wrote:

Thanks for the suggestion. Edited

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


[clang] [libc] [lldb] [llvm] [mlir] [compiler-rt] [lld] [libcxx] [Driver] Test ignored target-specific options for AMDGPU/NVPTX (PR #79222)

2024-01-23 Thread Fangrui Song via cfe-commits

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


[clang] [libc] [lldb] [llvm] [mlir] [compiler-rt] [lld] [libcxx] [Driver] Test ignored target-specific options for AMDGPU/NVPTX (PR #79222)

2024-01-23 Thread Joseph Huber via cfe-commits


@@ -0,0 +1,7 @@
+/// Some target-specific options are ignored for GPU, so %clang exits with 
code 0.
+// DEFINE: %{gpu_opts} = --cuda-gpu-arch=sm_60 
--cuda-path=%S/Inputs/CUDA/usr/local/cuda --no-cuda-version-check
+// DEFINE: %{check} = %clang -### -c %{gpu_opts} -mcmodel=medium %s
+// RUN: %{check} -fbasic-block-sections=all

jhuber6 wrote:

Offloading compilation for these single-source languages pretty much just 
combines one "host" compilation job with N "Device" compilation jobs. Doing 
`--offload-device-only` and `--offload-host-only` simply does one part of that. 
There's probably some flags that behave differently depending on which end 
you're compiling on, so maybe it would be useful for separating that behavior 
if needed.

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


[clang] [libc] [lldb] [llvm] [mlir] [compiler-rt] [lld] [libcxx] [Driver] Test ignored target-specific options for AMDGPU/NVPTX (PR #79222)

2024-01-23 Thread Fangrui Song via cfe-commits

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


[clang] [libc] [lldb] [llvm] [mlir] [compiler-rt] [lld] [libcxx] [Driver] Test ignored target-specific options for AMDGPU/NVPTX (PR #79222)

2024-01-23 Thread Fangrui Song via cfe-commits

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


[clang] [libc] [lldb] [llvm] [mlir] [compiler-rt] [lld] [libcxx] [Driver] Test ignored target-specific options for AMDGPU/NVPTX (PR #79222)

2024-01-23 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,7 @@
+/// Some target-specific options are ignored for GPU, so %clang exits with 
code 0.
+// DEFINE: %{gpu_opts} = --cuda-gpu-arch=sm_60 
--cuda-path=%S/Inputs/CUDA/usr/local/cuda --no-cuda-version-check
+// DEFINE: %{check} = %clang -### -c %{gpu_opts} -mcmodel=medium %s
+// RUN: %{check} -fbasic-block-sections=all

MaskRay wrote:

Added `-x cuda`. The test is to show we don't get an error 
(`err_drv_unsupported_opt_for_target`) when compiling for x86_64 using a device 
(AMDGPU/NVPTX) when certain target-specified options are specified.

I am not familiar with offloading but specifying `--cuda-host-only` would 
defeat the purpose.

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


[llvm] [clang] [RISCV][MC] Add experimental support of Zaamo and Zalrsc (PR #78970)

2024-01-23 Thread Wang Pengcheng via cfe-commits


@@ -1307,6 +1309,13 @@
 // CHECK-ZVKT-EXT: __riscv_zvkt 100{{$}}
 
 // Experimental extensions
+// RUN: %clang --target=riscv32 -menable-experimental-extensions \
+// RUN: -march=rv32i_zaamo0p1 -x c -E -dM %s \

wangpc-pp wrote:

Sorry for that I forgot to update this part...

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


[clang] [libc] [lldb] [llvm] [mlir] [compiler-rt] [lld] [libcxx] [Driver] Test ignored target-specific options for AMDGPU/NVPTX (PR #79222)

2024-01-23 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay updated 
https://github.com/llvm/llvm-project/pull/79222

>From 3a2b2a1110e7b3348a12a6476ab014a469891062 Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Tue, 23 Jan 2024 15:13:49 -0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 clang/test/Driver/unsupported-option-gpu.c | 7 +++
 1 file changed, 7 insertions(+)
 create mode 100644 clang/test/Driver/unsupported-option-gpu.c

diff --git a/clang/test/Driver/unsupported-option-gpu.c 
b/clang/test/Driver/unsupported-option-gpu.c
new file mode 100644
index 00..5713dbbfc7ae4d
--- /dev/null
+++ b/clang/test/Driver/unsupported-option-gpu.c
@@ -0,0 +1,7 @@
+/// Some target-specific options are ignored for GPU, so %clang exits with 
code 0.
+// DEFINE: %{gpu_opts} = --cuda-gpu-arch=sm_60 
--cuda-path=%S/Inputs/CUDA/usr/local/cuda --no-cuda-version-check
+// DEFINE: %{check} = %clang -### -c %{gpu_opts} -mcmodel=medium %s
+// RUN: %{check} -fbasic-block-sections=all
+
+// REDEFINE: %{gpu_opts} = -x hip --rocm-path=%S/Inputs/rocm -nogpulib
+// RUN: %{check}

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


[clang] [Modules] [HeaderSearch] Don't reenter headers if it is pragma once (PR #76119)

2024-01-23 Thread Chuanqi Xu via cfe-commits


@@ -1458,7 +1458,7 @@ bool HeaderSearch::ShouldEnterIncludeFile(Preprocessor 
&PP,
   } else {
 // Otherwise, if this is a #include of a file that was previously #import'd
 // or if this is the second #include of a #pragma once file, ignore it.
-if ((FileInfo.isPragmaOnce || FileInfo.isImport) && !TryEnterImported())

ChuanqiXu9 wrote:

I feel it will become harder to read. So I didn't inline it. But I move the 
definition to a closer place.

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


[clang] [Modules] [HeaderSearch] Don't reenter headers if it is pragma once (PR #76119)

2024-01-23 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 updated 
https://github.com/llvm/llvm-project/pull/76119

>From 65fdddbd501b36f7dcef2db3fd25a7a4a1f80a0b Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Thu, 21 Dec 2023 11:24:14 +0800
Subject: [PATCH] [Modules] [HeaderSearch] Don't reenter headers if it is
 pragma once of #import

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

The direct issue of https://github.com/llvm/llvm-project/issues/73023 is
that we entered a header which is marked as pragma once since the
compiler think it is OK if there is controlling macro.

It doesn't make sense. I feel like it should be sufficient to skip it
after we see the '#pragma once'.

>From the context, it looks like the workaround is primarily for
ObjectiveC. So we might need reviewers from OC.
---
 clang/lib/Lex/HeaderSearch.cpp | 78 +-
 clang/test/Modules/pr73023.cpp | 19 +
 2 files changed, 58 insertions(+), 39 deletions(-)
 create mode 100644 clang/test/Modules/pr73023.cpp

diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index 0f1090187734ff2..dfa974e9a67ede3 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -1408,57 +1408,57 @@ bool HeaderSearch::ShouldEnterIncludeFile(Preprocessor 
&PP,
   // Get information about this file.
   HeaderFileInfo &FileInfo = getFileInfo(File);
 
-  // FIXME: this is a workaround for the lack of proper modules-aware support
-  // for #import / #pragma once
-  auto TryEnterImported = [&]() -> bool {
-if (!ModulesEnabled)
-  return false;
-// Ensure FileInfo bits are up to date.
-ModMap.resolveHeaderDirectives(File);
-// Modules with builtins are special; multiple modules use builtins as
-// modular headers, example:
-//
-//module stddef { header "stddef.h" export * }
-//
-// After module map parsing, this expands to:
-//
-//module stddef {
-//  header "/path_to_builtin_dirs/stddef.h"
-//  textual "stddef.h"
-//}
-//
-// It's common that libc++ and system modules will both define such
-// submodules. Make sure cached results for a builtin header won't
-// prevent other builtin modules from potentially entering the builtin
-// header. Note that builtins are header guarded and the decision to
-// actually enter them is postponed to the controlling macros logic below.
-bool TryEnterHdr = false;
-if (FileInfo.isCompilingModuleHeader && FileInfo.isModuleHeader)
-  TryEnterHdr = ModMap.isBuiltinHeader(File);
-
-// Textual headers can be #imported from different modules. Since ObjC
-// headers find in the wild might rely only on #import and do not contain
-// controlling macros, be conservative and only try to enter textual 
headers
-// if such macro is present.
-if (!FileInfo.isModuleHeader &&
-FileInfo.getControllingMacro(ExternalLookup))
-  TryEnterHdr = true;
-return TryEnterHdr;
-  };
-
   // If this is a #import directive, check that we have not already imported
   // this header.
   if (isImport) {
 // If this has already been imported, don't import it again.
 FileInfo.isImport = true;
 
+// FIXME: this is a workaround for the lack of proper modules-aware support
+// for #import / #pragma once
+auto TryEnterImported = [&]() -> bool {
+  if (!ModulesEnabled)
+return false;
+  // Ensure FileInfo bits are up to date.
+  ModMap.resolveHeaderDirectives(File);
+  // Modules with builtins are special; multiple modules use builtins as
+  // modular headers, example:
+  //
+  //module stddef { header "stddef.h" export * }
+  //
+  // After module map parsing, this expands to:
+  //
+  //module stddef {
+  //  header "/path_to_builtin_dirs/stddef.h"
+  //  textual "stddef.h"
+  //}
+  //
+  // It's common that libc++ and system modules will both define such
+  // submodules. Make sure cached results for a builtin header won't
+  // prevent other builtin modules from potentially entering the builtin
+  // header. Note that builtins are header guarded and the decision to
+  // actually enter them is postponed to the controlling macros logic 
below.
+  bool TryEnterHdr = false;
+  if (FileInfo.isCompilingModuleHeader && FileInfo.isModuleHeader)
+TryEnterHdr = ModMap.isBuiltinHeader(File);
+
+  // Textual headers can be #imported from different modules. Since ObjC
+  // headers find in the wild might rely only on #import and do not contain
+  // controlling macros, be conservative and only try to enter textual
+  // headers if such macro is present.
+  if (!FileInfo.isModuleHeader &&
+  FileInfo.getControllingMacro(ExternalLookup))
+TryEnterHdr = true;
+  return TryEnterHdr;
+};
+
 // Has this already been #import'ed or #include'd?
 if (PP.alreadyIncluded(File) && !T

[llvm] [clang-tools-extra] [clang] [LoongArch] Insert nops and emit align reloc when handle alignment directive (PR #72962)

2024-01-23 Thread Nico Weber via cfe-commits

nico wrote:

Looks like this breaks check-llvm: http://45.33.8.238/macm1/77360/step_11.txt , 
http://45.33.8.238/linux/128902/step_12.txt

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

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


[clang] [llvm] [RISCV] Relax march string order constraint (PR #78120)

2024-01-23 Thread Piyou Chen via cfe-commits


@@ -695,6 +696,106 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) {
   return std::move(ISAInfo);
 }
 
+static Error splitExtsByUnderscore(StringRef Exts,
+   std::vector &SplitExts) {
+  SmallVector Split;
+  if (Exts.empty())
+return Error::success();
+
+  Exts.split(Split, "_");
+
+  for (auto Ext : Split) {
+if (Ext.empty())
+  return createStringError(errc::invalid_argument,
+   "extension name missing after separator '_'");
+
+SplitExts.push_back(Ext.str());
+  }
+  return Error::success();
+}
+
+static Error processMultiLetterExtension(
+StringRef RawExt,
+MapVector> &SeenExtMap,
+bool IgnoreUnknown, bool EnableExperimentalExtension,
+bool ExperimentalExtensionVersionCheck) {
+  StringRef Type = getExtensionType(RawExt);
+  StringRef Desc = getExtensionTypeDesc(RawExt);
+  auto Pos = findLastNonVersionCharacter(RawExt) + 1;
+  StringRef Name(RawExt.substr(0, Pos));
+  StringRef Vers(RawExt.substr(Pos));
+
+  if (Type.empty()) {
+if (IgnoreUnknown)
+  return Error::success();
+return createStringError(errc::invalid_argument,
+ "invalid extension prefix '" + RawExt + "'");
+  }
+
+  if (!IgnoreUnknown && Name.size() == Type.size())
+return createStringError(errc::invalid_argument,
+ "%s name missing after '%s'", Desc.str().c_str(),
+ Type.str().c_str());
+
+  unsigned Major, Minor, ConsumeLength;
+  if (auto E = getExtensionVersion(Name, Vers, Major, Minor, ConsumeLength,
+   EnableExperimentalExtension,
+   ExperimentalExtensionVersionCheck)) {
+if (IgnoreUnknown) {
+  consumeError(std::move(E));
+  return Error::success();
+}
+return E;
+  }
+
+  // Check if duplicated extension.
+  if (!IgnoreUnknown && (SeenExtMap.find(Name.str()) != SeenExtMap.end()))
+return createStringError(errc::invalid_argument, "duplicated %s '%s'",
+ Desc.str().c_str(), Name.str().c_str());
+
+  if (IgnoreUnknown && !RISCVISAInfo::isSupportedExtension(Name))
+return Error::success();
+
+  SeenExtMap[Name.str()] = {Major, Minor};
+  return Error::success();
+}
+
+static Error processSingleLetterExtension(
+StringRef &RawExt,
+MapVector> &SeenExtMap,
+bool IgnoreUnknown, bool EnableExperimentalExtension,
+bool ExperimentalExtensionVersionCheck) {
+  unsigned Major, Minor, ConsumeLength;
+  StringRef Name = RawExt.take_front(1);
+  RawExt.consume_front(Name);
+  if (auto E = getExtensionVersion(Name, RawExt, Major, Minor, ConsumeLength,
+   EnableExperimentalExtension,
+   ExperimentalExtensionVersionCheck)) {
+if (IgnoreUnknown) {
+  consumeError(std::move(E));
+  RawExt = RawExt.substr(ConsumeLength);
+  return Error::success();
+}
+return E;
+  }
+
+  RawExt = RawExt.substr(ConsumeLength);
+
+  // Check if duplicated extension.
+  if (!IgnoreUnknown && (SeenExtMap.find(Name.str()) != SeenExtMap.end()))

BeMg wrote:

Done

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


[llvm] [clang] [RISCV] Relax march string order constraint (PR #78120)

2024-01-23 Thread Piyou Chen via cfe-commits


@@ -695,6 +696,106 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) {
   return std::move(ISAInfo);
 }
 
+static Error splitExtsByUnderscore(StringRef Exts,
+   std::vector &SplitExts) {
+  SmallVector Split;
+  if (Exts.empty())
+return Error::success();
+
+  Exts.split(Split, "_");
+
+  for (auto Ext : Split) {
+if (Ext.empty())
+  return createStringError(errc::invalid_argument,
+   "extension name missing after separator '_'");
+
+SplitExts.push_back(Ext.str());
+  }
+  return Error::success();
+}
+
+static Error processMultiLetterExtension(
+StringRef RawExt,
+MapVector> &SeenExtMap,
+bool IgnoreUnknown, bool EnableExperimentalExtension,
+bool ExperimentalExtensionVersionCheck) {
+  StringRef Type = getExtensionType(RawExt);
+  StringRef Desc = getExtensionTypeDesc(RawExt);
+  auto Pos = findLastNonVersionCharacter(RawExt) + 1;
+  StringRef Name(RawExt.substr(0, Pos));
+  StringRef Vers(RawExt.substr(Pos));
+
+  if (Type.empty()) {
+if (IgnoreUnknown)
+  return Error::success();
+return createStringError(errc::invalid_argument,
+ "invalid extension prefix '" + RawExt + "'");
+  }
+
+  if (!IgnoreUnknown && Name.size() == Type.size())
+return createStringError(errc::invalid_argument,
+ "%s name missing after '%s'", Desc.str().c_str(),
+ Type.str().c_str());
+
+  unsigned Major, Minor, ConsumeLength;
+  if (auto E = getExtensionVersion(Name, Vers, Major, Minor, ConsumeLength,
+   EnableExperimentalExtension,
+   ExperimentalExtensionVersionCheck)) {
+if (IgnoreUnknown) {
+  consumeError(std::move(E));
+  return Error::success();
+}
+return E;
+  }
+
+  // Check if duplicated extension.
+  if (!IgnoreUnknown && (SeenExtMap.find(Name.str()) != SeenExtMap.end()))

BeMg wrote:

Done

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


[llvm] [clang] [RISCV] Relax march string order constraint (PR #78120)

2024-01-23 Thread Piyou Chen via cfe-commits

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

>From 88eef23588b545f29f3fe62a702ed2121b53c7cd Mon Sep 17 00:00:00 2001
From: Piyou Chen 
Date: Sun, 14 Jan 2024 19:41:59 -0800
Subject: [PATCH 1/7] [RISCV] Relax march string order constraint

---
 clang/test/Driver/riscv-arch.c  |  14 +-
 llvm/lib/Support/RISCVISAInfo.cpp   | 297 ++--
 llvm/unittests/Support/RISCVISAInfoTest.cpp |  91 --
 3 files changed, 226 insertions(+), 176 deletions(-)

diff --git a/clang/test/Driver/riscv-arch.c b/clang/test/Driver/riscv-arch.c
index 0ac81ea982f1b61..38de95e4fbf7aa4 100644
--- a/clang/test/Driver/riscv-arch.c
+++ b/clang/test/Driver/riscv-arch.c
@@ -156,9 +156,8 @@
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32L %s
 // RV32L: error: invalid arch name 'rv32l'
 
-// RUN: not %clang --target=riscv32-unknown-elf -march=rv32imadf -### %s \
-// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32IMADF %s
-// RV32IMADF: error: invalid arch name 'rv32imadf'
+// RUN: %clang --target=riscv32-unknown-elf -march=rv32imadf -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck %s
 
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32imm -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32IMM %s
@@ -184,9 +183,8 @@
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64L %s
 // RV64L: error: invalid arch name 'rv64l'
 
-// RUN: not %clang --target=riscv64-unknown-elf -march=rv64imadf -### %s \
-// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64IMADF %s
-// RV64IMADF: error: invalid arch name 'rv64imadf'
+// RUN: %clang --target=riscv64-unknown-elf -march=rv64imadf -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck %s
 
 // RUN: not %clang --target=riscv64-unknown-elf -march=rv64imm -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64IMM %s
@@ -216,7 +214,7 @@
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32imcq -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-ORDER %s
 // RV32-ORDER: error: invalid arch name 'rv32imcq',
-// RV32-ORDER: standard user-level extension not given in canonical order 'q'
+// RV32-ORDER: unsupported standard user-level extension 'q'
 
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32izvl64b -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-ZVL64B-ER %s
@@ -318,7 +316,7 @@
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32ixabc_a -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-PREFIX %s
 // RV32-PREFIX: error: invalid arch name 'rv32ixabc_a',
-// RV32-PREFIX: invalid extension prefix 'a'
+// RV32-PREFIX: unsupported non-standard user-level extension 'xabc'
 
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32ixdef_sabc -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-X-ORDER %s
diff --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index 390d950486a7956..865ca48aeb90d1a 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -695,6 +695,106 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) {
   return std::move(ISAInfo);
 }
 
+static Error splitExtsByUnderscore(StringRef Exts,
+   std::vector &SplitedExts) {
+  SmallVector Split;
+  if (Exts.empty())
+return Error::success();
+
+  Exts.split(Split, "_");
+
+  for (auto Ext : Split) {
+if (Ext.empty())
+  return createStringError(errc::invalid_argument,
+   "extension name missing after separator '_'");
+
+SplitedExts.push_back(Ext.str());
+  }
+  return Error::success();
+}
+
+static Error processMultiLetterExtension(
+StringRef RawExt, SmallVector &SeenExts,
+SmallVector &ExtsVersion,
+bool IgnoreUnknown, bool EnableExperimentalExtension,
+bool ExperimentalExtensionVersionCheck) {
+  StringRef Type = getExtensionType(RawExt);
+  StringRef Desc = getExtensionTypeDesc(RawExt);
+  auto Pos = findLastNonVersionCharacter(RawExt) + 1;
+  StringRef Name(RawExt.substr(0, Pos));
+  StringRef Vers(RawExt.substr(Pos));
+
+  if (Type.empty()) {
+if (IgnoreUnknown)
+  return Error::success();
+return createStringError(errc::invalid_argument,
+ "invalid extension prefix '" + RawExt + "'");
+  }
+
+  if (!IgnoreUnknown && Name.size() == Type.size())
+return createStringError(errc::invalid_argument,
+ "%s name missing after '%s'", Desc.str().c_str(),
+ Type.str().c_str());
+
+  unsigned Major, Minor, ConsumeLength;
+  if (auto E = getExtensionVersion(Name, Vers, Major, Minor, ConsumeLength,
+   EnableExperimentalExtension,
+   ExperimentalExtensionVersionCheck)) {
+if (IgnoreUnknown) {
+  consumeError(std::move(E));
+  return Error::success();
+}
+return E;
+  }
+
+  // Check if du

[clang] [clang][analyzer] Improve modeling of 'execv' and 'execvp' in StdLibraryFunctionsChecker (PR #78930)

2024-01-23 Thread Ben Shi via cfe-commits

benshi001 wrote:

> Test for these functions can be added to file std-c-library-functions-POSIX.c 
> (with check of return value and `errno`).

I will put them into `errno-stdlibraryfunctions.c`, which seems better.

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


[clang] [libc] [libcxx] [flang] [openmp] [lld] [compiler-rt] [lldb] [clang-tools-extra] [llvm] [PGO][OpenMP] Instrumentation for GPU devices (PR #76587)

2024-01-23 Thread Ethan Luis McDonough via cfe-commits

https://github.com/EthanLuisMcDonough updated 
https://github.com/llvm/llvm-project/pull/76587

>From 530eb982b9770190377bb0bd09c5cb715f34d484 Mon Sep 17 00:00:00 2001
From: Ethan Luis McDonough 
Date: Fri, 15 Dec 2023 20:38:38 -0600
Subject: [PATCH 01/13] Add profiling functions to libomptarget

---
 .../include/llvm/Frontend/OpenMP/OMPKinds.def |  3 +++
 openmp/libomptarget/DeviceRTL/CMakeLists.txt  |  2 ++
 .../DeviceRTL/include/Profiling.h | 21 +++
 .../libomptarget/DeviceRTL/src/Profiling.cpp  | 19 +
 4 files changed, 45 insertions(+)
 create mode 100644 openmp/libomptarget/DeviceRTL/include/Profiling.h
 create mode 100644 openmp/libomptarget/DeviceRTL/src/Profiling.cpp

diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPKinds.def 
b/llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
index d22d2a8e948b00e..1d887d5cb581276 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
@@ -503,6 +503,9 @@ __OMP_RTL(__kmpc_barrier_simple_generic, false, Void, 
IdentPtr, Int32)
 __OMP_RTL(__kmpc_warp_active_thread_mask, false, Int64,)
 __OMP_RTL(__kmpc_syncwarp, false, Void, Int64)
 
+__OMP_RTL(__llvm_profile_register_function, false, Void, VoidPtr)
+__OMP_RTL(__llvm_profile_register_names_function, false, Void, VoidPtr, Int64)
+
 __OMP_RTL(__last, false, Void, )
 
 #undef __OMP_RTL
diff --git a/openmp/libomptarget/DeviceRTL/CMakeLists.txt 
b/openmp/libomptarget/DeviceRTL/CMakeLists.txt
index 1ce3e1e40a80ab4..55ee15d068c67b7 100644
--- a/openmp/libomptarget/DeviceRTL/CMakeLists.txt
+++ b/openmp/libomptarget/DeviceRTL/CMakeLists.txt
@@ -89,6 +89,7 @@ set(include_files
   ${include_directory}/Interface.h
   ${include_directory}/LibC.h
   ${include_directory}/Mapping.h
+  ${include_directory}/Profiling.h
   ${include_directory}/State.h
   ${include_directory}/Synchronization.h
   ${include_directory}/Types.h
@@ -104,6 +105,7 @@ set(src_files
   ${source_directory}/Mapping.cpp
   ${source_directory}/Misc.cpp
   ${source_directory}/Parallelism.cpp
+  ${source_directory}/Profiling.cpp
   ${source_directory}/Reduction.cpp
   ${source_directory}/State.cpp
   ${source_directory}/Synchronization.cpp
diff --git a/openmp/libomptarget/DeviceRTL/include/Profiling.h 
b/openmp/libomptarget/DeviceRTL/include/Profiling.h
new file mode 100644
index 000..68c7744cd60752f
--- /dev/null
+++ b/openmp/libomptarget/DeviceRTL/include/Profiling.h
@@ -0,0 +1,21 @@
+//=== Profiling.h - OpenMP interface -- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+//
+//===--===//
+
+#ifndef OMPTARGET_DEVICERTL_PROFILING_H
+#define OMPTARGET_DEVICERTL_PROFILING_H
+
+extern "C" {
+
+void __llvm_profile_register_function(void *ptr);
+void __llvm_profile_register_names_function(void *ptr, long int i);
+}
+
+#endif
diff --git a/openmp/libomptarget/DeviceRTL/src/Profiling.cpp 
b/openmp/libomptarget/DeviceRTL/src/Profiling.cpp
new file mode 100644
index 000..799477f5e47d273
--- /dev/null
+++ b/openmp/libomptarget/DeviceRTL/src/Profiling.cpp
@@ -0,0 +1,19 @@
+//===--- Profiling.cpp  C++ 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Profiling.h"
+
+#pragma omp begin declare target device_type(nohost)
+
+extern "C" {
+
+void __llvm_profile_register_function(void *ptr) {}
+void __llvm_profile_register_names_function(void *ptr, long int i) {}
+}
+
+#pragma omp end declare target

>From fb067d4ffe604fd68cf90b705db1942bce49dbb1 Mon Sep 17 00:00:00 2001
From: Ethan Luis McDonough 
Date: Sat, 16 Dec 2023 01:18:41 -0600
Subject: [PATCH 02/13] Fix PGO instrumentation for GPU targets

---
 clang/lib/CodeGen/CodeGenPGO.cpp  | 10 --
 .../lib/Transforms/Instrumentation/InstrProfiling.cpp | 11 ---
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp
index 81bf8ea696b1647..edae6885b528ac7 100644
--- a/clang/lib/CodeGen/CodeGenPGO.cpp
+++ b/clang/lib/CodeGen/CodeGenPGO.cpp
@@ -959,8 +959,14 @@ void CodeGenPGO::emitCounterIncrement(CGBuilderTy 
&Builder, const Stmt *S,
 
   unsigned Counter = (*RegionCounterMap)[S];
 
-  llvm::Value *Args[] = {FuncNameVar,
- Builder.getInt64(FunctionHash),
+  // Make sure that pointer to global is passed in with zero addrsp

[clang] [clang][analyzer] Improve modeling of 'popen' and 'pclose' in StdLibraryFunctionsChecker (PR #78895)

2024-01-23 Thread Ben Shi via cfe-commits


@@ -51,6 +51,17 @@ void check_freopen(void) {
   if (errno) {} // expected-warning{{An undefined value may be read from 
'errno'}}
 }
 
+void check_popen(void) {
+  FILE *F = popen("xxx", "r");
+  if (!F) {
+clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
+if (errno) {}// no-warning
+  } else {
+if (errno) {} // expected-warning{{An undefined value may be read from 
'errno' [unix.Errno]}}
+pclose(F);
+  }
+}
+

benshi001 wrote:

I have put these tests to `errno-stdlibraryfunctions.c`, which seems better, 
since tests in `std-c-library-functions-POSIX.c` do not involve `errno`.

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


[clang] [clang][analyzer] Improve modeling of 'popen' and 'pclose' in StdLibraryFunctionsChecker (PR #78895)

2024-01-23 Thread Ben Shi via cfe-commits

https://github.com/benshi001 updated 
https://github.com/llvm/llvm-project/pull/78895

>From f2d64a755adc8393d4670d370f6b9a64e368a43b Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Sun, 21 Jan 2024 18:29:06 +0800
Subject: [PATCH 1/2] [clang][analyzer] Improve modeling of 'popen' and
 'pclose' in StdLibraryFunctionsChecker

---
 .../Checkers/StdLibraryFunctionsChecker.cpp   | 34 +++
 .../Analysis/Inputs/system-header-simulator.h |  2 ++
 .../Analysis/std-c-library-functions-POSIX.c  |  4 +--
 clang/test/Analysis/stream-errno.c| 25 ++
 4 files changed, 48 insertions(+), 17 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index d0eb5091444f6b6..722fafa457c240b 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2202,6 +2202,16 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 .ArgConstraint(NotNull(ArgNo(1)))
 .ArgConstraint(NotNull(ArgNo(2;
 
+// FILE *popen(const char *command, const char *type);
+addToFunctionSummaryMap(
+"popen",
+Signature(ArgTypes{ConstCharPtrTy, ConstCharPtrTy}, 
RetType{FilePtrTy}),
+Summary(NoEvalCall)
+.Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(NotNull(ArgNo(0)))
+.ArgConstraint(NotNull(ArgNo(1;
+
 // int fclose(FILE *stream);
 addToFunctionSummaryMap(
 "fclose", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
@@ -2211,6 +2221,15 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
   ErrnoNEZeroIrrelevant, GenericFailureMsg)
 .ArgConstraint(NotNull(ArgNo(0;
 
+// int pclose(FILE *stream);
+addToFunctionSummaryMap(
+"pclose", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
+Summary(NoEvalCall)
+.Case({ReturnValueCondition(WithinRange, {{0, IntMax}})},
+  ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(NotNull(ArgNo(0;
+
 // int ungetc(int c, FILE *stream);
 addToFunctionSummaryMap(
 "ungetc", Signature(ArgTypes{IntTy, FilePtrTy}, RetType{IntTy}),
@@ -2827,21 +2846,6 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 .ArgConstraint(
 ArgumentCondition(0, WithinRange, Range(0, IntMax;
 
-// FILE *popen(const char *command, const char *type);
-// FIXME: Improve for errno modeling.
-addToFunctionSummaryMap(
-"popen",
-Signature(ArgTypes{ConstCharPtrTy, ConstCharPtrTy}, 
RetType{FilePtrTy}),
-Summary(NoEvalCall)
-.ArgConstraint(NotNull(ArgNo(0)))
-.ArgConstraint(NotNull(ArgNo(1;
-
-// int pclose(FILE *stream);
-// FIXME: Improve for errno modeling.
-addToFunctionSummaryMap(
-"pclose", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
-Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0;
-
 // int close(int fildes);
 addToFunctionSummaryMap(
 "close", Signature(ArgTypes{IntTy}, RetType{IntTy}),
diff --git a/clang/test/Analysis/Inputs/system-header-simulator.h 
b/clang/test/Analysis/Inputs/system-header-simulator.h
index f8e3e546a7aed5e..c41f22fef388e19 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator.h
@@ -47,7 +47,9 @@ FILE *fopen(const char *restrict path, const char *restrict 
mode);
 FILE *fdopen(int fd, const char *mode);
 FILE *tmpfile(void);
 FILE *freopen(const char *restrict pathname, const char *restrict mode, FILE 
*restrict stream);
+FILE *popen(const char *command, const char *mode);
 int fclose(FILE *fp);
+int pclose(FILE *stream);
 size_t fread(void *restrict, size_t, size_t, FILE *restrict);
 size_t fwrite(const void *restrict, size_t, size_t, FILE *restrict);
 int fgetc(FILE *stream);
diff --git a/clang/test/Analysis/std-c-library-functions-POSIX.c 
b/clang/test/Analysis/std-c-library-functions-POSIX.c
index 51b136d9ba35673..03aa8e2e00a75dd 100644
--- a/clang/test/Analysis/std-c-library-functions-POSIX.c
+++ b/clang/test/Analysis/std-c-library-functions-POSIX.c
@@ -20,7 +20,9 @@
 // CHECK: Loaded summary for: FILE *fdopen(int fd, const char *mode)
 // CHECK: Loaded summary for: FILE *tmpfile(void)
 // CHECK: Loaded summary for: FILE *freopen(const char *restrict pathname, 
const char *restrict mode, FILE *restrict stream)
+// CHECK: Loaded summary for: FILE *popen(const char *command, const char 
*type)
 // CHECK: Loaded summary for: int fclose(FILE *stream)
+// CHECK: Loaded summary for: int pclose(FILE *stream)
 // CHECK: Loaded summary for: int fseek(FILE *stream

[clang] [mlir] [llvm] [AMDGPU] Add GFX12 WMMA and SWMMAC instructions (PR #77795)

2024-01-23 Thread Matt Arsenault via cfe-commits


@@ -2601,67 +2601,73 @@ def int_amdgcn_ds_bvh_stack_rtn :
 [ImmArg>, IntrWillReturn, IntrNoCallback, IntrNoFree]
   >;
 
+def int_amdgcn_s_wait_event_export_ready :
+  ClangBuiltin<"__builtin_amdgcn_s_wait_event_export_ready">,
+  Intrinsic<[], [], [IntrNoMem, IntrHasSideEffects, IntrWillReturn]
+>;
+
 // WMMA (Wave Matrix Multiply-Accumulate) intrinsics
 //
 // These operations perform a matrix multiplication and accumulation of
 // the form: D = A * B + C .
 
 class AMDGPUWmmaIntrinsic :
   Intrinsic<
-[CD],   // %D
+[CD], // %D
 [
   AB,   // %A
-  AB,   // %B
+  LLVMMatchType<1>, // %B
   LLVMMatchType<0>, // %C
 ],
 [IntrNoMem, IntrConvergent, IntrWillReturn, IntrNoCallback, IntrNoFree]
 >;
 
 class AMDGPUWmmaIntrinsicOPSEL :
   Intrinsic<
-[CD],   // %D
+[CD], // %D
 [
   AB,   // %A
-  AB,   // %B
+  LLVMMatchType<1>, // %B
   LLVMMatchType<0>, // %C
-  llvm_i1_ty,   // %high
+  llvm_i1_ty,   // %high (op_sel) for GFX11, 0 for GFX12
 ],
 [IntrNoMem, IntrConvergent, ImmArg>, IntrWillReturn, 
IntrNoCallback, IntrNoFree]
 >;
 
 class AMDGPUWmmaIntrinsicIU :
   Intrinsic<
-[CD],   // %D
+[CD], // %D
 [
   llvm_i1_ty,   // %A_sign
   AB,   // %A
   llvm_i1_ty,   // %B_sign
-  AB,   // %B
+  LLVMMatchType<1>, // %B
   LLVMMatchType<0>, // %C
   llvm_i1_ty,   // %clamp
 ],
 [IntrNoMem, IntrConvergent, ImmArg>, ImmArg>, 
ImmArg>, IntrWillReturn, IntrNoCallback, IntrNoFree]
 >;
 
-def int_amdgcn_wmma_f32_16x16x16_f16   : AMDGPUWmmaIntrinsic;
-def int_amdgcn_wmma_f32_16x16x16_bf16  : AMDGPUWmmaIntrinsic;
-// The regular, untied f16/bf16 wmma intrinsics only write to one half
-// of the registers (set via the op_sel bit).
-// The content of the other 16-bit of the registers is undefined.
-def int_amdgcn_wmma_f16_16x16x16_f16   : 
AMDGPUWmmaIntrinsicOPSEL;
-def int_amdgcn_wmma_bf16_16x16x16_bf16 : 
AMDGPUWmmaIntrinsicOPSEL;
-// The tied versions of the f16/bf16 wmma intrinsics tie the destination matrix
-// registers to the input accumulator registers.
-// Essentially, the content of the other 16-bit is preserved from the input.
-def int_amdgcn_wmma_f16_16x16x16_f16_tied   : 
AMDGPUWmmaIntrinsicOPSEL;
-def int_amdgcn_wmma_bf16_16x16x16_bf16_tied : 
AMDGPUWmmaIntrinsicOPSEL;
-def int_amdgcn_wmma_i32_16x16x16_iu8   : AMDGPUWmmaIntrinsicIU;
-def int_amdgcn_wmma_i32_16x16x16_iu4   : AMDGPUWmmaIntrinsicIU;
+// WMMA GFX11Only
 
-def int_amdgcn_s_wait_event_export_ready :
-  ClangBuiltin<"__builtin_amdgcn_s_wait_event_export_ready">,
-  Intrinsic<[], [], [IntrNoMem, IntrHasSideEffects, IntrWillReturn]
->;
+// The OPSEL intrinsics read from and write to one half of the registers, 
selected by the op_sel bit.
+// The tied versions of the f16/bf16 wmma intrinsics tie the destination 
matrix registers to the input accumulator registers.
+// The content of the other 16-bit half is preserved from the input.
+def int_amdgcn_wmma_f16_16x16x16_f16_tied   : 
AMDGPUWmmaIntrinsicOPSEL;
+def int_amdgcn_wmma_bf16_16x16x16_bf16_tied : 
AMDGPUWmmaIntrinsicOPSEL;
+
+// WMMA GFX11Plus
+
+def int_amdgcn_wmma_f32_16x16x16_f16   : AMDGPUWmmaIntrinsic;
+def int_amdgcn_wmma_f32_16x16x16_bf16  : AMDGPUWmmaIntrinsic;
+def int_amdgcn_wmma_i32_16x16x16_iu8   : AMDGPUWmmaIntrinsicIU;
+def int_amdgcn_wmma_i32_16x16x16_iu4   : AMDGPUWmmaIntrinsicIU;
+
+// GFX11: The OPSEL intrinsics read from and write to one half of the 
registers, selected by the op_sel bit.
+//The content of the other 16-bit half is undefined.
+// GFX12: The op_sel bit must be 0.
+def int_amdgcn_wmma_f16_16x16x16_f16   : 
AMDGPUWmmaIntrinsicOPSEL;
+def int_amdgcn_wmma_bf16_16x16x16_bf16 : AMDGPUWmmaIntrinsicOPSEL;

arsenm wrote:

This is kind of horrible. It's not at all clear you're supposed to use one type 
for one target and a different one for another. I wonder if they should just be 
renamed?

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


[clang] [llvm] [RISCV] Relax march string order constraint (PR #78120)

2024-01-23 Thread Craig Topper via cfe-commits


@@ -695,6 +696,106 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) {
   return std::move(ISAInfo);
 }
 
+static Error splitExtsByUnderscore(StringRef Exts,
+   std::vector &SplitExts) {
+  SmallVector Split;
+  if (Exts.empty())
+return Error::success();
+
+  Exts.split(Split, "_");
+
+  for (auto Ext : Split) {
+if (Ext.empty())
+  return createStringError(errc::invalid_argument,
+   "extension name missing after separator '_'");
+
+SplitExts.push_back(Ext.str());
+  }
+  return Error::success();
+}
+
+static Error processMultiLetterExtension(
+StringRef RawExt,
+MapVector> &SeenExtMap,
+bool IgnoreUnknown, bool EnableExperimentalExtension,
+bool ExperimentalExtensionVersionCheck) {
+  StringRef Type = getExtensionType(RawExt);
+  StringRef Desc = getExtensionTypeDesc(RawExt);
+  auto Pos = findLastNonVersionCharacter(RawExt) + 1;
+  StringRef Name(RawExt.substr(0, Pos));
+  StringRef Vers(RawExt.substr(Pos));
+
+  if (Type.empty()) {
+if (IgnoreUnknown)
+  return Error::success();
+return createStringError(errc::invalid_argument,
+ "invalid extension prefix '" + RawExt + "'");
+  }
+
+  if (!IgnoreUnknown && Name.size() == Type.size())
+return createStringError(errc::invalid_argument,
+ "%s name missing after '%s'", Desc.str().c_str(),
+ Type.str().c_str());
+
+  unsigned Major, Minor, ConsumeLength;
+  if (auto E = getExtensionVersion(Name, Vers, Major, Minor, ConsumeLength,
+   EnableExperimentalExtension,
+   ExperimentalExtensionVersionCheck)) {
+if (IgnoreUnknown) {
+  consumeError(std::move(E));
+  return Error::success();
+}
+return E;
+  }
+
+  // Check if duplicated extension.
+  if (!IgnoreUnknown && (SeenExtMap.find(Name.str()) != SeenExtMap.end()))

topperc wrote:

`SeenExtMap.contains(Name.str())`

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


[llvm] [clang] [RISCV] Relax march string order constraint (PR #78120)

2024-01-23 Thread Craig Topper via cfe-commits


@@ -695,6 +696,106 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) {
   return std::move(ISAInfo);
 }
 
+static Error splitExtsByUnderscore(StringRef Exts,
+   std::vector &SplitExts) {
+  SmallVector Split;
+  if (Exts.empty())
+return Error::success();
+
+  Exts.split(Split, "_");
+
+  for (auto Ext : Split) {
+if (Ext.empty())
+  return createStringError(errc::invalid_argument,
+   "extension name missing after separator '_'");
+
+SplitExts.push_back(Ext.str());
+  }
+  return Error::success();
+}
+
+static Error processMultiLetterExtension(
+StringRef RawExt,
+MapVector> &SeenExtMap,
+bool IgnoreUnknown, bool EnableExperimentalExtension,
+bool ExperimentalExtensionVersionCheck) {
+  StringRef Type = getExtensionType(RawExt);
+  StringRef Desc = getExtensionTypeDesc(RawExt);
+  auto Pos = findLastNonVersionCharacter(RawExt) + 1;
+  StringRef Name(RawExt.substr(0, Pos));
+  StringRef Vers(RawExt.substr(Pos));
+
+  if (Type.empty()) {
+if (IgnoreUnknown)
+  return Error::success();
+return createStringError(errc::invalid_argument,
+ "invalid extension prefix '" + RawExt + "'");
+  }
+
+  if (!IgnoreUnknown && Name.size() == Type.size())
+return createStringError(errc::invalid_argument,
+ "%s name missing after '%s'", Desc.str().c_str(),
+ Type.str().c_str());
+
+  unsigned Major, Minor, ConsumeLength;
+  if (auto E = getExtensionVersion(Name, Vers, Major, Minor, ConsumeLength,
+   EnableExperimentalExtension,
+   ExperimentalExtensionVersionCheck)) {
+if (IgnoreUnknown) {
+  consumeError(std::move(E));
+  return Error::success();
+}
+return E;
+  }
+
+  // Check if duplicated extension.
+  if (!IgnoreUnknown && (SeenExtMap.find(Name.str()) != SeenExtMap.end()))
+return createStringError(errc::invalid_argument, "duplicated %s '%s'",
+ Desc.str().c_str(), Name.str().c_str());
+
+  if (IgnoreUnknown && !RISCVISAInfo::isSupportedExtension(Name))
+return Error::success();
+
+  SeenExtMap[Name.str()] = {Major, Minor};
+  return Error::success();
+}
+
+static Error processSingleLetterExtension(
+StringRef &RawExt,
+MapVector> &SeenExtMap,
+bool IgnoreUnknown, bool EnableExperimentalExtension,
+bool ExperimentalExtensionVersionCheck) {
+  unsigned Major, Minor, ConsumeLength;
+  StringRef Name = RawExt.take_front(1);
+  RawExt.consume_front(Name);
+  if (auto E = getExtensionVersion(Name, RawExt, Major, Minor, ConsumeLength,
+   EnableExperimentalExtension,
+   ExperimentalExtensionVersionCheck)) {
+if (IgnoreUnknown) {
+  consumeError(std::move(E));
+  RawExt = RawExt.substr(ConsumeLength);
+  return Error::success();
+}
+return E;
+  }
+
+  RawExt = RawExt.substr(ConsumeLength);
+
+  // Check if duplicated extension.
+  if (!IgnoreUnknown && (SeenExtMap.find(Name.str()) != SeenExtMap.end()))

topperc wrote:

SeenExtMap.contains

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


[clang] [llvm] [AMDGPU] Emit a waitcnt instruction after each memory instruction (PR #68932)

2024-01-23 Thread Jun Wang via cfe-commits

jwanggit86 wrote:

Implementation is moved to SIMemoryLegalizer pass. See pull req 
[79236](https://github.com/llvm/llvm-project/pull/79236).

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


[llvm] [clang] [AMDGPU] Emit a waitcnt instruction after each memory instruction (PR #68932)

2024-01-23 Thread Jun Wang via cfe-commits

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


[clang] [llvm] [AMDGPU] Emit a waitcnt instruction after each memory instruction (PR #79236)

2024-01-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-amdgpu

Author: Jun Wang (jwanggit86)


Changes

This patch introduces a new command-line option for clang, namely, 
amdgpu-precise-mem-op. When this option is specified, a waitcnt instruction is 
generated after each memory load/store instruction. The counter values are 
always 0, but which counters are involved depends on the memory instruction.

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


6 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+4) 
- (modified) clang/test/Driver/amdgpu-features.c (+6) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPU.td (+4) 
- (modified) llvm/lib/Target/AMDGPU/GCNSubtarget.h (+3) 
- (modified) llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp (+79) 
- (added) llvm/test/CodeGen/AMDGPU/insert_waitcnt_for_all.ll (+199) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7f4fa33748facaf..d570786534b3611 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4796,6 +4796,10 @@ defm tgsplit : SimpleMFlag<"tgsplit", "Enable", 
"Disable",
 defm wavefrontsize64 : SimpleMFlag<"wavefrontsize64",
   "Specify wavefront size 64", "Specify wavefront size 32",
   " mode (AMDGPU only)">;
+defm amdgpu_precise_memory_op
+: SimpleMFlag<"amdgpu-precise-memory-op", "Enable", "Disable",
+  " precise memory mode (AMDGPU only)",
+  m_amdgpu_Features_Group>;
 
 defm unsafe_fp_atomics : BoolOption<"m", "unsafe-fp-atomics",
   TargetOpts<"AllowAMDGPUUnsafeFPAtomics">, DefaultFalse,
diff --git a/clang/test/Driver/amdgpu-features.c 
b/clang/test/Driver/amdgpu-features.c
index a516bc6b7ff2004..57d31ccedd8783e 100644
--- a/clang/test/Driver/amdgpu-features.c
+++ b/clang/test/Driver/amdgpu-features.c
@@ -32,3 +32,9 @@
 
 // RUN: %clang -### -target amdgcn -mcpu=gfx1010 -mno-cumode %s 2>&1 | 
FileCheck --check-prefix=NO-CUMODE %s
 // NO-CUMODE: "-target-feature" "-cumode"
+
+// RUN: %clang -### -target amdgcn -mcpu=gfx1010 -mamdgpu-precise-memory-op %s 
2>&1 | FileCheck --check-prefix=PREC-MEM %s
+// PREC-MEM: "-target-feature" "+amdgpu-precise-memory-op"
+
+// RUN: %clang -### -target amdgcn -mcpu=gfx1010 -mno-amdgpu-precise-memory-op 
%s 2>&1 | FileCheck --check-prefix=NO-PREC-MEM %s
+// NO-PREC-MEM: "-target-feature" "-amdgpu-precise-memory-op"
diff --git a/llvm/lib/Target/AMDGPU/AMDGPU.td b/llvm/lib/Target/AMDGPU/AMDGPU.td
index cb29d5d94759812..c39cc9477023591 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPU.td
+++ b/llvm/lib/Target/AMDGPU/AMDGPU.td
@@ -167,6 +167,10 @@ def FeatureCuMode : SubtargetFeature<"cumode",
   "Enable CU wavefront execution mode"
 >;
 
+def FeaturePreciseMemory
+: SubtargetFeature<"amdgpu-precise-memory-op", "EnablePreciseMemory",
+   "true", "Enable precise memory mode">;
+
 def FeatureSGPRInitBug : SubtargetFeature<"sgpr-init-bug",
   "SGPRInitBug",
   "true",
diff --git a/llvm/lib/Target/AMDGPU/GCNSubtarget.h 
b/llvm/lib/Target/AMDGPU/GCNSubtarget.h
index 8019b98b1c68d66..b69df21f7859851 100644
--- a/llvm/lib/Target/AMDGPU/GCNSubtarget.h
+++ b/llvm/lib/Target/AMDGPU/GCNSubtarget.h
@@ -87,6 +87,7 @@ class GCNSubtarget final : public AMDGPUGenSubtargetInfo,
   bool EnableTgSplit = false;
   bool EnableCuMode = false;
   bool TrapHandler = false;
+  bool EnablePreciseMemory = false;
 
   // Used as options.
   bool EnableLoadStoreOpt = false;
@@ -592,6 +593,8 @@ class GCNSubtarget final : public AMDGPUGenSubtargetInfo,
 return EnableCuMode;
   }
 
+  bool isPreciseMemoryEnabled() const { return EnablePreciseMemory; }
+
   bool hasFlatAddressSpace() const {
 return FlatAddressSpace;
   }
diff --git a/llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp 
b/llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp
index 84b9330ef9633eb..93cdceb37bd5017 100644
--- a/llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp
+++ b/llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp
@@ -17,6 +17,7 @@
 #include "AMDGPUMachineModuleInfo.h"
 #include "GCNSubtarget.h"
 #include "MCTargetDesc/AMDGPUMCTargetDesc.h"
+#include "Utils/AMDGPUBaseInfo.h"
 #include "llvm/ADT/BitmaskEnum.h"
 #include "llvm/CodeGen/MachineBasicBlock.h"
 #include "llvm/CodeGen/MachineFunctionPass.h"
@@ -24,6 +25,8 @@
 #include "llvm/Support/AtomicOrdering.h"
 #include "llvm/TargetParser/TargetParser.h"
 
+#include 
+
 using namespace llvm;
 using namespace llvm::AMDGPU;
 
@@ -641,6 +644,9 @@ class SIMemoryLegalizer final : public MachineFunctionPass {
   bool expandAtomicCmpxchgOrRmw(const SIMemOpInfo &MOI,
 MachineBasicBlock::iterator &MI);
 
+  bool GFX9InsertWaitcntForPreciseMem(MachineFunction &MF);
+  bool GFX10And11InsertWaitcntForPreciseMem(MachineFunction &MF);
+
 public:
   static char ID;
 
@@ -2561,6 +2567,70 @@ bool SIMemoryLegalizer::expandAtomicCmpxchgOrRmw(const 
SIMemOpInfo &MOI,
   return Changed;
 }
 
+bool SIMemoryLegalizer::GFX9InsertWaitcntForPreciseMem(

[clang] [llvm] [AMDGPU] Emit a waitcnt instruction after each memory instruction (PR #79236)

2024-01-23 Thread Jun Wang via cfe-commits

https://github.com/jwanggit86 created 
https://github.com/llvm/llvm-project/pull/79236

This patch introduces a new command-line option for clang, namely, 
amdgpu-precise-mem-op. When this option is specified, a waitcnt instruction is 
generated after each memory load/store instruction. The counter values are 
always 0, but which counters are involved depends on the memory instruction.

>From 9c40b1151b0673430ff53eb121784724a5b090e5 Mon Sep 17 00:00:00 2001
From: Jun Wang 
Date: Tue, 23 Jan 2024 19:19:00 -0600
Subject: [PATCH] [AMDGPU] Emit a waitcnt instruction after each memory
 instruction

This patch introduces a new command-line option for clang, namely,
amdgpu-precise-mem-op. When this option is specified, a waitcnt instruction
is generated after each memory load/store instruction. The counter values are
always 0, but which counters are involved depends on the memory instruction.
---
 clang/include/clang/Driver/Options.td |   4 +
 clang/test/Driver/amdgpu-features.c   |   6 +
 llvm/lib/Target/AMDGPU/AMDGPU.td  |   4 +
 llvm/lib/Target/AMDGPU/GCNSubtarget.h |   3 +
 llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp  |  79 +++
 .../CodeGen/AMDGPU/insert_waitcnt_for_all.ll  | 199 ++
 6 files changed, 295 insertions(+)
 create mode 100644 llvm/test/CodeGen/AMDGPU/insert_waitcnt_for_all.ll

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7f4fa33748facaf..d570786534b3611 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4796,6 +4796,10 @@ defm tgsplit : SimpleMFlag<"tgsplit", "Enable", 
"Disable",
 defm wavefrontsize64 : SimpleMFlag<"wavefrontsize64",
   "Specify wavefront size 64", "Specify wavefront size 32",
   " mode (AMDGPU only)">;
+defm amdgpu_precise_memory_op
+: SimpleMFlag<"amdgpu-precise-memory-op", "Enable", "Disable",
+  " precise memory mode (AMDGPU only)",
+  m_amdgpu_Features_Group>;
 
 defm unsafe_fp_atomics : BoolOption<"m", "unsafe-fp-atomics",
   TargetOpts<"AllowAMDGPUUnsafeFPAtomics">, DefaultFalse,
diff --git a/clang/test/Driver/amdgpu-features.c 
b/clang/test/Driver/amdgpu-features.c
index a516bc6b7ff2004..57d31ccedd8783e 100644
--- a/clang/test/Driver/amdgpu-features.c
+++ b/clang/test/Driver/amdgpu-features.c
@@ -32,3 +32,9 @@
 
 // RUN: %clang -### -target amdgcn -mcpu=gfx1010 -mno-cumode %s 2>&1 | 
FileCheck --check-prefix=NO-CUMODE %s
 // NO-CUMODE: "-target-feature" "-cumode"
+
+// RUN: %clang -### -target amdgcn -mcpu=gfx1010 -mamdgpu-precise-memory-op %s 
2>&1 | FileCheck --check-prefix=PREC-MEM %s
+// PREC-MEM: "-target-feature" "+amdgpu-precise-memory-op"
+
+// RUN: %clang -### -target amdgcn -mcpu=gfx1010 -mno-amdgpu-precise-memory-op 
%s 2>&1 | FileCheck --check-prefix=NO-PREC-MEM %s
+// NO-PREC-MEM: "-target-feature" "-amdgpu-precise-memory-op"
diff --git a/llvm/lib/Target/AMDGPU/AMDGPU.td b/llvm/lib/Target/AMDGPU/AMDGPU.td
index cb29d5d94759812..c39cc9477023591 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPU.td
+++ b/llvm/lib/Target/AMDGPU/AMDGPU.td
@@ -167,6 +167,10 @@ def FeatureCuMode : SubtargetFeature<"cumode",
   "Enable CU wavefront execution mode"
 >;
 
+def FeaturePreciseMemory
+: SubtargetFeature<"amdgpu-precise-memory-op", "EnablePreciseMemory",
+   "true", "Enable precise memory mode">;
+
 def FeatureSGPRInitBug : SubtargetFeature<"sgpr-init-bug",
   "SGPRInitBug",
   "true",
diff --git a/llvm/lib/Target/AMDGPU/GCNSubtarget.h 
b/llvm/lib/Target/AMDGPU/GCNSubtarget.h
index 8019b98b1c68d66..b69df21f7859851 100644
--- a/llvm/lib/Target/AMDGPU/GCNSubtarget.h
+++ b/llvm/lib/Target/AMDGPU/GCNSubtarget.h
@@ -87,6 +87,7 @@ class GCNSubtarget final : public AMDGPUGenSubtargetInfo,
   bool EnableTgSplit = false;
   bool EnableCuMode = false;
   bool TrapHandler = false;
+  bool EnablePreciseMemory = false;
 
   // Used as options.
   bool EnableLoadStoreOpt = false;
@@ -592,6 +593,8 @@ class GCNSubtarget final : public AMDGPUGenSubtargetInfo,
 return EnableCuMode;
   }
 
+  bool isPreciseMemoryEnabled() const { return EnablePreciseMemory; }
+
   bool hasFlatAddressSpace() const {
 return FlatAddressSpace;
   }
diff --git a/llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp 
b/llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp
index 84b9330ef9633eb..93cdceb37bd5017 100644
--- a/llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp
+++ b/llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp
@@ -17,6 +17,7 @@
 #include "AMDGPUMachineModuleInfo.h"
 #include "GCNSubtarget.h"
 #include "MCTargetDesc/AMDGPUMCTargetDesc.h"
+#include "Utils/AMDGPUBaseInfo.h"
 #include "llvm/ADT/BitmaskEnum.h"
 #include "llvm/CodeGen/MachineBasicBlock.h"
 #include "llvm/CodeGen/MachineFunctionPass.h"
@@ -24,6 +25,8 @@
 #include "llvm/Support/AtomicOrdering.h"
 #include "llvm/TargetParser/TargetParser.h"
 
+#include 
+
 using namespace llvm;
 using namespace llvm::AMDGPU;
 
@@ -641,6 +644,9 @@ class SIMemoryLegali

[clang] [-Wunsafe-buffer-usage] Add a new warning for uses of std::span two-parameter constructors (PR #77148)

2024-01-23 Thread Ziqing Luo via cfe-commits

https://github.com/ziqingluo-90 updated 
https://github.com/llvm/llvm-project/pull/77148

>From 1b169f49a129a5a69a82386b486c8a46ecfc815a Mon Sep 17 00:00:00 2001
From: ziqingluo-90 
Date: Fri, 5 Jan 2024 13:39:39 -0800
Subject: [PATCH 1/3] [-Wunsafe-buffer-usage] Add a new warning for use of
 two-parameter std::span constructors

Constructing `std::span` objects with the two parameter constructors
could introduce mismatched bounds information, which defeats the
purpose of using `std::span`.  Therefore, we warn every use of such
constructors.

We also plan to incrementally teach `-Wunsafe-buffer-usage` about benign
usages of those constructors.

rdar://115817781
---
 .../Analysis/Analyses/UnsafeBufferUsage.h |   8 +-
 .../Analyses/UnsafeBufferUsageGadgets.def |   8 ++
 .../clang/Basic/DiagnosticSemaKinds.td|   3 +
 clang/lib/Analysis/UnsafeBufferUsage.cpp  |  46 ++
 clang/lib/Sema/AnalysisBasedWarnings.cpp  |  15 +-
 ...ffer-usage-in-container-span-construct.cpp | 136 ++
 ...e-buffer-usage-warning-data-invocation.cpp |   2 +-
 7 files changed, 214 insertions(+), 4 deletions(-)
 create mode 100644 
clang/test/SemaCXX/warn-unsafe-buffer-usage-in-container-span-construct.cpp

diff --git a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h 
b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
index b28f2c6b99c50e..aca1ad998822c5 100644
--- a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
+++ b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
@@ -16,6 +16,7 @@
 
 #include "clang/AST/Decl.h"
 #include "clang/AST/Stmt.h"
+#include "clang/Basic/SourceLocation.h"
 #include "llvm/Support/Debug.h"
 
 namespace clang {
@@ -98,9 +99,14 @@ class UnsafeBufferUsageHandler {
 #endif
 
 public:
-  /// Returns a reference to the `Preprocessor`:
+  /// \return true iff buffer safety is opt-out at `Loc`; false otherwise.
   virtual bool isSafeBufferOptOut(const SourceLocation &Loc) const = 0;
 
+  /// \return true iff unsafe uses in containers should NOT be reported at
+  /// `Loc`; false otherwise.
+  virtual bool
+  ignoreUnsafeBufferInContainer(const SourceLocation &Loc) const = 0;
+
   virtual std::string
   getUnsafeBufferUsageAttributeTextAt(SourceLocation Loc,
   StringRef WSSuffix = "") const = 0;
diff --git a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def 
b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
index c9766168836510..07f805ebb11013 100644
--- a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
+++ b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
@@ -18,6 +18,12 @@
 #define WARNING_GADGET(name) GADGET(name)
 #endif
 
+/// A `WARNING_GADGET` subset, where the code pattern of each gadget
+/// corresponds uses of a (possibly hardened) contatiner (e.g., `std::span`).
+#ifndef WARNING_CONTAINER_GADGET
+#define WARNING_CONTAINER_GADGET(name) WARNING_GADGET(name)
+#endif
+
 /// Safe gadgets correspond to code patterns that aren't unsafe but need to be
 /// properly recognized in order to emit correct warnings and fixes over unsafe
 /// gadgets.
@@ -31,6 +37,7 @@ WARNING_GADGET(ArraySubscript)
 WARNING_GADGET(PointerArithmetic)
 WARNING_GADGET(UnsafeBufferUsageAttr)
 WARNING_GADGET(DataInvocation)
+WARNING_CONTAINER_GADGET(SpanTwoParamConstructor) // Uses of `std::span(arg0, 
arg1)`
 FIXABLE_GADGET(ULCArraySubscript)  // `DRE[any]` in an Unspecified 
Lvalue Context
 FIXABLE_GADGET(DerefSimplePtrArithFixable)
 FIXABLE_GADGET(PointerDereference)
@@ -43,4 +50,5 @@ FIXABLE_GADGET(PointerInit)
 
 #undef FIXABLE_GADGET
 #undef WARNING_GADGET
+#undef WARNING_CONTAINER_GADGET
 #undef GADGET
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index e54f969c19039d..438c2fcdb1c77b 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12075,6 +12075,9 @@ def note_unsafe_buffer_variable_fixit_together : Note<
   "%select{|, and change %2 to safe types to make function %4 bounds-safe}3">;
 def note_safe_buffer_usage_suggestions_disabled : Note<
   "pass -fsafe-buffer-usage-suggestions to receive code hardening 
suggestions">;
+def warn_unsafe_buffer_usage_in_container : Warning<
+  "the two-parameter std::span construction is unsafe as it can introduce 
mismatch between buffer size and the bound information">,
+  InGroup, DefaultIgnore;
 #ifndef NDEBUG
 // Not a user-facing diagnostic. Useful for debugging false negatives in
 // -fsafe-buffer-usage-suggestions (i.e. lack of -Wunsafe-buffer-usage fixits).
diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 724c4304a07242..3b6d69cac1afd8 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -232,6 +232,11 @@ AST_MATCHER_P(Stmt, notInSafeBufferOptOut, const 
Unsa

[clang] [Clang][Sema] fix outline member function template with default align crash (PR #78400)

2024-01-23 Thread Qizhi Hu via cfe-commits


@@ -859,6 +859,9 @@ Bug Fixes in This Version
   Fixes (`#78290 `_)
 - Fixed assertion failure with deleted overloaded unary operators.
   Fixes (`#78314 `_)
+- Fix crash when specialize out-of-line member function with default parameter

jcsxky wrote:

Yeah, thanks for your guidance of grammar and expression! I have update the 
note according to you suggestion.

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


[lld] [clang-tools-extra] [llvm] [clang] [Object][Wasm] Allow parsing of GC types in type and table sections (PR #79235)

2024-01-23 Thread Derek Schuff via cfe-commits

https://github.com/dschuff created 
https://github.com/llvm/llvm-project/pull/79235

This change allows a WasmObjectFile to be created from a wasm file even if it 
uses typed funcrefs and GC types.
It does not significantly change how lib/Object models its various internal 
types (e.g. WasmSignature,
WasmElemSegment), so LLVM does not really "support" or understand such files, 
but it is sufficient to parse
the type, global and element sections, discarding types that are not 
understood. This is useful for low-level binary
tools such as nm and objcopy, which use only limited aspects of the binary 
(such as function definitions) or deal
with sections as opaque blobs.

This is done by allowing `WasmValType` to have a value of `OTHERREF` 
(representing any unmodeled reference
type), and adding a field to `WasmSignature` indicating it's a placeholder for 
an unmodeled reference type (since
there is a 1:1 correspondence between WasmSignature objects and types in the 
type section). 
Then the object file parsers for the type and element sections are expanded to 
parse encoded reference types and
discard any unmodeled fields.

>From 976c98f631e5ed48bb18accbe59c9babd354a924 Mon Sep 17 00:00:00 2001
From: Derek Schuff 
Date: Wed, 3 Jan 2024 09:06:37 -0800
Subject: [PATCH 01/11] parse types

---
 llvm/include/llvm/BinaryFormat/Wasm.h |  8 +++
 llvm/lib/Object/WasmObjectFile.cpp| 83 +++
 2 files changed, 91 insertions(+)

diff --git a/llvm/include/llvm/BinaryFormat/Wasm.h 
b/llvm/include/llvm/BinaryFormat/Wasm.h
index c7658cc7b7432b3..89499a61b76c8c3 100644
--- a/llvm/include/llvm/BinaryFormat/Wasm.h
+++ b/llvm/include/llvm/BinaryFormat/Wasm.h
@@ -265,7 +265,13 @@ enum : unsigned {
   WASM_TYPE_V128 = 0x7B,
   WASM_TYPE_FUNCREF = 0x70,
   WASM_TYPE_EXTERNREF = 0x6F,
+  WASM_TYPE_NULLABLE = 0x63,
   WASM_TYPE_FUNC = 0x60,
+  WASM_TYPE_ARRAY = 0x5E, // Composite types, not used for codegen
+  WASM_TYPE_STRUCT = 0x5F,
+  WASM_TYPE_SUB = 0x50,
+  WASM_TYPE_SUB_FINAL = 0x4F,
+  WASM_TYPE_REC = 0x4E,
   WASM_TYPE_NORESULT = 0x40, // for blocks with no result values
 };
 
@@ -431,11 +437,13 @@ enum class ValType {
   V128 = WASM_TYPE_V128,
   FUNCREF = WASM_TYPE_FUNCREF,
   EXTERNREF = WASM_TYPE_EXTERNREF,
+  OTHERREF,
 };
 
 struct WasmSignature {
   SmallVector Returns;
   SmallVector Params;
+  enum {Function, Other} Kind = Function;
   // Support empty and tombstone instances, needed by DenseMap.
   enum { Plain, Empty, Tombstone } State = Plain;
 
diff --git a/llvm/lib/Object/WasmObjectFile.cpp 
b/llvm/lib/Object/WasmObjectFile.cpp
index 94cd96968ff2010..3d2b06342481aa0 100644
--- a/llvm/lib/Object/WasmObjectFile.cpp
+++ b/llvm/lib/Object/WasmObjectFile.cpp
@@ -21,6 +21,7 @@
 #include "llvm/Support/Endian.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/Format.h"
 #include "llvm/Support/LEB128.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/TargetParser/SubtargetFeature.h"
@@ -29,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define DEBUG_TYPE "wasm-object"
 
@@ -1104,26 +1106,107 @@ Error WasmObjectFile::parseCustomSection(WasmSection 
&Sec, ReadContext &Ctx) {
 }
 
 Error WasmObjectFile::parseTypeSection(ReadContext &Ctx) {
+  auto parseFieldDef = [&]() {
+int32_t TypeCode = readVarint32((Ctx));
+uint32_t Mutability = readVaruint32(Ctx);
+  };
+  auto parseRecType = [&]() {
+uint8_t Form = readUint8(Ctx);
+if (Form == wasm::WASM_TYPE_REC) {
+  uint32_t Size = readVaruint32(Ctx);
+  assert(Size > 0); // TODO real errors here and below
+  Form = readVaruint32(Ctx);
+}
+if (Form == wasm::WASM_TYPE_SUB || Form == wasm::WASM_TYPE_SUB_FINAL) {
+  uint32_t Supers = readVaruint32(Ctx);
+  if (Supers > 0) {
+assert(Supers == 1);
+uint32_t SuperIndex = readVaruint32(Ctx);
+  }
+  Form = readVaruint32(Ctx);
+}
+if (Form == wasm::WASM_TYPE_STRUCT) {
+  uint32_t NumFields = readVaruint32(Ctx);
+  for (size_t i = 0; i < NumFields; i++) {
+parseFieldDef();
+  }
+} else if (Form == wasm::WASM_TYPE_ARRAY) {
+  parseFieldDef();
+}
+
+  };
+  auto parseParamType = [&](uint32_t code) -> wasm::ValType {
+switch(code) {
+  case wasm::WASM_TYPE_I32:
+  case wasm::WASM_TYPE_I64:
+  case wasm::WASM_TYPE_F32:
+  case wasm::WASM_TYPE_F64:
+  case wasm::WASM_TYPE_V128:
+  case wasm::WASM_TYPE_FUNCREF:
+  case wasm::WASM_TYPE_EXTERNREF:
+return wasm::ValType(code);
+}
+  };
   uint32_t Count = readVaruint32(Ctx);
   Signatures.reserve(Count);
   while (Count--) {
 wasm::WasmSignature Sig;
 uint8_t Form = readUint8(Ctx);
+llvm::errs() << llvm::format("Top Count %d form %x", Count, Form) << '\n';
+if (Form == wasm::WASM_TYPE_REC) {
+  uint32_t Size = readVaruint32(Ctx);
+  assert(Size > 0); // TODO real errors here and below
+  Form = readVaruint32(Ctx);
+  wasm::

[llvm] [clang] [clang-tools-extra] [LoongArch] Insert nops and emit align reloc when handle alignment directive (PR #72962)

2024-01-23 Thread Lu Weining via cfe-commits

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


[clang] [Clang][Sema] fix outline member function template with default align crash (PR #78400)

2024-01-23 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/78400

>From 71660611976c4f21f71ebfe509fc021b1e3586e2 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Wed, 17 Jan 2024 14:16:34 +0800
Subject: [PATCH] [Clang][Sema] fix outline member function template with
 default align crash

---
 clang/docs/ReleaseNotes.rst   |  4 ++
 clang/lib/Sema/SemaTemplateInstantiate.cpp| 13 -
 clang/test/SemaTemplate/default-parm-init.cpp | 50 +++
 3 files changed, 65 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/SemaTemplate/default-parm-init.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 060bc7669b72a5..53bbf582420837 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -859,6 +859,10 @@ Bug Fixes in This Version
   Fixes (`#78290 `_)
 - Fixed assertion failure with deleted overloaded unary operators.
   Fixes (`#78314 `_)
+- Fix a crash when specializing an out-of-line member function with a default
+  parameter where we did an incorrect specialization of the initialization of
+  the default parameter.
+  Fixes (`#68490 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index e12186d7d82f8d..41e58b91de4e08 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3049,6 +3049,7 @@ bool Sema::SubstDefaultArgument(
 //   default argument expression appears.
 ContextRAII SavedContext(*this, FD);
 std::unique_ptr LIS;
+MultiLevelTemplateArgumentList NewTemplateArgs = TemplateArgs;
 
 if (ForCallExpr) {
   // When instantiating a default argument due to use in a call expression,
@@ -3061,11 +3062,19 @@ bool Sema::SubstDefaultArgument(
   /*ForDefinition*/ false);
   if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs))
 return true;
+  if (FD->isOutOfLine()) {
+TemplateArgumentList *CurrentTemplateArgumentList =
+TemplateArgumentList::CreateCopy(getASTContext(),
+ TemplateArgs.getInnermost());
+NewTemplateArgs = getTemplateInstantiationArgs(
+FD, FD->getDeclContext(), /*Final=*/false,
+CurrentTemplateArgumentList, /*RelativeToPrimary=*/true);
+  }
 }
 
 runWithSufficientStackSpace(Loc, [&] {
-  Result = SubstInitializer(PatternExpr, TemplateArgs,
-/*DirectInit*/false);
+  Result = SubstInitializer(PatternExpr, NewTemplateArgs,
+/*DirectInit*/ false);
 });
   }
   if (Result.isInvalid())
diff --git a/clang/test/SemaTemplate/default-parm-init.cpp 
b/clang/test/SemaTemplate/default-parm-init.cpp
new file mode 100644
index 00..4bcea7eaa10176
--- /dev/null
+++ b/clang/test/SemaTemplate/default-parm-init.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+// expected-no-diagnostics
+
+template
+struct Problem{
+  template
+  constexpr int FuncAlign(int param = alignof(FunctionTemplateParam));
+
+  template
+  constexpr int FuncSizeof(int param = sizeof(FunctionTemplateParam));
+
+  template
+  constexpr int FuncAlign2(int param = alignof(TemplateParam));
+
+  template
+  constexpr int FuncSizeof2(int param = sizeof(TemplateParam));
+};
+
+template <>
+template
+constexpr int Problem::FuncAlign(int param) {
+   return param;
+}
+
+template <>
+template
+constexpr int Problem::FuncSizeof(int param) {
+   return param;
+}
+
+template <>
+template
+constexpr int Problem::FuncAlign2(int param) {
+   return param;
+}
+
+template <>
+template
+constexpr int Problem::FuncSizeof2(int param) {
+   return param;
+}
+
+int main(){
+Problem p = {};
+static_assert(p.FuncAlign() == alignof(char));
+static_assert(p.FuncSizeof() == sizeof(char));
+static_assert(p.FuncAlign2() == alignof(int));
+static_assert(p.FuncSizeof2() == sizeof(int));
+}

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


[llvm] [clang] [clang-tools-extra] [LoongArch] Insert nops and emit align reloc when handle alignment directive (PR #72962)

2024-01-23 Thread Lu Weining via cfe-commits

https://github.com/SixWeining updated 
https://github.com/llvm/llvm-project/pull/72962

>From 4985669d2de986d595c791c04a42e84c1f080c01 Mon Sep 17 00:00:00 2001
From: Jinyang He 
Date: Tue, 9 Jan 2024 15:35:17 +0800
Subject: [PATCH 1/2] [LoongArch] Insert nops and emit align reloc when handle
 alignment directive

Refer to RISCV, we will fix up the alignment if linker relaxation changes
code size and breaks alignment. Insert enough Nops and emit R_LARCH_ALIGN
relocation type so that linker could satisfy the alignment by removing Nops.
It does so only in sections with the SHF_EXECINSTR flag.

In LoongArch psABI v2.30, R_LARCH_ALIGN requires symbol index. The
lowest 8 bits of addend represent alignment and the other bits of
addend represent the maximum number of bytes to emit.
---
 .../MCTargetDesc/LoongArchAsmBackend.cpp  | 69 +++
 .../MCTargetDesc/LoongArchAsmBackend.h| 15 
 .../MCTargetDesc/LoongArchFixupKinds.h|  2 +
 .../Relocations/align-non-executable.s| 22 ++
 .../MC/LoongArch/Relocations/relax-addsub.s   | 15 +++-
 .../MC/LoongArch/Relocations/relax-align.s| 53 ++
 6 files changed, 174 insertions(+), 2 deletions(-)
 create mode 100644 llvm/test/MC/LoongArch/Relocations/align-non-executable.s
 create mode 100644 llvm/test/MC/LoongArch/Relocations/relax-align.s

diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp 
b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
index 518f6b10edabe8..0f686643622891 100644
--- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
+++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
@@ -16,8 +16,11 @@
 #include "llvm/MC/MCAssembler.h"
 #include "llvm/MC/MCContext.h"
 #include "llvm/MC/MCELFObjectWriter.h"
+#include "llvm/MC/MCExpr.h"
+#include "llvm/MC/MCSection.h"
 #include "llvm/MC/MCValue.h"
 #include "llvm/Support/EndianStream.h"
+#include "llvm/Support/MathExtras.h"
 
 #define DEBUG_TYPE "loongarch-asmbackend"
 
@@ -174,6 +177,72 @@ void LoongArchAsmBackend::applyFixup(const MCAssembler 
&Asm,
   }
 }
 
+// Linker relaxation may change code size. We have to insert Nops
+// for .align directive when linker relaxation enabled. So then Linker
+// could satisfy alignment by removing Nops.
+// The function returns the total Nops Size we need to insert.
+bool LoongArchAsmBackend::shouldInsertExtraNopBytesForCodeAlign(
+const MCAlignFragment &AF, unsigned &Size) {
+  // Calculate Nops Size only when linker relaxation enabled.
+  const MCSubtargetInfo *STI = AF.getSubtargetInfo();
+  if (!STI->hasFeature(LoongArch::FeatureRelax))
+return false;
+
+  // Ignore alignment if the minimum Nop size is less than the MaxBytesToEmit.
+  const unsigned MinNopLen = 4;
+  if (AF.getMaxBytesToEmit() < MinNopLen)
+return false;
+  Size = AF.getAlignment().value() - MinNopLen;
+  return AF.getAlignment() > MinNopLen;
+}
+
+// We need to insert R_LARCH_ALIGN relocation type to indicate the
+// position of Nops and the total bytes of the Nops have been inserted
+// when linker relaxation enabled.
+// The function inserts fixup_loongarch_align fixup which eventually will
+// transfer to R_LARCH_ALIGN relocation type.
+// The improved R_LARCH_ALIGN requires symbol index. The lowest 8 bits of
+// addend represent alignment and the other bits of addend represent the
+// maximum number of bytes to emit. The maximum number of bytes is zero
+// means ignore the emit limit.
+bool LoongArchAsmBackend::shouldInsertFixupForCodeAlign(
+MCAssembler &Asm, const MCAsmLayout &Layout, MCAlignFragment &AF) {
+  // Insert the fixup only when linker relaxation enabled.
+  const MCSubtargetInfo *STI = AF.getSubtargetInfo();
+  if (!STI->hasFeature(LoongArch::FeatureRelax))
+return false;
+
+  // Calculate total Nops we need to insert. If there are none to insert
+  // then simply return.
+  unsigned Count;
+  if (!shouldInsertExtraNopBytesForCodeAlign(AF, Count))
+return false;
+
+  MCSection *Sec = AF.getParent();
+  MCContext &Ctx = Asm.getContext();
+  const MCExpr *Dummy = MCConstantExpr::create(0, Ctx);
+  // Create fixup_loongarch_align fixup.
+  MCFixup Fixup =
+  MCFixup::create(0, Dummy, MCFixupKind(LoongArch::fixup_loongarch_align));
+  const MCSymbolRefExpr *MCSym = getSecToAlignSym()[Sec];
+  if (MCSym == nullptr) {
+// Create a symbol and make the value of symbol is zero.
+MCSymbol *Sym = Ctx.createTempSymbol(".Lla-relax-align", false);
+Sym->setFragment(&*Sec->getBeginSymbol()->getFragment());
+Asm.registerSymbol(*Sym);
+MCSym = MCSymbolRefExpr::create(Sym, Ctx);
+getSecToAlignSym()[Sec] = MCSym;
+  }
+
+  uint64_t FixedValue = 0;
+  unsigned Lo = Log2_64(Count) + 1;
+  unsigned Hi = AF.getMaxBytesToEmit() >= Count ? 0 : AF.getMaxBytesToEmit();
+  MCValue Value = MCValue::get(MCSym, nullptr, Hi << 8 | Lo);
+  Asm.getWriter().recordRelocation(Asm, Layout, &AF, Fixup, Value, FixedValue);
+
+  return true;
+}
+
 boo

[clang] [RISCV][clang] Optimize memory usage of intrinsic lookup table (PR #77487)

2024-01-23 Thread Craig Topper via cfe-commits


@@ -416,8 +416,10 @@ class RVVIntrinsic {
   RVVTypePtr getOutputType() const { return OutputType; }
   const RVVTypes &getInputTypes() const { return InputTypes; }
   llvm::StringRef getBuiltinName() const { return BuiltinName; }
-  llvm::StringRef getName() const { return Name; }
-  llvm::StringRef getOverloadedName() const { return OverloadedName; }
+  llvm::StringRef getName() const { return "__riscv_" + Name; }

topperc wrote:

Sure

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


[llvm] [clang] [clang-tools-extra] [PGO] Sampled instrumentation in PGO to speed up instrumentation binary (PR #69535)

2024-01-23 Thread via cfe-commits

https://github.com/xur-llvm updated 
https://github.com/llvm/llvm-project/pull/69535

>From 62728756fd56e3427376268c4178765950a27636 Mon Sep 17 00:00:00 2001
From: Rong Xu 
Date: Wed, 18 Oct 2023 15:13:15 -0700
Subject: [PATCH 1/2] [PGO] Sampled instrumentation in PGO to speed up
 instrumentation binary

PGO instrumentation binary can be very slow comparing to the
non-instrumented binary. It's not uncommon to see 10x slowdown
for highly threaded programs, due to data race of false sharing
to the counters.

This patch uses sampling in PGO instrumentation to speed up
instrumentation binary. The basic idea is the same as one:
here: https://reviews.llvm.org/D63949

This patch makes some improvements so that we only use one
condition. We now fix the WholeDuring at 65536 and use the
wraparound of unsigned short.

With this sampled instrumentation, the binary runs much
faster. We measure 5x speedup using the default duration.
We now only see about 20% to 30% slow down (comparing to
8 to 10x slowdown without sampling).

The profile quality is pretty good with sampling: the edge
counts usually report >90% overlap.

For the apps that program behaviors change due to binary
speed, sampling instrumentation can improve the performance.
We have observed some apps getting up ~2% improvement in PGO.

One potential issue of this patch is the increased binary
size and compilation time.
---
 .../llvm/ProfileData/InstrProfData.inc|   1 +
 .../include/llvm/Transforms/Instrumentation.h |   6 +
 .../Instrumentation/InstrProfiling.h  |   6 +
 .../Instrumentation/PGOInstrumentation.h  |   6 +-
 llvm/lib/Passes/PassBuilderPipelines.cpp  |  10 +-
 .../Instrumentation/InstrProfiling.cpp| 131 --
 .../Instrumentation/PGOInstrumentation.cpp|   2 +
 .../PGOProfile/Inputs/cspgo_bar_sample.ll |  82 +++
 .../PGOProfile/counter_promo_sampling.ll  |  78 +++
 .../Transforms/PGOProfile/cspgo_sample.ll | 112 +++
 .../Transforms/PGOProfile/instrprof_sample.ll |  47 +++
 11 files changed, 463 insertions(+), 18 deletions(-)
 create mode 100644 llvm/test/Transforms/PGOProfile/Inputs/cspgo_bar_sample.ll
 create mode 100644 llvm/test/Transforms/PGOProfile/counter_promo_sampling.ll
 create mode 100644 llvm/test/Transforms/PGOProfile/cspgo_sample.ll
 create mode 100644 llvm/test/Transforms/PGOProfile/instrprof_sample.ll

diff --git a/llvm/include/llvm/ProfileData/InstrProfData.inc 
b/llvm/include/llvm/ProfileData/InstrProfData.inc
index 13be2753e514ef..6294505ac39685 100644
--- a/llvm/include/llvm/ProfileData/InstrProfData.inc
+++ b/llvm/include/llvm/ProfileData/InstrProfData.inc
@@ -676,6 +676,7 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
 #define INSTR_PROF_PROFILE_RUNTIME_VAR __llvm_profile_runtime
 #define INSTR_PROF_PROFILE_COUNTER_BIAS_VAR __llvm_profile_counter_bias
 #define INSTR_PROF_PROFILE_SET_TIMESTAMP __llvm_profile_set_timestamp
+#define INSTR_PROF_PROFILE_SAMPLING_VAR __llvm_profile_sampling
 
 /* The variable that holds the name of the profile data
  * specified via command line. */
diff --git a/llvm/include/llvm/Transforms/Instrumentation.h 
b/llvm/include/llvm/Transforms/Instrumentation.h
index 392983a1984445..76d4e1de75154f 100644
--- a/llvm/include/llvm/Transforms/Instrumentation.h
+++ b/llvm/include/llvm/Transforms/Instrumentation.h
@@ -116,12 +116,18 @@ struct InstrProfOptions {
   // Use BFI to guide register promotion
   bool UseBFIInPromotion = false;
 
+  // Use sampling to reduce the profile instrumentation runtime overhead.
+  bool Sampling = false;
+
   // Name of the profile file to use as output
   std::string InstrProfileOutput;
 
   InstrProfOptions() = default;
 };
 
+// Create the variable for profile sampling.
+void createProfileSamplingVar(Module &M);
+
 // Options for sanitizer coverage instrumentation.
 struct SanitizerCoverageOptions {
   enum Type {
diff --git a/llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h 
b/llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
index cb0c055dcb74ae..d0581ff72a1586 100644
--- a/llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
+++ b/llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
@@ -86,6 +86,9 @@ class InstrProfiling : public PassInfoMixin {
   /// Returns true if profile counter update register promotion is enabled.
   bool isCounterPromotionEnabled() const;
 
+  /// Return true if profile sampling is enabled.
+  bool isSamplingEnabled() const;
+
   /// Count the number of instrumented value sites for the function.
   void computeNumValueSiteCounts(InstrProfValueProfileInst *Ins);
 
@@ -109,6 +112,9 @@ class InstrProfiling : public PassInfoMixin 
{
   /// acts on.
   Value *getCounterAddress(InstrProfInstBase *I);
 
+  /// Lower the incremental instructions under profile sampling predicates.
+  void doSampling(Instruction *I);
+
   /// Get the region counters for an increment, creating them if necessary.
   ///
   

[clang-tools-extra] [clang] [llvm] [AsmPrinter] Remove mbb-profile-dump flag (PR #76595)

2024-01-23 Thread Aiden Grossman via cfe-commits

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


[clang-tools-extra] [llvm] [clang] [AsmPrinter] Remove mbb-profile-dump flag (PR #76595)

2024-01-23 Thread Aiden Grossman via cfe-commits

https://github.com/boomanaiden154 updated 
https://github.com/llvm/llvm-project/pull/76595

>From 55cf94d98c38cd2b5cd8fbf76e5fd83b5a47f4af Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Fri, 29 Dec 2023 16:14:15 -0800
Subject: [PATCH] [AsmPrinter] Remove mbb-profile-dump flag

Now that the work embedding PGO information in SHT_LLVM_BB_ADDR_MAP ELF
sections has landed, there is no longer a need to keep around the
mbb-profile-dump flag.
---
 llvm/include/llvm/CodeGen/AsmPrinter.h   |  4 --
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp   | 51 -
 llvm/test/CodeGen/Generic/bb-profile-dump.ll | 59 
 3 files changed, 114 deletions(-)
 delete mode 100644 llvm/test/CodeGen/Generic/bb-profile-dump.ll

diff --git a/llvm/include/llvm/CodeGen/AsmPrinter.h 
b/llvm/include/llvm/CodeGen/AsmPrinter.h
index 5ec246ee7015c4..fbd198a75a2436 100644
--- a/llvm/include/llvm/CodeGen/AsmPrinter.h
+++ b/llvm/include/llvm/CodeGen/AsmPrinter.h
@@ -236,10 +236,6 @@ class AsmPrinter : public MachineFunctionPass {
   /// split stack prologue.
   bool HasNoSplitStack = false;
 
-  /// Raw FDOstream for outputting machine basic block frequncies if the
-  /// --mbb-profile-dump flag is set for downstream cost modelling applications
-  std::unique_ptr MBBProfileDumpFileOutput;
-
 protected:
   explicit AsmPrinter(TargetMachine &TM, std::unique_ptr Streamer);
 
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp 
b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 4dd27702786e42..93857b05488b77 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -133,13 +133,6 @@ using namespace llvm;
 
 #define DEBUG_TYPE "asm-printer"
 
-static cl::opt BasicBlockProfileDump(
-"mbb-profile-dump", cl::Hidden,
-cl::desc("Basic block profile dump for external cost modelling. If "
- "matching up BBs with afterwards, the compilation must be "
- "performed with -basic-block-sections=labels. Enabling this "
- "flag during in-process ThinLTO is not supported."));
-
 const char DWARFGroupName[] = "dwarf";
 const char DWARFGroupDescription[] = "DWARF Emission";
 const char DbgTimerName[] = "emit";
@@ -624,16 +617,6 @@ bool AsmPrinter::doInitialization(Module &M) {
 HI.Handler->beginModule(&M);
   }
 
-  if (!BasicBlockProfileDump.empty()) {
-std::error_code PossibleFileError;
-MBBProfileDumpFileOutput = std::make_unique(
-BasicBlockProfileDump, PossibleFileError);
-if (PossibleFileError) {
-  M.getContext().emitError("Failed to open file for MBB Profile Dump: " +
-   PossibleFileError.message() + "\n");
-}
-  }
-
   return false;
 }
 
@@ -1952,40 +1935,6 @@ void AsmPrinter::emitFunctionBody() {
 OutStreamer->getCommentOS() << "-- End function\n";
 
   OutStreamer->addBlankLine();
-
-  // Output MBB ids, function names, and frequencies if the flag to dump
-  // MBB profile information has been set
-  if (MBBProfileDumpFileOutput && !MF->empty() &&
-  MF->getFunction().getEntryCount()) {
-if (!MF->hasBBLabels()) {
-  MF->getContext().reportError(
-  SMLoc(),
-  "Unable to find BB labels for MBB profile dump. -mbb-profile-dump "
-  "must be called with -basic-block-sections=labels");
-} else {
-  MachineBlockFrequencyInfo &MBFI =
-  getAnalysis().getBFI();
-  // The entry count and the entry basic block frequency aren't the same. 
We
-  // want to capture "absolute" frequencies, i.e. the frequency with which 
a
-  // MBB is executed when the program is executed. From there, we can 
derive
-  // Function-relative frequencies (divide by the value for the first MBB).
-  // We also have the information about frequency with which functions
-  // were called. This helps, for example, in a type of integration tests
-  // where we want to cross-validate the compiler's profile with a real
-  // profile.
-  // Using double precision because uint64 values used to encode mbb
-  // "frequencies" may be quite large.
-  const double EntryCount =
-  static_cast(MF->getFunction().getEntryCount()->getCount());
-  for (const auto &MBB : *MF) {
-const double MBBRelFreq = MBFI.getBlockFreqRelativeToEntryBlock(&MBB);
-const double AbsMBBFreq = MBBRelFreq * EntryCount;
-*MBBProfileDumpFileOutput.get()
-<< MF->getName() << "," << MBB.getBBID()->BaseID << ","
-<< AbsMBBFreq << "\n";
-  }
-}
-  }
 }
 
 /// Compute the number of Global Variables that uses a Constant.
diff --git a/llvm/test/CodeGen/Generic/bb-profile-dump.ll 
b/llvm/test/CodeGen/Generic/bb-profile-dump.ll
deleted file mode 100644
index 7391a6ee6f9128..00
--- a/llvm/test/CodeGen/Generic/bb-profile-dump.ll
+++ /dev/null
@@ -1,59 +0,0 @@
-; REQUIRES: x86-registered-target
-;
-; Check that the basic block profile dump outputs data and in the correct
-; fo

[llvm] [clang] [Clang] Correct __builtin_dynamic_object_size for subobject types (PR #78526)

2024-01-23 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

> maybe we could add the subtype as part of the llvm.objectsize intrinsic and 
> use that instead of grappling with the whole object's type

I'm not sure I follow; if you know the object's type, doesn't that mean you 
also know its size?

>(I don't readily know of any transformation that changes a structure's layout. 
>Does it exist?)

Any such transform has to reason about all the uses, so the llvm.objectsize 
call itself would prevent the transform from happening.

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


[clang] [Driver] Test ignored target-specific options for AMDGPU/NVPTX (PR #79222)

2024-01-23 Thread Artem Belevich via cfe-commits


@@ -0,0 +1,7 @@
+/// Some target-specific options are ignored for GPU, so %clang exits with 
code 0.
+// DEFINE: %{gpu_opts} = --cuda-gpu-arch=sm_60 
--cuda-path=%S/Inputs/CUDA/usr/local/cuda --no-cuda-version-check
+// DEFINE: %{check} = %clang -### -c %{gpu_opts} -mcmodel=medium %s
+// RUN: %{check} -fbasic-block-sections=all

Artem-B wrote:

You may want to either rename the file into `.cu` or use `-x cuda`. Otherwise 
you're running a plain C compilation.

Also, what exactly are we checking here? With `-###` CC1 sub-compilations do 
not run and, I think, that's where unsupported options were triggering 
warning/errors. 

You may want to do two actual compilations, one with `--cuda-host-only` and one 
with `--cuda-device-only -s`. 

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


[clang] [Driver] Test ignored target-specific options for AMDGPU/NVPTX (PR #79222)

2024-01-23 Thread Artem Belevich via cfe-commits


@@ -0,0 +1,7 @@
+/// Some target-specific options are ignored for GPU, so %clang exits with 
code 0.
+// DEFINE: %{gpu_opts} = --cuda-gpu-arch=sm_60 
--cuda-path=%S/Inputs/CUDA/usr/local/cuda --no-cuda-version-check

Artem-B wrote:

For the purpose of warning checking, we can drop this altogether and use 
`-nogpuinc -nogpulib` . Whatever default GPU we end up targeting is also 
irrelevant.

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


[libc] [openmp] [clang] [flang] [clang-tools-extra] [lldb] [libcxx] [lld] [compiler-rt] [llvm] [PGO][OpenMP] Instrumentation for GPU devices (PR #76587)

2024-01-23 Thread Ethan Luis McDonough via cfe-commits

https://github.com/EthanLuisMcDonough updated 
https://github.com/llvm/llvm-project/pull/76587

>From 530eb982b9770190377bb0bd09c5cb715f34d484 Mon Sep 17 00:00:00 2001
From: Ethan Luis McDonough 
Date: Fri, 15 Dec 2023 20:38:38 -0600
Subject: [PATCH 01/13] Add profiling functions to libomptarget

---
 .../include/llvm/Frontend/OpenMP/OMPKinds.def |  3 +++
 openmp/libomptarget/DeviceRTL/CMakeLists.txt  |  2 ++
 .../DeviceRTL/include/Profiling.h | 21 +++
 .../libomptarget/DeviceRTL/src/Profiling.cpp  | 19 +
 4 files changed, 45 insertions(+)
 create mode 100644 openmp/libomptarget/DeviceRTL/include/Profiling.h
 create mode 100644 openmp/libomptarget/DeviceRTL/src/Profiling.cpp

diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPKinds.def 
b/llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
index d22d2a8e948b00e..1d887d5cb581276 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
@@ -503,6 +503,9 @@ __OMP_RTL(__kmpc_barrier_simple_generic, false, Void, 
IdentPtr, Int32)
 __OMP_RTL(__kmpc_warp_active_thread_mask, false, Int64,)
 __OMP_RTL(__kmpc_syncwarp, false, Void, Int64)
 
+__OMP_RTL(__llvm_profile_register_function, false, Void, VoidPtr)
+__OMP_RTL(__llvm_profile_register_names_function, false, Void, VoidPtr, Int64)
+
 __OMP_RTL(__last, false, Void, )
 
 #undef __OMP_RTL
diff --git a/openmp/libomptarget/DeviceRTL/CMakeLists.txt 
b/openmp/libomptarget/DeviceRTL/CMakeLists.txt
index 1ce3e1e40a80ab4..55ee15d068c67b7 100644
--- a/openmp/libomptarget/DeviceRTL/CMakeLists.txt
+++ b/openmp/libomptarget/DeviceRTL/CMakeLists.txt
@@ -89,6 +89,7 @@ set(include_files
   ${include_directory}/Interface.h
   ${include_directory}/LibC.h
   ${include_directory}/Mapping.h
+  ${include_directory}/Profiling.h
   ${include_directory}/State.h
   ${include_directory}/Synchronization.h
   ${include_directory}/Types.h
@@ -104,6 +105,7 @@ set(src_files
   ${source_directory}/Mapping.cpp
   ${source_directory}/Misc.cpp
   ${source_directory}/Parallelism.cpp
+  ${source_directory}/Profiling.cpp
   ${source_directory}/Reduction.cpp
   ${source_directory}/State.cpp
   ${source_directory}/Synchronization.cpp
diff --git a/openmp/libomptarget/DeviceRTL/include/Profiling.h 
b/openmp/libomptarget/DeviceRTL/include/Profiling.h
new file mode 100644
index 000..68c7744cd60752f
--- /dev/null
+++ b/openmp/libomptarget/DeviceRTL/include/Profiling.h
@@ -0,0 +1,21 @@
+//=== Profiling.h - OpenMP interface -- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+//
+//===--===//
+
+#ifndef OMPTARGET_DEVICERTL_PROFILING_H
+#define OMPTARGET_DEVICERTL_PROFILING_H
+
+extern "C" {
+
+void __llvm_profile_register_function(void *ptr);
+void __llvm_profile_register_names_function(void *ptr, long int i);
+}
+
+#endif
diff --git a/openmp/libomptarget/DeviceRTL/src/Profiling.cpp 
b/openmp/libomptarget/DeviceRTL/src/Profiling.cpp
new file mode 100644
index 000..799477f5e47d273
--- /dev/null
+++ b/openmp/libomptarget/DeviceRTL/src/Profiling.cpp
@@ -0,0 +1,19 @@
+//===--- Profiling.cpp  C++ 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Profiling.h"
+
+#pragma omp begin declare target device_type(nohost)
+
+extern "C" {
+
+void __llvm_profile_register_function(void *ptr) {}
+void __llvm_profile_register_names_function(void *ptr, long int i) {}
+}
+
+#pragma omp end declare target

>From fb067d4ffe604fd68cf90b705db1942bce49dbb1 Mon Sep 17 00:00:00 2001
From: Ethan Luis McDonough 
Date: Sat, 16 Dec 2023 01:18:41 -0600
Subject: [PATCH 02/13] Fix PGO instrumentation for GPU targets

---
 clang/lib/CodeGen/CodeGenPGO.cpp  | 10 --
 .../lib/Transforms/Instrumentation/InstrProfiling.cpp | 11 ---
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp
index 81bf8ea696b1647..edae6885b528ac7 100644
--- a/clang/lib/CodeGen/CodeGenPGO.cpp
+++ b/clang/lib/CodeGen/CodeGenPGO.cpp
@@ -959,8 +959,14 @@ void CodeGenPGO::emitCounterIncrement(CGBuilderTy 
&Builder, const Stmt *S,
 
   unsigned Counter = (*RegionCounterMap)[S];
 
-  llvm::Value *Args[] = {FuncNameVar,
- Builder.getInt64(FunctionHash),
+  // Make sure that pointer to global is passed in with zero addrsp

[clang] [Driver] Test ignored target-specific options for AMDGPU/NVPTX (PR #79222)

2024-01-23 Thread Artem Belevich via cfe-commits

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


[clang] [Driver] Test ignored target-specific options for AMDGPU/NVPTX (PR #79222)

2024-01-23 Thread Artem Belevich via cfe-commits


@@ -0,0 +1,7 @@
+/// Some target-specific options are ignored for GPU, so %clang exits with 
code 0.
+// DEFINE: %{gpu_opts} = --cuda-gpu-arch=sm_60 
--cuda-path=%S/Inputs/CUDA/usr/local/cuda --no-cuda-version-check

Artem-B wrote:

+1 for merging them. I'd also rename 'check' into `offload options`

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


[flang] [libc] [clang-tools-extra] [libcxx] [llvm] [clang] [compiler-rt] [lldb] [lld] [AMDGPU][GFX12] VOP encoding and codegen - add support for v_cvt fp8/… (PR #78414)

2024-01-23 Thread Matt Arsenault via cfe-commits
Mirko =?utf-8?q?Brkušanin?= ,
Mirko =?utf-8?q?Brkušanin?= ,Mirko Brkusanin
 ,Mariusz Sikora 
Message-ID:
In-Reply-To: 


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


[libc] [flang] [clang] [clang-tools-extra] [lldb] [libcxx] [lld] [compiler-rt] [llvm] [AMDGPU][GFX12] VOP encoding and codegen - add support for v_cvt fp8/… (PR #78414)

2024-01-23 Thread Matt Arsenault via cfe-commits
Mirko =?utf-8?q?Brku=C5=A1anin?= ,
Mirko =?utf-8?q?Brku=C5=A1anin?= ,Mirko Brkusanin
 ,Mariusz Sikora 
Message-ID:
In-Reply-To: 


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


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


[compiler-rt] [libcxx] [lldb] [flang] [libc] [lld] [llvm] [clang-tools-extra] [clang] [AMDGPU][GFX12] VOP encoding and codegen - add support for v_cvt fp8/… (PR #78414)

2024-01-23 Thread Matt Arsenault via cfe-commits
Mirko =?utf-8?q?Brkušanin?= ,
Mirko =?utf-8?q?Brkušanin?= ,Mirko Brkusanin
 ,Mariusz Sikora 
Message-ID:
In-Reply-To: 



@@ -8770,6 +8781,22 @@ void AMDGPUAsmParser::cvtVOP3DPP(MCInst &Inst, const 
OperandVector &Operands,
   }
 }
 
+int VdstInIdx = AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::vdst_in);
+if (VdstInIdx == static_cast(Inst.getNumOperands())) {
+  Inst.addOperand(Inst.getOperand(0));
+}
+
+bool IsVOP3CvtSrDpp = Opc == AMDGPU::V_CVT_SR_BF8_F32_e64_dpp8_gfx12 ||
+  Opc == AMDGPU::V_CVT_SR_FP8_F32_e64_dpp8_gfx12 ||
+  Opc == AMDGPU::V_CVT_SR_BF8_F32_e64_dpp_gfx12 ||
+  Opc == AMDGPU::V_CVT_SR_FP8_F32_e64_dpp_gfx12;

arsenm wrote:

I don't want to hold this up for the release, but I do think this needs to be 
revisited. We should really avoid having more random lists of opcodes 

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


[clang] Add support for builtin_verbose_trap (PR #79230)

2024-01-23 Thread Akira Hatanaka via cfe-commits

https://github.com/ahatanak updated 
https://github.com/llvm/llvm-project/pull/79230

>From 92c9fccde29eec10c775fd86b9cf625987e7929d Mon Sep 17 00:00:00 2001
From: Akira Hatanaka 
Date: Tue, 16 Jan 2024 13:18:09 -0800
Subject: [PATCH 1/3] Add support for builtin_verbose_trap

The builtin causes the program to stop its execution abnormally and shows a
human-readable description of the reason for the termination when a debugger is
attached or in a symbolicated crash log.

The motivation for the builtin is explained in the following RFC:

https://discourse.llvm.org/t/rfc-adding-builtin-verbose-trap-string-literal/75845
---
 clang/docs/LanguageExtensions.rst | 48 ++
 clang/docs/ReleaseNotes.rst   |  2 +
 clang/include/clang/AST/Expr.h|  5 ++
 clang/include/clang/Basic/Builtins.def|  1 +
 .../clang/Basic/DiagnosticSemaKinds.td|  2 +
 clang/lib/AST/ExprConstant.cpp| 18 +--
 clang/lib/CodeGen/CGBuiltin.cpp   | 12 +
 clang/lib/CodeGen/CGDebugInfo.cpp | 42 
 clang/lib/CodeGen/CGDebugInfo.h   | 20 
 clang/lib/Sema/SemaChecking.cpp   | 22 +
 .../CodeGenCXX/debug-info-verbose-trap.cpp| 49 +++
 clang/test/SemaCXX/verbose-trap.cpp   | 28 +++
 12 files changed, 246 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/debug-info-verbose-trap.cpp
 create mode 100644 clang/test/SemaCXX/verbose-trap.cpp

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index c1420079f75118d..4526bc2df53e422 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -3379,6 +3379,54 @@ Query for this feature with 
``__has_builtin(__builtin_debugtrap)``.
 
 Query for this feature with ``__has_builtin(__builtin_trap)``.
 
+``__builtin_verbose_trap``
+--
+
+``__builtin_verbose_trap`` causes the program to stop its execution abnormally
+and shows a human-readable description of the reason for the termination when a
+debugger is attached or in a symbolicated crash log.
+
+**Syntax**:
+
+.. code-block:: c++
+
+__builtin_verbose_trap(const char *reason)
+
+**Description**
+
+``__builtin_verbose_trap`` is lowered to the ` ``llvm.trap`` 
`_ builtin.
+Additionally, clang emits debug metadata that represents an artificial inline
+frame whose name encodes the string passed to the builtin, prefixed by a 
"magic"
+prefix.
+
+For example, consider the following code:
+
+.. code-block:: c++
+
+void foo(int* p) {
+  if (p == nullptr)
+__builtin_verbose_trap("Argument_must_not_be_null");
+}
+
+The debug metadata would look as if it were produced for the following code:
+
+.. code-block:: c++
+
+__attribute__((always_inline))
+inline void "__llvm_verbose_trap: Argument_must_not_be_null"() {
+  __builtin_trap();
+}
+
+void foo(int* p) {
+  if (p == nullptr)
+"__llvm_verbose_trap: Argument_must_not_be_null"();
+}
+
+However, the LLVM IR would not actually contain a call to the artificial
+function — it only exists in the debug metadata.
+
+Query for this feature with ``__has_builtin(__builtin_verbose_trap)``.
+
 ``__builtin_nondeterministic_value``
 
 
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6e31849ce16dd40..6da216bbd19250a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -268,6 +268,8 @@ Non-comprehensive list of changes in this release
   and vector types as return value ``19``, to match GCC 14's behavior.
 * The default value of `_MSC_VER` was raised from 1920 to 1933.
 * Since MSVC 19.33 added undocumented attribute ``[[msvc::constexpr]]``, this 
release adds the attribute as well.
+* Support for ``__builtin_verbose_trap`` has been added. See
+  https://clang.llvm.org/docs/LanguageExtensions.html#builtin-functions.
 
 * Added ``#pragma clang fp reciprocal``.
 
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index a41f2d66b37b69d..34d913748d3021f 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -774,6 +774,11 @@ class Expr : public ValueStmt {
  const Expr *PtrExpression, ASTContext &Ctx,
  EvalResult &Status) const;
 
+  /// If the current Expr can be evaluated to a pointer to a null-terminated
+  /// constant string, return the constant string (without the terminating 
null)
+  /// in Result. Return true if it succeeds.
+  bool tryEvaluateString(std::string &Result, ASTContext &Ctx) const;
+
   /// Enumeration used to describe the kind of Null pointer constant
   /// returned from \c isNullPointerConstant().
   enum NullPointerConstantKind {
diff --git a/clang/include/clang/Basic/Builtins.def 
b/clang/inclu

[clang] [Driver] Test ignored target-specific options for AMDGPU/NVPTX (PR #79222)

2024-01-23 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,7 @@
+/// Some target-specific options are ignored for GPU, so %clang exits with 
code 0.
+// DEFINE: %{gpu_opts} = --cuda-gpu-arch=sm_60 
--cuda-path=%S/Inputs/CUDA/usr/local/cuda --no-cuda-version-check

MaskRay wrote:

I think `gpu_opts` can be merged into `%{check}`. `%{check}` should be kept as 
it will become longer soon.

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


[clang] [Driver] Test ignored target-specific options for AMDGPU/NVPTX (PR #79222)

2024-01-23 Thread Arthur Eubanks via cfe-commits


@@ -0,0 +1,7 @@
+/// Some target-specific options are ignored for GPU, so %clang exits with 
code 0.
+// DEFINE: %{gpu_opts} = --cuda-gpu-arch=sm_60 
--cuda-path=%S/Inputs/CUDA/usr/local/cuda --no-cuda-version-check

aeubanks wrote:

these defines seem overkill and harder to read compared to just duplicating the 
command line twice

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


[clang] Add support for builtin_verbose_trap (PR #79230)

2024-01-23 Thread Akira Hatanaka via cfe-commits

https://github.com/ahatanak updated 
https://github.com/llvm/llvm-project/pull/79230

>From 92c9fccde29eec10c775fd86b9cf625987e7929d Mon Sep 17 00:00:00 2001
From: Akira Hatanaka 
Date: Tue, 16 Jan 2024 13:18:09 -0800
Subject: [PATCH 1/2] Add support for builtin_verbose_trap

The builtin causes the program to stop its execution abnormally and shows a
human-readable description of the reason for the termination when a debugger is
attached or in a symbolicated crash log.

The motivation for the builtin is explained in the following RFC:

https://discourse.llvm.org/t/rfc-adding-builtin-verbose-trap-string-literal/75845
---
 clang/docs/LanguageExtensions.rst | 48 ++
 clang/docs/ReleaseNotes.rst   |  2 +
 clang/include/clang/AST/Expr.h|  5 ++
 clang/include/clang/Basic/Builtins.def|  1 +
 .../clang/Basic/DiagnosticSemaKinds.td|  2 +
 clang/lib/AST/ExprConstant.cpp| 18 +--
 clang/lib/CodeGen/CGBuiltin.cpp   | 12 +
 clang/lib/CodeGen/CGDebugInfo.cpp | 42 
 clang/lib/CodeGen/CGDebugInfo.h   | 20 
 clang/lib/Sema/SemaChecking.cpp   | 22 +
 .../CodeGenCXX/debug-info-verbose-trap.cpp| 49 +++
 clang/test/SemaCXX/verbose-trap.cpp   | 28 +++
 12 files changed, 246 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/debug-info-verbose-trap.cpp
 create mode 100644 clang/test/SemaCXX/verbose-trap.cpp

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index c1420079f75118d..4526bc2df53e422 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -3379,6 +3379,54 @@ Query for this feature with 
``__has_builtin(__builtin_debugtrap)``.
 
 Query for this feature with ``__has_builtin(__builtin_trap)``.
 
+``__builtin_verbose_trap``
+--
+
+``__builtin_verbose_trap`` causes the program to stop its execution abnormally
+and shows a human-readable description of the reason for the termination when a
+debugger is attached or in a symbolicated crash log.
+
+**Syntax**:
+
+.. code-block:: c++
+
+__builtin_verbose_trap(const char *reason)
+
+**Description**
+
+``__builtin_verbose_trap`` is lowered to the ` ``llvm.trap`` 
`_ builtin.
+Additionally, clang emits debug metadata that represents an artificial inline
+frame whose name encodes the string passed to the builtin, prefixed by a 
"magic"
+prefix.
+
+For example, consider the following code:
+
+.. code-block:: c++
+
+void foo(int* p) {
+  if (p == nullptr)
+__builtin_verbose_trap("Argument_must_not_be_null");
+}
+
+The debug metadata would look as if it were produced for the following code:
+
+.. code-block:: c++
+
+__attribute__((always_inline))
+inline void "__llvm_verbose_trap: Argument_must_not_be_null"() {
+  __builtin_trap();
+}
+
+void foo(int* p) {
+  if (p == nullptr)
+"__llvm_verbose_trap: Argument_must_not_be_null"();
+}
+
+However, the LLVM IR would not actually contain a call to the artificial
+function — it only exists in the debug metadata.
+
+Query for this feature with ``__has_builtin(__builtin_verbose_trap)``.
+
 ``__builtin_nondeterministic_value``
 
 
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6e31849ce16dd40..6da216bbd19250a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -268,6 +268,8 @@ Non-comprehensive list of changes in this release
   and vector types as return value ``19``, to match GCC 14's behavior.
 * The default value of `_MSC_VER` was raised from 1920 to 1933.
 * Since MSVC 19.33 added undocumented attribute ``[[msvc::constexpr]]``, this 
release adds the attribute as well.
+* Support for ``__builtin_verbose_trap`` has been added. See
+  https://clang.llvm.org/docs/LanguageExtensions.html#builtin-functions.
 
 * Added ``#pragma clang fp reciprocal``.
 
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index a41f2d66b37b69d..34d913748d3021f 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -774,6 +774,11 @@ class Expr : public ValueStmt {
  const Expr *PtrExpression, ASTContext &Ctx,
  EvalResult &Status) const;
 
+  /// If the current Expr can be evaluated to a pointer to a null-terminated
+  /// constant string, return the constant string (without the terminating 
null)
+  /// in Result. Return true if it succeeds.
+  bool tryEvaluateString(std::string &Result, ASTContext &Ctx) const;
+
   /// Enumeration used to describe the kind of Null pointer constant
   /// returned from \c isNullPointerConstant().
   enum NullPointerConstantKind {
diff --git a/clang/include/clang/Basic/Builtins.def 
b/clang/inclu

[llvm] [clang] [Offload] Fix the offloading wrapper when merged multiple times. (PR #79231)

2024-01-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Joseph Huber (jhuber6)


Changes

Summary:
The offloading wrapper is a object file that contains code necessary to
register offloading entries for the given runtime. Currently, we
expected only one of these to be present when we make the final
executable. However, in the case of redistributable linking with `-r` we
can end up with multiple of these being generated before finally
creating the executable.

This patch simply changes the defintiions of these globals to be
mergable. This allows multiples of these to participate in a single link
job. For ELF, we just make the dummy variable internal and used so it
sets up the section as expected. For COFF we make the entries weak_odr
so they merge to a single symbol


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


2 Files Affected:

- (modified) clang/test/Driver/linker-wrapper-image.c (+9-9) 
- (modified) llvm/lib/Frontend/Offloading/Utility.cpp (+11-8) 


``diff
diff --git a/clang/test/Driver/linker-wrapper-image.c 
b/clang/test/Driver/linker-wrapper-image.c
index fa2e59e36b3828a..b5d8ae217a9723d 100644
--- a/clang/test/Driver/linker-wrapper-image.c
+++ b/clang/test/Driver/linker-wrapper-image.c
@@ -14,10 +14,10 @@
 
 //  OPENMP-ELF: @__start_omp_offloading_entries = external hidden constant 
[0 x %struct.__tgt_offload_entry]
 // OPENMP-ELF-NEXT: @__stop_omp_offloading_entries = external hidden constant 
[0 x %struct.__tgt_offload_entry]
-// OPENMP-ELF-NEXT: @__dummy.omp_offloading_entries = hidden constant [0 x 
%struct.__tgt_offload_entry] zeroinitializer, section "omp_offloading_entries"
+// OPENMP-ELF-NEXT: @__dummy.omp_offloading_entries = internal constant [0 x 
%struct.__tgt_offload_entry] zeroinitializer, section "omp_offloading_entries"
 
-//  OPENMP-COFF: @__start_omp_offloading_entries = hidden constant [0 x 
%struct.__tgt_offload_entry] zeroinitializer, section 
"omp_offloading_entries$OA"
-// OPENMP-COFF-NEXT: @__stop_omp_offloading_entries = hidden constant [0 x 
%struct.__tgt_offload_entry] zeroinitializer, section 
"omp_offloading_entries$OZ"
+//  OPENMP-COFF: @__start_omp_offloading_entries = weak_odr hidden 
constant [0 x %struct.__tgt_offload_entry] zeroinitializer, section 
"omp_offloading_entries$OA"
+// OPENMP-COFF-NEXT: @__stop_omp_offloading_entries = weak_odr hidden constant 
[0 x %struct.__tgt_offload_entry] zeroinitializer, section 
"omp_offloading_entries$OZ"
 
 //  OPENMP: @.omp_offloading.device_image = internal unnamed_addr constant 
[[[SIZE:[0-9]+]] x i8] c"\10\FF\10\AD{{.*}}", section ".llvm.offloading", align 
8
 // OPENMP-NEXT: @.omp_offloading.device_images = internal unnamed_addr 
constant [1 x %__tgt_device_image] [%__tgt_device_image { ptr getelementptr 
inbounds ([[[BEGIN:[0-9]+]] x i8], ptr @.omp_offloading.device_image, i64 1, 
i64 0), ptr getelementptr inbounds ([[[END:[0-9]+]] x i8], ptr 
@.omp_offloading.device_image, i64 1, i64 0), ptr 
@__start_omp_offloading_entries, ptr @__stop_omp_offloading_entries }]
@@ -47,10 +47,10 @@
 
 //  CUDA-ELF: @__start_cuda_offloading_entries = external hidden constant 
[0 x %struct.__tgt_offload_entry]
 // CUDA-ELF-NEXT: @__stop_cuda_offloading_entries = external hidden constant 
[0 x %struct.__tgt_offload_entry]
-// CUDA-ELF-NEXT: @__dummy.cuda_offloading_entries = hidden constant [0 x 
%struct.__tgt_offload_entry] zeroinitializer, section "cuda_offloading_entries"
+// CUDA-ELF-NEXT: @__dummy.cuda_offloading_entries = internal constant [0 x 
%struct.__tgt_offload_entry] zeroinitializer, section "cuda_offloading_entries"
 
-//  CUDA-COFF: @__start_cuda_offloading_entries = hidden constant [0 x 
%struct.__tgt_offload_entry] zeroinitializer, section 
"cuda_offloading_entries$OA"
-// CUDA-COFF-NEXT: @__stop_cuda_offloading_entries = hidden constant [0 x 
%struct.__tgt_offload_entry] zeroinitializer, section 
"cuda_offloading_entries$OZ"
+//  CUDA-COFF: @__start_cuda_offloading_entries = weak_odr hidden constant 
[0 x %struct.__tgt_offload_entry] zeroinitializer, section 
"cuda_offloading_entries$OA"
+// CUDA-COFF-NEXT: @__stop_cuda_offloading_entries = weak_odr hidden constant 
[0 x %struct.__tgt_offload_entry] zeroinitializer, section 
"cuda_offloading_entries$OZ"
 
 //  CUDA: @.fatbin_image = internal constant [0 x i8] zeroinitializer, 
section ".nv_fatbin"
 // CUDA-NEXT: @.fatbin_wrapper = internal constant %fatbin_wrapper { i32 
1180844977, i32 1, ptr @.fatbin_image, ptr null }, section ".nvFatBinSegment", 
align 8
@@ -145,10 +145,10 @@
 
 //  HIP-ELF: @__start_hip_offloading_entries = external hidden constant [0 
x %struct.__tgt_offload_entry]
 // HIP-ELF-NEXT: @__stop_hip_offloading_entries = external hidden constant [0 
x %struct.__tgt_offload_entry]
-// HIP-ELF-NEXT: @__dummy.hip_offloading_entries = hidden constant [0 x 
%struct.__tgt_offload_entry] zeroinitializer, section "hip_offloading_entries"
+// HIP-ELF-NEXT: @__dummy.hip_offloading_entries 

[llvm] [clang] [Offload] Fix the offloading wrapper when merged multiple times. (PR #79231)

2024-01-23 Thread Joseph Huber via cfe-commits

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

Summary:
The offloading wrapper is a object file that contains code necessary to
register offloading entries for the given runtime. Currently, we
expected only one of these to be present when we make the final
executable. However, in the case of redistributable linking with `-r` we
can end up with multiple of these being generated before finally
creating the executable.

This patch simply changes the defintiions of these globals to be
mergable. This allows multiples of these to participate in a single link
job. For ELF, we just make the dummy variable internal and used so it
sets up the section as expected. For COFF we make the entries weak_odr
so they merge to a single symbol


>From 1c60daabebbca2189100217d271ff6fada2746e8 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Tue, 23 Jan 2024 17:53:40 -0600
Subject: [PATCH] [Offload] Fix the offloading wrapper when merged multiple
 times.

Summary:
The offloading wrapper is a object file that contains code necessary to
register offloading entries for the given runtime. Currently, we
expected only one of these to be present when we make the final
executable. However, in the case of redistributable linking with `-r` we
can end up with multiple of these being generated before finally
creating the executable.

This patch simply changes the defintiions of these globals to be
mergable. This allows multiples of these to participate in a single link
job. For ELF, we just make the dummy variable internal and used so it
sets up the section as expected. For COFF we make the entries weak_odr
so they merge to a single symbol
---
 clang/test/Driver/linker-wrapper-image.c | 18 +-
 llvm/lib/Frontend/Offloading/Utility.cpp | 19 +++
 2 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/clang/test/Driver/linker-wrapper-image.c 
b/clang/test/Driver/linker-wrapper-image.c
index fa2e59e36b3828a..b5d8ae217a9723d 100644
--- a/clang/test/Driver/linker-wrapper-image.c
+++ b/clang/test/Driver/linker-wrapper-image.c
@@ -14,10 +14,10 @@
 
 //  OPENMP-ELF: @__start_omp_offloading_entries = external hidden constant 
[0 x %struct.__tgt_offload_entry]
 // OPENMP-ELF-NEXT: @__stop_omp_offloading_entries = external hidden constant 
[0 x %struct.__tgt_offload_entry]
-// OPENMP-ELF-NEXT: @__dummy.omp_offloading_entries = hidden constant [0 x 
%struct.__tgt_offload_entry] zeroinitializer, section "omp_offloading_entries"
+// OPENMP-ELF-NEXT: @__dummy.omp_offloading_entries = internal constant [0 x 
%struct.__tgt_offload_entry] zeroinitializer, section "omp_offloading_entries"
 
-//  OPENMP-COFF: @__start_omp_offloading_entries = hidden constant [0 x 
%struct.__tgt_offload_entry] zeroinitializer, section 
"omp_offloading_entries$OA"
-// OPENMP-COFF-NEXT: @__stop_omp_offloading_entries = hidden constant [0 x 
%struct.__tgt_offload_entry] zeroinitializer, section 
"omp_offloading_entries$OZ"
+//  OPENMP-COFF: @__start_omp_offloading_entries = weak_odr hidden 
constant [0 x %struct.__tgt_offload_entry] zeroinitializer, section 
"omp_offloading_entries$OA"
+// OPENMP-COFF-NEXT: @__stop_omp_offloading_entries = weak_odr hidden constant 
[0 x %struct.__tgt_offload_entry] zeroinitializer, section 
"omp_offloading_entries$OZ"
 
 //  OPENMP: @.omp_offloading.device_image = internal unnamed_addr constant 
[[[SIZE:[0-9]+]] x i8] c"\10\FF\10\AD{{.*}}", section ".llvm.offloading", align 
8
 // OPENMP-NEXT: @.omp_offloading.device_images = internal unnamed_addr 
constant [1 x %__tgt_device_image] [%__tgt_device_image { ptr getelementptr 
inbounds ([[[BEGIN:[0-9]+]] x i8], ptr @.omp_offloading.device_image, i64 1, 
i64 0), ptr getelementptr inbounds ([[[END:[0-9]+]] x i8], ptr 
@.omp_offloading.device_image, i64 1, i64 0), ptr 
@__start_omp_offloading_entries, ptr @__stop_omp_offloading_entries }]
@@ -47,10 +47,10 @@
 
 //  CUDA-ELF: @__start_cuda_offloading_entries = external hidden constant 
[0 x %struct.__tgt_offload_entry]
 // CUDA-ELF-NEXT: @__stop_cuda_offloading_entries = external hidden constant 
[0 x %struct.__tgt_offload_entry]
-// CUDA-ELF-NEXT: @__dummy.cuda_offloading_entries = hidden constant [0 x 
%struct.__tgt_offload_entry] zeroinitializer, section "cuda_offloading_entries"
+// CUDA-ELF-NEXT: @__dummy.cuda_offloading_entries = internal constant [0 x 
%struct.__tgt_offload_entry] zeroinitializer, section "cuda_offloading_entries"
 
-//  CUDA-COFF: @__start_cuda_offloading_entries = hidden constant [0 x 
%struct.__tgt_offload_entry] zeroinitializer, section 
"cuda_offloading_entries$OA"
-// CUDA-COFF-NEXT: @__stop_cuda_offloading_entries = hidden constant [0 x 
%struct.__tgt_offload_entry] zeroinitializer, section 
"cuda_offloading_entries$OZ"
+//  CUDA-COFF: @__start_cuda_offloading_entries = weak_odr hidden constant 
[0 x %struct.__tgt_offload_entry] zeroinitializer, section 
"cuda_offloading_entries$OA"
+// CUDA-COFF-NEXT: @__stop_cuda_o

[clang] Add support for builtin_verbose_trap (PR #79230)

2024-01-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Akira Hatanaka (ahatanak)


Changes

The builtin causes the program to stop its execution abnormally and shows a 
human-readable description of the reason for the termination when a debugger is 
attached or in a symbolicated crash log.

The motivation for the builtin is explained in the following RFC:

https://discourse.llvm.org/t/rfc-adding-builtin-verbose-trap-string-literal/75845

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


12 Files Affected:

- (modified) clang/docs/LanguageExtensions.rst (+48) 
- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/include/clang/AST/Expr.h (+5) 
- (modified) clang/include/clang/Basic/Builtins.def (+1) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+2) 
- (modified) clang/lib/AST/ExprConstant.cpp (+15-3) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+12) 
- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+42) 
- (modified) clang/lib/CodeGen/CGDebugInfo.h (+20) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+22) 
- (added) clang/test/CodeGenCXX/debug-info-verbose-trap.cpp (+49) 
- (added) clang/test/SemaCXX/verbose-trap.cpp (+28) 


``diff
diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index c1420079f75118d..4526bc2df53e422 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -3379,6 +3379,54 @@ Query for this feature with 
``__has_builtin(__builtin_debugtrap)``.
 
 Query for this feature with ``__has_builtin(__builtin_trap)``.
 
+``__builtin_verbose_trap``
+--
+
+``__builtin_verbose_trap`` causes the program to stop its execution abnormally
+and shows a human-readable description of the reason for the termination when a
+debugger is attached or in a symbolicated crash log.
+
+**Syntax**:
+
+.. code-block:: c++
+
+__builtin_verbose_trap(const char *reason)
+
+**Description**
+
+``__builtin_verbose_trap`` is lowered to the ` ``llvm.trap`` 
`_ builtin.
+Additionally, clang emits debug metadata that represents an artificial inline
+frame whose name encodes the string passed to the builtin, prefixed by a 
"magic"
+prefix.
+
+For example, consider the following code:
+
+.. code-block:: c++
+
+void foo(int* p) {
+  if (p == nullptr)
+__builtin_verbose_trap("Argument_must_not_be_null");
+}
+
+The debug metadata would look as if it were produced for the following code:
+
+.. code-block:: c++
+
+__attribute__((always_inline))
+inline void "__llvm_verbose_trap: Argument_must_not_be_null"() {
+  __builtin_trap();
+}
+
+void foo(int* p) {
+  if (p == nullptr)
+"__llvm_verbose_trap: Argument_must_not_be_null"();
+}
+
+However, the LLVM IR would not actually contain a call to the artificial
+function — it only exists in the debug metadata.
+
+Query for this feature with ``__has_builtin(__builtin_verbose_trap)``.
+
 ``__builtin_nondeterministic_value``
 
 
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6e31849ce16dd40..6da216bbd19250a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -268,6 +268,8 @@ Non-comprehensive list of changes in this release
   and vector types as return value ``19``, to match GCC 14's behavior.
 * The default value of `_MSC_VER` was raised from 1920 to 1933.
 * Since MSVC 19.33 added undocumented attribute ``[[msvc::constexpr]]``, this 
release adds the attribute as well.
+* Support for ``__builtin_verbose_trap`` has been added. See
+  https://clang.llvm.org/docs/LanguageExtensions.html#builtin-functions.
 
 * Added ``#pragma clang fp reciprocal``.
 
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index a41f2d66b37b69d..34d913748d3021f 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -774,6 +774,11 @@ class Expr : public ValueStmt {
  const Expr *PtrExpression, ASTContext &Ctx,
  EvalResult &Status) const;
 
+  /// If the current Expr can be evaluated to a pointer to a null-terminated
+  /// constant string, return the constant string (without the terminating 
null)
+  /// in Result. Return true if it succeeds.
+  bool tryEvaluateString(std::string &Result, ASTContext &Ctx) const;
+
   /// Enumeration used to describe the kind of Null pointer constant
   /// returned from \c isNullPointerConstant().
   enum NullPointerConstantKind {
diff --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index 4dcbaf8a7beaa65..e9bea088941987f 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -673,6 +673,7 @@ BUILTIN(__builtin_expect_with_probability, "LiLiLid", "ncE")
 BUILTIN(__builtin_prefetch, "vvC*.", "nc")
 BUILTIN(__builtin_readcyclecounter, "ULLi",

[clang] Add support for builtin_verbose_trap (PR #79230)

2024-01-23 Thread Akira Hatanaka via cfe-commits

https://github.com/ahatanak created 
https://github.com/llvm/llvm-project/pull/79230

The builtin causes the program to stop its execution abnormally and shows a 
human-readable description of the reason for the termination when a debugger is 
attached or in a symbolicated crash log.

The motivation for the builtin is explained in the following RFC:

https://discourse.llvm.org/t/rfc-adding-builtin-verbose-trap-string-literal/75845

>From 92c9fccde29eec10c775fd86b9cf625987e7929d Mon Sep 17 00:00:00 2001
From: Akira Hatanaka 
Date: Tue, 16 Jan 2024 13:18:09 -0800
Subject: [PATCH] Add support for builtin_verbose_trap

The builtin causes the program to stop its execution abnormally and shows a
human-readable description of the reason for the termination when a debugger is
attached or in a symbolicated crash log.

The motivation for the builtin is explained in the following RFC:

https://discourse.llvm.org/t/rfc-adding-builtin-verbose-trap-string-literal/75845
---
 clang/docs/LanguageExtensions.rst | 48 ++
 clang/docs/ReleaseNotes.rst   |  2 +
 clang/include/clang/AST/Expr.h|  5 ++
 clang/include/clang/Basic/Builtins.def|  1 +
 .../clang/Basic/DiagnosticSemaKinds.td|  2 +
 clang/lib/AST/ExprConstant.cpp| 18 +--
 clang/lib/CodeGen/CGBuiltin.cpp   | 12 +
 clang/lib/CodeGen/CGDebugInfo.cpp | 42 
 clang/lib/CodeGen/CGDebugInfo.h   | 20 
 clang/lib/Sema/SemaChecking.cpp   | 22 +
 .../CodeGenCXX/debug-info-verbose-trap.cpp| 49 +++
 clang/test/SemaCXX/verbose-trap.cpp   | 28 +++
 12 files changed, 246 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/debug-info-verbose-trap.cpp
 create mode 100644 clang/test/SemaCXX/verbose-trap.cpp

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index c1420079f75118d..4526bc2df53e422 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -3379,6 +3379,54 @@ Query for this feature with 
``__has_builtin(__builtin_debugtrap)``.
 
 Query for this feature with ``__has_builtin(__builtin_trap)``.
 
+``__builtin_verbose_trap``
+--
+
+``__builtin_verbose_trap`` causes the program to stop its execution abnormally
+and shows a human-readable description of the reason for the termination when a
+debugger is attached or in a symbolicated crash log.
+
+**Syntax**:
+
+.. code-block:: c++
+
+__builtin_verbose_trap(const char *reason)
+
+**Description**
+
+``__builtin_verbose_trap`` is lowered to the ` ``llvm.trap`` 
`_ builtin.
+Additionally, clang emits debug metadata that represents an artificial inline
+frame whose name encodes the string passed to the builtin, prefixed by a 
"magic"
+prefix.
+
+For example, consider the following code:
+
+.. code-block:: c++
+
+void foo(int* p) {
+  if (p == nullptr)
+__builtin_verbose_trap("Argument_must_not_be_null");
+}
+
+The debug metadata would look as if it were produced for the following code:
+
+.. code-block:: c++
+
+__attribute__((always_inline))
+inline void "__llvm_verbose_trap: Argument_must_not_be_null"() {
+  __builtin_trap();
+}
+
+void foo(int* p) {
+  if (p == nullptr)
+"__llvm_verbose_trap: Argument_must_not_be_null"();
+}
+
+However, the LLVM IR would not actually contain a call to the artificial
+function — it only exists in the debug metadata.
+
+Query for this feature with ``__has_builtin(__builtin_verbose_trap)``.
+
 ``__builtin_nondeterministic_value``
 
 
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6e31849ce16dd40..6da216bbd19250a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -268,6 +268,8 @@ Non-comprehensive list of changes in this release
   and vector types as return value ``19``, to match GCC 14's behavior.
 * The default value of `_MSC_VER` was raised from 1920 to 1933.
 * Since MSVC 19.33 added undocumented attribute ``[[msvc::constexpr]]``, this 
release adds the attribute as well.
+* Support for ``__builtin_verbose_trap`` has been added. See
+  https://clang.llvm.org/docs/LanguageExtensions.html#builtin-functions.
 
 * Added ``#pragma clang fp reciprocal``.
 
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index a41f2d66b37b69d..34d913748d3021f 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -774,6 +774,11 @@ class Expr : public ValueStmt {
  const Expr *PtrExpression, ASTContext &Ctx,
  EvalResult &Status) const;
 
+  /// If the current Expr can be evaluated to a pointer to a null-terminated
+  /// constant string, return the constant string (without the terminating

  1   2   3   4   5   >