[llvm-branch-commits] [clang] [Serialization] Code cleanups and polish 83233 (PR #83237)

2024-09-06 Thread Richard Smith via llvm-branch-commits

zygoloid wrote:

> what the code does is: when we write a on-disk hash table, try to write the 
> imported merged hash table in the same process so that we don't need to read 
> these tables again. However, in line 329 the function will try to omit the 
> data from imported table with the same key which already emitted by the 
> current module file. This is the root cause of the problem.

It's been a while since I looked at this, but as I recall, a fundamental 
assumption of MultiObDiskHashTable is that if we have a lookup result for a key 
K in the current file, that result supersedes any results from dependency 
files. So lookup won't look in those files if we have a local result (they are 
overridden) and merging doesn't take results from those files either.

So I think the problem probably is that when we form a local result, we need to 
(but presumably don't) add all the imported results with the same key to the 
local result.

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


[llvm-branch-commits] [clang] ea99c88 - Permit __VA_OPT__ in all language modes and allow it to be detected with #ifdef.

2021-01-27 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2021-01-27T15:52:31-08:00
New Revision: ea99c885a63de9af673a5e5cd51f44fb70c83c1b

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

LOG: Permit __VA_OPT__ in all language modes and allow it to be detected with 
#ifdef.

These changes are intended to give code a path to move away from the GNU
,##__VA_ARGS__ extension, which is non-conforming in some situations and
which we'd like to disable in our conforming mode in those cases.

(cherry picked from commit 0436ec2128c9775ba13b0308937238fc79673fdd)

Added: 


Modified: 
clang/include/clang/Lex/Preprocessor.h
clang/include/clang/Lex/VariadicMacroSupport.h
clang/lib/Lex/PPDirectives.cpp
clang/lib/Lex/PPExpressions.cpp
clang/lib/Lex/PPMacroExpansion.cpp
clang/lib/Lex/Preprocessor.cpp
clang/test/Preprocessor/macro_vaopt_check.cpp
clang/test/Preprocessor/macro_vaopt_expand.cpp

Removed: 




diff  --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index 68139cb24b31..ba8bdaa23c4c 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -447,6 +447,25 @@ class Preprocessor {
   ElseLoc(ElseLoc) {}
   };
 
+  class IfdefMacroNameScopeRAII {
+Preprocessor &PP;
+bool VAOPTWasPoisoned;
+
+  public:
+IfdefMacroNameScopeRAII(Preprocessor &PP)
+: PP(PP), VAOPTWasPoisoned(PP.Ident__VA_OPT__->isPoisoned()) {
+  PP.Ident__VA_OPT__->setIsPoisoned(false);
+}
+IfdefMacroNameScopeRAII(const IfdefMacroNameScopeRAII&) = delete;
+IfdefMacroNameScopeRAII &operator=(const IfdefMacroNameScopeRAII&) = 
delete;
+~IfdefMacroNameScopeRAII() { Exit(); }
+
+void Exit() {
+  if (VAOPTWasPoisoned)
+PP.Ident__VA_OPT__->setIsPoisoned(true);
+}
+  };
+
 private:
   friend class ASTReader;
   friend class MacroArgs;

diff  --git a/clang/include/clang/Lex/VariadicMacroSupport.h 
b/clang/include/clang/Lex/VariadicMacroSupport.h
index 989e0ac703c9..119f02201fc6 100644
--- a/clang/include/clang/Lex/VariadicMacroSupport.h
+++ b/clang/include/clang/Lex/VariadicMacroSupport.h
@@ -39,17 +39,14 @@ namespace clang {
   assert(Ident__VA_ARGS__->isPoisoned() && "__VA_ARGS__ should be poisoned 
"
   "outside an ISO C/C++ variadic "
   "macro definition!");
-  assert(
-  !Ident__VA_OPT__ ||
-  (Ident__VA_OPT__->isPoisoned() && "__VA_OPT__ should be poisoned!"));
+  assert(Ident__VA_OPT__->isPoisoned() && "__VA_OPT__ should be 
poisoned!");
 }
 
 /// Client code should call this function just before the Preprocessor is
 /// about to Lex tokens from the definition of a variadic (ISO C/C++) 
macro.
 void enterScope() {
   Ident__VA_ARGS__->setIsPoisoned(false);
-  if (Ident__VA_OPT__)
-Ident__VA_OPT__->setIsPoisoned(false);
+  Ident__VA_OPT__->setIsPoisoned(false);
 }
 
 /// Client code should call this function as soon as the Preprocessor has
@@ -58,8 +55,7 @@ namespace clang {
 /// (might be explicitly called, and then reinvoked via the destructor).
 void exitScope() {
   Ident__VA_ARGS__->setIsPoisoned(true);
-  if (Ident__VA_OPT__)
-Ident__VA_OPT__->setIsPoisoned(true);
+  Ident__VA_OPT__->setIsPoisoned(true);
 }
 
 ~VariadicMacroScopeGuard() { exitScope(); }

diff  --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index d6b03d85913d..e2aa93455ea5 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -2928,9 +2928,14 @@ void Preprocessor::HandleIfdefDirective(Token &Result,
   ++NumIf;
   Token DirectiveTok = Result;
 
+  // __VA_OPT__ is allowed as the operand of #if[n]def.
+  IfdefMacroNameScopeRAII IfdefMacroNameScope(*this);
+
   Token MacroNameTok;
   ReadMacroName(MacroNameTok);
 
+  IfdefMacroNameScope.Exit();
+
   // Error reading macro name?  If so, diagnostic already issued.
   if (MacroNameTok.is(tok::eod)) {
 // Skip code until we get to #endif.  This helps with recovery by not

diff  --git a/clang/lib/Lex/PPExpressions.cpp b/clang/lib/Lex/PPExpressions.cpp
index 8c120c13d7d2..952fb8f121dc 100644
--- a/clang/lib/Lex/PPExpressions.cpp
+++ b/clang/lib/Lex/PPExpressions.cpp
@@ -104,6 +104,9 @@ static bool EvaluateDefined(PPValue &Result, Token 
&PeekTok, DefinedTracker &DT,
   SourceLocation beginLoc(PeekTok.getLocation());
   Result.setBegin(beginLoc);
 
+  // __VA_OPT__ is allowed as the operand of 'defined'.
+  Preprocessor::IfdefMacroNameScopeRAII IfdefMacroNameScope(PP);
+
   // Get the next token, don't expand it.
   PP.LexUnexpandedNonComment(PeekTok);
 
@@ -122,6 +125,8 @@ static bool EvaluateDefined(PPValue &Result

[llvm-branch-commits] [clang] 9ea2a10 - Don't allow __VA_OPT__ to be detected by #ifdef.

2021-01-27 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2021-01-27T15:52:31-08:00
New Revision: 9ea2a107ca4055a3a4960cb6dffb84b7f43bd8ea

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

LOG: Don't allow __VA_OPT__ to be detected by #ifdef.

More study has discovered this to not actually be useful: because
current C++20 implementations reject `#ifdef __VA_OPT__`, this can't
really be used as a feature-test mechanism. And it's not too hard to
detect __VA_OPT__ without this, for example:

  #define THIRD_ARG(a, b, c, ...) c
  #define HAS_VA_OPT(...) THIRD_ARG(__VA_OPT__(,), 1, 0, )
  #if HAS_VA_OPT(?)

Partially reverts 0436ec2128c9775ba13b0308937238fc79673fdd.

(cherry picked from commit 5dfa37a76153f2a18ac7fe30721cc1332b672ea2)

Added: 


Modified: 
clang/include/clang/Lex/Preprocessor.h
clang/lib/Lex/PPDirectives.cpp
clang/lib/Lex/PPExpressions.cpp
clang/lib/Lex/PPMacroExpansion.cpp
clang/lib/Lex/Preprocessor.cpp
clang/test/Preprocessor/macro_vaopt_check.cpp

Removed: 




diff  --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index ba8bdaa23c4c..68139cb24b31 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -447,25 +447,6 @@ class Preprocessor {
   ElseLoc(ElseLoc) {}
   };
 
-  class IfdefMacroNameScopeRAII {
-Preprocessor &PP;
-bool VAOPTWasPoisoned;
-
-  public:
-IfdefMacroNameScopeRAII(Preprocessor &PP)
-: PP(PP), VAOPTWasPoisoned(PP.Ident__VA_OPT__->isPoisoned()) {
-  PP.Ident__VA_OPT__->setIsPoisoned(false);
-}
-IfdefMacroNameScopeRAII(const IfdefMacroNameScopeRAII&) = delete;
-IfdefMacroNameScopeRAII &operator=(const IfdefMacroNameScopeRAII&) = 
delete;
-~IfdefMacroNameScopeRAII() { Exit(); }
-
-void Exit() {
-  if (VAOPTWasPoisoned)
-PP.Ident__VA_OPT__->setIsPoisoned(true);
-}
-  };
-
 private:
   friend class ASTReader;
   friend class MacroArgs;

diff  --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index e2aa93455ea5..d6b03d85913d 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -2928,14 +2928,9 @@ void Preprocessor::HandleIfdefDirective(Token &Result,
   ++NumIf;
   Token DirectiveTok = Result;
 
-  // __VA_OPT__ is allowed as the operand of #if[n]def.
-  IfdefMacroNameScopeRAII IfdefMacroNameScope(*this);
-
   Token MacroNameTok;
   ReadMacroName(MacroNameTok);
 
-  IfdefMacroNameScope.Exit();
-
   // Error reading macro name?  If so, diagnostic already issued.
   if (MacroNameTok.is(tok::eod)) {
 // Skip code until we get to #endif.  This helps with recovery by not

diff  --git a/clang/lib/Lex/PPExpressions.cpp b/clang/lib/Lex/PPExpressions.cpp
index 952fb8f121dc..8c120c13d7d2 100644
--- a/clang/lib/Lex/PPExpressions.cpp
+++ b/clang/lib/Lex/PPExpressions.cpp
@@ -104,9 +104,6 @@ static bool EvaluateDefined(PPValue &Result, Token 
&PeekTok, DefinedTracker &DT,
   SourceLocation beginLoc(PeekTok.getLocation());
   Result.setBegin(beginLoc);
 
-  // __VA_OPT__ is allowed as the operand of 'defined'.
-  Preprocessor::IfdefMacroNameScopeRAII IfdefMacroNameScope(PP);
-
   // Get the next token, don't expand it.
   PP.LexUnexpandedNonComment(PeekTok);
 
@@ -125,8 +122,6 @@ static bool EvaluateDefined(PPValue &Result, Token 
&PeekTok, DefinedTracker &DT,
 PP.LexUnexpandedNonComment(PeekTok);
   }
 
-  IfdefMacroNameScope.Exit();
-
   // If we don't have a pp-identifier now, this is an error.
   if (PP.CheckMacroName(PeekTok, MU_Other))
 return true;

diff  --git a/clang/lib/Lex/PPMacroExpansion.cpp 
b/clang/lib/Lex/PPMacroExpansion.cpp
index f6ca04defeb9..43d31d6c5732 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/clang/lib/Lex/PPMacroExpansion.cpp
@@ -323,16 +323,13 @@ void Preprocessor::dumpMacroInfo(const IdentifierInfo 
*II) {
 
 /// RegisterBuiltinMacro - Register the specified identifier in the identifier
 /// table and mark it as a builtin macro to be expanded.
-static IdentifierInfo *RegisterBuiltinMacro(Preprocessor &PP, const char *Name,
-bool Disabled = false) {
+static IdentifierInfo *RegisterBuiltinMacro(Preprocessor &PP, const char 
*Name){
   // Get the identifier.
   IdentifierInfo *Id = PP.getIdentifierInfo(Name);
 
   // Mark it as being a macro that is builtin.
   MacroInfo *MI = PP.AllocateMacroInfo(SourceLocation());
   MI->setIsBuiltinMacro();
-  if (Disabled)
-MI->DisableMacro();
   PP.appendDefMacroDirective(Id, MI);
   return Id;
 }
@@ -346,7 +343,6 @@ void Preprocessor::RegisterBuiltinMacros() {
   Ident__TIME__ = RegisterBuiltinMacro(*this, "__TIME__");
   Ident__COUNTER__ = RegisterBuiltinMacro(*this, "__COUNTER__");
   Ident_Pragma  = RegisterBuiltinMacro(*this, "_Pragma"

[llvm-branch-commits] [clang] 9df2b64 - [cxx_status] Mark P0732R2 as only 'partial', not 'Clang 12', as some of

2021-01-27 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2021-01-27T16:09:10-08:00
New Revision: 9df2b64fc5fa911ca59b3f646806ca3fd6787c2d

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

LOG: [cxx_status] Mark P0732R2 as only 'partial', not 'Clang 12', as some of
the changes were reverted.

(cherry picked from commit 727fc31a9898dfb89610ca1bc05ff86204a77177)

Added: 


Modified: 
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index 685f32dbe0d3..fc3340ec9d96 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -1005,7 +1005,7 @@ C++20 implementation status
 
   Class types as non-type template parameters
   https://wg21.link/p0732r2";>P0732R2
-  Clang 12
+  Partial
 

 https://wg21.link/p1907r1";>P1907R1



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


[llvm-branch-commits] [clang] 678c259 - PR44325 (and duplicates): don't issue -Wzero-as-null-pointer-constant

2021-02-03 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2021-02-03T14:59:48-08:00
New Revision: 678c259d277135ef32861887a8ac8618deba5f24

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

LOG: PR44325 (and duplicates): don't issue -Wzero-as-null-pointer-constant
when rewriting 'a < b' as '(a <=> b) < 0'.

It's pretty common for comparison category types to use a pointer or
pointer-to-member type as their '0' parameter.

(cherry picked from commit 1f06f41993b6363e6b2c4f22a13488a3e687f31b)

Added: 


Modified: 
clang/lib/Sema/Sema.cpp
clang/test/SemaCXX/cxx2a-three-way-comparison.cpp

Removed: 




diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 55cb3aee6194..cb5a84a31235 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -537,6 +537,13 @@ void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, 
const Expr* E) {
   if (E->IgnoreParenImpCasts()->getType()->isNullPtrType())
 return;
 
+  // Don't diagnose the conversion from a 0 literal to a null pointer argument
+  // in a synthesized call to operator<=>.
+  if (!CodeSynthesisContexts.empty() &&
+  CodeSynthesisContexts.back().Kind ==
+  CodeSynthesisContext::RewritingOperatorAsSpaceship)
+return;
+
   // If it is a macro from system header, and if the macro name is not "NULL",
   // do not warn.
   SourceLocation MaybeMacroLoc = E->getBeginLoc();

diff  --git a/clang/test/SemaCXX/cxx2a-three-way-comparison.cpp 
b/clang/test/SemaCXX/cxx2a-three-way-comparison.cpp
index 353360e052bb..b94225274fff 100644
--- a/clang/test/SemaCXX/cxx2a-three-way-comparison.cpp
+++ b/clang/test/SemaCXX/cxx2a-three-way-comparison.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++2a -verify %s
+// RUN: %clang_cc1 -std=c++2a -verify %s -Wzero-as-null-pointer-constant
 
 // Keep this test before any declarations of operator<=>.
 namespace PR44786 {
@@ -40,3 +40,21 @@ namespace PR47893 {
   int &f(...);
   int &r = f(A(), A());
 }
+
+namespace PR44325 {
+  struct cmp_cat {};
+  bool operator<(cmp_cat, void*);
+  bool operator>(cmp_cat, int cmp_cat::*);
+
+  struct X {};
+  cmp_cat operator<=>(X, X);
+
+  bool b1 = X() < X(); // no warning
+  bool b2 = X() > X(); // no warning
+
+  // FIXME: It's not clear whether warning here is useful, but we can't really
+  // tell that this is a comparison category in general. This is probably OK,
+  // as comparisons against zero are only really intended for use in the
+  // implicit rewrite rules, not for explicit use by programs.
+  bool c = cmp_cat() < 0; // expected-warning {{zero as null pointer constant}}
+}



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


[llvm-branch-commits] [clang] c9fb4a9 - [AST] Update LVal before evaluating lambda decl fields.

2021-02-08 Thread Richard Smith via llvm-branch-commits

Author: Zequan Wu
Date: 2021-02-08T15:31:53-08:00
New Revision: c9fb4a947e32abfaa73b0b91a58ef71c73316322

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

LOG: [AST] Update LVal before evaluating lambda decl fields.

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

(cherry picked from commit 96fb49c3ff8e08680127ddd4ec45a0e6c199243b)

Added: 


Modified: 
clang/lib/AST/ExprConstant.cpp
clang/test/SemaCXX/constant-expression-cxx2a.cpp

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 56181bbe1166..1c4caa2c1fc0 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -10009,6 +10009,7 @@ bool RecordExprEvaluator::VisitLambdaExpr(const 
LambdaExpr *E) {
   auto *CaptureInitIt = E->capture_init_begin();
   const LambdaCapture *CaptureIt = ClosureClass->captures_begin();
   bool Success = true;
+  const ASTRecordLayout &Layout = Info.Ctx.getASTRecordLayout(ClosureClass);
   for (const auto *Field : ClosureClass->fields()) {
 assert(CaptureInitIt != E->capture_init_end());
 // Get the initializer for this field
@@ -10019,8 +10020,13 @@ bool RecordExprEvaluator::VisitLambdaExpr(const 
LambdaExpr *E) {
 if (!CurFieldInit)
   return Error(E);
 
+LValue Subobject = This;
+
+if (!HandleLValueMember(Info, E, Subobject, Field, &Layout))
+  return false;
+
 APValue &FieldVal = Result.getStructField(Field->getFieldIndex());
-if (!EvaluateInPlace(FieldVal, Info, This, CurFieldInit)) {
+if (!EvaluateInPlace(FieldVal, Info, Subobject, CurFieldInit)) {
   if (!Info.keepEvaluatingAfterFailure())
 return false;
   Success = false;

diff  --git a/clang/test/SemaCXX/constant-expression-cxx2a.cpp 
b/clang/test/SemaCXX/constant-expression-cxx2a.cpp
index 4adadc9988ab..86020a09db44 100644
--- a/clang/test/SemaCXX/constant-expression-cxx2a.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx2a.cpp
@@ -1437,3 +1437,13 @@ constexpr bool destroy_at_test() {
   return true;
 }
 static_assert(destroy_at_test());
+
+namespace PR48582 {
+  struct S {
+void *p = this;
+constexpr S() {}
+constexpr S(const S&) {}
+  };
+  constexpr bool b = [a = S(), b = S()] { return a.p == b.p; }();
+  static_assert(!b);
+}



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


[llvm-branch-commits] [clang] 8153dee - PR48606: The lifetime of a constexpr heap allocation always started

2021-02-08 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2021-02-08T18:03:10-08:00
New Revision: 8153dee37272a73b1ed74ac1bc12422fac8ef033

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

LOG: PR48606: The lifetime of a constexpr heap allocation always started
during the same evaluation.

It looks like the only case for which this matters is determining
whether mutable subobjects of a heap allocation can be modified during
constant evaluation.

(cherry picked from commit 21e8bb83253e1a2f4b6fad9b53cafe8c530a38e2)

Added: 


Modified: 
clang/lib/AST/ExprConstant.cpp
clang/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 1c4caa2c1fc0..cd2b5141ebe8 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -3497,8 +3497,8 @@ static bool diagnoseMutableFields(EvalInfo &Info, const 
Expr *E, AccessKinds AK,
 static bool lifetimeStartedInEvaluation(EvalInfo &Info,
 APValue::LValueBase Base,
 bool MutableSubobject = false) {
-  // A temporary we created.
-  if (Base.getCallIndex())
+  // A temporary or transient heap allocation we created.
+  if (Base.getCallIndex() || Base.is())
 return true;
 
   switch (Info.IsEvaluatingDecl) {

diff  --git a/clang/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp 
b/clang/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp
index 3647526ff0af..097ca00640e9 100644
--- a/clang/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp
+++ b/clang/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp
@@ -176,3 +176,37 @@ constexpr bool construct_after_lifetime_2() {
   return true;
 }
 static_assert(construct_after_lifetime_2()); // expected-error {{}} 
expected-note {{in call}}
+
+namespace PR48606 {
+  struct A { mutable int n = 0; };
+
+  constexpr bool f() {
+A a;
+A *p = &a;
+p->~A();
+std::construct_at(p);
+return true;
+  }
+  static_assert(f());
+
+  constexpr bool g() {
+A *p = new A;
+p->~A();
+std::construct_at(p);
+delete p;
+return true;
+  }
+  static_assert(g());
+
+  constexpr bool h() {
+std::allocator alloc;
+A *p = alloc.allocate(1);
+std::construct_at(p);
+p->~A();
+std::construct_at(p);
+p->~A();
+alloc.deallocate(p);
+return true;
+  }
+  static_assert(h());
+}



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


[llvm-branch-commits] [cfe-branch] r312187 - Add a couple of release note updates for C++ changes since Clang 4.

2017-08-30 Thread Richard Smith via llvm-branch-commits
Author: rsmith
Date: Wed Aug 30 15:58:37 2017
New Revision: 312187

URL: http://llvm.org/viewvc/llvm-project?rev=312187&view=rev
Log:
Add a couple of release note updates for C++ changes since Clang 4.

Modified:
cfe/branches/release_50/docs/ReleaseNotes.rst

Modified: cfe/branches/release_50/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/branches/release_50/docs/ReleaseNotes.rst?rev=312187&r1=312186&r2=312187&view=diff
==
--- cfe/branches/release_50/docs/ReleaseNotes.rst (original)
+++ cfe/branches/release_50/docs/ReleaseNotes.rst Wed Aug 30 15:58:37 2017
@@ -149,10 +149,23 @@ assignment operators where applicable.
 C++ Language Changes in Clang
 -
 
+- Support for the C++17 standard has been completed. This mode can be enabled
+  using ``-std=c++17`` (the old flag ``-std=c++1z`` is still supported for
+  compatibility).
+
+- When targeting a platform that uses the Itanium C++ ABI, Clang implements a
+  `recent change to the ABI`__ that passes objects of class type indirectly if 
they
+  have a non-trivial move constructor. Previous versions of Clang only
+  considered the copy constructor, resulting in an ABI change in rare cases,
+  but GCC has already implemented this change for several releases.
+  This affects all targets other than Windows and PS4. You can opt out of this
+  ABI change with ``-fclang-abi-compat=4.0``.
+
 - As mentioned in `C Language Changes in Clang`_, Clang's support for
   implicit scalar to vector conversions also applies to C++. Additionally
   the following operators are also supported: ``&&`` and ``||``.
 
+.. __: 
https://github.com/itanium-cxx-abi/cxx-abi/commit/7099637aba11fed6bdad7ee65bf4fd3f97fbf076
 
 Objective-C Language Changes in Clang
 -


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


[llvm-branch-commits] [cfe-branch] r312189 - Consistently use code font for command-line flags in the release notes.

2017-08-30 Thread Richard Smith via llvm-branch-commits
Author: rsmith
Date: Wed Aug 30 16:03:58 2017
New Revision: 312189

URL: http://llvm.org/viewvc/llvm-project?rev=312189&view=rev
Log:
Consistently use code font for command-line flags in the release notes.

Modified:
cfe/branches/release_50/docs/ReleaseNotes.rst

Modified: cfe/branches/release_50/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/branches/release_50/docs/ReleaseNotes.rst?rev=312189&r1=312188&r2=312189&view=diff
==
--- cfe/branches/release_50/docs/ReleaseNotes.rst (original)
+++ cfe/branches/release_50/docs/ReleaseNotes.rst Wed Aug 30 16:03:58 2017
@@ -47,25 +47,25 @@ coroutine support. Here is `an example
 Improvements to Clang's diagnostics
 ^^^
 
--  -Wcast-qual was implemented for C++. C-style casts are now properly
+-  ``-Wcast-qual`` was implemented for C++. C-style casts are now properly
diagnosed.
 
--  -Wunused-lambda-capture warns when a variable explicitly captured
+-  ``-Wunused-lambda-capture`` warns when a variable explicitly captured
by a lambda is not used in the body of the lambda.
 
--  -Wstrict-prototypes is a new warning that warns about non-prototype
+-  ``-Wstrict-prototypes`` is a new warning that warns about non-prototype
function and block declarations and types in C and Objective-C.
 
--  -Wunguarded-availability is a new warning that warns about uses of new
+-  ``-Wunguarded-availability`` is a new warning that warns about uses of new
APIs that were introduced in a system whose version is newer than the
deployment target version. A new Objective-C expression ``@available`` has
been introduced to perform system version checking at runtime. This warning
is off by default to prevent unexpected warnings in existing projects.
-   However, its less strict sibling -Wunguarded-availability-new is on by
+   However, its less strict sibling ``-Wunguarded-availability-new`` is on by
default. It warns about unguarded uses of APIs only when they were 
introduced
in or after macOS 10.13, iOS 11, tvOS 11 or watchOS 4.
 
--  The -Wdocumentation warning now allows the use of ``\param`` and
+-  The ``-Wdocumentation`` warning now allows the use of ``\param`` and
``\returns`` documentation directives in the documentation comments for
declarations with a function or a block pointer type.
 
@@ -75,7 +75,8 @@ Improvements to Clang's diagnostics
 New Compiler Flags
 --
 
-- --autocomplete was implemented to obtain a list of flags and its arguments. 
This is used for shell autocompletion.
+- ``--autocomplete`` was implemented to obtain a list of flags and its 
arguments.
+  This is used for shell autocompletion.
 
 Deprecated Compiler Flags
 -
@@ -83,9 +84,9 @@ Deprecated Compiler Flags
 The following options are deprecated and ignored. They will be removed in
 future versions of Clang.
 
-- -fslp-vectorize-aggressive used to enable the BB vectorizing pass. They have 
been superseeded
+- ``-fslp-vectorize-aggressive`` used to enable the BB vectorizing pass. They 
have been superseeded
   by the normal SLP vectorizer.
-- -fno-slp-vectorize-aggressive used to be the default behavior of clang.
+- ``-fno-slp-vectorize-aggressive`` used to be the default behavior of clang.
 
 New Pragmas in Clang
 ---
@@ -134,11 +135,9 @@ a vector expression--occurs when:
   vector's elements.
 
 - For compile time constant values, the above rule is weakened to consider the
-  value of the scalar constant rather than the constant's type.
-
-- Floating point constants with precise integral representations are not
-  implicitly converted to integer values, this is for compatibility with GCC.
-
+  value of the scalar constant rather than the constant's type. However,
+  for compatibility with GCC, floating point constants with precise integral
+  representations are not implicitly converted to integer values.
 
 Currently the basic integer and floating point types with the following
 operators are supported: ``+``, ``/``, ``-``, ``*``, ``%``, ``>``, ``<``,
@@ -313,7 +312,7 @@ Undefined Behavior Sanitizer (UBSan)
 
 - The Undefined Behavior Sanitizer has a new check for pointer overflow. This
   check is on by default. The flag to control this functionality is
-  -fsanitize=pointer-overflow.
+  ``-fsanitize=pointer-overflow``.
 
   Pointer overflow is an indicator of undefined behavior: when a pointer
   indexing expression wraps around the address space, or produces other
@@ -321,10 +320,10 @@ Undefined Behavior Sanitizer (UBSan)
 
 - UBSan has several new checks which detect violations of nullability
   annotations. These checks are off by default. The flag to control this group
-  of checks is -fsanitize=nullability. The checks can be individially enabled
-  by -fsanitize=nullability-arg (which checks calls),
-  -fsanitize=nullability-assign (which checks assignments), and
-  -fsan

[llvm-branch-commits] [cfe-branch] r312293 - Mention the expected change to default -std= in future clang releases.

2017-08-31 Thread Richard Smith via llvm-branch-commits
Author: rsmith
Date: Thu Aug 31 16:19:49 2017
New Revision: 312293

URL: http://llvm.org/viewvc/llvm-project?rev=312293&view=rev
Log:
Mention the expected change to default -std= in future clang releases.

Modified:
cfe/branches/release_50/docs/ReleaseNotes.rst

Modified: cfe/branches/release_50/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/branches/release_50/docs/ReleaseNotes.rst?rev=312293&r1=312292&r2=312293&view=diff
==
--- cfe/branches/release_50/docs/ReleaseNotes.rst (original)
+++ cfe/branches/release_50/docs/ReleaseNotes.rst Thu Aug 31 16:19:49 2017
@@ -148,6 +148,12 @@ assignment operators where applicable.
 C++ Language Changes in Clang
 -
 
+- We expect this to be the last Clang release that defaults to ``-std=gnu++98``
+  when using the GCC-compatible ``clang++`` driver. From Clang 6 onwards we
+  expect to use ``-std=gnu++14`` or a later standard by default, to match the
+  behavior of recent GCC releases. Users are encouraged to change their build
+  files to explicitly specify their desired C++ standard.
+
 - Support for the C++17 standard has been completed. This mode can be enabled
   using ``-std=c++17`` (the old flag ``-std=c++1z`` is still supported for
   compatibility).


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


[llvm-branch-commits] [cfe-branch] r326297 - A few release notes updates for C++ support in Clang 6.0.

2018-02-27 Thread Richard Smith via llvm-branch-commits
Author: rsmith
Date: Tue Feb 27 18:59:20 2018
New Revision: 326297

URL: http://llvm.org/viewvc/llvm-project?rev=326297&view=rev
Log:
A few release notes updates for C++ support in Clang 6.0.

Modified:
cfe/branches/release_60/docs/ReleaseNotes.rst

Modified: cfe/branches/release_60/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/branches/release_60/docs/ReleaseNotes.rst?rev=326297&r1=326296&r2=326297&view=diff
==
--- cfe/branches/release_60/docs/ReleaseNotes.rst (original)
+++ cfe/branches/release_60/docs/ReleaseNotes.rst Tue Feb 27 18:59:20 2018
@@ -174,6 +174,34 @@ C++ Language Changes in Clang
   conforming GNU extensions. Projects incompatible with C++14 can add
   ``-std=gnu++98`` to their build settings to restore the previous behaviour.
 
+- Added support for some features from the C++ standard after C++14
+  (provisionally known as C++2a but expected to be C++20). This support can be
+  enabled with the ``-std=c++2a`` flag. This enables:
+
+  - Support for ``__VA_OPT__``, to allow variadic macros to easily provide
+different expansions when they are invoked without variadic arguments.
+
+  - Recognition of the ``<=>`` token (the C++2a three-way comparison operator).
+
+  - Support for default member initializers for bit-fields.
+
+  - Lambda capture of ``*this``.
+
+  - Pointer-to-member calls using ``const &``-qualified pointers on temporary 
objects.
+
+  All of these features other than ``__VA_OPT__`` and ``<=>`` are made
+  available with a warning in earlier C++ language modes.
+
+- A warning has been added for a ``<=`` token followed immediately by a ``>``
+  character. Code containing such constructs will change meaning in C++2a due
+  to the addition of the ``<=>`` operator.
+
+- Clang implements the "destroying operator delete" feature described in C++
+  committee paper `P0722R1
+  `,
+  which is targeting inclusion in C++2a but has not yet been voted into the C++
+  working draft. Support for this feature is enabled by the presence of the
+  standard library type ``std::destroying_delete_t``.
 
 OpenCL C Language Changes in Clang
 --


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


[llvm-branch-commits] [clang] cd4c55c - Fix grammar in diagnostic for wrong arity in a structured binding.

2021-01-13 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2021-01-13T17:41:09-08:00
New Revision: cd4c55c97402246099ae865a66517a36af5c3a7c

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

LOG: Fix grammar in diagnostic for wrong arity in a structured binding.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/SemaCXX/cxx1z-decomposition.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b387736832a9..7d36397a7993 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -470,8 +470,9 @@ def err_decomp_decl_not_alone : Error<
 def err_decomp_decl_requires_init : Error<
   "decomposition declaration %0 requires an initializer">;
 def err_decomp_decl_wrong_number_bindings : Error<
-  "type %0 decomposes into %2 elements, but %select{only |}3%1 "
-  "names were provided">;
+  "type %0 decomposes into %3 %plural{1:element|:elements}2, but "
+  "%select{%plural{0:no|:only %1}1|%1}4 "
+  "%plural{1:name was|:names were}1 provided">;
 def err_decomp_decl_unbindable_type : Error<
   "cannot decompose %select{union|non-class, non-array}1 type %2">;
 def err_decomp_decl_multiple_bases_with_members : Error<

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 0df022f036f2..27679ac6f8d3 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -902,7 +902,8 @@ static bool checkSimpleDecomposition(
 llvm::function_ref GetInit) {
   if ((int64_t)Bindings.size() != NumElems) {
 S.Diag(Src->getLocation(), diag::err_decomp_decl_wrong_number_bindings)
-<< DecompType << (unsigned)Bindings.size() << NumElems.toString(10)
+<< DecompType << (unsigned)Bindings.size()
+<< (unsigned)NumElems.getLimitedValue(UINT_MAX) << 
NumElems.toString(10)
 << (NumElems < Bindings.size());
 return true;
   }
@@ -1148,8 +1149,9 @@ static bool checkTupleLikeDecomposition(Sema &S,
 const llvm::APSInt &TupleSize) {
   if ((int64_t)Bindings.size() != TupleSize) {
 S.Diag(Src->getLocation(), diag::err_decomp_decl_wrong_number_bindings)
-<< DecompType << (unsigned)Bindings.size() << TupleSize.toString(10)
-<< (TupleSize < Bindings.size());
+<< DecompType << (unsigned)Bindings.size()
+<< (unsigned)TupleSize.getLimitedValue(UINT_MAX)
+<< TupleSize.toString(10) << (TupleSize < Bindings.size());
 return true;
   }
 
@@ -1373,7 +1375,7 @@ static bool checkMemberDecomposition(Sema &S, 
ArrayRef Bindings,
   [](FieldDecl *FD) { return !FD->isUnnamedBitfield(); });
 assert(Bindings.size() != NumFields);
 S.Diag(Src->getLocation(), diag::err_decomp_decl_wrong_number_bindings)
-<< DecompType << (unsigned)Bindings.size() << NumFields
+<< DecompType << (unsigned)Bindings.size() << NumFields << NumFields
 << (NumFields < Bindings.size());
 return true;
   };

diff  --git a/clang/test/SemaCXX/cxx1z-decomposition.cpp 
b/clang/test/SemaCXX/cxx1z-decomposition.cpp
index 45a062a916f3..1ce75fe48db3 100644
--- a/clang/test/SemaCXX/cxx1z-decomposition.cpp
+++ b/clang/test/SemaCXX/cxx1z-decomposition.cpp
@@ -4,6 +4,21 @@ void use_from_own_init() {
   auto [a] = a; // expected-error {{binding 'a' cannot appear in the 
initializer of its own decomposition declaration}}
 }
 
+void num_elems() {
+  struct A0 {} a0;
+  int a1[1], a2[2];
+
+  auto [] = a0; // expected-warning {{does not allow a decomposition group to 
be empty}}
+  auto [v1] = a0; // expected-error {{type 'A0' decomposes into 0 elements, 
but 1 name was provided}}
+  auto [] = a1; // expected-error {{type 'int [1]' decomposes into 1 element, 
but no names were provided}} expected-warning {{empty}}
+  auto [v2] = a1;
+  auto [v3, v4] = a1; // expected-error {{type 'int [1]' decomposes into 1 
element, but 2 names were provided}}
+  auto [] = a2; // expected-error {{type 'int [2]' decomposes into 2 elements, 
but no names were provided}} expected-warning {{empty}}
+  auto [v5] = a2; // expected-error {{type 'int [2]' decomposes into 2 
elements, but only 1 name was provided}}
+  auto [v6, v7] = a2;
+  auto [v8, v9, v10] = a2; // expected-error {{type 'int [2]' decomposes into 
2 elements, but 3 names were provided}}
+}
+
 // As a Clang extension, _Complex can be decomposed.
 float decompose_complex(_Complex float cf) {
   static _Complex float scf;



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


[llvm-branch-commits] [clang] bc713f6 - PR48763: Better handling for classes that inherit a default constructor.

2021-01-18 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2021-01-18T18:54:04-08:00
New Revision: bc713f6a004723d1325bc16e1efc32d0ac82f939

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

LOG: PR48763: Better handling for classes that inherit a default constructor.

The C++ standard wording doesn't appear to properly handle the case
where a class inherits a default constructor from a base class. Various
properties of classes are defined in terms of the corresponding property
of the default constructor, and in this case, the class does not have a
default constructor despite being default-constructible, which the
wording doesn't handle properly.

This change implements a tentative fix for these problems, which has
also been proposed to the C++ committee: if a class would inherit a
default constructor, and does not explicitly declare one, then one is
implicitly declared.

Added: 


Modified: 
clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
clang/include/clang/AST/DeclCXX.h
clang/lib/AST/DeclCXX.cpp
clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p15.cpp
clang/test/CXX/special/class.ctor/p6-0x.cpp
clang/test/CXX/special/class.inhctor/p1.cpp
clang/test/CXX/special/class.inhctor/p2.cpp

Removed: 




diff  --git a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def 
b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
index 4ce6771259d9..d15d6698860f 100644
--- a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
+++ b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
@@ -131,6 +131,10 @@ FIELD(HasUninitializedFields, 1, NO_MERGE)
 /// constructors from a base class.
 FIELD(HasInheritedConstructor, 1, NO_MERGE)
 
+/// True if there are any member using-declarations that inherit
+/// default constructors from a base class.
+FIELD(HasInheritedDefaultConstructor, 1, NO_MERGE)
+
 /// True if there are any member using-declarations named
 /// 'operator='.
 FIELD(HasInheritedAssignment, 1, NO_MERGE)

diff  --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 568eeb614a76..e32101bb2276 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -744,9 +744,14 @@ class CXXRecordDecl : public RecordDecl {
   ///
   /// This value is used for lazy creation of default constructors.
   bool needsImplicitDefaultConstructor() const {
-return !data().UserDeclaredConstructor &&
-   !(data().DeclaredSpecialMembers & SMF_DefaultConstructor) &&
-   (!isLambda() || lambdaIsDefaultConstructibleAndAssignable());
+return (!data().UserDeclaredConstructor &&
+!(data().DeclaredSpecialMembers & SMF_DefaultConstructor) &&
+(!isLambda() || lambdaIsDefaultConstructibleAndAssignable())) ||
+   // FIXME: Proposed fix to core wording issue: if a class inherits
+   // a default constructor and doesn't explicitly declare one, one
+   // is declared implicitly.
+   (data().HasInheritedDefaultConstructor &&
+!(data().DeclaredSpecialMembers & SMF_DefaultConstructor));
   }
 
   /// Determine whether this class has any user-declared constructors.

diff  --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index b806adf36bfb..0368ada0b81c 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -81,7 +81,9 @@ CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl 
*D)
   HasPublicFields(false), HasMutableFields(false), 
HasVariantMembers(false),
   HasOnlyCMembers(true), HasInClassInitializer(false),
   HasUninitializedReferenceMember(false), HasUninitializedFields(false),
-  HasInheritedConstructor(false), HasInheritedAssignment(false),
+  HasInheritedConstructor(false),
+  HasInheritedDefaultConstructor(false),
+  HasInheritedAssignment(false),
   NeedOverloadResolutionForCopyConstructor(false),
   NeedOverloadResolutionForMoveConstructor(false),
   NeedOverloadResolutionForCopyAssignment(false),
@@ -814,6 +816,8 @@ void CXXRecordDecl::addedMember(Decl *D) {
 //   constructor [...]
 if (Constructor->isConstexpr() && !Constructor->isCopyOrMoveConstructor())
   data().HasConstexprNonCopyMoveConstructor = true;
+if (!isa(D) && Constructor->isDefaultConstructor())
+  data().HasInheritedDefaultConstructor = true;
   }
 
   // Handle destructors.

diff  --git a/clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p15.cpp 
b/clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p15.cpp
index d64807ed5abd..4951ed6eb959 100644
--- a/clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p15.cpp
+++ b/clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p15.cpp
@@ -36,7 +36,7 @@ namespace default_ctor {
   };
 
   struct A {
-A(); // expected-note {{ca

[llvm-branch-commits] [clang] e3065ce - DR2064: decltype(E) is only a dependent type if E is type-dependent, not

2021-01-18 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2021-01-18T21:05:01-08:00
New Revision: e3065ce238475ec202c707f4c58d90df171626ca

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

LOG: DR2064: decltype(E) is only a dependent type if E is type-dependent, not
if E is merely instantiation-dependent.

Previously reverted in 34e72a146111dd986889a0f0ec8767b2ca6b2913;
re-committed with a fix to an issue that caused name mangling to assert.

Added: 


Modified: 
clang/include/clang/AST/DependenceFlags.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/Type.cpp
clang/test/CXX/drs/dr20xx.cpp
clang/test/CodeGenCXX/mangle-subst.cpp
clang/test/Sema/invalid-bitwidth-expr.mm
clang/test/SemaCXX/invalid-template-base-specifier.cpp
clang/test/SemaTemplate/dependent-expr.cpp
clang/test/SemaTemplate/temp_arg_template_cxx1z.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/include/clang/AST/DependenceFlags.h 
b/clang/include/clang/AST/DependenceFlags.h
index ca96b65574bd..8c47047a7526 100644
--- a/clang/include/clang/AST/DependenceFlags.h
+++ b/clang/include/clang/AST/DependenceFlags.h
@@ -255,6 +255,12 @@ inline TypeDependence 
toTypeDependence(TemplateNameDependence D) {
 inline TypeDependence toTypeDependence(TemplateArgumentDependence D) {
   return Dependence(D).type();
 }
+/// Compute the dependence of a type that depends on the type of an expression,
+/// given the dependence of that expression and of its type.
+inline TypeDependence typeToTypeDependence(ExprDependence ED, TypeDependence 
TD) {
+  return Dependence(ED & ~ExprDependence::Value).type() |
+ (TD & TypeDependence::VariablyModified);
+}
 
 inline NestedNameSpecifierDependence
 toNestedNameSpecifierDependendence(TypeDependence D) {

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 44545f00b146..0190573fe36e 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -5383,10 +5383,10 @@ QualType ASTContext::getDecltypeType(Expr *e, QualType 
UnderlyingType) const {
   DecltypeType *dt;
 
   // C++11 [temp.type]p2:
-  //   If an expression e involves a template parameter, decltype(e) denotes a
-  //   unique dependent type. Two such decltype-specifiers refer to the same
-  //   type only if their expressions are equivalent (14.5.6.1).
-  if (e->isInstantiationDependent()) {
+  //   If an expression e is type-dependent, decltype(e) denotes a unique
+  //   dependent type. Two such decltype-specifiers refer to the same type only
+  //   if their expressions are equivalent (14.5.6.1).
+  if (e->isTypeDependent()) {
 llvm::FoldingSetNodeID ID;
 DependentDecltypeType::Profile(ID, *this, e);
 

diff  --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 73c8f17a5d36..1f8c11f6de96 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -2578,6 +2578,11 @@ void CXXNameMangler::mangleType(QualType T) {
 if (!TST->isTypeAlias())
   break;
 
+  // Don't desugar instantiation-dependent decltype / typeof types. We need
+  // to mangle the expression as written.
+  if (isa(T))
+break;
+
   QualType Desugared
 = T.getSingleStepDesugaredType(Context.getASTContext());
   if (Desugared == T)
@@ -5568,12 +5573,11 @@ static bool hasMangledSubstitutionQualifiers(QualType 
T) {
 
 bool CXXNameMangler::mangleSubstitution(QualType T) {
   if (!hasMangledSubstitutionQualifiers(T)) {
-if (const RecordType *RT = T->getAs())
+if (const RecordType *RT = dyn_cast(T))
   return mangleSubstitution(RT->getDecl());
   }
 
   uintptr_t TypePtr = reinterpret_cast(T.getAsOpaquePtr());
-
   return mangleSubstitution(TypePtr);
 }
 
@@ -5732,7 +5736,7 @@ bool CXXNameMangler::mangleStandardSubstitution(const 
NamedDecl *ND) {
 
 void CXXNameMangler::addSubstitution(QualType T) {
   if (!hasMangledSubstitutionQualifiers(T)) {
-if (const RecordType *RT = T->getAs()) {
+if (const RecordType *RT = dyn_cast(T)) {
   addSubstitution(RT->getDecl());
   return;
 }

diff  --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 034e175f1352..5dec80be9ccb 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -125,8 +125,7 @@ ArrayType::ArrayType(TypeClass tc, QualType et, QualType 
can,
 //   template int arr[] = {N...};
 : Type(tc, can,
et->getDependence() |
-   (sz ? toTypeDependence(
- turnValueToTypeDependence(sz->getDependence()))
+   (sz ? toTypeDependence(sz->getDependence())
: TypeDependence::None) |
(tc == VariableArray ? TypeDependence::VariablyModified
  

[llvm-branch-commits] [lldb] 4b57400 - [c++20] P1907R1: Support for generalized non-type template arguments of scalar type.

2021-01-18 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2021-01-18T21:05:01-08:00
New Revision: 4b574008aef5a7235c1f894ab065fe300d26e786

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

LOG: [c++20] P1907R1: Support for generalized non-type template arguments of 
scalar type.

Previously committed as 9e08e51a20d0d2b1c5724bb17e969d036fced4cd, and
reverted because a dependency commit was reverted. This incorporates the
following follow-on commits that were also reverted:

7e84aa1b81e72d44bcc58ffe1731bfc7abb73ce0 by Simon Pilgrim
ed13d8c66781b50ff007cb089c5905f9bb9e8af2 by me
95c7b6cadbc9a3d4376ef44edbeb3c8bb5b8d7fc by Sam McCall
430d5d8429473c2b10b109991d7577a3cea41140 by Dave Zarzycki

Added: 
clang/test/CodeGenCXX/template-arguments.cpp

Modified: 
clang-tools-extra/clangd/DumpAST.cpp
clang-tools-extra/clangd/FindTarget.cpp
clang-tools-extra/clangd/index/remote/Client.cpp
clang/include/clang/AST/ASTContext.h
clang/include/clang/AST/PropertiesBase.td
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/AST/TemplateArgumentVisitor.h
clang/include/clang/AST/TemplateBase.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/ASTStructuralEquivalence.cpp
clang/lib/AST/Decl.cpp
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/MicrosoftMangle.cpp
clang/lib/AST/ODRHash.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/AST/TemplateBase.cpp
clang/lib/AST/TypeLoc.cpp
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/CodeGen/CGExprConstant.cpp
clang/lib/Index/USRGeneration.cpp
clang/lib/Sema/SemaLookup.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaTemplateVariadic.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/CodeGenCXX/mangle-ms-templates.cpp
clang/test/CodeGenCXX/mangle-template.cpp
clang/test/SemaTemplate/temp_arg_nontype_cxx17.cpp
clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
clang/tools/libclang/CIndex.cpp
clang/tools/libclang/CXCursor.cpp
lldb/include/lldb/lldb-enumerations.h
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/DumpAST.cpp 
b/clang-tools-extra/clangd/DumpAST.cpp
index 588bcfcf2424..bf7675e7d949 100644
--- a/clang-tools-extra/clangd/DumpAST.cpp
+++ b/clang-tools-extra/clangd/DumpAST.cpp
@@ -143,6 +143,7 @@ class DumpVisitor : public RecursiveASTVisitor 
{
   TEMPLATE_ARGUMENT_KIND(Declaration);
   TEMPLATE_ARGUMENT_KIND(Template);
   TEMPLATE_ARGUMENT_KIND(TemplateExpansion);
+  TEMPLATE_ARGUMENT_KIND(UncommonValue);
 #undef TEMPLATE_ARGUMENT_KIND
 }
 llvm_unreachable("Unhandled ArgKind enum");

diff  --git a/clang-tools-extra/clangd/FindTarget.cpp 
b/clang-tools-extra/clangd/FindTarget.cpp
index 84316659daad..98ef8b3b6d76 100644
--- a/clang-tools-extra/clangd/FindTarget.cpp
+++ b/clang-tools-extra/clangd/FindTarget.cpp
@@ -1079,6 +1079,7 @@ class ExplicitReferenceCollector
 case TemplateArgument::Pack:
 case TemplateArgument::Type:
 case TemplateArgument::Expression:
+case TemplateArgument::UncommonValue:
   break; // Handled by VisitType and VisitExpression.
 };
 return RecursiveASTVisitor::TraverseTemplateArgumentLoc(A);

diff  --git a/clang-tools-extra/clangd/index/remote/Client.cpp 
b/clang-tools-extra/clangd/index/remote/Client.cpp
index b09dbf915e46..a153a8812baf 100644
--- a/clang-tools-extra/clangd/index/remote/Client.cpp
+++ b/clang-tools-extra/clangd/index/remote/Client.cpp
@@ -152,7 +152,8 @@ class IndexClient : public clangd::SymbolIndex {
   });
   }
 
-  llvm::unique_function indexedFiles() const {
+  llvm::unique_function
+  indexedFiles() const override {
 // FIXME: For now we always return "false" regardless of whether the file
 //was indexed or not. A possible implementation could be based on
 //the idea that we do not want to send a request at every

diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 0c5d82b3e9aa..a9bfdb4d5fa5 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -2818,8 +2818,8 @@ class ASTContext : public RefCountedBase {
   /// for destruction.
   template  void addDestruction(T *Ptr) const {
 if (!std::is_trivially_destructible::value) {
-  auto DestroyPtr = [](void *V) { static_cast(V)->~T(); };
-  AddDeallocation(DestroyPtr, Ptr);
+  auto DestroyPtr =

[llvm-branch-commits] [clang] 5a391d3 - Following up on PR48517, fix handling of template arguments that refer

2021-01-18 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2021-01-18T21:05:01-08:00
New Revision: 5a391d38ac6c561ba908334d427f26124ed9132e

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

LOG: Following up on PR48517, fix handling of template arguments that refer
to dependent declarations.

Treat an id-expression that names a local variable in a templated
function as being instantiation-dependent.

This addresses a language defect whereby a reference to a dependent
declaration can be formed without any construct being value-dependent.
Fixing that through value-dependence turns out to be problematic, so
instead this patch takes the approach (proposed on the core reflector)
of allowing the use of pointers or references to (but not values of)
dependent declarations inside value-dependent expressions, and instead
treating template arguments as dependent if they evaluate to a constant
involving such dependent declarations.

This ends up affecting a bunch of OpenMP tests, due to OpenMP
imprecisely handling instantiation-dependent constructs, bailing out
early instead of processing dependent constructs to the extent possible
when handling the template.

Previously committed as 8c1f2d15b826591cdf6bd6b468b8a7d23377b29e, and
reverted because a dependency commit was reverted.

Added: 
clang/test/SemaTemplate/temp_arg_nontype_cxx17.cpp

Modified: 
clang/include/clang/AST/Expr.h
clang/include/clang/AST/TemplateBase.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/ComputeDependence.cpp
clang/lib/AST/Expr.cpp
clang/lib/AST/ExprCXX.cpp
clang/lib/AST/ExprConstant.cpp
clang/lib/AST/TemplateBase.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/test/OpenMP/distribute_dist_schedule_messages.cpp
clang/test/OpenMP/distribute_parallel_for_dist_schedule_messages.cpp
clang/test/OpenMP/distribute_parallel_for_simd_dist_schedule_messages.cpp
clang/test/OpenMP/distribute_simd_dist_schedule_messages.cpp
clang/test/OpenMP/target_parallel_for_simd_collapse_messages.cpp
clang/test/OpenMP/target_parallel_for_simd_ordered_messages.cpp
clang/test/OpenMP/target_simd_collapse_messages.cpp
clang/test/OpenMP/target_teams_distribute_dist_schedule_messages.cpp

clang/test/OpenMP/target_teams_distribute_parallel_for_dist_schedule_messages.cpp

clang/test/OpenMP/target_teams_distribute_parallel_for_simd_dist_schedule_messages.cpp
clang/test/OpenMP/target_teams_distribute_simd_dist_schedule_messages.cpp
clang/test/OpenMP/target_update_from_messages.cpp
clang/test/OpenMP/target_update_to_messages.cpp
clang/test/OpenMP/task_messages.cpp
clang/test/OpenMP/teams_distribute_dist_schedule_messages.cpp
clang/test/OpenMP/teams_distribute_parallel_for_dist_schedule_messages.cpp

clang/test/OpenMP/teams_distribute_parallel_for_simd_dist_schedule_messages.cpp
clang/test/OpenMP/teams_distribute_simd_dist_schedule_messages.cpp
clang/test/SemaCXX/warn-unused-lambda-capture.cpp
clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp

Removed: 
clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp



diff  --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index a44d06967431..c963be98d3cb 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -578,12 +578,12 @@ class Expr : public ValueStmt {
   struct EvalStatus {
 /// Whether the evaluated expression has side effects.
 /// For example, (f() && 0) can be folded, but it still has side effects.
-bool HasSideEffects;
+bool HasSideEffects = false;
 
 /// Whether the evaluation hit undefined behavior.
 /// For example, 1.0 / 0.0 can be folded to Inf, but has undefined 
behavior.
 /// Likewise, INT_MAX + 1 can be folded to INT_MIN, but has UB.
-bool HasUndefinedBehavior;
+bool HasUndefinedBehavior = false;
 
 /// Diag - If this is non-null, it will be filled in with a stack of notes
 /// indicating why evaluation failed (or why it failed to produce a 
constant
@@ -592,10 +592,7 @@ class Expr : public ValueStmt {
 /// foldable. If the expression is foldable, but not a constant expression,
 /// the notes will describes why it isn't a constant expression. If the
 /// expression *is* a constant expression, no notes will be produced.
-SmallVectorImpl *Diag;
-
-EvalStatus()
-: HasSideEffects(false), HasUndefinedBehavior(false), Diag(nullptr) {}
+SmallVectorImpl *Diag = nullptr;
 
 // hasSideEffects - Return true if the evaluated expression has
 // side effects.
@@ -606,8 +603,11 @@ class Expr : public ValueStmt {
 
   /// EvalResult is a struct with detailed info about an evaluated expression.
   struct EvalResult : Eva

[llvm-branch-commits] [clang] fbb83f1 - PR24076, PR33655, C++ CWG 1558: Consider the instantiation-dependence of

2021-01-18 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2021-01-18T21:05:01-08:00
New Revision: fbb83f18b5485218ad3c36c1d079c89f061372b8

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

LOG: PR24076, PR33655, C++ CWG 1558: Consider the instantiation-dependence of
the nested-name-specifier when determining whether a qualified type is
instantiation-dependent.

Previously reverted in 25a02c3d1a688d3cd18faef96c75fa553efbbac7 due to
causing us to reject some code. It turns out that the rejected code was
ill-formed (no diagnostic required).

Added: 
clang/test/SemaTemplate/instantiation-dependence.cpp

Modified: 
clang/include/clang/AST/Type.h
clang/lib/AST/ItaniumMangle.cpp
clang/test/CXX/drs/dr15xx.cpp
clang/test/CodeGenCXX/mangle-template.cpp
clang/test/SemaTemplate/partial-spec-instantiate.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 143a05cba6ad..319d3850346b 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -5412,7 +5412,9 @@ class ElaboratedType final
   ElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
  QualType NamedType, QualType CanonType, TagDecl *OwnedTagDecl)
   : TypeWithKeyword(Keyword, Elaborated, CanonType,
-NamedType->getDependence()),
+NamedType->getDependence() |
+(NNS ? toTypeDependence(NNS->getDependence())
+ : TypeDependence::None)),
 NNS(NNS), NamedType(NamedType) {
 ElaboratedTypeBits.HasOwnedTagDecl = false;
 if (OwnedTagDecl) {

diff  --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 1f8c11f6de96..084a0b0c5bf0 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -2583,6 +2583,10 @@ void CXXNameMangler::mangleType(QualType T) {
   if (isa(T))
 break;
 
+  // FIXME: We presumably shouldn't strip off ElaboratedTypes with
+  // instantation-dependent qualifiers. See
+  // https://github.com/itanium-cxx-abi/cxx-abi/issues/114.
+
   QualType Desugared
 = T.getSingleStepDesugaredType(Context.getASTContext());
   if (Desugared == T)

diff  --git a/clang/test/CXX/drs/dr15xx.cpp b/clang/test/CXX/drs/dr15xx.cpp
index 478a0d7d00dd..8bfa29a8b667 100644
--- a/clang/test/CXX/drs/dr15xx.cpp
+++ b/clang/test/CXX/drs/dr15xx.cpp
@@ -239,6 +239,20 @@ namespace dr1550 { // dr1550: yes
   }
 }
 
+namespace dr1558 { // dr1558: 12
+#if __cplusplus >= 201103L
+  template using first_of = T;
+  template first_of f(int); // expected-note 
{{'int' cannot be used prior to '::'}}
+  template void f(...) = delete; // expected-note {{deleted}}
+
+  struct X { typedef void type; };
+  void test() {
+f(0);
+f(0); // expected-error {{deleted}}
+  }
+#endif
+}
+
 namespace dr1560 { // dr1560: 3.5
   void f(bool b, int n) {
 (b ? throw 0 : n) = (b ? n : throw 0) = 0;

diff  --git a/clang/test/CodeGenCXX/mangle-template.cpp 
b/clang/test/CodeGenCXX/mangle-template.cpp
index 9b5220572c2e..40688de7e12e 100644
--- a/clang/test/CodeGenCXX/mangle-template.cpp
+++ b/clang/test/CodeGenCXX/mangle-template.cpp
@@ -342,3 +342,23 @@ namespace fixed_size_parameter_pack {
   template void f(A::B<0, Ns...>);
   void g() { f<1, 2>({}); }
 }
+
+namespace type_qualifier {
+  template using int_t = int;
+  template void f(decltype(int_t() + 1)) {}
+  // FIXME: This mangling doesn't work: we need to mangle the
+  // instantiation-dependent 'int_t' operand.
+  // CHECK: @_ZN14type_qualifier1fIPiEEvDTplcvi_ELi1EE
+  template void f(int);
+
+  // Note that this template has 
diff erent constraints but would mangle the
+  // same:
+  //template void f(decltype(int_t() + 1)) {}
+
+  struct impl { using type = void; };
+  template using alias = impl;
+  template void g(decltype(alias::type(), 1)) {}
+  // FIXME: Similarly we need to mangle the `T*` in here.
+  // CHECK: @_ZN14type_qualifier1gIPiEEvDTcmcvv_ELi1EE
+  template void g(int);
+}

diff  --git a/clang/test/SemaTemplate/instantiation-dependence.cpp 
b/clang/test/SemaTemplate/instantiation-dependence.cpp
new file mode 100644
index ..2b9a47ad25a4
--- /dev/null
+++ b/clang/test/SemaTemplate/instantiation-dependence.cpp
@@ -0,0 +1,82 @@
+// RUN: %clang_cc1 -std=c++2b -verify %s
+
+// Ensure we substitute into instantiation-dependent but non-dependent
+// constructs. The poster-child for this is...
+template using void_t = void;
+
+namespace PR24076 {
+  template T declval();
+  struct s {};
+
+  template() + 1)>>
+void foo(T) {} // expected-note {{invalid operands to binary expression}}
+
+  void f() {
+foo(s{}); // expected-error {{no matching function}}

[llvm-branch-commits] [clang] 987760b - [www] Fix background color in table cell.

2021-01-19 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2021-01-19T11:04:31-08:00
New Revision: 987760b463c1303121fff8197c4ebc66b61f0616

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

LOG: [www] Fix background color in table cell.

Added: 


Modified: 
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index 923b13db73a6..685f32dbe0d3 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -1005,7 +1005,7 @@ C++20 implementation status
 
   Class types as non-type template parameters
   https://wg21.link/p0732r2";>P0732R2
-  Clang 12
+  Clang 12
 

 https://wg21.link/p1907r1";>P1907R1



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


[llvm-branch-commits] [clang] da98651 - Revert "DR2064: decltype(E) is only a dependent type if E is type-dependent, not

2021-01-19 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2021-01-19T12:48:40-08:00
New Revision: da986511fb9da1a46a0ca4dba2e49e2426036303

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

LOG: Revert "DR2064: decltype(E) is only a dependent type if E is 
type-dependent, not
if E is merely instantiation-dependent."

This change leaves us unable to distinguish between different function
templates that differ in only instantiation-dependent ways, for example

template decltype(int(T())) f();
template decltype(int(T(0))) f();

We'll need substantially better support for types that are
instantiation-dependent but not dependent before we can go ahead with
this change.

This reverts commit e3065ce238475ec202c707f4c58d90df171626ca.

Added: 


Modified: 
clang/include/clang/AST/DependenceFlags.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/Type.cpp
clang/test/CXX/drs/dr20xx.cpp
clang/test/CodeGenCXX/mangle-subst.cpp
clang/test/Sema/invalid-bitwidth-expr.mm
clang/test/SemaCXX/coroutines.cpp
clang/test/SemaCXX/invalid-template-base-specifier.cpp
clang/test/SemaTemplate/dependent-expr.cpp
clang/test/SemaTemplate/temp_arg_template_cxx1z.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/include/clang/AST/DependenceFlags.h 
b/clang/include/clang/AST/DependenceFlags.h
index 8c47047a7526..ca96b65574bd 100644
--- a/clang/include/clang/AST/DependenceFlags.h
+++ b/clang/include/clang/AST/DependenceFlags.h
@@ -255,12 +255,6 @@ inline TypeDependence 
toTypeDependence(TemplateNameDependence D) {
 inline TypeDependence toTypeDependence(TemplateArgumentDependence D) {
   return Dependence(D).type();
 }
-/// Compute the dependence of a type that depends on the type of an expression,
-/// given the dependence of that expression and of its type.
-inline TypeDependence typeToTypeDependence(ExprDependence ED, TypeDependence 
TD) {
-  return Dependence(ED & ~ExprDependence::Value).type() |
- (TD & TypeDependence::VariablyModified);
-}
 
 inline NestedNameSpecifierDependence
 toNestedNameSpecifierDependendence(TypeDependence D) {

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index d396f81188df..c482235caaed 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -5383,10 +5383,10 @@ QualType ASTContext::getDecltypeType(Expr *e, QualType 
UnderlyingType) const {
   DecltypeType *dt;
 
   // C++11 [temp.type]p2:
-  //   If an expression e is type-dependent, decltype(e) denotes a unique
-  //   dependent type. Two such decltype-specifiers refer to the same type only
-  //   if their expressions are equivalent (14.5.6.1).
-  if (e->isTypeDependent()) {
+  //   If an expression e involves a template parameter, decltype(e) denotes a
+  //   unique dependent type. Two such decltype-specifiers refer to the same
+  //   type only if their expressions are equivalent (14.5.6.1).
+  if (e->isInstantiationDependent()) {
 llvm::FoldingSetNodeID ID;
 DependentDecltypeType::Profile(ID, *this, e);
 

diff  --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index e7db8e2baa84..27aa622e00e9 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -2578,11 +2578,6 @@ void CXXNameMangler::mangleType(QualType T) {
 if (!TST->isTypeAlias())
   break;
 
-  // Don't desugar instantiation-dependent decltype / typeof types. We need
-  // to mangle the expression as written.
-  if (isa(T))
-break;
-
   // FIXME: We presumably shouldn't strip off ElaboratedTypes with
   // instantation-dependent qualifiers. See
   // https://github.com/itanium-cxx-abi/cxx-abi/issues/114.
@@ -5612,11 +5607,12 @@ static bool hasMangledSubstitutionQualifiers(QualType 
T) {
 
 bool CXXNameMangler::mangleSubstitution(QualType T) {
   if (!hasMangledSubstitutionQualifiers(T)) {
-if (const RecordType *RT = dyn_cast(T))
+if (const RecordType *RT = T->getAs())
   return mangleSubstitution(RT->getDecl());
   }
 
   uintptr_t TypePtr = reinterpret_cast(T.getAsOpaquePtr());
+
   return mangleSubstitution(TypePtr);
 }
 
@@ -5775,7 +5771,7 @@ bool CXXNameMangler::mangleStandardSubstitution(const 
NamedDecl *ND) {
 
 void CXXNameMangler::addSubstitution(QualType T) {
   if (!hasMangledSubstitutionQualifiers(T)) {
-if (const RecordType *RT = dyn_cast(T)) {
+if (const RecordType *RT = T->getAs()) {
   addSubstitution(RT->getDecl());
   return;
 }

diff  --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 5dec80be9ccb..034e175f1352 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -125,7 +125,8 @@ ArrayType::ArrayType(TypeClass tc, QualType et, QualType 
can,
 //   template int arr

[llvm-branch-commits] [clang] 5a684b7 - Ensure we don't strip the ConstantExpr carrying a non-type template

2021-01-19 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2021-01-19T12:48:39-08:00
New Revision: 5a684b70dc74f9f671f8eb61993a25769ec68117

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

LOG: Ensure we don't strip the ConstantExpr carrying a non-type template
argument's value off it during substitution.

Added: 


Modified: 
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/test/SemaTemplate/temp_arg_nontype_cxx17.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 7679063ead71..7d7591ab669c 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1597,7 +1597,9 @@ 
TemplateInstantiator::TransformSubstNonTypeTemplateParmPackExpr(
 ExprResult
 TemplateInstantiator::TransformSubstNonTypeTemplateParmExpr(
   SubstNonTypeTemplateParmExpr *E) {
-  ExprResult SubstReplacement = TransformExpr(E->getReplacement());
+  ExprResult SubstReplacement = E->getReplacement();
+  if (!isa(SubstReplacement.get()))
+SubstReplacement = TransformExpr(E->getReplacement());
   if (SubstReplacement.isInvalid())
 return true;
   QualType SubstType = TransformType(E->getParameterType(getSema().Context));

diff  --git a/clang/test/SemaTemplate/temp_arg_nontype_cxx17.cpp 
b/clang/test/SemaTemplate/temp_arg_nontype_cxx17.cpp
index bc8a22e89041..4d61b9c7d937 100644
--- a/clang/test/SemaTemplate/temp_arg_nontype_cxx17.cpp
+++ b/clang/test/SemaTemplate/temp_arg_nontype_cxx17.cpp
@@ -511,3 +511,18 @@ namespace dependent_reference {
   // Ensure that we can instantiate the definition of S<...>.
   int n = *v.q + *w.q;
 }
+
+namespace decay {
+  template struct 
X {
+template void f(const X &v) {}
+  };
+  struct A {
+static constexpr const char *arr[] = {"hello", "world"};
+static constexpr int count = 2;
+  };
+  void f() {
+X x1;
+X x2;
+x1.f(x2);
+  }
+}



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


[llvm-branch-commits] [clang] 18e093f - [msabi] Mangle a template argument referring to array-to-pointer decay

2021-01-19 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2021-01-19T14:38:07-08:00
New Revision: 18e093faf726d15f210ab4917142beec51848258

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

LOG: [msabi] Mangle a template argument referring to array-to-pointer decay
applied to an array the same as the array itself.

This follows MS ABI, and corrects a regression from the implementation
of generalized non-type template parameters, where we "forgot" how to
mangle this case.

Added: 


Modified: 
clang/lib/AST/MicrosoftMangle.cpp
clang/test/CodeGenCXX/mangle-ms-templates.cpp

Removed: 




diff  --git a/clang/lib/AST/MicrosoftMangle.cpp 
b/clang/lib/AST/MicrosoftMangle.cpp
index 16e0aa2ae466..b9c289b6497a 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -1466,6 +1466,21 @@ void MicrosoftCXXNameMangler::mangleTemplateArgs(
   }
 }
 
+/// If value V (with type T) represents a decayed pointer to the first element
+/// of an array, return that array.
+static ValueDecl *getAsArrayToPointerDecayedDecl(QualType T, const APValue &V) 
{
+  // Must be a pointer...
+  if (!T->isPointerType() || !V.isLValue() || !V.hasLValuePath() ||
+  !V.getLValueBase())
+return nullptr;
+  // ... to element 0 of an array.
+  QualType BaseT = V.getLValueBase().getType();
+  if (!BaseT->isArrayType() || V.getLValuePath().size() != 1 ||
+  V.getLValuePath()[0].getAsArrayIndex() != 0)
+return nullptr;
+  return const_cast(V.getLValueBase().dyn_cast());
+}
+
 void MicrosoftCXXNameMangler::mangleTemplateArg(const TemplateDecl *TD,
 const TemplateArgument &TA,
 const NamedDecl *Parm) {
@@ -1576,6 +1591,14 @@ void MicrosoftCXXNameMangler::mangleTemplateArg(const 
TemplateDecl *TD,
 break;
   }
   case TemplateArgument::UncommonValue:
+if (ValueDecl *D = getAsArrayToPointerDecayedDecl(
+TA.getUncommonValueType(), TA.getAsUncommonValue())) {
+  // Mangle the result of array-to-pointer decay as if it were a reference
+  // to the original declaration, to match MSVC's behavior. This can result
+  // in mangling collisions in some cases!
+  return mangleTemplateArg(
+  TD, TemplateArgument(D, TA.getUncommonValueType()), Parm);
+}
 Out << "$";
 if (cast(Parm)
 ->getType()

diff  --git a/clang/test/CodeGenCXX/mangle-ms-templates.cpp 
b/clang/test/CodeGenCXX/mangle-ms-templates.cpp
index c9149a473b6f..a5ddb41461cc 100644
--- a/clang/test/CodeGenCXX/mangle-ms-templates.cpp
+++ b/clang/test/CodeGenCXX/mangle-ms-templates.cpp
@@ -4,6 +4,20 @@
 // RUN: %clang_cc1 -std=c++17 -fms-compatibility-version=19 -emit-llvm %s -o - 
-fms-extensions -fdelayed-template-parsing -triple=x86_64-pc-win32 | FileCheck 
-check-prefix X64 %s
 // RUN: %clang_cc1 -std=c++20 -fms-compatibility-version=19 -emit-llvm %s -o - 
-fms-extensions -fdelayed-template-parsing -triple=x86_64-pc-win32 | FileCheck 
-check-prefix CXX20-X64 %s
 
+// Check that array-to-pointer decay is mangled as the underlying declaration.
+extern const char arr[4] = "foo";
+template struct Decay1 {};
+// CHECK: "?decay1@@3U?$Decay1@$1?arr@@3QBDB@@A"
+Decay1 decay1;
+#if __cplusplus >= 201702L
+// Note that this mangling approach can lead to collisions.
+template struct Decay2 {};
+// CXX20-X64: "?decay2a@@3U?$Decay2@$1?arr@@3QBDB@@A"
+Decay2<(const void*)arr> decay2a;
+// CXX20-X64: "?decay2b@@3U?$Decay2@$1?arr@@3QBDB@@A"
+Decay2<(const void*)&arr> decay2b;
+#endif
+
 template
 class Class {
  public:



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


[llvm-branch-commits] [clang] e92be7c - PR47682: Merge the DeclContext of a merged FunctionDecl before we inherit

2021-01-22 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2021-01-22T15:46:41-08:00
New Revision: e92be7cd9f03ab3eb8c4a21e686743c2575a169a

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

LOG: PR47682: Merge the DeclContext of a merged FunctionDecl before we inherit
default arguments.

When a function is declared with a qualified name, its eventual semantic
DeclContext may differ from the scope specified by the qualifier if it
redeclares a function in an inline namespace. In this case, we need to
update the DeclContext to be that of the previous declaration, and we
need to do so before we decide whether to inherit default arguments from
that previous declaration, because we only inherit default arguments
from declarations in the same scope.

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaCXX/default1.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 832fd8384ba8..3ee0c43097d7 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -3238,6 +3238,10 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, 
NamedDecl *&OldD,
 }
   }
 
+  // If the old declaration was found in an inline namespace and the new
+  // declaration was qualified, update the DeclContext to match.
+  adjustDeclContextForDeclaratorDecl(New, Old);
+
   // If the old declaration is invalid, just give up here.
   if (Old->isInvalidDecl())
 return true;
@@ -4052,6 +4056,10 @@ void Sema::MergeVarDecl(VarDecl *New, LookupResult 
&Previous) {
 return New->setInvalidDecl();
   }
 
+  // If the old declaration was found in an inline namespace and the new
+  // declaration was qualified, update the DeclContext to match.
+  adjustDeclContextForDeclaratorDecl(New, Old);
+
   // Ensure the template parameters are compatible.
   if (NewTemplate &&
   !TemplateParameterListsAreEqual(NewTemplate->getTemplateParameters(),
@@ -4236,7 +4244,6 @@ void Sema::MergeVarDecl(VarDecl *New, LookupResult 
&Previous) {
   New->setPreviousDecl(Old);
   if (NewTemplate)
 NewTemplate->setPreviousDecl(OldTemplate);
-  adjustDeclContextForDeclaratorDecl(New, Old);
 
   // Inherit access appropriately.
   New->setAccess(Old->getAccess());
@@ -10788,7 +10795,6 @@ bool Sema::CheckFunctionDeclaration(Scope *S, 
FunctionDecl *NewFD,
   NewTemplateDecl->mergePrevDecl(OldTemplateDecl);
 
   NewFD->setPreviousDeclaration(OldFD);
-  adjustDeclContextForDeclaratorDecl(NewFD, OldFD);
   if (NewFD->isCXXClassMember()) {
 NewFD->setAccess(OldTemplateDecl->getAccess());
 NewTemplateDecl->setAccess(OldTemplateDecl->getAccess());
@@ -10815,7 +10821,6 @@ bool Sema::CheckFunctionDeclaration(Scope *S, 
FunctionDecl *NewFD,
 auto *OldFD = cast(OldDecl);
 // This needs to happen first so that 'inline' propagates.
 NewFD->setPreviousDeclaration(OldFD);
-adjustDeclContextForDeclaratorDecl(NewFD, OldFD);
 if (NewFD->isCXXClassMember())
   NewFD->setAccess(OldFD->getAccess());
   }

diff  --git a/clang/test/SemaCXX/default1.cpp b/clang/test/SemaCXX/default1.cpp
index 457cada13bda..8345b2433a3f 100644
--- a/clang/test/SemaCXX/default1.cpp
+++ b/clang/test/SemaCXX/default1.cpp
@@ -95,4 +95,12 @@ void g2(int c = f2()) {}
 template int f3() { return T::error; } // expected-error {{no 
members}}
 void g3(int c = f3()) {} // expected-note {{in instantiation of}}
 void use_g3() { g3(); }
+
+namespace PR47682 {
+  inline namespace A {
+void f(int = 0);
+  }
+}
+void PR47682::f(int) {}
+void PR47682_test() { PR47682::f(); }
 #endif



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


[llvm-branch-commits] [clang] b12e473 - Allow dependent alias template specializations in the preferred_name

2021-01-05 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2021-01-05T15:33:51-08:00
New Revision: b12e4735317ec96e1b35deee68b90d62a23a9353

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

LOG: Allow dependent alias template specializations in the preferred_name
attribute.

This was intended to work, but didn't match the checks because these
types are modeled as TemplateSpecializationTypes not TypedefTypes.

Added: 


Modified: 
clang/include/clang/AST/Type.h
clang/lib/AST/TypePrinter.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/SemaTemplate/attributes.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 684005c4876d..143a05cba6ad 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2093,6 +2093,7 @@ class alignas(8) Type : public ExtQualsTypeCommonBase {
   bool isAtomicType() const;// C11 _Atomic()
   bool isUndeducedAutoType() const; // C++11 auto or
 // C++14 decltype(auto)
+  bool isTypedefNameType() const;   // typedef or alias template
 
 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
   bool is##Id##Type() const;
@@ -7066,6 +7067,15 @@ inline bool Type::isOverloadableType() const {
   return isDependentType() || isRecordType() || isEnumeralType();
 }
 
+/// Determines whether this type is written as a typedef-name.
+inline bool Type::isTypedefNameType() const {
+  if (getAs())
+return true;
+  if (auto *TST = getAs())
+return TST->isTypeAlias();
+  return false;
+}
+
 /// Determines whether this type can decay to a pointer type.
 inline bool Type::canDecayToPointerType() const {
   return isFunctionType() || isArrayType();

diff  --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 54c451291a07..d1882ac1a3b3 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -116,6 +116,8 @@ namespace {
 static bool canPrefixQualifiers(const Type *T, bool 
&NeedARCStrongQualifier);
 void spaceBeforePlaceHolder(raw_ostream &OS);
 void printTypeSpec(NamedDecl *D, raw_ostream &OS);
+void printTemplateId(const TemplateSpecializationType *T, raw_ostream &OS,
+ bool FullyQualify);
 
 void printBefore(QualType T, raw_ostream &OS);
 void printAfter(QualType T, raw_ostream &OS);
@@ -1352,9 +1354,17 @@ void TypePrinter::printRecordBefore(const RecordType *T, 
raw_ostream &OS) {
   // Print the preferred name if we have one for this type.
   for (const auto *PNA : T->getDecl()->specific_attrs()) {
 if (declaresSameEntity(PNA->getTypedefType()->getAsCXXRecordDecl(),
-   T->getDecl()))
-  return printTypeSpec(
-  PNA->getTypedefType()->castAs()->getDecl(), OS);
+   T->getDecl())) {
+  // Find the outermost typedef or alias template.
+  QualType T = PNA->getTypedefType();
+  while (true) {
+if (auto *TT = dyn_cast(T))
+  return printTypeSpec(TT->getDecl(), OS);
+if (auto *TST = dyn_cast(T))
+  return printTemplateId(TST, OS, /*FullyQualify=*/true);
+T = T->getLocallyUnqualifiedSingleStepDesugaredType();
+  }
+}
   }
 
   printTag(T->getDecl(), OS);
@@ -1416,20 +1426,32 @@ void TypePrinter::printSubstTemplateTypeParmPackAfter(
   printTemplateTypeParmAfter(T->getReplacedParameter(), OS);
 }
 
-void TypePrinter::printTemplateSpecializationBefore(
-const TemplateSpecializationType 
*T,
-raw_ostream &OS) {
+void TypePrinter::printTemplateId(const TemplateSpecializationType *T,
+  raw_ostream &OS, bool FullyQualify) {
   IncludeStrongLifetimeRAII Strong(Policy);
-  T->getTemplateName().print(OS, Policy);
 
-  const TemplateParameterList *TPL = nullptr;
-  if (TemplateDecl *TD = T->getTemplateName().getAsTemplateDecl())
-TPL = TD->getTemplateParameters();
+  TemplateDecl *TD = T->getTemplateName().getAsTemplateDecl();
+  if (FullyQualify && TD) {
+if (!Policy.SuppressScope)
+  AppendScope(TD->getDeclContext(), OS, TD->getDeclName());
+
+IdentifierInfo *II = TD->getIdentifier();
+OS << II->getName();
+  } else {
+T->getTemplateName().print(OS, Policy);
+  }
 
+  const TemplateParameterList *TPL = TD ? TD->getTemplateParameters() : 
nullptr;
   printTemplateArgumentList(OS, T->template_arguments(), Policy, TPL);
   spaceBeforePlaceHolder(OS);
 }
 
+void TypePrinter::printTemplateSpecializationBefore(
+const TemplateSpecializationType 
*T,
+raw_ostream &OS) {
+  printTemplateId(T, 

[llvm-branch-commits] [clang] 2bf6e44 - Attempt to complete an incomplete expression type when considering a

2021-01-08 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2021-01-08T15:19:28-08:00
New Revision: 2bf6e443e54604c7818c4d1a1837f3d091023270

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

LOG: Attempt to complete an incomplete expression type when considering a
reference binding to an expression.

We need to know the array bound in order to determine whether the
parameter type is reference-compatible with the argument type, so we
need to trigger instantiation in this case.

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaInit.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/lib/Sema/SemaType.cpp
clang/test/SemaTemplate/instantiate-static-var.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index acc3184aea97..1d79e5716ef7 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2139,6 +2139,16 @@ class Sema final {
 return RequireCompleteType(Loc, T, CompleteTypeKind::Normal, Diagnoser);
   }
 
+  /// Get the type of expression E, triggering instantiation to complete the
+  /// type if necessary -- that is, if the expression refers to a templated
+  /// static data member of incomplete array type.
+  ///
+  /// May still return an incomplete type if instantiation was not possible or
+  /// if the type is incomplete for a 
diff erent reason. Use
+  /// RequireCompleteExprType instead if a diagnostic is expected for an
+  /// incomplete expression type.
+  QualType getCompletedType(Expr *E);
+
   void completeExprArrayBound(Expr *E);
   bool RequireCompleteExprType(Expr *E, CompleteTypeKind Kind,
TypeDiagnoser &Diagnoser);

diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 38f6a5975ea3..f4493d84238d 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4264,7 +4264,7 @@ static void TryReferenceListInitialization(Sema &S,
   // bind to that.
   if (InitList->getNumInits() == 1) {
 Expr *Initializer = InitList->getInit(0);
-QualType cv2T2 = Initializer->getType();
+QualType cv2T2 = S.getCompletedType(Initializer);
 Qualifiers T2Quals;
 QualType T2 = S.Context.getUnqualifiedArrayType(cv2T2, T2Quals);
 
@@ -4700,7 +4700,7 @@ static void TryReferenceInitialization(Sema &S,
   QualType cv1T1 = DestType->castAs()->getPointeeType();
   Qualifiers T1Quals;
   QualType T1 = S.Context.getUnqualifiedArrayType(cv1T1, T1Quals);
-  QualType cv2T2 = Initializer->getType();
+  QualType cv2T2 = S.getCompletedType(Initializer);
   Qualifiers T2Quals;
   QualType T2 = S.Context.getUnqualifiedArrayType(cv2T2, T2Quals);
 

diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 4a3b64cf5425..ee4316e7a632 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3861,10 +3861,8 @@ static bool AdjustFunctionParmAndArgTypesForDeduction(
 
   if (ParamRefType) {
 // If the argument has incomplete array type, try to complete its type.
-if (ArgType->isIncompleteArrayType()) {
-  S.completeExprArrayBound(Arg);
-  ArgType = Arg->getType();
-}
+if (ArgType->isIncompleteArrayType())
+  ArgType = S.getCompletedType(Arg);
 
 // C++1z [temp.deduct.call]p3:
 //   If P is a forwarding reference and the argument is an lvalue, the type

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index fe775b82a1d6..8f2dd384b43b 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -8276,6 +8276,20 @@ void Sema::completeExprArrayBound(Expr *E) {
   }
 }
 
+QualType Sema::getCompletedType(Expr *E) {
+  // Incomplete array types may be completed by the initializer attached to
+  // their definitions. For static data members of class templates and for
+  // variable templates, we need to instantiate the definition to get this
+  // initializer and complete the type.
+  if (E->getType()->isIncompleteArrayType())
+completeExprArrayBound(E);
+
+  // FIXME: Are there other cases which require instantiating something other
+  // than the type to complete the type of an expression?
+
+  return E->getType();
+}
+
 /// Ensure that the type of the given expression is complete.
 ///
 /// This routine checks whether the expression \p E has a complete type. If the
@@ -8293,21 +8307,8 @@ void Sema::completeExprArrayBound(Expr *E) {
 /// otherwise.
 bool Sema::RequireCompleteExprType(Expr *E, CompleteTypeKind Kind,
TypeDiagnoser &Diagnoser) {
-  QualType T = E->getType();
-
-  // Incomplete array types may be completed by the initializer attached to
-  // their definitions. For static data members of class templates and for
-  // var

[llvm-branch-commits] [clang] aab25fa - Never call a destroying operator delete when cleaning up from an

2021-01-08 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2021-01-08T16:51:47-08:00
New Revision: aab25fa7d853d6da960607310e2cd3e3a843d5a9

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

LOG: Never call a destroying operator delete when cleaning up from an
exception thrown during construction in a new-expression.

Instead, when performing deallocation function lookup for a
new-expression, ignore all destroying operator delete candidates, and
fall back to global operator delete if there is no member operator
delete other than a destroying operator delete.

Use of destroying operator delete only makes sense when there is an
object to destroy, which there isn't in this case. The language wording
doesn't cover this case; this oversight has been reported to WG21, with
the approach in this patch as the proposed fix.

Added: 


Modified: 
clang/lib/Sema/SemaExprCXX.cpp
clang/test/CodeGenCXX/cxx2a-destroying-delete.cpp
clang/test/SemaCXX/cxx2a-destroying-delete.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 05b28c11e5a5..1ee52107c3da 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -2630,8 +2630,24 @@ bool Sema::FindAllocationFunctions(SourceLocation 
StartLoc, SourceRange Range,
   if (FoundDelete.isAmbiguous())
 return true; // FIXME: clean up expressions?
 
+  // Filter out any destroying operator deletes. We can't possibly call such a
+  // function in this context, because we're handling the case where the object
+  // was not successfully constructed.
+  // FIXME: This is not covered by the language rules yet.
+  {
+LookupResult::Filter Filter = FoundDelete.makeFilter();
+while (Filter.hasNext()) {
+  auto *FD = dyn_cast(Filter.next()->getUnderlyingDecl());
+  if (FD && FD->isDestroyingOperatorDelete())
+Filter.erase();
+}
+Filter.done();
+  }
+
   bool FoundGlobalDelete = FoundDelete.empty();
   if (FoundDelete.empty()) {
+FoundDelete.clear(LookupOrdinaryName);
+
 if (DeleteScope == AFS_Class)
   return true;
 

diff  --git a/clang/test/CodeGenCXX/cxx2a-destroying-delete.cpp 
b/clang/test/CodeGenCXX/cxx2a-destroying-delete.cpp
index ac0407d37e45..2fe489efdd90 100644
--- a/clang/test/CodeGenCXX/cxx2a-destroying-delete.cpp
+++ b/clang/test/CodeGenCXX/cxx2a-destroying-delete.cpp
@@ -1,11 +1,11 @@
-// RUN: %clang_cc1 -std=c++2a -emit-llvm %s -triple x86_64-linux-gnu -o - | 
FileCheck %s --check-prefixes=CHECK,CHECK-ITANIUM,CHECK-64BIT
-// RUN: %clang_cc1 -std=c++2a -emit-llvm %s -triple x86_64-windows -o - | 
FileCheck %s --check-prefixes=CHECK,CHECK-MSABI,CHECK-MSABI64,CHECK-64BIT
-// RUN: %clang_cc1 -std=c++2a -emit-llvm %s -triple i386-windows -o - | 
FileCheck %s --check-prefixes=CHECK,CHECK-MSABI,CHECK-MSABI32,CHECK-32BIT
+// RUN: %clang_cc1 -std=c++2a -fexceptions -emit-llvm %s -triple 
x86_64-linux-gnu -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-ITANIUM,CHECK-64BIT
+// RUN: %clang_cc1 -std=c++2a -fexceptions -emit-llvm %s -triple 
x86_64-windows -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-MSABI,CHECK-MSABI64,CHECK-64BIT
+// RUN: %clang_cc1 -std=c++2a -fexceptions -emit-llvm %s -triple i386-windows 
-o - | FileCheck %s --check-prefixes=CHECK,CHECK-MSABI,CHECK-MSABI32,CHECK-32BIT
 
 // PR46908: ensure the IR passes the verifier with optimizations enabled.
-// RUN: %clang_cc1 -std=c++2a -emit-llvm-only %s -triple x86_64-linux-gnu -O2
-// RUN: %clang_cc1 -std=c++2a -emit-llvm-only %s -triple x86_64-windows -O2
-// RUN: %clang_cc1 -std=c++2a -emit-llvm-only %s -triple i386-windows -O2
+// RUN: %clang_cc1 -std=c++2a -fexceptions -emit-llvm-only %s -triple 
x86_64-linux-gnu -O2
+// RUN: %clang_cc1 -std=c++2a -fexceptions -emit-llvm-only %s -triple 
x86_64-windows -O2
+// RUN: %clang_cc1 -std=c++2a -fexceptions -emit-llvm-only %s -triple 
i386-windows -O2
 
 namespace std {
   using size_t = decltype(sizeof(0));
@@ -102,6 +102,41 @@ void delete_D(D *d) { delete d; }
 // CHECK-NOT: call
 // CHECK: }
 
+struct J {
+  J(); // might throw
+  void operator delete(J *, std::destroying_delete_t);
+};
+
+// CHECK-ITANIUM-LABEL: define {{.*}}@_Z1j
+// CHECK-MSABI-LABEL: define {{.*}}@"?j@@
+J *j() {
+  // CHECK-ITANIUM: invoke {{.*}}@_ZN1JC1Ev(
+  // CHECK-ITANIUM: call {{.*}}@_ZdlPv(
+  // CHECK-NOT: }
+  // CHECK-MSABI: invoke {{.*}}@"??0J@@Q{{AE|EAA}}@XZ"(
+  // CHECK-MSABI: call {{.*}}@"??3@YAXP{{E?}}AX@Z"(
+  return new J;
+  // CHECK: }
+}
+
+struct K {
+  K(); // might throw
+  void operator delete(void *);
+  void operator delete(K *, std::destroying_delete_t);
+};
+
+// CHECK-ITANIUM-LABEL: define {{.*}}@_Z1k
+// CHECK-MSABI-LABEL: define {{.*}}@"?k@@
+K *k() {
+  // CHECK-ITANIUM: invoke {{.*}}@_ZN1KC1Ev(
+  // CHECK-ITANIUM: call {{.*}}@_ZN1KdlEPv(
+  /

[llvm-branch-commits] [clang] 9b222b1 - [c++20] Don't consider string literal operator templates for numeric

2021-01-11 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2021-01-11T13:19:00-08:00
New Revision: 9b222b108a2e37eb45d3156ec8554d148d658a8a

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

LOG: [c++20] Don't consider string literal operator templates for numeric
literals.

A literal interpretation of the standard wording allows this, but it was
never intended that string literal operator templates would be used for
anything other than user-defined string literals.

Added: 


Modified: 
clang/lib/Sema/SemaLookup.cpp
clang/test/SemaCXX/cxx2a-user-defined-literals.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 16dd8f5105961..29038ab9fe1ca 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -3384,6 +3384,13 @@ Sema::LookupLiteralOperator(Scope *S, LookupResult &R,
   TemplateParameterList *Params = FD->getTemplateParameters();
   if (Params->size() == 1) {
 IsTemplate = true;
+if (!Params->getParam(0)->isTemplateParameterPack() && !StringLit) {
+  // Implied but not stated: user-defined integer and floating literals
+  // only ever use numeric literal operator templates, not templates
+  // taking a parameter of class type.
+  F.erase();
+  continue;
+}
 
 // A string literal template is only considered if the string literal
 // is a well-formed template argument for the template parameter.

diff  --git a/clang/test/SemaCXX/cxx2a-user-defined-literals.cpp 
b/clang/test/SemaCXX/cxx2a-user-defined-literals.cpp
index d730eba741a88..12f672ff640a9 100644
--- a/clang/test/SemaCXX/cxx2a-user-defined-literals.cpp
+++ b/clang/test/SemaCXX/cxx2a-user-defined-literals.cpp
@@ -24,4 +24,33 @@ chrono::day bin_d = 0b011d;
 // expected-note@9{{candidate constructor (the implicit move constructor)}}
 chrono::day hex_d = 0x44d;
 chrono::year y  = 10y;
+
+namespace ignore_class_udl_for_numeric_literals {
+  struct A { constexpr A(const char*) {} };
+  struct B { constexpr B(char); };
+  struct C { constexpr C(int); };
+  template void operator""_a();
+  template void operator""_b();
+  template void operator""_c();
+  void test_class_udl_1() {
+1_a; // expected-error {{no matching}}
+1_b; // expected-error {{no matching}}
+1_c; // expected-error {{no matching}}
+"1"_a;
+"1"_b; // expected-error {{no matching}}
+"1"_c; // expected-error {{no matching}}
+  }
+  template void operator""_a();
+  template void operator""_b();
+  template void operator""_c();
+  void test_class_udl_2() {
+1_a;
+// FIXME: The standard appears to say these two are ambiguous!
+1_b;
+1_c;
+"1"_a;
+"1"_b; // expected-error {{no matching}}
+"1"_c; // expected-error {{no matching}}
+  }
+}
 #endif



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


[llvm-branch-commits] [clang] 6c365cd - Consider reference, pointer, and pointer-to-member TemplateArguments to be different if they have different types.

2020-12-15 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-12-15T12:00:57-08:00
New Revision: 6c365cd31e323d2d075573edd927e4f7fb5ec01c

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

LOG: Consider reference, pointer, and pointer-to-member TemplateArguments to be 
different if they have different types.

For the Itanium ABI, this implements the mangling rule suggested in
https://github.com/itanium-cxx-abi/cxx-abi/issues/47, namely mangling
such template arguments as being cast to the parameter type in the case
where the template name is overloadable. This can cause a mangling
change for rare cases, where

 * the template argument declaration is converted from its declared type
   to the type of the template parameter, and
 * the template parameter either has a deduced type or is a parameter of
   a function template.

However, such changes are necessary to avoid mangling collisions. The
ABI changes can be reversed with -fclang-abi-compat=11 or earlier.

Re-commit with a fix for a couple of regressions.

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

Added: 


Modified: 
clang/include/clang/Basic/LangOptions.h
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/AST/TemplateBase.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/test/CodeGenCXX/clang-abi-compat.cpp
clang/test/CodeGenCXX/mangle-class-nttp.cpp
clang/test/CodeGenCXX/mangle-template.cpp
clang/test/SemaTemplate/temp_arg_nontype.cpp
clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index be2c7a004e0b..ed9f729417af 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -158,8 +158,10 @@ class LangOptions : public LangOptionsBase {
 
 /// Attempt to be ABI-compatible with code generated by Clang 11.0.x
 /// (git  2e10b7a39b93). This causes clang to pass unions with a 256-bit
-/// vector member on the stack instead of using registers, and to not
-/// properly mangle substitutions for template names in some cases.
+/// vector member on the stack instead of using registers, to not properly
+/// mangle substitutions for template names in some cases, and to mangle
+/// declaration template arguments without a cast to the parameter type
+/// even when that can lead to mangling collisions.
 Ver11,
 
 /// Conform to the underlying platform's C and C++ ABIs as closely

diff  --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index f5a4f6708c83..f2e9bc727ac6 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -551,13 +551,15 @@ class CXXNameMangler {
   void mangleCXXCtorType(CXXCtorType T, const CXXRecordDecl *InheritedFrom);
   void mangleCXXDtorType(CXXDtorType T);
 
-  void mangleTemplateArgs(const TemplateArgumentLoc *TemplateArgs,
+  void mangleTemplateArgs(TemplateName TN,
+  const TemplateArgumentLoc *TemplateArgs,
   unsigned NumTemplateArgs);
-  void mangleTemplateArgs(const TemplateArgument *TemplateArgs,
+  void mangleTemplateArgs(TemplateName TN, const TemplateArgument 
*TemplateArgs,
   unsigned NumTemplateArgs);
-  void mangleTemplateArgs(const TemplateArgumentList &AL);
-  void mangleTemplateArg(TemplateArgument A);
-  void mangleValueInTemplateArg(QualType T, const APValue &V);
+  void mangleTemplateArgs(TemplateName TN, const TemplateArgumentList &AL);
+  void mangleTemplateArg(TemplateArgument A, bool NeedExactType);
+  void mangleValueInTemplateArg(QualType T, const APValue &V, bool TopLevel,
+bool NeedExactType = false);
 
   void mangleTemplateParameter(unsigned Depth, unsigned Index);
 
@@ -823,6 +825,11 @@ isTemplate(GlobalDecl GD, const TemplateArgumentList 
*&TemplateArgs) {
   return GlobalDecl();
 }
 
+static TemplateName asTemplateName(GlobalDecl GD) {
+  const TemplateDecl *TD = dyn_cast_or_null(GD.getDecl());
+  return TemplateName(const_cast(TD));
+}
+
 void CXXNameMangler::mangleName(GlobalDecl GD) {
   const NamedDecl *ND = cast(GD.getDecl());
   if (const VarDecl *VD = dyn_cast(ND)) {
@@ -899,7 +906,7 @@ void CXXNameMangler::mangleNameWithAbiTags(GlobalDecl GD,
 const TemplateArgumentList *TemplateArgs = nullptr;
 if (GlobalDecl TD = isTemplate(GD, TemplateArgs)) {
   mangleUnscopedTemplateName(TD, AdditionalAbiTags);
-  mangleTemplateArgs(*TemplateArgs);
+  mangleTemplateArgs(asTemplateName(TD), *TemplateArgs);
   return;
 }
 
@@ -952,7 +959,7 @@ void CXXNameMangler::mangleTemplateName(const TemplateDecl 
*TD,
 
   if (DC->isTranslationUnit() || isStdNamespace(DC)) {
 mangleUnsco

[llvm-branch-commits] [clang] 76edf98 - Set decl on DeclRefExpr directly during deserialization rather than

2020-12-15 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-12-15T12:00:57-08:00
New Revision: 76edf98b27c45f1aa26c1972927ce1638cda50fd

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

LOG: Set decl on DeclRefExpr directly during deserialization rather than
relying on a setter that might have additional side-effects. NFC.

Added: 


Modified: 
clang/lib/Serialization/ASTReaderStmt.cpp

Removed: 




diff  --git a/clang/lib/Serialization/ASTReaderStmt.cpp 
b/clang/lib/Serialization/ASTReaderStmt.cpp
index 8b9d4a127691..0e1af53303b4 100644
--- a/clang/lib/Serialization/ASTReaderStmt.cpp
+++ b/clang/lib/Serialization/ASTReaderStmt.cpp
@@ -614,7 +614,7 @@ void ASTStmtReader::VisitDeclRefExpr(DeclRefExpr *E) {
 *E->getTrailingObjects(),
 E->getTrailingObjects(), NumTemplateArgs);
 
-  E->setDecl(readDeclAs());
+  E->D = readDeclAs();
   E->setLocation(readSourceLocation());
   E->DNLoc = Record.readDeclarationNameLoc(E->getDecl()->getDeclName());
 }



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


[llvm-branch-commits] [clang] c4736b9 - Don't memcpy from an empty ArrayRef; the base pointer could be null, and

2020-12-15 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-12-15T14:37:52-08:00
New Revision: c4736b91f87e9163edcdef78891398f32390ffc2

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

LOG: Don't memcpy from an empty ArrayRef; the base pointer could be null, and
the C rules say memcpy can't accept a null pointer.

This should fix a test failure with the ubsan buildbots.

Added: 


Modified: 
clang/lib/AST/APValue.cpp

Removed: 




diff  --git a/clang/lib/AST/APValue.cpp b/clang/lib/AST/APValue.cpp
index 5b340e6e85bd..c18f8854dc2b 100644
--- a/clang/lib/AST/APValue.cpp
+++ b/clang/lib/AST/APValue.cpp
@@ -952,8 +952,10 @@ void APValue::setLValue(LValueBase B, const CharUnits &O,
 bool IsNullPtr) {
   MutableArrayRef InternalPath =
   setLValueUninit(B, O, Path.size(), IsOnePastTheEnd, IsNullPtr);
-  memcpy(InternalPath.data(), Path.data(),
- Path.size() * sizeof(LValuePathEntry));
+  if (Path.size()) {
+memcpy(InternalPath.data(), Path.data(),
+   Path.size() * sizeof(LValuePathEntry));
+  }
 }
 
 void APValue::setUnion(const FieldDecl *Field, const APValue &Value) {



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


[llvm-branch-commits] [clang] 6b760a5 - DR2100: &expr is value-dependent if expr constant-evaluates to a

2020-12-15 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-12-15T14:53:26-08:00
New Revision: 6b760a50f52142e401a6380ff71f933cda22a909

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

LOG: DR2100: &expr is value-dependent if expr constant-evaluates to a
dependent declaration.

Added: 


Modified: 
clang/include/clang/AST/ComputeDependence.h
clang/lib/AST/ComputeDependence.cpp
clang/lib/AST/Expr.cpp
clang/test/CXX/drs/dr21xx.cpp
clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/include/clang/AST/ComputeDependence.h 
b/clang/include/clang/AST/ComputeDependence.h
index 6af0e4604b63..04e8e2c7d2cc 100644
--- a/clang/include/clang/AST/ComputeDependence.h
+++ b/clang/include/clang/AST/ComputeDependence.h
@@ -107,7 +107,7 @@ class ObjCMessageExpr;
 ExprDependence computeDependence(FullExpr *E);
 ExprDependence computeDependence(OpaqueValueExpr *E);
 ExprDependence computeDependence(ParenExpr *E);
-ExprDependence computeDependence(UnaryOperator *E);
+ExprDependence computeDependence(UnaryOperator *E, const ASTContext &Ctx);
 ExprDependence computeDependence(UnaryExprOrTypeTraitExpr *E);
 ExprDependence computeDependence(ArraySubscriptExpr *E);
 ExprDependence computeDependence(MatrixSubscriptExpr *E);

diff  --git a/clang/lib/AST/ComputeDependence.cpp 
b/clang/lib/AST/ComputeDependence.cpp
index d837ae29cb54..79e3b3b099fc 100644
--- a/clang/lib/AST/ComputeDependence.cpp
+++ b/clang/lib/AST/ComputeDependence.cpp
@@ -37,9 +37,38 @@ ExprDependence clang::computeDependence(ParenExpr *E) {
   return E->getSubExpr()->getDependence();
 }
 
-ExprDependence clang::computeDependence(UnaryOperator *E) {
-  return toExprDependence(E->getType()->getDependence()) |
- E->getSubExpr()->getDependence();
+ExprDependence clang::computeDependence(UnaryOperator *E,
+const ASTContext &Ctx) {
+  ExprDependence Dep = toExprDependence(E->getType()->getDependence()) |
+   E->getSubExpr()->getDependence();
+
+  // C++ [temp.dep.constexpr]p5:
+  //   An expression of the form & qualified-id where the qualified-id names a
+  //   dependent member of the current instantiation is value-dependent. An
+  //   expression of the form & cast-expression is also value-dependent if
+  //   evaluating cast-expression as a core constant expression succeeds and
+  //   the result of the evaluation refers to a templated entity that is an
+  //   object with static or thread storage duration or a member function.
+  //
+  // What this amounts to is: constant-evaluate the operand and check whether 
it
+  // refers to a templated entity other than a variable with local storage.
+  if (Ctx.getLangOpts().CPlusPlus11 && E->getOpcode() == UO_AddrOf &&
+  !(Dep & ExprDependence::Value)) {
+Expr::EvalResult Result;
+SmallVector Diag;
+Result.Diag = &Diag;
+if (E->getSubExpr()->EvaluateAsConstantExpr(Result, Ctx) && Diag.empty() &&
+Result.Val.isLValue()) {
+  auto *VD = Result.Val.getLValueBase().dyn_cast();
+  if (VD && VD->isTemplated()) {
+auto *VarD = dyn_cast(VD);
+if (!VarD || !VarD->hasLocalStorage())
+  Dep |= ExprDependence::Value;
+  }
+}
+  }
+
+  return Dep;
 }
 
 ExprDependence clang::computeDependence(UnaryExprOrTypeTraitExpr *E) {

diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 1bd032a04a51..50beeb5cabb1 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -4422,7 +4422,7 @@ UnaryOperator::UnaryOperator(const ASTContext &Ctx, Expr 
*input, Opcode opc,
   UnaryOperatorBits.HasFPFeatures = FPFeatures.requiresTrailingStorage();
   if (hasStoredFPFeatures())
 setStoredFPFeatures(FPFeatures);
-  setDependence(computeDependence(this));
+  setDependence(computeDependence(this, Ctx));
 }
 
 UnaryOperator *UnaryOperator::Create(const ASTContext &C, Expr *input,

diff  --git a/clang/test/CXX/drs/dr21xx.cpp b/clang/test/CXX/drs/dr21xx.cpp
index 6810944cde65..98593e543e72 100644
--- a/clang/test/CXX/drs/dr21xx.cpp
+++ b/clang/test/CXX/drs/dr21xx.cpp
@@ -8,6 +8,31 @@
 #define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
 #endif
 
+namespace dr2100 { // dr2100: 12
+  template struct X {};
+  template struct A {
+static const int n = 1;
+int f() {
+  return X<&n>::n; // ok, value-dependent
+}
+int g() {
+  static const int n = 2;
+  return X<&n>::n; // ok, value-dependent
+#if __cplusplus < 201702L
+  // expected-error@-2 {{does not have linkage}} expected-note@-3 {{here}}
+#endif
+}
+  };
+  template struct X {
+#if __cplusplus < 201103L
+static const int n = 0;
+#else
+static const int n = *P;
+#endif
+  };
+  int q = A().f() + A().g();
+}
+
 na

[llvm-branch-commits] [clang] 7e7f38f - DR1413 and part of P1815R2: Minor improvements to Clang's determination

2020-12-15 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-12-15T14:53:26-08:00
New Revision: 7e7f38f853fbf96c6ab2a0e5f9d7747ef8a76ffe

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

LOG: DR1413 and part of P1815R2: Minor improvements to Clang's determination
of type- and value-dependency.

A static data member initialized to a constant inside a class template
is no longer considered value-dependent, per DR1413. A const but not
constexpr variable of literal type (other than integer or enumeration)
is no longer considered value-dependent, per P1815R2.

Added: 


Modified: 
clang/include/clang/AST/Decl.h
clang/lib/AST/ComputeDependence.cpp
clang/test/CXX/drs/dr14xx.cpp
clang/test/CXX/drs/dr21xx.cpp
clang/test/CXX/drs/dr2xx.cpp
clang/test/CXX/temp/temp.res/temp.dep/temp.dep.constexpr/p2-0x.cpp
clang/test/SemaCXX/typedef-redecl.cpp
clang/test/SemaCXX/vector.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 7f6f143aa866..ab24c8779df2 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -1262,6 +1262,9 @@ class VarDecl : public DeclaratorDecl, public 
Redeclarable {
   /// constant expression, according to the relevant language standard.
   /// This only checks properties of the declaration, and does not check
   /// whether the initializer is in fact a constant expression.
+  ///
+  /// This corresponds to C++20 [expr.const]p3's notion of a
+  /// "potentially-constant" variable.
   bool mightBeUsableInConstantExpressions(const ASTContext &C) const;
 
   /// Determine whether this variable's value can be used in a

diff  --git a/clang/lib/AST/ComputeDependence.cpp 
b/clang/lib/AST/ComputeDependence.cpp
index 79e3b3b099fc..4026fdc76fd6 100644
--- a/clang/lib/AST/ComputeDependence.cpp
+++ b/clang/lib/AST/ComputeDependence.cpp
@@ -52,11 +52,12 @@ ExprDependence clang::computeDependence(UnaryOperator *E,
   //
   // What this amounts to is: constant-evaluate the operand and check whether 
it
   // refers to a templated entity other than a variable with local storage.
-  if (Ctx.getLangOpts().CPlusPlus11 && E->getOpcode() == UO_AddrOf &&
+  if (Ctx.getLangOpts().CPlusPlus && E->getOpcode() == UO_AddrOf &&
   !(Dep & ExprDependence::Value)) {
 Expr::EvalResult Result;
 SmallVector Diag;
 Result.Diag = &Diag;
+// FIXME: This doesn't enforce the C++98 constant expression rules.
 if (E->getSubExpr()->EvaluateAsConstantExpr(Result, Ctx) && Diag.empty() &&
 Result.Val.isLValue()) {
   auto *VD = Result.Val.getLValueBase().dyn_cast();
@@ -452,22 +453,21 @@ ExprDependence clang::computeDependence(DeclRefExpr *E, 
const ASTContext &Ctx) {
 Deps |= ExprDependence::UnexpandedPack;
   Deps |= toExprDependence(Type->getDependence()) & ExprDependence::Error;
 
-  // (TD) C++ [temp.dep.expr]p3:
+  // C++ [temp.dep.expr]p3:
   //   An id-expression is type-dependent if it contains:
-  //
-  // and
-  //
-  // (VD) C++ [temp.dep.constexpr]p2:
-  //  An identifier is value-dependent if it is:
 
-  //  (TD)  - an identifier that was declared with dependent type
-  //  (VD)  - a name declared with a dependent type,
+  //- an identifier associated by name lookup with one or more declarations
+  //  declared with a dependent type
+  //
+  // [The "or more" case is not modeled as a DeclRefExpr. There are a bunch
+  // more bullets here that we handle by treating the declaration as having a
+  // dependent type if they involve a placeholder type that can't be deduced.]
   if (Type->isDependentType())
 return Deps | ExprDependence::TypeValueInstantiation;
   else if (Type->isInstantiationDependentType())
 Deps |= ExprDependence::Instantiation;
 
-  //  (TD)  - a conversion-function-id that specifies a dependent type
+  //- a conversion-function-id that specifies a dependent type
   if (Decl->getDeclName().getNameKind() ==
   DeclarationName::CXXConversionFunctionName) {
 QualType T = Decl->getDeclName().getCXXNameType();
@@ -478,23 +478,28 @@ ExprDependence clang::computeDependence(DeclRefExpr *E, 
const ASTContext &Ctx) {
   Deps |= ExprDependence::Instantiation;
   }
 
-  //  (VD)  - the name of a non-type template parameter,
+  //   - a template-id that is dependent,
+  //   - a nested-name-specifier or a qualified-id that names a member of an
+  // unknown specialization
+  //   [These are not modeled as DeclRefExprs.]
+
+  //   or if it names a dependent member of the current instantiation that is a
+  //   static data member of type "array of unknown bound of T" for some T
+  //   [handled below].
+
+  // C++ [temp.dep.constexpr]p2:
+  //  An id-expression is value-dependent if:
+
+  //- it is type-dependent 

[llvm-branch-commits] [clang] 735ab86 - PR47474: Add test for Clang's current behavior.

2020-12-16 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-12-16T12:01:00-08:00
New Revision: 735ab86b811e40f1533ced98dfc4b7a0c09c545b

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

LOG: PR47474: Add test for Clang's current behavior.

Our current behavior rejects the example, following the current language
rules, but it's likely the rules will be revised to allow this example.

Added: 


Modified: 
clang/test/SemaCXX/cxx2a-destroying-delete.cpp

Removed: 




diff  --git a/clang/test/SemaCXX/cxx2a-destroying-delete.cpp 
b/clang/test/SemaCXX/cxx2a-destroying-delete.cpp
index 015d11e65526..46e5228ec6be 100644
--- a/clang/test/SemaCXX/cxx2a-destroying-delete.cpp
+++ b/clang/test/SemaCXX/cxx2a-destroying-delete.cpp
@@ -141,3 +141,29 @@ namespace templated {
 void operator delete(typename id_struct::type *, 
std::destroying_delete_t); // expected-error {{use 'D *'}}
   };
 }
+
+namespace dtor_access {
+  struct S {
+void operator delete(S *p, std::destroying_delete_t);
+  private:
+~S(); // expected-note {{here}}
+  };
+
+  // FIXME: PR47474: GCC accepts this, and it seems somewhat reasonable to
+  // allow, even though [expr.delete]p12 says this is ill-formed.
+  void f() { delete new S; } // expected-error {{calling a private destructor}}
+
+  struct T {
+void operator delete(T *, std::destroying_delete_t);
+  protected:
+virtual ~T(); // expected-note {{here}}
+  };
+
+  struct U : T {
+void operator delete(void *);
+  private:
+~U() override;
+  };
+
+  void g() { delete (T *)new U; } // expected-error {{calling a protected 
destructor}}
+}



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


[llvm-branch-commits] [clang] e53b9f7 - Print source location in the error message when parens are missing around sizeof typename and the expression is inside macro expansion

2020-12-16 Thread Richard Smith via llvm-branch-commits

Author: Shivanshu Goyal
Date: 2020-12-16T12:03:31-08:00
New Revision: e53b9f733a7cb0a5da372b73ab6b7711c0300d65

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

LOG: Print source location in the error message when parens are missing around 
sizeof typename and the expression is inside macro expansion

Given the following code:

```
void Foo(int);

void Baz()
{
Bar(sizeof int);
}
```

The error message which is printed today is this:
```
error: expected parentheses around type name in sizeof expression
```

There is no source location printed whatsoever, so fixing a compile break like 
this becomes extremely hard in a large codebase.

My change improves the error message. But it doesn't output a FixItHint because 
I wasn't able to figure out how to get the locations for left and right parens. 
So any tips would be appreciated.

```
:7:6: error: expected parentheses around type name in sizeof expression
Bar(sizeof int);
^
```

Reviewed By: rsmith

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

Added: 
clang/test/Parser/sizeof-missing-parens.c

Modified: 
clang/lib/Parse/ParseExpr.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index d993d9ce4bdb..6acf76d713fd 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -2266,10 +2266,15 @@ Parser::ParseExprAfterUnaryExprOrTypeTrait(const Token 
&OpTok,
 
 SourceLocation LParenLoc = PP.getLocForEndOfToken(OpTok.getLocation());
 SourceLocation RParenLoc = PP.getLocForEndOfToken(PrevTokLocation);
-Diag(LParenLoc, diag::err_expected_parentheses_around_typename)
-  << OpTok.getName()
-  << FixItHint::CreateInsertion(LParenLoc, "(")
-  << FixItHint::CreateInsertion(RParenLoc, ")");
+if (LParenLoc.isInvalid() || RParenLoc.isInvalid()) {
+  Diag(OpTok.getLocation(),
+   diag::err_expected_parentheses_around_typename)
+  << OpTok.getName();
+} else {
+  Diag(LParenLoc, diag::err_expected_parentheses_around_typename)
+  << OpTok.getName() << FixItHint::CreateInsertion(LParenLoc, "(")
+  << FixItHint::CreateInsertion(RParenLoc, ")");
+}
 isCastExpr = true;
 return ExprEmpty();
   }

diff  --git a/clang/test/Parser/sizeof-missing-parens.c 
b/clang/test/Parser/sizeof-missing-parens.c
new file mode 100644
index ..527f74151be1
--- /dev/null
+++ b/clang/test/Parser/sizeof-missing-parens.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void Foo(int);
+
+#define Bar(x) Foo(x)
+
+void Baz() {
+  Foo(sizeof int); // expected-error {{expected parentheses around type name 
in sizeof expression}}
+  Bar(sizeof int); // expected-error {{expected parentheses around type name 
in sizeof expression}}
+}



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


[llvm-branch-commits] [clang] d3bf0bb - PR24076, PR33655, C++ CWG 1558: Consider the instantiation-dependence of

2020-12-17 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-12-17T21:31:23-08:00
New Revision: d3bf0bb18952d830fe6df6f791a64552b271000b

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

LOG: PR24076, PR33655, C++ CWG 1558: Consider the instantiation-dependence of
the nested-name-specifier when determining whether a qualified type is
instantiation-dependent.

Added: 
clang/test/SemaTemplate/instantiation-dependence.cpp

Modified: 
clang/include/clang/AST/Type.h
clang/lib/AST/ItaniumMangle.cpp
clang/test/CXX/drs/dr15xx.cpp
clang/test/CodeGenCXX/mangle-template.cpp
clang/test/SemaTemplate/partial-spec-instantiate.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 945ea7a600c0..a3059b83c1be 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -5398,7 +5398,9 @@ class ElaboratedType final
   ElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
  QualType NamedType, QualType CanonType, TagDecl *OwnedTagDecl)
   : TypeWithKeyword(Keyword, Elaborated, CanonType,
-NamedType->getDependence()),
+NamedType->getDependence() |
+(NNS ? toTypeDependence(NNS->getDependence())
+ : TypeDependence::None)),
 NNS(NNS), NamedType(NamedType) {
 ElaboratedTypeBits.HasOwnedTagDecl = false;
 if (OwnedTagDecl) {

diff  --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 73c8f17a5d36..6c8d5687c64a 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -2578,6 +2578,10 @@ void CXXNameMangler::mangleType(QualType T) {
 if (!TST->isTypeAlias())
   break;
 
+  // FIXME: We presumably shouldn't strip off ElaboratedTypes with
+  // instantation-dependent qualifiers. See
+  // https://github.com/itanium-cxx-abi/cxx-abi/issues/114.
+
   QualType Desugared
 = T.getSingleStepDesugaredType(Context.getASTContext());
   if (Desugared == T)

diff  --git a/clang/test/CXX/drs/dr15xx.cpp b/clang/test/CXX/drs/dr15xx.cpp
index 478a0d7d00dd..8bfa29a8b667 100644
--- a/clang/test/CXX/drs/dr15xx.cpp
+++ b/clang/test/CXX/drs/dr15xx.cpp
@@ -239,6 +239,20 @@ namespace dr1550 { // dr1550: yes
   }
 }
 
+namespace dr1558 { // dr1558: 12
+#if __cplusplus >= 201103L
+  template using first_of = T;
+  template first_of f(int); // expected-note 
{{'int' cannot be used prior to '::'}}
+  template void f(...) = delete; // expected-note {{deleted}}
+
+  struct X { typedef void type; };
+  void test() {
+f(0);
+f(0); // expected-error {{deleted}}
+  }
+#endif
+}
+
 namespace dr1560 { // dr1560: 3.5
   void f(bool b, int n) {
 (b ? throw 0 : n) = (b ? n : throw 0) = 0;

diff  --git a/clang/test/CodeGenCXX/mangle-template.cpp 
b/clang/test/CodeGenCXX/mangle-template.cpp
index 9b5220572c2e..40688de7e12e 100644
--- a/clang/test/CodeGenCXX/mangle-template.cpp
+++ b/clang/test/CodeGenCXX/mangle-template.cpp
@@ -342,3 +342,23 @@ namespace fixed_size_parameter_pack {
   template void f(A::B<0, Ns...>);
   void g() { f<1, 2>({}); }
 }
+
+namespace type_qualifier {
+  template using int_t = int;
+  template void f(decltype(int_t() + 1)) {}
+  // FIXME: This mangling doesn't work: we need to mangle the
+  // instantiation-dependent 'int_t' operand.
+  // CHECK: @_ZN14type_qualifier1fIPiEEvDTplcvi_ELi1EE
+  template void f(int);
+
+  // Note that this template has 
diff erent constraints but would mangle the
+  // same:
+  //template void f(decltype(int_t() + 1)) {}
+
+  struct impl { using type = void; };
+  template using alias = impl;
+  template void g(decltype(alias::type(), 1)) {}
+  // FIXME: Similarly we need to mangle the `T*` in here.
+  // CHECK: @_ZN14type_qualifier1gIPiEEvDTcmcvv_ELi1EE
+  template void g(int);
+}

diff  --git a/clang/test/SemaTemplate/instantiation-dependence.cpp 
b/clang/test/SemaTemplate/instantiation-dependence.cpp
new file mode 100644
index ..75eb510cb68d
--- /dev/null
+++ b/clang/test/SemaTemplate/instantiation-dependence.cpp
@@ -0,0 +1,74 @@
+// RUN: %clang_cc1 -std=c++2b -verify %s
+
+// Ensure we substitute into instantiation-dependent but non-dependent
+// constructs. The poster-child for this is...
+template using void_t = void;
+
+namespace PR24076 {
+  template T declval();
+  struct s {};
+
+  template() + 1)>>
+void foo(T) {} // expected-note {{invalid operands to binary expression}}
+
+  void f() {
+foo(s{}); // expected-error {{no matching function}}
+  }
+
+  template() + 1)>> // expected-error 
{{invalid operands to binary expression}}
+  struct bar {};
+
+  bar bar; // expected-note {{in instantiation of}}
+}

[llvm-branch-commits] [clang] 638867a - DR2064: decltype(E) is only a dependent type if E is type-dependent, not

2020-12-17 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-12-17T23:23:05-08:00
New Revision: 638867afd4bce4a2c56dea041299428af3727d61

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

LOG: DR2064: decltype(E) is only a dependent type if E is type-dependent, not
if E is merely instantiation-dependent.

Added: 


Modified: 
clang/include/clang/AST/DependenceFlags.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/Type.cpp
clang/test/CXX/drs/dr20xx.cpp
clang/test/Sema/invalid-bitwidth-expr.mm
clang/test/SemaCXX/invalid-template-base-specifier.cpp
clang/test/SemaTemplate/dependent-expr.cpp
clang/test/SemaTemplate/temp_arg_template_cxx1z.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/include/clang/AST/DependenceFlags.h 
b/clang/include/clang/AST/DependenceFlags.h
index ca96b65574bd..8c47047a7526 100644
--- a/clang/include/clang/AST/DependenceFlags.h
+++ b/clang/include/clang/AST/DependenceFlags.h
@@ -255,6 +255,12 @@ inline TypeDependence 
toTypeDependence(TemplateNameDependence D) {
 inline TypeDependence toTypeDependence(TemplateArgumentDependence D) {
   return Dependence(D).type();
 }
+/// Compute the dependence of a type that depends on the type of an expression,
+/// given the dependence of that expression and of its type.
+inline TypeDependence typeToTypeDependence(ExprDependence ED, TypeDependence 
TD) {
+  return Dependence(ED & ~ExprDependence::Value).type() |
+ (TD & TypeDependence::VariablyModified);
+}
 
 inline NestedNameSpecifierDependence
 toNestedNameSpecifierDependendence(TypeDependence D) {

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 44545f00b146..0190573fe36e 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -5383,10 +5383,10 @@ QualType ASTContext::getDecltypeType(Expr *e, QualType 
UnderlyingType) const {
   DecltypeType *dt;
 
   // C++11 [temp.type]p2:
-  //   If an expression e involves a template parameter, decltype(e) denotes a
-  //   unique dependent type. Two such decltype-specifiers refer to the same
-  //   type only if their expressions are equivalent (14.5.6.1).
-  if (e->isInstantiationDependent()) {
+  //   If an expression e is type-dependent, decltype(e) denotes a unique
+  //   dependent type. Two such decltype-specifiers refer to the same type only
+  //   if their expressions are equivalent (14.5.6.1).
+  if (e->isTypeDependent()) {
 llvm::FoldingSetNodeID ID;
 DependentDecltypeType::Profile(ID, *this, e);
 

diff  --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 6c8d5687c64a..01deb598a078 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -2582,6 +2582,11 @@ void CXXNameMangler::mangleType(QualType T) {
   // instantation-dependent qualifiers. See
   // https://github.com/itanium-cxx-abi/cxx-abi/issues/114.
 
+  // Don't desugar instantiation-dependent decltype / typeof types. We need
+  // to mangle the expression as written.
+  if (isa(T))
+break;
+
   QualType Desugared
 = T.getSingleStepDesugaredType(Context.getASTContext());
   if (Desugared == T)

diff  --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index af39b80ef9e4..e5811dbc44c5 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -125,8 +125,7 @@ ArrayType::ArrayType(TypeClass tc, QualType et, QualType 
can,
 //   template int arr[] = {N...};
 : Type(tc, can,
et->getDependence() |
-   (sz ? toTypeDependence(
- turnValueToTypeDependence(sz->getDependence()))
+   (sz ? toTypeDependence(sz->getDependence())
: TypeDependence::None) |
(tc == VariableArray ? TypeDependence::VariablyModified
 : TypeDependence::None) |
@@ -3396,9 +3395,8 @@ QualType MacroQualifiedType::getModifiedType() const {
 
 TypeOfExprType::TypeOfExprType(Expr *E, QualType can)
 : Type(TypeOfExpr, can,
-   toTypeDependence(E->getDependence()) |
-   (E->getType()->getDependence() &
-TypeDependence::VariablyModified)),
+   typeToTypeDependence(E->getDependence(),
+E->getType()->getDependence())),
   TOExpr(E) {}
 
 bool TypeOfExprType::isSugared() const {
@@ -3418,18 +3416,12 @@ void 
DependentTypeOfExprType::Profile(llvm::FoldingSetNodeID &ID,
 }
 
 DecltypeType::DecltypeType(Expr *E, QualType underlyingType, QualType can)
-// C++11 [temp.type]p2: "If an expression e involves a template parameter,
-// decltype(e) denotes a unique dependent type." Hence a decltype type is
-// type-dependent even if its expression is o

[llvm-branch-commits] [clang] 71886c5 - Where possible, don't try to ask whether a template argument is

2020-12-17 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-12-17T23:23:05-08:00
New Revision: 71886c56f336667969be4cac0b6a17a3f75b7555

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

LOG: Where possible, don't try to ask whether a template argument is
dependent until it's been converted to match its parameter.

The type of a non-type template parameter can in general affect whether
the template argument is dependent.

Note that this is not always possible. For template arguments that name
static local variables in templates, the type of the template parameter
affects whether the argument is dependent, so the query is imprecise
until we know the parameter type. For example, in:

template void f() {
  static const int n = 5;
  typename T::template X x;
}

... we don't know whether 'n' is dependent until we know whether the
corresponding template parameter is of type 'int' or 'const int&'.

Added: 
clang/test/SemaTemplate/instantiate-static-local.cpp

Modified: 
clang/include/clang/AST/Type.h
clang/lib/AST/Type.cpp
clang/lib/Sema/SemaConcept.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaTemplate.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index a3059b83c1be..21c8bf79152e 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -5112,11 +5112,24 @@ class alignas(8) TemplateSpecializationType
 
 public:
   /// Determine whether any of the given template arguments are dependent.
-  static bool anyDependentTemplateArguments(ArrayRef Args,
-bool &InstantiationDependent);
-
-  static bool anyDependentTemplateArguments(const TemplateArgumentListInfo &,
-bool &InstantiationDependent);
+  ///
+  /// The converted arguments should be supplied when known; whether an
+  /// argument is dependent can depend on the conversions performed on it
+  /// (for example, a 'const int' passed as a template argument might be
+  /// dependent if the parameter is a reference but non-dependent if the
+  /// parameter is an int).
+  ///
+  /// Note that the \p Args parameter is unused: this is intentional, to remind
+  /// the caller that they need to pass in the converted arguments, not the
+  /// specified arguments.
+  static bool
+  anyDependentTemplateArguments(ArrayRef Args,
+ArrayRef Converted);
+  static bool
+  anyDependentTemplateArguments(const TemplateArgumentListInfo &,
+ArrayRef Converted);
+  static bool anyInstantiationDependentTemplateArguments(
+  ArrayRef Args);
 
   /// True if this template specialization type matches a current
   /// instantiation in the context in which it is found.

diff  --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index e5811dbc44c5..5dec80be9ccb 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -3590,24 +3590,24 @@ void 
SubstTemplateTypeParmPackType::Profile(llvm::FoldingSetNodeID &ID,
 ID.AddPointer(P.getAsType().getAsOpaquePtr());
 }
 
-bool TemplateSpecializationType::
-anyDependentTemplateArguments(const TemplateArgumentListInfo &Args,
-  bool &InstantiationDependent) {
-  return anyDependentTemplateArguments(Args.arguments(),
-   InstantiationDependent);
+bool TemplateSpecializationType::anyDependentTemplateArguments(
+const TemplateArgumentListInfo &Args, ArrayRef 
Converted) {
+  return anyDependentTemplateArguments(Args.arguments(), Converted);
 }
 
-bool TemplateSpecializationType::
-anyDependentTemplateArguments(ArrayRef Args,
-  bool &InstantiationDependent) {
-  for (const TemplateArgumentLoc &ArgLoc : Args) {
-if (ArgLoc.getArgument().isDependent()) {
-  InstantiationDependent = true;
+bool TemplateSpecializationType::anyDependentTemplateArguments(
+ArrayRef Args, ArrayRef Converted) {
+  for (const TemplateArgument &Arg : Converted)
+if (Arg.isDependent())
   return true;
-}
+  return false;
+}
 
+bool TemplateSpecializationType::anyInstantiationDependentTemplateArguments(
+  ArrayRef Args) {
+  for (const TemplateArgumentLoc &ArgLoc : Args) {
 if (ArgLoc.getArgument().isInstantiationDependent())
-  InstantiationDependent = true;
+  return true;
   }
   return false;
 }

diff  --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index ddd95faebe99..1ff7b1cdd515 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -1053,25 +1053,20 @@ ReturnTypeRequirement(TemplateParameterList *TPL) :
   auto *Constraint =
   cast_or_null(
   TC->getImmediatelyDeclaredConstraint());
-  bool Dependent = false;
- 

[llvm-branch-commits] [clang] 4b38885 - Ensure that we transform types into the current instantiation even if

2020-12-17 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-12-17T23:23:05-08:00
New Revision: 4b388859f527f822a27bcee409242c421f199f1d

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

LOG: Ensure that we transform types into the current instantiation even if
they're only instantiation-dependent.

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/test/SemaTemplate/class-template-decl.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 2b6eb397b82b..949df53b40e0 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -5491,7 +5491,7 @@ static bool RebuildDeclaratorInCurrentInstantiation(Sema 
&S, Declarator &D,
 // Grab the type from the parser.
 TypeSourceInfo *TSI = nullptr;
 QualType T = S.GetTypeFromParser(DS.getRepAsType(), &TSI);
-if (T.isNull() || !T->isDependentType()) break;
+if (T.isNull() || !T->isInstantiationDependentType()) break;
 
 // Make sure there's a type source info.  This isn't really much
 // of a waste; most dependent types should have type source info

diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index dd361ec91abe..64259767d98a 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -10730,7 +10730,7 @@ namespace {
 /// For the purposes of type reconstruction, a type has already been
 /// transformed if it is NULL or if it is not dependent.
 bool AlreadyTransformed(QualType T) {
-  return T.isNull() || !T->isDependentType();
+  return T.isNull() || !T->isInstantiationDependentType();
 }
 
 /// Returns the location of the entity whose type is being
@@ -10783,7 +10783,7 @@ namespace {
 TypeSourceInfo *Sema::RebuildTypeInCurrentInstantiation(TypeSourceInfo *T,
 SourceLocation Loc,
 DeclarationName Name) {
-  if (!T || !T->getType()->isDependentType())
+  if (!T || !T->getType()->isInstantiationDependentType())
 return T;
 
   CurrentInstantiationRebuilder Rebuilder(*this, Loc, Name);

diff  --git a/clang/test/SemaTemplate/class-template-decl.cpp 
b/clang/test/SemaTemplate/class-template-decl.cpp
index 453218ac3b40..c054a6a8d82f 100644
--- a/clang/test/SemaTemplate/class-template-decl.cpp
+++ b/clang/test/SemaTemplate/class-template-decl.cpp
@@ -167,3 +167,17 @@ namespace abstract_dependent_class {
   };
   template A *A::clone() { return new A; } // 
expected-error {{abstract class type 'A'}}
 }
+
+namespace qualified_out_of_line {
+  struct rbnode {};
+  template struct pair {};
+  template struct rbtree {
+using base = rbnode;
+pair f();
+  };
+  template
+  pair::base, typename rbtree::base>
+  rbtree::f() {
+return {};
+  }
+}



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


[llvm-branch-commits] [clang] 8c1f2d1 - Following up on PR48517, fix handling of template arguments that refer

2020-12-17 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-12-17T23:54:37-08:00
New Revision: 8c1f2d15b826591cdf6bd6b468b8a7d23377b29e

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

LOG: Following up on PR48517, fix handling of template arguments that refer
to dependent declarations.

Treat an id-expression that names a local variable in a templated
function as being instantiation-dependent.

This addresses a language defect whereby a reference to a dependent
declaration can be formed without any construct being value-dependent.
Fixing that through value-dependence turns out to be problematic, so
instead this patch takes the approach (proposed on the core reflector)
of allowing the use of pointers or references to (but not values of)
dependent declarations inside value-dependent expressions, and instead
treating template arguments as dependent if they evaluate to a constant
involving such dependent declarations.

This ends up affecting a bunch of OpenMP tests, due to OpenMP
imprecisely handling instantiation-dependent constructs, bailing out
early instead of processing dependent constructs to the extent possible
when handling the template.

Added: 
clang/test/SemaTemplate/temp_arg_nontype_cxx17.cpp

Modified: 
clang/include/clang/AST/Expr.h
clang/include/clang/AST/TemplateBase.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/ComputeDependence.cpp
clang/lib/AST/Expr.cpp
clang/lib/AST/ExprCXX.cpp
clang/lib/AST/ExprConstant.cpp
clang/lib/AST/TemplateBase.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/test/OpenMP/distribute_dist_schedule_messages.cpp
clang/test/OpenMP/distribute_parallel_for_dist_schedule_messages.cpp
clang/test/OpenMP/distribute_parallel_for_simd_dist_schedule_messages.cpp
clang/test/OpenMP/distribute_simd_dist_schedule_messages.cpp
clang/test/OpenMP/target_parallel_for_simd_collapse_messages.cpp
clang/test/OpenMP/target_parallel_for_simd_ordered_messages.cpp
clang/test/OpenMP/target_simd_collapse_messages.cpp
clang/test/OpenMP/target_teams_distribute_dist_schedule_messages.cpp

clang/test/OpenMP/target_teams_distribute_parallel_for_dist_schedule_messages.cpp

clang/test/OpenMP/target_teams_distribute_parallel_for_simd_dist_schedule_messages.cpp
clang/test/OpenMP/target_teams_distribute_simd_dist_schedule_messages.cpp
clang/test/OpenMP/target_update_from_messages.cpp
clang/test/OpenMP/target_update_to_messages.cpp
clang/test/OpenMP/task_messages.cpp
clang/test/OpenMP/teams_distribute_dist_schedule_messages.cpp
clang/test/OpenMP/teams_distribute_parallel_for_dist_schedule_messages.cpp

clang/test/OpenMP/teams_distribute_parallel_for_simd_dist_schedule_messages.cpp
clang/test/OpenMP/teams_distribute_simd_dist_schedule_messages.cpp
clang/test/SemaCXX/warn-unused-lambda-capture.cpp
clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp

Removed: 
clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp



diff  --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index c8d87ec48a3f..e1c3b6944142 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -578,12 +578,12 @@ class Expr : public ValueStmt {
   struct EvalStatus {
 /// Whether the evaluated expression has side effects.
 /// For example, (f() && 0) can be folded, but it still has side effects.
-bool HasSideEffects;
+bool HasSideEffects = false;
 
 /// Whether the evaluation hit undefined behavior.
 /// For example, 1.0 / 0.0 can be folded to Inf, but has undefined 
behavior.
 /// Likewise, INT_MAX + 1 can be folded to INT_MIN, but has UB.
-bool HasUndefinedBehavior;
+bool HasUndefinedBehavior = false;
 
 /// Diag - If this is non-null, it will be filled in with a stack of notes
 /// indicating why evaluation failed (or why it failed to produce a 
constant
@@ -592,10 +592,7 @@ class Expr : public ValueStmt {
 /// foldable. If the expression is foldable, but not a constant expression,
 /// the notes will describes why it isn't a constant expression. If the
 /// expression *is* a constant expression, no notes will be produced.
-SmallVectorImpl *Diag;
-
-EvalStatus()
-: HasSideEffects(false), HasUndefinedBehavior(false), Diag(nullptr) {}
+SmallVectorImpl *Diag = nullptr;
 
 // hasSideEffects - Return true if the evaluated expression has
 // side effects.
@@ -606,8 +603,11 @@ class Expr : public ValueStmt {
 
   /// EvalResult is a struct with detailed info about an evaluated expression.
   struct EvalResult : EvalStatus {
-/// Val - This is the value the expression can be folded to.
+/// This is the value the expression can 

[llvm-branch-commits] [clang] 9e08e51 - [c++20] P1907R1: Support for generalized non-type template arguments of scalar type.

2020-12-18 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-12-18T01:08:41-08:00
New Revision: 9e08e51a20d0d2b1c5724bb17e969d036fced4cd

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

LOG: [c++20] P1907R1: Support for generalized non-type template arguments of 
scalar type.

Added: 
clang/test/CodeGenCXX/template-arguments.cpp

Modified: 
clang/include/clang/AST/PropertiesBase.td
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/AST/TemplateArgumentVisitor.h
clang/include/clang/AST/TemplateBase.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/include/clang/Serialization/ASTRecordWriter.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/ASTStructuralEquivalence.cpp
clang/lib/AST/Decl.cpp
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/MicrosoftMangle.cpp
clang/lib/AST/ODRHash.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/AST/TemplateBase.cpp
clang/lib/AST/TypeLoc.cpp
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/CodeGen/CGExprConstant.cpp
clang/lib/Index/USRGeneration.cpp
clang/lib/Sema/SemaLookup.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaTemplateVariadic.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/CodeGenCXX/mangle-ms-templates.cpp
clang/test/CodeGenCXX/mangle-template.cpp
clang/test/SemaTemplate/temp_arg_nontype_cxx17.cpp
clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
clang/tools/libclang/CIndex.cpp
clang/tools/libclang/CXCursor.cpp

Removed: 




diff  --git a/clang/include/clang/AST/PropertiesBase.td 
b/clang/include/clang/AST/PropertiesBase.td
index ba0f237a3bc3..dbe75ab9de19 100644
--- a/clang/include/clang/AST/PropertiesBase.td
+++ b/clang/include/clang/AST/PropertiesBase.td
@@ -72,6 +72,7 @@ class CountPropertyType : 
PropertyType {
 
 def APInt : PropertyType<"llvm::APInt"> { let PassByReference = 1; }
 def APSInt : PropertyType<"llvm::APSInt"> { let PassByReference = 1; }
+def APValue : PropertyType { let PassByReference = 1; }
 def ArraySizeModifier : EnumPropertyType<"ArrayType::ArraySizeModifier">;
 def AttrKind : EnumPropertyType<"attr::Kind">;
 def AutoTypeKeyword : EnumPropertyType;
@@ -450,6 +451,17 @@ let Class = PropertyTypeCase 
in {
 return TemplateArgument(ctx, value, type);
   }]>;
 }
+let Class = PropertyTypeCase in {
+  def : Property<"value", APValue> {
+let Read = [{ node.getAsUncommonValue() }];
+  }
+  def : Property<"type", QualType> {
+let Read = [{ node.getUncommonValueType() }];
+  }
+  def : Creator<[{
+return TemplateArgument(ctx, type, value);
+  }]>;
+}
 let Class = PropertyTypeCase in {
   def : Property<"name", TemplateName> {
 let Read = [{ node.getAsTemplateOrTemplatePattern() }];

diff  --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index 96db0e439952..61e524793ec7 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -767,6 +767,7 @@ bool RecursiveASTVisitor::TraverseTemplateArgument(
   case TemplateArgument::Declaration:
   case TemplateArgument::Integral:
   case TemplateArgument::NullPtr:
+  case TemplateArgument::UncommonValue:
 return true;
 
   case TemplateArgument::Type:
@@ -800,6 +801,7 @@ bool 
RecursiveASTVisitor::TraverseTemplateArgumentLoc(
   case TemplateArgument::Declaration:
   case TemplateArgument::Integral:
   case TemplateArgument::NullPtr:
+  case TemplateArgument::UncommonValue:
 return true;
 
   case TemplateArgument::Type: {

diff  --git a/clang/include/clang/AST/TemplateArgumentVisitor.h 
b/clang/include/clang/AST/TemplateArgumentVisitor.h
index 190aa97adf45..8c0da70b25eb 100644
--- a/clang/include/clang/AST/TemplateArgumentVisitor.h
+++ b/clang/include/clang/AST/TemplateArgumentVisitor.h
@@ -37,6 +37,7 @@ class Base {
   DISPATCH(Declaration);
   DISPATCH(NullPtr);
   DISPATCH(Integral);
+  DISPATCH(UncommonValue);
   DISPATCH(Template);
   DISPATCH(TemplateExpansion);
   DISPATCH(Expression);
@@ -59,6 +60,7 @@ class Base {
   VISIT_METHOD(Declaration);
   VISIT_METHOD(NullPtr);
   VISIT_METHOD(Integral);
+  VISIT_METHOD(UncommonValue);
   VISIT_METHOD(Template);
   VISIT_METHOD(TemplateExpansion);
   VISIT_METHOD(Expression);

diff  --git a/clang/include/clang/AST/TemplateBase.h 
b/clang/include/clang/AST/TemplateBase.h
index abf873a7ee40..9968143e8761 100644
--- a/clang/include/clang/AST/TemplateBase.h
+++ b/clang/include/clang/AST/TemplateBase.h
@@

[llvm-branch-commits] [clang] 569676c - Make Expr::HasSideEffect more precise for instantiation-dependent

2020-12-18 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-12-18T01:08:42-08:00
New Revision: 569676c05725d79909bd8a9224bc709bd621553c

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

LOG: Make Expr::HasSideEffect more precise for instantiation-dependent
expressions.

Fixes a regression in the clang-tidy test suite from making DeclRefExprs
referring to dependent declarations be instantiation-dependent.

Added: 


Modified: 
clang/lib/AST/Expr.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaType.cpp

Removed: 




diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 0426b20a33a9..dafa7136ecb4 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -3242,9 +3242,6 @@ bool Expr::HasSideEffects(const ASTContext &Ctx,
   if (!IncludePossibleEffects && getExprLoc().isMacroID())
 return false;
 
-  if (isInstantiationDependent())
-return IncludePossibleEffects;
-
   switch (getStmtClass()) {
   case NoStmtClass:
   #define ABSTRACT_STMT(Type)
@@ -3264,7 +3261,8 @@ bool Expr::HasSideEffects(const ASTContext &Ctx,
   case TypoExprClass:
   case RecoveryExprClass:
   case CXXFoldExprClass:
-llvm_unreachable("shouldn't see dependent / unresolved nodes here");
+// Make a conservative assumption for dependent nodes.
+return IncludePossibleEffects;
 
   case DeclRefExprClass:
   case ObjCIvarRefExprClass:

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index ca1939222cf0..3992a373f721 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -4135,7 +4135,11 @@ bool Sema::CheckUnaryExprOrTypeTraitOperand(Expr *E,
 
   // The operand for sizeof and alignof is in an unevaluated expression 
context,
   // so side effects could result in unintended consequences.
+  // Exclude instantiation-dependent expressions, because 'sizeof' is sometimes
+  // used to build SFINAE gadgets.
+  // FIXME: Should we consider instantiation-dependent operands to 'alignof'?
   if (IsUnevaluatedOperand && !inTemplateInstantiation() &&
+  !E->isInstantiationDependent() &&
   E->HasSideEffects(Context, false))
 Diag(E->getExprLoc(), diag::warn_side_effects_unevaluated_context);
 

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 241b8f72c56e..05b28c11e5a5 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -7691,7 +7691,8 @@ ExprResult Sema::BuildCXXNoexceptExpr(SourceLocation 
KeyLoc, Expr *Operand,
 
   Operand = R.get();
 
-  if (!inTemplateInstantiation() && Operand->HasSideEffects(Context, false)) {
+  if (!inTemplateInstantiation() && !Operand->isInstantiationDependent() &&
+  Operand->HasSideEffects(Context, false)) {
 // The expression operand for noexcept is in an unevaluated expression
 // context, so side effects could result in unintended consequences.
 Diag(Operand->getExprLoc(), diag::warn_side_effects_unevaluated_context);

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 6485bebc0e8e..00ec0c4a0cee 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -8993,9 +8993,11 @@ QualType Sema::BuildDecltypeType(Expr *E, SourceLocation 
Loc,
   assert(!E->hasPlaceholderType() && "unexpected placeholder");
 
   if (AsUnevaluated && CodeSynthesisContexts.empty() &&
-  E->HasSideEffects(Context, false)) {
+  !E->isInstantiationDependent() && E->HasSideEffects(Context, false)) {
 // The expression operand for decltype is in an unevaluated expression
 // context, so side effects could result in unintended consequences.
+// Exclude instantiation-dependent expressions, because 'decltype' is often
+// used to build SFINAE gadgets.
 Diag(E->getExprLoc(), diag::warn_side_effects_unevaluated_context);
   }
 



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


[llvm-branch-commits] [clang] b4c63ef - [c++20] Mark class type NTTPs as done and start defining the feature test macro.

2020-12-18 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-12-18T13:42:23-08:00
New Revision: b4c63ef6dd90dba9af26a111c9a78b121c5284b1

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

LOG: [c++20] Mark class type NTTPs as done and start defining the feature test 
macro.

Added: 


Modified: 
clang/lib/Frontend/InitPreprocessor.cpp
clang/test/Lexer/cxx-features.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index f2c8d0f6b59a..d4b77a65aa63 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -565,7 +565,7 @@ static void InitializeCPlusPlusFeatureTestMacros(const 
LangOptions &LangOpts,
 Builder.defineMacro("__cpp_aggregate_bases", "201603L");
 Builder.defineMacro("__cpp_structured_bindings", "201606L");
 Builder.defineMacro("__cpp_nontype_template_args",
-"201411L"); // (not latest)
+LangOpts.CPlusPlus20 ? "201911L" : "201411L");
 Builder.defineMacro("__cpp_fold_expressions", "201603L");
 Builder.defineMacro("__cpp_guaranteed_copy_elision", "201606L");
 Builder.defineMacro("__cpp_nontype_template_parameter_auto", "201606L");

diff  --git a/clang/test/Lexer/cxx-features.cpp 
b/clang/test/Lexer/cxx-features.cpp
index 8b9cb5434730..afc3b56d8a37 100644
--- a/clang/test/Lexer/cxx-features.cpp
+++ b/clang/test/Lexer/cxx-features.cpp
@@ -155,7 +155,7 @@
 #error "wrong value for __cpp_structured_bindings"
 #endif
 
-#if check(nontype_template_args, 0, 0, 0, 201411, 201411)
+#if check(nontype_template_args, 0, 0, 0, 201411, 201911)
 #error "wrong value for __cpp_nontype_template_args"
 #endif
 

diff  --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index 4a66b7f9465e..923b13db73a6 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -1005,7 +1005,7 @@ C++20 implementation status
 
   Class types as non-type template parameters
   https://wg21.link/p0732r2";>P0732R2
-  No
+  Clang 12
 

 https://wg21.link/p1907r1";>P1907R1



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


[llvm-branch-commits] [clang] 939ba0b - Add tests for the absence of feature test macros for features we don't

2020-12-18 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-12-18T13:42:23-08:00
New Revision: 939ba0b501b27a2535c9bb62b6f6dc027d49f76d

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

LOG: Add tests for the absence of feature test macros for features we don't
support yet.

Added: 


Modified: 
clang/test/Lexer/cxx-features.cpp

Removed: 




diff  --git a/clang/test/Lexer/cxx-features.cpp 
b/clang/test/Lexer/cxx-features.cpp
index afc3b56d8a37..852c53449568 100644
--- a/clang/test/Lexer/cxx-features.cpp
+++ b/clang/test/Lexer/cxx-features.cpp
@@ -28,16 +28,30 @@
 
 // --- C++20 features ---
 
+#if check(aggregate_paren_init, 0, 0, 0, 0, 0)
+// FIXME: 201902 in C++20
+#error "wrong value for __cpp_aggregate_paren_init"
+#endif
+
 #if defined(CHAR8_T) ? check(char8_t, 201811, 201811, 201811, 201811, 201811) 
: \
 defined(NO_CHAR8_T) ? check(char8_t, 0, 0, 0, 0, 0) : \
 check(char8_t, 0, 0, 0, 0, 201811)
 #error "wrong value for __cpp_char8_t"
 #endif
 
+#if check(concepts, 0, 0, 0, 0, 201907)
+#error "wrong value for __cpp_concepts"
+#endif
+
 #if check(conditional_explicit, 0, 0, 0, 0, 201806)
 #error "wrong value for __cpp_conditional_explicit"
 #endif
 
+#if check(consteval, 0, 0, 0, 0, 0)
+// FIXME: 201811 in C++20
+#error "wrong value for __cpp_consteval"
+#endif
+
 // constexpr checked below
 
 #if check(constexpr_dynamic_alloc, 0, 0, 0, 0, 201907)
@@ -52,6 +66,8 @@
 #error "wrong value for __cpp_constinit"
 #endif
 
+// deduction_guides checked below
+
 #if check(designated_initializers, 0, 0, 0, 0, 201707)
 #error "wrong value for __cpp_designated_initializers"
 #endif
@@ -68,8 +84,14 @@
 
 // init_captures checked below
 
-#if check(concepts, 0, 0, 0, 0, 201907)
-#error "wrong value for __cpp_concepts"
+#if check(modules, 0, 0, 0, 0, 0)
+// FIXME: 201907 in C++20
+#error "wrong value for __cpp_modules"
+#endif
+
+#if check(using_enum, 0, 0, 0, 0, 0)
+// FIXME: 201907 in C++20
+#error "wrong value for __cpp_using_enum"
 #endif
 
 // --- C++17 features ---
@@ -113,6 +135,7 @@
 // static_assert checked below
 
 #if check(deduction_guides, 0, 0, 0, 201703, 201703)
+// FIXME: 201907 in C++20
 #error "wrong value for __cpp_deduction_guides"
 #endif
 



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


[llvm-branch-commits] [clang] 72d8f79 - [c++2b] Add tests for feature test macros.

2020-12-18 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-12-18T13:42:23-08:00
New Revision: 72d8f79f0c31c9b95454672b2319ac3eea8d2f9b

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

LOG: [c++2b] Add tests for feature test macros.

Added: 


Modified: 
clang/test/Lexer/cxx-features.cpp

Removed: 




diff  --git a/clang/test/Lexer/cxx-features.cpp 
b/clang/test/Lexer/cxx-features.cpp
index 852c53449568..f57faed4ed90 100644
--- a/clang/test/Lexer/cxx-features.cpp
+++ b/clang/test/Lexer/cxx-features.cpp
@@ -2,7 +2,8 @@
 // RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -verify %s
 // RUN: %clang_cc1 -std=c++14 -fcxx-exceptions -fsized-deallocation -verify %s
 // RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -fsized-deallocation -verify %s
-// RUN: %clang_cc1 -std=c++2a -fcxx-exceptions -fsized-deallocation -verify %s
+// RUN: %clang_cc1 -std=c++20 -fcxx-exceptions -fsized-deallocation -verify %s
+// RUN: %clang_cc1 -std=c++2b -fcxx-exceptions -fsized-deallocation -verify %s
 //
 // RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -fsized-deallocation 
-frelaxed-template-template-args -DRELAXED_TEMPLATE_TEMPLATE_ARGS=1 -verify %s
 // RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -fsized-deallocation 
-DCONCEPTS_TS=1 -verify %s
@@ -15,118 +16,120 @@
 
 // FIXME using `defined` in a macro has undefined behavior.
 #if __cplusplus < 201103L
-#define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20) (cxx98 == 0 ? 
defined(__cpp_##macro) : __cpp_##macro != cxx98)
+#define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20, cxx23) (cxx98 == 0 ? 
defined(__cpp_##macro) : __cpp_##macro != cxx98)
 #elif __cplusplus < 201402L
-#define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20) (cxx11 == 0 ? 
defined(__cpp_##macro) : __cpp_##macro != cxx11)
+#define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20, cxx23) (cxx11 == 0 ? 
defined(__cpp_##macro) : __cpp_##macro != cxx11)
 #elif __cplusplus < 201703L
-#define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20) (cxx14 == 0 ? 
defined(__cpp_##macro) : __cpp_##macro != cxx14)
-#elif __cplusplus <= 201703L
-#define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20) (cxx17 == 0 ? 
defined(__cpp_##macro) : __cpp_##macro != cxx17)
+#define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20, cxx23) (cxx14 == 0 ? 
defined(__cpp_##macro) : __cpp_##macro != cxx14)
+#elif __cplusplus < 202002L
+#define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20, cxx23) (cxx17 == 0 ? 
defined(__cpp_##macro) : __cpp_##macro != cxx17)
+#elif __cplusplus == 202002L
+#define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20, cxx23) (cxx20 == 0 ? 
defined(__cpp_##macro) : __cpp_##macro != cxx20)
 #else
-#define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20) (cxx20 == 0 ? 
defined(__cpp_##macro) : __cpp_##macro != cxx20)
+#define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20, cxx23) (cxx23 == 0 ? 
defined(__cpp_##macro) : __cpp_##macro != cxx23)
 #endif
 
 // --- C++20 features ---
 
-#if check(aggregate_paren_init, 0, 0, 0, 0, 0)
+#if check(aggregate_paren_init, 0, 0, 0, 0, 0, 0)
 // FIXME: 201902 in C++20
 #error "wrong value for __cpp_aggregate_paren_init"
 #endif
 
-#if defined(CHAR8_T) ? check(char8_t, 201811, 201811, 201811, 201811, 201811) 
: \
-defined(NO_CHAR8_T) ? check(char8_t, 0, 0, 0, 0, 0) : \
-check(char8_t, 0, 0, 0, 0, 201811)
+#if defined(CHAR8_T) ? check(char8_t, 201811, 201811, 201811, 201811, 201811, 
201811) : \
+defined(NO_CHAR8_T) ? check(char8_t, 0, 0, 0, 0, 0, 0) : \
+check(char8_t, 0, 0, 0, 0, 201811, 201811)
 #error "wrong value for __cpp_char8_t"
 #endif
 
-#if check(concepts, 0, 0, 0, 0, 201907)
+#if check(concepts, 0, 0, 0, 0, 201907, 201907)
 #error "wrong value for __cpp_concepts"
 #endif
 
-#if check(conditional_explicit, 0, 0, 0, 0, 201806)
+#if check(conditional_explicit, 0, 0, 0, 0, 201806, 201806)
 #error "wrong value for __cpp_conditional_explicit"
 #endif
 
-#if check(consteval, 0, 0, 0, 0, 0)
+#if check(consteval, 0, 0, 0, 0, 0, 0)
 // FIXME: 201811 in C++20
 #error "wrong value for __cpp_consteval"
 #endif
 
 // constexpr checked below
 
-#if check(constexpr_dynamic_alloc, 0, 0, 0, 0, 201907)
+#if check(constexpr_dynamic_alloc, 0, 0, 0, 0, 201907, 201907)
 #error "wrong value for __cpp_constexpr_dynamic_alloc"
 #endif
 
-#if check(constexpr_in_decltype, 0, 201711, 201711, 201711, 201711)
+#if check(constexpr_in_decltype, 0, 201711, 201711, 201711, 201711, 201711)
 #error "wrong value for __cpp_constexpr_in_decltype"
 #endif
 
-#if check(constinit, 0, 0, 0, 0, 201907)
+#if check(constinit, 0, 0, 0, 0, 201907, 201907)
 #error "wrong value for __cpp_constinit"
 #endif
 
 // deduction_guides checked below
 
-#if check(designated_initializers, 0, 0, 0, 0, 201707)
+#if check(designated_initializers, 0, 0, 0, 0, 201707, 201707)
 #error "wrong value for __cpp_designated_initializ

[llvm-branch-commits] [clang] ed13d8c - Fix memory leak complicated non-type template arguments.

2020-12-18 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-12-18T13:42:24-08:00
New Revision: ed13d8c66781b50ff007cb089c5905f9bb9e8af2

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

LOG: Fix memory leak complicated non-type template arguments.

Added: 


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

Removed: 




diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 0c5d82b3e9aa..a9bfdb4d5fa5 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -2818,8 +2818,8 @@ class ASTContext : public RefCountedBase {
   /// for destruction.
   template  void addDestruction(T *Ptr) const {
 if (!std::is_trivially_destructible::value) {
-  auto DestroyPtr = [](void *V) { static_cast(V)->~T(); };
-  AddDeallocation(DestroyPtr, Ptr);
+  auto DestroyPtr = [](void *V) { ((T*)V)->~T(); };
+  AddDeallocation(DestroyPtr, (void*)Ptr);
 }
   }
 

diff  --git a/clang/lib/AST/TemplateBase.cpp b/clang/lib/AST/TemplateBase.cpp
index 0029c90a0ab6..a746db315d85 100644
--- a/clang/lib/AST/TemplateBase.cpp
+++ b/clang/lib/AST/TemplateBase.cpp
@@ -137,6 +137,7 @@ TemplateArgument::TemplateArgument(const ASTContext &Ctx, 
QualType Type,
   else {
 Value.Kind = UncommonValue;
 Value.Value = new (Ctx) APValue(V);
+Ctx.addDestruction(Value.Value);
 Value.Type = Type.getAsOpaquePtr();
   }
 }



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


[llvm-branch-commits] [clang] f5cef87 - [www] Remove '$Date$' marker from cxx_dr_status.

2020-12-18 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-12-18T14:14:52-08:00
New Revision: f5cef870d116104354fe557c71025a9d4bfbe952

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

LOG: [www] Remove '$Date$' marker from cxx_dr_status.

This doesn't actually work (any more?), and instead renders as a literal
$Date$ on the website.

Added: 


Modified: 
clang/www/cxx_dr_status.html
clang/www/make_cxx_dr_status

Removed: 




diff  --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index b40d2c53bdec..9be6f1262b68 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -28,7 +28,6 @@
 

 C++ Defect Report Support in Clang
 

-Last updated: $Date$
 
 C++ defect report implementation status
 

diff  --git a/clang/www/make_cxx_dr_status b/clang/www/make_cxx_dr_status
index 3a9b18f59cfd..ee113779e32d 100755
--- a/clang/www/make_cxx_dr_status
+++ b/clang/www/make_cxx_dr_status
@@ -79,7 +79,6 @@ print >> out_file, '''\
 

 C++ Defect Report Support in Clang
 

-Last updated: $Date$
 
 C++ defect report implementation status
 



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


[llvm-branch-commits] [clang] d256b8a - Fix "unused variable" warning from recent GCC.

2020-07-15 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-07-15T11:35:05-07:00
New Revision: d256b8ad5f2898cd05faa7319e00ea4a86b0cb47

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

LOG: Fix "unused variable" warning from recent GCC.

(cherry picked from commit 268025e2636c023fc39eed80cc4589f7ce9db786)

Added: 


Modified: 
clang/lib/AST/ExprConstant.cpp

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index d20c2382b6ac..41a4ae4b91c8 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -9930,8 +9930,7 @@ namespace {
   const ConstantArrayType *CAT =
   Info.Ctx.getAsConstantArrayType(E->getType());
   if (!CAT) {
-if (const IncompleteArrayType *IAT =
-Info.Ctx.getAsIncompleteArrayType(E->getType())) {
+if (E->getType()->isIncompleteArrayType()) {
   // We can be asked to zero-initialize a flexible array member; this
   // is represented as an ImplicitValueInitExpr of incomplete array
   // type. In this case, the array has zero elements.



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


[llvm-branch-commits] [clang] ff47911 - PR47143: Don't crash while constant-evaluating value-initialization of

2020-08-12 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-08-12T16:56:53-07:00
New Revision: ff47911ddfc10d023ef0debf229a60c9fce9443a

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

LOG: PR47143: Don't crash while constant-evaluating value-initialization of
an array of unknown bound as the initializer of an array new expression.

(cherry picked from commit bd08e0cf1cb1f1f294e4253ba5907ec4c81b05fe)

Added: 


Modified: 
clang/lib/AST/ExprConstant.cpp
clang/test/SemaCXX/constant-expression-cxx2a.cpp

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 41a4ae4b91c8..8367ffc6f48c 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -8974,6 +8974,7 @@ bool PointerExprEvaluator::VisitCXXNewExpr(const 
CXXNewExpr *E) {
   const Expr *Init = E->getInitializer();
   const InitListExpr *ResizedArrayILE = nullptr;
   const CXXConstructExpr *ResizedArrayCCE = nullptr;
+  bool ValueInit = false;
 
   QualType AllocType = E->getAllocatedType();
   if (Optional ArraySize = E->getArraySize()) {
@@ -9017,7 +9018,14 @@ bool PointerExprEvaluator::VisitCXXNewExpr(const 
CXXNewExpr *E) {
 //   -- the new-initializer is a braced-init-list and the number of
 //  array elements for which initializers are provided [...]
 //  exceeds the number of elements to initialize
-if (Init && !isa(Init)) {
+if (!Init) {
+  // No initialization is performed.
+} else if (isa(Init) ||
+   isa(Init)) {
+  ValueInit = true;
+} else if (auto *CCE = dyn_cast(Init)) {
+  ResizedArrayCCE = CCE;
+} else {
   auto *CAT = Info.Ctx.getAsConstantArrayType(Init->getType());
   assert(CAT && "unexpected type for array initializer");
 
@@ -9040,8 +9048,6 @@ bool PointerExprEvaluator::VisitCXXNewExpr(const 
CXXNewExpr *E) {
   // special handling for this case when we initialize.
   if (InitBound != AllocBound)
 ResizedArrayILE = cast(Init);
-} else if (Init) {
-  ResizedArrayCCE = cast(Init);
 }
 
 AllocType = Info.Ctx.getConstantArrayType(AllocType, ArrayBound, nullptr,
@@ -9102,7 +9108,11 @@ bool PointerExprEvaluator::VisitCXXNewExpr(const 
CXXNewExpr *E) {
   return false;
   }
 
-  if (ResizedArrayILE) {
+  if (ValueInit) {
+ImplicitValueInitExpr VIE(AllocType);
+if (!EvaluateInPlace(*Val, Info, Result, &VIE))
+  return false;
+  } else if (ResizedArrayILE) {
 if (!EvaluateArrayNewInitList(Info, Result, *Val, ResizedArrayILE,
   AllocType))
   return false;

diff  --git a/clang/test/SemaCXX/constant-expression-cxx2a.cpp 
b/clang/test/SemaCXX/constant-expression-cxx2a.cpp
index f66f380b635f..344797bafb11 100644
--- a/clang/test/SemaCXX/constant-expression-cxx2a.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx2a.cpp
@@ -950,6 +950,20 @@ namespace dynamic_alloc {
 p = new ((std::align_val_t)n) char[n];
 p = new char(n);
   }
+
+  namespace PR47143 {
+constexpr char *f(int n) {
+  return new char[n]();
+}
+const char *p = f(3);
+constexpr bool test() {
+  char *p = f(3);
+  bool result = !p[0] && !p[1] && !p[2];
+  delete [] p;
+  return result;
+}
+static_assert(test());
+  }
 }
 
 struct placement_new_arg {};



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


[llvm-branch-commits] [llvm] 97c8fba - Fix signed integer overflow bug that's causing test failures with UBSan.

2020-11-24 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-11-23T17:20:58-08:00
New Revision: 97c8fba7e490db57d24a31c68ad12d7f840256d6

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

LOG: Fix signed integer overflow bug that's causing test failures with UBSan.

Added: 


Modified: 
llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp

Removed: 




diff  --git a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp 
b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
index f7102dccf6ee..01293deb647d 100644
--- a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -2012,7 +2012,7 @@ static unsigned mapToSinitPriority(int P) {
   if (P < 64512)
 return 2047 + (P - 1124) * 33878;
 
-  return 2147482625 + (P - 64512);
+  return 2147482625u + (P - 64512);
 }
 
 static std::string convertToSinitPriority(int Priority) {



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


[llvm-branch-commits] [clang] c2cb61b - Fix mangling of substitutions for template-prefixes.

2020-11-24 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-11-24T16:25:18-08:00
New Revision: c2cb61bed3652126278b4a738e367f524e040ccc

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

LOG: Fix mangling of substitutions for template-prefixes.

Previously we only considered using a substitution for a template-name
after already having mangled its prefix, so we'd produce nonsense
manglings like NS3_S4_IiEE where we should simply produce NS4_IiEE.

This is not ABI-compatible with previous Clang versions, and the old
behavior is restored by -fclang-abi-compat=11.0 or earlier.

Added: 


Modified: 
clang/include/clang/Basic/LangOptions.h
clang/lib/AST/ItaniumMangle.cpp
clang/test/CodeGenCXX/clang-abi-compat.cpp
clang/test/CodeGenCXX/mangle-template.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index d54bfcd7245b..203c45fdd9a7 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -155,7 +155,8 @@ class LangOptions : public LangOptionsBase {
 
 /// Attempt to be ABI-compatible with code generated by Clang 11.0.x
 /// (git  2e10b7a39b93). This causes clang to pass unions with a 256-bit
-/// vector member on the stack instead of using registers.
+/// vector member on the stack instead of using registers, and to not
+/// properly mangle substitutions for template names in some cases.
 Ver11,
 
 /// Conform to the underlying platform's C and C++ ABIs as closely

diff  --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 2b6fda4d9dcc..172b94f26018 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -479,8 +479,6 @@ class CXXNameMangler {
   const AbiTagList *AdditionalAbiTags);
   void mangleUnscopedTemplateName(GlobalDecl GD,
   const AbiTagList *AdditionalAbiTags);
-  void mangleUnscopedTemplateName(TemplateName,
-  const AbiTagList *AdditionalAbiTags);
   void mangleSourceName(const IdentifierInfo *II);
   void mangleRegCallName(const IdentifierInfo *II);
   void mangleDeviceStubName(const IdentifierInfo *II);
@@ -994,29 +992,6 @@ void CXXNameMangler::mangleUnscopedTemplateName(
   addSubstitution(ND);
 }
 
-void CXXNameMangler::mangleUnscopedTemplateName(
-TemplateName Template, const AbiTagList *AdditionalAbiTags) {
-  //  ::= 
-  //  ::= 
-  if (TemplateDecl *TD = Template.getAsTemplateDecl())
-return mangleUnscopedTemplateName(TD, AdditionalAbiTags);
-
-  if (mangleSubstitution(Template))
-return;
-
-  assert(!AdditionalAbiTags &&
- "dependent template name cannot have abi tags");
-
-  DependentTemplateName *Dependent = Template.getAsDependentTemplateName();
-  assert(Dependent && "Not a dependent template name?");
-  if (const IdentifierInfo *Id = Dependent->getIdentifier())
-mangleSourceName(Id);
-  else
-mangleOperatorName(Dependent->getOperator(), UnknownArity);
-
-  addSubstitution(Template);
-}
-
 void CXXNameMangler::mangleFloat(const llvm::APFloat &f) {
   // ABI:
   //   Floating-point literals are encoded using a fixed-length
@@ -1944,21 +1919,28 @@ void CXXNameMangler::mangleTemplatePrefix(TemplateName 
Template) {
   if (TemplateDecl *TD = Template.getAsTemplateDecl())
 return mangleTemplatePrefix(TD);
 
-  if (QualifiedTemplateName *Qualified = Template.getAsQualifiedTemplateName())
-manglePrefix(Qualified->getQualifier());
+  DependentTemplateName *Dependent = Template.getAsDependentTemplateName();
+  assert(Dependent && "unexpected template name kind");
 
-  if (OverloadedTemplateStorage *Overloaded
-  = Template.getAsOverloadedTemplate()) {
-mangleUnqualifiedName(GlobalDecl(), (*Overloaded->begin())->getDeclName(),
-  UnknownArity, nullptr);
+  // Clang 11 and before mangled the substitution for a dependent template name
+  // after already having emitted (a substitution for) the prefix.
+  bool Clang11Compat = getASTContext().getLangOpts().getClangABICompat() <=
+   LangOptions::ClangABI::Ver11;
+  if (!Clang11Compat && mangleSubstitution(Template))
 return;
-  }
 
-  DependentTemplateName *Dependent = Template.getAsDependentTemplateName();
-  assert(Dependent && "Unknown template name kind?");
   if (NestedNameSpecifier *Qualifier = Dependent->getQualifier())
 manglePrefix(Qualifier);
-  mangleUnscopedTemplateName(Template, /* AdditionalAbiTags */ nullptr);
+
+  if (Clang11Compat && mangleSubstitution(Template))
+return;
+
+  if (const IdentifierInfo *Id = Dependent->getIdentifier())
+mangleSourceName(Id);
+  else
+mangl

[llvm-branch-commits] [clang] 23dc049 - Treat a placeholder type for class template argument deduction as

2020-11-24 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-11-24T16:59:06-08:00
New Revision: 23dc04981be29b8398b7a409540646b58af76983

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

LOG: Treat a placeholder type for class template argument deduction as
substitutable for the deduced template.

As agreed in https://github.com/itanium-cxx-abi/cxx-abi/issues/109.

Added: 


Modified: 
clang/lib/AST/ItaniumMangle.cpp
clang/test/CodeGenCXX/cxx1z-class-deduction.cpp

Removed: 




diff  --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 172b94f26018..f5a4f6708c83 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -2507,6 +2507,12 @@ static bool isTypeSubstitutable(Qualifiers Quals, const 
Type *Ty,
   if (Ctx.getLangOpts().getClangABICompat() > LangOptions::ClangABI::Ver6 &&
   isa(Ty))
 return false;
+  // A placeholder type for class template deduction is substitutable with
+  // its corresponding template name; this is handled specially when mangling
+  // the type.
+  if (auto *DeducedTST = Ty->getAs())
+if (DeducedTST->getDeducedType().isNull())
+  return false;
   return true;
 }
 
@@ -3696,16 +3702,16 @@ void CXXNameMangler::mangleType(const AutoType *T) {
 void CXXNameMangler::mangleType(const DeducedTemplateSpecializationType *T) {
   QualType Deduced = T->getDeducedType();
   if (!Deduced.isNull())
-mangleType(Deduced);
-  else if (TemplateDecl *TD = T->getTemplateName().getAsTemplateDecl())
-mangleName(GlobalDecl(TD));
-  else {
-// For an unresolved template-name, mangle it as if it were a template
-// specialization but leave off the template arguments.
-Out << 'N';
-mangleTemplatePrefix(T->getTemplateName());
-Out << 'E';
-  }
+return mangleType(Deduced);
+
+  TemplateDecl *TD = T->getTemplateName().getAsTemplateDecl();
+  assert(TD && "shouldn't form deduced TST unless we know we have a template");
+
+  if (mangleSubstitution(TD))
+return;
+
+  mangleName(GlobalDecl(TD));
+  addSubstitution(TD);
 }
 
 void CXXNameMangler::mangleType(const AtomicType *T) {

diff  --git a/clang/test/CodeGenCXX/cxx1z-class-deduction.cpp 
b/clang/test/CodeGenCXX/cxx1z-class-deduction.cpp
index 8edab748338e..bf436e7ec980 100644
--- a/clang/test/CodeGenCXX/cxx1z-class-deduction.cpp
+++ b/clang/test/CodeGenCXX/cxx1z-class-deduction.cpp
@@ -29,9 +29,9 @@ struct X {
   template struct C { C(T); };
 };
 
-// CHECK: @_Z1gIiEDaT_DTcv1AfL0p_E1AIS0_E(
+// CHECK: @_Z1gIiEDaT_DTcv1AfL0p_ES1_IS0_E
 template auto g(T x, decltype(A(x)), A) {}
-// CHECK: @_Z1hIiEDaT_DTcvN1N1BEfL0p_ENS1_1BIS0_EE(
+// CHECK: @_Z1hIiEDaT_DTcvN1N1BEfL0p_ENS2_IS0_EE
 template auto h(T x, decltype(B(x)), B) {}
 // CHECK: @_Z1iI1XiEDaT0_DTcvNT_1CEfL0p_ENS2_1CIS1_EE(
 template auto i(T x, decltype(typename U::C(x)), 
typename U::template C) {}



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


[llvm-branch-commits] [clang] e0f4dea - Don't assume the clang binary name contains the string "clang".

2020-11-24 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-11-24T18:52:46-08:00
New Revision: e0f4dea0d0f1766eef1591d77b5673ce264e8fff

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

LOG: Don't assume the clang binary name contains the string "clang".

Also ensure the -cc1 argument is actually part of the clang -cc1 command
line rather than some unrelated command line.

Added: 


Modified: 
clang/test/Driver/aix-vec-extabi.c

Removed: 




diff  --git a/clang/test/Driver/aix-vec-extabi.c 
b/clang/test/Driver/aix-vec-extabi.c
index d5e4548c87fa..ccc3b0732e4b 100644
--- a/clang/test/Driver/aix-vec-extabi.c
+++ b/clang/test/Driver/aix-vec-extabi.c
@@ -1,8 +1,8 @@
 // RUN:  %clang -### -target powerpc-unknown-aix -S -maltivec -mabi=vec-extabi 
%s 2>&1 | \
 // RUN:  FileCheck %s
 
-// CHECK: {{.*}}clang{{.*}}" "-cc1"
-// CHECK: "-mabi=vec-extabi"
+// CHECK: "-cc1"
+// CHECK-SAME: "-mabi=vec-extabi"
 
 // RUN:  %clang -### -target powerpc-unknown-aix -S -maltivec 
-mabi=vec-default %s 2>&1 | \
 // RUN:  FileCheck %s --check-prefix=ERROR



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


[llvm-branch-commits] [clang] 3fb0879 - Refactor and simplify class scope name lookup.

2020-11-25 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-11-25T16:25:33-08:00
New Revision: 3fb0879867d7039cb61ffb6287ac17ac949adfa9

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

LOG: Refactor and simplify class scope name lookup.

This is partly in preparation for an upcoming change that can change the
order in which DeclContext lookup results are presented.

In passing, fix some obvious errors where name lookup's notion of a
"static member function" missed static member function templates, and
where its notion of "same set of declarations" was confused by the same
declarations appearing in a different order.

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
clang/include/clang/AST/DeclCXX.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/CXXInheritance.cpp
clang/lib/Sema/SemaLookup.cpp
clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
clang/test/SemaCXX/lookup-member.cpp
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index efc683c6c05d..ef8f54913ed9 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -611,12 +611,10 @@ static StyleKind findStyleKind(
 
 // If this method has the same name as any base method, this is likely
 // necessary even if it's not an override. e.g. CRTP.
-auto FindHidden = [&](const CXXBaseSpecifier *S, clang::CXXBasePath &P) {
-  return CXXRecordDecl::FindOrdinaryMember(S, P, Decl->getDeclName());
-};
-CXXBasePaths UnusedPaths;
-if (Decl->getParent()->lookupInBases(FindHidden, UnusedPaths))
-  return SK_Invalid;
+for (const CXXBaseSpecifier &Base : Decl->getParent()->bases())
+  if (const auto *RD = Base.getType()->getAsCXXRecordDecl())
+if (RD->hasMemberName(Decl->getDeclName()))
+  return SK_Invalid;
 
 if (Decl->isConstexpr() && NamingStyles[SK_ConstexprMethod])
   return SK_ConstexprMethod;

diff  --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 36f42c06a300..568eeb614a76 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1622,58 +1622,6 @@ class CXXRecordDecl : public RecordDecl {
CXXBasePath &Path,
const CXXRecordDecl *BaseRecord);
 
-  /// Base-class lookup callback that determines whether there exists
-  /// a tag with the given name.
-  ///
-  /// This callback can be used with \c lookupInBases() to find tag members
-  /// of the given name within a C++ class hierarchy.
-  static bool FindTagMember(const CXXBaseSpecifier *Specifier,
-CXXBasePath &Path, DeclarationName Name);
-
-  /// Base-class lookup callback that determines whether there exists
-  /// a member with the given name.
-  ///
-  /// This callback can be used with \c lookupInBases() to find members
-  /// of the given name within a C++ class hierarchy.
-  static bool FindOrdinaryMember(const CXXBaseSpecifier *Specifier,
- CXXBasePath &Path, DeclarationName Name);
-
-  /// Base-class lookup callback that determines whether there exists
-  /// a member with the given name.
-  ///
-  /// This callback can be used with \c lookupInBases() to find members
-  /// of the given name within a C++ class hierarchy, including dependent
-  /// classes.
-  static bool
-  FindOrdinaryMemberInDependentClasses(const CXXBaseSpecifier *Specifier,
-   CXXBasePath &Path, DeclarationName 
Name);
-
-  /// Base-class lookup callback that determines whether there exists
-  /// an OpenMP declare reduction member with the given name.
-  ///
-  /// This callback can be used with \c lookupInBases() to find members
-  /// of the given name within a C++ class hierarchy.
-  static bool FindOMPReductionMember(const CXXBaseSpecifier *Specifier,
- CXXBasePath &Path, DeclarationName Name);
-
-  /// Base-class lookup callback that determines whether there exists
-  /// an OpenMP declare mapper member with the given name.
-  ///
-  /// This callback can be used with \c lookupInBases() to find members
-  /// of the given name within a C++ class hierarchy.
-  static bool FindOMPMapperMember(const CXXBaseSpecifier *Specifier,
-  CXXBasePath &Path, DeclarationName Name);
-
-  /// Base-class lookup callback that determines whether there exists
-  /// a member with the given name that can be used in a nested-name-specifier.
-  /

[llvm-branch-commits] [clang] 7c327db - Part of C++ DR 39: a class member lookup is not ambiguous if it finds the

2020-11-25 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-11-25T17:03:11-08:00
New Revision: 7c327db3ef73d771bc022d0723672fc356dc9017

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

LOG: Part of C++ DR 39: a class member lookup is not ambiguous if it finds the
same type in multiple base classes.

Not even if the type is introduced by distinct declarations (for
example, two typedef declarations, or a typedef and a class definition).

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaLookup.cpp
clang/test/CXX/drs/dr3xx.cpp
clang/test/CXX/temp/temp.res/temp.local/p3.cpp
clang/test/SemaCXX/member-name-lookup.cpp
clang/test/SemaTemplate/dependent-base-classes.cpp
clang/test/SemaTemplate/ms-lookup-template-base-classes.cpp
clang/test/SemaTemplate/temp.cpp
clang/test/SemaTemplate/typename-specifier-4.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 2e479307ce22..f2b2b1d3ab6f 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8640,6 +8640,8 @@ def err_ambiguous_member_multiple_subobjects : Error<
 def err_ambiguous_member_multiple_subobject_types : Error<
   "member %0 found in multiple base classes of 
diff erent types">;
 def note_ambiguous_member_found : Note<"member found by ambiguous name 
lookup">;
+def note_ambiguous_member_type_found : Note<
+  "member type %0 found by ambiguous name lookup">;
 def err_ambiguous_reference : Error<"reference to %0 is ambiguous">;
 def note_ambiguous_candidate : Note<"candidate found by name lookup is %q0">;
 def err_ambiguous_tag_hiding : Error<"a type named %0 is hidden by a "

diff  --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 9a1312af42eb..16dd8f510596 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -2228,11 +2228,10 @@ bool Sema::LookupQualifiedName(LookupResult &R, 
DeclContext *LookupCtx,
 
   // Determine whether two sets of members contain the same members, as
   // required by C++ [class.member.lookup]p6.
-  auto HasSameDeclarations = [IDNS,
-  TemplateNameLookup](DeclContextLookupResult A,
-  DeclContextLookupResult B) {
+  auto HasSameDeclarations = [&](DeclContextLookupResult A,
+ DeclContextLookupResult B) {
 using Iterator = DeclContextLookupResult::iterator;
-using Result = const Decl *;
+using Result = const void *;
 
 auto Next = [&](Iterator &It, Iterator End) -> Result {
   while (It != End) {
@@ -2252,14 +2251,15 @@ bool Sema::LookupQualifiedName(LookupResult &R, 
DeclContext *LookupCtx,
   if (auto *TD = getAsTemplateNameDecl(ND))
 ND = TD;
 
-// FIXME: Per C++ [class.member.lookup]p3:
-//   type declarations (including injected-class-names are replaced by 
the
-//   types they designate
-// So two 
diff erent typedef declarations with the same name from two
-// 
diff erent base classes declaring the same type do not introduce an
-// ambiguity.
+// C++ [class.member.lookup]p3:
+//   type declarations (including injected-class-names) are replaced by
+//   the types they designate
+if (const TypeDecl *TD = dyn_cast(ND->getUnderlyingDecl())) {
+  QualType T = Context.getTypeDeclType(TD);
+  return T.getCanonicalType().getAsOpaquePtr();
+}
 
-return cast(ND->getUnderlyingDecl()->getCanonicalDecl());
+return ND->getUnderlyingDecl()->getCanonicalDecl();
   }
   return nullptr;
 };
@@ -2509,13 +2509,23 @@ void Sema::DiagnoseAmbiguousLookup(LookupResult 
&Result) {
   << Name << LookupRange;
 
 CXXBasePaths *Paths = Result.getBasePaths();
-std::set DeclsPrinted;
+std::set DeclsPrinted;
 for (CXXBasePaths::paths_iterator Path = Paths->begin(),
   PathEnd = Paths->end();
  Path != PathEnd; ++Path) {
-  Decl *D = Path->Decls.front();
-  if (DeclsPrinted.insert(D).second)
-Diag(D->getLocation(), diag::note_ambiguous_member_found);
+  const NamedDecl *D = Path->Decls.front();
+  if (!D->isInIdentifierNamespace(Result.getIdentifierNamespace()))
+continue;
+  if (DeclsPrinted.insert(D).second) {
+if (const auto *TD = dyn_cast(D->getUnderlyingDecl()))
+  Diag(D->getLocation(), diag::note_ambiguous_member_type_found)
+  << TD->getUnderlyingType();
+else if (const auto *TD = dyn_cast(D->getUnderlyingDecl()))
+  Diag(D->getLoc

[llvm-branch-commits] [clang] 1db60c1 - Remove redundant check for access in the conversion from the naming

2020-11-29 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-11-29T19:21:59-08:00
New Revision: 1db60c1307ac2e24796047c39d09bf400c22e531

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

LOG: Remove redundant check for access in the conversion from the naming
class to the declaring class in a class member access.

This check does not appear to be backed by any rule in the standard (the
rule in question was likely removed over the years), and only ever
produces duplicate diagnostics. (It's also not meaningful because there
isn't a unique declaring class after the resolution of core issue 39.)

Added: 


Modified: 
clang/lib/Sema/SemaExpr.cpp
clang/test/CXX/class.access/class.access.base/p1.cpp
clang/test/CXX/class.access/class.access.base/p5.cpp
clang/test/CXX/class.access/class.friend/p1.cpp
clang/test/CXX/class.access/class.protected/p1.cpp
clang/test/CXX/class.access/p4.cpp
clang/test/CXX/drs/dr0xx.cpp
clang/test/CXX/drs/dr1xx.cpp
clang/test/CXX/drs/dr2xx.cpp
clang/test/CXX/drs/dr3xx.cpp
clang/test/SemaCXX/anonymous-union.cpp
clang/test/SemaCXX/conversion-function.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index d25d91223826..88dab26f2e3b 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -2818,21 +2818,24 @@ Sema::LookupInObjCMethod(LookupResult &Lookup, Scope *S,
 
 /// Cast a base object to a member's actual type.
 ///
-/// Logically this happens in three phases:
+/// There are two relevant checks:
 ///
-/// * First we cast from the base type to the naming class.
-///   The naming class is the class into which we were looking
-///   when we found the member;  it's the qualifier type if a
-///   qualifier was provided, and otherwise it's the base type.
+/// C++ [class.access.base]p7:
 ///
-/// * Next we cast from the naming class to the declaring class.
-///   If the member we found was brought into a class's scope by
-///   a using declaration, this is that class;  otherwise it's
-///   the class declaring the member.
+///   If a class member access operator [...] is used to access a non-static
+///   data member or non-static member function, the reference is ill-formed if
+///   the left operand [...] cannot be implicitly converted to a pointer to the
+///   naming class of the right operand.
 ///
-/// * Finally we cast from the declaring class to the "true"
-///   declaring class of the member.  This conversion does not
-///   obey access control.
+/// C++ [expr.ref]p7:
+///
+///   If E2 is a non-static data member or a non-static member function, the
+///   program is ill-formed if the class of which E2 is directly a member is an
+///   ambiguous base (11.8) of the naming class (11.9.3) of E2.
+///
+/// Note that the latter check does not consider access; the access of the
+/// "real" base class is checked as appropriate when checking the access of the
+/// member name.
 ExprResult
 Sema::PerformObjectMemberConversion(Expr *From,
 NestedNameSpecifier *Qualifier,
@@ -2956,45 +2959,10 @@ Sema::PerformObjectMemberConversion(Expr *From,
 }
   }
 
-  bool IgnoreAccess = false;
-
-  // If we actually found the member through a using declaration, cast
-  // down to the using declaration's type.
-  //
-  // Pointer equality is fine here because only one declaration of a
-  // class ever has member declarations.
-  if (FoundDecl->getDeclContext() != Member->getDeclContext()) {
-assert(isa(FoundDecl));
-QualType URecordType = Context.getTypeDeclType(
-   cast(FoundDecl->getDeclContext()));
-
-// We only need to do this if the naming-class to declaring-class
-// conversion is non-trivial.
-if (!Context.hasSameUnqualifiedType(FromRecordType, URecordType)) {
-  assert(IsDerivedFrom(FromLoc, FromRecordType, URecordType));
-  CXXCastPath BasePath;
-  if (CheckDerivedToBaseConversion(FromRecordType, URecordType,
-   FromLoc, FromRange, &BasePath))
-return ExprError();
-
-  QualType UType = URecordType;
-  if (PointerConversions)
-UType = Context.getPointerType(UType);
-  From = ImpCastExprToType(From, UType, CK_UncheckedDerivedToBase,
-   VK, &BasePath).get();
-  FromType = UType;
-  FromRecordType = URecordType;
-}
-
-// We don't do access control for the conversion from the
-// declaring class to the true declaring class.
-IgnoreAccess = true;
-  }
-
   CXXCastPath BasePath;
   if (CheckDerivedToBaseConversion(FromRecordType, DestRecordType,
FromLoc, FromRange, &BasePath,
-   IgnoreAccess))
+   

[llvm-branch-commits] [clang] 1f40d60 - Remove CXXBasePaths::found_decls and simplify and modernize its only

2020-12-01 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-12-01T16:35:03-08:00
New Revision: 1f40d60a3b7f310ff3f77bb8643a27d979a703cb

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

LOG: Remove CXXBasePaths::found_decls and simplify and modernize its only
caller.

This function did not satisfy its documented contract: it only
considered the first lookup result on each base path, not all lookup
results. It also performed unnecessary memory allocations.

This change results in a minor change to our representation: we now
include overridden methods that are found by any derived-to-base path
(not involving another override) in the list of overridden methods for a
function, rather than filtering out functions from bases that are both
direct virtual bases and indirect virtual bases for which the indirect
virtual base path contains another override for the function. (That
filtering rule is part of the class-scope name lookup rules, and doesn't
really have much to do with enumerating overridden methods.) The users
of the list of overridden methods do not appear to rely on this
filtering having happened, and it's simpler to not do it.

Added: 


Modified: 
clang/include/clang/AST/CXXInheritance.h
clang/lib/AST/CXXInheritance.cpp
clang/lib/Sema/SemaDecl.cpp

Removed: 




diff  --git a/clang/include/clang/AST/CXXInheritance.h 
b/clang/include/clang/AST/CXXInheritance.h
index 8b1bcb367b3b..709f08bff82a 100644
--- a/clang/include/clang/AST/CXXInheritance.h
+++ b/clang/include/clang/AST/CXXInheritance.h
@@ -149,12 +149,6 @@ class CXXBasePaths {
   /// to help build the set of paths.
   CXXBasePath ScratchPath;
 
-  /// Array of the declarations that have been found. This
-  /// array is constructed only if needed, e.g., to iterate over the
-  /// results within LookupResult.
-  std::unique_ptr DeclsFound;
-  unsigned NumDeclsFound = 0;
-
   /// FindAmbiguities - Whether Sema::IsDerivedFrom should try find
   /// ambiguous paths while it is looking for a path from a derived
   /// type to a base type.
@@ -170,8 +164,6 @@ class CXXBasePaths {
   /// is also recorded.
   bool DetectVirtual;
 
-  void ComputeDeclsFound();
-
   bool lookupInBases(ASTContext &Context, const CXXRecordDecl *Record,
  CXXRecordDecl::BaseMatchesCallback BaseMatches,
  bool LookupInDependent = false);
@@ -198,8 +190,6 @@ class CXXBasePaths {
 
   using decl_range = llvm::iterator_range;
 
-  decl_range found_decls();
-
   /// Determine whether the path from the most-derived type to the
   /// given base type is ambiguous (i.e., it refers to multiple subobjects of
   /// the same base type).

diff  --git a/clang/lib/AST/CXXInheritance.cpp 
b/clang/lib/AST/CXXInheritance.cpp
index 816b5d10773a..c87bcf31d120 100644
--- a/clang/lib/AST/CXXInheritance.cpp
+++ b/clang/lib/AST/CXXInheritance.cpp
@@ -33,29 +33,6 @@
 
 using namespace clang;
 
-/// Computes the set of declarations referenced by these base
-/// paths.
-void CXXBasePaths::ComputeDeclsFound() {
-  assert(NumDeclsFound == 0 && !DeclsFound &&
- "Already computed the set of declarations");
-
-  llvm::SmallSetVector Decls;
-  for (paths_iterator Path = begin(), PathEnd = end(); Path != PathEnd; ++Path)
-Decls.insert(Path->Decls.front());
-
-  NumDeclsFound = Decls.size();
-  DeclsFound = std::make_unique(NumDeclsFound);
-  std::copy(Decls.begin(), Decls.end(), DeclsFound.get());
-}
-
-CXXBasePaths::decl_range CXXBasePaths::found_decls() {
-  if (NumDeclsFound == 0)
-ComputeDeclsFound();
-
-  return decl_range(decl_iterator(DeclsFound.get()),
-decl_iterator(DeclsFound.get() + NumDeclsFound));
-}
-
 /// isAmbiguous - Determines whether the set of paths provided is
 /// ambiguous, i.e., there are two or more paths that refer to
 /// 
diff erent base class subobjects of the same type. BaseType must be

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 2116b3f7b78e..7da854f4fb9e 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -8077,73 +8077,54 @@ bool Sema::CheckVariableDeclaration(VarDecl *NewVD, 
LookupResult &Previous) {
   return false;
 }
 
-namespace {
-struct FindOverriddenMethod {
-  Sema *S;
-  CXXMethodDecl *Method;
-
-  /// Member lookup function that determines whether a given C++
-  /// method overrides a method in a base class, to be used with
-  /// CXXRecordDecl::lookupInBases().
-  bool operator()(const CXXBaseSpecifier *Specifier, CXXBasePath &Path) {
-RecordDecl *BaseRecord =
-Specifier->getType()->castAs()->getDecl();
+/// AddOverriddenMethods - See if a method overrides any in the base classes,
+/// and if so, check that it's a valid override and remember it.
+bool Sema::AddOverriddenMethods(CXXRecordDecl *DC, CXXMethodDec

[llvm-branch-commits] [clang] 2ac5880 - Update MS ABI mangling for union constants based on new information from

2020-12-02 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-12-02T12:17:52-08:00
New Revision: 2ac58801873ab99dd5de48ad7557b76f1803100b

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

LOG: Update MS ABI mangling for union constants based on new information from
Jon Caves.

Added: 


Modified: 
clang/lib/AST/MicrosoftMangle.cpp
clang/test/CodeGenCXX/mangle-class-nttp.cpp

Removed: 




diff  --git a/clang/lib/AST/MicrosoftMangle.cpp 
b/clang/lib/AST/MicrosoftMangle.cpp
index b093b2514c19..1fba1392d0ed 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -1681,14 +1681,13 @@ void 
MicrosoftCXXNameMangler::mangleTemplateArgValue(QualType T,
   }
 
   case APValue::Union:
-Out << '2';
+Out << '7';
 mangleType(T, SourceRange(), QMM_Escape);
-// FIXME: MSVC doesn't mangle the active member, only the type, leading to
-// collisions if more than one member has the same type.
-// FIXME: MSVC doesn't yet support unions with no active member, but
-// there's an obvious mangling for that, so we use it.
-if (const FieldDecl *FD = V.getUnionField())
-  mangleTemplateArgValue(FD->getType(), V.getUnionValue());
+if (const FieldDecl *FD = V.getUnionField()) {
+  mangleUnqualifiedName(FD);
+  mangleTemplateArgValue(FD->getType(), V.getUnionValue(),
+ /*WithType*/false);
+}
 Out << '@';
 return;
 

diff  --git a/clang/test/CodeGenCXX/mangle-class-nttp.cpp 
b/clang/test/CodeGenCXX/mangle-class-nttp.cpp
index 9bb83fcf3246..579afd0a01be 100644
--- a/clang/test/CodeGenCXX/mangle-class-nttp.cpp
+++ b/clang/test/CodeGenCXX/mangle-class-nttp.cpp
@@ -120,16 +120,16 @@ template void f() {}
 // CHECK: define weak_odr void @_Z1fIXL1vv(
 // FIXME: MSVC rejects this; check this is the mangling MSVC uses when they
 // start accepting.
-// MSABI: define {{.*}} @"??$f@$2TE@YAXXZ"
+// MSABI: define {{.*}} @"??$f@$7TE@YAXXZ"
 template void f();
 // CHECK: define weak_odr void @_Z1fIXtl1vv(
-// MSABI: define {{.*}} @"??$f@$2TE@@H0AYAXXZ"
+// MSABI: define {{.*}} @"??$f@$7TE@@n@0AYAXXZ"
 template void f();
 // CHECK: define weak_odr void @_Z1fIXtl1Edi1nLi42vv(
-// MSABI: define {{.*}} @"??$f@$2TE@@H0CKYAXXZ"
+// MSABI: define {{.*}} @"??$f@$7TE@@n@0CKYAXXZ"
 template void f();
 // CHECK: define weak_odr void @_Z1fIXtl1Edi1fLfvv(
-// MSABI: define {{.*}} @"??$f@$2TE@@MAAYAXXZ"
+// MSABI: define {{.*}} @"??$f@$7TE@@0AAYAXXZ"
 template void f();
 
 // immintrin.h vector types.
@@ -210,24 +210,22 @@ template void f() {}
 template void f() {}
 template void f() {}
 // CHECK: define weak_odr void @_Z1fIXL2H1EEEvv
-// MSABI: define {{.*}} @"??$f@$2TH1@YAXXZ"
+// MSABI: define {{.*}} @"??$f@$7TH1@YAXXZ"
 template void f();
 // CHECK: define weak_odr void @_Z1fIXL2H2EEEvv
-// MSABI: define {{.*}} @"??$f@$2TH2@YAXXZ"
+// MSABI: define {{.*}} @"??$f@$7TH2@YAXXZ"
 template void f();
 // CHECK: define weak_odr void @_Z1fIXtl2H3EEEvv
-// MSABI: define {{.*}} @"??$f@$2TH3@@H0AYAXXZ"
+// MSABI: define {{.*}} @"??$f@$7TH3@@a@0AYAXXZ"
 template void f();
 // CHECK: define weak_odr void @_Z1fIXtl2H3di1aLi1vv
-// MSABI: define {{.*}} @"??$f@$2TH3@@H00@@@YAXXZ"
+// MSABI: define {{.*}} @"??$f@$7TH3@@a@00@@@YAXXZ"
 template void f();
-// FIXME: Leads to mangling collision under MS ABI; same mangling as the {.a = 
0} case.
-#ifndef _WIN32
 // CHECK: define weak_odr void @_Z1fIXtl2H3di1bLi0vv
+// MSABI: define {{.*}} @"??$f@$7TH3@@b@0AYAXXZ"
 template void f();
-#endif
 // CHECK: define weak_odr void @_Z1fIXtl2H4EEEvv
-// MSABI: define {{.*}} @"??$f@$2UH4@@2TH2@@YAXXZ"
+// MSABI: define {{.*}} @"??$f@$2UH4@@7TH2@@YAXXZ"
 template void f();
 
 // Floating-point.



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


[llvm-branch-commits] [clang] c4fb772 - PR48339: Improve diagnostics for invalid dependent unqualified function calls.

2020-12-02 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-12-02T17:54:55-08:00
New Revision: c4fb7720ceb30f25c38d994fb375e4d1978de144

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

LOG: PR48339: Improve diagnostics for invalid dependent unqualified function 
calls.

Fix bogus diagnostics that would get confused and think a "no viable
fuctions" case was an "undeclared identifiers" case, resulting in an
incorrect diagnostic preceding the correct one. Use overload resolution
to determine which function we should select when we can find call
candidates from a dependent base class. Make the diagnostics for a call
that could call a function from a dependent base class more specific,
and use a different diagnostic message for the case where the call
target is instead declared later in the same class. Plus some minor
diagnostic wording improvements.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaOverload.cpp
clang/test/CXX/drs/dr2xx.cpp
clang/test/CXX/expr/expr.prim/expr.prim.general/p3-0x.cpp
clang/test/SemaTemplate/cxx1z-using-declaration.cpp
clang/test/SemaTemplate/dependent-names.cpp
clang/test/SemaTemplate/dependent-typos-recovery.cpp
clang/test/SemaTemplate/ms-lookup-template-base-classes.cpp
clang/test/SemaTemplate/recovery-crash.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 3067c077ddb2..44195cc9db45 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5204,11 +5204,17 @@ def ext_undeclared_unqual_id_with_dependent_base : 
ExtWarn<
   "use of undeclared identifier %0; "
   "unqualified lookup into dependent bases of class template %1 is a Microsoft 
extension">,
   InGroup;
-def ext_found_via_dependent_bases_lookup : ExtWarn<"use of identifier %0 "
+def err_found_in_dependent_base : Error<
+  "explicit qualification required to use member %0 from dependent base 
class">;
+def ext_found_in_dependent_base : ExtWarn<"use of member %0 "
   "found via unqualified lookup into dependent bases of class templates is a "
   "Microsoft extension">, InGroup;
-def note_dependent_var_use : Note<"must qualify identifier to find this "
-"declaration in dependent base class">;
+def err_found_later_in_class : Error<"member %0 used before its declaration">;
+def ext_found_later_in_class : ExtWarn<
+  "use of member %0 before its declaration is a Microsoft extension">,
+  InGroup;
+def note_dependent_member_use : Note<
+  "must qualify identifier to find this declaration in dependent base class">;
 def err_not_found_by_two_phase_lookup : Error<"call to function %0 that is 
neither "
 "visible in the template definition nor found by argument-dependent 
lookup">;
 def note_not_found_by_two_phase_lookup : Note<"%0 should be declared prior to 
the "

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 775dd1793dea..8b4a18ab11d6 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3676,6 +3676,9 @@ class Sema final {
ArrayRef Args,
OverloadCandidateSet &CandidateSet,
bool PartialOverloading = false);
+  void AddOverloadedCallCandidates(
+  LookupResult &R, TemplateArgumentListInfo *ExplicitTemplateArgs,
+  ArrayRef Args, OverloadCandidateSet &CandidateSet);
 
   // An enum used to represent the 
diff erent possible results of building a
   // range-based for loop.
@@ -4958,6 +4961,8 @@ class Sema final {
   DeclarationNameInfo &NameInfo,
   const TemplateArgumentListInfo *&TemplateArgs);
 
+  bool DiagnoseDependentMemberLookup(LookupResult &R);
+
   bool
   DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
   CorrectionCandidateCallback &CCC,

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 7da854f4fb9e..6da530c245fe 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -255,7 +255,7 @@ static ParsedType recoverFromTypeInKnownDependentBase(Sema 
&S,
   // We found some types in dependent base classes.  Recover as if the user
   // wrote 'typename MyClass::II' instead of 'II'.  We'll fully resolve the
   // lookup during template instantiation.
-  S.Diag(NameLoc, diag::ext_found_via_dependent_bases_lookup) << &II;
+  S.Diag(NameLoc, diag::ext_found_in_dependent_base) << &II;
 
   ASTContext &Context = S.Context;
   auto *NNS = NestedNameSpecifier::Create(Context, 

[llvm-branch-commits] [clang] be162f4 - PR45699: Fix crash if an unexpanded parameter pack appears in a

2020-12-03 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-12-03T15:26:06-08:00
New Revision: be162f4c0e8563c8de510121435281ae628c8654

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

LOG: PR45699: Fix crash if an unexpanded parameter pack appears in a
requires-clause.

Added: 


Modified: 
clang/include/clang/AST/ExprCXX.h
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/AST/ExprCXX.cpp
clang/lib/Parse/ParseTemplate.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/SemaTemplate/concepts.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 2f89b43267b6..1efa78fc4294 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -2029,6 +2029,9 @@ class LambdaExpr final : public Expr,
   /// invented by use of an auto parameter).
   ArrayRef getExplicitTemplateParameters() const;
 
+  /// Get the trailing requires clause, if any.
+  Expr *getTrailingRequiresClause() const;
+
   /// Whether this is a generic lambda.
   bool isGenericLambda() const { return getTemplateParameterList(); }
 

diff  --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index 0a36ec9ad687..612e60cf4df1 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -2503,17 +2503,12 @@ DEF_TRAVERSE_STMT(LambdaExpr, {
 TypeLoc TL = S->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
 FunctionProtoTypeLoc Proto = TL.getAsAdjusted();
 
-for (Decl *D : S->getExplicitTemplateParameters()) {
-  // Visit explicit template parameters.
-  TRY_TO(TraverseDecl(D));
-}
+TRY_TO(TraverseTemplateParameterListHelper(S->getTemplateParameterList()));
 if (S->hasExplicitParameters()) {
   // Visit parameters.
   for (unsigned I = 0, N = Proto.getNumParams(); I != N; ++I)
 TRY_TO(TraverseDecl(Proto.getParam(I)));
 }
-if (S->hasExplicitResultType())
-  TRY_TO(TraverseTypeLoc(Proto.getReturnLoc()));
 
 auto *T = Proto.getTypePtr();
 for (const auto &E : T->exceptions())
@@ -2522,6 +2517,10 @@ DEF_TRAVERSE_STMT(LambdaExpr, {
 if (Expr *NE = T->getNoexceptExpr())
   TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(NE);
 
+if (S->hasExplicitResultType())
+  TRY_TO(TraverseTypeLoc(Proto.getReturnLoc()));
+TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getTrailingRequiresClause());
+
 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getBody());
   }
   ShouldVisitChildren = false;

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 44195cc9db45..23f374987c92 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5158,7 +5158,8 @@ def err_unexpanded_parameter_pack : Error<
   "using declaration|friend declaration|qualifier|initializer|default 
argument|"
   "non-type template parameter type|exception type|partial specialization|"
   "__if_exists name|__if_not_exists name|lambda|block|type constraint|"
-  "requirement}0 contains%plural{0: an|:}1 unexpanded parameter pack"
+  "requirement|requires clause}0 "
+  "contains%plural{0: an|:}1 unexpanded parameter pack"
   "%plural{0:|1: %2|2:s %2 and %3|:s %2, %3, ...}1">;
 
 def err_pack_expansion_without_parameter_packs : Error<

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 8b4a18ab11d6..fc19e04e6c5d 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2674,6 +2674,7 @@ class Sema final {
 SkipBodyInfo *SkipBody = nullptr);
   void ActOnStartTrailingRequiresClause(Scope *S, Declarator &D);
   ExprResult ActOnFinishTrailingRequiresClause(ExprResult ConstraintExpr);
+  ExprResult ActOnRequiresClause(ExprResult ConstraintExpr);
   void ActOnStartOfObjCMethodDef(Scope *S, Decl *D);
   bool isObjCMethodDecl(Decl *D) {
 return D && isa(D);
@@ -7927,6 +7928,9 @@ class Sema final {
 
 // A requirement in a requires-expression.
 UPPC_Requirement,
+
+// A requires-clause.
+UPPC_RequiresClause,
   };
 
   /// Diagnose unexpanded parameter packs.

diff  --git a/clang/lib/AST/ExprCXX.cpp b/clang/lib/AST/ExprCXX.cpp
index b7f677051ea2..8dc9d4296e14 100644
--- a/clang/lib/AST/ExprCXX.cpp
+++ b/clang/lib/AST/ExprCXX.cpp
@@ -1271,6 +1271,10 @@ ArrayRef 
LambdaExpr::getExplicitTemplateParameters() const {
   return Record->getLambdaExplicitTemplateParameters();
 }
 
+Expr *LambdaExpr::getTrailingRequiresClause() const {
+  return getCallOperator()->getTrailingRequiresClause();
+}
+
 bool LambdaExpr::isMutable() const { return 

[llvm-branch-commits] [clang] eccc734 - P0857R0: Parse a requires-clause after an explicit

2020-12-03 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-12-03T15:54:16-08:00
New Revision: eccc734a69c0c012ae3160887b65a535b35ead3e

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

LOG: P0857R0: Parse a requires-clause after an explicit
template-parameter-list in a lambda.

This implements one of the missing parts of P0857R0. Mark it as not done
on the cxx_status page given that it's still incomplete.

Added: 


Modified: 
clang/include/clang/Sema/ScopeInfo.h
clang/include/clang/Sema/Sema.h
clang/lib/Parse/ParseExprCXX.cpp
clang/lib/Sema/SemaLambda.cpp
clang/test/SemaTemplate/concepts.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/include/clang/Sema/ScopeInfo.h 
b/clang/include/clang/Sema/ScopeInfo.h
index ff2a20923415..8ec74cafeeca 100644
--- a/clang/include/clang/Sema/ScopeInfo.h
+++ b/clang/include/clang/Sema/ScopeInfo.h
@@ -849,6 +849,11 @@ class LambdaScopeInfo final :
   /// Source range covering the explicit template parameter list (if it 
exists).
   SourceRange ExplicitTemplateParamsRange;
 
+  /// The requires-clause immediately following the explicit template parameter
+  /// list, if any. (Note that there may be another requires-clause included as
+  /// part of the lambda-declarator.)
+  ExprResult RequiresClause;
+
   /// If this is a generic lambda, and the template parameter
   /// list has been created (from the TemplateParams) then store
   /// a reference to it (cache it to avoid reconstructing it).

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index fc19e04e6c5d..b3ede504542f 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -6551,7 +6551,8 @@ class Sema final {
   /// on a lambda (if it exists) in C++2a.
   void ActOnLambdaExplicitTemplateParameterList(SourceLocation LAngleLoc,
 ArrayRef TParams,
-SourceLocation RAngleLoc);
+SourceLocation RAngleLoc,
+ExprResult RequiresClause);
 
   /// Introduce the lambda parameters into scope.
   void addLambdaParameters(

diff  --git a/clang/lib/Parse/ParseExprCXX.cpp 
b/clang/lib/Parse/ParseExprCXX.cpp
index 96df2c932bea..4b5703d79f28 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -1268,7 +1268,6 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
   << A.getAttrName()->getName();
   };
 
-  // FIXME: Consider allowing this as an extension for GCC compatibiblity.
   MultiParseScope TemplateParamScope(*this);
   if (Tok.is(tok::less)) {
 Diag(Tok, getLangOpts().CPlusPlus20
@@ -1288,8 +1287,17 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
   Diag(RAngleLoc,
diag::err_lambda_template_parameter_list_empty);
 } else {
+  ExprResult RequiresClause;
+  if (TryConsumeToken(tok::kw_requires)) {
+RequiresClause =
+Actions.ActOnRequiresClause(ParseConstraintLogicalOrExpression(
+/*IsTrailingRequiresClause=*/false));
+if (RequiresClause.isInvalid())
+  SkipUntil({tok::l_brace, tok::l_paren}, StopAtSemi | 
StopBeforeMatch);
+  }
+
   Actions.ActOnLambdaExplicitTemplateParameterList(
-  LAngleLoc, TemplateParams, RAngleLoc);
+  LAngleLoc, TemplateParams, RAngleLoc, RequiresClause);
   ++CurTemplateDepthTracker;
 }
   }

diff  --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index c2eb663147c2..ec1db50cfaaa 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -233,7 +233,7 @@ getGenericLambdaTemplateParameterList(LambdaScopeInfo *LSI, 
Sema &SemaRef) {
 /*L angle loc*/ LSI->ExplicitTemplateParamsRange.getBegin(),
 LSI->TemplateParams,
 /*R angle loc*/LSI->ExplicitTemplateParamsRange.getEnd(),
-nullptr);
+LSI->RequiresClause.get());
   }
   return LSI->GLTemplateParameterList;
 }
@@ -520,7 +520,8 @@ void Sema::finishLambdaExplicitCaptures(LambdaScopeInfo 
*LSI) {
 
 void Sema::ActOnLambdaExplicitTemplateParameterList(SourceLocation LAngleLoc,
 ArrayRef 
TParams,
-SourceLocation RAngleLoc) {
+SourceLocation RAngleLoc,
+ExprResult RequiresClause) 
{
   LambdaScopeInfo *LSI = getCurLambda();
   assert(LSI && "Expected a lambda scope");
   assert(LSI->NumExplicitTemplateParams == 0 &&
@@ -533,6 +534,7 @@ void 
Sema::ActOnLambdaExplicitTemplateParameterList(SourceLocation LAngleLoc,
  

[llvm-branch-commits] [libcxx] 98f76ad - Add new 'preferred_name' attribute.

2020-12-07 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-12-07T12:53:07-08:00
New Revision: 98f76adf4e941738c0b9fe3b9965fa63603e9c89

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

LOG: Add new 'preferred_name' attribute.

This attribute permits a typedef to be associated with a class template
specialization as a preferred way of naming that class template
specialization. This permits us to specify that (for example) the
preferred way to express 'std::basic_string' is as 'std::string'.

The attribute is applied to the various class templates in libc++ that have
corresponding well-known typedef names.

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

Added: 


Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/AST/TypePrinter.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/SemaTemplate/attributes.cpp
clang/utils/TableGen/ClangAttrEmitter.cpp
libcxx/include/__config
libcxx/include/iosfwd
libcxx/include/regex
libcxx/include/string
libcxx/include/string_view

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 0212b60a2afe..123313079d28 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -126,6 +126,9 @@ def FunctionTmpl
  FunctionDecl::TK_FunctionTemplate}],
 "function templates">;
 
+def ClassTmpl : SubsetSubjectgetDescribedClassTemplate()}],
+  "class templates">;
+
 // FIXME: this hack is needed because DeclNodes.td defines the base Decl node
 // type to be a class, not a definition. This makes it impossible to create an
 // attribute subject which accepts a Decl. Normally, this is not a problem,
@@ -2376,6 +2379,16 @@ def Pascal : DeclOrTypeAttr {
   let Documentation = [Undocumented];
 }
 
+def PreferredName : InheritableAttr {
+  let Spellings = [Clang<"preferred_name", /*AllowInC*/0>];
+  let Subjects = SubjectList<[ClassTmpl]>;
+  let Args = [TypeArgument<"TypedefType">];
+  let Documentation = [PreferredNameDocs];
+  let InheritEvenIfAlreadyPresent = 1;
+  let MeaningfulToClassTemplateDefinition = 1;
+  let TemplateDependent = 1;
+}
+
 def PreserveMost : DeclOrTypeAttr {
   let Spellings = [Clang<"preserve_most">];
   let Documentation = [PreserveMostDocs];

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index bf985986e21b..a6f31e7e7f46 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -4417,6 +4417,30 @@ the old mangled name and the new code will use the new 
mangled name with tags.
   }];
 }
 
+def PreferredNameDocs : Documentation {
+  let Category = DocCatDecl;
+  let Content = [{
+The ``preferred_name`` attribute can be applied to a class template, and
+specifies a preferred way of naming a specialization of the template. The
+preferred name will be used whenever the corresponding template specialization
+would otherwise be printed in a diagnostic or similar context.
+
+The preferred name must be a typedef or type alias declaration that refers to a
+specialization of the class template (not including any type qualifiers). In
+general this requires the template to be declared at least twice. For example:
+
+.. code-block:: c++
+
+  template struct basic_string;
+  using string = basic_string;
+  using wstring = basic_string;
+  template struct [[clang::preferred_name(string),
+clang::preferred_name(wstring)]] basic_string {
+// ...
+  };
+  }];
+}
+
 def PreserveMostDocs : Documentation {
   let Category = DocCatCallingConvs;
   let Content = [{

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 01a521fc603e..e79d021c1c94 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3941,6 +3941,9 @@ def note_protocol_decl : Note<
   "protocol is declared here">;
 def note_protocol_decl_undefined : Note<
   "protocol %0 has no definition">;
+def err_attribute_preferred_name_arg_invalid : Error<
+  "argument %0 to 'preferred_name' attribute is not a typedef for "
+  "a specialization of %1">;
 
 // objc_designated_initializer attribute diagnostics.
 def warn_objc_designated_init_missing_super_call : Warning<

diff  --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 721031932a4a..b42ffde4a069 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -10,8 +10,8 @@
 //
 
//===--

[llvm-branch-commits] [clang] a64c26a - Fix deserialization cycle in preferred_name attribute.

2020-12-07 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-12-07T16:02:05-08:00
New Revision: a64c26a47a81b1b44e36d235ff3bc6a74a0bad9f

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

LOG: Fix deserialization cycle in preferred_name attribute.

This is really just a workaround for a more fundamental issue in the way
we deserialize attributes. See PR48434 for details.

Also fix tablegen code generator to produce more correct indentation to
resolve buildbot issues with -Werror=misleading-indentation firing
inside the generated code.

Added: 
clang/test/PCH/decl-attrs.cpp

Modified: 
clang/include/clang/AST/TypeProperties.td
clang/lib/AST/TypePrinter.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/SemaTemplate/attributes.cpp
clang/utils/TableGen/ClangAttrEmitter.cpp

Removed: 




diff  --git a/clang/include/clang/AST/TypeProperties.td 
b/clang/include/clang/AST/TypeProperties.td
index a183ac0479c6a..b582395c44a64 100644
--- a/clang/include/clang/AST/TypeProperties.td
+++ b/clang/include/clang/AST/TypeProperties.td
@@ -484,8 +484,12 @@ let Class = TagType in {
 let Read = [{ node->isDependentType() }];
   }
   def : Property<"declaration", DeclRef> {
-// Serializing a reference to the canonical declaration is apparently
-// necessary to make module-merging work.
+// We don't know which declaration was originally referenced here, and we
+// cannot reference a declaration that follows the use (because that can
+// introduce deserialization cycles), so conservatively generate a
+// reference to the first declaration.
+// FIXME: If this is a reference to a class template specialization, that
+// can still introduce a deserialization cycle.
 let Read = [{ node->getDecl()->getCanonicalDecl() }];
   }
 }

diff  --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 54c451291a077..77ca0f21cc8a1 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -1350,11 +1350,16 @@ void TypePrinter::printTag(TagDecl *D, raw_ostream &OS) 
{
 
 void TypePrinter::printRecordBefore(const RecordType *T, raw_ostream &OS) {
   // Print the preferred name if we have one for this type.
-  for (const auto *PNA : T->getDecl()->specific_attrs()) {
-if (declaresSameEntity(PNA->getTypedefType()->getAsCXXRecordDecl(),
-   T->getDecl()))
-  return printTypeSpec(
-  PNA->getTypedefType()->castAs()->getDecl(), OS);
+  if (const auto *Spec =
+  dyn_cast(T->getDecl())) {
+for (const auto *PNA : Spec->getSpecializedTemplate()
+   ->getTemplatedDecl()
+   ->getMostRecentDecl()
+   ->specific_attrs()) {
+  if (declaresSameEntity(PNA->getTypedefType()->getAsCXXRecordDecl(), 
Spec))
+return printTypeSpec(
+PNA->getTypedefType()->castAs()->getDecl(), OS);
+}
   }
 
   printTag(T->getDecl(), OS);

diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 9db4f23d72967..7403d31c884ae 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -552,20 +552,10 @@ static void instantiateDependentAMDGPUWavesPerEUAttr(
 /// If not, we can skip instantiating it. The attribute may or may not have
 /// been instantiated yet.
 static bool isRelevantAttr(Sema &S, const Decl *D, const Attr *A) {
-  // 'preferred_name' is only relevant to the matching specialization of the
+  // Never instantiate preferred_name attributes; they're relevant only on the
   // template.
-  if (const auto *PNA = dyn_cast(A)) {
-QualType T = PNA->getTypedefType();
-const auto *RD = cast(D);
-if (!T->isDependentType() && !RD->isDependentContext() &&
-!declaresSameEntity(T->getAsCXXRecordDecl(), RD))
-  return false;
-for (const auto *ExistingPNA : D->specific_attrs())
-  if (S.Context.hasSameType(ExistingPNA->getTypedefType(),
-PNA->getTypedefType()))
-return false;
-return true;
-  }
+  if (const auto *PNA = dyn_cast(A))
+return false;
 
   return true;
 }

diff  --git a/clang/test/PCH/decl-attrs.cpp b/clang/test/PCH/decl-attrs.cpp
new file mode 100644
index 0..c89354d0c5de5
--- /dev/null
+++ b/clang/test/PCH/decl-attrs.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -std=c++20 -emit-pch -o %t.a %s
+// RUN: %clang_cc1 -std=c++20 -include-pch %t.a %s -verify
+
+#ifndef HEADER
+#define HEADER
+
+namespace preferred_name {
+  template struct X;
+  using Y = X;
+  using Z = X;
+  template struct [[using clang: preferred_name(Y), 
preferred_name(Z)]] X {};
+  Y y;
+}
+
+#else
+
+namespace preferred_name {
+  Z z;
+
+  

[llvm-branch-commits] [clang] 590e146 - Fix assertion failure due to incorrect dependence bits on a DeclRefExpr

2020-12-07 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-12-07T18:48:38-08:00
New Revision: 590e14653252faa97c2a32ba38aeef05ec681f9b

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

LOG: Fix assertion failure due to incorrect dependence bits on a DeclRefExpr
that can only be set correctly after instantiating the initializer for a
variable.

Added: 


Modified: 
clang/include/clang/AST/Expr.h
clang/lib/AST/Expr.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/recovery-expr-type.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 3ea2817f1926..c8d87ec48a3f 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -1284,7 +1284,7 @@ class DeclRefExpr final
 
   ValueDecl *getDecl() { return D; }
   const ValueDecl *getDecl() const { return D; }
-  void setDecl(ValueDecl *NewD) { D = NewD; }
+  void setDecl(ValueDecl *NewD);
 
   DeclarationNameInfo getNameInfo() const {
 return DeclarationNameInfo(getDecl()->getDeclName(), getLocation(), DNLoc);
@@ -3167,7 +3167,7 @@ class MemberExpr final
   /// The returned declaration will be a FieldDecl or (in C++) a VarDecl (for
   /// static data members), a CXXMethodDecl, or an EnumConstantDecl.
   ValueDecl *getMemberDecl() const { return MemberDecl; }
-  void setMemberDecl(ValueDecl *D) { MemberDecl = D; }
+  void setMemberDecl(ValueDecl *D);
 
   /// Retrieves the declaration found by lookup.
   DeclAccessPair getFoundDecl() const {

diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index f55ee20f2476..1bd032a04a51 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -486,6 +486,11 @@ DeclRefExpr *DeclRefExpr::CreateEmpty(const ASTContext 
&Context,
   return new (Mem) DeclRefExpr(EmptyShell());
 }
 
+void DeclRefExpr::setDecl(ValueDecl *NewD) {
+  D = NewD;
+  setDependence(computeDependence(this, NewD->getASTContext()));
+}
+
 SourceLocation DeclRefExpr::getBeginLoc() const {
   if (hasQualifier())
 return getQualifierLoc().getBeginLoc();
@@ -1572,6 +1577,11 @@ MemberExpr *MemberExpr::CreateEmpty(const ASTContext 
&Context,
   return new (Mem) MemberExpr(EmptyShell());
 }
 
+void MemberExpr::setMemberDecl(ValueDecl *D) {
+  MemberDecl = D;
+  setDependence(computeDependence(this));
+}
+
 SourceLocation MemberExpr::getBeginLoc() const {
   if (isImplicitAccess()) {
 if (hasQualifier())

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 738fe87d37b4..859960d13007 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -18152,6 +18152,13 @@ static void DoMarkVarDeclReferenced(Sema &SemaRef, 
SourceLocation Loc,
 SemaRef.runWithSufficientStackSpace(PointOfInstantiation, [&] {
   SemaRef.InstantiateVariableDefinition(PointOfInstantiation, Var);
 });
+
+// Re-set the member to trigger a recomputation of the dependence bits
+// for the expression.
+if (auto *DRE = dyn_cast_or_null(E))
+  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
@@ -18286,6 +18293,9 @@ static void MarkExprReferenced(Sema &SemaRef, 
SourceLocation Loc,
 }
 
 /// Perform reference-marking and odr-use handling for a DeclRefExpr.
+///
+/// Note, this may change the dependence of the DeclRefExpr, and so needs to be
+/// handled with care if the DeclRefExpr is not newly-created.
 void Sema::MarkDeclRefReferenced(DeclRefExpr *E, const Expr *Base) {
   // TODO: update this with DR# once a defect report is filed.
   // C++11 defect. The address of a pure member should not be an ODR use, even
@@ -18412,6 +18422,10 @@ class EvaluatedExprMarker : public 
UsedDeclVisitor {
 if (VD->hasLocalStorage())
   return;
 }
+
+// FIXME: This can trigger the instantiation of the initializer of a
+// variable, which can cause the expression to become value-dependent
+// or error-dependent. Do we need to propagate the new dependence bits?
 S.MarkDeclRefReferenced(E);
   }
 

diff  --git a/clang/test/SemaCXX/recovery-expr-type.cpp 
b/clang/test/SemaCXX/recovery-expr-type.cpp
index f4691b47ab6d..ed18b7f262cd 100644
--- a/clang/test/SemaCXX/recovery-expr-type.cpp
+++ b/clang/test/SemaCXX/recovery-expr-type.cpp
@@ -109,3 +109,10 @@ auto f(); // expected-note {{candidate function not 
viable}}
 // verify no crash on evaluating the size of undeduced auto type.
 static_assert(sizeof(f(1)), ""); // expected-error {{no matching function for 
call to 'f'}}
 }
+
+namespace test10 {
+// Ensure we don't assert here.
+int f(); // expected-note

[llvm-branch-commits] [libcxx] a134477 - Revert "Add new 'preferred_name' attribute."

2020-12-08 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-12-08T00:42:48-08:00
New Revision: a1344779ab019a6bcd29842c1499343e15efbe87

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

LOG: Revert "Add new 'preferred_name' attribute."

This change exposed a pre-existing issue with deserialization cycles
caused by a combination of attributes and template instantiations
violating the deserialization ordering restrictions; see PR48434 for
details.

A previous commit attempted to work around PR48434, but appears to have
only been a partial fix, and fixing this properly seems non-trivial.
Backing out for now to unblock things.

This reverts commit 98f76adf4e941738c0b9fe3b9965fa63603e9c89 and
commit a64c26a47a81b1b44e36d235ff3bc6a74a0bad9f.

Added: 


Modified: 
clang/include/clang/AST/TypeProperties.td
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/AST/TypePrinter.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/SemaTemplate/attributes.cpp
clang/utils/TableGen/ClangAttrEmitter.cpp
libcxx/include/__config
libcxx/include/iosfwd
libcxx/include/regex
libcxx/include/string
libcxx/include/string_view

Removed: 
clang/test/PCH/decl-attrs.cpp



diff  --git a/clang/include/clang/AST/TypeProperties.td 
b/clang/include/clang/AST/TypeProperties.td
index b582395c44a6..a183ac0479c6 100644
--- a/clang/include/clang/AST/TypeProperties.td
+++ b/clang/include/clang/AST/TypeProperties.td
@@ -484,12 +484,8 @@ let Class = TagType in {
 let Read = [{ node->isDependentType() }];
   }
   def : Property<"declaration", DeclRef> {
-// We don't know which declaration was originally referenced here, and we
-// cannot reference a declaration that follows the use (because that can
-// introduce deserialization cycles), so conservatively generate a
-// reference to the first declaration.
-// FIXME: If this is a reference to a class template specialization, that
-// can still introduce a deserialization cycle.
+// Serializing a reference to the canonical declaration is apparently
+// necessary to make module-merging work.
 let Read = [{ node->getDecl()->getCanonicalDecl() }];
   }
 }

diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 51f654fc7613..52041201d22f 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -126,9 +126,6 @@ def FunctionTmpl
  FunctionDecl::TK_FunctionTemplate}],
 "function templates">;
 
-def ClassTmpl : SubsetSubjectgetDescribedClassTemplate()}],
-  "class templates">;
-
 // FIXME: this hack is needed because DeclNodes.td defines the base Decl node
 // type to be a class, not a definition. This makes it impossible to create an
 // attribute subject which accepts a Decl. Normally, this is not a problem,
@@ -2394,16 +2391,6 @@ def Pascal : DeclOrTypeAttr {
   let Documentation = [Undocumented];
 }
 
-def PreferredName : InheritableAttr {
-  let Spellings = [Clang<"preferred_name", /*AllowInC*/0>];
-  let Subjects = SubjectList<[ClassTmpl]>;
-  let Args = [TypeArgument<"TypedefType">];
-  let Documentation = [PreferredNameDocs];
-  let InheritEvenIfAlreadyPresent = 1;
-  let MeaningfulToClassTemplateDefinition = 1;
-  let TemplateDependent = 1;
-}
-
 def PreserveMost : DeclOrTypeAttr {
   let Spellings = [Clang<"preserve_most">];
   let Documentation = [PreserveMostDocs];

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 28f35cf2c0c7..e7e2805a9608 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -4471,30 +4471,6 @@ the old mangled name and the new code will use the new 
mangled name with tags.
   }];
 }
 
-def PreferredNameDocs : Documentation {
-  let Category = DocCatDecl;
-  let Content = [{
-The ``preferred_name`` attribute can be applied to a class template, and
-specifies a preferred way of naming a specialization of the template. The
-preferred name will be used whenever the corresponding template specialization
-would otherwise be printed in a diagnostic or similar context.
-
-The preferred name must be a typedef or type alias declaration that refers to a
-specialization of the class template (not including any type qualifiers). In
-general this requires the template to be declared at least twice. For example:
-
-.. code-block:: c++
-
-  template struct basic_string;
-  using string = basic_string;
-  using wstring = basic_string;
-  template struct [[clang::preferred_name(string),
- 

[llvm-branch-commits] [clang] 4ae8651 - Add another test for PR48434.

2020-12-09 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-12-09T12:22:35-08:00
New Revision: 4ae8651c59241bca0c1ea5adaf8f06b292696b6f

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

LOG: Add another test for PR48434.

Added: 


Modified: 
clang/test/PCH/decl-attrs.cpp

Removed: 




diff  --git a/clang/test/PCH/decl-attrs.cpp b/clang/test/PCH/decl-attrs.cpp
index c89354d0c5de..249107001874 100644
--- a/clang/test/PCH/decl-attrs.cpp
+++ b/clang/test/PCH/decl-attrs.cpp
@@ -12,6 +12,18 @@ namespace preferred_name {
   Y y;
 }
 
+namespace aligned {
+  // PR48434: ensure attributes don't introduce deserialization cycles.
+  template struct X1;
+  using Y1 = X1;
+  template struct alignas(Y1*) X1 {};
+  Y1 y1;
+
+  template struct X2;
+  using Y2 = X2;
+  template struct alignas(Y2*) X2 {};
+}
+
 #else
 
 namespace preferred_name {
@@ -24,4 +36,11 @@ namespace preferred_name {
   }
 }
 
+namespace aligned {
+  extern Y1 y1;
+  extern Y2 y2;
+  static_assert(alignof(Y1) == alignof(Y1*), "");
+  static_assert(alignof(Y2) == alignof(Y2*), "");
+}
+
 #endif



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


[llvm-branch-commits] [clang] 2a2c228 - Add new 'preferred_name' attribute.

2020-12-09 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-12-09T12:22:35-08:00
New Revision: 2a2c228c7ada0a5d77c48b4d445ab0013ca0ae19

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

LOG: Add new 'preferred_name' attribute.

This attribute permits a typedef to be associated with a class template
specialization as a preferred way of naming that class template
specialization. This permits us to specify that (for example) the
preferred way to express 'std::basic_string' is as 'std::string'.

The attribute is applied to the various class templates in libc++ that have
corresponding well-known typedef names.

This is a re-commit. The previous commit was reverted because it exposed
a pre-existing bug that has since been fixed / worked around; see
PR48434.

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

Added: 
clang/test/PCH/decl-attrs.cpp

Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/AST/TypePrinter.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/SemaTemplate/attributes.cpp
clang/utils/TableGen/ClangAttrEmitter.cpp
libcxx/include/__config
libcxx/include/iosfwd
libcxx/include/regex
libcxx/include/string
libcxx/include/string_view

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 52041201d22f..51f654fc7613 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -126,6 +126,9 @@ def FunctionTmpl
  FunctionDecl::TK_FunctionTemplate}],
 "function templates">;
 
+def ClassTmpl : SubsetSubjectgetDescribedClassTemplate()}],
+  "class templates">;
+
 // FIXME: this hack is needed because DeclNodes.td defines the base Decl node
 // type to be a class, not a definition. This makes it impossible to create an
 // attribute subject which accepts a Decl. Normally, this is not a problem,
@@ -2391,6 +2394,16 @@ def Pascal : DeclOrTypeAttr {
   let Documentation = [Undocumented];
 }
 
+def PreferredName : InheritableAttr {
+  let Spellings = [Clang<"preferred_name", /*AllowInC*/0>];
+  let Subjects = SubjectList<[ClassTmpl]>;
+  let Args = [TypeArgument<"TypedefType">];
+  let Documentation = [PreferredNameDocs];
+  let InheritEvenIfAlreadyPresent = 1;
+  let MeaningfulToClassTemplateDefinition = 1;
+  let TemplateDependent = 1;
+}
+
 def PreserveMost : DeclOrTypeAttr {
   let Spellings = [Clang<"preserve_most">];
   let Documentation = [PreserveMostDocs];

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index e7e2805a9608..28f35cf2c0c7 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -4471,6 +4471,30 @@ the old mangled name and the new code will use the new 
mangled name with tags.
   }];
 }
 
+def PreferredNameDocs : Documentation {
+  let Category = DocCatDecl;
+  let Content = [{
+The ``preferred_name`` attribute can be applied to a class template, and
+specifies a preferred way of naming a specialization of the template. The
+preferred name will be used whenever the corresponding template specialization
+would otherwise be printed in a diagnostic or similar context.
+
+The preferred name must be a typedef or type alias declaration that refers to a
+specialization of the class template (not including any type qualifiers). In
+general this requires the template to be declared at least twice. For example:
+
+.. code-block:: c++
+
+  template struct basic_string;
+  using string = basic_string;
+  using wstring = basic_string;
+  template struct [[clang::preferred_name(string),
+clang::preferred_name(wstring)]] basic_string {
+// ...
+  };
+  }];
+}
+
 def PreserveMostDocs : Documentation {
   let Category = DocCatCallingConvs;
   let Content = [{

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 4a5402455301..97773d35a694 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3941,6 +3941,9 @@ def note_protocol_decl : Note<
   "protocol is declared here">;
 def note_protocol_decl_undefined : Note<
   "protocol %0 has no definition">;
+def err_attribute_preferred_name_arg_invalid : Error<
+  "argument %0 to 'preferred_name' attribute is not a typedef for "
+  "a specialization of %1">;
 
 // objc_designated_initializer attribute diagnostics.
 def warn_objc_designated_init_missing_super_call : Warning<

diff  --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/T

[llvm-branch-commits] [clang] 997a719 - PR48434: Work around crashes due to deserialization cycles via typedefs.

2020-12-09 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-12-09T12:22:35-08:00
New Revision: 997a719d5a70100fcbbec1e51ce44cd66041bddc

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

LOG: PR48434: Work around crashes due to deserialization cycles via typedefs.

Ensure that we can deserialize a TypedefType even while in the middle of
deserializing its TypedefDecl, by removing the need to look at the
TypedefDecl while constructing the TypedefType.

This fixes all the currently-known failures for PR48434, but it's not a
complete fix, because we can still trigger deserialization cycles, which
are not supposed to happen.

Added: 


Modified: 
clang/include/clang/AST/ASTContext.h
clang/include/clang/AST/Type.h
clang/include/clang/AST/TypeProperties.td
clang/lib/AST/ASTContext.cpp
clang/lib/AST/Type.cpp
clang/test/PCH/cxx-templates.cpp
clang/test/PCH/cxx-templates.h

Removed: 




diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 7d58b426a3df..0a635875207d 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1430,7 +1430,7 @@ class ASTContext : public RefCountedBase {
   /// Return the unique reference to the type for the specified
   /// typedef-name decl.
   QualType getTypedefType(const TypedefNameDecl *Decl,
-  QualType Canon = QualType()) const;
+  QualType Underlying = QualType()) const;
 
   QualType getRecordType(const RecordDecl *Decl) const;
 

diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 60b8ee0f1614..99cfa3ae76f5 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -4362,10 +4362,11 @@ class UnresolvedUsingType : public Type {
 class TypedefType : public Type {
   TypedefNameDecl *Decl;
 
-protected:
+private:
   friend class ASTContext; // ASTContext creates these.
 
-  TypedefType(TypeClass tc, const TypedefNameDecl *D, QualType can);
+  TypedefType(TypeClass tc, const TypedefNameDecl *D, QualType underlying,
+  QualType can);
 
 public:
   TypedefNameDecl *getDecl() const { return Decl; }

diff  --git a/clang/include/clang/AST/TypeProperties.td 
b/clang/include/clang/AST/TypeProperties.td
index a183ac0479c6..b582395c44a6 100644
--- a/clang/include/clang/AST/TypeProperties.td
+++ b/clang/include/clang/AST/TypeProperties.td
@@ -484,8 +484,12 @@ let Class = TagType in {
 let Read = [{ node->isDependentType() }];
   }
   def : Property<"declaration", DeclRef> {
-// Serializing a reference to the canonical declaration is apparently
-// necessary to make module-merging work.
+// We don't know which declaration was originally referenced here, and we
+// cannot reference a declaration that follows the use (because that can
+// introduce deserialization cycles), so conservatively generate a
+// reference to the first declaration.
+// FIXME: If this is a reference to a class template specialization, that
+// can still introduce a deserialization cycle.
 let Read = [{ node->getDecl()->getCanonicalDecl() }];
   }
 }

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index c52369cd8a02..057574ec2b82 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -4449,15 +4449,15 @@ QualType ASTContext::getTypeDeclTypeSlow(const TypeDecl 
*Decl) const {
 
 /// getTypedefType - Return the unique reference to the type for the
 /// specified typedef name decl.
-QualType
-ASTContext::getTypedefType(const TypedefNameDecl *Decl,
-   QualType Canonical) const {
+QualType ASTContext::getTypedefType(const TypedefNameDecl *Decl,
+QualType Underlying) const {
   if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0);
 
-  if (Canonical.isNull())
-Canonical = getCanonicalType(Decl->getUnderlyingType());
+  if (Underlying.isNull())
+Underlying = Decl->getUnderlyingType();
+  QualType Canonical = getCanonicalType(Underlying);
   auto *newType = new (*this, TypeAlignment)
-TypedefType(Type::Typedef, Decl, Canonical);
+  TypedefType(Type::Typedef, Decl, Underlying, Canonical);
   Decl->TypeForDecl = newType;
   Types.push_back(newType);
   return QualType(newType, 0);

diff  --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index c07cab9a4006..aa623b000fb5 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -3369,8 +3369,9 @@ void FunctionProtoType::Profile(llvm::FoldingSetNodeID 
&ID,
   getExtProtoInfo(), Ctx, isCanonicalUnqualified());
 }
 
-TypedefType::TypedefType(TypeClass tc, const TypedefNameDecl *D, QualType can)
-: Type(tc, can, D->getUnderlyingType()->getDependence()),
+TypedefT

[llvm-branch-commits] [clang] 7127fd1 - MSABI: Basic mangling for access to member subobjects in a class

2020-12-09 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-12-09T18:08:49-08:00
New Revision: 7127fd1786e607990ada5ade2bf473e6cad68d9d

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

LOG: MSABI: Basic mangling for access to member subobjects in a class
non-type template parameter.

The mangling information used here comes from private communication with
Jon Caves at Microsoft.

Added: 


Modified: 
clang/lib/AST/MicrosoftMangle.cpp
clang/test/CodeGenCXX/mangle-class-nttp.cpp

Removed: 




diff  --git a/clang/lib/AST/MicrosoftMangle.cpp 
b/clang/lib/AST/MicrosoftMangle.cpp
index 1fba1392d0ed..286000faf2a4 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -394,7 +394,7 @@ class MicrosoftCXXNameMangler {
   void mangleTemplateArg(const TemplateDecl *TD, const TemplateArgument &TA,
  const NamedDecl *Parm);
   void mangleTemplateArgValue(QualType T, const APValue &V,
-  bool WithScalarType = true);
+  bool WithScalarType = false);
 
   void mangleObjCProtocol(const ObjCProtocolDecl *PD);
   void mangleObjCLifetime(const QualType T, Qualifiers Quals,
@@ -1473,11 +1473,34 @@ void MicrosoftCXXNameMangler::mangleTemplateArg(const 
TemplateDecl *TD,
   //::= 
   //::= 
   //::= 
-  //::= $E?  
-  //::= $1?  
-  //::= $2 # class NTTP
-  //::= $0A@
+  //::= $ 
   //::= 
+  //
+  //  ::= 0# integer
+  //  ::= 1  # address of D
+  //  ::= 2  * @ # struct
+  //  ::= 3  * @ # array
+  //  ::= 4 ???# string
+  //  ::= 5  @ # address of subobject
+  //  ::= 6   @ # a.b
+  //  ::= 7  [ ] @
+  //  # union, with or without an active member
+  //  # pointer to member, symbolically
+  //  ::= 8   @
+  //  ::= A# float
+  //  ::= B# double
+  //  ::= E  # reference to D
+  //  # pointer to member, by component value
+  //  ::= F  
+  //  ::= G   
+  //  ::= H  
+  //  ::= I   
+  //  ::= J
+  //
+  //  ::= [] 
+  //
+  // The  appears to be included in a  only in the
+  // '0', '1', '8', 'A', 'B', and 'E' cases.
 
   switch (TA.getKind()) {
   case TemplateArgument::Null:
@@ -1622,22 +1645,66 @@ void 
MicrosoftCXXNameMangler::mangleTemplateArgValue(QualType T,
 if (WithScalarType)
   mangleType(T, SourceRange(), QMM_Escape);
 
-APValue::LValueBase Base = V.getLValueBase();
-if (Base.isNull())
-  Out << "0A@";
-else if (auto *VD = Base.dyn_cast())
-  mangle(VD, T->isReferenceType() ? "E?" : "1?");
-else
+// We don't know how to mangle past-the-end pointers yet.
+if (V.isLValueOnePastTheEnd())
   break;
 
-// FIXME: MSVC doesn't support template arguments referring to subobjects
-// yet (it either mangles such template arguments as null pointers or
-// small integers or crashes). It's probably the intent to mangle the
-// declaration followed by an offset, but that's not what actually happens.
-// For now just bail.
-if (!V.hasLValuePath() || !V.getLValuePath().empty() ||
-V.isLValueOnePastTheEnd())
-  break;
+APValue::LValueBase Base = V.getLValueBase();
+if (!V.hasLValuePath() || V.getLValuePath().empty()) {
+  // Taking the address of a complete object has a special-case mangling.
+  if (Base.isNull()) {
+// MSVC emits 0A@ for null pointers. Generalize this for arbitrary
+// integers cast to pointers.
+// FIXME: This mangles 0 cast to a pointer the same as a null pointer,
+// even in cases where the two are 
diff erent values.
+Out << "0";
+mangleNumber(V.getLValueOffset().getQuantity());
+  } else if (!V.hasLValuePath()) {
+// FIXME: This can only happen as an extension. Invent a mangling.
+break;
+  } else if (auto *VD = Base.dyn_cast()) {
+Out << (T->isReferenceType() ? "E" : "1");
+mangle(VD);
+  } else {
+break;
+  }
+} else {
+  unsigned NumAts = 0;
+  if (T->isPointerType()) {
+Out << "5";
+++NumAts;
+  }
+
+  QualType T = Base.getType();
+  for (APValue::LValuePathEntry E : V.getLValuePath()) {
+// We don't know how to mangle array subscripting yet.
+if (T->isArrayType())
+  goto mangling_unknown;
+

[llvm-branch-commits] [clang] a3fe12d - Ensure that we don't leave behind "InstantiatingSpecialization" entries

2020-12-10 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-12-10T17:01:44-08:00
New Revision: a3fe12dc58aa2a0dd7292d748b7c104225f863ba

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

LOG: Ensure that we don't leave behind "InstantiatingSpecialization" entries
after destroying an InstantiatingTemplate object.

This previously caused us to (silently!) bail out of class template
instantiation, thinking we'd produced an error, in some corner cases.

Added: 


Modified: 
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Removed: 




diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 456daab7e032..829ab2253614 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -390,6 +390,9 @@ void Sema::Initialize() {
 }
 
 Sema::~Sema() {
+  assert(InstantiatingSpecializations.empty() &&
+ "failed to clean up an InstantiatingTemplate?");
+
   if (VisContext) FreeVisContext();
 
   // Kill all the active scopes.

diff  --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index e8e34c33e37b..39ea9e06e7b1 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -261,7 +261,7 @@ Sema::InstantiatingTemplate::InstantiatingTemplate(
 
 AlreadyInstantiating = !Inst.Entity ? false :
 !SemaRef.InstantiatingSpecializations
- .insert(std::make_pair(Inst.Entity->getCanonicalDecl(), 
Inst.Kind))
+ .insert({Inst.Entity->getCanonicalDecl(), Inst.Kind})
  .second;
 atTemplateBegin(SemaRef.TemplateInstCallbacks, SemaRef, Inst);
   }
@@ -480,7 +480,7 @@ void Sema::InstantiatingTemplate::Clear() {
   auto &Active = SemaRef.CodeSynthesisContexts.back();
   if (Active.Entity)
 SemaRef.InstantiatingSpecializations.erase(
-std::make_pair(Active.Entity, Active.Kind));
+{Active.Entity->getCanonicalDecl(), Active.Kind});
 }
 
 atTemplateEnd(SemaRef.TemplateInstCallbacks, SemaRef,
@@ -3037,14 +3037,16 @@ bool Sema::usesPartialOrExplicitSpecialization(
 /// Get the instantiation pattern to use to instantiate the definition of a
 /// given ClassTemplateSpecializationDecl (either the pattern of the primary
 /// template or of a partial specialization).
-static CXXRecordDecl *
+static ActionResult
 getPatternForClassTemplateSpecialization(
 Sema &S, SourceLocation PointOfInstantiation,
 ClassTemplateSpecializationDecl *ClassTemplateSpec,
-TemplateSpecializationKind TSK, bool Complain) {
+TemplateSpecializationKind TSK) {
   Sema::InstantiatingTemplate Inst(S, PointOfInstantiation, ClassTemplateSpec);
-  if (Inst.isInvalid() || Inst.isAlreadyInstantiating())
-return nullptr;
+  if (Inst.isInvalid())
+return {/*Invalid=*/true};
+  if (Inst.isAlreadyInstantiating())
+return {/*Invalid=*/false};
 
   llvm::PointerUnion
@@ -3141,7 +3143,7 @@ getPatternForClassTemplateSpecialization(
 << S.getTemplateArgumentBindingsText(
P->Partial->getTemplateParameters(), *P->Args);
 
-  return nullptr;
+  return {/*Invalid=*/true};
 }
   }
 
@@ -3192,14 +3194,15 @@ bool Sema::InstantiateClassTemplateSpecialization(
   if (ClassTemplateSpec->isInvalidDecl())
 return true;
 
-  CXXRecordDecl *Pattern = getPatternForClassTemplateSpecialization(
-  *this, PointOfInstantiation, ClassTemplateSpec, TSK, Complain);
-  if (!Pattern)
-return true;
+  ActionResult Pattern =
+  getPatternForClassTemplateSpecialization(*this, PointOfInstantiation,
+   ClassTemplateSpec, TSK);
+  if (!Pattern.isUsable())
+return Pattern.isInvalid();
 
-  return InstantiateClass(PointOfInstantiation, ClassTemplateSpec, Pattern,
-  getTemplateInstantiationArgs(ClassTemplateSpec), TSK,
-  Complain);
+  return InstantiateClass(
+  PointOfInstantiation, ClassTemplateSpec, Pattern.get(),
+  getTemplateInstantiationArgs(ClassTemplateSpec), TSK, Complain);
 }
 
 /// Instantiates the definitions of all of the member

diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 9db4f23d7296..d3d6df5e0064 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4521,6 +4521,8 @@ 
TemplateDeclInstantiator::InitFunctionInstantiation(FunctionDecl *New,
   // into a template instantiation for this specific function template
   // specialization, which is not a SFINAE context, so that we diagnose any
   // further errors in the declaration itself.
+  //
+  // FIXME: This is a hack.
 

[llvm-branch-commits] [clang] 7b3470b - Consider reference, pointer, and pointer-to-member TemplateArguments to be different if they have different types.

2020-12-11 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-12-11T13:26:33-08:00
New Revision: 7b3470baf8bab1919e3ad4c18e2b776c1f7be2d5

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

LOG: Consider reference, pointer, and pointer-to-member TemplateArguments to be 
different if they have different types.

For the Itanium ABI, this implements the mangling rule suggested in
https://github.com/itanium-cxx-abi/cxx-abi/issues/47, namely mangling
such template arguments as being cast to the parameter type in the case
where the template name is overloadable. This can cause a mangling
change for rare cases, where

 * the template argument declaration is converted from its declared type
   to the type of the template parameter, and
 * the template parameter either has a deduced type or is a parameter of
   a function template.

However, such changes are necessary to avoid mangling collisions. The
ABI changes can be reversed with -fclang-abi-compat=11 or earlier.

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

Added: 


Modified: 
clang/include/clang/Basic/LangOptions.h
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/AST/TemplateBase.cpp
clang/test/CodeGenCXX/clang-abi-compat.cpp
clang/test/CodeGenCXX/mangle-class-nttp.cpp
clang/test/CodeGenCXX/mangle-template.cpp
clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 203c45fdd9a7..251c9a9ecb5d 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -155,8 +155,10 @@ class LangOptions : public LangOptionsBase {
 
 /// Attempt to be ABI-compatible with code generated by Clang 11.0.x
 /// (git  2e10b7a39b93). This causes clang to pass unions with a 256-bit
-/// vector member on the stack instead of using registers, and to not
-/// properly mangle substitutions for template names in some cases.
+/// vector member on the stack instead of using registers, to not properly
+/// mangle substitutions for template names in some cases, and to mangle
+/// declaration template arguments without a cast to the parameter type
+/// even when that can lead to mangling collisions.
 Ver11,
 
 /// Conform to the underlying platform's C and C++ ABIs as closely

diff  --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index f5a4f6708c83..77ecba664f5b 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -551,13 +551,15 @@ class CXXNameMangler {
   void mangleCXXCtorType(CXXCtorType T, const CXXRecordDecl *InheritedFrom);
   void mangleCXXDtorType(CXXDtorType T);
 
-  void mangleTemplateArgs(const TemplateArgumentLoc *TemplateArgs,
+  void mangleTemplateArgs(TemplateName TN,
+  const TemplateArgumentLoc *TemplateArgs,
   unsigned NumTemplateArgs);
-  void mangleTemplateArgs(const TemplateArgument *TemplateArgs,
+  void mangleTemplateArgs(TemplateName TN, const TemplateArgument 
*TemplateArgs,
   unsigned NumTemplateArgs);
-  void mangleTemplateArgs(const TemplateArgumentList &AL);
-  void mangleTemplateArg(TemplateArgument A);
-  void mangleValueInTemplateArg(QualType T, const APValue &V);
+  void mangleTemplateArgs(TemplateName TN, const TemplateArgumentList &AL);
+  void mangleTemplateArg(TemplateArgument A, bool NeedExactType);
+  void mangleValueInTemplateArg(QualType T, const APValue &V, bool TopLevel,
+bool NeedExactType = false);
 
   void mangleTemplateParameter(unsigned Depth, unsigned Index);
 
@@ -823,6 +825,11 @@ isTemplate(GlobalDecl GD, const TemplateArgumentList 
*&TemplateArgs) {
   return GlobalDecl();
 }
 
+static TemplateName asTemplateName(GlobalDecl GD) {
+  const TemplateDecl *TD = dyn_cast_or_null(GD.getDecl());
+  return TemplateName(const_cast(TD));
+}
+
 void CXXNameMangler::mangleName(GlobalDecl GD) {
   const NamedDecl *ND = cast(GD.getDecl());
   if (const VarDecl *VD = dyn_cast(ND)) {
@@ -899,7 +906,7 @@ void CXXNameMangler::mangleNameWithAbiTags(GlobalDecl GD,
 const TemplateArgumentList *TemplateArgs = nullptr;
 if (GlobalDecl TD = isTemplate(GD, TemplateArgs)) {
   mangleUnscopedTemplateName(TD, AdditionalAbiTags);
-  mangleTemplateArgs(*TemplateArgs);
+  mangleTemplateArgs(asTemplateName(TD), *TemplateArgs);
   return;
 }
 
@@ -952,7 +959,7 @@ void CXXNameMangler::mangleTemplateName(const TemplateDecl 
*TD,
 
   if (DC->isTranslationUnit() || isStdNamespace(DC)) {
 mangleUnscopedTemplateName(TD, nullptr);
-mangleTemplateArgs(TemplateArgs, NumTemplateArgs);
+mangleTemplateArgs(asTemplateName(TD), Templa

[llvm-branch-commits] [clang] abbd57e - Factor out and centralize repeated 'getExpandedPackSize'.

2020-12-13 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-12-13T22:43:23-08:00
New Revision: abbd57e558b907a7be8adc5a5b9699dd7c23b1af

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

LOG: Factor out and centralize repeated 'getExpandedPackSize'.

Added: 


Modified: 
clang/include/clang/AST/DeclTemplate.h
clang/lib/AST/DeclTemplate.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index 641647659c17..7fbf6294970e 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -3353,6 +3353,36 @@ inline TemplateDecl *getAsTypeTemplateDecl(Decl *D) {
  : nullptr;
 }
 
+/// Check whether the template parameter is a pack expansion, and if so,
+/// determine the number of parameters produced by that expansion. For 
instance:
+///
+/// \code
+/// template struct A {
+///   template class ...TTs, typename ...Us> struct B;
+/// };
+/// \endcode
+///
+/// In \c A::B, \c NTs and \c TTs have expanded pack size 2, and \c Us
+/// is not a pack expansion, so returns an empty Optional.
+inline Optional getExpandedPackSize(const NamedDecl *Param) {
+  if (const auto *TTP = dyn_cast(Param)) {
+if (TTP->isExpandedParameterPack())
+  return TTP->getNumExpansionParameters();
+  }
+
+  if (const auto *NTTP = dyn_cast(Param)) {
+if (NTTP->isExpandedParameterPack())
+  return NTTP->getNumExpansionTypes();
+  }
+
+  if (const auto *TTP = dyn_cast(Param)) {
+if (TTP->isExpandedParameterPack())
+  return TTP->getNumExpansionTemplateParameters();
+  }
+
+  return None;
+}
+
 } // namespace clang
 
 #endif // LLVM_CLANG_AST_DECLTEMPLATE_H

diff  --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp
index 328ceaa63df3..25235c56ec46 100644
--- a/clang/lib/AST/DeclTemplate.cpp
+++ b/clang/lib/AST/DeclTemplate.cpp
@@ -102,24 +102,10 @@ unsigned TemplateParameterList::getMinRequiredArguments() 
const {
   unsigned NumRequiredArgs = 0;
   for (const NamedDecl *P : asArray()) {
 if (P->isTemplateParameterPack()) {
-  if (const auto *NTTP = dyn_cast(P)) {
-if (NTTP->isExpandedParameterPack()) {
-  NumRequiredArgs += NTTP->getNumExpansionTypes();
-  continue;
-}
-  } else if (const auto *TTP = dyn_cast(P)) {
-if (TTP->isExpandedParameterPack()) {
-  NumRequiredArgs += TTP->getNumExpansionParameters();
-  continue;
-}
-  } else {
-const auto *TP = cast(P);
-if (TP->isExpandedParameterPack()) {
-  NumRequiredArgs += TP->getNumExpansionTemplateParameters();
-  continue;
-}
+  if (Optional Expansions = getExpandedPackSize(P)) {
+NumRequiredArgs += *Expansions;
+continue;
   }
-
   break;
 }
 

diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 4176aa1f458f..70a25fb782e9 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -5588,39 +5588,6 @@ bool Sema::CheckTemplateArgument(NamedDecl *Param,
   return false;
 }
 
-/// Check whether the template parameter is a pack expansion, and if so,
-/// determine the number of parameters produced by that expansion. For 
instance:
-///
-/// \code
-/// template struct A {
-///   template class ...TTs, typename ...Us> struct B;
-/// };
-/// \endcode
-///
-/// In \c A::B, \c NTs and \c TTs have expanded pack size 2, and \c Us
-/// is not a pack expansion, so returns an empty Optional.
-static Optional getExpandedPackSize(NamedDecl *Param) {
-  if (TemplateTypeParmDecl *TTP
-= dyn_cast(Param)) {
-if (TTP->isExpandedParameterPack())
-  return TTP->getNumExpansionParameters();
-  }
-
-  if (NonTypeTemplateParmDecl *NTTP
-= dyn_cast(Param)) {
-if (NTTP->isExpandedParameterPack())
-  return NTTP->getNumExpansionTypes();
-  }
-
-  if (TemplateTemplateParmDecl *TTP
-= dyn_cast(Param)) {
-if (TTP->isExpandedParameterPack())
-  return TTP->getNumExpansionTemplateParameters();
-  }
-
-  return None;
-}
-
 /// Diagnose a missing template argument.
 template
 static bool diagnoseMissingArgument(Sema &S, SourceLocation Loc,

diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index d137aec82b8c..4a3b64cf5425 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -658,23 +658,6 @@ static TemplateParameter makeTemplateParameter(Decl *D) {
   return TemplateParameter(cast(D));
 }
 
-/// If \p Param is an expanded parameter pack, get the number of expansions.
-static Optional getExpandedPackSize(NamedDecl *Param) {
-  if (auto *TTP =

[llvm-branch-commits] [clang] 05cdf4a - Consider reference, pointer, and pointer-to-member TemplateArguments to be different if they have different types.

2020-12-13 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-12-13T22:43:24-08:00
New Revision: 05cdf4acf42acce9ddcff646a5d6ac666710fe6d

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

LOG: Consider reference, pointer, and pointer-to-member TemplateArguments to be 
different if they have different types.

For the Itanium ABI, this implements the mangling rule suggested in
https://github.com/itanium-cxx-abi/cxx-abi/issues/47, namely mangling
such template arguments as being cast to the parameter type in the case
where the template name is overloadable. This can cause a mangling
change for rare cases, where

 * the template argument declaration is converted from its declared type
   to the type of the template parameter, and
 * the template parameter either has a deduced type or is a parameter of
   a function template.

However, such changes are necessary to avoid mangling collisions. The
ABI changes can be reversed with -fclang-abi-compat=11 or earlier.

Re-commit with a fix for the regression introduced last time: don't
expect parameters and arguments to line up inside an 
mangling.

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

Added: 


Modified: 
clang/include/clang/Basic/LangOptions.h
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/AST/TemplateBase.cpp
clang/test/CodeGenCXX/clang-abi-compat.cpp
clang/test/CodeGenCXX/mangle-class-nttp.cpp
clang/test/CodeGenCXX/mangle-template.cpp
clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 203c45fdd9a7..251c9a9ecb5d 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -155,8 +155,10 @@ class LangOptions : public LangOptionsBase {
 
 /// Attempt to be ABI-compatible with code generated by Clang 11.0.x
 /// (git  2e10b7a39b93). This causes clang to pass unions with a 256-bit
-/// vector member on the stack instead of using registers, and to not
-/// properly mangle substitutions for template names in some cases.
+/// vector member on the stack instead of using registers, to not properly
+/// mangle substitutions for template names in some cases, and to mangle
+/// declaration template arguments without a cast to the parameter type
+/// even when that can lead to mangling collisions.
 Ver11,
 
 /// Conform to the underlying platform's C and C++ ABIs as closely

diff  --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index f5a4f6708c83..fe4968052e17 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -551,13 +551,15 @@ class CXXNameMangler {
   void mangleCXXCtorType(CXXCtorType T, const CXXRecordDecl *InheritedFrom);
   void mangleCXXDtorType(CXXDtorType T);
 
-  void mangleTemplateArgs(const TemplateArgumentLoc *TemplateArgs,
+  void mangleTemplateArgs(TemplateName TN,
+  const TemplateArgumentLoc *TemplateArgs,
   unsigned NumTemplateArgs);
-  void mangleTemplateArgs(const TemplateArgument *TemplateArgs,
+  void mangleTemplateArgs(TemplateName TN, const TemplateArgument 
*TemplateArgs,
   unsigned NumTemplateArgs);
-  void mangleTemplateArgs(const TemplateArgumentList &AL);
-  void mangleTemplateArg(TemplateArgument A);
-  void mangleValueInTemplateArg(QualType T, const APValue &V);
+  void mangleTemplateArgs(TemplateName TN, const TemplateArgumentList &AL);
+  void mangleTemplateArg(TemplateArgument A, bool NeedExactType);
+  void mangleValueInTemplateArg(QualType T, const APValue &V, bool TopLevel,
+bool NeedExactType = false);
 
   void mangleTemplateParameter(unsigned Depth, unsigned Index);
 
@@ -823,6 +825,11 @@ isTemplate(GlobalDecl GD, const TemplateArgumentList 
*&TemplateArgs) {
   return GlobalDecl();
 }
 
+static TemplateName asTemplateName(GlobalDecl GD) {
+  const TemplateDecl *TD = dyn_cast_or_null(GD.getDecl());
+  return TemplateName(const_cast(TD));
+}
+
 void CXXNameMangler::mangleName(GlobalDecl GD) {
   const NamedDecl *ND = cast(GD.getDecl());
   if (const VarDecl *VD = dyn_cast(ND)) {
@@ -899,7 +906,7 @@ void CXXNameMangler::mangleNameWithAbiTags(GlobalDecl GD,
 const TemplateArgumentList *TemplateArgs = nullptr;
 if (GlobalDecl TD = isTemplate(GD, TemplateArgs)) {
   mangleUnscopedTemplateName(TD, AdditionalAbiTags);
-  mangleTemplateArgs(*TemplateArgs);
+  mangleTemplateArgs(asTemplateName(TD), *TemplateArgs);
   return;
 }
 
@@ -952,7 +959,7 @@ void CXXNameMangler::mangleTemplateName(const TemplateDecl 
*TD,
 
   if (DC->isTranslationUnit() || isStdNamespace(DC)) {
 mangleUnscoped

[llvm-branch-commits] [libcxx] 7de9c61 - Fix test expectation to cope with custom version namespaces.

2020-12-13 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-12-13T22:43:24-08:00
New Revision: 7de9c61f3111c8b8bc9e03a7935356e2f372d8b4

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

LOG: Fix test expectation to cope with custom version namespaces.

Added: 


Modified: 
libcxx/test/std/numerics/rand/rand.eng/rand.eng.lcong/params.fail.cpp

Removed: 




diff  --git 
a/libcxx/test/std/numerics/rand/rand.eng/rand.eng.lcong/params.fail.cpp 
b/libcxx/test/std/numerics/rand/rand.eng/rand.eng.lcong/params.fail.cpp
index c325b77734bd..86e627344a48 100644
--- a/libcxx/test/std/numerics/rand/rand.eng/rand.eng.lcong/params.fail.cpp
+++ b/libcxx/test/std/numerics/rand/rand.eng/rand.eng.lcong/params.fail.cpp
@@ -24,8 +24,8 @@ int main(int, char**)
 // expected-error@random:* {{static_assert failed due to requirement '1ULL 
== 0 || 1ULL < 1ULL' "linear_congruential_engine invalid parameters"}}
 std::linear_congruential_engine e3;
 std::linear_congruential_engine e4;
-// expected-error@random:* {{static_assert failed due to requirement 
'std::__1::is_unsigned::value' "_UIntType must be unsigned type"}}
+// expected-error-re@random:* {{static_assert failed due to requirement 
'std:{{.*}}:is_unsigned::value' "_UIntType must be unsigned type"}}
 std::linear_congruential_engine e5;
 
 return 0;
-}
\ No newline at end of file
+}



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


[llvm-branch-commits] [clang] ed63454 - Update documentation and release notes to match the state of

2020-01-23 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-01-23T12:26:43-08:00
New Revision: ed63454d984f2262ce332b9b15d49917be3eac98

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

LOG: Update documentation and release notes to match the state of
-flax-vector-conversions on the Clang 10 release branch.

Added: 


Modified: 
clang/docs/CommandGuide/clang.rst
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/CommandGuide/clang.rst 
b/clang/docs/CommandGuide/clang.rst
index 7b0873600fc3..6947450beb43 100644
--- a/clang/docs/CommandGuide/clang.rst
+++ b/clang/docs/CommandGuide/clang.rst
@@ -278,9 +278,18 @@ Language Selection and Mode Options
  Make all string literals default to writable.  This disables uniquing of
  strings and other optimizations.
 
-.. option:: -flax-vector-conversions
+.. option:: -flax-vector-conversions, -flax-vector-conversions=, 
-fno-lax-vector-conversions
 
  Allow loose type checking rules for implicit vector conversions.
+ Possible values of :
+
+ - ``none``: allow no implicit conversions between vectors
+ - ``integer``: allow implicit bitcasts between integer vectors of the same
+   overall bit-width
+ - ``all``: allow implicit bitcasts between any vectors of the same
+   overall bit-width
+
+  defaults to ``integer`` if unspecified.
 
 .. option:: -fblocks
 

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8c48724e7c66..caa6abd4b791 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -102,14 +102,13 @@ Non-comprehensive list of changes in this release
   the found gcc installation is older than 4.7.0. Add ``-fno-use-init-array`` 
to
   get the old behavior (``.ctors``).
 
-* Lax vector conversions involving floating-point vectors have been disabled
-  by default, and can no longer be enabled with ``-flax-vector-conversions``.
-  This matches the behavior of these flags in GCC, but code relying on implicit
-  vector bitcasts between integer and floating-point types that used to compile
-  with older versions of Clang is no longer accepted by default in Clang 10.
-  The old behavior can be restored with ``-flax-vector-conversions=all``.
-  In a future release of Clang, we intend to change the default to
-  ``-fno-lax-vector-conversions``.
+* The behavior of the flag ``-flax-vector-conversions`` has been modified to
+  more closely match GCC, as described below. In Clang 10 onwards, command 
lines
+  specifying this flag do not permit implicit vector bitcasts between integer
+  vectors and floating-point vectors. Such conversions are still permitted by
+  default, however, and the default can be explicitly requested with the
+  Clang-specific flag ``-flax-vector-conversions=all``. In a future release of
+  Clang, we intend to change the default to ``-fno-lax-vector-conversions``.
 
 New Compiler Flags
 --
@@ -142,19 +141,21 @@ Modified Compiler Flags
   to the ``-march`` flag, overriding the target provided by ``-triple``.
 
 - ``-flax-vector-conversions`` has been split into three 
diff erent levels of
-  laxness:
+  laxness, and has been updated to match the GCC semantics:
 
-  - ``-flax-vector-conversions=all``: This is Clang's historical default, and
+  - ``-flax-vector-conversions=all``: This is Clang's current default, and
 permits implicit vector conversions (performed as bitcasts) between any
 two vector types of the same overall bit-width.
+Former synonym: ``-flax-vector-conversions`` (Clang <= 9).
 
-  - ``-flax-vector-conversions=integer``: This is Clang's current default,
-and permits implicit vector conversions (performed as bitcasts) between
-any two integer vector types of the same overall bit-width.
-Synonym: ``-flax-vector-conversions``.
+  - ``-flax-vector-conversions=integer``: This permits implicit vector
+conversions (performed as bitcasts) between any two integer vector types of
+the same overall bit-width.
+Synonym: ``-flax-vector-conversions`` (Clang >= 10).
 
   - ``-flax-vector-conversions=none``: Do not perform any implicit bitcasts
-between vector types. Synonym: ``-fno-lax-vector-conversions``.
+between vector types.
+Synonym: ``-fno-lax-vector-conversions``.
 
 New Pragmas in Clang
 



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


[llvm-branch-commits] [clang] 0ce7ea7 - PR41991: Accept attributes on defaulted and deleted friends.

2020-01-30 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-01-30T17:43:48-08:00
New Revision: 0ce7ea7c6e0e6fde5c961a574592bdd2ebebdeb7

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

LOG: PR41991: Accept attributes on defaulted and deleted friends.

Attributes are permitted on friend definitions, but we only checked for
a proper function body, not for the =default / =delete cases.

(cherry picked from commit 5ae6554a1dcd2e39346030c06d364492901c9e8d)

Added: 


Modified: 
clang/lib/Parse/ParseDeclCXX.cpp
clang/test/Parser/cxx-default-delete.cpp
clang/test/Parser/cxx2a-spaceship.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseDeclCXX.cpp 
b/clang/lib/Parse/ParseDeclCXX.cpp
index f872aa3a950c..09e5c7996fcd 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -2716,7 +2716,7 @@ Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS,
 // C++11 [dcl.attr.grammar] p4: If an attribute-specifier-seq appertains
 // to a friend declaration, that declaration shall be a definition.
 if (DeclaratorInfo.isFunctionDeclarator() &&
-DefinitionKind != FDK_Definition && DS.isFriendSpecified()) {
+DefinitionKind == FDK_Declaration && DS.isFriendSpecified()) {
   // Diagnose attributes that appear before decl specifier:
   // [[]] friend int foo();
   ProhibitAttributes(FnAttrs);

diff  --git a/clang/test/Parser/cxx-default-delete.cpp 
b/clang/test/Parser/cxx-default-delete.cpp
index 8766d861732e..6c74937504b0 100644
--- a/clang/test/Parser/cxx-default-delete.cpp
+++ b/clang/test/Parser/cxx-default-delete.cpp
@@ -21,3 +21,7 @@ void baz() = delete;
 struct quux {
   int quux() = default; // expected-error{{constructor cannot have a return 
type}}
 };
+
+struct attrs {
+  [[noreturn]] friend void deleted_with_attrs() = delete;
+};

diff  --git a/clang/test/Parser/cxx2a-spaceship.cpp 
b/clang/test/Parser/cxx2a-spaceship.cpp
index 24cece3eaa9d..f80420f89862 100644
--- a/clang/test/Parser/cxx2a-spaceship.cpp
+++ b/clang/test/Parser/cxx2a-spaceship.cpp
@@ -16,3 +16,9 @@ void f(X<0> x0, X<1> x1) {
   X<3> e = x0 < x0 <=> x0 << x0;
   X<3> f = x0 << x0 <=> x0 < x0; // expected-warning {{overloaded operator << 
has higher precedence than comparison operator}} expected-note 2{{}}
 }
+
+struct PR41991 {
+  [[nodiscard]] friend bool operator==(const PR41991&, const PR41991&) = 
default;
+  [[nodiscard]] friend bool operator!=(const PR41991&, const PR41991&) = 
delete;
+  [[nodiscard]] friend bool operator<(const PR41991&, const PR41991&); // 
expected-error {{an attribute list cannot appear here}}
+};



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


[llvm-branch-commits] [clang] 904d146 - PR44627: Consider reversing == and <=> candidates found by ADL.

2020-01-30 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-01-30T18:42:46-08:00
New Revision: 904d146c5f552f1b7f1376f532563b8ad6106c38

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

LOG: PR44627: Consider reversing == and <=> candidates found by ADL.

(cherry picked from commit 1db66e705f4dbe7dbe17edac804289ef59d5f616)

Added: 


Modified: 
clang/lib/Sema/SemaOverload.cpp
clang/test/CXX/class/class.compare/class.compare.default/p4.cpp
clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 9f4996b5463d..c5ada02ba898 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -9269,17 +9269,31 @@ 
Sema::AddArgumentDependentLookupCandidates(DeclarationName Name,
   if (ExplicitTemplateArgs)
 continue;
 
-  AddOverloadCandidate(FD, FoundDecl, Args, CandidateSet,
-   /*SuppressUserConversions=*/false, 
PartialOverloading,
-   /*AllowExplicit*/ true,
-   /*AllowExplicitConversions*/ false,
-   ADLCallKind::UsesADL);
+  AddOverloadCandidate(
+  FD, FoundDecl, Args, CandidateSet, /*SuppressUserConversions=*/false,
+  PartialOverloading, /*AllowExplicit=*/true,
+  /*AllowExplicitConversions=*/false, ADLCallKind::UsesADL);
+  if (CandidateSet.getRewriteInfo().shouldAddReversed(Context, FD)) {
+AddOverloadCandidate(
+FD, FoundDecl, {Args[1], Args[0]}, CandidateSet,
+/*SuppressUserConversions=*/false, PartialOverloading,
+/*AllowExplicit=*/true, /*AllowExplicitConversions=*/false,
+ADLCallKind::UsesADL, None, OverloadCandidateParamOrder::Reversed);
+  }
 } else {
+  auto *FTD = cast(*I);
   AddTemplateOverloadCandidate(
-  cast(*I), FoundDecl, ExplicitTemplateArgs, 
Args,
-  CandidateSet,
+  FTD, FoundDecl, ExplicitTemplateArgs, Args, CandidateSet,
   /*SuppressUserConversions=*/false, PartialOverloading,
-  /*AllowExplicit*/true, ADLCallKind::UsesADL);
+  /*AllowExplicit=*/true, ADLCallKind::UsesADL);
+  if (CandidateSet.getRewriteInfo().shouldAddReversed(
+  Context, FTD->getTemplatedDecl())) {
+AddTemplateOverloadCandidate(
+FTD, FoundDecl, ExplicitTemplateArgs, {Args[1], Args[0]},
+CandidateSet, /*SuppressUserConversions=*/false, 
PartialOverloading,
+/*AllowExplicit=*/true, ADLCallKind::UsesADL,
+OverloadCandidateParamOrder::Reversed);
+  }
 }
   }
 }

diff  --git a/clang/test/CXX/class/class.compare/class.compare.default/p4.cpp 
b/clang/test/CXX/class/class.compare/class.compare.default/p4.cpp
index 3820b5b44287..8c303c63d899 100644
--- a/clang/test/CXX/class/class.compare/class.compare.default/p4.cpp
+++ b/clang/test/CXX/class/class.compare/class.compare.default/p4.cpp
@@ -122,7 +122,7 @@ namespace NoInjectionIfOperatorEqualsDeclared {
   bool test_a = A() == A(); // expected-error {{invalid operands}}
 
   struct B {
-friend void operator==(int, struct Q); // expected-note {{not viable}}
+friend void operator==(int, struct Q); // expected-note 2{{not viable}}
 std::strong_ordering operator<=>(const B&) const = default;
   };
   bool test_b = B() == B(); // expected-error {{invalid operands}}

diff  --git 
a/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp 
b/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp
index 3be8dc7749c6..023e076d50a7 100644
--- a/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp
+++ b/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp
@@ -113,6 +113,18 @@ namespace bullet4 {
   X<3> reversed_add = x2 + x1; // expected-error {{invalid operands}}
 }
 
+namespace PR44627 {
+  namespace ADL {
+struct type {};
+bool operator==(type lhs, int rhs) {
+  return true;
+}
+  }
+
+  bool b1 = ADL::type() == 0;
+  bool b2 = 0 == ADL::type();
+}
+
 // Various C++17 cases that are known to be broken by the C++20 rules.
 namespace problem_cases {
   // We can have an ambiguity between an operator and its reversed form. This



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


[llvm-branch-commits] [clang] fdedf39 - PR44723: Trigger return type deduction for operator<=>s whose return

2020-01-31 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-01-31T13:08:25-08:00
New Revision: fdedf39c46f526afb1c07b0ca91a7c5bc1e43b8f

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

LOG: PR44723: Trigger return type deduction for operator<=>s whose return
types are needed to compute the return type of a defaulted operator<=>.

This raises the question of what to do if return type deduction fails.
The standard doesn't say, and implementations vary, so for now reject
that case eagerly to keep our options open.

(cherry picked from commit 42d4a55f227a1cc78ab8071062d869abe88655d9)

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/CXX/class/class.compare/class.spaceship/p2.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b7b8c5f17c41..5608e2064b25 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8392,6 +8392,12 @@ def note_defaulted_comparison_cannot_deduce : Note<
   "return type of defaulted 'operator<=>' cannot be deduced because "
   "return type %2 of three-way comparison for %select{|member|base class}0 %1 "
   "is not a standard comparison category type">;
+def err_defaulted_comparison_cannot_deduce_undeduced_auto : Error<
+  "return type of defaulted 'operator<=>' cannot be deduced because "
+  "three-way comparison for %select{|member|base class}0 %1 "
+  "has a deduced return type and is not yet defined">;
+def note_defaulted_comparison_cannot_deduce_undeduced_auto : Note<
+  "%select{|member|base class}0 %1 declared here">;
 def note_defaulted_comparison_cannot_deduce_callee : Note<
   "selected 'operator<=>' for %select{|member|base class}0 %1 declared here">;
 def err_incorrect_defaulted_comparison_constexpr : Error<

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 9fa5691983a1..19403e050850 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -7438,6 +7438,31 @@ class DefaultedComparisonAnalyzer
 
   if (OO == OO_Spaceship && FD->getReturnType()->isUndeducedAutoType()) {
 if (auto *BestFD = Best->Function) {
+  // If any callee has an undeduced return type, deduce it now.
+  // FIXME: It's not clear how a failure here should be handled. For
+  // now, we produce an eager diagnostic, because that is forward
+  // compatible with most (all?) other reasonable options.
+  if (BestFD->getReturnType()->isUndeducedType() &&
+  S.DeduceReturnType(BestFD, FD->getLocation(),
+ /*Diagnose=*/false)) {
+// Don't produce a duplicate error when asked to explain why the
+// comparison is deleted: we diagnosed that when initially checking
+// the defaulted operator.
+if (Diagnose == NoDiagnostics) {
+  S.Diag(
+  FD->getLocation(),
+  diag::err_defaulted_comparison_cannot_deduce_undeduced_auto)
+  << Subobj.Kind << Subobj.Decl;
+  S.Diag(
+  Subobj.Loc,
+  diag::note_defaulted_comparison_cannot_deduce_undeduced_auto)
+  << Subobj.Kind << Subobj.Decl;
+  S.Diag(BestFD->getLocation(),
+ diag::note_defaulted_comparison_cannot_deduce_callee)
+  << Subobj.Kind << Subobj.Decl;
+}
+return Result::deleted();
+  }
   if (auto *Info = S.Context.CompCategories.lookupInfoForType(
   BestFD->getCallResultType())) {
 R.Category = Info->Kind;

diff  --git a/clang/test/CXX/class/class.compare/class.spaceship/p2.cpp 
b/clang/test/CXX/class/class.compare/class.spaceship/p2.cpp
index a912384ccf76..dae31e925ba1 100644
--- a/clang/test/CXX/class/class.compare/class.spaceship/p2.cpp
+++ b/clang/test/CXX/class/class.compare/class.spaceship/p2.cpp
@@ -97,6 +97,39 @@ namespace Deduction {
 
   // Check that the above mechanism works.
   template void f(); // expected-note 
{{instantiation of}}
+
+  std::strong_ordering x = A() <=> A();
+}
+
+namespace PR44723 {
+  // Make sure we trigger return type deduction for a callee 'operator<=>'
+  // before inspecting its return type.
+  template struct a {
+friend constexpr auto operator<=>(a const &lhs, a const &rhs) {
+  return std::strong_ordering::equal;
+}
+  };
+  struct b {
+friend constexpr auto operator<=>(b const &, b const &) = default;
+a<0> m_value;
+  };
+  std::strong_ordering cmp_b = b() <=> b();
+
+  struct c {
+auto operator<=>(const c&) const&; // expected-note {{selected 
'operator<=

[llvm-branch-commits] [clang] f85d63a - Fix wrong devirtualization when the final overrider in one base class

2020-01-31 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-01-31T17:07:04-08:00
New Revision: f85d63a558364dcf57efe7b37b3e99b7fd91fd5c

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

LOG: Fix wrong devirtualization when the final overrider in one base class
overrides the final overrider in a different base class.

(cherry picked from commit aade5fbbfef3e8555df202082bea905deebc2ca5)

Added: 


Modified: 
clang/lib/AST/CXXInheritance.cpp
clang/lib/AST/DeclCXX.cpp
clang/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp

Removed: 




diff  --git a/clang/lib/AST/CXXInheritance.cpp 
b/clang/lib/AST/CXXInheritance.cpp
index a3a3794b2edd..0377bd324cb6 100644
--- a/clang/lib/AST/CXXInheritance.cpp
+++ b/clang/lib/AST/CXXInheritance.cpp
@@ -758,6 +758,8 @@ CXXRecordDecl::getFinalOverriders(CXXFinalOverriderMap 
&FinalOverriders) const {
 return false;
   };
 
+  // FIXME: IsHidden reads from Overriding from the middle of a remove_if
+  // over the same sequence! Is this guaranteed to work?
   Overriding.erase(
   std::remove_if(Overriding.begin(), Overriding.end(), IsHidden),
   Overriding.end());

diff  --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 48e310e858b2..227fe80ccab4 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -2038,17 +2038,36 @@ CXXMethodDecl::getCorrespondingMethodInClass(const 
CXXRecordDecl *RD,
   if (auto *MD = getCorrespondingMethodDeclaredInClass(RD, MayBeBase))
 return MD;
 
+  llvm::SmallVector FinalOverriders;
+  auto AddFinalOverrider = [&](CXXMethodDecl *D) {
+// If this function is overridden by a candidate final overrider, it is not
+// a final overrider.
+for (CXXMethodDecl *OtherD : FinalOverriders) {
+  if (declaresSameEntity(D, OtherD) || recursivelyOverrides(OtherD, D))
+return;
+}
+
+// Other candidate final overriders might be overridden by this function.
+FinalOverriders.erase(
+std::remove_if(FinalOverriders.begin(), FinalOverriders.end(),
+   [&](CXXMethodDecl *OtherD) {
+ return recursivelyOverrides(D, OtherD);
+   }),
+FinalOverriders.end());
+
+FinalOverriders.push_back(D);
+  };
+
   for (const auto &I : RD->bases()) {
 const RecordType *RT = I.getType()->getAs();
 if (!RT)
   continue;
 const auto *Base = cast(RT->getDecl());
-CXXMethodDecl *T = this->getCorrespondingMethodInClass(Base);
-if (T)
-  return T;
+if (CXXMethodDecl *D = this->getCorrespondingMethodInClass(Base))
+  AddFinalOverrider(D);
   }
 
-  return nullptr;
+  return FinalOverriders.size() == 1 ? FinalOverriders.front() : nullptr;
 }
 
 CXXMethodDecl *CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD,
@@ -2105,6 +2124,11 @@ CXXMethodDecl 
*CXXMethodDecl::getDevirtualizedMethod(const Expr *Base,
   CXXMethodDecl *DevirtualizedMethod =
   getCorrespondingMethodInClass(BestDynamicDecl);
 
+  // If there final overrider in the dynamic type is ambiguous, we can't
+  // devirtualize this call.
+  if (!DevirtualizedMethod)
+return nullptr;
+
   // If that method is pure virtual, we can't devirtualize. If this code is
   // reached, the result would be UB, not a direct call to the derived class
   // function, and we can't assume the derived class function is defined.

diff  --git 
a/clang/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp 
b/clang/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp
index 130103de97ae..6f5e844b587e 100644
--- a/clang/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp
+++ b/clang/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp
@@ -255,6 +255,49 @@ namespace Test10 {
   }
 }
 
+namespace TestVBase {
+  struct A { virtual void f(); };
+  struct B : virtual A {};
+  struct C : virtual A { void f() override; };
+
+  extern struct BC final : B, C {} &bc;
+  extern struct BCusingA final : B, C { using A::f; } &bc_using_a;
+  extern struct BCusingB final : B, C { using B::f; } &bc_using_b;
+  extern struct BCusingC final : B, C { using C::f; } &bc_using_c;
+
+  extern struct CB final : C, B {} &cb;
+  extern struct CBusingA final : C, B { using A::f; } &cb_using_a;
+  extern struct CBusingB final : C, B { using B::f; } &cb_using_b;
+  extern struct CBusingC final : C, B { using C::f; } &cb_using_c;
+
+  // CHECK-LABEL: @_ZN9TestVBase4testEv(
+  void test() {
+// FIXME: The 'using A' case can be devirtualized to call A's virtual
+// adjustment thunk for C::f.
+// FIXME: The 'using B' case can be devirtualized, but requires us to emit
+// a derived-to-base or base-to-derived conversion as part of
+// devirtualization.
+
+// CHECK: call void

[llvm-branch-commits] [clang] 300cbdc - PR44761: Fix fallback to later tiebreakers if two non-template functions

2020-02-04 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-02-04T12:22:49-08:00
New Revision: 300cbdc59da05756f7a0334338076124536df03d

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

LOG: PR44761: Fix fallback to later tiebreakers if two non-template functions
are equally constrained.

(cherry picked from commit cfacf9ae20b8c97a428f118a2720bc109ba6a143)

Added: 
clang/test/CXX/over/over.match/over.match.best/p2.cpp

Modified: 
clang/lib/Sema/SemaOverload.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index c5ada02ba898..9a9843827b3f 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -9579,17 +9579,15 @@ bool clang::isBetterOverloadCandidate(
   if (RC1 && RC2) {
 bool AtLeastAsConstrained1, AtLeastAsConstrained2;
 if (S.IsAtLeastAsConstrained(Cand1.Function, {RC1}, Cand2.Function,
- {RC2}, AtLeastAsConstrained1))
-  return false;
-if (!AtLeastAsConstrained1)
-  return false;
-if (S.IsAtLeastAsConstrained(Cand2.Function, {RC2}, Cand1.Function,
+ {RC2}, AtLeastAsConstrained1) ||
+S.IsAtLeastAsConstrained(Cand2.Function, {RC2}, Cand1.Function,
  {RC1}, AtLeastAsConstrained2))
   return false;
-if (!AtLeastAsConstrained2)
-  return true;
-  } else if (RC1 || RC2)
+if (AtLeastAsConstrained1 != AtLeastAsConstrained2)
+  return AtLeastAsConstrained1;
+  } else if (RC1 || RC2) {
 return RC1 != nullptr;
+  }
 }
   }
 

diff  --git a/clang/test/CXX/over/over.match/over.match.best/p2.cpp 
b/clang/test/CXX/over/over.match/over.match.best/p2.cpp
new file mode 100644
index ..3a4443665576
--- /dev/null
+++ b/clang/test/CXX/over/over.match/over.match.best/p2.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=c++2a -verify %s
+
+namespace PR44761 {
+  template concept X = (sizeof(T) == sizeof(T));
+
+  template struct A {
+bool operator<(const A&) const & requires X; // #1
+int operator<=>(const A&) const & requires X && X = delete; // #2
+  };
+  bool k1 = A() < A(); // not ordered by constraints: prefer 
non-rewritten form
+  bool k2 = A() < A(); // prefer more-constrained 'operator<=>'
+  // expected-error@-1 {{deleted}}
+  // expected-note@#1 {{candidate}}
+  // expected-note@#2 {{candidate function has been explicitly deleted}}
+  // expected-note@#2 {{candidate function (with reversed parameter order) has 
been explicitly deleted}}
+}



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


[llvm-branch-commits] [clang] 7a94fc0 - PR44721: Don't consider overloaded operators for built-in comparisons

2020-02-04 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-02-04T12:25:40-08:00
New Revision: 7a94fc09d17bc317032eb9605eba05dced8c87e5

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

LOG: PR44721: Don't consider overloaded operators for built-in comparisons
when building a defaulted comparison.

As a convenient way of asking whether `x @ y` is valid and building it,
we previouly always performed overload resolution and built an
overloaded expression, which would both end up picking a builtin
operator candidate when given a non-overloadable type. But that's not
quite right, because it can result in our finding a user-declared
operator overload, which we should never do when applying operators
non-overloadable types.

Handle this more correctly: skip overload resolution when building
`x @ y` if the operands are not overloadable. But still perform overload
resolution (considering only builtin candidates) when checking validity,
as we don't have any other good way to ask whether a binary operator
expression would be valid.

(cherry picked from commit 1f3f8c369a5067a132c871f33a955a7feaea8534)

Added: 


Modified: 
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/CXX/class/class.compare/class.compare.default/p3.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 19403e050850..831e55046e80 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -7373,7 +7373,14 @@ class DefaultedComparisonAnalyzer
 ///   resolution [...]
 CandidateSet.exclude(FD);
 
-S.LookupOverloadedBinOp(CandidateSet, OO, Fns, Args);
+if (Args[0]->getType()->isOverloadableType())
+  S.LookupOverloadedBinOp(CandidateSet, OO, Fns, Args);
+else {
+  // FIXME: We determine whether this is a valid expression by checking to
+  // see if there's a viable builtin operator candidate for it. That isn't
+  // really what the rules ask us to do, but should give the right results.
+  S.AddBuiltinOperatorCandidates(OO, FD->getLocation(), Args, 
CandidateSet);
+}
 
 Result R;
 
@@ -7851,10 +7858,14 @@ class DefaultedComparisonSynthesizer
   return StmtError();
 
 OverloadedOperatorKind OO = FD->getOverloadedOperator();
-ExprResult Op = S.CreateOverloadedBinOp(
-Loc, BinaryOperator::getOverloadedOpcode(OO), Fns,
-Obj.first.get(), Obj.second.get(), /*PerformADL=*/true,
-/*AllowRewrittenCandidates=*/true, FD);
+BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(OO);
+ExprResult Op;
+if (Type->isOverloadableType())
+  Op = S.CreateOverloadedBinOp(Loc, Opc, Fns, Obj.first.get(),
+   Obj.second.get(), /*PerformADL=*/true,
+   /*AllowRewrittenCandidates=*/true, FD);
+else
+  Op = S.CreateBuiltinBinOp(Loc, Opc, Obj.first.get(), Obj.second.get());
 if (Op.isInvalid())
   return StmtError();
 
@@ -7894,8 +7905,12 @@ class DefaultedComparisonSynthesizer
   llvm::APInt ZeroVal(S.Context.getIntWidth(S.Context.IntTy), 0);
   Expr *Zero =
   IntegerLiteral::Create(S.Context, ZeroVal, S.Context.IntTy, Loc);
-  ExprResult Comp = S.CreateOverloadedBinOp(Loc, BO_NE, Fns, VDRef.get(),
-Zero, true, true, FD);
+  ExprResult Comp;
+  if (VDRef.get()->getType()->isOverloadableType())
+Comp = S.CreateOverloadedBinOp(Loc, BO_NE, Fns, VDRef.get(), Zero, 
true,
+   true, FD);
+  else
+Comp = S.CreateBuiltinBinOp(Loc, BO_NE, VDRef.get(), Zero);
   if (Comp.isInvalid())
 return StmtError();
   Sema::ConditionResult Cond = S.ActOnCondition(

diff  --git a/clang/test/CXX/class/class.compare/class.compare.default/p3.cpp 
b/clang/test/CXX/class/class.compare/class.compare.default/p3.cpp
index 3d0ab2c5bde6..81a48a393a06 100644
--- a/clang/test/CXX/class/class.compare/class.compare.default/p3.cpp
+++ b/clang/test/CXX/class/class.compare/class.compare.default/p3.cpp
@@ -190,3 +190,15 @@ bool operator<(const G&, const G&);
 bool operator<=(const G&, const G&);
 bool operator>(const G&, const G&);
 bool operator>=(const G&, const G&);
+
+namespace PR44721 {
+  template  bool operator==(T const &, T const &) { return true; }
+  template  bool operator!=(T const &, U const &) { 
return true; }
+  template  int operator<=>(T const &, T const &) { return 0; }
+
+  struct S {
+friend bool operator==(const S &, const S &) = default;
+friend bool operator<=>(const S &, const S &) = default;
+int x;
+  };
+}



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

[llvm-branch-commits] [clang] b833e0c - PR44786: Don't assert when profiling <=> expressions.

2020-02-04 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-02-04T18:30:54-08:00
New Revision: b833e0c5f1190e7102e570b0eb5055174aa03b32

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

LOG: PR44786: Don't assert when profiling <=> expressions.

(cherry picked from commit b96c6b65b93f7b3878bced2374bef747a4c3b690)

Added: 


Modified: 
clang/lib/AST/StmtProfile.cpp
clang/test/SemaCXX/cxx2a-three-way-comparison.cpp

Removed: 




diff  --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp
index 382ea5c8d7ef..60dec50d53da 100644
--- a/clang/lib/AST/StmtProfile.cpp
+++ b/clang/lib/AST/StmtProfile.cpp
@@ -1535,8 +1535,8 @@ static Stmt::StmtClass DecodeOperatorCall(const 
CXXOperatorCallExpr *S,
 return Stmt::BinaryOperatorClass;
 
   case OO_Spaceship:
-// FIXME: Update this once we support <=> expressions.
-llvm_unreachable("<=> expressions not supported yet");
+BinaryOp = BO_Cmp;
+return Stmt::BinaryOperatorClass;
 
   case OO_AmpAmp:
 BinaryOp = BO_LAnd;

diff  --git a/clang/test/SemaCXX/cxx2a-three-way-comparison.cpp 
b/clang/test/SemaCXX/cxx2a-three-way-comparison.cpp
index eb1480ce6102..29ae95066e27 100644
--- a/clang/test/SemaCXX/cxx2a-three-way-comparison.cpp
+++ b/clang/test/SemaCXX/cxx2a-three-way-comparison.cpp
@@ -1,5 +1,14 @@
 // RUN: %clang_cc1 -std=c++2a -verify %s
 
+// Keep this test before any declarations of operator<=>.
+namespace PR44786 {
+  template void f(decltype(T{} <=> T{})) {} // expected-note 
{{previous}}
+
+  struct S {};
+  int operator<=>(S const &, S const &);
+  template void f(decltype(T{} <=> T{})) {} // expected-error 
{{redefinition}}
+}
+
 struct A {};
 constexpr int operator<=>(A a, A b) { return 42; }
 static_assert(operator<=>(A(), A()) == 42);



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


[llvm-branch-commits] [clang] 5175565 - Add -std=c++20 flag, replace C++2a with C++20 throughout the Clang

2020-02-19 Thread Richard Smith via llvm-branch-commits

Author: Richard Smith
Date: 2020-02-19T13:37:59-08:00
New Revision: 5175565cf154aede57354336102a7f6e15a16a20

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

LOG: Add -std=c++20 flag, replace C++2a with C++20 throughout the Clang
user interface and documentation, and update __cplusplus for C++20.

WG21 considers the C++20 standard to be finished (even though it still
has some more steps to pass through in the ISO process).

The old flag names are accepted for compatibility, as usual, and we
still have lots of references to C++2a in comments and identifiers;
those can be cleaned up separately.

(cherry picked from commit 24ad121582454e625bdad125c90d9ac0dae948c8)

Added: 


Modified: 
clang/docs/LanguageExtensions.rst
clang/include/clang/Basic/DiagnosticASTKinds.td
clang/include/clang/Basic/DiagnosticCommonKinds.td
clang/include/clang/Basic/DiagnosticFrontendKinds.td
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/LangStandards.def
clang/include/clang/Basic/StmtNodes.td
clang/lib/Frontend/InitPreprocessor.cpp
clang/test/CXX/basic/basic.lookup/basic.lookup.unqual/p3.cpp
clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp
clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp
clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p1.cpp
clang/test/CXX/drs/dr2xx.cpp
clang/test/CXX/drs/dr6xx.cpp
clang/test/CXX/expr/expr.prim/expr.prim.lambda/p8.cpp
clang/test/Driver/unknown-std.cpp
clang/test/Lexer/cxx2a-spaceship.cpp
clang/test/Lexer/cxx2a_keyword_as_cxx17.cpp
clang/test/Parser/cxx1z-decomposition.cpp
clang/test/Parser/cxx2a-concept-declaration.cpp
clang/test/Parser/cxx2a-inline-nested-namespace-definition.cpp
clang/test/Parser/explicit-bool.cpp
clang/test/Preprocessor/init.c
clang/test/SemaCXX/cxx17-compat.cpp
clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp
clang/test/SemaCXX/cxx1z-decomposition.cpp
clang/test/SemaCXX/cxx2a-compat.cpp
clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
clang/test/SemaCXX/member-init.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index f1df9dd93f93..456bcb305e3b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -122,7 +122,7 @@ of ``cxx_rvalue_references``.
 ``__has_cpp_attribute``
 ---
 
-This function-like macro is available in C++2a by default, and is provided as 
an
+This function-like macro is available in C++20 by default, and is provided as 
an
 extension in earlier language standards. It takes a single argument that is the
 name of a double-square-bracket-style attribute. The argument can either be a
 single identifier or a scoped identifier. If the attribute is supported, a

diff  --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index 95505b00344f..a0c15ba1cb05 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -13,7 +13,7 @@ def note_expr_divide_by_zero : Note<"division by zero">;
 def note_constexpr_invalid_cast : Note<
   "%select{reinterpret_cast|dynamic_cast|cast that performs the conversions of"
   " a reinterpret_cast|cast from %1}0 is not allowed in a constant expression"
-  "%select{| in C++ standards before C++2a||}0">;
+  "%select{| in C++ standards before C++20||}0">;
 def note_constexpr_invalid_downcast : Note<
   "cannot cast object of dynamic type %0 to type %1">;
 def note_constexpr_overflow : Note<
@@ -33,7 +33,7 @@ def note_constexpr_no_return : Note<
   "control reached end of constexpr function">;
 def note_constexpr_virtual_call : Note<
   "cannot evaluate call to virtual function in a constant expression "
-  "in C++ standards before C++2a">;
+  "in C++ standards before C++20">;
 def note_constexpr_pure_virtual_call : Note<
   "pure virtual function %q0 called">;
 def note_constexpr_polymorphic_unknown_dynamic_type : Note<
@@ -102,7 +102,7 @@ def note_constexpr_var_init_non_constant : Note<
   "initializer of %0 is not a constant expression">;
 def note_constexpr_typeid_polymorphic : Note<
   "typeid applied to expression of polymorphic type %0 is "
-  "not allowed in a constant expression in C++ standards before C++2a">;
+  "not allowed in a constant expression in C++ standards before C++20">;
 def note_constexpr_void_comparison : Note<
   "comparison between unequal pointers to void has unspecified r

[llvm-branch-commits] [ubsan] Remove -fsanitizer=vptr from -fsanitizer=undefined (PR #121115)

2024-12-26 Thread Richard Smith via llvm-branch-commits

https://github.com/zygoloid commented:

I think this is reasonable. Has it been discussed on discourse? Would be good 
to make sure people have a chance to comment, and to increase visibility of the 
change.

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


[llvm-branch-commits] [ubsan] Remove -fsanitizer=vptr from -fsanitizer=undefined (PR #121115)

2024-12-26 Thread Richard Smith via llvm-branch-commits

https://github.com/zygoloid edited 
https://github.com/llvm/llvm-project/pull/121115
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [ubsan] Remove -fsanitizer=vptr from -fsanitizer=undefined (PR #121115)

2024-12-26 Thread Richard Smith via llvm-branch-commits


@@ -210,11 +210,6 @@ Available checks are:
  (see ``-fsanitize=implicit-integer-conversion``).
   -  ``-fsanitize=vla-bound``: A variable-length array whose bound
  does not evaluate to a positive value.
-  -  ``-fsanitize=vptr``: Use of an object whose vptr indicates that it is of

zygoloid wrote:

I think this shouldn't be removed from here and moved to the next section -- 
this is a list of all available individual checks, so `vptr` should still be 
here.

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


[llvm-branch-commits] [ubsan] Remove -fsanitizer=vptr from -fsanitizer=undefined (PR #121115)

2024-12-26 Thread Richard Smith via llvm-branch-commits


@@ -210,11 +210,6 @@ Available checks are:
  (see ``-fsanitize=implicit-integer-conversion``).
   -  ``-fsanitize=vla-bound``: A variable-length array whose bound
  does not evaluate to a positive value.
-  -  ``-fsanitize=vptr``: Use of an object whose vptr indicates that it is of
- the wrong dynamic type, or that its lifetime has not begun or has ended.
- Incompatible with ``-fno-rtti``. Link must be performed by ``clang++``, 
not
- ``clang``, to make sure C++-specific parts of the runtime library and C++
- standard libraries are present.
 
 You can also use the following check groups:

zygoloid wrote:

The first bullet below should mention that `-fsanitize=undefined` doesn't 
include `-fsanitize=vptr`.

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


[llvm-branch-commits] [clang] release/21.x: [clang] Fix pointer comparisons between pointers to constexpr-unknown (#147663) (PR #148907)

2025-07-17 Thread Richard Smith via llvm-branch-commits

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

LG for branch.

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