diff options
-rw-r--r-- | clang/include/clang/AST/ASTContext.h | 6 | ||||
-rw-r--r-- | clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 | ||||
-rw-r--r-- | clang/include/clang/Sema/Sema.h | 2 | ||||
-rw-r--r-- | clang/lib/AST/ASTContext.cpp | 15 | ||||
-rw-r--r-- | clang/lib/Sema/Sema.cpp | 8 | ||||
-rw-r--r-- | clang/lib/Sema/SemaLookup.cpp | 8 | ||||
-rw-r--r-- | clang/lib/Sema/SemaType.cpp | 6 | ||||
-rw-r--r-- | clang/test/Sema/128bitfloat.cc | 13 |
8 files changed, 58 insertions, 2 deletions
diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index 830a956ca96..ebbf6c99e66 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -196,6 +196,9 @@ class ASTContext : public RefCountedBase<ASTContext> { /// \brief The typedef for the __uint128_t type. mutable TypedefDecl *UInt128Decl; + + /// \brief The typedef for the __float128 stub type. + mutable TypeDecl *Float128StubDecl; /// \brief The typedef for the target specific predefined /// __builtin_va_list type. @@ -808,6 +811,9 @@ public: /// \brief Retrieve the declaration for the 128-bit unsigned integer type. TypedefDecl *getUInt128Decl() const; + + /// \brief Retrieve the declaration for a 128-bit float stub type. + TypeDecl *getFloat128StubType() const; //===--------------------------------------------------------------------===// // Type Constructors diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 1873ef02e9c..cf1e6dc3ac8 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -4308,6 +4308,8 @@ def err_typecheck_pointer_arith_void_type : Error< "arithmetic on%select{ a|}0 pointer%select{|s}0 to void">; def err_typecheck_decl_incomplete_type : Error< "variable has incomplete type %0">; +def err_typecheck_decl_incomplete_type___float128 : Error< + "support for type '__float128' is not yet implemented">; def ext_typecheck_decl_incomplete_type : ExtWarn< "tentative definition of variable with internal linkage has incomplete non-array type %0">, InGroup<DiagGroup<"tentative-definition-incomplete-type">>; diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index f45b089e044..f0bcc401552 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -7612,6 +7612,7 @@ private: Scope *CurScope; mutable IdentifierInfo *Ident_super; + mutable IdentifierInfo *Ident___float128; protected: friend class Parser; @@ -7631,6 +7632,7 @@ public: Scope *getCurScope() const { return CurScope; } IdentifierInfo *getSuperIdentifier() const; + IdentifierInfo *getFloat128Identifier() const; Decl *getObjCDeclContext() const; diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index c76ed5fdb98..870e09cc674 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -698,7 +698,7 @@ ASTContext::ASTContext(LangOptions& LOpts, SourceManager &SM, DependentTemplateSpecializationTypes(this_()), SubstTemplateTemplateParmPacks(this_()), GlobalNestedNameSpecifier(0), - Int128Decl(0), UInt128Decl(0), + Int128Decl(0), UInt128Decl(0), Float128StubDecl(0), BuiltinVaListDecl(0), ObjCIdDecl(0), ObjCSelDecl(0), ObjCClassDecl(0), ObjCProtocolClassDecl(0), BOOLDecl(0), @@ -857,6 +857,19 @@ TypedefDecl *ASTContext::getUInt128Decl() const { return UInt128Decl; } +TypeDecl *ASTContext::getFloat128StubType() const { + if (!Float128StubDecl) { + Float128StubDecl = RecordDecl::Create(const_cast<ASTContext &>(*this), + TTK_Struct, + getTranslationUnitDecl(), + SourceLocation(), + SourceLocation(), + &Idents.get("__float128")); + } + + return Float128StubDecl; +} + void ASTContext::InitBuiltinType(CanQualType &R, BuiltinType::Kind K) { BuiltinType *Ty = new (*this, TypeAlignment) BuiltinType(K); R = CanQualType::CreateUnsafe(QualType(Ty, 0)); diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index e55524b1062..954091d6177 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -90,7 +90,7 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, AccessCheckingSFINAE(false), InNonInstantiationSFINAEContext(false), NonInstantiationEntries(0), ArgumentPackSubstitutionIndex(-1), CurrentInstantiationScope(0), TyposCorrected(0), - AnalysisWarnings(*this), CurScope(0), Ident_super(0) + AnalysisWarnings(*this), CurScope(0), Ident_super(0), Ident___float128(0) { TUScope = 0; @@ -1320,6 +1320,12 @@ IdentifierInfo *Sema::getSuperIdentifier() const { return Ident_super; } +IdentifierInfo *Sema::getFloat128Identifier() const { + if (!Ident___float128) + Ident___float128 = &Context.Idents.get("__float128"); + return Ident___float128; +} + void Sema::PushCapturedRegionScope(Scope *S, CapturedDecl *CD, RecordDecl *RD, CapturedRegionKind K) { CapturingScopeInfo *CSI = new CapturedRegionScopeInfo(getDiagnostics(), S, CD, RD, diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index c70367691f3..6ae040ffd7d 100644 --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -511,6 +511,14 @@ static bool LookupBuiltin(Sema &S, LookupResult &R) { NameKind == Sema::LookupRedeclarationWithLinkage) { IdentifierInfo *II = R.getLookupName().getAsIdentifierInfo(); if (II) { + if (S.getLangOpts().CPlusPlus11 && S.getLangOpts().GNUMode && + II == S.getFloat128Identifier()) { + // libstdc++4.7's type_traits expects type __float128 to exist, so + // insert a dummy type to make that header build in gnu++11 mode. + R.addDecl(S.getASTContext().getFloat128StubType()); + return true; + } + // If this is a builtin on this (or all) targets, create the decl. if (unsigned BuiltinID = II->getBuiltinID()) { // In C++, we don't have any predefined library functions like diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 279a6e34823..f5a28966f86 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -4939,6 +4939,12 @@ bool Sema::RequireCompleteType(SourceLocation Loc, QualType T, return true; // We have an incomplete type. Produce a diagnostic. + if (Ident___float128 && + T == Context.getTypeDeclType(Context.getFloat128StubType())) { + Diag(Loc, diag::err_typecheck_decl_incomplete_type___float128); + return true; + } + Diagnoser.diagnose(*this, Loc, T); // If the type was a forward declaration of a class/struct/union diff --git a/clang/test/Sema/128bitfloat.cc b/clang/test/Sema/128bitfloat.cc new file mode 100644 index 00000000000..077e61a51d4 --- /dev/null +++ b/clang/test/Sema/128bitfloat.cc @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=gnu++11 %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s + +#if !defined(__STRICT_ANSI__) +__float128 f; // expected-error{{support for type '__float128' is not yet implemented}} +// But this should work: +template<typename> struct __is_floating_point_helper {}; +template<> struct __is_floating_point_helper<__float128> {}; +#else +__float128 f; // expected-error {{unknown type name '__float128'}} +template<typename> struct __is_floating_point_helper {}; +template<> struct __is_floating_point_helper<__float128> {}; // expected-error {{use of undeclared identifier '__float128'}} +#endif |