[cfe-commits] r104941 - in /cfe/trunk: include/clang/AST/Decl.h include/clang/Basic/DiagnosticSemaKinds.td include/clang/Parse/AttributeList.h lib/AST/Decl.cpp lib/Basic/Targets.cpp lib/Frontend/PCHReaderDecl.cpp lib/Frontend/PCHWriterDecl.cpp lib/Parse/AttributeList.cpp lib/Sema/SemaDeclAttr.cpp lib/Sema/SemaLookup.cpp test/CXX/basic/basic.lookup/basic.lookup.argdep/p2.cpp
Douglas Gregor
dgregor at apple.com
Fri May 28 09:40:05 PDT 2010
On May 28, 2010, at 1:20 AM, John McCall wrote:
> Author: rjmccall
> Date: Fri May 28 03:20:36 2010
> New Revision: 104941
>
> URL: http://llvm.org/viewvc/llvm-project?rev=104941&view=rev
> Log:
> Add a new attribute on records, __attribute__((adl_invisible)), and define
> the x86-64 __va_list_tag with this attribute. The attribute causes the
> affected type to behave like a fundamental type when considered by ADL.
>
> (x86-64 is the only target we currently provide with a struct-based
> __builtin_va_list)
>
> Fixes PR6762.
This is a very heavy solution for a relatively small bug. There aren't any types other than the magical __va_list_tag that have this behavior, so introducing a user-visible attribute for it seems premature. Why not just go for the narrow fix of recognizing __va_list_tag within the ADL routines and ignoring it?
- Doug
>
> Modified:
> cfe/trunk/include/clang/AST/Decl.h
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/include/clang/Parse/AttributeList.h
> cfe/trunk/lib/AST/Decl.cpp
> cfe/trunk/lib/Basic/Targets.cpp
> cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
> cfe/trunk/lib/Frontend/PCHWriterDecl.cpp
> cfe/trunk/lib/Parse/AttributeList.cpp
> cfe/trunk/lib/Sema/SemaDeclAttr.cpp
> cfe/trunk/lib/Sema/SemaLookup.cpp
> cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2.cpp
>
> Modified: cfe/trunk/include/clang/AST/Decl.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=104941&r1=104940&r2=104941&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/AST/Decl.h (original)
> +++ cfe/trunk/include/clang/AST/Decl.h Fri May 28 03:20:36 2010
> @@ -1999,6 +1999,11 @@
> /// containing an object.
> bool HasObjectMember : 1;
>
> + /// InvisibleToADL - This is true if this struct is invisible to
> + /// argument-dependent lookup. Certain builtin types have this
> + /// property.
> + bool InvisibleToADL : 1;
> +
> protected:
> RecordDecl(Kind DK, TagKind TK, DeclContext *DC,
> SourceLocation L, IdentifierInfo *Id,
> @@ -2041,6 +2046,18 @@
> bool hasObjectMember() const { return HasObjectMember; }
> void setHasObjectMember (bool val) { HasObjectMember = val; }
>
> + /// \brief Determines whether this type is invisible to C++
> + /// argument-dependent lookup.
> + ///
> + /// Types with this bit set behave like fundamental types: they are
> + /// never associated classes, and they do not add their contexts as
> + /// associated namespaces.
> + ///
> + /// This can be specified in user code as __attribute__((adl_invisible)),
> + /// but it's generally better not to.
> + bool isInvisibleToADL() const { return InvisibleToADL; }
> + void setInvisibleToADL(bool val = true) { InvisibleToADL = val; }
> +
> /// \brief Determines whether this declaration represents the
> /// injected class name.
> ///
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=104941&r1=104940&r2=104941&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri May 28 03:20:36 2010
> @@ -884,9 +884,9 @@
> def err_attribute_wrong_decl_type : Error<
> "%0 attribute only applies to %select{function|union|"
> "variable and function|function or method|parameter|"
> - "parameter or Objective-C method |function, method or block|"
> + "parameter or Objective-C method|function, method or block|"
> "virtual method or class|function, method, or parameter|class|virtual method"
> - "|member}1 types">;
> + "|member|struct or union}1 types">;
> def warn_function_attribute_wrong_type : Warning<
> "%0 only applies to function types; type here is %1">;
> def warn_gnu_inline_attribute_requires_inline : Warning<
>
> Modified: cfe/trunk/include/clang/Parse/AttributeList.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/AttributeList.h?rev=104941&r1=104940&r2=104941&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Parse/AttributeList.h (original)
> +++ cfe/trunk/include/clang/Parse/AttributeList.h Fri May 28 03:20:36 2010
> @@ -115,6 +115,7 @@
> AT_weakref,
> AT_weak_import,
> AT_reqd_wg_size,
> + AT_adl_invisible,
> IgnoredAttribute,
> UnknownAttribute
> };
>
> Modified: cfe/trunk/lib/AST/Decl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=104941&r1=104940&r2=104941&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/Decl.cpp (original)
> +++ cfe/trunk/lib/AST/Decl.cpp Fri May 28 03:20:36 2010
> @@ -1596,6 +1596,7 @@
> HasFlexibleArrayMember = false;
> AnonymousStructOrUnion = false;
> HasObjectMember = false;
> + InvisibleToADL = false;
> assert(classof(static_cast<Decl*>(this)) && "Invalid Kind!");
> }
>
>
> Modified: cfe/trunk/lib/Basic/Targets.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=104941&r1=104940&r2=104941&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Basic/Targets.cpp (original)
> +++ cfe/trunk/lib/Basic/Targets.cpp Fri May 28 03:20:36 2010
> @@ -1272,7 +1272,7 @@
> " unsigned fp_offset;"
> " void* overflow_arg_area;"
> " void* reg_save_area;"
> - "} __va_list_tag;"
> + "} __attribute__((adl_invisible)) __va_list_tag;"
> "typedef __va_list_tag __builtin_va_list[1];";
> }
>
>
> Modified: cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderDecl.cpp?rev=104941&r1=104940&r2=104941&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Frontend/PCHReaderDecl.cpp (original)
> +++ cfe/trunk/lib/Frontend/PCHReaderDecl.cpp Fri May 28 03:20:36 2010
> @@ -171,6 +171,7 @@
> RD->setHasFlexibleArrayMember(Record[Idx++]);
> RD->setAnonymousStructOrUnion(Record[Idx++]);
> RD->setHasObjectMember(Record[Idx++]);
> + RD->setInvisibleToADL(Record[Idx++]);
> }
>
> void PCHDeclReader::VisitValueDecl(ValueDecl *VD) {
>
> Modified: cfe/trunk/lib/Frontend/PCHWriterDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriterDecl.cpp?rev=104941&r1=104940&r2=104941&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Frontend/PCHWriterDecl.cpp (original)
> +++ cfe/trunk/lib/Frontend/PCHWriterDecl.cpp Fri May 28 03:20:36 2010
> @@ -169,6 +169,7 @@
> Record.push_back(D->hasFlexibleArrayMember());
> Record.push_back(D->isAnonymousStructOrUnion());
> Record.push_back(D->hasObjectMember());
> + Record.push_back(D->isInvisibleToADL());
> Code = pch::DECL_RECORD;
> }
>
>
> Modified: cfe/trunk/lib/Parse/AttributeList.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/AttributeList.cpp?rev=104941&r1=104940&r2=104941&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Parse/AttributeList.cpp (original)
> +++ cfe/trunk/lib/Parse/AttributeList.cpp Fri May 28 03:20:36 2010
> @@ -120,6 +120,7 @@
> .Case("cf_returns_retained", AT_cf_returns_retained)
> .Case("reqd_work_group_size", AT_reqd_wg_size)
> .Case("no_instrument_function", AT_no_instrument_function)
> + .Case("adl_invisible", AT_adl_invisible)
> .Case("thiscall", AT_thiscall)
> .Case("__cdecl", AT_cdecl)
> .Case("__stdcall", AT_stdcall)
>
> Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=104941&r1=104940&r2=104941&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri May 28 03:20:36 2010
> @@ -703,7 +703,7 @@
>
> static void HandleObjCNSObject(Decl *D, const AttributeList &Attr, Sema &S) {
> if (Attr.getNumArgs() != 0) {
> - S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 1;
> + S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0;
> return;
> }
> if (TypedefDecl *TD = dyn_cast<TypedefDecl>(D)) {
> @@ -720,7 +720,7 @@
> static void
> HandleOverloadableAttr(Decl *D, const AttributeList &Attr, Sema &S) {
> if (Attr.getNumArgs() != 0) {
> - S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 1;
> + S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0;
> return;
> }
>
> @@ -732,6 +732,21 @@
> D->addAttr(::new (S.Context) OverloadableAttr());
> }
>
> +static void HandleADLInvisibleAttr(Decl *d, const AttributeList &Attr, Sema &S) {
> + if (Attr.getNumArgs() != 0) {
> + S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0;
> + return;
> + }
> +
> + if (!isa<RecordDecl>(d)) {
> + S.Diag(Attr.getLoc(), diag::err_attribute_wrong_decl_type)
> + << "adl_invisible" << 12;
> + return;
> + }
> +
> + cast<RecordDecl>(d)->setInvisibleToADL();
> +}
> +
> static void HandleBlocksAttr(Decl *d, const AttributeList &Attr, Sema &S) {
> if (!Attr.getParameterName()) {
> S.Diag(Attr.getLoc(), diag::err_attribute_argument_n_not_string)
> @@ -941,7 +956,7 @@
> Sema &S) {
> // Attribute has 3 arguments.
> if (Attr.getNumArgs() != 3) {
> - S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 1;
> + S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 3;
> return;
> }
>
> @@ -1969,6 +1984,7 @@
> HandleObjCExceptionAttr(D, Attr, S);
> break;
> case AttributeList::AT_overloadable:HandleOverloadableAttr(D, Attr, S); break;
> + case AttributeList::AT_adl_invisible: HandleADLInvisibleAttr(D, Attr, S); break;
> case AttributeList::AT_nsobject: HandleObjCNSObject (D, Attr, S); break;
> case AttributeList::AT_blocks: HandleBlocksAttr (D, Attr, S); break;
> case AttributeList::AT_sentinel: HandleSentinelAttr (D, Attr, S); break;
>
> Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=104941&r1=104940&r2=104941&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaLookup.cpp Fri May 28 03:20:36 2010
> @@ -1500,6 +1500,10 @@
> ASTContext &Context,
> Sema::AssociatedNamespaceSet &AssociatedNamespaces,
> Sema::AssociatedClassSet &AssociatedClasses) {
> +
> + // Some classes are invisible to ADL.
> + if (Class->isInvisibleToADL()) return;
> +
> // C++ [basic.lookup.koenig]p2:
> // [...]
> // -- If T is a class type (including unions), its associated
>
> Modified: cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2.cpp?rev=104941&r1=104940&r2=104941&view=diff
> ==============================================================================
> --- cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2.cpp (original)
> +++ cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2.cpp Fri May 28 03:20:36 2010
> @@ -97,3 +97,14 @@
> foo(&bar);
> }
> }
> +
> +// PR6762: __builtin_va_list should be invisible to ADL on all platforms.
> +void test6_function(__builtin_va_list &argv);
> +namespace test6 {
> + void test6_function(__builtin_va_list &argv);
> +
> + void test() {
> + __builtin_va_list args;
> + test6_function(args);
> + }
> +}
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list