[clang] 14c323c - [OpenMP][AMDGPU] Do not attach -fcuda-is-device (#99002)

2024-07-18 Thread via cfe-commits

Author: Dominik Adamski
Date: 2024-07-18T09:00:09+02:00
New Revision: 14c323cfd66454c65324c4d5b9d9b6a9c5651eca

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

LOG: [OpenMP][AMDGPU] Do not attach -fcuda-is-device (#99002)

-fcuda-is-device flag is not used for OpenMP offloading for AMD GPUs and
it does not need to be added as clang cc1 option for OpenMP code.

This PR has the same functionality as
https://github.com/llvm/llvm-project/pull/96909 but it doesn't introduce
regression for virtual function support.

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.h
clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
clang/test/Driver/amdgpu-openmp-toolchain.c

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.h 
b/clang/lib/CodeGen/CodeGenModule.h
index caa3786c033b5..657e681730c3a 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -1010,7 +1010,7 @@ class CodeGenModule : public CodeGenTypeCache {
   bool shouldEmitRTTI(bool ForEH = false) {
 return (ForEH || getLangOpts().RTTI) && !getLangOpts().CUDAIsDevice &&
!(getLangOpts().OpenMP && getLangOpts().OpenMPIsTargetDevice &&
- getTriple().isNVPTX());
+ (getTriple().isNVPTX() || getTriple().isAMDGPU()));
   }
 
   /// Get the address of the RTTI descriptor for the given type.

diff  --git a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp 
b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
index 1c0fb4babe3a5..b75d400e6ce91 100644
--- a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
@@ -47,8 +47,6 @@ void AMDGPUOpenMPToolChain::addClangTargetOptions(
   assert(DeviceOffloadingKind == Action::OFK_OpenMP &&
  "Only OpenMP offloading kinds are supported.");
 
-  CC1Args.push_back("-fcuda-is-device");
-
   if (DriverArgs.hasArg(options::OPT_nogpulib))
 return;
 

diff  --git a/clang/test/Driver/amdgpu-openmp-toolchain.c 
b/clang/test/Driver/amdgpu-openmp-toolchain.c
index 49af04acc4639..a153c4afb0ce8 100644
--- a/clang/test/Driver/amdgpu-openmp-toolchain.c
+++ b/clang/test/Driver/amdgpu-openmp-toolchain.c
@@ -7,7 +7,7 @@
 
 // verify the tools invocations
 // CHECK: "-cc1" "-triple" 
"x86_64-unknown-linux-gnu"{{.*}}"-emit-llvm-bc"{{.*}}"-x" "c"
-// CHECK: "-cc1" "-triple" "amdgcn-amd-amdhsa" "-aux-triple" 
"x86_64-unknown-linux-gnu"{{.*}}"-fcuda-is-device"{{.*}}"-target-cpu" "gfx906"
+// CHECK: "-cc1" "-triple" "amdgcn-amd-amdhsa" "-aux-triple" 
"x86_64-unknown-linux-gnu"{{.*}}"-target-cpu" "gfx906"
 // CHECK: "-cc1" "-triple" "x86_64-unknown-linux-gnu"{{.*}}"-emit-obj"
 // CHECK: clang-linker-wrapper{{.*}} "-o" "a.out"
 



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


[clang] [OpenMP][AMDGPU] Do not attach -fcuda-is-device (PR #99002)

2024-07-18 Thread Dominik Adamski via cfe-commits

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


[clang] 7aabdb8 - [clang][Interp][NFC] Protect ByteCodeEmitter against unfinished fns

2024-07-18 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-07-18T09:05:48+02:00
New Revision: 7aabdb8776eb11b90d43162254db47df46806ec9

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

LOG: [clang][Interp][NFC] Protect ByteCodeEmitter against unfinished fns

This is similar to a check in TextNodeDumper.cpp. Without this, we will
crash later when trying to iterate over FuncDecl->params().

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeEmitter.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp 
b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
index 17da77bc63c9b..a3d4c7d7392da 100644
--- a/clang/lib/AST/Interp/ByteCodeEmitter.cpp
+++ b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
@@ -31,6 +31,12 @@ static bool isUnevaluatedBuiltin(unsigned BuiltinID) {
 }
 
 Function *ByteCodeEmitter::compileFunc(const FunctionDecl *FuncDecl) {
+
+  // Manually created functions that haven't been assigned proper
+  // parameters yet.
+  if (!FuncDecl->param_empty() && !FuncDecl->param_begin())
+return nullptr;
+
   bool IsLambdaStaticInvoker = false;
   if (const auto *MD = dyn_cast(FuncDecl);
   MD && MD->isLambdaStaticInvoker()) {



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


[clang-tools-extra] Ensure functions are anchored in the global namespace (PR #99084)

2024-07-18 Thread Nathan James via cfe-commits

njames93 wrote:

Just a drive by comment, would it not have been nicer to use the `hasAnyName` 
matcher which understands `::` at the start means global namespace.

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


[clang] [Sema] Preserve ContainsUnexpandedParameterPack in TransformLambdaExpr (PR #86265)

2024-07-18 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/86265

>From 6e7b38b3e3f781e11db2fa5d552fdfb6123609df Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Fri, 22 Mar 2024 17:34:08 +0800
Subject: [PATCH 01/10] [Sema] Preserve ContainsUnexpandedParameterPack in
 TransformLambdaExpr

---
 clang/docs/ReleaseNotes.rst   |  2 +
 clang/include/clang/Sema/Sema.h   |  8 +++
 clang/lib/Sema/SemaTemplateVariadic.cpp   | 16 +-
 clang/lib/Sema/TreeTransform.h| 18 ++
 .../test/SemaTemplate/lambda-capture-pack.cpp | 57 +++
 5 files changed, 98 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 690fc7ed271a3..2d11a4b8c092a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -344,6 +344,8 @@ Bug Fixes to C++ Support
   when one of the function had more specialized templates.
   Fixes (`#82509 `_)
   and (`#74494 `_)
+- Fixed a crash where template parameter packs were not expanded correctly in 
a lambda being
+  used as a pattern of a folded expression. (#GH56852), (#GH85667)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index cfc1c3b349478..0d1a2e54840e5 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11201,6 +11201,14 @@ class Sema final {
   void collectUnexpandedParameterPacks(
   QualType T, SmallVectorImpl &Unexpanded);
 
+  /// Collect the set of unexpanded parameter packs from a lambda call 
operator.
+  ///
+  /// \param LambdaCall The lambda call operator that will be traversed to find
+  /// unexpanded parameter packs.
+  void collectUnexpandedParameterPacksFromLambda(
+  CXXMethodDecl *LambdaCall,
+  SmallVectorImpl &Unexpanded);
+
   /// Collect the set of unexpanded parameter packs within the given
   /// type.
   ///
diff --git a/clang/lib/Sema/SemaTemplateVariadic.cpp 
b/clang/lib/Sema/SemaTemplateVariadic.cpp
index 903fbfd18e779..638ceac4148ae 100644
--- a/clang/lib/Sema/SemaTemplateVariadic.cpp
+++ b/clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -8,14 +8,15 @@
 //  This file implements semantic analysis for C++0x variadic templates.
 //===--===/
 
-#include "clang/Sema/Sema.h"
 #include "TypeLocBuilder.h"
+#include "clang/AST/ASTLambda.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/TypeLoc.h"
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/ParsedTemplate.h"
 #include "clang/Sema/ScopeInfo.h"
+#include "clang/Sema/Sema.h"
 #include "clang/Sema/SemaInternal.h"
 #include "clang/Sema/Template.h"
 #include 
@@ -61,8 +62,9 @@ namespace {
 
   public:
 explicit CollectUnexpandedParameterPacksVisitor(
-SmallVectorImpl &Unexpanded)
-: Unexpanded(Unexpanded) {}
+SmallVectorImpl &Unexpanded,
+bool InLambda = false)
+: Unexpanded(Unexpanded), InLambda(InLambda) {}
 
 bool shouldWalkTypesOfTypeLocs() const { return false; }
 
@@ -544,6 +546,14 @@ void Sema::collectUnexpandedParameterPacks(QualType T,
   CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseType(T);
 }
 
+void Sema::collectUnexpandedParameterPacksFromLambda(
+CXXMethodDecl *LambdaCall,
+SmallVectorImpl &Unexpanded) {
+  assert(isLambdaCallOperator(LambdaCall) && "Expected a lambda call 
operator");
+  CollectUnexpandedParameterPacksVisitor(Unexpanded, /*InLambda=*/true)
+  .TraverseDecl(LambdaCall);
+}
+
 void Sema::collectUnexpandedParameterPacks(TypeLoc TL,
SmallVectorImpl &Unexpanded) {
   CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseTypeLoc(TL);
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 2d22692f3ab75..f5a859c57034a 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13748,6 +13748,8 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 }
 NewVDs.push_back(NewVD);
 getSema().addInitCapture(LSI, NewVD, C->getCaptureKind() == LCK_ByRef);
+LSI->ContainsUnexpandedParameterPack |=
+Init.get()->containsUnexpandedParameterPack();
   }
 
   if (Invalid)
@@ -13936,6 +13938,22 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 /*IsInstantiation*/ true);
   SavedContext.pop();
 
+  // The lambda may contain a pack that would be expanded by a fold expression
+  // outside. We should preserve the ContainsUnexpandedParameterPack flag here
+  // because CXXFoldExprs use it for the pattern.
+  // For example,
+  //
+  // []() { ([I = Is()]() {}, ...); }
+  //
+  // forgetting the flag will result in getPattern() of CXXFoldExpr returning
+  // null in terms of the

[clang] [Clang] Fix Microsoft ABI inheritance model when member pointer is used in a base specifier (PR #91990)

2024-07-18 Thread Mital Ashok via cfe-commits


@@ -13,3 +15,18 @@ template 
 struct S3 {
   int T::*foo;
 };
+
+template struct Base {};
+struct
+S5 // #S5
+:
+Base
+// expected-error@-1 {{member pointer has incomplete base type 'S5'}}

MitalAshok wrote:

It's an error for `-fcomplete-member-pointers` which is supposed to tell you 
when you use a member pointer in a way that the MS ABI would have it be 
unspecified, regardless of if you are compiling with MS member pointers or 
Itanium member pointers

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


[clang] [Clang SA]: add support for mismatched ownership_returns+ownership_takes calls for custom allocation classes (PR #98941)

2024-07-18 Thread Pavel Skripkin via cfe-commits

https://github.com/pskrgag updated 
https://github.com/llvm/llvm-project/pull/98941

>From 3d362cfb1e197713a51ce798996ff4308e7ab5aa Mon Sep 17 00:00:00 2001
From: Pavel Skripkin 
Date: Wed, 17 Jul 2024 16:41:20 +0300
Subject: [PATCH 1/7] clang/sema: disallow more than one 'onweship_takes' with
 different classes

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td |  4 
 clang/lib/Sema/SemaDeclAttr.cpp  | 10 ++
 clang/test/Sema/attr-ownership.c |  4 
 3 files changed, 18 insertions(+)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 0ea3677355169..77f830b3b4aee 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3328,6 +3328,10 @@ def err_ownership_returns_index_mismatch : Error<
   "'ownership_returns' attribute index does not match; here it is %0">;
 def note_ownership_returns_index_mismatch : Note<
   "declared with index %0 here">;
+def err_ownership_takes_class_mismatch : Error<
+  "'ownership_takes' attribute class does not match; here it is '%0'">;
+def note_ownership_takes_class_mismatch : Note<
+  "declared with class '%0' here">;
 def err_format_strftime_third_parameter : Error<
   "strftime format attribute requires 3rd parameter to be 0">;
 def err_format_attribute_not : Error<"format argument not a string type">;
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 20f46c003a464..12f8f2ab8954d 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -1537,6 +1537,16 @@ static void handleOwnershipAttr(Sema &S, Decl *D, const 
ParsedAttr &AL) {
 << Idx.getSourceIndex() << Ex->getSourceRange();
   return;
 }
+  } else if (K == OwnershipAttr::Takes &&
+ I->getOwnKind() == OwnershipAttr::Takes) {
+if (I->getModule()->getName() != ModuleName) {
+  S.Diag(I->getLocation(), diag::err_ownership_takes_class_mismatch)
+  << I->getModule()->getName();
+  S.Diag(AL.getLoc(), diag::note_ownership_takes_class_mismatch)
+  << ModuleName << Ex->getSourceRange();
+
+  return;
+}
   }
 }
 OwnershipArgs.push_back(Idx);
diff --git a/clang/test/Sema/attr-ownership.c b/clang/test/Sema/attr-ownership.c
index 8157ba7145a24..084624353315c 100644
--- a/clang/test/Sema/attr-ownership.c
+++ b/clang/test/Sema/attr-ownership.c
@@ -24,3 +24,7 @@ void f15(int, int)
 void f16(int *i, int *j) __attribute__((ownership_holds(foo, 1))) 
__attribute__((ownership_holds(foo, 1))); // OK, same index
 void f17(void*) __attribute__((ownership_takes(__, 1)));
 void f18() __attribute__((ownership_takes(foo, 1)));  // expected-warning 
{{'ownership_takes' attribute only applies to non-K&R-style functions}}
+
+int f19(void *)
+  __attribute__((ownership_takes(foo, 1)))// expected-error 
{{'ownership_takes' attribute class does not match; here it is 'foo'}}
+  __attribute__((ownership_takes(foo1, 1)));  // expected-note {{declared with 
class 'foo1' here}}

>From 426b1918f354835550e853a1f875af8dc3c04617 Mon Sep 17 00:00:00 2001
From: Pavel Skripkin 
Date: Wed, 17 Jul 2024 18:38:28 +0300
Subject: [PATCH 2/7] csa/MallocChecker: turn llvm_unreachable into asserts

---
 .../StaticAnalyzer/Checkers/MallocChecker.cpp | 22 ---
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index fe202c79ed620..8ff71318073ce 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -1293,7 +1293,8 @@ void MallocChecker::checkCXXNewOrCXXDelete(const 
CallEvent &Call,
AF_CXXNewArray);
 break;
   default:
-llvm_unreachable("not a new/delete operator");
+assert(false && "not a new/delete operator");
+return;
   }
 
   C.addTransition(State);
@@ -1489,8 +1490,10 @@ ProgramStateRef MallocChecker::ProcessZeroAllocCheck(
 } else {
   return State;
 }
-  } else
-llvm_unreachable("not a CallExpr or CXXNewExpr");
+  } else {
+assert(false && "not a CallExpr or CXXNewExpr");
+return nullptr;
+  }
 
   assert(Arg);
 
@@ -1925,7 +1928,7 @@ static void printExpectedAllocName(raw_ostream &os, 
AllocationFamily Family) {
 case AF_IfNameIndex: os << "'if_nameindex()'"; return;
 case AF_InnerBuffer: os << "container-specific allocator"; return;
 case AF_Alloca:
-case AF_None: llvm_unreachable("not a deallocation expression");
+case AF_None: assert(false && "not a deallocation expression");
   }
 }
 
@@ -1937,7 +1940,7 @@ static void printExpectedDeallocName(raw_ostream &os, 
AllocationFamily Family) {
 case AF_IfNameIndex: os << "'if_freenameindex()'"; return;
 case AF_InnerBuffer: os << "container-specific deall

[clang] [Sema] Preserve ContainsUnexpandedParameterPack in TransformLambdaExpr (PR #86265)

2024-07-18 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/86265

>From 6e7b38b3e3f781e11db2fa5d552fdfb6123609df Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Fri, 22 Mar 2024 17:34:08 +0800
Subject: [PATCH 01/11] [Sema] Preserve ContainsUnexpandedParameterPack in
 TransformLambdaExpr

---
 clang/docs/ReleaseNotes.rst   |  2 +
 clang/include/clang/Sema/Sema.h   |  8 +++
 clang/lib/Sema/SemaTemplateVariadic.cpp   | 16 +-
 clang/lib/Sema/TreeTransform.h| 18 ++
 .../test/SemaTemplate/lambda-capture-pack.cpp | 57 +++
 5 files changed, 98 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 690fc7ed271a3..2d11a4b8c092a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -344,6 +344,8 @@ Bug Fixes to C++ Support
   when one of the function had more specialized templates.
   Fixes (`#82509 `_)
   and (`#74494 `_)
+- Fixed a crash where template parameter packs were not expanded correctly in 
a lambda being
+  used as a pattern of a folded expression. (#GH56852), (#GH85667)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index cfc1c3b349478..0d1a2e54840e5 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11201,6 +11201,14 @@ class Sema final {
   void collectUnexpandedParameterPacks(
   QualType T, SmallVectorImpl &Unexpanded);
 
+  /// Collect the set of unexpanded parameter packs from a lambda call 
operator.
+  ///
+  /// \param LambdaCall The lambda call operator that will be traversed to find
+  /// unexpanded parameter packs.
+  void collectUnexpandedParameterPacksFromLambda(
+  CXXMethodDecl *LambdaCall,
+  SmallVectorImpl &Unexpanded);
+
   /// Collect the set of unexpanded parameter packs within the given
   /// type.
   ///
diff --git a/clang/lib/Sema/SemaTemplateVariadic.cpp 
b/clang/lib/Sema/SemaTemplateVariadic.cpp
index 903fbfd18e779..638ceac4148ae 100644
--- a/clang/lib/Sema/SemaTemplateVariadic.cpp
+++ b/clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -8,14 +8,15 @@
 //  This file implements semantic analysis for C++0x variadic templates.
 //===--===/
 
-#include "clang/Sema/Sema.h"
 #include "TypeLocBuilder.h"
+#include "clang/AST/ASTLambda.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/TypeLoc.h"
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/ParsedTemplate.h"
 #include "clang/Sema/ScopeInfo.h"
+#include "clang/Sema/Sema.h"
 #include "clang/Sema/SemaInternal.h"
 #include "clang/Sema/Template.h"
 #include 
@@ -61,8 +62,9 @@ namespace {
 
   public:
 explicit CollectUnexpandedParameterPacksVisitor(
-SmallVectorImpl &Unexpanded)
-: Unexpanded(Unexpanded) {}
+SmallVectorImpl &Unexpanded,
+bool InLambda = false)
+: Unexpanded(Unexpanded), InLambda(InLambda) {}
 
 bool shouldWalkTypesOfTypeLocs() const { return false; }
 
@@ -544,6 +546,14 @@ void Sema::collectUnexpandedParameterPacks(QualType T,
   CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseType(T);
 }
 
+void Sema::collectUnexpandedParameterPacksFromLambda(
+CXXMethodDecl *LambdaCall,
+SmallVectorImpl &Unexpanded) {
+  assert(isLambdaCallOperator(LambdaCall) && "Expected a lambda call 
operator");
+  CollectUnexpandedParameterPacksVisitor(Unexpanded, /*InLambda=*/true)
+  .TraverseDecl(LambdaCall);
+}
+
 void Sema::collectUnexpandedParameterPacks(TypeLoc TL,
SmallVectorImpl &Unexpanded) {
   CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseTypeLoc(TL);
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 2d22692f3ab75..f5a859c57034a 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13748,6 +13748,8 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 }
 NewVDs.push_back(NewVD);
 getSema().addInitCapture(LSI, NewVD, C->getCaptureKind() == LCK_ByRef);
+LSI->ContainsUnexpandedParameterPack |=
+Init.get()->containsUnexpandedParameterPack();
   }
 
   if (Invalid)
@@ -13936,6 +13938,22 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 /*IsInstantiation*/ true);
   SavedContext.pop();
 
+  // The lambda may contain a pack that would be expanded by a fold expression
+  // outside. We should preserve the ContainsUnexpandedParameterPack flag here
+  // because CXXFoldExprs use it for the pattern.
+  // For example,
+  //
+  // []() { ([I = Is()]() {}, ...); }
+  //
+  // forgetting the flag will result in getPattern() of CXXFoldExpr returning
+  // null in terms of the

[clang] [Clang] Fix Microsoft ABI inheritance model when member pointer is used in a base specifier (PR #91990)

2024-07-18 Thread Mital Ashok via cfe-commits


@@ -215,6 +215,14 @@ struct NewUnspecified;
 SingleTemplate tmpl_single;
 UnspecTemplate tmpl_unspec;
 
+// Member pointers used in base specifiers force an unspecified inheritance 
model
+struct MemPtrInBase : UnspecTemplate {};

MitalAshok wrote:

It's not for simply naming the type for the template argument but 
`UnspecTemplate`'s definition does complete it by taking its `sizeof`, forcing 
the inheritance model to be assigned

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


[clang] [Clang SA]: add support for mismatched ownership_returns+ownership_takes calls for custom allocation classes (PR #98941)

2024-07-18 Thread Pavel Skripkin via cfe-commits

pskrgag wrote:

Thank you for review!

I've applied your suggestions and fixed test failures. Messed up a bit with 
shadowing in constructor. 

> Usually, GitHub PRs prefer "merges" over "force-pushes". Whenever you 
> force-push, all the inline remarks could get lost, as it fails to track the 
> lines where the comments were made

Oh, ok. I've never really worked with gh workflow, so didn't know that. Thank 
you for guidance!

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


[clang] [Sema] Preserve ContainsUnexpandedParameterPack in TransformLambdaExpr (PR #86265)

2024-07-18 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/86265

>From 6e7b38b3e3f781e11db2fa5d552fdfb6123609df Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Fri, 22 Mar 2024 17:34:08 +0800
Subject: [PATCH 01/12] [Sema] Preserve ContainsUnexpandedParameterPack in
 TransformLambdaExpr

---
 clang/docs/ReleaseNotes.rst   |  2 +
 clang/include/clang/Sema/Sema.h   |  8 +++
 clang/lib/Sema/SemaTemplateVariadic.cpp   | 16 +-
 clang/lib/Sema/TreeTransform.h| 18 ++
 .../test/SemaTemplate/lambda-capture-pack.cpp | 57 +++
 5 files changed, 98 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 690fc7ed271a3..2d11a4b8c092a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -344,6 +344,8 @@ Bug Fixes to C++ Support
   when one of the function had more specialized templates.
   Fixes (`#82509 `_)
   and (`#74494 `_)
+- Fixed a crash where template parameter packs were not expanded correctly in 
a lambda being
+  used as a pattern of a folded expression. (#GH56852), (#GH85667)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index cfc1c3b349478..0d1a2e54840e5 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11201,6 +11201,14 @@ class Sema final {
   void collectUnexpandedParameterPacks(
   QualType T, SmallVectorImpl &Unexpanded);
 
+  /// Collect the set of unexpanded parameter packs from a lambda call 
operator.
+  ///
+  /// \param LambdaCall The lambda call operator that will be traversed to find
+  /// unexpanded parameter packs.
+  void collectUnexpandedParameterPacksFromLambda(
+  CXXMethodDecl *LambdaCall,
+  SmallVectorImpl &Unexpanded);
+
   /// Collect the set of unexpanded parameter packs within the given
   /// type.
   ///
diff --git a/clang/lib/Sema/SemaTemplateVariadic.cpp 
b/clang/lib/Sema/SemaTemplateVariadic.cpp
index 903fbfd18e779..638ceac4148ae 100644
--- a/clang/lib/Sema/SemaTemplateVariadic.cpp
+++ b/clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -8,14 +8,15 @@
 //  This file implements semantic analysis for C++0x variadic templates.
 //===--===/
 
-#include "clang/Sema/Sema.h"
 #include "TypeLocBuilder.h"
+#include "clang/AST/ASTLambda.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/TypeLoc.h"
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/ParsedTemplate.h"
 #include "clang/Sema/ScopeInfo.h"
+#include "clang/Sema/Sema.h"
 #include "clang/Sema/SemaInternal.h"
 #include "clang/Sema/Template.h"
 #include 
@@ -61,8 +62,9 @@ namespace {
 
   public:
 explicit CollectUnexpandedParameterPacksVisitor(
-SmallVectorImpl &Unexpanded)
-: Unexpanded(Unexpanded) {}
+SmallVectorImpl &Unexpanded,
+bool InLambda = false)
+: Unexpanded(Unexpanded), InLambda(InLambda) {}
 
 bool shouldWalkTypesOfTypeLocs() const { return false; }
 
@@ -544,6 +546,14 @@ void Sema::collectUnexpandedParameterPacks(QualType T,
   CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseType(T);
 }
 
+void Sema::collectUnexpandedParameterPacksFromLambda(
+CXXMethodDecl *LambdaCall,
+SmallVectorImpl &Unexpanded) {
+  assert(isLambdaCallOperator(LambdaCall) && "Expected a lambda call 
operator");
+  CollectUnexpandedParameterPacksVisitor(Unexpanded, /*InLambda=*/true)
+  .TraverseDecl(LambdaCall);
+}
+
 void Sema::collectUnexpandedParameterPacks(TypeLoc TL,
SmallVectorImpl &Unexpanded) {
   CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseTypeLoc(TL);
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 2d22692f3ab75..f5a859c57034a 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13748,6 +13748,8 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 }
 NewVDs.push_back(NewVD);
 getSema().addInitCapture(LSI, NewVD, C->getCaptureKind() == LCK_ByRef);
+LSI->ContainsUnexpandedParameterPack |=
+Init.get()->containsUnexpandedParameterPack();
   }
 
   if (Invalid)
@@ -13936,6 +13938,22 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 /*IsInstantiation*/ true);
   SavedContext.pop();
 
+  // The lambda may contain a pack that would be expanded by a fold expression
+  // outside. We should preserve the ContainsUnexpandedParameterPack flag here
+  // because CXXFoldExprs use it for the pattern.
+  // For example,
+  //
+  // []() { ([I = Is()]() {}, ...); }
+  //
+  // forgetting the flag will result in getPattern() of CXXFoldExpr returning
+  // null in terms of the

[clang] [Sema] Preserve ContainsUnexpandedParameterPack in TransformLambdaExpr (PR #86265)

2024-07-18 Thread Younan Zhang via cfe-commits

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


[clang] [clang] Add deprecation warning for `-Ofast` driver option (PR #98736)

2024-07-18 Thread Vlad Serebrennikov via cfe-commits


@@ -931,7 +931,9 @@ def O : Joined<["-"], "O">, Group,
 def O_flag : Flag<["-"], "O">, Visibility<[ClangOption, CC1Option, FC1Option]>,
   Alias, AliasArgs<["1"]>;
 def Ofast : Joined<["-"], "Ofast">, Group,
-  Visibility<[ClangOption, CC1Option, FlangOption]>;
+  Visibility<[ClangOption, CC1Option, FlangOption]>,
+  HelpText<"Deprecated; use '-O3 -ffast math' for the same behavior,"
+  " or '-O3' to enable conforming optimizations only">;

Endilll wrote:

Applied, thank you

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


[clang] [clang] Add deprecation warning for `-Ofast` driver option (PR #98736)

2024-07-18 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

This PR has passed CI before latest wording suggestion by Shafik, so I'll go 
ahead and merge this.

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


[clang] 2ef7cbf - [clang] Add deprecation warning for `-Ofast` driver option (#98736)

2024-07-18 Thread via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-07-18T11:49:53+04:00
New Revision: 2ef7cbf71c98246d6f3a9c63dea75b76c7b5e928

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

LOG: [clang] Add deprecation warning for `-Ofast` driver option (#98736)

This patch implements consensus on the corresponding RFC documented
here: https://discourse.llvm.org/t/rfc-deprecate-ofast/78687/72
Specifically, I added a deprecation warning for `-Ofast`, that suggests
to use `-O3` or `-O3` with `-ffast-math`, and a new diagnostic group for
aforementioned warning.
Deprecation period is going to be lengthy, so I hope this PR can be
merged in time for Clang 19.

Added: 


Modified: 
clang/docs/CommandGuide/clang.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/Ofast.c

Removed: 




diff  --git a/clang/docs/CommandGuide/clang.rst 
b/clang/docs/CommandGuide/clang.rst
index 29154292dc7a5..663aca1f6ddcb 100644
--- a/clang/docs/CommandGuide/clang.rst
+++ b/clang/docs/CommandGuide/clang.rst
@@ -429,7 +429,8 @@ Code Generation Options
 
 :option:`-Ofast` Enables all the optimizations from :option:`-O3` along
 with other aggressive optimizations that may violate strict compliance with
-language standards.
+language standards. This is deprecated in favor of :option:`-O3`
+in combination with :option:`-ffast-math`.
 
 :option:`-Os` Like :option:`-O2` with extra optimizations to reduce code
 size.

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1c1b874273a7c..469510d175887 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -473,6 +473,13 @@ New Compiler Flags
 Deprecated Compiler Flags
 -
 
+- The ``-Ofast`` command-line option has been deprecated. This option both
+  enables the ``-O3`` optimization-level, as well as enabling non-standard
+  ``-ffast-math`` behaviors. As such, it is somewhat misleading as an
+  "optimization level". Users are advised to switch to ``-O3 -ffast-math`` if
+  the use of non-standard math behavior is intended, and ``-O3`` otherwise.
+  See `RFC `_ for 
details.
+
 Modified Compiler Flags
 ---
 - Added a new diagnostic flag ``-Wreturn-mismatch`` which is grouped under

diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 359c0de7f811c..cfa897f28b4c0 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -442,6 +442,10 @@ def warn_drv_deprecated_arg : Warning<
 def warn_drv_deprecated_arg_no_relaxed_template_template_args : Warning<
   "argument '-fno-relaxed-template-template-args' is deprecated">,
   InGroup;
+def warn_drv_deprecated_arg_ofast : Warning<
+  "argument '-Ofast' is deprecated; use '-O3 -ffast math' for the same 
behavior,"
+  " or '-O3' to enable only conforming optimizations">,
+  InGroup;
 def warn_drv_deprecated_custom : Warning<
   "argument '%0' is deprecated, %1">, InGroup;
 def warn_drv_assuming_mfloat_abi_is : Warning<

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 2241f8481484e..d7dba76a0fcf8 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -103,6 +103,7 @@ def EnumConversion : DiagGroup<"enum-conversion",
 EnumFloatConversion,
 EnumCompareConditional]>;
 def DeprecatedNoRelaxedTemplateTemplateArgs : 
DiagGroup<"deprecated-no-relaxed-template-template-args">;
+def DeprecatedOFast : DiagGroup<"deprecated-ofast">;
 def ObjCSignedCharBoolImplicitIntConversion :
   DiagGroup<"objc-signed-char-bool-implicit-int-conversion">;
 def Shorten64To32 : DiagGroup<"shorten-64-to-32">;
@@ -228,6 +229,7 @@ def Deprecated : DiagGroup<"deprecated", 
[DeprecatedAnonEnumEnumConversion,
   DeprecatedPragma,
   DeprecatedRegister,
   
DeprecatedNoRelaxedTemplateTemplateArgs,
+  DeprecatedOFast,
   DeprecatedThisCapture,
   DeprecatedType,
   DeprecatedVolatile,

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2e4620523..1675e435d210c 100644
--- a/clang/

[clang] [clang] Add deprecation warning for `-Ofast` driver option (PR #98736)

2024-07-18 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [llvm] Add source file name for template instantiations in -ftime-trace (PR #98320)

2024-07-18 Thread Ilya Biryukov via cfe-commits


@@ -60,39 +74,65 @@ bool compileFromString(StringRef Code, StringRef Standard, 
StringRef FileName) {
   return Compiler.ExecuteAction(Action);
 }
 
+std::string GetMetadata(json::Object *Event) {
+  std::string Metadata = "";
+  if (json::Object *Args = Event->getObject("args")) {
+if (StringRef Detail = Args->getString("detail").value_or("");
+!Detail.empty())
+  Metadata += Detail.str();
+if (StringRef File = Args->getString("filename").value_or("");
+!File.empty())
+  Metadata += ", " + File.str();
+  }
+  return Metadata;
+}
+
 // Returns pretty-printed trace graph.
 std::string buildTraceGraph(StringRef Json) {
   struct EventRecord {
 int64_t TimestampBegin;
 int64_t TimestampEnd;
-StringRef Name;
-StringRef Detail;
+std::string Name;
+std::string Metadata;
   };
   std::vector Events;
 
   // Parse `EventRecord`s from JSON dump.
   Expected Root = json::parse(Json);
   if (!Root)
 return "";
+  std::stack SourceEvents;
   for (json::Value &TraceEventValue :
*Root->getAsObject()->getArray("traceEvents")) {
 json::Object *TraceEventObj = TraceEventValue.getAsObject();
 
 int64_t TimestampBegin = TraceEventObj->getInteger("ts").value_or(0);
 int64_t TimestampEnd =
 TimestampBegin + TraceEventObj->getInteger("dur").value_or(0);
-StringRef Name = TraceEventObj->getString("name").value_or("");
-StringRef Detail = "";
-if (json::Object *Args = TraceEventObj->getObject("args"))
-  Detail = Args->getString("detail").value_or("");
+std::string Name = TraceEventObj->getString("name").value_or("").str();
+std::string Metadata = GetMetadata(TraceEventObj);
+
+if (Name == "Source") {

ilya-biryukov wrote:

But why do we do this in the unit-tests, and not production code, and why do we 
need to do this in this change?
I am still vague on the motivation for this diff.

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


[clang] [libc] [libcxx] [libc][libcxx] Support for building libc++ against LLVM libc (PR #99287)

2024-07-18 Thread Petr Hosek via cfe-commits

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

>From 7d7a7882b713e056f9194b2dd7d792fb9bb86bb5 Mon Sep 17 00:00:00 2001
From: Petr Hosek 
Date: Wed, 17 Jul 2024 00:32:39 -0700
Subject: [PATCH 1/2] [libc][libcxx] Support for building libc++ against LLVM
 libc

Provide an option to build libc++ against LLVM libc and set the CMake
compile and link options appropriately when the option is enabled.
---
 clang/cmake/caches/Fuchsia-stage2.cmake|  2 ++
 libc/cmake/modules/CheckCompilerFeatures.cmake |  3 +++
 libc/include/CMakeLists.txt|  3 +++
 libc/lib/CMakeLists.txt|  5 -
 libcxx/CMakeLists.txt  |  1 +
 libcxx/include/CMakeLists.txt  |  3 +++
 libcxx/src/CMakeLists.txt  | 10 ++
 7 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index b4561e6c87ba5..dc9b596b4ba8f 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -338,6 +338,7 @@ foreach(target 
armv6m-unknown-eabi;armv7m-unknown-eabi;armv8m.main-unknown-eabi)
   set(RUNTIMES_${target}_LIBCXX_CXX_ABI none CACHE STRING "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC ON CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXX_USE_LLVM_LIBC ON CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_RANDOM_DEVICE OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_LOCALIZATION OFF CACHE BOOL "")
@@ -388,6 +389,7 @@ foreach(target riscv32-unknown-elf)
   set(RUNTIMES_${target}_LIBCXX_CXX_ABI none CACHE STRING "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC ON CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXX_USE_LLVM_LIBC ON CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_RANDOM_DEVICE OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_LOCALIZATION OFF CACHE BOOL "")
diff --git a/libc/cmake/modules/CheckCompilerFeatures.cmake 
b/libc/cmake/modules/CheckCompilerFeatures.cmake
index a6d793d495c45..d64d9de97af3c 100644
--- a/libc/cmake/modules/CheckCompilerFeatures.cmake
+++ b/libc/cmake/modules/CheckCompilerFeatures.cmake
@@ -102,3 +102,6 @@ check_cxx_compiler_flag("-nostdlib++" 
LIBC_CC_SUPPORTS_NOSTDLIBPP)
 
 # clang-3.0+
 check_cxx_compiler_flag("-nostdlibinc" LIBC_CC_SUPPORTS_NOSTDLIBINC)
+
+# clang-3.0+
+check_cxx_compiler_flag("-nolibc" LIBC_CC_SUPPORTS_NOLIBC)
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index 2cf7206f3a625..d521e205df8c3 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -664,6 +664,9 @@ get_all_install_header_targets(all_install_header_targets 
${TARGET_PUBLIC_HEADER
 add_library(libc-headers INTERFACE)
 add_dependencies(libc-headers ${all_install_header_targets})
 target_include_directories(libc-headers SYSTEM INTERFACE ${LIBC_INCLUDE_DIR})
+if(LIBC_CC_SUPPORTS_NOSTDLIBINC)
+  target_compile_options(libc-headers INTERFACE "-nostdlibinc")
+endif()
 
 foreach(target IN LISTS all_install_header_targets)
   get_target_property(header_file ${target} HEADER_FILE_PATH)
diff --git a/libc/lib/CMakeLists.txt b/libc/lib/CMakeLists.txt
index 37acf3950b460..7e18f35e7d60e 100644
--- a/libc/lib/CMakeLists.txt
+++ b/libc/lib/CMakeLists.txt
@@ -30,7 +30,10 @@ foreach(archive IN ZIP_LISTS
   ARCHIVE_OUTPUT_NAME ${archive_0}
   )
   if(LLVM_LIBC_FULL_BUILD)
-target_link_libraries(${archive_1} PUBLIC libc-headers)
+target_link_libraries(${archive_1} INTERFACE libc-headers)
+if(LIBC_CC_SUPPORTS_NOLIBC)
+  target_link_options(${archive_1} INTERFACE "-nolibc")
+endif()
 if(TARGET libc-startup)
   add_dependencies(${archive_1} libc-startup)
 endif()
diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index 190a97db9462f..5a568e95b239e 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -293,6 +293,7 @@ option(LIBCXX_ENABLE_THREADS "Build libc++ with support for 
threads." ON)
 option(LIBCXX_ENABLE_MONOTONIC_CLOCK
   "Build libc++ with support for a monotonic clock.
This option may only be set to OFF when LIBCXX_ENABLE_THREADS=OFF." ON)
+option(LIBCXX_USE_LLVM_LIBC "Build libc++ against LLVM libc." OFF)
 option(LIBCXX_HAS_MUSL_LIBC "Build libc++ with support for the Musl C library" 
OFF)
 option(LIBCXX_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread 
API" OFF)
 option(LIBCXX_HAS_WIN32_THREAD_API "Ignore auto-detection and force use of 
win32 thread API" OFF)
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index cd64fe91449c2..31a819932d521 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -1043

[clang] [Sema] Fix assertion error in Sema::FindInstantiatedDecl (PR #96509)

2024-07-18 Thread Alejandro Álvarez Ayllón via cfe-commits

https://github.com/alejandro-alvarez-sonarsource updated 
https://github.com/llvm/llvm-project/pull/96509

From 96b0c2c18c197a1ce03d31b01c14d1b18348e9ee Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alejandro=20=C3=81lvarez=20Ayll=C3=B3n?=
 
Date: Thu, 1 Jun 2023 16:30:54 +0200
Subject: [PATCH 1/6] [Sema] Fix crash in Sema::FindInstantiatedDecl

when looking for a template instantiation with a non-type
parameter of unknown type and with a default value.

This can happen when a template non-type parameter has a broken
expression that gets replaced by a `RecoveryExpr`.
---
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp   |  2 +-
 .../instantiate-template-broken-nontype-default.cpp  | 12 
 2 files changed, 13 insertions(+), 1 deletion(-)
 create mode 100644 
clang/test/SemaCXX/instantiate-template-broken-nontype-default.cpp

diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 0681520764d9a..999fec0ebb259 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -6300,7 +6300,7 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, 
NamedDecl *D,
   getTrivialTemplateArgumentLoc(UnpackedArg, QualType(), Loc));
   }
   QualType T = CheckTemplateIdType(TemplateName(TD), Loc, Args);
-  if (T.isNull())
+  if (T.isNull() || T->containsErrors())
 return nullptr;
   CXXRecordDecl *SubstRecord = T->getAsCXXRecordDecl();
 
diff --git a/clang/test/SemaCXX/instantiate-template-broken-nontype-default.cpp 
b/clang/test/SemaCXX/instantiate-template-broken-nontype-default.cpp
new file mode 100644
index 0..a644cc3d057cb
--- /dev/null
+++ b/clang/test/SemaCXX/instantiate-template-broken-nontype-default.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+
+constexpr Missing a = 0; // expected-error {{unknown type name 'Missing'}}
+
+template < typename T, Missing b = a> // expected-error {{unknown type name 
'Missing'}}
+class Klass { // expected-note {{candidate template ignored: could not match 
'Klass' against 'int'}}
+  Klass(T);   // expected-note {{candidate template ignored: substitution 
failure [with T = int, b = ()]}}
+};
+
+Klass foo{5}; // no-crash \
+ expected-error {{no viable constructor or deduction guide for 
deduction of template arguments of 'Klass'}}
+

From 9111797355ba860d0c6b62fde3a7b1e347a71dc6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alejandro=20=C3=81lvarez=20Ayll=C3=B3n?=
 
Date: Fri, 5 Jul 2024 15:12:47 +0200
Subject: [PATCH 2/6] Move the check to `CheckTemplateIdType()`

---
 clang/lib/Sema/SemaTemplate.cpp| 3 ++-
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index a032e3ec6f635..2ea18ec82b958 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -4700,7 +4700,8 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
 //   template struct A;
 CanonType = Context.getCanonicalTemplateSpecializationType(
 Name, CanonicalConverted);
-
+if (CanonType->containsErrors())
+  return QualType();
 // This might work out to be a current instantiation, in which
 // case the canonical type needs to be the InjectedClassNameType.
 //
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 999fec0ebb259..0681520764d9a 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -6300,7 +6300,7 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, 
NamedDecl *D,
   getTrivialTemplateArgumentLoc(UnpackedArg, QualType(), Loc));
   }
   QualType T = CheckTemplateIdType(TemplateName(TD), Loc, Args);
-  if (T.isNull() || T->containsErrors())
+  if (T.isNull())
 return nullptr;
   CXXRecordDecl *SubstRecord = T->getAsCXXRecordDecl();
 

From cf315c17ac5221e683af1260ef429c4b13fb5715 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alejandro=20=C3=81lvarez=20Ayll=C3=B3n?=
 
Date: Tue, 9 Jul 2024 11:21:44 +0200
Subject: [PATCH 3/6] Revert "Move the check to `CheckTemplateIdType()`"

This reverts commit 9111797355ba860d0c6b62fde3a7b1e347a71dc6.
---
 clang/lib/Sema/SemaTemplate.cpp| 3 +--
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 2ea18ec82b958..a032e3ec6f635 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -4700,8 +4700,7 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
 //   template struct A;
 CanonType = Context.getCanonicalTemplateSpecializationType(
   

[clang] [clang] Fix crash in concept deprecation (PR #98622)

2024-07-18 Thread via cfe-commits

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

I think this makes sense but please give @mizvekov  the day to review before 
landing

Thank you both for working on this

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


[clang] [clang] Fix crash in concept deprecation (PR #98622)

2024-07-18 Thread via cfe-commits

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


[clang] [clang] Fix crash in concept deprecation (PR #98622)

2024-07-18 Thread via cfe-commits


@@ -36,4 +36,11 @@ template 
 // expected-warning@-1 {{'C' is deprecated}}
 //   expected-note@#C {{'C' has been explicitly marked deprecated here}}
 void f();
+
+template 
+auto b() = delete; // #b
+
+decltype(b<0>()) x;
+// expected-error@-1 {{call to deleted function 'b'}}
+//   expected-note@#b {{candidate function [with $0 = 0] has been explicitly 
deleted}}

cor3ntin wrote:

Can you put that in a GH98164 namespace?

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


[clang] [clang] Fix crash in concept deprecation (PR #98622)

2024-07-18 Thread via cfe-commits


@@ -7416,10 +7416,11 @@ NamedDecl *Sema::ActOnVariableDeclarator(
 tryToFixVariablyModifiedVarType(TInfo, R, D.getIdentifierLoc(),
 /*DiagID=*/0);
 
-  if (const AutoType *AutoT = R->getAs())
-CheckConstrainedAuto(
-AutoT,
-TInfo->getTypeLoc().getContainedAutoTypeLoc().getConceptNameLoc());
+  if (const AutoType *AutoT = R->getAs()) {
+AutoTypeLoc Loc = TInfo->getTypeLoc().getContainedAutoTypeLoc();

cor3ntin wrote:

> If I correctly understand description of TypeLoc correctly, TypeLoc is 
> trailing data of Type SourceInfo. Is that correct?

Yes, the fact we have both and use both, inconsistently, which is not an ideal 
situation

> Calling DiagnoseUseOfDecl there seems too early. It triggers on declaration 
> of deprecated concept.

This is weird but I'm not sure we need further changes here

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


[clang] [clang] Extend lifetime analysis to support assignments for pointer-like objects. (PR #99032)

2024-07-18 Thread Haojian Wu via cfe-commits


@@ -34,6 +34,6 @@ struct basic_string {
 };
 }  // namespace std
 void test(const char* a) {
-  // verify we're emitting the `-Wdangling-assignment` warning.
+  // verify we're emitting the `-Wdangling-assignment-gsl` warning.
   a = std::basic_string().c_str(); // expected-warning {{object backing the 
pointer a will be destroyed at the end of the full-expression}}

hokein wrote:

The warning is triggered by the implicit `gsl::Owner` attribute on 
`std::basic_string`. Without this attribute, the warning would not be issued.

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


[clang] 3eba28d - [clang] Extend lifetime analysis to support assignments for pointer-like objects. (#99032)

2024-07-18 Thread via cfe-commits

Author: Haojian Wu
Date: 2024-07-18T10:02:35+02:00
New Revision: 3eba28d1fd3347a1658f68b63285148b0bb25fab

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

LOG: [clang] Extend lifetime analysis to support assignments for pointer-like 
objects. (#99032)

This is a follow-up patch to #96475 to detect dangling assignments for
C++ pointer-like objects (classes annotated with the
`[[gsl::Pointer]]`). Fixes #63310.

Similar to the behavior for built-in pointer types, if a temporary owner
(`[[gsl::Owner]]`) object is assigned to a pointer-like class object,
and this temporary object is destroyed at the end of the full assignment
expression, the assignee pointer is considered dangling. In such cases,
clang will emit a warning:

```
/tmp/t.cpp:7:20: warning: object backing the pointer my_string_view will be 
destroyed at the end of the full-expression [-Wdangling-assignment-gsl]
7 |   my_string_view = CreateString();
  |^~
1 warning generated.
```

This new warning is `-Wdangling-assignment-gsl`. It is initially
disabled, but I intend to enable it by default in clang 20.

I have initially tested this patch on our internal codebase, and it has
identified many use-after-free bugs, primarily related to `string_view`.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/CheckExprLifetime.cpp
clang/lib/Sema/SemaOverload.cpp
clang/test/Sema/warn-lifetime-analysis-nocfg-disabled.cpp
clang/test/Sema/warn-lifetime-analysis-nocfg.cpp
clang/test/SemaCXX/warn-dangling-local.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 469510d175887..e0e86af257a19 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -727,6 +727,9 @@ Improvements to Clang's diagnostics
 
 - Clang now diagnoses integer constant expressions that are folded to a 
constant value as an extension in more circumstances. Fixes #GH59863
 
+- Clang now diagnoses dangling assignments for pointer-like objects (annotated 
with `[[gsl::Pointer]]`) under `-Wdangling-assignment-gsl` (off by default)
+  Fixes #GH63310.
+
 Improvements to Clang's time-trace
 --
 

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index d7dba76a0fcf8..19c3f1e043349 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -451,6 +451,7 @@ def LogicalNotParentheses: 
DiagGroup<"logical-not-parentheses">;
 def ShiftOpParentheses: DiagGroup<"shift-op-parentheses">;
 def OverloadedShiftOpParentheses: DiagGroup<"overloaded-shift-op-parentheses">;
 def DanglingAssignment: DiagGroup<"dangling-assignment">;
+def DanglingAssignmentGsl : DiagGroup<"dangling-assignment-gsl">;
 def DanglingElse: DiagGroup<"dangling-else">;
 def DanglingField : DiagGroup<"dangling-field">;
 def DanglingInitializerList : DiagGroup<"dangling-initializer-list">;
@@ -459,6 +460,7 @@ def ReturnStackAddress : DiagGroup<"return-stack-address">;
 // Name of this warning in GCC
 def : DiagGroup<"return-local-addr", [ReturnStackAddress]>;
 def Dangling : DiagGroup<"dangling", [DanglingAssignment,
+  DanglingAssignmentGsl,
   DanglingField,
   DanglingInitializerList,
   DanglingGsl,

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b8a43b0a9fe8e..d60f32674ca3a 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10124,6 +10124,9 @@ def warn_dangling_lifetime_pointer : Warning<
   "object backing the pointer "
   "will be destroyed at the end of the full-expression">,
   InGroup;
+def warn_dangling_lifetime_pointer_assignment : Warning<"object backing the "
+  "pointer %0 will be destroyed at the end of the full-expression">,
+  InGroup, DefaultIgnore;
 def warn_new_dangling_initializer_list : Warning<
   "array backing "
   "%select{initializer list subobject of the allocated object|"

diff  --git a/clang/lib/Sema/CheckExprLifetime.cpp 
b/clang/lib/Sema/CheckExprLifetime.cpp
index 995e4cbadacfe..d9031256f235f 100644
--- a/clang/lib/Sema/CheckExprLifetime.cpp
+++ b/clang/lib/Sema/CheckExprLifetime.cpp
@@ -191,7 +191,8 @@ struct IndirectLocalPathEntry {
 TemporaryCopy,
 LambdaCaptureInit,
 GslReferenceInit,
-GslPointerInit
+GslPointerInit,
+GslPointerAssignment,
   } Kind;
   Expr *E;
   union {
@@ -337,7 +338,8 @@ s

[clang] [clang] Extend lifetime analysis to support assignments for pointer-like objects. (PR #99032)

2024-07-18 Thread Haojian Wu via cfe-commits

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


[clang] [llvm] Add source file name for template instantiations in -ftime-trace (PR #98320)

2024-07-18 Thread Ilya Biryukov via cfe-commits

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


[clang] [llvm] Add source file name for template instantiations in -ftime-trace (PR #98320)

2024-07-18 Thread Ilya Biryukov via cfe-commits

https://github.com/ilya-biryukov commented:

A few more suggestions, and happy to approve as soon as the question about 
source events gets resolved.

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


[clang] [llvm] Add source file name for template instantiations in -ftime-trace (PR #98320)

2024-07-18 Thread Ilya Biryukov via cfe-commits


@@ -3426,11 +3426,16 @@ Sema::InstantiateClass(SourceLocation 
PointOfInstantiation,
 return true;
 
   llvm::TimeTraceScope TimeScope("InstantiateClass", [&]() {
-std::string Name;
-llvm::raw_string_ostream OS(Name);
+llvm::TimeTraceMetadata M;
+llvm::raw_string_ostream OS(M.Detail);
 Instantiation->getNameForDiagnostic(OS, getPrintingPolicy(),
 /*Qualified=*/true);
-return Name;
+if (llvm::isTimeTraceVerbose()) {

ilya-biryukov wrote:

NIT: you might want to extract this into a function to share code.
Something like `RecordLocationInMetadata`.

It's not a big deal, though, with just few uses.

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


[clang] [llvm] Add source file name for template instantiations in -ftime-trace (PR #98320)

2024-07-18 Thread Ilya Biryukov via cfe-commits


@@ -38,14 +42,24 @@ std::string teardownProfiler() {
 
 // Returns true if code compiles successfully.
 // We only parse AST here. This is enough for constexpr evaluation.
-bool compileFromString(StringRef Code, StringRef Standard, StringRef FileName) 
{
+bool compileFromString(StringRef Code, StringRef Standard, StringRef File,
+   llvm::StringMap Headers = {}) {

ilya-biryukov wrote:

NIT: `StringMap` is a bit of a trap because it's way too easy to 
write something like `map.insert("foo.h", std::string("#include \n") + 
std::string("#include "))` and get into a state where the string is 
incorrect.
And we don't really need to avoid copies in tests for efficiency purposes, so 
I'd recommend just using `StringMap` instead to minimize the chance of 
getting potential use-after-free surprises in the future.

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


[clang] [llvm] Add source file name for template instantiations in -ftime-trace (PR #98320)

2024-07-18 Thread Ilya Biryukov via cfe-commits


@@ -3426,11 +3426,16 @@ Sema::InstantiateClass(SourceLocation 
PointOfInstantiation,
 return true;
 
   llvm::TimeTraceScope TimeScope("InstantiateClass", [&]() {
-std::string Name;
-llvm::raw_string_ostream OS(Name);
+llvm::TimeTraceMetadata M;
+llvm::raw_string_ostream OS(M.Detail);
 Instantiation->getNameForDiagnostic(OS, getPrintingPolicy(),
 /*Qualified=*/true);
-return Name;
+if (llvm::isTimeTraceVerbose()) {

ilya-biryukov wrote:

NIT: you might want to extract this into a function to share code.
Something like `RecordLocationInMetadata`.

It's not a big deal, though, with just few uses.

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


[clang] [llvm] Add source file name for template instantiations in -ftime-trace (PR #98320)

2024-07-18 Thread Utkarsh Saxena via cfe-commits


@@ -60,39 +74,65 @@ bool compileFromString(StringRef Code, StringRef Standard, 
StringRef FileName) {
   return Compiler.ExecuteAction(Action);
 }
 
+std::string GetMetadata(json::Object *Event) {
+  std::string Metadata = "";
+  if (json::Object *Args = Event->getObject("args")) {
+if (StringRef Detail = Args->getString("detail").value_or("");
+!Detail.empty())
+  Metadata += Detail.str();
+if (StringRef File = Args->getString("filename").value_or("");
+!File.empty())
+  Metadata += ", " + File.str();
+  }
+  return Metadata;
+}
+
 // Returns pretty-printed trace graph.
 std::string buildTraceGraph(StringRef Json) {
   struct EventRecord {
 int64_t TimestampBegin;
 int64_t TimestampEnd;
-StringRef Name;
-StringRef Detail;
+std::string Name;
+std::string Metadata;
   };
   std::vector Events;
 
   // Parse `EventRecord`s from JSON dump.
   Expected Root = json::parse(Json);
   if (!Root)
 return "";
+  std::stack SourceEvents;
   for (json::Value &TraceEventValue :
*Root->getAsObject()->getArray("traceEvents")) {
 json::Object *TraceEventObj = TraceEventValue.getAsObject();
 
 int64_t TimestampBegin = TraceEventObj->getInteger("ts").value_or(0);
 int64_t TimestampEnd =
 TimestampBegin + TraceEventObj->getInteger("dur").value_or(0);
-StringRef Name = TraceEventObj->getString("name").value_or("");
-StringRef Detail = "";
-if (json::Object *Args = TraceEventObj->getObject("args"))
-  Detail = Args->getString("detail").value_or("");
+std::string Name = TraceEventObj->getString("name").value_or("").str();
+std::string Metadata = GetMetadata(TraceEventObj);
+
+if (Name == "Source") {

usx95 wrote:

As discussed offline, these are due to new headers which are added to the 
tests. 
Decided to ignore Source events as they are not 100% accurate because of being 
async.

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


[clang] [libc] [libcxx] [libc][libcxx] Support for building libc++ against LLVM libc (PR #99287)

2024-07-18 Thread Petr Hosek via cfe-commits


@@ -293,6 +293,7 @@ option(LIBCXX_ENABLE_THREADS "Build libc++ with support for 
threads." ON)
 option(LIBCXX_ENABLE_MONOTONIC_CLOCK
   "Build libc++ with support for a monotonic clock.
This option may only be set to OFF when LIBCXX_ENABLE_THREADS=OFF." ON)
+option(LIBCXX_USE_LLVM_LIBC "Build libc++ against LLVM libc." OFF)

petrhosek wrote:

I introduced `LIBCXX_LIBC` which currently accepts `system` or `llvm-libc`. 
`system` is currently no-op but that can be expanded later. In the future we 
may also want to introduce additional options e.g. `musl` replacing the 
existing `LIBCXX_HAS_MUSL_LIBC` option but I'd prefer to do it in a separate 
change. 

I'm not sure if it's better to set the `-nostdlibinc` and `-nolibc` on the libc 
side (as interface flags on the targets) or on the libc++ side (as interface 
flags on the proxy targets), I can see an argument for doing either way. Right 
now I set those on the libc side which has the upside of not needing to 
duplicate those flags in libunwind and libc++abi which should eventually 
support LLVM libc as well.

In the future we'll probably want to move `HandleLibC.cmake` to the top-level 
`cmake/Modules` directory so they can be shared by libc++abi and libunwind, 
although we'll need to rethink the target and variables names because the 
`LIBCXX_` and `libcxx-` prefix is undesirable (maybe we can use `RUNTIMES_` and 
`runtimes-`)?

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


[clang] [llvm] Add source file name for template instantiations in -ftime-trace (PR #98320)

2024-07-18 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/98320

>From 03cc5fbebaf0c0c737e9304b8b3310ab4908fcaa Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 10 Jul 2024 13:52:46 +
Subject: [PATCH 01/12] Add an option to add source file info to -ftime-trace

---
 clang/include/clang/Driver/Options.td  | 4 
 clang/include/clang/Frontend/FrontendOptions.h | 3 +++
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 2 ++
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 2 ++
 4 files changed, 11 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index be7c3b60c20f1..c15f1b57bafc9 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3989,6 +3989,10 @@ def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, 
Group,
   HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory 
which will contain the JSON file">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
   MarshallingInfoString>;
+def ftime_trace_add_filename : Flag<["-"], "ftime-trace-add-filename">, 
Group,
+  HelpText<"Adds filename to event details wherever supported. Eg: For 
template instantiation A, details would include A@source_file.h.">,
+  Visibility<[ClangOption, CLOption, DXCOption]>;
+  MarshallingInfoString>;
 def fproc_stat_report : Joined<["-"], "fproc-stat-report">, Group,
   HelpText<"Print subprocess statistics">;
 def fproc_stat_report_EQ : Joined<["-"], "fproc-stat-report=">, Group,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Frontend/FrontendOptions.h
index 5e5034fe01eb5..019a6737f8129 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -583,6 +583,9 @@ class FrontendOptions {
   /// Path which stores the output files for -ftime-trace
   std::string TimeTracePath;
 
+  /// Adds filename to event details wherever supported
+  bool TimeTraceAddFilename = false;
+
   /// Output Path for module output file.
   std::string ModuleOutputPath;
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index a7bc6749c5852..f0fa7fd427906 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3430,6 +3430,8 @@ Sema::InstantiateClass(SourceLocation 
PointOfInstantiation,
 llvm::raw_string_ostream OS(Name);
 Instantiation->getNameForDiagnostic(OS, getPrintingPolicy(),
 /*Qualified=*/true);
+if (llvm::timeTraceAddFilename())
+  OS << "@" << SourceMgr.getFilename(Instantiation->getLocation());
 return Name;
   });
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 88f6af80cbc55..ba55db4117c34 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4966,6 +4966,8 @@ void Sema::InstantiateFunctionDefinition(SourceLocation 
PointOfInstantiation,
 llvm::raw_string_ostream OS(Name);
 Function->getNameForDiagnostic(OS, getPrintingPolicy(),
/*Qualified=*/true);
+if (llvm::timeTraceAddFilename())
+  OS << "@" << SourceMgr.getFilename(Function->getLocation());
 return Name;
   });
 

>From ae991f8c88c21a0872a5fa63219b3cb9b2787d9a Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 10 Jul 2024 15:52:55 +
Subject: [PATCH 02/12] Add tests

---
 clang/include/clang/Driver/Options.td  |  4 
 clang/include/clang/Frontend/FrontendOptions.h |  3 ---
 clang/lib/Sema/SemaTemplateInstantiate.cpp |  3 +--
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp |  3 +--
 clang/test/Driver/ftime-trace-sections.py  | 16 +++-
 5 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c15f1b57bafc9..be7c3b60c20f1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3989,10 +3989,6 @@ def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, 
Group,
   HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory 
which will contain the JSON file">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
   MarshallingInfoString>;
-def ftime_trace_add_filename : Flag<["-"], "ftime-trace-add-filename">, 
Group,
-  HelpText<"Adds filename to event details wherever supported. Eg: For 
template instantiation A, details would include A@source_file.h.">,
-  Visibility<[ClangOption, CLOption, DXCOption]>;
-  MarshallingInfoString>;
 def fproc_stat_report : Joined<["-"], "fproc-stat-report">, Group,
   HelpText<"Print subprocess statistics">;
 def fproc_stat_report_EQ : Joined<["-"], "fproc-stat-report=">, Group,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Fronte

[clang] [clang] Fix crash in concept deprecation (PR #98622)

2024-07-18 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll updated 
https://github.com/llvm/llvm-project/pull/98622

>From 5310764fb4044bcd4229434e80b64870c4b4ee8c Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Fri, 12 Jul 2024 15:12:37 +0300
Subject: [PATCH 1/4] [clang] Fix crash in concept deprecation

Apparently we can't assume that `AutoTypeLoc` from `AutoType` is always valid.

Fixes #98164
---
 clang/lib/Sema/SemaDecl.cpp   |  9 +
 clang/lib/Sema/SemaType.cpp   | 10 +-
 clang/test/SemaCXX/cxx-deprecated.cpp |  7 +++
 3 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 66eeaa8e6f777..7e4328cc176a2 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -7416,10 +7416,11 @@ NamedDecl *Sema::ActOnVariableDeclarator(
 tryToFixVariablyModifiedVarType(TInfo, R, D.getIdentifierLoc(),
 /*DiagID=*/0);
 
-  if (const AutoType *AutoT = R->getAs())
-CheckConstrainedAuto(
-AutoT,
-TInfo->getTypeLoc().getContainedAutoTypeLoc().getConceptNameLoc());
+  if (const AutoType *AutoT = R->getAs()) {
+AutoTypeLoc Loc = TInfo->getTypeLoc().getContainedAutoTypeLoc();
+CheckConstrainedAuto(AutoT,
+ Loc ? Loc.getConceptNameLoc() : SourceLocation());
+  }
 
   bool IsMemberSpecialization = false;
   bool IsVariableTemplateSpecialization = false;
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 714409f927a8d..887d1b395d475 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -6308,11 +6308,11 @@ TypeResult Sema::ActOnTypeName(Declarator &D) {
 CheckExtraCXXDefaultArguments(D);
   }
 
-  if (const AutoType *AutoT = T->getAs())
-CheckConstrainedAuto(
-AutoT,
-TInfo->getTypeLoc().getContainedAutoTypeLoc().getConceptNameLoc());
-
+  if (const AutoType *AutoT = T->getAs()) {
+AutoTypeLoc Loc = TInfo->getTypeLoc().getContainedAutoTypeLoc();
+CheckConstrainedAuto(AutoT,
+ Loc ? Loc.getConceptNameLoc() : SourceLocation());
+  }
   return CreateParsedType(T, TInfo);
 }
 
diff --git a/clang/test/SemaCXX/cxx-deprecated.cpp 
b/clang/test/SemaCXX/cxx-deprecated.cpp
index 81eb07608300d..870930f54af72 100644
--- a/clang/test/SemaCXX/cxx-deprecated.cpp
+++ b/clang/test/SemaCXX/cxx-deprecated.cpp
@@ -36,4 +36,11 @@ template 
 // expected-warning@-1 {{'C' is deprecated}}
 //   expected-note@#C {{'C' has been explicitly marked deprecated here}}
 void f();
+
+template 
+auto b() = delete; // #b
+
+decltype(b<0>()) x;
+// expected-error@-1 {{call to deleted function 'b'}}
+//   expected-note@#b {{candidate function [with $0 = 0] has been explicitly 
deleted}}
 } // namespace cxx20_concept

>From 126057f778254ecc071a24fed93c0cbf28f4f0de Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Wed, 17 Jul 2024 17:58:07 +0300
Subject: [PATCH 2/4] Apply suggestion from @mizvekov

---
 clang/lib/Sema/SemaDecl.cpp| 7 +++
 clang/test/CXX/drs/cwg24xx.cpp | 9 +
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 7e4328cc176a2..c2a6377ee19d1 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -7416,10 +7416,9 @@ NamedDecl *Sema::ActOnVariableDeclarator(
 tryToFixVariablyModifiedVarType(TInfo, R, D.getIdentifierLoc(),
 /*DiagID=*/0);
 
-  if (const AutoType *AutoT = R->getAs()) {
-AutoTypeLoc Loc = TInfo->getTypeLoc().getContainedAutoTypeLoc();
-CheckConstrainedAuto(AutoT,
- Loc ? Loc.getConceptNameLoc() : SourceLocation());
+  if (AutoTypeLoc TL = TInfo->getTypeLoc().getContainedAutoTypeLoc()) {
+const AutoType *AT = TL.getTypePtr();
+CheckConstrainedAuto(AT, TL.getConceptNameLoc());
   }
 
   bool IsMemberSpecialization = false;
diff --git a/clang/test/CXX/drs/cwg24xx.cpp b/clang/test/CXX/drs/cwg24xx.cpp
index 16b8ec07fc50f..00b6bb5a865df 100644
--- a/clang/test/CXX/drs/cwg24xx.cpp
+++ b/clang/test/CXX/drs/cwg24xx.cpp
@@ -82,6 +82,15 @@ auto h() -> C auto {
   C auto foo = T();
   // expected-warning@-1 {{'C' is deprecated}}
   //   expected-note@#cwg2428-C {{'C' has been explicitly marked deprecated 
here}}
+  C auto *bar = T();
+  // expected-warning@-1 {{'C' is deprecated}}
+  //   expected-note@#cwg2428-C {{'C' has been explicitly marked deprecated 
here}}
+  C auto &baz = T();
+  // expected-warning@-1 {{'C' is deprecated}}
+  //   expected-note@#cwg2428-C {{'C' has been explicitly marked deprecated 
here}}
+  C auto &&quux = T();
+  // expected-warning@-1 {{'C' is deprecated}}
+  //   expected-note@#cwg2428-C {{'C' has been explicitly marked deprecated 
here}}
   return foo;
 }
 #endif

>From 270b9fc1f1cbb089e4e208c172fcde3881df8720 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Wed, 17 Jul 2024 22:00:23 +0300
Subject: [PATCH 3/4] Fix `Ac

[clang] [llvm] Add source file name for template instantiations in -ftime-trace (PR #98320)

2024-07-18 Thread Utkarsh Saxena via cfe-commits


@@ -38,14 +42,24 @@ std::string teardownProfiler() {
 
 // Returns true if code compiles successfully.
 // We only parse AST here. This is enough for constexpr evaluation.
-bool compileFromString(StringRef Code, StringRef Standard, StringRef FileName) 
{
+bool compileFromString(StringRef Code, StringRef Standard, StringRef File,
+   llvm::StringMap Headers = {}) {

usx95 wrote:

Done.

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


[clang] [clang] Fix crash in concept deprecation (PR #98622)

2024-07-18 Thread Vlad Serebrennikov via cfe-commits


@@ -36,4 +36,11 @@ template 
 // expected-warning@-1 {{'C' is deprecated}}
 //   expected-note@#C {{'C' has been explicitly marked deprecated here}}
 void f();
+
+template 
+auto b() = delete; // #b
+
+decltype(b<0>()) x;
+// expected-error@-1 {{call to deleted function 'b'}}
+//   expected-note@#b {{candidate function [with $0 = 0] has been explicitly 
deleted}}

Endilll wrote:

Fixed

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


[clang] [Clang] make SVE types known to device targets too (PR #99446)

2024-07-18 Thread Emanuele Rocca via cfe-commits

https://github.com/ema created https://github.com/llvm/llvm-project/pull/99446

For the purpose of preprocessing and declarations in header files, ensure clang 
accepts SVE types for both device and host targets.

>From 2f7b2bbd9d2db29534dc354cfa9ada5c29c26b3f Mon Sep 17 00:00:00 2001
From: Emanuele Rocca 
Date: Wed, 17 Jul 2024 16:03:27 +0200
Subject: [PATCH] [Clang] make SVE types known to device targets too

For the purpose of preprocessing and declarations in header files, ensure clang
accepts SVE types for both device and host targets.

Co-authored-by: Sander De Smalen 
---
 clang/lib/AST/ASTContext.cpp | 3 ++-
 clang/lib/Sema/Sema.cpp  | 4 +++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index ccbb4baad68af..c87b8deca9da6 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1384,7 +1384,8 @@ void ASTContext::InitBuiltinTypes(const TargetInfo 
&Target,
 #include "clang/Basic/OpenCLExtensionTypes.def"
   }
 
-  if (Target.hasAArch64SVETypes()) {
+  if (Target.hasAArch64SVETypes() ||
+  (AuxTarget && AuxTarget->hasAArch64SVETypes())) {
 #define SVE_TYPE(Name, Id, SingletonId) \
 InitBuiltinType(SingletonId, BuiltinType::Id);
 #include "clang/Basic/AArch64SVEACLETypes.def"
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index d6228718d53ae..733090a68c990 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -469,7 +469,9 @@ void Sema::Initialize() {
 #include "clang/Basic/OpenCLExtensionTypes.def"
   }
 
-  if (Context.getTargetInfo().hasAArch64SVETypes()) {
+  if (Context.getTargetInfo().hasAArch64SVETypes() ||
+  (Context.getAuxTargetInfo() &&
+   Context.getAuxTargetInfo()->hasAArch64SVETypes())) {
 #define SVE_TYPE(Name, Id, SingletonId) \
 addImplicitTypedef(Name, Context.SingletonId);
 #include "clang/Basic/AArch64SVEACLETypes.def"

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


[clang] [Clang] make SVE types known to device targets too (PR #99446)

2024-07-18 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


[clang] [Clang] make SVE types known to device targets too (PR #99446)

2024-07-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Emanuele Rocca (ema)


Changes

For the purpose of preprocessing and declarations in header files, ensure clang 
accepts SVE types for both device and host targets.

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


2 Files Affected:

- (modified) clang/lib/AST/ASTContext.cpp (+2-1) 
- (modified) clang/lib/Sema/Sema.cpp (+3-1) 


``diff
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index ccbb4baad68af..c87b8deca9da6 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1384,7 +1384,8 @@ void ASTContext::InitBuiltinTypes(const TargetInfo 
&Target,
 #include "clang/Basic/OpenCLExtensionTypes.def"
   }
 
-  if (Target.hasAArch64SVETypes()) {
+  if (Target.hasAArch64SVETypes() ||
+  (AuxTarget && AuxTarget->hasAArch64SVETypes())) {
 #define SVE_TYPE(Name, Id, SingletonId) \
 InitBuiltinType(SingletonId, BuiltinType::Id);
 #include "clang/Basic/AArch64SVEACLETypes.def"
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index d6228718d53ae..733090a68c990 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -469,7 +469,9 @@ void Sema::Initialize() {
 #include "clang/Basic/OpenCLExtensionTypes.def"
   }
 
-  if (Context.getTargetInfo().hasAArch64SVETypes()) {
+  if (Context.getTargetInfo().hasAArch64SVETypes() ||
+  (Context.getAuxTargetInfo() &&
+   Context.getAuxTargetInfo()->hasAArch64SVETypes())) {
 #define SVE_TYPE(Name, Id, SingletonId) \
 addImplicitTypedef(Name, Context.SingletonId);
 #include "clang/Basic/AArch64SVEACLETypes.def"

``




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


[clang] [llvm] Add source file name for template instantiations in -ftime-trace (PR #98320)

2024-07-18 Thread Utkarsh Saxena via cfe-commits


@@ -3426,11 +3426,16 @@ Sema::InstantiateClass(SourceLocation 
PointOfInstantiation,
 return true;
 
   llvm::TimeTraceScope TimeScope("InstantiateClass", [&]() {
-std::string Name;
-llvm::raw_string_ostream OS(Name);
+llvm::TimeTraceMetadata M;
+llvm::raw_string_ostream OS(M.Detail);
 Instantiation->getNameForDiagnostic(OS, getPrintingPolicy(),
 /*Qualified=*/true);
-return Name;
+if (llvm::isTimeTraceVerbose()) {

usx95 wrote:

Resolving duplicate comment.

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


[clang] [Clang][AMDGPU] Add builtins for instrinsic `llvm.amdgcn.raw.ptr.buffer.load` (PR #99258)

2024-07-18 Thread Matt Arsenault via cfe-commits


@@ -155,6 +155,12 @@ BUILTIN(__builtin_amdgcn_raw_buffer_store_b32, "viQbiiIi", 
"n")
 BUILTIN(__builtin_amdgcn_raw_buffer_store_b64, "vV2iQbiiIi", "n")
 BUILTIN(__builtin_amdgcn_raw_buffer_store_b96, "vV3iQbiiIi", "n")
 BUILTIN(__builtin_amdgcn_raw_buffer_store_b128, "vV4iQbiiIi", "n")
+BUILTIN(__builtin_amdgcn_raw_buffer_load_b8, "cQbiiIi", "n")
+BUILTIN(__builtin_amdgcn_raw_buffer_load_b16, "sQbiiIi", "n")
+BUILTIN(__builtin_amdgcn_raw_buffer_load_b32, "iQbiiIi", "n")
+BUILTIN(__builtin_amdgcn_raw_buffer_load_b64, "V2iQbiiIi", "n")
+BUILTIN(__builtin_amdgcn_raw_buffer_load_b96, "V3iQbiiIi", "n")

arsenm wrote:

These should be returning unsigned results? The stores also should have been 
unsigned 

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


[clang] [llvm] [PAC][Driver] Support `pauthtest` ABI for AArch64 Linux triples (PR #97237)

2024-07-18 Thread Daniil Kovalev via cfe-commits

https://github.com/kovdan01 updated 
https://github.com/llvm/llvm-project/pull/97237

>From 3b4b1b1739b810d758e68f30c48b648963cff740 Mon Sep 17 00:00:00 2001
From: Daniil Kovalev 
Date: Mon, 1 Jul 2024 00:50:21 +0300
Subject: [PATCH 1/8] [PAC][Driver] Implement `-mbranch-protection=pauthabi`
 option

Enable the following ptrauth flags when `pauthabi` is passed as branch
protection:

- `intrinsics`;
- `calls`;
- `returns`;
- `auth-traps`;
- `vtable-pointer-address-discrimination`;
- `vtable-pointer-type-discrimination`;
- `init-fini`.

Co-authored-by: Anatoly Trosinenko 
---
 clang/lib/Driver/ToolChains/Clang.cpp | 38 +++
 clang/test/Driver/aarch64-ptrauth.c   | 36 ++
 .../llvm/TargetParser/ARMTargetParserCommon.h |  1 +
 .../TargetParser/ARMTargetParserCommon.cpp|  6 ++-
 4 files changed, 72 insertions(+), 9 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 1b7cc82ea816e..4ed1ece22b7aa 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1484,6 +1484,39 @@ void AddUnalignedAccessWarning(ArgStringList &CmdArgs) {
 }
 }
 
+static void handlePAuthABIOption(const ArgList &DriverArgs,
+ ArgStringList &CC1Args, const Driver &D) {
+  if (!DriverArgs.hasArg(options::OPT_fptrauth_intrinsics,
+ options::OPT_fno_ptrauth_intrinsics))
+CC1Args.push_back("-fptrauth-intrinsics");
+
+  if (!DriverArgs.hasArg(options::OPT_fptrauth_calls,
+ options::OPT_fno_ptrauth_calls))
+CC1Args.push_back("-fptrauth-calls");
+
+  if (!DriverArgs.hasArg(options::OPT_fptrauth_returns,
+ options::OPT_fno_ptrauth_returns))
+CC1Args.push_back("-fptrauth-returns");
+
+  if (!DriverArgs.hasArg(options::OPT_fptrauth_auth_traps,
+ options::OPT_fno_ptrauth_auth_traps))
+CC1Args.push_back("-fptrauth-auth-traps");
+
+  if (!DriverArgs.hasArg(
+  options::OPT_fptrauth_vtable_pointer_address_discrimination,
+  options::OPT_fno_ptrauth_vtable_pointer_address_discrimination))
+CC1Args.push_back("-fptrauth-vtable-pointer-address-discrimination");
+
+  if (!DriverArgs.hasArg(
+  options::OPT_fptrauth_vtable_pointer_type_discrimination,
+  options::OPT_fno_ptrauth_vtable_pointer_type_discrimination))
+CC1Args.push_back("-fptrauth-vtable-pointer-type-discrimination");
+
+  if (!DriverArgs.hasArg(options::OPT_fptrauth_init_fini,
+ options::OPT_fno_ptrauth_init_fini))
+CC1Args.push_back("-fptrauth-init-fini");
+}
+
 static void CollectARMPACBTIOptions(const ToolChain &TC, const ArgList &Args,
 ArgStringList &CmdArgs, bool isAArch64) {
   const Arg *A = isAArch64
@@ -1537,11 +1570,16 @@ static void CollectARMPACBTIOptions(const ToolChain 
&TC, const ArgList &Args,
 if (!isAArch64 && PBP.Key == "b_key")
   D.Diag(diag::warn_unsupported_branch_protection)
   << "b-key" << A->getAsString(Args);
+if (!isAArch64 && PBP.HasPauthABI)
+  D.Diag(diag::warn_unsupported_branch_protection)
+  << "pauthabi" << A->getAsString(Args);
 Scope = PBP.Scope;
 Key = PBP.Key;
 BranchProtectionPAuthLR = PBP.BranchProtectionPAuthLR;
 IndirectBranches = PBP.BranchTargetEnforcement;
 GuardedControlStack = PBP.GuardedControlStack;
+if (isAArch64 && PBP.HasPauthABI)
+  handlePAuthABIOption(Args, CmdArgs, D);
   }
 
   CmdArgs.push_back(
diff --git a/clang/test/Driver/aarch64-ptrauth.c 
b/clang/test/Driver/aarch64-ptrauth.c
index fa0125f4b22a9..dc63545a47a86 100644
--- a/clang/test/Driver/aarch64-ptrauth.c
+++ b/clang/test/Driver/aarch64-ptrauth.c
@@ -13,13 +13,33 @@
 // RUN:   %s 2>&1 | FileCheck %s --check-prefix=ALL
 // ALL: "-cc1"{{.*}} "-fptrauth-intrinsics" "-fptrauth-calls" 
"-fptrauth-returns" "-fptrauth-auth-traps" 
"-fptrauth-vtable-pointer-address-discrimination" 
"-fptrauth-vtable-pointer-type-discrimination" "-fptrauth-init-fini"
 
+// RUN: %clang -### -c --target=aarch64 -mbranch-protection=pauthabi %s 2>&1 | 
\
+// RUN:   FileCheck %s --check-prefix=PAUTHABI1
+// PAUTHABI1: "-cc1"{{.*}} "-fptrauth-intrinsics" "-fptrauth-calls" 
"-fptrauth-returns" "-fptrauth-auth-traps" 
"-fptrauth-vtable-pointer-address-discrimination" 
"-fptrauth-vtable-pointer-type-discrimination" "-fptrauth-init-fini"
+
+// RUN: %clang -### -c --target=aarch64 -mbranch-protection=pauthabi 
-fno-ptrauth-intrinsics \
+// RUN:   -fno-ptrauth-calls -fno-ptrauth-returns -fno-ptrauth-auth-traps \
+// RUN:   -fno-ptrauth-vtable-pointer-address-discrimination 
-fno-ptrauth-vtable-pointer-type-discrimination \
+// RUN:   -fno-ptrauth-init-fini %s 2>&1 | FileCheck %s 
--check-prefix=PAUTHABI2
+// PAUTHABI2-NOT: "-fptrauth-intrinsics"
+// PAUTHABI2-NOT: "-fptrauth-calls"
+// PAUTHABI2-NOT: "-fptrauth-returns"
+// PAUTHABI2-NOT: "-fptrauth-auth-traps"
+//

[clang] [Clang][AMDGPU] Add builtins for instrinsic `llvm.amdgcn.raw.ptr.buffer.load` (PR #99258)

2024-07-18 Thread Matt Arsenault via cfe-commits


@@ -155,6 +155,12 @@ BUILTIN(__builtin_amdgcn_raw_buffer_store_b32, "viQbiiIi", 
"n")
 BUILTIN(__builtin_amdgcn_raw_buffer_store_b64, "vV2iQbiiIi", "n")
 BUILTIN(__builtin_amdgcn_raw_buffer_store_b96, "vV3iQbiiIi", "n")
 BUILTIN(__builtin_amdgcn_raw_buffer_store_b128, "vV4iQbiiIi", "n")
+BUILTIN(__builtin_amdgcn_raw_buffer_load_b8, "cQbiiIi", "n")
+BUILTIN(__builtin_amdgcn_raw_buffer_load_b16, "sQbiiIi", "n")
+BUILTIN(__builtin_amdgcn_raw_buffer_load_b32, "iQbiiIi", "n")
+BUILTIN(__builtin_amdgcn_raw_buffer_load_b64, "V2iQbiiIi", "n")
+BUILTIN(__builtin_amdgcn_raw_buffer_load_b96, "V3iQbiiIi", "n")

arsenm wrote:

For the 8/16-bit cases, we could also return the 32-bit result they really 
return and insert the sext/zext we fold into the instruction during codegen. 
Not sure if that would be better 

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


[clang] [llvm] [PAC][Driver] Support `pauthtest` ABI for AArch64 Linux triples (PR #97237)

2024-07-18 Thread Daniil Kovalev via cfe-commits


@@ -1546,16 +1581,28 @@ static void CollectARMPACBTIOptions(const ToolChain 
&TC, const ArgList &Args,
 
   CmdArgs.push_back(
   Args.MakeArgString(Twine("-msign-return-address=") + Scope));
-  if (Scope != "none")
+  if (Scope != "none") {
+if (Triple.getEnvironment() == llvm::Triple::PAuthTest)
+  D.Diag(diag::err_drv_unsupported_opt_for_target)
+  << A->getAsString(Args) << Triple.getTriple();
 CmdArgs.push_back(
 Args.MakeArgString(Twine("-msign-return-address-key=") + Key));
-  if (BranchProtectionPAuthLR)
+  }
+  if (BranchProtectionPAuthLR) {
+if (Triple.getEnvironment() == llvm::Triple::PAuthTest)
+  D.Diag(diag::err_drv_unsupported_opt_for_target)
+  << A->getAsString(Args) << Triple.getTriple();
 CmdArgs.push_back(
 Args.MakeArgString(Twine("-mbranch-protection-pauth-lr")));
+  }
   if (IndirectBranches)
 CmdArgs.push_back("-mbranch-target-enforce");
-  if (GuardedControlStack)
+  if (GuardedControlStack) {

kovdan01 wrote:

Added a comment, thanks! See 4f3da9e51338aec21b8bfe8dd08598507edcea38

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


[clang] [Clang][AMDGPU] Add builtins for instrinsic `llvm.amdgcn.raw.ptr.buffer.load` (PR #99258)

2024-07-18 Thread Matt Arsenault via cfe-commits


@@ -19177,6 +19177,42 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
   case AMDGPU::BI__builtin_amdgcn_raw_buffer_store_b128:
 return emitBuiltinWithOneOverloadedType<5>(
 *this, E, Intrinsic::amdgcn_raw_ptr_buffer_store);
+  case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b8:
+  case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b16:
+  case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b32:
+  case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b64:
+  case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b96:
+  case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b128: {
+llvm::Type *RetTy = nullptr;
+switch (BuiltinID) {
+case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b8:
+  RetTy = Int8Ty;
+  break;
+case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b16:
+  RetTy = Int16Ty;
+  break;
+case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b32:
+  RetTy = Int32Ty;
+  break;
+case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b64:
+  RetTy = llvm::FixedVectorType::get(Int32Ty, /*NumElements=*/2);
+  break;
+case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b96:
+  RetTy = llvm::FixedVectorType::get(Int32Ty, /*NumElements=*/3);
+  break;
+case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b128:
+  RetTy = llvm::FixedVectorType::get(Int32Ty, /*NumElements=*/4);
+  break;
+}
+SmallVector Args;
+Args.push_back(EmitScalarExpr(E->getArg(0)));
+Args.push_back(EmitScalarExpr(E->getArg(1)));
+Args.push_back(EmitScalarExpr(E->getArg(2)));
+Args.push_back(EmitScalarExpr(E->getArg(3)));

arsenm wrote:

Can do this in initializer list 

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


[clang] [clang] Emit bad shift warnings (PR #70307)

2024-07-18 Thread Alexander Kornienko via cfe-commits

alexfh wrote:

Just to confirm: is this the intentional outcome of this patch? 
https://gcc.godbolt.org/z/Kf9YK1qM3
```
enum {
a = 1<<12,
b = (-1)<<13
};
```
```
:3:9: error: expression is not an integral constant expression
3 | b = (-1)<<13
  | ^~~~
:3:13: note: left shift of negative value -1
3 | b = (-1)<<13
  | ^
```

Though technically, it's UB before C++20, the diagnostic - "expression is not 
an integral constant expression" - doesn't sound helpful (how is it not 
constant or not integral?). And what's worse, is that it's an error rather than 
a warning that can be disabled.

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


[clang] [Clang] Implement P3034R1 Module Declarations Shouldn’t be Macros (PR #90574)

2024-07-18 Thread via cfe-commits

https://github.com/cor3ntin commented:

I think once you address the few remaining comments from @ChuanqiXu9, this can 
be landed. 
The general. I am glad we were able to get rid of some of the convoluted state 
machines

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


[clang] [Clang] Implement P3034R1 Module Declarations Shouldn’t be Macros (PR #90574)

2024-07-18 Thread via cfe-commits


@@ -1121,6 +1153,149 @@ void 
Preprocessor::CollectPpImportSuffix(SmallVectorImpl &Toks) {
   }
 }
 
+std::string ModuleNameInfo::getFlatName() const {
+  std::string FlatModuleName;
+  for (auto &Tok : getTokens()) {
+switch (Tok.getKind()) {
+case tok::identifier:
+  FlatModuleName += Tok.getIdentifierInfo()->getName();
+  break;
+case tok::period:
+  FlatModuleName += '.';
+  break;
+case tok::colon:
+  FlatModuleName += ':';
+  break;
+default:
+  llvm_unreachable("Unexpected token in module name");
+}
+  }
+  return FlatModuleName;
+}
+
+void ModuleNameInfo::getModuleIdPath(
+SmallVectorImpl> &Path) const {
+  return getModuleIdPath(getTokens(), Path);
+}
+
+void ModuleNameInfo::getModuleIdPath(
+ArrayRef ModuleName,
+SmallVectorImpl> &Path) {
+  for (const auto &Tok : ModuleName) {
+if (Tok.is(tok::identifier))
+  Path.push_back(
+  std::make_pair(Tok.getIdentifierInfo(), Tok.getLocation()));
+  }
+}
+
+/// Lex a module name or a partition name.
+///
+/// module-name:
+///   module-name-qualifier[opt] identifier
+///
+/// partition-name: [C++20]
+///   : module-name-qualifier[opt] identifier
+///
+/// module-name-qualifier
+///   module-name-qualifier[opt] identifier .
+bool Preprocessor::LexModuleName(Token &Result, bool IsImport) {
+  bool ExpectsIdentifier = true, IsLexingPartition = false;
+  SmallVector ModuleName;
+  std::optional ColonTokIndex;
+  auto LexNextToken = [&](Token &Tok) {
+if (IsImport)
+  Lex(Tok);
+else
+  LexUnexpandedToken(Tok);
+  };
+
+  while (true) {
+LexNextToken(Result);
+if (ExpectsIdentifier && Result.is(tok::identifier)) {
+  auto *MI = getMacroInfo(Result.getIdentifierInfo());
+  if (getLangOpts().CPlusPlusModules && !IsImport && MI &&
+  MI->isObjectLike()) {
+Diag(Result, diag::err_module_decl_cannot_be_macros)
+<< Result.getLocation() << IsLexingPartition
+<< Result.getIdentifierInfo();
+  }
+  ModuleName.push_back(Result);
+  ExpectsIdentifier = false;
+  continue;
+}
+
+if (!ExpectsIdentifier && Result.is(tok::period)) {
+  ModuleName.push_back(Result);
+  ExpectsIdentifier = true;
+  continue;
+}
+
+// Module partition only allowed in C++20 Modules.
+if (getLangOpts().CPlusPlusModules && Result.is(tok::colon)) {
+  // Handle the form like: import :P;
+  // If the token after ':' is not an identifier, this is a invalid module
+  // name.
+  if (ModuleName.empty()) {
+Token Tmp;
+LexNextToken(Tmp);
+EnterToken(Tmp, /*IsReiject=*/false);
+// A private-module-fragment, module :private;
+if (!IsImport && Tmp.is(tok::kw_private))
+  return true;
+// import :N;
+if (IsImport && Tmp.isNot(tok::identifier))
+  return false;
+  } else if (!ExpectsIdentifier) {
+ExpectsIdentifier = true;
+  }
+  IsLexingPartition = true;
+  ColonTokIndex = ModuleName.size();
+  ModuleName.push_back(Result);
+  continue;
+}
+
+// [cpp.module]/p2: where the pp-tokens (if any) shall not begin with a (
+// preprocessing token [...]
+//
+// We only emit diagnostic in the preprocessor, and in the parser we skip
+// invalid tokens and recover from errors.
+if (getLangOpts().CPlusPlusModules && !ExpectsIdentifier &&
+Result.is(tok::l_paren))
+  Diag(Result, diag::err_unxepected_paren_in_module_decl)
+  << IsLexingPartition;
+break;
+  }
+
+  // Put the last token back to stream, it's not a valid part of module name.
+  // We lexed it unexpanded but it might be a valid macro expansion
+  Result.clearFlag(Token::DisableExpand);
+  auto ToksCopy = std::make_unique(1);
+  *ToksCopy.get() = Result;
+  EnterTokenStream(std::move(ToksCopy), 1,
+   /*DisableMacroExpansion=*/false,
+   /*IsReinject=*/false);
+
+  if (ModuleName.empty())
+return false;
+  Result.startToken();
+  Result.setKind(tok::annot_module_name);
+  Result.setLocation(ModuleName.front().getLocation());
+  Result.setAnnotationEndLoc(ModuleName.back().getLocation());
+  auto AnnotToks = ArrayRef(ModuleName).copy(getPreprocessorAllocator());
+  ArrayRef ModuleNameToks, PartitionNameToks;
+  if (ColonTokIndex.has_value()) {
+ModuleNameToks =
+ArrayRef(AnnotToks.begin(), AnnotToks.begin() + *ColonTokIndex);
+PartitionNameToks =
+ArrayRef(AnnotToks.begin() + *ColonTokIndex, AnnotToks.end());
+  } else {
+ModuleNameToks = AnnotToks;
+  }

cor3ntin wrote:

I think you can simplify that by first  setting `ColonTokIndex` to 
`AnnotToks.size()` when it does not have a value.
Maybe we want to move the logic of creating the two slices to the constructor 
of `ModuleNameInfo` 
ie have a `ModuleNameInfo(Tok, OptionalColonIndex)` constructor 

https://git

[clang] [Clang] Implement P3034R1 Module Declarations Shouldn’t be Macros (PR #90574)

2024-07-18 Thread via cfe-commits

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


[clang] [Clang] Implement P3034R1 Module Declarations Shouldn’t be Macros (PR #90574)

2024-07-18 Thread via cfe-commits


@@ -3071,6 +3073,45 @@ struct EmbedAnnotationData {
 /// Registry of pragma handlers added by plugins
 using PragmaHandlerRegistry = llvm::Registry;
 
+/// Module/Partition name token sequance.
+///
+/// module-name:
+///   module-name-qualifier[opt] identifier
+///
+/// module-name-qualifier
+///   module-name-qualifier[opt] identifier .
+class ModuleNameInfo {
+  friend class Preprocessor;
+  ArrayRef ModuleName;
+  ArrayRef PartitionName;
+
+  ModuleNameInfo(ArrayRef Module, ArrayRef Partition)
+  : ModuleName(Module), PartitionName(Partition) {}
+
+public:
+  ArrayRef getTokens() const {
+if (ModuleName.empty())
+  return PartitionName;
+if (PartitionName.empty())
+  return ModuleName;
+return ArrayRef(ModuleName.begin(), PartitionName.end());

cor3ntin wrote:

This is subtle.
It relies on the two source array being contiguous in memory
https://github.com/llvm/llvm-project/pull/90574/files#diff-e33e22703774cdd6fbed70f2c691485f818c168f0a2bb1d394b87a1c540b2df6R1285

We at least need a comment + `assert(Module.end() == Partition.begin());`

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


[clang] [Clang] Implement P3034R1 Module Declarations Shouldn’t be Macros (PR #90574)

2024-07-18 Thread via cfe-commits


@@ -1002,6 +1002,7 @@ PRAGMA_ANNOTATION(pragma_riscv)
 ANNOTATION(module_include)
 ANNOTATION(module_begin)
 ANNOTATION(module_end)
+ANNOTATION(module_name)

cor3ntin wrote:

```suggestion

// Annotations for c++ named modules
ANNOTATION(module_name)
```

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


[clang-tools-extra] 1ce8989 - [clang-tidy] Fix false in unnecessary-value-param inside templates (#98488)

2024-07-18 Thread via cfe-commits

Author: Dmitry Polukhin
Date: 2024-07-18T09:55:36+01:00
New Revision: 1ce89899ad33a0d2976859d8d278dba4342cbb6b

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

LOG: [clang-tidy] Fix false in unnecessary-value-param inside templates (#98488)

Summary:
If callExpr is type dependent, there is no way to analyze individual
arguments until template specialization. Before this diff only calls
with dependent callees were skipped so unnecessary-value-param was
processing arguments that had non-dependent type that gave false
positives because the call was not fully resolved till specialization.
So now instead of checking type dependent callee, the whole expression
will be checked for type dependent.

Test Plan: check-clang-tools

Added: 


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

clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param.cpp
clang/lib/Analysis/ExprMutationAnalyzer.cpp

Removed: 




diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 697b514ae1572..a23483e6df6d2 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -450,7 +450,8 @@ Changes in existing checks
   ` check
   detecting more cases for template functions including lambdas with ``auto``.
   E.g., ``std::sort(a.begin(), a.end(), [](auto x, auto y) { return a > b; 
});``
-  will be detected for expensive to copy types.
+  will be detected for expensive to copy types. Fixed false positives for
+  dependent call expressions.
 
 - Improved :doc:`readability-avoid-return-with-void-value
   ` check by adding

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param.cpp
index 0dffaefa213a4..7c7ae43698929 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param.cpp
@@ -2,6 +2,31 @@
 
 // CHECK-FIXES: #include 
 
+namespace std {
+template 
+struct remove_reference;
+
+template 
+struct remove_reference {
+  typedef _Tp type;
+};
+
+template 
+struct remove_reference<_Tp &> {
+  typedef _Tp type;
+};
+
+template 
+struct remove_reference<_Tp &&> {
+  typedef _Tp type;
+};
+
+template 
+constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) {
+  return static_cast::type &&>(__t);
+}
+} // namespace std
+
 struct ExpensiveToCopyType {
   const ExpensiveToCopyType & constReference() const {
 return *this;
@@ -357,3 +382,12 @@ void fun() {
   ExpensiveToCopyType E;
   NegativeUsingConstructor S(E);
 }
+
+struct B {
+  static void bar(ExpensiveMovableType a, ExpensiveMovableType b);
+};
+
+template 
+void NegativeCallWithDependentAndNondependentArgs(ExpensiveMovableType a, T b) 
{
+B::bar(std::move(a), b);
+}

diff  --git a/clang/lib/Analysis/ExprMutationAnalyzer.cpp 
b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
index 3b3782fa1db9a..6d726ae44104e 100644
--- a/clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -404,25 +404,24 @@ ExprMutationAnalyzer::Analyzer::findDirectMutation(const 
Expr *Exp) {
 memberExpr(hasObjectExpression(canResolveToExpr(Exp,
   nonConstReferenceType());
   const auto NotInstantiated = unless(hasDeclaration(isInstantiated()));
-  const auto TypeDependentCallee =
-  callee(expr(anyOf(unresolvedLookupExpr(), unresolvedMemberExpr(),
-cxxDependentScopeMemberExpr(),
-hasType(templateTypeParmType()), isTypeDependent(;
-
-  const auto AsNonConstRefArg = anyOf(
-  callExpr(NonConstRefParam, NotInstantiated),
-  cxxConstructExpr(NonConstRefParam, NotInstantiated),
-  callExpr(TypeDependentCallee, hasAnyArgument(canResolveToExpr(Exp))),
-  cxxUnresolvedConstructExpr(hasAnyArgument(canResolveToExpr(Exp))),
-  // Previous False Positive in the following Code:
-  // `template  void f() { int i = 42; new Type(i); }`
-  // Where the constructor of `Type` takes its argument as reference.
-  // The AST does not resolve in a `cxxConstructExpr` because it is
-  // type-dependent.
-  parenListExpr(hasDescendant(expr(canResolveToExpr(Exp,
-  // If the initializer is for a reference type, there is no cast for
-  // the variable. Values are cast to RValue first.
-  initListExpr(hasAnyInit(expr(canResolveToExpr(Exp);
+
+  const auto AsNonConstRefArg =
+  anyOf(callExpr(NonConstRefParam, NotInstantiated),
+cxxConstructExpr(NonConstRefParam, NotInstantiated),
+// If the call is type-dependent, we can't properly proc

[clang] [clang-tools-extra] [clang-tidy] Fix false in unnecessary-value-param inside templates (PR #98488)

2024-07-18 Thread Dmitry Polukhin via cfe-commits

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


[libclc] libclc: increase fp16 support (PR #98149)

2024-07-18 Thread Fraser Cormack via cfe-commits

frasercrmck wrote:

> Also, just leave that thought here: A next step might be to use `native` 
> functions instead (when available). They should provide enough precision for 
> half, but be more performance. Also as the accuracy is undefined for those 
> functions, maybe it should be an opt-in option in the libclc (clspv would 
> enable it for sure).

Yeah, it would definitely need to be opt-in. Ideally we'd also implement the 
`half` builtins properly so they're not going through `float` and are as fast 
as they can be, but then _also_ allow native functions if users so wish. But 
that involves maths, haha.

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


[libclc] libclc: increase fp16 support (PR #98149)

2024-07-18 Thread Fraser Cormack via cfe-commits

frasercrmck wrote:

@rjodinchr I was about to merge and noticed your email is hidden. I just wanted 
to check with you whether you want to make it public, as per the discussion 
https://discourse.llvm.org/t/hidden-emails-on-github-should-we-do-something-about-it/74223/67.
 AFAICT there's still no official policy, but thought I'd check.

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


[clang] [Parser][ObjC] Add -Wobjc-prefix-length warning option. (PR #97597)

2024-07-18 Thread Alastair Houghton via cfe-commits

https://github.com/al45tair updated 
https://github.com/llvm/llvm-project/pull/97597

>From c11624370bf5615c7902993052435b92ae50b41b Mon Sep 17 00:00:00 2001
From: Alastair Houghton 
Date: Wed, 3 Jul 2024 17:00:51 +0100
Subject: [PATCH 1/8] [Parser][ObjC] Add -Wobjc-prefix-length warning option.

This lets clang generate warnings automatically if it sees Objective-C
names that don't have the correct prefix length.

rdar://131055157
---
 clang/include/clang/Basic/DiagnosticGroups.td |  1 +
 .../clang/Basic/DiagnosticParseKinds.td   |  7 ++
 clang/include/clang/Basic/LangOptions.def |  2 +
 clang/include/clang/Driver/Options.td |  7 ++
 clang/include/clang/Parse/Parser.h|  1 +
 clang/lib/Driver/ToolChains/Clang.cpp |  1 +
 clang/lib/Parse/ParseObjc.cpp | 65 +++
 clang/test/Parser/objc-prefixes.m | 62 ++
 8 files changed, 146 insertions(+)
 create mode 100644 clang/test/Parser/objc-prefixes.m

diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 2241f8481484e..fc09603bf3e1e 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -612,6 +612,7 @@ def ObjCPointerIntrospect : 
DiagGroup<"deprecated-objc-pointer-introspection", [
 def ObjCMultipleMethodNames : DiagGroup<"objc-multiple-method-names">;
 def ObjCFlexibleArray : DiagGroup<"objc-flexible-array">;
 def ObjCBoxing : DiagGroup<"objc-boxing">;
+def ObjCPrefixLength : DiagGroup<"objc-prefix-length">;
 def CompletionHandler : DiagGroup<"completion-handler">;
 def CalledOnceParameter : DiagGroup<"called-once-parameter", 
[CompletionHandler]>;
 def OpenCLUnsupportedRGBA: DiagGroup<"opencl-unsupported-rgba">;
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 12aab09f28556..7e26bd13f9c7b 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -563,6 +563,13 @@ def err_declaration_does_not_declare_param : Error<
   "declaration does not declare a parameter">;
 def err_no_matching_param : Error<"parameter named %0 is missing">;
 
+def warn_objc_unprefixed_class_name : Warning<
+  "un-prefixed Objective-C class name">,
+  InGroup;
+def warn_objc_unprefixed_protocol_name : Warning<
+  "un-prefixed Objective-C protocol name">,
+  InGroup;
+
 /// Objective-C++ parser diagnostics
 def err_expected_token_instead_of_objcxx_keyword : Error<
   "expected %0; %1 is a keyword in Objective-C++">;
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 5ad9c1f24b7c5..7debdc0cdf75a 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -353,6 +353,8 @@ LANGOPT(ObjCAutoRefCount , 1, 0, "Objective-C automated 
reference counting")
 LANGOPT(ObjCWeakRuntime , 1, 0, "__weak support in the ARC runtime")
 LANGOPT(ObjCWeak, 1, 0, "Objective-C __weak in ARC and MRC files")
 LANGOPT(ObjCSubscriptingLegacyRuntime , 1, 0, "Subscripting support in 
legacy ObjectiveC runtime")
+BENIGN_LANGOPT(ObjCPrefixLength, 32, 0,
+   "if non-zero, warn about Objective-C classes or protocols with 
names that do not have a prefix of the specified length.")
 BENIGN_LANGOPT(CompatibilityQualifiedIdBlockParamTypeChecking, 1, 0,
"compatibility mode for type checking block parameters "
"involving qualified id types")
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2400b193d4d38..57344b75cebda 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3419,6 +3419,13 @@ defm objc_exceptions : BoolFOption<"objc-exceptions",
   PosFlag,
   NegFlag>;
+def Wobjc_prefix_length_EQ:
+  Joined<["-"], "Wobjc-prefix-length=">,
+  Visibility<[ClangOption, CC1Option]>,
+  MetaVarName<"">,
+  HelpText<"Warn if Objective-C class or protocol names do not start with a 
prefix of the specified length">,
+  MarshallingInfoInt>;
+
 defm application_extension : BoolFOption<"application-extension",
   LangOpts<"AppExt">, DefaultFalse,
   PosFlaggetBeginLoc(), diag::note_objc_container_start) << (int)ock;
 }
 
+/// An Objective-C public name (a class name or protocol name) is
+/// expected to have a prefix as all names are in a single global
+/// namespace.
+///
+/// If the -Wobjc-prefix-length is set to N, the name must start
+/// with N+1 capital letters, which must be followed by a character
+/// that is not a capital letter.
+///
+/// For instance, for N set to 2, the following are valid:
+///
+///  NSString
+///  NSArray
+///
+///  but these are not:
+///
+///  MyString
+///  NSKString
+///  NSnotAString
+///
+/// We make a special exception for NSCF things when the prefix is set
+//

[clang] [llvm] Support for assume directive : Parse & AST modules (PR #97535)

2024-07-18 Thread via cfe-commits

https://github.com/SunilKuravinakop updated 
https://github.com/llvm/llvm-project/pull/97535

>From a331d2343a43a9ca2030ef07a25ca93ff26a5778 Mon Sep 17 00:00:00 2001
From: Sunil Kuravinakop 
Date: Mon, 1 Jul 2024 03:29:45 -0500
Subject: [PATCH 1/8] Support for "#pragma omp assume" Directive in Parse and
 AST.

  Changes to be committed:
modified:   clang/include/clang/Parse/Parser.h
modified:   clang/include/clang/Sema/Sema.h
modified:   clang/lib/Basic/OpenMPKinds.cpp
modified:   clang/lib/Parse/ParseOpenMP.cpp
modified:   clang/lib/Sema/SemaOpenMP.cpp
modified:   llvm/include/llvm/Frontend/OpenMP/OMP.td
---
 clang/include/clang/Parse/Parser.h   |  4 +-
 clang/include/clang/Sema/Sema.h  |  3 ++
 clang/lib/Basic/OpenMPKinds.cpp  |  3 ++
 clang/lib/Parse/ParseOpenMP.cpp  | 33 +++-
 clang/lib/Sema/SemaOpenMP.cpp| 67 +++-
 llvm/include/llvm/Frontend/OpenMP/OMP.td |  3 ++
 6 files changed, 108 insertions(+), 5 deletions(-)

diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 5950dd74cfe83..7568c053eb77f 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -3380,8 +3380,8 @@ class Parser : public CodeCompletionHandler {
  SourceLocation Loc);
 
   /// Parse 'omp [begin] assume[s]' directive.
-  void ParseOpenMPAssumesDirective(OpenMPDirectiveKind DKind,
-   SourceLocation Loc);
+  StmtResult ParseOpenMPAssumesDirective(OpenMPDirectiveKind DKind,
+ SourceLocation Loc);
 
   /// Parse 'omp end assumes' directive.
   void ParseOpenMPEndAssumesDirective(SourceLocation Loc);
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index c6035445e9019..652df4a16e62d 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -12966,6 +12966,9 @@ class Sema final : public SemaBase {
   /// Act on \p D, a function definition inside of an `omp [begin/end] 
assumes`.
   void ActOnFinishedFunctionDefinitionInOpenMPAssumeScope(Decl *D);
 
+  /// Act on \p D, Associated statements of `omp assume`.
+  StmtResult ActOnFinishedStatementInOpenMPAssumeScope(Stmt *);
+
   /// Can we exit an OpenMP declare variant scope at the moment.
   bool isInOpenMPDeclareVariantScope() const {
 return !OMPDeclareVariantScopes.empty();
diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp
index b3e9affbb3e58..97a0dd508c0a5 100644
--- a/clang/lib/Basic/OpenMPKinds.cpp
+++ b/clang/lib/Basic/OpenMPKinds.cpp
@@ -721,6 +721,9 @@ void clang::getOpenMPCaptureRegions(
   case OMPD_parallel_loop:
 CaptureRegions.push_back(OMPD_parallel);
 break;
+  case OMPD_assume:
+CaptureRegions.push_back(OMPD_assume);
+break;
   case OMPD_target_teams:
   case OMPD_target_teams_distribute:
   case OMPD_target_teams_distribute_simd:
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 814126e321d3b..3d1a9564897af 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -1673,8 +1673,8 @@ void Parser::ParseOpenMPClauses(OpenMPDirectiveKind DKind,
 /// 'no_openmp_routines'
 /// 'no_parallelism'
 ///
-void Parser::ParseOpenMPAssumesDirective(OpenMPDirectiveKind DKind,
- SourceLocation Loc) {
+StmtResult Parser::ParseOpenMPAssumesDirective(OpenMPDirectiveKind DKind,
+   SourceLocation Loc) {
   SmallVector Assumptions;
   bool SkippedClauses = false;
 
@@ -1750,7 +1750,33 @@ void 
Parser::ParseOpenMPAssumesDirective(OpenMPDirectiveKind DKind,
 Assumptions.push_back(Assumption);
   }
 
+  StmtResult AssociatedStmt;
+
+  // Fix the scope for assume.
+  if (DKind == llvm::omp::Directive::OMPD_assume) {
+
+if (Tok.getKind() == clang::tok::annot_pragma_openmp_end)
+  ConsumeAnyToken();
+
+DeclarationNameInfo DirName;
+Actions.StartOpenMPDSABlock(DKind, DirName, Actions.getCurScope(), Loc);
+  }
+
   Actions.ActOnOpenMPAssumesDirective(Loc, DKind, Assumptions, SkippedClauses);
+
+  if (DKind == llvm::omp::Directive::OMPD_assume) {
+
+AssociatedStmt = ParseStatement();
+AssociatedStmt =
+
Actions.ActOnFinishedStatementInOpenMPAssumeScope(AssociatedStmt.get());
+
+// End the scope for assume.
+ParseOpenMPEndAssumesDirective(Loc);
+Actions.EndOpenMPDSABlock(nullptr);
+if (Tok.getKind() == clang::tok::annot_pragma_openmp_end)
+  ConsumeAnyToken();
+  }
+  return AssociatedStmt;
 }
 
 void Parser::ParseOpenMPEndAssumesDirective(SourceLocation Loc) {
@@ -2759,6 +2785,9 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
 }
 break;
   }
+  case OMPD_assume:
+Directive = ParseOpenMPAssumesDirective(DKind, ConsumeToken());
+break;
   case OMPD_flush:
   case 

[clang] [llvm] Remove 3dnow from X86TargetParser. (PR #99352)

2024-07-18 Thread Simon Pilgrim via cfe-commits

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

LGTM - cheers

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


[clang] [clang] Fix static analyzer concerns in #embed code (PR #99331)

2024-07-18 Thread Mariya Podchishchaeva via cfe-commits


@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -std=c23 %s -E -verify
+// RUN: %clang_cc1 -std=c23 %s -E -verify --embed-dir=%S --embed-dir=%S/Inputs
 
+#embed 

Fznamznon wrote:

Makes sense.

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


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

2024-07-18 Thread Piyou Chen via cfe-commits


@@ -0,0 +1,8 @@
+// RUN: not %clang_cc1 -triple riscv64 -target-feature +i -emit-llvm -o - %s 
2>&1 | FileCheck %s --check-prefix=CHECK-UNSUPPORT-OS
+
+// CHECK-UNSUPPORT-OS: error: target_clones is currently only supported on 
Linux

BeMg wrote:

Added.

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


[libclc] libclc: increase fp16 support (PR #98149)

2024-07-18 Thread Romaric Jodin via cfe-commits

rjodinchr wrote:

> @rjodinchr I was about to merge and noticed your email is hidden. I just 
> wanted to check with you whether you want to make it public, as per the 
> discussion 
> https://discourse.llvm.org/t/hidden-emails-on-github-should-we-do-something-about-it/74223/67.
>  AFAICT there's still no official policy, but thought I'd check.

I was not aware my email was private. It should be public now. Thanks

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


[libclc] 6838c7a - [libclc] Revise IDE folder structure (#89746)

2024-07-18 Thread via cfe-commits

Author: Michael Kruse
Date: 2024-07-18T12:40:55+02:00
New Revision: 6838c7afb2d2fa5eb642a4b5922ae55d97f7b344

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

LOG: [libclc] Revise IDE folder structure (#89746)

Reviewers of #89153 suggested to break up the patch into per-subproject
patches. This is the libclc part. See #89153 for the entire series and
motivation.

Update the folder titles for targets in the monorepository that have not
seen taken care of for some time. These are the folders that targets are
organized in Visual Studio and XCode
(`set_property(TARGET  PROPERTY FOLDER "")`)
when using the respective CMake's IDE generator.

 * Ensure that every target is in a folder
 * Use a folder hierarchy with each LLVM subproject as a top-level folder
 * Use consistent folder names between subprojects
 * When using target-creating functions from AddLLVM.cmake, automatically
deduce the folder. This reduces the number of
`set_property`/`set_target_property`, but are still necessary when
`add_custom_target`, `add_executable`, `add_library`, etc. are used. A
LLVM_SUBPROJECT_TITLE definition is used for that in each subproject's
root CMakeLists.txt.

Added: 


Modified: 
libclc/CMakeLists.txt
libclc/cmake/modules/AddLibclc.cmake

Removed: 




diff  --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 4f5625ff94916..02bb859ae8590 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.20.0)
 if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
   project(libclc VERSION 0.2.0 LANGUAGES CXX C)
 endif()
+set(LLVM_SUBPROJECT_TITLE "libclc")
 
 set(CMAKE_CXX_STANDARD 17)
 
@@ -230,12 +231,14 @@ add_custom_command(
   COMMAND ${Python3_EXECUTABLE} ${script_loc} > convert.cl
   DEPENDS ${script_loc} )
 add_custom_target( "generate_convert.cl" DEPENDS convert.cl )
+set_target_properties( "generate_convert.cl" PROPERTIES FOLDER 
"libclc/Sourcegenning" )
 
 add_custom_command(
   OUTPUT clspv-convert.cl
   COMMAND ${Python3_EXECUTABLE} ${script_loc} --clspv > clspv-convert.cl
   DEPENDS ${script_loc} )
 add_custom_target( "clspv-generate_convert.cl" DEPENDS clspv-convert.cl )
+set_target_properties( "clspv-generate_convert.cl" PROPERTIES FOLDER 
"libclc/Sourcegenning" )
 
 enable_testing()
 
@@ -388,6 +391,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
 add_custom_target( ${builtins_comp_lib_tgt}
   DEPENDS ${bytecode_files}
 )
+set_target_properties( ${builtins_comp_lib_tgt} PROPERTIES FOLDER 
"libclc/Device IR/Comp" )
 
 set( builtins_link_lib_tgt builtins.link.${arch_suffix} )
 link_bc(
@@ -405,6 +409,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
 DEPENDS ${builtins_link_lib} ${builtins_link_lib_tgt}
   )
   add_custom_target( "prepare-${spv_suffix}" ALL DEPENDS "${spv_suffix}" )
+  set_target_properties( "prepare-${spv_suffix}" PROPERTIES FOLDER 
"libclc/Device IR/Prepare" )
   install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${spv_suffix}
  DESTINATION "${CMAKE_INSTALL_DATADIR}/clc" )
 else()
@@ -421,6 +426,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
   )
   set_target_properties( ${builtins_opt_lib_tgt}
 PROPERTIES TARGET_FILE ${builtins_opt_lib_tgt}.bc
+   FOLDER "libclc/Device IR/Opt"
   )
 
   set( builtins_opt_lib 
$ )
@@ -431,6 +437,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
 COMMAND ${prepare_builtins_exe} -o ${obj_suffix} ${builtins_opt_lib}
 DEPENDS ${builtins_opt_lib} ${builtins_opt_lib_tgt} 
${prepare_builtins_target} )
   add_custom_target( prepare-${obj_suffix} ALL DEPENDS ${obj_suffix} )
+  set_target_properties( "prepare-${obj_suffix}" PROPERTIES FOLDER 
"libclc/Device IR/Prepare" )
 
   # nvptx-- targets don't include workitem builtins
   if( NOT clang_triple MATCHES ".*ptx.*--$" )
@@ -445,6 +452,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
 add_custom_target( ${alias_suffix} ALL
   COMMAND ${CMAKE_COMMAND} -E create_symlink ${obj_suffix} 
${alias_suffix}
   DEPENDS prepare-${obj_suffix} )
+set_target_properties( "${alias_suffix}" PROPERTIES FOLDER 
"libclc/Device IR/Aliases" )
 install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${alias_suffix} DESTINATION 
"${CMAKE_INSTALL_DATADIR}/clc" )
   endforeach( a )
 endif()

diff  --git a/libclc/cmake/modules/AddLibclc.cmake 
b/libclc/cmake/modules/AddLibclc.cmake
index 68b33ede6c369..839815d8cc6ff 100644
--- a/libclc/cmake/modules/AddLibclc.cmake
+++ b/libclc/cmake/modules/AddLibclc.cmake
@@ -112,7 +112,10 @@ function(link_bc)
   )
 
   add_custom_target( ${ARG_TARGET} ALL DEPENDS ${ARG_TARGET}.bc )
-  set_target_properties( ${ARG_TARGET} PROPERTIES TARGET_FILE ${ARG_TARGET}.bc 
)
+  set_target_pr

[libclc] [llvm] [libclc] Revise IDE folder structure (PR #89746)

2024-07-18 Thread Michael Kruse via cfe-commits

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


[clang] Improve stack usage to increase recursive initialization depth (PR #88546)

2024-07-18 Thread via cfe-commits

cor3ntin wrote:

@AaronBallman ping


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


[clang] [Clang] make SVE types known to device targets too (PR #99446)

2024-07-18 Thread Emanuele Rocca via cfe-commits

https://github.com/ema updated https://github.com/llvm/llvm-project/pull/99446

>From 3c11c7fb055c114084577fb51fb87f928a0cc31c Mon Sep 17 00:00:00 2001
From: Emanuele Rocca 
Date: Wed, 17 Jul 2024 16:03:27 +0200
Subject: [PATCH] [Clang] make SVE types known to device targets too

For the purpose of preprocessing and declarations in header files, ensure clang
accepts SVE types for both device and host targets.

Co-authored-by: Sander De Smalen 
---
 clang/lib/AST/ASTContext.cpp   | 3 ++-
 clang/lib/Sema/Sema.cpp| 4 +++-
 clang/test/PCH/aarch64-sve-types.c | 2 ++
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index ccbb4baad68af..c87b8deca9da6 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1384,7 +1384,8 @@ void ASTContext::InitBuiltinTypes(const TargetInfo 
&Target,
 #include "clang/Basic/OpenCLExtensionTypes.def"
   }
 
-  if (Target.hasAArch64SVETypes()) {
+  if (Target.hasAArch64SVETypes() ||
+  (AuxTarget && AuxTarget->hasAArch64SVETypes())) {
 #define SVE_TYPE(Name, Id, SingletonId) \
 InitBuiltinType(SingletonId, BuiltinType::Id);
 #include "clang/Basic/AArch64SVEACLETypes.def"
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index d6228718d53ae..733090a68c990 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -469,7 +469,9 @@ void Sema::Initialize() {
 #include "clang/Basic/OpenCLExtensionTypes.def"
   }
 
-  if (Context.getTargetInfo().hasAArch64SVETypes()) {
+  if (Context.getTargetInfo().hasAArch64SVETypes() ||
+  (Context.getAuxTargetInfo() &&
+   Context.getAuxTargetInfo()->hasAArch64SVETypes())) {
 #define SVE_TYPE(Name, Id, SingletonId) \
 addImplicitTypedef(Name, Context.SingletonId);
 #include "clang/Basic/AArch64SVEACLETypes.def"
diff --git a/clang/test/PCH/aarch64-sve-types.c 
b/clang/test/PCH/aarch64-sve-types.c
index 4c4549af0b6d6..249618c3a9708 100644
--- a/clang/test/PCH/aarch64-sve-types.c
+++ b/clang/test/PCH/aarch64-sve-types.c
@@ -1,6 +1,8 @@
 // RUN: %clang_cc1 -triple aarch64-linux-gnu -emit-pch -o %t %s
 // RUN: %clang_cc1 -triple aarch64-linux-gnu -include-pch %t \
 // RUN:   -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -aux-triple aarch64-linux-gnu \
+// RUN:   -x hip-cpp-output -emit-pch -o %t %s
 
 // expected-no-diagnostics
 

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


[libclc] libclc: increase fp16 support (PR #98149)

2024-07-18 Thread Fraser Cormack via cfe-commits

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


[libclc] 7e6a739 - libclc: increase fp16 support (#98149)

2024-07-18 Thread via cfe-commits

Author: Romaric Jodin
Date: 2024-07-18T12:00:41+01:00
New Revision: 7e6a73959ae97b1f9476a90290a492ba90cb950d

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

LOG: libclc: increase fp16 support (#98149)

Increase fp16 support to allow clspv to continue to be OpenCL compliant
following the update of the OpenCL-CTS adding more testing on math
functions and conversions with half.

Math functions are implemented by upscaling to fp32 and using the fp32
implementation. It garantees the accuracy required for half-precision
float-point by the CTS.

Added: 


Modified: 
libclc/clspv/lib/math/fma.cl
libclc/generic/include/clc/convert.h
libclc/generic/include/math/clc_ldexp.h
libclc/generic/lib/clcmacro.h
libclc/generic/lib/gen_convert.py
libclc/generic/lib/math/acos.cl
libclc/generic/lib/math/acosh.cl
libclc/generic/lib/math/acospi.cl
libclc/generic/lib/math/asinh.cl
libclc/generic/lib/math/atan.cl
libclc/generic/lib/math/atan2.cl
libclc/generic/lib/math/atan2pi.cl
libclc/generic/lib/math/atanh.cl
libclc/generic/lib/math/atanpi.cl
libclc/generic/lib/math/cbrt.cl
libclc/generic/lib/math/clc_ldexp.cl
libclc/generic/lib/math/clc_pown.cl
libclc/generic/lib/math/clc_remquo.cl
libclc/generic/lib/math/clc_rootn.cl
libclc/generic/lib/math/clc_sw_binary.inc
libclc/generic/lib/math/clc_sw_unary.inc
libclc/generic/lib/math/cos.cl
libclc/generic/lib/math/cosh.cl
libclc/generic/lib/math/cospi.cl
libclc/generic/lib/math/exp.cl
libclc/generic/lib/math/expm1.cl
libclc/generic/lib/math/fdim.inc
libclc/generic/lib/math/frexp.inc
libclc/generic/lib/math/ilogb.cl
libclc/generic/lib/math/lgamma.cl
libclc/generic/lib/math/lgamma_r.cl
libclc/generic/lib/math/lgamma_r.inc
libclc/generic/lib/math/log10.cl
libclc/generic/lib/math/log1p.cl
libclc/generic/lib/math/log2.cl
libclc/generic/lib/math/log_base.h
libclc/generic/lib/math/logb.cl
libclc/generic/lib/math/pown.inc
libclc/generic/lib/math/remquo.inc
libclc/generic/lib/math/rootn.inc
libclc/generic/lib/math/sin.cl
libclc/generic/lib/math/sincos.inc
libclc/generic/lib/math/sinh.cl
libclc/generic/lib/math/sinpi.cl
libclc/generic/lib/math/tanh.cl

Removed: 




diff  --git a/libclc/clspv/lib/math/fma.cl b/libclc/clspv/lib/math/fma.cl
index 4f2806933eda9..3ffca28bd3bef 100644
--- a/libclc/clspv/lib/math/fma.cl
+++ b/libclc/clspv/lib/math/fma.cl
@@ -269,3 +269,14 @@ _CLC_DEF _CLC_OVERLOAD float fma(float a, float b, float 
c) {
   ((uint)st_fma.mantissa.lo & 0x7f));
 }
 _CLC_TERNARY_VECTORIZE(_CLC_DEF _CLC_OVERLOAD, float, fma, float, float, float)
+
+#ifdef cl_khr_fp16
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+_CLC_DEF _CLC_OVERLOAD half fma(half a, half b, half c) {
+  return (half)mad((float)a, (float)b, (float)c);
+}
+_CLC_TERNARY_VECTORIZE(_CLC_DEF _CLC_OVERLOAD, half, fma, half, half, half)
+
+#endif

diff  --git a/libclc/generic/include/clc/convert.h 
b/libclc/generic/include/clc/convert.h
index f0ba796864d4d..db7bb0402491e 100644
--- a/libclc/generic/include/clc/convert.h
+++ b/libclc/generic/include/clc/convert.h
@@ -20,10 +20,19 @@
   _CLC_VECTOR_CONVERT_DECL(FROM_TYPE, ulong, SUFFIX) \
   _CLC_VECTOR_CONVERT_DECL(FROM_TYPE, float, SUFFIX)
 
-#ifdef cl_khr_fp64
+#if defined(cl_khr_fp64) && defined(cl_khr_fp16)
+#define _CLC_VECTOR_CONVERT_FROM(FROM_TYPE, SUFFIX)
\
+  _CLC_VECTOR_CONVERT_FROM1(FROM_TYPE, SUFFIX) 
\
+  _CLC_VECTOR_CONVERT_DECL(FROM_TYPE, double, SUFFIX)  
\
+  _CLC_VECTOR_CONVERT_DECL(FROM_TYPE, half, SUFFIX)
+#elif defined(cl_khr_fp64)
 #define _CLC_VECTOR_CONVERT_FROM(FROM_TYPE, SUFFIX) \
   _CLC_VECTOR_CONVERT_FROM1(FROM_TYPE, SUFFIX) \
   _CLC_VECTOR_CONVERT_DECL(FROM_TYPE, double, SUFFIX)
+#elif defined(cl_khr_fp16)
+#define _CLC_VECTOR_CONVERT_FROM(FROM_TYPE, SUFFIX)
\
+  _CLC_VECTOR_CONVERT_FROM1(FROM_TYPE, SUFFIX) 
\
+  _CLC_VECTOR_CONVERT_DECL(FROM_TYPE, half, SUFFIX)
 #else
 #define _CLC_VECTOR_CONVERT_FROM(FROM_TYPE, SUFFIX) \
   _CLC_VECTOR_CONVERT_FROM1(FROM_TYPE, SUFFIX)
@@ -40,11 +49,19 @@
   _CLC_VECTOR_CONVERT_FROM(ulong, SUFFIX) \
   _CLC_VECTOR_CONVERT_FROM(float, SUFFIX)
 
-#ifdef cl_khr_fp64
+#if defined(cl_khr_fp64) && defined(cl_khr_fp16)
+#define _CLC_VECTOR_CONVERT_TO(SUFFIX) 
\
+  _CLC_VECTOR_CONVERT_TO1(SUFFIX)  
\
+  _CLC_VECTOR_CONVERT_FROM(double, SUFFIX) 
\
+  _CLC_VECTOR_CONVERT_FROM(half, SUFFIX)
+#elif defined(cl_khr_fp64)
 #define _CLC_VECTOR_CON

[clang] [clang] Fix static analyzer concerns in #embed code (PR #99331)

2024-07-18 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon updated 
https://github.com/llvm/llvm-project/pull/99331

>From 178c66c9c4c68485931cf2d60063dd97f7858309 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Wed, 17 Jul 2024 07:39:02 -0700
Subject: [PATCH 1/2] [clang] Fix static analyzer concerns in #embed code

1. Dead code int LookupEmbedFile. The loop always exited on the first
   iteration. This was also causing a bug of not checking all
   directories provided by --embed-dir

2. Use of uninitialized variable CurTok LexEmbedParameters. It was used
   to initialize the field which seems to be unused. Removed unused
   field, this way CurTok should be initialized by Lex method.
---
 clang/include/clang/Lex/PPEmbedParameters.h| 1 -
 clang/lib/Lex/PPDirectives.cpp | 8 +++-
 clang/test/Preprocessor/embed_file_not_found_chevron.c | 3 ++-
 3 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/clang/include/clang/Lex/PPEmbedParameters.h 
b/clang/include/clang/Lex/PPEmbedParameters.h
index 51bf908524e7a..c4fb8d02f6f35 100644
--- a/clang/include/clang/Lex/PPEmbedParameters.h
+++ b/clang/include/clang/Lex/PPEmbedParameters.h
@@ -75,7 +75,6 @@ struct LexEmbedParametersResult {
   std::optional MaybeIfEmptyParam;
   std::optional MaybePrefixParam;
   std::optional MaybeSuffixParam;
-  SourceRange ParamRange;
   int UnrecognizedParams;
 
   size_t PrefixTokenCount() const {
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index a53540b12dee6..4e77df9ec444c 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -1137,7 +1137,9 @@ Preprocessor::LookupEmbedFile(StringRef Filename, bool 
isAngled, bool OpenFile,
 SeparateComponents(LookupPath, Entry, Filename, false);
 llvm::Expected ShouldBeEntry =
 FM.getFileRef(LookupPath, OpenFile);
-return llvm::expectedToOptional(std::move(ShouldBeEntry));
+if (ShouldBeEntry)
+  return llvm::expectedToOptional(std::move(ShouldBeEntry));
+llvm::consumeError(ShouldBeEntry.takeError());
   }
   return std::nullopt;
 }
@@ -3624,12 +3626,10 @@ Preprocessor::LexEmbedParameters(Token &CurTok, bool 
ForHasEmbed) {
   LexEmbedParametersResult Result{};
   SmallVector ParameterTokens;
   tok::TokenKind EndTokenKind = ForHasEmbed ? tok::r_paren : tok::eod;
-  Result.ParamRange = {CurTok.getLocation(), CurTok.getLocation()};
 
   auto DiagMismatchedBracesAndSkipToEOD =
   [&](tok::TokenKind Expected,
   std::pair Matches) {
-Result.ParamRange.setEnd(CurTok.getEndLoc());
 Diag(CurTok, diag::err_expected) << Expected;
 Diag(Matches.second, diag::note_matching) << Matches.first;
 if (CurTok.isNot(tok::eod))
@@ -3638,7 +3638,6 @@ Preprocessor::LexEmbedParameters(Token &CurTok, bool 
ForHasEmbed) {
 
   auto ExpectOrDiagAndSkipToEOD = [&](tok::TokenKind Kind) {
 if (CurTok.isNot(Kind)) {
-  Result.ParamRange.setEnd(CurTok.getEndLoc());
   Diag(CurTok, diag::err_expected) << Kind;
   if (CurTok.isNot(tok::eod))
 DiscardUntilEndOfDirective(CurTok);
@@ -3872,7 +3871,6 @@ Preprocessor::LexEmbedParameters(Token &CurTok, bool 
ForHasEmbed) {
   }
 }
   }
-  Result.ParamRange.setEnd(CurTok.getLocation());
   return Result;
 }
 
diff --git a/clang/test/Preprocessor/embed_file_not_found_chevron.c 
b/clang/test/Preprocessor/embed_file_not_found_chevron.c
index 47aafa55a..b6d110f452c09 100644
--- a/clang/test/Preprocessor/embed_file_not_found_chevron.c
+++ b/clang/test/Preprocessor/embed_file_not_found_chevron.c
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -std=c23 %s -E -verify
+// RUN: %clang_cc1 -std=c23 %s -E -verify --embed-dir=%S --embed-dir=%S/Inputs
 
+#embed 
 #embed 
 // expected-error@-1 {{'nfejfNejAKFe' file not found}}

>From 9c6914f33b91fe3a449680c5726b7b886687fa5f Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Thu, 18 Jul 2024 04:04:13 -0700
Subject: [PATCH 2/2] Rename the test

---
 clang/test/Preprocessor/embed_file_not_found_chevron.c | 3 +--
 clang/test/Preprocessor/embed_search_paths.c   | 4 
 2 files changed, 5 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Preprocessor/embed_search_paths.c

diff --git a/clang/test/Preprocessor/embed_file_not_found_chevron.c 
b/clang/test/Preprocessor/embed_file_not_found_chevron.c
index b6d110f452c09..47aafa55a 100644
--- a/clang/test/Preprocessor/embed_file_not_found_chevron.c
+++ b/clang/test/Preprocessor/embed_file_not_found_chevron.c
@@ -1,5 +1,4 @@
-// RUN: %clang_cc1 -std=c23 %s -E -verify --embed-dir=%S --embed-dir=%S/Inputs
+// RUN: %clang_cc1 -std=c23 %s -E -verify
 
-#embed 
 #embed 
 // expected-error@-1 {{'nfejfNejAKFe' file not found}}
diff --git a/clang/test/Preprocessor/embed_search_paths.c 
b/clang/test/Preprocessor/embed_search_paths.c
new file mode 100644
index 0..5cc1bbf9f87a9
--- /dev/null
+++ b/clang/test/Preprocessor/embed_search_paths.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -std=c

[clang] [SystemZ][z/OS] Implement z/OS XPLINK ABI (PR #91384)

2024-07-18 Thread Ulrich Weigand via cfe-commits

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


[clang] [SystemZ][z/OS] Implement z/OS XPLINK ABI (PR #91384)

2024-07-18 Thread Ulrich Weigand via cfe-commits


@@ -529,9 +530,355 @@ bool SystemZTargetCodeGenInfo::isVectorTypeBased(const 
Type *Ty,
   return false;
 }
 
+//===--===//
+// z/OS XPLINK ABI Implementation
+//===--===//
+
+namespace {
+
+class ZOSXPLinkABIInfo : public ABIInfo {
+  const unsigned GPRBits = 64;
+  bool HasVector;
+
+public:
+  ZOSXPLinkABIInfo(CodeGenTypes &CGT, bool HV) : ABIInfo(CGT), HasVector(HV) {}
+
+  bool isPromotableIntegerType(QualType Ty) const;
+  bool isVectorArgumentType(QualType Ty) const;
+  bool isFPArgumentType(QualType Ty) const;
+  QualType getSingleElementType(QualType Ty) const;
+  std::optional getFPTypeOfComplexLikeType(QualType Ty) const;
+
+  ABIArgInfo classifyReturnType(QualType RetTy) const;
+  ABIArgInfo classifyArgumentType(QualType ArgTy, bool IsNamedArg) const;
+
+  void computeInfo(CGFunctionInfo &FI) const override {
+if (!getCXXABI().classifyReturnType(FI))
+  FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
+
+unsigned NumRequiredArgs = FI.getNumRequiredArgs();
+unsigned ArgNo = 0;
+
+for (auto &I : FI.arguments()) {
+  bool IsNamedArg = ArgNo < NumRequiredArgs;
+  I.info = classifyArgumentType(I.type, IsNamedArg);
+  ++ArgNo;
+}
+  }
+
+  Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
+QualType Ty) const override;
+};
+
+class ZOSXPLinkTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  ZOSXPLinkTargetCodeGenInfo(CodeGenTypes &CGT, bool HasVector)
+  : TargetCodeGenInfo(std::make_unique(CGT, HasVector)) {
+SwiftInfo =
+std::make_unique(CGT, /*SwiftErrorInRegister=*/false);
+  }
+};
+
+} // namespace
+
+// Return true if the ABI requires Ty to be passed sign- or zero-
+// extended to 64 bits.
+bool ZOSXPLinkABIInfo::isPromotableIntegerType(QualType Ty) const {
+  // Treat an enum type as its underlying type.
+  if (const EnumType *EnumTy = Ty->getAs())
+Ty = EnumTy->getDecl()->getIntegerType();
+
+  // Promotable integer types are required to be promoted by the ABI.
+  if (getContext().isPromotableIntegerType(Ty))
+return true;
+
+  if (const auto *EIT = Ty->getAs())
+if (EIT->getNumBits() < 64)
+  return true;
+
+  // In addition to the usual promotable integer types, we also need to
+  // extend all 32-bit types, since the ABI requires promotion to 64 bits.
+  if (const BuiltinType *BT = Ty->getAs())
+switch (BT->getKind()) {
+case BuiltinType::Int:
+case BuiltinType::UInt:
+  return true;
+default:
+  break;
+}
+
+  return false;
+}
+
+bool ZOSXPLinkABIInfo::isVectorArgumentType(QualType Ty) const {
+  return (HasVector && Ty->isVectorType() &&
+  getContext().getTypeSize(Ty) <= 128);
+}
+
+bool ZOSXPLinkABIInfo::isFPArgumentType(QualType Ty) const {
+  if (const BuiltinType *BT = Ty->getAs())
+switch (BT->getKind()) {
+case BuiltinType::Float:
+case BuiltinType::Double:
+case BuiltinType::LongDouble:
+  return true;
+default:
+  return false;
+}
+
+  return false;
+}
+
+QualType ZOSXPLinkABIInfo::getSingleElementType(QualType Ty) const {
+  const RecordType *RT = Ty->getAs();
+
+  if (RT && RT->isStructureOrClassType()) {
+const RecordDecl *RD = RT->getDecl();
+QualType Found;
+
+// If this is a C++ record, check the bases first.
+if (const CXXRecordDecl *CXXRD = dyn_cast(RD))
+  if (CXXRD->hasDefinition())
+for (const auto &I : CXXRD->bases()) {
+  QualType Base = I.getType();
+
+  // Empty bases don't affect things either way.
+  if (isEmptyRecord(getContext(), Base, true))
+continue;
+
+  if (!Found.isNull())
+return Ty;
+  Found = getSingleElementType(Base);
+}
+
+// Check the fields.
+for (const auto *FD : RD->fields()) {
+  QualType FT = FD->getType();
+
+  // Ignore empty fields.
+  if (isEmptyField(getContext(), FD, true))
+continue;
+
+  if (!Found.isNull())
+return Ty;
+
+  // Treat single element arrays as the element.
+  while (const ConstantArrayType *AT =
+ getContext().getAsConstantArrayType(FT)) {
+if (AT->getZExtSize() != 1)
+  break;
+FT = AT->getElementType();
+  }
+
+  Found = getSingleElementType(FT);
+}
+
+// Unlike isSingleElementStruct(), trailing padding is allowed.
+if (!Found.isNull())
+  return Found;
+  }
+
+  return Ty;
+}
+
+std::optional
+ZOSXPLinkABIInfo::getFPTypeOfComplexLikeType(QualType Ty) const {
+  if (const RecordType *RT = Ty->getAsStructureType()) {
+const RecordDecl *RD = RT->getDecl();
+
+// Check for non-empty base classes.
+if (const CXXRecordDecl *CXXRD = dyn_cast(RD))
+  if (CXXRD->hasDefinition())
+for (const auto &I : CXXRD->bases()) {
+  QualType Base = I.getType();
+   

[clang] [SystemZ][z/OS] Implement z/OS XPLINK ABI (PR #91384)

2024-07-18 Thread Ulrich Weigand via cfe-commits

https://github.com/uweigand commented:

This version LGTM now, I think once the transparent-union thing is resolved, 
this should be ready to commit.  Thanks!

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


[clang] [clang] Diagnose use of deprecated template alias (PR #97619)

2024-07-18 Thread Aaron Ballman via cfe-commits

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


[clang] [clang] Diagnose use of deprecated template alias (PR #97619)

2024-07-18 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman commented:

Thank you for this, the changes should also come with a release note in 
clang/docs/ReleaseNotes.rst so users know about the improvement. Changes 
generally LG, but I did have some test suggestions.

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


[clang] [clang] Diagnose use of deprecated template alias (PR #97619)

2024-07-18 Thread Aaron Ballman via cfe-commits


@@ -0,0 +1,72 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+//
+// This test checks that a deprecated attribute on an alias
+// template triggers a warning diagnostic when it is used.
+
+template 
+struct NoAttr {
+  void foo() {}
+};
+
+// expected-note@+2 5{{'UsingWithAttr' has been explicitly marked deprecated 
here}}
+template 
+using UsingWithAttr __attribute__((deprecated)) = NoAttr;
+
+// expected-note@+1 {{'UsingInstWithAttr' has been explicitly marked 
deprecated here}}
+using UsingInstWithAttr __attribute__((deprecated)) = NoAttr;
+
+// expected-note@+1 {{'TDWithAttr' has been explicitly marked deprecated here}}
+typedef NoAttr TDWithAttr __attribute__((deprecated));
+
+// expected-warning@+1 {{'UsingWithAttr' is deprecated}}
+typedef UsingWithAttr TDUsingWithAttr;
+
+typedef NoAttr TDNoAttr;
+
+// expected-note@+1 {{'UsingTDWithAttr' has been explicitly marked deprecated 
here}}
+using UsingTDWithAttr __attribute__((deprecated)) = TDNoAttr;
+
+struct S {
+  NoAttr f1;
+  // expected-warning@+1 {{'UsingWithAttr' is deprecated}}
+  UsingWithAttr f2;
+};
+
+// expected-warning@+1 {{'UsingWithAttr' is deprecated}}
+void foo(NoAttr s1, UsingWithAttr s2) {
+}
+
+// expected-note@+2 {{'UsingWithCPPAttr' has been explicitly marked deprecated 
here}}
+template 
+using UsingWithCPPAttr [[deprecated]] = NoAttr;
+
+// expected-note@+1 {{'UsingInstWithCPPAttr' has been explicitly marked 
deprecated here}}
+using UsingInstWithCPPAttr [[deprecated("Do not use this")]] = NoAttr;
+
+void bar() {
+  NoAttr obj; // Okay
+
+  // expected-warning@+2 {{'UsingWithAttr' is deprecated}}
+  // expected-note@+1 {{in instantiation of template type alias 
'UsingWithAttr' requested here}}
+  UsingWithAttr objUsingWA;
+
+  // expected-warning@+2 {{'UsingWithAttr' is deprecated}}
+  // expected-note@+1 {{in instantiation of template type alias 
'UsingWithAttr' requested here}}
+  UsingWithAttr().foo();
+
+  // expected-warning@+1 {{'UsingInstWithAttr' is deprecated}}
+  UsingInstWithAttr objUIWA;
+
+  // expected-warning@+1 {{'TDWithAttr' is deprecated}}
+  TDWithAttr objTDWA;
+
+  // expected-warning@+1 {{'UsingTDWithAttr' is deprecated}}
+  UsingTDWithAttr objUTDWA;
+
+  // expected-warning@+2 {{'UsingWithCPPAttr' is deprecated}}
+  // expected-note@+1 {{in instantiation of template type alias 
'UsingWithCPPAttr' requested here}}
+  UsingWithCPPAttr objUsingWCPPA;
+
+  // expected-warning@+1 {{'UsingInstWithCPPAttr' is deprecated: Do not use 
this}}
+  UsingInstWithCPPAttr objUICPPWA;

AaronBallman wrote:

Some more test cases I'd like to see:
```
NoAttr> s; // diag

using Foo [[deprecated]] = int;
using X = UsingWithAttr; // two diagnostics, one for Foo and one for 
UsingWithAttr
```

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


[clang] [clang] Fix static analyzer concerns in #embed code (PR #99331)

2024-07-18 Thread Aaron Ballman via cfe-commits

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

LGTM!

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


[clang] [Sema] Preserve ContainsUnexpandedParameterPack in TransformLambdaExpr (PR #86265)

2024-07-18 Thread Younan Zhang via cfe-commits


@@ -14636,6 +14645,20 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 /*IsInstantiation*/ true);
   SavedContext.pop();
 
+  // Parts other than the capture e.g. the lambda body might still contain a
+  // pattern that an outer fold expression would expand.
+  //
+  // We don't have a way to propagate up the ContainsUnexpandedParameterPack
+  // flag from a Stmt, so we have to revisit the lambda.
+  if (!LSICopy.ContainsUnexpandedParameterPack) {
+llvm::SmallVector UnexpandedPacks;
+getSema().collectUnexpandedParameterPacksFromLambda(NewCallOperator,
+UnexpandedPacks);
+// FIXME: Should we call Sema::DiagnoseUnexpandedParameterPacks() instead?
+// Unfortunately, that requires the LambdaScopeInfo to exist, which has 
been
+// removed by ActOnFinishFunctionBody().
+LSICopy.ContainsUnexpandedParameterPack = !UnexpandedPacks.empty();
+  }

zyn0217 wrote:

We probably need a refactor here to teach `ActOnFinishFunctionBody()` not to 
pop the LSI eventually. How about leaving it as an NFC?

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


[clang] [Sema] Preserve ContainsUnexpandedParameterPack in TransformLambdaExpr (PR #86265)

2024-07-18 Thread Younan Zhang via cfe-commits


@@ -23,3 +23,104 @@ namespace PR41576 {
   }
   static_assert(f(3, 4) == 6); // expected-note {{instantiation}}
 }
+
+namespace PR85667 {
+
+template 
+struct identity {
+  using type = T;
+};
+
+template  void f() {
+
+  static_assert([](Is... x) {
+return ([I(x)] {
+  return I;
+}() + ...);
+  }(1, 2) == 3);
+
+  static_assert([](Is... x) {
+return ([](auto y = Is()) { return y + 1; } + ...);
+  }(0, 0, 0) == 3);
+
+  []() {
+return ([]() noexcept(Is()) { return 0; }() + ...);
+  }.template operator()();
+
+  static_assert(__is_same(decltype([]() {
+return ([]() -> decltype(Is()) { return {}; }(),
+...);
+  }.template operator()()),
+  char));
+
+  []() {
+return ([]() -> decltype(Is()) { return Ts(); }() + ...);
+// expected-error@-1 {{unexpanded parameter pack 'Ts'}}
+  }.template operator()();
+
+  // Note that GCC and EDG reject this case currently.
+  // GCC says the fold expression "has no unexpanded parameter packs", while
+  // EDG says the constraint is not allowed on a non-template function.
+  // MSVC is happy with it.
+  []() {
+([]()
+   requires(Is())
+ {},
+ ...);
+  }.template operator()();
+
+  // https://github.com/llvm/llvm-project/issues/56852
+  [](Is...) {
+([] {
+  using T = identity::type;
+}(), ...);
+  }(1, 2);
+
+  [](auto ...y) {
+([y] { }(), ...);
+  }();
+
+  [](auto ...x) {
+([&](auto ...y) {
+  ([x..., y] { }(), ...);
+})(1);
+  }(2, 'b');
+
+#if 0
+  // https://github.com/llvm/llvm-project/issues/18873
+  [](auto ...x) { // #1
+([&](auto ...y) {  // #2
+  ([x, y] { }(), ...); // #3
+})(1, 'a');  // #4
+  }(2, 'b');  // #5
+

zyn0217 wrote:

I'm unsure if it's feasible to sneak in these tests, though they still crash 
for a different reason after this patch. @cor3ntin lmk what you think.

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


[clang] [Parser][ObjC] Add -Wobjc-prefix-length warning option. (PR #97597)

2024-07-18 Thread Alastair Houghton via cfe-commits

https://github.com/al45tair updated 
https://github.com/llvm/llvm-project/pull/97597

>From 6dfbc7b61b137fdfd9d39b23bce62e451dca3e1c Mon Sep 17 00:00:00 2001
From: Alastair Houghton 
Date: Wed, 3 Jul 2024 17:00:51 +0100
Subject: [PATCH] [Sema][ObjC] Add warning options to detect bad name prefixes.

On Darwin, two-character prefixes are reserved for Apple, while three-
character prefixes are reserved for use by third party developers.
Breaking these rules in framework code can lead to symbol clashes,
which can result in unexpected behaviour.

This changeset adds three warning options, all turned off by default,
that cause Clang to warn the user if they breach the policy specified
by the warning options.  They are:

* `-Wobjc-prefix-length=`, which tests for a certain prefix length
  on every ObjC class or protocol
* `-Wobjc-prefixes=[,...]`, which requires that the prefix
  on every ObjC class or protocol be one from a specified list, and
* `-Wobjc-forbidden-prefixes=[,...]`, which lists prefixes
  that are explicitly disallowed.

These are also used to determine whether or not a prefix should be added
to a category method; if the class on which the category is being declared
does not match the permitted prefix settings, then the above warning
options will *also* require a prefix on any methods declared in that
category.

All of these warnings are disabled for system headers.

rdar://131055157
---
 clang/include/clang/Basic/DiagnosticGroups.td |   3 +
 .../clang/Basic/DiagnosticSemaKinds.td|  31 +++
 clang/include/clang/Basic/LangOptions.def |   2 +
 clang/include/clang/Basic/LangOptions.h   |   6 +
 clang/include/clang/Driver/Options.td |  19 ++
 clang/include/clang/Sema/SemaObjC.h   |   9 +
 clang/lib/Driver/ToolChains/Clang.cpp |   4 +
 clang/lib/Parse/ParseObjc.cpp |   1 +
 clang/lib/Sema/SemaDeclObjC.cpp   | 254 ++
 clang/lib/Sema/SemaObjCProperty.cpp   |  45 +++-
 clang/test/SemaObjC/prefixes.m| 129 +
 clang/test/SemaObjC/prefixes2.m   |  70 +
 12 files changed, 572 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaObjC/prefixes.m
 create mode 100644 clang/test/SemaObjC/prefixes2.m

diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 2241f8481484e..7f3d4b463a8df 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -612,6 +612,9 @@ def ObjCPointerIntrospect : 
DiagGroup<"deprecated-objc-pointer-introspection", [
 def ObjCMultipleMethodNames : DiagGroup<"objc-multiple-method-names">;
 def ObjCFlexibleArray : DiagGroup<"objc-flexible-array">;
 def ObjCBoxing : DiagGroup<"objc-boxing">;
+def ObjCPrefixes : DiagGroup<"objc-prefixes">;
+def ObjCForbiddenPrefixes : DiagGroup<"objc-forbidden-prefixes">;
+def ObjCPrefixLength : DiagGroup<"objc-prefix-length">;
 def CompletionHandler : DiagGroup<"completion-handler">;
 def CalledOnceParameter : DiagGroup<"called-once-parameter", 
[CompletionHandler]>;
 def OpenCLUnsupportedRGBA: DiagGroup<"opencl-unsupported-rgba">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 52ff4b026a60e..4e0c9f0fa2d06 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1419,6 +1419,37 @@ def warn_objc_property_retain_of_block : Warning<
 def warn_objc_readonly_property_has_setter : Warning<
 "setter cannot be specified for a readonly property">,
 InGroup;
+
+def warn_objc_unprefixed_class_name : Warning<
+  "un-prefixed Objective-C class name">,
+  InGroup;
+def warn_objc_unprefixed_protocol_name : Warning<
+  "un-prefixed Objective-C protocol name">,
+  InGroup;
+def warn_objc_unprefixed_category_method_name : Warning<
+  "un-prefixed Objective-C method name on category">,
+  InGroup;
+
+def warn_objc_bad_class_name_prefix : Warning<
+  "Objective-C class name prefix not in permitted list">,
+  InGroup;
+def warn_objc_bad_protocol_name_prefix : Warning<
+  "Objective-C protocol name prefix not in permitted list">,
+  InGroup;
+def warn_objc_bad_category_method_name_prefix : Warning<
+  "Objective-C category method name prefix not in permitted list">,
+  InGroup;
+
+def warn_objc_forbidden_class_name_prefix : Warning<
+  "Objective-C class name prefix in forbidden list">,
+  InGroup;
+def warn_objc_forbidden_protocol_name_prefix : Warning<
+  "Objective-C protocol name prefix in forbidden list">,
+  InGroup;
+def warn_objc_forbidden_category_method_name_prefix : Warning<
+  "Objective-C category method name prefix in forbidden list">,
+  InGroup;
+
 def warn_atomic_property_rule : Warning<
   "writable atomic property %0 cannot pair a synthesized 
%select{getter|setter}1 "
   "with a user defined %select{getter|setter}2">,
diff --git a/clang/include/clang/Basic/LangOptions.def

[clang] [Parser][ObjC] Add -Wobjc-prefix-length warning option. (PR #97597)

2024-07-18 Thread Alastair Houghton via cfe-commits

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


[clang] [Sema][ObjC] Add warning options to detect bad name prefixes. (PR #97597)

2024-07-18 Thread Alastair Houghton via cfe-commits

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


[clang] [Sema] Preserve ContainsUnexpandedParameterPack in TransformLambdaExpr (PR #86265)

2024-07-18 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

> I was waiting for the CI, but it seems Linux CI would take hours. However 
> that shouldn't block the review I think, because Windows CI is green now.

FWIW Linux CI is recovering as we speak. I expect full recovery over the 
weekend.

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


[clang-tools-extra] [clang-tidy][NFC] Fix gsl::not_null template parameter (PR #99472)

2024-07-18 Thread Rafael Stahl via cfe-commits

https://github.com/rafzi created https://github.com/llvm/llvm-project/pull/99472

`T` is expected to be a pointer type.

https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-nullptr

>From 48e452b9032d26889dfceb7668159275015a5290 Mon Sep 17 00:00:00 2001
From: Rafael Stahl 
Date: Thu, 18 Jul 2024 13:35:28 +0200
Subject: [PATCH] [clang-tidy][NFC] Fix gsl::not_null template parameter

---
 .../cppcoreguidelines/avoid-const-or-ref-data-members.rst | 2 +-
 .../cppcoreguidelines/avoid-const-or-ref-data-members.cpp | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-const-or-ref-data-members.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-const-or-ref-data-members.rst
index 5783280478dc1..57c4829431e76 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-const-or-ref-data-members.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-const-or-ref-data-members.rst
@@ -35,7 +35,7 @@ Examples:
 int* x;
 std::unique_ptr x;
 std::shared_ptr x;
-gsl::not_null x;
+gsl::not_null x;
   };
 
   // Bad, rvalue reference member
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-const-or-ref-data-members.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-const-or-ref-data-members.cpp
index 5a5d05bb4e94e..e3864be134da3 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-const-or-ref-data-members.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-const-or-ref-data-members.cpp
@@ -18,7 +18,7 @@ struct Ok {
   const int *pc;
   std::unique_ptr up;
   std::shared_ptr sp;
-  gsl::not_null n;
+  gsl::not_null n;
 };
 
 struct ConstMember {
@@ -60,7 +60,7 @@ struct Ok2 {
   const Foo *pc;
   std::unique_ptr up;
   std::shared_ptr sp;
-  gsl::not_null n;
+  gsl::not_null n;
 };
 
 struct ConstMember2 {

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


[clang-tools-extra] [clang-tidy][NFC] Fix gsl::not_null template parameter (PR #99472)

2024-07-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Rafael Stahl (rafzi)


Changes

`T` is expected to be a pointer type.

https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-nullptr

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


2 Files Affected:

- (modified) 
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-const-or-ref-data-members.rst
 (+1-1) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-const-or-ref-data-members.cpp
 (+2-2) 


``diff
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-const-or-ref-data-members.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-const-or-ref-data-members.rst
index 5783280478dc1..57c4829431e76 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-const-or-ref-data-members.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-const-or-ref-data-members.rst
@@ -35,7 +35,7 @@ Examples:
 int* x;
 std::unique_ptr x;
 std::shared_ptr x;
-gsl::not_null x;
+gsl::not_null x;
   };
 
   // Bad, rvalue reference member
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-const-or-ref-data-members.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-const-or-ref-data-members.cpp
index 5a5d05bb4e94e..e3864be134da3 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-const-or-ref-data-members.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-const-or-ref-data-members.cpp
@@ -18,7 +18,7 @@ struct Ok {
   const int *pc;
   std::unique_ptr up;
   std::shared_ptr sp;
-  gsl::not_null n;
+  gsl::not_null n;
 };
 
 struct ConstMember {
@@ -60,7 +60,7 @@ struct Ok2 {
   const Foo *pc;
   std::unique_ptr up;
   std::shared_ptr sp;
-  gsl::not_null n;
+  gsl::not_null n;
 };
 
 struct ConstMember2 {

``




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


[clang-tools-extra] [clang-tidy][NFC] Fix gsl::not_null template parameter (PR #99472)

2024-07-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tools-extra

Author: Rafael Stahl (rafzi)


Changes

`T` is expected to be a pointer type.

https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-nullptr

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


2 Files Affected:

- (modified) 
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-const-or-ref-data-members.rst
 (+1-1) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-const-or-ref-data-members.cpp
 (+2-2) 


``diff
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-const-or-ref-data-members.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-const-or-ref-data-members.rst
index 5783280478dc1..57c4829431e76 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-const-or-ref-data-members.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-const-or-ref-data-members.rst
@@ -35,7 +35,7 @@ Examples:
 int* x;
 std::unique_ptr x;
 std::shared_ptr x;
-gsl::not_null x;
+gsl::not_null x;
   };
 
   // Bad, rvalue reference member
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-const-or-ref-data-members.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-const-or-ref-data-members.cpp
index 5a5d05bb4e94e..e3864be134da3 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-const-or-ref-data-members.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-const-or-ref-data-members.cpp
@@ -18,7 +18,7 @@ struct Ok {
   const int *pc;
   std::unique_ptr up;
   std::shared_ptr sp;
-  gsl::not_null n;
+  gsl::not_null n;
 };
 
 struct ConstMember {
@@ -60,7 +60,7 @@ struct Ok2 {
   const Foo *pc;
   std::unique_ptr up;
   std::shared_ptr sp;
-  gsl::not_null n;
+  gsl::not_null n;
 };
 
 struct ConstMember2 {

``




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


[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)

2024-07-18 Thread Nico Weber via cfe-commits


@@ -161,6 +163,7 @@ clang_target_link_libraries(clangDaemon
   clangAST
   clangASTMatchers
   clangBasic
+  clangDependencyScanning

nico wrote:

This dependency makes clangd depend (transitively) on clangCodeGen, which it 
didn't depend on previously.

This makes clangd take ~30% longer to build, increases its binary size, and 
it's conceptually strange that a language server contains code generation code.

Any chance we could cut the dependency on clangCodeGen again?

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


[clang] [Clang] Add __common_type builtin (PR #99473)

2024-07-18 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 created 
https://github.com/llvm/llvm-project/pull/99473

This implements the logic of the `common_type` base template as a builtin 
alias. If there should be no `type` member, an empty class is returned. 
Otherwise a specialization of a `type_identity`-like class is returned. The 
base template (i.e. `std::common_type`) as well as the empty class and 
`type_identity`-like struct are given as arguments to the builtin.


>From c893eb9db0b25eef0b1c9df8e711358c14bc8a63 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 16 Jul 2024 14:48:10 +0200
Subject: [PATCH] [Clang] Add __common_type builtin

---
 clang/include/clang/AST/ASTContext.h  |  11 +
 clang/include/clang/AST/DeclID.h  |   3 +
 clang/include/clang/Basic/Builtins.h  |   5 +-
 clang/include/clang/Sema/Sema.h   |   4 +
 clang/lib/AST/ASTContext.cpp  |   8 +
 clang/lib/AST/ASTImporter.cpp |   3 +
 clang/lib/AST/DeclTemplate.cpp|  53 
 clang/lib/Lex/PPMacroExpansion.cpp|   1 +
 clang/lib/Sema/SemaChecking.cpp   |   8 +
 clang/lib/Sema/SemaLookup.cpp |   4 +
 clang/lib/Sema/SemaTemplate.cpp   | 154 ++-
 clang/test/AST/Interp/crash-GH49103-2.cpp |   4 +-
 clang/test/SemaCXX/crash-GH49103-2.cpp|   4 +-
 clang/test/SemaCXX/type-trait-common-type.cpp | 125 +
 clang/test/SemaCXX/type-traits.cpp| 240 +-
 15 files changed, 501 insertions(+), 126 deletions(-)
 create mode 100644 clang/test/SemaCXX/type-trait-common-type.cpp

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 57022e75073fe..867467d01f4d1 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -399,6 +399,9 @@ class ASTContext : public RefCountedBase {
   /// The identifier '__type_pack_element'.
   mutable IdentifierInfo *TypePackElementName = nullptr;
 
+  /// The identifier '__common_type'.
+  mutable IdentifierInfo *CommonTypeName = nullptr;
+
   QualType ObjCConstantStringType;
   mutable RecordDecl *CFConstantStringTagDecl = nullptr;
   mutable TypedefDecl *CFConstantStringTypeDecl = nullptr;
@@ -606,6 +609,7 @@ class ASTContext : public RefCountedBase {
   mutable ExternCContextDecl *ExternCContext = nullptr;
   mutable BuiltinTemplateDecl *MakeIntegerSeqDecl = nullptr;
   mutable BuiltinTemplateDecl *TypePackElementDecl = nullptr;
+  mutable BuiltinTemplateDecl *CommonTypeDecl = nullptr;
 
   /// The associated SourceManager object.
   SourceManager &SourceMgr;
@@ -1104,6 +1108,7 @@ class ASTContext : public RefCountedBase {
   ExternCContextDecl *getExternCContextDecl() const;
   BuiltinTemplateDecl *getMakeIntegerSeqDecl() const;
   BuiltinTemplateDecl *getTypePackElementDecl() const;
+  BuiltinTemplateDecl *getCommonTypeDecl() const;
 
   // Builtin Types.
   CanQualType VoidTy;
@@ -1981,6 +1986,12 @@ class ASTContext : public RefCountedBase {
 return TypePackElementName;
   }
 
+  IdentifierInfo *getCommonTypeName() const {
+if (!CommonTypeName)
+  CommonTypeName = &Idents.get("__common_type");
+return CommonTypeName;
+  }
+
   /// Retrieve the Objective-C "instancetype" type, if already known;
   /// otherwise, returns a NULL type;
   QualType getObjCInstanceType() {
diff --git a/clang/include/clang/AST/DeclID.h b/clang/include/clang/AST/DeclID.h
index e5e27389fac60..d8243773d8d98 100644
--- a/clang/include/clang/AST/DeclID.h
+++ b/clang/include/clang/AST/DeclID.h
@@ -84,6 +84,9 @@ enum PredefinedDeclIDs {
 
   /// The internal '__type_pack_element' template.
   PREDEF_DECL_TYPE_PACK_ELEMENT_ID = 17,
+
+  /// The internal '__common_type' template.
+  PREDEF_DECL_COMMON_TYPE_ID = 17,
 };
 
 /// The number of declaration IDs that are predefined.
diff --git a/clang/include/clang/Basic/Builtins.h 
b/clang/include/clang/Basic/Builtins.h
index f955d21169556..defffb334d480 100644
--- a/clang/include/clang/Basic/Builtins.h
+++ b/clang/include/clang/Basic/Builtins.h
@@ -304,7 +304,10 @@ enum BuiltinTemplateKind : int {
   BTK__make_integer_seq,
 
   /// This names the __type_pack_element BuiltinTemplateDecl.
-  BTK__type_pack_element
+  BTK__type_pack_element,
+
+  /// This names the __common_type BuiltinTemplateDecl.
+  BTK__common_type,
 };
 
 } // end namespace clang
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 48dff1b76cc57..1f9480418238a 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2282,6 +2282,10 @@ class Sema final : public SemaBase {
   /// Check to see if a given expression could have '.c_str()' called on it.
   bool hasCStrMethod(const Expr *E);
 
+  // Check whether a type member 'Type::Name' exists, and if yes, return the
+  // type. If there is no type, the QualType is null
+  QualType getTypeMember(StringRef Name, QualType Type);
+
   /// Diagnose pointers that are

[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)

2024-07-18 Thread Nico Weber via cfe-commits

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


[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)

2024-07-18 Thread Nico Weber via cfe-commits

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


[clang] [libcxx] [Clang] Add __common_type builtin (PR #99473)

2024-07-18 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/99473

>From f9b9431a97952909190c69e1dee188ef234addb2 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 16 Jul 2024 14:48:10 +0200
Subject: [PATCH] [Clang] Add __common_type builtin

---
 clang/include/clang/AST/ASTContext.h  |  11 +
 clang/include/clang/AST/DeclID.h  |   3 +
 clang/include/clang/Basic/Builtins.h  |   5 +-
 clang/include/clang/Sema/Sema.h   |   4 +
 clang/lib/AST/ASTContext.cpp  |   8 +
 clang/lib/AST/ASTImporter.cpp |   3 +
 clang/lib/AST/DeclTemplate.cpp|  53 
 clang/lib/Lex/PPMacroExpansion.cpp|   1 +
 clang/lib/Sema/SemaChecking.cpp   |   8 +
 clang/lib/Sema/SemaLookup.cpp |   4 +
 clang/lib/Sema/SemaTemplate.cpp   | 154 ++-
 clang/test/AST/Interp/crash-GH49103-2.cpp |   4 +-
 clang/test/SemaCXX/crash-GH49103-2.cpp|   4 +-
 clang/test/SemaCXX/type-trait-common-type.cpp | 125 +
 clang/test/SemaCXX/type-traits.cpp| 240 +-
 libcxx/include/__type_traits/common_type.h|  10 +
 16 files changed, 511 insertions(+), 126 deletions(-)
 create mode 100644 clang/test/SemaCXX/type-trait-common-type.cpp

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 57022e75073fe..867467d01f4d1 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -399,6 +399,9 @@ class ASTContext : public RefCountedBase {
   /// The identifier '__type_pack_element'.
   mutable IdentifierInfo *TypePackElementName = nullptr;
 
+  /// The identifier '__common_type'.
+  mutable IdentifierInfo *CommonTypeName = nullptr;
+
   QualType ObjCConstantStringType;
   mutable RecordDecl *CFConstantStringTagDecl = nullptr;
   mutable TypedefDecl *CFConstantStringTypeDecl = nullptr;
@@ -606,6 +609,7 @@ class ASTContext : public RefCountedBase {
   mutable ExternCContextDecl *ExternCContext = nullptr;
   mutable BuiltinTemplateDecl *MakeIntegerSeqDecl = nullptr;
   mutable BuiltinTemplateDecl *TypePackElementDecl = nullptr;
+  mutable BuiltinTemplateDecl *CommonTypeDecl = nullptr;
 
   /// The associated SourceManager object.
   SourceManager &SourceMgr;
@@ -1104,6 +1108,7 @@ class ASTContext : public RefCountedBase {
   ExternCContextDecl *getExternCContextDecl() const;
   BuiltinTemplateDecl *getMakeIntegerSeqDecl() const;
   BuiltinTemplateDecl *getTypePackElementDecl() const;
+  BuiltinTemplateDecl *getCommonTypeDecl() const;
 
   // Builtin Types.
   CanQualType VoidTy;
@@ -1981,6 +1986,12 @@ class ASTContext : public RefCountedBase {
 return TypePackElementName;
   }
 
+  IdentifierInfo *getCommonTypeName() const {
+if (!CommonTypeName)
+  CommonTypeName = &Idents.get("__common_type");
+return CommonTypeName;
+  }
+
   /// Retrieve the Objective-C "instancetype" type, if already known;
   /// otherwise, returns a NULL type;
   QualType getObjCInstanceType() {
diff --git a/clang/include/clang/AST/DeclID.h b/clang/include/clang/AST/DeclID.h
index e5e27389fac60..d8243773d8d98 100644
--- a/clang/include/clang/AST/DeclID.h
+++ b/clang/include/clang/AST/DeclID.h
@@ -84,6 +84,9 @@ enum PredefinedDeclIDs {
 
   /// The internal '__type_pack_element' template.
   PREDEF_DECL_TYPE_PACK_ELEMENT_ID = 17,
+
+  /// The internal '__common_type' template.
+  PREDEF_DECL_COMMON_TYPE_ID = 17,
 };
 
 /// The number of declaration IDs that are predefined.
diff --git a/clang/include/clang/Basic/Builtins.h 
b/clang/include/clang/Basic/Builtins.h
index f955d21169556..defffb334d480 100644
--- a/clang/include/clang/Basic/Builtins.h
+++ b/clang/include/clang/Basic/Builtins.h
@@ -304,7 +304,10 @@ enum BuiltinTemplateKind : int {
   BTK__make_integer_seq,
 
   /// This names the __type_pack_element BuiltinTemplateDecl.
-  BTK__type_pack_element
+  BTK__type_pack_element,
+
+  /// This names the __common_type BuiltinTemplateDecl.
+  BTK__common_type,
 };
 
 } // end namespace clang
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 48dff1b76cc57..1f9480418238a 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2282,6 +2282,10 @@ class Sema final : public SemaBase {
   /// Check to see if a given expression could have '.c_str()' called on it.
   bool hasCStrMethod(const Expr *E);
 
+  // Check whether a type member 'Type::Name' exists, and if yes, return the
+  // type. If there is no type, the QualType is null
+  QualType getTypeMember(StringRef Name, QualType Type);
+
   /// Diagnose pointers that are always non-null.
   /// \param E the expression containing the pointer
   /// \param NullKind NPCK_NotNull if E is a cast to bool, otherwise, E is
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 6c89e3890ae3e..4000c2c2d6836 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/l

[clang] [libcxx] [Clang] Add __common_type builtin (PR #99473)

2024-07-18 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 7e2b5e233a49f1c99cf9a3696ca4322ff989a386 
f9b9431a97952909190c69e1dee188ef234addb2 --extensions cpp,h -- 
clang/test/SemaCXX/type-trait-common-type.cpp 
clang/include/clang/AST/ASTContext.h clang/include/clang/AST/DeclID.h 
clang/include/clang/Basic/Builtins.h clang/include/clang/Sema/Sema.h 
clang/lib/AST/ASTContext.cpp clang/lib/AST/ASTImporter.cpp 
clang/lib/AST/DeclTemplate.cpp clang/lib/Lex/PPMacroExpansion.cpp 
clang/lib/Sema/SemaChecking.cpp clang/lib/Sema/SemaLookup.cpp 
clang/lib/Sema/SemaTemplate.cpp clang/test/AST/Interp/crash-GH49103-2.cpp 
clang/test/SemaCXX/crash-GH49103-2.cpp clang/test/SemaCXX/type-traits.cpp 
libcxx/include/__type_traits/common_type.h
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 4000c2c2d6..355b809da9 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1170,8 +1170,7 @@ ASTContext::getTypePackElementDecl() const {
   return TypePackElementDecl;
 }
 
-BuiltinTemplateDecl *
-ASTContext::getCommonTypeDecl() const {
+BuiltinTemplateDecl *ASTContext::getCommonTypeDecl() const {
   if (!CommonTypeDecl)
 CommonTypeDecl =
 buildBuiltinTemplateDecl(BTK__common_type, getCommonTypeName());
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 3f862d06af..e520df617e 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -3058,9 +3058,10 @@ void Sema::NoteAllFoundTemplates(TemplateName Name) {
   }
 }
 
-static std::optional
-commonTypeImpl(Sema &S, TemplateName BaseTemplate,
-   SourceLocation TemplateLoc, ArrayRef Ts) {
+static std::optional commonTypeImpl(Sema &S,
+  TemplateName BaseTemplate,
+  SourceLocation TemplateLoc,
+  ArrayRef Ts) {
   auto lookUpCommonType = [&](TemplateArgument T1,
   TemplateArgument T2) -> std::optional {
 // Don't bother looking for other specializations if both types are
@@ -3130,8 +3131,8 @@ commonTypeImpl(Sema &S, TemplateName BaseTemplate,
 ExprResult Cond = &CondExpr;
 
 // declval()
-auto EVK = ConstRefQual ? ExprValueKind::VK_LValue
- : ExprValueKind::VK_PRValue;
+auto EVK =
+ConstRefQual ? ExprValueKind::VK_LValue : 
ExprValueKind::VK_PRValue;
 if (ConstRefQual) {
   D1.addConst();
   D2.addConst();
diff --git a/libcxx/include/__type_traits/common_type.h 
b/libcxx/include/__type_traits/common_type.h
index 8240250742..103b58e42a 100644
--- a/libcxx/include/__type_traits/common_type.h
+++ b/libcxx/include/__type_traits/common_type.h
@@ -31,7 +31,7 @@ template 
 struct common_type : __common_type {};
 
 #else
-#if _LIBCPP_STD_VER >= 20
+#  if _LIBCPP_STD_VER >= 20
 // Let COND_RES(X, Y) be:
 template 
 using __cond_type = decltype(false ? std::declval<_Tp>() : 
std::declval<_Up>());
@@ -47,10 +47,10 @@ struct __common_type3<_Tp, _Up, void_t<__cond_type>> {
 
 template 
 struct __common_type2_imp : __common_type3<_Tp, _Up> {};
-#else
+#  else
 template 
 struct __common_type2_imp {};
-#endif
+#  endif
 
 // sub-bullet 3 - "if decay_t() : declval())> 
..."
 template 

``




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


[clang] [clang] Emit bad shift warnings (PR #70307)

2024-07-18 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> Just to confirm: is this the intentional outcome of this patch?

Before C++20, left shift of -1 does not produce a mathematical result that's 
within the range of representable values for the result type, so it's undefined 
behavior, and therefore not a core constant expression, and therefore invalid 
as the initializer for an enumeration constant. So I believe the behavior is 
expected and correct; you can see the UB diagnostic in other contexts: 
https://gcc.godbolt.org/z/bqj6xhzzr and GCC agrees with Clang in the 
enumeration case: https://gcc.godbolt.org/z/qjKzeaYTz

> the diagnostic - "expression is not an integral constant expression" - 
> doesn't sound helpful (how is it not constant or not integral?). And what's 
> worse, is that it's an error rather than a warning that can be disabled.

It has integral constants but it's not an integral constant expression as far 
as the language is concerned. The note tells you why it's not a valid integral 
constant expression. As for warning vs error; the standard makes the code 
ill-formed and we treat that as an error generally speaking.

If you can't enable C++20 mode, you can still get the same value in C++17 and 
earlier with well-formed code: https://gcc.godbolt.org/z/3ra83joqs

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


[clang] Improve stack usage to increase recursive initialization depth (PR #88546)

2024-07-18 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> @AaronBallman ping

I've not been able to get back on to this, unfortunately. I'm not certain when 
I'll have time, either.

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


[clang] [clang] pointer to member with qualified-id enclosed in parentheses in unevaluated context should be invalid (PR #89713)

2024-07-18 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> I can try to look at that this week. Either way be ill-formed is much better 
> than being incorrect

Thank you @cor3ntin! If it looks like you won't have a solution by Monday 
sometime, let's revert the changes so they don't end up on the release branch. 
We can cherry-pick if we think we have a rock solid solution, if needs be.

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


[clang-tools-extra] [clang-tidy][cppcoreguidelines-missing-std-forward] Do not warn when the parameter is used in a `static_cast`. (PR #99477)

2024-07-18 Thread Clement Courbet via cfe-commits

https://github.com/legrosbuffle created 
https://github.com/llvm/llvm-project/pull/99477

This provides a way to inform the check that we're intending to use an the 
forwarding reference as a specific reference category

Fixes #99474.

>From b423b26cba90288912b3377c39ab4207c9fc95dc Mon Sep 17 00:00:00 2001
From: Clement Courbet 
Date: Thu, 18 Jul 2024 11:47:56 +
Subject: [PATCH] [clang-tidy][cppcoreguidelines-missing-std-forward] Do not
 warn when the parameter is used in a `static_cast`.

This provides a way to inform the check that we're intending to use an
the forwarding reference as a specific reference category

Fixes #99474.
---
 .../MissingStdForwardCheck.cpp  |  8 ++--
 clang-tools-extra/docs/ReleaseNotes.rst |  5 +
 .../cppcoreguidelines/missing-std-forward.rst   |  3 +++
 .../cppcoreguidelines/missing-std-forward.cpp   | 17 +
 4 files changed, 31 insertions(+), 2 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
index bbb35228ce47f..726e9fffc628b 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
@@ -129,6 +129,9 @@ void MissingStdForwardCheck::registerMatchers(MatchFinder 
*Finder) {
   unless(anyOf(hasAncestor(typeLoc()),
hasAncestor(expr(hasUnevaluatedContext());
 
+  auto StaticCast = cxxStaticCastExpr(
+  hasSourceExpression(declRefExpr(to(equalsBoundNode("param");
+
   Finder->addMatcher(
   parmVarDecl(
   parmVarDecl().bind("param"), hasIdentifier(),
@@ -136,8 +139,9 @@ void MissingStdForwardCheck::registerMatchers(MatchFinder 
*Finder) {
   hasAncestor(functionDecl().bind("func")),
   hasAncestor(functionDecl(
   isDefinition(), equalsBoundNode("func"), ToParam,
-  unless(anyOf(isDeleted(),
-   hasDescendant(std::move(ForwardCallMatcher))),
+  unless(anyOf(isDeleted(), hasDescendant(expr(
+
anyOf(std::move(ForwardCallMatcher),
+  
std::move(StaticCast),
   this);
 }
 
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index a23483e6df6d2..c3f41811fa7d7 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -518,6 +518,11 @@ Changes in existing checks
   usages of ``std::string_view::compare``. Added a `StringLikeClasses` option
   to detect usages of ``compare`` method in custom string-like classes.
 
+- Improved :doc:`cppcoreguidelines-missing-std-forward
+  ` check to allow
+  using ``static_cast`` to explicitly convey the intention of using a
+  forwarding reference as an lvalue reference.
+
 Removed checks
 ^^
 
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/missing-std-forward.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/missing-std-forward.rst
index 0c311b59a5d5a..12765b45088de 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/missing-std-forward.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/missing-std-forward.rst
@@ -38,3 +38,6 @@ Example:
 This check implements `F.19
 `_
 from the C++ Core Guidelines.
+
+Users who want to use the forwarding reference as an lvalue reference can 
convey
+the intention by using ``static_cast(t)``.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
index 8116db58c937d..519d2822948bb 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
@@ -211,3 +211,20 @@ template
 void unused_argument3(F&& _) {}
 
 } // namespace unused_arguments
+
+namespace escape_hatch {
+
+template
+void used_as_lvalue_on_purpose(T&& t) {
+  static_cast(t);
+  static_cast(t);
+}
+
+template
+void used_as_rvalue_on_purpose(T&& t) {
+  static_cast(t);
+  // Typically used as another spelling for `std::forward`.
+  static_cast(t);
+}
+
+}

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


[clang-tools-extra] [clang-tidy][cppcoreguidelines-missing-std-forward] Do not warn when the parameter is used in a `static_cast`. (PR #99477)

2024-07-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tools-extra

Author: Clement Courbet (legrosbuffle)


Changes

This provides a way to inform the check that we're intending to use an the 
forwarding reference as a specific reference category

Fixes #99474.

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


4 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp 
(+6-2) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+5) 
- (modified) 
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/missing-std-forward.rst
 (+3) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
 (+17) 


``diff
diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
index bbb35228ce47f..726e9fffc628b 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
@@ -129,6 +129,9 @@ void MissingStdForwardCheck::registerMatchers(MatchFinder 
*Finder) {
   unless(anyOf(hasAncestor(typeLoc()),
hasAncestor(expr(hasUnevaluatedContext());
 
+  auto StaticCast = cxxStaticCastExpr(
+  hasSourceExpression(declRefExpr(to(equalsBoundNode("param");
+
   Finder->addMatcher(
   parmVarDecl(
   parmVarDecl().bind("param"), hasIdentifier(),
@@ -136,8 +139,9 @@ void MissingStdForwardCheck::registerMatchers(MatchFinder 
*Finder) {
   hasAncestor(functionDecl().bind("func")),
   hasAncestor(functionDecl(
   isDefinition(), equalsBoundNode("func"), ToParam,
-  unless(anyOf(isDeleted(),
-   hasDescendant(std::move(ForwardCallMatcher))),
+  unless(anyOf(isDeleted(), hasDescendant(expr(
+
anyOf(std::move(ForwardCallMatcher),
+  
std::move(StaticCast),
   this);
 }
 
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index a23483e6df6d2..c3f41811fa7d7 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -518,6 +518,11 @@ Changes in existing checks
   usages of ``std::string_view::compare``. Added a `StringLikeClasses` option
   to detect usages of ``compare`` method in custom string-like classes.
 
+- Improved :doc:`cppcoreguidelines-missing-std-forward
+  ` check to allow
+  using ``static_cast`` to explicitly convey the intention of using a
+  forwarding reference as an lvalue reference.
+
 Removed checks
 ^^
 
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/missing-std-forward.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/missing-std-forward.rst
index 0c311b59a5d5a..12765b45088de 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/missing-std-forward.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/missing-std-forward.rst
@@ -38,3 +38,6 @@ Example:
 This check implements `F.19
 `_
 from the C++ Core Guidelines.
+
+Users who want to use the forwarding reference as an lvalue reference can 
convey
+the intention by using ``static_cast(t)``.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
index 8116db58c937d..519d2822948bb 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
@@ -211,3 +211,20 @@ template
 void unused_argument3(F&& _) {}
 
 } // namespace unused_arguments
+
+namespace escape_hatch {
+
+template
+void used_as_lvalue_on_purpose(T&& t) {
+  static_cast(t);
+  static_cast(t);
+}
+
+template
+void used_as_rvalue_on_purpose(T&& t) {
+  static_cast(t);
+  // Typically used as another spelling for `std::forward`.
+  static_cast(t);
+}
+
+}

``




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


[clang-tools-extra] [clang-tidy][cppcoreguidelines-missing-std-forward] Do not warn when the parameter is used in a `static_cast`. (PR #99477)

2024-07-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Clement Courbet (legrosbuffle)


Changes

This provides a way to inform the check that we're intending to use an the 
forwarding reference as a specific reference category

Fixes #99474.

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


4 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp 
(+6-2) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+5) 
- (modified) 
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/missing-std-forward.rst
 (+3) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
 (+17) 


``diff
diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
index bbb35228ce47f..726e9fffc628b 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
@@ -129,6 +129,9 @@ void MissingStdForwardCheck::registerMatchers(MatchFinder 
*Finder) {
   unless(anyOf(hasAncestor(typeLoc()),
hasAncestor(expr(hasUnevaluatedContext());
 
+  auto StaticCast = cxxStaticCastExpr(
+  hasSourceExpression(declRefExpr(to(equalsBoundNode("param");
+
   Finder->addMatcher(
   parmVarDecl(
   parmVarDecl().bind("param"), hasIdentifier(),
@@ -136,8 +139,9 @@ void MissingStdForwardCheck::registerMatchers(MatchFinder 
*Finder) {
   hasAncestor(functionDecl().bind("func")),
   hasAncestor(functionDecl(
   isDefinition(), equalsBoundNode("func"), ToParam,
-  unless(anyOf(isDeleted(),
-   hasDescendant(std::move(ForwardCallMatcher))),
+  unless(anyOf(isDeleted(), hasDescendant(expr(
+
anyOf(std::move(ForwardCallMatcher),
+  
std::move(StaticCast),
   this);
 }
 
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index a23483e6df6d2..c3f41811fa7d7 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -518,6 +518,11 @@ Changes in existing checks
   usages of ``std::string_view::compare``. Added a `StringLikeClasses` option
   to detect usages of ``compare`` method in custom string-like classes.
 
+- Improved :doc:`cppcoreguidelines-missing-std-forward
+  ` check to allow
+  using ``static_cast`` to explicitly convey the intention of using a
+  forwarding reference as an lvalue reference.
+
 Removed checks
 ^^
 
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/missing-std-forward.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/missing-std-forward.rst
index 0c311b59a5d5a..12765b45088de 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/missing-std-forward.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/missing-std-forward.rst
@@ -38,3 +38,6 @@ Example:
 This check implements `F.19
 `_
 from the C++ Core Guidelines.
+
+Users who want to use the forwarding reference as an lvalue reference can 
convey
+the intention by using ``static_cast(t)``.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
index 8116db58c937d..519d2822948bb 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
@@ -211,3 +211,20 @@ template
 void unused_argument3(F&& _) {}
 
 } // namespace unused_arguments
+
+namespace escape_hatch {
+
+template
+void used_as_lvalue_on_purpose(T&& t) {
+  static_cast(t);
+  static_cast(t);
+}
+
+template
+void used_as_rvalue_on_purpose(T&& t) {
+  static_cast(t);
+  // Typically used as another spelling for `std::forward`.
+  static_cast(t);
+}
+
+}

``




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


[clang] Handle constant "pointers" for `__atomic_always_lock_free`/`__atomic_is_lock_free`. (PR #99340)

2024-07-18 Thread Aaron Ballman via cfe-commits


@@ -124,6 +124,24 @@ _Static_assert(__atomic_always_lock_free(4, &i64), "");
 _Static_assert(!__atomic_always_lock_free(8, &i32), "");
 _Static_assert(__atomic_always_lock_free(8, &i64), "");
 
+// Validate use with fake pointers constants. This mechanism is used to allow
+// validating atomicity of a given size and alignment.
+_Static_assert(__atomic_is_lock_free(1, (void*)1), "");
+_Static_assert(__atomic_is_lock_free(1, (void*)-1), "");
+_Static_assert(__atomic_is_lock_free(4, (void*)2), ""); // expected-error 
{{not an integral constant expression}}
+_Static_assert(__atomic_is_lock_free(4, (void*)-2), ""); // expected-error 
{{not an integral constant expression}}
+_Static_assert(__atomic_is_lock_free(4, (void*)4), "");
+_Static_assert(__atomic_is_lock_free(4, (void*)-4), "");
+
+_Static_assert(__atomic_always_lock_free(1, (void*)1), "");
+_Static_assert(__atomic_always_lock_free(1, (void*)-1), "");
+_Static_assert(!__atomic_always_lock_free(4, (void*)2), "");
+_Static_assert(!__atomic_always_lock_free(4, (void*)-2), "");
+_Static_assert(__atomic_always_lock_free(4, (void*)4), "");
+_Static_assert(__atomic_always_lock_free(4, (void*)-4), "");

AaronBallman wrote:

I think it should undergo an actual lvalue to rvalue conversion on the operand 
so that we get all the expected conversions like decay. We have the same issue 
with: https://godbolt.org/z/P69vx5W8a or with the even-more-cursed: 
https://godbolt.org/z/zxTbbWbdc

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


[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)

2024-07-18 Thread Chuanqi Xu via cfe-commits


@@ -161,6 +163,7 @@ clang_target_link_libraries(clangDaemon
   clangAST
   clangASTMatchers
   clangBasic
+  clangDependencyScanning

ChuanqiXu9 wrote:

It looks like it comes from 
https://github.com/llvm/llvm-project/blob/b634e057ddecc41dce046887d0f0854fed305374/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp#L489-L490

but clangd didn't touch this function. So it might be possible to split that. 
I'll file an issue to track this.

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


[clang] [llvm] [clang][ARM64EC] Add support for hybrid_patchable attribute. (PR #99478)

2024-07-18 Thread Jacek Caban via cfe-commits

https://github.com/cjacek created 
https://github.com/llvm/llvm-project/pull/99478

This adds support for `hybrid_patchable` on top of LLVM part from #92965 (so it 
depends on #92965 and this PR is meant only for the second commit). For the 
most part, it just adds LLVM attribute whenever C/C++ attribute is specified.

I added a warning when it's used on static function. Due to the way it works 
(emitting a reference to an undefined symbol that linker substitutes with a 
generated thunk), it can't work on static functions. MSVC just silently ignores 
it; using it like that seems like a non-obvious mistake to me, so I followed 
MSVC by allowing it too, but emitting an additional warning.

The patch does nothing special for function inlining, which matches my 
experimentation with MSVC. `hybrid_patchable` functions may be specified on 
inline functions. Depending on optimizations taken, when they are actually 
inlined, it has no effect, but when they are not inlined, it works as expected.

>From b27a1205f893204aca939042f7c17dc7b9196cd4 Mon Sep 17 00:00:00 2001
From: Jacek Caban 
Date: Fri, 3 May 2024 00:24:39 +0200
Subject: [PATCH 1/2] [CodeGen][ARM64EC] Add support for hybrid_patchable
 attribute.

---
 llvm/include/llvm/Bitcode/LLVMBitCodes.h  |   1 +
 llvm/include/llvm/CodeGen/AsmPrinter.h|   2 +-
 llvm/include/llvm/IR/Attributes.td|   3 +
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp |   2 +
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp|   4 +-
 .../AArch64/AArch64Arm64ECCallLowering.cpp| 138 +++-
 llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp |  27 ++
 .../AArch64/AArch64CallingConvention.td   |   2 +-
 llvm/lib/Transforms/Utils/CodeExtractor.cpp   |   1 +
 .../AArch64/arm64ec-hybrid-patchable.ll   | 315 ++
 10 files changed, 484 insertions(+), 11 deletions(-)
 create mode 100644 llvm/test/CodeGen/AArch64/arm64ec-hybrid-patchable.ll

diff --git a/llvm/include/llvm/Bitcode/LLVMBitCodes.h 
b/llvm/include/llvm/Bitcode/LLVMBitCodes.h
index 184bbe32df695..fb88f2fe75adb 100644
--- a/llvm/include/llvm/Bitcode/LLVMBitCodes.h
+++ b/llvm/include/llvm/Bitcode/LLVMBitCodes.h
@@ -757,6 +757,7 @@ enum AttributeKindCodes {
   ATTR_KIND_RANGE = 92,
   ATTR_KIND_SANITIZE_NUMERICAL_STABILITY = 93,
   ATTR_KIND_INITIALIZES = 94,
+  ATTR_KIND_HYBRID_PATCHABLE = 95,
 };
 
 enum ComdatSelectionKindCodes {
diff --git a/llvm/include/llvm/CodeGen/AsmPrinter.h 
b/llvm/include/llvm/CodeGen/AsmPrinter.h
index dc00bd57d655d..1c4e9e9111441 100644
--- a/llvm/include/llvm/CodeGen/AsmPrinter.h
+++ b/llvm/include/llvm/CodeGen/AsmPrinter.h
@@ -892,7 +892,6 @@ class AsmPrinter : public MachineFunctionPass {
   virtual void emitModuleCommandLines(Module &M);
 
   GCMetadataPrinter *getOrCreateGCPrinter(GCStrategy &S);
-  virtual void emitGlobalAlias(const Module &M, const GlobalAlias &GA);
   void emitGlobalIFunc(Module &M, const GlobalIFunc &GI);
 
 private:
@@ -900,6 +899,7 @@ class AsmPrinter : public MachineFunctionPass {
   bool shouldEmitLabelForBasicBlock(const MachineBasicBlock &MBB) const;
 
 protected:
+  virtual void emitGlobalAlias(const Module &M, const GlobalAlias &GA);
   virtual bool shouldEmitWeakSwiftAsyncExtendedFramePointerFlags() const {
 return false;
   }
diff --git a/llvm/include/llvm/IR/Attributes.td 
b/llvm/include/llvm/IR/Attributes.td
index 0457f0c388d26..e1bd193891c1e 100644
--- a/llvm/include/llvm/IR/Attributes.td
+++ b/llvm/include/llvm/IR/Attributes.td
@@ -112,6 +112,9 @@ def ElementType : TypeAttr<"elementtype", [ParamAttr]>;
 /// symbol.
 def FnRetThunkExtern : EnumAttr<"fn_ret_thunk_extern", [FnAttr]>;
 
+/// Function has a hybrid patchable thunk.
+def HybridPatchable : EnumAttr<"hybrid_patchable", [FnAttr]>;
+
 /// Pass structure in an alloca.
 def InAlloca : TypeAttr<"inalloca", [ParamAttr]>;
 
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp 
b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index b3ebe70e8c52f..324dcbca8137e 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -727,6 +727,8 @@ static uint64_t getAttrKindEncoding(Attribute::AttrKind 
Kind) {
 return bitc::ATTR_KIND_HOT;
   case Attribute::ElementType:
 return bitc::ATTR_KIND_ELEMENTTYPE;
+  case Attribute::HybridPatchable:
+return bitc::ATTR_KIND_HYBRID_PATCHABLE;
   case Attribute::InlineHint:
 return bitc::ATTR_KIND_INLINE_HINT;
   case Attribute::InReg:
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp 
b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 1f59ec545b4f7..b46a6d348413b 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -2859,8 +2859,8 @@ bool AsmPrinter::emitSpecialLLVMGlobal(const 
GlobalVariable *GV) {
 auto *Arr = cast(GV->getInitializer());
 for (auto &U : Arr->operands()) {
   auto *C = cast(U);
-  auto *Src = cast(C->getOperand(0)->stripPointerCasts());
-  auto *Dst = cast(C->getOperand(1)->stripPointe

  1   2   3   4   5   >