[cfe-commits] r140931 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td include/clang/Sema/AttributeList.h include/clang/Sema/Sema.h lib/Sema/SemaDeclAttr.cpp lib/Sema/SemaExpr.cpp lib/Sema/SemaType.cpp test/Parser/MicrosoftExtensions.c
Nico Weber
thakis at chromium.org
Thu Oct 6 11:21:36 PDT 2011
Hi John,
this breaks the build of every project that uses glib and -Werror:
In file included from /usr/include/glib-2.0/glib/gasyncqueue.h:34:
/usr/include/glib-2.0/glib/gthread.h:348:27: error: 'may_alias'
attribute ignored when parsing type
if G_LIKELY ((gpointer) g_atomic_pointer_get (value_location) != NULL)
~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gatomic.h:73:46: note: expanded from:
(g_atomic_pointer_get) ((volatile gpointer G_GNUC_MAY_ALIAS *) (void
*) (atomic)))
^
/usr/include/glib-2.0/glib/gmacros.h:111:43: note: expanded from:
# define G_GNUC_MAY_ALIAS __attribute__((may_alias))
^
/usr/include/glib-2.0/glib/gmacros.h:273:25: note: expanded from:
#define G_LIKELY(expr) (expr)
^~~~
Thoughts? Should this be a disablable warning?
Nico
On Fri, Sep 30, 2011 at 10:17 PM, John McCall <rjmccall at apple.com> wrote:
> Author: rjmccall
> Date: Sat Oct 1 00:17:03 2011
> New Revision: 140931
>
> URL: http://llvm.org/viewvc/llvm-project?rev=140931&view=rev
> Log:
> Hey, maybe we shouldn't silently ignore decl attributes
> on declarators written as types.
>
>
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/include/clang/Sema/AttributeList.h
> cfe/trunk/include/clang/Sema/Sema.h
> cfe/trunk/lib/Sema/SemaDeclAttr.cpp
> cfe/trunk/lib/Sema/SemaExpr.cpp
> cfe/trunk/lib/Sema/SemaType.cpp
> cfe/trunk/test/Parser/MicrosoftExtensions.c
> cfe/trunk/test/Sema/types.c
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=140931&r1=140930&r2=140931&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sat Oct 1 00:17:03 2011
> @@ -1435,6 +1435,8 @@
> def err_invalid_pcs : Error<"Invalid PCS type">;
> def err_attribute_can_be_applied_only_to_value_decl : Error<
> "%0 attribute can only be applied to value declarations">;
> +def warn_attribute_not_on_decl : Error<
> + "%0 attribute ignored when parsing type">;
>
>
> // Availability attribute
>
> Modified: cfe/trunk/include/clang/Sema/AttributeList.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/AttributeList.h?rev=140931&r1=140930&r2=140931&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Sema/AttributeList.h (original)
> +++ cfe/trunk/include/clang/Sema/AttributeList.h Sat Oct 1 00:17:03 2011
> @@ -73,6 +73,9 @@
> /// True if already diagnosed as invalid.
> mutable unsigned Invalid : 1;
>
> + /// True if this attribute was used as a type attribute.
> + mutable unsigned UsedAsTypeAttr : 1;
> +
> /// True if this has the extra information associated with an
> /// availability attribute.
> unsigned IsAvailability : 1;
> @@ -123,7 +126,8 @@
> AttrRange(attrRange), ScopeLoc(scopeLoc), ParmLoc(parmLoc),
> NumArgs(numArgs),
> DeclspecAttribute(declspec), CXX0XAttribute(cxx0x), Invalid(false),
> - IsAvailability(false), NextInPosition(0), NextInPool(0) {
> + UsedAsTypeAttr(false), IsAvailability(false),
> + NextInPosition(0), NextInPool(0) {
> if (numArgs) memcpy(getArgsBuffer(), args, numArgs * sizeof(Expr*));
> AttrKind = getKind(getName());
> }
> @@ -139,8 +143,8 @@
> : AttrName(attrName), ScopeName(scopeName), ParmName(parmName),
> AttrRange(attrRange), ScopeLoc(scopeLoc), ParmLoc(parmLoc),
> NumArgs(0), DeclspecAttribute(declspec), CXX0XAttribute(cxx0x),
> - Invalid(false), IsAvailability(true), UnavailableLoc(unavailable),
> - NextInPosition(0), NextInPool(0) {
> + Invalid(false), UsedAsTypeAttr(false), IsAvailability(true),
> + UnavailableLoc(unavailable), NextInPosition(0), NextInPool(0) {
> new (&getAvailabilitySlot(IntroducedSlot)) AvailabilityChange(introduced);
> new (&getAvailabilitySlot(DeprecatedSlot)) AvailabilityChange(deprecated);
> new (&getAvailabilitySlot(ObsoletedSlot)) AvailabilityChange(obsoleted);
> @@ -287,6 +291,9 @@
> bool isInvalid() const { return Invalid; }
> void setInvalid(bool b = true) const { Invalid = b; }
>
> + bool isUsedAsTypeAttr() const { return UsedAsTypeAttr; }
> + void setUsedAsTypeAttr() { UsedAsTypeAttr = true; }
> +
> Kind getKind() const { return Kind(AttrKind); }
> static Kind getKind(const IdentifierInfo *Name);
>
>
> Modified: cfe/trunk/include/clang/Sema/Sema.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=140931&r1=140930&r2=140931&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Sema/Sema.h (original)
> +++ cfe/trunk/include/clang/Sema/Sema.h Sat Oct 1 00:17:03 2011
> @@ -1829,6 +1829,8 @@
> void ProcessDeclAttributeList(Scope *S, Decl *D, const AttributeList *AL,
> bool NonInheritable = true, bool Inheritable = true);
>
> + void checkUnusedDeclAttributes(Declarator &D);
> +
> bool CheckRegparmAttr(const AttributeList &attr, unsigned &value);
> bool CheckCallingConvAttr(const AttributeList &attr, CallingConv &CC);
> bool CheckNoReturnAttr(const AttributeList &attr);
>
> Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=140931&r1=140930&r2=140931&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Sat Oct 1 00:17:03 2011
> @@ -3719,6 +3719,34 @@
> }
> }
>
> +/// checkUnusedDeclAttributes - Check a list of attributes to see if it
> +/// contains any decl attributes that we should warn about.
> +static void checkUnusedDeclAttributes(Sema &S, const AttributeList *A) {
> + for ( ; A; A = A->getNext()) {
> + // Only warn if the attribute is an unignored, non-type attribute.
> + if (A->isUsedAsTypeAttr()) continue;
> + if (A->getKind() == AttributeList::IgnoredAttribute) continue;
> +
> + if (A->getKind() == AttributeList::UnknownAttribute) {
> + S.Diag(A->getLoc(), diag::warn_unknown_attribute_ignored)
> + << A->getName() << A->getRange();
> + } else {
> + S.Diag(A->getLoc(), diag::warn_attribute_not_on_decl)
> + << A->getName() << A->getRange();
> + }
> + }
> +}
> +
> +/// checkUnusedDeclAttributes - Given a declarator which is not being
> +/// used to build a declaration, complain about any decl attributes
> +/// which might be lying around on it.
> +void Sema::checkUnusedDeclAttributes(Declarator &D) {
> + ::checkUnusedDeclAttributes(*this, D.getDeclSpec().getAttributes().getList());
> + ::checkUnusedDeclAttributes(*this, D.getAttributes());
> + for (unsigned i = 0, e = D.getNumTypeObjects(); i != e; ++i)
> + ::checkUnusedDeclAttributes(*this, D.getTypeObject(i).getAttrs());
> +}
> +
> /// DeclClonePragmaWeak - clone existing decl (maybe definition),
> /// #pragma weak needs a non-definition decl and source may not have one
> NamedDecl * Sema::DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II,
>
> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=140931&r1=140930&r2=140931&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Sat Oct 1 00:17:03 2011
> @@ -4291,6 +4291,8 @@
> CheckExtraCXXDefaultArguments(D);
> }
>
> + checkUnusedDeclAttributes(D);
> +
> QualType castType = castTInfo->getType();
> Ty = CreateParsedType(castType, castTInfo);
>
>
> Modified: cfe/trunk/lib/Sema/SemaType.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=140931&r1=140930&r2=140931&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaType.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaType.cpp Sat Oct 1 00:17:03 2011
> @@ -3064,6 +3064,9 @@
> if (D.isInvalidType())
> return true;
>
> + // Make sure there are no unused decl attributes on the declarator.
> + checkUnusedDeclAttributes(D);
> +
> if (getLangOptions().CPlusPlus) {
> // Check that there are no default arguments (C++ only).
> CheckExtraCXXDefaultArguments(D);
> @@ -3758,30 +3761,37 @@
>
> case AttributeList::AT_address_space:
> HandleAddressSpaceTypeAttribute(type, attr, state.getSema());
> + attr.setUsedAsTypeAttr();
> break;
> OBJC_POINTER_TYPE_ATTRS_CASELIST:
> if (!handleObjCPointerTypeAttr(state, attr, type))
> distributeObjCPointerTypeAttr(state, attr, type);
> + attr.setUsedAsTypeAttr();
> break;
> case AttributeList::AT_vector_size:
> HandleVectorSizeAttr(type, attr, state.getSema());
> + attr.setUsedAsTypeAttr();
> break;
> case AttributeList::AT_ext_vector_type:
> if (state.getDeclarator().getDeclSpec().getStorageClassSpec()
> != DeclSpec::SCS_typedef)
> HandleExtVectorTypeAttr(type, attr, state.getSema());
> + attr.setUsedAsTypeAttr();
> break;
> case AttributeList::AT_neon_vector_type:
> HandleNeonVectorTypeAttr(type, attr, state.getSema(),
> VectorType::NeonVector, "neon_vector_type");
> + attr.setUsedAsTypeAttr();
> break;
> case AttributeList::AT_neon_polyvector_type:
> HandleNeonVectorTypeAttr(type, attr, state.getSema(),
> VectorType::NeonPolyVector,
> "neon_polyvector_type");
> + attr.setUsedAsTypeAttr();
> break;
> case AttributeList::AT_opencl_image_access:
> HandleOpenCLImageAccessAttribute(type, attr, state.getSema());
> + attr.setUsedAsTypeAttr();
> break;
>
> case AttributeList::AT_ns_returns_retained:
> @@ -3790,6 +3800,8 @@
> // fallthrough into the function attrs
>
> FUNCTION_TYPE_ATTRS_CASELIST:
> + attr.setUsedAsTypeAttr();
> +
> // Never process function type attributes as part of the
> // declaration-specifiers.
> if (isDeclSpec)
>
> Modified: cfe/trunk/test/Parser/MicrosoftExtensions.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/MicrosoftExtensions.c?rev=140931&r1=140930&r2=140931&view=diff
> ==============================================================================
> --- cfe/trunk/test/Parser/MicrosoftExtensions.c (original)
> +++ cfe/trunk/test/Parser/MicrosoftExtensions.c Sat Oct 1 00:17:03 2011
> @@ -11,11 +11,11 @@
>
> void * __ptr64 PtrToPtr64(const void *p)
> {
> - return((void * __ptr64) (unsigned __int64) (ULONG_PTR)p );
> + return((void * __ptr64) (unsigned __int64) (ULONG_PTR)p ); // expected-warning {{unknown attribute '__ptr64' ignored}}
> }
> void * __ptr32 PtrToPtr32(const void *p)
> {
> - return((void * __ptr32) (unsigned __int32) (ULONG_PTR)p );
> + return((void * __ptr32) (unsigned __int32) (ULONG_PTR)p ); // expected-warning {{unknown attribute '__ptr32' ignored}}
> }
>
> void __forceinline InterlockedBitTestAndSet (long *Base, long Bit)
>
> Modified: cfe/trunk/test/Sema/types.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/types.c?rev=140931&r1=140930&r2=140931&view=diff
> ==============================================================================
> --- cfe/trunk/test/Sema/types.c (original)
> +++ cfe/trunk/test/Sema/types.c Sat Oct 1 00:17:03 2011
> @@ -37,3 +37,7 @@
>
> // rdar://6880951
> int __attribute__ ((vector_size (8), vector_size (8))) v; // expected-error {{invalid vector element type}}
> +
> +void test(int i) {
> + char c = (char __attribute__((align(8)))) i; // expected-error {{'align' attribute ignored when parsing type}}
> +}
>
>
> _______________________________________________
> 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