[PATCH] D135239: [clang] adds copy-assignable type-trait builtins

2022-10-04 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb created this revision.
cjdb added a reviewer: aaron.ballman.
Herald added a project: All.
cjdb requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

- `__is_copy_assignable`
- `__is_nothrow_copy_assignable`
- `__is_trivially_copy_assignable`

This is information that the compiler already has, and should be exposed
so that the library doesn't need to reimplement the exact same
functionality.

Similarly to `__is_copy_construcitble`, etc., these traits can't be
implemented using `__is_assignable`, etc., because we can't form
references to void, which are a fundamental part of copy assignment.

Depends on D135238 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135239

Files:
  clang/include/clang/Basic/TokenKinds.def
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/deprecated-builtins.cpp
  clang/test/SemaCXX/type-traits.cpp

Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -2865,6 +2865,675 @@
   static_assert(!__is_trivially_copy_constructible(void()), "");
 }
 
+struct MutableCopyAssign_QualNone {
+  MutableCopyAssign_QualNone =(MutableCopyAssign_QualNone &);
+};
+struct MutableCopyAssign_QualConst {
+  MutableCopyAssign_QualConst =(MutableCopyAssign_QualConst &) const;
+};
+struct MutableCopyAssign_QualVolatile {
+  MutableCopyAssign_QualVolatile =(MutableCopyAssign_QualVolatile &) volatile;
+};
+struct MutableCopyAssign_QualCV {
+  MutableCopyAssign_QualCV =(MutableCopyAssign_QualCV &) const volatile;
+};
+struct MutableCopyAssign_QualLvalue {
+  MutableCopyAssign_QualLvalue =(MutableCopyAssign_QualLvalue &) &;
+};
+struct MutableCopyAssign_QualConstLvalue {
+  MutableCopyAssign_QualConstLvalue =(MutableCopyAssign_QualConstLvalue &) const &;
+};
+struct MutableCopyAssign_QualVolatileLvalue {
+  MutableCopyAssign_QualVolatileLvalue =(MutableCopyAssign_QualVolatileLvalue &) volatile &;
+};
+struct MutableCopyAssign_QualCVLvalue {
+  MutableCopyAssign_QualCVLvalue =(MutableCopyAssign_QualCVLvalue &) const volatile &;
+};
+struct MutableCopyAssign_QualRvalue {
+  MutableCopyAssign_QualRvalue =(MutableCopyAssign_QualRvalue &) &&;
+};
+struct MutableCopyAssign_QualConstRvalue {
+  MutableCopyAssign_QualConstRvalue =(MutableCopyAssign_QualConstRvalue &) const &&;
+};
+struct MutableCopyAssign_QualVolatileRvalue {
+  MutableCopyAssign_QualVolatileRvalue =(MutableCopyAssign_QualVolatileRvalue &) volatile &&;
+};
+struct MutableCopyAssign_QualCVRvalue {
+  MutableCopyAssign_QualCVRvalue =(MutableCopyAssign_QualCVRvalue &) const volatile &&;
+};
+
+struct CopyAssign_QualNone {
+  CopyAssign_QualNone =(const CopyAssign_QualNone &);
+};
+struct CopyAssign_QualConst {
+  CopyAssign_QualConst =(const CopyAssign_QualConst &) const;
+};
+struct CopyAssign_QualVolatile {
+  CopyAssign_QualVolatile =(const CopyAssign_QualVolatile &) volatile;
+};
+struct CopyAssign_QualCV {
+  CopyAssign_QualCV =(const CopyAssign_QualCV &) const volatile;
+};
+struct CopyAssign_QualLvalue {
+  CopyAssign_QualLvalue =(const CopyAssign_QualLvalue &) &;
+};
+struct CopyAssign_QualConstLvalue {
+  CopyAssign_QualConstLvalue =(const CopyAssign_QualConstLvalue &) const &;
+};
+struct CopyAssign_QualVolatileLvalue {
+  CopyAssign_QualVolatileLvalue =(const CopyAssign_QualVolatileLvalue &) volatile &;
+};
+struct CopyAssign_QualCVLvalue {
+  CopyAssign_QualCVLvalue =(const CopyAssign_QualCVLvalue &) const volatile &;
+};
+struct CopyAssign_QualRvalue {
+  CopyAssign_QualRvalue =(const CopyAssign_QualRvalue &) &&;
+};
+struct CopyAssign_QualConstRvalue {
+  CopyAssign_QualConstRvalue =(const CopyAssign_QualConstRvalue &) const &&;
+};
+struct CopyAssign_QualVolatileRvalue {
+  CopyAssign_QualVolatileRvalue =(const CopyAssign_QualVolatileRvalue &) volatile &&;
+};
+struct CopyAssign_QualCVRvalue {
+  CopyAssign_QualCVRvalue =(const CopyAssign_QualCVRvalue &) const volatile &&;
+};
+
+struct VolatileCopyAssign_QualNone {
+  VolatileCopyAssign_QualNone =(volatile VolatileCopyAssign_QualNone &);
+};
+struct VolatileCopyAssign_QualConst {
+  VolatileCopyAssign_QualConst =(volatile VolatileCopyAssign_QualConst &) const;
+};
+struct VolatileCopyAssign_QualVolatile {
+  VolatileCopyAssign_QualVolatile =(volatile VolatileCopyAssign_QualVolatile &) volatile;
+};
+struct VolatileCopyAssign_QualCV {
+  VolatileCopyAssign_QualCV =(volatile VolatileCopyAssign_QualCV &) const volatile;
+};
+struct VolatileCopyAssign_QualLvalue {
+  VolatileCopyAssign_QualLvalue =(volatile VolatileCopyAssign_QualLvalue &) &;
+};
+struct VolatileCopyAssign_QualConstLvalue {
+  VolatileCopyAssign_QualConstLvalue =(volatile VolatileCopyAssign_QualConstLvalue &) const &;
+};
+struct VolatileCopyAssign_QualVolatileLvalue {
+  VolatileCopyAssign_QualVolatileLvalue 

[PATCH] D133289: [C2X] N3007 Type inference for object definitions

2022-10-04 Thread Guillot Tony via Phabricator via cfe-commits
to268 updated this revision to Diff 465280.
to268 added a comment.

Added a check to not diagnose a missing type specifier in C2x mode


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133289

Files:
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/DeclSpec.cpp
  clang/test/C/C2x/n3007.c
  clang/test/CodeGen/auto.c
  clang/test/Parser/c2x-auto.c
  clang/test/Sema/c2x-auto.c
  clang/www/c_status.html

Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -1184,7 +1184,7 @@
 
   Type inference for object declarations
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3007.htm;>N3007
-  No
+  Clang 16
 
 
   constexpr for object definitions
Index: clang/test/Sema/c2x-auto.c
===
--- /dev/null
+++ clang/test/Sema/c2x-auto.c
@@ -0,0 +1,52 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c2x %s
+
+void test_basic_types(void) {
+  auto undefined; // expected-error {{declaration of variable 'undefined' with deduced type 'auto' requires an initializer}}
+  auto auto_int = 4;
+  auto auto_long = 4UL;
+}
+
+void test_sizeof_typeof(void) {
+  auto auto_size = sizeof(auto);  // expected-error {{expected expression}}
+  typeof(auto) tpof = 4;  // expected-error {{expected expression}}
+}
+
+void test_casts(void) {
+  auto int_cast = (int)(4 + 3);
+  auto double_cast = (double)(1 / 3);
+  auto long_cast = (long)(4UL + 3UL);
+  auto auto_cast = (auto)(4 + 3); // expected-error {{expected expression}}
+}
+
+void test_compound_literral(void) {
+  auto int_cl = (int){13};
+  auto double_cl = (double){2.5};
+
+  // FIXME: This should be accepted per C2x 6.5.2.5p4
+  auto auto_cl = (auto){13};  // expected-error {{'auto' is not allowed in a compound literal}}
+  auto array[] = { 1, 2, 3 }; // expected-error {{'array' declared as array of 'auto'}}
+}
+
+void test_qualifiers(int x, const int y) {
+  const auto a = x;
+  auto b = y;
+  static auto c = 1UL;
+  int* pa =  // expected-warning {{initializing 'int *' with an expression of type 'const int *' discards qualifiers}}
+  const int* pb = 
+  int* pc =  // expected-warning {{incompatible pointer types initializing 'int *' with an expression of type 'unsigned long *'}}
+}
+
+void test_scopes(void) {
+  {
+auto a = 7;
+auto b = 9;
+auto c = a + b;
+  }
+  {
+auto d = a * b;   // expected-error {{use of undeclared identifier 'a'}} \
+ expected-error {{use of undeclared identifier 'b'}}
+{
+  auto e = d + c; // expected-error {{use of undeclared identifier 'c'}}
+}
+  }
+}
Index: clang/test/Parser/c2x-auto.c
===
--- /dev/null
+++ clang/test/Parser/c2x-auto.c
@@ -0,0 +1,123 @@
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,c2x -std=c2x %s
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,c17 -std=c17 %s
+
+#define AUTO_MACRO(_NAME, ARG, ARG2, ARG3) \
+  auto _NAME = ARG + (ARG2 / ARG3);
+
+struct S {
+int a;
+auto b;   // c2x-error {{'auto' not allowed in struct member}} \
+ c17-error {{type name does not allow storage class to be specified}} \
+ c17-error {{type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int}}
+union {
+  char c;
+  auto smth;  // c2x-error {{'auto' not allowed in union member}} \
+ c17-error {{type name does not allow storage class to be specified}} \
+ c17-error {{type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int}}
+} u;
+};
+
+enum E : auto { // c2x-error {{'auto' not allowed here}} \
+   c17-error {{expected a type}} \
+   c17-error {{type name does not allow storage class to be specified}}
+  One,
+  Two,
+  Tree,
+};
+
+auto basic_usage(auto auto) {   // c2x-error {{'auto' not allowed in function prototype}} \
+   c2x-error {{'auto' not allowed in function return type}} \
+   c2x-error {{cannot combine with previous 'auto' declaration specifier}} \
+   c17-error {{invalid storage class specifier in function declarator}} \
+   c17-error {{illegal storage class on function}} \
+   c17-warning {{duplicate 'auto' declaration specifier}} \
+   c17-warning {{omitting the parameter name in a function definition is a C2x extension}} \
+   c17-error {{type specifier missing, defaults to 'int'; ISO C99 and later do not support 

[PATCH] D135011: Add builtin_elementwise_sin and builtin_elementwise_cos

2022-10-04 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/docs/LanguageExtensions.rst:606
  T __builtin_elementwise_ceil(T x)   return the smallest integral 
value greater than or equal to xfloating point types
+ T __builtin_elementwise_cos(T x)return the ratio of the adjacent 
side length over thefloating point types
+ hypoteneuse side length, given 
the angle x in radians

This list doesn't appear to be in an overall alphabetical order. It looks more 
like its grouped by similarity. add_sat/sub_sat are together for example.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135011

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


[PATCH] D135011: Add builtin_elementwise_sin and builtin_elementwise_cos

2022-10-04 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/docs/LanguageExtensions.rst:607
+ T __builtin_elementwise_cos(T x)return the ratio of the adjacent 
side length over thefloating point types
+ hypoteneuse side length, given 
the angle x in radians
  T __builtin_elementwise_floor(T x)  return the largest integral value 
less than or equal to xfloating point types

hypotenuse*


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135011

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


[PATCH] D135011: Add builtin_elementwise_sin and builtin_elementwise_cos

2022-10-04 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

In D135011#3835553 , @bob80905 wrote:

> - add sve tests to prove compiler doesn't crash

Thank you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135011

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


[PATCH] D134699: [clang][Interp] Implement This pointer passing to methods

2022-10-04 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 465279.

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

https://reviews.llvm.org/D134699

Files:
  clang/lib/AST/Interp/ByteCodeEmitter.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/lib/AST/Interp/Disasm.cpp
  clang/lib/AST/Interp/EvalEmitter.cpp
  clang/lib/AST/Interp/Function.cpp
  clang/lib/AST/Interp/Function.h
  clang/lib/AST/Interp/Interp.cpp
  clang/lib/AST/Interp/InterpFrame.cpp
  clang/lib/AST/Interp/InterpFrame.h
  clang/test/AST/Interp/records.cpp

Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -102,3 +102,24 @@
   return 
 }
 static_assert(getPointer()->a == 100, "");
+
+constexpr C RVOAndParams(const C *c) {
+  return C();
+}
+constexpr C RVOAndParamsResult = RVOAndParams();
+
+constexpr int locals() {
+  C c;
+  c.a = 10;
+
+  // Assignment, not an initializer.
+  // c = C(); FIXME
+  c.a = 10;
+
+
+  // Assignment, not an initializer.
+  //c = RVOAndParams(); FIXME
+
+  return c.a;
+}
+static_assert(locals() == 10, "");
Index: clang/lib/AST/Interp/InterpFrame.h
===
--- clang/lib/AST/Interp/InterpFrame.h
+++ clang/lib/AST/Interp/InterpFrame.h
@@ -35,6 +35,11 @@
   InterpFrame(InterpState , Function *Func, InterpFrame *Caller,
   CodePtr RetPC, Pointer &);
 
+  /// Creates a new frame with the values that make sense.
+  /// I.e., the caller is the current frame of S,
+  /// and the This() pointer is the current Pointer on the top of S's stack,
+  InterpFrame(InterpState , Function *Func, CodePtr RetPC);
+
   /// Destroys the frame, killing all live pointers to stack slots.
   ~InterpFrame();
 
Index: clang/lib/AST/Interp/InterpFrame.cpp
===
--- clang/lib/AST/Interp/InterpFrame.cpp
+++ clang/lib/AST/Interp/InterpFrame.cpp
@@ -36,6 +36,36 @@
   }
 }
 
+InterpFrame::InterpFrame(InterpState , Function *Func, CodePtr RetPC)
+: Caller(S.Current), S(S), Func(Func), RetPC(RetPC),
+  ArgSize(Func ? Func->getArgSize() : 0),
+  Args(static_cast(S.Stk.top())), FrameOffset(S.Stk.size()) {
+  assert(Func);
+
+  // As per our calling convention, the this pointer is
+  // part of the ArgSize.
+  // If the function has RVO, the RVO pointer is first.
+  // If the fuction has a This pointer, that one is next.
+  // Then follow the actual arguments (but those are handled
+  // in getParamPointer()).
+  if (Func->hasThisPointer()) {
+if (Func->hasRVO())
+  This = stackRef(sizeof(Pointer));
+else
+  This = stackRef(0);
+  }
+
+  if (unsigned FrameSize = Func->getFrameSize()) {
+Locals = std::make_unique(FrameSize);
+for (auto  : Func->scopes()) {
+  for (auto  : Scope.locals()) {
+Block *B = new (localBlock(Local.Offset)) Block(Local.Desc);
+B->invokeCtor();
+  }
+}
+  }
+}
+
 InterpFrame::~InterpFrame() {
   if (Func && Func->isConstructor() && This.isBaseClass())
 This.initialize();
Index: clang/lib/AST/Interp/Interp.cpp
===
--- clang/lib/AST/Interp/Interp.cpp
+++ clang/lib/AST/Interp/Interp.cpp
@@ -55,8 +55,7 @@
 
 template ::T>
 static bool Call(InterpState , CodePtr , const Function *Func) {
-  S.Current =
-  new InterpFrame(S, const_cast(Func), S.Current, PC, {});
+  S.Current = new InterpFrame(S, const_cast(Func), PC);
   APValue CallResult;
   // Note that we cannot assert(CallResult.hasValue()) here since
   // Ret() above only sets the APValue if the curent frame doesn't
@@ -66,8 +65,7 @@
 
 static bool CallVoid(InterpState , CodePtr , const Function *Func) {
   APValue VoidResult;
-  S.Current =
-  new InterpFrame(S, const_cast(Func), S.Current, PC, {});
+  S.Current = new InterpFrame(S, const_cast(Func), PC);
   bool Success = Interpret(S, VoidResult);
   assert(VoidResult.isAbsent());
 
Index: clang/lib/AST/Interp/Function.h
===
--- clang/lib/AST/Interp/Function.h
+++ clang/lib/AST/Interp/Function.h
@@ -56,6 +56,21 @@
 ///
 /// Contains links to the bytecode of the function, as well as metadata
 /// describing all arguments and stack-local variables.
+///
+/// # Calling Convention
+///
+/// When calling a function, all argument values must be on the stack.
+///
+/// If the function has a This pointer (i.e. hasThisPointer() returns true,
+/// the argument values need to be preceeded by a Pointer for the This object.
+///
+/// If the function uses Return Value Optimization, the arguments (and
+/// potentially the This pointer) need to be proceeded by a Pointer pointing
+/// to the location to construct the returned value.
+///
+/// After the function has been called, it will 

[PATCH] D135238: [clang] adds copy-constructible type-trait builtins

2022-10-04 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb updated this revision to Diff 465278.
cjdb added a comment.

Restarts CI


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135238

Files:
  clang/include/clang/Basic/TokenKinds.def
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/deprecated-builtins.cpp
  clang/test/SemaCXX/type-traits.cpp

Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -1637,8 +1637,8 @@
 typedef const IntAr ConstIntAr;
 typedef ConstIntAr ConstIntArAr[4];
 
-struct HasCopy {
-  HasCopy(HasCopy& cp);
+struct HasMutableCopyCtor {
+  HasMutableCopyCtor(HasMutableCopyCtor );
 };
 
 struct HasMove {
@@ -1674,7 +1674,7 @@
   { int arr[F(__has_trivial_constructor(AnIncompleteType[]))]; } // expected-error {{incomplete type}}
   { int arr[F(__has_trivial_constructor(HasCons))]; }
   { int arr[F(__has_trivial_constructor(HasRef))]; }
-  { int arr[F(__has_trivial_constructor(HasCopy))]; }
+  { int arr[F(__has_trivial_constructor(HasMutableCopyCtor))]; }
   { int arr[F(__has_trivial_constructor(IntRef))]; }
   { int arr[F(__has_trivial_constructor(VirtAr))]; }
   { int arr[F(__has_trivial_constructor(void))]; }
@@ -1737,7 +1737,7 @@
   { int arr[T(__has_trivial_copy(ACompleteType[]))]; }
 
   { int arr[F(__has_trivial_copy(AnIncompleteType[]))]; } // expected-error {{incomplete type}}
-  { int arr[F(__has_trivial_copy(HasCopy))]; }
+  { int arr[F(__has_trivial_copy(HasMutableCopyCtor))]; }
   { int arr[F(__has_trivial_copy(HasTemplateCons))]; }
   { int arr[F(__has_trivial_copy(VirtAr))]; }
   { int arr[F(__has_trivial_copy(void))]; }
@@ -1757,7 +1757,7 @@
   { int arr[T(__has_trivial_assign(HasPriv))]; }
   { int arr[T(__has_trivial_assign(HasCons))]; }
   { int arr[T(__has_trivial_assign(HasRef))]; }
-  { int arr[T(__has_trivial_assign(HasCopy))]; }
+  { int arr[T(__has_trivial_assign(HasMutableCopyCtor))]; }
   { int arr[T(__has_trivial_assign(HasMove))]; }
   { int arr[T(__has_trivial_assign(HasMoveAssign))]; }
   { int arr[T(__has_trivial_assign(AllDefaulted))]; }
@@ -1791,7 +1791,7 @@
   { int arr[T(__has_trivial_destructor(HasPriv))]; }
   { int arr[T(__has_trivial_destructor(HasCons))]; }
   { int arr[T(__has_trivial_destructor(HasRef))]; }
-  { int arr[T(__has_trivial_destructor(HasCopy))]; }
+  { int arr[T(__has_trivial_destructor(HasMutableCopyCtor))]; }
   { int arr[T(__has_trivial_destructor(HasMove))]; }
   { int arr[T(__has_trivial_destructor(IntRef))]; }
   { int arr[T(__has_trivial_destructor(HasCopyAssign))]; }
@@ -1848,7 +1848,7 @@
   { int arr[T(__has_nothrow_assign(HasPriv))]; }
   { int arr[T(__has_nothrow_assign(HasCons))]; }
   { int arr[T(__has_nothrow_assign(HasRef))]; }
-  { int arr[T(__has_nothrow_assign(HasCopy))]; }
+  { int arr[T(__has_nothrow_assign(HasMutableCopyCtor))]; }
   { int arr[T(__has_nothrow_assign(HasMove))]; }
   { int arr[T(__has_nothrow_assign(HasMoveAssign))]; }
   { int arr[T(__has_nothrow_assign(HasNoThrowCopyAssign))]; }
@@ -1957,7 +1957,7 @@
   { int arr[T(__has_nothrow_copy(ACompleteType[]))]; }
 
   { int arr[F(__has_nothrow_copy(AnIncompleteType[]))]; } // expected-error {{incomplete type}}
-  { int arr[F(__has_nothrow_copy(HasCopy))]; }
+  { int arr[F(__has_nothrow_copy(HasMutableCopyCtor))]; }
   { int arr[F(__has_nothrow_copy(HasMultipleCopy))]; }
   { int arr[F(__has_nothrow_copy(VirtAr))]; }
   { int arr[F(__has_nothrow_copy(void))]; }
@@ -1987,7 +1987,7 @@
   { int arr[F(__has_nothrow_constructor(AnIncompleteType[]))]; } // expected-error {{incomplete type}}
   { int arr[F(__has_nothrow_constructor(HasCons))]; }
   { int arr[F(__has_nothrow_constructor(HasRef))]; }
-  { int arr[F(__has_nothrow_constructor(HasCopy))]; }
+  { int arr[F(__has_nothrow_constructor(HasMutableCopyCtor))]; }
   { int arr[F(__has_nothrow_constructor(HasMove))]; }
   { int arr[F(__has_nothrow_constructor(HasNoThrowConstructorWithArgs))]; }
   { int arr[F(__has_nothrow_constructor(IntRef))]; }
@@ -2014,7 +2014,7 @@
   { int arr[F(__has_virtual_destructor(HasPriv))]; }
   { int arr[F(__has_virtual_destructor(HasCons))]; }
   { int arr[F(__has_virtual_destructor(HasRef))]; }
-  { int arr[F(__has_virtual_destructor(HasCopy))]; }
+  { int arr[F(__has_virtual_destructor(HasMutableCopyCtor))]; }
   { int arr[F(__has_virtual_destructor(HasMove))]; }
   { int arr[F(__has_virtual_destructor(HasCopyAssign))]; }
   { int arr[F(__has_virtual_destructor(HasMoveAssign))]; }
@@ -2481,6 +2481,390 @@
   { int arr[F(__is_nothrow_constructible(const volatile void))]; }
 }
 
+struct VolatileCopyCtor {
+  VolatileCopyCtor(volatile VolatileCopyCtor &);
+};
+
+struct CVCopyCtor {
+  CVCopyCtor(const volatile CVCopyCtor &);
+};
+
+struct CopyCtorDeleted {
+  CopyCtorDeleted(const CopyCtorDeleted &) = delete;
+};
+
+struct 

[PATCH] D135177: [clang] adds `__is_scoped_enum`, `__is_nullptr`, and `__is_referenceable`

2022-10-04 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb updated this revision to Diff 465277.
cjdb edited the summary of this revision.
cjdb added a comment.

Updates the commit message so patch applications work


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135177

Files:
  clang/include/clang/Basic/TokenKinds.def
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/type-traits.cpp

Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -345,11 +345,19 @@
 }
 
 typedef Enum EnumType;
+typedef EnumClass EnumClassType;
 
 void is_enum()
 {
   { int arr[T(__is_enum(Enum))]; }
   { int arr[T(__is_enum(EnumType))]; }
+  { int arr[T(__is_enum(SignedEnum))]; }
+  { int arr[T(__is_enum(UnsignedEnum))]; }
+
+  { int arr[T(__is_enum(EnumClass))]; }
+  { int arr[T(__is_enum(EnumClassType))]; }
+  { int arr[T(__is_enum(SignedEnumClass))]; }
+  { int arr[T(__is_enum(UnsignedEnumClass))]; }
 
   { int arr[F(__is_enum(int))]; }
   { int arr[F(__is_enum(Union))]; }
@@ -363,6 +371,29 @@
   { int arr[F(__is_enum(HasAnonymousUnion))]; }
 }
 
+void is_scoped_enum() {
+  static_assert(!__is_scoped_enum(Enum), "");
+  static_assert(!__is_scoped_enum(EnumType), "");
+  static_assert(!__is_scoped_enum(SignedEnum), "");
+  static_assert(!__is_scoped_enum(UnsignedEnum), "");
+
+  static_assert(__is_scoped_enum(EnumClass), "");
+  static_assert(__is_scoped_enum(EnumClassType), "");
+  static_assert(__is_scoped_enum(SignedEnumClass), "");
+  static_assert(__is_scoped_enum(UnsignedEnumClass), "");
+
+  static_assert(!__is_scoped_enum(int), "");
+  static_assert(!__is_scoped_enum(Union), "");
+  static_assert(!__is_scoped_enum(Int), "");
+  static_assert(!__is_scoped_enum(IntAr), "");
+  static_assert(!__is_scoped_enum(UnionAr), "");
+  static_assert(!__is_scoped_enum(Derives), "");
+  static_assert(!__is_scoped_enum(ClassType), "");
+  static_assert(!__is_scoped_enum(cvoid), "");
+  static_assert(!__is_scoped_enum(IntArNB), "");
+  static_assert(!__is_scoped_enum(HasAnonymousUnion), "");
+}
+
 struct FinalClass final {
 };
 
@@ -766,6 +797,31 @@
   (void)__is_unbounded_array(decltype(t32)); // expected-error{{variable length arrays are not supported for '__is_unbounded_array'}}
 }
 
+void is_referenceable() {
+  static_assert(__is_referenceable(int), "");
+  static_assert(__is_referenceable(const int), "");
+  static_assert(__is_referenceable(volatile int), "");
+  static_assert(__is_referenceable(const volatile int), "");
+  static_assert(__is_referenceable(int *), "");
+  static_assert(__is_referenceable(int &), "");
+  static_assert(__is_referenceable(int &&), "");
+  static_assert(__is_referenceable(int (*)()), "");
+  static_assert(__is_referenceable(int (&)()), "");
+  static_assert(__is_referenceable(int(&&)()), "");
+  static_assert(__is_referenceable(IntAr), "");
+  static_assert(__is_referenceable(IntArNB), "");
+  static_assert(__is_referenceable(decltype(nullptr)), "");
+  static_assert(__is_referenceable(Empty), "");
+  static_assert(__is_referenceable(Union), "");
+  static_assert(__is_referenceable(Derives), "");
+  static_assert(__is_referenceable(Enum), "");
+  static_assert(__is_referenceable(EnumClass), "");
+  static_assert(__is_referenceable(int Empty::*), "");
+  static_assert(__is_referenceable(int(Empty::*)()), "");
+
+  { int a[F(__is_referenceable(void))]; }
+}
+
 template  void tmpl_func(T&) {}
 
 template  struct type_wrapper {
@@ -998,6 +1054,42 @@
   int t34[F(__is_pointer(void (StructWithMembers::*) ()))];
 }
 
+void is_null_pointer() {
+  StructWithMembers x;
+
+  static_assert(__is_nullptr(decltype(nullptr)), "");
+  static_assert(!__is_nullptr(void *), "");
+  static_assert(!__is_nullptr(cvoid *), "");
+  static_assert(!__is_nullptr(cvoid *), "");
+  static_assert(!__is_nullptr(char *), "");
+  static_assert(!__is_nullptr(int *), "");
+  static_assert(!__is_nullptr(int **), "");
+  static_assert(!__is_nullptr(ClassType *), "");
+  static_assert(!__is_nullptr(Derives *), "");
+  static_assert(!__is_nullptr(Enum *), "");
+  static_assert(!__is_nullptr(IntArNB *), "");
+  static_assert(!__is_nullptr(Union *), "");
+  static_assert(!__is_nullptr(UnionAr *), "");
+  static_assert(!__is_nullptr(StructWithMembers *), "");
+  static_assert(!__is_nullptr(void (*)()), "");
+
+  static_assert(!__is_nullptr(void), "");
+  static_assert(!__is_nullptr(cvoid), "");
+  static_assert(!__is_nullptr(cvoid), "");
+  static_assert(!__is_nullptr(char), "");
+  static_assert(!__is_nullptr(int), "");
+  static_assert(!__is_nullptr(int), "");
+  static_assert(!__is_nullptr(ClassType), "");
+  static_assert(!__is_nullptr(Derives), "");
+  static_assert(!__is_nullptr(Enum), "");
+  static_assert(!__is_nullptr(IntArNB), "");
+  static_assert(!__is_nullptr(Union), "");
+  

[PATCH] D135238: [clang] adds copy-constructible type-trait builtins

2022-10-04 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb created this revision.
Herald added a project: All.
cjdb requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

- `__is_copy_constructible`
- `__is_nothrow_copy_constructible`
- `__is_trivially_copy_constructible`

This is information that the compiler already has, and should be exposed
so that the library doesn't need to reimplement the exact same
functionality.

Unlike their default-constructible cousins, the copy-construcitble
traits can't be implemented using `__is_constructible`, etc., because we
can't form references to `void`, which are a fundamental part of copy
constructors.

This was originally a part of D116280 .

Depends on D135177 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135238

Files:
  clang/include/clang/Basic/TokenKinds.def
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/deprecated-builtins.cpp
  clang/test/SemaCXX/type-traits.cpp

Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -1637,8 +1637,8 @@
 typedef const IntAr ConstIntAr;
 typedef ConstIntAr ConstIntArAr[4];
 
-struct HasCopy {
-  HasCopy(HasCopy& cp);
+struct HasMutableCopyCtor {
+  HasMutableCopyCtor(HasMutableCopyCtor );
 };
 
 struct HasMove {
@@ -1674,7 +1674,7 @@
   { int arr[F(__has_trivial_constructor(AnIncompleteType[]))]; } // expected-error {{incomplete type}}
   { int arr[F(__has_trivial_constructor(HasCons))]; }
   { int arr[F(__has_trivial_constructor(HasRef))]; }
-  { int arr[F(__has_trivial_constructor(HasCopy))]; }
+  { int arr[F(__has_trivial_constructor(HasMutableCopyCtor))]; }
   { int arr[F(__has_trivial_constructor(IntRef))]; }
   { int arr[F(__has_trivial_constructor(VirtAr))]; }
   { int arr[F(__has_trivial_constructor(void))]; }
@@ -1737,7 +1737,7 @@
   { int arr[T(__has_trivial_copy(ACompleteType[]))]; }
 
   { int arr[F(__has_trivial_copy(AnIncompleteType[]))]; } // expected-error {{incomplete type}}
-  { int arr[F(__has_trivial_copy(HasCopy))]; }
+  { int arr[F(__has_trivial_copy(HasMutableCopyCtor))]; }
   { int arr[F(__has_trivial_copy(HasTemplateCons))]; }
   { int arr[F(__has_trivial_copy(VirtAr))]; }
   { int arr[F(__has_trivial_copy(void))]; }
@@ -1757,7 +1757,7 @@
   { int arr[T(__has_trivial_assign(HasPriv))]; }
   { int arr[T(__has_trivial_assign(HasCons))]; }
   { int arr[T(__has_trivial_assign(HasRef))]; }
-  { int arr[T(__has_trivial_assign(HasCopy))]; }
+  { int arr[T(__has_trivial_assign(HasMutableCopyCtor))]; }
   { int arr[T(__has_trivial_assign(HasMove))]; }
   { int arr[T(__has_trivial_assign(HasMoveAssign))]; }
   { int arr[T(__has_trivial_assign(AllDefaulted))]; }
@@ -1791,7 +1791,7 @@
   { int arr[T(__has_trivial_destructor(HasPriv))]; }
   { int arr[T(__has_trivial_destructor(HasCons))]; }
   { int arr[T(__has_trivial_destructor(HasRef))]; }
-  { int arr[T(__has_trivial_destructor(HasCopy))]; }
+  { int arr[T(__has_trivial_destructor(HasMutableCopyCtor))]; }
   { int arr[T(__has_trivial_destructor(HasMove))]; }
   { int arr[T(__has_trivial_destructor(IntRef))]; }
   { int arr[T(__has_trivial_destructor(HasCopyAssign))]; }
@@ -1848,7 +1848,7 @@
   { int arr[T(__has_nothrow_assign(HasPriv))]; }
   { int arr[T(__has_nothrow_assign(HasCons))]; }
   { int arr[T(__has_nothrow_assign(HasRef))]; }
-  { int arr[T(__has_nothrow_assign(HasCopy))]; }
+  { int arr[T(__has_nothrow_assign(HasMutableCopyCtor))]; }
   { int arr[T(__has_nothrow_assign(HasMove))]; }
   { int arr[T(__has_nothrow_assign(HasMoveAssign))]; }
   { int arr[T(__has_nothrow_assign(HasNoThrowCopyAssign))]; }
@@ -1957,7 +1957,7 @@
   { int arr[T(__has_nothrow_copy(ACompleteType[]))]; }
 
   { int arr[F(__has_nothrow_copy(AnIncompleteType[]))]; } // expected-error {{incomplete type}}
-  { int arr[F(__has_nothrow_copy(HasCopy))]; }
+  { int arr[F(__has_nothrow_copy(HasMutableCopyCtor))]; }
   { int arr[F(__has_nothrow_copy(HasMultipleCopy))]; }
   { int arr[F(__has_nothrow_copy(VirtAr))]; }
   { int arr[F(__has_nothrow_copy(void))]; }
@@ -1987,7 +1987,7 @@
   { int arr[F(__has_nothrow_constructor(AnIncompleteType[]))]; } // expected-error {{incomplete type}}
   { int arr[F(__has_nothrow_constructor(HasCons))]; }
   { int arr[F(__has_nothrow_constructor(HasRef))]; }
-  { int arr[F(__has_nothrow_constructor(HasCopy))]; }
+  { int arr[F(__has_nothrow_constructor(HasMutableCopyCtor))]; }
   { int arr[F(__has_nothrow_constructor(HasMove))]; }
   { int arr[F(__has_nothrow_constructor(HasNoThrowConstructorWithArgs))]; }
   { int arr[F(__has_nothrow_constructor(IntRef))]; }
@@ -2014,7 +2014,7 @@
   { int arr[F(__has_virtual_destructor(HasPriv))]; }
   { int arr[F(__has_virtual_destructor(HasCons))]; }
   { int arr[F(__has_virtual_destructor(HasRef))]; }
-  { int 

[PATCH] D135177: [clang] adds `__is_scoped_enum`, `__is_nullptr`, and `__is_referenceable`

2022-10-04 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb updated this revision to Diff 465273.
cjdb added a comment.

Replaces `T`/`F` with `static_assert` to match D116203 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135177

Files:
  clang/include/clang/Basic/TokenKinds.def
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/type-traits.cpp

Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -345,11 +345,19 @@
 }
 
 typedef Enum EnumType;
+typedef EnumClass EnumClassType;
 
 void is_enum()
 {
   { int arr[T(__is_enum(Enum))]; }
   { int arr[T(__is_enum(EnumType))]; }
+  { int arr[T(__is_enum(SignedEnum))]; }
+  { int arr[T(__is_enum(UnsignedEnum))]; }
+
+  { int arr[T(__is_enum(EnumClass))]; }
+  { int arr[T(__is_enum(EnumClassType))]; }
+  { int arr[T(__is_enum(SignedEnumClass))]; }
+  { int arr[T(__is_enum(UnsignedEnumClass))]; }
 
   { int arr[F(__is_enum(int))]; }
   { int arr[F(__is_enum(Union))]; }
@@ -363,6 +371,29 @@
   { int arr[F(__is_enum(HasAnonymousUnion))]; }
 }
 
+void is_scoped_enum() {
+  static_assert(!__is_scoped_enum(Enum), "");
+  static_assert(!__is_scoped_enum(EnumType), "");
+  static_assert(!__is_scoped_enum(SignedEnum), "");
+  static_assert(!__is_scoped_enum(UnsignedEnum), "");
+
+  static_assert(__is_scoped_enum(EnumClass), "");
+  static_assert(__is_scoped_enum(EnumClassType), "");
+  static_assert(__is_scoped_enum(SignedEnumClass), "");
+  static_assert(__is_scoped_enum(UnsignedEnumClass), "");
+
+  static_assert(!__is_scoped_enum(int), "");
+  static_assert(!__is_scoped_enum(Union), "");
+  static_assert(!__is_scoped_enum(Int), "");
+  static_assert(!__is_scoped_enum(IntAr), "");
+  static_assert(!__is_scoped_enum(UnionAr), "");
+  static_assert(!__is_scoped_enum(Derives), "");
+  static_assert(!__is_scoped_enum(ClassType), "");
+  static_assert(!__is_scoped_enum(cvoid), "");
+  static_assert(!__is_scoped_enum(IntArNB), "");
+  static_assert(!__is_scoped_enum(HasAnonymousUnion), "");
+}
+
 struct FinalClass final {
 };
 
@@ -766,6 +797,31 @@
   (void)__is_unbounded_array(decltype(t32)); // expected-error{{variable length arrays are not supported for '__is_unbounded_array'}}
 }
 
+void is_referenceable() {
+  static_assert(__is_referenceable(int), "");
+  static_assert(__is_referenceable(const int), "");
+  static_assert(__is_referenceable(volatile int), "");
+  static_assert(__is_referenceable(const volatile int), "");
+  static_assert(__is_referenceable(int *), "");
+  static_assert(__is_referenceable(int &), "");
+  static_assert(__is_referenceable(int &&), "");
+  static_assert(__is_referenceable(int (*)()), "");
+  static_assert(__is_referenceable(int (&)()), "");
+  static_assert(__is_referenceable(int(&&)()), "");
+  static_assert(__is_referenceable(IntAr), "");
+  static_assert(__is_referenceable(IntArNB), "");
+  static_assert(__is_referenceable(decltype(nullptr)), "");
+  static_assert(__is_referenceable(Empty), "");
+  static_assert(__is_referenceable(Union), "");
+  static_assert(__is_referenceable(Derives), "");
+  static_assert(__is_referenceable(Enum), "");
+  static_assert(__is_referenceable(EnumClass), "");
+  static_assert(__is_referenceable(int Empty::*), "");
+  static_assert(__is_referenceable(int(Empty::*)()), "");
+
+  { int a[F(__is_referenceable(void))]; }
+}
+
 template  void tmpl_func(T&) {}
 
 template  struct type_wrapper {
@@ -998,6 +1054,42 @@
   int t34[F(__is_pointer(void (StructWithMembers::*) ()))];
 }
 
+void is_null_pointer() {
+  StructWithMembers x;
+
+  static_assert(__is_nullptr(decltype(nullptr)), "");
+  static_assert(!__is_nullptr(void *), "");
+  static_assert(!__is_nullptr(cvoid *), "");
+  static_assert(!__is_nullptr(cvoid *), "");
+  static_assert(!__is_nullptr(char *), "");
+  static_assert(!__is_nullptr(int *), "");
+  static_assert(!__is_nullptr(int **), "");
+  static_assert(!__is_nullptr(ClassType *), "");
+  static_assert(!__is_nullptr(Derives *), "");
+  static_assert(!__is_nullptr(Enum *), "");
+  static_assert(!__is_nullptr(IntArNB *), "");
+  static_assert(!__is_nullptr(Union *), "");
+  static_assert(!__is_nullptr(UnionAr *), "");
+  static_assert(!__is_nullptr(StructWithMembers *), "");
+  static_assert(!__is_nullptr(void (*)()), "");
+
+  static_assert(!__is_nullptr(void), "");
+  static_assert(!__is_nullptr(cvoid), "");
+  static_assert(!__is_nullptr(cvoid), "");
+  static_assert(!__is_nullptr(char), "");
+  static_assert(!__is_nullptr(int), "");
+  static_assert(!__is_nullptr(int), "");
+  static_assert(!__is_nullptr(ClassType), "");
+  static_assert(!__is_nullptr(Derives), "");
+  static_assert(!__is_nullptr(Enum), "");
+  static_assert(!__is_nullptr(IntArNB), "");
+  static_assert(!__is_nullptr(Union), "");
+  

[PATCH] D135175: [clang] adds `__is_bounded_array` and `__is_unbounded_array` as builtins

2022-10-04 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb updated this revision to Diff 465272.
cjdb added a comment.

Changes `T`/`F` to `static_assert` to match D116203 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135175

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/TokenKinds.def
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/SemaCXX/type-traits.cpp

Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -702,6 +702,70 @@
   int t31[F(__is_array(cvoid*))];
 }
 
+void is_bounded_array(int n) {
+  static_assert(__is_bounded_array(IntAr), "");
+  static_assert(!__is_bounded_array(IntArNB), "");
+  static_assert(__is_bounded_array(UnionAr), "");
+
+  static_assert(!__is_bounded_array(void), "");
+  static_assert(!__is_bounded_array(cvoid), "");
+  static_assert(!__is_bounded_array(float), "");
+  static_assert(!__is_bounded_array(double), "");
+  static_assert(!__is_bounded_array(long double), "");
+  static_assert(!__is_bounded_array(bool), "");
+  static_assert(!__is_bounded_array(char), "");
+  static_assert(!__is_bounded_array(signed char), "");
+  static_assert(!__is_bounded_array(unsigned char), "");
+  static_assert(!__is_bounded_array(wchar_t), "");
+  static_assert(!__is_bounded_array(short), "");
+  static_assert(!__is_bounded_array(unsigned short), "");
+  static_assert(!__is_bounded_array(int), "");
+  static_assert(!__is_bounded_array(unsigned int), "");
+  static_assert(!__is_bounded_array(long), "");
+  static_assert(!__is_bounded_array(unsigned long), "");
+  static_assert(!__is_bounded_array(Union), "");
+  static_assert(!__is_bounded_array(Derives), "");
+  static_assert(!__is_bounded_array(ClassType), "");
+  static_assert(!__is_bounded_array(Enum), "");
+  static_assert(!__is_bounded_array(void *), "");
+  static_assert(!__is_bounded_array(cvoid *), "");
+
+  int t32[n];
+  (void)__is_bounded_array(decltype(t32)); // expected-error{{variable length arrays are not supported for '__is_bounded_array'}}
+}
+
+void is_unbounded_array(int n) {
+  static_assert(!__is_unbounded_array(IntAr), "");
+  static_assert(__is_unbounded_array(IntArNB), "");
+  static_assert(!__is_unbounded_array(UnionAr), "");
+
+  static_assert(!__is_unbounded_array(void), "");
+  static_assert(!__is_unbounded_array(cvoid), "");
+  static_assert(!__is_unbounded_array(float), "");
+  static_assert(!__is_unbounded_array(double), "");
+  static_assert(!__is_unbounded_array(long double), "");
+  static_assert(!__is_unbounded_array(bool), "");
+  static_assert(!__is_unbounded_array(char), "");
+  static_assert(!__is_unbounded_array(signed char), "");
+  static_assert(!__is_unbounded_array(unsigned char), "");
+  static_assert(!__is_unbounded_array(wchar_t), "");
+  static_assert(!__is_unbounded_array(short), "");
+  static_assert(!__is_unbounded_array(unsigned short), "");
+  static_assert(!__is_unbounded_array(int), "");
+  static_assert(!__is_unbounded_array(unsigned int), "");
+  static_assert(!__is_unbounded_array(long), "");
+  static_assert(!__is_unbounded_array(unsigned long), "");
+  static_assert(!__is_unbounded_array(Union), "");
+  static_assert(!__is_unbounded_array(Derives), "");
+  static_assert(!__is_unbounded_array(ClassType), "");
+  static_assert(!__is_unbounded_array(Enum), "");
+  static_assert(!__is_unbounded_array(void *), "");
+  static_assert(!__is_unbounded_array(cvoid *), "");
+
+  int t32[n];
+  (void)__is_unbounded_array(decltype(t32)); // expected-error{{variable length arrays are not supported for '__is_unbounded_array'}}
+}
+
 template  void tmpl_func(T&) {}
 
 template  struct type_wrapper {
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2627,12 +2627,10 @@
 
   if (T->isVariableArrayType() && !Context.getTargetInfo().isVLASupported()) {
 // CUDA device code and some other targets don't support VLAs.
-targetDiag(Loc, (getLangOpts().CUDA && getLangOpts().CUDAIsDevice)
-? diag::err_cuda_vla
-: diag::err_vla_unsupported)
-<< ((getLangOpts().CUDA && getLangOpts().CUDAIsDevice)
-? CurrentCUDATarget()
-: CFT_InvalidTarget);
+bool IsCUDADevice = (getLangOpts().CUDA && getLangOpts().CUDAIsDevice);
+targetDiag(Loc,
+   IsCUDADevice ? diag::err_cuda_vla : diag::err_vla_unsupported)
+<< (IsCUDADevice ? CurrentCUDATarget() : 0);
   }
 
   // If this is not C99, diagnose array size modifiers on non-VLAs.
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- 

[PATCH] D135025: [clang][Interp] Support base class constructors

2022-10-04 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 465271.

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

https://reviews.llvm.org/D135025

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/test/AST/Interp/records.cpp

Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -1,9 +1,6 @@
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
 // RUN: %clang_cc1 -verify=ref %s
 
-// ref-no-diagnostics
-// expected-no-diagnostics
-
 struct BoolPair {
   bool first;
   bool second;
@@ -157,3 +154,57 @@
 static_assert(LT2.v[0].second == false, "");
 static_assert(LT2.v[2].first == true, "");
 static_assert(LT2.v[2].second == false, "");
+
+class Base {
+public:
+  int i;
+  constexpr Base() : i(10) {}
+  constexpr Base(int i) : i(i) {}
+};
+
+class A : public Base {
+public:
+  constexpr A() : Base(100) {}
+  constexpr A(int a) : Base(a) {}
+};
+constexpr A a{};
+static_assert(a.i == 100, "");
+constexpr A a2{12};
+static_assert(a2.i == 12, "");
+static_assert(a2.i == 200, ""); // ref-error {{static assertion failed}} \
+// ref-note {{evaluates to '12 == 200'}} \
+// expected-error {{static assertion failed}} \
+// expected-note {{evaluates to '12 == 200'}}
+
+namespace MI {
+  class A {
+  public:
+int a;
+constexpr A(int a) : a(a) {}
+  };
+
+  class B {
+  public:
+int b;
+constexpr B(int b) : b(b) {}
+  };
+
+  class C : public A, public B {
+  public:
+constexpr C() : A(10), B(20) {}
+  };
+  constexpr C c = {};
+  static_assert(c.a == 10);
+  static_assert(c.b == 20);
+
+
+  class D : private A, private B {
+public:
+constexpr D() : A(20), B(30) {}
+constexpr int getA() const { return a; }
+constexpr int getB() const { return b; }
+  };
+  constexpr D d = {};
+  static_assert(d.getA() == 20);
+  static_assert(d.getB() == 30);
+};
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -100,31 +100,45 @@
 const Record *R = this->getRecord(RD);
 
 for (const auto *Init : Ctor->inits()) {
-  const FieldDecl *Member = Init->getMember();
   const Expr *InitExpr = Init->getInit();
-  const Record::Field *F = R->getField(Member);
-
-  if (Optional T = this->classify(InitExpr->getType())) {
-if (!this->emitThis(InitExpr))
-  return false;
-
-if (!this->visit(InitExpr))
-  return false;
-
-if (!this->emitInitField(*T, F->Offset, InitExpr))
+  if (const FieldDecl *Member = Init->getMember()) {
+const Record::Field *F = R->getField(Member);
+
+if (Optional T = this->classify(InitExpr->getType())) {
+  if (!this->emitThis(InitExpr))
+return false;
+
+  if (!this->visit(InitExpr))
+return false;
+
+  if (!this->emitInitField(*T, F->Offset, InitExpr))
+return false;
+} else {
+  // Non-primitive case. Get a pointer to the field-to-initialize
+  // on the stack and call visitInitialzer() for it.
+  if (!this->emitThis(InitExpr))
+return false;
+
+  if (!this->emitGetPtrField(F->Offset, InitExpr))
+return false;
+
+  if (!this->visitInitializer(InitExpr))
+return false;
+
+  if (!this->emitPopPtr(InitExpr))
+return false;
+}
+  } else if (const Type *Base = Init->getBaseClass()) {
+// Base class initializer.
+// Get This Base and call initializer on it.
+auto *BaseDecl = Base->getAsCXXRecordDecl();
+assert(BaseDecl);
+const Record::Base *B = R->getBase(BaseDecl);
+assert(B);
+if (!this->emitGetPtrThisBase(B->Offset, InitExpr))
   return false;
-  } else {
-// Non-primitive case. Get a pointer to the field-to-initialize
-// on the stack and call visitInitialzer() for it.
-if (!this->emitThis(InitExpr))
-  return false;
-
-if (!this->emitGetPtrField(F->Offset, InitExpr))
-  return false;
-
 if (!this->visitInitializer(InitExpr))
   return false;
-
 if (!this->emitPopPtr(InitExpr))
   return false;
   }
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -253,6 +253,15 @@
 return (*InitFn)();
   }
 
+  /// Returns the CXXRecordDecl for the type of the given expression,
+  /// or nullptr if no such decl exists.
+  const CXXRecordDecl * 

[PATCH] D134546: [clang-offload-bundler] extracting compatible bundle entry

2022-10-04 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 465265.
yaxunl marked an inline comment as done.
yaxunl added a comment.

check bundle entry ID compatibility when bundling


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

https://reviews.llvm.org/D134546

Files:
  clang/include/clang/Basic/TargetID.h
  clang/include/clang/Driver/OffloadBundler.h
  clang/lib/Basic/TargetID.cpp
  clang/lib/Driver/OffloadBundler.cpp
  clang/test/Driver/clang-offload-bundler.c
  clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp

Index: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
===
--- clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
+++ clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
@@ -13,6 +13,7 @@
 //===--===//
 
 #include "clang/Basic/Cuda.h"
+#include "clang/Basic/TargetID.h"
 #include "clang/Basic/Version.h"
 #include "clang/Driver/OffloadBundler.h"
 #include "llvm/ADT/ArrayRef.h"
@@ -46,6 +47,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -309,6 +311,8 @@
   unsigned HostTargetNum = 0u;
   bool HIPOnly = true;
   llvm::DenseSet ParsedTargets;
+  // Map {offload-kind}-{triple} to target IDs.
+  std::map> TargetIDs;
   for (StringRef Target : TargetNames) {
 if (ParsedTargets.contains(Target)) {
   reportError(createStringError(errc::invalid_argument,
@@ -331,6 +335,8 @@
   reportError(createStringError(errc::invalid_argument, Msg.str()));
 }
 
+TargetIDs[OffloadInfo.OffloadKind.str() + "-" + OffloadInfo.Triple.str()]
+.insert(OffloadInfo.TargetID);
 if (KindIsValid && OffloadInfo.hasHostKind()) {
   ++HostTargetNum;
   // Save the index of the input that refers to the host.
@@ -342,6 +348,17 @@
 
 ++Index;
   }
+  for (const auto  : TargetIDs) {
+if (auto ConflictingTID =
+clang::getConflictTargetIDCombination(TargetID.second)) {
+  SmallVector Buf;
+  raw_svector_ostream Msg(Buf);
+  Msg << "Cannot bundle inputs with conflicting targets: '"
+  << TargetID.first + "-" + ConflictingTID->first << "' and '"
+  << TargetID.first + "-" + ConflictingTID->second << "'";
+  reportError(createStringError(errc::invalid_argument, Msg.str()));
+}
+  }
 
   // HIP uses clang-offload-bundler to bundle device-only compilation results
   // for multiple GPU archs, therefore allow no host target if all entries
Index: clang/test/Driver/clang-offload-bundler.c
===
--- clang/test/Driver/clang-offload-bundler.c
+++ clang/test/Driver/clang-offload-bundler.c
@@ -224,7 +224,7 @@
 // RUN: diff %t.empty %t.res.tgt2
 
 // Check that bindler prints an error if given host bundle does not exist in the fat binary.
-// RUN: not clang-offload-bundler -type=s -targets=host-x86_64-xxx-linux-gnu,openmp-powerpc64le-ibm-linux-gnu -output=%t.res.s -output=%t.res.tgt1 -input=%t.bundle3.s -unbundle -allow-missing-bundles 2>&1 | FileCheck %s --check-prefix CK-NO-HOST-BUNDLE
+// RUN: not clang-offload-bundler -type=s -targets=host-amdgcn-xxx-linux-gnu,openmp-powerpc64le-ibm-linux-gnu -output=%t.res.s -output=%t.res.tgt1 -input=%t.bundle3.s -unbundle -allow-missing-bundles 2>&1 | FileCheck %s --check-prefix CK-NO-HOST-BUNDLE
 // CK-NO-HOST-BUNDLE: error: Can't find bundle for the host target
 
 //
@@ -432,6 +432,41 @@
 // NOHOST-NOT: host-
 // NOHOST-DAG: hip-amdgcn-amd-amdhsa--gfx900
 // NOHOST-DAG: hip-amdgcn-amd-amdhsa--gfx906
+
+//
+// Check bundling ID compatibility for HIP.
+//
+// RUN: clang-offload-bundler -type=bc -targets=hip-amdgcn-amd-amdhsa--gfx906:xnack- \
+// RUN:   -targets=hip-amdgcn-amd-amdhsa--gfx906:xnack+ \
+// RUN:   -input=%t.tgt1 -input=%t.tgt2 -output=%t.hip.bundle.bc
+// RUN: not clang-offload-bundler -type=bc -targets=hip-amdgcn-amd-amdhsa--gfx906 \
+// RUN:   -targets=hip-amdgcn-amd-amdhsa--gfx906:xnack+ \
+// RUN:   -input=%t.tgt1 -input=%t.tgt2 -output=%t.hip.bundle.bc 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=CONFLICT-TID
+// CONFLICT-TID: error: Cannot bundle inputs with conflicting targets: 'hip-amdgcn-amd-amdhsa--gfx906' and 'hip-amdgcn-amd-amdhsa--gfx906:xnack+'
+
+//
+// Check extracting bundle entry with compatible target ID for HIP.
+//
+// RUN: clang-offload-bundler -type=bc -targets=hip-amdgcn-amd-amdhsa--gfx906 \
+// RUN:   -input=%t.tgt1 -output=%t.hip.bundle.bc
+// RUN: clang-offload-bundler -type=bc -targets=hip-amdgcn-amd-amdhsa--gfx906:xnack- \
+// RUN:   -output=%t.res.tgt1 -input=%t.hip.bundle.bc -unbundle
+// RUN: diff %t.tgt1 %t.res.tgt1
+// RUN: clang-offload-bundler -type=bc -targets=hip-amdgcn-amd-amdhsa--gfx906:xnack+ \
+// RUN:   -output=%t.res.tgt1 -input=%t.hip.bundle.bc -unbundle
+// RUN: diff %t.tgt1 %t.res.tgt1
+
+// RUN: clang-offload-bundler -type=bc -targets=hip-amdgcn-amd-amdhsa--gfx906:xnack+ \
+// RUN:   -input=%t.tgt1 

[PATCH] D134546: [clang-offload-bundler] extracting compatible bundle entry

2022-10-04 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked 3 inline comments as done.
yaxunl added inline comments.



Comment at: clang/lib/Driver/OffloadBundler.cpp:1008
+auto Output = Worklist.begin();
+for (auto E = Worklist.end(); Output != E; Output++) {
+  if (isCodeObjectCompatible(

tra wrote:
> saiislam wrote:
> > tra wrote:
> > > The patch description implies that there are at least two classes of 
> > > compatible objects -- the ones that match exactly and the ones that are 
> > > not exact match, but are still compatible.
> > > 
> > > 
> > > Here we're iterating until we find the first compatible object. What if 
> > > we also have the object that matches exactly, but it's further down the 
> > > list. Is that a problem that we may pick one or the other, depending on 
> > > the order they happen to appear in the worklist? It would be good to add 
> > > a test case for this scenario.
> > Though it looks plausible, such a case is not possible.
> >  
> > From [[ 
> > https://clang.llvm.org/docs/ClangOffloadBundler.html#bundle-entry-id | 
> > Clang Offload Bundler's Documentation]]
> > > If there is an entry with a target feature specified as Any, then all 
> > > entries must specify that target feature as Any for the same processor.
> > 
> > 
> Does it mean that the bundler is supposed to error out if  I pass 
> `-targets=hip-amdgcn-amd-amdhsa--gfx906,hip-amdgcn-amd-amdhsa--gfx906:xnack-` 
> ?
> 
> I've just tried it with a bundler built in recent LLVM tree and it accepts 
> such a mis of targets without complaining. 
> 
> 
Bundle entries in the same bundle should follow the constraints specified in 
the clang-offload-bundler documentation.

Currently, clang enforces the rule when specifying `--offload-arch` options, 
which is the most common approach to generate the clang-offload-bundler 
bundles. However, if users use clang-offload-bundler directly to generate the 
bundle, the rule is not enforced.

I will add the enforcement to clang-offload-bundler too.


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

https://reviews.llvm.org/D134546

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


[PATCH] D135155: [AMDGPU] Annotate the intrinsics to be default and nocallback

2022-10-04 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm accepted this revision.
arsenm added inline comments.
This revision is now accepted and ready to land.



Comment at: llvm/include/llvm/IR/IntrinsicsAMDGPU.td:1226
 
 def int_amdgcn_raw_tbuffer_store : Intrinsic <
 [],

Default



Comment at: llvm/include/llvm/IR/IntrinsicsAMDGPU.td:1241
 
 def int_amdgcn_struct_tbuffer_load : Intrinsic <
 [llvm_any_ty],// overloaded for types f32/i32, v2f32/v2i32, v4f32/v4i32

Default 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135155

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


[PATCH] D135155: [AMDGPU] Annotate the intrinsics to be default and nocallback

2022-10-04 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert updated this revision to Diff 465262.
jdoerfert marked 6 inline comments as done.
jdoerfert added a comment.

Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135155

Files:
  clang/test/CodeGenOpenCL/builtins-amdgcn.cl
  llvm/include/llvm/IR/Intrinsics.td
  llvm/include/llvm/IR/IntrinsicsAMDGPU.td
  llvm/test/Bitcode/compatibility-3.6.ll
  llvm/test/Bitcode/compatibility-3.7.ll
  llvm/test/Bitcode/compatibility-3.8.ll
  llvm/test/Bitcode/compatibility-3.9.ll
  llvm/test/Bitcode/compatibility-4.0.ll
  llvm/test/Bitcode/compatibility-5.0.ll
  llvm/test/Bitcode/compatibility-6.0.ll
  llvm/test/Bitcode/compatibility.ll
  llvm/test/CodeGen/AMDGPU/annotate-kernel-features-hsa-call.ll
  llvm/test/CodeGen/AMDGPU/annotate-kernel-features-hsa.ll
  llvm/test/CodeGen/AMDGPU/annotate-kernel-features.ll
  llvm/test/CodeGen/AMDGPU/pal-simple-indirect-call.ll
  llvm/test/Transforms/Inline/AMDGPU/amdgpu-inline-alloca-argument.ll
  llvm/test/Transforms/OpenMP/barrier_removal.ll

Index: llvm/test/Transforms/OpenMP/barrier_removal.ll
===
--- llvm/test/Transforms/OpenMP/barrier_removal.ll
+++ llvm/test/Transforms/OpenMP/barrier_removal.ll
@@ -249,7 +249,8 @@
 ;.
 ; CHECK: attributes #[[ATTR0:[0-9]+]] = { "llvm.assume"="ompx_aligned_barrier" }
 ; CHECK: attributes #[[ATTR1:[0-9]+]] = { convergent nocallback nounwind }
-; CHECK: attributes #[[ATTR2:[0-9]+]] = { convergent nounwind willreturn }
+; CHECK: attributes #[[ATTR2:[0-9]+]] = { convergent nocallback nounwind willreturn }
+; CHECK: attributes #[[ATTR3:[0-9]+]] = { inaccessiblememonly nocallback nofree nosync nounwind willreturn }
 ;.
 ; CHECK: [[META0:![0-9]+]] = !{i32 7, !"openmp", i32 50}
 ; CHECK: [[META1:![0-9]+]] = !{i32 7, !"openmp-device", i32 50}
Index: llvm/test/Transforms/Inline/AMDGPU/amdgpu-inline-alloca-argument.ll
===
--- llvm/test/Transforms/Inline/AMDGPU/amdgpu-inline-alloca-argument.ll
+++ llvm/test/Transforms/Inline/AMDGPU/amdgpu-inline-alloca-argument.ll
@@ -45,8 +45,7 @@
 ; addrspacecasted' alloca.
 ; CHECK-LABEL: @test_inliner_flat_ptr(
 ; CHECK: call i32 @llvm.amdgcn.workitem.id.x()
-; CHECK-NOT: call
-; CHECK-NOT: call
+; CHECK-NOT: call [[.*]]@
 define amdgpu_kernel void @test_inliner_flat_ptr(float addrspace(1)* nocapture %a, i32 %n) {
 entry:
   %pvt_arr = alloca [64 x float], align 4, addrspace(5)
Index: llvm/test/CodeGen/AMDGPU/pal-simple-indirect-call.ll
===
--- llvm/test/CodeGen/AMDGPU/pal-simple-indirect-call.ll
+++ llvm/test/CodeGen/AMDGPU/pal-simple-indirect-call.ll
@@ -40,7 +40,6 @@
 ; GFX9-NEXT:s_mov_b64 s[2:3], s[10:11]
 ; GFX9-NEXT:s_swappc_b64 s[30:31], s[4:5]
 ; GFX9-NEXT:s_endpgm
-;
 ; GFX10-LABEL: test_simple_indirect_call:
 ; GFX10:   ; %bb.0:
 ; GFX10-NEXT:s_getpc_b64 s[8:9]
@@ -69,8 +68,8 @@
 
 attributes #0 = { nounwind readnone speculatable willreturn }
 ;.
-; AKF_GCN: attributes #[[ATTR0:[0-9]+]] = { nounwind readnone speculatable willreturn }
+; AKF_GCN: attributes #[[ATTR0:[0-9]+]] = { nocallback nofree nosync nounwind readnone speculatable willreturn }
 ;.
 ; ATTRIBUTOR_GCN: attributes #[[ATTR0]] = { "uniform-work-group-size"="false" }
-; ATTRIBUTOR_GCN: attributes #[[ATTR1:[0-9]+]] = { nounwind readnone speculatable willreturn }
+; ATTRIBUTOR_GCN: attributes #[[ATTR1:[0-9]+]] = { nocallback nofree nosync nounwind readnone speculatable willreturn }
 ;.
Index: llvm/test/CodeGen/AMDGPU/annotate-kernel-features.ll
===
--- llvm/test/CodeGen/AMDGPU/annotate-kernel-features.ll
+++ llvm/test/CodeGen/AMDGPU/annotate-kernel-features.ll
@@ -414,10 +414,10 @@
 ; NOHSA: attributes #[[ATTR8]] = { nounwind "amdgpu-work-item-id-y" "amdgpu-work-item-id-z" "uniform-work-group-size"="false" }
 ; NOHSA: attributes #[[ATTR9]] = { nounwind "amdgpu-work-group-id-y" "amdgpu-work-group-id-z" "amdgpu-work-item-id-y" "amdgpu-work-item-id-z" "uniform-work-group-size"="false" }
 ;.
-; AKF_CHECK: attributes #[[ATTR0:[0-9]+]] = { nounwind readnone speculatable willreturn }
+; AKF_CHECK: attributes #[[ATTR0:[0-9]+]] = { nocallback nofree nosync nounwind readnone speculatable willreturn }
 ; AKF_CHECK: attributes #[[ATTR1]] = { nounwind }
 ;.
-; ATTRIBUTOR_CHECK: attributes #[[ATTR0:[0-9]+]] = { nounwind readnone speculatable willreturn }
+; ATTRIBUTOR_CHECK: attributes #[[ATTR0:[0-9]+]] = { nocallback nofree nosync nounwind readnone speculatable willreturn }
 ; ATTRIBUTOR_CHECK: attributes #[[ATTR1]] = { nounwind "amdgpu-no-dispatch-id" "amdgpu-no-dispatch-ptr" "amdgpu-no-heap-ptr" "amdgpu-no-hostcall-ptr" "amdgpu-no-implicitarg-ptr" "amdgpu-no-lds-kernel-id" "amdgpu-no-multigrid-sync-arg" "amdgpu-no-queue-ptr" "amdgpu-no-workgroup-id-x" "amdgpu-no-workgroup-id-y" 

[PATCH] D135155: [AMDGPU] Annotate the intrinsics to be default and nocallback

2022-10-04 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: llvm/include/llvm/IR/IntrinsicsAMDGPU.td:1581
   ClangBuiltin<"__builtin_amdgcn_ds_swizzle">,
-  Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty],
-[IntrNoMem, IntrConvergent, IntrWillReturn,
+  DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty],
+[IntrNoMem, IntrConvergent,

Shouldn't be default, nosync is wrong



Comment at: llvm/include/llvm/IR/IntrinsicsAMDGPU.td:1649-1686
 def int_amdgcn_icmp :
-  Intrinsic<[llvm_anyint_ty], [llvm_anyint_ty, LLVMMatchType<1>, llvm_i32_ty],
-[IntrNoMem, IntrConvergent, IntrWillReturn,
+  DefaultAttrsIntrinsic<[llvm_anyint_ty], [llvm_anyint_ty, LLVMMatchType<1>, 
llvm_i32_ty],
+[IntrNoMem, IntrConvergent,
  ImmArg>]>;
 
 def int_amdgcn_fcmp :
+  DefaultAttrsIntrinsic<[llvm_anyint_ty], [llvm_anyfloat_ty, LLVMMatchType<1>, 
llvm_i32_ty],

Not default, probably should not get nosync



Comment at: llvm/include/llvm/IR/IntrinsicsAMDGPU.td:1990
 def int_amdgcn_permlane64 :
-  Intrinsic<[llvm_i32_ty], [llvm_i32_ty],
-[IntrNoMem, IntrConvergent, IntrWillReturn]>;
+  DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i32_ty],
+[IntrNoMem, IntrConvergent]>;

Shouldn't get nosync



Comment at: llvm/include/llvm/IR/IntrinsicsAMDGPU.td:1993-2012
 def int_amdgcn_ds_add_gs_reg_rtn :
   ClangBuiltin<"__builtin_amdgcn_ds_add_gs_reg_rtn">,
-  Intrinsic<[llvm_anyint_ty], [llvm_i32_ty, llvm_i32_ty],
-[ImmArg>, IntrHasSideEffects, IntrWillReturn]>;
+  DefaultAttrsIntrinsic<[llvm_anyint_ty], [llvm_i32_ty, llvm_i32_ty],
+[ImmArg>, IntrHasSideEffects]>;
 
 def int_amdgcn_ds_sub_gs_reg_rtn :
   ClangBuiltin<"__builtin_amdgcn_ds_sub_gs_reg_rtn">,

Not sure about these ones, but maybe shouldn't get nosync



Comment at: llvm/include/llvm/IR/IntrinsicsAMDGPU.td:2020-2044
 class AMDGPUWmmaIntrinsic :
-  Intrinsic<
+  DefaultAttrsIntrinsic<
 [CD],   // %D
 [
   AB,   // %A
   AB,   // %B
   LLVMMatchType<0>, // %C

Also not sure about nosync for these



Comment at: llvm/include/llvm/IR/IntrinsicsAMDGPU.td:2457-2465
 def int_amdgcn_fdiv_fast : Intrinsic<
   [llvm_float_ty], [llvm_float_ty, llvm_float_ty],
-  [IntrNoMem, IntrSpeculatable, IntrWillReturn]
+  [IntrNoMem, IntrSpeculatable, IntrWillReturn, IntrNoCallback, IntrNoFree]
 >;
 
 // Represent a relocation constant.
 def int_amdgcn_reloc_constant : Intrinsic<

Defaults


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135155

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


[PATCH] D135155: [AMDGPU] Annotate the intrinsics to be default and nocallback

2022-10-04 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert updated this revision to Diff 465256.
jdoerfert added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Update tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135155

Files:
  clang/test/CodeGenOpenCL/builtins-amdgcn.cl
  llvm/include/llvm/IR/Intrinsics.td
  llvm/include/llvm/IR/IntrinsicsAMDGPU.td
  llvm/test/Bitcode/compatibility-3.6.ll
  llvm/test/Bitcode/compatibility-3.7.ll
  llvm/test/Bitcode/compatibility-3.8.ll
  llvm/test/Bitcode/compatibility-3.9.ll
  llvm/test/Bitcode/compatibility-4.0.ll
  llvm/test/Bitcode/compatibility-5.0.ll
  llvm/test/Bitcode/compatibility-6.0.ll
  llvm/test/Bitcode/compatibility.ll
  llvm/test/CodeGen/AMDGPU/annotate-kernel-features-hsa-call.ll
  llvm/test/CodeGen/AMDGPU/annotate-kernel-features-hsa.ll
  llvm/test/CodeGen/AMDGPU/annotate-kernel-features.ll
  llvm/test/CodeGen/AMDGPU/pal-simple-indirect-call.ll
  llvm/test/Transforms/Inline/AMDGPU/amdgpu-inline-alloca-argument.ll
  llvm/test/Transforms/OpenMP/barrier_removal.ll

Index: llvm/test/Transforms/OpenMP/barrier_removal.ll
===
--- llvm/test/Transforms/OpenMP/barrier_removal.ll
+++ llvm/test/Transforms/OpenMP/barrier_removal.ll
@@ -249,7 +249,8 @@
 ;.
 ; CHECK: attributes #[[ATTR0:[0-9]+]] = { "llvm.assume"="ompx_aligned_barrier" }
 ; CHECK: attributes #[[ATTR1:[0-9]+]] = { convergent nocallback nounwind }
-; CHECK: attributes #[[ATTR2:[0-9]+]] = { convergent nounwind willreturn }
+; CHECK: attributes #[[ATTR2:[0-9]+]] = { convergent nocallback nounwind willreturn }
+; CHECK: attributes #[[ATTR3:[0-9]+]] = { inaccessiblememonly nocallback nofree nosync nounwind willreturn }
 ;.
 ; CHECK: [[META0:![0-9]+]] = !{i32 7, !"openmp", i32 50}
 ; CHECK: [[META1:![0-9]+]] = !{i32 7, !"openmp-device", i32 50}
Index: llvm/test/Transforms/Inline/AMDGPU/amdgpu-inline-alloca-argument.ll
===
--- llvm/test/Transforms/Inline/AMDGPU/amdgpu-inline-alloca-argument.ll
+++ llvm/test/Transforms/Inline/AMDGPU/amdgpu-inline-alloca-argument.ll
@@ -45,8 +45,7 @@
 ; addrspacecasted' alloca.
 ; CHECK-LABEL: @test_inliner_flat_ptr(
 ; CHECK: call i32 @llvm.amdgcn.workitem.id.x()
-; CHECK-NOT: call
-; CHECK-NOT: call
+; CHECK-NOT: call [[.*]]@
 define amdgpu_kernel void @test_inliner_flat_ptr(float addrspace(1)* nocapture %a, i32 %n) {
 entry:
   %pvt_arr = alloca [64 x float], align 4, addrspace(5)
Index: llvm/test/CodeGen/AMDGPU/pal-simple-indirect-call.ll
===
--- llvm/test/CodeGen/AMDGPU/pal-simple-indirect-call.ll
+++ llvm/test/CodeGen/AMDGPU/pal-simple-indirect-call.ll
@@ -40,7 +40,6 @@
 ; GFX9-NEXT:s_mov_b64 s[2:3], s[10:11]
 ; GFX9-NEXT:s_swappc_b64 s[30:31], s[4:5]
 ; GFX9-NEXT:s_endpgm
-;
 ; GFX10-LABEL: test_simple_indirect_call:
 ; GFX10:   ; %bb.0:
 ; GFX10-NEXT:s_getpc_b64 s[8:9]
@@ -69,8 +68,8 @@
 
 attributes #0 = { nounwind readnone speculatable willreturn }
 ;.
-; AKF_GCN: attributes #[[ATTR0:[0-9]+]] = { nounwind readnone speculatable willreturn }
+; AKF_GCN: attributes #[[ATTR0:[0-9]+]] = { nocallback nofree nosync nounwind readnone speculatable willreturn }
 ;.
 ; ATTRIBUTOR_GCN: attributes #[[ATTR0]] = { "uniform-work-group-size"="false" }
-; ATTRIBUTOR_GCN: attributes #[[ATTR1:[0-9]+]] = { nounwind readnone speculatable willreturn }
+; ATTRIBUTOR_GCN: attributes #[[ATTR1:[0-9]+]] = { nocallback nofree nosync nounwind readnone speculatable willreturn }
 ;.
Index: llvm/test/CodeGen/AMDGPU/annotate-kernel-features.ll
===
--- llvm/test/CodeGen/AMDGPU/annotate-kernel-features.ll
+++ llvm/test/CodeGen/AMDGPU/annotate-kernel-features.ll
@@ -414,10 +414,10 @@
 ; NOHSA: attributes #[[ATTR8]] = { nounwind "amdgpu-work-item-id-y" "amdgpu-work-item-id-z" "uniform-work-group-size"="false" }
 ; NOHSA: attributes #[[ATTR9]] = { nounwind "amdgpu-work-group-id-y" "amdgpu-work-group-id-z" "amdgpu-work-item-id-y" "amdgpu-work-item-id-z" "uniform-work-group-size"="false" }
 ;.
-; AKF_CHECK: attributes #[[ATTR0:[0-9]+]] = { nounwind readnone speculatable willreturn }
+; AKF_CHECK: attributes #[[ATTR0:[0-9]+]] = { nocallback nofree nosync nounwind readnone speculatable willreturn }
 ; AKF_CHECK: attributes #[[ATTR1]] = { nounwind }
 ;.
-; ATTRIBUTOR_CHECK: attributes #[[ATTR0:[0-9]+]] = { nounwind readnone speculatable willreturn }
+; ATTRIBUTOR_CHECK: attributes #[[ATTR0:[0-9]+]] = { nocallback nofree nosync nounwind readnone speculatable willreturn }
 ; ATTRIBUTOR_CHECK: attributes #[[ATTR1]] = { nounwind "amdgpu-no-dispatch-id" "amdgpu-no-dispatch-ptr" "amdgpu-no-heap-ptr" "amdgpu-no-hostcall-ptr" "amdgpu-no-implicitarg-ptr" "amdgpu-no-lds-kernel-id" "amdgpu-no-multigrid-sync-arg" "amdgpu-no-queue-ptr" "amdgpu-no-workgroup-id-x" 

[PATCH] D128142: [MemProf] Memprof profile matching and annotation

2022-10-04 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD added a comment.

Please disregard my previous comment, I missed the latest commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128142

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


[PATCH] D128142: [MemProf] Memprof profile matching and annotation

2022-10-04 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD added a comment.

I see that this revision is reverted along with reversion of D128143 
, I see that D128143 
 is re-commited.
The commit message of D128143  says that it 
depends on this patch. Does the dependence still exist?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128142

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


[clang] b60e7a7 - [clang-format] Handle C# interpolated verbatim string prefix @$

2022-10-04 Thread via cfe-commits

Author: owenca
Date: 2022-10-04T18:27:36-07:00
New Revision: b60e7a7f1afc45af5a6ca9fc8a531c41d0e93c85

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

LOG: [clang-format] Handle C# interpolated verbatim string prefix @$

Fixes #58062.

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

Added: 


Modified: 
clang/lib/Format/FormatTokenLexer.cpp
clang/unittests/Format/FormatTestCSharp.cpp

Removed: 




diff  --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index 95d7b51763cc1..313ea673ca757 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -312,36 +312,32 @@ bool FormatTokenLexer::tryMergeCSharpStringLiteral() {
 return false;
 
   // Look for @"aa" or $"aa".
-  auto  = *(Tokens.end() - 1);
-  if (!String->is(tok::string_literal))
+  const auto String = *(Tokens.end() - 1);
+  if (String->isNot(tok::string_literal))
 return false;
 
-  auto  = *(Tokens.end() - 2);
-  if (!(At->is(tok::at) || At->TokenText == "$"))
+  auto Prefix = *(Tokens.end() - 2);
+  if (Prefix->isNot(tok::at) && Prefix->TokenText != "$")
 return false;
 
-  if (Tokens.size() > 2 && At->is(tok::at)) {
-auto  = *(Tokens.end() - 3);
-if (Dollar->TokenText == "$") {
-  // This looks like $@"a" so we need to combine all 3 tokens.
-  Dollar->Tok.setKind(tok::string_literal);
-  Dollar->TokenText =
-  StringRef(Dollar->TokenText.begin(),
-String->TokenText.end() - Dollar->TokenText.begin());
-  Dollar->ColumnWidth += (At->ColumnWidth + String->ColumnWidth);
-  Dollar->setType(TT_CSharpStringLiteral);
+  if (Tokens.size() > 2) {
+const auto Tok = *(Tokens.end() - 3);
+if ((Tok->TokenText == "$" && Prefix->is(tok::at)) ||
+(Tok->is(tok::at) && Prefix->TokenText == "$")) {
+  // This looks like $@"aaa" or @$"aaa" so we need to combine all 3 tokens.
+  Tok->ColumnWidth += Prefix->ColumnWidth;
   Tokens.erase(Tokens.end() - 2);
-  Tokens.erase(Tokens.end() - 1);
-  return true;
+  Prefix = Tok;
 }
   }
 
   // Convert back into just a string_literal.
-  At->Tok.setKind(tok::string_literal);
-  At->TokenText = StringRef(At->TokenText.begin(),
-String->TokenText.end() - At->TokenText.begin());
-  At->ColumnWidth += String->ColumnWidth;
-  At->setType(TT_CSharpStringLiteral);
+  Prefix->Tok.setKind(tok::string_literal);
+  Prefix->TokenText =
+  StringRef(Prefix->TokenText.begin(),
+String->TokenText.end() - Prefix->TokenText.begin());
+  Prefix->ColumnWidth += String->ColumnWidth;
+  Prefix->setType(TT_CSharpStringLiteral);
   Tokens.erase(Tokens.end() - 1);
   return true;
 }
@@ -375,9 +371,11 @@ bool FormatTokenLexer::tryMergeNullishCoalescingEqual() {
 bool FormatTokenLexer::tryMergeCSharpKeywordVariables() {
   if (Tokens.size() < 2)
 return false;
-  auto  = *(Tokens.end() - 2);
-  auto  = *(Tokens.end() - 1);
-  if (!At->is(tok::at))
+  const auto At = *(Tokens.end() - 2);
+  if (At->isNot(tok::at))
+return false;
+  const auto Keyword = *(Tokens.end() - 1);
+  if (Keyword->TokenText == "$")
 return false;
   if (!Keywords.isCSharpKeyword(*Keyword))
 return false;
@@ -683,7 +681,7 @@ void 
FormatTokenLexer::handleCSharpVerbatimAndInterpolatedStrings() {
 
   bool Verbatim = false;
   bool Interpolated = false;
-  if (TokenText.startswith(R"($@")")) {
+  if (TokenText.startswith(R"($@")") || TokenText.startswith(R"(@$")")) {
 Verbatim = true;
 Interpolated = true;
   } else if (TokenText.startswith(R"(@")")) {

diff  --git a/clang/unittests/Format/FormatTestCSharp.cpp 
b/clang/unittests/Format/FormatTestCSharp.cpp
index 47ad779d632a9..a18f57ec57144 100644
--- a/clang/unittests/Format/FormatTestCSharp.cpp
+++ b/clang/unittests/Format/FormatTestCSharp.cpp
@@ -575,6 +575,8 @@ TEST_F(FormatTestCSharp, 
CSharpEscapedQuotesInVerbatimStrings) {
   verifyFormat(R"(string str = @"""Hello world""";)", Style);
   verifyFormat(R"(string str = $@"""Hello {friend}""";)", Style);
   verifyFormat(R"(return $@"Foo ""/foo?f={Request.Query["f"]}""";)", Style);
+  verifyFormat(R"(return @$"Foo ""/foo?f={Request.Query["f"]}""";)", Style);
+  verifyFormat(R"(return @$"path\to\{specifiedFile}")", Style);
 }
 
 TEST_F(FormatTestCSharp, CSharpQuotesInInterpolatedStrings) {



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


[PATCH] D135026: [clang-format] Handle C# interpolated verbatim string prefix @$

2022-10-04 Thread Owen Pan via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb60e7a7f1afc: [clang-format] Handle C# interpolated verbatim 
string prefix @$ (authored by owenpan).

Changed prior to commit:
  https://reviews.llvm.org/D135026?vs=464541=465248#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135026

Files:
  clang/lib/Format/FormatTokenLexer.cpp
  clang/unittests/Format/FormatTestCSharp.cpp


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -575,6 +575,8 @@
   verifyFormat(R"(string str = @"""Hello world""";)", Style);
   verifyFormat(R"(string str = $@"""Hello {friend}""";)", Style);
   verifyFormat(R"(return $@"Foo ""/foo?f={Request.Query["f"]}""";)", Style);
+  verifyFormat(R"(return @$"Foo ""/foo?f={Request.Query["f"]}""";)", Style);
+  verifyFormat(R"(return @$"path\to\{specifiedFile}")", Style);
 }
 
 TEST_F(FormatTestCSharp, CSharpQuotesInInterpolatedStrings) {
Index: clang/lib/Format/FormatTokenLexer.cpp
===
--- clang/lib/Format/FormatTokenLexer.cpp
+++ clang/lib/Format/FormatTokenLexer.cpp
@@ -312,36 +312,32 @@
 return false;
 
   // Look for @"aa" or $"aa".
-  auto  = *(Tokens.end() - 1);
-  if (!String->is(tok::string_literal))
+  const auto String = *(Tokens.end() - 1);
+  if (String->isNot(tok::string_literal))
 return false;
 
-  auto  = *(Tokens.end() - 2);
-  if (!(At->is(tok::at) || At->TokenText == "$"))
+  auto Prefix = *(Tokens.end() - 2);
+  if (Prefix->isNot(tok::at) && Prefix->TokenText != "$")
 return false;
 
-  if (Tokens.size() > 2 && At->is(tok::at)) {
-auto  = *(Tokens.end() - 3);
-if (Dollar->TokenText == "$") {
-  // This looks like $@"a" so we need to combine all 3 tokens.
-  Dollar->Tok.setKind(tok::string_literal);
-  Dollar->TokenText =
-  StringRef(Dollar->TokenText.begin(),
-String->TokenText.end() - Dollar->TokenText.begin());
-  Dollar->ColumnWidth += (At->ColumnWidth + String->ColumnWidth);
-  Dollar->setType(TT_CSharpStringLiteral);
+  if (Tokens.size() > 2) {
+const auto Tok = *(Tokens.end() - 3);
+if ((Tok->TokenText == "$" && Prefix->is(tok::at)) ||
+(Tok->is(tok::at) && Prefix->TokenText == "$")) {
+  // This looks like $@"aaa" or @$"aaa" so we need to combine all 3 tokens.
+  Tok->ColumnWidth += Prefix->ColumnWidth;
   Tokens.erase(Tokens.end() - 2);
-  Tokens.erase(Tokens.end() - 1);
-  return true;
+  Prefix = Tok;
 }
   }
 
   // Convert back into just a string_literal.
-  At->Tok.setKind(tok::string_literal);
-  At->TokenText = StringRef(At->TokenText.begin(),
-String->TokenText.end() - At->TokenText.begin());
-  At->ColumnWidth += String->ColumnWidth;
-  At->setType(TT_CSharpStringLiteral);
+  Prefix->Tok.setKind(tok::string_literal);
+  Prefix->TokenText =
+  StringRef(Prefix->TokenText.begin(),
+String->TokenText.end() - Prefix->TokenText.begin());
+  Prefix->ColumnWidth += String->ColumnWidth;
+  Prefix->setType(TT_CSharpStringLiteral);
   Tokens.erase(Tokens.end() - 1);
   return true;
 }
@@ -375,9 +371,11 @@
 bool FormatTokenLexer::tryMergeCSharpKeywordVariables() {
   if (Tokens.size() < 2)
 return false;
-  auto  = *(Tokens.end() - 2);
-  auto  = *(Tokens.end() - 1);
-  if (!At->is(tok::at))
+  const auto At = *(Tokens.end() - 2);
+  if (At->isNot(tok::at))
+return false;
+  const auto Keyword = *(Tokens.end() - 1);
+  if (Keyword->TokenText == "$")
 return false;
   if (!Keywords.isCSharpKeyword(*Keyword))
 return false;
@@ -683,7 +681,7 @@
 
   bool Verbatim = false;
   bool Interpolated = false;
-  if (TokenText.startswith(R"($@")")) {
+  if (TokenText.startswith(R"($@")") || TokenText.startswith(R"(@$")")) {
 Verbatim = true;
 Interpolated = true;
   } else if (TokenText.startswith(R"(@")")) {


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -575,6 +575,8 @@
   verifyFormat(R"(string str = @"""Hello world""";)", Style);
   verifyFormat(R"(string str = $@"""Hello {friend}""";)", Style);
   verifyFormat(R"(return $@"Foo ""/foo?f={Request.Query["f"]}""";)", Style);
+  verifyFormat(R"(return @$"Foo ""/foo?f={Request.Query["f"]}""";)", Style);
+  verifyFormat(R"(return @$"path\to\{specifiedFile}")", Style);
 }
 
 TEST_F(FormatTestCSharp, CSharpQuotesInInterpolatedStrings) {
Index: clang/lib/Format/FormatTokenLexer.cpp
===
--- 

[PATCH] D135232: [modules] Allow to validate system headers less often with `-fmodules-validate-once-per-build-session`.

2022-10-04 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

Here is the documentation for both flags:

- 
https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fmodules-validate-system-headers
- 
https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fmodules-validate-once-per-build-session

There is no mention of how these flags are interconnected.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135232

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


[PATCH] D135118: [clang/Sema] Fix non-deterministic order for certain kind of diagnostics

2022-10-04 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi marked an inline comment as done.
akyrtzi added inline comments.



Comment at: clang/include/clang/AST/DeclObjC.h:1091
   virtual void collectPropertiesToImplement(PropertyMap ,
 PropertyDeclOrder ) const {}
 

akyrtzi wrote:
> benlangmuir wrote:
> > Can we use the existing `PropertyDeclOrder` instead of changing the map 
> > type? Or else get rid of the `PO` parameter to functions using 
> > `PropertyMap` if we keep the MapVector?
> I'll take a look.
See updated patch.

The diagnostic machinery (e.g. in `DiagnoseUnimplementedProperties`) for these 
ObjC diagnostics is using `PropertyMap` separately from the 
`collectPropertiesToImplement` functions, so I kept the map type change and 
removed `PropertyDeclOrder` from these functions accepting `PropertyMap`.
This is better for maintainance since it'd be an easy mistake to add new code 
that iterates the `DenseMap` instead of the vector.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135118

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


[PATCH] D135232: [modules] Allow to validate system headers less often with `-fmodules-validate-once-per-build-session`.

2022-10-04 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai created this revision.
vsapsai added reviewers: benlangmuir, MaskRay.
Herald added subscribers: StephenFan, ributzka.
Herald added a project: All.
vsapsai requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Make flags `-fmodules-validate-system-headers` and
`-fmodules-validate-once-per-build-session` orthogonal, so they have
their own independent responsibilities - if system headers should be
validated and how often.

rdar://8799


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135232

Files:
  clang/lib/Serialization/ASTReader.cpp
  clang/test/Modules/fmodules-validate-once-per-build-session.c
  clang/test/Modules/validate-system-headers.m


Index: clang/test/Modules/validate-system-headers.m
===
--- clang/test/Modules/validate-system-headers.m
+++ clang/test/Modules/validate-system-headers.m
@@ -34,8 +34,8 @@
 // RUN: %clang_cc1 -isystem %t/Inputs/usr/include -fmodules 
-fimplicit-module-maps -fmodules-cache-path=%t/ModuleCache 
-fdisable-module-hash -x objective-c-header -fsyntax-only %s 
-fbuild-session-timestamp=139000 -fmodules-validate-once-per-build-session
 // RUN: diff %t/ModuleCache/Foo.pcm %t/Foo.pcm.saved
 
-// Now add -fmodules-validate-system-headers and rebuild
+// Now add -fmodules-validate-system-headers and rebuild. No recompilation due 
to -fmodules-validate-once-per-build-session
 // RUN: %clang_cc1 -isystem %t/Inputs/usr/include -fmodules 
-fimplicit-module-maps -fmodules-validate-system-headers 
-fmodules-cache-path=%t/ModuleCache -fdisable-module-hash -x objective-c-header 
-fsyntax-only %s -fbuild-session-timestamp=139000 
-fmodules-validate-once-per-build-session
-// RUN: not diff %t/ModuleCache/Foo.pcm %t/Foo.pcm.saved
+// RUN: diff %t/ModuleCache/Foo.pcm %t/Foo.pcm.saved
 
 @import Foo;
Index: clang/test/Modules/fmodules-validate-once-per-build-session.c
===
--- clang/test/Modules/fmodules-validate-once-per-build-session.c
+++ clang/test/Modules/fmodules-validate-once-per-build-session.c
@@ -17,8 +17,8 @@
 
 // ===
 // Compile the module.
-// RUN: %clang_cc1 -cc1 -fmodules -fimplicit-module-maps -fdisable-module-hash 
-fmodules-cache-path=%t/modules-cache -fsyntax-only -isystem %t/Inputs 
-fbuild-session-timestamp=139000 -fmodules-validate-once-per-build-session 
%s
-// RUN: %clang_cc1 -cc1 -fmodules -fimplicit-module-maps -fdisable-module-hash 
-fmodules-cache-path=%t/modules-cache-user -fsyntax-only -I %t/Inputs 
-fbuild-session-timestamp=139000 -fmodules-validate-once-per-build-session 
%s
+// RUN: %clang_cc1 -cc1 -fmodules -fimplicit-module-maps -fdisable-module-hash 
-fmodules-cache-path=%t/modules-cache -fsyntax-only -isystem %t/Inputs 
-fmodules-validate-system-headers -fbuild-session-timestamp=139000 
-fmodules-validate-once-per-build-session %s
+// RUN: %clang_cc1 -cc1 -fmodules -fimplicit-module-maps -fdisable-module-hash 
-fmodules-cache-path=%t/modules-cache-user -fsyntax-only -I %t/Inputs 
-fmodules-validate-system-headers -fbuild-session-timestamp=139000 
-fmodules-validate-once-per-build-session %s
 // RUN: ls -R %t/modules-cache | grep Foo.pcm.timestamp
 // RUN: ls -R %t/modules-cache | grep Bar.pcm.timestamp
 // RUN: ls -R %t/modules-cache-user | grep Foo.pcm.timestamp
@@ -30,8 +30,8 @@
 
 // ===
 // Use it, and make sure that we did not recompile it.
-// RUN: %clang_cc1 -cc1 -fmodules -fimplicit-module-maps -fdisable-module-hash 
-fmodules-cache-path=%t/modules-cache -fsyntax-only -isystem %t/Inputs 
-fbuild-session-timestamp=139000 -fmodules-validate-once-per-build-session 
%s
-// RUN: %clang_cc1 -cc1 -fmodules -fimplicit-module-maps -fdisable-module-hash 
-fmodules-cache-path=%t/modules-cache-user -fsyntax-only -I %t/Inputs 
-fbuild-session-timestamp=139000 -fmodules-validate-once-per-build-session 
%s
+// RUN: %clang_cc1 -cc1 -fmodules -fimplicit-module-maps -fdisable-module-hash 
-fmodules-cache-path=%t/modules-cache -fsyntax-only -isystem %t/Inputs 
-fmodules-validate-system-headers -fbuild-session-timestamp=139000 
-fmodules-validate-once-per-build-session %s
+// RUN: %clang_cc1 -cc1 -fmodules -fimplicit-module-maps -fdisable-module-hash 
-fmodules-cache-path=%t/modules-cache-user -fsyntax-only -I %t/Inputs 
-fmodules-validate-system-headers -fbuild-session-timestamp=139000 
-fmodules-validate-once-per-build-session %s
 // RUN: ls -R %t/modules-cache | grep Foo.pcm.timestamp
 // RUN: ls -R %t/modules-cache | grep Bar.pcm.timestamp
 // RUN: ls -R %t/modules-cache-user | grep Foo.pcm.timestamp
@@ -54,8 +54,8 @@
 // ===
 // Use the module, and make sure that we did not recompile it if foo.h or
 // module.map are system files, even though the sources changed.
-// RUN: %clang_cc1 -cc1 -fmodules -fimplicit-module-maps -fdisable-module-hash 
-fmodules-cache-path=%t/modules-cache -fsyntax-only -isystem %t/Inputs 

[PATCH] D135118: [clang/Sema] Fix non-deterministic order for certain kind of diagnostics

2022-10-04 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi updated this revision to Diff 465241.
akyrtzi added a comment.
Herald added subscribers: steakhal, martong.
Herald added a reviewer: NoQ.

Remove `PropertyDeclOrder` parameter from the `collectPropertiesToImplement` 
functions. This is not necessary with `PropertyMap` becoming a `MapVector`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135118

Files:
  clang/include/clang/AST/DeclObjC.h
  clang/include/clang/Sema/Scope.h
  clang/lib/AST/DeclObjC.cpp
  clang/lib/Sema/SemaObjCProperty.cpp
  clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
  clang/test/Sema/deterministic-diagnostics-order.m

Index: clang/test/Sema/deterministic-diagnostics-order.m
===
--- /dev/null
+++ clang/test/Sema/deterministic-diagnostics-order.m
@@ -0,0 +1,116 @@
+// RUN: %clang_cc1 %s -fsyntax-only -Wobjc-property-implementation -Watomic-property-with-user-defined-accessor -Wunused 2> %t.err
+// RUN: FileCheck -input-file=%t.err %s
+
+@interface I
+@end
+
+@interface I(cat)
+@property id prop1;
+@property id prop2;
+@property id prop3;
+@end
+
+@implementation I(cat)
+@end
+
+// CHECK: warning: property 'prop1' requires method
+// CHECK: warning: property 'prop2' requires method
+// CHECK: warning: property 'prop3' requires method
+
+@interface I2
+@property int prop1;
+@property int prop2;
+@property int prop3;
+@end
+
+@implementation I2
+@synthesize prop1, prop2, prop3;
+-(int) prop1 { return 0; }
+-(int) prop2 { return 0; }
+-(int) prop3 { return 0; }
+@end
+
+// CHECK: warning: writable atomic property 'prop1'
+// CHECK: warning: writable atomic property 'prop2'
+// CHECK: warning: writable atomic property 'prop3'
+
+void test_unused() {
+  // Add enough variables to exceed the small storage of Scope::DeclSetTy.
+  int v1;
+  int v2;
+  int v3;
+  int v4;
+  int v5;
+  int v6;
+  int v7;
+  int v8;
+  int v9;
+  int v10;
+  int v11;
+  int v12;
+  int v13;
+  int v14;
+  int v15;
+  int v16;
+  int v17;
+  int v18;
+  int v19;
+  int v20;
+  int v21;
+  int v22;
+  int v23;
+  int v24;
+  int v25;
+  int v26;
+  int v27;
+  int v28;
+  int v29;
+  int v30;
+  int v31;
+  int v32;
+  int v33;
+  int v34;
+  int v35;
+  int v36;
+  int v37;
+  int v38;
+}
+
+// CHECK: warning: unused variable 'v1'
+// CHECK: warning: unused variable 'v2'
+// CHECK: warning: unused variable 'v3'
+// CHECK: warning: unused variable 'v4'
+// CHECK: warning: unused variable 'v5'
+// CHECK: warning: unused variable 'v6'
+// CHECK: warning: unused variable 'v7'
+// CHECK: warning: unused variable 'v8'
+// CHECK: warning: unused variable 'v9'
+// CHECK: warning: unused variable 'v10'
+// CHECK: warning: unused variable 'v11'
+// CHECK: warning: unused variable 'v12'
+// CHECK: warning: unused variable 'v13'
+// CHECK: warning: unused variable 'v14'
+// CHECK: warning: unused variable 'v15'
+// CHECK: warning: unused variable 'v16'
+// CHECK: warning: unused variable 'v17'
+// CHECK: warning: unused variable 'v18'
+// CHECK: warning: unused variable 'v19'
+// CHECK: warning: unused variable 'v20'
+// CHECK: warning: unused variable 'v21'
+// CHECK: warning: unused variable 'v22'
+// CHECK: warning: unused variable 'v23'
+// CHECK: warning: unused variable 'v24'
+// CHECK: warning: unused variable 'v25'
+// CHECK: warning: unused variable 'v26'
+// CHECK: warning: unused variable 'v27'
+// CHECK: warning: unused variable 'v28'
+// CHECK: warning: unused variable 'v29'
+// CHECK: warning: unused variable 'v30'
+// CHECK: warning: unused variable 'v31'
+// CHECK: warning: unused variable 'v32'
+// CHECK: warning: unused variable 'v33'
+// CHECK: warning: unused variable 'v34'
+// CHECK: warning: unused variable 'v35'
+// CHECK: warning: unused variable 'v36'
+// CHECK: warning: unused variable 'v37'
+// CHECK: warning: unused variable 'v38'
Index: clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
@@ -379,8 +379,7 @@
   IvarToPropMapTy IvarToPopertyMap;
 
   ObjCInterfaceDecl::PropertyMap PropMap;
-  ObjCInterfaceDecl::PropertyDeclOrder PropOrder;
-  InterfaceD->collectPropertiesToImplement(PropMap, PropOrder);
+  InterfaceD->collectPropertiesToImplement(PropMap);
 
   for (ObjCInterfaceDecl::PropertyMap::iterator
   I = PropMap.begin(), E = PropMap.end(); I != E; ++I) {
Index: clang/lib/Sema/SemaObjCProperty.cpp
===
--- clang/lib/Sema/SemaObjCProperty.cpp
+++ clang/lib/Sema/SemaObjCProperty.cpp
@@ -1822,9 +1822,8 @@
 static void CollectSuperClassPropertyImplementations(ObjCInterfaceDecl *CDecl,
 ObjCInterfaceDecl::PropertyMap ) {
   if (ObjCInterfaceDecl *SDecl = 

[PATCH] D135220: [clang] Update ModuleMap::getModuleMapFile* to use FileEntryRef

2022-10-04 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 accepted this revision.
jansvoboda11 added a comment.
This revision is now accepted and ready to land.

LGTM with a couple of small suggestions.




Comment at: clang/include/clang/Basic/SourceManager.h:1062
+Optional F = sloc.getFile().getContentCache().OrigEntry;
+return F ? >getFileEntry() : nullptr;
   }

Could you wrap `F` in `OptionalFileEntryRefDegradesToFileEntryPtr` to handle 
the conversion for you?



Comment at: clang/lib/Basic/SourceManager.cpp:402
 // pass that file to ContentCache.
-llvm::DenseMap::iterator
-overI = OverriddenFilesInfo->OverriddenFiles.find(FileEnt);
+llvm::DenseMap::iterator overI =
+OverriddenFilesInfo->OverriddenFiles.find(FileEnt);

Nit: Could use `auto`.



Comment at: clang/lib/Lex/ModuleMap.cpp:628
+InferredModuleAllowedBy[Result] =
+UmbrellaModuleMap ? *UmbrellaModuleMap : nullptr;
 Result->IsInferred = true;

Nit: Use `OptionalFileEntryRefDegradesToFileEntryPtr`?



Comment at: clang/lib/Lex/ModuleMap.cpp:647
+  InferredModuleAllowedBy[Result] =
+  UmbrellaModuleMap ? *UmbrellaModuleMap : nullptr;
   Result->IsInferred = true;

Nit: Use `OptionalFileEntryRefDegradesToFileEntryPtr`?



Comment at: clang/lib/Lex/ModuleMap.cpp:1030
+Optional ModuleMapRef = getModuleMapFileForUniquing(Parent);
+ModuleMapFile = ModuleMapRef ? *ModuleMapRef : nullptr;
+  }

Nit: Use `OptionalFileEntryRefDegradesToFileEntryPtr`? Maybe we should return 
that from `getModuleMapFileForUniquing` in the first place.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135220

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


[PATCH] D133823: Add APFloat and MLIR type support for fp8 (e5m2).

2022-10-04 Thread Stella Laurenzo via Phabricator via cfe-commits
stellaraccident added a comment.

Ran the full clang/llvm/mlir test suite in debug mode just to be safe.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133823

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


[PATCH] D133823: Add APFloat and MLIR type support for fp8 (e5m2).

2022-10-04 Thread Stella Laurenzo via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe28b15b572b5: Add APFloat and MLIR type support for fp8 
(e5m2). (authored by stellaraccident).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133823

Files:
  clang/lib/AST/MicrosoftMangle.cpp
  llvm/include/llvm/ADT/APFloat.h
  llvm/lib/Support/APFloat.cpp
  llvm/unittests/ADT/APFloatTest.cpp
  mlir/include/mlir-c/BuiltinTypes.h
  mlir/include/mlir/IR/Builders.h
  mlir/include/mlir/IR/BuiltinTypes.h
  mlir/include/mlir/IR/BuiltinTypes.td
  mlir/include/mlir/IR/Types.h
  mlir/lib/AsmParser/TokenKinds.def
  mlir/lib/AsmParser/TypeParser.cpp
  mlir/lib/CAPI/IR/BuiltinTypes.cpp
  mlir/lib/IR/AsmPrinter.cpp
  mlir/lib/IR/Builders.cpp
  mlir/lib/IR/BuiltinTypes.cpp
  mlir/lib/IR/MLIRContext.cpp
  mlir/lib/IR/Types.cpp
  mlir/test/IR/attribute.mlir
  mlir/test/lib/Dialect/Test/TestOps.td

Index: mlir/test/lib/Dialect/Test/TestOps.td
===
--- mlir/test/lib/Dialect/Test/TestOps.td
+++ mlir/test/lib/Dialect/Test/TestOps.td
@@ -193,6 +193,14 @@
   let assemblyFormat = "$attr attr-dict";
 }
 
+def FloatAttrOp : TEST_Op<"float_attrs"> {
+  // TODO: Clean up the OpBase float type and attribute selectors so they
+  // can express all of the types.
+  let arguments = (ins
+AnyAttr:$float_attr
+  );
+}
+
 def I32Case5:  I32EnumAttrCase<"case5", 5>;
 def I32Case10: I32EnumAttrCase<"case10", 10>;
 
Index: mlir/test/IR/attribute.mlir
===
--- mlir/test/IR/attribute.mlir
+++ mlir/test/IR/attribute.mlir
@@ -31,6 +31,42 @@
 
 // -
 
+//===--===//
+// Test float attributes
+//===--===//
+
+func.func @float_attrs_pass() {
+  "test.float_attrs"() {
+// CHECK: float_attr = 2.00e+00 : f8E5M2
+float_attr = 2. : f8E5M2
+  } : () -> ()
+  "test.float_attrs"() {
+// CHECK: float_attr = 2.00e+00 : f16
+float_attr = 2. : f16
+  } : () -> ()
+  "test.float_attrs"() {
+// CHECK: float_attr = 2.00e+00 : bf16
+float_attr = 2. : bf16
+  } : () -> ()
+  "test.float_attrs"() {
+// CHECK: float_attr = 2.00e+00 : f32
+float_attr = 2. : f32
+  } : () -> ()
+  "test.float_attrs"() {
+// CHECK: float_attr = 2.00e+00 : f64
+float_attr = 2. : f64
+  } : () -> ()
+  "test.float_attrs"() {
+// CHECK: float_attr = 2.00e+00 : f80
+float_attr = 2. : f80
+  } : () -> ()
+  "test.float_attrs"() {
+// CHECK: float_attr = 2.00e+00 : f128
+float_attr = 2. : f128
+  } : () -> ()
+  return
+}
+
 //===--===//
 // Test integer attributes
 //===--===//
Index: mlir/lib/IR/Types.cpp
===
--- mlir/lib/IR/Types.cpp
+++ mlir/lib/IR/Types.cpp
@@ -18,6 +18,7 @@
 
 MLIRContext *Type::getContext() const { return getDialect().getContext(); }
 
+bool Type::isFloat8E5M2() const { return isa(); }
 bool Type::isBF16() const { return isa(); }
 bool Type::isF16() const { return isa(); }
 bool Type::isF32() const { return isa(); }
Index: mlir/lib/IR/MLIRContext.cpp
===
--- mlir/lib/IR/MLIRContext.cpp
+++ mlir/lib/IR/MLIRContext.cpp
@@ -206,6 +206,7 @@
   StorageUniquer typeUniquer;
 
   /// Cached Type Instances.
+  Float8E5M2Type f8E5M2Ty;
   BFloat16Type bf16Ty;
   Float16Type f16Ty;
   Float32Type f32Ty;
@@ -276,6 +277,7 @@
 
    Types.
   /// Floating-point Types.
+  impl->f8E5M2Ty = TypeUniquer::get(this);
   impl->bf16Ty = TypeUniquer::get(this);
   impl->f16Ty = TypeUniquer::get(this);
   impl->f32Ty = TypeUniquer::get(this);
@@ -840,6 +842,9 @@
 /// This should not be used directly.
 StorageUniquer ::getTypeUniquer() { return getImpl().typeUniquer; }
 
+Float8E5M2Type Float8E5M2Type::get(MLIRContext *context) {
+  return context->getImpl().f8E5M2Ty;
+}
 BFloat16Type BFloat16Type::get(MLIRContext *context) {
   return context->getImpl().bf16Ty;
 }
Index: mlir/lib/IR/BuiltinTypes.cpp
===
--- mlir/lib/IR/BuiltinTypes.cpp
+++ mlir/lib/IR/BuiltinTypes.cpp
@@ -88,6 +88,8 @@
 //===--===//
 
 unsigned FloatType::getWidth() {
+  if (isa())
+return 8;
   if (isa())
 return 16;
   if (isa())
@@ -103,6 +105,8 @@
 
 /// Returns the floating semantics for the given type.
 const llvm::fltSemantics ::getFloatSemantics() {
+  if (isa())
+return APFloat::Float8E5M2();
   if (isa())
 return 

[clang] e28b15b - Add APFloat and MLIR type support for fp8 (e5m2).

2022-10-04 Thread Stella Laurenzo via cfe-commits

Author: Stella Laurenzo
Date: 2022-10-04T17:18:17-07:00
New Revision: e28b15b572b58e5db4375da35745a4131858fc4c

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

LOG: Add APFloat and MLIR type support for fp8 (e5m2).

(Re-Apply with fixes to clang MicrosoftMangle.cpp)

This is a first step towards high level representation for fp8 types
that have been built in to hardware with near term roadmaps. Like the
BFLOAT16 type, the family of fp8 types are inspired by IEEE-754 binary
floating point formats but, due to the size limits, have been tweaked in
various ways in order to maximally use the range/precision in various
scenarios. The list of variants is small/finite and bounded by real
hardware.

This patch introduces the E5M2 FP8 format as proposed by Nvidia, ARM,
and Intel in the paper: https://arxiv.org/pdf/2209.05433.pdf

As the more conformant of the two implemented datatypes, we are plumbing
it through LLVM's APFloat type and MLIR's type system first as a
template. It will be followed by the range optimized E4M3 FP8 format
described in the paper. Since that format deviates further from the
IEEE-754 norms, it may require more debate and implementation
complexity.

Given that we see two parts of the FP8 implementation space represented
by these cases, we are recommending naming of:

* `F8M` : For FP8 types that can be conceived of as following the
  same rules as FP16 but with a smaller number of mantissa/exponent
  bits. Including the number of mantissa bits in the type name is enough
  to fully specify the type. This naming scheme is used to represent
  the E5M2 type described in the paper.
* `F8MF` : For FP8 types such as E4M3 which only support finite
  values.

The first of these (this patch) seems fairly non-controversial. The
second is previewed here to illustrate options for extending to the
other known variant (but can be discussed in detail in the patch
which implements it).

Many conversations about these types focus on the Machine-Learning
ecosystem where they are used to represent mixed-datatype computations
at a high level. At that level (which is why we also expose them in
MLIR), it is important to retain the actual type definition so that when
lowering to actual kernels or target specific code, the correct
promotions, casts and rescalings can be done as needed. We expect that
most LLVM backends will only experience these types as opaque `I8`
values that are applicable to some instructions.

MLIR does not make it particularly easy to add new floating point types
(i.e. the FloatType hierarchy is not open). Given the need to fully
model FloatTypes and make them interop with tooling, such types will
always be "heavy-weight" and it is not expected that a highly open type
system will be particularly helpful. There are also a bounded number of
floating point types in use for current and upcoming hardware, and we
can just implement them like this (perhaps looking for some cosmetic
ways to reduce the number of places that need to change). Creating a
more generic mechanism for extending floating point types seems like it
wouldn't be worth it and we should just deal with defining them one by
one on an as-needed basis when real hardware implements a new scheme.
Hopefully, with some additional production use and complete software
stacks, hardware makers will converge on a set of such types that is not
terribly divergent at the level that the compiler cares about.

(I cleaned up some old formatting and sorted some items for this case:
If we converge on landing this in some form, I will NFC commit format
only changes as a separate commit)

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

Added: 


Modified: 
clang/lib/AST/MicrosoftMangle.cpp
llvm/include/llvm/ADT/APFloat.h
llvm/lib/Support/APFloat.cpp
llvm/unittests/ADT/APFloatTest.cpp
mlir/include/mlir-c/BuiltinTypes.h
mlir/include/mlir/IR/Builders.h
mlir/include/mlir/IR/BuiltinTypes.h
mlir/include/mlir/IR/BuiltinTypes.td
mlir/include/mlir/IR/Types.h
mlir/lib/AsmParser/TokenKinds.def
mlir/lib/AsmParser/TypeParser.cpp
mlir/lib/CAPI/IR/BuiltinTypes.cpp
mlir/lib/IR/AsmPrinter.cpp
mlir/lib/IR/Builders.cpp
mlir/lib/IR/BuiltinTypes.cpp
mlir/lib/IR/MLIRContext.cpp
mlir/lib/IR/Types.cpp
mlir/test/IR/attribute.mlir
mlir/test/lib/Dialect/Test/TestOps.td

Removed: 




diff  --git a/clang/lib/AST/MicrosoftMangle.cpp 
b/clang/lib/AST/MicrosoftMangle.cpp
index bc69d85e49c96..8f724191e697a 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -838,6 +838,8 @@ void MicrosoftCXXNameMangler::mangleFloat(llvm::APFloat 
Number) {
   case APFloat::S_x87DoubleExtended: Out << 'X'; break;
   case APFloat::S_IEEEquad: Out << 'Y'; 

[PATCH] D135231: [clangd] Don't clone SymbolSlab::Builder arenas when finalizing.

2022-10-04 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

My first take on this was to keep track in various ways of whether GC was 
required (statically known at callsite, or have builder track whether symbols 
were overwritten).
However these failed to identify a bunch of cases where the arena wasn't 
shrinking, and this seems much simpler.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135231

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


[PATCH] D135231: [clangd] Don't clone SymbolSlab::Builder arenas when finalizing.

2022-10-04 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: adamcz.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

SymbolSlab::Builder has an arena to store strings of owned symbols, and
deduplicates them. build() copies all the strings and deduplicates them again!
This is potentially useful: we may have overwritten a symbol and
rendered some strings unreachable.

However in practice this is not the case. When testing on a variety of
files in LLVM (e.g. SemaExpr.cpp), the strings for the full preamble
index are 3MB and shrink by 0.4% (12KB). For comparison the serializde
preamble is >50MB.
There are also hundreds of smaller slabs (file sharding) that do not shrink at
all.

CPU time spent on this is significant (something like 3-5% of buildPreamble).
We're better off not bothering.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135231

Files:
  clang-tools-extra/clangd/index/Symbol.cpp


Index: clang-tools-extra/clangd/index/Symbol.cpp
===
--- clang-tools-extra/clangd/index/Symbol.cpp
+++ clang-tools-extra/clangd/index/Symbol.cpp
@@ -61,12 +61,9 @@
 SortedSymbols.push_back(std::move(Entry.second));
   llvm::sort(SortedSymbols,
  [](const Symbol , const Symbol ) { return L.ID < R.ID; });
-  // We may have unused strings from overwritten symbols. Build a new arena.
-  llvm::BumpPtrAllocator NewArena;
-  llvm::UniqueStringSaver Strings(NewArena);
-  for (auto  : SortedSymbols)
-own(S, Strings);
-  return SymbolSlab(std::move(NewArena), std::move(SortedSymbols));
+  // We may have unused strings from overwritten symbols.
+  // In practice, these are extremely small, it's not worth compacting.
+  return SymbolSlab(std::move(Arena), std::move(SortedSymbols));
 }
 
 llvm::raw_ostream <<(llvm::raw_ostream , const SymbolSlab ) {


Index: clang-tools-extra/clangd/index/Symbol.cpp
===
--- clang-tools-extra/clangd/index/Symbol.cpp
+++ clang-tools-extra/clangd/index/Symbol.cpp
@@ -61,12 +61,9 @@
 SortedSymbols.push_back(std::move(Entry.second));
   llvm::sort(SortedSymbols,
  [](const Symbol , const Symbol ) { return L.ID < R.ID; });
-  // We may have unused strings from overwritten symbols. Build a new arena.
-  llvm::BumpPtrAllocator NewArena;
-  llvm::UniqueStringSaver Strings(NewArena);
-  for (auto  : SortedSymbols)
-own(S, Strings);
-  return SymbolSlab(std::move(NewArena), std::move(SortedSymbols));
+  // We may have unused strings from overwritten symbols.
+  // In practice, these are extremely small, it's not worth compacting.
+  return SymbolSlab(std::move(Arena), std::move(SortedSymbols));
 }
 
 llvm::raw_ostream <<(llvm::raw_ostream , const SymbolSlab ) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D135011: Add builtin_elementwise_sin and builtin_elementwise_cos

2022-10-04 Thread Joshua Batista via Phabricator via cfe-commits
bob80905 updated this revision to Diff 465236.
bob80905 added a comment.

- add new line to end of new files


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135011

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Builtins.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-elementwise-math.c
  clang/test/Sema/aarch64-sve-vector-trig-ops.c
  clang/test/Sema/builtins-elementwise-math.c
  clang/test/Sema/riscv-sve-vector-trig-ops.c
  clang/test/SemaCXX/builtins-elementwise-math.cpp

Index: clang/test/SemaCXX/builtins-elementwise-math.cpp
===
--- clang/test/SemaCXX/builtins-elementwise-math.cpp
+++ clang/test/SemaCXX/builtins-elementwise-math.cpp
@@ -59,3 +59,17 @@
   static_assert(!is_const::value);
   static_assert(!is_const::value);
 }
+
+void test_builtin_elementwise_cos() {
+  const float a = 42.0;
+  float b = 42.3;
+  static_assert(!is_const::value);
+  static_assert(!is_const::value);
+}
+
+void test_builtin_elementwise_sin() {
+  const float a = 42.0;
+  float b = 42.3;
+  static_assert(!is_const::value);
+  static_assert(!is_const::value);
+}
Index: clang/test/Sema/riscv-sve-vector-trig-ops.c
===
--- /dev/null
+++ clang/test/Sema/riscv-sve-vector-trig-ops.c
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-feature +d \
+// RUN:   -target-feature +v -target-feature +zfh -target-feature +experimental-zvfh \
+// RUN:   -disable-O0-optnone -o - -fsyntax-only %s -verify 
+
+#include 
+
+
+vfloat32mf2_t test_sin_vv_i8mf8(vfloat32mf2_t v) {
+
+  return __builtin_elementwise_sin(v);
+  // expected-error@-1 {{1st argument must be a vector, integer or floating point type}}
+}
+
+vfloat32mf2_t test_cos_vv_i8mf8(vfloat32mf2_t v) {
+
+  return __builtin_elementwise_cos(v);
+  // expected-error@-1 {{1st argument must be a vector, integer or floating point type}}
+}
Index: clang/test/Sema/builtins-elementwise-math.c
===
--- clang/test/Sema/builtins-elementwise-math.c
+++ clang/test/Sema/builtins-elementwise-math.c
@@ -280,6 +280,27 @@
   // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
 }
 
+void test_builtin_elementwise_cos(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
+
+  struct Foo s = __builtin_elementwise_cos(f);
+  // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'float'}}
+
+  i = __builtin_elementwise_cos();
+  // expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
+
+  i = __builtin_elementwise_cos(i);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'int')}}
+
+  i = __builtin_elementwise_cos(f, f);
+  // expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
+
+  u = __builtin_elementwise_cos(u);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned int')}}
+
+  uv = __builtin_elementwise_cos(uv);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
+}
+
 void test_builtin_elementwise_floor(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
 
   struct Foo s = __builtin_elementwise_floor(f);
@@ -322,6 +343,27 @@
   // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
 }
 
+void test_builtin_elementwise_sin(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
+
+  struct Foo s = __builtin_elementwise_sin(f);
+  // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'float'}}
+
+  i = __builtin_elementwise_sin();
+  // expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
+
+  i = __builtin_elementwise_sin(i);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'int')}}
+
+  i = __builtin_elementwise_sin(f, f);
+  // expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
+
+  u = __builtin_elementwise_sin(u);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned int')}}
+
+  uv = __builtin_elementwise_sin(uv);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
+}
+
 void test_builtin_elementwise_trunc(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
 
   struct Foo s = __builtin_elementwise_trunc(f);
Index: clang/test/Sema/aarch64-sve-vector-trig-ops.c
===
--- /dev/null
+++ 

[PATCH] D135011: Add builtin_elementwise_sin and builtin_elementwise_cos

2022-10-04 Thread Joshua Batista via Phabricator via cfe-commits
bob80905 updated this revision to Diff 465235.
bob80905 added a comment.
Herald added subscribers: frasercrmck, luismarques, apazos, sameer.abuasal, 
s.egerton, Jim, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, 
edward-jones, zzheng, jrtc27, niosHD, sabuasal, simoncook, johnrusso, rbar, asb.

- add sve tests to prove compiler doesn't crash


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135011

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Builtins.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-elementwise-math.c
  clang/test/Sema/aarch64-sve-vector-trig-ops.c
  clang/test/Sema/builtins-elementwise-math.c
  clang/test/Sema/riscv-sve-vector-trig-ops.c
  clang/test/SemaCXX/builtins-elementwise-math.cpp

Index: clang/test/SemaCXX/builtins-elementwise-math.cpp
===
--- clang/test/SemaCXX/builtins-elementwise-math.cpp
+++ clang/test/SemaCXX/builtins-elementwise-math.cpp
@@ -59,3 +59,17 @@
   static_assert(!is_const::value);
   static_assert(!is_const::value);
 }
+
+void test_builtin_elementwise_cos() {
+  const float a = 42.0;
+  float b = 42.3;
+  static_assert(!is_const::value);
+  static_assert(!is_const::value);
+}
+
+void test_builtin_elementwise_sin() {
+  const float a = 42.0;
+  float b = 42.3;
+  static_assert(!is_const::value);
+  static_assert(!is_const::value);
+}
Index: clang/test/Sema/riscv-sve-vector-trig-ops.c
===
--- /dev/null
+++ clang/test/Sema/riscv-sve-vector-trig-ops.c
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-feature +d \
+// RUN:   -target-feature +v -target-feature +zfh -target-feature +experimental-zvfh \
+// RUN:   -disable-O0-optnone -o - -fsyntax-only %s -verify 
+
+#include 
+
+
+vfloat32mf2_t test_sin_vv_i8mf8(vfloat32mf2_t v) {
+
+  return __builtin_elementwise_sin(v);
+  // expected-error@-1 {{1st argument must be a vector, integer or floating point type}}
+}
+
+vfloat32mf2_t test_cos_vv_i8mf8(vfloat32mf2_t v) {
+
+  return __builtin_elementwise_cos(v);
+  // expected-error@-1 {{1st argument must be a vector, integer or floating point type}}
+}
\ No newline at end of file
Index: clang/test/Sema/builtins-elementwise-math.c
===
--- clang/test/Sema/builtins-elementwise-math.c
+++ clang/test/Sema/builtins-elementwise-math.c
@@ -280,6 +280,27 @@
   // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
 }
 
+void test_builtin_elementwise_cos(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
+
+  struct Foo s = __builtin_elementwise_cos(f);
+  // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'float'}}
+
+  i = __builtin_elementwise_cos();
+  // expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
+
+  i = __builtin_elementwise_cos(i);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'int')}}
+
+  i = __builtin_elementwise_cos(f, f);
+  // expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
+
+  u = __builtin_elementwise_cos(u);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned int')}}
+
+  uv = __builtin_elementwise_cos(uv);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
+}
+
 void test_builtin_elementwise_floor(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
 
   struct Foo s = __builtin_elementwise_floor(f);
@@ -322,6 +343,27 @@
   // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
 }
 
+void test_builtin_elementwise_sin(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
+
+  struct Foo s = __builtin_elementwise_sin(f);
+  // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'float'}}
+
+  i = __builtin_elementwise_sin();
+  // expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
+
+  i = __builtin_elementwise_sin(i);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'int')}}
+
+  i = __builtin_elementwise_sin(f, f);
+  // expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
+
+  u = __builtin_elementwise_sin(u);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned int')}}
+
+  uv = __builtin_elementwise_sin(uv);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
+}
+
 void test_builtin_elementwise_trunc(int i, 

[PATCH] D133823: Add APFloat and MLIR type support for fp8 (e5m2).

2022-10-04 Thread Stella Laurenzo via Phabricator via cfe-commits
stellaraccident updated this revision to Diff 465233.
stellaraccident marked an inline comment as done.
stellaraccident added a comment.

Remove break after llvm_unreachable for consistency with other switches in file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133823

Files:
  clang/lib/AST/MicrosoftMangle.cpp
  llvm/include/llvm/ADT/APFloat.h
  llvm/lib/Support/APFloat.cpp
  llvm/unittests/ADT/APFloatTest.cpp
  mlir/include/mlir-c/BuiltinTypes.h
  mlir/include/mlir/IR/Builders.h
  mlir/include/mlir/IR/BuiltinTypes.h
  mlir/include/mlir/IR/BuiltinTypes.td
  mlir/include/mlir/IR/Types.h
  mlir/lib/AsmParser/TokenKinds.def
  mlir/lib/AsmParser/TypeParser.cpp
  mlir/lib/CAPI/IR/BuiltinTypes.cpp
  mlir/lib/IR/AsmPrinter.cpp
  mlir/lib/IR/Builders.cpp
  mlir/lib/IR/BuiltinTypes.cpp
  mlir/lib/IR/MLIRContext.cpp
  mlir/lib/IR/Types.cpp
  mlir/test/IR/attribute.mlir
  mlir/test/lib/Dialect/Test/TestOps.td

Index: mlir/test/lib/Dialect/Test/TestOps.td
===
--- mlir/test/lib/Dialect/Test/TestOps.td
+++ mlir/test/lib/Dialect/Test/TestOps.td
@@ -193,6 +193,14 @@
   let assemblyFormat = "$attr attr-dict";
 }
 
+def FloatAttrOp : TEST_Op<"float_attrs"> {
+  // TODO: Clean up the OpBase float type and attribute selectors so they
+  // can express all of the types.
+  let arguments = (ins
+AnyAttr:$float_attr
+  );
+}
+
 def I32Case5:  I32EnumAttrCase<"case5", 5>;
 def I32Case10: I32EnumAttrCase<"case10", 10>;
 
Index: mlir/test/IR/attribute.mlir
===
--- mlir/test/IR/attribute.mlir
+++ mlir/test/IR/attribute.mlir
@@ -31,6 +31,42 @@
 
 // -
 
+//===--===//
+// Test float attributes
+//===--===//
+
+func.func @float_attrs_pass() {
+  "test.float_attrs"() {
+// CHECK: float_attr = 2.00e+00 : f8E5M2
+float_attr = 2. : f8E5M2
+  } : () -> ()
+  "test.float_attrs"() {
+// CHECK: float_attr = 2.00e+00 : f16
+float_attr = 2. : f16
+  } : () -> ()
+  "test.float_attrs"() {
+// CHECK: float_attr = 2.00e+00 : bf16
+float_attr = 2. : bf16
+  } : () -> ()
+  "test.float_attrs"() {
+// CHECK: float_attr = 2.00e+00 : f32
+float_attr = 2. : f32
+  } : () -> ()
+  "test.float_attrs"() {
+// CHECK: float_attr = 2.00e+00 : f64
+float_attr = 2. : f64
+  } : () -> ()
+  "test.float_attrs"() {
+// CHECK: float_attr = 2.00e+00 : f80
+float_attr = 2. : f80
+  } : () -> ()
+  "test.float_attrs"() {
+// CHECK: float_attr = 2.00e+00 : f128
+float_attr = 2. : f128
+  } : () -> ()
+  return
+}
+
 //===--===//
 // Test integer attributes
 //===--===//
Index: mlir/lib/IR/Types.cpp
===
--- mlir/lib/IR/Types.cpp
+++ mlir/lib/IR/Types.cpp
@@ -18,6 +18,7 @@
 
 MLIRContext *Type::getContext() const { return getDialect().getContext(); }
 
+bool Type::isFloat8E5M2() const { return isa(); }
 bool Type::isBF16() const { return isa(); }
 bool Type::isF16() const { return isa(); }
 bool Type::isF32() const { return isa(); }
Index: mlir/lib/IR/MLIRContext.cpp
===
--- mlir/lib/IR/MLIRContext.cpp
+++ mlir/lib/IR/MLIRContext.cpp
@@ -206,6 +206,7 @@
   StorageUniquer typeUniquer;
 
   /// Cached Type Instances.
+  Float8E5M2Type f8E5M2Ty;
   BFloat16Type bf16Ty;
   Float16Type f16Ty;
   Float32Type f32Ty;
@@ -276,6 +277,7 @@
 
    Types.
   /// Floating-point Types.
+  impl->f8E5M2Ty = TypeUniquer::get(this);
   impl->bf16Ty = TypeUniquer::get(this);
   impl->f16Ty = TypeUniquer::get(this);
   impl->f32Ty = TypeUniquer::get(this);
@@ -840,6 +842,9 @@
 /// This should not be used directly.
 StorageUniquer ::getTypeUniquer() { return getImpl().typeUniquer; }
 
+Float8E5M2Type Float8E5M2Type::get(MLIRContext *context) {
+  return context->getImpl().f8E5M2Ty;
+}
 BFloat16Type BFloat16Type::get(MLIRContext *context) {
   return context->getImpl().bf16Ty;
 }
Index: mlir/lib/IR/BuiltinTypes.cpp
===
--- mlir/lib/IR/BuiltinTypes.cpp
+++ mlir/lib/IR/BuiltinTypes.cpp
@@ -88,6 +88,8 @@
 //===--===//
 
 unsigned FloatType::getWidth() {
+  if (isa())
+return 8;
   if (isa())
 return 16;
   if (isa())
@@ -103,6 +105,8 @@
 
 /// Returns the floating semantics for the given type.
 const llvm::fltSemantics ::getFloatSemantics() {
+  if (isa())
+return APFloat::Float8E5M2();
   if (isa())
 return APFloat::BFloat();
   if (isa())
Index: 

[PATCH] D133823: Add APFloat and MLIR type support for fp8 (e5m2).

2022-10-04 Thread Stella Laurenzo via Phabricator via cfe-commits
stellaraccident updated this revision to Diff 465231.
stellaraccident added a comment.

Switch to explicit case per comment from ctopper.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133823

Files:
  clang/lib/AST/MicrosoftMangle.cpp
  llvm/include/llvm/ADT/APFloat.h
  llvm/lib/Support/APFloat.cpp
  llvm/unittests/ADT/APFloatTest.cpp
  mlir/include/mlir-c/BuiltinTypes.h
  mlir/include/mlir/IR/Builders.h
  mlir/include/mlir/IR/BuiltinTypes.h
  mlir/include/mlir/IR/BuiltinTypes.td
  mlir/include/mlir/IR/Types.h
  mlir/lib/AsmParser/TokenKinds.def
  mlir/lib/AsmParser/TypeParser.cpp
  mlir/lib/CAPI/IR/BuiltinTypes.cpp
  mlir/lib/IR/AsmPrinter.cpp
  mlir/lib/IR/Builders.cpp
  mlir/lib/IR/BuiltinTypes.cpp
  mlir/lib/IR/MLIRContext.cpp
  mlir/lib/IR/Types.cpp
  mlir/test/IR/attribute.mlir
  mlir/test/lib/Dialect/Test/TestOps.td

Index: mlir/test/lib/Dialect/Test/TestOps.td
===
--- mlir/test/lib/Dialect/Test/TestOps.td
+++ mlir/test/lib/Dialect/Test/TestOps.td
@@ -193,6 +193,14 @@
   let assemblyFormat = "$attr attr-dict";
 }
 
+def FloatAttrOp : TEST_Op<"float_attrs"> {
+  // TODO: Clean up the OpBase float type and attribute selectors so they
+  // can express all of the types.
+  let arguments = (ins
+AnyAttr:$float_attr
+  );
+}
+
 def I32Case5:  I32EnumAttrCase<"case5", 5>;
 def I32Case10: I32EnumAttrCase<"case10", 10>;
 
Index: mlir/test/IR/attribute.mlir
===
--- mlir/test/IR/attribute.mlir
+++ mlir/test/IR/attribute.mlir
@@ -31,6 +31,42 @@
 
 // -
 
+//===--===//
+// Test float attributes
+//===--===//
+
+func.func @float_attrs_pass() {
+  "test.float_attrs"() {
+// CHECK: float_attr = 2.00e+00 : f8E5M2
+float_attr = 2. : f8E5M2
+  } : () -> ()
+  "test.float_attrs"() {
+// CHECK: float_attr = 2.00e+00 : f16
+float_attr = 2. : f16
+  } : () -> ()
+  "test.float_attrs"() {
+// CHECK: float_attr = 2.00e+00 : bf16
+float_attr = 2. : bf16
+  } : () -> ()
+  "test.float_attrs"() {
+// CHECK: float_attr = 2.00e+00 : f32
+float_attr = 2. : f32
+  } : () -> ()
+  "test.float_attrs"() {
+// CHECK: float_attr = 2.00e+00 : f64
+float_attr = 2. : f64
+  } : () -> ()
+  "test.float_attrs"() {
+// CHECK: float_attr = 2.00e+00 : f80
+float_attr = 2. : f80
+  } : () -> ()
+  "test.float_attrs"() {
+// CHECK: float_attr = 2.00e+00 : f128
+float_attr = 2. : f128
+  } : () -> ()
+  return
+}
+
 //===--===//
 // Test integer attributes
 //===--===//
Index: mlir/lib/IR/Types.cpp
===
--- mlir/lib/IR/Types.cpp
+++ mlir/lib/IR/Types.cpp
@@ -18,6 +18,7 @@
 
 MLIRContext *Type::getContext() const { return getDialect().getContext(); }
 
+bool Type::isFloat8E5M2() const { return isa(); }
 bool Type::isBF16() const { return isa(); }
 bool Type::isF16() const { return isa(); }
 bool Type::isF32() const { return isa(); }
Index: mlir/lib/IR/MLIRContext.cpp
===
--- mlir/lib/IR/MLIRContext.cpp
+++ mlir/lib/IR/MLIRContext.cpp
@@ -206,6 +206,7 @@
   StorageUniquer typeUniquer;
 
   /// Cached Type Instances.
+  Float8E5M2Type f8E5M2Ty;
   BFloat16Type bf16Ty;
   Float16Type f16Ty;
   Float32Type f32Ty;
@@ -276,6 +277,7 @@
 
    Types.
   /// Floating-point Types.
+  impl->f8E5M2Ty = TypeUniquer::get(this);
   impl->bf16Ty = TypeUniquer::get(this);
   impl->f16Ty = TypeUniquer::get(this);
   impl->f32Ty = TypeUniquer::get(this);
@@ -840,6 +842,9 @@
 /// This should not be used directly.
 StorageUniquer ::getTypeUniquer() { return getImpl().typeUniquer; }
 
+Float8E5M2Type Float8E5M2Type::get(MLIRContext *context) {
+  return context->getImpl().f8E5M2Ty;
+}
 BFloat16Type BFloat16Type::get(MLIRContext *context) {
   return context->getImpl().bf16Ty;
 }
Index: mlir/lib/IR/BuiltinTypes.cpp
===
--- mlir/lib/IR/BuiltinTypes.cpp
+++ mlir/lib/IR/BuiltinTypes.cpp
@@ -88,6 +88,8 @@
 //===--===//
 
 unsigned FloatType::getWidth() {
+  if (isa())
+return 8;
   if (isa())
 return 16;
   if (isa())
@@ -103,6 +105,8 @@
 
 /// Returns the floating semantics for the given type.
 const llvm::fltSemantics ::getFloatSemantics() {
+  if (isa())
+return APFloat::Float8E5M2();
   if (isa())
 return APFloat::BFloat();
   if (isa())
Index: mlir/lib/IR/Builders.cpp

[PATCH] D133823: Add APFloat and MLIR type support for fp8 (e5m2).

2022-10-04 Thread Stella Laurenzo via Phabricator via cfe-commits
stellaraccident updated this revision to Diff 465230.
stellaraccident added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add fix to MicrosoftMangle.cpp that caused buildbot failure.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133823

Files:
  clang/lib/AST/MicrosoftMangle.cpp
  llvm/include/llvm/ADT/APFloat.h
  llvm/lib/Support/APFloat.cpp
  llvm/unittests/ADT/APFloatTest.cpp
  mlir/include/mlir-c/BuiltinTypes.h
  mlir/include/mlir/IR/Builders.h
  mlir/include/mlir/IR/BuiltinTypes.h
  mlir/include/mlir/IR/BuiltinTypes.td
  mlir/include/mlir/IR/Types.h
  mlir/lib/AsmParser/TokenKinds.def
  mlir/lib/AsmParser/TypeParser.cpp
  mlir/lib/CAPI/IR/BuiltinTypes.cpp
  mlir/lib/IR/AsmPrinter.cpp
  mlir/lib/IR/Builders.cpp
  mlir/lib/IR/BuiltinTypes.cpp
  mlir/lib/IR/MLIRContext.cpp
  mlir/lib/IR/Types.cpp
  mlir/test/IR/attribute.mlir
  mlir/test/lib/Dialect/Test/TestOps.td

Index: mlir/test/lib/Dialect/Test/TestOps.td
===
--- mlir/test/lib/Dialect/Test/TestOps.td
+++ mlir/test/lib/Dialect/Test/TestOps.td
@@ -193,6 +193,14 @@
   let assemblyFormat = "$attr attr-dict";
 }
 
+def FloatAttrOp : TEST_Op<"float_attrs"> {
+  // TODO: Clean up the OpBase float type and attribute selectors so they
+  // can express all of the types.
+  let arguments = (ins
+AnyAttr:$float_attr
+  );
+}
+
 def I32Case5:  I32EnumAttrCase<"case5", 5>;
 def I32Case10: I32EnumAttrCase<"case10", 10>;
 
Index: mlir/test/IR/attribute.mlir
===
--- mlir/test/IR/attribute.mlir
+++ mlir/test/IR/attribute.mlir
@@ -31,6 +31,42 @@
 
 // -
 
+//===--===//
+// Test float attributes
+//===--===//
+
+func.func @float_attrs_pass() {
+  "test.float_attrs"() {
+// CHECK: float_attr = 2.00e+00 : f8E5M2
+float_attr = 2. : f8E5M2
+  } : () -> ()
+  "test.float_attrs"() {
+// CHECK: float_attr = 2.00e+00 : f16
+float_attr = 2. : f16
+  } : () -> ()
+  "test.float_attrs"() {
+// CHECK: float_attr = 2.00e+00 : bf16
+float_attr = 2. : bf16
+  } : () -> ()
+  "test.float_attrs"() {
+// CHECK: float_attr = 2.00e+00 : f32
+float_attr = 2. : f32
+  } : () -> ()
+  "test.float_attrs"() {
+// CHECK: float_attr = 2.00e+00 : f64
+float_attr = 2. : f64
+  } : () -> ()
+  "test.float_attrs"() {
+// CHECK: float_attr = 2.00e+00 : f80
+float_attr = 2. : f80
+  } : () -> ()
+  "test.float_attrs"() {
+// CHECK: float_attr = 2.00e+00 : f128
+float_attr = 2. : f128
+  } : () -> ()
+  return
+}
+
 //===--===//
 // Test integer attributes
 //===--===//
Index: mlir/lib/IR/Types.cpp
===
--- mlir/lib/IR/Types.cpp
+++ mlir/lib/IR/Types.cpp
@@ -18,6 +18,7 @@
 
 MLIRContext *Type::getContext() const { return getDialect().getContext(); }
 
+bool Type::isFloat8E5M2() const { return isa(); }
 bool Type::isBF16() const { return isa(); }
 bool Type::isF16() const { return isa(); }
 bool Type::isF32() const { return isa(); }
Index: mlir/lib/IR/MLIRContext.cpp
===
--- mlir/lib/IR/MLIRContext.cpp
+++ mlir/lib/IR/MLIRContext.cpp
@@ -206,6 +206,7 @@
   StorageUniquer typeUniquer;
 
   /// Cached Type Instances.
+  Float8E5M2Type f8E5M2Ty;
   BFloat16Type bf16Ty;
   Float16Type f16Ty;
   Float32Type f32Ty;
@@ -276,6 +277,7 @@
 
    Types.
   /// Floating-point Types.
+  impl->f8E5M2Ty = TypeUniquer::get(this);
   impl->bf16Ty = TypeUniquer::get(this);
   impl->f16Ty = TypeUniquer::get(this);
   impl->f32Ty = TypeUniquer::get(this);
@@ -840,6 +842,9 @@
 /// This should not be used directly.
 StorageUniquer ::getTypeUniquer() { return getImpl().typeUniquer; }
 
+Float8E5M2Type Float8E5M2Type::get(MLIRContext *context) {
+  return context->getImpl().f8E5M2Ty;
+}
 BFloat16Type BFloat16Type::get(MLIRContext *context) {
   return context->getImpl().bf16Ty;
 }
Index: mlir/lib/IR/BuiltinTypes.cpp
===
--- mlir/lib/IR/BuiltinTypes.cpp
+++ mlir/lib/IR/BuiltinTypes.cpp
@@ -88,6 +88,8 @@
 //===--===//
 
 unsigned FloatType::getWidth() {
+  if (isa())
+return 8;
   if (isa())
 return 16;
   if (isa())
@@ -103,6 +105,8 @@
 
 /// Returns the floating semantics for the given type.
 const llvm::fltSemantics ::getFloatSemantics() {
+  if (isa())
+return APFloat::Float8E5M2();
   if (isa())
 return APFloat::BFloat();
   if (isa())
Index: 

[PATCH] D135171: FreeBSD: enable __float128 on x86

2022-10-04 Thread Brooks Davis via Phabricator via cfe-commits
brooks updated this revision to Diff 465223.
brooks added a comment.

Add a test as requested by @arichardson


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135171

Files:
  clang/lib/Basic/Targets/OSTargets.h
  clang/test/CodeGenCXX/float128-declarations.cpp


Index: clang/test/CodeGenCXX/float128-declarations.cpp
===
--- clang/test/CodeGenCXX/float128-declarations.cpp
+++ clang/test/CodeGenCXX/float128-declarations.cpp
@@ -2,6 +2,8 @@
 // RUN:   -target-feature +float128 -std=c++11 %s -o - | FileCheck %s
 // RUN: %clang_cc1 -no-opaque-pointers -emit-llvm -triple 
powerpc64le-unknown-unknown \
 // RUN:   -target-feature +float128 -std=c++11 %s -o - | FileCheck %s
+// RUN: %clang_cc1 -no-opaque-pointers -emit-llvm -triple 
x86_64-unknown-freebsd -std=c++11 \
+// RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
 // RUN: %clang_cc1 -no-opaque-pointers -emit-llvm -triple 
i386-unknown-linux-gnu -std=c++11 \
 // RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
 // RUN: %clang_cc1 -no-opaque-pointers -emit-llvm -triple 
x86_64-unknown-linux-gnu -std=c++11 \
Index: clang/lib/Basic/Targets/OSTargets.h
===
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -232,15 +232,20 @@
 // setting this to 1 is conforming even if all the basic source
 // character literals have the same encoding as char and wchar_t.
 Builder.defineMacro("__STDC_MB_MIGHT_NEQ_WC__", "1");
+
+if (this->HasFloat128)
+  Builder.defineMacro("__FLOAT128__");
   }
 
 public:
   FreeBSDTargetInfo(const llvm::Triple , const TargetOptions )
   : OSTargetInfo(Triple, Opts) {
 switch (Triple.getArch()) {
-default:
 case llvm::Triple::x86:
 case llvm::Triple::x86_64:
+  this->HasFloat128 = true;
+  [[fallthrough]];
+default:
   this->MCountName = ".mcount";
   break;
 case llvm::Triple::mips:


Index: clang/test/CodeGenCXX/float128-declarations.cpp
===
--- clang/test/CodeGenCXX/float128-declarations.cpp
+++ clang/test/CodeGenCXX/float128-declarations.cpp
@@ -2,6 +2,8 @@
 // RUN:   -target-feature +float128 -std=c++11 %s -o - | FileCheck %s
 // RUN: %clang_cc1 -no-opaque-pointers -emit-llvm -triple powerpc64le-unknown-unknown \
 // RUN:   -target-feature +float128 -std=c++11 %s -o - | FileCheck %s
+// RUN: %clang_cc1 -no-opaque-pointers -emit-llvm -triple x86_64-unknown-freebsd -std=c++11 \
+// RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
 // RUN: %clang_cc1 -no-opaque-pointers -emit-llvm -triple i386-unknown-linux-gnu -std=c++11 \
 // RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
 // RUN: %clang_cc1 -no-opaque-pointers -emit-llvm -triple x86_64-unknown-linux-gnu -std=c++11 \
Index: clang/lib/Basic/Targets/OSTargets.h
===
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -232,15 +232,20 @@
 // setting this to 1 is conforming even if all the basic source
 // character literals have the same encoding as char and wchar_t.
 Builder.defineMacro("__STDC_MB_MIGHT_NEQ_WC__", "1");
+
+if (this->HasFloat128)
+  Builder.defineMacro("__FLOAT128__");
   }
 
 public:
   FreeBSDTargetInfo(const llvm::Triple , const TargetOptions )
   : OSTargetInfo(Triple, Opts) {
 switch (Triple.getArch()) {
-default:
 case llvm::Triple::x86:
 case llvm::Triple::x86_64:
+  this->HasFloat128 = true;
+  [[fallthrough]];
+default:
   this->MCountName = ".mcount";
   break;
 case llvm::Triple::mips:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D135224: [Clang][OpenMP] Only check value if the expression is not instantiation dependent

2022-10-04 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

Test is needed


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135224

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


[PATCH] D135226: [clangd] Optimize Dex::generateProximityURIs().

2022-10-04 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: adamcz.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Production profiles show that generateProximityURIs is roughly 3.8% of
buildPreamble. Of this, the majority (3% of buildPreamble) is parsing
and reserializing URIs.

We can do this with ugly string manipulation instead.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135226

Files:
  clang-tools-extra/clangd/index/dex/Dex.cpp
  clang-tools-extra/clangd/index/dex/Dex.h

Index: clang-tools-extra/clangd/index/dex/Dex.h
===
--- clang-tools-extra/clangd/index/dex/Dex.h
+++ clang-tools-extra/clangd/index/dex/Dex.h
@@ -132,7 +132,7 @@
 /// Should be used within the index build process.
 ///
 /// This function is exposed for testing only.
-std::vector generateProximityURIs(llvm::StringRef URIPath);
+llvm::SmallVector generateProximityURIs(const char *);
 
 } // namespace dex
 } // namespace clangd
Index: clang-tools-extra/clangd/index/dex/Dex.cpp
===
--- clang-tools-extra/clangd/index/dex/Dex.cpp
+++ clang-tools-extra/clangd/index/dex/Dex.cpp
@@ -163,8 +163,8 @@
   llvm::StringMap Sources;
   for (const auto  : ProximityPaths) {
 Sources[Path] = SourceParams();
-auto PathURI = URI::create(Path);
-const auto PathProximityURIs = generateProximityURIs(PathURI.toString());
+auto PathURI = URI::create(Path).toString();
+const auto PathProximityURIs = generateProximityURIs(PathURI.c_str());
 for (const auto  : PathProximityURIs)
   ParentURIs.insert(ProximityURI);
   }
@@ -353,30 +353,59 @@
   return Bytes + BackingDataSize;
 }
 
-std::vector generateProximityURIs(llvm::StringRef URIPath) {
-  std::vector Result;
-  auto ParsedURI = URI::parse(URIPath);
-  assert(ParsedURI &&
- "Non-empty argument of generateProximityURIs() should be a valid "
- "URI.");
-  llvm::StringRef Body = ParsedURI->body();
-  // FIXME(kbobyrev): Currently, this is a heuristic which defines the maximum
-  // size of resulting vector. Some projects might want to have higher limit if
-  // the file hierarchy is deeper. For the generic case, it would be useful to
-  // calculate Limit in the index build stage by calculating the maximum depth
-  // of the project source tree at runtime.
-  size_t Limit = 5;
-  // Insert original URI before the loop: this would save a redundant iteration
-  // with a URI parse.
-  Result.emplace_back(ParsedURI->toString());
-  while (!Body.empty() && --Limit > 0) {
-// FIXME(kbobyrev): Parsing and encoding path to URIs is not necessary and
-// could be optimized.
-Body = llvm::sys::path::parent_path(Body, llvm::sys::path::Style::posix);
-if (!Body.empty())
-  Result.emplace_back(
-  URI(ParsedURI->scheme(), ParsedURI->authority(), Body).toString());
+// Given foo://bar/one/two
+// Returns^
+const char *findPathInURI(const char *S) {
+  // Skip over scheme.
+  for (;;) {
+if (!*S)
+  return S;
+if (*S++ == ':')
+  break;
   }
+  // Skip over authority.
+  if (*S == '/' && *(S+1) == '/') {
+S += 2;
+while (*S && *S != '/')
+  ++S;
+  }
+  return S;
+}
+
+// FIXME(kbobyrev): Currently, this is a heuristic which defines the maximum
+// size of resulting vector. Some projects might want to have higher limit if
+// the file hierarchy is deeper. For the generic case, it would be useful to
+// calculate Limit in the index build stage by calculating the maximum depth
+// of the project source tree at runtime.
+constexpr unsigned ProximityURILimit = 5;
+
+llvm::SmallVector
+generateProximityURIs(const char *URI) {
+  // This function is hot when indexing, so don't parse/reserialize URIPath,
+  // just emit substrings of it instead.
+  //
+  // foo://bar/one/two
+  // ^URI ^Path   ^End
+  const char *Path = findPathInURI(URI);
+  const char *End = Path;
+  while (*End)
+++End;
+  // The original URI is a proximity path.
+  llvm::SmallVector Result = {
+  StringRef(URI, End - URI)};
+  unsigned Limit = ProximityURILimit - 1;
+  while (--End != Path) { // foo://bar is not a proximity path.
+if (*End == '/') {
+  // foo://bar/one/two
+  //  ^End
+  Result.push_back(StringRef(URI, End - URI));
+  if (--Limit == 0)
+return Result;
+}
+  }
+  // The root foo://bar/ is a proximity path.
+  if (*Path == '/')
+Result.push_back(StringRef(URI, Path + 1 - URI));
   return Result;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D135224: [Clang][OpenMP] Only check value if the expression is not instantiation dependent

2022-10-04 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 created this revision.
tianshilei1992 added reviewers: jdoerfert, ABataev.
Herald added subscribers: guansong, yaxunl.
Herald added a project: All.
tianshilei1992 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

Currently the following case fails:

  template
  Ty foo(Ty *addr, Ty val) {
Ty v;
  #pragma omp atomic compare capture
{
  v = *addr;
  if (*addr > val)
*addr = val;
}
return v;
  }

The compiler complains `addr` is not a lvalue. That's because when an expression
is instantiation dependent, we cannot tell if it is lvalue or not.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135224

Files:
  clang/lib/Sema/SemaOpenMP.cpp


Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -11577,6 +11577,9 @@
 
   static bool CheckValue(const Expr *E, ErrorInfoTy ,
  bool ShouldBeLValue, bool ShouldBeInteger = false) {
+if (E->isInstantiationDependent())
+  return true;
+
 if (ShouldBeLValue && !E->isLValue()) {
   ErrorInfo.Error = ErrorTy::XNotLValue;
   ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = E->getExprLoc();
@@ -11584,25 +11587,23 @@
   return false;
 }
 
-if (!E->isInstantiationDependent()) {
-  QualType QTy = E->getType();
-  if (!QTy->isScalarType()) {
-ErrorInfo.Error = ErrorTy::NotScalar;
-ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = E->getExprLoc();
-ErrorInfo.ErrorRange = ErrorInfo.NoteRange = E->getSourceRange();
-return false;
-  }
-  if (ShouldBeInteger && !QTy->isIntegerType()) {
-ErrorInfo.Error = ErrorTy::NotInteger;
-ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = E->getExprLoc();
-ErrorInfo.ErrorRange = ErrorInfo.NoteRange = E->getSourceRange();
-return false;
-  }
+QualType QTy = E->getType();
+if (!QTy->isScalarType()) {
+  ErrorInfo.Error = ErrorTy::NotScalar;
+  ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = E->getExprLoc();
+  ErrorInfo.ErrorRange = ErrorInfo.NoteRange = E->getSourceRange();
+  return false;
+}
+if (ShouldBeInteger && !QTy->isIntegerType()) {
+  ErrorInfo.Error = ErrorTy::NotInteger;
+  ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = E->getExprLoc();
+  ErrorInfo.ErrorRange = ErrorInfo.NoteRange = E->getSourceRange();
+  return false;
 }
 
 return true;
   }
-};
+  };
 
 bool OpenMPAtomicCompareChecker::checkCondUpdateStmt(IfStmt *S,
  ErrorInfoTy ) {


Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -11577,6 +11577,9 @@
 
   static bool CheckValue(const Expr *E, ErrorInfoTy ,
  bool ShouldBeLValue, bool ShouldBeInteger = false) {
+if (E->isInstantiationDependent())
+  return true;
+
 if (ShouldBeLValue && !E->isLValue()) {
   ErrorInfo.Error = ErrorTy::XNotLValue;
   ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = E->getExprLoc();
@@ -11584,25 +11587,23 @@
   return false;
 }
 
-if (!E->isInstantiationDependent()) {
-  QualType QTy = E->getType();
-  if (!QTy->isScalarType()) {
-ErrorInfo.Error = ErrorTy::NotScalar;
-ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = E->getExprLoc();
-ErrorInfo.ErrorRange = ErrorInfo.NoteRange = E->getSourceRange();
-return false;
-  }
-  if (ShouldBeInteger && !QTy->isIntegerType()) {
-ErrorInfo.Error = ErrorTy::NotInteger;
-ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = E->getExprLoc();
-ErrorInfo.ErrorRange = ErrorInfo.NoteRange = E->getSourceRange();
-return false;
-  }
+QualType QTy = E->getType();
+if (!QTy->isScalarType()) {
+  ErrorInfo.Error = ErrorTy::NotScalar;
+  ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = E->getExprLoc();
+  ErrorInfo.ErrorRange = ErrorInfo.NoteRange = E->getSourceRange();
+  return false;
+}
+if (ShouldBeInteger && !QTy->isIntegerType()) {
+  ErrorInfo.Error = ErrorTy::NotInteger;
+  ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = E->getExprLoc();
+  ErrorInfo.ErrorRange = ErrorInfo.NoteRange = E->getSourceRange();
+  return false;
 }
 
 return true;
   }
-};
+  };
 
 bool OpenMPAtomicCompareChecker::checkCondUpdateStmt(IfStmt *S,
  ErrorInfoTy ) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129156: Add -fpass-plugin option to Flang

2022-10-04 Thread Tarun Prabhu via Phabricator via cfe-commits
tarunprabhu added a comment.

Thanks for the review and the comments. :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129156

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


[PATCH] D129156: Add -fpass-plugin option to Flang

2022-10-04 Thread Tarun Prabhu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG43fe6f7cc35d: [flang] Add -fpass-plugin option to Flang 
frontend (authored by tarunprabhu).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129156

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/docs/FlangDriver.md
  flang/docs/ReleaseNotes.md
  flang/include/flang/Frontend/CodeGenOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/frontend-forwarding.f90
  flang/test/Driver/pass-plugin-not-found.f90
  flang/test/Driver/pass-plugin.f90

Index: flang/test/Driver/pass-plugin.f90
===
--- /dev/null
+++ flang/test/Driver/pass-plugin.f90
@@ -0,0 +1,13 @@
+! Verify that the plugin passed to -fpass-plugin is loaded and run
+
+! UNSUPPORTED: system-windows
+
+! REQUIRES: plugins, shell
+
+! RUN: %flang -S %s -fpass-plugin=%llvmshlibdir/Bye%pluginext -Xflang -fdebug-pass-manager -o /dev/null 2>&1 | FileCheck %s
+! RUN: %flang_fc1 -S %s -fpass-plugin=%llvmshlibdir/Bye%pluginext -fdebug-pass-manager -o /dev/null 2>&1 | FileCheck %s
+
+! CHECK: Running pass: {{.*}}Bye on empty_
+
+subroutine empty
+end subroutine empty
Index: flang/test/Driver/pass-plugin-not-found.f90
===
--- /dev/null
+++ flang/test/Driver/pass-plugin-not-found.f90
@@ -0,0 +1,8 @@
+! Check the correct error diagnostic is reported when a pass plugin shared object isn't found
+
+! REQUIRES: plugins, shell
+
+! RUN: not %flang -fpass-plugin=X.Y %s 2>&1 | FileCheck %s --check-prefix=ERROR
+! RUN: not %flang_fc1 -emit-llvm -o /dev/null -fpass-plugin=X.Y %s 2>&1 | FileCheck %s --check-prefix=ERROR
+
+! ERROR: error: unable to load plugin 'X.Y': 'Could not load library 'X.Y': X.Y: cannot open shared object file: No such file or directory'
Index: flang/test/Driver/frontend-forwarding.f90
===
--- flang/test/Driver/frontend-forwarding.f90
+++ flang/test/Driver/frontend-forwarding.f90
@@ -7,6 +7,7 @@
 ! RUN: -fdefault-integer-8 \
 ! RUN: -fdefault-real-8 \
 ! RUN: -flarge-sizes \
+! RUN: -fpass-plugin=Bye%pluginext \
 ! RUN: -mllvm -print-before-all\
 ! RUN: -P \
 ! RUN:   | FileCheck %s
@@ -17,4 +18,5 @@
 ! CHECK: "-fdefault-integer-8"
 ! CHECK: "-fdefault-real-8"
 ! CHECK: "-flarge-sizes"
-! CHECK:  "-mllvm" "-print-before-all"
+! CHECK: "-fpass-plugin=Bye
+! CHECK: "-mllvm" "-print-before-all"
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -42,6 +42,7 @@
 ! HELP-NEXT: -fno-integrated-as  Disable the integrated assembler
 ! HELP-NEXT: -fopenacc  Enable OpenACC
 ! HELP-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
+! HELP-NEXT: -fpass-plugin= Load pass plugin from a dynamic shared object file (only with new pass manager).
 ! HELP-NEXT: -fsyntax-only  Run the preprocessor, parser and semantic analysis stages
 ! HELP-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
 ! HELP-NEXT: -help  Display available options
@@ -120,6 +121,7 @@
 ! HELP-FC1-NEXT: -fno-reformat  Dump the cooked character stream in -E mode
 ! HELP-FC1-NEXT: -fopenacc  Enable OpenACC
 ! HELP-FC1-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
+! HELP-FC1-NEXT: -fpass-plugin= Load pass plugin from a dynamic shared object file (only with new pass manager).
 ! HELP-FC1-NEXT: -fsyntax-only  Run the preprocessor, parser and semantic analysis stages
 ! HELP-FC1-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
 ! HELP-FC1-NEXT: -help  Display available options
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -44,6 +44,7 @@
 ! CHECK-NEXT: -fno-integrated-as Disable the integrated assembler
 ! CHECK-NEXT: -fopenacc  Enable OpenACC
 ! CHECK-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
+! CHECK-NEXT: -fpass-plugin= Load pass plugin from a dynamic shared object file (only with new pass manager).
 ! CHECK-NEXT: -fsyntax-only  Run the preprocessor, parser and semantic analysis stages
 ! CHECK-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
 ! CHECK-NEXT: -help Display available options
@@ -71,4 +72,3 @@
 
 ! Frontend 

[clang] 43fe6f7 - [flang] Add -fpass-plugin option to Flang frontend

2022-10-04 Thread Tarun Prabhu via cfe-commits

Author: Tarun Prabhu
Date: 2022-10-04T17:02:45-06:00
New Revision: 43fe6f7cc35ded691bbc2fa844086d321e705d46

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

LOG: [flang] Add -fpass-plugin option to Flang frontend

Add the -fpass-plugin option to flang which dynamically loads LLVM passes from 
the
shared object passed as the argument to the flag. The behavior of the option is
designed to replicate that of the same option in clang and thus has the same
capabilities and limitations.

- Multiple instances of -fpass-plugin=path-to-file can be specified and each of 
the
  files will be loaded in that order.

- The flag can be passed to both flang-new and flang-new -fc1.

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

Added: 
flang/test/Driver/pass-plugin-not-found.f90
flang/test/Driver/pass-plugin.f90

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Flang.cpp
flang/docs/FlangDriver.md
flang/docs/ReleaseNotes.md
flang/include/flang/Frontend/CodeGenOptions.h
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendActions.cpp
flang/test/Driver/driver-help-hidden.f90
flang/test/Driver/driver-help.f90
flang/test/Driver/frontend-forwarding.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 0b795184b7bd0..f09025d34346c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2710,7 +2710,7 @@ def fplugin_arg : Joined<["-"], "fplugin-arg-">,
   MetaVarName<"-">,
   HelpText<"Pass  to plugin ">;
 def fpass_plugin_EQ : Joined<["-"], "fpass-plugin=">,
-  Group, Flags<[CC1Option]>, MetaVarName<"">,
+  Group, Flags<[CC1Option,FlangOption,FC1Option]>, 
MetaVarName<"">,
   HelpText<"Load pass plugin from a dynamic shared object file (only with new 
pass manager).">,
   MarshallingInfoStringVector>;
 defm preserve_as_comments : BoolFOption<"preserve-as-comments",

diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index b279529a33184..9fe83ed0886b4 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -55,7 +55,8 @@ void Flang::AddOtherOptions(const ArgList , 
ArgStringList ) const {
   Args.AddAllArgs(CmdArgs,
   {options::OPT_module_dir, options::OPT_fdebug_module_writer,
options::OPT_fintrinsic_modules_path, options::OPT_pedantic,
-   options::OPT_std_EQ, options::OPT_W_Joined});
+   options::OPT_std_EQ, options::OPT_W_Joined,
+   options::OPT_fpass_plugin_EQ});
 }
 
 void Flang::AddPicOptions(const ArgList , ArgStringList ) const {

diff  --git a/flang/docs/FlangDriver.md b/flang/docs/FlangDriver.md
index af1fddc8f750a..b44f44efc93fa 100644
--- a/flang/docs/FlangDriver.md
+++ b/flang/docs/FlangDriver.md
@@ -507,3 +507,28 @@ Lastly, if `ParseTree` modifications are performed, then 
it might be necessary
 to re-analyze expressions and modify scope or symbols. You can check
 [Semantics.md](Semantics.md) for more details on how `ParseTree` is edited
 e.g. during the semantic checks.
+
+# LLVM Pass Plugins
+
+Pass plugins are dynamic shared objects that consist of one or more LLVM IR
+passes. The `-fpass-plugin` option enables these passes to be passed to the 
+middle-end where they are added to the optimization pass pipeline and run after
+lowering to LLVM IR.The exact position of the pass in the pipeline will depend 
+on how it has been registered with the `llvm::PassBuilder`. See the 
+documentation for 
+[`llvm::PassBuilder`](https://llvm.org/doxygen/classllvm_1_1PassBuilder.html)
+for details. 
+
+The framework to enable pass plugins in `flang-new` uses the exact same 
+machinery as that used by `clang` and thus has the same capabilities and
+limitations. 
+
+In order to use a pass plugin, the pass(es) must be compiled into a dynamic 
+shared object which is then loaded using the `-fpass-plugin` option. 
+
+```
+flang-new -fpass-plugin=/path/to/plugin.so 
+```
+
+This option is available in both the compiler driver and the frontend driver. 
+Note that LLVM plugins are not officially supported on Windows.

diff  --git a/flang/docs/ReleaseNotes.md b/flang/docs/ReleaseNotes.md
index fd1db3b00eb83..0cc85db9debc5 100644
--- a/flang/docs/ReleaseNotes.md
+++ b/flang/docs/ReleaseNotes.md
@@ -24,6 +24,10 @@ page](https://llvm.org/releases/).
 
 ## Major New Features
 
+* Flang now supports loading LLVM pass plugins with the `-fpass-plugin` option
+  which is also available in clang. The option mimics the behavior of the
+  corresponding option in clang and has the same capabilities and limitations.
+
 ## Bug Fixes
 
 ## Non-comprehensive 

[PATCH] D129531: [clang][C++20] P0960R3: Allow initializing aggregates from a parenthesized list of values

2022-10-04 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao added inline comments.



Comment at: clang/lib/Sema/SemaInit.cpp:4151
+  QualType T = Entity.getType();
+  // FIXME: Union is unsupported.
+  int InitKind = T->isArrayType() ? 0 : 4;

ayzhao wrote:
> Hmm...it seems like as is this patch generates the correct code for 
> parentheses-initialized `union`s:
> 
> ```
> % cat ~/src/tests/test-union.cc
> union C {
>   float a;
>   double b;
> };
> 
> 
> C foo() {
>   return C(1);
> }
> 
> % bin/clang++ -std=c++20 -emit-llvm -S -c -o - ~/src/tests/test-union.cc
> ; ModuleID = '/usr/local/google/home/ayzhao/src/tests/test-union.cc'
> source_filename = "/usr/local/google/home/ayzhao/src/tests/test-union.cc"
> target datalayout = 
> "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
> target triple = "x86_64-unknown-linux-gnu"
> 
> %union.C = type { double }
> 
> ; Function Attrs: mustprogress noinline nounwind optnone uwtable
> define dso_local double @_Z3foov() #0 {
> entry:
>   %retval = alloca %union.C, align 8
>   store float 1.00e+00, ptr %retval, align 8
>   %coerce.dive = getelementptr inbounds %union.C, ptr %retval, i32 0, i32 0
>   %0 = load double, ptr %coerce.dive, align 8
>   ret double %0
> }
> 
> attributes #0 = { mustprogress noinline nounwind optnone uwtable 
> "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" 
> "stack-protector-buffer-size"="8" "target-cpu"="x86-64" 
> "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
> 
> !llvm.linker.options = !{}
> !llvm.module.flags = !{!0, !1, !2, !3, !4}
> !llvm.ident = !{!5}
> 
> !0 = !{i32 1, !"wchar_size", i32 4}
> !1 = !{i32 8, !"PIC Level", i32 2}
> !2 = !{i32 7, !"PIE Level", i32 2}
> !3 = !{i32 7, !"uwtable", i32 2}
> !4 = !{i32 7, !"frame-pointer", i32 2}
> !5 = !{!"clang version 16.0.0"}
> ```
> 
> I'm guessing this comment is specific to error messages.
OK, I see what's going on. The following program fails to build:

```
#include 

union C {
  int a;
  std::string b;
};


C foo() {
  return C("Hello, World!");
}
```



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129531

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


[PATCH] D135142: Use TI.hasBuiltinAtomic() when setting ATOMIC_*_LOCK_FREE values. NFCI

2022-10-04 Thread Ryan Prichard via Phabricator via cfe-commits
rprichard accepted this revision.
rprichard added a comment.
This revision is now accepted and ready to land.

It looks OK to me, but I wonder if you need someone else to accept it also.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135142

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


[PATCH] D135220: [clang] Update ModuleMap::getModuleMapFile* to use FileEntryRef

2022-10-04 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir created this revision.
benlangmuir added reviewers: jansvoboda11, bnbarham.
Herald added a subscriber: arphaman.
Herald added a project: All.
benlangmuir requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Update `SourceManager::ContentCache::OrigEntry` to keep the original 
`FileEntryRef`, and use that to enable `ModuleMap::getModuleMapFile*` to return 
the original `FileEntryRef`. This change should be NFC for most users of 
`SourceManager::ContentCache`, but it could affect behaviour for users of 
`getNameAsRequested` such as in `compileModuleImpl`. I have not found a way to 
detect that difference without additional functional changes, so there is no 
test change here.

Note: this should fix the Windows failure on https://reviews.llvm.org/D134923 
which was caused by an incidental `getFile` call mutating `LastRef` on the 
`FileEntry`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135220

Files:
  clang/include/clang/Basic/FileEntry.h
  clang/include/clang/Basic/SourceManager.h
  clang/include/clang/Lex/ModuleMap.h
  clang/lib/Basic/SourceManager.cpp
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Lex/HeaderSearch.cpp
  clang/lib/Lex/ModuleMap.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/tools/libclang/CIndexInclusionStack.cpp

Index: clang/tools/libclang/CIndexInclusionStack.cpp
===
--- clang/tools/libclang/CIndexInclusionStack.cpp
+++ clang/tools/libclang/CIndexInclusionStack.cpp
@@ -59,8 +59,8 @@
 
 // Callback to the client.
 // FIXME: We should have a function to construct CXFiles.
-CB(static_cast(
-   const_cast(FI.getContentCache().OrigEntry)),
+CB(static_cast(const_cast(
+   static_cast(FI.getContentCache().OrigEntry))),
InclusionStack.data(), InclusionStack.size(), clientData);
   }
 }
Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -227,7 +227,7 @@
   if (llvm::any_of(CI.getFrontendOpts().Inputs, needsModules)) {
 Preprocessor  = ScanInstance.getPreprocessor();
 if (Module *CurrentModule = PP.getCurrentModuleImplementation())
-  if (const FileEntry *CurrentModuleMap =
+  if (Optional CurrentModuleMap =
   PP.getHeaderSearchInfo()
   .getModuleMap()
   .getModuleMapFileForUniquing(CurrentModule))
@@ -406,13 +406,13 @@
   MD.ImplicitModulePCMPath = std::string(M->getASTFile()->getName());
   MD.IsSystem = M->IsSystem;
 
-  const FileEntry *ModuleMap = MDC.ScanInstance.getPreprocessor()
-   .getHeaderSearchInfo()
-   .getModuleMap()
-   .getModuleMapFileForUniquing(M);
+  Optional ModuleMap = MDC.ScanInstance.getPreprocessor()
+ .getHeaderSearchInfo()
+ .getModuleMap()
+ .getModuleMapFileForUniquing(M);
 
   if (ModuleMap) {
-StringRef Path = ModuleMap->tryGetRealPathName();
+StringRef Path = ModuleMap->getFileEntry().tryGetRealPathName();
 if (Path.empty())
   Path = ModuleMap->getName();
 MD.ClangModuleMapFile = std::string(Path);
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -193,13 +193,13 @@
 auto *CurrentModule = ModulesToProcess.pop_back_val();
 ProcessedModules.insert(CurrentModule);
 
-auto *ModuleMapFile =
+Optional ModuleMapFile =
 HS.getModuleMap().getModuleMapFileForUniquing(CurrentModule);
 if (!ModuleMapFile) {
   continue;
 }
 
-ModuleMaps.insert(ModuleMapFile);
+ModuleMaps.insert(*ModuleMapFile);
 
 for (auto *ImportedModule : (CurrentModule)->Imports) {
   if (!ImportedModule ||
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -3919,7 +3919,8 @@
 Module *M =
 PP.getHeaderSearchInfo().lookupModule(F.ModuleName, F.ImportLoc);
 auto  = PP.getHeaderSearchInfo().getModuleMap();
-const FileEntry *ModMap = M ? Map.getModuleMapFileForUniquing(M) : nullptr;
+Optional ModMap =
+M ? Map.getModuleMapFileForUniquing(M) : None;
 // Don't emit module relocation error if we have -fno-validate-pch
 if (!bool(PP.getPreprocessorOpts().DisablePCHOrModuleValidation &
   

[PATCH] D20401: [Lexer] Don't merge macro args from different macro files

2022-10-04 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Started a thread: 
https://discourse.llvm.org/t/macro-performance-lexer-and-sourcemanager/65713


Repository:
  rL LLVM

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

https://reviews.llvm.org/D20401

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


[PATCH] D134859: [clang][Interp] Implement basic support for floating point values

2022-10-04 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added inline comments.



Comment at: clang/lib/AST/Interp/Floating.h:27-29
+  template  struct Repr;
+  template <> struct Repr<32> { using Type = float; };
+  template <> struct Repr<64> { using Type = double; };

jcranmer-intel wrote:
> aaron.ballman wrote:
> > tbaeder wrote:
> > > aaron.ballman wrote:
> > > > tbaeder wrote:
> > > > > jcranmer-intel wrote:
> > > > > > tbaeder wrote:
> > > > > > > jcranmer-intel wrote:
> > > > > > > > aaron.ballman wrote:
> > > > > > > > > Er, how will this extend to `long double` where the number of 
> > > > > > > > > bits is rather more difficult?
> > > > > > > > Or `half` and `bfloat`, which are both 16-bit floating-point 
> > > > > > > > types?
> > > > > > > I have spent some time with this today and tried to simply always 
> > > > > > > use `APFloat` instead of a primitive type. Unfortunately that 
> > > > > > > doesn't work because what we put on the stack is not the 
> > > > > > > `Floating` (or `Integral`), but the underlying primitive type. So 
> > > > > > > even if we do the final math (in `::add`, etc) via `APFloat`, we 
> > > > > > > need something we can serialize to `char[]` so we can put it on 
> > > > > > > the stack. Do you think that would work?
> > > > > > I don't know enough about the structure of the bytecode interpreter 
> > > > > > here to say for sure, but this smells to me like you're baking in 
> > > > > > an assumption that every primitive target type has a corresponding 
> > > > > > primitive type on the host. This assumption just doesn't hold when 
> > > > > > it comes to floating point (only two of the seven types, `float` 
> > > > > > and `double`, are generally portable, and even then, there be 
> > > > > > dragons in some corner cases).
> > > > > > 
> > > > > > If you do need to continue down this route, there are two 
> > > > > > requirements that should be upheld:
> > > > > > * The representation shouldn't assume that the underlying primitive 
> > > > > > type exists on host (bfloat16 and float128 are better test cases 
> > > > > > here).
> > > > > > * Conversion to/from host primitive types shouldn't be easy to 
> > > > > > accidentally do.
> > > > > > 
> > > > > > (Worth repeating again that bit size is insufficient to distinguish 
> > > > > > floating point types: `bfloat` and `half` are both 16-bit, PPC 
> > > > > > `long double` and IEEE 754 quad precision are both 128-bit, and x86 
> > > > > > `long double` is 80 bits stored as 96 bits on 32-bit and 128 bits 
> > > > > > on 64-bit.)
> > > > > Well, is there a way to convert an APFloat to a char[] that would 
> > > > > work instead of going to float/double and storing that? The only 
> > > > > thing I see in the docs is `convertToHexString()` (and the docs don't 
> > > > > mention whether the conversion is lossy). If not, do you think adding 
> > > > > such a conversion to `APFloat` and its various implementations is the 
> > > > > better way forward?
> > > > Let's avoid serializing the floats to strings so that we can parse the 
> > > > string to turn it back into a float later; that's going to have poor 
> > > > performance even if we do get all the corner cases correct regarding 
> > > > things like rounding, etc.
> > > > 
> > > > `APFloat` does not have any sort of serialization functionality beyond 
> > > > through strings representing the value. I think you'd have to invent 
> > > > such an interface.
> > > Do you know who I might talk to regrading such an interface, both the 
> > > implementation as well as general feasibility?
> > I think there may be at least two ways to do this: use an `APFloat` and put 
> > the serialization interfaces there, or use an `APValue` and put the 
> > serialization interfaces there.
> > 
> > Because `APFloat` is an ADT in LLVM, I think it should probably go up on 
> > Discourse for broader discussion. @chandlerc is still listed as the code 
> > owner for ADTs but he's not been active in quite some time. Instead, I 
> > would recommend talking to @dblaikie (he's got a good eye for ADT work in 
> > general) and @foad, @RKSimon, and @sepavloff as folks who have recently 
> > been touching `APFloat`.
> > 
> > `APValue` is a Clang-specific class, and it already has some amount of 
> > serialization support, it seems 
> > (https://github.com/llvm/llvm-project/blob/main/clang/include/clang/AST/APValue.h#L54).
> >  From a quick look, it seems we're already using `APValue` in a reasonable 
> > number of places in the interpreter, so it might make sense to use this 
> > object consistently to represent all values in the new interpreter?
> Going through `APInt` is already possible in `APFloat`, and that might have 
> some methods to go to char arrays.
Yeah - IR gets serialized APFloats somehow (maybe through some layers of 
indirection) so I'd suggest looking at how, say, a global float named constant 
gets lowered to bitcode to see how that APFloat is serialized.

If that's not enough of a pointer for you/others 

[PATCH] D130131: [HLSL] CodeGen hlsl cbuffer/tbuffer.

2022-10-04 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added a reviewer: asl.
beanz added a subscriber: asl.
beanz added a comment.

+@asl for codegen owner perspective.

This LGTM too. The changes here are well isolated to HLSL, so they should have 
no adverse impact on other language support.

@efriedma, @asl & @rjmccall any feedback?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130131

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


[PATCH] D129531: [clang][C++20] P0960R3: Allow initializing aggregates from a parenthesized list of values

2022-10-04 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao added inline comments.



Comment at: clang/lib/Sema/SemaInit.cpp:4151
+  QualType T = Entity.getType();
+  // FIXME: Union is unsupported.
+  int InitKind = T->isArrayType() ? 0 : 4;

Hmm...it seems like as is this patch generates the correct code for 
parentheses-initialized `union`s:

```
% cat ~/src/tests/test-union.cc
union C {
  float a;
  double b;
};


C foo() {
  return C(1);
}

% bin/clang++ -std=c++20 -emit-llvm -S -c -o - ~/src/tests/test-union.cc
; ModuleID = '/usr/local/google/home/ayzhao/src/tests/test-union.cc'
source_filename = "/usr/local/google/home/ayzhao/src/tests/test-union.cc"
target datalayout = 
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%union.C = type { double }

; Function Attrs: mustprogress noinline nounwind optnone uwtable
define dso_local double @_Z3foov() #0 {
entry:
  %retval = alloca %union.C, align 8
  store float 1.00e+00, ptr %retval, align 8
  %coerce.dive = getelementptr inbounds %union.C, ptr %retval, i32 0, i32 0
  %0 = load double, ptr %coerce.dive, align 8
  ret double %0
}

attributes #0 = { mustprogress noinline nounwind optnone uwtable 
"frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "target-cpu"="x86-64" 
"target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.linker.options = !{}
!llvm.module.flags = !{!0, !1, !2, !3, !4}
!llvm.ident = !{!5}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{i32 7, !"frame-pointer", i32 2}
!5 = !{!"clang version 16.0.0"}
```

I'm guessing this comment is specific to error messages.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129531

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


[PATCH] D119051: Extend the C++03 definition of POD to include defaulted functions

2022-10-04 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

Relatedly, if we put this POD behavior query on TargetInfo, I wonder if it 
makes sense to move the tail padding predicate from TargetCXXABI to TargetInfo:
https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/TargetCXXABI.h#L282

The switch there is basically a switch over architectures.




Comment at: clang/lib/AST/DeclCXX.cpp:774-775
+if ((!Constructor->isDeleted() && !Constructor->isDefaulted()) ||
+(getLangOpts().getClangABICompat() <=
+ LangOptions::ClangABI::Ver15 || Target.isPS() || 
Target.isOSDarwin())) {
+  // C++ [class]p4:

I think this ought to be factored into a TargetInfo method, so we can share the 
logic here and below somehow. Compare this for example with 
`TargetInfo::getCallingConvKind`, which has a similar purpose.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119051

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


[PATCH] D134456: [PGO] Consider parent context when weighing branches with likelyhood.

2022-10-04 Thread Anton Bikineev via Phabricator via cfe-commits
AntonBikineev added a comment.

Anyone wants to take a look/stamp? :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134456

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


[clang] eed92a9 - [NFC] Fix warning wiht parens in assert from 1376c7

2022-10-04 Thread Erich Keane via cfe-commits

Author: Erich Keane
Date: 2022-10-04T14:33:36-07:00
New Revision: eed92a99ddfc411b7b78847b8c0ca30f624d8c7d

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

LOG: [NFC] Fix warning wiht parens in assert from 1376c7

Added: 


Modified: 
clang/include/clang/AST/Decl.h

Removed: 




diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 6a6db7a0c34c..d566564ee7d0 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -2257,9 +2257,8 @@ class FunctionDecl : public DeclaratorDecl,
   }
 
   void setDefaultLoc(SourceLocation NewLoc) {
-assert(NewLoc.isInvalid() ||
-   isExplicitlyDefaulted() &&
-   "Can't set default loc is function isn't explicitly defaulted");
+assert((NewLoc.isInvalid() || isExplicitlyDefaulted()) &&
+   "Can't set default loc is function isn't explicitly defaulted");
 DefaultKWLoc = NewLoc;
   }
 



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


[PATCH] D116735: [RISCV] Adjust RISCV data layout by using n32:64 in layout string

2022-10-04 Thread Craig Topper via Phabricator via cfe-commits
craig.topper updated this revision to Diff 465165.
craig.topper added a comment.

Add requested comment to test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116735

Files:
  clang/lib/Basic/Targets/RISCV.h
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
  llvm/test/CodeGen/RISCV/aext-to-sext.ll
  llvm/test/CodeGen/RISCV/loop-strength-reduce-add-cheaper-than-mul.ll
  llvm/test/CodeGen/RISCV/loop-strength-reduce-loop-invar.ll
  llvm/test/CodeGen/RISCV/rvv/fixed-vector-strided-load-store-asm.ll
  llvm/test/CodeGen/RISCV/rvv/fixed-vectors-fp-buildvec.ll
  llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp

Index: llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp
===
--- llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp
+++ llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp
@@ -31,6 +31,11 @@
   // Check that AMDGPU targets add -G1 if it's not present.
   EXPECT_EQ(UpgradeDataLayoutString("e-p:32:32", "r600"), "e-p:32:32-G1");
   EXPECT_EQ(UpgradeDataLayoutString("e-p:64:64", "amdgcn"), "e-p:64:64-G1");
+
+  // Check that RISCV64 upgrades -n64 to -n32:64.
+  EXPECT_EQ(UpgradeDataLayoutString("e-m:e-p:64:64-i64:64-i128:128-n64-S128",
+"riscv64"),
+"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
 }
 
 TEST(DataLayoutUpgradeTest, NoDataLayoutUpgrade) {
Index: llvm/test/CodeGen/RISCV/rvv/fixed-vectors-fp-buildvec.ll
===
--- llvm/test/CodeGen/RISCV/rvv/fixed-vectors-fp-buildvec.ll
+++ llvm/test/CodeGen/RISCV/rvv/fixed-vectors-fp-buildvec.ll
@@ -286,14 +286,12 @@
 ; RV64-NEXT:addi a1, a1, %lo(.LCPI12_0)
 ; RV64-NEXT:vsetivli zero, 4, e32, m1, ta, mu
 ; RV64-NEXT:vlse32.v v8, (a1), zero
-; RV64-NEXT:li a1, 0
-; RV64-NEXT:li a2, 1024
+; RV64-NEXT:li a1, 1024
 ; RV64-NEXT:  .LBB12_1: # =>This Inner Loop Header: Depth=1
-; RV64-NEXT:slli a3, a1, 2
-; RV64-NEXT:add a3, a0, a3
-; RV64-NEXT:addiw a1, a1, 4
-; RV64-NEXT:vse32.v v8, (a3)
-; RV64-NEXT:bne a1, a2, .LBB12_1
+; RV64-NEXT:vse32.v v8, (a0)
+; RV64-NEXT:addiw a1, a1, -4
+; RV64-NEXT:addi a0, a0, 16
+; RV64-NEXT:bnez a1, .LBB12_1
 ; RV64-NEXT:  # %bb.2:
 ; RV64-NEXT:ret
   br label %2
Index: llvm/test/CodeGen/RISCV/rvv/fixed-vector-strided-load-store-asm.ll
===
--- llvm/test/CodeGen/RISCV/rvv/fixed-vector-strided-load-store-asm.ll
+++ llvm/test/CodeGen/RISCV/rvv/fixed-vector-strided-load-store-asm.ll
@@ -794,20 +794,20 @@
 ; CHECK-NEXT:  # %bb.4:
 ; CHECK-NEXT:beq a4, a5, .LBB12_7
 ; CHECK-NEXT:  .LBB12_5:
-; CHECK-NEXT:slli a2, a3, 2
-; CHECK-NEXT:add a2, a2, a3
-; CHECK-NEXT:add a1, a1, a2
-; CHECK-NEXT:li a2, 1024
+; CHECK-NEXT:addiw a2, a3, -1024
+; CHECK-NEXT:add a0, a0, a3
+; CHECK-NEXT:slli a4, a3, 2
+; CHECK-NEXT:add a3, a4, a3
+; CHECK-NEXT:add a1, a1, a3
 ; CHECK-NEXT:  .LBB12_6: # =>This Inner Loop Header: Depth=1
-; CHECK-NEXT:lb a4, 0(a1)
-; CHECK-NEXT:add a5, a0, a3
-; CHECK-NEXT:lb a6, 0(a5)
-; CHECK-NEXT:addw a4, a6, a4
-; CHECK-NEXT:sb a4, 0(a5)
-; CHECK-NEXT:addiw a4, a3, 1
-; CHECK-NEXT:addi a3, a3, 1
+; CHECK-NEXT:lb a3, 0(a1)
+; CHECK-NEXT:lb a4, 0(a0)
+; CHECK-NEXT:addw a3, a4, a3
+; CHECK-NEXT:sb a3, 0(a0)
+; CHECK-NEXT:addiw a2, a2, 1
+; CHECK-NEXT:addi a0, a0, 1
 ; CHECK-NEXT:addi a1, a1, 5
-; CHECK-NEXT:bne a4, a2, .LBB12_6
+; CHECK-NEXT:bnez a2, .LBB12_6
 ; CHECK-NEXT:  .LBB12_7:
 ; CHECK-NEXT:ret
   %4 = icmp eq i32 %2, 1024
Index: llvm/test/CodeGen/RISCV/loop-strength-reduce-loop-invar.ll
===
--- llvm/test/CodeGen/RISCV/loop-strength-reduce-loop-invar.ll
+++ llvm/test/CodeGen/RISCV/loop-strength-reduce-loop-invar.ll
@@ -53,25 +53,24 @@
 ; RV64:   # %bb.0: # %entry
 ; RV64-NEXT:blez a1, .LBB0_3
 ; RV64-NEXT:  # %bb.1: # %cond_true.preheader
-; RV64-NEXT:li a4, 0
+; RV64-NEXT:li a2, 0
 ; RV64-NEXT:slli a0, a0, 6
-; RV64-NEXT:lui a2, %hi(A)
-; RV64-NEXT:addi a2, a2, %lo(A)
-; RV64-NEXT:add a0, a2, a0
-; RV64-NEXT:li a2, 4
-; RV64-NEXT:li a3, 5
+; RV64-NEXT:lui a3, %hi(A)
+; RV64-NEXT:addi a3, a3, %lo(A)
+; RV64-NEXT:add a0, a3, a0
+; RV64-NEXT:addi a3, a0, 4
+; RV64-NEXT:li a4, 4
+; RV64-NEXT:li a5, 5
 ; RV64-NEXT:  .LBB0_2: # %cond_true
 ; RV64-NEXT:# =>This Inner Loop Header: Depth=1
-; RV64-NEXT:addiw a5, a4, 1
-; RV64-NEXT:slli a6, a5, 2
+; RV64-NEXT:sw a4, 0(a3)
+; RV64-NEXT:addiw a6, a2, 2
+; RV64-NEXT:slli a6, a6, 2
 ; RV64-NEXT:add a6, a0, a6
-; RV64-NEXT:sw a2, 0(a6)
-; RV64-NEXT:addiw a4, a4, 2
-; RV64-NEXT:slli a4, a4, 2
-; RV64-NEXT:add a4, a0, a4

[PATCH] D135199: [OpenMP][C++] Allow #pragma omp simd in constexpr functions

2022-10-04 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert created this revision.
jdoerfert added reviewers: aaron.ballman, faisalv.
Herald added subscribers: guansong, bollu, yaxunl.
Herald added a project: All.
jdoerfert requested review of this revision.
Herald added a subscriber: sstefan1.
Herald added a project: clang.

There is no reason (obvious to me) that would prevent us from ignoring
the "simd" part during constexpr eval, assuming there are no clauses.
The potentially controversial part is the change from Equal to Encloses
when we do the context lookup.

Fixes https://github.com/llvm/llvm-project/issues/58092


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135199

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/constexpr-openmp-simd.cpp

Index: clang/test/SemaCXX/constexpr-openmp-simd.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/constexpr-openmp-simd.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only -fopenmp -triple x86_64-apple-macosx10.14.0 %s
+// RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only -fopenmp -triple x86_64-apple-macosx10.14.0 %s -fno-signed-char
+// RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only -fopenmp -triple aarch64_be-linux-gnu %s
+// RUN: %clang_cc1 -emit-llvm -std=c++2a -fopenmp -triple aarch64_be-linux-gnu %s -DEMIT_IR -o - | FileCheck %s
+
+constexpr int good(int r) {
+
+  #pragma omp simd
+  for (int i = 0; i != 10; ++i)
+r += 1;
+
+  return r;
+}
+
+int test1() {
+  if (good(10) == 20)
+return 42;
+  return good(7);
+// Make sure this is folded to 42 and not 17.
+// CHECK: ret i32 42
+}
+
+#ifndef EMIT_IR
+constexpr int bad(int r) {
+  #pragma omp simd private(r) // expected-error {{OpenMP simd statement with clauses not allowed in constexpr function}}
+  for (int i = 0; i != 10; ++i)
+r += 1;
+
+  return r;
+}
+
+int test2() {
+  return bad(10);
+}
+#endif
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -2169,6 +2169,23 @@
   return false;
 return true;
 
+  case Stmt::OMPSimdDirectiveClass: {
+if (!cast(S)->clauses().empty()) {
+  if (Kind == Sema::CheckConstexprKind::Diagnose) {
+SemaRef.Diag(
+S->getBeginLoc(),
+diag::err_constexpr_body_invalid_omp_simd_stmt_with_clauses)
+<< isa(Dcl) << Dcl->isConsteval();
+  }
+  return false;
+}
+Stmt *LoopStmt = cast(S)->getAssociatedStmt();
+if (auto *CS = dyn_cast(LoopStmt))
+  LoopStmt = CS->getCapturedStmt();
+return CheckConstexprFunctionStmt(SemaRef, Dcl, LoopStmt, ReturnStmts,
+  Cxx1yLoc, Cxx2aLoc, Cxx2bLoc, Kind);
+  }
+
   default:
 if (!isa(S))
   break;
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -5489,6 +5489,13 @@
   case Stmt::CXXTryStmtClass:
 // Evaluate try blocks by evaluating all sub statements.
 return EvaluateStmt(Result, Info, cast(S)->getTryBlock(), Case);
+
+  case Stmt::OMPSimdDirectiveClass: {
+const Stmt *LoopStmt = cast(S)->getAssociatedStmt();
+if (auto *CS = dyn_cast(LoopStmt))
+  LoopStmt = CS->getCapturedStmt();
+return EvaluateStmt(Result, Info, LoopStmt, Case);
+  }
   }
 }
 
@@ -8271,7 +8278,8 @@
 // variable) or be ill-formed (and trigger an appropriate evaluation
 // diagnostic)).
 CallStackFrame *CurrFrame = Info.CurrentCall;
-if (CurrFrame->Callee && CurrFrame->Callee->Equals(VD->getDeclContext())) {
+if (CurrFrame->Callee &&
+CurrFrame->Callee->Encloses(VD->getDeclContext())) {
   // Function parameters are stored in some caller's frame. (Usually the
   // immediate caller, but for an inherited constructor they may be more
   // distant.)
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2719,6 +2719,8 @@
   "use of this statement in a constexpr %select{function|constructor}0 "
   "is incompatible with C++ standards before C++2b">,
   InGroup, DefaultIgnore;
+def err_constexpr_body_invalid_omp_simd_stmt_with_clauses : Error<
+  "OpenMP simd statement with clauses not allowed in %select{constexpr|consteval}1 %select{function|constructor}0">;
 def ext_constexpr_type_definition : ExtWarn<
   "type definition in a constexpr %select{function|constructor}0 "
   "is a C++14 extension">, InGroup;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134813: Properly print unnamed TagDecl objects in diagnostics

2022-10-04 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D134813#3834776 , @aaron.ballman 
wrote:

> Thank you for this! I applied D135191  over 
> the top of my changes here and ran the tests to get all the new failures with 
> the changes, then I reverted those tests which failed back to their trunk 
> form. When I re-ran the tests, I get the following failures:
>
>    TEST 'Clang :: Index/usrs.m' FAILED 
> 
>   ...
>   $ "f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe" 
> "-check-prefix=CHECK-source" "F:\source\llvm-project\clang\test\Index\usrs.m"
>   # command stderr:
>   F:\source\llvm-project\clang\test\Index\usrs.m:188:18: error: CHECK-source: 
> expected string not found in input
>   // CHECK-source: usrs.m:5:1: EnumDecl=:5:1 (Definition) Extent=[5:1 - 8:2]
>^
>   :386:63: note: scanning from here
>   // CHECK: usrs.m:3:56: DeclRefExpr=y:3:40 Extent=[3:56 - 3:57]
> ^
>   :387:89: note: possible intended match here
>   // CHECK: usrs.m:5:1: EnumDecl=enum (unnamed at 
> F:\source\llvm-project\clang\test\Index\usrs.m:5:1):5:1 (Definition) 
> Extent=[5:1 - 8:2]

This isn't a change to USRs, it's a change to libclang's 
`clang_getCursorSpelling`. I think it's safe to update (unlike the USRs earlier 
in the file).
Since this is a general-purpose API it makes sense that it would follow the 
change in printName() defaults.

>    TEST 'Clang :: ExtractAPI/enum.c' FAILED 
> 
>   # command output:
>   *** 
> F:\source\llvm-project\llvm\out\build\x64-Debug\tools\clang\test\ExtractAPI\Output\enum.c.tmp/reference.output.json
>   --- 
> F:\source\llvm-project\llvm\out\build\x64-Debug\tools\clang\test\ExtractAPI\Output\enum.c.tmp/output-normalized.json
>   ***
>   *** 655,667 
> "navigator": [
>   {
> "kind": "identifier",
>   ! "spelling": "(anonymous)"
>   !   }
>   ! ],
>   ! "title": "(anonymous)"
>   !   },
>   !   "pathComponents": [
>   ! "(anonymous)"
>   ]
> },
> {
>   --- 655,667 
> "navigator": [
>   {
> "kind": "identifier",
>   ! "spelling": "enum (unnamed at 
> F:\\source\\llvm-project\\llvm\\out\\build\\x64-Debug\\tools\\clang\\test\\ExtractAPI\\Output\\enum.c.tmp/input.h:17:1)"
>   !   }
>   ! ],
>   ! "title": "enum (unnamed at 
> F:\\source\\llvm-project\\llvm\\out\\build\\x64-Debug\\tools\\clang\\test\\ExtractAPI\\Output\\enum.c.tmp/input.h:17:1)"
>   !   },
>   !   "pathComponents": [
>   ! "enum (unnamed at 
> F:\\source\\llvm-project\\llvm\\out\\build\\x64-Debug\\tools\\clang\\test\\ExtractAPI\\Output\\enum.c.tmp/input.h:17:1)"
>   ]
> },
>   ...

ExtractAPI seems to produce a data description of the AST for programmatic 
consumption (apple swift interop?), this looks like a breaking change to me.
It looks like they have at least one explicit check similar to USRs in 
clang/lib/ExtractAPI/ExtractAPIConsumer.cpp:361, but I know very little about 
how this tool is used out-of-tree by Apple: I'm not sure how much the exact 
strings/lack of strings matters, may need owners of that tool involved here.

>    TEST 'Clang :: Index/annotate-comments-typedef.m' 
> FAILED 

I can't see the actual output of the tool in that log, but I guess this is 
related to clang/lib/Index/CommentToXML.cpp:908.
I don't know if reporting exactly `` is important behavior that 
should be preserved, or `(unnamed)` would be fine. I don't even know what 
CommentToXML is: again I guess it's consumed by something related to XCode 
out-of-tree.

> and also the clangd unit tests failed:
>
>   [--] 1 test from FindExplicitReferencesTest
>   [ RUN  ] FindExplicitReferencesTest.All
>   ...
>   With diff:
>   @@ -1,3 +1,3 @@
>   -0: targets = {}
>   +0: targets = {(unnamed)}
>1: targets = {x}, decl
>2: targets = {fptr}, decl
>   
>   
>void foo() {
> $0^class {} $1^x;
> int (*$2^fptr)(int $3^a, int) = nullptr;
>}

  Yes, this is expected: the test identifies which target is referenced by 
name, and we changed the name from "" to "(unnamed)".
  This patch can change the test data on 
clang-tools-extra/clangd/unittests/FindTargetTests.cpp:1619 from `targets = {}` 
to `targets={(unnamed)}`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134813

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


[PATCH] D134330: [Docs] [HLSL] Add note about PCH support

2022-10-04 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added inline comments.



Comment at: clang/docs/HLSL/HLSLSupport.rst:98
+``HLSLExternalSemaSource`` will create new decls and use the old decls as
+argument for setPreviousDecl.
+

We can probably generalize this to something like:
```
When precompiled headers are used compiling HLSL, the ``ExternalSemaSource``
will be a ``MultiplexExternalSemaSource`` which include both the ``ASTReader``
and ``HLSLExternalSemaSource``. For Built-in declarations that are  already
completed in the serialized AST, the ``HLSLExternalSemaSource`` will reuse the
existing declarations and not introduce new declarations. If the built-in types
are not completed in the serialized AST, the ``HLSLExternalSemaSource`` will
create new declarations and connect the de-serialized decls as the previous
declaration.
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134330

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


[PATCH] D118511: Add a warning for not packing non-POD members in packed structs

2022-10-04 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added inline comments.



Comment at: clang/lib/AST/RecordLayoutBuilder.cpp:2029-2036
   // The align if the field is not packed. This is to check if the attribute
   // was unnecessary (-Wpacked).
   CharUnits UnpackedFieldAlign =
   !DefaultsToAIXPowerAlignment ? FieldAlign : PreferredAlign;
   CharUnits UnpackedFieldOffset = FieldOffset;
   CharUnits OriginalFieldAlign = UnpackedFieldAlign;
 

dblaikie wrote:
> rsmith wrote:
> > It seems a little wasteful and error-prone that we're now computing the 
> > actual alignment, the alignment if the field were not packed, and the 
> > alignment if the field were packed. Is there any way we can reduce this 
> > down to computing just the alignment if the field were packed plus the 
> > alignment if the field were not packed, then picking one of those two as 
> > the actual field alignment? Or does that end up being messier?
> I had a go at that refactor - we can't pull the `FieldPacked` computation 
> lower (it'd be great if it could move down to after the packed/unpacked 
> computation, so it was clear that those values were computed independently of 
> the `FieldPacked` value, and that `FieldPacked` just determined which one to 
> pick) because of the `alignedAttrCanDecreaseAIXAlignment`, by the looks of it.
> 
> And also the AIX alignment stuff seems to do some weird things around the 
> preferred alignment that caused the carefully constructed 3 `if`s below 
> (`!FieldPacked`, `DefaultsToAIXPowerAlignment`, and `FieldPacked`) which I 
> spent more time than I'd like to admit figuring out why anything 
> else/less/more streamlined was inadequate.
> 
> But I also don't understand why `DefaultsToAIXAlignment` causes the `AlignTo` 
> value to be the `PreferredAlign`, but the `FieldAlign` stays as it is? (like 
> why doesn't `DefaultsToAIXPowerAlignment` cause `FieldAlign` to /be/ 
> `PreferredAlign` - I think that'd simplify things, but tests (maybe the tests 
> are incorrect/) seemed to break when I tried that) - I would've thought not 
> doing that (as the code currently doesn't) would cause problems for the 
> `UnadjustedAlignment`, `UpdateAlignment`, and `warn_unaligned_access` issues 
> later on that depend on `FieldAlign`, but feel like they should probably 
> depend on the alignment that actually got used (the `PreferredAlign`) 
> instead? It's pretty confusing to me, so... yeah.
Ping on this discussion. @rsmith 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118511

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


[PATCH] D116735: [RISCV] Adjust RISCV data layout by using n32:64 in layout string

2022-10-04 Thread Craig Topper via Phabricator via cfe-commits
craig.topper updated this revision to Diff 465162.
craig.topper added a comment.

Use TT.isRISCV64() in AutoUpgrade.cpp


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116735

Files:
  clang/lib/Basic/Targets/RISCV.h
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
  llvm/test/CodeGen/RISCV/aext-to-sext.ll
  llvm/test/CodeGen/RISCV/loop-strength-reduce-add-cheaper-than-mul.ll
  llvm/test/CodeGen/RISCV/loop-strength-reduce-loop-invar.ll
  llvm/test/CodeGen/RISCV/rvv/fixed-vector-strided-load-store-asm.ll
  llvm/test/CodeGen/RISCV/rvv/fixed-vectors-fp-buildvec.ll
  llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp

Index: llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp
===
--- llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp
+++ llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp
@@ -31,6 +31,10 @@
   // Check that AMDGPU targets add -G1 if it's not present.
   EXPECT_EQ(UpgradeDataLayoutString("e-p:32:32", "r600"), "e-p:32:32-G1");
   EXPECT_EQ(UpgradeDataLayoutString("e-p:64:64", "amdgcn"), "e-p:64:64-G1");
+
+  EXPECT_EQ(UpgradeDataLayoutString("e-m:e-p:64:64-i64:64-i128:128-n64-S128",
+"riscv64"),
+"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
 }
 
 TEST(DataLayoutUpgradeTest, NoDataLayoutUpgrade) {
Index: llvm/test/CodeGen/RISCV/rvv/fixed-vectors-fp-buildvec.ll
===
--- llvm/test/CodeGen/RISCV/rvv/fixed-vectors-fp-buildvec.ll
+++ llvm/test/CodeGen/RISCV/rvv/fixed-vectors-fp-buildvec.ll
@@ -286,14 +286,12 @@
 ; RV64-NEXT:addi a1, a1, %lo(.LCPI12_0)
 ; RV64-NEXT:vsetivli zero, 4, e32, m1, ta, mu
 ; RV64-NEXT:vlse32.v v8, (a1), zero
-; RV64-NEXT:li a1, 0
-; RV64-NEXT:li a2, 1024
+; RV64-NEXT:li a1, 1024
 ; RV64-NEXT:  .LBB12_1: # =>This Inner Loop Header: Depth=1
-; RV64-NEXT:slli a3, a1, 2
-; RV64-NEXT:add a3, a0, a3
-; RV64-NEXT:addiw a1, a1, 4
-; RV64-NEXT:vse32.v v8, (a3)
-; RV64-NEXT:bne a1, a2, .LBB12_1
+; RV64-NEXT:vse32.v v8, (a0)
+; RV64-NEXT:addiw a1, a1, -4
+; RV64-NEXT:addi a0, a0, 16
+; RV64-NEXT:bnez a1, .LBB12_1
 ; RV64-NEXT:  # %bb.2:
 ; RV64-NEXT:ret
   br label %2
Index: llvm/test/CodeGen/RISCV/rvv/fixed-vector-strided-load-store-asm.ll
===
--- llvm/test/CodeGen/RISCV/rvv/fixed-vector-strided-load-store-asm.ll
+++ llvm/test/CodeGen/RISCV/rvv/fixed-vector-strided-load-store-asm.ll
@@ -794,20 +794,20 @@
 ; CHECK-NEXT:  # %bb.4:
 ; CHECK-NEXT:beq a4, a5, .LBB12_7
 ; CHECK-NEXT:  .LBB12_5:
-; CHECK-NEXT:slli a2, a3, 2
-; CHECK-NEXT:add a2, a2, a3
-; CHECK-NEXT:add a1, a1, a2
-; CHECK-NEXT:li a2, 1024
+; CHECK-NEXT:addiw a2, a3, -1024
+; CHECK-NEXT:add a0, a0, a3
+; CHECK-NEXT:slli a4, a3, 2
+; CHECK-NEXT:add a3, a4, a3
+; CHECK-NEXT:add a1, a1, a3
 ; CHECK-NEXT:  .LBB12_6: # =>This Inner Loop Header: Depth=1
-; CHECK-NEXT:lb a4, 0(a1)
-; CHECK-NEXT:add a5, a0, a3
-; CHECK-NEXT:lb a6, 0(a5)
-; CHECK-NEXT:addw a4, a6, a4
-; CHECK-NEXT:sb a4, 0(a5)
-; CHECK-NEXT:addiw a4, a3, 1
-; CHECK-NEXT:addi a3, a3, 1
+; CHECK-NEXT:lb a3, 0(a1)
+; CHECK-NEXT:lb a4, 0(a0)
+; CHECK-NEXT:addw a3, a4, a3
+; CHECK-NEXT:sb a3, 0(a0)
+; CHECK-NEXT:addiw a2, a2, 1
+; CHECK-NEXT:addi a0, a0, 1
 ; CHECK-NEXT:addi a1, a1, 5
-; CHECK-NEXT:bne a4, a2, .LBB12_6
+; CHECK-NEXT:bnez a2, .LBB12_6
 ; CHECK-NEXT:  .LBB12_7:
 ; CHECK-NEXT:ret
   %4 = icmp eq i32 %2, 1024
Index: llvm/test/CodeGen/RISCV/loop-strength-reduce-loop-invar.ll
===
--- llvm/test/CodeGen/RISCV/loop-strength-reduce-loop-invar.ll
+++ llvm/test/CodeGen/RISCV/loop-strength-reduce-loop-invar.ll
@@ -53,25 +53,24 @@
 ; RV64:   # %bb.0: # %entry
 ; RV64-NEXT:blez a1, .LBB0_3
 ; RV64-NEXT:  # %bb.1: # %cond_true.preheader
-; RV64-NEXT:li a4, 0
+; RV64-NEXT:li a2, 0
 ; RV64-NEXT:slli a0, a0, 6
-; RV64-NEXT:lui a2, %hi(A)
-; RV64-NEXT:addi a2, a2, %lo(A)
-; RV64-NEXT:add a0, a2, a0
-; RV64-NEXT:li a2, 4
-; RV64-NEXT:li a3, 5
+; RV64-NEXT:lui a3, %hi(A)
+; RV64-NEXT:addi a3, a3, %lo(A)
+; RV64-NEXT:add a0, a3, a0
+; RV64-NEXT:addi a3, a0, 4
+; RV64-NEXT:li a4, 4
+; RV64-NEXT:li a5, 5
 ; RV64-NEXT:  .LBB0_2: # %cond_true
 ; RV64-NEXT:# =>This Inner Loop Header: Depth=1
-; RV64-NEXT:addiw a5, a4, 1
-; RV64-NEXT:slli a6, a5, 2
+; RV64-NEXT:sw a4, 0(a3)
+; RV64-NEXT:addiw a6, a2, 2
+; RV64-NEXT:slli a6, a6, 2
 ; RV64-NEXT:add a6, a0, a6
-; RV64-NEXT:sw a2, 0(a6)
-; RV64-NEXT:addiw a4, a4, 2
-; RV64-NEXT:slli a4, a4, 2
-; RV64-NEXT:add a4, a0, a4
-; RV64-NEXT:sw a3, 0(a4)
-; RV64-NEXT: 

[PATCH] D118511: Add a warning for not packing non-POD members in packed structs

2022-10-04 Thread David Blaikie via Phabricator via cfe-commits
dblaikie updated this revision to Diff 465161.
dblaikie added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118511

Files:
  clang/include/clang/Basic/DiagnosticASTKinds.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/test/CodeGenCXX/warn-padded-packed.cpp

Index: clang/test/CodeGenCXX/warn-padded-packed.cpp
===
--- clang/test/CodeGenCXX/warn-padded-packed.cpp
+++ clang/test/CodeGenCXX/warn-padded-packed.cpp
@@ -146,8 +146,28 @@
   unsigned char b : 8;
 } __attribute__((packed));
 
+struct S28_non_pod {
+ protected:
+  int i;
+};
+struct S28 {
+  char c1;
+  short s1;
+  char c2;
+  S28_non_pod p1; // expected-warning {{not packing field 'p1' as it is non-POD}}
+} __attribute__((packed));
+
+struct S29_non_pod_align_1 {
+ protected:
+  char c;
+};
+struct S29 {
+  S29_non_pod_align_1 p1;
+  int i;
+} __attribute__((packed)); // no warning
+static_assert(alignof(S29) == 1, "");
 
 // The warnings are emitted when the layout of the structs is computed, so we have to use them.
 void f(S1*, S2*, S3*, S4*, S5*, S6*, S7*, S8*, S9*, S10*, S11*, S12*, S13*,
S14*, S15*, S16*, S17*, S18*, S19*, S20*, S21*, S22*, S23*, S24*, S25*,
-   S26*, S27*){}
+   S26*, S27*, S28*, S29*){}
Index: clang/lib/AST/RecordLayoutBuilder.cpp
===
--- clang/lib/AST/RecordLayoutBuilder.cpp
+++ clang/lib/AST/RecordLayoutBuilder.cpp
@@ -1890,11 +1890,6 @@
   LastBitfieldStorageUnitSize = 0;
 
   llvm::Triple Target = Context.getTargetInfo().getTriple();
-  bool FieldPacked = (Packed && (!FieldClass || FieldClass->isPOD() ||
- Context.getLangOpts().getClangABICompat() <=
- LangOptions::ClangABI::Ver14 ||
- Target.isPS() || Target.isOSDarwin())) ||
- D->hasAttr();
 
   AlignRequirementKind AlignRequirement = AlignRequirementKind::None;
   CharUnits FieldSize;
@@ -1975,6 +1970,12 @@
 }
   }
 
+  bool FieldPacked = (Packed && (!FieldClass || FieldClass->isPOD() ||
+ Context.getLangOpts().getClangABICompat() <=
+ LangOptions::ClangABI::Ver14 ||
+ Target.isPS() || Target.isOSDarwin())) ||
+ D->hasAttr();
+
   // When used as part of a typedef, or together with a 'packed' attribute, the
   // 'aligned' attribute can be used to decrease alignment. In that case, it
   // overrides any computed alignment we have, and there is no need to upgrade
@@ -2025,28 +2026,34 @@
 
   // The align if the field is not packed. This is to check if the attribute
   // was unnecessary (-Wpacked).
-  CharUnits UnpackedFieldAlign =
-  !DefaultsToAIXPowerAlignment ? FieldAlign : PreferredAlign;
+  CharUnits UnpackedFieldAlign = FieldAlign; 
+  CharUnits PackedFieldAlign = CharUnits::One();
   CharUnits UnpackedFieldOffset = FieldOffset;
   CharUnits OriginalFieldAlign = UnpackedFieldAlign;
 
-  if (FieldPacked) {
-FieldAlign = CharUnits::One();
-PreferredAlign = CharUnits::One();
-  }
   CharUnits MaxAlignmentInChars =
   Context.toCharUnitsFromBits(D->getMaxAlignment());
-  FieldAlign = std::max(FieldAlign, MaxAlignmentInChars);
+  PackedFieldAlign = std::max(PackedFieldAlign, MaxAlignmentInChars);
   PreferredAlign = std::max(PreferredAlign, MaxAlignmentInChars);
   UnpackedFieldAlign = std::max(UnpackedFieldAlign, MaxAlignmentInChars);
 
   // The maximum field alignment overrides the aligned attribute.
   if (!MaxFieldAlignment.isZero()) {
-FieldAlign = std::min(FieldAlign, MaxFieldAlignment);
+PackedFieldAlign = std::min(PackedFieldAlign, MaxFieldAlignment);
 PreferredAlign = std::min(PreferredAlign, MaxFieldAlignment);
 UnpackedFieldAlign = std::min(UnpackedFieldAlign, MaxFieldAlignment);
   }
 
+
+  if (!FieldPacked)
+FieldAlign = UnpackedFieldAlign;
+  if (DefaultsToAIXPowerAlignment)
+UnpackedFieldAlign = PreferredAlign;
+  if (FieldPacked) {
+PreferredAlign = PackedFieldAlign;
+FieldAlign = PackedFieldAlign;
+  }
+
   CharUnits AlignTo =
   !DefaultsToAIXPowerAlignment ? FieldAlign : PreferredAlign;
   // Round up the current record size to the field's alignment boundary.
@@ -2129,6 +2136,9 @@
 << Context.getTypeDeclType(RD) << D->getName() << D->getType();
 }
   }
+
+  if (Packed && !FieldPacked && PackedFieldAlign < FieldAlign)
+Diag(D->getLocation(), diag::warn_unpacked_field) << D;
 }
 
 void ItaniumRecordLayoutBuilder::FinishLayout(const NamedDecl *D) {
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ 

[PATCH] D119051: Extend the C++03 definition of POD to include defaulted functions

2022-10-04 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D119051#3747673 , @rnk wrote:

> In D119051#3747201 , @dblaikie 
> wrote:
>
>> So... my conclusion is that Clang's AArch64 appears to be correct for x86  
>> as well, and we should just rename the function and use it unconditionally, 
>> removing any use of Clang's AST POD property in the MSVC ABI handling?
>
> Sounds good to me, I think you did the hard work of verifying, thanks for 
> that. :)
>
> Anyway, removing this isPOD usage should be it's own patch, with tests. We 
> should already have test coverage for aarch64 that can be reused. @ayzhao, 
> can you help David with this? This is not C++20-related, but it is clang 
> frontend related.

Popping the stack, the use of AST's isPOD in Microsoft's ABI has been removed 
in favor of more nuanced custom implementation in the Microsoft ABI handling 
that fixed a few bugs along the way (D133817 
, D134688 ).

I've rebased this patch and addressed a test failure I hadn't spotted before, 
in `clang/test/AST/conditionally-trivial-smfs.cpp` - added some details to the 
patch description.
And now that the Microsoft ABI doesn't depend on the AST isPOD property at all, 
I've removed the previously proposed new test 
`clang/test/CodeGenCXX/return-abi.cpp` that was testing the Microsoft return 
ABI.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119051

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


[PATCH] D119051: Extend the C++03 definition of POD to include defaulted functions

2022-10-04 Thread David Blaikie via Phabricator via cfe-commits
dblaikie updated this revision to Diff 465159.
dblaikie added a comment.

Remove Microsoft return ABI test, now that the Microsoft ABI implementation no 
longer depends on the AST isPOD property


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119051

Files:
  clang/include/clang/Basic/LangOptions.h
  clang/lib/AST/DeclCXX.cpp
  clang/test/AST/conditionally-trivial-smfs.cpp
  clang/test/SemaCXX/class-layout.cpp

Index: clang/test/SemaCXX/class-layout.cpp
===
--- clang/test/SemaCXX/class-layout.cpp
+++ clang/test/SemaCXX/class-layout.cpp
@@ -1,10 +1,12 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++98 -Wno-inaccessible-base
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++98 -Wno-inaccessible-base -Wno-c++11-extensions
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base
 // RUN: %clang_cc1 -triple x86_64-apple-darwin%s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=14
 // RUN: %clang_cc1 -triple x86_64-scei-ps4%s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
 // RUN: %clang_cc1 -triple x86_64-sie-ps5 %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=6 -DCLANG_ABI_COMPAT=6
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=14 -DCLANG_ABI_COMPAT=14
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=16 -DCLANG_ABI_COMPAT=16
 // expected-no-diagnostics
 
 #define SA(n, p) int a##n[(p) ? 1 : -1]
@@ -642,3 +644,33 @@
 _Static_assert(_Alignof(t1) == 1, "");
 _Static_assert(_Alignof(t2) == 1, "");
 } // namespace non_pod_packed
+
+namespace cxx11_pod {
+struct t1 {
+  t1() = default;
+  t1(const t1&) = delete;
+  ~t1() = delete;
+  t1(t1&&) = default;
+  int a;
+  char c;
+};
+struct t2 {
+  t1 v1;
+} __attribute__((packed));
+// 14 and below consider t1 non-pod, but pack it anyway
+// 15 considers it non-pod and doesn't pack it
+// 16 and up considers it pod and packs it again...
+#if defined(CLANG_ABI_COMPAT) && CLANG_ABI_COMPAT == 15
+_Static_assert(_Alignof(t2) == 4, "");
+#else
+_Static_assert(_Alignof(t2) == 1, "");
+#endif
+struct t3 : t1 {
+  char c;
+};
+#if defined(CLANG_ABI_COMPAT) && CLANG_ABI_COMPAT <= 15
+_Static_assert(sizeof(t3) == 8, "");
+#else
+_Static_assert(sizeof(t3) == 12, "");
+#endif
+}
Index: clang/test/AST/conditionally-trivial-smfs.cpp
===
--- clang/test/AST/conditionally-trivial-smfs.cpp
+++ clang/test/AST/conditionally-trivial-smfs.cpp
@@ -297,6 +297,7 @@
 // CHECK-NEXT:  "isAggregate": true,
 // CHECK-NEXT:  "isEmpty": true,
 // CHECK-NEXT:  "isLiteral": true,
+// CHECK-NEXT:  "isPOD": true,
 // CHECK-NEXT:  "isStandardLayout": true,
 // CHECK-NEXT:  "isTrivial": true,
 // CHECK-NEXT:  "isTriviallyCopyable": true,
@@ -316,6 +317,7 @@
 // CHECK-NEXT:  "isAggregate": true,
 // CHECK-NEXT:  "isEmpty": true,
 // CHECK-NEXT:  "isLiteral": true,
+// CHECK-NEXT:  "isPOD": true,
 // CHECK-NEXT:  "isStandardLayout": true,
 // CHECK-NEXT:  "isTrivial": true,
 // CHECK-NEXT:  "isTriviallyCopyable": true,
@@ -335,6 +337,7 @@
 // CHECK-NEXT:  "isAggregate": true,
 // CHECK-NEXT:  "isEmpty": true,
 // CHECK-NEXT:  "isLiteral": true,
+// CHECK-NEXT:  "isPOD": true,
 // CHECK-NEXT:  "isStandardLayout": true,
 // CHECK-NEXT:  "moveAssign": {
 // CHECK-NEXT:"exists": true,
Index: clang/lib/AST/DeclCXX.cpp
===
--- clang/lib/AST/DeclCXX.cpp
+++ clang/lib/AST/DeclCXX.cpp
@@ -36,6 +36,7 @@
 #include "clang/Basic/PartialDiagnostic.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/Specifiers.h"
+#include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallVector.h"
@@ -768,12 +769,17 @@
 // Note that we have a user-declared constructor.
 data().UserDeclaredConstructor = true;
 
-// C++ [class]p4:
-//   A POD-struct is an aggregate class [...]
-// Since the POD bit is meant to be C++03 POD-ness, clear it even if
-// the type is technically an aggregate in C++0x since it 

[PATCH] D119051: Extend the C++03 definition of POD to include defaulted functions

2022-10-04 Thread David Blaikie via Phabricator via cfe-commits
dblaikie updated this revision to Diff 465158.
dblaikie added a comment.

rebase and fix an AST test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119051

Files:
  clang/include/clang/Basic/LangOptions.h
  clang/lib/AST/DeclCXX.cpp
  clang/test/AST/conditionally-trivial-smfs.cpp
  clang/test/CodeGenCXX/return-abi.cpp
  clang/test/SemaCXX/class-layout.cpp

Index: clang/test/SemaCXX/class-layout.cpp
===
--- clang/test/SemaCXX/class-layout.cpp
+++ clang/test/SemaCXX/class-layout.cpp
@@ -1,10 +1,12 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++98 -Wno-inaccessible-base
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++98 -Wno-inaccessible-base -Wno-c++11-extensions
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base
 // RUN: %clang_cc1 -triple x86_64-apple-darwin%s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=14
 // RUN: %clang_cc1 -triple x86_64-scei-ps4%s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
 // RUN: %clang_cc1 -triple x86_64-sie-ps5 %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=6 -DCLANG_ABI_COMPAT=6
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=14 -DCLANG_ABI_COMPAT=14
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=16 -DCLANG_ABI_COMPAT=16
 // expected-no-diagnostics
 
 #define SA(n, p) int a##n[(p) ? 1 : -1]
@@ -642,3 +644,33 @@
 _Static_assert(_Alignof(t1) == 1, "");
 _Static_assert(_Alignof(t2) == 1, "");
 } // namespace non_pod_packed
+
+namespace cxx11_pod {
+struct t1 {
+  t1() = default;
+  t1(const t1&) = delete;
+  ~t1() = delete;
+  t1(t1&&) = default;
+  int a;
+  char c;
+};
+struct t2 {
+  t1 v1;
+} __attribute__((packed));
+// 14 and below consider t1 non-pod, but pack it anyway
+// 15 considers it non-pod and doesn't pack it
+// 16 and up considers it pod and packs it again...
+#if defined(CLANG_ABI_COMPAT) && CLANG_ABI_COMPAT == 15
+_Static_assert(_Alignof(t2) == 4, "");
+#else
+_Static_assert(_Alignof(t2) == 1, "");
+#endif
+struct t3 : t1 {
+  char c;
+};
+#if defined(CLANG_ABI_COMPAT) && CLANG_ABI_COMPAT <= 15
+_Static_assert(sizeof(t3) == 8, "");
+#else
+_Static_assert(sizeof(t3) == 12, "");
+#endif
+}
Index: clang/test/CodeGenCXX/return-abi.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/return-abi.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -emit-llvm -o - -triple i686-pc-windows-msvc -Wno-return-type %s | FileCheck %s
+namespace nonpod {
+struct base {};
+struct t1 : base {
+int a;
+};
+t1 f1() {}
+// CHECK: define {{.*}}void {{.*}}nonpod{{.*}}(ptr
+}  // namespace nonpod
+namespace smf_defaulted_pod {
+struct t1 {
+t1() = default;
+int a;
+};
+t1 f1() {}
+// CHECK: define {{.*}}i32 {{.*}}smf_defaulted_pod{{.*}}()
+}  // namespace smf_defaulted_pod
+namespace pod {
+struct t1 {
+int a;
+};
+t1 f1() {}
+// CHECK: define {{.*}}i32 {{.*}}pod{{.*}}()
+}  // namespace pod
Index: clang/test/AST/conditionally-trivial-smfs.cpp
===
--- clang/test/AST/conditionally-trivial-smfs.cpp
+++ clang/test/AST/conditionally-trivial-smfs.cpp
@@ -297,6 +297,7 @@
 // CHECK-NEXT:  "isAggregate": true,
 // CHECK-NEXT:  "isEmpty": true,
 // CHECK-NEXT:  "isLiteral": true,
+// CHECK-NEXT:  "isPOD": true,
 // CHECK-NEXT:  "isStandardLayout": true,
 // CHECK-NEXT:  "isTrivial": true,
 // CHECK-NEXT:  "isTriviallyCopyable": true,
@@ -316,6 +317,7 @@
 // CHECK-NEXT:  "isAggregate": true,
 // CHECK-NEXT:  "isEmpty": true,
 // CHECK-NEXT:  "isLiteral": true,
+// CHECK-NEXT:  "isPOD": true,
 // CHECK-NEXT:  "isStandardLayout": true,
 // CHECK-NEXT:  "isTrivial": true,
 // CHECK-NEXT:  "isTriviallyCopyable": true,
@@ -335,6 +337,7 @@
 // CHECK-NEXT:  "isAggregate": true,
 // CHECK-NEXT:  "isEmpty": true,
 // CHECK-NEXT:  "isLiteral": true,
+// CHECK-NEXT:  "isPOD": true,
 // CHECK-NEXT:  "isStandardLayout": true,
 // CHECK-NEXT:  "moveAssign": {
 // CHECK-NEXT:"exists": true,
Index: clang/lib/AST/DeclCXX.cpp

[PATCH] D135192: Fix incorrect check for running out of source locations.

2022-10-04 Thread Paul Pluzhnikov via Phabricator via cfe-commits
ppluzhnikov created this revision.
Herald added a project: All.
ppluzhnikov published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When CurrentLoadedOffset is less than TotalSize, current code will
trigger unsigned overflow and will not return an "allocation failed"
indicator.

Google ref: b/248613299


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135192

Files:
  clang/lib/Basic/SourceManager.cpp


Index: clang/lib/Basic/SourceManager.cpp
===
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -455,8 +455,10 @@
  SourceLocation::UIntTy TotalSize) {
   assert(ExternalSLocEntries && "Don't have an external sloc source");
   // Make sure we're not about to run out of source locations.
-  if (CurrentLoadedOffset - TotalSize < NextLocalOffset)
+  if (CurrentLoadedOffset < TotalSize ||
+  CurrentLoadedOffset - TotalSize < NextLocalOffset) {
 return std::make_pair(0, 0);
+  }
   LoadedSLocEntryTable.resize(LoadedSLocEntryTable.size() + NumSLocEntries);
   SLocEntryLoaded.resize(LoadedSLocEntryTable.size());
   CurrentLoadedOffset -= TotalSize;


Index: clang/lib/Basic/SourceManager.cpp
===
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -455,8 +455,10 @@
  SourceLocation::UIntTy TotalSize) {
   assert(ExternalSLocEntries && "Don't have an external sloc source");
   // Make sure we're not about to run out of source locations.
-  if (CurrentLoadedOffset - TotalSize < NextLocalOffset)
+  if (CurrentLoadedOffset < TotalSize ||
+  CurrentLoadedOffset - TotalSize < NextLocalOffset) {
 return std::make_pair(0, 0);
+  }
   LoadedSLocEntryTable.resize(LoadedSLocEntryTable.size() + NumSLocEntries);
   SLocEntryLoaded.resize(LoadedSLocEntryTable.size());
   CurrentLoadedOffset -= TotalSize;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116735: [RISCV] Adjust RISCV data layout by using n32:64 in layout string

2022-10-04 Thread Craig Topper via Phabricator via cfe-commits
craig.topper updated this revision to Diff 465152.
craig.topper marked 2 inline comments as done.
craig.topper added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116735

Files:
  clang/lib/Basic/Targets/RISCV.h
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
  llvm/test/CodeGen/RISCV/aext-to-sext.ll
  llvm/test/CodeGen/RISCV/loop-strength-reduce-add-cheaper-than-mul.ll
  llvm/test/CodeGen/RISCV/loop-strength-reduce-loop-invar.ll
  llvm/test/CodeGen/RISCV/rvv/fixed-vector-strided-load-store-asm.ll
  llvm/test/CodeGen/RISCV/rvv/fixed-vectors-fp-buildvec.ll
  llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp

Index: llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp
===
--- llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp
+++ llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp
@@ -31,6 +31,10 @@
   // Check that AMDGPU targets add -G1 if it's not present.
   EXPECT_EQ(UpgradeDataLayoutString("e-p:32:32", "r600"), "e-p:32:32-G1");
   EXPECT_EQ(UpgradeDataLayoutString("e-p:64:64", "amdgcn"), "e-p:64:64-G1");
+
+  EXPECT_EQ(UpgradeDataLayoutString("e-m:e-p:64:64-i64:64-i128:128-n64-S128",
+"riscv64"),
+"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
 }
 
 TEST(DataLayoutUpgradeTest, NoDataLayoutUpgrade) {
Index: llvm/test/CodeGen/RISCV/rvv/fixed-vectors-fp-buildvec.ll
===
--- llvm/test/CodeGen/RISCV/rvv/fixed-vectors-fp-buildvec.ll
+++ llvm/test/CodeGen/RISCV/rvv/fixed-vectors-fp-buildvec.ll
@@ -286,14 +286,12 @@
 ; RV64-NEXT:addi a1, a1, %lo(.LCPI12_0)
 ; RV64-NEXT:vsetivli zero, 4, e32, m1, ta, mu
 ; RV64-NEXT:vlse32.v v8, (a1), zero
-; RV64-NEXT:li a1, 0
-; RV64-NEXT:li a2, 1024
+; RV64-NEXT:li a1, 1024
 ; RV64-NEXT:  .LBB12_1: # =>This Inner Loop Header: Depth=1
-; RV64-NEXT:slli a3, a1, 2
-; RV64-NEXT:add a3, a0, a3
-; RV64-NEXT:addiw a1, a1, 4
-; RV64-NEXT:vse32.v v8, (a3)
-; RV64-NEXT:bne a1, a2, .LBB12_1
+; RV64-NEXT:vse32.v v8, (a0)
+; RV64-NEXT:addiw a1, a1, -4
+; RV64-NEXT:addi a0, a0, 16
+; RV64-NEXT:bnez a1, .LBB12_1
 ; RV64-NEXT:  # %bb.2:
 ; RV64-NEXT:ret
   br label %2
Index: llvm/test/CodeGen/RISCV/rvv/fixed-vector-strided-load-store-asm.ll
===
--- llvm/test/CodeGen/RISCV/rvv/fixed-vector-strided-load-store-asm.ll
+++ llvm/test/CodeGen/RISCV/rvv/fixed-vector-strided-load-store-asm.ll
@@ -794,20 +794,20 @@
 ; CHECK-NEXT:  # %bb.4:
 ; CHECK-NEXT:beq a4, a5, .LBB12_7
 ; CHECK-NEXT:  .LBB12_5:
-; CHECK-NEXT:slli a2, a3, 2
-; CHECK-NEXT:add a2, a2, a3
-; CHECK-NEXT:add a1, a1, a2
-; CHECK-NEXT:li a2, 1024
+; CHECK-NEXT:addiw a2, a3, -1024
+; CHECK-NEXT:add a0, a0, a3
+; CHECK-NEXT:slli a4, a3, 2
+; CHECK-NEXT:add a3, a4, a3
+; CHECK-NEXT:add a1, a1, a3
 ; CHECK-NEXT:  .LBB12_6: # =>This Inner Loop Header: Depth=1
-; CHECK-NEXT:lb a4, 0(a1)
-; CHECK-NEXT:add a5, a0, a3
-; CHECK-NEXT:lb a6, 0(a5)
-; CHECK-NEXT:addw a4, a6, a4
-; CHECK-NEXT:sb a4, 0(a5)
-; CHECK-NEXT:addiw a4, a3, 1
-; CHECK-NEXT:addi a3, a3, 1
+; CHECK-NEXT:lb a3, 0(a1)
+; CHECK-NEXT:lb a4, 0(a0)
+; CHECK-NEXT:addw a3, a4, a3
+; CHECK-NEXT:sb a3, 0(a0)
+; CHECK-NEXT:addiw a2, a2, 1
+; CHECK-NEXT:addi a0, a0, 1
 ; CHECK-NEXT:addi a1, a1, 5
-; CHECK-NEXT:bne a4, a2, .LBB12_6
+; CHECK-NEXT:bnez a2, .LBB12_6
 ; CHECK-NEXT:  .LBB12_7:
 ; CHECK-NEXT:ret
   %4 = icmp eq i32 %2, 1024
Index: llvm/test/CodeGen/RISCV/loop-strength-reduce-loop-invar.ll
===
--- llvm/test/CodeGen/RISCV/loop-strength-reduce-loop-invar.ll
+++ llvm/test/CodeGen/RISCV/loop-strength-reduce-loop-invar.ll
@@ -53,25 +53,24 @@
 ; RV64:   # %bb.0: # %entry
 ; RV64-NEXT:blez a1, .LBB0_3
 ; RV64-NEXT:  # %bb.1: # %cond_true.preheader
-; RV64-NEXT:li a4, 0
+; RV64-NEXT:li a2, 0
 ; RV64-NEXT:slli a0, a0, 6
-; RV64-NEXT:lui a2, %hi(A)
-; RV64-NEXT:addi a2, a2, %lo(A)
-; RV64-NEXT:add a0, a2, a0
-; RV64-NEXT:li a2, 4
-; RV64-NEXT:li a3, 5
+; RV64-NEXT:lui a3, %hi(A)
+; RV64-NEXT:addi a3, a3, %lo(A)
+; RV64-NEXT:add a0, a3, a0
+; RV64-NEXT:addi a3, a0, 4
+; RV64-NEXT:li a4, 4
+; RV64-NEXT:li a5, 5
 ; RV64-NEXT:  .LBB0_2: # %cond_true
 ; RV64-NEXT:# =>This Inner Loop Header: Depth=1
-; RV64-NEXT:addiw a5, a4, 1
-; RV64-NEXT:slli a6, a5, 2
+; RV64-NEXT:sw a4, 0(a3)
+; RV64-NEXT:addiw a6, a2, 2
+; RV64-NEXT:slli a6, a6, 2
 ; RV64-NEXT:add a6, a0, a6
-; RV64-NEXT:sw a2, 0(a6)
-; RV64-NEXT:addiw a4, a4, 2
-; RV64-NEXT:

[PATCH] D135115: [clang-format] update --files help description

2022-10-04 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen updated this revision to Diff 465151.
ychen added a comment.

- make corresponding change in the commandline


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135115

Files:
  clang/docs/ClangFormat.rst
  clang/tools/clang-format/ClangFormat.cpp


Index: clang/tools/clang-format/ClangFormat.cpp
===
--- clang/tools/clang-format/ClangFormat.cpp
+++ clang/tools/clang-format/ClangFormat.cpp
@@ -125,9 +125,11 @@
  "determined by the QualifierAlignment style flag"),
 cl::init(""), cl::cat(ClangFormatCategory));
 
-static cl::opt
-Files("files", cl::desc("Provide a list of files to run clang-format"),
-  cl::init(""), cl::cat(ClangFormatCategory));
+static cl::opt Files(
+"files",
+cl::desc("A file containing a list of files to process, one per line."),
+cl::value_desc("filename"),
+cl::init(""), cl::cat(ClangFormatCategory));
 
 static cl::opt
 Verbose("verbose", cl::desc("If set, shows the list of processed files"),
Index: clang/docs/ClangFormat.rst
===
--- clang/docs/ClangFormat.rst
+++ clang/docs/ClangFormat.rst
@@ -26,7 +26,7 @@
   together with s, the files are edited in-place. Otherwise, the
   result is written to the standard output.
 
-  USAGE: clang-format [options] [ ...]
+  USAGE: clang-format [options] [@] [ ...]
 
   OPTIONS:
 
@@ -69,7 +69,8 @@
 --ferror-limit=  - Set the maximum number of clang-format 
errors to emit
  before stopping (0 = no limit).
  Used only with --dry-run or -n
---files=   - Provide a list of files to run 
clang-format
+--files= - A file containing a list of files to 
process, one
+ per line.
 -i - Inplace edit s, if specified.
 --length=- Format a range of this length (in bytes).
  Multiple ranges can be formatted by 
specifying


Index: clang/tools/clang-format/ClangFormat.cpp
===
--- clang/tools/clang-format/ClangFormat.cpp
+++ clang/tools/clang-format/ClangFormat.cpp
@@ -125,9 +125,11 @@
  "determined by the QualifierAlignment style flag"),
 cl::init(""), cl::cat(ClangFormatCategory));
 
-static cl::opt
-Files("files", cl::desc("Provide a list of files to run clang-format"),
-  cl::init(""), cl::cat(ClangFormatCategory));
+static cl::opt Files(
+"files",
+cl::desc("A file containing a list of files to process, one per line."),
+cl::value_desc("filename"),
+cl::init(""), cl::cat(ClangFormatCategory));
 
 static cl::opt
 Verbose("verbose", cl::desc("If set, shows the list of processed files"),
Index: clang/docs/ClangFormat.rst
===
--- clang/docs/ClangFormat.rst
+++ clang/docs/ClangFormat.rst
@@ -26,7 +26,7 @@
   together with s, the files are edited in-place. Otherwise, the
   result is written to the standard output.
 
-  USAGE: clang-format [options] [ ...]
+  USAGE: clang-format [options] [@] [ ...]
 
   OPTIONS:
 
@@ -69,7 +69,8 @@
 --ferror-limit=  - Set the maximum number of clang-format errors to emit
  before stopping (0 = no limit).
  Used only with --dry-run or -n
---files=   - Provide a list of files to run clang-format
+--files= - A file containing a list of files to process, one
+ per line.
 -i - Inplace edit s, if specified.
 --length=- Format a range of this length (in bytes).
  Multiple ranges can be formatted by specifying
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134453: Introduce the `AlwaysIncludeTypeForNonTypeTemplateArgument` into printing policy

2022-10-04 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D134453#3834659 , @dblaikie wrote:

>>> OK, so it sounds like the printing behavior change (not necessarily with a 
>>> policy flag) necessary for diagnostics (make it non-ambiguous/not invalid 
>>> code which is what is currently emitted) would be a good bug fix both for 
>>> diagnostics and for ast-print? I'm not sure we need anything other than 
>>> that.
>>
>> Agreed, fixing up diagnostics and ast print to not print invalid types would 
>> be a good fix to have. It doesn't necessitate a new printing policy.
>>
>>> So that what is currently printing as `t1<{}>` (ambiguous if the NTTP is of 
>>> type `auto`, non-ambiguous, but invalid C++ if the NTTP has the specific 
>>> type already) prints out as `t1` (correct C++ and disambiguates in 
>>> the case of `auto` ambiguity).
>>>
>>> Or would you want the non-auto case to print in diagnostics as `t1<{}>` 
>>> since there's no ambiguity, despite that not being valid C++? And then have 
>>> a separate policy for ast-print that still prints it as `t1` so it's 
>>> valid code?
>>
>> Personally (and others are welcome to disagree with me here!), I think we 
>> would want to print `t1` even in the `auto` case for diagnostics and 
>> ast print.
>
> (sorry to nitpick, but this conversation's been a bit confusing so trying to 
> be extra clear) - I guess you meant "even in the *non*-`auto`" case? (the 
> auto case I think is clearer that it should always have the type - otherwise 
> it's ambiguous) - but yeah, I'm with you - I think the language requires the 
> type even in the non-auto case and it seems reasonable to side with that for 
> explicitness/clarity even if it could arguably be omitted without loss of 
> information, technically.

No apologies necessary, sorry for the confusion! Yes, I meant the non-auto case 
(practically, I mean both cases).

>> For diagnostics, we sometimes print type information reasonably far away 
>> from where the declaration of a type is (and use a note to shift the user's 
>> gaze to the related type), and so I think having the extra type information 
>> is useful for that situation. But even when we print the type information 
>> reasonably close to the declaration of the type, it can be helpful because 
>> the code context might be easy to lose -- consider using Clang from an IDE 
>> where diagnostics are added to a listbox; if you copy the diagnostic from 
>> the listbox to paste into an email to a coworker to ask about it, the 
>> related code isn't going to come along without extra intervention.
>
> Ok, so sounds like we're on the same page that `t1<{}>` is a diagnostic 
> quality bug and we'd love to see a fix for it to include the top level type 
> of the NTTP, as in `t1`, and that shouldn't need a new printing policy 
> - because we never want to print `t1<{}>` and anywhere we do is a bug to be 
> fixed.

I think we're on the same page, yes, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134453

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


[PATCH] D130096: [Clang][AMDGPU] Emit AMDGPU library control constants in clang

2022-10-04 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/test/CodeGen/amdgcn-control-constants.c:8
+
+// GFX90A: @__oclc_daz_opt = linkonce_odr hidden local_unnamed_addr 
addrspace(4) constant i8 0, align 1
+// GFX90A: @__oclc_wavefrontsize64 = linkonce_odr hidden local_unnamed_addr 
addrspace(4) constant i8 1, align 1

jhuber6 wrote:
> yaxunl wrote:
> > yaxunl wrote:
> > > need an OpenCL test for -cl-denorms-are-zero
> > still missing this test, and some other tests for -cl-* options as 
> > commented below.
> > 
> > Also, missing a HIP test for -ffast-math
> The cc1 math options tested individually should be enabled by `-ffast-math`.
Since we cannot test -ffast-math directly, can we add a driver test to ensure 
we are not missing any -cc1 options needed by the control variables when 
-ffast-math is specified for the driver? Thanks.

Also, the -cl-* options are -cc1 options. We need to test them.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130096

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


[PATCH] D135115: [clang-format] update --files help description

2022-10-04 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

The help text in ClangFormat.cpp for the `--files` option needs to be updated 
the same way.
Note using `cl::value_desc("filename")` is what you need to change the 
meta-variable in the help output.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135115

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


[PATCH] D134813: Properly print unnamed TagDecl objects in diagnostics

2022-10-04 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D134813#3834710 , @sammccall wrote:

> In D134813#3834613 , @sammccall 
> wrote:
>
>> Changing USR generation to not rely on this detail seems easier, I can take 
>> a stab at this.
>
> Seems trivial: https://reviews.llvm.org/D135191
> If there are still diffs in USR tests after rebasing on that, I'm happy to 
> take a look at them.

Thank you for this! I applied D135191  over 
the top of my changes here and ran the tests to get all the new failures with 
the changes, then I reverted those tests which failed back to their trunk form. 
When I re-ran the tests, I get the following failures:

  F:\source\llvm-project>python llvm\out\build\x64-Debug\bin\llvm-lit.py -sv 
-j61 clang\test\
  llvm-lit.py: F:\source\llvm-project\llvm\utils\lit\lit\llvm\config.py:46: 
note: using lit tools: C:\GnuWin32\bin
  llvm-lit.py: F:\source\llvm-project\llvm\utils\lit\lit\llvm\config.py:456: 
note: using clang: f:\source\llvm-project\llvm\out\build\x64-debug\bin\clang.exe
  llvm-lit.py: F:\source\llvm-project\llvm\utils\lit\lit\discovery.py:247: 
warning: test suite 'Clang-Unit' contained no tests
  -- Testing: 15539 tests, 61 workers --
  Testing:
  FAIL: Clang :: Index/usrs.m (1 of 15539)
   TEST 'Clang :: Index/usrs.m' FAILED 
  Script:
  --
  : 'RUN: at line 103';   
f:\source\llvm-project\llvm\out\build\x64-debug\bin\c-index-test.exe 
-test-load-source-usrs all -target x86_64-apple-macosx10.7 
F:\source\llvm-project\clang\test\Index\usrs.m -isystem 
F:\source\llvm-project\clang\test\Index/Inputs | 
f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe 
F:\source\llvm-project\clang\test\Index\usrs.m
  : 'RUN: at line 173';   
f:\source\llvm-project\llvm\out\build\x64-debug\bin\c-index-test.exe 
-test-load-source all F:\source\llvm-project\clang\test\Index\usrs.m -isystem 
F:\source\llvm-project\clang\test\Index/Inputs | 
f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe 
-check-prefix=CHECK-source F:\source\llvm-project\clang\test\Index\usrs.m
  --
  Exit Code: 1
  
  Command Output (stdout):
  --
  $ ":" "RUN: at line 103"
  $ "f:\source\llvm-project\llvm\out\build\x64-debug\bin\c-index-test.exe" 
"-test-load-source-usrs" "all" "-target" "x86_64-apple-macosx10.7" 
"F:\source\llvm-project\clang\test\Index\usrs.m" "-isystem" 
"F:\source\llvm-project\clang\test\Index/Inputs"
  # command stderr:
  F:\source\llvm-project\clang\test\Index\usrs.m:25:12: warning: class 'Foo' 
defined without specifying a base class [-Wobjc-root-class]
  Number FIX-ITs = 0
  F:\source\llvm-project\clang\test\Index\usrs.m:25:15: note: add a super class 
to fix this problem
  Number FIX-ITs = 0
  F:\source\llvm-project\clang\test\Index\usrs.m:51:12: warning: class 
'CWithExt' defined without specifying a base class [-Wobjc-root-class]
  Number FIX-ITs = 0
  F:\source\llvm-project\clang\test\Index\usrs.m:51:20: note: add a super class 
to fix this problem
  Number FIX-ITs = 0
  F:\source\llvm-project\clang\test\Index\usrs.m:101:9: warning: 'MACRO3' macro 
redefined [-Wmacro-redefined]
  Number FIX-ITs = 0
  F:\source\llvm-project\clang\test\Index\usrs.m:100:9: note: previous 
definition is here
  Number FIX-ITs = 0
  
  $ "f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe" 
"F:\source\llvm-project\clang\test\Index\usrs.m"
  $ ":" "RUN: at line 173"
  $ "f:\source\llvm-project\llvm\out\build\x64-debug\bin\c-index-test.exe" 
"-test-load-source" "all" "F:\source\llvm-project\clang\test\Index\usrs.m" 
"-isystem" "F:\source\llvm-project\clang\test\Index/Inputs"
  # command stderr:
  F:\source\llvm-project\clang\test\Index\usrs.m:44:13: error: synthesized 
property 'd1' must either be named the same as a compatible instance variable 
or must explicitly name an instance variable
  F:\source\llvm-project\clang\test\Index\usrs.m:25:12: warning: class 'Foo' 
defined without specifying a base class [-Wobjc-root-class]
  F:\source\llvm-project\clang\test\Index\usrs.m:25:15: note: add a super class 
to fix this problem
  F:\source\llvm-project\clang\test\Index\usrs.m:51:12: warning: class 
'CWithExt' defined without specifying a base class [-Wobjc-root-class]
  F:\source\llvm-project\clang\test\Index\usrs.m:51:20: note: add a super class 
to fix this problem
  F:\source\llvm-project\clang\test\Index\usrs.m:86:6: error: instance 
variables may not be placed in class extension
  F:\source\llvm-project\clang\test\Index\usrs.m:101:9: warning: 'MACRO3' macro 
redefined [-Wmacro-redefined]
  F:\source\llvm-project\clang\test\Index\usrs.m:100:9: note: previous 
definition is here
  F:\source\llvm-project\clang\test\Index\usrs.m:44:13: error: synthesized 
property 'd1' must either be named the same as a compatible instance variable 
or must explicitly name an instance variable
  Number FIX-ITs = 0
  

[PATCH] D135011: Add builtin_elementwise_sin and builtin_elementwise_cos

2022-10-04 Thread Xiang Li via Phabricator via cfe-commits
python3kgae added a comment.

In D135011#3834739 , @bob80905 wrote:

> Here is the code I used to test the machine code output:
>
>   typedef float float4 __attribute__((ext_vector_type(4)));
>   
>   void test_builtin_elementwise_sin(float f1, float f2, double d1, double d2, 
>   float4 vf1, float4 vf2)
>   {
> f2 = __builtin_elementwise_sin(f1);
> d2 = __builtin_elementwise_sin(d1);
> vf2 = __builtin_elementwise_sin(vf1);
>   }
>
> f2 = __builtin_elementwise_sin(f1); can be swapped for f2 = 
> __builtin_elementwise_cos(f1); to test the cos builtin,

Not sure these will test scalable vector types.
Maybe something like vfloat32mf2_t or svfloat32_t?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135011

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


[PATCH] D135118: [clang/Sema] Fix non-deterministic order for certain kind of diagnostics

2022-10-04 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added inline comments.



Comment at: clang/include/clang/AST/DeclObjC.h:1091
   virtual void collectPropertiesToImplement(PropertyMap ,
 PropertyDeclOrder ) const {}
 

benlangmuir wrote:
> Can we use the existing `PropertyDeclOrder` instead of changing the map type? 
> Or else get rid of the `PO` parameter to functions using `PropertyMap` if we 
> keep the MapVector?
I'll take a look.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135118

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


[PATCH] D133817: MSVC ABI: Looks like even non-aarch64 uses the MSVC/14 definition for pod/aggregate passing

2022-10-04 Thread David Blaikie via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4769976c49be: MSVC ABI: Looks like even non-aarch64 uses the 
MSVC/14 definition for… (authored by dblaikie).

Changed prior to commit:
  https://reviews.llvm.org/D133817?vs=460637=465139#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133817

Files:
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp

Index: clang/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
===
--- clang/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
+++ clang/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
@@ -1,8 +1,8 @@
 // RUN: %clang_cc1 -no-opaque-pointers -std=c++11 -emit-llvm %s -o - -triple=i386-pc-linux | FileCheck -check-prefix LINUX %s
-// RUN: %clang_cc1 -no-opaque-pointers -std=c++11 -emit-llvm %s -o - -triple=i386-pc-win32 -mconstructor-aliases -fno-rtti | FileCheck -check-prefix WIN32 %s
-// RUN: %clang_cc1 -no-opaque-pointers -std=c++11 -emit-llvm %s -o - -triple=thumb-pc-win32 -mconstructor-aliases -fno-rtti | FileCheck -check-prefix WOA %s
-// RUN: %clang_cc1 -no-opaque-pointers -std=c++11 -emit-llvm %s -o - -triple=x86_64-pc-win32 -mconstructor-aliases -fno-rtti | FileCheck -check-prefix WIN64 %s
-// RUN: %clang_cc1 -no-opaque-pointers -std=c++11 -emit-llvm %s -o - -triple=aarch64-windows-msvc -mconstructor-aliases -fno-rtti | FileCheck -check-prefix WOA64 %s
+// RUN: %clang_cc1 -no-opaque-pointers -std=c++11 -emit-llvm %s -o - -triple=i386-pc-win32 -mconstructor-aliases -fno-rtti | FileCheck -check-prefix WIN32 --check-prefix WIN %s
+// RUN: %clang_cc1 -no-opaque-pointers -std=c++11 -emit-llvm %s -o - -triple=thumb-pc-win32 -mconstructor-aliases -fno-rtti | FileCheck -check-prefix WOA --check-prefix WIN %s
+// RUN: %clang_cc1 -no-opaque-pointers -std=c++11 -emit-llvm %s -o - -triple=x86_64-pc-win32 -mconstructor-aliases -fno-rtti | FileCheck -check-prefix WIN64 --check-prefix WIN %s
+// RUN: %clang_cc1 -no-opaque-pointers -std=c++11 -emit-llvm %s -o - -triple=aarch64-windows-msvc -mconstructor-aliases -fno-rtti | FileCheck -check-prefix WOA64 --check-prefix WIN %s
 
 struct Empty {};
 
@@ -74,6 +74,10 @@
  int i;
 };
 
+struct SmallWithSmallWithPrivate {
+  SmallWithPrivate p;
+};
+
 // WIN32: declare dso_local void @"{{.*take_bools_and_chars.*}}"
 // WIN32:   (<{ i8, [3 x i8], i8, [3 x i8], %struct.SmallWithDtor,
 // WIN32:   i8, [3 x i8], i8, [3 x i8], i32, i8, [3 x i8] }>* inalloca(<{ i8, [3 x i8], i8, [3 x i8], %struct.SmallWithDtor, i8, [3 x i8], i8, [3 x i8], i32, i8, [3 x i8] }>)
@@ -197,6 +201,10 @@
 // WOA64: define dso_local void @"?small_arg_with_private_member@@YA?AUSmallWithPrivate@@U1@@Z"(%struct.SmallWithPrivate* inreg noalias sret(%struct.SmallWithPrivate) align 4 %agg.result, i64 %s.coerce) {{.*}} {
 SmallWithPrivate small_arg_with_private_member(SmallWithPrivate s) { return s; }
 
+// WOA64: define dso_local i32 @"?small_arg_with_small_struct_with_private_member@@YA?AUSmallWithSmallWithPrivate@@U1@@Z"(i64 %s.coerce) {{.*}} {
+// WIN64: define dso_local i32 @"?small_arg_with_small_struct_with_private_member@@YA?AUSmallWithSmallWithPrivate@@U1@@Z"(i32 %s.coerce) {{.*}} {
+SmallWithSmallWithPrivate small_arg_with_small_struct_with_private_member(SmallWithSmallWithPrivate s) { return s; }
+
 void call_small_arg_with_dtor() {
   small_arg_with_dtor(SmallWithDtor());
 }
@@ -468,3 +476,32 @@
 // WIN64-LABEL: define dso_local void @"?g@C@pr30293@@QEAAXXZ"(%"struct.pr30293::C"* {{[^,]*}} %this)
 // WIN64: declare dso_local void @"?h@C@pr30293@@UEAAXUSmallWithDtor@@@Z"(i8* noundef, i32)
 }
+
+namespace protected_member_of_member {
+struct field { protected: int i; };
+struct t1 {
+  field f;
+};
+extern const t1& v1;
+t1 f1() { return v1; }
+// WIN: define dso_local {{.*}}i32 @"?f1@protected_member_of_member@@YA?AUt1@1@XZ"()
+}
+
+namespace default_member_initializer {
+struct t1 {
+  int i = 3;
+};
+extern const t1& v1;
+t1 f1() { return v1; }
+// WIN: define dso_local {{.*}}i32 @"?f1@default_member_initializer@@YA?AUt1@1@XZ"()
+}
+
+namespace defaulted_copy_ctor {
+struct t1 {
+  int i;
+  t1(const t1&) = default;
+};
+extern const t1& v1;
+t1 f1() { return v1; }
+// WIN: define dso_local {{.*}}i32 @"?f1@defaulted_copy_ctor@@YA?AUt1@1@XZ"()
+}
Index: clang/lib/CodeGen/MicrosoftCXXABI.cpp
===
--- clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1086,8 +1086,8 @@
   return isDeletingDtor(GD);
 }
 
-static bool isTrivialForAArch64MSVC(const CXXRecordDecl *RD) {
-  // For AArch64, we use the C++14 definition of an aggregate, so we also
+static bool isTrivialForMSVC(const 

[clang] 4769976 - MSVC ABI: Looks like even non-aarch64 uses the MSVC/14 definition for pod/aggregate passing

2022-10-04 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-10-04T20:19:17Z
New Revision: 4769976c49be468d7629d513080e6959a25adcfe

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

LOG: MSVC ABI: Looks like even non-aarch64 uses the MSVC/14 definition for 
pod/aggregate passing

Details posted here: https://reviews.llvm.org/D119051#3747201

3 cases that were inconsistent with the MSABI without this patch applied:
  https://godbolt.org/z/GY48qxh3G - field with protected member
  https://godbolt.org/z/Mb1PYhjrP - non-static data member initializer
  https://godbolt.org/z/sGvxcEPjo - defaulted copy constructor

I'm not sure what's suitable/sufficient testing for this - I did verify
the three cases above. Though if it helps to add them as explicit tests,
I can do that too.

Also, I was wondering if the other use of isTrivialForAArch64MSVC in
isPermittedToBeHomogenousAggregate could be another source of bugs - I
tried changing the function to unconditionally call
isTrivialFor(AArch64)MSVC without testing AArch64 first, but no tests
fail, so it looks like this is undertested in any case. But I had
trouble figuring out how to exercise this functionality properly to add
test coverage and then compare that to MSVC itself... - I got very
confused/turned around trying to test this, so I've given up enough to
send what I have out for review, but happy to look further into this
with help.

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

Added: 


Modified: 
clang/lib/CodeGen/MicrosoftCXXABI.cpp
clang/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp 
b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index 76aeb7bb7b76..1034066b472e 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1086,8 +1086,8 @@ bool MicrosoftCXXABI::hasMostDerivedReturn(GlobalDecl GD) 
const {
   return isDeletingDtor(GD);
 }
 
-static bool isTrivialForAArch64MSVC(const CXXRecordDecl *RD) {
-  // For AArch64, we use the C++14 definition of an aggregate, so we also
+static bool isTrivialForMSVC(const CXXRecordDecl *RD) {
+  // We use the C++14 definition of an aggregate, so we also
   // check for:
   //   No private or protected non static data members.
   //   No base classes
@@ -1115,15 +1115,7 @@ bool MicrosoftCXXABI::classifyReturnType(CGFunctionInfo 
) const {
   if (!RD)
 return false;
 
-  // Normally, the C++ concept of "is trivially copyable" is used to determine
-  // if a struct can be returned directly. However, as MSVC and the language
-  // have evolved, the definition of "trivially copyable" has changed, while 
the
-  // ABI must remain stable. AArch64 uses the C++14 concept of an "aggregate",
-  // while other ISAs use the older concept of "plain old data".
-  bool isTrivialForABI = RD->isPOD();
-  bool isAArch64 = CGM.getTarget().getTriple().isAArch64();
-  if (isAArch64)
-isTrivialForABI = RD->canPassInRegisters() && isTrivialForAArch64MSVC(RD);
+  bool isTrivialForABI = RD->canPassInRegisters() && isTrivialForMSVC(RD);
 
   // MSVC always returns structs indirectly from C++ instance methods.
   bool isIndirectReturn = !isTrivialForABI || FI.isInstanceMethod();
@@ -1137,7 +1129,7 @@ bool MicrosoftCXXABI::classifyReturnType(CGFunctionInfo 
) const {
 
 // On AArch64, use the `inreg` attribute if the object is considered to not
 // be trivially copyable, or if this is an instance method struct return.
-FI.getReturnInfo().setInReg(isAArch64);
+FI.getReturnInfo().setInReg(CGM.getTarget().getTriple().isAArch64());
 
 return true;
   }

diff  --git a/clang/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp 
b/clang/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
index d6ee0684e36f..08c9faf6fd77 100644
--- a/clang/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
+++ b/clang/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
@@ -1,8 +1,8 @@
 // RUN: %clang_cc1 -no-opaque-pointers -std=c++11 -emit-llvm %s -o - 
-triple=i386-pc-linux | FileCheck -check-prefix LINUX %s
-// RUN: %clang_cc1 -no-opaque-pointers -std=c++11 -emit-llvm %s -o - 
-triple=i386-pc-win32 -mconstructor-aliases -fno-rtti | FileCheck -check-prefix 
WIN32 %s
-// RUN: %clang_cc1 -no-opaque-pointers -std=c++11 -emit-llvm %s -o - 
-triple=thumb-pc-win32 -mconstructor-aliases -fno-rtti | FileCheck 
-check-prefix WOA %s
-// RUN: %clang_cc1 -no-opaque-pointers -std=c++11 -emit-llvm %s -o - 
-triple=x86_64-pc-win32 -mconstructor-aliases -fno-rtti | FileCheck 
-check-prefix WIN64 %s
-// RUN: %clang_cc1 -no-opaque-pointers -std=c++11 -emit-llvm %s -o - 
-triple=aarch64-windows-msvc -mconstructor-aliases -fno-rtti | FileCheck 
-check-prefix WOA64 %s
+// RUN: %clang_cc1 -no-opaque-pointers -std=c++11 -emit-llvm %s -o - 

[PATCH] D135118: [clang/Sema] Fix non-deterministic order for certain kind of diagnostics

2022-10-04 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a comment.

In D135118#3833978 , @steven_wu wrote:

> LGTM.
>
> `RemoveDecl` does become more expensive but I don't have better solution.

Luckily AFAICT this is not a "hot" function.

> I am also wondering if as follow up we should add an option to 
> `VerifyDiagnosticConsumer` to be location aware (so the diagnostics from a 
> file is emitted in order) to prevent more problem like this.

Interesting idea! Something to keep in mind.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135118

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


[PATCH] D20401: [Lexer] Don't merge macro args from different macro files

2022-10-04 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

In D20401#3833201 , @hokein wrote:

>>> Meanwhile, I think besides evaluating the high level logic in in TokenLexer 
>>> and how it might be improved, I think there's potentially an opportunity 
>>> for a "AOS vs. SOA" speedup in SourceManager. 
>>> SourceManager::LoadedSLocEntryTable is a 
>>> llvm::SmallVector. SourceManager::getFileIDLoaded only 
>>> really cares about the SLocEntry's Offset. I suspect we could get major 
>>> memory locality wins by packing those into a standalone vector so that we 
>>> could search them faster.
>>
>> Ah, great point. SLocEntry is 24 bytes while Offset is only 4.
>
> And SLocEntry costs 4 bytes for padding only, which is bad :(
>
>> SLocEntry is an important public API, but Offset is ~only used in 
>> SourceManager, so that refactoring might be doable. I guess we can cheaply 
>> prototype by redundantly storing offset *both* in a separate array used for 
>> search and in the SLocEntry.

Do we need to store both the whole SLocEntry and a copy of the Offset, or can 
we just store the Offset (or perhaps individual arrays of the pieces of an 
SLocEntry)? Perhaps we can lazily materialize an SLocEntry only when needed, if 
ever?

> This is an interesting idea. I got a quick prototype of adding an in-parallel 
> offset table in SourceManager:
>
> - clang::SourceManager::getFileIDLocal  2.45% -> 1.57% (reduce by 30%+)
> - SourceManager memory usage is increased by ~10%:  `SemaExpr.cpp` 12.6MB -> 
> 14.3MB

How did you measure the memory usage of an individual class? (I think we should 
move this discussion to LLVM Discourse for more visibility of our discussion).

> The improvement of `getFileIDLocal` seems promising, but the memory 
> increasement is a thing (10% is not small, maybe it is ok compared the actual 
> AST size).

At this point, I'll pay it.  Unless it regresses peak RSS of the compiler, I 
don't care.

> An alternative is to restructure the SLocEntry and the underlying storage in 
> SourceManager, it will give us both performance and memory improvement, but 
> we need to make a significant change of the SourceManager.

At this point, I think it's worth it.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D20401

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


[PATCH] D134617: [HLSL] Support register binding attribute on global variable

2022-10-04 Thread Xiang Li via Phabricator via cfe-commits
python3kgae marked an inline comment as done.
python3kgae added inline comments.



Comment at: clang/include/clang/Parse/Parser.h:2817-2818
 
+  void MaybeParseHLSLSemantics(Declarator ,
+   SourceLocation *EndLoc = nullptr) {
+if (Tok.is(tok::colon)) {

aaron.ballman wrote:
> aaron.ballman wrote:
> > Let's assert we're in HLSL mode here so that we don't accidentally call 
> > this from non-HLSL parsing contexts.
> Precommit CI finds a way to trigger this assert, so it looks like we caught a 
> case we didn't know about (yay asserts!).
Yeah. Pre-commit CI is really cool. :)

It would be nice if there's an optional config so we can let it test 
experimental targets too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134617

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


[PATCH] D135011: Add builtin_elementwise_sin and builtin_elementwise_cos

2022-10-04 Thread Joshua Batista via Phabricator via cfe-commits
bob80905 added a comment.

Here is the code I used to test the machine code output:

  typedef float float4 __attribute__((ext_vector_type(4)));
  
  void test_builtin_elementwise_sin(float f1, float f2, double d1, double d2, 
  float4 vf1, float4 vf2)
  {
f2 = __builtin_elementwise_sin(f1);
d2 = __builtin_elementwise_sin(d1);
vf2 = __builtin_elementwise_sin(vf1);
  }

f2 = __builtin_elementwise_sin(f1); can be swapped for f2 = 
__builtin_elementwise_cos(f1); to test the cos builtin,


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135011

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


[clang] 2e1c1d6 - MSVC AArch64 ABI: Homogeneous aggregates

2022-10-04 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-10-04T20:17:29Z
New Revision: 2e1c1d6d72879cafc339ad035b1b5a6d1c8cc130

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

LOG: MSVC AArch64 ABI: Homogeneous aggregates

Fixes:
Protected members, HFA: https://godbolt.org/z/zqdK7vdKc
Private members, HFA: https://godbolt.org/z/zqdK7vdKc
Non-empty base, HFA: https://godbolt.org/z/PKTz59Wev
User-provided ctor, HFA: https://godbolt.org/z/sfrTddcW6

Existing correct cases:
Empty base class, NonHFA: https://godbolt.org/z/4veY9MWP3
 - correct by accident of not allowing bases at all (see non-empty base
   case/fix above for counterexample)
Polymorphic: NonHFA: https://godbolt.org/z/4veY9MWP3
Trivial copy assignment, HFA: https://godbolt.org/z/Tdecj836P
Non-trivial copy assignment, NonHFA: https://godbolt.org/z/7c4bE9Whq
Non-trivial default ctor, NonHFA: https://godbolt.org/z/Tsq1EE7b7
 - correct by accident of disallowing all user-provided ctors (see
   user-provided non-default ctor example above for counterexample)
Trivial dtor, HFA: https://godbolt.org/z/nae999aqz
Non-trivial dtor, NonHFA: https://godbolt.org/z/69oMcshb1
Empty field, NonHFA: https://godbolt.org/z/8PTxsKKMK
 - true due to checking for the absence of padding (see comment in code)

After a bunch of testing, this fixes a bunch of cases that were
incorrect. Some of the tests verify the nuances of the existing
behavior/code checks that were already present.

This was mostly motivated by cleanup from/in D133817 which itself was
motivated by D119051.

By removing the incorrect use of isTrivialForAArch64MSVC here & adding
more nuance to the homogeneous testing we can more safely/confidently
make changes to the isTrivialFor(AArch64)MSVC to more properly align
with its usage anyway.

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

Added: 


Modified: 
clang/lib/CodeGen/MicrosoftCXXABI.cpp
clang/test/CodeGenCXX/homogeneous-aggregates.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp 
b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index 539f0a6eb8cb8..76aeb7bb7b76f 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -4476,10 +4476,45 @@ MicrosoftCXXABI::LoadVTablePtr(CodeGenFunction , 
Address This,
 }
 
 bool MicrosoftCXXABI::isPermittedToBeHomogeneousAggregate(
-const CXXRecordDecl *CXXRD) const {
-  // MSVC Windows on Arm64 considers a type not HFA if it is not an
-  // aggregate according to the C++14 spec. This is not consistent with the
-  // AAPCS64, but is defacto spec on that platform.
-  return !CGM.getTarget().getTriple().isAArch64() ||
- isTrivialForAArch64MSVC(CXXRD);
+const CXXRecordDecl *RD) const {
+  // All aggregates are permitted to be HFA on non-ARM platforms, which mostly
+  // affects vectorcall on x64/x86.
+  if (!CGM.getTarget().getTriple().isAArch64())
+return true;
+  // MSVC Windows on Arm64 has its own rules for determining if a type is HFA
+  // that are inconsistent with the AAPCS64 ABI. The following are our best
+  // determination of those rules so far, based on observation of MSVC's
+  // behavior.
+  if (RD->isEmpty())
+return false;
+  if (RD->isPolymorphic())
+return false;
+  if (RD->hasNonTrivialCopyAssignment())
+return false;
+  if (RD->hasNonTrivialDestructor())
+return false;
+  if (RD->hasNonTrivialDefaultConstructor())
+return false;
+  // These two are somewhat redundant given the caller
+  // (ABIInfo::isHomogeneousAggregate) checks the bases and fields, but that
+  // caller doesn't consider empty bases/fields to be non-homogenous, but it
+  // looks like Microsoft's AArch64 ABI does care about these empty types &
+  // anything containing/derived from one is non-homogeneous.
+  // Instead we could add another CXXABI entry point to query this property and
+  // have ABIInfo::isHomogeneousAggregate use that property.
+  // I don't think any other of the features listed above could be true of a
+  // base/field while not true of the outer struct. For example, if you have a
+  // base/field that has an non-trivial copy assignment/dtor/default ctor, then
+  // the outer struct's corresponding operation must be non-trivial.
+  for (const CXXBaseSpecifier  : RD->bases()) {
+if (const CXXRecordDecl *FRD = B.getType()->getAsCXXRecordDecl()) {
+  if (!isPermittedToBeHomogeneousAggregate(FRD))
+return false;
+}
+  }
+  // empty fields seem to be caught by the ABIInfo::isHomogeneousAggregate
+  // checking for padding - but maybe there are ways to end up with an empty
+  // field without padding? Not that I know of, so don't check fields here &
+  // rely on the padding check.
+  return true;
 }

diff  --git a/clang/test/CodeGenCXX/homogeneous-aggregates.cpp 

[PATCH] D134688: MSVC AArch64 ABI: Homogeneous aggregates

2022-10-04 Thread David Blaikie via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2e1c1d6d7287: MSVC AArch64 ABI: Homogeneous aggregates 
(authored by dblaikie).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134688

Files:
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/test/CodeGenCXX/homogeneous-aggregates.cpp

Index: clang/test/CodeGenCXX/homogeneous-aggregates.cpp
===
--- clang/test/CodeGenCXX/homogeneous-aggregates.cpp
+++ clang/test/CodeGenCXX/homogeneous-aggregates.cpp
@@ -92,7 +92,7 @@
 // ARM32: define{{.*}} arm_aapcs_vfpcc void @_Z15with_empty_base16HVAWithEmptyBase(%struct.HVAWithEmptyBase %a.coerce)
 void CC with_empty_base(HVAWithEmptyBase a) {}
 
-// FIXME: MSVC doesn't consider this an HVA because of the empty base.
+// WOA64: define dso_local void @"?with_empty_base@@YAXUHVAWithEmptyBase@@@Z"([2 x i64] %{{.*}})
 // X64: define dso_local x86_vectorcallcc void @"\01_Z15with_empty_base16HVAWithEmptyBase@@16"(%struct.HVAWithEmptyBase inreg %a.coerce)
 
 struct HVAWithEmptyBitField : Float1, Float2 {
@@ -172,4 +172,117 @@
   // WOA64-LABEL: define dso_local void @"?call_copy_haspodbase@pr47611@@YAXPEAUHasPodBase@1@@Z"
   // WOA64: call void @"?copy@pr47611@@YA?AUHasPodBase@1@PEAU21@@Z"(%"struct.pr47611::HasPodBase"* inreg sret(%"struct.pr47611::HasPodBase") align 8 %{{.*}}, %"struct.pr47611::HasPodBase"* noundef %{{.*}})
 }
-}; // namespace pr47611
+} // namespace pr47611
+
+namespace protected_member {
+struct HFA {
+  double x;
+  double y;
+protected:
+  double z;
+};
+double foo(HFA v) { return v.x + v.y; }
+// WOA64: define dso_local noundef double @"?foo@protected_member@@YANUHFA@1@@Z"([3 x double] %{{.*}})
+}
+namespace private_member {
+struct HFA {
+  double x;
+  double y;
+private:
+  double z;
+};
+double foo(HFA v) { return v.x + v.y; }
+// WOA64: define dso_local noundef double @"?foo@private_member@@YANUHFA@1@@Z"([3 x double] %{{.*}})
+}
+namespace polymorphic {
+struct NonHFA {
+  double x;
+  double y;
+  double z;
+  virtual void f1();
+};
+double foo(NonHFA v) { return v.x + v.y; }
+// WOA64: define dso_local noundef double @"?foo@polymorphic@@YANUNonHFA@1@@Z"(%"struct.polymorphic::NonHFA"* noundef %{{.*}})
+}
+namespace trivial_copy_assignment {
+struct HFA {
+  double x;
+  double y;
+  double z;
+  HFA =(const HFA&) = default;
+};
+double foo(HFA v) { return v.x + v.y; }
+// WOA64: define dso_local noundef double @"?foo@trivial_copy_assignment@@YANUHFA@1@@Z"([3 x double] %{{.*}})
+}
+namespace non_trivial_copy_assignment {
+struct NonHFA {
+  double x;
+  double y;
+  double z;
+  NonHFA =(const NonHFA&);
+};
+double foo(NonHFA v) { return v.x + v.y; }
+// WOA64: define dso_local noundef double @"?foo@non_trivial_copy_assignment@@YANUNonHFA@1@@Z"(%"struct.non_trivial_copy_assignment::NonHFA"* noundef %{{.*}})
+}
+namespace user_provided_ctor {
+struct HFA {
+  double x;
+  double y;
+  double z;
+  HFA(int);
+};
+double foo(HFA v) { return v.x + v.y; }
+// WOA64: define dso_local noundef double @"?foo@user_provided_ctor@@YANUHFA@1@@Z"([3 x double] %{{.*}})
+}
+namespace trivial_dtor {
+struct HFA {
+  double x;
+  double y;
+  double z;
+  ~HFA() = default;
+};
+double foo(HFA v) { return v.x + v.y; }
+// WOA64: define dso_local noundef double @"?foo@trivial_dtor@@YANUHFA@1@@Z"([3 x double] %{{.*}})
+}
+namespace non_trivial_dtor {
+struct NonHFA {
+  double x;
+  double y;
+  double z;
+  ~NonHFA();
+};
+double foo(NonHFA v) { return v.x + v.y; }
+// WOA64: define dso_local noundef double @"?foo@non_trivial_dtor@@YANUNonHFA@1@@Z"(%"struct.non_trivial_dtor::NonHFA"* noundef %{{.*}})
+}
+namespace non_empty_base {
+struct non_empty_base { double d; };
+struct HFA : non_empty_base {
+  double x;
+  double y;
+  double z;
+};
+double foo(HFA v) { return v.x + v.y; }
+// WOA64: define dso_local noundef double @"?foo@non_empty_base@@YANUHFA@1@@Z"([4 x double] %{{.*}})
+}
+namespace empty_field {
+struct empty { };
+struct NonHFA {
+  double x;
+  double y;
+  double z;
+  empty e;
+};
+double foo(NonHFA v) { return v.x + v.y; }
+// WOA64: define dso_local noundef double @"?foo@empty_field@@YANUNonHFA@1@@Z"(%"struct.empty_field::NonHFA"* noundef %{{.*}})
+}
+namespace non_empty_field {
+struct non_empty { double d; };
+struct HFA {
+  double x;
+  double y;
+  double z;
+  non_empty e;
+};
+double foo(HFA v) { return v.x + v.y; }
+// WOA64: define dso_local noundef double @"?foo@non_empty_field@@YANUHFA@1@@Z"([4 x double] %{{.*}})
+}
Index: clang/lib/CodeGen/MicrosoftCXXABI.cpp
===
--- clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -4476,10 +4476,45 @@
 }
 
 bool MicrosoftCXXABI::isPermittedToBeHomogeneousAggregate(
-const CXXRecordDecl *CXXRD) const {
-  // MSVC Windows on Arm64 considers a type not HFA if it is not 

[PATCH] D134942: [Lex] Simplify and cleanup the updateConsecutiveMacroArgTokens implementation.

2022-10-04 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: clang/lib/Lex/TokenLexer.cpp:1019
+// sourcelocation-against-bounds comparison.
+FileID BeginFID = SM.getFileID(BeginLoc);
+SourceLocation Limit =

sammccall wrote:
> this getFileID() call is unneccesary when `All.empty() || 
> All.front().getLocation().isFileID()`.
> 
> Worth checking whether bailing out in that case is profitable?
> 
> You could do it right at the top:
> ```
> if (All.size() == 1 || All[0].getLocation().isFileID() != 
> All[1].getLocation().isFileID())
>   return All.take_front(1);
> ```
Good point; I'd say "avoid getFileID" at all costs, even to readability/style.



Comment at: clang/lib/Lex/TokenLexer.cpp:1008
+});
+assert(!Partition.empty() &&
+   llvm::all_of(Partition.drop_front(),

hokein wrote:
> sammccall wrote:
> > nickdesaulniers wrote:
> > > Could you just check that all of the tokens in the partition have the 
> > > same fileID as the first token?
> > > 
> > > ```
> > > FileID FirstFID = SM.getFileID(Partition[0]->getLocation());
> > > llvm::all_of(Partition, [, ](const Token ) { return 
> > > SM.getFileID(T.getLocation() == FID; });
> > > ```
> > > or move the assertion into the take_while above so we iterate less?
> > this assertion seems to belong outside the if() - it applies to both the 
> > file/macro case?
> > I'd suggest asserting nonempty first and then the rest as another assertion.
> > also missing an assertion that if there are any more tokens, the next token 
> > has a different FileID
> > 
> > that said with these assertions we should probably check we're not 
> > regressing debug performance too much!
> The optimization for this case is that we don't call any `getFileID`, the 
> getFileID is only needed in the assert sanity check, so moving the assertion 
> to `take_while` doesn't really work.
> 
> I adjust the code to save some unnecessary `getFileID` call in assert.
Right, I do all development and profiles with Release builds with assertions 
enabled.  So avoiding getFileID in release+no_asserts builds is a win, but am 
somewhat bummed to not get as much a win for my rel+assert builds.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134942

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


[PATCH] D135115: [clang-format] update --files help description

2022-10-04 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen updated this revision to Diff 465134.
ychen added a comment.

- address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135115

Files:
  clang/docs/ClangFormat.rst


Index: clang/docs/ClangFormat.rst
===
--- clang/docs/ClangFormat.rst
+++ clang/docs/ClangFormat.rst
@@ -26,7 +26,7 @@
   together with s, the files are edited in-place. Otherwise, the
   result is written to the standard output.
 
-  USAGE: clang-format [options] [ ...]
+  USAGE: clang-format [options] [@] [ ...] 
 
   OPTIONS:
 
@@ -69,7 +69,8 @@
 --ferror-limit=  - Set the maximum number of clang-format 
errors to emit
  before stopping (0 = no limit).
  Used only with --dry-run or -n
---files=   - Provide a list of files to run 
clang-format
+--files= - A file containing a list of files to 
process, one
+ per line.
 -i - Inplace edit s, if specified.
 --length=- Format a range of this length (in bytes).
  Multiple ranges can be formatted by 
specifying


Index: clang/docs/ClangFormat.rst
===
--- clang/docs/ClangFormat.rst
+++ clang/docs/ClangFormat.rst
@@ -26,7 +26,7 @@
   together with s, the files are edited in-place. Otherwise, the
   result is written to the standard output.
 
-  USAGE: clang-format [options] [ ...]
+  USAGE: clang-format [options] [@] [ ...] 
 
   OPTIONS:
 
@@ -69,7 +69,8 @@
 --ferror-limit=  - Set the maximum number of clang-format errors to emit
  before stopping (0 = no limit).
  Used only with --dry-run or -n
---files=   - Provide a list of files to run clang-format
+--files= - A file containing a list of files to process, one
+ per line.
 -i - Inplace edit s, if specified.
 --length=- Format a range of this length (in bytes).
  Multiple ranges can be formatted by specifying
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D135062: [clang-tools-extra] [clangd] Respect llvm_shlib_dir in tests

2022-10-04 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG77945a344c3d: [clang-tools-extra] [clangd] Respect 
llvm_shlib_dir in tests (authored by mgorny).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135062

Files:
  clang-tools-extra/clangd/test/lit.site.cfg.py.in


Index: clang-tools-extra/clangd/test/lit.site.cfg.py.in
===
--- clang-tools-extra/clangd/test/lit.site.cfg.py.in
+++ clang-tools-extra/clangd/test/lit.site.cfg.py.in
@@ -10,6 +10,7 @@
 config.clang_tools_dir = lit_config.substitute("@CURRENT_TOOLS_DIR@")
 config.llvm_tools_dir = lit_config.substitute("@LLVM_TOOLS_DIR@")
 config.llvm_libs_dir = lit_config.substitute("@LLVM_LIBS_DIR@")
+config.llvm_shlib_dir = "@SHLIBDIR@"
 
 config.clangd_source_dir = "@CMAKE_CURRENT_SOURCE_DIR@/.."
 config.clangd_binary_dir = "@CMAKE_CURRENT_BINARY_DIR@/.."


Index: clang-tools-extra/clangd/test/lit.site.cfg.py.in
===
--- clang-tools-extra/clangd/test/lit.site.cfg.py.in
+++ clang-tools-extra/clangd/test/lit.site.cfg.py.in
@@ -10,6 +10,7 @@
 config.clang_tools_dir = lit_config.substitute("@CURRENT_TOOLS_DIR@")
 config.llvm_tools_dir = lit_config.substitute("@LLVM_TOOLS_DIR@")
 config.llvm_libs_dir = lit_config.substitute("@LLVM_LIBS_DIR@")
+config.llvm_shlib_dir = "@SHLIBDIR@"
 
 config.clangd_source_dir = "@CMAKE_CURRENT_SOURCE_DIR@/.."
 config.clangd_binary_dir = "@CMAKE_CURRENT_BINARY_DIR@/.."
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 77945a3 - [clang-tools-extra] [clangd] Respect llvm_shlib_dir in tests

2022-10-04 Thread Michał Górny via cfe-commits

Author: Michał Górny
Date: 2022-10-04T22:12:37+02:00
New Revision: 77945a344c3dee3f9735744c8d4151ef2cec6a8d

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

LOG: [clang-tools-extra] [clangd] Respect llvm_shlib_dir in tests

Add llvm_shlib_dir to variables used in clangd test suite, consistently
to how it is used in the test suites of clang, clang-tools-extra
and a few other components.  This is necessary to ensure that
the correct shared libraries are used when building clang standalone --
otherwise, use_clang() sets LD_LIBRARY_PATH to the directory containing
the earlier system installation of clang rather than the just-built
library.

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

Added: 


Modified: 
clang-tools-extra/clangd/test/lit.site.cfg.py.in

Removed: 




diff  --git a/clang-tools-extra/clangd/test/lit.site.cfg.py.in 
b/clang-tools-extra/clangd/test/lit.site.cfg.py.in
index 20caa72af3da1..1fe7c8d0f3244 100644
--- a/clang-tools-extra/clangd/test/lit.site.cfg.py.in
+++ b/clang-tools-extra/clangd/test/lit.site.cfg.py.in
@@ -10,6 +10,7 @@ config.python_executable = "@Python3_EXECUTABLE@"
 config.clang_tools_dir = lit_config.substitute("@CURRENT_TOOLS_DIR@")
 config.llvm_tools_dir = lit_config.substitute("@LLVM_TOOLS_DIR@")
 config.llvm_libs_dir = lit_config.substitute("@LLVM_LIBS_DIR@")
+config.llvm_shlib_dir = "@SHLIBDIR@"
 
 config.clangd_source_dir = "@CMAKE_CURRENT_SOURCE_DIR@/.."
 config.clangd_binary_dir = "@CMAKE_CURRENT_BINARY_DIR@/.."



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


[PATCH] D134813: Properly print unnamed TagDecl objects in diagnostics

2022-10-04 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D134813#3834613 , @sammccall wrote:

> Changing USR generation to not rely on this detail seems easier, I can take a 
> stab at this.

Seems trivial: https://reviews.llvm.org/D135191
If there are still diffs in USR tests after rebasing on that, I'm happy to take 
a look at them.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134813

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


[PATCH] D135062: [clang-tools-extra] [clangd] Respect llvm_shlib_dir in tests

2022-10-04 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

Thanks!


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

https://reviews.llvm.org/D135062

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


[PATCH] D135191: [Index] USRGeneration doesn't depend on unnamed.printName() => ''. NFC

2022-10-04 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: aaron.ballman.
Herald added a subscriber: arphaman.
Herald added a project: All.
sammccall requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This prepares for printName() to print `(anonymous struct)` etc in D134813 
.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135191

Files:
  clang/lib/Index/USRGeneration.cpp


Index: clang/lib/Index/USRGeneration.cpp
===
--- clang/lib/Index/USRGeneration.cpp
+++ clang/lib/Index/USRGeneration.cpp
@@ -179,10 +179,11 @@
 
//===--===//
 
 bool USRGenerator::EmitDeclName(const NamedDecl *D) {
-  const unsigned startSize = Buf.size();
-  D->printName(Out);
-  const unsigned endSize = Buf.size();
-  return startSize == endSize;
+  DeclarationName N = D->getDeclName();
+  if (N.isEmpty())
+return true;
+  Out << N;
+  return false;
 }
 
 bool USRGenerator::ShouldGenerateLocation(const NamedDecl *D) {


Index: clang/lib/Index/USRGeneration.cpp
===
--- clang/lib/Index/USRGeneration.cpp
+++ clang/lib/Index/USRGeneration.cpp
@@ -179,10 +179,11 @@
 //===--===//
 
 bool USRGenerator::EmitDeclName(const NamedDecl *D) {
-  const unsigned startSize = Buf.size();
-  D->printName(Out);
-  const unsigned endSize = Buf.size();
-  return startSize == endSize;
+  DeclarationName N = D->getDeclName();
+  if (N.isEmpty())
+return true;
+  Out << N;
+  return false;
 }
 
 bool USRGenerator::ShouldGenerateLocation(const NamedDecl *D) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D135011: Add builtin_elementwise_sin and builtin_elementwise_cos

2022-10-04 Thread Joshua Batista via Phabricator via cfe-commits
bob80905 added a comment.

In D135011#3831452 , @craig.topper 
wrote:

> Does these support scalable vector types from ARM SVE or RISC-V? I can't 
> remember what the rest of the __builtin_elementwise do. I ask because the 
> backends will probably crash for them.

I sat with @beanz and looked at the assembly code generated for the 
riscv64-unknown-elf target and the aarch64-apple-darwin target.
The compiler doesn't crash. The generated assembly looks good, there are 4 sinf 
calls, one generated for each element in the vector.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135011

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


[PATCH] D133092: [clang] fix generation of .debug_aranges with LTO

2022-10-04 Thread David Blaikie via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG165128989568: [clang] fix generation of .debug_aranges with 
LTO (authored by azat, committed by dblaikie).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133092

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/debug-options-aranges.c


Index: clang/test/Driver/debug-options-aranges.c
===
--- /dev/null
+++ clang/test/Driver/debug-options-aranges.c
@@ -0,0 +1,6 @@
+// REQUIRES: lld
+
+/// Check that the linker plugin will get -generate-arange-section.
+// RUN: %clang -### -g --target=x86_64-linux -flto  -gdwarf-aranges %s 
2>&1 | FileCheck %s
+// RUN: %clang -### -g --target=x86_64-linux -flto=thin -gdwarf-aranges %s 
2>&1 | FileCheck %s
+// CHECK: --plugin-opt=-generate-arange-section
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -509,6 +509,14 @@
 CmdArgs.push_back(Args.MakeArgString(Plugin));
   }
 
+  // Note, this solution is far from perfect, better to encode it into IR
+  // metadata, but this may not be worth it, since it looks like aranges is on
+  // the way out.
+  if (Args.hasArg(options::OPT_gdwarf_aranges)) {
+CmdArgs.push_back(
+Args.MakeArgString("--plugin-opt=-generate-arange-section"));
+  }
+
   // Try to pass driver level flags relevant to LTO code generation down to
   // the plugin.
 


Index: clang/test/Driver/debug-options-aranges.c
===
--- /dev/null
+++ clang/test/Driver/debug-options-aranges.c
@@ -0,0 +1,6 @@
+// REQUIRES: lld
+
+/// Check that the linker plugin will get -generate-arange-section.
+// RUN: %clang -### -g --target=x86_64-linux -flto  -gdwarf-aranges %s 2>&1 | FileCheck %s
+// RUN: %clang -### -g --target=x86_64-linux -flto=thin -gdwarf-aranges %s 2>&1 | FileCheck %s
+// CHECK: --plugin-opt=-generate-arange-section
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -509,6 +509,14 @@
 CmdArgs.push_back(Args.MakeArgString(Plugin));
   }
 
+  // Note, this solution is far from perfect, better to encode it into IR
+  // metadata, but this may not be worth it, since it looks like aranges is on
+  // the way out.
+  if (Args.hasArg(options::OPT_gdwarf_aranges)) {
+CmdArgs.push_back(
+Args.MakeArgString("--plugin-opt=-generate-arange-section"));
+  }
+
   // Try to pass driver level flags relevant to LTO code generation down to
   // the plugin.
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 1651289 - [clang] fix generation of .debug_aranges with LTO

2022-10-04 Thread David Blaikie via cfe-commits

Author: Azat Khuzhin
Date: 2022-10-04T20:03:36Z
New Revision: 16512898956857b13e566165ba9a195be81d325f

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

LOG: [clang] fix generation of .debug_aranges with LTO

Right now in case of LTO the section is not emited:

$ cat test.c
void __attribute__((optnone)) bar()
{
}
void __attribute__((optnone)) foo()
{
bar();
}
int main()
{
foo();
}

$ clang -flto=thin -gdwarf-aranges -g -O3 test.c
$ eu-readelf -waranges a.out  | fgrep -c -e foo -e bar
0

$ clang -gdwarf-aranges -g -O3 test.c
$ eu-readelf -waranges a.out  | fgrep -c -e foo -e bar
2

Fix this by passing explicitly --plugin-opt=-generate-arange-section.

Suggested-by: OCHyams 

Reviewed By: dblaikie, MaskRay

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

Added: 
clang/test/Driver/debug-options-aranges.c

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

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 4bc16710e194..d81faa365228 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -509,6 +509,14 @@ void tools::addLTOOptions(const ToolChain , 
const ArgList ,
 CmdArgs.push_back(Args.MakeArgString(Plugin));
   }
 
+  // Note, this solution is far from perfect, better to encode it into IR
+  // metadata, but this may not be worth it, since it looks like aranges is on
+  // the way out.
+  if (Args.hasArg(options::OPT_gdwarf_aranges)) {
+CmdArgs.push_back(
+Args.MakeArgString("--plugin-opt=-generate-arange-section"));
+  }
+
   // Try to pass driver level flags relevant to LTO code generation down to
   // the plugin.
 

diff  --git a/clang/test/Driver/debug-options-aranges.c 
b/clang/test/Driver/debug-options-aranges.c
new file mode 100644
index ..4dc098b7d185
--- /dev/null
+++ b/clang/test/Driver/debug-options-aranges.c
@@ -0,0 +1,6 @@
+// REQUIRES: lld
+
+/// Check that the linker plugin will get -generate-arange-section.
+// RUN: %clang -### -g --target=x86_64-linux -flto  -gdwarf-aranges %s 
2>&1 | FileCheck %s
+// RUN: %clang -### -g --target=x86_64-linux -flto=thin -gdwarf-aranges %s 
2>&1 | FileCheck %s
+// CHECK: --plugin-opt=-generate-arange-section



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


[PATCH] D135107: [clang][NFC] Use enum for -fstrict-flex-arrays

2022-10-04 Thread Bill Wendling via Phabricator via cfe-commits
void added inline comments.



Comment at: clang/include/clang/Driver/Options.td:1155
+  NormalizedValuesScope<"LangOptions::StrictFlexArraysLevelKind">,
+  NormalizedValues<["Default", "OneZeroOrIncomplete", "ZeroOrIncomplete", 
"Incomplete"]>,
   HelpText<"Enable optimizations based on the strict definition of flexible 
arrays">,

serge-sans-paille wrote:
> Note that this depends on https://reviews.llvm.org/D134902 to have the 
> "Incomplete" support.
Would it be better to remove `Incomplete` until that is approved?



Comment at: clang/lib/StaticAnalyzer/Core/MemRegion.cpp:799
+const FAMKind StrictFlexArraysLevel =
+  getContext().getLangOpts().getStrictFlexArraysLevel();
+if (StrictFlexArraysLevel == FAMKind::ZeroOrIncomplete ||

steakhal wrote:
> 
Doh! Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135107

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


[PATCH] D135107: [clang][NFC] Use enum for -fstrict-flex-arrays

2022-10-04 Thread Bill Wendling via Phabricator via cfe-commits
void updated this revision to Diff 465129.
void marked an inline comment as done.
void added a comment.

Use an already available context.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135107

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/StaticAnalyzer/Core/MemRegion.cpp

Index: clang/lib/StaticAnalyzer/Core/MemRegion.cpp
===
--- clang/lib/StaticAnalyzer/Core/MemRegion.cpp
+++ clang/lib/StaticAnalyzer/Core/MemRegion.cpp
@@ -794,7 +794,11 @@
 if (Size.isZero())
   return true;
 
-if (getContext().getLangOpts().StrictFlexArrays >= 2)
+using FAMKind = LangOptions::StrictFlexArraysLevelKind;
+const FAMKind StrictFlexArraysLevel =
+  Ctx.getLangOpts().getStrictFlexArraysLevel();
+if (StrictFlexArraysLevel == FAMKind::ZeroOrIncomplete ||
+StrictFlexArraysLevel == FAMKind::Incomplete)
   return false;
 
 const AnalyzerOptions  = SVB.getAnalyzerOptions();
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -15904,7 +15904,8 @@
 /// We avoid emitting out-of-bounds access warnings for such arrays.
 static bool isFlexibleArrayMemberExpr(Sema , const Expr *E,
   const NamedDecl *ND,
-  unsigned StrictFlexArraysLevel) {
+  LangOptions::StrictFlexArraysLevelKind
+  StrictFlexArraysLevel) {
 
   if (!ND)
 return false;
@@ -15919,7 +15920,9 @@
   // FIXME: While the default -fstrict-flex-arrays=0 permits Size>1 trailing
   // arrays to be treated as flexible-array-members, we still emit diagnostics
   // as if they are not. Pending further discussion...
-  if (StrictFlexArraysLevel >= 2 || Size.uge(2))
+  using FAMKind = LangOptions::StrictFlexArraysLevelKind;
+  if (StrictFlexArraysLevel == FAMKind::ZeroOrIncomplete ||
+  Size.uge(2))
 return false;
 
   const FieldDecl *FD = dyn_cast(ND);
@@ -15981,7 +15984,8 @@
   const ConstantArrayType *ArrayTy =
   Context.getAsConstantArrayType(BaseExpr->getType());
 
-  unsigned StrictFlexArraysLevel = getLangOpts().StrictFlexArrays;
+  LangOptions::StrictFlexArraysLevelKind
+StrictFlexArraysLevel = getLangOpts().getStrictFlexArraysLevel();
 
   const NamedDecl *ND = nullptr;
   if (const auto *DRE = dyn_cast(BaseExpr))
Index: clang/lib/CodeGen/CGExpr.cpp
===
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -878,16 +878,20 @@
 /// Determine whether this expression refers to a flexible array member in a
 /// struct. We disable array bounds checks for such members.
 static bool isFlexibleArrayMemberExpr(const Expr *E,
-  unsigned StrictFlexArraysLevel) {
+  LangOptions::StrictFlexArraysLevelKind
+  StrictFlexArraysLevel) {
   // For compatibility with existing code, we treat arrays of length 0 or
   // 1 as flexible array members.
   // FIXME: This is inconsistent with the warning code in SemaChecking. Unify
   // the two mechanisms.
   const ArrayType *AT = E->getType()->castAsArrayTypeUnsafe();
   if (const auto *CAT = dyn_cast(AT)) {
+using FAMKind = LangOptions::StrictFlexArraysLevelKind;
+
 // FIXME: Sema doesn't treat [1] as a flexible array member if the bound
 // was produced by macro expansion.
-if (StrictFlexArraysLevel >= 2 && CAT->getSize().ugt(0))
+if (StrictFlexArraysLevel == FAMKind::ZeroOrIncomplete &&
+CAT->getSize().ugt(0))
   return false;
 // FIXME: While the default -fstrict-flex-arrays=0 permits Size>1 trailing
 // arrays to be treated as flexible-array-members, we still emit ubsan
@@ -963,7 +967,8 @@
 static llvm::Value *getArrayIndexingBound(CodeGenFunction ,
   const Expr *Base,
   QualType ,
-  unsigned StrictFlexArraysLevel) {
+  LangOptions::StrictFlexArraysLevelKind
+  StrictFlexArraysLevel) {
   // For the vector indexing extension, the bound is the number of elements.
   if (const VectorType *VT = Base->getType()->getAs()) {
 IndexedType = Base->getType();
@@ -1001,7 +1006,8 @@
  "should not be called unless adding bounds checks");
   SanitizerScope SanScope(this);
 
-  const unsigned 

[PATCH] D135090: [Clang] fix -Wvoid-ptr-dereference for gnu89

2022-10-04 Thread Nick Desaulniers via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2dbfd06f2a8b: [Clang] fix -Wvoid-ptr-dereference for gnu89 
(authored by nickdesaulniers).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135090

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/no-warn-void-ptr-uneval.c


Index: clang/test/Sema/no-warn-void-ptr-uneval.c
===
--- clang/test/Sema/no-warn-void-ptr-uneval.c
+++ clang/test/Sema/no-warn-void-ptr-uneval.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -Wno-unused-value -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wno-unused-value -verify -std=gnu89 %s
 
 // expected-no-diagnostics
 void foo(void *vp) {
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -14536,7 +14536,7 @@
 //   [...] the expression to which [the unary * operator] is applied shall
 //   be a pointer to an object type, or a pointer to a function type
 LangOptions LO = S.getLangOpts();
-if (LO.CPlusPlus || !(LO.C99 && (IsAfterAmp || S.isUnevaluatedContext(
+if (LO.CPlusPlus || (!(LO.C99 && IsAfterAmp) && !S.isUnevaluatedContext()))
   S.Diag(OpLoc, diag::ext_typecheck_indirection_through_void_pointer)
   << LO.CPlusPlus << OpTy << Op->getSourceRange();
   }


Index: clang/test/Sema/no-warn-void-ptr-uneval.c
===
--- clang/test/Sema/no-warn-void-ptr-uneval.c
+++ clang/test/Sema/no-warn-void-ptr-uneval.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -Wno-unused-value -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wno-unused-value -verify -std=gnu89 %s
 
 // expected-no-diagnostics
 void foo(void *vp) {
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -14536,7 +14536,7 @@
 //   [...] the expression to which [the unary * operator] is applied shall
 //   be a pointer to an object type, or a pointer to a function type
 LangOptions LO = S.getLangOpts();
-if (LO.CPlusPlus || !(LO.C99 && (IsAfterAmp || S.isUnevaluatedContext(
+if (LO.CPlusPlus || (!(LO.C99 && IsAfterAmp) && !S.isUnevaluatedContext()))
   S.Diag(OpLoc, diag::ext_typecheck_indirection_through_void_pointer)
   << LO.CPlusPlus << OpTy << Op->getSourceRange();
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D135107: [clang][NFC] Use enum for -fstrict-flex-arrays

2022-10-04 Thread Bill Wendling via Phabricator via cfe-commits
void added inline comments.



Comment at: clang/include/clang/Basic/LangOptions.h:369-376
+/// Any trailing array memeber is a FAM.
+Default = 0,
+/// Any trailing array member of undefined, 0, or 1 size is a FAM.
+OneZeroOrIncomplete = 1,
+/// Any trailing array member of undefined or 0 is a FAM.
+ZeroOrIncomplete = 2,
+/// Any trailing array member of undefined or 0 is a FAM.

steakhal wrote:
> serge-sans-paille wrote:
> > typo: member
> For most cases, I can either see no initializers or only the first entry is 
> being initialized.
> I believe, by default, the entries would be initialized to `0`, `1`, and `2` 
> here anyway.
I wanted to be explicit with the numbering, because it corresponds with the 
value specified with `-fstrict-flex-arrays=`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135107

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


[clang] 2dbfd06 - [Clang] fix -Wvoid-ptr-dereference for gnu89

2022-10-04 Thread Nick Desaulniers via cfe-commits

Author: Nick Desaulniers
Date: 2022-10-04T13:01:01-07:00
New Revision: 2dbfd06f2a8ba6cd7cc3f587808f1ea2c61ad2c7

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

LOG: [Clang] fix -Wvoid-ptr-dereference for gnu89

Follow up to D134702; it looks like we were still warning for gnu89
mode.

Link: https://reviews.llvm.org/D134702
Link: 
https://github.com/ClangBuiltLinux/linux/issues/1720#issuecomment-1265738778

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/lib/Sema/SemaExpr.cpp
clang/test/Sema/no-warn-void-ptr-uneval.c

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index fca9240362e76..6d28a44952318 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -14536,7 +14536,7 @@ static QualType CheckIndirectionOperand(Sema , Expr 
*Op, ExprValueKind ,
 //   [...] the expression to which [the unary * operator] is applied shall
 //   be a pointer to an object type, or a pointer to a function type
 LangOptions LO = S.getLangOpts();
-if (LO.CPlusPlus || !(LO.C99 && (IsAfterAmp || S.isUnevaluatedContext(
+if (LO.CPlusPlus || (!(LO.C99 && IsAfterAmp) && !S.isUnevaluatedContext()))
   S.Diag(OpLoc, diag::ext_typecheck_indirection_through_void_pointer)
   << LO.CPlusPlus << OpTy << Op->getSourceRange();
   }

diff  --git a/clang/test/Sema/no-warn-void-ptr-uneval.c 
b/clang/test/Sema/no-warn-void-ptr-uneval.c
index 2aed1180ab0da..cc93efcda68f1 100644
--- a/clang/test/Sema/no-warn-void-ptr-uneval.c
+++ b/clang/test/Sema/no-warn-void-ptr-uneval.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -Wno-unused-value -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wno-unused-value -verify -std=gnu89 %s
 
 // expected-no-diagnostics
 void foo(void *vp) {



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


[PATCH] D135107: [clang][NFC] Use enum for -fstrict-flex-arrays

2022-10-04 Thread Bill Wendling via Phabricator via cfe-commits
void updated this revision to Diff 465127.
void marked 3 inline comments as done.
void added a comment.

Fix typos.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135107

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/StaticAnalyzer/Core/MemRegion.cpp

Index: clang/lib/StaticAnalyzer/Core/MemRegion.cpp
===
--- clang/lib/StaticAnalyzer/Core/MemRegion.cpp
+++ clang/lib/StaticAnalyzer/Core/MemRegion.cpp
@@ -794,7 +794,11 @@
 if (Size.isZero())
   return true;
 
-if (getContext().getLangOpts().StrictFlexArrays >= 2)
+using FAMKind = LangOptions::StrictFlexArraysLevelKind;
+const FAMKind StrictFlexArraysLevel =
+  getContext().getLangOpts().getStrictFlexArraysLevel();
+if (StrictFlexArraysLevel == FAMKind::ZeroOrIncomplete ||
+StrictFlexArraysLevel == FAMKind::Incomplete)
   return false;
 
 const AnalyzerOptions  = SVB.getAnalyzerOptions();
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -15904,7 +15904,8 @@
 /// We avoid emitting out-of-bounds access warnings for such arrays.
 static bool isFlexibleArrayMemberExpr(Sema , const Expr *E,
   const NamedDecl *ND,
-  unsigned StrictFlexArraysLevel) {
+  LangOptions::StrictFlexArraysLevelKind
+  StrictFlexArraysLevel) {
 
   if (!ND)
 return false;
@@ -15919,7 +15920,9 @@
   // FIXME: While the default -fstrict-flex-arrays=0 permits Size>1 trailing
   // arrays to be treated as flexible-array-members, we still emit diagnostics
   // as if they are not. Pending further discussion...
-  if (StrictFlexArraysLevel >= 2 || Size.uge(2))
+  using FAMKind = LangOptions::StrictFlexArraysLevelKind;
+  if (StrictFlexArraysLevel == FAMKind::ZeroOrIncomplete ||
+  Size.uge(2))
 return false;
 
   const FieldDecl *FD = dyn_cast(ND);
@@ -15981,7 +15984,8 @@
   const ConstantArrayType *ArrayTy =
   Context.getAsConstantArrayType(BaseExpr->getType());
 
-  unsigned StrictFlexArraysLevel = getLangOpts().StrictFlexArrays;
+  LangOptions::StrictFlexArraysLevelKind
+StrictFlexArraysLevel = getLangOpts().getStrictFlexArraysLevel();
 
   const NamedDecl *ND = nullptr;
   if (const auto *DRE = dyn_cast(BaseExpr))
Index: clang/lib/CodeGen/CGExpr.cpp
===
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -878,16 +878,20 @@
 /// Determine whether this expression refers to a flexible array member in a
 /// struct. We disable array bounds checks for such members.
 static bool isFlexibleArrayMemberExpr(const Expr *E,
-  unsigned StrictFlexArraysLevel) {
+  LangOptions::StrictFlexArraysLevelKind
+  StrictFlexArraysLevel) {
   // For compatibility with existing code, we treat arrays of length 0 or
   // 1 as flexible array members.
   // FIXME: This is inconsistent with the warning code in SemaChecking. Unify
   // the two mechanisms.
   const ArrayType *AT = E->getType()->castAsArrayTypeUnsafe();
   if (const auto *CAT = dyn_cast(AT)) {
+using FAMKind = LangOptions::StrictFlexArraysLevelKind;
+
 // FIXME: Sema doesn't treat [1] as a flexible array member if the bound
 // was produced by macro expansion.
-if (StrictFlexArraysLevel >= 2 && CAT->getSize().ugt(0))
+if (StrictFlexArraysLevel == FAMKind::ZeroOrIncomplete &&
+CAT->getSize().ugt(0))
   return false;
 // FIXME: While the default -fstrict-flex-arrays=0 permits Size>1 trailing
 // arrays to be treated as flexible-array-members, we still emit ubsan
@@ -963,7 +967,8 @@
 static llvm::Value *getArrayIndexingBound(CodeGenFunction ,
   const Expr *Base,
   QualType ,
-  unsigned StrictFlexArraysLevel) {
+  LangOptions::StrictFlexArraysLevelKind
+  StrictFlexArraysLevel) {
   // For the vector indexing extension, the bound is the number of elements.
   if (const VectorType *VT = Base->getType()->getAs()) {
 IndexedType = Base->getType();
@@ -1001,7 +1006,8 @@
  "should not be called unless adding bounds checks");
   SanitizerScope SanScope(this);
 
-  const unsigned StrictFlexArraysLevel = 

[PATCH] D134453: Introduce the `AlwaysIncludeTypeForNonTypeTemplateArgument` into printing policy

2022-10-04 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.



>> OK, so it sounds like the printing behavior change (not necessarily with a 
>> policy flag) necessary for diagnostics (make it non-ambiguous/not invalid 
>> code which is what is currently emitted) would be a good bug fix both for 
>> diagnostics and for ast-print? I'm not sure we need anything other than that.
>
> Agreed, fixing up diagnostics and ast print to not print invalid types would 
> be a good fix to have. It doesn't necessitate a new printing policy.
>
>> So that what is currently printing as `t1<{}>` (ambiguous if the NTTP is of 
>> type `auto`, non-ambiguous, but invalid C++ if the NTTP has the specific 
>> type already) prints out as `t1` (correct C++ and disambiguates in the 
>> case of `auto` ambiguity).
>>
>> Or would you want the non-auto case to print in diagnostics as `t1<{}>` 
>> since there's no ambiguity, despite that not being valid C++? And then have 
>> a separate policy for ast-print that still prints it as `t1` so it's 
>> valid code?
>
> Personally (and others are welcome to disagree with me here!), I think we 
> would want to print `t1` even in the `auto` case for diagnostics and 
> ast print.

(sorry to nitpick, but this conversation's been a bit confusing so trying to be 
extra clear) - I guess you meant "even in the *non*-`auto`" case? (the auto 
case I think is clearer that it should always have the type - otherwise it's 
ambiguous) - but yeah, I'm with you - I think the language requires the type 
even in the non-auto case and it seems reasonable to side with that for 
explicitness/clarity even if it could arguably be omitted without loss of 
information, technically.

> For diagnostics, we sometimes print type information reasonably far away from 
> where the declaration of a type is (and use a note to shift the user's gaze 
> to the related type), and so I think having the extra type information is 
> useful for that situation. But even when we print the type information 
> reasonably close to the declaration of the type, it can be helpful because 
> the code context might be easy to lose -- consider using Clang from an IDE 
> where diagnostics are added to a listbox; if you copy the diagnostic from the 
> listbox to paste into an email to a coworker to ask about it, the related 
> code isn't going to come along without extra intervention.

Ok, so sounds like we're on the same page that `t1<{}>` is a diagnostic quality 
bug and we'd love to see a fix for it to include the top level type of the 
NTTP, as in `t1`, and that shouldn't need a new printing policy - because 
we never want to print `t1<{}>` and anywhere we do is a bug to be fixed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134453

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


[PATCH] D135128: [clang][cli] Simplify repetitive macro invocations

2022-10-04 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added reviewers: Bigcheese, thieta.
jansvoboda11 added a subscriber: thieta.
jansvoboda11 added a comment.

Adding @thieta as a reviewer for the MSVC flag change, since it's possible due 
to his D122976  and D130689 
.

Note that this is essentially a re-commit of D95532 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135128

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


[PATCH] D134813: Properly print unnamed TagDecl objects in diagnostics

2022-10-04 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D134813#3834613 , @sammccall wrote:

> In D134813#3834540 , @aaron.ballman 
> wrote:
>
>> In D134813#3834496 , @sammccall 
>> wrote:
>>
>>> Sorry, Monday was a holiday here...
>>
>> No worries, I hope you had a good holiday!
>
> Thanks :-)
>
>>> I don't think unconditionally including the filename in 
>>> printQualifiedName() is great for tools, it can be unreasonably long and is 
>>> generally just noise when shown in the context of that file. I'm surprised 
>>> that USR generation + that clangd test are the only things that broke! Poor 
>>> test coverage in the tools, I think :-(
>>> If the intent is to change this for diagnostics only, can it be behind a 
>>> PrintingPolicy flag?
>>
>> Diagnostics are largely the intent for this and I could probably put a 
>> printing policy flag, but I'm not yet convinced that printing nothing is 
>> actually better for tools in general.
>
> Agreed - I think in my perfect world we'd switch between `(unnammed struct)` 
> and `(unnamed struct at ...)`.
> ... wait, we already have `PrintingPolicy::AnonymousTagLocations`, looks like 
> that does what I want. I've set this for clangd in 
> e212a4f838f17e2d37b1d572d8c1b49c50d7fe17 
> , so 
> this patch should be fine with just updating the string in the test to 
> `(unnamed class)`.

Hehe, I was getting a start on your idea when I discovered that as well. :-D

>> I think it really boils down to whether the name is user-facing or not. 
>> e.g., for USRs, it seems like we don't want to print this sort of thing, 
>> which is fine because users don't stare at those. But tools like clang-query 
>> output various names of things based on user queries, and it seems like it's 
>> less useful for that output to print nothing for the name.
>
> Yeah, I can't see a case where silently printing *nothing* is clearly what we 
> want.
> Even USRs mostly don't do that: they try to print the name, detect nothing 
> got printed, and print something else instead!
>
>> That said, it still sounds like we should have a printing policy for it, but 
>> what should the default be? (I lean towards "print more information instead 
>> of less".)
>
> Given that we have a way to suppress the filename, I don't think we should 
> add another printing policy (until we see a reason to).
> Changing USR generation to not rely on this detail seems easier, I can take a 
> stab at this.

Thank you, I think that's a good idea. I'll rebase on top of those changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134813

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


  1   2   3   >