mirror of
https://github.com/llvm/llvm-project.git
synced 2025-05-02 02:36:07 +00:00
Handle __thread and storage-class-specifiers
llvm-svn: 38816
This commit is contained in:
parent
fe533e3ecd
commit
f63f89acc2
@ -21,7 +21,8 @@ using namespace clang;
|
||||
///
|
||||
unsigned DeclSpec::getParsedSpecifiers() const {
|
||||
unsigned Res = 0;
|
||||
if (StorageClassSpec != SCS_unspecified)
|
||||
if (StorageClassSpec != SCS_unspecified ||
|
||||
SCS_thread_specified)
|
||||
Res |= PQ_StorageClassSpecifier;
|
||||
|
||||
if (TypeQualifiers != TQ_unspecified)
|
||||
@ -33,11 +34,27 @@ unsigned DeclSpec::getParsedSpecifiers() const {
|
||||
TypeSpecType != TST_unspecified)
|
||||
Res |= PQ_TypeSpecifier;
|
||||
|
||||
if (FuncSpec != FS_unspecified)
|
||||
if (FS_inline_specified)
|
||||
Res |= PQ_FunctionSpecifier;
|
||||
return Res;
|
||||
}
|
||||
|
||||
static const char *getSpecifierName(DeclSpec::SCS S) {
|
||||
switch (S) {
|
||||
default: assert(0 && "Unknown typespec!");
|
||||
case DeclSpec::SCS_unspecified: return "unspecified";
|
||||
case DeclSpec::SCS_typedef: return "typedef";
|
||||
case DeclSpec::SCS_extern: return "extern";
|
||||
case DeclSpec::SCS_static: return "static";
|
||||
case DeclSpec::SCS_auto: return "auto";
|
||||
case DeclSpec::SCS_register: return "register";
|
||||
}
|
||||
}
|
||||
|
||||
static bool BadSpecifier(DeclSpec::SCS S, const char *&PrevSpec) {
|
||||
PrevSpec = getSpecifierName(S);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool BadSpecifier(DeclSpec::TSW W, const char *&PrevSpec) {
|
||||
switch (W) {
|
||||
@ -99,6 +116,14 @@ static bool BadSpecifier(DeclSpec::TQ T, const char *&PrevSpec) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DeclSpec::SetStorageClassSpec(SCS S, const char *&PrevSpec) {
|
||||
if (StorageClassSpec != SCS_unspecified)
|
||||
return BadSpecifier(StorageClassSpec, PrevSpec);
|
||||
StorageClassSpec = S;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/// These methods set the specified attribute of the DeclSpec, but return true
|
||||
/// and ignore the request if invalid (e.g. "extern" then "auto" is
|
||||
/// specified).
|
||||
@ -139,12 +164,6 @@ bool DeclSpec::SetTypeQual(TQ T, const char *&PrevSpec,
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DeclSpec::SetFuncSpec(FS F, const char *&PrevSpec) {
|
||||
// 'inline inline' is ok.
|
||||
FuncSpec = F;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Finish - This does final analysis of the declspec, rejecting things like
|
||||
/// "_Imaginary" (lacking an FP type). This returns a diagnostic to issue or
|
||||
/// diag::NUM_DIAGNOSTICS if there is no error. After calling this method,
|
||||
@ -196,7 +215,7 @@ void DeclSpec::Finish(SourceLocation Loc, Diagnostic &D,
|
||||
D.Report(Loc, diag::ext_plain_complex);
|
||||
TypeSpecType = TST_double; // _Complex -> _Complex double.
|
||||
} else if (TypeSpecType == TST_int || TypeSpecType == TST_char) {
|
||||
// Note that GCC doesn't support _Complex _Bool.
|
||||
// Note that this intentionally doesn't include _Complex _Bool.
|
||||
D.Report(Loc, diag::ext_integer_complex);
|
||||
} else if (TypeSpecType != TST_float && TypeSpecType != TST_double) {
|
||||
D.Report(Loc, diag::err_invalid_complex_spec,
|
||||
@ -213,5 +232,18 @@ void DeclSpec::Finish(SourceLocation Loc, Diagnostic &D,
|
||||
|
||||
// Okay, now we can infer the real type.
|
||||
|
||||
|
||||
// Verify __thread.
|
||||
if (SCS_thread_specified) {
|
||||
if (StorageClassSpec == SCS_unspecified) {
|
||||
StorageClassSpec = SCS_extern; // '__thread int' -> 'extern __thread int'
|
||||
} else if (StorageClassSpec != SCS_extern &&
|
||||
StorageClassSpec != SCS_static) {
|
||||
D.Report(Loc, diag::err_invalid_thread_spec,
|
||||
getSpecifierName(StorageClassSpec));
|
||||
SCS_thread_specified = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 'data definition has no type or storage class'?
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ using namespace clang;
|
||||
/// [C99] function-specifier declaration-specifiers [opt]
|
||||
/// [GNU] attributes declaration-specifiers [opt] [TODO]
|
||||
///
|
||||
/// storage-class-specifier: [C99 6.7.1] [TODO]
|
||||
/// storage-class-specifier: [C99 6.7.1]
|
||||
/// 'typedef'
|
||||
/// 'extern'
|
||||
/// 'static'
|
||||
@ -51,6 +51,7 @@ using namespace clang;
|
||||
/// [GNU] '_Decimal32'
|
||||
/// [GNU] '_Decimal64'
|
||||
/// [GNU] '_Decimal128'
|
||||
/// [GNU] typeof-specifier [TODO]
|
||||
/// [OBJC] class-name objc-protocol-refs [opt] [TODO]
|
||||
/// [OBJC] typedef-name objc-protocol-refs [TODO]
|
||||
/// [OBJC] objc-protocol-refs [TODO]
|
||||
@ -75,6 +76,34 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS) {
|
||||
// specifiers. First verify that DeclSpec's are consistent.
|
||||
DS.Finish(StartLoc, Diags, getLang());
|
||||
return;
|
||||
|
||||
// storage-class-specifier
|
||||
case tok::kw_typedef:
|
||||
isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_typedef, PrevSpec);
|
||||
break;
|
||||
case tok::kw_extern:
|
||||
if (DS.SCS_thread_specified)
|
||||
Diag(Tok, diag::ext_thread_before, "extern");
|
||||
isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_extern, PrevSpec);
|
||||
break;
|
||||
case tok::kw_static:
|
||||
if (DS.SCS_thread_specified)
|
||||
Diag(Tok, diag::ext_thread_before, "static");
|
||||
isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_static, PrevSpec);
|
||||
break;
|
||||
case tok::kw_auto:
|
||||
isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_auto, PrevSpec);
|
||||
break;
|
||||
case tok::kw_register:
|
||||
isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_register, PrevSpec);
|
||||
break;
|
||||
case tok::kw___thread:
|
||||
if (DS.SCS_thread_specified)
|
||||
isInvalid = 2, PrevSpec = "__thread";
|
||||
else
|
||||
DS.SCS_thread_specified = true;
|
||||
break;
|
||||
|
||||
// type-specifiers
|
||||
case tok::kw_short:
|
||||
isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_short, PrevSpec);
|
||||
@ -144,7 +173,8 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS) {
|
||||
|
||||
// function-specifier
|
||||
case tok::kw_inline:
|
||||
isInvalid = DS.SetFuncSpec(DeclSpec::FS_inline, PrevSpec);
|
||||
// 'inline inline' is ok.
|
||||
DS.FS_inline_specified = true;
|
||||
break;
|
||||
}
|
||||
// If the specifier combination wasn't legal, issue a diagnostic.
|
||||
|
@ -247,6 +247,8 @@ DIAG(ext_plain_complex, EXTENSION,
|
||||
"ISO C does not support plain '_Complex' meaning '_Complex double'")
|
||||
DIAG(ext_integer_complex, EXTENSION,
|
||||
"ISO C does not support complex integer types")
|
||||
DIAG(ext_thread_before, EXTENSION,
|
||||
"'__thread' before 'static'")
|
||||
|
||||
DIAG(err_invalid_decl_spec_combination, ERROR,
|
||||
"cannot combine with previous '%s' declaration specifier")
|
||||
@ -260,5 +262,7 @@ DIAG(err_invalid_longlong_spec, ERROR,
|
||||
"'long long %s' is invalid")
|
||||
DIAG(err_invalid_complex_spec, ERROR,
|
||||
"'_Complex %s' is invalid")
|
||||
DIAG(err_invalid_thread_spec, ERROR,
|
||||
"'__thread %s' is invalid")
|
||||
|
||||
#undef DIAG
|
||||
|
@ -36,6 +36,9 @@ public:
|
||||
SCS_register
|
||||
} StorageClassSpec : 3;
|
||||
|
||||
// storage-class-specifier
|
||||
bool SCS_thread_specified : 1;
|
||||
|
||||
// type-specifier
|
||||
enum TSW {
|
||||
TSW_unspecified,
|
||||
@ -79,10 +82,7 @@ public:
|
||||
unsigned TypeQualifiers : 3; // Bitwise OR of typequals.
|
||||
|
||||
// function-specifier
|
||||
enum FS {
|
||||
FS_unspecified,
|
||||
FS_inline
|
||||
} FuncSpec : 1;
|
||||
bool FS_inline_specified : 1;
|
||||
|
||||
// attributes.
|
||||
// FIXME: implement declspec attributes.
|
||||
@ -98,12 +98,13 @@ public:
|
||||
|
||||
DeclSpec()
|
||||
: StorageClassSpec(SCS_unspecified),
|
||||
SCS_thread_specified(false),
|
||||
TypeSpecWidth(TSW_unspecified),
|
||||
TypeSpecComplex(TSC_unspecified),
|
||||
TypeSpecSign(TSS_unspecified),
|
||||
TypeSpecType(TST_unspecified),
|
||||
TypeQualifiers(TSS_unspecified),
|
||||
FuncSpec(FS_unspecified) {
|
||||
FS_inline_specified(false) {
|
||||
}
|
||||
|
||||
/// getParsedSpecifiers - Return a bitmask of which flavors of specifiers this
|
||||
@ -114,11 +115,11 @@ public:
|
||||
/// These methods set the specified attribute of the DeclSpec, but return true
|
||||
/// and ignore the request if invalid (e.g. "extern" then "auto" is
|
||||
/// specified). The name of the previous specifier is returned in prevspec.
|
||||
bool SetStorageClassSpec(SCS S, const char *&PrevSpec);
|
||||
bool SetTypeSpecWidth(TSW W, const char *&PrevSpec);
|
||||
bool SetTypeSpecComplex(TSC C, const char *&PrevSpec);
|
||||
bool SetTypeSpecSign(TSS S, const char *&PrevSpec);
|
||||
bool SetTypeSpecType(TST T, const char *&PrevSpec);
|
||||
bool SetFuncSpec(FS F, const char *&PrevSpec);
|
||||
|
||||
bool SetTypeQual(TQ T, const char *&PrevSpec, const LangOptions &Lang);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user