initial support for recognizing __transparent_union__ attributes
comments on the ML will follow llvm-svn: 50262
This commit is contained in:
parent
59834d1c7a
commit
0276933b4b
|
@ -36,7 +36,8 @@ public:
|
||||||
Format,
|
Format,
|
||||||
Visibility,
|
Visibility,
|
||||||
FastCall,
|
FastCall,
|
||||||
StdCall
|
StdCall,
|
||||||
|
TransparentUnion
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -218,6 +219,16 @@ public:
|
||||||
static bool classof(const StdCallAttr *A) { return true; }
|
static bool classof(const StdCallAttr *A) { return true; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class TransparentUnionAttr : public Attr {
|
||||||
|
public:
|
||||||
|
TransparentUnionAttr() : Attr(TransparentUnion) {}
|
||||||
|
|
||||||
|
// Implement isa/cast/dyncast/etc.
|
||||||
|
|
||||||
|
static bool classof(const Attr *A) { return A->getKind() == TransparentUnion; }
|
||||||
|
static bool classof(const TransparentUnionAttr *A) { return true; }
|
||||||
|
};
|
||||||
|
|
||||||
} // end namespace clang
|
} // end namespace clang
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -64,6 +64,7 @@ public:
|
||||||
AT_stdcall,
|
AT_stdcall,
|
||||||
AT_nothrow,
|
AT_nothrow,
|
||||||
AT_noinline,
|
AT_noinline,
|
||||||
|
AT_transparent_union,
|
||||||
AT_warn_unused_result
|
AT_warn_unused_result
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -90,6 +90,9 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) {
|
||||||
case 15:
|
case 15:
|
||||||
if (!memcmp(Str, "ext_vector_type", 15)) return AT_ext_vector_type;
|
if (!memcmp(Str, "ext_vector_type", 15)) return AT_ext_vector_type;
|
||||||
break;
|
break;
|
||||||
|
case 17:
|
||||||
|
if (!memcmp(Str, "transparent_union", 17)) return AT_transparent_union;
|
||||||
|
break;
|
||||||
case 18:
|
case 18:
|
||||||
if (!memcmp(Str, "warn_unused_result", 18)) return AT_warn_unused_result;
|
if (!memcmp(Str, "warn_unused_result", 18)) return AT_warn_unused_result;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -323,6 +323,7 @@ private:
|
||||||
void HandleFormatAttribute(Decl *d, AttributeList *rawAttr);
|
void HandleFormatAttribute(Decl *d, AttributeList *rawAttr);
|
||||||
void HandleStdCallAttribute(Decl *d, AttributeList *rawAttr);
|
void HandleStdCallAttribute(Decl *d, AttributeList *rawAttr);
|
||||||
void HandleFastCallAttribute(Decl *d, AttributeList *rawAttr);
|
void HandleFastCallAttribute(Decl *d, AttributeList *rawAttr);
|
||||||
|
void HandleTransparentUnionAttribute(Decl *d, AttributeList *rawAttr);
|
||||||
|
|
||||||
void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
|
void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
|
||||||
bool &IncompleteImpl);
|
bool &IncompleteImpl);
|
||||||
|
|
|
@ -2003,6 +2003,9 @@ void Sema::HandleDeclAttribute(Decl *New, AttributeList *Attr) {
|
||||||
case AttributeList::AT_format:
|
case AttributeList::AT_format:
|
||||||
HandleFormatAttribute(New, Attr);
|
HandleFormatAttribute(New, Attr);
|
||||||
break;
|
break;
|
||||||
|
case AttributeList::AT_transparent_union:
|
||||||
|
HandleTransparentUnionAttribute(New, Attr);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
#if 0
|
#if 0
|
||||||
// TODO: when we have the full set of attributes, warn about unknown ones.
|
// TODO: when we have the full set of attributes, warn about unknown ones.
|
||||||
|
@ -2419,6 +2422,29 @@ void Sema::HandleFormatAttribute(Decl *d, AttributeList *rawAttr) {
|
||||||
Idx.getZExtValue(), FirstArg.getZExtValue()));
|
Idx.getZExtValue(), FirstArg.getZExtValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Sema::HandleTransparentUnionAttribute(Decl *d, AttributeList *rawAttr) {
|
||||||
|
// check the attribute arguments.
|
||||||
|
if (rawAttr->getNumArgs() != 0) {
|
||||||
|
Diag(rawAttr->getLoc(), diag::err_attribute_wrong_number_arguments,
|
||||||
|
std::string("0"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
TypeDecl *decl = dyn_cast<TypeDecl>(d);
|
||||||
|
|
||||||
|
if (!decl || !Context.getTypeDeclType(decl)->isUnionType()) {
|
||||||
|
Diag(rawAttr->getLoc(), diag::warn_attribute_wrong_decl_type,
|
||||||
|
"transparent_union", "union");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QualType QTy = Context.getTypeDeclType(decl);
|
||||||
|
const RecordType *Ty = QTy->getAsUnionType();
|
||||||
|
|
||||||
|
// FIXME
|
||||||
|
// Ty->addAttr(new TransparentUnionAttr());
|
||||||
|
}
|
||||||
|
|
||||||
void Sema::HandleAnnotateAttribute(Decl *d, AttributeList *rawAttr) {
|
void Sema::HandleAnnotateAttribute(Decl *d, AttributeList *rawAttr) {
|
||||||
// check the attribute arguments.
|
// check the attribute arguments.
|
||||||
if (rawAttr->getNumArgs() != 1) {
|
if (rawAttr->getNumArgs() != 1) {
|
||||||
|
|
Loading…
Reference in New Issue