[clang] a9af8f8 - [clang][Interp] Implement IntegralAP::truncate() (#69912)

2023-11-05 Thread via cfe-commits

Author: Timm Baeder
Date: 2023-11-05T08:26:29+01:00
New Revision: a9af8f8882f9d64870d3b60adfbe07e59c63c523

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

LOG: [clang][Interp] Implement IntegralAP::truncate() (#69912)

Added: 


Modified: 
clang/lib/AST/Interp/IntegralAP.h
clang/test/AST/Interp/intap.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/IntegralAP.h 
b/clang/lib/AST/Interp/IntegralAP.h
index 9aefea6d0c47ed9..1f535d420bcd54b 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -140,9 +140,8 @@ template  class IntegralAP final {
 return NameStr;
   }
 
-  IntegralAP truncate(unsigned bitWidth) const {
-assert(false);
-return V;
+  IntegralAP truncate(unsigned BitWidth) const {
+return IntegralAP(V.trunc(BitWidth));
   }
 
   IntegralAP toUnsigned() const {

diff  --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp
index 02a860eb0986c15..db9f516131af474 100644
--- a/clang/test/AST/Interp/intap.cpp
+++ b/clang/test/AST/Interp/intap.cpp
@@ -121,4 +121,20 @@ namespace AddSubOffset {
   static_assert(*P2 == 1,"");
 }
 
+namespace Bitfields {
+  struct S1 {
+unsigned _BitInt(128) a : 2;
+  };
+  constexpr S1 s1{100}; // ref-warning {{changes value from 100 to 0}} \
+// expected-warning {{changes value from 100 to 0}}
+  constexpr S1 s12{3};
+  static_assert(s12.a == 3, "");
+
+  struct S2 {
+unsigned __int128 a : 2;
+  };
+  constexpr S2 s2{100}; // ref-warning {{changes value from 100 to 0}} \
+// expected-warning {{changes value from 100 to 0}}
+}
+
 #endif



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


[clang] [clang][Interp] Implement IntegralAP::truncate() (PR #69912)

2023-11-05 Thread Timm Baeder via cfe-commits

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


[clang] c0a7391 - [ItaniumCXXABI] Add -fassume-nothrow-exception-dtor to assume that all exception objects' destructors are non-throwing

2023-11-05 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-11-05T00:39:38-07:00
New Revision: c0a73918bfddc6a04a897aab57fb95e8d2da7ec0

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

LOG: [ItaniumCXXABI] Add -fassume-nothrow-exception-dtor to assume that all 
exception objects' destructors are non-throwing

Link: https://lists.llvm.org/pipermail/cfe-dev/2021-August/068740.html 
("[Exception Handling] Could we mark __cxa_end_catch as nounwind conditionally?"
Link: https://github.com/llvm/llvm-project/issues/57375

A catch handler calls `__cxa_begin_catch` and `__cxa_end_catch`. For a catch-all
clause or a catch clause matching a record type, we:

* assume that the exception object may have a throwing destructor
* emit `invoke void @__cxa_end_catch` (as the call is not marked as the 
`nounwind` attribute).
* emit a landing pad to destroy local variables and call `_Unwind_Resume`

```
struct A { ~A(); };
struct B { int x; };
void opaque();
void foo() {
  A a;
  try { opaque(); } catch (...) { } // the exception object has an unknown type 
and may throw
  try { opaque(); } catch (B b) { } // B::~B is nothrow, but we do not utilize 
this
}
```

Per C++ [dcl.fct.def.coroutine], a coroutine's function body implies a `catch 
(...)`.
Our code generation pessimizes even simple code, like:
```
UserFacing foo() {
  A a;
  opaque();
  co_return;
  // For `invoke void @__cxa_end_catch()`, the landing pad destroys the
  // promise_type and deletes the coro frame.
}
```

Throwing destructors are typically discouraged. In many environments, the
destructors of exception objects are guaranteed to never throw, making our
conservative code generation approach seem wasteful.

Furthermore, throwing destructors tend not to work well in practice:

* GCC does not emit call site records for the region containing 
`__cxa_end_catch`. This has been a long time, since 2000.
* If a catch-all clause catches an exception object that throws, both GCC and 
Clang using libstdc++ leak the allocated exception object.

To avoid code generation pessimization, add an opt-in driver option
-fassume-nothrow-exception-dtor to assume that `__cxa_end_catch` calls have the
`nounwind` attribute. This implies that thrown exception objects' destructors
will never throw.

To detect misuses, diagnose throw expressions with a potentially-throwing
destructor. Technically, it is possible that a potentially-throwing destructor
never throws when called transitively by `__cxa_end_catch`, but these cases seem
rare enough to justify a relaxed mode.

Reviewed By: ChuanqiXu

Differential Revision: https://reviews.llvm.org/D108905

Added: 
clang/test/SemaCXX/assume-nothrow-exception-dtor.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/docs/UsersManual.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/test/CodeGenCXX/eh.cpp
clang/test/CodeGenCXX/exceptions.cpp
clang/test/CodeGenCoroutines/coro-cleanup.cpp
clang/test/Driver/clang-exception-flags.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index afe7e2e79c2d087..3edf480665ba10c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -232,6 +232,10 @@ New Compiler Flags
   preserving ``#include`` directives for "system" headers instead of copying
   the preprocessed text to the output. This can greatly reduce the size of the
   preprocessed output, which can be helpful when trying to reduce a test case.
+* ``-fassume-nothrow-exception-dtor`` is added to assume that the destructor of
+  an thrown exception object will not throw. The generated code for catch
+  handlers will be smaller. A throw expression of a type with a
+  potentially-throwing destructor will lead to an error.
 
 Deprecated Compiler Flags
 -

diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index edc2bce6a964dc4..2e658557b0e310c 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -2134,6 +2134,18 @@ are listed below.
new operator will always return a pointer that does not alias any
other pointer when the function returns.
 
+.. option:: -fassume-nothrow-exception-dtor
+
+   Assume that an exception object' destructor will not throw, and generate
+   less code for catch handlers. A throw expression of a type with a
+   potentially-throwing destructor will lead to an error.
+
+   By default, Clang assumes that the exception object may have a throwing
+   destructor. For the Itanium C++ ABI, Clang generates a landing pad to
+   destroy local variables and call ``_Unwind_Resume`

[PATCH] D108905: [ItaniumCXXABI] Add -fassume-nothrow-exception-dtor to assume that all exception objects' destructors are non-throwing

2023-11-05 Thread Fangrui Song via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc0a73918bfdd: [ItaniumCXXABI] Add 
-fassume-nothrow-exception-dtor to assume that all… (authored by MaskRay).

Changed prior to commit:
  https://reviews.llvm.org/D108905?vs=557976&id=558008#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108905/new/

https://reviews.llvm.org/D108905

Files:
  clang/docs/ReleaseNotes.rst
  clang/docs/UsersManual.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/CodeGenCXX/eh.cpp
  clang/test/CodeGenCXX/exceptions.cpp
  clang/test/CodeGenCoroutines/coro-cleanup.cpp
  clang/test/Driver/clang-exception-flags.cpp
  clang/test/SemaCXX/assume-nothrow-exception-dtor.cpp

Index: clang/test/SemaCXX/assume-nothrow-exception-dtor.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/assume-nothrow-exception-dtor.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -fsyntax-only %s -fcxx-exceptions -fassume-nothrow-exception-dtor -verify
+
+namespace test1 {
+template  struct A { A(); ~A(); };
+struct B { ~B() noexcept(false); };
+struct B1 : B {};
+struct B2 { B b; };
+struct C { virtual void f(); } c;
+struct MoveOnly { MoveOnly(); MoveOnly(MoveOnly&&); };
+void run() {
+  throw A();
+  throw B();  // expected-error{{cannot throw object of type 'B' with a potentially-throwing destructor}}
+  throw new B;
+  throw B1(); // expected-error{{cannot throw object of type 'B1' with a potentially-throwing destructor}}
+  B2 b2;
+  throw b2;   // expected-error{{cannot throw object of type 'B2' with a potentially-throwing destructor}}
+  throw c;
+  MoveOnly m;
+  throw m;
+}
+}
Index: clang/test/Driver/clang-exception-flags.cpp
===
--- clang/test/Driver/clang-exception-flags.cpp
+++ clang/test/Driver/clang-exception-flags.cpp
@@ -27,3 +27,6 @@
 // RUN: %clang -### -target x86_64-scei-ps4 %s 2>&1 | FileCheck %s -check-prefix=PS-OFF
 // RUN: %clang -### -target x86_64-sie-ps5 %s 2>&1 | FileCheck %s -check-prefix=PS-OFF
 // PS-OFF-NOT: "-cc1" {{.*}} "-f{{(cxx-)?}}exceptions"
+
+// RUN: %clang -### -fexceptions -fno-assume-nothrow-exception-dtor -fassume-nothrow-exception-dtor %s 2>&1 | FileCheck %s --check-prefix=NOTHROW-DTOR
+// NOTHROW-DTOR: "-cc1"{{.*}} "-fcxx-exceptions" "-fassume-nothrow-exception-dtor"
Index: clang/test/CodeGenCoroutines/coro-cleanup.cpp
===
--- clang/test/CodeGenCoroutines/coro-cleanup.cpp
+++ clang/test/CodeGenCoroutines/coro-cleanup.cpp
@@ -1,5 +1,6 @@
 // Verify that coroutine promise and allocated memory are freed up on exception.
-// RUN: %clang_cc1 -std=c++20 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s -fexceptions -fcxx-exceptions -disable-llvm-passes | FileCheck %s
+// RUN: %clang_cc1 -std=c++20 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s -fexceptions -fcxx-exceptions -disable-llvm-passes | FileCheck %s --check-prefixes=CHECK,THROWEND
+// RUN: %clang_cc1 -std=c++20 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s -fexceptions -fcxx-exceptions -fassume-nothrow-exception-dtor -disable-llvm-passes | FileCheck %s --check-prefixes=CHECK,NOTHROWEND
 
 namespace std {
 template  struct coroutine_traits;
@@ -49,7 +50,9 @@
   // CHECK: [[DeallocPad]]:
   // CHECK-NEXT: landingpad
   // CHECK-NEXT:   cleanup
-  // CHECK: br label %[[Dealloc:.+]]
+  // THROWEND:br label %[[Dealloc:.+]]
+  // NOTHROWEND:  icmp ne ptr %[[#]], null
+  // NOTHROWEND-NEXT: br i1 %[[#]], label %[[Dealloc:.+]], label
 
   Cleanup cleanup;
   may_throw();
@@ -68,13 +71,15 @@
   // CHECK: [[Catch]]:
   // CHECK:call ptr @__cxa_begin_catch(
   // CHECK:call void @_ZNSt16coroutine_traitsIJvEE12promise_type19unhandled_exceptionEv(
-  // CHECK:invoke void @__cxa_end_catch()
-  // CHECK-NEXT:to label %[[Cont:.+]] unwind
+  // THROWEND:invoke void @__cxa_end_catch()
+  // THROWEND-NEXT: to label %[[Cont:.+]] unwind
+  // NOTHROWEND:  call void @__cxa_end_catch()
+  // NOTHROWEND-NEXT:   br label %[[Cont2:.+]]
 
-  // CHECK: [[Cont]]:
-  // CHECK-NEXT: br label %[[Cont2:.+]]
-  // CHECK: [[Cont2]]:
-  // CHECK-NEXT: br label %[[Cleanup:.+]]
+  // THROWEND:  [[Cont]]:
+  // THROWEND-NEXT:   br label %[[Cont2:.+]]
+  // CHECK: [[Cont2]]:
+  // CHECK-NEXT:  br label %[[Cleanup:.+]]
 
   // CHECK: [[Cleanup]]:
   // CHECK: call void @_ZNSt16coroutine_traitsIJvEE12promise_typeD1Ev(
@@ -82,8 +87,8 @@
   // CHECK: call void @_ZdlPv(ptr noundef %[[Mem0]]
 
   // CHECK: [[Dealloc]]:
-  // CHECK:   %[[Mem:.+]] = call ptr @llvm.coro.free(
-  // CHECK:   call void @_ZdlPv(ptr noundef %[[Mem]])
+

[clang] [Driver][Solaris][NFC] A little bit of clean up (PR #69867)

2023-11-05 Thread Fangrui Song via cfe-commits

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


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


[clang] [Clang][CodeGen] Stoping emitting alignment assumes for `align_{up,down}` (PR #71295)

2023-11-05 Thread Nikita Popov via cfe-commits

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


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


[clang] 3e6ce58 - [clang][NFC] Refactor `StringLiteral::StringKind`

2023-11-05 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2023-11-05T12:30:49+03:00
New Revision: 3e6ce58701a3a8463b53fb3fd2023c02b4e90554

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

LOG: [clang][NFC] Refactor `StringLiteral::StringKind`

This patch converts `StringLiteral::StringKind` to a scoped enum in namespace 
scope. This enabled forward-declarations of this enum where necessary, e.g. for 
`preferred_type` annotation for bit-fields.

Added: 


Modified: 
clang/include/clang/AST/Expr.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/Expr.cpp
clang/lib/AST/ExprConstant.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
clang/lib/Frontend/Rewrite/RewriteObjC.cpp
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaExprObjC.cpp
clang/lib/Sema/SemaInit.cpp
clang/lib/Serialization/ASTWriterStmt.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 37821982000ea1b..1baaf06d96d86a3 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -1786,6 +1786,15 @@ class ImaginaryLiteral : public Expr {
   }
 };
 
+enum class StringLiteralKind {
+  Ordinary,
+  Wide,
+  UTF8,
+  UTF16,
+  UTF32,
+  Unevaluated
+};
+
 /// StringLiteral - This represents a string literal expression, e.g. "foo"
 /// or L"bar" (wide strings). The actual string data can be obtained with
 /// getBytes() and is NOT null-terminated. The length of the string data is
@@ -1825,7 +1834,7 @@ class StringLiteral final
   /// * An array of getByteLength() char used to store the string data.
 
 public:
-  enum StringKind { Ordinary, Wide, UTF8, UTF16, UTF32, Unevaluated };
+  // enum StringKind { Ordinary, Wide, UTF8, UTF16, UTF32, Unevaluated };
 
 private:
   unsigned numTrailingObjects(OverloadToken) const { return 1; }
@@ -1849,7 +1858,7 @@ class StringLiteral final
   }
 
   /// Build a string literal.
-  StringLiteral(const ASTContext &Ctx, StringRef Str, StringKind Kind,
+  StringLiteral(const ASTContext &Ctx, StringRef Str, StringLiteralKind Kind,
 bool Pascal, QualType Ty, const SourceLocation *Loc,
 unsigned NumConcatenated);
 
@@ -1858,7 +1867,8 @@ class StringLiteral final
 unsigned CharByteWidth);
 
   /// Map a target and string kind to the appropriate character width.
-  static unsigned mapCharByteWidth(TargetInfo const &Target, StringKind SK);
+  static unsigned mapCharByteWidth(TargetInfo const &Target,
+   StringLiteralKind SK);
 
   /// Set one of the string literal token.
   void setStrTokenLoc(unsigned TokNum, SourceLocation L) {
@@ -1870,13 +1880,13 @@ class StringLiteral final
   /// This is the "fully general" constructor that allows representation of
   /// strings formed from multiple concatenated tokens.
   static StringLiteral *Create(const ASTContext &Ctx, StringRef Str,
-   StringKind Kind, bool Pascal, QualType Ty,
+   StringLiteralKind Kind, bool Pascal, QualType 
Ty,
const SourceLocation *Loc,
unsigned NumConcatenated);
 
   /// Simple constructor for string literals made from one token.
   static StringLiteral *Create(const ASTContext &Ctx, StringRef Str,
-   StringKind Kind, bool Pascal, QualType Ty,
+   StringLiteralKind Kind, bool Pascal, QualType 
Ty,
SourceLocation Loc) {
 return Create(Ctx, Str, Kind, Pascal, Ty, &Loc, 1);
   }
@@ -1918,16 +1928,16 @@ class StringLiteral final
   unsigned getLength() const { return *getTrailingObjects(); }
   unsigned getCharByteWidth() const { return StringLiteralBits.CharByteWidth; }
 
-  StringKind getKind() const {
-return static_cast(StringLiteralBits.Kind);
+  StringLiteralKind getKind() const {
+return static_cast(StringLiteralBits.Kind);
   }
 
-  bool isOrdinary() const { return getKind() == Ordinary; }
-  bool isWide() const { return getKind() == Wide; }
-  bool isUTF8() const { return getKind() == UTF8; }
-  bool isUTF16() const { return getKind() == UTF16; }
-  bool isUTF32() const { return getKind() == UTF32; }
-  bool isUnevaluated() const { return getKind() == Unevaluated; }
+  bool isOrdinary() const { return getKind() == StringLiteralKind::Ordinary; }
+  bool isWide() const { return getKind() == StringLiteralKind::Wide; }
+  bool isUTF8() const { return getKind() == StringLiteralKind::UTF8; }
+  bool isUTF16() const { return getKind() == StringLiteralKind::UTF16; }
+  bool isUTF32() const { return getKind() == StringLiteralKind::UTF32; }
+  bool isUne

[clang] c23aaa4 - [clang][NFC] Refactor `CharacterLiteral::CharacterKind`

2023-11-05 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2023-11-05T13:36:08+03:00
New Revision: c23aaa410358b9f9c364ddaaeb6b2069b185a99b

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

LOG: [clang][NFC] Refactor `CharacterLiteral::CharacterKind`

This patch converts `CharacterLiteral::CharacterKind` to scoped enum in 
namespace scope. This enables forward declaration of this enum, which is useful 
in case like annotating bit-fields with `preferred_type`.

Added: 


Modified: 
clang/include/clang/AST/Expr.h
clang/lib/AST/Expr.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/AST/TemplateBase.cpp
clang/lib/Edit/RewriteObjCFoundationAPI.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprObjC.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriterStmt.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 1baaf06d96d86a3..7e8e183afc5d3cf 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -1620,26 +1620,18 @@ class FixedPointLiteral : public Expr, public 
APIntStorage {
   }
 };
 
-class CharacterLiteral : public Expr {
-public:
-  enum CharacterKind {
-Ascii,
-Wide,
-UTF8,
-UTF16,
-UTF32
-  };
+enum class CharacterLiteralKind { Ascii, Wide, UTF8, UTF16, UTF32 };
 
-private:
+class CharacterLiteral : public Expr {
   unsigned Value;
   SourceLocation Loc;
 public:
   // type should be IntTy
-  CharacterLiteral(unsigned value, CharacterKind kind, QualType type,
+  CharacterLiteral(unsigned value, CharacterLiteralKind kind, QualType type,
SourceLocation l)
   : Expr(CharacterLiteralClass, type, VK_PRValue, OK_Ordinary),
 Value(value), Loc(l) {
-CharacterLiteralBits.Kind = kind;
+CharacterLiteralBits.Kind = llvm::to_underlying(kind);
 setDependence(ExprDependence::None);
   }
 
@@ -1647,8 +1639,8 @@ class CharacterLiteral : public Expr {
   CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { }
 
   SourceLocation getLocation() const { return Loc; }
-  CharacterKind getKind() const {
-return static_cast(CharacterLiteralBits.Kind);
+  CharacterLiteralKind getKind() const {
+return static_cast(CharacterLiteralBits.Kind);
   }
 
   SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
@@ -1657,14 +1649,16 @@ class CharacterLiteral : public Expr {
   unsigned getValue() const { return Value; }
 
   void setLocation(SourceLocation Location) { Loc = Location; }
-  void setKind(CharacterKind kind) { CharacterLiteralBits.Kind = kind; }
+  void setKind(CharacterLiteralKind kind) {
+CharacterLiteralBits.Kind = llvm::to_underlying(kind);
+  }
   void setValue(unsigned Val) { Value = Val; }
 
   static bool classof(const Stmt *T) {
 return T->getStmtClass() == CharacterLiteralClass;
   }
 
-  static void print(unsigned val, CharacterKind Kind, raw_ostream &OS);
+  static void print(unsigned val, CharacterLiteralKind Kind, raw_ostream &OS);
 
   // Iterators
   child_range children() {

diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 15a64cc71b79fa3..eccff0699d21a2a 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -982,21 +982,21 @@ std::string FixedPointLiteral::getValueAsString(unsigned 
Radix) const {
   return std::string(S.str());
 }
 
-void CharacterLiteral::print(unsigned Val, CharacterKind Kind,
+void CharacterLiteral::print(unsigned Val, CharacterLiteralKind Kind,
  raw_ostream &OS) {
   switch (Kind) {
-  case CharacterLiteral::Ascii:
+  case CharacterLiteralKind::Ascii:
 break; // no prefix.
-  case CharacterLiteral::Wide:
+  case CharacterLiteralKind::Wide:
 OS << 'L';
 break;
-  case CharacterLiteral::UTF8:
+  case CharacterLiteralKind::UTF8:
 OS << "u8";
 break;
-  case CharacterLiteral::UTF16:
+  case CharacterLiteralKind::UTF16:
 OS << 'u';
 break;
-  case CharacterLiteral::UTF32:
+  case CharacterLiteralKind::UTF32:
 OS << 'U';
 break;
   }
@@ -1009,7 +1009,7 @@ void CharacterLiteral::print(unsigned Val, CharacterKind 
Kind,
 // would result in an invalid \U escape sequence.
 // FIXME: multicharacter literals such as '\xFF\xFF\xFF\xFF'
 // are not correctly handled.
-if ((Val & ~0xFFu) == ~0xFFu && Kind == CharacterLiteral::Ascii)
+if ((Val & ~0xFFu) == ~0xFFu && Kind == CharacterLiteralKind::Ascii)
   Val &= 0xFFu;
 if (Val < 256 && isPrintable((unsigned char)Val))
   OS << "'" << (char)Val << "'";

diff  --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp
index c4f524142ba6317..ce3381781ff68fa 100644
--- a/clang/lib/AST/StmtProfile.cpp
+++ b/clang/lib/AST/StmtProfile.cpp
@

[clang] [clang][Interp] Fix variables refering to their own address (PR #70587)

2023-11-05 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Ping

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


[clang] [clang][Interp] IndirectMember initializers (PR #69900)

2023-11-05 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Ping

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


[flang] [libcxx] [libc] [clang] [llvm] [compiler-rt] [clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-11-05 Thread James E T Smith via cfe-commits

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


[clang] [clang][docs] Improve "Obtainig Clang" section (PR #71313)

2023-11-05 Thread Robin Caloudis via cfe-commits

https://github.com/robincaloudis created 
https://github.com/llvm/llvm-project/pull/71313

The documentation is written relatively to `clang-llvm`, not the root 
repository directory. Therefore, the `llvm-project` repo needs to be cloned 
into the existing directory `clang-llvm`. As cloning into an existing directory 
is only allowed if the directory is empty, I added `mkdir ~/clang-llvm` to make 
the intent of creating an empty directory explicit.

>From 85d6cfbcebc97e3893f79d1cd39b1718f6e928d4 Mon Sep 17 00:00:00 2001
From: Robin Caloudis <53619127+robincalou...@users.noreply.github.com>
Date: Sun, 5 Nov 2023 13:34:29 +0100
Subject: [PATCH] [clang][docs] Improve "Obtainig Clang" section

The documentation is written relatively to `clang-llvm`, not the root 
repository directory. Therefore, the `llvm-project` repo needs to be cloned 
into the existing directory `clang-llvm`. As cloning into an existing directory 
is only allowed if the directory is empty, I added `mkdir ~/clang-llvm` to make 
the intent of creating an empty directory explicit.
---
 clang/docs/LibASTMatchersTutorial.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/docs/LibASTMatchersTutorial.rst 
b/clang/docs/LibASTMatchersTutorial.rst
index 37c9f178fa8df31..2a3f052f2e9ce15 100644
--- a/clang/docs/LibASTMatchersTutorial.rst
+++ b/clang/docs/LibASTMatchersTutorial.rst
@@ -22,8 +22,8 @@ started guide `_.
 
 .. code-block:: console
 
-  cd ~/clang-llvm
-  git clone https://github.com/llvm/llvm-project.git
+  mkdir ~/clang-llvm && cd ~/clang-llvm
+  git clone https://github.com/llvm/llvm-project.git .
 
 Next you need to obtain the CMake build system and Ninja build tool.
 

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


[clang] [clang][docs] Improve "Obtainig Clang" section (PR #71313)

2023-11-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Robin Caloudis (robincaloudis)


Changes

The documentation is written relatively to `clang-llvm`, not the root 
repository directory. Therefore, the `llvm-project` repo needs to be cloned 
into the existing directory `clang-llvm`. As cloning into an existing directory 
is only allowed if the directory is empty, I added `mkdir ~/clang-llvm` to make 
the intent of creating an empty directory explicit.

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


1 Files Affected:

- (modified) clang/docs/LibASTMatchersTutorial.rst (+2-2) 


``diff
diff --git a/clang/docs/LibASTMatchersTutorial.rst 
b/clang/docs/LibASTMatchersTutorial.rst
index 37c9f178fa8df31..2a3f052f2e9ce15 100644
--- a/clang/docs/LibASTMatchersTutorial.rst
+++ b/clang/docs/LibASTMatchersTutorial.rst
@@ -22,8 +22,8 @@ started guide `_.
 
 .. code-block:: console
 
-  cd ~/clang-llvm
-  git clone https://github.com/llvm/llvm-project.git
+  mkdir ~/clang-llvm && cd ~/clang-llvm
+  git clone https://github.com/llvm/llvm-project.git .
 
 Next you need to obtain the CMake build system and Ninja build tool.
 

``




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


[clang] [clang][docs] Improve "Obtaining Clang" section (PR #71313)

2023-11-05 Thread Robin Caloudis via cfe-commits

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


[flang] [libcxx] [libc] [clang] [llvm] [compiler-rt] [clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-11-05 Thread James E T Smith via cfe-commits

https://github.com/jamesETsmith updated 
https://github.com/llvm/llvm-project/pull/68494

>From c4a3ccfbad090ad8314aa8ad53092edc8d5432bc Mon Sep 17 00:00:00 2001
From: James Smith 
Date: Thu, 28 Sep 2023 10:11:15 -0400
Subject: [PATCH 01/17] [libc++] Implement ranges::iota and
 ranges::out_value_result

---
 libcxx/include/CMakeLists.txt |   2 +
 libcxx/include/__algorithm/out_value_result.h |  52 +
 libcxx/include/__numeric/ranges_iota.h|  53 +
 libcxx/include/algorithm  |   4 +
 libcxx/include/numeric|   1 +
 libcxx/include/version|   2 +-
 .../out_value_result.pass.cpp | 102 ++
 .../numeric.iota/ranges.iota.pass.cpp |  52 +
 8 files changed, 267 insertions(+), 1 deletion(-)
 create mode 100644 libcxx/include/__algorithm/out_value_result.h
 create mode 100644 libcxx/include/__numeric/ranges_iota.h
 create mode 100644 
libcxx/test/std/algorithms/algorithms.results/out_value_result.pass.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.iota/ranges.iota.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 2ec755236dbaee2..c6eb03f1d68e984 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -63,6 +63,7 @@ set(files
   __algorithm/next_permutation.h
   __algorithm/none_of.h
   __algorithm/nth_element.h
+  __algorithm/out_value_result.h
   __algorithm/partial_sort.h
   __algorithm/partial_sort_copy.h
   __algorithm/partition.h
@@ -561,6 +562,7 @@ set(files
   __numeric/partial_sum.h
   __numeric/pstl_reduce.h
   __numeric/pstl_transform_reduce.h
+  __numeric/ranges_iota.h
   __numeric/reduce.h
   __numeric/transform_exclusive_scan.h
   __numeric/transform_inclusive_scan.h
diff --git a/libcxx/include/__algorithm/out_value_result.h 
b/libcxx/include/__algorithm/out_value_result.h
new file mode 100644
index 000..8baffec7b9ef4da
--- /dev/null
+++ b/libcxx/include/__algorithm/out_value_result.h
@@ -0,0 +1,52 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
+#define _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+
+template 
+struct out_value_result {
+  _LIBCPP_NO_UNIQUE_ADDRESS _OutIter1 out;
+  _LIBCPP_NO_UNIQUE_ADDRESS _ValType1 value;
+
+  template 
+requires convertible_to && 
convertible_to
+  constexpr operator out_value_result<_OutIter2, _ValType2>() const& { return 
{out, value}; }
+
+  template 
+requires convertible_to<_OutIter1, _OutIter2> && convertible_to<_ValType1, 
_ValType2>
+  constexpr operator out_value_result<_OutIter2, _ValType2>() && { return 
{std::move(out), std::move(value)}; }
+};
+
+} // namespace ranges
+
+#endif // _LIBCPP_STD_VER >= 23
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
diff --git a/libcxx/include/__numeric/ranges_iota.h 
b/libcxx/include/__numeric/ranges_iota.h
new file mode 100644
index 000..20311a68c2a348c
--- /dev/null
+++ b/libcxx/include/__numeric/ranges_iota.h
@@ -0,0 +1,53 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___NUMERIC_RANGES_IOTA_H
+#define _LIBCPP___NUMERIC_RANGES_IOTA_H
+
+#include <__algorithm/out_value_result.h>
+#include <__config>
+#include <__ranges/concepts.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+namespace ranges {
+template 
+using iota_result = ranges::out_value_result<_Out, _Tp>;
+
+struct __iota_fn {
+  template  _Sent, 
weakly_incrementable _Tp>
+requires indirectly_writable<_Out, const _Tp&>
+  constexpr iota_result<_Out, _Tp> operator()(_Out __first, _Sent __last, _Tp 
__value) const {
+while (__first != __last) {
+  *__first = static_cast(__value);
+  ++__first;
+  ++__value;
+}
+return {std::move(__first), std::move(__valu

[clang] 6e35db0 - [clang][NFC] Refactor `PredefinedExpr::IdentKind`

2023-11-05 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2023-11-05T15:39:05+03:00
New Revision: 6e35db0694b2cb80ffe0c7edfed3090f9ede4805

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

LOG: [clang][NFC] Refactor `PredefinedExpr::IdentKind`

This patch converts `PredefinedExpr::IdentKind` into a scoped enum in namespace 
scope, making it eligible for forward declaring. This is useful in certain 
contexts, such as `preferred_type` annotations on bit-fields.

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/LambdaFunctionNameCheck.cpp
clang/include/clang/AST/Expr.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/Expr.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/AST/VTableBuilder.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTWriterStmt.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/LambdaFunctionNameCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/LambdaFunctionNameCheck.cpp
index a01b7f5a4ee6e68..5260a8b4ecb0bad 100644
--- a/clang-tools-extra/clang-tidy/bugprone/LambdaFunctionNameCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/LambdaFunctionNameCheck.cpp
@@ -82,8 +82,8 @@ void LambdaFunctionNameCheck::registerPPCallbacks(
 
 void LambdaFunctionNameCheck::check(const MatchFinder::MatchResult &Result) {
   const auto *E = Result.Nodes.getNodeAs("E");
-  if (E->getIdentKind() != PredefinedExpr::Func &&
-  E->getIdentKind() != PredefinedExpr::Function) {
+  if (E->getIdentKind() != PredefinedIdentKind::Func &&
+  E->getIdentKind() != PredefinedIdentKind::Function) {
 // We don't care about other PredefinedExprs.
 return;
   }

diff  --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 7e8e183afc5d3cf..c2691f80dc54a7e 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -1999,6 +1999,19 @@ class StringLiteral final
   }
 };
 
+enum class PredefinedIdentKind {
+  Func,
+  Function,
+  LFunction, // Same as Function, but as wide string.
+  FuncDName,
+  FuncSig,
+  LFuncSig, // Same as FuncSig, but as wide string
+  PrettyFunction,
+  /// The same as PrettyFunction, except that the
+  /// 'virtual' keyword is omitted for virtual member functions.
+  PrettyFunctionNoVirtual
+};
+
 /// [C99 6.4.2.2] - A predefined identifier such as __func__.
 class PredefinedExpr final
 : public Expr,
@@ -2010,22 +2023,7 @@ class PredefinedExpr final
   // "Stmt *" for the predefined identifier. It is present if and only if
   // hasFunctionName() is true and is always a "StringLiteral *".
 
-public:
-  enum IdentKind {
-Func,
-Function,
-LFunction, // Same as Function, but as wide string.
-FuncDName,
-FuncSig,
-LFuncSig, // Same as FuncSig, but as wide string
-PrettyFunction,
-/// The same as PrettyFunction, except that the
-/// 'virtual' keyword is omitted for virtual member functions.
-PrettyFunctionNoVirtual
-  };
-
-private:
-  PredefinedExpr(SourceLocation L, QualType FNTy, IdentKind IK,
+  PredefinedExpr(SourceLocation L, QualType FNTy, PredefinedIdentKind IK,
  bool IsTransparent, StringLiteral *SL);
 
   explicit PredefinedExpr(EmptyShell Empty, bool HasFunctionName);
@@ -2045,15 +2043,15 @@ class PredefinedExpr final
   /// If IsTransparent, the PredefinedExpr is transparently handled as a
   /// StringLiteral.
   static PredefinedExpr *Create(const ASTContext &Ctx, SourceLocation L,
-QualType FNTy, IdentKind IK, bool 
IsTransparent,
-StringLiteral *SL);
+QualType FNTy, PredefinedIdentKind IK,
+bool IsTransparent, StringLiteral *SL);
 
   /// Create an empty PredefinedExpr.
   static PredefinedExpr *CreateEmpty(const ASTContext &Ctx,
  bool HasFunctionName);
 
-  IdentKind getIdentKind() const {
-return static_cast(PredefinedExprBits.Kind);
+  PredefinedIdentKind getIdentKind() const {
+return static_cast(PredefinedExprBits.Kind);
   }
 
   bool isTransparent() const { return PredefinedExprBits.IsTransparent; }
@@ -2073,12 +2071,13 @@ class PredefinedExpr final
: nullptr;
   }
 
-  static StringRef getIdentKindName(IdentKind IK);
+  static StringRef getIdentKindName(PredefinedIdentKind IK);
   StringRef getIdentKindName() const {
 return getIdentKindName(getIdentKind());
   }
 
-  static std::string ComputeName(IdentKind IK, const Decl *CurrentDecl);
+  static std::string ComputeName(PredefinedIdentKind IK,
+ const Decl *CurrentDecl);
 
   SourceLocation getBeginLoc() const { return getLocation(); }
   SourceLocation getEndLoc() const { return getLocatio

[clang] [clang][docs] Improve "Obtaining Clang" section (PR #71313)

2023-11-05 Thread Robin Caloudis via cfe-commits

https://github.com/robincaloudis updated 
https://github.com/llvm/llvm-project/pull/71313

>From a2862b11889a0ce5ad696c6397a1a557f72c2191 Mon Sep 17 00:00:00 2001
From: Robin Caloudis <53619127+robincalou...@users.noreply.github.com>
Date: Sun, 5 Nov 2023 13:34:29 +0100
Subject: [PATCH] [clang][docs] Improve "Obtaining Clang" section

The documentation is written relatively to
`clang-llvm`, not the root repository directory.
Therefore, the `llvm-project` repo needs to be
cloned into the existing directory `clang-llvm`.
As cloning into an existing directory is only
allowed if the directory is empty, I added
`mkdir ~/clang-llvm` to make the intent of
creating an empty directory explicit.
---
 clang/docs/LibASTMatchersTutorial.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/docs/LibASTMatchersTutorial.rst 
b/clang/docs/LibASTMatchersTutorial.rst
index 37c9f178fa8df31..2a3f052f2e9ce15 100644
--- a/clang/docs/LibASTMatchersTutorial.rst
+++ b/clang/docs/LibASTMatchersTutorial.rst
@@ -22,8 +22,8 @@ started guide `_.
 
 .. code-block:: console
 
-  cd ~/clang-llvm
-  git clone https://github.com/llvm/llvm-project.git
+  mkdir ~/clang-llvm && cd ~/clang-llvm
+  git clone https://github.com/llvm/llvm-project.git .
 
 Next you need to obtain the CMake build system and Ninja build tool.
 

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


[clang] [flang] [llvm] [clang-tools-extra] [lldb] [IndVars] Add check of loop invariant for trunc instructions (PR #71072)

2023-11-05 Thread Markos Horro via cfe-commits


@@ -0,0 +1,28 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -passes=indvars -S | FileCheck %s
+
+declare void @foo(i16 noundef)
+
+; Function Attrs: mustprogress noreturn uwtable
+define void @bar(i64 noundef %ptr) {
+; CHECK-LABEL: @bar(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[TMP0:%.*]] = trunc i64 [[PTR:%.*]] to i4
+; CHECK-NEXT:[[TMP1:%.*]] = zext i4 [[TMP0]] to i16
+; CHECK-NEXT:br label [[WHILE_BODY:%.*]]
+; CHECK:   while.body:
+; CHECK-NEXT:tail call void @foo(i16 noundef signext [[TMP1]])
+; CHECK-NEXT:br label [[WHILE_BODY]]
+;
+entry:
+  br label %while.body
+
+while.body:   ; preds = %entry, %while.body
+  %0 = phi i64 [ %ptr, %entry ], [ %add.ptr, %while.body ]
+  %1 = trunc i64 %0 to i16
+  %and = and i16 %1, 15   ; loop invariant
+  tail call void @foo(i16 noundef signext %and)

markoshorro wrote:

What I've also observed from the regression is that we have one test failing: 
`test_11` in `Transforms/IndVarSimplify/X86/eliminate-trunc.ll`.

In concrete, in the function the statement failing is:

```ll
define void @test_11() {
...
bb5:  ; preds = %bb5, %bb5
  %_tmp24 = icmp slt i16 %_tmp15, 0
  br i1 %_tmp24, label %bb5, label %bb5
...
}
```

which instead of the expected (as it is currently in the test):

```ll
; CHECK:   bb5:
; CHECK-NEXT:[[_TMP24:%.*]] = icmp slt i16 poison, 0
; CHECK-NEXT:br i1 [[_TMP24]], label [[BB5:%.*]], label [[BB5]]
```

It gets simplified to:

```ll
bb5:  ; preds = %bb5, %bb5
  br i1 poison, label %bb5, label %bb5
```

I'm assuming this simplification is correct, but I don't understand why this is 
happening with this change. 


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


[lldb] [clang-tools-extra] [clang] [llvm] [flang] [IndVars] Add check of loop invariant for trunc instructions (PR #71072)

2023-11-05 Thread Markos Horro via cfe-commits

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


[clang] [clang][Interp] Add an EvaluationResult class (PR #71315)

2023-11-05 Thread Timm Baeder via cfe-commits

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

Add an `EvaluationResult` class. This contains the result either as a `Pointer` 
or as a `APValue`.

This way, we can inspect the result of the evaluation and diagnose problems 
with it (e.g. uninitialized fields in global initializers or pointers pointing 
to things they shouldn't point to).

Other changes:
 1) Move the code from `EvalEmitter::emitRetValue` to `Pointer::toRValue`.
 2) To the implicit lvalue-to-rvalue ourselves instead of doing it in 
`ExprConstant.cpp`.
 3) Remove the awkward `CheckGlobalCtor` opcode and do it in 
`evaluateAsInitializer` instead.
 4) Add  a new `Context::evaluate()` function which is similar to 
`evaluateAsRValue() but without the lvalue-to-rvalue conversion.
  5) This patch also contains changes from 
https://github.com/llvm/llvm-project/pull/70763
  6) To make the changes in `EvalEmitter::interpret{Expr,Decl}` easier, this 
also removes the `BailLocation` handling. It was untested anyway and I we would 
towards never needing it anyway.


>From 52403454622937d4c9a608e95845ead97427268e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Tue, 31 Oct 2023 14:57:51 +0100
Subject: [PATCH] EvaluationResult

---
 clang/lib/AST/CMakeLists.txt  |   1 +
 clang/lib/AST/ExprConstant.cpp|  27 ++-
 clang/lib/AST/Interp/ByteCodeEmitter.cpp  |  13 +-
 clang/lib/AST/Interp/ByteCodeEmitter.h|   5 +-
 clang/lib/AST/Interp/ByteCodeExprGen.cpp  |   3 +-
 clang/lib/AST/Interp/ByteCodeExprGen.h|  12 +-
 clang/lib/AST/Interp/Context.cpp  | 110 
 clang/lib/AST/Interp/Context.h|   3 +
 clang/lib/AST/Interp/EvalEmitter.cpp  | 153 +
 clang/lib/AST/Interp/EvalEmitter.h|  11 +-
 clang/lib/AST/Interp/EvaluationResult.cpp | 196 ++
 clang/lib/AST/Interp/EvaluationResult.h   | 111 
 clang/lib/AST/Interp/Interp.cpp   |  92 --
 clang/lib/AST/Interp/Interp.h |  16 +-
 clang/lib/AST/Interp/Opcodes.td   |   2 -
 clang/lib/AST/Interp/Pointer.cpp  | 132 ---
 clang/lib/AST/Interp/Pointer.h|   3 +-
 clang/test/AST/Interp/literals.cpp|   4 +-
 clang/test/AST/Interp/records.cpp |   1 -
 19 files changed, 587 insertions(+), 308 deletions(-)
 create mode 100644 clang/lib/AST/Interp/EvaluationResult.cpp
 create mode 100644 clang/lib/AST/Interp/EvaluationResult.h

diff --git a/clang/lib/AST/CMakeLists.txt b/clang/lib/AST/CMakeLists.txt
index fe3f8c485ec1c56..ebcb3952198a5b5 100644
--- a/clang/lib/AST/CMakeLists.txt
+++ b/clang/lib/AST/CMakeLists.txt
@@ -75,6 +75,7 @@ add_clang_library(clangAST
   Interp/Function.cpp
   Interp/InterpBuiltin.cpp
   Interp/Floating.cpp
+  Interp/EvaluationResult.cpp
   Interp/Interp.cpp
   Interp/InterpBlock.cpp
   Interp/InterpFrame.cpp
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index b6b1e6617dffaa9..d6e223e77d6f1c3 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -15418,11 +15418,13 @@ static bool EvaluateAsRValue(EvalInfo &Info, const 
Expr *E, APValue &Result) {
   if (Info.EnableNewConstInterp) {
 if (!Info.Ctx.getInterpContext().evaluateAsRValue(Info, E, Result))
   return false;
-  } else {
-if (!::Evaluate(Result, Info, E))
-  return false;
+return CheckConstantExpression(Info, E->getExprLoc(), E->getType(), Result,
+   ConstantExprKind::Normal);
   }
 
+  if (!::Evaluate(Result, Info, E))
+return false;
+
   // Implicit lvalue-to-rvalue cast.
   if (E->isGLValue()) {
 LValue LV;
@@ -15650,6 +15652,13 @@ bool Expr::EvaluateAsConstantExpr(EvalResult &Result, 
const ASTContext &Ctx,
   EvalInfo Info(Ctx, Result, EM);
   Info.InConstantContext = true;
 
+  if (Info.EnableNewConstInterp) {
+if (!Info.Ctx.getInterpContext().evaluate(Info, this, Result.Val))
+  return false;
+return CheckConstantExpression(Info, getExprLoc(),
+   getStorageType(Ctx, this), Result.Val, 
Kind);
+  }
+
   // The type of the object we're initializing is 'const T' for a class NTTP.
   QualType T = getType();
   if (Kind == ConstantExprKind::ClassTemplateArgument)
@@ -15662,10 +15671,10 @@ bool Expr::EvaluateAsConstantExpr(EvalResult &Result, 
const ASTContext &Ctx,
   APValue::LValueBase Base(&BaseMTE);
 
   Info.setEvaluatingDecl(Base, Result.Val);
-  LValue LVal;
-  LVal.set(Base);
 
   {
+LValue LVal;
+LVal.set(Base);
 // C++23 [intro.execution]/p5
 // A full-expression is [...] a constant-expression
 // So we need to make sure temporary objects are destroyed after having
@@ -15723,10 +15732,16 @@ bool Expr::EvaluateAsInitializer(APValue &Value, 
const ASTContext &Ctx,
   Info.setEvaluatingDecl(VD, Value);
   Info.InConstantContext = IsConstantInitialization;
 
+  SourceLocation DeclLoc = VD->getLocation();
+ 

[clang] [clang][Interp] Add an EvaluationResult class (PR #71315)

2023-11-05 Thread Timm Baeder via cfe-commits

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

>From b102c7d258e5538ad9f4a851191656243b913523 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Tue, 31 Oct 2023 14:57:51 +0100
Subject: [PATCH] EvaluationResult

---
 clang/lib/AST/CMakeLists.txt  |   1 +
 clang/lib/AST/ExprConstant.cpp|  27 ++-
 clang/lib/AST/Interp/ByteCodeEmitter.cpp  |  13 +-
 clang/lib/AST/Interp/ByteCodeEmitter.h|   5 +-
 clang/lib/AST/Interp/ByteCodeExprGen.cpp  |   3 +-
 clang/lib/AST/Interp/ByteCodeExprGen.h|  12 +-
 clang/lib/AST/Interp/Context.cpp  | 106 
 clang/lib/AST/Interp/Context.h|   3 +
 clang/lib/AST/Interp/EvalEmitter.cpp  | 153 +
 clang/lib/AST/Interp/EvalEmitter.h|  11 +-
 clang/lib/AST/Interp/EvaluationResult.cpp | 196 ++
 clang/lib/AST/Interp/EvaluationResult.h   | 111 
 clang/lib/AST/Interp/Interp.cpp   |  92 --
 clang/lib/AST/Interp/Interp.h |  16 +-
 clang/lib/AST/Interp/Opcodes.td   |   2 -
 clang/lib/AST/Interp/Pointer.cpp  | 132 ---
 clang/lib/AST/Interp/Pointer.h|   3 +-
 clang/test/AST/Interp/literals.cpp|   4 +-
 clang/test/AST/Interp/records.cpp |   1 -
 19 files changed, 583 insertions(+), 308 deletions(-)
 create mode 100644 clang/lib/AST/Interp/EvaluationResult.cpp
 create mode 100644 clang/lib/AST/Interp/EvaluationResult.h

diff --git a/clang/lib/AST/CMakeLists.txt b/clang/lib/AST/CMakeLists.txt
index fe3f8c485ec1c56..ebcb3952198a5b5 100644
--- a/clang/lib/AST/CMakeLists.txt
+++ b/clang/lib/AST/CMakeLists.txt
@@ -75,6 +75,7 @@ add_clang_library(clangAST
   Interp/Function.cpp
   Interp/InterpBuiltin.cpp
   Interp/Floating.cpp
+  Interp/EvaluationResult.cpp
   Interp/Interp.cpp
   Interp/InterpBlock.cpp
   Interp/InterpFrame.cpp
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index b6b1e6617dffaa9..d6e223e77d6f1c3 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -15418,11 +15418,13 @@ static bool EvaluateAsRValue(EvalInfo &Info, const 
Expr *E, APValue &Result) {
   if (Info.EnableNewConstInterp) {
 if (!Info.Ctx.getInterpContext().evaluateAsRValue(Info, E, Result))
   return false;
-  } else {
-if (!::Evaluate(Result, Info, E))
-  return false;
+return CheckConstantExpression(Info, E->getExprLoc(), E->getType(), Result,
+   ConstantExprKind::Normal);
   }
 
+  if (!::Evaluate(Result, Info, E))
+return false;
+
   // Implicit lvalue-to-rvalue cast.
   if (E->isGLValue()) {
 LValue LV;
@@ -15650,6 +15652,13 @@ bool Expr::EvaluateAsConstantExpr(EvalResult &Result, 
const ASTContext &Ctx,
   EvalInfo Info(Ctx, Result, EM);
   Info.InConstantContext = true;
 
+  if (Info.EnableNewConstInterp) {
+if (!Info.Ctx.getInterpContext().evaluate(Info, this, Result.Val))
+  return false;
+return CheckConstantExpression(Info, getExprLoc(),
+   getStorageType(Ctx, this), Result.Val, 
Kind);
+  }
+
   // The type of the object we're initializing is 'const T' for a class NTTP.
   QualType T = getType();
   if (Kind == ConstantExprKind::ClassTemplateArgument)
@@ -15662,10 +15671,10 @@ bool Expr::EvaluateAsConstantExpr(EvalResult &Result, 
const ASTContext &Ctx,
   APValue::LValueBase Base(&BaseMTE);
 
   Info.setEvaluatingDecl(Base, Result.Val);
-  LValue LVal;
-  LVal.set(Base);
 
   {
+LValue LVal;
+LVal.set(Base);
 // C++23 [intro.execution]/p5
 // A full-expression is [...] a constant-expression
 // So we need to make sure temporary objects are destroyed after having
@@ -15723,10 +15732,16 @@ bool Expr::EvaluateAsInitializer(APValue &Value, 
const ASTContext &Ctx,
   Info.setEvaluatingDecl(VD, Value);
   Info.InConstantContext = IsConstantInitialization;
 
+  SourceLocation DeclLoc = VD->getLocation();
+  QualType DeclTy = VD->getType();
+
   if (Info.EnableNewConstInterp) {
 auto &InterpCtx = const_cast(Ctx).getInterpContext();
 if (!InterpCtx.evaluateAsInitializer(Info, VD, Value))
   return false;
+
+return CheckConstantExpression(Info, DeclLoc, DeclTy, Value,
+   ConstantExprKind::Normal);
   } else {
 LValue LVal;
 LVal.set(VD);
@@ -15744,8 +15759,6 @@ bool Expr::EvaluateAsInitializer(APValue &Value, const 
ASTContext &Ctx,
   llvm_unreachable("Unhandled cleanup; missing full expression marker?");
   }
 
-  SourceLocation DeclLoc = VD->getLocation();
-  QualType DeclTy = VD->getType();
   return CheckConstantExpression(Info, DeclLoc, DeclTy, Value,
  ConstantExprKind::Normal) &&
  CheckMemoryLeaks(Info);
diff --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp 
b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
index c8abb7c17a38ba2..d3a9583bee59e59 100644
--- a/clang/lib/AST/Interp

[clang] [clang][Interp] Add an EvaluationResult class (PR #71315)

2023-11-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

Add an `EvaluationResult` class. This contains the result either as a `Pointer` 
or as a `APValue`.

This way, we can inspect the result of the evaluation and diagnose problems 
with it (e.g. uninitialized fields in global initializers or pointers pointing 
to things they shouldn't point to).

Other changes:
 1) Move the code from `EvalEmitter::emitRetValue` to `Pointer::toRValue`.
 2) To the implicit lvalue-to-rvalue ourselves instead of doing it in 
`ExprConstant.cpp`.
 3) Remove the awkward `CheckGlobalCtor` opcode and do it in 
`evaluateAsInitializer` instead.
 4) Add  a new `Context::evaluate()` function which is similar to 
`evaluateAsRValue() but without the lvalue-to-rvalue conversion.
  5) This patch also contains changes from 
https://github.com/llvm/llvm-project/pull/70763
  6) To make the changes in `EvalEmitter::interpret{Expr,Decl}` easier, this 
also removes the `BailLocation` handling. It was untested anyway and I we would 
towards never needing it anyway.


---

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


19 Files Affected:

- (modified) clang/lib/AST/CMakeLists.txt (+1) 
- (modified) clang/lib/AST/ExprConstant.cpp (+20-7) 
- (modified) clang/lib/AST/Interp/ByteCodeEmitter.cpp (+2-11) 
- (modified) clang/lib/AST/Interp/ByteCodeEmitter.h (+1-4) 
- (modified) clang/lib/AST/Interp/ByteCodeExprGen.cpp (+2-1) 
- (modified) clang/lib/AST/Interp/ByteCodeExprGen.h (+7-5) 
- (modified) clang/lib/AST/Interp/Context.cpp (+73-33) 
- (modified) clang/lib/AST/Interp/Context.h (+3) 
- (modified) clang/lib/AST/Interp/EvalEmitter.cpp (+42-111) 
- (modified) clang/lib/AST/Interp/EvalEmitter.h (+6-5) 
- (added) clang/lib/AST/Interp/EvaluationResult.cpp (+196) 
- (added) clang/lib/AST/Interp/EvaluationResult.h (+111) 
- (modified) clang/lib/AST/Interp/Interp.cpp (-92) 
- (modified) clang/lib/AST/Interp/Interp.h (+6-10) 
- (modified) clang/lib/AST/Interp/Opcodes.td (-2) 
- (modified) clang/lib/AST/Interp/Pointer.cpp (+110-22) 
- (modified) clang/lib/AST/Interp/Pointer.h (+2-1) 
- (modified) clang/test/AST/Interp/literals.cpp (+1-3) 
- (modified) clang/test/AST/Interp/records.cpp (-1) 


``diff
diff --git a/clang/lib/AST/CMakeLists.txt b/clang/lib/AST/CMakeLists.txt
index fe3f8c485ec1c56..ebcb3952198a5b5 100644
--- a/clang/lib/AST/CMakeLists.txt
+++ b/clang/lib/AST/CMakeLists.txt
@@ -75,6 +75,7 @@ add_clang_library(clangAST
   Interp/Function.cpp
   Interp/InterpBuiltin.cpp
   Interp/Floating.cpp
+  Interp/EvaluationResult.cpp
   Interp/Interp.cpp
   Interp/InterpBlock.cpp
   Interp/InterpFrame.cpp
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index b6b1e6617dffaa9..d6e223e77d6f1c3 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -15418,11 +15418,13 @@ static bool EvaluateAsRValue(EvalInfo &Info, const 
Expr *E, APValue &Result) {
   if (Info.EnableNewConstInterp) {
 if (!Info.Ctx.getInterpContext().evaluateAsRValue(Info, E, Result))
   return false;
-  } else {
-if (!::Evaluate(Result, Info, E))
-  return false;
+return CheckConstantExpression(Info, E->getExprLoc(), E->getType(), Result,
+   ConstantExprKind::Normal);
   }
 
+  if (!::Evaluate(Result, Info, E))
+return false;
+
   // Implicit lvalue-to-rvalue cast.
   if (E->isGLValue()) {
 LValue LV;
@@ -15650,6 +15652,13 @@ bool Expr::EvaluateAsConstantExpr(EvalResult &Result, 
const ASTContext &Ctx,
   EvalInfo Info(Ctx, Result, EM);
   Info.InConstantContext = true;
 
+  if (Info.EnableNewConstInterp) {
+if (!Info.Ctx.getInterpContext().evaluate(Info, this, Result.Val))
+  return false;
+return CheckConstantExpression(Info, getExprLoc(),
+   getStorageType(Ctx, this), Result.Val, 
Kind);
+  }
+
   // The type of the object we're initializing is 'const T' for a class NTTP.
   QualType T = getType();
   if (Kind == ConstantExprKind::ClassTemplateArgument)
@@ -15662,10 +15671,10 @@ bool Expr::EvaluateAsConstantExpr(EvalResult &Result, 
const ASTContext &Ctx,
   APValue::LValueBase Base(&BaseMTE);
 
   Info.setEvaluatingDecl(Base, Result.Val);
-  LValue LVal;
-  LVal.set(Base);
 
   {
+LValue LVal;
+LVal.set(Base);
 // C++23 [intro.execution]/p5
 // A full-expression is [...] a constant-expression
 // So we need to make sure temporary objects are destroyed after having
@@ -15723,10 +15732,16 @@ bool Expr::EvaluateAsInitializer(APValue &Value, 
const ASTContext &Ctx,
   Info.setEvaluatingDecl(VD, Value);
   Info.InConstantContext = IsConstantInitialization;
 
+  SourceLocation DeclLoc = VD->getLocation();
+  QualType DeclTy = VD->getType();
+
   if (Info.EnableNewConstInterp) {
 auto &InterpCtx = const_cast(Ctx).getInterpContext();
 if (!InterpCtx.evaluateAsInitializer(Info, VD, Value))
   re

[clang-tools-extra] a9070f2 - [clang][NFC] Refactor `CXXConstructExpr::ConstructionKind`

2023-11-05 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2023-11-05T16:38:45+03:00
New Revision: a9070f22a29e28f7d6f83c24a8dd88f3a94969ae

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

LOG: [clang][NFC] Refactor `CXXConstructExpr::ConstructionKind`

This patch converts `CXXConstructExpr::ConstructionKind` into a scoped enum in 
namespace scope, making it eligible for forward declaring. This is useful in 
cases like annotating bit-fields with `preferred_type`.

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
clang/include/clang/AST/ExprCXX.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/ExprCXX.cpp
clang/lib/AST/JSONNodeDumper.cpp
clang/lib/CodeGen/CGExprCXX.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaInit.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTWriterStmt.cpp
clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
clang/www/analyzer/open_projects.html

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp 
b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
index c92bd8afa6add82..e7e01bab0e9d523 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
@@ -174,7 +174,7 @@ const Expr *digThroughConstructorsConversions(const Expr 
*E) {
 // The initial constructor must take exactly one parameter, but base class
 // and deferred constructors can take more.
 if (ConstructExpr->getNumArgs() != 1 ||
-ConstructExpr->getConstructionKind() != CXXConstructExpr::CK_Complete)
+ConstructExpr->getConstructionKind() != CXXConstructionKind::Complete)
   return nullptr;
 E = ConstructExpr->getArg(0);
 if (const auto *Temp = dyn_cast(E))

diff  --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 020dcfd86ad67ea..a106bafcfa3e021 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -1519,19 +1519,17 @@ class CXXBindTemporaryExpr : public Expr {
   }
 };
 
+enum class CXXConstructionKind {
+  Complete,
+  NonVirtualBase,
+  VirtualBase,
+  Delegating
+};
+
 /// Represents a call to a C++ constructor.
 class CXXConstructExpr : public Expr {
   friend class ASTStmtReader;
 
-public:
-  enum ConstructionKind {
-CK_Complete,
-CK_NonVirtualBase,
-CK_VirtualBase,
-CK_Delegating
-  };
-
-private:
   /// A pointer to the constructor which will be ultimately called.
   CXXConstructorDecl *Constructor;
 
@@ -1567,7 +1565,7 @@ class CXXConstructExpr : public Expr {
CXXConstructorDecl *Ctor, bool Elidable,
ArrayRef Args, bool HadMultipleCandidates,
bool ListInitialization, bool StdInitListInitialization,
-   bool ZeroInitialization, ConstructionKind ConstructKind,
+   bool ZeroInitialization, CXXConstructionKind ConstructKind,
SourceRange ParenOrBraceRange);
 
   /// Build an empty C++ construction expression.
@@ -1586,7 +1584,7 @@ class CXXConstructExpr : public Expr {
  CXXConstructorDecl *Ctor, bool Elidable, ArrayRef Args,
  bool HadMultipleCandidates, bool ListInitialization,
  bool StdInitListInitialization, bool ZeroInitialization,
- ConstructionKind ConstructKind, SourceRange ParenOrBraceRange);
+ CXXConstructionKind ConstructKind, SourceRange ParenOrBraceRange);
 
   /// Create an empty C++ construction expression.
   static CXXConstructExpr *CreateEmpty(const ASTContext &Ctx, unsigned 
NumArgs);
@@ -1640,11 +1638,12 @@ class CXXConstructExpr : public Expr {
 
   /// Determine whether this constructor is actually constructing
   /// a base class (rather than a complete object).
-  ConstructionKind getConstructionKind() const {
-return 
static_cast(CXXConstructExprBits.ConstructionKind);
+  CXXConstructionKind getConstructionKind() const {
+return static_cast(
+CXXConstructExprBits.ConstructionKind);
   }
-  void setConstructionKind(ConstructionKind CK) {
-CXXConstructExprBits.ConstructionKind = CK;
+  void setConstructionKind(CXXConstructionKind CK) {
+CXXConstructExprBits.ConstructionKind = llvm::to_underlying(CK);
   }
 
   using arg_iterator = ExprIterator;
@@ -1761,9 +1760,9 @@ class CXXInheritedCtorInitExpr : public Expr {
   /// Determine whether this constructor is actually constructing
   /// a base class (rather than a complete object).
   bool constructsVBase() const { return ConstructsV

[clang] [X86] Add a EVEX256 macro to match with GCC and MSVC (PR #71317)

2023-11-05 Thread Phoebe Wang via cfe-commits

https://github.com/phoebewang created 
https://github.com/llvm/llvm-project/pull/71317

None

>From 50fb9c29b16c26e82bbc07ae8a092f572caa73a5 Mon Sep 17 00:00:00 2001
From: Phoebe Wang 
Date: Sun, 5 Nov 2023 21:50:44 +0800
Subject: [PATCH] [X86] Add a EVEX256 macro to match with GCC and MSVC

---
 clang/lib/Basic/Targets/X86.cpp   |  4 +++-
 .../Preprocessor/predefined-arch-macros.c | 24 +++
 clang/test/Preprocessor/x86_target_features.c | 11 +
 3 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index eec3cd558435e2a..6703e51df5eaa36 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -797,8 +797,10 @@ void X86TargetInfo::getTargetDefines(const LangOptions 
&Opts,
 Builder.defineMacro("__AVX512BITALG__");
   if (HasAVX512BW)
 Builder.defineMacro("__AVX512BW__");
-  if (HasAVX512VL)
+  if (HasAVX512VL) {
 Builder.defineMacro("__AVX512VL__");
+Builder.defineMacro("__EVEX256__");
+  }
   if (HasAVX512VBMI)
 Builder.defineMacro("__AVX512VBMI__");
   if (HasAVX512VBMI2)
diff --git a/clang/test/Preprocessor/predefined-arch-macros.c 
b/clang/test/Preprocessor/predefined-arch-macros.c
index f10793983b5e7c6..1ae6faea7767857 100644
--- a/clang/test/Preprocessor/predefined-arch-macros.c
+++ b/clang/test/Preprocessor/predefined-arch-macros.c
@@ -799,6 +799,7 @@
 // CHECK_KNL_M32: #define __AVX__ 1
 // CHECK_KNL_M32: #define __BMI2__ 1
 // CHECK_KNL_M32: #define __BMI__ 1
+// CHECK_KNL_M32-NOT: #define __EVEX256__ 1
 // CHECK_KNL_M32: #define __EVEX512__ 1
 // CHECK_KNL_M32: #define __F16C__ 1
 // CHECK_KNL_M32: #define __FMA__ 1
@@ -837,6 +838,7 @@
 // CHECK_KNL_M64: #define __AVX__ 1
 // CHECK_KNL_M64: #define __BMI2__ 1
 // CHECK_KNL_M64: #define __BMI__ 1
+// CHECK_KNL_M64-NOT: #define __EVEX256__ 1
 // CHECK_KNL_M64: #define __EVEX512__ 1
 // CHECK_KNL_M64: #define __F16C__ 1
 // CHECK_KNL_M64: #define __FMA__ 1
@@ -879,6 +881,7 @@
 // CHECK_KNM_M32: #define __AVX__ 1
 // CHECK_KNM_M32: #define __BMI2__ 1
 // CHECK_KNM_M32: #define __BMI__ 1
+// CHECK_KNM_M32-NOT: #define __EVEX256__ 1
 // CHECK_KNM_M32: #define __EVEX512__ 1
 // CHECK_KNM_M32: #define __F16C__ 1
 // CHECK_KNM_M32: #define __FMA__ 1
@@ -915,6 +918,7 @@
 // CHECK_KNM_M64: #define __AVX__ 1
 // CHECK_KNM_M64: #define __BMI2__ 1
 // CHECK_KNM_M64: #define __BMI__ 1
+// CHECK_KNM_M64-NOT: #define __EVEX256__ 1
 // CHECK_KNM_M64: #define __EVEX512__ 1
 // CHECK_KNM_M64: #define __F16C__ 1
 // CHECK_KNM_M64: #define __FMA__ 1
@@ -956,6 +960,7 @@
 // CHECK_SKX_M32: #define __BMI__ 1
 // CHECK_SKX_M32: #define __CLFLUSHOPT__ 1
 // CHECK_SKX_M32: #define __CLWB__ 1
+// CHECK_SKX_M32: #define __EVEX256__ 1
 // CHECK_SKX_M32: #define __EVEX512__ 1
 // CHECK_SKX_M32: #define __F16C__ 1
 // CHECK_SKX_M32: #define __FMA__ 1
@@ -1002,6 +1007,7 @@
 // CHECK_SKX_M64: #define __BMI__ 1
 // CHECK_SKX_M64: #define __CLFLUSHOPT__ 1
 // CHECK_SKX_M64: #define __CLWB__ 1
+// CHECK_SKX_M64: #define __EVEX256__ 1
 // CHECK_SKX_M64: #define __EVEX512__ 1
 // CHECK_SKX_M64: #define __F16C__ 1
 // CHECK_SKX_M64: #define __FMA__ 1
@@ -1052,6 +1058,7 @@
 // CHECK_CLX_M32: #define __BMI__ 1
 // CHECK_CLX_M32: #define __CLFLUSHOPT__ 1
 // CHECK_CLX_M32: #define __CLWB__ 1
+// CHECK_CLX_M32: #define __EVEX256__ 1
 // CHECK_CLX_M32: #define __EVEX512__ 1
 // CHECK_CLX_M32: #define __F16C__ 1
 // CHECK_CLX_M32: #define __FMA__ 1
@@ -1099,6 +1106,7 @@
 // CHECK_CLX_M64: #define __BMI__ 1
 // CHECK_CLX_M64: #define __CLFLUSHOPT__ 1
 // CHECK_CLX_M64: #define __CLWB__ 1
+// CHECK_CLX_M64: #define __EVEX256__ 1
 // CHECK_CLX_M64: #define __EVEX512__ 1
 // CHECK_CLX_M64: #define __F16C__ 1
 // CHECK_CLX_M64: #define __FMA__ 1
@@ -1150,6 +1158,7 @@
 // CHECK_CPX_M32: #define __BMI__ 1
 // CHECK_CPX_M32: #define __CLFLUSHOPT__ 1
 // CHECK_CPX_M32: #define __CLWB__ 1
+// CHECK_CPX_M32: #define __EVEX256__ 1
 // CHECK_CPX_M32: #define __EVEX512__ 1
 // CHECK_CPX_M32: #define __F16C__ 1
 // CHECK_CPX_M32: #define __FMA__ 1
@@ -1198,6 +1207,7 @@
 // CHECK_CPX_M64: #define __BMI__ 1
 // CHECK_CPX_M64: #define __CLFLUSHOPT__ 1
 // CHECK_CPX_M64: #define __CLWB__ 1
+// CHECK_CPX_M64: #define __EVEX256__ 1
 // CHECK_CPX_M64: #define __EVEX512__ 1
 // CHECK_CPX_M64: #define __F16C__ 1
 // CHECK_CPX_M64: #define __FMA__ 1
@@ -1249,6 +1259,7 @@
 // CHECK_CNL_M32: #define __BMI__ 1
 // CHECK_CNL_M32: #define __CLFLUSHOPT__ 1
 // CHECK_CNL_M32-NOT: #define __CLWB__ 1
+// CHECK_CNL_M32: #define __EVEX256__ 1
 // CHECK_CNL_M32: #define __EVEX512__ 1
 // CHECK_CNL_M32: #define __F16C__ 1
 // CHECK_CNL_M32: #define __FMA__ 1
@@ -1298,6 +1309,7 @@
 // CHECK_CNL_M64: #define __BMI__ 1
 // CHECK_CNL_M64: #define __CLFLUSHOPT__ 1
 // CHECK_CNL_M64-NOT: #define __CLWB__ 1
+// CHECK_CNL_M64: #define __EVEX256__ 1
 // CHECK_CNL_M64: #define __EVEX512__ 1
 // CHECK_CNL_M64: #define __F16C__ 1
 // CHECK_CNL_M64: #define __FMA__ 1
@@ -1355,6 +136

[clang] [X86][AVX10] Permit AVX512 options/features used together with AVX10 (PR #71318)

2023-11-05 Thread Phoebe Wang via cfe-commits

https://github.com/phoebewang created 
https://github.com/llvm/llvm-project/pull/71318

This patch relaxes the driver logic to permit combinations between AVX512 and 
AVX10 options and makes sure we have a unified behavior between options and 
features combination.

Here are rules we are following when handle these combinations:
1. evex512 can only be used for avx512xxx options/features. It will be ignored 
if used without them;
2. avx512xxx and avx10.xxx are options in two worlds. Avoid to use them 
together in any case. It will enable a common super set when they are used 
together. E.g., "-mavx512f -mavx10.1-256" euqals "-mavx10.1-512".

Compiler emits warnings when user using combinations like "-mavx512f 
-mavx10.1-256" in case they won't get unexpected result silently.

>From d9ee6309924e7f248695cbd488afe98273432e84 Mon Sep 17 00:00:00 2001
From: Phoebe Wang 
Date: Sun, 5 Nov 2023 21:15:53 +0800
Subject: [PATCH] [X86][AVX10] Permit AVX512 options/features used together
 with AVX10

This patch relaxes the driver logic to permit combinations between
AVX512 and AVX10 options and makes sure we have a unified behavior
between options and features combination.

Here are rules we are following when handle these combinations:
1. evex512 can only be used for avx512xxx options/features. It will be
   ignored if used without them;
2. avx512xxx and avx10.xxx are options in two worlds. Avoid to use them
   together in any case. It will enable a common super set when they are
   used together. E.g., "-mavx512f -mavx10.1-256" euqals "-mavx10.1-512".

Compiler emits warnings when user using combinations like
"-mavx512f -mavx10.1-256" in case they won't get unexpected result silently.
---
 .../clang/Basic/DiagnosticCommonKinds.td  |  2 +
 clang/lib/Basic/Targets/X86.cpp   | 57 ---
 clang/lib/Driver/ToolChains/Arch/X86.cpp  |  7 ---
 clang/lib/Headers/avx2intrin.h|  4 +-
 clang/lib/Headers/avx512bf16intrin.h  |  3 +-
 clang/lib/Headers/avx512bwintrin.h|  4 +-
 clang/lib/Headers/avx512dqintrin.h|  4 +-
 clang/lib/Headers/avx512fintrin.h |  8 ++-
 clang/lib/Headers/avx512fp16intrin.h  |  6 +-
 clang/lib/Headers/avx512ifmavlintrin.h| 10 +++-
 clang/lib/Headers/avx512pfintrin.h|  5 --
 clang/lib/Headers/avx512vbmivlintrin.h| 11 +++-
 clang/lib/Headers/avx512vlbf16intrin.h| 14 +++--
 clang/lib/Headers/avx512vlbitalgintrin.h  | 10 +++-
 clang/lib/Headers/avx512vlbwintrin.h  | 10 +++-
 clang/lib/Headers/avx512vlcdintrin.h  | 11 +++-
 clang/lib/Headers/avx512vldqintrin.h  | 10 +++-
 clang/lib/Headers/avx512vlfp16intrin.h|  4 +-
 clang/lib/Headers/avx512vlintrin.h| 10 +++-
 clang/lib/Headers/avx512vlvbmi2intrin.h   | 10 +++-
 clang/lib/Headers/avx512vlvnniintrin.h| 10 +++-
 .../lib/Headers/avx512vlvp2intersectintrin.h  | 10 ++--
 clang/lib/Headers/avx512vpopcntdqvlintrin.h   |  8 ++-
 clang/lib/Headers/avxintrin.h |  4 +-
 clang/lib/Headers/emmintrin.h |  4 +-
 clang/lib/Headers/gfniintrin.h| 14 +++--
 clang/lib/Headers/pmmintrin.h |  2 +-
 clang/lib/Headers/smmintrin.h |  2 +-
 clang/lib/Headers/tmmintrin.h |  4 +-
 clang/lib/Headers/xmmintrin.h |  4 +-
 clang/test/CodeGen/X86/avx512-error.c | 13 +
 clang/test/CodeGen/target-avx-abi-diag.c  | 28 -
 clang/test/Driver/x86-target-features.c   |  6 +-
 33 files changed, 214 insertions(+), 95 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index 9f0ccd255a32148..8084a4ce0d1751b 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -346,6 +346,8 @@ def err_opt_not_valid_on_target : Error<
   "option '%0' cannot be specified on this target">;
 def err_invalid_feature_combination : Error<
   "invalid feature combination: %0">;
+def warn_invalid_feature_combination : Warning<
+  "invalid feature combination: %0">, 
InGroup>;
 def warn_target_unrecognized_env : Warning<
   "mismatch between architecture and environment in target triple '%0'; did 
you mean '%1'?">,
   InGroup;
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index eec3cd558435e2a..9cfda95f385d627 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -119,9 +119,13 @@ bool X86TargetInfo::initFeatureMap(
 setFeatureEnabled(Features, F, true);
 
   std::vector UpdatedFeaturesVec;
-  bool HasEVEX512 = true;
+  std::vector UpdatedAVX10FeaturesVec;
+  int HasEVEX512 = -1;
   bool HasAVX512F = false;
   bool HasAVX10 = false;
+  bool HasAVX10_512 = false;
+  std::string LastAVX10;
+  std::string LastAVX512;
   for (const auto &Feature : FeaturesVec) {
 // Expand general-reg

[clang] [X86][AVX10] Permit AVX512 options/features used together with AVX10 (PR #71318)

2023-11-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-x86

Author: Phoebe Wang (phoebewang)


Changes

This patch relaxes the driver logic to permit combinations between AVX512 and 
AVX10 options and makes sure we have a unified behavior between options and 
features combination.

Here are rules we are following when handle these combinations:
1. evex512 can only be used for avx512xxx options/features. It will be ignored 
if used without them;
2. avx512xxx and avx10.xxx are options in two worlds. Avoid to use them 
together in any case. It will enable a common super set when they are used 
together. E.g., "-mavx512f -mavx10.1-256" euqals "-mavx10.1-512".

Compiler emits warnings when user using combinations like "-mavx512f 
-mavx10.1-256" in case they won't get unexpected result silently.

---

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


33 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticCommonKinds.td (+2) 
- (modified) clang/lib/Basic/Targets/X86.cpp (+38-19) 
- (modified) clang/lib/Driver/ToolChains/Arch/X86.cpp (-7) 
- (modified) clang/lib/Headers/avx2intrin.h (+2-2) 
- (modified) clang/lib/Headers/avx512bf16intrin.h (+2-1) 
- (modified) clang/lib/Headers/avx512bwintrin.h (+3-1) 
- (modified) clang/lib/Headers/avx512dqintrin.h (+3-1) 
- (modified) clang/lib/Headers/avx512fintrin.h (+6-2) 
- (modified) clang/lib/Headers/avx512fp16intrin.h (+4-2) 
- (modified) clang/lib/Headers/avx512ifmavlintrin.h (+8-2) 
- (modified) clang/lib/Headers/avx512pfintrin.h (-5) 
- (modified) clang/lib/Headers/avx512vbmivlintrin.h (+8-3) 
- (modified) clang/lib/Headers/avx512vlbf16intrin.h (+8-6) 
- (modified) clang/lib/Headers/avx512vlbitalgintrin.h (+8-2) 
- (modified) clang/lib/Headers/avx512vlbwintrin.h (+8-2) 
- (modified) clang/lib/Headers/avx512vlcdintrin.h (+8-3) 
- (modified) clang/lib/Headers/avx512vldqintrin.h (+8-2) 
- (modified) clang/lib/Headers/avx512vlfp16intrin.h (+2-2) 
- (modified) clang/lib/Headers/avx512vlintrin.h (+8-2) 
- (modified) clang/lib/Headers/avx512vlvbmi2intrin.h (+8-2) 
- (modified) clang/lib/Headers/avx512vlvnniintrin.h (+8-2) 
- (modified) clang/lib/Headers/avx512vlvp2intersectintrin.h (+6-4) 
- (modified) clang/lib/Headers/avx512vpopcntdqvlintrin.h (+6-2) 
- (modified) clang/lib/Headers/avxintrin.h (+2-2) 
- (modified) clang/lib/Headers/emmintrin.h (+2-2) 
- (modified) clang/lib/Headers/gfniintrin.h (+10-4) 
- (modified) clang/lib/Headers/pmmintrin.h (+1-1) 
- (modified) clang/lib/Headers/smmintrin.h (+1-1) 
- (modified) clang/lib/Headers/tmmintrin.h (+2-2) 
- (modified) clang/lib/Headers/xmmintrin.h (+2-2) 
- (modified) clang/test/CodeGen/X86/avx512-error.c (+13) 
- (modified) clang/test/CodeGen/target-avx-abi-diag.c (+25-3) 
- (modified) clang/test/Driver/x86-target-features.c (+2-4) 


``diff
diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index 9f0ccd255a32148..8084a4ce0d1751b 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -346,6 +346,8 @@ def err_opt_not_valid_on_target : Error<
   "option '%0' cannot be specified on this target">;
 def err_invalid_feature_combination : Error<
   "invalid feature combination: %0">;
+def warn_invalid_feature_combination : Warning<
+  "invalid feature combination: %0">, 
InGroup>;
 def warn_target_unrecognized_env : Warning<
   "mismatch between architecture and environment in target triple '%0'; did 
you mean '%1'?">,
   InGroup;
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index eec3cd558435e2a..9cfda95f385d627 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -119,9 +119,13 @@ bool X86TargetInfo::initFeatureMap(
 setFeatureEnabled(Features, F, true);
 
   std::vector UpdatedFeaturesVec;
-  bool HasEVEX512 = true;
+  std::vector UpdatedAVX10FeaturesVec;
+  int HasEVEX512 = -1;
   bool HasAVX512F = false;
   bool HasAVX10 = false;
+  bool HasAVX10_512 = false;
+  std::string LastAVX10;
+  std::string LastAVX512;
   for (const auto &Feature : FeaturesVec) {
 // Expand general-regs-only to -x86, -mmx and -sse
 if (Feature == "+general-regs-only") {
@@ -131,35 +135,50 @@ bool X86TargetInfo::initFeatureMap(
   continue;
 }
 
-if (Feature.substr(0, 7) == "+avx10.") {
-  HasAVX10 = true;
-  HasAVX512F = true;
-  if (Feature.substr(Feature.size() - 3, 3) == "512") {
-HasEVEX512 = true;
-  } else if (Feature.substr(7, 2) == "1-") {
-HasEVEX512 = false;
+if (Feature.substr(1, 6) == "avx10.") {
+  if (Feature[0] == '+') {
+HasAVX10 = true;
+if (Feature.substr(Feature.size() - 3, 3) == "512")
+  HasAVX10_512 = true;
+LastAVX10 = Feature;
+  } else if (HasAVX10 && Feature == "-avx10.1-256") {
+HasAVX10 = false;
+HasAVX10_512 = false;
+  }

[clang] [X86][AVX10] Permit AVX512 options/features used together with AVX10 (PR #71318)

2023-11-05 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 8a7846fe86f95e82c6bd5f4f45b8dd311320e903 
d9ee6309924e7f248695cbd488afe98273432e84 -- clang/lib/Basic/Targets/X86.cpp 
clang/lib/Driver/ToolChains/Arch/X86.cpp clang/lib/Headers/avx2intrin.h 
clang/lib/Headers/avx512bf16intrin.h clang/lib/Headers/avx512bwintrin.h 
clang/lib/Headers/avx512dqintrin.h clang/lib/Headers/avx512fintrin.h 
clang/lib/Headers/avx512fp16intrin.h clang/lib/Headers/avx512ifmavlintrin.h 
clang/lib/Headers/avx512pfintrin.h clang/lib/Headers/avx512vbmivlintrin.h 
clang/lib/Headers/avx512vlbf16intrin.h clang/lib/Headers/avx512vlbitalgintrin.h 
clang/lib/Headers/avx512vlbwintrin.h clang/lib/Headers/avx512vlcdintrin.h 
clang/lib/Headers/avx512vldqintrin.h clang/lib/Headers/avx512vlfp16intrin.h 
clang/lib/Headers/avx512vlintrin.h clang/lib/Headers/avx512vlvbmi2intrin.h 
clang/lib/Headers/avx512vlvnniintrin.h 
clang/lib/Headers/avx512vlvp2intersectintrin.h 
clang/lib/Headers/avx512vpopcntdqvlintrin.h clang/lib/Headers/avxintrin.h 
clang/lib/Headers/emmintrin.h clang/lib/Headers/gfniintrin.h 
clang/lib/Headers/pmmintrin.h clang/lib/Headers/smmintrin.h 
clang/lib/Headers/tmmintrin.h clang/lib/Headers/xmmintrin.h 
clang/test/CodeGen/X86/avx512-error.c clang/test/CodeGen/target-avx-abi-diag.c 
clang/test/Driver/x86-target-features.c
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Headers/avx2intrin.h b/clang/lib/Headers/avx2intrin.h
index 2bb0fa39c..096cae01b 100644
--- a/clang/lib/Headers/avx2intrin.h
+++ b/clang/lib/Headers/avx2intrin.h
@@ -15,8 +15,12 @@
 #define __AVX2INTRIN_H
 
 /* Define the default attributes for the functions in this file. */
-#define __DEFAULT_FN_ATTRS256 __attribute__((__always_inline__, __nodebug__, 
__target__("avx2,no-evex512"), __min_vector_width__(256)))
-#define __DEFAULT_FN_ATTRS128 __attribute__((__always_inline__, __nodebug__, 
__target__("avx2,no-evex512"), __min_vector_width__(128)))
+#define __DEFAULT_FN_ATTRS256  
\
+  __attribute__((__always_inline__, __nodebug__,   
\
+ __target__("avx2,no-evex512"), __min_vector_width__(256)))
+#define __DEFAULT_FN_ATTRS128  
\
+  __attribute__((__always_inline__, __nodebug__,   
\
+ __target__("avx2,no-evex512"), __min_vector_width__(128)))
 
 /* SSE4 Multiple Packed Sums of Absolute Difference.  */
 /// Computes sixteen sum of absolute difference (SAD) operations on sets of
diff --git a/clang/lib/Headers/avxintrin.h b/clang/lib/Headers/avxintrin.h
index b74701a8c..f116d8bc3 100644
--- a/clang/lib/Headers/avxintrin.h
+++ b/clang/lib/Headers/avxintrin.h
@@ -50,8 +50,12 @@ typedef __bf16 __m256bh __attribute__((__vector_size__(32), 
__aligned__(32)));
 #endif
 
 /* Define the default attributes for the functions in this file. */
-#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, 
__target__("avx,no-evex512"), __min_vector_width__(256)))
-#define __DEFAULT_FN_ATTRS128 __attribute__((__always_inline__, __nodebug__, 
__target__("avx,no-evex512"), __min_vector_width__(128)))
+#define __DEFAULT_FN_ATTRS 
\
+  __attribute__((__always_inline__, __nodebug__, __target__("avx,no-evex512"), 
\
+ __min_vector_width__(256)))
+#define __DEFAULT_FN_ATTRS128  
\
+  __attribute__((__always_inline__, __nodebug__, __target__("avx,no-evex512"), 
\
+ __min_vector_width__(128)))
 
 /* Arithmetic */
 /// Adds two 256-bit vectors of [4 x double].
diff --git a/clang/lib/Headers/emmintrin.h b/clang/lib/Headers/emmintrin.h
index 3ff13e6b0..96e3ebdec 100644
--- a/clang/lib/Headers/emmintrin.h
+++ b/clang/lib/Headers/emmintrin.h
@@ -50,11 +50,11 @@ typedef __bf16 __m128bh __attribute__((__vector_size__(16), 
__aligned__(16)));
 
 /* Define the default attributes for the functions in this file. */
 #define __DEFAULT_FN_ATTRS 
\
-  __attribute__((__always_inline__, __nodebug__, 
__target__("sse2,no-evex512"),   \
- __min_vector_width__(128)))
+  __attribute__((__always_inline__, __nodebug__,   
\
+ __target__("sse2,no-evex512"), __min_vector_width__(128)))
 #define __DEFAULT_FN_ATTRS_MMX 
\
-  __attribute__((__always_inline__, __nodebug__, 
__target__("mmx,sse2,no-evex512"),   \
- __min_vector_width__(64)))
+  __attribute__((__always_inline__, __nodebug__,   
\
+ __target__("mmx,sse2,no-evex512"), __min_vector_width__(64)))
 
 /// Adds l

[clang] [llvm] [compiler-rt] [AArch64][SME] Add support for sme-fa64 (PR #70809)

2023-11-05 Thread Sander de Smalen via cfe-commits


@@ -0,0 +1,33 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mattr=+sve -mattr=+sme-fa64 -force-streaming-compatible-sve < %s | 
FileCheck %s -check-prefix=FA64
+; RUN: llc -mattr=+sve -force-streaming-compatible-sve < %s | FileCheck %s 
-check-prefix=NO-FA64
+
+
+target triple = "aarch64-unknown-linux-gnu"
+
+define half @fadda_v4f16(half %start, <4 x half> %a) {

sdesmalen-arm wrote:

Could you add a similar test where a Neon instruction would be used when 
`sme-fa64` is set? (and where it would be scalarised otherwise)

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


[clang] [llvm] [compiler-rt] [AArch64][SME] Add support for sme-fa64 (PR #70809)

2023-11-05 Thread Sander de Smalen via cfe-commits


@@ -162,6 +163,7 @@ enum ArchExtKind : unsigned {
   AEK_FPMR =  58, // FEAT_FPMR
   AEK_FP8 =   59, // FEAT_FP8
   AEK_FAMINMAX =  60, // FEAT_FAMINMAX
+  AEK_SMEFA64 =   61, // FEAT_SMEFA64

sdesmalen-arm wrote:

nit: can you define this after `AEK_SME`? The feature is part of SME(1), so at 
least that way we keep the definitions together in this enum.

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


[compiler-rt] [clang] [llvm] [AArch64][SME] Add support for sme-fa64 (PR #70809)

2023-11-05 Thread Sander de Smalen via cfe-commits


@@ -508,6 +508,9 @@ def FeatureSMEI16I64 : SubtargetFeature<"sme-i16i64", 
"HasSMEI16I64", "true",
 def FeatureSMEF16F16 : SubtargetFeature<"sme-f16f16", "HasSMEF16F16", "true",
   "Enable SME2.1 non-widening Float16 instructions (FEAT_SME_F16F16)", []>;
 
+def FeatureSMEFA64 : SubtargetFeature<"sme-fa64", "HasSMEFA64", "true",
+  "Enable the full A64 instruction set in SVE streaming mode (FEAT_SME_FA64)", 
[]>;

sdesmalen-arm wrote:

```suggestion
  "Enable the full A64 instruction set in streaming SVE mode (FEAT_SME_FA64)", 
[]>;
```

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


[compiler-rt] [clang] [llvm] [AArch64][SME] Add support for sme-fa64 (PR #70809)

2023-11-05 Thread Sander de Smalen via cfe-commits


@@ -248,8 +250,9 @@ inline constexpr ExtensionInfo Extensions[] = {
 {"simd", AArch64::AEK_SIMD, "+neon", "-neon", FEAT_SIMD, 
"+fp-armv8,+neon", 100},
 {"sm4", AArch64::AEK_SM4, "+sm4", "-sm4", FEAT_SM4, 
"+sm4,+fp-armv8,+neon", 60},
 {"sme-f16f16", AArch64::AEK_SMEF16F16, "+sme-f16f16", "-sme-f16f16", 
FEAT_INIT, "", 0},
-{"sme-f64f64", AArch64::AEK_SMEF64F64, "+sme-f64f64", "-sme-f64f64", 
FEAT_SME_F64, "+sme,+sme-f64f64,+bf16", 560},
-{"sme-i16i64", AArch64::AEK_SMEI16I64, "+sme-i16i64", "-sme-i16i64", 
FEAT_SME_I64, "+sme,+sme-i16i64,+bf16", 570},
+{"sme-f64f64", AArch64::AEK_SMEF64F64, "+sme-f64f64", "-sme-f64f64", 
FEAT_SME_F64,  "+sme,+sme-f64f64,+bf16", 560},
+{"sme-i16i64", AArch64::AEK_SMEI16I64, "+sme-i16i64", "-sme-i16i64", 
FEAT_SME_I64,  "+sme,+sme-i16i64,+bf16", 570},
+{"sme-fa64",   AArch64::AEK_SMEFA64,   "+sme-fa64",   "-sme-fa64",   
FEAT_SME_FA64, "+sve2",  580},

sdesmalen-arm wrote:

I wonder if this has something to do with the order in which it emits the 
runtime checks for these target features in the resolver function. I can't 
really gauge whether this priority is better or worse than  any other though. 
Perhaps @ilinpv can give some guidance here?

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


[clang] [X86][AVX10] Permit AVX512 options/features used together with AVX10 (PR #71318)

2023-11-05 Thread Phoebe Wang via cfe-commits

https://github.com/phoebewang updated 
https://github.com/llvm/llvm-project/pull/71318

>From d9ee6309924e7f248695cbd488afe98273432e84 Mon Sep 17 00:00:00 2001
From: Phoebe Wang 
Date: Sun, 5 Nov 2023 21:15:53 +0800
Subject: [PATCH 1/2] [X86][AVX10] Permit AVX512 options/features used together
 with AVX10

This patch relaxes the driver logic to permit combinations between
AVX512 and AVX10 options and makes sure we have a unified behavior
between options and features combination.

Here are rules we are following when handle these combinations:
1. evex512 can only be used for avx512xxx options/features. It will be
   ignored if used without them;
2. avx512xxx and avx10.xxx are options in two worlds. Avoid to use them
   together in any case. It will enable a common super set when they are
   used together. E.g., "-mavx512f -mavx10.1-256" euqals "-mavx10.1-512".

Compiler emits warnings when user using combinations like
"-mavx512f -mavx10.1-256" in case they won't get unexpected result silently.
---
 .../clang/Basic/DiagnosticCommonKinds.td  |  2 +
 clang/lib/Basic/Targets/X86.cpp   | 57 ---
 clang/lib/Driver/ToolChains/Arch/X86.cpp  |  7 ---
 clang/lib/Headers/avx2intrin.h|  4 +-
 clang/lib/Headers/avx512bf16intrin.h  |  3 +-
 clang/lib/Headers/avx512bwintrin.h|  4 +-
 clang/lib/Headers/avx512dqintrin.h|  4 +-
 clang/lib/Headers/avx512fintrin.h |  8 ++-
 clang/lib/Headers/avx512fp16intrin.h  |  6 +-
 clang/lib/Headers/avx512ifmavlintrin.h| 10 +++-
 clang/lib/Headers/avx512pfintrin.h|  5 --
 clang/lib/Headers/avx512vbmivlintrin.h| 11 +++-
 clang/lib/Headers/avx512vlbf16intrin.h| 14 +++--
 clang/lib/Headers/avx512vlbitalgintrin.h  | 10 +++-
 clang/lib/Headers/avx512vlbwintrin.h  | 10 +++-
 clang/lib/Headers/avx512vlcdintrin.h  | 11 +++-
 clang/lib/Headers/avx512vldqintrin.h  | 10 +++-
 clang/lib/Headers/avx512vlfp16intrin.h|  4 +-
 clang/lib/Headers/avx512vlintrin.h| 10 +++-
 clang/lib/Headers/avx512vlvbmi2intrin.h   | 10 +++-
 clang/lib/Headers/avx512vlvnniintrin.h| 10 +++-
 .../lib/Headers/avx512vlvp2intersectintrin.h  | 10 ++--
 clang/lib/Headers/avx512vpopcntdqvlintrin.h   |  8 ++-
 clang/lib/Headers/avxintrin.h |  4 +-
 clang/lib/Headers/emmintrin.h |  4 +-
 clang/lib/Headers/gfniintrin.h| 14 +++--
 clang/lib/Headers/pmmintrin.h |  2 +-
 clang/lib/Headers/smmintrin.h |  2 +-
 clang/lib/Headers/tmmintrin.h |  4 +-
 clang/lib/Headers/xmmintrin.h |  4 +-
 clang/test/CodeGen/X86/avx512-error.c | 13 +
 clang/test/CodeGen/target-avx-abi-diag.c  | 28 -
 clang/test/Driver/x86-target-features.c   |  6 +-
 33 files changed, 214 insertions(+), 95 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index 9f0ccd255a32148..8084a4ce0d1751b 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -346,6 +346,8 @@ def err_opt_not_valid_on_target : Error<
   "option '%0' cannot be specified on this target">;
 def err_invalid_feature_combination : Error<
   "invalid feature combination: %0">;
+def warn_invalid_feature_combination : Warning<
+  "invalid feature combination: %0">, 
InGroup>;
 def warn_target_unrecognized_env : Warning<
   "mismatch between architecture and environment in target triple '%0'; did 
you mean '%1'?">,
   InGroup;
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index eec3cd558435e2a..9cfda95f385d627 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -119,9 +119,13 @@ bool X86TargetInfo::initFeatureMap(
 setFeatureEnabled(Features, F, true);
 
   std::vector UpdatedFeaturesVec;
-  bool HasEVEX512 = true;
+  std::vector UpdatedAVX10FeaturesVec;
+  int HasEVEX512 = -1;
   bool HasAVX512F = false;
   bool HasAVX10 = false;
+  bool HasAVX10_512 = false;
+  std::string LastAVX10;
+  std::string LastAVX512;
   for (const auto &Feature : FeaturesVec) {
 // Expand general-regs-only to -x86, -mmx and -sse
 if (Feature == "+general-regs-only") {
@@ -131,35 +135,50 @@ bool X86TargetInfo::initFeatureMap(
   continue;
 }
 
-if (Feature.substr(0, 7) == "+avx10.") {
-  HasAVX10 = true;
-  HasAVX512F = true;
-  if (Feature.substr(Feature.size() - 3, 3) == "512") {
-HasEVEX512 = true;
-  } else if (Feature.substr(7, 2) == "1-") {
-HasEVEX512 = false;
+if (Feature.substr(1, 6) == "avx10.") {
+  if (Feature[0] == '+') {
+HasAVX10 = true;
+if (Feature.substr(Feature.size() - 3, 3) == "512")
+  HasAVX10_512 = true;
+LastAVX10 = Feature;
+  } else if (HasAVX10 && Feature == "-avx

[clang-tools-extra] [clang-tidy] Improve `container-data-pointer` check to use `c_str()` (PR #71304)

2023-11-05 Thread via cfe-commits


@@ -111,16 +115,18 @@ void ContainerDataPointerCheck::check(const 
MatchFinder::MatchResult &Result) {
MemberExpr>(CE))
 ReplacementText = "(" + ReplacementText + ")";
 
-  if (CE->getType()->isPointerType())
-ReplacementText += "->data()";
-  else
-ReplacementText += ".data()";
+  ReplacementText += CE->getType()->isPointerType() ? "->" : ".";
+  ReplacementText += CStrMethod != NULL ? "c_str()" : "data()";

EugeneZelenko wrote:

`nullptr` or use only pointer (with implicit Boolean conversion).

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


[clang] [ObjC] Fix offsets following `[[no_unique_address]]` for `@encode()` (PR #71321)

2023-11-05 Thread Daniel Bertalan via cfe-commits

https://github.com/BertalanD created 
https://github.com/llvm/llvm-project/pull/71321

Commit 46ca880fca made `@encode` skip fields that are made zero-sized by 
`[[no_unique_address]]`. When iterating the fields, the index which is passed 
to `getFieldOffset` failed to be incremented for those due to the use of an 
early `continue`, so subsequent fields reported an incorrect offset. This 
caused an assertion to be triggered in `getObjCEncodingForStructureImpl`.

Fixes #71250

>From 2ad862a174685a679d398b628769e88c5eebbee6 Mon Sep 17 00:00:00 2001
From: Daniel Bertalan 
Date: Sun, 5 Nov 2023 16:19:50 +0100
Subject: [PATCH] [ObjC] Fix offsets following `[[no_unique_address]]` for
 `@encode()`

Commit 46ca880fca made `@encode` skip fields that are made zero-sized by
`[[no_unique_address]]`. When iterating the fields, the index which is
passed to `getFieldOffset` failed to be incremented for those due to the
use of an early `continue`, so subsequent fields reported an incorrect
offset. This caused an assertion to be triggered in
`getObjCEncodingForStructureImpl`.

Fixes #71250
---
 clang/lib/AST/ASTContext.cpp   |  4 +---
 clang/test/CodeGenObjCXX/encode.mm | 14 ++
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index da90136752210b6..60146e9901bc44d 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -8535,14 +8535,12 @@ void 
ASTContext::getObjCEncodingForStructureImpl(RecordDecl *RDecl,
 }
   }
 
-  unsigned i = 0;
   for (FieldDecl *Field : RDecl->fields()) {
 if (!Field->isZeroLengthBitField(*this) && Field->isZeroSize(*this))
   continue;
-uint64_t offs = layout.getFieldOffset(i);
+uint64_t offs = layout.getFieldOffset(Field->getFieldIndex());
 FieldOrBaseOffsets.insert(FieldOrBaseOffsets.upper_bound(offs),
   std::make_pair(offs, Field));
-++i;
   }
 
   if (CXXRec && includeVBases) {
diff --git a/clang/test/CodeGenObjCXX/encode.mm 
b/clang/test/CodeGenObjCXX/encode.mm
index f382e7f23d77335..cad70e379c386bf 100644
--- a/clang/test/CodeGenObjCXX/encode.mm
+++ b/clang/test/CodeGenObjCXX/encode.mm
@@ -339,3 +339,17 @@ @implementation N
 const char *inner0 = @encode(Outer0::Inner0 *);
 const char *inner1 = @encode(Outer0::Inner1 *);
 }
+
+#if __cplusplus >= 202002L
+namespace GH71250 {
+  struct Empty {};
+  struct S {
+[[no_unique_address]] Empty a;
+long b;
+long c;
+  };
+
+  // CHECKCXX20: @_ZN7GH712501sE =  constant [7 x i8] c"{S=qq}\00", align 1
+  extern const char s[] = @encode(S);
+}
+#endif

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


[clang] [ObjC] Fix offsets following `[[no_unique_address]]` for `@encode()` (PR #71321)

2023-11-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Daniel Bertalan (BertalanD)


Changes

Commit 46ca880fca made `@encode` skip fields that are made zero-sized 
by `[[no_unique_address]]`. When iterating the fields, the index which is 
passed to `getFieldOffset` failed to be incremented for those due to the use of 
an early `continue`, so subsequent fields reported an incorrect offset. This 
caused an assertion to be triggered in `getObjCEncodingForStructureImpl`.

Fixes #71250

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


2 Files Affected:

- (modified) clang/lib/AST/ASTContext.cpp (+1-3) 
- (modified) clang/test/CodeGenObjCXX/encode.mm (+14) 


``diff
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index da90136752210b6..60146e9901bc44d 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -8535,14 +8535,12 @@ void 
ASTContext::getObjCEncodingForStructureImpl(RecordDecl *RDecl,
 }
   }
 
-  unsigned i = 0;
   for (FieldDecl *Field : RDecl->fields()) {
 if (!Field->isZeroLengthBitField(*this) && Field->isZeroSize(*this))
   continue;
-uint64_t offs = layout.getFieldOffset(i);
+uint64_t offs = layout.getFieldOffset(Field->getFieldIndex());
 FieldOrBaseOffsets.insert(FieldOrBaseOffsets.upper_bound(offs),
   std::make_pair(offs, Field));
-++i;
   }
 
   if (CXXRec && includeVBases) {
diff --git a/clang/test/CodeGenObjCXX/encode.mm 
b/clang/test/CodeGenObjCXX/encode.mm
index f382e7f23d77335..cad70e379c386bf 100644
--- a/clang/test/CodeGenObjCXX/encode.mm
+++ b/clang/test/CodeGenObjCXX/encode.mm
@@ -339,3 +339,17 @@ @implementation N
 const char *inner0 = @encode(Outer0::Inner0 *);
 const char *inner1 = @encode(Outer0::Inner1 *);
 }
+
+#if __cplusplus >= 202002L
+namespace GH71250 {
+  struct Empty {};
+  struct S {
+[[no_unique_address]] Empty a;
+long b;
+long c;
+  };
+
+  // CHECKCXX20: @_ZN7GH712501sE =  constant [7 x i8] c"{S=qq}\00", align 1
+  extern const char s[] = @encode(S);
+}
+#endif

``




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


[clang] [ObjC] Fix offsets following `[[no_unique_address]]` for `@encode()` (PR #71321)

2023-11-05 Thread Daniel Bertalan via cfe-commits

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


[clang] [ObjC] Fix offsets following `[[no_unique_address]]` for `@encode()` (PR #71321)

2023-11-05 Thread Daniel Bertalan via cfe-commits

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


[clang] [clang-tools-extra] [clang][NFC] Refacator `CXXNewExpr::InitializationStyle` (PR #71322)

2023-11-05 Thread Vlad Serebrennikov via cfe-commits

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

This patch converts `CXXNewExpr::InitializationStyle` into a scoped enum at 
namespace scope. It also affirms the status quo by adding a new enumerator to 
represent implicit initializer.

>From 40d25b8009f1c8734a99fd1350adaced6884cc7f Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Sun, 5 Nov 2023 18:53:48 +0300
Subject: [PATCH 1/2] [clang][NFC] Refacator `CXXNewExpr::InitializationStyle`

This patch converts `CXXNewExpr::InitializationStyle` into a scoped enum at 
namespace scope. It also affirms the status quo by adding a new enumerator to 
represent implicit initializer.
---
 .../modernize/MakeSmartPtrCheck.cpp   |  7 +--
 clang/include/clang/AST/ExprCXX.h | 48 +++
 clang/lib/AST/ExprCXX.cpp | 12 ++---
 clang/lib/AST/ItaniumMangle.cpp   |  4 +-
 clang/lib/AST/JSONNodeDumper.cpp  |  7 +--
 clang/lib/AST/StmtPrinter.cpp |  6 +--
 clang/lib/AST/StmtProfile.cpp |  2 +-
 clang/lib/Sema/SemaExprCXX.cpp| 22 -
 8 files changed, 58 insertions(+), 50 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
index 71fd8eca300c1b2..616e57efa76ded5 100644
--- a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -323,7 +323,8 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
 return false;
   };
   switch (New->getInitializationStyle()) {
-  case CXXNewExpr::NoInit: {
+  case CXXNewInitializationStyle::None:
+  case CXXNewInitializationStyle::Implicit: {
 if (ArraySizeExpr.empty()) {
   Diag << FixItHint::CreateRemoval(SourceRange(NewStart, NewEnd));
 } else {
@@ -334,7 +335,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
 }
 break;
   }
-  case CXXNewExpr::CallInit: {
+  case CXXNewInitializationStyle::Call: {
 // FIXME: Add fixes for constructors with parameters that can be created
 // with a C++11 braced-init-list (e.g. std::vector, std::map).
 // Unlike ordinal cases, braced list can not be deduced in
@@ -371,7 +372,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
 }
 break;
   }
-  case CXXNewExpr::ListInit: {
+  case CXXNewInitializationStyle::List: {
 // Range of the substring that we do not want to remove.
 SourceRange InitRange;
 if (const auto *NewConstruct = New->getConstructExpr()) {
diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index a106bafcfa3e021..d713bcf8eb70258 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -2206,6 +2206,20 @@ class CXXScalarValueInitExpr : public Expr {
   }
 };
 
+enum class CXXNewInitializationStyle {
+  /// New-expression has no initializer as written.
+  None,
+
+  /// New-expression has no written initializer, but has an implicit one.
+  Implicit,
+
+  /// New-expression has a C++98 paren-delimited initializer.
+  Call,
+
+  /// New-expression has a C++11 list-initializer.
+  List
+};
+
 /// Represents a new-expression for memory allocation and constructor
 /// calls, e.g: "new CXXNewExpr(foo)".
 class CXXNewExpr final
@@ -2259,25 +2273,12 @@ class CXXNewExpr final
 return isParenTypeId();
   }
 
-public:
-  enum InitializationStyle {
-/// New-expression has no initializer as written.
-NoInit,
-
-/// New-expression has a C++98 paren-delimited initializer.
-CallInit,
-
-/// New-expression has a C++11 list-initializer.
-ListInit
-  };
-
-private:
   /// Build a c++ new expression.
   CXXNewExpr(bool IsGlobalNew, FunctionDecl *OperatorNew,
  FunctionDecl *OperatorDelete, bool ShouldPassAlignment,
  bool UsualArrayDeleteWantsSize, ArrayRef PlacementArgs,
  SourceRange TypeIdParens, std::optional ArraySize,
- InitializationStyle InitializationStyle, Expr *Initializer,
+ CXXNewInitializationStyle InitializationStyle, Expr *Initializer,
  QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
  SourceRange DirectInitRange);
 
@@ -2292,7 +2293,7 @@ class CXXNewExpr final
  FunctionDecl *OperatorDelete, bool ShouldPassAlignment,
  bool UsualArrayDeleteWantsSize, ArrayRef PlacementArgs,
  SourceRange TypeIdParens, std::optional ArraySize,
- InitializationStyle InitializationStyle, Expr *Initializer,
+ CXXNewInitializationStyle InitializationStyle, Expr *Initializer,
  QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
  SourceRange DirectInitRange);
 
@@ -2388,15 +2389,20 @@ class CXXNewExpr final
 
   /// Whether this new-expression has any initializer at all.
   bool hasInitializer() const {
-return CXXNewExprB

[clang-tools-extra] [clang-tidy] Improve `container-data-pointer` check to use `c_str()` (PR #71304)

2023-11-05 Thread Eli Black via cfe-commits


@@ -111,16 +115,18 @@ void ContainerDataPointerCheck::check(const 
MatchFinder::MatchResult &Result) {
MemberExpr>(CE))
 ReplacementText = "(" + ReplacementText + ")";
 
-  if (CE->getType()->isPointerType())
-ReplacementText += "->data()";
-  else
-ReplacementText += ".data()";
+  ReplacementText += CE->getType()->isPointerType() ? "->" : ".";
+  ReplacementText += CStrMethod != NULL ? "c_str()" : "data()";

neoncube2 wrote:

Fixed :)

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


[clang-tools-extra] [clang-tidy] Improve `container-data-pointer` check to use `c_str()` (PR #71304)

2023-11-05 Thread Eli Black via cfe-commits

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


[clang] [clang-tools-extra] [libcxx] [libc] [llvm] [mlir] [compiler-rt] [flang] [MLIR] SPIRV Target Attribute (PR #69949)

2023-11-05 Thread Lei Zhang via cfe-commits

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

LGTM. Thanks for addressing the comments!

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


[clang] [clang-tools-extra] [libcxx] [libc] [llvm] [mlir] [compiler-rt] [flang] [mlir][spirv] Implement gpu::TargetAttrInterface (PR #69949)

2023-11-05 Thread Lei Zhang via cfe-commits

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


[clang-tools-extra] [clang-tidy] Improve `container-data-pointer` check to use `c_str()` (PR #71304)

2023-11-05 Thread Eli Black via cfe-commits

https://github.com/neoncube2 updated 
https://github.com/llvm/llvm-project/pull/71304

>From ab1e2e7487fdc7b1e16e563c63e225a3dd39da05 Mon Sep 17 00:00:00 2001
From: Eli Black 
Date: Sun, 5 Nov 2023 13:43:20 +0800
Subject: [PATCH] [clang-tidy] Improve `container-data-pointer` check to use
 `c_str()` instead of `data()` when it's available.

Fixes #55026
---
 .../readability/ContainerDataPointerCheck.cpp | 26 ---
 .../readability/ContainerDataPointerCheck.h   |  4 +--
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 +++
 .../readability/container-data-pointer.rst|  8 ++
 .../readability/container-data-pointer.cpp| 12 -
 5 files changed, 30 insertions(+), 24 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.cpp
index a05e228520c9ef1..eb76d05667d300a 100644
--- a/clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.cpp
@@ -40,8 +40,10 @@ void ContainerDataPointerCheck::registerMatchers(MatchFinder 
*Finder) {
   cxxRecordDecl(
   unless(matchers::matchesAnyListedName(IgnoredContainers)),
   isSameOrDerivedFrom(
-  namedDecl(
-  has(cxxMethodDecl(isPublic(), hasName("data")).bind("data")))
+  namedDecl(anyOf(has(cxxMethodDecl(isPublic(), hasName("c_str"))
+  .bind("c_str")),
+  has(cxxMethodDecl(isPublic(), hasName("data"))
+  .bind("data"
   .bind("container")))
   .bind("record");
 
@@ -93,6 +95,8 @@ void ContainerDataPointerCheck::check(const 
MatchFinder::MatchResult &Result) {
   const auto *DCE = Result.Nodes.getNodeAs(DerefContainerExprName);
   const auto *ACE = Result.Nodes.getNodeAs(AddrOfContainerExprName);
 
+  const auto *CStrMethod = Result.Nodes.getNodeAs("c_str");
+
   if (!UO || !CE)
 return;
 
@@ -111,16 +115,18 @@ void ContainerDataPointerCheck::check(const 
MatchFinder::MatchResult &Result) {
MemberExpr>(CE))
 ReplacementText = "(" + ReplacementText + ")";
 
-  if (CE->getType()->isPointerType())
-ReplacementText += "->data()";
-  else
-ReplacementText += ".data()";
+  ReplacementText += CE->getType()->isPointerType() ? "->" : ".";
+  ReplacementText += CStrMethod ? "c_str()" : "data()";
+
+  std::string Description =
+  CStrMethod
+  ? "'c_str' should be used instead of taking the address of the 0-th "
+"element"
+  : "'data' should be used for accessing the data pointer instead of "
+"taking the address of the 0-th element";
 
   FixItHint Hint =
   FixItHint::CreateReplacement(UO->getSourceRange(), ReplacementText);
-  diag(UO->getBeginLoc(),
-   "'data' should be used for accessing the data pointer instead of taking 
"
-   "the address of the 0-th element")
-  << Hint;
+  diag(UO->getBeginLoc(), Description) << Hint;
 }
 } // namespace clang::tidy::readability
diff --git 
a/clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.h 
b/clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.h
index 2a15b95095171f1..f5c1a974ff84801 100644
--- a/clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.h
@@ -12,8 +12,8 @@
 #include "../ClangTidyCheck.h"
 
 namespace clang::tidy::readability {
-/// Checks whether a call to `operator[]` and `&` can be replaced with a call 
to
-/// `data()`.
+/// Finds cases where code references the address of the element at index 0 in 
a
+/// container and replaces them with calls to ``data()`` or ``c_str()``.
 ///
 /// This only replaces the case where the offset being accessed through the
 /// subscript operation is a known constant 0.  This avoids a potential invalid
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index ecfb3aa9267f140..6477f2243d31e18 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -238,6 +238,10 @@ Changes in existing checks
   Casting to ``void`` no longer suppresses issues by default, control this
   behavior with the new `AllowCastToVoid` option.
 
+- Improved :doc:`container-data-pointer
+  ` check
+  to use ``c_str()`` when it's present on a container.
+
 - Improved :doc:`cppcoreguidelines-avoid-non-const-global-variables
   ` check
   to ignore ``static`` variables declared within the scope of
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/readability/container-data-pointer.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/readability/container-data-pointer.rst
index 0d10829ed3c2f9b..8a6b48c58005bf2 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/readability/container-data-pointer.rst
+++ 
b/clang-

[clang-tools-extra] [clang-tidy] Improve `container-data-pointer` check to use `c_str()` (PR #71304)

2023-11-05 Thread Eli Black via cfe-commits


@@ -3,13 +3,9 @@
 readability-container-data-pointer
 ==
 
-Finds cases where code could use ``data()`` rather than the address of the
-element at index 0 in a container. This pattern is commonly used to materialize
-a pointer to the backing data of a container. ``std::vector`` and
-``std::string`` provide a ``data()`` accessor to retrieve the data pointer 
which
-should be preferred.
+Finds cases where code references the address of the element at index 0 in a 
container and replaces them with calls to ``data()`` or ``c_str()``.

neoncube2 wrote:

Fixed, thanks :)

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


[clang-tools-extra] [clang-tidy] Improve `container-data-pointer` check to use `c_str()` (PR #71304)

2023-11-05 Thread Eli Black via cfe-commits


@@ -111,16 +115,18 @@ void ContainerDataPointerCheck::check(const 
MatchFinder::MatchResult &Result) {
MemberExpr>(CE))
 ReplacementText = "(" + ReplacementText + ")";
 
-  if (CE->getType()->isPointerType())
-ReplacementText += "->data()";
-  else
-ReplacementText += ".data()";
+  ReplacementText += CE->getType()->isPointerType() ? "->" : ".";
+  ReplacementText += CStrMethod != NULL ? "c_str()" : "data()";

neoncube2 wrote:

Fixed! :)

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


[clang] [clang-tools-extra] [clang][NFC] Refactor `CXXNewExpr::InitializationStyle` (PR #71322)

2023-11-05 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [clang-tools-extra] [libcxx] [libc] [llvm] [mlir] [compiler-rt] [flang] [mlir][spirv] Implement gpu::TargetAttrInterface (PR #69949)

2023-11-05 Thread Lei Zhang via cfe-commits

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


[clang] [clang-tools-extra] [libcxx] [libc] [llvm] [mlir] [compiler-rt] [flang] [mlir][spirv] Implement gpu::TargetAttrInterface (PR #69949)

2023-11-05 Thread Lei Zhang via cfe-commits

antiagainst wrote:

I revised the commit message a bit and landed it. Thanks for the waiting!

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


[clang] b26b1ce - [clang][CodeGenModule] Remove no-op ptr-to-ptr bitcasts (NFC)

2023-11-05 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2023-11-05T10:17:45-06:00
New Revision: b26b1cee2e6b0b730fda87dbd4a236810d424129

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

LOG: [clang][CodeGenModule] Remove no-op ptr-to-ptr bitcasts (NFC)

Opaque ptr cleanup effort (NFC).

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 35f651b39f6748a..f72101799d31e4c 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3201,10 +3201,9 @@ llvm::Constant *CodeGenModule::EmitAnnotationArgs(const 
AnnotateAttr *Attr) {
   ".args");
   GV->setSection(AnnotationSection);
   GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
-  auto *Bitcasted = llvm::ConstantExpr::getBitCast(GV, GlobalsInt8PtrTy);
 
-  Lookup = Bitcasted;
-  return Bitcasted;
+  Lookup = GV;
+  return GV;
 }
 
 llvm::Constant *CodeGenModule::EmitAnnotateAttr(llvm::GlobalValue *GV,
@@ -3227,11 +3226,7 @@ llvm::Constant 
*CodeGenModule::EmitAnnotateAttr(llvm::GlobalValue *GV,
 
   // Create the ConstantStruct for the global annotation.
   llvm::Constant *Fields[] = {
-  llvm::ConstantExpr::getBitCast(GVInGlobalsAS, GlobalsInt8PtrTy),
-  llvm::ConstantExpr::getBitCast(AnnoGV, ConstGlobalsPtrTy),
-  llvm::ConstantExpr::getBitCast(UnitGV, ConstGlobalsPtrTy),
-  LineNoCst,
-  Args,
+  GVInGlobalsAS, AnnoGV, UnitGV, LineNoCst, Args,
   };
   return llvm::ConstantStruct::getAnon(Fields);
 }
@@ -4697,9 +4692,7 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef 
MangledName, llvm::Type *Ty,
 GV->takeName(Entry);
 
 if (!Entry->use_empty()) {
-  llvm::Constant *NewPtrForOldDecl =
-  llvm::ConstantExpr::getBitCast(GV, Entry->getType());
-  Entry->replaceAllUsesWith(NewPtrForOldDecl);
+  Entry->replaceAllUsesWith(GV);
 }
 
 Entry->eraseFromParent();
@@ -4878,9 +4871,7 @@ llvm::GlobalVariable 
*CodeGenModule::CreateOrReplaceCXXRuntimeVariable(
 GV->takeName(OldGV);
 
 if (!OldGV->use_empty()) {
-  llvm::Constant *NewPtrForOldDecl =
-  llvm::ConstantExpr::getBitCast(GV, OldGV->getType());
-  OldGV->replaceAllUsesWith(NewPtrForOldDecl);
+  OldGV->replaceAllUsesWith(GV);
 }
 
 OldGV->eraseFromParent();
@@ -5766,8 +5757,7 @@ void CodeGenModule::EmitAliasDefinition(GlobalDecl GD) {
 // Remove it and replace uses of it with the alias.
 GA->takeName(Entry);
 
-Entry->replaceAllUsesWith(llvm::ConstantExpr::getBitCast(GA,
-  Entry->getType()));
+Entry->replaceAllUsesWith(GA);
 Entry->eraseFromParent();
   } else {
 GA->setName(MangledName);
@@ -5845,8 +5835,7 @@ void CodeGenModule::emitIFuncDefinition(GlobalDecl GD) {
 // Remove it and replace uses of it with the ifunc.
 GIF->takeName(Entry);
 
-Entry->replaceAllUsesWith(llvm::ConstantExpr::getBitCast(GIF,
-  Entry->getType()));
+Entry->replaceAllUsesWith(GIF);
 Entry->eraseFromParent();
   } else
 GIF->setName(MangledName);
@@ -6042,9 +6031,6 @@ CodeGenModule::GetAddrOfConstantCFString(const 
StringLiteral *Literal) {
   llvm::Constant *Str =
   llvm::ConstantExpr::getGetElementPtr(GV->getValueType(), GV, Zeros);
 
-  if (isUTF16)
-// Cast the UTF16 string to the correct type.
-Str = llvm::ConstantExpr::getBitCast(Str, Int8PtrTy);
   Fields.add(Str);
 
   // String length.
@@ -6414,8 +6400,7 @@ ConstantAddress CodeGenModule::GetAddrOfGlobalTemporary(
   // replace it with the new global now.
   llvm::Constant *&Entry = MaterializedGlobalTemporaryMap[E];
   if (Entry) {
-Entry->replaceAllUsesWith(
-llvm::ConstantExpr::getBitCast(CV, Entry->getType()));
+Entry->replaceAllUsesWith(CV);
 llvm::cast(Entry)->eraseFromParent();
   }
   Entry = CV;



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


[clang-tools-extra] [clang-tidy] Improve `container-data-pointer` check to use `c_str()` (PR #71304)

2023-11-05 Thread Eli Black via cfe-commits

neoncube2 wrote:

@PiotrZSL Thanks for the quick review! :)

I think #54076 covers the `const` issue. Since `container-data-pointer` is 
already broken for code such as `char *t = str.data();`, I think merging this 
PR wouldn't cause additional issues, but I could be wrong about that! :)

I'd like to take a look at #54076 next, but I think that'd be a bit more 
complicated to fix, since it involves the left-hand side of the expression 
(Unless there's already a helper method to determine whether the left-hand side 
of the expression is `const`?)

Thanks again for the review! :)

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


[llvm] [clang] [openmp] [OpenMP] Introduce support for OMPX extensions and taskgraph frontend (PR #66919)

2023-11-05 Thread via cfe-commits

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


[clang-tools-extra] [clang] [clang][NFC] Refactor `CXXNewExpr::InitializationStyle` (PR #71322)

2023-11-05 Thread Timm Baeder via cfe-commits


@@ -2388,15 +2389,20 @@ class CXXNewExpr final
 
   /// Whether this new-expression has any initializer at all.
   bool hasInitializer() const {
-return CXXNewExprBits.StoredInitializationStyle > 0;
+switch (getInitializationStyle()) {
+case CXXNewInitializationStyle::None:
+  return true;
+case CXXNewInitializationStyle::Implicit:
+case CXXNewInitializationStyle::Call:
+case CXXNewInitializationStyle::List:
+  return false;
+}

tbaederr wrote:

```suggestion
return getInitializationStyle() != CXXNewInitializationStyele::None;
```

(Isn't the logic of that code right now inverted?)

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


[clang] [llvm] [PowerPC] Add an alias for -mregnames so that full register names used in assembly. (PR #70255)

2023-11-05 Thread Fangrui Song via cfe-commits

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

Mostly looks good

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


[clang] [llvm] [PowerPC] Add an alias for -mregnames so that full register names used in assembly. (PR #70255)

2023-11-05 Thread Fangrui Song via cfe-commits


@@ -5011,6 +5011,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 Args.AddLastArg(CmdArgs, options::OPT_fthinlto_index_EQ);
   }
 
+  if (Triple.isPPC())
+if (const Arg *A =

MaskRay wrote:

use `AddOptInFlag`

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


[clang] [llvm] [PowerPC] Add an alias for -mregnames so that full register names used in assembly. (PR #70255)

2023-11-05 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,18 @@
+// REQUIRES: powerpc-registered-target
+// RUN: %clang -### -target powerpc-ibm-aix-xcoff -mcpu=pwr8 -O3 -mregnames \
+// RUN:   %s 2>&1 >/dev/null | FileCheck %s --check-prefix=FULLNAMES
+// RUN: %clang -### -target powerpc64-ibm-aix-xcoff -mcpu=pwr8 -O3 -mregnames \
+// RUN:   %s 2>&1 >/dev/null | FileCheck %s --check-prefix=FULLNAMES
+// RUN: %clang -### -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -O3 
-mregnames \
+// RUN:   %s 2>&1 >/dev/null | FileCheck %s --check-prefix=FULLNAMES
+// RUN: %clang -### -target powerpc-ibm-aix-xcoff -mcpu=pwr8 -O3 -mno-regnames 
\
+// RUN:   %s 2>&1 >/dev/null | FileCheck %s --check-prefix=NOFULLNAMES
+// RUN: %clang -### -target powerpc64-ibm-aix-xcoff -mcpu=pwr8 -O3 
-mno-regnames \
+// RUN:   %s 2>&1 >/dev/null | FileCheck %s --check-prefix=NOFULLNAMES
+// RUN: %clang -### -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -O3 
-mno-regnames \
+// RUN:   %s 2>&1 >/dev/null | FileCheck %s --check-prefix=NOFULLNAMES
+
+// FULLNAMES: -mregnames
+// NOFULLNAMES-NOT: -mregnames
+

MaskRay wrote:

Delete trailing blank lines

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


[llvm] [clang] [PowerPC] Add an alias for -mregnames so that full register names used in assembly. (PR #70255)

2023-11-05 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,18 @@
+// REQUIRES: powerpc-registered-target
+// RUN: %clang -### -target powerpc-ibm-aix-xcoff -mcpu=pwr8 -O3 -mregnames \
+// RUN:   %s 2>&1 >/dev/null | FileCheck %s --check-prefix=FULLNAMES
+// RUN: %clang -### -target powerpc64-ibm-aix-xcoff -mcpu=pwr8 -O3 -mregnames \

MaskRay wrote:

> This should just test that clang passes -target-feature. It's unnecessary to 
> enumerate every combination.

I think most RUN lines can be removed. `-O3` should be removed as well.

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


[llvm] [clang] [PowerPC] Add an alias for -mregnames so that full register names used in assembly. (PR #70255)

2023-11-05 Thread Fangrui Song via cfe-commits

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


[llvm] [clang] [PowerPC] Add an alias for -mregnames so that full register names used in assembly. (PR #70255)

2023-11-05 Thread Fangrui Song via cfe-commits


@@ -1780,6 +1780,9 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions 
&Opts, ArgList &Args,
   Opts.setDebugInfo(llvm::codegenoptions::LimitedDebugInfo);
   }
 
+  if (const Arg *A = Args.getLastArg(OPT_mregnames))
+Opts.PPCUseFullRegisterNames = true;

MaskRay wrote:

With `CodeGenOpts<"PPCUseFullRegisterNames">` this is unneeded

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


[llvm] [clang] [PowerPC] Add an alias for -mregnames so that full register names used in assembly. (PR #70255)

2023-11-05 Thread Fangrui Song via cfe-commits

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


[clang-tools-extra] [mlir] [flang] [clang] [libcxx] [compiler-rt] [llvm] [libc] [mlir][spirv] Implement gpu::TargetAttrInterface (PR #69949)

2023-11-05 Thread Youngsuk Kim via cfe-commits

JOE1994 wrote:

This revision seems related to the following buildbot failure:

* https://lab.llvm.org/buildbot/#/builders/268/builds/1747
  (+ builds 1748 & 1749) 

Would you mind taking a look? Thank you 👍 

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


[flang] [clang] [compiler-rt] [libcxx] [llvm] [libc] [mlir] [clang-tools-extra] [mlir][spirv] Implement gpu::TargetAttrInterface (PR #69949)

2023-11-05 Thread Lei Zhang via cfe-commits

antiagainst wrote:

Sorry about that! I uploaded 
https://github.com/llvm/llvm-project/commit/4a4b8570f7c16346094c59fab1bd8debf9b177e1
 to fix this. Verified that it fixes the break for me locally.

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


[PATCH] D150083: [clang-format] ObjCPropertyAttributeOrder to sort ObjC property attributes

2023-11-05 Thread Jared Grubb via Phabricator via cfe-commits
jaredgrubb added inline comments.



Comment at: clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp:55
+const FormatToken *LParenTok, const FormatToken *RParenTok) const {
+  // Skip past any leading comments.
+  const FormatToken *const BeginTok = LParenTok->getNextNonComment();

owenpan wrote:
> I strongly suggest that we bail out as well if there are leading and/or 
> trailing comments.
I'm ok with that!

In our codebase we have some code like this:
```
@property (/*nullable*/ readonly, strong) Thing *thing;
```
Nullablility annotations are all-or-nothing in a header file (putting it once 
triggers clang to complain about it missing in other eligible places). We have 
places where a dev wanted to add the attribute to one line but didn't want to 
commit to auditing the whole header. Their comment is a hint to the lucky 
person who does that work one day.

I thought it would be easy to handle a leading/trailing comment in this patch, 
but I am very ok with skipping these lines completely as you suggest. 
Conservative is probably safer!

I've revised the tests to affirm that any comments get skipped now.



Comment at: clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp:77
+  // Memoize the attribute. (Note that 'class' is a legal attribute!)
+  PropertyAttributes.push_back({Tok->TokenText.trim(), StringRef{}});
+

owenpan wrote:
> Do we need `trim()`?
I removed both `trim()` and my tests still pass. I wasn't fully sure when 
`trim` would help, but it doesn't seem to in this case.



Comment at: clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp:97
+  }
+
+  // Create a "remapping index" on how to reorder the attributes.

owenpan wrote:
> Can we assert `PropertyAttributes.size() > 1` here?
We shouldn't _assert_, as it is valid to have just one. But I can add an 
early-return for that though. (I'll also early-return if it's zero, which is 
also legal, eg `@property () int x`)



Comment at: clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp:113
+
+  // Deduplicate the attributes.
+  Indices.erase(std::unique(Indices.begin(), Indices.end(),

owenpan wrote:
> Is it valid in Objective-C to have duplicate attributes?
It's silly, but clang doesn't seem to care. I tried this, so duplicate was ok, 
but contradiction was flagged:
```
@property (strong, nonatomic, nonatomic) X *X;   // duplicate, but no error
@property (strong, nonatomic, weak) Y *y;   // error: Property attributes 
'strong' and 'weak' are mutually exclusive
```

I wasn't sure whether to do this, but went that way since that's what "sort 
include files" did. However, it seems like an odd corner case so I'd be ok 
removing this uniquing if you prefer.



Comment at: clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp:120
+Indices.end());
+
+  // If there are no removals or shuffling, then don't suggest any fixup.

owenpan wrote:
> Is it possible that `Indices` becomes empty or has only one element after 
> deduplication? 
It is possible to reduce to one element (I have a unit test case for that 
scenario `(a, a)`).

I don't see how `std::unique` could take a non-empty list and output an empty 
list, so I'll claim "no" on the empty part.



Comment at: clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp:184
+  for (AnnotatedLine *Line : AnnotatedLines) {
+if (!Line->Affected || Line->InPPDirective)
+  continue;

owenpan wrote:
> Why not `InPPDirective`?
I copy-pasted this from `LeftRightQualifierAlignmentFixer::analyze`, which I 
used as a template since I'm still getting used to the codebase. I wasn't sure 
whether this was important, so I left it in. But I don't think I have a good 
reason. 

I've added a new test case `SortsInPPDirective` that spot-checks some macro 
definition examples (which did fail unless this `Line->InPPDirective` check was 
removed, as expected.).



Comment at: clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp:190
+  continue;
+
+const auto *Last = Line->Last;

owenpan wrote:
> Must `@property` be the first non-comment tokens of an unwrapped line in 
> Objective-C? And at most one `@property` per line?
I can't think of any token that should precede a `@property`. Aka, I don't 
think there are any `__attribute__` that can fill that slot. 

You could have `@optional` or `@required` floating around between 
property/method declarations. I've added a test-case for a `@property` that is 
preceded by these tokens and proved that the reordering is handled correctly.

As for multiple properties in one line, I've never seen a codebase with that. 
clang-format does split them already.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150083/new/

https://reviews.llvm.org/D150083

___
cfe-commits mailing list
cf

[PATCH] D150083: [clang-format] ObjCPropertyAttributeOrder to sort ObjC property attributes

2023-11-05 Thread Jared Grubb via Phabricator via cfe-commits
jaredgrubb updated this revision to Diff 558009.
jaredgrubb marked 28 inline comments as done.
jaredgrubb added a comment.

Addressing all review comments to date.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150083/new/

https://reviews.llvm.org/D150083

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/CMakeLists.txt
  clang/lib/Format/Format.cpp
  clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp
  clang/lib/Format/ObjCPropertyAttributeOrderFixer.h
  clang/unittests/Format/CMakeLists.txt
  clang/unittests/Format/ObjCPropertyAttributeOrderFixerTest.cpp

Index: clang/unittests/Format/ObjCPropertyAttributeOrderFixerTest.cpp
===
--- /dev/null
+++ clang/unittests/Format/ObjCPropertyAttributeOrderFixerTest.cpp
@@ -0,0 +1,412 @@
+//===- unittest/Format/ObjCPropertyAttributeOrderFixerTest.cpp - unit tests
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "../lib/Format/ObjCPropertyAttributeOrderFixer.h"
+#include "FormatTestBase.h"
+#include "TestLexer.h"
+
+#define DEBUG_TYPE "format-objc-property-attribute-order-fixer-test"
+
+namespace clang {
+namespace format {
+namespace test {
+namespace {
+
+#define CHECK_PARSE(TEXT, FIELD, VALUE)\
+  EXPECT_NE(VALUE, Style.FIELD) << "Initial value already the same!";  \
+  EXPECT_EQ(0, parseConfiguration(TEXT, &Style).value());  \
+  EXPECT_EQ(VALUE, Style.FIELD) << "Unexpected value after parsing!"
+
+#define FAIL_PARSE(TEXT, FIELD, VALUE) \
+  EXPECT_NE(0, parseConfiguration(TEXT, &Style).value());  \
+  EXPECT_EQ(VALUE, Style.FIELD) << "Unexpected value after parsing!"
+
+class ObjCPropertyAttributeOrderFixerTest : public FormatTestBase {
+protected:
+  TokenList annotate(llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle()) {
+return TestLexer(Allocator, Buffers, Style).annotate(Code);
+  }
+
+  llvm::SpecificBumpPtrAllocator Allocator;
+  std::vector> Buffers;
+};
+
+TEST_F(ObjCPropertyAttributeOrderFixerTest, ParsesStyleOption) {
+  FormatStyle Style = {};
+  Style.Language = FormatStyle::LK_ObjC;
+
+  CHECK_PARSE("ObjCPropertyAttributeOrder: [class]", ObjCPropertyAttributeOrder,
+  std::vector({"class"}));
+
+  CHECK_PARSE("ObjCPropertyAttributeOrder: ["
+  "class, direct, atomic, nonatomic, "
+  "assign, retain, strong, copy, weak, unsafe_unretained, "
+  "readonly, readwrite, getter, setter, "
+  "nullable, nonnull, null_resettable, null_unspecified"
+  "]",
+  ObjCPropertyAttributeOrder,
+  std::vector({
+  "class",
+  "direct",
+  "atomic",
+  "nonatomic",
+  "assign",
+  "retain",
+  "strong",
+  "copy",
+  "weak",
+  "unsafe_unretained",
+  "readonly",
+  "readwrite",
+  "getter",
+  "setter",
+  "nullable",
+  "nonnull",
+  "null_resettable",
+  "null_unspecified",
+  }));
+}
+
+TEST_F(ObjCPropertyAttributeOrderFixerTest, SortsSpecifiedAttributes) {
+  FormatStyle Style = getLLVMStyle();
+  Style.Language = FormatStyle::LK_ObjC;
+  Style.ObjCPropertyAttributeOrder = {"a", "b", "c"};
+
+  // Zero: nothing to do, but is legal.
+  verifyFormat("@property() int p;", Style);
+
+  // One: shouldn't move.
+  verifyFormat("@property(a) int p;", Style);
+  verifyFormat("@property(b) int p;", Style);
+  verifyFormat("@property(c) int p;", Style);
+
+  // Two in correct order already: no change.
+  verifyFormat("@property(a, b) int p;", Style);
+  verifyFormat("@property(a, c) int p;", Style);
+  verifyFormat("@property(b, c) int p;", Style);
+
+  // Three in correct order already: no change.
+  verifyFormat("@property(a, b, c) int p;", Style);
+
+  // Two wrong order.
+  verifyFormat("@property(a, b) int p;", "@property(b, a) int p;", Style);
+  verifyFormat("@property(a, c) int p;", "@property(c, a) int p;", Style);
+  verifyFormat("@property(b, c) int p;", "@property(c, b) int p;", Style);
+
+  // Three wrong order.
+  verifyFormat("@property(a, b, c) int p;", "@property(b, a, c) int p;", Style);
+  verifyFormat("@property(a, b, c) int p;", "@property(c, b, a) int p;", Style);
+
+  // Check that properties preceded by @optional/@required work.
+  verifyFormat("@optional\n"
+   "@property(a,

[PATCH] D150083: [clang-format] ObjCPropertyAttributeOrder to sort ObjC property attributes

2023-11-05 Thread Jared Grubb via Phabricator via cfe-commits
jaredgrubb added a comment.

I opened https://github.com/llvm/llvm-project/issues/71323 for this patch.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150083/new/

https://reviews.llvm.org/D150083

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


[clang] Added removal of file extension when guessing the toolchain (PR #69887)

2023-11-05 Thread via cfe-commits

Overhatted wrote:

@MaskRay Pinging. Please let me know if I should tag someone else. 

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


[clang] [clang-tools-extra] [llvm] [flang] [mlir] [lldb] [compiler-rt] [libcxx] [mlir] Prepare convert-gpu-to-spirv for OpenCL support (PR #69941)

2023-11-05 Thread Sang Ik Lee via cfe-commits

silee2 wrote:

@antiagainst @joker-eph Can someone merge this PR?

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


[clang] [clang-tools-extra] [clang][NFC] Refactor `CXXNewExpr::InitializationStyle` (PR #71322)

2023-11-05 Thread Vlad Serebrennikov via cfe-commits

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

>From 40d25b8009f1c8734a99fd1350adaced6884cc7f Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Sun, 5 Nov 2023 18:53:48 +0300
Subject: [PATCH 1/3] [clang][NFC] Refacator `CXXNewExpr::InitializationStyle`

This patch converts `CXXNewExpr::InitializationStyle` into a scoped enum at 
namespace scope. It also affirms the status quo by adding a new enumerator to 
represent implicit initializer.
---
 .../modernize/MakeSmartPtrCheck.cpp   |  7 +--
 clang/include/clang/AST/ExprCXX.h | 48 +++
 clang/lib/AST/ExprCXX.cpp | 12 ++---
 clang/lib/AST/ItaniumMangle.cpp   |  4 +-
 clang/lib/AST/JSONNodeDumper.cpp  |  7 +--
 clang/lib/AST/StmtPrinter.cpp |  6 +--
 clang/lib/AST/StmtProfile.cpp |  2 +-
 clang/lib/Sema/SemaExprCXX.cpp| 22 -
 8 files changed, 58 insertions(+), 50 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
index 71fd8eca300c1b2..616e57efa76ded5 100644
--- a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -323,7 +323,8 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
 return false;
   };
   switch (New->getInitializationStyle()) {
-  case CXXNewExpr::NoInit: {
+  case CXXNewInitializationStyle::None:
+  case CXXNewInitializationStyle::Implicit: {
 if (ArraySizeExpr.empty()) {
   Diag << FixItHint::CreateRemoval(SourceRange(NewStart, NewEnd));
 } else {
@@ -334,7 +335,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
 }
 break;
   }
-  case CXXNewExpr::CallInit: {
+  case CXXNewInitializationStyle::Call: {
 // FIXME: Add fixes for constructors with parameters that can be created
 // with a C++11 braced-init-list (e.g. std::vector, std::map).
 // Unlike ordinal cases, braced list can not be deduced in
@@ -371,7 +372,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
 }
 break;
   }
-  case CXXNewExpr::ListInit: {
+  case CXXNewInitializationStyle::List: {
 // Range of the substring that we do not want to remove.
 SourceRange InitRange;
 if (const auto *NewConstruct = New->getConstructExpr()) {
diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index a106bafcfa3e021..d713bcf8eb70258 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -2206,6 +2206,20 @@ class CXXScalarValueInitExpr : public Expr {
   }
 };
 
+enum class CXXNewInitializationStyle {
+  /// New-expression has no initializer as written.
+  None,
+
+  /// New-expression has no written initializer, but has an implicit one.
+  Implicit,
+
+  /// New-expression has a C++98 paren-delimited initializer.
+  Call,
+
+  /// New-expression has a C++11 list-initializer.
+  List
+};
+
 /// Represents a new-expression for memory allocation and constructor
 /// calls, e.g: "new CXXNewExpr(foo)".
 class CXXNewExpr final
@@ -2259,25 +2273,12 @@ class CXXNewExpr final
 return isParenTypeId();
   }
 
-public:
-  enum InitializationStyle {
-/// New-expression has no initializer as written.
-NoInit,
-
-/// New-expression has a C++98 paren-delimited initializer.
-CallInit,
-
-/// New-expression has a C++11 list-initializer.
-ListInit
-  };
-
-private:
   /// Build a c++ new expression.
   CXXNewExpr(bool IsGlobalNew, FunctionDecl *OperatorNew,
  FunctionDecl *OperatorDelete, bool ShouldPassAlignment,
  bool UsualArrayDeleteWantsSize, ArrayRef PlacementArgs,
  SourceRange TypeIdParens, std::optional ArraySize,
- InitializationStyle InitializationStyle, Expr *Initializer,
+ CXXNewInitializationStyle InitializationStyle, Expr *Initializer,
  QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
  SourceRange DirectInitRange);
 
@@ -2292,7 +2293,7 @@ class CXXNewExpr final
  FunctionDecl *OperatorDelete, bool ShouldPassAlignment,
  bool UsualArrayDeleteWantsSize, ArrayRef PlacementArgs,
  SourceRange TypeIdParens, std::optional ArraySize,
- InitializationStyle InitializationStyle, Expr *Initializer,
+ CXXNewInitializationStyle InitializationStyle, Expr *Initializer,
  QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
  SourceRange DirectInitRange);
 
@@ -2388,15 +2389,20 @@ class CXXNewExpr final
 
   /// Whether this new-expression has any initializer at all.
   bool hasInitializer() const {
-return CXXNewExprBits.StoredInitializationStyle > 0;
+switch(getInitializationStyle()) {
+case CXXNewInitializationStyle::None:
+  return true;
+case CXXNewInitializationStyle::Implicit:
+   

[clang] [clang-tools-extra] [clang][NFC] Refactor `CXXNewExpr::InitializationStyle` (PR #71322)

2023-11-05 Thread Vlad Serebrennikov via cfe-commits


@@ -2388,15 +2389,20 @@ class CXXNewExpr final
 
   /// Whether this new-expression has any initializer at all.
   bool hasInitializer() const {
-return CXXNewExprBits.StoredInitializationStyle > 0;
+switch (getInitializationStyle()) {
+case CXXNewInitializationStyle::None:
+  return true;
+case CXXNewInitializationStyle::Implicit:
+case CXXNewInitializationStyle::Call:
+case CXXNewInitializationStyle::List:
+  return false;
+}

Endilll wrote:

Behavioral change wasn't intended and is now fixed (thank you!)
I find inequality checks against enums not very robust, so I refactored this 
into switch.

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


[clang] [Clang][Driver][LTO] Fix empty stats filename when in LTO mode (PR #71197)

2023-11-05 Thread Min-Yih Hsu via cfe-commits

https://github.com/mshockwave updated 
https://github.com/llvm/llvm-project/pull/71197

>From 8d5acb56b364648d1abd6bfff6815af71e131d6e Mon Sep 17 00:00:00 2001
From: Min Hsu 
Date: Thu, 2 Nov 2023 17:26:17 -0700
Subject: [PATCH 1/2] [Clang][Driver][LTO] Fix empty stats filename when in LTO
 mode

Previously, if a linker flag (i.e.g -Wl) is presented before any input
filenames, Gnu driver would use the InputInfo object of that flag to
generate stats filename for LTO backend, causing an empty filename.
This patch fixes such issue.
---
 clang/lib/Driver/ToolChains/Gnu.cpp | 10 +-
 clang/test/Driver/save-stats.c  |  2 ++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 5237951f84cce03..8448d4bda13c434 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -535,7 +535,15 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 
   if (D.isUsingLTO()) {
 assert(!Inputs.empty() && "Must have at least one input.");
-addLTOOptions(ToolChain, Args, CmdArgs, Output, Inputs[0],
+// Find the first filename InputInfo object.
+auto Input = llvm::find_if(
+Inputs, [](const InputInfo &II) -> bool { return II.isFilename(); });
+if (Input == Inputs.end())
+  // For a very rare case, all of the inputs to the linker are
+  // flags. If that happens, just use the first InputInfo.
+  Input = Inputs.begin();
+
+addLTOOptions(ToolChain, Args, CmdArgs, Output, *Input,
   D.getLTOMode() == LTOK_Thin);
   }
 
diff --git a/clang/test/Driver/save-stats.c b/clang/test/Driver/save-stats.c
index ca8f2a457d4488c..d6ad4e0097f3432 100644
--- a/clang/test/Driver/save-stats.c
+++ b/clang/test/Driver/save-stats.c
@@ -20,6 +20,8 @@
 // CHECK-INVALID: invalid value 'bla' in '-save-stats=bla'
 
 // RUN: %clang -target x86_64-linux-unknown -save-stats -flto -o 
obj/dir/save-stats.exe %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
+// Previously `-plugin-opt=stats-file` would use empty filename if a linker 
flag (i.e. -Wl) is presented before any input filename.
+// RUN: %clang -target x86_64-linux-unknown -save-stats -flto -o 
obj/dir/save-stats.exe -Wl,-plugin-opt=-dummy %s -### 2>&1 | FileCheck %s 
-check-prefix=CHECK-LTO
 // CHECK-LTO: "-stats-file=save-stats.stats"
 // CHECK-LTO: "-o" "obj/dir{{/|}}save-stats.exe"
 // CHECK-LTO: "-plugin-opt=stats-file=save-stats.stats"

>From a235c39323e7e46e81a474fb6eb45a74ea4adcc5 Mon Sep 17 00:00:00 2001
From: Min Hsu 
Date: Sun, 5 Nov 2023 11:29:42 -0800
Subject: [PATCH 2/2] fixup! [Clang][Driver][LTO] Fix empty stats filename when
 in LTO mode

---
 clang/lib/Driver/ToolChains/Gnu.cpp | 2 +-
 clang/test/Driver/save-stats.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 8448d4bda13c434..3276590729e47ea 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -540,7 +540,7 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 Inputs, [](const InputInfo &II) -> bool { return II.isFilename(); });
 if (Input == Inputs.end())
   // For a very rare case, all of the inputs to the linker are
-  // flags. If that happens, just use the first InputInfo.
+  // InputArg. If that happens, just use the first InputInfo.
   Input = Inputs.begin();
 
 addLTOOptions(ToolChain, Args, CmdArgs, Output, *Input,
diff --git a/clang/test/Driver/save-stats.c b/clang/test/Driver/save-stats.c
index d6ad4e0097f3432..2208c229b91e56c 100644
--- a/clang/test/Driver/save-stats.c
+++ b/clang/test/Driver/save-stats.c
@@ -21,7 +21,7 @@
 
 // RUN: %clang -target x86_64-linux-unknown -save-stats -flto -o 
obj/dir/save-stats.exe %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
 // Previously `-plugin-opt=stats-file` would use empty filename if a linker 
flag (i.e. -Wl) is presented before any input filename.
-// RUN: %clang -target x86_64-linux-unknown -save-stats -flto -o 
obj/dir/save-stats.exe -Wl,-plugin-opt=-dummy %s -### 2>&1 | FileCheck %s 
-check-prefix=CHECK-LTO
+// RUN: %clang --target=x86_64-linux-unknown -save-stats -flto -o 
obj/dir/save-stats.exe -Wl,-plugin-opt=-dummy %s -### 2>&1 | FileCheck %s 
-check-prefix=CHECK-LTO
 // CHECK-LTO: "-stats-file=save-stats.stats"
 // CHECK-LTO: "-o" "obj/dir{{/|}}save-stats.exe"
 // CHECK-LTO: "-plugin-opt=stats-file=save-stats.stats"

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


[clang] [Clang][Driver][LTO] Fix empty stats filename when in LTO mode (PR #71197)

2023-11-05 Thread Min-Yih Hsu via cfe-commits


@@ -20,6 +20,8 @@
 // CHECK-INVALID: invalid value 'bla' in '-save-stats=bla'
 
 // RUN: %clang -target x86_64-linux-unknown -save-stats -flto -o 
obj/dir/save-stats.exe %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
+// Previously `-plugin-opt=stats-file` would use empty filename if a linker 
flag (i.e. -Wl) is presented before any input filename.
+// RUN: %clang -target x86_64-linux-unknown -save-stats -flto -o 
obj/dir/save-stats.exe -Wl,-plugin-opt=-dummy %s -### 2>&1 | FileCheck %s 
-check-prefix=CHECK-LTO

mshockwave wrote:

Done

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


[clang] [Clang][Driver][LTO] Fix empty stats filename when in LTO mode (PR #71197)

2023-11-05 Thread Min-Yih Hsu via cfe-commits


@@ -535,7 +535,15 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 
   if (D.isUsingLTO()) {
 assert(!Inputs.empty() && "Must have at least one input.");
-addLTOOptions(ToolChain, Args, CmdArgs, Output, Inputs[0],
+// Find the first filename InputInfo object.
+auto Input = llvm::find_if(
+Inputs, [](const InputInfo &II) -> bool { return II.isFilename(); });
+if (Input == Inputs.end())
+  // For a very rare case, all of the inputs to the linker are
+  // flags. If that happens, just use the first InputInfo.

mshockwave wrote:

Done

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


[clang] 85451f4 - [Clang][Driver][LTO] Fix empty stats filename when in LTO mode (#71197)

2023-11-05 Thread via cfe-commits

Author: Min-Yih Hsu
Date: 2023-11-05T11:31:26-08:00
New Revision: 85451f486d8144f8aacd94a47802c77da5a04d27

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

LOG: [Clang][Driver][LTO] Fix empty stats filename when in LTO mode (#71197)

Previously, if a linker argument (i.e. -Wl) is presented before any input
filenames, Gnu driver would use the InputInfo object of that argument to 
generate stats filename for LTO backend, causing an empty filename. This patch 
fixes such issue.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Gnu.cpp
clang/test/Driver/save-stats.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 5237951f84cce03..3276590729e47ea 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -535,7 +535,15 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 
   if (D.isUsingLTO()) {
 assert(!Inputs.empty() && "Must have at least one input.");
-addLTOOptions(ToolChain, Args, CmdArgs, Output, Inputs[0],
+// Find the first filename InputInfo object.
+auto Input = llvm::find_if(
+Inputs, [](const InputInfo &II) -> bool { return II.isFilename(); });
+if (Input == Inputs.end())
+  // For a very rare case, all of the inputs to the linker are
+  // InputArg. If that happens, just use the first InputInfo.
+  Input = Inputs.begin();
+
+addLTOOptions(ToolChain, Args, CmdArgs, Output, *Input,
   D.getLTOMode() == LTOK_Thin);
   }
 

diff  --git a/clang/test/Driver/save-stats.c b/clang/test/Driver/save-stats.c
index ca8f2a457d4488c..2208c229b91e56c 100644
--- a/clang/test/Driver/save-stats.c
+++ b/clang/test/Driver/save-stats.c
@@ -20,6 +20,8 @@
 // CHECK-INVALID: invalid value 'bla' in '-save-stats=bla'
 
 // RUN: %clang -target x86_64-linux-unknown -save-stats -flto -o 
obj/dir/save-stats.exe %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
+// Previously `-plugin-opt=stats-file` would use empty filename if a linker 
flag (i.e. -Wl) is presented before any input filename.
+// RUN: %clang --target=x86_64-linux-unknown -save-stats -flto -o 
obj/dir/save-stats.exe -Wl,-plugin-opt=-dummy %s -### 2>&1 | FileCheck %s 
-check-prefix=CHECK-LTO
 // CHECK-LTO: "-stats-file=save-stats.stats"
 // CHECK-LTO: "-o" "obj/dir{{/|}}save-stats.exe"
 // CHECK-LTO: "-plugin-opt=stats-file=save-stats.stats"



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


[clang] [Clang][Driver][LTO] Fix empty stats filename when in LTO mode (PR #71197)

2023-11-05 Thread Min-Yih Hsu via cfe-commits

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


[clang] [clang-tools-extra] [llvm] [libc] [flang] [mlir] [compiler-rt] [libcxx] [mlir][spirv] Implement gpu::TargetAttrInterface (PR #69949)

2023-11-05 Thread Jacques Pienaar via cfe-commits


@@ -15,6 +15,7 @@
 
 #include "Utils.h"
 #include "mlir/Dialect/GPU/IR/GPUDialect.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.h"

jpienaar wrote:

This feels off: you have GPU dialect transforms depending on SPIRV 
attributes/dialect (esp in header). Why is this pass in GPU dialect rather than 
SPIRV one?

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


[clang-tools-extra] [libc] [libcxx] [compiler-rt] [flang] [mlir] [clang] [llvm] [mlir][spirv] Implement gpu::TargetAttrInterface (PR #69949)

2023-11-05 Thread Fabian Mora via cfe-commits


@@ -15,6 +15,7 @@
 
 #include "Utils.h"
 #include "mlir/Dialect/GPU/IR/GPUDialect.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.h"

fabianmcg wrote:

Back when the compilation redesign was happening we decided to add the attach* 
passes in GPU to avoid polluting lower level dialects with GPU includes. 
However, I do agree that include shouldn't be there, as far as I could tell, 
that include is only needed by one pass option 
`mlir::spirv::TargetEnvAttr::kUnknownDeviceID`, so it should be possible to 
remove it. I'll fix it.

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


[clang-tools-extra] [libc] [libcxx] [compiler-rt] [flang] [clang] [llvm] [libcxx] Unifying __is_trivial_equality_predicate and __is_trivial_plus_operation into __desugars_to (PR #68642)

2023-11-05 Thread Anton Rydahl via cfe-commits


@@ -18,8 +18,11 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-template 
-struct __is_trivial_plus_operation : false_type {};
+template 

AntonRydahl wrote:

Hi @ldionne!

I am unsure about what I am supposed to do with the following:
```C++
template  struct __desugars_to<__equal_tag, __equal, _Tp, 
_Up> : true_type {};
```
Do we want to match the function from `include/__algorithm/equal.h`?

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


[clang] 8103ae6 - [Driver][Solaris][NFC] A little bit of clean up (#69867)

2023-11-05 Thread via cfe-commits

Author: Brad Smith
Date: 2023-11-05T15:09:31-05:00
New Revision: 8103ae666402fbcfd68839994bfd848c3925fbed

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

LOG: [Driver][Solaris][NFC] A little bit of clean up (#69867)

Added: 


Modified: 
clang/lib/Driver/ToolChains/Solaris.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Solaris.cpp 
b/clang/lib/Driver/ToolChains/Solaris.cpp
index 5421c029562abca..e45932008a65ab8 100644
--- a/clang/lib/Driver/ToolChains/Solaris.cpp
+++ b/clang/lib/Driver/ToolChains/Solaris.cpp
@@ -87,10 +87,12 @@ void solaris::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
const InputInfoList &Inputs,
const ArgList &Args,
const char *LinkingOutput) const {
-  const Driver &D = getToolChain().getDriver();
-  const bool IsPIE = getPIE(Args, getToolChain());
+  const auto &ToolChain = static_cast(getToolChain());
+  const Driver &D = ToolChain.getDriver();
+  const llvm::Triple::ArchType Arch = ToolChain.getArch();
+  const bool IsPIE = getPIE(Args, ToolChain);
+  const bool LinkerIsGnuLd = isLinkerGnuLd(ToolChain, Args);
   ArgStringList CmdArgs;
-  bool LinkerIsGnuLd = isLinkerGnuLd(getToolChain(), Args);
 
   // Demangle C++ names in errors.  GNU ld already defaults to --demangle.
   if (!LinkerIsGnuLd)
@@ -126,9 +128,6 @@ void solaris::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 
   if (LinkerIsGnuLd) {
 // Set the correct linker emulation for 32- and 64-bit Solaris.
-const auto &ToolChain = static_cast(getToolChain());
-const llvm::Triple::ArchType Arch = ToolChain.getArch();
-
 switch (Arch) {
 case llvm::Triple::x86:
   CmdArgs.push_back("-m");
@@ -168,10 +167,9 @@ void solaris::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
options::OPT_r)) {
 if (!Args.hasArg(options::OPT_shared))
-  CmdArgs.push_back(
-  Args.MakeArgString(getToolChain().GetFilePath("crt1.o")));
+  CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt1.o")));
 
-
CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crti.o")));
+CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.o")));
 
 const Arg *Std = Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi);
 bool HaveAnsi = false;
@@ -186,43 +184,42 @@ void solaris::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 // Use values-Xc.o for -ansi, -std=c*, -std=iso9899:199409.
 if (HaveAnsi || (LangStd && !LangStd->isGNUMode()))
   values_X = "values-Xc.o";
-
CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(values_X)));
+CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(values_X)));
 
 const char *values_xpg = "values-xpg6.o";
 // Use values-xpg4.o for -std=c90, -std=gnu90, -std=iso9899:199409.
 if (LangStd && LangStd->getLanguage() == Language::C && !LangStd->isC99())
   values_xpg = "values-xpg4.o";
-CmdArgs.push_back(
-Args.MakeArgString(getToolChain().GetFilePath(values_xpg)));
+CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(values_xpg)));
 
 const char *crtbegin = nullptr;
 if (Args.hasArg(options::OPT_shared) || IsPIE)
   crtbegin = "crtbeginS.o";
 else
   crtbegin = "crtbegin.o";
-
CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(crtbegin)));
+CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtbegin)));
 // Add crtfastmath.o if available and fast math is enabled.
-getToolChain().addFastMathRuntimeIfAvailable(Args, CmdArgs);
+ToolChain.addFastMathRuntimeIfAvailable(Args, CmdArgs);
   }
 
-  getToolChain().AddFilePathLibArgs(Args, CmdArgs);
+  ToolChain.AddFilePathLibArgs(Args, CmdArgs);
 
   Args.addAllArgs(CmdArgs,
   {options::OPT_L, options::OPT_T_Group, options::OPT_r});
 
-  bool NeedsSanitizerDeps = addSanitizerRuntimes(getToolChain(), Args, 
CmdArgs);
-  AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
+  bool NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs);
+  AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
options::OPT_r)) {
 // Use the static OpenMP runtime with -static-openmp
 bool StaticOpenMP = Args.hasArg(options::OPT_static_openmp) &&
 !Args.hasArg(options::OPT_static);
-addOpenMPRuntime(CmdArgs, getToolChain(), Args, StaticOpenMP);
+addOpenMPRuntime(CmdArgs, ToolChain, Args, StaticOpenMP);
 
 if (D.CCCIsCXX()) {
-  if (get

[clang] [Driver][Solaris][NFC] A little bit of clean up (PR #69867)

2023-11-05 Thread Brad Smith via cfe-commits

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


[clang] Added removal of file extension when guessing the toolchain (PR #69887)

2023-11-05 Thread Fangrui Song via cfe-commits

MaskRay wrote:

In quite a few places we only detect `.exe` as the extension name. I am not 
sure we should commit to arbitrary extension name now. The build systems can 
consider `--driver-mode=cl`

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


[clang] [StackProtector] Do not emit the stack protector on GPU architectures (PR #70799)

2023-11-05 Thread Fangrui Song via cfe-commits

MaskRay wrote:

I think this is fine, but we probably should think about the general option 
compatibility problem 
https://github.com/llvm/llvm-project/pull/70740#issuecomment-1786180822

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


[libcxx] [clang] [libc] [flang] [llvm] [compiler-rt] [clang-tools-extra] [libcxx] Unifying __is_trivial_equality_predicate and __is_trivial_plus_operation into __desugars_to (PR #68642)

2023-11-05 Thread Anton Rydahl via cfe-commits

https://github.com/AntonRydahl updated 
https://github.com/llvm/llvm-project/pull/68642

>From f0d93cc6a5cd485c654ab38221691db038bacc7d Mon Sep 17 00:00:00 2001
From: AntonRydahl 
Date: Mon, 9 Oct 2023 15:13:22 -0700
Subject: [PATCH 1/5] Merged __is_trivial_equality_predicate and
 __is_trivial_plus_operation into __desugars_to

---
 libcxx/include/CMakeLists.txt |  1 -
 libcxx/include/__algorithm/comp.h |  7 ++---
 libcxx/include/__algorithm/equal.h| 22 
 .../cpu_backends/transform_reduce.h   | 23 
 libcxx/include/__functional/operations.h  | 15 +--
 .../include/__functional/ranges_operations.h  |  7 ++---
 .../include/__numeric/pstl_transform_reduce.h |  2 +-
 .../include/__type_traits/operation_traits.h  |  4 +--
 .../include/__type_traits/predicate_traits.h  | 26 ---
 libcxx/include/module.modulemap.in|  1 -
 10 files changed, 40 insertions(+), 68 deletions(-)
 delete mode 100644 libcxx/include/__type_traits/predicate_traits.h

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 340353f8ebb41c4..7eb09a06ccd482e 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -813,7 +813,6 @@ set(files
   __type_traits/negation.h
   __type_traits/noexcept_move_assign_container.h
   __type_traits/operation_traits.h
-  __type_traits/predicate_traits.h
   __type_traits/promote.h
   __type_traits/rank.h
   __type_traits/remove_all_extents.h
diff --git a/libcxx/include/__algorithm/comp.h 
b/libcxx/include/__algorithm/comp.h
index 9474536615ffb67..0993c37cce36a6b 100644
--- a/libcxx/include/__algorithm/comp.h
+++ b/libcxx/include/__algorithm/comp.h
@@ -10,8 +10,9 @@
 #define _LIBCPP___ALGORITHM_COMP_H
 
 #include <__config>
+#include <__functional/operations.h>
 #include <__type_traits/integral_constant.h>
-#include <__type_traits/predicate_traits.h>
+#include <__type_traits/operation_traits.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
@@ -26,8 +27,8 @@ struct __equal_to {
   }
 };
 
-template 
-struct __is_trivial_equality_predicate<__equal_to, _Lhs, _Rhs> : true_type {};
+template <>
+struct __desugars_to<__equal_to, std::equal_to<>> : true_type {};
 
 // The definition is required because __less is part of the ABI, but it's empty
 // because all comparisons should be transparent.
diff --git a/libcxx/include/__algorithm/equal.h 
b/libcxx/include/__algorithm/equal.h
index b69aeff92bb9289..35e82da15e4d058 100644
--- a/libcxx/include/__algorithm/equal.h
+++ b/libcxx/include/__algorithm/equal.h
@@ -15,6 +15,7 @@
 #include <__config>
 #include <__functional/identity.h>
 #include <__functional/invoke.h>
+#include <__functional/operations.h>
 #include <__iterator/distance.h>
 #include <__iterator/iterator_traits.h>
 #include <__string/constexpr_c_functions.h>
@@ -23,7 +24,7 @@
 #include <__type_traits/is_constant_evaluated.h>
 #include <__type_traits/is_equality_comparable.h>
 #include <__type_traits/is_volatile.h>
-#include <__type_traits/predicate_traits.h>
+#include <__type_traits/operation_traits.h>
 #include <__utility/move.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -41,13 +42,12 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI 
_LIBCPP_CONSTEXPR_SINCE_CXX20 boo
   return true;
 }
 
-template <
-class _Tp,
-class _Up,
-class _BinaryPredicate,
-__enable_if_t<__is_trivial_equality_predicate<_BinaryPredicate, _Tp, 
_Up>::value && !is_volatile<_Tp>::value &&
-  !is_volatile<_Up>::value && 
__libcpp_is_trivially_equality_comparable<_Tp, _Up>::value,
-  int> = 0>
+template < class _Tp,
+   class _Up,
+   class _BinaryPredicate,
+   __enable_if_t<__desugars_to<_BinaryPredicate, 
std::equal_to<>>::value && !is_volatile<_Tp>::value &&
+ !is_volatile<_Up>::value && 
__libcpp_is_trivially_equality_comparable<_Tp, _Up>::value,
+ int> = 0>
 _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 
bool
 __equal_iter_impl(_Tp* __first1, _Tp* __last1, _Up* __first2, 
_BinaryPredicate&) {
   return std::__constexpr_memcmp_equal(__first1, __first2, 
__element_count(__last1 - __first1));
@@ -94,12 +94,12 @@ template ::value && __is_identity<_Proj1>::value &&
+  __enable_if_t<__desugars_to<_Pred, std::equal_to<>>::value && 
__is_identity<_Proj1>::value &&
 __is_identity<_Proj2>::value && 
!is_volatile<_Tp>::value && !is_volatile<_Up>::value &&
 __libcpp_is_trivially_equality_comparable<_Tp, 
_Up>::value,
 int> = 0>
-_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 
bool __equal_impl(
-_Tp* __first1, _Tp* __last1, _Up* __first2, _Up*, _Pred&, _Proj1&, 
_Proj2&) {
+_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 
bool
+

[compiler-rt] [libcxx] [clang] [libc] [flang] [llvm] [clang-tools-extra] [libcxx] Unifying __is_trivial_equality_predicate and __is_trivial_plus_operation into __desugars_to (PR #68642)

2023-11-05 Thread Anton Rydahl via cfe-commits

https://github.com/AntonRydahl updated 
https://github.com/llvm/llvm-project/pull/68642

>From f0d93cc6a5cd485c654ab38221691db038bacc7d Mon Sep 17 00:00:00 2001
From: AntonRydahl 
Date: Mon, 9 Oct 2023 15:13:22 -0700
Subject: [PATCH 1/5] Merged __is_trivial_equality_predicate and
 __is_trivial_plus_operation into __desugars_to

---
 libcxx/include/CMakeLists.txt |  1 -
 libcxx/include/__algorithm/comp.h |  7 ++---
 libcxx/include/__algorithm/equal.h| 22 
 .../cpu_backends/transform_reduce.h   | 23 
 libcxx/include/__functional/operations.h  | 15 +--
 .../include/__functional/ranges_operations.h  |  7 ++---
 .../include/__numeric/pstl_transform_reduce.h |  2 +-
 .../include/__type_traits/operation_traits.h  |  4 +--
 .../include/__type_traits/predicate_traits.h  | 26 ---
 libcxx/include/module.modulemap.in|  1 -
 10 files changed, 40 insertions(+), 68 deletions(-)
 delete mode 100644 libcxx/include/__type_traits/predicate_traits.h

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 340353f8ebb41c4..7eb09a06ccd482e 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -813,7 +813,6 @@ set(files
   __type_traits/negation.h
   __type_traits/noexcept_move_assign_container.h
   __type_traits/operation_traits.h
-  __type_traits/predicate_traits.h
   __type_traits/promote.h
   __type_traits/rank.h
   __type_traits/remove_all_extents.h
diff --git a/libcxx/include/__algorithm/comp.h 
b/libcxx/include/__algorithm/comp.h
index 9474536615ffb67..0993c37cce36a6b 100644
--- a/libcxx/include/__algorithm/comp.h
+++ b/libcxx/include/__algorithm/comp.h
@@ -10,8 +10,9 @@
 #define _LIBCPP___ALGORITHM_COMP_H
 
 #include <__config>
+#include <__functional/operations.h>
 #include <__type_traits/integral_constant.h>
-#include <__type_traits/predicate_traits.h>
+#include <__type_traits/operation_traits.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
@@ -26,8 +27,8 @@ struct __equal_to {
   }
 };
 
-template 
-struct __is_trivial_equality_predicate<__equal_to, _Lhs, _Rhs> : true_type {};
+template <>
+struct __desugars_to<__equal_to, std::equal_to<>> : true_type {};
 
 // The definition is required because __less is part of the ABI, but it's empty
 // because all comparisons should be transparent.
diff --git a/libcxx/include/__algorithm/equal.h 
b/libcxx/include/__algorithm/equal.h
index b69aeff92bb9289..35e82da15e4d058 100644
--- a/libcxx/include/__algorithm/equal.h
+++ b/libcxx/include/__algorithm/equal.h
@@ -15,6 +15,7 @@
 #include <__config>
 #include <__functional/identity.h>
 #include <__functional/invoke.h>
+#include <__functional/operations.h>
 #include <__iterator/distance.h>
 #include <__iterator/iterator_traits.h>
 #include <__string/constexpr_c_functions.h>
@@ -23,7 +24,7 @@
 #include <__type_traits/is_constant_evaluated.h>
 #include <__type_traits/is_equality_comparable.h>
 #include <__type_traits/is_volatile.h>
-#include <__type_traits/predicate_traits.h>
+#include <__type_traits/operation_traits.h>
 #include <__utility/move.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -41,13 +42,12 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI 
_LIBCPP_CONSTEXPR_SINCE_CXX20 boo
   return true;
 }
 
-template <
-class _Tp,
-class _Up,
-class _BinaryPredicate,
-__enable_if_t<__is_trivial_equality_predicate<_BinaryPredicate, _Tp, 
_Up>::value && !is_volatile<_Tp>::value &&
-  !is_volatile<_Up>::value && 
__libcpp_is_trivially_equality_comparable<_Tp, _Up>::value,
-  int> = 0>
+template < class _Tp,
+   class _Up,
+   class _BinaryPredicate,
+   __enable_if_t<__desugars_to<_BinaryPredicate, 
std::equal_to<>>::value && !is_volatile<_Tp>::value &&
+ !is_volatile<_Up>::value && 
__libcpp_is_trivially_equality_comparable<_Tp, _Up>::value,
+ int> = 0>
 _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 
bool
 __equal_iter_impl(_Tp* __first1, _Tp* __last1, _Up* __first2, 
_BinaryPredicate&) {
   return std::__constexpr_memcmp_equal(__first1, __first2, 
__element_count(__last1 - __first1));
@@ -94,12 +94,12 @@ template ::value && __is_identity<_Proj1>::value &&
+  __enable_if_t<__desugars_to<_Pred, std::equal_to<>>::value && 
__is_identity<_Proj1>::value &&
 __is_identity<_Proj2>::value && 
!is_volatile<_Tp>::value && !is_volatile<_Up>::value &&
 __libcpp_is_trivially_equality_comparable<_Tp, 
_Up>::value,
 int> = 0>
-_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 
bool __equal_impl(
-_Tp* __first1, _Tp* __last1, _Up* __first2, _Up*, _Pred&, _Proj1&, 
_Proj2&) {
+_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 
bool
+

[PATCH] D154396: [clang] Add support for SerenityOS

2023-11-05 Thread Andrew Kaster via Phabricator via cfe-commits
ADKaster added inline comments.



Comment at: clang/lib/Driver/ToolChains/Serenity.cpp:202
+  addSystemInclude(DriverArgs, CC1Args,
+   concat(D.SysRoot, "/usr/local/include"));
+  addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, "/usr/include"));

brad wrote:
> IMO if the library path is removed then the header path should be as well.
Fair. /usr/local is the prefix that all ports in the Ports/ tree are installed 
into by default (though some end up with files in /opt). We can for sure work a 
bit harder to make those headers/libs available to ports in our build 
infrastructure for them rather than putting that logic in the compiler.



Comment at: clang/lib/Driver/ToolChains/Serenity.cpp:211
+  options::OPT_fno_use_init_array, true))
+CC1Args.push_back("-fno-use-init-array");
+}

MaskRay wrote:
> This is for systems that historically support .ctors/.dtors 
> https://maskray.me/blog/2021-11-07-init-ctors-init-array
> 
> If Serenity doesn't, this should be removed.
It's my understanding that we don't currently support .ctors/.dtors, though we 
did a few years ago. It is a bit confusing to me how those are related to 
.init/.fini though. We have some stubs here for `crti.S` and `crtn.S` 
https://github.com/SerenityOS/serenity/blob/cf3c8a216be5aa496844aadb43ca05ad5c47bb46/Userland/Libraries/LibC/arch/x86_64/crti.S
 which end up giving every .so and executable a DT_INIT section, but all the 
actual global ctors and dtors end up in .init_array/.fini_array.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154396/new/

https://reviews.llvm.org/D154396

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


[PATCH] D150083: [clang-format] ObjCPropertyAttributeOrder to sort ObjC property attributes

2023-11-05 Thread Jared Grubb via Phabricator via cfe-commits
jaredgrubb updated this revision to Diff 558010.
jaredgrubb added a comment.

Adjusting the Style comments, since the behavior changed and were not updated 
to reflect that leading/trailing comments no longer have special handling.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150083/new/

https://reviews.llvm.org/D150083

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/CMakeLists.txt
  clang/lib/Format/Format.cpp
  clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp
  clang/lib/Format/ObjCPropertyAttributeOrderFixer.h
  clang/unittests/Format/CMakeLists.txt
  clang/unittests/Format/ObjCPropertyAttributeOrderFixerTest.cpp

Index: clang/unittests/Format/ObjCPropertyAttributeOrderFixerTest.cpp
===
--- /dev/null
+++ clang/unittests/Format/ObjCPropertyAttributeOrderFixerTest.cpp
@@ -0,0 +1,412 @@
+//===- unittest/Format/ObjCPropertyAttributeOrderFixerTest.cpp - unit tests
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "../lib/Format/ObjCPropertyAttributeOrderFixer.h"
+#include "FormatTestBase.h"
+#include "TestLexer.h"
+
+#define DEBUG_TYPE "format-objc-property-attribute-order-fixer-test"
+
+namespace clang {
+namespace format {
+namespace test {
+namespace {
+
+#define CHECK_PARSE(TEXT, FIELD, VALUE)\
+  EXPECT_NE(VALUE, Style.FIELD) << "Initial value already the same!";  \
+  EXPECT_EQ(0, parseConfiguration(TEXT, &Style).value());  \
+  EXPECT_EQ(VALUE, Style.FIELD) << "Unexpected value after parsing!"
+
+#define FAIL_PARSE(TEXT, FIELD, VALUE) \
+  EXPECT_NE(0, parseConfiguration(TEXT, &Style).value());  \
+  EXPECT_EQ(VALUE, Style.FIELD) << "Unexpected value after parsing!"
+
+class ObjCPropertyAttributeOrderFixerTest : public FormatTestBase {
+protected:
+  TokenList annotate(llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle()) {
+return TestLexer(Allocator, Buffers, Style).annotate(Code);
+  }
+
+  llvm::SpecificBumpPtrAllocator Allocator;
+  std::vector> Buffers;
+};
+
+TEST_F(ObjCPropertyAttributeOrderFixerTest, ParsesStyleOption) {
+  FormatStyle Style = {};
+  Style.Language = FormatStyle::LK_ObjC;
+
+  CHECK_PARSE("ObjCPropertyAttributeOrder: [class]", ObjCPropertyAttributeOrder,
+  std::vector({"class"}));
+
+  CHECK_PARSE("ObjCPropertyAttributeOrder: ["
+  "class, direct, atomic, nonatomic, "
+  "assign, retain, strong, copy, weak, unsafe_unretained, "
+  "readonly, readwrite, getter, setter, "
+  "nullable, nonnull, null_resettable, null_unspecified"
+  "]",
+  ObjCPropertyAttributeOrder,
+  std::vector({
+  "class",
+  "direct",
+  "atomic",
+  "nonatomic",
+  "assign",
+  "retain",
+  "strong",
+  "copy",
+  "weak",
+  "unsafe_unretained",
+  "readonly",
+  "readwrite",
+  "getter",
+  "setter",
+  "nullable",
+  "nonnull",
+  "null_resettable",
+  "null_unspecified",
+  }));
+}
+
+TEST_F(ObjCPropertyAttributeOrderFixerTest, SortsSpecifiedAttributes) {
+  FormatStyle Style = getLLVMStyle();
+  Style.Language = FormatStyle::LK_ObjC;
+  Style.ObjCPropertyAttributeOrder = {"a", "b", "c"};
+
+  // Zero: nothing to do, but is legal.
+  verifyFormat("@property() int p;", Style);
+
+  // One: shouldn't move.
+  verifyFormat("@property(a) int p;", Style);
+  verifyFormat("@property(b) int p;", Style);
+  verifyFormat("@property(c) int p;", Style);
+
+  // Two in correct order already: no change.
+  verifyFormat("@property(a, b) int p;", Style);
+  verifyFormat("@property(a, c) int p;", Style);
+  verifyFormat("@property(b, c) int p;", Style);
+
+  // Three in correct order already: no change.
+  verifyFormat("@property(a, b, c) int p;", Style);
+
+  // Two wrong order.
+  verifyFormat("@property(a, b) int p;", "@property(b, a) int p;", Style);
+  verifyFormat("@property(a, c) int p;", "@property(c, a) int p;", Style);
+  verifyFormat("@property(b, c) int p;", "@property(c, b) int p;", Style);
+
+  // Three wrong order.
+  verifyFormat("@property(a, b, c) int p;", "@property(b, a, c) int p;", Style);
+  verifyFormat("@property(a, b, c) int p;", "@property(c, b, a) int p;", Style);
+
+  // Check that properties preceded by @optional/@requir

[clang] [analyzer][solver] On SymSym RelOps, check EQClass members for contradictions (PR #71284)

2023-11-05 Thread Gábor Horváth via cfe-commits

Xazax-hun wrote:

I think every time we need to iterate over all member of an equivalence class, 
we might do something wrong. The point of the equivalence class would be to 
make sure those elements are equivalent. One way to avoid iteration would be to 
always use the representative of the equivalence class. E.g., each time we 
record a new constraint to a member of the class, we add this information to 
the representative element. Every time we do a query, we first look up the 
representative element which already should have all the info from the class 
and use it instead of the original symbol.

Would something like this work or am I missing something?

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


[PATCH] D154396: [clang] Add support for SerenityOS

2023-11-05 Thread Andrew Kaster via Phabricator via cfe-commits
ADKaster added inline comments.



Comment at: clang/lib/Driver/ToolChains/Serenity.cpp:76
+  if (!IsStatic || IsStaticPIE)
+CmdArgs.push_back("--eh-frame-hdr");
+

MaskRay wrote:
> This is not tested
Hm. this also seems like incorrect logic. In my next push I will remove this 
condition around --eh-frame-hdr to match the other ToolChains.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154396/new/

https://reviews.llvm.org/D154396

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


[clang] [clang] Do not pass -canonical-system-headers on Windows by default (PR #71097)

2023-11-05 Thread Fangrui Song via cfe-commits


@@ -1180,8 +1180,19 @@ void Clang::AddPreprocessingOptions(Compilation &C, 
const JobAction &JA,
 if (ArgM->getOption().matches(options::OPT_M) ||
 ArgM->getOption().matches(options::OPT_MD))
   CmdArgs.push_back("-sys-header-deps");
+
+  // #70011: Canonicalization on Windows does unexpected things like change
+  // drive letters.
+  // FIXME: find and use Windows API that canonicalizes paths except for
+  // drive letter.
+#if defined(_WIN32) || defined(_WIN64)

MaskRay wrote:

`_WIN32` is defined on 64-bit Windows.

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


[clang] [clang] Do not pass -canonical-system-headers on Windows by default (PR #71097)

2023-11-05 Thread Fangrui Song via cfe-commits

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


[clang] [clang] Do not pass -canonical-system-headers on Windows by default (PR #71097)

2023-11-05 Thread Fangrui Song via cfe-commits

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


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


[clang] [clang] Do not pass -canonical-system-headers on Windows by default (PR #71097)

2023-11-05 Thread Fangrui Song via cfe-commits


@@ -1,3 +1,6 @@
+// REQUIRES: !system-windows

MaskRay wrote:

`UNSUPPORTED: system-windows`

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


[libcxx] [clang] [llvm] [libc] [clang-tools-extra] [compiler-rt] [flang] [libcxxabi] [lld] [libc++] Fix the behavior of throwing `operator new` under -fno-exceptions (PR #69498)

2023-11-05 Thread Louis Dionne via cfe-commits


@@ -0,0 +1,38 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___OVERRIDABLE_FUNCTION
+#define _LIBCPP___OVERRIDABLE_FUNCTION
+
+#include <__config>
+#include 
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#define _LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE   
\
+  
__attribute__((__section__("__TEXT,__lcxx_override,regular,pure_instructions")))

ldionne wrote:

I think I finally got this to work for ELF! The next revision will tell.

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


[libc] [libcxx] [clang] [libcxxabi] [llvm] [lld] [flang] [clang-tools-extra] [compiler-rt] [libc++] Fix the behavior of throwing `operator new` under -fno-exceptions (PR #69498)

2023-11-05 Thread Louis Dionne via cfe-commits

https://github.com/ldionne updated 
https://github.com/llvm/llvm-project/pull/69498

>From 77c0256c3ae99808a8def68bfcf5eee2fad704ca Mon Sep 17 00:00:00 2001
From: Louis Dionne 
Date: Wed, 14 Jun 2023 17:49:22 -0700
Subject: [PATCH 1/7] [libc++] Fix the behavior of throwing `operator new`
 under -fno-exceptions

In D144319, Clang tried to land a change that would cause some functions
that are not supposed to return nullptr to optimize better. As reported
in https://reviews.llvm.org/D144319#4203982, libc++ started seeing failures
in its CI shortly after this change was landed.

As explained in D146379, the reason for these failures is that libc++'s
throwing `operator new` can in fact return nullptr when compiled with
exceptions disabled. However, this contradicts the Standard, which
clearly says that the throwing version of `operator new(size_t)`
should never return nullptr. This is actually a long standing issue.
I've previously seen a case where LTO would optimize incorrectly based
on the assumption that `operator new` doesn't return nullptr, an
assumption that was violated in that case because libc++.dylib was
compiled with -fno-exceptions.

Unfortunately, fixing this is kind of tricky. The Standard has a few
requirements for the allocation functions, some of which are impossible
to satisfy under -fno-exceptions:
1. `operator new(size_t)` must never return nullptr
2. `operator new(size_t, nothrow_t)` must call the throwing version
 and return nullptr on failure to allocate
3. We can't throw exceptions when compiled with -fno-exceptions

In the case where exceptions are enabled, things work nicely. `new(size_t)`
throws and `new(size_t, nothrow_t)` uses a try-catch to return nullptr.
However, when compiling the library with -fno-exceptions, we can't throw
an exception from `new(size_t)`, and we can't catch anything from
`new(size_t, nothrow_t)`. The only thing we can do from `new(size_t)`
is actually abort the program, which does not make it possible for
`new(size_t, nothrow_t)` to catch something and return nullptr.

This patch makes the following changes:
1. When compiled with -fno-exceptions, the throwing version of
   `operator new` will now abort on failure instead of returning
   nullptr on failure. This resolves the issue that the compiler
   could mis-compile based on the assumption that nullptr is never
   returned. This constitutes an API and ABI breaking change for
   folks compiling the library with -fno-exceptions (which is not
   the general public, who merely uses libc++ headers but use a
   shared library that has already been compiled). This should mostly
   impact vendors and other folks who compile libc++.dylib themselves.

2. When the library is compiled with -fexceptions, the nothrow version
   of `operator new` has no change. When the library is compiled with
   -fno-exceptions, the nothrow version of `operator new` will now check
   whether the throwing version of `operator new` has been overridden.
   If it has not been overridden, then it will use an implementation
   equivalent to that of the throwing `operator new`, except it will
   return nullptr on failure to allocate (instead of terminating).
   However, if the throwing `operator new` has been overridden, it is
   now an error NOT to also override the nothrow `operator new`. Indeed,
   there is no way for us to implement a valid nothrow `operator new`
   without knowing the exact implementation of the throwing version.

rdar://103958777

Differential Revision: https://reviews.llvm.org/D150610
---
 libcxx/docs/ReleaseNotes/18.rst   | 23 +
 libcxx/include/CMakeLists.txt |  1 +
 libcxx/include/__overridable_function | 38 
 libcxx/include/new|  9 +-
 libcxx/src/new.cpp| 79 +++-
 ...new_not_overridden_fno_exceptions.pass.cpp | 56 
 .../new_dont_return_nullptr.pass.cpp  | 37 
 libcxx/test/support/check_assertion.h |  6 ++
 libcxxabi/src/stdlib_new_delete.cpp   | 90 ++-
 9 files changed, 291 insertions(+), 48 deletions(-)
 create mode 100644 libcxx/include/__overridable_function
 create mode 100644 
libcxx/test/libcxx/language.support/support.dynamic/assert.nothrow_new_not_overridden_fno_exceptions.pass.cpp
 create mode 100644 
libcxx/test/libcxx/language.support/support.dynamic/new_dont_return_nullptr.pass.cpp

diff --git a/libcxx/docs/ReleaseNotes/18.rst b/libcxx/docs/ReleaseNotes/18.rst
index ac78563aa73848f..bf017613a01b892 100644
--- a/libcxx/docs/ReleaseNotes/18.rst
+++ b/libcxx/docs/ReleaseNotes/18.rst
@@ -118,6 +118,29 @@ LLVM 20
 ABI Affecting Changes
 -
 
+- When the shared/static library is built with ``-fno-exceptions``, the 
behavior of ``operator new`` was changed
+  to make it standards-conforming. In LLVM 17 and before, the throwing 
versions of ``operator new`` would return
+  ``nullptr`` upon failure to allocate, when 

[libc] [libcxx] [clang] [libcxxabi] [llvm] [lld] [flang] [clang-tools-extra] [compiler-rt] [libc++] Fix the behavior of throwing `operator new` under -fno-exceptions (PR #69498)

2023-11-05 Thread Louis Dionne via cfe-commits

ldionne wrote:

> I think we can check whether it's been overridden more easily using an asm 
> alias like this (when libc++ is built under -fno-exceptions):

This doesn't work on Darwin (apparently we don't support the alias attribute on 
that platform). I could investigate doing this all non-Darwin platforms, 
however that would make the utility a lot less generic than in my latest patch, 
since I'd have to handle each function I want to check for overrides 
individually.


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


[clang] [clang] Allow MCTargetOptions to be parseable by -mllvm. (PR #66347)

2023-11-05 Thread Fangrui Song via cfe-commits

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

Agree that the motivation should be communicated. Driver options have stronger 
stability guarantee. If there are sufficient motivation and useful 
MCTargetOptions that we don't feel comfortable exposing driver options, I think 
this is probably fine.

We probably don't want to test every option. Just 2 or 3 suffices.

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


[clang] [libclang/python] Expose Rewriter to the libclang python binding. (PR #71341)

2023-11-05 Thread Jimmy Z via cfe-commits

https://github.com/jimmy-zx created 
https://github.com/llvm/llvm-project/pull/71341

Exposes `CXRewriter` API in 
https://github.com/llvm/llvm-project/commit/69e5abb57b70570cf04671a93246e5e624023650.

>From 887751e365ca72515679f61d0734b1631ac38335 Mon Sep 17 00:00:00 2001
From: Jimmy Z <51149050+jimmy...@users.noreply.github.com>
Date: Mon, 6 Nov 2023 00:25:39 +
Subject: [PATCH] [libclang/python] Expose Rewriter to the libclang python
 binding.

---
 clang/bindings/python/clang/cindex.py | 62 
 .../python/tests/cindex/test_rewrite.py   | 74 +++
 2 files changed, 136 insertions(+)
 create mode 100644 clang/bindings/python/tests/cindex/test_rewrite.py

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 6a16f3a9ef6e957..e51d558ab73fbce 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -3531,6 +3531,61 @@ def cursor(self):
 return cursor
 
 
+class Rewriter(ClangObject):
+"""
+The Rewriter is a wrapper class around clang::Rewriter
+
+It enables rewriting buffers.
+"""
+
+@staticmethod
+def create(tu):
+"""
+Creates a new Rewriter
+Parameters:
+tu -- The translation unit for the target AST.
+"""
+return Rewriter(conf.lib.clang_CXRewriter_create(tu))
+
+def __init__(self, ptr):
+ClangObject.__init__(self, ptr)
+
+def __del__(self):
+conf.lib.clang_CXRewriter_dispose(self)
+
+def insertTextBefore(self, loc, insert):
+"""
+Insert the specified string at the specified location in the original 
buffer.
+"""
+conf.lib.clang_CXRewriter_insertTextBefore(self, loc, insert)
+
+def replaceText(self, toBeReplaced, replacement):
+"""
+This method replaces a range of characters in the input buffer with a 
new string.
+"""
+conf.lib.clang_CXRewriter_replaceText(self, toBeReplaced, replacement)
+
+def removeText(self, toBeRemoved):
+"""
+Remove the specified text region.
+"""
+conf.lib.clang_CXRewriter_removeText(self, toBeRemoved)
+
+def overwriteChangedFiles(self):
+"""
+Save all changed files to disk.
+"""
+conf.lib.clang_CXRewriter_overwriteChangedFiles(self)
+
+def writeMainFileToStdOut(self):
+"""
+Writes the main file to stdout.
+"""
+conf.lib.clang_CXRewriter_writeMainFileToStdOut(self)
+
+
+
+
 # Now comes the plumbing to hook up the C library.
 
 # Register callback types in common container.
@@ -3596,6 +3651,13 @@ def cursor(self):
 ("clang_codeCompleteGetNumDiagnostics", [CodeCompletionResults], c_int),
 ("clang_createIndex", [c_int, c_int], c_object_p),
 ("clang_createTranslationUnit", [Index, c_interop_string], c_object_p),
+("clang_CXRewriter_create", [TranslationUnit], c_object_p),
+("clang_CXRewriter_dispose", [Rewriter]),
+("clang_CXRewriter_insertTextBefore", [Rewriter, SourceLocation, 
c_interop_string]),
+("clang_CXRewriter_overwriteChangedFiles", [Rewriter], c_int),
+("clang_CXRewriter_removeText", [Rewriter, SourceRange]),
+("clang_CXRewriter_replaceText", [Rewriter, SourceRange, 
c_interop_string]),
+("clang_CXRewriter_writeMainFileToStdOut", [Rewriter]),
 ("clang_CXXConstructor_isConvertingConstructor", [Cursor], bool),
 ("clang_CXXConstructor_isCopyConstructor", [Cursor], bool),
 ("clang_CXXConstructor_isDefaultConstructor", [Cursor], bool),
diff --git a/clang/bindings/python/tests/cindex/test_rewrite.py 
b/clang/bindings/python/tests/cindex/test_rewrite.py
new file mode 100644
index 000..eb697f72a923030
--- /dev/null
+++ b/clang/bindings/python/tests/cindex/test_rewrite.py
@@ -0,0 +1,74 @@
+import sys
+import io
+import unittest
+import tempfile
+
+from clang.cindex import Rewriter, TranslationUnit, Config, File, 
SourceLocation, SourceRange
+
+class TestRewrite(unittest.TestCase):
+code = '''
+int test1;
+
+void test2(void);
+
+int f(int c) {
+return c;
+}
+'''
+
+@classmethod
+def setUpClass(cls):
+Config.set_compatibility_check(False)
+
+def setUp(self):
+self.tmp = tempfile.NamedTemporaryFile(suffix='.cpp', buffering=0)
+self.tmp.write(TestRewrite.code.encode('utf-8'))
+self.tmp.flush()
+self.tu = TranslationUnit.from_source(self.tmp.name)
+self.rew = Rewriter.create(self.tu)
+self.file = File.from_name(self.tu, self.tmp.name)
+
+def tearDown(self):
+self.tmp.close()
+
+
+def test_insert(self):
+snip = '#include \n'
+
+beginning = SourceLocation.from_offset(self.tu, self.file, 0)
+self.rew.insertTextBefore(beginning, snip)
+self.rew.overwriteChangedFiles()
+
+with open(self.tmp.name, 'r', encoding='utf-8') as f:
+self.assertEqual(f.read(), snip + TestRewrite.code)
+
+
+  

[clang] [libclang/python] Expose Rewriter to the libclang python binding. (PR #71341)

2023-11-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jimmy Z (jimmy-zx)


Changes

Exposes `CXRewriter` API in 
https://github.com/llvm/llvm-project/commit/69e5abb57b70570cf04671a93246e5e624023650.

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


2 Files Affected:

- (modified) clang/bindings/python/clang/cindex.py (+62) 
- (added) clang/bindings/python/tests/cindex/test_rewrite.py (+74) 


``diff
diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 6a16f3a9ef6e957..e51d558ab73fbce 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -3531,6 +3531,61 @@ def cursor(self):
 return cursor
 
 
+class Rewriter(ClangObject):
+"""
+The Rewriter is a wrapper class around clang::Rewriter
+
+It enables rewriting buffers.
+"""
+
+@staticmethod
+def create(tu):
+"""
+Creates a new Rewriter
+Parameters:
+tu -- The translation unit for the target AST.
+"""
+return Rewriter(conf.lib.clang_CXRewriter_create(tu))
+
+def __init__(self, ptr):
+ClangObject.__init__(self, ptr)
+
+def __del__(self):
+conf.lib.clang_CXRewriter_dispose(self)
+
+def insertTextBefore(self, loc, insert):
+"""
+Insert the specified string at the specified location in the original 
buffer.
+"""
+conf.lib.clang_CXRewriter_insertTextBefore(self, loc, insert)
+
+def replaceText(self, toBeReplaced, replacement):
+"""
+This method replaces a range of characters in the input buffer with a 
new string.
+"""
+conf.lib.clang_CXRewriter_replaceText(self, toBeReplaced, replacement)
+
+def removeText(self, toBeRemoved):
+"""
+Remove the specified text region.
+"""
+conf.lib.clang_CXRewriter_removeText(self, toBeRemoved)
+
+def overwriteChangedFiles(self):
+"""
+Save all changed files to disk.
+"""
+conf.lib.clang_CXRewriter_overwriteChangedFiles(self)
+
+def writeMainFileToStdOut(self):
+"""
+Writes the main file to stdout.
+"""
+conf.lib.clang_CXRewriter_writeMainFileToStdOut(self)
+
+
+
+
 # Now comes the plumbing to hook up the C library.
 
 # Register callback types in common container.
@@ -3596,6 +3651,13 @@ def cursor(self):
 ("clang_codeCompleteGetNumDiagnostics", [CodeCompletionResults], c_int),
 ("clang_createIndex", [c_int, c_int], c_object_p),
 ("clang_createTranslationUnit", [Index, c_interop_string], c_object_p),
+("clang_CXRewriter_create", [TranslationUnit], c_object_p),
+("clang_CXRewriter_dispose", [Rewriter]),
+("clang_CXRewriter_insertTextBefore", [Rewriter, SourceLocation, 
c_interop_string]),
+("clang_CXRewriter_overwriteChangedFiles", [Rewriter], c_int),
+("clang_CXRewriter_removeText", [Rewriter, SourceRange]),
+("clang_CXRewriter_replaceText", [Rewriter, SourceRange, 
c_interop_string]),
+("clang_CXRewriter_writeMainFileToStdOut", [Rewriter]),
 ("clang_CXXConstructor_isConvertingConstructor", [Cursor], bool),
 ("clang_CXXConstructor_isCopyConstructor", [Cursor], bool),
 ("clang_CXXConstructor_isDefaultConstructor", [Cursor], bool),
diff --git a/clang/bindings/python/tests/cindex/test_rewrite.py 
b/clang/bindings/python/tests/cindex/test_rewrite.py
new file mode 100644
index 000..eb697f72a923030
--- /dev/null
+++ b/clang/bindings/python/tests/cindex/test_rewrite.py
@@ -0,0 +1,74 @@
+import sys
+import io
+import unittest
+import tempfile
+
+from clang.cindex import Rewriter, TranslationUnit, Config, File, 
SourceLocation, SourceRange
+
+class TestRewrite(unittest.TestCase):
+code = '''
+int test1;
+
+void test2(void);
+
+int f(int c) {
+return c;
+}
+'''
+
+@classmethod
+def setUpClass(cls):
+Config.set_compatibility_check(False)
+
+def setUp(self):
+self.tmp = tempfile.NamedTemporaryFile(suffix='.cpp', buffering=0)
+self.tmp.write(TestRewrite.code.encode('utf-8'))
+self.tmp.flush()
+self.tu = TranslationUnit.from_source(self.tmp.name)
+self.rew = Rewriter.create(self.tu)
+self.file = File.from_name(self.tu, self.tmp.name)
+
+def tearDown(self):
+self.tmp.close()
+
+
+def test_insert(self):
+snip = '#include \n'
+
+beginning = SourceLocation.from_offset(self.tu, self.file, 0)
+self.rew.insertTextBefore(beginning, snip)
+self.rew.overwriteChangedFiles()
+
+with open(self.tmp.name, 'r', encoding='utf-8') as f:
+self.assertEqual(f.read(), snip + TestRewrite.code)
+
+
+def test_replace(self):
+pattern = 'test2'
+replacement = 'func'
+
+offset = TestRewrite.code.find(pattern)
+pattern_range = SourceRange.from_locations(
+SourceLocation.from_offset(self.tu, self.file, offset),
+Source

[PATCH] D154396: [clang] Add support for SerenityOS

2023-11-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/Driver/ToolChains/Serenity.cpp:76
+  if (!IsStatic || IsStaticPIE)
+CmdArgs.push_back("--eh-frame-hdr");
+

ADKaster wrote:
> MaskRay wrote:
> > This is not tested
> Hm. this also seems like incorrect logic. In my next push I will remove this 
> condition around --eh-frame-hdr to match the other ToolChains.
https://maskray.me/blog/2020-11-08-stack-unwinding I have some notes on 
".eh_frame_hdr and PT_GNU_EH_FRAME". 

> Clang and GCC usually pass --eh-frame-hdr to ld, with the exception that gcc 
> -static does not pass --eh-frame-hdr. The difference is a historical choice 
> related to `__register_frame_info`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154396/new/

https://reviews.llvm.org/D154396

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


[clang] [libclang/python] Expose Rewriter to the libclang python binding. (PR #71341)

2023-11-05 Thread Jimmy Z via cfe-commits

https://github.com/jimmy-zx updated 
https://github.com/llvm/llvm-project/pull/71341

>From 887751e365ca72515679f61d0734b1631ac38335 Mon Sep 17 00:00:00 2001
From: Jimmy Z <51149050+jimmy...@users.noreply.github.com>
Date: Mon, 6 Nov 2023 00:25:39 +
Subject: [PATCH 1/2] [libclang/python] Expose Rewriter to the libclang python
 binding.

---
 clang/bindings/python/clang/cindex.py | 62 
 .../python/tests/cindex/test_rewrite.py   | 74 +++
 2 files changed, 136 insertions(+)
 create mode 100644 clang/bindings/python/tests/cindex/test_rewrite.py

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 6a16f3a9ef6e957..e51d558ab73fbce 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -3531,6 +3531,61 @@ def cursor(self):
 return cursor
 
 
+class Rewriter(ClangObject):
+"""
+The Rewriter is a wrapper class around clang::Rewriter
+
+It enables rewriting buffers.
+"""
+
+@staticmethod
+def create(tu):
+"""
+Creates a new Rewriter
+Parameters:
+tu -- The translation unit for the target AST.
+"""
+return Rewriter(conf.lib.clang_CXRewriter_create(tu))
+
+def __init__(self, ptr):
+ClangObject.__init__(self, ptr)
+
+def __del__(self):
+conf.lib.clang_CXRewriter_dispose(self)
+
+def insertTextBefore(self, loc, insert):
+"""
+Insert the specified string at the specified location in the original 
buffer.
+"""
+conf.lib.clang_CXRewriter_insertTextBefore(self, loc, insert)
+
+def replaceText(self, toBeReplaced, replacement):
+"""
+This method replaces a range of characters in the input buffer with a 
new string.
+"""
+conf.lib.clang_CXRewriter_replaceText(self, toBeReplaced, replacement)
+
+def removeText(self, toBeRemoved):
+"""
+Remove the specified text region.
+"""
+conf.lib.clang_CXRewriter_removeText(self, toBeRemoved)
+
+def overwriteChangedFiles(self):
+"""
+Save all changed files to disk.
+"""
+conf.lib.clang_CXRewriter_overwriteChangedFiles(self)
+
+def writeMainFileToStdOut(self):
+"""
+Writes the main file to stdout.
+"""
+conf.lib.clang_CXRewriter_writeMainFileToStdOut(self)
+
+
+
+
 # Now comes the plumbing to hook up the C library.
 
 # Register callback types in common container.
@@ -3596,6 +3651,13 @@ def cursor(self):
 ("clang_codeCompleteGetNumDiagnostics", [CodeCompletionResults], c_int),
 ("clang_createIndex", [c_int, c_int], c_object_p),
 ("clang_createTranslationUnit", [Index, c_interop_string], c_object_p),
+("clang_CXRewriter_create", [TranslationUnit], c_object_p),
+("clang_CXRewriter_dispose", [Rewriter]),
+("clang_CXRewriter_insertTextBefore", [Rewriter, SourceLocation, 
c_interop_string]),
+("clang_CXRewriter_overwriteChangedFiles", [Rewriter], c_int),
+("clang_CXRewriter_removeText", [Rewriter, SourceRange]),
+("clang_CXRewriter_replaceText", [Rewriter, SourceRange, 
c_interop_string]),
+("clang_CXRewriter_writeMainFileToStdOut", [Rewriter]),
 ("clang_CXXConstructor_isConvertingConstructor", [Cursor], bool),
 ("clang_CXXConstructor_isCopyConstructor", [Cursor], bool),
 ("clang_CXXConstructor_isDefaultConstructor", [Cursor], bool),
diff --git a/clang/bindings/python/tests/cindex/test_rewrite.py 
b/clang/bindings/python/tests/cindex/test_rewrite.py
new file mode 100644
index 000..eb697f72a923030
--- /dev/null
+++ b/clang/bindings/python/tests/cindex/test_rewrite.py
@@ -0,0 +1,74 @@
+import sys
+import io
+import unittest
+import tempfile
+
+from clang.cindex import Rewriter, TranslationUnit, Config, File, 
SourceLocation, SourceRange
+
+class TestRewrite(unittest.TestCase):
+code = '''
+int test1;
+
+void test2(void);
+
+int f(int c) {
+return c;
+}
+'''
+
+@classmethod
+def setUpClass(cls):
+Config.set_compatibility_check(False)
+
+def setUp(self):
+self.tmp = tempfile.NamedTemporaryFile(suffix='.cpp', buffering=0)
+self.tmp.write(TestRewrite.code.encode('utf-8'))
+self.tmp.flush()
+self.tu = TranslationUnit.from_source(self.tmp.name)
+self.rew = Rewriter.create(self.tu)
+self.file = File.from_name(self.tu, self.tmp.name)
+
+def tearDown(self):
+self.tmp.close()
+
+
+def test_insert(self):
+snip = '#include \n'
+
+beginning = SourceLocation.from_offset(self.tu, self.file, 0)
+self.rew.insertTextBefore(beginning, snip)
+self.rew.overwriteChangedFiles()
+
+with open(self.tmp.name, 'r', encoding='utf-8') as f:
+self.assertEqual(f.read(), snip + TestRewrite.code)
+
+
+def test_replace(self):
+pattern = 'test2'
+replacement = 'func'
+
+offset = TestRewri

[clang-tools-extra] [llvm] [libcxx] [clang] [libunwind] [libc++] Allow running the test suite with optimizations (PR #68753)

2023-11-05 Thread Louis Dionne via cfe-commits

https://github.com/ldionne updated 
https://github.com/llvm/llvm-project/pull/68753

>From 9824ef111975386152173916c1fd6a85264be0a0 Mon Sep 17 00:00:00 2001
From: Louis Dionne 
Date: Tue, 10 Oct 2023 16:35:11 -0700
Subject: [PATCH 1/5] [libc++] Allow running the test suite with optimizations

This patch adds a configuration of the libc++ test suite that enables
optimizations when building the tests. It also adds a new CI configuration
to exercise this on a regular basis. This is added in the context of [1],
which requires building with optimizations in order to hit the bug.

[1]: https://github.com/llvm/llvm-project/issues/68552
---
 libcxx/cmake/caches/Generic-optimized.cmake |  4 +++
 libcxx/utils/ci/buildkite-pipeline.yml  | 18 +
 libcxx/utils/ci/run-buildbot|  5 
 libcxx/utils/libcxx/test/params.py  | 28 -
 4 files changed, 54 insertions(+), 1 deletion(-)
 create mode 100644 libcxx/cmake/caches/Generic-optimized.cmake

diff --git a/libcxx/cmake/caches/Generic-optimized.cmake 
b/libcxx/cmake/caches/Generic-optimized.cmake
new file mode 100644
index 000..577a5de9f34c539
--- /dev/null
+++ b/libcxx/cmake/caches/Generic-optimized.cmake
@@ -0,0 +1,4 @@
+set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+set(LIBCXX_TEST_PARAMS "optimization=speed" CACHE STRING "")
+set(LIBCXXABI_TEST_PARAMS "${LIBCXX_TEST_PARAMS}" CACHE STRING "")
+set(LIBUNWIND_TEST_PARAMS "${LIBCXX_TEST_PARAMS}" CACHE STRING "")
diff --git a/libcxx/utils/ci/buildkite-pipeline.yml 
b/libcxx/utils/ci/buildkite-pipeline.yml
index ebfb35eee91e1ed..1b52d994081c46f 100644
--- a/libcxx/utils/ci/buildkite-pipeline.yml
+++ b/libcxx/utils/ci/buildkite-pipeline.yml
@@ -743,6 +743,24 @@ steps:
   limit: 2
 timeout_in_minutes: 120
 
+  - label: "Optimized build and test suite"
+command: "libcxx/utils/ci/run-buildbot generic-optimized"
+artifact_paths:
+  - "**/test-results.xml"
+  - "**/*.abilist"
+env:
+CC: "clang-${LLVM_HEAD_VERSION}"
+CXX: "clang++-${LLVM_HEAD_VERSION}"
+ENABLE_CLANG_TIDY: "On"
+agents:
+  queue: "libcxx-builders"
+  os: "linux"
+retry:
+  automatic:
+- exit_status: -1  # Agent was lost
+  limit: 2
+timeout_in_minutes: 120
+
   # Other non-testing CI jobs
   - label: "Benchmarks"
 command: "libcxx/utils/ci/run-buildbot benchmarks"
diff --git a/libcxx/utils/ci/run-buildbot b/libcxx/utils/ci/run-buildbot
index a71318123db3b12..18243b44a3d745c 100755
--- a/libcxx/utils/ci/run-buildbot
+++ b/libcxx/utils/ci/run-buildbot
@@ -479,6 +479,11 @@ generic-abi-unstable)
 generate-cmake -C 
"${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-abi-unstable.cmake"
 check-runtimes
 ;;
+generic-optimized)
+clean
+generate-cmake -C 
"${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-optimized.cmake"
+check-runtimes
+;;
 apple-system)
 clean
 
diff --git a/libcxx/utils/libcxx/test/params.py 
b/libcxx/utils/libcxx/test/params.py
index 456794b9b1cce95..9452f179aea3fec 100644
--- a/libcxx/utils/libcxx/test/params.py
+++ b/libcxx/utils/libcxx/test/params.py
@@ -11,7 +11,7 @@
 from pathlib import Path
 
 from libcxx.test.dsl import *
-from libcxx.test.features import _isMSVC
+from libcxx.test.features import _isClang, _isAppleClang, _isGCC, _isMSVC
 
 
 _warningFlags = [
@@ -90,6 +90,21 @@ def getStdFlag(cfg, std):
 return "-std=" + fallbacks[std]
 return None
 
+def getSpeedOptimizationFlag(cfg):
+if _isClang(cfg) or _isAppleClang(cfg) or _isGCC(cfg):
+return "-O3"
+elif _isMSVC(cfg):
+return "/O2"
+else:
+raise RuntimeError("Can't figure out what compiler is used in the 
configuration")
+
+def getSizeOptimizationFlag(cfg):
+if _isClang(cfg) or _isAppleClang(cfg) or _isGCC(cfg):
+return "-Os"
+elif _isMSVC(cfg):
+return "/O1"
+else:
+raise RuntimeError("Can't figure out what compiler is used in the 
configuration")
 
 # fmt: off
 DEFAULT_PARAMETERS = [
@@ -121,6 +136,17 @@ def getStdFlag(cfg, std):
 AddCompileFlag(lambda cfg: getStdFlag(cfg, std)),
 ],
 ),
+Parameter(
+name="optimization",
+choices=["none", "speed", "size"],
+type=str,
+help="The version of the standard to compile the test suite with.",
+default="none",
+actions=lambda opt: filter(None, [
+AddCompileFlag(lambda cfg: getSpeedOptimizationFlag(cfg)) if opt 
== "speed" else None,
+AddCompileFlag(lambda cfg: getSizeOptimizationFlag(cfg)) if opt == 
"size" else None,
+]),
+),
 Parameter(
 name="enable_modules",
 choices=["none", "clang", "clang-lsv"],

>From f799be39afed6b82d1942a87cea66a4d1192d765 Mon Sep 17 00:00:00 2001
From: Louis Dionne 
Date: Wed, 1 Nov 2023 10:56:30 -0400
Subject: [PATCH 2/5] Fix incorrect help

---
 libcxx/utils/libcxx/test/params.py | 2 +-
 1 file changed, 1 insertion(+

[clang] [libclang/python] Expose Rewriter to the libclang python binding. (PR #71341)

2023-11-05 Thread Jimmy Z via cfe-commits

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


  1   2   >