[clang] [clang-cl] Fix value of __FUNCTION__ in MSVC mode. (PR #84014)

2024-03-05 Thread via cfe-commits


@@ -1635,6 +1635,17 @@ void TypePrinter::printElaboratedBefore(const 
ElaboratedType *T,
 if (T->getKeyword() != ElaboratedTypeKeyword::None)
   OS << " ";
 NestedNameSpecifier *Qualifier = T->getQualifier();
+if (!Policy.SuppressTagKeyword && Policy.SuppressScope &&
+!Policy.SuppressUnwrittenScope) {
+  std::string prefix = T->isClassType()   ? "class "
+   : T->isStructureType() ? "struct "
+   : T->isUnionType() ? "union "
+  : "";

Sirraide wrote:

```suggestion
  StringRef prefix = T->isClassType()   ? "class "
 : T->isStructureType() ? "struct "
 : T->isUnionType() ? "union "
: "";
```

Don’t think we need a string here.

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


[clang] [llvm] [RISCV] Improve error message when the extension is not supported (PR #83989)

2024-03-05 Thread Craig Topper via cfe-commits

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

LGTM

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


[clang] [clang-cl] Fix value of __FUNCTION__ in MSVC mode. (PR #84014)

2024-03-05 Thread via cfe-commits


@@ -3741,7 +3741,10 @@ ExprResult Sema::BuildPredefinedExpr(SourceLocation Loc,
   else {
 // Pre-defined identifiers are of type char[x], where x is the length of
 // the string.
-auto Str = PredefinedExpr::ComputeName(IK, currentDecl);
+bool ForceElaboratedPrinting =
+IK == PredefinedIdentKind::Function && getLangOpts().MicrosoftExt;

Sirraide wrote:

```suggestion
IK == PredefinedIdentKind::Function && getLangOpts().MSVCCompat;
```

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


[clang] [clang-cl] Fix value of __FUNCTION__ in MSVC mode. (PR #84014)

2024-03-05 Thread via cfe-commits


@@ -55,9 +55,14 @@ struct A {
 clang_analyzer_dump(__func__);
 clang_analyzer_dump(__FUNCTION__);
 clang_analyzer_dump(__PRETTY_FUNCTION__);
-// expected-warning@-3 {{&Element{"A",0 S64b,char}}}
-// expected-warning@-3 {{&Element{"A",0 S64b,char}}}
-// expected-warning@-3 {{&Element{"A::A()",0 S64b,char}}}
+#ifdef ANALYZER_MS
+// expected-warning@-4 {{&Element{"A",0 S64b,char}}}
+// expected-warning@-4 {{&Element{"A::A",0 S64b,char}}}
+#else
+// expected-warning@-7 {{&Element{"A",0 S64b,char}}}
+// expected-warning@-7 {{&Element{"A",0 S64b,char}}}

Sirraide wrote:

The first of these two doesn’t seem to have changed. Is there a good reason why 
it’s inside the `#ifdef`?

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


[clang] [clang-cl] Fix value of __FUNCTION__ in MSVC mode. (PR #84014)

2024-03-05 Thread via cfe-commits

Sirraide wrote:

I’m not entirely sure this change is a good idea: some people might be relying 
on Clang’s behaviour wrt `__FUNCTION__`, especially with how long it’s been 
around; Clang may not be fully MSVC-compatible in this case, but that 
incompatibilty seems unlikely to cause problems imo since afaik most people 
that actually depend on the output of these sorts of macros for e.g. reflexion 
use `__FUNCSIG__` or `__PRETTY_FUNCTION__` instead—then again, that could also 
be a reason as to why changing it might actually be fine.

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


[clang-tools-extra] ec7062d - [clangd] Add metric for rename decl kind (#83867)

2024-03-05 Thread via cfe-commits

Author: David Goldman
Date: 2024-03-05T11:10:57-05:00
New Revision: ec7062d9d822df42dee6dccada13f42798976f3c

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

LOG: [clangd] Add metric for rename decl kind (#83867)

This will give us insight into what users are renaming in practice - for
instance, try to gauge the impact of the ObjC rename support.

Added: 


Modified: 
clang-tools-extra/clangd/refactor/Rename.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/refactor/Rename.cpp 
b/clang-tools-extra/clangd/refactor/Rename.cpp
index 4e135801f6853d..75b30e66d63761 100644
--- a/clang-tools-extra/clangd/refactor/Rename.cpp
+++ b/clang-tools-extra/clangd/refactor/Rename.cpp
@@ -1062,6 +1062,10 @@ llvm::Expected rename(const RenameInputs 
&RInputs) {
 return makeError(ReasonToReject::AmbiguousSymbol);
 
   const auto &RenameDecl = **DeclsUnderCursor.begin();
+  static constexpr trace::Metric RenameTriggerCounter(
+  "rename_trigger_count", trace::Metric::Counter, "decl_kind");
+  RenameTriggerCounter.record(1, RenameDecl.getDeclKindName());
+
   std::string Placeholder = getName(RenameDecl);
   auto Invalid = checkName(RenameDecl, RInputs.NewName, Placeholder);
   if (Invalid)



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


[clang-tools-extra] [clangd] Add metric for rename decl kind (PR #83867)

2024-03-05 Thread David Goldman via cfe-commits

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


[clang] [clang-cl] Fix value of __FUNCTION__ in MSVC mode. (PR #84014)

2024-03-05 Thread Zahira Ammarguellat via cfe-commits

zahiraam wrote:

> I’m not entirely sure this change is a good idea: some people might be 
> relying on Clang’s behaviour wrt `__FUNCTION__`, especially with how long 
> it’s been around; Clang may not be fully MSVC-compatible in this case, but 
> that incompatibilty seems unlikely to cause problems imo since afaik most 
> people that actually depend on the output of these sorts of macros for e.g. 
> reflexion use `__FUNCSIG__` or `__PRETTY_FUNCTION__` instead—then again, that 
> could also be a reason as to why changing it might actually be fine.

Thanks for the review. This is an issue that we encountered in our internal 
testing with an application using `__FUNCTION__`. I agree that might not be 
used by a lot of users/apps, but it is used and having it compatible with MSVC 
doesn't actually hurt? (I hope).

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


[clang] [clang-cl] Fix value of __FUNCTION__ in MSVC mode. (PR #84014)

2024-03-05 Thread Zahira Ammarguellat via cfe-commits

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


[clang] [clang-cl] Fix value of __FUNCTION__ in MSVC mode. (PR #84014)

2024-03-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Zahira Ammarguellat (zahiraam)


Changes

Predefined macro FUNCTION in clang is not returning the same string than MS for 
templated functions.

See https://godbolt.org/z/q3EKn5zq4

For the same test case MSVC is returning:

function: TestClass::TestClass
function: TestStruct::TestStruct
function: TestEnum::TestEnum

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


9 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+3) 
- (modified) clang/include/clang/AST/Expr.h (+2-1) 
- (modified) clang/lib/AST/Expr.cpp (+21-5) 
- (modified) clang/lib/AST/TypePrinter.cpp (+20-4) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+4-1) 
- (modified) clang/test/AST/Interp/literals.cpp (+4-4) 
- (modified) clang/test/Analysis/eval-predefined-exprs.cpp (+16-6) 
- (modified) clang/test/SemaCXX/source_location.cpp (+64) 
- (modified) clang/unittests/AST/DeclPrinterTest.cpp (+15) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 612b4329727455..20c14fae1dd31b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -224,6 +224,9 @@ Bug Fixes in This Version
   for variables created through copy initialization having side-effects in 
C++17 and later.
   Fixes (#GH64356) (#GH79518).
 
+- Fix value of predefined macro ``__FUNCTION__`` to match MSVC's value. Fixes
+  (`#66114 `_).
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index bf0622bdeca30e..ce8e64a4bed04b 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -2034,7 +2034,8 @@ class PredefinedExpr final
   }
 
   static std::string ComputeName(PredefinedIdentKind IK,
- const Decl *CurrentDecl);
+ const Decl *CurrentDecl,
+ bool ForceElaboratedPrinting = false);
 
   SourceLocation getBeginLoc() const { return getLocation(); }
   SourceLocation getEndLoc() const { return getLocation(); }
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index b4de2155adcebd..796e50817ee319 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -673,7 +673,8 @@ StringRef 
PredefinedExpr::getIdentKindName(PredefinedIdentKind IK) {
 // FIXME: Maybe this should use DeclPrinter with a special "print predefined
 // expr" policy instead.
 std::string PredefinedExpr::ComputeName(PredefinedIdentKind IK,
-const Decl *CurrentDecl) {
+const Decl *CurrentDecl,
+bool ForceElaboratedPrinting) {
   ASTContext &Context = CurrentDecl->getASTContext();
 
   if (IK == PredefinedIdentKind::FuncDName) {
@@ -721,10 +722,17 @@ std::string 
PredefinedExpr::ComputeName(PredefinedIdentKind IK,
 return std::string(Out.str());
   }
   if (const FunctionDecl *FD = dyn_cast(CurrentDecl)) {
-if (IK != PredefinedIdentKind::PrettyFunction &&
-IK != PredefinedIdentKind::PrettyFunctionNoVirtual &&
-IK != PredefinedIdentKind::FuncSig &&
-IK != PredefinedIdentKind::LFuncSig)
+const auto &LO = Context.getLangOpts();
+if ((ForceElaboratedPrinting &&
+ (((IK == PredefinedIdentKind::Func ||
+IK == PredefinedIdentKind ::Function) &&
+   !LO.MicrosoftExt) ||
+  (IK == PredefinedIdentKind::LFunction && LO.MicrosoftExt))) ||
+(!ForceElaboratedPrinting &&
+ (IK != PredefinedIdentKind::PrettyFunction &&
+  IK != PredefinedIdentKind::PrettyFunctionNoVirtual &&
+  IK != PredefinedIdentKind::FuncSig &&
+  IK != PredefinedIdentKind::LFuncSig)))
   return FD->getNameAsString();
 
 SmallString<256> Name;
@@ -752,6 +760,8 @@ std::string PredefinedExpr::ComputeName(PredefinedIdentKind 
IK,
 PrintingPolicy Policy(Context.getLangOpts());
 PrettyCallbacks PrettyCB(Context.getLangOpts());
 Policy.Callbacks = &PrettyCB;
+if (IK == PredefinedIdentKind::Function && ForceElaboratedPrinting)
+  Policy.SuppressTagKeyword = !LO.MicrosoftExt;
 std::string Proto;
 llvm::raw_string_ostream POut(Proto);
 
@@ -779,6 +789,12 @@ std::string 
PredefinedExpr::ComputeName(PredefinedIdentKind IK,
 
 FD->printQualifiedName(POut, Policy);
 
+if (IK == PredefinedIdentKind::Function) {
+  POut.flush();
+  Out << Proto;
+  return std::string(Name);
+}
+
 POut << "(";
 if (FT) {
   for (unsigned i = 0, e = Decl->getNumParams(); i != e; ++i) {
diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 7dcc4348f8e036..21605e1f53e3d9 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -1635,6 +1635,17 @@ void TypePrinter::printElaboratedBefore(const 
ElaboratedType *T,
 if (T->getKey

[clang] [HIP] fix host-used external kernel (PR #83870)

2024-03-05 Thread Yaxun Liu via cfe-commits

https://github.com/yxsamliu updated 
https://github.com/llvm/llvm-project/pull/83870

>From 9c6991bbcdce6f24c8f99c8f2a6ff0e5b6c2ac5a Mon Sep 17 00:00:00 2001
From: "Yaxun (Sam) Liu" 
Date: Mon, 4 Mar 2024 11:38:06 -0500
Subject: [PATCH] [HIP] fix host-used external kernel

In -fgpu-rdc mode, when an external kernel is used by a host function
with weak_odr linkage (e.g. explicitly instantiated template function),
the kernel should not be marked as host-used external kernel, since
the host function may be dropped by the linker. Mark the external
kernel as host-used external kernel will force a reference to
the external kernel, which the user may not define in other TU.

Fixes: https://github.com/llvm/llvm-project/issues/83771
---
 clang/lib/Sema/SemaCUDA.cpp|  5 -
 clang/lib/Sema/SemaExpr.cpp|  5 -
 clang/test/CodeGenCUDA/host-used-extern.cu | 13 +
 3 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaCUDA.cpp b/clang/lib/Sema/SemaCUDA.cpp
index 6a66ecf6f94c17..4d4f4b6a2d4d95 100644
--- a/clang/lib/Sema/SemaCUDA.cpp
+++ b/clang/lib/Sema/SemaCUDA.cpp
@@ -895,7 +895,10 @@ bool Sema::CheckCUDACall(SourceLocation Loc, FunctionDecl 
*Callee) {
   if (DiagKind == SemaDiagnosticBuilder::K_Nop) {
 // For -fgpu-rdc, keep track of external kernels used by host functions.
 if (LangOpts.CUDAIsDevice && LangOpts.GPURelocatableDeviceCode &&
-Callee->hasAttr() && !Callee->isDefined())
+Callee->hasAttr() && !Callee->isDefined() &&
+(!Caller || (!Caller->getDescribedFunctionTemplate() &&
+ getASTContext().GetGVALinkageForFunction(Caller) ==
+ GVA_StrongExternal)))
   getASTContext().CUDAExternalDeviceDeclODRUsedByHost.insert(Callee);
 return true;
   }
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 47bb263f56aade..93f82e68ab6440 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -19218,7 +19218,10 @@ MarkVarDeclODRUsed(ValueDecl *V, SourceLocation Loc, 
Sema &SemaRef,
   // externalize the static device side variable ODR-used by host code.
   if (!Var->hasExternalStorage())
 SemaRef.getASTContext().CUDADeviceVarODRUsedByHost.insert(Var);
-  else if (SemaRef.LangOpts.GPURelocatableDeviceCode)
+  else if (SemaRef.LangOpts.GPURelocatableDeviceCode &&
+   (!FD || (!FD->getDescribedFunctionTemplate() &&
+SemaRef.getASTContext().GetGVALinkageForFunction(FD) ==
+GVA_StrongExternal)))
 
SemaRef.getASTContext().CUDAExternalDeviceDeclODRUsedByHost.insert(Var);
 }
   }
diff --git a/clang/test/CodeGenCUDA/host-used-extern.cu 
b/clang/test/CodeGenCUDA/host-used-extern.cu
index e8f8e12aad47d1..b82b2d65aa741f 100644
--- a/clang/test/CodeGenCUDA/host-used-extern.cu
+++ b/clang/test/CodeGenCUDA/host-used-extern.cu
@@ -24,6 +24,7 @@
 
 // NEG-NOT: @__clang_gpu_used_external = {{.*}} @_Z7kernel2v
 // NEG-NOT: @__clang_gpu_used_external = {{.*}} @_Z7kernel3v
+// NEG-NOT: @__clang_gpu_used_external = {{.*}} @_Z7kernel5v
 // NEG-NOT: @__clang_gpu_used_external = {{.*}} @var2
 // NEG-NOT: @__clang_gpu_used_external = {{.*}} @var3
 // NEG-NOT: @__clang_gpu_used_external = {{.*}} @ext_shvar
@@ -44,6 +45,10 @@ __global__ void kernel3();
 // kernel4 is marked as used even though it is not called.
 __global__ void kernel4();
 
+// kernel5 is not marked as used since it is called by host function
+// with linkonce_odr linkage, which may be dropped by linker.
+__global__ void kernel5();
+
 extern __device__ int var1;
 
 __device__ int var2;
@@ -67,3 +72,11 @@ __global__ void test_lambda_using_extern_shared() {
   };
   lambda();
 }
+
+template
+void template_caller() {
+  kernel5<<<1, 1>>>();
+  var1 = 1;
+}
+
+template void template_caller();

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


[clang] [HIP] fix host-used external kernel (PR #83870)

2024-03-05 Thread Yaxun Liu via cfe-commits

https://github.com/yxsamliu updated 
https://github.com/llvm/llvm-project/pull/83870

>From 902f09d9124b387ad02bd758e9c54bf44746b0fd Mon Sep 17 00:00:00 2001
From: "Yaxun (Sam) Liu" 
Date: Mon, 4 Mar 2024 11:38:06 -0500
Subject: [PATCH] [HIP] fix host-used external kernel

In -fgpu-rdc mode, when an external kernel is used by a host function
with weak_odr linkage (e.g. explicitly instantiated template function),
the kernel should not be marked as host-used external kernel, since
the host function may be dropped by the linker. Mark the external
kernel as host-used external kernel will force a reference to
the external kernel, which the user may not define in other TU.

Fixes: https://github.com/llvm/llvm-project/issues/83771
---
 clang/lib/Sema/SemaCUDA.cpp|  5 -
 clang/lib/Sema/SemaExpr.cpp|  5 -
 clang/test/CodeGenCUDA/host-used-extern.cu | 13 +
 3 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaCUDA.cpp b/clang/lib/Sema/SemaCUDA.cpp
index 6a66ecf6f94c17..4d4f4b6a2d4d95 100644
--- a/clang/lib/Sema/SemaCUDA.cpp
+++ b/clang/lib/Sema/SemaCUDA.cpp
@@ -895,7 +895,10 @@ bool Sema::CheckCUDACall(SourceLocation Loc, FunctionDecl 
*Callee) {
   if (DiagKind == SemaDiagnosticBuilder::K_Nop) {
 // For -fgpu-rdc, keep track of external kernels used by host functions.
 if (LangOpts.CUDAIsDevice && LangOpts.GPURelocatableDeviceCode &&
-Callee->hasAttr() && !Callee->isDefined())
+Callee->hasAttr() && !Callee->isDefined() &&
+(!Caller || (!Caller->getDescribedFunctionTemplate() &&
+ getASTContext().GetGVALinkageForFunction(Caller) ==
+ GVA_StrongExternal)))
   getASTContext().CUDAExternalDeviceDeclODRUsedByHost.insert(Callee);
 return true;
   }
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 47bb263f56aade..93f82e68ab6440 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -19218,7 +19218,10 @@ MarkVarDeclODRUsed(ValueDecl *V, SourceLocation Loc, 
Sema &SemaRef,
   // externalize the static device side variable ODR-used by host code.
   if (!Var->hasExternalStorage())
 SemaRef.getASTContext().CUDADeviceVarODRUsedByHost.insert(Var);
-  else if (SemaRef.LangOpts.GPURelocatableDeviceCode)
+  else if (SemaRef.LangOpts.GPURelocatableDeviceCode &&
+   (!FD || (!FD->getDescribedFunctionTemplate() &&
+SemaRef.getASTContext().GetGVALinkageForFunction(FD) ==
+GVA_StrongExternal)))
 
SemaRef.getASTContext().CUDAExternalDeviceDeclODRUsedByHost.insert(Var);
 }
   }
diff --git a/clang/test/CodeGenCUDA/host-used-extern.cu 
b/clang/test/CodeGenCUDA/host-used-extern.cu
index e8f8e12aad47d1..1ae644ae981aaf 100644
--- a/clang/test/CodeGenCUDA/host-used-extern.cu
+++ b/clang/test/CodeGenCUDA/host-used-extern.cu
@@ -24,6 +24,7 @@
 
 // NEG-NOT: @__clang_gpu_used_external = {{.*}} @_Z7kernel2v
 // NEG-NOT: @__clang_gpu_used_external = {{.*}} @_Z7kernel3v
+// NEG-NOT: @__clang_gpu_used_external = {{.*}} @_Z7kernel5v
 // NEG-NOT: @__clang_gpu_used_external = {{.*}} @var2
 // NEG-NOT: @__clang_gpu_used_external = {{.*}} @var3
 // NEG-NOT: @__clang_gpu_used_external = {{.*}} @ext_shvar
@@ -44,6 +45,10 @@ __global__ void kernel3();
 // kernel4 is marked as used even though it is not called.
 __global__ void kernel4();
 
+// kernel5 is not marked as used since it is called by host function
+// with weak_odr linkage, which may be dropped by linker.
+__global__ void kernel5();
+
 extern __device__ int var1;
 
 __device__ int var2;
@@ -67,3 +72,11 @@ __global__ void test_lambda_using_extern_shared() {
   };
   lambda();
 }
+
+template
+void template_caller() {
+  kernel5<<<1, 1>>>();
+  var1 = 1;
+}
+
+template void template_caller();

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


[clang] [clang-cl] Fix value of __FUNCTION__ in MSVC mode. (PR #84014)

2024-03-05 Thread via cfe-commits


@@ -55,9 +55,14 @@ struct A {
 clang_analyzer_dump(__func__);
 clang_analyzer_dump(__FUNCTION__);
 clang_analyzer_dump(__PRETTY_FUNCTION__);
-// expected-warning@-3 {{&Element{"A",0 S64b,char}}}
-// expected-warning@-3 {{&Element{"A",0 S64b,char}}}
-// expected-warning@-3 {{&Element{"A::A()",0 S64b,char}}}
+#ifdef ANALYZER_MS
+// expected-warning@-4 {{&Element{"A",0 S64b,char}}}
+// expected-warning@-4 {{&Element{"A::A",0 S64b,char}}}
+#else
+// expected-warning@-7 {{&Element{"A",0 S64b,char}}}
+// expected-warning@-7 {{&Element{"A",0 S64b,char}}}

Sirraide wrote:

Reading this again, it seems it’s because of the relative `@`. I’d suggest 
using markers instead, or if possible, putting the comments on the same line as 
the diagnostic to avoid problems like these—I know this is how it’s done in the 
rest of the file too, but we tend to prefer not to use relative offsets in 
cases like these.

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


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-05 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> We can enable it as an extension in older language modes later as a separate 
> patch in case there is user's demand on this. @cor3ntin , @AaronBallman 
> please let me know what you think.

Thank you for investigating this! I'm perfectly fine not enabling this as an 
extension in older language modes until we have a strong enough need to justify 
the efforts.

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


[clang] [clang][NFC] Trim license header comments to 81 characters (PR #82919)

2024-03-05 Thread Paul T Robinson via cfe-commits

pogo59 wrote:

I grepped `clang` for "^/+=[^/]*/.*\.(h|cpp) " and found only 35 files with 
directory components. So, the majority of files have only the filename in the 
header line. The example in the Coding Standard does not reflect common 
practice.

I think it's fine to remove everything but the filename.

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


[clang] [clang-cl] Fix value of __FUNCTION__ in MSVC mode. (PR #84014)

2024-03-05 Thread via cfe-commits

Sirraide wrote:

Oh, I just noticed that you’ve tried to land this change before 
(https://github.com/llvm/llvm-project/pull/66120), but it seems it was reverted 
because of some problems; if those are fixed now, then I’d say going forward 
with this is probably fine, seeing as it was approved the first time round.

This would have been a bit less confusing if you had pointed that out, just 
saying ;Þ

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


[clang] 7df43cc - [clang] Add -Wmissing-designated-field-initializers (#81364)

2024-03-05 Thread via cfe-commits

Author: Vadim D
Date: 2024-03-05T11:27:58-05:00
New Revision: 7df43ccf08e40468354d0564f9bcd7dfe681590b

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

LOG: [clang] Add -Wmissing-designated-field-initializers (#81364)

#56628 changed the behavior of `-Wmissing-field-initializers`, which
introduces many new warnings in C++ code that uses partial designated
initializers. If such code is being built with `-Wextra -Werror`, this
change will break the build.

This PR adds a new flag that allows to disable these new warnings and
keep the old ones, as was suggested by @AaronBallman in the original
issue:
https://github.com/llvm/llvm-project/issues/56628#issuecomment-1761510850

Fixes  #68933

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaInit.cpp
clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index de5f339cc7f0ba..5e0352a7eaf6cd 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -150,6 +150,10 @@ Non-comprehensive list of changes in this release
 New Compiler Flags
 --
 
+- ``-Wmissing-designated-field-initializers``, grouped under 
``-Wmissing-field-initializers``.
+  This diagnostic can be disabled to make ``-Wmissing-field-initializers`` 
behave
+  like it did before Clang 18.x. Fixes (`#56628 
`_)
+
 Deprecated Compiler Flags
 -
 

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index e8b4139d7893ce..0791a0002319de 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -517,7 +517,15 @@ def MethodSignatures : DiagGroup<"method-signatures">;
 def MismatchedParameterTypes : DiagGroup<"mismatched-parameter-types">;
 def MismatchedReturnTypes : DiagGroup<"mismatched-return-types">;
 def MismatchedTags : DiagGroup<"mismatched-tags">;
-def MissingFieldInitializers : DiagGroup<"missing-field-initializers">;
+def MissingDesignatedFieldInitializers : 
DiagGroup<"missing-designated-field-initializers">{
+  code Documentation = [{
+Warn about designated initializers with some fields missing (only in C++).
+  }];
+}
+// Default -Wmissing-field-initializers matches gcc behavior,
+// but missing-designated-field-initializers can be turned off to match old 
clang behavior.
+def MissingFieldInitializers : DiagGroup<"missing-field-initializers",
+ [MissingDesignatedFieldInitializers]>;
 def ModuleLock : DiagGroup<"module-lock">;
 def ModuleBuild : DiagGroup<"module-build">;
 def ModuleImport : DiagGroup<"module-import">;

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b50a4895e171b5..708b3c7f1ede0a 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6170,6 +6170,10 @@ def ext_initializer_string_for_char_array_too_long : 
ExtWarn<
 def warn_missing_field_initializers : Warning<
   "missing field %0 initializer">,
   InGroup, DefaultIgnore;
+// The same warning, but another group is needed to disable it separately.
+def warn_missing_designated_field_initializers : Warning<
+  warn_missing_field_initializers.Summary>,
+  InGroup, DefaultIgnore;
 def warn_braces_around_init : Warning<
   "braces around %select{scalar |}0initializer">,
   InGroup>;

diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 93b125382b164f..060fe35ad96808 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -2227,8 +2227,6 @@ void InitListChecker::CheckStructUnionTypes(
   size_t NumRecordDecls = llvm::count_if(RD->decls(), [&](const Decl *D) {
 return isa(D) || isa(D);
   });
-  bool CheckForMissingFields =
-!IList->isIdiomaticZeroInitializer(SemaRef.getLangOpts());
   bool HasDesignatedInit = false;
 
   llvm::SmallPtrSet InitializedFields;
@@ -2269,11 +2267,6 @@ void InitListChecker::CheckStructUnionTypes(
   }
 
   InitializedSomething = true;
-
-  // Disable check for missing fields when designators are used.
-  // This matches gcc behaviour.
-  if (!SemaRef.getLangOpts().CPlusPlus)
-CheckForMissingFields = false;
   continue;
 }
 
@@ -2285,7 +2278,7 @@ void InitListChecker::CheckStructUnionTypes(
 // These are okay for randomized structures. [C99 6.7.8p19]
 //
 // Also, if there is only one element in the structure, we allow something
-// like this, because it's really not rand

[clang] [clang] Add -Wmissing-designated-field-initializers (PR #81364)

2024-03-05 Thread Aaron Ballman via cfe-commits

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


[clang] [clang] Add -Wmissing-designated-field-initializers (PR #81364)

2024-03-05 Thread via cfe-commits

github-actions[bot] wrote:



@vvd170501 Congratulations on having your first Pull Request (PR) merged into 
the LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested
by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with 
a build, you may recieve a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself.
This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


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


[clang] [clang][RISCV] Reorder sema check for RVV type (PR #83553)

2024-03-05 Thread Craig Topper via cfe-commits

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

LGTM

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


[clang] [clang-cl] Fix value of __FUNCTION__ in MSVC mode. (PR #84014)

2024-03-05 Thread Zahira Ammarguellat via cfe-commits

zahiraam wrote:

> Oh, I just noticed that you’ve tried to land this change before (#66120), but 
> it seems it was reverted because of some problems; if those are fixed now, 
> then I’d say going forward with this is probably fine, seeing as it was 
> approved the first time round.
> 
> This would have been a bit less confusing if you had pointed that out, just 
> saying ;Þ

Yes. Sorry about that. This patch was mostly to fix the issues raised in 
PR#66120.

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


[clang] [clang] Bugfix for choosing the more specialized overload (PR #83279)

2024-03-05 Thread Botond István Horváth via cfe-commits

https://github.com/HoBoIs updated 
https://github.com/llvm/llvm-project/pull/83279

From 68200ecf3267d1b3940fa73c25c50ee706932a98 Mon Sep 17 00:00:00 2001
From: Botond Istvan Horvath 
Date: Wed, 28 Feb 2024 13:09:15 +0100
Subject: [PATCH 01/10] Bugfix for choosing the more specialized overload

There was a bug in clang where it couldn't choose which overload candidate is
more specialized if it was comparing a member-function to a non-member
function. Previously, this was detected as an ambigouity, now clang chooses 
correctly.

This patch fixes the bug by fully implementing CWG2445 and moving the template
transformation described in [temp.func.order] paragraph 3 from
isAtLeastAsSpecializedAs to Sema::getMoreSpecializedTemplate so we have the
transformed parameter list during the whole comperrassion. Also, to be able
to add the correct type for the implicit object parameter
Sema::getMoreSpecializedTemplate has new parameters for the object type.
---
 clang/include/clang/Sema/Sema.h  |   4 +-
 clang/lib/Sema/SemaOverload.cpp  |  12 +-
 clang/lib/Sema/SemaTemplateDeduction.cpp | 263 +++
 3 files changed, 186 insertions(+), 93 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index ef4b93fac95ce5..1a2a3a6bebd95e 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9463,7 +9463,9 @@ class Sema final {
   FunctionTemplateDecl *getMoreSpecializedTemplate(
   FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc,
   TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1,
-  unsigned NumCallArguments2, bool Reversed = false);
+  unsigned NumCallArguments2, QualType ObjType1 = {},
+  QualType ObjType2 = {}, bool Reversed = false);
+
   UnresolvedSetIterator
   getMostSpecialized(UnresolvedSetIterator SBegin, UnresolvedSetIterator SEnd,
  TemplateSpecCandidateSet &FailedCandidates,
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 7d38043890ca20..60138236abf1d8 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -10526,14 +10526,24 @@ bool clang::isBetterOverloadCandidate(
   //  according to the partial ordering rules described in 14.5.5.2, or,
   //  if not that,
   if (Cand1IsSpecialization && Cand2IsSpecialization) {
+const auto *ObjContext1 =
+dyn_cast(Cand1.FoundDecl->getDeclContext());
+const auto *ObjContext2 =
+dyn_cast(Cand2.FoundDecl->getDeclContext());
 if (FunctionTemplateDecl *BetterTemplate = S.getMoreSpecializedTemplate(
 Cand1.Function->getPrimaryTemplate(),
 Cand2.Function->getPrimaryTemplate(), Loc,
 isa(Cand1.Function) ? TPOC_Conversion
: TPOC_Call,
 Cand1.ExplicitCallArguments, Cand2.ExplicitCallArguments,
-Cand1.isReversed() ^ Cand2.isReversed()))
+ObjContext1 ? QualType(ObjContext1->getTypeForDecl(), 0)
+: QualType{},
+ObjContext2 ? QualType(ObjContext2->getTypeForDecl(), 0)
+: QualType{},
+Cand1.isReversed() ^ Cand2.isReversed())) {
   return BetterTemplate == Cand1.Function->getPrimaryTemplate();
+}
+
   }
 
   //   -— F1 and F2 are non-template functions with the same
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 563491f76f5478..2af3c29ae1f1c4 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -5333,11 +5333,31 @@ bool 
Sema::CheckIfFunctionSpecializationIsImmediate(FunctionDecl *FD,
   return false;
 }
 
+static QualType GetImplicitObjectParameterTypeCXX20(ASTContext &Context,
+const CXXMethodDecl 
*Method,
+QualType rawType,
+bool isOtherRvr) {
+  // C++20 [temp.func.order]p3.1, p3.2:
+  //- The type X(M ) is “rvalue reference to cv A” if the optional 
ref-qualifier
+  //  of M is && or if M has no ref-qualifier and the 
positionally-corresponding
+  //  parameter of the other transformed template has rvalue reference type;
+  //  if this determination depends recursively upon whether X(M ) is an rvalue
+  //  reference type, it is not considered to have rvalue reference type.
+  //- Otherwise, X(M ) is “lvalue reference to cv A”.
+  assert(Method && !Method->isExplicitObjectMemberFunction() &&
+ "expected a member function with no explicit object parameter");
+
+  rawType = Context.getQualifiedType(rawType, Method->getMethodQualifiers());
+  if (Method->getRefQualifier() == RQ_RValue ||
+  (isOtherRvr && Method->getRefQualifier() == RQ_None))
+return Context.getRValueReferenceType(rawType);
+  return Context.getLValueReferenceTyp

[clang-tools-extra] [clangd] Add container field to remote index Refs grpc method (PR #71605)

2024-03-05 Thread via cfe-commits

https://github.com/tdupes updated 
https://github.com/llvm/llvm-project/pull/71605

>From 4282c39fd0b40c26c68f57257c150b984264f50b Mon Sep 17 00:00:00 2001
From: dup 
Date: Fri, 3 Nov 2023 09:03:24 -0700
Subject: [PATCH 1/2] Add container field to remote index Refs grpc method

---
 clang-tools-extra/clangd/index/YAMLSerialization.cpp  | 1 +
 clang-tools-extra/clangd/index/remote/Index.proto | 1 +
 .../clangd/index/remote/marshalling/Marshalling.cpp   | 4 
 .../clangd/unittests/remote/MarshallingTests.cpp  | 1 +
 4 files changed, 7 insertions(+)

diff --git a/clang-tools-extra/clangd/index/YAMLSerialization.cpp 
b/clang-tools-extra/clangd/index/YAMLSerialization.cpp
index 214a847b5eddb3..495d8a2ff487aa 100644
--- a/clang-tools-extra/clangd/index/YAMLSerialization.cpp
+++ b/clang-tools-extra/clangd/index/YAMLSerialization.cpp
@@ -319,6 +319,7 @@ template <> struct MappingTraits {
 MappingNormalization NKind(IO, R.Kind);
 IO.mapRequired("Kind", NKind->Kind);
 IO.mapRequired("Location", R.Location);
+IO.mapOptional("Container", R.Container);
   }
 };
 
diff --git a/clang-tools-extra/clangd/index/remote/Index.proto 
b/clang-tools-extra/clangd/index/remote/Index.proto
index 3072299d8f345f..33bf095d88598f 100644
--- a/clang-tools-extra/clangd/index/remote/Index.proto
+++ b/clang-tools-extra/clangd/index/remote/Index.proto
@@ -81,6 +81,7 @@ message Symbol {
 message Ref {
   optional SymbolLocation location = 1;
   optional uint32 kind = 2;
+  optional string container = 3;
 }
 
 message SymbolInfo {
diff --git a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp 
b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
index 7e31ada18a6579..e9f0972ba91c3f 100644
--- a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
+++ b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
@@ -189,6 +189,9 @@ llvm::Expected Marshaller::fromProtobuf(const 
Ref &Message) {
 return Location.takeError();
   Result.Location = *Location;
   Result.Kind = static_cast(Message.kind());
+  auto ContainerID = SymbolID::fromStr(Message.container());
+  if (ContainerID)
+Result.Container = *ContainerID;
   return Result;
 }
 
@@ -296,6 +299,7 @@ llvm::Expected Marshaller::toProtobuf(const 
clangd::Ref &From) {
   if (!Location)
 return Location.takeError();
   *Result.mutable_location() = *Location;
+  Result.set_container(From.Container.str());
   return Result;
 }
 
diff --git a/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp 
b/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
index a2b31698a059a9..85e79eae331bc1 100644
--- a/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
@@ -223,6 +223,7 @@ TEST(RemoteMarshallingTest, RefSerialization) {
   Location.FileURI = testPathURI(
   "llvm-project/llvm/clang-tools-extra/clangd/Protocol.h", Strings);
   Ref.Location = Location;
+  Ref.Container = llvm::cantFail(SymbolID::fromStr("0001"));
 
   Marshaller ProtobufMarshaller(testPath("llvm-project/"),
 testPath("llvm-project/"));

>From 6c1b25686a214a178efb6f6b8216de9329d37ad0 Mon Sep 17 00:00:00 2001
From: dup 
Date: Wed, 28 Feb 2024 18:19:19 -0800
Subject: [PATCH 2/2] [clangd] Include Json Rpc Request ID in trace events

Included in a new field, `rid,` this allows us to associate each trace
log with the incoming request that sent them. Helpful for associating
insights from clangd logs with logging on an lsp client side - such as a
vscode extension.
---
 clang-tools-extra/clangd/ClangdLSPServer.cpp | 11 +--
 clang-tools-extra/clangd/support/Trace.cpp   |  6 ++
 clang-tools-extra/clangd/support/Trace.h |  2 ++
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index f29dadde2b86d5..632cdd04cf6fc4 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -229,7 +229,7 @@ class ClangdLSPServer::MessageHandler : public 
Transport::MessageHandler {
 
   bool onCall(llvm::StringRef Method, llvm::json::Value Params,
   llvm::json::Value ID) override {
-WithContext HandlerContext(handlerContext());
+WithContext HandlerContext(handlerContext(llvm::to_string(ID)));
 // Calls can be canceled by the client. Add cancellation context.
 WithContext WithCancel(cancelableRequestContext(ID));
 trace::Span Tracer(Method, LSPLatency);
@@ -252,7 +252,7 @@ class ClangdLSPServer::MessageHandler : public 
Transport::MessageHandler {
 
   bool onReply(llvm::json::Value ID,
llvm::Expected Result) override {
-WithContext HandlerContext(handlerContext());
+WithContext HandlerContext(handlerContext(llvm::to_string(ID)));
 
 Callback ReplyHandler = nullptr;
  

[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-05 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

Okay then, could you please review or give me an LGTM if everything is ok? The 
patch transformed a bit since it was first approved. It doesn't enable feature 
as extension now, it incorporates changes and test highlighted by 
https://github.com/llvm/llvm-project/pull/77753#issuecomment-1899137960 and I 
renamed diagnostic messages according to other similar ones.

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


[clang] Don't do casting of atomic FP loads/stores in FE. (PR #83446)

2024-03-05 Thread Matt Arsenault via cfe-commits


@@ -1453,9 +1457,11 @@ void AtomicInfo::EmitAtomicLoadLibcall(llvm::Value 
*AddForLoaded,
 }
 
 llvm::Value *AtomicInfo::EmitAtomicLoadOp(llvm::AtomicOrdering AO,
-  bool IsVolatile) {
+  bool IsVolatile, bool CastFP) {
   // Okay, we're doing this natively.
-  Address Addr = getAtomicAddressAsAtomicIntPointer();
+  Address Addr = getAtomicAddress();
+  if (!(Addr.getElementType()->isIEEELikeFPTy() && !CastFP))

arsenm wrote:

```suggestion
  if (CastFP || !Addr.getElementType()->isIEEELikeFPTy())
```

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


[clang] Don't do casting of atomic FP loads/stores in FE. (PR #83446)

2024-03-05 Thread Matt Arsenault via cfe-commits


@@ -1453,9 +1457,11 @@ void AtomicInfo::EmitAtomicLoadLibcall(llvm::Value 
*AddForLoaded,
 }
 
 llvm::Value *AtomicInfo::EmitAtomicLoadOp(llvm::AtomicOrdering AO,
-  bool IsVolatile) {
+  bool IsVolatile, bool CastFP) {
   // Okay, we're doing this natively.
-  Address Addr = getAtomicAddressAsAtomicIntPointer();
+  Address Addr = getAtomicAddress();
+  if (!(Addr.getElementType()->isIEEELikeFPTy() && !CastFP))

arsenm wrote:

Still should probably pass through the non-ieee type case through to the IR 
also, but step at a time I guess 

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


[clang] Don't do casting of atomic FP loads/stores in FE. (PR #83446)

2024-03-05 Thread Matt Arsenault via cfe-commits


@@ -0,0 +1,84 @@
+// RUN: %clang_cc1 -triple s390x-linux-gnu -O1 -emit-llvm %s -o - | FileCheck 
%s
+//
+// Test that floating point atomic stores and loads do not get casted to/from
+// integer.
+
+#include 
+
+_Atomic float Af;
+_Atomic double Ad;
+_Atomic long double Ald;
+
+ Atomic stores of floating point values.
+void fun0(float Arg) {
+// CHECK-LABEL: @fun0
+// CHECK:   store atomic float %Arg, ptr @Af seq_cst, align 4
+  Af = Arg;
+}
+
+void fun1(double Arg) {
+// CHECK-LABEL: @fun1
+// CHECK:   store atomic double %Arg, ptr @Ad seq_cst, align 8
+  Ad = Arg;
+}
+
+void fun2(long double Arg) {
+// CHECK-LABEL: @fun2
+// CHECK:   store atomic fp128 %Arg, ptr @Ald seq_cst, align 16
+  Ald = Arg;
+}
+
+void fun3(_Atomic float *Dst, float Arg) {
+// CHECK-LABEL: @fun
+// CHECK:   store atomic float %Arg, ptr %Dst seq_cst, align 4
+  *Dst = Arg;
+}
+
+void fun4(_Atomic double *Dst, double Arg) {
+// CHECK-LABEL: @fun4
+// CHECK:   store atomic double %Arg, ptr %Dst seq_cst, align 8
+  *Dst = Arg;
+}
+
+void fun5(_Atomic long double *Dst, long double Arg) {
+// CHECK-LABEL: @fun5
+// CHECK:   store atomic fp128 %Arg, ptr %Dst seq_cst, align 16
+  *Dst = Arg;
+}
+
+ Atomic loads of floating point values.
+float fun6() {
+// CHECK-LABEL: @fun6
+// CHECK:   %atomic-load = load atomic float, ptr @Af seq_cst, align 4
+  return Af;
+}
+
+float fun7() {
+// CHECK-LABEL: @fun7
+// CHECK:   %atomic-load = load atomic double, ptr @Ad seq_cst, align 8
+  return Ad;
+}
+
+float fun8() {
+// CHECK-LABEL: @fun8
+// CHECK:   %atomic-load = load atomic fp128, ptr @Ald seq_cst, align 16
+  return Ald;
+}
+
+float fun9(_Atomic float *Src) {
+// CHECK-LABEL: @fun9
+// CHECK:   %atomic-load = load atomic float, ptr %Src seq_cst, align 4
+  return *Src;
+}
+
+double fun10(_Atomic double *Src) {
+// CHECK-LABEL: @fun10
+// CHECK:   %atomic-load = load atomic double, ptr %Src seq_cst, align 8
+  return *Src;
+}
+
+long double fun11(_Atomic long double *Src) {
+// CHECK-LABEL: @fun11
+// CHECK:   %atomic-load = load atomic fp128, ptr %Src seq_cst, align 16
+  return *Src;
+}

arsenm wrote:

test the volatile is preserved too? 

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


[clang] [llvm] [HLSL] implement the any intrinsic (PR #83903)

2024-03-05 Thread Xiang Li via cfe-commits

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


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


[clang] [llvm] [HLSL] implement the rcp intrinsic (PR #83857)

2024-03-05 Thread Xiang Li via cfe-commits

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


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


[clang] [FMV] Allow target version definitions in any order. (PR #83887)

2024-03-05 Thread Pavel Iliin via cfe-commits

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

Thanks for tests!

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


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-05 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman commented:

I found some possible changes to be made to the diagnostics.

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


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-05 Thread Aaron Ballman via cfe-commits

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


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-05 Thread Aaron Ballman via cfe-commits


@@ -2809,10 +2813,13 @@ def note_non_literal_virtual_base : 
Note<"%select{struct|interface|class}0 "
   "with virtual base %plural{1:class|:classes}1 is not a literal type">;
 def note_constexpr_virtual_base_here : Note<"virtual base class declared 
here">;
 def err_constexpr_non_literal_return : Error<
-  "%select{constexpr|consteval}0 function's return type %1 is not a literal 
type">;
+  "%select{constexpr|consteval}0 function with non-literal return type %1 is a 
C++23 extension">;
+def warn_cxx20_compat_constexpr_non_literal_return : Warning<
+  "%select{constexpr|consteval}0 function with non-literal return type %1 is 
incompatible with C++ standards before C++23">, InGroup, 
DefaultIgnore;
 def err_constexpr_non_literal_param : Error<
-  "%select{constexpr|consteval}2 %select{function|constructor}1's %ordinal0 
parameter type %3 is "
-  "not a literal type">;
+  "%select{constexpr|consteval}2 %select{function|constructor}1 with %ordinal0 
non-literal parameter type %3 is a C++23 extension">;
+def warn_cxx20_compat_constexpr_non_literal_param : Warning<

AaronBallman wrote:

This one can also go away.

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


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-05 Thread Aaron Ballman via cfe-commits


@@ -2809,10 +2813,13 @@ def note_non_literal_virtual_base : 
Note<"%select{struct|interface|class}0 "
   "with virtual base %plural{1:class|:classes}1 is not a literal type">;
 def note_constexpr_virtual_base_here : Note<"virtual base class declared 
here">;
 def err_constexpr_non_literal_return : Error<
-  "%select{constexpr|consteval}0 function's return type %1 is not a literal 
type">;
+  "%select{constexpr|consteval}0 function with non-literal return type %1 is a 
C++23 extension">;
+def warn_cxx20_compat_constexpr_non_literal_return : Warning<

AaronBallman wrote:

This warning can be removed.

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


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-05 Thread Aaron Ballman via cfe-commits


@@ -2774,9 +2774,13 @@ def err_constexpr_tag : Error<
 def err_constexpr_dtor : Error<
   "destructor cannot be declared %sub{select_constexpr_spec_kind}0">;
 def err_constexpr_dtor_subobject : Error<
-  "destructor cannot be declared %sub{select_constexpr_spec_kind}0 because "
+  "destructor cannot be declared %sub{select_constexpr_spec_kind}0 before 
C++23 because "
   "%select{data member %2|base class %3}1 does not have a "
   "constexpr destructor">;
+def warn_cxx20_compat_constexpr_dtor_subobject : Warning<

AaronBallman wrote:

We usually only issue the compat warnings in cases where we expose it as an 
extension in earlier modes, so I think this warning can go away.

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


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-05 Thread Aaron Ballman via cfe-commits


@@ -2809,10 +2813,13 @@ def note_non_literal_virtual_base : 
Note<"%select{struct|interface|class}0 "
   "with virtual base %plural{1:class|:classes}1 is not a literal type">;
 def note_constexpr_virtual_base_here : Note<"virtual base class declared 
here">;
 def err_constexpr_non_literal_return : Error<
-  "%select{constexpr|consteval}0 function's return type %1 is not a literal 
type">;
+  "%select{constexpr|consteval}0 function with non-literal return type %1 is a 
C++23 extension">;
+def warn_cxx20_compat_constexpr_non_literal_return : Warning<
+  "%select{constexpr|consteval}0 function with non-literal return type %1 is 
incompatible with C++ standards before C++23">, InGroup, 
DefaultIgnore;
 def err_constexpr_non_literal_param : Error<
-  "%select{constexpr|consteval}2 %select{function|constructor}1's %ordinal0 
parameter type %3 is "
-  "not a literal type">;
+  "%select{constexpr|consteval}2 %select{function|constructor}1 with %ordinal0 
non-literal parameter type %3 is a C++23 extension">;

AaronBallman wrote:

This should be reverted to the original wording as well.

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


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-05 Thread Aaron Ballman via cfe-commits


@@ -2809,10 +2813,13 @@ def note_non_literal_virtual_base : 
Note<"%select{struct|interface|class}0 "
   "with virtual base %plural{1:class|:classes}1 is not a literal type">;
 def note_constexpr_virtual_base_here : Note<"virtual base class declared 
here">;
 def err_constexpr_non_literal_return : Error<
-  "%select{constexpr|consteval}0 function's return type %1 is not a literal 
type">;
+  "%select{constexpr|consteval}0 function with non-literal return type %1 is a 
C++23 extension">;

AaronBallman wrote:

This should be reverted back to the original diagnostic wording; we no longer 
treat it as an extension.

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


[clang] [llvm] [HLSL] implement the rcp intrinsic (PR #83857)

2024-03-05 Thread Matt Arsenault via cfe-commits


@@ -18057,6 +18057,14 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 /*ReturnType*/ Op0->getType(), Intrinsic::dx_frac,
 ArrayRef{Op0}, nullptr, "dx.frac");
   }
+  case Builtin::BI__builtin_hlsl_elementwise_rcp: {
+Value *Op0 = EmitScalarExpr(E->getArg(0));
+if (!E->getArg(0)->getType()->hasFloatingRepresentation())
+  llvm_unreachable("rcp operand must have a float representation");
+return Builder.CreateIntrinsic(
+/*ReturnType*/ Op0->getType(), Intrinsic::dx_rcp,

arsenm wrote:

```suggestion
/*ReturnType=*/ Op0->getType(), Intrinsic::dx_rcp,
```

You're supposed to include the = after the parameter name to get clang-format 
to recognize it 

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


[clang] [llvm] [RISCV] Improve error message when the extension is not supported (PR #83989)

2024-03-05 Thread David Blaikie via cfe-commits

dwblaikie wrote:

perhaps the llvm libSupport prats of this change should be unit tested in LLVM, 
rather than only tested indirectly in clang?

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


[clang] [clang][analyzer] Improve documentation of StreamChecker (NFC). (PR #83858)

2024-03-05 Thread Balázs Kéri via cfe-commits


@@ -3020,44 +3020,82 @@ Check for misuses of stream APIs. Check for misuses of 
stream APIs: ``fopen, fcl
 
 alpha.unix.Stream (C)
 "
-Check stream handling functions: ``fopen, tmpfile, fclose, fread, fwrite, 
fseek, ftell, rewind, fgetpos,``
-``fsetpos, clearerr, feof, ferror, fileno``.
+Check C stream handling functions:
+``fopen, fdopen, freopen, tmpfile, fclose, fread, fwrite, fgetc, fgets, fputc, 
fputs, fprintf, fscanf, ungetc, getdelim, getline, fseek, fseeko, ftell, 
ftello, fflush, rewind, fgetpos, fsetpos, clearerr, feof, ferror, fileno``.
+
+The checker maintains information about the C stream objects (``FILE *``) and
+can detect error conditions related to use of streams. The following conditions
+are detected:
+
+* The ``FILE *`` pointer passed to the function is NULL (the single exception 
is
+  ``fflush`` where NULL is allowed).
+* Use of stream after close.
+* Opened stream is not closed.
+* Read from a stream after end-of-file. (This is not a fatal error but reported
+  by the checker. Stream remains in EOF state and the read operation fails.)

balazske wrote:

I have the feeling that these words (NULL, EOF) are relatively commonly used 
(NULL is an abbrevation for null pointer, EOF = end-of-file). Probably `NULL` 
can be better as keyword (code format), but by EOF I did not mean the numeric 
constant, just "end of file".

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


[clang] [clang][Sema] Fix for enums overflowing (#24667) (PR #78742)

2024-03-05 Thread Aaron Ballman via cfe-commits

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


[clang] [clang][Sema] Fix for enums overflowing (#24667) (PR #78742)

2024-03-05 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman commented:

Thank you for working on this! One thing I would like to see are some tests 
added to `clang/test/C/C2x/` (`n3029.c` and `n3030.c`) that tests the examples 
and changes from the original papers/final standard to demonstrate the features 
are complete. There are other tests in that directory that show the boilerplate 
for C feature testing.

Aside from testing and some nits, I think this is pretty close to ready.

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


[clang] [clang][Sema] Fix for enums overflowing (#24667) (PR #78742)

2024-03-05 Thread Aaron Ballman via cfe-commits


@@ -211,6 +217,8 @@ Bug Fixes in This Version
 - Clang now doesn't produce false-positive warning `-Wconstant-logical-operand`
   for logical operators in C23.
   Fixes (`#64356 `_).
+- Fixes miscompilation when an enum has a specified value such that the auto
+  increment overflows a signed long. Fixes (`#24667 
`_)

AaronBallman wrote:

```suggestion
- Fixes a miscompilation when an enum has a specified value such that the 
automatic
  increment overflows a ``signed long``. Fixes #GH24667.
```

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


[clang] [clang][Sema] Fix for enums overflowing (#24667) (PR #78742)

2024-03-05 Thread Aaron Ballman via cfe-commits


@@ -135,6 +135,12 @@ C23 Feature Support
   ``__TYPE_FMTb__`` (e.g., ``__UINT_FAST64_FMTB__``) in C23 mode for use with
   macros typically exposed from , such as ``PRIb8``.
   (`#81896: `_).
+- Enumerations should allow values greater than INT_MAX and smaller than
+  INT_MIN, in order to provide a value-preserved set of integer constants. 
`N3029 Improved Normal Enumerations 
`_

AaronBallman wrote:

```suggestion
- Enumerations should allow values greater than ``INT_MAX`` and smaller than
  ``INT_MIN``, in order to provide a value-preserved set of integer constants. 
`N3029 Improved Normal Enumerations 
`_
```

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


[clang] [clang][Sema] Fix for enums overflowing (#24667) (PR #78742)

2024-03-05 Thread Aaron Ballman via cfe-commits


@@ -19797,6 +19797,19 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl 
*Enum,
   // - If an initializer is specified for an enumerator, the
   //   initializing value has the same type as the expression.
   EltTy = Val->getType();
+} else if (getLangOpts().C23) {
+  // C23 6.7.2.2p11 b4
+  // int, if given explicitly with = and the value of the
+  // integer constant expression is representable by an int
+  //
+  // C23 6.7.2.2p11 b5
+  // the type of the integer constant expression, if given
+  // explicitly with = and if the value of the integer
+  // constant expression is not representable by int;
+  if (isRepresentableIntegerValue(Context, EnumVal, Context.IntTy)) {
+Val = ImpCastExprToType(Val, Context.IntTy, CK_IntegralCast).get();
+  }

AaronBallman wrote:

```suggestion
  if (isRepresentableIntegerValue(Context, EnumVal, Context.IntTy))
Val = ImpCastExprToType(Val, Context.IntTy, CK_IntegralCast).get();
```
Per our odd coding standard.

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


[clang] [HIP] fix host-used external kernel (PR #83870)

2024-03-05 Thread Yaxun Liu via cfe-commits


@@ -24,6 +24,7 @@
 
 // NEG-NOT: @__clang_gpu_used_external = {{.*}} @_Z7kernel2v
 // NEG-NOT: @__clang_gpu_used_external = {{.*}} @_Z7kernel3v
+// XEG-NOT: @__clang_gpu_used_external = {{.*}} @_Z7kernel5v

yxsamliu wrote:

fixed

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


[clang] [llvm] [HLSL] implement `mad` intrinsic (PR #83826)

2024-03-05 Thread Justin Bogner via cfe-commits

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


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


[clang] 643b31d - [HLSL] implement `mad` intrinsic (#83826)

2024-03-05 Thread via cfe-commits

Author: Farzon Lotfi
Date: 2024-03-05T12:23:26-05:00
New Revision: 643b31dbe8a515e007a0f1b2e1072c34e461b778

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

LOG: [HLSL] implement `mad` intrinsic (#83826)

This change implements #83736
The dot product lowering needs a tertiary multipy add operation. DXIL
has three mad opcodes for `fmad`(46), `imad`(48), and `umad`(49). Dot
product in DXIL only uses `imad`\ `umad`, but for completeness and
because the hlsl `mad` intrinsic requires it `fmad` was also included.
Two new intrinsics were needed to be created to complete this change.
the `fmad` case already supported by llvm via `fmuladd` intrinsic.

- `hlsl_intrinsics.h` - exposed mad api call.
- `Builtins.td` - exposed a `mad` builtin.
- `Sema.h` - make `tertiary` calls check for float types optional. 
- `CGBuiltin.cpp` - pick the intrinsic for singed\unsigned & float also
reuse `int_fmuladd`.
- `SemaChecking.cpp` - type checks for `__builtin_hlsl_mad`. 
- `IntrinsicsDirectX.td` create the two new intrinsics for
`imad`\`umad`/
- `DXIL.td` - create the llvm intrinsic to  `DXIL` opcode mapping.

-

Co-authored-by: Farzon Lotfi 

Added: 
clang/test/CodeGenHLSL/builtins/mad.hlsl
clang/test/SemaHLSL/BuiltIns/mad-errors.hlsl
llvm/test/CodeGen/DirectX/fmad.ll
llvm/test/CodeGen/DirectX/imad.ll
llvm/test/CodeGen/DirectX/umad.ll

Modified: 
clang/include/clang/Basic/Builtins.td
clang/include/clang/Sema/Sema.h
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Headers/hlsl/hlsl_intrinsics.h
clang/lib/Sema/SemaChecking.cpp
llvm/include/llvm/IR/IntrinsicsDirectX.td
llvm/lib/Target/DirectX/DXIL.td

Removed: 




diff  --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 384442e6a9359b..26c7be47891451 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4572,6 +4572,12 @@ def HLSLLerp : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
+def HLSLMad : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_mad"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void(...)";
+}
+
 // Builtins for XRay.
 def XRayCustomEvent : Builtin {
   let Spellings = ["__xray_customevent"];

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 29baf542f6cbf5..25c4c58ad4ae43 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -14146,7 +14146,8 @@ class Sema final {
   bool SemaBuiltinVectorMath(CallExpr *TheCall, QualType &Res);
   bool SemaBuiltinVectorToScalarMath(CallExpr *TheCall);
   bool SemaBuiltinElementwiseMath(CallExpr *TheCall);
-  bool SemaBuiltinElementwiseTernaryMath(CallExpr *TheCall);
+  bool SemaBuiltinElementwiseTernaryMath(CallExpr *TheCall,
+ bool CheckForFloatArgs = true);
   bool PrepareBuiltinElementwiseMathOneArgCall(CallExpr *TheCall);
   bool PrepareBuiltinReduceMathOneArgCall(CallExpr *TheCall);
 

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 9ee51ca7142c77..191f6d5a9fab5e 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18044,6 +18044,25 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 /*ReturnType*/ Op0->getType(), Intrinsic::dx_frac,
 ArrayRef{Op0}, nullptr, "dx.frac");
   }
+  case Builtin::BI__builtin_hlsl_mad: {
+Value *M = EmitScalarExpr(E->getArg(0));
+Value *A = EmitScalarExpr(E->getArg(1));
+Value *B = EmitScalarExpr(E->getArg(2));
+if (E->getArg(0)->getType()->hasFloatingRepresentation()) {
+  return Builder.CreateIntrinsic(
+  /*ReturnType*/ M->getType(), Intrinsic::fmuladd,
+  ArrayRef{M, A, B}, nullptr, "dx.fmad");
+}
+if (E->getArg(0)->getType()->hasSignedIntegerRepresentation()) {
+  return Builder.CreateIntrinsic(
+  /*ReturnType*/ M->getType(), Intrinsic::dx_imad,
+  ArrayRef{M, A, B}, nullptr, "dx.imad");
+}
+assert(E->getArg(0)->getType()->hasUnsignedIntegerRepresentation());
+return Builder.CreateIntrinsic(
+/*ReturnType*/ M->getType(), Intrinsic::dx_umad,
+ArrayRef{M, A, B}, nullptr, "dx.umad");
+  }
   }
   return nullptr;
 }

diff  --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 5180530363889f..b5bef78fae72fe 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -511,6 +511,111 @@ double3 log2(double3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_log2)
 double4 log2(double4);
 
+//===--===//
+// mad builtins
+//===--

[clang] [llvm] [HLSL] implement `mad` intrinsic (PR #83826)

2024-03-05 Thread Farzon Lotfi via cfe-commits

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


[clang] [llvm] [HLSL] implement the rcp intrinsic (PR #83857)

2024-03-05 Thread Farzon Lotfi via cfe-commits

https://github.com/farzonl updated 
https://github.com/llvm/llvm-project/pull/83857

>From 0060612b4fc1b7f5f5cc51a41a5fae7535ba2b02 Mon Sep 17 00:00:00 2001
From: Farzon Lotfi 
Date: Sun, 3 Mar 2024 16:14:35 -0500
Subject: [PATCH 1/2] [HLSL] implement the rcp  intrinsic This PR implements
 the frontend for llvm#70100 This PR is part 1 of 2. Part 2 depends on
 dixl-lerp-intrinsic-lowering PR which will have an intrinsic to instruction
 expansion pass. THat pass is what we need to complete the DXIL lowering
 portion of this PR:
 llvm/llvm-project@main...farzonl:llvm-project:dixl-lerp-intrinsic-lowering

Builtins.td - add an rcp builtin
CGBuiltin.cpp add the builtin to intrinsic lowering
hlsl_intrinsics.h - add the rcp  api
SemaChecking.cpp - reuse frac's semachecks
IntrinsicsDirectX.td add the llvm intrinsic
---
 clang/include/clang/Basic/Builtins.td|  6 +++
 clang/lib/CodeGen/CGBuiltin.cpp  |  8 +++
 clang/lib/Headers/hlsl/hlsl_intrinsics.h | 41 +++
 clang/lib/Sema/SemaChecking.cpp  |  1 +
 clang/test/CodeGenHLSL/builtins/rcp.hlsl | 53 
 clang/test/SemaHLSL/BuiltIns/rcp-errors.hlsl | 27 ++
 llvm/include/llvm/IR/IntrinsicsDirectX.td|  2 +
 7 files changed, 138 insertions(+)
 create mode 100644 clang/test/CodeGenHLSL/builtins/rcp.hlsl
 create mode 100644 clang/test/SemaHLSL/BuiltIns/rcp-errors.hlsl

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 2c83dca248fb7d..a30953f4a94fa3 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4548,6 +4548,12 @@ def HLSLLerp : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
+def HLSLRcp : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_elementwise_rcp"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void(...)";
+}
+
 // Builtins for XRay.
 def XRayCustomEvent : Builtin {
   let Spellings = ["__xray_customevent"];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e90014261217bc..aefc09767378a6 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18057,6 +18057,14 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 /*ReturnType*/ Op0->getType(), Intrinsic::dx_frac,
 ArrayRef{Op0}, nullptr, "dx.frac");
   }
+  case Builtin::BI__builtin_hlsl_elementwise_rcp: {
+Value *Op0 = EmitScalarExpr(E->getArg(0));
+if (!E->getArg(0)->getType()->hasFloatingRepresentation())
+  llvm_unreachable("rcp operand must have a float representation");
+return Builder.CreateIntrinsic(
+/*ReturnType*/ Op0->getType(), Intrinsic::dx_rcp,
+ArrayRef{Op0}, nullptr, "dx.rcp");
+  }
   }
   return nullptr;
 }
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 5180530363889f..6174461cfa8802 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -831,6 +831,47 @@ uint64_t3 reversebits(uint64_t3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_bitreverse)
 uint64_t4 reversebits(uint64_t4);
 
+//===--===//
+// rcp builtins
+//===--===//
+
+/// \fn T rcp(T x)
+/// \brief Calculates a fast, approximate, per-component reciprocal ie 1 / \a 
x.
+/// \param x The specified input value.
+///
+/// The return value is the reciprocal of the \a x parameter.
+
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rcp)
+half rcp(half);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rcp)
+half2 rcp(half2);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rcp)
+half3 rcp(half3);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rcp)
+half4 rcp(half4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rcp)
+float rcp(float);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rcp)
+float2 rcp(float2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rcp)
+float3 rcp(float3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rcp)
+float4 rcp(float4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rcp)
+double rcp(double);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rcp)
+double2 rcp(double2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rcp)
+double3 rcp(double3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rcp)
+double4 rcp(double4);
+
 
//===--===//
 // round builtins
 
//===--===//
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 0d4d57db01c93a..237c838cb8c255 100644
--- a/clang/lib/Sema/SemaChecking.cpp

[clang] [llvm] [HLSL] implement the rcp intrinsic (PR #83857)

2024-03-05 Thread Farzon Lotfi via cfe-commits


@@ -18057,6 +18057,14 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 /*ReturnType*/ Op0->getType(), Intrinsic::dx_frac,
 ArrayRef{Op0}, nullptr, "dx.frac");
   }
+  case Builtin::BI__builtin_hlsl_elementwise_rcp: {
+Value *Op0 = EmitScalarExpr(E->getArg(0));
+if (!E->getArg(0)->getType()->hasFloatingRepresentation())
+  llvm_unreachable("rcp operand must have a float representation");
+return Builder.CreateIntrinsic(
+/*ReturnType*/ Op0->getType(), Intrinsic::dx_rcp,

farzonl wrote:

done

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


[clang] [clang][StaticAnalyzer] Adding getentropy to CStringChecker. (PR #83675)

2024-03-05 Thread Balázs Kéri via cfe-commits

balazske wrote:

Currently it looks OK to add `getentropy` to this checker because it is a 
string related function in a way. Otherwise it looks like that many of the 
checks (for buffer access, and buffer invalidations) that are implemented in 
`CStringChecker` could be moved to `StdLibraryFunctionsChecker` (but this can 
be more work). 

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


[clang] [llvm] [HLSL] implement the rcp intrinsic (PR #83857)

2024-03-05 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 5105f1551b4bc800f564e7c105fc95e2c51f1239 
512a90253652db73fbc5a6bb65165f8624b9f5e3 -- clang/lib/CodeGen/CGBuiltin.cpp 
clang/lib/Headers/hlsl/hlsl_intrinsics.h clang/lib/Sema/SemaChecking.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f060cd2864..e4470daeb0 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18009,7 +18009,7 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
"Dot product requires vectors to be of the same size.");
 
 return Builder.CreateIntrinsic(
-/*ReturnType=*/ T0->getScalarType(), Intrinsic::dx_dot,
+/*ReturnType=*/T0->getScalarType(), Intrinsic::dx_dot,
 ArrayRef{Op0, Op1}, nullptr, "dx.dot");
   } break;
   case Builtin::BI__builtin_hlsl_lerp: {
@@ -18046,7 +18046,7 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
XVecTy->getElementType() == SVecTy->getElementType() &&
"Lerp requires float vectors to be of the same type.");
 return Builder.CreateIntrinsic(
-/*ReturnType=*/ Xty, Intrinsic::dx_lerp, ArrayRef{X, Y, S},
+/*ReturnType=*/Xty, Intrinsic::dx_lerp, ArrayRef{X, Y, S},
 nullptr, "dx.lerp");
   }
   case Builtin::BI__builtin_hlsl_elementwise_frac: {
@@ -18054,7 +18054,7 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 if (!E->getArg(0)->getType()->hasFloatingRepresentation())
   llvm_unreachable("frac operand must have a float representation");
 return Builder.CreateIntrinsic(
-/*ReturnType=*/ Op0->getType(), Intrinsic::dx_frac,
+/*ReturnType=*/Op0->getType(), Intrinsic::dx_frac,
 ArrayRef{Op0}, nullptr, "dx.frac");
   }
   case Builtin::BI__builtin_hlsl_elementwise_rcp: {
@@ -18062,7 +18062,7 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 if (!E->getArg(0)->getType()->hasFloatingRepresentation())
   llvm_unreachable("rcp operand must have a float representation");
 return Builder.CreateIntrinsic(
-/*ReturnType=*/ Op0->getType(), Intrinsic::dx_rcp,
+/*ReturnType=*/Op0->getType(), Intrinsic::dx_rcp,
 ArrayRef{Op0}, nullptr, "dx.rcp");
   }
   }

``




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


[clang] [llvm] [HLSL] implement the rcp intrinsic (PR #83857)

2024-03-05 Thread Farzon Lotfi via cfe-commits

https://github.com/farzonl updated 
https://github.com/llvm/llvm-project/pull/83857

>From 710cef1e42c50c935a2fdd535b48002db3796497 Mon Sep 17 00:00:00 2001
From: Farzon Lotfi 
Date: Sun, 3 Mar 2024 16:14:35 -0500
Subject: [PATCH 1/2] [HLSL] implement the rcp  intrinsic This PR implements
 the frontend for llvm#70100 This PR is part 1 of 2. Part 2 depends on
 dixl-lerp-intrinsic-lowering PR which will have an intrinsic to instruction
 expansion pass. THat pass is what we need to complete the DXIL lowering
 portion of this PR:
 llvm/llvm-project@main...farzonl:llvm-project:dixl-lerp-intrinsic-lowering

Builtins.td - add an rcp builtin
CGBuiltin.cpp add the builtin to intrinsic lowering
hlsl_intrinsics.h - add the rcp  api
SemaChecking.cpp - reuse frac's semachecks
IntrinsicsDirectX.td add the llvm intrinsic
---
 clang/include/clang/Basic/Builtins.td|  6 +++
 clang/lib/CodeGen/CGBuiltin.cpp  |  8 +++
 clang/lib/Headers/hlsl/hlsl_intrinsics.h | 41 +++
 clang/lib/Sema/SemaChecking.cpp  |  1 +
 clang/test/CodeGenHLSL/builtins/rcp.hlsl | 53 
 clang/test/SemaHLSL/BuiltIns/rcp-errors.hlsl | 27 ++
 llvm/include/llvm/IR/IntrinsicsDirectX.td|  2 +
 7 files changed, 138 insertions(+)
 create mode 100644 clang/test/CodeGenHLSL/builtins/rcp.hlsl
 create mode 100644 clang/test/SemaHLSL/BuiltIns/rcp-errors.hlsl

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 384442e6a9359b..16695d07b89d70 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4572,6 +4572,12 @@ def HLSLLerp : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
+def HLSLRcp : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_elementwise_rcp"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void(...)";
+}
+
 // Builtins for XRay.
 def XRayCustomEvent : Builtin {
   let Spellings = ["__xray_customevent"];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 9ee51ca7142c77..3f770c87b55809 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18044,6 +18044,14 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 /*ReturnType*/ Op0->getType(), Intrinsic::dx_frac,
 ArrayRef{Op0}, nullptr, "dx.frac");
   }
+  case Builtin::BI__builtin_hlsl_elementwise_rcp: {
+Value *Op0 = EmitScalarExpr(E->getArg(0));
+if (!E->getArg(0)->getType()->hasFloatingRepresentation())
+  llvm_unreachable("rcp operand must have a float representation");
+return Builder.CreateIntrinsic(
+/*ReturnType*/ Op0->getType(), Intrinsic::dx_rcp,
+ArrayRef{Op0}, nullptr, "dx.rcp");
+  }
   }
   return nullptr;
 }
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 5180530363889f..6174461cfa8802 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -831,6 +831,47 @@ uint64_t3 reversebits(uint64_t3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_bitreverse)
 uint64_t4 reversebits(uint64_t4);
 
+//===--===//
+// rcp builtins
+//===--===//
+
+/// \fn T rcp(T x)
+/// \brief Calculates a fast, approximate, per-component reciprocal ie 1 / \a 
x.
+/// \param x The specified input value.
+///
+/// The return value is the reciprocal of the \a x parameter.
+
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rcp)
+half rcp(half);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rcp)
+half2 rcp(half2);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rcp)
+half3 rcp(half3);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rcp)
+half4 rcp(half4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rcp)
+float rcp(float);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rcp)
+float2 rcp(float2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rcp)
+float3 rcp(float3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rcp)
+float4 rcp(float4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rcp)
+double rcp(double);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rcp)
+double2 rcp(double2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rcp)
+double3 rcp(double3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rcp)
+double4 rcp(double4);
+
 
//===--===//
 // round builtins
 
//===--===//
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 2cda1d08784ece..c140429e8e71f8 100644
--- a/clang/lib/Sema/SemaChecking.cpp

[clang] [clang] Bugfix for choosing the more specialized overload (PR #83279)

2024-03-05 Thread Botond István Horváth via cfe-commits


@@ -5548,13 +5504,100 @@ static bool isAtLeastAsSpecializedAs(Sema &S,
 FunctionTemplateDecl *Sema::getMoreSpecializedTemplate(
 FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc,
 TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1,
-unsigned NumCallArguments2, bool Reversed) {
+unsigned NumCallArguments2, QualType RawObjType1, QualType RawObjType2,
+bool Reversed) {
+  SmallVector Args1;
+  SmallVector Args2;
+  const FunctionDecl *FD1 = FT1->getTemplatedDecl();
+  const FunctionDecl *FD2 = FT2->getTemplatedDecl();
+  bool shouldConvert1 = false;
+  bool shouldConvert2 = false;
+  QualType ObjType1;
+  QualType ObjType2;
+  if (TPOC == TPOC_Call) {
+const FunctionProtoType *Proto1 =
+FD1->getType()->getAs();
+const FunctionProtoType *Proto2 =
+FD2->getType()->getAs();
+
+//   - In the context of a function call, the function parameter types are
+// used.
+const CXXMethodDecl *Method1 = dyn_cast(FD1);
+const CXXMethodDecl *Method2 = dyn_cast(FD2);
+
+if (getLangOpts().CPlusPlus20) {
+  // C++20 [temp.func.order]p3
+  //   [...] Each function template M that is a member function is
+  //   considered to have a new first parameter of type
+  //   X(M), described below, inserted in its function parameter list.
+  //
+  // Note that we interpret "that is a member function" as
+  // "that is a member function with no expicit object argument".
+  // Otherwise the ordering rules for methods with expicit objet arguments
+  // against anything else make no sense.
+  shouldConvert1 = Method1 && !Method1->isExplicitObjectMemberFunction();
+  shouldConvert2 = Method2 && !Method2->isExplicitObjectMemberFunction();
+} else {
+  // C++11 [temp.func.order]p3:
+  //   [...] If only one of the function templates is a non-static
+  //   member, that function template is considered to have a new
+  //   first parameter inserted in its function parameter list.
+  //
+  // Note that we interpret this to mean "if one of the function
+  // templates is a non-static member and the other is a non-member";
+  // otherwise, the ordering rules for static functions against non-static
+  // functions don't make any sense.
+  //
+  // C++98/03 doesn't have this provision but we've extended DR532 to cover
+  // it as wording was broken prior to it.
+  shouldConvert1 =
+  !Method2 && Method1 && Method1->isImplicitObjectMemberFunction();
+  shouldConvert2 =
+  !Method1 && Method2 && Method2->isImplicitObjectMemberFunction();
+}
+if (shouldConvert1) {
+  bool isR2 =
+  getLangOpts().CPlusPlus20 &&
+  (shouldConvert1
+   ? Method2->getRefQualifier() == RQ_RValue
+   : Proto2->param_type_begin()[0]->isRValueReferenceType());
+  // Compare 'this' from Method1 against first parameter from Method2.
+  ObjType1 = GetImplicitObjectParameterType(this->Context, Method1,
+RawObjType1, isR2);
+  Args1.push_back(ObjType1);
+}
+if (shouldConvert2) {
+  bool isR1 =
+  getLangOpts().CPlusPlus20 &&
+  (shouldConvert2
+   ? Method1->getRefQualifier() == RQ_RValue
+   : Proto1->param_type_begin()[0]->isRValueReferenceType());
+  // Compare 'this' from Method2 against first parameter from Method1.
+  ObjType2 = GetImplicitObjectParameterType(this->Context, Method2,
+RawObjType2, isR1);
+  Args2.push_back(ObjType2);
+}
+unsigned NumComparedArguments = NumCallArguments1 + shouldConvert1;
 
-  bool Better1 = isAtLeastAsSpecializedAs(*this, Loc, FT1, FT2, TPOC,
-  NumCallArguments1, Reversed);
-  bool Better2 = isAtLeastAsSpecializedAs(*this, Loc, FT2, FT1, TPOC,
-  NumCallArguments2, Reversed);
+Args1.insert(Args1.end(), Proto1->param_type_begin(),
+ Proto1->param_type_end());
+Args2.insert(Args2.end(), Proto2->param_type_begin(),
+ Proto2->param_type_end());
 
+// C++ [temp.func.order]p5:
+//   The presence of unused ellipsis and default arguments has no effect on
+//   the partial ordering of function templates.
+if (Args1.size() > NumComparedArguments)

HoBoIs wrote:

Done

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


[clang] [llvm] [HLSL] implement exp intrinsic (PR #83832)

2024-03-05 Thread Justin Bogner via cfe-commits

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


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


[clang] 2807ea6 - [HLSL] implement the any intrinsic (#83903)

2024-03-05 Thread via cfe-commits

Author: Farzon Lotfi
Date: 2024-03-05T12:46:01-05:00
New Revision: 2807ea6b8047780b5e66a122faf09fae786c917b

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

LOG: [HLSL] implement the any intrinsic (#83903)

This PR implements the frontend for #70076
This PR is part 1 of 2.
Part 2 requires an intrinsic to instructions lowering.

- `Builtins.td` - add an `any` builtin
- `CGBuiltin.cpp` add the builtin to intrinsic lowering
- `hlsl_basic_types.h` -add the `bool` vectors since that is an input
for any
- `hlsl_intrinsics.h` - add the `any`  api
- `SemaChecking.cpp` - addy `any` builtin checking
- `IntrinsicsDirectX.td` - add the llvm intrinsic

Added: 
clang/test/CodeGenHLSL/builtins/any.hlsl
clang/test/SemaHLSL/BuiltIns/any-errors.hlsl

Modified: 
clang/include/clang/Basic/Builtins.td
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Headers/hlsl/hlsl_basic_types.h
clang/lib/Headers/hlsl/hlsl_intrinsics.h
clang/lib/Sema/SemaChecking.cpp
llvm/include/llvm/IR/IntrinsicsDirectX.td

Removed: 




diff  --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 26c7be47891451..dd9c1bb9e5f8e1 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4542,6 +4542,12 @@ def GetDeviceSideMangledName : LangBuiltin<"CUDA_LANG"> {
 }
 
 // HLSL
+def HLSLAny : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_elementwise_any"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "bool(...)";
+}
+
 def HLSLWaveActiveCountBits : LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_wave_active_count_bits"];
   let Attributes = [NoThrow, Const];

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 191f6d5a9fab5e..31d13d590bc71d 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -17963,6 +17963,12 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 return nullptr;
 
   switch (BuiltinID) {
+  case Builtin::BI__builtin_hlsl_elementwise_any: {
+Value *Op0 = EmitScalarExpr(E->getArg(0));
+return Builder.CreateIntrinsic(
+/*ReturnType*/ llvm::Type::getInt1Ty(getLLVMContext()),
+Intrinsic::dx_any, ArrayRef{Op0}, nullptr, "dx.any");
+  }
   case Builtin::BI__builtin_hlsl_dot: {
 Value *Op0 = EmitScalarExpr(E->getArg(0));
 Value *Op1 = EmitScalarExpr(E->getArg(1));

diff  --git a/clang/lib/Headers/hlsl/hlsl_basic_types.h 
b/clang/lib/Headers/hlsl/hlsl_basic_types.h
index 3d0d296aadca3a..da6903df65ffed 100644
--- a/clang/lib/Headers/hlsl/hlsl_basic_types.h
+++ b/clang/lib/Headers/hlsl/hlsl_basic_types.h
@@ -42,7 +42,9 @@ typedef vector uint16_t2;
 typedef vector uint16_t3;
 typedef vector uint16_t4;
 #endif
-
+typedef vector bool2;
+typedef vector bool3;
+typedef vector bool4;
 typedef vector int2;
 typedef vector int3;
 typedef vector int4;

diff  --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index ed288fa1b692f7..b794a96f0bf320 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -100,6 +100,118 @@ double3 abs(double3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_abs)
 double4 abs(double4);
 
+//===--===//
+// any builtins
+//===--===//
+
+/// \fn bool any(T x)
+/// \brief Returns True if any components of the \a x parameter are non-zero;
+/// otherwise, false. \param x The input value.
+
+#ifdef __HLSL_ENABLE_16_BIT
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_any)
+bool any(int16_t);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_any)
+bool any(int16_t2);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_any)
+bool any(int16_t3);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_any)
+bool any(int16_t4);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_any)
+bool any(uint16_t);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_any)
+bool any(uint16_t2);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_any)
+bool any(uint16_t3);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_any)
+bool any(uint16_t4);
+#endif
+
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_any)
+bool any(half);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_any)
+bool any(half2);
+_HLSL_

[clang] [llvm] [HLSL] implement the any intrinsic (PR #83903)

2024-03-05 Thread Farzon Lotfi via cfe-commits

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


[clang] [clang-tools-extra] [lld] [lldb] [llvm] [mlir] Rename llvm::ThreadPool -> llvm::DefaultThreadPool (NFC) (PR #83702)

2024-03-05 Thread David Blaikie via cfe-commits

dwblaikie wrote:

> I did the first part of the renaming @dwblaikie : looks good?

Hmm - this patch still seems to have both renamings in it, if I'm reading the 
PR correctly? I take it from the subject that isn't the intent/the intent is 
that his patch only does the ThreadPool->DefaultThreadPool change?

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


[clang] [clang-tools-extra] [lld] [lldb] [llvm] [mlir] Rename llvm::ThreadPool -> llvm::DefaultThreadPool (NFC) (PR #83702)

2024-03-05 Thread David Blaikie via cfe-commits

dwblaikie wrote:

Oh, maybe issues related to layered patches - this is intended to be submitted 
after the introduction of the ThreadPoolInterface? But includes those changes 
in this review at  the moment (I still haven't figured out what we're doing for 
dependent changes - and I thought the ThreadPoolInterface-introducing patch was 
already in - so not sure why it appears in this patch too)

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


[clang] [Clang][Sema] Diagnose class member access expressions naming non-existent members of the current instantiation prior to instantiation in the absence of dependent base classes (PR #84050)

2024-03-05 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian created 
https://github.com/llvm/llvm-project/pull/84050

Consider the following:
```cpp
template
struct A
{
auto f()
{
return this->x;
}
};
```
Although `A` has no dependent base classes and the lookup context for `x` is 
the current instantiation, we currently do not diagnose the absence of a member 
`x` until `A::f` is instantiated. This patch moves the point of diagnosis 
for such expressions to occur at the point of definition. 

Note that this PR is a bit of a work in progress. Although it passes all tests, 
some aspects (e.g. calling `LookupResult::setNotFoundInCurrentInstantiation` in 
`LookupMemberExprInRecord`, using `Type::getAsRecordDecl` to determine whether 
a type names the current instantiation, and using `computeDeclContext` to 
determine whether a nested-name-specifier names the current instantiation) are 
a bit "sketchy" and may need some work. I also need to add more tests, e.g. for 
using declarations, or class member access expressions naming members of nested 
classes which are explicitly specialized for a given implicitly instantiated 
specialization of the enclosing class template. 

>From 1495e87d7cbbab6a824d9d1d2bf53d0ef9ec9125 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Fri, 1 Mar 2024 08:08:52 -0500
Subject: [PATCH 1/6] [Clang][Sema] Earlier resolution of class member access
 expressions naming member of the current instantiation

---
 clang/lib/AST/Expr.cpp  |   2 +-
 clang/lib/Sema/SemaExpr.cpp |   4 +-
 clang/lib/Sema/SemaExprMember.cpp   | 121 ++--
 clang/lib/Sema/SemaOverload.cpp |   3 +
 clang/test/SemaTemplate/dependent-names.cpp |   4 +-
 5 files changed, 93 insertions(+), 41 deletions(-)

diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index b4de2155adcebd..643c938d63c654 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -103,7 +103,7 @@ const Expr *Expr::skipRValueSubobjectAdjustments(
   }
 } else if (const auto *ME = dyn_cast(E)) {
   if (!ME->isArrow()) {
-assert(ME->getBase()->getType()->isRecordType());
+assert(ME->getBase()->getType()->getAsRecordDecl());
 if (const auto *Field = dyn_cast(ME->getMemberDecl())) {
   if (!Field->isBitField() && !Field->getType()->isReferenceType()) {
 E = ME->getBase();
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 47bb263f56aade..e071c3e580b9d8 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -666,7 +666,9 @@ ExprResult Sema::DefaultLvalueConversion(Expr *E) {
   // expressions of certain types in C++.
   if (getLangOpts().CPlusPlus &&
   (E->getType() == Context.OverloadTy ||
-   T->isDependentType() ||
+  // FIXME: This is a hack! We want the lvalue-to-rvalue conversion applied
+  // to pointer types even if the pointee type is dependent.
+  (T->isDependentType() && !T->isPointerType()) ||
T->isRecordType()))
 return E;
 
diff --git a/clang/lib/Sema/SemaExprMember.cpp 
b/clang/lib/Sema/SemaExprMember.cpp
index 32998ae60eafe2..fd55e6f46a1066 100644
--- a/clang/lib/Sema/SemaExprMember.cpp
+++ b/clang/lib/Sema/SemaExprMember.cpp
@@ -624,8 +624,8 @@ namespace {
 // classes, one of its base classes.
 class RecordMemberExprValidatorCCC final : public CorrectionCandidateCallback {
 public:
-  explicit RecordMemberExprValidatorCCC(const RecordType *RTy)
-  : Record(RTy->getDecl()) {
+  explicit RecordMemberExprValidatorCCC(QualType RTy)
+  : Record(RTy->getAsRecordDecl()) {
 // Don't add bare keywords to the consumer since they will always fail
 // validation by virtue of not being associated with any decls.
 WantTypeSpecifiers = false;
@@ -671,33 +671,55 @@ class RecordMemberExprValidatorCCC final : public 
CorrectionCandidateCallback {
 
 static bool LookupMemberExprInRecord(Sema &SemaRef, LookupResult &R,
  Expr *BaseExpr,
- const RecordType *RTy,
+ QualType RTy,
  SourceLocation OpLoc, bool IsArrow,
  CXXScopeSpec &SS, bool HasTemplateArgs,
  SourceLocation TemplateKWLoc,
  TypoExpr *&TE) {
+  RecordDecl *RDecl = RTy->getAsRecordDecl();
+  DeclContext *DC = SemaRef.computeDeclContext(RTy);
+  // If the object expression is dependent and isn't the current instantiation,
+  // lookup will not find anything and we must defer until instantiation.
+  if (!DC) {
+R.setNotFoundInCurrentInstantiation();
+return false;
+  }
+
+  // FIXME: Should this use Name.isDependentName()?
+  if (DeclarationName Name = R.getLookupName();
+  Name.getNameKind() == DeclarationName::CXXConversionFunctionName &&
+  Name.getCXXNameType()->isDependentType()) {
+R

[clang] [Clang][Sema] Diagnose class member access expressions naming non-existent members of the current instantiation prior to instantiation in the absence of dependent base classes (PR #84050)

2024-03-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Krystian Stasiowski (sdkrystian)


Changes

Consider the following:
```cpp
template
struct A
{
auto f()
{
return this->x;
}
};
```
Although `A` has no dependent base classes and the lookup context for `x` is 
the current instantiation, we currently do not diagnose the absence of a member 
`x` until `A::f` is instantiated. This patch moves the point of 
diagnosis for such expressions to occur at the point of definition. 

Note that this PR is a bit of a work in progress. Although it passes all tests, 
some aspects (e.g. calling `LookupResult::setNotFoundInCurrentInstantiation` in 
`LookupMemberExprInRecord`, using `Type::getAsRecordDecl` to determine whether 
a type names the current instantiation, and using `computeDeclContext` to 
determine whether a nested-name-specifier names the current instantiation) are 
a bit "sketchy" and may need some work. I also need to add more tests, e.g. for 
using declarations, or class member access expressions naming members of nested 
classes which are explicitly specialized for a given implicitly instantiated 
specialization of the enclosing class template. 

---

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


11 Files Affected:

- (modified) clang/lib/AST/Expr.cpp (+1-1) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+3-1) 
- (modified) clang/lib/Sema/SemaExprMember.cpp (+80-52) 
- (modified) clang/lib/Sema/SemaOverload.cpp (+3) 
- (modified) clang/lib/Sema/TreeTransform.h (+20) 
- (modified) clang/test/AST/HLSL/this-reference-template.hlsl (+1-1) 
- (added) clang/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p4.cpp (+110) 
- (modified) clang/test/CodeGenCXX/mangle.cpp (-8) 
- (modified) clang/test/Index/annotate-nested-name-specifier.cpp (+2-2) 
- (modified) clang/test/SemaTemplate/instantiate-function-1.cpp (+7-7) 
- (modified) clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp (+2-2) 


``diff
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index b4de2155adcebd..643c938d63c654 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -103,7 +103,7 @@ const Expr *Expr::skipRValueSubobjectAdjustments(
   }
 } else if (const auto *ME = dyn_cast(E)) {
   if (!ME->isArrow()) {
-assert(ME->getBase()->getType()->isRecordType());
+assert(ME->getBase()->getType()->getAsRecordDecl());
 if (const auto *Field = dyn_cast(ME->getMemberDecl())) {
   if (!Field->isBitField() && !Field->getType()->isReferenceType()) {
 E = ME->getBase();
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 47bb263f56aade..e071c3e580b9d8 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -666,7 +666,9 @@ ExprResult Sema::DefaultLvalueConversion(Expr *E) {
   // expressions of certain types in C++.
   if (getLangOpts().CPlusPlus &&
   (E->getType() == Context.OverloadTy ||
-   T->isDependentType() ||
+  // FIXME: This is a hack! We want the lvalue-to-rvalue conversion applied
+  // to pointer types even if the pointee type is dependent.
+  (T->isDependentType() && !T->isPointerType()) ||
T->isRecordType()))
 return E;
 
diff --git a/clang/lib/Sema/SemaExprMember.cpp 
b/clang/lib/Sema/SemaExprMember.cpp
index 32998ae60eafe2..eb87e0edda0128 100644
--- a/clang/lib/Sema/SemaExprMember.cpp
+++ b/clang/lib/Sema/SemaExprMember.cpp
@@ -624,8 +624,8 @@ namespace {
 // classes, one of its base classes.
 class RecordMemberExprValidatorCCC final : public CorrectionCandidateCallback {
 public:
-  explicit RecordMemberExprValidatorCCC(const RecordType *RTy)
-  : Record(RTy->getDecl()) {
+  explicit RecordMemberExprValidatorCCC(QualType RTy)
+  : Record(RTy->getAsRecordDecl()) {
 // Don't add bare keywords to the consumer since they will always fail
 // validation by virtue of not being associated with any decls.
 WantTypeSpecifiers = false;
@@ -671,33 +671,54 @@ class RecordMemberExprValidatorCCC final : public 
CorrectionCandidateCallback {
 
 static bool LookupMemberExprInRecord(Sema &SemaRef, LookupResult &R,
  Expr *BaseExpr,
- const RecordType *RTy,
+ QualType RTy,
  SourceLocation OpLoc, bool IsArrow,
  CXXScopeSpec &SS, bool HasTemplateArgs,
  SourceLocation TemplateKWLoc,
  TypoExpr *&TE) {
+  DeclContext *DC = SemaRef.computeDeclContext(RTy);
+  // If the object expression is dependent and isn't the current instantiation,
+  // lookup will not find anything and we must defer until instantiation.
+  if (!DC) {
+R.setNotFoundInCurrentInstantiation();
+return false;
+  }
+
+  // FIXME: Should this use Name

[clang] [Clang][Sema] Diagnose class member access expressions naming non-existent members of the current instantiation prior to instantiation in the absence of dependent base classes (PR #84050)

2024-03-05 Thread Krystian Stasiowski via cfe-commits

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


[clang] [Doc][HLSL] Add documentation for root signature. (PR #83933)

2024-03-05 Thread Damyan Pepper via cfe-commits

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


[clang] [Doc][HLSL] Add documentation for root signature. (PR #83933)

2024-03-05 Thread Damyan Pepper via cfe-commits

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


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


[clang] [Doc][HLSL] Add documentation for root signature. (PR #83933)

2024-03-05 Thread Damyan Pepper via cfe-commits


@@ -0,0 +1,312 @@
+
+HLSL Root Signatures
+
+
+.. contents::
+   :local:
+
+Usage
+=
+
+In HLSL, the `root signature
+`_ 
+defines what types of resources are bound to the graphics pipeline. 
+
+A root signature can be specified in HLSL as a `string
+`_.
 
+The string contains a collection of comma-separated clauses that describe root 
+signature constituent components. 
+
+There are two mechanisms to compile an HLSL root signature. First, it is 
+possible to attach a root signature string to a particular shader via the 
+RootSignature attribute (in the following example, using the MyRS1 entry 
+point):
+
+.. code-block:: c++
+
+#define RS "RootFlags( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT | " \ 
+  "DENY_VERTEX_SHADER_ROOT_ACCESS), " \ 
+  "CBV(b0, space = 1, flags = DATA_STATIC), " \ 
+  "SRV(t0), " \ 
+  "UAV(u0), " \ 
+  "DescriptorTable( CBV(b1), " \ 
+  " SRV(t1, numDescriptors = 8, " \ 
+  " flags = DESCRIPTORS_VOLATILE), " \ 
+  " UAV(u1, numDescriptors = unbounded, " \ 
+  " flags = DESCRIPTORS_VOLATILE)), " \ 
+  "DescriptorTable(Sampler(s0, space=1, numDescriptors = 4)), " \ 
+  "RootConstants(num32BitConstants=3, b10), " \ 
+  "StaticSampler(s1)," \ 
+  "StaticSampler(s2, " \ 
+  "  addressU = TEXTURE_ADDRESS_CLAMP, " \ 
+  "  filter = FILTER_MIN_MAG_MIP_LINEAR )"
+
+[RootSignature(RS)]
+float4 main(float4 coord : COORD) : SV_Target
+{
+…
+}
+
+The compiler will create and verify the root signature blob for the shader and 
+embed it alongside the shader byte code into the shader blob. 
+
+The other mechanism is to create a standalone root signature blob, perhaps to 
+reuse it with a large set of shaders, saving space. The name of the define 
+string is specified via the usual -E argument. For example:
+
+.. code-block:: c++
+
+  dxc.exe -T rootsig_1_1 MyRS1.hlsl -E MyRS1 -Fo MyRS1.fxo
+
+Note that the root signature string define can also be passed on the command 
+line, e.g, -D MyRS1=”…”.
+
+Root Signature Grammar
+==
+
+.. code-block:: c++
+
+RootSignature : (RootElement(,RootElement)?)?
+
+RootElement : RootFlags | RootConstants | RootCBV | RootSRV | RootUAV |
+  DescriptorTable | StaticSampler
+
+RootFlags : 'RootFlags' '(' (RootFlag(|RootFlag)?)? ')'
+
+RootFlag : 'ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT' | 
+   'DENY_VERTEX_SHADER_ROOT_ACCESS'
+
+RootConstants : 'RootConstants' '(' 'num32BitConstants' '=' NUMBER ',' 
+   bReg (',' 'space' '=' NUMBER)? 
+   (',' 'visibility' '=' SHADER_VISIBILITY)? ')'
+
+RootCBV : 'CBV' '(' bReg (',' 'space' '=' NUMBER)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+RootSRV : 'SRV' '(' tReg (',' 'space' '=' NUMBER)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+RootUAV : 'UAV' '(' uReg (',' 'space' '=' NUMBER)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+DescriptorTable : 'DescriptorTable' '(' (DTClause(|DTClause)?)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? ')'
+
+DTClause : CBV | SRV | UAV | Sampler
+
+CBV : 'CBV' '(' bReg (',' 'numDescriptors' '=' NUMBER)? 
+  (',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+SRV : 'SRV' '(' tReg (',' 'numDescriptors' '=' NUMBER)? 
+(',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+UAV : 'UAV' '(' uReg (',' 'numDescriptors' '=' NUMBER)? 
+  (',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+Sampler : 'Sampler' '(' sReg (',' 'numDescriptors' '=' NUMBER)? 
+  (',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? (',' 'flags' '=' 
NUMBER)? ')'
+
+
+SHADER_VISIBILITY : 'SHADER_VISIBILITY_ALL' | 'SHADER_VISIBILITY_VERTEX' | 
+'SHADER_VISIBILITY_HULL' | 
+'SHADER_VISIBILITY_DOMAIN' | 
+'SHADER_VISIBILITY_GEOMETRY' | 
+'SHADER_VISIBILITY_PIXEL' | 
+'SHADER_VISIBILITY_AMPLIFICATION' | 
+'SHADER_VISIBILITY_MESH'
+
+DATA_FLAGS : 'DATA_STATIC_WH

[clang] [Clang][Sema] Diagnose class member access expressions naming non-existent members of the current instantiation prior to instantiation in the absence of dependent base classes (PR #84050)

2024-03-05 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff a642eb89bdaf10c6b4994fc1187de27b441236ed 
5fc710a43e7799d2721e56dd53d5828e55090a0d -- 
clang/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p4.cpp 
clang/lib/AST/Expr.cpp clang/lib/Sema/SemaExpr.cpp 
clang/lib/Sema/SemaExprMember.cpp clang/lib/Sema/SemaOverload.cpp 
clang/lib/Sema/TreeTransform.h clang/test/CodeGenCXX/mangle.cpp 
clang/test/Index/annotate-nested-name-specifier.cpp 
clang/test/SemaTemplate/instantiate-function-1.cpp 
clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index e071c3e580..22216dc9e0 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -666,10 +666,9 @@ ExprResult Sema::DefaultLvalueConversion(Expr *E) {
   // expressions of certain types in C++.
   if (getLangOpts().CPlusPlus &&
   (E->getType() == Context.OverloadTy ||
-  // FIXME: This is a hack! We want the lvalue-to-rvalue conversion applied
-  // to pointer types even if the pointee type is dependent.
-  (T->isDependentType() && !T->isPointerType()) ||
-   T->isRecordType()))
+   // FIXME: This is a hack! We want the lvalue-to-rvalue conversion 
applied
+   // to pointer types even if the pointee type is dependent.
+   (T->isDependentType() && !T->isPointerType()) || T->isRecordType()))
 return E;
 
   // The C standard is actually really unclear on this point, and
diff --git a/clang/lib/Sema/SemaExprMember.cpp 
b/clang/lib/Sema/SemaExprMember.cpp
index eb87e0edda..da32ea251a 100644
--- a/clang/lib/Sema/SemaExprMember.cpp
+++ b/clang/lib/Sema/SemaExprMember.cpp
@@ -670,8 +670,7 @@ private:
 }
 
 static bool LookupMemberExprInRecord(Sema &SemaRef, LookupResult &R,
- Expr *BaseExpr,
- QualType RTy,
+ Expr *BaseExpr, QualType RTy,
  SourceLocation OpLoc, bool IsArrow,
  CXXScopeSpec &SS, bool HasTemplateArgs,
  SourceLocation TemplateKWLoc,
@@ -695,9 +694,8 @@ static bool LookupMemberExprInRecord(Sema &SemaRef, 
LookupResult &R,
   SourceRange BaseRange = BaseExpr ? BaseExpr->getSourceRange() : 
SourceRange();
   if (!RTy->isDependentType() &&
   !SemaRef.isThisOutsideMemberFunctionBody(RTy) &&
-  SemaRef.RequireCompleteType(OpLoc, RTy,
-  diag::err_typecheck_incomplete_tag,
-  BaseRange))
+  SemaRef.RequireCompleteType(
+  OpLoc, RTy, diag::err_typecheck_incomplete_tag, BaseRange))
 return true;
 
   if (HasTemplateArgs || TemplateKWLoc.isValid()) {
@@ -792,16 +790,12 @@ static ExprResult LookupMemberExpr(Sema &S, LookupResult 
&R,
Decl *ObjCImpDecl, bool HasTemplateArgs,
SourceLocation TemplateKWLoc);
 
-ExprResult
-Sema::BuildMemberReferenceExpr(Expr *Base, QualType BaseType,
-   SourceLocation OpLoc, bool IsArrow,
-   CXXScopeSpec &SS,
-   SourceLocation TemplateKWLoc,
-   NamedDecl *FirstQualifierInScope,
-   const DeclarationNameInfo &NameInfo,
-   const TemplateArgumentListInfo *TemplateArgs,
-   const Scope *S,
-   ActOnMemberAccessExtraArgs *ExtraArgs) {
+ExprResult Sema::BuildMemberReferenceExpr(
+Expr *Base, QualType BaseType, SourceLocation OpLoc, bool IsArrow,
+CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
+NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &NameInfo,
+const TemplateArgumentListInfo *TemplateArgs, const Scope *S,
+ActOnMemberAccessExtraArgs *ExtraArgs) {
   LookupResult R(*this, NameInfo, LookupMemberName);
 
   // Implicit member accesses.
@@ -809,9 +803,9 @@ Sema::BuildMemberReferenceExpr(Expr *Base, QualType 
BaseType,
 TypoExpr *TE = nullptr;
 QualType RecordTy = BaseType;
 if (IsArrow) RecordTy = RecordTy->castAs()->getPointeeType();
-if (LookupMemberExprInRecord(
-*this, R, nullptr, RecordTy, OpLoc, IsArrow,
-SS, TemplateArgs != nullptr, TemplateKWLoc, TE))
+if (LookupMemberExprInRecord(*this, R, nullptr, RecordTy, OpLoc, IsArrow,
+ SS, TemplateArgs != nullptr, TemplateKWLoc,
+ TE))
   return ExprError();
 if (TE)
   return TE;
@@ -1006,9 +1000,8 @@ Sema::BuildMemberReferenceExpr(Expr *BaseExpr, QualType 
BaseExprType,
 
   if (R.wasNotFound

[clang] [Clang][Sema] Diagnose class member access expressions naming non-existent members of the current instantiation prior to instantiation in the absence of dependent base classes (PR #84050)

2024-03-05 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian updated 
https://github.com/llvm/llvm-project/pull/84050

>From 1495e87d7cbbab6a824d9d1d2bf53d0ef9ec9125 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Fri, 1 Mar 2024 08:08:52 -0500
Subject: [PATCH 1/7] [Clang][Sema] Earlier resolution of class member access
 expressions naming member of the current instantiation

---
 clang/lib/AST/Expr.cpp  |   2 +-
 clang/lib/Sema/SemaExpr.cpp |   4 +-
 clang/lib/Sema/SemaExprMember.cpp   | 121 ++--
 clang/lib/Sema/SemaOverload.cpp |   3 +
 clang/test/SemaTemplate/dependent-names.cpp |   4 +-
 5 files changed, 93 insertions(+), 41 deletions(-)

diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index b4de2155adcebd..643c938d63c654 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -103,7 +103,7 @@ const Expr *Expr::skipRValueSubobjectAdjustments(
   }
 } else if (const auto *ME = dyn_cast(E)) {
   if (!ME->isArrow()) {
-assert(ME->getBase()->getType()->isRecordType());
+assert(ME->getBase()->getType()->getAsRecordDecl());
 if (const auto *Field = dyn_cast(ME->getMemberDecl())) {
   if (!Field->isBitField() && !Field->getType()->isReferenceType()) {
 E = ME->getBase();
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 47bb263f56aade..e071c3e580b9d8 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -666,7 +666,9 @@ ExprResult Sema::DefaultLvalueConversion(Expr *E) {
   // expressions of certain types in C++.
   if (getLangOpts().CPlusPlus &&
   (E->getType() == Context.OverloadTy ||
-   T->isDependentType() ||
+  // FIXME: This is a hack! We want the lvalue-to-rvalue conversion applied
+  // to pointer types even if the pointee type is dependent.
+  (T->isDependentType() && !T->isPointerType()) ||
T->isRecordType()))
 return E;
 
diff --git a/clang/lib/Sema/SemaExprMember.cpp 
b/clang/lib/Sema/SemaExprMember.cpp
index 32998ae60eafe2..fd55e6f46a1066 100644
--- a/clang/lib/Sema/SemaExprMember.cpp
+++ b/clang/lib/Sema/SemaExprMember.cpp
@@ -624,8 +624,8 @@ namespace {
 // classes, one of its base classes.
 class RecordMemberExprValidatorCCC final : public CorrectionCandidateCallback {
 public:
-  explicit RecordMemberExprValidatorCCC(const RecordType *RTy)
-  : Record(RTy->getDecl()) {
+  explicit RecordMemberExprValidatorCCC(QualType RTy)
+  : Record(RTy->getAsRecordDecl()) {
 // Don't add bare keywords to the consumer since they will always fail
 // validation by virtue of not being associated with any decls.
 WantTypeSpecifiers = false;
@@ -671,33 +671,55 @@ class RecordMemberExprValidatorCCC final : public 
CorrectionCandidateCallback {
 
 static bool LookupMemberExprInRecord(Sema &SemaRef, LookupResult &R,
  Expr *BaseExpr,
- const RecordType *RTy,
+ QualType RTy,
  SourceLocation OpLoc, bool IsArrow,
  CXXScopeSpec &SS, bool HasTemplateArgs,
  SourceLocation TemplateKWLoc,
  TypoExpr *&TE) {
+  RecordDecl *RDecl = RTy->getAsRecordDecl();
+  DeclContext *DC = SemaRef.computeDeclContext(RTy);
+  // If the object expression is dependent and isn't the current instantiation,
+  // lookup will not find anything and we must defer until instantiation.
+  if (!DC) {
+R.setNotFoundInCurrentInstantiation();
+return false;
+  }
+
+  // FIXME: Should this use Name.isDependentName()?
+  if (DeclarationName Name = R.getLookupName();
+  Name.getNameKind() == DeclarationName::CXXConversionFunctionName &&
+  Name.getCXXNameType()->isDependentType()) {
+R.setNotFoundInCurrentInstantiation();
+return false;
+  }
+
   SourceRange BaseRange = BaseExpr ? BaseExpr->getSourceRange() : 
SourceRange();
-  RecordDecl *RDecl = RTy->getDecl();
-  if (!SemaRef.isThisOutsideMemberFunctionBody(QualType(RTy, 0)) &&
-  SemaRef.RequireCompleteType(OpLoc, QualType(RTy, 0),
+  if (!RTy->isDependentType() &&
+  !SemaRef.isThisOutsideMemberFunctionBody(RTy) &&
+  SemaRef.RequireCompleteType(OpLoc, RTy,
   diag::err_typecheck_incomplete_tag,
   BaseRange))
 return true;
 
   if (HasTemplateArgs || TemplateKWLoc.isValid()) {
 // LookupTemplateName doesn't expect these both to exist simultaneously.
-QualType ObjectType = SS.isSet() ? QualType() : QualType(RTy, 0);
+QualType ObjectType = SS.isSet() ? QualType() : RTy;
 
 bool MOUS;
 return SemaRef.LookupTemplateName(R, nullptr, SS, ObjectType, false, MOUS,
   TemplateKWLoc);
   }
 
-  DeclContext *DC = RDecl;
   if (SS.isSet()) {
 // If the member name wa

[clang] [llvm] [HLSL] implement the rcp intrinsic (PR #83857)

2024-03-05 Thread Farzon Lotfi via cfe-commits

https://github.com/farzonl updated 
https://github.com/llvm/llvm-project/pull/83857

>From 786d0b41971dcd39fd76ae24ef16c8d086abb092 Mon Sep 17 00:00:00 2001
From: Farzon Lotfi 
Date: Tue, 5 Mar 2024 12:52:39 -0500
Subject: [PATCH] fix merge conflict, address pr concerns

---
 clang/include/clang/Basic/Builtins.td|  6 +++
 clang/lib/CodeGen/CGBuiltin.cpp  | 18 +--
 clang/lib/Headers/hlsl/hlsl_intrinsics.h | 41 +++
 clang/lib/Sema/SemaChecking.cpp  |  1 +
 clang/test/CodeGenHLSL/builtins/rcp.hlsl | 53 
 clang/test/SemaHLSL/BuiltIns/rcp-errors.hlsl | 27 ++
 llvm/include/llvm/IR/IntrinsicsDirectX.td|  5 +-
 7 files changed, 144 insertions(+), 7 deletions(-)
 create mode 100644 clang/test/CodeGenHLSL/builtins/rcp.hlsl
 create mode 100644 clang/test/SemaHLSL/BuiltIns/rcp-errors.hlsl

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index dd9c1bb9e5f8e1..a81131d82c4cb4 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4584,6 +4584,12 @@ def HLSLMad : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
+def HLSLRcp : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_elementwise_rcp"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void(...)";
+}
+
 // Builtins for XRay.
 def XRayCustomEvent : Builtin {
   let Spellings = ["__xray_customevent"];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 31d13d590bc71d..cc30665a4d 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -17966,7 +17966,7 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
   case Builtin::BI__builtin_hlsl_elementwise_any: {
 Value *Op0 = EmitScalarExpr(E->getArg(0));
 return Builder.CreateIntrinsic(
-/*ReturnType*/ llvm::Type::getInt1Ty(getLLVMContext()),
+/*ReturnType=*/llvm::Type::getInt1Ty(getLLVMContext()),
 Intrinsic::dx_any, ArrayRef{Op0}, nullptr, "dx.any");
   }
   case Builtin::BI__builtin_hlsl_dot: {
@@ -18002,7 +18002,7 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
"Dot product requires vectors to be of the same size.");
 
 return Builder.CreateIntrinsic(
-/*ReturnType*/ T0->getScalarType(), Intrinsic::dx_dot,
+/*ReturnType=*/T0->getScalarType(), Intrinsic::dx_dot,
 ArrayRef{Op0, Op1}, nullptr, "dx.dot");
   } break;
   case Builtin::BI__builtin_hlsl_lerp: {
@@ -18039,7 +18039,7 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
XVecTy->getElementType() == SVecTy->getElementType() &&
"Lerp requires float vectors to be of the same type.");
 return Builder.CreateIntrinsic(
-/*ReturnType*/ Xty, Intrinsic::dx_lerp, ArrayRef{X, Y, S},
+/*ReturnType=*/Xty, Intrinsic::dx_lerp, ArrayRef{X, Y, S},
 nullptr, "dx.lerp");
   }
   case Builtin::BI__builtin_hlsl_elementwise_frac: {
@@ -18047,7 +18047,7 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 if (!E->getArg(0)->getType()->hasFloatingRepresentation())
   llvm_unreachable("frac operand must have a float representation");
 return Builder.CreateIntrinsic(
-/*ReturnType*/ Op0->getType(), Intrinsic::dx_frac,
+/*ReturnType=*/Op0->getType(), Intrinsic::dx_frac,
 ArrayRef{Op0}, nullptr, "dx.frac");
   }
   case Builtin::BI__builtin_hlsl_mad: {
@@ -18066,9 +18066,17 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 }
 assert(E->getArg(0)->getType()->hasUnsignedIntegerRepresentation());
 return Builder.CreateIntrinsic(
-/*ReturnType*/ M->getType(), Intrinsic::dx_umad,
+/*ReturnType=*/M->getType(), Intrinsic::dx_umad,
 ArrayRef{M, A, B}, nullptr, "dx.umad");
   }
+  case Builtin::BI__builtin_hlsl_elementwise_rcp: {
+Value *Op0 = EmitScalarExpr(E->getArg(0));
+if (!E->getArg(0)->getType()->hasFloatingRepresentation())
+  llvm_unreachable("rcp operand must have a float representation");
+return Builder.CreateIntrinsic(
+/*ReturnType=*/Op0->getType(), Intrinsic::dx_rcp,
+ArrayRef{Op0}, nullptr, "dx.rcp");
+  }
   }
   return nullptr;
 }
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index b794a96f0bf320..45f8544392584e 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -1112,6 +1112,47 @@ uint64_t3 reversebits(uint64_t3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_bitreverse)
 uint64_t4 reversebits(uint64_t4);
 
+//===--===//
+// rcp builtins
+//===--===//
+
+/// \fn T rcp(T x)
+/// \brief Calculates a fast, approximate, per-component reciprocal ie 1 / \a 
x.
+/// \param

[clang] [Clang][Sema] Diagnose class member access expressions naming non-existent members of the current instantiation prior to instantiation in the absence of dependent base classes (PR #84050)

2024-03-05 Thread Erich Keane via cfe-commits

https://github.com/erichkeane commented:

I like the direction of this, and look forward to seeing how this turns out!



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


[clang] [llvm] [CMAKE] Enable FatLTO as a build option for LLVM (PR #80480)

2024-03-05 Thread Paul Kirth via cfe-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/80480

>From 1946ea0be5b87da44e05a5e668e383c3c463cdd7 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Tue, 22 Aug 2023 15:24:03 +
Subject: [PATCH 1/3] [CMAKE] Enable FatLTO as a build option for LLVM

---
 clang/cmake/caches/Fuchsia-stage2.cmake|  1 +
 llvm/cmake/modules/AddLLVM.cmake   | 11 +--
 llvm/cmake/modules/HandleLLVMOptions.cmake |  6 ++
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index eee37c5e7901fa..d5a1662cbf4aa6 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -11,6 +11,7 @@ set(LLVM_ENABLE_RUNTIMES 
"compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "
 
 set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
 set(LLVM_ENABLE_DIA_SDK OFF CACHE BOOL "")
+set(LLVM_ENABLE_FATLTO ON CACHE BOOL "")
 set(LLVM_ENABLE_HTTPLIB ON CACHE BOOL "")
 set(LLVM_ENABLE_LIBCXX ON CACHE BOOL "")
 set(LLVM_ENABLE_LIBEDIT OFF CACHE BOOL "")
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 828de4bd9940d6..2228237645be63 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -1621,8 +1621,15 @@ function(add_unittest test_suite test_name)
   # The runtime benefits of LTO don't outweight the compile time costs for 
tests.
   if(LLVM_ENABLE_LTO)
 if((UNIX OR MINGW) AND LINKER_IS_LLD)
-  set_property(TARGET ${test_name} APPEND_STRING PROPERTY
-LINK_FLAGS " -Wl,--lto-O0")
+  if(LLVM_ENABLE_FATLTO)
+# When using FatLTO, just use relocatable linking.
+set_property(TARGET ${test_name} APPEND_STRING PROPERTY
+  LINK_FLAGS " -Wl,--no-fat-lto-objects")
+set_property(TARGET ${test_name} APPEND_STRING PROPERTY COMPILE_FLAGS 
" -fno-lto")
+  else()
+set_property(TARGET ${test_name} APPEND_STRING PROPERTY
+  LINK_FLAGS " -Wl,--lto-O0")
+  endif()
 elseif(LINKER_IS_LLD_LINK)
   set_property(TARGET ${test_name} APPEND_STRING PROPERTY
 LINK_FLAGS " /opt:lldlto=0")
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake 
b/llvm/cmake/modules/HandleLLVMOptions.cmake
index eca2962cf82071..38876a5d19ad9f 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -32,6 +32,8 @@ endif()
 set(LLVM_ENABLE_LTO OFF CACHE STRING "Build LLVM with LTO. May be specified as 
Thin or Full to use a particular kind of LTO")
 string(TOUPPER "${LLVM_ENABLE_LTO}" uppercase_LLVM_ENABLE_LTO)
 
+option(LLVM_ENABLE_FATLTO "Build LLVM with -ffat-lto-objects." OFF)
+
 # Ninja Job Pool support
 # The following only works with the Ninja generator in CMake >= 3.0.
 set(LLVM_PARALLEL_COMPILE_JOBS "" CACHE STRING
@@ -1258,6 +1260,10 @@ elseif(LLVM_ENABLE_LTO)
   endif()
 endif()
 
+if(LLVM_ENABLE_FATLTO AND (FUCHSIA OR UNIX))
+append("-ffat-lto-objects" CMAKE_EXE_LINKER_FLAGS 
CMAKE_SHARED_LINKER_FLAGS)
+endif()
+
 # Set an AIX default for LLVM_EXPORT_SYMBOLS_FOR_PLUGINS based on whether we 
are
 # doing dynamic linking (see below).
 set(LLVM_EXPORT_SYMBOLS_FOR_PLUGINS_AIX_default OFF)

>From 51b1d85ee4b0f476bece474784da504052271a5e Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Fri, 2 Feb 2024 13:09:18 -0800
Subject: [PATCH 2/3] Add -ffat-lto-objects to CMAKE_C_FLAGS and
 CMAKE_CXX_FLAGS

---
 llvm/cmake/modules/HandleLLVMOptions.cmake | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake 
b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 38876a5d19ad9f..10f466a3e5207d 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -1261,7 +1261,10 @@ elseif(LLVM_ENABLE_LTO)
 endif()
 
 if(LLVM_ENABLE_FATLTO AND (FUCHSIA OR UNIX))
+  append("-ffat-lto-objects" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+  if(NOT LINKER_IS_LLD_LINK)
 append("-ffat-lto-objects" CMAKE_EXE_LINKER_FLAGS 
CMAKE_SHARED_LINKER_FLAGS)
+  endif()
 endif()
 
 # Set an AIX default for LLVM_EXPORT_SYMBOLS_FOR_PLUGINS based on whether we 
are

>From d4d997a7775962abd39644e3fb957fa007baa518 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Tue, 5 Mar 2024 10:08:26 -0800
Subject: [PATCH 3/3] [cmake] Append -ffat-lto-objects to
 CMAKE_MODULE_LINKER_FLAGS

---
 llvm/cmake/modules/HandleLLVMOptions.cmake | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake 
b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 10f466a3e5207d..425a98315e2cc1 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -1263,7 +1263,7 @@ endif()
 if(LLVM_ENABLE_FATLTO AND (FUCHSIA OR UNIX))
   append("-ffat-lto-objects" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
   if(NOT LINKER_IS_LLD_LINK)
-append("-ffat-lto-objects" CMAKE_EXE_LI

[clang] [llvm] [CMAKE] Enable FatLTO as a build option for LLVM (PR #80480)

2024-03-05 Thread Paul Kirth via cfe-commits


@@ -1251,6 +1253,10 @@ elseif(LLVM_ENABLE_LTO)
   endif()
 endif()
 
+if(LLVM_ENABLE_FATLTO AND (FUCHSIA OR UNIX))
+append("-ffat-lto-objects" CMAKE_EXE_LINKER_FLAGS 
CMAKE_SHARED_LINKER_FLAGS)

ilovepi wrote:

done. Thanks for the suggestion.

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


[clang] [clang] Diagnose config_macros before building modules (PR #83641)

2024-03-05 Thread Michael Spencer via cfe-commits

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


[clang] ee044d5 - [clang] Diagnose config_macros before building modules (#83641)

2024-03-05 Thread via cfe-commits

Author: Michael Spencer
Date: 2024-03-05T10:15:21-08:00
New Revision: ee044d5e651787c5d73b37b2cbb7ca6444bb0502

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

LOG: [clang] Diagnose config_macros before building modules (#83641)

Before this patch, if a module fails to build because of a missing
config_macro, the user will never see the config macro warning. This
patch diagnoses this before building, and each subsequent time a module
is imported.

rdar://123921931

Added: 


Modified: 
clang/lib/Frontend/CompilerInstance.cpp
clang/test/Modules/Inputs/module.modulemap
clang/test/Modules/config_macros.m

Removed: 
clang/test/Modules/Inputs/config.h



diff  --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index 4443073775..ec4e68209d657d 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -1591,6 +1591,14 @@ static void checkConfigMacro(Preprocessor &PP, StringRef 
ConfigMacro,
   }
 }
 
+static void checkConfigMacros(Preprocessor &PP, Module *M,
+  SourceLocation ImportLoc) {
+  clang::Module *TopModule = M->getTopLevelModule();
+  for (const StringRef ConMacro : TopModule->ConfigMacros) {
+checkConfigMacro(PP, ConMacro, M, ImportLoc);
+  }
+}
+
 /// Write a new timestamp file with the given path.
 static void writeTimestampFile(StringRef TimestampFile) {
   std::error_code EC;
@@ -1829,6 +1837,13 @@ ModuleLoadResult 
CompilerInstance::findOrCompileModuleAndReadAST(
   Module *M =
   HS.lookupModule(ModuleName, ImportLoc, true, !IsInclusionDirective);
 
+  // Check for any configuration macros that have changed. This is done
+  // immediately before potentially building a module in case this module
+  // depends on having one of its configuration macros defined to successfully
+  // build. If this is not done the user will never see the warning.
+  if (M)
+checkConfigMacros(getPreprocessor(), M, ImportLoc);
+
   // Select the source and filename for loading the named module.
   std::string ModuleFilename;
   ModuleSource Source =
@@ -2006,12 +2021,23 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
   if (auto MaybeModule = MM.getCachedModuleLoad(*Path[0].first)) {
 // Use the cached result, which may be nullptr.
 Module = *MaybeModule;
+// Config macros are already checked before building a module, but they 
need
+// to be checked at each import location in case any of the config macros
+// have a new value at the current `ImportLoc`.
+if (Module)
+  checkConfigMacros(getPreprocessor(), Module, ImportLoc);
   } else if (ModuleName == getLangOpts().CurrentModule) {
 // This is the module we're building.
 Module = PP->getHeaderSearchInfo().lookupModule(
 ModuleName, ImportLoc, /*AllowSearch*/ true,
 /*AllowExtraModuleMapSearch*/ !IsInclusionDirective);
 
+// Config macros do not need to be checked here for two reasons.
+// * This will always be textual inclusion, and thus the config macros
+//   actually do impact the content of the header.
+// * `Preprocessor::HandleHeaderIncludeOrImport` will never call this
+//   function as the `#include` or `#import` is textual.
+
 MM.cacheModuleLoad(*Path[0].first, Module);
   } else {
 ModuleLoadResult Result = findOrCompileModuleAndReadAST(
@@ -2146,18 +2172,11 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
 TheASTReader->makeModuleVisible(Module, Visibility, ImportLoc);
   }
 
-  // Check for any configuration macros that have changed.
-  clang::Module *TopModule = Module->getTopLevelModule();
-  for (unsigned I = 0, N = TopModule->ConfigMacros.size(); I != N; ++I) {
-checkConfigMacro(getPreprocessor(), TopModule->ConfigMacros[I],
- Module, ImportLoc);
-  }
-
   // Resolve any remaining module using export_as for this one.
   getPreprocessor()
   .getHeaderSearchInfo()
   .getModuleMap()
-  .resolveLinkAsDependencies(TopModule);
+  .resolveLinkAsDependencies(Module->getTopLevelModule());
 
   LastModuleImportLoc = ImportLoc;
   LastModuleImportResult = ModuleLoadResult(Module);

diff  --git a/clang/test/Modules/Inputs/config.h 
b/clang/test/Modules/Inputs/config.h
deleted file mode 100644
index 4c124b0bf82b7c..00
--- a/clang/test/Modules/Inputs/config.h
+++ /dev/null
@@ -1,7 +0,0 @@
-#ifdef WANT_FOO
-int* foo(void);
-#endif
-
-#ifdef WANT_BAR
-char *bar(void);
-#endif

diff  --git a/clang/test/Modules/Inputs/module.modulemap 
b/clang/test/Modules/Inputs/module.modulemap
index e7cb4b27bc08b9..47f6c5c1010d7d 100644
--- a/clang/test/Modules/Inputs/module.modulemap
+++ b/clang/test/Modules/Inputs/module.modulemap
@@ -260,11 +260,6 @@ module cxx_d

[clang] [Clang][Sema] Diagnose class member access expressions naming non-existent members of the current instantiation prior to instantiation in the absence of dependent base classes (PR #84050)

2024-03-05 Thread Krystian Stasiowski via cfe-commits

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


[clang] [clang-tools-extra] [lld] [lldb] [llvm] [mlir] Rename llvm::ThreadPool -> llvm::DefaultThreadPool (NFC) (PR #83702)

2024-03-05 Thread Mehdi Amini via cfe-commits

joker-eph wrote:

Actually no: the first patch landed already, so `ThreadPoolInterface` is now 
the base class in the codebase. I have some mixup here in that when renaming 
ThreadPool -> DefaultThreadPool, I used the base class ThreadPoolInterface when 
updating some of the uses.

I will push these ahead as a NFC change and rebase, that'll reduce the diff 
here.

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


[clang] [Doc][HLSL] Add documentation for root signature. (PR #83933)

2024-03-05 Thread Chris B via cfe-commits


@@ -0,0 +1,312 @@
+
+HLSL Root Signatures
+
+
+.. contents::
+   :local:
+
+Usage
+=
+
+In HLSL, the `root signature
+`_ 
+defines what types of resources are bound to the graphics pipeline. 
+
+A root signature can be specified in HLSL as a `string
+`_.
 
+The string contains a collection of comma-separated clauses that describe root 
+signature constituent components. 
+
+There are two mechanisms to compile an HLSL root signature. First, it is 
+possible to attach a root signature string to a particular shader via the 
+RootSignature attribute (in the following example, using the MyRS1 entry 
+point):
+
+.. code-block:: c++
+
+#define RS "RootFlags( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT | " \ 
+  "DENY_VERTEX_SHADER_ROOT_ACCESS), " \ 
+  "CBV(b0, space = 1, flags = DATA_STATIC), " \ 
+  "SRV(t0), " \ 
+  "UAV(u0), " \ 
+  "DescriptorTable( CBV(b1), " \ 
+  " SRV(t1, numDescriptors = 8, " \ 
+  " flags = DESCRIPTORS_VOLATILE), " \ 
+  " UAV(u1, numDescriptors = unbounded, " \ 
+  " flags = DESCRIPTORS_VOLATILE)), " \ 
+  "DescriptorTable(Sampler(s0, space=1, numDescriptors = 4)), " \ 
+  "RootConstants(num32BitConstants=3, b10), " \ 
+  "StaticSampler(s1)," \ 
+  "StaticSampler(s2, " \ 
+  "  addressU = TEXTURE_ADDRESS_CLAMP, " \ 
+  "  filter = FILTER_MIN_MAG_MIP_LINEAR )"
+
+[RootSignature(RS)]
+float4 main(float4 coord : COORD) : SV_Target
+{
+…
+}
+
+The compiler will create and verify the root signature blob for the shader and 
+embed it alongside the shader byte code into the shader blob. 
+
+The other mechanism is to create a standalone root signature blob, perhaps to 
+reuse it with a large set of shaders, saving space. The name of the define 
+string is specified via the usual -E argument. For example:
+
+.. code-block:: c++
+
+  dxc.exe -T rootsig_1_1 MyRS1.hlsl -E MyRS1 -Fo MyRS1.fxo
+
+Note that the root signature string define can also be passed on the command 
+line, e.g, -D MyRS1=”…”.
+
+Root Signature Grammar
+==
+
+.. code-block:: c++
+
+RootSignature : (RootElement(,RootElement)?)?
+
+RootElement : RootFlags | RootConstants | RootCBV | RootSRV | RootUAV |
+  DescriptorTable | StaticSampler
+
+RootFlags : 'RootFlags' '(' (RootFlag(|RootFlag)?)? ')'
+
+RootFlag : 'ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT' | 
+   'DENY_VERTEX_SHADER_ROOT_ACCESS'
+
+RootConstants : 'RootConstants' '(' 'num32BitConstants' '=' NUMBER ',' 
+   bReg (',' 'space' '=' NUMBER)? 
+   (',' 'visibility' '=' SHADER_VISIBILITY)? ')'
+
+RootCBV : 'CBV' '(' bReg (',' 'space' '=' NUMBER)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+RootSRV : 'SRV' '(' tReg (',' 'space' '=' NUMBER)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+RootUAV : 'UAV' '(' uReg (',' 'space' '=' NUMBER)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+DescriptorTable : 'DescriptorTable' '(' (DTClause(|DTClause)?)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? ')'
+
+DTClause : CBV | SRV | UAV | Sampler
+
+CBV : 'CBV' '(' bReg (',' 'numDescriptors' '=' NUMBER)? 
+  (',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+SRV : 'SRV' '(' tReg (',' 'numDescriptors' '=' NUMBER)? 
+(',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+UAV : 'UAV' '(' uReg (',' 'numDescriptors' '=' NUMBER)? 
+  (',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+Sampler : 'Sampler' '(' sReg (',' 'numDescriptors' '=' NUMBER)? 
+  (',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? (',' 'flags' '=' 
NUMBER)? ')'
+
+
+SHADER_VISIBILITY : 'SHADER_VISIBILITY_ALL' | 'SHADER_VISIBILITY_VERTEX' | 
+'SHADER_VISIBILITY_HULL' | 
+'SHADER_VISIBILITY_DOMAIN' | 
+'SHADER_VISIBILITY_GEOMETRY' | 
+'SHADER_VISIBILITY_PIXEL' | 
+'SHADER_VISIBILITY_AMPLIFICATION' | 
+'SHADER_VISIBILITY_MESH'
+
+DATA_FLAGS : 'DATA_STATIC_WH

[clang] [Doc][HLSL] Add documentation for root signature. (PR #83933)

2024-03-05 Thread Xiang Li via cfe-commits


@@ -0,0 +1,312 @@
+
+HLSL Root Signatures
+
+
+.. contents::
+   :local:
+
+Usage
+=
+
+In HLSL, the `root signature
+`_ 
+defines what types of resources are bound to the graphics pipeline. 
+
+A root signature can be specified in HLSL as a `string
+`_.
 
+The string contains a collection of comma-separated clauses that describe root 
+signature constituent components. 
+
+There are two mechanisms to compile an HLSL root signature. First, it is 
+possible to attach a root signature string to a particular shader via the 
+RootSignature attribute (in the following example, using the MyRS1 entry 
+point):
+
+.. code-block:: c++
+
+#define RS "RootFlags( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT | " \ 
+  "DENY_VERTEX_SHADER_ROOT_ACCESS), " \ 
+  "CBV(b0, space = 1, flags = DATA_STATIC), " \ 
+  "SRV(t0), " \ 
+  "UAV(u0), " \ 
+  "DescriptorTable( CBV(b1), " \ 
+  " SRV(t1, numDescriptors = 8, " \ 
+  " flags = DESCRIPTORS_VOLATILE), " \ 
+  " UAV(u1, numDescriptors = unbounded, " \ 
+  " flags = DESCRIPTORS_VOLATILE)), " \ 
+  "DescriptorTable(Sampler(s0, space=1, numDescriptors = 4)), " \ 
+  "RootConstants(num32BitConstants=3, b10), " \ 
+  "StaticSampler(s1)," \ 
+  "StaticSampler(s2, " \ 
+  "  addressU = TEXTURE_ADDRESS_CLAMP, " \ 
+  "  filter = FILTER_MIN_MAG_MIP_LINEAR )"
+
+[RootSignature(RS)]
+float4 main(float4 coord : COORD) : SV_Target
+{
+…
+}
+
+The compiler will create and verify the root signature blob for the shader and 
+embed it alongside the shader byte code into the shader blob. 
+
+The other mechanism is to create a standalone root signature blob, perhaps to 
+reuse it with a large set of shaders, saving space. The name of the define 
+string is specified via the usual -E argument. For example:
+
+.. code-block:: c++
+
+  dxc.exe -T rootsig_1_1 MyRS1.hlsl -E MyRS1 -Fo MyRS1.fxo
+
+Note that the root signature string define can also be passed on the command 
+line, e.g, -D MyRS1=”…”.
+
+Root Signature Grammar
+==
+
+.. code-block:: c++
+
+RootSignature : (RootElement(,RootElement)?)?
+
+RootElement : RootFlags | RootConstants | RootCBV | RootSRV | RootUAV |
+  DescriptorTable | StaticSampler
+
+RootFlags : 'RootFlags' '(' (RootFlag(|RootFlag)?)? ')'
+
+RootFlag : 'ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT' | 
+   'DENY_VERTEX_SHADER_ROOT_ACCESS'
+
+RootConstants : 'RootConstants' '(' 'num32BitConstants' '=' NUMBER ',' 
+   bReg (',' 'space' '=' NUMBER)? 
+   (',' 'visibility' '=' SHADER_VISIBILITY)? ')'
+
+RootCBV : 'CBV' '(' bReg (',' 'space' '=' NUMBER)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+RootSRV : 'SRV' '(' tReg (',' 'space' '=' NUMBER)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+RootUAV : 'UAV' '(' uReg (',' 'space' '=' NUMBER)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+DescriptorTable : 'DescriptorTable' '(' (DTClause(|DTClause)?)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? ')'
+
+DTClause : CBV | SRV | UAV | Sampler
+
+CBV : 'CBV' '(' bReg (',' 'numDescriptors' '=' NUMBER)? 
+  (',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+SRV : 'SRV' '(' tReg (',' 'numDescriptors' '=' NUMBER)? 
+(',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+UAV : 'UAV' '(' uReg (',' 'numDescriptors' '=' NUMBER)? 
+  (',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+Sampler : 'Sampler' '(' sReg (',' 'numDescriptors' '=' NUMBER)? 
+  (',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? (',' 'flags' '=' 
NUMBER)? ')'
+
+
+SHADER_VISIBILITY : 'SHADER_VISIBILITY_ALL' | 'SHADER_VISIBILITY_VERTEX' | 
+'SHADER_VISIBILITY_HULL' | 
+'SHADER_VISIBILITY_DOMAIN' | 
+'SHADER_VISIBILITY_GEOMETRY' | 
+'SHADER_VISIBILITY_PIXEL' | 
+'SHADER_VISIBILITY_AMPLIFICATION' | 
+'SHADER_VISIBILITY_MESH'
+
+DATA_FLAGS : 'DATA_STATIC_WH

[clang] [Clang][Driver] Merge the different strategies of how libc++ is included (PR #83721)

2024-03-05 Thread Fangrui Song via cfe-commits


@@ -705,6 +705,47 @@ class ToolChain {
   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const;
 
+  struct IncludeStrategy {
+enum AvailabilityOptions {
+  // Check whether the directory is exists before adding it to the
+  // include path. This is the case if AssumeAvailable isn't set.
+  CheckIfAvailable,
+
+  // Don't check whether the directory exists. Just assume it does and add
+  // the include.
+  AssumeAvailable,
+
+  // Use v that is inside `/c++`. If not set, 
always
+  // uses v1.
+  UseMaxVersionAvailable,
+};
+
+IncludeStrategy(AvailabilityOptions Availability,
+bool AddTargetDirIfAvailable = false,
+bool PrintDebugStatements = false)
+: Availability(Availability),
+  AddTargetDirIfAvailable(AddTargetDirIfAvailable),
+  PrintDebugStatements(PrintDebugStatements) {}
+
+LLVM_PREFERRED_TYPE(AvailabilityOptions)
+unsigned Availability : 2;
+
+// Check whether the directory `//c++/v`
+// exists, and add it to the include path if it does.
+LLVM_PREFERRED_TYPE(bool)
+unsigned AddTargetDirIfAvailable : 1;
+
+// Whether to print a message if a checked directory isn't available.
+LLVM_PREFERRED_TYPE(bool)
+unsigned PrintDebugStatements : 1;
+  };
+
+  /// Helper function to implement AddClangCXXStdlibIncludeArgs for libc++.
+  bool AddLibcxxInclude(const llvm::opt::ArgList &DriverArgs,

MaskRay wrote:

The case of the first function name character is unfortunately inconsistent, 
but the convention is that newer function names look like `functionName`, e.g. 
addLibStdCxxIncludePaths, addGCCLibStdCxxIncludePaths

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


[clang] [clang] Implement __builtin_{clzg,ctzg} (PR #83431)

2024-03-05 Thread via cfe-commits

overmighty wrote:

cc @nickdesaulniers 

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


[clang] [clang] Fix __builtin_popcountg not matching GCC (PR #83313)

2024-03-05 Thread via cfe-commits

overmighty wrote:

cc @nickdesaulniers 

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


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-05 Thread Richard Smith via cfe-commits

zygoloid wrote:

> +1 for this, it will be the 95%/5% rule, you might think all cases of 
> (identifier) is a cast, but I'm pretty sure it won't be

Specifically, what I suggested was: when disambiguating whether 
`(identifier)&...` or `(identifier)*...` is a cast vs a multiplication or 
bitwise and (that is, the case that the previous patch changed, resulting in 
the regression we're trying to fix), treat it as a cast unless `identifier` is 
a macro parameter name. I think that will be right >99% of the time. And even 
when clang-format gets it wrong, the programmer can fix that by removing the 
redundant and non-idiomatic parentheses around the identifier.

> I'm with @owenca on this, this patch will move us closer, meaning users don't 
> need to add common types to TypeNames

As I said before, I think special-casing these typedefs is a good thing - it's 
reasonable for clang-format to assume they're type names. But I don't think 
this moves us much closer to fixing the bug, because most casts won't be to one 
of these typedefs.

I do wonder, though -- there's a lot of churn in this patch adding and wiring 
through a new parameter. Can the `TypeNames` mechanism be prepopulated with 
this list of types instead?

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


[clang] [clang-cl] Fix value of __FUNCTION__ in MSVC mode. (PR #84014)

2024-03-05 Thread Zahira Ammarguellat via cfe-commits


@@ -463,8 +463,72 @@ void ctor_tests() {
 constexpr SL global_sl = SL::current();
 static_assert(is_equal(global_sl.function(), ""));
 
+template 
+class TestBI {
+public:
+   TestBI() {
+#ifdef MS
+ static_assert(is_equal(__FUNCTION__, "test_func::TestBI::TestBI"));
+ static_assert(is_equal(__func__, "TestBI"));
+#else
+ static_assert(is_equal(__FUNCTION__, "TestBI"));
+ static_assert(is_equal(__func__, "TestBI"));
+#endif
+   }
+};
+
+template 
+class TestClass {
+public:
+   TestClass() {
+#ifdef MS
+  static_assert(is_equal(__FUNCTION__, "test_func::TestClass::TestClass"));

zahiraam wrote:

Yes CL output is: `TestClass::TestClass`

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


[clang] [llvm] Implement a subset of builtin_cpu_supports() features (PR #82809)

2024-03-05 Thread zhijian lin via cfe-commits

https://github.com/diggerlin updated 
https://github.com/llvm/llvm-project/pull/82809

>From 557e7163d744890aadfa703a81a0c4f2cd112517 Mon Sep 17 00:00:00 2001
From: zhijian 
Date: Fri, 23 Feb 2024 13:23:18 -0500
Subject: [PATCH] Implement a subset of builtin_cpu_supports() features

---
 clang/lib/Basic/Targets/PPC.cpp   |  15 +-
 clang/lib/Basic/Targets/PPC.h |   9 +-
 clang/lib/CodeGen/CGBuiltin.cpp   | 104 +++---
 clang/lib/Sema/SemaChecking.cpp   |   6 +-
 clang/test/CodeGen/aix-builtin-cpu-is.c   |   4 +-
 clang/test/CodeGen/aix-builtin-cpu-supports.c | 135 ++
 clang/test/Sema/aix-builtin-cpu-unsupports.c  |  40 +-
 .../test/Sema/builtin-cpu-unsupports-AIX-Os.c |   9 ++
 .../llvm/TargetParser/PPCTargetParser.def |  73 +-
 9 files changed, 356 insertions(+), 39 deletions(-)
 create mode 100644 clang/test/CodeGen/aix-builtin-cpu-supports.c
 create mode 100644 clang/test/Sema/builtin-cpu-unsupports-AIX-Os.c

diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index aebe51bfa4daad..1d488dff825ede 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -897,6 +897,19 @@ ArrayRef PPCTargetInfo::getTargetBuiltins() 
const {
 }
 
 bool PPCTargetInfo::validateCpuSupports(StringRef FeatureStr) const {
+  llvm::Triple Triple = getTriple();
+  if (Triple.isOSAIX()) {
+#define PPC_AIX_FEATURE(NAME, DESC, SUPPORT_METHOD, INDEX, MASK, COMP_OP,  
\
+VALUE) 
\
+  .Case(NAME, true)
+return llvm::StringSwitch(FeatureStr)
+#include "llvm/TargetParser/PPCTargetParser.def"
+.Default(false);
+  }
+
+  assert(Triple.isOSLinux() &&
+ "__builtin_cpu_supports() is only supported for AIX and Linux.");
+
 #define PPC_LNX_FEATURE(NAME, DESC, ENUMNAME, ENUMVAL, HWCAPN) .Case(NAME, 
true)
   return llvm::StringSwitch(FeatureStr)
 #include "llvm/TargetParser/PPCTargetParser.def"
@@ -906,7 +919,7 @@ bool PPCTargetInfo::validateCpuSupports(StringRef 
FeatureStr) const {
 bool PPCTargetInfo::validateCpuIs(StringRef CPUName) const {
   llvm::Triple Triple = getTriple();
   if (Triple.isOSAIX()) {
-#define PPC_AIX_CPU(NAME, SUPPORT, INDEX, OP, VALUE) .Case(NAME, true)
+#define PPC_AIX_CPU(NAME, SUPPORT_METHOD, INDEX, OP, VALUE) .Case(NAME, true)
 return llvm::StringSwitch(CPUName)
 #include "llvm/TargetParser/PPCTargetParser.def"
 .Default(false);
diff --git a/clang/lib/Basic/Targets/PPC.h b/clang/lib/Basic/Targets/PPC.h
index 70683916a8b04f..39b52d362f36b8 100644
--- a/clang/lib/Basic/Targets/PPC.h
+++ b/clang/lib/Basic/Targets/PPC.h
@@ -364,7 +364,14 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public 
TargetInfo {
   // have Glibc since it is Glibc that provides the HWCAP[2] in the auxv.
   static constexpr int MINIMUM_AIX_OS_MAJOR = 7;
   static constexpr int MINIMUM_AIX_OS_MINOR = 2;
-  bool supportsCpuSupports() const override { return getTriple().isOSGlibc(); }
+  bool supportsCpuSupports() const override {
+llvm::Triple Triple = getTriple();
+// AIX 7.2 is the minimum requirement to support __builtin_cpu_supports().
+return Triple.isOSGlibc() ||
+   (Triple.isOSAIX() &&
+!Triple.isOSVersionLT(MINIMUM_AIX_OS_MAJOR, MINIMUM_AIX_OS_MINOR));
+  }
+
   bool supportsCpuIs() const override {
 llvm::Triple Triple = getTriple();
 // AIX 7.2 is the minimum requirement to support __builtin_cpu_is().
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 9ee51ca7142c77..1565e4103d9ef8 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -16570,7 +16570,7 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned 
BuiltinID,
 
 #include "llvm/TargetParser/PPCTargetParser.def"
   auto GenAIXPPCBuiltinCpuExpr = [&](unsigned SupportMethod, unsigned FieldIdx,
- unsigned CompOp,
+ unsigned Mask, unsigned CompOp,
  unsigned OpValue) -> Value * {
 if (SupportMethod == AIX_BUILTIN_PPC_FALSE)
   return llvm::ConstantInt::getFalse(ConvertType(E->getType()));
@@ -16578,24 +16578,64 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned 
BuiltinID,
 if (SupportMethod == AIX_BUILTIN_PPC_TRUE)
   return llvm::ConstantInt::getTrue(ConvertType(E->getType()));
 
-assert(SupportMethod <= USE_SYS_CONF && "Invalid value for 
SupportMethod.");
-assert((CompOp == COMP_EQ) && "Only equal comparisons are supported.");
+assert(SupportMethod <= SYS_CALL && "Invalid value for SupportMethod.");
+
+llvm::Value *FieldValue = nullptr;
+if (SupportMethod == USE_SYS_CONF) {
+  llvm::Type *STy = llvm::StructType::get(PPC_SYSTEMCONFIG_TYPE);
+  llvm::Constant *SysConf =
+  CGM.CreateRuntimeVariable(STy, "_system_configuration");
+
+  // Grab the appropriate f

[clang] Add new flag -Wreturn-mismatch (PR #82872)

2024-03-05 Thread Bhuminjay Soni via cfe-commits

https://github.com/11happy updated 
https://github.com/llvm/llvm-project/pull/82872

>From 557ee75d60f0fdb4dd2b353c819b4f22f71b46d7 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Sat, 24 Feb 2024 13:50:30 +0530
Subject: [PATCH 1/3] add new flag -Wreturn-mismatch

Signed-off-by: 11happy 
---
 clang/include/clang/Basic/DiagnosticGroups.td| 1 +
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 6 +++---
 clang/test/Analysis/null-deref-ps.c  | 4 ++--
 clang/test/CodeGen/statements.c  | 2 +-
 clang/test/CodeGen/volatile-1.c  | 2 +-
 clang/test/Sema/return-silent.c  | 2 +-
 clang/test/Sema/return.c | 2 +-
 7 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6765721ae7002c..7a786a24083583 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -607,6 +607,7 @@ def RedundantMove : DiagGroup<"redundant-move">;
 def Register : DiagGroup<"register", [DeprecatedRegister]>;
 def ReturnTypeCLinkage : DiagGroup<"return-type-c-linkage">;
 def ReturnType : DiagGroup<"return-type", [ReturnTypeCLinkage]>;
+def ReturnMismatch : DiagGroup<"return-mismatch">;
 def BindToTemporaryCopy : DiagGroup<"bind-to-temporary-copy",
 [CXX98CompatBindToTemporaryCopy]>;
 def SelfAssignmentField : DiagGroup<"self-assign-field">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 24d32cb87c89e2..7057b4b2123671 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10212,14 +10212,14 @@ def warn_second_parameter_to_va_arg_never_compatible 
: Warning<
 
 def warn_return_missing_expr : Warning<
   "non-void %select{function|method}1 %0 should return a value">, DefaultError,
-  InGroup;
+  InGroup;
 def ext_return_missing_expr : ExtWarn<
   "non-void %select{function|method}1 %0 should return a value">, DefaultError,
-  InGroup;
+  InGroup;
 def ext_return_has_expr : ExtWarn<
   "%select{void function|void method|constructor|destructor}1 %0 "
   "should not return a value">,
-  DefaultError, InGroup;
+  DefaultError, InGroup;
 def ext_return_has_void_expr : Extension<
   "void %select{function|method|block}1 %0 should not return void expression">;
 def err_return_init_list : Error<
diff --git a/clang/test/Analysis/null-deref-ps.c 
b/clang/test/Analysis/null-deref-ps.c
index d80de15c05a3fe..2682ad02ee37f9 100644
--- a/clang/test/Analysis/null-deref-ps.c
+++ b/clang/test/Analysis/null-deref-ps.c
@@ -1,5 +1,5 @@
-// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 -Wno-int-conversion 
-Wno-strict-prototypes -Wno-tautological-constant-compare 
-Wtautological-unsigned-zero-compare -analyzer-checker=core,deadcode,alpha.core 
-std=gnu99 -analyzer-purge=none -verify %s -Wno-error=return-type
-// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 -Wno-int-conversion 
-Wno-strict-prototypes -Wno-tautological-constant-compare 
-Wtautological-unsigned-zero-compare -analyzer-checker=core,deadcode,alpha.core 
-std=gnu99 -verify %s -Wno-error=return-type
+// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 -Wno-int-conversion 
-Wno-strict-prototypes -Wno-tautological-constant-compare 
-Wtautological-unsigned-zero-compare -analyzer-checker=core,deadcode,alpha.core 
-std=gnu99 -analyzer-purge=none -verify %s -Wno-error=return-type 
-Wno-error=return-mismatch
+// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 -Wno-int-conversion 
-Wno-strict-prototypes -Wno-tautological-constant-compare 
-Wtautological-unsigned-zero-compare -analyzer-checker=core,deadcode,alpha.core 
-std=gnu99 -verify %s -Wno-error=return-type -Wno-error=return-mismatch
 
 typedef unsigned uintptr_t;
 
diff --git a/clang/test/CodeGen/statements.c b/clang/test/CodeGen/statements.c
index 07ae075d6d807e..76f4f254dfd1dc 100644
--- a/clang/test/CodeGen/statements.c
+++ b/clang/test/CodeGen/statements.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -Wno-error=return-type -Wno-error=int-conversion %s 
-emit-llvm-only
+// RUN: %clang_cc1 -Wno-error=return-type -Wno-error=return-mismatch 
-Wno-error=int-conversion %s -emit-llvm-only
 // REQUIRES: LP64
 
 // Mismatched type between return and function result.
diff --git a/clang/test/CodeGen/volatile-1.c b/clang/test/CodeGen/volatile-1.c
index cd919c78989fe2..80c40d21cf593e 100644
--- a/clang/test/CodeGen/volatile-1.c
+++ b/clang/test/CodeGen/volatile-1.c
@@ -1,5 +1,5 @@
 // XFAIL: target=aarch64-pc-windows-msvc
-// RUN: %clang_cc1 -Wno-return-type -Wno-unused-value -emit-llvm %s -w -o - | 
FileCheck %s
+// RUN: %clang_cc1 -Wno-return-type -Wno-return-mismatch -Wno-unused-value 
-emit-llvm %s -w -o - | FileCheck %s
 
 // CHECK: @i = {{(dso_local )?}}global [[INT:i[0-9]+]] 0
 volatile int i, j, k;
diff --git a/clang/test/Sema/return-s

[clang] Add new flag -Wreturn-mismatch (PR #82872)

2024-03-05 Thread Bhuminjay Soni via cfe-commits


@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -Wno-return-type -Wreturn-mismatch -fsyntax-only -verify %s
+
+// Test that -Wreturn-mismatch is enabled and -Wreturn-type is disabled.
+
+int foo(void) __attribute__((noreturn));
+int bar(void);
+
+void test1() {
+  return 1; // expected-warning{{void function 'test1' should not return a 
value}}
+}
+
+int test2() { 
+return; // expected-warning{{non-void function 'test2' should return a 
value}}
+} 
+
+int test3() { 
+// no-warning
+} 
+
+int test4() {
+(void)(bar() || foo()); // no-warning
+} 
+
+void test5() {
+} // no-warning
+
+int test6() {
+  return 0; // no-warning
+}

11happy wrote:

done

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


[clang] Add new flag -Wreturn-mismatch (PR #82872)

2024-03-05 Thread Bhuminjay Soni via cfe-commits


@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -Wreturn-type -Wno-return-mismatch -fsyntax-only -verify %s

11happy wrote:

done

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


[clang] Add new flag -Wreturn-mismatch (PR #82872)

2024-03-05 Thread Bhuminjay Soni via cfe-commits


@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -Wno-return-type -Wreturn-mismatch -fsyntax-only -verify %s

11happy wrote:

done

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


[clang] Add new flag -Wreturn-mismatch (PR #82872)

2024-03-05 Thread Bhuminjay Soni via cfe-commits


@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -Wno-return-type -Wreturn-mismatch -fsyntax-only -verify %s
+
+// Test that -Wreturn-mismatch is enabled and -Wreturn-type is disabled.
+
+int foo(void) __attribute__((noreturn));
+int bar(void);
+
+void test1() {
+  return 1; // expected-warning{{void function 'test1' should not return a 
value}}

11happy wrote:

done

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


[clang] Add new flag -Wreturn-mismatch (PR #82872)

2024-03-05 Thread Bhuminjay Soni via cfe-commits


@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -Wno-return-type -Wreturn-mismatch -fsyntax-only -verify %s
+
+// Test that -Wreturn-mismatch is enabled and -Wreturn-type is disabled.
+
+int foo(void) __attribute__((noreturn));
+int bar(void);
+
+void test1() {
+  return 1; // expected-warning{{void function 'test1' should not return a 
value}}
+}
+
+int test2() { 
+return; // expected-warning{{non-void function 'test2' should return a 
value}}

11happy wrote:

done

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


[clang] Add new flag -Wreturn-mismatch (PR #82872)

2024-03-05 Thread Bhuminjay Soni via cfe-commits


@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -Wno-return-type -Wreturn-mismatch -fsyntax-only -verify %s
+
+// Test that -Wreturn-mismatch is enabled and -Wreturn-type is disabled.
+
+int foo(void) __attribute__((noreturn));
+int bar(void);
+
+void test1() {
+  return 1; // expected-warning{{void function 'test1' should not return a 
value}}
+}
+
+int test2() { 
+return; // expected-warning{{non-void function 'test2' should return a 
value}}
+} 
+
+int test3() { 
+// no-warning

11happy wrote:

done

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


[clang] [llvm] Implement a subset of builtin_cpu_supports() features (PR #82809)

2024-03-05 Thread zhijian lin via cfe-commits

https://github.com/diggerlin updated 
https://github.com/llvm/llvm-project/pull/82809

>From 557e7163d744890aadfa703a81a0c4f2cd112517 Mon Sep 17 00:00:00 2001
From: zhijian 
Date: Fri, 23 Feb 2024 13:23:18 -0500
Subject: [PATCH 1/2] Implement a subset of builtin_cpu_supports() features

---
 clang/lib/Basic/Targets/PPC.cpp   |  15 +-
 clang/lib/Basic/Targets/PPC.h |   9 +-
 clang/lib/CodeGen/CGBuiltin.cpp   | 104 +++---
 clang/lib/Sema/SemaChecking.cpp   |   6 +-
 clang/test/CodeGen/aix-builtin-cpu-is.c   |   4 +-
 clang/test/CodeGen/aix-builtin-cpu-supports.c | 135 ++
 clang/test/Sema/aix-builtin-cpu-unsupports.c  |  40 +-
 .../test/Sema/builtin-cpu-unsupports-AIX-Os.c |   9 ++
 .../llvm/TargetParser/PPCTargetParser.def |  73 +-
 9 files changed, 356 insertions(+), 39 deletions(-)
 create mode 100644 clang/test/CodeGen/aix-builtin-cpu-supports.c
 create mode 100644 clang/test/Sema/builtin-cpu-unsupports-AIX-Os.c

diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index aebe51bfa4daad..1d488dff825ede 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -897,6 +897,19 @@ ArrayRef PPCTargetInfo::getTargetBuiltins() 
const {
 }
 
 bool PPCTargetInfo::validateCpuSupports(StringRef FeatureStr) const {
+  llvm::Triple Triple = getTriple();
+  if (Triple.isOSAIX()) {
+#define PPC_AIX_FEATURE(NAME, DESC, SUPPORT_METHOD, INDEX, MASK, COMP_OP,  
\
+VALUE) 
\
+  .Case(NAME, true)
+return llvm::StringSwitch(FeatureStr)
+#include "llvm/TargetParser/PPCTargetParser.def"
+.Default(false);
+  }
+
+  assert(Triple.isOSLinux() &&
+ "__builtin_cpu_supports() is only supported for AIX and Linux.");
+
 #define PPC_LNX_FEATURE(NAME, DESC, ENUMNAME, ENUMVAL, HWCAPN) .Case(NAME, 
true)
   return llvm::StringSwitch(FeatureStr)
 #include "llvm/TargetParser/PPCTargetParser.def"
@@ -906,7 +919,7 @@ bool PPCTargetInfo::validateCpuSupports(StringRef 
FeatureStr) const {
 bool PPCTargetInfo::validateCpuIs(StringRef CPUName) const {
   llvm::Triple Triple = getTriple();
   if (Triple.isOSAIX()) {
-#define PPC_AIX_CPU(NAME, SUPPORT, INDEX, OP, VALUE) .Case(NAME, true)
+#define PPC_AIX_CPU(NAME, SUPPORT_METHOD, INDEX, OP, VALUE) .Case(NAME, true)
 return llvm::StringSwitch(CPUName)
 #include "llvm/TargetParser/PPCTargetParser.def"
 .Default(false);
diff --git a/clang/lib/Basic/Targets/PPC.h b/clang/lib/Basic/Targets/PPC.h
index 70683916a8b04f..39b52d362f36b8 100644
--- a/clang/lib/Basic/Targets/PPC.h
+++ b/clang/lib/Basic/Targets/PPC.h
@@ -364,7 +364,14 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public 
TargetInfo {
   // have Glibc since it is Glibc that provides the HWCAP[2] in the auxv.
   static constexpr int MINIMUM_AIX_OS_MAJOR = 7;
   static constexpr int MINIMUM_AIX_OS_MINOR = 2;
-  bool supportsCpuSupports() const override { return getTriple().isOSGlibc(); }
+  bool supportsCpuSupports() const override {
+llvm::Triple Triple = getTriple();
+// AIX 7.2 is the minimum requirement to support __builtin_cpu_supports().
+return Triple.isOSGlibc() ||
+   (Triple.isOSAIX() &&
+!Triple.isOSVersionLT(MINIMUM_AIX_OS_MAJOR, MINIMUM_AIX_OS_MINOR));
+  }
+
   bool supportsCpuIs() const override {
 llvm::Triple Triple = getTriple();
 // AIX 7.2 is the minimum requirement to support __builtin_cpu_is().
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 9ee51ca7142c77..1565e4103d9ef8 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -16570,7 +16570,7 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned 
BuiltinID,
 
 #include "llvm/TargetParser/PPCTargetParser.def"
   auto GenAIXPPCBuiltinCpuExpr = [&](unsigned SupportMethod, unsigned FieldIdx,
- unsigned CompOp,
+ unsigned Mask, unsigned CompOp,
  unsigned OpValue) -> Value * {
 if (SupportMethod == AIX_BUILTIN_PPC_FALSE)
   return llvm::ConstantInt::getFalse(ConvertType(E->getType()));
@@ -16578,24 +16578,64 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned 
BuiltinID,
 if (SupportMethod == AIX_BUILTIN_PPC_TRUE)
   return llvm::ConstantInt::getTrue(ConvertType(E->getType()));
 
-assert(SupportMethod <= USE_SYS_CONF && "Invalid value for 
SupportMethod.");
-assert((CompOp == COMP_EQ) && "Only equal comparisons are supported.");
+assert(SupportMethod <= SYS_CALL && "Invalid value for SupportMethod.");
+
+llvm::Value *FieldValue = nullptr;
+if (SupportMethod == USE_SYS_CONF) {
+  llvm::Type *STy = llvm::StructType::get(PPC_SYSTEMCONFIG_TYPE);
+  llvm::Constant *SysConf =
+  CGM.CreateRuntimeVariable(STy, "_system_configuration");
+
+  // Grab the appropria

[clang] Add new flag -Wreturn-mismatch (PR #82872)

2024-03-05 Thread Bhuminjay Soni via cfe-commits


@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -Wno-return-type -Wreturn-mismatch -fsyntax-only -verify %s
+
+// Test that -Wreturn-mismatch is enabled and -Wreturn-type is disabled.
+
+int foo(void) __attribute__((noreturn));
+int bar(void);
+
+void test1() {

11happy wrote:

done

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


[clang] Add new flag -Wreturn-mismatch (PR #82872)

2024-03-05 Thread Bhuminjay Soni via cfe-commits


@@ -94,6 +94,7 @@ Deprecated Compiler Flags
 
 Modified Compiler Flags
 ---
+- The `-Wreturn-type` flag has been modified to split some of its 
functionality into `-Wreturn-mismatch` flag.

11happy wrote:

done

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


[clang] [llvm] [AMDGPU] Adding the amdgpu-num-work-groups function attribute (PR #79035)

2024-03-05 Thread Jun Wang via cfe-commits


@@ -194,3 +204,105 @@ __global__ void non_cexpr_waves_per_eu_2() {}
 // expected-error@+1{{'amdgpu_waves_per_eu' attribute requires parameter 1 to 
be an integer constant}}
 __attribute__((amdgpu_waves_per_eu(2, ipow2(2
 __global__ void non_cexpr_waves_per_eu_2_4() {}
+
+// expected-error@+1{{'amdgpu_max_num_work_groups' attribute requires exactly 
3 arguments}}
+__attribute__((amdgpu_max_num_work_groups(32)))
+__global__ void max_num_work_groups_32() {}
+
+// expected-error@+1{{'amdgpu_max_num_work_groups' attribute requires exactly 
3 arguments}}
+__attribute__((amdgpu_max_num_work_groups(32, 1)))
+__global__ void max_num_work_groups_32_1() {}
+
+// expected-error@+1{{'amdgpu_max_num_work_groups' attribute requires exactly 
3 arguments}}
+__attribute__((amdgpu_max_num_work_groups(32, 1, 1, 1)))
+__global__ void max_num_work_groups_32_1_1_1() {}
+
+// expected-error@+1{{'amdgpu_max_num_work_groups' attribute requires 
parameter 0 to be an integer constant}}
+__attribute__((amdgpu_max_num_work_groups(ipow2(5), 1, 1)))
+__global__ void max_num_work_groups_32_1_1_non_int_arg0() {}
+
+// expected-error@+1{{'amdgpu_max_num_work_groups' attribute requires 
parameter 1 to be an integer constant}}
+__attribute__((amdgpu_max_num_work_groups(32, "1", 1)))
+__global__ void max_num_work_groups_32_1_1_non_int_arg1() {}
+
+// expected-error@+1{{'amdgpu_max_num_work_groups' attribute requires a 
non-negative integral compile time constant expression}}
+__attribute__((amdgpu_max_num_work_groups(-32, 1, 1)))
+__global__ void max_num_work_groups_32_1_1_neg_int_arg0() {}
+
+// expected-error@+1{{'amdgpu_max_num_work_groups' attribute requires a 
non-negative integral compile time constant expression}}
+__attribute__((amdgpu_max_num_work_groups(32, -1, 1)))
+__global__ void max_num_work_groups_32_1_1_neg_int_arg1() {}
+
+// expected-error@+1{{'amdgpu_max_num_work_groups' attribute requires a 
non-negative integral compile time constant expression}}
+__attribute__((amdgpu_max_num_work_groups(32, 1, -1)))
+__global__ void max_num_work_groups_32_1_1_neg_int_arg2() {}
+
+// expected-error@+1{{'amdgpu_max_num_work_groups' attribute must be greater 
than 0}}
+__attribute__((amdgpu_max_num_work_groups(0, 1, 1)))
+__global__ void max_num_work_groups_0_1_1() {}
+
+// expected-error@+1{{'amdgpu_max_num_work_groups' attribute must be greater 
than 0}}
+__attribute__((amdgpu_max_num_work_groups(32, 0, 1)))
+__global__ void max_num_work_groups_32_0_1() {}
+
+// expected-error@+1{{'amdgpu_max_num_work_groups' attribute must be greater 
than 0}}
+__attribute__((amdgpu_max_num_work_groups(32, 1, 0)))
+__global__ void max_num_work_groups_32_1_0() {}
+
+
+int num_wg_x = 32;
+int num_wg_y = 1;
+int num_wg_z = 1;
+// expected-error@+1{{'amdgpu_max_num_work_groups' attribute requires 
parameter 0 to be an integer constant}}
+__attribute__((amdgpu_max_num_work_groups(num_wg_x, 1, 1)))
+__global__ void max_num_work_groups_32_1_1_non_const_arg0() {}
+
+// expected-error@+1{{'amdgpu_max_num_work_groups' attribute requires 
parameter 1 to be an integer constant}}
+__attribute__((amdgpu_max_num_work_groups(32, num_wg_y, 1)))
+__global__ void max_num_work_groups_32_1_1_non_const_arg1() {}
+
+// expected-error@+1{{'amdgpu_max_num_work_groups' attribute requires 
parameter 2 to be an integer constant}}
+__attribute__((amdgpu_max_num_work_groups(32, 1, num_wg_z)))
+__global__ void max_num_work_groups_32_1_1_non_const_arg2() {}
+
+const int c_num_wg_x = 32;
+__attribute__((amdgpu_max_num_work_groups(c_num_wg_x, 1, 1)))
+__global__ void max_num_work_groups_32_1_1_const_arg0() {}
+
+template
+__attribute__((amdgpu_max_num_work_groups(a, 1, 1)))
+__global__ void template_a_1_1_max_num_work_groups() {}
+template __global__ void template_a_1_1_max_num_work_groups<32>();
+
+template
+__attribute__((amdgpu_max_num_work_groups(32, a, 1)))
+__global__ void template_32_a_1_max_num_work_groups() {}
+template __global__ void template_32_a_1_max_num_work_groups<1>();
+
+template
+__attribute__((amdgpu_max_num_work_groups(32, 1, a)))
+__global__ void template_32_1_a_max_num_work_groups() {}
+template __global__ void template_32_1_a_max_num_work_groups<1>();
+
+// expected-error@+3{{'amdgpu_max_num_work_groups' attribute must be greater 
than 0}}
+// expected-note@+4{{in instantiation of}}
+template
+__attribute__((amdgpu_max_num_work_groups(b, 1, 1)))
+__global__ void template_b_1_1_max_num_work_groups() {}
+template __global__ void template_b_1_1_max_num_work_groups<0>();
+
+// expected-error@+3{{'amdgpu_max_num_work_groups' attribute must be greater 
than 0}}
+// expected-note@+4{{in instantiation of}}
+template
+__attribute__((amdgpu_max_num_work_groups(32, b, 1)))
+__global__ void template_32_b_1_max_num_work_groups() {}
+template __global__ void template_32_b_1_max_num_work_groups<0>();
+
+// expected-error@+3{{'amdgpu_max_num_work_groups' attribute must be greater 
than 0}}
+// expected-note@+4{{in instantiation of}}
+template
+__attribute__(

[clang] [Fuchsia] Include baremetal ARM builtins and libc (PR #83949)

2024-03-05 Thread Petr Hosek via cfe-commits

https://github.com/petrhosek updated 
https://github.com/llvm/llvm-project/pull/83949

>From 8c5829c6eb9607152b85dd0e99ccb39770d536fd Mon Sep 17 00:00:00 2001
From: Petr Hosek 
Date: Mon, 6 Mar 2023 19:31:13 +
Subject: [PATCH] [Fuchsia] Include baremetal ARM builtins and libc

For now we only include the armv6m-unknown-eabi target but we plan to
include more targets in the future (including multilibs).
---
 clang/cmake/caches/Fuchsia-stage2.cmake | 33 +
 1 file changed, 33 insertions(+)

diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index eee37c5e7901fa..db7430b3344c3e 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -300,6 +300,39 @@ if(FUCHSIA_SDK)
   set(LLVM_RUNTIME_MULTILIB_hwasan+noexcept_TARGETS 
"aarch64-unknown-fuchsia;riscv64-unknown-fuchsia" CACHE STRING "")
 endif()
 
+foreach(target armv6m-unknown-eabi)
+  list(APPEND BUILTIN_TARGETS "${target}")
+  set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Generic CACHE STRING "")
+  set(BUILTINS_${target}_CMAKE_SYSTEM_PROCESSOR arm CACHE STRING "")
+  set(BUILTINS_${target}_CMAKE_SYSROOT "" CACHE STRING "")
+  set(BUILTINS_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+  foreach(lang C;CXX;ASM)
+set(BUILTINS_${target}_CMAKE_${lang}_FLAGS "--target=${target} 
-mcpu=cortex-m0plus -mthumb" CACHE STRING "")
+  endforeach()
+  foreach(type SHARED;MODULE;EXE)
+set(BUILTINS_${target}_CMAKE_${type}_LINKER_FLAGS "-fuse-ld=lld" CACHE 
STRING "")
+  endforeach()
+  set(BUILTINS_${target}_COMPILER_RT_BAREMETAL_BUILD ON CACHE BOOL "")
+
+  list(APPEND RUNTIME_TARGETS "${target}")
+  set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Generic CACHE STRING "")
+  set(RUNTIMES_${target}_CMAKE_SYSTEM_PROCESSOR arm CACHE STRING "")
+  set(RUNTIMES_${target}_CMAKE_SYSROOT "" CACHE STRING "")
+  set(RUNTIMES_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+  set(RUNTIMES_${target}_CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY CACHE 
STRING "")
+  foreach(lang C;CXX;ASM)
+set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS "--target=${target} 
-mcpu=cortex-m0plus -mthumb" CACHE STRING "")
+  endforeach()
+  foreach(type SHARED;MODULE;EXE)
+set(RUNTIMES_${target}_CMAKE_${type}_LINKER_FLAGS "-fuse-ld=lld" CACHE 
STRING "")
+  endforeach()
+  set(RUNTIMES_${target}_LLVM_LIBC_FULL_BUILD ON CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBC_ENABLE_USE_BY_CLANG ON CACHE BOOL "")
+  set(RUNTIMES_${target}_LLVM_INCLUDE_TESTS OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LLVM_ENABLE_ASSERTIONS OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES "libc" CACHE STRING "")
+endforeach()
+
 foreach(target riscv32-unknown-elf)
   list(APPEND BUILTIN_TARGETS "${target}")
   set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Generic CACHE STRING "")

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


[clang] [Fuchsia] Include baremetal ARM builtins and libc (PR #83949)

2024-03-05 Thread Petr Hosek via cfe-commits


@@ -300,10 +300,43 @@ if(FUCHSIA_SDK)
   set(LLVM_RUNTIME_MULTILIB_hwasan+noexcept_TARGETS 
"aarch64-unknown-fuchsia;riscv64-unknown-fuchsia" CACHE STRING "")
 endif()
 
+foreach(target armv6m-unknown-eabi)
+  list(APPEND BUILTIN_TARGETS "${target}")
+  set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Generic CACHE STRING "")
+  set(BUILTINS_${target}_CMAKE_SYSTEM_PROCESSOR arm CACHE STRING "")
+  set(BUILTINS_${target}_CMAKE_SYSROOT "" CACHE STRING "")
+  set(BUILTINS_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+  foreach(lang C;CXX;ASM)
+set(BUILTINS_${target}_CMAKE_${lang}_FLAGS "--target=${target} 
-mcpu=cortex-m0plus -mthumb" CACHE STRING "")
+  endforeach()
+  foreach(type SHARED;MODULE;EXE)
+set(BUILTINS_${target}_CMAKE_${type}_LINKER_FLAGS "-fuse-ld=lld" CACHE 
STRING "")
+  endforeach()
+  set(BUILTINS_${target}_COMPILER_RT_BAREMETAL_BUILD ON CACHE BOOL "")
+
+  list(APPEND RUNTIME_TARGETS "${target}")
+  set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Generic CACHE STRING "")
+  set(RUNTIMES_${target}_CMAKE_SYSTEM_PROCESSOR arm CACHE STRING "")
+  set(RUNTIMES_${target}_CMAKE_SYSROOT "" CACHE STRING "")
+  set(RUNTIMES_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+  set(RUNTIMES_${target}_CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY CACHE 
STRING "")
+  foreach(lang C;CXX;ASM)
+set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS "--target=${target} 
-mcpu=cortex-m0plus -mthumb" CACHE STRING "")
+  endforeach()
+  foreach(type SHARED;MODULE;EXE)
+set(RUNTIMES_${target}_CMAKE_${type}_LINKER_FLAGS "-fuse-ld=lld" CACHE 
STRING "")
+  endforeach()
+  set(RUNTIMES_${target}_LLVM_LIBC_FULL_BUILD ON CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBC_ENABLE_USE_BY_CLANG ON CACHE BOOL "")
+  set(RUNTIMES_${target}_LLVM_INCLUDE_TESTS OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LLVM_ENABLE_ASSERTIONS OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES "libc" CACHE STRING "")
+endforeach()
+
 foreach(target riscv32-unknown-elf)
   list(APPEND BUILTIN_TARGETS "${target}")
   set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Generic CACHE STRING "")
-  set(BUILTINS_${target}_CMAKE_SYSTEM_PROCESSOR RISCV CACHE STRING "")
+  set(BUILTINS_${target}_CMAKE_SYSTEM_PROCESSOR riscv CACHE STRING "")

petrhosek wrote:

Removed

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


[clang] b3b408b - [Fuchsia] Include baremetal ARM builtins and libc (#83949)

2024-03-05 Thread via cfe-commits

Author: Petr Hosek
Date: 2024-03-05T11:42:51-08:00
New Revision: b3b408bbb379a1cfdac66a71534d86c23a9cf3f1

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

LOG: [Fuchsia] Include baremetal ARM builtins and libc (#83949)

For now we only include the armv6m-unknown-eabi target but we plan to
include more targets in the future (including multilibs).

Added: 


Modified: 
clang/cmake/caches/Fuchsia-stage2.cmake

Removed: 




diff  --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index eee37c5e7901fa..db7430b3344c3e 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -300,6 +300,39 @@ if(FUCHSIA_SDK)
   set(LLVM_RUNTIME_MULTILIB_hwasan+noexcept_TARGETS 
"aarch64-unknown-fuchsia;riscv64-unknown-fuchsia" CACHE STRING "")
 endif()
 
+foreach(target armv6m-unknown-eabi)
+  list(APPEND BUILTIN_TARGETS "${target}")
+  set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Generic CACHE STRING "")
+  set(BUILTINS_${target}_CMAKE_SYSTEM_PROCESSOR arm CACHE STRING "")
+  set(BUILTINS_${target}_CMAKE_SYSROOT "" CACHE STRING "")
+  set(BUILTINS_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+  foreach(lang C;CXX;ASM)
+set(BUILTINS_${target}_CMAKE_${lang}_FLAGS "--target=${target} 
-mcpu=cortex-m0plus -mthumb" CACHE STRING "")
+  endforeach()
+  foreach(type SHARED;MODULE;EXE)
+set(BUILTINS_${target}_CMAKE_${type}_LINKER_FLAGS "-fuse-ld=lld" CACHE 
STRING "")
+  endforeach()
+  set(BUILTINS_${target}_COMPILER_RT_BAREMETAL_BUILD ON CACHE BOOL "")
+
+  list(APPEND RUNTIME_TARGETS "${target}")
+  set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Generic CACHE STRING "")
+  set(RUNTIMES_${target}_CMAKE_SYSTEM_PROCESSOR arm CACHE STRING "")
+  set(RUNTIMES_${target}_CMAKE_SYSROOT "" CACHE STRING "")
+  set(RUNTIMES_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+  set(RUNTIMES_${target}_CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY CACHE 
STRING "")
+  foreach(lang C;CXX;ASM)
+set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS "--target=${target} 
-mcpu=cortex-m0plus -mthumb" CACHE STRING "")
+  endforeach()
+  foreach(type SHARED;MODULE;EXE)
+set(RUNTIMES_${target}_CMAKE_${type}_LINKER_FLAGS "-fuse-ld=lld" CACHE 
STRING "")
+  endforeach()
+  set(RUNTIMES_${target}_LLVM_LIBC_FULL_BUILD ON CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBC_ENABLE_USE_BY_CLANG ON CACHE BOOL "")
+  set(RUNTIMES_${target}_LLVM_INCLUDE_TESTS OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LLVM_ENABLE_ASSERTIONS OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES "libc" CACHE STRING "")
+endforeach()
+
 foreach(target riscv32-unknown-elf)
   list(APPEND BUILTIN_TARGETS "${target}")
   set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Generic CACHE STRING "")



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


[clang] [Fuchsia] Include baremetal ARM builtins and libc (PR #83949)

2024-03-05 Thread Petr Hosek via cfe-commits

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


[clang] [clang] Bugfix for choosing the more specialized overload (PR #83279)

2024-03-05 Thread Botond István Horváth via cfe-commits

HoBoIs wrote:

@erichkeane Thank you for the suggestions, I have removed the checking for 
C++20 and I also changed to the `Args.resize(std::min(...))` based on what you 
suggested. Is there anything else to be done?

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


  1   2   3   4   5   6   >