From 43eba818cd2b03302d072f7fa0aa32bfa36fa3a8 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 23 Dec 2014 15:57:12 +0000 Subject: [PATCH] This reverts commit r224668 and r224667. r224667 broke bootstrap on Fedora 20 X86_64 (at least). See pr22006 for the details. r224668 depends on r224667. llvm-svn: 224770 --- clang/lib/AST/ASTDiagnostic.cpp | 35 ++++++++++++++++++------------- clang/lib/Sema/SemaTemplate.cpp | 7 ------- clang/test/Misc/diag-template-diffing.cpp | 14 ------------- 3 files changed, 21 insertions(+), 35 deletions(-) diff --git a/clang/lib/AST/ASTDiagnostic.cpp b/clang/lib/AST/ASTDiagnostic.cpp index f55e032..3212359 100644 --- a/clang/lib/AST/ASTDiagnostic.cpp +++ b/clang/lib/AST/ASTDiagnostic.cpp @@ -998,6 +998,10 @@ class TemplateDiff { (!HasFromValueDecl && !HasToValueDecl)) && "Template argument cannot be both integer and declaration"); + unsigned ParamWidth = 128; // Safe default + if (FromDefaultNonTypeDecl->getType()->isIntegralOrEnumerationType()) + ParamWidth = Context.getIntWidth(FromDefaultNonTypeDecl->getType()); + if (!HasFromInt && !HasToInt && !HasFromValueDecl && !HasToValueDecl) { Tree.SetNode(FromExpr, ToExpr); Tree.SetDefault(FromIter.isEnd() && FromExpr, ToIter.isEnd() && ToExpr); @@ -1009,14 +1013,14 @@ class TemplateDiff { } if (HasFromInt && HasToInt) { Tree.SetNode(FromInt, ToInt, HasFromInt, HasToInt); - Tree.SetSame(FromInt == ToInt); + Tree.SetSame(IsSameConvertedInt(ParamWidth, FromInt, ToInt)); Tree.SetKind(DiffTree::Integer); } else if (HasFromInt || HasToInt) { Tree.SetNode(FromInt, ToInt, HasFromInt, HasToInt); Tree.SetSame(false); Tree.SetKind(DiffTree::Integer); } else { - Tree.SetSame(IsEqualExpr(Context, FromExpr, ToExpr) || + Tree.SetSame(IsEqualExpr(Context, ParamWidth, FromExpr, ToExpr) || (FromNullPtr && ToNullPtr)); Tree.SetNullPtr(FromNullPtr, ToNullPtr); Tree.SetKind(DiffTree::Expression); @@ -1030,11 +1034,7 @@ class TemplateDiff { if (!HasToInt && ToExpr) HasToInt = GetInt(Context, ToIter, ToExpr, ToInt); Tree.SetNode(FromInt, ToInt, HasFromInt, HasToInt); - if (HasFromInt && HasToInt) { - Tree.SetSame(FromInt == ToInt); - } else { - Tree.SetSame(false); - } + Tree.SetSame(IsSameConvertedInt(ParamWidth, FromInt, ToInt)); Tree.SetDefault(FromIter.isEnd() && HasFromInt, ToIter.isEnd() && HasToInt); Tree.SetKind(DiffTree::Integer); @@ -1212,7 +1212,7 @@ class TemplateDiff { /// GetInt - Retrieves the template integer argument, including evaluating /// default arguments. static bool GetInt(ASTContext &Context, const TSTiterator &Iter, - Expr *ArgExpr, llvm::APSInt &Int) { + Expr *ArgExpr, llvm::APInt &Int) { // Default, value-depenedent expressions require fetching // from the desugared TemplateArgument, otherwise expression needs to // be evaluatable. @@ -1302,8 +1302,18 @@ class TemplateDiff { return nullptr; } + /// IsSameConvertedInt - Returns true if both integers are equal when + /// converted to an integer type with the given width. + static bool IsSameConvertedInt(unsigned Width, const llvm::APSInt &X, + const llvm::APSInt &Y) { + llvm::APInt ConvertedX = X.extOrTrunc(Width); + llvm::APInt ConvertedY = Y.extOrTrunc(Width); + return ConvertedX == ConvertedY; + } + /// IsEqualExpr - Returns true if the expressions evaluate to the same value. - static bool IsEqualExpr(ASTContext &Context, Expr *FromExpr, Expr *ToExpr) { + static bool IsEqualExpr(ASTContext &Context, unsigned ParamWidth, + Expr *FromExpr, Expr *ToExpr) { if (FromExpr == ToExpr) return true; @@ -1335,7 +1345,7 @@ class TemplateDiff { switch (FromVal.getKind()) { case APValue::Int: - return FromVal.getInt() == ToVal.getInt(); + return IsSameConvertedInt(ParamWidth, FromVal.getInt(), ToVal.getInt()); case APValue::LValue: { APValue::LValueBase FromBase = FromVal.getLValueBase(); APValue::LValueBase ToBase = ToVal.getLValueBase(); @@ -1645,14 +1655,11 @@ class TemplateDiff { } Unbold(); } - + /// HasExtraInfo - Returns true if E is not an integer literal or the /// negation of an integer literal bool HasExtraInfo(Expr *E) { if (!E) return false; - - E = E->IgnoreImpCasts(); - if (isa(E)) return false; if (UnaryOperator *UO = dyn_cast(E)) diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 2099649..67c36a5 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -3433,13 +3433,6 @@ bool Sema::CheckTemplateArgument(NamedDecl *Param, if (Res.isInvalid()) return true; - // If the resulting expression is new, then use it in place of the - // old expression in the template argument. - if (Res.get() != Arg.getArgument().getAsExpr()) { - TemplateArgument TA(Res.get()); - Arg = TemplateArgumentLoc(TA, Res.get()); - } - Converted.push_back(Result); break; } diff --git a/clang/test/Misc/diag-template-diffing.cpp b/clang/test/Misc/diag-template-diffing.cpp index 9f4806f..bdd6d62 100644 --- a/clang/test/Misc/diag-template-diffing.cpp +++ b/clang/test/Misc/diag-template-diffing.cpp @@ -1247,20 +1247,6 @@ template using A7 = A<(T::num)>; // CHECK-ELIDE-NOTREE: type alias template redefinition with different types ('A<(T::num), (default) 0>' vs 'A') } -namespace TemplateArgumentImplicitConversion { -template struct condition {}; - -struct is_const { - constexpr operator int() const { return 10; } -}; - -using T = condition<(is_const())>; -void foo(const T &t) { - T &t2 = t; -} -// CHECK-ELIDE-NOTREE: binding of reference to type 'condition<[...]>' to a value of type 'const condition<[...]>' drops qualifiers -} - // CHECK-ELIDE-NOTREE: {{[0-9]*}} errors generated. // CHECK-NOELIDE-NOTREE: {{[0-9]*}} errors generated. // CHECK-ELIDE-TREE: {{[0-9]*}} errors generated. -- 2.7.4