Hi,
The attached patch fixes PR9812 by splitting TST_bool into TST_bool (for
C++ bool) and TST__Bool (for C99 _Bool). They both still translate into
BuiltinType::Bool, but are now given the appropriate names in diagnostics.
One subtlety: BuiltinTypeLoc::getWrittenTypeSpec tries to convert
backwards from a BuiltinType to a TypeSpecifierType. I've arbitrarily made
this continue to produce TST_bool for BuiltinType::Bool, but this code is
actually not currently reachable: the function is only called by the AST
serialization code, and only in cases where the type cannot be bool.
OK to commit?
Richard
Index: test/Parser/cxx-bool.cpp
===================================================================
--- test/Parser/cxx-bool.cpp (revision 132879)
+++ test/Parser/cxx-bool.cpp (working copy)
@@ -1,4 +1,6 @@
-// RUN: %clang_cc1 -fsyntax-only %s
+// RUN: %clang_cc1 -fsyntax-only %s -verify
bool a = true;
bool b = false;
+
+signed bool c; // expected-error {{'bool' cannot be signed or unsigned}}
Index: test/Parser/types.c
===================================================================
--- test/Parser/types.c (revision 132879)
+++ test/Parser/types.c (working copy)
@@ -12,3 +12,4 @@
foo->x = 0;
}
+signed _Bool b; // expected-error {{'_Bool' cannot be signed or unsigned}}
Index: include/clang/Basic/Specifiers.h
===================================================================
--- include/clang/Basic/Specifiers.h (revision 132879)
+++ include/clang/Basic/Specifiers.h (working copy)
@@ -42,7 +42,8 @@
TST_int,
TST_float,
TST_double,
- TST_bool, // _Bool
+ TST_bool, // C++ bool
+ TST__Bool, // C99 _Bool
TST_decimal32, // _Decimal32
TST_decimal64, // _Decimal64
TST_decimal128, // _Decimal128
Index: include/clang/Sema/DeclSpec.h
===================================================================
--- include/clang/Sema/DeclSpec.h (revision 132879)
+++ include/clang/Sema/DeclSpec.h (working copy)
@@ -238,6 +238,7 @@
static const TST TST_float = clang::TST_float;
static const TST TST_double = clang::TST_double;
static const TST TST_bool = clang::TST_bool;
+ static const TST TST__Bool = clang::TST__Bool;
static const TST TST_decimal32 = clang::TST_decimal32;
static const TST TST_decimal64 = clang::TST_decimal64;
static const TST TST_decimal128 = clang::TST_decimal128;
Index: lib/Sema/DeclSpec.cpp
===================================================================
--- lib/Sema/DeclSpec.cpp (revision 132879)
+++ lib/Sema/DeclSpec.cpp (working copy)
@@ -296,7 +296,8 @@
case DeclSpec::TST_int: return "int";
case DeclSpec::TST_float: return "float";
case DeclSpec::TST_double: return "double";
- case DeclSpec::TST_bool: return "_Bool";
+ case DeclSpec::TST_bool: return "bool";
+ case DeclSpec::TST__Bool: return "_Bool";
case DeclSpec::TST_decimal32: return "_Decimal32";
case DeclSpec::TST_decimal64: return "_Decimal64";
case DeclSpec::TST_decimal128: return "_Decimal128";
@@ -504,7 +505,8 @@
}
TSTLoc = Loc;
TSTNameLoc = Loc;
- if (TypeAltiVecVector && (T == TST_bool) && !TypeAltiVecBool) {
+ if (TypeAltiVecVector && (T == TST_bool || T == TST__Bool) &&
+ !TypeAltiVecBool) {
TypeAltiVecBool = true;
return false;
}
Index: lib/Sema/SemaType.cpp
===================================================================
--- lib/Sema/SemaType.cpp (revision 132879)
+++ lib/Sema/SemaType.cpp (working copy)
@@ -726,6 +726,7 @@
declarator.setInvalidType(true);
}
break;
+ case DeclSpec::TST__Bool:
case DeclSpec::TST_bool: Result = Context.BoolTy; break; // _Bool or bool
case DeclSpec::TST_decimal32: // _Decimal32
case DeclSpec::TST_decimal64: // _Decimal64
Index: lib/Sema/SemaTemplateVariadic.cpp
===================================================================
--- lib/Sema/SemaTemplateVariadic.cpp (revision 132879)
+++ lib/Sema/SemaTemplateVariadic.cpp (working copy)
@@ -642,6 +642,7 @@
case TST_float:
case TST_double:
case TST_bool:
+ case TST__Bool:
case TST_decimal32:
case TST_decimal64:
case TST_decimal128:
Index: lib/AST/TypeLoc.cpp
===================================================================
--- lib/AST/TypeLoc.cpp (revision 132879)
+++ lib/AST/TypeLoc.cpp (working copy)
@@ -201,6 +201,7 @@
case BuiltinType::Void:
return TST_void;
case BuiltinType::Bool:
+ // FIXME: In C99, this came from TST__Bool.
return TST_bool;
case BuiltinType::Char_U:
case BuiltinType::Char_S:
Index: lib/Parse/ParseDecl.cpp
===================================================================
--- lib/Parse/ParseDecl.cpp (revision 132879)
+++ lib/Parse/ParseDecl.cpp (working copy)
@@ -1523,7 +1523,8 @@
// static const bool __is_signed;
//
// then treat __is_signed as an identifier rather than as a keyword.
- if (DS.getTypeSpecType() == TST_bool &&
+ if ((DS.getTypeSpecType() == TST_bool ||
+ DS.getTypeSpecType() == TST__Bool) &&
DS.getTypeQualifiers() == DeclSpec::TQ_const &&
DS.getStorageClassSpec() == DeclSpec::SCS_static) {
Tok.getIdentifierInfo()->RevertTokenIDToIdentifier();
@@ -1806,8 +1807,9 @@
Tok.setKind(tok::identifier);
isInvalid = true;
} else {
- isInvalid = DS.SetTypeSpecType(DeclSpec::TST_bool, Loc, PrevSpec,
- DiagID);
+ isInvalid = DS.SetTypeSpecType(
+ Tok.is(tok::kw_bool) ? DeclSpec::TST_bool : DeclSpec::TST__Bool,
+ Loc, PrevSpec, DiagID);
}
break;
case tok::kw__Decimal32:
@@ -2092,9 +2094,11 @@
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_char32, Loc, PrevSpec, DiagID);
break;
case tok::kw_bool:
- case tok::kw__Bool:
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_bool, Loc, PrevSpec, DiagID);
break;
+ case tok::kw__Bool:
+ isInvalid = DS.SetTypeSpecType(DeclSpec::TST__Bool, Loc, PrevSpec, DiagID);
+ break;
case tok::kw__Decimal32:
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal32, Loc, PrevSpec,
DiagID);_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits