Re: r338467 - Avoid exposing name for range-based for '__range' variables in lifetime warnings.
There's definitely scope for improving this diagnostic text further. Right now I don't think there's an easy way to figure out that the variable is the range variable in a range-based for loop, but I think that case is common enough that that's the level of special-case we should be looking at here. If we track that state, something like "error: range refers to a temporary object that will be destroyed before the first iteration of the loop" would seem much preferable. On Tue, 7 Aug 2018 at 09:28, David Blaikie via cfe-commits < cfe-commits@lists.llvm.org> wrote: > Reckon there's a chance of improved diagnostic text in cases like this? > Will users understand what the problem is/how to fix it when they read > "temporary > implicitly bound to local reference will be destroyed at the end of the > full-expression" - feels very standard-ese-y to me? & I appreciate teh > desire/need for precision, I wonder if there's better ways to communicate > it to the user... :/ > > On Tue, Jul 31, 2018 at 6:03 PM Richard Smith via cfe-commits < > cfe-commits@lists.llvm.org> wrote: > >> Author: rsmith >> Date: Tue Jul 31 18:03:33 2018 >> New Revision: 338467 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=338467&view=rev >> Log: >> Avoid exposing name for range-based for '__range' variables in lifetime >> warnings. >> >> Modified: >> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td >> cfe/trunk/lib/Sema/SemaInit.cpp >> cfe/trunk/test/SemaCXX/attr-lifetimebound.cpp >> >> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=338467&r1=338466&r2=338467&view=diff >> >> == >> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) >> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Jul 31 >> 18:03:33 2018 >> @@ -7875,7 +7875,8 @@ def warn_ret_addr_label : Warning< >> def err_ret_local_block : Error< >>"returning block that lives on the local stack">; >> def note_local_var_initializer : Note< >> - "%select{via initialization of|binding reference}0 variable %1 here">; >> + "%select{via initialization of|binding reference}0 variable " >> + "%select{%2 |}1here">; >> def note_init_with_default_member_initalizer : Note< >>"initializing field %0 with default member initializer">; >> >> @@ -7907,13 +7908,14 @@ def note_lifetime_extending_member_decla >>"member with %select{reference|'std::initializer_list'}0 subobject}1 " >>"declared here">; >> def warn_dangling_variable : Warning< >> - "%select{temporary %select{whose address is used as value of|bound >> to}3 " >> - "%select{%select{|reference }3member of local variable|" >> - "local %select{variable|reference}3}1|" >> + "%select{temporary %select{whose address is used as value of|" >> + "%select{|implicitly }2bound to}4 " >> + "%select{%select{|reference }4member of local variable|" >> + "local %select{variable|reference}4}1|" >>"array backing " >>"%select{initializer list subobject of local variable|" >>"local initializer list}1}0 " >> - "%2 will be destroyed at the end of the full-expression">, >> + "%select{%3 |}2will be destroyed at the end of the full-expression">, >>InGroup; >> def warn_new_dangling_reference : Warning< >>"temporary bound to reference member of allocated object " >> >> Modified: cfe/trunk/lib/Sema/SemaInit.cpp >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=338467&r1=338466&r2=338467&view=diff >> >> == >> --- cfe/trunk/lib/Sema/SemaInit.cpp (original) >> +++ cfe/trunk/lib/Sema/SemaInit.cpp Tue Jul 31 18:03:33 2018 >> @@ -6847,8 +6847,9 @@ void Sema::checkInitializerLifetime(cons >>return false; >> >> Diag(DiagLoc, diag::warn_dangling_variable) >> -<< RK << !Entity.getParent() << ExtendingEntity->getDecl() >> -<< Init->isGLValue() << DiagRange; >> +<< RK << !Entity.getParent() >> +
r339187 - Clean up and simplify RequireCompleteType.
Author: rsmith Date: Tue Aug 7 14:35:41 2018 New Revision: 339187 URL: http://llvm.org/viewvc/llvm-project?rev=339187&view=rev Log: Clean up and simplify RequireCompleteType. No functional change intended, except that we will now produce more "declared here" notes. Modified: cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp cfe/trunk/lib/Sema/SemaType.cpp cfe/trunk/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp cfe/trunk/test/SemaObjC/arc.m Modified: cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp?rev=339187&r1=339186&r2=339187&view=diff == --- cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp (original) +++ cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp Tue Aug 7 14:35:41 2018 @@ -209,11 +209,13 @@ bool Sema::RequireCompleteDeclContext(CX if (!tag || tag->isDependentContext()) return false; + // Grab the tag definition, if there is one. + QualType type = Context.getTypeDeclType(tag); + tag = type->getAsTagDecl(); + // If we're currently defining this type, then lookup into the // type is okay: don't complain that it isn't complete yet. - QualType type = Context.getTypeDeclType(tag); - const TagType *tagType = type->getAs(); - if (tagType && tagType->isBeingDefined()) + if (tag->isBeingDefined()) return false; SourceLocation loc = SS.getLastQualifierNameLoc(); @@ -229,13 +231,13 @@ bool Sema::RequireCompleteDeclContext(CX // Fixed enum types are complete, but they aren't valid as scopes // until we see a definition, so awkwardly pull out this special // case. - const EnumType *enumType = dyn_cast_or_null(tagType); - if (!enumType) + auto *EnumD = dyn_cast(tag); + if (!EnumD) return false; - if (enumType->getDecl()->isCompleteDefinition()) { + if (EnumD->isCompleteDefinition()) { // If we know about the definition but it is not visible, complain. NamedDecl *SuggestedDef = nullptr; -if (!hasVisibleDefinition(enumType->getDecl(), &SuggestedDef, +if (!hasVisibleDefinition(EnumD, &SuggestedDef, /*OnlyNeedComplete*/false)) { // If the user is going to see an error here, recover by making the // definition visible. @@ -249,11 +251,11 @@ bool Sema::RequireCompleteDeclContext(CX // Try to instantiate the definition, if this is a specialization of an // enumeration temploid. - EnumDecl *ED = enumType->getDecl(); - if (EnumDecl *Pattern = ED->getInstantiatedFromMemberEnum()) { -MemberSpecializationInfo *MSI = ED->getMemberSpecializationInfo(); + if (EnumDecl *Pattern = EnumD->getInstantiatedFromMemberEnum()) { +MemberSpecializationInfo *MSI = EnumD->getMemberSpecializationInfo(); if (MSI->getTemplateSpecializationKind() != TSK_ExplicitSpecialization) { - if (InstantiateEnum(loc, ED, Pattern, getTemplateInstantiationArgs(ED), + if (InstantiateEnum(loc, EnumD, Pattern, + getTemplateInstantiationArgs(EnumD), TSK_ImplicitInstantiation)) { SS.SetInvalid(SS.getRange()); return true; Modified: cfe/trunk/lib/Sema/SemaType.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=339187&r1=339186&r2=339187&view=diff == --- cfe/trunk/lib/Sema/SemaType.cpp (original) +++ cfe/trunk/lib/Sema/SemaType.cpp Tue Aug 7 14:35:41 2018 @@ -7684,39 +7684,24 @@ bool Sema::RequireCompleteTypeImpl(Sourc return false; } - const TagType *Tag = T->getAs(); - const ObjCInterfaceType *IFace = T->getAs(); + TagDecl *Tag = dyn_cast_or_null(Def); + ObjCInterfaceDecl *IFace = dyn_cast_or_null(Def); - // If there's an unimported definition of this type in a module (for - // instance, because we forward declared it, then imported the definition), - // import that definition now. - // - // FIXME: What about other cases where an import extends a redeclaration - // chain for a declaration that can be accessed through a mechanism other - // than name lookup (eg, referenced in a template, or a variable whose type - // could be completed by the module)? - // - // FIXME: Should we map through to the base array element type before - // checking for a tag type? + // Give the external source a chance to provide a definition of the type. + // This is kept separate from completing the redeclaration chain so that + // external sources such as LLDB can avoid synthesizing a type definition + // unless it's actually needed. if (Tag || IFace) { -NamedDecl *D = -Tag ? static_cast(Tag->getDecl()) : IFace->getDecl(); - // Avoid diagnosing invalid decls as incomplete. -if (D->isInvalidDecl()) +if (Def->isInvalidDecl()) return true; // Give the external AST source a chance to complete the type. if (auto *Source = Context.getExternalSource
r339210 - PR38286: Don't crash when attempting to define a constructor for an
Author: rsmith Date: Tue Aug 7 17:42:42 2018 New Revision: 339210 URL: http://llvm.org/viewvc/llvm-project?rev=339210&view=rev Log: PR38286: Don't crash when attempting to define a constructor for an incomplete class template. Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp cfe/trunk/test/SemaCXX/constructor.cpp Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=339210&r1=339209&r2=339210&view=diff == --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original) +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Tue Aug 7 17:42:42 2018 @@ -113,9 +113,15 @@ ParsedType Sema::getConstructorName(Iden break; } } - if (!InjectedClassName && CurClass->isInvalidDecl()) + if (!InjectedClassName) { +if (!CurClass->isInvalidDecl()) { + // FIXME: RequireCompleteDeclContext doesn't check dependent contexts + // properly. Work around it here for now. + Diag(SS.getLastQualifierNameLoc(), + diag::err_incomplete_nested_name_spec) << CurClass << SS.getRange(); +} return ParsedType(); - assert(InjectedClassName && "couldn't find injected class name"); + } QualType T = Context.getTypeDeclType(InjectedClassName); DiagnoseUseOfDecl(InjectedClassName, NameLoc); Modified: cfe/trunk/test/SemaCXX/constructor.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constructor.cpp?rev=339210&r1=339209&r2=339210&view=diff == --- cfe/trunk/test/SemaCXX/constructor.cpp (original) +++ cfe/trunk/test/SemaCXX/constructor.cpp Tue Aug 7 17:42:42 2018 @@ -86,3 +86,14 @@ A::S::operator int() { return 1; } A::S::~S() {} +namespace PR38286 { + // FIXME: It'd be nice to give more consistent diagnostics for these cases + // (but they're all failing for somewhat different reasons...). + template struct A; + template A::A() {} // expected-error {{incomplete type 'A' named in nested name specifier}} + /*FIXME: needed to recover properly from previous error*/; + template struct B; + template void B::f() {} // expected-error {{out-of-line definition of 'f' from class 'B'}} + template struct C; + template C::~C() {} // expected-error {{no type named 'C' in 'C'}} +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r339210 - PR38286: Don't crash when attempting to define a constructor for an
Would be good to get this into the Clang 7 release. On Tue, 7 Aug 2018 at 17:43, Richard Smith via cfe-commits < cfe-commits@lists.llvm.org> wrote: > Author: rsmith > Date: Tue Aug 7 17:42:42 2018 > New Revision: 339210 > > URL: http://llvm.org/viewvc/llvm-project?rev=339210&view=rev > Log: > PR38286: Don't crash when attempting to define a constructor for an > incomplete class template. > > Modified: > cfe/trunk/lib/Sema/SemaExprCXX.cpp > cfe/trunk/test/SemaCXX/constructor.cpp > > Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=339210&r1=339209&r2=339210&view=diff > > == > --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original) > +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Tue Aug 7 17:42:42 2018 > @@ -113,9 +113,15 @@ ParsedType Sema::getConstructorName(Iden >break; > } >} > - if (!InjectedClassName && CurClass->isInvalidDecl()) > + if (!InjectedClassName) { > +if (!CurClass->isInvalidDecl()) { > + // FIXME: RequireCompleteDeclContext doesn't check dependent > contexts > + // properly. Work around it here for now. > + Diag(SS.getLastQualifierNameLoc(), > + diag::err_incomplete_nested_name_spec) << CurClass << > SS.getRange(); > +} > return ParsedType(); > - assert(InjectedClassName && "couldn't find injected class name"); > + } > >QualType T = Context.getTypeDeclType(InjectedClassName); >DiagnoseUseOfDecl(InjectedClassName, NameLoc); > > Modified: cfe/trunk/test/SemaCXX/constructor.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constructor.cpp?rev=339210&r1=339209&r2=339210&view=diff > > == > --- cfe/trunk/test/SemaCXX/constructor.cpp (original) > +++ cfe/trunk/test/SemaCXX/constructor.cpp Tue Aug 7 17:42:42 2018 > @@ -86,3 +86,14 @@ A::S::operator int() { return 1; } > > A::S::~S() {} > > +namespace PR38286 { > + // FIXME: It'd be nice to give more consistent diagnostics for these > cases > + // (but they're all failing for somewhat different reasons...). > + template struct A; > + template A::A() {} // expected-error {{incomplete type > 'A' named in nested name specifier}} > + /*FIXME: needed to recover properly from previous error*/; > + template struct B; > + template void B::f() {} // expected-error {{out-of-line > definition of 'f' from class 'B'}} > + template struct C; > + template C::~C() {} // expected-error {{no type named > 'C' in 'C'}} > +} > > > ___ > cfe-commits mailing list > cfe-commits@lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits > ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r339304 - Delete some unreachable AST printing code.
Author: rsmith Date: Wed Aug 8 17:44:49 2018 New Revision: 339304 URL: http://llvm.org/viewvc/llvm-project?rev=339304&view=rev Log: Delete some unreachable AST printing code. Modified: cfe/trunk/lib/AST/TypePrinter.cpp Modified: cfe/trunk/lib/AST/TypePrinter.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypePrinter.cpp?rev=339304&r1=339303&r2=339304&view=diff == --- cfe/trunk/lib/AST/TypePrinter.cpp (original) +++ cfe/trunk/lib/AST/TypePrinter.cpp Wed Aug 8 17:44:49 2018 @@ -1427,22 +1427,6 @@ void TypePrinter::printAttributedAfter(c ->getExtInfo().getProducesResult()) return; - // Print nullability type specifiers that occur after - if (T->getAttrKind() == AttributedType::attr_nonnull || - T->getAttrKind() == AttributedType::attr_nullable || - T->getAttrKind() == AttributedType::attr_null_unspecified) { -if (T->getAttrKind() == AttributedType::attr_nonnull) - OS << " _Nonnull"; -else if (T->getAttrKind() == AttributedType::attr_nullable) - OS << " _Nullable"; -else if (T->getAttrKind() == AttributedType::attr_null_unspecified) - OS << " _Null_unspecified"; -else - llvm_unreachable("unhandled nullability"); - -return; - } - if (T->getAttrKind() == AttributedType::attr_lifetimebound) { OS << " [[clang::lifetimebound]]"; return; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r339306 - Refactor attribute printing to be a bit more obviously-correct.
Author: rsmith Date: Wed Aug 8 18:21:06 2018 New Revision: 339306 URL: http://llvm.org/viewvc/llvm-project?rev=339306&view=rev Log: Refactor attribute printing to be a bit more obviously-correct. No functionality change intended. Added: cfe/trunk/test/Misc/ast-print-attr.c Modified: cfe/trunk/lib/AST/TypePrinter.cpp Modified: cfe/trunk/lib/AST/TypePrinter.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypePrinter.cpp?rev=339306&r1=339305&r2=339306&view=diff == --- cfe/trunk/lib/AST/TypePrinter.cpp (original) +++ cfe/trunk/lib/AST/TypePrinter.cpp Wed Aug 8 18:21:06 2018 @@ -1398,25 +1398,21 @@ void TypePrinter::printAttributedAfter(c T->getAttrKind() == AttributedType::attr_objc_ownership) return printAfter(T->getEquivalentType(), OS); - if (T->getAttrKind() == AttributedType::attr_objc_kindof) -return; - - // TODO: not all attributes are GCC-style attributes. - if (T->isMSTypeSpec()) -return; - - // Nothing to print after. - if (T->getAttrKind() == AttributedType::attr_nonnull || - T->getAttrKind() == AttributedType::attr_nullable || - T->getAttrKind() == AttributedType::attr_null_unspecified) -return printAfter(T->getModifiedType(), OS); - // If this is a calling convention attribute, don't print the implicit CC from // the modified type. SaveAndRestore MaybeSuppressCC(InsideCCAttribute, T->isCallingConv()); printAfter(T->getModifiedType(), OS); + // Some attributes are printed as qualifiers before the type, so we have + // nothing left to do. + if (T->getAttrKind() == AttributedType::attr_objc_kindof || + T->isMSTypeSpec() || + T->getAttrKind() == AttributedType::attr_nonnull || + T->getAttrKind() == AttributedType::attr_nullable || + T->getAttrKind() == AttributedType::attr_null_unspecified) +return; + // Don't print the inert __unsafe_unretained attribute at all. if (T->getAttrKind() == AttributedType::attr_objc_inert_unsafe_unretained) return; Added: cfe/trunk/test/Misc/ast-print-attr.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/ast-print-attr.c?rev=339306&view=auto == --- cfe/trunk/test/Misc/ast-print-attr.c (added) +++ cfe/trunk/test/Misc/ast-print-attr.c Wed Aug 8 18:21:06 2018 @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -ast-print -x objective-c++ -fms-extensions %s -o - | FileCheck %s + +// CHECK: using A = __kindof id (*)[1]; +using A = __kindof id (*)[1]; + +// CHECK: using B = int ** __ptr32 *[3]; +using B = int ** __ptr32 *[3]; + +// FIXME: This is the wrong spelling for the attribute. +// FIXME: Too many parens here! +// CHECK: using C = int ((*))() __attribute__((cdecl)); +using C = int (*)() [[gnu::cdecl]]; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r339387 - Revert -r339382, which apparently breaks the Windows build.
On Thu, 9 Aug 2018 at 14:14, Erich Keane via cfe-commits < cfe-commits@lists.llvm.org> wrote: > Author: erichkeane > Date: Thu Aug 9 14:13:46 2018 > New Revision: 339387 > > URL: http://llvm.org/viewvc/llvm-project?rev=339387&view=rev > Log: > Revert -r339382, which apparently breaks the Windows build. > > Modified: > cfe/trunk/include/clang/Sema/ParsedAttr.h > > Modified: cfe/trunk/include/clang/Sema/ParsedAttr.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/ParsedAttr.h?rev=339387&r1=339386&r2=339387&view=diff > > == > --- cfe/trunk/include/clang/Sema/ParsedAttr.h (original) > +++ cfe/trunk/include/clang/Sema/ParsedAttr.h Thu Aug 9 14:13:46 2018 > @@ -118,7 +118,9 @@ class ParsedAttr final > : private llvm::TrailingObjects< >ParsedAttr, ArgsUnion, detail::AvailabilityData, >detail::TypeTagForDatatypeData, ParsedType, > detail::PropertyData> { > - friend class TrailingObjects; > + friend class llvm::TrailingObjects< > + ParsedAttr, ArgsUnion, detail::AvailabilityData, > + detail::TypeTagForDatatypeData, ParsedType, detail::PropertyData>; > You need to use "friend TrailingObjects;" here, not "friend class TrailingObjects;", to avoid breaking MSVC (which doesn't implement injected-class-names quite according to spec). >size_t numTrailingObjects(OverloadToken) const { return > NumArgs; } >size_t numTrailingObjects(OverloadToken) > const { > > > ___ > cfe-commits mailing list > cfe-commits@lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits > ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r339624 - Fix Clang warnings and bad #include filenames in r339595 and r339599.
Author: rsmith Date: Mon Aug 13 15:07:11 2018 New Revision: 339624 URL: http://llvm.org/viewvc/llvm-project?rev=339624&view=rev Log: Fix Clang warnings and bad #include filenames in r339595 and r339599. Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h?rev=339624&r1=339623&r2=339624&view=diff == --- cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h (original) +++ cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h Mon Aug 13 15:07:11 2018 @@ -32,6 +32,8 @@ class FieldNode { protected: const FieldRegion *FR; + ~FieldNode() = default; + public: FieldNode(const FieldRegion *FR) : FR(FR) { assert(FR); } Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp?rev=339624&r1=339623&r2=339624&view=diff == --- cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp Mon Aug 13 15:07:11 2018 @@ -46,7 +46,7 @@ // //===--===// -#include "ClangSACheckers.h" +#include "../ClangSACheckers.h" #include "UninitializedObject.h" #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h" #include "clang/StaticAnalyzer/Core/Checker.h" @@ -74,7 +74,7 @@ public: /// A basic field type, that is not a pointer or a reference, it's dynamic and /// static type is the same. -class RegularField : public FieldNode { +class RegularField final : public FieldNode { public: RegularField(const FieldRegion *FR) : FieldNode(FR) {} @@ -84,7 +84,7 @@ public: virtual void printPrefix(llvm::raw_ostream &Out) const override {} - virtual void printNode(llvm::raw_ostream &Out) const { + virtual void printNode(llvm::raw_ostream &Out) const override { Out << getVariableName(getDecl()); } Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp?rev=339624&r1=339623&r2=339624&view=diff == --- cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp Mon Aug 13 15:07:11 2018 @@ -18,7 +18,7 @@ // //===--===// -#include "ClangSACheckers.h" +#include "../ClangSACheckers.h" #include "UninitializedObject.h" #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h" #include "clang/StaticAnalyzer/Core/Checker.h" @@ -31,7 +31,7 @@ using namespace clang::ento; namespace { /// Represents a pointer or a reference field. -class LocField : public FieldNode { +class LocField final : public FieldNode { /// We'll store whether the pointee or the pointer itself is uninitialited. const bool IsDereferenced; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r339623 - Model type attributes as regular Attrs.
Author: rsmith Date: Mon Aug 13 15:07:09 2018 New Revision: 339623 URL: http://llvm.org/viewvc/llvm-project?rev=339623&view=rev Log: Model type attributes as regular Attrs. Specifically, AttributedType now tracks a regular attr::Kind rather than having its own parallel Kind enumeration, and AttributedTypeLoc now holds an Attr* instead of holding an ad-hoc collection of Attr fields. Differential Revision: https://reviews.llvm.org/D50526 Modified: cfe/trunk/include/clang/AST/ASTContext.h cfe/trunk/include/clang/AST/Attr.h cfe/trunk/include/clang/AST/Type.h cfe/trunk/include/clang/AST/TypeLoc.h cfe/trunk/include/clang/Basic/Attr.td cfe/trunk/include/clang/Sema/Sema.h cfe/trunk/include/clang/Serialization/ASTReader.h cfe/trunk/include/clang/Serialization/ASTWriter.h cfe/trunk/lib/ARCMigrate/TransGCAttrs.cpp cfe/trunk/lib/ARCMigrate/Transforms.cpp cfe/trunk/lib/AST/ASTContext.cpp cfe/trunk/lib/AST/Type.cpp cfe/trunk/lib/AST/TypeLoc.cpp cfe/trunk/lib/AST/TypePrinter.cpp cfe/trunk/lib/Sema/SemaDecl.cpp cfe/trunk/lib/Sema/SemaExpr.cpp cfe/trunk/lib/Sema/SemaInit.cpp cfe/trunk/lib/Sema/SemaObjCProperty.cpp cfe/trunk/lib/Sema/SemaType.cpp cfe/trunk/lib/Sema/TreeTransform.h cfe/trunk/lib/Serialization/ASTReader.cpp cfe/trunk/lib/Serialization/ASTReaderDecl.cpp cfe/trunk/lib/Serialization/ASTWriter.cpp cfe/trunk/lib/StaticAnalyzer/Core/CheckerHelpers.cpp cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp Modified: cfe/trunk/include/clang/AST/ASTContext.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=339623&r1=339622&r2=339623&view=diff == --- cfe/trunk/include/clang/AST/ASTContext.h (original) +++ cfe/trunk/include/clang/AST/ASTContext.h Mon Aug 13 15:07:09 2018 @@ -31,6 +31,7 @@ #include "clang/AST/TemplateName.h" #include "clang/AST/Type.h" #include "clang/Basic/AddressSpaces.h" +#include "clang/Basic/AttrKinds.h" #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/LangOptions.h" @@ -1422,7 +1423,7 @@ public: QualType getInjectedClassNameType(CXXRecordDecl *Decl, QualType TST) const; - QualType getAttributedType(AttributedType::Kind attrKind, + QualType getAttributedType(attr::Kind attrKind, QualType modifiedType, QualType equivalentType); Modified: cfe/trunk/include/clang/AST/Attr.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Attr.h?rev=339623&r1=339622&r2=339623&view=diff == --- cfe/trunk/include/clang/AST/Attr.h (original) +++ cfe/trunk/include/clang/AST/Attr.h Mon Aug 13 15:07:09 2018 @@ -113,6 +113,19 @@ public: void printPretty(raw_ostream &OS, const PrintingPolicy &Policy) const; }; +class TypeAttr : public Attr { +protected: + TypeAttr(attr::Kind AK, SourceRange R, unsigned SpellingListIndex, + bool IsLateParsed) + : Attr(AK, R, SpellingListIndex, IsLateParsed) {} + +public: + static bool classof(const Attr *A) { +return A->getKind() >= attr::FirstTypeAttr && + A->getKind() <= attr::LastTypeAttr; + } +}; + class StmtAttr : public Attr { protected: StmtAttr(attr::Kind AK, SourceRange R, unsigned SpellingListIndex, Modified: cfe/trunk/include/clang/AST/Type.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=339623&r1=339622&r2=339623&view=diff == --- cfe/trunk/include/clang/AST/Type.h (original) +++ cfe/trunk/include/clang/AST/Type.h Mon Aug 13 15:07:09 2018 @@ -21,6 +21,7 @@ #include "clang/AST/NestedNameSpecifier.h" #include "clang/AST/TemplateName.h" #include "clang/Basic/AddressSpaces.h" +#include "clang/Basic/AttrKinds.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/ExceptionSpecificationType.h" #include "clang/Basic/LLVM.h" @@ -1870,7 +1871,16 @@ public: bool isObjCQualifiedClassType() const;// Class bool isObjCObjectOrInterfaceType() const; bool isObjCIdType() const;// id - bool isObjCInertUnsafeUnretainedType() const; + + /// Was this type written with the special inert-in-ARC __unsafe_unretained + /// qualifier? + /// + /// This approximates the answer to the following question: if this + /// translation unit were compiled in ARC, would this type be qualified + /// with __unsafe_unretained? + bool isObjCInertUnsafeUnretainedType() const { +return hasAttr(attr::ObjCInertUnsafeUnretained); + } /// Whether the type is Objective-C 'id' or a __kindof type of an /// object type, e.g., __kindof NSView * or __kindof id @@ -2084,6 +2094,10 @@ public: /// qualifiers from the outermost type. const ArrayType *castAsArrayTypeUnsafe() const; + /// Dete
r339747 - Silence "unused variable" warning.
Author: rsmith Date: Tue Aug 14 18:06:30 2018 New Revision: 339747 URL: http://llvm.org/viewvc/llvm-project?rev=339747&view=rev Log: Silence "unused variable" warning. Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp?rev=339747&r1=339746&r2=339747&view=diff == --- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp Tue Aug 14 18:06:30 2018 @@ -519,6 +519,7 @@ ProgramStateRef ExprEngine::finishArgume if (Optional V = getObjectUnderConstruction(State, {E, I}, LC)) { SVal VV = *V; + (void)VV; assert(cast(VV.castAs().getRegion()) ->getStackFrame()->getParent() ->getStackFrame() == LC->getStackFrame()); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libcxxabi] r339952 - Factor Node creation out of the demangler. No functionality change intended.
Author: rsmith Date: Thu Aug 16 15:04:36 2018 New Revision: 339952 URL: http://llvm.org/viewvc/llvm-project?rev=339952&view=rev Log: Factor Node creation out of the demangler. No functionality change intended. (This is a port of llvm r339944 to libcxxabi.) Modified: libcxxabi/trunk/src/cxa_demangle.cpp Modified: libcxxabi/trunk/src/cxa_demangle.cpp URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_demangle.cpp?rev=339952&r1=339951&r2=339952&view=diff == --- libcxxabi/trunk/src/cxa_demangle.cpp (original) +++ libcxxabi/trunk/src/cxa_demangle.cpp Thu Aug 16 15:04:36 2018 @@ -1953,6 +1953,23 @@ public: } }; +class DefaultAllocator { + BumpPointerAllocator Alloc; + +public: + void reset() { Alloc.reset(); } + + template T *makeNode(Args &&...args) { +return new (Alloc.allocate(sizeof(T))) +T(std::forward(args)...); + } + + void *allocateNodeArray(size_t sz) { +return Alloc.allocate(sizeof(Node *) * sz); + } +}; + +template struct Db { const char *First; const char *Last; @@ -1983,7 +2000,7 @@ struct Db { bool PermitForwardTemplateReferences = false; bool ParsingLambdaParams = false; - BumpPointerAllocator ASTAllocator; + Alloc ASTAllocator; Db(const char *First_, const char *Last_) : First(First_), Last(Last_) {} @@ -2000,13 +2017,12 @@ struct Db { } template T *make(Args &&... args) { -return new (ASTAllocator.allocate(sizeof(T))) -T(std::forward(args)...); +return ASTAllocator.template makeNode(std::forward(args)...); } template NodeArray makeNodeArray(It begin, It end) { size_t sz = static_cast(end - begin); -void *mem = ASTAllocator.allocate(sizeof(Node *) * sz); +void *mem = ASTAllocator.allocateNodeArray(sz); Node **data = new (mem) Node *[sz]; std::copy(begin, end, data); return NodeArray(data, sz); @@ -2143,7 +2159,7 @@ const char* parse_discriminator(const ch // // ::= // ::= -Node *Db::parseName(NameState *State) { +template Node *Db::parseName(NameState *State) { consumeIf('L'); // extension if (look() == 'N') @@ -2184,7 +2200,7 @@ Node *Db::parseName(NameState *State) { // := Z E [] // := Z E s [] // := Z Ed [ ] _ -Node *Db::parseLocalName(NameState *State) { +template Node *Db::parseLocalName(NameState *State) { if (!consumeIf('Z')) return nullptr; Node *Encoding = parseEncoding(); @@ -2216,7 +2232,7 @@ Node *Db::parseLocalName(NameState *Stat // ::= // ::= St# ::std:: // extension ::= StL -Node *Db::parseUnscopedName(NameState *State) { +template Node *Db::parseUnscopedName(NameState *State) { if (consumeIf("StL") || consumeIf("St")) { Node *R = parseUnqualifiedName(State); if (R == nullptr) @@ -2231,27 +2247,28 @@ Node *Db::parseUnscopedName(NameState *S //::= //::= //::= DC + E # structured binding declaration -Node *Db::parseUnqualifiedName(NameState *State) { - // s are special-cased in parseNestedName(). - Node *Result; - if (look() == 'U') - Result = parseUnnamedTypeName(State); - else if (look() >= '1' && look() <= '9') - Result = parseSourceName(State); - else if (consumeIf("DC")) { - size_t BindingsBegin = Names.size(); - do { - Node *Binding = parseSourceName(State); - if (Binding == nullptr) - return nullptr; - Names.push_back(Binding); - } while (!consumeIf('E')); - Result = make(popTrailingNodeArray(BindingsBegin)); - } else - Result = parseOperatorName(State); - if (Result != nullptr) - Result = parseAbiTags(Result); - return Result; +template +Node *Db::parseUnqualifiedName(NameState *State) { + // s are special-cased in parseNestedName(). + Node *Result; + if (look() == 'U') +Result = parseUnnamedTypeName(State); + else if (look() >= '1' && look() <= '9') +Result = parseSourceName(State); + else if (consumeIf("DC")) { +size_t BindingsBegin = Names.size(); +do { + Node *Binding = parseSourceName(State); + if (Binding == nullptr) +return nullptr; + Names.push_back(Binding); +} while (!consumeIf('E')); +Result = make(popTrailingNodeArray(BindingsBegin)); + } else +Result = parseOperatorName(State); + if (Result != nullptr) +Result = parseAbiTags(Result); + return Result; } // ::= Ut [] _ @@ -2260,7 +2277,7 @@ Node *Db::parseUnqualifiedName(NameState // ::= Ul E [ ] _ // // ::= + # Parameter types or "v" if the lambda has no parameters -Node *Db::parseUnnamedTypeName(NameState *) { +template Node *Db::parseUnnamedTypeName(NameState *) { if (consumeIf("Ut")) { StringView Count = parseNumber(); if (!consumeIf('_')) @@ -2289,7 +2306,7 @@ Node *Db::parseUnnamedTypeName(NameState } // ::= -Node *Db::parseSourceName(NameState *) { +template Node *Db::parseSo
r340074 - Improve diagnostic for missing comma in template parameter list.
Author: rsmith Date: Fri Aug 17 12:43:40 2018 New Revision: 340074 URL: http://llvm.org/viewvc/llvm-project?rev=340074&view=rev Log: Improve diagnostic for missing comma in template parameter list. Given 'typename T typename U', we would correctly diagnose the missing comma, but incorrectly disambiguate the first parameter as being a non-type parameter and complain that the 'T' is not a qualified-id. See also gcc.gnu.org/PR86998. Modified: cfe/trunk/lib/Parse/ParseTemplate.cpp cfe/trunk/test/CXX/temp/temp.param/p2.cpp Modified: cfe/trunk/lib/Parse/ParseTemplate.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTemplate.cpp?rev=340074&r1=340073&r2=340074&view=diff == --- cfe/trunk/lib/Parse/ParseTemplate.cpp (original) +++ cfe/trunk/lib/Parse/ParseTemplate.cpp Fri Aug 17 12:43:40 2018 @@ -425,7 +425,9 @@ bool Parser::isStartOfTemplateTypeParame } } - if (Tok.isNot(tok::kw_typename)) + // 'typedef' is a reasonably-common typo/thinko for 'typename', and is + // ill-formed otherwise. + if (Tok.isNot(tok::kw_typename) && Tok.isNot(tok::kw_typedef)) return false; // C++ [temp.param]p2: @@ -448,6 +450,13 @@ bool Parser::isStartOfTemplateTypeParame case tok::ellipsis: return true; + case tok::kw_typename: + case tok::kw_typedef: + case tok::kw_class: +// These indicate that a comma was missed after a type parameter, not that +// we have found a non-type parameter. +return true; + default: return false; } @@ -469,26 +478,25 @@ bool Parser::isStartOfTemplateTypeParame /// 'template' '<' template-parameter-list '>' 'class' identifier[opt] /// = id-expression NamedDecl *Parser::ParseTemplateParameter(unsigned Depth, unsigned Position) { - if (isStartOfTemplateTypeParameter()) -return ParseTypeParameter(Depth, Position); - - if (Tok.is(tok::kw_template)) -return ParseTemplateTemplateParameter(Depth, Position); + if (isStartOfTemplateTypeParameter()) { +// Is there just a typo in the input code? ('typedef' instead of 'typename') +if (Tok.is(tok::kw_typedef)) { + Diag(Tok.getLocation(), diag::err_expected_template_parameter); + + Diag(Tok.getLocation(), diag::note_meant_to_use_typename) + << FixItHint::CreateReplacement(CharSourceRange::getCharRange( + Tok.getLocation(), Tok.getEndLoc()), + "typename"); - // Is there just a typo in the input code? ('typedef' instead of 'typename') - if (Tok.is(tok::kw_typedef)) { -Diag(Tok.getLocation(), diag::err_expected_template_parameter); - -Diag(Tok.getLocation(), diag::note_meant_to_use_typename) -<< FixItHint::CreateReplacement(CharSourceRange::getCharRange( -Tok.getLocation(), Tok.getEndLoc()), -"typename"); - -Tok.setKind(tok::kw_typename); + Tok.setKind(tok::kw_typename); +} return ParseTypeParameter(Depth, Position); } + if (Tok.is(tok::kw_template)) +return ParseTemplateTemplateParameter(Depth, Position); + // If it's none of the above, then it must be a parameter declaration. // NOTE: This will pick up errors in the closure of the template parameter // list (e.g., template < ; Check here to implement >> style closures. Modified: cfe/trunk/test/CXX/temp/temp.param/p2.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.param/p2.cpp?rev=340074&r1=340073&r2=340074&view=diff == --- cfe/trunk/test/CXX/temp/temp.param/p2.cpp (original) +++ cfe/trunk/test/CXX/temp/temp.param/p2.cpp Fri Aug 17 12:43:40 2018 @@ -8,14 +8,17 @@ template struct X; template struct X; -// typename followed by aqualified-id denotes the type in a non-type +// typename followed by a qualified-id denotes the type in a non-type // parameter-declaration. template struct Y0; template::type Value> struct Y1; +template struct Y2; // expected-error{{expected ',' or '>'}} +template struct Y3; // expected-error{{expected a qualified name after 'typename'}} expected-error{{expected ',' or '>'}} +template struct Y4; // expected-error{{expected template parameter}} expected-note {{did you mean to use 'typename'?}} expected-error{{expected ',' or '>'}} // A storage class shall not be specified in a template-parameter declaration. template struct Z; //expected-error{{invalid declaration specifier}} -template struct Z0; //expected-error{{expected template parameter}} expected-error{{expected identifier}} expected-error{{extraneous 'template<>' in declaration of struct 'Z0'}} expected-note{{did you mean to use 'typename'?}} +template struct Z0; //expected-error{{invalid declaration specifier}} template struct Z1; //expected-error2{{invalid declarat
r340215 - Model type attributes as regular Attrs.
Author: rsmith Date: Mon Aug 20 14:47:29 2018 New Revision: 340215 URL: http://llvm.org/viewvc/llvm-project?rev=340215&view=rev Log: Model type attributes as regular Attrs. Specifically, AttributedType now tracks a regular attr::Kind rather than having its own parallel Kind enumeration, and AttributedTypeLoc now holds an Attr* instead of holding an ad-hoc collection of Attr fields. Differential Revision: https://reviews.llvm.org/D50526 This reinstates r339623, reverted in r339638, with a fix to not fail template instantiation if we instantiate a QualType with no associated type source information and we encounter an AttributedType. Modified: cfe/trunk/include/clang/AST/ASTContext.h cfe/trunk/include/clang/AST/Attr.h cfe/trunk/include/clang/AST/Type.h cfe/trunk/include/clang/AST/TypeLoc.h cfe/trunk/include/clang/Basic/Attr.td cfe/trunk/include/clang/Sema/Sema.h cfe/trunk/include/clang/Serialization/ASTReader.h cfe/trunk/include/clang/Serialization/ASTWriter.h cfe/trunk/lib/ARCMigrate/TransGCAttrs.cpp cfe/trunk/lib/ARCMigrate/Transforms.cpp cfe/trunk/lib/AST/ASTContext.cpp cfe/trunk/lib/AST/Type.cpp cfe/trunk/lib/AST/TypeLoc.cpp cfe/trunk/lib/AST/TypePrinter.cpp cfe/trunk/lib/Sema/SemaDecl.cpp cfe/trunk/lib/Sema/SemaExpr.cpp cfe/trunk/lib/Sema/SemaInit.cpp cfe/trunk/lib/Sema/SemaObjCProperty.cpp cfe/trunk/lib/Sema/SemaType.cpp cfe/trunk/lib/Sema/TreeTransform.h cfe/trunk/lib/Serialization/ASTReader.cpp cfe/trunk/lib/Serialization/ASTReaderDecl.cpp cfe/trunk/lib/Serialization/ASTWriter.cpp cfe/trunk/lib/StaticAnalyzer/Core/CheckerHelpers.cpp cfe/trunk/test/SemaCXX/calling-conv-compat.cpp cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp Modified: cfe/trunk/include/clang/AST/ASTContext.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=340215&r1=340214&r2=340215&view=diff == --- cfe/trunk/include/clang/AST/ASTContext.h (original) +++ cfe/trunk/include/clang/AST/ASTContext.h Mon Aug 20 14:47:29 2018 @@ -31,6 +31,7 @@ #include "clang/AST/TemplateName.h" #include "clang/AST/Type.h" #include "clang/Basic/AddressSpaces.h" +#include "clang/Basic/AttrKinds.h" #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/LangOptions.h" @@ -1422,7 +1423,7 @@ public: QualType getInjectedClassNameType(CXXRecordDecl *Decl, QualType TST) const; - QualType getAttributedType(AttributedType::Kind attrKind, + QualType getAttributedType(attr::Kind attrKind, QualType modifiedType, QualType equivalentType); Modified: cfe/trunk/include/clang/AST/Attr.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Attr.h?rev=340215&r1=340214&r2=340215&view=diff == --- cfe/trunk/include/clang/AST/Attr.h (original) +++ cfe/trunk/include/clang/AST/Attr.h Mon Aug 20 14:47:29 2018 @@ -113,6 +113,19 @@ public: void printPretty(raw_ostream &OS, const PrintingPolicy &Policy) const; }; +class TypeAttr : public Attr { +protected: + TypeAttr(attr::Kind AK, SourceRange R, unsigned SpellingListIndex, + bool IsLateParsed) + : Attr(AK, R, SpellingListIndex, IsLateParsed) {} + +public: + static bool classof(const Attr *A) { +return A->getKind() >= attr::FirstTypeAttr && + A->getKind() <= attr::LastTypeAttr; + } +}; + class StmtAttr : public Attr { protected: StmtAttr(attr::Kind AK, SourceRange R, unsigned SpellingListIndex, Modified: cfe/trunk/include/clang/AST/Type.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=340215&r1=340214&r2=340215&view=diff == --- cfe/trunk/include/clang/AST/Type.h (original) +++ cfe/trunk/include/clang/AST/Type.h Mon Aug 20 14:47:29 2018 @@ -21,6 +21,7 @@ #include "clang/AST/NestedNameSpecifier.h" #include "clang/AST/TemplateName.h" #include "clang/Basic/AddressSpaces.h" +#include "clang/Basic/AttrKinds.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/ExceptionSpecificationType.h" #include "clang/Basic/LLVM.h" @@ -1970,7 +1971,16 @@ public: bool isObjCQualifiedClassType() const;// Class bool isObjCObjectOrInterfaceType() const; bool isObjCIdType() const;// id - bool isObjCInertUnsafeUnretainedType() const; + + /// Was this type written with the special inert-in-ARC __unsafe_unretained + /// qualifier? + /// + /// This approximates the answer to the following question: if this + /// translation unit were compiled in ARC, would this type be qualified + /// with __unsafe_unretained? + bool isObjCInertUnsafeUnretainedType() const { +return hasAttr(attr::ObjCInertUnsafeUnretained); + } /// Whether
Re: r314872 - We allow implicit function declarations as an extension in all C dialects. Remove OpenCL special case.
On Tue, 21 Aug 2018 at 07:41, Anastasia Stulova via cfe-commits < cfe-commits@lists.llvm.org> wrote: > If there are no objections I would like to revert this old commit that > coverts error about implicit function declaration into a warning. > > > We have decided to generate an error for this > https://reviews.llvm.org/D31745 because for OpenCL variadic prototypes > are disallowed (section 6.9.e, > https://www.khronos.org/registry/OpenCL/specs/opencl-2.0-openclc.pdf) and > the implicit prototype requires variadic support. > This is incorrect. Implicit function declarations declare unprototyped functions, which are *not* variadic, and are in fact supported by Clang's OpenCL language mode. See C90 6.5.4.3 Semantics, last paragraph, and 6.3.2.2 Semantics, second paragraph. So that argument does not appear to apply. The reason we accept implicitly-declared functions outside of our C89 mode is because this is an explicit, supported Clang extension. Generally, Clang intends to support using all of its extensions together, unless there is some fundamental reason why they cannot be combined. So, just as it doesn't make sense for our OpenCL language mode to conflict with, say, AltiVec vector extensions, it doesn't make sense for the OpenCL language mode to conflict with our implicitly-declared functions extension. I would have sympathy for your position if we did not produce an extension warning on this construct by default. But we do, and it says the construct is invalid in OpenCL; moreover, in our strict conformance mode (-pedantic-errors), we reject the code. > As most vendors that support OpenCL don't support variadic functions it > was decided to restrict this explicitly in the spec (section s6.9.u). There > is a little bit of more history in https://reviews.llvm.org/D17438. > > Currently the code that can't run correctly on most OpenCL targets > compiles successfully. The problem can't be easily seen by the OpenCL > developers since it's not very common to retrieve the compilation warning > log during online compilation. Also generated IR doesn't seem to be > correct if I compare with the similar code in C. > > Example: > 1 typedef long long16 __attribute__((ext_vector_type(16))); > 2 void test_somefunc( __global int *d, __global void *s ) > 3 { > 4 int i = get_global_id(0); > 5 d[i] = somefunc((( __global long16 *)s)[i]); > 6 } > > Is generated to: > > %call1 = call i32 (<16 x i64>*, ...) bitcast (i32 ()* @somefunc to i32 > (<16 x i64>*, ...)*)(<16 x i64>* byval nonnull align 128 > %indirect-arg-temp) #2 > ... > > declare i32 @somefunc() local_unnamed_addr #1 > > Equivalent C code at least generates variadic function prototype correctly > : > > %call1 = call i32 (<16 x i64>*, ...) bitcast (i32 (...)* @somefunc to i32 > (<16 x i64>*, ...)*)(<16 x i64>* byval align 128 %indirect-arg-temp) > ... > declare i32 @somefunc(...) > > Anastasia > -- > *From:* cfe-commits on behalf of > Richard Smith via cfe-commits > *Sent:* 04 October 2017 02:58 > *To:* cfe-commits@lists.llvm.org > *Subject:* r314872 - We allow implicit function declarations as an > extension in all C dialects. Remove OpenCL special case. > > Author: rsmith > Date: Tue Oct 3 18:58:22 2017 > New Revision: 314872 > > URL: http://llvm.org/viewvc/llvm-project?rev=314872&view=rev > Log: > We allow implicit function declarations as an extension in all C dialects. > Remove OpenCL special case. > > Modified: > cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td > cfe/trunk/lib/Sema/SemaDecl.cpp > cfe/trunk/test/SemaOpenCL/clang-builtin-version.cl > cfe/trunk/test/SemaOpenCL/to_addr_builtin.cl > > Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=314872&r1=314871&r2=314872&view=diff > > == > --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) > +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Oct 3 > 18:58:22 2017 > @@ -355,7 +355,7 @@ def warn_implicit_function_decl : Warnin >"implicit declaration of function %0">, >InGroup, DefaultIgnore; > def ext_implicit_function_decl : ExtWarn< > - "implicit declaration of function %0 is invalid in C99">, > + "implicit declaration of function %0 is invalid in > %select{C99|OpenCL}1">, >InGroup; > def note_function_suggestion : Note<"did you mean %0?">; > > @@ -8449,8 +8449,6 @@ def err_opencl_scalar_type_rank_g
Re: r314872 - We allow implicit function declarations as an extension in all C dialects. Remove OpenCL special case.
rror about implicit function declaration into a warning. > > > We have decided to generate an error for this > https://reviews.llvm.org/D31745 because for OpenCL variadic prototypes > are disallowed (section 6.9.e, > https://www.khronos.org/registry/OpenCL/specs/opencl-2.0-openclc.pdf) and > the implicit prototype requires variadic support. > > This is incorrect. Implicit function declarations declare unprototyped > functions, which are *not* variadic, and are in fact supported by Clang's > OpenCL language mode. > > See C90 6.5.4.3 Semantics, last paragraph, and 6.3.2.2 Semantics, second > paragraph. > > So that argument does not appear to apply. The reason we accept > implicitly-declared functions outside of our C89 mode is because this is an > explicit, supported Clang extension. Generally, Clang intends to support > using all of its extensions together, unless there is some fundamental > reason why they cannot be combined. So, just as it doesn't make sense for > our OpenCL language mode to conflict with, say, AltiVec vector extensions, > it doesn't make sense for the OpenCL language mode to conflict with our > implicitly-declared functions extension. > > I would have sympathy for your position if we did not produce an extension > warning on this construct by default. But we do, and it says the construct > is invalid in OpenCL; moreover, in our strict conformance mode > (-pedantic-errors), we reject the code. > > As most vendors that support OpenCL don't support variadic functions it > was decided to restrict this explicitly in the spec (section s6.9.u). There > is a little bit of more history in https://reviews.llvm.org/D17438. > > > Currently the code that can't run correctly on most OpenCL targets > compiles successfully. The problem can't be easily seen by the OpenCL > developers since it's not very common to retrieve the compilation warning > log during online compilation. Also generated IR doesn't seem to be correct > if I compare with the similar code in C. > > Example: > 1 typedef long long16 __attribute__((ext_vector_type(16))); > 2 void test_somefunc( __global int *d, __global void *s ) > 3 { > 4 int i = get_global_id(0); > 5 d[i] = somefunc((( __global long16 *)s)[i]); > 6 } > > Is generated to: > > %call1 = call i32 (<16 x i64>*, ...) bitcast (i32 ()* @somefunc to i32 > (<16 x i64>*, ...)*)(<16 x i64>* byval nonnull align 128 > %indirect-arg-temp) #2 > ... > > declare i32 @somefunc() local_unnamed_addr #1 > > Equivalent C code at least generates variadic function prototype correctly: > > %call1 = call i32 (<16 x i64>*, ...) bitcast (i32 (...)* @somefunc to i32 > (<16 x i64>*, ...)*)(<16 x i64>* byval align 128 %indirect-arg-temp) > ... > declare i32 @somefunc(...) > > Anastasia > > From: cfe-commits cfe-commits-boun...@lists.llvm.org>> on behalf of Richard Smith via > cfe-commits mailto:cfe-commits@lists.llvm.org > >> > Sent: 04 October 2017 02:58 > To: cfe-commits@lists.llvm.org<mailto:cfe-commits@lists.llvm.org> > Subject: r314872 - We allow implicit function declarations as an extension > in all C dialects. Remove OpenCL special case. > > Author: rsmith > Date: Tue Oct 3 18:58:22 2017 > New Revision: 314872 > > URL: http://llvm.org/viewvc/llvm-project?rev=314872&view=rev > Log: > We allow implicit function declarations as an extension in all C dialects. > Remove OpenCL special case. > > Modified: > cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td > cfe/trunk/lib/Sema/SemaDecl.cpp > cfe/trunk/test/SemaOpenCL/clang-builtin-version.cl< > http://clang-builtin-version.cl> > cfe/trunk/test/SemaOpenCL/to_addr_builtin.cl<http://to_addr_builtin.cl > > > > Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=314872&r1=314871&r2=314872&view=diff > > == > --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) > +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Oct 3 > 18:58:22 2017 > @@ -355,7 +355,7 @@ def warn_implicit_function_decl : Warnin >"implicit declaration of function %0">, >InGroup, DefaultIgnore; > def ext_implicit_function_decl : ExtWarn< > - "implicit declaration of function %0 is invalid in C99">, > + "implicit declaration of function %0 is invalid in > %select{C99|OpenCL}1">, >InGroup; >
r332076 - Improve diagnostics and error recovery for template name lookup.
Author: rsmith Date: Thu May 10 19:43:08 2018 New Revision: 332076 URL: http://llvm.org/viewvc/llvm-project?rev=332076&view=rev Log: Improve diagnostics and error recovery for template name lookup. For 'x::template y', consistently give a "no member named 'y' in 'x'" diagnostic if there is no such member, and give a 'template keyword not followed by a template' name error if there is such a member but it's not a template. In the latter case, add a note pointing at the non-template. Don't suggest inserting a 'template' keyword in 'X::Y<' if X is dependent if the lookup of X::Y was actually not a dependent lookup and found only non-templates. Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/include/clang/Sema/Sema.h cfe/trunk/lib/Parse/ParseExprCXX.cpp cfe/trunk/lib/Sema/SemaExpr.cpp cfe/trunk/lib/Sema/SemaExprMember.cpp cfe/trunk/lib/Sema/SemaTemplate.cpp cfe/trunk/lib/Sema/TreeTransform.h cfe/trunk/test/CXX/drs/dr1xx.cpp cfe/trunk/test/CXX/drs/dr3xx.cpp cfe/trunk/test/SemaCXX/cxx1y-variable-templates_in_class.cpp cfe/trunk/test/SemaCXX/invalid-template-specifier.cpp cfe/trunk/test/SemaObjCXX/parameterized_classes_subst.mm cfe/trunk/test/SemaTemplate/dependent-base-classes.cpp cfe/trunk/test/SemaTemplate/metafun-apply.cpp cfe/trunk/test/SemaTemplate/nested-name-spec-template.cpp cfe/trunk/test/SemaTemplate/template-id-expr.cpp cfe/trunk/test/SemaTemplate/typo-dependent-name.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=332076&r1=332075&r2=332076&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu May 10 19:43:08 2018 @@ -4505,6 +4505,8 @@ def note_using_value_decl_missing_typena def err_template_kw_refers_to_non_template : Error< "%0 following the 'template' keyword does not refer to a template">; +def note_template_kw_refers_to_non_template : Note< + "declared as a non-template here">; def err_template_kw_refers_to_class_template : Error< "'%0%1' instantiated to a class template, not a function template">; def note_referenced_class_template : Note< Modified: cfe/trunk/include/clang/Sema/Sema.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=332076&r1=332075&r2=332076&view=diff == --- cfe/trunk/include/clang/Sema/Sema.h (original) +++ cfe/trunk/include/clang/Sema/Sema.h Thu May 10 19:43:08 2018 @@ -6090,9 +6090,10 @@ public: bool hasAnyAcceptableTemplateNames(LookupResult &R, bool AllowFunctionTemplates = true); - void LookupTemplateName(LookupResult &R, Scope *S, CXXScopeSpec &SS, + bool LookupTemplateName(LookupResult &R, Scope *S, CXXScopeSpec &SS, QualType ObjectType, bool EnteringContext, - bool &MemberOfUnknownSpecialization); + bool &MemberOfUnknownSpecialization, + SourceLocation TemplateKWLoc = SourceLocation()); TemplateNameKind isTemplateName(Scope *S, CXXScopeSpec &SS, Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=332076&r1=332075&r2=332076&view=diff == --- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original) +++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Thu May 10 19:43:08 2018 @@ -515,7 +515,7 @@ bool Parser::ParseOptionalCXXScopeSpecif << FixItHint::CreateInsertion(Tok.getLocation(), "template "); if (TemplateNameKind TNK = Actions.ActOnDependentTemplateName( -getCurScope(), SS, SourceLocation(), TemplateName, ObjectType, +getCurScope(), SS, Tok.getLocation(), TemplateName, ObjectType, EnteringContext, Template, /*AllowInjectedClassName*/ true)) { // Consume the identifier. ConsumeToken(); Modified: cfe/trunk/lib/Sema/SemaExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=332076&r1=332075&r2=332076&view=diff == --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) +++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu May 10 19:43:08 2018 @@ -2087,8 +2087,9 @@ Sema::ActOnIdExpression(Scope *S, CXXSco // this becomes a performance hit, we can work harder to preserve those // results until we get here but it's likely not worth it. bool MemberOfUnknownSpecialization; -LookupTemplateName(R, S, SS, QualType(), /*EnteringContext=*/false, - MemberOfU
r332130 - [libclang] Stop assuming that the internal C++ ABI ExceptionSpecificationType enumeration is the same as CXCursor_ExceptionSpecificationKind.
Author: rsmith Date: Fri May 11 12:46:31 2018 New Revision: 332130 URL: http://llvm.org/viewvc/llvm-project?rev=332130&view=rev Log: [libclang] Stop assuming that the internal C++ ABI ExceptionSpecificationType enumeration is the same as CXCursor_ExceptionSpecificationKind. Modified: cfe/trunk/include/clang-c/Index.h cfe/trunk/test/Index/get-cursor.cpp cfe/trunk/tools/libclang/CXType.cpp Modified: cfe/trunk/include/clang-c/Index.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=332130&r1=332129&r2=332130&view=diff == --- cfe/trunk/include/clang-c/Index.h (original) +++ cfe/trunk/include/clang-c/Index.h Fri May 11 12:46:31 2018 @@ -3586,6 +3586,7 @@ CINDEX_LINKAGE CXType clang_getResultTyp /** * Retrieve the exception specification type associated with a function type. + * This is a value of type CXCursor_ExceptionSpecificationKind. * * If a non-function type is passed in, an error code of -1 is returned. */ @@ -3621,6 +3622,7 @@ CINDEX_LINKAGE CXType clang_getCursorRes /** * Retrieve the exception specification type associated with a given cursor. + * This is a value of type CXCursor_ExceptionSpecificationKind. * * This only returns a valid result if the cursor refers to a function or method. */ Modified: cfe/trunk/test/Index/get-cursor.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/get-cursor.cpp?rev=332130&r1=332129&r2=332130&view=diff == --- cfe/trunk/test/Index/get-cursor.cpp (original) +++ cfe/trunk/test/Index/get-cursor.cpp Fri May 11 12:46:31 2018 @@ -151,6 +151,8 @@ template void f_computed_noexc void f_dynamic_noexcept_none() throw(); void f_dynamic_noexcept() throw(int); void f_dynamic_noexcept_any() throw(...); +void f_computed_noexcept_true() noexcept(true); +void f_computed_noexcept_false() noexcept(false); enum EnumType { Enumerator }; struct Z { @@ -221,7 +223,7 @@ struct Z { // RUN: c-index-test -cursor-at=%s:66:23 %s | FileCheck -check-prefix=CHECK-TEMPLSPEC %s // CHECK-TEMPLSPEC: 66:23 ClassDecl=TC:66:23 (Definition) [Specialization of TC:59:7] Extent=[66:1 - 66:31] Spelling=TC ([66:23 - 66:25]) -// RUN: c-index-test -cursor-at=%s:69:3 -cursor-at=%s:70:11 -cursor-at=%s:73:6 -cursor-at=%s:74:6 -cursor-at=%s:77:8 -cursor-at=%s:78:8 -cursor-at=%s:79:8 -cursor-at=%s:80:8 -cursor-at=%s:81:8 -cursor-at=%s:82:8 -cursor-at=%s:85:6 -cursor-at=%s:86:6 -cursor-at=%s:87:6 -cursor-at=%s:88:6 -cursor-at=%s:91:5 -cursor-at=%s:92:5 -cursor-at=%s:93:5 -cursor-at=%s:94:5 -cursor-at=%s:95:5 -cursor-at=%s:96:5 -cursor-at=%s:97:5 -cursor-at=%s:98:5 -cursor-at=%s:100:5 -cursor-at=%s:101:5 -cursor-at=%s:104:6 -cursor-at=%s:105:6 -cursor-at=%s:106:6 -cursor-at=%s:107:6 -cursor-at=%s:108:6 -cursor-at=%s:109:6 -cursor-at=%s:110:6 -cursor-at=%s:111:6 -cursor-at=%s:113:6 -cursor-at=%s:114:6 -cursor-at=%s:117:8 -cursor-at=%s:118:8 -cursor-at=%s:120:8 -cursor-at=%s:121:8 -cursor-at=%s:122:8 -cursor-at=%s:123:8 -cursor-at=%s:124:8 -cursor-at=%s:125:8 -cursor-at=%s:128:6 -cursor-at=%s:129:6 -cursor-at=%s:130:6 -cursor-at=%s:132:3 -cursor-at=%s:146:15 -cursor-at=%s:149:6 -cursor-at=%s:150:25 -cursor-at=%s:151:6 -cursor-at=%s:152:6 -cursor-at=%s:153:6 -std=c++11 %s | FileCheck -check-prefix=CHECK-SPELLING %s +// RUN: c-index-test -cursor-at=%s:69:3 -cursor-at=%s:70:11 -cursor-at=%s:73:6 -cursor-at=%s:74:6 -cursor-at=%s:77:8 -cursor-at=%s:78:8 -cursor-at=%s:79:8 -cursor-at=%s:80:8 -cursor-at=%s:81:8 -cursor-at=%s:82:8 -cursor-at=%s:85:6 -cursor-at=%s:86:6 -cursor-at=%s:87:6 -cursor-at=%s:88:6 -cursor-at=%s:91:5 -cursor-at=%s:92:5 -cursor-at=%s:93:5 -cursor-at=%s:94:5 -cursor-at=%s:95:5 -cursor-at=%s:96:5 -cursor-at=%s:97:5 -cursor-at=%s:98:5 -cursor-at=%s:100:5 -cursor-at=%s:101:5 -cursor-at=%s:104:6 -cursor-at=%s:105:6 -cursor-at=%s:106:6 -cursor-at=%s:107:6 -cursor-at=%s:108:6 -cursor-at=%s:109:6 -cursor-at=%s:110:6 -cursor-at=%s:111:6 -cursor-at=%s:113:6 -cursor-at=%s:114:6 -cursor-at=%s:117:8 -cursor-at=%s:118:8 -cursor-at=%s:120:8 -cursor-at=%s:121:8 -cursor-at=%s:122:8 -cursor-at=%s:123:8 -cursor-at=%s:124:8 -cursor-at=%s:125:8 -cursor-at=%s:128:6 -cursor-at=%s:129:6 -cursor-at=%s:130:6 -cursor-at=%s:132:3 -cursor-at=%s:146:15 -cursor-at=%s:149:6 -cursor-at=%s:150:25 -cursor-at=%s:151:6 -cursor-at=%s:152:6 -cursor-at=%s:153:6 -cursor-at=%s:154:6 -cursor-at=%s:155:6 -std=c++11 %s | FileCheck -check-prefix=CHECK-SPELLING %s // CHECK-SPELLING: 69:3 CXXConstructor=A:69:3 (default constructor) Extent=[69:3 - 69:6] Spelling=A ([69:3 - 69:4]) // CHECK-SPELLING: 70:11 CXXDestructor=~A:70:11 (virtual) Extent=[70:3 - 70:15] Spelling=~A ([70:11 - 70:13]) // CHECK-SPELLING: 73:6 CXXMethod=operator=:73:6 Extent=[73:3 - 73:25] Spelling=operator= ([73:6 - 73:15]) @@ -274,12 +276,14 @@ struct Z { // CHECK-SPELLING: 151:6 FunctionDecl=f_dynamic_n
r332286 - PR37450: Fix bug that disabled some type checks for variables with deduced types.
Author: rsmith Date: Mon May 14 13:15:04 2018 New Revision: 332286 URL: http://llvm.org/viewvc/llvm-project?rev=332286&view=rev Log: PR37450: Fix bug that disabled some type checks for variables with deduced types. Also improve diagnostic for the case where a type is non-literal because it's a lambda. Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaDecl.cpp cfe/trunk/lib/Sema/SemaType.cpp cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p3.cpp cfe/trunk/test/SemaCXX/cxx1z-constexpr-lambdas.cpp cfe/trunk/test/SemaCXX/for-range-examples.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=332286&r1=332285&r2=332286&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon May 14 13:15:04 2018 @@ -2381,6 +2381,8 @@ def note_non_literal_user_provided_dtor "%0 is not literal because it has a user-provided destructor">; def note_non_literal_nontrivial_dtor : Note< "%0 is not literal because it has a non-trivial destructor">; +def note_non_literal_lambda : Note< + "lambda closure types are non-literal types before C++17">; def warn_private_extern : Warning< "use of __private_extern__ on a declaration may not produce external symbol " "private to the linkage unit and is deprecated">, InGroup; Modified: cfe/trunk/lib/Sema/SemaDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=332286&r1=332285&r2=332286&view=diff == --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon May 14 13:15:04 2018 @@ -7293,8 +7293,7 @@ void Sema::CheckVariableDeclarationType( if (NewVD->isInvalidDecl()) return; - TypeSourceInfo *TInfo = NewVD->getTypeSourceInfo(); - QualType T = TInfo->getType(); + QualType T = NewVD->getType(); // Defer checking an 'auto' type until its initializer is attached. if (T->isUndeducedType()) @@ -7438,10 +7437,18 @@ void Sema::CheckVariableDeclarationType( (T->isVariableArrayType() && NewVD->hasGlobalStorage())) { bool SizeIsNegative; llvm::APSInt Oversized; -TypeSourceInfo *FixedTInfo = - TryToFixInvalidVariablyModifiedTypeSourceInfo(TInfo, Context, -SizeIsNegative, Oversized); -if (!FixedTInfo && T->isVariableArrayType()) { +TypeSourceInfo *FixedTInfo = TryToFixInvalidVariablyModifiedTypeSourceInfo( +NewVD->getTypeSourceInfo(), Context, SizeIsNegative, Oversized); +QualType FixedT; +if (FixedTInfo && T == NewVD->getTypeSourceInfo()->getType()) + FixedT = FixedTInfo->getType(); +else if (FixedTInfo) { + // Type and type-as-written are canonically different. We need to fix up + // both types separately. + FixedT = TryToFixInvalidVariablyModifiedType(T, Context, SizeIsNegative, + Oversized); +} +if ((!FixedTInfo || FixedT.isNull()) && T->isVariableArrayType()) { const VariableArrayType *VAT = Context.getAsVariableArrayType(T); // FIXME: This won't give the correct result for // int a[10][n]; @@ -7470,7 +7477,7 @@ void Sema::CheckVariableDeclarationType( } Diag(NewVD->getLocation(), diag::warn_illegal_constant_array_size); -NewVD->setType(FixedTInfo->getType()); +NewVD->setType(FixedT); NewVD->setTypeSourceInfo(FixedTInfo); } Modified: cfe/trunk/lib/Sema/SemaType.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=332286&r1=332285&r2=332286&view=diff == --- cfe/trunk/lib/Sema/SemaType.cpp (original) +++ cfe/trunk/lib/Sema/SemaType.cpp Mon May 14 13:15:04 2018 @@ -7809,6 +7809,13 @@ bool Sema::RequireLiteralType(SourceLoca if (RequireCompleteType(Loc, ElemType, diag::note_non_literal_incomplete, T)) return true; + // [expr.prim.lambda]p3: + // This class type is [not] a literal type. + if (RD->isLambda() && !getLangOpts().CPlusPlus17) { +Diag(RD->getLocation(), diag::note_non_literal_lambda); +return true; + } + // If the class has virtual base classes, then it's not an aggregate, and // cannot have any constexpr constructors or a trivial default constructor, // so is non-literal. This is better to diagnose than the resulting absence Modified: cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p3.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p3.cpp?rev=332286&r1=332285&r2=332286&view=diff == --- cfe/trunk
r332291 - Fix regression in r332076.
Author: rsmith Date: Mon May 14 13:52:48 2018 New Revision: 332291 URL: http://llvm.org/viewvc/llvm-project?rev=332291&view=rev Log: Fix regression in r332076. If the name after 'template' is an unresolved using declaration (not containing 'typename'), then we don't yet know if it's a valid template-name, so don't reject it prior to instantiation. Instead, treat it as naming a dependent member of the current instantiation. Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp cfe/trunk/test/CXX/drs/dr1xx.cpp cfe/trunk/test/SemaTemplate/dependent-names.cpp Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=332291&r1=332290&r2=332291&view=diff == --- cfe/trunk/lib/Sema/SemaTemplate.cpp (original) +++ cfe/trunk/lib/Sema/SemaTemplate.cpp Mon May 14 13:52:48 2018 @@ -105,6 +105,12 @@ static NamedDecl *isAcceptableTemplateNa return nullptr; } + // 'using Dependent::foo;' can resolve to a template name. + // 'using typename Dependent::foo;' cannot (not even if 'foo' is an + // injected-class-name). + if (isa(D)) +return D; + return nullptr; } @@ -214,6 +220,10 @@ TemplateNameKind Sema::isTemplateName(Sc // We'll do this lookup again later. R.suppressDiagnostics(); + } else if (isa((*R.begin())->getUnderlyingDecl())) { +// We don't yet know whether this is a template-name or not. +MemberOfUnknownSpecialization = true; +return TNK_Non_template; } else { TemplateDecl *TD = cast((*R.begin())->getUnderlyingDecl()); @@ -429,7 +439,7 @@ bool Sema::LookupTemplateName(LookupResu if (ExampleLookupResult && TemplateKWLoc.isValid()) { Diag(Found.getNameLoc(), diag::err_template_kw_refers_to_non_template) << Found.getLookupName() << SS.getRange(); - Diag(ExampleLookupResult->getLocation(), + Diag(ExampleLookupResult->getUnderlyingDecl()->getLocation(), diag::note_template_kw_refers_to_non_template) << Found.getLookupName(); return true; Modified: cfe/trunk/test/CXX/drs/dr1xx.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/drs/dr1xx.cpp?rev=332291&r1=332290&r2=332291&view=diff == --- cfe/trunk/test/CXX/drs/dr1xx.cpp (original) +++ cfe/trunk/test/CXX/drs/dr1xx.cpp Mon May 14 13:52:48 2018 @@ -71,8 +71,7 @@ namespace dr109 { // dr109: yes using T::template f; // expected-error {{'template' keyword not permitted here}} expected-error {{using declaration cannot refer to a template specialization}} // FIXME: We shouldn't suggest using the 'template' keyword in a location where it's not valid. using T::f; // expected-error {{use 'template' keyword}} expected-error {{using declaration cannot refer to a template specialization}} -// FIXME: The first 'using' above introduces 'f' as a non-template member of 'B', leading to bad recovery: -void g() { this->f(123); } // expected-error {{expected '('}} +void g() { this->f(123); } // expected-error {{use 'template' keyword}} }; } Modified: cfe/trunk/test/SemaTemplate/dependent-names.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/dependent-names.cpp?rev=332291&r1=332290&r2=332291&view=diff == --- cfe/trunk/test/SemaTemplate/dependent-names.cpp (original) +++ cfe/trunk/test/SemaTemplate/dependent-names.cpp Mon May 14 13:52:48 2018 @@ -427,3 +427,23 @@ namespace DependentTemplateIdWithNoArgs }; void g() { f(); } } + +namespace DependentUnresolvedUsingTemplate { + template + struct X : T { +using T::foo; +void f() { this->template foo(); } // expected-error {{does not refer to a template}} +void g() { this->template foo<>(); } // expected-error {{does not refer to a template}} +void h() { this->template foo(); } // expected-error {{does not refer to a template}} + }; + struct A { template int foo(); }; + struct B { int foo(); }; // expected-note 3{{non-template here}} + void test(X xa, X xb) { +xa.f(); +xa.g(); +xa.h(); +xb.f(); // expected-note {{instantiation of}} +xb.g(); // expected-note {{instantiation of}} +xb.h(); // expected-note {{instantiation of}} + } +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r332401 - Don't produce a redundant "auto type is incompatible with C++98" on every lambda with no explicit return type.
Author: rsmith Date: Tue May 15 14:27:30 2018 New Revision: 332401 URL: http://llvm.org/viewvc/llvm-project?rev=332401&view=rev Log: Don't produce a redundant "auto type is incompatible with C++98" on every lambda with no explicit return type. We already warned about the lambda, and we don't have a source location for the imagined "auto" anyway. Modified: cfe/trunk/lib/Sema/SemaType.cpp cfe/trunk/test/SemaCXX/cxx98-compat.cpp Modified: cfe/trunk/lib/Sema/SemaType.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=332401&r1=332400&r2=332401&view=diff == --- cfe/trunk/lib/Sema/SemaType.cpp (original) +++ cfe/trunk/lib/Sema/SemaType.cpp Tue May 15 14:27:30 2018 @@ -2962,9 +2962,11 @@ static QualType GetDeclSpecTypeForDeclar T = SemaRef.Context.IntTy; D.setInvalidType(true); -} else if (!HaveTrailing) { +} else if (!HaveTrailing && + D.getContext() != DeclaratorContext::LambdaExprContext) { // If there was a trailing return type, we already got // warn_cxx98_compat_trailing_return_type in the parser. + // If this was a lambda, we already warned on that too. SemaRef.Diag(AutoRange.getBegin(), diag::warn_cxx98_compat_auto_type_specifier) << AutoRange; Modified: cfe/trunk/test/SemaCXX/cxx98-compat.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx98-compat.cpp?rev=332401&r1=332400&r2=332401&view=diff == --- cfe/trunk/test/SemaCXX/cxx98-compat.cpp (original) +++ cfe/trunk/test/SemaCXX/cxx98-compat.cpp Tue May 15 14:27:30 2018 @@ -47,6 +47,8 @@ namespace TemplateParsing { void Lambda() { []{}(); // expected-warning {{lambda expressions are incompatible with C++98}} + // Don't warn about implicit "-> auto" here. + [](){}(); // expected-warning {{lambda expressions are incompatible with C++98}} } struct Ctor { ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r332286 - PR37450: Fix bug that disabled some type checks for variables with deduced types.
Sorry for the delay, looking now. On 15 May 2018 at 02:24, Maxim Kuvyrkov wrote: > Hi Richard, > > The for-range-examples.cpp test fails on 32-bit arm buildbots, e.g.: > http://lab.llvm.org:8011/builders/clang-cmake-armv7-full/builds/840 . > Would you please investigate? > > You didn't get a notification because your commit was around the same time > as a fix for an unrelated testcase issue that caused same bots to be red. > > -- > Maxim Kuvyrkov > www.linaro.org > > > > > On May 14, 2018, at 11:15 PM, Richard Smith via cfe-commits < > cfe-commits@lists.llvm.org> wrote: > > > > Author: rsmith > > Date: Mon May 14 13:15:04 2018 > > New Revision: 332286 > > > > URL: http://llvm.org/viewvc/llvm-project?rev=332286&view=rev > > Log: > > PR37450: Fix bug that disabled some type checks for variables with > deduced types. > > > > Also improve diagnostic for the case where a type is non-literal because > it's a lambda. > > > > Modified: > >cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td > >cfe/trunk/lib/Sema/SemaDecl.cpp > >cfe/trunk/lib/Sema/SemaType.cpp > >cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p3.cpp > >cfe/trunk/test/SemaCXX/cxx1z-constexpr-lambdas.cpp > >cfe/trunk/test/SemaCXX/for-range-examples.cpp > > > > Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td > > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/ > DiagnosticSemaKinds.td?rev=332286&r1=332285&r2=332286&view=diff > > > == > > --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) > > +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon May 14 > 13:15:04 2018 > > @@ -2381,6 +2381,8 @@ def note_non_literal_user_provided_dtor > > "%0 is not literal because it has a user-provided destructor">; > > def note_non_literal_nontrivial_dtor : Note< > > "%0 is not literal because it has a non-trivial destructor">; > > +def note_non_literal_lambda : Note< > > + "lambda closure types are non-literal types before C++17">; > > def warn_private_extern : Warning< > > "use of __private_extern__ on a declaration may not produce external > symbol " > > "private to the linkage unit and is deprecated">, > InGroup; > > > > Modified: cfe/trunk/lib/Sema/SemaDecl.cpp > > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/ > SemaDecl.cpp?rev=332286&r1=332285&r2=332286&view=diff > > > == > > --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) > > +++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon May 14 13:15:04 2018 > > @@ -7293,8 +7293,7 @@ void Sema::CheckVariableDeclarationType( > > if (NewVD->isInvalidDecl()) > > return; > > > > - TypeSourceInfo *TInfo = NewVD->getTypeSourceInfo(); > > - QualType T = TInfo->getType(); > > + QualType T = NewVD->getType(); > > > > // Defer checking an 'auto' type until its initializer is attached. > > if (T->isUndeducedType()) > > @@ -7438,10 +7437,18 @@ void Sema::CheckVariableDeclarationType( > > (T->isVariableArrayType() && NewVD->hasGlobalStorage())) { > > bool SizeIsNegative; > > llvm::APSInt Oversized; > > -TypeSourceInfo *FixedTInfo = > > - TryToFixInvalidVariablyModifiedTypeSourceInfo(TInfo, Context, > > -SizeIsNegative, > Oversized); > > -if (!FixedTInfo && T->isVariableArrayType()) { > > +TypeSourceInfo *FixedTInfo = TryToFixInvalidVariablyModifie > dTypeSourceInfo( > > +NewVD->getTypeSourceInfo(), Context, SizeIsNegative, Oversized); > > +QualType FixedT; > > +if (FixedTInfo && T == NewVD->getTypeSourceInfo()->getType()) > > + FixedT = FixedTInfo->getType(); > > +else if (FixedTInfo) { > > + // Type and type-as-written are canonically different. We need to > fix up > > + // both types separately. > > + FixedT = TryToFixInvalidVariablyModifiedType(T, Context, > SizeIsNegative, > > + Oversized); > > +} > > +if ((!FixedTInfo || FixedT.isNull()) && T->isVariableArrayType()) { > > const VariableArrayType *VAT = Context.getAsVariableArrayType(T); > > // FIXME: This won't giv
r332425 - Fix 32-bit buildbots.
Author: rsmith Date: Tue May 15 18:08:07 2018 New Revision: 332425 URL: http://llvm.org/viewvc/llvm-project?rev=332425&view=rev Log: Fix 32-bit buildbots. Modified: cfe/trunk/test/SemaCXX/for-range-examples.cpp Modified: cfe/trunk/test/SemaCXX/for-range-examples.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/for-range-examples.cpp?rev=332425&r1=332424&r2=332425&view=diff == --- cfe/trunk/test/SemaCXX/for-range-examples.cpp (original) +++ cfe/trunk/test/SemaCXX/for-range-examples.cpp Tue May 15 18:08:07 2018 @@ -221,7 +221,7 @@ namespace test7 { for (c alignas(8) : arr) { // expected-error {{requires type for loop variable}} static_assert(alignof(c) == 8, ""); // expected-warning {{extension}} } -for (d alignas(1) : arr) {} // expected-error {{requested alignment is less than minimum alignment of 8 for type 'int &'}} expected-error {{requires type for loop variable}} +for (d alignas(1) : arr) {} // expected-error {{requested alignment is less than minimum}} expected-error {{requires type for loop variable}} for (e [[deprecated]] : arr) { e = 0; } // expected-warning {{deprecated}} expected-note {{here}} expected-error {{requires type for loop variable}} } } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r332286 - PR37450: Fix bug that disabled some type checks for variables with deduced types.
Should be fixed in r332425. Apologies for the delay addressing this. On 15 May 2018 at 18:10, Richard Smith wrote: > Sorry for the delay, looking now. > > On 15 May 2018 at 02:24, Maxim Kuvyrkov wrote: > >> Hi Richard, >> >> The for-range-examples.cpp test fails on 32-bit arm buildbots, e.g.: >> http://lab.llvm.org:8011/builders/clang-cmake-armv7-full/builds/840 . >> Would you please investigate? >> >> You didn't get a notification because your commit was around the same >> time as a fix for an unrelated testcase issue that caused same bots to be >> red. >> >> -- >> Maxim Kuvyrkov >> www.linaro.org >> >> >> >> > On May 14, 2018, at 11:15 PM, Richard Smith via cfe-commits < >> cfe-commits@lists.llvm.org> wrote: >> > >> > Author: rsmith >> > Date: Mon May 14 13:15:04 2018 >> > New Revision: 332286 >> > >> > URL: http://llvm.org/viewvc/llvm-project?rev=332286&view=rev >> > Log: >> > PR37450: Fix bug that disabled some type checks for variables with >> deduced types. >> > >> > Also improve diagnostic for the case where a type is non-literal >> because it's a lambda. >> > >> > Modified: >> >cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td >> >cfe/trunk/lib/Sema/SemaDecl.cpp >> >cfe/trunk/lib/Sema/SemaType.cpp >> >cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p3.cpp >> >cfe/trunk/test/SemaCXX/cxx1z-constexpr-lambdas.cpp >> >cfe/trunk/test/SemaCXX/for-range-examples.cpp >> > >> > Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td >> > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ >> Basic/DiagnosticSemaKinds.td?rev=332286&r1=332285&r2=332286&view=diff >> > >> == >> > --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) >> > +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon May 14 >> 13:15:04 2018 >> > @@ -2381,6 +2381,8 @@ def note_non_literal_user_provided_dtor >> > "%0 is not literal because it has a user-provided destructor">; >> > def note_non_literal_nontrivial_dtor : Note< >> > "%0 is not literal because it has a non-trivial destructor">; >> > +def note_non_literal_lambda : Note< >> > + "lambda closure types are non-literal types before C++17">; >> > def warn_private_extern : Warning< >> > "use of __private_extern__ on a declaration may not produce external >> symbol " >> > "private to the linkage unit and is deprecated">, >> InGroup; >> > >> > Modified: cfe/trunk/lib/Sema/SemaDecl.cpp >> > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaD >> ecl.cpp?rev=332286&r1=332285&r2=332286&view=diff >> > >> == >> > --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) >> > +++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon May 14 13:15:04 2018 >> > @@ -7293,8 +7293,7 @@ void Sema::CheckVariableDeclarationType( >> > if (NewVD->isInvalidDecl()) >> > return; >> > >> > - TypeSourceInfo *TInfo = NewVD->getTypeSourceInfo(); >> > - QualType T = TInfo->getType(); >> > + QualType T = NewVD->getType(); >> > >> > // Defer checking an 'auto' type until its initializer is attached. >> > if (T->isUndeducedType()) >> > @@ -7438,10 +7437,18 @@ void Sema::CheckVariableDeclarationType( >> > (T->isVariableArrayType() && NewVD->hasGlobalStorage())) { >> > bool SizeIsNegative; >> > llvm::APSInt Oversized; >> > -TypeSourceInfo *FixedTInfo = >> > - TryToFixInvalidVariablyModifiedTypeSourceInfo(TInfo, Context, >> > -SizeIsNegative, >> Oversized); >> > -if (!FixedTInfo && T->isVariableArrayType()) { >> > +TypeSourceInfo *FixedTInfo = TryToFixInvalidVariablyModifie >> dTypeSourceInfo( >> > +NewVD->getTypeSourceInfo(), Context, SizeIsNegative, >> Oversized); >> > +QualType FixedT; >> > +if (FixedTInfo && T == NewVD->getTypeSourceInfo()->getType()) >> > + FixedT = FixedTInfo->getType(); >> > +else if (FixedTInfo) { >> > +
Re: r276514 - [cxx1z-constexpr-lambda] Make a lambda's closure type eligible as a literal-type in C++1z
On 17 February 2017 at 18:03, Richard Smith wrote: > On 22 July 2016 at 21:05, Faisal Vali via cfe-commits < > cfe-commits@lists.llvm.org> wrote: > >> Author: faisalv >> Date: Fri Jul 22 23:05:19 2016 >> New Revision: 276514 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=276514&view=rev >> Log: >> [cxx1z-constexpr-lambda] Make a lambda's closure type eligible as a >> literal-type in C++1z >> >> >> Additionally, for pre-C++1z, instead of forbidding a lambda's closure >> type from being a literal type through circumlocutorily setting >> HasNonLiteralTypeFieldsOrBases falsely to true -- handle lambda's more >> directly in CXXRecordDecl::isLiteral(). >> >> One additional small step towards implementing constexpr-lambdas. >> > > I don't know if this problem started with this change, but we now accept > this invalid code in C++14 mode: > > constexpr auto a = [] {}; > This was a result of two separate bugs. I've fixed one of them, but another remains, and can be observed in this example: constexpr int f() { return ([]{}, 0); } constexpr int n = f(); This is ill-formed before C++17, and yet we accept it in C++11 mode. > Thanks to Richard Smith for his review! >> https://reviews.llvm.org/D22662 >> >> >> Modified: >> cfe/trunk/include/clang/AST/DeclCXX.h >> cfe/trunk/test/SemaCXX/cxx1z-constexpr-lambdas.cpp >> >> Modified: cfe/trunk/include/clang/AST/DeclCXX.h >> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ >> AST/DeclCXX.h?rev=276514&r1=276513&r2=276514&view=diff >> >> == >> --- cfe/trunk/include/clang/AST/DeclCXX.h (original) >> +++ cfe/trunk/include/clang/AST/DeclCXX.h Fri Jul 22 23:05:19 2016 >> @@ -535,11 +535,10 @@ class CXXRecordDecl : public RecordDecl >> MethodTyInfo(Info) { >>IsLambda = true; >> >> - // C++11 [expr.prim.lambda]p3: >> - // This class type is neither an aggregate nor a literal type. >> + // C++1z [expr.prim.lambda]p4: >> + // This class type is not an aggregate type. >>Aggregate = false; >>PlainOldData = false; >> - HasNonLiteralTypeFieldsOrBases = true; >> } >> >> /// \brief Whether this lambda is known to be dependent, even if its >> @@ -1338,11 +1337,15 @@ public: >>/// >>/// We resolve DR1361 by ignoring the second bullet. We resolve DR1452 >> by >>/// treating types with trivial default constructors as literal types. >> + /// >> + /// Only in C++1z and beyond, are lambdas literal types. >>bool isLiteral() const { >> return hasTrivialDestructor() && >> - (isAggregate() || hasConstexprNonCopyMoveConstructor() || >> -hasTrivialDefaultConstructor()) && >> - !hasNonLiteralTypeFieldsOrBases(); >> + (!isLambda() || getASTContext().getLangOpts().CPlusPlus1z) && >> + !hasNonLiteralTypeFieldsOrBases() && >> + (isAggregate() || isLambda() || >> +hasConstexprNonCopyMoveConstructor() || >> +hasTrivialDefaultConstructor()); >>} >> >>/// \brief If this record is an instantiation of a member class, >> >> Modified: cfe/trunk/test/SemaCXX/cxx1z-constexpr-lambdas.cpp >> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ >> cxx1z-constexpr-lambdas.cpp?rev=276514&r1=276513&r2=276514&view=diff >> >> == >> --- cfe/trunk/test/SemaCXX/cxx1z-constexpr-lambdas.cpp (original) >> +++ cfe/trunk/test/SemaCXX/cxx1z-constexpr-lambdas.cpp Fri Jul 22 >> 23:05:19 2016 >> @@ -1,8 +1,8 @@ >> // RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks %s >> // RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks >> -fdelayed-template-parsing %s >> -// RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks >> -fms-extensions %s >> -// RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks >> -fdelayed-template-parsing -fms-extensions %s >> +// RUN: %clang_cc1 -std=c++14 -verify -fsyntax-only -fblocks %s >> -DCPP14_AND_EARLIER >> >> +#ifndef CPP14_AND_EARLIER >> namespace test_constexpr_checking { >> >> namespace ns1 { >> @@ -33,4 +33,16 @@ namespace ns3 { >>L(3); //expected-note{{non-constexpr function}} >> } >> >> -} // end ns test_constexpr_call >> \ No newline at end of file >> +} // end ns test_constexpr_call >> + >> +#endif >> + >> +namespace test_lambda_is_literal { >> +#ifdef CPP14_AND_EARLIER >> +//expected-error@+4{{not a literal type}} >> +//expected-note@+2{{not an aggregate and has no constexpr constructors}} >> +#endif >> +auto L = [] { }; >> +constexpr int foo(decltype(L) l) { return 0; } >> + >> +} >> \ No newline at end of file >> >> >> ___ >> cfe-commits mailing list >> cfe-commits@lists.llvm.org >> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits >> > > ___ cfe-commits mailing list cfe-commits@list
Re: r332470 - Add support for __declspec(code_seg("segname"))
On 16 May 2018 at 06:57, Erich Keane via cfe-commits < cfe-commits@lists.llvm.org> wrote: > Author: erichkeane > Date: Wed May 16 06:57:17 2018 > New Revision: 332470 > > URL: http://llvm.org/viewvc/llvm-project?rev=332470&view=rev > Log: > Add support for __declspec(code_seg("segname")) > > Add support for __declspec(code_seg("segname")) > > This patch is built on the existing support for #pragma code_seg. The > code_seg > declspec is allowed on functions and classes. The attribute enables the > placement of code into separate named segments, including > compiler-generated > members and template instantiations. > > For more information, please see the following: > https://msdn.microsoft.com/en-us/library/dn636922.aspx > > A new CodeSeg attribute is used instead of adding a new spelling to the > existing > Section attribute since they don’t apply to the same Subjects. Section > attributes are also added for the code_seg declspec since they are used for > #pragma code_seg. No CodeSeg attributes are added to the AST. > This approach really doesn't work. You're incorrectly applying the __declspec(code_seg) restrictions to __attribute__((section)), regressing our support for the latter. Also, code_seg has fundamentally different semantics from the section attribute -- the former exists in part to support paged addressing (which is why it has the virtual function restriction) and the latter exists merely to control properties of the object file. This approach also violates our policy of maintaining source fidelity. I'm going to revert this for now to fix the regression; when it comes back, I think you should just use CodeSegAttr to represent __declspec(code_seg) rather than trying to treat it as -- effectively -- a different spelling of SectionAttr. > The patch is written to match with the Microsoft compiler’s behavior even > where > that behavior is a little complicated (see https://reviews.llvm.org/D22931, > the > Microsoft feedback page is no longer available since MS has removed the > page). > That code is in getImplicitSectionAttrFromClass routine. > > Diagnostics messages are added to match with the Microsoft compiler for > code-seg > attribute mismatches on base and derived classes and virtual overrides. > > > Differential Revision: https://reviews.llvm.org/D43352 > > Modified: > cfe/trunk/include/clang/Basic/Attr.td > cfe/trunk/include/clang/Basic/AttrDocs.td > cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td > cfe/trunk/include/clang/Sema/Sema.h > cfe/trunk/lib/Sema/SemaDecl.cpp > cfe/trunk/lib/Sema/SemaDeclAttr.cpp > cfe/trunk/lib/Sema/SemaDeclCXX.cpp > cfe/trunk/lib/Sema/SemaLambda.cpp > > Modified: cfe/trunk/include/clang/Basic/Attr.td > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/ > clang/Basic/Attr.td?rev=332470&r1=332469&r2=332470&view=diff > > == > --- cfe/trunk/include/clang/Basic/Attr.td (original) > +++ cfe/trunk/include/clang/Basic/Attr.td Wed May 16 06:57:17 2018 > @@ -1769,6 +1769,13 @@ def Section : InheritableAttr { >let Documentation = [SectionDocs]; > } > > +def CodeSeg : InheritableAttr { > + let Spellings = [Declspec<"code_seg">]; > + let Args = [StringArgument<"Name">]; > + let Subjects = SubjectList<[Function, CXXRecord], ErrorDiag>; > + let Documentation = [CodeSegDocs]; > +} > + > def PragmaClangBSSSection : InheritableAttr { >// This attribute has no spellings as it is only ever created > implicitly. >let Spellings = []; > > Modified: cfe/trunk/include/clang/Basic/AttrDocs.td > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/ > clang/Basic/AttrDocs.td?rev=332470&r1=332469&r2=332470&view=diff > > == > --- cfe/trunk/include/clang/Basic/AttrDocs.td (original) > +++ cfe/trunk/include/clang/Basic/AttrDocs.td Wed May 16 06:57:17 2018 > @@ -306,6 +306,18 @@ An example of how to use ``alloc_size`` >}]; > } > > +def CodeSegDocs : Documentation { > + let Category = DocCatFunction; > + let Content = [{ > +The ``__declspec(code_seg)`` attribute enables the placement of code into > separate > +named segments that can be paged or locked in memory individually. This > attribute > +is used to control the placement of instantiated templates and > compiler-generated > +code. See the documentation for `__declspec(code_seg)`_ on MSDN. > + > +.. _`__declspec(code_seg)`: http://msdn.microsoft.com/en- > us/library/dn636922.aspx > + }]; > +} > + > def AllocAlignDocs : Documentation { >let Category = DocCatFunction; >let Content = [{ > > Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/ > DiagnosticSemaKinds.td?rev=332470&r1=332469&r2=332470&view=diff > > == > --- cfe/trunk/include/clang/Bas
Re: r332470 - Add support for __declspec(code_seg("segname"))
Here's an example regression: https://godbolt.org/g/S72Nki I'll check that into the test suite alongside the revert once my testing finishes. On 18 May 2018 at 13:03, Richard Smith wrote: > On 16 May 2018 at 06:57, Erich Keane via cfe-commits < > cfe-commits@lists.llvm.org> wrote: > >> Author: erichkeane >> Date: Wed May 16 06:57:17 2018 >> New Revision: 332470 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=332470&view=rev >> Log: >> Add support for __declspec(code_seg("segname")) >> >> Add support for __declspec(code_seg("segname")) >> >> This patch is built on the existing support for #pragma code_seg. The >> code_seg >> declspec is allowed on functions and classes. The attribute enables the >> placement of code into separate named segments, including >> compiler-generated >> members and template instantiations. >> >> For more information, please see the following: >> https://msdn.microsoft.com/en-us/library/dn636922.aspx >> >> A new CodeSeg attribute is used instead of adding a new spelling to the >> existing >> Section attribute since they don’t apply to the same Subjects. Section >> attributes are also added for the code_seg declspec since they are used >> for >> #pragma code_seg. No CodeSeg attributes are added to the AST. >> > > This approach really doesn't work. You're incorrectly applying the > __declspec(code_seg) restrictions to __attribute__((section)), regressing > our support for the latter. Also, code_seg has fundamentally different > semantics from the section attribute -- the former exists in part to > support paged addressing (which is why it has the virtual function > restriction) and the latter exists merely to control properties of the > object file. This approach also violates our policy of maintaining source > fidelity. > > I'm going to revert this for now to fix the regression; when it comes > back, I think you should just use CodeSegAttr to represent > __declspec(code_seg) rather than trying to treat it as -- effectively -- a > different spelling of SectionAttr. > > >> The patch is written to match with the Microsoft compiler’s behavior even >> where >> that behavior is a little complicated (see https://reviews.llvm.org/D2293 >> 1, the >> Microsoft feedback page is no longer available since MS has removed the >> page). >> That code is in getImplicitSectionAttrFromClass routine. >> >> Diagnostics messages are added to match with the Microsoft compiler for >> code-seg >> attribute mismatches on base and derived classes and virtual overrides. >> >> >> Differential Revision: https://reviews.llvm.org/D43352 >> >> Modified: >> cfe/trunk/include/clang/Basic/Attr.td >> cfe/trunk/include/clang/Basic/AttrDocs.td >> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td >> cfe/trunk/include/clang/Sema/Sema.h >> cfe/trunk/lib/Sema/SemaDecl.cpp >> cfe/trunk/lib/Sema/SemaDeclAttr.cpp >> cfe/trunk/lib/Sema/SemaDeclCXX.cpp >> cfe/trunk/lib/Sema/SemaLambda.cpp >> >> Modified: cfe/trunk/include/clang/Basic/Attr.td >> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ >> Basic/Attr.td?rev=332470&r1=332469&r2=332470&view=diff >> >> == >> --- cfe/trunk/include/clang/Basic/Attr.td (original) >> +++ cfe/trunk/include/clang/Basic/Attr.td Wed May 16 06:57:17 2018 >> @@ -1769,6 +1769,13 @@ def Section : InheritableAttr { >>let Documentation = [SectionDocs]; >> } >> >> +def CodeSeg : InheritableAttr { >> + let Spellings = [Declspec<"code_seg">]; >> + let Args = [StringArgument<"Name">]; >> + let Subjects = SubjectList<[Function, CXXRecord], ErrorDiag>; >> + let Documentation = [CodeSegDocs]; >> +} >> + >> def PragmaClangBSSSection : InheritableAttr { >>// This attribute has no spellings as it is only ever created >> implicitly. >>let Spellings = []; >> >> Modified: cfe/trunk/include/clang/Basic/AttrDocs.td >> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ >> Basic/AttrDocs.td?rev=332470&r1=332469&r2=332470&view=diff >> >> == >> --- cfe/trunk/include/clang/Basic/AttrDocs.td (original) >> +++ cfe/trunk/include/clang/Basic/AttrDocs.td Wed May 16 06:57:17 2018 >> @@ -306,6 +306,18 @@ An example of how to use ``alloc_size`` >>}]; >> } >> >> +def CodeSegDocs : Documentation { >> + let Category = DocCatFunction; >> + let Content = [{ >> +The ``__declspec(code_seg)`` attribute enables the placement of code >> into separate >> +named segments that can be paged or locked in memory individually. This >> attribute >> +is used to control the placement of instantiated templates and >> compiler-generated >> +code. See the documentation for `__declspec(code_seg)`_ on MSDN. >> + >> +.. _`__declspec(code_seg)`: http://msdn.microsoft.com/en-u >> s/library/dn636922.aspx >> + }]; >> +} >> + >> def AllocAlignDocs : Documentation { >>let Category = DocCatFunction; >>let Con
r332760 - Revert r332470 (and corresponding tests in r332492).
Author: rsmith Date: Fri May 18 13:18:17 2018 New Revision: 332760 URL: http://llvm.org/viewvc/llvm-project?rev=332760&view=rev Log: Revert r332470 (and corresponding tests in r332492). This regressed our support for __attribute__((section)). See added test file for example of code broken by this. Added: cfe/trunk/test/SemaCXX/attr-section.cpp - copied, changed from r332757, cfe/trunk/test/Sema/attr-section.c Removed: cfe/trunk/test/CodeGenCXX/code_seg1.cpp cfe/trunk/test/CodeGenCXX/code_seg2.cpp cfe/trunk/test/CodeGenCXX/code_seg3.cpp cfe/trunk/test/CodeGenCXX/code_seg4.cpp cfe/trunk/test/SemaCXX/code_seg.cpp cfe/trunk/test/SemaCXX/code_seg1.cpp Modified: cfe/trunk/include/clang/Basic/Attr.td cfe/trunk/include/clang/Basic/AttrDocs.td cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/include/clang/Sema/Sema.h cfe/trunk/lib/Sema/SemaDecl.cpp cfe/trunk/lib/Sema/SemaDeclAttr.cpp cfe/trunk/lib/Sema/SemaDeclCXX.cpp cfe/trunk/lib/Sema/SemaLambda.cpp Modified: cfe/trunk/include/clang/Basic/Attr.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=332760&r1=332759&r2=332760&view=diff == --- cfe/trunk/include/clang/Basic/Attr.td (original) +++ cfe/trunk/include/clang/Basic/Attr.td Fri May 18 13:18:17 2018 @@ -1770,13 +1770,6 @@ def Section : InheritableAttr { let Documentation = [SectionDocs]; } -def CodeSeg : InheritableAttr { - let Spellings = [Declspec<"code_seg">]; - let Args = [StringArgument<"Name">]; - let Subjects = SubjectList<[Function, CXXRecord], ErrorDiag>; - let Documentation = [CodeSegDocs]; -} - def PragmaClangBSSSection : InheritableAttr { // This attribute has no spellings as it is only ever created implicitly. let Spellings = []; Modified: cfe/trunk/include/clang/Basic/AttrDocs.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AttrDocs.td?rev=332760&r1=332759&r2=332760&view=diff == --- cfe/trunk/include/clang/Basic/AttrDocs.td (original) +++ cfe/trunk/include/clang/Basic/AttrDocs.td Fri May 18 13:18:17 2018 @@ -306,18 +306,6 @@ An example of how to use ``alloc_size`` }]; } -def CodeSegDocs : Documentation { - let Category = DocCatFunction; - let Content = [{ -The ``__declspec(code_seg)`` attribute enables the placement of code into separate -named segments that can be paged or locked in memory individually. This attribute -is used to control the placement of instantiated templates and compiler-generated -code. See the documentation for `__declspec(code_seg)`_ on MSDN. - -.. _`__declspec(code_seg)`: http://msdn.microsoft.com/en-us/library/dn636922.aspx - }]; -} - def AllocAlignDocs : Documentation { let Category = DocCatFunction; let Content = [{ Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=332760&r1=332759&r2=332760&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri May 18 13:18:17 2018 @@ -2668,14 +2668,6 @@ def warn_mismatched_section : Warning< def warn_attribute_section_on_redeclaration : Warning< "section attribute is specified on redeclared variable">, InGroup; -def err_mismatched_code_seg_base : Error< - "derived class must specify the same code segment as its base classes">; -def err_mismatched_code_seg_override : Error< - "overriding virtual function must specify the same code segment as its overridden function">; -def err_conflicting_codeseg_attribute : Error< - "conflicting code segment specifiers">; -def warn_duplicate_codeseg_attribute : Warning< - "duplicate code segment specifiers">, InGroup; def err_anonymous_property: Error< "anonymous property is not supported">; def err_property_is_variably_modified : Error< Modified: cfe/trunk/include/clang/Sema/Sema.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=332760&r1=332759&r2=332760&view=diff == --- cfe/trunk/include/clang/Sema/Sema.h (original) +++ cfe/trunk/include/clang/Sema/Sema.h Fri May 18 13:18:17 2018 @@ -1934,7 +1934,6 @@ public: bool shouldLinkDependentDeclWithPrevious(Decl *D, Decl *OldDecl); void CheckMain(FunctionDecl *FD, const DeclSpec &D); void CheckMSVCRTEntryPoint(FunctionDecl *FD); - Attr *getImplicitSectionAttrForFunction(const FunctionDecl *FD, bool IsDefinition = true); Decl *ActOnParamDeclarator(Scope *S, Declarator &D); ParmVarDecl *BuildParmVarDeclForTypedef(DeclContext *DC, SourceLocation Loc, @@ -5837,7 +5836,6 @@ pub
r332879 - Revert r332028; see PR37545 for details.
Author: rsmith Date: Mon May 21 13:10:54 2018 New Revision: 332879 URL: http://llvm.org/viewvc/llvm-project?rev=332879&view=rev Log: Revert r332028; see PR37545 for details. Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp cfe/trunk/test/CodeGenCXX/rtti-linkage.cpp Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=332879&r1=332878&r2=332879&view=diff == --- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original) +++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Mon May 21 13:10:54 2018 @@ -3006,46 +3006,8 @@ void ItaniumRTTIBuilder::BuildVTablePoin /// Return the linkage that the type info and type info name constants /// should have for the given type. -static std::pair -getTypeInfoLinkage(CodeGenModule &CGM, QualType Ty) { - llvm::GlobalValue::LinkageTypes TypeLinkage = [&]() { -switch (Ty->getLinkage()) { -case NoLinkage: -case InternalLinkage: -case UniqueExternalLinkage: - return llvm::GlobalValue::InternalLinkage; - -case VisibleNoLinkage: -case ModuleInternalLinkage: -case ModuleLinkage: -case ExternalLinkage: - // RTTI is not enabled, which means that this type info struct is going - // to be used for exception handling. Give it linkonce_odr linkage. - if (!CGM.getLangOpts().RTTI) -return llvm::GlobalValue::LinkOnceODRLinkage; - - if (const RecordType *Record = dyn_cast(Ty)) { -const CXXRecordDecl *RD = cast(Record->getDecl()); -if (RD->hasAttr()) - return llvm::GlobalValue::WeakODRLinkage; -if (CGM.getTriple().isWindowsItaniumEnvironment()) - if (RD->hasAttr() && - ShouldUseExternalRTTIDescriptor(CGM, Ty)) -return llvm::GlobalValue::ExternalLinkage; -// MinGW always uses LinkOnceODRLinkage for type info. -if (RD->isCompleteDefinition() && RD->isDynamicClass() && -!CGM.getContext() - .getTargetInfo() - .getTriple() - .isWindowsGNUEnvironment()) - return CGM.getVTableLinkage(RD); - } - - return llvm::GlobalValue::LinkOnceODRLinkage; -} -llvm_unreachable("Invalid linkage!"); - }(); +static llvm::GlobalVariable::LinkageTypes getTypeInfoLinkage(CodeGenModule &CGM, + QualType Ty) { // Itanium C++ ABI 2.9.5p7: // In addition, it and all of the intermediate abi::__pointer_type_info // structs in the chain down to the abi::__class_type_info for the @@ -3056,8 +3018,44 @@ getTypeInfoLinkage(CodeGenModule &CGM, Q // complete class RTTI (because the latter need not exist), possibly by // making it a local static object. if (ContainsIncompleteClassType(Ty)) -return {llvm::GlobalValue::InternalLinkage, TypeLinkage}; - return {TypeLinkage, TypeLinkage}; +return llvm::GlobalValue::InternalLinkage; + + switch (Ty->getLinkage()) { + case NoLinkage: + case InternalLinkage: + case UniqueExternalLinkage: +return llvm::GlobalValue::InternalLinkage; + + case VisibleNoLinkage: + case ModuleInternalLinkage: + case ModuleLinkage: + case ExternalLinkage: +// RTTI is not enabled, which means that this type info struct is going +// to be used for exception handling. Give it linkonce_odr linkage. +if (!CGM.getLangOpts().RTTI) + return llvm::GlobalValue::LinkOnceODRLinkage; + +if (const RecordType *Record = dyn_cast(Ty)) { + const CXXRecordDecl *RD = cast(Record->getDecl()); + if (RD->hasAttr()) +return llvm::GlobalValue::WeakODRLinkage; + if (CGM.getTriple().isWindowsItaniumEnvironment()) +if (RD->hasAttr() && +ShouldUseExternalRTTIDescriptor(CGM, Ty)) + return llvm::GlobalValue::ExternalLinkage; + // MinGW always uses LinkOnceODRLinkage for type info. + if (RD->isDynamicClass() && + !CGM.getContext() + .getTargetInfo() + .getTriple() + .isWindowsGNUEnvironment()) +return CGM.getVTableLinkage(RD); +} + +return llvm::GlobalValue::LinkOnceODRLinkage; + } + + llvm_unreachable("Invalid linkage!"); } llvm::Constant *ItaniumRTTIBuilder::BuildTypeInfo(QualType Ty, bool Force, @@ -3084,25 +3082,23 @@ llvm::Constant *ItaniumRTTIBuilder::Buil return GetAddrOfExternalRTTIDescriptor(Ty); // Emit the standard library with external linkage. - llvm::GlobalVariable::LinkageTypes InfoLinkage, NameLinkage; + llvm::GlobalVariable::LinkageTypes Linkage; if (IsStdLib) -InfoLinkage = NameLinkage = llvm::GlobalValue::ExternalLinkage; - else { -auto LinkagePair = getTypeInfoLinkage(CGM, Ty); -InfoLinkage = LinkagePair.first; -NameLinkage = LinkagePair.second; - } +Linkage = llvm::GlobalValue::ExternalLinkage; + else +Linkage = getTypeInfoLinkage(CGM, Ty)
Re: r332847 - [CodeGen] Recognize more cases of zero initialization
On 21 May 2018 at 09:09, Serge Pavlov via cfe-commits < cfe-commits@lists.llvm.org> wrote: > Author: sepavloff > Date: Mon May 21 09:09:54 2018 > New Revision: 332847 > > URL: http://llvm.org/viewvc/llvm-project?rev=332847&view=rev > Log: > [CodeGen] Recognize more cases of zero initialization > > If a variable has an initializer, codegen tries to build its value. If > the variable is large in size, building its value requires substantial > resources. It causes strange behavior from user viewpoint: compilation > of huge zero initialized arrays like: > > char data_1[2147483648u] = { 0 }; > > consumes enormous amount of time and memory. > > With this change codegen tries to determine if variable initializer is > equivalent to zero initializer. In this case variable value is not > constructed. > > This change fixes PR18978. > > Differential Revision: https://reviews.llvm.org/D46241 > > Removed: > cfe/trunk/test/SemaCXX/large-array-init.cpp > Modified: > cfe/trunk/include/clang/AST/Expr.h > cfe/trunk/lib/AST/ExprConstant.cpp > cfe/trunk/lib/CodeGen/CGExprConstant.cpp > cfe/trunk/test/CodeGen/const-init.c > cfe/trunk/test/CodeGen/designated-initializers.c > cfe/trunk/test/CodeGen/union-init2.c > cfe/trunk/test/CodeGenCXX/cxx11-initializer-aggregate.cpp > cfe/trunk/test/CodeGenCXX/cxx1z-initializer-aggregate.cpp > > Modified: cfe/trunk/include/clang/AST/Expr.h > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/ > clang/AST/Expr.h?rev=332847&r1=332846&r2=332847&view=diff > > == > --- cfe/trunk/include/clang/AST/Expr.h (original) > +++ cfe/trunk/include/clang/AST/Expr.h Mon May 21 09:09:54 2018 > @@ -537,6 +537,13 @@ public: >bool isConstantInitializer(ASTContext &Ctx, bool ForRef, > const Expr **Culprit = nullptr) const; > > + enum SideEffectsKind { > +SE_NoSideEffects, ///< Strictly evaluate the expression. > +SE_AllowUndefinedBehavior, ///< Allow UB that we can give a value, > but not > + ///< arbitrary unmodeled side effects. > +SE_AllowSideEffects///< Allow any unmodeled side effect. > + }; > + >/// EvalStatus is a struct with detailed info about an evaluation in > progress. >struct EvalStatus { > /// Whether the evaluated expression has side effects. > @@ -565,6 +572,11 @@ public: > bool hasSideEffects() const { >return HasSideEffects; > } > + > +bool hasUnacceptableSideEffect(SideEffectsKind SEK) { > + return (SEK < SE_AllowSideEffects && HasSideEffects) || > + (SEK < SE_AllowUndefinedBehavior && HasUndefinedBehavior); > +} >}; > >/// EvalResult is a struct with detailed info about an evaluated > expression. > @@ -591,13 +603,6 @@ public: >/// side-effects. >bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx) > const; > > - enum SideEffectsKind { > -SE_NoSideEffects, ///< Strictly evaluate the expression. > -SE_AllowUndefinedBehavior, ///< Allow UB that we can give a value, > but not > - ///< arbitrary unmodeled side effects. > -SE_AllowSideEffects///< Allow any unmodeled side effect. > - }; > - >/// EvaluateAsInt - Return true if this is a constant which we can fold > and >/// convert to an integer, using any crazy technique that we want to. >bool EvaluateAsInt(llvm::APSInt &Result, const ASTContext &Ctx, > > Modified: cfe/trunk/lib/AST/ExprConstant.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ > ExprConstant.cpp?rev=332847&r1=332846&r2=332847&view=diff > > == > --- cfe/trunk/lib/AST/ExprConstant.cpp (original) > +++ cfe/trunk/lib/AST/ExprConstant.cpp Mon May 21 09:09:54 2018 > @@ -10312,12 +10312,6 @@ bool Expr::EvaluateAsBooleanCondition(bo > HandleConversionToBool(Scratch.Val, Result); > } > > -static bool hasUnacceptableSideEffect(Expr::EvalStatus &Result, > - Expr::SideEffectsKind SEK) { > - return (SEK < Expr::SE_AllowSideEffects && Result.HasSideEffects) || > - (SEK < Expr::SE_AllowUndefinedBehavior && > Result.HasUndefinedBehavior); > -} > - > bool Expr::EvaluateAsInt(APSInt &Result, const ASTContext &Ctx, > SideEffectsKind AllowSideEffects) const { >if (!getType()->isIntegralOrEnumerationType()) > @@ -10325,7 +10319,7 @@ bool Expr::EvaluateAsInt(APSInt &Result, > >EvalResult ExprResult; >if (!EvaluateAsRValue(ExprResult, Ctx) || !ExprResult.Val.isInt() || > - hasUnacceptableSideEffect(ExprResult, AllowSideEffects)) > + ExprResult.hasUnacceptableSideEffect(AllowSideEffects)) > return false; > >Result = ExprResult.Val.getInt(); > @@ -10339,7 +10333,7 @@ bool Expr::EvaluateAsFloat(APFloat &Resu > >EvalResult Ex
Re: r332847 - [CodeGen] Recognize more cases of zero initialization
On 21 May 2018 at 13:22, Richard Smith wrote: > On 21 May 2018 at 09:09, Serge Pavlov via cfe-commits < > cfe-commits@lists.llvm.org> wrote: > >> Author: sepavloff >> Date: Mon May 21 09:09:54 2018 >> New Revision: 332847 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=332847&view=rev >> Log: >> [CodeGen] Recognize more cases of zero initialization >> >> If a variable has an initializer, codegen tries to build its value. If >> the variable is large in size, building its value requires substantial >> resources. It causes strange behavior from user viewpoint: compilation >> of huge zero initialized arrays like: >> >> char data_1[2147483648u] = { 0 }; >> >> consumes enormous amount of time and memory. >> >> With this change codegen tries to determine if variable initializer is >> equivalent to zero initializer. In this case variable value is not >> constructed. >> >> This change fixes PR18978. >> >> Differential Revision: https://reviews.llvm.org/D46241 >> >> Removed: >> cfe/trunk/test/SemaCXX/large-array-init.cpp >> Modified: >> cfe/trunk/include/clang/AST/Expr.h >> cfe/trunk/lib/AST/ExprConstant.cpp >> cfe/trunk/lib/CodeGen/CGExprConstant.cpp >> cfe/trunk/test/CodeGen/const-init.c >> cfe/trunk/test/CodeGen/designated-initializers.c >> cfe/trunk/test/CodeGen/union-init2.c >> cfe/trunk/test/CodeGenCXX/cxx11-initializer-aggregate.cpp >> cfe/trunk/test/CodeGenCXX/cxx1z-initializer-aggregate.cpp >> >> Modified: cfe/trunk/include/clang/AST/Expr.h >> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ >> AST/Expr.h?rev=332847&r1=332846&r2=332847&view=diff >> >> == >> --- cfe/trunk/include/clang/AST/Expr.h (original) >> +++ cfe/trunk/include/clang/AST/Expr.h Mon May 21 09:09:54 2018 >> @@ -537,6 +537,13 @@ public: >>bool isConstantInitializer(ASTContext &Ctx, bool ForRef, >> const Expr **Culprit = nullptr) const; >> >> + enum SideEffectsKind { >> +SE_NoSideEffects, ///< Strictly evaluate the expression. >> +SE_AllowUndefinedBehavior, ///< Allow UB that we can give a value, >> but not >> + ///< arbitrary unmodeled side effects. >> +SE_AllowSideEffects///< Allow any unmodeled side effect. >> + }; >> + >>/// EvalStatus is a struct with detailed info about an evaluation in >> progress. >>struct EvalStatus { >> /// Whether the evaluated expression has side effects. >> @@ -565,6 +572,11 @@ public: >> bool hasSideEffects() const { >>return HasSideEffects; >> } >> + >> +bool hasUnacceptableSideEffect(SideEffectsKind SEK) { >> + return (SEK < SE_AllowSideEffects && HasSideEffects) || >> + (SEK < SE_AllowUndefinedBehavior && HasUndefinedBehavior); >> +} >>}; >> >>/// EvalResult is a struct with detailed info about an evaluated >> expression. >> @@ -591,13 +603,6 @@ public: >>/// side-effects. >>bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx) >> const; >> >> - enum SideEffectsKind { >> -SE_NoSideEffects, ///< Strictly evaluate the expression. >> -SE_AllowUndefinedBehavior, ///< Allow UB that we can give a value, >> but not >> - ///< arbitrary unmodeled side effects. >> -SE_AllowSideEffects///< Allow any unmodeled side effect. >> - }; >> - >>/// EvaluateAsInt - Return true if this is a constant which we can >> fold and >>/// convert to an integer, using any crazy technique that we want to. >>bool EvaluateAsInt(llvm::APSInt &Result, const ASTContext &Ctx, >> >> Modified: cfe/trunk/lib/AST/ExprConstant.cpp >> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprCo >> nstant.cpp?rev=332847&r1=332846&r2=332847&view=diff >> >> == >> --- cfe/trunk/lib/AST/ExprConstant.cpp (original) >> +++ cfe/trunk/lib/AST/ExprConstant.cpp Mon May 21 09:09:54 2018 >> @@ -10312,12 +10312,6 @@ bool Expr::EvaluateAsBooleanCondition(bo >> HandleConversionToBool(Scratch.Val, Result); >> } >> >> -static bool hasUnacceptableSideEffect(Expr::EvalStatus &Result, >> - Expr::SideEffectsKind SEK) { >> - return (SEK < Expr::SE_AllowSideEffects && Result.HasSideEffects) || >> - (SEK < Expr::SE_AllowUndefinedBehavior && >> Result.HasUndefinedBehavior); >> -} >> - >> bool Expr::EvaluateAsInt(APSInt &Result, const ASTContext &Ctx, >> SideEffectsKind AllowSideEffects) const { >>if (!getType()->isIntegralOrEnumerationType()) >> @@ -10325,7 +10319,7 @@ bool Expr::EvaluateAsInt(APSInt &Result, >> >>EvalResult ExprResult; >>if (!EvaluateAsRValue(ExprResult, Ctx) || !ExprResult.Val.isInt() || >> - hasUnacceptableSideEffect(ExprResult, AllowSideEffects)) >> + ExprResult.hasUnacceptableSideEffe
Re: r332847 - [CodeGen] Recognize more cases of zero initialization
Reverted in r332886; I added a testcase for the miscompile below to test/CodeGenCXX/reference-init.cpp On 21 May 2018 at 13:28, Richard Smith wrote: > On 21 May 2018 at 13:22, Richard Smith wrote: > >> On 21 May 2018 at 09:09, Serge Pavlov via cfe-commits < >> cfe-commits@lists.llvm.org> wrote: >> >>> Author: sepavloff >>> Date: Mon May 21 09:09:54 2018 >>> New Revision: 332847 >>> >>> URL: http://llvm.org/viewvc/llvm-project?rev=332847&view=rev >>> Log: >>> [CodeGen] Recognize more cases of zero initialization >>> >>> If a variable has an initializer, codegen tries to build its value. If >>> the variable is large in size, building its value requires substantial >>> resources. It causes strange behavior from user viewpoint: compilation >>> of huge zero initialized arrays like: >>> >>> char data_1[2147483648u] = { 0 }; >>> >>> consumes enormous amount of time and memory. >>> >>> With this change codegen tries to determine if variable initializer is >>> equivalent to zero initializer. In this case variable value is not >>> constructed. >>> >>> This change fixes PR18978. >>> >>> Differential Revision: https://reviews.llvm.org/D46241 >>> >>> Removed: >>> cfe/trunk/test/SemaCXX/large-array-init.cpp >>> Modified: >>> cfe/trunk/include/clang/AST/Expr.h >>> cfe/trunk/lib/AST/ExprConstant.cpp >>> cfe/trunk/lib/CodeGen/CGExprConstant.cpp >>> cfe/trunk/test/CodeGen/const-init.c >>> cfe/trunk/test/CodeGen/designated-initializers.c >>> cfe/trunk/test/CodeGen/union-init2.c >>> cfe/trunk/test/CodeGenCXX/cxx11-initializer-aggregate.cpp >>> cfe/trunk/test/CodeGenCXX/cxx1z-initializer-aggregate.cpp >>> >>> Modified: cfe/trunk/include/clang/AST/Expr.h >>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ >>> AST/Expr.h?rev=332847&r1=332846&r2=332847&view=diff >>> >>> == >>> --- cfe/trunk/include/clang/AST/Expr.h (original) >>> +++ cfe/trunk/include/clang/AST/Expr.h Mon May 21 09:09:54 2018 >>> @@ -537,6 +537,13 @@ public: >>>bool isConstantInitializer(ASTContext &Ctx, bool ForRef, >>> const Expr **Culprit = nullptr) const; >>> >>> + enum SideEffectsKind { >>> +SE_NoSideEffects, ///< Strictly evaluate the expression. >>> +SE_AllowUndefinedBehavior, ///< Allow UB that we can give a value, >>> but not >>> + ///< arbitrary unmodeled side effects. >>> +SE_AllowSideEffects///< Allow any unmodeled side effect. >>> + }; >>> + >>>/// EvalStatus is a struct with detailed info about an evaluation in >>> progress. >>>struct EvalStatus { >>> /// Whether the evaluated expression has side effects. >>> @@ -565,6 +572,11 @@ public: >>> bool hasSideEffects() const { >>>return HasSideEffects; >>> } >>> + >>> +bool hasUnacceptableSideEffect(SideEffectsKind SEK) { >>> + return (SEK < SE_AllowSideEffects && HasSideEffects) || >>> + (SEK < SE_AllowUndefinedBehavior && HasUndefinedBehavior); >>> +} >>>}; >>> >>>/// EvalResult is a struct with detailed info about an evaluated >>> expression. >>> @@ -591,13 +603,6 @@ public: >>>/// side-effects. >>>bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx) >>> const; >>> >>> - enum SideEffectsKind { >>> -SE_NoSideEffects, ///< Strictly evaluate the expression. >>> -SE_AllowUndefinedBehavior, ///< Allow UB that we can give a value, >>> but not >>> - ///< arbitrary unmodeled side effects. >>> -SE_AllowSideEffects///< Allow any unmodeled side effect. >>> - }; >>> - >>>/// EvaluateAsInt - Return true if this is a constant which we can >>> fold and >>>/// convert to an integer, using any crazy technique that we want to. >>>bool EvaluateAsInt(llvm::APSInt &Result, const ASTContext &Ctx, >>> >>> Modified: cfe/trunk/lib/AST/ExprConstant.cpp >>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprCo >>> nstant.cpp?rev=332847&r1=332846&r2=332847&view=diff >>> >>> == >>> --- cfe/trunk/lib/AST/ExprConstant.cpp (original) >>> +++ cfe/trunk/lib/AST/ExprConstant.cpp Mon May 21 09:09:54 2018 >>> @@ -10312,12 +10312,6 @@ bool Expr::EvaluateAsBooleanCondition(bo >>> HandleConversionToBool(Scratch.Val, Result); >>> } >>> >>> -static bool hasUnacceptableSideEffect(Expr::EvalStatus &Result, >>> - Expr::SideEffectsKind SEK) { >>> - return (SEK < Expr::SE_AllowSideEffects && Result.HasSideEffects) || >>> - (SEK < Expr::SE_AllowUndefinedBehavior && >>> Result.HasUndefinedBehavior); >>> -} >>> - >>> bool Expr::EvaluateAsInt(APSInt &Result, const ASTContext &Ctx, >>> SideEffectsKind AllowSideEffects) const { >>>if (!getType()->isIntegralOrEnumerationType()) >>> @@ -10325,7
r332886 - Revert r332847; it caused us to miscompile certain forms of reference initialization.
Author: rsmith Date: Mon May 21 13:36:58 2018 New Revision: 332886 URL: http://llvm.org/viewvc/llvm-project?rev=332886&view=rev Log: Revert r332847; it caused us to miscompile certain forms of reference initialization. Added: cfe/trunk/test/SemaCXX/large-array-init.cpp - copied unchanged from r332846, cfe/trunk/test/SemaCXX/large-array-init.cpp Modified: cfe/trunk/include/clang/AST/Expr.h cfe/trunk/lib/AST/ExprConstant.cpp cfe/trunk/lib/CodeGen/CGExprConstant.cpp cfe/trunk/test/CodeGen/const-init.c cfe/trunk/test/CodeGen/designated-initializers.c cfe/trunk/test/CodeGen/union-init2.c cfe/trunk/test/CodeGenCXX/cxx11-initializer-aggregate.cpp cfe/trunk/test/CodeGenCXX/cxx1z-initializer-aggregate.cpp cfe/trunk/test/CodeGenCXX/reference-init.cpp Modified: cfe/trunk/include/clang/AST/Expr.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=332886&r1=332885&r2=332886&view=diff == --- cfe/trunk/include/clang/AST/Expr.h (original) +++ cfe/trunk/include/clang/AST/Expr.h Mon May 21 13:36:58 2018 @@ -537,13 +537,6 @@ public: bool isConstantInitializer(ASTContext &Ctx, bool ForRef, const Expr **Culprit = nullptr) const; - enum SideEffectsKind { -SE_NoSideEffects, ///< Strictly evaluate the expression. -SE_AllowUndefinedBehavior, ///< Allow UB that we can give a value, but not - ///< arbitrary unmodeled side effects. -SE_AllowSideEffects///< Allow any unmodeled side effect. - }; - /// EvalStatus is a struct with detailed info about an evaluation in progress. struct EvalStatus { /// Whether the evaluated expression has side effects. @@ -572,11 +565,6 @@ public: bool hasSideEffects() const { return HasSideEffects; } - -bool hasUnacceptableSideEffect(SideEffectsKind SEK) { - return (SEK < SE_AllowSideEffects && HasSideEffects) || - (SEK < SE_AllowUndefinedBehavior && HasUndefinedBehavior); -} }; /// EvalResult is a struct with detailed info about an evaluated expression. @@ -603,6 +591,13 @@ public: /// side-effects. bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx) const; + enum SideEffectsKind { +SE_NoSideEffects, ///< Strictly evaluate the expression. +SE_AllowUndefinedBehavior, ///< Allow UB that we can give a value, but not + ///< arbitrary unmodeled side effects. +SE_AllowSideEffects///< Allow any unmodeled side effect. + }; + /// EvaluateAsInt - Return true if this is a constant which we can fold and /// convert to an integer, using any crazy technique that we want to. bool EvaluateAsInt(llvm::APSInt &Result, const ASTContext &Ctx, Modified: cfe/trunk/lib/AST/ExprConstant.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=332886&r1=332885&r2=332886&view=diff == --- cfe/trunk/lib/AST/ExprConstant.cpp (original) +++ cfe/trunk/lib/AST/ExprConstant.cpp Mon May 21 13:36:58 2018 @@ -10312,6 +10312,12 @@ bool Expr::EvaluateAsBooleanCondition(bo HandleConversionToBool(Scratch.Val, Result); } +static bool hasUnacceptableSideEffect(Expr::EvalStatus &Result, + Expr::SideEffectsKind SEK) { + return (SEK < Expr::SE_AllowSideEffects && Result.HasSideEffects) || + (SEK < Expr::SE_AllowUndefinedBehavior && Result.HasUndefinedBehavior); +} + bool Expr::EvaluateAsInt(APSInt &Result, const ASTContext &Ctx, SideEffectsKind AllowSideEffects) const { if (!getType()->isIntegralOrEnumerationType()) @@ -10319,7 +10325,7 @@ bool Expr::EvaluateAsInt(APSInt &Result, EvalResult ExprResult; if (!EvaluateAsRValue(ExprResult, Ctx) || !ExprResult.Val.isInt() || - ExprResult.hasUnacceptableSideEffect(AllowSideEffects)) + hasUnacceptableSideEffect(ExprResult, AllowSideEffects)) return false; Result = ExprResult.Val.getInt(); @@ -10333,7 +10339,7 @@ bool Expr::EvaluateAsFloat(APFloat &Resu EvalResult ExprResult; if (!EvaluateAsRValue(ExprResult, Ctx) || !ExprResult.Val.isFloat() || - ExprResult.hasUnacceptableSideEffect(AllowSideEffects)) + hasUnacceptableSideEffect(ExprResult, AllowSideEffects)) return false; Result = ExprResult.Val.getFloat(); @@ -10411,7 +10417,7 @@ bool Expr::EvaluateAsInitializer(APValue bool Expr::isEvaluatable(const ASTContext &Ctx, SideEffectsKind SEK) const { EvalResult Result; return EvaluateAsRValue(Result, Ctx) && - !Result.hasUnacceptableSideEffect(SEK); + !hasUnacceptableSideEffect(Result, SEK); } APSInt Expr::EvaluateKnownConstInt(const ASTContext &Ctx, Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp URL: http://llvm.org/viewvc/llv
r333044 - Use zeroinitializer for (trailing zero portion of) large array initializers
Author: rsmith Date: Tue May 22 17:09:29 2018 New Revision: 333044 URL: http://llvm.org/viewvc/llvm-project?rev=333044&view=rev Log: Use zeroinitializer for (trailing zero portion of) large array initializers more reliably. Clang has two different ways it emits array constants (from InitListExprs and from APValues), and both had some ability to emit zeroinitializer, but neither was able to catch all cases where we could use zeroinitializer reliably. In particular, emitting from an APValue would fail to notice if all the explicit array elements happened to be zero. In addition, for large arrays where only an initial portion has an explicit initializer, we would emit the complete initializer (which could be huge) rather than emitting only the non-zero portion. With this change, when the element would have a suffix of more than 8 zero elements, we emit the array constant as a packed struct of its initial portion followed by a zeroinitializer constant for the trailing zero portion. In passing, I found a bug where SemaInit would sometimes walk the entire array when checking an initializer that only covers the first few elements; that's fixed here to unblock testing of the rest. Differential Revision: https://reviews.llvm.org/D47166 Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp cfe/trunk/lib/Sema/SemaInit.cpp cfe/trunk/test/CodeGen/init.c cfe/trunk/test/CodeGenCXX/cxx11-initializer-aggregate.cpp cfe/trunk/test/SemaCXX/aggregate-initialization.cpp Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=333044&r1=333043&r2=333044&view=diff == --- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original) +++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Tue May 22 17:09:29 2018 @@ -635,6 +635,52 @@ static ConstantAddress tryEmitGlobalComp return ConstantAddress(GV, Align); } +static llvm::Constant * +EmitArrayConstant(llvm::ArrayType *PreferredArrayType, + llvm::Type *CommonElementType, unsigned ArrayBound, + SmallVectorImpl &Elements, + llvm::Constant *Filler) { + // Figure out how long the initial prefix of non-zero elements is. + unsigned NonzeroLength = ArrayBound; + if (Elements.size() < NonzeroLength && Filler->isNullValue()) +NonzeroLength = Elements.size(); + if (NonzeroLength == Elements.size()) { +while (NonzeroLength > 0 && Elements[NonzeroLength - 1]->isNullValue()) + --NonzeroLength; + } + + if (NonzeroLength == 0) +return llvm::ConstantAggregateZero::get(PreferredArrayType); + + // If there's not many trailing zero elements, just emit an array + // constant. + if (NonzeroLength + 8 >= ArrayBound && CommonElementType) { +Elements.resize(ArrayBound, Filler); +return llvm::ConstantArray::get( +llvm::ArrayType::get(CommonElementType, ArrayBound), Elements); + } + + // Add a zeroinitializer array filler if we have trailing zeroes. + if (unsigned TrailingZeroes = ArrayBound - NonzeroLength) { +assert(Elements.size() >= NonzeroLength && + "missing initializer for non-zero element"); +Elements.resize(NonzeroLength + 1); +auto *FillerType = PreferredArrayType->getElementType(); +if (TrailingZeroes > 1) + FillerType = llvm::ArrayType::get(FillerType, TrailingZeroes); +Elements.back() = llvm::ConstantAggregateZero::get(FillerType); + } + + // We have mixed types. Use a packed struct. + llvm::SmallVector Types; + Types.reserve(Elements.size()); + for (llvm::Constant *Elt : Elements) +Types.push_back(Elt->getType()); + llvm::StructType *SType = + llvm::StructType::get(PreferredArrayType->getContext(), Types, true); + return llvm::ConstantStruct::get(SType, Elements); +} + /// This class only needs to handle two cases: /// 1) Literals (this is used by APValue emission to emit literals). /// 2) Arrays, structs and unions (outside C++11 mode, we don't currently @@ -834,7 +880,6 @@ public: llvm::Constant *EmitArrayInitialization(InitListExpr *ILE, QualType T) { llvm::ArrayType *AType = cast(ConvertType(ILE->getType())); -llvm::Type *ElemTy = AType->getElementType(); unsigned NumInitElements = ILE->getNumInits(); unsigned NumElements = AType->getNumElements(); @@ -845,55 +890,35 @@ public: QualType EltType = CGM.getContext().getAsArrayType(T)->getElementType(); // Initialize remaining array elements. -llvm::Constant *fillC; -if (Expr *filler = ILE->getArrayFiller()) +llvm::Constant *fillC = nullptr; +if (Expr *filler = ILE->getArrayFiller()) { fillC = Emitter.tryEmitAbstractForMemory(filler, EltType); -else - fillC = Emitter.emitNullForMemory(EltType); -if (!fillC) - return nullptr; - -// Try to use a ConstantAggregateZero if we can. -if (fillC->isNullValue() && !NumInitableElts) - return llvm:
Re: r333044 - Use zeroinitializer for (trailing zero portion of) large array initializers
OK, thanks for the revert. On Wed, 23 May 2018, 01:28 Hans Wennborg via cfe-commits, < cfe-commits@lists.llvm.org> wrote: > We're hitting asserts after this in Chromium. I've filed PR37560 and > reverted in r333067. > > On Wed, May 23, 2018 at 2:09 AM, Richard Smith via cfe-commits > wrote: > > Author: rsmith > > Date: Tue May 22 17:09:29 2018 > > New Revision: 333044 > > > > URL: http://llvm.org/viewvc/llvm-project?rev=333044&view=rev > > Log: > > Use zeroinitializer for (trailing zero portion of) large array > initializers > > more reliably. > > > > Clang has two different ways it emits array constants (from > InitListExprs and > > from APValues), and both had some ability to emit zeroinitializer, but > neither > > was able to catch all cases where we could use zeroinitializer reliably. > In > > particular, emitting from an APValue would fail to notice if all the > explicit > > array elements happened to be zero. In addition, for large arrays where > only an > > initial portion has an explicit initializer, we would emit the complete > > initializer (which could be huge) rather than emitting only the non-zero > > portion. With this change, when the element would have a suffix of more > than 8 > > zero elements, we emit the array constant as a packed struct of its > initial > > portion followed by a zeroinitializer constant for the trailing zero > portion. > > > > In passing, I found a bug where SemaInit would sometimes walk the entire > array > > when checking an initializer that only covers the first few elements; > that's > > fixed here to unblock testing of the rest. > > > > Differential Revision: https://reviews.llvm.org/D47166 > > > > Modified: > > cfe/trunk/lib/CodeGen/CGExprConstant.cpp > > cfe/trunk/lib/Sema/SemaInit.cpp > > cfe/trunk/test/CodeGen/init.c > > cfe/trunk/test/CodeGenCXX/cxx11-initializer-aggregate.cpp > > cfe/trunk/test/SemaCXX/aggregate-initialization.cpp > ___ > cfe-commits mailing list > cfe-commits@lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits > ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r333126 - Rework __builtin_classify_type support to better match GCC and to not assert on
Author: rsmith Date: Wed May 23 14:18:00 2018 New Revision: 333126 URL: http://llvm.org/viewvc/llvm-project?rev=333126&view=rev Log: Rework __builtin_classify_type support to better match GCC and to not assert on unusual types. Following the observed behavior of GCC, we now return -1 for vector types (along with all of our extensions that GCC doesn't support), and for atomic types we classify the underlying type. GCC appears to have changed its classification for function and array arguments between version 5 and version 6. Previously it would classify them as pointers in C and as functions or arrays in C++, but from version 6 onwards, it classifies them as pointers. We now follow the more recent GCC behavior rather than emulating what I can only assume to be a historical bug in their C++ support for this builtin. Finally, no version of GCC that I can find has ever used the "method" classification for C++ pointers to member functions. Instead, GCC classifies them as record types, presumably reflecting an internal implementation detail, but whatever the reason we now produce compatible results. Modified: cfe/trunk/lib/AST/ExprConstant.cpp cfe/trunk/test/Sema/builtin-classify-type.c cfe/trunk/test/SemaCXX/builtin-classify-type.cpp Modified: cfe/trunk/lib/AST/ExprConstant.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=333126&r1=333125&r2=333126&view=diff == --- cfe/trunk/lib/AST/ExprConstant.cpp (original) +++ cfe/trunk/lib/AST/ExprConstant.cpp Wed May 23 14:18:00 2018 @@ -7277,30 +7277,43 @@ bool IntExprEvaluator::CheckReferencedDe return false; } +/// Values returned by __builtin_classify_type, chosen to match the values +/// produced by GCC's builtin. +enum class GCCTypeClass { + None = -1, + Void = 0, + Integer = 1, + // GCC reserves 2 for character types, but instead classifies them as + // integers. + Enum = 3, + Bool = 4, + Pointer = 5, + // GCC reserves 6 for references, but appears to never use it (because + // expressions never have reference type, presumably). + PointerToDataMember = 7, + RealFloat = 8, + Complex = 9, + // GCC reserves 10 for functions, but does not use it since GCC version 6 due + // to decay to pointer. (Prior to version 6 it was only used in C++ mode). + // GCC claims to reserve 11 for pointers to member functions, but *actually* + // uses 12 for that purpose, same as for a class or struct. Maybe it + // internally implements a pointer to member as a struct? Who knows. + PointerToMemberFunction = 12, // Not a bug, see above. + ClassOrStruct = 12, + Union = 13, + // GCC reserves 14 for arrays, but does not use it since GCC version 6 due to + // decay to pointer. (Prior to version 6 it was only used in C++ mode). + // GCC reserves 15 for strings, but actually uses 5 (pointer) for string + // literals. +}; + /// EvaluateBuiltinClassifyType - Evaluate __builtin_classify_type the same way /// as GCC. -static int EvaluateBuiltinClassifyType(const CallExpr *E, - const LangOptions &LangOpts) { - // The following enum mimics the values returned by GCC. - // FIXME: Does GCC differ between lvalue and rvalue references here? - enum gcc_type_class { -no_type_class = -1, -void_type_class, integer_type_class, char_type_class, -enumeral_type_class, boolean_type_class, -pointer_type_class, reference_type_class, offset_type_class, -real_type_class, complex_type_class, -function_type_class, method_type_class, -record_type_class, union_type_class, -array_type_class, string_type_class, -lang_type_class - }; - - // If no argument was supplied, default to "no_type_class". This isn't - // ideal, however it is what gcc does. - if (E->getNumArgs() == 0) -return no_type_class; +static GCCTypeClass +EvaluateBuiltinClassifyType(QualType T, const LangOptions &LangOpts) { + assert(!T->isDependentType() && "unexpected dependent type"); - QualType CanTy = E->getArg(0)->getType().getCanonicalType(); + QualType CanTy = T.getCanonicalType(); const BuiltinType *BT = dyn_cast(CanTy); switch (CanTy->getTypeClass()) { @@ -7309,37 +7322,41 @@ static int EvaluateBuiltinClassifyType(c #define NON_CANONICAL_TYPE(ID, BASE) case Type::ID: #define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(ID, BASE) case Type::ID: #include "clang/AST/TypeNodes.def" - llvm_unreachable("CallExpr::isBuiltinClassifyType(): unimplemented type"); + case Type::Auto: + case Type::DeducedTemplateSpecialization: + llvm_unreachable("unexpected non-canonical or dependent type"); case Type::Builtin: switch (BT->getKind()) { #define BUILTIN_TYPE(ID, SINGLETON_ID) -#define SIGNED_TYPE(ID, SINGLETON_ID) case BuiltinType::ID: return integer_type_class; -#define FLOATING_TYPE(ID, SINGLETON_ID) case BuiltinType::ID: return real_type_class; -#define PLACEHOLDER_TYPE(ID, SINGLETON_
r333141 - Use zeroinitializer for (trailing zero portion of) large array initializers
Author: rsmith Date: Wed May 23 16:41:38 2018 New Revision: 333141 URL: http://llvm.org/viewvc/llvm-project?rev=333141&view=rev Log: Use zeroinitializer for (trailing zero portion of) large array initializers more reliably. This re-commits r333044 with a fix for PR37560. Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp cfe/trunk/lib/Sema/SemaInit.cpp cfe/trunk/test/CodeGen/init.c cfe/trunk/test/CodeGenCXX/cxx11-initializer-aggregate.cpp cfe/trunk/test/SemaCXX/aggregate-initialization.cpp Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=333141&r1=333140&r2=333141&view=diff == --- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original) +++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Wed May 23 16:41:38 2018 @@ -635,6 +635,60 @@ static ConstantAddress tryEmitGlobalComp return ConstantAddress(GV, Align); } +static llvm::Constant * +EmitArrayConstant(CodeGenModule &CGM, const ConstantArrayType *DestType, + llvm::Type *CommonElementType, unsigned ArrayBound, + SmallVectorImpl &Elements, + llvm::Constant *Filler) { + // Figure out how long the initial prefix of non-zero elements is. + unsigned NonzeroLength = ArrayBound; + if (Elements.size() < NonzeroLength && Filler->isNullValue()) +NonzeroLength = Elements.size(); + if (NonzeroLength == Elements.size()) { +while (NonzeroLength > 0 && Elements[NonzeroLength - 1]->isNullValue()) + --NonzeroLength; + } + + if (NonzeroLength == 0) { +return llvm::ConstantAggregateZero::get( +CGM.getTypes().ConvertType(QualType(DestType, 0))); + } + + // Add a zeroinitializer array filler if we have lots of trailing zeroes. + unsigned TrailingZeroes = ArrayBound - NonzeroLength; + if (TrailingZeroes >= 8) { +assert(Elements.size() >= NonzeroLength && + "missing initializer for non-zero element"); +Elements.resize(NonzeroLength + 1); +auto *FillerType = +CommonElementType +? CommonElementType +: CGM.getTypes().ConvertType(DestType->getElementType()); +FillerType = llvm::ArrayType::get(FillerType, TrailingZeroes); +Elements.back() = llvm::ConstantAggregateZero::get(FillerType); +CommonElementType = nullptr; + } else if (Elements.size() != ArrayBound) { +// Otherwise pad to the right size with the filler if necessary. +Elements.resize(ArrayBound, Filler); +if (Filler->getType() != CommonElementType) + CommonElementType = nullptr; + } + + // If all elements have the same type, just emit an array constant. + if (CommonElementType) +return llvm::ConstantArray::get( +llvm::ArrayType::get(CommonElementType, ArrayBound), Elements); + + // We have mixed types. Use a packed struct. + llvm::SmallVector Types; + Types.reserve(Elements.size()); + for (llvm::Constant *Elt : Elements) +Types.push_back(Elt->getType()); + llvm::StructType *SType = + llvm::StructType::get(CGM.getLLVMContext(), Types, true); + return llvm::ConstantStruct::get(SType, Elements); +} + /// This class only needs to handle two cases: /// 1) Literals (this is used by APValue emission to emit literals). /// 2) Arrays, structs and unions (outside C++11 mode, we don't currently @@ -832,68 +886,47 @@ public: } llvm::Constant *EmitArrayInitialization(InitListExpr *ILE, QualType T) { -llvm::ArrayType *AType = -cast(ConvertType(ILE->getType())); -llvm::Type *ElemTy = AType->getElementType(); +auto *CAT = CGM.getContext().getAsConstantArrayType(ILE->getType()); +assert(CAT && "can't emit array init for non-constant-bound array"); unsigned NumInitElements = ILE->getNumInits(); -unsigned NumElements = AType->getNumElements(); +unsigned NumElements = CAT->getSize().getZExtValue(); // Initialising an array requires us to automatically // initialise any elements that have not been initialised explicitly unsigned NumInitableElts = std::min(NumInitElements, NumElements); -QualType EltType = CGM.getContext().getAsArrayType(T)->getElementType(); +QualType EltType = CAT->getElementType(); // Initialize remaining array elements. -llvm::Constant *fillC; -if (Expr *filler = ILE->getArrayFiller()) +llvm::Constant *fillC = nullptr; +if (Expr *filler = ILE->getArrayFiller()) { fillC = Emitter.tryEmitAbstractForMemory(filler, EltType); -else - fillC = Emitter.emitNullForMemory(EltType); -if (!fillC) - return nullptr; - -// Try to use a ConstantAggregateZero if we can. -if (fillC->isNullValue() && !NumInitableElts) - return llvm::ConstantAggregateZero::get(AType); + if (!fillC) +return nullptr; +} // Copy initializer elements. SmallVector Elts; -Elts.reserve(std::max(NumInitableElts, NumElements)); +
r333220 - Improve diagnostics for config mismatches with -fmodule-file.
Author: rsmith Date: Thu May 24 13:03:51 2018 New Revision: 333220 URL: http://llvm.org/viewvc/llvm-project?rev=333220&view=rev Log: Improve diagnostics for config mismatches with -fmodule-file. Unless the user uses -Wno-module-file-config-mismatch (or -Wno-error=...), allow the AST reader to produce errors describing the nature of the config mismatch. Modified: cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td cfe/trunk/lib/Frontend/CompilerInstance.cpp cfe/trunk/test/Modules/check-for-sanitizer-feature.cpp cfe/trunk/test/Modules/merge-target-features.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td?rev=333220&r1=333219&r2=333220&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td Thu May 24 13:03:51 2018 @@ -38,8 +38,8 @@ def err_pch_targetopt_mismatch : Error< "PCH file was compiled for the %0 '%1' but the current translation " "unit is being compiled for target '%2'">; def err_pch_targetopt_feature_mismatch : Error< -"%select{AST file|current translation unit}0 was compiled with the target " -"feature'%1' but the %select{current translation unit is|AST file was}0 " +"%select{AST file was|current translation unit is}0 compiled with the target " +"feature '%1' but the %select{current translation unit is|AST file was}0 " "not">; def err_pch_langopt_mismatch : Error<"%0 was %select{disabled|enabled}1 in " "PCH file but is currently %select{disabled|enabled}2">; Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=333220&r1=333219&r2=333220&view=diff == --- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original) +++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Thu May 24 13:03:51 2018 @@ -1602,15 +1602,22 @@ bool CompilerInstance::loadModuleFile(St if (!ModuleManager) createModuleManager(); + // If -Wmodule-file-config-mismatch is mapped as an error or worse, allow the + // ASTReader to diagnose it, since it can produce better errors that we can. + bool ConfigMismatchIsRecoverable = + getDiagnostics().getDiagnosticLevel(diag::warn_module_config_mismatch, + SourceLocation()) +<= DiagnosticsEngine::Warning; + auto Listener = llvm::make_unique(*this); auto &ListenerRef = *Listener; ASTReader::ListenerScope ReadModuleNamesListener(*ModuleManager, std::move(Listener)); // Try to load the module file. - switch (ModuleManager->ReadAST(FileName, serialization::MK_ExplicitModule, - SourceLocation(), - ASTReader::ARR_ConfigurationMismatch)) { + switch (ModuleManager->ReadAST( + FileName, serialization::MK_ExplicitModule, SourceLocation(), + ConfigMismatchIsRecoverable ? ASTReader::ARR_ConfigurationMismatch : 0)) { case ASTReader::Success: // We successfully loaded the module file; remember the set of provided // modules so that we don't try to load implicit modules for them. Modified: cfe/trunk/test/Modules/check-for-sanitizer-feature.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/check-for-sanitizer-feature.cpp?rev=333220&r1=333219&r2=333220&view=diff == --- cfe/trunk/test/Modules/check-for-sanitizer-feature.cpp (original) +++ cfe/trunk/test/Modules/check-for-sanitizer-feature.cpp Thu May 24 13:03:51 2018 @@ -43,7 +43,7 @@ // // Import the PCH without ASan enabled (we expect an error). // RUN: not %clang_cc1 -x c -include-pch %t.asan_pch %s -verify 2>&1 | FileCheck %s --check-prefix=PCH_MISMATCH -// PCH_MISMATCH: AST file was compiled with the target feature'-fsanitize=address' but the current translation unit is not +// PCH_MISMATCH: AST file was compiled with the target feature '-fsanitize=address' but the current translation unit is not // // Emit a PCH with UBSan enabled. // RUN: %clang_cc1 -x c -fsanitize=null %S/Inputs/check-for-sanitizer-feature/check.h -emit-pch -o %t.ubsan_pch Modified: cfe/trunk/test/Modules/merge-target-features.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/merge-target-features.cpp?rev=333220&r1=333219&r2=333220&view=diff == --- cfe/trunk/test/Modules/merge-target-features.cpp (original) +++ cfe/trunk/test/Modules/merge-target-features.cpp Thu May 24 13:03:51 2018 @@ -19,10 +19,9 @@ // RUN: -triple i386-unknown-unknown \
r333233 - Switch a couple of users of LangOpts::GNUMode to the more appropriate LangOpts::GNUKeywords.
Author: rsmith Date: Thu May 24 14:51:52 2018 New Revision: 333233 URL: http://llvm.org/viewvc/llvm-project?rev=333233&view=rev Log: Switch a couple of users of LangOpts::GNUMode to the more appropriate LangOpts::GNUKeywords. Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp cfe/trunk/lib/Sema/SemaLookup.cpp Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=333233&r1=333232&r2=333233&view=diff == --- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original) +++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Thu May 24 14:51:52 2018 @@ -1371,8 +1371,8 @@ static void AddTypeSpecifierResults(cons } else Results.AddResult(Result("__auto_type", CCP_Type)); - // GNU extensions - if (LangOpts.GNUMode) { + // GNU keywords + if (LangOpts.GNUKeywords) { // FIXME: Enable when we actually support decimal floating point. //Results.AddResult(Result("_Decimal32")); //Results.AddResult(Result("_Decimal64")); Modified: cfe/trunk/lib/Sema/SemaLookup.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=333233&r1=333232&r2=333233&view=diff == --- cfe/trunk/lib/Sema/SemaLookup.cpp (original) +++ cfe/trunk/lib/Sema/SemaLookup.cpp Thu May 24 14:51:52 2018 @@ -4459,7 +4459,7 @@ static void AddKeywordsToConsumer(Sema & } } -if (SemaRef.getLangOpts().GNUMode) +if (SemaRef.getLangOpts().GNUKeywords) Consumer.addKeywordResult("typeof"); } else if (CCC.WantFunctionLikeCasts) { static const char *const CastableTypeSpecs[] = { ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r333234 - Improve diagonstic for braced-init-list as operand to ?: expression.
Author: rsmith Date: Thu May 24 15:02:52 2018 New Revision: 333234 URL: http://llvm.org/viewvc/llvm-project?rev=333234&view=rev Log: Improve diagonstic for braced-init-list as operand to ?: expression. Modified: cfe/trunk/lib/Parse/ParseExpr.cpp cfe/trunk/test/Parser/cxx11-brace-initializers.cpp Modified: cfe/trunk/lib/Parse/ParseExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=333234&r1=333233&r2=333234&view=diff == --- cfe/trunk/lib/Parse/ParseExpr.cpp (original) +++ cfe/trunk/lib/Parse/ParseExpr.cpp Thu May 24 15:02:52 2018 @@ -336,7 +336,17 @@ Parser::ParseRHSOfBinaryExpression(ExprR // Special case handling for the ternary operator. ExprResult TernaryMiddle(true); if (NextTokPrec == prec::Conditional) { - if (Tok.isNot(tok::colon)) { + if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) { +// Parse a braced-init-list here for error recovery purposes. +SourceLocation BraceLoc = Tok.getLocation(); +TernaryMiddle = ParseBraceInitializer(); +if (!TernaryMiddle.isInvalid()) { + Diag(BraceLoc, diag::err_init_list_bin_op) + << /*RHS*/ 1 << PP.getSpelling(OpToken) + << Actions.getExprRange(TernaryMiddle.get()); + TernaryMiddle = ExprError(); +} + } else if (Tok.isNot(tok::colon)) { // Don't parse FOO:BAR as if it were a typo for FOO::BAR. ColonProtectionRAIIObject X(*this); @@ -345,11 +355,6 @@ Parser::ParseRHSOfBinaryExpression(ExprR // In particular, the RHS of the '?' is 'expression', not // 'logical-OR-expression' as we might expect. TernaryMiddle = ParseExpression(); -if (TernaryMiddle.isInvalid()) { - Actions.CorrectDelayedTyposInExpr(LHS); - LHS = ExprError(); - TernaryMiddle = nullptr; -} } else { // Special case handling of "X ? Y : Z" where Y is empty: // logical-OR-expression '?' ':' conditional-expression [GNU] @@ -357,6 +362,12 @@ Parser::ParseRHSOfBinaryExpression(ExprR Diag(Tok, diag::ext_gnu_conditional_expr); } + if (TernaryMiddle.isInvalid()) { +Actions.CorrectDelayedTyposInExpr(LHS); +LHS = ExprError(); +TernaryMiddle = nullptr; + } + if (!TryConsumeToken(tok::colon, ColonLoc)) { // Otherwise, we're missing a ':'. Assume that this was a typo that // the user forgot. If we're not in a macro expansion, we can suggest @@ -469,6 +480,11 @@ Parser::ParseRHSOfBinaryExpression(ExprR if (ThisPrec == prec::Assignment) { Diag(OpToken, diag::warn_cxx98_compat_generalized_initializer_lists) << Actions.getExprRange(RHS.get()); + } else if (ColonLoc.isValid()) { +Diag(ColonLoc, diag::err_init_list_bin_op) + << /*RHS*/1 << ":" + << Actions.getExprRange(RHS.get()); +LHS = ExprError(); } else { Diag(OpToken, diag::err_init_list_bin_op) << /*RHS*/1 << PP.getSpelling(OpToken) Modified: cfe/trunk/test/Parser/cxx11-brace-initializers.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx11-brace-initializers.cpp?rev=333234&r1=333233&r2=333234&view=diff == --- cfe/trunk/test/Parser/cxx11-brace-initializers.cpp (original) +++ cfe/trunk/test/Parser/cxx11-brace-initializers.cpp Thu May 24 15:02:52 2018 @@ -1,5 +1,4 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 -// expected-no-diagnostics struct S { S(int, int) {} @@ -25,3 +24,6 @@ namespace PR14948 { template T Q::x {}; } + +int conditional1 = 1 ? {} : 0; // expected-error {{initializer list cannot be used on the right hand side of operator '?'}} +int conditional2 = 1 ? 0 : {}; // expected-error {{initializer list cannot be used on the right hand side of operator ':'}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r333333 - Test commit; please ignore.
Congratulations? On Fri, 25 May 2018, 19:33 George Burgess IV via cfe-commits, < cfe-commits@lists.llvm.org> wrote: > Author: gbiv > Date: Fri May 25 19:29:14 2018 > New Revision: 33 > > URL: http://llvm.org/viewvc/llvm-project?rev=33&view=rev > Log: > Test commit; please ignore. > > Modified: > cfe/trunk/lib/Sema/SemaAttr.cpp > > Modified: cfe/trunk/lib/Sema/SemaAttr.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaAttr.cpp?rev=33&r1=32&r2=33&view=diff > > == > --- cfe/trunk/lib/Sema/SemaAttr.cpp (original) > +++ cfe/trunk/lib/Sema/SemaAttr.cpp Fri May 25 19:29:14 2018 > @@ -330,7 +330,7 @@ void Sema::PragmaStack::Act(S > Stack.erase(std::prev(I.base()), Stack.end()); >} > } else if (!Stack.empty()) { > - // We don't have a label, just pop the last entry. > + // We do not have a label, just pop the last entry. >CurrentValue = Stack.back().Value; >CurrentPragmaLocation = Stack.back().PragmaLocation; >Stack.pop_back(); > > > ___ > cfe-commits mailing list > cfe-commits@lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits > ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r333141 - Use zeroinitializer for (trailing zero portion of) large array initializers
On 28 May 2018 at 15:34, David Blaikie via cfe-commits < cfe-commits@lists.llvm.org> wrote: > Probably nice to mention in the commit message what the fix was (& > if/where there was there a test added for it?) so readers don't have to try > to eyeball diff this commit against the otherone. > Fair point. The bug was that we would sometimes use the wrong "common" element type (when the type actually used for an array element differs from the IR type that we prefer for that array element type -- this can happen when emitting a union constant, for example). See the tests in CodeGenCXX/cxx11-initializer-aggregate.cpp in namespace PR37560 for examples. > On Wed, May 23, 2018 at 4:45 PM Richard Smith via cfe-commits < > cfe-commits@lists.llvm.org> wrote: > >> Author: rsmith >> Date: Wed May 23 16:41:38 2018 >> New Revision: 333141 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=333141&view=rev >> Log: >> Use zeroinitializer for (trailing zero portion of) large array >> initializers >> more reliably. >> >> This re-commits r333044 with a fix for PR37560. >> >> Modified: >> cfe/trunk/lib/CodeGen/CGExprConstant.cpp >> cfe/trunk/lib/Sema/SemaInit.cpp >> cfe/trunk/test/CodeGen/init.c >> cfe/trunk/test/CodeGenCXX/cxx11-initializer-aggregate.cpp >> cfe/trunk/test/SemaCXX/aggregate-initialization.cpp >> >> Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp >> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ >> CGExprConstant.cpp?rev=333141&r1=333140&r2=333141&view=diff >> >> == >> --- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original) >> +++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Wed May 23 16:41:38 2018 >> @@ -635,6 +635,60 @@ static ConstantAddress tryEmitGlobalComp >>return ConstantAddress(GV, Align); >> } >> >> +static llvm::Constant * >> +EmitArrayConstant(CodeGenModule &CGM, const ConstantArrayType *DestType, >> + llvm::Type *CommonElementType, unsigned ArrayBound, >> + SmallVectorImpl &Elements, >> + llvm::Constant *Filler) { >> + // Figure out how long the initial prefix of non-zero elements is. >> + unsigned NonzeroLength = ArrayBound; >> + if (Elements.size() < NonzeroLength && Filler->isNullValue()) >> +NonzeroLength = Elements.size(); >> + if (NonzeroLength == Elements.size()) { >> +while (NonzeroLength > 0 && Elements[NonzeroLength - >> 1]->isNullValue()) >> + --NonzeroLength; >> + } >> + >> + if (NonzeroLength == 0) { >> +return llvm::ConstantAggregateZero::get( >> +CGM.getTypes().ConvertType(QualType(DestType, 0))); >> + } >> + >> + // Add a zeroinitializer array filler if we have lots of trailing >> zeroes. >> + unsigned TrailingZeroes = ArrayBound - NonzeroLength; >> + if (TrailingZeroes >= 8) { >> +assert(Elements.size() >= NonzeroLength && >> + "missing initializer for non-zero element"); >> +Elements.resize(NonzeroLength + 1); >> +auto *FillerType = >> +CommonElementType >> +? CommonElementType >> +: CGM.getTypes().ConvertType(DestType->getElementType()); >> +FillerType = llvm::ArrayType::get(FillerType, TrailingZeroes); >> +Elements.back() = llvm::ConstantAggregateZero::get(FillerType); >> +CommonElementType = nullptr; >> + } else if (Elements.size() != ArrayBound) { >> +// Otherwise pad to the right size with the filler if necessary. >> +Elements.resize(ArrayBound, Filler); >> +if (Filler->getType() != CommonElementType) >> + CommonElementType = nullptr; >> + } >> + >> + // If all elements have the same type, just emit an array constant. >> + if (CommonElementType) >> +return llvm::ConstantArray::get( >> +llvm::ArrayType::get(CommonElementType, ArrayBound), Elements); >> + >> + // We have mixed types. Use a packed struct. >> + llvm::SmallVector Types; >> + Types.reserve(Elements.size()); >> + for (llvm::Constant *Elt : Elements) >> +Types.push_back(Elt->getType()); >> + llvm::StructType *SType = >> + llvm::StructType::get(CGM.getLLVMContext(), Types, true); >> + return llvm::ConstantStruct::get(SType, Elements); >> +} >> + >> /// This class only needs to handle two cases: >> /// 1) Literals (this is used by APValue
r333482 - Revert r332839.
Author: rsmith Date: Tue May 29 17:45:10 2018 New Revision: 333482 URL: http://llvm.org/viewvc/llvm-project?rev=333482&view=rev Log: Revert r332839. This is causing miscompiles and "definition with same mangled name as another definition" errors. Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp cfe/trunk/test/CodeGenCXX/float16-declarations.cpp Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=333482&r1=333481&r2=333482&view=diff == --- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original) +++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Tue May 29 17:45:10 2018 @@ -3627,22 +3627,12 @@ static StructorCodegen getCodegenToUse(C } llvm::GlobalValue::LinkageTypes Linkage = CGM.getFunctionLinkage(AliasDecl); - // All discardable structors can be RAUWed, but we don't want to do that in - // unoptimized code, as that makes complete structor symbol disappear - // completely, which degrades debugging experience. - // Symbols with private linkage can be safely aliased, so we special case them - // here. - if (llvm::GlobalValue::isLocalLinkage(Linkage)) -return CGM.getCodeGenOpts().OptimizationLevel > 0 ? StructorCodegen::RAUW - : StructorCodegen::Alias; + if (llvm::GlobalValue::isDiscardableIfUnused(Linkage)) +return StructorCodegen::RAUW; - // Linkonce structors cannot be aliased nor placed in a comdat, so these need - // to be emitted separately. // FIXME: Should we allow available_externally aliases? - if (llvm::GlobalValue::isDiscardableIfUnused(Linkage) || - !llvm::GlobalAlias::isValidLinkage(Linkage)) -return CGM.getCodeGenOpts().OptimizationLevel > 0 ? StructorCodegen::RAUW - : StructorCodegen::Emit; + if (!llvm::GlobalAlias::isValidLinkage(Linkage)) +return StructorCodegen::RAUW; if (llvm::GlobalValue::isWeakForLinker(Linkage)) { // Only ELF and wasm support COMDATs with arbitrary names (C5/D5). Modified: cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp?rev=333482&r1=333481&r2=333482&view=diff == --- cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp (original) +++ cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp Tue May 29 17:45:10 2018 @@ -1,7 +1,5 @@ -// RUN: %clang_cc1 %s -triple i686-linux -emit-llvm -o - -mconstructor-aliases > %t -// RUN: FileCheck --check-prefix=NOOPT1 --input-file=%t %s -// RUN: FileCheck --check-prefix=NOOPT2 --input-file=%t %s -// RUN: FileCheck --check-prefix=NOOPT3 --input-file=%t %s +// RUN: %clang_cc1 %s -triple i686-linux -emit-llvm -o - -mconstructor-aliases | FileCheck --check-prefix=NOOPT %s + // RUN: %clang_cc1 %s -triple i686-linux -emit-llvm -o - -mconstructor-aliases -O1 -disable-llvm-passes > %t // RUN: FileCheck --check-prefix=CHECK1 --input-file=%t %s // RUN: FileCheck --check-prefix=CHECK2 --input-file=%t %s @@ -23,13 +21,6 @@ namespace test1 { // CHECK1: define weak_odr void @_ZN5test16foobarIvED0Ev({{.*}} comdat($_ZN5test16foobarIvED5Ev) // CHECK1-NOT: comdat -// This should happen regardless of the opt level. -// NOOPT1: @_ZN5test16foobarIvEC1Ev = weak_odr alias void {{.*}} @_ZN5test16foobarIvEC2Ev -// NOOPT1: @_ZN5test16foobarIvED1Ev = weak_odr alias void (%"struct.test1::foobar"*), void (%"struct.test1::foobar"*)* @_ZN5test16foobarIvED2Ev -// NOOPT1: define weak_odr void @_ZN5test16foobarIvEC2Ev({{.*}} comdat($_ZN5test16foobarIvEC5Ev) -// NOOPT1: define weak_odr void @_ZN5test16foobarIvED2Ev({{.*}} comdat($_ZN5test16foobarIvED5Ev) -// NOOPT1: define weak_odr void @_ZN5test16foobarIvED0Ev({{.*}} comdat($_ZN5test16foobarIvED5Ev) - // COFF doesn't support comdats with arbitrary names (C5/D5). // COFF: define weak_odr {{.*}} void @_ZN5test16foobarIvEC2Ev({{.*}} comdat align // COFF: define weak_odr {{.*}} void @_ZN5test16foobarIvEC1Ev({{.*}} comdat align @@ -46,17 +37,12 @@ template struct foobar; } namespace test2 { -// test that when the destructor is linkonce_odr we just replace every use of +// test that when the destrucor is linkonce_odr we just replace every use of // C1 with C2. // CHECK1: define internal void @__cxx_global_var_init() // CHECK1: call void @_ZN5test26foobarIvEC2Ev // CHECK1: define linkonce_odr void @_ZN5test26foobarIvEC2Ev({{.*}} comdat align - -// At -O0, we should still emit the complete constructor. -// NOOPT1: define internal void @__cxx_global_var_init() -// NOOPT1: call void @_ZN5test26foobarIvEC1Ev -// NOOPT1: define linkonce_odr void @_ZN5test26foobarIvEC1Ev({{.*}} comdat align void g(); template struct foobar { foobar() { g(); } @@ -71,11 +57,6 @@ namespace test3 { //
Re: r332839 - [CodeGen] Disable aggressive structor optimizations at -O0, take 2
Sorry, this is still resulting in problems: we're seeing miscompiles and "definition with same mangled name as another definition" errors after this change. It seems plausible that this is a pre-existing issue that's just being exposed by this change, but either way I've temporarily reverted this in r333482. I'll get you more details, including steps to reproduce this, offline. On 21 May 2018 at 04:47, Pavel Labath via cfe-commits < cfe-commits@lists.llvm.org> wrote: > Author: labath > Date: Mon May 21 04:47:45 2018 > New Revision: 332839 > > URL: http://llvm.org/viewvc/llvm-project?rev=332839&view=rev > Log: > [CodeGen] Disable aggressive structor optimizations at -O0, take 2 > > The first version of the patch (r332228) was flawed because it was > putting structors into C5/D5 comdats very eagerly. This is correct only > if we can ensure the comdat contains all required versions of the > structor (which wasn't the case). This version uses a more nuanced > approach: > - for local structor symbols we use an alias because we don't have to > worry about comdats or other compilation units. > - linkonce symbols are emitted separately, as we cannot guarantee we > will have all symbols we need to form a comdat (they are emitted > lazily, only when referenced). > - available_externally symbols are also emitted separately, as the code > seemed to be worried about emitting an alias in this case. > - other linkage types are not affected by the optimization level. They > either get put into a comdat (weak) or get aliased (external). > > Reviewers: rjmccall, aprantl > > Subscribers: cfe-commits > > Differential Revision: https://reviews.llvm.org/D46685 > > Modified: > cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp > cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp > cfe/trunk/test/CodeGenCXX/float16-declarations.cpp > > Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ > ItaniumCXXABI.cpp?rev=332839&r1=332838&r2=332839&view=diff > > == > --- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original) > +++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Mon May 21 04:47:45 2018 > @@ -3628,12 +3628,22 @@ static StructorCodegen getCodegenToUse(C >} >llvm::GlobalValue::LinkageTypes Linkage = CGM.getFunctionLinkage( > AliasDecl); > > - if (llvm::GlobalValue::isDiscardableIfUnused(Linkage)) > -return StructorCodegen::RAUW; > + // All discardable structors can be RAUWed, but we don't want to do > that in > + // unoptimized code, as that makes complete structor symbol disappear > + // completely, which degrades debugging experience. > + // Symbols with private linkage can be safely aliased, so we special > case them > + // here. > + if (llvm::GlobalValue::isLocalLinkage(Linkage)) > +return CGM.getCodeGenOpts().OptimizationLevel > 0 ? > StructorCodegen::RAUW > + : > StructorCodegen::Alias; > > + // Linkonce structors cannot be aliased nor placed in a comdat, so > these need > + // to be emitted separately. >// FIXME: Should we allow available_externally aliases? > - if (!llvm::GlobalAlias::isValidLinkage(Linkage)) > -return StructorCodegen::RAUW; > + if (llvm::GlobalValue::isDiscardableIfUnused(Linkage) || > + !llvm::GlobalAlias::isValidLinkage(Linkage)) > +return CGM.getCodeGenOpts().OptimizationLevel > 0 ? > StructorCodegen::RAUW > + : > StructorCodegen::Emit; > >if (llvm::GlobalValue::isWeakForLinker(Linkage)) { > // Only ELF and wasm support COMDATs with arbitrary names (C5/D5). > > Modified: cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ > CodeGenCXX/ctor-dtor-alias.cpp?rev=332839&r1=332838&r2=332839&view=diff > > == > --- cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp (original) > +++ cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp Mon May 21 04:47:45 2018 > @@ -1,5 +1,7 @@ > -// RUN: %clang_cc1 %s -triple i686-linux -emit-llvm -o - > -mconstructor-aliases | FileCheck --check-prefix=NOOPT %s > - > +// RUN: %clang_cc1 %s -triple i686-linux -emit-llvm -o - > -mconstructor-aliases > %t > +// RUN: FileCheck --check-prefix=NOOPT1 --input-file=%t %s > +// RUN: FileCheck --check-prefix=NOOPT2 --input-file=%t %s > +// RUN: FileCheck --check-prefix=NOOPT3 --input-file=%t %s > // RUN: %clang_cc1 %s -triple i686-linux -emit-llvm -o - > -mconstructor-aliases -O1 -disable-llvm-passes > %t > // RUN: FileCheck --check-prefix=CHECK1 --input-file=%t %s > // RUN: FileCheck --check-prefix=CHECK2 --input-file=%t %s > @@ -21,6 +23,13 @@ namespace test1 { > // CHECK1: define weak_odr void @_ZN5test16foobarIvED0Ev({{.*}} comdat($_ > ZN5test16foobarIvED5Ev) > // CHECK1-NOT: comdat > > +// This should happen regardless
r333489 - Make the mangled name collision diagnostic a bit more useful by listing the mangling.
Author: rsmith Date: Tue May 29 18:52:16 2018 New Revision: 333489 URL: http://llvm.org/viewvc/llvm-project?rev=333489&view=rev Log: Make the mangled name collision diagnostic a bit more useful by listing the mangling. This helps especially when the collision is for a template specialization, where the template arguments are not available from anywhere else in the diagnostic, and are likely relevant to the problem. Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/CodeGen/CodeGenModule.cpp cfe/trunk/test/CodeGenCXX/duplicate-mangled-name.cpp cfe/trunk/test/Sema/attr-ifunc.c Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=333489&r1=333488&r2=333489&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue May 29 18:52:16 2018 @@ -2820,7 +2820,7 @@ def warn_alias_with_section : Warning< "%select{alias|ifunc}1 will not be in section '%0' but in the same section as the %select{aliasee|resolver}2">, InGroup; def err_duplicate_mangled_name : Error< - "definition with same mangled name as another definition">; + "definition with same mangled name '%0' as another definition">; def err_cyclic_alias : Error< "%select{alias|ifunc}0 definition is part of a cycle">; def err_ifunc_resolver_return : Error< Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=333489&r1=333488&r2=333489&view=diff == --- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original) +++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue May 29 18:52:16 2018 @@ -2445,8 +2445,8 @@ llvm::Constant *CodeGenModule::GetOrCrea (GD.getCanonicalDecl().getDecl() != OtherGD.getCanonicalDecl().getDecl()) && DiagnosedConflictingDefinitions.insert(GD).second) { -getDiags().Report(D->getLocation(), - diag::err_duplicate_mangled_name); +getDiags().Report(D->getLocation(), diag::err_duplicate_mangled_name) +<< MangledName; getDiags().Report(OtherGD.getDecl()->getLocation(), diag::note_previous_definition); } @@ -2744,8 +2744,8 @@ CodeGenModule::GetOrCreateLLVMGlobal(Str (OtherD = dyn_cast(OtherGD.getDecl())) && OtherD->hasInit() && DiagnosedConflictingDefinitions.insert(D).second) { -getDiags().Report(D->getLocation(), - diag::err_duplicate_mangled_name); +getDiags().Report(D->getLocation(), diag::err_duplicate_mangled_name) +<< MangledName; getDiags().Report(OtherGD.getDecl()->getLocation(), diag::note_previous_definition); } @@ -3783,7 +3783,8 @@ void CodeGenModule::emitIFuncDefinition( GlobalDecl OtherGD; if (lookupRepresentativeDecl(MangledName, OtherGD) && DiagnosedConflictingDefinitions.insert(GD).second) { - Diags.Report(D->getLocation(), diag::err_duplicate_mangled_name); + Diags.Report(D->getLocation(), diag::err_duplicate_mangled_name) + << MangledName; Diags.Report(OtherGD.getDecl()->getLocation(), diag::note_previous_definition); } Modified: cfe/trunk/test/CodeGenCXX/duplicate-mangled-name.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/duplicate-mangled-name.cpp?rev=333489&r1=333488&r2=333489&view=diff == --- cfe/trunk/test/CodeGenCXX/duplicate-mangled-name.cpp (original) +++ cfe/trunk/test/CodeGenCXX/duplicate-mangled-name.cpp Tue May 29 18:52:16 2018 @@ -11,7 +11,7 @@ class MyClass { }; void MyClass::meth() { } // expected-note {{previous}} extern "C" { - void _ZN7MyClass4methEv() { } // expected-error {{definition with same mangled name as another definition}} + void _ZN7MyClass4methEv() { } // expected-error {{definition with same mangled name '_ZN7MyClass4methEv' as another definition}} } #elif TEST2 @@ -49,7 +49,7 @@ float foo() { extern "C" void _ZN2T2D2Ev() {}; // expected-note {{previous definition is here}} struct T2 { - ~T2() {} // expected-error {{definition with same mangled name as another definition}} + ~T2() {} // expected-error {{definition with same mangled name '_ZN2T2D2Ev' as another definition}} }; void foo() { @@ -64,7 +64,7 @@ extern "C" { } namespace nm { - float abc = 2; // expected-error {{definition with same mangled name as another definition}} + float abc = 2; // expected-error {{definition with same mangled name '_ZN2nm3abcE' as another definition}} } float foo() { Modified: cfe/trunk/te
r314231 - Resolve a defect in C++17 copy omission.
Author: rsmith Date: Tue Sep 26 11:37:55 2017 New Revision: 314231 URL: http://llvm.org/viewvc/llvm-project?rev=314231&view=rev Log: Resolve a defect in C++17 copy omission. When selecting constructors for initializing an object of type T from a single expression of class type U, also consider conversion functions of U that convert to T (rather than modeling such conversions as calling a conversion function and then calling a constructor). This approach is proposed as the resolution for the defect, and is also already implemented by GCC. Modified: cfe/trunk/include/clang/Sema/Overload.h cfe/trunk/include/clang/Sema/Sema.h cfe/trunk/lib/Sema/SemaCodeComplete.cpp cfe/trunk/lib/Sema/SemaInit.cpp cfe/trunk/lib/Sema/SemaOverload.cpp cfe/trunk/test/SemaCXX/cxx1z-copy-omission.cpp Modified: cfe/trunk/include/clang/Sema/Overload.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Overload.h?rev=314231&r1=314230&r2=314231&view=diff == --- cfe/trunk/include/clang/Sema/Overload.h (original) +++ cfe/trunk/include/clang/Sema/Overload.h Tue Sep 26 11:37:55 2017 @@ -726,11 +726,20 @@ namespace clang { enum CandidateSetKind { /// Normal lookup. CSK_Normal, - /// Lookup for candidates for a call using operator syntax. Candidates - /// that have no parameters of class type will be skipped unless there - /// is a parameter of (reference to) enum type and the corresponding - /// argument is of the same enum type. - CSK_Operator + /// C++ [over.match.oper]: + /// Lookup of operator function candidates in a call using operator + /// syntax. Candidates that have no parameters of class type will be + /// skipped unless there is a parameter of (reference to) enum type and + /// the corresponding argument is of the same enum type. + CSK_Operator, + /// C++ [over.match.copy]: + /// Copy-initialization of an object of class type by user-defined + /// conversion. + CSK_InitByUserDefinedConversion, + /// C++ [over.match.ctor], [over.match.list] + /// Initialization of an object of class type by constructor, + /// using either a parenthesized or braced list of arguments. + CSK_InitByConstructor, }; private: @@ -795,7 +804,7 @@ namespace clang { } /// \brief Clear out all of the candidates. -void clear(); +void clear(CandidateSetKind CSK); typedef SmallVectorImpl::iterator iterator; iterator begin() { return Candidates.begin(); } @@ -835,8 +844,7 @@ namespace clang { /// Find the best viable function on this overload set, if it exists. OverloadingResult BestViableFunction(Sema &S, SourceLocation Loc, - OverloadCandidateSet::iterator& Best, - bool UserDefinedConversion = false); + OverloadCandidateSet::iterator& Best); void NoteCandidates(Sema &S, OverloadCandidateDisplayKind OCD, @@ -848,10 +856,10 @@ namespace clang { }; bool isBetterOverloadCandidate(Sema &S, - const OverloadCandidate& Cand1, - const OverloadCandidate& Cand2, + const OverloadCandidate &Cand1, + const OverloadCandidate &Cand2, SourceLocation Loc, - bool UserDefinedConversion = false); + OverloadCandidateSet::CandidateSetKind Kind); struct ConstructorInfo { DeclAccessPair FoundDecl; Modified: cfe/trunk/include/clang/Sema/Sema.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=314231&r1=314230&r2=314231&view=diff == --- cfe/trunk/include/clang/Sema/Sema.h (original) +++ cfe/trunk/include/clang/Sema/Sema.h Tue Sep 26 11:37:55 2017 @@ -2742,13 +2742,15 @@ public: CXXRecordDecl *ActingContext, Expr *From, QualType ToType, OverloadCandidateSet& CandidateSet, - bool AllowObjCConversionOnExplicit); + bool AllowObjCConversionOnExplicit, + bool AllowResultConversion = true); void AddTemplateConversionCandidate(FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl, CXXRecordDecl *ActingContext, Expr *From, QualType ToType, OverloadCandidateSet &CandidateSet, - bool AllowObjCConversionOnExplicit); +
r314246 - Fix uninitialized member found by msan build bot.
Author: rsmith Date: Tue Sep 26 14:33:43 2017 New Revision: 314246 URL: http://llvm.org/viewvc/llvm-project?rev=314246&view=rev Log: Fix uninitialized member found by msan build bot. Modified: cfe/trunk/lib/Sema/SemaOverload.cpp Modified: cfe/trunk/lib/Sema/SemaOverload.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=314246&r1=314245&r2=314246&view=diff == --- cfe/trunk/lib/Sema/SemaOverload.cpp (original) +++ cfe/trunk/lib/Sema/SemaOverload.cpp Tue Sep 26 14:33:43 2017 @@ -10271,7 +10271,7 @@ struct CompareOverloadCandidatesForDispl CompareOverloadCandidatesForDisplay( Sema &S, SourceLocation Loc, size_t NArgs, OverloadCandidateSet::CandidateSetKind CSK) - : S(S), NumArgs(NArgs) {} + : S(S), NumArgs(NArgs), CSK(CSK) {} bool operator()(const OverloadCandidate *L, const OverloadCandidate *R) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r314570 - Add a "vexing parse" warning for ambiguity between a variable declaration and a
Author: rsmith Date: Fri Sep 29 16:57:25 2017 New Revision: 314570 URL: http://llvm.org/viewvc/llvm-project?rev=314570&view=rev Log: Add a "vexing parse" warning for ambiguity between a variable declaration and a function-style cast. This fires for cases such as T(x); ... where 'x' was previously declared and T is a type. This construct declares a variable named 'x' rather than the (probably expected) interpretation of a function-style cast of 'x' to T. Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/include/clang/Sema/DeclSpec.h cfe/trunk/lib/Sema/SemaType.cpp cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.qual/class.qual/p2.cpp cfe/trunk/test/FixIt/fixit-vexing-parse.cpp cfe/trunk/test/Parser/cxx0x-condition.cpp cfe/trunk/test/Parser/cxx1z-class-template-argument-deduction.cpp cfe/trunk/test/SemaCXX/decl-expr-ambiguity.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=314570&r1=314569&r2=314570&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Sep 29 16:57:25 2017 @@ -295,8 +295,20 @@ def warn_empty_parens_are_function_decl def warn_parens_disambiguated_as_function_declaration : Warning< "parentheses were disambiguated as a function declaration">, InGroup; +def warn_parens_disambiguated_as_variable_declaration : Warning< + "parentheses were disambiguated as redundant parentheses around declaration " + "of variable named %0">, InGroup; +def warn_redundant_parens_around_declarator : Warning< + "redundant parentheses surrounding declarator">, + InGroup>, DefaultIgnore; def note_additional_parens_for_variable_declaration : Note< "add a pair of parentheses to declare a variable">; +def note_raii_guard_add_name : Note< + "add a variable name to declare a %0 initialized with %1">; +def note_function_style_cast_add_parentheses : Note< + "add enclosing parentheses to perform a function-style cast">; +def note_remove_parens_for_variable_declaration : Note< + "remove parentheses to silence this warning">; def note_empty_parens_function_call : Note< "change this ',' to a ';' to call %0">; def note_empty_parens_default_ctor : Note< Modified: cfe/trunk/include/clang/Sema/DeclSpec.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/DeclSpec.h?rev=314570&r1=314569&r2=314570&view=diff == --- cfe/trunk/include/clang/Sema/DeclSpec.h (original) +++ cfe/trunk/include/clang/Sema/DeclSpec.h Fri Sep 29 16:57:25 2017 @@ -2301,6 +2301,42 @@ public: } llvm_unreachable("unknown context kind!"); } + + /// Determine whether this declaration appears in a context where an + /// expression could appear. + bool isExpressionContext() const { +switch (Context) { +case FileContext: +case KNRTypeListContext: +case MemberContext: +case TypeNameContext: // FIXME: sizeof(...) permits an expression. +case FunctionalCastContext: +case AliasDeclContext: +case AliasTemplateContext: +case PrototypeContext: +case LambdaExprParameterContext: +case ObjCParameterContext: +case ObjCResultContext: +case TemplateParamContext: +case CXXNewContext: +case CXXCatchContext: +case ObjCCatchContext: +case BlockLiteralContext: +case LambdaExprContext: +case ConversionIdContext: +case TrailingReturnContext: + return false; + +case BlockContext: +case ForContext: +case InitStmtContext: +case ConditionContext: +case TemplateTypeArgContext: + return true; +} + +llvm_unreachable("unknown context kind!"); + } /// \brief Return true if a function declarator at this position would be a /// function declaration. Modified: cfe/trunk/lib/Sema/SemaType.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=314570&r1=314569&r2=314570&view=diff == --- cfe/trunk/lib/Sema/SemaType.cpp (original) +++ cfe/trunk/lib/Sema/SemaType.cpp Fri Sep 29 16:57:25 2017 @@ -3065,6 +3065,7 @@ static void warnAboutAmbiguousFunction(S S.Diag(D.getCommaLoc(), diag::note_empty_parens_function_call) << FixItHint::CreateReplacement(D.getCommaLoc(), ";") << D.getIdentifier(); + Result.suppressDiagnostics(); } } @@ -3106,6 +3107,99 @@ static void warnAboutAmbiguousFunction(S } } +/// Produce an appropriate diagnostic for a declarator with top-level +/// parentheses. +static void warnAboutRedundantParens(Sema &S, Declarator &D, QualType T) { + DeclaratorChunk &Paren = D.getTypeObject(D.getNumTypeObjects() - 1); + assert(Paren.Kind == Declara
r314733 - PR33839: Fix -Wunused handling for structured binding declarations.
Author: rsmith Date: Mon Oct 2 15:43:36 2017 New Revision: 314733 URL: http://llvm.org/viewvc/llvm-project?rev=314733&view=rev Log: PR33839: Fix -Wunused handling for structured binding declarations. We warn about a structured binding declaration being unused only if none of its bindings are used. Modified: cfe/trunk/lib/Sema/SemaDecl.cpp cfe/trunk/lib/Sema/SemaDeclCXX.cpp cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp cfe/trunk/test/SemaCXX/unused.cpp Modified: cfe/trunk/lib/Sema/SemaDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=314733&r1=314732&r2=314733&view=diff == --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Oct 2 15:43:36 2017 @@ -1604,7 +1604,24 @@ static bool ShouldDiagnoseUnusedDecl(con if (D->isInvalidDecl()) return false; - if (D->isReferenced() || D->isUsed() || D->hasAttr() || + bool Referenced = false; + if (auto *DD = dyn_cast(D)) { +// For a decomposition declaration, warn if none of the bindings are +// referenced, instead of if the variable itself is referenced (which +// it is, by the bindings' expressions). +for (auto *BD : DD->bindings()) { + if (BD->isReferenced()) { +Referenced = true; +break; + } +} + } else if (!D->getDeclName()) { +return false; + } else if (D->isReferenced() || D->isUsed()) { +Referenced = true; + } + + if (Referenced || D->hasAttr() || D->hasAttr()) return false; @@ -1727,7 +1744,7 @@ void Sema::DiagnoseUnusedDecl(const Name else DiagID = diag::warn_unused_variable; - Diag(D->getLocation(), DiagID) << D->getDeclName() << Hint; + Diag(D->getLocation(), DiagID) << D << Hint; } static void CheckPoppedLabel(LabelDecl *L, Sema &S) { @@ -1757,8 +1774,6 @@ void Sema::ActOnPopScope(SourceLocation assert(isa(TmpD) && "Decl isn't NamedDecl?"); NamedDecl *D = cast(TmpD); -if (!D->getDeclName()) continue; - // Diagnose unused variables in this scope. if (!S->hasUnrecoverableErrorOccurred()) { DiagnoseUnusedDecl(D); @@ -1766,6 +1781,8 @@ void Sema::ActOnPopScope(SourceLocation DiagnoseUnusedNestedTypedefs(RD); } +if (!D->getDeclName()) continue; + // If this was a forward reference to a label, verify it was defined. if (LabelDecl *LD = dyn_cast(D)) CheckPoppedLabel(LD, *this); @@ -6164,7 +6181,6 @@ NamedDecl *Sema::ActOnVariableDeclarator IdentifierInfo *II = Name.getAsIdentifierInfo(); if (D.isDecompositionDeclarator()) { -AddToScope = false; // Take the name of the first declarator as our name for diagnostic // purposes. auto &Decomp = D.getDecompositionDeclarator(); Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=314733&r1=314732&r2=314733&view=diff == --- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original) +++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Mon Oct 2 15:43:36 2017 @@ -829,7 +829,10 @@ Sema::ActOnDecompositionDeclarator(Scope NamedDecl *New = ActOnVariableDeclarator(S, D, DC, TInfo, Previous, MultiTemplateParamsArg(), AddToScope, Bindings); - CurContext->addHiddenDecl(New); + if (AddToScope) { +S->AddDecl(New); +CurContext->addHiddenDecl(New); + } if (isInOpenMPDeclareTargetContext()) checkDeclIsAllowedInOpenMPTarget(nullptr, New); Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=314733&r1=314732&r2=314733&view=diff == --- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Mon Oct 2 15:43:36 2017 @@ -677,6 +677,7 @@ TemplateDeclInstantiator::VisitTypeAlias Decl *TemplateDeclInstantiator::VisitBindingDecl(BindingDecl *D) { auto *NewBD = BindingDecl::Create(SemaRef.Context, Owner, D->getLocation(), D->getIdentifier()); + NewBD->setReferenced(D->isReferenced()); SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, NewBD); return NewBD; } Modified: cfe/trunk/test/SemaCXX/unused.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/unused.cpp?rev=314733&r1=314732&r2=314733&view=diff == --- cfe/trunk/test/SemaCXX/unused.cpp (original) +++ cfe/trunk/test/SemaCXX/unused.cpp Mon Oct 2 15:43:36 2017 @@ -1,6 +1,7 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s -// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s -// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s +// RUN: %clang_cc1 -fsyntax-only -
r314754 - R34811: Allow visibilities other than 'default' for VisibleNoLinkage entities.
Author: rsmith Date: Mon Oct 2 18:58:15 2017 New Revision: 314754 URL: http://llvm.org/viewvc/llvm-project?rev=314754&view=rev Log: R34811: Allow visibilities other than 'default' for VisibleNoLinkage entities. Modified: cfe/trunk/lib/AST/Decl.cpp cfe/trunk/test/CodeGenCXX/visibility-inlines-hidden.cpp Modified: cfe/trunk/lib/AST/Decl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=314754&r1=314753&r2=314754&view=diff == --- cfe/trunk/lib/AST/Decl.cpp (original) +++ cfe/trunk/lib/AST/Decl.cpp Mon Oct 2 18:58:15 2017 @@ -817,9 +817,9 @@ LinkageComputer::getLVForNamespaceScopeD return LinkageInfo::none(); } - // If we ended up with non-external linkage, visibility should + // If we ended up with non-externally-visible linkage, visibility should // always be default. - if (LV.getLinkage() != ExternalLinkage) + if (!isExternallyVisible(LV.getLinkage())) return LinkageInfo(LV.getLinkage(), DefaultVisibility, false); return LV; Modified: cfe/trunk/test/CodeGenCXX/visibility-inlines-hidden.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/visibility-inlines-hidden.cpp?rev=314754&r1=314753&r2=314754&view=diff == --- cfe/trunk/test/CodeGenCXX/visibility-inlines-hidden.cpp (original) +++ cfe/trunk/test/CodeGenCXX/visibility-inlines-hidden.cpp Mon Oct 2 18:58:15 2017 @@ -162,3 +162,16 @@ namespace test6 { C::g(); } } + +namespace PR34811 { + template void tf() {} + + // CHECK-LABEL: define linkonce_odr hidden i8* @_ZN7PR348111fEv( + inline void *f() { +auto l = []() {}; +// CHECK-LABEL: define linkonce_odr hidden void @_ZN7PR348112tfIZNS_1fEvEUlvE_EEvv( +return (void *)&tf; + } + + void *p = (void *)f; +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r313957 - Closure types have no name (and can't have a typedef name for linkage
On 2 October 2017 at 17:10, Peter Collingbourne via cfe-commits < cfe-commits@lists.llvm.org> wrote: > Looks like this caused PR34811, which caused a link error on a Chromium > bot: > https://build.chromium.org/p/chromium.fyi/builders/CFI% > 20Linux%20ToT/builds/7081 > > The link error might be caused by an unrelated LTO bug, but this bug does > seem real. > Agreed. This turned out to be a pre-existing bug that we hit a lot more often after this change. Fixed in r314754. That said, this bug would only cause declarations to have default visibility when they should have some other visibility (it should only cause too much visibility, not too little), and it's not obvious to me how that could result in the link error on the Chromium bot. > Peter > > On Thu, Sep 21, 2017 at 9:33 PM, Richard Smith via cfe-commits < > cfe-commits@lists.llvm.org> wrote: > >> Author: rsmith >> Date: Thu Sep 21 21:33:20 2017 >> New Revision: 313957 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=313957&view=rev >> Log: >> Closure types have no name (and can't have a typedef name for linkage >> purposes), so they never formally have linkage. >> >> Modified: >> cfe/trunk/lib/AST/Decl.cpp >> cfe/trunk/test/CXX/basic/basic.link/p8.cpp >> >> Modified: cfe/trunk/lib/AST/Decl.cpp >> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl. >> cpp?rev=313957&r1=313956&r2=313957&view=diff >> >> == >> --- cfe/trunk/lib/AST/Decl.cpp (original) >> +++ cfe/trunk/lib/AST/Decl.cpp Thu Sep 21 21:33:20 2017 >> @@ -1104,24 +1104,25 @@ LinkageInfo LinkageComputer::getLVForClo >>else >> Owner = cast(ContextDecl); >> >> - // FIXME: If there is no owner, the closure should have no linkage. >>if (!Owner) >> -return LinkageInfo::external(); >> +return LinkageInfo::none(); >> >>// If the owner has a deduced type, we need to skip querying the >> linkage and >>// visibility of that type, because it might involve this closure >> type. The >>// only effect of this is that we might give a lambda VisibleNoLinkage >> rather >>// than NoLinkage when we don't strictly need to, which is benign. >>auto *VD = dyn_cast(Owner); >> - LinkageInfo OwnerLinkage = >> + LinkageInfo OwnerLV = >>VD && VD->getType()->getContainedDeducedType() >>? computeLVForDecl(Owner, computation, >> /*IgnoreVarTypeLinkage*/true) >>: getLVForDecl(Owner, computation); >> >> - // FIXME: This is wrong. A lambda never formally has linkage; if this >> - // calculation determines a lambda has external linkage, it should be >> - // downgraded to VisibleNoLinkage. >> - return OwnerLinkage; >> + // A lambda never formally has linkage. But if the owner is externally >> + // visible, then the lambda is too. We apply the same rules to blocks. >> + if (!isExternallyVisible(OwnerLV.getLinkage())) >> +return LinkageInfo::none(); >> + return LinkageInfo(VisibleNoLinkage, OwnerLV.getVisibility(), >> + OwnerLV.isVisibilityExplicit()); >> } >> >> LinkageInfo LinkageComputer::getLVForLocalDecl(const NamedDecl *D, >> >> Modified: cfe/trunk/test/CXX/basic/basic.link/p8.cpp >> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/basic >> /basic.link/p8.cpp?rev=313957&r1=313956&r2=313957&view=diff >> >> == >> --- cfe/trunk/test/CXX/basic/basic.link/p8.cpp (original) >> +++ cfe/trunk/test/CXX/basic/basic.link/p8.cpp Thu Sep 21 21:33:20 2017 >> @@ -14,7 +14,7 @@ typedef decltype(f()) NoLinkage3; >> inline auto g() { return [] {}; } >> typedef decltype(g()) VisibleNoLinkage1; >> inline auto y = [] {}; >> -typedef decltype(x) VisibleNoLinkage2; >> +typedef decltype(y) VisibleNoLinkage2; >> inline auto h() { struct {} x; return x; } >> typedef decltype(h()) VisibleNoLinkage3; >> >> @@ -42,19 +42,12 @@ void use_no_linkage() { >>no_linkage3(); // expected-note {{used here}} >> } >> >> -// FIXME: This should emit an extension warning. It does not because we >> -// incorrectly give the lambda external linkage. >> -extern VisibleNoLinkage1 visible_no_linkage1(); >> - >> -// FIXME: We should accept this as an extension. We don't because we >> -// incorrectly give the lambda no linkage instead of "VisibleN
r314838 - Suppress -Wmissing-braces warning when aggregate-initializing a struct with a single field that is itself an aggregate.
Author: rsmith Date: Tue Oct 3 13:36:00 2017 New Revision: 314838 URL: http://llvm.org/viewvc/llvm-project?rev=314838&view=rev Log: Suppress -Wmissing-braces warning when aggregate-initializing a struct with a single field that is itself an aggregate. In C++, such initialization of std::array types is guaranteed to work by the standard, is completely idiomatic, and the "suggested" alternative from Clang was technically invalid. Modified: cfe/trunk/lib/Sema/SemaInit.cpp cfe/trunk/test/Sema/zero-initializer.c cfe/trunk/test/SemaCXX/aggregate-initialization.cpp Modified: cfe/trunk/lib/Sema/SemaInit.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=314838&r1=314837&r2=314838&view=diff == --- cfe/trunk/lib/Sema/SemaInit.cpp (original) +++ cfe/trunk/lib/Sema/SemaInit.cpp Tue Oct 3 13:36:00 2017 @@ -826,6 +826,34 @@ int InitListChecker::numStructUnionEleme return InitializableMembers - structDecl->hasFlexibleArrayMember(); } +/// Determine whether Entity is an entity for which it is idiomatic to elide +/// the braces in aggregate initialization. +static bool isIdiomaticBraceElisionEntity(const InitializedEntity &Entity) { + // Recursive initialization of the one and only field within an aggregate + // class is considered idiomatic. This case arises in particular for + // initialization of std::array, where the C++ standard suggests the idiom of + // + // std::array arr = {1, 2, 3}; + // + // (where std::array is an aggregate struct containing a single array field. + + // FIXME: Should aggregate initialization of a struct with a single + // base class and no members also suppress the warning? + if (Entity.getKind() != InitializedEntity::EK_Member || !Entity.getParent()) +return false; + + auto *ParentRD = + Entity.getParent()->getType()->castAs()->getDecl(); + if (CXXRecordDecl *CXXRD = dyn_cast(ParentRD)) +if (CXXRD->getNumBases()) + return false; + + auto FieldIt = ParentRD->field_begin(); + assert(FieldIt != ParentRD->field_end() && + "no fields but have initializer for member?"); + return ++FieldIt == ParentRD->field_end(); +} + /// Check whether the range of the initializer \p ParentIList from element /// \p Index onwards can be used to initialize an object of type \p T. Update /// \p Index to indicate how many elements of the list were consumed. @@ -887,7 +915,8 @@ void InitListChecker::CheckImplicitInitL // Complain about missing braces. if ((T->isArrayType() || T->isRecordType()) && -!ParentIList->isIdiomaticZeroInitializer(SemaRef.getLangOpts())) { +!ParentIList->isIdiomaticZeroInitializer(SemaRef.getLangOpts()) && +!isIdiomaticBraceElisionEntity(Entity)) { SemaRef.Diag(StructuredSubobjectInitList->getLocStart(), diag::warn_missing_braces) << StructuredSubobjectInitList->getSourceRange() Modified: cfe/trunk/test/Sema/zero-initializer.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/zero-initializer.c?rev=314838&r1=314837&r2=314838&view=diff == --- cfe/trunk/test/Sema/zero-initializer.c (original) +++ cfe/trunk/test/Sema/zero-initializer.c Tue Oct 3 13:36:00 2017 @@ -6,6 +6,7 @@ struct bar { struct foo a; struct foo b; struct A { int a; }; struct B { struct A a; }; struct C { struct B b; }; +struct D { struct C c; int n; }; int main(void) { @@ -20,7 +21,8 @@ int main(void) struct bar n = { { 0 }, { 9, 9 } }; // no-warning struct bar o = { { 9 }, { 9, 9 } }; // expected-warning {{missing field 'y' initializer}} struct C p = { 0 }; // no-warning - struct C q = { 9 }; // expected-warning {{suggest braces around initialization of subobject}} expected-warning {{suggest braces around initialization of subobject}} + struct C q = { 9 }; // warning suppressed for struct with single element + struct D r = { 9 }; // expected-warning {{suggest braces around initialization of subobject}} expected-warning {{missing field 'n' initializer}} f = (struct foo ) { 0 }; // no-warning g = (struct foo ) { 9 }; // expected-warning {{missing field 'y' initializer}} h = (struct foo ) { 9, 9 }; // no-warning @@ -32,7 +34,8 @@ int main(void) n = (struct bar) { { 0 }, { 9, 9 } }; // no-warning o = (struct bar) { { 9 }, { 9, 9 } }; // expected-warning {{missing field 'y' initializer}} p = (struct C) { 0 }; // no-warning - q = (struct C) { 9 }; // expected-warning {{suggest braces around initialization of subobject}} expected-warning {{suggest braces around initialization of subobject}} + q = (struct C) { 9 }; // warning suppressed for struct with single element + r = (struct D) { 9 }; // expected-warning {{suggest braces around initialization of subobject}} expected-warning {{missing field 'n' initializer}} return 0; } Modified: cfe/trunk/te
r314871 - PR34822: Fix a collection of related bugs with our handling of C89 implicit function declarations.
Author: rsmith Date: Tue Oct 3 18:49:22 2017 New Revision: 314871 URL: http://llvm.org/viewvc/llvm-project?rev=314871&view=rev Log: PR34822: Fix a collection of related bugs with our handling of C89 implicit function declarations. We were injecting the function into the wrong semantic context, resulting in it failing to be registered as a global for redeclaration lookup. As a consequence, we accepted invalid code since r310616. Fixing that resulted in the "out-of-scope declaration" diagnostic firing a lot more often. It turned out that warning codepath was non-conforming, because it did not cause us to inject the implicitly-declared function into the enclosing block scope. We now only warn if the type of the out-of-scope declaration doesn't match the type of an implicitly-declared function; in all other cases, we produce the normal warning for an implicitly-declared function. Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaDecl.cpp cfe/trunk/test/Misc/warning-flags.c cfe/trunk/test/Sema/implicit-decl-c90.c cfe/trunk/test/Sema/implicit-decl.c Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=314871&r1=314870&r2=314871&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Oct 3 18:49:22 2017 @@ -366,8 +366,10 @@ def err_language_linkage_spec_unknown : def err_language_linkage_spec_not_ascii : Error< "string literal in language linkage specifier cannot have an " "encoding-prefix">; -def warn_use_out_of_scope_declaration : Warning< - "use of out-of-scope declaration of %0">; +def ext_use_out_of_scope_declaration : ExtWarn< + "use of out-of-scope declaration of %0%select{| whose type is not " + "compatible with that of an implicit declaration}1">, + InGroup>; def err_inline_non_function : Error< "'inline' can only appear on functions%select{| and non-local variables}0">; def err_noreturn_non_function : Error< Modified: cfe/trunk/lib/Sema/SemaDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=314871&r1=314870&r2=314871&view=diff == --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Oct 3 18:49:22 2017 @@ -12613,14 +12613,32 @@ void Sema::ActOnFinishDelayedAttribute(S /// call, forming a call to an implicitly defined function (per C99 6.5.1p2). NamedDecl *Sema::ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II, Scope *S) { + Scope *BlockScope = S; + while (!BlockScope->isCompoundStmtScope() && BlockScope->getParent()) +BlockScope = BlockScope->getParent(); + // Before we produce a declaration for an implicitly defined // function, see whether there was a locally-scoped declaration of // this name as a function or variable. If so, use that // (non-visible) declaration, and complain about it. - if (NamedDecl *ExternCPrev = findLocallyScopedExternCDecl(&II)) { -Diag(Loc, diag::warn_use_out_of_scope_declaration) << ExternCPrev; -Diag(ExternCPrev->getLocation(), diag::note_previous_declaration); -return ExternCPrev; + NamedDecl *ExternCPrev = findLocallyScopedExternCDecl(&II); + if (ExternCPrev) { +// We still need to inject the function into the enclosing block scope so +// that later (non-call) uses can see it. +PushOnScopeChains(ExternCPrev, BlockScope, /*AddToContext*/false); + +// C89 footnote 38: +// If in fact it is not defined as having type "function returning int", +// the behavior is undefined. +if (!isa(ExternCPrev) || +!Context.typesAreCompatible( +cast(ExternCPrev)->getType(), +Context.getFunctionNoProtoType(Context.IntTy))) { + Diag(Loc, diag::ext_use_out_of_scope_declaration) + << ExternCPrev << !getLangOpts().C99; + Diag(ExternCPrev->getLocation(), diag::note_previous_declaration); + return ExternCPrev; +} } // Extension in C99. Legal in C90, but warn about it. @@ -12636,6 +12654,12 @@ NamedDecl *Sema::ImplicitlyDefineFunctio diag_id = diag::warn_implicit_function_decl; Diag(Loc, diag_id) << &II; + // If we found a prior declaration of this function, don't bother building + // another one. We've already pushed that one into scope, so there's nothing + // more to do. + if (ExternCPrev) +return ExternCPrev; + // Because typo correction is expensive, only do it if the implicit // function declaration is going to be treated as an error. if (Diags.getDiagnosticLevel(diag_id, Loc) >= DiagnosticsEngine::Error) { @@ -12687,19 +12711,9 @@ NamedDecl *Sema::ImplicitlyDefineFunctio D.SetIdentifi
r314872 - We allow implicit function declarations as an extension in all C dialects. Remove OpenCL special case.
Author: rsmith Date: Tue Oct 3 18:58:22 2017 New Revision: 314872 URL: http://llvm.org/viewvc/llvm-project?rev=314872&view=rev Log: We allow implicit function declarations as an extension in all C dialects. Remove OpenCL special case. Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaDecl.cpp cfe/trunk/test/SemaOpenCL/clang-builtin-version.cl cfe/trunk/test/SemaOpenCL/to_addr_builtin.cl Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=314872&r1=314871&r2=314872&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Oct 3 18:58:22 2017 @@ -355,7 +355,7 @@ def warn_implicit_function_decl : Warnin "implicit declaration of function %0">, InGroup, DefaultIgnore; def ext_implicit_function_decl : ExtWarn< - "implicit declaration of function %0 is invalid in C99">, + "implicit declaration of function %0 is invalid in %select{C99|OpenCL}1">, InGroup; def note_function_suggestion : Note<"did you mean %0?">; @@ -8449,8 +8449,6 @@ def err_opencl_scalar_type_rank_greater_ "element. (%0 and %1)">; def err_bad_kernel_param_type : Error< "%0 cannot be used as the type of a kernel parameter">; -def err_opencl_implicit_function_decl : Error< - "implicit declaration of function %0 is invalid in OpenCL">; def err_record_with_pointers_kernel_param : Error< "%select{struct|union}0 kernel parameters may not contain pointers">; def note_within_field_of_type : Note< Modified: cfe/trunk/lib/Sema/SemaDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=314872&r1=314871&r2=314872&view=diff == --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Oct 3 18:58:22 2017 @@ -12642,17 +12642,15 @@ NamedDecl *Sema::ImplicitlyDefineFunctio } // Extension in C99. Legal in C90, but warn about it. + // OpenCL v2.0 s6.9.u - Implicit function declaration is not supported. unsigned diag_id; if (II.getName().startswith("__builtin_")) diag_id = diag::warn_builtin_unknown; - // OpenCL v2.0 s6.9.u - Implicit function declaration is not supported. - else if (getLangOpts().OpenCL) -diag_id = diag::err_opencl_implicit_function_decl; - else if (getLangOpts().C99) + else if (getLangOpts().C99 || getLangOpts().OpenCL) diag_id = diag::ext_implicit_function_decl; else diag_id = diag::warn_implicit_function_decl; - Diag(Loc, diag_id) << &II; + Diag(Loc, diag_id) << &II << getLangOpts().OpenCL; // If we found a prior declaration of this function, don't bother building // another one. We've already pushed that one into scope, so there's nothing Modified: cfe/trunk/test/SemaOpenCL/clang-builtin-version.cl URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/clang-builtin-version.cl?rev=314872&r1=314871&r2=314872&view=diff == --- cfe/trunk/test/SemaOpenCL/clang-builtin-version.cl (original) +++ cfe/trunk/test/SemaOpenCL/clang-builtin-version.cl Tue Oct 3 18:58:22 2017 @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 %s -fblocks -verify -pedantic -fsyntax-only -ferror-limit 100 +// RUN: %clang_cc1 %s -fblocks -verify -pedantic-errors -fsyntax-only -ferror-limit 100 // Confirm CL2.0 Clang builtins are not available in earlier versions Modified: cfe/trunk/test/SemaOpenCL/to_addr_builtin.cl URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/to_addr_builtin.cl?rev=314872&r1=314871&r2=314872&view=diff == --- cfe/trunk/test/SemaOpenCL/to_addr_builtin.cl (original) +++ cfe/trunk/test/SemaOpenCL/to_addr_builtin.cl Tue Oct 3 18:58:22 2017 @@ -10,7 +10,7 @@ void test(void) { glob = to_global(glob, loc); #if __OPENCL_C_VERSION__ < CL_VERSION_2_0 - // expected-error@-2{{implicit declaration of function 'to_global' is invalid in OpenCL}} + // expected-warning@-2{{implicit declaration of function 'to_global' is invalid in OpenCL}} // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}} #else // expected-error@-5{{invalid number of arguments to function: 'to_global'}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r314955 - Remove PendingBody mechanism for function and ObjC method deserialization.
Author: rsmith Date: Wed Oct 4 17:43:38 2017 New Revision: 314955 URL: http://llvm.org/viewvc/llvm-project?rev=314955&view=rev Log: Remove PendingBody mechanism for function and ObjC method deserialization. In its place, track on the canonical function declaration whether there is a declaration with a body (and if so, which one). This brings function definition handling in line with what we do in all other contexts, and is necessary to allow us to merge declarations within multiple definitions of the same function (eg, PR33924). No functionality change intended. Modified: cfe/trunk/include/clang/Serialization/ASTReader.h cfe/trunk/lib/Serialization/ASTReader.cpp cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Modified: cfe/trunk/include/clang/Serialization/ASTReader.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=314955&r1=314954&r2=314955&view=diff == --- cfe/trunk/include/clang/Serialization/ASTReader.h (original) +++ cfe/trunk/include/clang/Serialization/ASTReader.h Wed Oct 4 17:43:38 2017 @@ -559,13 +559,9 @@ private: /// declarations that have not yet been linked to their definitions. llvm::SmallPtrSet PendingDefinitions; - typedef llvm::MapVector, - SmallVector, 4> > -PendingBodiesMap; - - /// \brief Functions or methods that have bodies that will be attached. - PendingBodiesMap PendingBodies; + /// \brief Functions or methods that are known to already have a definition + /// (that might not yet be merged into the redeclaration chain). + llvm::SmallDenseMap FunctionDefinitions; /// \brief Definitions for which we have added merged definitions but not yet /// performed deduplication. @@ -991,25 +987,13 @@ private: /// the last time we loaded information about this identifier. llvm::DenseMap IdentifierGeneration; - class InterestingDecl { -Decl *D; -bool DeclHasPendingBody; - - public: -InterestingDecl(Decl *D, bool HasBody) -: D(D), DeclHasPendingBody(HasBody) {} -Decl *getDecl() { return D; } -/// Whether the declaration has a pending body. -bool hasPendingBody() { return DeclHasPendingBody; } - }; - /// \brief Contains declarations and definitions that could be /// "interesting" to the ASTConsumer, when we get that AST consumer. /// /// "Interesting" declarations are those that have data that may /// need to be emitted, such as inline function definitions or /// Objective-C protocols. - std::deque PotentiallyInterestingDecls; + std::deque PotentiallyInterestingDecls; /// \brief The list of redeclaration chains that still need to be /// reconstructed, and the local offset to the corresponding list Modified: cfe/trunk/lib/Serialization/ASTReader.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=314955&r1=314954&r2=314955&view=diff == --- cfe/trunk/lib/Serialization/ASTReader.cpp (original) +++ cfe/trunk/lib/Serialization/ASTReader.cpp Wed Oct 4 17:43:38 2017 @@ -9168,30 +9168,6 @@ void ASTReader::finishPendingActions() { } PendingDefinitions.clear(); - // Load the bodies of any functions or methods we've encountered. We do - // this now (delayed) so that we can be sure that the declaration chains - // have been fully wired up (hasBody relies on this). - // FIXME: We shouldn't require complete redeclaration chains here. - for (PendingBodiesMap::iterator PB = PendingBodies.begin(), - PBEnd = PendingBodies.end(); - PB != PBEnd; ++PB) { -if (FunctionDecl *FD = dyn_cast(PB->first)) { - // FIXME: Check for =delete/=default? - // FIXME: Complain about ODR violations here? - const FunctionDecl *Defn = nullptr; - if (!getContext().getLangOpts().Modules || !FD->hasBody(Defn)) { -FD->setLazyBody(PB->second); - } else -mergeDefinitionVisibility(const_cast(Defn), FD); - continue; -} - -ObjCMethodDecl *MD = cast(PB->first); -if (!getContext().getLangOpts().Modules || !MD->hasBody()) - MD->setLazyBody(PB->second); - } - PendingBodies.clear(); - // Do some cleanup. for (auto *ND : PendingMergedDefinitionsToDeduplicate) getContext().deduplicateMergedDefinitonsFor(ND); Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=314955&r1=314954&r2=314955&view=diff == --- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original) +++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Wed Oct 4 17:43:38 2017 @@ -45,8 +45,6 @@ namespace clang { GlobalDeclID NamedDeclForTagDecl; IdentifierInfo *TypedefNameForLinkage; -bool HasPendingBody; -
r314957 - Add testcase for r314956:
Author: rsmith Date: Wed Oct 4 17:48:18 2017 New Revision: 314957 URL: http://llvm.org/viewvc/llvm-project?rev=314957&view=rev Log: Add testcase for r314956: PR33924: Merge block-scope anonymous declarations if there are multiple definitions of the enclosing function. Added: cfe/trunk/test/Modules/merge-lambdas.cpp Added: cfe/trunk/test/Modules/merge-lambdas.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/merge-lambdas.cpp?rev=314957&view=auto == --- cfe/trunk/test/Modules/merge-lambdas.cpp (added) +++ cfe/trunk/test/Modules/merge-lambdas.cpp Wed Oct 4 17:48:18 2017 @@ -0,0 +1,43 @@ +// RUN: %clang_cc1 -std=c++11 -emit-llvm-only -fmodules %s + +// PR33924: ensure that we merge together local lambas in multiple definitions +// of the same function. + +#pragma clang module build format +module format {} +#pragma clang module contents +#pragma clang module begin format +struct A { template void doFormat(T &&out) {} }; +template void format(T t) { A().doFormat([]{}); } +#pragma clang module end +#pragma clang module endbuild + +#pragma clang module build foo1 +module foo1 { export * } +#pragma clang module contents +#pragma clang module begin foo1 +#pragma clang module import format +inline void foo1() { + format(0); +} +#pragma clang module end +#pragma clang module endbuild + +#pragma clang module build foo2 +module foo2 { export * } +#pragma clang module contents +#pragma clang module begin foo2 +#pragma clang module import format +inline void foo2() { + format(0); +} +#pragma clang module end +#pragma clang module endbuild + +#pragma clang module import foo1 +#pragma clang module import foo2 + +int main() { + foo1(); + foo2(); +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r315005 - Fix two-phase name lookup for non-dependent overloaded operators.
Author: rsmith Date: Thu Oct 5 12:35:51 2017 New Revision: 315005 URL: http://llvm.org/viewvc/llvm-project?rev=315005&view=rev Log: Fix two-phase name lookup for non-dependent overloaded operators. If we resolve an overloaded operator call to a specific function during template definition, don't perform ADL during template instantiation. Doing so finds overloads that we're not supposed to find. Modified: cfe/trunk/include/clang/Sema/Sema.h cfe/trunk/lib/Sema/SemaOverload.cpp cfe/trunk/lib/Sema/TreeTransform.h cfe/trunk/test/SemaCXX/overloaded-operator.cpp Modified: cfe/trunk/include/clang/Sema/Sema.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=315005&r1=315004&r2=315005&view=diff == --- cfe/trunk/include/clang/Sema/Sema.h (original) +++ cfe/trunk/include/clang/Sema/Sema.h Thu Oct 5 12:35:51 2017 @@ -2914,12 +2914,13 @@ public: ExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc, const UnresolvedSetImpl &Fns, - Expr *input); + Expr *input, bool RequiresADL = true); ExprResult CreateOverloadedBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc, const UnresolvedSetImpl &Fns, - Expr *LHS, Expr *RHS); + Expr *LHS, Expr *RHS, + bool RequiresADL = true); ExprResult CreateOverloadedArraySubscriptExpr(SourceLocation LLoc, SourceLocation RLoc, Modified: cfe/trunk/lib/Sema/SemaOverload.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=315005&r1=315004&r2=315005&view=diff == --- cfe/trunk/lib/Sema/SemaOverload.cpp (original) +++ cfe/trunk/lib/Sema/SemaOverload.cpp Thu Oct 5 12:35:51 2017 @@ -11927,7 +11927,7 @@ static bool IsOverloaded(const Unresolve ExprResult Sema::CreateOverloadedUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc, const UnresolvedSetImpl &Fns, - Expr *Input) { + Expr *Input, bool PerformADL) { OverloadedOperatorKind Op = UnaryOperator::getOverloadedOperator(Opc); assert(Op != OO_None && "Invalid opcode for overloaded unary operator"); DeclarationName OpName = Context.DeclarationNames.getCXXOperatorName(Op); @@ -11978,9 +11978,11 @@ Sema::CreateOverloadedUnaryOp(SourceLoca AddMemberOperatorCandidates(Op, OpLoc, ArgsArray, CandidateSet); // Add candidates from ADL. - AddArgumentDependentLookupCandidates(OpName, OpLoc, ArgsArray, - /*ExplicitTemplateArgs*/nullptr, - CandidateSet); + if (PerformADL) { +AddArgumentDependentLookupCandidates(OpName, OpLoc, ArgsArray, + /*ExplicitTemplateArgs*/nullptr, + CandidateSet); + } // Add builtin operator candidates. AddBuiltinOperatorCandidates(Op, OpLoc, ArgsArray, CandidateSet); @@ -12118,7 +12120,7 @@ ExprResult Sema::CreateOverloadedBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc, const UnresolvedSetImpl &Fns, -Expr *LHS, Expr *RHS) { +Expr *LHS, Expr *RHS, bool PerformADL) { Expr *Args[2] = { LHS, RHS }; LHS=RHS=nullptr; // Please use only Args instead of LHS/RHS couple @@ -12149,7 +12151,7 @@ Sema::CreateOverloadedBinOp(SourceLocati UnresolvedLookupExpr *Fn = UnresolvedLookupExpr::Create(Context, NamingClass, NestedNameSpecifierLoc(), OpNameInfo, - /*ADL*/ true, IsOverloaded(Fns), + /*ADL*/PerformADL, IsOverloaded(Fns), Fns.begin(), Fns.end()); return new (Context) CXXOperatorCallExpr(Context, Op, Fn, Args, Context.DependentTy, @@ -12192,7 +12194,7 @@ Sema::CreateOverloadedBinOp(SourceLocati // Add candidates from ADL. Per [over.match.oper]p2, this lookup is not // performed for an assignment operator (nor for operator[] nor operator->, // which don't get here). - if (Opc != BO_Assign) + if (Opc != BO_Assign && PerformADL) AddArgumentDependentLookupCandidates(OpName, OpLoc, Args, /*ExplicitTemplateArgs*/ nullptr, CandidateSet); Modified: cfe/trunk/lib/Sema/TreeTransform.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransf
r315251 - [Modules TS] Module ownership semantics for redeclarations.
Author: rsmith Date: Mon Oct 9 16:42:09 2017 New Revision: 315251 URL: http://llvm.org/viewvc/llvm-project?rev=315251&view=rev Log: [Modules TS] Module ownership semantics for redeclarations. When declaring an entity in the "purview" of a module, it's never a redeclaration of an entity in the purview of a default module or in no module ("in the global module"). Don't consider those other declarations as possible redeclaration targets if they're not visible, and reject any cases where we pick a prior visible declaration that violates this rule. Added: cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p6/ cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p6/global-vs-module.cpp cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p6/module-vs-global.cpp cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p6/module-vs-module.cpp Modified: cfe/trunk/include/clang/AST/Decl.h cfe/trunk/include/clang/AST/DeclBase.h cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/include/clang/Sema/Lookup.h cfe/trunk/include/clang/Sema/Sema.h cfe/trunk/lib/AST/Decl.cpp cfe/trunk/lib/AST/DeclBase.cpp cfe/trunk/lib/AST/DeclCXX.cpp cfe/trunk/lib/Sema/SemaDecl.cpp cfe/trunk/lib/Sema/SemaDeclCXX.cpp cfe/trunk/lib/Sema/SemaDeclObjC.cpp cfe/trunk/lib/Sema/SemaExprMember.cpp cfe/trunk/lib/Sema/SemaLookup.cpp cfe/trunk/lib/Sema/SemaOpenMP.cpp cfe/trunk/lib/Sema/SemaTemplate.cpp cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp cfe/trunk/test/SemaCXX/modules-ts.cppm Modified: cfe/trunk/include/clang/AST/Decl.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=315251&r1=315250&r2=315251&view=diff == --- cfe/trunk/include/clang/AST/Decl.h (original) +++ cfe/trunk/include/clang/AST/Decl.h Mon Oct 9 16:42:09 2017 @@ -339,6 +339,12 @@ public: return clang::isExternallyVisible(getLinkageInternal()); } + /// Determine whether this declaration can be redeclared in a + /// different translation unit. + bool isExternallyDeclarable() const { +return isExternallyVisible() && !getOwningModuleForLinkage(); + } + /// \brief Determines the visibility of this entity. Visibility getVisibility() const { return getLinkageAndVisibility().getVisibility(); @@ -379,10 +385,6 @@ public: return hasCachedLinkage(); } - /// Get the module that owns this declaration for linkage purposes. - /// There only ever is such a module under the C++ Modules TS. - Module *getOwningModuleForLinkage() const; - /// \brief Looks through UsingDecls and ObjCCompatibleAliasDecls for /// the underlying named decl. NamedDecl *getUnderlyingDecl() { Modified: cfe/trunk/include/clang/AST/DeclBase.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=315251&r1=315250&r2=315251&view=diff == --- cfe/trunk/include/clang/AST/DeclBase.h (original) +++ cfe/trunk/include/clang/AST/DeclBase.h Mon Oct 9 16:42:09 2017 @@ -738,6 +738,10 @@ public: return isFromASTFile() ? getImportedOwningModule() : getLocalOwningModule(); } + /// Get the module that owns this declaration for linkage purposes. + /// There only ever is such a module under the C++ Modules TS. + Module *getOwningModuleForLinkage() const; + /// \brief Determine whether this declaration might be hidden from name /// lookup. Note that the declaration might be visible even if this returns /// \c false, if the owning module is visible within the query context. Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=315251&r1=315250&r2=315251&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Oct 9 16:42:09 2017 @@ -4801,6 +4801,9 @@ def err_thread_non_thread : Error< def err_thread_thread_different_kind : Error< "thread-local declaration of %0 with %select{static|dynamic}1 initialization " "follows declaration with %select{dynamic|static}1 initialization">; +def err_mismatched_owning_module : Error< + "declaration of %0 in %select{the global module|module %2}1 follows " + "declaration in %select{the global module|module %4}3">; def err_redefinition_different_type : Error< "redefinition of %0 with a different type%diff{: $ vs $|}1,2">; def err_redefinition_different_kind : Error< Modified: cfe/trunk/include/clang/Sema/Lookup.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Lookup.h?rev=315251&r1=315250&r2=315251&view=diff == --- cfe/trunk/include/clang/Sema/Lookup.h (original
r315256 - [Modules TS] Avoid computing the linkage of the enclosing DeclContext for a declaration in the global module.
Author: rsmith Date: Mon Oct 9 17:49:38 2017 New Revision: 315256 URL: http://llvm.org/viewvc/llvm-project?rev=315256&view=rev Log: [Modules TS] Avoid computing the linkage of the enclosing DeclContext for a declaration in the global module. This works around a language issue where adding a typedef name for linkage purposes changes the linkage of an already-defined class after it becomes complete. Added: cfe/trunk/test/Modules/anon-linkage.cpp Modified: cfe/trunk/include/clang/AST/DeclBase.h cfe/trunk/include/clang/Sema/Sema.h cfe/trunk/lib/AST/Decl.cpp Modified: cfe/trunk/include/clang/AST/DeclBase.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=315256&r1=315255&r2=315256&view=diff == --- cfe/trunk/include/clang/AST/DeclBase.h (original) +++ cfe/trunk/include/clang/AST/DeclBase.h Mon Oct 9 17:49:38 2017 @@ -740,7 +740,10 @@ public: /// Get the module that owns this declaration for linkage purposes. /// There only ever is such a module under the C++ Modules TS. - Module *getOwningModuleForLinkage() const; + /// + /// \param IgnoreLinkage Ignore the linkage of the entity; assume that + /// all declarations in a global module fragment are unowned. + Module *getOwningModuleForLinkage(bool IgnoreLinkage = false) const; /// \brief Determine whether this declaration might be hidden from name /// lookup. Note that the declaration might be visible even if this returns Modified: cfe/trunk/include/clang/Sema/Sema.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=315256&r1=315255&r2=315256&view=diff == --- cfe/trunk/include/clang/Sema/Sema.h (original) +++ cfe/trunk/include/clang/Sema/Sema.h Mon Oct 9 17:49:38 2017 @@ -3051,8 +3051,11 @@ public: RedeclarationKind forRedeclarationInCurContext() { // A declaration with an owning module for linkage can never link against -// anything that is not visible. -if (cast(CurContext)->getOwningModuleForLinkage()) +// anything that is not visible. We don't need to check linkage here; if +// the context has internal linkage, redeclaration lookup won't find things +// from other TUs, and we can't safely compute linkage yet in general. +if (cast(CurContext) +->getOwningModuleForLinkage(/*IgnoreLinkage*/true)) return ForVisibleRedeclaration; return ForExternalRedeclaration; } Modified: cfe/trunk/lib/AST/Decl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=315256&r1=315255&r2=315256&view=diff == --- cfe/trunk/lib/AST/Decl.cpp (original) +++ cfe/trunk/lib/AST/Decl.cpp Mon Oct 9 17:49:38 2017 @@ -1395,7 +1395,7 @@ LinkageInfo LinkageComputer::getDeclLink : NamedDecl::VisibilityForValue)); } -Module *Decl::getOwningModuleForLinkage() const { +Module *Decl::getOwningModuleForLinkage(bool IgnoreLinkage) const { Module *M = getOwningModule(); if (!M) return nullptr; @@ -1413,6 +1413,8 @@ Module *Decl::getOwningModuleForLinkage( // for linkage purposes. But internal linkage declarations in the global // module fragment of a particular module are owned by that module for // linkage purposes. +if (IgnoreLinkage) + return nullptr; bool InternalLinkage; if (auto *ND = dyn_cast(this)) InternalLinkage = !ND->hasExternalFormalLinkage(); Added: cfe/trunk/test/Modules/anon-linkage.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/anon-linkage.cpp?rev=315256&view=auto == --- cfe/trunk/test/Modules/anon-linkage.cpp (added) +++ cfe/trunk/test/Modules/anon-linkage.cpp Mon Oct 9 17:49:38 2017 @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -std=c++17 -fmodules-ts %s + +typedef struct { + int c; + union { +int n; +char c[4]; + } v; +} mbstate; + +export module M; +export using ::mbstate; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r315251 - [Modules TS] Module ownership semantics for redeclarations.
On 10 Oct 2017 05:41, "Eric Liu via cfe-commits" wrote: Hi Richard, This is breaking the boostrap stage in the internal integration. I'm seeing "unsupported: typedef changes linkage of anonymous type, but linkage was already computed" error for many `struct`s defined with typedef. I'm not sure if it is user code or clang that needs fixing; however, as there are likely many more struct definitions that would cause the same failure, I'll revert this commit as well as r315256, which depends on this. Sorry about that. r315256 should have fixed those errors. Did it not? I'll also send you the repros separately. Regards, Eric On Tue, Oct 10, 2017 at 1:42 AM Richard Smith via cfe-commits < cfe-commits@lists.llvm.org> wrote: > Author: rsmith > Date: Mon Oct 9 16:42:09 2017 > New Revision: 315251 > > URL: http://llvm.org/viewvc/llvm-project?rev=315251&view=rev > Log: > [Modules TS] Module ownership semantics for redeclarations. > > When declaring an entity in the "purview" of a module, it's never a > redeclaration of an entity in the purview of a default module or in no > module > ("in the global module"). Don't consider those other declarations as > possible > redeclaration targets if they're not visible, and reject any cases where we > pick a prior visible declaration that violates this rule. > > Added: > cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p6/ > cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p6/global- > vs-module.cpp > cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p6/module- > vs-global.cpp > cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p6/module- > vs-module.cpp > Modified: > cfe/trunk/include/clang/AST/Decl.h > cfe/trunk/include/clang/AST/DeclBase.h > cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td > cfe/trunk/include/clang/Sema/Lookup.h > cfe/trunk/include/clang/Sema/Sema.h > cfe/trunk/lib/AST/Decl.cpp > cfe/trunk/lib/AST/DeclBase.cpp > cfe/trunk/lib/AST/DeclCXX.cpp > cfe/trunk/lib/Sema/SemaDecl.cpp > cfe/trunk/lib/Sema/SemaDeclCXX.cpp > cfe/trunk/lib/Sema/SemaDeclObjC.cpp > cfe/trunk/lib/Sema/SemaExprMember.cpp > cfe/trunk/lib/Sema/SemaLookup.cpp > cfe/trunk/lib/Sema/SemaOpenMP.cpp > cfe/trunk/lib/Sema/SemaTemplate.cpp > cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp > cfe/trunk/test/SemaCXX/modules-ts.cppm > > Modified: cfe/trunk/include/clang/AST/Decl.h > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/ > clang/AST/Decl.h?rev=315251&r1=315250&r2=315251&view=diff > > == > --- cfe/trunk/include/clang/AST/Decl.h (original) > +++ cfe/trunk/include/clang/AST/Decl.h Mon Oct 9 16:42:09 2017 > @@ -339,6 +339,12 @@ public: > return clang::isExternallyVisible(getLinkageInternal()); >} > > + /// Determine whether this declaration can be redeclared in a > + /// different translation unit. > + bool isExternallyDeclarable() const { > +return isExternallyVisible() && !getOwningModuleForLinkage(); > + } > + >/// \brief Determines the visibility of this entity. >Visibility getVisibility() const { > return getLinkageAndVisibility().getVisibility(); > @@ -379,10 +385,6 @@ public: > return hasCachedLinkage(); >} > > - /// Get the module that owns this declaration for linkage purposes. > - /// There only ever is such a module under the C++ Modules TS. > - Module *getOwningModuleForLinkage() const; > - >/// \brief Looks through UsingDecls and ObjCCompatibleAliasDecls for >/// the underlying named decl. >NamedDecl *getUnderlyingDecl() { > > Modified: cfe/trunk/include/clang/AST/DeclBase.h > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/ > clang/AST/DeclBase.h?rev=315251&r1=315250&r2=315251&view=diff > > == > --- cfe/trunk/include/clang/AST/DeclBase.h (original) > +++ cfe/trunk/include/clang/AST/DeclBase.h Mon Oct 9 16:42:09 2017 > @@ -738,6 +738,10 @@ public: > return isFromASTFile() ? getImportedOwningModule() : > getLocalOwningModule(); >} > > + /// Get the module that owns this declaration for linkage purposes. > + /// There only ever is such a module under the C++ Modules TS. > + Module *getOwningModuleForLinkage() const; > + >/// \brief Determine whether this declaration might be hidden from name >/// lookup. Note that the declaration might be visible even if this > returns >/// \c false, if the owning module is visible within the query con
r315366 - Add test for regression caused by reverted patch r315251.
Author: rsmith Date: Tue Oct 10 14:07:44 2017 New Revision: 315366 URL: http://llvm.org/viewvc/llvm-project?rev=315366&view=rev Log: Add test for regression caused by reverted patch r315251. Modified: cfe/trunk/test/SemaCXX/linkage2.cpp Modified: cfe/trunk/test/SemaCXX/linkage2.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/linkage2.cpp?rev=315366&r1=315365&r2=315366&view=diff == --- cfe/trunk/test/SemaCXX/linkage2.cpp (original) +++ cfe/trunk/test/SemaCXX/linkage2.cpp Tue Oct 10 14:07:44 2017 @@ -218,3 +218,34 @@ namespace PR18964 { unsigned &*foo; //expected-error{{'foo' declared as a pointer to a reference of type}} extern struct {} *foo; // don't assert } + +namespace typedef_name_for_linkage { + template struct Use {}; + + struct A { A(); A(const A&); ~A(); }; + + typedef struct { +A a; + } B; + + struct C { +typedef struct { + A a; +} D; + }; + + typedef struct { +void f() { static int n; struct Inner {};} + } E; + + // FIXME: Ideally this would be accepted in all modes. In C++98, we trigger a + // linkage calculation to drive the "internal linkage type as template + // argument" warning. + typedef struct { +void f() { struct Inner {}; Use ui; } + } F; +#if __cplusplus < 201103L + // expected-error@-2 {{unsupported: typedef changes linkage of anonymous type, but linkage was already computed}} + // expected-note@-5 {{use a tag name here}} +#endif +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r315379 - [Modules TS] Module ownership semantics for redeclarations.
Author: rsmith Date: Tue Oct 10 15:33:17 2017 New Revision: 315379 URL: http://llvm.org/viewvc/llvm-project?rev=315379&view=rev Log: [Modules TS] Module ownership semantics for redeclarations. When declaring an entity in the "purview" of a module, it's never a redeclaration of an entity in the purview of a default module or in no module ("in the global module"). Don't consider those other declarations as possible redeclaration targets if they're not visible, and reject any cases where we pick a prior visible declaration that violates this rule. This reinstates r315251 and r315256, reverted in r315309 and r315308 respectively, tweaked to avoid triggering a linkage calculation when declaring implicit special members (this exposed our pre-existing issue with typedef names for linkage changing the linkage of types whose linkage has already been computed and cached in more cases). A testcase for that regression has been added in r315366. Added: cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p6/global-vs-module.cpp - copied unchanged from r315308, cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p6/global-vs-module.cpp cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p6/module-vs-global.cpp - copied unchanged from r315308, cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p6/module-vs-global.cpp cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p6/module-vs-module.cpp - copied unchanged from r315308, cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p6/module-vs-module.cpp cfe/trunk/test/Modules/anon-linkage.cpp - copied unchanged from r315307, cfe/trunk/test/Modules/anon-linkage.cpp Modified: cfe/trunk/include/clang/AST/Decl.h cfe/trunk/include/clang/AST/DeclBase.h cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/include/clang/Sema/Lookup.h cfe/trunk/include/clang/Sema/Sema.h cfe/trunk/lib/AST/Decl.cpp cfe/trunk/lib/AST/DeclBase.cpp cfe/trunk/lib/AST/DeclCXX.cpp cfe/trunk/lib/Sema/SemaDecl.cpp cfe/trunk/lib/Sema/SemaDeclCXX.cpp cfe/trunk/lib/Sema/SemaDeclObjC.cpp cfe/trunk/lib/Sema/SemaExprMember.cpp cfe/trunk/lib/Sema/SemaLookup.cpp cfe/trunk/lib/Sema/SemaOpenMP.cpp cfe/trunk/lib/Sema/SemaTemplate.cpp cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp cfe/trunk/test/SemaCXX/modules-ts.cppm Modified: cfe/trunk/include/clang/AST/Decl.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=315379&r1=315378&r2=315379&view=diff == --- cfe/trunk/include/clang/AST/Decl.h (original) +++ cfe/trunk/include/clang/AST/Decl.h Tue Oct 10 15:33:17 2017 @@ -339,6 +339,12 @@ public: return clang::isExternallyVisible(getLinkageInternal()); } + /// Determine whether this declaration can be redeclared in a + /// different translation unit. + bool isExternallyDeclarable() const { +return isExternallyVisible() && !getOwningModuleForLinkage(); + } + /// \brief Determines the visibility of this entity. Visibility getVisibility() const { return getLinkageAndVisibility().getVisibility(); @@ -379,10 +385,6 @@ public: return hasCachedLinkage(); } - /// Get the module that owns this declaration for linkage purposes. - /// There only ever is such a module under the C++ Modules TS. - Module *getOwningModuleForLinkage() const; - /// \brief Looks through UsingDecls and ObjCCompatibleAliasDecls for /// the underlying named decl. NamedDecl *getUnderlyingDecl() { Modified: cfe/trunk/include/clang/AST/DeclBase.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=315379&r1=315378&r2=315379&view=diff == --- cfe/trunk/include/clang/AST/DeclBase.h (original) +++ cfe/trunk/include/clang/AST/DeclBase.h Tue Oct 10 15:33:17 2017 @@ -738,6 +738,13 @@ public: return isFromASTFile() ? getImportedOwningModule() : getLocalOwningModule(); } + /// Get the module that owns this declaration for linkage purposes. + /// There only ever is such a module under the C++ Modules TS. + /// + /// \param IgnoreLinkage Ignore the linkage of the entity; assume that + /// all declarations in a global module fragment are unowned. + Module *getOwningModuleForLinkage(bool IgnoreLinkage = false) const; + /// \brief Determine whether this declaration might be hidden from name /// lookup. Note that the declaration might be visible even if this returns /// \c false, if the owning module is visible within the query context. Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=315379&r1=315378&r2=315379&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +
r315381 - [Modules TS] Diagnose attempts to enter module implementation units without the module interface being available.
Author: rsmith Date: Tue Oct 10 15:35:27 2017 New Revision: 315381 URL: http://llvm.org/viewvc/llvm-project?rev=315381&view=rev Log: [Modules TS] Diagnose attempts to enter module implementation units without the module interface being available. Added: cfe/trunk/test/CXX/modules-ts/dcl.dcl/dcl.module/p2.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/include/clang/Sema/Sema.h cfe/trunk/lib/Parse/Parser.cpp cfe/trunk/lib/Sema/SemaDecl.cpp cfe/trunk/test/CXX/modules-ts/basic/basic.link/module-declaration.cpp cfe/trunk/test/CXX/modules-ts/dcl.dcl/dcl.module/dcl.module.import/p1.cpp cfe/trunk/test/CXX/modules-ts/dcl.dcl/dcl.module/dcl.module.interface/p1.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=315381&r1=315380&r2=315381&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Oct 10 15:35:27 2017 @@ -8994,6 +8994,9 @@ def err_module_redefinition : Error< "redefinition of module '%0'">; def note_prev_module_definition : Note<"previously defined here">; def note_prev_module_definition_from_ast_file : Note<"module loaded from '%0'">; +def err_module_not_defined : Error< + "definition of module '%0' is not available; use -fmodule-file= to specify " + "path to precompiled module interface">; def err_module_private_specialization : Error< "%select{template|partial|member}0 specialization cannot be " "declared __module_private__">; Modified: cfe/trunk/include/clang/Sema/Sema.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=315381&r1=315380&r2=315381&view=diff == --- cfe/trunk/include/clang/Sema/Sema.h (original) +++ cfe/trunk/include/clang/Sema/Sema.h Tue Oct 10 15:35:27 2017 @@ -1533,7 +1533,8 @@ private: TypeDiagnoser *Diagnoser); struct ModuleScope { -clang::Module *Module; +clang::Module *Module = nullptr; +bool ModuleInterface = false; VisibleModuleSet OuterVisibleModules; }; /// The modules we're currently parsing. @@ -2051,9 +2052,9 @@ public: SourceLocation SemiLoc); enum class ModuleDeclKind { -Module, ///< 'module X;' +Interface, ///< 'export module X;' +Implementation, ///< 'module X;' Partition, ///< 'module partition X;' -Implementation, ///< 'module implementation X;' }; /// The parser has processed a module-declaration that begins the definition Modified: cfe/trunk/lib/Parse/Parser.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=315381&r1=315380&r2=315381&view=diff == --- cfe/trunk/lib/Parse/Parser.cpp (original) +++ cfe/trunk/lib/Parse/Parser.cpp Tue Oct 10 15:35:27 2017 @@ -2048,7 +2048,7 @@ Parser::DeclGroupPtrTy Parser::ParseModu SourceLocation StartLoc = Tok.getLocation(); Sema::ModuleDeclKind MDK = TryConsumeToken(tok::kw_export) - ? Sema::ModuleDeclKind::Module + ? Sema::ModuleDeclKind::Interface : Sema::ModuleDeclKind::Implementation; assert(Tok.is(tok::kw_module) && "not a module declaration"); @@ -2057,7 +2057,7 @@ Parser::DeclGroupPtrTy Parser::ParseModu if (Tok.is(tok::identifier) && NextToken().is(tok::identifier) && Tok.getIdentifierInfo()->isStr("partition")) { // If 'partition' is present, this must be a module interface unit. -if (MDK != Sema::ModuleDeclKind::Module) +if (MDK != Sema::ModuleDeclKind::Interface) Diag(Tok.getLocation(), diag::err_module_implementation_partition) << FixItHint::CreateInsertion(ModuleLoc, "export "); MDK = Sema::ModuleDeclKind::Partition; Modified: cfe/trunk/lib/Sema/SemaDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=315381&r1=315380&r2=315381&view=diff == --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Oct 10 15:35:27 2017 @@ -16168,6 +16168,7 @@ Sema::DeclGroupPtrTy Sema::ActOnModuleDe // implementation unit. That indicates the 'export' is missing. Diag(ModuleLoc, diag::err_module_interface_implementation_mismatch) << FixItHint::CreateInsertion(ModuleLoc, "export "); +MDK = ModuleDeclKind::Interface; break; case LangOptions::CMK_ModuleMap: @@ -16207,7 +16208,7 @@ Sema::DeclGroupPtrTy Sema::ActOnModuleDe assert(ModuleScopes.size() == 1 && "expected to be at global module scope"); switch (MDK)
r315397 - [Modules TS] Diagnose missing/duplicate module-declaration.
Author: rsmith Date: Tue Oct 10 17:36:56 2017 New Revision: 315397 URL: http://llvm.org/viewvc/llvm-project?rev=315397&view=rev Log: [Modules TS] Diagnose missing/duplicate module-declaration. Added: cfe/trunk/test/CXX/modules-ts/dcl.dcl/dcl.module/p1.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/Sema.cpp cfe/trunk/lib/Sema/SemaDecl.cpp cfe/trunk/test/CXX/modules-ts/dcl.dcl/dcl.module/dcl.module.interface/p1.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=315397&r1=315396&r2=315397&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Oct 10 17:36:56 2017 @@ -8997,6 +8997,11 @@ def note_prev_module_definition_from_ast def err_module_not_defined : Error< "definition of module '%0' is not available; use -fmodule-file= to specify " "path to precompiled module interface">; +def err_module_redeclaration : Error< + "translation unit contains multiple module declarations">; +def note_prev_module_declaration : Note<"previous module declaration is here">; +def err_module_declaration_missing : Error< + "missing 'export module' declaration in module interface unit">; def err_module_private_specialization : Error< "%select{template|partial|member}0 specialization cannot be " "declared __module_private__">; Modified: cfe/trunk/lib/Sema/Sema.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=315397&r1=315396&r2=315397&view=diff == --- cfe/trunk/lib/Sema/Sema.cpp (original) +++ cfe/trunk/lib/Sema/Sema.cpp Tue Oct 10 17:36:56 2017 @@ -930,6 +930,17 @@ void Sema::ActOnEndOfTranslationUnit() { } if (TUKind == TU_Module) { +// If we are building a module interface unit, we need to have seen the +// module declaration by now. +if (getLangOpts().getCompilingModule() == +LangOptions::CMK_ModuleInterface && +ModuleScopes.back().Module->Kind != Module::ModuleInterfaceUnit) { + // FIXME: Make a better guess as to where to put the module declaration. + Diag(getSourceManager().getLocForStartOfFile( + getSourceManager().getMainFileID()), + diag::err_module_declaration_missing); +} + // If we are building a module, resolve all of the exported declarations // now. if (Module *CurrentModule = PP.getCurrentModule()) { Modified: cfe/trunk/lib/Sema/SemaDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=315397&r1=315396&r2=315397&view=diff == --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Oct 10 17:36:56 2017 @@ -16176,9 +16176,19 @@ Sema::DeclGroupPtrTy Sema::ActOnModuleDe return nullptr; } + assert(ModuleScopes.size() == 1 && "expected to be at global module scope"); + // FIXME: Most of this work should be done by the preprocessor rather than // here, in order to support macro import. + // Only one module-declaration is permitted per source file. + if (ModuleScopes.back().Module->Kind == Module::ModuleInterfaceUnit) { +Diag(ModuleLoc, diag::err_module_redeclaration); +Diag(VisibleModules.getImportLoc(ModuleScopes.back().Module), + diag::note_prev_module_declaration); +return nullptr; + } + // Flatten the dots in a module name. Unlike Clang's hierarchical module map // modules, the dots here are just another character that can appear in a // module name. @@ -16189,8 +16199,6 @@ Sema::DeclGroupPtrTy Sema::ActOnModuleDe ModuleName += Piece.first->getName(); } - // FIXME: If we've already seen a module-declaration, report an error. - // If a module name was explicitly specified on the command line, it must be // correct. if (!getLangOpts().CurrentModule.empty() && @@ -16205,8 +16213,6 @@ Sema::DeclGroupPtrTy Sema::ActOnModuleDe auto &Map = PP.getHeaderSearchInfo().getModuleMap(); Module *Mod; - assert(ModuleScopes.size() == 1 && "expected to be at global module scope"); - switch (MDK) { case ModuleDeclKind::Interface: { // We can't have parsed or imported a definition of this module or parsed a @@ -16240,7 +16246,9 @@ Sema::DeclGroupPtrTy Sema::ActOnModuleDe /*IsIncludeDirective=*/false); if (!Mod) { Diag(ModuleLoc, diag::err_module_not_defined) << ModuleName; - return nullptr; + // Create an empty module interface unit for error recovery. + Mod = Map.createModuleForInterfaceUnit(ModuleLoc, ModuleName, + ModuleScopes.front().Module); }
r315402 - [modules] Only take visible using-directives into account during name lookup.
Author: rsmith Date: Tue Oct 10 18:19:11 2017 New Revision: 315402 URL: http://llvm.org/viewvc/llvm-project?rev=315402&view=rev Log: [modules] Only take visible using-directives into account during name lookup. Added: cfe/trunk/test/Modules/using-directive.cpp Modified: cfe/trunk/lib/Sema/SemaLookup.cpp Modified: cfe/trunk/lib/Sema/SemaLookup.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=315402&r1=315401&r2=315402&view=diff == --- cfe/trunk/lib/Sema/SemaLookup.cpp (original) +++ cfe/trunk/lib/Sema/SemaLookup.cpp Tue Oct 10 18:19:11 2017 @@ -88,13 +88,15 @@ namespace { /// A collection of using directives, as used by C++ unqualified /// lookup. class UnqualUsingDirectiveSet { +Sema &SemaRef; + typedef SmallVector ListTy; ListTy list; llvm::SmallPtrSet visited; public: -UnqualUsingDirectiveSet() {} +UnqualUsingDirectiveSet(Sema &SemaRef) : SemaRef(SemaRef) {} void visitScopeChain(Scope *S, Scope *InnermostFileScope) { // C++ [namespace.udir]p1: @@ -113,7 +115,8 @@ namespace { visit(Ctx, Ctx); } else if (!Ctx || Ctx->isFunctionOrMethod()) { for (auto *I : S->using_directives()) -visit(I, InnermostFileDC); +if (SemaRef.isVisible(I)) + visit(I, InnermostFileDC); } } } @@ -152,7 +155,7 @@ namespace { while (true) { for (auto UD : DC->using_directives()) { DeclContext *NS = UD->getNominatedNamespace(); - if (visited.insert(NS).second) { + if (visited.insert(NS).second && SemaRef.isVisible(UD)) { addUsingDirective(UD, EffectiveDC); queue.push_back(NS); } @@ -1085,7 +1088,7 @@ bool Sema::CppLookupName(LookupResult &R // } // } // - UnqualUsingDirectiveSet UDirs; + UnqualUsingDirectiveSet UDirs(*this); bool VisitedUsingDirectives = false; bool LeftStartingScope = false; DeclContext *OutsideOfTemplateParamDC = nullptr; @@ -1868,22 +1871,19 @@ static bool LookupQualifiedNameInUsingDi DeclContext *StartDC) { assert(StartDC->isFileContext() && "start context is not a file context"); - DeclContext::udir_range UsingDirectives = StartDC->using_directives(); - if (UsingDirectives.begin() == UsingDirectives.end()) return false; + // We have not yet looked into these namespaces, much less added + // their "using-children" to the queue. + SmallVector Queue; // We have at least added all these contexts to the queue. llvm::SmallPtrSet Visited; Visited.insert(StartDC); - // We have not yet looked into these namespaces, much less added - // their "using-children" to the queue. - SmallVector Queue; - // We have already looked into the initial namespace; seed the queue // with its using-children. - for (auto *I : UsingDirectives) { + for (auto *I : StartDC->using_directives()) { NamespaceDecl *ND = I->getNominatedNamespace()->getOriginalNamespace(); -if (Visited.insert(ND).second) +if (Visited.insert(ND).second && S.isVisible(I)) Queue.push_back(ND); } @@ -1931,7 +1931,7 @@ static bool LookupQualifiedNameInUsingDi for (auto I : ND->using_directives()) { NamespaceDecl *Nom = I->getNominatedNamespace(); - if (Visited.insert(Nom).second) + if (Visited.insert(Nom).second && S.isVisible(I)) Queue.push_back(Nom); } } @@ -3540,6 +3540,8 @@ static void LookupVisibleDecls(DeclConte if (QualifiedNameLookup) { ShadowContextRAII Shadow(Visited); for (auto I : Ctx->using_directives()) { + if (!Result.getSema().isVisible(I)) +continue; LookupVisibleDecls(I->getNominatedNamespace(), Result, QualifiedNameLookup, InBaseClass, Consumer, Visited, IncludeDependentBases); @@ -3746,7 +3748,7 @@ void Sema::LookupVisibleDecls(Scope *S, // Determine the set of using directives available during // unqualified name lookup. Scope *Initial = S; - UnqualUsingDirectiveSet UDirs; + UnqualUsingDirectiveSet UDirs(*this); if (getLangOpts().CPlusPlus) { // Find the first namespace or translation-unit scope. while (S && !isNamespaceOrTranslationUnitScope(S)) Added: cfe/trunk/test/Modules/using-directive.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/using-directive.cpp?rev=315402&view=auto == --- cfe/trunk/test/Modules/using-directive.cpp (added) +++ cfe/trunk/test/Modules/using-directive.cpp Tue Oct 10 18:19:11 2017 @@ -0,0 +1,62 @@ +// RUN: %clang_cc1 -fmodules -fmodules-local-submodule-visibility -fno-modules-error-recovery -fno-spell-checking -verify %s + +#pragma clang module build a +module a { explicit module b {} explicit module c {} } +#pra
r315408 - [modules] Fix visibility checking for using declarations via ADL.
Author: rsmith Date: Tue Oct 10 18:49:57 2017 New Revision: 315408 URL: http://llvm.org/viewvc/llvm-project?rev=315408&view=rev Log: [modules] Fix visibility checking for using declarations via ADL. We want to check whether the using (shadow) declaration itself is visible, not whether its target is visible. Added: cfe/trunk/test/Modules/adl.cpp Modified: cfe/trunk/lib/Sema/SemaLookup.cpp Modified: cfe/trunk/lib/Sema/SemaLookup.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=315408&r1=315407&r2=315408&view=diff == --- cfe/trunk/lib/Sema/SemaLookup.cpp (original) +++ cfe/trunk/lib/Sema/SemaLookup.cpp Tue Oct 10 18:49:57 2017 @@ -3349,16 +3349,24 @@ void Sema::ArgumentDependentLookup(Decla continue; } - if (isa(D)) -D = cast(D)->getTargetDecl(); + auto *Underlying = D; + if (auto *USD = dyn_cast(D)) +Underlying = USD->getTargetDecl(); - if (!isa(D) && !isa(D)) + if (!isa(Underlying) && + !isa(Underlying)) continue; - if (!isVisible(D) && !(D = findAcceptableDecl(*this, D))) -continue; + if (!isVisible(D)) { +D = findAcceptableDecl(*this, D); +if (!D) + continue; +if (auto *USD = dyn_cast(D)) + Underlying = USD->getTargetDecl(); + } - Result.insert(D); + // FIXME: Preserve D as the FoundDecl. + Result.insert(Underlying); } } } Added: cfe/trunk/test/Modules/adl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/adl.cpp?rev=315408&view=auto == --- cfe/trunk/test/Modules/adl.cpp (added) +++ cfe/trunk/test/Modules/adl.cpp Tue Oct 10 18:49:57 2017 @@ -0,0 +1,40 @@ +// RUN: %clang_cc1 -fmodules -verify -fno-modules-error-recovery -fno-spell-checking %s +// RUN: %clang_cc1 -fmodules -verify -fno-modules-error-recovery -DONLY_Y %s + +#pragma clang module build a +module a { + explicit module x {} + explicit module y {} +} +#pragma clang module contents +#pragma clang module begin a.x +namespace N { + template extern int f(T) { return 0; } +} +#pragma clang module end + +#pragma clang module begin a.y +#pragma clang module import a.x +using N::f; +#pragma clang module end +#pragma clang module endbuild + +namespace N { struct A {}; } +struct B {}; + +#ifndef ONLY_Y +#pragma clang module import a.x +void test1() { + f(N::A()); + f(B()); // expected-error {{use of undeclared identifier 'f'}} +} +#else +// expected-no-diagnostics +#endif + +#pragma clang module import a.y +void test2() { + // These are OK even if a.x is not imported. + f(N::A()); + f(B()); +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r313386 - [Sema] Error out early for tags defined inside an enumeration.
On 22 September 2017 at 18:00, Volodymyr Sapsai via cfe-commits < cfe-commits@lists.llvm.org> wrote: > > > On Sep 21, 2017, at 15:17, Richard Smith wrote: > > On 15 September 2017 at 12:51, Volodymyr Sapsai via cfe-commits < > cfe-commits@lists.llvm.org> wrote: > >> Author: vsapsai >> Date: Fri Sep 15 12:51:42 2017 >> New Revision: 313386 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=313386&view=rev >> Log: >> [Sema] Error out early for tags defined inside an enumeration. >> >> This fixes PR28903 by avoiding access check for inner enum constant. We >> are performing access check because one enum constant references another >> and because enum is defined in CXXRecordDecl. But access check doesn't >> work because FindDeclaringClass doesn't expect more than one EnumDecl >> and because inner enum has access AS_none due to not being an immediate >> child of a record. >> >> The change detects an enum is defined in wrong place and allows to skip >> parsing its body. Access check is skipped together with body parsing. >> There was no crash in C, added test case to cover the new error. >> >> rdar://problem/28530809 >> >> Reviewers: rnk, doug.gregor, rsmith >> >> Reviewed By: doug.gregor >> >> Subscribers: cfe-commits >> >> Differential Revision: https://reviews.llvm.org/D37089 >> >> >> Modified: >> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td >> cfe/trunk/lib/Sema/SemaDecl.cpp >> cfe/trunk/test/Sema/enum.c >> cfe/trunk/test/SemaCXX/enum.cpp >> >> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td >> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/ >> include/clang/Basic/DiagnosticSemaKinds.td?rev=313386&r1= >> 313385&r2=313386&view=diff >> >> == >> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) >> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Sep 15 >> 12:51:42 2017 >> @@ -1335,6 +1335,8 @@ def err_type_defined_in_alias_template : >>"%0 cannot be defined in a type alias template">; >> def err_type_defined_in_condition : Error< >>"%0 cannot be defined in a condition">; >> +def err_type_defined_in_enum : Error< >> + "%0 cannot be defined in an enumeration">; >> >> def note_pure_virtual_function : Note< >>"unimplemented pure virtual method %0 in %1">; >> >> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp >> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ >> Sema/SemaDecl.cpp?rev=313386&r1=313385&r2=313386&view=diff >> >> == >> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) >> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Sep 15 12:51:42 2017 >> @@ -13928,6 +13928,12 @@ CreateNewDecl: >> Invalid = true; >>} >> >> + if (!Invalid && TUK == TUK_Definition && DC->getDeclKind() == >> Decl::Enum) { >> +Diag(New->getLocation(), diag::err_type_defined_in_enum) >> + << Context.getTagDeclType(New); >> +Invalid = true; >> + } >> > > This looks like the wrong fix. As noted elsewhere, this is wrong in C. And > in C++, the relevant context is a type-specifier, which should be rejected > due to the check 7 lines above. > > It looks like the actual bug is that we don't consider the type within a > C99 compound literal to be a type-specifier. The fact that the context is > an enumeration is irrelevant. > > > At which point can we detect IsTypeSpecifier should be true? Which in turn > boils down to DeclSpecContext should be DSC_type_specifier. Currently we > have DeclSpecContext DSC_normal because it is a default argument in > Parser::ParseSpecifierQualifierList. > Which is called from > > #4 clang::Parser::ParseParenExpression(clang::Parser::ParenParseOption&, > bool, bool, clang::OpaquePtr&, clang::SourceLocation&) > at llvm-project/clang/lib/Parse/ParseExpr.cpp:2375 > The call to ParseSpecifierQualfiierList here should always pass DSC_type_specifier. We're parsing a type within parentheses (which we've already disambiguated as being a type cast / compound literal rather than an expression), which is the DSC_type_specifier case. > #5 clang::Parser::ParseCastExpression(bool, bool, bool&, > clang::Parser::TypeCastState, bool) at llvm-project/clang/lib/Parse/ > ParseExpr.cpp:768 > #6 clang::Parser::ParseCastExpression(bool, bool, > clang::Parser::TypeCastState, bool) at llvm-project/clang/lib/Parse/ > ParseExpr.cpp:521 > #7 > clang::Parser::ParseConstantExpressionInExprEvalContext(clang::Parser::TypeCastState) > at llvm-project/clang/lib/Parse/ParseExpr.cpp:201 > > I have considered using TypeCastState for setting DeclSpecContext but its > value is NotTypeCast because Parser::ParseEnumBody calls > ParseConstantExpression with default argument. And it looks correct as > parsing enum body doesn't imply presence of a type cast. > > I was struggling to find a good indication we are parsing type specifier > and the best option seems to be ParseCastExpression because it ex
Re: [PATCH] D38101: [Sema] Diagnose tautological comparison with type's min/max values
On 12 October 2017 at 15:11, Roman Lebedev via Phabricator via cfe-commits < cfe-commits@lists.llvm.org> wrote: > lebedev.ri reopened this revision. > lebedev.ri added a comment. > This revision is now accepted and ready to land. > > Reverted due to http://bb9.pgr.jp/#/builders/20/builds/59 that i don't > currently know how to deal with. > It is really sad that i failed to encounter it during testing. I see three issues there: 1) A warning in this code due to missing parentheses around a ^ operator. 2) This code generating correct warnings in the libc++ test suite. You could ask EricWF (cc'd) to look at those and either fix them or turn the warning flag off for libc++'s tests. 3) A stage2 / stage3 comparison failure in CGAtomic.cpp. That's pre-existing and nothing to do with your change. ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D38101: [Sema] Diagnose tautological comparison with type's min/max values
On 12 October 2017 at 15:41, Roman Lebedev via cfe-commits < cfe-commits@lists.llvm.org> wrote: > On Fri, Oct 13, 2017 at 1:22 AM, Richard Smith > wrote: > > On 12 October 2017 at 15:11, Roman Lebedev via Phabricator via > cfe-commits > > wrote: > >> > >> lebedev.ri reopened this revision. > >> lebedev.ri added a comment. > >> This revision is now accepted and ready to land. > >> > >> Reverted due to http://bb9.pgr.jp/#/builders/20/builds/59 that i don't > >> currently know how to deal with. > >> It is really sad that i failed to encounter it during testing. > > > > > > I see three issues there: > > > 1) A warning in this code due to missing parentheses around a ^ operator. > > > 2) This code generating correct warnings in the libc++ test suite. > Yes, this one is the problem. > > I'm honestly not sure about these comparisons with > std::numeric_limits<...>::{min,max}() > They is similar to what Nico Weber (CC'd, just in case) is raising in > post-review mail in > https://lists.llvm.org/pipermail/cfe-commits/Week-of- > Mon-20171009/206427.html > I personally would very much prefer to have the warning, as explained > in the follow-up mail. Our general philosophy on such things is: if there's some pattern of false positives (ie, cases where the code is reasonable and intentionally performing a tautological comparison) that we can reasonably identify, then disabling the warning for those cases would be a good idea. If the rate of false positives is not very low and we can't identify the problematic patterns, then we should turn the warning off by default. But even if the warning ends up off by default, we should still have it available. > You could ask EricWF (cc'd) to look at those and either fix them or turn > the warning > > flag off for libc++'s tests. > Eric: could you *please* look into that? :) > That is way too deep to change without prior knowledge about the code i > think. > > > 3) A stage2 / stage3 comparison failure in CGAtomic.cpp. That's > pre-existing > > and nothing to do with your change. > > Roman. > ___ > cfe-commits mailing list > cfe-commits@lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits > ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r315662 - Support for destroying operator delete, per C++2a proposal P0722.
Author: rsmith Date: Thu Oct 12 18:55:36 2017 New Revision: 315662 URL: http://llvm.org/viewvc/llvm-project?rev=315662&view=rev Log: Support for destroying operator delete, per C++2a proposal P0722. This feature is not (yet) approved by the C++ committee, so this is liable to be reverted or significantly modified based on committee feedback. No functionality change intended for existing code (a new type must be defined in namespace std to take advantage of this feature). Added: cfe/trunk/test/CodeGenCXX/cxx2a-destroying-delete.cpp cfe/trunk/test/SemaCXX/cxx2a-destroying-delete.cpp Modified: cfe/trunk/include/clang/AST/ASTMutationListener.h cfe/trunk/include/clang/AST/Decl.h cfe/trunk/include/clang/AST/DeclCXX.h cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/include/clang/Serialization/ASTWriter.h cfe/trunk/lib/AST/Decl.cpp cfe/trunk/lib/AST/DeclCXX.cpp cfe/trunk/lib/AST/ExprCXX.cpp cfe/trunk/lib/CodeGen/CGClass.cpp cfe/trunk/lib/CodeGen/CGExprCXX.cpp cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp cfe/trunk/lib/Frontend/MultiplexConsumer.cpp cfe/trunk/lib/Sema/SemaDeclCXX.cpp cfe/trunk/lib/Sema/SemaExprCXX.cpp cfe/trunk/lib/Serialization/ASTReaderDecl.cpp cfe/trunk/lib/Serialization/ASTWriter.cpp cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Modified: cfe/trunk/include/clang/AST/ASTMutationListener.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTMutationListener.h?rev=315662&r1=315661&r2=315662&view=diff == --- cfe/trunk/include/clang/AST/ASTMutationListener.h (original) +++ cfe/trunk/include/clang/AST/ASTMutationListener.h Thu Oct 12 18:55:36 2017 @@ -22,6 +22,7 @@ namespace clang { class CXXRecordDecl; class Decl; class DeclContext; + class Expr; class FieldDecl; class FunctionDecl; class FunctionTemplateDecl; @@ -80,7 +81,8 @@ public: /// \brief A virtual destructor's operator delete has been resolved. virtual void ResolvedOperatorDelete(const CXXDestructorDecl *DD, - const FunctionDecl *Delete) {} + const FunctionDecl *Delete, + Expr *ThisArg) {} /// \brief An implicit member got a definition. virtual void CompletedImplicitDefinition(const FunctionDecl *D) {} Modified: cfe/trunk/include/clang/AST/Decl.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=315662&r1=315661&r2=315662&view=diff == --- cfe/trunk/include/clang/AST/Decl.h (original) +++ cfe/trunk/include/clang/AST/Decl.h Thu Oct 12 18:55:36 2017 @@ -2036,6 +2036,9 @@ public: /// true through IsAligned. bool isReplaceableGlobalAllocationFunction(bool *IsAligned = nullptr) const; + /// \brief Determine whether this is a destroying operator delete. + bool isDestroyingOperatorDelete() const; + /// Compute the language linkage. LanguageLinkage getLanguageLinkage() const; Modified: cfe/trunk/include/clang/AST/DeclCXX.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=315662&r1=315661&r2=315662&view=diff == --- cfe/trunk/include/clang/AST/DeclCXX.h (original) +++ cfe/trunk/include/clang/AST/DeclCXX.h Thu Oct 12 18:55:36 2017 @@ -2566,7 +2566,10 @@ public: class CXXDestructorDecl : public CXXMethodDecl { void anchor() override; + // FIXME: Don't allocate storage for these except in the first declaration + // of a virtual destructor. FunctionDecl *OperatorDelete; + Expr *OperatorDeleteThisArg; CXXDestructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, @@ -2574,7 +2577,7 @@ class CXXDestructorDecl : public CXXMeth bool isInline, bool isImplicitlyDeclared) : CXXMethodDecl(CXXDestructor, C, RD, StartLoc, NameInfo, T, TInfo, SC_None, isInline, /*isConstexpr=*/false, SourceLocation()), - OperatorDelete(nullptr) { + OperatorDelete(nullptr), OperatorDeleteThisArg(nullptr) { setImplicit(isImplicitlyDeclared); } @@ -2587,10 +2590,13 @@ public: bool isImplicitlyDeclared); static CXXDestructorDecl *CreateDeserialized(ASTContext & C, unsigned ID); - void setOperatorDelete(FunctionDecl *OD); + void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg); const FunctionDecl *getOperatorDelete() const { return getCanonicalDecl()->OperatorDelete; } + Expr *getOperatorDeleteThisArg() const { +return getCanonicalDecl()->OperatorDeleteThisArg; + } CXXDestructorDecl *getCanonicalDecl() override { return cast(FunctionDecl::getCanonicalDecl()); Modified: cfe/trunk/include/clang/Basic/Dia
r315784 - Fix backwards warning for use of C++17 attributes-on-namespaces-and-enumerators feature.
Author: rsmith Date: Fri Oct 13 17:56:24 2017 New Revision: 315784 URL: http://llvm.org/viewvc/llvm-project?rev=315784&view=rev Log: Fix backwards warning for use of C++17 attributes-on-namespaces-and-enumerators feature. Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td cfe/trunk/lib/Parse/ParseDecl.cpp cfe/trunk/lib/Parse/ParseDeclCXX.cpp cfe/trunk/test/Parser/cxx0x-attributes.cpp cfe/trunk/test/SemaCXX/cxx0x-compat.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=315784&r1=315783&r2=315784&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Fri Oct 13 17:56:24 2017 @@ -558,10 +558,13 @@ def warn_cxx98_compat_noexcept_expr : Wa def warn_cxx98_compat_nullptr : Warning< "'nullptr' is incompatible with C++98">, InGroup, DefaultIgnore; -def warn_cxx14_compat_attribute : Warning< +def ext_ns_enum_attribute : Extension< + "attributes on %select{a namespace|an enumerator}0 declaration are " + "a C++17 extension">, InGroup; +def warn_cxx14_compat_ns_enum_attribute : Warning< "attributes on %select{a namespace|an enumerator}0 declaration are " "incompatible with C++ standards before C++17">, - InGroup, DefaultIgnore; + InGroup, DefaultIgnore; def warn_cxx98_compat_alignas : Warning<"'alignas' is incompatible with C++98">, InGroup, DefaultIgnore; def warn_cxx98_compat_attribute : Warning< Modified: cfe/trunk/lib/Parse/ParseDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=315784&r1=315783&r2=315784&view=diff == --- cfe/trunk/lib/Parse/ParseDecl.cpp (original) +++ cfe/trunk/lib/Parse/ParseDecl.cpp Fri Oct 13 17:56:24 2017 @@ -4413,9 +4413,10 @@ void Parser::ParseEnumBody(SourceLocatio MaybeParseGNUAttributes(attrs); ProhibitAttributes(attrs); // GNU-style attributes are prohibited. if (getLangOpts().CPlusPlus11 && isCXX11AttributeSpecifier()) { - if (!getLangOpts().CPlusPlus1z) -Diag(Tok.getLocation(), diag::warn_cxx14_compat_attribute) -<< 1 /*enumerator*/; + Diag(Tok.getLocation(), getLangOpts().CPlusPlus1z + ? diag::warn_cxx14_compat_ns_enum_attribute + : diag::ext_ns_enum_attribute) +<< 1 /*enumerator*/; ParseCXX11Attributes(attrs); } Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=315784&r1=315783&r2=315784&view=diff == --- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original) +++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Fri Oct 13 17:56:24 2017 @@ -77,9 +77,10 @@ Parser::DeclGroupPtrTy Parser::ParseName ParsedAttributesWithRange attrs(AttrFactory); SourceLocation attrLoc; if (getLangOpts().CPlusPlus11 && isCXX11AttributeSpecifier()) { -if (!getLangOpts().CPlusPlus1z) - Diag(Tok.getLocation(), diag::warn_cxx14_compat_attribute) - << 0 /*namespace*/; +Diag(Tok.getLocation(), getLangOpts().CPlusPlus1z +? diag::warn_cxx14_compat_ns_enum_attribute +: diag::ext_ns_enum_attribute) + << 0 /*namespace*/; attrLoc = Tok.getLocation(); ParseCXX11Attributes(attrs); } Modified: cfe/trunk/test/Parser/cxx0x-attributes.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx0x-attributes.cpp?rev=315784&r1=315783&r2=315784&view=diff == --- cfe/trunk/test/Parser/cxx0x-attributes.cpp (original) +++ cfe/trunk/test/Parser/cxx0x-attributes.cpp Fri Oct 13 17:56:24 2017 @@ -127,7 +127,7 @@ extern "C++" [[]] { } // expected-error [[]] using ns::i; // expected-error {{an attribute list cannot appear here}} [[unknown]] using namespace ns; // expected-warning {{unknown attribute 'unknown' ignored}} [[noreturn]] using namespace ns; // expected-error {{'noreturn' attribute only applies to functions}} -namespace [[]] ns2 {} // expected-warning {{attributes on a namespace declaration are incompatible with C++ standards before C++17}} +namespace [[]] ns2 {} // expected-warning {{attributes on a namespace declaration are a C++17 extension}} using [[]] alignas(4) [[]] ns::i; // expected-error {{an attribute list cannot appear here}} using [[]] alignas(4) [[]] foobar = int; // expected-error {{an attribute list cannot appear here}} expected-error {{'alignas' attribute only applies to}} @@ -179,7 +179,7 @@ enum [[]] E2; // expected-error {{forbid enum [[]] E1; enum [[]] E3 : int; enum [[]] { - k_123 [
r316055 - [modules] When finding the owning module of an instantiated context in template
Author: rsmith Date: Tue Oct 17 18:41:38 2017 New Revision: 316055 URL: http://llvm.org/viewvc/llvm-project?rev=316055&view=rev Log: [modules] When finding the owning module of an instantiated context in template instantiation, follow lexical parents not semantic ones: we want to find the module where the pattern was written. Added: cfe/trunk/test/Modules/visibility-in-instantiation.cpp Modified: cfe/trunk/include/clang/Frontend/VerifyDiagnosticConsumer.h cfe/trunk/lib/Frontend/VerifyDiagnosticConsumer.cpp cfe/trunk/lib/Sema/SemaLookup.cpp Modified: cfe/trunk/include/clang/Frontend/VerifyDiagnosticConsumer.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/VerifyDiagnosticConsumer.h?rev=316055&r1=316054&r2=316055&view=diff == --- cfe/trunk/include/clang/Frontend/VerifyDiagnosticConsumer.h (original) +++ cfe/trunk/include/clang/Frontend/VerifyDiagnosticConsumer.h Tue Oct 17 18:41:38 2017 @@ -176,7 +176,8 @@ public: : DirectiveLoc(DirectiveLoc), DiagnosticLoc(DiagnosticLoc), Text(Text), Min(Min), Max(Max), MatchAnyLine(MatchAnyLine) { assert(!DirectiveLoc.isInvalid() && "DirectiveLoc is invalid!"); -assert(!DiagnosticLoc.isInvalid() && "DiagnosticLoc is invalid!"); +assert((!DiagnosticLoc.isInvalid() || MatchAnyLine) && + "DiagnosticLoc is invalid!"); } private: Modified: cfe/trunk/lib/Frontend/VerifyDiagnosticConsumer.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/VerifyDiagnosticConsumer.cpp?rev=316055&r1=316054&r2=316055&view=diff == --- cfe/trunk/lib/Frontend/VerifyDiagnosticConsumer.cpp (original) +++ cfe/trunk/lib/Frontend/VerifyDiagnosticConsumer.cpp Tue Oct 17 18:41:38 2017 @@ -416,9 +416,12 @@ static bool ParseDirective(StringRef S, MatchAnyLine = true; ExpectedLoc = SM.translateFileLineCol(FE, 1, 1); } + } else if (PH.Next("*")) { +MatchAnyLine = true; +ExpectedLoc = SourceLocation(); } - if (ExpectedLoc.isInvalid()) { + if (ExpectedLoc.isInvalid() && !MatchAnyLine) { Diags.Report(Pos.getLocWithOffset(PH.C-PH.Begin), diag::err_verify_missing_line) << KindStr; continue; @@ -650,7 +653,10 @@ static unsigned PrintExpected(Diagnostic llvm::raw_svector_ostream OS(Fmt); for (auto *DirPtr : DL) { Directive &D = *DirPtr; -OS << "\n File " << SourceMgr.getFilename(D.DiagnosticLoc); +if (D.DiagnosticLoc.isInvalid()) + OS << "\n File *"; +else + OS << "\n File " << SourceMgr.getFilename(D.DiagnosticLoc); if (D.MatchAnyLine) OS << " Line *"; else @@ -708,7 +714,8 @@ static unsigned CheckLists(DiagnosticsEn continue; } -if (!IsFromSameFile(SourceMgr, D.DiagnosticLoc, II->first)) +if (!D.DiagnosticLoc.isInvalid() && +!IsFromSameFile(SourceMgr, D.DiagnosticLoc, II->first)) continue; const std::string &RightText = II->second; Modified: cfe/trunk/lib/Sema/SemaLookup.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=316055&r1=316054&r2=316055&view=diff == --- cfe/trunk/lib/Sema/SemaLookup.cpp (original) +++ cfe/trunk/lib/Sema/SemaLookup.cpp Tue Oct 17 18:41:38 2017 @@ -1374,7 +1374,7 @@ static Module *getDefiningModule(Sema &S // Walk up to the containing context. That might also have been instantiated // from a template. - DeclContext *Context = Entity->getDeclContext(); + DeclContext *Context = Entity->getLexicalDeclContext(); if (Context->isFileContext()) return S.getOwningModule(Entity); return getDefiningModule(S, cast(Context)); Added: cfe/trunk/test/Modules/visibility-in-instantiation.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/visibility-in-instantiation.cpp?rev=316055&view=auto == --- cfe/trunk/test/Modules/visibility-in-instantiation.cpp (added) +++ cfe/trunk/test/Modules/visibility-in-instantiation.cpp Tue Oct 17 18:41:38 2017 @@ -0,0 +1,51 @@ +// RUN: %clang_cc1 -std=c++11 -fmodules %s -verify + +#pragma clang module build M + module M { module A {} module B {} module C {} } +#pragma clang module contents + + #pragma clang module begin M.A +template struct X { + template void f(); +}; + #pragma clang module end + + #pragma clang module begin M.B +template struct ST { static void f(); }; + #pragma clang module end + + #pragma clang module begin M.C +template struct X; +void foo(X); + #pragma clang module end +#pragma clang module endbuild + +#pragma clang module build N + module N {} +#pragma clang module contents + #pragma clang module
r316056 - Provide a flag group to turn on/off all "binary literals" extension warnings.
Author: rsmith Date: Tue Oct 17 19:19:24 2017 New Revision: 316056 URL: http://llvm.org/viewvc/llvm-project?rev=316056&view=rev Log: Provide a flag group to turn on/off all "binary literals" extension warnings. Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td cfe/trunk/test/SemaCXX/cxx98-compat-flags.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=316056&r1=316055&r2=316056&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Tue Oct 17 19:19:24 2017 @@ -32,7 +32,11 @@ def Availability : DiagGroup<"availabili def Section : DiagGroup<"section">; def AutoImport : DiagGroup<"auto-import">; def CXX14BinaryLiteral : DiagGroup<"c++14-binary-literal">; +def CXXPre14CompatBinaryLiteral : DiagGroup<"c++98-c++11-compat-binary-literal">; def GNUBinaryLiteral : DiagGroup<"gnu-binary-literal">; +def BinaryLiteral : DiagGroup<"binary-literal", [CXX14BinaryLiteral, + CXXPre14CompatBinaryLiteral, + GNUBinaryLiteral]>; def GNUCompoundLiteralInitializer : DiagGroup<"gnu-compound-literal-initializer">; def BitFieldConstantConversion : DiagGroup<"bitfield-constant-conversion">; def BitFieldEnumConversion : DiagGroup<"bitfield-enum-conversion">; @@ -166,7 +170,8 @@ def NoexceptType : DiagGroup<"noexcept-t // Warnings for C++1y code which is not compatible with prior C++ standards. def CXXPre14Compat : DiagGroup<"c++98-c++11-compat">; def CXXPre14CompatPedantic : DiagGroup<"c++98-c++11-compat-pedantic", - [CXXPre14Compat]>; + [CXXPre14Compat, +CXXPre14CompatBinaryLiteral]>; def CXXPre17Compat : DiagGroup<"c++98-c++11-c++14-compat">; def CXXPre17CompatPedantic : DiagGroup<"c++98-c++11-c++14-compat-pedantic", [CXXPre17Compat]>; Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=316056&r1=316055&r2=316056&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Tue Oct 17 19:19:24 2017 @@ -192,7 +192,7 @@ def ext_binary_literal_cxx14 : Extension "binary integer literals are a C++14 extension">, InGroup; def warn_cxx11_compat_binary_literal : Warning< "binary integer literals are incompatible with C++ standards before C++14">, - InGroup, DefaultIgnore; + InGroup, DefaultIgnore; def err_pascal_string_too_long : Error<"Pascal string is too long">; def err_escape_too_large : Error< "%select{hex|octal}0 escape sequence out of range">; Modified: cfe/trunk/test/SemaCXX/cxx98-compat-flags.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx98-compat-flags.cpp?rev=316056&r1=316055&r2=316056&view=diff == --- cfe/trunk/test/SemaCXX/cxx98-compat-flags.cpp (original) +++ cfe/trunk/test/SemaCXX/cxx98-compat-flags.cpp Tue Oct 17 19:19:24 2017 @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wc++98-compat-pedantic -verify %s -// RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wc++98-compat-pedantic -Wno-bind-to-temporary-copy -Wno-unnamed-type-template-args -Wno-local-type-template-args -Werror %s +// RUN: %clang_cc1 -fsyntax-only -std=c++17 -Wc++98-compat-pedantic -verify %s +// RUN: %clang_cc1 -fsyntax-only -std=c++17 -Wc++98-compat-pedantic -Wno-bind-to-temporary-copy -Wno-unnamed-type-template-args -Wno-local-type-template-args -Wno-binary-literal -Werror %s template int TemplateFn(T) { return 0; } void LocalTemplateArg() { @@ -32,4 +32,6 @@ namespace CopyCtorIssues { const NoViable &b = NoViable(); // expected-warning {{copying variable of type 'CopyCtorIssues::NoViable' when binding a reference to a temporary would find no viable constructor in C++98}} const Ambiguous &c = Ambiguous(); // expected-warning {{copying variable of type 'CopyCtorIssues::Ambiguous' when binding a reference to a temporary would find ambiguous constructors in C++98}} const Deleted &d = Deleted(); // expected-warning {{copying variable of type 'CopyCtorIssues::Deleted' when binding a reference to a temporary would invoke a deleted constructor in C++98}} + + int n = 0b00100101001; // expected-warning {{binary integer literals are incompatible with C++ standards before C++14}} } ___ cfe-commits mailing list cfe-commits@li
r316136 - Don't suppress instantiation of definitions for variables subject to explicit
Author: rsmith Date: Wed Oct 18 15:45:01 2017 New Revision: 316136 URL: http://llvm.org/viewvc/llvm-project?rev=316136&view=rev Log: Don't suppress instantiation of definitions for variables subject to explicit instantiation declarations if they are usable from constant expressions. We are permitted to instantiate in these cases, and required to do so in order to have an initializer available for use within constant evaluation. Added: cfe/trunk/test/SemaTemplate/cxx17-inline-variables.cpp Modified: cfe/trunk/lib/Sema/SemaExpr.cpp cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp cfe/trunk/test/CodeGenCXX/dllimport-members.cpp cfe/trunk/test/SemaTemplate/extern-templates.cpp Modified: cfe/trunk/lib/Sema/SemaExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=316136&r1=316135&r2=316136&view=diff == --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) +++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Oct 18 15:45:01 2017 @@ -14823,9 +14823,10 @@ static void DoMarkVarDeclReferenced(Sema TemplateSpecializationKind TSK = Var->getTemplateSpecializationKind(); bool OdrUseContext = isOdrUseContext(SemaRef); + bool UsableInConstantExpr = + Var->isUsableInConstantExpressions(SemaRef.Context); bool NeedDefinition = - OdrUseContext || (isEvaluatableContext(SemaRef) && -Var->isUsableInConstantExpressions(SemaRef.Context)); + OdrUseContext || (isEvaluatableContext(SemaRef) && UsableInConstantExpr); VarTemplateSpecializationDecl *VarSpec = dyn_cast(Var); @@ -14844,14 +14845,19 @@ static void DoMarkVarDeclReferenced(Sema // instantiations of variable templates, except for those that could be used // in a constant expression. if (NeedDefinition && isTemplateInstantiation(TSK)) { -bool TryInstantiating = TSK == TSK_ImplicitInstantiation; +// Per C++17 [temp.explicit]p10, we may instantiate despite an explicit +// instantiation declaration if a variable is usable in a constant +// expression (among other cases). +bool TryInstantiating = +TSK == TSK_ImplicitInstantiation || +(TSK == TSK_ExplicitInstantiationDeclaration && UsableInConstantExpr); if (TryInstantiating && !isa(Var)) { if (Var->getPointOfInstantiation().isInvalid()) { // This is a modification of an existing AST node. Notify listeners. if (ASTMutationListener *L = SemaRef.getASTMutationListener()) L->StaticDataMemberInstantiated(Var); - } else if (!Var->isUsableInConstantExpressions(SemaRef.Context)) + } else if (!UsableInConstantExpr) // Don't bother trying to instantiate it again, unless we might need // its initializer before we get to the end of the TU. TryInstantiating = false; @@ -14870,7 +14876,7 @@ static void DoMarkVarDeclReferenced(Sema // Do not instantiate specializations that are still type-dependent. if (IsNonDependent) { -if (Var->isUsableInConstantExpressions(SemaRef.Context)) { +if (UsableInConstantExpr) { // Do not defer instantiations of variables which could be used in a // constant expression. SemaRef.InstantiateVariableDefinition(PointOfInstantiation, Var); Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=316136&r1=316135&r2=316136&view=diff == --- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Wed Oct 18 15:45:01 2017 @@ -4359,10 +4359,12 @@ void Sema::InstantiateVariableDefinition return; // C++11 [temp.explicit]p10: - // Except for inline functions, [...] explicit instantiation declarations + // Except for inline functions, const variables of literal types, variables + // of reference types, [...] explicit instantiation declarations // have the effect of suppressing the implicit instantiation of the entity // to which they refer. - if (TSK == TSK_ExplicitInstantiationDeclaration) + if (TSK == TSK_ExplicitInstantiationDeclaration && + !Var->isUsableInConstantExpressions(getASTContext())) return; // Make sure to pass the instantiated variable to the consumer at the end. Modified: cfe/trunk/test/CodeGenCXX/dllimport-members.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dllimport-members.cpp?rev=316136&r1=316135&r2=316136&view=diff == --- cfe/trunk/test/CodeGenCXX/dllimport-members.cpp (original) +++ cfe/trunk/test/CodeGenCXX/dllimport-members.cpp Wed Oct 18 15:45:01 2017 @@ -836,7 +836,7 @@ USEMV(MemVarTmpl, ImportedStaticVar; USEMV(MemVarTmpl, ImportedStaticVar) @@ -861,7 +861,7
r316195 - Revert r316193.
Author: rsmith Date: Thu Oct 19 17:25:07 2017 New Revision: 316195 URL: http://llvm.org/viewvc/llvm-project?rev=316195&view=rev Log: Revert r316193. This patch breaks users using -fno-canonical-prefixes, for whom resolving symlinks is not acceptable. Removed: cfe/trunk/test/Preprocessor/dependencies-realpath.c Modified: cfe/trunk/include/clang/Driver/Options.td cfe/trunk/include/clang/Frontend/DependencyOutputOptions.h cfe/trunk/lib/Driver/Job.cpp cfe/trunk/lib/Driver/ToolChains/Clang.cpp cfe/trunk/lib/Frontend/CompilerInvocation.cpp cfe/trunk/lib/Frontend/DependencyFile.cpp cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp Modified: cfe/trunk/include/clang/Driver/Options.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=316195&r1=316194&r2=316195&view=diff == --- cfe/trunk/include/clang/Driver/Options.td (original) +++ cfe/trunk/include/clang/Driver/Options.td Thu Oct 19 17:25:07 2017 @@ -384,11 +384,6 @@ def MT : JoinedOrSeparate<["-"], "MT">, HelpText<"Specify name of main file output in depfile">; def MV : Flag<["-"], "MV">, Group, Flags<[CC1Option]>, HelpText<"Use NMake/Jom format for the depfile">; -def fno_canonical_system_headers : Flag<["-"], "fno-canonical-system-headers">, -Group, Flags<[CC1Option]>, -HelpText<"Do not shorten system header paths in depfiles">; -def fcanonical_system_headers : Flag<["-"], "fcanonical-system-headers">, -Group; def Mach : Flag<["-"], "Mach">, Group; def O0 : Flag<["-"], "O0">, Group, Flags<[CC1Option, HelpHidden]>; def O4 : Flag<["-"], "O4">, Group, Flags<[CC1Option, HelpHidden]>; Modified: cfe/trunk/include/clang/Frontend/DependencyOutputOptions.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/DependencyOutputOptions.h?rev=316195&r1=316194&r2=316195&view=diff == --- cfe/trunk/include/clang/Frontend/DependencyOutputOptions.h (original) +++ cfe/trunk/include/clang/Frontend/DependencyOutputOptions.h Thu Oct 19 17:25:07 2017 @@ -30,8 +30,6 @@ public: unsigned AddMissingHeaderDeps : 1; ///< Add missing headers to dependency list unsigned PrintShowIncludes : 1; ///< Print cl.exe style /showIncludes info. unsigned IncludeModuleFiles : 1; ///< Include module file dependencies. - unsigned CanonicalSystemHeaders : 1; ///< Try to output a shorter path for - /// system header dependencies. /// The format for the dependency file. DependencyOutputFormat OutputFormat; @@ -69,7 +67,6 @@ public: AddMissingHeaderDeps = 0; PrintShowIncludes = 0; IncludeModuleFiles = 0; -CanonicalSystemHeaders = 1; OutputFormat = DependencyOutputFormat::Make; } }; Modified: cfe/trunk/lib/Driver/Job.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Job.cpp?rev=316195&r1=316194&r2=316195&view=diff == --- cfe/trunk/lib/Driver/Job.cpp (original) +++ cfe/trunk/lib/Driver/Job.cpp Thu Oct 19 17:25:07 2017 @@ -73,8 +73,8 @@ static bool skipArgs(const char *Flag, b // These flags are all of the form -Flag and have no second argument. ShouldSkip = llvm::StringSwitch(Flag) -.Cases("-M", "-MM", "-MG", "-MP", "-MD", "-MMD", true) -.Cases("-fno-canonical-system-headers", "-fcanonical-system-headers", true) +.Cases("-M", "-MM", "-MG", "-MP", "-MD", true) +.Case("-MMD", true) .Default(false); // Match found. Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=316195&r1=316194&r2=316195&view=diff == --- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original) +++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Thu Oct 19 17:25:07 2017 @@ -964,13 +964,6 @@ void Clang::AddPreprocessingOptions(Comp Args.AddLastArg(CmdArgs, options::OPT_C); Args.AddLastArg(CmdArgs, options::OPT_CC); - if (Arg *A = Args.getLastArg(options::OPT_fno_canonical_system_headers, - options::OPT_fcanonical_system_headers)) { -if (A->getOption().matches(options::OPT_fno_canonical_system_headers)) { - CmdArgs.push_back("-fno-canonical-system-headers"); -} - } - // Handle dependency file generation. if ((A = Args.getLastArg(options::OPT_M, options::OPT_MM)) || (A = Args.getLastArg(options::OPT_MD)) || Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=316195&r1=316194&r2=316195&view=diff == --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original) +++ cfe/trunk/lib/Frontend/C
r316245 - Implement current CWG direction for support of arrays of unknown bounds in
Author: rsmith Date: Fri Oct 20 15:56:25 2017 New Revision: 316245 URL: http://llvm.org/viewvc/llvm-project?rev=316245&view=rev Log: Implement current CWG direction for support of arrays of unknown bounds in constant expressions. We permit array-to-pointer decay on such arrays, but disallow pointer arithmetic (since we do not know whether it will have defined behavior). This is based on r311970 and r301822 (the former by me and the latter by Robert Haberlach). Between then and now, two things have changed: we have committee feedback indicating that this is indeed the right direction, and the code broken by this change has been fixed. This is necessary in C++17 to continue accepting certain forms of non-type template argument involving arrays of unknown bound. Added: cfe/trunk/test/SemaCXX/constexpr-array-unknown-bound.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td cfe/trunk/include/clang/Basic/DiagnosticIDs.h cfe/trunk/lib/AST/ExprConstant.cpp cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp cfe/trunk/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td?rev=316245&r1=316244&r2=316245&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td Fri Oct 20 15:56:25 2017 @@ -127,6 +127,10 @@ def note_constexpr_access_null : Note< def note_constexpr_access_past_end : Note< "%select{read of|assignment to|increment of|decrement of}0 " "dereferenced one-past-the-end pointer is not allowed in a constant expression">; +def note_constexpr_access_unsized_array : Note< + "%select{read of|assignment to|increment of|decrement of}0 " + "pointer to element of array without known bound " + "is not allowed in a constant expression">; def note_constexpr_access_inactive_union_member : Note< "%select{read of|assignment to|increment of|decrement of}0 " "member %1 of union with %select{active member %3|no active member}2 " @@ -154,6 +158,11 @@ def note_constexpr_baa_insufficient_alig def note_constexpr_baa_value_insufficient_alignment : Note< "value of the aligned pointer (%0) is not a multiple of the asserted %1 " "%plural{1:byte|:bytes}1">; +def note_constexpr_unsupported_unsized_array : Note< + "array-to-pointer decay of array member without known bound is not supported">; +def note_constexpr_unsized_array_indexed : Note< + "indexing of array without known bound is not allowed " + "in a constant expression">; def warn_integer_constant_overflow : Warning< "overflow in expression; result is %0 with type %1">, Modified: cfe/trunk/include/clang/Basic/DiagnosticIDs.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticIDs.h?rev=316245&r1=316244&r2=316245&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticIDs.h (original) +++ cfe/trunk/include/clang/Basic/DiagnosticIDs.h Fri Oct 20 15:56:25 2017 @@ -34,7 +34,7 @@ namespace clang { DIAG_SIZE_SERIALIZATION = 120, DIAG_SIZE_LEX = 400, DIAG_SIZE_PARSE = 500, - DIAG_SIZE_AST = 110, + DIAG_SIZE_AST = 150, DIAG_SIZE_COMMENT = 100, DIAG_SIZE_CROSSTU = 100, DIAG_SIZE_SEMA = 3500, Modified: cfe/trunk/lib/AST/ExprConstant.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=316245&r1=316244&r2=316245&view=diff == --- cfe/trunk/lib/AST/ExprConstant.cpp (original) +++ cfe/trunk/lib/AST/ExprConstant.cpp Fri Oct 20 15:56:25 2017 @@ -62,7 +62,13 @@ namespace { static QualType getType(APValue::LValueBase B) { if (!B) return QualType(); if (const ValueDecl *D = B.dyn_cast()) - return D->getType(); + // FIXME: It's unclear where we're supposed to take the type from, and + // this actually matters for arrays of unknown bound. Using the type of + // the most recent declaration isn't clearly correct in general. Eg: + // + // extern int arr[]; void f() { extern int arr[3]; }; + // constexpr int *p = &arr[1]; // valid? + return cast(D->getMostRecentDecl())->getType(); const Expr *Base = B.get(); @@ -141,6 +147,12 @@ namespace { return E && E->getType()->isPointerType() && tryUnwrapAllocSizeCall(E); } + /// The bound to claim that an array of unknown bound has. + /// The value in MostDerivedArraySize is undefined in this case. So, set it + /// to an arbitrary value that's likely to loudly break things if it's used. + static const uint64_t AssumedSizeForUnsizedArray = + std::numeric_limits::max() / 2; + /// Dete
r316310 - For better compatibility with C++11 and C++14, emit a nondiscardable definition
Author: rsmith Date: Sun Oct 22 20:58:34 2017 New Revision: 316310 URL: http://llvm.org/viewvc/llvm-project?rev=316310&view=rev Log: For better compatibility with C++11 and C++14, emit a nondiscardable definition of a static constexpr data member if it's defined 'constexpr' out of line, not only if it's defined 'constexpr' in the class. Modified: cfe/trunk/lib/AST/ASTContext.cpp cfe/trunk/test/CodeGenCXX/cxx1z-inline-variables.cpp Modified: cfe/trunk/lib/AST/ASTContext.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=316310&r1=316309&r2=316310&view=diff == --- cfe/trunk/lib/AST/ASTContext.cpp (original) +++ cfe/trunk/lib/AST/ASTContext.cpp Sun Oct 22 20:58:34 2017 @@ -5635,14 +5635,14 @@ ASTContext::getInlineVariableDefinitionK // In almost all cases, it's a weak definition. auto *First = VD->getFirstDecl(); - if (!First->isConstexpr() || First->isInlineSpecified() || - !VD->isStaticDataMember()) + if (First->isInlineSpecified() || !First->isStaticDataMember()) return InlineVariableDefinitionKind::Weak; // If there's a file-context declaration in this translation unit, it's a // non-discardable definition. for (auto *D : VD->redecls()) -if (D->getLexicalDeclContext()->isFileContext()) +if (D->getLexicalDeclContext()->isFileContext() && +!D->isInlineSpecified() && (D->isConstexpr() || First->isConstexpr())) return InlineVariableDefinitionKind::Strong; // If we've not seen one yet, we don't know. Modified: cfe/trunk/test/CodeGenCXX/cxx1z-inline-variables.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/cxx1z-inline-variables.cpp?rev=316310&r1=316309&r2=316310&view=diff == --- cfe/trunk/test/CodeGenCXX/cxx1z-inline-variables.cpp (original) +++ cfe/trunk/test/CodeGenCXX/cxx1z-inline-variables.cpp Sun Oct 22 20:58:34 2017 @@ -31,18 +31,28 @@ struct compat { static constexpr int b = 2; static constexpr int c = 3; static inline constexpr int d = 4; + static const int e = 5; + static const int f = 6; + static const int g = 7; }; const int &compat_use_before_redecl = compat::b; const int compat::a; const int compat::b; const int compat::c; const int compat::d; +const int compat::e; +constexpr int compat::f; +constexpr inline int compat::g; const int &compat_use_after_redecl1 = compat::c; const int &compat_use_after_redecl2 = compat::d; -// CHECK: @_ZN6compat1bE = weak_odr constant i32 2 -// CHECK: @_ZN6compat1aE = weak_odr constant i32 1 -// CHECK: @_ZN6compat1cE = weak_odr constant i32 3 -// CHECK: @_ZN6compat1dE = linkonce_odr constant i32 4 +const int &compat_use_after_redecl3 = compat::g; +// CHECK-DAG: @_ZN6compat1bE = weak_odr constant i32 2 +// CHECK-DAG: @_ZN6compat1aE = weak_odr constant i32 1 +// CHECK-DAG: @_ZN6compat1cE = weak_odr constant i32 3 +// CHECK-DAG: @_ZN6compat1dE = linkonce_odr constant i32 4 +// CHECK-DAG: @_ZN6compat1eE = constant i32 5 +// CHECK-DAG: @_ZN6compat1fE = weak_odr constant i32 6 +// CHECK-DAG: @_ZN6compat1gE = linkonce_odr constant i32 7 template struct X { static int a; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r314872 - We allow implicit function declarations as an extension in all C dialects. Remove OpenCL special case.
for my PDP-11, then I should be allowed to do that > (assuming I have a suitable LLVM backend), and that target presumably would > support variadic functions just fine.] Likewise, if the target doesn't > support variadic functions, we should not be generating variadic function > types when producing IR (particularly in calls to non-variadic functions > like in your example elsewhere in this thread). This is true regardless of > whether the source language is OpenCL or C89 or C++ or anything else. > > It is a goal of Clang to allow its various features to be used together, > including combining them in ways that we didn't think of. The particular > case of implicit function declarations is not especially important in and > of itself, but the underlying principle is: the OpenCL language mode of > Clang should not disable other Clang extensions unless there's some > fundamental reason why they are incompatible. > > Consider this: we allow implicit function declarations in languages based > on C in order to allow C89 code (or code that started as C89 code) to be > built unchanged in those languages. That applies to OpenCL and Objective-C > as much as it applies to C99 and C11. (It doesn't apply to C++ because > there is no such thing as an unprototyped function in C++'s type system.) > > > From: Richard Smith > Sent: 21 August 2018 22:09:35 > To: Anastasia Stulova > Cc: cfe-commits; nd > Subject: Re: r314872 - We allow implicit function declarations as an > extension in all C dialects. Remove OpenCL special case. > > On Tue, 21 Aug 2018 at 07:41, Anastasia Stulova via cfe-commits < > cfe-commits@lists.llvm.org<mailto:cfe-commits@lists.llvm.org>> wrote: > > If there are no objections I would like to revert this old commit that > coverts error about implicit function declaration into a warning. > > > We have decided to generate an error for this > https://reviews.llvm.org/D31745 because for OpenCL variadic prototypes > are disallowed (section 6.9.e, > https://www.khronos.org/registry/OpenCL/specs/opencl-2.0-openclc.pdf) and > the implicit prototype requires variadic support. > > This is incorrect. Implicit function declarations declare unprototyped > functions, which are *not* variadic, and are in fact supported by Clang's > OpenCL language mode. > > See C90 6.5.4.3 Semantics, last paragraph, and 6.3.2.2 Semantics, second > paragraph. > > So that argument does not appear to apply. The reason we accept > implicitly-declared functions outside of our C89 mode is because this is an > explicit, supported Clang extension. Generally, Clang intends to support > using all of its extensions together, unless there is some fundamental > reason why they cannot be combined. So, just as it doesn't make sense for > our OpenCL language mode to conflict with, say, AltiVec vector extensions, > it doesn't make sense for the OpenCL language mode to conflict with our > implicitly-declared functions extension. > > I would have sympathy for your position if we did not produce an extension > warning on this construct by default. But we do, and it says the construct > is invalid in OpenCL; moreover, in our strict conformance mode > (-pedantic-errors), we reject the code. > > As most vendors that support OpenCL don't support variadic functions it > was decided to restrict this explicitly in the spec (section s6.9.u). There > is a little bit of more history in https://reviews.llvm.org/D17438. > > > Currently the code that can't run correctly on most OpenCL targets > compiles successfully. The problem can't be easily seen by the OpenCL > developers since it's not very common to retrieve the compilation warning > log during online compilation. Also generated IR doesn't seem to be correct > if I compare with the similar code in C. > > Example: > 1 typedef long long16 __attribute__((ext_vector_type(16))); > 2 void test_somefunc( __global int *d, __global void *s ) > 3 { > 4 int i = get_global_id(0); > 5 d[i] = somefunc((( __global long16 *)s)[i]); > 6 } > > Is generated to: > > %call1 = call i32 (<16 x i64>*, ...) bitcast (i32 ()* @somefunc to i32 > (<16 x i64>*, ...)*)(<16 x i64>* byval nonnull align 128 > %indirect-arg-temp) #2 > ... > > declare i32 @somefunc() local_unnamed_addr #1 > > Equivalent C code at least generates variadic function prototype correctly: > > %call1 = call i32 (<16 x i64>*, ...) bitcast (i32 (...)* @somefunc to i32 > (<16 x i64>*, ...)*)(<16 x i64>* byval align 128 %indirect-arg-temp) > ... > declare i32 @somefunc(...) > > Anastasia >
[libcxxabi] r340671 - Port my recent changes from LLVM copy of the demangler:
Author: rsmith Date: Fri Aug 24 16:30:26 2018 New Revision: 340671 URL: http://llvm.org/viewvc/llvm-project?rev=340671&view=rev Log: Port my recent changes from LLVM copy of the demangler: r340663 - Allow Allocator::make to make a node of a different type than that requested. r340664 - Add documentation comment to ForwardTemplateReference. r340665 - Fix ExpandedSpecialSubstitution demangling for Sa and Sb. r340670 - Allow demangler's node allocator to fail, and bail out of the entire demangling process when it does. Modified: libcxxabi/trunk/src/demangle/ItaniumDemangle.h Modified: libcxxabi/trunk/src/demangle/ItaniumDemangle.h URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/demangle/ItaniumDemangle.h?rev=340671&r1=340670&r2=340671&view=diff == --- libcxxabi/trunk/src/demangle/ItaniumDemangle.h (original) +++ libcxxabi/trunk/src/demangle/ItaniumDemangle.h Fri Aug 24 16:30:26 2018 @@ -1123,6 +1123,24 @@ public: } }; +/// A forward-reference to a template argument that was not known at the point +/// where the template parameter name was parsed in a mangling. +/// +/// This is created when demangling the name of a specialization of a +/// conversion function template: +/// +/// \code +/// struct A { +/// template operator T*(); +/// }; +/// \endcode +/// +/// When demangling a specialization of the conversion function template, we +/// encounter the name of the template (including the \c T) before we reach +/// the template argument list, so we cannot substitute the parameter name +/// for the corresponding argument while parsing. Instead, we create a +/// \c ForwardTemplateReference node that is resolved after we parse the +/// template arguments. struct ForwardTemplateReference : Node { size_t Index; Node *Ref = nullptr; @@ -1271,10 +1289,11 @@ public: void printLeft(OutputStream &S) const override { switch (SSK) { case SpecialSubKind::allocator: - S += "std::basic_string, " - "std::allocator >"; + S += "std::allocator"; break; case SpecialSubKind::basic_string: + S += "std::basic_string"; + break; case SpecialSubKind::string: S += "std::basic_string, " "std::allocator >"; @@ -2165,7 +2184,7 @@ struct Db { ASTAllocator.reset(); } - template T *make(Args &&... args) { + template Node *make(Args &&... args) { return ASTAllocator.template makeNode(std::forward(args)...); } @@ -2358,7 +2377,10 @@ template Node *Db if (consumeIf('s')) { First = parse_discriminator(First, Last); -return make(Encoding, make("string literal")); +auto *StringLitName = make("string literal"); +if (!StringLitName) + return nullptr; +return make(Encoding, StringLitName); } if (consumeIf('d')) { @@ -2772,6 +2794,8 @@ Node *Db::parseCtorDtorName(Node case SpecialSubKind::ostream: case SpecialSubKind::iostream: SoFar = make(SSK); + if (!SoFar) +return nullptr; default: break; } @@ -2833,13 +2857,18 @@ template Node *Db Node *SoFar = nullptr; auto PushComponent = [&](Node *Comp) { +if (!Comp) return false; if (SoFar) SoFar = make(SoFar, Comp); else SoFar = Comp; if (State) State->EndsWithTemplateArgs = false; +return SoFar != nullptr; }; - if (consumeIf("St")) + if (consumeIf("St")) { SoFar = make("std"); +if (!SoFar) + return nullptr; + } while (!consumeIf('E')) { consumeIf('L'); // extension @@ -2853,10 +2882,8 @@ template Node *Db // ::= if (look() == 'T') { - Node *TP = parseTemplateParam(); - if (TP == nullptr) + if (!PushComponent(parseTemplateParam())) return nullptr; - PushComponent(TP); Subs.push_back(SoFar); continue; } @@ -2867,6 +2894,8 @@ template Node *Db if (TA == nullptr || SoFar == nullptr) return nullptr; SoFar = make(SoFar, TA); + if (!SoFar) +return nullptr; if (State) State->EndsWithTemplateArgs = true; Subs.push_back(SoFar); continue; @@ -2874,10 +2903,8 @@ template Node *Db // ::= if (look() == 'D' && (look(1) == 't' || look(1) == 'T')) { - Node *DT = parseDecltype(); - if (DT == nullptr) + if (!PushComponent(parseDecltype())) return nullptr; - PushComponent(DT); Subs.push_back(SoFar); continue; } @@ -2885,9 +2912,8 @@ template Node *Db // ::= if (look() == 'S' && look(1) != 't') { Node *S = parseSubstitution(); - if (S == nullptr) + if (!PushComponent(S)) return nullptr; - PushComponent(S); if (SoFar != S) Subs.push_back(S); continue; @@ -2897,10 +2923,8 @@ template Node *Db if (look() == 'C' || (look() == 'D' && look(1) != 'C')) { if (SoFar == nullptr)
[libcxx] r340778 - Fix ODR violation: namespace-scope helpers should not be declared 'static'.
Author: rsmith Date: Mon Aug 27 14:41:50 2018 New Revision: 340778 URL: http://llvm.org/viewvc/llvm-project?rev=340778&view=rev Log: Fix ODR violation: namespace-scope helpers should not be declared 'static'. Modified: libcxx/trunk/include/variant Modified: libcxx/trunk/include/variant URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/variant?rev=340778&r1=340777&r2=340778&view=diff == --- libcxx/trunk/include/variant (original) +++ libcxx/trunk/include/variant Mon Aug 27 14:41:50 2018 @@ -1320,7 +1320,7 @@ constexpr bool holds_alternative(const v template inline _LIBCPP_INLINE_VISIBILITY -static constexpr auto&& __generic_get(_Vp&& __v) { +constexpr auto&& __generic_get(_Vp&& __v) { using __variant_detail::__access::__variant; if (!__holds_alternative<_Ip>(__v)) { __throw_bad_variant_access(); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r341009 - Adjust Attr representation so that changes to documentation don't affect
Author: rsmith Date: Wed Aug 29 18:01:07 2018 New Revision: 341009 URL: http://llvm.org/viewvc/llvm-project?rev=341009&view=rev Log: Adjust Attr representation so that changes to documentation don't affect how we parse source code. Instead of implicitly opting all undocumented attributes out of '#pragma clang attribute' support, explicitly opt them all out and remove the documentation check from TableGen. (No new attributes should be added without documentation, so this has little chance of backsliding. We already support the pragma on one undocumented attribute, so we don't even want to enforce our old "rule".) No functionality change intended. Modified: cfe/trunk/include/clang/Basic/Attr.td cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp Modified: cfe/trunk/include/clang/Basic/Attr.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=341009&r1=341008&r2=341009&view=diff == --- cfe/trunk/include/clang/Basic/Attr.td (original) +++ cfe/trunk/include/clang/Basic/Attr.td Wed Aug 29 18:01:07 2018 @@ -473,13 +473,12 @@ class Attr { // in a class template definition. bit MeaningfulToClassTemplateDefinition = 0; // Set to true if this attribute can be used with '#pragma clang attribute'. - // By default, when this value is false, an attribute is supported by the - // '#pragma clang attribute' only when: - // - It has documentation. + // By default, an attribute is supported by the '#pragma clang attribute' + // only when: // - It has a subject list whose subjects can be represented using subject // match rules. // - It has GNU/CXX11 spelling and doesn't require delayed parsing. - bit ForcePragmaAttributeSupport = 0; + bit PragmaAttributeSupport; // Lists language options, one of which is required to be true for the // attribute to be applicable. If empty, no language options are required. list LangOpts = []; @@ -546,6 +545,7 @@ class IgnoredAttr : Attr { let ASTNode = 0; let SemaHandler = 0; let Documentation = [Undocumented]; + let PragmaAttributeSupport = 0; } // @@ -564,6 +564,7 @@ def AddressSpace : TypeAttr { let Spellings = [Clang<"address_space">]; let Args = [IntArgument<"AddressSpace">]; let Documentation = [Undocumented]; + let PragmaAttributeSupport = 0; } def Alias : Attr { @@ -571,6 +572,7 @@ def Alias : Attr { let Args = [StringArgument<"Aliasee">]; let Subjects = SubjectList<[Function, GlobalVar], ErrorDiag>; let Documentation = [Undocumented]; + let PragmaAttributeSupport = 0; } def Aligned : InheritableAttr { @@ -583,6 +585,7 @@ def Aligned : InheritableAttr { Keyword<"_Alignas">]>, Accessor<"isDeclspec",[Declspec<"align">]>]; let Documentation = [Undocumented]; + let PragmaAttributeSupport = 0; } def AlignValue : Attr { @@ -610,12 +613,14 @@ def AlignMac68k : InheritableAttr { let Spellings = []; let SemaHandler = 0; let Documentation = [Undocumented]; + let PragmaAttributeSupport = 0; } def AlwaysInline : InheritableAttr { let Spellings = [GCC<"always_inline">, Keyword<"__forceinline">]; let Subjects = SubjectList<[Function]>; let Documentation = [Undocumented]; + let PragmaAttributeSupport = 0; } def Artificial : InheritableAttr { @@ -661,6 +666,7 @@ def AnalyzerNoReturn : InheritableAttr { // analyzer? let Spellings = [GNU<"analyzer_noreturn">]; let Documentation = [Undocumented]; + let PragmaAttributeSupport = 0; } def Annotate : InheritableParamAttr { @@ -668,7 +674,7 @@ def Annotate : InheritableParamAttr { let Args = [StringArgument<"Annotation">]; // Ensure that the annotate attribute can be used with // '#pragma clang attribute' even though it has no subject list. - let ForcePragmaAttributeSupport = 1; + let PragmaAttributeSupport = 1; let Documentation = [Undocumented]; } @@ -703,6 +709,7 @@ def AsmLabel : InheritableAttr { let Args = [StringArgument<"Label">]; let SemaHandler = 0; let Documentation = [Undocumented]; + let PragmaAttributeSupport = 0; } def Availability : InheritableAttr { @@ -769,6 +776,7 @@ def Blocks : InheritableAttr { let Spellings = [Clang<"blocks">]; let Args = [EnumArgument<"Type", "BlockType", ["byref"], ["ByRef"]>]; let Documentation = [Undocumented]; + let PragmaAttributeSupport = 0; } def Bounded : IgnoredAttr { @@ -787,6 +795,7 @@ def CDecl : DeclOrTypeAttr { let Spellings = [GCC<"cdecl">, Keyword<"__cdecl">, Keyword<"_cdecl">]; // let Subjects = [Function, ObjCMethod]; let Documentation = [Undocumented]; + let PragmaAttributeSupport = 0; } // cf_audited_transfer indicates that the given function has been @@ -797,6 +806,7 @@ def CFAuditedTransfer : InheritableAttr let Spellings = [Clang<"cf_audited_transfer">]; let Subjects = SubjectList<[Function], ErrorDiag>; let Documentation = [Un
r341098 - Add missing -Wc++11-compat / -Wc++14-compat warnings for:
Author: rsmith Date: Thu Aug 30 12:16:35 2018 New Revision: 341098 URL: http://llvm.org/viewvc/llvm-project?rev=341098&view=rev Log: Add missing -Wc++11-compat / -Wc++14-compat warnings for: * generic lambdas * return type deduction * class template argument deduction Added: cfe/trunk/test/SemaCXX/cxx11-compat.cpp - copied, changed from r341097, cfe/trunk/test/SemaCXX/cxx0x-compat.cpp Removed: cfe/trunk/test/SemaCXX/cxx0x-compat.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaInit.cpp cfe/trunk/lib/Sema/SemaType.cpp cfe/trunk/test/SemaCXX/cxx98-compat.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=341098&r1=341097&r2=341098&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Aug 30 12:16:35 2018 @@ -2143,8 +2143,11 @@ def note_deduction_guide_template_access "member template declared %0 here">; def note_deduction_guide_access : Note< "deduction guide declared %0 by intervening access specifier">; +def warn_cxx14_compat_class_template_argument_deduction : Warning< + "class template argument deduction is incompatible with C++ standards " + "before C++17">, InGroup, DefaultIgnore; -// C++1y deduced return types +// C++14 deduced return types def err_auto_fn_deduction_failure : Error< "cannot deduce return type %0 from returned value of type %1">; def err_auto_fn_different_deductions : Error< @@ -2160,6 +2163,9 @@ def err_auto_fn_return_init_list : Error "cannot deduce return type from initializer list">; def err_auto_fn_virtual : Error< "function with deduced return type cannot be virtual">; +def warn_cxx11_compat_deduced_return_type : Warning< + "return type deduction is incompatible with C++ standards before C++14">, + InGroup, DefaultIgnore; // C++11 override control def override_keyword_only_allowed_on_virtual_member_functions : Error< @@ -6576,6 +6582,11 @@ let CategoryName = "Lambda Issue" in { def err_init_capture_deduction_failure_from_init_list : Error< "cannot deduce type for lambda capture %0 from initializer list">; + // C++14 generic lambdas. + def warn_cxx11_compat_generic_lambda : Warning< +"generic lambdas are incompatible with C++11">, +InGroup, DefaultIgnore; + // C++17 '*this' captures. def warn_cxx14_compat_star_this_lambda_capture : Warning< "by value capture of '*this' is incompatible with C++ standards before C++17">, Modified: cfe/trunk/lib/Sema/SemaInit.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=341098&r1=341097&r2=341098&view=diff == --- cfe/trunk/lib/Sema/SemaInit.cpp (original) +++ cfe/trunk/lib/Sema/SemaInit.cpp Thu Aug 30 12:16:35 2018 @@ -9062,6 +9062,10 @@ QualType Sema::DeduceTemplateSpecializat return QualType(); } + Diag(TSInfo->getTypeLoc().getBeginLoc(), + diag::warn_cxx14_compat_class_template_argument_deduction) + << TSInfo->getTypeLoc().getSourceRange(); + // Can't deduce from dependent arguments. if (Expr::hasAnyTypeDependentArguments(Inits)) return Context.DependentTy; Modified: cfe/trunk/lib/Sema/SemaType.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=341098&r1=341097&r2=341098&view=diff == --- cfe/trunk/lib/Sema/SemaType.cpp (original) +++ cfe/trunk/lib/Sema/SemaType.cpp Thu Aug 30 12:16:35 2018 @@ -2887,6 +2887,7 @@ static QualType GetDeclSpecTypeForDeclar // class template argument deduction)? bool IsCXXAutoType = (Auto && Auto->getKeyword() != AutoTypeKeyword::GNUAutoType); +bool IsDeducedReturnType = false; switch (D.getContext()) { case DeclaratorContext::LambdaExprContext: @@ -2978,10 +2979,12 @@ static QualType GetDeclSpecTypeForDeclar case DeclaratorContext::TrailingReturnVarContext: if (!SemaRef.getLangOpts().CPlusPlus14 || !IsCXXAutoType) Error = 13; // Function return type + IsDeducedReturnType = true; break; case DeclaratorContext::ConversionIdContext: if (!SemaRef.getLangOpts().CPlusPlus14 || !IsCXXAutoType) Error = 14; // conversion-type-id + IsDeducedReturnType = true; break; case DeclaratorContext::FunctionalCastContext: if (isa(Deduced)) @@ -3066,10 +3069,14 @@ static QualType GetDeclSpecTypeForDeclar D.getContext() != DeclaratorContext::LambdaExprContext) { // If there was a trailing return type, we already got // warn_cxx98_compat_trailing_return_type in the parser. - // If this was a lambda, we already warned on that too.
r341097 - Improve attribute documentation to list which spellings are used in which syntaxes.
Author: rsmith Date: Thu Aug 30 12:16:33 2018 New Revision: 341097 URL: http://llvm.org/viewvc/llvm-project?rev=341097&view=rev Log: Improve attribute documentation to list which spellings are used in which syntaxes. Summary: Instead of listing all the spellings (including attribute namespaces) in the section heading, only list the actual attribute names there, and list the spellings in the supported syntaxes table. This allows us to properly describe things like [[fallthrough]], for which we allow a clang:: prefix in C++ but not in C, and AlwaysInline, which has one spelling as a GNU attribute and a different spelling as a keyword, without needing to repeat the syntax description in the documentation text. Sample rendering: https://pste.eu/p/T1ZV.html Reviewers: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D51473 Modified: cfe/trunk/include/clang/Basic/AttrDocs.td cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp Modified: cfe/trunk/include/clang/Basic/AttrDocs.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AttrDocs.td?rev=341097&r1=341096&r2=341097&view=diff == --- cfe/trunk/include/clang/Basic/AttrDocs.td (original) +++ cfe/trunk/include/clang/Basic/AttrDocs.td Thu Aug 30 12:16:33 2018 @@ -38,6 +38,10 @@ Attributes in Clang .. contents:: :local: +.. |br| raw:: html + + + Introduction @@ -51,7 +55,7 @@ def SectionDocs : Documentation { The ``section`` attribute allows you to specify a specific section a global variable or function should be in after translation. }]; - let Heading = "section (gnu::section, __declspec(allocate))"; + let Heading = "section, __declspec(allocate)"; } def InitSegDocs : Documentation { @@ -270,7 +274,7 @@ that appears to be capable of returning def AssertCapabilityDocs : Documentation { let Category = DocCatFunction; - let Heading = "assert_capability (assert_shared_capability, clang::assert_capability, clang::assert_shared_capability)"; + let Heading = "assert_capability, assert_shared_capability"; let Content = [{ Marks a function that dynamically tests whether a capability is held, and halts the program if it is not held. @@ -279,7 +283,7 @@ the program if it is not held. def AcquireCapabilityDocs : Documentation { let Category = DocCatFunction; - let Heading = "acquire_capability (acquire_shared_capability, clang::acquire_capability, clang::acquire_shared_capability)"; + let Heading = "acquire_capability, acquire_shared_capability"; let Content = [{ Marks a function as acquiring a capability. }]; @@ -287,7 +291,7 @@ Marks a function as acquiring a capabili def TryAcquireCapabilityDocs : Documentation { let Category = DocCatFunction; - let Heading = "try_acquire_capability (try_acquire_shared_capability, clang::try_acquire_capability, clang::try_acquire_shared_capability)"; + let Heading = "try_acquire_capability, try_acquire_shared_capability"; let Content = [{ Marks a function that attempts to acquire a capability. This function may fail to actually acquire the capability; they accept a Boolean value determining @@ -298,7 +302,7 @@ the capability means success (false). def ReleaseCapabilityDocs : Documentation { let Category = DocCatFunction; - let Heading = "release_capability (release_shared_capability, clang::release_capability, clang::release_shared_capability)"; + let Heading = "release_capability, release_shared_capability"; let Content = [{ Marks a function as releasing a capability. }]; @@ -1261,7 +1265,7 @@ of silently falling back on dynamic init def WarnMaybeUnusedDocs : Documentation { let Category = DocCatVariable; - let Heading = "maybe_unused, unused, gnu::unused"; + let Heading = "maybe_unused, unused"; let Content = [{ When passing the ``-Wunused`` flag to Clang, entities that are unused by the program may be diagnosed. The ``[[maybe_unused]]`` (or @@ -1287,7 +1291,7 @@ enumerator, a non-static data member, or def WarnUnusedResultsDocs : Documentation { let Category = DocCatFunction; - let Heading = "nodiscard, warn_unused_result, clang::warn_unused_result, gnu::warn_unused_result"; + let Heading = "nodiscard, warn_unused_result"; let Content = [{ Clang supports the ability to diagnose when the results of a function call expression are discarded under suspicious circumstances. A diagnostic is @@ -1312,7 +1316,7 @@ potentially-evaluated discarded-value ex def FallthroughDocs : Documentation { let Category = DocCatStmt; - let Heading = "fallthrough, clang::fallthrough"; + let Heading = "fallthrough"; let Content = [{ The ``fallthrough`` (or ``clang::fallthrough``) attribute is used to annotate intentional fall-through @@ -1460,7 +1464,7 @@ on the command line. def MipsLongCallStyleDocs : Documentation { let Category = DocCatFunction; - let Heading = "long_ca
r341099 - Add test file missed from r341097.
Author: rsmith Date: Thu Aug 30 12:17:11 2018 New Revision: 341099 URL: http://llvm.org/viewvc/llvm-project?rev=341099&view=rev Log: Add test file missed from r341097. Added: cfe/trunk/test/SemaCXX/cxx14-compat.cpp Added: cfe/trunk/test/SemaCXX/cxx14-compat.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx14-compat.cpp?rev=341099&view=auto == --- cfe/trunk/test/SemaCXX/cxx14-compat.cpp (added) +++ cfe/trunk/test/SemaCXX/cxx14-compat.cpp Thu Aug 30 12:17:11 2018 @@ -0,0 +1,34 @@ +// RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wc++14-compat-pedantic -verify %s +// RUN: %clang_cc1 -fsyntax-only -std=c++17 -Wc++14-compat-pedantic -verify %s + +#if __cplusplus < 201402L + +// expected-no-diagnostics +// FIXME: C++11 features removed or changed in C++14? + +#else + +static_assert(true); // expected-warning {{incompatible with C++ standards before C++17}} + +template int f() { return (N + ...); } // expected-warning {{incompatible with C++ standards before C++17}} + +namespace [[]] NS_with_attr {} // expected-warning {{incompatible with C++ standards before C++17}} +enum { e [[]] }; // expected-warning {{incompatible with C++ standards before C++17}} + +template struct X {}; +X x; // expected-warning {{class template argument deduction is incompatible with C++ standards before C++17}} + +template class> struct Y {}; +Y yx; // ok, not class template argument deduction + +template void f(T t) { + X x = t; // expected-warning {{incompatible}} +} + +template void g(T t) { + typename T::X x = t; // expected-warning {{incompatible}} +} +struct A { template struct X { X(T); }; }; +void h(A a) { g(a); } // expected-note {{in instantiation of}} + +#endif ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r341100 - Update FIXME as requested in code review.
Author: rsmith Date: Thu Aug 30 12:19:15 2018 New Revision: 341100 URL: http://llvm.org/viewvc/llvm-project?rev=341100&view=rev Log: Update FIXME as requested in code review. Modified: cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp Modified: cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp?rev=341100&r1=341099&r2=341100&view=diff == --- cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp (original) +++ cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp Thu Aug 30 12:19:15 2018 @@ -3878,7 +3878,8 @@ static void WriteDocumentation(RecordKee OS << " \""; for (size_t Kind = 0; Kind != NumSpellingKinds; ++Kind) { SpellingKind K = (SpellingKind)Kind; -// FIXME: Why are Microsoft spellings not listed? +// TODO: List Microsoft (IDL-style attribute) spellings once we fully +// support them. if (K == SpellingKind::Microsoft) continue; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r341099 - Add test file missed from r341097.
On Thu, 30 Aug 2018 at 12:18, Richard Smith via cfe-commits < cfe-commits@lists.llvm.org> wrote: > Author: rsmith > Date: Thu Aug 30 12:17:11 2018 > New Revision: 341099 > > URL: http://llvm.org/viewvc/llvm-project?rev=341099&view=rev > Log: > Add test file missed from r341097. > Sorry, typo, this should say r341098. > Added: > cfe/trunk/test/SemaCXX/cxx14-compat.cpp > > Added: cfe/trunk/test/SemaCXX/cxx14-compat.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx14-compat.cpp?rev=341099&view=auto > > == > --- cfe/trunk/test/SemaCXX/cxx14-compat.cpp (added) > +++ cfe/trunk/test/SemaCXX/cxx14-compat.cpp Thu Aug 30 12:17:11 2018 > @@ -0,0 +1,34 @@ > +// RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wc++14-compat-pedantic > -verify %s > +// RUN: %clang_cc1 -fsyntax-only -std=c++17 -Wc++14-compat-pedantic > -verify %s > + > +#if __cplusplus < 201402L > + > +// expected-no-diagnostics > +// FIXME: C++11 features removed or changed in C++14? > + > +#else > + > +static_assert(true); // expected-warning {{incompatible with C++ > standards before C++17}} > + > +template int f() { return (N + ...); } // expected-warning > {{incompatible with C++ standards before C++17}} > + > +namespace [[]] NS_with_attr {} // expected-warning {{incompatible with > C++ standards before C++17}} > +enum { e [[]] }; // expected-warning {{incompatible with C++ standards > before C++17}} > + > +template struct X {}; > +X x; // expected-warning {{class template argument deduction is > incompatible with C++ standards before C++17}} > + > +template class> struct Y {}; > +Y yx; // ok, not class template argument deduction > + > +template void f(T t) { > + X x = t; // expected-warning {{incompatible}} > +} > + > +template void g(T t) { > + typename T::X x = t; // expected-warning {{incompatible}} > +} > +struct A { template struct X { X(T); }; }; > +void h(A a) { g(a); } // expected-note {{in instantiation of}} > + > +#endif > > > ___ > cfe-commits mailing list > cfe-commits@lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits > ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D51473: Improve attribute documentation to list which spellings are used in which syntaxes.
On Thu, 30 Aug 2018 at 12:27, Aaron Ballman via cfe-commits < cfe-commits@lists.llvm.org> wrote: > On Thu, Aug 30, 2018 at 3:21 PM, Richard Smith - zygoloid via > Phabricator wrote: > > rsmith marked an inline comment as done. > > rsmith added inline comments. > > > > > > > > Comment at: utils/TableGen/ClangAttrEmitter.cpp:3881 > > +SpellingKind K = (SpellingKind)Kind; > > +// FIXME: Why are Microsoft spellings not listed? > > +if (K == SpellingKind::Microsoft) > > > > aaron.ballman wrote: > >> We don't actually support Microsoft's attribute spellings currently and > have no attributes there to document. I think the fixme should probably > read "TODO: support documenting Microsoft spellings" or something more > concrete. > > Done. (I accidentally pushed the old version, so this is done in > r341100.) > > > > For what it's worth, we have one `Microsoft` spelling listed in the .td > file already (but I assume this has no effect): > > > > ``` > > def Uuid : InheritableAttr { > > let Spellings = [Declspec<"uuid">, Microsoft<"uuid">]; > > ``` > > Hmm, I take it back, we do support a Microsoft attribute, only to warn > about it being deprecated and telling users to use __declspec instead: > https://godbolt.org/z/_0ZxWq > > I remember when we tried to add more support for parsing Microsoft > attributes, but I had the impression we didn't support them beyond the > very basics of parsing. Perhaps we do want to document them though, > since there's at least one? > Given that doing so will make the "supported syntaxes" table wider for all attributes, and it's already about as wide as seems reasonable, and we consider all attributes of this form to be deprecated, I don't think it's worth it. Maybe if we only included non-empty columns in the syntax table? ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r341110 - [cxx_status] Use the correct color for a feature in "SVN" status
Author: rsmith Date: Thu Aug 30 13:15:28 2018 New Revision: 341110 URL: http://llvm.org/viewvc/llvm-project?rev=341110&view=rev Log: [cxx_status] Use the correct color for a feature in "SVN" status Modified: cfe/trunk/www/cxx_status.html Modified: cfe/trunk/www/cxx_status.html URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/www/cxx_status.html?rev=341110&r1=341109&r2=341110&view=diff == --- cfe/trunk/www/cxx_status.html (original) +++ cfe/trunk/www/cxx_status.html Thu Aug 30 13:15:28 2018 @@ -755,7 +755,7 @@ version 3.7. http://wg21.link/p0961r1";>P0961R1 (DR) -SVN +SVN ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D51507: Allow all supportable attributes to be used with #pragma clang attribute.
On Fri, 31 Aug 2018 at 06:35, Aaron Ballman via cfe-commits < cfe-commits@lists.llvm.org> wrote: > My reasoning is because type attributes have more impact than variable > attributes and types appear more frequently. Consider using > address_space where the region includes function definitions. Should > that apply to the parameters and return types of the function as well > as the code within the function? Will that be intuitive for users? > I think there's actually an easy answer for this: the #pragma clang attribute mechanism does not support type attributes at all. Calling conventions, address_space attributes, and the like are not affected by this patch. So, while we should figure out whether we want to support injecting type attributes with this pragma, the status quo is that we do not and cannot. However... there are some attributes that (for historical reasons, I think) are not classified as type attribtues, despite clearly being type attributes in principle, and that this patch would allow usage of with #pragma clang attribute: * ext_vector_type: We handle this as a type attribute but classify it as a type alias attribute. This just seems to be a bug in the .td file. (We do *have* type alias handling for it, but that seems wrong to me: all we do when we see the attribute applied to an alias is to remember the type for later, and it would make a lot more sense to do that when building the alias declaration itself rather than pretending the attribute is a declaration attribute to support this.) * mode: We model and handle this as a declaration attribute, but it's really notionally a type attribute. I expect we model it as a declaration attribute for GCC compatibility. (The other type_alias attributes really do apply to the alias and not to the type, typically transforming the alias declaration into a declaration of a new type that is different from the original type in some way but that is canonically equivalent to the original. As such, introducing an attribute for a block of such aliases seems reasonable and useful.) I'm going to blacklist those two attributes in this patch. We can decide at some later time if we want to support type attributes with this pragma or not, but I think for now we have consensus on the changes herein for all non-type attributes, and we should go ahead with that part of the change. ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r341373 - Fix the -print-multi-directory flag to print the selected multilib.
This is breaking buildbots: http://lab.llvm.org:8011/builders/clang-x86_64-linux-selfhost-modules/builds/19509 Can you take a look? Thanks! On Tue, 4 Sep 2018 at 08:36, Christian Bruel via cfe-commits < cfe-commits@lists.llvm.org> wrote: > Author: chrib > Date: Tue Sep 4 08:22:13 2018 > New Revision: 341373 > > URL: http://llvm.org/viewvc/llvm-project?rev=341373&view=rev > Log: > Fix the -print-multi-directory flag to print the selected multilib. > > Summary: Fix -print-multi-directory to print the selected multilib > > Reviewers: jroelofs > > Reviewed By: jroelofs > > Subscribers: srhines, cfe-commits > > Differential Revision: https://reviews.llvm.org/D51354 > > Added: > cfe/trunk/test/Driver/print-multi-directory.c > Modified: > cfe/trunk/include/clang/Driver/ToolChain.h > cfe/trunk/lib/Driver/Driver.cpp > cfe/trunk/lib/Driver/ToolChains/Linux.cpp > > Modified: cfe/trunk/include/clang/Driver/ToolChain.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/ToolChain.h?rev=341373&r1=341372&r2=341373&view=diff > > == > --- cfe/trunk/include/clang/Driver/ToolChain.h (original) > +++ cfe/trunk/include/clang/Driver/ToolChain.h Tue Sep 4 08:22:13 2018 > @@ -149,6 +149,7 @@ private: > > protected: >MultilibSet Multilibs; > + Multilib SelectedMultilib; > >ToolChain(const Driver &D, const llvm::Triple &T, > const llvm::opt::ArgList &Args); > @@ -227,6 +228,8 @@ public: > >const MultilibSet &getMultilibs() const { return Multilibs; } > > + const Multilib &getMultilib() const { return SelectedMultilib; } > + >const SanitizerArgs& getSanitizerArgs() const; > >const XRayArgs& getXRayArgs() const; > > Modified: cfe/trunk/lib/Driver/Driver.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=341373&r1=341372&r2=341373&view=diff > > == > --- cfe/trunk/lib/Driver/Driver.cpp (original) > +++ cfe/trunk/lib/Driver/Driver.cpp Tue Sep 4 08:22:13 2018 > @@ -1661,14 +1661,13 @@ bool Driver::HandleImmediateArgs(const C >} > >if (C.getArgs().hasArg(options::OPT_print_multi_directory)) { > -for (const Multilib &Multilib : TC.getMultilibs()) { > - if (Multilib.gccSuffix().empty()) > -llvm::outs() << ".\n"; > - else { > -StringRef Suffix(Multilib.gccSuffix()); > -assert(Suffix.front() == '/'); > -llvm::outs() << Suffix.substr(1) << "\n"; > - } > +const Multilib &Multilib = TC.getMultilib(); > +if (Multilib.gccSuffix().empty()) > + llvm::outs() << ".\n"; > +else { > + StringRef Suffix(Multilib.gccSuffix()); > + assert(Suffix.front() == '/'); > + llvm::outs() << Suffix.substr(1) << "\n"; > } > return false; >} > > Modified: cfe/trunk/lib/Driver/ToolChains/Linux.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Linux.cpp?rev=341373&r1=341372&r2=341373&view=diff > > == > --- cfe/trunk/lib/Driver/ToolChains/Linux.cpp (original) > +++ cfe/trunk/lib/Driver/ToolChains/Linux.cpp Tue Sep 4 08:22:13 2018 > @@ -210,6 +210,7 @@ Linux::Linux(const Driver &D, const llvm > : Generic_ELF(D, Triple, Args) { >GCCInstallation.init(Triple, Args); >Multilibs = GCCInstallation.getMultilibs(); > + SelectedMultilib = GCCInstallation.getMultilib(); >llvm::Triple::ArchType Arch = Triple.getArch(); >std::string SysRoot = computeSysRoot(); > > @@ -299,16 +300,14 @@ Linux::Linux(const Driver &D, const llvm >if (GCCInstallation.isValid()) { > const llvm::Triple &GCCTriple = GCCInstallation.getTriple(); > const std::string &LibPath = GCCInstallation.getParentLibPath(); > -const Multilib &Multilib = GCCInstallation.getMultilib(); > -const MultilibSet &Multilibs = GCCInstallation.getMultilibs(); > > // Add toolchain / multilib specific file paths. > -addMultilibsFilePaths(D, Multilibs, Multilib, > +addMultilibsFilePaths(D, Multilibs, SelectedMultilib, >GCCInstallation.getInstallPath(), Paths); > > // Sourcery CodeBench MIPS toolchain holds some libraries under > // a biarch-like suffix of the GCC installation. > -addPathIfExists(D, GCCInstallation.getInstallPath() + > Multilib.gccSuffix(), > +addPathIfExists(D, GCCInstallation.getInstallPath() + > SelectedMultilib.gccSuffix(), > Paths); > > // GCC cross compiling toolchains will install target libraries which > ship > @@ -330,7 +329,7 @@ Linux::Linux(const Driver &D, const llvm > // Note that this matches the GCC behavior. See the below comment for > where > // Clang diverges from GCC's behavior. > addPathIfExists(D, LibPath + "/../" + GCCTriple.str() + "/lib/../" + > - OSLibDir
r341437 - Allow all supportable non-type attributes to be used with #pragma clang attribute.
Author: rsmith Date: Tue Sep 4 17:28:57 2018 New Revision: 341437 URL: http://llvm.org/viewvc/llvm-project?rev=341437&view=rev Log: Allow all supportable non-type attributes to be used with #pragma clang attribute. Summary: We previously disallowed use of undocumented attributes with #pragma clang attribute, but the justification for doing so was weak and it prevented many reasonable use cases. Reviewers: aaron.ballman, arphaman Subscribers: cfe-commits, rnk, benlangmuir, dexonsmith, erik.pilkington Differential Revision: https://reviews.llvm.org/D51507 Modified: cfe/trunk/include/clang/Basic/Attr.td cfe/trunk/test/Misc/pragma-attribute-supported-attributes-list.test cfe/trunk/test/Parser/pragma-attribute.cpp Modified: cfe/trunk/include/clang/Basic/Attr.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=341437&r1=341436&r2=341437&view=diff == --- cfe/trunk/include/clang/Basic/Attr.td (original) +++ cfe/trunk/include/clang/Basic/Attr.td Tue Sep 4 17:28:57 2018 @@ -545,7 +545,6 @@ class IgnoredAttr : Attr { let ASTNode = 0; let SemaHandler = 0; let Documentation = [Undocumented]; - let PragmaAttributeSupport = 0; } // @@ -564,7 +563,6 @@ def AddressSpace : TypeAttr { let Spellings = [Clang<"address_space">]; let Args = [IntArgument<"AddressSpace">]; let Documentation = [Undocumented]; - let PragmaAttributeSupport = 0; } def Alias : Attr { @@ -572,7 +570,6 @@ def Alias : Attr { let Args = [StringArgument<"Aliasee">]; let Subjects = SubjectList<[Function, GlobalVar], ErrorDiag>; let Documentation = [Undocumented]; - let PragmaAttributeSupport = 0; } def Aligned : InheritableAttr { @@ -585,7 +582,6 @@ def Aligned : InheritableAttr { Keyword<"_Alignas">]>, Accessor<"isDeclspec",[Declspec<"align">]>]; let Documentation = [Undocumented]; - let PragmaAttributeSupport = 0; } def AlignValue : Attr { @@ -613,14 +609,12 @@ def AlignMac68k : InheritableAttr { let Spellings = []; let SemaHandler = 0; let Documentation = [Undocumented]; - let PragmaAttributeSupport = 0; } def AlwaysInline : InheritableAttr { let Spellings = [GCC<"always_inline">, Keyword<"__forceinline">]; let Subjects = SubjectList<[Function]>; let Documentation = [Undocumented]; - let PragmaAttributeSupport = 0; } def Artificial : InheritableAttr { @@ -665,8 +659,8 @@ def AnalyzerNoReturn : InheritableAttr { // vendor namespace, or should it use a vendor namespace specific to the // analyzer? let Spellings = [GNU<"analyzer_noreturn">]; + // TODO: Add subject list. let Documentation = [Undocumented]; - let PragmaAttributeSupport = 0; } def Annotate : InheritableParamAttr { @@ -709,7 +703,6 @@ def AsmLabel : InheritableAttr { let Args = [StringArgument<"Label">]; let SemaHandler = 0; let Documentation = [Undocumented]; - let PragmaAttributeSupport = 0; } def Availability : InheritableAttr { @@ -776,7 +769,6 @@ def Blocks : InheritableAttr { let Spellings = [Clang<"blocks">]; let Args = [EnumArgument<"Type", "BlockType", ["byref"], ["ByRef"]>]; let Documentation = [Undocumented]; - let PragmaAttributeSupport = 0; } def Bounded : IgnoredAttr { @@ -795,7 +787,6 @@ def CDecl : DeclOrTypeAttr { let Spellings = [GCC<"cdecl">, Keyword<"__cdecl">, Keyword<"_cdecl">]; // let Subjects = [Function, ObjCMethod]; let Documentation = [Undocumented]; - let PragmaAttributeSupport = 0; } // cf_audited_transfer indicates that the given function has been @@ -806,7 +797,6 @@ def CFAuditedTransfer : InheritableAttr let Spellings = [Clang<"cf_audited_transfer">]; let Subjects = SubjectList<[Function], ErrorDiag>; let Documentation = [Undocumented]; - let PragmaAttributeSupport = 0; } // cf_unknown_transfer is an explicit opt-out of cf_audited_transfer. @@ -816,28 +806,24 @@ def CFUnknownTransfer : InheritableAttr let Spellings = [Clang<"cf_unknown_transfer">]; let Subjects = SubjectList<[Function], ErrorDiag>; let Documentation = [Undocumented]; - let PragmaAttributeSupport = 0; } def CFReturnsRetained : InheritableAttr { let Spellings = [Clang<"cf_returns_retained">]; // let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>; let Documentation = [Undocumented]; - let PragmaAttributeSupport = 0; } def CFReturnsNotRetained : InheritableAttr { let Spellings = [Clang<"cf_returns_not_retained">]; // let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>; let Documentation = [Undocumented]; - let PragmaAttributeSupport = 0; } def CFConsumed : InheritableParamAttr { let Spellings = [Clang<"cf_consumed">]; let Subjects = SubjectList<[ParmVar]>; let Documentation = [Undocumented]; - let PragmaAttributeSupport = 0; } def Cleanup : InheritableAttr { @@ -845,27 +831,23 @@ d
r341499 - PR38627: Fix handling of exception specification adjustment for
Author: rsmith Date: Wed Sep 5 15:30:37 2018 New Revision: 341499 URL: http://llvm.org/viewvc/llvm-project?rev=341499&view=rev Log: PR38627: Fix handling of exception specification adjustment for destructors. We previously tried to patch up the exception specification after completing the class, which went wrong when the exception specification was needed within the class body (in particular, by a friend redeclaration of the destructor in a nested class). We now mark the destructor as having a not-yet-computed exception specification immediately after creating it. This requires delaying various checks against the exception specification (where we'd previously have just got the wrong exception specification, and now find we have an exception specification that we can't compute yet) when those checks fire while the class is being defined. This also exposed an issue that we were missing a CodeSynthesisContext for computation of exception specifications (otherwise we'd fail to make the module containing the definition of the class visible when computing its members' exception specs). Adding that incidentally also gives us a diagnostic quality improvement. This has also exposed an pre-existing problem: making the exception specification evaluation context a non-SFINAE context (as it should be) results in a bootstrap failure; PR38850 filed for this. Added: cfe/trunk/test/Modules/exception-spec.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/include/clang/Sema/Sema.h cfe/trunk/lib/Frontend/FrontendActions.cpp cfe/trunk/lib/Sema/Sema.cpp cfe/trunk/lib/Sema/SemaDecl.cpp cfe/trunk/lib/Sema/SemaDeclCXX.cpp cfe/trunk/lib/Sema/SemaExceptionSpec.cpp cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp cfe/trunk/test/CXX/drs/dr13xx.cpp cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/templates.cpp cfe/trunk/test/Modules/cxx-templates.cpp cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp cfe/trunk/test/SemaCXX/cxx0x-defaulted-functions.cpp cfe/trunk/test/SemaCXX/exception-spec.cpp cfe/trunk/test/SemaCXX/implicit-exception-spec.cpp cfe/trunk/test/SemaCXX/member-init.cpp cfe/trunk/test/SemaTemplate/instantiate-init.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=341499&r1=341498&r2=341499&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Sep 5 15:30:37 2018 @@ -1467,6 +1467,10 @@ def err_noexcept_needs_constant_expressi "argument to noexcept specifier must be a constant expression">; def err_exception_spec_not_parsed : Error< "exception specification is not available until end of class definition">; +def err_exception_spec_cycle : Error< + "exception specification of %0 uses itself">; +def err_exception_spec_incomplete_type : Error< + "exception specification needed for member of incomplete class %0">; // C++ access checking def err_class_redeclared_with_different_access : Error< @@ -4270,6 +4274,8 @@ def note_forward_template_decl : Note< def note_inst_declaration_hint : Note<"add an explicit instantiation " "declaration to suppress this warning if %q0 is explicitly instantiated in " "another translation unit">; +def note_evaluating_exception_spec_here : Note< + "in evaluation of exception specification for %q0 needed here">; def note_default_arg_instantiation_here : Note< "in instantiation of default argument for '%0' required here">; @@ -7471,8 +7477,6 @@ def note_in_class_initializer_not_yet_pa "default member initializer declared here">; def err_in_class_initializer_cycle : Error<"default member initializer for %0 uses itself">; -def err_exception_spec_cycle -: Error<"exception specification of %0 uses itself">; def ext_in_class_initializer_non_constant : Extension< "in-class initializer for static data member is not a constant expression; " Modified: cfe/trunk/include/clang/Sema/Sema.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=341499&r1=341498&r2=341499&view=diff == --- cfe/trunk/include/clang/Sema/Sema.h (original) +++ cfe/trunk/include/clang/Sema/Sema.h Wed Sep 5 15:30:37 2018 @@ -608,7 +608,15 @@ public: /// that had their exception spec checks delayed, plus the overridden /// function. SmallVector, 2> -DelayedExceptionSpecChecks; +DelayedOverridingExceptionSpecChecks; + + /// All the function redeclarations seen during a class definition that had + /// their exception spec checks delayed, plus the prior declaration they + /// should be checked against. Except during error recovery, the new d
r341700 - PR38870: Add warning for zero-width unicode characters appearing in
Author: rsmith Date: Fri Sep 7 12:25:39 2018 New Revision: 341700 URL: http://llvm.org/viewvc/llvm-project?rev=341700&view=rev Log: PR38870: Add warning for zero-width unicode characters appearing in identifiers. Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td cfe/trunk/lib/Lex/Lexer.cpp cfe/trunk/test/Lexer/unicode.c Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=341700&r1=341699&r2=341700&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Fri Sep 7 12:25:39 2018 @@ -122,6 +122,9 @@ def ext_unicode_whitespace : ExtWarn< def warn_utf8_symbol_homoglyph : Warning< "treating Unicode character as identifier character rather than " "as '%1' symbol">, InGroup>; +def warn_utf8_symbol_zero_width : Warning< + "identifier contains Unicode character that is invisible in " + "some environments">, InGroup>; def err_hex_escape_no_digits : Error< "\\%0 used with no following hex digits">; Modified: cfe/trunk/lib/Lex/Lexer.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=341700&r1=341699&r2=341700&view=diff == --- cfe/trunk/lib/Lex/Lexer.cpp (original) +++ cfe/trunk/lib/Lex/Lexer.cpp Fri Sep 7 12:25:39 2018 @@ -1510,8 +1510,17 @@ static void maybeDiagnoseUTF8Homoglyph(D bool operator<(HomoglyphPair R) const { return Character < R.Character; } }; static constexpr HomoglyphPair SortedHomoglyphs[] = { +{U'\u00ad', 0}, // SOFT HYPHEN {U'\u01c3', '!'}, // LATIN LETTER RETROFLEX CLICK {U'\u037e', ';'}, // GREEK QUESTION MARK +{U'\u200b', 0}, // ZERO WIDTH SPACE +{U'\u200c', 0}, // ZERO WIDTH NON-JOINER +{U'\u200d', 0}, // ZERO WIDTH JOINER +{U'\u2060', 0}, // WORD JOINER +{U'\u2061', 0}, // FUNCTION APPLICATION +{U'\u2062', 0}, // INVISIBLE TIMES +{U'\u2063', 0}, // INVISIBLE SEPARATOR +{U'\u2064', 0}, // INVISIBLE PLUS {U'\u2212', '-'}, // MINUS SIGN {U'\u2215', '/'}, // DIVISION SLASH {U'\u2216', '\\'}, // SET MINUS @@ -1521,6 +1530,7 @@ static void maybeDiagnoseUTF8Homoglyph(D {U'\u2236', ':'}, // RATIO {U'\u223c', '~'}, // TILDE OPERATOR {U'\ua789', ':'}, // MODIFIER LETTER COLON +{U'\ufeff', 0}, // ZERO WIDTH NO-BREAK SPACE {U'\uff01', '!'}, // FULLWIDTH EXCLAMATION MARK {U'\uff03', '#'}, // FULLWIDTH NUMBER SIGN {U'\uff04', '$'}, // FULLWIDTH DOLLAR SIGN @@ -1560,9 +1570,14 @@ static void maybeDiagnoseUTF8Homoglyph(D llvm::raw_svector_ostream CharOS(CharBuf); llvm::write_hex(CharOS, C, llvm::HexPrintStyle::Upper, 4); } -const char LooksLikeStr[] = {Homoglyph->LooksLike, 0}; -Diags.Report(Range.getBegin(), diag::warn_utf8_symbol_homoglyph) -<< Range << CharBuf << LooksLikeStr; +if (Homoglyph->LooksLike) { + const char LooksLikeStr[] = {Homoglyph->LooksLike, 0}; + Diags.Report(Range.getBegin(), diag::warn_utf8_symbol_homoglyph) + << Range << CharBuf << LooksLikeStr; +} else { + Diags.Report(Range.getBegin(), diag::warn_utf8_symbol_zero_width) + << Range << CharBuf; +} } } Modified: cfe/trunk/test/Lexer/unicode.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/unicode.c?rev=341700&r1=341699&r2=341700&view=diff == --- cfe/trunk/test/Lexer/unicode.c (original) +++ cfe/trunk/test/Lexer/unicode.c Fri Sep 7 12:25:39 2018 @@ -38,3 +38,10 @@ int n; = 3; // expected-warning {{tre int *nêêv = &n;; // expected-warning 2{{treating Unicode character as identifier character rather than as ':' symbol}} // expected-warning@-1 {{treating Unicode character as identifier character rather than as ';' symbol}} int vï¼ï¼»ï¼ï¼½ï¼autoï¼ï½returnï½xï¼ï½ï¼ï¼; // expected-warning 12{{treating Unicode character}} + +int â xxâ; +// expected-warning@-1 {{identifier contains Unicode character that is invisible in some environments}} +// expected-warning@-2 {{identifier contains Unicode character that is invisible in some environments}} +// expected-warning@-3 {{identifier contains Unicode character that is invisible in some environments}} +int fooâbar = 0; // expected-warning {{identifier contains Unicode character that is invisible in some environments}} +int x = foobar; // expected-error {{undeclared identifier}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r341710 - Make -Watomic-alignment say whether the atomic operation was oversized
Author: rsmith Date: Fri Sep 7 14:24:27 2018 New Revision: 341710 URL: http://llvm.org/viewvc/llvm-project?rev=341710&view=rev Log: Make -Watomic-alignment say whether the atomic operation was oversized or misaligned. Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/CodeGen/CGAtomic.cpp cfe/trunk/test/CodeGen/atomics-sema-alignment.c Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=341710&r1=341709&r2=341710&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Sep 7 14:24:27 2018 @@ -7093,8 +7093,8 @@ def warn_atomic_op_has_invalid_memory_or def err_atomic_op_has_invalid_synch_scope : Error< "synchronization scope argument to atomic operation is invalid">; def warn_atomic_op_misaligned : Warning< - "misaligned or large atomic operation may incur significant performance penalty">, - InGroup>; + "%select{large|misaligned}0 atomic operation may incur " + "significant performance penalty">, InGroup>; def err_overflow_builtin_must_be_int : Error< "operand argument to overflow builtin must be an integer (%0 invalid)">; Modified: cfe/trunk/lib/CodeGen/CGAtomic.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGAtomic.cpp?rev=341710&r1=341709&r2=341710&view=diff == --- cfe/trunk/lib/CodeGen/CGAtomic.cpp (original) +++ cfe/trunk/lib/CodeGen/CGAtomic.cpp Fri Sep 7 14:24:27 2018 @@ -765,11 +765,15 @@ RValue CodeGenFunction::EmitAtomicExpr(A std::tie(sizeChars, alignChars) = getContext().getTypeInfoInChars(AtomicTy); uint64_t Size = sizeChars.getQuantity(); unsigned MaxInlineWidthInBits = getTarget().getMaxAtomicInlineWidth(); - bool UseLibcall = ((Ptr.getAlignment() % sizeChars) != 0 || - getContext().toBits(sizeChars) > MaxInlineWidthInBits); - if (UseLibcall) -CGM.getDiags().Report(E->getBeginLoc(), diag::warn_atomic_op_misaligned); + bool Oversized = getContext().toBits(sizeChars) > MaxInlineWidthInBits; + bool Misaligned = (Ptr.getAlignment() % sizeChars) != 0; + bool UseLibcall = Misaligned | Oversized; + + if (UseLibcall) { +CGM.getDiags().Report(E->getBeginLoc(), diag::warn_atomic_op_misaligned) +<< !Oversized; + } llvm::Value *Order = EmitScalarExpr(E->getOrder()); llvm::Value *Scope = Modified: cfe/trunk/test/CodeGen/atomics-sema-alignment.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/atomics-sema-alignment.c?rev=341710&r1=341709&r2=341710&view=diff == --- cfe/trunk/test/CodeGen/atomics-sema-alignment.c (original) +++ cfe/trunk/test/CodeGen/atomics-sema-alignment.c Fri Sep 7 14:24:27 2018 @@ -12,10 +12,10 @@ typedef int __attribute__((aligned(1))) void func(IntPair *p) { IntPair res; - __atomic_load(p, &res, 0); // expected-warning {{misaligned or large atomic operation may incur significant performance penalty}} - __atomic_store(p, &res, 0); // expected-warning {{misaligned or large atomic operation may incur significant performance penalty}} - __atomic_fetch_add((unaligned_int *)p, 1, 2); // expected-warning {{misaligned or large atomic operation may incur significant performance penalty}} - __atomic_fetch_sub((unaligned_int *)p, 1, 3); // expected-warning {{misaligned or large atomic operation may incur significant performance penalty}} + __atomic_load(p, &res, 0); // expected-warning {{misaligned atomic operation may incur significant performance penalty}} + __atomic_store(p, &res, 0); // expected-warning {{misaligned atomic operation may incur significant performance penalty}} + __atomic_fetch_add((unaligned_int *)p, 1, 2); // expected-warning {{misaligned atomic operation may incur significant performance penalty}} + __atomic_fetch_sub((unaligned_int *)p, 1, 3); // expected-warning {{misaligned atomic operation may incur significant performance penalty}} } void func1(LongStruct *p) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r341734 - Do not use optimized atomic libcalls for misaligned atomics.
Author: rsmith Date: Fri Sep 7 16:57:54 2018 New Revision: 341734 URL: http://llvm.org/viewvc/llvm-project?rev=341734&view=rev Log: Do not use optimized atomic libcalls for misaligned atomics. Summary: The optimized (__atomic_foo_) libcalls assume that the atomic object is properly aligned, so should never be called on an underaligned object. This addresses one of several problems identified in PR38846. Reviewers: jyknight, t.p.northover Subscribers: jfb, cfe-commits Differential Revision: https://reviews.llvm.org/D51817 Modified: cfe/trunk/lib/CodeGen/CGAtomic.cpp cfe/trunk/test/CodeGen/atomic-ops.c Modified: cfe/trunk/lib/CodeGen/CGAtomic.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGAtomic.cpp?rev=341734&r1=341733&r2=341734&view=diff == --- cfe/trunk/lib/CodeGen/CGAtomic.cpp (original) +++ cfe/trunk/lib/CodeGen/CGAtomic.cpp Fri Sep 7 16:57:54 2018 @@ -927,6 +927,15 @@ RValue CodeGenFunction::EmitAtomicExpr(A UseOptimizedLibcall = true; break; +case AtomicExpr::AO__atomic_load: +case AtomicExpr::AO__atomic_store: +case AtomicExpr::AO__atomic_exchange: +case AtomicExpr::AO__atomic_compare_exchange: + // Use the generic version if we don't know that the operand will be + // suitably aligned for the optimized version. + if (Misaligned) +break; + LLVM_FALLTHROUGH; case AtomicExpr::AO__c11_atomic_load: case AtomicExpr::AO__c11_atomic_store: case AtomicExpr::AO__c11_atomic_exchange: @@ -938,14 +947,11 @@ RValue CodeGenFunction::EmitAtomicExpr(A case AtomicExpr::AO__opencl_atomic_compare_exchange_weak: case AtomicExpr::AO__opencl_atomic_compare_exchange_strong: case AtomicExpr::AO__atomic_load_n: -case AtomicExpr::AO__atomic_load: case AtomicExpr::AO__atomic_store_n: -case AtomicExpr::AO__atomic_store: case AtomicExpr::AO__atomic_exchange_n: -case AtomicExpr::AO__atomic_exchange: case AtomicExpr::AO__atomic_compare_exchange_n: -case AtomicExpr::AO__atomic_compare_exchange: // Only use optimized library calls for sizes for which they exist. + // FIXME: Size == 16 optimized library functions exist too. if (Size == 1 || Size == 2 || Size == 4 || Size == 8) UseOptimizedLibcall = true; break; Modified: cfe/trunk/test/CodeGen/atomic-ops.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/atomic-ops.c?rev=341734&r1=341733&r2=341734&view=diff == --- cfe/trunk/test/CodeGen/atomic-ops.c (original) +++ cfe/trunk/test/CodeGen/atomic-ops.c Fri Sep 7 16:57:54 2018 @@ -198,10 +198,12 @@ struct S implicit_load(_Atomic(struct S) struct S fd1(struct S *a) { // CHECK-LABEL: @fd1 // CHECK: [[RETVAL:%.*]] = alloca %struct.S, align 4 - // CHECK: bitcast %struct.S* {{.*}} to i64* + // CHECK: [[A:%.*]] = bitcast %struct.S* {{.*}} to i64* // CHECK: [[CAST:%.*]] = bitcast %struct.S* [[RETVAL]] to i64* - // CHECK: [[CALL:%.*]] = call i64 @__atomic_load_8( - // CHECK: store i64 [[CALL]], i64* [[CAST]], align 4 + // CHECK: [[SRC:%.*]] = bitcast i64* [[A]] to i8* + // CHECK: [[DEST:%.*]] = bitcast i64* [[CAST]] to i8* + // CHECK: call void @__atomic_load(i32 8, i8* [[SRC]], i8* [[DEST]], i32 5) + // CHECK: ret struct S ret; __atomic_load(a, &ret, memory_order_seq_cst); return ret; @@ -218,8 +220,8 @@ void fd2(struct S *a, struct S *b) { // CHECK-NEXT: [[COERCED_A_TMP:%.*]] = bitcast %struct.S* [[LOAD_A_PTR]] to i64* // CHECK-NEXT: [[COERCED_B:%.*]] = bitcast %struct.S* [[LOAD_B_PTR]] to i64* // CHECK-NEXT: [[COERCED_A:%.*]] = bitcast i64* [[COERCED_A_TMP]] to i8* - // CHECK-NEXT: [[LOAD_B:%.*]] = load i64, i64* [[COERCED_B]], align 4 - // CHECK-NEXT: call void @__atomic_store_8(i8* [[COERCED_A]], i64 [[LOAD_B]], + // CHECK-NEXT: [[CAST_B:%.*]] = bitcast i64* [[COERCED_B]] to i8* + // CHECK-NEXT: call void @__atomic_store(i32 8, i8* [[COERCED_A]], i8* [[CAST_B]], // CHECK-NEXT: ret void __atomic_store(a, b, memory_order_seq_cst); } @@ -239,9 +241,9 @@ void fd3(struct S *a, struct S *b, struc // CHECK-NEXT: [[COERCED_B:%.*]] = bitcast %struct.S* [[LOAD_B_PTR]] to i64* // CHECK-NEXT: [[COERCED_C:%.*]] = bitcast %struct.S* [[LOAD_C_PTR]] to i64* // CHECK-NEXT: [[COERCED_A:%.*]] = bitcast i64* [[COERCED_A_TMP]] to i8* - // CHECK-NEXT: [[LOAD_B:%.*]] = load i64, i64* [[COERCED_B]], align 4 - // CHECK-NEXT: [[CALL:%.*]] = call i64 @__atomic_exchange_8(i8* [[COERCED_A]], i64 [[LOAD_B]], - // CHECK-NEXT: store i64 [[CALL]], i64* [[COERCED_C]], align 4 + // CHECK-NEXT: [[CAST_B:%.*]] = bitcast i64* [[COERCED_B]] to i8* + // CHECK-NEXT: [[CAST_C:%.*]] = bitcast i64* [[COERCED_C]] to i8* + // CHECK-NEXT: call void @__atomic_exchange(i32 8, i8* [[COERCED_A]], i8* [[CAST_B]], i8* [[CAST_C]], __atomic_exchange(a, b, c,
r341775 - Part of PR33222: defer enforcing return type mismatch for dependent
Author: rsmith Date: Sun Sep 9 22:32:13 2018 New Revision: 341775 URL: http://llvm.org/viewvc/llvm-project?rev=341775&view=rev Log: Part of PR33222: defer enforcing return type mismatch for dependent friend function declarations of class templates. Modified: cfe/trunk/include/clang/Sema/Sema.h cfe/trunk/lib/Sema/SemaDecl.cpp cfe/trunk/test/SemaCXX/friend.cpp Modified: cfe/trunk/include/clang/Sema/Sema.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=341775&r1=341774&r2=341775&view=diff == --- cfe/trunk/include/clang/Sema/Sema.h (original) +++ cfe/trunk/include/clang/Sema/Sema.h Sun Sep 9 22:32:13 2018 @@ -1956,6 +1956,8 @@ public: FunctionDecl *NewFD, LookupResult &Previous, bool IsMemberSpecialization); bool shouldLinkDependentDeclWithPrevious(Decl *D, Decl *OldDecl); + bool canFullyTypeCheckRedeclaration(ValueDecl *NewD, ValueDecl *OldD, + QualType NewT, QualType OldT); void CheckMain(FunctionDecl *FD, const DeclSpec &D); void CheckMSVCRTEntryPoint(FunctionDecl *FD); Attr *getImplicitCodeSegOrSectionAttrForFunction(const FunctionDecl *FD, bool IsDefinition); Modified: cfe/trunk/lib/Sema/SemaDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=341775&r1=341774&r2=341775&view=diff == --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Sep 9 22:32:13 2018 @@ -3254,8 +3254,8 @@ bool Sema::MergeFunctionDecl(FunctionDec ? New->getTypeSourceInfo()->getType()->castAs() : NewType)->getReturnType(); if (!Context.hasSameType(OldDeclaredReturnType, NewDeclaredReturnType) && -!((NewQType->isDependentType() || OldQType->isDependentType()) && - New->isLocalExternDecl())) { +canFullyTypeCheckRedeclaration(New, Old, NewDeclaredReturnType, + OldDeclaredReturnType)) { QualType ResQT; if (NewDeclaredReturnType->isObjCObjectPointerType() && OldDeclaredReturnType->isObjCObjectPointerType()) @@ -3423,13 +3423,11 @@ bool Sema::MergeFunctionDecl(FunctionDec if (OldQTypeForComparison == NewQType) return MergeCompatibleFunctionDecls(New, Old, S, MergeTypeWithOld); -if ((NewQType->isDependentType() || OldQType->isDependentType()) && -New->isLocalExternDecl()) { - // It's OK if we couldn't merge types for a local function declaraton - // if either the old or new type is dependent. We'll merge the types - // when we instantiate the function. +// If the types are imprecise (due to dependent constructs in friends or +// local extern declarations), it's OK if they differ. We'll check again +// during instantiation. +if (!canFullyTypeCheckRedeclaration(New, Old, NewQType, OldQType)) return false; -} // Fall through for conflicting redeclarations and redefinitions. } @@ -9300,6 +9298,39 @@ Attr *Sema::getImplicitCodeSegOrSectionA } return nullptr; } + +/// Determines if we can perform a correct type check for \p D as a +/// redeclaration of \p PrevDecl. If not, we can generally still perform a +/// best-effort check. +/// +/// \param NewD The new declaration. +/// \param OldD The old declaration. +/// \param NewT The portion of the type of the new declaration to check. +/// \param OldT The portion of the type of the old declaration to check. +bool Sema::canFullyTypeCheckRedeclaration(ValueDecl *NewD, ValueDecl *OldD, + QualType NewT, QualType OldT) { + if (!NewD->getLexicalDeclContext()->isDependentContext()) +return true; + + // For dependently-typed local extern declarations and friends, we can't + // perform a correct type check in general until instantiation: + // + // int f(); + // template void g() { T f(); } + // + // (valid if g() is only instantiated with T = int). + if (NewT->isDependentType() && + (NewD->isLocalExternDecl() || NewD->getFriendObjectKind())) +return false; + + // Similarly, if the previous declaration was a dependent local extern + // declaration, we don't really know its type yet. + if (OldT->isDependentType() && OldD->isLocalExternDecl()) +return false; + + return true; +} + /// Checks if the new declaration declared in dependent context must be /// put in the same redeclaration chain as the specified declaration. /// @@ -9310,20 +9341,30 @@ Attr *Sema::getImplicitCodeSegOrSectionA /// belongs to. /// bool Sema::shouldLinkDependentDeclWithPrevious(Decl *D, Decl *PrevDecl) { - // Any declarations should be put into redeclaration chains except for - // friend declaration in a dependent context that names a function in - // namespace sc
r341778 - PR33222: Require the declared return type not the actual return type to
Author: rsmith Date: Sun Sep 9 23:35:32 2018 New Revision: 341778 URL: http://llvm.org/viewvc/llvm-project?rev=341778&view=rev Log: PR33222: Require the declared return type not the actual return type to match when checking for redeclaration of a function template. This properly handles differences in deduced return types, particularly when performing redeclaration checks for a friend function template. Modified: cfe/trunk/include/clang/AST/Decl.h cfe/trunk/lib/Sema/SemaDecl.cpp cfe/trunk/lib/Sema/SemaOverload.cpp cfe/trunk/lib/Sema/SemaTemplate.cpp cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp Modified: cfe/trunk/include/clang/AST/Decl.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=341778&r1=341777&r2=341778&view=diff == --- cfe/trunk/include/clang/AST/Decl.h (original) +++ cfe/trunk/include/clang/AST/Decl.h Sun Sep 9 23:35:32 2018 @@ -2269,8 +2269,7 @@ public: unsigned getMinRequiredArguments() const; QualType getReturnType() const { -assert(getType()->getAs() && "Expected a FunctionType!"); -return getType()->getAs()->getReturnType(); +return getType()->castAs()->getReturnType(); } /// Attempt to compute an informative source range covering the @@ -2278,14 +2277,22 @@ public: /// limited representation in the AST. SourceRange getReturnTypeSourceRange() const; + /// Get the declared return type, which may differ from the actual return + /// type if the return type is deduced. + QualType getDeclaredReturnType() const { +auto *TSI = getTypeSourceInfo(); +QualType T = TSI ? TSI->getType() : getType(); +return T->castAs()->getReturnType(); + } + /// Attempt to compute an informative source range covering the /// function exception specification, if any. SourceRange getExceptionSpecSourceRange() const; /// Determine the type of an expression that calls this function. QualType getCallResultType() const { -assert(getType()->getAs() && "Expected a FunctionType!"); -return getType()->getAs()->getCallResultType(getASTContext()); +return getType()->castAs()->getCallResultType( +getASTContext()); } /// Returns the WarnUnusedResultAttr that is either declared on this Modified: cfe/trunk/lib/Sema/SemaDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=341778&r1=341777&r2=341778&view=diff == --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Sep 9 23:35:32 2018 @@ -3245,20 +3245,15 @@ bool Sema::MergeFunctionDecl(FunctionDec // Redeclarations or specializations of a function or function template // with a declared return type that uses a placeholder type shall also // use that placeholder, not a deduced type. -QualType OldDeclaredReturnType = -(Old->getTypeSourceInfo() - ? Old->getTypeSourceInfo()->getType()->castAs() - : OldType)->getReturnType(); -QualType NewDeclaredReturnType = -(New->getTypeSourceInfo() - ? New->getTypeSourceInfo()->getType()->castAs() - : NewType)->getReturnType(); +QualType OldDeclaredReturnType = Old->getDeclaredReturnType(); +QualType NewDeclaredReturnType = New->getDeclaredReturnType(); if (!Context.hasSameType(OldDeclaredReturnType, NewDeclaredReturnType) && canFullyTypeCheckRedeclaration(New, Old, NewDeclaredReturnType, OldDeclaredReturnType)) { QualType ResQT; if (NewDeclaredReturnType->isObjCObjectPointerType() && OldDeclaredReturnType->isObjCObjectPointerType()) +// FIXME: This does the wrong thing for a deduced return type. ResQT = Context.mergeObjCGCQualifiers(NewQType, OldQType); if (ResQT.isNull()) { if (New->isCXXClassMember() && New->isOutOfLine()) Modified: cfe/trunk/lib/Sema/SemaOverload.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=341778&r1=341777&r2=341778&view=diff == --- cfe/trunk/lib/Sema/SemaOverload.cpp (original) +++ cfe/trunk/lib/Sema/SemaOverload.cpp Sun Sep 9 23:35:32 2018 @@ -1105,7 +1105,8 @@ bool Sema::IsOverload(FunctionDecl *New, (!TemplateParameterListsAreEqual(NewTemplate->getTemplateParameters(), OldTemplate->getTemplateParameters(), false, TPL_TemplateMatch) || - OldType->getReturnType() != NewType->getReturnType())) + !Context.hasSameType(Old->getDeclaredReturnType(), +New->getDeclaredReturnType( return true; // If the function is a class member, its signature includes the Modified: cfe/trunk/lib/Sema/SemaTemp
r341858 - Enhance -Wc++14-compat for class template argument deduction to list the
Author: rsmith Date: Mon Sep 10 13:31:03 2018 New Revision: 341858 URL: http://llvm.org/viewvc/llvm-project?rev=341858&view=rev Log: Enhance -Wc++14-compat for class template argument deduction to list the deduced type (if known). Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaInit.cpp cfe/trunk/test/SemaCXX/cxx14-compat.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=341858&r1=341857&r2=341858&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Sep 10 13:31:03 2018 @@ -2153,7 +2153,8 @@ def note_deduction_guide_access : Note< "deduction guide declared %0 by intervening access specifier">; def warn_cxx14_compat_class_template_argument_deduction : Warning< "class template argument deduction is incompatible with C++ standards " - "before C++17">, InGroup, DefaultIgnore; + "before C++17%select{|; for compatibility, use explicit type name %1}0">, + InGroup, DefaultIgnore; // C++14 deduced return types def err_auto_fn_deduction_failure : Error< Modified: cfe/trunk/lib/Sema/SemaInit.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=341858&r1=341857&r2=341858&view=diff == --- cfe/trunk/lib/Sema/SemaInit.cpp (original) +++ cfe/trunk/lib/Sema/SemaInit.cpp Mon Sep 10 13:31:03 2018 @@ -9139,13 +9139,13 @@ QualType Sema::DeduceTemplateSpecializat return QualType(); } - Diag(TSInfo->getTypeLoc().getBeginLoc(), - diag::warn_cxx14_compat_class_template_argument_deduction) - << TSInfo->getTypeLoc().getSourceRange(); - // Can't deduce from dependent arguments. - if (Expr::hasAnyTypeDependentArguments(Inits)) + if (Expr::hasAnyTypeDependentArguments(Inits)) { +Diag(TSInfo->getTypeLoc().getBeginLoc(), + diag::warn_cxx14_compat_class_template_argument_deduction) +<< TSInfo->getTypeLoc().getSourceRange() << 0; return Context.DependentTy; + } // FIXME: Perform "exact type" matching first, per CWG discussion? //Or implement this via an implied 'T(T) -> T' deduction guide? @@ -9348,5 +9348,10 @@ QualType Sema::DeduceTemplateSpecializat // C++ [dcl.type.class.deduct]p1: // The placeholder is replaced by the return type of the function selected // by overload resolution for class template deduction. - return SubstAutoType(TSInfo->getType(), Best->Function->getReturnType()); + QualType DeducedType = + SubstAutoType(TSInfo->getType(), Best->Function->getReturnType()); + Diag(TSInfo->getTypeLoc().getBeginLoc(), + diag::warn_cxx14_compat_class_template_argument_deduction) + << TSInfo->getTypeLoc().getSourceRange() << 1 << DeducedType; + return DeducedType; } Modified: cfe/trunk/test/SemaCXX/cxx14-compat.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx14-compat.cpp?rev=341858&r1=341857&r2=341858&view=diff == --- cfe/trunk/test/SemaCXX/cxx14-compat.cpp (original) +++ cfe/trunk/test/SemaCXX/cxx14-compat.cpp Mon Sep 10 13:31:03 2018 @@ -16,7 +16,7 @@ namespace [[]] NS_with_attr {} // expect enum { e [[]] }; // expected-warning {{incompatible with C++ standards before C++17}} template struct X {}; -X x; // expected-warning {{class template argument deduction is incompatible with C++ standards before C++17}} +X x; // expected-warning {{class template argument deduction is incompatible with C++ standards before C++17; for compatibility, use explicit type name 'X'}} template class> struct Y {}; Y yx; // ok, not class template argument deduction ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r342017 - Fix tracking of merged definitions when the merge target is also merged
Author: rsmith Date: Tue Sep 11 19:13:46 2018 New Revision: 342017 URL: http://llvm.org/viewvc/llvm-project?rev=342017&view=rev Log: Fix tracking of merged definitions when the merge target is also merged into something else. Added: cfe/trunk/test/Modules/merge-template-pattern-visibility-2.cpp Modified: cfe/trunk/include/clang/AST/ASTContext.h cfe/trunk/lib/AST/ASTContext.cpp Modified: cfe/trunk/include/clang/AST/ASTContext.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=342017&r1=342016&r2=342017&view=diff == --- cfe/trunk/include/clang/AST/ASTContext.h (original) +++ cfe/trunk/include/clang/AST/ASTContext.h Tue Sep 11 19:13:46 2018 @@ -997,7 +997,8 @@ public: /// Get the additional modules in which the definition \p Def has /// been merged. ArrayRef getModulesWithMergedDefinition(const NamedDecl *Def) { -auto MergedIt = MergedDefModules.find(Def); +auto MergedIt = +MergedDefModules.find(cast(Def->getCanonicalDecl())); if (MergedIt == MergedDefModules.end()) return None; return MergedIt->second; Modified: cfe/trunk/lib/AST/ASTContext.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=342017&r1=342016&r2=342017&view=diff == --- cfe/trunk/lib/AST/ASTContext.cpp (original) +++ cfe/trunk/lib/AST/ASTContext.cpp Tue Sep 11 19:13:46 2018 @@ -933,13 +933,13 @@ void ASTContext::mergeDefinitionIntoModu Listener->RedefinedHiddenDefinition(ND, M); if (getLangOpts().ModulesLocalVisibility) -MergedDefModules[ND].push_back(M); +MergedDefModules[cast(ND->getCanonicalDecl())].push_back(M); else ND->setVisibleDespiteOwningModule(); } void ASTContext::deduplicateMergedDefinitonsFor(NamedDecl *ND) { - auto It = MergedDefModules.find(ND); + auto It = MergedDefModules.find(cast(ND->getCanonicalDecl())); if (It == MergedDefModules.end()) return; Added: cfe/trunk/test/Modules/merge-template-pattern-visibility-2.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/merge-template-pattern-visibility-2.cpp?rev=342017&view=auto == --- cfe/trunk/test/Modules/merge-template-pattern-visibility-2.cpp (added) +++ cfe/trunk/test/Modules/merge-template-pattern-visibility-2.cpp Tue Sep 11 19:13:46 2018 @@ -0,0 +1,34 @@ +// RUN: %clang_cc1 -fmodules -fmodules-local-submodule-visibility %s -verify -Werror=undefined-inline + +#pragma clang module build A1 +module A1 { export * } +#pragma clang module contents +#pragma clang module begin A1 +template class A {}; +template inline bool f(const A&) { return T::error; } +#pragma clang module end +#pragma clang module endbuild + +#pragma clang module build A2 +module A2 { export * } +#pragma clang module contents +#pragma clang module begin A2 +#pragma clang module load A1 +template class A {}; +template inline bool f(const A&) { return T::error; } +#pragma clang module end +#pragma clang module endbuild + +#pragma clang module build A3 +module A3 { export * } +#pragma clang module contents +#pragma clang module begin A3 +template class A {}; +template inline bool f(const A&) { return T::error; } +#pragma clang module end +#pragma clang module endbuild + +#pragma clang module load A3 +#pragma clang module import A2 +// expected-error@* {{cannot be used prior to}} +bool y(A o) { return f(o); } // expected-note {{instantiation of}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r342018 - Consistently create a new declaration when merging a pre-existing but
Author: rsmith Date: Tue Sep 11 19:13:47 2018 New Revision: 342018 URL: http://llvm.org/viewvc/llvm-project?rev=342018&view=rev Log: Consistently create a new declaration when merging a pre-existing but hidden definition with a would-be-parsed redefinition. This permits a bunch of cleanups. In particular, we no longer need to take merged definitions into account when checking declaration visibility, only when checking definition visibility, which makes certain visibility checks take linear instead of quadratic time. We could also now remove the UPD_DECL_EXPORTED update record and track on each declaration whether it was demoted from a definition (as we already do for variables), but I'm not doing that in this patch to keep the changes here simpler. Modified: cfe/trunk/include/clang/Sema/Sema.h cfe/trunk/lib/AST/ASTDumper.cpp cfe/trunk/lib/Sema/SemaDecl.cpp cfe/trunk/lib/Sema/SemaDeclCXX.cpp cfe/trunk/lib/Sema/SemaLookup.cpp cfe/trunk/lib/Sema/SemaTemplate.cpp cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp cfe/trunk/lib/Sema/SemaType.cpp cfe/trunk/test/Modules/submodules-merge-defs.cpp Modified: cfe/trunk/include/clang/Sema/Sema.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=342018&r1=342017&r2=342018&view=diff == --- cfe/trunk/include/clang/Sema/Sema.h (original) +++ cfe/trunk/include/clang/Sema/Sema.h Tue Sep 11 19:13:47 2018 @@ -1562,7 +1562,7 @@ public: /// visible at the specified location. void makeMergedDefinitionVisible(NamedDecl *ND); - bool isModuleVisible(const Module *M) { return VisibleModules.isVisible(M); } + bool isModuleVisible(const Module *M, bool ModulePrivate = false); /// Determine whether a declaration is visible to name lookup. bool isVisible(const NamedDecl *D) { @@ -6192,7 +6192,8 @@ public: bool CheckTemplateParameterList(TemplateParameterList *NewParams, TemplateParameterList *OldParams, - TemplateParamListContext TPC); + TemplateParamListContext TPC, + SkipBodyInfo *SkipBody = nullptr); TemplateParameterList *MatchTemplateParametersToScopeSpecifier( SourceLocation DeclStartLoc, SourceLocation DeclLoc, const CXXScopeSpec &SS, TemplateIdAnnotation *TemplateId, Modified: cfe/trunk/lib/AST/ASTDumper.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDumper.cpp?rev=342018&r1=342017&r2=342018&view=diff == --- cfe/trunk/lib/AST/ASTDumper.cpp (original) +++ cfe/trunk/lib/AST/ASTDumper.cpp Tue Sep 11 19:13:47 2018 @@ -1641,6 +1641,9 @@ void ASTDumper::VisitTemplateTypeParmDec dumpName(D); if (D->hasDefaultArgument()) dumpTemplateArgument(D->getDefaultArgument()); + if (auto *From = D->getDefaultArgStorage().getInheritedFrom()) +dumpDeclRef(From, D->defaultArgumentWasInherited() ? "inherited from" + : "previous"); } void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) { @@ -1651,6 +1654,9 @@ void ASTDumper::VisitNonTypeTemplateParm dumpName(D); if (D->hasDefaultArgument()) dumpTemplateArgument(D->getDefaultArgument()); + if (auto *From = D->getDefaultArgStorage().getInheritedFrom()) +dumpDeclRef(From, D->defaultArgumentWasInherited() ? "inherited from" + : "previous"); } void ASTDumper::VisitTemplateTemplateParmDecl( @@ -1662,6 +1668,9 @@ void ASTDumper::VisitTemplateTemplatePar dumpTemplateParameters(D->getTemplateParameters()); if (D->hasDefaultArgument()) dumpTemplateArgumentLoc(D->getDefaultArgument()); + if (auto *From = D->getDefaultArgStorage().getInheritedFrom()) +dumpDeclRef(From, D->defaultArgumentWasInherited() ? "inherited from" + : "previous"); } void ASTDumper::VisitUsingDecl(const UsingDecl *D) { Modified: cfe/trunk/lib/Sema/SemaDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=342018&r1=342017&r2=342018&view=diff == --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Sep 11 19:13:47 2018 @@ -12706,6 +12706,7 @@ Sema::CheckForFunctionRedefinition(Funct Definition->getDescribedFunctionTemplate() || Definition->getNumTemplateParameterLists())) { SkipBody->ShouldSkip = true; +SkipBody->Previous = const_cast(Definition); if (auto *TD = Definition->getDescribedFunctionTemplate()) makeMergedDefinitionVisible(TD); makeMergedDefinitionVisible(const_cast(Definition)); @@ -14034,7 +14035,7 @@ Decl *Sema::ActOnTag(Scope *S, unsigned
r342019 - Track definition merging on the canonical declaration even when local
Author: rsmith Date: Tue Sep 11 19:13:48 2018 New Revision: 342019 URL: http://llvm.org/viewvc/llvm-project?rev=342019&view=rev Log: Track definition merging on the canonical declaration even when local submodule visibility is disabled. Attempting to pick a specific declaration to make visible when the module containing the merged declaration becomes visible is error-prone, as we don't yet know which declaration we'll choose to be the definition when we are informed of the merging. Added: cfe/trunk/test/Modules/merge-template-pattern-visibility-3.cpp Modified: cfe/trunk/lib/AST/ASTContext.cpp cfe/trunk/lib/Sema/SemaType.cpp cfe/trunk/lib/Serialization/ASTReader.cpp cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Modified: cfe/trunk/lib/AST/ASTContext.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=342019&r1=342018&r2=342019&view=diff == --- cfe/trunk/lib/AST/ASTContext.cpp (original) +++ cfe/trunk/lib/AST/ASTContext.cpp Tue Sep 11 19:13:48 2018 @@ -932,10 +932,7 @@ void ASTContext::mergeDefinitionIntoModu if (auto *Listener = getASTMutationListener()) Listener->RedefinedHiddenDefinition(ND, M); - if (getLangOpts().ModulesLocalVisibility) -MergedDefModules[cast(ND->getCanonicalDecl())].push_back(M); - else -ND->setVisibleDespiteOwningModule(); + MergedDefModules[cast(ND->getCanonicalDecl())].push_back(M); } void ASTContext::deduplicateMergedDefinitonsFor(NamedDecl *ND) { Modified: cfe/trunk/lib/Sema/SemaType.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=342019&r1=342018&r2=342019&view=diff == --- cfe/trunk/lib/Sema/SemaType.cpp (original) +++ cfe/trunk/lib/Sema/SemaType.cpp Tue Sep 11 19:13:48 2018 @@ -7623,8 +7623,15 @@ bool Sema::hasVisibleDefinition(NamedDec // A visible module might have a merged definition instead. if (D->isModulePrivate() ? hasMergedDefinitionInCurrentModule(D) - : hasVisibleMergedDefinition(D)) + : hasVisibleMergedDefinition(D)) { + if (CodeSynthesisContexts.empty() && + !getLangOpts().ModulesLocalVisibility) { +// Cache the fact that this definition is implicitly visible because +// there is a visible merged definition. +D->setVisibleDespiteOwningModule(); + } return true; +} return false; }; Modified: cfe/trunk/lib/Serialization/ASTReader.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=342019&r1=342018&r2=342019&view=diff == --- cfe/trunk/lib/Serialization/ASTReader.cpp (original) +++ cfe/trunk/lib/Serialization/ASTReader.cpp Tue Sep 11 19:13:48 2018 @@ -3780,22 +3780,15 @@ void ASTReader::makeModuleVisible(Module /// visible. void ASTReader::mergeDefinitionVisibility(NamedDecl *Def, NamedDecl *MergedDef) { - // FIXME: This doesn't correctly handle the case where MergedDef is visible - // in modules other than its owning module. We should instead give the - // ASTContext a list of merged definitions for Def. if (Def->isHidden()) { // If MergedDef is visible or becomes visible, make the definition visible. if (!MergedDef->isHidden()) Def->setVisibleDespiteOwningModule(); -else if (getContext().getLangOpts().ModulesLocalVisibility) { +else { getContext().mergeDefinitionIntoModule( Def, MergedDef->getImportedOwningModule(), /*NotifyListeners*/ false); PendingMergedDefinitionsToDeduplicate.insert(Def); -} else { - auto SubmoduleID = MergedDef->getOwningModuleID(); - assert(SubmoduleID && "hidden definition in no module"); - HiddenNamesMap[getSubmodule(SubmoduleID)].push_back(Def); } } } Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=342019&r1=342018&r2=342019&view=diff == --- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original) +++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Tue Sep 11 19:13:48 2018 @@ -4419,22 +4419,9 @@ void ASTDeclReader::UpdateDecl(Decl *D, case UPD_DECL_EXPORTED: { unsigned SubmoduleID = readSubmoduleID(); auto *Exported = cast(D); - if (auto *TD = dyn_cast(Exported)) -Exported = TD->getDefinition(); Module *Owner = SubmoduleID ? Reader.getSubmodule(SubmoduleID) : nullptr; - if (Reader.getContext().getLangOpts().ModulesLocalVisibility) { - Reader.getContext().mergeDefinitionIntoModule(cast(Exported), - Owner); -Reader