[clang] [clang-repl] Simplify the value printing logic to enable out-of-process. (PR #107737)

2024-09-08 Thread Vassil Vassilev via cfe-commits

https://github.com/vgvassilev created 
https://github.com/llvm/llvm-project/pull/107737

This patch improves the design of the IncrementalParser and Interpreter 
classes. Now the incremental parser is only responsible for building the 
partial translation unit declaration and the AST, while the Interpreter fills 
in the lower level llvm::Module and other JIT-related infrastructure. Finally 
the Interpreter class now orchestrates the AST and the LLVM IR with the 
IncrementalParser and IncrementalExecutor classes.

The design improvement allows us to rework some of the logic that extracts an 
interpreter value into the clang::Value object. The new implementation 
simplifies use-cases which are used for out-of-process execution by allowing 
interpreter to be inherited or customized with an clang::ASTConsumer.

This change will enable completing the pretty printing work which is in 
llvm-project#84769

>From d4aa06a9118f92b4a2410794d56ee6cb530bbece Mon Sep 17 00:00:00 2001
From: Vassil Vassilev 
Date: Fri, 6 Sep 2024 09:52:36 +
Subject: [PATCH] [clang-repl] Simplify the value printing logic to enable
 out-of-process.

This patch improves the design of the IncrementalParser and Interpreter classes.
Now the incremental parser is only responsible for building the partial
translation unit declaration and the AST, while the Interpreter fills in the
lower level llvm::Module and other JIT-related infrastructure. Finally the
Interpreter class now orchestrates the AST and the LLVM IR with the
IncrementalParser and IncrementalExecutor classes.

The design improvement allows us to rework some of the logic that extracts an
interpreter value into the clang::Value object. The new implementation
simplifies use-cases which are used for out-of-process execution by allowing
interpreter to be inherited or customized with an clang::ASTConsumer.

This change will enable completing the pretty printing work which is in
llvm-project#84769
---
 .../clang/Frontend/MultiplexConsumer.h|   3 +-
 clang/include/clang/Interpreter/Interpreter.h |  53 +-
 clang/lib/Frontend/MultiplexConsumer.cpp  |   7 +
 clang/lib/Interpreter/CMakeLists.txt  |   1 +
 clang/lib/Interpreter/DeviceOffload.cpp   |  10 +-
 clang/lib/Interpreter/DeviceOffload.h |  14 +-
 clang/lib/Interpreter/IncrementalExecutor.cpp |   2 +-
 clang/lib/Interpreter/IncrementalParser.cpp   | 253 +--
 clang/lib/Interpreter/IncrementalParser.h |  45 +-
 clang/lib/Interpreter/Interpreter.cpp | 646 ++
 .../Interpreter/InterpreterValuePrinter.cpp   | 398 +++
 .../Interpreter/CodeCompletionTest.cpp|   2 +-
 .../Interpreter/InterpreterExtensionsTest.cpp |  64 +-
 13 files changed, 705 insertions(+), 793 deletions(-)
 create mode 100644 clang/lib/Interpreter/InterpreterValuePrinter.cpp

diff --git a/clang/include/clang/Frontend/MultiplexConsumer.h 
b/clang/include/clang/Frontend/MultiplexConsumer.h
index 3a7670d7a51aa6..b190750bb29fb8 100644
--- a/clang/include/clang/Frontend/MultiplexConsumer.h
+++ b/clang/include/clang/Frontend/MultiplexConsumer.h
@@ -53,6 +53,7 @@ class MultiplexConsumer : public SemaConsumer {
 public:
   // Takes ownership of the pointers in C.
   MultiplexConsumer(std::vector> C);
+  MultiplexConsumer(std::unique_ptr C);
   ~MultiplexConsumer() override;
 
   // ASTConsumer
@@ -80,7 +81,7 @@ class MultiplexConsumer : public SemaConsumer {
   void InitializeSema(Sema &S) override;
   void ForgetSema() override;
 
-private:
+protected:
   std::vector> Consumers; // Owns these.
   std::unique_ptr MutationListener;
   std::unique_ptr DeserializationListener;
diff --git a/clang/include/clang/Interpreter/Interpreter.h 
b/clang/include/clang/Interpreter/Interpreter.h
index 1234608bb58647..cbb1cfd4ab02a8 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -14,11 +14,9 @@
 #ifndef LLVM_CLANG_INTERPRETER_INTERPRETER_H
 #define LLVM_CLANG_INTERPRETER_INTERPRETER_H
 
-#include "clang/AST/Decl.h"
 #include "clang/AST/GlobalDecl.h"
 #include "clang/Interpreter/PartialTranslationUnit.h"
 #include "clang/Interpreter/Value.h"
-#include "clang/Sema/Ownership.h"
 
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ExecutionEngine/JITSymbol.h"
@@ -38,6 +36,9 @@ class ThreadSafeContext;
 namespace clang {
 
 class CompilerInstance;
+class CodeGenerator;
+class CXXRecordDecl;
+class Decl;
 class IncrementalExecutor;
 class IncrementalParser;
 
@@ -77,26 +78,27 @@ class IncrementalCompilerBuilder {
   llvm::StringRef CudaSDKPath;
 };
 
-/// Generate glue code between the Interpreter's built-in runtime and user 
code.
-class RuntimeInterfaceBuilder {
-public:
-  virtual ~RuntimeInterfaceBuilder() = default;
-
-  using TransformExprFunction = ExprResult(RuntimeInterfaceBuilder *Builder,
-   Expr *, ArrayRef);
-  virtual TransformExprFunction *getPrintValueTransformer() = 0;
-};
+class IncrementalAction;
+class In

[clang] [clang-repl] Simplify the value printing logic to enable out-of-process. (PR #107737)

2024-09-08 Thread Vassil Vassilev via cfe-commits

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


[clang] [clang-repl] Simplify the value printing logic to enable out-of-process. (PR #107737)

2024-09-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Vassil Vassilev (vgvassilev)


Changes

This patch improves the design of the IncrementalParser and Interpreter 
classes. Now the incremental parser is only responsible for building the 
partial translation unit declaration and the AST, while the Interpreter fills 
in the lower level llvm::Module and other JIT-related infrastructure. Finally 
the Interpreter class now orchestrates the AST and the LLVM IR with the 
IncrementalParser and IncrementalExecutor classes.

The design improvement allows us to rework some of the logic that extracts an 
interpreter value into the clang::Value object. The new implementation 
simplifies use-cases which are used for out-of-process execution by allowing 
interpreter to be inherited or customized with an clang::ASTConsumer.

This change will enable completing the pretty printing work which is in 
llvm/llvm-project#84769

---

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


13 Files Affected:

- (modified) clang/include/clang/Frontend/MultiplexConsumer.h (+2-1) 
- (modified) clang/include/clang/Interpreter/Interpreter.h (+26-27) 
- (modified) clang/lib/Frontend/MultiplexConsumer.cpp (+7) 
- (modified) clang/lib/Interpreter/CMakeLists.txt (+1) 
- (modified) clang/lib/Interpreter/DeviceOffload.cpp (+5-5) 
- (modified) clang/lib/Interpreter/DeviceOffload.h (+7-7) 
- (modified) clang/lib/Interpreter/IncrementalExecutor.cpp (+1-1) 
- (modified) clang/lib/Interpreter/IncrementalParser.cpp (+8-245) 
- (modified) clang/lib/Interpreter/IncrementalParser.h (+8-37) 
- (modified) clang/lib/Interpreter/Interpreter.cpp (+218-428) 
- (added) clang/lib/Interpreter/InterpreterValuePrinter.cpp (+398) 
- (modified) clang/unittests/Interpreter/CodeCompletionTest.cpp (+1-1) 
- (modified) clang/unittests/Interpreter/InterpreterExtensionsTest.cpp (+23-41) 


``diff
diff --git a/clang/include/clang/Frontend/MultiplexConsumer.h 
b/clang/include/clang/Frontend/MultiplexConsumer.h
index 3a7670d7a51aa6..b190750bb29fb8 100644
--- a/clang/include/clang/Frontend/MultiplexConsumer.h
+++ b/clang/include/clang/Frontend/MultiplexConsumer.h
@@ -53,6 +53,7 @@ class MultiplexConsumer : public SemaConsumer {
 public:
   // Takes ownership of the pointers in C.
   MultiplexConsumer(std::vector> C);
+  MultiplexConsumer(std::unique_ptr C);
   ~MultiplexConsumer() override;
 
   // ASTConsumer
@@ -80,7 +81,7 @@ class MultiplexConsumer : public SemaConsumer {
   void InitializeSema(Sema &S) override;
   void ForgetSema() override;
 
-private:
+protected:
   std::vector> Consumers; // Owns these.
   std::unique_ptr MutationListener;
   std::unique_ptr DeserializationListener;
diff --git a/clang/include/clang/Interpreter/Interpreter.h 
b/clang/include/clang/Interpreter/Interpreter.h
index 1234608bb58647..cbb1cfd4ab02a8 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -14,11 +14,9 @@
 #ifndef LLVM_CLANG_INTERPRETER_INTERPRETER_H
 #define LLVM_CLANG_INTERPRETER_INTERPRETER_H
 
-#include "clang/AST/Decl.h"
 #include "clang/AST/GlobalDecl.h"
 #include "clang/Interpreter/PartialTranslationUnit.h"
 #include "clang/Interpreter/Value.h"
-#include "clang/Sema/Ownership.h"
 
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ExecutionEngine/JITSymbol.h"
@@ -38,6 +36,9 @@ class ThreadSafeContext;
 namespace clang {
 
 class CompilerInstance;
+class CodeGenerator;
+class CXXRecordDecl;
+class Decl;
 class IncrementalExecutor;
 class IncrementalParser;
 
@@ -77,26 +78,27 @@ class IncrementalCompilerBuilder {
   llvm::StringRef CudaSDKPath;
 };
 
-/// Generate glue code between the Interpreter's built-in runtime and user 
code.
-class RuntimeInterfaceBuilder {
-public:
-  virtual ~RuntimeInterfaceBuilder() = default;
-
-  using TransformExprFunction = ExprResult(RuntimeInterfaceBuilder *Builder,
-   Expr *, ArrayRef);
-  virtual TransformExprFunction *getPrintValueTransformer() = 0;
-};
+class IncrementalAction;
+class InProcessPrintingASTConsumer;
 
 /// Provides top-level interfaces for incremental compilation and execution.
 class Interpreter {
+  friend class Value;
+  friend InProcessPrintingASTConsumer;
+
   std::unique_ptr TSCtx;
+  /// Long-lived, incremental parsing action.
+  std::unique_ptr Act;
   std::unique_ptr IncrParser;
   std::unique_ptr IncrExecutor;
-  std::unique_ptr RuntimeIB;
 
   // An optional parser for CUDA offloading
   std::unique_ptr DeviceParser;
 
+  /// List containing every information about every incrementally parsed piece
+  /// of code.
+  std::list PTUs;
+
   unsigned InitPTUSize = 0;
 
   // This member holds the last result of the value printing. It's a class
@@ -104,15 +106,15 @@ class Interpreter {
   // printing happens, it's in an invalid state.
   Value LastValue;
 
-  // Add a call to an Expr to report its result. We query the function from
-  // Runt

[clang] [Frontend] Avoid repeated hash lookups (NFC) (PR #107728)

2024-09-08 Thread Kazu Hirata via cfe-commits

kazutakahirata wrote:

> LGTM with the note that converting these to SmallSetVector would probably be 
> more elegant...

Sure.

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


[clang] 81ec7bd - [Frontend] Avoid repeated hash lookups (NFC) (#107728)

2024-09-08 Thread via cfe-commits

Author: Kazu Hirata
Date: 2024-09-08T00:08:06-07:00
New Revision: 81ec7bd4183439ba824045b92f00fdebb10ff224

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

LOG: [Frontend] Avoid repeated hash lookups (NFC) (#107728)

Added: 


Modified: 
clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp

Removed: 




diff  --git a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp 
b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
index f618c536b5f3c6..31ec86e2e4f096 100644
--- a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
+++ b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
@@ -4340,17 +4340,13 @@ void 
RewriteModernObjC::SynthesizeBlockLiterals(SourceLocation FunLocStart,
   ValueDecl *VD = Exp->getDecl();
   BlockDeclRefs.push_back(Exp);
   if (!VD->hasAttr()) {
-if (!BlockByCopyDeclsPtrSet.count(VD)) {
-  BlockByCopyDeclsPtrSet.insert(VD);
+if (BlockByCopyDeclsPtrSet.insert(VD).second)
   BlockByCopyDecls.push_back(VD);
-}
 continue;
   }
 
-  if (!BlockByRefDeclsPtrSet.count(VD)) {
-BlockByRefDeclsPtrSet.insert(VD);
+  if (BlockByRefDeclsPtrSet.insert(VD).second)
 BlockByRefDecls.push_back(VD);
-  }
 
   // imported objects in the inner blocks not used in the outer
   // blocks must be copied/disposed in the outer block as well.
@@ -5161,18 +5157,14 @@ void 
RewriteModernObjC::CollectBlockDeclRefInfo(BlockExpr *Exp) {
 // Unique all "by copy" declarations.
 for (unsigned i = 0; i < BlockDeclRefs.size(); i++)
   if (!BlockDeclRefs[i]->getDecl()->hasAttr()) {
-if (!BlockByCopyDeclsPtrSet.count(BlockDeclRefs[i]->getDecl())) {
-  BlockByCopyDeclsPtrSet.insert(BlockDeclRefs[i]->getDecl());
+if (BlockByCopyDeclsPtrSet.insert(BlockDeclRefs[i]->getDecl()).second)
   BlockByCopyDecls.push_back(BlockDeclRefs[i]->getDecl());
-}
   }
 // Unique all "by ref" declarations.
 for (unsigned i = 0; i < BlockDeclRefs.size(); i++)
   if (BlockDeclRefs[i]->getDecl()->hasAttr()) {
-if (!BlockByRefDeclsPtrSet.count(BlockDeclRefs[i]->getDecl())) {
-  BlockByRefDeclsPtrSet.insert(BlockDeclRefs[i]->getDecl());
+if (BlockByRefDeclsPtrSet.insert(BlockDeclRefs[i]->getDecl()).second)
   BlockByRefDecls.push_back(BlockDeclRefs[i]->getDecl());
-}
   }
 // Find any imported blocks...they will need special attention.
 for (unsigned i = 0; i < BlockDeclRefs.size(); i++)



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


[clang] [Frontend] Avoid repeated hash lookups (NFC) (PR #107728)

2024-09-08 Thread Kazu Hirata via cfe-commits

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


[clang] [clang][bytecode] Fix a variable scope problem with continue/break jumps (PR #107738)

2024-09-08 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/107738

Cleaning up _all_ the scopes is a little too much. Only clean up until the 
point here we started the scope relevant for the break/continue statement.

>From 0de29f7ce0b2e2fd6e153de6c2bd4e7d44a74872 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sun, 8 Sep 2024 07:30:40 +0200
Subject: [PATCH] [clang][bytecode] Fix a variable scope problem with
 continue/break jumps

Cleaning up _all_ the scopes is a little too much. Only clean up until
the point here we started the scope relevant for the break/continue
statement.
---
 clang/lib/AST/ByteCode/Compiler.cpp| 18 +++
 clang/lib/AST/ByteCode/Compiler.h  |  2 ++
 clang/test/AST/ByteCode/new-delete.cpp | 32 +++---
 3 files changed, 35 insertions(+), 17 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 46f9c98d59befc..cd25ccdd930237 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -114,7 +114,8 @@ template  class LoopScope final : public 
LabelScope {
 
   LoopScope(Compiler *Ctx, LabelTy BreakLabel, LabelTy ContinueLabel)
   : LabelScope(Ctx), OldBreakLabel(Ctx->BreakLabel),
-OldContinueLabel(Ctx->ContinueLabel) {
+OldContinueLabel(Ctx->ContinueLabel),
+OldLabelVarScope(Ctx->LabelVarScope) {
 this->Ctx->BreakLabel = BreakLabel;
 this->Ctx->ContinueLabel = ContinueLabel;
   }
@@ -122,11 +123,13 @@ template  class LoopScope final : public 
LabelScope {
   ~LoopScope() {
 this->Ctx->BreakLabel = OldBreakLabel;
 this->Ctx->ContinueLabel = OldContinueLabel;
+this->Ctx->LabelVarScope = OldLabelVarScope;
   }
 
 private:
   OptLabelTy OldBreakLabel;
   OptLabelTy OldContinueLabel;
+  VariableScope *OldLabelVarScope;
 };
 
 // Sets the context for a switch scope, mapping labels.
@@ -140,7 +143,8 @@ template  class SwitchScope final : public 
LabelScope {
   OptLabelTy DefaultLabel)
   : LabelScope(Ctx), OldBreakLabel(Ctx->BreakLabel),
 OldDefaultLabel(this->Ctx->DefaultLabel),
-OldCaseLabels(std::move(this->Ctx->CaseLabels)) {
+OldCaseLabels(std::move(this->Ctx->CaseLabels)),
+OldLabelVarScope(Ctx->LabelVarScope) {
 this->Ctx->BreakLabel = BreakLabel;
 this->Ctx->DefaultLabel = DefaultLabel;
 this->Ctx->CaseLabels = std::move(CaseLabels);
@@ -150,12 +154,14 @@ template  class SwitchScope final : public 
LabelScope {
 this->Ctx->BreakLabel = OldBreakLabel;
 this->Ctx->DefaultLabel = OldDefaultLabel;
 this->Ctx->CaseLabels = std::move(OldCaseLabels);
+this->Ctx->LabelVarScope = OldLabelVarScope;
   }
 
 private:
   OptLabelTy OldBreakLabel;
   OptLabelTy OldDefaultLabel;
   CaseMap OldCaseLabels;
+  VariableScope *OldLabelVarScope;
 };
 
 template  class StmtExprScope final {
@@ -4734,7 +4740,9 @@ bool Compiler::visitBreakStmt(const BreakStmt 
*S) {
   if (!BreakLabel)
 return false;
 
-  this->emitCleanup();
+  for (VariableScope *C = VarScope; C != LabelVarScope;
+   C = C->getParent())
+C->emitDestruction();
   return this->jump(*BreakLabel);
 }
 
@@ -4743,7 +4751,9 @@ bool Compiler::visitContinueStmt(const 
ContinueStmt *S) {
   if (!ContinueLabel)
 return false;
 
-  this->emitCleanup();
+  for (VariableScope *C = VarScope; C != LabelVarScope;
+   C = C->getParent())
+C->emitDestruction();
   return this->jump(*ContinueLabel);
 }
 
diff --git a/clang/lib/AST/ByteCode/Compiler.h 
b/clang/lib/AST/ByteCode/Compiler.h
index 39c0736cb4e27e..ac4c08c4d0ffb6 100644
--- a/clang/lib/AST/ByteCode/Compiler.h
+++ b/clang/lib/AST/ByteCode/Compiler.h
@@ -409,6 +409,8 @@ class Compiler : public ConstStmtVisitor, 
bool>,
   /// Switch case mapping.
   CaseMap CaseLabels;
 
+  /// Scope to cleanup until when chumping to one of the labels.
+  VariableScope *LabelVarScope = nullptr;
   /// Point to break to.
   OptLabelTy BreakLabel;
   /// Point to continue to.
diff --git a/clang/test/AST/ByteCode/new-delete.cpp 
b/clang/test/AST/ByteCode/new-delete.cpp
index 902ab4aab10fb5..76858aa94bb37d 100644
--- a/clang/test/AST/ByteCode/new-delete.cpp
+++ b/clang/test/AST/ByteCode/new-delete.cpp
@@ -618,22 +618,28 @@ namespace OperatorNewDelete {
 
   constexpr bool mismatched(int alloc_kind, int dealloc_kind) {
 int *p;
-
-if (alloc_kind == 0)
-  p = new int; // both-note {{allocation performed here}}
-else if (alloc_kind == 1)
-  p = new int[1]; // both-note {{allocation performed here}}
-else if (alloc_kind == 2)
+switch (alloc_kind) {
+case 0:
+  p = new int; // both-note {{heap allocation performed here}}
+  break;
+case 1:
+  p = new int[1]; // both-note {{heap allocation performed here}}
+  break;
+case 2:
   p = std::allocator().allocate(1);
-
-
-if (dealloc_kind == 0)
+  break;
+}
+switch (dealloc_kind) {
+case 0:
 

[clang] [clang][bytecode] Fix a variable scope problem with continue/break jumps (PR #107738)

2024-09-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

Cleaning up _all_ the scopes is a little too much. Only clean up until the 
point here we started the scope relevant for the break/continue statement.

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


3 Files Affected:

- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+14-4) 
- (modified) clang/lib/AST/ByteCode/Compiler.h (+2) 
- (modified) clang/test/AST/ByteCode/new-delete.cpp (+19-13) 


``diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 46f9c98d59befc..cd25ccdd930237 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -114,7 +114,8 @@ template  class LoopScope final : public 
LabelScope {
 
   LoopScope(Compiler *Ctx, LabelTy BreakLabel, LabelTy ContinueLabel)
   : LabelScope(Ctx), OldBreakLabel(Ctx->BreakLabel),
-OldContinueLabel(Ctx->ContinueLabel) {
+OldContinueLabel(Ctx->ContinueLabel),
+OldLabelVarScope(Ctx->LabelVarScope) {
 this->Ctx->BreakLabel = BreakLabel;
 this->Ctx->ContinueLabel = ContinueLabel;
   }
@@ -122,11 +123,13 @@ template  class LoopScope final : public 
LabelScope {
   ~LoopScope() {
 this->Ctx->BreakLabel = OldBreakLabel;
 this->Ctx->ContinueLabel = OldContinueLabel;
+this->Ctx->LabelVarScope = OldLabelVarScope;
   }
 
 private:
   OptLabelTy OldBreakLabel;
   OptLabelTy OldContinueLabel;
+  VariableScope *OldLabelVarScope;
 };
 
 // Sets the context for a switch scope, mapping labels.
@@ -140,7 +143,8 @@ template  class SwitchScope final : public 
LabelScope {
   OptLabelTy DefaultLabel)
   : LabelScope(Ctx), OldBreakLabel(Ctx->BreakLabel),
 OldDefaultLabel(this->Ctx->DefaultLabel),
-OldCaseLabels(std::move(this->Ctx->CaseLabels)) {
+OldCaseLabels(std::move(this->Ctx->CaseLabels)),
+OldLabelVarScope(Ctx->LabelVarScope) {
 this->Ctx->BreakLabel = BreakLabel;
 this->Ctx->DefaultLabel = DefaultLabel;
 this->Ctx->CaseLabels = std::move(CaseLabels);
@@ -150,12 +154,14 @@ template  class SwitchScope final : public 
LabelScope {
 this->Ctx->BreakLabel = OldBreakLabel;
 this->Ctx->DefaultLabel = OldDefaultLabel;
 this->Ctx->CaseLabels = std::move(OldCaseLabels);
+this->Ctx->LabelVarScope = OldLabelVarScope;
   }
 
 private:
   OptLabelTy OldBreakLabel;
   OptLabelTy OldDefaultLabel;
   CaseMap OldCaseLabels;
+  VariableScope *OldLabelVarScope;
 };
 
 template  class StmtExprScope final {
@@ -4734,7 +4740,9 @@ bool Compiler::visitBreakStmt(const BreakStmt 
*S) {
   if (!BreakLabel)
 return false;
 
-  this->emitCleanup();
+  for (VariableScope *C = VarScope; C != LabelVarScope;
+   C = C->getParent())
+C->emitDestruction();
   return this->jump(*BreakLabel);
 }
 
@@ -4743,7 +4751,9 @@ bool Compiler::visitContinueStmt(const 
ContinueStmt *S) {
   if (!ContinueLabel)
 return false;
 
-  this->emitCleanup();
+  for (VariableScope *C = VarScope; C != LabelVarScope;
+   C = C->getParent())
+C->emitDestruction();
   return this->jump(*ContinueLabel);
 }
 
diff --git a/clang/lib/AST/ByteCode/Compiler.h 
b/clang/lib/AST/ByteCode/Compiler.h
index 39c0736cb4e27e..ac4c08c4d0ffb6 100644
--- a/clang/lib/AST/ByteCode/Compiler.h
+++ b/clang/lib/AST/ByteCode/Compiler.h
@@ -409,6 +409,8 @@ class Compiler : public ConstStmtVisitor, 
bool>,
   /// Switch case mapping.
   CaseMap CaseLabels;
 
+  /// Scope to cleanup until when chumping to one of the labels.
+  VariableScope *LabelVarScope = nullptr;
   /// Point to break to.
   OptLabelTy BreakLabel;
   /// Point to continue to.
diff --git a/clang/test/AST/ByteCode/new-delete.cpp 
b/clang/test/AST/ByteCode/new-delete.cpp
index 902ab4aab10fb5..76858aa94bb37d 100644
--- a/clang/test/AST/ByteCode/new-delete.cpp
+++ b/clang/test/AST/ByteCode/new-delete.cpp
@@ -618,22 +618,28 @@ namespace OperatorNewDelete {
 
   constexpr bool mismatched(int alloc_kind, int dealloc_kind) {
 int *p;
-
-if (alloc_kind == 0)
-  p = new int; // both-note {{allocation performed here}}
-else if (alloc_kind == 1)
-  p = new int[1]; // both-note {{allocation performed here}}
-else if (alloc_kind == 2)
+switch (alloc_kind) {
+case 0:
+  p = new int; // both-note {{heap allocation performed here}}
+  break;
+case 1:
+  p = new int[1]; // both-note {{heap allocation performed here}}
+  break;
+case 2:
   p = std::allocator().allocate(1);
-
-
-if (dealloc_kind == 0)
+  break;
+}
+switch (dealloc_kind) {
+case 0:
   delete p; // both-note {{'delete' used to delete pointer to object 
allocated with 'std::allocator<...>::allocate'}}
-else if (dealloc_kind == 1)
+  break;
+case 1:
   delete[] p; // both-note {{'delete' used to delete pointer to object 
allocated with 'std::allocator<...>::allocate'}}
-else if (dealloc_kind == 2)
- 

[clang] [clang-format] Fix a regression on BAS_AlwaysBreak (PR #107506)

2024-09-08 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/107506

>From bd7da6ec9afabd829010db4c33d088590ab68b5a Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Thu, 5 Sep 2024 19:44:46 -0700
Subject: [PATCH 1/3] [clang-format] Fix a regression on BAS_AlwaysBreak

Fixes #107401.
---
 clang/lib/Format/ContinuationIndenter.cpp | 2 +-
 clang/unittests/Format/FormatTestJS.cpp   | 8 
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 5843571718b3a2..f65c1640a8765a 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -861,7 +861,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
&State, bool DryRun,
   //  or
   //  cal(
   //   new SomethingElseee());
-  !IsSimpleFunction(Current)) {
+  Current.isNot(tok::comment) && !IsSimpleFunction(Current)) {
 CurrentState.NoLineBreak = true;
   }
 
diff --git a/clang/unittests/Format/FormatTestJS.cpp 
b/clang/unittests/Format/FormatTestJS.cpp
index 4b29ba720f6823..a0b663170c7b33 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -2850,5 +2850,13 @@ TEST_F(FormatTestJS, DontBreakFieldsAsGoToLabels) {
"};");
 }
 
+TEST_F(FormatTestJS, BreakAfterOpenBracket) {
+  auto Style = getGoogleStyle(FormatStyle::LK_JavaScript);
+  EXPECT_EQ(Style.AlignAfterOpenBracket, FormatStyle::BAS_AlwaysBreak);
+  verifyFormat("ctrl.onCopy(/** @type {!WizEvent}*/ (\n"
+   "{event, targetElement: {el: () => selectedElement}}));",
+   Style);
+}
+
 } // namespace format
 } // end namespace clang

>From 920e26dcd9c5d7f78a4f8b572451ecae73dd9201 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sat, 7 Sep 2024 16:40:04 -0700
Subject: [PATCH 2/3] Rename `InSimpleFunction` to `StartsSimpleOneArgList` and
 skip to the next token if the argument is a comment.

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

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index f65c1640a8765a..58e6b78ce578e4 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -815,7 +815,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
&State, bool DryRun,
 return Tok.is(tok::l_paren) && Tok.ParameterCount > 0 && Tok.Previous &&
Tok.Previous->is(tok::identifier);
   };
-  const auto IsInTemplateString = [this](const FormatToken &Tok) {
+  auto IsInTemplateString = [this](const FormatToken &Tok) {
 if (!Style.isJavaScript())
   return false;
 for (const auto *Prev = &Tok; Prev; Prev = Prev->Previous) {
@@ -827,7 +827,10 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
&State, bool DryRun,
 return false;
   };
   // Identifies simple (no expression) one-argument function calls.
-  const auto IsSimpleFunction = [&](const FormatToken &Tok) {
+  auto StartsSimpleOneArgList = [&](const FormatToken &TokAfterLParen) {
+assert(TokAfterLParen.isNot(tok::comment) || TokAfterLParen.Next);
+const auto &Tok =
+TokAfterLParen.is(tok::comment) ? *TokAfterLParen.Next : 
TokAfterLParen;
 if (!Tok.FakeLParens.empty() && Tok.FakeLParens.back() > prec::Unknown)
   return false;
 // Nested calls that involve `new` expressions also look like simple
@@ -861,7 +864,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
&State, bool DryRun,
   //  or
   //  cal(
   //   new SomethingElseee());
-  Current.isNot(tok::comment) && !IsSimpleFunction(Current)) {
+  !StartsSimpleOneArgList(Current)) {
 CurrentState.NoLineBreak = true;
   }
 

>From 4ff558c57fbd931cc65053c81def60501d3fe4af Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sun, 8 Sep 2024 00:54:41 -0700
Subject: [PATCH 3/3] Also fix #107574.

---
 clang/lib/Format/ContinuationIndenter.cpp | 5 +
 clang/unittests/Format/FormatTestJS.cpp   | 9 +
 2 files changed, 14 insertions(+)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 58e6b78ce578e4..f29f8796ea9290 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -839,6 +839,11 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
&State, bool DryRun,
 // - foo(::new Bar())
 if (Tok.is(tok::kw_new) || Tok.startsSequence(tok::coloncolon, 
tok::kw_new))
   return true;
+if (Tok.is(TT_UnaryOperator) ||
+(Style.isJavaScript() &&
+ Tok.isOneOf(tok::ellipsis, Keywords.kw_await))) {
+  return true;
+}
 const auto *Previous = Tok.Previous;
 if (!Previous || (!Previous->isOneOf(TT_FunctionDec

[clang] [clang-format] Fix regressions in BAS_AlwaysBreak (PR #107506)

2024-09-08 Thread Owen Pan via cfe-commits

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


[clang] [clang-format] Fix regressions in BAS_AlwaysBreak (PR #107506)

2024-09-08 Thread Owen Pan via cfe-commits

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


[clang] [FrontEnd] Use SetVector for BlockByCopyDecls (NFC) (PR #107743)

2024-09-08 Thread Kazu Hirata via cfe-commits

https://github.com/kazutakahirata created 
https://github.com/llvm/llvm-project/pull/107743

We could also use range-based for loops at several places, but I'm
leaving that to a subsequent patch.


>From cb2cc5934488f75664eee61b26a9a3ce3f27010c Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Sun, 8 Sep 2024 00:48:25 -0700
Subject: [PATCH] [FrontEnd] Use SetVector for BlockByCopyDecls (NFC)

We could also use range-based for loops at several places, but I'm
leaving that to a subsequent patch.
---
 .../Frontend/Rewrite/RewriteModernObjC.cpp| 88 ++-
 1 file changed, 45 insertions(+), 43 deletions(-)

diff --git a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp 
b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
index 31ec86e2e4f096..c6539658669ef3 100644
--- a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
+++ b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
@@ -138,10 +138,8 @@ namespace {
 SmallVector BlockDeclRefs;
 
 // Block related declarations.
-SmallVector BlockByCopyDecls;
-llvm::SmallPtrSet BlockByCopyDeclsPtrSet;
-SmallVector BlockByRefDecls;
-llvm::SmallPtrSet BlockByRefDeclsPtrSet;
+llvm::SmallSetVector BlockByCopyDecls;
+llvm::SmallSetVector BlockByRefDecls;
 llvm::DenseMap BlockByRefDeclNo;
 llvm::SmallPtrSet ImportedBlockDecls;
 llvm::SmallPtrSet ImportedLocalExternalDecls;
@@ -4082,8 +4080,10 @@ std::string 
RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i,
 
   // Create local declarations to avoid rewriting all closure decl ref exprs.
   // First, emit a declaration for all "by ref" decls.
-  for (SmallVectorImpl::iterator I = BlockByRefDecls.begin(),
-   E = BlockByRefDecls.end(); I != E; ++I) {
+  for (llvm::SmallSetVector::iterator
+   I = BlockByRefDecls.begin(),
+   E = BlockByRefDecls.end();
+   I != E; ++I) {
 S += "  ";
 std::string Name = (*I)->getNameAsString();
 std::string TypeString;
@@ -4093,8 +4093,10 @@ std::string 
RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i,
 S += Name + " = __cself->" + (*I)->getNameAsString() + "; // bound by 
ref\n";
   }
   // Next, emit a declaration for all "by copy" declarations.
-  for (SmallVectorImpl::iterator I = BlockByCopyDecls.begin(),
-   E = BlockByCopyDecls.end(); I != E; ++I) {
+  for (llvm::SmallSetVector::iterator
+   I = BlockByCopyDecls.begin(),
+   E = BlockByCopyDecls.end();
+   I != E; ++I) {
 S += "  ";
 // Handle nested closure invocation. For example:
 //
@@ -4146,7 +4148,7 @@ std::string RewriteModernObjC::SynthesizeBlockHelperFuncs(
 S += VD->getNameAsString();
 S += ", (void*)src->";
 S += VD->getNameAsString();
-if (BlockByRefDeclsPtrSet.count(VD))
+if (BlockByRefDecls.count(VD))
   S += ", " + utostr(BLOCK_FIELD_IS_BYREF) + "/*BLOCK_FIELD_IS_BYREF*/);";
 else if (VD->getType()->isBlockPointerType())
   S += ", " + utostr(BLOCK_FIELD_IS_BLOCK) + "/*BLOCK_FIELD_IS_BLOCK*/);";
@@ -4163,7 +4165,7 @@ std::string RewriteModernObjC::SynthesizeBlockHelperFuncs(
   for (ValueDecl *VD : ImportedBlockDecls) {
 S += "_Block_object_dispose((void*)src->";
 S += VD->getNameAsString();
-if (BlockByRefDeclsPtrSet.count(VD))
+if (BlockByRefDecls.count(VD))
   S += ", " + utostr(BLOCK_FIELD_IS_BYREF) + "/*BLOCK_FIELD_IS_BYREF*/);";
 else if (VD->getType()->isBlockPointerType())
   S += ", " + utostr(BLOCK_FIELD_IS_BLOCK) + "/*BLOCK_FIELD_IS_BLOCK*/);";
@@ -4190,8 +4192,10 @@ std::string 
RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE,
 
   if (BlockDeclRefs.size()) {
 // Output all "by copy" declarations.
-for (SmallVectorImpl::iterator I = BlockByCopyDecls.begin(),
- E = BlockByCopyDecls.end(); I != E; ++I) {
+for (llvm::SmallSetVector::iterator
+ I = BlockByCopyDecls.begin(),
+ E = BlockByCopyDecls.end();
+ I != E; ++I) {
   S += "  ";
   std::string FieldName = (*I)->getNameAsString();
   std::string ArgName = "_" + FieldName;
@@ -4219,8 +4223,10 @@ std::string 
RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE,
   S += FieldName + ";\n";
 }
 // Output all "by ref" declarations.
-for (SmallVectorImpl::iterator I = BlockByRefDecls.begin(),
- E = BlockByRefDecls.end(); I != E; ++I) {
+for (llvm::SmallSetVector::iterator
+ I = BlockByRefDecls.begin(),
+ E = BlockByRefDecls.end();
+ I != E; ++I) {
   S += "  ";
   std::string FieldName = (*I)->getNameAsString();
   std::string ArgName = "_" + FieldName;
@@ -4238,8 +4244,10 @@ std::string 
RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE,
 Constructor += ", int flags=0)";
 // Initialize all "by copy" arguments.
 bool firsTime = true;
-for (SmallVectorImpl::iterator I = BlockByCopyDecls.begin(),
- E = BlockByCopyDecls.end(); I != E; ++I) {
+for (llvm::SmallSetVector::iterator
+ I

[clang] [FrontEnd] Use SetVector for BlockByCopyDecls (NFC) (PR #107743)

2024-09-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes

We could also use range-based for loops at several places, but I'm
leaving that to a subsequent patch.


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


1 Files Affected:

- (modified) clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp (+45-43) 


``diff
diff --git a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp 
b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
index 31ec86e2e4f096..c6539658669ef3 100644
--- a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
+++ b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
@@ -138,10 +138,8 @@ namespace {
 SmallVector BlockDeclRefs;
 
 // Block related declarations.
-SmallVector BlockByCopyDecls;
-llvm::SmallPtrSet BlockByCopyDeclsPtrSet;
-SmallVector BlockByRefDecls;
-llvm::SmallPtrSet BlockByRefDeclsPtrSet;
+llvm::SmallSetVector BlockByCopyDecls;
+llvm::SmallSetVector BlockByRefDecls;
 llvm::DenseMap BlockByRefDeclNo;
 llvm::SmallPtrSet ImportedBlockDecls;
 llvm::SmallPtrSet ImportedLocalExternalDecls;
@@ -4082,8 +4080,10 @@ std::string 
RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i,
 
   // Create local declarations to avoid rewriting all closure decl ref exprs.
   // First, emit a declaration for all "by ref" decls.
-  for (SmallVectorImpl::iterator I = BlockByRefDecls.begin(),
-   E = BlockByRefDecls.end(); I != E; ++I) {
+  for (llvm::SmallSetVector::iterator
+   I = BlockByRefDecls.begin(),
+   E = BlockByRefDecls.end();
+   I != E; ++I) {
 S += "  ";
 std::string Name = (*I)->getNameAsString();
 std::string TypeString;
@@ -4093,8 +4093,10 @@ std::string 
RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i,
 S += Name + " = __cself->" + (*I)->getNameAsString() + "; // bound by 
ref\n";
   }
   // Next, emit a declaration for all "by copy" declarations.
-  for (SmallVectorImpl::iterator I = BlockByCopyDecls.begin(),
-   E = BlockByCopyDecls.end(); I != E; ++I) {
+  for (llvm::SmallSetVector::iterator
+   I = BlockByCopyDecls.begin(),
+   E = BlockByCopyDecls.end();
+   I != E; ++I) {
 S += "  ";
 // Handle nested closure invocation. For example:
 //
@@ -4146,7 +4148,7 @@ std::string RewriteModernObjC::SynthesizeBlockHelperFuncs(
 S += VD->getNameAsString();
 S += ", (void*)src->";
 S += VD->getNameAsString();
-if (BlockByRefDeclsPtrSet.count(VD))
+if (BlockByRefDecls.count(VD))
   S += ", " + utostr(BLOCK_FIELD_IS_BYREF) + "/*BLOCK_FIELD_IS_BYREF*/);";
 else if (VD->getType()->isBlockPointerType())
   S += ", " + utostr(BLOCK_FIELD_IS_BLOCK) + "/*BLOCK_FIELD_IS_BLOCK*/);";
@@ -4163,7 +4165,7 @@ std::string RewriteModernObjC::SynthesizeBlockHelperFuncs(
   for (ValueDecl *VD : ImportedBlockDecls) {
 S += "_Block_object_dispose((void*)src->";
 S += VD->getNameAsString();
-if (BlockByRefDeclsPtrSet.count(VD))
+if (BlockByRefDecls.count(VD))
   S += ", " + utostr(BLOCK_FIELD_IS_BYREF) + "/*BLOCK_FIELD_IS_BYREF*/);";
 else if (VD->getType()->isBlockPointerType())
   S += ", " + utostr(BLOCK_FIELD_IS_BLOCK) + "/*BLOCK_FIELD_IS_BLOCK*/);";
@@ -4190,8 +4192,10 @@ std::string 
RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE,
 
   if (BlockDeclRefs.size()) {
 // Output all "by copy" declarations.
-for (SmallVectorImpl::iterator I = BlockByCopyDecls.begin(),
- E = BlockByCopyDecls.end(); I != E; ++I) {
+for (llvm::SmallSetVector::iterator
+ I = BlockByCopyDecls.begin(),
+ E = BlockByCopyDecls.end();
+ I != E; ++I) {
   S += "  ";
   std::string FieldName = (*I)->getNameAsString();
   std::string ArgName = "_" + FieldName;
@@ -4219,8 +4223,10 @@ std::string 
RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE,
   S += FieldName + ";\n";
 }
 // Output all "by ref" declarations.
-for (SmallVectorImpl::iterator I = BlockByRefDecls.begin(),
- E = BlockByRefDecls.end(); I != E; ++I) {
+for (llvm::SmallSetVector::iterator
+ I = BlockByRefDecls.begin(),
+ E = BlockByRefDecls.end();
+ I != E; ++I) {
   S += "  ";
   std::string FieldName = (*I)->getNameAsString();
   std::string ArgName = "_" + FieldName;
@@ -4238,8 +4244,10 @@ std::string 
RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE,
 Constructor += ", int flags=0)";
 // Initialize all "by copy" arguments.
 bool firsTime = true;
-for (SmallVectorImpl::iterator I = BlockByCopyDecls.begin(),
- E = BlockByCopyDecls.end(); I != E; ++I) {
+for (llvm::SmallSetVector::iterator
+ I = BlockByCopyDecls.begin(),
+ E = BlockByCopyDecls.end();
+ I != E; ++I) {
   std::string Name = (*I)->getNameAsString();
 if (firsTime) {
   Constructor += " : ";
@@ -4253,8 +4261,10 @@ std::string 
Rewrite

[clang] 13546c2 - [CodeGen] Avoid repeated hash lookups (NFC) (#107736)

2024-09-08 Thread via cfe-commits

Author: Kazu Hirata
Date: 2024-09-08T01:26:24-07:00
New Revision: 13546c284fc31fa5543b07941e864b9b0aaa8638

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

LOG: [CodeGen] Avoid repeated hash lookups (NFC) (#107736)

Added: 


Modified: 
clang/lib/CodeGen/CodeGenFunction.h

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index 368fc112187ffc..9b93e9673ec5f8 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -1143,17 +1143,11 @@ class CodeGenFunction : public CodeGenTypeCache {
 /// Copy all the entries in the source map over the corresponding
 /// entries in the destination, which must exist.
 static void copyInto(const DeclMapTy &Src, DeclMapTy &Dest) {
-  for (auto &Pair : Src) {
-if (!Pair.second.isValid()) {
-  Dest.erase(Pair.first);
-  continue;
-}
-
-auto I = Dest.find(Pair.first);
-if (I != Dest.end())
-  I->second = Pair.second;
+  for (auto &[Decl, Addr] : Src) {
+if (!Addr.isValid())
+  Dest.erase(Decl);
 else
-  Dest.insert(Pair);
+  Dest.insert_or_assign(Decl, Addr);
   }
 }
   };



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


[clang] [CodeGen] Avoid repeated hash lookups (NFC) (PR #107736)

2024-09-08 Thread Kazu Hirata via cfe-commits

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


[clang] [CodeGen] Avoid repeated hash lookups (NFC) (PR #107736)

2024-09-08 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`openmp-offload-amdgpu-runtime` running on `omp-vega20-0` while building 
`clang` at step 6 "test-openmp".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/30/builds/5709


Here is the relevant piece of the build log for the reference

```
Step 6 (test-openmp) failure: test (failure)
 TEST 'libomp :: tasking/issue-94260-2.c' FAILED 

Exit Code: -11

Command Output (stdout):
--
# RUN: at line 1
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/clang 
-fopenmp   -I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/openmp/runtime/test 
-L 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
  -fno-omit-frame-pointer -I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/openmp/runtime/test/ompt
 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c
 -o 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
 -lm -latomic && 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
# executed command: 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/clang 
-fopenmp -I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/openmp/runtime/test 
-L 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -fno-omit-frame-pointer -I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/openmp/runtime/test/ompt
 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c
 -o 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
 -lm -latomic
# note: command had no output on stdout or stderr
# executed command: 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
# note: command had no output on stdout or stderr
# error: command failed with exit status: -11

--




```



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


[clang] [lld] [llvm] [clang][MIPS] Add support for mipsel-windows-* targets (PR #107744)

2024-09-08 Thread via cfe-commits
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau 
Message-ID: 
In-Reply-To:


https://github.com/hpoussin created 
https://github.com/llvm/llvm-project/pull/107744

- Add support for Windows MIPS relocations types
- Support reading MIPS COFF files in objdump
- Support generating MIPS COFF files in yaml2obj
- Support generating MIPS COFF files in llvm-lib
- Support generating MIPS COFF files in llvm-dlltool
- Support generating MIPS COFF files in clang

Compiler and library creation have been cross-tested with Microsoft 
counterparts.
Linker part is not yet ready (although available in my 
[mips-pe](https://github.com/hpoussin/llvm-project/tree/mips-pe) branch).

By using Microsoft linker (or my work-in-process work on lld), I get working 
executables.
![clang-20-mips](https://github.com/user-attachments/assets/6914fc93-8c07-41de-8bdc-acd64d31b376)


>From 193f3d3d60c2c9742db50dcb47d689b7968b08d9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= 
Date: Sun, 22 Oct 2023 07:19:08 +0200
Subject: [PATCH 01/13] [Triple] Make mipsel-*-windows-* use COFF files by
 default

Windows NT/MIPS and Windows CE/MIPS always used COFF format.
---
 llvm/lib/TargetParser/Triple.cpp   | 6 +-
 llvm/unittests/TargetParser/TripleTest.cpp | 3 +++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 55911a7d71ac70..18e2d4fa465f8f 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -905,7 +905,6 @@ static Triple::ObjectFormatType getDefaultFormat(const 
Triple &T) {
   case Triple::mips64:
   case Triple::mips64el:
   case Triple::mips:
-  case Triple::mipsel:
   case Triple::msp430:
   case Triple::nvptx64:
   case Triple::nvptx:
@@ -930,6 +929,11 @@ static Triple::ObjectFormatType getDefaultFormat(const 
Triple &T) {
   case Triple::xtensa:
 return Triple::ELF;
 
+  case Triple::mipsel:
+if (T.isOSWindows())
+  return Triple::COFF;
+return Triple::ELF;
+
   case Triple::ppc64:
   case Triple::ppc:
 if (T.isOSAIX())
diff --git a/llvm/unittests/TargetParser/TripleTest.cpp 
b/llvm/unittests/TargetParser/TripleTest.cpp
index 0aecfc64da2080..1beb52088941e9 100644
--- a/llvm/unittests/TargetParser/TripleTest.cpp
+++ b/llvm/unittests/TargetParser/TripleTest.cpp
@@ -2302,6 +2302,9 @@ TEST(TripleTest, NormalizeWindows) {
 Triple::normalize("i686-pc-windows-elf-elf"));
 
   EXPECT_TRUE(Triple("x86_64-pc-win32").isWindowsMSVCEnvironment());
+
+  
EXPECT_TRUE(Triple(Triple::normalize("mipsel-windows-msvccoff")).isOSBinFormatCOFF());
+  
EXPECT_TRUE(Triple(Triple::normalize("mipsel-windows-msvc")).isOSBinFormatCOFF());
 }
 
 TEST(TripleTest, NormalizeAndroid) {

>From 83d84c1190f32539392e99e0214350b10d6fda94 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= 
Date: Sun, 22 Oct 2023 07:30:37 +0200
Subject: [PATCH 02/13] [COFF] Add MIPS relocation types

Add the MIPS COFF relocation types. They will be needed to add support for
MIPS Windows object file.
---
 llvm/include/llvm/BinaryFormat/COFF.h | 18 ++
 llvm/lib/Object/COFFObjectFile.cpp| 21 +
 2 files changed, 39 insertions(+)

diff --git a/llvm/include/llvm/BinaryFormat/COFF.h 
b/llvm/include/llvm/BinaryFormat/COFF.h
index 3fc543f73c49db..bbc5264d17872a 100644
--- a/llvm/include/llvm/BinaryFormat/COFF.h
+++ b/llvm/include/llvm/BinaryFormat/COFF.h
@@ -417,6 +417,24 @@ enum RelocationTypesARM64 : unsigned {
   IMAGE_REL_ARM64_REL32 = 0x0011,
 };
 
+enum RelocationTypesMips : unsigned {
+  IMAGE_REL_MIPS_ABSOLUTE = 0x,
+  IMAGE_REL_MIPS_REFHALF = 0x0001,
+  IMAGE_REL_MIPS_REFWORD = 0x0002,
+  IMAGE_REL_MIPS_JMPADDR = 0x0003,
+  IMAGE_REL_MIPS_REFHI = 0x0004,
+  IMAGE_REL_MIPS_REFLO = 0x0005,
+  IMAGE_REL_MIPS_GPREL = 0x0006,
+  IMAGE_REL_MIPS_LITERAL = 0x0007,
+  IMAGE_REL_MIPS_SECTION = 0x000A,
+  IMAGE_REL_MIPS_SECREL = 0x000B,
+  IMAGE_REL_MIPS_SECRELLO = 0x000C,
+  IMAGE_REL_MIPS_SECRELHI = 0x000D,
+  IMAGE_REL_MIPS_JMPADDR16 = 0x0010,
+  IMAGE_REL_MIPS_REFWORDNB = 0x0022,
+  IMAGE_REL_MIPS_PAIR = 0x0025,
+};
+
 enum DynamicRelocationType : unsigned {
   IMAGE_DYNAMIC_RELOCATION_GUARD_RF_PROLOGUE = 1,
   IMAGE_DYNAMIC_RELOCATION_GUARD_RF_EPILOGUE = 2,
diff --git a/llvm/lib/Object/COFFObjectFile.cpp 
b/llvm/lib/Object/COFFObjectFile.cpp
index 5fdf3baf8c02cc..5077c38c2de766 100644
--- a/llvm/lib/Object/COFFObjectFile.cpp
+++ b/llvm/lib/Object/COFFObjectFile.cpp
@@ -1465,6 +1465,27 @@ StringRef COFFObjectFile::getRelocationTypeName(uint16_t 
Type) const {
   return "Unknown";
 }
 break;
+  case COFF::IMAGE_FILE_MACHINE_R4000:
+

[clang] [lld] [llvm] [clang][MIPS] Add support for mipsel-windows-* targets (PR #107744)

2024-09-08 Thread via cfe-commits
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau 
Message-ID:
In-Reply-To: 


github-actions[bot] wrote:



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

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

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

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

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

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

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

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


[clang] [FrontEnd] Use SetVector (NFC) (PR #107743)

2024-09-08 Thread Kazu Hirata via cfe-commits

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


[clang] [compiler-rt] [UBSan] Diagnose assumption violation (PR #104741)

2024-09-08 Thread Yingwei Zheng via cfe-commits

dtcxzyw wrote:

Ping.

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


[clang] [FrontEnd] Use SetVector (NFC) (PR #107743)

2024-09-08 Thread Nikita Popov via cfe-commits


@@ -5157,14 +5163,12 @@ void 
RewriteModernObjC::CollectBlockDeclRefInfo(BlockExpr *Exp) {
 // Unique all "by copy" declarations.
 for (unsigned i = 0; i < BlockDeclRefs.size(); i++)
   if (!BlockDeclRefs[i]->getDecl()->hasAttr()) {

nikic wrote:

Can drop the braces now.

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


[clang] [FrontEnd] Use SetVector (NFC) (PR #107743)

2024-09-08 Thread Nikita Popov via cfe-commits

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


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


[clang] [FrontEnd] Use SetVector (NFC) (PR #107743)

2024-09-08 Thread Nikita Popov via cfe-commits


@@ -4082,8 +4080,10 @@ std::string 
RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i,
 
   // Create local declarations to avoid rewriting all closure decl ref exprs.
   // First, emit a declaration for all "by ref" decls.
-  for (SmallVectorImpl::iterator I = BlockByRefDecls.begin(),
-   E = BlockByRefDecls.end(); I != E; ++I) {
+  for (llvm::SmallSetVector::iterator

nikic wrote:

Use auto for iterators please.

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


[clang] [lld] [llvm] [clang][MIPS] Add support for mipsel-windows-* targets (PR #107744)

2024-09-08 Thread via cfe-commits
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau 
Message-ID:
In-Reply-To: 


https://github.com/hpoussin updated 
https://github.com/llvm/llvm-project/pull/107744

>From 193f3d3d60c2c9742db50dcb47d689b7968b08d9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= 
Date: Sun, 22 Oct 2023 07:19:08 +0200
Subject: [PATCH 01/13] [Triple] Make mipsel-*-windows-* use COFF files by
 default

Windows NT/MIPS and Windows CE/MIPS always used COFF format.
---
 llvm/lib/TargetParser/Triple.cpp   | 6 +-
 llvm/unittests/TargetParser/TripleTest.cpp | 3 +++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 55911a7d71ac70..18e2d4fa465f8f 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -905,7 +905,6 @@ static Triple::ObjectFormatType getDefaultFormat(const 
Triple &T) {
   case Triple::mips64:
   case Triple::mips64el:
   case Triple::mips:
-  case Triple::mipsel:
   case Triple::msp430:
   case Triple::nvptx64:
   case Triple::nvptx:
@@ -930,6 +929,11 @@ static Triple::ObjectFormatType getDefaultFormat(const 
Triple &T) {
   case Triple::xtensa:
 return Triple::ELF;
 
+  case Triple::mipsel:
+if (T.isOSWindows())
+  return Triple::COFF;
+return Triple::ELF;
+
   case Triple::ppc64:
   case Triple::ppc:
 if (T.isOSAIX())
diff --git a/llvm/unittests/TargetParser/TripleTest.cpp 
b/llvm/unittests/TargetParser/TripleTest.cpp
index 0aecfc64da2080..1beb52088941e9 100644
--- a/llvm/unittests/TargetParser/TripleTest.cpp
+++ b/llvm/unittests/TargetParser/TripleTest.cpp
@@ -2302,6 +2302,9 @@ TEST(TripleTest, NormalizeWindows) {
 Triple::normalize("i686-pc-windows-elf-elf"));
 
   EXPECT_TRUE(Triple("x86_64-pc-win32").isWindowsMSVCEnvironment());
+
+  
EXPECT_TRUE(Triple(Triple::normalize("mipsel-windows-msvccoff")).isOSBinFormatCOFF());
+  
EXPECT_TRUE(Triple(Triple::normalize("mipsel-windows-msvc")).isOSBinFormatCOFF());
 }
 
 TEST(TripleTest, NormalizeAndroid) {

>From f99b2ea9f3f744500acaab0c05a346250e0e7751 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= 
Date: Sun, 22 Oct 2023 07:30:37 +0200
Subject: [PATCH 02/13] [COFF] Add MIPS relocation types

Add the MIPS COFF relocation types. They will be needed to add support for
MIPS Windows object file.
---
 llvm/include/llvm/BinaryFormat/COFF.h | 18 ++
 llvm/lib/Object/COFFObjectFile.cpp| 21 +
 2 files changed, 39 insertions(+)

diff --git a/llvm/include/llvm/BinaryFormat/COFF.h 
b/llvm/include/llvm/BinaryFormat/COFF.h
index 3fc543f73c49db..bbc5264d17872a 100644
--- a/llvm/include/llvm/BinaryFormat/COFF.h
+++ b/llvm/include/llvm/BinaryFormat/COFF.h
@@ -417,6 +417,24 @@ enum RelocationTypesARM64 : unsigned {
   IMAGE_REL_ARM64_REL32 = 0x0011,
 };
 
+enum RelocationTypesMips : unsigned {
+  IMAGE_REL_MIPS_ABSOLUTE = 0x,
+  IMAGE_REL_MIPS_REFHALF = 0x0001,
+  IMAGE_REL_MIPS_REFWORD = 0x0002,
+  IMAGE_REL_MIPS_JMPADDR = 0x0003,
+  IMAGE_REL_MIPS_REFHI = 0x0004,
+  IMAGE_REL_MIPS_REFLO = 0x0005,
+  IMAGE_REL_MIPS_GPREL = 0x0006,
+  IMAGE_REL_MIPS_LITERAL = 0x0007,
+  IMAGE_REL_MIPS_SECTION = 0x000A,
+  IMAGE_REL_MIPS_SECREL = 0x000B,
+  IMAGE_REL_MIPS_SECRELLO = 0x000C,
+  IMAGE_REL_MIPS_SECRELHI = 0x000D,
+  IMAGE_REL_MIPS_JMPADDR16 = 0x0010,
+  IMAGE_REL_MIPS_REFWORDNB = 0x0022,
+  IMAGE_REL_MIPS_PAIR = 0x0025,
+};
+
 enum DynamicRelocationType : unsigned {
   IMAGE_DYNAMIC_RELOCATION_GUARD_RF_PROLOGUE = 1,
   IMAGE_DYNAMIC_RELOCATION_GUARD_RF_EPILOGUE = 2,
diff --git a/llvm/lib/Object/COFFObjectFile.cpp 
b/llvm/lib/Object/COFFObjectFile.cpp
index 5fdf3baf8c02cc..f55138bb23907a 100644
--- a/llvm/lib/Object/COFFObjectFile.cpp
+++ b/llvm/lib/Object/COFFObjectFile.cpp
@@ -1465,6 +1465,27 @@ StringRef COFFObjectFile::getRelocationTypeName(uint16_t 
Type) const {
   return "Unknown";
 }
 break;
+  case Triple::mipsel:
+switch (Type) {
+LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_ABSOLUTE);
+LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_REFHALF);
+LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_REFWORD);
+LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_JMPADDR);
+LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_REFHI);
+LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_REFLO);
+LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_GPREL);
+LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_LITERAL);
+LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_SECTION);
+LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_SECREL);
+LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_SECRELLO);
+LLVM

[clang] [Clang] correct error message when assigning to const reference captured in lambda (PR #105647)

2024-09-08 Thread via cfe-commits

nfrmtk wrote:

ping @cor3ntin 

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


[clang] [lld] [llvm] [clang][MIPS] Add support for mipsel-windows-* targets (PR #107744)

2024-09-08 Thread via cfe-commits
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau 
Message-ID:
In-Reply-To: 


https://github.com/hpoussin updated 
https://github.com/llvm/llvm-project/pull/107744

>From 193f3d3d60c2c9742db50dcb47d689b7968b08d9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= 
Date: Sun, 22 Oct 2023 07:19:08 +0200
Subject: [PATCH 01/13] [Triple] Make mipsel-*-windows-* use COFF files by
 default

Windows NT/MIPS and Windows CE/MIPS always used COFF format.
---
 llvm/lib/TargetParser/Triple.cpp   | 6 +-
 llvm/unittests/TargetParser/TripleTest.cpp | 3 +++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 55911a7d71ac70..18e2d4fa465f8f 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -905,7 +905,6 @@ static Triple::ObjectFormatType getDefaultFormat(const 
Triple &T) {
   case Triple::mips64:
   case Triple::mips64el:
   case Triple::mips:
-  case Triple::mipsel:
   case Triple::msp430:
   case Triple::nvptx64:
   case Triple::nvptx:
@@ -930,6 +929,11 @@ static Triple::ObjectFormatType getDefaultFormat(const 
Triple &T) {
   case Triple::xtensa:
 return Triple::ELF;
 
+  case Triple::mipsel:
+if (T.isOSWindows())
+  return Triple::COFF;
+return Triple::ELF;
+
   case Triple::ppc64:
   case Triple::ppc:
 if (T.isOSAIX())
diff --git a/llvm/unittests/TargetParser/TripleTest.cpp 
b/llvm/unittests/TargetParser/TripleTest.cpp
index 0aecfc64da2080..1beb52088941e9 100644
--- a/llvm/unittests/TargetParser/TripleTest.cpp
+++ b/llvm/unittests/TargetParser/TripleTest.cpp
@@ -2302,6 +2302,9 @@ TEST(TripleTest, NormalizeWindows) {
 Triple::normalize("i686-pc-windows-elf-elf"));
 
   EXPECT_TRUE(Triple("x86_64-pc-win32").isWindowsMSVCEnvironment());
+
+  
EXPECT_TRUE(Triple(Triple::normalize("mipsel-windows-msvccoff")).isOSBinFormatCOFF());
+  
EXPECT_TRUE(Triple(Triple::normalize("mipsel-windows-msvc")).isOSBinFormatCOFF());
 }
 
 TEST(TripleTest, NormalizeAndroid) {

>From f99b2ea9f3f744500acaab0c05a346250e0e7751 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= 
Date: Sun, 22 Oct 2023 07:30:37 +0200
Subject: [PATCH 02/13] [COFF] Add MIPS relocation types

Add the MIPS COFF relocation types. They will be needed to add support for
MIPS Windows object file.
---
 llvm/include/llvm/BinaryFormat/COFF.h | 18 ++
 llvm/lib/Object/COFFObjectFile.cpp| 21 +
 2 files changed, 39 insertions(+)

diff --git a/llvm/include/llvm/BinaryFormat/COFF.h 
b/llvm/include/llvm/BinaryFormat/COFF.h
index 3fc543f73c49db..bbc5264d17872a 100644
--- a/llvm/include/llvm/BinaryFormat/COFF.h
+++ b/llvm/include/llvm/BinaryFormat/COFF.h
@@ -417,6 +417,24 @@ enum RelocationTypesARM64 : unsigned {
   IMAGE_REL_ARM64_REL32 = 0x0011,
 };
 
+enum RelocationTypesMips : unsigned {
+  IMAGE_REL_MIPS_ABSOLUTE = 0x,
+  IMAGE_REL_MIPS_REFHALF = 0x0001,
+  IMAGE_REL_MIPS_REFWORD = 0x0002,
+  IMAGE_REL_MIPS_JMPADDR = 0x0003,
+  IMAGE_REL_MIPS_REFHI = 0x0004,
+  IMAGE_REL_MIPS_REFLO = 0x0005,
+  IMAGE_REL_MIPS_GPREL = 0x0006,
+  IMAGE_REL_MIPS_LITERAL = 0x0007,
+  IMAGE_REL_MIPS_SECTION = 0x000A,
+  IMAGE_REL_MIPS_SECREL = 0x000B,
+  IMAGE_REL_MIPS_SECRELLO = 0x000C,
+  IMAGE_REL_MIPS_SECRELHI = 0x000D,
+  IMAGE_REL_MIPS_JMPADDR16 = 0x0010,
+  IMAGE_REL_MIPS_REFWORDNB = 0x0022,
+  IMAGE_REL_MIPS_PAIR = 0x0025,
+};
+
 enum DynamicRelocationType : unsigned {
   IMAGE_DYNAMIC_RELOCATION_GUARD_RF_PROLOGUE = 1,
   IMAGE_DYNAMIC_RELOCATION_GUARD_RF_EPILOGUE = 2,
diff --git a/llvm/lib/Object/COFFObjectFile.cpp 
b/llvm/lib/Object/COFFObjectFile.cpp
index 5fdf3baf8c02cc..f55138bb23907a 100644
--- a/llvm/lib/Object/COFFObjectFile.cpp
+++ b/llvm/lib/Object/COFFObjectFile.cpp
@@ -1465,6 +1465,27 @@ StringRef COFFObjectFile::getRelocationTypeName(uint16_t 
Type) const {
   return "Unknown";
 }
 break;
+  case Triple::mipsel:
+switch (Type) {
+LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_ABSOLUTE);
+LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_REFHALF);
+LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_REFWORD);
+LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_JMPADDR);
+LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_REFHI);
+LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_REFLO);
+LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_GPREL);
+LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_LITERAL);
+LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_SECTION);
+LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_SECREL);
+LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_SECRELLO);
+LLVM

[clang] [HIP][Clang][CodeGen] Handle hip bin symbols properly. (PR #107458)

2024-09-08 Thread via cfe-commits

https://github.com/jofrn updated 
https://github.com/llvm/llvm-project/pull/107458

>From 60e30f156f1d8dcf015b10704c8ebbab5cd36ce5 Mon Sep 17 00:00:00 2001
From: jofernau 
Date: Thu, 5 Sep 2024 23:31:55 -0400
Subject: [PATCH] [HIP][Clang][CodeGen] Handle hip bin symbols properly.

Remove '_' in fatbin symbol suffix when missing TU hash ID. Internalize gpubin 
symbol so that it is not unresolved at link-time.
---
 clang/lib/CodeGen/CGCUDANV.cpp | 18 ++
 clang/test/CodeGenCUDA/device-stub.cu  |  1 -
 clang/test/Driver/hip-partial-link.hip |  1 -
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 59c5927717933d..7988d4ce462caf 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -840,8 +840,10 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() {
   FatBinStr = new llvm::GlobalVariable(
   CGM.getModule(), CGM.Int8Ty,
   /*isConstant=*/true, llvm::GlobalValue::ExternalLinkage, nullptr,
-  "__hip_fatbin_" + CGM.getContext().getCUIDHash(), nullptr,
-  llvm::GlobalVariable::NotThreadLocal);
+  "__hip_fatbin" + (CGM.getLangOpts().CUID.empty()
+? ""
+: "_" + CGM.getContext().getCUIDHash()),
+  nullptr, llvm::GlobalVariable::NotThreadLocal);
   cast(FatBinStr)->setSection(FatbinConstantName);
 }
 
@@ -894,8 +896,8 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() {
   // thread safety of the loaded program. Therefore we can assume sequential
   // execution of constructor functions here.
   if (IsHIP) {
-auto Linkage = CudaGpuBinary ? llvm::GlobalValue::InternalLinkage
- : llvm::GlobalValue::ExternalLinkage;
+auto Linkage = RelocatableDeviceCode ? llvm::GlobalValue::ExternalLinkage
+ : llvm::GlobalValue::InternalLinkage;
 llvm::BasicBlock *IfBlock =
 llvm::BasicBlock::Create(Context, "if", ModuleCtorFunc);
 llvm::BasicBlock *ExitBlock =
@@ -905,10 +907,10 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() 
{
 GpuBinaryHandle = new llvm::GlobalVariable(
 TheModule, PtrTy, /*isConstant=*/false, Linkage,
 /*Initializer=*/
-CudaGpuBinary ? llvm::ConstantPointerNull::get(PtrTy) : nullptr,
-CudaGpuBinary
-? "__hip_gpubin_handle"
-: "__hip_gpubin_handle_" + CGM.getContext().getCUIDHash());
+llvm::ConstantPointerNull::get(PtrTy),
+"__hip_gpubin_handle" + (CGM.getLangOpts().CUID.empty()
+ ? ""
+ : "_" + CGM.getContext().getCUIDHash()));
 GpuBinaryHandle->setAlignment(CGM.getPointerAlign().getAsAlign());
 // Prevent the weak symbol in different shared libraries being merged.
 if (Linkage != llvm::GlobalValue::InternalLinkage)
diff --git a/clang/test/CodeGenCUDA/device-stub.cu 
b/clang/test/CodeGenCUDA/device-stub.cu
index 60304647bd4c54..11d1f5a867b09a 100644
--- a/clang/test/CodeGenCUDA/device-stub.cu
+++ b/clang/test/CodeGenCUDA/device-stub.cu
@@ -175,7 +175,6 @@ __device__ void device_use() {
 // HIP-SAME: section ".hipFatBinSegment"
 // * variable to save GPU binary handle after initialization
 // CUDANORDC: @__[[PREFIX]]_gpubin_handle = internal global ptr null
-// HIPNEF: @__[[PREFIX]]_gpubin_handle_{{[0-9a-f]+}} = external hidden global 
ptr, align 8
 // * constant unnamed string with NVModuleID
 // CUDARDC: [[MODULE_ID_GLOBAL:@.*]] = private constant
 // CUDARDC-SAME: c"[[MODULE_ID:.+]]\00", section "__nv_module_id", align 32
diff --git a/clang/test/Driver/hip-partial-link.hip 
b/clang/test/Driver/hip-partial-link.hip
index c8451ec81ed37e..ab36a505fd8d42 100644
--- a/clang/test/Driver/hip-partial-link.hip
+++ b/clang/test/Driver/hip-partial-link.hip
@@ -15,7 +15,6 @@
 // RUN: llvm-nm  %t.1.o | FileCheck -check-prefix=OBJ1 %s
 // OBJ1:  B __hip_cuid_[[ID:[0-9a-f]+]]
 // OBJ1:  U __hip_fatbin_[[ID]]
-// OBJ1:  U __hip_gpubin_handle_[[ID]]
 
 // RUN: llvm-nm  %t.2.o | FileCheck -check-prefix=OBJ2 %s
 // OBJ2:  B __hip_cuid_[[ID:[0-9a-f]+]]

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


[clang] Reapply "[Clang][CWG1815] Support lifetime extension of temporary created by aggregate initialization using a default member initializer" (PR #97308)

2024-09-08 Thread via cfe-commits

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

LGTM, thanks!
Sorry the review took some time

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


[clang] [HIP][Clang][CodeGen] Handle hip bin symbols properly. (PR #107458)

2024-09-08 Thread via cfe-commits

https://github.com/jofrn updated 
https://github.com/llvm/llvm-project/pull/107458

>From b21b6c38f6a4cfb3103bb60b3122be4b5253b57f Mon Sep 17 00:00:00 2001
From: jofernau 
Date: Thu, 5 Sep 2024 23:31:55 -0400
Subject: [PATCH] [HIP][Clang][CodeGen] Handle hip bin symbols properly.

Remove '_' in fatbin symbol suffix when missing TU hash ID. Internalize gpubin 
symbol so that it is not unresolved at link-time.
---
 clang/lib/CodeGen/CGCUDANV.cpp | 18 ++
 clang/test/CodeGenCUDA/device-stub.cu  |  1 -
 clang/test/Driver/hip-partial-link.hip |  8 
 3 files changed, 10 insertions(+), 17 deletions(-)

diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 59c5927717933d..7988d4ce462caf 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -840,8 +840,10 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() {
   FatBinStr = new llvm::GlobalVariable(
   CGM.getModule(), CGM.Int8Ty,
   /*isConstant=*/true, llvm::GlobalValue::ExternalLinkage, nullptr,
-  "__hip_fatbin_" + CGM.getContext().getCUIDHash(), nullptr,
-  llvm::GlobalVariable::NotThreadLocal);
+  "__hip_fatbin" + (CGM.getLangOpts().CUID.empty()
+? ""
+: "_" + CGM.getContext().getCUIDHash()),
+  nullptr, llvm::GlobalVariable::NotThreadLocal);
   cast(FatBinStr)->setSection(FatbinConstantName);
 }
 
@@ -894,8 +896,8 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() {
   // thread safety of the loaded program. Therefore we can assume sequential
   // execution of constructor functions here.
   if (IsHIP) {
-auto Linkage = CudaGpuBinary ? llvm::GlobalValue::InternalLinkage
- : llvm::GlobalValue::ExternalLinkage;
+auto Linkage = RelocatableDeviceCode ? llvm::GlobalValue::ExternalLinkage
+ : llvm::GlobalValue::InternalLinkage;
 llvm::BasicBlock *IfBlock =
 llvm::BasicBlock::Create(Context, "if", ModuleCtorFunc);
 llvm::BasicBlock *ExitBlock =
@@ -905,10 +907,10 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() 
{
 GpuBinaryHandle = new llvm::GlobalVariable(
 TheModule, PtrTy, /*isConstant=*/false, Linkage,
 /*Initializer=*/
-CudaGpuBinary ? llvm::ConstantPointerNull::get(PtrTy) : nullptr,
-CudaGpuBinary
-? "__hip_gpubin_handle"
-: "__hip_gpubin_handle_" + CGM.getContext().getCUIDHash());
+llvm::ConstantPointerNull::get(PtrTy),
+"__hip_gpubin_handle" + (CGM.getLangOpts().CUID.empty()
+ ? ""
+ : "_" + CGM.getContext().getCUIDHash()));
 GpuBinaryHandle->setAlignment(CGM.getPointerAlign().getAsAlign());
 // Prevent the weak symbol in different shared libraries being merged.
 if (Linkage != llvm::GlobalValue::InternalLinkage)
diff --git a/clang/test/CodeGenCUDA/device-stub.cu 
b/clang/test/CodeGenCUDA/device-stub.cu
index 60304647bd4c54..11d1f5a867b09a 100644
--- a/clang/test/CodeGenCUDA/device-stub.cu
+++ b/clang/test/CodeGenCUDA/device-stub.cu
@@ -175,7 +175,6 @@ __device__ void device_use() {
 // HIP-SAME: section ".hipFatBinSegment"
 // * variable to save GPU binary handle after initialization
 // CUDANORDC: @__[[PREFIX]]_gpubin_handle = internal global ptr null
-// HIPNEF: @__[[PREFIX]]_gpubin_handle_{{[0-9a-f]+}} = external hidden global 
ptr, align 8
 // * constant unnamed string with NVModuleID
 // CUDARDC: [[MODULE_ID_GLOBAL:@.*]] = private constant
 // CUDARDC-SAME: c"[[MODULE_ID:.+]]\00", section "__nv_module_id", align 32
diff --git a/clang/test/Driver/hip-partial-link.hip 
b/clang/test/Driver/hip-partial-link.hip
index c8451ec81ed37e..3deea52086c874 100644
--- a/clang/test/Driver/hip-partial-link.hip
+++ b/clang/test/Driver/hip-partial-link.hip
@@ -15,12 +15,10 @@
 // RUN: llvm-nm  %t.1.o | FileCheck -check-prefix=OBJ1 %s
 // OBJ1:  B __hip_cuid_[[ID:[0-9a-f]+]]
 // OBJ1:  U __hip_fatbin_[[ID]]
-// OBJ1:  U __hip_gpubin_handle_[[ID]]
 
 // RUN: llvm-nm  %t.2.o | FileCheck -check-prefix=OBJ2 %s
 // OBJ2:  B __hip_cuid_[[ID:[0-9a-f]+]]
 // OBJ2:  U __hip_fatbin_[[ID]]
-// OBJ2:  U __hip_gpubin_handle_[[ID]]
 
 // Link %t.1.o and %t.2.o by -r and then link with %t.main.o
 
@@ -30,8 +28,6 @@
 // RUN:   2>&1 | FileCheck -check-prefix=LD-R %s
 // LD-R: Found undefined HIP fatbin symbol: __hip_fatbin_[[ID1:[0-9a-f]+]]
 // LD-R: Found undefined HIP fatbin symbol: __hip_fatbin_[[ID2:[0-9a-f]+]]
-// LD-R: Found undefined HIP gpubin handle symbol: __hip_gpubin_handle_[[ID1]]
-// LD-R: Found undefined HIP gpubin handle symbol: __hip_gpubin_handle_[[ID2]]
 // LD-R: "{{.*}}/clang-offload-bundler" {{.*}}-unbundle
 // LD-R: "{{.*}}/lld" -flavor gnu -m elf64_amdgpu
 // LD-R: "{{.*}}/clang-offload-bundler"
@@ -43,8 +39,6 @@
 // OBJ:  B __hip_cuid_[[ID2:[0-9a-f]+]]
 // OBJ:  R __hip_

[clang] 0f1bc5d - Fix GCC Wimplicit-fallthrough warnings. NFC.

2024-09-08 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2024-09-08T14:07:38+01:00
New Revision: 0f1bc5dbf3c51a1ee33d6037a6a169f0b0fbe217

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

LOG: Fix GCC Wimplicit-fallthrough warnings. NFC.

Added: 


Modified: 
clang/lib/Sema/Sema.cpp

Removed: 




diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 29acd06af603be..46ddd360870b4f 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -2865,6 +2865,7 @@ bool FunctionEffectDiff::shouldDiagnoseConversion(
   // matching is better.
   return true;
 }
+llvm_unreachable("Unhandled FunctionEffectDiff::Kind enum");
   case FunctionEffect::Kind::Blocking:
   case FunctionEffect::Kind::Allocating:
 return false;
@@ -2890,6 +2891,7 @@ bool FunctionEffectDiff::shouldDiagnoseRedeclaration(
   // All these forms of mismatches are diagnosed.
   return true;
 }
+llvm_unreachable("Unhandled FunctionEffectDiff::Kind enum");
   case FunctionEffect::Kind::Blocking:
   case FunctionEffect::Kind::Allocating:
 return false;
@@ -2921,6 +2923,7 @@ FunctionEffectDiff::shouldDiagnoseMethodOverride(
 case Kind::ConditionMismatch:
   return OverrideResult::Warn;
 }
+llvm_unreachable("Unhandled FunctionEffectDiff::Kind enum");
 
   case FunctionEffect::Kind::Blocking:
   case FunctionEffect::Kind::Allocating:



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


[clang] [Clang] Add `__builtin_experimental_vectorcompress` (PR #102476)

2024-09-08 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

What's the status of this? I'd really like to use it in a libc++ optimization.

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


[clang] [Clang][Sema] Use the correct lookup context when building overloaded 'operator->' in the current instantiation (PR #104458)

2024-09-08 Thread via cfe-commits

cor3ntin wrote:

@sdkrystian can you merge soon so that we can cherry pick in 19? thanks!

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


[clang] [HIP][Clang][CodeGen] Handle hip bin symbols properly. (PR #107458)

2024-09-08 Thread via cfe-commits

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


[clang] [FrontEnd] Use SetVector (NFC) (PR #107743)

2024-09-08 Thread Kazu Hirata via cfe-commits

https://github.com/kazutakahirata updated 
https://github.com/llvm/llvm-project/pull/107743

>From cb2cc5934488f75664eee61b26a9a3ce3f27010c Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Sun, 8 Sep 2024 00:48:25 -0700
Subject: [PATCH 1/2] [FrontEnd] Use SetVector for BlockByCopyDecls (NFC)

We could also use range-based for loops at several places, but I'm
leaving that to a subsequent patch.
---
 .../Frontend/Rewrite/RewriteModernObjC.cpp| 88 ++-
 1 file changed, 45 insertions(+), 43 deletions(-)

diff --git a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp 
b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
index 31ec86e2e4f096..c6539658669ef3 100644
--- a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
+++ b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
@@ -138,10 +138,8 @@ namespace {
 SmallVector BlockDeclRefs;
 
 // Block related declarations.
-SmallVector BlockByCopyDecls;
-llvm::SmallPtrSet BlockByCopyDeclsPtrSet;
-SmallVector BlockByRefDecls;
-llvm::SmallPtrSet BlockByRefDeclsPtrSet;
+llvm::SmallSetVector BlockByCopyDecls;
+llvm::SmallSetVector BlockByRefDecls;
 llvm::DenseMap BlockByRefDeclNo;
 llvm::SmallPtrSet ImportedBlockDecls;
 llvm::SmallPtrSet ImportedLocalExternalDecls;
@@ -4082,8 +4080,10 @@ std::string 
RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i,
 
   // Create local declarations to avoid rewriting all closure decl ref exprs.
   // First, emit a declaration for all "by ref" decls.
-  for (SmallVectorImpl::iterator I = BlockByRefDecls.begin(),
-   E = BlockByRefDecls.end(); I != E; ++I) {
+  for (llvm::SmallSetVector::iterator
+   I = BlockByRefDecls.begin(),
+   E = BlockByRefDecls.end();
+   I != E; ++I) {
 S += "  ";
 std::string Name = (*I)->getNameAsString();
 std::string TypeString;
@@ -4093,8 +4093,10 @@ std::string 
RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i,
 S += Name + " = __cself->" + (*I)->getNameAsString() + "; // bound by 
ref\n";
   }
   // Next, emit a declaration for all "by copy" declarations.
-  for (SmallVectorImpl::iterator I = BlockByCopyDecls.begin(),
-   E = BlockByCopyDecls.end(); I != E; ++I) {
+  for (llvm::SmallSetVector::iterator
+   I = BlockByCopyDecls.begin(),
+   E = BlockByCopyDecls.end();
+   I != E; ++I) {
 S += "  ";
 // Handle nested closure invocation. For example:
 //
@@ -4146,7 +4148,7 @@ std::string RewriteModernObjC::SynthesizeBlockHelperFuncs(
 S += VD->getNameAsString();
 S += ", (void*)src->";
 S += VD->getNameAsString();
-if (BlockByRefDeclsPtrSet.count(VD))
+if (BlockByRefDecls.count(VD))
   S += ", " + utostr(BLOCK_FIELD_IS_BYREF) + "/*BLOCK_FIELD_IS_BYREF*/);";
 else if (VD->getType()->isBlockPointerType())
   S += ", " + utostr(BLOCK_FIELD_IS_BLOCK) + "/*BLOCK_FIELD_IS_BLOCK*/);";
@@ -4163,7 +4165,7 @@ std::string RewriteModernObjC::SynthesizeBlockHelperFuncs(
   for (ValueDecl *VD : ImportedBlockDecls) {
 S += "_Block_object_dispose((void*)src->";
 S += VD->getNameAsString();
-if (BlockByRefDeclsPtrSet.count(VD))
+if (BlockByRefDecls.count(VD))
   S += ", " + utostr(BLOCK_FIELD_IS_BYREF) + "/*BLOCK_FIELD_IS_BYREF*/);";
 else if (VD->getType()->isBlockPointerType())
   S += ", " + utostr(BLOCK_FIELD_IS_BLOCK) + "/*BLOCK_FIELD_IS_BLOCK*/);";
@@ -4190,8 +4192,10 @@ std::string 
RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE,
 
   if (BlockDeclRefs.size()) {
 // Output all "by copy" declarations.
-for (SmallVectorImpl::iterator I = BlockByCopyDecls.begin(),
- E = BlockByCopyDecls.end(); I != E; ++I) {
+for (llvm::SmallSetVector::iterator
+ I = BlockByCopyDecls.begin(),
+ E = BlockByCopyDecls.end();
+ I != E; ++I) {
   S += "  ";
   std::string FieldName = (*I)->getNameAsString();
   std::string ArgName = "_" + FieldName;
@@ -4219,8 +4223,10 @@ std::string 
RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE,
   S += FieldName + ";\n";
 }
 // Output all "by ref" declarations.
-for (SmallVectorImpl::iterator I = BlockByRefDecls.begin(),
- E = BlockByRefDecls.end(); I != E; ++I) {
+for (llvm::SmallSetVector::iterator
+ I = BlockByRefDecls.begin(),
+ E = BlockByRefDecls.end();
+ I != E; ++I) {
   S += "  ";
   std::string FieldName = (*I)->getNameAsString();
   std::string ArgName = "_" + FieldName;
@@ -4238,8 +4244,10 @@ std::string 
RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE,
 Constructor += ", int flags=0)";
 // Initialize all "by copy" arguments.
 bool firsTime = true;
-for (SmallVectorImpl::iterator I = BlockByCopyDecls.begin(),
- E = BlockByCopyDecls.end(); I != E; ++I) {
+for (llvm::SmallSetVector::iterator
+ I = BlockByCopyDecls.begin(),
+ E = BlockByCopyDecls.end();
+ I != E; ++I) {
 

[clang] [FrontEnd] Use SetVector (NFC) (PR #107743)

2024-09-08 Thread Kazu Hirata via cfe-commits


@@ -4082,8 +4080,10 @@ std::string 
RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i,
 
   // Create local declarations to avoid rewriting all closure decl ref exprs.
   // First, emit a declaration for all "by ref" decls.
-  for (SmallVectorImpl::iterator I = BlockByRefDecls.begin(),
-   E = BlockByRefDecls.end(); I != E; ++I) {
+  for (llvm::SmallSetVector::iterator

kazutakahirata wrote:

Fixed in the latest iteration.  Thanks!

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


[clang] [FrontEnd] Use SetVector (NFC) (PR #107743)

2024-09-08 Thread Kazu Hirata via cfe-commits


@@ -5157,14 +5163,12 @@ void 
RewriteModernObjC::CollectBlockDeclRefInfo(BlockExpr *Exp) {
 // Unique all "by copy" declarations.
 for (unsigned i = 0; i < BlockDeclRefs.size(); i++)
   if (!BlockDeclRefs[i]->getDecl()->hasAttr()) {

kazutakahirata wrote:

Fixed in the latest iteration.  Thanks!

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


[clang] Reapply "[Clang][CWG1815] Support lifetime extension of temporary created by aggregate initialization using a default member initializer" (PR #97308)

2024-09-08 Thread via cfe-commits

yronglin wrote:

Thanks for your review!

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


[clang] 45c8766 - Reapply "[Clang][CWG1815] Support lifetime extension of temporary created by aggregate initialization using a default member initializer" (#97308)

2024-09-08 Thread via cfe-commits

Author: yronglin
Date: 2024-09-08T22:36:49+08:00
New Revision: 45c8766973bb3bb73dd8d996231e114dcf45df9f

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

LOG: Reapply "[Clang][CWG1815] Support lifetime extension of temporary created 
by aggregate initialization using a default member initializer" (#97308)

The PR reapply https://github.com/llvm/llvm-project/pull/92527.
Implemented CWG1815 and fixed the bugs mentioned in the comments of
https://github.com/llvm/llvm-project/pull/92527 and
https://github.com/llvm/llvm-project/pull/87933.

The reason why the original PR was reverted was that errors might occur
during the rebuild.

-

Signed-off-by: yronglin 

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Parse/ParseDecl.cpp
clang/lib/Sema/CheckExprLifetime.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaInit.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/lib/Sema/TreeTransform.h
clang/test/AST/ast-dump-default-init-json.cpp
clang/test/AST/ast-dump-default-init.cpp
clang/test/Analysis/lifetime-extended-regions.cpp
clang/test/CXX/drs/cwg16xx.cpp
clang/test/CXX/drs/cwg18xx.cpp
clang/test/CXX/special/class.temporary/p6.cpp
clang/test/SemaCXX/constexpr-default-arg.cpp
clang/test/SemaCXX/cxx11-default-member-initializers.cpp
clang/test/SemaCXX/eval-crashes.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f4e54a0470d862..f7c3194c91fa31 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -108,6 +108,9 @@ C++ Language Changes
 - Allow single element access of GCC vector/ext_vector_type object to be
   constant expression. Supports the `V.xyzw` syntax and other tidbits
   as seen in OpenCL. Selecting multiple elements is left as a future work.
+- Implement `CWG1815 `_. Support lifetime extension 
+  of temporary created by aggregate initialization using a default member
+  initializer.
 
 - Accept C++26 user-defined ``static_assert`` messages in C++11 as an 
extension.
 

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 58819a64813fce..4609d2ec2b7209 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10159,13 +10159,6 @@ def warn_dangling_pointer_assignment : Warning<
"will be destroyed at the end of the full-expression">,
InGroup;
 
-def warn_unsupported_lifetime_extension : Warning<
-  "lifetime extension of "
-  "%select{temporary|backing array of initializer list}0 created "
-  "by aggregate initialization using a default member initializer "
-  "is not yet supported; lifetime of %select{temporary|backing array}0 "
-  "will end at the end of the full-expression">, InGroup;
-
 // For non-floating point, expressions of the form x == x or x != x
 // should result in a warning, since these always evaluate to a constant.
 // Array comparisons have similar warnings

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 68c782a15c6f1b..ac4c11964b126f 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -6403,6 +6403,9 @@ class Sema final : public SemaBase {
 /// example, in a for-range initializer).
 bool InLifetimeExtendingContext = false;
 
+/// Whether we should rebuild CXXDefaultArgExpr and CXXDefaultInitExpr.
+bool RebuildDefaultArgOrDefaultInit = false;
+
 // When evaluating immediate functions in the initializer of a default
 // argument or default member initializer, this is the declaration whose
 // default initializer is being evaluated and the location of the call
@@ -7810,9 +7813,11 @@ class Sema final : public SemaBase {
   }
 
   bool isInLifetimeExtendingContext() const {
-assert(!ExprEvalContexts.empty() &&
-   "Must be in an expression evaluation context");
-return ExprEvalContexts.back().InLifetimeExtendingContext;
+return currentEvaluationContext().InLifetimeExtendingContext;
+  }
+
+  bool needRebuildDefaultArgOrInit() const {
+return currentEvaluationContext().RebuildDefaultArgOrDefaultInit;
   }
 
   bool isCheckingDefaultArgumentOrInitializer() const {
@@ -7854,18 +7859,6 @@ class Sema final : public SemaBase {
 return Res;
   }
 
-  /// keepInLifetimeExtendingContext - Pull down InLifetimeExtendingContext
-  /// flag from previous context.
-  void keepInLifetimeExtendingContext() {
-if (ExprEvalContexts.size() > 2 &&
-parentEvaluationContext().InLi

[clang] Reapply "[Clang][CWG1815] Support lifetime extension of temporary created by aggregate initialization using a default member initializer" (PR #97308)

2024-09-08 Thread via cfe-commits

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


[clang] e29e7e7 - [FrontEnd] Use SetVector (NFC) (#107743)

2024-09-08 Thread via cfe-commits

Author: Kazu Hirata
Date: 2024-09-08T07:48:30-07:00
New Revision: e29e7e726614d59cd5adae1f81266de947ee2f3b

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

LOG: [FrontEnd] Use SetVector (NFC) (#107743)

We could also use range-based for loops at several places, but I'm
leaving that to a subsequent patch.

Added: 


Modified: 
clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp

Removed: 




diff  --git a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp 
b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
index 31ec86e2e4f096..326920c7915537 100644
--- a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
+++ b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
@@ -138,10 +138,8 @@ namespace {
 SmallVector BlockDeclRefs;
 
 // Block related declarations.
-SmallVector BlockByCopyDecls;
-llvm::SmallPtrSet BlockByCopyDeclsPtrSet;
-SmallVector BlockByRefDecls;
-llvm::SmallPtrSet BlockByRefDeclsPtrSet;
+llvm::SmallSetVector BlockByCopyDecls;
+llvm::SmallSetVector BlockByRefDecls;
 llvm::DenseMap BlockByRefDeclNo;
 llvm::SmallPtrSet ImportedBlockDecls;
 llvm::SmallPtrSet ImportedLocalExternalDecls;
@@ -4082,8 +4080,8 @@ std::string 
RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i,
 
   // Create local declarations to avoid rewriting all closure decl ref exprs.
   // First, emit a declaration for all "by ref" decls.
-  for (SmallVectorImpl::iterator I = BlockByRefDecls.begin(),
-   E = BlockByRefDecls.end(); I != E; ++I) {
+  for (auto I = BlockByRefDecls.begin(), E = BlockByRefDecls.end(); I != E;
+   ++I) {
 S += "  ";
 std::string Name = (*I)->getNameAsString();
 std::string TypeString;
@@ -4093,8 +4091,8 @@ std::string 
RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i,
 S += Name + " = __cself->" + (*I)->getNameAsString() + "; // bound by 
ref\n";
   }
   // Next, emit a declaration for all "by copy" declarations.
-  for (SmallVectorImpl::iterator I = BlockByCopyDecls.begin(),
-   E = BlockByCopyDecls.end(); I != E; ++I) {
+  for (auto I = BlockByCopyDecls.begin(), E = BlockByCopyDecls.end(); I != E;
+   ++I) {
 S += "  ";
 // Handle nested closure invocation. For example:
 //
@@ -4146,7 +4144,7 @@ std::string RewriteModernObjC::SynthesizeBlockHelperFuncs(
 S += VD->getNameAsString();
 S += ", (void*)src->";
 S += VD->getNameAsString();
-if (BlockByRefDeclsPtrSet.count(VD))
+if (BlockByRefDecls.count(VD))
   S += ", " + utostr(BLOCK_FIELD_IS_BYREF) + "/*BLOCK_FIELD_IS_BYREF*/);";
 else if (VD->getType()->isBlockPointerType())
   S += ", " + utostr(BLOCK_FIELD_IS_BLOCK) + "/*BLOCK_FIELD_IS_BLOCK*/);";
@@ -4163,7 +4161,7 @@ std::string RewriteModernObjC::SynthesizeBlockHelperFuncs(
   for (ValueDecl *VD : ImportedBlockDecls) {
 S += "_Block_object_dispose((void*)src->";
 S += VD->getNameAsString();
-if (BlockByRefDeclsPtrSet.count(VD))
+if (BlockByRefDecls.count(VD))
   S += ", " + utostr(BLOCK_FIELD_IS_BYREF) + "/*BLOCK_FIELD_IS_BYREF*/);";
 else if (VD->getType()->isBlockPointerType())
   S += ", " + utostr(BLOCK_FIELD_IS_BLOCK) + "/*BLOCK_FIELD_IS_BLOCK*/);";
@@ -4190,8 +4188,8 @@ std::string 
RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE,
 
   if (BlockDeclRefs.size()) {
 // Output all "by copy" declarations.
-for (SmallVectorImpl::iterator I = BlockByCopyDecls.begin(),
- E = BlockByCopyDecls.end(); I != E; ++I) {
+for (auto I = BlockByCopyDecls.begin(), E = BlockByCopyDecls.end(); I != E;
+ ++I) {
   S += "  ";
   std::string FieldName = (*I)->getNameAsString();
   std::string ArgName = "_" + FieldName;
@@ -4219,8 +4217,8 @@ std::string 
RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE,
   S += FieldName + ";\n";
 }
 // Output all "by ref" declarations.
-for (SmallVectorImpl::iterator I = BlockByRefDecls.begin(),
- E = BlockByRefDecls.end(); I != E; ++I) {
+for (auto I = BlockByRefDecls.begin(), E = BlockByRefDecls.end(); I != E;
+ ++I) {
   S += "  ";
   std::string FieldName = (*I)->getNameAsString();
   std::string ArgName = "_" + FieldName;
@@ -4238,8 +4236,8 @@ std::string 
RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE,
 Constructor += ", int flags=0)";
 // Initialize all "by copy" arguments.
 bool firsTime = true;
-for (SmallVectorImpl::iterator I = BlockByCopyDecls.begin(),
- E = BlockByCopyDecls.end(); I != E; ++I) {
+for (auto I = BlockByCopyDecls.begin(), E = BlockByCopyDecls.end(); I != E;
+ ++I) {
   std::string Name = (*I)->getNameAsString();
 if (firsTime) {
   Constructor += " : ";
@@ -4253,8 +4251,8 @@ std::string 
RewriteModernObjC::Synthesiz

[clang] [FrontEnd] Use SetVector (NFC) (PR #107743)

2024-09-08 Thread Kazu Hirata via cfe-commits

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


[clang] [Frontend] Use range-based for loops (NFC) (PR #107757)

2024-09-08 Thread Kazu Hirata via cfe-commits

https://github.com/kazutakahirata created 
https://github.com/llvm/llvm-project/pull/107757

None

>From 54c996208763db5003e3d7f1e03aaee3de634664 Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Sun, 8 Sep 2024 07:20:15 -0700
Subject: [PATCH] [Frontend] Use range-based for loops (NFC)

---
 .../Frontend/Rewrite/RewriteModernObjC.cpp| 108 --
 1 file changed, 48 insertions(+), 60 deletions(-)

diff --git a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp 
b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
index 326920c7915537..8cdb463e2c99f2 100644
--- a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
+++ b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
@@ -4080,19 +4080,17 @@ std::string 
RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i,
 
   // Create local declarations to avoid rewriting all closure decl ref exprs.
   // First, emit a declaration for all "by ref" decls.
-  for (auto I = BlockByRefDecls.begin(), E = BlockByRefDecls.end(); I != E;
-   ++I) {
+  for (ValueDecl *VD : BlockByRefDecls) {
 S += "  ";
-std::string Name = (*I)->getNameAsString();
+std::string Name = VD->getNameAsString();
 std::string TypeString;
-RewriteByRefString(TypeString, Name, (*I));
+RewriteByRefString(TypeString, Name, VD);
 TypeString += " *";
 Name = TypeString + Name;
-S += Name + " = __cself->" + (*I)->getNameAsString() + "; // bound by 
ref\n";
+S += Name + " = __cself->" + VD->getNameAsString() + "; // bound by ref\n";
   }
   // Next, emit a declaration for all "by copy" declarations.
-  for (auto I = BlockByCopyDecls.begin(), E = BlockByCopyDecls.end(); I != E;
-   ++I) {
+  for (ValueDecl *VD : BlockByCopyDecls) {
 S += "  ";
 // Handle nested closure invocation. For example:
 //
@@ -4104,21 +4102,20 @@ std::string 
RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i,
 // myImportedClosure(); // import and invoke the closure
 //   };
 //
-if (isTopLevelBlockPointerType((*I)->getType())) {
-  RewriteBlockPointerTypeVariable(S, (*I));
+if (isTopLevelBlockPointerType(VD->getType())) {
+  RewriteBlockPointerTypeVariable(S, VD);
   S += " = (";
-  RewriteBlockPointerType(S, (*I)->getType());
+  RewriteBlockPointerType(S, VD->getType());
   S += ")";
-  S += "__cself->" + (*I)->getNameAsString() + "; // bound by copy\n";
-}
-else {
-  std::string Name = (*I)->getNameAsString();
-  QualType QT = (*I)->getType();
-  if (HasLocalVariableExternalStorage(*I))
+  S += "__cself->" + VD->getNameAsString() + "; // bound by copy\n";
+} else {
+  std::string Name = VD->getNameAsString();
+  QualType QT = VD->getType();
+  if (HasLocalVariableExternalStorage(VD))
 QT = Context->getPointerType(QT);
   QT.getAsStringInternal(Name, Context->getPrintingPolicy());
-  S += Name + " = __cself->" +
-  (*I)->getNameAsString() + "; // bound by copy\n";
+  S += Name + " = __cself->" + VD->getNameAsString() +
+   "; // bound by copy\n";
 }
   }
   std::string RewrittenStr = RewrittenBlockExprs[CE];
@@ -4188,10 +4185,9 @@ std::string 
RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE,
 
   if (BlockDeclRefs.size()) {
 // Output all "by copy" declarations.
-for (auto I = BlockByCopyDecls.begin(), E = BlockByCopyDecls.end(); I != E;
- ++I) {
+for (ValueDecl *VD : BlockByCopyDecls) {
   S += "  ";
-  std::string FieldName = (*I)->getNameAsString();
+  std::string FieldName = VD->getNameAsString();
   std::string ArgName = "_" + FieldName;
   // Handle nested closure invocation. For example:
   //
@@ -4203,12 +4199,12 @@ std::string 
RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE,
   // myImportedBlock(); // import and invoke the closure
   //   };
   //
-  if (isTopLevelBlockPointerType((*I)->getType())) {
+  if (isTopLevelBlockPointerType(VD->getType())) {
 S += "struct __block_impl *";
 Constructor += ", void *" + ArgName;
   } else {
-QualType QT = (*I)->getType();
-if (HasLocalVariableExternalStorage(*I))
+QualType QT = VD->getType();
+if (HasLocalVariableExternalStorage(VD))
   QT = Context->getPointerType(QT);
 QT.getAsStringInternal(FieldName, Context->getPrintingPolicy());
 QT.getAsStringInternal(ArgName, Context->getPrintingPolicy());
@@ -4217,14 +4213,13 @@ std::string 
RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE,
   S += FieldName + ";\n";
 }
 // Output all "by ref" declarations.
-for (auto I = BlockByRefDecls.begin(), E = BlockByRefDecls.end(); I != E;
- ++I) {
+for (ValueDecl *VD : BlockByRefDecls) {
   S += "  ";
-  std::string FieldName = (*I)->getNameAsString();
+  std::string FieldName = VD->getNameAsString();
   std::string ArgName = "_" + FieldName;
   {
 std::st

[clang] [Frontend] Use range-based for loops (NFC) (PR #107757)

2024-09-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes



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


1 Files Affected:

- (modified) clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp (+48-60) 


``diff
diff --git a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp 
b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
index 326920c7915537..8cdb463e2c99f2 100644
--- a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
+++ b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
@@ -4080,19 +4080,17 @@ std::string 
RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i,
 
   // Create local declarations to avoid rewriting all closure decl ref exprs.
   // First, emit a declaration for all "by ref" decls.
-  for (auto I = BlockByRefDecls.begin(), E = BlockByRefDecls.end(); I != E;
-   ++I) {
+  for (ValueDecl *VD : BlockByRefDecls) {
 S += "  ";
-std::string Name = (*I)->getNameAsString();
+std::string Name = VD->getNameAsString();
 std::string TypeString;
-RewriteByRefString(TypeString, Name, (*I));
+RewriteByRefString(TypeString, Name, VD);
 TypeString += " *";
 Name = TypeString + Name;
-S += Name + " = __cself->" + (*I)->getNameAsString() + "; // bound by 
ref\n";
+S += Name + " = __cself->" + VD->getNameAsString() + "; // bound by ref\n";
   }
   // Next, emit a declaration for all "by copy" declarations.
-  for (auto I = BlockByCopyDecls.begin(), E = BlockByCopyDecls.end(); I != E;
-   ++I) {
+  for (ValueDecl *VD : BlockByCopyDecls) {
 S += "  ";
 // Handle nested closure invocation. For example:
 //
@@ -4104,21 +4102,20 @@ std::string 
RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i,
 // myImportedClosure(); // import and invoke the closure
 //   };
 //
-if (isTopLevelBlockPointerType((*I)->getType())) {
-  RewriteBlockPointerTypeVariable(S, (*I));
+if (isTopLevelBlockPointerType(VD->getType())) {
+  RewriteBlockPointerTypeVariable(S, VD);
   S += " = (";
-  RewriteBlockPointerType(S, (*I)->getType());
+  RewriteBlockPointerType(S, VD->getType());
   S += ")";
-  S += "__cself->" + (*I)->getNameAsString() + "; // bound by copy\n";
-}
-else {
-  std::string Name = (*I)->getNameAsString();
-  QualType QT = (*I)->getType();
-  if (HasLocalVariableExternalStorage(*I))
+  S += "__cself->" + VD->getNameAsString() + "; // bound by copy\n";
+} else {
+  std::string Name = VD->getNameAsString();
+  QualType QT = VD->getType();
+  if (HasLocalVariableExternalStorage(VD))
 QT = Context->getPointerType(QT);
   QT.getAsStringInternal(Name, Context->getPrintingPolicy());
-  S += Name + " = __cself->" +
-  (*I)->getNameAsString() + "; // bound by copy\n";
+  S += Name + " = __cself->" + VD->getNameAsString() +
+   "; // bound by copy\n";
 }
   }
   std::string RewrittenStr = RewrittenBlockExprs[CE];
@@ -4188,10 +4185,9 @@ std::string 
RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE,
 
   if (BlockDeclRefs.size()) {
 // Output all "by copy" declarations.
-for (auto I = BlockByCopyDecls.begin(), E = BlockByCopyDecls.end(); I != E;
- ++I) {
+for (ValueDecl *VD : BlockByCopyDecls) {
   S += "  ";
-  std::string FieldName = (*I)->getNameAsString();
+  std::string FieldName = VD->getNameAsString();
   std::string ArgName = "_" + FieldName;
   // Handle nested closure invocation. For example:
   //
@@ -4203,12 +4199,12 @@ std::string 
RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE,
   // myImportedBlock(); // import and invoke the closure
   //   };
   //
-  if (isTopLevelBlockPointerType((*I)->getType())) {
+  if (isTopLevelBlockPointerType(VD->getType())) {
 S += "struct __block_impl *";
 Constructor += ", void *" + ArgName;
   } else {
-QualType QT = (*I)->getType();
-if (HasLocalVariableExternalStorage(*I))
+QualType QT = VD->getType();
+if (HasLocalVariableExternalStorage(VD))
   QT = Context->getPointerType(QT);
 QT.getAsStringInternal(FieldName, Context->getPrintingPolicy());
 QT.getAsStringInternal(ArgName, Context->getPrintingPolicy());
@@ -4217,14 +4213,13 @@ std::string 
RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE,
   S += FieldName + ";\n";
 }
 // Output all "by ref" declarations.
-for (auto I = BlockByRefDecls.begin(), E = BlockByRefDecls.end(); I != E;
- ++I) {
+for (ValueDecl *VD : BlockByRefDecls) {
   S += "  ";
-  std::string FieldName = (*I)->getNameAsString();
+  std::string FieldName = VD->getNameAsString();
   std::string ArgName = "_" + FieldName;
   {
 std::string TypeString;
-RewriteByRefString(TypeString, FieldName, (*I));
+RewriteByRefString(TypeString, FieldName, VD);
 

[clang] [APINotes] Avoid repeated hash lookups (NFC) (PR #107758)

2024-09-08 Thread Kazu Hirata via cfe-commits

https://github.com/kazutakahirata created 
https://github.com/llvm/llvm-project/pull/107758

None

>From f4517cfe4d48b964001a74452a200558746a3b7e Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Sun, 8 Sep 2024 07:41:45 -0700
Subject: [PATCH] [APINotes] Avoid repeated hash lookups (NFC)

---
 clang/lib/APINotes/APINotesWriter.cpp | 10 ++
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/clang/lib/APINotes/APINotesWriter.cpp 
b/clang/lib/APINotes/APINotesWriter.cpp
index c452677983bb36..2f4e5e803f6a2b 100644
--- a/clang/lib/APINotes/APINotesWriter.cpp
+++ b/clang/lib/APINotes/APINotesWriter.cpp
@@ -147,14 +147,8 @@ class APINotesWriter::Implementation {
 for (auto piece : SelectorRef.Identifiers)
   Selector.Identifiers.push_back(getIdentifier(piece));
 
-// Look for the stored selector.
-auto Known = SelectorIDs.find(Selector);
-if (Known != SelectorIDs.end())
-  return Known->second;
-
-// Add to the selector table.
-Known = SelectorIDs.insert({Selector, SelectorIDs.size()}).first;
-return Known->second;
+// Look for the stored selector.  Add to the selector table if missing.
+return SelectorIDs.try_emplace(Selector, SelectorIDs.size()).first->second;
   }
 
 private:

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


[clang] [CodeGen] Avoid repeated hash lookups (NFC) (PR #107759)

2024-09-08 Thread Kazu Hirata via cfe-commits

https://github.com/kazutakahirata created 
https://github.com/llvm/llvm-project/pull/107759

None

>From 98280f2c6c2d1e3b6b0566f3c77649e00fe75da9 Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Sun, 8 Sep 2024 07:43:18 -0700
Subject: [PATCH] [CodeGen] Avoid repeated hash lookups (NFC)

---
 clang/lib/CodeGen/CoverageMappingGen.cpp | 7 +--
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 67a9caf8b4ec4b..07015834bc84f3 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -2595,12 +2595,7 @@ void CoverageMappingModuleGen::emit() {
 }
 
 unsigned CoverageMappingModuleGen::getFileID(FileEntryRef File) {
-  auto It = FileEntries.find(File);
-  if (It != FileEntries.end())
-return It->second;
-  unsigned FileID = FileEntries.size() + 1;
-  FileEntries.insert(std::make_pair(File, FileID));
-  return FileID;
+  return FileEntries.try_emplace(File, FileEntries.size() + 1).first->second;
 }
 
 void CoverageMappingGen::emitCounterMapping(const Decl *D,

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


[clang] [APINotes] Avoid repeated hash lookups (NFC) (PR #107758)

2024-09-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes



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


1 Files Affected:

- (modified) clang/lib/APINotes/APINotesWriter.cpp (+2-8) 


``diff
diff --git a/clang/lib/APINotes/APINotesWriter.cpp 
b/clang/lib/APINotes/APINotesWriter.cpp
index c452677983bb36..2f4e5e803f6a2b 100644
--- a/clang/lib/APINotes/APINotesWriter.cpp
+++ b/clang/lib/APINotes/APINotesWriter.cpp
@@ -147,14 +147,8 @@ class APINotesWriter::Implementation {
 for (auto piece : SelectorRef.Identifiers)
   Selector.Identifiers.push_back(getIdentifier(piece));
 
-// Look for the stored selector.
-auto Known = SelectorIDs.find(Selector);
-if (Known != SelectorIDs.end())
-  return Known->second;
-
-// Add to the selector table.
-Known = SelectorIDs.insert({Selector, SelectorIDs.size()}).first;
-return Known->second;
+// Look for the stored selector.  Add to the selector table if missing.
+return SelectorIDs.try_emplace(Selector, SelectorIDs.size()).first->second;
   }
 
 private:

``




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


[clang] [CodeGen] Avoid repeated hash lookups (NFC) (PR #107759)

2024-09-08 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-codegen

Author: Kazu Hirata (kazutakahirata)


Changes



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


1 Files Affected:

- (modified) clang/lib/CodeGen/CoverageMappingGen.cpp (+1-6) 


``diff
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 67a9caf8b4ec4b..07015834bc84f3 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -2595,12 +2595,7 @@ void CoverageMappingModuleGen::emit() {
 }
 
 unsigned CoverageMappingModuleGen::getFileID(FileEntryRef File) {
-  auto It = FileEntries.find(File);
-  if (It != FileEntries.end())
-return It->second;
-  unsigned FileID = FileEntries.size() + 1;
-  FileEntries.insert(std::make_pair(File, FileID));
-  return FileID;
+  return FileEntries.try_emplace(File, FileEntries.size() + 1).first->second;
 }
 
 void CoverageMappingGen::emitCounterMapping(const Decl *D,

``




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


[clang] [libcxx] [Clang] Add __builtin_common_type (PR #99473)

2024-09-08 Thread Nikolas Klauser via cfe-commits

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


[clang] [CodeGen] Avoid repeated hash lookups (NFC) (PR #107759)

2024-09-08 Thread Nikita Popov via cfe-commits

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


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


[clang] nonblocking/nonallocating attributes: 2nd pass caller/callee analysis (PR #99656)

2024-09-08 Thread Doug Wyatt via cfe-commits

dougsonos wrote:

In working with this version of the compiler, I've discovered a pain point with 
libc++, `std::__libcpp_verbose_abort()`. Many things which one would expect to 
be nonblocking, e.g. `std::vector::operator[]`, have hardening paths which 
call `__libcpp_verbose_abort()` on failure.

I chatted with a libc++ maintainer about this. A first thought was to simply 
declare `__libcpp_verbose_abort()` as `nonblocking`. But that feels like a 
weird lie. Possibly most ideally, functions like this would have an attribute 
to exempt them from nonblocking analysis.

A quick hack would be to synthesize that attribute from a combination of the 
`noreturn` attribute and the function name containing "abort" or "terminate". 
(`noreturn` on its own is initially attractive, but it can also apply to a 
wrapper around `throw`).

The only workaround is to redeclare `__libcpp_verbose_abort()` with 
`[[clang::nonblocking]]`. This is tricky because the redeclaration has to 
follow the one in `<__verbose_abort>` but precede its use from other headers 
like ``. That leads to having to include `<__verbose_abort>` directly.

Would appreciate any thoughts!

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


[clang] nonblocking/nonallocating attributes: 2nd pass caller/callee analysis (PR #99656)

2024-09-08 Thread Doug Wyatt via cfe-commits

dougsonos wrote:

> I do agree, it seems reasonable for it to be in `-Wall` or similar! That is 
> absolutely what I'd expect as a user :)

I guess my thinking was colored a bit by the way many of our codebases use 
`-Wall`.

I did come around to thinking that without `-Wall`, it's cleaner for the 
diagnostics to be disabled by default. Pushed a change.

Thanks, Chris.

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


[clang] [clang-tools-extra] [libc] [libc][c11] implement ctime (PR #107285)

2024-09-08 Thread Зишан Мирза via cfe-commits

https://github.com/zimirza updated 
https://github.com/llvm/llvm-project/pull/107285

From b982621407a1ab1746a023809aae5c6a2b983679 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=97=D0=B8=D1=88=D0=B0=D0=BD=20=D0=9C=D0=B8=D1=80=D0=B7?=
 =?UTF-8?q?=D0=B0?= <149377404+zimi...@users.noreply.github.com>
Date: Tue, 3 Sep 2024 22:47:30 +0200
Subject: [PATCH 01/49] [libc][c11] implement ctime (#86567)

---
 libc/src/time/CMakeLists.txt  |  11 ++
 libc/src/time/ctime.cpp   |  23 
 libc/src/time/ctime.h |  21 +++
 libc/src/time/time_utils.h|  46 +++
 libc/test/src/time/ctime_test.cpp | 215 ++
 5 files changed, 316 insertions(+)
 create mode 100644 libc/src/time/ctime.cpp
 create mode 100644 libc/src/time/ctime.h
 create mode 100644 libc/test/src/time/ctime_test.cpp

diff --git a/libc/src/time/CMakeLists.txt b/libc/src/time/CMakeLists.txt
index 5680718715974e..befe67677f3ec7 100644
--- a/libc/src/time/CMakeLists.txt
+++ b/libc/src/time/CMakeLists.txt
@@ -36,6 +36,17 @@ add_entrypoint_object(
 libc.include.time
 )
 
+add_entrypoint_object(
+  ctime
+  SRCS
+ctime.cpp
+  HDRS
+ctime.h
+  DEPENDS
+.time_utils
+libc.include.time
+)
+
 add_entrypoint_object(
   difftime
   SRCS
diff --git a/libc/src/time/ctime.cpp b/libc/src/time/ctime.cpp
new file mode 100644
index 00..f3181816ad9ab1
--- /dev/null
+++ b/libc/src/time/ctime.cpp
@@ -0,0 +1,23 @@
+//===-- Implementation of asctime function 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "src/time/ctime.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+#include "src/time/time_utils.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+using LIBC_NAMESPACE::time_utils::TimeConstants;
+
+LLVM_LIBC_FUNCTION(char *, ctime, (const struct tm *timeptr)) {
+  static char buffer[TimeConstants::CTIME_BUFFER_SIZE];
+  return time_utils::ctime(timeptr, buffer, TimeConstants::CTIME_MAX_BYTES);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/time/ctime.h b/libc/src/time/ctime.h
new file mode 100644
index 00..ec5530ffb5bc71
--- /dev/null
+++ b/libc/src/time/ctime.h
@@ -0,0 +1,21 @@
+//===-- Implementation header of ctime *- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SRC_TIME_CTIME_H
+#define LLVM_LIBC_SRC_TIME_CTIME_H
+
+#include "src/__support/macros/config.h"
+#include 
+
+namespace LIBC_NAMESPACE_DECL {
+
+char *ctime(const struct tm *timeptr);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_TIME_CTIME_H
diff --git a/libc/src/time/time_utils.h b/libc/src/time/time_utils.h
index 47f55f7d389122..6fa590fefac8d0 100644
--- a/libc/src/time/time_utils.h
+++ b/libc/src/time/time_utils.h
@@ -62,6 +62,9 @@ struct TimeConstants {
   static constexpr int ASCTIME_BUFFER_SIZE = 256;
   static constexpr int ASCTIME_MAX_BYTES = 26;
 
+  static constexpr int CTIME_BUFFER_SIZE = 256;
+  static constexpr int CTIME_MAX_BYTES = 26;
+
   /* 2000-03-01 (mod 400 year, immediately after feb29 */
   static constexpr int64_t SECONDS_UNTIL2000_MARCH_FIRST =
   (946684800LL + SECONDS_PER_DAY * (31 + 29));
@@ -145,6 +148,49 @@ LIBC_INLINE char *asctime(const struct tm *timeptr, char 
*buffer,
   return buffer;
 }
 
+LIBC_INLINE char *ctime(const struct tm *timeptr, char *buffer,
+size_t bufferLength) {
+  if (timeptr == nullptr || buffer == nullptr) {
+invalid_value();
+return nullptr;
+  }
+  if (timeptr->tm_wday < 0 ||
+  timeptr->tm_wday > (TimeConstants::DAYS_PER_WEEK - 1)) {
+invalid_value();
+return nullptr;
+  }
+  if (timeptr->tm_mon < 0 ||
+  timeptr->tm_mon > (TimeConstants::MONTHS_PER_YEAR - 1)) {
+invalid_value();
+return nullptr;
+  }
+
+  // TODO(rtenneti): i18n the following strings.
+  static const char *week_days_name[TimeConstants::DAYS_PER_WEEK] = {
+  "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
+
+  static const char *months_name[TimeConstants::MONTHS_PER_YEAR] = {
+  "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
+
+  // TODO(michaelr): look into removing this call to __builtin_snprintf that 
may
+  // be emitted as a call to snprintf. Alternatively, look into using our
+  // internal printf machinery.
+  int written_size = __builtin_snprintf(
+  buffer, bufferLength, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n",
+  week_days

[clang] [clang-tools-extra] [libc] [libc][c11] implement ctime (PR #107285)

2024-09-08 Thread Зишан Мирза via cfe-commits


@@ -0,0 +1,26 @@
+//===-- Implementation of ctime function 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ctime.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+#include "time_utils.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+using LIBC_NAMESPACE::time_utils::TimeConstants;
+
+LLVM_LIBC_FUNCTION(char *, ctime, (const time_t *t_ptr)) {
+  if (t_ptr > TimeConstants::MAXIMUM_32_BIT_VALUE) {

zimirza wrote:

Yes, that is correct. The pointer should be dereferenced. Fixed it now.

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


[clang] [clang-tools-extra] [libc] [libc][c11] implement ctime (PR #107285)

2024-09-08 Thread Зишан Мирза via cfe-commits


@@ -37,6 +37,7 @@ enum Month : int {
 };
 
 struct TimeConstants {
+  static constexpr int MAXIMUM_32_BIT_VALUE = 2147483647;

zimirza wrote:

I have removed the constant and used this function.

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


[clang] [clang-tools-extra] [libc] [libc][c11] implement ctime (PR #107285)

2024-09-08 Thread Зишан Мирза via cfe-commits


@@ -0,0 +1,26 @@
+//===-- Implementation of ctime function 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ctime.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+#include "time_utils.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+using LIBC_NAMESPACE::time_utils::TimeConstants;
+
+LLVM_LIBC_FUNCTION(char *, ctime, (const time_t *t_ptr)) {
+  if (t_ptr > TimeConstants::MAXIMUM_32_BIT_VALUE) {
+return nullptr;
+  }
+  static char buffer[TimeConstants::ASCTIME_BUFFER_SIZE];
+  return time_utils::asctime(localtime(t_ptr), buffer, 
TimeConstants::ASCTIME_MAX_BYTES);

zimirza wrote:

Yes, that is actually better. I added `time_utils::`.

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


[clang] [clang-tools-extra] [libc] [libc][c11] implement ctime (PR #107285)

2024-09-08 Thread Зишан Мирза via cfe-commits


@@ -0,0 +1,64 @@
+//===-- Unittests for ctime_r 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "src/errno/libc_errno.h"
+#include "src/time/ctime_r.h"
+#include "src/time/time_utils.h"
+#include "test/UnitTest/Test.h"
+#include "test/src/time/TmHelper.h"
+
+using LIBC_NAMESPACE::time_utils::TimeConstants;
+
+// make check-libc LIBC_TEST_TARGET=call_ctime_r VERBOSE=1

zimirza wrote:

This is interesting. I did not know that. I have updated the comments. Thank 
you.

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


[clang] [clang][analyzer] Fix #embed crash (PR #107764)

2024-09-08 Thread Nicolas van Kempen via cfe-commits

https://github.com/nicovank created 
https://github.com/llvm/llvm-project/pull/107764


Fix #107724.


>From a43b9b74ac253c0072498007cf56ed57d8255143 Mon Sep 17 00:00:00 2001
From: Nicolas van Kempen 
Date: Sun, 8 Sep 2024 11:52:28 -0400
Subject: [PATCH] [clang][analyzer] Fix #embed crash

Fix #107724.
---
 clang/lib/StaticAnalyzer/Core/ExprEngine.cpp | 5 +
 clang/test/Analysis/embed.c  | 9 +
 2 files changed, 10 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/Analysis/embed.c

diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
index 315d85319a85a9..fdabba46992b08 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1938,6 +1938,7 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred,
 case Stmt::CXXRewrittenBinaryOperatorClass:
 case Stmt::RequiresExprClass:
 case Expr::CXXParenListInitExprClass:
+case Stmt::EmbedExprClass:
   // Fall through.
 
 // Cases we intentionally don't evaluate, since they don't need
@@ -2440,10 +2441,6 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred,
   Bldr.addNodes(Dst);
   break;
 }
-
-case Stmt::EmbedExprClass:
-  llvm::report_fatal_error("Support for EmbedExpr is not implemented.");
-  break;
   }
 }
 
diff --git a/clang/test/Analysis/embed.c b/clang/test/Analysis/embed.c
new file mode 100644
index 00..7201bb30386fb7
--- /dev/null
+++ b/clang/test/Analysis/embed.c
@@ -0,0 +1,9 @@
+// RUN: %clang_analyze_cc1 -std=c23 
-analyzer-checker=core,debug.ExprInspection -verify %s
+
+// expected-no-diagnostics
+
+int main() {
+const unsigned char SelfBytes[] = {
+#embed "embed.c"
+};
+}

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


[clang] [clang][analyzer] Fix #embed crash (PR #107764)

2024-09-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Nicolas van Kempen (nicovank)


Changes


Fix #107724.


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


2 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Core/ExprEngine.cpp (+1-4) 
- (added) clang/test/Analysis/embed.c (+9) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
index 315d85319a85a9..fdabba46992b08 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1938,6 +1938,7 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred,
 case Stmt::CXXRewrittenBinaryOperatorClass:
 case Stmt::RequiresExprClass:
 case Expr::CXXParenListInitExprClass:
+case Stmt::EmbedExprClass:
   // Fall through.
 
 // Cases we intentionally don't evaluate, since they don't need
@@ -2440,10 +2441,6 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred,
   Bldr.addNodes(Dst);
   break;
 }
-
-case Stmt::EmbedExprClass:
-  llvm::report_fatal_error("Support for EmbedExpr is not implemented.");
-  break;
   }
 }
 
diff --git a/clang/test/Analysis/embed.c b/clang/test/Analysis/embed.c
new file mode 100644
index 00..7201bb30386fb7
--- /dev/null
+++ b/clang/test/Analysis/embed.c
@@ -0,0 +1,9 @@
+// RUN: %clang_analyze_cc1 -std=c23 
-analyzer-checker=core,debug.ExprInspection -verify %s
+
+// expected-no-diagnostics
+
+int main() {
+const unsigned char SelfBytes[] = {
+#embed "embed.c"
+};
+}

``




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


[clang] [clang][analyzer] Fix #embed crash (PR #107764)

2024-09-08 Thread Nicolas van Kempen via cfe-commits

nicovank wrote:

PS: Should this be cherry-picked into 19?

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


[clang] 08085ed - [CodeGen] Avoid repeated hash lookups (NFC) (#107759)

2024-09-08 Thread via cfe-commits

Author: Kazu Hirata
Date: 2024-09-08T09:04:20-07:00
New Revision: 08085eddfdca51f2bcc23945579109d01b730310

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

LOG: [CodeGen] Avoid repeated hash lookups (NFC) (#107759)

Added: 


Modified: 
clang/lib/CodeGen/CoverageMappingGen.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 67a9caf8b4ec4b..07015834bc84f3 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -2595,12 +2595,7 @@ void CoverageMappingModuleGen::emit() {
 }
 
 unsigned CoverageMappingModuleGen::getFileID(FileEntryRef File) {
-  auto It = FileEntries.find(File);
-  if (It != FileEntries.end())
-return It->second;
-  unsigned FileID = FileEntries.size() + 1;
-  FileEntries.insert(std::make_pair(File, FileID));
-  return FileID;
+  return FileEntries.try_emplace(File, FileEntries.size() + 1).first->second;
 }
 
 void CoverageMappingGen::emitCounterMapping(const Decl *D,



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


[clang] [CodeGen] Avoid repeated hash lookups (NFC) (PR #107759)

2024-09-08 Thread Kazu Hirata via cfe-commits

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


[clang] [FrontEnd] Use SetVector (NFC) (PR #107743)

2024-09-08 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`clang-aarch64-sve-vla-2stage` running on `linaro-g3-03` while building `clang` 
at step 11 "build stage 2".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/41/builds/1894


Here is the relevant piece of the build log for the reference

```
Step 11 (build stage 2) failure: 'ninja' (failure)
...
[7829/8665] Building CXX object 
tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-nullify.cpp.o
[7830/8665] Building CXX object 
tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-purity.cpp.o
[7831/8665] Building CXX object 
tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-namelist.cpp.o
[7832/8665] Building CXX object 
tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-stop.cpp.o
[7833/8665] Building CXX object 
tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-if-stmt.cpp.o
[7834/8665] Building CXX object 
tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/program-tree.cpp.o
[7835/8665] Building CXX object 
tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/compute-offsets.cpp.o
[7836/8665] Building CXX object 
tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-io.cpp.o
[7837/8665] Building CXX object 
tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-select-rank.cpp.o
[7838/8665] Building CXX object 
tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/scope.cpp.o
command timed out: 1200 seconds without output running [b'ninja'], attempting 
to kill
process killed by signal 9
program finished with exit code -1
elapsedTime=3320.371399

```



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


[clang] [clang][bytecode] Fix a variable scope problem with continue/break jumps (PR #107738)

2024-09-08 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/107738

>From 17478ebc579cbbaceb9d54ad114b8633112f1f1c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sun, 8 Sep 2024 07:30:40 +0200
Subject: [PATCH] [clang][bytecode] Fix a variable scope problem with
 continue/break jumps

Cleaning up _all_ the scopes is a little too much. Only clean up until
the point here we started the scope relevant for the break/continue
statement.
---
 clang/lib/AST/ByteCode/Compiler.cpp| 20 
 clang/lib/AST/ByteCode/Compiler.h  |  2 ++
 clang/test/AST/ByteCode/new-delete.cpp | 32 +++---
 3 files changed, 37 insertions(+), 17 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 46f9c98d59befc..85ad430d95a5e5 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -114,19 +114,23 @@ template  class LoopScope final : public 
LabelScope {
 
   LoopScope(Compiler *Ctx, LabelTy BreakLabel, LabelTy ContinueLabel)
   : LabelScope(Ctx), OldBreakLabel(Ctx->BreakLabel),
-OldContinueLabel(Ctx->ContinueLabel) {
+OldContinueLabel(Ctx->ContinueLabel),
+OldLabelVarScope(Ctx->LabelVarScope) {
 this->Ctx->BreakLabel = BreakLabel;
 this->Ctx->ContinueLabel = ContinueLabel;
+this->Ctx->LabelVarScope = this->Ctx->VarScope;
   }
 
   ~LoopScope() {
 this->Ctx->BreakLabel = OldBreakLabel;
 this->Ctx->ContinueLabel = OldContinueLabel;
+this->Ctx->LabelVarScope = OldLabelVarScope;
   }
 
 private:
   OptLabelTy OldBreakLabel;
   OptLabelTy OldContinueLabel;
+  VariableScope *OldLabelVarScope;
 };
 
 // Sets the context for a switch scope, mapping labels.
@@ -140,22 +144,26 @@ template  class SwitchScope final : public 
LabelScope {
   OptLabelTy DefaultLabel)
   : LabelScope(Ctx), OldBreakLabel(Ctx->BreakLabel),
 OldDefaultLabel(this->Ctx->DefaultLabel),
-OldCaseLabels(std::move(this->Ctx->CaseLabels)) {
+OldCaseLabels(std::move(this->Ctx->CaseLabels)),
+OldLabelVarScope(Ctx->LabelVarScope) {
 this->Ctx->BreakLabel = BreakLabel;
 this->Ctx->DefaultLabel = DefaultLabel;
 this->Ctx->CaseLabels = std::move(CaseLabels);
+this->Ctx->LabelVarScope = this->Ctx->VarScope;
   }
 
   ~SwitchScope() {
 this->Ctx->BreakLabel = OldBreakLabel;
 this->Ctx->DefaultLabel = OldDefaultLabel;
 this->Ctx->CaseLabels = std::move(OldCaseLabels);
+this->Ctx->LabelVarScope = OldLabelVarScope;
   }
 
 private:
   OptLabelTy OldBreakLabel;
   OptLabelTy OldDefaultLabel;
   CaseMap OldCaseLabels;
+  VariableScope *OldLabelVarScope;
 };
 
 template  class StmtExprScope final {
@@ -4734,7 +4742,9 @@ bool Compiler::visitBreakStmt(const BreakStmt 
*S) {
   if (!BreakLabel)
 return false;
 
-  this->emitCleanup();
+  for (VariableScope *C = VarScope; C != LabelVarScope;
+   C = C->getParent())
+C->emitDestruction();
   return this->jump(*BreakLabel);
 }
 
@@ -4743,7 +4753,9 @@ bool Compiler::visitContinueStmt(const 
ContinueStmt *S) {
   if (!ContinueLabel)
 return false;
 
-  this->emitCleanup();
+  for (VariableScope *C = VarScope; C != LabelVarScope;
+   C = C->getParent())
+C->emitDestruction();
   return this->jump(*ContinueLabel);
 }
 
diff --git a/clang/lib/AST/ByteCode/Compiler.h 
b/clang/lib/AST/ByteCode/Compiler.h
index 39c0736cb4e27e..ac4c08c4d0ffb6 100644
--- a/clang/lib/AST/ByteCode/Compiler.h
+++ b/clang/lib/AST/ByteCode/Compiler.h
@@ -409,6 +409,8 @@ class Compiler : public ConstStmtVisitor, 
bool>,
   /// Switch case mapping.
   CaseMap CaseLabels;
 
+  /// Scope to cleanup until when chumping to one of the labels.
+  VariableScope *LabelVarScope = nullptr;
   /// Point to break to.
   OptLabelTy BreakLabel;
   /// Point to continue to.
diff --git a/clang/test/AST/ByteCode/new-delete.cpp 
b/clang/test/AST/ByteCode/new-delete.cpp
index 902ab4aab10fb5..76858aa94bb37d 100644
--- a/clang/test/AST/ByteCode/new-delete.cpp
+++ b/clang/test/AST/ByteCode/new-delete.cpp
@@ -618,22 +618,28 @@ namespace OperatorNewDelete {
 
   constexpr bool mismatched(int alloc_kind, int dealloc_kind) {
 int *p;
-
-if (alloc_kind == 0)
-  p = new int; // both-note {{allocation performed here}}
-else if (alloc_kind == 1)
-  p = new int[1]; // both-note {{allocation performed here}}
-else if (alloc_kind == 2)
+switch (alloc_kind) {
+case 0:
+  p = new int; // both-note {{heap allocation performed here}}
+  break;
+case 1:
+  p = new int[1]; // both-note {{heap allocation performed here}}
+  break;
+case 2:
   p = std::allocator().allocate(1);
-
-
-if (dealloc_kind == 0)
+  break;
+}
+switch (dealloc_kind) {
+case 0:
   delete p; // both-note {{'delete' used to delete pointer to object 
allocated with 'std::allocator<...>::allocate'}}
-else if (dealloc_kind == 1)
+  break;
+ 

[clang] [FrontEnd] Use SetVector (NFC) (PR #107743)

2024-09-08 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-s390x-linux` running 
on `systemz-1` while building `clang` at step 5 "ninja check 1".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/42/builds/1006


Here is the relevant piece of the build log for the reference

```
Step 5 (ninja check 1) failure: stage 1 checked (failure)
 TEST 'libFuzzer-s390x-default-Linux :: 
fuzzer-timeout.test' FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: 
/home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/./bin/clang
-Wthread-safety -Wthread-safety-reference -Wthread-safety-beta   
--driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer 
-I/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/lib/fuzzer 
 
/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/test/fuzzer/TimeoutTest.cpp
 -o 
/home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest
+ /home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/./bin/clang 
-Wthread-safety -Wthread-safety-reference -Wthread-safety-beta 
--driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer 
-I/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/lib/fuzzer 
/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/test/fuzzer/TimeoutTest.cpp
 -o 
/home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest
RUN: at line 2: 
/home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/./bin/clang
-Wthread-safety -Wthread-safety-reference -Wthread-safety-beta   
--driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer 
-I/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/lib/fuzzer 
 
/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/test/fuzzer/TimeoutEmptyTest.cpp
 -o 
/home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutEmptyTest
+ /home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/./bin/clang 
-Wthread-safety -Wthread-safety-reference -Wthread-safety-beta 
--driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer 
-I/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/lib/fuzzer 
/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/test/fuzzer/TimeoutEmptyTest.cpp
 -o 
/home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutEmptyTest
RUN: at line 3: not  
/home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest
 -timeout=1 2>&1 | FileCheck 
/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/test/fuzzer/fuzzer-timeout.test
 --check-prefix=TimeoutTest
+ not 
/home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest
 -timeout=1
+ FileCheck 
/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/test/fuzzer/fuzzer-timeout.test
 --check-prefix=TimeoutTest
RUN: at line 12: not  
/home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest
 -timeout=1 
/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/test/fuzzer/hi.txt
 2>&1 | FileCheck 
/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/test/fuzzer/fuzzer-timeout.test
 --check-prefix=SingleInputTimeoutTest
+ not 
/home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest
 -timeout=1 
/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/test/fuzzer/hi.txt
+ FileCheck 
/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/test/fuzzer/fuzzer-timeout.test
 --check-prefix=SingleInputTimeoutTest
RUN: at line 16: 
/home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest
 -timeout=1 -timeout_exitcode=0
+ 
/home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest
 -timeout=1 -timeout_exitcode=0
INFO: Running with entropic power schedule (0xFF, 100).
INFO: Seed: 2575301253
INFO: Loaded 1 modules   (13 inline 8-bit counters): 13 [0x2aa041e8e48, 
0x2aa041e8e55), 
INFO: Loaded 1 PC tables (

[clang] fix access checking about function overloading (PR #107768)

2024-09-08 Thread Zhikai Zeng via cfe-commits

https://github.com/Backl1ght created 
https://github.com/llvm/llvm-project/pull/107768

fix https://github.com/llvm/llvm-project/issues/107629

TODO: add UT.
TODO: test UB mentioned in https://github.com/llvm/llvm-project/issues/107629.

>From 65172d8391cef4c0c7e239c9a09b34e061f4963a Mon Sep 17 00:00:00 2001
From: Backl1ght 
Date: Mon, 9 Sep 2024 00:34:31 +0800
Subject: [PATCH] fix

---
 clang/lib/Sema/SemaOverload.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 861b0a91240b3b..fdfa18eff93037 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -16265,6 +16265,7 @@ ExprResult Sema::FixOverloadedFunctionReference(Expr 
*E, DeclAccessPair Found,
   }
 
   if (UnresolvedLookupExpr *ULE = dyn_cast(E)) {
+CheckUnresolvedLookupAccess(ULE, Found);
 // FIXME: avoid copy.
 TemplateArgumentListInfo TemplateArgsBuffer, *TemplateArgs = nullptr;
 if (ULE->hasExplicitTemplateArgs()) {

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


[clang] [Frontend] Use range-based for loops (NFC) (PR #107757)

2024-09-08 Thread Nikita Popov via cfe-commits

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


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


[clang] [APINotes] Avoid repeated hash lookups (NFC) (PR #107758)

2024-09-08 Thread Nikita Popov via cfe-commits

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


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


[clang] 668cbd8 - [Frontend] Use range-based for loops (NFC) (#107757)

2024-09-08 Thread via cfe-commits

Author: Kazu Hirata
Date: 2024-09-08T09:50:34-07:00
New Revision: 668cbd84099c82f9c34e220a019db2f5f50f4320

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

LOG: [Frontend] Use range-based for loops (NFC) (#107757)

Added: 


Modified: 
clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp

Removed: 




diff  --git a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp 
b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
index 326920c7915537..8cdb463e2c99f2 100644
--- a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
+++ b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
@@ -4080,19 +4080,17 @@ std::string 
RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i,
 
   // Create local declarations to avoid rewriting all closure decl ref exprs.
   // First, emit a declaration for all "by ref" decls.
-  for (auto I = BlockByRefDecls.begin(), E = BlockByRefDecls.end(); I != E;
-   ++I) {
+  for (ValueDecl *VD : BlockByRefDecls) {
 S += "  ";
-std::string Name = (*I)->getNameAsString();
+std::string Name = VD->getNameAsString();
 std::string TypeString;
-RewriteByRefString(TypeString, Name, (*I));
+RewriteByRefString(TypeString, Name, VD);
 TypeString += " *";
 Name = TypeString + Name;
-S += Name + " = __cself->" + (*I)->getNameAsString() + "; // bound by 
ref\n";
+S += Name + " = __cself->" + VD->getNameAsString() + "; // bound by ref\n";
   }
   // Next, emit a declaration for all "by copy" declarations.
-  for (auto I = BlockByCopyDecls.begin(), E = BlockByCopyDecls.end(); I != E;
-   ++I) {
+  for (ValueDecl *VD : BlockByCopyDecls) {
 S += "  ";
 // Handle nested closure invocation. For example:
 //
@@ -4104,21 +4102,20 @@ std::string 
RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i,
 // myImportedClosure(); // import and invoke the closure
 //   };
 //
-if (isTopLevelBlockPointerType((*I)->getType())) {
-  RewriteBlockPointerTypeVariable(S, (*I));
+if (isTopLevelBlockPointerType(VD->getType())) {
+  RewriteBlockPointerTypeVariable(S, VD);
   S += " = (";
-  RewriteBlockPointerType(S, (*I)->getType());
+  RewriteBlockPointerType(S, VD->getType());
   S += ")";
-  S += "__cself->" + (*I)->getNameAsString() + "; // bound by copy\n";
-}
-else {
-  std::string Name = (*I)->getNameAsString();
-  QualType QT = (*I)->getType();
-  if (HasLocalVariableExternalStorage(*I))
+  S += "__cself->" + VD->getNameAsString() + "; // bound by copy\n";
+} else {
+  std::string Name = VD->getNameAsString();
+  QualType QT = VD->getType();
+  if (HasLocalVariableExternalStorage(VD))
 QT = Context->getPointerType(QT);
   QT.getAsStringInternal(Name, Context->getPrintingPolicy());
-  S += Name + " = __cself->" +
-  (*I)->getNameAsString() + "; // bound by copy\n";
+  S += Name + " = __cself->" + VD->getNameAsString() +
+   "; // bound by copy\n";
 }
   }
   std::string RewrittenStr = RewrittenBlockExprs[CE];
@@ -4188,10 +4185,9 @@ std::string 
RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE,
 
   if (BlockDeclRefs.size()) {
 // Output all "by copy" declarations.
-for (auto I = BlockByCopyDecls.begin(), E = BlockByCopyDecls.end(); I != E;
- ++I) {
+for (ValueDecl *VD : BlockByCopyDecls) {
   S += "  ";
-  std::string FieldName = (*I)->getNameAsString();
+  std::string FieldName = VD->getNameAsString();
   std::string ArgName = "_" + FieldName;
   // Handle nested closure invocation. For example:
   //
@@ -4203,12 +4199,12 @@ std::string 
RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE,
   // myImportedBlock(); // import and invoke the closure
   //   };
   //
-  if (isTopLevelBlockPointerType((*I)->getType())) {
+  if (isTopLevelBlockPointerType(VD->getType())) {
 S += "struct __block_impl *";
 Constructor += ", void *" + ArgName;
   } else {
-QualType QT = (*I)->getType();
-if (HasLocalVariableExternalStorage(*I))
+QualType QT = VD->getType();
+if (HasLocalVariableExternalStorage(VD))
   QT = Context->getPointerType(QT);
 QT.getAsStringInternal(FieldName, Context->getPrintingPolicy());
 QT.getAsStringInternal(ArgName, Context->getPrintingPolicy());
@@ -4217,14 +4213,13 @@ std::string 
RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE,
   S += FieldName + ";\n";
 }
 // Output all "by ref" declarations.
-for (auto I = BlockByRefDecls.begin(), E = BlockByRefDecls.end(); I != E;
- ++I) {
+for (ValueDecl *VD : BlockByRefDecls) {
   S += "  ";
-  std::string FieldName = (*I)->getNameAsString();
+  

[clang] [Frontend] Use range-based for loops (NFC) (PR #107757)

2024-09-08 Thread Kazu Hirata via cfe-commits

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


[clang] [APINotes] Avoid repeated hash lookups (NFC) (PR #107758)

2024-09-08 Thread Kazu Hirata via cfe-commits

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


[clang] bdb6f1b - [APINotes] Avoid repeated hash lookups (NFC) (#107758)

2024-09-08 Thread via cfe-commits

Author: Kazu Hirata
Date: 2024-09-08T09:50:44-07:00
New Revision: bdb6f1b9d6d6262f1a0f96f410c2702a438a7498

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

LOG: [APINotes] Avoid repeated hash lookups (NFC) (#107758)

Added: 


Modified: 
clang/lib/APINotes/APINotesWriter.cpp

Removed: 




diff  --git a/clang/lib/APINotes/APINotesWriter.cpp 
b/clang/lib/APINotes/APINotesWriter.cpp
index c452677983bb36..2f4e5e803f6a2b 100644
--- a/clang/lib/APINotes/APINotesWriter.cpp
+++ b/clang/lib/APINotes/APINotesWriter.cpp
@@ -147,14 +147,8 @@ class APINotesWriter::Implementation {
 for (auto piece : SelectorRef.Identifiers)
   Selector.Identifiers.push_back(getIdentifier(piece));
 
-// Look for the stored selector.
-auto Known = SelectorIDs.find(Selector);
-if (Known != SelectorIDs.end())
-  return Known->second;
-
-// Add to the selector table.
-Known = SelectorIDs.insert({Selector, SelectorIDs.size()}).first;
-return Known->second;
+// Look for the stored selector.  Add to the selector table if missing.
+return SelectorIDs.try_emplace(Selector, SelectorIDs.size()).first->second;
   }
 
 private:



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


[clang] 6f67c38 - [clang][bytecode] Fix a variable scope problem with continue/break jumps (#107738)

2024-09-08 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-09-08T19:22:18+02:00
New Revision: 6f67c386845be85cfcbf5c90949edcdaf40a0ef7

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

LOG: [clang][bytecode] Fix a variable scope problem with continue/break jumps 
(#107738)

Cleaning up _all_ the scopes is a little too much. Only clean up until
the point here we started the scope relevant for the break/continue
statement.

Added: 


Modified: 
clang/lib/AST/ByteCode/Compiler.cpp
clang/lib/AST/ByteCode/Compiler.h
clang/test/AST/ByteCode/new-delete.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 43268bafc387bd..fddd6db4f4814c 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -114,19 +114,23 @@ template  class LoopScope final : public 
LabelScope {
 
   LoopScope(Compiler *Ctx, LabelTy BreakLabel, LabelTy ContinueLabel)
   : LabelScope(Ctx), OldBreakLabel(Ctx->BreakLabel),
-OldContinueLabel(Ctx->ContinueLabel) {
+OldContinueLabel(Ctx->ContinueLabel),
+OldLabelVarScope(Ctx->LabelVarScope) {
 this->Ctx->BreakLabel = BreakLabel;
 this->Ctx->ContinueLabel = ContinueLabel;
+this->Ctx->LabelVarScope = this->Ctx->VarScope;
   }
 
   ~LoopScope() {
 this->Ctx->BreakLabel = OldBreakLabel;
 this->Ctx->ContinueLabel = OldContinueLabel;
+this->Ctx->LabelVarScope = OldLabelVarScope;
   }
 
 private:
   OptLabelTy OldBreakLabel;
   OptLabelTy OldContinueLabel;
+  VariableScope *OldLabelVarScope;
 };
 
 // Sets the context for a switch scope, mapping labels.
@@ -140,22 +144,26 @@ template  class SwitchScope final : public 
LabelScope {
   OptLabelTy DefaultLabel)
   : LabelScope(Ctx), OldBreakLabel(Ctx->BreakLabel),
 OldDefaultLabel(this->Ctx->DefaultLabel),
-OldCaseLabels(std::move(this->Ctx->CaseLabels)) {
+OldCaseLabels(std::move(this->Ctx->CaseLabels)),
+OldLabelVarScope(Ctx->LabelVarScope) {
 this->Ctx->BreakLabel = BreakLabel;
 this->Ctx->DefaultLabel = DefaultLabel;
 this->Ctx->CaseLabels = std::move(CaseLabels);
+this->Ctx->LabelVarScope = this->Ctx->VarScope;
   }
 
   ~SwitchScope() {
 this->Ctx->BreakLabel = OldBreakLabel;
 this->Ctx->DefaultLabel = OldDefaultLabel;
 this->Ctx->CaseLabels = std::move(OldCaseLabels);
+this->Ctx->LabelVarScope = OldLabelVarScope;
   }
 
 private:
   OptLabelTy OldBreakLabel;
   OptLabelTy OldDefaultLabel;
   CaseMap OldCaseLabels;
+  VariableScope *OldLabelVarScope;
 };
 
 template  class StmtExprScope final {
@@ -4752,7 +4760,9 @@ bool Compiler::visitBreakStmt(const BreakStmt 
*S) {
   if (!BreakLabel)
 return false;
 
-  this->emitCleanup();
+  for (VariableScope *C = VarScope; C != LabelVarScope;
+   C = C->getParent())
+C->emitDestruction();
   return this->jump(*BreakLabel);
 }
 
@@ -4761,7 +4771,9 @@ bool Compiler::visitContinueStmt(const 
ContinueStmt *S) {
   if (!ContinueLabel)
 return false;
 
-  this->emitCleanup();
+  for (VariableScope *C = VarScope; C != LabelVarScope;
+   C = C->getParent())
+C->emitDestruction();
   return this->jump(*ContinueLabel);
 }
 

diff  --git a/clang/lib/AST/ByteCode/Compiler.h 
b/clang/lib/AST/ByteCode/Compiler.h
index 39c0736cb4e27e..ac4c08c4d0ffb6 100644
--- a/clang/lib/AST/ByteCode/Compiler.h
+++ b/clang/lib/AST/ByteCode/Compiler.h
@@ -409,6 +409,8 @@ class Compiler : public ConstStmtVisitor, 
bool>,
   /// Switch case mapping.
   CaseMap CaseLabels;
 
+  /// Scope to cleanup until when chumping to one of the labels.
+  VariableScope *LabelVarScope = nullptr;
   /// Point to break to.
   OptLabelTy BreakLabel;
   /// Point to continue to.

diff  --git a/clang/test/AST/ByteCode/new-delete.cpp 
b/clang/test/AST/ByteCode/new-delete.cpp
index 902ab4aab10fb5..76858aa94bb37d 100644
--- a/clang/test/AST/ByteCode/new-delete.cpp
+++ b/clang/test/AST/ByteCode/new-delete.cpp
@@ -618,22 +618,28 @@ namespace OperatorNewDelete {
 
   constexpr bool mismatched(int alloc_kind, int dealloc_kind) {
 int *p;
-
-if (alloc_kind == 0)
-  p = new int; // both-note {{allocation performed here}}
-else if (alloc_kind == 1)
-  p = new int[1]; // both-note {{allocation performed here}}
-else if (alloc_kind == 2)
+switch (alloc_kind) {
+case 0:
+  p = new int; // both-note {{heap allocation performed here}}
+  break;
+case 1:
+  p = new int[1]; // both-note {{heap allocation performed here}}
+  break;
+case 2:
   p = std::allocator().allocate(1);
-
-
-if (dealloc_kind == 0)
+  break;
+}
+switch (dealloc_kind) {
+case 0:
   delete p; // both-note {{'delete' used to delete pointer to object 
allocated with 'std::all

[clang] [clang][bytecode] Fix a variable scope problem with continue/break jumps (PR #107738)

2024-09-08 Thread Timm Baeder via cfe-commits

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


[clang] [llvm] [TableGen] Change SetTheory set/vec to use const Record * (PR #107692)

2024-09-08 Thread Rahul Joshi via cfe-commits

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


[clang] [llvm] [TableGen] Change SetTheory set/vec to use const Record * (PR #107692)

2024-09-08 Thread Rahul Joshi via cfe-commits


@@ -2808,10 +2806,10 @@ RecordRecTy *Record::getType() {
   return RecordRecTy::get(TrackedRecords, DirectSCs);
 }
 
-DefInit *Record::getDefInit() {
+DefInit *Record::getDefInit() const {
   if (!CorrespondingDefInit) {
-CorrespondingDefInit =
-new (TrackedRecords.getImpl().Allocator) DefInit(this);
+CorrespondingDefInit = new (TrackedRecords.getImpl().Allocator)
+DefInit(const_cast(this));

jurahul wrote:

The only issue/smell is here, where CodeGenDAGPatterns.cpp and 
CodeGenRegisters.cpp call DefInit::get() on the result of a SetTheory::expand() 
returned record (which is now const *). I looked a little bit to see what they 
are doing, but decided to "cut off" the change here to keep it smaller. This is 
part of effort to have better const correctness w.r.t records and recordkeeper, 
so with this, the "smell" is atleast localized to this function and we can have 
const records otherwise.

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


[clang] [llvm] [TableGen] Change SetTheory set/vec to use const Record * (PR #107692)

2024-09-08 Thread Rahul Joshi via cfe-commits


@@ -2808,10 +2806,10 @@ RecordRecTy *Record::getType() {
   return RecordRecTy::get(TrackedRecords, DirectSCs);
 }
 
-DefInit *Record::getDefInit() {
+DefInit *Record::getDefInit() const {
   if (!CorrespondingDefInit) {
-CorrespondingDefInit =
-new (TrackedRecords.getImpl().Allocator) DefInit(this);
+CorrespondingDefInit = new (TrackedRecords.getImpl().Allocator)
+DefInit(const_cast(this));

jurahul wrote:

I did look into making the Def pointer in DefInit const. It's possible, but 
will spawn a bunch of other changes, so best done as a separate PR. I also 
checked if we can always instantiate the `CorrespondingDefInit` when a new 
Record is added to the `RecordKeeper` when parsing, it seems only a small 
fraction of Records have CorrespondingDefInit set to non-null (measured in 
RecordKeeper destructor) so unconditionally populating CorrespondingDefInit 
will likely cause memory footprint increase. So this seems like a reasonable 
thing, and will be followed by removing the const_cast<> (but 
CorrespondingDefInit will stay mutable, its like a cache).

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


[clang] [clang][Frontend] Fix Sema::PerformImplicitConversion for atomic expressions (PR #107773)

2024-09-08 Thread Daniel Petrovic via cfe-commits

https://github.com/daniel-petrovic created 
https://github.com/llvm/llvm-project/pull/107773

Fixes #106576 

In `Sema::PerformImplicitConversion` for standard conversion sequence the 
NonAtomicToAtomic conversion is not reverted back after 3.rd conversion step if 
not starting from scalar initially.

This solves this issue and also other issues  like e.g. returning r-value 
atomic expressions where AtomicToNonAtomic conversion should also normally 
occur.

Basically this means that atomicity is stripped after lvalue to rvalue 
conversoin of an atomic expression.



>From 3ab605f2d939130d973892d21e538631cebb42bc Mon Sep 17 00:00:00 2001
From: Daniel Petrovic 
Date: Sun, 8 Sep 2024 21:29:57 +0200
Subject: [PATCH] [clang][Frontend] Fix Sema::PerformImplicitConversion for
 atomic expressions

---
 clang/lib/Sema/SemaExprCXX.cpp |  6 +-
 clang/test/Sema/atomic-expr.c  | 17 +
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 746c67ff1e979f..24d0df132d6648 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -4393,6 +4393,10 @@ Sema::PerformImplicitConversion(Expr *From, QualType 
ToType,
 ToType = ToAtomic->getValueType();
   }
 
+  // Save the initial `atomicity` information of the From-expression for later 
check
+  // before it's potentially removed in the StandardConversionSequence steps 
1-3.
+  const AtomicType* StartingFromAtomic = From->getType()->getAs();
+
   QualType InitialFromType = FromType;
   // Perform the first implicit conversion.
   switch (SCS.First) {
@@ -4918,7 +4922,7 @@ Sema::PerformImplicitConversion(Expr *From, QualType 
ToType,
 
   // If this conversion sequence involved a scalar -> atomic conversion, 
perform
   // that conversion now.
-  if (!ToAtomicType.isNull()) {
+  if (!StartingFromAtomic && !ToAtomicType.isNull()) {
 assert(Context.hasSameType(
 ToAtomicType->castAs()->getValueType(), From->getType()));
 From = ImpCastExprToType(From, ToAtomicType, CK_NonAtomicToAtomic,
diff --git a/clang/test/Sema/atomic-expr.c b/clang/test/Sema/atomic-expr.c
index 7e5219dd3f14ab..167de036ae73d6 100644
--- a/clang/test/Sema/atomic-expr.c
+++ b/clang/test/Sema/atomic-expr.c
@@ -227,3 +227,20 @@ void func_19(void) {
   _Atomic int a = 0;
   switch (a) { }
 }
+
+// Test correct implicit conversions of r-value atomic expressions.
+// Bugfix: https://github.com/llvm/llvm-project/issues/106576
+typedef _Atomic char atomic_char;
+atomic_char counter;
+char load_stmtexpr() {
+  return ({counter;});
+}
+char load_plus_one_stmtexpr() {
+  return ({counter;}) + 1;
+}
+char load_cast() {
+  return (atomic_char)('x');
+}
+char load_cast_plus_one() {
+  return (atomic_char)('x') + 1;
+}

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


[clang] [clang][Frontend] Fix Sema::PerformImplicitConversion for atomic expressions (PR #107773)

2024-09-08 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


[clang] [clang][Frontend] Fix Sema::PerformImplicitConversion for atomic expressions (PR #107773)

2024-09-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Daniel Petrovic (daniel-petrovic)


Changes

Fixes #106576 

In `Sema::PerformImplicitConversion` for standard conversion sequence the 
NonAtomicToAtomic conversion is not reverted back after 3.rd conversion step if 
not starting from scalar initially.

This solves this issue and also other issues  like e.g. returning r-value 
atomic expressions where AtomicToNonAtomic conversion should also normally 
occur.

Basically this means that atomicity is stripped after lvalue to rvalue 
conversoin of an atomic expression.



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


2 Files Affected:

- (modified) clang/lib/Sema/SemaExprCXX.cpp (+5-1) 
- (modified) clang/test/Sema/atomic-expr.c (+17) 


``diff
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 746c67ff1e979f..24d0df132d6648 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -4393,6 +4393,10 @@ Sema::PerformImplicitConversion(Expr *From, QualType 
ToType,
 ToType = ToAtomic->getValueType();
   }
 
+  // Save the initial `atomicity` information of the From-expression for later 
check
+  // before it's potentially removed in the StandardConversionSequence steps 
1-3.
+  const AtomicType* StartingFromAtomic = From->getType()->getAs();
+
   QualType InitialFromType = FromType;
   // Perform the first implicit conversion.
   switch (SCS.First) {
@@ -4918,7 +4922,7 @@ Sema::PerformImplicitConversion(Expr *From, QualType 
ToType,
 
   // If this conversion sequence involved a scalar -> atomic conversion, 
perform
   // that conversion now.
-  if (!ToAtomicType.isNull()) {
+  if (!StartingFromAtomic && !ToAtomicType.isNull()) {
 assert(Context.hasSameType(
 ToAtomicType->castAs()->getValueType(), From->getType()));
 From = ImpCastExprToType(From, ToAtomicType, CK_NonAtomicToAtomic,
diff --git a/clang/test/Sema/atomic-expr.c b/clang/test/Sema/atomic-expr.c
index 7e5219dd3f14ab..167de036ae73d6 100644
--- a/clang/test/Sema/atomic-expr.c
+++ b/clang/test/Sema/atomic-expr.c
@@ -227,3 +227,20 @@ void func_19(void) {
   _Atomic int a = 0;
   switch (a) { }
 }
+
+// Test correct implicit conversions of r-value atomic expressions.
+// Bugfix: https://github.com/llvm/llvm-project/issues/106576
+typedef _Atomic char atomic_char;
+atomic_char counter;
+char load_stmtexpr() {
+  return ({counter;});
+}
+char load_plus_one_stmtexpr() {
+  return ({counter;}) + 1;
+}
+char load_cast() {
+  return (atomic_char)('x');
+}
+char load_cast_plus_one() {
+  return (atomic_char)('x') + 1;
+}

``




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


[clang-tools-extra] [clang-tidy] Add `modernize-use-uniform-initializer` check (PR #91124)

2024-09-08 Thread via cfe-commits

https://github.com/AMS21 updated https://github.com/llvm/llvm-project/pull/91124

>From 84c8e546c0826ddcf9c580b9368541670ed05068 Mon Sep 17 00:00:00 2001
From: AMS21 
Date: Tue, 16 Apr 2024 08:56:13 +0200
Subject: [PATCH] [clang-tidy] Add `modernize-use-uniform-initializer` check

Finds usage of C-Style initialization that can be rewritten with
C++-11 uniform initializers.
---
 .../clang-tidy/modernize/CMakeLists.txt   |   1 +
 .../modernize/ModernizeTidyModule.cpp |   3 +
 .../modernize/UseUniformInitializerCheck.cpp  | 320 ++
 .../modernize/UseUniformInitializerCheck.h|  37 ++
 .../clang-tidy/utils/LexerUtils.cpp   |  23 ++
 .../clang-tidy/utils/LexerUtils.h |   4 +
 clang-tools-extra/docs/ReleaseNotes.rst   |   6 +
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../modernize/use-uniform-initializer.rst |  34 ++
 .../modernize/use-uniform-initializer.cpp | 174 ++
 10 files changed, 603 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseUniformInitializerCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseUniformInitializerCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-uniform-initializer.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-uniform-initializer.cpp

diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 4f68c487cac9d4..4ca56cb26bd433 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -48,6 +48,7 @@ add_clang_library(clangTidyModernizeModule
   UseTrailingReturnTypeCheck.cpp
   UseTransparentFunctorsCheck.cpp
   UseUncaughtExceptionsCheck.cpp
+  UseUniformInitializerCheck.cpp
   UseUsingCheck.cpp
 
   LINK_LIBS
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 18607593320635..35fb2bdf042ceb 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -49,6 +49,7 @@
 #include "UseTrailingReturnTypeCheck.h"
 #include "UseTransparentFunctorsCheck.h"
 #include "UseUncaughtExceptionsCheck.h"
+#include "UseUniformInitializerCheck.h"
 #include "UseUsingCheck.h"
 
 using namespace clang::ast_matchers;
@@ -121,6 +122,8 @@ class ModernizeModule : public ClangTidyModule {
 "modernize-use-transparent-functors");
 CheckFactories.registerCheck(
 "modernize-use-uncaught-exceptions");
+CheckFactories.registerCheck(
+"modernize-use-uniform-initializer");
 CheckFactories.registerCheck("modernize-use-using");
   }
 };
diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseUniformInitializerCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseUniformInitializerCheck.cpp
new file mode 100644
index 00..204a42d8c81895
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseUniformInitializerCheck.cpp
@@ -0,0 +1,320 @@
+//===--- UseUniformInitializerCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseUniformInitializerCheck.h"
+#include "../utils/LexerUtils.h"
+#include "clang/Tooling/FixIt.h"
+
+AST_MATCHER(clang::VarDecl, isVarOldStyleInitializer) {
+  // If it doesn't have any initializer the initializer style is not defined.
+  if (!Node.hasInit())
+return false;
+
+  const clang::VarDecl::InitializationStyle InitStyle = Node.getInitStyle();
+
+  return InitStyle == clang::VarDecl::InitializationStyle::CInit ||
+ InitStyle == clang::VarDecl::InitializationStyle::CallInit;
+}
+
+AST_MATCHER(clang::FieldDecl, isFieldOldStyleInitializer) {
+  // If it doesn't have any initializer the initializer style is not defined.
+  if (!Node.hasInClassInitializer() || Node.getInClassInitializer() == nullptr)
+return false;
+
+  const clang::InClassInitStyle InitStyle = Node.getInClassInitStyle();
+
+  return InitStyle == clang::InClassInitStyle::ICIS_CopyInit;
+}
+
+AST_MATCHER(clang::CXXCtorInitializer, isCStyleInitializer) {
+  const clang::Expr *Init = Node.getInit();
+  if (Init == nullptr)
+return false;
+
+  return !llvm::isa(Init);
+}
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+namespace {
+
+constexpr const StringRef VarDeclID = "VarDecl";
+constexpr const StringRef FieldDeclId = "FieldDecl";
+constexpr const StringRef CtorInitID = "CtorInit";
+
+constexpr const StringRef CStyleWarningMessage =
+"Use uniform initializer instead of C-style initializer";
+
+constexpr StringR

[clang] [lld] [llvm] [clang][MIPS] Add support for mipsel-windows-* targets (PR #107744)

2024-09-08 Thread via cfe-commits
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau 
Message-ID:
In-Reply-To: 


https://github.com/hpoussin updated 
https://github.com/llvm/llvm-project/pull/107744

>From 193f3d3d60c2c9742db50dcb47d689b7968b08d9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= 
Date: Sun, 22 Oct 2023 07:19:08 +0200
Subject: [PATCH 01/13] [Triple] Make mipsel-*-windows-* use COFF files by
 default

Windows NT/MIPS and Windows CE/MIPS always used COFF format.
---
 llvm/lib/TargetParser/Triple.cpp   | 6 +-
 llvm/unittests/TargetParser/TripleTest.cpp | 3 +++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 55911a7d71ac70..18e2d4fa465f8f 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -905,7 +905,6 @@ static Triple::ObjectFormatType getDefaultFormat(const 
Triple &T) {
   case Triple::mips64:
   case Triple::mips64el:
   case Triple::mips:
-  case Triple::mipsel:
   case Triple::msp430:
   case Triple::nvptx64:
   case Triple::nvptx:
@@ -930,6 +929,11 @@ static Triple::ObjectFormatType getDefaultFormat(const 
Triple &T) {
   case Triple::xtensa:
 return Triple::ELF;
 
+  case Triple::mipsel:
+if (T.isOSWindows())
+  return Triple::COFF;
+return Triple::ELF;
+
   case Triple::ppc64:
   case Triple::ppc:
 if (T.isOSAIX())
diff --git a/llvm/unittests/TargetParser/TripleTest.cpp 
b/llvm/unittests/TargetParser/TripleTest.cpp
index 0aecfc64da2080..1beb52088941e9 100644
--- a/llvm/unittests/TargetParser/TripleTest.cpp
+++ b/llvm/unittests/TargetParser/TripleTest.cpp
@@ -2302,6 +2302,9 @@ TEST(TripleTest, NormalizeWindows) {
 Triple::normalize("i686-pc-windows-elf-elf"));
 
   EXPECT_TRUE(Triple("x86_64-pc-win32").isWindowsMSVCEnvironment());
+
+  
EXPECT_TRUE(Triple(Triple::normalize("mipsel-windows-msvccoff")).isOSBinFormatCOFF());
+  
EXPECT_TRUE(Triple(Triple::normalize("mipsel-windows-msvc")).isOSBinFormatCOFF());
 }
 
 TEST(TripleTest, NormalizeAndroid) {

>From f99b2ea9f3f744500acaab0c05a346250e0e7751 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= 
Date: Sun, 22 Oct 2023 07:30:37 +0200
Subject: [PATCH 02/13] [COFF] Add MIPS relocation types

Add the MIPS COFF relocation types. They will be needed to add support for
MIPS Windows object file.
---
 llvm/include/llvm/BinaryFormat/COFF.h | 18 ++
 llvm/lib/Object/COFFObjectFile.cpp| 21 +
 2 files changed, 39 insertions(+)

diff --git a/llvm/include/llvm/BinaryFormat/COFF.h 
b/llvm/include/llvm/BinaryFormat/COFF.h
index 3fc543f73c49db..bbc5264d17872a 100644
--- a/llvm/include/llvm/BinaryFormat/COFF.h
+++ b/llvm/include/llvm/BinaryFormat/COFF.h
@@ -417,6 +417,24 @@ enum RelocationTypesARM64 : unsigned {
   IMAGE_REL_ARM64_REL32 = 0x0011,
 };
 
+enum RelocationTypesMips : unsigned {
+  IMAGE_REL_MIPS_ABSOLUTE = 0x,
+  IMAGE_REL_MIPS_REFHALF = 0x0001,
+  IMAGE_REL_MIPS_REFWORD = 0x0002,
+  IMAGE_REL_MIPS_JMPADDR = 0x0003,
+  IMAGE_REL_MIPS_REFHI = 0x0004,
+  IMAGE_REL_MIPS_REFLO = 0x0005,
+  IMAGE_REL_MIPS_GPREL = 0x0006,
+  IMAGE_REL_MIPS_LITERAL = 0x0007,
+  IMAGE_REL_MIPS_SECTION = 0x000A,
+  IMAGE_REL_MIPS_SECREL = 0x000B,
+  IMAGE_REL_MIPS_SECRELLO = 0x000C,
+  IMAGE_REL_MIPS_SECRELHI = 0x000D,
+  IMAGE_REL_MIPS_JMPADDR16 = 0x0010,
+  IMAGE_REL_MIPS_REFWORDNB = 0x0022,
+  IMAGE_REL_MIPS_PAIR = 0x0025,
+};
+
 enum DynamicRelocationType : unsigned {
   IMAGE_DYNAMIC_RELOCATION_GUARD_RF_PROLOGUE = 1,
   IMAGE_DYNAMIC_RELOCATION_GUARD_RF_EPILOGUE = 2,
diff --git a/llvm/lib/Object/COFFObjectFile.cpp 
b/llvm/lib/Object/COFFObjectFile.cpp
index 5fdf3baf8c02cc..f55138bb23907a 100644
--- a/llvm/lib/Object/COFFObjectFile.cpp
+++ b/llvm/lib/Object/COFFObjectFile.cpp
@@ -1465,6 +1465,27 @@ StringRef COFFObjectFile::getRelocationTypeName(uint16_t 
Type) const {
   return "Unknown";
 }
 break;
+  case Triple::mipsel:
+switch (Type) {
+LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_ABSOLUTE);
+LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_REFHALF);
+LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_REFWORD);
+LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_JMPADDR);
+LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_REFHI);
+LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_REFLO);
+LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_GPREL);
+LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_LITERAL);
+LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_SECTION);
+LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_SECREL);
+LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_SECRELLO);
+LLVM

[clang] [clang][Frontend] Fix Sema::PerformImplicitConversion for atomic expressions (PR #107773)

2024-09-08 Thread Daniel Petrovic via cfe-commits

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


[clang] [lld] [llvm] [clang][MIPS] Add support for mipsel-windows-* targets (PR #107744)

2024-09-08 Thread Martin Storsjö via cfe-commits

mstorsjo wrote:

Overall, thanks for the PR - this looks very exciting to me!

First off, I think it'd be good to set the scope for this. This is one of the 
historical Windows architectures, supported in early versions of NT and CE. As 
such, it probably has mostly hobbyist value at this point. However that 
shouldn't really be an issue for LLVM - I don't foresee this to add very much 
maintainance burden (as this isn't a new target per se, but mostly scattered 
COFF specific conditions), and is quite interesting for Windows target 
completeness. The main extra "burden" may be that people interested in testing 
all Windows configurations now should enable another target backend.

As for getting changes properly reviewed and merged; within LLVM, each PR, once 
merged, results in one commit. So for a longer patch series like this, one 
would need to do some sort of set of stacked PRs. (Or as a simpler version, one 
can make one branch per commit, i.e. one for commit 1, one for commits 1+2, one 
for commits 1+2+3 etc, and just point out the dependencies in each PR.)

In practice, I guess we can do some sort of pre-review within this PR, and for 
the commits that look fine, you can file individual PRs, avoiding needing to 
have 13 outstanding stacked PRs at once.

CCing a couple people who may be interested in commenting on things, @rnk 
@zmodem @cjacek @efriedma-quic.

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


[clang] Updated and renamed README.txt to README.md (PR #106198)

2024-09-08 Thread Tarık Çelik via cfe-commits

tarik-celik wrote:

Ping

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


[clang] [lld] [llvm] [clang][MIPS] Add support for mipsel-windows-* targets (PR #107744)

2024-09-08 Thread via cfe-commits
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau ,
=?utf-8?q?Hervé?= Poussineau 
Message-ID:
In-Reply-To: 


hpoussin wrote:

I need a little bit help to understand why Linux buildbot succeeds, while 
Windows one fails.

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


[clang] [clang][Frontend] Fix Sema::PerformImplicitConversion for atomic expressions (PR #107773)

2024-09-08 Thread Daniel Petrovic via cfe-commits

https://github.com/daniel-petrovic updated 
https://github.com/llvm/llvm-project/pull/107773

>From 20f065d70ab4ff8b3f77b53db6ce6cf1033e00aa Mon Sep 17 00:00:00 2001
From: Daniel Petrovic 
Date: Sun, 8 Sep 2024 21:29:57 +0200
Subject: [PATCH] [clang][Frontend] Fix Sema::PerformImplicitConversion for
 atomic expressions

---
 clang/lib/Sema/SemaExprCXX.cpp   |  6 +-
 clang/test/Sema/atomic-expr-rvalue.c | 23 +++
 2 files changed, 28 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Sema/atomic-expr-rvalue.c

diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 746c67ff1e979f..24d0df132d6648 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -4393,6 +4393,10 @@ Sema::PerformImplicitConversion(Expr *From, QualType 
ToType,
 ToType = ToAtomic->getValueType();
   }
 
+  // Save the initial `atomicity` information of the From-expression for later 
check
+  // before it's potentially removed in the StandardConversionSequence steps 
1-3.
+  const AtomicType* StartingFromAtomic = From->getType()->getAs();
+
   QualType InitialFromType = FromType;
   // Perform the first implicit conversion.
   switch (SCS.First) {
@@ -4918,7 +4922,7 @@ Sema::PerformImplicitConversion(Expr *From, QualType 
ToType,
 
   // If this conversion sequence involved a scalar -> atomic conversion, 
perform
   // that conversion now.
-  if (!ToAtomicType.isNull()) {
+  if (!StartingFromAtomic && !ToAtomicType.isNull()) {
 assert(Context.hasSameType(
 ToAtomicType->castAs()->getValueType(), From->getType()));
 From = ImpCastExprToType(From, ToAtomicType, CK_NonAtomicToAtomic,
diff --git a/clang/test/Sema/atomic-expr-rvalue.c 
b/clang/test/Sema/atomic-expr-rvalue.c
new file mode 100644
index 00..8314afd9ecb051
--- /dev/null
+++ b/clang/test/Sema/atomic-expr-rvalue.c
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify
+// expected-no-diagnostics
+
+typedef _Atomic char atomic_char;
+atomic_char counter;
+
+// Check correct implicit conversions of r-value atomic expressions.
+// Bugfix: https://github.com/llvm/llvm-project/issues/106576
+char load_plus_one_stmtexpr() {
+  return ({counter;}) + 1;
+}
+
+char load_stmtexpr() {
+  return ({counter;});
+}
+
+char load_cast_plus_one() {
+  return (atomic_char)('x') + 1;
+}
+
+char load_cast() {
+  return (atomic_char)('x');
+}

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


[clang] [analyzer] Remove overzealous "No dispatcher registered" assertion (PR #107294)

2024-09-08 Thread via cfe-commits


@@ -0,0 +1,10 @@
+// RUN: %clang_analyze_cc1 -w -analyzer-checker=nullability \
+// RUN:   -analyzer-output=text -verify %s
+//
+// expected-no-diagnostics
+//
+// This case previously crashed because of an assert in CheckerManager.cpp,
+// checking for registered event dispatchers. This check is too strict so
+// was removed by this commit. This test case covers the previous crash,
+// and is expected to simply not crash. The source file can be anything,
+// and does not need to be empty.

vabridgers wrote:

I resolved this with the latest update. 

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


[clang] [analyzer] Remove overzealous "No dispatcher registered" assertion (PR #107294)

2024-09-08 Thread via cfe-commits


@@ -48,15 +48,7 @@ bool CheckerManager::hasPathSensitiveCheckers() const {
   EvalCallCheckers, EndOfTranslationUnitCheckers);
 }
 
-void CheckerManager::finishedCheckerRegistration() {
-#ifndef NDEBUG
-  // Make sure that for every event that has listeners, there is at least
-  // one dispatcher registered for it.
-  for (const auto &Event : Events)
-assert(Event.second.HasDispatcher &&
-   "No dispatcher registered for an event");
-#endif
-}
+void CheckerManager::finishedCheckerRegistration() {}

vabridgers wrote:

I resolved this comment with the latest update. 

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


[clang] [Clang] prevent recovery call expression from proceeding with explicit attributes and undeclared templates (PR #107786)

2024-09-08 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk created 
https://github.com/llvm/llvm-project/pull/107786

Fixes #107047
Fixes #49093

>From b50e49be3765c31b1c555384c41e1f528d529a88 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Mon, 9 Sep 2024 02:30:35 +0300
Subject: [PATCH] [Clang] prevent recovery call expression from proceeding with
 explicit attributes and undeclared templates

---
 clang/docs/ReleaseNotes.rst   |  3 +-
 clang/lib/Sema/SemaTemplate.cpp   |  6 
 .../SemaTemplate/recovery-crash-cxx20.cpp | 32 +++
 3 files changed, 40 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaTemplate/recovery-crash-cxx20.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f7c3194c91fa31..f96045c57e7a0d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -376,8 +376,9 @@ Bug Fixes to C++ Support
 - Fixed a bug in the substitution of empty pack indexing types. (#GH105903)
 - Clang no longer tries to capture non-odr used default arguments of template 
parameters of generic lambdas (#GH107048)
 - Fixed a bug where defaulted comparison operators would remove ``const`` from 
base classes. (#GH102588)
-
 - Fix a crash when using ``source_location`` in the trailing return type of a 
lambda expression. (#GH67134)
+- Fixed an assertion failure when invoking recovery call expressions with 
explicit attributes
+  and undeclared templates. (#GH107047, #GH49093)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 513f83146fb59e..1ec6219bbd6ea8 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -4458,6 +4458,12 @@ ExprResult Sema::BuildTemplateIdExpr(const CXXScopeSpec 
&SS,
   R.getAsSingle(), TemplateArgs);
   }
 
+  if (TemplateArgs && R.getAsSingle()) {
+if (R.getAsSingle()->getTemplateSpecializationKind() ==
+TemplateSpecializationKind::TSK_Undeclared)
+  return ExprError();
+  }
+
   // We don't want lookup warnings at this point.
   R.suppressDiagnostics();
 
diff --git a/clang/test/SemaTemplate/recovery-crash-cxx20.cpp 
b/clang/test/SemaTemplate/recovery-crash-cxx20.cpp
new file mode 100644
index 00..dd92ddcd36ab02
--- /dev/null
+++ b/clang/test/SemaTemplate/recovery-crash-cxx20.cpp
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+
+namespace GH49093 {
+  class B {
+  public:
+static int a() { return 0; } // expected-note {{member is declared here}}
+decltype(a< 0 >(0)) test;// expected-error {{member 'a' used before 
its declaration}}
+  };
+
+  struct C {
+  static int a() { return 0; } // expected-note {{member is declared here}}
+  decltype(a < 0 > (0)) test;  // expected-error {{member 'a' used before 
its declaration}}
+  };
+
+  void test_is_bool(bool t) {}
+  void test_is_bool(int t) {}
+
+  int main() {
+B b;
+test_is_bool(b.test);
+
+C c;
+test_is_bool(c.test);
+  }
+}
+
+namespace GH107047 {
+  struct A {
+static constexpr auto test() { return 1; } // expected-note {{member is 
declared here}}
+static constexpr int s = test< 1 >();  // expected-error {{member 
'test' used before its declaration}}
+  };
+}

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


[clang] [Clang] prevent recovery call expression from proceeding with explicit attributes and undeclared templates (PR #107786)

2024-09-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Oleksandr T. (a-tarasyuk)


Changes

Fixes #107047
Fixes #49093

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2-1) 
- (modified) clang/lib/Sema/SemaTemplate.cpp (+6) 
- (added) clang/test/SemaTemplate/recovery-crash-cxx20.cpp (+32) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f7c3194c91fa31..f96045c57e7a0d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -376,8 +376,9 @@ Bug Fixes to C++ Support
 - Fixed a bug in the substitution of empty pack indexing types. (#GH105903)
 - Clang no longer tries to capture non-odr used default arguments of template 
parameters of generic lambdas (#GH107048)
 - Fixed a bug where defaulted comparison operators would remove ``const`` from 
base classes. (#GH102588)
-
 - Fix a crash when using ``source_location`` in the trailing return type of a 
lambda expression. (#GH67134)
+- Fixed an assertion failure when invoking recovery call expressions with 
explicit attributes
+  and undeclared templates. (#GH107047, #GH49093)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 513f83146fb59e..1ec6219bbd6ea8 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -4458,6 +4458,12 @@ ExprResult Sema::BuildTemplateIdExpr(const CXXScopeSpec 
&SS,
   R.getAsSingle(), TemplateArgs);
   }
 
+  if (TemplateArgs && R.getAsSingle()) {
+if (R.getAsSingle()->getTemplateSpecializationKind() ==
+TemplateSpecializationKind::TSK_Undeclared)
+  return ExprError();
+  }
+
   // We don't want lookup warnings at this point.
   R.suppressDiagnostics();
 
diff --git a/clang/test/SemaTemplate/recovery-crash-cxx20.cpp 
b/clang/test/SemaTemplate/recovery-crash-cxx20.cpp
new file mode 100644
index 00..dd92ddcd36ab02
--- /dev/null
+++ b/clang/test/SemaTemplate/recovery-crash-cxx20.cpp
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+
+namespace GH49093 {
+  class B {
+  public:
+static int a() { return 0; } // expected-note {{member is declared here}}
+decltype(a< 0 >(0)) test;// expected-error {{member 'a' used before 
its declaration}}
+  };
+
+  struct C {
+  static int a() { return 0; } // expected-note {{member is declared here}}
+  decltype(a < 0 > (0)) test;  // expected-error {{member 'a' used before 
its declaration}}
+  };
+
+  void test_is_bool(bool t) {}
+  void test_is_bool(int t) {}
+
+  int main() {
+B b;
+test_is_bool(b.test);
+
+C c;
+test_is_bool(c.test);
+  }
+}
+
+namespace GH107047 {
+  struct A {
+static constexpr auto test() { return 1; } // expected-note {{member is 
declared here}}
+static constexpr int s = test< 1 >();  // expected-error {{member 
'test' used before its declaration}}
+  };
+}

``




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


[clang] [clang] Improve diagnostics with incompatible VLA types (PR #101261)

2024-09-08 Thread Andrew Sukach via cfe-commits

https://github.com/sookach updated 
https://github.com/llvm/llvm-project/pull/101261

>From 7c6109ea5133941baf32ec57e48c770ad015b883 Mon Sep 17 00:00:00 2001
From: Andrew Sukach 
Date: Tue, 30 Jul 2024 19:31:41 -0400
Subject: [PATCH] [clang] Improve diagnostics with incompatible VLA types

---
 clang/lib/AST/ASTDiagnostic.cpp   | 22 +++
 .../test/Sema/incompatible-vla-assignment.cpp |  9 
 2 files changed, 31 insertions(+)
 create mode 100644 clang/test/Sema/incompatible-vla-assignment.cpp

diff --git a/clang/lib/AST/ASTDiagnostic.cpp b/clang/lib/AST/ASTDiagnostic.cpp
index 0680ff5e3a3851..0f5e8ae600f235 100644
--- a/clang/lib/AST/ASTDiagnostic.cpp
+++ b/clang/lib/AST/ASTDiagnostic.cpp
@@ -422,8 +422,30 @@ void clang::FormatASTNodeDiagnosticArgument(
   // Attempting to do a template diff on non-templates.  Set the variables
   // and continue with regular type printing of the appropriate type.
   Val = TDT.PrintFromType ? TDT.FromType : TDT.ToType;
+
   Modifier = StringRef();
   Argument = StringRef();
+
+  if ((FromType->isVariableArrayType() || FromType->isPointerType()) &&
+  (ToType->isVariableArrayType() || ToType->isPointerType()) &&
+  ConvertTypeToDiagnosticString(Context, FromType, PrevArgs,
+QualTypeVals) ==
+  ConvertTypeToDiagnosticString(Context, ToType, PrevArgs,
+QualTypeVals)) {
+assert(Modifier.empty() && Argument.empty() &&
+   "Invalid modifier for QualType argument");
+
+QualType Ty(QualType::getFromOpaquePtr(reinterpret_cast(Val)));
+OS << ConvertTypeToDiagnosticString(Context, Ty, PrevArgs,
+QualTypeVals);
+NeedQuotes = false;
+
+if (!TDT.PrintFromType)
+  OS << "; VLA types differ despite using the same array size "
+"expression";
+
+break;
+  }
   // Fall through
   [[fallthrough]];
 }
diff --git a/clang/test/Sema/incompatible-vla-assignment.cpp 
b/clang/test/Sema/incompatible-vla-assignment.cpp
new file mode 100644
index 00..9df97a1223150a
--- /dev/null
+++ b/clang/test/Sema/incompatible-vla-assignment.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void func(int n) {
+int grp[n][n];
+int (*ptr)[n];
+
+for (int i = 0; i < n; i++)
+ptr = &grp[i]; // expected-error {{incompatible pointer types 
assigning to 'int (*)[n]' from 'int (*)[n]'; VLA types differ despite using the 
same array size expression}}
+}

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


[clang] [clang][docs] Add clang-tutor to ExternalClangExamples. (PR #107665)

2024-09-08 Thread via cfe-commits

c8ef wrote:

Dear reviewers, if you the patch looks good to you, could you please assist me 
in merging it?
@SimplyDanny @shafik 

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


[clang] [TBAA] Emit "omnipotent char" for intrinsics with type cast (PR #107793)

2024-09-08 Thread via cfe-commits

https://github.com/huhu233 created 
https://github.com/llvm/llvm-project/pull/107793

For the case,
```
  long long res2[SIZE];
  svst1(pa, (long *)&res2[0], v2);
  /* use res2[i] */
```
svst1 is emitted with TBAA metadata for "long", but other users of "res2" use 
"long long", which is a strict aliasing violation and may cause incorrect 
optimization like https://github.com/llvm/llvm-project/issues/97783. The root 
cause is we explictly cast the type of res2 when calling svst1, and the 
compiler emits an improper type. This patch fixes the case by emitting 
"omnipotent char" for intrinsics with type cast.

>From 433a80915de87098093302b57f8554bbf33fdeca Mon Sep 17 00:00:00 2001
From: zhangtiehu 
Date: Tue, 3 Sep 2024 14:43:50 +0800
Subject: [PATCH 1/2] [TBAA] Precommit a test for tbaa enhancement

---
 clang/test/CodeGen/tbaa-sve-store-acle.c | 18 ++
 1 file changed, 18 insertions(+)
 create mode 100644 clang/test/CodeGen/tbaa-sve-store-acle.c

diff --git a/clang/test/CodeGen/tbaa-sve-store-acle.c 
b/clang/test/CodeGen/tbaa-sve-store-acle.c
new file mode 100644
index 00..3a7c49c27e41ca
--- /dev/null
+++ b/clang/test/CodeGen/tbaa-sve-store-acle.c
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -O1  %s 
\
+// RUN: -emit-llvm -o - | FileCheck %s -check-prefix=TBAA
+#include 
+
+// TBAA:store 
+// TBAA:!tbaa ![[TBAA6:[0-9]+]]
+long long sveStoreWithTypeCast(int *datas) {
+  long long res2[16];
+  svbool_t pa = svptrue_b32();
+  svint32_t v1 = svld1(pa, &datas[0]);
+  svint64_t v2 = svunpklo(v1);
+  svst1(pa, (long *)&res2[0], v2);
+  return res2[0] + res2[1];
+}
+
+// TBAA: ![[CHAR:[0-9]+]] = !{!"omnipotent char",
+// TBAA: ![[TBAA6:[0-9]+]] = !{![[LONG:.+]], ![[LONG]], i64 0}
+// TBAA: ![[LONG:[0-9]+]] = !{!"long", ![[CHAR]], i64 0}

>From dbe0528ad1599a0ed89929647bec5f7b7118e1b3 Mon Sep 17 00:00:00 2001
From: zhangtiehu 
Date: Mon, 2 Sep 2024 17:45:23 +0800
Subject: [PATCH 2/2] [TBAA] Emit "omnipotent char" for intrinsics with type
 cast

For the case,

  long long res2[SIZE];
  svst1(pa, (long *)&res2[0], v2);
  /* use res2[i] */

svst1 is emitted with TBAA metadata for "long", but other users of
"res2" use "long long", which is a strict aliasing violation and may
cause incorrect optimization like #97783. The root cause is we explictly
cast the type of res2 when calling svst1, and the compiler emits an
improper type. This patch fixes the case by emitting "omnipotent char"
for intrinsics with type cast.
---
 clang/lib/CodeGen/CGBuiltin.cpp  | 10 ++
 clang/lib/CodeGen/CodeGenModule.cpp  |  4 
 clang/lib/CodeGen/CodeGenModule.h|  2 ++
 clang/lib/CodeGen/CodeGenTBAA.cpp|  5 +
 clang/lib/CodeGen/CodeGenTBAA.h  |  2 ++
 clang/test/CodeGen/tbaa-sve-store-acle.c |  3 +--
 6 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index da7a1a55da5313..27fd5ce976bec5 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -10155,6 +10155,11 @@ Value *CodeGenFunction::EmitSVEMaskedLoad(const 
CallExpr *E,
   auto *Load =
   cast(Builder.CreateCall(F, {Predicate, BasePtr}));
   auto TBAAInfo = CGM.getTBAAAccessInfo(LangPTy->getPointeeType());
+  if (auto *CastE = dyn_cast(E->getArg(1))) {
+CastKind CK = CastE->getCastKind();
+if (CK == CK_BitCast)
+  TBAAInfo = CGM.genConservativeTBAA(LangPTy->getPointeeType());
+  }
   CGM.DecorateInstructionWithTBAA(Load, TBAAInfo);
 
   if (IsQuadLoad)
@@ -10207,6 +10212,11 @@ Value *CodeGenFunction::EmitSVEMaskedStore(const 
CallExpr *E,
   auto *Store =
   cast(Builder.CreateCall(F, {Val, Predicate, 
BasePtr}));
   auto TBAAInfo = CGM.getTBAAAccessInfo(LangPTy->getPointeeType());
+  if (auto *CastE = dyn_cast(E->getArg(1))) {
+CastKind CK = CastE->getCastKind();
+if (CK == CK_BitCast)
+  TBAAInfo = CGM.genConservativeTBAA(LangPTy->getPointeeType());
+  }
   CGM.DecorateInstructionWithTBAA(Store, TBAAInfo);
   return Store;
 }
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index df4c13c9ad97aa..7c25591d08a92a 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1499,6 +1499,10 @@ TBAAAccessInfo CodeGenModule::getTBAAAccessInfo(QualType 
AccessType) {
   return TBAA->getAccessInfo(AccessType);
 }
 
+TBAAAccessInfo CodeGenModule::genConservativeTBAA(QualType AccessType) {
+  return TBAA->genConservativeTBAA(AccessType);
+}
+
 TBAAAccessInfo
 CodeGenModule::getTBAAVTablePtrAccessInfo(llvm::Type *VTablePtrType) {
   if (!TBAA)
diff --git a/clang/lib/CodeGen/CodeGenModule.h 
b/clang/lib/CodeGen/CodeGenModule.h
index c58bb88035ca8a..2c30429850907e 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -811,6 +811,8 @@ class CodeGenModule : public CodeGenTypeCache {
   /// an object of the given type.
   TBAAA

[clang] [TBAA] Emit "omnipotent char" for intrinsics with type cast (PR #107793)

2024-09-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: None (huhu233)


Changes

For the case,
```
  long long res2[SIZE];
  svst1(pa, (long *)&res2[0], v2);
  /* use res2[i] */
```
svst1 is emitted with TBAA metadata for "long", but other users of "res2" use 
"long long", which is a strict aliasing violation and may cause incorrect 
optimization like https://github.com/llvm/llvm-project/issues/97783. The root 
cause is we explictly cast the type of res2 when calling svst1, and the 
compiler emits an improper type. This patch fixes the case by emitting 
"omnipotent char" for intrinsics with type cast.

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


6 Files Affected:

- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+10) 
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+4) 
- (modified) clang/lib/CodeGen/CodeGenModule.h (+2) 
- (modified) clang/lib/CodeGen/CodeGenTBAA.cpp (+5) 
- (modified) clang/lib/CodeGen/CodeGenTBAA.h (+2) 
- (added) clang/test/CodeGen/tbaa-sve-store-acle.c (+17) 


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index da7a1a55da5313..27fd5ce976bec5 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -10155,6 +10155,11 @@ Value *CodeGenFunction::EmitSVEMaskedLoad(const 
CallExpr *E,
   auto *Load =
   cast(Builder.CreateCall(F, {Predicate, BasePtr}));
   auto TBAAInfo = CGM.getTBAAAccessInfo(LangPTy->getPointeeType());
+  if (auto *CastE = dyn_cast(E->getArg(1))) {
+CastKind CK = CastE->getCastKind();
+if (CK == CK_BitCast)
+  TBAAInfo = CGM.genConservativeTBAA(LangPTy->getPointeeType());
+  }
   CGM.DecorateInstructionWithTBAA(Load, TBAAInfo);
 
   if (IsQuadLoad)
@@ -10207,6 +10212,11 @@ Value *CodeGenFunction::EmitSVEMaskedStore(const 
CallExpr *E,
   auto *Store =
   cast(Builder.CreateCall(F, {Val, Predicate, 
BasePtr}));
   auto TBAAInfo = CGM.getTBAAAccessInfo(LangPTy->getPointeeType());
+  if (auto *CastE = dyn_cast(E->getArg(1))) {
+CastKind CK = CastE->getCastKind();
+if (CK == CK_BitCast)
+  TBAAInfo = CGM.genConservativeTBAA(LangPTy->getPointeeType());
+  }
   CGM.DecorateInstructionWithTBAA(Store, TBAAInfo);
   return Store;
 }
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index df4c13c9ad97aa..7c25591d08a92a 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1499,6 +1499,10 @@ TBAAAccessInfo CodeGenModule::getTBAAAccessInfo(QualType 
AccessType) {
   return TBAA->getAccessInfo(AccessType);
 }
 
+TBAAAccessInfo CodeGenModule::genConservativeTBAA(QualType AccessType) {
+  return TBAA->genConservativeTBAA(AccessType);
+}
+
 TBAAAccessInfo
 CodeGenModule::getTBAAVTablePtrAccessInfo(llvm::Type *VTablePtrType) {
   if (!TBAA)
diff --git a/clang/lib/CodeGen/CodeGenModule.h 
b/clang/lib/CodeGen/CodeGenModule.h
index c58bb88035ca8a..2c30429850907e 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -811,6 +811,8 @@ class CodeGenModule : public CodeGenTypeCache {
   /// an object of the given type.
   TBAAAccessInfo getTBAAAccessInfo(QualType AccessType);
 
+  TBAAAccessInfo genConservativeTBAA(QualType AccessType);
+
   /// getTBAAVTablePtrAccessInfo - Get the TBAA information that describes an
   /// access to a virtual table pointer.
   TBAAAccessInfo getTBAAVTablePtrAccessInfo(llvm::Type *VTablePtrType);
diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp 
b/clang/lib/CodeGen/CodeGenTBAA.cpp
index 5b3393ec150e44..be285ba0dbff2a 100644
--- a/clang/lib/CodeGen/CodeGenTBAA.cpp
+++ b/clang/lib/CodeGen/CodeGenTBAA.cpp
@@ -306,6 +306,11 @@ llvm::MDNode *CodeGenTBAA::getTypeInfo(QualType QTy) {
   return MetadataCache[Ty] = TypeNode;
 }
 
+TBAAAccessInfo CodeGenTBAA::genConservativeTBAA(QualType AccessType) {
+  uint64_t Size = Context.getTypeSizeInChars(AccessType).getQuantity();
+  return TBAAAccessInfo(getChar(), Size);
+}
+
 TBAAAccessInfo CodeGenTBAA::getAccessInfo(QualType AccessType) {
   // Pointee values may have incomplete types, but they shall never be
   // dereferenced.
diff --git a/clang/lib/CodeGen/CodeGenTBAA.h b/clang/lib/CodeGen/CodeGenTBAA.h
index ba74a39a4d25ee..de89783bc13e17 100644
--- a/clang/lib/CodeGen/CodeGenTBAA.h
+++ b/clang/lib/CodeGen/CodeGenTBAA.h
@@ -213,6 +213,8 @@ class CodeGenTBAA {
   /// purpose of memory transfer calls.
   TBAAAccessInfo mergeTBAAInfoForMemoryTransfer(TBAAAccessInfo DestInfo,
 TBAAAccessInfo SrcInfo);
+
+  TBAAAccessInfo genConservativeTBAA(QualType AccessType);
 };
 
 }  // end namespace CodeGen
diff --git a/clang/test/CodeGen/tbaa-sve-store-acle.c 
b/clang/test/CodeGen/tbaa-sve-store-acle.c
new file mode 100644
index 00..e9078ecb4370ad
--- /dev/null
+++ b/clang/test/CodeGen/tbaa-sve-store-acle.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -O1  %s 
\
+// RUN: -emit-

[clang] [TBAA] Emit "omnipotent char" for intrinsics with type cast (PR #107793)

2024-09-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (huhu233)


Changes

For the case,
```
  long long res2[SIZE];
  svst1(pa, (long *)&res2[0], v2);
  /* use res2[i] */
```
svst1 is emitted with TBAA metadata for "long", but other users of "res2" use 
"long long", which is a strict aliasing violation and may cause incorrect 
optimization like https://github.com/llvm/llvm-project/issues/97783. The root 
cause is we explictly cast the type of res2 when calling svst1, and the 
compiler emits an improper type. This patch fixes the case by emitting 
"omnipotent char" for intrinsics with type cast.

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


6 Files Affected:

- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+10) 
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+4) 
- (modified) clang/lib/CodeGen/CodeGenModule.h (+2) 
- (modified) clang/lib/CodeGen/CodeGenTBAA.cpp (+5) 
- (modified) clang/lib/CodeGen/CodeGenTBAA.h (+2) 
- (added) clang/test/CodeGen/tbaa-sve-store-acle.c (+17) 


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index da7a1a55da5313..27fd5ce976bec5 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -10155,6 +10155,11 @@ Value *CodeGenFunction::EmitSVEMaskedLoad(const 
CallExpr *E,
   auto *Load =
   cast(Builder.CreateCall(F, {Predicate, BasePtr}));
   auto TBAAInfo = CGM.getTBAAAccessInfo(LangPTy->getPointeeType());
+  if (auto *CastE = dyn_cast(E->getArg(1))) {
+CastKind CK = CastE->getCastKind();
+if (CK == CK_BitCast)
+  TBAAInfo = CGM.genConservativeTBAA(LangPTy->getPointeeType());
+  }
   CGM.DecorateInstructionWithTBAA(Load, TBAAInfo);
 
   if (IsQuadLoad)
@@ -10207,6 +10212,11 @@ Value *CodeGenFunction::EmitSVEMaskedStore(const 
CallExpr *E,
   auto *Store =
   cast(Builder.CreateCall(F, {Val, Predicate, 
BasePtr}));
   auto TBAAInfo = CGM.getTBAAAccessInfo(LangPTy->getPointeeType());
+  if (auto *CastE = dyn_cast(E->getArg(1))) {
+CastKind CK = CastE->getCastKind();
+if (CK == CK_BitCast)
+  TBAAInfo = CGM.genConservativeTBAA(LangPTy->getPointeeType());
+  }
   CGM.DecorateInstructionWithTBAA(Store, TBAAInfo);
   return Store;
 }
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index df4c13c9ad97aa..7c25591d08a92a 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1499,6 +1499,10 @@ TBAAAccessInfo CodeGenModule::getTBAAAccessInfo(QualType 
AccessType) {
   return TBAA->getAccessInfo(AccessType);
 }
 
+TBAAAccessInfo CodeGenModule::genConservativeTBAA(QualType AccessType) {
+  return TBAA->genConservativeTBAA(AccessType);
+}
+
 TBAAAccessInfo
 CodeGenModule::getTBAAVTablePtrAccessInfo(llvm::Type *VTablePtrType) {
   if (!TBAA)
diff --git a/clang/lib/CodeGen/CodeGenModule.h 
b/clang/lib/CodeGen/CodeGenModule.h
index c58bb88035ca8a..2c30429850907e 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -811,6 +811,8 @@ class CodeGenModule : public CodeGenTypeCache {
   /// an object of the given type.
   TBAAAccessInfo getTBAAAccessInfo(QualType AccessType);
 
+  TBAAAccessInfo genConservativeTBAA(QualType AccessType);
+
   /// getTBAAVTablePtrAccessInfo - Get the TBAA information that describes an
   /// access to a virtual table pointer.
   TBAAAccessInfo getTBAAVTablePtrAccessInfo(llvm::Type *VTablePtrType);
diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp 
b/clang/lib/CodeGen/CodeGenTBAA.cpp
index 5b3393ec150e44..be285ba0dbff2a 100644
--- a/clang/lib/CodeGen/CodeGenTBAA.cpp
+++ b/clang/lib/CodeGen/CodeGenTBAA.cpp
@@ -306,6 +306,11 @@ llvm::MDNode *CodeGenTBAA::getTypeInfo(QualType QTy) {
   return MetadataCache[Ty] = TypeNode;
 }
 
+TBAAAccessInfo CodeGenTBAA::genConservativeTBAA(QualType AccessType) {
+  uint64_t Size = Context.getTypeSizeInChars(AccessType).getQuantity();
+  return TBAAAccessInfo(getChar(), Size);
+}
+
 TBAAAccessInfo CodeGenTBAA::getAccessInfo(QualType AccessType) {
   // Pointee values may have incomplete types, but they shall never be
   // dereferenced.
diff --git a/clang/lib/CodeGen/CodeGenTBAA.h b/clang/lib/CodeGen/CodeGenTBAA.h
index ba74a39a4d25ee..de89783bc13e17 100644
--- a/clang/lib/CodeGen/CodeGenTBAA.h
+++ b/clang/lib/CodeGen/CodeGenTBAA.h
@@ -213,6 +213,8 @@ class CodeGenTBAA {
   /// purpose of memory transfer calls.
   TBAAAccessInfo mergeTBAAInfoForMemoryTransfer(TBAAAccessInfo DestInfo,
 TBAAAccessInfo SrcInfo);
+
+  TBAAAccessInfo genConservativeTBAA(QualType AccessType);
 };
 
 }  // end namespace CodeGen
diff --git a/clang/test/CodeGen/tbaa-sve-store-acle.c 
b/clang/test/CodeGen/tbaa-sve-store-acle.c
new file mode 100644
index 00..e9078ecb4370ad
--- /dev/null
+++ b/clang/test/CodeGen/tbaa-sve-store-acle.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -O1  %s 
\
+// RUN: -emit-llvm -o 

[clang] [clang-format] Add new option: WrapNamespaceBodyWithNewlines (PR #106145)

2024-09-08 Thread Owen Pan via cfe-commits

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

Running `FormatTests` failed:
```
[ RUN  ] FormatTest.WrapNamespaceBodyWithEmptyLinesNever
Assertion failed: (TheLine->MatchingClosingBlockLineIndex > 0), function 
tryFitMultipleLinesInOne, file UnwrappedLineFormatter.cpp, line 390.
```

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


[clang] [clang] Support --sysroot= for ${arch}-windows-msvc targets (PR #96417)

2024-09-08 Thread via cfe-commits

https://github.com/trcrsired updated 
https://github.com/llvm/llvm-project/pull/96417

>From 17608570eb2ba6086203f1f8eb20ebafc621caf2 Mon Sep 17 00:00:00 2001
From: trcrsired 
Date: Sun, 23 Jun 2024 00:07:19 -0400
Subject: [PATCH] Support --sysroot= for ${arch}-windows-msvc targets

I think it is possible to use the same rule for msvc targets with
--target= and --sysroot=

See Repository:
https://github.com/trcrsired/windows-msvc-sysroot

Add sysroot support for msvc

MSVC.cpp needs getDriver before using D

add stl in parser for -stdlib=

Add Vcruntime to runtime list and unwind list

MSVC add default runtime lib type and default unwind lib type

add a msvc sysroot test

use %S instead of /foo

Fix test for msvc-sysroot

Also add a pesudo implementation for WebAssembly and
maybe Microsoft STL could be ported to more targets in the future

Fix the toggle of wasm that prevents -stdlib=stl passed into

Avoid clang-formatting in MSVC.cpp

Add some comments to ToolChain

avoid indent the if block

Add back space before winsysroot line

use  instead of arch in the comment

remove FIXME for libc++ since we have added the logic here

Remove MSVC.h formatting

Remove default cases in WebAssembly

add back the empty line before the Sysroot line

fix msvc-sysroot typo for libc++ loongarch

Fix : missing in CST_Stl case
---
 clang/include/clang/Driver/ToolChain.h  |  11 +-
 clang/lib/Driver/ToolChain.cpp  |  10 ++
 clang/lib/Driver/ToolChains/MSVC.cpp| 128 +++-
 clang/lib/Driver/ToolChains/MSVC.h  |  15 +++
 clang/lib/Driver/ToolChains/WebAssembly.cpp |  25 
 clang/lib/Driver/ToolChains/WebAssembly.h   |   2 +
 clang/test/Driver/msvc-sysroot.cpp  |  81 +
 clang/test/Driver/wasm-toolchain.cpp|  12 ++
 8 files changed, 279 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/Driver/msvc-sysroot.cpp

diff --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index 5347e29be91439..81e4e46f5806ae 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -94,19 +94,22 @@ class ToolChain {
   using path_list = SmallVector;
 
   enum CXXStdlibType {
-CST_Libcxx,
-CST_Libstdcxx
+CST_Libcxx, // LLVM libc++
+CST_Libstdcxx,  // GNU libstdc++
+CST_Stl,  // MSVC STL
   };
 
   enum RuntimeLibType {
 RLT_CompilerRT,
-RLT_Libgcc
+RLT_Libgcc,
+RLT_Vcruntime
   };
 
   enum UnwindLibType {
 UNW_None,
 UNW_CompilerRT,
-UNW_Libgcc
+UNW_Libgcc,
+UNW_Vcruntime
   };
 
   enum class UnwindTableLevel {
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 16f9b629fc538c..3f1064ba26e559 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -1143,6 +1143,8 @@ ToolChain::RuntimeLibType ToolChain::GetRuntimeLibType(
 runtimeLibType = ToolChain::RLT_CompilerRT;
   else if (LibName == "libgcc")
 runtimeLibType = ToolChain::RLT_Libgcc;
+  else if (LibName == "vcruntime")
+runtimeLibType = ToolChain::RLT_Vcruntime;
   else if (LibName == "platform")
 runtimeLibType = GetDefaultRuntimeLibType();
   else {
@@ -1181,6 +1183,8 @@ ToolChain::UnwindLibType ToolChain::GetUnwindLibType(
 unwindLibType = ToolChain::UNW_CompilerRT;
   } else if (LibName == "libgcc")
 unwindLibType = ToolChain::UNW_Libgcc;
+  else if (LibName == "vcruntime")
+unwindLibType = ToolChain::UNW_Vcruntime;
   else {
 if (A)
   getDriver().Diag(diag::err_drv_invalid_unwindlib_name)
@@ -1204,6 +1208,8 @@ ToolChain::CXXStdlibType 
ToolChain::GetCXXStdlibType(const ArgList &Args) const{
 cxxStdlibType = ToolChain::CST_Libcxx;
   else if (LibName == "libstdc++")
 cxxStdlibType = ToolChain::CST_Libstdcxx;
+  else if (LibName == "stl")
+cxxStdlibType = ToolChain::CST_Stl;
   else if (LibName == "platform")
 cxxStdlibType = GetDefaultCXXStdlibType();
   else {
@@ -1342,6 +1348,10 @@ void ToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
   case ToolChain::CST_Libstdcxx:
 CmdArgs.push_back("-lstdc++");
 break;
+
+  case ToolChain::CST_Stl:
+// MSVC STL does not need to add -l
+break;
   }
 }
 
diff --git a/clang/lib/Driver/ToolChains/MSVC.cpp 
b/clang/lib/Driver/ToolChains/MSVC.cpp
index ca266e3e1d1d3c..ad89003ed1c33c 100644
--- a/clang/lib/Driver/ToolChains/MSVC.cpp
+++ b/clang/lib/Driver/ToolChains/MSVC.cpp
@@ -90,6 +90,16 @@ void visualstudio::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 CmdArgs.push_back("-defaultlib:oldnames");
   }
 
+  auto SysRoot = TC.getDriver().SysRoot;
+  if (!SysRoot.empty()) {
+// If we have --sysroot, then we ignore all other setings
+// libpath is $SYSROOT/lib and $SYSROOT/lib/${ARCH}-unknown-windows-msvc
+const std::string MultiarchTriple =
+TC.getMultiarchTriple(TC.getDriver(), TC.getTriple(), SysRoot);
+std::string SysRootLib = "-libpath:" + SysRoot + "/lib";
+CmdA

[clang] [clang-tools-extra] [clangd] show lambda name instead of operator() in signature help (PR #101857)

2024-09-08 Thread Timothy Akintilo via cfe-commits

https://github.com/tilobyte updated 
https://github.com/llvm/llvm-project/pull/101857

>From c1afe853ccacae1605fecfe552bb9a263c6b8c1d Mon Sep 17 00:00:00 2001
From: Timothy Akintilo 
Date: Sat, 27 Jul 2024 16:17:46 -0500
Subject: [PATCH 1/7] use lambda name instead of operator()

---
 clang-tools-extra/clangd/CodeComplete.cpp |  2 ++
 .../clangd/unittests/CodeCompleteTests.cpp|  9 +++
 .../include/clang/Sema/CodeCompleteConsumer.h | 18 ++
 clang/include/clang/Sema/Overload.h   |  5 
 clang/include/clang/Sema/Sema.h   | 22 -
 clang/lib/Sema/CodeCompleteConsumer.cpp   | 10 +++-
 clang/lib/Sema/SemaCodeComplete.cpp   | 17 ++---
 clang/lib/Sema/SemaLookup.cpp |  3 ++-
 clang/lib/Sema/SemaOverload.cpp   | 24 +--
 9 files changed, 82 insertions(+), 28 deletions(-)

diff --git a/clang-tools-extra/clangd/CodeComplete.cpp 
b/clang-tools-extra/clangd/CodeComplete.cpp
index 89eee392837af4..4f8a53aa7aae7e 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -1139,6 +1139,8 @@ class SignatureHelpCollector final : public 
CodeCompleteConsumer {
   switch (K) {
   case OC::CK_Aggregate:
 return 0;
+  case OC::CK_Lambda:
+[[fallthrough]];
   case OC::CK_Function:
 return 1;
   case OC::CK_FunctionType:
diff --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp 
b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
index 96d1ee1f0add73..4f748168d75aa7 100644
--- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -1437,6 +1437,15 @@ TEST(SignatureHelpTest, Overloads) {
   EXPECT_EQ(0, Results.activeParameter);
 }
 
+TEST(SignatureHelpTest, ShowLambdaNameInsteadOfOperatorParens) {
+  auto const Results = signatures(R"cpp(
+auto foo = [](int x, int y){};
+int main() { foo(^); }
+  )cpp");
+  EXPECT_THAT(Results.signatures,
+  UnorderedElementsAre(sig("foo([[int x]], [[int y]]) -> void")));
+}
+
 TEST(SignatureHelpTest, FunctionPointers) {
   llvm::StringLiteral Tests[] = {
   // Variable of function pointer type
diff --git a/clang/include/clang/Sema/CodeCompleteConsumer.h 
b/clang/include/clang/Sema/CodeCompleteConsumer.h
index 0924dc27af82b5..a6530c3c93d912 100644
--- a/clang/include/clang/Sema/CodeCompleteConsumer.h
+++ b/clang/include/clang/Sema/CodeCompleteConsumer.h
@@ -1028,6 +1028,9 @@ class CodeCompleteConsumer {
   /// The candidate is a function declaration.
   CK_Function,
 
+  // The candidate is a lambda operator().
+  CK_Lambda,
+
   /// The candidate is a function template, arguments are being completed.
   CK_FunctionTemplate,
 
@@ -1055,6 +1058,13 @@ class CodeCompleteConsumer {
   /// Kind == CK_Function.
   FunctionDecl *Function;
 
+  /// The lambda operator() candidate paired with the
+  /// lambda variable, available when Kind == CK_Lambda.
+  struct {
+FunctionDecl *OperatorParens;
+VarDecl *Var;
+  } Lambda;
+
   /// The function template overload candidate, available when
   /// Kind == CK_FunctionTemplate.
   FunctionTemplateDecl *FunctionTemplate;
@@ -1082,6 +1092,12 @@ class CodeCompleteConsumer {
   assert(Function != nullptr);
 }
 
+OverloadCandidate(FunctionDecl *LambdaOperatorParens, VarDecl *LambdaVar)
+: Kind(CK_Lambda), Lambda{LambdaOperatorParens, LambdaVar} {
+  assert(Lambda.OperatorParens != nullptr);
+  assert(Lambda.Var != nullptr);
+}
+
 OverloadCandidate(FunctionTemplateDecl *FunctionTemplateDecl)
 : Kind(CK_FunctionTemplate), FunctionTemplate(FunctionTemplateDecl) {
   assert(FunctionTemplateDecl != nullptr);
@@ -1112,6 +1128,8 @@ class CodeCompleteConsumer {
 /// function declaration for a function template.
 FunctionDecl *getFunction() const;
 
+VarDecl *getLambdaVarDecl() const;
+
 /// Retrieve the function template overload candidate.
 FunctionTemplateDecl *getFunctionTemplate() const {
   assert(getKind() == CK_FunctionTemplate && "Not a function template");
diff --git a/clang/include/clang/Sema/Overload.h 
b/clang/include/clang/Sema/Overload.h
index d6a6cee62a7528..7c4e82f07de02e 100644
--- a/clang/include/clang/Sema/Overload.h
+++ b/clang/include/clang/Sema/Overload.h
@@ -876,6 +876,11 @@ class Sema;
 /// function pointer or reference (C++ [over.call.object]).
 FunctionDecl *Function;
 
+/// LambdaName - When the OverloadCandidate is for a
+/// lambda's operator(), points to the declaration of
+/// the lambda variable.
+VarDecl *LambdaName{nullptr};
+
 /// FoundDecl - The original declaration that was looked up /
 /// invented / otherwise found, together with its access.
 /// Might be a UsingShadowDecl or a FunctionTemplateDec

[clang] [clang-tools-extra] [clangd] show lambda name instead of operator() in signature help (PR #101857)

2024-09-08 Thread Timothy Akintilo via cfe-commits


@@ -6292,11 +6298,16 @@ SemaCodeCompletion::ProduceCallSignatureHelp(Expr *Fn, 
ArrayRef Args,
 SmallVector ArgExprs(1, NakedFn);
 ArgExprs.append(ArgsWithoutDependentTypes.begin(),
 ArgsWithoutDependentTypes.end());
+auto *const LambdaName =
+DC->isLambda() ? 
cast(NakedFn->getReferencedDeclOfCallee())
+   : nullptr;
 SemaRef.AddFunctionCandidates(R.asUnresolvedSet(), ArgExprs,
   CandidateSet,
   /*ExplicitArgs=*/nullptr,
   /*SuppressUserConversions=*/false,
-  /*PartialOverloading=*/true);
+  /*PartialOverloading=*/true,
+  /*FirstArgumentIsBase=*/false,
+  /*LambdaName=*/LambdaName);

tilobyte wrote:

i see, renamed to `LambdaDecl`

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


[clang] [clang-tools-extra] [clangd] show lambda name instead of operator() in signature help (PR #101857)

2024-09-08 Thread Timothy Akintilo via cfe-commits


@@ -6292,11 +6298,16 @@ SemaCodeCompletion::ProduceCallSignatureHelp(Expr *Fn, 
ArrayRef Args,
 SmallVector ArgExprs(1, NakedFn);
 ArgExprs.append(ArgsWithoutDependentTypes.begin(),
 ArgsWithoutDependentTypes.end());
+auto *const LambdaName =
+DC->isLambda() ? 
cast(NakedFn->getReferencedDeclOfCallee())

tilobyte wrote:

@erichkeane stepping through the test i added for a lambda returned from a 
function, `NakedFn->getReferencedDeclOfCallee()` returns `nullptr` in the case 
of a lambda returned from a function. i believe this is because `NakedFn` is an 
rvalue, so there is no referenced decl to get.
using `cast_if_present`/`dyn_cast_if_present` seems to cover that case.

@zyn0217 yes, you are correct that `NakedFn` is a `DeclRefExpr` referring to 
the `VarDecl` of the declaration. `dyn_cast_if_present` indeed works, though i 
wonder--if `NakedFn->getReferencedDeclOfCallee()` returns `nullptr` in the case 
of a lambda returned from a function, could we get away with just 
`cast_if_present`?

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


  1   2   >