[PATCH] D135012: [clang][Interp] Implement bitwise and operations

2022-10-01 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135012

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Opcodes.td


Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -109,6 +109,11 @@
   let HasGroup = 1;
 }
 
+class IntegerOpcode : Opcode {
+  let Types = [IntegerTypeClass];
+  let HasGroup = 1;
+}
+
 
//===--===//
 // Jump opcodes
 
//===--===//
@@ -417,10 +422,8 @@
 def Sub : AluOpcode;
 def Add : AluOpcode;
 def Mul : AluOpcode;
-def Rem : Opcode {
-  let Types = [IntegerTypeClass];
-  let HasGroup = 1;
-}
+def Rem : IntegerOpcode;
+def And : IntegerOpcode;
 def Div : Opcode {
   let Types = [NumberTypeClass];
   let HasGroup = 1;
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -158,6 +158,23 @@
   return AddSubMulHelper(S, OpPC, Bits, LHS, RHS);
 }
 
+/// 1) Pops the RHS from the stack.
+/// 2) Pops the LHS from the stack.
+/// 3) Pushes 'LHS & RHS' on the stack
+template ::T>
+bool And(InterpState &S, CodePtr OpPC) {
+  const T &RHS = S.Stk.pop();
+  const T &LHS = S.Stk.pop();
+
+  unsigned Bits = RHS.bitWidth();
+  T Result;
+  if (!T::band(LHS, RHS, Bits, &Result)) {
+S.Stk.push(Result);
+return true;
+  }
+  return false;
+}
+
 /// 1) Pops the RHS from the stack.
 /// 2) Pops the LHS from the stack.
 /// 3) Pushes 'LHS % RHS' on the stack (the remainder of dividing LHS by RHS).
Index: clang/lib/AST/Interp/Integral.h
===
--- clang/lib/AST/Interp/Integral.h
+++ clang/lib/AST/Interp/Integral.h
@@ -212,6 +212,11 @@
 return false;
   }
 
+  static bool band(Integral A, Integral B, unsigned OpBits, Integral *R) {
+*R = Integral(A.V & B.V);
+return false;
+  }
+
   static bool neg(Integral A, Integral *R) {
 *R = -A;
 return false;
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -229,6 +229,11 @@
   if (!this->emitStore(*T, BO))
 return false;
   return DiscardResult ? this->emitPopPtr(BO) : true;
+case BO_And:
+  return Discard(this->emitAnd(*T, BO));
+case BO_Or:
+case BO_LAnd:
+case BO_LOr:
 default:
   return this->bail(BO);
 }


Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -109,6 +109,11 @@
   let HasGroup = 1;
 }
 
+class IntegerOpcode : Opcode {
+  let Types = [IntegerTypeClass];
+  let HasGroup = 1;
+}
+
 //===--===//
 // Jump opcodes
 //===--===//
@@ -417,10 +422,8 @@
 def Sub : AluOpcode;
 def Add : AluOpcode;
 def Mul : AluOpcode;
-def Rem : Opcode {
-  let Types = [IntegerTypeClass];
-  let HasGroup = 1;
-}
+def Rem : IntegerOpcode;
+def And : IntegerOpcode;
 def Div : Opcode {
   let Types = [NumberTypeClass];
   let HasGroup = 1;
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -158,6 +158,23 @@
   return AddSubMulHelper(S, OpPC, Bits, LHS, RHS);
 }
 
+/// 1) Pops the RHS from the stack.
+/// 2) Pops the LHS from the stack.
+/// 3) Pushes 'LHS & RHS' on the stack
+template ::T>
+bool And(InterpState &S, CodePtr OpPC) {
+  const T &RHS = S.Stk.pop();
+  const T &LHS = S.Stk.pop();
+
+  unsigned Bits = RHS.bitWidth();
+  T Result;
+  if (!T::band(LHS, RHS, Bits, &Result)) {
+S.Stk.push(Result);
+return true;
+  }
+  return false;
+}
+
 /// 1) Pops the RHS from the stack.
 /// 2) Pops the LHS from the stack.
 /// 3) Pushes 'LHS % RHS' on the stack (the remainder of dividing LHS by RHS).
Index: clang/lib/AST/Interp/Integral.h
===
--- clang/lib/AST/Interp/Integral.h
+++ clang/lib/AST/Interp/Integral.h
@@ -212,6 +212,11 @@
 return false;
   }
 
+  static bool band(Integral A, Integral B, unsigned OpBits, Integral *R) {
+*R = Integral(A.V & B.V);
+return false;
+  }
+
   static bool neg(I

[PATCH] D135012: [clang][Interp] Implement bitwise and operations

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

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

https://reviews.llvm.org/D135012

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Opcodes.td
  clang/test/AST/Interp/literals.cpp

Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -280,3 +280,10 @@
  // expected-error {{invalid argument type 'float' to unary expression}}
 
 };
+
+namespace band {
+  static_assert((10 & 1) == 0, "");
+  static_assert((10 & 10) == 10, "");
+
+  static_assert((1337 & -1) == 1337, "");
+};
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -109,6 +109,11 @@
   let HasGroup = 1;
 }
 
+class IntegerOpcode : Opcode {
+  let Types = [IntegerTypeClass];
+  let HasGroup = 1;
+}
+
 //===--===//
 // Jump opcodes
 //===--===//
@@ -417,10 +422,8 @@
 def Sub : AluOpcode;
 def Add : AluOpcode;
 def Mul : AluOpcode;
-def Rem : Opcode {
-  let Types = [IntegerTypeClass];
-  let HasGroup = 1;
-}
+def Rem : IntegerOpcode;
+def And : IntegerOpcode;
 def Div : Opcode {
   let Types = [NumberTypeClass];
   let HasGroup = 1;
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -158,6 +158,23 @@
   return AddSubMulHelper(S, OpPC, Bits, LHS, RHS);
 }
 
+/// 1) Pops the RHS from the stack.
+/// 2) Pops the LHS from the stack.
+/// 3) Pushes 'LHS & RHS' on the stack
+template ::T>
+bool And(InterpState &S, CodePtr OpPC) {
+  const T &RHS = S.Stk.pop();
+  const T &LHS = S.Stk.pop();
+
+  unsigned Bits = RHS.bitWidth();
+  T Result;
+  if (!T::band(LHS, RHS, Bits, &Result)) {
+S.Stk.push(Result);
+return true;
+  }
+  return false;
+}
+
 /// 1) Pops the RHS from the stack.
 /// 2) Pops the LHS from the stack.
 /// 3) Pushes 'LHS % RHS' on the stack (the remainder of dividing LHS by RHS).
Index: clang/lib/AST/Interp/Integral.h
===
--- clang/lib/AST/Interp/Integral.h
+++ clang/lib/AST/Interp/Integral.h
@@ -212,6 +212,11 @@
 return false;
   }
 
+  static bool band(Integral A, Integral B, unsigned OpBits, Integral *R) {
+*R = Integral(A.V & B.V);
+return false;
+  }
+
   static bool neg(Integral A, Integral *R) {
 *R = -A;
 return false;
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -229,6 +229,11 @@
   if (!this->emitStore(*T, BO))
 return false;
   return DiscardResult ? this->emitPopPtr(BO) : true;
+case BO_And:
+  return Discard(this->emitAnd(*T, BO));
+case BO_Or:
+case BO_LAnd:
+case BO_LOr:
 default:
   return this->bail(BO);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D135013: [clang][Interp] Array initialization via ImplicitValueInitExpr

2022-10-01 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Unfortunately, I have //no idea// how to test this, the one and only reproducer 
I have so far is:

  #include 
  constexpr std::array IntArray = {};

which results in a `InitListExpr` containing a `ImplicitValueInitExpr` with an 
array type.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135013

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp


Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -732,6 +732,23 @@
 return false;
 }
 return true;
+  } else if (const auto *IVIE = dyn_cast(Initializer)) {
+auto ArrayType = IVIE->getType()->getAsArrayTypeUnsafe();
+const auto *CAT = dyn_cast(ArrayType);
+const size_t NumElems = CAT->getSize().getZExtValue();
+Optional ElemT = classify(CAT->getElementType());
+
+for (size_t I = 0; I != NumElems; ++I) {
+  if (ElemT) {
+if (!this->emitZero(*ElemT, Initializer))
+  return false;
+if (!this->emitInitElem(*ElemT, I, Initializer))
+  return false;
+  } else {
+assert(false && "default initializer for non-primitive type");
+  }
+}
+return true;
   }
 
   assert(false && "Unknown expression for array initialization");


Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -732,6 +732,23 @@
 return false;
 }
 return true;
+  } else if (const auto *IVIE = dyn_cast(Initializer)) {
+auto ArrayType = IVIE->getType()->getAsArrayTypeUnsafe();
+const auto *CAT = dyn_cast(ArrayType);
+const size_t NumElems = CAT->getSize().getZExtValue();
+Optional ElemT = classify(CAT->getElementType());
+
+for (size_t I = 0; I != NumElems; ++I) {
+  if (ElemT) {
+if (!this->emitZero(*ElemT, Initializer))
+  return false;
+if (!this->emitInitElem(*ElemT, I, Initializer))
+  return false;
+  } else {
+assert(false && "default initializer for non-primitive type");
+  }
+}
+return true;
   }
 
   assert(false && "Unknown expression for array initialization");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134791: [clang] Unify Sema and CodeGen implementation of isFlexibleArrayMemberExpr

2022-10-01 Thread serge via Phabricator via cfe-commits
serge-sans-paille updated this revision to Diff 464485.
serge-sans-paille edited the summary of this revision.
serge-sans-paille added a comment.

Add test case for ObjC interface with FAM, as hinted by @msebor


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

https://reviews.llvm.org/D134791

Files:
  clang/include/clang/AST/Expr.h
  clang/lib/AST/Expr.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/SemaObjC/flexible-array-bounds.m

Index: clang/test/SemaObjC/flexible-array-bounds.m
===
--- /dev/null
+++ clang/test/SemaObjC/flexible-array-bounds.m
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// expected-no-diagnostics
+//
+// RUN: %clang_cc1 -fsyntax-only -fstrict-flex-arrays=2 -verify=warn %s
+
+@interface Flexible {
+@public
+  char flexible[];
+}
+@end
+
+@interface Flexible0 {
+@public
+  char flexible[0];
+}
+@end
+
+@interface Flexible1 {
+@public
+  char flexible[1];
+}
+@end
+
+char readit(Flexible *p) { return p->flexible[2]; }
+char readit0(Flexible0 *p) { return p->flexible[2]; }
+char readit1(Flexible1 *p) { return p->flexible[2]; } // warn-warning {{array index 2 is past the end of the array (which contains 1 element)}}
+
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -15898,72 +15898,6 @@
 << TRange << Op->getSourceRange();
 }
 
-/// Check whether this array fits the idiom of a flexible array member,
-/// depending on the value of -fstrict-flex-array.
-///
-/// We avoid emitting out-of-bounds access warnings for such arrays.
-static bool isFlexibleArrayMemberExpr(Sema &S, const Expr *E,
-  const NamedDecl *ND,
-  unsigned StrictFlexArraysLevel) {
-
-  if (!ND)
-return false;
-
-  const ConstantArrayType *ArrayTy =
-  S.Context.getAsConstantArrayType(E->getType());
-  llvm::APInt Size = ArrayTy->getSize();
-
-  if (Size == 0)
-return true;
-
-  // 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))
-return false;
-
-  const FieldDecl *FD = dyn_cast(ND);
-  if (!FD)
-return false;
-
-  // Don't consider sizes resulting from macro expansions or template argument
-  // substitution to form C89 tail-padded arrays.
-
-  TypeSourceInfo *TInfo = FD->getTypeSourceInfo();
-  while (TInfo) {
-TypeLoc TL = TInfo->getTypeLoc();
-// Look through typedefs.
-if (TypedefTypeLoc TTL = TL.getAsAdjusted()) {
-  const TypedefNameDecl *TDL = TTL.getTypedefNameDecl();
-  TInfo = TDL->getTypeSourceInfo();
-  continue;
-}
-if (ConstantArrayTypeLoc CTL = TL.getAs()) {
-  const Expr *SizeExpr = dyn_cast(CTL.getSizeExpr());
-  if (!SizeExpr || SizeExpr->getExprLoc().isMacroID())
-return false;
-}
-break;
-  }
-
-  const RecordDecl *RD = dyn_cast(FD->getDeclContext());
-  if (!RD)
-return false;
-  if (RD->isUnion())
-return false;
-  if (const CXXRecordDecl *CRD = dyn_cast(RD)) {
-if (!CRD->isStandardLayout())
-  return false;
-  }
-
-  // See if this is the last field decl in the record.
-  const Decl *D = FD;
-  while ((D = D->getNextDeclInContext()))
-if (isa(D))
-  return false;
-  return true;
-}
-
 void Sema::CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr,
 const ArraySubscriptExpr *ASE,
 bool AllowOnePastEnd, bool IndexNegated) {
@@ -15983,17 +15917,12 @@
 
   unsigned StrictFlexArraysLevel = getLangOpts().StrictFlexArrays;
 
-  const NamedDecl *ND = nullptr;
-  if (const auto *DRE = dyn_cast(BaseExpr))
-ND = DRE->getDecl();
-  else if (const auto *ME = dyn_cast(BaseExpr))
-ND = ME->getMemberDecl();
-
   const Type *BaseType =
   ArrayTy == nullptr ? nullptr : ArrayTy->getElementType().getTypePtr();
   bool IsUnboundedArray =
-  BaseType == nullptr ||
-  isFlexibleArrayMemberExpr(*this, BaseExpr, ND, StrictFlexArraysLevel);
+  BaseType == nullptr || BaseExpr->isFlexibleArrayMemberLike(
+ Context, StrictFlexArraysLevel,
+ /*IgnoreTemplateOrMacroSubstitution=*/true);
   if (EffectiveType->isDependentType() ||
   (!IsUnboundedArray && BaseType->isDependentType()))
 return;
@@ -16061,15 +15990,14 @@
   << (unsigned)MaxElems.getLimitedValue(~0U)
   << IndexExpr->getSourceRange());
 
-  if (!ND) {
-// Try harder to find a NamedDecl to point at in the note.
-while (const auto *ASE = dyn_cast(BaseExpr))
-  BaseExpr = ASE->getBase()->Ig

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

2022-10-01 Thread Azat Khuzhin via Phabricator via cfe-commits
azat updated this revision to Diff 464486.
azat added a comment.

Rerun CI


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,7 @@
+// 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
@@ -508,6 +508,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,7 @@
+// 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
@@ -508,6 +508,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


[PATCH] D134791: [clang] Unify Sema and CodeGen implementation of isFlexibleArrayMemberExpr

2022-10-01 Thread Thorsten via Phabricator via cfe-commits
tschuett added inline comments.



Comment at: clang/lib/AST/Expr.cpp:225
+
+  } else if (!Context.getAsIncompleteArrayType(getType()))
+return false;

Could this be an early exit?



Comment at: clang/lib/AST/Expr.cpp:267
+
+if (FD->getParent()->isUnion())
+  return true;

Could this be an early exit by moving it up?


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

https://reviews.llvm.org/D134791

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


[PATCH] D133499: [clang]: Add DeclContext::dumpAsDecl().

2022-10-01 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann updated this revision to Diff 464487.
tahonermann retitled this revision from "[clang]: Add DeclContext::dumpDecl() 
in order to conveniently dump an AST from a DeclContext." to "[clang]: Add 
DeclContext::dumpAsDecl().".
tahonermann edited the summary of this revision.
tahonermann added a comment.

Addressed review feedback; when presented with an invalid `DeclContext`, output 
will not be produced that explains why it is invalid.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133499

Files:
  clang/include/clang/AST/ASTDumper.h
  clang/include/clang/AST/DeclBase.h
  clang/lib/AST/ASTDumper.cpp
  clang/lib/AST/DeclBase.cpp

Index: clang/lib/AST/DeclBase.cpp
===
--- clang/lib/AST/DeclBase.cpp
+++ clang/lib/AST/DeclBase.cpp
@@ -152,6 +152,15 @@
   }
 }
 
+bool DeclContext::hasValidDeclKind() const {
+  switch (getDeclKind()) {
+#define DECL(DERIVED, BASE) case Decl::DERIVED: return true;
+#define ABSTRACT_DECL(DECL)
+#include "clang/AST/DeclNodes.inc"
+  }
+  return false;
+}
+
 const char *DeclContext::getDeclKindName() const {
   switch (getDeclKind()) {
 #define DECL(DERIVED, BASE) case Decl::DERIVED: return #DERIVED;
Index: clang/lib/AST/ASTDumper.cpp
===
--- clang/lib/AST/ASTDumper.cpp
+++ clang/lib/AST/ASTDumper.cpp
@@ -19,9 +19,37 @@
 #include "clang/Basic/Module.h"
 #include "clang/Basic/SourceManager.h"
 #include "llvm/Support/raw_ostream.h"
+
 using namespace clang;
 using namespace clang::comments;
 
+void ASTDumper::dumpInvalidDeclContext(const DeclContext *DC) {
+  NodeDumper.AddChild([=] {
+if (!DC) {
+  ColorScope Color(OS, ShowColors, NullColor);
+  OS << "<<>>";
+  return;
+}
+// An invalid DeclContext is one for which a dyn_cast() from a DeclContext
+// pointer to a Decl pointer would fail an assertion or otherwise fall prey
+// to undefined behavior as a result of an invalid associated DeclKind.
+// Such invalidity is not supposed to happen of course, but, when it does,
+// the information provided below is intended to provide some hints about
+// what might have gone awry.
+{
+  ColorScope Color(OS, ShowColors, DeclKindNameColor);
+  OS << "DeclContext";
+}
+NodeDumper.dumpPointer(DC);
+OS << " <";
+{
+  ColorScope Color(OS, ShowColors, DeclNameColor);
+  OS << "unrecognized Decl kind " << (unsigned)DC->getDeclKind();
+}
+OS << ">";
+  });
+}
+
 void ASTDumper::dumpLookups(const DeclContext *DC, bool DumpDecls) {
   NodeDumper.AddChild([=] {
 OS << "StoredDeclsMap ";
@@ -200,6 +228,37 @@
   P.Visit(this);
 }
 
+LLVM_DUMP_METHOD void DeclContext::dumpAsDecl() const {
+  dumpAsDecl(nullptr);
+}
+
+LLVM_DUMP_METHOD void DeclContext::dumpAsDecl(const ASTContext *Ctx) const {
+  // By design, every DeclContext instance is required to be a base class of
+  // some class that derives from Decl. Thus, it should always be possible to
+  // dyn_cast() from a DeclContext pointer to a Decl pointer and, indeed,
+  // the innerworkings of dyn_cast() do assert that to be the case! Alas,
+  // strange and unfortunate things do occasionally occur that lead to folk
+  // like yourself, dear reader, running a debugger and feeling extraordinarily
+  // curious about the origin of a DeclContext instance for which you have
+  // little knowledge. This function has been carefully designed to provide you,
+  // yes you, the answers you desperately seek and deserve with minimal risk
+  // that simply asking the question will upend your debugging experience. The
+  // call to dyn_cast() below is guarded by a validity check that ensures its
+  // success, thus preventing an otherwise potentially volatile (no, not that
+  // kind of volatile) situation.
+  if (hasValidDeclKind()) {
+const Decl *D = dyn_cast(this);
+D->dump();
+  } else {
+// If an ASTContext is not available, a less capable ASTDumper is
+// constructed for which color diagnostics are, regrettably, disabled.
+ASTDumper P = Ctx ? ASTDumper(llvm::errs(), *Ctx,
+  Ctx->getDiagnostics().getShowColors())
+  : ASTDumper(llvm::errs(), /*ShowColors*/ false);
+P.dumpInvalidDeclContext(this);
+  }
+}
+
 LLVM_DUMP_METHOD void DeclContext::dumpLookups() const {
   dumpLookups(llvm::errs());
 }
Index: clang/include/clang/AST/DeclBase.h
===
--- clang/include/clang/AST/DeclBase.h
+++ clang/include/clang/AST/DeclBase.h
@@ -1906,6 +1906,10 @@
 public:
   ~DeclContext();
 
+  // For use when debugging; hasValidDeclKind() will always return true for
+  // a correctly constructed object within its lifetime.
+  bool hasValidDeclKind() const;
+
   Decl::Kind getDeclKind() const {
 return static_cast(DeclContextBits.D

[PATCH] D133499: [clang]: Add DeclContext::dumpAsDecl().

2022-10-01 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann updated this revision to Diff 464488.
tahonermann marked 9 inline comments as done.
tahonermann added a comment.

Addressed a suggested edit I originally failed to notice.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133499

Files:
  clang/include/clang/AST/ASTDumper.h
  clang/include/clang/AST/DeclBase.h
  clang/lib/AST/ASTDumper.cpp
  clang/lib/AST/DeclBase.cpp

Index: clang/lib/AST/DeclBase.cpp
===
--- clang/lib/AST/DeclBase.cpp
+++ clang/lib/AST/DeclBase.cpp
@@ -152,6 +152,15 @@
   }
 }
 
+bool DeclContext::hasValidDeclKind() const {
+  switch (getDeclKind()) {
+#define DECL(DERIVED, BASE) case Decl::DERIVED: return true;
+#define ABSTRACT_DECL(DECL)
+#include "clang/AST/DeclNodes.inc"
+  }
+  return false;
+}
+
 const char *DeclContext::getDeclKindName() const {
   switch (getDeclKind()) {
 #define DECL(DERIVED, BASE) case Decl::DERIVED: return #DERIVED;
Index: clang/lib/AST/ASTDumper.cpp
===
--- clang/lib/AST/ASTDumper.cpp
+++ clang/lib/AST/ASTDumper.cpp
@@ -19,9 +19,37 @@
 #include "clang/Basic/Module.h"
 #include "clang/Basic/SourceManager.h"
 #include "llvm/Support/raw_ostream.h"
+
 using namespace clang;
 using namespace clang::comments;
 
+void ASTDumper::dumpInvalidDeclContext(const DeclContext *DC) {
+  NodeDumper.AddChild([=] {
+if (!DC) {
+  ColorScope Color(OS, ShowColors, NullColor);
+  OS << "<<>>";
+  return;
+}
+// An invalid DeclContext is one for which a dyn_cast() from a DeclContext
+// pointer to a Decl pointer would fail an assertion or otherwise fall prey
+// to undefined behavior as a result of an invalid associated DeclKind.
+// Such invalidity is not supposed to happen of course, but, when it does,
+// the information provided below is intended to provide some hints about
+// what might have gone awry.
+{
+  ColorScope Color(OS, ShowColors, DeclKindNameColor);
+  OS << "DeclContext";
+}
+NodeDumper.dumpPointer(DC);
+OS << " <";
+{
+  ColorScope Color(OS, ShowColors, DeclNameColor);
+  OS << "unrecognized Decl kind " << (unsigned)DC->getDeclKind();
+}
+OS << ">";
+  });
+}
+
 void ASTDumper::dumpLookups(const DeclContext *DC, bool DumpDecls) {
   NodeDumper.AddChild([=] {
 OS << "StoredDeclsMap ";
@@ -200,6 +228,37 @@
   P.Visit(this);
 }
 
+LLVM_DUMP_METHOD void DeclContext::dumpAsDecl() const {
+  dumpAsDecl(nullptr);
+}
+
+LLVM_DUMP_METHOD void DeclContext::dumpAsDecl(const ASTContext *Ctx) const {
+  // By design, every DeclContext instance is required to be a base class of
+  // some class that derives from Decl. Thus, it should always be possible to
+  // dyn_cast() from a DeclContext pointer to a Decl pointer and, indeed,
+  // the innerworkings of dyn_cast() do assert that to be the case! Alas,
+  // strange and unfortunate things do occasionally occur that lead to folk
+  // like yourself, dear reader, running a debugger and feeling extraordinarily
+  // curious about the origin of a DeclContext instance for which you have
+  // little knowledge. This function has been carefully designed to provide you,
+  // yes you, the answers you desperately seek and deserve with minimal risk
+  // that simply asking the question will upend your debugging experience. The
+  // call to dyn_cast() below is guarded by a validity check that ensures its
+  // success, thus preventing an otherwise potentially volatile (no, not that
+  // kind of volatile) situation.
+  if (hasValidDeclKind()) {
+const auto *D = dyn_cast(this);
+D->dump();
+  } else {
+// If an ASTContext is not available, a less capable ASTDumper is
+// constructed for which color diagnostics are, regrettably, disabled.
+ASTDumper P = Ctx ? ASTDumper(llvm::errs(), *Ctx,
+  Ctx->getDiagnostics().getShowColors())
+  : ASTDumper(llvm::errs(), /*ShowColors*/ false);
+P.dumpInvalidDeclContext(this);
+  }
+}
+
 LLVM_DUMP_METHOD void DeclContext::dumpLookups() const {
   dumpLookups(llvm::errs());
 }
Index: clang/include/clang/AST/DeclBase.h
===
--- clang/include/clang/AST/DeclBase.h
+++ clang/include/clang/AST/DeclBase.h
@@ -1906,6 +1906,10 @@
 public:
   ~DeclContext();
 
+  // For use when debugging; hasValidDeclKind() will always return true for
+  // a correctly constructed object within its lifetime.
+  bool hasValidDeclKind() const;
+
   Decl::Kind getDeclKind() const {
 return static_cast(DeclContextBits.DeclKind);
   }
@@ -2527,6 +2531,8 @@
   static bool classof(const Decl *D);
   static bool classof(const DeclContext *D) { return true; }
 
+  void dumpAsDecl() const;
+  void dumpAsDecl(const ASTContext *Ctx) const;
   void dumpDeclContext() const;
   void dumpLo

[PATCH] D133499: [clang]: Add DeclContext::dumpAsDecl().

2022-10-01 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann marked an inline comment as done.
tahonermann added inline comments.



Comment at: clang/lib/AST/ASTDumper.cpp:203
 
+LLVM_DUMP_METHOD void DeclContext::dumpDecl() const {
+  if (const Decl *D = dyn_cast(this))

shafik wrote:
> Interesting ` DeclContext::dumpDeclContext()` is in `DeclPrinter.cpp` I 
> wonder why these were split like this.
It looks like the implementation of ` DeclContext::dumpDeclContext()` requires 
class `DeclPrinter` to be defined. `DeclPrinter` is defined in 
`clang/lib/AST/DeclPrinter.cpp` in an unnamed namespace.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133499

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


[PATCH] D133500: [clang] Correct handling of lambdas in lambda default arguments in dependent contexts.

2022-10-01 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann updated this revision to Diff 464489.
tahonermann added a comment.

Rebased and removed redundant asserts pointed out in code review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133500

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/DeclBase.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/default-arguments.cpp
  clang/test/CodeGenCXX/mangle-lambdas-cxx14.cpp
  clang/test/CodeGenCXX/mangle-lambdas-cxx20.cpp
  clang/test/CodeGenCXX/mangle-lambdas.cpp
  clang/test/SemaCXX/vartemplate-lambda.cpp
  clang/test/SemaTemplate/default-arguments.cpp
  clang/test/SemaTemplate/instantiate-local-class.cpp

Index: clang/test/SemaTemplate/instantiate-local-class.cpp
===
--- clang/test/SemaTemplate/instantiate-local-class.cpp
+++ clang/test/SemaTemplate/instantiate-local-class.cpp
@@ -401,7 +401,8 @@
 namespace PR21332 {
   template void f1() {
 struct S {  // expected-note{{in instantiation of member class 'S' requested here}}
-  void g1(int n = T::error);  // expected-error{{type 'int' cannot be used prior to '::' because it has no members}}
+  void g1(int n = T::error);  // expected-error{{type 'int' cannot be used prior to '::' because it has no members}} \
+  // expected-note {{in instantiation of default function argument expression for 'g1' required here}}
 };
   }
   template void f1();  // expected-note{{in instantiation of function template specialization 'PR21332::f1' requested here}}
@@ -438,7 +439,8 @@
 class S {  // expected-note {{in instantiation of member function 'PR21332::f6()::S::get' requested here}}
   void get() {
 class S2 {  // expected-note {{in instantiation of member class 'S2' requested here}}
-  void g1(int n = T::error);  // expected-error {{type 'int' cannot be used prior to '::' because it has no members}}
+  void g1(int n = T::error);  // expected-error {{type 'int' cannot be used prior to '::' because it has no members}} \
+  // expected-note  {{in instantiation of default function argument expression for 'g1' required here}}
 };
   }
 };
@@ -460,16 +462,18 @@
 
   template  void foo() {
 struct Inner { // expected-note {{in instantiation}}
-  void operator()(T a = "") {} // expected-error {{conversion function from 'const char[1]' to 'rdar23721638::A' invokes a deleted function}}
-  // expected-note@-1 {{passing argument to parameter 'a' here}}
+  void operator()(T a = "") {} // expected-error {{conversion function from 'const char[1]' to 'rdar23721638::A' invokes a deleted function}} \
+   // expected-note  {{in instantiation of default function argument expression for 'operator()' required here}} \
+   // expected-note  {{passing argument to parameter 'a' here}}
 };
-Inner()(); // expected-error {{type 'Inner' does not provide a call operator}}
+Inner()();
   }
-  template void foo(); // expected-note 2 {{in instantiation}}
+  template void foo(); // expected-note {{in instantiation}}
 
   template  void bar() {
-auto lambda = [](T a = "") {}; // expected-error {{conversion function from 'const char[1]' to 'rdar23721638::A' invokes a deleted function}}
-  // expected-note@-1 {{passing argument to parameter 'a' here}}
+auto lambda = [](T a = "") {}; // expected-error {{conversion function from 'const char[1]' to 'rdar23721638::A' invokes a deleted function}} \
+   // expected-note  {{in instantiation of default function argument expression for 'operator()' required here}} \
+   // expected-note  {{passing argument to parameter 'a' here}}
 lambda();
   }
   template void bar(); // expected-note {{in instantiation}}
@@ -490,7 +494,8 @@
   template 
   void f(int x = [](T x = nullptr) -> int { return x; }());
   // expected-error@-1 {{cannot initialize a parameter of type 'int' with an rvalue of type 'std::nullptr_t'}}
-  // expected-note@-2 {{passing argument to parameter 'x' here}}
+  // expected-note@-2  {{in instantiation of default function argument expression for 'operator()' required here}}
+  // expected-note@-3  {{passing argument to parameter 'x' here}}
 
   void g() { f(); }
   // expected-note@-1 {{in instantiation of default function argument expression for 'f' required here}}
Index: clang/test/SemaTemplate/default-arguments.cpp
===
--- clang/test/SemaTemplate/default-arguments.cpp
+++ clang/test/SemaTemplate/default-arguments.cpp
@@ -169,7 +169,8 @@
 
 namespace NondefDecls {
   template void f1() {
-int g1(int defarg = T::error);  // expect

[PATCH] D133500: [clang] Correct handling of lambdas in lambda default arguments in dependent contexts.

2022-10-01 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann marked 5 inline comments as done.
tahonermann added inline comments.



Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:1159
+Expr *UninstExpr = PVD->getUninstantiatedDefaultArg();
+// FIXME: Obtain the source location for the '=' token.
+SourceLocation EqualLoc = UninstExpr->getBeginLoc();

erichkeane wrote:
> Looks like we don't store the equals-token location, so any attempt here 
> probably would have to have ParmVarDecl store this location somewhere?
That's right. This is a pre-existing issue; there are several places that have 
this same (or similar) FIXME comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133500

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


[PATCH] D134384: [clangd] Add support for HeaderInsertion in .clangd config file

2022-10-01 Thread Quentin Chateau via Phabricator via cfe-commits
qchateau updated this revision to Diff 464492.
qchateau added a comment.

- clangd: rename HeaderInsertion and IncludeInsertion, read value from Config


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134384

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/CodeComplete.h
  clang-tools-extra/clangd/Config.h
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/ConfigFragment.h
  clang-tools-extra/clangd/ConfigYAML.cpp
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
  clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp

Index: clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
===
--- clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
+++ clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
@@ -218,6 +218,20 @@
   EXPECT_THAT(Results[0].Completion.AllScopes, testing::Eq(llvm::None));
 }
 
+TEST(ParseYAML, InsertIncludes) {
+  CapturedDiags Diags;
+  Annotations YAML(R"yaml(
+Completion:
+  InsertIncludes: Never
+  )yaml");
+  auto Results =
+  Fragment::parseYAML(YAML.code(), "config.yaml", Diags.callback());
+  ASSERT_THAT(Diags.Diagnostics, IsEmpty());
+  ASSERT_EQ(Results.size(), 1u);
+  EXPECT_THAT(Results[0].Completion.InsertIncludes,
+  llvm::ValueIs(val("Never")));
+}
+
 TEST(ParseYAML, ShowAKA) {
   CapturedDiags Diags;
   Annotations YAML(R"yaml(
Index: clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
===
--- clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
+++ clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
@@ -6,6 +6,7 @@
 //
 //===--===//
 
+#include "CodeComplete.h"
 #include "Config.h"
 #include "ConfigFragment.h"
 #include "ConfigTesting.h"
@@ -537,6 +538,23 @@
   EXPECT_TRUE(Conf.Completion.AllScopes);
 }
 
+TEST_F(ConfigCompileTests, InsertIncludes) {
+  // Defaults to IWYU.
+  EXPECT_TRUE(compileAndApply());
+  EXPECT_EQ(Conf.Completion.InsertIncludes, Config::InsertIncludesPolicy::IWYU);
+
+  Frag = {};
+  Frag.Completion.InsertIncludes = std::string("IWYU");
+  EXPECT_TRUE(compileAndApply());
+  EXPECT_EQ(Conf.Completion.InsertIncludes, Config::InsertIncludesPolicy::IWYU);
+
+  Frag = {};
+  Frag.Completion.InsertIncludes = std::string("Never");
+  EXPECT_TRUE(compileAndApply());
+  EXPECT_EQ(Conf.Completion.InsertIncludes,
+Config::InsertIncludesPolicy::NeverInsert);
+}
+
 TEST_F(ConfigCompileTests, Style) {
   Frag = {};
   Frag.Style.FullyQualifiedNamespaces.push_back(std::string("foo"));
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -11,6 +11,7 @@
 #include "ClangdServer.h"
 #include "CodeComplete.h"
 #include "Compiler.h"
+#include "Config.h"
 #include "Matchers.h"
 #include "Protocol.h"
 #include "Quality.h"
@@ -742,7 +743,7 @@
   EXPECT_TRUE(Results.HasMore);
 }
 
-TEST(CompletionTest, IncludeInsertionPreprocessorIntegrationTests) {
+TEST(CompletionTest, InsertIncludesPolicyPreprocessorIntegrationTests) {
   TestTU TU;
   TU.ExtraArgs.push_back("-I" + testPath("sub"));
   TU.AdditionalFiles["sub/bar.h"] = "";
@@ -757,12 +758,15 @@
   auto Results = completions(TU, Test.point(), {Sym});
   EXPECT_THAT(Results.Completions,
   ElementsAre(AllOf(named("X"), insertInclude("\"bar.h\"";
-  // Can be disabled via option.
-  CodeCompleteOptions NoInsertion;
-  NoInsertion.InsertIncludes = CodeCompleteOptions::NeverInsert;
-  Results = completions(TU, Test.point(), {Sym}, NoInsertion);
-  EXPECT_THAT(Results.Completions,
-  ElementsAre(AllOf(named("X"), Not(insertInclude();
+  // Can be disabled via config.
+  {
+Config Cfg;
+Cfg.Completion.InsertIncludes = Config::InsertIncludesPolicy::NeverInsert;
+WithContextValue WithCfg(Config::Key, std::move(Cfg));
+Results = completions(TU, Test.point(), {Sym});
+EXPECT_THAT(Results.Completions,
+ElementsAre(AllOf(named("X"), Not(insertInclude();
+  }
   // Duplicate based on inclusions in preamble.
   Test = Annotations(R"cpp(
   #include "sub/bar.h"  // not shortest, so should only match resolved.
Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -249,19 +249,19 @@
 init(CodeCompleteOptions().EnableFunctionArgSnippets),
 };
 
-opt HeaderInsertion{
+opt HeaderInsertion{
 "header-inse

[PATCH] D127695: [clang] Implement Template Specialization Resugaring

2022-10-01 Thread David Rector via Phabricator via cfe-commits
davrec added a subscriber: rjmccall.
davrec added a comment.

First thank you for having separated out the public AST changes into other 
patches, it makes these mostly-Sema changes much easier to review.

I don't see any major issues with the code, though this would benefit from a 
close look from more folks with deeper Sema familiarity.  Maybe @rjmccall would 
be willing or could @ someone?

The larger issues:

1. Performance - can we see some numbers?  and
2. There are a lot of FIXMEs introduced - understandable because of the scale, 
but it would be nice to hear you commit to eventually getting to those because 
otherwise they will probably remain indefinitely.   @aaron.ballman should 
probably weigh in/sign off on this one given the number of FIXMEs, which 
probably can't be handled before @mizvekov 's deadline (when is that again?).




Comment at: clang/lib/Sema/SemaCXXScopeSpec.cpp:879-882
+  TypeLocBuilder TLB;
+  DecltypeTypeLoc DecltypeTL = TLB.push(T);
+  DecltypeTL.setDecltypeLoc(DS.getTypeSpecTypeLoc());
+  DecltypeTL.setRParenLoc(DS.getTypeofParensRange().getEnd());

Move back down?



Comment at: clang/lib/Sema/SemaCXXScopeSpec.cpp:993-999
+  // Alias template specializations can produce types which are not valid
+  // nested name specifiers.
+  if (!T->isDependentType() && !T->getAs()) {
+Diag(TemplateNameLoc, diag::err_nested_name_spec_non_tag) << T;
+NoteAllFoundTemplates(Template);
+return true;
+  }

Move back up?



Comment at: clang/lib/Sema/SemaExpr.cpp:3427-3430
 if (unsigned BID = cast(VD)->getBuiltinID()) {
   if (!Context.BuiltinInfo.isDirectlyAddressable(BID)) {
 type = Context.BuiltinFnTy;
 valueKind = VK_PRValue;

Does this need the same changes as Sema::FixOverloadedFunctionReference?  (see 
below)



Comment at: clang/lib/Sema/SemaExpr.cpp:20800
 DRE->copyTemplateArgumentsInto(TemplateArgs);
+// FIXME: resugar
 return BuildDeclRefExpr(

Could this be done same as earlier (lines 19548-19553)?



Comment at: clang/lib/Sema/SemaExprMember.cpp:1862
 
 Qualifiers MemberQuals =
+Context.getCanonicalType(FieldType).getQualifiers();

Rename to FieldQuals



Comment at: clang/lib/Sema/SemaOverload.cpp:15357
 
 // FIXME: Duplicated from BuildDeclarationNameExpr.
+QualType Type;

I think this should have said "Duplicated from 
diagnoseUncapturableValueReferenceOrBinding" - if so do we need the below 
changes over there too?



Comment at: clang/lib/Sema/SemaTemplate.cpp:743
+  }
+  llvm_unreachable("");
+}

Add message



Comment at: clang/lib/Sema/SemaTemplate.cpp:95
 
+TemplateDecl *getTemplateDecl(NamedDecl *D) {
+  switch (D->getKind()) {

static/move to namespace {} below.  Or make it a public method of Decl?  
`Decl::getOriginalDescribedTemplate()` or something like that?  (If you go that 
route then best to fall back to getDescribedTemplate instead of the 
unreachable.)



Comment at: clang/lib/Sema/SemaTemplate.cpp:130
+// Maybe fall back to Decl::getDescribedTemplate.
+D->dumpColor();
+llvm_unreachable("Unhandled decl kind");

Not sure of policy, should this dump should be removed?  Several others below 
too.



Comment at: clang/lib/Sema/SemaTemplate.cpp:161
+public:
+  struct SemanticContextRAII {
+SemanticContextRAII(Resugarer &R, NamedDecl *ND,

Wouldn't hurt to add a brief comment above each RAII class describing its role



Comment at: clang/lib/Sema/SemaTemplate.cpp:257
+  assert(!Args.empty());
+  if (Reverse)
+R->CurTemplateToArgs.try_emplace(Template, Args);

Would be nice to have a comment explaining the effect of Reverse here or above 
addTypeToMap.  (Reverse iteration?)



Comment at: clang/lib/Sema/SemaTemplate.cpp:265
+  struct {
+NamedDecl *ND;
+const TemplateSpecializationType *TS;

Could clarify to CXXRecordDecl



Comment at: clang/lib/Sema/SemaTemplate.cpp:293
+  T->dump();
+  llvm_unreachable("");
+}

Add message



Comment at: clang/lib/Sema/SemaTemplate.cpp:466
+  Result = SemaRef.Context.getElaboratedType(
+  T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), NamedT);
+

Maybe include T->OwnedTagDecl arg for consistency with deduction resugaring



Comment at: clang/lib/Sema/SemaTemplate.cpp:479
+const SubstTemplateTypeParmType *T = TL.getTypePtr();
+Decl *ReplacedDecl = T->getAssociatedDecl();
+Optional PackIndex = T->getPackIndex();

AssociatedDecl



Comment at: clang/l

[PATCH] D134791: [clang] Unify Sema and CodeGen implementation of isFlexibleArrayMemberExpr

2022-10-01 Thread serge via Phabricator via cfe-commits
serge-sans-paille updated this revision to Diff 464494.
serge-sans-paille added a comment.

Add an early exit


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

https://reviews.llvm.org/D134791

Files:
  clang/include/clang/AST/Expr.h
  clang/lib/AST/Expr.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/SemaObjC/flexible-array-bounds.m

Index: clang/test/SemaObjC/flexible-array-bounds.m
===
--- /dev/null
+++ clang/test/SemaObjC/flexible-array-bounds.m
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// expected-no-diagnostics
+//
+// RUN: %clang_cc1 -fsyntax-only -fstrict-flex-arrays=2 -verify=warn %s
+
+@interface Flexible {
+@public
+  char flexible[];
+}
+@end
+
+@interface Flexible0 {
+@public
+  char flexible[0];
+}
+@end
+
+@interface Flexible1 {
+@public
+  char flexible[1];
+}
+@end
+
+char readit(Flexible *p) { return p->flexible[2]; }
+char readit0(Flexible0 *p) { return p->flexible[2]; }
+char readit1(Flexible1 *p) { return p->flexible[2]; } // warn-warning {{array index 2 is past the end of the array (which contains 1 element)}}
+
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -15898,72 +15898,6 @@
 << TRange << Op->getSourceRange();
 }
 
-/// Check whether this array fits the idiom of a flexible array member,
-/// depending on the value of -fstrict-flex-array.
-///
-/// We avoid emitting out-of-bounds access warnings for such arrays.
-static bool isFlexibleArrayMemberExpr(Sema &S, const Expr *E,
-  const NamedDecl *ND,
-  unsigned StrictFlexArraysLevel) {
-
-  if (!ND)
-return false;
-
-  const ConstantArrayType *ArrayTy =
-  S.Context.getAsConstantArrayType(E->getType());
-  llvm::APInt Size = ArrayTy->getSize();
-
-  if (Size == 0)
-return true;
-
-  // 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))
-return false;
-
-  const FieldDecl *FD = dyn_cast(ND);
-  if (!FD)
-return false;
-
-  // Don't consider sizes resulting from macro expansions or template argument
-  // substitution to form C89 tail-padded arrays.
-
-  TypeSourceInfo *TInfo = FD->getTypeSourceInfo();
-  while (TInfo) {
-TypeLoc TL = TInfo->getTypeLoc();
-// Look through typedefs.
-if (TypedefTypeLoc TTL = TL.getAsAdjusted()) {
-  const TypedefNameDecl *TDL = TTL.getTypedefNameDecl();
-  TInfo = TDL->getTypeSourceInfo();
-  continue;
-}
-if (ConstantArrayTypeLoc CTL = TL.getAs()) {
-  const Expr *SizeExpr = dyn_cast(CTL.getSizeExpr());
-  if (!SizeExpr || SizeExpr->getExprLoc().isMacroID())
-return false;
-}
-break;
-  }
-
-  const RecordDecl *RD = dyn_cast(FD->getDeclContext());
-  if (!RD)
-return false;
-  if (RD->isUnion())
-return false;
-  if (const CXXRecordDecl *CRD = dyn_cast(RD)) {
-if (!CRD->isStandardLayout())
-  return false;
-  }
-
-  // See if this is the last field decl in the record.
-  const Decl *D = FD;
-  while ((D = D->getNextDeclInContext()))
-if (isa(D))
-  return false;
-  return true;
-}
-
 void Sema::CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr,
 const ArraySubscriptExpr *ASE,
 bool AllowOnePastEnd, bool IndexNegated) {
@@ -15983,17 +15917,12 @@
 
   unsigned StrictFlexArraysLevel = getLangOpts().StrictFlexArrays;
 
-  const NamedDecl *ND = nullptr;
-  if (const auto *DRE = dyn_cast(BaseExpr))
-ND = DRE->getDecl();
-  else if (const auto *ME = dyn_cast(BaseExpr))
-ND = ME->getMemberDecl();
-
   const Type *BaseType =
   ArrayTy == nullptr ? nullptr : ArrayTy->getElementType().getTypePtr();
   bool IsUnboundedArray =
-  BaseType == nullptr ||
-  isFlexibleArrayMemberExpr(*this, BaseExpr, ND, StrictFlexArraysLevel);
+  BaseType == nullptr || BaseExpr->isFlexibleArrayMemberLike(
+ Context, StrictFlexArraysLevel,
+ /*IgnoreTemplateOrMacroSubstitution=*/true);
   if (EffectiveType->isDependentType() ||
   (!IsUnboundedArray && BaseType->isDependentType()))
 return;
@@ -16061,15 +15990,14 @@
   << (unsigned)MaxElems.getLimitedValue(~0U)
   << IndexExpr->getSourceRange());
 
-  if (!ND) {
-// Try harder to find a NamedDecl to point at in the note.
-while (const auto *ASE = dyn_cast(BaseExpr))
-  BaseExpr = ASE->getBase()->IgnoreParenCasts();
-if (const auto *DRE = dyn_cast(BaseExpr))
-  ND = DRE->getDecl();

[PATCH] D134791: [clang] Unify Sema and CodeGen implementation of isFlexibleArrayMemberExpr

2022-10-01 Thread serge via Phabricator via cfe-commits
serge-sans-paille marked an inline comment as done.
serge-sans-paille added inline comments.



Comment at: clang/lib/AST/Expr.cpp:225
+
+  } else if (!Context.getAsIncompleteArrayType(getType()))
+return false;

tschuett wrote:
> Could this be an early exit?
I don't think so, the first branch is more likely to trigger than this one, so 
keeping it here seems a better choice (and it's conservative wrt. previous 
implementation)


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

https://reviews.llvm.org/D134791

___
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-01 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder 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:
> > 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?


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

https://reviews.llvm.org/D134859

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


[clang] 781b491 - [Clang][AArch64] Support AArch64 target(..) attribute formats.

2022-10-01 Thread David Green via cfe-commits

Author: David Green
Date: 2022-10-01T15:40:59+01:00
New Revision: 781b491bba9d798e53f7784dced3c2be77c81dd4

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

LOG: [Clang][AArch64] Support AArch64 target(..) attribute formats.

This adds support under AArch64 for the target("..") attributes. The
current parsing is very X86-shaped, this patch attempts to bring it line
with the GCC implementation from
https://gcc.gnu.org/onlinedocs/gcc/AArch64-Function-Attributes.html#AArch64-Function-Attributes.

The supported formats are:
- "arch=" strings, that specify the architecture features for a
  function as per the -march=arch+feature option.
- "cpu=" strings, that specify the target-cpu and any implied
  atributes as per the -mcpu=cpu+feature option.
- "tune=" strings, that specify the tune-cpu cpu for a function as
  per -mtune.
- "+", "+no" enables/disables the specific feature, for
  compatibility with GCC target attributes.
- "", "no-" enabled/disables the specific feature, for
  backward compatibility with previous releases.

To do this, the parsing of target attributes has been moved into
TargetInfo to give the target the opportunity to override the existing
parsing. The only non-aarch64 change should be a minor alteration to the
error message, specifying using "CPU" to describe the cpu, not
"architecture", and the DuplicateArch/Tune from ParsedTargetAttr have
been combined into a single option.

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

Added: 
clang/test/CodeGen/aarch64-targetattr.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/Attr.h
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/TargetInfo.h
clang/lib/AST/ASTContext.cpp
clang/lib/Basic/TargetInfo.cpp
clang/lib/Basic/Targets/AArch64.cpp
clang/lib/Basic/Targets/AArch64.h
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/TargetInfo.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/Sema/attr-target.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0237a3c4e1b2..c2fedad18e0c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -450,6 +450,14 @@ DWARF Support in Clang
 
 Arm and AArch64 Support in Clang
 
+
+- The target(..) function attributes for AArch64 now accept:
+
+  * ``"arch="`` strings, that specify the architecture for a function as 
per the ``-march`` option.
+  * ``"cpu="`` strings, that specify the cpu for a function as per the 
``-mcpu`` option.
+  * ``"tune="`` strings, that specify the tune cpu for a function as per 
``-mtune``.
+  * ``"+"``, ``"+no"`` enables/disables the specific 
feature, for compatibility with GCC target attributes.
+  * ``""``, ``"no-"`` enabled/disables the specific feature, 
for backward compatibility with previous releases.
 - ``-march`` values for targeting armv2, armv2A, armv3 and armv3M have been 
removed.
   Their presence gave the impression that Clang can correctly generate code for
   them, which it cannot.

diff  --git a/clang/include/clang/AST/Attr.h b/clang/include/clang/AST/Attr.h
index aff561371fd9..ab64ef39f4b5 100644
--- a/clang/include/clang/AST/Attr.h
+++ b/clang/include/clang/AST/Attr.h
@@ -365,17 +365,13 @@ static_assert(sizeof(ParamIdx) == 
sizeof(ParamIdx::SerialType),
 /// Contains information gathered from parsing the contents of TargetAttr.
 struct ParsedTargetAttr {
   std::vector Features;
-  StringRef Architecture;
+  StringRef CPU;
   StringRef Tune;
   StringRef BranchProtection;
-  bool DuplicateArchitecture = false;
-  bool DuplicateTune = false;
+  StringRef Duplicate;
   bool operator ==(const ParsedTargetAttr &Other) const {
-return DuplicateArchitecture == Other.DuplicateArchitecture &&
-   DuplicateTune == Other.DuplicateTune &&
-   Architecture == Other.Architecture &&
-   Tune == Other.Tune &&
-   BranchProtection == Other.BranchProtection &&
+return Duplicate == Other.Duplicate && CPU == Other.CPU &&
+   Tune == Other.Tune && BranchProtection == Other.BranchProtection &&
Features == Other.Features;
   }
 };

diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 6ace1f081474..1bfe4b6c48a2 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2697,10 +2697,6 @@ def Target : InheritableAttr {
   let Subjects = SubjectList<[Function], ErrorDiag>;
   let Documentation = [TargetDocs];
   let AdditionalMembers = [{
-ParsedTargetAttr parse() const {
-  return parse(getFeaturesStr());
-}
-
 StringRef get

[PATCH] D133848: [Clang][AArch64] Support AArch64 target(..) attribute formats.

2022-10-01 Thread Dave Green 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 rG781b491bba9d: [Clang][AArch64] Support AArch64 target(..) 
attribute formats. (authored by dmgreen).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D133848?vs=460017&id=464501#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133848

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/Attr.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/aarch64-targetattr.c
  clang/test/Sema/attr-target.c

Index: clang/test/Sema/attr-target.c
===
--- clang/test/Sema/attr-target.c
+++ clang/test/Sema/attr-target.c
@@ -1,5 +1,6 @@
-// RUN: %clang_cc1 -triple x86_64-linux-gnu  -fsyntax-only -verify %s
-// RUN: %clang_cc1 -triple aarch64-linux-gnu  -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu  -fsyntax-only -verify -std=c2x %s
+// RUN: %clang_cc1 -triple aarch64-linux-gnu  -fsyntax-only -verify -std=c2x %s
+// RUN: %clang_cc1 -triple arm-linux-gnu  -fsyntax-only -verify -std=c2x %s
 
 #ifdef __x86_64__
 
@@ -10,13 +11,13 @@
 int __attribute__((target("tune=sandybridge"))) baz(void) { return 4; }
 //expected-warning@+1 {{unsupported 'fpmath=' in the 'target' attribute string; 'target' attribute ignored}}
 int __attribute__((target("fpmath=387"))) walrus(void) { return 4; }
-//expected-warning@+1 {{unknown architecture 'hiss' in the 'target' attribute string; 'target' attribute ignored}}
+//expected-warning@+1 {{unknown CPU 'hiss' in the 'target' attribute string; 'target' attribute ignored}}
 int __attribute__((target("avx,sse4.2,arch=hiss"))) meow(void) {  return 4; }
 //expected-warning@+1 {{unsupported 'woof' in the 'target' attribute string; 'target' attribute ignored}}
 int __attribute__((target("woof"))) bark(void) {  return 4; }
 // no warning, same as saying 'nothing'.
 int __attribute__((target("arch="))) turtle(void) { return 4; }
-//expected-warning@+1 {{unknown architecture 'hiss' in the 'target' attribute string; 'target' attribute ignored}}
+//expected-warning@+1 {{unknown CPU 'hiss' in the 'target' attribute string; 'target' attribute ignored}}
 int __attribute__((target("arch=hiss,arch=woof"))) pine_tree(void) { return 4; }
 //expected-warning@+1 {{duplicate 'arch=' in the 'target' attribute string; 'target' attribute ignored}}
 int __attribute__((target("arch=ivybridge,arch=haswell"))) oak_tree(void) { return 4; }
@@ -25,6 +26,36 @@
 //expected-warning@+1 {{unknown tune CPU 'hiss' in the 'target' attribute string; 'target' attribute ignored}}
 int __attribute__((target("tune=hiss,tune=woof"))) apple_tree(void) { return 4; }
 
+#elifdef __aarch64__
+
+int __attribute__((target("sve,arch=armv8-a"))) foo(void) { return 4; }
+//expected-error@+1 {{'target' attribute takes one argument}}
+int __attribute__((target())) bar(void) { return 4; }
+// no warning, tune is supported for aarch64
+int __attribute__((target("tune=cortex-a710"))) baz(void) { return 4; }
+//expected-warning@+1 {{unsupported 'fpmath=' in the 'target' attribute string; 'target' attribute ignored}}
+int __attribute__((target("fpmath=387"))) walrus(void) { return 4; }
+//expected-warning@+1 {{unknown CPU 'hiss' in the 'target' attribute string; 'target' attribute ignored}}
+int __attribute__((target("sve,cpu=hiss"))) meow(void) {  return 4; }
+// FIXME: We currently have no implementation of isValidFeatureName, so this is not noticed as an error.
+int __attribute__((target("woof"))) bark(void) {  return 4; }
+// FIXME: Same
+int __attribute__((target("arch=armv8-a+woof"))) buff(void) {  return 4; }
+// FIXME: Same
+int __attribute__((target("+noway"))) noway(void) {  return 4; }
+// no warning, same as saying 'nothing'.
+int __attribute__((target("arch="))) turtle(void) { return 4; }
+//expected-warning@+1 {{unknown CPU 'hiss' in the 'target' attribute string; 'target' attribute ignored}}
+int __attribute__((target("cpu=hiss,cpu=woof"))) pine_tree(void) { return 4; }
+//expected-warning@+1 {{duplicate 'arch=' in the 'target' attribute string; 'target' attribute ignored}}
+int __attribute__((target("arch=armv8.1-a,arch=armv8-a"))) oak_tree(void) { return 4; }
+//expected-warning@+1 {{duplicate 'cpu=' in the 'target' attribute string; 'target' attribute ignored}}
+int __attribute__((target("cpu=cortex-a710,cpu=neoverse-n2"))) apple_tree

[PATCH] D134589: [C++20][Modules] Elide unused guard variables in Itanium ABI module initializers.

2022-10-01 Thread Iain Sandoe via Phabricator via cfe-commits
iains updated this revision to Diff 464502.
iains edited the summary of this revision.
iains added a comment.

rebased and updated to elide the guard only for the case of no inits _and_ no 
imports.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134589

Files:
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/test/CodeGenCXX/module-initializer-guard-elision.cpp

Index: clang/test/CodeGenCXX/module-initializer-guard-elision.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/module-initializer-guard-elision.cpp
@@ -0,0 +1,69 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 O.cpp \
+// RUN:-emit-module-interface -o O.pcm
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 O.pcm -S -emit-llvm \
+// RUN:  -o - | FileCheck %s --check-prefix=CHECK-O
+
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 P.cpp \
+// RUN:-emit-module-interface -fmodule-file=O.pcm -o P.pcm
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 P.pcm -S -emit-llvm \
+// RUN:  -o - | FileCheck %s --check-prefix=CHECK-P
+
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 Q.cpp \
+// RUN:-emit-module-interface -fmodule-file=O.pcm -o Q.pcm
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 Q.pcm -S -emit-llvm \
+// RUN:  -o - | FileCheck %s --check-prefix=CHECK-Q
+
+// Testing cases where we can elide the module initializer guard variable.
+
+// This module has no global inits and does not import any other module
+//--- O.cpp
+
+export module O;
+
+export int foo ();
+
+// CHECK-O: define void @_ZGIW1O
+// CHECK-O-LABEL: entry
+// CHECK-O-NEXT: ret void
+// CHECK-O-NOT: @_ZGIW1O__in_chrg
+
+// This has no global inits but imports a module, and therefore needs a guard
+// variable.
+//--- P.cpp
+
+export module P;
+
+export import O;
+export int bar ();
+
+// CHECK-P: define void @_ZGIW1P
+// CHECK-P-LABEL: init
+// CHECK-P: store i8 1, ptr @_ZGIW1P__in_chrg
+// CHECK-P: call void @_ZGIW1O()
+// CHECK-P-NOT: call void @__cxx_global_var_init
+
+// This imports a module and has global inits, so needs a guard.
+//--- Q.cpp
+
+export module Q;
+export import O;
+
+export struct Quack {
+  Quack(){};
+};
+
+export Quack Duck;
+
+export int baz ();
+
+// CHECK-Q: define internal void @__cxx_global_var_init
+// CHECK-Q: call {{.*}} @_ZNW1Q5QuackC1Ev
+// CHECK-Q: define void @_ZGIW1Q
+// CHECK-Q: store i8 1, ptr @_ZGIW1Q__in_chrg
+// CHECK-Q: call void @_ZGIW1O()
+// CHECK-Q: call void @__cxx_global_var_init
+
Index: clang/lib/CodeGen/CGDeclCXX.cpp
===
--- clang/lib/CodeGen/CGDeclCXX.cpp
+++ clang/lib/CodeGen/CGDeclCXX.cpp
@@ -640,7 +640,11 @@
 
 /* Build the initializer for a C++20 module:
This is arranged to be run only once regardless of how many times the module
-   might be included transitively.  This arranged by using a control variable.
+   might be included transitively.  This arranged by using a guard variable.
+
+   If there are no initalizers at all (and also no imported modules) we reduce
+   this to an empty function (since importers of the  module will call this
+   unconditionally for the current implementation).
 
First we call any initializers for imported modules.
We then call initializers for the Global Module Fragment (if present)
@@ -652,13 +656,10 @@
   while (!CXXGlobalInits.empty() && !CXXGlobalInits.back())
 CXXGlobalInits.pop_back();
 
-  // We create the function, even if it is empty, since an importer of this
-  // module will refer to it unconditionally (for the current implementation
-  // there is no way for the importer to know that an importee does not need
-  // an initializer to be run).
-
+  // As noted above, we create the function, even if it is empty.
   // Module initializers for imported modules are emitted first.
-  // Collect the modules that we import
+
+  // Collect all the modules that we import
   SmallVector AllImports;
   // Ones that we export
   for (auto I : Primary->Exports)
@@ -685,7 +686,6 @@
 FTy, llvm::Function::ExternalLinkage, FnName.str(), &getModule());
 ModuleInits.push_back(Fn);
   }
-  AllImports.clear();
 
   // Add any initializers with specified priority; this uses the same  approach
   // as EmitCXXGlobalInitFunc().
@@ -703,13 +703,11 @@
   for (; I < PrioE; ++I)
 ModuleInits.push_back(I->second);
 }
-PrioritizedCXXGlobalInits.clear();
   }
 
   // Now append the ones without specified priority.
   for (auto *F : CXXGlobalInits)
 ModuleInits.push_back(F);
-  CXXGlobalInits.clear();
 
   llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy, false);
   const CGFunctionInfo &FI = getTypes().arrangeNullaryFunction();
@@ -719,7 +717,6 @@
   // each init is run just once (even though a module might be imported

[clang] 6dc5f3e - Foward declare ParsedTargetAttr as a struct.

2022-10-01 Thread David Green via cfe-commits

Author: David Green
Date: 2022-10-01T16:14:00+01:00
New Revision: 6dc5f3ec89748f2aa7cface6698bdcd27c8b329e

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

LOG: Foward declare ParsedTargetAttr as a struct.

Added: 


Modified: 
clang/include/clang/Basic/TargetInfo.h

Removed: 




diff  --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 0b42e21a4158..d37d84d121d4 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -49,7 +49,7 @@ class DiagnosticsEngine;
 class LangOptions;
 class CodeGenOptions;
 class MacroBuilder;
-class ParsedTargetAttr;
+struct ParsedTargetAttr;
 
 namespace Builtin { struct Info; }
 



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


[PATCH] D134874: [Concepts] Fix Concepts on generic lambda in a VarTemplateSpecDecl

2022-10-01 Thread Johel Ernesto Guerrero Peña via Phabricator via cfe-commits
JohelEGP added a comment.

I can confirm that, with this patch, Clang successfully compiles my actual code 
base.


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

https://reviews.llvm.org/D134874

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


[clang] d7804e1 - [Clang] Move ParsedTargetAttr to TargetInfo.h

2022-10-01 Thread David Green via cfe-commits

Author: David Green
Date: 2022-10-01T18:26:42+01:00
New Revision: d7804e187a8fc90bde2c12e373aff85a1148b5e7

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

LOG: [Clang] Move ParsedTargetAttr to TargetInfo.h

This moves the struct, as it is now parsed by TargetInfo, so avoiding
some includes of AST in Basic.

Added: 


Modified: 
clang/include/clang/AST/Attr.h
clang/include/clang/Basic/TargetInfo.h
clang/lib/Basic/TargetInfo.cpp
clang/lib/Basic/Targets/AArch64.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Attr.h b/clang/include/clang/AST/Attr.h
index ab64ef39f4b5..793732cd26b0 100644
--- a/clang/include/clang/AST/Attr.h
+++ b/clang/include/clang/AST/Attr.h
@@ -362,20 +362,6 @@ class ParamIdx {
 static_assert(sizeof(ParamIdx) == sizeof(ParamIdx::SerialType),
   "ParamIdx does not fit its serialization type");
 
-/// Contains information gathered from parsing the contents of TargetAttr.
-struct ParsedTargetAttr {
-  std::vector Features;
-  StringRef CPU;
-  StringRef Tune;
-  StringRef BranchProtection;
-  StringRef Duplicate;
-  bool operator ==(const ParsedTargetAttr &Other) const {
-return Duplicate == Other.Duplicate && CPU == Other.CPU &&
-   Tune == Other.Tune && BranchProtection == Other.BranchProtection &&
-   Features == Other.Features;
-  }
-};
-
 #include "clang/AST/Attrs.inc"
 
 inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,

diff  --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index d37d84d121d4..9b9439e2c34f 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -49,7 +49,20 @@ class DiagnosticsEngine;
 class LangOptions;
 class CodeGenOptions;
 class MacroBuilder;
-struct ParsedTargetAttr;
+
+/// Contains information gathered from parsing the contents of TargetAttr.
+struct ParsedTargetAttr {
+  std::vector Features;
+  StringRef CPU;
+  StringRef Tune;
+  StringRef BranchProtection;
+  StringRef Duplicate;
+  bool operator ==(const ParsedTargetAttr &Other) const {
+return Duplicate == Other.Duplicate && CPU == Other.CPU &&
+   Tune == Other.Tune && BranchProtection == Other.BranchProtection &&
+   Features == Other.Features;
+  }
+};
 
 namespace Builtin { struct Info; }
 

diff  --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index a9a97c6e752e..833e37b325e6 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -11,7 +11,6 @@
 
//===--===//
 
 #include "clang/Basic/TargetInfo.h"
-#include "clang/AST/Attr.h"
 #include "clang/Basic/AddressSpaces.h"
 #include "clang/Basic/CharInfo.h"
 #include "clang/Basic/Diagnostic.h"

diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index a18e00f6f4f3..8c0f5dd66cd1 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -11,7 +11,6 @@
 
//===--===//
 
 #include "AArch64.h"
-#include "clang/AST/Attr.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/TargetBuiltins.h"
 #include "clang/Basic/TargetInfo.h"



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


[PATCH] D135018: [compiler-rt] [test] Fix sem_init_glibc.cpp test for glibc 2.36 on i386

2022-10-01 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: eugenis, vitalybuka, rovka.
Herald added subscribers: Enna1, dberris.
Herald added a project: All.
mgorny requested review of this revision.

Update sem_init_glibc.cpp to apply the "newer" GET_SEM_VALUE(v) logic
to i386 if glibc is 2.36 or newer.  With this glibc version, the old
macro returns "84" instead of "42".


https://reviews.llvm.org/D135018

Files:
  compiler-rt/test/sanitizer_common/TestCases/Linux/sem_init_glibc.cpp


Index: compiler-rt/test/sanitizer_common/TestCases/Linux/sem_init_glibc.cpp
===
--- compiler-rt/test/sanitizer_common/TestCases/Linux/sem_init_glibc.cpp
+++ compiler-rt/test/sanitizer_common/TestCases/Linux/sem_init_glibc.cpp
@@ -30,7 +30,8 @@
 // Therefore, it is not enough to rely on the __GLIBC_PREREQ macro - we should
 // instead check the platform as well to make sure we only expect the new
 // behavior on platforms where the older symbols do not exist.
-#if defined(__arm__) && __GLIBC_PREREQ(2, 21)
+#if (defined(__arm__) && __GLIBC_PREREQ(2, 21)) || 
\
+(defined(__i386__) && __GLIBC_PREREQ(2, 36))
 #define GET_SEM_VALUE(V) ((V) >> 1)
 #else
 #define GET_SEM_VALUE(V) (V)


Index: compiler-rt/test/sanitizer_common/TestCases/Linux/sem_init_glibc.cpp
===
--- compiler-rt/test/sanitizer_common/TestCases/Linux/sem_init_glibc.cpp
+++ compiler-rt/test/sanitizer_common/TestCases/Linux/sem_init_glibc.cpp
@@ -30,7 +30,8 @@
 // Therefore, it is not enough to rely on the __GLIBC_PREREQ macro - we should
 // instead check the platform as well to make sure we only expect the new
 // behavior on platforms where the older symbols do not exist.
-#if defined(__arm__) && __GLIBC_PREREQ(2, 21)
+#if (defined(__arm__) && __GLIBC_PREREQ(2, 21)) || \
+(defined(__i386__) && __GLIBC_PREREQ(2, 36))
 #define GET_SEM_VALUE(V) ((V) >> 1)
 #else
 #define GET_SEM_VALUE(V) (V)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134979: [llvm-driver][NFC] Simplify handling of tool symlinks

2022-10-01 Thread Alex Brachet 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 rGaa1c58b9c67a: [llvm-driver][NFC] Simplify handling of tool 
symlinks (authored by abrachet).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134979

Files:
  clang/cmake/modules/AddClang.cmake
  llvm/cmake/modules/AddLLVM.cmake
  llvm/tools/llvm-driver/CMakeLists.txt


Index: llvm/tools/llvm-driver/CMakeLists.txt
===
--- llvm/tools/llvm-driver/CMakeLists.txt
+++ llvm/tools/llvm-driver/CMakeLists.txt
@@ -5,15 +5,17 @@
 
 foreach(tool ${LLVM_DRIVER_TOOLS})
   string(REPLACE "-" "_" tool_entry ${tool})
-  string(REPLACE "llvm-" "" tool ${tool})
-  set(def_decl "${def_decl}LLVM_DRIVER_TOOL(\"${tool}\", ${tool_entry})\n")
+  get_property(tool_aliases GLOBAL PROPERTY LLVM_DRIVER_TOOL_ALIASES_${tool})
+  foreach(alias ${tool_aliases})
+set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_TOOL_SYMLINKS ${alias})
+string(REPLACE "llvm-" "" alias ${alias})
+set(def_decl "${def_decl}LLVM_DRIVER_TOOL(\"${alias}\", ${tool_entry})\n")
+  endforeach()
 endforeach()
 
-get_property(LLVM_EXTRA_DRIVER_ENTRIES GLOBAL PROPERTY 
LLVM_EXTRA_DRIVER_ENTRIES)
-
 file(WRITE
   "${CMAKE_CURRENT_BINARY_DIR}/LLVMDriverTools.def"
-  "${def_decl}${LLVM_EXTRA_DRIVER_ENTRIES}#undef LLVM_DRIVER_TOOL\n")
+  "${def_decl}#undef LLVM_DRIVER_TOOL\n")
 
 target_include_directories(llvm-driver PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
 target_sources(llvm-driver PRIVATE llvm-driver.cpp)
@@ -28,9 +30,8 @@
 endif(APPLE)
 
 macro(generate_driver_tool_targets)
-  get_property(LLVM_DRIVER_TOOLS GLOBAL PROPERTY LLVM_DRIVER_TOOLS)
   get_property(LLVM_DRIVER_TOOL_SYMLINKS GLOBAL PROPERTY 
LLVM_DRIVER_TOOL_SYMLINKS)
-  foreach(name IN LISTS LLVM_DRIVER_TOOLS LLVM_DRIVER_TOOL_SYMLINKS)
+  foreach(name ${LLVM_DRIVER_TOOL_SYMLINKS})
 add_llvm_tool_symlink(${name} llvm-driver ALWAYS_GENERATE)
 # Always generate install targets
 llvm_install_symlink(LLVM ${name} llvm-driver ALWAYS_GENERATE)
Index: llvm/cmake/modules/AddLLVM.cmake
===
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -916,6 +916,7 @@
   set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_OBJLIBS "${obj_name}")
 
   set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_TOOLS ${name})
+  set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_TOOL_ALIASES_${name} 
${name})
   target_link_libraries(${obj_name} ${LLVM_PTHREAD_LIB})
   llvm_config(${obj_name} ${USE_SHARED} ${LLVM_LINK_COMPONENTS} )
 endif()
@@ -2032,7 +2033,6 @@
 function(llvm_install_symlink project name dest)
   get_property(LLVM_DRIVER_TOOLS GLOBAL PROPERTY LLVM_DRIVER_TOOLS)
   if(LLVM_TOOL_LLVM_DRIVER_BUILD AND ${dest} IN_LIST LLVM_DRIVER_TOOLS)
-set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_TOOL_SYMLINKS ${name})
 return()
   endif()
   cmake_parse_arguments(ARG "ALWAYS_GENERATE" "COMPONENT" "" ${ARGN})
@@ -2079,11 +2079,7 @@
   get_property(LLVM_DRIVER_TOOLS GLOBAL PROPERTY LLVM_DRIVER_TOOLS)
 
   if (${target} IN_LIST LLVM_DRIVER_TOOLS)
-string(REPLACE "-" "_" tool_entry ${target})
-string(REPLACE "-" "_" key ${link_name})
-string(REPLACE "llvm-" "" tool_name ${link_name})
-set_property(GLOBAL APPEND_STRING PROPERTY
- LLVM_EXTRA_DRIVER_ENTRIES "LLVM_DRIVER_TOOL(\"${tool_name}\", 
${tool_entry})\n")
+set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_TOOL_ALIASES_${target} 
${link_name})
   endif()
   set(dest_binary "$")
 
Index: clang/cmake/modules/AddClang.cmake
===
--- clang/cmake/modules/AddClang.cmake
+++ clang/cmake/modules/AddClang.cmake
@@ -182,7 +182,7 @@
 macro(add_clang_symlink name dest)
   get_property(LLVM_DRIVER_TOOLS GLOBAL PROPERTY LLVM_DRIVER_TOOLS)
   if(LLVM_TOOL_LLVM_DRIVER_BUILD AND ${dest} IN_LIST LLVM_DRIVER_TOOLS)
-set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_TOOL_SYMLINKS ${name})
+set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_TOOL_ALIASES_${dest} 
${name})
   else()
 llvm_add_tool_symlink(CLANG ${name} ${dest} ALWAYS_GENERATE)
 # Always generate install targets


Index: llvm/tools/llvm-driver/CMakeLists.txt
===
--- llvm/tools/llvm-driver/CMakeLists.txt
+++ llvm/tools/llvm-driver/CMakeLists.txt
@@ -5,15 +5,17 @@
 
 foreach(tool ${LLVM_DRIVER_TOOLS})
   string(REPLACE "-" "_" tool_entry ${tool})
-  string(REPLACE "llvm-" "" tool ${tool})
-  set(def_decl "${def_decl}LLVM_DRIVER_TOOL(\"${tool}\", ${tool_entry})\n")
+  get_property(tool_aliases GLOBAL PROPERTY LLVM_DRIVER_TOOL_ALIASES_${tool})
+  foreach(alias ${tool_al

[clang] aa1c58b - [llvm-driver][NFC] Simplify handling of tool symlinks

2022-10-01 Thread Alex Brachet via cfe-commits

Author: Alex Brachet
Date: 2022-10-01T20:18:49Z
New Revision: aa1c58b9c67a30228a59df18e004d0c6e2c02d3e

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

LOG: [llvm-driver][NFC] Simplify handling of tool symlinks

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

Added: 


Modified: 
clang/cmake/modules/AddClang.cmake
llvm/cmake/modules/AddLLVM.cmake
llvm/tools/llvm-driver/CMakeLists.txt

Removed: 




diff  --git a/clang/cmake/modules/AddClang.cmake 
b/clang/cmake/modules/AddClang.cmake
index d952ff3165587..823b6dc1b9796 100644
--- a/clang/cmake/modules/AddClang.cmake
+++ b/clang/cmake/modules/AddClang.cmake
@@ -182,7 +182,7 @@ endmacro()
 macro(add_clang_symlink name dest)
   get_property(LLVM_DRIVER_TOOLS GLOBAL PROPERTY LLVM_DRIVER_TOOLS)
   if(LLVM_TOOL_LLVM_DRIVER_BUILD AND ${dest} IN_LIST LLVM_DRIVER_TOOLS)
-set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_TOOL_SYMLINKS ${name})
+set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_TOOL_ALIASES_${dest} 
${name})
   else()
 llvm_add_tool_symlink(CLANG ${name} ${dest} ALWAYS_GENERATE)
 # Always generate install targets

diff  --git a/llvm/cmake/modules/AddLLVM.cmake 
b/llvm/cmake/modules/AddLLVM.cmake
index 946d66140fa3e..67806e16814da 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -916,6 +916,7 @@ macro(generate_llvm_objects name)
   set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_OBJLIBS "${obj_name}")
 
   set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_TOOLS ${name})
+  set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_TOOL_ALIASES_${name} 
${name})
   target_link_libraries(${obj_name} ${LLVM_PTHREAD_LIB})
   llvm_config(${obj_name} ${USE_SHARED} ${LLVM_LINK_COMPONENTS} )
 endif()
@@ -2032,7 +2033,6 @@ endfunction()
 function(llvm_install_symlink project name dest)
   get_property(LLVM_DRIVER_TOOLS GLOBAL PROPERTY LLVM_DRIVER_TOOLS)
   if(LLVM_TOOL_LLVM_DRIVER_BUILD AND ${dest} IN_LIST LLVM_DRIVER_TOOLS)
-set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_TOOL_SYMLINKS ${name})
 return()
   endif()
   cmake_parse_arguments(ARG "ALWAYS_GENERATE" "COMPONENT" "" ${ARGN})
@@ -2079,11 +2079,7 @@ function(llvm_add_tool_symlink project link_name target)
   get_property(LLVM_DRIVER_TOOLS GLOBAL PROPERTY LLVM_DRIVER_TOOLS)
 
   if (${target} IN_LIST LLVM_DRIVER_TOOLS)
-string(REPLACE "-" "_" tool_entry ${target})
-string(REPLACE "-" "_" key ${link_name})
-string(REPLACE "llvm-" "" tool_name ${link_name})
-set_property(GLOBAL APPEND_STRING PROPERTY
- LLVM_EXTRA_DRIVER_ENTRIES "LLVM_DRIVER_TOOL(\"${tool_name}\", 
${tool_entry})\n")
+set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_TOOL_ALIASES_${target} 
${link_name})
   endif()
   set(dest_binary "$")
 

diff  --git a/llvm/tools/llvm-driver/CMakeLists.txt 
b/llvm/tools/llvm-driver/CMakeLists.txt
index 148e54b33b0e3..e709cd7fdb56d 100644
--- a/llvm/tools/llvm-driver/CMakeLists.txt
+++ b/llvm/tools/llvm-driver/CMakeLists.txt
@@ -5,15 +5,17 @@ get_property(LLVM_DRIVER_TOOLS GLOBAL PROPERTY 
LLVM_DRIVER_TOOLS)
 
 foreach(tool ${LLVM_DRIVER_TOOLS})
   string(REPLACE "-" "_" tool_entry ${tool})
-  string(REPLACE "llvm-" "" tool ${tool})
-  set(def_decl "${def_decl}LLVM_DRIVER_TOOL(\"${tool}\", ${tool_entry})\n")
+  get_property(tool_aliases GLOBAL PROPERTY LLVM_DRIVER_TOOL_ALIASES_${tool})
+  foreach(alias ${tool_aliases})
+set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_TOOL_SYMLINKS ${alias})
+string(REPLACE "llvm-" "" alias ${alias})
+set(def_decl "${def_decl}LLVM_DRIVER_TOOL(\"${alias}\", ${tool_entry})\n")
+  endforeach()
 endforeach()
 
-get_property(LLVM_EXTRA_DRIVER_ENTRIES GLOBAL PROPERTY 
LLVM_EXTRA_DRIVER_ENTRIES)
-
 file(WRITE
   "${CMAKE_CURRENT_BINARY_DIR}/LLVMDriverTools.def"
-  "${def_decl}${LLVM_EXTRA_DRIVER_ENTRIES}#undef LLVM_DRIVER_TOOL\n")
+  "${def_decl}#undef LLVM_DRIVER_TOOL\n")
 
 target_include_directories(llvm-driver PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
 target_sources(llvm-driver PRIVATE llvm-driver.cpp)
@@ -28,9 +30,8 @@ if(APPLE)
 endif(APPLE)
 
 macro(generate_driver_tool_targets)
-  get_property(LLVM_DRIVER_TOOLS GLOBAL PROPERTY LLVM_DRIVER_TOOLS)
   get_property(LLVM_DRIVER_TOOL_SYMLINKS GLOBAL PROPERTY 
LLVM_DRIVER_TOOL_SYMLINKS)
-  foreach(name IN LISTS LLVM_DRIVER_TOOLS LLVM_DRIVER_TOOL_SYMLINKS)
+  foreach(name ${LLVM_DRIVER_TOOL_SYMLINKS})
 add_llvm_tool_symlink(${name} llvm-driver ALWAYS_GENERATE)
 # Always generate install targets
 llvm_install_symlink(LLVM ${name} llvm-driver ALWAYS_GENERATE)



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


[PATCH] D131310: [llvm-driver] Support single distributions

2022-10-01 Thread Alex Brachet 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 rG3b0df701b0d9: [llvm-driver] Support single distributions 
(authored by abrachet).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131310

Files:
  clang/cmake/modules/AddClang.cmake
  llvm/cmake/modules/AddLLVM.cmake
  llvm/cmake/modules/LLVMDistributionSupport.cmake


Index: llvm/cmake/modules/LLVMDistributionSupport.cmake
===
--- llvm/cmake/modules/LLVMDistributionSupport.cmake
+++ llvm/cmake/modules/LLVMDistributionSupport.cmake
@@ -244,6 +244,8 @@
 set(distributions "")
   endif()
 
+  get_property(LLVM_DRIVER_TOOL_SYMLINKS GLOBAL PROPERTY 
LLVM_DRIVER_TOOL_SYMLINKS)
+
   foreach(distribution ${distributions})
 if(distribution STREQUAL "")
   set(distribution_target distribution)
@@ -268,12 +270,16 @@
 
   if(TARGET install-${target})
 add_dependencies(install-${distribution_target} install-${target})
+  elseif(TARGET install-llvm-driver AND ${target} IN_LIST 
LLVM_DRIVER_TOOL_SYMLINKS)
+add_dependencies(install-${distribution_target} install-llvm-driver)
   else()
 message(SEND_ERROR "Specified distribution component '${target}' 
doesn't have an install target")
   endif()
 
   if(TARGET install-${target}-stripped)
 add_dependencies(install-${distribution_target}-stripped 
install-${target}-stripped)
+  elseif(TARGET install-llvm-driver-stripped AND ${target} IN_LIST 
LLVM_DRIVER_TOOL_SYMLINKS)
+add_dependencies(install-${distribution_target}-stripped 
install-llvm-driver-stripped)
   else()
 message(SEND_ERROR
 "Specified distribution component '${target}' doesn't have an 
install-stripped target."
Index: llvm/cmake/modules/AddLLVM.cmake
===
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -910,7 +910,9 @@
 
 list(APPEND ALL_FILES ${CMAKE_CURRENT_BINARY_DIR}/${name}-driver.cpp)
 
-if (LLVM_TOOL_LLVM_DRIVER_BUILD)
+if (LLVM_TOOL_LLVM_DRIVER_BUILD
+AND (NOT LLVM_DISTRIBUTION_COMPONENTS OR ${name} IN_LIST 
LLVM_DISTRIBUTION_COMPONENTS)
+   )
   set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_COMPONENTS 
${LLVM_LINK_COMPONENTS})
   set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_DEPS ${ARG_DEPENDS} 
${LLVM_COMMON_DEPENDS})
   set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_OBJLIBS "${obj_name}")
@@ -1301,7 +1303,10 @@
   if( NOT LLVM_BUILD_TOOLS )
 set(EXCLUDE_FROM_ALL ON)
   endif()
-  if(ARG_GENERATE_DRIVER AND LLVM_TOOL_LLVM_DRIVER_BUILD)
+  if(ARG_GENERATE_DRIVER
+ AND LLVM_TOOL_LLVM_DRIVER_BUILD
+ AND (NOT LLVM_DISTRIBUTION_COMPONENTS OR ${name} IN_LIST 
LLVM_DISTRIBUTION_COMPONENTS)
+)
 generate_llvm_objects(${name} ${ARGN})
 add_custom_target(${name} DEPENDS llvm-driver)
   else()
@@ -2032,7 +2037,10 @@
 
 function(llvm_install_symlink project name dest)
   get_property(LLVM_DRIVER_TOOLS GLOBAL PROPERTY LLVM_DRIVER_TOOLS)
-  if(LLVM_TOOL_LLVM_DRIVER_BUILD AND ${dest} IN_LIST LLVM_DRIVER_TOOLS)
+  if(LLVM_TOOL_LLVM_DRIVER_BUILD
+ AND ${dest} IN_LIST LLVM_DRIVER_TOOLS
+ AND (NOT LLVM_DISTRIBUTION_COMPONENTS OR ${dest} IN_LIST 
LLVM_DISTRIBUTION_COMPONENTS)
+)
 return()
   endif()
   cmake_parse_arguments(ARG "ALWAYS_GENERATE" "COMPONENT" "" ${ARGN})
Index: clang/cmake/modules/AddClang.cmake
===
--- clang/cmake/modules/AddClang.cmake
+++ clang/cmake/modules/AddClang.cmake
@@ -153,7 +153,10 @@
   if (NOT CLANG_BUILD_TOOLS)
 set(EXCLUDE_FROM_ALL ON)
   endif()
-  if(ARG_GENERATE_DRIVER AND LLVM_TOOL_LLVM_DRIVER_BUILD)
+  if(ARG_GENERATE_DRIVER
+ AND LLVM_TOOL_LLVM_DRIVER_BUILD
+ AND (NOT LLVM_DISTRIBUTION_COMPONENTS OR ${name} IN_LIST 
LLVM_DISTRIBUTION_COMPONENTS)
+)
 set(get_obj_args ${ARGN})
 list(FILTER get_obj_args EXCLUDE REGEX "^SUPPORT_PLUGINS$")
 generate_llvm_objects(${name} ${get_obj_args})
@@ -181,7 +184,10 @@
 
 macro(add_clang_symlink name dest)
   get_property(LLVM_DRIVER_TOOLS GLOBAL PROPERTY LLVM_DRIVER_TOOLS)
-  if(LLVM_TOOL_LLVM_DRIVER_BUILD AND ${dest} IN_LIST LLVM_DRIVER_TOOLS)
+  if(LLVM_TOOL_LLVM_DRIVER_BUILD
+ AND ${dest} IN_LIST LLVM_DRIVER_TOOLS
+ AND (NOT LLVM_DISTRIBUTION_COMPONENTS OR ${dest} IN_LIST 
LLVM_DISTRIBUTION_COMPONENTS)
+)
 set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_TOOL_ALIASES_${dest} 
${name})
   else()
 llvm_add_tool_symlink(CLANG ${name} ${dest} ALWAYS_GENERATE)


Index: llvm/cmake/modules/LLVMDistributionSupport.cmake
===
--- llvm/cmake/modules/LLVMDi

[clang] 3b0df70 - [llvm-driver] Support single distributions

2022-10-01 Thread Alex Brachet via cfe-commits

Author: Alex Brachet
Date: 2022-10-01T20:20:28Z
New Revision: 3b0df701b0d95612e5da3544e2361808b78a6015

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

LOG: [llvm-driver] Support single distributions

`LLVM_DISTRIBUTION_COMPONENTS` now influences the llvm binary in the
normal cmake output directory when it is set. This allows for
distribution targets to only include tools they want in the llvm
binary. It must be done this way because only one target can be
associated with a specific output name.

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

Added: 


Modified: 
clang/cmake/modules/AddClang.cmake
llvm/cmake/modules/AddLLVM.cmake
llvm/cmake/modules/LLVMDistributionSupport.cmake

Removed: 




diff  --git a/clang/cmake/modules/AddClang.cmake 
b/clang/cmake/modules/AddClang.cmake
index 823b6dc1b9796..495ed1c6f18a1 100644
--- a/clang/cmake/modules/AddClang.cmake
+++ b/clang/cmake/modules/AddClang.cmake
@@ -153,7 +153,10 @@ macro(add_clang_tool name)
   if (NOT CLANG_BUILD_TOOLS)
 set(EXCLUDE_FROM_ALL ON)
   endif()
-  if(ARG_GENERATE_DRIVER AND LLVM_TOOL_LLVM_DRIVER_BUILD)
+  if(ARG_GENERATE_DRIVER
+ AND LLVM_TOOL_LLVM_DRIVER_BUILD
+ AND (NOT LLVM_DISTRIBUTION_COMPONENTS OR ${name} IN_LIST 
LLVM_DISTRIBUTION_COMPONENTS)
+)
 set(get_obj_args ${ARGN})
 list(FILTER get_obj_args EXCLUDE REGEX "^SUPPORT_PLUGINS$")
 generate_llvm_objects(${name} ${get_obj_args})
@@ -181,7 +184,10 @@ endmacro()
 
 macro(add_clang_symlink name dest)
   get_property(LLVM_DRIVER_TOOLS GLOBAL PROPERTY LLVM_DRIVER_TOOLS)
-  if(LLVM_TOOL_LLVM_DRIVER_BUILD AND ${dest} IN_LIST LLVM_DRIVER_TOOLS)
+  if(LLVM_TOOL_LLVM_DRIVER_BUILD
+ AND ${dest} IN_LIST LLVM_DRIVER_TOOLS
+ AND (NOT LLVM_DISTRIBUTION_COMPONENTS OR ${dest} IN_LIST 
LLVM_DISTRIBUTION_COMPONENTS)
+)
 set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_TOOL_ALIASES_${dest} 
${name})
   else()
 llvm_add_tool_symlink(CLANG ${name} ${dest} ALWAYS_GENERATE)

diff  --git a/llvm/cmake/modules/AddLLVM.cmake 
b/llvm/cmake/modules/AddLLVM.cmake
index 67806e16814da..152325beca760 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -910,7 +910,9 @@ macro(generate_llvm_objects name)
 
 list(APPEND ALL_FILES ${CMAKE_CURRENT_BINARY_DIR}/${name}-driver.cpp)
 
-if (LLVM_TOOL_LLVM_DRIVER_BUILD)
+if (LLVM_TOOL_LLVM_DRIVER_BUILD
+AND (NOT LLVM_DISTRIBUTION_COMPONENTS OR ${name} IN_LIST 
LLVM_DISTRIBUTION_COMPONENTS)
+   )
   set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_COMPONENTS 
${LLVM_LINK_COMPONENTS})
   set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_DEPS ${ARG_DEPENDS} 
${LLVM_COMMON_DEPENDS})
   set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_OBJLIBS "${obj_name}")
@@ -1301,7 +1303,10 @@ macro(llvm_add_tool project name)
   if( NOT LLVM_BUILD_TOOLS )
 set(EXCLUDE_FROM_ALL ON)
   endif()
-  if(ARG_GENERATE_DRIVER AND LLVM_TOOL_LLVM_DRIVER_BUILD)
+  if(ARG_GENERATE_DRIVER
+ AND LLVM_TOOL_LLVM_DRIVER_BUILD
+ AND (NOT LLVM_DISTRIBUTION_COMPONENTS OR ${name} IN_LIST 
LLVM_DISTRIBUTION_COMPONENTS)
+)
 generate_llvm_objects(${name} ${ARGN})
 add_custom_target(${name} DEPENDS llvm-driver)
   else()
@@ -2032,7 +2037,10 @@ endfunction()
 
 function(llvm_install_symlink project name dest)
   get_property(LLVM_DRIVER_TOOLS GLOBAL PROPERTY LLVM_DRIVER_TOOLS)
-  if(LLVM_TOOL_LLVM_DRIVER_BUILD AND ${dest} IN_LIST LLVM_DRIVER_TOOLS)
+  if(LLVM_TOOL_LLVM_DRIVER_BUILD
+ AND ${dest} IN_LIST LLVM_DRIVER_TOOLS
+ AND (NOT LLVM_DISTRIBUTION_COMPONENTS OR ${dest} IN_LIST 
LLVM_DISTRIBUTION_COMPONENTS)
+)
 return()
   endif()
   cmake_parse_arguments(ARG "ALWAYS_GENERATE" "COMPONENT" "" ${ARGN})

diff  --git a/llvm/cmake/modules/LLVMDistributionSupport.cmake 
b/llvm/cmake/modules/LLVMDistributionSupport.cmake
index 526f36dcda830..0b78f8f9137c5 100644
--- a/llvm/cmake/modules/LLVMDistributionSupport.cmake
+++ b/llvm/cmake/modules/LLVMDistributionSupport.cmake
@@ -244,6 +244,8 @@ function(llvm_distribution_add_targets)
 set(distributions "")
   endif()
 
+  get_property(LLVM_DRIVER_TOOL_SYMLINKS GLOBAL PROPERTY 
LLVM_DRIVER_TOOL_SYMLINKS)
+
   foreach(distribution ${distributions})
 if(distribution STREQUAL "")
   set(distribution_target distribution)
@@ -268,12 +270,16 @@ function(llvm_distribution_add_targets)
 
   if(TARGET install-${target})
 add_dependencies(install-${distribution_target} install-${target})
+  elseif(TARGET install-llvm-driver AND ${target} IN_LIST 
LLVM_DRIVER_TOOL_SYMLINKS)
+add_dependencies(install-${distribution_target} install-llvm-driver)
   else()
 message(SEND_ERROR "Specified distribution component '${target}' 
doesn't have an install targ

[PATCH] D135018: [compiler-rt] [test] Fix sem_init_glibc.cpp test for glibc 2.36 on i386

2022-10-01 Thread Michał Górny via Phabricator via cfe-commits
mgorny added reviewers: MaskRay, thesamesam.
mgorny added subscribers: thesamesam, MaskRay.
mgorny added a comment.
Herald added a subscriber: StephenFan.

@MaskRay, @thesamesam, any chance you could reproduce/test this?


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

https://reviews.llvm.org/D135018

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


[PATCH] D134475: Add C++11 attribute msvc::constexpr

2022-10-01 Thread Richard Dzenis via Phabricator via cfe-commits
RIscRIpt updated this revision to Diff 464522.
RIscRIpt retitled this revision from "[AST] Add C++11 attribute 
msvc::constexpr" to "Add C++11 attribute msvc::constexpr".
RIscRIpt added a comment.

Add more tests, don't alter constexprKind of `[[msvc::constexpr]]` functions - 
instead change implementation of `isConstexpr`

In D134475#3827712 , @aaron.ballman 
wrote:

> ... we're missing some significant test coverage for it. I had some 
> suggestions for specific things we should be thinking about, but another 
> useful test would be to modify an existing constexpr test to add a RUN line 
> enabling ms extensions, and use a macro to switch between `constexpr` and 
> `[[msvc::constexpr]]` based on those RUN lines. Basically, ensure that 
> `[[msvc::constexpr]]` gives the same behavior (both in terms of evaluation 
> and in terms of semantic checking) as `constexpr`. WDYT?

That's a good idea. Based on my experiments with MSVC, I am more convinced that 
`constexpr` and `[[msvc::constexpr]]` are synonyms (with some extra 
undocumented (yet?) features by MSFT). I added more tests as per your 
suggestion.
Regarding existing tests, I was able to find only 
`clang/test/AST/Interp/functions.cpp` which uses `constexpr` only with 
functions (otherwise `-Dconstexpr=[[msvc::constexpr]]` would break code in case 
there are `constexpr` variables) - I added `RUN` lines there.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134475

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/Decl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/AST/Interp/functions.cpp
  clang/test/AST/msvc-attrs-invalid.cpp
  clang/test/AST/msvc-attrs.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test

Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -83,6 +83,7 @@
 // CHECK-NEXT: LoaderUninitialized (SubjectMatchRule_variable_is_global)
 // CHECK-NEXT: Lockable (SubjectMatchRule_record)
 // CHECK-NEXT: MIGServerRoutine (SubjectMatchRule_function, SubjectMatchRule_objc_method, SubjectMatchRule_block)
+// CHECK-NEXT: MSConstexpr (SubjectMatchRule_function)
 // CHECK-NEXT: MSStruct (SubjectMatchRule_record)
 // CHECK-NEXT: MaybeUndef (SubjectMatchRule_variable_is_parameter)
 // CHECK-NEXT: MicroMips (SubjectMatchRule_function)
Index: clang/test/AST/msvc-attrs.cpp
===
--- /dev/null
+++ clang/test/AST/msvc-attrs.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -fms-extensions -std=c++20 -ast-dump %s | FileCheck %s
+// RUN: not %clang_cc1 -Werror=ignored-attributes -ast-dump %s 2> %t.stderr.txt
+// RUN: FileCheck -check-prefix CHECK-DIAG-NO-MSX %s < %t.stderr.txt
+
+// CHECK: msvc-attrs.cpp:[[@LINE+3]]:21, col:32> col:26 f0 'void ()'
+// CHECK: MSConstexprAttr 0x{{[0-9a-f]+}} 
+// CHECK-DIAG-NO-MSX: msvc-attrs.cpp:[[@LINE+1]]:3: error: 'constexpr' attribute ignored
+[[msvc::constexpr]] void f0() {}
+
+struct s0 {
+  // CHECK: CXXConstructorDecl 0x{{[0-9a-f]+}}  col:23 s0 'void ()' implicit-inline
+  // CHECK: MSConstexprAttr 0x{{[0-9a-f]+}} 
+  [[msvc::constexpr]] s0() {}
+
+  // CHECK: CXXDestructorDecl 0x{{[0-9a-f]+}}  col:23 ~s0 'void () noexcept' implicit-inline
+  // CHECK: MSConstexprAttr 0x{{[0-9a-f]+}} 
+  [[msvc::constexpr]] ~s0() {}
+
+  // CHECK: CXXMethodDecl 0x{{[0-9a-f]+}}  col:36 used f1 'void ()' virtual implicit-inline
+  // CHECK: MSConstexprAttr 0x{{[0-9a-f]+}} 
+  [[msvc::constexpr]] virtual void f1() {}
+};
+
+// Check 'constexpr' and '[[msvc::constexpr]]' functions can call each other
+void f2();
+constexpr void f3();
+
+[[msvc::constexpr]] void f2() { f3(); }
+constexpr void f3() { f2(); }
+
+[[msvc::constexpr]] void f4();
+constexpr void f5();
+
+void f4() { f5(); }
+constexpr void f5() { f4(); }
Index: clang/test/AST/msvc-attrs-invalid.cpp
===
--- /dev/null
+++ clang/test/AST/msvc-attrs-invalid.cpp
@@ -0,0 +1,14 @@
+// RUN: not %clang_cc1 -fms-extensions -std=c++20 -ast-dump %s 2> %t.stderr.txt
+// RUN: FileCheck %s < %t.stderr.txt
+
+void runtime() {}
+
+// CHECK: msvc-attrs-invalid.cpp:[[@LINE+1]]:26: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
+[[msvc::constexpr]] void f0() { runtime(); }
+
+// CHECK: msvc-attrs-invalid.cpp:[[@LINE+1]]:3: error: {{\[\[}}msvc::constexpr{{]]}} cannot be applied to a 'constexpr' or 'consteval' function 'f1'
+[[msvc::constexpr]] constexpr void f1() {}
+
+// CHECK: msvc-attrs-invalid.cpp:[[@LINE+1]]:3: error: {{\[\[}}msvc::constexpr{{]]}

[PATCH] D134475: Add C++11 attribute msvc::constexpr

2022-10-01 Thread Richard Dzenis via Phabricator via cfe-commits
RIscRIpt planned changes to this revision.
RIscRIpt added inline comments.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:4995-4997
+  case ParsedAttr::AT_MSConstexpr:
+D->addAttr(::new (S.Context) MSConstexprAttr(S.Context, AL));
+return;

aaron.ballman wrote:
> This looks incorrect to me -- constexpr isn't a calling convention, so I 
> think this code should be removed.
Oops, removed.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:7057-7058
+static void handleMSConstexprAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
+  if (auto *FD = dyn_cast(D))
+FD->setConstexprKind(ConstexprSpecKind::Constexpr);
+  D->addAttr(::new (S.Context) MSConstexprAttr(S.Context, AL));

aaron.ballman wrote:
> We can use `cast` here because we know the declaration must have already been 
> determined to be a function (from the subjects list in Attr.td).
> 
> That said, I think there's more semantic checking we want to do here. For 
> example, can you use this attribute on a virtual function? What about a 
> function already marked `constexpr`? Even more scary, what about a function 
> marked `consteval`?
> 
> Also, I presume a `constexpr` function should be able to call an 
> `[[msvc::constexpr]]` function and vice versa?
> We can use cast here because we know the declaration must have already been 
> determined to be a function (from the subjects list in Attr.td).

Indeed. Changed.

> That said, I think there's more semantic checking we want to do here. For 
> example, can you use this attribute on a virtual function? What about a 
> function already marked constexpr? Even more scary, what about a function 
> marked consteval?

Good questions. By running `strings c1xx.dll` I was able to find only the 
following diagnostic messages regarding `[[msvc::constexpr]]`:
```
[[msvc::constexpr]] may only be applied to statements and functions"
[[msvc::constexpr]] cannot be applied to a 'constexpr' or 'consteval' function"
```

I've made a similar check here and added relevant test cases in 
`msvc-attrs-invalid.cpp`. But in order to make it possible, I had to change 
`FunctionDecl::isConstexpr()`, please check new changes.

//TODO//: I think, I'll need to read more about `constexpr` for functions in 
standard (and LLVM code), to add relevant restrictions here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134475

___
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-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/test/Driver/debug-options-aranges.c:1
+// REQUIRES: lld
+

Remove `// REQUIRES: lld`



Comment at: clang/test/Driver/debug-options-aranges.c:3
+
+// Check that the linker plugin will get -generate-arange-section
+//

Optional: End full sentences with a period. Some directories use the convention 
that non-RUN-non-CHECK lines use `///` as the comment marker. The idea is to 
make comments stand out and foster possible future lit/FileCheck improvement 
that check unused prefixes.



Comment at: clang/test/Driver/debug-options-aranges.c:4
+// 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

This otherwise empty line is not useful.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133092

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


[PATCH] D134853: [clang-format] Correctly annotate UDLs as OverloadedOperator

2022-10-01 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

In D134853#3822842 , @rymiel wrote:

> Unless any reviewers have any other opinions, I would leave fixing those out 
> of this patch and leave the tests "incomplete" for now?

+1.

> Also, UDLs that don't start with an underscore aren't considered a single 
> "string_literal" token, instead becoming a string literal `""` and an 
> identifier following it (where as those with an underscore become one token, 
> such as `""_a`). I'm unsure if that's the expected case and if both tokens 
> should just be considered part of the operator

The operator `""` and the identifier that follows should be two separate tokens 
regardless if the identifier starts with an underscore.




Comment at: clang/lib/Format/TokenAnnotator.cpp:1185
+TT_BinaryOperator, TT_UnaryOperator, tok::comma, tok::star,
+tok::arrow, tok::amp, tok::ampamp, tok::string_literal)) {
   CurrentToken->Previous->setType(TT_OverloadedOperator);

We should check for `""`, not just any `string_literal`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134853

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


[clang] 9d0d404 - [clang] Use std::enable_if_t (NFC)

2022-10-01 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-10-01T17:24:54-07:00
New Revision: 9d0d4046c05f230183d31130425b5294b768200b

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

LOG: [clang] Use std::enable_if_t (NFC)

Added: 


Modified: 
clang/include/clang/ASTMatchers/ASTMatchersInternal.h
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
clang/include/clang/Basic/Diagnostic.h
clang/include/clang/Basic/PartialDiagnostic.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/Decl.cpp

Removed: 




diff  --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h 
b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
index 5785a72559987..12bc593b785ae 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -1966,8 +1966,8 @@ template  struct 
GetBodyMatcher {
 };
 
 template 
-struct GetBodyMatcher::value>::type> 
{
+struct GetBodyMatcher<
+Ty, std::enable_if_t::value>> {
   static const Stmt *get(const Ty &Node) {
 return Node.doesThisDeclarationHaveABody() ? Node.getBody() : nullptr;
   }

diff  --git 
a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
index e7533794de48b..f73ea7985d79e 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
@@ -71,7 +71,7 @@ class DataflowAnalysisContext {
   ///
   ///  `Loc` must not be null.
   template 
-  typename std::enable_if::value, T 
&>::type
+  std::enable_if_t::value, T &>
   takeOwnership(std::unique_ptr Loc) {
 assert(Loc != nullptr);
 Locs.push_back(std::move(Loc));
@@ -84,7 +84,7 @@ class DataflowAnalysisContext {
   ///
   ///  `Val` must not be null.
   template 
-  typename std::enable_if::value, T &>::type
+  std::enable_if_t::value, T &>
   takeOwnership(std::unique_ptr Val) {
 assert(Val != nullptr);
 Vals.push_back(std::move(Val));

diff  --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
index 541b9132ebf50..d093967e193a1 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -260,7 +260,7 @@ class Environment {
   ///
   ///  `Loc` must not be null.
   template 
-  typename std::enable_if::value, T 
&>::type
+  std::enable_if_t::value, T &>
   takeOwnership(std::unique_ptr Loc) {
 return DACtx->takeOwnership(std::move(Loc));
   }
@@ -272,7 +272,7 @@ class Environment {
   ///
   ///  `Val` must not be null.
   template 
-  typename std::enable_if::value, T &>::type
+  std::enable_if_t::value, T &>
   takeOwnership(std::unique_ptr Val) {
 return DACtx->takeOwnership(std::move(Val));
   }

diff  --git a/clang/include/clang/Basic/Diagnostic.h 
b/clang/include/clang/Basic/Diagnostic.h
index 09857da61d326..120e3f578568d 100644
--- a/clang/include/clang/Basic/Diagnostic.h
+++ b/clang/include/clang/Basic/Diagnostic.h
@@ -1346,8 +1346,8 @@ class DiagnosticBuilder : public StreamingDiagnostic {
   // It is necessary to limit this to rvalue reference to avoid calling this
   // function with a bitfield lvalue argument since non-const reference to
   // bitfield is not allowed.
-  template ::value>::type>
+  template ::value>>
   const DiagnosticBuilder &operator<<(T &&V) const {
 assert(isActive() && "Clients must not add to cleared diagnostic!");
 const StreamingDiagnostic &DB = *this;

diff  --git a/clang/include/clang/Basic/PartialDiagnostic.h 
b/clang/include/clang/Basic/PartialDiagnostic.h
index ddee6821e2e13..507d789c54ff9 100644
--- a/clang/include/clang/Basic/PartialDiagnostic.h
+++ b/clang/include/clang/Basic/PartialDiagnostic.h
@@ -64,8 +64,8 @@ class PartialDiagnostic : public StreamingDiagnostic {
   // It is necessary to limit this to rvalue reference to avoid calling this
   // function with a bitfield lvalue argument since non-const reference to
   // bitfield is not allowed.
-  template ::value>::type>
+  template ::value>>
   const PartialDiagnostic &operator<<(T &&V) const {
 const StreamingDiagnostic &DB = *this;
 DB << std::move(V);

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 52b554b9f8b10..2ae74896f6201 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1719,8 +1719,8 @@ class Sema final {
 // It is necessary to limit this to rvalue reference to avoid calling this
 // function with a bitfield lvalue argument since non-const reference to
 /

[PATCH] D125142: [clang][auto-init] Deprecate -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang

2022-10-01 Thread Kees Cook via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
kees marked an inline comment as done.
Closed by commit rGaef03c9b3bed: [clang][auto-init] Deprecate 
-enable-trivial-auto-var-init-zero-knowing-it-will… (authored by kees).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125142

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/cl-options.c
  clang/test/Driver/clang_f_opts.c

Index: clang/test/Driver/clang_f_opts.c
===
--- clang/test/Driver/clang_f_opts.c
+++ clang/test/Driver/clang_f_opts.c
@@ -569,18 +569,19 @@
 
 // RUN: %clang -### -S -ftrivial-auto-var-init=uninitialized %s 2>&1 | FileCheck -check-prefix=CHECK-TRIVIAL-UNINIT %s
 // RUN: %clang -### -S -ftrivial-auto-var-init=pattern %s 2>&1 | FileCheck -check-prefix=CHECK-TRIVIAL-PATTERN %s
-// RUN: %clang -### -S -ftrivial-auto-var-init=zero -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang %s 2>&1 | FileCheck -check-prefix=CHECK-TRIVIAL-ZERO-GOOD %s
-// RUN: %clang -### -S -ftrivial-auto-var-init=zero %s 2>&1 | FileCheck -check-prefix=CHECK-TRIVIAL-ZERO-BAD %s
+// RUN: %clang -### -S -ftrivial-auto-var-init=zero %s 2>&1 | FileCheck -check-prefix=CHECK-TRIVIAL-ZERO %s
+// RUN: %clang -### -S -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang \
+// RUN:   -ftrivial-auto-var-init=zero %s 2>&1 | FileCheck -check-prefix=CHECK-TRIVIAL-ZERO-ENABLE-DEPRECATED %s
 // CHECK-TRIVIAL-UNINIT-NOT: hasn't been enabled
 // CHECK-TRIVIAL-PATTERN-NOT: hasn't been enabled
-// CHECK-TRIVIAL-ZERO-GOOD-NOT: hasn't been enabled
-// CHECK-TRIVIAL-ZERO-BAD: hasn't been enabled
+// CHECK-TRIVIAL-ZERO-NOT: hasn't been enabled
+// CHECK-TRIVIAL-ZERO-ENABLE-DEPRECATED: has been deprecated
 
 // RUN: %clang -### -S -ftrivial-auto-var-init=pattern -ftrivial-auto-var-init-stop-after=1 %s 2>&1 | FileCheck -check-prefix=CHECK-TRIVIAL-PATTERN-STOP-AFTER %s
-// RUN: %clang -### -S -ftrivial-auto-var-init=zero -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang -ftrivial-auto-var-init-stop-after=1 %s 2>&1 | FileCheck -check-prefix=CHECK-TRIVIAL-ZERO-STOP-AFTER %s
+// RUN: %clang -### -S -ftrivial-auto-var-init=zero -ftrivial-auto-var-init-stop-after=1 %s 2>&1 | FileCheck -check-prefix=CHECK-TRIVIAL-ZERO-STOP-AFTER %s
 // RUN: %clang -### -S -ftrivial-auto-var-init-stop-after=0 %s 2>&1 | FileCheck -check-prefix=CHECK-TRIVIAL-STOP-AFTER-MISSING-DEPENDENCY %s
 // RUN: %clang -### -S -ftrivial-auto-var-init=pattern -ftrivial-auto-var-init-stop-after=0 %s 2>&1 | FileCheck -check-prefix=CHECK-TRIVIAL-PATTERN-STOP-AFTER-INVALID-VALUE %s
-// RUN: %clang -### -S -ftrivial-auto-var-init=zero -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang -ftrivial-auto-var-init-stop-after=0 %s 2>&1 | FileCheck -check-prefix=CHECK-TRIVIAL-ZERO-STOP-AFTER-INVALID-VALUE %s
+// RUN: %clang -### -S -ftrivial-auto-var-init=zero -ftrivial-auto-var-init-stop-after=0 %s 2>&1 | FileCheck -check-prefix=CHECK-TRIVIAL-ZERO-STOP-AFTER-INVALID-VALUE %s
 // CHECK-TRIVIAL-PATTERN-STOP-AFTER-NOT: is used without '-ftrivial-auto-var-init'
 // CHECK-TRIVIAL-PATTERN-STOP-AFTER-NOT: only accepts positive integers
 // CHECK-TRIVIAL-ZERO-STOP-AFTER-NOT: is used without '-ftrivial-auto-var-init'
Index: clang/test/Driver/cl-options.c
===
--- clang/test/Driver/cl-options.c
+++ clang/test/Driver/cl-options.c
@@ -719,7 +719,6 @@
 // RUN: -fimplicit-modules \
 // RUN: -fno-implicit-modules \
 // RUN: -ftrivial-auto-var-init=zero \
-// RUN: -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang \
 // RUN: --version \
 // RUN: -Werror /Zs -- %s 2>&1
 
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3458,8 +3458,6 @@
 }
 
   if (!TrivialAutoVarInit.empty()) {
-if (TrivialAutoVarInit == "zero" && !Args.hasArg(options::OPT_enable_trivial_var_init_zero))
-  D.Diag(diag::err_drv_trivial_auto_var_init_zero_disabled);
 CmdArgs.push_back(
 Args.MakeArgString("-ftrivial-auto-var-init=" + TrivialAutoVarInit));
   }
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -247,6 +247,12 @@
 def mmpx : Flag<["-"], "mmpx">, Group;
 def mno_mpx : Flag<["-"], "mno-mpx">, Group;
 
+// Retired with clang-16.0, to provide a deprecation period; it should
+// be removed in Clang 18 or later.
+def enable_trivial_var_init_zero : Flag<["-"], "enable-t

[clang] aef03c9 - [clang][auto-init] Deprecate -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang

2022-10-01 Thread Kees Cook via cfe-commits

Author: Kees Cook
Date: 2022-10-01T18:45:45-07:00
New Revision: aef03c9b3bed5cef5a1940774b80128aefcb4095

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

LOG: [clang][auto-init] Deprecate 
-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang

GCC 12 has been released and contains unconditional support for
-ftrivial-auto-var-init=zero:
https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-ftrivial-auto-var-init

Maintain compatibility with GCC, and remove the -enable flag for "zero"
mode. The flag is left to generate an "unused" warning, though, to not
break all the existing users. The flag will be fully removed in Clang 17.

Link: https://github.com/llvm/llvm-project/issues/44842

Reviewed By: nickdesaulniers, MaskRay, srhines, xbolva00

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/cl-options.c
clang/test/Driver/clang_f_opts.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c2fedad18e0c2..2320f4a7a4fac 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -277,6 +277,10 @@ New Compiler Flags
 
 Deprecated Compiler Flags
 -
+- ``-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang``
+  has been deprecated. The flag will be removed in Clang 18.
+  ``-ftrivial-auto-var-init=zero`` is now available unconditionally, to be
+  compatible with GCC.
 
 Modified Compiler Flags
 ---

diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 56d8d508cdbc8..282ecdbed4cec 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -588,11 +588,6 @@ def warn_drv_darwin_sdk_invalid_settings : Warning<
   "SDK settings were ignored as 'SDKSettings.json' could not be parsed">,
   InGroup>;
 
-def err_drv_trivial_auto_var_init_zero_disabled : Error<
-  "'-ftrivial-auto-var-init=zero' hasn't been enabled; enable it at your own "
-  "peril for benchmarking purpose only with "
-  
"'-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang'">;
-
 def err_drv_trivial_auto_var_init_stop_after_missing_dependency : Error<
   "'-ftrivial-auto-var-init-stop-after=*' is used without "
   "'-ftrivial-auto-var-init=zero' or '-ftrivial-auto-var-init=pattern'">;

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 4e85242f136b1..f7744a109f9a0 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -247,6 +247,12 @@ def : Flag<["-"], "fno-slp-vectorize-aggressive">, 
Group, Group;
 def mno_mpx : Flag<["-"], "mno-mpx">, 
Group;
 
+// Retired with clang-16.0, to provide a deprecation period; it should
+// be removed in Clang 18 or later.
+def enable_trivial_var_init_zero : Flag<["-"], 
"enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang">,
+  Flags<[CC1Option, CoreOption, NoArgumentUnused]>,
+  Group;
+
 // Group that ignores all gcc optimizations that won't be implemented
 def clang_ignored_gcc_optimization_f_Group : OptionGroup<
   "">, Group, 
Flags<[Ignored]>;
@@ -2791,9 +2797,6 @@ def ftrivial_auto_var_init : Joined<["-"], 
"ftrivial-auto-var-init=">, Group,
   NormalizedValues<["Uninitialized", "Zero", "Pattern"]>,
   MarshallingInfoEnum, "Uninitialized">;
-def enable_trivial_var_init_zero : Flag<["-"], 
"enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang">,
-  Flags<[CC1Option, CoreOption, NoArgumentUnused]>,
-  HelpText<"Trivial automatic variable initialization to zero is only here for 
benchmarks, it'll eventually be removed, and I'm OK with that because I'm only 
using it to benchmark">;
 def ftrivial_auto_var_init_stop_after : Joined<["-"], 
"ftrivial-auto-var-init-stop-after=">, Group,
   Flags<[CC1Option, CoreOption]>, HelpText<"Stop initializing trivial 
automatic stack variables after the specified number of instances">,
   MarshallingInfoInt>;

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index dd5596bc942e8..e5fce35793598 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3458,8 +3458,6 @@ static void RenderTrivialAutoVarInitOptions(const Driver 
&D,
 }
 
   if (!TrivialAutoVarInit.empty()) {
-if (TrivialAutoVarInit == "zero" && 
!Args.hasArg(options::OPT_enable_trivial_var_init_zero))
-  D.Diag(diag::err_drv_trivial_auto_var_init_zero_