[clang] [clang-tools-extra] [CLANGD] Do not crash on designator initialization of union (PR #83369)

2024-03-05 Thread via cfe-commits

https://github.com/alirezamoshtaghi updated 
https://github.com/llvm/llvm-project/pull/83369

>From 3d6afe011221ac239bb668b375ed3f6c356fc47d Mon Sep 17 00:00:00 2001
From: alirezamoshtaghi 
Date: Wed, 28 Feb 2024 13:55:11 -0800
Subject: [PATCH 1/3] [CLANGD] Do not crash on designator initialization of
 union

---
 .../clangd/test/designator_init.test  | 31 +++
 clang/lib/AST/Expr.cpp| 14 +++--
 2 files changed, 43 insertions(+), 2 deletions(-)
 create mode 100644 clang-tools-extra/clangd/test/designator_init.test

diff --git a/clang-tools-extra/clangd/test/designator_init.test 
b/clang-tools-extra/clangd/test/designator_init.test
new file mode 100644
index 00..739f2bfab54bcf
--- /dev/null
+++ b/clang-tools-extra/clangd/test/designator_init.test
@@ -0,0 +1,31 @@
+//# RUN: rm -rf %t.dir/* && mkdir -p %t.dir
+//# RUN: echo '[{"directory": "%/t.dir", "command": "clang -x c -c %s", 
"file": "%s"}]' > %t.dir/compile_commands.json
+//# RUN: clangd --compile-commands-dir=%t.dir --check=%s 2>&1 | FileCheck %s
+
+typedef struct S {
+  unsigned char id;
+  union {
+unsigned int mask;
+struct {
+  unsigned int unused:10;
+  unsigned int reserved:3;
+  unsigned int rest:19;
+};
+  };
+} __attribute__((packed)) S_t;
+
+typedef struct H {
+  unsigned char hid;
+  unsigned int val;
+} handler_t;
+
+struct S
+get_foo (handler_t *h)
+{
+  S_t retval =
+{.id=h->hid,
+ .mask=h->val};
+  return retval;
+}
+
+// CHECK: All checks completed, 0 errors
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index b4de2155adcebd..33eeeda89fe7a5 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -4601,11 +4601,21 @@ SourceRange 
DesignatedInitExpr::getDesignatorsSourceRange() const {
 SourceLocation DesignatedInitExpr::getBeginLoc() const {
   auto *DIE = const_cast(this);
   Designator &First = *DIE->getDesignator(0);
-  if (First.isFieldDesignator())
-return GNUSyntax ? First.getFieldLoc() : First.getDotLoc();
+  if (First.isFieldDesignator()) {
+/* search all designators in case the first one is not
+   initialized */
+for (unsigned int i=0; isize(); i++) {
+  Designator &Des = *DIE->getDesignator(i);
+  SourceLocation retval = GNUSyntax ? Des.getFieldLoc() : Des.getDotLoc();
+  if (!retval.isValid ())
+   continue;
+  return retval;
+}
+  }
   return First.getLBracketLoc();
 }
 
+
 SourceLocation DesignatedInitExpr::getEndLoc() const {
   return getInit()->getEndLoc();
 }

>From 397f6cd893a6a07426d39f1dabd7ad27282435af Mon Sep 17 00:00:00 2001
From: alirezamoshtaghi 
Date: Mon, 4 Mar 2024 11:54:56 -0800
Subject: [PATCH 2/3] fix formatting errors

---
 clang/lib/AST/Expr.cpp | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 33eeeda89fe7a5..2e7170ecac0618 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -4602,20 +4602,17 @@ SourceLocation DesignatedInitExpr::getBeginLoc() const {
   auto *DIE = const_cast(this);
   Designator &First = *DIE->getDesignator(0);
   if (First.isFieldDesignator()) {
-/* search all designators in case the first one is not
-   initialized */
-for (unsigned int i=0; isize(); i++) {
+for (unsigned int i = 0; i < DIE->size(); i++) {
   Designator &Des = *DIE->getDesignator(i);
   SourceLocation retval = GNUSyntax ? Des.getFieldLoc() : Des.getDotLoc();
-  if (!retval.isValid ())
-   continue;
+  if (!retval.isValid())
+continue;
   return retval;
 }
   }
   return First.getLBracketLoc();
 }
 
-
 SourceLocation DesignatedInitExpr::getEndLoc() const {
   return getInit()->getEndLoc();
 }

>From d1d1458809e0b27dc05c70ef449ebbe6896437d4 Mon Sep 17 00:00:00 2001
From: alirezamoshtaghi 
Date: Tue, 5 Mar 2024 00:04:52 -0800
Subject: [PATCH 3/3] dont test designator on Windows

---
 clang-tools-extra/clangd/test/designator_init.test | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/clangd/test/designator_init.test 
b/clang-tools-extra/clangd/test/designator_init.test
index 739f2bfab54bcf..4009945ed81fd4 100644
--- a/clang-tools-extra/clangd/test/designator_init.test
+++ b/clang-tools-extra/clangd/test/designator_init.test
@@ -1,7 +1,7 @@
 //# RUN: rm -rf %t.dir/* && mkdir -p %t.dir
 //# RUN: echo '[{"directory": "%/t.dir", "command": "clang -x c -c %s", 
"file": "%s"}]' > %t.dir/compile_commands.json
 //# RUN: clangd --compile-commands-dir=%t.dir --check=%s 2>&1 | FileCheck %s
-
+//# UNSUPPORTED: system-windows
 typedef struct S {
   unsigned char id;
   union {

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


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

2024-03-05 Thread Balazs Benics via cfe-commits

steakhal wrote:

I did some grepping.
Inside the `clang` project:
`^/+=(.*)/(.*)...$`: 297 files
`^/+=([^\n/]*)\.(h|cpp)([^\n/]*)...$`: 1766 files

This suggests to me that indeed, absolute paths are the used way fewer times.

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


[clang] [X86_64] fix empty structure vaarg in c++ (PR #77907)

2024-03-05 Thread Eli Friedman via cfe-commits


@@ -3014,6 +3014,16 @@ Address X86_64ABIInfo::EmitVAArg(CodeGenFunction &CGF, 
Address VAListAddr,
   ABIArgInfo AI = classifyArgumentType(Ty, 0, neededInt, neededSSE,
/*isNamedArg*/false);
 
+  // Empty records are ignored for parameter passing purposes.
+  if (AI.isIgnore()) {
+CharUnits Align = CGF.getContext().getTypeAlignInChars(Ty);
+VAListAddr = CGF.Builder.CreateStructGEP(VAListAddr, 2);
+llvm::Value *Load = CGF.Builder.CreateLoad(VAListAddr);
+llvm::Value *Offset = llvm::ConstantInt::get(CGF.Int32Ty, 0);
+Load = CGF.Builder.CreateGEP(CGF.Int8Ty, Load, Offset);
+return Address(Load, CGF.ConvertTypeForMem(Ty), Align);

efriedma-quic wrote:

I don't think the address here is guaranteed to be appropriately aligned.  It's 
probably better to create a temporary like I suggested before.

Also, a GEP with offset 0 does nothing.

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


[clang] [X86_64] fix empty structure vaarg in c++ (PR #77907)

2024-03-05 Thread Longsheng Mou via cfe-commits


@@ -3014,6 +3014,16 @@ Address X86_64ABIInfo::EmitVAArg(CodeGenFunction &CGF, 
Address VAListAddr,
   ABIArgInfo AI = classifyArgumentType(Ty, 0, neededInt, neededSSE,
/*isNamedArg*/false);
 
+  // Empty records are ignored for parameter passing purposes.
+  if (AI.isIgnore()) {
+CharUnits Align = CGF.getContext().getTypeAlignInChars(Ty);
+VAListAddr = CGF.Builder.CreateStructGEP(VAListAddr, 2);
+llvm::Value *Load = CGF.Builder.CreateLoad(VAListAddr);
+llvm::Value *Offset = llvm::ConstantInt::get(CGF.Int32Ty, 0);
+Load = CGF.Builder.CreateGEP(CGF.Int8Ty, Load, Offset);
+return Address(Load, CGF.ConvertTypeForMem(Ty), Align);

CoTinker wrote:

how to create a temporary?

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


[clang] [analyzer][NFC] Make CheckerDocumentation checker in-sync with actual checker callbacks (PR #83973)

2024-03-05 Thread Balazs Benics via cfe-commits

https://github.com/steakhal created 
https://github.com/llvm/llvm-project/pull/83973

In PR #83677 I was surprised to see that outdated checker callback signatures 
are a problem. It turns out, we need the `registerChecker...` function to 
invoke the `Mgr.registerChecker<>()` which would instantiate the `_register` 
calls, that would take the address of the defined checker callbacks. 
Consequently, if the expected signatires mismatch, it won't complie from now 
on, so we have static guarantee that this issue never pops up again.

Given we need the `register` call, at this point we could just hook this 
checker into the `debug` package and make it never registered. It shouldn't 
hurt anyone :)

>From 8d6e6fe68663d9788a994a214c8f29c5f4e2a958 Mon Sep 17 00:00:00 2001
From: Balazs Benics 
Date: Tue, 5 Mar 2024 09:29:19 +0100
Subject: [PATCH] [analyzer][NFC] Make CheckerDocumentation checker in-sync
 with actual checker callbacks

In PR #83677 I was surprised to see that outdated checker callback
signatures are a problem. It turns out, we need the `registerChecker...`
function to invoke the `Mgr.registerChecker<>()` which would instantiate
the `_register` calls, that would take the address of the defined
checker callbacks. Consequently, if the expected signatires mismatch, it
won't complie from now on, so we have static guarantee that this issue
never pops up again.

Given we need the `register` call, at this point we could just hook this
checker into the `debug` package and make it never registered.
It shouldn't hurt anyone :)
---
 .../clang/StaticAnalyzer/Checkers/Checkers.td   |  4 
 .../Checkers/CheckerDocumentation.cpp   | 13 +
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index a224b81c33a624..686e5e99f4a62c 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -1654,6 +1654,10 @@ def StdCLibraryFunctionsTesterChecker : 
Checker<"StdCLibraryFunctionsTester">,
   WeakDependencies<[StdCLibraryFunctionsChecker]>,
   Documentation;
 
+def CheckerDocumentationChecker : Checker<"CheckerDocumentation">,
+  HelpText<"Defines an empty checker callback for all possible handlers.">,
+  Documentation;
+
 } // end "debug"
 
 
diff --git a/clang/lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp
index 0ca0c487b64550..01e0bed54cc6ed 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp
@@ -137,10 +137,7 @@ class CheckerDocumentation : public Checker< 
check::PreStmt,
   /// (2) and (3). Post-call for the allocator is called after step (1).
   /// Pre-statement for the new-expression is called on step (4) when the value
   /// of the expression is evaluated.
-  /// \param NE The C++ new-expression that triggered the allocation.
-  /// \param Target The allocated region, casted to the class type.
-  void checkNewAllocator(const CXXNewExpr *NE, SVal Target,
- CheckerContext &) const {}
+  void checkNewAllocator(const CXXAllocatorCall &, CheckerContext &) const {}
 
   /// Called on a load from and a store to a location.
   ///
@@ -330,5 +327,13 @@ void CheckerDocumentation::checkPostStmt(const DeclStmt 
*DS,
  CheckerContext &C) const {
 }
 
+void registerCheckerDocumentationChecker(CheckerManager &Mgr) {
+  Mgr.registerChecker();
+}
+
+bool shouldRegisterCheckerDocumentationChecker(const CheckerManager &) {
+  return false;
+}
+
 } // end namespace ento
 } // end namespace clang

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


[clang] [analyzer][NFC] Make CheckerDocumentation checker in-sync with actual checker callbacks (PR #83973)

2024-03-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-static-analyzer-1

Author: Balazs Benics (steakhal)


Changes

In PR #83677 I was surprised to see that outdated checker callback 
signatures are a problem. It turns out, we need the `registerChecker...` 
function to invoke the `Mgr.registerChecker<>()` which would instantiate 
the `_register` calls, that would take the address of the defined checker 
callbacks. Consequently, if the expected signatires mismatch, it won't complie 
from now on, so we have static guarantee that this issue never pops up again.

Given we need the `register` call, at this point we could just hook this 
checker into the `debug` package and make it never registered. It shouldn't 
hurt anyone :)

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


2 Files Affected:

- (modified) clang/include/clang/StaticAnalyzer/Checkers/Checkers.td (+4) 
- (modified) clang/lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp (+9-4) 


``diff
diff --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index a224b81c33a624..686e5e99f4a62c 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -1654,6 +1654,10 @@ def StdCLibraryFunctionsTesterChecker : 
Checker<"StdCLibraryFunctionsTester">,
   WeakDependencies<[StdCLibraryFunctionsChecker]>,
   Documentation;
 
+def CheckerDocumentationChecker : Checker<"CheckerDocumentation">,
+  HelpText<"Defines an empty checker callback for all possible handlers.">,
+  Documentation;
+
 } // end "debug"
 
 
diff --git a/clang/lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp
index 0ca0c487b64550..01e0bed54cc6ed 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp
@@ -137,10 +137,7 @@ class CheckerDocumentation : public Checker< 
check::PreStmt,
   /// (2) and (3). Post-call for the allocator is called after step (1).
   /// Pre-statement for the new-expression is called on step (4) when the value
   /// of the expression is evaluated.
-  /// \param NE The C++ new-expression that triggered the allocation.
-  /// \param Target The allocated region, casted to the class type.
-  void checkNewAllocator(const CXXNewExpr *NE, SVal Target,
- CheckerContext &) const {}
+  void checkNewAllocator(const CXXAllocatorCall &, CheckerContext &) const {}
 
   /// Called on a load from and a store to a location.
   ///
@@ -330,5 +327,13 @@ void CheckerDocumentation::checkPostStmt(const DeclStmt 
*DS,
  CheckerContext &C) const {
 }
 
+void registerCheckerDocumentationChecker(CheckerManager &Mgr) {
+  Mgr.registerChecker();
+}
+
+bool shouldRegisterCheckerDocumentationChecker(const CheckerManager &) {
+  return false;
+}
+
 } // end namespace ento
 } // end namespace clang

``




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


[clang] NFC: format clang/lib/Sema/Sema.cpp (PR #83974)

2024-03-05 Thread Takuto Ikuta via cfe-commits

https://github.com/atetubou created 
https://github.com/llvm/llvm-project/pull/83974

This is to avoid modifying unrelated code when auto format is on in our editor.

>From 8d660f8a15b04285a4218a22944aef902d645b27 Mon Sep 17 00:00:00 2001
From: Takuto Ikuta 
Date: Tue, 5 Mar 2024 17:34:15 +0900
Subject: [PATCH] NFC: format clang/lib/Sema/Sema.cpp

---
 clang/lib/Sema/Sema.cpp | 223 +---
 1 file changed, 118 insertions(+), 105 deletions(-)

diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index cfb653e665ea03..fe00dc3198fdc0 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -269,8 +269,8 @@ void Sema::Initialize() {
 SC->InitializeSema(*this);
 
   // Tell the external Sema source about this Sema object.
-  if (ExternalSemaSource *ExternalSema
-  = dyn_cast_or_null(Context.getExternalSource()))
+  if (ExternalSemaSource *ExternalSema =
+  dyn_cast_or_null(Context.getExternalSource()))
 ExternalSema->InitializeSema(*this);
 
   // This needs to happen after ExternalSemaSource::InitializeSema(this) or we
@@ -295,7 +295,6 @@ void Sema::Initialize() {
   PushOnScopeChains(Context.getUInt128Decl(), TUScope);
   }
 
-
   // Initialize predefined Objective-C types:
   if (getLangOpts().ObjC) {
 // If 'SEL' does not yet refer to any declarations, make it refer to the
@@ -361,7 +360,6 @@ void Sema::Initialize() {
   // 32-bit integer and OpenCLC v2.0, s6.1.1 int is always 32-bit wide.
   addImplicitTypedef("atomic_flag", Context.getAtomicType(Context.IntTy));
 
-
   // OpenCL v2.0 s6.13.11.6:
   // - The atomic_long and atomic_ulong types are supported if the
   //   cl_khr_int64_base_atomics and cl_khr_int64_extended_atomics
@@ -410,7 +408,6 @@ void Sema::Initialize() {
 addImplicitTypedef("atomic_long", AtomicLongT);
 addImplicitTypedef("atomic_ulong", AtomicULongT);
 
-
 if (Context.getTypeSize(Context.getSizeType()) == 64) {
   AddPointerSizeDependentTypes();
 }
@@ -425,17 +422,17 @@ void Sema::Initialize() {
   }
 
   if (Context.getTargetInfo().hasAArch64SVETypes()) {
-#define SVE_TYPE(Name, Id, SingletonId) \
-addImplicitTypedef(Name, Context.SingletonId);
+#define SVE_TYPE(Name, Id, SingletonId)
\
+  addImplicitTypedef(Name, Context.SingletonId);
 #include "clang/Basic/AArch64SVEACLETypes.def"
   }
 
   if (Context.getTargetInfo().getTriple().isPPC64()) {
-#define PPC_VECTOR_MMA_TYPE(Name, Id, Size) \
-  addImplicitTypedef(#Name, Context.Id##Ty);
+#define PPC_VECTOR_MMA_TYPE(Name, Id, Size)
\
+  addImplicitTypedef(#Name, Context.Id##Ty);
 #include "clang/Basic/PPCTypes.def"
-#define PPC_VECTOR_VSX_TYPE(Name, Id, Size) \
-addImplicitTypedef(#Name, Context.Id##Ty);
+#define PPC_VECTOR_VSX_TYPE(Name, Id, Size)
\
+  addImplicitTypedef(#Name, Context.Id##Ty);
 #include "clang/Basic/PPCTypes.def"
   }
 
@@ -467,7 +464,8 @@ Sema::~Sema() {
   assert(InstantiatingSpecializations.empty() &&
  "failed to clean up an InstantiatingTemplate?");
 
-  if (VisContext) FreeVisContext();
+  if (VisContext)
+FreeVisContext();
 
   // Kill all the active scopes.
   for (sema::FunctionScopeInfo *FSI : FunctionScopes)
@@ -478,8 +476,8 @@ Sema::~Sema() {
 SC->ForgetSema();
 
   // Detach from the external Sema source.
-  if (ExternalSemaSource *ExternalSema
-= dyn_cast_or_null(Context.getExternalSource()))
+  if (ExternalSemaSource *ExternalSema =
+  dyn_cast_or_null(Context.getExternalSource()))
 ExternalSema->ForgetSema();
 
   // Delete cached satisfactions.
@@ -517,11 +515,12 @@ void Sema::runWithSufficientStackSpace(SourceLocation Loc,
 /// context.  If we're still in a system header, and we can plausibly
 /// make the relevant declaration unavailable instead of erroring, do
 /// so and return true.
-bool Sema::makeUnavailableInSystemHeader(SourceLocation loc,
-  UnavailableAttr::ImplicitReason reason) {
+bool Sema::makeUnavailableInSystemHeader(
+SourceLocation loc, UnavailableAttr::ImplicitReason reason) {
   // If we're not in a function, it's an error.
   FunctionDecl *fn = dyn_cast(CurContext);
-  if (!fn) return false;
+  if (!fn)
+return false;
 
   // If we're in template instantiation, it's an error.
   if (inTemplateInstantiation())
@@ -532,7 +531,8 @@ bool Sema::makeUnavailableInSystemHeader(SourceLocation loc,
 return false;
 
   // If the function is already unavailable, it's not an error.
-  if (fn->hasAttr()) return true;
+  if (fn->hasAttr())
+return true;
 
   fn->addAttr(UnavailableAttr::CreateImplicit(Context, "", reason, loc));
   return true;
@@ -542,8 +542,8 @@ ASTMutationListener *Sema::getASTMutationListener() const {
   return getASTConsumer().GetASTMutationListener();
 }
 
-///Registers an external source. If an external source already 

[clang] NFC: format clang/lib/Sema/Sema.cpp (PR #83974)

2024-03-05 Thread Takuto Ikuta via cfe-commits

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


[clang] NFC: format clang/lib/Sema/Sema.cpp (PR #83974)

2024-03-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Takuto Ikuta (atetubou)


Changes

This is to avoid modifying unrelated code when auto format is on in our editor.

---

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


1 Files Affected:

- (modified) clang/lib/Sema/Sema.cpp (+118-105) 


``diff
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index cfb653e665ea03..fe00dc3198fdc0 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -269,8 +269,8 @@ void Sema::Initialize() {
 SC->InitializeSema(*this);
 
   // Tell the external Sema source about this Sema object.
-  if (ExternalSemaSource *ExternalSema
-  = dyn_cast_or_null(Context.getExternalSource()))
+  if (ExternalSemaSource *ExternalSema =
+  dyn_cast_or_null(Context.getExternalSource()))
 ExternalSema->InitializeSema(*this);
 
   // This needs to happen after ExternalSemaSource::InitializeSema(this) or we
@@ -295,7 +295,6 @@ void Sema::Initialize() {
   PushOnScopeChains(Context.getUInt128Decl(), TUScope);
   }
 
-
   // Initialize predefined Objective-C types:
   if (getLangOpts().ObjC) {
 // If 'SEL' does not yet refer to any declarations, make it refer to the
@@ -361,7 +360,6 @@ void Sema::Initialize() {
   // 32-bit integer and OpenCLC v2.0, s6.1.1 int is always 32-bit wide.
   addImplicitTypedef("atomic_flag", Context.getAtomicType(Context.IntTy));
 
-
   // OpenCL v2.0 s6.13.11.6:
   // - The atomic_long and atomic_ulong types are supported if the
   //   cl_khr_int64_base_atomics and cl_khr_int64_extended_atomics
@@ -410,7 +408,6 @@ void Sema::Initialize() {
 addImplicitTypedef("atomic_long", AtomicLongT);
 addImplicitTypedef("atomic_ulong", AtomicULongT);
 
-
 if (Context.getTypeSize(Context.getSizeType()) == 64) {
   AddPointerSizeDependentTypes();
 }
@@ -425,17 +422,17 @@ void Sema::Initialize() {
   }
 
   if (Context.getTargetInfo().hasAArch64SVETypes()) {
-#define SVE_TYPE(Name, Id, SingletonId) \
-addImplicitTypedef(Name, Context.SingletonId);
+#define SVE_TYPE(Name, Id, SingletonId)
\
+  addImplicitTypedef(Name, Context.SingletonId);
 #include "clang/Basic/AArch64SVEACLETypes.def"
   }
 
   if (Context.getTargetInfo().getTriple().isPPC64()) {
-#define PPC_VECTOR_MMA_TYPE(Name, Id, Size) \
-  addImplicitTypedef(#Name, Context.Id##Ty);
+#define PPC_VECTOR_MMA_TYPE(Name, Id, Size)
\
+  addImplicitTypedef(#Name, Context.Id##Ty);
 #include "clang/Basic/PPCTypes.def"
-#define PPC_VECTOR_VSX_TYPE(Name, Id, Size) \
-addImplicitTypedef(#Name, Context.Id##Ty);
+#define PPC_VECTOR_VSX_TYPE(Name, Id, Size)
\
+  addImplicitTypedef(#Name, Context.Id##Ty);
 #include "clang/Basic/PPCTypes.def"
   }
 
@@ -467,7 +464,8 @@ Sema::~Sema() {
   assert(InstantiatingSpecializations.empty() &&
  "failed to clean up an InstantiatingTemplate?");
 
-  if (VisContext) FreeVisContext();
+  if (VisContext)
+FreeVisContext();
 
   // Kill all the active scopes.
   for (sema::FunctionScopeInfo *FSI : FunctionScopes)
@@ -478,8 +476,8 @@ Sema::~Sema() {
 SC->ForgetSema();
 
   // Detach from the external Sema source.
-  if (ExternalSemaSource *ExternalSema
-= dyn_cast_or_null(Context.getExternalSource()))
+  if (ExternalSemaSource *ExternalSema =
+  dyn_cast_or_null(Context.getExternalSource()))
 ExternalSema->ForgetSema();
 
   // Delete cached satisfactions.
@@ -517,11 +515,12 @@ void Sema::runWithSufficientStackSpace(SourceLocation Loc,
 /// context.  If we're still in a system header, and we can plausibly
 /// make the relevant declaration unavailable instead of erroring, do
 /// so and return true.
-bool Sema::makeUnavailableInSystemHeader(SourceLocation loc,
-  UnavailableAttr::ImplicitReason reason) {
+bool Sema::makeUnavailableInSystemHeader(
+SourceLocation loc, UnavailableAttr::ImplicitReason reason) {
   // If we're not in a function, it's an error.
   FunctionDecl *fn = dyn_cast(CurContext);
-  if (!fn) return false;
+  if (!fn)
+return false;
 
   // If we're in template instantiation, it's an error.
   if (inTemplateInstantiation())
@@ -532,7 +531,8 @@ bool Sema::makeUnavailableInSystemHeader(SourceLocation loc,
 return false;
 
   // If the function is already unavailable, it's not an error.
-  if (fn->hasAttr()) return true;
+  if (fn->hasAttr())
+return true;
 
   fn->addAttr(UnavailableAttr::CreateImplicit(Context, "", reason, loc));
   return true;
@@ -542,8 +542,8 @@ ASTMutationListener *Sema::getASTMutationListener() const {
   return getASTConsumer().GetASTMutationListener();
 }
 
-///Registers an external source. If an external source already exists,
-/// creates a multiplex external source and appends to it.
+/// Registers an external sour

[clang] [clang][NFC] Format clang/lib/Sema/Sema.cpp (PR #83974)

2024-03-05 Thread Takuto Ikuta via cfe-commits

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


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

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

https://github.com/joker-eph updated 
https://github.com/llvm/llvm-project/pull/83702

>From 41e5c286c29a4fea65f6116f6844b44a3847f9db Mon Sep 17 00:00:00 2001
From: Mehdi Amini 
Date: Mon, 4 Mar 2024 23:21:04 -0800
Subject: [PATCH] Rename llvm::ThreadPool -> llvm::DefaultThreadPool (NFC)

The base class llvm::ThreadPoolInterface will be renamed llvm::ThreadPool
in a subsequent commit.
---
 bolt/include/bolt/Core/ParallelUtilities.h|  4 ++--
 bolt/lib/Core/ParallelUtilities.cpp   | 10 -
 bolt/lib/Passes/IdenticalCodeFolding.cpp  |  2 +-
 bolt/lib/Rewrite/DWARFRewriter.cpp|  2 +-
 bolt/tools/merge-fdata/merge-fdata.cpp|  2 +-
 .../clang-doc/tool/ClangDocMain.cpp   |  2 +-
 .../tool/FindAllSymbolsMain.cpp   |  2 +-
 clang/lib/Tooling/AllTUsExecution.cpp |  2 +-
 lld/MachO/Writer.cpp  |  2 +-
 lldb/source/Core/Debugger.cpp |  2 +-
 llvm/docs/ORCv2.rst   |  2 +-
 .../SpeculativeJIT/SpeculativeJIT.cpp |  2 +-
 llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h |  2 +-
 llvm/include/llvm/Support/ThreadPool.h|  7 +++---
 llvm/lib/CodeGen/ParallelCG.cpp   |  2 +-
 llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp  |  2 +-
 .../DWARFLinker/Parallel/DWARFLinkerImpl.cpp  |  2 +-
 llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp  |  2 +-
 llvm/lib/ExecutionEngine/Orc/LLJIT.cpp|  4 ++--
 llvm/lib/LTO/LTO.cpp  |  2 +-
 llvm/lib/LTO/LTOBackend.cpp   |  2 +-
 llvm/lib/LTO/ThinLTOCodeGenerator.cpp |  4 ++--
 llvm/lib/Support/BalancedPartitioning.cpp |  2 +-
 llvm/tools/dsymutil/dsymutil.cpp  |  2 +-
 llvm/tools/llvm-cov/CodeCoverage.cpp  |  2 +-
 llvm/tools/llvm-cov/CoverageExporterJson.cpp  |  2 +-
 llvm/tools/llvm-cov/CoverageReport.cpp|  4 ++--
 .../tools/llvm-debuginfod/llvm-debuginfod.cpp |  2 +-
 llvm/tools/llvm-profdata/llvm-profdata.cpp|  2 +-
 llvm/tools/llvm-reduce/deltas/Delta.cpp   |  6 ++---
 llvm/unittests/ADT/LazyAtomicPointerTest.cpp  |  4 ++--
 llvm/unittests/Debuginfod/HTTPServerTests.cpp | 16 +++---
 llvm/unittests/Support/ParallelTest.cpp   |  2 +-
 llvm/unittests/Support/ThreadPool.cpp | 22 +--
 .../Support/ThreadSafeAllocatorTest.cpp   |  6 ++---
 mlir/lib/CAPI/IR/Support.cpp  |  2 +-
 mlir/lib/ExecutionEngine/AsyncRuntime.cpp |  4 ++--
 mlir/lib/IR/MLIRContext.cpp   |  4 ++--
 38 files changed, 72 insertions(+), 73 deletions(-)

diff --git a/bolt/include/bolt/Core/ParallelUtilities.h 
b/bolt/include/bolt/Core/ParallelUtilities.h
index e510525bc51d00..e7b35a79acc78c 100644
--- a/bolt/include/bolt/Core/ParallelUtilities.h
+++ b/bolt/include/bolt/Core/ParallelUtilities.h
@@ -49,8 +49,8 @@ enum SchedulingPolicy {
   SP_BB_QUADRATIC,   /// cost is estimated by the square of the BB count
 };
 
-/// Return the managed thread pool and initialize it if not initiliazed.
-ThreadPool &getThreadPool();
+/// Return the managed thread pool and initialize it if not initialized.
+ThreadPoolInterface &getThreadPool();
 
 /// Perform the work on each BinaryFunction except those that are accepted
 /// by SkipPredicate, scheduling heuristic is based on SchedPolicy.
diff --git a/bolt/lib/Core/ParallelUtilities.cpp 
b/bolt/lib/Core/ParallelUtilities.cpp
index 1a28bc4346ecd5..5f5e96e0e7881c 100644
--- a/bolt/lib/Core/ParallelUtilities.cpp
+++ b/bolt/lib/Core/ParallelUtilities.cpp
@@ -49,7 +49,7 @@ namespace ParallelUtilities {
 
 namespace {
 /// A single thread pool that is used to run parallel tasks
-std::unique_ptr ThreadPoolPtr;
+std::unique_ptr ThreadPoolPtr;
 
 unsigned computeCostFor(const BinaryFunction &BF,
 const PredicateTy &SkipPredicate,
@@ -102,11 +102,11 @@ inline unsigned estimateTotalCost(const BinaryContext &BC,
 
 } // namespace
 
-ThreadPool &getThreadPool() {
+ThreadPoolInterface &getThreadPool() {
   if (ThreadPoolPtr.get())
 return *ThreadPoolPtr;
 
-  ThreadPoolPtr = std::make_unique(
+  ThreadPoolPtr = std::make_unique(
   llvm::hardware_concurrency(opts::ThreadCount));
   return *ThreadPoolPtr;
 }
@@ -145,7 +145,7 @@ void runOnEachFunction(BinaryContext &BC, SchedulingPolicy 
SchedPolicy,
   TotalCost > BlocksCount ? TotalCost / BlocksCount : 1;
 
   // Divide work into blocks of equal cost
-  ThreadPool &Pool = getThreadPool();
+  ThreadPoolInterface &Pool = getThreadPool();
   auto BlockBegin = BC.getBinaryFunctions().begin();
   unsigned CurrentCost = 0;
 
@@ -202,7 +202,7 @@ void runOnEachFunctionWithUniqueAllocId(
   TotalCost > BlocksCount ? TotalCost / BlocksCount : 1;
 
   // Divide work into blocks of equal cost
-  ThreadPool &Pool = getThreadPool();
+  ThreadPoolInterface &Pool = getThreadPool();
   auto BlockBegin = BC.getBinaryFunctions().begin();
   unsigned CurrentCost = 0;
   unsigned AllocId = 1;
diff --git a/bolt/lib/Passes/Id

[clang] [clang][NFC] Format clang/lib/Sema/Sema.cpp (PR #83974)

2024-03-05 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

I remember we have policies that we don't like patches which purely formats 
codes. It makes backporting and cherry-picking harder. But I can't find the 
wording now.

CC: @AaronBallman @Endilll 

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


[clang] [clang][nullability] Don't discard expression state before end of full-expression. (PR #82611)

2024-03-05 Thread via cfe-commits

martinboehme wrote:

> I'm a little concerned with the complexity and cost required to support this 
> optimization. With this added cost, do you know if the analysis still faster 
> (and less SAT timeouts?) than if we just did the simple thing of not dropping 
> state?

Yes, significantly faster and fewer SAT timeouts.

To compare against the alternative of not dropping state, I reverse-applied 
#72985, then ran benchmarks for the Crubit nullability check and looked at the 
number of SAT solver timeouts when running the nullability check on an internal 
codebase.

Benchmark results show that this patch ("old") performs significantly better 
than reverse-applied #72985 ("new"):

```
name  old cpu/op   new cpu/op   delta
BM_PointerAnalysisCopyPointer 72.4µs ± 4%  71.0µs ± 4%   -1.94%  (p=0.006 
n=19+19)
BM_PointerAnalysisIntLoop  191µs ± 3%   237µs ± 3%  +24.50%  (p=0.000 
n=19+20)
BM_PointerAnalysisPointerLoop  326µs ± 3%   405µs ± 3%  +24.16%  (p=0.000 
n=17+19)
BM_PointerAnalysisBranch   192µs ± 3%   186µs ± 4%   -3.26%  (p=0.000 
n=20+20)
BM_PointerAnalysisLoopAndBranch523µs ± 4%   690µs ± 5%  +31.95%  (p=0.000 
n=20+20)
BM_PointerAnalysisTwoLoops 339µs ± 3%   445µs ± 2%  +31.49%  (p=0.000 
n=20+20)
BM_PointerAnalysisJoinFilePath1.62ms ± 3%  2.04ms ± 4%  +25.65%  (p=0.000 
n=20+20)
BM_PointerAnalysisCallInLoop  1.15ms ± 4%  1.48ms ± 4%  +29.03%  (p=0.000 
n=19+19)
```

Regarding SAT solver timeouts, on the codebase I looked at, reverse-applied 
#72985 results in over four times as many SAT solver timeouts as this patch. 
This is because reverse-applied #72985 performs joins on entries in `ExprToVal` 
that could simply have been discarded, and those joins often require calling 
the SAT solver.

I'll address the code-level comments next but wanted to get this high-level 
comment out first.

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


[clang] [clang][NFC] Format clang/lib/Sema/Sema.cpp (PR #83974)

2024-03-05 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

Oh, I found it here: https://llvm.org/docs/CodingStandards.html#introduction

> Our long term goal is for the entire codebase to follow the convention, but 
> we explicitly do not want patches that do large-scale reformatting of 
> existing code.

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


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

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

https://github.com/joker-eph updated 
https://github.com/llvm/llvm-project/pull/83702

>From f961f22a3643673c1f3a040715dcfa2887ee1dca Mon Sep 17 00:00:00 2001
From: Mehdi Amini 
Date: Mon, 4 Mar 2024 23:21:04 -0800
Subject: [PATCH] Rename llvm::ThreadPool -> llvm::DefaultThreadPool (NFC)

The base class llvm::ThreadPoolInterface will be renamed llvm::ThreadPool
in a subsequent commit.
---
 bolt/include/bolt/Core/ParallelUtilities.h|  4 ++--
 bolt/lib/Core/ParallelUtilities.cpp   | 10 -
 bolt/lib/Passes/IdenticalCodeFolding.cpp  |  2 +-
 bolt/lib/Rewrite/DWARFRewriter.cpp|  2 +-
 bolt/tools/merge-fdata/merge-fdata.cpp|  2 +-
 .../clang-doc/tool/ClangDocMain.cpp   |  2 +-
 .../tool/FindAllSymbolsMain.cpp   |  2 +-
 clang/lib/Tooling/AllTUsExecution.cpp |  2 +-
 clang/tools/clang-scan-deps/ClangScanDeps.cpp |  2 +-
 lld/MachO/Writer.cpp  |  2 +-
 lldb/source/Core/Debugger.cpp |  4 ++--
 llvm/docs/ORCv2.rst   |  2 +-
 .../SpeculativeJIT/SpeculativeJIT.cpp |  2 +-
 llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h |  2 +-
 llvm/include/llvm/Support/ThreadPool.h|  7 +++---
 llvm/lib/CodeGen/ParallelCG.cpp   |  2 +-
 llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp  |  2 +-
 .../DWARFLinker/Parallel/DWARFLinkerImpl.cpp  |  2 +-
 llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp  |  2 +-
 llvm/lib/ExecutionEngine/Orc/LLJIT.cpp|  4 ++--
 llvm/lib/LTO/LTO.cpp  |  2 +-
 llvm/lib/LTO/LTOBackend.cpp   |  2 +-
 llvm/lib/LTO/ThinLTOCodeGenerator.cpp |  4 ++--
 llvm/lib/Support/BalancedPartitioning.cpp |  2 +-
 llvm/tools/dsymutil/dsymutil.cpp  |  2 +-
 llvm/tools/llvm-cov/CodeCoverage.cpp  |  2 +-
 llvm/tools/llvm-cov/CoverageExporterJson.cpp  |  2 +-
 llvm/tools/llvm-cov/CoverageReport.cpp|  4 ++--
 .../tools/llvm-debuginfod/llvm-debuginfod.cpp |  2 +-
 llvm/tools/llvm-profdata/llvm-profdata.cpp|  2 +-
 llvm/tools/llvm-reduce/deltas/Delta.cpp   |  6 ++---
 llvm/unittests/ADT/LazyAtomicPointerTest.cpp  |  4 ++--
 llvm/unittests/Debuginfod/HTTPServerTests.cpp | 16 +++---
 llvm/unittests/Support/ParallelTest.cpp   |  2 +-
 llvm/unittests/Support/ThreadPool.cpp | 22 +--
 .../Support/ThreadSafeAllocatorTest.cpp   |  6 ++---
 mlir/include/mlir/IR/MLIRContext.h|  2 +-
 mlir/lib/CAPI/IR/Support.cpp  |  2 +-
 mlir/lib/ExecutionEngine/AsyncRuntime.cpp |  4 ++--
 mlir/lib/IR/MLIRContext.cpp   |  4 ++--
 40 files changed, 75 insertions(+), 76 deletions(-)

diff --git a/bolt/include/bolt/Core/ParallelUtilities.h 
b/bolt/include/bolt/Core/ParallelUtilities.h
index e510525bc51d00..e7b35a79acc78c 100644
--- a/bolt/include/bolt/Core/ParallelUtilities.h
+++ b/bolt/include/bolt/Core/ParallelUtilities.h
@@ -49,8 +49,8 @@ enum SchedulingPolicy {
   SP_BB_QUADRATIC,   /// cost is estimated by the square of the BB count
 };
 
-/// Return the managed thread pool and initialize it if not initiliazed.
-ThreadPool &getThreadPool();
+/// Return the managed thread pool and initialize it if not initialized.
+ThreadPoolInterface &getThreadPool();
 
 /// Perform the work on each BinaryFunction except those that are accepted
 /// by SkipPredicate, scheduling heuristic is based on SchedPolicy.
diff --git a/bolt/lib/Core/ParallelUtilities.cpp 
b/bolt/lib/Core/ParallelUtilities.cpp
index 1a28bc4346ecd5..5f5e96e0e7881c 100644
--- a/bolt/lib/Core/ParallelUtilities.cpp
+++ b/bolt/lib/Core/ParallelUtilities.cpp
@@ -49,7 +49,7 @@ namespace ParallelUtilities {
 
 namespace {
 /// A single thread pool that is used to run parallel tasks
-std::unique_ptr ThreadPoolPtr;
+std::unique_ptr ThreadPoolPtr;
 
 unsigned computeCostFor(const BinaryFunction &BF,
 const PredicateTy &SkipPredicate,
@@ -102,11 +102,11 @@ inline unsigned estimateTotalCost(const BinaryContext &BC,
 
 } // namespace
 
-ThreadPool &getThreadPool() {
+ThreadPoolInterface &getThreadPool() {
   if (ThreadPoolPtr.get())
 return *ThreadPoolPtr;
 
-  ThreadPoolPtr = std::make_unique(
+  ThreadPoolPtr = std::make_unique(
   llvm::hardware_concurrency(opts::ThreadCount));
   return *ThreadPoolPtr;
 }
@@ -145,7 +145,7 @@ void runOnEachFunction(BinaryContext &BC, SchedulingPolicy 
SchedPolicy,
   TotalCost > BlocksCount ? TotalCost / BlocksCount : 1;
 
   // Divide work into blocks of equal cost
-  ThreadPool &Pool = getThreadPool();
+  ThreadPoolInterface &Pool = getThreadPool();
   auto BlockBegin = BC.getBinaryFunctions().begin();
   unsigned CurrentCost = 0;
 
@@ -202,7 +202,7 @@ void runOnEachFunctionWithUniqueAllocId(
   TotalCost > BlocksCount ? TotalCost / BlocksCount : 1;
 
   // Divide work into blocks of equal cost
-  ThreadPool &Pool = getThreadPool();
+  ThreadPoolInterface &Pool = getThreadPool();
   auto BlockBegin = BC.get

[clang] [clang][NFC] Regroup declarations in `Sema` (PR #82217)

2024-03-05 Thread via cfe-commits

cor3ntin wrote:

Please run clang-format as a separate PR (before this one) - this will help 
folks deal with merge conflicts. Thanks

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


[clang] [C++20] [Modules] Introduce reduced BMI (PR #75894)

2024-03-05 Thread Iain Sandoe via cfe-commits

iains wrote:


* I do not want to block progress, so let's move forward with this patch for 
now.

* It seems to me (as we found with GMF decl elision) that the process is quite 
a bit more complex than simply omitting a decl.  We need to elide other decls 
that are then unused (e.g. decls local to an elided function body) and also 
avoid emitting types that are now no longer existent.

The process seems to me to be either one of:
 - rewriting the AST (which is why my patch set picked the use of the plugin 
API since that is the purpose there).
 - walking the AST and marking entities as used / not used / elided.
 
 It still feels to me to be better to have clear separation of this work from 
the work of streaming - but if we can make clear layers within the streaming, 
then maybe the maintenance will not be too hard.


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


[clang] [clang][NFC] Format clang/lib/Sema/Sema.cpp (PR #83974)

2024-03-05 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

Bulk formatting of Clang is still under discussion in 
https://discourse.llvm.org/t/rfc-clang-format-all-the-things/76614. At least I 
don't see a consensus called there one way or another.

Our [developer policy](https://llvm.org/docs/DeveloperPolicy.html) states the 
following:
> Avoid committing formatting- or whitespace-only changes outside of code you 
> plan to make subsequent changes to.

So yeah, we can't merge this at the moment, unfortunately. This might change in 
the future, though, as more people lean towards bulk formatting after several 
years of very slow gradual reformatting with accordance to our current policy.

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


[clang] [C++20] [Modules] Introduce reduced BMI (PR #75894)

2024-03-05 Thread Iain Sandoe via cfe-commits


@@ -830,6 +843,19 @@ class PCHGenerator : public SemaConsumer {
   bool hasEmittedPCH() const { return Buffer->IsComplete; }
 };
 
+class ReducedBMIGenerator : public PCHGenerator {
+public:
+  ReducedBMIGenerator(const Preprocessor &PP, InMemoryModuleCache &ModuleCache,
+  StringRef OutputFile, std::shared_ptr Buffer,
+  bool IncludeTimestamps);
+
+  void HandleTranslationUnit(ASTContext &Ctx) override;
+};
+
+/// If the definition may impact the ABI. If yes, we're allowed to eliminate
+/// the definition of D in reduced BMI.
+bool MayDefAffectABI(const Decl *D);

iains wrote:

Perhaps this would be better named ShouldElideDecl?
I also find the comment a bit confusing - normally if something affects ABI we 
cannot change it (so I think we really mean that this would introduce a break 
into the 'module interface ABI').  Maybe the comment could better refer to the 
bug and/or descriiption of the issue.

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


[clang] [Clang] Fix looking for immediate calls in default arguments. (PR #80690)

2024-03-05 Thread via cfe-commits

https://github.com/cor3ntin updated 
https://github.com/llvm/llvm-project/pull/80690

>From 690a251c4d8df2099b213ba63e9836c2752b5ac1 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Mon, 5 Feb 2024 15:42:21 +0100
Subject: [PATCH 1/2] [Clang] Fix looking for immediate calls in default
 arguments.

Due to improper use of RecursiveASTVisitor.

Fixes #80630
---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaExpr.cpp|  6 +++---
 .../SemaCXX/cxx2a-consteval-default-params.cpp | 15 +++
 clang/test/SemaCXX/source_location.cpp | 18 ++
 4 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c239c97f7afc91..9ebff537e11079 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -294,6 +294,8 @@ Bug Fixes to C++ Support
   instead of only on class, alias, and variable templates, as last updated by
   CWG2032. Fixes (#GH#83461)
 
+- Fix evaluation of some immediate calls in default arguments.
+  Fixes (#GH80630)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 0a449fc1082bd4..9b4c3440448ba8 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6199,7 +6199,7 @@ struct ImmediateCallVisitor : public 
RecursiveASTVisitor {
   bool VisitCallExpr(CallExpr *E) {
 if (const FunctionDecl *FD = E->getDirectCallee())
   HasImmediateCalls |= FD->isImmediateFunction();
-return RecursiveASTVisitor::VisitStmt(E);
+return RecursiveASTVisitor::VisitCallExpr(E);
   }
 
   bool VisitCXXConstructExpr(CXXConstructExpr *E) {
@@ -6229,9 +6229,9 @@ struct ImmediateCallVisitor : public 
RecursiveASTVisitor {
 
   // Blocks don't support default parameters, and, as for lambdas,
   // we don't consider their body a subexpression.
-  bool VisitBlockDecl(BlockDecl *B) { return false; }
+  bool VisitBlockDecl(BlockDecl *B) { return true; }
 
-  bool VisitCompoundStmt(CompoundStmt *B) { return false; }
+  bool VisitCompoundStmt(CompoundStmt *B) { return true; }
 
   bool VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
 return TraverseStmt(E->getExpr());
diff --git a/clang/test/SemaCXX/cxx2a-consteval-default-params.cpp 
b/clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
index be8f7cc788589f..e4b13725b2dacd 100644
--- a/clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
+++ b/clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
@@ -82,3 +82,18 @@ namespace GH62224 {
   C<> Val; // No error since fwd is defined already.
   static_assert(Val.get() == 42);
 }
+
+namespace GH80630 {
+
+consteval const char* ce() { return "Hello"; }
+
+auto f2(const char* loc = []( char const* fn )
+{ return fn; }  ( ce() ) ) {
+return loc;
+}
+
+auto g() {
+return f2();
+}
+
+}
diff --git a/clang/test/SemaCXX/source_location.cpp 
b/clang/test/SemaCXX/source_location.cpp
index 7414fbce7828d1..b151fc45fdad62 100644
--- a/clang/test/SemaCXX/source_location.cpp
+++ b/clang/test/SemaCXX/source_location.cpp
@@ -832,3 +832,21 @@ void test() {
 }
 
 }
+
+namespace GH80630 {
+
+#define GH80630_LAMBDA \
+[]( char const* fn ) { \
+static constexpr std::source_location loc = 
std::source_location::current(); \
+return &loc; \
+}( std::source_location::current().function() )
+
+auto f( std::source_location const* loc = GH80630_LAMBDA ) {
+return loc;
+}
+
+auto g() {
+return f();
+}
+
+}

>From 077db5232f786b1298ae01edc4f8e2b165aef80a Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Sun, 18 Feb 2024 14:45:22 +0100
Subject: [PATCH 2/2] Address Aaron's feedback

---
 clang/lib/Sema/SemaExpr.cpp | 8 +---
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 9b4c3440448ba8..47bb263f56aade 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6199,7 +6199,7 @@ struct ImmediateCallVisitor : public 
RecursiveASTVisitor {
   bool VisitCallExpr(CallExpr *E) {
 if (const FunctionDecl *FD = E->getDirectCallee())
   HasImmediateCalls |= FD->isImmediateFunction();
-return RecursiveASTVisitor::VisitCallExpr(E);
+return RecursiveASTVisitor::VisitStmt(E);
   }
 
   bool VisitCXXConstructExpr(CXXConstructExpr *E) {
@@ -6227,12 +6227,6 @@ struct ImmediateCallVisitor : public 
RecursiveASTVisitor {
 return VisitCXXMethodDecl(E->getCallOperator());
   }
 
-  // Blocks don't support default parameters, and, as for lambdas,
-  // we don't consider their body a subexpression.
-  bool VisitBlockDecl(BlockDecl *B) { return true; }
-
-  bool VisitCompoundStmt(CompoundStmt *B) { return true; }
-
   bool VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
 return TraverseStmt(E->getExpr());
   }

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

[clang] [Clang] Fix looking for immediate calls in default arguments. (PR #80690)

2024-03-05 Thread via cfe-commits

cor3ntin wrote:

> Does this fix #67134 as well?

I don't think so, no 

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


[clang] d773c00 - [Clang] Fix looking for immediate calls in default arguments. (#80690)

2024-03-05 Thread via cfe-commits

Author: cor3ntin
Date: 2024-03-05T10:04:45+01:00
New Revision: d773c00e52f1acd68267c6f2f5bfa269b73810a0

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

LOG: [Clang] Fix looking for immediate calls in default arguments. (#80690)

Due to improper use of RecursiveASTVisitor.

Fixes #80630

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
clang/test/SemaCXX/source_location.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 612b4329727455..b94e491de5e468 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -298,6 +298,8 @@ Bug Fixes to C++ Support
 - Fixed an issue where an attribute on a declarator would cause the attribute 
to
   be destructed prematurely. This fixes a pair of Chromium that were brought to
   our attention by an attempt to fix in (#GH77703). Fixes (#GH83385).
+- Fix evaluation of some immediate calls in default arguments.
+  Fixes (#GH80630)
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 0a449fc1082bd4..47bb263f56aade 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6227,12 +6227,6 @@ struct ImmediateCallVisitor : public 
RecursiveASTVisitor {
 return VisitCXXMethodDecl(E->getCallOperator());
   }
 
-  // Blocks don't support default parameters, and, as for lambdas,
-  // we don't consider their body a subexpression.
-  bool VisitBlockDecl(BlockDecl *B) { return false; }
-
-  bool VisitCompoundStmt(CompoundStmt *B) { return false; }
-
   bool VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
 return TraverseStmt(E->getExpr());
   }

diff  --git a/clang/test/SemaCXX/cxx2a-consteval-default-params.cpp 
b/clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
index be8f7cc788589f..e4b13725b2dacd 100644
--- a/clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
+++ b/clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
@@ -82,3 +82,18 @@ namespace GH62224 {
   C<> Val; // No error since fwd is defined already.
   static_assert(Val.get() == 42);
 }
+
+namespace GH80630 {
+
+consteval const char* ce() { return "Hello"; }
+
+auto f2(const char* loc = []( char const* fn )
+{ return fn; }  ( ce() ) ) {
+return loc;
+}
+
+auto g() {
+return f2();
+}
+
+}

diff  --git a/clang/test/SemaCXX/source_location.cpp 
b/clang/test/SemaCXX/source_location.cpp
index 7414fbce7828d1..b151fc45fdad62 100644
--- a/clang/test/SemaCXX/source_location.cpp
+++ b/clang/test/SemaCXX/source_location.cpp
@@ -832,3 +832,21 @@ void test() {
 }
 
 }
+
+namespace GH80630 {
+
+#define GH80630_LAMBDA \
+[]( char const* fn ) { \
+static constexpr std::source_location loc = 
std::source_location::current(); \
+return &loc; \
+}( std::source_location::current().function() )
+
+auto f( std::source_location const* loc = GH80630_LAMBDA ) {
+return loc;
+}
+
+auto g() {
+return f();
+}
+
+}



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


[clang] [Clang] Fix looking for immediate calls in default arguments. (PR #80690)

2024-03-05 Thread via cfe-commits

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


[clang] [llvm] [RISCV] Support RISC-V Profiles in -march option (PR #76357)

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

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

>From bd9b759d853d8196ae893a90442a3c3e7e5fa74d Mon Sep 17 00:00:00 2001
From: wangpc 
Date: Mon, 25 Dec 2023 18:52:36 +0800
Subject: [PATCH] [RFC][RISCV] Support RISC-V Profiles in -march option

This PR implements the draft
https://github.com/riscv-non-isa/riscv-toolchain-conventions/pull/36.

Currently, we replace specified profile in `-march` with standard
arch string.
---
 clang/test/Driver/riscv-profiles.c   | 324 +++
 llvm/include/llvm/Support/RISCVISAInfo.h |   2 +
 llvm/lib/Support/RISCVISAInfo.cpp|  76 ++
 llvm/lib/Target/RISCV/RISCV.td   |   6 +
 llvm/lib/Target/RISCV/RISCVProfiles.td   | 189 +
 llvm/lib/Target/RISCV/RISCVSubtarget.h   |  19 ++
 llvm/test/CodeGen/RISCV/attributes.ll|  25 ++
 7 files changed, 641 insertions(+)
 create mode 100644 clang/test/Driver/riscv-profiles.c
 create mode 100644 llvm/lib/Target/RISCV/RISCVProfiles.td

diff --git a/clang/test/Driver/riscv-profiles.c 
b/clang/test/Driver/riscv-profiles.c
new file mode 100644
index 00..8d1a7faf607838
--- /dev/null
+++ b/clang/test/Driver/riscv-profiles.c
@@ -0,0 +1,324 @@
+// RUN: %clang -### -c %s 2>&1 -march=rvi20u32 | FileCheck 
-check-prefix=RVI20U32 %s
+// RVI20U32: "-target-feature" "-a"
+// RVI20U32: "-target-feature" "-c"
+// RVI20U32: "-target-feature" "-d"
+// RVI20U32: "-target-feature" "-f"
+// RVI20U32: "-target-feature" "-m"
+// RVI20U32: "-target-feature" "+rvi20u32"
+
+// RUN: %clang -### -c %s 2>&1 -march=rvi20u64 | FileCheck 
-check-prefix=RVI20U64 %s
+// RVI20U64: "-target-feature" "-a"
+// RVI20U64: "-target-feature" "-c"
+// RVI20U64: "-target-feature" "-d"
+// RVI20U64: "-target-feature" "-f"
+// RVI20U64: "-target-feature" "-m"
+// RVI20U64: "-target-feature" "+rvi20u64"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva20u64 | FileCheck 
-check-prefix=RVA20U64 %s
+// RVA20U64: "-target-feature" "+m"
+// RVA20U64: "-target-feature" "+a"
+// RVA20U64: "-target-feature" "+f"
+// RVA20U64: "-target-feature" "+d"
+// RVA20U64: "-target-feature" "+c"
+// RVA20U64: "-target-feature" "+ziccamoa"
+// RVA20U64: "-target-feature" "+ziccif"
+// RVA20U64: "-target-feature" "+zicclsm"
+// RVA20U64: "-target-feature" "+ziccrse"
+// RVA20U64: "-target-feature" "+zicntr"
+// RVA20U64: "-target-feature" "+zicsr"
+// RVA20U64: "-target-feature" "+za128rs"
+// RVA20U64: "-target-feature" "+rva20u64"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva20s64 | FileCheck 
-check-prefix=RVA20S64 %s
+// RVA20S64: "-target-feature" "+m"
+// RVA20S64: "-target-feature" "+a"
+// RVA20S64: "-target-feature" "+f"
+// RVA20S64: "-target-feature" "+d"
+// RVA20S64: "-target-feature" "+c"
+// RVA20S64: "-target-feature" "+ziccamoa"
+// RVA20S64: "-target-feature" "+ziccif"
+// RVA20S64: "-target-feature" "+zicclsm"
+// RVA20S64: "-target-feature" "+ziccrse"
+// RVA20S64: "-target-feature" "+zicntr"
+// RVA20S64: "-target-feature" "+zicsr"
+// RVA20S64: "-target-feature" "+zifencei"
+// RVA20S64: "-target-feature" "+za128rs"
+// RVA20S64: "-target-feature" "+ssccptr"
+// RVA20S64: "-target-feature" "+sstvala"
+// RVA20S64: "-target-feature" "+sstvecd"
+// RVA20S64: "-target-feature" "+svade"
+// RVA20S64: "-target-feature" "+svbare"
+// RVA20S64: "-target-feature" "+rva20s64"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva22u64 | FileCheck 
-check-prefix=RVA22U64 %s
+// RVA22U64: "-target-feature" "+m"
+// RVA22U64: "-target-feature" "+a"
+// RVA22U64: "-target-feature" "+f"
+// RVA22U64: "-target-feature" "+d"
+// RVA22U64: "-target-feature" "+c"
+// RVA22U64: "-target-feature" "+zic64b"
+// RVA22U64: "-target-feature" "+zicbom"
+// RVA22U64: "-target-feature" "+zicbop"
+// RVA22U64: "-target-feature" "+zicboz"
+// RVA22U64: "-target-feature" "+ziccamoa"
+// RVA22U64: "-target-feature" "+ziccif"
+// RVA22U64: "-target-feature" "+zicclsm"
+// RVA22U64: "-target-feature" "+ziccrse"
+// RVA22U64: "-target-feature" "+zicntr"
+// RVA22U64: "-target-feature" "+zicsr"
+// RVA22U64: "-target-feature" "+zihintpause"
+// RVA22U64: "-target-feature" "+zihpm"
+// RVA22U64: "-target-feature" "+za64rs"
+// RVA22U64: "-target-feature" "+zfhmin"
+// RVA22U64: "-target-feature" "+zba"
+// RVA22U64: "-target-feature" "+zbb"
+// RVA22U64: "-target-feature" "+zbs"
+// RVA22U64: "-target-feature" "+zkt"
+// RVA22U64: "-target-feature" "+rva22u64"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva22s64 | FileCheck 
-check-prefix=RVA22S64 %s
+// RVA22S64: "-target-feature" "+m"
+// RVA22S64: "-target-feature" "+a"
+// RVA22S64: "-target-feature" "+f"
+// RVA22S64: "-target-feature" "+d"
+// RVA22S64: "-target-feature" "+c"
+// RVA22S64: "-target-feature" "+zic64b"
+// RVA22S64: "-target-feature" "+zicbom"
+// RVA22S64: "-target-feature" "+zicbop"
+// RVA22S64: "-target-feature" "+zicboz"
+// RVA22S64: "-target-feature" "+ziccamoa"
+// RVA22S64: "-target-feature" "+ziccif"
+// RVA22S64: "-target-feature" "+zicclsm"
+// RVA22S6

[clang] [clang][NFC] Format clang/lib/Sema/Sema.cpp (PR #83974)

2024-03-05 Thread Takuto Ikuta via cfe-commits

atetubou wrote:

Thank you for references both.

Actually, I'd like to have PR like 
https://github.com/llvm/llvm-project/pull/83961.
Is it acceptable to merge this kind of PR in that case then?

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


[clang] 690bf64 - [clang] Support `__is_trivially_copyable(int()&)==false` (#81298)

2024-03-05 Thread via cfe-commits

Author: Amirreza Ashouri
Date: 2024-03-05T10:07:00+01:00
New Revision: 690bf64f077a281d434537b0907c9fc170123dcc

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

LOG: [clang] Support `__is_trivially_copyable(int()&)==false` (#81298)

IMHO it would be productive to make a similar change for `typeid`, in
`ParseCXXTypeid`, in order to improve Clang's error message for
https://godbolt.org/z/oKKWxeYra
But that might be better done by adding a new DeclaratorContext
specifically for TypeidArg, instead of pretending that the argument to
`typeid` is a template argument, because I don't know what else that
change might affect.

Fixes #77585

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Parse/ParseExprCXX.cpp
clang/test/Sema/static-assert.c
clang/test/SemaCXX/type-traits-nonobject.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b94e491de5e468..d4e6bcf661da1a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -265,6 +265,8 @@ Bug Fixes to C++ Support
 - Fix a crash when trying to call a varargs function that also has an explicit 
object parameter. (#GH80971)
 - Fixed a bug where abbreviated function templates would append their invented 
template parameters to
   an empty template parameter lists.
+- Fix parsing of abominable function types inside type traits.
+  Fixes (`#77585 `_)
 - Clang now classifies aggregate initialization in C++17 and newer as constant
   or non-constant more accurately. Previously, only a subset of the initializer
   elements were considered, misclassifying some initializers as constant. 
Partially fixes

diff  --git a/clang/lib/Parse/ParseExprCXX.cpp 
b/clang/lib/Parse/ParseExprCXX.cpp
index 22ee60af4616d2..9471f6f725efb1 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -3908,7 +3908,10 @@ ExprResult Parser::ParseTypeTrait() {
   SmallVector Args;
   do {
 // Parse the next type.
-TypeResult Ty = ParseTypeName();
+TypeResult Ty =
+ParseTypeName(/*SourceRange=*/nullptr,
+  getLangOpts().CPlusPlus ? DeclaratorContext::TemplateArg
+  : DeclaratorContext::TypeName);
 if (Ty.isInvalid()) {
   Parens.skipToEnd();
   return ExprError();
@@ -3950,7 +3953,8 @@ ExprResult Parser::ParseArrayTypeTrait() {
   if (T.expectAndConsume())
 return ExprError();
 
-  TypeResult Ty = ParseTypeName();
+  TypeResult Ty =
+  ParseTypeName(/*SourceRange=*/nullptr, DeclaratorContext::TemplateArg);
   if (Ty.isInvalid()) {
 SkipUntil(tok::comma, StopAtSemi);
 SkipUntil(tok::r_paren, StopAtSemi);

diff  --git a/clang/test/Sema/static-assert.c b/clang/test/Sema/static-assert.c
index 4e9e6b7ee558bd..ae5e8076e0beda 100644
--- a/clang/test/Sema/static-assert.c
+++ b/clang/test/Sema/static-assert.c
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -std=c11 -Wgnu-folding-constant -fsyntax-only -verify %s
-// RUN: %clang_cc1 -fms-compatibility -Wgnu-folding-constant -DMS 
-fsyntax-only -verify=expected,ms %s
-// RUN: %clang_cc1 -std=c99 -pedantic -Wgnu-folding-constant -fsyntax-only 
-verify=expected,ext %s
+// RUN: %clang_cc1 -std=c11 -Wgnu-folding-constant -fsyntax-only 
-verify=expected,c %s
+// RUN: %clang_cc1 -fms-compatibility -Wgnu-folding-constant -DMS 
-fsyntax-only -verify=expected,ms,c %s
+// RUN: %clang_cc1 -std=c99 -pedantic -Wgnu-folding-constant -fsyntax-only 
-verify=expected,ext,c %s
 // RUN: %clang_cc1 -xc++ -std=c++11 -pedantic -fsyntax-only 
-verify=expected,ext,cxx %s
 
 _Static_assert("foo", "string is nonzero"); // ext-warning {{'_Static_assert' 
is a C11 extension}}
@@ -57,7 +57,8 @@ UNION(char[2], short) u2 = { .one = { 'a', 'b' } }; // 
ext-warning 3 {{'_Static_
 typedef UNION(char, short) U3; // expected-error {{static assertion failed due 
to requirement 'sizeof(char) == sizeof(short)': type size mismatch}} \
// expected-note{{evaluates to '1 == 2'}} \
// ext-warning 3 {{'_Static_assert' is a C11 
extension}}
-typedef UNION(float, 0.5f) U4; // expected-error {{expected a type}} \
+typedef UNION(float, 0.5f) U4; // c-error {{expected a type}} \
+   // cxx-error {{type name requires a specifier 
or qualifier}} \
// ext-warning 3 {{'_Static_assert' is a C11 
extension}}
 
 // After defining the assert macro in MS-compatibility mode, we should

diff  --git a/clang/test/SemaCXX/type-traits-nonobject.cpp 
b/clang/test/SemaCXX/type-traits-nonobject.cpp
index c9e3c30e5533d4..5f7c20cc2e11c3 100644
--- a/clang/test/SemaCXX/type-traits-nonobject.cpp
+++ b/clang/test/SemaCXX/

[clang] [clang] Support `__is_trivially_copyable(int()&)==false` (PR #81298)

2024-03-05 Thread via cfe-commits

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


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

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

joker-eph wrote:

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

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


[clang] [llvm] [RISCV] Support RISC-V Profiles in -march option (PR #76357)

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

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

>From a54f47f8055e898b6452183663863f6df01e98e1 Mon Sep 17 00:00:00 2001
From: wangpc 
Date: Mon, 25 Dec 2023 18:52:36 +0800
Subject: [PATCH] [RFC][RISCV] Support RISC-V Profiles in -march option

This PR implements the draft
https://github.com/riscv-non-isa/riscv-toolchain-conventions/pull/36.

Currently, we replace specified profile in `-march` with standard
arch string.
---
 clang/test/Driver/riscv-profiles.c   | 324 +++
 llvm/include/llvm/Support/RISCVISAInfo.h |   2 +
 llvm/lib/Support/RISCVISAInfo.cpp|  76 ++
 llvm/lib/Target/RISCV/RISCV.td   |   6 +
 llvm/lib/Target/RISCV/RISCVProfiles.td   | 189 +
 llvm/lib/Target/RISCV/RISCVSubtarget.h   |  19 ++
 llvm/test/CodeGen/RISCV/attributes.ll|  25 ++
 7 files changed, 641 insertions(+)
 create mode 100644 clang/test/Driver/riscv-profiles.c
 create mode 100644 llvm/lib/Target/RISCV/RISCVProfiles.td

diff --git a/clang/test/Driver/riscv-profiles.c 
b/clang/test/Driver/riscv-profiles.c
new file mode 100644
index 00..8d1a7faf607838
--- /dev/null
+++ b/clang/test/Driver/riscv-profiles.c
@@ -0,0 +1,324 @@
+// RUN: %clang -### -c %s 2>&1 -march=rvi20u32 | FileCheck 
-check-prefix=RVI20U32 %s
+// RVI20U32: "-target-feature" "-a"
+// RVI20U32: "-target-feature" "-c"
+// RVI20U32: "-target-feature" "-d"
+// RVI20U32: "-target-feature" "-f"
+// RVI20U32: "-target-feature" "-m"
+// RVI20U32: "-target-feature" "+rvi20u32"
+
+// RUN: %clang -### -c %s 2>&1 -march=rvi20u64 | FileCheck 
-check-prefix=RVI20U64 %s
+// RVI20U64: "-target-feature" "-a"
+// RVI20U64: "-target-feature" "-c"
+// RVI20U64: "-target-feature" "-d"
+// RVI20U64: "-target-feature" "-f"
+// RVI20U64: "-target-feature" "-m"
+// RVI20U64: "-target-feature" "+rvi20u64"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva20u64 | FileCheck 
-check-prefix=RVA20U64 %s
+// RVA20U64: "-target-feature" "+m"
+// RVA20U64: "-target-feature" "+a"
+// RVA20U64: "-target-feature" "+f"
+// RVA20U64: "-target-feature" "+d"
+// RVA20U64: "-target-feature" "+c"
+// RVA20U64: "-target-feature" "+ziccamoa"
+// RVA20U64: "-target-feature" "+ziccif"
+// RVA20U64: "-target-feature" "+zicclsm"
+// RVA20U64: "-target-feature" "+ziccrse"
+// RVA20U64: "-target-feature" "+zicntr"
+// RVA20U64: "-target-feature" "+zicsr"
+// RVA20U64: "-target-feature" "+za128rs"
+// RVA20U64: "-target-feature" "+rva20u64"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva20s64 | FileCheck 
-check-prefix=RVA20S64 %s
+// RVA20S64: "-target-feature" "+m"
+// RVA20S64: "-target-feature" "+a"
+// RVA20S64: "-target-feature" "+f"
+// RVA20S64: "-target-feature" "+d"
+// RVA20S64: "-target-feature" "+c"
+// RVA20S64: "-target-feature" "+ziccamoa"
+// RVA20S64: "-target-feature" "+ziccif"
+// RVA20S64: "-target-feature" "+zicclsm"
+// RVA20S64: "-target-feature" "+ziccrse"
+// RVA20S64: "-target-feature" "+zicntr"
+// RVA20S64: "-target-feature" "+zicsr"
+// RVA20S64: "-target-feature" "+zifencei"
+// RVA20S64: "-target-feature" "+za128rs"
+// RVA20S64: "-target-feature" "+ssccptr"
+// RVA20S64: "-target-feature" "+sstvala"
+// RVA20S64: "-target-feature" "+sstvecd"
+// RVA20S64: "-target-feature" "+svade"
+// RVA20S64: "-target-feature" "+svbare"
+// RVA20S64: "-target-feature" "+rva20s64"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva22u64 | FileCheck 
-check-prefix=RVA22U64 %s
+// RVA22U64: "-target-feature" "+m"
+// RVA22U64: "-target-feature" "+a"
+// RVA22U64: "-target-feature" "+f"
+// RVA22U64: "-target-feature" "+d"
+// RVA22U64: "-target-feature" "+c"
+// RVA22U64: "-target-feature" "+zic64b"
+// RVA22U64: "-target-feature" "+zicbom"
+// RVA22U64: "-target-feature" "+zicbop"
+// RVA22U64: "-target-feature" "+zicboz"
+// RVA22U64: "-target-feature" "+ziccamoa"
+// RVA22U64: "-target-feature" "+ziccif"
+// RVA22U64: "-target-feature" "+zicclsm"
+// RVA22U64: "-target-feature" "+ziccrse"
+// RVA22U64: "-target-feature" "+zicntr"
+// RVA22U64: "-target-feature" "+zicsr"
+// RVA22U64: "-target-feature" "+zihintpause"
+// RVA22U64: "-target-feature" "+zihpm"
+// RVA22U64: "-target-feature" "+za64rs"
+// RVA22U64: "-target-feature" "+zfhmin"
+// RVA22U64: "-target-feature" "+zba"
+// RVA22U64: "-target-feature" "+zbb"
+// RVA22U64: "-target-feature" "+zbs"
+// RVA22U64: "-target-feature" "+zkt"
+// RVA22U64: "-target-feature" "+rva22u64"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva22s64 | FileCheck 
-check-prefix=RVA22S64 %s
+// RVA22S64: "-target-feature" "+m"
+// RVA22S64: "-target-feature" "+a"
+// RVA22S64: "-target-feature" "+f"
+// RVA22S64: "-target-feature" "+d"
+// RVA22S64: "-target-feature" "+c"
+// RVA22S64: "-target-feature" "+zic64b"
+// RVA22S64: "-target-feature" "+zicbom"
+// RVA22S64: "-target-feature" "+zicbop"
+// RVA22S64: "-target-feature" "+zicboz"
+// RVA22S64: "-target-feature" "+ziccamoa"
+// RVA22S64: "-target-feature" "+ziccif"
+// RVA22S64: "-target-feature" "+zicclsm"
+// RVA22S6

[clang] [llvm] [openmp] [libomptarget] Build plugins-nextgen for SystemZ (PR #83978)

2024-03-05 Thread Ulrich Weigand via cfe-commits

https://github.com/uweigand created 
https://github.com/llvm/llvm-project/pull/83978

The plugin was not getting built as the build_generic_elf64 macro assumes the 
LLVM triple processor name matches the CMake processor name, which is 
unfortunately not the case for SystemZ.

Fix this by providing two separate arguments instead.

Actually building the plugin exposed a number of other issues causing various 
test failures.  Specifically, I've had to add the SystemZ target to
- CompilerInvocation::ParseLangArgs
- linkDevice in ClangLinuxWrapper.cpp
- OMPContext::OMPContext (to set the device_kind_cpu trait)
- LIBOMPTARGET_ALL_TARGETS in libomptarget/CMakeLists.txt
- a check_plugin_target call in libomptarget/src/CMakeLists.txt

Finally, I've had to set a number of test cases to UNSUPPORTED on 
s390x-ibm-linux-gnu; all these tests were already marked as UNSUPPORTED for 
x86_64-pc-linux-gnu and aarch64-unknown-linux-gnu and are failing on s390x for 
what seem to be the same reason.

In addition, this also requires support for BE ELF files in plugins-nextgen: 
https://github.com/llvm/llvm-project/pull/83976

>From 0ab19aae09cfdc1c0213ce1365d8a47a32d6ec9c Mon Sep 17 00:00:00 2001
From: Ulrich Weigand 
Date: Tue, 5 Mar 2024 10:03:55 +0100
Subject: [PATCH] [libomptarget] Build plugins-nextgen for SystemZ

The plugin was not getting built as the build_generic_elf64
macro assumes the LLVM triple processor name matches the
CMake processor name, which is unfortunately not the case
for SystemZ.

Fix this by providing two separate arguments instead.

Actually building the plugin exposed a number of other issues
causing various test failures.  Specifically, I've had to add
the SystemZ target to
- CompilerInvocation::ParseLangArgs
- linkDevice in ClangLinuxWrapper.cpp
- OMPContext::OMPContext (to set the device_kind_cpu trait)
- LIBOMPTARGET_ALL_TARGETS in libomptarget/CMakeLists.txt
- a check_plugin_target call in libomptarget/src/CMakeLists.txt

Finally, I've had to set a number of test cases to UNSUPPORTED
on s390x-ibm-linux-gnu; all these tests were already marked as
UNSUPPORTED for x86_64-pc-linux-gnu and aarch64-unknown-linux-gnu
and are failing on s390x for what seem to be the same reason.

In addition, this also requires support for BE ELF files in
plugins-nextgen: https://github.com/llvm/llvm-project/pull/83976
---
 clang/lib/Frontend/CompilerInvocation.cpp| 1 +
 clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp  | 1 +
 llvm/lib/Frontend/OpenMP/OMPContext.cpp  | 1 +
 openmp/libomptarget/CMakeLists.txt   | 2 ++
 openmp/libomptarget/plugins-nextgen/CMakeLists.txt   | 9 ++---
 .../libomptarget/plugins-nextgen/aarch64/CMakeLists.txt  | 2 +-
 openmp/libomptarget/plugins-nextgen/ppc64/CMakeLists.txt | 2 +-
 .../libomptarget/plugins-nextgen/ppc64le/CMakeLists.txt  | 2 +-
 openmp/libomptarget/plugins-nextgen/s390x/CMakeLists.txt | 2 +-
 .../libomptarget/plugins-nextgen/x86_64/CMakeLists.txt   | 2 +-
 openmp/libomptarget/src/CMakeLists.txt   | 1 +
 openmp/libomptarget/test/api/omp_dynamic_shared_memory.c | 2 ++
 openmp/libomptarget/test/jit/empty_kernel_lvl1.c | 2 ++
 openmp/libomptarget/test/jit/empty_kernel_lvl2.c | 2 ++
 openmp/libomptarget/test/jit/type_punning.c  | 2 ++
 openmp/libomptarget/test/mapping/auto_zero_copy.cpp  | 2 ++
 .../libomptarget/test/mapping/auto_zero_copy_globals.cpp | 2 ++
 openmp/libomptarget/test/offloading/barrier_fence.c  | 2 ++
 openmp/libomptarget/test/offloading/bug49334.cpp | 2 ++
 .../libomptarget/test/offloading/default_thread_limit.c  | 2 ++
 openmp/libomptarget/test/offloading/ompx_bare.c  | 2 ++
 openmp/libomptarget/test/offloading/ompx_coords.c| 2 ++
 openmp/libomptarget/test/offloading/ompx_saxpy_mixed.c   | 2 ++
 .../test/offloading/parallel_target_teams_reduction.cpp  | 2 ++
 openmp/libomptarget/test/offloading/small_trip_count.c   | 2 ++
 .../test/offloading/small_trip_count_thread_limit.cpp| 2 ++
 openmp/libomptarget/test/offloading/spmdization.c| 2 ++
 .../test/offloading/target_critical_region.cpp   | 2 ++
 openmp/libomptarget/test/offloading/thread_limit.c   | 2 ++
 openmp/libomptarget/test/ompt/target_memcpy.c| 2 ++
 openmp/libomptarget/test/ompt/target_memcpy_emi.c| 2 ++
 openmp/libomptarget/test/ompt/veccopy.c  | 2 ++
 openmp/libomptarget/test/ompt/veccopy_data.c | 2 ++
 openmp/libomptarget/test/ompt/veccopy_disallow_both.c| 2 ++
 openmp/libomptarget/test/ompt/veccopy_emi.c  | 2 ++
 openmp/libomptarget/test/ompt/veccopy_emi_map.c  | 2 ++
 openmp/libomptarget/test/ompt/veccopy_map.c  | 2 ++
 37 files changed, 69 insertions(+), 8 deletions(-)

diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 691f3b989b81e5..7e17c3e49acaf6 100644
--- a/clang/lib/Frontend/CompilerInvocation

[clang] [clang][NFC] Format clang/lib/Sema/Sema.cpp (PR #83974)

2024-03-05 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

> Thank you for references both.
> 
> Actually, I'd like to have PR like #83961. Is it acceptable to merge this 
> kind of PR in that case then?

I don't feel the patches are related. I think you can only format the changed 
lines.

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


[clang] [llvm] [openmp] [libomptarget] Build plugins-nextgen for SystemZ (PR #83978)

2024-03-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-flang-openmp

Author: Ulrich Weigand (uweigand)


Changes

The plugin was not getting built as the build_generic_elf64 macro assumes the 
LLVM triple processor name matches the CMake processor name, which is 
unfortunately not the case for SystemZ.

Fix this by providing two separate arguments instead.

Actually building the plugin exposed a number of other issues causing various 
test failures.  Specifically, I've had to add the SystemZ target to
- CompilerInvocation::ParseLangArgs
- linkDevice in ClangLinuxWrapper.cpp
- OMPContext::OMPContext (to set the device_kind_cpu trait)
- LIBOMPTARGET_ALL_TARGETS in libomptarget/CMakeLists.txt
- a check_plugin_target call in libomptarget/src/CMakeLists.txt

Finally, I've had to set a number of test cases to UNSUPPORTED on 
s390x-ibm-linux-gnu; all these tests were already marked as UNSUPPORTED for 
x86_64-pc-linux-gnu and aarch64-unknown-linux-gnu and are failing on s390x for 
what seem to be the same reason.

In addition, this also requires support for BE ELF files in plugins-nextgen: 
https://github.com/llvm/llvm-project/pull/83976

---

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


37 Files Affected:

- (modified) clang/lib/Frontend/CompilerInvocation.cpp (+1) 
- (modified) clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp (+1) 
- (modified) llvm/lib/Frontend/OpenMP/OMPContext.cpp (+1) 
- (modified) openmp/libomptarget/CMakeLists.txt (+2) 
- (modified) openmp/libomptarget/plugins-nextgen/CMakeLists.txt (+6-3) 
- (modified) openmp/libomptarget/plugins-nextgen/aarch64/CMakeLists.txt (+1-1) 
- (modified) openmp/libomptarget/plugins-nextgen/ppc64/CMakeLists.txt (+1-1) 
- (modified) openmp/libomptarget/plugins-nextgen/ppc64le/CMakeLists.txt (+1-1) 
- (modified) openmp/libomptarget/plugins-nextgen/s390x/CMakeLists.txt (+1-1) 
- (modified) openmp/libomptarget/plugins-nextgen/x86_64/CMakeLists.txt (+1-1) 
- (modified) openmp/libomptarget/src/CMakeLists.txt (+1) 
- (modified) openmp/libomptarget/test/api/omp_dynamic_shared_memory.c (+2) 
- (modified) openmp/libomptarget/test/jit/empty_kernel_lvl1.c (+2) 
- (modified) openmp/libomptarget/test/jit/empty_kernel_lvl2.c (+2) 
- (modified) openmp/libomptarget/test/jit/type_punning.c (+2) 
- (modified) openmp/libomptarget/test/mapping/auto_zero_copy.cpp (+2) 
- (modified) openmp/libomptarget/test/mapping/auto_zero_copy_globals.cpp (+2) 
- (modified) openmp/libomptarget/test/offloading/barrier_fence.c (+2) 
- (modified) openmp/libomptarget/test/offloading/bug49334.cpp (+2) 
- (modified) openmp/libomptarget/test/offloading/default_thread_limit.c (+2) 
- (modified) openmp/libomptarget/test/offloading/ompx_bare.c (+2) 
- (modified) openmp/libomptarget/test/offloading/ompx_coords.c (+2) 
- (modified) openmp/libomptarget/test/offloading/ompx_saxpy_mixed.c (+2) 
- (modified) 
openmp/libomptarget/test/offloading/parallel_target_teams_reduction.cpp (+2) 
- (modified) openmp/libomptarget/test/offloading/small_trip_count.c (+2) 
- (modified) 
openmp/libomptarget/test/offloading/small_trip_count_thread_limit.cpp (+2) 
- (modified) openmp/libomptarget/test/offloading/spmdization.c (+2) 
- (modified) openmp/libomptarget/test/offloading/target_critical_region.cpp 
(+2) 
- (modified) openmp/libomptarget/test/offloading/thread_limit.c (+2) 
- (modified) openmp/libomptarget/test/ompt/target_memcpy.c (+2) 
- (modified) openmp/libomptarget/test/ompt/target_memcpy_emi.c (+2) 
- (modified) openmp/libomptarget/test/ompt/veccopy.c (+2) 
- (modified) openmp/libomptarget/test/ompt/veccopy_data.c (+2) 
- (modified) openmp/libomptarget/test/ompt/veccopy_disallow_both.c (+2) 
- (modified) openmp/libomptarget/test/ompt/veccopy_emi.c (+2) 
- (modified) openmp/libomptarget/test/ompt/veccopy_emi_map.c (+2) 
- (modified) openmp/libomptarget/test/ompt/veccopy_map.c (+2) 


``diff
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 691f3b989b81e5..7e17c3e49acaf6 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -4012,6 +4012,7 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, 
ArgList &Args,
 
   if (TT.getArch() == llvm::Triple::UnknownArch ||
   !(TT.getArch() == llvm::Triple::aarch64 || TT.isPPC() ||
+TT.getArch() == llvm::Triple::systemz ||
 TT.getArch() == llvm::Triple::nvptx ||
 TT.getArch() == llvm::Triple::nvptx64 ||
 TT.getArch() == llvm::Triple::amdgcn ||
diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 576e8f2cd7f8fd..b3efa56b33021a 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -552,6 +552,7 @@ Expected linkDevice(ArrayRef 
InputFiles,
   case Triple::aarch64_be:
   case Triple

[clang] [llvm] [openmp] [libomptarget] Build plugins-nextgen for SystemZ (PR #83978)

2024-03-05 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff ff66e9b7e2fad71d1c65e884d6f94fb6ea5bdc21 
0ab19aae09cfdc1c0213ce1365d8a47a32d6ec9c -- 
clang/lib/Frontend/CompilerInvocation.cpp 
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
llvm/lib/Frontend/OpenMP/OMPContext.cpp 
openmp/libomptarget/test/api/omp_dynamic_shared_memory.c 
openmp/libomptarget/test/jit/empty_kernel_lvl1.c 
openmp/libomptarget/test/jit/empty_kernel_lvl2.c 
openmp/libomptarget/test/jit/type_punning.c 
openmp/libomptarget/test/mapping/auto_zero_copy.cpp 
openmp/libomptarget/test/mapping/auto_zero_copy_globals.cpp 
openmp/libomptarget/test/offloading/barrier_fence.c 
openmp/libomptarget/test/offloading/bug49334.cpp 
openmp/libomptarget/test/offloading/default_thread_limit.c 
openmp/libomptarget/test/offloading/ompx_bare.c 
openmp/libomptarget/test/offloading/ompx_coords.c 
openmp/libomptarget/test/offloading/ompx_saxpy_mixed.c 
openmp/libomptarget/test/offloading/parallel_target_teams_reduction.cpp 
openmp/libomptarget/test/offloading/small_trip_count.c 
openmp/libomptarget/test/offloading/small_trip_count_thread_limit.cpp 
openmp/libomptarget/test/offloading/spmdization.c 
openmp/libomptarget/test/offloading/target_critical_region.cpp 
openmp/libomptarget/test/offloading/thread_limit.c 
openmp/libomptarget/test/ompt/target_memcpy.c 
openmp/libomptarget/test/ompt/target_memcpy_emi.c 
openmp/libomptarget/test/ompt/veccopy.c 
openmp/libomptarget/test/ompt/veccopy_data.c 
openmp/libomptarget/test/ompt/veccopy_disallow_both.c 
openmp/libomptarget/test/ompt/veccopy_emi.c 
openmp/libomptarget/test/ompt/veccopy_emi_map.c 
openmp/libomptarget/test/ompt/veccopy_map.c
``





View the diff from clang-format here.


``diff
diff --git a/openmp/libomptarget/test/offloading/ompx_bare.c 
b/openmp/libomptarget/test/offloading/ompx_bare.c
index 6b1a4950f4..ce4f2e5dd2 100644
--- a/openmp/libomptarget/test/offloading/ompx_bare.c
+++ b/openmp/libomptarget/test/offloading/ompx_bare.c
@@ -1,5 +1,6 @@
 // RUN: %libomptarget-compile-generic
-// RUN: env LIBOMPTARGET_INFO=63 %libomptarget-run-generic 2>&1 | 
%fcheck-generic
+// RUN: env LIBOMPTARGET_INFO=63 %libomptarget-run-generic 2>&1 |
+// %fcheck-generic
 //
 // UNSUPPORTED: x86_64-pc-linux-gnu
 // UNSUPPORTED: x86_64-pc-linux-gnu-LTO

``




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


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

2024-03-05 Thread Owen Pan via cfe-commits

owenca wrote:

> > It does fix the example given.
> 
> #83400 has 6 real-world examples. This patch fixes none of them. It also has 
> a reduced testcase, which this patch does fix. But fixing the reduced 
> testcase without fixing the real-world examples is not fixing the bug.

You took what I said out of context. I'll reiterate it below:
> It does fix the example given. For other diffs involving user-defined types, 
> the user need to use the TypeNames option. (If that doesn't work, a separate 
> issue should be filed.)

So again, this patch fixes the test case that "reproduces the issue" (in the 
issue author's own words), and I already explained to you that the other 6 
diffs (which are of the same construct, i.e. casting an address to a 
user-defined type in a macro definition) require the user to use the TypeNames 
option. (See the added test cases in fcae75ddb85e above.)

If the author of #83400 is still not satisfied, there's nothing to stop them 
from reopening the issue or filing a new issue. However, that's highly unlikely 
as they already expressed their view on it:
> But you can also see in the same PR 
> https://github.com/godotengine/godot/pull/88959 that other cases where & is a 
> bitwise operator were fixed by clang-format. I'm not sure there's any easy 
> way for clang-format to know which is which, if so I understand if this is 
> considered a "won't fix".

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


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

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

https://github.com/balazske updated 
https://github.com/llvm/llvm-project/pull/83858

From bb81a944b78315471df8866bf21b317e8c50166c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Mon, 4 Mar 2024 09:48:41 +0100
Subject: [PATCH 1/2] [clang][analyzer] Improve documentation of StreamChecker
 (NFC).

---
 clang/docs/analyzer/checkers.rst | 66 +---
 1 file changed, 52 insertions(+), 14 deletions(-)

diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index fe211514914272..aa79792c64dc54 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -3020,44 +3020,82 @@ Check for misuses of stream APIs. Check for misuses of 
stream APIs: ``fopen, fcl
 
 alpha.unix.Stream (C)
 "
-Check stream handling functions: ``fopen, tmpfile, fclose, fread, fwrite, 
fseek, ftell, rewind, fgetpos,``
-``fsetpos, clearerr, feof, ferror, fileno``.
+Check C stream handling functions:
+``fopen, fdopen, freopen, tmpfile, fclose, fread, fwrite, fgetc, fgets, fputc, 
fputs, fprintf, fscanf, ungetc, getdelim, getline, fseek, fseeko, ftell, 
ftello, fflush, rewind, fgetpos, fsetpos, clearerr, feof, ferror, fileno``.
+
+The checker maintains information about the C stream objects (``FILE *``) and
+can detect error conditions related to use of streams. The following conditions
+are detected:
+
+* The ``FILE *`` pointer passed to the function is NULL. (At ``fflush``
+  NULL is allowed.)
+* Use of stream after close.
+* Opened stream is not closed.
+* Read from a stream after end-of-file. (This is not a fatal error but reported
+  by the checker. Stream remains in EOF state and the read operation fails.)
+* Use of stream when the file position is indeterminate after a previous failed
+  operation. Some functions are allowed in this state.
+* Invalid 3rd ("``whence``") argument to ``fseek``.
+
+The checker is not capable of maintaining a relation between integer file
+descriptors and ``FILE *`` pointers. Operations on standard streams like
+``stdin`` are not treated specially and are therefore often not recognized
+(because these streams are usually not opened explicitly by the program, and
+are global variables).
 
 .. code-block:: c
 
- void test() {
+ void test1() {
FILE *p = fopen("foo", "r");
  } // warn: opened file is never closed
 
- void test() {
+ void test2() {
FILE *p = fopen("foo", "r");
fseek(p, 1, SEEK_SET); // warn: stream pointer might be NULL
fclose(p);
  }
 
- void test() {
+ void test3() {
FILE *p = fopen("foo", "r");
+   if (p) {
+ fseek(p, 1, 3); // warn: third arg should be SEEK_SET, SEEK_END, or 
SEEK_CUR
+ fclose(p);
+   }
+ }
 
-   if (p)
- fseek(p, 1, 3);
-  // warn: third arg should be SEEK_SET, SEEK_END, or SEEK_CUR
+ void test4() {
+   FILE *p = fopen("foo", "r");
+   if (!p)
+ return;
 
fclose(p);
+   fclose(p); // warn: stream already closed
  }
 
- void test() {
+ void test5() {
FILE *p = fopen("foo", "r");
+   if (!p)
+ return;
+
+   fgetc(p);
+   if (!ferror(p))
+ fgetc(p); // warn: possible read after end-of-file
+
fclose(p);
-   fclose(p); // warn: already closed
  }
 
- void test() {
-   FILE *p = tmpfile();
-   ftell(p); // warn: stream pointer might be NULL
+ void test6() {
+   FILE *p = fopen("foo", "r");
+   if (!p)
+ return;
+
+   fgetc(p);
+   if (!feof(p))
+ fgetc(p); // warn: file position may be indeterminate after I/O error
+
fclose(p);
  }
 
-
 .. _alpha-unix-cstring-BufferOverlap:
 
 alpha.unix.cstring.BufferOverlap (C)

From 5d723d165331b9a3e38a2ea1c9ff83b70745b6e6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Tue, 5 Mar 2024 10:25:46 +0100
Subject: [PATCH 2/2] maked documentation more exact

---
 clang/docs/analyzer/checkers.rst | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index aa79792c64dc54..e6eb7c2ced620c 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -3027,21 +3027,21 @@ The checker maintains information about the C stream 
objects (``FILE *``) and
 can detect error conditions related to use of streams. The following conditions
 are detected:
 
-* The ``FILE *`` pointer passed to the function is NULL. (At ``fflush``
-  NULL is allowed.)
+* The ``FILE *`` pointer passed to the function is NULL (the single exception 
is
+  ``fflush`` where NULL is allowed).
 * Use of stream after close.
 * Opened stream is not closed.
 * Read from a stream after end-of-file. (This is not a fatal error but reported
   by the checker. Stream remains in EOF state and the read operation fails.)
 * Use of stream when the file position is indeterminate after a previous failed
-  operation. Some functions are allowed in this state.
+  operation. Some functions (like ``ferror``, ``clearerr``, ``fseek``) are
+  allowed in this state.
 * Inval

[clang] [analyzer][NFC] Remove dead code (PR #83968)

2024-03-05 Thread via cfe-commits

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


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


[clang] [clang][NFC] Refactor `clang/test/SemaCXX/type-traits.cpp` to use modern `static_assert` (PR #77584)

2024-03-05 Thread Amirreza Ashouri via cfe-commits


@@ -214,56 +212,56 @@ struct HasVirtBase : virtual ACompleteType {};
 
 void is_pod()
 {
-  { int arr[T(__is_pod(int))]; }
-  { int arr[T(__is_pod(Enum))]; }
-  { int arr[T(__is_pod(POD))]; }
-  { int arr[T(__is_pod(Int))]; }
-  { int arr[T(__is_pod(IntAr))]; }
-  { int arr[T(__is_pod(Statics))]; }
-  { int arr[T(__is_pod(Empty))]; }
-  { int arr[T(__is_pod(EmptyUnion))]; }
-  { int arr[T(__is_pod(Union))]; }
-  { int arr[T(__is_pod(HasFunc))]; }
-  { int arr[T(__is_pod(HasOp))]; }
-  { int arr[T(__is_pod(HasConv))]; }
-  { int arr[T(__is_pod(HasAssign))]; }
-  { int arr[T(__is_pod(IntArNB))]; }
-  { int arr[T(__is_pod(HasAnonymousUnion))]; }
-  { int arr[T(__is_pod(Vector))]; }
-  { int arr[T(__is_pod(VectorExt))]; }
-  { int arr[T(__is_pod(Derives))]; }
-  { int arr[T(__is_pod(DerivesAr))]; }
-  { int arr[T(__is_pod(DerivesArNB))]; }
-  { int arr[T(__is_pod(DerivesEmpty))]; }
-  { int arr[T(__is_pod(HasPriv))]; }
-  { int arr[T(__is_pod(HasProt))]; }
-  { int arr[T(__is_pod(DerivesHasPriv))]; }
-  { int arr[T(__is_pod(DerivesHasProt))]; }
-
-  { int arr[F(__is_pod(HasCons))]; }
-  { int arr[F(__is_pod(HasCopyAssign))]; }
-  { int arr[F(__is_pod(HasMoveAssign))]; }
-  { int arr[F(__is_pod(HasDest))]; }
-  { int arr[F(__is_pod(HasRef))]; }
-  { int arr[F(__is_pod(HasVirt))]; }
-  { int arr[F(__is_pod(DerivesHasCons))]; }
-  { int arr[F(__is_pod(DerivesHasCopyAssign))]; }
-  { int arr[F(__is_pod(DerivesHasMoveAssign))]; }
-  { int arr[F(__is_pod(DerivesHasDest))]; }
-  { int arr[F(__is_pod(DerivesHasRef))]; }
-  { int arr[F(__is_pod(DerivesHasVirt))]; }
-  { int arr[F(__is_pod(NonPOD))]; }
-  { int arr[F(__is_pod(HasNonPOD))]; }
-  { int arr[F(__is_pod(NonPODAr))]; }
-  { int arr[F(__is_pod(NonPODArNB))]; }
-  { int arr[F(__is_pod(void))]; }
-  { int arr[F(__is_pod(cvoid))]; }
-// { int arr[F(__is_pod(NonPODUnion))]; }
-
-  { int arr[T(__is_pod(ACompleteType))]; }
-  { int arr[F(__is_pod(AnIncompleteType))]; } // expected-error {{incomplete 
type}}
-  { int arr[F(__is_pod(AnIncompleteType[]))]; } // expected-error {{incomplete 
type}}
-  { int arr[F(__is_pod(AnIncompleteType[1]))]; } // expected-error 
{{incomplete type}}
+  static_assert(__is_pod(int), "");

AMP999 wrote:

@cor3ntin Empty messages have been eliminated by commit `5e043de`. Should we 
also remove the messages in the `__has_unique_object_representations` section?

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


[clang] [analyzer][NFC] Remove dead code (PR #83968)

2024-03-05 Thread via cfe-commits

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


[clang] 88414c8 - [analyzer][NFC] Remove dead code (#83968)

2024-03-05 Thread via cfe-commits

Author: Balazs Benics
Date: 2024-03-05T10:30:28+01:00
New Revision: 88414c8862c58fa4e708a092acb87bd0687121ce

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

LOG: [analyzer][NFC] Remove dead code (#83968)

Remove the unused method `CoreEngine::ExecuteWorkListWithInitialState`.

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
clang/lib/StaticAnalyzer/Core/CoreEngine.cpp

Removed: 




diff  --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
index 8dbe767cef9d7e..8e392421fef9bb 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
@@ -149,12 +149,6 @@ class CoreEngine {
   bool ExecuteWorkList(const LocationContext *L, unsigned Steps,
ProgramStateRef InitState);
 
-  /// Returns true if there is still simulation state on the worklist.
-  bool ExecuteWorkListWithInitialState(const LocationContext *L,
-   unsigned Steps,
-   ProgramStateRef InitState,
-   ExplodedNodeSet &Dst);
-
   /// Dispatch the work list item based on the given location information.
   /// Use Pred parameter as the predecessor state.
   void dispatchWorkItem(ExplodedNode* Pred, ProgramPoint Loc,

diff  --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
index ed5c4adb5e3d56..f7894fb83ce65c 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
@@ -190,16 +190,6 @@ class ExprEngine {
 return Engine.ExecuteWorkList(L, Steps, nullptr);
   }
 
-  /// Execute the work list with an initial state. Nodes that reaches the exit
-  /// of the function are added into the Dst set, which represent the exit
-  /// state of the function call. Returns true if there is still simulation
-  /// state on the worklist.
-  bool ExecuteWorkListWithInitialState(const LocationContext *L, unsigned 
Steps,
-   ProgramStateRef InitState,
-   ExplodedNodeSet &Dst) {
-return Engine.ExecuteWorkListWithInitialState(L, Steps, InitState, Dst);
-  }
-
   /// getContext - Return the ASTContext associated with this analysis.
   ASTContext &getContext() const { return AMgr.getASTContext(); }
 

diff  --git a/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp 
b/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
index d3499e7a917d34..141d0cb320bffa 100644
--- a/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
@@ -222,18 +222,6 @@ void CoreEngine::dispatchWorkItem(ExplodedNode* Pred, 
ProgramPoint Loc,
   }
 }
 
-bool CoreEngine::ExecuteWorkListWithInitialState(const LocationContext *L,
- unsigned Steps,
- ProgramStateRef InitState,
- ExplodedNodeSet &Dst) {
-  bool DidNotFinish = ExecuteWorkList(L, Steps, InitState);
-  for (ExplodedGraph::eop_iterator I = G.eop_begin(), E = G.eop_end(); I != E;
-   ++I) {
-Dst.Add(*I);
-  }
-  return DidNotFinish;
-}
-
 void CoreEngine::HandleBlockEdge(const BlockEdge &L, ExplodedNode *Pred) {
   const CFGBlock *Blk = L.getDst();
   NodeBuilderContext BuilderCtx(*this, Blk, Pred);



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


[clang] [clang][NFC] Refactor `clang/test/SemaCXX/type-traits.cpp` to use modern `static_assert` (PR #77584)

2024-03-05 Thread Amirreza Ashouri via cfe-commits


@@ -2875,10 +2875,10 @@ struct __attribute__((packed)) PackedNoPadding2 {
   int j;
   short i;
 };
-static_assert(has_unique_object_representations::value, 
"Packed structs have no padding");
-static_assert(has_unique_object_representations::value, 
"Packed structs have no padding");
+static_assert(__has_unique_object_representations(PackedNoPadding1), "Packed 
structs have no padding");
+static_assert(__has_unique_object_representations(PackedNoPadding2), "Packed 
structs have no padding");
 
-static_assert(!has_unique_object_representations::value, "Functions 
are not unique");
+static_assert(!__has_unique_object_representations(int(int)), "Functions are 
not unique");
 static_assert(!has_unique_object_representations::value, 
"Functions are not unique");

AMP999 wrote:

By merging #81298 into the `main` branch, the elimination is now possible and 
it has been done in commit `2018c5a`.

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


[clang] [clang][analyzer] Bring cplusplus.ArrayDelete out of alpha (PR #83985)

2024-03-05 Thread via cfe-commits

https://github.com/Discookie created 
https://github.com/llvm/llvm-project/pull/83985

The checker finds a type of undefined behavior, where if the type of a pointer 
to an object-array is different from the objects' underlying type, calling 
delete[] is undefined, as the size of the two objects might be different.

The checker has been in alpha for a while now, it is a simple checker that 
causes no crashes, and considering the severity of the issue, it has a low 
result-count on open-source projects.

This commit cleans up the documentation and adds docs for the limitation 
related to tracking through references, in addition to moving it to `cplusplus`.

>From 28ed5ca4295360c8bbe671d4aed6cd2826c6 Mon Sep 17 00:00:00 2001
From: Viktor 
Date: Tue, 5 Mar 2024 09:46:26 +
Subject: [PATCH] [clang][analyzer] Bring cplusplus.ArrayDelete out of alpha

---
 clang/docs/analyzer/checkers.rst  | 68 ---
 .../clang/StaticAnalyzer/Checkers/Checkers.td | 10 +--
 .../Checkers/CXXDeleteChecker.cpp |  4 +-
 clang/test/Analysis/ArrayDelete.cpp   |  2 +-
 clang/www/analyzer/alpha_checks.html  | 20 --
 clang/www/analyzer/available_checks.html  | 27 
 6 files changed, 79 insertions(+), 52 deletions(-)

diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index fe211514914272..fc0c90f3f5d4e5 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -340,6 +340,50 @@ cplusplus
 
 C++ Checkers.
 
+.. _cplusplus-ArrayDelete:
+
+cplusplus.ArrayDelete (C++)
+"""
+Reports destructions of arrays of polymorphic objects that are destructed as
+their base class. If the dynamic type of the array's object is different from
+its static type, calling `delete[]` is undefined.
+
+This checker corresponds to the CERT rule `EXP51-CPP: Do not delete an array 
through a pointer of the incorrect type 
`_.
+
+.. code-block:: cpp
+
+ class Base {
+ public:
+   virtual ~Base() {}
+ };
+ class Derived : public Base {};
+
+ Base *create() {
+   Base *x = new Derived[10]; // note: Casting from 'Derived' to 'Base' here
+   return x;
+ }
+
+ void foo() {
+   Base *x = create();
+   delete[] x; // warn: Deleting an array of 'Derived' objects as their base 
class 'Base' is undefined
+ }
+
+**Limitations**
+
+The checker does not emit note tags when casting to and from reference types,
+even though the pointer values are tracked across references.
+
+.. code-block:: cpp
+
+ void foo() {
+   Derived *d = new Derived[10];
+   Derived &dref = *d;
+
+   Base &bref = static_cast(dref); // no note
+   Base *b = &bref;
+   delete[] b; // warn: Deleting an array of 'Derived' objects as their base 
class 'Base' is undefined
+ }
+
 .. _cplusplus-InnerPointer:
 
 cplusplus.InnerPointer (C++)
@@ -2139,30 +2183,6 @@ Either the comparison is useless or there is division by 
zero.
 alpha.cplusplus
 ^^^
 
-.. _alpha-cplusplus-ArrayDelete:
-
-alpha.cplusplus.ArrayDelete (C++)
-"
-Reports destructions of arrays of polymorphic objects that are destructed as 
their base class.
-This checker corresponds to the CERT rule `EXP51-CPP: Do not delete an array 
through a pointer of the incorrect type 
`_.
-
-.. code-block:: cpp
-
- class Base {
-   virtual ~Base() {}
- };
- class Derived : public Base {}
-
- Base *create() {
-   Base *x = new Derived[10]; // note: Casting from 'Derived' to 'Base' here
-   return x;
- }
-
- void foo() {
-   Base *x = create();
-   delete[] x; // warn: Deleting an array of 'Derived' objects as their base 
class 'Base' is undefined
- }
-
 .. _alpha-cplusplus-DeleteWithNonVirtualDtor:
 
 alpha.cplusplus.DeleteWithNonVirtualDtor (C++)
diff --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index a224b81c33a624..97fa8ac060eafa 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -622,6 +622,11 @@ def BlockInCriticalSectionChecker : 
Checker<"BlockInCriticalSection">,
 
 let ParentPackage = Cplusplus in {
 
+def ArrayDeleteChecker : Checker<"ArrayDelete">,
+  HelpText<"Reports destructions of arrays of polymorphic objects that are "
+   "destructed as their base class.">,
+  Documentation;
+
 def InnerPointerChecker : Checker<"InnerPointer">,
   HelpText<"Check for inner pointers of C++ containers used after "
"re/deallocation">,
@@ -777,11 +782,6 @@ def ContainerModeling : Checker<"ContainerModeling">,
   Documentation,
   Hidden;
 
-def CXXArrayDeleteChecker : Checker<"ArrayDelete">,
-  HelpText<"Reports destructions of arrays of po

[clang] [clang][analyzer] Bring cplusplus.ArrayDelete out of alpha (PR #83985)

2024-03-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Discookie (Discookie)


Changes

The checker finds a type of undefined behavior, where if the type of a pointer 
to an object-array is different from the objects' underlying type, calling 
delete[] is undefined, as the size of the two objects might be different.

The checker has been in alpha for a while now, it is a simple checker that 
causes no crashes, and considering the severity of the issue, it has a low 
result-count on open-source projects.

This commit cleans up the documentation and adds docs for the limitation 
related to tracking through references, in addition to moving it to `cplusplus`.

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


6 Files Affected:

- (modified) clang/docs/analyzer/checkers.rst (+44-24) 
- (modified) clang/include/clang/StaticAnalyzer/Checkers/Checkers.td (+5-5) 
- (modified) clang/lib/StaticAnalyzer/Checkers/CXXDeleteChecker.cpp (+2-2) 
- (modified) clang/test/Analysis/ArrayDelete.cpp (+1-1) 
- (modified) clang/www/analyzer/alpha_checks.html (-20) 
- (modified) clang/www/analyzer/available_checks.html (+27) 


``diff
diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index fe211514914272..fc0c90f3f5d4e5 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -340,6 +340,50 @@ cplusplus
 
 C++ Checkers.
 
+.. _cplusplus-ArrayDelete:
+
+cplusplus.ArrayDelete (C++)
+"""
+Reports destructions of arrays of polymorphic objects that are destructed as
+their base class. If the dynamic type of the array's object is different from
+its static type, calling `delete[]` is undefined.
+
+This checker corresponds to the CERT rule `EXP51-CPP: Do not delete an array 
through a pointer of the incorrect type 
`_.
+
+.. code-block:: cpp
+
+ class Base {
+ public:
+   virtual ~Base() {}
+ };
+ class Derived : public Base {};
+
+ Base *create() {
+   Base *x = new Derived[10]; // note: Casting from 'Derived' to 'Base' here
+   return x;
+ }
+
+ void foo() {
+   Base *x = create();
+   delete[] x; // warn: Deleting an array of 'Derived' objects as their base 
class 'Base' is undefined
+ }
+
+**Limitations**
+
+The checker does not emit note tags when casting to and from reference types,
+even though the pointer values are tracked across references.
+
+.. code-block:: cpp
+
+ void foo() {
+   Derived *d = new Derived[10];
+   Derived &dref = *d;
+
+   Base &bref = static_cast(dref); // no note
+   Base *b = &bref;
+   delete[] b; // warn: Deleting an array of 'Derived' objects as their base 
class 'Base' is undefined
+ }
+
 .. _cplusplus-InnerPointer:
 
 cplusplus.InnerPointer (C++)
@@ -2139,30 +2183,6 @@ Either the comparison is useless or there is division by 
zero.
 alpha.cplusplus
 ^^^
 
-.. _alpha-cplusplus-ArrayDelete:
-
-alpha.cplusplus.ArrayDelete (C++)
-"
-Reports destructions of arrays of polymorphic objects that are destructed as 
their base class.
-This checker corresponds to the CERT rule `EXP51-CPP: Do not delete an array 
through a pointer of the incorrect type 
`_.
-
-.. code-block:: cpp
-
- class Base {
-   virtual ~Base() {}
- };
- class Derived : public Base {}
-
- Base *create() {
-   Base *x = new Derived[10]; // note: Casting from 'Derived' to 'Base' here
-   return x;
- }
-
- void foo() {
-   Base *x = create();
-   delete[] x; // warn: Deleting an array of 'Derived' objects as their base 
class 'Base' is undefined
- }
-
 .. _alpha-cplusplus-DeleteWithNonVirtualDtor:
 
 alpha.cplusplus.DeleteWithNonVirtualDtor (C++)
diff --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index a224b81c33a624..97fa8ac060eafa 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -622,6 +622,11 @@ def BlockInCriticalSectionChecker : 
Checker<"BlockInCriticalSection">,
 
 let ParentPackage = Cplusplus in {
 
+def ArrayDeleteChecker : Checker<"ArrayDelete">,
+  HelpText<"Reports destructions of arrays of polymorphic objects that are "
+   "destructed as their base class.">,
+  Documentation;
+
 def InnerPointerChecker : Checker<"InnerPointer">,
   HelpText<"Check for inner pointers of C++ containers used after "
"re/deallocation">,
@@ -777,11 +782,6 @@ def ContainerModeling : Checker<"ContainerModeling">,
   Documentation,
   Hidden;
 
-def CXXArrayDeleteChecker : Checker<"ArrayDelete">,
-  HelpText<"Reports destructions of arrays of polymorphic objects that are "
-   "destructed as their base class.">,
-  Documentation;
-
 def DeleteWithNonVirtualDt

[clang-tools-extra] [clangd] Remove calls to getFileLoc() in declToSym() (PR #83532)

2024-03-05 Thread Haojian Wu via cfe-commits

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


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


[clang] [clang][analyzer] Bring cplusplus.ArrayDelete out of alpha (PR #83985)

2024-03-05 Thread via cfe-commits

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


[clang] [C++20] [Modules] Introduce reduced BMI (PR #75894)

2024-03-05 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

> * I do not want to block progress, so let's move forward with this patch for 
> now.

Yeah. Great to see we have some progress finally. I think this is really 
important since I see more and more peope complaninig the performance for 
modules. I feel this series patch is key to to improve the user's impression 
that named modules are just purely wrappers for PCH.

> * It seems to me (as we found with GMF decl elision) that the process is 
> quite a bit more complex than simply omitting a decl.  We need to elide other 
> decls that are then unused (e.g. decls local to an elided function body) and 
> also avoid emitting types that are now no longer existent.

After looking into the codes more, I changed my mind for this. I feel it is the 
most efficient and the most natural way to omit declarations in ASTWriter.

The idea is, previously, we'll start to write declarations in the current TU 
from the first declarations. And in the C++20 named modules world, we would 
start to write declarations from the first declarations in the global module 
fragment.  And we can implement GMF decl elision naturally by writing 
declarations from the first declaration in the module purview and only write 
the referenced decl from the GMF during the writing process. This is super 
natural and efficient.

> 
> The process seems to me to be either one of:
> 
> * rewriting the AST (which is why my patch set picked the use of the plugin 
> API since that is the purpose there).
> * walking the AST and marking entities as used / not used / elided.

Now I doubt both of the method to be not efficiency and it adds additional 
burdens to the developers and the users.

> 
> It still feels to me to be better to have clear separation of this work from 
> the work of streaming - but if we can make clear layers within the streaming, 
> then maybe the maintenance will not be too hard.

I think the maintainance may not be too hard in that way. ASTWriter is not such 
a devil :) Probably we need some refactoration in the serialization to make 
codes more clear. But the point is that we must get the ASTWriter/ASTReader 
involved. It may not be a good idea to leave the ASTWriter/ASTReader as is and 
add another layer... 

For example, it should be better to not deserialize the declaration from the 
very beginning instead of deserializing the declaration and judge that it is 
not wanted/visible. And to achieve this, we must  touch the serialization layer 
deeply.



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


[clang] [C++20] [Modules] Introduce reduced BMI (PR #75894)

2024-03-05 Thread Chuanqi Xu via cfe-commits


@@ -830,6 +843,19 @@ class PCHGenerator : public SemaConsumer {
   bool hasEmittedPCH() const { return Buffer->IsComplete; }
 };
 
+class ReducedBMIGenerator : public PCHGenerator {
+public:
+  ReducedBMIGenerator(const Preprocessor &PP, InMemoryModuleCache &ModuleCache,
+  StringRef OutputFile, std::shared_ptr Buffer,
+  bool IncludeTimestamps);
+
+  void HandleTranslationUnit(ASTContext &Ctx) override;
+};
+
+/// If the definition may impact the ABI. If yes, we're allowed to eliminate
+/// the definition of D in reduced BMI.
+bool MayDefAffectABI(const Decl *D);

ChuanqiXu9 wrote:

Nice catch up.

I changed the name to `CanElideDeclDef` and the comments to:

```
/// If we can elide the definition of \param D in reduced BMI.
///
/// Generally, we can elide the definition of a declaration if it won't affect 
the
/// ABI. e.g., the non-inline function bodies.
```

Hope this to be clear.

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


[clang] [clang-tools-extra] [flang] [lld] [llvm] [flang][clang] Add Visibility specific help text for options (PR #81869)

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

DavidSpickett wrote:

@banach-space Your thoughts as the Flang driver owner?

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


[clang] [clang] Sequence C++20 Parenthesized List Init (PR #83476)

2024-03-05 Thread via cfe-commits

cor3ntin wrote:

@vapdrs Do you need us to merge that for you? Thanks

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


[clang] [clang-tools-extra] [libcxx] [clang] Enable sized deallocation by default in C++14 onwards (PR #83774)

2024-03-05 Thread Vlad Serebrennikov via cfe-commits

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

>From 26245679b0f40b510e628aaed091739e9931c29c Mon Sep 17 00:00:00 2001
From: wangpc 
Date: Fri, 14 Jul 2023 10:38:14 +0800
Subject: [PATCH 1/3] [clang] Enable sized deallocation by default in C++14
 onwards

Since C++14 has been released for about nine years and most standard
libraries have implemented sized deallocation functions, it's time to
make this feature default again.

Differential Revision: https://reviews.llvm.org/D112921
---
 .../clangd/unittests/FindTargetTests.cpp  |   4 +-
 .../checkers/misc/new-delete-overloads.cpp|  10 -
 clang/docs/ReleaseNotes.rst   |   4 +
 clang/include/clang/Basic/SizedDeallocation.h |  44 
 clang/include/clang/Driver/Options.td |   5 +-
 clang/lib/Driver/ToolChains/Clang.cpp |  13 +-
 clang/lib/Driver/ToolChains/Darwin.cpp|  41 ++-
 clang/lib/Driver/ToolChains/Darwin.h  |   4 +
 clang/lib/Driver/ToolChains/ZOS.cpp   |   6 +
 clang/test/AST/ast-dump-expr-json.cpp |   2 +-
 clang/test/AST/ast-dump-expr.cpp  |   2 +-
 clang/test/AST/ast-dump-stmt-json.cpp | 244 +-
 clang/test/Analysis/cxxnewexpr-callback.cpp   |   4 +-
 .../basic.stc.dynamic.deallocation/p2.cpp |   2 +-
 clang/test/CXX/drs/dr292.cpp  |   6 +-
 .../test/CXX/expr/expr.unary/expr.new/p14.cpp |   2 +-
 .../CodeGenCXX/cxx1y-sized-deallocation.cpp   |  10 +-
 .../CodeGenCXX/cxx1z-aligned-allocation.cpp   |   6 +-
 .../CodeGenCXX/cxx2a-destroying-delete.cpp|   4 +-
 clang/test/CodeGenCXX/delete-two-arg.cpp  |   4 +-
 clang/test/CodeGenCXX/delete.cpp  |  12 +-
 clang/test/CodeGenCXX/dllimport.cpp   |   4 +-
 clang/test/CodeGenCXX/new.cpp |   6 +-
 .../coro-aligned-alloc-2.cpp  |   2 -
 .../CodeGenCoroutines/coro-aligned-alloc.cpp  |   6 +-
 clang/test/CodeGenCoroutines/coro-alloc.cpp   |   6 +-
 clang/test/CodeGenCoroutines/coro-cleanup.cpp |   6 +-
 clang/test/CodeGenCoroutines/coro-dealloc.cpp |   2 -
 clang/test/CodeGenCoroutines/coro-gro.cpp |   3 +-
 clang/test/CodeGenCoroutines/pr56919.cpp  |   9 +-
 clang/test/Lexer/cxx-features.cpp |  20 +-
 clang/test/PCH/cxx1z-aligned-alloc.cpp|  10 +-
 clang/test/SemaCXX/MicrosoftExtensions.cpp|   8 +-
 .../SemaCXX/builtin-operator-new-delete.cpp   |   2 +-
 .../test/SemaCXX/cxx1y-sized-deallocation.cpp |   2 +-
 .../unavailable_aligned_allocation.cpp|  15 +-
 .../StaticAnalyzer/CallEventTest.cpp  |   2 +-
 clang/www/cxx_status.html |  11 +-
 .../support.dynamic/libcpp_deallocate.sh.cpp  |   3 +
 .../sized_delete_array14.pass.cpp |   8 +-
 .../new.delete.single/sized_delete14.pass.cpp |   8 +-
 41 files changed, 458 insertions(+), 104 deletions(-)
 create mode 100644 clang/include/clang/Basic/SizedDeallocation.h

diff --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp 
b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
index 0af6036734ba53..1b7b96281dfaa5 100644
--- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -839,7 +839,9 @@ TEST_F(TargetDeclTest, OverloadExpr) {
   [[delete]] x;
 }
   )cpp";
-  EXPECT_DECLS("CXXDeleteExpr", "void operator delete(void *) noexcept");
+  // Sized deallocation is enabled by default in C++14 onwards.
+  EXPECT_DECLS("CXXDeleteExpr",
+   "void operator delete(void *, unsigned long) noexcept");
 }
 
 TEST_F(TargetDeclTest, DependentExprs) {
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/new-delete-overloads.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/new-delete-overloads.cpp
index 78f021144b2e19..f86fe8a4c5b14f 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/new-delete-overloads.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/new-delete-overloads.cpp
@@ -12,16 +12,6 @@ struct S {
 // CHECK-MESSAGES: :[[@LINE+1]]:7: warning: declaration of 'operator new' has 
no matching declaration of 'operator delete' at the same scope
 void *operator new(size_t size) noexcept(false);
 
-struct T {
-  // Sized deallocations are not enabled by default, and so this new/delete 
pair
-  // does not match. However, we expect only one warning, for the new, because
-  // the operator delete is a placement delete and we do not warn on 
mismatching
-  // placement operations.
-  // CHECK-MESSAGES: :[[@LINE+1]]:9: warning: declaration of 'operator new' 
has no matching declaration of 'operator delete' at the same scope
-  void *operator new(size_t size) noexcept;
-  void operator delete(void *ptr, size_t) noexcept; // ok only if sized 
deallocation is enabled
-};
-
 struct U {
   void *operator new(size_t size) noexcept;
   void operator delete(void *ptr) noexcept;
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6f6ce7c68a

[clang-tools-extra] [clang-tidy] fix false negative in cppcoreguidelines-missing-std-forward (PR #83987)

2024-03-05 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky created 
https://github.com/llvm/llvm-project/pull/83987

Try to fix https://github.com/llvm/llvm-project/issues/83845
When `std::forward` is invoked in a function, make sure it uses correct 
parameter by checking if the bounded `var` equals the parameter.

>From 67e7001dee4fdcc1da3d267a9a120d3bc65ae69b Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Tue, 5 Mar 2024 18:02:01 +0800
Subject: [PATCH] [clang-tidy] fix false negative in
 cppcoreguidelines-missing-std-forward

---
 .../cppcoreguidelines/MissingStdForwardCheck.cpp   | 10 ++
 clang-tools-extra/docs/ReleaseNotes.rst|  3 ++-
 .../checkers/cppcoreguidelines/missing-std-forward.cpp | 10 ++
 3 files changed, 18 insertions(+), 5 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
index c633683570f748..87fd8adf997082 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
@@ -112,10 +112,12 @@ void MissingStdForwardCheck::registerMatchers(MatchFinder 
*Finder) {
 
   auto ForwardCallMatcher = callExpr(
   callExpr().bind("call"), argumentCountIs(1),
-  hasArgument(
-  0, declRefExpr(to(
- varDecl(optionally(equalsBoundNode("param"))).bind("var",
-  forCallable(anyOf(equalsBoundNode("func"), CapturedInLambda)),
+  hasArgument(0, declRefExpr(to(varDecl().bind("var",
+  forCallable(
+  anyOf(allOf(equalsBoundNode("func"),
+  functionDecl(hasAnyParameter(parmVarDecl(allOf(
+  equalsBoundNode("param"), 
equalsBoundNode("var")),
+CapturedInLambda)),
   callee(unresolvedLookupExpr(hasAnyDeclaration(
   namedDecl(hasUnderlyingDecl(hasName("::std::forward")),
 
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 143ae230fc443c..1abe45bae8a84d 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -156,7 +156,8 @@ Changes in existing checks
 
 - Improved :doc:`cppcoreguidelines-missing-std-forward
   ` check by no longer
-  giving false positives for deleted functions.
+  giving false positives for deleted functions and fix false negative when one
+  parameter is forwarded, but some other parameter isn't.
 
 - Cleaned up :doc:`cppcoreguidelines-prefer-member-initializer
   `
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 20e43f04180ff3..29af67b60614c8 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
@@ -95,6 +95,16 @@ void lambda_value_capture_copy(T&& t) {
   [&,t]() { T other = std::forward(t); };
 }
 
+template 
+void use(const X &x) {}
+
+template 
+void foo(X &&x, Y &&y) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: forwarding reference parameter 
't' is never forwarded inside the function body 
[cppcoreguidelines-missing-std-forward]
+use(std::forward(x));
+use(y);
+}
+
 } // namespace positive_cases
 
 namespace negative_cases {

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


[clang-tools-extra] [clang-tidy] fix false negative in cppcoreguidelines-missing-std-forward (PR #83987)

2024-03-05 Thread via cfe-commits

llvmbot wrote:




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

Author: Qizhi Hu (jcsxky)


Changes

Try to fix https://github.com/llvm/llvm-project/issues/83845
When `std::forward` is invoked in a function, make sure it uses correct 
parameter by checking if the bounded `var` equals the parameter.

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


3 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp 
(+6-4) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+2-1) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
 (+10) 


``diff
diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
index c633683570f748..87fd8adf997082 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
@@ -112,10 +112,12 @@ void MissingStdForwardCheck::registerMatchers(MatchFinder 
*Finder) {
 
   auto ForwardCallMatcher = callExpr(
   callExpr().bind("call"), argumentCountIs(1),
-  hasArgument(
-  0, declRefExpr(to(
- varDecl(optionally(equalsBoundNode("param"))).bind("var",
-  forCallable(anyOf(equalsBoundNode("func"), CapturedInLambda)),
+  hasArgument(0, declRefExpr(to(varDecl().bind("var",
+  forCallable(
+  anyOf(allOf(equalsBoundNode("func"),
+  functionDecl(hasAnyParameter(parmVarDecl(allOf(
+  equalsBoundNode("param"), 
equalsBoundNode("var")),
+CapturedInLambda)),
   callee(unresolvedLookupExpr(hasAnyDeclaration(
   namedDecl(hasUnderlyingDecl(hasName("::std::forward")),
 
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 143ae230fc443c..1abe45bae8a84d 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -156,7 +156,8 @@ Changes in existing checks
 
 - Improved :doc:`cppcoreguidelines-missing-std-forward
   ` check by no longer
-  giving false positives for deleted functions.
+  giving false positives for deleted functions and fix false negative when one
+  parameter is forwarded, but some other parameter isn't.
 
 - Cleaned up :doc:`cppcoreguidelines-prefer-member-initializer
   `
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 20e43f04180ff3..29af67b60614c8 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
@@ -95,6 +95,16 @@ void lambda_value_capture_copy(T&& t) {
   [&,t]() { T other = std::forward(t); };
 }
 
+template 
+void use(const X &x) {}
+
+template 
+void foo(X &&x, Y &&y) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: forwarding reference parameter 
't' is never forwarded inside the function body 
[cppcoreguidelines-missing-std-forward]
+use(std::forward(x));
+use(y);
+}
+
 } // namespace positive_cases
 
 namespace negative_cases {

``




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


[clang] [clang][NFC] Format clang/lib/Sema/Sema.cpp (PR #83974)

2024-03-05 Thread Takuto Ikuta via cfe-commits

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


[clang] [clang][NFC] Format clang/lib/Sema/Sema.cpp (PR #83974)

2024-03-05 Thread Takuto Ikuta via cfe-commits

atetubou wrote:

Oh, I found 
https://code.visualstudio.com/docs/getstarted/settings#:~:text=modificationsIfAvailable.
 
So let me use that instead. Thank you for your comments.

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


[clang] [clang-tools-extra] [libcxx] [clang] Enable sized deallocation by default in C++14 onwards (PR #83774)

2024-03-05 Thread Vlad Serebrennikov via cfe-commits

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

I used a different approach for CWG292 test that avoids passing 
`-fsized-deallocation` in 98 and 11 modes, as this is not a conforming mode for 
them. Now changes to DR tests look good :) I hope you don't mind me pushing 
commits to your PR.

(I'm the author of CWG292 test)

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


[clang] [clang][NFC] Refactor `clang/test/SemaCXX/type-traits.cpp` to use modern `static_assert` (PR #77584)

2024-03-05 Thread via cfe-commits

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

LGTM

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


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

2024-03-05 Thread Brandon Wu via cfe-commits

https://github.com/4vtomat created 
https://github.com/llvm/llvm-project/pull/83989

If the "march" has some extension with version that is not supported, it
returns the error message like: "error: invalid arch name 'some_arch',
unsupported version number 2.0 for extension 'some_arch'", which is not
precise enough, it should return the message that only tells users "the
extension is not supported".


>From 764c861931fd8013df5b144c2d789614bc952126 Mon Sep 17 00:00:00 2001
From: Brandon Wu 
Date: Tue, 5 Mar 2024 02:28:10 -0800
Subject: [PATCH] [RISCV] Improve error message when the extension is not
 supported

If the "march" has some extension with version that is not supported, it
returns the error message like: "error: invalid arch name 'some_arch',
unsupported version number 2.0 for extension 'some_arch'", which is not
precise enough, it should return the message that only tells users "the
extension is not supported".
---
 clang/test/Driver/riscv-arch.c|  4 ++--
 llvm/lib/Support/RISCVISAInfo.cpp | 26 --
 2 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/clang/test/Driver/riscv-arch.c b/clang/test/Driver/riscv-arch.c
index c9e984e07cbea9..8399b4e97f86d5 100644
--- a/clang/test/Driver/riscv-arch.c
+++ b/clang/test/Driver/riscv-arch.c
@@ -306,7 +306,7 @@
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32ist2p0 -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-SMINOR0 %s
 // RV32-SMINOR0: error: invalid arch name 'rv32ist2p0',
-// RV32-SMINOR0: unsupported version number 2.0 for extension 'st'
+// RV32-SMINOR0: unsupported standard supervisor-level extension 'st'
 
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32ixabc_ -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-XSEP %s
@@ -397,7 +397,7 @@
 
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32izbb1p0zbs1p0 
-menable-experimental-extensions -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck 
-check-prefix=RV32-EXPERIMENTAL-ZBB-ZBS-UNDERSCORE %s
-// RV32-EXPERIMENTAL-ZBB-ZBS-UNDERSCORE: error: invalid arch name 
'rv32izbb1p0zbs1p0', unsupported version number 1.0 for extension 'zbb1p0zbs'
+// RV32-EXPERIMENTAL-ZBB-ZBS-UNDERSCORE: error: invalid arch name 
'rv32izbb1p0zbs1p0', unsupported standard user-level extension 'zbb1p0zbs'
 
 // RUN: %clang --target=riscv32-unknown-elf -march=rv32izba1p0 -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-ZBA %s
diff --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index 54b4dcb22de8e0..6eec03fd6f7082 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -531,6 +531,17 @@ std::vector RISCVISAInfo::toFeatures(bool 
AddAllExtensions,
   return Features;
 }
 
+static Error getStringErrorForInvalidExt(std::string_view ExtName) {
+  if (ExtName.size() == 1) {
+return createStringError(errc::invalid_argument,
+ "unsupported standard user-level extension '" +
+ ExtName + "'");
+  }
+  return createStringError(errc::invalid_argument,
+   "unsupported " + getExtensionTypeDesc(ExtName) +
+   " '" + ExtName + "'");
+}
+
 // Extensions may have a version number, and may be separated by
 // an underscore '_' e.g.: rv32i2_m2.
 // Version number is divided into major and minor version numbers,
@@ -629,6 +640,9 @@ static Error getExtensionVersion(StringRef Ext, StringRef 
In, unsigned &Major,
   if (RISCVISAInfo::isSupportedExtension(Ext, Major, Minor))
 return Error::success();
 
+  if (!RISCVISAInfo::isSupportedExtension(Ext))
+return getStringErrorForInvalidExt(Ext);
+
   std::string Error = "unsupported version number " + std::string(MajorStr);
   if (!MinorStr.empty())
 Error += "." + MinorStr.str();
@@ -965,16 +979,8 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool 
EnableExperimentalExtension,
 const std::string &ExtName = SeenExtAndVers.first;
 RISCVISAInfo::ExtensionVersion ExtVers = SeenExtAndVers.second;
 
-if (!RISCVISAInfo::isSupportedExtension(ExtName)) {
-  if (ExtName.size() == 1) {
-return createStringError(errc::invalid_argument,
- "unsupported standard user-level extension '" 
+
- ExtName + "'");
-  }
-  return createStringError(errc::invalid_argument,
-   "unsupported " + getExtensionTypeDesc(ExtName) +
-   " '" + ExtName + "'");
-}
+if (!RISCVISAInfo::isSupportedExtension(ExtName))
+  return getStringErrorForInvalidExt(ExtName);
 ISAInfo->addExtension(ExtName, ExtVers);
   }
 

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


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

2024-03-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-support

Author: Brandon Wu (4vtomat)


Changes

If the "march" has some extension with version that is not supported, it
returns the error message like: "error: invalid arch name 'some_arch',
unsupported version number 2.0 for extension 'some_arch'", which is not
precise enough, it should return the message that only tells users "the
extension is not supported".


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


2 Files Affected:

- (modified) clang/test/Driver/riscv-arch.c (+2-2) 
- (modified) llvm/lib/Support/RISCVISAInfo.cpp (+16-10) 


``diff
diff --git a/clang/test/Driver/riscv-arch.c b/clang/test/Driver/riscv-arch.c
index c9e984e07cbea9..8399b4e97f86d5 100644
--- a/clang/test/Driver/riscv-arch.c
+++ b/clang/test/Driver/riscv-arch.c
@@ -306,7 +306,7 @@
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32ist2p0 -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-SMINOR0 %s
 // RV32-SMINOR0: error: invalid arch name 'rv32ist2p0',
-// RV32-SMINOR0: unsupported version number 2.0 for extension 'st'
+// RV32-SMINOR0: unsupported standard supervisor-level extension 'st'
 
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32ixabc_ -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-XSEP %s
@@ -397,7 +397,7 @@
 
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32izbb1p0zbs1p0 
-menable-experimental-extensions -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck 
-check-prefix=RV32-EXPERIMENTAL-ZBB-ZBS-UNDERSCORE %s
-// RV32-EXPERIMENTAL-ZBB-ZBS-UNDERSCORE: error: invalid arch name 
'rv32izbb1p0zbs1p0', unsupported version number 1.0 for extension 'zbb1p0zbs'
+// RV32-EXPERIMENTAL-ZBB-ZBS-UNDERSCORE: error: invalid arch name 
'rv32izbb1p0zbs1p0', unsupported standard user-level extension 'zbb1p0zbs'
 
 // RUN: %clang --target=riscv32-unknown-elf -march=rv32izba1p0 -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-ZBA %s
diff --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index 54b4dcb22de8e0..6eec03fd6f7082 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -531,6 +531,17 @@ std::vector RISCVISAInfo::toFeatures(bool 
AddAllExtensions,
   return Features;
 }
 
+static Error getStringErrorForInvalidExt(std::string_view ExtName) {
+  if (ExtName.size() == 1) {
+return createStringError(errc::invalid_argument,
+ "unsupported standard user-level extension '" +
+ ExtName + "'");
+  }
+  return createStringError(errc::invalid_argument,
+   "unsupported " + getExtensionTypeDesc(ExtName) +
+   " '" + ExtName + "'");
+}
+
 // Extensions may have a version number, and may be separated by
 // an underscore '_' e.g.: rv32i2_m2.
 // Version number is divided into major and minor version numbers,
@@ -629,6 +640,9 @@ static Error getExtensionVersion(StringRef Ext, StringRef 
In, unsigned &Major,
   if (RISCVISAInfo::isSupportedExtension(Ext, Major, Minor))
 return Error::success();
 
+  if (!RISCVISAInfo::isSupportedExtension(Ext))
+return getStringErrorForInvalidExt(Ext);
+
   std::string Error = "unsupported version number " + std::string(MajorStr);
   if (!MinorStr.empty())
 Error += "." + MinorStr.str();
@@ -965,16 +979,8 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool 
EnableExperimentalExtension,
 const std::string &ExtName = SeenExtAndVers.first;
 RISCVISAInfo::ExtensionVersion ExtVers = SeenExtAndVers.second;
 
-if (!RISCVISAInfo::isSupportedExtension(ExtName)) {
-  if (ExtName.size() == 1) {
-return createStringError(errc::invalid_argument,
- "unsupported standard user-level extension '" 
+
- ExtName + "'");
-  }
-  return createStringError(errc::invalid_argument,
-   "unsupported " + getExtensionTypeDesc(ExtName) +
-   " '" + ExtName + "'");
-}
+if (!RISCVISAInfo::isSupportedExtension(ExtName))
+  return getStringErrorForInvalidExt(ExtName);
 ISAInfo->addExtension(ExtName, ExtVers);
   }
 

``




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


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

2024-03-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-risc-v

Author: Brandon Wu (4vtomat)


Changes

If the "march" has some extension with version that is not supported, it
returns the error message like: "error: invalid arch name 'some_arch',
unsupported version number 2.0 for extension 'some_arch'", which is not
precise enough, it should return the message that only tells users "the
extension is not supported".


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


2 Files Affected:

- (modified) clang/test/Driver/riscv-arch.c (+2-2) 
- (modified) llvm/lib/Support/RISCVISAInfo.cpp (+16-10) 


``diff
diff --git a/clang/test/Driver/riscv-arch.c b/clang/test/Driver/riscv-arch.c
index c9e984e07cbea9..8399b4e97f86d5 100644
--- a/clang/test/Driver/riscv-arch.c
+++ b/clang/test/Driver/riscv-arch.c
@@ -306,7 +306,7 @@
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32ist2p0 -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-SMINOR0 %s
 // RV32-SMINOR0: error: invalid arch name 'rv32ist2p0',
-// RV32-SMINOR0: unsupported version number 2.0 for extension 'st'
+// RV32-SMINOR0: unsupported standard supervisor-level extension 'st'
 
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32ixabc_ -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-XSEP %s
@@ -397,7 +397,7 @@
 
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32izbb1p0zbs1p0 
-menable-experimental-extensions -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck 
-check-prefix=RV32-EXPERIMENTAL-ZBB-ZBS-UNDERSCORE %s
-// RV32-EXPERIMENTAL-ZBB-ZBS-UNDERSCORE: error: invalid arch name 
'rv32izbb1p0zbs1p0', unsupported version number 1.0 for extension 'zbb1p0zbs'
+// RV32-EXPERIMENTAL-ZBB-ZBS-UNDERSCORE: error: invalid arch name 
'rv32izbb1p0zbs1p0', unsupported standard user-level extension 'zbb1p0zbs'
 
 // RUN: %clang --target=riscv32-unknown-elf -march=rv32izba1p0 -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-ZBA %s
diff --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index 54b4dcb22de8e0..6eec03fd6f7082 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -531,6 +531,17 @@ std::vector RISCVISAInfo::toFeatures(bool 
AddAllExtensions,
   return Features;
 }
 
+static Error getStringErrorForInvalidExt(std::string_view ExtName) {
+  if (ExtName.size() == 1) {
+return createStringError(errc::invalid_argument,
+ "unsupported standard user-level extension '" +
+ ExtName + "'");
+  }
+  return createStringError(errc::invalid_argument,
+   "unsupported " + getExtensionTypeDesc(ExtName) +
+   " '" + ExtName + "'");
+}
+
 // Extensions may have a version number, and may be separated by
 // an underscore '_' e.g.: rv32i2_m2.
 // Version number is divided into major and minor version numbers,
@@ -629,6 +640,9 @@ static Error getExtensionVersion(StringRef Ext, StringRef 
In, unsigned &Major,
   if (RISCVISAInfo::isSupportedExtension(Ext, Major, Minor))
 return Error::success();
 
+  if (!RISCVISAInfo::isSupportedExtension(Ext))
+return getStringErrorForInvalidExt(Ext);
+
   std::string Error = "unsupported version number " + std::string(MajorStr);
   if (!MinorStr.empty())
 Error += "." + MinorStr.str();
@@ -965,16 +979,8 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool 
EnableExperimentalExtension,
 const std::string &ExtName = SeenExtAndVers.first;
 RISCVISAInfo::ExtensionVersion ExtVers = SeenExtAndVers.second;
 
-if (!RISCVISAInfo::isSupportedExtension(ExtName)) {
-  if (ExtName.size() == 1) {
-return createStringError(errc::invalid_argument,
- "unsupported standard user-level extension '" 
+
- ExtName + "'");
-  }
-  return createStringError(errc::invalid_argument,
-   "unsupported " + getExtensionTypeDesc(ExtName) +
-   " '" + ExtName + "'");
-}
+if (!RISCVISAInfo::isSupportedExtension(ExtName))
+  return getStringErrorForInvalidExt(ExtName);
 ISAInfo->addExtension(ExtName, ExtVers);
   }
 

``




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


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

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

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

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

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

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

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

[clang] [clang] Implement CTAD for type alias template. (PR #77890)

2024-03-05 Thread Haojian Wu via cfe-commits

hokein wrote:

@cor3ntin, @erichkeane, thanks for all review comments. I'm not sure you have 
reviewed the whole patch. My feeling is that the core part 
(`DeclareImplicitDeductionGuidesForTypeAlias`) may not have received sufficient 
reviews. It would be great if you can take a closer look at this part. 

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


[clang-tools-extra] [clangd] Make all calls to format::getStyle() go through getFormatStyleForFile() (PR #82948)

2024-03-05 Thread Haojian Wu via cfe-commits

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

+1, this looks like an improvement.

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


[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

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

Fznamznon wrote:

> Please let me know your thoughts.

@AaronBallman , implemented in 
https://github.com/llvm/llvm-project/pull/73099/commits/dff61e0f49d0ba0d868f4e9668f75718b031e1e3
 .
I was mostly referring to the original page 
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3018.htm when implementing 
the feature, so these NaN cases slipped.

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


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

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

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


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

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

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


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


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

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


@@ -11429,6 +11429,16 @@ static bool CheckTargetCausesMultiVersioning(Sema &S, 
FunctionDecl *OldFD,
  bool &Redeclaration,
  NamedDecl *&OldDecl,
  LookupResult &Previous) {
+  assert(!OldFD->isMultiVersion() && "Unexpected MultiVersion");
+
+  // The definitions should be allowed in any order. If we have discovered
+  // a new target version and the preceeding was the default, then add the
+  // corresponding attribute to it.
+  if (OldFD->getMultiVersionKind() == MultiVersionKind::None &&

ilinpv wrote:

Should it work for case target_version("default") declared first? It would good 
to add tests for various orders of function definition and target_version 
attributes. 

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


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

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


@@ -11455,9 +11465,8 @@ static bool CheckTargetCausesMultiVersioning(Sema &S, 
FunctionDecl *OldFD,
   }
 
   // If this is 'default', permit the forward declaration.
-  if (!OldFD->isMultiVersion() &&
-  ((NewTA && NewTA->isDefaultVersion() && !OldTA) ||
-   (NewTVA && NewTVA->isDefaultVersion() && !OldTVA))) {
+  if ((NewTA && NewTA->isDefaultVersion() && !OldTA) ||

ilinpv wrote:

Seems we are changing "target" attribute semantic here as well that we would 
like to avoid, why are we sure that !OldFD->isMultiVersion() is always true ?

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


[clang] [clang] Refactor Builtins.def to be a tablegen file (PR #68324)

2024-03-05 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

Not right now. I think the first thing to do is moving all the builtins to 
tablegen before we can make better use of it, which is going to take a while.


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


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

2024-03-05 Thread via cfe-commits

mydeveloperday wrote:





> > But looking for a parenthesized single identifier addresses all of the 
> > examples in the issue.
> 
> I don't think it would work, but you are welcome to submit a patch to prove 
> me wrong. 🙂

+1 for this, it will be the 95%/5% rule, you might think all cases of 
(identifier) is a cast, but I'm pretty sure it won't be I'm with @owenca  on 
this, this patch will move us closer, meaning users don't need to add common 
types to TypeNames

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


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

2024-03-05 Thread via cfe-commits

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


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


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

2024-03-05 Thread via cfe-commits


@@ -71,8 +71,21 @@ bool FormatToken::isSimpleTypeSpecifier() const {
   }
 }
 
-bool FormatToken::isTypeOrIdentifier() const {
-  return isSimpleTypeSpecifier() || Tok.isOneOf(tok::kw_auto, tok::identifier);
+// Sorted common C++ non-keyword types.
+static SmallVector CppNonKeywordTypes = {
+"int16_t",  "int32_t",  "int64_t",  "int8_t",  "intptr_t",  "size_t",

mydeveloperday wrote:

ssize_t too? should everything be considered? 
https://en.cppreference.com/w/cpp/types/integer

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


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

2024-03-05 Thread via cfe-commits


@@ -620,6 +620,23 @@ TEST_F(TokenAnnotatorTest, UnderstandsCasts) {
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
   EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_Unknown);
   EXPECT_TOKEN(Tokens[4], tok::amp, TT_BinaryOperator);
+
+  Tokens = annotate("#define FOO(bar) foo((uint64_t)&bar)");
+  ASSERT_EQ(Tokens.size(), 15u) << Tokens;
+  EXPECT_TOKEN(Tokens[10], tok::r_paren, TT_CastRParen);
+  EXPECT_TOKEN(Tokens[11], tok::amp, TT_UnaryOperator);
+
+  Tokens = annotate("#define FOO(bar) foo((time_t) & bar)");

mydeveloperday wrote:

you didn't have time_t in the list did you? does that mean we are just checking 
this one uint64_t type above

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


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

2024-03-05 Thread via cfe-commits


@@ -268,20 +268,24 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
   if (isPossibleMacro(TypeToken))
 return Tok;
 
+  const bool IsCpp = Style.isCpp();
+
   // The case `const long long int volatile` -> `long long int const volatile`
   // The case `long const long int volatile` -> `long long int const volatile`
   // The case `long long volatile int const` -> `long long int const volatile`
   // The case `const long long volatile int` -> `long long int const volatile`
-  if (TypeToken->isSimpleTypeSpecifier()) {
+  if (TypeToken->isTypeName(IsCpp)) {

mydeveloperday wrote:

I'm not a fan of this extra argument proliferation

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


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

2024-03-05 Thread via cfe-commits

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


[clang] [Clang][Sema] Fix the lambda call expression inside of a type alias declaration (PR #82310)

2024-03-05 Thread via cfe-commits


@@ -313,9 +313,75 @@ Response HandleRecordDecl(const CXXRecordDecl *Rec,
 
   // This is to make sure we pick up the VarTemplateSpecializationDecl that 
this
   // lambda is defined inside of.
-  if (Rec->isLambda())
+  if (Rec->isLambda()) {
 if (const Decl *LCD = Rec->getLambdaContextDecl())
   return Response::ChangeDecl(LCD);
+// Attempt to retrieve the template arguments for a using alias 
declaration.
+// This is necessary for constraint checking, since we always keep
+// constraints relative to the primary template.
+if (ForConstraintInstantiation && !SemaRef.CodeSynthesisContexts.empty()) {
+  for (auto &CSC : llvm::reverse(SemaRef.CodeSynthesisContexts)) {
+if (CSC.Kind != Sema::CodeSynthesisContext::SynthesisKind::
+TypeAliasTemplateInstantiation)
+  continue;
+auto *TATD = cast(CSC.Entity),
+ *CurrentTATD = TATD;
+FunctionDecl *LambdaCallOperator = Rec->getLambdaCallOperator();
+// Retrieve the 'primary' template for a lambda call operator. It's
+// unfortunate that we only have the mappings of call operators rather
+// than lambda classes.
+while (true) {
+  auto *FTD = dyn_cast_if_present(
+  LambdaCallOperator->getDescribedTemplate());
+  if (FTD && FTD->getInstantiatedFromMemberTemplate()) {
+LambdaCallOperator =
+FTD->getInstantiatedFromMemberTemplate()->getTemplatedDecl();
+  } else if (auto *Prev = cast(LambdaCallOperator)
+  ->getInstantiatedFromMemberFunction())
+LambdaCallOperator = Prev;
+  else
+break;
+}
+// Same applies for type alias Decl. We perform this to obtain the

cor3ntin wrote:

> Same applies for type alias Decl

I'm not sure I understand this comment. What does "Same" refer to? Can you 
rephrase?

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


[clang] [Clang][Sema] Fix the lambda call expression inside of a type alias declaration (PR #82310)

2024-03-05 Thread via cfe-commits


@@ -313,9 +313,75 @@ Response HandleRecordDecl(const CXXRecordDecl *Rec,
 
   // This is to make sure we pick up the VarTemplateSpecializationDecl that 
this
   // lambda is defined inside of.
-  if (Rec->isLambda())
+  if (Rec->isLambda()) {
 if (const Decl *LCD = Rec->getLambdaContextDecl())
   return Response::ChangeDecl(LCD);
+// Attempt to retrieve the template arguments for a using alias 
declaration.

cor3ntin wrote:

```suggestion
// Retrieve the template arguments for a using alias declaration.
```

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


[clang] [Clang][Sema] Fix the lambda call expression inside of a type alias declaration (PR #82310)

2024-03-05 Thread via cfe-commits


@@ -614,10 +614,14 @@ bool Sema::SetupConstraintScope(
 // reference the original primary template.
 // We walk up the instantiated template chain so that nested lambdas get
 // handled properly.
-for (FunctionTemplateDecl *FromMemTempl =
- PrimaryTemplate->getInstantiatedFromMemberTemplate();
- FromMemTempl;
- FromMemTempl = FromMemTempl->getInstantiatedFromMemberTemplate()) {
+// Note that we shall not collect instantiated parameters from
+// 'intermediate' transformed function templates but the primary template
+// for which we have built up the template arguments relative to. 
Otherwise,
+// we may have mismatched template parameter depth!

cor3ntin wrote:

```suggestion
// We should only collect instantiated parameters from 
// the primary template. Otherwise, we may have mismatched template 
parameter depth!
```

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


[clang] [Clang][Sema] Fix the lambda call expression inside of a type alias declaration (PR #82310)

2024-03-05 Thread via cfe-commits


@@ -313,9 +313,75 @@ Response HandleRecordDecl(const CXXRecordDecl *Rec,
 
   // This is to make sure we pick up the VarTemplateSpecializationDecl that 
this
   // lambda is defined inside of.
-  if (Rec->isLambda())
+  if (Rec->isLambda()) {
 if (const Decl *LCD = Rec->getLambdaContextDecl())
   return Response::ChangeDecl(LCD);
+// Attempt to retrieve the template arguments for a using alias 
declaration.
+// This is necessary for constraint checking, since we always keep
+// constraints relative to the primary template.
+if (ForConstraintInstantiation && !SemaRef.CodeSynthesisContexts.empty()) {

cor3ntin wrote:

```suggestion
if (ForConstraintInstantiation) {
```

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


[clang] [Clang][Sema] Fix the lambda call expression inside of a type alias declaration (PR #82310)

2024-03-05 Thread via cfe-commits


@@ -313,9 +313,75 @@ Response HandleRecordDecl(const CXXRecordDecl *Rec,
 
   // This is to make sure we pick up the VarTemplateSpecializationDecl that 
this
   // lambda is defined inside of.
-  if (Rec->isLambda())
+  if (Rec->isLambda()) {
 if (const Decl *LCD = Rec->getLambdaContextDecl())
   return Response::ChangeDecl(LCD);
+// Attempt to retrieve the template arguments for a using alias 
declaration.
+// This is necessary for constraint checking, since we always keep
+// constraints relative to the primary template.
+if (ForConstraintInstantiation && !SemaRef.CodeSynthesisContexts.empty()) {
+  for (auto &CSC : llvm::reverse(SemaRef.CodeSynthesisContexts)) {
+if (CSC.Kind != Sema::CodeSynthesisContext::SynthesisKind::
+TypeAliasTemplateInstantiation)
+  continue;
+auto *TATD = cast(CSC.Entity),
+ *CurrentTATD = TATD;
+FunctionDecl *LambdaCallOperator = Rec->getLambdaCallOperator();
+// Retrieve the 'primary' template for a lambda call operator. It's
+// unfortunate that we only have the mappings of call operators rather
+// than lambda classes.
+while (true) {
+  auto *FTD = dyn_cast_if_present(
+  LambdaCallOperator->getDescribedTemplate());
+  if (FTD && FTD->getInstantiatedFromMemberTemplate()) {
+LambdaCallOperator =
+FTD->getInstantiatedFromMemberTemplate()->getTemplatedDecl();
+  } else if (auto *Prev = cast(LambdaCallOperator)
+  ->getInstantiatedFromMemberFunction())
+LambdaCallOperator = Prev;
+  else
+break;
+}

cor3ntin wrote:

```suggestion
  if (auto *FTD = dyn_cast_if_present(
  LambdaCallOperator->getDescribedTemplate(); FTD && 
FTD->getInstantiatedFromMemberTemplate()) {
LambdaCallOperator =
FTD->getInstantiatedFromMemberTemplate()->getTemplatedDecl();
  } else if (auto *Prev = cast(LambdaCallOperator)
  ->getInstantiatedFromMemberFunction())
LambdaCallOperator = Prev;
  else
break;
}
```

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


[clang] [Clang][Sema] Fix the lambda call expression inside of a type alias declaration (PR #82310)

2024-03-05 Thread via cfe-commits


@@ -313,9 +313,75 @@ Response HandleRecordDecl(const CXXRecordDecl *Rec,
 
   // This is to make sure we pick up the VarTemplateSpecializationDecl that 
this
   // lambda is defined inside of.
-  if (Rec->isLambda())
+  if (Rec->isLambda()) {
 if (const Decl *LCD = Rec->getLambdaContextDecl())
   return Response::ChangeDecl(LCD);
+// Attempt to retrieve the template arguments for a using alias 
declaration.
+// This is necessary for constraint checking, since we always keep
+// constraints relative to the primary template.
+if (ForConstraintInstantiation && !SemaRef.CodeSynthesisContexts.empty()) {
+  for (auto &CSC : llvm::reverse(SemaRef.CodeSynthesisContexts)) {
+if (CSC.Kind != Sema::CodeSynthesisContext::SynthesisKind::
+TypeAliasTemplateInstantiation)
+  continue;
+auto *TATD = cast(CSC.Entity),
+ *CurrentTATD = TATD;
+FunctionDecl *LambdaCallOperator = Rec->getLambdaCallOperator();
+// Retrieve the 'primary' template for a lambda call operator. It's
+// unfortunate that we only have the mappings of call operators rather
+// than lambda classes.
+while (true) {
+  auto *FTD = dyn_cast_if_present(
+  LambdaCallOperator->getDescribedTemplate());
+  if (FTD && FTD->getInstantiatedFromMemberTemplate()) {
+LambdaCallOperator =
+FTD->getInstantiatedFromMemberTemplate()->getTemplatedDecl();
+  } else if (auto *Prev = cast(LambdaCallOperator)
+  ->getInstantiatedFromMemberFunction())
+LambdaCallOperator = Prev;
+  else
+break;
+}
+// Same applies for type alias Decl. We perform this to obtain the
+// "canonical" template parameter depths.
+while (TATD->getInstantiatedFromMemberTemplate())
+  TATD = TATD->getInstantiatedFromMemberTemplate();
+// Tell if we're currently inside of a lambda expression that is
+// surrounded by a using alias declaration. e.g.
+//   template  using type = decltype([](auto) { ^ }());
+// By checking if:
+//  1. The lambda expression and the using alias declaration share the
+//  same declaration context.
+//  2. They have the same template depth.
+// Then we assume the template arguments from the using alias
+// declaration are essential for constraint instantiation. We have to 
do
+// so since a TypeAliasTemplateDecl (or a TypeAliasDecl) is never a
+// DeclContext, nor does it have an associated specialization Decl from
+// which we could collect these template arguments.
+if (cast(LambdaCallOperator->getDeclContext())
+->getTemplateDepth() == TATD->getTemplateDepth() &&
+getLambdaAwareParentOfDeclContext(LambdaCallOperator) ==
+TATD->getDeclContext()) {
+  Result.addOuterTemplateArguments(CurrentTATD,
+   CSC.template_arguments(),
+   /*Final=*/false);
+  // Visit the parent of the current type alias declaration rather than
+  // the lambda thereof. We have the following case:
+  // struct S {
+  //  template  using T = decltype([] {} ());
+  // };
+  // void foo() {
+  //   S::T var;
+  // }
+  // The instantiated lambda expression (which we're visiting at 'var')
+  // has a function DeclContext 'foo' rather than the Record 
DeclContext
+  // S. This seems to be an oversight that we may want to set a Sema
+  // Context from the CXXScopeSpec before substituting into T to me.

cor3ntin wrote:

@erichkeane Opinion?

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


[clang] [Clang][Sema] Fix the lambda call expression inside of a type alias declaration (PR #82310)

2024-03-05 Thread via cfe-commits


@@ -13905,6 +13911,31 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 /*IsInstantiation*/ true);
   SavedContext.pop();
 
+  // Recompute the dependency of the lambda so that we can defer the lambda 
call
+  // construction until after we have sufficient template arguments. For

cor3ntin wrote:

```suggestion
  // construction until after we have all the necessary template arguments. For
```

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


[clang] [Clang][Sema] Fix the lambda call expression inside of a type alias declaration (PR #82310)

2024-03-05 Thread via cfe-commits


@@ -313,9 +313,75 @@ Response HandleRecordDecl(const CXXRecordDecl *Rec,
 
   // This is to make sure we pick up the VarTemplateSpecializationDecl that 
this
   // lambda is defined inside of.
-  if (Rec->isLambda())
+  if (Rec->isLambda()) {
 if (const Decl *LCD = Rec->getLambdaContextDecl())
   return Response::ChangeDecl(LCD);
+// Attempt to retrieve the template arguments for a using alias 
declaration.
+// This is necessary for constraint checking, since we always keep
+// constraints relative to the primary template.
+if (ForConstraintInstantiation && !SemaRef.CodeSynthesisContexts.empty()) {
+  for (auto &CSC : llvm::reverse(SemaRef.CodeSynthesisContexts)) {
+if (CSC.Kind != Sema::CodeSynthesisContext::SynthesisKind::
+TypeAliasTemplateInstantiation)
+  continue;
+auto *TATD = cast(CSC.Entity),
+ *CurrentTATD = TATD;
+FunctionDecl *LambdaCallOperator = Rec->getLambdaCallOperator();
+// Retrieve the 'primary' template for a lambda call operator. It's
+// unfortunate that we only have the mappings of call operators rather
+// than lambda classes.
+while (true) {
+  auto *FTD = dyn_cast_if_present(
+  LambdaCallOperator->getDescribedTemplate());
+  if (FTD && FTD->getInstantiatedFromMemberTemplate()) {
+LambdaCallOperator =
+FTD->getInstantiatedFromMemberTemplate()->getTemplatedDecl();
+  } else if (auto *Prev = cast(LambdaCallOperator)
+  ->getInstantiatedFromMemberFunction())
+LambdaCallOperator = Prev;
+  else
+break;
+}
+// Same applies for type alias Decl. We perform this to obtain the
+// "canonical" template parameter depths.
+while (TATD->getInstantiatedFromMemberTemplate())
+  TATD = TATD->getInstantiatedFromMemberTemplate();
+// Tell if we're currently inside of a lambda expression that is

cor3ntin wrote:

```suggestion
// Check if we are currently inside of a lambda expression that is
```

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


[clang] [Clang][Sema] Fix the lambda call expression inside of a type alias declaration (PR #82310)

2024-03-05 Thread via cfe-commits


@@ -313,9 +313,75 @@ Response HandleRecordDecl(const CXXRecordDecl *Rec,
 
   // This is to make sure we pick up the VarTemplateSpecializationDecl that 
this
   // lambda is defined inside of.
-  if (Rec->isLambda())
+  if (Rec->isLambda()) {
 if (const Decl *LCD = Rec->getLambdaContextDecl())
   return Response::ChangeDecl(LCD);
+// Attempt to retrieve the template arguments for a using alias 
declaration.
+// This is necessary for constraint checking, since we always keep
+// constraints relative to the primary template.
+if (ForConstraintInstantiation && !SemaRef.CodeSynthesisContexts.empty()) {
+  for (auto &CSC : llvm::reverse(SemaRef.CodeSynthesisContexts)) {
+if (CSC.Kind != Sema::CodeSynthesisContext::SynthesisKind::
+TypeAliasTemplateInstantiation)
+  continue;
+auto *TATD = cast(CSC.Entity),
+ *CurrentTATD = TATD;
+FunctionDecl *LambdaCallOperator = Rec->getLambdaCallOperator();
+// Retrieve the 'primary' template for a lambda call operator. It's
+// unfortunate that we only have the mappings of call operators rather
+// than lambda classes.
+while (true) {
+  auto *FTD = dyn_cast_if_present(
+  LambdaCallOperator->getDescribedTemplate());
+  if (FTD && FTD->getInstantiatedFromMemberTemplate()) {
+LambdaCallOperator =
+FTD->getInstantiatedFromMemberTemplate()->getTemplatedDecl();
+  } else if (auto *Prev = cast(LambdaCallOperator)
+  ->getInstantiatedFromMemberFunction())
+LambdaCallOperator = Prev;
+  else
+break;
+}
+// Same applies for type alias Decl. We perform this to obtain the
+// "canonical" template parameter depths.

cor3ntin wrote:

```suggestion
// canonical template parameter depth.
```

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


[clang] [Clang][Sema] Fix the lambda call expression inside of a type alias declaration (PR #82310)

2024-03-05 Thread via cfe-commits


@@ -13905,6 +13911,31 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 /*IsInstantiation*/ true);
   SavedContext.pop();
 
+  // Recompute the dependency of the lambda so that we can defer the lambda 
call
+  // construction until after we have sufficient template arguments. For
+  // example, template  struct S {
+  //   template 

cor3ntin wrote:

```suggestion
  // example, given
  // template  struct S {
  //   template 
```

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


[clang] [Clang][Sema] Fix the lambda call expression inside of a type alias declaration (PR #82310)

2024-03-05 Thread via cfe-commits


@@ -614,6 +682,15 @@ Sema::InstantiatingTemplate::InstantiatingTemplate(
   PointOfInstantiation, InstantiationRange, Param, Template,
   TemplateArgs) {}
 
+Sema::InstantiatingTemplate::InstantiatingTemplate(
+Sema &SemaRef, SourceLocation PointOfInstantiation,
+TypeAliasTemplateDecl *Template, ArrayRef TemplateArgs,
+SourceRange InstantiationRange)
+: InstantiatingTemplate(
+  SemaRef, Sema::CodeSynthesisContext::TypeAliasTemplateInstantiation,
+  PointOfInstantiation, InstantiationRange, /*Entity=*/Template,
+  nullptr, TemplateArgs) {}

cor3ntin wrote:

Can you add a comment for the `nullptr`?

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


[clang] [Clang][Sema] Fix the lambda call expression inside of a type alias declaration (PR #82310)

2024-03-05 Thread via cfe-commits


@@ -313,9 +313,75 @@ Response HandleRecordDecl(const CXXRecordDecl *Rec,
 
   // This is to make sure we pick up the VarTemplateSpecializationDecl that 
this
   // lambda is defined inside of.
-  if (Rec->isLambda())
+  if (Rec->isLambda()) {
 if (const Decl *LCD = Rec->getLambdaContextDecl())
   return Response::ChangeDecl(LCD);
+// Attempt to retrieve the template arguments for a using alias 
declaration.
+// This is necessary for constraint checking, since we always keep
+// constraints relative to the primary template.
+if (ForConstraintInstantiation && !SemaRef.CodeSynthesisContexts.empty()) {
+  for (auto &CSC : llvm::reverse(SemaRef.CodeSynthesisContexts)) {
+if (CSC.Kind != Sema::CodeSynthesisContext::SynthesisKind::
+TypeAliasTemplateInstantiation)
+  continue;
+auto *TATD = cast(CSC.Entity),
+ *CurrentTATD = TATD;
+FunctionDecl *LambdaCallOperator = Rec->getLambdaCallOperator();
+// Retrieve the 'primary' template for a lambda call operator. It's
+// unfortunate that we only have the mappings of call operators rather
+// than lambda classes.
+while (true) {
+  auto *FTD = dyn_cast_if_present(
+  LambdaCallOperator->getDescribedTemplate());
+  if (FTD && FTD->getInstantiatedFromMemberTemplate()) {
+LambdaCallOperator =
+FTD->getInstantiatedFromMemberTemplate()->getTemplatedDecl();
+  } else if (auto *Prev = cast(LambdaCallOperator)
+  ->getInstantiatedFromMemberFunction())
+LambdaCallOperator = Prev;
+  else
+break;
+}
+// Same applies for type alias Decl. We perform this to obtain the
+// "canonical" template parameter depths.
+while (TATD->getInstantiatedFromMemberTemplate())
+  TATD = TATD->getInstantiatedFromMemberTemplate();
+// Tell if we're currently inside of a lambda expression that is
+// surrounded by a using alias declaration. e.g.
+//   template  using type = decltype([](auto) { ^ }());
+// By checking if:
+//  1. The lambda expression and the using alias declaration share the
+//  same declaration context.
+//  2. They have the same template depth.
+// Then we assume the template arguments from the using alias
+// declaration are essential for constraint instantiation. We have to 
do

cor3ntin wrote:

```suggestion
// Then we assume the template arguments of the using alias
// declaration are necessary for constraint instantiation. We have to do
```

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


[clang] [Clang][Sema] Fix the lambda call expression inside of a type alias declaration (PR #82310)

2024-03-05 Thread via cfe-commits


@@ -13905,6 +13911,31 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 /*IsInstantiation*/ true);
   SavedContext.pop();
 
+  // Recompute the dependency of the lambda so that we can defer the lambda 
call
+  // construction until after we have sufficient template arguments. For
+  // example, template  struct S {
+  //   template 
+  //   using Type = decltype([](U){}(42.0));
+  // };
+  // void foo() {
+  //   using T = S::Type;
+  // ^~
+  // }
+  // We would end up here from instantiating the S as we're ensuring the
+  // completeness. That would make us transform the lambda call expression
+  // despite the fact that we don't see the argument for U yet. We have a

cor3ntin wrote:

```suggestion
  // We would end up here from instantiating S when ensuring its
  // completeness. That would make us transform the lambda call expression
  // despite the fact that we don't have a corresponding argument for U yet. We 
have a
```

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


[clang] [Clang][Sema] Fix the lambda call expression inside of a type alias declaration (PR #82310)

2024-03-05 Thread via cfe-commits


@@ -313,9 +313,75 @@ Response HandleRecordDecl(const CXXRecordDecl *Rec,
 
   // This is to make sure we pick up the VarTemplateSpecializationDecl that 
this
   // lambda is defined inside of.
-  if (Rec->isLambda())
+  if (Rec->isLambda()) {
 if (const Decl *LCD = Rec->getLambdaContextDecl())
   return Response::ChangeDecl(LCD);
+// Attempt to retrieve the template arguments for a using alias 
declaration.
+// This is necessary for constraint checking, since we always keep
+// constraints relative to the primary template.
+if (ForConstraintInstantiation && !SemaRef.CodeSynthesisContexts.empty()) {
+  for (auto &CSC : llvm::reverse(SemaRef.CodeSynthesisContexts)) {
+if (CSC.Kind != Sema::CodeSynthesisContext::SynthesisKind::
+TypeAliasTemplateInstantiation)
+  continue;
+auto *TATD = cast(CSC.Entity),
+ *CurrentTATD = TATD;
+FunctionDecl *LambdaCallOperator = Rec->getLambdaCallOperator();
+// Retrieve the 'primary' template for a lambda call operator. It's
+// unfortunate that we only have the mappings of call operators rather
+// than lambda classes.
+while (true) {
+  auto *FTD = dyn_cast_if_present(
+  LambdaCallOperator->getDescribedTemplate());
+  if (FTD && FTD->getInstantiatedFromMemberTemplate()) {
+LambdaCallOperator =
+FTD->getInstantiatedFromMemberTemplate()->getTemplatedDecl();
+  } else if (auto *Prev = cast(LambdaCallOperator)
+  ->getInstantiatedFromMemberFunction())
+LambdaCallOperator = Prev;
+  else
+break;
+}
+// Same applies for type alias Decl. We perform this to obtain the
+// "canonical" template parameter depths.
+while (TATD->getInstantiatedFromMemberTemplate())
+  TATD = TATD->getInstantiatedFromMemberTemplate();
+// Tell if we're currently inside of a lambda expression that is
+// surrounded by a using alias declaration. e.g.
+//   template  using type = decltype([](auto) { ^ }());
+// By checking if:
+//  1. The lambda expression and the using alias declaration share the
+//  same declaration context.
+//  2. They have the same template depth.
+// Then we assume the template arguments from the using alias
+// declaration are essential for constraint instantiation. We have to 
do
+// so since a TypeAliasTemplateDecl (or a TypeAliasDecl) is never a
+// DeclContext, nor does it have an associated specialization Decl from
+// which we could collect these template arguments.
+if (cast(LambdaCallOperator->getDeclContext())
+->getTemplateDepth() == TATD->getTemplateDepth() &&
+getLambdaAwareParentOfDeclContext(LambdaCallOperator) ==
+TATD->getDeclContext()) {
+  Result.addOuterTemplateArguments(CurrentTATD,
+   CSC.template_arguments(),
+   /*Final=*/false);
+  // Visit the parent of the current type alias declaration rather than
+  // the lambda thereof. We have the following case:

cor3ntin wrote:

```suggestion
  // Visit the parent of the current type alias declaration rather than
  // the lambda thereof. 
  E.g, in the following example:
```

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


[clang] [Clang][Sema] Fix the lambda call expression inside of a type alias declaration (PR #82310)

2024-03-05 Thread via cfe-commits


@@ -13905,6 +13911,31 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 /*IsInstantiation*/ true);
   SavedContext.pop();
 
+  // Recompute the dependency of the lambda so that we can defer the lambda 
call
+  // construction until after we have sufficient template arguments. For
+  // example, template  struct S {
+  //   template 
+  //   using Type = decltype([](U){}(42.0));
+  // };
+  // void foo() {
+  //   using T = S::Type;
+  // ^~
+  // }
+  // We would end up here from instantiating the S as we're ensuring the
+  // completeness. That would make us transform the lambda call expression
+  // despite the fact that we don't see the argument for U yet. We have a
+  // mechanism that circumvents the semantic checking if the CallExpr is
+  // dependent. We can harness that by recomputing the lambda dependency from
+  // the instantiation arguments. I'm putting it here rather than the above
+  // since we can see transformed lambda parameters in case that they're
+  // useful for calculation.
+  DependencyKind = getDerived().ComputeLambdaDependency(&LSICopy);
+  Class->setLambdaDependencyKind(DependencyKind);
+  // Clean up the type cache created previously. Then, we re-create a type for
+  // such Decl with the new DependencyKind.
+  Class->setTypeForDecl(nullptr);
+  getSema().Context.getTypeDeclType(Class);
+

cor3ntin wrote:

This is not great, but I am not sure how we can improve. 
I think it's worth a fixme
@erichkeane 

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


[clang] [ObjC] Check entire chain of superclasses to see if class layout is statically known (PR #81335)

2024-03-05 Thread Youngsuk Kim via cfe-commits

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

LGTM

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


[clang] 923ddf6 - [ObjC] Check entire chain of superclasses to see if class layout is statically known (#81335)

2024-03-05 Thread via cfe-commits

Author: AtariDreams
Date: 2024-03-05T06:32:45-05:00
New Revision: 923ddf65f4e21ec67018cf56e823895de18d83bc

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

LOG: [ObjC] Check entire chain of superclasses to see if class layout is 
statically known (#81335)

As of now, we only check if a class directly inherits from NSObject to
determine if said class has fixed offsets and can therefore "opt-out"
from the non-fragile ABI for ivars.

However, if an NSObject subclass has fixed offsets, then so must the
subclasses of that subclass, so this allows us to optimize instances of
subclasses of subclasses that inherit from NSObject and so on.

To determine this, we need to find that the compiler can see the
implementation of each intermediate class, as that means it is
statically linked.

Fixes: #81369

Added: 


Modified: 
clang/lib/CodeGen/CGObjCMac.cpp
clang/test/CodeGenObjC/constant-non-fragile-ivar-offset.m

Removed: 




diff  --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 27d77e9a8a5511..e815e097e1fb48 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -1593,12 +1593,20 @@ class CGObjCNonFragileABIMac : public CGObjCCommonMac {
   }
 
   bool isClassLayoutKnownStatically(const ObjCInterfaceDecl *ID) {
-// NSObject is a fixed size. If we can see the @implementation of a class
-// which inherits from NSObject then we know that all it's offsets also 
must
-// be fixed. FIXME: Can we do this if see a chain of super classes with
-// implementations leading to NSObject?
-return ID->getImplementation() && ID->getSuperClass() &&
-   ID->getSuperClass()->getName() == "NSObject";
+// Test a class by checking its superclasses up to
+// its base class if it has one.
+for (; ID; ID = ID->getSuperClass()) {
+  // The layout of base class NSObject
+  // is guaranteed to be statically known
+  if (ID->getIdentifier()->getName() == "NSObject")
+return true;
+
+  // If we cannot see the @implementation of a class,
+  // we cannot statically know the class layout.
+  if (!ID->getImplementation())
+return false;
+}
+return false;
   }
 
 public:

diff  --git a/clang/test/CodeGenObjC/constant-non-fragile-ivar-offset.m 
b/clang/test/CodeGenObjC/constant-non-fragile-ivar-offset.m
index 788b3220af3067..8d55e6c7d23081 100644
--- a/clang/test/CodeGenObjC/constant-non-fragile-ivar-offset.m
+++ b/clang/test/CodeGenObjC/constant-non-fragile-ivar-offset.m
@@ -1,6 +1,13 @@
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.14.0 -emit-llvm %s -o - | 
FileCheck %s
 
 // CHECK: @"OBJC_IVAR_$_StaticLayout.static_layout_ivar" = hidden constant i64 
20
+// CHECK: @"OBJC_IVAR_$_SuperClass.superClassIvar" = hidden constant i64 20
+// CHECK: @"OBJC_IVAR_$_SuperClass._superClassProperty" = hidden constant i64 
24
+// CHECK: @"OBJC_IVAR_$_IntermediateClass.intermediateClassIvar" = constant 
i64 32
+// CHECK: @"OBJC_IVAR_$_IntermediateClass.intermediateClassIvar2" = constant 
i64 40
+// CHECK: @"OBJC_IVAR_$_IntermediateClass._intermediateProperty" = hidden 
constant i64 48
+// CHECK: @"OBJC_IVAR_$_SubClass.subClassIvar" = constant i64 56
+// CHECK: @"OBJC_IVAR_$_SubClass._subClassProperty" = hidden constant i64 64
 // CHECK: @"OBJC_IVAR_$_NotStaticLayout.not_static_layout_ivar" = hidden 
global i64 12
 
 @interface NSObject {
@@ -14,12 +21,105 @@ @interface StaticLayout : NSObject
 @implementation StaticLayout {
   int static_layout_ivar;
 }
+
+// CHECK-LABEL: define internal void @"\01-[StaticLayout meth]"
 -(void)meth {
   static_layout_ivar = 0;
   // CHECK-NOT: load i64, ptr @"OBJC_IVAR_$_StaticLayout
+  // CHECK: getelementptr inbounds i8, ptr %0, i64 20
+}
+@end
+
+@interface SuperClass : NSObject
+@property (nonatomic, assign) int superClassProperty;
+@end
+
+@implementation SuperClass {
+  int superClassIvar; // Declare an ivar
+}
+
+// CHECK-LABEL: define internal void @"\01-[SuperClass superClassMethod]"
+- (void)superClassMethod {
+_superClassProperty = 42;
+superClassIvar = 10;
+// CHECK-NOT: load i64, ptr @"OBJC_IVAR_$_SuperClass
+// CHECK: getelementptr inbounds i8, ptr %1, i64 20
+}
+
+// Implicitly synthesized method here
+// CHECK-LABEL: define internal i32 @"\01-[SuperClass superClassProperty]"
+// CHECK: getelementptr inbounds i8, ptr %0, i64 24
+
+// CHECK-LABEL: define internal void @"\01-[SuperClass setSuperClassProperty:]"
+// CHECK: getelementptr inbounds i8, ptr %1, i64 24
+@end
+
+@interface IntermediateClass : SuperClass {
+double intermediateClassIvar;
+
+@protected
+int intermediateClassIvar2;
+}
+@property (nonatomic, strong) SuperClass *intermediateProperty;
+@end
+
+@implementation IntermediateClass
+@synthes

[clang] [ObjC] Check entire chain of superclasses to see if class layout is statically known (PR #81335)

2024-03-05 Thread Youngsuk Kim via cfe-commits

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


[clang] [clang][nullability] Don't discard expression state before end of full-expression. (PR #82611)

2024-03-05 Thread via cfe-commits

https://github.com/martinboehme updated 
https://github.com/llvm/llvm-project/pull/82611

>From 109e72445fb8da4dd0cf08b5985986ca864a3536 Mon Sep 17 00:00:00 2001
From: Martin Braenne 
Date: Thu, 22 Feb 2024 11:23:30 +
Subject: [PATCH 1/2] [clang][nullability] Don't discard expression state
 before end of full-expression.

In https://github.com/llvm/llvm-project/pull/72985, I made a change to discard
expression state (`ExprToLoc` and `ExprToVal`) at the beginning of each basic
block. I did so with the claim that "we never need to access entries from these
maps outside of the current basic block", noting that there are exceptions to
this claim when control flow happens inside a full-expression (the operands of
`&&`, `||`, and the conditional operator live in different basic blocks than the
operator itself) but that we already have a mechanism for retrieving the values
of these operands from the environment for the block they are computed in.

It turns out, however, that the operands of these operators aren't the only
expressions whose values can be accessed from a different basic block; when
control flow happens within a full-expression, that control flow can be
"interposed" between an expression and its parent. Here is an example:

```cxx
void f(int*, int);
bool cond();

void target() {
  int i = 0;
  f(&i, cond() ? 1 : 0);
}
```

([godbolt](https://godbolt.org/z/hrbj1Mj3o))

In the CFG[^1] , note how the expression for `&i` is computed in block B4,
but the parent of this expression (the `CallExpr`) is located in block B1.
The the argument expression `&i` and the `CallExpr` are essentially "torn apart"
into different basic blocks by the conditional operator in the second argument.
In other words, the edge between the `CallExpr` and its argument `&i` straddles
the boundary between two blocks.

I used to think that this scenario -- where an edge between an expression and
one of its children straddles a block boundary -- could only happen between the
expression that triggers the control flow (`&&`, `||`, or the conditional
operator) and its children, but the example above shows that other expressions
can be affected as well; the control flow is still triggered by `&&`, `||` or
the conditional operator, but the expressions affected lie outside these
operators.

Discarding expression state too soon is harmful. For example, an analysis that
checks the arguments of the `CallExpr` above would not be able to retrieve a
value for the `&i` argument.

This patch therefore ensures that we don't discard expression state before the
end of a full-expression. In other cases -- when the evaluation of a
full-expression is complete -- we still want to discard expression state for the
reasons explained in https://github.com/llvm/llvm-project/pull/72985 (avoid
performing joins on boolean values that are no longer needed, which
unnecessarily extends the flow condition; improve debuggability by removing
clutter from the expression state).

[^1]:
```
 [B5 (ENTRY)]
   Succs (1): B4

 [B1]
   1: [B4.9] ? [B2.1] : [B3.1]
   2: [B4.4]([B4.6], [B1.1])
   Preds (2): B2 B3
   Succs (1): B0

 [B2]
   1: 1
   Preds (1): B4
   Succs (1): B1

 [B3]
   1: 0
   Preds (1): B4
   Succs (1): B1

 [B4]
   1: 0
   2: int i = 0;
   3: f
   4: [B4.3] (ImplicitCastExpr, FunctionToPointerDecay, void (*)(int *, int))
   5: i
   6: &[B4.5]
   7: cond
   8: [B4.7] (ImplicitCastExpr, FunctionToPointerDecay, _Bool (*)(void))
   9: [B4.8]()
   T: [B4.9] ? ... : ...
   Preds (1): B5
   Succs (2): B2 B3

 [B0 (EXIT)]
   Preds (1): B1
```
---
 .../FlowSensitive/ControlFlowContext.h|  25 -
 .../FlowSensitive/DataflowEnvironment.h   |  11 +-
 .../FlowSensitive/ControlFlowContext.cpp  |  36 +-
 .../FlowSensitive/DataflowEnvironment.cpp |  28 -
 .../TypeErasedDataflowAnalysis.cpp|  32 --
 .../FlowSensitive/DataflowEnvironmentTest.cpp |   3 +-
 .../TypeErasedDataflowAnalysisTest.cpp| 104 --
 7 files changed, 187 insertions(+), 52 deletions(-)

diff --git a/clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h 
b/clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
index 405e93287a05d3..9a0a00f3c01343 100644
--- a/clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
+++ b/clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
@@ -58,19 +58,36 @@ class ControlFlowContext {
 return BlockReachable[B.getBlockID()];
   }
 
+  /// Returns whether `B` contains an expression that is consumed in a
+  /// different block than `B` (i.e. the parent of the expression is in a
+  /// different block).
+  /// This happens if there is control flow within a full-expression (triggered
+  /// by `&&`, `||`, or the conditional operator). Note that the operands of
+  /// these operators are not the only expressions that can be consumed in a
+  /// different block. For example, in the function call
+  /// `f(&i, cond() ? 1 : 0)`, `&i` is in a different block than the 
`C

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

2024-03-05 Thread Alexandros Lamprineas via cfe-commits


@@ -11455,9 +11465,8 @@ static bool CheckTargetCausesMultiVersioning(Sema &S, 
FunctionDecl *OldFD,
   }
 
   // If this is 'default', permit the forward declaration.
-  if (!OldFD->isMultiVersion() &&
-  ((NewTA && NewTA->isDefaultVersion() && !OldTA) ||
-   (NewTVA && NewTVA->isDefaultVersion() && !OldTVA))) {
+  if ((NewTA && NewTA->isDefaultVersion() && !OldTA) ||

labrinea wrote:

As far as I can tell yes, this is astatic function with exactly one call site.

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


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

2024-03-05 Thread Alexandros Lamprineas via cfe-commits

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


[clang] [C++20] [Modules] Introduce reduced BMI (PR #75894)

2024-03-05 Thread Iain Sandoe via cfe-commits

iains wrote:

Do you expect to make any changes to type streaming?


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


[clang] [clang][nullability] Don't discard expression state before end of full-expression. (PR #82611)

2024-03-05 Thread via cfe-commits


@@ -248,12 +251,12 @@ class JoinedStateBuilder {
   // initialize the state of each basic block differently.
   return {AC.Analysis.typeErasedInitialElement(), AC.InitEnv.fork()};
 if (All.size() == 1)

martinboehme wrote:

> guard on ExprBehavior as well, like `if (All.size() == 1 && ExprBehavior == 
> DiscardExprState)`?

We would also need to return the existing state in the case `All.size() == 1 && 
ExprBehavior == KeepExprState`, right? IOW, the code would become something 
like this:

```
if (All.size() == 1) {
  if (ExprBehavior == KeepExprState)
return All[0];
  // Join the environment with itself so that we discard expression state.
  // FIXME: We could consider writing special-case code for this that only
  // does the discarding, but it's not clear if this is worth it.
  return {All[0]->Lattice, Environment::join(All[0]->Env, All[0]->Env,
 AC.Analysis, 
DiscardExprState)};
}
```

And it doesn't deal with the FIXME, as we still need some way to discard the 
expression state.

I'm not sure that, all in all, changing the code in this way would be 
preferable.

The upside is that we're now a bit more efficient in the case where `All.size() 
== 1` and we want to keep expression state.

The downside is that we're treating `KeepExprState` specially when `join()` 
could have handled it for us. Right now, `join()` is the only place that needs 
to care about what to do for `KeepExprState` versus `DiscardExprState`, and it 
would be nice to keep the behavior localized in this way.

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


[clang] [Sema] gh56556 (PR #83997)

2024-03-05 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 created 
https://github.com/llvm/llvm-project/pull/83997

CI

>From 69414d7352b170f6fcff22c6f5dfa91cc76b0b58 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Tue, 5 Mar 2024 19:56:59 +0800
Subject: [PATCH] gh56556

---
 clang/lib/Sema/TreeTransform.h | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 7389a48fe56fcc..c96ffcb97a7591 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13649,10 +13649,12 @@ 
TreeTransform::TransformLambdaExpr(LambdaExpr *E) {
   // use evaluation contexts to distinguish the function parameter case.
   CXXRecordDecl::LambdaDependencyKind DependencyKind =
   CXXRecordDecl::LDK_Unknown;
+  DeclContext *DC = getSema().CurContext;
+  if (DC->getDeclKind() == Decl::Kind::RequiresExprBody)
+DC = DC->getParent();
   if ((getSema().isUnevaluatedContext() ||
getSema().isConstantEvaluatedContext()) &&
-  (getSema().CurContext->isFileContext() ||
-   !getSema().CurContext->getParent()->isDependentContext()))
+  (DC->isFileContext() || !DC->getParent()->isDependentContext()))
 DependencyKind = CXXRecordDecl::LDK_NeverDependent;
 
   CXXRecordDecl *OldClass = E->getLambdaClass();

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


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

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

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

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

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

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

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

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


@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -fsyntax-only 
-Wignored-qualifiers -Wno-error=return-type -Wno-error=implicit-int -verify 
-fblocks -Wno-unreachable-code -Wno-unused-value -Wno-strict-prototypes
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -fsyntax-only 
-Wignored-qualifiers -Wno-error=return-type -Wno-error=return-mismatch 
-Wno-error=implicit-int -verify -fblocks -Wno-unreachable-code 
-Wno-unused-value -Wno-strict-prototypes
 
 // clang emits the following warning by default.
 // With GCC, -pedantic, -Wreturn-type or -Wall are required to produce the

11happy wrote:

done 

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


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

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


@@ -1,5 +1,5 @@
-// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 -Wno-int-conversion 
-Wno-strict-prototypes -Wno-tautological-constant-compare 
-Wtautological-unsigned-zero-compare -analyzer-checker=core,deadcode,alpha.core 
-std=gnu99 -analyzer-purge=none -verify %s -Wno-error=return-type
-// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 -Wno-int-conversion 
-Wno-strict-prototypes -Wno-tautological-constant-compare 
-Wtautological-unsigned-zero-compare -analyzer-checker=core,deadcode,alpha.core 
-std=gnu99 -verify %s -Wno-error=return-type
+// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 -Wno-int-conversion 
-Wno-strict-prototypes -Wno-tautological-constant-compare 
-Wtautological-unsigned-zero-compare -analyzer-checker=core,deadcode,alpha.core 
-std=gnu99 -analyzer-purge=none -verify %s -Wno-error=return-type 
-Wno-error=return-mismatch

11happy wrote:

sorry earlier I created a new seperate return-mismatch & tests were failing 
corrected it.

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


  1   2   3   4   5   6   >