[clang] [Clang] Move the builtin workaround logic to the lexer (PR #96097)

2024-06-29 Thread Vlad Serebrennikov via cfe-commits

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

>From b77b2d9b10ad90ee67893904732003bf11eec21d Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Wed, 19 Jun 2024 19:47:43 +0200
Subject: [PATCH 1/5] [Clang] Move the builtin workaround logic to the lexer

---
 .../include/clang/Basic/DiagnosticLexKinds.td |  4 +
 clang/include/clang/Basic/IdentifierTable.h   | 19 +++-
 clang/include/clang/Parse/Parser.h|  4 -
 clang/lib/Basic/IdentifierTable.cpp   | 75 +++
 clang/lib/Lex/Preprocessor.cpp|  5 +
 clang/lib/Parse/ParseDecl.cpp | 19 +---
 clang/lib/Parse/ParseDeclCXX.cpp  | 71 ---
 clang/lib/Parse/ParseExpr.cpp | 91 ---
 clang/test/SemaCXX/libstdcxx_is_pod_hack.cpp  | 14 +--
 9 files changed, 109 insertions(+), 193 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 25fbfe83fa2bc..372d549dc59ba 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -85,6 +85,10 @@ def warn_c99_keyword : Warning<"'%0' is a keyword in C99">,
 def warn_c23_keyword : Warning<"'%0' is a keyword in C23">,
   InGroup, DefaultIgnore;
 
+def warn_deprecated_builtin_replacement : Warning<
+  "using the name of the builtin '%0' outside of "
+  "a builtin invocation is deprecated">, InGroup;
+
 def ext_unterminated_char_or_string : ExtWarn<
   "missing terminating %select{'|'\"'}0 character">, InGroup;
 def ext_empty_character : ExtWarn<"empty character constant">,
diff --git a/clang/include/clang/Basic/IdentifierTable.h 
b/clang/include/clang/Basic/IdentifierTable.h
index ae9ebd9f59154..00d1f9b7c9949 100644
--- a/clang/include/clang/Basic/IdentifierTable.h
+++ b/clang/include/clang/Basic/IdentifierTable.h
@@ -196,6 +196,9 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
   LLVM_PREFERRED_TYPE(bool)
   unsigned IsFinal : 1;
 
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned IsReusableBuiltinName : 1;
+
   // 22 bits left in a 64-bit word.
 
   // Managed by the language front-end.
@@ -213,7 +216,8 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
 IsFromAST(false), ChangedAfterLoad(false), FEChangedAfterLoad(false),
 RevertedTokenID(false), OutOfDate(false), IsModulesImport(false),
 IsMangledOpenMPVariantName(false), IsDeprecatedMacro(false),
-IsRestrictExpansion(false), IsFinal(false) {}
+IsRestrictExpansion(false), IsFinal(false),
+IsReusableBuiltinName(false) {}
 
 public:
   IdentifierInfo(const IdentifierInfo &) = delete;
@@ -332,6 +336,16 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
 RevertedTokenID = false;
   }
 
+  bool isReusableBuiltinName() const { return IsReusableBuiltinName; };
+
+  void setIsReusableBuiltinName(bool Val) {
+IsReusableBuiltinName = Val;
+if (Val)
+  NeedsHandleIdentifier = true;
+else
+  RecomputeNeedsHandleIdentifier();
+  };
+
   /// Return the preprocessor keyword ID for this identifier.
   ///
   /// For example, "define" will return tok::pp_define.
@@ -569,7 +583,8 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
   void RecomputeNeedsHandleIdentifier() {
 NeedsHandleIdentifier = isPoisoned() || hasMacroDefinition() ||
 isExtensionToken() || isFutureCompatKeyword() ||
-isOutOfDate() || isModulesImport();
+isReusableBuiltinName() || isOutOfDate() ||
+isModulesImport();
   }
 };
 
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index d054b8cf0d240..ed5d32bf5e076 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -169,10 +169,6 @@ class Parser : public CodeCompletionHandler {
   mutable IdentifierInfo *Ident_import;
   mutable IdentifierInfo *Ident_module;
 
-  // C++ type trait keywords that can be reverted to identifiers and still be
-  // used as type traits.
-  llvm::SmallDenseMap RevertibleTypeTraits;
-
   std::unique_ptr AlignHandler;
   std::unique_ptr GCCVisibilityHandler;
   std::unique_ptr OptionsHandler;
diff --git a/clang/lib/Basic/IdentifierTable.cpp 
b/clang/lib/Basic/IdentifierTable.cpp
index feea84544d62f..f2f2fb822a378 100644
--- a/clang/lib/Basic/IdentifierTable.cpp
+++ b/clang/lib/Basic/IdentifierTable.cpp
@@ -246,6 +246,79 @@ static KeywordStatus getKeywordStatus(const LangOptions 
&LangOpts,
   return CurStatus;
 }
 
+static bool isReusableBuiltinName(tok::TokenKind TokenCode) {
+#define RTT_JOIN(X, Y) X##Y
+#define REVERTIBLE_TYPE_TRAIT(Name)
\
+  case RTT_JOIN(tok::kw_, Name):   
\
+return true;
+
+  switch (TokenCode) {
+  default:
+return false;
+REVERTIBLE_TYPE_TRAIT(__is_abstract);
+R

[clang] [Clang] Move the builtin workaround logic to the lexer (PR #96097)

2024-06-29 Thread Vlad Serebrennikov via cfe-commits


@@ -1673,6 +1673,7 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
 return II && HasExtension(*this, II->getName());
   });
   } else if (II == Ident__has_builtin) {
+EvaluatingHasBuiltinMacro = true;

Endilll wrote:

I'm not particularly proud of this workaround, and if reviewers think that we 
should do this in some other way (e.g. enable backtracking for every 
`__has_builtin` use, and look behind when we see a revertible type trait 
identifier), I'm open for suggestions.

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


[clang] [clang] Warn when builtin names are used outside of invocations (PR #96097)

2024-06-29 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [clang] Warn when builtin names are used outside of invocations (PR #96097)

2024-06-29 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [clang] Warn when builtin names are used outside of invocations (PR #96097)

2024-06-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: cor3ntin (cor3ntin)


Changes



---

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


19 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+4) 
- (modified) clang/include/clang/Basic/DiagnosticLexKinds.td (+4) 
- (modified) clang/include/clang/Basic/IdentifierTable.h (+17-2) 
- (modified) clang/include/clang/Lex/Preprocessor.h (+3) 
- (modified) clang/include/clang/Parse/Parser.h (-4) 
- (modified) clang/lib/Basic/IdentifierTable.cpp (+75) 
- (modified) clang/lib/Lex/PPMacroExpansion.cpp (+2) 
- (modified) clang/lib/Lex/Preprocessor.cpp (+10) 
- (modified) clang/lib/Parse/ParseDecl.cpp (+1-18) 
- (modified) clang/lib/Parse/ParseDeclCXX.cpp (-71) 
- (modified) clang/lib/Parse/ParseExpr.cpp (-91) 
- (modified) clang/test/PCH/cxx-traits.cpp (+3-5) 
- (modified) clang/test/PCH/cxx-traits.h (+51-51) 
- (modified) 
clang/test/SemaCXX/libcxx_is_trivially_equality_comparable_hack.cpp (+8-2) 
- (modified) clang/test/SemaCXX/libstdcxx_is_nothrow_convertible_hack.cpp 
(+9-2) 
- (modified) clang/test/SemaCXX/libstdcxx_is_pod_hack.cpp (+7-7) 
- (modified) clang/test/SemaObjCXX/arc-libstdcxx.mm (+6-1) 
- (modified) clang/test/SemaObjCXX/arc-type-traits.mm (+180-189) 
- (modified) clang/test/SemaObjCXX/objc-weak-type-traits.mm (+173-178) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0f958d213172a..7f026b6f9c953 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -132,6 +132,10 @@ Clang Frontend Potentially Breaking Changes
 $ clang --target= -print-target-triple
 
 
+- Clang now issues a deprecation warning when an identifier of a builtin is 
used
+  for something else than invoking the builtin, e.g. ``struct __is_pointer``.
+  This affects libstdc++ prior to 14.2, and libc++ prior to 3.5.
+
 - The ``hasTypeLoc`` AST matcher will no longer match a 
``classTemplateSpecializationDecl``;
   existing uses should switch to ``templateArgumentLoc`` or 
``hasAnyTemplateArgumentLoc`` instead.
 
diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 25fbfe83fa2bc..372d549dc59ba 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -85,6 +85,10 @@ def warn_c99_keyword : Warning<"'%0' is a keyword in C99">,
 def warn_c23_keyword : Warning<"'%0' is a keyword in C23">,
   InGroup, DefaultIgnore;
 
+def warn_deprecated_builtin_replacement : Warning<
+  "using the name of the builtin '%0' outside of "
+  "a builtin invocation is deprecated">, InGroup;
+
 def ext_unterminated_char_or_string : ExtWarn<
   "missing terminating %select{'|'\"'}0 character">, InGroup;
 def ext_empty_character : ExtWarn<"empty character constant">,
diff --git a/clang/include/clang/Basic/IdentifierTable.h 
b/clang/include/clang/Basic/IdentifierTable.h
index ae9ebd9f59154..00d1f9b7c9949 100644
--- a/clang/include/clang/Basic/IdentifierTable.h
+++ b/clang/include/clang/Basic/IdentifierTable.h
@@ -196,6 +196,9 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
   LLVM_PREFERRED_TYPE(bool)
   unsigned IsFinal : 1;
 
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned IsReusableBuiltinName : 1;
+
   // 22 bits left in a 64-bit word.
 
   // Managed by the language front-end.
@@ -213,7 +216,8 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
 IsFromAST(false), ChangedAfterLoad(false), FEChangedAfterLoad(false),
 RevertedTokenID(false), OutOfDate(false), IsModulesImport(false),
 IsMangledOpenMPVariantName(false), IsDeprecatedMacro(false),
-IsRestrictExpansion(false), IsFinal(false) {}
+IsRestrictExpansion(false), IsFinal(false),
+IsReusableBuiltinName(false) {}
 
 public:
   IdentifierInfo(const IdentifierInfo &) = delete;
@@ -332,6 +336,16 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
 RevertedTokenID = false;
   }
 
+  bool isReusableBuiltinName() const { return IsReusableBuiltinName; };
+
+  void setIsReusableBuiltinName(bool Val) {
+IsReusableBuiltinName = Val;
+if (Val)
+  NeedsHandleIdentifier = true;
+else
+  RecomputeNeedsHandleIdentifier();
+  };
+
   /// Return the preprocessor keyword ID for this identifier.
   ///
   /// For example, "define" will return tok::pp_define.
@@ -569,7 +583,8 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
   void RecomputeNeedsHandleIdentifier() {
 NeedsHandleIdentifier = isPoisoned() || hasMacroDefinition() ||
 isExtensionToken() || isFutureCompatKeyword() ||
-isOutOfDate() || isModulesImport();
+isReusableBuiltinName() || isOutOfDate() ||
+isModulesImport();
   }
 };
 
diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index 9d8a

[clang] [llvm] [Clang][Coroutines] Introducing the `[[clang::coro_inplace_task]]` attribute (PR #94693)

2024-06-29 Thread Yuxuan Chen via cfe-commits

https://github.com/yuxuanchen1997 updated 
https://github.com/llvm/llvm-project/pull/94693

>From 5d7ebf65f321735debcd919aae6b6dcb4ed5537f Mon Sep 17 00:00:00 2001
From: Yuxuan Chen 
Date: Tue, 4 Jun 2024 23:22:00 -0700
Subject: [PATCH] [Clang] Introduce [[clang::coro_inplace_task]]

---
 clang/include/clang/AST/ExprCXX.h | 26 --
 clang/include/clang/Basic/Attr.td |  8 ++
 clang/include/clang/Basic/AttrDocs.td | 19 +
 clang/lib/CodeGen/CGBlocks.cpp|  5 +-
 clang/lib/CodeGen/CGCUDARuntime.cpp   |  5 +-
 clang/lib/CodeGen/CGCUDARuntime.h |  8 +-
 clang/lib/CodeGen/CGCXXABI.h  | 10 +--
 clang/lib/CodeGen/CGClass.cpp | 16 ++--
 clang/lib/CodeGen/CGCoroutine.cpp | 30 +--
 clang/lib/CodeGen/CGExpr.cpp  | 41 +
 clang/lib/CodeGen/CGExprCXX.cpp   | 60 +++--
 clang/lib/CodeGen/CodeGenFunction.h   | 64 --
 clang/lib/CodeGen/ItaniumCXXABI.cpp   | 16 ++--
 clang/lib/CodeGen/MicrosoftCXXABI.cpp | 18 ++--
 clang/lib/Sema/SemaCoroutine.cpp  | 58 -
 clang/lib/Serialization/ASTReaderStmt.cpp | 10 ++-
 clang/lib/Serialization/ASTWriterStmt.cpp |  3 +-
 clang/test/CodeGenCoroutines/Inputs/utility.h | 13 +++
 .../coro-structured-concurrency.cpp   | 84 +++
 ...a-attribute-supported-attributes-list.test |  1 +
 llvm/include/llvm/IR/Intrinsics.td|  3 +
 .../lib/Transforms/Coroutines/CoroCleanup.cpp |  9 +-
 llvm/lib/Transforms/Coroutines/CoroElide.cpp  | 58 -
 llvm/lib/Transforms/Coroutines/Coroutines.cpp |  1 +
 .../coro-elide-structured-concurrency.ll  | 64 ++
 25 files changed, 496 insertions(+), 134 deletions(-)
 create mode 100644 clang/test/CodeGenCoroutines/Inputs/utility.h
 create mode 100644 clang/test/CodeGenCoroutines/coro-structured-concurrency.cpp
 create mode 100644 
llvm/test/Transforms/Coroutines/coro-elide-structured-concurrency.ll

diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index c2feac525c1ea..0cf62aee41b66 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -5082,7 +5082,8 @@ class CoroutineSuspendExpr : public Expr {
   enum SubExpr { Operand, Common, Ready, Suspend, Resume, Count };
 
   Stmt *SubExprs[SubExpr::Count];
-  OpaqueValueExpr *OpaqueValue = nullptr;
+  OpaqueValueExpr *CommonExprOpaqueValue = nullptr;
+  OpaqueValueExpr *InplaceCallOpaqueValue = nullptr;
 
 public:
   // These types correspond to the three C++ 'await_suspend' return variants
@@ -5090,10 +5091,10 @@ class CoroutineSuspendExpr : public Expr {
 
   CoroutineSuspendExpr(StmtClass SC, SourceLocation KeywordLoc, Expr *Operand,
Expr *Common, Expr *Ready, Expr *Suspend, Expr *Resume,
-   OpaqueValueExpr *OpaqueValue)
+   OpaqueValueExpr *CommonExprOpaqueValue)
   : Expr(SC, Resume->getType(), Resume->getValueKind(),
  Resume->getObjectKind()),
-KeywordLoc(KeywordLoc), OpaqueValue(OpaqueValue) {
+KeywordLoc(KeywordLoc), CommonExprOpaqueValue(CommonExprOpaqueValue) {
 SubExprs[SubExpr::Operand] = Operand;
 SubExprs[SubExpr::Common] = Common;
 SubExprs[SubExpr::Ready] = Ready;
@@ -5128,7 +5129,16 @@ class CoroutineSuspendExpr : public Expr {
   }
 
   /// getOpaqueValue - Return the opaque value placeholder.
-  OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; }
+  OpaqueValueExpr *getCommonExprOpaqueValue() const {
+return CommonExprOpaqueValue;
+  }
+
+  OpaqueValueExpr *getInplaceCallOpaqueValue() const {
+return InplaceCallOpaqueValue;
+  }
+  void setInplaceCallOpaqueValue(OpaqueValueExpr *E) {
+InplaceCallOpaqueValue = E;
+  }
 
   Expr *getReadyExpr() const {
 return static_cast(SubExprs[SubExpr::Ready]);
@@ -5194,9 +5204,9 @@ class CoawaitExpr : public CoroutineSuspendExpr {
 public:
   CoawaitExpr(SourceLocation CoawaitLoc, Expr *Operand, Expr *Common,
   Expr *Ready, Expr *Suspend, Expr *Resume,
-  OpaqueValueExpr *OpaqueValue, bool IsImplicit = false)
+  OpaqueValueExpr *CommonExprOpaqueValue, bool IsImplicit = false)
   : CoroutineSuspendExpr(CoawaitExprClass, CoawaitLoc, Operand, Common,
- Ready, Suspend, Resume, OpaqueValue) {
+ Ready, Suspend, Resume, CommonExprOpaqueValue) {
 CoawaitBits.IsImplicit = IsImplicit;
   }
 
@@ -5275,9 +5285,9 @@ class CoyieldExpr : public CoroutineSuspendExpr {
 public:
   CoyieldExpr(SourceLocation CoyieldLoc, Expr *Operand, Expr *Common,
   Expr *Ready, Expr *Suspend, Expr *Resume,
-  OpaqueValueExpr *OpaqueValue)
+  OpaqueValueExpr *CommonExprOpaqueValue)
   : CoroutineSuspendExpr(CoyieldExprClass, CoyieldLoc, Operand, Common,
-  

[clang] [clang] Warn when builtin names are used outside of invocations (PR #96097)

2024-06-29 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [llvm] [Clang][Coroutines] Introducing the `[[clang::coro_inplace_task]]` attribute (PR #94693)

2024-06-29 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff cd0f89109bf90442cab8cfeaf5fce17cbddeef73 
5d7ebf65f321735debcd919aae6b6dcb4ed5537f -- 
clang/test/CodeGenCoroutines/Inputs/utility.h 
clang/test/CodeGenCoroutines/coro-structured-concurrency.cpp 
clang/include/clang/AST/ExprCXX.h clang/lib/CodeGen/CGBlocks.cpp 
clang/lib/CodeGen/CGCUDARuntime.cpp clang/lib/CodeGen/CGCUDARuntime.h 
clang/lib/CodeGen/CGCXXABI.h clang/lib/CodeGen/CGClass.cpp 
clang/lib/CodeGen/CGCoroutine.cpp clang/lib/CodeGen/CGExpr.cpp 
clang/lib/CodeGen/CGExprCXX.cpp clang/lib/CodeGen/CodeGenFunction.h 
clang/lib/CodeGen/ItaniumCXXABI.cpp clang/lib/CodeGen/MicrosoftCXXABI.cpp 
clang/lib/Sema/SemaCoroutine.cpp clang/lib/Serialization/ASTReaderStmt.cpp 
clang/lib/Serialization/ASTWriterStmt.cpp 
llvm/lib/Transforms/Coroutines/CoroCleanup.cpp 
llvm/lib/Transforms/Coroutines/CoroElide.cpp 
llvm/lib/Transforms/Coroutines/Coroutines.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/Transforms/Coroutines/CoroCleanup.cpp 
b/llvm/lib/Transforms/Coroutines/CoroCleanup.cpp
index 0e347f2747..35455ea87a 100644
--- a/llvm/lib/Transforms/Coroutines/CoroCleanup.cpp
+++ b/llvm/lib/Transforms/Coroutines/CoroCleanup.cpp
@@ -11,8 +11,8 @@
 #include "llvm/IR/Function.h"
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/InstIterator.h"
-#include "llvm/IR/Module.h"
 #include "llvm/IR/Intrinsics.h"
+#include "llvm/IR/Module.h"
 #include "llvm/IR/PassManager.h"
 #include "llvm/Transforms/Scalar/SimplifyCFG.h"
 

``




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


[clang] [clang] Warn when builtin names are used outside of invocations (PR #96097)

2024-06-29 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

CC @MitalAshok 

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


[clang] [clang] Warn when builtin names are used outside of invocations (PR #96097)

2024-06-29 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

To clear potential confusion, Corentin suggested to me offline to take over 
this PR. I fixed the tests and implemented the workaround for `__has_builtin` 
case, which surfaced while I was fixing the tests.

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


[clang] df067e5 - [clang][Interp][NFC] Pretty-print global temporary APValues

2024-06-29 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-06-29T18:29:02+02:00
New Revision: df067e567f7793a7c82096df0387a6e6dd31a828

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

LOG: [clang][Interp][NFC] Pretty-print global temporary APValues

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/Disasm.cpp b/clang/lib/AST/Interp/Disasm.cpp
index 56c2b7032f6d5..d946a10c22dc3 100644
--- a/clang/lib/AST/Interp/Disasm.cpp
+++ b/clang/lib/AST/Interp/Disasm.cpp
@@ -156,15 +156,28 @@ LLVM_DUMP_METHOD void Program::dump(llvm::raw_ostream 
&OS) const {
 }
 Desc->dump(OS);
 
-if (Desc->IsTemporary) {
+if (GP.isInitialized() && Desc->IsTemporary) {
   if (const auto *MTE =
   dyn_cast_if_present(Desc->asExpr());
   MTE && MTE->getLifetimeExtendedTemporaryDecl()) {
-const APValue *V = MTE->getLifetimeExtendedTemporaryDecl()->getValue();
-if (V->isInt())
-  OS << " (global temporary value: " << V->getInt() << ")";
-else
-  OS << " (huh?)";
+if (const APValue *V =
+MTE->getLifetimeExtendedTemporaryDecl()->getValue()) {
+  OS << " (global temporary value: ";
+  {
+ColorScope SC(OS, true, {llvm::raw_ostream::BRIGHT_MAGENTA, true});
+std::string VStr;
+llvm::raw_string_ostream SS(VStr);
+V->dump(SS, Ctx.getASTContext());
+
+for (unsigned I = 0; I != VStr.size(); ++I) {
+  if (VStr[I] == '\n')
+VStr[I] = ' ';
+}
+VStr.pop_back(); // Remove the newline (or now space) at the end.
+OS << VStr;
+  }
+  OS << ')';
+}
   }
 }
 



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


[clang] [llvm] [mlir] Add f8E4M3 IEEE 754 type (PR #97118)

2024-06-29 Thread Thorsten Schütt via cfe-commits

tschuett wrote:

If this is a new float type, could you please split out the apfloat changes in 
separate PR.

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


[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)

2024-06-29 Thread Paul Kirth via cfe-commits


@@ -979,6 +980,17 @@ static llvm::Error serializeIndex(ClangDocContext &CDCtx) {
"error creating index file: " +
FileErr.message());
   }
+  llvm::SmallString<128> RootPath(CDCtx.OutDirectory);
+  if (llvm::sys::path::is_relative(RootPath)) {
+llvm::sys::fs::make_absolute(RootPath);
+  }
+  // replace escape character with forward slash it shouldn't matter
+  // when viewing from the browser this helps with preventing javascript
+  // from escaping unwanted characters leading to bad paths

ilovepi wrote:

Can you use sentences and punctuation here?

Maybe something along these lines?
```suggestion
  // Replace the escaped characters with a forward slash. It shouldn't matter
  // when rendering the webpage in a web browser. This helps to prevent the
  // JavaScript from escaping characters incorrectly, and introducing  bad paths
  // in the URLs.
```

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


[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)

2024-06-29 Thread Paul Kirth via cfe-commits

https://github.com/ilovepi commented:

This is almost there. I've left a few minor comments, but I'd like to see 
better testing here. I'm awfully surprised we don't need to update any test 
lines, other than the 1 JS check. It would really help to see how the output is 
changing, if that was captured in the tests.

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


[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)

2024-06-29 Thread Paul Kirth via cfe-commits


@@ -7,6 +7,7 @@
 // RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/Rectangle.html 
-check-prefix=HTML-RECTANGLE
 // RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/Circle.html 
-check-prefix=HTML-CIRCLE
 
+// JSON-INDEX: var RootPath = "{{.*}}";

ilovepi wrote:

This is a URL, right? if so, is there a reason it wouldn't match, regardless of 
platform? I'm a bit surprised this is the only change required to the tests, so 
I'm wondering if we're doing a good job checking things in our existing HTML 
tests.

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


[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)

2024-06-29 Thread Paul Kirth via cfe-commits

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


[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)

2024-06-29 Thread Paul Kirth via cfe-commits


@@ -1,12 +1,19 @@
 function genLink(Ref) {
   var Path = 
`${window.location.protocol}//${window.location.host}/${Ref.Path}`;
+  var isFileProtocol = window.location.protocol.startsWith("file");
+  // we treat the file paths different depending on if we're
+  // serving via a http server or viewing from a local
+  if (isFileProtocol) {
+Path = `${window.location.protocol}//${RootPath}/${Ref.Path}`;
+  }

ilovepi wrote:

Maybe it makes sense to initialize `Path` w/ the ternary operator? Also, I'm 
now wondering if we really want `var` here or if this should be declared w/ 
`let`.  

This should improve the performance slightly, since `Path` is only initialized 
once, and saves at least 1 allocation on the JS heap. My JS is pretty weak 
though, so if I'm wrong on that, I'm happy to defer.

```suggestion
  let isFileProtocol = window.location.protocol.startsWith("file");
  // We treat the file paths different depending on if we're
  // serving via a http server or viewing from a local.
  var Path =  isFileProtocol ?  
`${window.location.protocol}//${RootPath}/${Ref.Path}` 
:`${window.location.protocol}//${window.location.host}/${Ref.Path}`;
```


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


[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)

2024-06-29 Thread Paul Kirth via cfe-commits


@@ -1,12 +1,19 @@
 function genLink(Ref) {
   var Path = 
`${window.location.protocol}//${window.location.host}/${Ref.Path}`;
+  var isFileProtocol = window.location.protocol.startsWith("file");
+  // we treat the file paths different depending on if we're
+  // serving via a http server or viewing from a local
+  if (isFileProtocol) {
+Path = `${window.location.protocol}//${RootPath}/${Ref.Path}`;
+  }
   if (Ref.RefType !== "namespace") {
 if (Ref.Path === "") {
   Path = `${Path}${Ref.Name}.html`;
-}
-else {
+} else {
   Path = `${Path}/${Ref.Name}.html`;
 }
+  } else {
+Path = `${Path}/index.html`
   }

ilovepi wrote:

I'm also wondering if we should reverse the logic here to be slightly easer to 
follow.
```
if(Ref.RefType === "namespace"){
  Path = `${Path}/index.html`
} else {
 //...
}
```
It's not really any functional change, though. IIRC in JS the ordering of 
statements has some performance impact, so I guess the ordering should be 
determined by which case we think is more common? Then again, you'd hope 
anything that affects performance would hit the JIT and get optimized nicely, 
so maybe this whole point is moot in practice.

I'll leave the final determination up to you, since you deal w/ JS and website 
performance more frequently than I do.

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


[clang-tools-extra] [clang-doc] add async loading (PR #93276)

2024-06-29 Thread Paul Kirth via cfe-commits


@@ -80,8 +80,8 @@ function createIndex(Index) {
 
 // Runs after DOM loads
 document.addEventListener("DOMContentLoaded", function() {
-  // JsonIndex is a variable from another file that contains the index
-  // in JSON format
-  var Index = JSON.parse(JsonIndex);
-  createIndex(Index);
+  // LoadIndex is an asynchronous function that will be generated clang-doc
+  // it ensures that the function call will not blocked as soon the page loads
+  // since the index object are often huge and can contain thousands of lines
+  LoadIndex().then((Index) => { createIndex(Index); });

ilovepi wrote:

@PeterChou1, once this comment is fixed, I'm happy to land this.

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


[clang] [compiler-rt] [compiler-rt] adding safestack support for sunos platforms. (PR #95648)

2024-06-29 Thread Saleem Abdulrasool via cfe-commits

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


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


[clang] 540fd42 - [compiler-rt] adding safestack support for sunos platforms. (#95648)

2024-06-29 Thread via cfe-commits

Author: David CARLIER
Date: 2024-06-29T18:13:44+01:00
New Revision: 540fd42c755f20f7b79c6c79493ec36d8cb9b3d3

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

LOG: [compiler-rt] adding safestack support for sunos platforms. (#95648)

Added: 


Modified: 
clang/lib/Driver/ToolChains/Solaris.cpp
compiler-rt/cmake/config-ix.cmake
compiler-rt/lib/safestack/safestack_platform.h
compiler-rt/test/safestack/lit.cfg.py

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Solaris.cpp 
b/clang/lib/Driver/ToolChains/Solaris.cpp
index 7126e018ca5b6..e82ed2ca79ffd 100644
--- a/clang/lib/Driver/ToolChains/Solaris.cpp
+++ b/clang/lib/Driver/ToolChains/Solaris.cpp
@@ -341,6 +341,7 @@ SanitizerMask Solaris::getSupportedSanitizers() const {
 Res |= SanitizerKind::PointerCompare;
 Res |= SanitizerKind::PointerSubtract;
   }
+  Res |= SanitizerKind::SafeStack;
   Res |= SanitizerKind::Vptr;
   return Res;
 }

diff  --git a/compiler-rt/cmake/config-ix.cmake 
b/compiler-rt/cmake/config-ix.cmake
index 75e4d3677703a..7037bf89d6532 100644
--- a/compiler-rt/cmake/config-ix.cmake
+++ b/compiler-rt/cmake/config-ix.cmake
@@ -837,7 +837,7 @@ else()
 endif()
 
 if (COMPILER_RT_HAS_SANITIZER_COMMON AND SAFESTACK_SUPPORTED_ARCH AND
-OS_NAME MATCHES "Linux|FreeBSD|NetBSD")
+OS_NAME MATCHES "Linux|FreeBSD|NetBSD|SunOS")
   set(COMPILER_RT_HAS_SAFESTACK TRUE)
 else()
   set(COMPILER_RT_HAS_SAFESTACK FALSE)

diff  --git a/compiler-rt/lib/safestack/safestack_platform.h 
b/compiler-rt/lib/safestack/safestack_platform.h
index 2b1fc139baa90..822611315d010 100644
--- a/compiler-rt/lib/safestack/safestack_platform.h
+++ b/compiler-rt/lib/safestack/safestack_platform.h
@@ -25,8 +25,9 @@
 #include 
 #include 
 
-#if !(SANITIZER_NETBSD || SANITIZER_FREEBSD || SANITIZER_LINUX)
-#error "Support for your platform has not been implemented"
+#if !(SANITIZER_NETBSD || SANITIZER_FREEBSD || SANITIZER_LINUX || \
+  SANITIZER_SOLARIS)
+#  error "Support for your platform has not been implemented"
 #endif
 
 #if SANITIZER_NETBSD
@@ -39,6 +40,10 @@ extern "C" void *__mmap(void *, size_t, int, int, int, int, 
off_t);
 #include 
 #endif
 
+#if SANITIZER_SOLARIS
+#  include 
+#endif
+
 namespace safestack {
 
 #if SANITIZER_NETBSD
@@ -73,6 +78,8 @@ inline ThreadId GetTid() {
   long Tid;
   thr_self(&Tid);
   return Tid;
+#elif SANITIZER_SOLARIS
+  return thr_self();
 #else
   return syscall(SYS_gettid);
 #endif
@@ -83,6 +90,8 @@ inline int TgKill(pid_t pid, ThreadId tid, int sig) {
   DEFINE__REAL(int, _lwp_kill, int a, int b);
   (void)pid;
   return _REAL(_lwp_kill, tid, sig);
+#elif SANITIZER_SOLARIS
+  return syscall(SYS_lwp_kill, tid, sig);
 #elif SANITIZER_FREEBSD
   return syscall(SYS_thr_kill2, pid, tid, sig);
 #else

diff  --git a/compiler-rt/test/safestack/lit.cfg.py 
b/compiler-rt/test/safestack/lit.cfg.py
index aadb8bf0d5c77..17dfae46a412b 100644
--- a/compiler-rt/test/safestack/lit.cfg.py
+++ b/compiler-rt/test/safestack/lit.cfg.py
@@ -33,5 +33,5 @@
 )
 )
 
-if config.host_os not in ["Linux", "FreeBSD", "NetBSD"]:
+if config.host_os not in ["Linux", "FreeBSD", "NetBSD", "SunOS"]:
 config.unsupported = True



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


[clang] [compiler-rt] [compiler-rt] adding safestack support for sunos platforms. (PR #95648)

2024-06-29 Thread David CARLIER via cfe-commits

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


[clang] [clang-repl] Fix RuntimeInterfaceBuilder for 32-bit systems (PR #97071)

2024-06-29 Thread Eymen Ünay via cfe-commits

eymay wrote:

Great work, I can imagine how hard it would be to uncover it!

Small note: I think you may also want to remove the Arm macro guards that mask 
the unittest in the same commit, as you did in the previous 
[PR](https://github.com/llvm/llvm-project/pull/96900/files#diff-9b27f347e7ca15f949d4453d24eeca3a6f841a1f7873c86eb98aa44192faaf15)
 

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


[clang] [clang] Emitting a warning if optimizations are enabled with sanitizers (PR #95934)

2024-06-29 Thread Fangrui Song via cfe-commits

MaskRay wrote:

I agree that we should not add a driver diagnostic.
Using sanitizers with -O2/-O3 is pretty common, especially when user programs 
are so large that -O0 is too slow or does not build at all.
I think msan is the most affected sanitizer which will detect fewer bugs.


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


[clang] [compiler-rt] [compiler-rt] adding safestack support for sunos platforms. (PR #95648)

2024-06-29 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`llvm-clang-x86_64-sie-ubuntu-fast` running on `sie-linux-worker` while 
building `clang,compiler-rt` at step 6 "test-build-unified-tree-check-all".

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

Here is the relevant piece of the build log for the reference:
```
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
 TEST 'LLVM :: 
Analysis/StructuralHash/structural-hash-printer.ll' FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/opt 
-passes='print' -disable-output 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/Analysis/StructuralHash/structural-hash-printer.ll
 2>&1 | 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/FileCheck
 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/Analysis/StructuralHash/structural-hash-printer.ll
+ /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/opt 
'-passes=print' -disable-output 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/Analysis/StructuralHash/structural-hash-printer.ll
+ 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/FileCheck
 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/Analysis/StructuralHash/structural-hash-printer.ll
RUN: at line 2: 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/opt 
-passes='print' -disable-output 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/Analysis/StructuralHash/structural-hash-printer.ll
 2>&1 | 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/FileCheck
 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/Analysis/StructuralHash/structural-hash-printer.ll
 -check-prefix=DETAILED-HASH
+ /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/opt 
'-passes=print' -disable-output 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/Analysis/StructuralHash/structural-hash-printer.ll
+ 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/FileCheck
 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/Analysis/StructuralHash/structural-hash-printer.ll
 -check-prefix=DETAILED-HASH
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/Analysis/StructuralHash/structural-hash-printer.ll:22:23:
 error: DETAILED-HASH-NEXT: expected string not found in 
input
; DETAILED-HASH-NEXT: Function f1 Hash: [[DF1H:([a-z0-9]{14,})]]
  ^
:1:29: note: scanning from here
Module Hash: 64fc99a803d8204
^
:2:1: note: possible intended match here
Function f1 Hash: 6d6a4bf7ff005
^

Input file: 
Check file: 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/Analysis/StructuralHash/structural-hash-printer.ll

-dump-input=help explains the following input dump.

Input was:
<<
   1: Module Hash: 
64fc99a803d8204 
check:21  ^~~~
next:22'0 X error: no match found
   2: Function f1 Hash: 6d6a4bf7ff005 
next:22'0 
next:22'1 ?possible intended 
match
   3: Function f2 Hash: dd4a2adf9742ebed 

next:22'0 ~~~
>>

--




```

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


[clang] [HLSL][clang][Driver] Fix error when using the option -fcgl in --driver-mode=dxc. (PR #97001)

2024-06-29 Thread Fangrui Song via cfe-commits

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


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


[clang] [compiler-rt] [compiler-rt] adding safestack support for sunos platforms. (PR #95648)

2024-06-29 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `sanitizer-x86_64-linux` 
running on `sanitizer-buildbot2` while building `clang,compiler-rt` at step 2 
"annotate".

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

Here is the relevant piece of the build log for the reference:
```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
llvm-lit: 
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/i386-unknown-linux-gnu". 
This path was found by running 
['/b/sanitizer-x86_64-linux/build/build_default/bin/clang', 
'--target=x86_64-unknown-linux-gnu', '-m32', '-nobuiltininc', 
'-I/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/include', 
'-idirafter', 
'/b/sanitizer-x86_64-linux/build/build_default/lib/clang/19/include', 
'-resource-dir=/b/sanitizer-x86_64-linux/build/compiler_rt_build', 
'-Wl,-rpath,/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/linux', 
'-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/x86_64-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-x86_64-linux/build/build_default/bin/clang', 
'--target=x86_64-unknown-linux-gnu', '-m64', '-nobuiltininc', 
'-I/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/include', 
'-idirafter', 
'/b/sanitizer-x86_64-linux/build/build_default/lib/clang/19/include', 
'-resource-dir=/b/sanitizer-x86_64-linux/build/compiler_rt_build', 
'-Wl,-rpath,/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/linux', 
'-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/x86_64-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-x86_64-linux/build/build_default/bin/clang', 
'--target=x86_64-unknown-linux-gnu', '-Wthread-safety', 
'-Wthread-safety-reference', '-Wthread-safety-beta', '-nobuiltininc', 
'-I/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/include', 
'-idirafter', 
'/b/sanitizer-x86_64-linux/build/build_default/lib/clang/19/include', 
'-resource-dir=/b/sanitizer-x86_64-linux/build/compiler_rt_build', 
'-Wl,-rpath,/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/linux', 
'-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/x86_64-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-x86_64-linux/build/build_default/bin/clang', 
'--target=x86_64-unknown-linux-gnu', '-m64', '-nobuiltininc', 
'-I/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/include', 
'-idirafter', 
'/b/sanitizer-x86_64-linux/build/build_default/lib/clang/19/include', 
'-resource-dir=/b/sanitizer-x86_64-linux/build/compiler_rt_build', 
'-Wl,-rpath,/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/linux', 
'-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/x86_64-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-x86_64-linux/build/build_default/bin/clang', 
'--target=x86_64-unknown-linux-gnu', '-m64', '-nobuiltininc', 
'-I/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/include', 
'-idirafter', 
'/b/sanitizer-x86_64-linux/build/build_default/lib/clang/19/include', 
'-resource-dir=/b/sanitizer-x86_64-linux/build/compiler_rt_build', 
'-Wl,-rpath,/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/linux', 
'-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/x86_64-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-x86_64-linux/build/build_default/bin/clang', 
'--target=x86_64-unknown-linux-gnu', '-m64', '-nobuiltininc', 
'-I/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/include', 
'-idirafter', 
'/b/sanitizer-x86_64-linux/build/build_default/lib/clang/19/include', 
'-resource-dir=/b/sanitizer-x86_64-linux/build/compiler_rt_build', 
'-Wl,-rpath,/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/linux', 
'-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/x86_64-unkno

[clang] d957da8 - [clang][Interp] Allow taking the address of a non-const global reference

2024-06-29 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-06-29T19:55:29+02:00
New Revision: d957da83791930a3c23f4f936ca7c7644c4b07a4

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

LOG: [clang][Interp] Allow taking the address of a non-const global reference

This is not a read, but the GetGlobal op before failed if the reference
we were taking a pointer of was non-const. Use GetGlobalUnchecked
instead.

Added: 


Modified: 
clang/lib/AST/Interp/Compiler.cpp
clang/lib/AST/Interp/Interp.h
clang/test/AST/Interp/references.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index e21e2c0eb8b6a..8b6f7f644a778 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -4906,8 +4906,11 @@ bool Compiler::visitDeclRef(const ValueDecl *D, 
const Expr *E) {
   return this->emitGetLocal(PT_Ptr, Offset, E);
 return this->emitGetPtrLocal(Offset, E);
   } else if (auto GlobalIndex = P.getGlobal(D)) {
-if (IsReference)
-  return this->emitGetGlobal(classifyPrim(E), *GlobalIndex, E);
+if (IsReference) {
+  if (!Ctx.getLangOpts().CPlusPlus11)
+return this->emitGetGlobal(classifyPrim(E), *GlobalIndex, E);
+  return this->emitGetGlobalUnchecked(classifyPrim(E), *GlobalIndex, E);
+}
 
 return this->emitGetPtrGlobal(*GlobalIndex, E);
   } else if (const auto *PVD = dyn_cast(D)) {

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 916d268aa4f09..6c9246f692204 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1255,7 +1255,10 @@ bool GetGlobal(InterpState &S, CodePtr OpPC, uint32_t I) 
{
 /// Same as GetGlobal, but without the checks.
 template ::T>
 bool GetGlobalUnchecked(InterpState &S, CodePtr OpPC, uint32_t I) {
-  auto *B = S.P.getGlobal(I);
+  const Pointer &Ptr = S.P.getPtrGlobal(I);
+  if (!Ptr.isInitialized())
+return false;
+  const Block *B = S.P.getGlobal(I);
   S.Stk.push(B->deref());
   return true;
 }

diff  --git a/clang/test/AST/Interp/references.cpp 
b/clang/test/AST/Interp/references.cpp
index efb756545b4aa..9a790dc75d730 100644
--- a/clang/test/AST/Interp/references.cpp
+++ b/clang/test/AST/Interp/references.cpp
@@ -130,3 +130,8 @@ const char (&nonextended_string_ref)[3] = {"hi"};
 static_assert(nonextended_string_ref[0] == 'h', "");
 static_assert(nonextended_string_ref[1] == 'i', "");
 static_assert(nonextended_string_ref[2] == '\0', "");
+
+/// This isa non-constant context. Reading A is not allowed,
+/// but taking its address is.
+int &&A = 12;
+int arr[!&A];



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


[clang] deb039e - [clang][Interp][NFC] Provide Program accessor for global temporaries

2024-06-29 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-06-29T19:55:30+02:00
New Revision: deb039e69ed7efc94ef517809f36298f40359c21

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

LOG: [clang][Interp][NFC] Provide Program accessor for global temporaries

Just like the one we have taking a ValueDecl*, provide a getGlobal()
version taking an expression.

Added: 


Modified: 
clang/lib/AST/Interp/Program.cpp
clang/lib/AST/Interp/Program.h

Removed: 




diff  --git a/clang/lib/AST/Interp/Program.cpp 
b/clang/lib/AST/Interp/Program.cpp
index caff9d01cdfee..2a1ad4d4eb850 100644
--- a/clang/lib/AST/Interp/Program.cpp
+++ b/clang/lib/AST/Interp/Program.cpp
@@ -126,6 +126,12 @@ std::optional Program::getGlobal(const ValueDecl 
*VD) {
   return std::nullopt;
 }
 
+std::optional Program::getGlobal(const Expr *E) {
+  if (auto It = GlobalIndices.find(E); It != GlobalIndices.end())
+return It->second;
+  return std::nullopt;
+}
+
 std::optional Program::getOrCreateGlobal(const ValueDecl *VD,
const Expr *Init) {
   if (auto Idx = getGlobal(VD))
@@ -195,7 +201,14 @@ std::optional Program::createGlobal(const 
ValueDecl *VD,
 }
 
 std::optional Program::createGlobal(const Expr *E) {
-  return createGlobal(E, E->getType(), /*isStatic=*/true, /*isExtern=*/false);
+  if (auto Idx = getGlobal(E))
+return Idx;
+  if (auto Idx = createGlobal(E, E->getType(), /*isStatic=*/true,
+  /*isExtern=*/false)) {
+GlobalIndices[E] = *Idx;
+return *Idx;
+  }
+  return std::nullopt;
 }
 
 std::optional Program::createGlobal(const DeclTy &D, QualType Ty,

diff  --git a/clang/lib/AST/Interp/Program.h b/clang/lib/AST/Interp/Program.h
index ec7c0744b8856..1cabc5212180f 100644
--- a/clang/lib/AST/Interp/Program.h
+++ b/clang/lib/AST/Interp/Program.h
@@ -77,6 +77,7 @@ class Program final {
 
   /// Finds a global's index.
   std::optional getGlobal(const ValueDecl *VD);
+  std::optional getGlobal(const Expr *E);
 
   /// Returns or creates a global an creates an index to it.
   std::optional getOrCreateGlobal(const ValueDecl *VD,



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


[clang] [clang][NFC] Move more functions from `Sema` to `SemaObjC` (PR #97172)

2024-06-29 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll created 
https://github.com/llvm/llvm-project/pull/97172

This patch continues the effort to split `Sema` up, moving more function to 
`SemaObjC`. Additional context can be found in 
https://github.com/llvm/llvm-project/pull/84184 and 
https://github.com/llvm/llvm-project/pull/92682.

Highlights are `getCurBlock()` and `PushBlockScope()`. 

>From 890d449d9cfa956badc1ba1f97022ffb84281ca3 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Sat, 29 Jun 2024 21:14:35 +0300
Subject: [PATCH 1/2] [clang] Move more function from `Sema` to `SemaObjC`

---
 clang/include/clang/Sema/Sema.h   |  41 --
 clang/include/clang/Sema/SemaObjC.h   |  47 ++-
 clang/lib/Parse/ParseExpr.cpp |  16 +-
 clang/lib/Sema/Sema.cpp   |  21 -
 clang/lib/Sema/SemaChecking.cpp   | 118 --
 clang/lib/Sema/SemaCodeComplete.cpp   |   8 +-
 clang/lib/Sema/SemaDecl.cpp   |  33 +-
 clang/lib/Sema/SemaDeclObjC.cpp   |   2 +-
 clang/lib/Sema/SemaExpr.cpp   | 374 +
 clang/lib/Sema/SemaExprObjC.cpp   | 376 +-
 clang/lib/Sema/SemaLookup.cpp |   3 +-
 clang/lib/Sema/SemaObjC.cpp   | 188 -
 clang/lib/Sema/SemaOpenMP.cpp |   4 +-
 clang/lib/Sema/SemaPseudoObject.cpp   |   4 +-
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  10 +-
 clang/lib/Sema/TreeTransform.h|  10 +-
 16 files changed, 631 insertions(+), 624 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index ef4fc47567a7c..422149896fb36 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -694,7 +694,6 @@ class Sema final : public SemaBase {
   Scope *getScopeForContext(DeclContext *Ctx);
 
   void PushFunctionScope();
-  void PushBlockScope(Scope *BlockScope, BlockDecl *Block);
   sema::LambdaScopeInfo *PushLambdaScope();
 
   /// This is used to inform Sema what the current TemplateParameterDepth
@@ -736,9 +735,6 @@ class Sema final : public SemaBase {
 
   bool hasAnyUnrecoverableErrorsInThisFunction() const;
 
-  /// Retrieve the current block, if any.
-  sema::BlockScopeInfo *getCurBlock();
-
   /// Get the innermost lambda enclosing the current location, if any. This
   /// looks through intervening non-lambda scopes such as local functions and
   /// blocks.
@@ -2182,14 +2178,6 @@ class Sema final : public SemaBase {
 
   void CheckCastAlign(Expr *Op, QualType T, SourceRange TRange);
 
-  /// checkUnsafeAssigns - Check whether +1 expr is being assigned
-  /// to weak/__unsafe_unretained type.
-  bool checkUnsafeAssigns(SourceLocation Loc, QualType LHS, Expr *RHS);
-
-  /// checkUnsafeExprAssigns - Check whether +1 expr is being assigned
-  /// to weak/__unsafe_unretained expression.
-  void checkUnsafeExprAssigns(SourceLocation Loc, Expr *LHS, Expr *RHS);
-
   /// Emit \p DiagID if statement located on \p StmtLoc has a suspicious null
   /// statement as a \p Body, and it is located on the same line.
   ///
@@ -3853,8 +3841,6 @@ class Sema final : public SemaBase {
   void AddLaunchBoundsAttr(Decl *D, const AttributeCommonInfo &CI,
Expr *MaxThreads, Expr *MinBlocks, Expr *MaxBlocks);
 
-  enum class RetainOwnershipKind { NS, CF, OS };
-
   UuidAttr *mergeUuidAttr(Decl *D, const AttributeCommonInfo &CI,
   StringRef UuidAsWritten, MSGuidDecl *GuidDecl);
 
@@ -5833,26 +5819,6 @@ class Sema final : public SemaBase {
 
   bool CheckCaseExpression(Expr *E);
 
-  //===- "Block" Extension 
===//
-
-  /// ActOnBlockStart - This callback is invoked when a block literal is
-  /// started.
-  void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope);
-
-  /// ActOnBlockArguments - This callback allows processing of block arguments.
-  /// If there are no arguments, this is still invoked.
-  void ActOnBlockArguments(SourceLocation CaretLoc, Declarator &ParamInfo,
-   Scope *CurScope);
-
-  /// ActOnBlockError - If there is an error parsing a block, this callback
-  /// is invoked to pop the information about the block from the action impl.
-  void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope);
-
-  /// ActOnBlockStmtExpr - This is called when the body of a block statement
-  /// literal was successfully completed.  ^(int x){...}
-  ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, Stmt *Body,
-Scope *CurScope);
-
   //=== Clang Extensions 
--===//
 
   /// __builtin_convertvector(...)
@@ -6571,13 +6537,6 @@ class Sema final : public SemaBase {
   // Set of failed immediate invocations to avoid double diagnosing.
   llvm::SmallPtrSet FailedImmediateInvocations;
 
-  /// List of SourceLocations where 'self' is implicitly retained 

[clang] [clang][NFC] Move more functions from `Sema` to `SemaObjC` (PR #97172)

2024-06-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Vlad Serebrennikov (Endilll)


Changes

This patch continues the effort to split `Sema` up, moving more function to 
`SemaObjC`. Additional context can be found in 
https://github.com/llvm/llvm-project/pull/84184 and 
https://github.com/llvm/llvm-project/pull/92682.

Highlights are `getCurBlock()` and `PushBlockScope()`. 

---

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


16 Files Affected:

- (modified) clang/include/clang/Sema/Sema.h (-41) 
- (modified) clang/include/clang/Sema/SemaObjC.h (+45-4) 
- (modified) clang/lib/Parse/ParseExpr.cpp (+9-8) 
- (modified) clang/lib/Sema/Sema.cpp (-21) 
- (modified) clang/lib/Sema/SemaChecking.cpp (-118) 
- (modified) clang/lib/Sema/SemaCodeComplete.cpp (+5-4) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+2-31) 
- (modified) clang/lib/Sema/SemaDeclObjC.cpp (+1-1) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+4-370) 
- (modified) clang/lib/Sema/SemaExprObjC.cpp (+380-3) 
- (modified) clang/lib/Sema/SemaLookup.cpp (+2-1) 
- (modified) clang/lib/Sema/SemaObjC.cpp (+174-10) 
- (modified) clang/lib/Sema/SemaOpenMP.cpp (+2-2) 
- (modified) clang/lib/Sema/SemaPseudoObject.cpp (+2-2) 
- (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+5-6) 
- (modified) clang/lib/Sema/TreeTransform.h (+6-6) 


``diff
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index ef4fc47567a7c..422149896fb36 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -694,7 +694,6 @@ class Sema final : public SemaBase {
   Scope *getScopeForContext(DeclContext *Ctx);
 
   void PushFunctionScope();
-  void PushBlockScope(Scope *BlockScope, BlockDecl *Block);
   sema::LambdaScopeInfo *PushLambdaScope();
 
   /// This is used to inform Sema what the current TemplateParameterDepth
@@ -736,9 +735,6 @@ class Sema final : public SemaBase {
 
   bool hasAnyUnrecoverableErrorsInThisFunction() const;
 
-  /// Retrieve the current block, if any.
-  sema::BlockScopeInfo *getCurBlock();
-
   /// Get the innermost lambda enclosing the current location, if any. This
   /// looks through intervening non-lambda scopes such as local functions and
   /// blocks.
@@ -2182,14 +2178,6 @@ class Sema final : public SemaBase {
 
   void CheckCastAlign(Expr *Op, QualType T, SourceRange TRange);
 
-  /// checkUnsafeAssigns - Check whether +1 expr is being assigned
-  /// to weak/__unsafe_unretained type.
-  bool checkUnsafeAssigns(SourceLocation Loc, QualType LHS, Expr *RHS);
-
-  /// checkUnsafeExprAssigns - Check whether +1 expr is being assigned
-  /// to weak/__unsafe_unretained expression.
-  void checkUnsafeExprAssigns(SourceLocation Loc, Expr *LHS, Expr *RHS);
-
   /// Emit \p DiagID if statement located on \p StmtLoc has a suspicious null
   /// statement as a \p Body, and it is located on the same line.
   ///
@@ -3853,8 +3841,6 @@ class Sema final : public SemaBase {
   void AddLaunchBoundsAttr(Decl *D, const AttributeCommonInfo &CI,
Expr *MaxThreads, Expr *MinBlocks, Expr *MaxBlocks);
 
-  enum class RetainOwnershipKind { NS, CF, OS };
-
   UuidAttr *mergeUuidAttr(Decl *D, const AttributeCommonInfo &CI,
   StringRef UuidAsWritten, MSGuidDecl *GuidDecl);
 
@@ -5833,26 +5819,6 @@ class Sema final : public SemaBase {
 
   bool CheckCaseExpression(Expr *E);
 
-  //===- "Block" Extension 
===//
-
-  /// ActOnBlockStart - This callback is invoked when a block literal is
-  /// started.
-  void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope);
-
-  /// ActOnBlockArguments - This callback allows processing of block arguments.
-  /// If there are no arguments, this is still invoked.
-  void ActOnBlockArguments(SourceLocation CaretLoc, Declarator &ParamInfo,
-   Scope *CurScope);
-
-  /// ActOnBlockError - If there is an error parsing a block, this callback
-  /// is invoked to pop the information about the block from the action impl.
-  void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope);
-
-  /// ActOnBlockStmtExpr - This is called when the body of a block statement
-  /// literal was successfully completed.  ^(int x){...}
-  ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, Stmt *Body,
-Scope *CurScope);
-
   //=== Clang Extensions 
--===//
 
   /// __builtin_convertvector(...)
@@ -6571,13 +6537,6 @@ class Sema final : public SemaBase {
   // Set of failed immediate invocations to avoid double diagnosing.
   llvm::SmallPtrSet FailedImmediateInvocations;
 
-  /// List of SourceLocations where 'self' is implicitly retained inside a
-  /// block.
-  llvm::SmallVector, 1>
-  ImplicitlyRetainedSelfLocs;
-
-  void maybeExtendBlockObject(ExprResult &E);
-
 private:
   static BinaryOperatorKind ConvertTo

[clang] [Clang] Prevent null pointer dereference in template deduction guide creation (PR #97097)

2024-06-29 Thread via cfe-commits

smanna12 wrote:

Thank you @antangelo for reviews!

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


[clang] f7fec8c - [Clang] Prevent null pointer dereference in template deduction guide creation (#97097)

2024-06-29 Thread via cfe-commits

Author: smanna12
Date: 2024-06-29T13:32:39-05:00
New Revision: f7fec8c80a986e82ef174080a3e07703c7b2c3c6

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

LOG: [Clang] Prevent null pointer dereference in template deduction guide 
creation (#97097)

This patch addresses static analyzer concerns where `TSI` could be
dereferenced after being assigned a null value from `SubstType` in
`ConvertConstructorToDeductionGuideTransform()`.

The fixes now check null value of `TSI` after the call to `SubstType`
and return `nullptr` to prevent potential null pointer dereferences when
calling getTypeLoc() or getType() and ensure safe execution.

Added: 


Modified: 
clang/lib/Sema/SemaTemplate.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index e36ee2d5a46cf..9f4acbe5e6dd5 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2513,6 +2513,9 @@ struct ConvertConstructorToDeductionGuideTransform {
   TSI = SemaRef.SubstType(TSI, OuterInstantiationArgs, Loc,
   DeductionGuideName);
 
+if (!TSI)
+  return nullptr;
+
 FunctionProtoTypeLoc FPTL =
 TSI->getTypeLoc().castAs();
 
@@ -2523,6 +2526,9 @@ struct ConvertConstructorToDeductionGuideTransform {
   if (NestedPattern)
 TSI = SemaRef.SubstType(TSI, OuterInstantiationArgs, Loc,
 DeclarationName());
+  if (!TSI)
+return nullptr;
+
   ParmVarDecl *NewParam =
   ParmVarDecl::Create(SemaRef.Context, DC, Loc, Loc, nullptr,
   TSI->getType(), TSI, SC_None, nullptr);



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


[clang] [Clang] Prevent null pointer dereference in template deduction guide creation (PR #97097)

2024-06-29 Thread via cfe-commits

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


[clang] [compiler-rt] [compiler-rt] adding safestack support for sunos platforms. (PR #95648)

2024-06-29 Thread Rainer Orth via cfe-commits

rorth wrote:

This patch broke the 
[Solaris/amd64](https://lab.llvm.org/staging/#/builders/94/builds/4729) 
buildbot.

For god's sake, can you please either test your Illumos patches on Solaris, too 
(there are Solaris buildbots in the cfarm for exactly such a purpose) and 
finally handle Issue #53919 when it's necessary to distinguish Solaris and 
Illumos.

This happens ever and ever again with your patches and I'm getting pissed off 
by this attitude!

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


[clang] [Clang] Prevent null pointer dereference in template deduction guide creation (PR #97097)

2024-06-29 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `sanitizer-x86_64-linux` 
running on `sanitizer-buildbot2` while building `clang` at step 2 "annotate".

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

Here is the relevant piece of the build log for the reference:
```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
llvm-lit: 
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-x86_64-linux/build/build_default/lib/clang/19/lib/i386-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-x86_64-linux/build/build_default/./bin/clang', 
'--target=x86_64-unknown-linux-gnu', '-m32', '-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-x86_64-linux/build/build_default/lib/clang/19/lib/x86_64-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-x86_64-linux/build/build_default/./bin/clang', 
'--target=x86_64-unknown-linux-gnu', '-m64', '-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-x86_64-linux/build/build_default/lib/clang/19/lib/x86_64-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-x86_64-linux/build/build_default/./bin/clang', 
'--target=x86_64-unknown-linux-gnu', '-Wthread-safety', 
'-Wthread-safety-reference', '-Wthread-safety-beta', '-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-x86_64-linux/build/build_default/lib/clang/19/lib/x86_64-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-x86_64-linux/build/build_default/./bin/clang', 
'--target=x86_64-unknown-linux-gnu', '-m64', '-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-x86_64-linux/build/build_default/lib/clang/19/lib/x86_64-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-x86_64-linux/build/build_default/./bin/clang', 
'--target=x86_64-unknown-linux-gnu', '-m64', '-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-x86_64-linux/build/build_default/lib/clang/19/lib/x86_64-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-x86_64-linux/build/build_default/./bin/clang', 
'--target=x86_64-unknown-linux-gnu', '-m64', '-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-x86_64-linux/build/build_default/lib/clang/19/lib/x86_64-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-x86_64-linux/build/build_default/./bin/clang', 
'--target=x86_64-unknown-linux-gnu', '-m64', '-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-x86_64-linux/build/llvm-project/llvm/utils/lit/lit/main.py:72: 
note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 9980 tests, 80 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70
FAIL: libFuzzer-x86_64-static-libcxx-Linux :: fuzzer-finalstats.test (2426 of 
9980)
 TEST 'libFuzzer-x86_64-static-libcxx-Linux :: 
fuzzer-finalstats.test' FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: /b/sanitizer-x86_64-linux/build/build_default/./bin/clang
-Wthread-safety -Wthread-safety-reference -Wthread-safety-beta   
--driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer 
-I/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/lib/fuzzer -m64 
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/fuzzer/SimpleTest.cpp
 -o 
/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/fuzzer/X86_64StaticLibcxxLinuxConfig/Output/fuzzer-finalstats.test.tmp-SimpleTest
+ /b/sanitizer-x86_64-linux/build/build_default/./bin/clang -Wthread-safety 
-Wthread-safety-reference -Wthread-safety-beta --driver-mode=g++ -O2 
-gline-tables-only -fsanitize=address,fuzzer 
-I/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/lib/fuzzer -m64 
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/fuzzer/SimpleTest.cpp
 -o 
/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/fuzzer/X86_64StaticLibcxxLinuxConfig/Output/fuzzer-finalstats.test.tmp-S

[clang] [clang] Use std::make_unique (NFC) (PR #97176)

2024-06-29 Thread Kazu Hirata via cfe-commits

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

This patch is based on clang-tidy's modernize-make-unique but limited
to those cases where type names are mentioned twice like
std::unique_ptr(new Type()), which is a bit mouthful.


>From 84e939e920af0c54092362d854850be2c6dd2897 Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Sat, 29 Jun 2024 06:28:42 -0700
Subject: [PATCH] [clang] Use std::make_unique (NFC)

This patch is based on clang-tidy's modernize-make-unique but limited
to those cases where type names are mentioned twice like
std::unique_ptr(new Type()), which is a bit mouthful.
---
 clang/lib/CodeGen/CGCoroutine.cpp| 2 +-
 clang/lib/Interpreter/CodeCompletion.cpp | 3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/clang/lib/CodeGen/CGCoroutine.cpp 
b/clang/lib/CodeGen/CGCoroutine.cpp
index b4c724422c14a..a8a70186c2c5a 100644
--- a/clang/lib/CodeGen/CGCoroutine.cpp
+++ b/clang/lib/CodeGen/CGCoroutine.cpp
@@ -103,7 +103,7 @@ static void createCoroData(CodeGenFunction &CGF,
 return;
   }
 
-  CurCoro.Data = std::unique_ptr(new CGCoroData);
+  CurCoro.Data = std::make_unique();
   CurCoro.Data->CoroId = CoroId;
   CurCoro.Data->CoroIdExpr = CoroIdExpr;
 }
diff --git a/clang/lib/Interpreter/CodeCompletion.cpp 
b/clang/lib/Interpreter/CodeCompletion.cpp
index 25183ae9eeb99..791426807cb91 100644
--- a/clang/lib/Interpreter/CodeCompletion.cpp
+++ b/clang/lib/Interpreter/CodeCompletion.cpp
@@ -368,8 +368,7 @@ void ReplCodeCompleter::codeComplete(CompilerInstance 
*InterpCI,
   llvm::SmallVector tb = {};
   InterpCI->getFrontendOpts().Inputs[0] = FrontendInputFile(
   CodeCompletionFileName, Language::CXX, InputKind::Source);
-  auto Act = std::unique_ptr(
-  new IncrementalSyntaxOnlyAction(ParentCI));
+  auto Act = std::make_unique(ParentCI);
   std::unique_ptr MB =
   llvm::MemoryBuffer::getMemBufferCopy(Content, CodeCompletionFileName);
   llvm::SmallVector RemappedFiles;

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


[clang] [clang] Use std::make_unique (NFC) (PR #97176)

2024-06-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Kazu Hirata (kazutakahirata)


Changes

This patch is based on clang-tidy's modernize-make-unique but limited
to those cases where type names are mentioned twice like
std::unique_ptr(new Type()), which is a bit mouthful.


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


2 Files Affected:

- (modified) clang/lib/CodeGen/CGCoroutine.cpp (+1-1) 
- (modified) clang/lib/Interpreter/CodeCompletion.cpp (+1-2) 


``diff
diff --git a/clang/lib/CodeGen/CGCoroutine.cpp 
b/clang/lib/CodeGen/CGCoroutine.cpp
index b4c724422c14a..a8a70186c2c5a 100644
--- a/clang/lib/CodeGen/CGCoroutine.cpp
+++ b/clang/lib/CodeGen/CGCoroutine.cpp
@@ -103,7 +103,7 @@ static void createCoroData(CodeGenFunction &CGF,
 return;
   }
 
-  CurCoro.Data = std::unique_ptr(new CGCoroData);
+  CurCoro.Data = std::make_unique();
   CurCoro.Data->CoroId = CoroId;
   CurCoro.Data->CoroIdExpr = CoroIdExpr;
 }
diff --git a/clang/lib/Interpreter/CodeCompletion.cpp 
b/clang/lib/Interpreter/CodeCompletion.cpp
index 25183ae9eeb99..791426807cb91 100644
--- a/clang/lib/Interpreter/CodeCompletion.cpp
+++ b/clang/lib/Interpreter/CodeCompletion.cpp
@@ -368,8 +368,7 @@ void ReplCodeCompleter::codeComplete(CompilerInstance 
*InterpCI,
   llvm::SmallVector tb = {};
   InterpCI->getFrontendOpts().Inputs[0] = FrontendInputFile(
   CodeCompletionFileName, Language::CXX, InputKind::Source);
-  auto Act = std::unique_ptr(
-  new IncrementalSyntaxOnlyAction(ParentCI));
+  auto Act = std::make_unique(ParentCI);
   std::unique_ptr MB =
   llvm::MemoryBuffer::getMemBufferCopy(Content, CodeCompletionFileName);
   llvm::SmallVector RemappedFiles;

``




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


[clang] [compiler-rt] [compiler-rt] adding safestack support for sunos platforms. (PR #95648)

2024-06-29 Thread David CARLIER via cfe-commits

devnexen wrote:

oh I see let me figure out a fix, getting into it.

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


[clang] [Clang] Fix __is_trivially_equality_comparable returning true with ineligebile defaulted overloads (PR #93113)

2024-06-29 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

> @ZequanWu I can't successfully build your reproducer with clang trunk. Would 
> it be possible to provide the full test case or a fully reduced one?

Because I reverted this change at 
https://github.com/llvm/llvm-project/commit/567b2c608c307c097315dd5ec4d6a5bbcddf898d,
 so it no longer crashes. If you recommit this or checkout to 
5b363483cf2461617fbb2449491c9914811c8d53, you can repro the crash.

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


[clang] 8d4aa1f - [clang][Interp] Update global temporaries at the end of a declaration

2024-06-29 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-06-29T21:10:24+02:00
New Revision: 8d4aa1f22ea08b12a7958b681e8a265f78cb349f

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

LOG: [clang][Interp] Update global temporaries at the end of a declaration

When we create a global temporary variable via a
LifetimeExtendedTemporaryDecl, we have an expression to initialize it
with, so we evaluate that expression, convert it to an APValue and set
it on the LETD. However, when the value is updated after the
initialization, we don't propagate the new value to the LETD, which
means we will see an outdated value set on the LETD.

Fix this by keeping a list of seen LETDs and update them from the
global variable at the end of evaluation a declaration.

Added: 
clang/test/AST/Interp/const-temporaries.cpp

Modified: 
clang/lib/AST/Interp/EvalEmitter.cpp
clang/lib/AST/Interp/EvalEmitter.h
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/InterpState.h

Removed: 




diff  --git a/clang/lib/AST/Interp/EvalEmitter.cpp 
b/clang/lib/AST/Interp/EvalEmitter.cpp
index a13cd94b0ba1c..6748b305d5c8e 100644
--- a/clang/lib/AST/Interp/EvalEmitter.cpp
+++ b/clang/lib/AST/Interp/EvalEmitter.cpp
@@ -71,6 +71,7 @@ EvaluationResult EvalEmitter::interpretDecl(const VarDecl *VD,
 EvalResult.setInvalid();
 
   S.EvaluatingDecl = nullptr;
+  updateGlobalTemporaries();
   return std::move(this->EvalResult);
 }
 
@@ -237,6 +238,28 @@ bool EvalEmitter::emitDestroy(uint32_t I, const SourceInfo 
&Info) {
   return true;
 }
 
+/// Global temporaries (LifetimeExtendedTemporary) carry their value
+/// around as an APValue, which codegen accesses.
+/// We set their value once when creating them, but we don't update it
+/// afterwards when code changes it later.
+/// This is what we do here.
+void EvalEmitter::updateGlobalTemporaries() {
+  for (const auto &[E, Temp] : S.SeenGlobalTemporaries) {
+if (std::optional GlobalIndex = P.getGlobal(E)) {
+  const Pointer &Ptr = P.getPtrGlobal(*GlobalIndex);
+  APValue *Cached = Temp->getOrCreateValue(true);
+
+  if (std::optional T = Ctx.classify(E->getType())) {
+TYPE_SWITCH(*T, { *Cached = Ptr.deref().toAPValue(); });
+  } else {
+if (std::optional APV = Ptr.toRValue(Ctx))
+  *Cached = *APV;
+  }
+}
+  }
+  S.SeenGlobalTemporaries.clear();
+}
+
 
//===--===//
 // Opcode evaluators
 
//===--===//

diff  --git a/clang/lib/AST/Interp/EvalEmitter.h 
b/clang/lib/AST/Interp/EvalEmitter.h
index 109e6e0bc0d76..d1e125cae9594 100644
--- a/clang/lib/AST/Interp/EvalEmitter.h
+++ b/clang/lib/AST/Interp/EvalEmitter.h
@@ -109,6 +109,8 @@ class EvalEmitter : public SourceMapper {
 return reinterpret_cast(It->second.get());
   }
 
+  void updateGlobalTemporaries();
+
   // The emitter always tracks the current instruction and sets OpPC to a token
   // value which is mapped to the location of the opcode being evaluated.
   CodePtr OpPC;

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 6c9246f692204..75a8f66cc5d50 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1283,16 +1283,20 @@ bool InitGlobal(InterpState &S, CodePtr OpPC, uint32_t 
I) {
 template ::T>
 bool InitGlobalTemp(InterpState &S, CodePtr OpPC, uint32_t I,
 const LifetimeExtendedTemporaryDecl *Temp) {
-  assert(Temp);
+  const Pointer &Ptr = S.P.getGlobal(I);
+
   const T Value = S.Stk.peek();
   APValue APV = Value.toAPValue();
   APValue *Cached = Temp->getOrCreateValue(true);
   *Cached = APV;
 
-  const Pointer &P = S.P.getGlobal(I);
-  P.deref() = S.Stk.pop();
-  P.initialize();
+  assert(Ptr.getDeclDesc()->asExpr());
+
+  S.SeenGlobalTemporaries.push_back(
+  std::make_pair(Ptr.getDeclDesc()->asExpr(), Temp));
 
+  Ptr.deref() = S.Stk.pop();
+  Ptr.initialize();
   return true;
 }
 
@@ -1305,6 +1309,9 @@ inline bool InitGlobalTempComp(InterpState &S, CodePtr 
OpPC,
   const Pointer &P = S.Stk.peek();
   APValue *Cached = Temp->getOrCreateValue(true);
 
+  S.SeenGlobalTemporaries.push_back(
+  std::make_pair(P.getDeclDesc()->asExpr(), Temp));
+
   if (std::optional APV = P.toRValue(S.getCtx())) {
 *Cached = *APV;
 return true;

diff  --git a/clang/lib/AST/Interp/InterpState.h 
b/clang/lib/AST/Interp/InterpState.h
index 925395b6eba0c..138e1d7ac95d5 100644
--- a/clang/lib/AST/Interp/InterpState.h
+++ b/clang/lib/AST/Interp/InterpState.h
@@ -123,6 +123,10 @@ class InterpState final : public State, public 
SourceMapper {
   SourceLocation EvalLocation;
   /// Declaration we're initializing/evaluting, if any.
   const VarDecl *EvaluatingDecl = nullptr

[clang] [Clang] Fix __is_trivially_equality_comparable returning true with ineligebile defaulted overloads (PR #93113)

2024-06-29 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

> > @ZequanWu I can't successfully build your reproducer with clang trunk. 
> > Would it be possible to provide the full test case or a fully reduced one?
> 
> Because I reverted this change at 
> [567b2c6](https://github.com/llvm/llvm-project/commit/567b2c608c307c097315dd5ec4d6a5bbcddf898d),
>  so it no longer crashes. If you recommit this or checkout to 
> [5b36348](https://github.com/llvm/llvm-project/commit/5b363483cf2461617fbb2449491c9914811c8d53),
>  you can repro the crash.

No, I mean it isn't a well-formed program. There are semicolons missing after 
class definitions.

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


[clang] [clang] Use std::make_unique (NFC) (PR #97176)

2024-06-29 Thread David Blaikie via cfe-commits

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


[clang] [clang] Use std::make_unique (NFC) (PR #97176)

2024-06-29 Thread David Blaikie via cfe-commits

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


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


[clang] [clang] Warn when builtin names are used outside of invocations (PR #96097)

2024-06-29 Thread Mital Ashok via cfe-commits

MitalAshok wrote:

Looks like `!__is_identifier()` is used instead of 
`__has_builtin` sometimes. With this patch, `__is_identifier()` is true because there's no lparen after the name

In libc++: 7f302f220e7b8727ed1bf8832dcc2d87b897e527 (Pretty easy fix to replace 
`__has_keyword(__reference_binds_to_temporary)` with 
`__has_builtin(__reference_binds_to_temporary)` again though)

In WIL which seems to be used by a few people: 
https://github.com/microsoft/wil/blob/68ab8c19ef557e1006cae6b1b84dedf12c91c9d6/include/wil/wistd_config.h#L249

libstdc++, indirectly through a macro: 
https://gcc.gnu.org/git/?p=gcc.git;a=blobdiff;f=libstdc%2B%2B-v3/include/bits/c%2B%2Bconfig;h=27302ed392eb163954c5a2d367831dbcb0ead3c3;hp=2e6c880ad95a1cc1dfdead2bbcfb977960172ac5;hb=6aa12274007bccbae2691a9d336c37fe167bb535;hpb=6ea5a23766b8077a503362c4fa6f51de92669c11

These will now all report that those things are identifiers and not available 
as builtins. It can be supported with the same workaround used for 
`__has_builtin`. Apparantly `__has_feature(__is_abstract)` is also supposed to 
be true 
(https://github.com/llvm/llvm-project/blob/8d4aa1f22ea08b12a7958b681e8a265f78cb349f/clang/docs/LanguageExtensions.rst?plain=1#L1693),
 but that seems to be broken on main and not a new issue with this patch.

---

Also it doesn't seem ideal to not support things like:

```c++
#define IS_CLASS __is_class
static_assert(!IS_CLASS(void));
```

Since these are supported by GCC and MSVC. Could you check again for an lparen 
after a macro expansion?

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


[clang] [Clang] Fix __is_trivially_equality_comparable returning true with ineligebile defaulted overloads (PR #93113)

2024-06-29 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

> > > @ZequanWu I can't successfully build your reproducer with clang trunk. 
> > > Would it be possible to provide the full test case or a fully reduced one?
> > 
> > 
> > Because I reverted this change at 
> > [567b2c6](https://github.com/llvm/llvm-project/commit/567b2c608c307c097315dd5ec4d6a5bbcddf898d),
> >  so it no longer crashes. If you recommit this or checkout to 
> > [5b36348](https://github.com/llvm/llvm-project/commit/5b363483cf2461617fbb2449491c9914811c8d53),
> >  you can repro the crash.
> 
> No, I mean it isn't a well-formed program. There are semicolons missing after 
> class definitions.

That's caused by creduce but it shouldn't matter (clang shouldn't crash due to 
syntax errors). I attached the original crash source here as creduce is still 
running. The command to repro is same as above.
[rtp_transmission_manager-8cce12.txt](https://github.com/user-attachments/files/16041931/rtp_transmission_manager-8cce12.txt)



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


[clang] 37698d9 - [clang][Interp][NFC] Use CheckLoad() in Inc/Dec ops

2024-06-29 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-06-29T21:10:24+02:00
New Revision: 37698d924840a229e5a1bece8f5e845e0f5c80a6

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

LOG: [clang][Interp][NFC] Use CheckLoad() in Inc/Dec ops

CheckLoad checks more things than we did before.

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 76a0751a006e4..2fe8ab7d0df4b 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -476,23 +476,24 @@ bool CheckGlobalInitialized(InterpState &S, CodePtr OpPC, 
const Pointer &Ptr) {
   return false;
 }
 
-bool CheckLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
-  if (!CheckLive(S, OpPC, Ptr, AK_Read))
+bool CheckLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
+   AccessKinds AK) {
+  if (!CheckLive(S, OpPC, Ptr, AK))
 return false;
   if (!CheckConstant(S, OpPC, Ptr))
 return false;
 
-  if (!CheckDummy(S, OpPC, Ptr, AK_Read))
+  if (!CheckDummy(S, OpPC, Ptr, AK))
 return false;
   if (!CheckExtern(S, OpPC, Ptr))
 return false;
-  if (!CheckRange(S, OpPC, Ptr, AK_Read))
+  if (!CheckRange(S, OpPC, Ptr, AK))
 return false;
-  if (!CheckActive(S, OpPC, Ptr, AK_Read))
+  if (!CheckActive(S, OpPC, Ptr, AK))
 return false;
-  if (!CheckInitialized(S, OpPC, Ptr, AK_Read))
+  if (!CheckInitialized(S, OpPC, Ptr, AK))
 return false;
-  if (!CheckTemporary(S, OpPC, Ptr, AK_Read))
+  if (!CheckTemporary(S, OpPC, Ptr, AK))
 return false;
   if (!CheckMutable(S, OpPC, Ptr))
 return false;

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 75a8f66cc5d50..866593b9af094 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -92,7 +92,8 @@ bool CheckConstant(InterpState &S, CodePtr OpPC, const 
Descriptor *Desc);
 bool CheckMutable(InterpState &S, CodePtr OpPC, const Pointer &Ptr);
 
 /// Checks if a value can be loaded from a block.
-bool CheckLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr);
+bool CheckLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
+   AccessKinds AK = AK_Read);
 
 bool CheckInitialized(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
   AccessKinds AK);
@@ -724,9 +725,7 @@ bool IncDecHelper(InterpState &S, CodePtr OpPC, const 
Pointer &Ptr) {
 template ::T>
 bool Inc(InterpState &S, CodePtr OpPC) {
   const Pointer &Ptr = S.Stk.pop();
-  if (!CheckDummy(S, OpPC, Ptr, AK_Increment))
-return false;
-  if (!CheckInitialized(S, OpPC, Ptr, AK_Increment))
+  if (!CheckLoad(S, OpPC, Ptr, AK_Increment))
 return false;
 
   return IncDecHelper(S, OpPC, Ptr);
@@ -738,9 +737,7 @@ bool Inc(InterpState &S, CodePtr OpPC) {
 template ::T>
 bool IncPop(InterpState &S, CodePtr OpPC) {
   const Pointer &Ptr = S.Stk.pop();
-  if (!CheckDummy(S, OpPC, Ptr, AK_Increment))
-return false;
-  if (!CheckInitialized(S, OpPC, Ptr, AK_Increment))
+  if (!CheckLoad(S, OpPC, Ptr, AK_Increment))
 return false;
 
   return IncDecHelper(S, OpPC, Ptr);
@@ -753,9 +750,7 @@ bool IncPop(InterpState &S, CodePtr OpPC) {
 template ::T>
 bool Dec(InterpState &S, CodePtr OpPC) {
   const Pointer &Ptr = S.Stk.pop();
-  if (!CheckDummy(S, OpPC, Ptr, AK_Decrement))
-return false;
-  if (!CheckInitialized(S, OpPC, Ptr, AK_Decrement))
+  if (!CheckLoad(S, OpPC, Ptr, AK_Decrement))
 return false;
 
   return IncDecHelper(S, OpPC, Ptr);
@@ -767,9 +762,7 @@ bool Dec(InterpState &S, CodePtr OpPC) {
 template ::T>
 bool DecPop(InterpState &S, CodePtr OpPC) {
   const Pointer &Ptr = S.Stk.pop();
-  if (!CheckDummy(S, OpPC, Ptr, AK_Decrement))
-return false;
-  if (!CheckInitialized(S, OpPC, Ptr, AK_Decrement))
+  if (!CheckLoad(S, OpPC, Ptr, AK_Decrement))
 return false;
 
   return IncDecHelper(S, OpPC, Ptr);
@@ -797,9 +790,7 @@ bool IncDecFloatHelper(InterpState &S, CodePtr OpPC, const 
Pointer &Ptr,
 
 inline bool Incf(InterpState &S, CodePtr OpPC, llvm::RoundingMode RM) {
   const Pointer &Ptr = S.Stk.pop();
-  if (Ptr.isDummy())
-return false;
-  if (!CheckInitialized(S, OpPC, Ptr, AK_Increment))
+  if (!CheckLoad(S, OpPC, Ptr, AK_Increment))
 return false;
 
   return IncDecFloatHelper(S, OpPC, Ptr, RM);
@@ -807,9 +798,7 @@ inline bool Incf(InterpState &S, CodePtr OpPC, 
llvm::RoundingMode RM) {
 
 inline bool IncfPop(InterpState &S, CodePtr OpPC, llvm::RoundingMode RM) {
   const Pointer &Ptr = S.Stk.pop();
-  if (Ptr.isDummy())
-return false;
-  if (!CheckInitialized(S, OpPC, Ptr, AK_Increment))
+  if (!CheckLoad(S, OpPC, Ptr, AK_Increment))
 return false;
 
   return IncDecFloatHelper(S, OpPC, Ptr, RM);
@@ -817,11 +806,7 @@ in

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

2024-06-29 Thread Mital Ashok via cfe-commits

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

LGTM

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


[clang] [Clang] Fix __is_trivially_equality_comparable returning true with ineligebile defaulted overloads (PR #93113)

2024-06-29 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

> > > > @ZequanWu I can't successfully build your reproducer with clang trunk. 
> > > > Would it be possible to provide the full test case or a fully reduced 
> > > > one?
> > > 
> > > 
> > > Because I reverted this change at 
> > > [567b2c6](https://github.com/llvm/llvm-project/commit/567b2c608c307c097315dd5ec4d6a5bbcddf898d),
> > >  so it no longer crashes. If you recommit this or checkout to 
> > > [5b36348](https://github.com/llvm/llvm-project/commit/5b363483cf2461617fbb2449491c9914811c8d53),
> > >  you can repro the crash.
> > 
> > 
> > No, I mean it isn't a well-formed program. There are semicolons missing 
> > after class definitions.
> 
> That's caused by creduce but it shouldn't matter (clang shouldn't crash due 
> to syntax errors). I attached the original crash source here as creduce is 
> still running. The command to repro is same as above. 
> [rtp_transmission_manager-8cce12.txt](https://github.com/user-attachments/files/16041931/rtp_transmission_manager-8cce12.txt)

Yes, but it's a lot easier to reduce a file without errors, at least for me. 
(And FWIW I'd also question reverting a bug fix that could result into bad code 
gen because of a crash-on-invalid it introduced)

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


[clang] 40f4bd1 - [clang][Interp] Allow reading mutable members if they were created...

2024-06-29 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-06-29T21:10:24+02:00
New Revision: 40f4bd18f2fb01731fa7891fb7349e05dc98aeec

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

LOG: [clang][Interp] Allow reading mutable members if they were created...

... in this evaluation.

Added: 
clang/test/AST/Interp/mutable.cpp

Modified: 
clang/lib/AST/Interp/Context.cpp
clang/lib/AST/Interp/Context.h
clang/lib/AST/Interp/EvalEmitter.cpp
clang/lib/AST/Interp/Interp.cpp
clang/lib/AST/Interp/InterpBlock.cpp
clang/lib/AST/Interp/InterpBlock.h
clang/lib/AST/Interp/InterpFrame.cpp
clang/lib/AST/Interp/Program.cpp
clang/test/AST/Interp/const-temporaries.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Context.cpp 
b/clang/lib/AST/Interp/Context.cpp
index 22ccae4fa30f8..913e8d514282a 100644
--- a/clang/lib/AST/Interp/Context.cpp
+++ b/clang/lib/AST/Interp/Context.cpp
@@ -39,6 +39,7 @@ bool Context::isPotentialConstantExpr(State &Parent, const 
FunctionDecl *FD) {
 }
 
 bool Context::evaluateAsRValue(State &Parent, const Expr *E, APValue &Result) {
+  ++EvalID;
   bool Recursing = !Stk.empty();
   Compiler C(*this, *P, Parent, Stk);
 
@@ -65,6 +66,7 @@ bool Context::evaluateAsRValue(State &Parent, const Expr *E, 
APValue &Result) {
 }
 
 bool Context::evaluate(State &Parent, const Expr *E, APValue &Result) {
+  ++EvalID;
   bool Recursing = !Stk.empty();
   Compiler C(*this, *P, Parent, Stk);
 
@@ -90,6 +92,7 @@ bool Context::evaluate(State &Parent, const Expr *E, APValue 
&Result) {
 
 bool Context::evaluateAsInitializer(State &Parent, const VarDecl *VD,
 APValue &Result) {
+  ++EvalID;
   bool Recursing = !Stk.empty();
   Compiler C(*this, *P, Parent, Stk);
 

diff  --git a/clang/lib/AST/Interp/Context.h b/clang/lib/AST/Interp/Context.h
index c78dc9a2a471e..b8ea4ad6b3b44 100644
--- a/clang/lib/AST/Interp/Context.h
+++ b/clang/lib/AST/Interp/Context.h
@@ -109,6 +109,8 @@ class Context final {
 
   const Record *getRecord(const RecordDecl *D) const;
 
+  unsigned getEvalID() const { return EvalID; }
+
 private:
   /// Runs a function.
   bool Run(State &Parent, const Function *Func, APValue &Result);
@@ -119,6 +121,8 @@ class Context final {
   InterpStack Stk;
   /// Constexpr program.
   std::unique_ptr P;
+  /// ID identifying an evaluation.
+  unsigned EvalID = 0;
 };
 
 } // namespace interp

diff  --git a/clang/lib/AST/Interp/EvalEmitter.cpp 
b/clang/lib/AST/Interp/EvalEmitter.cpp
index 6748b305d5c8e..f4854adba9348 100644
--- a/clang/lib/AST/Interp/EvalEmitter.cpp
+++ b/clang/lib/AST/Interp/EvalEmitter.cpp
@@ -84,7 +84,7 @@ EvalEmitter::LabelTy EvalEmitter::getLabel() { return 
NextLabel++; }
 Scope::Local EvalEmitter::createLocal(Descriptor *D) {
   // Allocate memory for a local.
   auto Memory = std::make_unique(sizeof(Block) + D->getAllocSize());
-  auto *B = new (Memory.get()) Block(D, /*isStatic=*/false);
+  auto *B = new (Memory.get()) Block(Ctx.getEvalID(), D, /*isStatic=*/false);
   B->invokeCtor();
 
   // Initialize local variable inline descriptor.

diff  --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 2fe8ab7d0df4b..0411fcad88ad0 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -400,7 +400,7 @@ bool CheckDowncast(InterpState &S, CodePtr OpPC, const 
Pointer &Ptr,
 
 bool CheckConst(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
   assert(Ptr.isLive() && "Pointer is not live");
-  if (!Ptr.isConst())
+  if (!Ptr.isConst() || Ptr.isMutable())
 return true;
 
   // The This pointer is writable in constructors and destructors,
@@ -422,9 +422,14 @@ bool CheckConst(InterpState &S, CodePtr OpPC, const 
Pointer &Ptr) {
 
 bool CheckMutable(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
   assert(Ptr.isLive() && "Pointer is not live");
-  if (!Ptr.isMutable()) {
+  if (!Ptr.isMutable())
+return true;
+
+  // In C++14 onwards, it is permitted to read a mutable member whose
+  // lifetime began within the evaluation.
+  if (S.getLangOpts().CPlusPlus14 &&
+  Ptr.block()->getEvalID() == S.Ctx.getEvalID())
 return true;
-  }
 
   const SourceInfo &Loc = S.Current->getSource(OpPC);
   const FieldDecl *Field = Ptr.getField();

diff  --git a/clang/lib/AST/Interp/InterpBlock.cpp 
b/clang/lib/AST/Interp/InterpBlock.cpp
index 9b33d1b778fb2..c34ea7634b4a9 100644
--- a/clang/lib/AST/Interp/InterpBlock.cpp
+++ b/clang/lib/AST/Interp/InterpBlock.cpp
@@ -92,7 +92,8 @@ bool Block::hasPointer(const Pointer *P) const {
 #endif
 
 DeadBlock::DeadBlock(DeadBlock *&Root, Block *Blk)
-: Root(Root), B(Blk->Desc, Blk->IsStatic, Blk->IsExtern, /*isDead=*/true) {
+: Root(Root),
+  B(~0u, Blk->Desc, Blk->IsStatic, Blk->IsExtern, /*isDead=*/true) {
   // Ad

[clang] [clang][C23] N3006 Underspecified object declarations (PR #79845)

2024-06-29 Thread Guillot Tony via cfe-commits

https://github.com/to268 updated https://github.com/llvm/llvm-project/pull/79845

>From 44d103f75aef4227262b823fd5168c081307ce23 Mon Sep 17 00:00:00 2001
From: Guillot Tony 
Date: Mon, 29 Jan 2024 15:14:32 +0100
Subject: [PATCH 1/4] Implementation base of N3006 Underspecified object
 declarations

---
 clang/docs/ReleaseNotes.rst   |  5 +++-
 .../clang/Basic/DiagnosticSemaKinds.td|  2 ++
 clang/lib/Sema/SemaExpr.cpp   | 27 +++
 clang/test/C/C2x/n3006.c  | 27 +++
 clang/test/Parser/c2x-underspecified-decls.c  | 12 +
 clang/www/c_status.html   |  2 +-
 6 files changed, 73 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/C/C2x/n3006.c
 create mode 100644 clang/test/Parser/c2x-underspecified-decls.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index feba3c7ba8d77..70f00844caa2f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -104,7 +104,7 @@ ABI Changes in This Version
   ifuncs. Its purpose was to preserve backwards compatibility when the ".ifunc"
   suffix got removed from the name mangling. The alias interacts badly with
   GlobalOpt (see the issue #96197).
-  
+
 - Fixed Microsoft name mangling for auto non-type template arguments of pointer
   type for MSVC 1920+. This change resolves incompatibilities with code 
compiled
   by MSVC 1920+ but will introduce incompatibilities with code compiled by
@@ -337,6 +337,9 @@ C23 Feature Support
 - Properly promote bit-fields of bit-precise integer types to the field's type
   rather than to ``int``. #GH87641
 
+- Clang now diagnoses `N3006 Underspecified object declarations
+  `_.
+
 Non-comprehensive list of changes in this release
 -
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 5dc36c594bcb7..ba19fbe542176 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7781,6 +7781,8 @@ def err_attribute_arm_mve_polymorphism : Error<
   "'__clang_arm_mve_strict_polymorphism' attribute can only be applied to an 
MVE/NEON vector type">;
 def err_attribute_webassembly_funcref : Error<
   "'__funcref' attribute can only be applied to a function pointer type">;
+def err_c23_underspecified_object_declaration: Error<
+  "'%select{struct||union||enum}0 %1' is defined as an 
underspecified object initializer">;
 
 def warn_setter_getter_impl_required : Warning<
   "property %0 requires method %1 to be defined - "
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index db44cfe1288b6..89af7641e8e6e 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -7117,6 +7117,33 @@ Sema::BuildCompoundLiteralExpr(SourceLocation LParenLoc, 
TypeSourceInfo *TInfo,
diagID))
 return ExprError();
 }
+  } else if (LangOpts.C23 &&
+ (literalType->isRecordType() || literalType->isEnumeralType())) {
+// C23 6.2.1p7: Structure, union, and enumeration tags have scope that
+// begins just after the appearance of the tag in a type specifier that
+// declares the tag.
+// [...]
+// An ordinary identifier that has an underspecified definition has scope
+// that starts when the definition is completed; if the same ordinary
+// identifier declares another entity with a scope that encloses the 
current
+// block, that declaration is hidden as soon as the inner declarator is
+// completed*.)
+// [...]
+// *) That means, that the outer declaration is not visible for the
+// initializer.
+auto Range = SourceRange(LParenLoc, RParenLoc);
+const auto *Tag = literalType->castAs();
+const auto &TagRange = Tag->getDecl()->getSourceRange();
+
+// We should diagnose underspecified declaration, unless the identifier has
+// been diagnosed as being a redefinition, since the tag is made anonymous.
+if (Range.fullyContains(TagRange) && Tag->getDecl()->getIdentifier()) {
+  Diag(TagRange.getBegin(),
+   diag::err_c23_underspecified_object_declaration)
+  << (unsigned)Tag->getDecl()->getTagKind()
+  << Tag->getDecl()->getName() << TagRange;
+  return ExprError();
+}
   } else if (!literalType->isDependentType() &&
  RequireCompleteType(LParenLoc, literalType,
diag::err_typecheck_decl_incomplete_type,
diff --git a/clang/test/C/C2x/n3006.c b/clang/test/C/C2x/n3006.c
new file mode 100644
index 0..15efc0ccd6d32
--- /dev/null
+++ b/clang/test/C/C2x/n3006.c
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -std=c2x -verify %s
+
+/* WG14 N3006: Full
+ * Underspecified object declarations
+ */
+
+struct S1 { int x, y; };// expected-note {{previous defi

[clang] 5a8c4b5 - [clang][Interp] Don't allow reading from non-const blocks when returning

2024-06-29 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-06-29T21:10:25+02:00
New Revision: 5a8c4b597beed38e392f221042d29f475a3d1626

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

LOG: [clang][Interp] Don't allow reading from non-const blocks when returning

Added: 


Modified: 
clang/lib/AST/Interp/EvalEmitter.cpp
clang/test/AST/Interp/const-temporaries.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/EvalEmitter.cpp 
b/clang/lib/AST/Interp/EvalEmitter.cpp
index f4854adba9348..d17151416b44b 100644
--- a/clang/lib/AST/Interp/EvalEmitter.cpp
+++ b/clang/lib/AST/Interp/EvalEmitter.cpp
@@ -151,6 +151,11 @@ template <> bool EvalEmitter::emitRet(const 
SourceInfo &Info) {
 
   // Implicitly convert lvalue to rvalue, if requested.
   if (ConvertResultToRValue) {
+// Never allow reading from a non-const pointer, unless the memory
+// has been created in this evaluation.
+if (!Ptr.isConst() && Ptr.block()->getEvalID() != Ctx.getEvalID())
+  return false;
+
 if (std::optional V = Ptr.toRValue(Ctx)) {
   EvalResult.setValue(*V);
 } else {

diff  --git a/clang/test/AST/Interp/const-temporaries.cpp 
b/clang/test/AST/Interp/const-temporaries.cpp
index bbb95b3c3dff7..1dc16ef63a846 100644
--- a/clang/test/AST/Interp/const-temporaries.cpp
+++ b/clang/test/AST/Interp/const-temporaries.cpp
@@ -90,3 +90,12 @@ struct R { mutable long x; };
 struct Z2 { const R &x, y; };
 Z2 z2 = { R{1}, z2.x.x = 10 };
 
+// CHECK: __cxa_atexit({{.*}} @_ZN1BD1Ev, {{.*}} @b
+
+// CHECK: define
+// CHECK-NOT: @_ZGRN21ModifyStaticTemporary1cE_
+// CHECK: store {{.*}} @_ZGRN21ModifyStaticTemporary1cE_, {{.*}} 
@_ZN21ModifyStaticTemporary1cE
+// CHECK: add
+// CHECK: store
+// CHECK: load {{.*}} @_ZN21ModifyStaticTemporary1bE
+// CHECK: store {{.*}} @_ZN21ModifyStaticTemporary1cE



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


[clang] [clang] Warn when builtin names are used outside of invocations (PR #96097)

2024-06-29 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

> Looks like !__is_identifier() is used instead of 
> __has_builtin sometimes. With this patch, __is_identifier( trait name>) is true because there's no lparen after the name

Thank you, I'll make `__is_identifier` work.

> Apparantly __has_feature(__is_abstract) is also supposed to be true (...), 
> but that seems to be broken on main and not a new issue with this patch.

I can't make it work even on ancient version of Clang on Compiler Explorer, so 
I wonder if it ever worked.

> Also it doesn't seem ideal to not support things like:
>
> #define IS_CLASS __is_class
> static_assert(!IS_CLASS(void));
>
> Since these are supported by GCC and MSVC. Could you check again for an 
> lparen after a macro expansion?

I think this would require us to abandon the lex approach implemented here. But 
read on...

> In libc++: 
> https://github.com/llvm/llvm-project/commit/7f302f220e7b8727ed1bf8832dcc2d87b897e527
>  (Pretty easy fix to replace __has_keyword(__reference_binds_to_temporary) 
> with __has_builtin(__reference_binds_to_temporary) again though)

Goodness, I think this usage makes lex approach non-viable. Even if libc++ 
fixes that now, it has been deployed in system headers.

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


[clang] [clang] Warn when builtin names are used outside of invocations (PR #96097)

2024-06-29 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

@zygoloid @cor3ntin @AaronBallman in the light of new data in 
https://github.com/llvm/llvm-project/pull/96097#issuecomment-2198314023, do you 
think this lex approach to revertible type trait identifiers is still viable?

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


[clang] [clang][C23] N3006 Underspecified object declarations (PR #79845)

2024-06-29 Thread Guillot Tony via cfe-commits

to268 wrote:

I've rebased the branch from main

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


[clang] [clang] Warn when builtin names are used outside of invocations (PR #96097)

2024-06-29 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

```
/usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/uniform_int_dist.h:250:31:
 error: expected unqualified-id
  static_assert(!_Up_traits::__is_signed, "U must be unsigned");
```
Results from CI are not making this any better.

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


[clang] [clang] Warn when builtin names are used outside of invocations (PR #96097)

2024-06-29 Thread Mital Ashok via cfe-commits

MitalAshok wrote:

What if we went in the other direction? We want to deprecate `__is_pointer` as 
an identifier, so only make it an identifier when it is being used by libstdc++ 
as an identifier. libstdc++ usage looks something like:

```c++
// type template
template
struct __is_pointer;
template
struct __is_pointer : true_type {};
__is_pointer::value

// variable template
template
inline constexpr bool __is_pointer = ...
__is_pointer
```

So only make it an identifier if it is preceded by `struct`/`class` or if it is 
succeeded by `<`/`=`?

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


[clang] [llvm] Add f8E4M3 IEEE 754 type to llvm (PR #97179)

2024-06-29 Thread Alexander Pivovarov via cfe-commits

https://github.com/apivovarov created 
https://github.com/llvm/llvm-project/pull/97179

This PR adds `f8E4M3` type to llvm.

`f8E4M3` type  follows IEEE 754 convention

```c
f8E4M3 (IEEE 754)
- Exponent: 4
- Mantissa: 3
- Exponent bias: 7
- Follows IEEE 754 conventions for representation of special values
- Has Positive and Negative zero
- Has Positive and Negative infinity
- Has NaNs

Additional details:
- Max exp (unbiased): 7
- Min exp (unbiased): -6
- Infinities (+/-): S..000
- Zeros (+/-): S..000
- NaNs: S..{001, 010, 011, 100, 101, 110, 111}
- Max normal number: S.1110.111 = +/-240
- Min normal number: S.0001.000 = +/-2^(-6)
- Max subnormal number: S..111 = +/-2^(-6) x 0.875 = +/-2^(-9) x 7
- Min subnormal number: S..001 = +/-2^(-6) x 0.125 = +/-2^(-9)
```

Related PRs:
- [PR-97118](https://github.com/llvm/llvm-project/pull/97118) Add f8E4M3 IEEE 
754 type to mlir


>From 38a885014046f5e696a98361586919d14362dbed Mon Sep 17 00:00:00 2001
From: Alexander Pivovarov 
Date: Fri, 28 Jun 2024 21:09:33 +
Subject: [PATCH] Add f8E4M3 IEEE 754 type to llvm

---
 clang/include/clang/AST/Stmt.h |  6 ++---
 clang/lib/AST/MicrosoftMangle.cpp  |  1 +
 llvm/include/llvm/ADT/APFloat.h|  6 +
 llvm/lib/Support/APFloat.cpp   | 20 
 llvm/unittests/ADT/APFloatTest.cpp | 38 ++
 5 files changed, 68 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index 9cd7a364cd3f1..4edb04502f83e 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -460,10 +460,10 @@ class alignas(void *) Stmt {
 unsigned : NumExprBits;
 
 static_assert(
-llvm::APFloat::S_MaxSemantics < 16,
-"Too many Semantics enum values to fit in bitfield of size 4");
+llvm::APFloat::S_MaxSemantics < 32,
+"Too many Semantics enum values to fit in bitfield of size 5");
 LLVM_PREFERRED_TYPE(llvm::APFloat::Semantics)
-unsigned Semantics : 4; // Provides semantics for APFloat construction
+unsigned Semantics : 5; // Provides semantics for APFloat construction
 LLVM_PREFERRED_TYPE(bool)
 unsigned IsExact : 1;
   };
diff --git a/clang/lib/AST/MicrosoftMangle.cpp 
b/clang/lib/AST/MicrosoftMangle.cpp
index 7f1e9ab02ec26..a2e270df276cb 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -946,6 +946,7 @@ void MicrosoftCXXNameMangler::mangleFloat(llvm::APFloat 
Number) {
   case APFloat::S_IEEEquad: Out << 'Y'; break;
   case APFloat::S_PPCDoubleDouble: Out << 'Z'; break;
   case APFloat::S_Float8E5M2:
+  case APFloat::S_Float8E4M3:
   case APFloat::S_Float8E4M3FN:
   case APFloat::S_Float8E5M2FNUZ:
   case APFloat::S_Float8E4M3FNUZ:
diff --git a/llvm/include/llvm/ADT/APFloat.h b/llvm/include/llvm/ADT/APFloat.h
index db2fa480655c6..bff8e6490d1de 100644
--- a/llvm/include/llvm/ADT/APFloat.h
+++ b/llvm/include/llvm/ADT/APFloat.h
@@ -166,6 +166,9 @@ struct APFloatBase {
 // This format's exponent bias is 16, instead of the 15 (2 ** (5 - 1) - 1)
 // that IEEE precedent would imply.
 S_Float8E5M2FNUZ,
+// 8-bit floating point number following IEEE-754 conventions with bit
+// layout S1E4M3.
+S_Float8E4M3,
 // 8-bit floating point number mostly following IEEE-754 conventions with
 // bit layout S1E4M3 as described in https://arxiv.org/abs/2209.05433.
 // Unlike IEEE-754 types, there are no infinity values, and NaN is
@@ -217,6 +220,7 @@ struct APFloatBase {
   static const fltSemantics &PPCDoubleDouble() LLVM_READNONE;
   static const fltSemantics &Float8E5M2() LLVM_READNONE;
   static const fltSemantics &Float8E5M2FNUZ() LLVM_READNONE;
+  static const fltSemantics &Float8E4M3() LLVM_READNONE;
   static const fltSemantics &Float8E4M3FN() LLVM_READNONE;
   static const fltSemantics &Float8E4M3FNUZ() LLVM_READNONE;
   static const fltSemantics &Float8E4M3B11FNUZ() LLVM_READNONE;
@@ -638,6 +642,7 @@ class IEEEFloat final : public APFloatBase {
   APInt convertPPCDoubleDoubleAPFloatToAPInt() const;
   APInt convertFloat8E5M2APFloatToAPInt() const;
   APInt convertFloat8E5M2FNUZAPFloatToAPInt() const;
+  APInt convertFloat8E4M3APFloatToAPInt() const;
   APInt convertFloat8E4M3FNAPFloatToAPInt() const;
   APInt convertFloat8E4M3FNUZAPFloatToAPInt() const;
   APInt convertFloat8E4M3B11FNUZAPFloatToAPInt() const;
@@ -656,6 +661,7 @@ class IEEEFloat final : public APFloatBase {
   void initFromPPCDoubleDoubleAPInt(const APInt &api);
   void initFromFloat8E5M2APInt(const APInt &api);
   void initFromFloat8E5M2FNUZAPInt(const APInt &api);
+  void initFromFloat8E4M3APInt(const APInt &api);
   void initFromFloat8E4M3FNAPInt(const APInt &api);
   void initFromFloat8E4M3FNUZAPInt(const APInt &api);
   void initFromFloat8E4M3B11FNUZAPInt(const APInt &api);
diff --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp
index 3017a9b976658..79e0094b243b2 100644
--- a/llvm/lib/Support/APFloat.

[clang] [llvm] Add f8E4M3 IEEE 754 type to llvm (PR #97179)

2024-06-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-support

Author: Alexander Pivovarov (apivovarov)


Changes

This PR adds `f8E4M3` type to llvm.

`f8E4M3` type  follows IEEE 754 convention

```c
f8E4M3 (IEEE 754)
- Exponent: 4
- Mantissa: 3
- Exponent bias: 7
- Follows IEEE 754 conventions for representation of special values
- Has Positive and Negative zero
- Has Positive and Negative infinity
- Has NaNs

Additional details:
- Max exp (unbiased): 7
- Min exp (unbiased): -6
- Infinities (+/-): S..000
- Zeros (+/-): S..000
- NaNs: S..{001, 010, 011, 100, 101, 110, 111}
- Max normal number: S.1110.111 = +/-240
- Min normal number: S.0001.000 = +/-2^(-6)
- Max subnormal number: S..111 = +/-2^(-6) x 0.875 = +/-2^(-9) x 7
- Min subnormal number: S..001 = +/-2^(-6) x 0.125 = +/-2^(-9)
```

Related PRs:
- [PR-97118](https://github.com/llvm/llvm-project/pull/97118) Add f8E4M3 IEEE 
754 type to mlir


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


5 Files Affected:

- (modified) clang/include/clang/AST/Stmt.h (+3-3) 
- (modified) clang/lib/AST/MicrosoftMangle.cpp (+1) 
- (modified) llvm/include/llvm/ADT/APFloat.h (+6) 
- (modified) llvm/lib/Support/APFloat.cpp (+20) 
- (modified) llvm/unittests/ADT/APFloatTest.cpp (+38) 


``diff
diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index 9cd7a364cd3f1..4edb04502f83e 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -460,10 +460,10 @@ class alignas(void *) Stmt {
 unsigned : NumExprBits;
 
 static_assert(
-llvm::APFloat::S_MaxSemantics < 16,
-"Too many Semantics enum values to fit in bitfield of size 4");
+llvm::APFloat::S_MaxSemantics < 32,
+"Too many Semantics enum values to fit in bitfield of size 5");
 LLVM_PREFERRED_TYPE(llvm::APFloat::Semantics)
-unsigned Semantics : 4; // Provides semantics for APFloat construction
+unsigned Semantics : 5; // Provides semantics for APFloat construction
 LLVM_PREFERRED_TYPE(bool)
 unsigned IsExact : 1;
   };
diff --git a/clang/lib/AST/MicrosoftMangle.cpp 
b/clang/lib/AST/MicrosoftMangle.cpp
index 7f1e9ab02ec26..a2e270df276cb 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -946,6 +946,7 @@ void MicrosoftCXXNameMangler::mangleFloat(llvm::APFloat 
Number) {
   case APFloat::S_IEEEquad: Out << 'Y'; break;
   case APFloat::S_PPCDoubleDouble: Out << 'Z'; break;
   case APFloat::S_Float8E5M2:
+  case APFloat::S_Float8E4M3:
   case APFloat::S_Float8E4M3FN:
   case APFloat::S_Float8E5M2FNUZ:
   case APFloat::S_Float8E4M3FNUZ:
diff --git a/llvm/include/llvm/ADT/APFloat.h b/llvm/include/llvm/ADT/APFloat.h
index db2fa480655c6..bff8e6490d1de 100644
--- a/llvm/include/llvm/ADT/APFloat.h
+++ b/llvm/include/llvm/ADT/APFloat.h
@@ -166,6 +166,9 @@ struct APFloatBase {
 // This format's exponent bias is 16, instead of the 15 (2 ** (5 - 1) - 1)
 // that IEEE precedent would imply.
 S_Float8E5M2FNUZ,
+// 8-bit floating point number following IEEE-754 conventions with bit
+// layout S1E4M3.
+S_Float8E4M3,
 // 8-bit floating point number mostly following IEEE-754 conventions with
 // bit layout S1E4M3 as described in https://arxiv.org/abs/2209.05433.
 // Unlike IEEE-754 types, there are no infinity values, and NaN is
@@ -217,6 +220,7 @@ struct APFloatBase {
   static const fltSemantics &PPCDoubleDouble() LLVM_READNONE;
   static const fltSemantics &Float8E5M2() LLVM_READNONE;
   static const fltSemantics &Float8E5M2FNUZ() LLVM_READNONE;
+  static const fltSemantics &Float8E4M3() LLVM_READNONE;
   static const fltSemantics &Float8E4M3FN() LLVM_READNONE;
   static const fltSemantics &Float8E4M3FNUZ() LLVM_READNONE;
   static const fltSemantics &Float8E4M3B11FNUZ() LLVM_READNONE;
@@ -638,6 +642,7 @@ class IEEEFloat final : public APFloatBase {
   APInt convertPPCDoubleDoubleAPFloatToAPInt() const;
   APInt convertFloat8E5M2APFloatToAPInt() const;
   APInt convertFloat8E5M2FNUZAPFloatToAPInt() const;
+  APInt convertFloat8E4M3APFloatToAPInt() const;
   APInt convertFloat8E4M3FNAPFloatToAPInt() const;
   APInt convertFloat8E4M3FNUZAPFloatToAPInt() const;
   APInt convertFloat8E4M3B11FNUZAPFloatToAPInt() const;
@@ -656,6 +661,7 @@ class IEEEFloat final : public APFloatBase {
   void initFromPPCDoubleDoubleAPInt(const APInt &api);
   void initFromFloat8E5M2APInt(const APInt &api);
   void initFromFloat8E5M2FNUZAPInt(const APInt &api);
+  void initFromFloat8E4M3APInt(const APInt &api);
   void initFromFloat8E4M3FNAPInt(const APInt &api);
   void initFromFloat8E4M3FNUZAPInt(const APInt &api);
   void initFromFloat8E4M3B11FNUZAPInt(const APInt &api);
diff --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp
index 3017a9b976658..79e0094b243b2 100644
--- a/llvm/lib/Support/APFloat.cpp
+++ b/llvm/lib/Support/APFloat.cpp
@@ -136,6 +136,7 @@ static constexpr fltSemantics semIEEEquad = {16383, -16382, 
113, 12

[clang] [llvm] [mlir] Add f8E4M3 IEEE 754 type (PR #97118)

2024-06-29 Thread Alexander Pivovarov via cfe-commits

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


[clang] [llvm] [mlir] Add f8E4M3 IEEE 754 type to mlir (PR #97118)

2024-06-29 Thread Alexander Pivovarov via cfe-commits

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


[clang] [llvm] [mlir] Add f8E4M3 IEEE 754 type to mlir (PR #97118)

2024-06-29 Thread Alexander Pivovarov via cfe-commits

apivovarov wrote:

> If this is a new float type, could you please split out the apfloat changes 
> in separate PR.

Sure - [PR-97179](https://github.com/llvm/llvm-project/pull/97179) Add f8E4M3 
IEEE 754 type to llvm

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


[clang] [llvm] [mlir] Add f8E4M3 IEEE 754 type to mlir (PR #97118)

2024-06-29 Thread Alexander Pivovarov via cfe-commits

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


[clang] [llvm] [mlir] Add f8E4M3 IEEE 754 type to mlir (PR #97118)

2024-06-29 Thread Alexander Pivovarov via cfe-commits

https://github.com/apivovarov updated 
https://github.com/llvm/llvm-project/pull/97118

>From 38a885014046f5e696a98361586919d14362dbed Mon Sep 17 00:00:00 2001
From: Alexander Pivovarov 
Date: Fri, 28 Jun 2024 21:09:33 +
Subject: [PATCH 1/2] Add f8E4M3 IEEE 754 type to llvm

---
 clang/include/clang/AST/Stmt.h |  6 ++---
 clang/lib/AST/MicrosoftMangle.cpp  |  1 +
 llvm/include/llvm/ADT/APFloat.h|  6 +
 llvm/lib/Support/APFloat.cpp   | 20 
 llvm/unittests/ADT/APFloatTest.cpp | 38 ++
 5 files changed, 68 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index 9cd7a364cd3f1..4edb04502f83e 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -460,10 +460,10 @@ class alignas(void *) Stmt {
 unsigned : NumExprBits;
 
 static_assert(
-llvm::APFloat::S_MaxSemantics < 16,
-"Too many Semantics enum values to fit in bitfield of size 4");
+llvm::APFloat::S_MaxSemantics < 32,
+"Too many Semantics enum values to fit in bitfield of size 5");
 LLVM_PREFERRED_TYPE(llvm::APFloat::Semantics)
-unsigned Semantics : 4; // Provides semantics for APFloat construction
+unsigned Semantics : 5; // Provides semantics for APFloat construction
 LLVM_PREFERRED_TYPE(bool)
 unsigned IsExact : 1;
   };
diff --git a/clang/lib/AST/MicrosoftMangle.cpp 
b/clang/lib/AST/MicrosoftMangle.cpp
index 7f1e9ab02ec26..a2e270df276cb 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -946,6 +946,7 @@ void MicrosoftCXXNameMangler::mangleFloat(llvm::APFloat 
Number) {
   case APFloat::S_IEEEquad: Out << 'Y'; break;
   case APFloat::S_PPCDoubleDouble: Out << 'Z'; break;
   case APFloat::S_Float8E5M2:
+  case APFloat::S_Float8E4M3:
   case APFloat::S_Float8E4M3FN:
   case APFloat::S_Float8E5M2FNUZ:
   case APFloat::S_Float8E4M3FNUZ:
diff --git a/llvm/include/llvm/ADT/APFloat.h b/llvm/include/llvm/ADT/APFloat.h
index db2fa480655c6..bff8e6490d1de 100644
--- a/llvm/include/llvm/ADT/APFloat.h
+++ b/llvm/include/llvm/ADT/APFloat.h
@@ -166,6 +166,9 @@ struct APFloatBase {
 // This format's exponent bias is 16, instead of the 15 (2 ** (5 - 1) - 1)
 // that IEEE precedent would imply.
 S_Float8E5M2FNUZ,
+// 8-bit floating point number following IEEE-754 conventions with bit
+// layout S1E4M3.
+S_Float8E4M3,
 // 8-bit floating point number mostly following IEEE-754 conventions with
 // bit layout S1E4M3 as described in https://arxiv.org/abs/2209.05433.
 // Unlike IEEE-754 types, there are no infinity values, and NaN is
@@ -217,6 +220,7 @@ struct APFloatBase {
   static const fltSemantics &PPCDoubleDouble() LLVM_READNONE;
   static const fltSemantics &Float8E5M2() LLVM_READNONE;
   static const fltSemantics &Float8E5M2FNUZ() LLVM_READNONE;
+  static const fltSemantics &Float8E4M3() LLVM_READNONE;
   static const fltSemantics &Float8E4M3FN() LLVM_READNONE;
   static const fltSemantics &Float8E4M3FNUZ() LLVM_READNONE;
   static const fltSemantics &Float8E4M3B11FNUZ() LLVM_READNONE;
@@ -638,6 +642,7 @@ class IEEEFloat final : public APFloatBase {
   APInt convertPPCDoubleDoubleAPFloatToAPInt() const;
   APInt convertFloat8E5M2APFloatToAPInt() const;
   APInt convertFloat8E5M2FNUZAPFloatToAPInt() const;
+  APInt convertFloat8E4M3APFloatToAPInt() const;
   APInt convertFloat8E4M3FNAPFloatToAPInt() const;
   APInt convertFloat8E4M3FNUZAPFloatToAPInt() const;
   APInt convertFloat8E4M3B11FNUZAPFloatToAPInt() const;
@@ -656,6 +661,7 @@ class IEEEFloat final : public APFloatBase {
   void initFromPPCDoubleDoubleAPInt(const APInt &api);
   void initFromFloat8E5M2APInt(const APInt &api);
   void initFromFloat8E5M2FNUZAPInt(const APInt &api);
+  void initFromFloat8E4M3APInt(const APInt &api);
   void initFromFloat8E4M3FNAPInt(const APInt &api);
   void initFromFloat8E4M3FNUZAPInt(const APInt &api);
   void initFromFloat8E4M3B11FNUZAPInt(const APInt &api);
diff --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp
index 3017a9b976658..79e0094b243b2 100644
--- a/llvm/lib/Support/APFloat.cpp
+++ b/llvm/lib/Support/APFloat.cpp
@@ -136,6 +136,7 @@ static constexpr fltSemantics semIEEEquad = {16383, -16382, 
113, 128};
 static constexpr fltSemantics semFloat8E5M2 = {15, -14, 3, 8};
 static constexpr fltSemantics semFloat8E5M2FNUZ = {
 15, -15, 3, 8, fltNonfiniteBehavior::NanOnly, 
fltNanEncoding::NegativeZero};
+static constexpr fltSemantics semFloat8E4M3 = {7, -6, 4, 8};
 static constexpr fltSemantics semFloat8E4M3FN = {
 8, -6, 4, 8, fltNonfiniteBehavior::NanOnly, fltNanEncoding::AllOnes};
 static constexpr fltSemantics semFloat8E4M3FNUZ = {
@@ -208,6 +209,8 @@ const llvm::fltSemantics 
&APFloatBase::EnumToSemantics(Semantics S) {
 return Float8E5M2();
   case S_Float8E5M2FNUZ:
 return Float8E5M2FNUZ();
+  case S_Float8E4M3:
+return Float8E4M3();
   case S_Float8E4M3

[clang] [llvm] [mlir] Add f8E4M3 IEEE 754 type to mlir (PR #97118)

2024-06-29 Thread Alexander Pivovarov via cfe-commits

https://github.com/apivovarov updated 
https://github.com/llvm/llvm-project/pull/97118

>From 38a885014046f5e696a98361586919d14362dbed Mon Sep 17 00:00:00 2001
From: Alexander Pivovarov 
Date: Fri, 28 Jun 2024 21:09:33 +
Subject: [PATCH 1/2] Add f8E4M3 IEEE 754 type to llvm

---
 clang/include/clang/AST/Stmt.h |  6 ++---
 clang/lib/AST/MicrosoftMangle.cpp  |  1 +
 llvm/include/llvm/ADT/APFloat.h|  6 +
 llvm/lib/Support/APFloat.cpp   | 20 
 llvm/unittests/ADT/APFloatTest.cpp | 38 ++
 5 files changed, 68 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index 9cd7a364cd3f1..4edb04502f83e 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -460,10 +460,10 @@ class alignas(void *) Stmt {
 unsigned : NumExprBits;
 
 static_assert(
-llvm::APFloat::S_MaxSemantics < 16,
-"Too many Semantics enum values to fit in bitfield of size 4");
+llvm::APFloat::S_MaxSemantics < 32,
+"Too many Semantics enum values to fit in bitfield of size 5");
 LLVM_PREFERRED_TYPE(llvm::APFloat::Semantics)
-unsigned Semantics : 4; // Provides semantics for APFloat construction
+unsigned Semantics : 5; // Provides semantics for APFloat construction
 LLVM_PREFERRED_TYPE(bool)
 unsigned IsExact : 1;
   };
diff --git a/clang/lib/AST/MicrosoftMangle.cpp 
b/clang/lib/AST/MicrosoftMangle.cpp
index 7f1e9ab02ec26..a2e270df276cb 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -946,6 +946,7 @@ void MicrosoftCXXNameMangler::mangleFloat(llvm::APFloat 
Number) {
   case APFloat::S_IEEEquad: Out << 'Y'; break;
   case APFloat::S_PPCDoubleDouble: Out << 'Z'; break;
   case APFloat::S_Float8E5M2:
+  case APFloat::S_Float8E4M3:
   case APFloat::S_Float8E4M3FN:
   case APFloat::S_Float8E5M2FNUZ:
   case APFloat::S_Float8E4M3FNUZ:
diff --git a/llvm/include/llvm/ADT/APFloat.h b/llvm/include/llvm/ADT/APFloat.h
index db2fa480655c6..bff8e6490d1de 100644
--- a/llvm/include/llvm/ADT/APFloat.h
+++ b/llvm/include/llvm/ADT/APFloat.h
@@ -166,6 +166,9 @@ struct APFloatBase {
 // This format's exponent bias is 16, instead of the 15 (2 ** (5 - 1) - 1)
 // that IEEE precedent would imply.
 S_Float8E5M2FNUZ,
+// 8-bit floating point number following IEEE-754 conventions with bit
+// layout S1E4M3.
+S_Float8E4M3,
 // 8-bit floating point number mostly following IEEE-754 conventions with
 // bit layout S1E4M3 as described in https://arxiv.org/abs/2209.05433.
 // Unlike IEEE-754 types, there are no infinity values, and NaN is
@@ -217,6 +220,7 @@ struct APFloatBase {
   static const fltSemantics &PPCDoubleDouble() LLVM_READNONE;
   static const fltSemantics &Float8E5M2() LLVM_READNONE;
   static const fltSemantics &Float8E5M2FNUZ() LLVM_READNONE;
+  static const fltSemantics &Float8E4M3() LLVM_READNONE;
   static const fltSemantics &Float8E4M3FN() LLVM_READNONE;
   static const fltSemantics &Float8E4M3FNUZ() LLVM_READNONE;
   static const fltSemantics &Float8E4M3B11FNUZ() LLVM_READNONE;
@@ -638,6 +642,7 @@ class IEEEFloat final : public APFloatBase {
   APInt convertPPCDoubleDoubleAPFloatToAPInt() const;
   APInt convertFloat8E5M2APFloatToAPInt() const;
   APInt convertFloat8E5M2FNUZAPFloatToAPInt() const;
+  APInt convertFloat8E4M3APFloatToAPInt() const;
   APInt convertFloat8E4M3FNAPFloatToAPInt() const;
   APInt convertFloat8E4M3FNUZAPFloatToAPInt() const;
   APInt convertFloat8E4M3B11FNUZAPFloatToAPInt() const;
@@ -656,6 +661,7 @@ class IEEEFloat final : public APFloatBase {
   void initFromPPCDoubleDoubleAPInt(const APInt &api);
   void initFromFloat8E5M2APInt(const APInt &api);
   void initFromFloat8E5M2FNUZAPInt(const APInt &api);
+  void initFromFloat8E4M3APInt(const APInt &api);
   void initFromFloat8E4M3FNAPInt(const APInt &api);
   void initFromFloat8E4M3FNUZAPInt(const APInt &api);
   void initFromFloat8E4M3B11FNUZAPInt(const APInt &api);
diff --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp
index 3017a9b976658..79e0094b243b2 100644
--- a/llvm/lib/Support/APFloat.cpp
+++ b/llvm/lib/Support/APFloat.cpp
@@ -136,6 +136,7 @@ static constexpr fltSemantics semIEEEquad = {16383, -16382, 
113, 128};
 static constexpr fltSemantics semFloat8E5M2 = {15, -14, 3, 8};
 static constexpr fltSemantics semFloat8E5M2FNUZ = {
 15, -15, 3, 8, fltNonfiniteBehavior::NanOnly, 
fltNanEncoding::NegativeZero};
+static constexpr fltSemantics semFloat8E4M3 = {7, -6, 4, 8};
 static constexpr fltSemantics semFloat8E4M3FN = {
 8, -6, 4, 8, fltNonfiniteBehavior::NanOnly, fltNanEncoding::AllOnes};
 static constexpr fltSemantics semFloat8E4M3FNUZ = {
@@ -208,6 +209,8 @@ const llvm::fltSemantics 
&APFloatBase::EnumToSemantics(Semantics S) {
 return Float8E5M2();
   case S_Float8E5M2FNUZ:
 return Float8E5M2FNUZ();
+  case S_Float8E4M3:
+return Float8E4M3();
   case S_Float8E4M3

[clang] [CUDA][NFC] CudaArch to OffloadArch rename (PR #97028)

2024-06-29 Thread Jakub Chlanda via cfe-commits

https://github.com/jchlanda updated 
https://github.com/llvm/llvm-project/pull/97028

>From 74eb15f035e4aed1dd19b735ac0b2fc5ad172213 Mon Sep 17 00:00:00 2001
From: Jakub Chlanda 
Date: Fri, 28 Jun 2024 09:25:56 +
Subject: [PATCH] [CUDA][NFC] CudaArch to OffloadArch rename

Rename CudaArch to OffloadArch to better reflect its content and the
use. Apply a similar rename to helpers handling the enum.
---
 clang/include/clang/Basic/Cuda.h |  28 +--
 clang/lib/Basic/Cuda.cpp | 110 ++--
 clang/lib/Basic/Targets/NVPTX.cpp| 160 -
 clang/lib/Basic/Targets/NVPTX.h  |  20 +--
 clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp | 173 +--
 clang/lib/Driver/Driver.cpp  |  43 ++---
 clang/lib/Driver/OffloadBundler.cpp  |   3 +-
 clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp |   2 +-
 clang/lib/Driver/ToolChains/Cuda.cpp |  38 ++--
 clang/lib/Driver/ToolChains/Cuda.h   |   4 +-
 clang/lib/Sema/SemaDeclAttr.cpp  |  14 +-
 11 files changed, 297 insertions(+), 298 deletions(-)

diff --git a/clang/include/clang/Basic/Cuda.h b/clang/include/clang/Basic/Cuda.h
index 01cfe286c491b..83699f8897f66 100644
--- a/clang/include/clang/Basic/Cuda.h
+++ b/clang/include/clang/Basic/Cuda.h
@@ -52,7 +52,7 @@ const char *CudaVersionToString(CudaVersion V);
 // Input is "Major.Minor"
 CudaVersion CudaStringToVersion(const llvm::Twine &S);
 
-enum class CudaArch {
+enum class OffloadArch {
   UNUSED,
   UNKNOWN,
   // TODO: Deprecate and remove GPU architectures older than sm_52.
@@ -133,8 +133,8 @@ enum class CudaArch {
// public one.
   LAST,
 
-  CudaDefault = CudaArch::SM_52,
-  HIPDefault = CudaArch::GFX906,
+  CudaDefault = OffloadArch::SM_52,
+  HIPDefault = OffloadArch::GFX906,
 };
 
 enum class CUDAFunctionTarget {
@@ -145,26 +145,26 @@ enum class CUDAFunctionTarget {
   InvalidTarget
 };
 
-static inline bool IsNVIDIAGpuArch(CudaArch A) {
-  return A >= CudaArch::SM_20 && A < CudaArch::GFX600;
+static inline bool IsNVIDIAOffloadArch(OffloadArch A) {
+  return A >= OffloadArch::SM_20 && A < OffloadArch::GFX600;
 }
 
-static inline bool IsAMDGpuArch(CudaArch A) {
+static inline bool IsAMDOffloadArch(OffloadArch A) {
   // Generic processor model is for testing only.
-  return A >= CudaArch::GFX600 && A < CudaArch::Generic;
+  return A >= OffloadArch::GFX600 && A < OffloadArch::Generic;
 }
 
-const char *CudaArchToString(CudaArch A);
-const char *CudaArchToVirtualArchString(CudaArch A);
+const char *OffloadArchToString(OffloadArch A);
+const char *OffloadArchToVirtualArchString(OffloadArch A);
 
 // The input should have the form "sm_20".
-CudaArch StringToCudaArch(llvm::StringRef S);
+OffloadArch StringToOffloadArch(llvm::StringRef S);
 
-/// Get the earliest CudaVersion that supports the given CudaArch.
-CudaVersion MinVersionForCudaArch(CudaArch A);
+/// Get the earliest CudaVersion that supports the given OffloadArch.
+CudaVersion MinVersionForOffloadArch(OffloadArch A);
 
-/// Get the latest CudaVersion that supports the given CudaArch.
-CudaVersion MaxVersionForCudaArch(CudaArch A);
+/// Get the latest CudaVersion that supports the given OffloadArch.
+CudaVersion MaxVersionForOffloadArch(OffloadArch A);
 
 //  Various SDK-dependent features that affect CUDA compilation
 enum class CudaFeature {
diff --git a/clang/lib/Basic/Cuda.cpp b/clang/lib/Basic/Cuda.cpp
index af99c4d61021e..faf3878f064d2 100644
--- a/clang/lib/Basic/Cuda.cpp
+++ b/clang/lib/Basic/Cuda.cpp
@@ -72,23 +72,21 @@ CudaVersion ToCudaVersion(llvm::VersionTuple Version) {
 }
 
 namespace {
-struct CudaArchToStringMap {
-  CudaArch arch;
+struct OffloadArchToStringMap {
+  OffloadArch arch;
   const char *arch_name;
   const char *virtual_arch_name;
 };
 } // namespace
 
-#define SM2(sm, ca)
\
-  { CudaArch::SM_##sm, "sm_" #sm, ca }
+#define SM2(sm, ca) {OffloadArch::SM_##sm, "sm_" #sm, ca}
 #define SM(sm) SM2(sm, "compute_" #sm)
-#define GFX(gpu)   
\
-  { CudaArch::GFX##gpu, "gfx" #gpu, "compute_amdgcn" }
-static const CudaArchToStringMap arch_names[] = {
+#define GFX(gpu) {OffloadArch::GFX##gpu, "gfx" #gpu, "compute_amdgcn"}
+static const OffloadArchToStringMap arch_names[] = {
 // clang-format off
-{CudaArch::UNUSED, "", ""},
+{OffloadArch::UNUSED, "", ""},
 SM2(20, "compute_20"), SM2(21, "compute_20"), // Fermi
-SM(30), {CudaArch::SM_32_, "sm_32", "compute_32"}, SM(35), SM(37),  // 
Kepler
+SM(30), {OffloadArch::SM_32_, "sm_32", "compute_32"}, SM(35), SM(37),  // 
Kepler
 SM(50), SM(52), SM(53),  // Maxwell
 SM(60), SM(61), SM(62),  // Pascal
 SM(70), SM(72),  // Volta
@@ -112,7 +110,7 @@ static const CudaArchToStringMap arch_names[] = {
 GFX(803),  // gfx803
 GFX(805),  // gfx805
 GFX(810),  // gfx810
-{Cuda

[clang] [llvm] Add f8E4M3 IEEE 754 type to llvm (PR #97179)

2024-06-29 Thread Alexander Pivovarov via cfe-commits

https://github.com/apivovarov updated 
https://github.com/llvm/llvm-project/pull/97179

>From 639ca43f1c57657ecaeb43a097664bae008093fd Mon Sep 17 00:00:00 2001
From: Alexander Pivovarov 
Date: Fri, 28 Jun 2024 21:09:33 +
Subject: [PATCH] Add f8E4M3 IEEE 754 type to llvm

---
 clang/include/clang/AST/Stmt.h |  6 +--
 clang/lib/AST/MicrosoftMangle.cpp  |  1 +
 llvm/include/llvm/ADT/APFloat.h|  6 +++
 llvm/lib/Support/APFloat.cpp   | 20 +
 llvm/unittests/ADT/APFloatTest.cpp | 66 ++
 5 files changed, 96 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index 9cd7a364cd3f1..4edb04502f83e 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -460,10 +460,10 @@ class alignas(void *) Stmt {
 unsigned : NumExprBits;
 
 static_assert(
-llvm::APFloat::S_MaxSemantics < 16,
-"Too many Semantics enum values to fit in bitfield of size 4");
+llvm::APFloat::S_MaxSemantics < 32,
+"Too many Semantics enum values to fit in bitfield of size 5");
 LLVM_PREFERRED_TYPE(llvm::APFloat::Semantics)
-unsigned Semantics : 4; // Provides semantics for APFloat construction
+unsigned Semantics : 5; // Provides semantics for APFloat construction
 LLVM_PREFERRED_TYPE(bool)
 unsigned IsExact : 1;
   };
diff --git a/clang/lib/AST/MicrosoftMangle.cpp 
b/clang/lib/AST/MicrosoftMangle.cpp
index 7f1e9ab02ec26..a2e270df276cb 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -946,6 +946,7 @@ void MicrosoftCXXNameMangler::mangleFloat(llvm::APFloat 
Number) {
   case APFloat::S_IEEEquad: Out << 'Y'; break;
   case APFloat::S_PPCDoubleDouble: Out << 'Z'; break;
   case APFloat::S_Float8E5M2:
+  case APFloat::S_Float8E4M3:
   case APFloat::S_Float8E4M3FN:
   case APFloat::S_Float8E5M2FNUZ:
   case APFloat::S_Float8E4M3FNUZ:
diff --git a/llvm/include/llvm/ADT/APFloat.h b/llvm/include/llvm/ADT/APFloat.h
index db2fa480655c6..bff8e6490d1de 100644
--- a/llvm/include/llvm/ADT/APFloat.h
+++ b/llvm/include/llvm/ADT/APFloat.h
@@ -166,6 +166,9 @@ struct APFloatBase {
 // This format's exponent bias is 16, instead of the 15 (2 ** (5 - 1) - 1)
 // that IEEE precedent would imply.
 S_Float8E5M2FNUZ,
+// 8-bit floating point number following IEEE-754 conventions with bit
+// layout S1E4M3.
+S_Float8E4M3,
 // 8-bit floating point number mostly following IEEE-754 conventions with
 // bit layout S1E4M3 as described in https://arxiv.org/abs/2209.05433.
 // Unlike IEEE-754 types, there are no infinity values, and NaN is
@@ -217,6 +220,7 @@ struct APFloatBase {
   static const fltSemantics &PPCDoubleDouble() LLVM_READNONE;
   static const fltSemantics &Float8E5M2() LLVM_READNONE;
   static const fltSemantics &Float8E5M2FNUZ() LLVM_READNONE;
+  static const fltSemantics &Float8E4M3() LLVM_READNONE;
   static const fltSemantics &Float8E4M3FN() LLVM_READNONE;
   static const fltSemantics &Float8E4M3FNUZ() LLVM_READNONE;
   static const fltSemantics &Float8E4M3B11FNUZ() LLVM_READNONE;
@@ -638,6 +642,7 @@ class IEEEFloat final : public APFloatBase {
   APInt convertPPCDoubleDoubleAPFloatToAPInt() const;
   APInt convertFloat8E5M2APFloatToAPInt() const;
   APInt convertFloat8E5M2FNUZAPFloatToAPInt() const;
+  APInt convertFloat8E4M3APFloatToAPInt() const;
   APInt convertFloat8E4M3FNAPFloatToAPInt() const;
   APInt convertFloat8E4M3FNUZAPFloatToAPInt() const;
   APInt convertFloat8E4M3B11FNUZAPFloatToAPInt() const;
@@ -656,6 +661,7 @@ class IEEEFloat final : public APFloatBase {
   void initFromPPCDoubleDoubleAPInt(const APInt &api);
   void initFromFloat8E5M2APInt(const APInt &api);
   void initFromFloat8E5M2FNUZAPInt(const APInt &api);
+  void initFromFloat8E4M3APInt(const APInt &api);
   void initFromFloat8E4M3FNAPInt(const APInt &api);
   void initFromFloat8E4M3FNUZAPInt(const APInt &api);
   void initFromFloat8E4M3B11FNUZAPInt(const APInt &api);
diff --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp
index 3017a9b976658..79e0094b243b2 100644
--- a/llvm/lib/Support/APFloat.cpp
+++ b/llvm/lib/Support/APFloat.cpp
@@ -136,6 +136,7 @@ static constexpr fltSemantics semIEEEquad = {16383, -16382, 
113, 128};
 static constexpr fltSemantics semFloat8E5M2 = {15, -14, 3, 8};
 static constexpr fltSemantics semFloat8E5M2FNUZ = {
 15, -15, 3, 8, fltNonfiniteBehavior::NanOnly, 
fltNanEncoding::NegativeZero};
+static constexpr fltSemantics semFloat8E4M3 = {7, -6, 4, 8};
 static constexpr fltSemantics semFloat8E4M3FN = {
 8, -6, 4, 8, fltNonfiniteBehavior::NanOnly, fltNanEncoding::AllOnes};
 static constexpr fltSemantics semFloat8E4M3FNUZ = {
@@ -208,6 +209,8 @@ const llvm::fltSemantics 
&APFloatBase::EnumToSemantics(Semantics S) {
 return Float8E5M2();
   case S_Float8E5M2FNUZ:
 return Float8E5M2FNUZ();
+  case S_Float8E4M3:
+return Float8E4M3();
   case S_Float8E4M3FN:
 return

[clang] [llvm] Add f8E4M3 IEEE 754 type to llvm (PR #97179)

2024-06-29 Thread Alexander Pivovarov via cfe-commits

apivovarov wrote:

Thorsten, Matt, What you think about adding the following tests?
```c
// E4M3 <-> E5M2
ConvertE4M3ToE5M2
ConvertE5M2ToE4M3

// E4M3 <-> E4M3FN
ConvertE4M3ToE4M3FN
ConvertE4M3FNToE4M3
```
@tschuett @arsenm

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


[clang] [Clang][ExprConstant] fix constant expression did not evaluate to integer (PR #97146)

2024-06-29 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

I'm concerned that we're calling EvaluateKnownConstInt on an lvalue; that might 
indicate there's something wrong with the AST.  Usually there should be an 
lvalue-to-rvalue cast somewhere.

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


[clang] [clang] Implement function pointer type discrimination (PR #96992)

2024-06-29 Thread Eli Friedman via cfe-commits


@@ -2220,6 +2220,11 @@ llvm::Constant 
*ConstantLValueEmitter::emitPointerAuthPointer(const Expr *E) {
 
   // The assertions here are all checked by Sema.
   assert(Result.Val.isLValue());
+  auto *Base = Result.Val.getLValueBase().get();
+  if (auto *Decl = dyn_cast_or_null(Base)) {
+assert(Result.Val.getLValueOffset().isZero());
+return CGM.getRawFunctionPointer(Decl);

efriedma-quic wrote:

In that case, why are you special-casing functions here?  This looks like 
emitPointerAuthPointer can return either a signed pointer or an unsigned 
pointer, depending on what exactly the expression is referring to, which seems 
bad.

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


[clang] [lldb] [clang][AST] fix ast-print of extern with >=2 declarators, fixed (PR #93913)

2024-06-29 Thread via cfe-commits

temyurchenko wrote:

> Do you need someone to land these changes on your behalf?

Given that the PR is approved, perhaps, yo

> Do you need someone to land these changes on your behalf?

@erichkeane, perhaps you can land these, given that the PR is approved?

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


[clang] eb5dbaf - [clang] Use std::make_unique (NFC) (#97176)

2024-06-29 Thread via cfe-commits

Author: Kazu Hirata
Date: 2024-06-29T16:12:18-07:00
New Revision: eb5dbaf8d013839a66691e954a58d22a41f3c027

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

LOG: [clang] Use std::make_unique (NFC) (#97176)

This patch is based on clang-tidy's modernize-make-unique but limited
to those cases where type names are mentioned twice like
`std::unique_ptr(new Type())`, which is a bit mouthful.

Added: 


Modified: 
clang/lib/CodeGen/CGCoroutine.cpp
clang/lib/Interpreter/CodeCompletion.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGCoroutine.cpp 
b/clang/lib/CodeGen/CGCoroutine.cpp
index b4c724422c14a..a8a70186c2c5a 100644
--- a/clang/lib/CodeGen/CGCoroutine.cpp
+++ b/clang/lib/CodeGen/CGCoroutine.cpp
@@ -103,7 +103,7 @@ static void createCoroData(CodeGenFunction &CGF,
 return;
   }
 
-  CurCoro.Data = std::unique_ptr(new CGCoroData);
+  CurCoro.Data = std::make_unique();
   CurCoro.Data->CoroId = CoroId;
   CurCoro.Data->CoroIdExpr = CoroIdExpr;
 }

diff  --git a/clang/lib/Interpreter/CodeCompletion.cpp 
b/clang/lib/Interpreter/CodeCompletion.cpp
index 25183ae9eeb99..791426807cb91 100644
--- a/clang/lib/Interpreter/CodeCompletion.cpp
+++ b/clang/lib/Interpreter/CodeCompletion.cpp
@@ -368,8 +368,7 @@ void ReplCodeCompleter::codeComplete(CompilerInstance 
*InterpCI,
   llvm::SmallVector tb = {};
   InterpCI->getFrontendOpts().Inputs[0] = FrontendInputFile(
   CodeCompletionFileName, Language::CXX, InputKind::Source);
-  auto Act = std::unique_ptr(
-  new IncrementalSyntaxOnlyAction(ParentCI));
+  auto Act = std::make_unique(ParentCI);
   std::unique_ptr MB =
   llvm::MemoryBuffer::getMemBufferCopy(Content, CodeCompletionFileName);
   llvm::SmallVector RemappedFiles;



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


[clang] [clang] Use std::make_unique (NFC) (PR #97176)

2024-06-29 Thread Kazu Hirata via cfe-commits

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


[clang] Improve error message for invalid lambda captures (PR #94865)

2024-06-29 Thread via cfe-commits

https://github.com/CedricSwa updated 
https://github.com/llvm/llvm-project/pull/94865

>From 012849c5410960001ca5bbcb90ea2cf4a661b840 Mon Sep 17 00:00:00 2001
From: Cedric Schwarzer 
Date: Sat, 8 Jun 2024 17:52:02 +0200
Subject: [PATCH 1/5] Improve error message for invalid lambda captures

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 ++
 clang/lib/Sema/SemaLambda.cpp| 7 ++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 9f0b6f5a36389..fdf4409125c00 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8173,6 +8173,8 @@ let CategoryName = "Lambda Issue" in {
 "'&' must precede a capture when the capture default is '='">;
   def err_capture_does_not_name_variable : Error<
 "%0 in capture list does not name a variable">;
+  def err_capture_class_member_does_not_name_variable : Error<
+"class member %0 cannot appear in capture list as it is not a variable">;
   def err_capture_non_automatic_variable : Error<
 "%0 cannot be captured because it does not have automatic storage "
 "duration">;
diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index e9476a0c93c5d..79c10c3bad6d7 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -1246,7 +1246,12 @@ void 
Sema::ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro,
 
   if (auto *BD = R.getAsSingle())
 Var = BD;
-  else
+  else if (auto *FD = R.getAsSingle()) {
+Var = R.getAsSingle();
+Diag(C->Loc, diag::err_capture_class_member_does_not_name_variable)
+<< C->Id;
+continue;
+  } else
 Var = R.getAsSingle();
   if (Var && DiagnoseUseOfDecl(Var, C->Loc))
 continue;

>From dc1ca518ea4a4b5407decd9d99e561282cf7f4e4 Mon Sep 17 00:00:00 2001
From: "cedric.SWA" 
Date: Mon, 10 Jun 2024 20:48:59 +0200
Subject: [PATCH 2/5] remove unnecessary variable assignment

---
 clang/lib/Sema/SemaLambda.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index 79c10c3bad6d7..97f1d9428fef6 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -1247,7 +1247,6 @@ void 
Sema::ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro,
   if (auto *BD = R.getAsSingle())
 Var = BD;
   else if (auto *FD = R.getAsSingle()) {
-Var = R.getAsSingle();
 Diag(C->Loc, diag::err_capture_class_member_does_not_name_variable)
 << C->Id;
 continue;

>From 9ec08c86a22060a42996fdbc131a864e16ccb0d8 Mon Sep 17 00:00:00 2001
From: "cedric.SWA" 
Date: Tue, 25 Jun 2024 17:09:39 +0200
Subject: [PATCH 3/5] test for lambda try captureing class member

---
 clang/test/SemaCXX/lambda-expressions.cpp | 9 +
 1 file changed, 9 insertions(+)

diff --git a/clang/test/SemaCXX/lambda-expressions.cpp 
b/clang/test/SemaCXX/lambda-expressions.cpp
index 151d74f21d64d..acf8d014a9896 100644
--- a/clang/test/SemaCXX/lambda-expressions.cpp
+++ b/clang/test/SemaCXX/lambda-expressions.cpp
@@ -609,6 +609,15 @@ namespace PR25627_dont_odr_use_local_consts {
   }
 }
 
+namespace PR94764 {
+  struct X {
+int x;
+void foo() {
+  [x](){}; // expected-error{{class member 'x' cannot appear in capture 
list as it is not a variable}}
+}
+  };
+}
+
 namespace ConversionOperatorDoesNotHaveDeducedReturnType {
   auto x = [](int){};
   auto y = [](auto &v) -> void { v.n = 0; }; // cxx03-cxx11-error {{'auto' not 
allowed in lambda parameter}} cxx03-cxx11-note {{candidate function not 
viable}} cxx03-cxx11-note {{conversion candidate}}

>From 9bed94ac9c0620807b1c9054fd36a5aaa7b0d8ab Mon Sep 17 00:00:00 2001
From: "cedric.SWA" 
Date: Tue, 25 Jun 2024 18:12:20 +0200
Subject: [PATCH 4/5] add to diagnostic improvements in release notes

---
 clang/docs/ReleaseNotes.rst | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b9c9070fcb22f..8358e8e32f18c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -569,6 +569,8 @@ Improvements to Clang's diagnostics
 - Clang no longer emits a "declared here" note for a builtin function that has 
no declaration in source.
   Fixes #GH93369.
 
+- Clang now has an improved error message when trying to capture a variable 
for lambda function expressions.
+
 Improvements to Clang's time-trace
 --
 

>From f5bb934f43b4185f8574e1dd198e02a6a2431d11 Mon Sep 17 00:00:00 2001
From: "cedric.SWA" 
Date: Sun, 30 Jun 2024 01:28:45 +0200
Subject: [PATCH 5/5] more explicit release note

---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 82441bcbf4d95..

[clang] [clang] Default to -fno-sized-deallocation for AIX (PR #97076)

2024-06-29 Thread Xing Xue via cfe-commits

https://github.com/xingxue-ibm updated 
https://github.com/llvm/llvm-project/pull/97076

>From d6a486c4f007297d087fe4454da3ec501e824825 Mon Sep 17 00:00:00 2001
From: Xing Xue 
Date: Fri, 28 Jun 2024 11:25:25 -0400
Subject: [PATCH 1/2] Default to -fno-sized-deallocation for AIX.

---
 clang/lib/Driver/ToolChains/AIX.cpp  | 6 ++
 clang/unittests/StaticAnalyzer/CallEventTest.cpp | 4 
 2 files changed, 10 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/AIX.cpp 
b/clang/lib/Driver/ToolChains/AIX.cpp
index 381d72e045b95..b04502a57a9f7 100644
--- a/clang/lib/Driver/ToolChains/AIX.cpp
+++ b/clang/lib/Driver/ToolChains/AIX.cpp
@@ -551,6 +551,12 @@ void AIX::addClangTargetOptions(
   if (Args.hasFlag(options::OPT_fxl_pragma_pack,
options::OPT_fno_xl_pragma_pack, true))
 CC1Args.push_back("-fxl-pragma-pack");
+
+  // Pass "-fno-sized-deallocation" only when the user hasn't manually enabled
+  // or disabled sized deallocations.
+  if (!Args.getLastArgNoClaim(options::OPT_fsized_deallocation,
+  options::OPT_fno_sized_deallocation))
+CC1Args.push_back("-fno-sized-deallocation");
 }
 
 void AIX::addProfileRTLibs(const llvm::opt::ArgList &Args,
diff --git a/clang/unittests/StaticAnalyzer/CallEventTest.cpp 
b/clang/unittests/StaticAnalyzer/CallEventTest.cpp
index 7c4132788ca7e..de28bb158ef66 100644
--- a/clang/unittests/StaticAnalyzer/CallEventTest.cpp
+++ b/clang/unittests/StaticAnalyzer/CallEventTest.cpp
@@ -76,7 +76,11 @@ TEST(CXXDeallocatorCall, SimpleDestructor) {
 }
   )",
  Diags));
+#if !defined(__cpp_sized_deallocation)
+  EXPECT_EQ(Diags, "test.CXXDeallocator: NumArgs: 1\n");
+#else
   EXPECT_EQ(Diags, "test.CXXDeallocator: NumArgs: 2\n");
+#endif
 }
 
 } // namespace

>From 612f60e20ba45dd91cd6722a8df33410f452127e Mon Sep 17 00:00:00 2001
From: Xing Xue 
Date: Sat, 29 Jun 2024 19:35:18 -0400
Subject: [PATCH 2/2] Guard the NumArgs check with OS macros instead of
 __cpp_sized_deallocation because the latter is not defined for the test.

---
 clang/unittests/StaticAnalyzer/CallEventTest.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/unittests/StaticAnalyzer/CallEventTest.cpp 
b/clang/unittests/StaticAnalyzer/CallEventTest.cpp
index de28bb158ef66..987162f9fdf34 100644
--- a/clang/unittests/StaticAnalyzer/CallEventTest.cpp
+++ b/clang/unittests/StaticAnalyzer/CallEventTest.cpp
@@ -76,7 +76,8 @@ TEST(CXXDeallocatorCall, SimpleDestructor) {
 }
   )",
  Diags));
-#if !defined(__cpp_sized_deallocation)
+#if defined(_AIX) || defined(__MVS__)
+  // AIX and ZOS default to -fno-sized-deallocation.
   EXPECT_EQ(Diags, "test.CXXDeallocator: NumArgs: 1\n");
 #else
   EXPECT_EQ(Diags, "test.CXXDeallocator: NumArgs: 2\n");

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


[clang] Improve error message for invalid lambda captures (PR #94865)

2024-06-29 Thread via cfe-commits

https://github.com/CedricSwa updated 
https://github.com/llvm/llvm-project/pull/94865

>From 012849c5410960001ca5bbcb90ea2cf4a661b840 Mon Sep 17 00:00:00 2001
From: Cedric Schwarzer 
Date: Sat, 8 Jun 2024 17:52:02 +0200
Subject: [PATCH 1/5] Improve error message for invalid lambda captures

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 ++
 clang/lib/Sema/SemaLambda.cpp| 7 ++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 9f0b6f5a36389..fdf4409125c00 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8173,6 +8173,8 @@ let CategoryName = "Lambda Issue" in {
 "'&' must precede a capture when the capture default is '='">;
   def err_capture_does_not_name_variable : Error<
 "%0 in capture list does not name a variable">;
+  def err_capture_class_member_does_not_name_variable : Error<
+"class member %0 cannot appear in capture list as it is not a variable">;
   def err_capture_non_automatic_variable : Error<
 "%0 cannot be captured because it does not have automatic storage "
 "duration">;
diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index e9476a0c93c5d..79c10c3bad6d7 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -1246,7 +1246,12 @@ void 
Sema::ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro,
 
   if (auto *BD = R.getAsSingle())
 Var = BD;
-  else
+  else if (auto *FD = R.getAsSingle()) {
+Var = R.getAsSingle();
+Diag(C->Loc, diag::err_capture_class_member_does_not_name_variable)
+<< C->Id;
+continue;
+  } else
 Var = R.getAsSingle();
   if (Var && DiagnoseUseOfDecl(Var, C->Loc))
 continue;

>From dc1ca518ea4a4b5407decd9d99e561282cf7f4e4 Mon Sep 17 00:00:00 2001
From: "cedric.SWA" 
Date: Mon, 10 Jun 2024 20:48:59 +0200
Subject: [PATCH 2/5] remove unnecessary variable assignment

---
 clang/lib/Sema/SemaLambda.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index 79c10c3bad6d7..97f1d9428fef6 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -1247,7 +1247,6 @@ void 
Sema::ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro,
   if (auto *BD = R.getAsSingle())
 Var = BD;
   else if (auto *FD = R.getAsSingle()) {
-Var = R.getAsSingle();
 Diag(C->Loc, diag::err_capture_class_member_does_not_name_variable)
 << C->Id;
 continue;

>From 9ec08c86a22060a42996fdbc131a864e16ccb0d8 Mon Sep 17 00:00:00 2001
From: "cedric.SWA" 
Date: Tue, 25 Jun 2024 17:09:39 +0200
Subject: [PATCH 3/5] test for lambda try captureing class member

---
 clang/test/SemaCXX/lambda-expressions.cpp | 9 +
 1 file changed, 9 insertions(+)

diff --git a/clang/test/SemaCXX/lambda-expressions.cpp 
b/clang/test/SemaCXX/lambda-expressions.cpp
index 151d74f21d64d..acf8d014a9896 100644
--- a/clang/test/SemaCXX/lambda-expressions.cpp
+++ b/clang/test/SemaCXX/lambda-expressions.cpp
@@ -609,6 +609,15 @@ namespace PR25627_dont_odr_use_local_consts {
   }
 }
 
+namespace PR94764 {
+  struct X {
+int x;
+void foo() {
+  [x](){}; // expected-error{{class member 'x' cannot appear in capture 
list as it is not a variable}}
+}
+  };
+}
+
 namespace ConversionOperatorDoesNotHaveDeducedReturnType {
   auto x = [](int){};
   auto y = [](auto &v) -> void { v.n = 0; }; // cxx03-cxx11-error {{'auto' not 
allowed in lambda parameter}} cxx03-cxx11-note {{candidate function not 
viable}} cxx03-cxx11-note {{conversion candidate}}

>From 9bed94ac9c0620807b1c9054fd36a5aaa7b0d8ab Mon Sep 17 00:00:00 2001
From: "cedric.SWA" 
Date: Tue, 25 Jun 2024 18:12:20 +0200
Subject: [PATCH 4/5] add to diagnostic improvements in release notes

---
 clang/docs/ReleaseNotes.rst | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b9c9070fcb22f..8358e8e32f18c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -569,6 +569,8 @@ Improvements to Clang's diagnostics
 - Clang no longer emits a "declared here" note for a builtin function that has 
no declaration in source.
   Fixes #GH93369.
 
+- Clang now has an improved error message when trying to capture a variable 
for lambda function expressions.
+
 Improvements to Clang's time-trace
 --
 

>From f5bb934f43b4185f8574e1dd198e02a6a2431d11 Mon Sep 17 00:00:00 2001
From: "cedric.SWA" 
Date: Sun, 30 Jun 2024 01:28:45 +0200
Subject: [PATCH 5/5] more explicit release note

---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 82441bcbf4d95..

[clang] [clang-tools-extra] [clang-format] Aggregate options regarding empty lines (PR #96770)

2024-06-29 Thread via cfe-commits

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


[clang] 2853a83 - [clang-format] Add option to remove leading blank lines (#91221)

2024-06-29 Thread via cfe-commits

Author: sstwcw
Date: 2024-06-30T01:20:20Z
New Revision: 2853a838d22b69f61ed376abbd9ab5e625111f44

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

LOG: [clang-format] Add option to remove leading blank lines (#91221)

The options regarding which blank lines are kept are also aggregated.
The new option is `KeepEmptyLines`.

This patch was initially part of 9267f8f19a2e502e.  I neglected to check
the server builds before I added it.  It broke clangd.  Jie Fu fixed the
problem in 4c91b49bab0728d4.  I was unaware of it.  I thought the main
branch was still broken.  I reverted the first patch in
70cfece24d6cbb57.  It broke his fix.  He reverted it in
c69ea04fb9738db2.  Now the feature is added again including the fix.

Added: 


Modified: 
clang-tools-extra/clangd/Format.cpp
clang/docs/ClangFormatStyleOptions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Format/Format.h
clang/lib/Format/Format.cpp
clang/lib/Format/UnwrappedLineFormatter.cpp
clang/unittests/Format/ConfigParseTest.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Format.cpp 
b/clang-tools-extra/clangd/Format.cpp
index 272a34d4ed797..f6fc72c1dd559 100644
--- a/clang-tools-extra/clangd/Format.cpp
+++ b/clang-tools-extra/clangd/Format.cpp
@@ -281,7 +281,11 @@ formatIncremental(llvm::StringRef OriginalCode, unsigned 
OriginalCursor,
   // Never *remove* lines in response to pressing enter! This annoys users.
   if (InsertedText == "\n") {
 Style.MaxEmptyLinesToKeep = 1000;
-Style.KeepEmptyLinesAtTheStartOfBlocks = true;
+Style.KeepEmptyLines = {
+/*AtEndOfFile=*/true,
+/*AtStartOfBlock=*/true,
+/*AtStartOfFile=*/true,
+};
   }
 
   // Compute the code we want to format:

diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index bb00c20922d36..080cba90c4a8b 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -4443,23 +4443,51 @@ the configuration (without a prefix: ``Auto``).
  false:
  import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, 
VeryLongImportsAreAnnoying,} from "some/module.js"
 
+.. _KeepEmptyLines:
+
+**KeepEmptyLines** (``KeepEmptyLinesStyle``) :versionbadge:`clang-format 19` 
:ref:`¶ `
+  Which empty lines are kept.  See ``MaxEmptyLinesToKeep`` for how many
+  consecutive empty lines are kept.
+
+  Nested configuration flags:
+
+  Options regarding which empty lines are kept.
+
+  For example, the config below will remove empty lines at start of the
+  file, end of the file, and start of blocks.
+
+
+  .. code-block:: c++
+
+KeepEmptyLines:
+  AtEndOfFile: false
+  AtStartOfBlock: false
+  AtStartOfFile: false
+
+  * ``bool AtEndOfFile`` Keep empty lines at end of file.
+
+  * ``bool AtStartOfBlock`` Keep empty lines at start of a block.
+
+.. code-block:: c++
+
+   true:  false:
+   if (foo) { vs. if (foo) {
+bar();
+ bar();   }
+   }
+
+  * ``bool AtStartOfFile`` Keep empty lines at start of file.
+
+
 .. _KeepEmptyLinesAtEOF:
 
 **KeepEmptyLinesAtEOF** (``Boolean``) :versionbadge:`clang-format 17` :ref:`¶ 
`
-  Keep empty lines (up to ``MaxEmptyLinesToKeep``) at end of file.
+  This option is deprecated. See ``AtEndOfFile`` of ``KeepEmptyLines``.
 
 .. _KeepEmptyLinesAtTheStartOfBlocks:
 
 **KeepEmptyLinesAtTheStartOfBlocks** (``Boolean``) :versionbadge:`clang-format 
3.7` :ref:`¶ `
-  If true, the empty line at the start of blocks is kept.
-
-  .. code-block:: c++
-
- true:  false:
- if (foo) { vs. if (foo) {
-  bar();
-   bar();   }
- }
+  This option is deprecated. See ``AtStartOfBlock`` of ``KeepEmptyLines``.
 
 .. _LambdaBodyIndentation:
 

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index feba3c7ba8d77..35d2509eacece 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1112,6 +1112,8 @@ clang-format
 - Adds ``AllowShortCaseExpressionOnASingleLine`` option.
 - Adds ``AlignCaseArrows`` suboption to 
``AlignConsecutiveShortCaseStatements``.
 - Adds ``LeftWithLastLine`` suboption to ``AlignEscapedNewlines``.
+- Adds ``KeepEmptyLines`` option to deprecate ``KeepEmptyLinesAtEOF``
+  and ``KeepEmptyLinesAtTheStartOfBlocks``.
 
 libclang
 

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 7d257be10af42..efc2e450b723f 100644
--- a/clang/include/clang/Format/Format.h

[clang] Improve error message for invalid lambda captures (PR #94865)

2024-06-29 Thread via cfe-commits

https://github.com/CedricSwa updated 
https://github.com/llvm/llvm-project/pull/94865

>From 012849c5410960001ca5bbcb90ea2cf4a661b840 Mon Sep 17 00:00:00 2001
From: Cedric Schwarzer 
Date: Sat, 8 Jun 2024 17:52:02 +0200
Subject: [PATCH 1/5] Improve error message for invalid lambda captures

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 ++
 clang/lib/Sema/SemaLambda.cpp| 7 ++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 9f0b6f5a36389..fdf4409125c00 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8173,6 +8173,8 @@ let CategoryName = "Lambda Issue" in {
 "'&' must precede a capture when the capture default is '='">;
   def err_capture_does_not_name_variable : Error<
 "%0 in capture list does not name a variable">;
+  def err_capture_class_member_does_not_name_variable : Error<
+"class member %0 cannot appear in capture list as it is not a variable">;
   def err_capture_non_automatic_variable : Error<
 "%0 cannot be captured because it does not have automatic storage "
 "duration">;
diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index e9476a0c93c5d..79c10c3bad6d7 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -1246,7 +1246,12 @@ void 
Sema::ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro,
 
   if (auto *BD = R.getAsSingle())
 Var = BD;
-  else
+  else if (auto *FD = R.getAsSingle()) {
+Var = R.getAsSingle();
+Diag(C->Loc, diag::err_capture_class_member_does_not_name_variable)
+<< C->Id;
+continue;
+  } else
 Var = R.getAsSingle();
   if (Var && DiagnoseUseOfDecl(Var, C->Loc))
 continue;

>From dc1ca518ea4a4b5407decd9d99e561282cf7f4e4 Mon Sep 17 00:00:00 2001
From: "cedric.SWA" 
Date: Mon, 10 Jun 2024 20:48:59 +0200
Subject: [PATCH 2/5] remove unnecessary variable assignment

---
 clang/lib/Sema/SemaLambda.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index 79c10c3bad6d7..97f1d9428fef6 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -1247,7 +1247,6 @@ void 
Sema::ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro,
   if (auto *BD = R.getAsSingle())
 Var = BD;
   else if (auto *FD = R.getAsSingle()) {
-Var = R.getAsSingle();
 Diag(C->Loc, diag::err_capture_class_member_does_not_name_variable)
 << C->Id;
 continue;

>From 9ec08c86a22060a42996fdbc131a864e16ccb0d8 Mon Sep 17 00:00:00 2001
From: "cedric.SWA" 
Date: Tue, 25 Jun 2024 17:09:39 +0200
Subject: [PATCH 3/5] test for lambda try captureing class member

---
 clang/test/SemaCXX/lambda-expressions.cpp | 9 +
 1 file changed, 9 insertions(+)

diff --git a/clang/test/SemaCXX/lambda-expressions.cpp 
b/clang/test/SemaCXX/lambda-expressions.cpp
index 151d74f21d64d..acf8d014a9896 100644
--- a/clang/test/SemaCXX/lambda-expressions.cpp
+++ b/clang/test/SemaCXX/lambda-expressions.cpp
@@ -609,6 +609,15 @@ namespace PR25627_dont_odr_use_local_consts {
   }
 }
 
+namespace PR94764 {
+  struct X {
+int x;
+void foo() {
+  [x](){}; // expected-error{{class member 'x' cannot appear in capture 
list as it is not a variable}}
+}
+  };
+}
+
 namespace ConversionOperatorDoesNotHaveDeducedReturnType {
   auto x = [](int){};
   auto y = [](auto &v) -> void { v.n = 0; }; // cxx03-cxx11-error {{'auto' not 
allowed in lambda parameter}} cxx03-cxx11-note {{candidate function not 
viable}} cxx03-cxx11-note {{conversion candidate}}

>From 9bed94ac9c0620807b1c9054fd36a5aaa7b0d8ab Mon Sep 17 00:00:00 2001
From: "cedric.SWA" 
Date: Tue, 25 Jun 2024 18:12:20 +0200
Subject: [PATCH 4/5] add to diagnostic improvements in release notes

---
 clang/docs/ReleaseNotes.rst | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b9c9070fcb22f..8358e8e32f18c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -569,6 +569,8 @@ Improvements to Clang's diagnostics
 - Clang no longer emits a "declared here" note for a builtin function that has 
no declaration in source.
   Fixes #GH93369.
 
+- Clang now has an improved error message when trying to capture a variable 
for lambda function expressions.
+
 Improvements to Clang's time-trace
 --
 

>From f5bb934f43b4185f8574e1dd198e02a6a2431d11 Mon Sep 17 00:00:00 2001
From: "cedric.SWA" 
Date: Sun, 30 Jun 2024 01:28:45 +0200
Subject: [PATCH 5/5] more explicit release note

---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 82441bcbf4d95..

[clang-tools-extra] aec7670 - [clangd] Revert the change concerning new lines

2024-06-29 Thread via cfe-commits

Author: sstwcw
Date: 2024-06-30T02:04:44Z
New Revision: aec7670b5d6354b63b011c9ed0632b70983b0328

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

LOG: [clangd] Revert the change concerning new lines

See the comment.

https://github.com/llvm/llvm-project/commit/2853a838d22b69f61ed376abbd9ab5e625111f44#r143690024

Added: 


Modified: 
clang-tools-extra/clangd/Format.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Format.cpp 
b/clang-tools-extra/clangd/Format.cpp
index f6fc72c1dd559..fc56a1c8c5030 100644
--- a/clang-tools-extra/clangd/Format.cpp
+++ b/clang-tools-extra/clangd/Format.cpp
@@ -281,11 +281,7 @@ formatIncremental(llvm::StringRef OriginalCode, unsigned 
OriginalCursor,
   // Never *remove* lines in response to pressing enter! This annoys users.
   if (InsertedText == "\n") {
 Style.MaxEmptyLinesToKeep = 1000;
-Style.KeepEmptyLines = {
-/*AtEndOfFile=*/true,
-/*AtStartOfBlock=*/true,
-/*AtStartOfFile=*/true,
-};
+Style.KeepEmptyLines.AtStartOfBlock = true;
   }
 
   // Compute the code we want to format:



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


[clang] [clang-format] Add option to remove leading blank lines (PR #91221)

2024-06-29 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `sanitizer-aarch64-linux` 
running on `sanitizer-buildbot7` while building `clang-tools-extra,clang` at 
step 2 "annotate".

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

Here is the relevant piece of the build log for the reference:
```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
llvm-lit: 
/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-aarch64-linux/build/compiler_rt_build/lib/aarch64-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-aarch64-linux/build/build_default/bin/clang', 
'--target=aarch64-unknown-linux-gnu', '-Wthread-safety', 
'-Wthread-safety-reference', '-Wthread-safety-beta', '-nobuiltininc', 
'-I/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/include', 
'-idirafter', 
'/b/sanitizer-aarch64-linux/build/build_default/lib/clang/19/include', 
'-resource-dir=/b/sanitizer-aarch64-linux/build/compiler_rt_build', 
'-Wl,-rpath,/b/sanitizer-aarch64-linux/build/compiler_rt_build/lib/linux', 
'-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-aarch64-linux/build/compiler_rt_build/lib/aarch64-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-aarch64-linux/build/build_default/bin/clang', 
'--target=aarch64-unknown-linux-gnu', '-Wthread-safety', 
'-Wthread-safety-reference', '-Wthread-safety-beta', '-nobuiltininc', 
'-I/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/include', 
'-idirafter', 
'/b/sanitizer-aarch64-linux/build/build_default/lib/clang/19/include', 
'-resource-dir=/b/sanitizer-aarch64-linux/build/compiler_rt_build', 
'-Wl,-rpath,/b/sanitizer-aarch64-linux/build/compiler_rt_build/lib/linux', 
'-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-aarch64-linux/build/compiler_rt_build/lib/aarch64-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-aarch64-linux/build/build_default/bin/clang', 
'--target=aarch64-unknown-linux-gnu', '-Wthread-safety', 
'-Wthread-safety-reference', '-Wthread-safety-beta', '-nobuiltininc', 
'-I/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/include', 
'-idirafter', 
'/b/sanitizer-aarch64-linux/build/build_default/lib/clang/19/include', 
'-resource-dir=/b/sanitizer-aarch64-linux/build/compiler_rt_build', 
'-Wl,-rpath,/b/sanitizer-aarch64-linux/build/compiler_rt_build/lib/linux', 
'-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-aarch64-linux/build/compiler_rt_build/lib/aarch64-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-aarch64-linux/build/build_default/bin/clang', 
'--target=aarch64-unknown-linux-gnu', '-Wthread-safety', 
'-Wthread-safety-reference', '-Wthread-safety-beta', '-nobuiltininc', 
'-I/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/include', 
'-idirafter', 
'/b/sanitizer-aarch64-linux/build/build_default/lib/clang/19/include', 
'-resource-dir=/b/sanitizer-aarch64-linux/build/compiler_rt_build', 
'-Wl,-rpath,/b/sanitizer-aarch64-linux/build/compiler_rt_build/lib/linux', 
'-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-aarch64-linux/build/compiler_rt_build/lib/aarch64-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-aarch64-linux/build/build_default/bin/clang', 
'--target=aarch64-unknown-linux-gnu', '-Wthread-safety', 
'-Wthread-safety-reference', '-Wthread-safety-beta', '-nobuiltininc', 
'-I/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/include', 
'-idirafter', 
'/b/sanitizer-aarch64-linux/build/build_default/lib/clang/19/include', 
'-resource-dir=/b/sanitizer-aarch64-linux/build/compiler_rt_build', 
'-Wl,-rpath,/b/sanitizer-aarch64-linux/build/compiler_rt_build/lib/linux', 
'-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-aarch64-linux/build/compiler_rt_build/lib/aarch64-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-aarch64-linux/build/build_default/bin/clang', 
'--target=aarch64-unknown-linux-gnu', '-Wthread-safety', 
'-Wthread-safety-reference', '-Wthread-safety-beta', '-nobuiltininc', 
'-I/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/include', 
'-idirafter', 
'/b/sanitizer-aarch64-linux/build/build_default/lib/clang/19/inc

[clang] [llvm] [WebAssembly] support getVT from `externref` and `funcref` (PR #97080)

2024-06-29 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/97080

>From b49737505ad3ad84e977787daf141b98fe3e6607 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sat, 29 Jun 2024 00:24:30 +0800
Subject: [PATCH 1/2] [WebAssembly] support getVT from wasm externref and
 funcref

---
 .../CodeGen/WebAssembly/wasm-externref-novec.c | 18 ++
 llvm/include/llvm/IR/Type.h|  2 ++
 llvm/lib/CodeGen/ValueTypes.cpp|  9 +
 llvm/lib/IR/Type.cpp   |  4 ++--
 4 files changed, 31 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/CodeGen/WebAssembly/wasm-externref-novec.c

diff --git a/clang/test/CodeGen/WebAssembly/wasm-externref-novec.c 
b/clang/test/CodeGen/WebAssembly/wasm-externref-novec.c
new file mode 100644
index 0..d91072f379623
--- /dev/null
+++ b/clang/test/CodeGen/WebAssembly/wasm-externref-novec.c
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -O2 -triple wasm32-unknown-unknown-wasm -target-feature 
+reference-types -emit-llvm -o - %s | FileCheck %s
+
+// From issue 69894. Reftypes need to be marked as not valid as vector 
elements.
+
+__externref_t foo(void);
+// CHECK: declare ptr addrspace(10) @foo()
+
+void bar(__externref_t);
+// CHECK: declare void @bar(ptr addrspace(10))
+
+void test(int flag, __externref_t ref1, __externref_t ref2) {
+  if (flag) {
+ref1 = foo();
+ref2 = foo();
+  }
+  bar(ref1);
+  bar(ref2);
+}
diff --git a/llvm/include/llvm/IR/Type.h b/llvm/include/llvm/IR/Type.h
index 1f0133c08e7d6..cacb0539b3ddf 100644
--- a/llvm/include/llvm/IR/Type.h
+++ b/llvm/include/llvm/IR/Type.h
@@ -479,6 +479,8 @@ class Type {
   }
   static Type *getFloatingPointTy(LLVMContext &C, const fltSemantics &S);
 
+  static constexpr unsigned WasmExternrefAddressSpace = 10;
+  static constexpr unsigned WasmFuncrefAddressSpace = 20;
   
//======//
   // Convenience methods for getting pointer types.
   //
diff --git a/llvm/lib/CodeGen/ValueTypes.cpp b/llvm/lib/CodeGen/ValueTypes.cpp
index b0f736a49c20e..5aa7c406206d9 100644
--- a/llvm/lib/CodeGen/ValueTypes.cpp
+++ b/llvm/lib/CodeGen/ValueTypes.cpp
@@ -263,6 +263,15 @@ MVT MVT::getVT(Type *Ty, bool HandleUnknown){
   getVT(VTy->getElementType(), /*HandleUnknown=*/ false),
 VTy->getElementCount());
   }
+  case Type::PointerTyID: {
+if (Ty->getPointerAddressSpace() == Type::WasmExternrefAddressSpace)
+  return MVT(MVT::externref);
+if (Ty->getPointerAddressSpace() == Type::WasmFuncrefAddressSpace)
+  return MVT(MVT::funcref);
+if (HandleUnknown)
+  return MVT(MVT::Other);
+llvm_unreachable("Unknown pointer type!");
+  }
   }
 }
 
diff --git a/llvm/lib/IR/Type.cpp b/llvm/lib/IR/Type.cpp
index 5c61ad9f000b0..2279b5eb873b7 100644
--- a/llvm/lib/IR/Type.cpp
+++ b/llvm/lib/IR/Type.cpp
@@ -261,13 +261,13 @@ IntegerType *Type::getIntNTy(LLVMContext &C, unsigned N) {
 
 Type *Type::getWasm_ExternrefTy(LLVMContext &C) {
   // opaque pointer in addrspace(10)
-  static PointerType *Ty = PointerType::get(C, 10);
+  static PointerType *Ty = PointerType::get(C, WasmExternrefAddressSpace);
   return Ty;
 }
 
 Type *Type::getWasm_FuncrefTy(LLVMContext &C) {
   // opaque pointer in addrspace(20)
-  static PointerType *Ty = PointerType::get(C, 20);
+  static PointerType *Ty = PointerType::get(C, WasmFuncrefAddressSpace);
   return Ty;
 }
 

>From 20d847ee59be5a8cf4d4ffde2228cba2c5534e68 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sun, 30 Jun 2024 10:29:21 +0800
Subject: [PATCH 2/2] update test

---
 clang/test/CodeGen/WebAssembly/wasm-externref-novec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/test/CodeGen/WebAssembly/wasm-externref-novec.c 
b/clang/test/CodeGen/WebAssembly/wasm-externref-novec.c
index d91072f379623..30942773b1ae5 100644
--- a/clang/test/CodeGen/WebAssembly/wasm-externref-novec.c
+++ b/clang/test/CodeGen/WebAssembly/wasm-externref-novec.c
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -O2 -triple wasm32-unknown-unknown-wasm -target-feature 
+reference-types -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang -O2 --target=wasm32 -S -emit-llvm -mreference-types -o - %s | 
FileCheck %s
 
-// From issue 69894. Reftypes need to be marked as not valid as vector 
elements.
+// Issue: https://github.com/llvm/llvm-project/issues/69894
 
 __externref_t foo(void);
 // CHECK: declare ptr addrspace(10) @foo()

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


[clang] [Clang][ExprConstant] fix constant expression did not evaluate to integer (PR #97146)

2024-06-29 Thread Zhikai Zeng via cfe-commits

Backl1ght wrote:

> I'm concerned that we're calling EvaluateKnownConstInt on an lvalue; that 
> might indicate there's something wrong with the AST. Usually there should be 
> an lvalue-to-rvalue cast somewhere.

@efriedma-quic lvalue-to-rvalue cast is done here at 
https://github.com/llvm/llvm-project/blob/aec7670b5d6354b63b011c9ed0632b70983b0328/clang/lib/AST/ExprConstant.cpp#L15829-L15835

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


[clang] [llvm] [WebAssembly] support getVT from `externref` and `funcref` (PR #97080)

2024-06-29 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/97080

>From b49737505ad3ad84e977787daf141b98fe3e6607 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sat, 29 Jun 2024 00:24:30 +0800
Subject: [PATCH 1/2] [WebAssembly] support getVT from wasm externref and
 funcref

---
 .../CodeGen/WebAssembly/wasm-externref-novec.c | 18 ++
 llvm/include/llvm/IR/Type.h|  2 ++
 llvm/lib/CodeGen/ValueTypes.cpp|  9 +
 llvm/lib/IR/Type.cpp   |  4 ++--
 4 files changed, 31 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/CodeGen/WebAssembly/wasm-externref-novec.c

diff --git a/clang/test/CodeGen/WebAssembly/wasm-externref-novec.c 
b/clang/test/CodeGen/WebAssembly/wasm-externref-novec.c
new file mode 100644
index 0..d91072f379623
--- /dev/null
+++ b/clang/test/CodeGen/WebAssembly/wasm-externref-novec.c
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -O2 -triple wasm32-unknown-unknown-wasm -target-feature 
+reference-types -emit-llvm -o - %s | FileCheck %s
+
+// From issue 69894. Reftypes need to be marked as not valid as vector 
elements.
+
+__externref_t foo(void);
+// CHECK: declare ptr addrspace(10) @foo()
+
+void bar(__externref_t);
+// CHECK: declare void @bar(ptr addrspace(10))
+
+void test(int flag, __externref_t ref1, __externref_t ref2) {
+  if (flag) {
+ref1 = foo();
+ref2 = foo();
+  }
+  bar(ref1);
+  bar(ref2);
+}
diff --git a/llvm/include/llvm/IR/Type.h b/llvm/include/llvm/IR/Type.h
index 1f0133c08e7d6..cacb0539b3ddf 100644
--- a/llvm/include/llvm/IR/Type.h
+++ b/llvm/include/llvm/IR/Type.h
@@ -479,6 +479,8 @@ class Type {
   }
   static Type *getFloatingPointTy(LLVMContext &C, const fltSemantics &S);
 
+  static constexpr unsigned WasmExternrefAddressSpace = 10;
+  static constexpr unsigned WasmFuncrefAddressSpace = 20;
   
//======//
   // Convenience methods for getting pointer types.
   //
diff --git a/llvm/lib/CodeGen/ValueTypes.cpp b/llvm/lib/CodeGen/ValueTypes.cpp
index b0f736a49c20e..5aa7c406206d9 100644
--- a/llvm/lib/CodeGen/ValueTypes.cpp
+++ b/llvm/lib/CodeGen/ValueTypes.cpp
@@ -263,6 +263,15 @@ MVT MVT::getVT(Type *Ty, bool HandleUnknown){
   getVT(VTy->getElementType(), /*HandleUnknown=*/ false),
 VTy->getElementCount());
   }
+  case Type::PointerTyID: {
+if (Ty->getPointerAddressSpace() == Type::WasmExternrefAddressSpace)
+  return MVT(MVT::externref);
+if (Ty->getPointerAddressSpace() == Type::WasmFuncrefAddressSpace)
+  return MVT(MVT::funcref);
+if (HandleUnknown)
+  return MVT(MVT::Other);
+llvm_unreachable("Unknown pointer type!");
+  }
   }
 }
 
diff --git a/llvm/lib/IR/Type.cpp b/llvm/lib/IR/Type.cpp
index 5c61ad9f000b0..2279b5eb873b7 100644
--- a/llvm/lib/IR/Type.cpp
+++ b/llvm/lib/IR/Type.cpp
@@ -261,13 +261,13 @@ IntegerType *Type::getIntNTy(LLVMContext &C, unsigned N) {
 
 Type *Type::getWasm_ExternrefTy(LLVMContext &C) {
   // opaque pointer in addrspace(10)
-  static PointerType *Ty = PointerType::get(C, 10);
+  static PointerType *Ty = PointerType::get(C, WasmExternrefAddressSpace);
   return Ty;
 }
 
 Type *Type::getWasm_FuncrefTy(LLVMContext &C) {
   // opaque pointer in addrspace(20)
-  static PointerType *Ty = PointerType::get(C, 20);
+  static PointerType *Ty = PointerType::get(C, WasmFuncrefAddressSpace);
   return Ty;
 }
 

>From 20d847ee59be5a8cf4d4ffde2228cba2c5534e68 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sun, 30 Jun 2024 10:29:21 +0800
Subject: [PATCH 2/2] update test

---
 clang/test/CodeGen/WebAssembly/wasm-externref-novec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/test/CodeGen/WebAssembly/wasm-externref-novec.c 
b/clang/test/CodeGen/WebAssembly/wasm-externref-novec.c
index d91072f379623..30942773b1ae5 100644
--- a/clang/test/CodeGen/WebAssembly/wasm-externref-novec.c
+++ b/clang/test/CodeGen/WebAssembly/wasm-externref-novec.c
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -O2 -triple wasm32-unknown-unknown-wasm -target-feature 
+reference-types -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang -O2 --target=wasm32 -S -emit-llvm -mreference-types -o - %s | 
FileCheck %s
 
-// From issue 69894. Reftypes need to be marked as not valid as vector 
elements.
+// Issue: https://github.com/llvm/llvm-project/issues/69894
 
 __externref_t foo(void);
 // CHECK: declare ptr addrspace(10) @foo()

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


[clang] [llvm] [WebAssembly] support getVT from `externref` and `funcref` (PR #97080)

2024-06-29 Thread Congcong Cai via cfe-commits

HerrCai0907 wrote:

> What happens if you compile a file that really vectorizes reference types? 
> The attached test doesn't seem to actually end up getting vectorized after 
> all. Can you add a test that get vectorized?

Is it possible to vectorize external reference types? I don't think there are 
valid test case for it.

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


[clang] 6b737c4 - [clang][Sema] Fix crash on atomic builtins with incomplete type args (#96374)

2024-06-29 Thread via cfe-commits

Author: Takuya Shimizu
Date: 2024-06-30T14:09:10+09:00
New Revision: 6b737c444617fe8c11eb48f978c579cc160bfff0

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

LOG: [clang][Sema] Fix crash on atomic builtins with incomplete type args 
(#96374)

This patch fixes the crash when pointers to incomplete type are passed
to atomic builtins such as `__atomic_load`.
`ASTContext::getTypeInfoInChars` assumes that the argument type is a
complete type, so I added a check to eliminate cases where incomplete
types gets passed to this function

Relevant PR: https://github.com/llvm/llvm-project/pull/91057
Fixes https://github.com/llvm/llvm-project/issues/96289

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaChecking.cpp
clang/test/Sema/atomic-ops.c
clang/test/SemaCXX/atomic-ops.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 35d2509eacece..c720e47dbe35b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -745,6 +745,9 @@ Bug Fixes to Compiler Builtins
 
 - Fix crash when atomic builtins are called with pointer to zero-size struct 
(#GH90330)
 
+- Clang now allows pointee types of atomic builtin arguments to be complete 
template types
+  that was not instantiated elsewhere.
+
 Bug Fixes to Attribute Support
 ^^
 

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 005fbfd42a8ab..cc3615da7f940 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3814,6 +3814,9 @@ ExprResult Sema::BuildAtomicExpr(SourceRange CallRange, 
SourceRange ExprRange,
   }
 
   // Pointer to object of size zero is not allowed.
+  if (RequireCompleteType(Ptr->getBeginLoc(), AtomTy,
+  diag::err_incomplete_type))
+return ExprError();
   if (Context.getTypeInfoInChars(AtomTy).Width.isZero()) {
 Diag(ExprRange.getBegin(), diag::err_atomic_builtin_must_be_pointer)
 << Ptr->getType() << 1 << Ptr->getSourceRange();

diff  --git a/clang/test/Sema/atomic-ops.c b/clang/test/Sema/atomic-ops.c
index 2024b81ce6aec..9b82d82ff8269 100644
--- a/clang/test/Sema/atomic-ops.c
+++ b/clang/test/Sema/atomic-ops.c
@@ -671,6 +671,36 @@ void zeroSizeArgError(struct Z *a, struct Z *b, struct Z 
*c) {
 
 }
 
+struct IncompleteTy IncA, IncB, IncC; // expected-error 3{{tentative 
definition has type 'struct IncompleteTy' that is never completed}} \
+  // expected-note 27{{forward declaration 
of 'struct IncompleteTy'}}
+void incompleteTypeArgError() {
+  __atomic_exchange(&IncB, &IncB, &IncC, memory_order_relaxed); // 
expected-error {{incomplete type 'struct IncompleteTy' where a complete type is 
required}}
+  __atomic_exchange(&IncB, &IncB, &IncC, memory_order_acq_rel); // 
expected-error {{incomplete type 'struct IncompleteTy' where a complete type is 
required}}
+  __atomic_exchange(&IncB, &IncB, &IncC, memory_order_acquire); // 
expected-error {{incomplete type 'struct IncompleteTy' where a complete type is 
required}}
+  __atomic_exchange(&IncB, &IncB, &IncC, memory_order_consume); // 
expected-error {{incomplete type 'struct IncompleteTy' where a complete type is 
required}}
+  __atomic_exchange(&IncB, &IncB, &IncC, memory_order_release); // 
expected-error {{incomplete type 'struct IncompleteTy' where a complete type is 
required}}
+  __atomic_exchange(&IncB, &IncB, &IncC, memory_order_seq_cst); // 
expected-error {{incomplete type 'struct IncompleteTy' where a complete type is 
required}}
+  __atomic_load(&IncA, &IncB, memory_order_relaxed); // expected-error 
{{incomplete type 'struct IncompleteTy' where a complete type is required}}
+  __atomic_load(&IncA, &IncB, memory_order_acq_rel); // expected-error 
{{incomplete type 'struct IncompleteTy' where a complete type is required}}
+  __atomic_load(&IncA, &IncB, memory_order_acquire); // expected-error 
{{incomplete type 'struct IncompleteTy' where a complete type is required}}
+  __atomic_load(&IncA, &IncB, memory_order_consume); // expected-error 
{{incomplete type 'struct IncompleteTy' where a complete type is required}}
+  __atomic_load(&IncA, &IncB, memory_order_release); // expected-error 
{{incomplete type 'struct IncompleteTy' where a complete type is required}}
+  __atomic_load(&IncA, &IncB, memory_order_seq_cst); // expected-error 
{{incomplete type 'struct IncompleteTy' where a complete type is required}}
+  __atomic_store(&IncA, &IncB, memory_order_relaxed); // expected-error 
{{incomplete type 'struct IncompleteTy' where a complete type is required}}
+  __atomic_store(&IncA, &IncB, memory_order_acq_rel); // expected-error 
{{incomplete type 'struct IncompleteTy' where a complete type is required}}
+  __

[clang] [clang][Sema] Fix crash on atomic builtins with incomplete type args (PR #96374)

2024-06-29 Thread Takuya Shimizu via cfe-commits

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


[clang-tools-extra] [clang-doc][nfc] Avoid constructing SmallString in ToString method (PR #96921)

2024-06-29 Thread via cfe-commits

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


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


[clang-tools-extra] [clang-doc] add async loading (PR #93276)

2024-06-29 Thread via cfe-commits

https://github.com/PeterChou1 updated 
https://github.com/llvm/llvm-project/pull/93276

>From 0b6d536133f63e078fbde491a8c92c7ec916cb47 Mon Sep 17 00:00:00 2001
From: PeterChou1 
Date: Fri, 24 May 2024 05:18:05 -0400
Subject: [PATCH 1/8] [clang-doc] make loading of json side bar async

---
 clang-tools-extra/clang-doc/HTMLGenerator.cpp | 28 +--
 clang-tools-extra/clang-doc/Representation.h  |  1 +
 clang-tools-extra/clang-doc/assets/index.js   |  5 ++--
 .../clang-doc/tool/ClangDocMain.cpp   |  6 +++-
 4 files changed, 23 insertions(+), 17 deletions(-)

diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp 
b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index c0faf5f7e8fd9..fb1a7f94c9094 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -964,7 +964,7 @@ static llvm::Error SerializeIndex(ClangDocContext &CDCtx) {
   std::error_code FileErr;
   llvm::SmallString<128> FilePath;
   llvm::sys::path::native(CDCtx.OutDirectory, FilePath);
-  llvm::sys::path::append(FilePath, "index_json.js");
+  llvm::sys::path::append(FilePath, "index.json");
   llvm::raw_fd_ostream OS(FilePath, FileErr, llvm::sys::fs::OF_None);
   if (FileErr != OK) {
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
@@ -985,9 +985,7 @@ static llvm::Error SerializeIndex(ClangDocContext &CDCtx) {
   });
 });
   };
-  OS << "var JsonIndex = `\n";
   IndexToJSON(CDCtx.Idx);
-  OS << "`;\n";
   return llvm::Error::success();
 }
 
@@ -1049,31 +1047,33 @@ static llvm::Error CopyFile(StringRef FilePath, 
StringRef OutDirectory) {
   std::error_code FileErr = llvm::sys::fs::copy_file(PathRead, PathWrite);
   if (FileErr != OK) {
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
-   "error creating file " +
-   llvm::sys::path::filename(FilePath) +
-   ": " + FileErr.message() + "\n");
+   "error creating file " + FilePath + ": " +
+   FileErr.message() + "\n");
   }
   return llvm::Error::success();
 }
 
 llvm::Error HTMLGenerator::createResources(ClangDocContext &CDCtx) {
-  auto Err = SerializeIndex(CDCtx);
-  if (Err)
+  if (auto Err = SerializeIndex(CDCtx)) {
 return Err;
-  Err = GenIndex(CDCtx);
-  if (Err)
+  }
+
+  if (auto Err = GenIndex(CDCtx)) {
 return Err;
+  }
 
   for (const auto &FilePath : CDCtx.UserStylesheets) {
-Err = CopyFile(FilePath, CDCtx.OutDirectory);
-if (Err)
+if (auto Err = CopyFile(FilePath, CDCtx.OutDirectory)) {
   return Err;
+}
   }
+
   for (const auto &FilePath : CDCtx.FilesToCopy) {
-Err = CopyFile(FilePath, CDCtx.OutDirectory);
-if (Err)
+if (auto Err = CopyFile(FilePath, CDCtx.OutDirectory)) {
   return Err;
+}
   }
+
   return llvm::Error::success();
 }
 
diff --git a/clang-tools-extra/clang-doc/Representation.h 
b/clang-tools-extra/clang-doc/Representation.h
index a6b144eb7fa2a..23323f1cbdf46 100644
--- a/clang-tools-extra/clang-doc/Representation.h
+++ b/clang-tools-extra/clang-doc/Representation.h
@@ -491,6 +491,7 @@ struct ClangDocContext {
   std::string SourceRoot;   // Directory where processed files are stored. 
Links
 // to definition locations will only be generated 
if
 // the file is in this dir.
+
   // URL of repository that hosts code used for links to definition locations.
   std::optional RepositoryUrl;
   // Path of CSS stylesheets that will be copied to OutDirectory and used to
diff --git a/clang-tools-extra/clang-doc/assets/index.js 
b/clang-tools-extra/clang-doc/assets/index.js
index a5ac90f2e06e7..379867268527e 100644
--- a/clang-tools-extra/clang-doc/assets/index.js
+++ b/clang-tools-extra/clang-doc/assets/index.js
@@ -82,6 +82,7 @@ function createIndex(Index) {
 document.addEventListener("DOMContentLoaded", function() {
   // JsonIndex is a variable from another file that contains the index
   // in JSON format
-  var Index = JSON.parse(JsonIndex);
-  createIndex(Index);
+  fetch("/index.json")
+  .then((response) => response.json())
+  .then((Index) => { createIndex(Index); });
 });
diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp 
b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index 21b581fa6df2e..53108a77dab21 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -155,6 +155,10 @@ Example usage for a project using a compile commands 
database:
 return 1;
   }
 
+  // add option to customize url fragment
+  // such as
+  // 
https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clang-doc/ClangDocMain.cpp#L1
+
   // Fail early if an invalid format was provided.
   std::string Format = getFormatString();
   llvm::outs() << "Emiting docs in " << Format << " format.\n";
@@ -179

[clang] ab20086 - [CUDA][NFC] CudaArch to OffloadArch rename (#97028)

2024-06-29 Thread via cfe-commits

Author: Jakub Chlanda
Date: 2024-06-30T07:56:07+02:00
New Revision: ab200864220b72b3bdf1fe9d001ad3d1e4d9d4b3

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

LOG: [CUDA][NFC] CudaArch to OffloadArch rename (#97028)

Rename `CudaArch` to `OffloadArch` to better reflect its content and the
use.
Apply a similar rename to helpers handling the enum.

Added: 


Modified: 
clang/include/clang/Basic/Cuda.h
clang/lib/Basic/Cuda.cpp
clang/lib/Basic/Targets/NVPTX.cpp
clang/lib/Basic/Targets/NVPTX.h
clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
clang/lib/Driver/Driver.cpp
clang/lib/Driver/OffloadBundler.cpp
clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
clang/lib/Driver/ToolChains/Cuda.cpp
clang/lib/Driver/ToolChains/Cuda.h
clang/lib/Sema/SemaDeclAttr.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Cuda.h 
b/clang/include/clang/Basic/Cuda.h
index 01cfe286c491b..83699f8897f66 100644
--- a/clang/include/clang/Basic/Cuda.h
+++ b/clang/include/clang/Basic/Cuda.h
@@ -52,7 +52,7 @@ const char *CudaVersionToString(CudaVersion V);
 // Input is "Major.Minor"
 CudaVersion CudaStringToVersion(const llvm::Twine &S);
 
-enum class CudaArch {
+enum class OffloadArch {
   UNUSED,
   UNKNOWN,
   // TODO: Deprecate and remove GPU architectures older than sm_52.
@@ -133,8 +133,8 @@ enum class CudaArch {
// public one.
   LAST,
 
-  CudaDefault = CudaArch::SM_52,
-  HIPDefault = CudaArch::GFX906,
+  CudaDefault = OffloadArch::SM_52,
+  HIPDefault = OffloadArch::GFX906,
 };
 
 enum class CUDAFunctionTarget {
@@ -145,26 +145,26 @@ enum class CUDAFunctionTarget {
   InvalidTarget
 };
 
-static inline bool IsNVIDIAGpuArch(CudaArch A) {
-  return A >= CudaArch::SM_20 && A < CudaArch::GFX600;
+static inline bool IsNVIDIAOffloadArch(OffloadArch A) {
+  return A >= OffloadArch::SM_20 && A < OffloadArch::GFX600;
 }
 
-static inline bool IsAMDGpuArch(CudaArch A) {
+static inline bool IsAMDOffloadArch(OffloadArch A) {
   // Generic processor model is for testing only.
-  return A >= CudaArch::GFX600 && A < CudaArch::Generic;
+  return A >= OffloadArch::GFX600 && A < OffloadArch::Generic;
 }
 
-const char *CudaArchToString(CudaArch A);
-const char *CudaArchToVirtualArchString(CudaArch A);
+const char *OffloadArchToString(OffloadArch A);
+const char *OffloadArchToVirtualArchString(OffloadArch A);
 
 // The input should have the form "sm_20".
-CudaArch StringToCudaArch(llvm::StringRef S);
+OffloadArch StringToOffloadArch(llvm::StringRef S);
 
-/// Get the earliest CudaVersion that supports the given CudaArch.
-CudaVersion MinVersionForCudaArch(CudaArch A);
+/// Get the earliest CudaVersion that supports the given OffloadArch.
+CudaVersion MinVersionForOffloadArch(OffloadArch A);
 
-/// Get the latest CudaVersion that supports the given CudaArch.
-CudaVersion MaxVersionForCudaArch(CudaArch A);
+/// Get the latest CudaVersion that supports the given OffloadArch.
+CudaVersion MaxVersionForOffloadArch(OffloadArch A);
 
 //  Various SDK-dependent features that affect CUDA compilation
 enum class CudaFeature {

diff  --git a/clang/lib/Basic/Cuda.cpp b/clang/lib/Basic/Cuda.cpp
index af99c4d61021e..faf3878f064d2 100644
--- a/clang/lib/Basic/Cuda.cpp
+++ b/clang/lib/Basic/Cuda.cpp
@@ -72,23 +72,21 @@ CudaVersion ToCudaVersion(llvm::VersionTuple Version) {
 }
 
 namespace {
-struct CudaArchToStringMap {
-  CudaArch arch;
+struct OffloadArchToStringMap {
+  OffloadArch arch;
   const char *arch_name;
   const char *virtual_arch_name;
 };
 } // namespace
 
-#define SM2(sm, ca)
\
-  { CudaArch::SM_##sm, "sm_" #sm, ca }
+#define SM2(sm, ca) {OffloadArch::SM_##sm, "sm_" #sm, ca}
 #define SM(sm) SM2(sm, "compute_" #sm)
-#define GFX(gpu)   
\
-  { CudaArch::GFX##gpu, "gfx" #gpu, "compute_amdgcn" }
-static const CudaArchToStringMap arch_names[] = {
+#define GFX(gpu) {OffloadArch::GFX##gpu, "gfx" #gpu, "compute_amdgcn"}
+static const OffloadArchToStringMap arch_names[] = {
 // clang-format off
-{CudaArch::UNUSED, "", ""},
+{OffloadArch::UNUSED, "", ""},
 SM2(20, "compute_20"), SM2(21, "compute_20"), // Fermi
-SM(30), {CudaArch::SM_32_, "sm_32", "compute_32"}, SM(35), SM(37),  // 
Kepler
+SM(30), {OffloadArch::SM_32_, "sm_32", "compute_32"}, SM(35), SM(37),  // 
Kepler
 SM(50), SM(52), SM(53),  // Maxwell
 SM(60), SM(61), SM(62),  // Pascal
 SM(70), SM(72),  // Volta
@@ -112,7 +110,7 @@ static const CudaArchToStringMap arch_names[] = {
 GFX(803),  // gfx803
 GFX(805),  // gfx805
 GFX(810),  // gfx810
-{CudaArch::GFX9_GENERIC, "gfx9-generic", "compute_amdgcn"},
+{OffloadArch::GFX9_G

[clang] [CUDA][NFC] CudaArch to OffloadArch rename (PR #97028)

2024-06-29 Thread Jakub Chlanda via cfe-commits

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


[clang] [compiler-rt] [llvm] [TypeProf][InstrFDO]Implement more efficient comparison sequence for indirect-call-promotion with vtable profiles. (PR #81442)

2024-06-29 Thread Mingming Liu via cfe-commits

minglotus-6 wrote:

Going to merge as the failed tests are not related to this PR.

```
cat github-pull-requests_build_76910_linux-linux-x64.log | grep -B 2 -A 10 
"Failed Tests "
--

Failed Tests (1):
  BOLT :: X86/reader-stale-yaml-std.test


Testing Time: 385.93s

Total Discovered Tests: 120952
  Skipped  : 47 (0.04%)
  Unsupported  :   3335 (2.76%)
  Passed   : 117251 (96.94%)
  Expectedly Failed:318 (0.26%)
--
--

Failed Tests (1):
  BOLT :: X86/reader-stale-yaml-std.test


Testing Time: 1.98s

Total Discovered Tests: 454
  Skipped  :   7 (1.54%)
  Unsupported  :  13 (2.86%)
  Passed   : 431 (94.93%)
  Expectedly Failed:   2 (0.44%)
```

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


[clang] [compiler-rt] [llvm] [TypeProf][InstrFDO]Implement more efficient comparison sequence for indirect-call-promotion with vtable profiles. (PR #81442)

2024-06-29 Thread Mingming Liu via cfe-commits

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


[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)

2024-06-29 Thread via cfe-commits

https://github.com/PeterChou1 updated 
https://github.com/llvm/llvm-project/pull/93281

>From f5872e7c82d097ae3c141765d3f1d7e3d0b25b82 Mon Sep 17 00:00:00 2001
From: PeterChou1 
Date: Fri, 24 May 2024 04:28:08 -0400
Subject: [PATCH 1/4] clang-doc switched from using relative to absolute paths

---
 clang-tools-extra/clang-doc/assets/index.js | 72 ++---
 1 file changed, 35 insertions(+), 37 deletions(-)

diff --git a/clang-tools-extra/clang-doc/assets/index.js 
b/clang-tools-extra/clang-doc/assets/index.js
index a5ac90f2e06e7..fe35e706cc98d 100644
--- a/clang-tools-extra/clang-doc/assets/index.js
+++ b/clang-tools-extra/clang-doc/assets/index.js
@@ -1,48 +1,46 @@
-// Append using posix-style a file name or directory to Base
-function append(Base, New) {
-  if (!New)
-return Base;
-  if (Base)
-Base += "/";
-  Base += New;
-  return Base;
-}
-
-// Get relative path to access FilePath from CurrentDirectory
-function computeRelativePath(FilePath, CurrentDirectory) {
-  var Path = FilePath;
-  while (Path) {
-if (CurrentDirectory == Path)
-  return FilePath.substring(Path.length + 1);
-Path = Path.substring(0, Path.lastIndexOf("/"));
-  }
-
-  var Dir = CurrentDirectory;
-  var Result = "";
-  while (Dir) {
-if (Dir == FilePath)
-  break;
-Dir = Dir.substring(0, Dir.lastIndexOf("/"));
-Result = append(Result, "..")
+function genLink(Ref) {
+  var Path = 
`${window.location.protocol}//${window.location.host}/${Ref.Path}`;
+  if (Ref.RefType !== "namespace") {
+if (Ref.Path === "") {
+  Path = `${Path}${Ref.Name}.html`;
+}
+else {
+  Path = `${Path}/${Ref.Name}.html`;
+}
   }
-  Result = append(Result, FilePath.substring(Dir.length))
-  return Result;
-}
-
-function genLink(Ref, CurrentDirectory) {
-  var Path = computeRelativePath(Ref.Path, CurrentDirectory);
-  if (Ref.RefType == "namespace")
-Path = append(Path, "index.html");
-  else
-Path = append(Path, Ref.Name + ".html")
 
-ANode = document.createElement("a");
+  ANode = document.createElement("a");
   ANode.setAttribute("href", Path);
   var TextNode = document.createTextNode(Ref.Name);
   ANode.appendChild(TextNode);
   return ANode;
 }
 
+function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
+  // Out will store the HTML elements that Index requires to be generated
+  var Out = [];
+  if (Index.Name) {
+var SpanNode = document.createElement("span");
+var TextNode = document.createTextNode(Index.Name);
+SpanNode.appendChild(genLink(Index));
+Out.push(SpanNode);
+  }
+  if (Index.Children.length == 0)
+return Out;
+  // Only the outermost list should use ol, the others should use ul
+  var ListNodeName = IsOutermostList ? "ol" : "ul";
+  var ListNode = document.createElement(ListNodeName);
+  for (Child of Index.Children) {
+var LiNode = document.createElement("li");
+ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false);
+for (Node of ChildNodes)
+  LiNode.appendChild(Node);
+ListNode.appendChild(LiNode);
+  }
+  Out.push(ListNode);
+  return Out;
+}
+
 function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
   // Out will store the HTML elements that Index requires to be generated
   var Out = [];

>From a22609f75064194604e476a12bc8154676dacfb9 Mon Sep 17 00:00:00 2001
From: PeterChou1 
Date: Fri, 24 May 2024 05:10:03 -0400
Subject: [PATCH 2/4] remove duplicate function

---
 clang-tools-extra/clang-doc/assets/index.js | 24 -
 1 file changed, 24 deletions(-)

diff --git a/clang-tools-extra/clang-doc/assets/index.js 
b/clang-tools-extra/clang-doc/assets/index.js
index fe35e706cc98d..b013418c82093 100644
--- a/clang-tools-extra/clang-doc/assets/index.js
+++ b/clang-tools-extra/clang-doc/assets/index.js
@@ -16,30 +16,6 @@ function genLink(Ref) {
   return ANode;
 }
 
-function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
-  // Out will store the HTML elements that Index requires to be generated
-  var Out = [];
-  if (Index.Name) {
-var SpanNode = document.createElement("span");
-var TextNode = document.createTextNode(Index.Name);
-SpanNode.appendChild(genLink(Index));
-Out.push(SpanNode);
-  }
-  if (Index.Children.length == 0)
-return Out;
-  // Only the outermost list should use ol, the others should use ul
-  var ListNodeName = IsOutermostList ? "ol" : "ul";
-  var ListNode = document.createElement(ListNodeName);
-  for (Child of Index.Children) {
-var LiNode = document.createElement("li");
-ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false);
-for (Node of ChildNodes)
-  LiNode.appendChild(Node);
-ListNode.appendChild(LiNode);
-  }
-  Out.push(ListNode);
-  return Out;
-}
 
 function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
   // Out will store the HTML elements that Index requires to be generated

>From be0fb1acdd97a07e665b61fbba44d32dd40e1b94 Mon Sep 17 00:00:00 2001
From: PeterChou1 
Date: Sa

[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)

2024-06-29 Thread via cfe-commits


@@ -1,12 +1,19 @@
 function genLink(Ref) {
   var Path = 
`${window.location.protocol}//${window.location.host}/${Ref.Path}`;
+  var isFileProtocol = window.location.protocol.startsWith("file");
+  // we treat the file paths different depending on if we're
+  // serving via a http server or viewing from a local
+  if (isFileProtocol) {
+Path = `${window.location.protocol}//${RootPath}/${Ref.Path}`;
+  }
   if (Ref.RefType !== "namespace") {
 if (Ref.Path === "") {
   Path = `${Path}${Ref.Name}.html`;
-}
-else {
+} else {
   Path = `${Path}/${Ref.Name}.html`;
 }
+  } else {
+Path = `${Path}/index.html`
   }

PeterChou1 wrote:

I don't think this will make a meaningful performance difference either way. 
Although I agree for readability purposes this is much more concise I've 
updated the code to reflect this

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


[clang] [TBAA] Emit int TBAA metadata on FP math libcalls (PR #96025)

2024-06-29 Thread via cfe-commits

vfdff wrote:

hi, is there any new suggestion ?

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


[clang] [llvm] [polly] Revert "[IR] Don't include Module.h in Analysis.h (NFC) (#97023)" (PR #97129)

2024-06-29 Thread Nikita Popov via cfe-commits

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

This is probably caused by some downstream patches in google3? 
https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
 does not contain any mentions of `M->getFunction` or `M->getContext`. You need 
to add the missing include to your downstream patches.

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


[clang] [Clang][ExprConstant] fix constant expression did not evaluate to integer (PR #97146)

2024-06-29 Thread Zhikai Zeng via cfe-commits

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

fixes https://github.com/llvm/llvm-project/issues/96670

The cause is that we might return a lvalue here at

https://github.com/llvm/llvm-project/blob/3e53c97d33210db68188e731e93ee48dbaeeae32/clang/lib/AST/ExprConstant.cpp#L15861-L15865

This PR will make sure we return a rvalue in `FastEvaluateAsRValue`.

>From 5a443296eecbdf90d1cf274c3e52797be380bdd3 Mon Sep 17 00:00:00 2001
From: Backl1ght 
Date: Sat, 29 Jun 2024 15:26:21 +0800
Subject: [PATCH] fix

---
 clang/docs/ReleaseNotes.rst |  1 +
 clang/lib/AST/ExprConstant.cpp  |  2 +-
 clang/test/SemaCXX/eval-crashes.cpp | 10 ++
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index feba3c7ba8d77..8ec1c105cef9f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -936,6 +936,7 @@ Bug Fixes to C++ Support
   forward-declared class. (#GH93512).
 - Fixed a bug in access checking inside return-type-requirement of compound 
requirements. (#GH93788).
 - Fixed an assertion failure about invalid conversion when calling lambda. 
(#GH96205).
+- Fixed an assertion failure about constant expression did not evaluate to 
integer. (#GH96670).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 374a3acf7aa26..0ccdc5eaabeef 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -15858,7 +15858,7 @@ static bool FastEvaluateAsRValue(const Expr *Exp, 
Expr::EvalResult &Result,
   }
 
   if (const auto *CE = dyn_cast(Exp)) {
-if (CE->hasAPValueResult()) {
+if (CE->hasAPValueResult() && !CE->getAPValueResult().isLValue()) {
   Result.Val = CE->getAPValueResult();
   IsConst = true;
   return true;
diff --git a/clang/test/SemaCXX/eval-crashes.cpp 
b/clang/test/SemaCXX/eval-crashes.cpp
index 017df977b26b7..0865dafe4bf92 100644
--- a/clang/test/SemaCXX/eval-crashes.cpp
+++ b/clang/test/SemaCXX/eval-crashes.cpp
@@ -61,3 +61,13 @@ struct array {
   array() : data(*new int[1][2]) {}
 };
 }
+
+namespace GH96670 {
+inline constexpr long ullNil = -1;
+
+template
+struct Test {};
+
+inline constexpr long lNil = -1;
+Test c;
+}

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


[clang] [Clang][ExprConstant] fix constant expression did not evaluate to integer (PR #97146)

2024-06-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Zhikai Zeng (Backl1ght)


Changes

fixes https://github.com/llvm/llvm-project/issues/96670

The cause is that we might return a lvalue here at

https://github.com/llvm/llvm-project/blob/3e53c97d33210db68188e731e93ee48dbaeeae32/clang/lib/AST/ExprConstant.cpp#L15861-L15865

This PR will make sure we return a rvalue in `FastEvaluateAsRValue`.

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/lib/AST/ExprConstant.cpp (+1-1) 
- (modified) clang/test/SemaCXX/eval-crashes.cpp (+10) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index feba3c7ba8d77..8ec1c105cef9f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -936,6 +936,7 @@ Bug Fixes to C++ Support
   forward-declared class. (#GH93512).
 - Fixed a bug in access checking inside return-type-requirement of compound 
requirements. (#GH93788).
 - Fixed an assertion failure about invalid conversion when calling lambda. 
(#GH96205).
+- Fixed an assertion failure about constant expression did not evaluate to 
integer. (#GH96670).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 374a3acf7aa26..0ccdc5eaabeef 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -15858,7 +15858,7 @@ static bool FastEvaluateAsRValue(const Expr *Exp, 
Expr::EvalResult &Result,
   }
 
   if (const auto *CE = dyn_cast(Exp)) {
-if (CE->hasAPValueResult()) {
+if (CE->hasAPValueResult() && !CE->getAPValueResult().isLValue()) {
   Result.Val = CE->getAPValueResult();
   IsConst = true;
   return true;
diff --git a/clang/test/SemaCXX/eval-crashes.cpp 
b/clang/test/SemaCXX/eval-crashes.cpp
index 017df977b26b7..0865dafe4bf92 100644
--- a/clang/test/SemaCXX/eval-crashes.cpp
+++ b/clang/test/SemaCXX/eval-crashes.cpp
@@ -61,3 +61,13 @@ struct array {
   array() : data(*new int[1][2]) {}
 };
 }
+
+namespace GH96670 {
+inline constexpr long ullNil = -1;
+
+template
+struct Test {};
+
+inline constexpr long lNil = -1;
+Test c;
+}

``




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


[clang] [Clang] fix cast failures by adjusting the resolution of record declaration contexts to handle semantic and lexical distinctions (PR #96228)

2024-06-29 Thread Oleksandr T. via cfe-commits

a-tarasyuk wrote:

ping

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


  1   2   >