[clang] [clang][ExprConst] allow single element access of vector object to be constant expression (PR #72607)

2024-01-26 Thread Yuanfang Chen via cfe-commits


@@ -144,6 +144,9 @@ sections with improvements to Clang's support for those 
languages.
 
 C++ Language Changes
 
+- Allow single element access of vector object to be constant expression.
+  Supports the `V.xyzw` syntax and other tidbits as seen in OpenCL.

yuanfang-chen wrote:

done

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


[clang] [clang][ExprConst] allow single element access of vector object to be constant expression (PR #72607)

2024-01-14 Thread Yuanfang Chen via cfe-commits

yuanfang-chen wrote:

ping?

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


[clang] [clang][ExprConst] allow single element access of vector object to be constant expression (PR #72607)

2024-01-02 Thread Yuanfang Chen via cfe-commits

https://github.com/yuanfang-chen updated 
https://github.com/llvm/llvm-project/pull/72607

>From 471f87e727d71e3984d533eeb9db9ebab40e63ff Mon Sep 17 00:00:00 2001
From: Yuanfang Chen 
Date: Fri, 17 Nov 2023 03:16:38 +
Subject: [PATCH] [clang][ExprConst] allow single element access of vector
 object to be constant expression

Supports both v[0] and v.x/v.r/v.s0 syntax.
Selecting multiple elements is left as a future work.
---
 clang/docs/ReleaseNotes.rst   |   3 +
 clang/lib/AST/ExprConstant.cpp| 103 +-
 clang/lib/AST/Interp/State.h  |   3 +-
 clang/test/CodeGenCXX/temporaries.cpp |  43 
 .../constexpr-vectors-access-elements.cpp |  29 +
 5 files changed, 155 insertions(+), 26 deletions(-)
 create mode 100644 clang/test/SemaCXX/constexpr-vectors-access-elements.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0c8fec691bf3c9..070f0109501863 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -144,6 +144,9 @@ sections with improvements to Clang's support for those 
languages.
 
 C++ Language Changes
 
+- Allow single element access of vector object to be constant expression.
+  Supports the `V.xyzw` syntax and other tidbits as seen in OpenCL.
+  Selecting multiple elements is left as a future work.
 
 C++20 Feature Support
 ^
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f6aeee1a4e935d..9e2fc9b1af2ad1 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -221,6 +221,11 @@ namespace {
 ArraySize = 2;
 MostDerivedLength = I + 1;
 IsArray = true;
+  } else if (const auto *VT = Type->getAs()) {
+Type = VT->getElementType();
+ArraySize = VT->getNumElements();
+MostDerivedLength = I + 1;
+IsArray = true;
   } else if (const FieldDecl *FD = getAsField(Path[I])) {
 Type = FD->getType();
 ArraySize = 0;
@@ -437,6 +442,16 @@ namespace {
   MostDerivedArraySize = 2;
   MostDerivedPathLength = Entries.size();
 }
+void addVectorUnchecked(QualType EltTy, uint64_t Size, uint64_t Idx) {
+  Entries.push_back(PathEntry::ArrayIndex(Idx));
+
+  // This is technically a most-derived object, though in practice this
+  // is unlikely to matter.
+  MostDerivedType = EltTy;
+  MostDerivedIsArrayElement = true;
+  MostDerivedArraySize = Size;
+  MostDerivedPathLength = Entries.size();
+}
 void diagnoseUnsizedArrayPointerArithmetic(EvalInfo , const Expr *E);
 void diagnosePointerArithmetic(EvalInfo , const Expr *E,
const APSInt );
@@ -1732,6 +1747,11 @@ namespace {
   if (checkSubobject(Info, E, Imag ? CSK_Imag : CSK_Real))
 Designator.addComplexUnchecked(EltTy, Imag);
 }
+void addVectorElement(EvalInfo , const Expr *E, QualType EltTy,
+  uint64_t Size, uint64_t Idx) {
+  if (checkSubobject(Info, E, CSK_VectorElement))
+Designator.addVectorUnchecked(EltTy, Size, Idx);
+}
 void clearIsNullPointer() {
   IsNullPtr = false;
 }
@@ -3278,6 +3298,19 @@ static bool HandleLValueComplexElement(EvalInfo , 
const Expr *E,
   return true;
 }
 
+static bool HandleLValueVectorElement(EvalInfo , const Expr *E,
+  LValue , QualType EltTy,
+  uint64_t Size, uint64_t Idx) {
+  if (Idx) {
+CharUnits SizeOfElement;
+if (!HandleSizeof(Info, E->getExprLoc(), EltTy, SizeOfElement))
+  return false;
+LVal.Offset += SizeOfElement * Idx;
+  }
+  LVal.addVectorElement(Info, E, EltTy, Size, Idx);
+  return true;
+}
+
 /// Try to evaluate the initializer for a variable declaration.
 ///
 /// \param Info   Information about the ongoing evaluation.
@@ -3823,6 +3856,21 @@ findSubobject(EvalInfo , const Expr *E, const 
CompleteObject ,
 return handler.found(Index ? O->getComplexFloatImag()
: O->getComplexFloatReal(), ObjType);
   }
+} else if (const auto *VT = ObjType->getAs()) {
+  uint64_t Index = Sub.Entries[I].getAsArrayIndex();
+  if (Index >= VT->getNumElements()) {
+if (Info.getLangOpts().CPlusPlus11)
+  Info.FFDiag(E, diag::note_constexpr_access_past_end)
+<< handler.AccessKind;
+else
+  Info.FFDiag(E);
+return handler.failed();
+  }
+
+  ObjType = VT->getElementType();
+
+  assert(I == N - 1 && "extracting subobject of scalar?");
+  return handler.found(O->getVectorElt(Index), ObjType);
 } else if (const FieldDecl *Field = getAsField(Sub.Entries[I])) {
   if (Field->isMutable() &&
   !Obj.mayAccessMutableMembers(Info, handler.AccessKind)) {
@@ -8432,6 +8480,7 @@ class LValueExprEvaluator
   bool VisitCXXTypeidExpr(const CXXTypeidExpr 

[clang] [Clang] support vector subscript expressions in constant evaluator (WIP) (PR #76379)

2023-12-26 Thread Yuanfang Chen via cfe-commits

yuanfang-chen wrote:

#72607

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


[lld] [clang] [llvm] [LTO] Improve diagnostics handling when parsing module-level inline assembly (PR #75726)

2023-12-17 Thread Yuanfang Chen via cfe-commits

https://github.com/yuanfang-chen approved this pull request.

LGTM

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


[clang] [llvm] [LTO] Improve diagnostics handling when parsing module-level inline assembly (PR #75726)

2023-12-17 Thread Yuanfang Chen via cfe-commits

yuanfang-chen wrote:

`MachO/lto-module-asm-err.ll` needs update?

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


[clang] [clang][ExprConst] allow single element access of vector object to be constant expression (PR #72607)

2023-12-01 Thread Yuanfang Chen via cfe-commits

yuanfang-chen wrote:

ping ..

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


[clang] [clang][ExprConst] allow single element access of vector object to be constant expression (PR #72607)

2023-11-22 Thread Yuanfang Chen via cfe-commits

https://github.com/yuanfang-chen updated 
https://github.com/llvm/llvm-project/pull/72607

>From b7d7c5fc70ffb792f67d007ec1bd71bcaed868fc Mon Sep 17 00:00:00 2001
From: Yuanfang Chen 
Date: Fri, 17 Nov 2023 03:16:38 +
Subject: [PATCH] [clang][ExprConst] allow single element access of vector
 object to be constant expression

Supports both v[0] and v.x/v.r/v.s0 syntax.
Selecting multiple elements is left as a future work.
---
 clang/lib/AST/ExprConstant.cpp| 104 +-
 clang/lib/AST/Interp/State.h  |   3 +-
 clang/test/CodeGenCXX/temporaries.cpp |  43 
 .../constexpr-vectors-access-elements.cpp |  29 +
 4 files changed, 153 insertions(+), 26 deletions(-)
 create mode 100644 clang/test/SemaCXX/constexpr-vectors-access-elements.cpp

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 3a41e9718bb5875..d699a3a8fcf3e68 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -221,6 +221,12 @@ namespace {
 ArraySize = 2;
 MostDerivedLength = I + 1;
 IsArray = true;
+  } else if (Type->isVectorType()) {
+const auto *VT = Type->castAs();
+Type = VT->getElementType();
+ArraySize = VT->getNumElements();
+MostDerivedLength = I + 1;
+IsArray = true;
   } else if (const FieldDecl *FD = getAsField(Path[I])) {
 Type = FD->getType();
 ArraySize = 0;
@@ -437,6 +443,16 @@ namespace {
   MostDerivedArraySize = 2;
   MostDerivedPathLength = Entries.size();
 }
+void addVectorUnchecked(QualType EltTy, uint64_t Size, uint64_t Idx) {
+  Entries.push_back(PathEntry::ArrayIndex(Idx));
+
+  // This is technically a most-derived object, though in practice this
+  // is unlikely to matter.
+  MostDerivedType = EltTy;
+  MostDerivedIsArrayElement = true;
+  MostDerivedArraySize = Size;
+  MostDerivedPathLength = Entries.size();
+}
 void diagnoseUnsizedArrayPointerArithmetic(EvalInfo , const Expr *E);
 void diagnosePointerArithmetic(EvalInfo , const Expr *E,
const APSInt );
@@ -1715,6 +1731,11 @@ namespace {
   if (checkSubobject(Info, E, Imag ? CSK_Imag : CSK_Real))
 Designator.addComplexUnchecked(EltTy, Imag);
 }
+void addVectorElement(EvalInfo , const Expr *E, QualType EltTy,
+  uint64_t Size, uint64_t Idx) {
+  if (checkSubobject(Info, E, CSK_VectorElement))
+Designator.addVectorUnchecked(EltTy, Size, Idx);
+}
 void clearIsNullPointer() {
   IsNullPtr = false;
 }
@@ -3261,6 +3282,19 @@ static bool HandleLValueComplexElement(EvalInfo , 
const Expr *E,
   return true;
 }
 
+static bool HandleLValueVectorElement(EvalInfo , const Expr *E,
+  LValue , QualType EltTy,
+  uint64_t Size, uint64_t Idx) {
+  if (Idx) {
+CharUnits SizeOfElement;
+if (!HandleSizeof(Info, E->getExprLoc(), EltTy, SizeOfElement))
+  return false;
+LVal.Offset += SizeOfElement * Idx;
+  }
+  LVal.addVectorElement(Info, E, EltTy, Size, Idx);
+  return true;
+}
+
 /// Try to evaluate the initializer for a variable declaration.
 ///
 /// \param Info   Information about the ongoing evaluation.
@@ -3806,6 +3840,21 @@ findSubobject(EvalInfo , const Expr *E, const 
CompleteObject ,
 return handler.found(Index ? O->getComplexFloatImag()
: O->getComplexFloatReal(), ObjType);
   }
+} else if (ObjType->isVectorType()) {
+  uint64_t Index = Sub.Entries[I].getAsArrayIndex();
+  if (Index >= ObjType->castAs()->getNumElements()) {
+if (Info.getLangOpts().CPlusPlus11)
+  Info.FFDiag(E, diag::note_constexpr_access_past_end)
+<< handler.AccessKind;
+else
+  Info.FFDiag(E);
+return handler.failed();
+  }
+
+  ObjType = ObjType->castAs()->getElementType();
+
+  assert(I == N - 1 && "extracting subobject of scalar?");
+  return handler.found(O->getVectorElt(Index), ObjType);
 } else if (const FieldDecl *Field = getAsField(Sub.Entries[I])) {
   if (Field->isMutable() &&
   !Obj.mayAccessMutableMembers(Info, handler.AccessKind)) {
@@ -8408,6 +8457,7 @@ class LValueExprEvaluator
   bool VisitCXXTypeidExpr(const CXXTypeidExpr *E);
   bool VisitCXXUuidofExpr(const CXXUuidofExpr *E);
   bool VisitArraySubscriptExpr(const ArraySubscriptExpr *E);
+  bool VisitExtVectorElementExpr(const ExtVectorElementExpr *E);
   bool VisitUnaryDeref(const UnaryOperator *E);
   bool VisitUnaryReal(const UnaryOperator *E);
   bool VisitUnaryImag(const UnaryOperator *E);
@@ -8721,15 +8771,63 @@ bool LValueExprEvaluator::VisitMemberExpr(const 
MemberExpr *E) {
   return LValueExprEvaluatorBaseTy::VisitMemberExpr(E);
 }
 
+bool LValueExprEvaluator::VisitExtVectorElementExpr(
+const ExtVectorElementExpr 

[clang] [clang][ExprConst] allow single element access of vector object to be constant expression (PR #72607)

2023-11-21 Thread Yuanfang Chen via cfe-commits

yuanfang-chen wrote:

ping?

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


[clang] [clang][ExprConst] allow single element access of vector object to be constant expression (PR #72607)

2023-11-16 Thread Yuanfang Chen via cfe-commits

https://github.com/yuanfang-chen created 
https://github.com/llvm/llvm-project/pull/72607

Supports both v[0] and v.x/v.r/v.s0 syntax.

Selecting multiple elements is left as a future work.

>From 26a20b1c3594676b138395f91143356d87ec72cd Mon Sep 17 00:00:00 2001
From: Yuanfang Chen 
Date: Fri, 17 Nov 2023 03:16:38 +
Subject: [PATCH] [clang][ExprConst] allow single element access of vector
 object to be constant expression

Supports both v[0] and v.x/v.r/v.s0 syntax.
Selecting multiple elements is left as a future work.
---
 clang/lib/AST/ExprConstant.cpp| 98 ++-
 clang/lib/AST/Interp/State.h  |  3 +-
 clang/test/CodeGenCXX/temporaries.cpp | 43 
 .../constexpr-vectors-access-elements.cpp | 29 ++
 4 files changed, 147 insertions(+), 26 deletions(-)
 create mode 100644 clang/test/SemaCXX/constexpr-vectors-access-elements.cpp

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index eea0827d6f7a8a1..7468dc5c71fa895 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -436,6 +436,16 @@ namespace {
   MostDerivedArraySize = 2;
   MostDerivedPathLength = Entries.size();
 }
+void addVectorUnchecked(QualType EltTy, uint64_t Size, uint64_t Idx) {
+  Entries.push_back(PathEntry::ArrayIndex(Idx));
+
+  // This is technically a most-derived object, though in practice this
+  // is unlikely to matter.
+  MostDerivedType = EltTy;
+  MostDerivedIsArrayElement = true;
+  MostDerivedArraySize = Size;
+  MostDerivedPathLength = Entries.size();
+}
 void diagnoseUnsizedArrayPointerArithmetic(EvalInfo , const Expr *E);
 void diagnosePointerArithmetic(EvalInfo , const Expr *E,
const APSInt );
@@ -1714,6 +1724,11 @@ namespace {
   if (checkSubobject(Info, E, Imag ? CSK_Imag : CSK_Real))
 Designator.addComplexUnchecked(EltTy, Imag);
 }
+void addVectorElement(EvalInfo , const Expr *E, QualType EltTy,
+  uint64_t Size, uint64_t Idx) {
+  if (checkSubobject(Info, E, CSK_VectorElement))
+Designator.addVectorUnchecked(EltTy, Size, Idx);
+}
 void clearIsNullPointer() {
   IsNullPtr = false;
 }
@@ -3294,6 +3309,19 @@ static bool HandleLValueComplexElement(EvalInfo , 
const Expr *E,
   return true;
 }
 
+static bool HandleLValueVectorElement(EvalInfo , const Expr *E,
+  LValue , QualType EltTy,
+  uint64_t Size, uint64_t Idx) {
+  if (Idx) {
+CharUnits SizeOfElement;
+if (!HandleSizeof(Info, E->getExprLoc(), EltTy, SizeOfElement))
+  return false;
+LVal.Offset += SizeOfElement * Idx;
+  }
+  LVal.addVectorElement(Info, E, EltTy, Size, Idx);
+  return true;
+}
+
 /// Try to evaluate the initializer for a variable declaration.
 ///
 /// \param Info   Information about the ongoing evaluation.
@@ -3839,6 +3867,21 @@ findSubobject(EvalInfo , const Expr *E, const 
CompleteObject ,
 return handler.found(Index ? O->getComplexFloatImag()
: O->getComplexFloatReal(), ObjType);
   }
+} else if (ObjType->isVectorType()) {
+  uint64_t Index = Sub.Entries[I].getAsArrayIndex();
+  if (Index >= ObjType->castAs()->getNumElements()) {
+if (Info.getLangOpts().CPlusPlus11)
+  Info.FFDiag(E, diag::note_constexpr_access_past_end)
+<< handler.AccessKind;
+else
+  Info.FFDiag(E);
+return handler.failed();
+  }
+
+  ObjType = ObjType->castAs()->getElementType();
+
+  assert(I == N - 1 && "extracting subobject of scalar?");
+  return handler.found(O->getVectorElt(Index), ObjType);
 } else if (const FieldDecl *Field = getAsField(Sub.Entries[I])) {
   if (Field->isMutable() &&
   !Obj.mayAccessMutableMembers(Info, handler.AccessKind)) {
@@ -8294,6 +8337,7 @@ class LValueExprEvaluator
   bool VisitCXXTypeidExpr(const CXXTypeidExpr *E);
   bool VisitCXXUuidofExpr(const CXXUuidofExpr *E);
   bool VisitArraySubscriptExpr(const ArraySubscriptExpr *E);
+  bool VisitExtVectorElementExpr(const ExtVectorElementExpr *E);
   bool VisitUnaryDeref(const UnaryOperator *E);
   bool VisitUnaryReal(const UnaryOperator *E);
   bool VisitUnaryImag(const UnaryOperator *E);
@@ -8607,15 +8651,63 @@ bool LValueExprEvaluator::VisitMemberExpr(const 
MemberExpr *E) {
   return LValueExprEvaluatorBaseTy::VisitMemberExpr(E);
 }
 
+bool LValueExprEvaluator::VisitExtVectorElementExpr(
+const ExtVectorElementExpr *E) {
+  bool Success = true;
+
+  APValue Val;
+  if (!Evaluate(Val, Info, E->getBase())) {
+if (!Info.noteFailure())
+  return false;
+Success = false;
+  }
+
+  SmallVector Indices;
+  E->getEncodedElementAccess(Indices);
+  // FIXME: support accessing more than one element
+  if (Indices.size() > 1)
+return false;
+
+  if (Success) {
+

[clang] [flang][driver] support -dumpversion and -dumpmachine (PR #68896)

2023-10-24 Thread Yuanfang Chen via cfe-commits

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


[clang] [flang][driver] support -dumpversion and -dumpmachine (PR #68896)

2023-10-20 Thread Yuanfang Chen via cfe-commits

yuanfang-chen wrote:

> You are adding a support for these new flags in `flang-new`, which is 
> implemented in terms of `clangDriver` - this scenario (i.e. the two projects 
> being out of sync) would be very unlikely at the moment (perhaps even 
> impossible). And even if that was desired, you'd need to update Flang's 
> driver too. I'd rather keep this to the required minimum. If you really want 
> to keep this, you will need to update flang/tools/flang-driver/driver.cpp too.

Thanks for the explanation. I've updated the patch.

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


[clang] [flang][driver] support -dumpversion and -dumpmachine (PR #68896)

2023-10-20 Thread Yuanfang Chen via cfe-commits

https://github.com/yuanfang-chen updated 
https://github.com/llvm/llvm-project/pull/68896

>From db72a97acc7fd5a517b5ccd525fcf8a7b714fa29 Mon Sep 17 00:00:00 2001
From: Yuanfang Chen 
Date: Sat, 21 Oct 2023 01:18:47 +
Subject: [PATCH] [flang][driver] support -dumpversion and -dumpmachine

Match GCC driver. GCC has -cc1/-fc1 support too, but this patch does not 
address that.
---
 clang/include/clang/Driver/Options.td| 8 ++--
 flang/test/Driver/driver-help-hidden.f90 | 2 ++
 flang/test/Driver/driver-help.f90| 2 ++
 flang/test/Driver/dumpmachine.f90| 8 
 flang/test/Driver/immediate-options.f90  | 2 ++
 5 files changed, 20 insertions(+), 2 deletions(-)
 create mode 100644 flang/test/Driver/dumpmachine.f90
 create mode 100644 flang/test/Driver/immediate-options.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c272a7f1c398aa6..cae7bd07fc3cc54 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1375,9 +1375,13 @@ def dsym_dir : JoinedOrSeparate<["-"], "dsym-dir">,
 def dumpdir : Separate<["-"], "dumpdir">, Visibility<[ClangOption, CC1Option]>,
   MetaVarName<"">,
   HelpText<"Use  as a prefix to form auxiliary and dump file names">;
-def dumpmachine : Flag<["-"], "dumpmachine">;
+def dumpmachine : Flag<["-"], "dumpmachine">,
+  Visibility<[ClangOption, FlangOption]>,
+  HelpText<"Display the compiler's target processor">;
+def dumpversion : Flag<["-"], "dumpversion">,
+  Visibility<[ClangOption, FlangOption]>,
+  HelpText<"Display the version of the compiler">;
 def dumpspecs : Flag<["-"], "dumpspecs">, Flags<[Unsupported]>;
-def dumpversion : Flag<["-"], "dumpversion">;
 def dylib__file : Separate<["-"], "dylib_file">;
 def dylinker__install__name : JoinedOrSeparate<["-"], "dylinker_install_name">;
 def dylinker : Flag<["-"], "dylinker">;
diff --git a/flang/test/Driver/driver-help-hidden.f90 
b/flang/test/Driver/driver-help-hidden.f90
index 807b0f938d27b5c..caea8880ba8fb8e 100644
--- a/flang/test/Driver/driver-help-hidden.f90
+++ b/flang/test/Driver/driver-help-hidden.f90
@@ -21,6 +21,8 @@
 ! CHECK-NEXT: -ccc-print-phases   Dump list of actions to perform
 ! CHECK-NEXT: -cppEnable predefined and command line 
preprocessor macros
 ! CHECK-NEXT: -c  Only run preprocess, compile, and 
assemble steps
+! CHECK-NEXT: -dumpmachineDisplay the compiler's target processor
+! CHECK-NEXT: -dumpversionDisplay the version of the compiler
 ! CHECK-NEXT: -D =  Define  to  (or 1 if 
 omitted)
 ! CHECK-NEXT: -emit-llvm  Use the LLVM representation for 
assembler and object files
 ! CHECK-NEXT: -E  Only run the preprocessor
diff --git a/flang/test/Driver/driver-help.f90 
b/flang/test/Driver/driver-help.f90
index 4894f90f5310439..1580c267cfc6ae6 100644
--- a/flang/test/Driver/driver-help.f90
+++ b/flang/test/Driver/driver-help.f90
@@ -17,6 +17,8 @@
 ! HELP-NEXT: -###Print (but do not run) the commands to 
run for this compilation
 ! HELP-NEXT: -cppEnable predefined and command line 
preprocessor macros
 ! HELP-NEXT: -c  Only run preprocess, compile, and 
assemble steps
+! HELP-NEXT: -dumpmachineDisplay the compiler's target processor
+! HELP-NEXT: -dumpversionDisplay the version of the compiler
 ! HELP-NEXT: -D =  Define  to  (or 1 if 
 omitted)
 ! HELP-NEXT: -emit-llvm  Use the LLVM representation for assembler 
and object files
 ! HELP-NEXT: -E  Only run the preprocessor
diff --git a/flang/test/Driver/dumpmachine.f90 
b/flang/test/Driver/dumpmachine.f90
new file mode 100644
index 000..b68705707eefa04
--- /dev/null
+++ b/flang/test/Driver/dumpmachine.f90
@@ -0,0 +1,8 @@
+! Test that -dumpmachine prints the target triple.
+
+! Note: Debian GCC may omit "unknown-".
+! RUN: %flang --target=x86_64-linux-gnu -dumpmachine | FileCheck %s 
--check-prefix=X86_64
+! X86_64: x86_64-unknown-linux-gnu
+
+! RUN: %flang --target=xxx-pc-freebsd -dumpmachine | FileCheck %s 
--check-prefix=FREEBSD
+! FREEBSD: xxx-pc-freebsd
diff --git a/flang/test/Driver/immediate-options.f90 
b/flang/test/Driver/immediate-options.f90
new file mode 100644
index 000..81c1e7181ba7935
--- /dev/null
+++ b/flang/test/Driver/immediate-options.f90
@@ -0,0 +1,2 @@
+! RUN: %flang -dumpversion | FileCheck %s -check-prefix=DUMPVERSION
+! DUMPVERSION: {{[0-9]+\.[0-9.]+}}

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


[clang] [flang][driver] support -dumpversion and -dumpmachine (PR #68896)

2023-10-17 Thread Yuanfang Chen via cfe-commits

yuanfang-chen wrote:

> Could this be implemented without any updates to Clang (beyond Options.td)?

The options could work by changing options.td only. However,  
`CLANG_VERSION_STRING` and `FLANG_VERSION_STRING` could be different. This is 
to handle that.

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


[clang] [flang][driver] support -dumpversion and -dumpmachine (PR #68896)

2023-10-12 Thread Yuanfang Chen via cfe-commits

https://github.com/yuanfang-chen created 
https://github.com/llvm/llvm-project/pull/68896

Match GCC driver. GCC has -cc1/-fc1 support too, but this patch does not 
address that.

>From b248b63c74853cfd57809ffc32f437c517a926ef Mon Sep 17 00:00:00 2001
From: Yuanfang Chen 
Date: Thu, 12 Oct 2023 07:40:13 +
Subject: [PATCH] [flang][driver] support -dumpversion and -dumpmachine

Match GCC driver. GCC has -cc1/-fc1 support too, but this patch
does not address that.
---
 clang/include/clang/Driver/Driver.h  | 7 ++-
 clang/include/clang/Driver/Options.td| 8 ++--
 clang/lib/Driver/Driver.cpp  | 9 +
 flang/test/Driver/driver-help-hidden.f90 | 2 ++
 flang/test/Driver/driver-help.f90| 2 ++
 flang/test/Driver/dumpmachine.f90| 8 
 flang/test/Driver/immediate-options.f90  | 2 ++
 7 files changed, 31 insertions(+), 7 deletions(-)
 create mode 100644 flang/test/Driver/dumpmachine.f90
 create mode 100644 flang/test/Driver/immediate-options.f90

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 3ee1bcf2a69c9bd..fdb8aaf3572ba31 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -12,6 +12,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/HeaderInclude.h"
 #include "clang/Basic/LLVM.h"
+#include "clang/Basic/Version.h"
 #include "clang/Driver/Action.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/InputInfo.h"
@@ -188,6 +189,9 @@ class Driver {
   /// Driver title to use with help.
   std::string DriverTitle;
 
+  /// Driver version.
+  std::string DriverVersion;
+
   /// Information about the host which can be overridden by the user.
   std::string HostBits, HostMachine, HostSystem, HostRelease;
 
@@ -373,7 +377,8 @@ class Driver {
 
   Driver(StringRef ClangExecutable, StringRef TargetTriple,
  DiagnosticsEngine , std::string Title = "clang LLVM compiler",
- IntrusiveRefCntPtr VFS = nullptr);
+ IntrusiveRefCntPtr VFS = nullptr,
+ std::string Version = CLANG_VERSION_STRING);
 
   /// @name Accessors
   /// @{
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c272a7f1c398aa6..cae7bd07fc3cc54 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1375,9 +1375,13 @@ def dsym_dir : JoinedOrSeparate<["-"], "dsym-dir">,
 def dumpdir : Separate<["-"], "dumpdir">, Visibility<[ClangOption, CC1Option]>,
   MetaVarName<"">,
   HelpText<"Use  as a prefix to form auxiliary and dump file names">;
-def dumpmachine : Flag<["-"], "dumpmachine">;
+def dumpmachine : Flag<["-"], "dumpmachine">,
+  Visibility<[ClangOption, FlangOption]>,
+  HelpText<"Display the compiler's target processor">;
+def dumpversion : Flag<["-"], "dumpversion">,
+  Visibility<[ClangOption, FlangOption]>,
+  HelpText<"Display the version of the compiler">;
 def dumpspecs : Flag<["-"], "dumpspecs">, Flags<[Unsupported]>;
-def dumpversion : Flag<["-"], "dumpversion">;
 def dylib__file : Separate<["-"], "dylib_file">;
 def dylinker__install__name : JoinedOrSeparate<["-"], "dylinker_install_name">;
 def dylinker : Flag<["-"], "dylinker">;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 77328e1f99e5021..c84acb2beb17a70 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -190,14 +190,15 @@ std::string Driver::GetResourcesPath(StringRef BinaryPath,
 
 Driver::Driver(StringRef ClangExecutable, StringRef TargetTriple,
DiagnosticsEngine , std::string Title,
-   IntrusiveRefCntPtr VFS)
+   IntrusiveRefCntPtr VFS,
+   std::string Version)
 : Diags(Diags), VFS(std::move(VFS)), Mode(GCCMode),
   SaveTemps(SaveTempsNone), BitcodeEmbed(EmbedNone),
   Offload(OffloadHostDevice), CXX20HeaderType(HeaderMode_None),
   ModulesModeCXX20(false), LTOMode(LTOK_None),
   ClangExecutable(ClangExecutable), SysRoot(DEFAULT_SYSROOT),
-  DriverTitle(Title), CCCPrintBindings(false), CCPrintOptions(false),
-  CCLogDiagnostics(false), CCGenDiagnostics(false),
+  DriverTitle(Title), DriverVersion(Version), CCCPrintBindings(false),
+  CCPrintOptions(false), CCLogDiagnostics(false), CCGenDiagnostics(false),
   CCPrintProcessStats(false), CCPrintInternalStats(false),
   TargetTriple(TargetTriple), Saver(Alloc), PrependArg(nullptr),
   CheckInputsExist(true), ProbePrecompiled(true),
@@ -2081,7 +2082,7 @@ bool Driver::HandleImmediateArgs(const Compilation ) {
   if (C.getArgs().hasArg(options::OPT_dumpversion)) {
 // Since -dumpversion is only implemented for pedantic GCC compatibility, 
we
 // return an answer which matches our definition of __VERSION__.
-llvm::outs() << CLANG_VERSION_STRING << "\n";
+llvm::outs() << DriverVersion << "\n";
 return false;
   }
 
diff --git a/flang/test/Driver/driver-help-hidden.f90 

[clang] [Clang] Fix crash when ill-formed code is treated as a deduction guide (PR #67373)

2023-09-29 Thread Yuanfang Chen via cfe-commits

https://github.com/yuanfang-chen approved this pull request.

LGTM

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


[clang-tools-extra] [Clang] Fix crash when ill-formed code is treated as a deduction guide (PR #67373)

2023-09-29 Thread Yuanfang Chen via cfe-commits

https://github.com/yuanfang-chen approved this pull request.

LGTM

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


[clang] 92f4bf2 - Fix aggregate CTAD with string literals adding extra const

2023-07-05 Thread Yuanfang Chen via cfe-commits

Author: Mital Ashok
Date: 2023-07-05T11:54:51-07:00
New Revision: 92f4bf268998201ec05dab9917c2873afc578a94

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

LOG: Fix aggregate CTAD with string literals adding extra const

Missing a `withConst`, so when deducing from a string literal, a `const` is 
erroneously added to the deduced type.

Reviewed By: ychen

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

Added: 


Modified: 
clang/lib/Sema/SemaInit.cpp
clang/test/CXX/drs/dr26xx.cpp
clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 6db211a20e311f..f2bbdae3d5f36b 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -10714,7 +10714,8 @@ QualType 
Sema::DeduceTemplateSpecializationFromInitializer(
   ElementTypes[I] = 
Context.getRValueReferenceType(ElementTypes[I]);
 else if (isa(
  ListInit->getInit(I)->IgnoreParenImpCasts()))
-  ElementTypes[I] = 
Context.getLValueReferenceType(ElementTypes[I]);
+  ElementTypes[I] =
+  Context.getLValueReferenceType(ElementTypes[I].withConst());
   }
 
 llvm::FoldingSetNodeID ID;

diff  --git a/clang/test/CXX/drs/dr26xx.cpp b/clang/test/CXX/drs/dr26xx.cpp
index 175e27e6e2ed63..e4b6156235ecc0 100644
--- a/clang/test/CXX/drs/dr26xx.cpp
+++ b/clang/test/CXX/drs/dr26xx.cpp
@@ -126,3 +126,27 @@ void f() {
 brachiosaur |= neck;// OK
 }
 }
+
+namespace dr2681 { // dr2681: 17
+using size_t = decltype(sizeof(int));
+
+template
+struct H {
+  T array[N];
+};
+template
+struct I {
+  volatile T array[N];
+};
+template
+struct J {  // expected-note 3{{candidate}}
+  unsigned char array[N];
+};
+
+H h = { "abc" };
+I i = { "def" };
+static_assert(__is_same(decltype(h), H));  // Not H
+static_assert(__is_same(decltype(i), I));
+
+J j = { "ghi" };  // expected-error {{no viable constructor or deduction 
guide}}
+}

diff  --git a/clang/test/SemaTemplate/aggregate-deduction-candidate.cpp 
b/clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
index 71189be0762364..d455d424ab3d0e 100644
--- a/clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
+++ b/clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
@@ -198,22 +198,22 @@ namespace Array {
   // CHECK: FunctionTemplateDecl {{.*}} implicit 
   // CHECK: |-TemplateTypeParmDecl {{.*}} referenced typename depth 0 index 0 T
   // CHECK: |-NonTypeTemplateParmDecl {{.*}} 'size_t':'unsigned {{.*}}' depth 
0 index 1 N
-  // CHECK: |-CXXDeductionGuideDecl {{.*}} implicit  
'auto (T (&)[N]) -> A'
-  // CHECK: | `-ParmVarDecl {{.*}} 'T (&)[N]'
-  // CHECK: `-CXXDeductionGuideDecl {{.*}} implicit used  'auto (const char (&)[5]) -> Array::A'
-  // CHECK:   |-TemplateArgument type 'const char'
-  // CHECK:   | `-QualType {{.*}} 'const char' const
-  // CHECK:   |   `-BuiltinType {{.*}} 'char'
+  // CHECK: |-CXXDeductionGuideDecl {{.*}} implicit  
'auto (const T (&)[N]) -> A'
+  // CHECK: | `-ParmVarDecl {{.*}} 'const T (&)[N]'
+  // CHECK: `-CXXDeductionGuideDecl {{.*}} implicit used  'auto (const char (&)[5]) -> Array::A'
+  // CHECK:   |-TemplateArgument type 'char'
+  // CHECK:   | `-BuiltinType {{.*}} 'char'
   // CHECK:   |-TemplateArgument integral 5
   // CHECK:   `-ParmVarDecl {{.*}} 'const char (&)[5]'
-  // CHECK: FunctionProtoType {{.*}} 'auto (T (&)[N]) -> A' dependent 
trailing_return cdecl
+  // CHECK: FunctionProtoType {{.*}} 'auto (const T (&)[N]) -> A' 
dependent trailing_return cdecl
   // CHECK: |-InjectedClassNameType {{.*}} 'A' dependent
   // CHECK: | `-CXXRecord {{.*}} 'A'
-  // CHECK: `-LValueReferenceType {{.*}} 'T (&)[N]' dependent
-  // CHECK:   `-DependentSizedArrayType {{.*}} 'T[N]' dependent
-  // CHECK: |-TemplateTypeParmType {{.*}} 'T' dependent depth 0 index 0
-  // CHECK: | `-TemplateTypeParm {{.*}} 'T'
-  // CHECK: `-DeclRefExpr {{.*}} 'size_t':'unsigned {{.*}}' 
NonTypeTemplateParm {{.*}} 'N' 'size_t':'unsigned {{.*}}'
+  // CHECK: `-LValueReferenceType {{.*}} 'const T (&)[N]' dependent
+  // CHECK:   `-QualType {{.*}} 'const T[N]' const
+  // CHECK: `-DependentSizedArrayType {{.*}} 'T[N]' dependent
+  // CHECK:   |-TemplateTypeParmType {{.*}} 'T' dependent depth 0 index 0
+  // CHECK:   | `-TemplateTypeParm {{.*}} 'T'
+  // CHECK:   `-DeclRefExpr {{.*}} 'size_t':'unsigned{{.*}}' 
NonTypeTemplateParm {{.*}} 'N' 'size_t':'unsigned{{.*}}'
 }
 
 namespace BraceElision {

diff  --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 13b230706b9e80..702d84ebba9859 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html

[clang] c0e23bc - [clang] P1816R0 and P2082R1 should work for cxx20 and after only

2023-07-01 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2023-07-01T17:23:41-07:00
New Revision: c0e23bcdfb743f4d7d05e215fb60c987f629498d

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

LOG: [clang] P1816R0 and P2082R1 should work for cxx20 and after only

For commit 632dd6a4ca0036009f

Added: 


Modified: 
clang/lib/Sema/SemaInit.cpp
clang/test/SemaTemplate/aggregate-deduction-candidate.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 90c1bfa8f6d1fa..b893d358dfe790 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -10675,7 +10675,7 @@ QualType 
Sema::DeduceTemplateSpecializationFromInitializer(
   TD, FoundDecl, /*ExplicitArgs=*/nullptr, TmpInits, Candidates,
   SuppressUserConversions,
   /*PartialOverloading=*/false, AllowExplicit, ADLCallKind::NotADL,
-  /*PO=*/{}, /*AggregateCandidateDeduction=*/true);
+  /*PO=*/{}, AllowAggregateDeductionCandidate);
 } else {
   AddOverloadCandidate(GD, FoundDecl, Inits, Candidates,
SuppressUserConversions,
@@ -10772,7 +10772,7 @@ QualType 
Sema::DeduceTemplateSpecializationFromInitializer(
 //   parenthesized expression-list, and there are no deduction-guides for
 //   C, the set contains an additional function template, called the
 //   aggregate deduction candidate, defined as follows.
-if (!HasAnyDeductionGuide) {
+if (getLangOpts().CPlusPlus20 && !HasAnyDeductionGuide) {
   if (ListInit && ListInit->getNumInits()) {
 SynthesizeAggrGuide(ListInit);
   } else if (PL && PL->getNumExprs()) {

diff  --git a/clang/test/SemaTemplate/aggregate-deduction-candidate.cpp 
b/clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
index 4bec1a8d4c48a6..71189be0762364 100644
--- a/clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
+++ b/clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
@@ -1,15 +1,16 @@
-// RUN: %clang_cc1 -std=c++20 -verify -ast-dump -ast-dump-decl-types 
-ast-dump-filter "deduction guide" %s | FileCheck %s --strict-whitespace
+// RUN: %clang_cc1 -std=c++17 -verify=expected,cxx17 %s
+// RUN: %clang_cc1 -std=c++20 -verify=expected,cxx20 -ast-dump 
-ast-dump-decl-types -ast-dump-filter "deduction guide" %s | FileCheck %s 
--strict-whitespace
 
 namespace Basic {
-  template struct A {
+  template struct A { // cxx17-note 6 {{candidate}}
 T x;
 T y;
   };
 
-  A a1 = {3.0, 4.0};
-  A a2 = {.x = 3.0, .y = 4.0};
+  A a1 = {3.0, 4.0}; // cxx17-error {{no viable}}
+  A a2 = {.x = 3.0, .y = 4.0}; // cxx17-error {{no viable}}
 
-  A a3(3.0, 4.0);
+  A a3(3.0, 4.0); // cxx17-error {{no viable}}
 
   // CHECK-LABEL: Dumping Basic:::
   // CHECK: FunctionTemplateDecl {{.*}} implicit 
@@ -30,31 +31,31 @@ namespace Basic {
   // CHECK: `-TemplateTypeParmType {{.*}} 'T' dependent depth 0 index 0
   // CHECK:   `-TemplateTypeParm {{.*}} 'T'
 
-  template  struct S { // expected-note 2 {{candidate}}
+  template  struct S { // cxx20-note 2 {{candidate}}
 T x;
 T y;
   };
 
-  template  struct C { // expected-note 10 {{candidate}}
+  template  struct C { // cxx20-note 10 {{candidate}} cxx17-note 
12 {{candidate}}
 S s;
 T t;
   };
 
-  template  struct D { // expected-note 6 {{candidate}}
+  template  struct D { // cxx20-note 6 {{candidate}} cxx17-note 8 
{{candidate}}
 S s;
 T t;
   };
 
   C c1 = {1, 2}; // expected-error {{no viable}}
   C c2 = {1, 2, 3}; // expected-error {{no viable}}
-  C c3 = {{1u, 2u}, 3};
+  C c3 = {{1u, 2u}, 3}; // cxx17-error {{no viable}}
 
   C c4(1, 2);// expected-error {{no viable}}
   C c5(1, 2, 3); // expected-error {{no viable}}
-  C c6({1u, 2u}, 3);
+  C c6({1u, 2u}, 3); // cxx17-error {{no viable}}
 
   D d1 = {1, 2}; // expected-error {{no viable}}
-  D d2 = {1, 2, 3};
+  D d2 = {1, 2, 3}; // cxx17-error {{no viable}}
 
   D d3(1, 2); // expected-error {{no viable}}
   // CTAD succeed but brace elision is not allowed for parenthesized aggregate 
init. 
@@ -98,14 +99,14 @@ namespace Basic {
   // CHECK:   |-ClassTemplateSpecialization {{.*}} 'S'
   // CHECK:   `-BuiltinType {{.*}} 'int'
 
-  template  struct E {
+  template  struct E { // cxx17-note 4 {{candidate}}
 T t;
 decltype(t) t2;
   };
 
-  E e1 = {1, 2};
+  E e1 = {1, 2}; // cxx17-error {{no viable}}
 
-  E e2(1, 2);
+  E e2(1, 2); // cxx17-error {{no viable}}
 
   // CHECK-LABEL: Dumping Basic:::
   // CHECK: FunctionTemplateDecl {{.*}} implicit 
@@ -132,12 +133,12 @@ namespace Basic {
   };
 
   template 
-  struct F {
+  struct F { // cxx17-note 2 {{candidate}}
 typename I::type i;
 T t;
   };
 
-  F f1 = {1, 2};
+  F f1 = {1, 2}; // cxx17-error {{no viable}}
 
   // CHECK-LABEL: Dumping Basic:::
   // CHECK: 

[clang] e5cc56a - [clang] Update cxx_status for 632dd6a4ca0036009f

2023-06-30 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2023-06-30T09:10:33-07:00
New Revision: e5cc56a0d1026ca25410b3abea64496c13bfbbe3

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

LOG: [clang] Update cxx_status for 632dd6a4ca0036009f

missed this after rebase

Added: 


Modified: 
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index 94c96ba0614e27..2c98f86c09a984 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -811,7 +811,7 @@ C++20 implementation status
 
   Class template argument deduction for aggregates
   https://wg21.link/p1816r0;>P1816R0
-  No
+  Clang 17
 

 https://wg21.link/p2082r1;>P2082R1



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


[clang] f78c9be - Adjust tests in 632dd6a4ca0036009f for ARM host

2023-06-29 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2023-06-29T15:35:10-07:00
New Revision: f78c9be14d739b27875004a751283c2431220ad1

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

LOG: Adjust tests in 632dd6a4ca0036009f for ARM host

size_t is unsigned int on ARM.

Added: 


Modified: 
clang/test/SemaTemplate/aggregate-deduction-candidate.cpp

Removed: 




diff  --git a/clang/test/SemaTemplate/aggregate-deduction-candidate.cpp 
b/clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
index 90794e012c6ee5..4bec1a8d4c48a6 100644
--- a/clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
+++ b/clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
@@ -176,7 +176,7 @@ namespace Array {
   // CHECK-LABEL: Dumping Array:::
   // CHECK: FunctionTemplateDecl {{.*}} implicit 
   // CHECK: |-TemplateTypeParmDecl {{.*}} referenced typename depth 0 index 0 T
-  // CHECK: |-NonTypeTemplateParmDecl {{.*}} 'size_t':'unsigned long{{( 
long)?}}' depth 0 index 1 N
+  // CHECK: |-NonTypeTemplateParmDecl {{.*}} 'size_t':'unsigned {{.*}}' depth 
0 index 1 N
   // CHECK: |-CXXDeductionGuideDecl {{.*}} implicit  
'auto (T (&&)[N]) -> A'
   // CHECK: | `-ParmVarDecl {{.*}} 'T (&&)[N]'
   // CHECK: `-CXXDeductionGuideDecl {{.*}} implicit used  'auto (int (&&)[3]) -> Array::A'
@@ -191,12 +191,12 @@ namespace Array {
   // CHECK:   `-DependentSizedArrayType {{.*}} 'T[N]' dependent
   // CHECK: |-TemplateTypeParmType {{.*}} 'T' dependent depth 0 index 0
   // CHECK: | `-TemplateTypeParm {{.*}} 'T'
-  // CHECK: `-DeclRefExpr {{.*}} 'size_t':'unsigned long{{( long)?}}' 
NonTypeTemplateParm {{.*}} 'N' 'size_t':'unsigned long{{( long)?}}'
+  // CHECK: `-DeclRefExpr {{.*}} 'size_t':'unsigned {{.*}}' 
NonTypeTemplateParm {{.*}} 'N' 'size_t':'unsigned {{.*}}'
 
   // CHECK: Dumping Array:::
   // CHECK: FunctionTemplateDecl {{.*}} implicit 
   // CHECK: |-TemplateTypeParmDecl {{.*}} referenced typename depth 0 index 0 T
-  // CHECK: |-NonTypeTemplateParmDecl {{.*}} 'size_t':'unsigned long{{( 
long)?}}' depth 0 index 1 N
+  // CHECK: |-NonTypeTemplateParmDecl {{.*}} 'size_t':'unsigned {{.*}}' depth 
0 index 1 N
   // CHECK: |-CXXDeductionGuideDecl {{.*}} implicit  
'auto (T (&)[N]) -> A'
   // CHECK: | `-ParmVarDecl {{.*}} 'T (&)[N]'
   // CHECK: `-CXXDeductionGuideDecl {{.*}} implicit used  'auto (const char (&)[5]) -> Array::A'
@@ -212,7 +212,7 @@ namespace Array {
   // CHECK:   `-DependentSizedArrayType {{.*}} 'T[N]' dependent
   // CHECK: |-TemplateTypeParmType {{.*}} 'T' dependent depth 0 index 0
   // CHECK: | `-TemplateTypeParm {{.*}} 'T'
-  // CHECK: `-DeclRefExpr {{.*}} 'size_t':'unsigned long{{( long)?}}' 
NonTypeTemplateParm {{.*}} 'N' 'size_t':'unsigned long{{( long)?}}'
+  // CHECK: `-DeclRefExpr {{.*}} 'size_t':'unsigned {{.*}}' 
NonTypeTemplateParm {{.*}} 'N' 'size_t':'unsigned {{.*}}'
 }
 
 namespace BraceElision {



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


[clang] 632dd6a - [Clang] Implements CTAD for aggregates P1816R0 and P2082R1

2023-06-29 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2023-06-29T14:22:24-07:00
New Revision: 632dd6a4ca0036009febd55d95e4e1f93eeb412c

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

LOG: [Clang] Implements CTAD for aggregates P1816R0 and P2082R1

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

Added: 
clang/test/SemaTemplate/aggregate-deduction-candidate.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/DeclBase.h
clang/include/clang/AST/DeclCXX.h
clang/include/clang/Sema/Sema.h
clang/include/clang/Sema/TemplateDeduction.h
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/Decl.cpp
clang/lib/AST/DeclCXX.cpp
clang/lib/Frontend/FrontendActions.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaInit.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriterDecl.cpp
clang/unittests/AST/ASTImporterTest.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 03c27a207d5e1b..3afb4b1edb2dbd 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -112,6 +112,8 @@ C++20 Feature Support
 - Clang now supports `requires cplusplus20` for module maps.
 - Implemented missing parts of `P2002R1: Consistent comparison operators 
`_
 - Clang now defines `__cpp_consteval` macro.
+- Implemented `P1816R0: `_ and `P2082R1: 
`_,
+  which allows CTAD for aggregates.
 
 C++23 Feature Support
 ^

diff  --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index eea8a111ab774f..1b99709ca90d99 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -1382,6 +1382,13 @@ class DeclContextLookupResult {
   }
 };
 
+/// Only used by CXXDeductionGuideDecl.
+enum class DeductionCandidate : unsigned char {
+  Normal,
+  Copy,
+  Aggregate,
+};
+
 /// DeclContext - This is used only as base class of specific decl types that
 /// can act as declaration contexts. These decls are (only the top classes
 /// that directly derive from DeclContext are mentioned, not their subclasses):
@@ -1620,10 +1627,10 @@ class DeclContext {
   /// Stores the bits used by FunctionDecl.
   /// If modified NumFunctionDeclBits and the accessor
   /// methods in FunctionDecl and CXXDeductionGuideDecl
-  /// (for IsCopyDeductionCandidate) should be updated appropriately.
+  /// (for DeductionCandidateKind) should be updated appropriately.
   class FunctionDeclBitfields {
 friend class FunctionDecl;
-/// For IsCopyDeductionCandidate
+/// For DeductionCandidateKind
 friend class CXXDeductionGuideDecl;
 /// For the bits in DeclContextBitfields.
 uint64_t : NumDeclContextBits;
@@ -1678,10 +1685,10 @@ class DeclContext {
 /// function using attribute 'target'.
 uint64_t IsMultiVersion : 1;
 
-/// [C++17] Only used by CXXDeductionGuideDecl. Indicates that
-/// the Deduction Guide is the implicitly generated 'copy
-/// deduction candidate' (is used during overload resolution).
-uint64_t IsCopyDeductionCandidate : 1;
+/// Only used by CXXDeductionGuideDecl. Indicates the kind
+/// of the Deduction Guide that is implicitly generated
+/// (used during overload resolution).
+uint64_t DeductionCandidateKind : 2;
 
 /// Store the ODRHash after first calculation.
 uint64_t HasODRHash : 1;

diff  --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index b8e5224a0f2251..f4322e1e00f0c6 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1942,13 +1942,13 @@ class CXXDeductionGuideDecl : public FunctionDecl {
 ExplicitSpecifier ES,
 const DeclarationNameInfo , QualType T,
 TypeSourceInfo *TInfo, SourceLocation EndLocation,
-CXXConstructorDecl *Ctor)
+CXXConstructorDecl *Ctor, DeductionCandidate Kind)
   : FunctionDecl(CXXDeductionGuide, C, DC, StartLoc, NameInfo, T, TInfo,
  SC_None, false, false, ConstexprSpecKind::Unspecified),
 Ctor(Ctor), ExplicitSpec(ES) {
 if (EndLocation.isValid())
   setRangeEnd(EndLocation);
-setIsCopyDeductionCandidate(false);
+setDeductionCandidateKind(Kind);
   }
 
   CXXConstructorDecl *Ctor;
@@ -1963,7 +1963,8 @@ class CXXDeductionGuideDecl : public FunctionDecl {
   Create(ASTContext , DeclContext *DC, SourceLocation 

[clang] 9aae408 - [NFC] fix typo `funciton` -> `function`

2023-03-10 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2023-03-10T18:05:25-08:00
New Revision: 9aae408d551083bbbac96ecc512d45c30358e4b9

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

LOG: [NFC] fix typo `funciton` -> `function`

credits to @jmagee

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticGroups.td
clang/test/SemaCXX/coroutine-alloc-4.cpp
flang/lib/Evaluate/intrinsics-library.cpp
lldb/include/lldb/Target/TraceDumper.h
lldb/source/Plugins/Language/CPlusPlus/CPlusPlusNameParser.cpp
llvm/include/llvm/CodeGen/MIRPrinter.h
llvm/include/llvm/ExecutionEngine/Orc/EPCDebugObjectRegistrar.h
llvm/include/llvm/ExecutionEngine/Orc/EPCEHFrameRegistrar.h
llvm/include/llvm/Transforms/Scalar/LoopPassManager.h
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp
llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp
llvm/lib/Target/PowerPC/PPCISelLowering.cpp
llvm/test/Transforms/SampleProfile/inline-mergeprof-dup.ll
llvm/tools/llvm-xray/xray-account.cpp
llvm/tools/llvm-xray/xray-graph.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index d56aba34ac0a..866dca008381 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -65,7 +65,7 @@ def DeprecatedCoroutine :
 def AlwaysInlineCoroutine :
   DiagGroup<"always-inline-coroutine">;
 def CoroNonAlignedAllocationFunction :
-  DiagGroup<"coro-non-aligned-allocation-funciton">;
+  DiagGroup<"coro-non-aligned-allocation-function">;
 def Coroutine : DiagGroup<"coroutine", [CoroutineMissingUnhandledException, 
DeprecatedCoroutine,
 AlwaysInlineCoroutine, 
CoroNonAlignedAllocationFunction]>;
 def ObjCBoolConstantConversion : DiagGroup<"objc-bool-constant-conversion">;

diff  --git a/clang/test/SemaCXX/coroutine-alloc-4.cpp 
b/clang/test/SemaCXX/coroutine-alloc-4.cpp
index acad2779a254..262c163fb178 100644
--- a/clang/test/SemaCXX/coroutine-alloc-4.cpp
+++ b/clang/test/SemaCXX/coroutine-alloc-4.cpp
@@ -1,4 +1,4 @@
-// Tests that we'll find aligned allocation funciton properly.
+// Tests that we'll find aligned allocation function properly.
 // RUN: %clang_cc1 %s -std=c++20 %s -fsyntax-only -verify 
-fcoro-aligned-allocation
 
 #include "Inputs/std-coroutine.h"

diff  --git a/flang/lib/Evaluate/intrinsics-library.cpp 
b/flang/lib/Evaluate/intrinsics-library.cpp
index c333ffeac90c..3a6d28e4ab04 100644
--- a/flang/lib/Evaluate/intrinsics-library.cpp
+++ b/flang/lib/Evaluate/intrinsics-library.cpp
@@ -295,7 +295,7 @@ struct HostRuntimeLibrary, 
LibraryVersion::Libm> {
 /// Define libm extensions
 /// Bessel functions are defined in POSIX.1-2001.
 
-// Remove float bessel funcitons for AIX as they are not supported
+// Remove float bessel functions for AIX as they are not supported
 #ifndef _AIX
 template <> struct HostRuntimeLibrary {
   using F = FuncPointer;

diff  --git a/lldb/include/lldb/Target/TraceDumper.h 
b/lldb/include/lldb/Target/TraceDumper.h
index ca3bf2c08808..ca08dc254182 100644
--- a/lldb/include/lldb/Target/TraceDumper.h
+++ b/lldb/include/lldb/Target/TraceDumper.h
@@ -317,7 +317,7 @@ class TraceDumper {
 FunctionCall(const lldb::TraceCursorSP _sp,
  const SymbolInfo _info);
 
-/// Append a new traced segment to this funciton call.
+/// Append a new traced segment to this function call.
 ///
 /// \param[in] cursor_sp
 ///   A cursor pointing to the first instruction of the new segment.

diff  --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusNameParser.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusNameParser.cpp
index 617181a35d1d..1f7d8a1b8598 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusNameParser.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusNameParser.cpp
@@ -172,7 +172,7 @@ CPlusPlusNameParser::ParseFuncPtr(bool expect_return_type) {
   //
   // Consume inner function name. This will fail unless
   // we stripped all the pointers on the left hand side
-  // of the funciton name.
+  // of the function name.
   {
 Bookmark before_inner_function_pos = SetBookmark();
 auto maybe_inner_function_name = ParseFunctionImpl(false);

diff  --git a/llvm/include/llvm/CodeGen/MIRPrinter.h 
b/llvm/include/llvm/CodeGen/MIRPrinter.h
index 45e30686b642..5e94418d5fe0 100644
--- a/llvm/include/llvm/CodeGen/MIRPrinter.h
+++ b/llvm/include/llvm/CodeGen/MIRPrinter.h
@@ -34,7 +34,7 @@ void printMIR(raw_ostream , const MachineFunction );
 /// you the correct list of successor blocks in most cases except for things
 /// like jump tables where the basic block references can't easily be found.
 /// The MIRPRinter will 

[clang] 3e00f24 - [NFC][Clang] add test comments for GitHub issue 58896

2023-03-06 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2023-03-06T11:55:39-08:00
New Revision: 3e00f24f6356cb351b969bc7414546c2d220e059

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

LOG: [NFC][Clang] add test comments for GitHub issue 58896

Per discussions with @erichkeane.

Added: 


Modified: 
clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp

Removed: 




diff  --git a/clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp 
b/clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
index d6e6d73d05ed5..55626edddf20d 100644
--- a/clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
+++ b/clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
@@ -89,6 +89,10 @@ void f() {
   Y3 c;
 }
 
+// Per [temp.func.order]p6.2.2, specifically "if the function parameters that
+// positionally correspond between the two templates are not of the same type",
+// this partial specialization does not work.
+// See https://github.com/llvm/llvm-project/issues/58896
 template struct Y4; // expected-note {{template is declared here}}
 template struct Y4; // expected-error {{class template partial 
specialization is not more specialized than the primary template}}
 



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


[clang] 7f8d844 - [CodeGen] guarantee variable templates are initialized in the reverse instantiation order

2023-03-05 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2023-03-05T15:31:23-08:00
New Revision: 7f8d844df5e91f8f689d0e9658e811d21bc4a605

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

LOG: [CodeGen] guarantee variable templates are initialized in the reverse 
instantiation order

Following up D127259.

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

Added: 
clang/test/CodeGenCXX/static-init-variable-template.cpp

Modified: 
clang/lib/Sema/SemaExpr.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index c3e2b6fdeaf1f..56abde04eaf0d 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -19888,16 +19888,11 @@ static void DoMarkVarDeclReferenced(
   DRE->setDecl(DRE->getDecl());
 else if (auto *ME = dyn_cast_or_null(E))
   ME->setMemberDecl(ME->getMemberDecl());
-  } else if (FirstInstantiation ||
- isa(Var)) {
-// FIXME: For a specialization of a variable template, we don't
-// distinguish between "declaration and type implicitly instantiated"
-// and "implicit instantiation of definition requested", so we have
-// no direct way to avoid enqueueing the pending instantiation
-// multiple times.
+  } else if (FirstInstantiation) {
 SemaRef.PendingInstantiations
 .push_back(std::make_pair(Var, PointOfInstantiation));
   } else {
+bool Inserted = false;
 for (auto  : SemaRef.SavedPendingInstantiations) {
   auto Iter = llvm::find_if(
   I, [Var](const Sema::PendingImplicitInstantiation ) {
@@ -19906,9 +19901,19 @@ static void DoMarkVarDeclReferenced(
   if (Iter != I.end()) {
 SemaRef.PendingInstantiations.push_back(*Iter);
 I.erase(Iter);
+Inserted = true;
 break;
   }
 }
+
+// FIXME: For a specialization of a variable template, we don't
+// distinguish between "declaration and type implicitly instantiated"
+// and "implicit instantiation of definition requested", so we have
+// no direct way to avoid enqueueing the pending instantiation
+// multiple times.
+if (isa(Var) && !Inserted)
+  SemaRef.PendingInstantiations
+.push_back(std::make_pair(Var, PointOfInstantiation));
   }
 }
   }

diff  --git a/clang/test/CodeGenCXX/static-init-variable-template.cpp 
b/clang/test/CodeGenCXX/static-init-variable-template.cpp
new file mode 100644
index 0..672ab11059a30
--- /dev/null
+++ b/clang/test/CodeGenCXX/static-init-variable-template.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -std=c++14 -S -emit-llvm -disable-llvm-passes -o - %s 
-triple x86_64-linux-gnu | FileCheck %s
+
+template int Fib = Fib + Fib;
+template<> int Fib<0> = 0;
+template<> int Fib<1> = 1;
+int f = Fib<5>;
+
+template int Fib2 = Fib2 + Fib2;
+template<> int Fib2<0> = 0;
+template<> int Fib2<1> = 1;
+int f2 = Fib2<5>;
+
+// CHECK: @llvm.global_ctors = appending global [9 x { i32, ptr, ptr }] [
+// CHECK-SAME: { i32, ptr, ptr } { i32 65535, ptr @__cxx_global_var_init.4, 
ptr @_Z3FibILi2EE },
+// CHECK-SAME: { i32, ptr, ptr } { i32 65535, ptr @__cxx_global_var_init.3, 
ptr @_Z3FibILi3EE },
+// CHECK-SAME: { i32, ptr, ptr } { i32 65535, ptr @__cxx_global_var_init.5, 
ptr @_Z3FibILi4EE },
+// CHECK-SAME: { i32, ptr, ptr } { i32 65535, ptr @__cxx_global_var_init.2,  
ptr @_Z3FibILi5EE },
+// CHECK-SAME: { i32, ptr, ptr } { i32 65535, ptr @__cxx_global_var_init.8, 
ptr @_Z4Fib2ILi2EE },
+// CHECK-SAME: { i32, ptr, ptr } { i32 65535, ptr @__cxx_global_var_init.9, 
ptr @_Z4Fib2ILi3EE },
+// CHECK-SAME: { i32, ptr, ptr } { i32 65535, ptr @__cxx_global_var_init.7,  
ptr @_Z4Fib2ILi4EE },
+// CHECK-SAME: { i32, ptr, ptr } { i32 65535, ptr @__cxx_global_var_init.6, 
ptr @_Z4Fib2ILi5EE },
+// CHECK-SAME: { i32, ptr, ptr } { i32 65535, ptr 
@_GLOBAL__sub_I_static_init_variable_template.cpp, ptr null }



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


[clang] e423885 - [CodeGen] guarantee templated static variables are initialized in the reverse instantiation order

2023-03-03 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2023-03-03T00:12:28-08:00
New Revision: e423885e272c0e57c6d240d07bc934e0a8649417

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

LOG: [CodeGen] guarantee templated static variables are initialized in the 
reverse instantiation order

Based on Richard's suggestion in D126341:
`If we can actually describe a rule that we provide for initialization
order of instantiated variables, and we can easily implement that rule
and be confident we won't want to substantially weaken it later, and we
can thereby assure our users that we will satisfy that rule, then I
think that could be interesting, but anything less than that doesn't
seem worthwhile to me.`

I'm giving it try here. IMHO the implementation is pretty simple and
does not change behavior for unrelated constructs like the timing when
instantiated variables are passed to CodeGen.

This is based on the same ordering guarantee needed for inline variables 
D127233.
To provide this guarantee, we also need to
emit DeferredDeclsToEmit in the DFS order. 
https://github.com/llvm/llvm-project/commit/e5df59ff78faebd897e81907606ce6074aac0df6
originally supported this but it is not exactly DFS order for cases like
the one in cwg362. For the example of Fib<5>, it triggers the instantiation
of Fib<4> and Fib<3>. However, due to the way GlobalEagerInstantiationScope
is implemented, Fib<4> does not actually trigger Fib<3> instantiation
since it is already triggered by Fib<5>. This breaks the guarantee.

This patch makes sure DeferredDeclsToEmit is emitted in DFS order by moving
DeferredDeclsToEmit storage from the call stack to an explicit stack-like
data structure. Then the DFS order could be enforced.

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

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaExpr.cpp
clang/test/CodeGenCXX/static-member-variable-explicit-specialization.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 60fed8603ec55..d1342876f85dc 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9847,14 +9847,21 @@ class Sema final {
   /// eagerly.
   SmallVector LateParsedInstantiations;
 
+  SmallVector, 8> SavedVTableUses;
+  SmallVector, 8>
+  SavedPendingInstantiations;
+
   class GlobalEagerInstantiationScope {
   public:
 GlobalEagerInstantiationScope(Sema , bool Enabled)
 : S(S), Enabled(Enabled) {
   if (!Enabled) return;
 
-  SavedPendingInstantiations.swap(S.PendingInstantiations);
-  SavedVTableUses.swap(S.VTableUses);
+  S.SavedPendingInstantiations.emplace_back();
+  S.SavedPendingInstantiations.back().swap(S.PendingInstantiations);
+
+  S.SavedVTableUses.emplace_back();
+  S.SavedVTableUses.back().swap(S.VTableUses);
 }
 
 void perform() {
@@ -9870,26 +9877,28 @@ class Sema final {
   // Restore the set of pending vtables.
   assert(S.VTableUses.empty() &&
  "VTableUses should be empty before it is discarded.");
-  S.VTableUses.swap(SavedVTableUses);
+  S.VTableUses.swap(S.SavedVTableUses.back());
+  S.SavedVTableUses.pop_back();
 
   // Restore the set of pending implicit instantiations.
   if (S.TUKind != TU_Prefix || !S.LangOpts.PCHInstantiateTemplates) {
 assert(S.PendingInstantiations.empty() &&
"PendingInstantiations should be empty before it is 
discarded.");
-S.PendingInstantiations.swap(SavedPendingInstantiations);
+S.PendingInstantiations.swap(S.SavedPendingInstantiations.back());
+S.SavedPendingInstantiations.pop_back();
   } else {
 // Template instantiations in the PCH may be delayed until the TU.
-S.PendingInstantiations.swap(SavedPendingInstantiations);
-S.PendingInstantiations.insert(S.PendingInstantiations.end(),
-   SavedPendingInstantiations.begin(),
-   SavedPendingInstantiations.end());
+S.PendingInstantiations.swap(S.SavedPendingInstantiations.back());
+S.PendingInstantiations.insert(
+S.PendingInstantiations.end(),
+S.SavedPendingInstantiations.back().begin(),
+S.SavedPendingInstantiations.back().end());
+S.SavedPendingInstantiations.pop_back();
   }
 }
 
   private:
 Sema 
-SmallVector SavedVTableUses;
-std::deque SavedPendingInstantiations;
 bool Enabled;
   };
 

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 3207f42aad63c..c3e2b6fdeaf1f 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -19897,6 +19897,18 @@ static void DoMarkVarDeclReferenced(
 // 

[clang] 40e9947 - [Clang] follow-up D128745, remove ClangABICompat checks

2022-11-02 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-11-02T16:33:10-07:00
New Revision: 40e99473170f5045e0b5f2cafabd2a1be8c7ec26

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

LOG: [Clang] follow-up D128745, remove ClangABICompat checks

Per discussions in D128745, remove ClangABICompat checks for implementations
of DR692/DR1395/DR1432. This is a potentially breaking changes, so the release
note is updated accordingly.

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaTemplateDeduction.cpp

Removed: 
clang/test/CodeGen/partial-order-variadic.cpp
clang/test/SemaCXX/pre-dr692.cpp



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1198926974bff..435d9ded7c72e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -161,6 +161,21 @@ code bases.
 - The ``-fexperimental-new-pass-manager`` and ``-fno-legacy-pass-manager``
   flags have been removed. These have been no-ops since 15.0.0.
 
+- As a side effect of implementing DR692/DR1395/DR1432, Clang now rejects some
+  overloaded function templates as ambiguous when one of the candidates has a
+  trailing parameter pack.
+
+  .. code-block:: c++
+
+template  void g(T, T = T());
+template  void g(T, U...);
+void h() {
+  // This is rejected due to ambiguity between the pack and the
+  // default argument. Only parameters with arguments are considered during
+  // partial ordering of function templates.
+  g(42);
+}
+
 What's New in Clang |release|?
 ==
 Some of the major new features and improvements to Clang are listed
@@ -551,10 +566,10 @@ C2x Feature Support
 
 C++ Language Changes in Clang
 -
-- Implemented DR692, DR1395 and DR1432. Use the ``-fclang-abi-compat=15`` 
option
-  to get the old partial ordering behavior regarding packs. Note that the fix 
for
-  DR1432 is speculative that there is no wording or even resolution for this 
issue.
-  A speculative fix for DR1432 is needed because it fixes regressions caused 
by DR692.
+- Implemented `DR692 `_, `DR1395 
`_,
+  and `DR1432 `_. The fix for DR1432 is speculative 
since the
+  issue is still open and has no proposed resolution at this time. A 
speculative fix
+  for DR1432 is needed to prevent regressions that would otherwise occur due 
to DR692.
 - Clang's default C++/ObjC++ standard is now ``gnu++17`` instead of 
``gnu++14``.
   This means Clang will by default accept code using features from C++17 and
   conforming GNU extensions. Projects incompatible with C++17 can add

diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 17c0e2f04f4bd..3db06a51e4eb7 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -1128,9 +1128,7 @@ DeduceTemplateArguments(Sema ,
   // During partial ordering, if Ai was originally a function parameter pack:
   // - if P does not contain a function parameter type corresponding to Ai then
   //   Ai is ignored;
-  bool ClangABICompat15 = S.Context.getLangOpts().getClangABICompat() <=
-  LangOptions::ClangABI::Ver15;
-  if (!ClangABICompat15 && PartialOrdering && ArgIdx + 1 == NumArgs &&
+  if (PartialOrdering && ArgIdx + 1 == NumArgs &&
   isa(Args[ArgIdx]))
 return Sema::TDK_Success;
 
@@ -2466,9 +2464,6 @@ static bool isSameTemplateArg(ASTContext ,
   if (X.getKind() != Y.getKind())
 return false;
 
-  bool ClangABICompat15 =
-  Context.getLangOpts().getClangABICompat() <= 
LangOptions::ClangABI::Ver15;
-
   switch (X.getKind()) {
 case TemplateArgument::Null:
   llvm_unreachable("Comparing NULL template argument");
@@ -2500,45 +2495,33 @@ static bool isSameTemplateArg(ASTContext ,
   return XID == YID;
 }
 
-case TemplateArgument::Pack:
-  if (ClangABICompat15) {
-if (X.pack_size() != Y.pack_size())
+case TemplateArgument::Pack: {
+  unsigned PackIterationSize = X.pack_size();
+  if (X.pack_size() != Y.pack_size()) {
+if (!PartialOrdering)
   return false;
 
-for (TemplateArgument::pack_iterator XP = X.pack_begin(),
- XPEnd = X.pack_end(),
- YP = Y.pack_begin();
- XP != XPEnd; ++XP, ++YP)
-  if (!isSameTemplateArg(Context, *XP, *YP, PartialOrdering,
- PackExpansionMatchesPack))
-return false;
-  } else {
-unsigned PackIterationSize = X.pack_size();
-if 

[clang] e18c2c5 - [Clang] use non-instantiated function declaration for constraints partial ordering

2022-10-30 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-10-30T22:39:47-07:00
New Revision: e18c2c5548f6864def4a110239395a18afc195d6

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

LOG: [Clang] use non-instantiated function declaration for constraints partial 
ordering

Per wordings in
- https://eel.is/c++draft/over.match#best.general-2.6
- https://eel.is/c++draft/temp.constr.order
- https://eel.is/c++draft/temp.constr#atomic-1

constraints partial ordering should use the unsubstituted template
parameters of the constrained entity, not the instantiated entity.

Fix #56154

Reviewed By: erichkeane, royjacobson, mizvekov

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

Added: 
clang/test/CXX/temp/temp.constr/temp.constr.order/non-template-functions.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaConcept.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaOverload.cpp
clang/test/CXX/over/over.match/over.match.best/p2.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index bd4c0bf7fa0c0..641f75eeeb64c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -264,6 +264,8 @@ Bug Fixes
   constraint, which re-evaluated the same constraint.
   `Issue 53213 `_
   `Issue 45736 `_
+- Fix an issue when performing constraints partial ordering on non-template
+  functions. `Issue 56154 `_
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index d3d87c8354aea..54d8a746fa247 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -1300,6 +1300,18 @@ bool Sema::IsAtLeastAsConstrained(NamedDecl *D1,
   NamedDecl *D2,
   MutableArrayRef AC2,
   bool ) {
+  if (const auto *FD1 = dyn_cast(D1)) {
+auto IsExpectedEntity = [](const FunctionDecl *FD) {
+  FunctionDecl::TemplatedKind Kind = FD->getTemplatedKind();
+  return Kind == FunctionDecl::TK_NonTemplate ||
+ Kind == FunctionDecl::TK_FunctionTemplate;
+};
+const auto *FD2 = dyn_cast(D2);
+assert(IsExpectedEntity(FD1) && FD2 && IsExpectedEntity(FD2) &&
+   "use non-instantiated function declaration for constraints partial "
+   "ordering");
+  }
+
   if (AC1.empty()) {
 Result = AC2.empty();
 return false;

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 686a126968e8a..a164d9af8f34a 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -18218,13 +18218,20 @@ static void SetEligibleMethods(Sema , CXXRecordDecl 
*Record,
 if (!SatisfactionStatus[i])
   continue;
 CXXMethodDecl *Method = Methods[i];
-const Expr *Constraints = Method->getTrailingRequiresClause();
+CXXMethodDecl *OrigMethod = Method;
+if (FunctionDecl *MF = OrigMethod->getInstantiatedFromMemberFunction())
+  OrigMethod = cast(MF);
+
+const Expr *Constraints = OrigMethod->getTrailingRequiresClause();
 bool AnotherMethodIsMoreConstrained = false;
 for (size_t j = 0; j < Methods.size(); j++) {
   if (i == j || !SatisfactionStatus[j])
 continue;
   CXXMethodDecl *OtherMethod = Methods[j];
-  if (!AreSpecialMemberFunctionsSameKind(S.Context, Method, OtherMethod,
+  if (FunctionDecl *MF = OtherMethod->getInstantiatedFromMemberFunction())
+OtherMethod = cast(MF);
+
+  if (!AreSpecialMemberFunctionsSameKind(S.Context, OrigMethod, 
OtherMethod,
  CSM))
 continue;
 
@@ -18235,7 +18242,7 @@ static void SetEligibleMethods(Sema , CXXRecordDecl 
*Record,
 AnotherMethodIsMoreConstrained = true;
 break;
   }
-  if (S.IsAtLeastAsConstrained(OtherMethod, {OtherConstraints}, Method,
+  if (S.IsAtLeastAsConstrained(OtherMethod, {OtherConstraints}, OrigMethod,
{Constraints},
AnotherMethodIsMoreConstrained)) {
 // There was an error with the constraints comparison. Exit the loop

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index d21de7db3f53b..45bca3a31d3a7 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -10039,13 +10039,20 @@ bool clang::isBetterOverloadCandidate(
   //  parameter-type-lists, and F1 is more constrained than F2 [...],
   if (!Cand1IsSpecialization && !Cand2IsSpecialization &&
   sameFunctionParameterTypeLists(S, 

[clang] 5d086cc - [Clang] perform "maximum TLS alignment" check for template instantiation

2022-10-30 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-10-30T22:39:47-07:00
New Revision: 5d086cce8b92680a2cdadf1f07d4267cd374122e

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

LOG: [Clang] perform "maximum TLS alignment" check for template instantiation

follow up 
https://github.com/llvm/llvm-project/commit/d30e2eefc3cf8dfd2210aefd62f13a6e7c011b43

Reviewed By: mizvekov

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

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/Sema/tls_alignment.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index b32dfe158c8f3..23b4e3f60cef1 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3013,6 +3013,7 @@ class Sema final {
   void SetDeclDeleted(Decl *dcl, SourceLocation DelLoc);
   void SetDeclDefaulted(Decl *dcl, SourceLocation DefaultLoc);
   void CheckStaticLocalForDllExport(VarDecl *VD);
+  void CheckThreadLocalForLargeAlignment(VarDecl *VD);
   void FinalizeDeclaration(Decl *D);
   DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec ,
  ArrayRef Group);

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 19bd670e791bc..686a126968e8a 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -14032,6 +14032,26 @@ void Sema::CheckStaticLocalForDllExport(VarDecl *VD) {
   }
 }
 
+void Sema::CheckThreadLocalForLargeAlignment(VarDecl *VD) {
+  assert(VD->getTLSKind());
+
+  // Perform TLS alignment check here after attributes attached to the variable
+  // which may affect the alignment have been processed. Only perform the check
+  // if the target has a maximum TLS alignment (zero means no constraints).
+  if (unsigned MaxAlign = Context.getTargetInfo().getMaxTLSAlign()) {
+// Protect the check so that it's not performed on dependent types and
+// dependent alignments (we can't determine the alignment in that case).
+if (!VD->hasDependentAlignment()) {
+  CharUnits MaxAlignChars = Context.toCharUnitsFromBits(MaxAlign);
+  if (Context.getDeclAlign(VD) > MaxAlignChars) {
+Diag(VD->getLocation(), diag::err_tls_var_aligned_over_maximum)
+<< (unsigned)Context.getDeclAlign(VD).getQuantity() << VD
+<< (unsigned)MaxAlignChars.getQuantity();
+  }
+}
+  }
+}
+
 /// FinalizeDeclaration - called by ParseDeclarationAfterDeclarator to perform
 /// any semantic actions necessary after any initializer has been attached.
 void Sema::FinalizeDeclaration(Decl *ThisDecl) {
@@ -14075,25 +14095,12 @@ void Sema::FinalizeDeclaration(Decl *ThisDecl) {
 
   checkAttributesAfterMerging(*this, *VD);
 
-  // Perform TLS alignment check here after attributes attached to the variable
-  // which may affect the alignment have been processed. Only perform the check
-  // if the target has a maximum TLS alignment (zero means no constraints).
-  if (unsigned MaxAlign = Context.getTargetInfo().getMaxTLSAlign()) {
-// Protect the check so that it's not performed on dependent types and
-// dependent alignments (we can't determine the alignment in that case).
-if (VD->getTLSKind() && !VD->hasDependentAlignment()) {
-  CharUnits MaxAlignChars = Context.toCharUnitsFromBits(MaxAlign);
-  if (Context.getDeclAlign(VD) > MaxAlignChars) {
-Diag(VD->getLocation(), diag::err_tls_var_aligned_over_maximum)
-  << (unsigned)Context.getDeclAlign(VD).getQuantity() << VD
-  << (unsigned)MaxAlignChars.getQuantity();
-  }
-}
-  }
-
   if (VD->isStaticLocal())
 CheckStaticLocalForDllExport(VD);
 
+  if (VD->getTLSKind())
+CheckThreadLocalForLargeAlignment(VD);
+
   // Perform check for initializers of device-side global variables.
   // CUDA allows empty constructors as initializers (see E.2.3.1, CUDA
   // 7.5). We must also apply the same checks to all __shared__

diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index d8dd1ab8e1d17..da9aa611793f9 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -4341,7 +4341,7 @@ void Sema::AddAlignedAttr(Decl *D, const 
AttributeCommonInfo , Expr *E,
   }
 
   const auto *VD = dyn_cast(D);
-  if (VD && Context.getTargetInfo().isTLSSupported()) {
+  if (VD) {
 unsigned MaxTLSAlign =
 Context.toCharUnitsFromBits(Context.getTargetInfo().getMaxTLSAlign())
 .getQuantity();

diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index e034094431bb7..49be412df64c0 100644
--- 

[clang] c9447c6 - [Clang] fold expression is considered atomic during constraints normalization

2022-10-22 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-10-22T20:48:57-07:00
New Revision: c9447c62966e5ec60ec277e4a7d75420224f53f6

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

LOG: [Clang] fold expression is considered atomic during constraints 
normalization

`|| fold` is not disjunction; `&& fold` is not conjunction. Both are atomic per
current wording. See http://cplusplus.github.io/concepts-ts/ts-active.html#28.

D128750 accidentally tried to partially addresss this which is not desirable.
This patch reverts that part and associated test cases.

Added: 


Modified: 
clang/lib/Sema/SemaConcept.cpp
clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 9809ccb2ccc00..484c02498f20b 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -1110,14 +1110,8 @@ NormalizedConstraint::fromConstraintExpr(Sema , 
NamedDecl *D, const Expr *E) {
 
   // C++2a [temp.param]p4:
   // [...] If T is not a pack, then E is E', otherwise E is (E' && ...).
-  //
-  // Using the pattern suffices because the partial ordering rules guarantee
-  // the template paramaters are equivalent.
-  if (auto *FoldE = dyn_cast(E)) {
-assert(FoldE->isRightFold() && FoldE->getOperator() == BO_LAnd);
-assert(E->IgnoreParenImpCasts() == E);
-E = FoldE->getPattern();
-  }
+  // Fold expression is considered atomic constraints per current wording.
+  // See http://cplusplus.github.io/concepts-ts/ts-active.html#28
 
   if (LogicalBinOp BO = E) {
 auto LHS = fromConstraintExpr(S, D, BO.getLHS());

diff  --git a/clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp 
b/clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
index bdd1c376243bb..d6e6d73d05ed5 100644
--- a/clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
+++ b/clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
@@ -44,23 +44,8 @@ template
 void foo(T, U);
 
-// check auto template parameter pack.
-template class U,
- C auto... Z>
-void foo2(T, U) = delete;
-template class U,
- D auto... Z>
-void foo2(T, U) = delete;
-template class U,
- E auto... Z>
-void foo2(T, U);
-
 void bar(S s, S2 s2) {
   foo(0, s);
-  foo2(0, s2);
 }
 
 template void bar2();
@@ -110,8 +95,9 @@ template struct Y4; // expected-error 
{{class template partial s
 template struct W1;
 template struct W1 {};
 
-template struct W2;
-template struct W2 {};
+// See http://cplusplus.github.io/concepts-ts/ts-active.html#28
+// template struct W2;
+// template struct W2 {};
 
 template
 concept C1 = C && C;
@@ -121,8 +107,9 @@ concept D1 = D && C;
 template auto T> struct W3;
 template auto T> struct W3 {};
 
-template auto... T> struct W4;
-template auto... T> struct W4 {};
+// See http://cplusplus.github.io/concepts-ts/ts-active.html#28
+// template auto... T> struct W4;
+// template auto... T> struct W4 {};
 
 // FIXME: enable once Clang support non-trivial auto on NTTP.
 // template struct W5;
@@ -133,9 +120,9 @@ template auto... T> struct W4 {};
 // template struct W6 {};
 
 struct W1<0> w1;
-struct W2<0> w2;
+// struct W2<0> w2;
 struct W3<0> w3;
-struct W4<0> w4;
+// struct W4<0> w4;
 // FIXME: enable once Clang support non-trivial auto on NTTP.
 // struct W5<(int*)nullptr> w5;
 // struct W6 w6;



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


[clang] 13d6a57 - [Clang] constraints partial ordering should work with deduction guide

2022-10-18 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-10-18T17:30:47-07:00
New Revision: 13d6a57cbe2776c4873302c0cf04e27b77bd2862

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

LOG: [Clang] constraints partial ordering should work with deduction guide

D128750 incorrectly skips constraints partial ordering for deduction guide.
This patch reverts that part.

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

Added: 
clang/test/SemaTemplate/deduction-guide-partial-ordering.cpp

Modified: 
clang/lib/Sema/SemaTemplateDeduction.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 00b1cf1224e2..0572a663561c 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -5243,8 +5243,7 @@ FunctionTemplateDecl *Sema::getMoreSpecializedTemplate(
 }
   }
 
-  if (!Context.getLangOpts().CPlusPlus20 || isa(FD1) ||
-  isa(FD2))
+  if (!Context.getLangOpts().CPlusPlus20)
 return nullptr;
 
   // Match GCC on not implementing [temp.func.order]p6.2.1.

diff  --git a/clang/test/SemaTemplate/deduction-guide-partial-ordering.cpp 
b/clang/test/SemaTemplate/deduction-guide-partial-ordering.cpp
new file mode 100644
index ..4f57d07a850d
--- /dev/null
+++ b/clang/test/SemaTemplate/deduction-guide-partial-ordering.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+// expected-no-diagnostics
+
+namespace pr58456 {
+  template
+  struct s {
+constexpr s(auto) {
+}
+  };
+
+  template
+  s(T) -> s;
+
+  template requires true
+  s(T) -> s;
+
+  void f() {
+auto const y = s(0);
+  }
+}



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


[clang] 340eac0 - [C++20] Implement P2113R0: Changes to the Partial Ordering of Constrained Functions

2022-10-18 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-10-18T11:58:57-07:00
New Revision: 340eac01f7dad6c24cee35dd35f2484098dd6b1a

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

LOG: [C++20] Implement P2113R0: Changes to the Partial Ordering of Constrained 
Functions

This implementation matches GCC behavior in that [[ 
https://eel.is/c++draft/temp.func.order#6.2.1 | temp.func.order p6.2.1 ]] is 
not implemented [1]. I reached out to the GCC author to confirm that some 
changes elsewhere to overload resolution are probably needed, but no solution 
has been developed sufficiently [3].

Most of the wordings are implemented straightforwardly. However,
for [[ https://eel.is/c++draft/temp.func.order#6.2.2 | temp.func.order p6.2.2 
]] "... or if the function parameters that positionally correspond between the 
two templates are not of the same type", the "same type" is not very clear ([2] 
is a bug related to this). Here is a quick example
```
template int f(T, U);
template  int f(U, T);

int x = f(0, 0);
```
Is the `U` and `T` from different `f`s the "same type"? The answer is NO even 
though both `U` and `T` are deduced to be `int` in this case. The reason is 
that `U` and `T` are dependent types, according to [[ 
https://eel.is/c++draft/temp.over.link#3 |  temp.over.link p3 ]], they can not 
be the "same type".

To check if two function parameters are the "same type":
* For //function template//: compare the function parameter canonical types and 
return type between two function templates.
* For //class template/partial specialization//: by [[ 
https://eel.is/c++draft/temp.spec.partial.order#1.2 | temp.spec.partial.order 
p1.2 ]], compare the injected template arguments between two templates using 
hashing(TemplateArgument::Profile) is enough.

[1] 
https://gcc.gnu.org/git/gitweb.cgi?p=gcc.git;h=57b4daf8dc4ed7b669cc70638866ddb00f5b7746
[2] https://github.com/llvm/llvm-project/issues/49308
[3] https://lists.isocpp.org/core/2020/06/index.php#msg9392

Fixes https://github.com/llvm/llvm-project/issues/54039
Fixes https://github.com/llvm/llvm-project/issues/49308 (PR49964)

Reviewed By: royjacobson, #clang-language-wg, mizvekov

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/DeclTemplate.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/DeclTemplate.cpp
clang/lib/Sema/SemaConcept.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9fe63dd5de840..cb704266df407 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -534,6 +534,9 @@ C++20 Feature Support
   which removes the requirement for the ``typename`` keyword in certain 
contexts.
 - Implemented The Equality Operator You Are Looking For (`P2468 
`_).
 
+- Implemented `P2113R0: Proposed resolution for 2019 comment CA 112 
`_
+  ([temp.func.order]p6.2.1 is not implemented, matching GCC).
+
 C++2b Feature Support
 ^
 

diff  --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index 5cd1de4d24132..ae10744383559 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -847,6 +847,15 @@ class RedeclarableTemplateDecl : public TemplateDecl,
 /// The first value in the array is the number of specializations/partial
 /// specializations that follow.
 uint32_t *LazySpecializations = nullptr;
+
+/// The set of "injected" template arguments used within this
+/// template.
+///
+/// This pointer refers to the template arguments (there are as
+/// many template arguments as template parameaters) for the
+/// template, and is allocated lazily, since most templates do not
+/// require the use of this information.
+TemplateArgument *InjectedArgs = nullptr;
   };
 
   /// Pointer to the common data shared by all declarations of this
@@ -954,6 +963,14 @@ class RedeclarableTemplateDecl : public TemplateDecl,
 getCommonPtr()->InstantiatedFromMember.setPointer(TD);
   }
 
+  /// Retrieve the "injected" template arguments that correspond to the
+  /// template parameters of this template.
+  ///
+  /// Although the C++ standard has no notion of the "injected" template
+  /// arguments for a template, the notion is convenient when
+  /// we need to perform substitutions inside the definition of a template.
+  ArrayRef 

[clang] 6bca52b - [Clang] update cxx_dr_status.html by running make_cxx_dr_status

2022-10-18 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-10-18T11:45:40-07:00
New Revision: 6bca52be03491e796e82dd51133f29e2b7bda148

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

LOG: [Clang] update cxx_dr_status.html by running make_cxx_dr_status

For https://github.com/llvm/llvm-project/issues/58382

Reviewed By: erichkeane

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

Added: 


Modified: 
clang/test/CXX/drs/dr25xx.cpp
clang/test/CXX/drs/dr2xx.cpp
clang/www/cxx_dr_status.html
clang/www/make_cxx_dr_status

Removed: 




diff  --git a/clang/test/CXX/drs/dr25xx.cpp b/clang/test/CXX/drs/dr25xx.cpp
index 37b8dea188b60..a0b947b8d58ed 100644
--- a/clang/test/CXX/drs/dr25xx.cpp
+++ b/clang/test/CXX/drs/dr25xx.cpp
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify
 
-namespace dr2565 { // dr252: 16
+namespace dr2565 { // dr2565: 16
   template
 concept C = requires (typename T::type x) {
   x + 1;

diff  --git a/clang/test/CXX/drs/dr2xx.cpp b/clang/test/CXX/drs/dr2xx.cpp
index 580e496857bd7..c76b65ddeef56 100644
--- a/clang/test/CXX/drs/dr2xx.cpp
+++ b/clang/test/CXX/drs/dr2xx.cpp
@@ -243,7 +243,7 @@ namespace dr222 { // dr222: dup 637
 
 // dr223: na
 
-namespace dr224 { // dr224: yes
+namespace dr224 { // dr224: 16
   namespace example1 {
 template  class A {
   typedef int type;

diff  --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 0289372644056..24beb7fc88b65 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -1383,7 +1383,7 @@ C++ defect report implementation 
status
 https://wg21.link/cwg224;>224
 CD1
 Definition of dependent names
-No
+Clang 16
   
   
 https://wg21.link/cwg225;>225
@@ -7650,7 +7650,7 @@ C++ defect report implementation 
status
 https://wg21.link/cwg1307;>1307
 C++14
 Overload resolution based on size of array initializer-list
-Clang 14
+Clang 14
   
   
 https://wg21.link/cwg1308;>1308
@@ -8172,7 +8172,7 @@ C++ defect report implementation 
status
 https://wg21.link/cwg1394;>1394
 CD3
 Incomplete types as parameters of deleted functions
-Clang 15
+Clang 15
   
   
 https://wg21.link/cwg1395;>1395
@@ -8400,7 +8400,7 @@ C++ defect report implementation 
status
 https://wg21.link/cwg1432;>1432
 open
 Newly-ambiguous variadic template expansions
-Not resolved
+Clang 16
   
   
 https://wg21.link/cwg1433;>1433
@@ -10380,7 +10380,7 @@ C++ defect report implementation 
status
 https://wg21.link/cwg1762;>1762
 C++14
 Reserved identifier used in literal-operator-id example
-Clang 14
+Clang 14
   
   
 https://wg21.link/cwg1763;>1763
@@ -10440,7 +10440,7 @@ C++ defect report implementation 
status
 https://wg21.link/cwg1772;>1772
 C++14
 __func__ in a lambda body
-Clang 14
+Clang 14
   
   
 https://wg21.link/cwg1773;>1773
@@ -10482,7 +10482,7 @@ C++ defect report implementation 
status
 https://wg21.link/cwg1779;>1779
 CD4
 Type dependency of __func__
-Clang 14
+Clang 14
   
   
 https://wg21.link/cwg1780;>1780
@@ -12834,7 +12834,7 @@ C++ defect report implementation 
status
 https://wg21.link/cwg2171;>2171
 CD4
 Triviality of copy constructor with less-qualified parameter
-Clang 15
+Clang 15
   
   
 https://wg21.link/cwg2172;>2172
@@ -13932,7 +13932,7 @@ C++ defect report implementation 
status
 https://wg21.link/cwg2354;>2354
 CD5
 Extended alignment and object representation
-Clang 15
+Clang 15
   
   
 https://wg21.link/cwg2355;>2355
@@ -14172,7 +14172,7 @@ C++ defect report implementation 
status
 https://wg21.link/cwg2394;>2394
 CD5
 Const-default-constructible for members
-Clang 15
+Clang 15
   
   
 https://wg21.link/cwg2395;>2395
@@ -15198,7 +15198,7 @@ C++ defect report implementation 
status
 https://wg21.link/cwg2565;>2565
 open
 Invalid types in the parameter-declaration-clause of a 
requires-expression
-Clang 16
+Clang 16
   
   
 https://wg21.link/cwg2566;>2566

diff  --git a/clang/www/make_cxx_dr_status b/clang/www/make_cxx_dr_status
index b02ccb724bde2..73cecb3afbc02 100755
--- a/clang/www/make_cxx_dr_status
+++ b/clang/www/make_cxx_dr_status
@@ -91,7 +91,7 @@ out_file.write('''\
 Available in Clang?
   ''')
 
-latest_release = 13
+latest_release = 15
 
 def availability(issue):
   status = status_map.get(issue, 'unknown')
@@ -158,7 +158,10 @@ for dr in drs:
 # This refers to the old ("C++0x") concepts feature, which was not part
 # of any C++ International Standard or Technical Specification.
 continue
-  if dr.status in ('open', 'concurrency', 'drafting', 

[clang] 4e2a629 - [Clang] add DR tests for D128745

2022-10-18 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-10-17T23:24:29-07:00
New Revision: 4e2a629c7238008de0ab45e6bb96aeaecac2bca9

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

LOG: [Clang] add DR tests for D128745

Added: 


Modified: 
clang/test/CXX/drs/dr13xx.cpp
clang/test/CXX/drs/dr14xx.cpp
clang/test/CXX/drs/dr6xx.cpp

Removed: 




diff  --git a/clang/test/CXX/drs/dr13xx.cpp b/clang/test/CXX/drs/dr13xx.cpp
index dc116f75b1aed..1a792f838e87c 100644
--- a/clang/test/CXX/drs/dr13xx.cpp
+++ b/clang/test/CXX/drs/dr13xx.cpp
@@ -457,6 +457,17 @@ Incomplete f(Incomplete) = delete; // well-formed
 #endif
 }
 
+namespace dr1395 { // dr1395: 16
+#if __cplusplus >= 201103L
+  template  void f(T, U...);
+  template  void f(T);
+  void h(int i) {
+// This is made ambiguous by dr692, but made valid again by dr1395.
+f();
+  }
+#endif
+}
+
 namespace dr1399 { // dr1399: dup 1388
   template void f(T..., int, T...) {} // expected-note 
{{candidate}} expected-error 0-1{{C++11}}
   void g() {

diff  --git a/clang/test/CXX/drs/dr14xx.cpp b/clang/test/CXX/drs/dr14xx.cpp
index 526211c0e0062..7d27d3b542443 100644
--- a/clang/test/CXX/drs/dr14xx.cpp
+++ b/clang/test/CXX/drs/dr14xx.cpp
@@ -36,6 +36,27 @@ namespace dr1423 { // dr1423: 11
 #endif
 }
 
+namespace dr1432 { // dr1432: 16
+#if __cplusplus >= 201103L
+  template T declval();
+
+  template 
+  struct common_type;
+
+  template 
+  struct common_type {
+   typedef decltype(true ? declval() : declval()) type;
+  };
+
+  template 
+  struct common_type {
+   typedef typename common_type::type, V...>::type 
type;
+  };
+
+  template struct common_type;
+#endif
+}
+
 namespace dr1443 { // dr1443: yes
 struct A {
   int i;

diff  --git a/clang/test/CXX/drs/dr6xx.cpp b/clang/test/CXX/drs/dr6xx.cpp
index 527379590bd39..494d857e829ae 100644
--- a/clang/test/CXX/drs/dr6xx.cpp
+++ b/clang/test/CXX/drs/dr6xx.cpp
@@ -1079,16 +1079,16 @@ namespace dr687 { // dr687 (9 c++20, but the issue is 
still considered open)
   }
 }
 
-namespace dr692 { // dr692: no
+namespace dr692 { // dr692: 16
   // Also see dr1395.
 
   namespace temp_func_order_example2 {
 template  struct A1 {}; // expected-error 0-1{{C++11}}
 template  struct A2 {}; // expected-error 
0-1{{C++11}}
-template  void e1(A1) = delete; // 
expected-error 0-2{{C++11}}
-template  void e1(A1);
-template  void e2(A2) = delete; // 
expected-error 0-2{{C++11}}
-template  void e2(A2);
+template  void e1(A1) = delete; // 
expected-error 0-2{{C++11}}
+template  void e1(A1);
+template  void e2(A2) = delete; // 
expected-error 0-2{{C++11}}
+template  void e2(A2);
 template  void f(U, A1 *p = 0) = delete; // 
expected-note {{candidate}} expected-error 0-1{{C++11}}
 template  int (U, A1 *p = 0); // expected-note 
{{candidate}}
 template  void g(T, T = T()); // expected-note {{candidate}}



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


[clang] 2c94f75 - [clang-format] update --files help description

2022-10-11 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-10-11T10:25:04-07:00
New Revision: 2c94f75f00af16b6b4c2336e5cbfd8187d8bf33c

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

LOG: [clang-format] update --files help description

correlates the option with reponse file concept.

Reviewed By: HazardyKnusperkeks

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

Added: 


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

Removed: 




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

diff  --git a/clang/tools/clang-format/ClangFormat.cpp 
b/clang/tools/clang-format/ClangFormat.cpp
index 269bc59506b2d..9e8b881c8fafe 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -125,9 +125,11 @@ static cl::opt QualifierAlignment(
  "determined by the QualifierAlignment style flag"),
 cl::init(""), cl::cat(ClangFormatCategory));
 
-static cl::opt
-Files("files", cl::desc("Provide a list of files to run clang-format"),
-  cl::init(""), cl::cat(ClangFormatCategory));
+static cl::opt Files(
+"files",
+cl::desc("A file containing a list of files to process, one per line."),
+cl::value_desc("filename"),
+cl::init(""), cl::cat(ClangFormatCategory));
 
 static cl::opt
 Verbose("verbose", cl::desc("If set, shows the list of processed files"),



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


[clang] 5d69937 - [Clang] make canonical AutoType constraints-free

2022-10-04 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-10-04T11:56:03-07:00
New Revision: 5d69937b9f9c8e102663c2edcbdbe5335858b215

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

LOG: [Clang] make canonical AutoType constraints-free

As @mizvekov suggested in D134772. This works great for D128750 when
dealing with AutoType's.

Reviewed By: mizvekov, erichkeane

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

Added: 


Modified: 
clang/lib/AST/ASTContext.cpp
clang/lib/AST/DeclTemplate.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/test/CXX/dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index d609fe8cbed09..461a108915c3a 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -696,7 +696,11 @@ 
ASTContext::CanonicalTemplateTemplateParm::Profile(llvm::FoldingSetNodeID ,
 if (const auto *NTTP = dyn_cast(*P)) {
   ID.AddInteger(1);
   ID.AddBoolean(NTTP->isParameterPack());
+  const Expr *TC = NTTP->getPlaceholderTypeConstraint();
+  ID.AddBoolean(TC != nullptr);
   ID.AddPointer(NTTP->getType().getCanonicalType().getAsOpaquePtr());
+  if (TC)
+TC->Profile(ID, C, /*Canonical=*/true);
   if (NTTP->isExpandedParameterPack()) {
 ID.AddBoolean(true);
 ID.AddInteger(NTTP->getNumExpansionTypes());
@@ -5751,9 +5755,6 @@ QualType ASTContext::getAutoTypeInternal(
   !TypeConstraintConcept && !IsDependent)
 return getAutoDeductType();
 
-  if (TypeConstraintConcept)
-TypeConstraintConcept = TypeConstraintConcept->getCanonicalDecl();
-
   // Look in the folding set for an existing type.
   void *InsertPos = nullptr;
   llvm::FoldingSetNodeID ID;
@@ -5764,20 +5765,15 @@ QualType ASTContext::getAutoTypeInternal(
 
   QualType Canon;
   if (!IsCanon) {
-if (DeducedType.isNull()) {
-  SmallVector CanonArgs;
-  bool AnyNonCanonArgs =
-  ::getCanonicalTemplateArguments(*this, TypeConstraintArgs, 
CanonArgs);
-  if (AnyNonCanonArgs) {
-Canon = getAutoTypeInternal(QualType(), Keyword, IsDependent, IsPack,
-TypeConstraintConcept, CanonArgs, true);
-// Find the insert position again.
-[[maybe_unused]] auto *Nothing =
-AutoTypes.FindNodeOrInsertPos(ID, InsertPos);
-assert(!Nothing && "canonical type broken");
-  }
-} else {
+if (!DeducedType.isNull()) {
   Canon = DeducedType.getCanonicalType();
+} else if (TypeConstraintConcept) {
+  Canon = getAutoTypeInternal(QualType(), Keyword, IsDependent, IsPack,
+  nullptr, {}, true);
+  // Find the insert position again.
+  [[maybe_unused]] auto *Nothing =
+  AutoTypes.FindNodeOrInsertPos(ID, InsertPos);
+  assert(!Nothing && "canonical type broken");
 }
   }
 
@@ -6333,7 +6329,9 @@ bool ASTContext::isSameTemplateParameter(const NamedDecl 
*X,
   if (auto *TX = dyn_cast(X)) {
 auto *TY = cast(Y);
 return TX->isParameterPack() == TY->isParameterPack() &&
-   TX->getASTContext().hasSameType(TX->getType(), TY->getType());
+   TX->getASTContext().hasSameType(TX->getType(), TY->getType()) &&
+   isSameConstraintExpr(TX->getPlaceholderTypeConstraint(),
+TY->getPlaceholderTypeConstraint());
   }
 
   auto *TX = cast(X);

diff  --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp
index 6bb5a493485ef..7159a87a69271 100644
--- a/clang/lib/AST/DeclTemplate.cpp
+++ b/clang/lib/AST/DeclTemplate.cpp
@@ -529,6 +529,9 @@ static void ProfileTemplateParameterList(ASTContext ,
   ID.AddInteger(0);
   ID.AddBoolean(NTTP->isParameterPack());
   NTTP->getType().getCanonicalType().Profile(ID);
+  ID.AddBoolean(NTTP->hasPlaceholderTypeConstraint());
+  if (const Expr *E = NTTP->getPlaceholderTypeConstraint())
+E->Profile(ID, C, /*Canonical=*/true);
   continue;
 }
 if (const auto *TTP = dyn_cast(D)) {

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 82171f64a1d7b..5cc5dc1c449a6 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -8666,10 +8666,11 @@ bool Sema::CheckExplicitlyDefaultedComparison(Scope *S, 
FunctionDecl *FD,
   // C++2a [class.spaceship]p2 [P2002R0]:
   //   Let R be the declared return type [...]. If R is auto, [...]. Otherwise,
   //   R shall not contain a placeholder type.
-  if (DCK == DefaultedComparisonKind::ThreeWay &&
-  FD->getDeclaredReturnType()->getContainedDeducedType() &&
-  !Context.hasSameType(FD->getDeclaredReturnType(),
-   

[clang] 1fb728e - [c++] implements tentative DR1432 for partial ordering of function template

2022-10-03 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-10-03T16:30:27-07:00
New Revision: 1fb728e95c74bf72698c00094f18fa8d2eb42cda

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

LOG: [c++] implements tentative DR1432 for partial ordering of function template

D128745 handled DR1432 for the partial ordering of partial specializations, but
missed the handling for the partial ordering of function templates. This patch
implements the latter. While at it, also simplifies the previous implementation 
to
be more close to the wording without functional changes.

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

Reviewed By: erichkeane, #clang-language-wg, mizvekov

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

Added: 
clang/test/SemaCXX/pre-dr692.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/test/CXX/drs/dr6xx.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2320f4a7a4fa..d113d9b450b7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -363,7 +363,9 @@ C2x Feature Support
 C++ Language Changes in Clang
 -
 - Implemented DR692, DR1395 and DR1432. Use the ``-fclang-abi-compat=15`` 
option
-  to get the old partial ordering behavior regarding packs.
+  to get the old partial ordering behavior regarding packs. Note that the fix 
for
+  DR1432 is speculative that there is no wording or even resolution for this 
issue.
+  A speculative fix for DR1432 is needed because it fixes regressions caused 
by DR692.
 - Clang's default C++/ObjC++ standard is now ``gnu++17`` instead of 
``gnu++14``.
   This means Clang will by default accept code using features from C++17 and
   conforming GNU extensions. Projects incompatible with C++17 can add

diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 6ddbd9055870..e3301081da55 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -5222,6 +5222,39 @@ FunctionTemplateDecl *Sema::getMoreSpecializedTemplate(
   return FT1;
   }
 
+  // This a speculative fix for CWG1432 (Similar to the fix for CWG1395) that
+  // there is no wording or even resolution for this issue.
+  bool ClangABICompat15 =
+  Context.getLangOpts().getClangABICompat() <= 
LangOptions::ClangABI::Ver15;
+  if (!ClangABICompat15) {
+for (int i = 0, e = std::min(NumParams1, NumParams2); i < e; ++i) {
+  QualType T1 = FD1->getParamDecl(i)->getType().getCanonicalType();
+  QualType T2 = FD2->getParamDecl(i)->getType().getCanonicalType();
+  auto *TST1 = dyn_cast(T1);
+  auto *TST2 = dyn_cast(T2);
+  if (!TST1 || !TST2)
+continue;
+  const TemplateArgument  = TST1->template_arguments().back();
+  if (TA1.getKind() == TemplateArgument::Pack) {
+assert(TST1->getNumArgs() == TST2->getNumArgs());
+const TemplateArgument  = TST2->template_arguments().back();
+assert(TA2.getKind() == TemplateArgument::Pack);
+unsigned PackSize1 = TA1.pack_size();
+unsigned PackSize2 = TA2.pack_size();
+bool IsPackExpansion1 =
+PackSize1 && TA1.pack_elements().back().isPackExpansion();
+bool IsPackExpansion2 =
+PackSize2 && TA2.pack_elements().back().isPackExpansion();
+if (PackSize1 != PackSize2 && IsPackExpansion1 != IsPackExpansion2) {
+  if (PackSize1 > PackSize2 && IsPackExpansion1)
+return FT2;
+  if (PackSize1 < PackSize2 && IsPackExpansion2)
+return FT1;
+}
+  }
+}
+  }
+
   return JudgeByConstraints();
 }
 
@@ -5457,30 +5490,29 @@ getMoreSpecialized(Sema , QualType T1, QualType T2, 
TemplateLikeDecl *P1,
 return nullptr;
 
   if (Better1 && Better2) {
+// This a speculative fix for CWG1432 (Similar to the fix for CWG1395) that
+// there is no wording or even resolution for this issue.
 bool ClangABICompat15 = S.Context.getLangOpts().getClangABICompat() <=
 LangOptions::ClangABI::Ver15;
 if (!ClangABICompat15) {
-  // Consider this a fix for CWG1432. Similar to the fix for CWG1395.
-  auto *TST1 = T1->castAs();
-  auto *TST2 = T2->castAs();
-  if (TST1->getNumArgs()) {
-const TemplateArgument  = TST1->template_arguments().back();
-if (TA1.getKind() == TemplateArgument::Pack) {
-  assert(TST1->getNumArgs() == TST2->getNumArgs());
-  const TemplateArgument  = TST2->template_arguments().back();
-  assert(TA2.getKind() == TemplateArgument::Pack);
-  unsigned PackSize1 = TA1.pack_size();
-  unsigned PackSize2 = TA2.pack_size();
-  bool 

[clang] c4b79bf - Fix the test added in 55cd5bc50964449627f6f1

2022-09-27 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-09-27T16:42:55-07:00
New Revision: c4b79bf083e0c50f86f0dfe85b8bd0df1b3506a0

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

LOG: Fix the test added in 55cd5bc50964449627f6f1

It is hard to test the functionality for multiple platforms. Just test it
on Linux as similar patches did in the past.

Added: 
clang/test/Driver/crash-diagnostics-dir-4.c

Modified: 
clang/test/Driver/crash-diagnostics-dir-2.c

Removed: 




diff  --git a/clang/test/Driver/crash-diagnostics-dir-2.c 
b/clang/test/Driver/crash-diagnostics-dir-2.c
index 071afb81ed51b..432a8893f8786 100644
--- a/clang/test/Driver/crash-diagnostics-dir-2.c
+++ b/clang/test/Driver/crash-diagnostics-dir-2.c
@@ -1,16 +1,5 @@
-// UNSUPPORTED: ps4, system-windows
-
 // RUN: %clang -### -fcrash-diagnostics-dir=mydumps -c %s 2>&1 \
 // RUN: | FileCheck %s --check-prefix=OPTION
 // OPTION: "-crash-diagnostics-dir=mydumps"
 // RUN: %clang -### -c %s 2>&1 | FileCheck %s --check-prefix=NOOPTION
 // NOOPTION-NOT: "-crash-diagnostics-dir
-
-// RUN: %clang -### -fcrash-diagnostics-dir=mydumps -flto %s 2>&1 \
-// RUN: | FileCheck %s --check-prefix=LTO-OPTION
-// LTO-OPTION: "-cc1"
-// LTO-OPTION: "-plugin-opt=-crash-diagnostics-dir=mydumps"
-
-// RUN: %clang -### -flto %s 2>&1 | FileCheck %s --check-prefix=LTO-NOOPTION
-// LTO-NOOPTION: "-cc1"
-// LTO-NOOPTION-NOT: "-plugin-opt=-crash-diagnostics-dir=mydumps"

diff  --git a/clang/test/Driver/crash-diagnostics-dir-4.c 
b/clang/test/Driver/crash-diagnostics-dir-4.c
new file mode 100644
index 0..573e821ca1f81
--- /dev/null
+++ b/clang/test/Driver/crash-diagnostics-dir-4.c
@@ -0,0 +1,8 @@
+// RUN: %clang -target x86_64-linux-unknown -### 
-fcrash-diagnostics-dir=mydumps -flto %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=LTO-OPTION
+// LTO-OPTION: "-cc1"
+// LTO-OPTION: "-plugin-opt=-crash-diagnostics-dir=mydumps"
+
+// RUN: %clang -target x86_64-linux-unknown -### -flto %s 2>&1 | FileCheck %s 
--check-prefix=LTO-NOOPTION
+// LTO-NOOPTION: "-cc1"
+// LTO-NOOPTION-NOT: "-plugin-opt=-crash-diagnostics-dir=mydumps"



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


[clang] fbfb4a6 - Fix test after 5839fb6d25b4ba6edb

2022-09-27 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-09-27T14:01:13-07:00
New Revision: fbfb4a6359c100ac4f33982688cb0e2c299fb239

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

LOG: Fix test after 5839fb6d25b4ba6edb

The test is not expected for Windows.

Added: 


Modified: 
clang/test/Driver/crash-diagnostics-dir-2.c

Removed: 




diff  --git a/clang/test/Driver/crash-diagnostics-dir-2.c 
b/clang/test/Driver/crash-diagnostics-dir-2.c
index 9910a0a155fb..071afb81ed51 100644
--- a/clang/test/Driver/crash-diagnostics-dir-2.c
+++ b/clang/test/Driver/crash-diagnostics-dir-2.c
@@ -1,4 +1,4 @@
-// UNSUPPORTED: ps4
+// UNSUPPORTED: ps4, system-windows
 
 // RUN: %clang -### -fcrash-diagnostics-dir=mydumps -c %s 2>&1 \
 // RUN: | FileCheck %s --check-prefix=OPTION



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


[clang] c12c26c - Fix test after 5839fb6d25b4ba6edb

2022-09-27 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-09-27T13:39:56-07:00
New Revision: c12c26c1768ac1525ce4240adf194c59bed11097

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

LOG: Fix test after 5839fb6d25b4ba6edb

The test is not expected for PS4.

Added: 


Modified: 
clang/test/Driver/crash-diagnostics-dir-2.c

Removed: 




diff  --git a/clang/test/Driver/crash-diagnostics-dir-2.c 
b/clang/test/Driver/crash-diagnostics-dir-2.c
index 664acd9b7959..9910a0a155fb 100644
--- a/clang/test/Driver/crash-diagnostics-dir-2.c
+++ b/clang/test/Driver/crash-diagnostics-dir-2.c
@@ -1,3 +1,5 @@
+// UNSUPPORTED: ps4
+
 // RUN: %clang -### -fcrash-diagnostics-dir=mydumps -c %s 2>&1 \
 // RUN: | FileCheck %s --check-prefix=OPTION
 // OPTION: "-crash-diagnostics-dir=mydumps"



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


[clang] 54967c0 - [Driver] pass -fjmc to LTO

2022-09-27 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-09-27T13:14:16-07:00
New Revision: 54967c01d2bb6daa1959865d9a780678e652419d

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

LOG: [Driver] pass -fjmc to LTO

So the behavior is consistent with non-LTO mode.

Reviewed By: MaskRay

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/Driver/clang_f_opts.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index c926e98a7f9e..4bc16710e194 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -626,6 +626,14 @@ void tools::addLTOOptions(const ToolChain , 
const ArgList ,
  Path));
   }
 
+  // This controls whether or not we perform JustMyCode instrumentation.
+  if (Args.hasFlag(options::OPT_fjmc, options::OPT_fno_jmc, false)) {
+if (ToolChain.getEffectiveTriple().isOSBinFormatELF())
+  CmdArgs.push_back("-plugin-opt=-enable-jmc-instrument");
+else
+  D.Diag(clang::diag::warn_drv_fjmc_for_elf_only);
+  }
+
   // Setup statistics file output.
   SmallString<128> StatsFile = getStatsFileName(Args, Output, Input, D);
   if (!StatsFile.empty())

diff  --git a/clang/test/Driver/clang_f_opts.c 
b/clang/test/Driver/clang_f_opts.c
index d529f9ad5c48..9c38b5906b7b 100644
--- a/clang/test/Driver/clang_f_opts.c
+++ b/clang/test/Driver/clang_f_opts.c
@@ -601,10 +601,15 @@
 // RUN: %clang -### -S -fjmc -target x86_64-pc-windows-msvc %s 2>&1 | 
FileCheck -check-prefixes=CHECK_JMC_WARN_NOT_ELF,CHECK_NOJMC %s
 // RUN: %clang -### -S -fjmc -g -target x86_64-unknown-linux %s 2>&1 | 
FileCheck -check-prefix=CHECK_JMC %s
 // RUN: %clang -### -S -fjmc -g -fno-jmc -target x86_64-unknown-linux %s 2>&1 
| FileCheck -check-prefix=CHECK_NOJMC %s
+// RUN: %clang -### -fjmc -g -flto -target x86_64-pc-windows-msvc %s 2>&1 | 
FileCheck -check-prefixes=CHECK_JMC_WARN_NOT_ELF,CHECK_NOJMC_LTO %s
+// RUN: %clang -### -fjmc -g -flto -target x86_64-unknown-linux %s 2>&1 | 
FileCheck -check-prefix=CHECK_JMC_LTO %s
+// RUN: %clang -### -fjmc -g -flto -fno-jmc -target x86_64-unknown-linux %s 
2>&1 | FileCheck -check-prefix=CHECK_NOJMC_LTO %s
 // CHECK_JMC_WARN: -fjmc requires debug info. Use -g or debug options that 
enable debugger's stepping function; option ignored
 // CHECK_JMC_WARN_NOT_ELF: -fjmc works only for ELF; option ignored
 // CHECK_NOJMC-NOT: -fjmc
 // CHECK_JMC: -fjmc
+// CHECK_NOJMC_LTO-NOT: -plugin-opt=-enable-jmc-instrument
+// CHECK_JMC_LTO: -plugin-opt=-enable-jmc-instrument
 
 // RUN: %clang -### -fintegrated-objemitter -target x86_64 %s 2>&1 | FileCheck 
-check-prefix=CHECK-INT-OBJEMITTER %s
 // CHECK-INT-OBJEMITTER-NOT: unsupported option '-fintegrated-objemitter' for 
target



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


[clang] 55cd5bc - [Driver][PS4] pass -fcrash-diagnostics-dir to LTO

2022-09-27 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-09-27T13:14:16-07:00
New Revision: 55cd5bc50964449627f6f1fa82ce8268d0629d9e

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

LOG: [Driver][PS4] pass -fcrash-diagnostics-dir to LTO

Also refactor the existing code a little bit.

Reviewed By: probinson

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

Added: 
clang/test/Driver/ps4-ps5-linker.c

Modified: 
clang/lib/Driver/ToolChains/PS4CPU.cpp
clang/test/Driver/debug-options.c

Removed: 
clang/test/Driver/ps4-ps5-linker-jmc.c



diff  --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 989bdb4065eaa..643f815c5835a 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -158,34 +158,32 @@ void tools::PScpu::Linker::ConstructJob(Compilation , 
const JobAction ,
   const bool IsPS4 = TC.getTriple().isPS4();
   const bool IsPS5 = TC.getTriple().isPS5();
   assert(IsPS4 || IsPS5);
-  (void)IsPS5;
 
-  ArgStringList DbgOpts;
-
-  // This tells LTO to perform JustMyCode instrumentation.
-  if (UseLTO && UseJMC)
-DbgOpts.push_back("-enable-jmc-instrument");
+  auto AddCodeGenFlag = [&](Twine Flag) {
+const char *Prefix = nullptr;
+if (IsPS4 && D.getLTOMode() == LTOK_Thin)
+  Prefix = "-lto-thin-debug-options=";
+else if (IsPS4 && D.getLTOMode() == LTOK_Full)
+  Prefix = "-lto-debug-options=";
+else if (IsPS5)
+  Prefix = "-plugin-opt=";
+else
+  llvm_unreachable("new LTO mode?");
 
-  // We default to creating the arange section, but LTO does not. Enable it
-  // here.
-  if (UseLTO)
-DbgOpts.push_back("-generate-arange-section");
+CmdArgs.push_back(Args.MakeArgString(Twine(Prefix) + Flag));
+  };
 
   if (UseLTO) {
-if (IsPS4) {
-  StringRef F = (D.getLTOMode() == LTOK_Thin) ?
-  "-lto-thin-debug-options=" : "-lto-debug-options=";
-  F = makeArgString(Args, F.data(), DbgOpts.front(), "");
-  DbgOpts.erase(DbgOpts.begin());
-  for (auto X : DbgOpts)
-F = makeArgString(Args, F.data(), " ", X);
-  CmdArgs.push_back(F.data());
-} else {
-  for (auto D : DbgOpts) {
-CmdArgs.push_back("-mllvm");
-CmdArgs.push_back(D);
-  }
-}
+// We default to creating the arange section, but LTO does not. Enable it
+// here.
+AddCodeGenFlag("-generate-arange-section");
+
+// This tells LTO to perform JustMyCode instrumentation.
+if (UseJMC)
+  AddCodeGenFlag("-enable-jmc-instrument");
+
+if (Arg *A = Args.getLastArg(options::OPT_fcrash_diagnostics_dir))
+  AddCodeGenFlag(Twine("-crash-diagnostics-dir=") + A->getValue());
   }
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))

diff  --git a/clang/test/Driver/debug-options.c 
b/clang/test/Driver/debug-options.c
index bd13a63162c8e..7e33d8d393eb2 100644
--- a/clang/test/Driver/debug-options.c
+++ b/clang/test/Driver/debug-options.c
@@ -375,8 +375,8 @@
 //
 
 // LDGARANGE: {{".*ld.*"}} {{.*}}
-// LDGARANGE-NOT: "-generate-arange-section"
-// LLDGARANGE: {{".*lld.*"}} {{.*}} "-generate-arange-section"
+// LDGARANGE-NOT: "-plugin-opt=-generate-arange-section"
+// LLDGARANGE: {{".*lld.*"}} {{.*}} "-plugin-opt=-generate-arange-section"
 // SNLDTLTOGARANGE: {{".*orbis-ld.*"}} {{.*}} 
"-lto-thin-debug-options=-generate-arange-section"
 // SNLDFLTOGARANGE: {{".*orbis-ld.*"}} {{.*}} 
"-lto-debug-options=-generate-arange-section"
 

diff  --git a/clang/test/Driver/ps4-ps5-linker-jmc.c 
b/clang/test/Driver/ps4-ps5-linker.c
similarity index 50%
rename from clang/test/Driver/ps4-ps5-linker-jmc.c
rename to clang/test/Driver/ps4-ps5-linker.c
index f5accd14291c4..ee8e96bbfbd02 100644
--- a/clang/test/Driver/ps4-ps5-linker-jmc.c
+++ b/clang/test/Driver/ps4-ps5-linker.c
@@ -7,14 +7,23 @@
 // RUN: %clang --target=x86_64-scei-ps5 -flto -fjmc %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-PS5-LTO,CHECK-PS5-LIB %s
 
 // CHECK-PS4-NOT: -enable-jmc-instrument
-
 // CHECK-PS4-THIN-LTO: -lto-thin-debug-options=-enable-jmc-instrument
 // CHECK-PS4-FULL-LTO: -lto-debug-options=-enable-jmc-instrument
-
-// CHECK-PS5-NOT: "-enable-jmc-instrument"
-
-// CHECK-PS5-LTO: "-mllvm" "-enable-jmc-instrument"
+// CHECK-PS5-NOT: -plugin-opt=-enable-jmc-instrument
+// CHECK-PS5-LTO: -plugin-opt=-enable-jmc-instrument
 
 // Check the default library name.
 // CHECK-PS4-LIB: "--whole-archive" "-lSceDbgJmc" "--no-whole-archive"
 // CHECK-PS5-LIB: "--whole-archive" "-lSceJmc_nosubmission" 
"--no-whole-archive"
+
+// Test the driver's control over the -fcrash-diagnostics-dir behavior with 
linker flags.
+
+// RUN: %clang --target=x86_64-scei-ps4 -flto=thin 
-fcrash-diagnostics-dir=mydumps %s -### 2>&1 | FileCheck 

[clang] 5839fb6 - [Driver] pass -fcrash-diagnostics-dir to LTO

2022-09-27 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-09-27T13:14:16-07:00
New Revision: 5839fb6d25b4ba6edb4d9a707c75bffd178d6cc6

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

LOG: [Driver] pass -fcrash-diagnostics-dir to LTO

So the behavior is consistent with non-LTO mode.

Reviewed By: MaskRay

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/Driver/crash-diagnostics-dir-2.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index d0abc4a0e26c..c926e98a7f9e 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -632,6 +632,11 @@ void tools::addLTOOptions(const ToolChain , 
const ArgList ,
 CmdArgs.push_back(
 Args.MakeArgString(Twine("-plugin-opt=stats-file=") + StatsFile));
 
+  // Setup crash diagnostics dir.
+  if (Arg *A = Args.getLastArg(options::OPT_fcrash_diagnostics_dir))
+CmdArgs.push_back(Args.MakeArgString(
+Twine("-plugin-opt=-crash-diagnostics-dir=") + A->getValue()));
+
   addX86AlignBranchArgs(D, Args, CmdArgs, /*IsLTO=*/true);
 
   // Handle remark diagnostics on screen options: '-Rpass-*'.

diff  --git a/clang/test/Driver/crash-diagnostics-dir-2.c 
b/clang/test/Driver/crash-diagnostics-dir-2.c
index 432a8893f878..664acd9b7959 100644
--- a/clang/test/Driver/crash-diagnostics-dir-2.c
+++ b/clang/test/Driver/crash-diagnostics-dir-2.c
@@ -3,3 +3,12 @@
 // OPTION: "-crash-diagnostics-dir=mydumps"
 // RUN: %clang -### -c %s 2>&1 | FileCheck %s --check-prefix=NOOPTION
 // NOOPTION-NOT: "-crash-diagnostics-dir
+
+// RUN: %clang -### -fcrash-diagnostics-dir=mydumps -flto %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=LTO-OPTION
+// LTO-OPTION: "-cc1"
+// LTO-OPTION: "-plugin-opt=-crash-diagnostics-dir=mydumps"
+
+// RUN: %clang -### -flto %s 2>&1 | FileCheck %s --check-prefix=LTO-NOOPTION
+// LTO-NOOPTION: "-cc1"
+// LTO-NOOPTION-NOT: "-plugin-opt=-crash-diagnostics-dir=mydumps"



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


[clang] f3e0298 - [NFC][Clang] Remove dead code

2022-09-26 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-09-26T18:32:52-07:00
New Revision: f3e02989e6e5d6fa90d5ac1ea21c592197a0ae7d

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

LOG: [NFC][Clang] Remove dead code

And correct a few typos.

Added: 


Modified: 
clang/include/clang/AST/DeclTemplate.h
clang/lib/AST/ASTContext.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index dbea107f368fb..78e99f8335b98 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -1226,7 +1226,7 @@ class TemplateTypeParmDecl final : public TypeDecl,
   /// type constraint.
   bool TypeConstraintInitialized : 1;
 
-  /// Whether this non-type template parameter is an "expanded"
+  /// Whether this type template parameter is an "expanded"
   /// parameter pack, meaning that its type is a pack expansion and we
   /// already know the set of types that expansion expands to.
   bool ExpandedParameterPack : 1;
@@ -1391,7 +1391,7 @@ class TemplateTypeParmDecl final : public TypeDecl,
   /// \brief Get the associated-constraints of this template parameter.
   /// This will either be the immediately-introduced constraint or empty.
   ///
-  /// Use this instead of getConstraintExpression for concepts APIs that
+  /// Use this instead of getTypeConstraint for concepts APIs that
   /// accept an ArrayRef of constraint expressions.
   void getAssociatedConstraints(llvm::SmallVectorImpl ) const 
{
 if (HasTypeConstraint)

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 1a15292c12d3e..99ab66d4f3640 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -800,12 +800,6 @@ ASTContext::getCanonicalTemplateTemplateParmDecl(
 Expr *NewIDC = canonicalizeImmediatelyDeclaredConstraint(
 *this, TC->getImmediatelyDeclaredConstraint(),
 ParamAsArgument);
-TemplateArgumentListInfo CanonArgsAsWritten;
-if (auto *Args = TC->getTemplateArgsAsWritten())
-  for (const auto  : Args->arguments())
-CanonArgsAsWritten.addArgument(
-TemplateArgumentLoc(ArgLoc.getArgument(),
-TemplateArgumentLocInfo()));
 NewTTP->setTypeConstraint(
 NestedNameSpecifierLoc(),
 DeclarationNameInfo(TC->getNamedConcept()->getDeclName(),
@@ -5166,7 +5160,7 @@ TemplateArgument 
ASTContext::getInjectedTemplateArg(NamedDecl *Param) {
 if (T->isRecordType())
   T.addConst();
 Expr *E = new (*this) DeclRefExpr(
-*this, NTTP, /*enclosing*/ false, T,
+*this, NTTP, /*RefersToEnclosingVariableOrCapture*/ false, T,
 Expr::getValueKindForType(NTTP->getType()), NTTP->getLocation());
 
 if (NTTP->isParameterPack())



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


[clang] 288576f - [PS4][driver] make -fjmc work with LTO driver linking stage

2022-08-29 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-08-29T12:12:19-07:00
New Revision: 288576f474f260c77beb6f5d1029101626f776f0

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

LOG: [PS4][driver] make -fjmc work with LTO driver linking stage

Reviewed By: probinson

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

Added: 
clang/test/Driver/ps4-ps5-linker-jmc.c

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

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 35a83d79abfd1..97688470008fa 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -152,6 +152,26 @@ void tools::PScpu::Linker::ConstructJob(Compilation , 
const JobAction ,
 assert(Output.isNothing() && "Invalid output.");
   }
 
+  const bool UseLTO = D.isUsingLTO();
+  const bool UseJMC =
+  Args.hasFlag(options::OPT_fjmc, options::OPT_fno_jmc, false);
+  const bool IsPS4 = TC.getTriple().isPS4();
+  const bool IsPS5 = TC.getTriple().isPS5();
+  assert(IsPS4 || IsPS5);
+
+  // This tells LTO to perform JustMyCode instrumentation.
+  if (UseLTO && UseJMC) {
+if (IsPS4 && D.getLTOMode() == LTOK_Thin) {
+  CmdArgs.push_back("-lto-thin-debug-options=-enable-jmc-instrument");
+} else if (IsPS4 && D.getLTOMode() == LTOK_Full) {
+  CmdArgs.push_back("-lto-debug-options=-enable-jmc-instrument");
+} else if (IsPS5) {
+  CmdArgs.push_back("-mllvm");
+  CmdArgs.push_back("-enable-jmc-instrument");
+} else
+  llvm_unreachable("new LTO mode?");
+  }
+
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
 TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
 
@@ -171,6 +191,15 @@ void tools::PScpu::Linker::ConstructJob(Compilation , 
const JobAction ,
 CmdArgs.push_back("-lpthread");
   }
 
+  if (UseJMC) {
+CmdArgs.push_back("--whole-archive");
+if (IsPS4)
+  CmdArgs.push_back("-lSceDbgJmc");
+else
+  CmdArgs.push_back("-lSceJmc_nosubmission");
+CmdArgs.push_back("--no-whole-archive");
+  }
+
   if (Args.hasArg(options::OPT_fuse_ld_EQ)) {
 D.Diag(diag::err_drv_unsupported_opt_for_target)
 << "-fuse-ld" << TC.getTriple().str();

diff  --git a/clang/test/Driver/ps4-ps5-linker-jmc.c 
b/clang/test/Driver/ps4-ps5-linker-jmc.c
new file mode 100644
index 0..3d308d13e64fc
--- /dev/null
+++ b/clang/test/Driver/ps4-ps5-linker-jmc.c
@@ -0,0 +1,20 @@
+// Test the driver's control over the JustMyCode behavior with linker flags.
+
+// RUN: %clang --target=x86_64-scei-ps4 -fjmc %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-PS4,CHECK-PS4-LIB %s
+// RUN: %clang --target=x86_64-scei-ps4 -flto=thin -fjmc %s -### 2>&1 | 
FileCheck --check-prefixes=CHECK-PS4-THIN-LTO,CHECK-PS4-LIB %s
+// RUN: %clang --target=x86_64-scei-ps4 -flto=full -fjmc %s -### 2>&1 | 
FileCheck --check-prefixes=CHECK-PS4-FULL-LTO,CHECK-PS4-LIB %s
+// RUN: %clang --target=x86_64-scei-ps5 -fjmc %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-PS5,CHECK-PS5-LIB %s
+// RUN: %clang --target=x86_64-scei-ps5 -flto -fjmc %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-PS5-LTO,CHECK-PS5-LIB %s
+
+// CHECK-PS4-NOT: "-enable-jmc-instrument"
+
+// CHECK-PS4-THIN-LTO: "-lto-thin-debug-options=-enable-jmc-instrument"
+// CHECK-PS4-FULL-LTO: "-lto-debug-options=-enable-jmc-instrument"
+
+// CHECK-PS5-NOT: "-enable-jmc-instrument"
+
+// CHECK-PS5-LTO: "-mllvm" "-enable-jmc-instrument"
+
+// Check the default library name.
+// CHECK-PS4-LIB: "--whole-archive" "-lSceDbgJmc" "--no-whole-archive"
+// CHECK-PS5-LIB: "--whole-archive" "-lSceJmc_nosubmission" 
"--no-whole-archive"



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


[clang] 70248bf - [Clang] Implement function attribute nouwtable

2022-08-29 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-08-29T12:12:19-07:00
New Revision: 70248bfdea6c70008ca42bf03bb28ebdee252744

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

LOG: [Clang] Implement function attribute nouwtable

To have finer control of IR uwtable attribute generation. For target code 
generation,
IR nounwind and uwtable may have some interaction. However, for frontend, there 
are
no semantic interactions so the this new `nouwtable` is marked "SimpleHandler = 
1".

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

Added: 
clang/test/CodeGen/attr-nouwtable.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/Misc/pragma-attribute-supported-attributes-list.test

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ef3950501f963..92b52b8998b4f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -149,6 +149,9 @@ Attribute Changes in Clang
   using the MinGW environment. This attribute is only available for Windows
   targets.
 
+- Introduced a new function attribute ``__attribute__((nouwtable))`` to 
suppress
+  LLVM IR ``uwtable`` function attribute.
+
 Windows Support
 ---
 

diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 3b0e3e2971803..0ad59b2c153ae 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2092,6 +2092,13 @@ def NoThrow : InheritableAttr {
   let Documentation = [NoThrowDocs];
 }
 
+def NoUwtable : InheritableAttr {
+  let Spellings = [Clang<"nouwtable">];
+  let Subjects = SubjectList<[FunctionLike]>;
+  let Documentation = [NoUwtableDocs];
+  let SimpleHandler = 1;
+}
+
 def NvWeak : IgnoredAttr {
   // No Declspec spelling of this attribute; the CUDA headers use
   // __attribute__((nv_weak)) unconditionally. Does not receive an [[]]

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 32084bf512bc1..68f1268ed7da9 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -4537,6 +4537,16 @@ guaranteed to not throw an exception.
 }];
 }
 
+def NoUwtableDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Clang supports the ``nouwtable`` attribute which skips emitting
+the unwind table entry for the specified function. This attribute is useful for
+selectively emitting the unwind table entry on some functions when building 
with
+``-funwind-tables`` compiler option.
+}];
+}
+
 def InternalLinkageDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 6294fe9e87d32..62e906a87af48 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1963,7 +1963,7 @@ void 
CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
llvm::Function *F) {
   llvm::AttrBuilder B(F->getContext());
 
-  if (CodeGenOpts.UnwindTables)
+  if ((!D || !D->hasAttr()) && CodeGenOpts.UnwindTables)
 B.addUWTableAttr(llvm::UWTableKind(CodeGenOpts.UnwindTables));
 
   if (CodeGenOpts.StackClashProtector)

diff  --git a/clang/test/CodeGen/attr-nouwtable.c 
b/clang/test/CodeGen/attr-nouwtable.c
new file mode 100644
index 0..a0c6d9232ef30
--- /dev/null
+++ b/clang/test/CodeGen/attr-nouwtable.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -funwind-tables=2 -S -emit-llvm %s -o - | FileCheck %s
+
+__attribute__((nouwtable))
+int test1(void) { return 0; }
+
+// CHECK: @test1{{.*}}[[ATTR1:#[0-9]+]]
+// CHECK: attributes [[ATTR1]] = {
+// CHECK-NOT: uwtable
+// CHECK: }

diff  --git a/clang/test/Misc/pragma-attribute-supported-attributes-list.test 
b/clang/test/Misc/pragma-attribute-supported-attributes-list.test
index bde9505009934..b6a52832dadde 100644
--- a/clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ b/clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -115,6 +115,7 @@
 // CHECK-NEXT: NoStackProtector (SubjectMatchRule_function)
 // CHECK-NEXT: NoThreadSafetyAnalysis (SubjectMatchRule_function)
 // CHECK-NEXT: NoThrow (SubjectMatchRule_hasType_functionType)
+// CHECK-NEXT: NoUwtable (SubjectMatchRule_hasType_functionType)
 // CHECK-NEXT: NotTailCalled (SubjectMatchRule_function)
 // CHECK-NEXT: OSConsumed (SubjectMatchRule_variable_is_parameter)
 // CHECK-NEXT: OSReturnsNotRetained (SubjectMatchRule_function, 
SubjectMatchRule_objc_method, SubjectMatchRule_objc_property, 
SubjectMatchRule_variable_is_parameter)




[clang] 088ba8e - [Clang] follow-up D128745, use ClangABICompat15 instead of ClangABICompat14

2022-08-23 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-08-23T10:45:35-07:00
New Revision: 088ba8efeb4921deb49534714ddefb14a91afe46

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

LOG: [Clang] follow-up D128745, use ClangABICompat15 instead of ClangABICompat14

Since the patch missed release 15.x and will be included in release 16.x. Also, 
simplify related tests.

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/LangOptions.h
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/test/CXX/temp/temp.decls/temp.class.spec/p8-0x.cpp
clang/test/CodeGen/partial-order-variadic.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0ba35edd5dcb7..64a2ce2bb2b8b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -144,7 +144,7 @@ C2x Feature Support
 C++ Language Changes in Clang
 -
 
-- Implemented DR692, DR1395 and DR1432. Use the ``-fclang-abi-compat=14`` 
option
+- Implemented DR692, DR1395 and DR1432. Use the ``-fclang-abi-compat=15`` 
option
   to get the old partial ordering behavior regarding packs.
 
 C++20 Feature Support

diff  --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 3a1c13dd72568..dd2a7920a5f17 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -223,6 +223,11 @@ class LangOptions : public LangOptionsBase {
 /// implicit declaration.
 Ver14,
 
+/// Attempt to be ABI-compatible with code generated by Clang 15.0.x.
+/// This causes clang to:
+///   - Reverse the implementation for DR692, DR1395 and DR1432.
+Ver15,
+
 /// Conform to the underlying platform's C and C++ ABIs as closely
 /// as we can.
 Latest

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 6b5baa75fd27a..574514bdd0b0a 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3522,6 +3522,8 @@ void CompilerInvocation::GenerateLangArgs(const 
LangOptions ,
 GenerateArg(Args, OPT_fclang_abi_compat_EQ, "12.0", SA);
   else if (Opts.getClangABICompat() == LangOptions::ClangABI::Ver14)
 GenerateArg(Args, OPT_fclang_abi_compat_EQ, "14.0", SA);
+  else if (Opts.getClangABICompat() == LangOptions::ClangABI::Ver15)
+GenerateArg(Args, OPT_fclang_abi_compat_EQ, "15.0", SA);
 
   if (Opts.getSignReturnAddressScope() ==
   LangOptions::SignReturnAddressScopeKind::All)
@@ -4014,6 +4016,8 @@ bool CompilerInvocation::ParseLangArgs(LangOptions , 
ArgList ,
 Opts.setClangABICompat(LangOptions::ClangABI::Ver12);
   else if (Major <= 14)
 Opts.setClangABICompat(LangOptions::ClangABI::Ver14);
+  else if (Major <= 15)
+Opts.setClangABICompat(LangOptions::ClangABI::Ver15);
 } else if (Ver != "latest") {
   Diags.Report(diag::err_drv_invalid_value)
   << A->getAsString(Args) << A->getValue();

diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 99119bcb2e4e6..84c4a191ec327 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -1107,9 +1107,9 @@ DeduceTemplateArguments(Sema ,
   // During partial ordering, if Ai was originally a function parameter pack:
   // - if P does not contain a function parameter type corresponding to Ai then
   //   Ai is ignored;
-  bool ClangABICompat14 = S.Context.getLangOpts().getClangABICompat() <=
-  LangOptions::ClangABI::Ver14;
-  if (!ClangABICompat14 && PartialOrdering && ArgIdx + 1 == NumArgs &&
+  bool ClangABICompat15 = S.Context.getLangOpts().getClangABICompat() <=
+  LangOptions::ClangABI::Ver15;
+  if (!ClangABICompat15 && PartialOrdering && ArgIdx + 1 == NumArgs &&
   isa(Args[ArgIdx]))
 return Sema::TDK_Success;
 
@@ -2445,8 +2445,8 @@ static bool isSameTemplateArg(ASTContext ,
   if (X.getKind() != Y.getKind())
 return false;
 
-  bool ClangABICompat14 =
-  Context.getLangOpts().getClangABICompat() <= 
LangOptions::ClangABI::Ver14;
+  bool ClangABICompat15 =
+  Context.getLangOpts().getClangABICompat() <= 
LangOptions::ClangABI::Ver15;
 
   switch (X.getKind()) {
 case TemplateArgument::Null:
@@ -2480,7 +2480,7 @@ static bool isSameTemplateArg(ASTContext ,
 }
 
 case TemplateArgument::Pack:
-  if (ClangABICompat14) {
+  if (ClangABICompat15) {
 if (X.pack_size() != Y.pack_size())
   return false;
 
@@ -5464,9 +5464,9 @@ 

[clang] f9969a3 - [CodeGen] Sort llvm.global_ctors by lexing order before emission

2022-08-22 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-08-22T16:00:14-07:00
New Revision: f9969a3d28e738e9427e371aac06d71269220123

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

LOG: [CodeGen] Sort llvm.global_ctors by lexing order before emission

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

The lexing order is already bookkept in DelayedCXXInitPosition but we
were not using it based on the wrong assumption that inline variable is
unordered. This patch fixes it by ordering entries in llvm.global_ctors
by orders in DelayedCXXInitPosition.

for llvm.global_ctors entries without a lexing order, ordering them by
the insertion order.

(This *mostly* orders the template instantiation in
https://reviews.llvm.org/D126341 intuitively, minus one tweak for which I'll
submit a separate patch.)

Reviewed By: efriedma

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

Added: 
clang/test/CodeGenCXX/static-init-inline-variable.cpp

Modified: 
clang/lib/CodeGen/CGDeclCXX.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenModule.h
clang/lib/CodeGen/ItaniumCXXABI.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index 8ceb4863d6ead..2075857848656 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -562,7 +562,7 @@ CodeGenModule::EmitCXXGlobalVarDeclInitFunc(const VarDecl 
*D,
   Priority = 400;
 
 if (Priority != -1)
-  AddGlobalCtor(Fn, Priority, COMDATKey);
+  AddGlobalCtor(Fn, Priority, ~0U, COMDATKey);
 else
   EmitPointerToInitFunc(D, Addr, Fn, ISA);
   } else if (auto *IPA = D->getAttr()) {
@@ -588,8 +588,16 @@ CodeGenModule::EmitCXXGlobalVarDeclInitFunc(const VarDecl 
*D,
 // SelectAny globals will be comdat-folded. Put the initializer into a
 // COMDAT group associated with the global, so the initializers get folded
 // too.
-
-AddGlobalCtor(Fn, 65535, COMDATKey);
+I = DelayedCXXInitPosition.find(D);
+// CXXGlobalInits.size() is the lex order number for the next deferred
+// VarDecl. Use it when the current VarDecl is non-deferred. Although this
+// lex order number is shared between current VarDecl and some following
+// VarDecls, their order of insertion into `llvm.global_ctors` is the same
+// as the lexing order and the following stable sort would preserve such
+// order.
+unsigned LexOrder =
+I == DelayedCXXInitPosition.end() ? CXXGlobalInits.size() : I->second;
+AddGlobalCtor(Fn, 65535, LexOrder, COMDATKey);
 if (COMDATKey && (getTriple().isOSBinFormatELF() ||
   getTarget().getCXXABI().isMicrosoft())) {
   // When COMDAT is used on ELF or in the MS C++ ABI, the key must be in

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 9b97e890c3523..74c14fed6575e 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -47,6 +47,7 @@
 #include "clang/CodeGen/BackendUtil.h"
 #include "clang/CodeGen/ConstantInitBuilder.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/ADT/Triple.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
@@ -560,6 +561,9 @@ void CodeGenModule::Release() {
 if (PGOStats.hasDiagnostics())
   PGOStats.reportDiagnostics(getDiags(), getCodeGenOpts().MainFileName);
   }
+  llvm::stable_sort(GlobalCtors, [](const Structor , const Structor ) {
+return L.LexOrder < R.LexOrder;
+  });
   EmitCtorList(GlobalCtors, "llvm.global_ctors");
   EmitCtorList(GlobalDtors, "llvm.global_dtors");
   EmitGlobalAnnotations();
@@ -1579,9 +1583,10 @@ llvm::GlobalValue 
*CodeGenModule::GetGlobalValue(StringRef Name) {
 /// AddGlobalCtor - Add a function to the list that will be called before
 /// main() runs.
 void CodeGenModule::AddGlobalCtor(llvm::Function *Ctor, int Priority,
+  unsigned LexOrder,
   llvm::Constant *AssociatedData) {
   // FIXME: Type coercion of void()* types.
-  GlobalCtors.push_back(Structor(Priority, Ctor, AssociatedData));
+  GlobalCtors.push_back(Structor(Priority, LexOrder, Ctor, AssociatedData));
 }
 
 /// AddGlobalDtor - Add a function to the list that will be called
@@ -1595,7 +1600,7 @@ void CodeGenModule::AddGlobalDtor(llvm::Function *Dtor, 
int Priority,
   }
 
   // FIXME: Type coercion of void()* types.
-  GlobalDtors.push_back(Structor(Priority, Dtor, nullptr));
+  GlobalDtors.push_back(Structor(Priority, ~0U, Dtor, nullptr));
 }
 
 void CodeGenModule::EmitCtorList(CtorList , const char *GlobalName) {

diff  --git a/clang/lib/CodeGen/CodeGenModule.h 
b/clang/lib/CodeGen/CodeGenModule.h
index 

[clang] b296aed - [clang] fix a typo in da6187f566b7881cb835

2022-08-17 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-08-17T01:27:12-07:00
New Revision: b296aed8ae239c20ebdd7969e978f8d2a3b9c178

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

LOG: [clang] fix a typo in da6187f566b7881cb835

Added: 


Modified: 
clang/lib/Sema/SemaTemplateDeduction.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index ac0b3fe8e04a..99119bcb2e4e 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -2488,7 +2488,8 @@ static bool isSameTemplateArg(ASTContext ,
  XPEnd = X.pack_end(),
  YP = Y.pack_begin();
  XP != XPEnd; ++XP, ++YP)
-  if (!isSameTemplateArg(Context, *XP, *YP, PackExpansionMatchesPack))
+  if (!isSameTemplateArg(Context, *XP, *YP, PartialOrdering,
+ PackExpansionMatchesPack))
 return false;
   } else {
 unsigned PackIterationSize = X.pack_size();



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


[clang] da6187f - [Clang] followup D128745, add a missing ClangABICompat check

2022-08-16 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-08-16T18:40:00-07:00
New Revision: da6187f566b7881cb8350621aea9bd582de569b9

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

LOG: [Clang] followup D128745, add a missing ClangABICompat check

Added: 


Modified: 
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/test/CodeGen/partial-order-variadic.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 6836f7c090be2..ac0b3fe8e04a2 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -2445,6 +2445,9 @@ static bool isSameTemplateArg(ASTContext ,
   if (X.getKind() != Y.getKind())
 return false;
 
+  bool ClangABICompat14 =
+  Context.getLangOpts().getClangABICompat() <= 
LangOptions::ClangABI::Ver14;
+
   switch (X.getKind()) {
 case TemplateArgument::Null:
   llvm_unreachable("Comparing NULL template argument");
@@ -2477,30 +2480,42 @@ static bool isSameTemplateArg(ASTContext ,
 }
 
 case TemplateArgument::Pack:
-  unsigned PackIterationSize = X.pack_size();
-  if (X.pack_size() != Y.pack_size()) {
-if (!PartialOrdering)
+  if (ClangABICompat14) {
+if (X.pack_size() != Y.pack_size())
   return false;
 
-// C++0x [temp.deduct.type]p9:
-// During partial ordering, if Ai was originally a pack expansion:
-// - if P does not contain a template argument corresponding to Ai then
-//   Ai is ignored;
-bool XHasMoreArg = X.pack_size() > Y.pack_size();
-if (!(XHasMoreArg && X.pack_elements().back().isPackExpansion()) &&
-!(!XHasMoreArg && Y.pack_elements().back().isPackExpansion()))
-  return false;
+for (TemplateArgument::pack_iterator XP = X.pack_begin(),
+ XPEnd = X.pack_end(),
+ YP = Y.pack_begin();
+ XP != XPEnd; ++XP, ++YP)
+  if (!isSameTemplateArg(Context, *XP, *YP, PackExpansionMatchesPack))
+return false;
+  } else {
+unsigned PackIterationSize = X.pack_size();
+if (X.pack_size() != Y.pack_size()) {
+  if (!PartialOrdering)
+return false;
+
+  // C++0x [temp.deduct.type]p9:
+  // During partial ordering, if Ai was originally a pack expansion:
+  // - if P does not contain a template argument corresponding to Ai
+  //   then Ai is ignored;
+  bool XHasMoreArg = X.pack_size() > Y.pack_size();
+  if (!(XHasMoreArg && X.pack_elements().back().isPackExpansion()) &&
+  !(!XHasMoreArg && Y.pack_elements().back().isPackExpansion()))
+return false;
+
+  if (XHasMoreArg)
+PackIterationSize = Y.pack_size();
+}
 
-if (XHasMoreArg)
-  PackIterationSize = Y.pack_size();
+ArrayRef XP = X.pack_elements();
+ArrayRef YP = Y.pack_elements();
+for (unsigned i = 0; i < PackIterationSize; ++i)
+  if (!isSameTemplateArg(Context, XP[i], YP[i], PartialOrdering,
+ PackExpansionMatchesPack))
+return false;
   }
-
-  ArrayRef XP = X.pack_elements();
-  ArrayRef YP = Y.pack_elements();
-  for (unsigned i = 0; i < PackIterationSize; ++i)
-if (!isSameTemplateArg(Context, XP[i], YP[i], PartialOrdering,
-   PackExpansionMatchesPack))
-  return false;
   return true;
   }
 

diff  --git a/clang/test/CodeGen/partial-order-variadic.cpp 
b/clang/test/CodeGen/partial-order-variadic.cpp
index 496a7da42208a..9a366c83e222c 100644
--- a/clang/test/CodeGen/partial-order-variadic.cpp
+++ b/clang/test/CodeGen/partial-order-variadic.cpp
@@ -3,20 +3,28 @@
 
 #if defined(CLANG_ABI_COMPAT) && CLANG_ABI_COMPAT <= 14
 
+// CHECK-14: %"struct.temp_func_order_example3::S" = type { i8 }
+
 // CHECK-14: define dso_local void @_ZN24temp_func_order_example31hEi(i32 
noundef %i)
-// CHECK-14-NEXT: entry:
-// CHECK-14-NEXT:   %i.addr = alloca i32, align 4
-// CHECK-14-NEXT:   %r = alloca ptr, align 8
-// CHECK-14-NEXT:   store i32 %i, ptr %i.addr, align 4
-// CHECK-14-NEXT:   %call = call noundef nonnull align 4 dereferenceable(4) 
ptr @_ZN24temp_func_order_example31gIiJEEERiPT_DpT0_(ptr noundef %i.addr)
-// CHECK-14-NEXT:   store ptr %call, ptr %r, align 8
-// CHECK-14-NEXT:   ret void
+// CHECK-14-NEXT:  entry:
+// CHECK-14-NEXT:%i.addr = alloca i32, align 4
+// CHECK-14-NEXT:%r = alloca ptr, align 8
+// CHECK-14-NEXT:%a = alloca %"struct.temp_func_order_example3::S", align 1
+// CHECK-14-NEXT:store i32 %i, ptr %i.addr, align 4
+// CHECK-14-NEXT:%call = call noundef 

[clang] 6afcc4a - [c++] implements DR692, DR1395 and tentatively DR1432, about partial ordering of variadic template partial specialization or function template

2022-08-14 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-08-14T14:37:40-07:00
New Revision: 6afcc4a459ead8809a0d6d9b4bf7b64bcc13582b

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

LOG: [c++] implements DR692, DR1395 and tentatively DR1432, about partial 
ordering of variadic template partial specialization or function template

DR692 handles two cases: pack expansion (for class/var template) and function 
parameter pack. The former needs DR1432 as a fix, and the latter needs DR1395 
as a fix. However, DR1432 has not yet made a wording change. so I made a 
tentative fix for DR1432 with the same spirit as DR1395.

Reviewed By: aaron.ballman, erichkeane, #clang-language-wg

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

Added: 
clang/test/CodeGen/partial-order-variadic.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/test/CXX/drs/dr6xx.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6970149444d1..a635b734c47a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -135,6 +135,9 @@ C2x Feature Support
 C++ Language Changes in Clang
 -
 
+- Implemented DR692, DR1395 and DR1432. Use the ``-fclang-abi-compat=14`` 
option
+  to get the old partial ordering behavior regarding packs.
+
 C++20 Feature Support
 ^
 

diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 09e5d7b80127..6836f7c090be 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -55,6 +55,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 namespace clang {
@@ -1100,6 +1101,18 @@ DeduceTemplateArguments(Sema ,
   return Result;
   }
 
+  // DR692, DR1395
+  // C++0x [temp.deduct.type]p10:
+  // If the parameter-declaration corresponding to P_i ...
+  // During partial ordering, if Ai was originally a function parameter pack:
+  // - if P does not contain a function parameter type corresponding to Ai then
+  //   Ai is ignored;
+  bool ClangABICompat14 = S.Context.getLangOpts().getClangABICompat() <=
+  LangOptions::ClangABI::Ver14;
+  if (!ClangABICompat14 && PartialOrdering && ArgIdx + 1 == NumArgs &&
+  isa(Args[ArgIdx]))
+return Sema::TDK_Success;
+
   // Make sure we don't have any extra arguments.
   if (ArgIdx < NumArgs)
 return Sema::TDK_MiscellaneousDeductionFailure;
@@ -1755,7 +1768,7 @@ static Sema::TemplateDeductionResult 
DeduceTemplateArgumentsByTypeMatch(
   if (auto Result = DeduceTemplateArguments(
   S, TemplateParams, FPP->param_type_begin(), FPP->getNumParams(),
   FPA->param_type_begin(), FPA->getNumParams(), Info, Deduced,
-  TDF & TDF_TopLevelParameterTypeList))
+  TDF & TDF_TopLevelParameterTypeList, PartialOrdering))
 return Result;
 
   if (TDF & TDF_AllowCompatibleFunctionType)
@@ -2422,6 +2435,7 @@ DeduceTemplateArguments(Sema , TemplateParameterList 
*TemplateParams,
 static bool isSameTemplateArg(ASTContext ,
   TemplateArgument X,
   const TemplateArgument ,
+  bool PartialOrdering,
   bool PackExpansionMatchesPack = false) {
   // If we're checking deduced arguments (X) against original arguments (Y),
   // we will have flattened packs to non-expansions in X.
@@ -2463,16 +2477,30 @@ static bool isSameTemplateArg(ASTContext ,
 }
 
 case TemplateArgument::Pack:
-  if (X.pack_size() != Y.pack_size())
-return false;
-
-  for (TemplateArgument::pack_iterator XP = X.pack_begin(),
-XPEnd = X.pack_end(),
-   YP = Y.pack_begin();
-   XP != XPEnd; ++XP, ++YP)
-if (!isSameTemplateArg(Context, *XP, *YP, PackExpansionMatchesPack))
+  unsigned PackIterationSize = X.pack_size();
+  if (X.pack_size() != Y.pack_size()) {
+if (!PartialOrdering)
   return false;
 
+// C++0x [temp.deduct.type]p9:
+// During partial ordering, if Ai was originally a pack expansion:
+// - if P does not contain a template argument corresponding to Ai then
+//   Ai is ignored;
+bool XHasMoreArg = X.pack_size() > Y.pack_size();
+if (!(XHasMoreArg && X.pack_elements().back().isPackExpansion()) &&
+!(!XHasMoreArg && Y.pack_elements().back().isPackExpansion()))
+  return false;
+
+if (XHasMoreArg)
+  PackIterationSize = Y.pack_size();
+  }
+
+  ArrayRef XP = X.pack_elements();
+  ArrayRef 

[clang] ec08114 - [NFC][Clang] make AtomicConstraint::ParameterMapping const

2022-08-10 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-08-10T10:51:39-07:00
New Revision: ec0811413375bfe75a9361264f98ad9b5dab85b6

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

LOG: [NFC][Clang] make AtomicConstraint::ParameterMapping const

It was not const due to the way it is initialized. This is needed for
a following patch.

Added: 


Modified: 
clang/include/clang/Sema/SemaConcept.h
clang/lib/Sema/SemaConcept.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/SemaConcept.h 
b/clang/include/clang/Sema/SemaConcept.h
index b73a152533d11..a5b65f2edf940 100644
--- a/clang/include/clang/Sema/SemaConcept.h
+++ b/clang/include/clang/Sema/SemaConcept.h
@@ -28,7 +28,7 @@ class Sema;
 
 struct AtomicConstraint {
   const Expr *ConstraintExpr;
-  Optional> ParameterMapping;
+  Optional> ParameterMapping;
 
   AtomicConstraint(Sema , const Expr *ConstraintExpr) :
   ConstraintExpr(ConstraintExpr) { };

diff  --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index f0ccc0710cfb4..7545b7974ce49 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -754,14 +754,13 @@ static bool substituteParameterMappings(Sema , 
NormalizedConstraint ,
 llvm::SmallBitVector OccurringIndices(TemplateParams->size());
 S.MarkUsedTemplateParameters(Atomic.ConstraintExpr, /*OnlyDeduced=*/false,
  /*Depth=*/0, OccurringIndices);
-Atomic.ParameterMapping.emplace(
-MutableArrayRef(
-new (S.Context) TemplateArgumentLoc[OccurringIndices.count()],
-OccurringIndices.count()));
+TemplateArgumentLoc *TempArgs =
+new (S.Context) TemplateArgumentLoc[OccurringIndices.count()];
 for (unsigned I = 0, J = 0, C = TemplateParams->size(); I != C; ++I)
   if (OccurringIndices[I])
-new (&(*Atomic.ParameterMapping)[J++]) TemplateArgumentLoc(
-S.getIdentityTemplateArgumentLoc(TemplateParams->begin()[I],
+new (&(TempArgs)[J++])
+TemplateArgumentLoc(S.getIdentityTemplateArgumentLoc(
+TemplateParams->begin()[I],
 // Here we assume we do not support things like
 // template
 // concept C = ...;
@@ -770,9 +769,10 @@ static bool substituteParameterMappings(Sema , 
NormalizedConstraint ,
 // struct S { };
 // The above currently yields a diagnostic.
 // We still might have default arguments for concept 
parameters.
-ArgsAsWritten->NumTemplateArgs > I ?
-ArgsAsWritten->arguments()[I].getLocation() :
-SourceLocation()));
+ArgsAsWritten->NumTemplateArgs > I
+? ArgsAsWritten->arguments()[I].getLocation()
+: SourceLocation()));
+Atomic.ParameterMapping.emplace(TempArgs,  OccurringIndices.count());
   }
   Sema::InstantiatingTemplate Inst(
   S, ArgsAsWritten->arguments().front().getSourceRange().getBegin(),
@@ -781,12 +781,12 @@ static bool substituteParameterMappings(Sema , 
NormalizedConstraint ,
   
ArgsAsWritten->arguments().back().getSourceRange().getEnd()));
   if (S.SubstTemplateArguments(*Atomic.ParameterMapping, MLTAL, SubstArgs))
 return true;
-  Atomic.ParameterMapping.emplace(
-MutableArrayRef(
-new (S.Context) TemplateArgumentLoc[SubstArgs.size()],
-SubstArgs.size()));
+
+  TemplateArgumentLoc *TempArgs =
+  new (S.Context) TemplateArgumentLoc[SubstArgs.size()];
   std::copy(SubstArgs.arguments().begin(), SubstArgs.arguments().end(),
-N.getAtomicConstraint()->ParameterMapping->begin());
+TempArgs);
+  Atomic.ParameterMapping.emplace(TempArgs, SubstArgs.size());
   return false;
 }
 



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


[clang] 92c1bc6 - [CodeGen][inlineasm] assume the flag output of inline asm is boolean value

2022-08-02 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-08-02T11:49:01-07:00
New Revision: 92c1bc61586c9d6c7bf0c36b1005fe00b4f48cc0

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

LOG: [CodeGen][inlineasm] assume the flag output of inline asm is boolean value

GCC inline asm document says that
"... the general rule is that the output variable must be a scalar
integer, and the value is boolean."

Commit e5c37958f901cc9bec50624dbee85d40143e4bca lowers flag output of
inline asm on X86 with setcc, hence it is guaranteed that the flag
is of boolean value. Clang does not support ARM inline asm flag output
yet so nothing need to be worried about ARM.

See "Flag Output" section at
https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#OutputOperands

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

Reviewed By: nikic

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

Added: 


Modified: 
clang/lib/CodeGen/CGStmt.cpp
clang/test/CodeGen/inline-asm-x86-flag-output.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 05ab16668743b..481438de0e53a 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -2343,6 +2343,7 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt ) {
   std::vector ArgElemTypes;
   std::vector Args;
   llvm::BitVector ResultTypeRequiresCast;
+  llvm::BitVector ResultRegIsFlagReg;
 
   // Keep track of inout constraints.
   std::string InOutConstraints;
@@ -2400,6 +2401,9 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt ) {
   ResultRegQualTys.push_back(QTy);
   ResultRegDests.push_back(Dest);
 
+  bool IsFlagReg = llvm::StringRef(OutputConstraint).startswith("{@cc");
+  ResultRegIsFlagReg.push_back(IsFlagReg);
+
   llvm::Type *Ty = ConvertTypeForMem(QTy);
   const bool RequiresCast = Info.allowsRegister() &&
   (getTargetHooks().isScalarizableAsmOperand(*this, Ty) ||
@@ -2717,10 +2721,21 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt ) {
   // ResultRegDests can be also populated by addReturnRegisterOutputs() above,
   // in which case its size may grow.
   assert(ResultTypeRequiresCast.size() <= ResultRegDests.size());
+  assert(ResultRegIsFlagReg.size() <= ResultRegDests.size());
   for (unsigned i = 0, e = RegResults.size(); i != e; ++i) {
 llvm::Value *Tmp = RegResults[i];
 llvm::Type *TruncTy = ResultTruncRegTypes[i];
 
+if ((i < ResultRegIsFlagReg.size()) && ResultRegIsFlagReg[i]) {
+  // Target must guarantee the Value `Tmp` here is lowered to a boolean
+  // value.
+  llvm::Constant *Two = llvm::ConstantInt::get(Tmp->getType(), 2);
+  llvm::Value *IsBooleanValue =
+  Builder.CreateCmp(llvm::CmpInst::ICMP_ULT, Tmp, Two);
+  llvm::Function *FnAssume = CGM.getIntrinsic(llvm::Intrinsic::assume);
+  Builder.CreateCall(FnAssume, IsBooleanValue);
+}
+
 // If the result type of the LLVM IR asm doesn't match the result type of
 // the expression, do the conversion.
 if (ResultRegTypes[i] != ResultTruncRegTypes[i]) {

diff  --git a/clang/test/CodeGen/inline-asm-x86-flag-output.c 
b/clang/test/CodeGen/inline-asm-x86-flag-output.c
index 4c7e750e6d939..732714388c195 100644
--- a/clang/test/CodeGen/inline-asm-x86-flag-output.c
+++ b/clang/test/CodeGen/inline-asm-x86-flag-output.c
@@ -374,3 +374,22 @@ _Bool check_no_clobber_conflicts(void) {
   : "cx");
   return b;
 }
+
+int test_assume_boolean_flag(long nr, volatile long *addr) {
+  //CHECK-LABEL: @test_assume_boolean_flag
+  //CHECK: %0 = tail call { i32, i32 } asm "cmp $2,$1", 
"={@cca},={@ccae},=*m,r,~{cc},~{dirflag},~{fpsr},~{flags}"(i64* 
elementtype(i64) %addr, i64 %nr)
+  //CHECK: [[RES1:%.*]] = extractvalue { i32, i32 } %0, 0
+  //CHECK: [[RES2:%.*]] = extractvalue { i32, i32 } %0, 1
+  //CHECK: %1 = icmp ult i32 [[RES1]], 2
+  //CHECK: tail call void @llvm.assume(i1 %1)
+  //CHECK: %2 = icmp ult i32 [[RES2]], 2
+  //CHECK: tail call void @llvm.assume(i1 %2)
+  int x,y;
+  asm("cmp %2,%1"
+  : "=@cca"(x), "=@ccae"(y), "=m"(*(volatile long *)(addr))
+  : "r"(nr)
+  : "cc");
+  if (x)
+return 0;
+  return 1;
+}



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


[clang] fcb7d76 - [coroutine] add nomerge function attribute to `llvm.coro.save`

2022-07-12 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-07-12T10:39:38-07:00
New Revision: fcb7d76d65e8df04ea54058cb5e9f2d63b13787a

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

LOG: [coroutine] add nomerge function attribute to `llvm.coro.save`

It is illegal to merge two `llvm.coro.save` calls unless their
`llvm.coro.suspend` users are also merged. Marks it "nomerge" for
the moment.

This reverts D129025.

Alternative to D129025, which affects other token type users like WinEH.

Reviewed By: ChuanqiXu

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

Added: 
llvm/test/Transforms/Coroutines/coro-save-nomerge.ll

Modified: 
clang/test/CodeGenCoroutines/coro-attributes.cpp
llvm/docs/Coroutines.rst
llvm/include/llvm/IR/Intrinsics.td
llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Removed: 
llvm/test/Transforms/SimplifyCFG/hoist-skip-token.ll



diff  --git a/clang/test/CodeGenCoroutines/coro-attributes.cpp 
b/clang/test/CodeGenCoroutines/coro-attributes.cpp
index ecd298e6b4b57..8f171771a8cbc 100644
--- a/clang/test/CodeGenCoroutines/coro-attributes.cpp
+++ b/clang/test/CodeGenCoroutines/coro-attributes.cpp
@@ -14,7 +14,9 @@ struct coro {
 };
 
 // CHECK: void @_Z3foov() #[[FOO_ATTR_NUM:[0-9]+]]
+// CHECK: declare token @llvm.coro.save(ptr) #[[SAVE_ATTR_NUM:[0-9]+]]
 // CHECK: attributes #[[FOO_ATTR_NUM]] = { {{.*}} presplitcoroutine
+// CHECK: attributes #[[SAVE_ATTR_NUM]] = { {{.*}}nomerge
 coro foo() {
   co_await suspend_always{};
 }

diff  --git a/llvm/docs/Coroutines.rst b/llvm/docs/Coroutines.rst
index f20284a74d5a5..df05d02649679 100644
--- a/llvm/docs/Coroutines.rst
+++ b/llvm/docs/Coroutines.rst
@@ -1555,7 +1555,9 @@ Overview:
 
 The '``llvm.coro.save``' marks the point where a coroutine need to update its
 state to prepare for resumption to be considered suspended (and thus eligible
-for resumption).
+for resumption). It is illegal to merge two '``llvm.coro.save``' calls unless 
their
+'``llvm.coro.suspend``' users are also merged. So '``llvm.coro.save``' is 
currently
+tagged with the `no_merge` function attribute.
 
 Arguments:
 ""

diff  --git a/llvm/include/llvm/IR/Intrinsics.td 
b/llvm/include/llvm/IR/Intrinsics.td
index 0dceea13ea366..8bf8e9ca76adf 100644
--- a/llvm/include/llvm/IR/Intrinsics.td
+++ b/llvm/include/llvm/IR/Intrinsics.td
@@ -1308,7 +1308,7 @@ def int_coro_noop : Intrinsic<[llvm_ptr_ty], [], 
[IntrNoMem]>;
 def int_coro_size : Intrinsic<[llvm_anyint_ty], [], [IntrNoMem]>;
 def int_coro_align : Intrinsic<[llvm_anyint_ty], [], [IntrNoMem]>;
 
-def int_coro_save : Intrinsic<[llvm_token_ty], [llvm_ptr_ty], []>;
+def int_coro_save : Intrinsic<[llvm_token_ty], [llvm_ptr_ty], [IntrNoMerge]>;
 def int_coro_suspend : Intrinsic<[llvm_i8_ty], [llvm_token_ty, llvm_i1_ty], 
[]>;
 def int_coro_suspend_retcon : Intrinsic<[llvm_any_ty], [llvm_vararg_ty], []>;
 def int_coro_prepare_retcon : Intrinsic<[llvm_ptr_ty], [llvm_ptr_ty],

diff  --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp 
b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 86b2128a19374..c1d9de197a6bf 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -1499,10 +1499,6 @@ bool SimplifyCFGOpt::HoistThenElseCodeToIf(BranchInst 
*BI,
 if (I1->isTerminator())
   goto HoistTerminator;
 
-// Hoisting token-returning instructions would obscure the origin.
-if (I1->getType()->isTokenTy())
-  return Changed;
-
 // If we're going to hoist a call, make sure that the two instructions 
we're
 // commoning/hoisting are both marked with musttail, or neither of them is
 // marked as such. Otherwise, we might end up in a situation where we hoist

diff  --git a/llvm/test/Transforms/Coroutines/coro-save-nomerge.ll 
b/llvm/test/Transforms/Coroutines/coro-save-nomerge.ll
new file mode 100644
index 0..17dfe2c269207
--- /dev/null
+++ b/llvm/test/Transforms/Coroutines/coro-save-nomerge.ll
@@ -0,0 +1,75 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -passes='simplifycfg' -S | FileCheck %s
+
+declare token @llvm.coro.save(ptr) #0
+declare i8 @llvm.coro.suspend(token, i1)
+
+define void @final_nonfinal_suspend(i32 %x) {
+; CHECK-LABEL: @final_nonfinal_suspend(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
+; CHECK-NEXT:br i1 [[CMP]], label [[AWAIT_SUSPEND:%.*]], label 
[[FINAL_SUSPEND:%.*]]
+; CHECK:   await.suspend:
+; CHECK-NEXT:[[TMP0:%.*]] = call token @llvm.coro.save(ptr null)
+; CHECK-NEXT:[[TMP1:%.*]] = call i8 @llvm.coro.suspend(token [[TMP0]], i1 
false)
+; CHECK-NEXT:br label [[CORO_RET:%.*]]
+; CHECK:   final.suspend:
+; CHECK-NEXT:[[TMP2:%.*]] = call token @llvm.coro.save(ptr null)
+; CHECK-NEXT:

[clang] 6678f8e - [ubsan] Using metadata instead of prologue data for function sanitizer

2022-06-27 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-06-27T12:09:13-07:00
New Revision: 6678f8e505b19069a9dbdc3e3ee088d543752412

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

LOG: [ubsan] Using metadata instead of prologue data for function sanitizer

Information in the function `Prologue Data` is intentionally opaque.
When a function with `Prologue Data` is duplicated. The self (global
value) references inside `Prologue Data` is still pointing to the
original function. This may cause errors like `fatal error: error in backend: 
Cannot represent a difference across sections`.

This patch detaches the information from function `Prologue Data`
and attaches it to a function metadata node.

This and D116130 fix https://github.com/llvm/llvm-project/issues/49689.

Reviewed By: pcc

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

Added: 
llvm/test/CodeGen/X86/func-sanitizer.ll

Modified: 
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenModule.h
clang/lib/Driver/SanitizerArgs.cpp
clang/test/CodeGen/ubsan-function.cpp
clang/test/CodeGenCXX/catch-undef-behavior.cpp
clang/test/CodeGenCXX/ubsan-function-noexcept.cpp
clang/test/Driver/fsanitize.c
llvm/docs/LangRef.rst
llvm/include/llvm/IR/FixedMetadataKinds.def
llvm/include/llvm/IR/MDBuilder.h
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/lib/IR/MDBuilder.cpp
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 4255f1ca9759c..05942f462dd1d 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -559,29 +559,6 @@ bool CodeGenFunction::AlwaysEmitXRayTypedEvents() const {
   XRayInstrKind::Typed);
 }
 
-llvm::Constant *
-CodeGenFunction::EncodeAddrForUseInPrologue(llvm::Function *F,
-llvm::Constant *Addr) {
-  // Addresses stored in prologue data can't require run-time fixups and must
-  // be PC-relative. Run-time fixups are undesirable because they necessitate
-  // writable text segments, which are unsafe. And absolute addresses are
-  // undesirable because they break PIE mode.
-
-  // Add a layer of indirection through a private global. Taking its address
-  // won't result in a run-time fixup, even if Addr has linkonce_odr linkage.
-  auto *GV = new llvm::GlobalVariable(CGM.getModule(), Addr->getType(),
-  /*isConstant=*/true,
-  llvm::GlobalValue::PrivateLinkage, Addr);
-
-  // Create a PC-relative address.
-  auto *GOTAsInt = llvm::ConstantExpr::getPtrToInt(GV, IntPtrTy);
-  auto *FuncAsInt = llvm::ConstantExpr::getPtrToInt(F, IntPtrTy);
-  auto *PCRelAsInt = llvm::ConstantExpr::getSub(GOTAsInt, FuncAsInt);
-  return (IntPtrTy == Int32Ty)
- ? PCRelAsInt
- : llvm::ConstantExpr::getTrunc(PCRelAsInt, Int32Ty);
-}
-
 llvm::Value *
 CodeGenFunction::DecodeAddrUsedInPrologue(llvm::Value *F,
   llvm::Value *EncodedAddr) {
@@ -937,12 +914,13 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, 
QualType RetTy,
   FD->getType(), EST_None);
   llvm::Constant *FTRTTIConst =
   CGM.GetAddrOfRTTIDescriptor(ProtoTy, /*ForEH=*/true);
-  llvm::Constant *FTRTTIConstEncoded =
-  EncodeAddrForUseInPrologue(Fn, FTRTTIConst);
-  llvm::Constant *PrologueStructElems[] = {PrologueSig, 
FTRTTIConstEncoded};
-  llvm::Constant *PrologueStructConst =
-  llvm::ConstantStruct::getAnon(PrologueStructElems, /*Packed=*/true);
-  Fn->setPrologueData(PrologueStructConst);
+  llvm::GlobalVariable *FTRTTIProxy =
+  CGM.GetOrCreateRTTIProxyGlobalVariable(FTRTTIConst);
+  llvm::LLVMContext  = Fn->getContext();
+  llvm::MDBuilder MDB(Ctx);
+  Fn->setMetadata(llvm::LLVMContext::MD_func_sanitize,
+  MDB.createRTTIPointerPrologue(PrologueSig, FTRTTIProxy));
+  CGM.addCompilerUsedGlobal(FTRTTIProxy);
 }
   }
 

diff  --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index 118d3144069bd..fe0890f433e8c 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -2356,10 +2356,6 @@ class CodeGenFunction : public CodeGenTypeCache {
   /// XRay typed event handling calls.
   bool AlwaysEmitXRayTypedEvents() const;
 
-  /// Encode an address into a form suitable for use in a function prologue.
-  llvm::Constant *EncodeAddrForUseInPrologue(llvm::Function *F,
- llvm::Constant *Addr);
-
   /// 

[clang] 52af5df - [Driver][test] run one test in darwin-dsymutil.c for Darwin only

2022-05-11 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-05-11T14:45:00-07:00
New Revision: 52af5df8aef737b5b609912ea28f79fcb3d9ba22

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

LOG: [Driver][test] run one test in darwin-dsymutil.c for Darwin only

Added: 


Modified: 
clang/test/Driver/darwin-dsymutil.c

Removed: 




diff  --git a/clang/test/Driver/darwin-dsymutil.c 
b/clang/test/Driver/darwin-dsymutil.c
index 9f77e7237d023..7a6e4940afeac 100644
--- a/clang/test/Driver/darwin-dsymutil.c
+++ b/clang/test/Driver/darwin-dsymutil.c
@@ -68,4 +68,4 @@
 // RUN: not grep "Dsymutil" %t
 
 // Check that we don't crash when translating arguments for dsymutil.
-// RUN: %clang -m32 -arch x86_64 -g %s -###
+// RUN: %clang -m32 -target x86_64-apple-darwin10 -arch x86_64 -g %s -###



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


[clang] 7e80976 - [PS4] Make __BIGGEST_ALIGNMENT__ 32bytes

2022-03-17 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-03-17T10:12:38-07:00
New Revision: 7e80976fdf3f0af87780f6490f39a1d500fc9886

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

LOG: [PS4] Make __BIGGEST_ALIGNMENT__ 32bytes

So it matches `__STDCPP_DEFAULT_NEW_ALIGNMENT__`.

Reviewed By: probinson, aaron.ballman

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

Added: 


Modified: 
clang/include/clang/Basic/TargetInfo.h
clang/lib/Basic/Targets/OSTargets.h
clang/test/Preprocessor/init.c

Removed: 




diff  --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 94da7ac593a07..470d153d845de 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -101,10 +101,10 @@ struct TransferrableTargetInfo {
   unsigned char AccumScale;
   unsigned char LongAccumScale;
 
-  unsigned char SuitableAlign;
   unsigned char DefaultAlignForAttributeAligned;
   unsigned char MinGlobalAlign;
 
+  unsigned short SuitableAlign;
   unsigned short NewAlign;
   unsigned MaxVectorAlign;
   unsigned MaxTLSAlign;

diff  --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index f61652d285a89..9dd5debf1c47a 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -570,6 +570,7 @@ class LLVM_LIBRARY_VISIBILITY PS4OSTargetInfo : public 
OSTargetInfo {
 case llvm::Triple::x86_64:
   this->MCountName = ".mcount";
   this->NewAlign = 256;
+  this->SuitableAlign = 256;
   break;
 }
   }

diff  --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c
index 33354e8975fd2..2d488159ea2c6 100644
--- a/clang/test/Preprocessor/init.c
+++ b/clang/test/Preprocessor/init.c
@@ -1247,6 +1247,7 @@
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 
-triple=x86_64-scei-ps4 < /dev/null | FileCheck -match-full-lines -check-prefix 
PS4 %s
 //
 // PS4:#define _LP64 1
+// PS4:#define __BIGGEST_ALIGNMENT__ 32
 // PS4:#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
 // PS4:#define __CHAR16_TYPE__ unsigned short
 // PS4:#define __CHAR32_TYPE__ unsigned int



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


[clang] eddd94c - Reland "[clang][debug] port clang-cl /JMC flag to ELF"

2022-03-07 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-03-07T21:55:41-08:00
New Revision: eddd94c27df609113af1d1b795d8483aa6dd662c

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

LOG: Reland "[clang][debug] port clang-cl /JMC flag to ELF"

This relands commit 731347431976509823e38329a96fcbc69fe98cd2.

It failed on Windows/Mac because `-fjmc` is only checked for ELF targets.
Check the flag unconditionally instead and issue a warning for non-ELF targets.

Added: 
llvm/test/Instrumentation/JustMyCode/jmc-instrument-elf.ll

Modified: 
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
llvm/lib/CodeGen/JMCInstrumenter.cpp
llvm/test/Instrumentation/JustMyCode/jmc-instrument-x86.ll
llvm/test/Instrumentation/JustMyCode/jmc-instrument.ll

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 1ac5bf844efe6..afedb37797e32 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -634,7 +634,12 @@ def err_drv_cuda_offload_only_emit_bc : Error<
   "CUDA offload target is supported only along with --emit-llvm">;
 
 def warn_drv_jmc_requires_debuginfo : Warning<
-  "/JMC requires debug info. Use '/Zi', '/Z7' or other debug options; option 
ignored">,
+  "%0 requires debug info. Use %1 or debug options that enable debugger's "
+  "stepping function; option ignored">,
+  InGroup;
+
+def warn_drv_fjmc_for_elf_only : Warning<
+  "-fjmc works only for ELF; option ignored">,
   InGroup;
 
 def err_drv_target_variant_invalid : Error<

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 06802ae424f7a..3b7011760a5b5 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1459,9 +1459,6 @@ def fno_elide_type : Flag<["-"], "fno-elide-type">, 
Group,
 HelpText<"Do not elide types when printing diagnostics">,
 MarshallingInfoNegativeFlag>;
 def feliminate_unused_debug_symbols : Flag<["-"], 
"feliminate-unused-debug-symbols">, Group;
-def fjmc : Flag<["-"], "fjmc">, Group,Flags<[CC1Option]>,
-HelpText<"Enable just-my-code debugging">,
-MarshallingInfoFlag>;
 defm eliminate_unused_debug_types : 
OptOutCC1FFlag<"eliminate-unused-debug-types",
   "Do not emit ", "Emit ", " debug info for defined but unused types">;
 def femit_all_decls : Flag<["-"], "femit-all-decls">, Group, 
Flags<[CC1Option]>,
@@ -1923,6 +1920,10 @@ def finline_functions : Flag<["-"], 
"finline-functions">, Group,
 def finline_hint_functions: Flag<["-"], "finline-hint-functions">, 
Group, Flags<[CC1Option]>,
   HelpText<"Inline functions which are (explicitly or implicitly) marked 
inline">;
 def finline : Flag<["-"], "finline">, Group;
+defm jmc : BoolFOption<"jmc",
+  CodeGenOpts<"JMCInstrument">, DefaultFalse,
+  PosFlag,
+  NegFlag>;
 def fglobal_isel : Flag<["-"], "fglobal-isel">, Group,
   HelpText<"Enables the global instruction selector">;
 def fexperimental_isel : Flag<["-"], "fexperimental-isel">, 
Group,

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 7cb8df6e44c04..89d8b0c4dc413 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5392,6 +5392,19 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
  types::isLLVMIR(InputType), CmdArgs, DebugInfoKind,
  DwarfFission);
 
+  // This controls whether or not we perform JustMyCode instrumentation.
+  if (Args.hasFlag(options::OPT_fjmc, options::OPT_fno_jmc, false)) {
+if (TC.getTriple().isOSBinFormatELF()) {
+  if (DebugInfoKind >= codegenoptions::DebugInfoConstructor)
+CmdArgs.push_back("-fjmc");
+  else
+D.Diag(clang::diag::warn_drv_jmc_requires_debuginfo) << "-fjmc"
+ << "-g";
+} else {
+  D.Diag(clang::diag::warn_drv_fjmc_for_elf_only);
+}
+  }
+
   // Add the split debug info name to the command lines here so we
   // can propagate it to the backend.
   bool SplitDWARF = (DwarfFission != DwarfFissionKind::None) &&
@@ -7533,7 +7546,8 @@ void Clang::AddClangCLArgs(const ArgList , types::ID 
InputType,
 if (*EmitCodeView && *DebugInfoKind >= 
codegenoptions::DebugInfoConstructor)
   CmdArgs.push_back("-fjmc");
 else
-  D.Diag(clang::diag::warn_drv_jmc_requires_debuginfo);
+  D.Diag(clang::diag::warn_drv_jmc_requires_debuginfo) << "/JMC"
+   << "'/Zi', '/Z7'";
   }
 
 

[clang] f46fa4d - Revert "[clang][debug] port clang-cl /JMC flag to ELF"

2022-03-07 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-03-07T12:40:43-08:00
New Revision: f46fa4de4a95329b74ba0bb4ce9623b64ad84876

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

LOG: Revert "[clang][debug] port clang-cl /JMC flag to ELF"

This reverts commit 731347431976509823e38329a96fcbc69fe98cd2.

Break bots:
http://45.33.8.238/win/54551/step_7.txt
http://45.33.8.238/macm1/29590/step_7.txt

Added: 


Modified: 
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
llvm/lib/CodeGen/JMCInstrumenter.cpp
llvm/test/Instrumentation/JustMyCode/jmc-instrument-x86.ll
llvm/test/Instrumentation/JustMyCode/jmc-instrument.ll

Removed: 
llvm/test/Instrumentation/JustMyCode/jmc-instrument-elf.ll



diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 65b6d606a9dd0..1ac5bf844efe6 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -634,8 +634,7 @@ def err_drv_cuda_offload_only_emit_bc : Error<
   "CUDA offload target is supported only along with --emit-llvm">;
 
 def warn_drv_jmc_requires_debuginfo : Warning<
-  "%0 requires debug info. Use %1 or debug options that enable debugger's "
-  "stepping function; option ignored">,
+  "/JMC requires debug info. Use '/Zi', '/Z7' or other debug options; option 
ignored">,
   InGroup;
 
 def err_drv_target_variant_invalid : Error<

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 351eb674a109b..24e2069711be5 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1462,7 +1462,6 @@ def feliminate_unused_debug_symbols : Flag<["-"], 
"feliminate-unused-debug-symbo
 def fjmc : Flag<["-"], "fjmc">, Group,Flags<[CC1Option]>,
 HelpText<"Enable just-my-code debugging">,
 MarshallingInfoFlag>;
-def fno_jmc : Flag<["-"], "fno-jmc">, Group, Flags<[CC1Option]>;
 defm eliminate_unused_debug_types : 
OptOutCC1FFlag<"eliminate-unused-debug-types",
   "Do not emit ", "Emit ", " debug info for defined but unused types">;
 def femit_all_decls : Flag<["-"], "femit-all-decls">, Group, 
Flags<[CC1Option]>,

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 92da7a748ea8c..7cb8df6e44c04 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5392,16 +5392,6 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
  types::isLLVMIR(InputType), CmdArgs, DebugInfoKind,
  DwarfFission);
 
-  // This controls whether or not we perform JustMyCode instrumentation.
-  if (TC.getTriple().isOSBinFormatELF() &&
-  Args.hasFlag(options::OPT_fjmc, options::OPT_fno_jmc, false)) {
-if (DebugInfoKind >= codegenoptions::DebugInfoConstructor)
-  CmdArgs.push_back("-fjmc");
-else
-  D.Diag(clang::diag::warn_drv_jmc_requires_debuginfo) << "-fjmc"
-   << "-g";
-  }
-
   // Add the split debug info name to the command lines here so we
   // can propagate it to the backend.
   bool SplitDWARF = (DwarfFission != DwarfFissionKind::None) &&
@@ -7543,8 +7533,7 @@ void Clang::AddClangCLArgs(const ArgList , types::ID 
InputType,
 if (*EmitCodeView && *DebugInfoKind >= 
codegenoptions::DebugInfoConstructor)
   CmdArgs.push_back("-fjmc");
 else
-  D.Diag(clang::diag::warn_drv_jmc_requires_debuginfo) << "/JMC"
-   << "'/Zi', '/Z7'";
+  D.Diag(clang::diag::warn_drv_jmc_requires_debuginfo);
   }
 
   EHFlags EH = parseClangCLEHFlags(D, Args);

diff  --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index f332cd83b26e4..4a8a1b3c5ac4e 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -779,7 +779,7 @@
 // TARGET: "-triple" "i686-pc-windows-msvc19.14.0"
 
 // RUN: %clang_cl /JMC /c -### -- %s 2>&1 | FileCheck %s --check-prefix JMCWARN
-// JMCWARN: /JMC requires debug info. Use '/Zi', '/Z7' or debug options that 
enable debugger's stepping function; option ignored
+// JMCWARN: /JMC requires debug info. Use '/Zi', '/Z7' or other debug options; 
option ignored
 
 // RUN: %clang_cl /JMC /c -### -- %s 2>&1 | FileCheck %s --check-prefix NOJMC
 // RUN: %clang_cl /JMC /Z7 /JMC- /c -### -- %s 2>&1 | FileCheck %s 
--check-prefix NOJMC

diff  --git a/clang/test/Driver/clang_f_opts.c 
b/clang/test/Driver/clang_f_opts.c
index dca7d8c9e83ba..4b0159b80f739 100644
--- a/clang/test/Driver/clang_f_opts.c

[clang] 7313474 - [clang][debug] port clang-cl /JMC flag to ELF

2022-03-07 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-03-07T10:16:24-08:00
New Revision: 731347431976509823e38329a96fcbc69fe98cd2

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

LOG: [clang][debug] port clang-cl /JMC flag to ELF

The motivation is to enable the MSVC-style JMC instrumentation usable by a 
ELF-based
debugger. Since there is no prior experience implementing JMC feature for 
ELF-based
debugger, it might be better to just reuse existing MSVC-style JMC 
instrumentation.
For debuggers that support both ELF (like lldb), the JMC implementation 
might
be shared between ELF If this is found to inadequate, it is pretty 
low-cost
switching to alternatives.

Implementation:
- The '-fjmc' is already a driver and cc1 flag. Wire it up for ELF in the 
driver.
- Refactor the JMC instrumentation pass a little bit.
- The ELF handling is different from MSVC in two places:
  * the flag section name is ".just.my.code" instead of ".msvcjmc"
  * the way default function is provided: MSVC uses /alternatename; ELF uses 
weak function.

Based on D118428.

Reviewed By: rnk

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

Added: 
llvm/test/Instrumentation/JustMyCode/jmc-instrument-elf.ll

Modified: 
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
llvm/lib/CodeGen/JMCInstrumenter.cpp
llvm/test/Instrumentation/JustMyCode/jmc-instrument-x86.ll
llvm/test/Instrumentation/JustMyCode/jmc-instrument.ll

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 1ac5bf844efe6..65b6d606a9dd0 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -634,7 +634,8 @@ def err_drv_cuda_offload_only_emit_bc : Error<
   "CUDA offload target is supported only along with --emit-llvm">;
 
 def warn_drv_jmc_requires_debuginfo : Warning<
-  "/JMC requires debug info. Use '/Zi', '/Z7' or other debug options; option 
ignored">,
+  "%0 requires debug info. Use %1 or debug options that enable debugger's "
+  "stepping function; option ignored">,
   InGroup;
 
 def err_drv_target_variant_invalid : Error<

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 24e2069711be5..351eb674a109b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1462,6 +1462,7 @@ def feliminate_unused_debug_symbols : Flag<["-"], 
"feliminate-unused-debug-symbo
 def fjmc : Flag<["-"], "fjmc">, Group,Flags<[CC1Option]>,
 HelpText<"Enable just-my-code debugging">,
 MarshallingInfoFlag>;
+def fno_jmc : Flag<["-"], "fno-jmc">, Group, Flags<[CC1Option]>;
 defm eliminate_unused_debug_types : 
OptOutCC1FFlag<"eliminate-unused-debug-types",
   "Do not emit ", "Emit ", " debug info for defined but unused types">;
 def femit_all_decls : Flag<["-"], "femit-all-decls">, Group, 
Flags<[CC1Option]>,

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 7cb8df6e44c04..92da7a748ea8c 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5392,6 +5392,16 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
  types::isLLVMIR(InputType), CmdArgs, DebugInfoKind,
  DwarfFission);
 
+  // This controls whether or not we perform JustMyCode instrumentation.
+  if (TC.getTriple().isOSBinFormatELF() &&
+  Args.hasFlag(options::OPT_fjmc, options::OPT_fno_jmc, false)) {
+if (DebugInfoKind >= codegenoptions::DebugInfoConstructor)
+  CmdArgs.push_back("-fjmc");
+else
+  D.Diag(clang::diag::warn_drv_jmc_requires_debuginfo) << "-fjmc"
+   << "-g";
+  }
+
   // Add the split debug info name to the command lines here so we
   // can propagate it to the backend.
   bool SplitDWARF = (DwarfFission != DwarfFissionKind::None) &&
@@ -7533,7 +7543,8 @@ void Clang::AddClangCLArgs(const ArgList , types::ID 
InputType,
 if (*EmitCodeView && *DebugInfoKind >= 
codegenoptions::DebugInfoConstructor)
   CmdArgs.push_back("-fjmc");
 else
-  D.Diag(clang::diag::warn_drv_jmc_requires_debuginfo);
+  D.Diag(clang::diag::warn_drv_jmc_requires_debuginfo) << "/JMC"
+   << "'/Zi', '/Z7'";
   }
 
   EHFlags EH = parseClangCLEHFlags(D, Args);

diff  --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index 4a8a1b3c5ac4e..f332cd83b26e4 100644
--- a/clang/test/Driver/cl-options.c
+++ 

[clang] f927021 - Reland "[clang-cl] Support the /JMC flag"

2022-02-10 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-02-10T15:16:17-08:00
New Revision: f927021410691bc2612cfb635b1d9cf9b94977e6

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

LOG: Reland "[clang-cl] Support the /JMC flag"

This relands commit b380a31de084a540cfa38b72e609b25ea0569bb7.

Restrict the tests to Windows only since the flag symbol hash depends on
system-dependent path normalization.

Added: 
llvm/lib/CodeGen/JMCInstrumenter.cpp
llvm/test/Instrumentation/JustMyCode/jmc-instrument-x86.ll
llvm/test/Instrumentation/JustMyCode/jmc-instrument.ll

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/cl-options.c
llvm/include/llvm/CodeGen/CommandFlags.h
llvm/include/llvm/CodeGen/Passes.h
llvm/include/llvm/InitializePasses.h
llvm/include/llvm/LinkAllPasses.h
llvm/include/llvm/Target/TargetOptions.h
llvm/lib/CodeGen/CMakeLists.txt
llvm/lib/CodeGen/CodeGen.cpp
llvm/lib/CodeGen/CommandFlags.cpp
llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
llvm/lib/Target/ARM/ARMTargetMachine.cpp
llvm/lib/Target/X86/X86TargetMachine.cpp
llvm/tools/opt/opt.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9055514d80293..ba8e028eb6aea 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -80,6 +80,12 @@ Attribute Changes in Clang
 Windows Support
 ---
 
+- Add support for MSVC-compatible ``/JMC``/``/JMC-`` flag in clang-cl (supports
+  X86/X64/ARM/ARM64). ``/JMC`` could only be used when ``/Zi`` or ``/Z7`` is
+  turned on. With this addition, clang-cl can be used in Visual Studio for the
+  JustMyCode feature. Note, you may need to manually add ``/JMC`` as additional
+  compile options in the Visual Studio since it currently assumes clang-cl 
does not support ``/JMC``.
+
 C Language Changes in Clang
 ---
 

diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index ec1b13f40d453..1df5168c7d4ec 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -144,6 +144,7 @@ VALUE_CODEGENOPT(PatchableFunctionEntryOffset , 32, 0)
 CODEGENOPT(HotPatch, 1, 0) ///< Supports the Microsoft /HOTPATCH flag and
///< generates a 'patchable-function' attribute.
 
+CODEGENOPT(JMCInstrument, 1, 0) ///< Set when -fjmc is enabled.
 CODEGENOPT(InstrumentForProfiling , 1, 0) ///< Set when -pg is enabled.
 CODEGENOPT(CallFEntry , 1, 0) ///< Set when -mfentry is enabled.
 CODEGENOPT(MNopMCount , 1, 0) ///< Set when -mnop-mcount is enabled.

diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 51a10ab54953c..427cb788c3a4c 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -633,4 +633,8 @@ def err_drv_invalid_or_unsupported_offload_target : Error<
   "invalid or unsupported offload target: '%0'">;
 def err_drv_cuda_offload_only_emit_bc : Error<
   "CUDA offload target is supported only along with --emit-llvm">;
+
+def warn_drv_jmc_requires_debuginfo : Warning<
+  "/JMC requires debug info. Use '/Zi', '/Z7' or other debug options; option 
ignored">,
+  InGroup;
 }

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d668118e58a0b..6be3aa117220e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1446,6 +1446,9 @@ def fno_elide_type : Flag<["-"], "fno-elide-type">, 
Group,
 HelpText<"Do not elide types when printing diagnostics">,
 MarshallingInfoNegativeFlag>;
 def feliminate_unused_debug_symbols : Flag<["-"], 
"feliminate-unused-debug-symbols">, Group;
+def fjmc : Flag<["-"], "fjmc">, Group,Flags<[CC1Option]>,
+HelpText<"Enable just-my-code debugging">,
+MarshallingInfoFlag>;
 defm eliminate_unused_debug_types : 
OptOutCC1FFlag<"eliminate-unused-debug-types",
   "Do not emit ", "Emit ", " debug info for defined but unused types">;
 def femit_all_decls : Flag<["-"], "femit-all-decls">, Group, 
Flags<[CC1Option]>,
@@ -6361,6 +6364,10 @@ def _SLASH_GX_ : CLFlag<"GX-">,
 def _SLASH_imsvc : CLJoinedOrSeparate<"imsvc">,
   HelpText<"Add  to system include search path, as if in %INCLUDE%">,
   MetaVarName<"">;
+def _SLASH_JMC : CLFlag<"JMC">,
+  HelpText<"Enable just-my-code debugging">;
+def _SLASH_JMC_ : CLFlag<"JMC-">,
+  HelpText<"Disable just-my-code debugging 

[clang] b380a31 - Revert "[clang-cl] Support the /JMC flag"

2022-02-10 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-02-10T14:17:37-08:00
New Revision: b380a31de084a540cfa38b72e609b25ea0569bb7

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

LOG: Revert "[clang-cl] Support the /JMC flag"

This reverts commit bd3a1de683f80d174ea9c97000db3ec3276bc022.

Break bots:
https://luci-milo.appspot.com/ui/p/fuchsia/builders/toolchain.ci/clang-windows-x64/b8822587673277278177/overview

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/cl-options.c
llvm/include/llvm/CodeGen/CommandFlags.h
llvm/include/llvm/CodeGen/Passes.h
llvm/include/llvm/InitializePasses.h
llvm/include/llvm/LinkAllPasses.h
llvm/include/llvm/Target/TargetOptions.h
llvm/lib/CodeGen/CMakeLists.txt
llvm/lib/CodeGen/CodeGen.cpp
llvm/lib/CodeGen/CommandFlags.cpp
llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
llvm/lib/Target/ARM/ARMTargetMachine.cpp
llvm/lib/Target/X86/X86TargetMachine.cpp
llvm/tools/opt/opt.cpp

Removed: 
llvm/lib/CodeGen/JMCInstrumenter.cpp
llvm/test/Instrumentation/JustMyCode/jmc-instrument-x86.ll
llvm/test/Instrumentation/JustMyCode/jmc-instrument.ll



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ba8e028eb6aea..9055514d80293 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -80,12 +80,6 @@ Attribute Changes in Clang
 Windows Support
 ---
 
-- Add support for MSVC-compatible ``/JMC``/``/JMC-`` flag in clang-cl (supports
-  X86/X64/ARM/ARM64). ``/JMC`` could only be used when ``/Zi`` or ``/Z7`` is
-  turned on. With this addition, clang-cl can be used in Visual Studio for the
-  JustMyCode feature. Note, you may need to manually add ``/JMC`` as additional
-  compile options in the Visual Studio since it currently assumes clang-cl 
does not support ``/JMC``.
-
 C Language Changes in Clang
 ---
 

diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 1df5168c7d4ec..ec1b13f40d453 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -144,7 +144,6 @@ VALUE_CODEGENOPT(PatchableFunctionEntryOffset , 32, 0)
 CODEGENOPT(HotPatch, 1, 0) ///< Supports the Microsoft /HOTPATCH flag and
///< generates a 'patchable-function' attribute.
 
-CODEGENOPT(JMCInstrument, 1, 0) ///< Set when -fjmc is enabled.
 CODEGENOPT(InstrumentForProfiling , 1, 0) ///< Set when -pg is enabled.
 CODEGENOPT(CallFEntry , 1, 0) ///< Set when -mfentry is enabled.
 CODEGENOPT(MNopMCount , 1, 0) ///< Set when -mnop-mcount is enabled.

diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 427cb788c3a4c..51a10ab54953c 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -633,8 +633,4 @@ def err_drv_invalid_or_unsupported_offload_target : Error<
   "invalid or unsupported offload target: '%0'">;
 def err_drv_cuda_offload_only_emit_bc : Error<
   "CUDA offload target is supported only along with --emit-llvm">;
-
-def warn_drv_jmc_requires_debuginfo : Warning<
-  "/JMC requires debug info. Use '/Zi', '/Z7' or other debug options; option 
ignored">,
-  InGroup;
 }

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 6be3aa117220e..d668118e58a0b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1446,9 +1446,6 @@ def fno_elide_type : Flag<["-"], "fno-elide-type">, 
Group,
 HelpText<"Do not elide types when printing diagnostics">,
 MarshallingInfoNegativeFlag>;
 def feliminate_unused_debug_symbols : Flag<["-"], 
"feliminate-unused-debug-symbols">, Group;
-def fjmc : Flag<["-"], "fjmc">, Group,Flags<[CC1Option]>,
-HelpText<"Enable just-my-code debugging">,
-MarshallingInfoFlag>;
 defm eliminate_unused_debug_types : 
OptOutCC1FFlag<"eliminate-unused-debug-types",
   "Do not emit ", "Emit ", " debug info for defined but unused types">;
 def femit_all_decls : Flag<["-"], "femit-all-decls">, Group, 
Flags<[CC1Option]>,
@@ -6364,10 +6361,6 @@ def _SLASH_GX_ : CLFlag<"GX-">,
 def _SLASH_imsvc : CLJoinedOrSeparate<"imsvc">,
   HelpText<"Add  to system include search path, as if in %INCLUDE%">,
   MetaVarName<"">;
-def _SLASH_JMC : CLFlag<"JMC">,
-  HelpText<"Enable just-my-code debugging">;
-def _SLASH_JMC_ : CLFlag<"JMC-">,
-  HelpText<"Disable just-my-code 

[clang] bd3a1de - [clang-cl] Support the /JMC flag

2022-02-10 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-02-10T10:26:30-08:00
New Revision: bd3a1de683f80d174ea9c97000db3ec3276bc022

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

LOG: [clang-cl] Support the /JMC flag

The introduction and some examples are on this page:
https://devblogs.microsoft.com/cppblog/announcing-jmc-stepping-in-visual-studio/

The `/JMC` flag enables these instrumentations:
- Insert at the beginning of every function immediately after the prologue with
  a call to `void __fastcall __CheckForDebuggerJustMyCode(unsigned char 
*JMC_flag)`.
  The argument for `__CheckForDebuggerJustMyCode` is the address of a boolean
  global variable (the global variable is initialized to 1) with the name
  convention `___`. All such global variables are placed in
  the `.msvcjmc` section.
- The `` part of `___` has a one-to-one mapping
  with a directory path. MSVC uses some unknown hashing function. Here I
  used DJB.
- Add a dummy/empty COMDAT function `__JustMyCode_Default`.
- Add `/alternatename:__CheckForDebuggerJustMyCode=__JustMyCode_Default` link
  option via ".drectve" section. This is to prevent failure in
  case `__CheckForDebuggerJustMyCode` is not provided during linking.

Implementation:
All the instrumentations are implemented in an IR codegen pass. The pass is 
placed immediately before CodeGenPrepare pass. This is to not interfere with 
mid-end optimizations and make the instrumentation target-independent (I'm 
still working on an ELF port in a separate patch).

Reviewed By: hans

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

Added: 
llvm/lib/CodeGen/JMCInstrumenter.cpp
llvm/test/Instrumentation/JustMyCode/jmc-instrument-x86.ll
llvm/test/Instrumentation/JustMyCode/jmc-instrument.ll

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/cl-options.c
llvm/include/llvm/CodeGen/CommandFlags.h
llvm/include/llvm/CodeGen/Passes.h
llvm/include/llvm/InitializePasses.h
llvm/include/llvm/LinkAllPasses.h
llvm/include/llvm/Target/TargetOptions.h
llvm/lib/CodeGen/CMakeLists.txt
llvm/lib/CodeGen/CodeGen.cpp
llvm/lib/CodeGen/CommandFlags.cpp
llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
llvm/lib/Target/ARM/ARMTargetMachine.cpp
llvm/lib/Target/X86/X86TargetMachine.cpp
llvm/tools/opt/opt.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9055514d80293..ba8e028eb6aea 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -80,6 +80,12 @@ Attribute Changes in Clang
 Windows Support
 ---
 
+- Add support for MSVC-compatible ``/JMC``/``/JMC-`` flag in clang-cl (supports
+  X86/X64/ARM/ARM64). ``/JMC`` could only be used when ``/Zi`` or ``/Z7`` is
+  turned on. With this addition, clang-cl can be used in Visual Studio for the
+  JustMyCode feature. Note, you may need to manually add ``/JMC`` as additional
+  compile options in the Visual Studio since it currently assumes clang-cl 
does not support ``/JMC``.
+
 C Language Changes in Clang
 ---
 

diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index ec1b13f40d453..1df5168c7d4ec 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -144,6 +144,7 @@ VALUE_CODEGENOPT(PatchableFunctionEntryOffset , 32, 0)
 CODEGENOPT(HotPatch, 1, 0) ///< Supports the Microsoft /HOTPATCH flag and
///< generates a 'patchable-function' attribute.
 
+CODEGENOPT(JMCInstrument, 1, 0) ///< Set when -fjmc is enabled.
 CODEGENOPT(InstrumentForProfiling , 1, 0) ///< Set when -pg is enabled.
 CODEGENOPT(CallFEntry , 1, 0) ///< Set when -mfentry is enabled.
 CODEGENOPT(MNopMCount , 1, 0) ///< Set when -mnop-mcount is enabled.

diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 51a10ab54953c..427cb788c3a4c 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -633,4 +633,8 @@ def err_drv_invalid_or_unsupported_offload_target : Error<
   "invalid or unsupported offload target: '%0'">;
 def err_drv_cuda_offload_only_emit_bc : Error<
   "CUDA offload target is supported only along with --emit-llvm">;
+
+def warn_drv_jmc_requires_debuginfo : Warning<
+  "/JMC requires debug info. Use '/Zi', '/Z7' or other debug options; option 
ignored">,
+  InGroup;
 }

diff  --git 

[clang] b96106a - [AArch64][ARM] add -Wunaligned-access only for clang

2022-02-10 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-02-10T10:26:30-08:00
New Revision: b96106af3f557da833b5e3b9ef9194c23ecd1596

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

LOG: [AArch64][ARM] add -Wunaligned-access only for clang

Reviewed By: lenary

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Arch/AArch64.cpp
clang/lib/Driver/ToolChains/Arch/AArch64.h
clang/lib/Driver/ToolChains/Arch/ARM.cpp
clang/lib/Driver/ToolChains/Arch/ARM.h
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/arm-alignment.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp 
b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
index ca0ca4bf4eeac..6e3e3d04bbe3a 100644
--- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -222,7 +222,6 @@ getAArch64MicroArchFeaturesFromMcpu(const Driver , 
StringRef Mcpu,
 void aarch64::getAArch64TargetFeatures(const Driver ,
const llvm::Triple ,
const ArgList ,
-   llvm::opt::ArgStringList ,
std::vector ,
bool ForAS) {
   Arg *A;
@@ -466,16 +465,10 @@ void aarch64::getAArch64TargetFeatures(const Driver ,
 
   if (Arg *A = Args.getLastArg(options::OPT_mno_unaligned_access,
options::OPT_munaligned_access)) {
-if (A->getOption().matches(options::OPT_mno_unaligned_access)) {
+if (A->getOption().matches(options::OPT_mno_unaligned_access))
   Features.push_back("+strict-align");
-  if (!ForAS)
-CmdArgs.push_back("-Wunaligned-access");
-}
-  } else if (Triple.isOSOpenBSD()) {
+  } else if (Triple.isOSOpenBSD())
 Features.push_back("+strict-align");
-if (!ForAS)
-  CmdArgs.push_back("-Wunaligned-access");
-  }
 
   if (Args.hasArg(options::OPT_ffixed_x1))
 Features.push_back("+reserve-x1");

diff  --git a/clang/lib/Driver/ToolChains/Arch/AArch64.h 
b/clang/lib/Driver/ToolChains/Arch/AArch64.h
index 0cdc2ec725e02..d47c402d4a42d 100644
--- a/clang/lib/Driver/ToolChains/Arch/AArch64.h
+++ b/clang/lib/Driver/ToolChains/Arch/AArch64.h
@@ -22,7 +22,6 @@ namespace aarch64 {
 
 void getAArch64TargetFeatures(const Driver , const llvm::Triple ,
   const llvm::opt::ArgList ,
-  llvm::opt::ArgStringList ,
   std::vector ,
   bool ForAS);
 

diff  --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp 
b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
index 16af9f6d71295..2d961f6e836ff 100644
--- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -434,7 +434,7 @@ static bool hasIntegerMVE(const std::vector ) {
 }
 
 void arm::getARMTargetFeatures(const Driver , const llvm::Triple ,
-   const ArgList , ArgStringList ,
+   const ArgList ,
std::vector , bool ForAS) {
   bool KernelOrKext =
   Args.hasArg(options::OPT_mkernel, options::OPT_fapple_kext);
@@ -772,8 +772,6 @@ void arm::getARMTargetFeatures(const Driver , const 
llvm::Triple ,
   // Kernel code has more strict alignment requirements.
   if (KernelOrKext) {
 Features.push_back("+strict-align");
-if (!ForAS)
-  CmdArgs.push_back("-Wunaligned-access");
   } else if (Arg *A = Args.getLastArg(options::OPT_mno_unaligned_access,
   options::OPT_munaligned_access)) {
 if (A->getOption().matches(options::OPT_munaligned_access)) {
@@ -784,11 +782,8 @@ void arm::getARMTargetFeatures(const Driver , const 
llvm::Triple ,
   // access either.
   else if (Triple.getSubArch() == 
llvm::Triple::SubArchType::ARMSubArch_v8m_baseline)
 D.Diag(diag::err_target_unsupported_unaligned) << "v8m.base";
-} else {
+} else
   Features.push_back("+strict-align");
-  if (!ForAS)
-CmdArgs.push_back("-Wunaligned-access");
-}
   } else {
 // Assume pre-ARMv6 doesn't support unaligned accesses.
 //
@@ -807,23 +802,14 @@ void arm::getARMTargetFeatures(const Driver , const 
llvm::Triple ,
 int VersionNum = getARMSubArchVersionNumber(Triple);
 if (Triple.isOSDarwin() || Triple.isOSNetBSD()) {
   if (VersionNum < 6 ||
-  Triple.getSubArch() == llvm::Triple::SubArchType::ARMSubArch_v6m) {
+  Triple.getSubArch() == llvm::Triple::SubArchType::ARMSubArch_v6m)
 Features.push_back("+strict-align");
-if (!ForAS)
-  CmdArgs.push_back("-Wunaligned-access");
-  }
 } else if 

[clang-tools-extra] 4f30a52 - NFC: fix GCC warning -Wcast-qual

2022-02-09 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-02-09T18:03:25-08:00
New Revision: 4f30a5269696ff03fd600e756e934a44d4c71b46

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

LOG: NFC: fix GCC warning -Wcast-qual

Added: 


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

Removed: 




diff  --git a/clang-tools-extra/clangd/CompileCommands.cpp 
b/clang-tools-extra/clangd/CompileCommands.cpp
index df5f84c894e7b..f3103b21530c6 100644
--- a/clang-tools-extra/clangd/CompileCommands.cpp
+++ b/clang-tools-extra/clangd/CompileCommands.cpp
@@ -471,11 +471,11 @@ llvm::ArrayRef 
ArgStripper::rulesFor(llvm::StringRef Arg) {
 struct {
   DriverID ID;
   DriverID AliasID;
-  void *AliasArgs;
+  const void *AliasArgs;
 } AliasTable[] = {
 #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  
\
HELP, METAVAR, VALUES)  
\
-  {DriverID::OPT_##ID, DriverID::OPT_##ALIAS, (void *)ALIASARGS},
+  {DriverID::OPT_##ID, DriverID::OPT_##ALIAS, ALIASARGS},
 #include "clang/Driver/Options.inc"
 #undef OPTION
 };



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


[clang] da85307 - [CMake] Pass CMAKE_C/CXX_COMPILER_LAUNCHER down to cross-compile and runtime build

2022-01-24 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-01-24T14:27:14-08:00
New Revision: da85307ba699ea2260252f523e089c85e863d671

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

LOG: [CMake] Pass CMAKE_C/CXX_COMPILER_LAUNCHER down to cross-compile and 
runtime build

Similar to D59032.

Reviewed By: dexonsmith

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

Added: 


Modified: 
clang/runtime/CMakeLists.txt
llvm/cmake/modules/CrossCompile.cmake
llvm/cmake/modules/LLVMExternalProjectUtils.cmake

Removed: 




diff  --git a/clang/runtime/CMakeLists.txt b/clang/runtime/CMakeLists.txt
index 61b1c60bf590b..0388008792511 100644
--- a/clang/runtime/CMakeLists.txt
+++ b/clang/runtime/CMakeLists.txt
@@ -78,6 +78,8 @@ if(LLVM_BUILD_EXTERNAL_COMPILER_RT AND EXISTS 
${COMPILER_RT_SRC_ROOT}/)
-DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
+   -DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER}
+   -DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}
-DLLVM_CONFIG_PATH=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-config
-DLLVM_LIT_ARGS=${LLVM_LIT_ARGS}

-DCOMPILER_RT_OUTPUT_DIR=${LLVM_LIBRARY_OUTPUT_INTDIR}/clang/${CLANG_VERSION}

diff  --git a/llvm/cmake/modules/CrossCompile.cmake 
b/llvm/cmake/modules/CrossCompile.cmake
index 2d637f035a7c0..2a39b6a40a285 100644
--- a/llvm/cmake/modules/CrossCompile.cmake
+++ b/llvm/cmake/modules/CrossCompile.cmake
@@ -70,6 +70,8 @@ function(llvm_create_cross_target project_name target_name 
toolchain buildtype)
   add_custom_command(OUTPUT 
${${project_name}_${target_name}_BUILD}/CMakeCache.txt
 COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}"
 -DCMAKE_MAKE_PROGRAM="${CMAKE_MAKE_PROGRAM}"
+-DCMAKE_C_COMPILER_LAUNCHER="${CMAKE_C_COMPILER_LAUNCHER}"
+-DCMAKE_CXX_COMPILER_LAUNCHER="${CMAKE_CXX_COMPILER_LAUNCHER}"
 ${CROSS_TOOLCHAIN_FLAGS_${target_name}} ${CMAKE_CURRENT_SOURCE_DIR}
 ${CROSS_TOOLCHAIN_FLAGS_${project_name}_${target_name}}
 -DLLVM_TARGET_IS_CROSSCOMPILE_HOST=TRUE

diff  --git a/llvm/cmake/modules/LLVMExternalProjectUtils.cmake 
b/llvm/cmake/modules/LLVMExternalProjectUtils.cmake
index 7c417b41cd344..f99a50df22801 100644
--- a/llvm/cmake/modules/LLVMExternalProjectUtils.cmake
+++ b/llvm/cmake/modules/LLVMExternalProjectUtils.cmake
@@ -314,6 +314,8 @@ function(llvm_ExternalProject_Add name source_dir)
-DPACKAGE_VERSION=${PACKAGE_VERSION}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
+   -DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER}
+   -DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}
-DCMAKE_EXPORT_COMPILE_COMMANDS=1
${cmake_args}
${PASSTHROUGH_VARIABLES}



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


[clang-tools-extra] 3b64ab5 - [NFC][clangd] Use table to collect option aliases

2022-01-24 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-01-24T14:27:14-08:00
New Revision: 3b64ab574d985b70cb4ec0f69c1fc1c1c4527cde

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

LOG: [NFC][clangd] Use table to collect option aliases

* Suppress a lot of `-Wtautological-compare` warning
* Speed up file build a little bit

Reviewed By: kadircet

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

Added: 


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

Removed: 




diff  --git a/clang-tools-extra/clangd/CompileCommands.cpp 
b/clang-tools-extra/clangd/CompileCommands.cpp
index 7d6f612cb8b96..df5f84c894e7b 100644
--- a/clang-tools-extra/clangd/CompileCommands.cpp
+++ b/clang-tools-extra/clangd/CompileCommands.cpp
@@ -463,13 +463,26 @@ llvm::ArrayRef 
ArgStripper::rulesFor(llvm::StringRef Arg) {
 #define PREFIX(NAME, VALUE) static const char *const NAME[] = VALUE;
 #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  
\
HELP, METAVAR, VALUES)  
\
-  if (DriverID::OPT_##ALIAS != DriverID::OPT_INVALID && ALIASARGS == nullptr)  
\
-AddAlias(DriverID::OPT_##ID, DriverID::OPT_##ALIAS);   
\
   Prefixes[DriverID::OPT_##ID] = PREFIX;
 #include "clang/Driver/Options.inc"
 #undef OPTION
 #undef PREFIX
 
+struct {
+  DriverID ID;
+  DriverID AliasID;
+  void *AliasArgs;
+} AliasTable[] = {
+#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  
\
+   HELP, METAVAR, VALUES)  
\
+  {DriverID::OPT_##ID, DriverID::OPT_##ALIAS, (void *)ALIASARGS},
+#include "clang/Driver/Options.inc"
+#undef OPTION
+};
+for (auto  : AliasTable)
+  if (E.AliasID != DriverID::OPT_INVALID && E.AliasArgs == nullptr)
+AddAlias(E.ID, E.AliasID);
+
 auto Result = std::make_unique();
 // Iterate over distinct options (represented by the canonical alias).
 // Every spelling of this option will get the same set of rules.



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


[clang] e902ffe - [Sema] Fix the assertion in Sema::ActOnDependentMemberExpr

2022-01-04 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-01-04T13:08:12-08:00
New Revision: e902ffe6d7560f708b76edaa53d75edcb5d49a3f

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

LOG: [Sema] Fix the assertion in Sema::ActOnDependentMemberExpr

617007240cbfb97c introduced the use of ActOnDependentMemberExpr with
variable template specialization. The assertion inside
ActOnDependentMemberExpr should be adjusted accordingly.

Fixes https://bugs.llvm.org/show_bug.cgi?id=47211

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/lib/Sema/SemaExprMember.cpp
clang/test/SemaCXX/cxx1y-variable-templates_in_class.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExprMember.cpp 
b/clang/lib/Sema/SemaExprMember.cpp
index 83006f9d804ab..f67ef030feb70 100644
--- a/clang/lib/Sema/SemaExprMember.cpp
+++ b/clang/lib/Sema/SemaExprMember.cpp
@@ -504,9 +504,12 @@ Sema::ActOnDependentMemberExpr(Expr *BaseExpr, QualType 
BaseType,
 }
   }
 
-  assert(BaseType->isDependentType() ||
- NameInfo.getName().isDependentName() ||
- isDependentScopeSpecifier(SS));
+  assert(BaseType->isDependentType() || NameInfo.getName().isDependentName() ||
+ isDependentScopeSpecifier(SS) ||
+ (TemplateArgs && llvm::any_of(TemplateArgs->arguments(),
+   [](const TemplateArgumentLoc ) {
+ return 
Arg.getArgument().isDependent();
+   })));
 
   // Get the type being accessed in BaseType.  If this is an arrow, the 
BaseExpr
   // must have pointer type, and the accessed type is the pointee.

diff  --git a/clang/test/SemaCXX/cxx1y-variable-templates_in_class.cpp 
b/clang/test/SemaCXX/cxx1y-variable-templates_in_class.cpp
index 1a24c66805690..af121a8b75d51 100644
--- a/clang/test/SemaCXX/cxx1y-variable-templates_in_class.cpp
+++ b/clang/test/SemaCXX/cxx1y-variable-templates_in_class.cpp
@@ -394,6 +394,18 @@ namespace dependent_static_var_template {
 template static int n; // expected-note {{here}}
   }
   int  = B::template n; // expected-error {{use of variable template 'n' 
requires template arguments}}
+
+  struct C {
+template  static T G;
+  };
+  template T C::G = T(6);
+
+  template  T F() {
+C c;
+return c.G;
+  }
+
+  int cf() { return F(); }
 }
 
 #ifndef PRECXX11



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


[clang] 1510595 - [Sema] Mark explicit specialization declaration in a friend invalid

2021-12-15 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2021-12-15T10:26:55-08:00
New Revision: 1510595dce9c48b9e7ddd49becd422c4e5e66fc9

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

LOG: [Sema] Mark explicit specialization declaration in a friend invalid

Down the path, if there is a implicit instantiation, this may trigger
the assertion "Member specialization must be an explicit specialization"
in `clang::FunctionDecl::setFunctionTemplateSpecialization`.

Reviewed By: aaron.ballman

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

Added: 
clang/test/CXX/temp/temp.spec/temp.expl.spec/p20-2.cpp

Modified: 
clang/lib/Sema/SemaDecl.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index b1312a7ccc512..5e9c92db81b4a 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -9202,6 +9202,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator , 
DeclContext *DC,
 << Name << RemoveRange
 << FixItHint::CreateRemoval(RemoveRange)
 << FixItHint::CreateInsertion(InsertLoc, "<>");
+  Invalid = true;
 }
   }
 } else {

diff  --git a/clang/test/CXX/temp/temp.spec/temp.expl.spec/p20-2.cpp 
b/clang/test/CXX/temp/temp.spec/temp.expl.spec/p20-2.cpp
new file mode 100644
index 0..7bc5f13cd7375
--- /dev/null
+++ b/clang/test/CXX/temp/temp.spec/temp.expl.spec/p20-2.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+template
+void f(T);
+
+template
+struct A {
+  // expected-error@+1{{cannot declare an explicit specialization in a friend}}
+  template <> friend void f<>(int) {}
+};
+
+// Makes sure implicit instantiation here does not trigger
+// the assertion "Member specialization must be an explicit specialization"
+void foo(void) {
+A a;
+}



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


[clang] 0d1363e - Revert "[Sema] Mark explicit specialization declaration in a friend invalid"

2021-12-15 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2021-12-15T10:25:37-08:00
New Revision: 0d1363e5614e24d164373e19e3f4b7102188d4e3

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

LOG: Revert "[Sema] Mark explicit specialization declaration in a friend 
invalid"

This reverts commit 8cb6ecbc4da2b0cfd8dcf04f612dc413716d27a1.

Nothing wrong with the commit. It is missing Phabricator informations.

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp

Removed: 
clang/test/CXX/temp/temp.spec/temp.expl.spec/p20-2.cpp



diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 5e9c92db81b4a..b1312a7ccc512 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -9202,7 +9202,6 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator , 
DeclContext *DC,
 << Name << RemoveRange
 << FixItHint::CreateRemoval(RemoveRange)
 << FixItHint::CreateInsertion(InsertLoc, "<>");
-  Invalid = true;
 }
   }
 } else {

diff  --git a/clang/test/CXX/temp/temp.spec/temp.expl.spec/p20-2.cpp 
b/clang/test/CXX/temp/temp.spec/temp.expl.spec/p20-2.cpp
deleted file mode 100644
index 7bc5f13cd7375..0
--- a/clang/test/CXX/temp/temp.spec/temp.expl.spec/p20-2.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
-template
-void f(T);
-
-template
-struct A {
-  // expected-error@+1{{cannot declare an explicit specialization in a friend}}
-  template <> friend void f<>(int) {}
-};
-
-// Makes sure implicit instantiation here does not trigger
-// the assertion "Member specialization must be an explicit specialization"
-void foo(void) {
-A a;
-}



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


[clang] 8cb6ecb - [Sema] Mark explicit specialization declaration in a friend invalid

2021-12-15 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2021-12-15T10:24:02-08:00
New Revision: 8cb6ecbc4da2b0cfd8dcf04f612dc413716d27a1

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

LOG: [Sema] Mark explicit specialization declaration in a friend invalid

Down the path, if there is a implicit instantiation, this may trigger
the assertion "Member specialization must be an explicit specialization"
in `clang::FunctionDecl::setFunctionTemplateSpecialization`.

Added: 
clang/test/CXX/temp/temp.spec/temp.expl.spec/p20-2.cpp

Modified: 
clang/lib/Sema/SemaDecl.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index b1312a7ccc51..5e9c92db81b4 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -9202,6 +9202,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator , 
DeclContext *DC,
 << Name << RemoveRange
 << FixItHint::CreateRemoval(RemoveRange)
 << FixItHint::CreateInsertion(InsertLoc, "<>");
+  Invalid = true;
 }
   }
 } else {

diff  --git a/clang/test/CXX/temp/temp.spec/temp.expl.spec/p20-2.cpp 
b/clang/test/CXX/temp/temp.spec/temp.expl.spec/p20-2.cpp
new file mode 100644
index ..7bc5f13cd737
--- /dev/null
+++ b/clang/test/CXX/temp/temp.spec/temp.expl.spec/p20-2.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+template
+void f(T);
+
+template
+struct A {
+  // expected-error@+1{{cannot declare an explicit specialization in a friend}}
+  template <> friend void f<>(int) {}
+};
+
+// Makes sure implicit instantiation here does not trigger
+// the assertion "Member specialization must be an explicit specialization"
+void foo(void) {
+A a;
+}



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


[clang] 7562c64 - [Sema] Mark virtual method declaration in union as invalid

2021-11-09 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2021-11-09T10:57:38-08:00
New Revision: 7562c64197acbee60c4bb0d211eb699ad24f5bb8

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

LOG: [Sema] Mark virtual method declaration in union as invalid

Currently, this is only diagnosed but the decl is not marked invalid. This may 
hit assertions down the path.

This also reverts the fix for PR49534 since it is not needed anymore.

Reviewed By: hubert.reinterpretcast

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

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaCXX/PR49534.cpp
clang/test/SemaCXX/virtual-function-in-union.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index d61570ee6a104..638fe86c20abc 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -5302,8 +5302,7 @@ Decl *Sema::BuildAnonymousStructOrUnion(Scope *S, 
DeclSpec ,
 // trivial in almost all cases, except if a union member has an in-class
 // initializer:
 //   union { int n = 0; };
-if (!Invalid)
-  ActOnUninitializedDecl(Anon);
+ActOnUninitializedDecl(Anon);
   }
   Anon->setImplicit();
 
@@ -9109,8 +9108,10 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator , 
DeclContext *DC,
 
   // C++ [class.union]p2
   //   A union can have member functions, but not virtual functions.
-  if (isVirtual && Parent->isUnion())
+  if (isVirtual && Parent->isUnion()) {
 Diag(D.getDeclSpec().getVirtualSpecLoc(), diag::err_virtual_in_union);
+NewFD->setInvalidDecl();
+  }
 }
 
 SetNestedNameSpecifier(*this, NewFD, D);

diff  --git a/clang/test/SemaCXX/PR49534.cpp b/clang/test/SemaCXX/PR49534.cpp
index 8a17402689e66..6b6452257f6a9 100644
--- a/clang/test/SemaCXX/PR49534.cpp
+++ b/clang/test/SemaCXX/PR49534.cpp
@@ -1,6 +1,5 @@
 // RUN: %clang_cc1 -x c++ -fsyntax-only %s -verify
 
 static union { // expected-warning {{declaration does not declare 
anything}}
-  virtual int a(); // expected-error {{unions cannot have virtual functions}} \
-   // expected-error {{functions cannot be declared in an 
anonymous union}}
+  virtual int a(); // expected-error {{unions cannot have virtual functions}}
 };

diff  --git a/clang/test/SemaCXX/virtual-function-in-union.cpp 
b/clang/test/SemaCXX/virtual-function-in-union.cpp
index 0c4ba5d32caac..b7cf26618c9fb 100644
--- a/clang/test/SemaCXX/virtual-function-in-union.cpp
+++ b/clang/test/SemaCXX/virtual-function-in-union.cpp
@@ -1,5 +1,8 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 
-union x {
-  virtual void f(); // expected-error {{unions cannot have virtual functions}}
+union U {
+  int d;
+  virtual int f() { return d; }; // expected-error {{unions cannot have 
virtual functions}}
 };
+
+int foo() { U u; return u.d; }



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


[clang] a944f80 - [Clang][NFC] Fix the comment for Sema::DiagIfReachable

2021-10-03 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2021-10-03T13:03:24-07:00
New Revision: a944f801cacdaa40b3869986844a6ffa08b87c19

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

LOG: [Clang][NFC] Fix the comment for Sema::DiagIfReachable

Added: 


Modified: 
clang/include/clang/Sema/Sema.h

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 64863e3a5781..6c0f5cee7eaf 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5114,13 +5114,13 @@ class Sema final {
   /// conversion.
   ExprResult tryConvertExprToType(Expr *E, QualType Ty);
 
-  /// Conditionally issue a diagnostic based on the statement's reachability
-  /// analysis evaluation context.
+  /// Conditionally issue a diagnostic based on the statements's reachability
+  /// analysis.
   ///
-  /// \param Statement If Statement is non-null, delay reporting the
-  /// diagnostic until the function body is parsed, and then do a basic
-  /// reachability analysis to determine if the statement is reachable.
-  /// If it is unreachable, the diagnostic will not be emitted.
+  /// \param Stmts If Stmts is non-empty, delay reporting the diagnostic until
+  /// the function body is parsed, and then do a basic reachability analysis to
+  /// determine if the statement is reachable. If it is unreachable, the
+  /// diagnostic will not be emitted.
   bool DiagIfReachable(SourceLocation Loc, ArrayRef Stmts,
const PartialDiagnostic );
 



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


[clang] 27a972a - Diagnose -Wunused-value based on CFG reachability

2021-09-28 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2021-09-28T10:00:15-07:00
New Revision: 27a972a699cd875c7fa9114dc0888015cd724f31

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

LOG: Diagnose -Wunused-value based on CFG reachability

(This relands 59337263ab45d7657e and makes sure comma operator
 diagnostics are suppressed in a SFINAE context.)

While at it, add the diagnosis message "left operand of comma operator has no 
effect" (used by GCC) for comma operator.

This also makes Clang diagnose in the constant evaluation context which aligns 
with GCC/MSVC behavior. (https://godbolt.org/z/7zxb8Tx96)

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaStmt.cpp
clang/test/Analysis/dead-stores.c
clang/test/CXX/basic/basic.link/p8.cpp
clang/test/CXX/drs/dr14xx.cpp
clang/test/CXX/drs/dr20xx.cpp
clang/test/CXX/drs/dr7xx.cpp

clang/test/CXX/temp/temp.constr/temp.constr.constr/partial-specializations.cpp
clang/test/CodeCompletion/pragma-macro-token-caching.c
clang/test/Frontend/fixed_point_crash.c
clang/test/PCH/cxx-explicit-specifier.cpp
clang/test/Parser/cxx-ambig-decl-expr.cpp
clang/test/Parser/cxx0x-ambig.cpp
clang/test/Parser/cxx1z-init-statement.cpp
clang/test/Parser/objc-messaging-1.m
clang/test/Parser/objc-try-catch-1.m
clang/test/Parser/objcxx11-attributes.mm
clang/test/Sema/const-eval.c
clang/test/Sema/exprs.c
clang/test/Sema/i-c-e.c
clang/test/Sema/sizeless-1.c
clang/test/Sema/switch-1.c
clang/test/Sema/vla-2.c
clang/test/Sema/warn-type-safety.c
clang/test/Sema/warn-unused-value.c
clang/test/SemaCXX/attr-annotate.cpp
clang/test/SemaCXX/builtin-constant-p.cpp
clang/test/SemaCXX/constant-expression-cxx2a.cpp
clang/test/SemaCXX/constant-expression.cpp
clang/test/SemaCXX/expression-traits.cpp
clang/test/SemaCXX/matrix-type-operators.cpp
clang/test/SemaCXX/overloaded-operator.cpp
clang/test/SemaCXX/sizeless-1.cpp
clang/test/SemaCXX/vector.cpp
clang/test/SemaCXX/warn-comma-operator.cpp
clang/test/SemaCXX/warn-unused-value.cpp
clang/test/SemaTemplate/derived.cpp
clang/test/SemaTemplate/lambda-capture-pack.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 07c5e85913712..00b6acf8bbe68 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8560,6 +8560,9 @@ def err_typecheck_choose_expr_requires_constant : Error<
   "'__builtin_choose_expr' requires a constant expression">;
 def warn_unused_expr : Warning<"expression result unused">,
   InGroup;
+def warn_unused_comma_left_operand : Warning<
+  "left operand of comma operator has no effect">,
+  InGroup;
 def warn_unused_voidptr : Warning<
   "expression result unused; should this cast be to 'void'?">,
   InGroup;

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index d35f5c520a949..bd5cf12183712 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -4908,7 +4908,7 @@ class Sema final {
 
   /// DiagnoseUnusedExprResult - If the statement passed in is an expression
   /// whose result is unused, warn.
-  void DiagnoseUnusedExprResult(const Stmt *S);
+  void DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID);
   void DiagnoseUnusedNestedTypedefs(const RecordDecl *D);
   void DiagnoseUnusedDecl(const NamedDecl *ND);
 
@@ -5114,6 +5114,16 @@ class Sema final {
   /// conversion.
   ExprResult tryConvertExprToType(Expr *E, QualType Ty);
 
+  /// Conditionally issue a diagnostic based on the statement's reachability
+  /// analysis evaluation context.
+  ///
+  /// \param Statement If Statement is non-null, delay reporting the
+  /// diagnostic until the function body is parsed, and then do a basic
+  /// reachability analysis to determine if the statement is reachable.
+  /// If it is unreachable, the diagnostic will not be emitted.
+  bool DiagIfReachable(SourceLocation Loc, ArrayRef Stmts,
+   const PartialDiagnostic );
+
   /// Conditionally issue a diagnostic based on the current
   /// evaluation context.
   ///

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 8eee366fbec67..8d483f317a421 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -28,6 +28,7 @@
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/Builtins.h"
+#include 

[clang] 5933726 - Revert "Diagnose -Wunused-value based on CFG reachability"

2021-09-23 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2021-09-23T11:12:00-07:00
New Revision: 59337263ab45d7657ee901eb5525a21967c46265

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

LOG: Revert "Diagnose -Wunused-value based on CFG reachability"

This reverts commit cbbf2e8c8ae7730ff0121f4868de4a7d188feb65.
It seems causing diagnoses in SFINAE context.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaStmt.cpp
clang/test/Analysis/dead-stores.c
clang/test/CXX/basic/basic.link/p8.cpp
clang/test/CXX/drs/dr14xx.cpp
clang/test/CXX/drs/dr20xx.cpp
clang/test/CXX/drs/dr7xx.cpp

clang/test/CXX/temp/temp.constr/temp.constr.constr/partial-specializations.cpp
clang/test/CodeCompletion/pragma-macro-token-caching.c
clang/test/Frontend/fixed_point_crash.c
clang/test/PCH/cxx-explicit-specifier.cpp
clang/test/Parser/cxx-ambig-decl-expr.cpp
clang/test/Parser/cxx0x-ambig.cpp
clang/test/Parser/cxx1z-init-statement.cpp
clang/test/Parser/objc-messaging-1.m
clang/test/Parser/objc-try-catch-1.m
clang/test/Parser/objcxx11-attributes.mm
clang/test/Sema/const-eval.c
clang/test/Sema/exprs.c
clang/test/Sema/i-c-e.c
clang/test/Sema/sizeless-1.c
clang/test/Sema/switch-1.c
clang/test/Sema/vla-2.c
clang/test/Sema/warn-type-safety.c
clang/test/Sema/warn-unused-value.c
clang/test/SemaCXX/attr-annotate.cpp
clang/test/SemaCXX/builtin-constant-p.cpp
clang/test/SemaCXX/constant-expression-cxx2a.cpp
clang/test/SemaCXX/constant-expression.cpp
clang/test/SemaCXX/expression-traits.cpp
clang/test/SemaCXX/matrix-type-operators.cpp
clang/test/SemaCXX/overloaded-operator.cpp
clang/test/SemaCXX/sizeless-1.cpp
clang/test/SemaCXX/vector.cpp
clang/test/SemaCXX/warn-comma-operator.cpp
clang/test/SemaCXX/warn-unused-value.cpp
clang/test/SemaTemplate/derived.cpp
clang/test/SemaTemplate/lambda-capture-pack.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index cafee92e46e75..0e803ee028ce9 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8565,9 +8565,6 @@ def err_typecheck_choose_expr_requires_constant : Error<
   "'__builtin_choose_expr' requires a constant expression">;
 def warn_unused_expr : Warning<"expression result unused">,
   InGroup;
-def warn_unused_comma_left_operand : Warning<
-  "left operand of comma operator has no effect">,
-  InGroup;
 def warn_unused_voidptr : Warning<
   "expression result unused; should this cast be to 'void'?">,
   InGroup;

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index fc0b6919bd50b..93d5558b8267c 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -4912,7 +4912,7 @@ class Sema final {
 
   /// DiagnoseUnusedExprResult - If the statement passed in is an expression
   /// whose result is unused, warn.
-  void DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID);
+  void DiagnoseUnusedExprResult(const Stmt *S);
   void DiagnoseUnusedNestedTypedefs(const RecordDecl *D);
   void DiagnoseUnusedDecl(const NamedDecl *ND);
 
@@ -5118,16 +5118,6 @@ class Sema final {
   /// conversion.
   ExprResult tryConvertExprToType(Expr *E, QualType Ty);
 
-  /// Conditionally issue a diagnostic based on the statement's reachability
-  /// analysis evaluation context.
-  ///
-  /// \param Statement If Statement is non-null, delay reporting the
-  /// diagnostic until the function body is parsed, and then do a basic
-  /// reachability analysis to determine if the statement is reachable.
-  /// If it is unreachable, the diagnostic will not be emitted.
-  bool DiagIfReachable(SourceLocation Loc, ArrayRef Stmts,
-   const PartialDiagnostic );
-
   /// Conditionally issue a diagnostic based on the current
   /// evaluation context.
   ///

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 8d483f317a421..8eee366fbec67 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -28,7 +28,6 @@
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/Builtins.h"
-#include "clang/Basic/DiagnosticSema.h"
 #include "clang/Basic/PartialDiagnostic.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
@@ -13372,7 +13371,7 @@ static QualType CheckCommaOperands(Sema , ExprResult 
, ExprResult ,
   if (LHS.isInvalid())
 return QualType();
 
-  S.DiagnoseUnusedExprResult(LHS.get(), 

[clang] cbbf2e8 - Diagnose -Wunused-value based on CFG reachability

2021-09-22 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2021-09-22T14:38:06-07:00
New Revision: cbbf2e8c8ae7730ff0121f4868de4a7d188feb65

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

LOG: Diagnose -Wunused-value based on CFG reachability

While at it, add the diagnosis message "left operand of comma operator has no 
effect" (used by GCC) for comma operator.

This also makes Clang diagnose in the constant evaluation context which aligns 
with GCC/MSVC behavior. (https://godbolt.org/z/7zxb8Tx96)

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaStmt.cpp
clang/test/Analysis/dead-stores.c
clang/test/CXX/basic/basic.link/p8.cpp
clang/test/CXX/drs/dr14xx.cpp
clang/test/CXX/drs/dr20xx.cpp
clang/test/CXX/drs/dr7xx.cpp

clang/test/CXX/temp/temp.constr/temp.constr.constr/partial-specializations.cpp
clang/test/CodeCompletion/pragma-macro-token-caching.c
clang/test/Frontend/fixed_point_crash.c
clang/test/PCH/cxx-explicit-specifier.cpp
clang/test/Parser/cxx-ambig-decl-expr.cpp
clang/test/Parser/cxx0x-ambig.cpp
clang/test/Parser/cxx1z-init-statement.cpp
clang/test/Parser/objc-messaging-1.m
clang/test/Parser/objc-try-catch-1.m
clang/test/Parser/objcxx11-attributes.mm
clang/test/Sema/const-eval.c
clang/test/Sema/exprs.c
clang/test/Sema/i-c-e.c
clang/test/Sema/sizeless-1.c
clang/test/Sema/switch-1.c
clang/test/Sema/vla-2.c
clang/test/Sema/warn-type-safety.c
clang/test/Sema/warn-unused-value.c
clang/test/SemaCXX/attr-annotate.cpp
clang/test/SemaCXX/builtin-constant-p.cpp
clang/test/SemaCXX/constant-expression-cxx2a.cpp
clang/test/SemaCXX/constant-expression.cpp
clang/test/SemaCXX/expression-traits.cpp
clang/test/SemaCXX/matrix-type-operators.cpp
clang/test/SemaCXX/overloaded-operator.cpp
clang/test/SemaCXX/sizeless-1.cpp
clang/test/SemaCXX/vector.cpp
clang/test/SemaCXX/warn-comma-operator.cpp
clang/test/SemaCXX/warn-unused-value.cpp
clang/test/SemaTemplate/derived.cpp
clang/test/SemaTemplate/lambda-capture-pack.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 0e803ee028ce9..cafee92e46e75 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8565,6 +8565,9 @@ def err_typecheck_choose_expr_requires_constant : Error<
   "'__builtin_choose_expr' requires a constant expression">;
 def warn_unused_expr : Warning<"expression result unused">,
   InGroup;
+def warn_unused_comma_left_operand : Warning<
+  "left operand of comma operator has no effect">,
+  InGroup;
 def warn_unused_voidptr : Warning<
   "expression result unused; should this cast be to 'void'?">,
   InGroup;

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 93d5558b8267c..fc0b6919bd50b 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -4912,7 +4912,7 @@ class Sema final {
 
   /// DiagnoseUnusedExprResult - If the statement passed in is an expression
   /// whose result is unused, warn.
-  void DiagnoseUnusedExprResult(const Stmt *S);
+  void DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID);
   void DiagnoseUnusedNestedTypedefs(const RecordDecl *D);
   void DiagnoseUnusedDecl(const NamedDecl *ND);
 
@@ -5118,6 +5118,16 @@ class Sema final {
   /// conversion.
   ExprResult tryConvertExprToType(Expr *E, QualType Ty);
 
+  /// Conditionally issue a diagnostic based on the statement's reachability
+  /// analysis evaluation context.
+  ///
+  /// \param Statement If Statement is non-null, delay reporting the
+  /// diagnostic until the function body is parsed, and then do a basic
+  /// reachability analysis to determine if the statement is reachable.
+  /// If it is unreachable, the diagnostic will not be emitted.
+  bool DiagIfReachable(SourceLocation Loc, ArrayRef Stmts,
+   const PartialDiagnostic );
+
   /// Conditionally issue a diagnostic based on the current
   /// evaluation context.
   ///

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 8eee366fbec67..8d483f317a421 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -28,6 +28,7 @@
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/Builtins.h"
+#include "clang/Basic/DiagnosticSema.h"
 #include "clang/Basic/PartialDiagnostic.h"
 #include "clang/Basic/SourceManager.h"
 #include 

[clang] 63e0d03 - Diagnose -Wunused-value based on CFG reachability

2021-09-20 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2021-09-20T10:43:34-07:00
New Revision: 63e0d038fc20c894a3d541effa1bc2b1fdea37b9

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

LOG: Diagnose -Wunused-value based on CFG reachability

While at it, add the diagnosis message "left operand of comma operator has no 
effect" (used by GCC) for comma operator.

This also makes Clang diagnose in the constant evaluation context which aligns 
with GCC/MSVC behavior. (https://godbolt.org/z/7zxb8Tx96)

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaStmt.cpp
clang/test/Analysis/dead-stores.c
clang/test/CXX/basic/basic.link/p8.cpp
clang/test/CXX/drs/dr14xx.cpp
clang/test/CXX/drs/dr20xx.cpp
clang/test/CXX/drs/dr7xx.cpp

clang/test/CXX/temp/temp.constr/temp.constr.constr/partial-specializations.cpp
clang/test/CodeCompletion/pragma-macro-token-caching.c
clang/test/Frontend/fixed_point_crash.c
clang/test/PCH/cxx-explicit-specifier.cpp
clang/test/Parser/cxx-ambig-decl-expr.cpp
clang/test/Parser/cxx0x-ambig.cpp
clang/test/Parser/cxx1z-init-statement.cpp
clang/test/Parser/objc-messaging-1.m
clang/test/Parser/objc-try-catch-1.m
clang/test/Parser/objcxx11-attributes.mm
clang/test/Sema/const-eval.c
clang/test/Sema/exprs.c
clang/test/Sema/i-c-e.c
clang/test/Sema/sizeless-1.c
clang/test/Sema/switch-1.c
clang/test/Sema/vla-2.c
clang/test/Sema/warn-type-safety.c
clang/test/Sema/warn-unused-value.c
clang/test/SemaCXX/attr-annotate.cpp
clang/test/SemaCXX/builtin-constant-p.cpp
clang/test/SemaCXX/constant-expression-cxx2a.cpp
clang/test/SemaCXX/constant-expression.cpp
clang/test/SemaCXX/expression-traits.cpp
clang/test/SemaCXX/matrix-type-operators.cpp
clang/test/SemaCXX/overloaded-operator.cpp
clang/test/SemaCXX/sizeless-1.cpp
clang/test/SemaCXX/vector.cpp
clang/test/SemaCXX/warn-comma-operator.cpp
clang/test/SemaCXX/warn-unused-value.cpp
clang/test/SemaTemplate/derived.cpp
clang/test/SemaTemplate/lambda-capture-pack.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 3cadd986b8ae4..530e8cf2e9725 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8565,6 +8565,9 @@ def err_typecheck_choose_expr_requires_constant : Error<
   "'__builtin_choose_expr' requires a constant expression">;
 def warn_unused_expr : Warning<"expression result unused">,
   InGroup;
+def warn_unused_comma_left_operand : Warning<
+  "left operand of comma operator has no effect">,
+  InGroup;
 def warn_unused_voidptr : Warning<
   "expression result unused; should this cast be to 'void'?">,
   InGroup;

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 93d5558b8267c..fc0b6919bd50b 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -4912,7 +4912,7 @@ class Sema final {
 
   /// DiagnoseUnusedExprResult - If the statement passed in is an expression
   /// whose result is unused, warn.
-  void DiagnoseUnusedExprResult(const Stmt *S);
+  void DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID);
   void DiagnoseUnusedNestedTypedefs(const RecordDecl *D);
   void DiagnoseUnusedDecl(const NamedDecl *ND);
 
@@ -5118,6 +5118,16 @@ class Sema final {
   /// conversion.
   ExprResult tryConvertExprToType(Expr *E, QualType Ty);
 
+  /// Conditionally issue a diagnostic based on the statement's reachability
+  /// analysis evaluation context.
+  ///
+  /// \param Statement If Statement is non-null, delay reporting the
+  /// diagnostic until the function body is parsed, and then do a basic
+  /// reachability analysis to determine if the statement is reachable.
+  /// If it is unreachable, the diagnostic will not be emitted.
+  bool DiagIfReachable(SourceLocation Loc, ArrayRef Stmts,
+   const PartialDiagnostic );
+
   /// Conditionally issue a diagnostic based on the current
   /// evaluation context.
   ///

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 7991e4c5e8b0a..83ff35b056e2e 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -28,6 +28,7 @@
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/Builtins.h"
+#include "clang/Basic/DiagnosticSema.h"
 #include "clang/Basic/PartialDiagnostic.h"
 #include "clang/Basic/SourceManager.h"
 #include 

[clang] 61d1cce - PR45881: Properly use CXXThisOverride for templated lambda

2021-09-07 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2021-09-07T17:02:24-07:00
New Revision: 61d1cce2f83571c00f76144d42a2dea2cb3ab1ca

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

LOG: PR45881: Properly use CXXThisOverride for templated lambda

- `this` used in lambda expression parameter declarations needs no capture.
- Set up CXXThisOverride for default template arguments of a lambda.

A similar fix to this is c3d2ebb60f604.

Reviewed By: aaron.ballman

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

Added: 
clang/test/SemaCXX/cxx20-lambda-decltype-this.cpp

Modified: 
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/test/SemaCXX/cxx1z-lambda-star-this.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index ba2e17c4a6313..e30e1bb7df786 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1137,11 +1137,10 @@ static QualType 
adjustCVQualifiersForCXXThisWithinLambda(
 }
   }
 
-  // 2) We've run out of ScopeInfos but check if CurDC is a lambda (which can
-  // happen during instantiation of its nested generic lambda call operator)
-  if (isLambdaCallOperator(CurDC)) {
-assert(CurLSI && "While computing 'this' capture-type for a generic "
- "lambda, we must have a corresponding LambdaScopeInfo");
+  // 2) We've run out of ScopeInfos but check 1. if CurDC is a lambda (which
+  //can happen during instantiation of its nested generic lambda call
+  //operator); 2. if we're in a lambda scope (lambda body).
+  if (CurLSI && isLambdaCallOperator(CurDC)) {
 assert(isGenericLambdaCallOperatorSpecialization(CurLSI->CallOperator) &&
"While computing 'this' capture-type for a generic lambda, when we "
"run out of enclosing LSI's, yet the enclosing DC is a "

diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 5d26f2d2c11a5..6682b17f4e146 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -5110,7 +5110,11 @@ SubstDefaultTemplateArgument(Sema ,
 for (unsigned i = 0, e = Param->getDepth(); i != e; ++i)
   TemplateArgLists.addOuterTemplateArguments(None);
 
-Sema::ContextRAII SavedContext(SemaRef, Template->getDeclContext());
+bool ForLambdaCallOperator = false;
+if (const auto *Rec = dyn_cast(Template->getDeclContext()))
+  ForLambdaCallOperator = Rec->isLambda();
+Sema::ContextRAII SavedContext(SemaRef, Template->getDeclContext(),
+   !ForLambdaCallOperator);
 ArgType =
 SemaRef.SubstType(ArgType, TemplateArgLists,
   Param->getDefaultArgumentLoc(), 
Param->getDeclName());

diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 5d93a17922269..f0a9e820c028c 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -2858,9 +2858,24 @@ static Sema::TemplateDeductionResult 
ConvertDeducedTemplateArguments(
   return Sema::TDK_Incomplete;
 }
 
-TemplateArgumentLoc DefArg = S.SubstDefaultTemplateArgumentIfAvailable(
-TD, TD->getLocation(), TD->getSourceRange().getEnd(), Param, Builder,
-HasDefaultArg);
+TemplateArgumentLoc DefArg;
+{
+  Qualifiers ThisTypeQuals;
+  CXXRecordDecl *ThisContext = nullptr;
+  if (auto *Rec = dyn_cast(TD->getDeclContext()))
+if (Rec->isLambda())
+  if (auto *Method = dyn_cast(Rec->getDeclContext())) {
+ThisContext = Method->getParent();
+ThisTypeQuals = Method->getMethodQualifiers();
+  }
+
+  Sema::CXXThisScopeRAII ThisScope(S, ThisContext, ThisTypeQuals,
+   S.getLangOpts().CPlusPlus17);
+
+  DefArg = S.SubstDefaultTemplateArgumentIfAvailable(
+  TD, TD->getLocation(), TD->getSourceRange().getEnd(), Param, Builder,
+  HasDefaultArg);
+}
 
 // If there was no default argument, deduction is incomplete.
 if (DefArg.getArgument().isNull()) {

diff  --git a/clang/test/SemaCXX/cxx1z-lambda-star-this.cpp 
b/clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
index 2426e8f5a207f..5a471fd6b6940 100644
--- a/clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
+++ b/clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
@@ -298,3 +298,13 @@ class A {
 
 } // namespace PR32831
 
+namespace PR45881 {
+struct A {
+void f();
+};
+int id(A*);
+void A::f() {
+auto z = [*this](auto z2, decltype(z2(this)) z3){};
+z(id,3);
+}
+} // namespace PR45881

diff  --git a/clang/test/SemaCXX/cxx20-lambda-decltype-this.cpp 
b/clang/test/SemaCXX/cxx20-lambda-decltype-this.cpp
new file 

[clang] 9ffd492 - [NFC][Coroutines] Fix two tests by removing hardcoded SSA value.

2021-05-09 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2021-05-09T19:06:16-07:00
New Revision: 9ffd4924e8e1a056760256c4cd5ffde38ccdf010

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

LOG: [NFC][Coroutines] Fix two tests by removing hardcoded SSA value.

Added: 


Modified: 
clang/test/CodeGenCoroutines/coro-dest-slot.cpp
clang/test/CodeGenCoroutines/coro-params.cpp

Removed: 




diff  --git a/clang/test/CodeGenCoroutines/coro-dest-slot.cpp 
b/clang/test/CodeGenCoroutines/coro-dest-slot.cpp
index 762fa1aede3c8..c7129df115261 100644
--- a/clang/test/CodeGenCoroutines/coro-dest-slot.cpp
+++ b/clang/test/CodeGenCoroutines/coro-dest-slot.cpp
@@ -25,7 +25,7 @@ extern "C" coro f(int) { co_return; }
 // CHECK: %[[CLEANUP_DEST0:.+]] = phi i32 [ 0, %[[INIT_READY]] ], [ 2, 
%[[INIT_CLEANUP]] ]
 
 // CHECK: %[[FINAL_SUSPEND:.+]] = call i8 @llvm.coro.suspend(
-// CHECK-NEXT: switch i8 %29, label %coro.ret [
+// CHECK-NEXT: switch i8 %{{.*}}, label %coro.ret [
 // CHECK-NEXT:   i8 0, label %[[FINAL_READY:.+]]
 // CHECK-NEXT:   i8 1, label %[[FINAL_CLEANUP:.+]]
 // CHECK-NEXT: ]

diff  --git a/clang/test/CodeGenCoroutines/coro-params.cpp 
b/clang/test/CodeGenCoroutines/coro-params.cpp
index 12332cd793c4f..28753d524df28 100644
--- a/clang/test/CodeGenCoroutines/coro-params.cpp
+++ b/clang/test/CodeGenCoroutines/coro-params.cpp
@@ -78,7 +78,7 @@ void f(int val, MoveOnly moParam, MoveAndCopy mcParam) {
   // CHECK-NEXT: invoke void 
@_ZNSt12experimental16coroutine_traitsIJvi8MoveOnly11MoveAndCopyEE12promise_typeC1Ev(
 
   // CHECK: call void @_ZN14suspend_always12await_resumeEv(
-  // CHECK: %[[IntParam:.+]] = load i32, i32* %val1
+  // CHECK: %[[IntParam:.+]] = load i32, i32* %{{.*}}
   // CHECK: %[[MoGep:.+]] = getelementptr inbounds %struct.MoveOnly, 
%struct.MoveOnly* %[[MoCopy]], i32 0, i32 0
   // CHECK: %[[MoVal:.+]] = load i32, i32* %[[MoGep]]
   // CHECK: %[[McGep:.+]] =  getelementptr inbounds %struct.MoveAndCopy, 
%struct.MoveAndCopy* %[[McCopy]], i32 0, i32 0
@@ -121,7 +121,7 @@ void dependent_params(T x, U, U y) {
   // CHECK-NEXT: bitcast %struct.B* %[[unnamed_copy]] to i8*
   // CHECK-NEXT: call void @llvm.lifetime.start.p0i8(
   // CHECK-NEXT: call void @_ZN1BC1EOS_(%struct.B* {{[^,]*}} 
%[[unnamed_copy]], %struct.B* nonnull align 4 dereferenceable(512) %0)
-  // CHECK-NEXT: %10 = bitcast %struct.B* %[[y_copy]] to i8*
+  // CHECK-NEXT: bitcast %struct.B* %[[y_copy]] to i8*
   // CHECK-NEXT: call void @llvm.lifetime.start.p0i8(
   // CHECK-NEXT: call void @_ZN1BC1EOS_(%struct.B* {{[^,]*}} %[[y_copy]], 
%struct.B* nonnull align 4 dereferenceable(512) %y)
   // CHECK-NEXT: bitcast %"struct.std::experimental::coroutine_traits::promise_type"* %__promise to i8*



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


[clang] 217f0f7 - [Clang][Sema] Implement GCC -Wcast-function-type

2021-03-24 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2021-03-24T16:04:18-07:00
New Revision: 217f0f735afec57a51fa6f9ab863d4713a2f85e2

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

LOG: [Clang][Sema] Implement GCC -Wcast-function-type

```
Warn when a function pointer is cast to an incompatible function
pointer. In a cast involving function types with a variable argument
list only the types of initial arguments that are provided are
considered. Any parameter of pointer-type matches any other
pointer-type. Any benign differences in integral types are ignored, like
int vs. long on ILP32 targets. Likewise type qualifiers are ignored. The
function type void (*) (void) is special and matches everything, which
can be used to suppress this warning. In a cast involving pointer to
member types this warning warns whenever the type cast is changing the
pointer to member type. This warning is enabled by -Wextra.
```

Reviewed By: rsmith

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

Added: 
clang/test/Sema/warn-cast-function-type.c
clang/test/Sema/warn-cast-function-type.cpp

Modified: 
clang/docs/DiagnosticsReference.rst
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaCast.cpp

Removed: 




diff  --git a/clang/docs/DiagnosticsReference.rst 
b/clang/docs/DiagnosticsReference.rst
index 04d7f74d5bfc9..730077f33397a 100644
--- a/clang/docs/DiagnosticsReference.rst
+++ b/clang/docs/DiagnosticsReference.rst
@@ -851,6 +851,13 @@ This diagnostic is enabled by default.
 |:warning:`warning:` |nbsp| :diagtext:`cast from function call of type` |nbsp| 
:placeholder:`A` |nbsp| :diagtext:`to non-matching type` |nbsp| 
:placeholder:`B`|
 
+--+
 
+-Wcast-function-type
+---
+**Diagnostic text:**
+
++--+
+|:warning:`warning:` |nbsp| :diagtext:`cast from` |nbsp| :placeholder:`A` 
|nbsp| :diagtext:`to` |nbsp| :placeholder:`B` |nbsp| :diagtext:`converts to 
incompatible function types`|
++--+
 
 -Wbinary-literal
 

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 291cca02694fc..85f798013a3d4 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -499,6 +499,7 @@ def PrivateExtern : DiagGroup<"private-extern">;
 def SelTypeCast : DiagGroup<"cast-of-sel-type">;
 def FunctionDefInObjCContainer : DiagGroup<"function-def-in-objc-container">;
 def BadFunctionCast : DiagGroup<"bad-function-cast">;
+def CastFunctionType : DiagGroup<"cast-function-type">;
 def ObjCPropertyImpl : DiagGroup<"objc-property-implementation">;
 def ObjCPropertyNoAttribute : DiagGroup<"objc-property-no-attribute">;
 def ObjCPropertyAssignOnObjectType : 
DiagGroup<"objc-property-assign-on-object-type">;

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 58e221a004689..df2f79a4f3441 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8386,6 +8386,9 @@ def note_change_calling_conv_fixit : Note<
 def warn_bad_function_cast : Warning<
   "cast from function call of type %0 to non-matching type %1">,
   InGroup, DefaultIgnore;
+def warn_cast_function_type : Warning<
+  "cast from %0 to %1 converts to incompatible function types">,
+  InGroup, DefaultIgnore;
 def err_cast_pointer_to_non_pointer_int : Error<
   "pointer cannot be cast to type %0">;
 def err_cast_to_bfloat16 : Error<"cannot type-cast to __bf16">;

diff  --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
index 22ec2c7ed8bbf..719cbf46bd5c2 100644
--- a/clang/lib/Sema/SemaCast.cpp
+++ b/clang/lib/Sema/SemaCast.cpp
@@ -13,8 +13,8 @@
 //
 
//===--===//
 
-#include "clang/Sema/SemaInternal.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/ASTStructuralEquivalence.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/ExprObjC.h"
@@ -23,6 +23,7 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Sema/Initialization.h"
+#include "clang/Sema/SemaInternal.h"
 #include "llvm/ADT/SmallVector.h"
 #include 

[clang] 1490f6b - Fix build 5de2d189e6ad4

2021-03-01 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2021-03-01T16:06:30-08:00
New Revision: 1490f6b72c30f690b18018ceefd499562b255efa

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

LOG: Fix build 5de2d189e6ad4

Remove source_mgr remark diagnose kind.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticFrontendKinds.td

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 831f906ffac8..3086e922d9ed 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -22,7 +22,6 @@ def note_fe_inline_asm_here : Note<"instantiated into 
assembly here">;
 def err_fe_source_mgr : Error<"%0">, CatSourceMgr;
 def warn_fe_source_mgr : Warning<"%0">, CatSourceMgr, 
InGroup;
 def note_fe_source_mgr : Note<"%0">, CatSourceMgr;
-def remark_fe_source_mgr: Remark<"%0">, CatSourceMgr, 
InGroup;
 def err_fe_cannot_link_module : Error<"cannot link module '%0': %1">,
   DefaultFatal;
 



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


[clang] 5de2d18 - [Diagnose] Unify MCContext and LLVMContext diagnosing

2021-03-01 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2021-03-01T15:58:37-08:00
New Revision: 5de2d189e6ad466a1f0616195e8c524a4eb3cbc0

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

LOG: [Diagnose] Unify MCContext and LLVMContext diagnosing

The situation with inline asm/MC error reporting is kind of messy at the
moment. The errors from MC layout are not reliably propagated and users
have to specify an inlineasm handler separately to get inlineasm
diagnose. The latter issue is not a correctness issue but could be improved.

* Kill LLVMContext inlineasm diagnose handler and migrate it to use
  DiagnoseInfo/DiagnoseHandler.
* Introduce `DiagnoseInfoSrcMgr` to diagnose SourceMgr backed errors. This
  covers use cases like inlineasm, MC, and any clients using SourceMgr.
* Move AsmPrinter::SrcMgrDiagInfo and its instance to MCContext. The next step
  is to combine MCContext::SrcMgr and MCContext::InlineSrcMgr because in all
  use cases, only one of them is used.
* If LLVMContext is available, let MCContext uses LLVMContext's diagnose
  handler; if LLVMContext is not available, MCContext uses its own default
  diagnose handler which just prints SMDiagnostic.
* Change a few clients(Clang, llc, lldb) to use the new way of reporting.

Reviewed By: MaskRay

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticCategories.td
clang/include/clang/Basic/DiagnosticFrontendKinds.td
clang/include/clang/Basic/DiagnosticGroups.td
clang/lib/CodeGen/CodeGenAction.cpp
lldb/source/Expression/IRExecutionUnit.cpp
llvm/include/llvm/CodeGen/AsmPrinter.h
llvm/include/llvm/IR/DiagnosticInfo.h
llvm/include/llvm/IR/LLVMContext.h
llvm/include/llvm/MC/MCContext.h
llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
llvm/lib/CodeGen/MachineModuleInfo.cpp
llvm/lib/IR/DiagnosticInfo.cpp
llvm/lib/IR/LLVMContext.cpp
llvm/lib/IR/LLVMContextImpl.h
llvm/lib/MC/MCContext.cpp
llvm/lib/MC/MCParser/AsmParser.cpp
llvm/test/CodeGen/AMDGPU/lds-initializer.ll
llvm/test/CodeGen/AMDGPU/lds-zero-initializer.ll
llvm/test/CodeGen/XCore/section-name.ll
llvm/tools/llc/llc.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticCategories.td 
b/clang/include/clang/Basic/DiagnosticCategories.td
index d7203173790e..fb6bdd710741 100644
--- a/clang/include/clang/Basic/DiagnosticCategories.td
+++ b/clang/include/clang/Basic/DiagnosticCategories.td
@@ -7,4 +7,5 @@
 
//===--===//
 
 class CatInlineAsm : DiagCategory<"Inline Assembly Issue">;
+class CatSourceMgr : DiagCategory<"SourceMgr Reported Issue">;
 class CatBackend : DiagCategory<"Backend Issue">;

diff  --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index b9f8c78e43da..831f906ffac8 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -19,6 +19,10 @@ def err_fe_inline_asm : Error<"%0">, CatInlineAsm;
 def warn_fe_inline_asm : Warning<"%0">, CatInlineAsm, 
InGroup;
 def note_fe_inline_asm : Note<"%0">, CatInlineAsm;
 def note_fe_inline_asm_here : Note<"instantiated into assembly here">;
+def err_fe_source_mgr : Error<"%0">, CatSourceMgr;
+def warn_fe_source_mgr : Warning<"%0">, CatSourceMgr, 
InGroup;
+def note_fe_source_mgr : Note<"%0">, CatSourceMgr;
+def remark_fe_source_mgr: Remark<"%0">, CatSourceMgr, 
InGroup;
 def err_fe_cannot_link_module : Error<"cannot link module '%0': %1">,
   DefaultFatal;
 

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 1a1ce66656f5..81d78c69cc44 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1145,6 +1145,7 @@ def OpenMP : DiagGroup<"openmp", [
 
 // Backend warnings.
 def BackendInlineAsm : DiagGroup<"inline-asm">;
+def BackendSourceMgr : DiagGroup<"source-mgr">;
 def BackendFrameLargerThanEQ : DiagGroup<"frame-larger-than=">;
 def BackendPlugin : DiagGroup<"backend-plugin">;
 def RemarkBackendPlugin : DiagGroup<"remark-backend-plugin">;

diff  --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index 6853926f4362..ff56b2902c54 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -301,14 +301,7 @@ namespace clang {
   if (!getModule())
 return;
 
-  // Install an inline asm handler so that diagnostics get printed through
-  // our diagnostics hooks.
   LLVMContext  = getModule()->getContext();
-  LLVMContext::InlineAsmDiagHandlerTy OldHandler =
-Ctx.getInlineAsmDiagnosticHandler();

[clang] fc39425 - [NFCI] Add a missing triple in clang/test/CodeGen/ppc64le-varargs-f128.c

2020-12-09 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2020-12-09T18:17:34-08:00
New Revision: fc3942526f5c048759e90d10289ecef75410f728

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

LOG: [NFCI] Add a missing triple in clang/test/CodeGen/ppc64le-varargs-f128.c

Added: 


Modified: 
clang/test/CodeGen/ppc64le-varargs-f128.c

Removed: 




diff  --git a/clang/test/CodeGen/ppc64le-varargs-f128.c 
b/clang/test/CodeGen/ppc64le-varargs-f128.c
index 7868fe322ce8..3cc13c259977 100644
--- a/clang/test/CodeGen/ppc64le-varargs-f128.c
+++ b/clang/test/CodeGen/ppc64le-varargs-f128.c
@@ -12,7 +12,7 @@
 // RUN:   -target-feature +float128 -fopenmp -fopenmp-is-device -emit-llvm \
 // RUN:   -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s \
 // RUN:   -check-prefix=OMP-TARGET
-// RUN: %clang_cc1 %t-ppc-host.bc -emit-llvm -o - | FileCheck %s \
+// RUN: %clang_cc1 -triple ppc64le %t-ppc-host.bc -emit-llvm -o - | FileCheck 
%s \
 // RUN:   -check-prefix=OMP-HOST
 
 #include 



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


[clang] 8b23b3a - [NFCI] Add missing triple to several LTO tests

2020-12-09 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2020-12-09T13:13:58-08:00
New Revision: 8b23b3ab3aea28b91e5aa48f29fe9eb1828515a3

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

LOG: [NFCI] Add missing triple to several LTO tests

Also remove the module triple of clang/test/CodeGenObjC/arc.ll, the
commandline tripe is all it needs.

Added: 


Modified: 
clang/test/CodeGenObjC/arc.ll
llvm/test/ThinLTO/X86/Inputs/distributed_import.ll
llvm/test/tools/gold/X86/Inputs/comdat.ll
llvm/test/tools/gold/X86/Inputs/type-merge2.ll
llvm/test/tools/gold/X86/Inputs/visibility.ll

Removed: 




diff  --git a/clang/test/CodeGenObjC/arc.ll b/clang/test/CodeGenObjC/arc.ll
index 7b903d05cd17..cfc88c3c7eb7 100644
--- a/clang/test/CodeGenObjC/arc.ll
+++ b/clang/test/CodeGenObjC/arc.ll
@@ -1,7 +1,5 @@
 ; RUN: %clang_cc1 -triple x86_64-apple-darwin10 -Os -emit-llvm -fobjc-arc -o - 
%s | FileCheck %s
 
-target triple = "x86_64-apple-darwin10"
-
 declare i8* @llvm.objc.retain(i8*)
 declare void @llvm.objc.release(i8*)
 

diff  --git a/llvm/test/ThinLTO/X86/Inputs/distributed_import.ll 
b/llvm/test/ThinLTO/X86/Inputs/distributed_import.ll
index 328603d20c46..d7d9bb6789af 100644
--- a/llvm/test/ThinLTO/X86/Inputs/distributed_import.ll
+++ b/llvm/test/ThinLTO/X86/Inputs/distributed_import.ll
@@ -1,4 +1,5 @@
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
 
 @G = internal global i32 7
 define i32 @g() {

diff  --git a/llvm/test/tools/gold/X86/Inputs/comdat.ll 
b/llvm/test/tools/gold/X86/Inputs/comdat.ll
index e70b71815665..ca4bbb4bf81e 100644
--- a/llvm/test/tools/gold/X86/Inputs/comdat.ll
+++ b/llvm/test/tools/gold/X86/Inputs/comdat.ll
@@ -1,4 +1,5 @@
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
 
 $c2 = comdat any
 $c1 = comdat any

diff  --git a/llvm/test/tools/gold/X86/Inputs/type-merge2.ll 
b/llvm/test/tools/gold/X86/Inputs/type-merge2.ll
index 7cdea6e82f37..7890c47a3004 100644
--- a/llvm/test/tools/gold/X86/Inputs/type-merge2.ll
+++ b/llvm/test/tools/gold/X86/Inputs/type-merge2.ll
@@ -1,4 +1,5 @@
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
 
 %zed = type { i16 }
 define void @bar(%zed* %this)  {

diff  --git a/llvm/test/tools/gold/X86/Inputs/visibility.ll 
b/llvm/test/tools/gold/X86/Inputs/visibility.ll
index 42796a97bc87..37442469aa7e 100644
--- a/llvm/test/tools/gold/X86/Inputs/visibility.ll
+++ b/llvm/test/tools/gold/X86/Inputs/visibility.ll
@@ -1,4 +1,5 @@
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
 
 define void @foo() {
   ret void



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


[clang] 1821265 - [Time-report] Add a flag -ftime-report={per-pass,per-pass-run} to control the pass timing aggregation

2020-12-08 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2020-12-08T10:13:19-08:00
New Revision: 1821265db681cd2289fce9331e3aed26bdf814e3

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

LOG: [Time-report] Add a flag -ftime-report={per-pass,per-pass-run} to control 
the pass timing aggregation

Currently, -ftime-report + new pass manager emits one line of report for each
pass run. This potentially causes huge output text especially with regular LTO
or large single file (Obeserved in private tests and was reported in D51276).
The behaviour of -ftime-report + legacy pass manager is
emitting one line of report for each pass object which has relatively reasonable
text output size. This patch adds a flag `-ftime-report=` to control time report
aggregation for new pass manager.

The flag is for new pass manager only. Using it with legacy pass manager gives
an error. It is a driver and cc1 flag. `per-pass` is the new default so
`-ftime-report` is aliased to `-ftime-report=per-pass`. Before this patch,
functionality-wise `-ftime-report` is aliased to `-ftime-report=per-pass-run`.

* Adds an boolean variable TimePassesHandler::PerRun to control per-pass vs 
per-pass-run.
* Adds a new clang CodeGen flag CodeGenOptions::TimePassesPerRun to work with 
the existing CodeGenOptions::TimePasses.
* Remove FrontendOptions::ShowTimers, its uses are replaced by the existing 
CodeGenOptions::TimePasses.
* Remove FrontendTimesIsEnabled (It was introduced in D45619 which was largely 
reverted.)

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

Added: 
clang/test/Driver/time-report.c
clang/test/Misc/time-passes.c

Modified: 
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Driver/Options.td
clang/include/clang/Frontend/FrontendOptions.h
clang/include/clang/Frontend/Utils.h
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/CodeGen/CodeGenAction.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CMakeLists.txt
clang/lib/Frontend/CompilerInstance.cpp
clang/lib/Frontend/CompilerInvocation.cpp
llvm/include/llvm/IR/PassTimingInfo.h
llvm/include/llvm/Pass.h
llvm/lib/IR/PassTimingInfo.cpp
llvm/test/Other/time-passes.ll

Removed: 
clang/lib/Frontend/FrontendTiming.cpp



diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index d4bbdbfa13b5..9c3b4f8289f9 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -252,7 +252,8 @@ CODEGENOPT(SpeculativeLoadHardening, 1, 0) ///< Enable 
speculative load hardenin
 CODEGENOPT(FineGrainedBitfieldAccesses, 1, 0) ///< Enable fine-grained 
bitfield accesses.
 CODEGENOPT(StrictEnums   , 1, 0) ///< Optimize based on strict enum 
definition.
 CODEGENOPT(StrictVTablePointers, 1, 0) ///< Optimize based on the strict 
vtable pointers
-CODEGENOPT(TimePasses, 1, 0) ///< Set when -ftime-report is enabled.
+CODEGENOPT(TimePasses, 1, 0) ///< Set when -ftime-report or 
-ftime-report= is enabled.
+CODEGENOPT(TimePassesPerRun  , 1, 0) ///< Set when -ftime-report=per-pass-run 
is enabled.
 CODEGENOPT(TimeTrace , 1, 0) ///< Set when -ftime-trace is enabled.
 VALUE_CODEGENOPT(TimeTraceGranularity, 32, 500) ///< Minimum time granularity 
(in microseconds),
///< traced by time profiler

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 794aa24f997d..8cabcd671161 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2005,7 +2005,12 @@ def Wframe_larger_than_EQ : Joined<["-"], 
"Wframe-larger-than=">, Group
 def : Flag<["-"], "fterminated-vtables">, Alias;
 def fthreadsafe_statics : Flag<["-"], "fthreadsafe-statics">, Group;
 def ftime_report : Flag<["-"], "ftime-report">, Group, 
Flags<[CC1Option]>,
-  MarshallingInfoFlag<"FrontendOpts.ShowTimers">;
+  MarshallingInfoFlag<"CodeGenOpts.TimePasses">;
+def ftime_report_EQ: Joined<["-"], "ftime-report=">, Group,
+  Flags<[CC1Option]>, Values<"per-pass,per-pass-run">,
+  MarshallingInfoFlag<"CodeGenOpts.TimePassesPerRun">,
+  HelpText<"(For new pass manager) \"per-pass\": one report for each pass; "
+   "\"per-pass-run\": one report for each pass invocation">;
 def ftime_trace : Flag<["-"], "ftime-trace">, Group,
   HelpText<"Turn on time profiler. Generates JSON file based on output 
filename.">,
   DocBrief<[{

diff  --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Frontend/FrontendOptions.h
index b06ad5203e75..223c1e05d053 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -239,9 +239,6 @@ class FrontendOptions {

[clang] 2c94d88 - [NewPM] collapsing nested pass mangers of the same type

2020-10-04 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2020-10-04T15:57:13-07:00
New Revision: 2c94d88e076990a7b533578a392a150d4b9b0fa8

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

LOG: [NewPM] collapsing nested pass mangers of the same type

This is one of the reason for extra invalidations in D84959. In
practice, I don't think we have use cases needing this. This simplifies
the pipeline a bit and prune corner cases when considering
invalidations.

Reviewed By: asbirlea

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

Added: 


Modified: 
clang/test/CodeGen/thinlto-distributed-newpm.ll
llvm/include/llvm/IR/PassManager.h
llvm/test/Other/new-pass-manager.ll
llvm/test/Other/new-pm-defaults.ll
llvm/test/Other/new-pm-lto-defaults.ll
llvm/test/Other/new-pm-thinlto-defaults.ll
llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll
llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
llvm/test/Other/pass-pipeline-parsing.ll

Removed: 




diff  --git a/clang/test/CodeGen/thinlto-distributed-newpm.ll 
b/clang/test/CodeGen/thinlto-distributed-newpm.ll
index 9f9a8bec4ef5..ec56845a8fdf 100644
--- a/clang/test/CodeGen/thinlto-distributed-newpm.ll
+++ b/clang/test/CodeGen/thinlto-distributed-newpm.ll
@@ -25,7 +25,6 @@
 ; CHECK-O: Running pass: LowerTypeTestsPass
 ; CHECK-O: Invalidating analysis: InnerAnalysisManagerProxy
 ; CHECK-O: Running pass: ForceFunctionAttrsPass
-; CHECK-O: Starting {{.*}}Module pass manager run.
 ; CHECK-O: Running pass: PGOIndirectCallPromotion
 ; CHECK-O: Running analysis: ProfileSummaryAnalysis
 ; CHECK-O: Running analysis: InnerAnalysisManagerProxy
@@ -151,8 +150,6 @@
 ; CHECK-O: Invalidating analysis: DemandedBitsAnalysis on main
 ; CHECK-O: Invalidating analysis: PostDominatorTreeAnalysis on main
 ; CHECK-O: Invalidating analysis: CallGraphAnalysis
-; CHECK-O: Finished {{.*}}Module pass manager run.
-; CHECK-O: Starting {{.*}}Module pass manager run.
 ; CHECK-O: Running pass: GlobalOptPass
 ; CHECK-O: Running pass: GlobalDCEPass
 ; CHECK-O: Running pass: EliminateAvailableExternallyPass
@@ -207,7 +204,6 @@
 ; CHECK-O: Running pass: GlobalDCEPass
 ; CHECK-O: Running pass: ConstantMergePass
 ; CHECK-O: Finished {{.*}}Module pass manager run.
-; CHECK-O: Finished {{.*}}Module pass manager run.
 
 target datalayout = 
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-grtev4-linux-gnu"

diff  --git a/llvm/include/llvm/IR/PassManager.h 
b/llvm/include/llvm/IR/PassManager.h
index 6b4f8e3140ee..44f8900f2ebf 100644
--- a/llvm/include/llvm/IR/PassManager.h
+++ b/llvm/include/llvm/IR/PassManager.h
@@ -548,7 +548,9 @@ class PassManager : public PassInfoMixin<
 return PA;
   }
 
-  template  void addPass(PassT Pass) {
+  template 
+  std::enable_if_t::value>
+  addPass(PassT Pass) {
 using PassModelT =
 detail::PassModel;
@@ -556,6 +558,18 @@ class PassManager : public PassInfoMixin<
 Passes.emplace_back(new PassModelT(std::move(Pass)));
   }
 
+  /// When adding a pass manager pass that has the same type as this pass
+  /// manager, simply move the passes over. This is because we don't have use
+  /// cases rely on executing nested pass managers. Doing this could reduce
+  /// implementation complexity and avoid potential invalidation issues that 
may
+  /// happen with nested pass managers of the same type.
+  template 
+  std::enable_if_t::value>
+  addPass(PassT &) {
+for (auto  : Pass.Passes)
+  Passes.emplace_back(std::move(P));
+  }
+
   static bool isRequired() { return true; }
 
 protected:

diff  --git a/llvm/test/Other/new-pass-manager.ll 
b/llvm/test/Other/new-pass-manager.ll
index 31be3adb6897..70d1f7152120 100644
--- a/llvm/test/Other/new-pass-manager.ll
+++ b/llvm/test/Other/new-pass-manager.ll
@@ -207,7 +207,6 @@
 ; CHECK-INVALIDATE-ALL: Starting llvm::Module pass manager run
 ; CHECK-INVALIDATE-ALL: Running pass: RequireAnalysisPass
 ; CHECK-INVALIDATE-ALL: Running analysis: NoOpModuleAnalysis
-; CHECK-INVALIDATE-ALL: Starting llvm::Module pass manager run
 ; CHECK-INVALIDATE-ALL: Running pass: RequireAnalysisPass
 ; CHECK-INVALIDATE-ALL-NOT: Running analysis: NoOpModuleAnalysis
 ; CHECK-INVALIDATE-ALL: Starting llvm::Function pass manager run
@@ -221,7 +220,6 @@
 ; CHECK-INVALIDATE-ALL: Invalidating analysis: NoOpModuleAnalysis
 ; CHECK-INVALIDATE-ALL: Running pass: RequireAnalysisPass
 ; CHECK-INVALIDATE-ALL: Running analysis: NoOpModuleAnalysis
-; CHECK-INVALIDATE-ALL: Finished llvm::Module pass manager run
 ; CHECK-INVALIDATE-ALL-NOT: Invalidating analysis: NoOpModuleAnalysis
 ; CHECK-INVALIDATE-ALL: Running pass: 

[clang] 555cf42 - [NewPM][PassInstrument] Add PrintPass callback to StandardInstrumentations

2020-07-30 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2020-07-30T10:07:57-07:00
New Revision: 555cf42f380d86f35e761c3a2179c761356ab152

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

LOG: [NewPM][PassInstrument] Add PrintPass callback to StandardInstrumentations

Problem:
Right now, our "Running pass" is not accurate when passes are wrapped in 
adaptor because adaptor is never skipped and a pass could be skipped. The other 
problem is that "Running pass" for a adaptor is before any "Running pass" of 
passes/analyses it depends on. (for example, FunctionToLoopPassAdaptor). So the 
order of printing is not the actual order.

Solution:
Doing things like PassManager::Debuglogging is very intrusive because we need 
to specify Debuglogging whenever adaptor is created. (Actually, right now we're 
not specifying Debuglogging for some sub-PassManagers. Check PassBuilder)

This patch move debug logging for pass as a PassInstrument callback. We could 
be sure that all running passes are logged and in the correct order.

This could also be used to implement hierarchy pass logging in legacy PM. We 
could also move logging of pass manager to this if we want.

The test fixes looks messy. It includes changes:
- Remove PassInstrumentationAnalysis
- Remove PassAdaptor
- If a PassAdaptor is for a real pass, the pass is added
- Pass reorder (to the correct order), related to PassAdaptor
- Add missing passes (due to Debuglogging not passed down)

Reviewed By: asbirlea, aeubanks

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

Added: 


Modified: 
clang/test/CodeGen/thinlto-distributed-newpm.ll
llvm/include/llvm/IR/PassInstrumentation.h
llvm/include/llvm/IR/PassManager.h
llvm/include/llvm/IR/PassManagerImpl.h
llvm/include/llvm/Passes/StandardInstrumentations.h
llvm/lib/Analysis/CGSCCPassManager.cpp
llvm/lib/IR/PassInstrumentation.cpp
llvm/lib/IR/PassTimingInfo.cpp
llvm/lib/Passes/StandardInstrumentations.cpp
llvm/lib/Transforms/Scalar/LoopPassManager.cpp
llvm/test/Other/loop-pm-invalidation.ll
llvm/test/Other/new-pass-manager.ll
llvm/test/Other/new-pm-defaults.ll
llvm/test/Other/new-pm-lto-defaults.ll
llvm/test/Other/new-pm-pgo.ll
llvm/test/Other/new-pm-thinlto-defaults.ll
llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll
llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
llvm/test/Other/pass-pipeline-parsing.ll
llvm/test/Transforms/LoopRotate/pr35210.ll
llvm/test/Transforms/LoopUnroll/revisit.ll
llvm/test/Transforms/LoopUnroll/unroll-loop-invalidation.ll
llvm/test/Transforms/SCCP/ipsccp-preserve-analysis.ll

Removed: 




diff  --git a/clang/test/CodeGen/thinlto-distributed-newpm.ll 
b/clang/test/CodeGen/thinlto-distributed-newpm.ll
index 6269fd677ca8..3dcc6a196365 100644
--- a/clang/test/CodeGen/thinlto-distributed-newpm.ll
+++ b/clang/test/CodeGen/thinlto-distributed-newpm.ll
@@ -1,3 +1,4 @@
+; FIXME: This test should use CHECK-NEXT to keep up-to-date.
 ; REQUIRES: x86-registered-target
 
 ; Validate ThinLTO post link pipeline at O2 and O3
@@ -18,7 +19,6 @@
 ; RUN:   -c -fthinlto-index=%t.o.thinlto.bc \
 ; RUN:   -o %t.native.o -x ir %t.o 2>&1 | FileCheck 
-check-prefixes=CHECK-O,CHECK-O3 %s --dump-input=fail
 
-; CHECK-O: Running analysis: PassInstrumentationAnalysis
 ; CHECK-O: Starting {{.*}}Module pass manager run.
 ; CHECK-O: Running pass: WholeProgramDevirtPass
 ; CHECK-O: Running analysis: InnerAnalysisManagerProxy
@@ -26,15 +26,12 @@
 ; CHECK-O: Invalidating all non-preserved analyses for:
 ; CHECK-O: Invalidating analysis: InnerAnalysisManagerProxy
 ; CHECK-O: Running pass: ForceFunctionAttrsPass
-; CHECK-O: Running pass: PassManager<{{.*}}Module>
 ; CHECK-O: Starting {{.*}}Module pass manager run.
 ; CHECK-O: Running pass: PGOIndirectCallPromotion
 ; CHECK-O: Running analysis: ProfileSummaryAnalysis
 ; CHECK-O: Running analysis: InnerAnalysisManagerProxy
 ; CHECK-O: Running analysis: OptimizationRemarkEmitterAnalysis on main
-; CHECK-O: Running analysis: PassInstrumentationAnalysis on main
 ; CHECK-O: Running pass: InferFunctionAttrsPass
-; CHECK-O: Running pass: 
ModuleToFunctionPassAdaptor<{{.*}}PassManager<{{.*}}Function>{{ ?}}>
 ; CHECK-O: Starting {{.*}}Function pass manager run.
 ; CHECK-O: Running pass: SimplifyCFGPass on main
 ; CHECK-O: Running analysis: TargetIRAnalysis on main
@@ -46,18 +43,17 @@
 ; CHECK-O: Running pass: LowerExpectIntrinsicPass on main
 ; CHECK-O3: Running pass: CallSiteSplittingPass on main
 ; CHECK-O: Finished {{.*}}Function pass manager run.
+; CHECK-O: Running pass: LowerTypeTestsPass
 ; CHECK-O: Running pass: IPSCCPPass
 ; CHECK-O: Running 

[clang] 2956cc5 - [Clang][Driver] Remove gold linker support for PS4 toolchain

2020-06-17 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2020-06-17T09:45:14-07:00
New Revision: 2956cc50f3405ae32c8c6d6e2c63fe8cb6456fa2

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

LOG: [Clang][Driver] Remove gold linker support for PS4 toolchain

Reviewers: probinson

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/PS4CPU.cpp
clang/test/Driver/ps4-linker-non-win.c
clang/test/Driver/ps4-linker-win.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index ebeed3803e06..49f26c370168 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -88,13 +88,13 @@ void tools::PS4cpu::addSanitizerArgs(const ToolChain ,
 CmdArgs.push_back("--dependent-lib=libSceDbgAddressSanitizer_stub_weak.a");
 }
 
-static void ConstructPS4LinkJob(const Tool , Compilation ,
-const JobAction , const InputInfo ,
-const InputInfoList ,
-const ArgList ,
-const char *LinkingOutput) {
+void tools::PS4cpu::Link::ConstructJob(Compilation , const JobAction ,
+   const InputInfo ,
+   const InputInfoList ,
+   const ArgList ,
+   const char *LinkingOutput) const {
   const toolchains::FreeBSD  =
-  static_cast(T.getToolChain());
+  static_cast(getToolChain());
   const Driver  = ToolChain.getDriver();
   ArgStringList CmdArgs;
 
@@ -143,216 +143,15 @@ static void ConstructPS4LinkJob(const Tool , 
Compilation ,
 CmdArgs.push_back("-lpthread");
   }
 
-  const char *Exec = Args.MakeArgString(ToolChain.GetProgramPath("orbis-ld"));
-
-  C.addCommand(std::make_unique(JA, T, Exec, CmdArgs, Inputs));
-}
-
-static void ConstructGoldLinkJob(const Tool , Compilation ,
- const JobAction , const InputInfo ,
- const InputInfoList ,
- const ArgList ,
- const char *LinkingOutput) {
-  const toolchains::FreeBSD  =
-  static_cast(T.getToolChain());
-  const Driver  = ToolChain.getDriver();
-  ArgStringList CmdArgs;
-
-  // Silence warning for "clang -g foo.o -o foo"
-  Args.ClaimAllArgs(options::OPT_g_Group);
-  // and "clang -emit-llvm foo.o -o foo"
-  Args.ClaimAllArgs(options::OPT_emit_llvm);
-  // and for "clang -w foo.o -o foo". Other warning options are already
-  // handled somewhere else.
-  Args.ClaimAllArgs(options::OPT_w);
-
-  if (!D.SysRoot.empty())
-CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
-
-  if (Args.hasArg(options::OPT_pie))
-CmdArgs.push_back("-pie");
-
-  if (Args.hasArg(options::OPT_static)) {
-CmdArgs.push_back("-Bstatic");
-  } else {
-if (Args.hasArg(options::OPT_rdynamic))
-  CmdArgs.push_back("-export-dynamic");
-CmdArgs.push_back("--eh-frame-hdr");
-if (Args.hasArg(options::OPT_shared)) {
-  CmdArgs.push_back("-Bshareable");
-} else {
-  CmdArgs.push_back("-dynamic-linker");
-  CmdArgs.push_back("/libexec/ld-elf.so.1");
-}
-CmdArgs.push_back("--enable-new-dtags");
-  }
-
-  if (Output.isFilename()) {
-CmdArgs.push_back("-o");
-CmdArgs.push_back(Output.getFilename());
-  } else {
-assert(Output.isNothing() && "Invalid output.");
-  }
-
-  if(!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
-AddPS4SanitizerArgs(ToolChain, CmdArgs);
-
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
-const char *crt1 = nullptr;
-if (!Args.hasArg(options::OPT_shared)) {
-  if (Args.hasArg(options::OPT_pg))
-crt1 = "gcrt1.o";
-  else if (Args.hasArg(options::OPT_pie))
-crt1 = "Scrt1.o";
-  else
-crt1 = "crt1.o";
-}
-if (crt1)
-  CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crt1)));
-
-CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.o")));
-
-const char *crtbegin = nullptr;
-if (Args.hasArg(options::OPT_static))
-  crtbegin = "crtbeginT.o";
-else if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie))
-  crtbegin = "crtbeginS.o";
-else
-  crtbegin = "crtbegin.o";
-
-CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtbegin)));
-  }
-
-  Args.AddAllArgs(CmdArgs, options::OPT_L);
-  ToolChain.AddFilePathLibArgs(Args, CmdArgs);
-  Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
-  Args.AddAllArgs(CmdArgs, options::OPT_e);
-  Args.AddAllArgs(CmdArgs, 

[clang] 8d4a806 - Revert "remove gold linker"

2020-06-16 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2020-06-16T13:05:53-07:00
New Revision: 8d4a806ef0b988200111b7d99f792361bcd3f7d1

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

LOG: Revert "remove gold linker"

This reverts commit 719c87edc58018a0e9f3ee04305e081d4b582c2b.

Checked in by accident. Sorry.

Added: 


Modified: 
clang/lib/Driver/ToolChains/PS4CPU.cpp
clang/test/Driver/ps4-linker-non-win.c
clang/test/Driver/ps4-linker-win.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 379b88017b0e..ebeed3803e06 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -88,13 +88,13 @@ void tools::PS4cpu::addSanitizerArgs(const ToolChain ,
 CmdArgs.push_back("--dependent-lib=libSceDbgAddressSanitizer_stub_weak.a");
 }
 
-void tools::PS4cpu::Link::ConstructJob(Compilation , const JobAction ,
-   const InputInfo ,
-   const InputInfoList ,
-   const ArgList ,
-   const char *LinkingOutput) const {
+static void ConstructPS4LinkJob(const Tool , Compilation ,
+const JobAction , const InputInfo ,
+const InputInfoList ,
+const ArgList ,
+const char *LinkingOutput) {
   const toolchains::FreeBSD  =
-  static_cast(getToolChain());
+  static_cast(T.getToolChain());
   const Driver  = ToolChain.getDriver();
   ArgStringList CmdArgs;
 
@@ -143,17 +143,216 @@ void tools::PS4cpu::Link::ConstructJob(Compilation , 
const JobAction ,
 CmdArgs.push_back("-lpthread");
   }
 
-  if (Args.hasArg(options::OPT_fuse_ld_EQ)) {
-D.Diag(diag::err_drv_unsupported_opt_for_target)
-<< "-fuse-ld" << getToolChain().getTriple().str();
+  const char *Exec = Args.MakeArgString(ToolChain.GetProgramPath("orbis-ld"));
+
+  C.addCommand(std::make_unique(JA, T, Exec, CmdArgs, Inputs));
+}
+
+static void ConstructGoldLinkJob(const Tool , Compilation ,
+ const JobAction , const InputInfo ,
+ const InputInfoList ,
+ const ArgList ,
+ const char *LinkingOutput) {
+  const toolchains::FreeBSD  =
+  static_cast(T.getToolChain());
+  const Driver  = ToolChain.getDriver();
+  ArgStringList CmdArgs;
+
+  // Silence warning for "clang -g foo.o -o foo"
+  Args.ClaimAllArgs(options::OPT_g_Group);
+  // and "clang -emit-llvm foo.o -o foo"
+  Args.ClaimAllArgs(options::OPT_emit_llvm);
+  // and for "clang -w foo.o -o foo". Other warning options are already
+  // handled somewhere else.
+  Args.ClaimAllArgs(options::OPT_w);
+
+  if (!D.SysRoot.empty())
+CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
+
+  if (Args.hasArg(options::OPT_pie))
+CmdArgs.push_back("-pie");
+
+  if (Args.hasArg(options::OPT_static)) {
+CmdArgs.push_back("-Bstatic");
+  } else {
+if (Args.hasArg(options::OPT_rdynamic))
+  CmdArgs.push_back("-export-dynamic");
+CmdArgs.push_back("--eh-frame-hdr");
+if (Args.hasArg(options::OPT_shared)) {
+  CmdArgs.push_back("-Bshareable");
+} else {
+  CmdArgs.push_back("-dynamic-linker");
+  CmdArgs.push_back("/libexec/ld-elf.so.1");
+}
+CmdArgs.push_back("--enable-new-dtags");
+  }
+
+  if (Output.isFilename()) {
+CmdArgs.push_back("-o");
+CmdArgs.push_back(Output.getFilename());
+  } else {
+assert(Output.isNothing() && "Invalid output.");
+  }
+
+  if(!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
+AddPS4SanitizerArgs(ToolChain, CmdArgs);
+
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
+const char *crt1 = nullptr;
+if (!Args.hasArg(options::OPT_shared)) {
+  if (Args.hasArg(options::OPT_pg))
+crt1 = "gcrt1.o";
+  else if (Args.hasArg(options::OPT_pie))
+crt1 = "Scrt1.o";
+  else
+crt1 = "crt1.o";
+}
+if (crt1)
+  CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crt1)));
+
+CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.o")));
+
+const char *crtbegin = nullptr;
+if (Args.hasArg(options::OPT_static))
+  crtbegin = "crtbeginT.o";
+else if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie))
+  crtbegin = "crtbeginS.o";
+else
+  crtbegin = "crtbegin.o";
+
+CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtbegin)));
+  }
+
+  Args.AddAllArgs(CmdArgs, options::OPT_L);
+  ToolChain.AddFilePathLibArgs(Args, CmdArgs);
+  

[clang] 8c6c606 - [Clang] Add a "#pragma unroll" test case for correct error reporting

2020-06-16 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2020-06-16T13:03:32-07:00
New Revision: 8c6c606cdc72c3ddd55f382d91ef1afc3cb9f2a8

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

LOG: [Clang] Add a "#pragma unroll" test case for correct error reporting

For PR46336.

Added: 


Modified: 
clang/test/Parser/pragma-unroll.cpp

Removed: 




diff  --git a/clang/test/Parser/pragma-unroll.cpp 
b/clang/test/Parser/pragma-unroll.cpp
index fb713812877e..c89cf49a0020 100644
--- a/clang/test/Parser/pragma-unroll.cpp
+++ b/clang/test/Parser/pragma-unroll.cpp
@@ -55,6 +55,15 @@ void test(int *List, int Length) {
 #pragma nounroll
 /* expected-error {{expected a for, while, or do-while loop to follow '#pragma 
nounroll'}} */ int l = Length;
 
+  switch (i) {
+  case 1:
+#pragma unroll
+/* expected-error {{expected a for, while, or do-while loop to follow '#pragma 
unroll'}} */ [[fallthrough]];
+  case 2:
+for (int i = 0; i < 10; ++i);
+break;
+  }
+
 #pragma unroll 4
 /* expected-error {{incompatible directives 'unroll(disable)' and '#pragma 
unroll(4)'}} */ #pragma clang loop unroll(disable)
   while (i-10 < Length) {



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


[clang] 719c87e - remove gold linker

2020-06-16 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2020-06-16T13:03:31-07:00
New Revision: 719c87edc58018a0e9f3ee04305e081d4b582c2b

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

LOG: remove gold linker

Added: 


Modified: 
clang/lib/Driver/ToolChains/PS4CPU.cpp
clang/test/Driver/ps4-linker-non-win.c
clang/test/Driver/ps4-linker-win.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index ebeed3803e06..379b88017b0e 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -88,13 +88,13 @@ void tools::PS4cpu::addSanitizerArgs(const ToolChain ,
 CmdArgs.push_back("--dependent-lib=libSceDbgAddressSanitizer_stub_weak.a");
 }
 
-static void ConstructPS4LinkJob(const Tool , Compilation ,
-const JobAction , const InputInfo ,
-const InputInfoList ,
-const ArgList ,
-const char *LinkingOutput) {
+void tools::PS4cpu::Link::ConstructJob(Compilation , const JobAction ,
+   const InputInfo ,
+   const InputInfoList ,
+   const ArgList ,
+   const char *LinkingOutput) const {
   const toolchains::FreeBSD  =
-  static_cast(T.getToolChain());
+  static_cast(getToolChain());
   const Driver  = ToolChain.getDriver();
   ArgStringList CmdArgs;
 
@@ -143,216 +143,17 @@ static void ConstructPS4LinkJob(const Tool , 
Compilation ,
 CmdArgs.push_back("-lpthread");
   }
 
-  const char *Exec = Args.MakeArgString(ToolChain.GetProgramPath("orbis-ld"));
-
-  C.addCommand(std::make_unique(JA, T, Exec, CmdArgs, Inputs));
-}
-
-static void ConstructGoldLinkJob(const Tool , Compilation ,
- const JobAction , const InputInfo ,
- const InputInfoList ,
- const ArgList ,
- const char *LinkingOutput) {
-  const toolchains::FreeBSD  =
-  static_cast(T.getToolChain());
-  const Driver  = ToolChain.getDriver();
-  ArgStringList CmdArgs;
-
-  // Silence warning for "clang -g foo.o -o foo"
-  Args.ClaimAllArgs(options::OPT_g_Group);
-  // and "clang -emit-llvm foo.o -o foo"
-  Args.ClaimAllArgs(options::OPT_emit_llvm);
-  // and for "clang -w foo.o -o foo". Other warning options are already
-  // handled somewhere else.
-  Args.ClaimAllArgs(options::OPT_w);
-
-  if (!D.SysRoot.empty())
-CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
-
-  if (Args.hasArg(options::OPT_pie))
-CmdArgs.push_back("-pie");
-
-  if (Args.hasArg(options::OPT_static)) {
-CmdArgs.push_back("-Bstatic");
-  } else {
-if (Args.hasArg(options::OPT_rdynamic))
-  CmdArgs.push_back("-export-dynamic");
-CmdArgs.push_back("--eh-frame-hdr");
-if (Args.hasArg(options::OPT_shared)) {
-  CmdArgs.push_back("-Bshareable");
-} else {
-  CmdArgs.push_back("-dynamic-linker");
-  CmdArgs.push_back("/libexec/ld-elf.so.1");
-}
-CmdArgs.push_back("--enable-new-dtags");
-  }
-
-  if (Output.isFilename()) {
-CmdArgs.push_back("-o");
-CmdArgs.push_back(Output.getFilename());
-  } else {
-assert(Output.isNothing() && "Invalid output.");
-  }
-
-  if(!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
-AddPS4SanitizerArgs(ToolChain, CmdArgs);
-
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
-const char *crt1 = nullptr;
-if (!Args.hasArg(options::OPT_shared)) {
-  if (Args.hasArg(options::OPT_pg))
-crt1 = "gcrt1.o";
-  else if (Args.hasArg(options::OPT_pie))
-crt1 = "Scrt1.o";
-  else
-crt1 = "crt1.o";
-}
-if (crt1)
-  CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crt1)));
-
-CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.o")));
-
-const char *crtbegin = nullptr;
-if (Args.hasArg(options::OPT_static))
-  crtbegin = "crtbeginT.o";
-else if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie))
-  crtbegin = "crtbeginS.o";
-else
-  crtbegin = "crtbegin.o";
-
-CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtbegin)));
-  }
-
-  Args.AddAllArgs(CmdArgs, options::OPT_L);
-  ToolChain.AddFilePathLibArgs(Args, CmdArgs);
-  Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
-  Args.AddAllArgs(CmdArgs, options::OPT_e);
-  Args.AddAllArgs(CmdArgs, options::OPT_s);
-  Args.AddAllArgs(CmdArgs, options::OPT_t);
-  Args.AddAllArgs(CmdArgs, options::OPT_r);
-
-  if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle))
-

[clang] 4676cf4 - [Clang] Skip adding begin source location for PragmaLoopHint'd loop when

2020-06-16 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2020-06-16T10:19:36-07:00
New Revision: 4676cf444ea2678660ee48279be99efde4bf60e9

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

LOG: [Clang] Skip adding begin source location for PragmaLoopHint'd loop when
the range start is already set

The range start could be set already in some invalid cases. Fixes
PR46336.

Added: 


Modified: 
clang/lib/Parse/ParseStmt.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index d00f6b640fb4..773c31ff3aec 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -2195,9 +2195,11 @@ StmtResult Parser::ParsePragmaLoopHint(StmtVector ,
 
   Attrs.takeAllFrom(TempAttrs);
 
-  assert(Attrs.Range.getBegin().isInvalid() &&
- "start of attribute range already set");
-  Attrs.Range.setBegin(StartLoc);
+  // Start of attribute range may already be set for some invalid input.
+  // See PR46336.
+  if (Attrs.Range.getBegin().isInvalid())
+Attrs.Range.setBegin(StartLoc);
+
   return S;
 }
 



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


[clang] 9c2e770 - Add begin source location for the attributed statement created from PragmaLoopHint decorated loop

2020-06-09 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2020-06-09T10:08:40-07:00
New Revision: 9c2e770034d04a0966b84cac14a9e3fb3b0d4ab7

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

LOG: Add begin source location for the attributed statement created from 
PragmaLoopHint decorated loop

Summary:
Right now it is a '' for cases like this.
CounterCoverageMappingBuilder relies on the information to decide the
region for a attributed loop.

Fixes PR40971

Reviewers: ABataev, jdenny, lebedev.ri, aaron.ballman

Reviewed by: jdenny, aaron.ballman

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

Added: 


Modified: 
clang/lib/Parse/ParsePragma.cpp
clang/lib/Parse/ParseStmt.cpp
clang/test/AST/sourceranges.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp
index 816aaf9f0956..2631c3556273 100644
--- a/clang/lib/Parse/ParsePragma.cpp
+++ b/clang/lib/Parse/ParsePragma.cpp
@@ -3099,7 +3099,7 @@ void PragmaLoopHintHandler::HandlePragma(Preprocessor ,
 Token LoopHintTok;
 LoopHintTok.startToken();
 LoopHintTok.setKind(tok::annot_pragma_loop_hint);
-LoopHintTok.setLocation(PragmaName.getLocation());
+LoopHintTok.setLocation(Introducer.Loc);
 LoopHintTok.setAnnotationEndLoc(PragmaName.getLocation());
 LoopHintTok.setAnnotationValue(static_cast(Info));
 TokenList.push_back(LoopHintTok);
@@ -3186,7 +3186,7 @@ void PragmaUnrollHintHandler::HandlePragma(Preprocessor 
,
   auto TokenArray = std::make_unique(1);
   TokenArray[0].startToken();
   TokenArray[0].setKind(tok::annot_pragma_loop_hint);
-  TokenArray[0].setLocation(PragmaName.getLocation());
+  TokenArray[0].setLocation(Introducer.Loc);
   TokenArray[0].setAnnotationEndLoc(PragmaName.getLocation());
   TokenArray[0].setAnnotationValue(static_cast(Info));
   PP.EnterTokenStream(std::move(TokenArray), 1,

diff  --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index 84166bbbdc7b..d00f6b640fb4 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -2172,6 +2172,8 @@ StmtResult Parser::ParsePragmaLoopHint(StmtVector ,
   // Create temporary attribute list.
   ParsedAttributesWithRange TempAttrs(AttrFactory);
 
+  SourceLocation StartLoc = Tok.getLocation();
+
   // Get loop hints and consume annotated token.
   while (Tok.is(tok::annot_pragma_loop_hint)) {
 LoopHint Hint;
@@ -2192,6 +2194,10 @@ StmtResult Parser::ParsePragmaLoopHint(StmtVector ,
   Stmts, StmtCtx, TrailingElseLoc, Attrs);
 
   Attrs.takeAllFrom(TempAttrs);
+
+  assert(Attrs.Range.getBegin().isInvalid() &&
+ "start of attribute range already set");
+  Attrs.Range.setBegin(StartLoc);
   return S;
 }
 

diff  --git a/clang/test/AST/sourceranges.cpp b/clang/test/AST/sourceranges.cpp
index 3c023c868946..a38ec3207ae4 100644
--- a/clang/test/AST/sourceranges.cpp
+++ b/clang/test/AST/sourceranges.cpp
@@ -108,6 +108,36 @@ namespace attributed_decl {
   }
 }
 
+// CHECK: NamespaceDecl {{.*}} attributed_stmt
+namespace attributed_stmt {
+  // In DO_PRAGMA and _Pragma cases, `LoopHintAttr` comes from 
+  // file.
+
+  #define DO_PRAGMA(x) _Pragma (#x)
+
+  void f() {
+// CHECK: AttributedStmt {{.*}} 
+DO_PRAGMA (unroll(2))
+for (int i = 0; i < 10; ++i);
+
+// CHECK: AttributedStmt {{.*}} 
+// CHECK: LoopHintAttr {{.*}} 
+#pragma unroll(2)
+for (int i = 0; i < 10; ++i);
+
+// CHECK: AttributedStmt {{.*}} 
+// CHECK: LoopHintAttr {{.*}} 
+#pragma clang loop vectorize(enable)
+// CHECK: LoopHintAttr {{.*}} 
+#pragma clang loop interleave(enable)
+for (int i = 0; i < 10; ++i);
+
+// CHECK: AttributedStmt {{.*}} 
+_Pragma("unroll(2)")
+for (int i = 0; i < 10; ++i);
+  }
+}
+
 #if __cplusplus >= 201703L
 // CHECK-1Z: FunctionDecl {{.*}} construct_with_init_list
 std::map construct_with_init_list() {



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


[clang] f9ea86e - [Docs] Add the entry for `Advanced builds` in UserGuide.rst

2020-06-04 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2020-06-04T14:52:51-07:00
New Revision: f9ea86eaa1a3ba18973666c4de56dfde8d488574

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

LOG: [Docs] Add the entry for `Advanced builds` in UserGuide.rst

Also add a link to it from ThinLTO.rst.

Added: 


Modified: 
clang/docs/ThinLTO.rst
llvm/docs/UserGuides.rst

Removed: 




diff  --git a/clang/docs/ThinLTO.rst b/clang/docs/ThinLTO.rst
index 2d5d0a71fa6b..528530c5ae98 100644
--- a/clang/docs/ThinLTO.rst
+++ b/clang/docs/ThinLTO.rst
@@ -194,7 +194,8 @@ Possible key-value pairs are:
 Clang Bootstrap
 ---
 
-To bootstrap clang/LLVM with ThinLTO, follow these steps:
+To `bootstrap clang/LLVM 
`_
+with ThinLTO, follow these steps:
 
 1. The host compiler_ must be a version of clang that supports ThinLTO.
 #. The host linker_ must support ThinLTO (and in the case of gold, must be
@@ -225,7 +226,7 @@ To bootstrap clang/LLVM with ThinLTO, follow these steps:
``CMAKE_EXE_LINKER_FLAGS:STRING=``. Note the configure may fail if
linker plugin options are instead specified directly in the previous step.
 
-The `BOOTSTRAP_LLVM_ENABLE_LTO=Thin`` will enable ThinLTO for stage 2 and
+The ``BOOTSTRAP_LLVM_ENABLE_LTO=Thin`` will enable ThinLTO for stage 2 and
 stage 3 in case the compiler used for stage 1 does not support the ThinLTO
 option.
 

diff  --git a/llvm/docs/UserGuides.rst b/llvm/docs/UserGuides.rst
index 0b91b3cbe66d..6e4329128fab 100644
--- a/llvm/docs/UserGuides.rst
+++ b/llvm/docs/UserGuides.rst
@@ -96,7 +96,10 @@ LLVM Builds and Distributions
 
 :doc:`Support Library `
This document describes the LLVM Support Library (``lib/Support``) and
-   how to keep LLVM source code portable
+   how to keep LLVM source code portable.
+
+:doc:`AdvancedBuilds`
+   This document describes more advanced build configurations.
 
 Optimizations
 -



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


[clang] d8e0ad9 - [clang][test] fix tests for external assemblers

2020-05-25 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2020-05-25T22:14:05-07:00
New Revision: d8e0ad9620c6e626d753a3ae0da6c712e4d400d3

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

LOG: [clang][test] fix tests for external assemblers

The test depends on using the integrated assembler. Make it
explicit by specifying -fintegrated-as.

Added: 


Modified: 
clang/test/Driver/modules-ts.cpp

Removed: 




diff  --git a/clang/test/Driver/modules-ts.cpp 
b/clang/test/Driver/modules-ts.cpp
index 3847b71f7b74..80eef081371f 100644
--- a/clang/test/Driver/modules-ts.cpp
+++ b/clang/test/Driver/modules-ts.cpp
@@ -9,7 +9,7 @@
 
 // Check compiling a .pcm file to a .o file.
 //
-// RUN: %clang -fmodules-ts %t.pcm -c -o %t.pcm.o -v 2>&1 | FileCheck %s 
--check-prefix=CHECK-COMPILE
+// RUN: %clang -fmodules-ts -fintegrated-as %t.pcm -c -o %t.pcm.o -v 2>&1 | 
FileCheck %s --check-prefix=CHECK-COMPILE
 //
 // CHECK-COMPILE: -cc1 {{.*}} -emit-obj
 // CHECK-COMPILE-SAME: -o {{.*}}.pcm.o
@@ -18,7 +18,7 @@
 
 // Check use of a .pcm file in another compilation.
 //
-// RUN: %clang -fmodules-ts -fmodule-file=%t.pcm -Dexport= %s -c -o %t.o -v 
2>&1 | FileCheck %s --check-prefix=CHECK-USE
+// RUN: %clang -fmodules-ts -fmodule-file=%t.pcm -fintegrated-as -Dexport= %s 
-c -o %t.o -v 2>&1 | FileCheck %s --check-prefix=CHECK-USE
 //
 // CHECK-USE: -cc1
 // CHECK-USE-SAME: -emit-obj
@@ -28,7 +28,7 @@
 
 // Check combining precompile and compile steps works.
 //
-// RUN: %clang -fmodules-ts -x c++-module %s -c -o %t.pcm.o -v 2>&1 | 
FileCheck %s --check-prefix=CHECK-PRECOMPILE --check-prefix=CHECK-COMPILE
+// RUN: %clang -fmodules-ts -fintegrated-as -x c++-module %s -c -o %t.pcm.o -v 
2>&1 | FileCheck %s --check-prefix=CHECK-PRECOMPILE --check-prefix=CHECK-COMPILE
 
 // Check that .cppm is treated as a module implicitly.
 // RUN: cp %s %t.cppm



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


[clang] 9a8d7bd - [clang][test] fix tests for external assemblers

2020-05-25 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2020-05-25T17:36:28-07:00
New Revision: 9a8d7bd77040a6497233ea10fd866ad9de8bf98c

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

LOG: [clang][test] fix tests for external assemblers

These three tests depend on using the integrated assembler. Make it
explicit by specifying -fintegrated-as.

Added: 


Modified: 
clang/test/Driver/debug-prefix-map.S
clang/test/Driver/flang/flang.f90
clang/test/Driver/flang/flang_ucase.F90

Removed: 




diff  --git a/clang/test/Driver/debug-prefix-map.S 
b/clang/test/Driver/debug-prefix-map.S
index 7d12a1747972..6dd1ded9bfdf 100644
--- a/clang/test/Driver/debug-prefix-map.S
+++ b/clang/test/Driver/debug-prefix-map.S
@@ -1,5 +1,5 @@
-// RUN: %clang -### -g -fdebug-prefix-map=old=new %s 2>&1 | FileCheck %s
-// RUN: %clang -### -g -ffile-prefix-map=old=new %s 2>&1 | FileCheck %s
+// RUN: %clang -### -g -fintegrated-as -fdebug-prefix-map=old=new %s 2>&1 | 
FileCheck %s
+// RUN: %clang -### -g -fintegrated-as -ffile-prefix-map=old=new %s 2>&1 | 
FileCheck %s
 
 // CHECK: cc1as
 // CHECK-SAME: -fdebug-prefix-map=old=new

diff  --git a/clang/test/Driver/flang/flang.f90 
b/clang/test/Driver/flang/flang.f90
index 9d47c7c90225..a68be31343f9 100644
--- a/clang/test/Driver/flang/flang.f90
+++ b/clang/test/Driver/flang/flang.f90
@@ -43,7 +43,7 @@
 ! CHECK-S-DAG: "-S"
 ! CHECK-S-DAG: "-o" "{{[^"]*}}.s"
 
-! RUN: %clang --driver-mode=flang -### %s 2>&1 | FileCheck 
--check-prefixes=ALL,CHECK-EMIT-OBJ %s
+! RUN: %clang --driver-mode=flang -### -fintegrated-as %s 2>&1 | FileCheck 
--check-prefixes=ALL,CHECK-EMIT-OBJ %s
 ! CHECK-EMIT-OBJ-DAG: "-emit-obj"
 ! CHECK-EMIT-OBJ-DAG: "-o" "{{[^"]*}}.o"
 

diff  --git a/clang/test/Driver/flang/flang_ucase.F90 
b/clang/test/Driver/flang/flang_ucase.F90
index 323afb21dccf..dd1e20088191 100644
--- a/clang/test/Driver/flang/flang_ucase.F90
+++ b/clang/test/Driver/flang/flang_ucase.F90
@@ -43,7 +43,7 @@
 ! CHECK-S-DAG: "-S"
 ! CHECK-S-DAG: "-o" "{{[^"]*}}.s"
 
-! RUN: %clang --driver-mode=flang -### %s 2>&1 | FileCheck 
--check-prefixes=ALL,CHECK-EMIT-OBJ %s
+! RUN: %clang --driver-mode=flang -### -fintegrated-as %s 2>&1 | FileCheck 
--check-prefixes=ALL,CHECK-EMIT-OBJ %s
 ! CHECK-EMIT-OBJ-DAG: "-emit-obj"
 ! CHECK-EMIT-OBJ-DAG: "-o" "{{[^"]*}}.o"
 



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


[clang] 3a2df3b - [Clang][test] fix tests when using external assembler.

2020-05-25 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2020-05-25T16:47:50-07:00
New Revision: 3a2df3bad07f7e5fc22538ad782e08ee55f29e41

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

LOG: [Clang][test] fix tests when using external assembler.

Summary:
The test assume using integraed-as, so make it explicit.

Reviewered by: aganea

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

Added: 


Modified: 
clang/test/Driver/cc1-spawnprocess.c

Removed: 




diff  --git a/clang/test/Driver/cc1-spawnprocess.c 
b/clang/test/Driver/cc1-spawnprocess.c
index 8af8cc4c0555..36df7067487c 100644
--- a/clang/test/Driver/cc1-spawnprocess.c
+++ b/clang/test/Driver/cc1-spawnprocess.c
@@ -1,18 +1,23 @@
-// RUN: %clang -fintegrated-cc1 -c -### %s 2>&1 | FileCheck %s 
--check-prefix=YES
+// If a toolchain uses an external assembler, the test would fail because using
+// an external assember would increase job counts. Most toolchains in tree
+// use integrated assembler, but we still support external assembler.
+// So -fintegrated-as is specified explicitly when applicable.
+
+// RUN: %clang -fintegrated-cc1 -fintegrated-as -c -### %s 2>&1 | FileCheck %s 
--check-prefix=YES
 // RUN: %clang -fno-integrated-cc1 -c -### %s 2>&1 | FileCheck %s 
--check-prefix=NO
 
 // RUN: %clang -fintegrated-cc1 -fno-integrated-cc1 -c -### %s 2>&1 \
 // RUN: | FileCheck %s --check-prefix=NO
-// RUN: %clang -fno-integrated-cc1 -fintegrated-cc1 -c -### %s 2>&1 \
+// RUN: %clang -fno-integrated-cc1 -fintegrated-cc1 -fintegrated-as -c -### %s 
2>&1 \
 // RUN: | FileCheck %s --check-prefix=YES
 
-// RUN: %clang_cl -fintegrated-cc1 -c -### -- %s 2>&1 \
+// RUN: %clang_cl -fintegrated-cc1 -fintegrated-as -c -### -- %s 2>&1 \
 // RUN: | FileCheck %s --check-prefix=YES
 // RUN: %clang_cl -fno-integrated-cc1 -c -### -- %s 2>&1 \
 // RUN: | FileCheck %s --check-prefix=NO
 
 // RUN: env CCC_OVERRIDE_OPTIONS=+-fintegrated-cc1 \
-// RUN: %clang -fintegrated-cc1 -c -### %s 2>&1 \
+// RUN: %clang -fintegrated-cc1 -fintegrated-as -c -### %s 2>&1 \
 // RUN: | FileCheck %s --check-prefix=YES
 // RUN: env CCC_OVERRIDE_OPTIONS=+-fno-integrated-cc1 \
 // RUN: %clang -fintegrated-cc1 -c -### %s 2>&1 \
@@ -24,7 +29,7 @@
 // The following tests ensure that only one integrated-cc1 is executed.
 
 // Only one TU, one job, thus integrated-cc1 is enabled.
-// RUN: %clang -fintegrated-cc1 -c %s -### 2>&1 | FileCheck %s 
--check-prefix=YES
+// RUN: %clang -fintegrated-cc1 -fintegrated-as -c %s -### 2>&1 | FileCheck %s 
--check-prefix=YES
 
 // Only one TU, but we're linking, two jobs, thus integrated-cc1 is disabled.
 // RUN: %clang -fintegrated-cc1 %s -### 2>&1 | FileCheck %s --check-prefix=NO



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


[clang] ef7a154 - [clang][ThinLTO] Promote cc1 -fthin_link_bitcode to driver -fthinlto_link_bitcode

2019-10-24 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2019-10-24T16:54:45-07:00
New Revision: ef7a154d17f2e38ba3c8bfa33f240b60464e4cc7

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

LOG: [clang][ThinLTO] Promote cc1 -fthin_link_bitcode to driver 
-fthinlto_link_bitcode

Summary:
A necessary step to let build system caching work for its output.

Reviewers: tejohnson, steven_wu

Reviewed by: tejohnson

Subscribers: mehdi_amini, inglorion, dexonsmith, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Driver/CC1Options.td
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/CodeGen/thin_link_bitcode.c

Removed: 




diff  --git a/clang/include/clang/Driver/CC1Options.td 
b/clang/include/clang/Driver/CC1Options.td
index 4518aca82ef6..72019aa2a01a 100644
--- a/clang/include/clang/Driver/CC1Options.td
+++ b/clang/include/clang/Driver/CC1Options.td
@@ -387,8 +387,6 @@ def flto_visibility_public_std:
 def flto_unit: Flag<["-"], "flto-unit">,
 HelpText<"Emit IR to support LTO unit features (CFI, whole program vtable 
opt)">;
 def fno_lto_unit: Flag<["-"], "fno-lto-unit">;
-def fthin_link_bitcode_EQ : Joined<["-"], "fthin-link-bitcode=">,
-HelpText<"Write minimized bitcode to  for the ThinLTO thin link 
only">;
 def femit_debug_entry_values : Flag<["-"], "femit-debug-entry-values">,
 HelpText<"Enables debug info about call site parameter's entry values">;
 def fdebug_pass_manager : Flag<["-"], "fdebug-pass-manager">,

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 20d7c241a937..1c3d7f77707e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1312,6 +1312,9 @@ def flto_jobs_EQ : Joined<["-"], "flto-jobs=">,
 def fthinlto_index_EQ : Joined<["-"], "fthinlto-index=">,
   Flags<[CoreOption, CC1Option]>, Group,
   HelpText<"Perform ThinLTO importing using provided function summary index">;
+def fthin_link_bitcode_EQ : Joined<["-"], "fthin-link-bitcode=">,
+  Flags<[CoreOption, CC1Option]>, Group,
+  HelpText<"Write minimized bitcode to  for the ThinLTO thin link only">;
 def fmacro_backtrace_limit_EQ : Joined<["-"], "fmacro-backtrace-limit=">,
 Group, Flags<[DriverOption, 
CoreOption]>;
 def fmerge_all_constants : Flag<["-"], "fmerge-all-constants">, Group,

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 198b0b5b228f..70c70dcdbd4d 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3641,6 +3641,9 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
 Args.AddLastArg(CmdArgs, options::OPT_fthinlto_index_EQ);
   }
 
+  if (Args.getLastArg(options::OPT_fthin_link_bitcode_EQ))
+Args.AddLastArg(CmdArgs, options::OPT_fthin_link_bitcode_EQ);
+
   if (Args.getLastArg(options::OPT_save_temps_EQ))
 Args.AddLastArg(CmdArgs, options::OPT_save_temps_EQ);
 

diff  --git a/clang/test/CodeGen/thin_link_bitcode.c 
b/clang/test/CodeGen/thin_link_bitcode.c
index 52c5715ba561..052af9fd22c8 100644
--- a/clang/test/CodeGen/thin_link_bitcode.c
+++ b/clang/test/CodeGen/thin_link_bitcode.c
@@ -1,5 +1,7 @@
 // REQUIRES: x86-registered-target
 //
+// RUN: %clang -flto=thin -fthin-link-bitcode=%t.bc -target 
x86_64-unknown-linux-gnu -### %s 2>&1 | FileCheck %s --check-prefix=LINKBC
+//
 // RUN: %clang_cc1 -o %t -flto=thin -fthin-link-bitcode=%t.nodebug -triple 
x86_64-unknown-linux-gnu -emit-llvm-bc -debug-info-kind=limited %s
 // RUN: llvm-bcanalyzer -dump %t | FileCheck %s
 // RUN: llvm-bcanalyzer -dump %t.nodebug | FileCheck %s --check-prefix=NO_DEBUG
@@ -10,5 +12,7 @@ int main (void) {
   return 0;
 }
 
+// LINKBC: -fthin-link-bitcode=
+
 // CHECK: COMPILE_UNIT
 // NO_DEBUG-NOT: COMPILE_UNIT



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


r373792 - [clang] fix a typo from r372531

2019-10-04 Thread Yuanfang Chen via cfe-commits
Author: yuanfang
Date: Fri Oct  4 14:37:20 2019
New Revision: 373792

URL: http://llvm.org/viewvc/llvm-project?rev=373792=rev
Log:
[clang] fix a typo from r372531

Reviewers: xbolva00

Subscribers: cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/Sema/warn-integer-constants-in-ternary.c

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=373792=373791=373792=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri Oct  4 14:37:20 2019
@@ -11384,7 +11384,7 @@ static void DiagnoseIntInBoolContext(Sem
 (RHS->getValue() == 0 || RHS->getValue() == 1))
   // Do not diagnose common idioms.
   return;
-if (LHS->getValue() != 0 && LHS->getValue() != 0)
+if (LHS->getValue() != 0 && RHS->getValue() != 0)
   S.Diag(ExprLoc, diag::warn_integer_constants_in_conditional_always_true);
   }
 }

Modified: cfe/trunk/test/Sema/warn-integer-constants-in-ternary.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-integer-constants-in-ternary.c?rev=373792=373791=373792=diff
==
--- cfe/trunk/test/Sema/warn-integer-constants-in-ternary.c (original)
+++ cfe/trunk/test/Sema/warn-integer-constants-in-ternary.c Fri Oct  4 14:37:20 
2019
@@ -18,7 +18,7 @@ void test(boolean a) {
   boolean r;
   r = a ? (1) : TWO;
   r = a ? 3 : TWO; // expected-warning {{converting the result of '?:' with 
integer constants to a boolean always evaluates to 'true'}}
-  r = a ? -2 : 0;  // expected-warning {{converting the result of '?:' with 
integer constants to a boolean always evaluates to 'true'}}
+  r = a ? -2 : 0;
   r = a ? 3 : -2;  // expected-warning {{converting the result of '?:' with 
integer constants to a boolean always evaluates to 'true'}}
   r = a ? 0 : TWO;
   r = a ? 3 : ONE; // expected-warning {{converting the result of '?:' with 
integer constants to a boolean always evaluates to 'true'}}


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


r370981 - [DebugInfo] Emit DW_TAG_enumeration_type for referenced global enumerator.

2019-09-04 Thread Yuanfang Chen via cfe-commits
Author: yuanfang
Date: Wed Sep  4 13:58:15 2019
New Revision: 370981

URL: http://llvm.org/viewvc/llvm-project?rev=370981=rev
Log:
[DebugInfo] Emit DW_TAG_enumeration_type for referenced global enumerator.

This essentially reverts changes from r361400 while keeping behavior for
CodeView.

Reviewers: akhuang, rnk, probinson

Reviewed by: rnk

Subscribers: cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/test/CodeGen/enum2.c

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=370981=370980=370981=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Wed Sep  4 13:58:15 2019
@@ -4438,19 +4438,27 @@ void CGDebugInfo::EmitGlobalVariable(con
   StringRef Name = VD->getName();
   llvm::DIType *Ty = getOrCreateType(VD->getType(), Unit);
 
-  // Do not use global variables for enums, unless in CodeView.
   if (const auto *ECD = dyn_cast(VD)) {
 const auto *ED = cast(ECD->getDeclContext());
 assert(isa(ED->getTypeForDecl()) && "Enum without EnumType?");
-(void)ED;
 
-// If CodeView, emit enums as global variables, unless they are defined
-// inside a class. We do this because MSVC doesn't emit S_CONSTANTs for
-// enums in classes, and because it is difficult to attach this scope
-// information to the global variable.
-if (!CGM.getCodeGenOpts().EmitCodeView ||
-isa(ED->getDeclContext()))
+if (CGM.getCodeGenOpts().EmitCodeView) {
+  // If CodeView, emit enums as global variables, unless they are defined
+  // inside a class. We do this because MSVC doesn't emit S_CONSTANTs for
+  // enums in classes, and because it is difficult to attach this scope
+  // information to the global variable.
+  if (isa(ED->getDeclContext()))
+return;
+} else {
+  // If not CodeView, emit DW_TAG_enumeration_type if necessary. For
+  // example: for "enum { ZERO };", a DW_TAG_enumeration_type is created 
the
+  // first time `ZERO` is referenced in a function.
+  llvm::DIType *EDTy =
+  getOrCreateType(QualType(ED->getTypeForDecl(), 0), Unit);
+  assert (EDTy->getTag() == llvm::dwarf::DW_TAG_enumeration_type);
+  (void)EDTy;
   return;
+}
   }
 
   llvm::DIScope *DContext = nullptr;

Modified: cfe/trunk/test/CodeGen/enum2.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/enum2.c?rev=370981=370980=370981=diff
==
--- cfe/trunk/test/CodeGen/enum2.c (original)
+++ cfe/trunk/test/CodeGen/enum2.c Wed Sep  4 13:58:15 2019
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -triple i386-unknown-unknown %s -debug-info-kind=limited 
-emit-llvm -o /dev/null
+// RUN: %clang_cc1 -triple i386-unknown-unknown %s -debug-info-kind=limited 
-emit-llvm -o - | FileCheck %s
+
 int v;
 enum e { MAX };
 
@@ -6,3 +7,9 @@ void foo (void)
 {
   v = MAX;
 }
+// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type,
+// CHECK-SAME: baseType: ![[LONG:[0-9]+]]
+// CHECK-SAME: elements: ![[ELTS:[0-9]+]]
+// CHECK: ![[LONG]] = !DIBasicType(name: "unsigned int", size: 32, encoding: 
DW_ATE_unsigned)
+// CHECK: ![[ELTS]] = !{![[MAX:[0-9]+]]}
+// CHECK: ![[MAX]] = !DIEnumerator(name: "MAX", value: 0, isUnsigned: true)


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


  1   2   >