From: Nico Weber Date: Thu, 20 Jun 2013 21:44:55 +0000 (+0000) Subject: Lazily provide a __float128 dummy type in -std=gnu++11 mode. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cac18add73d095eaab600aefe27ea7174aec4922;p=clang Lazily provide a __float128 dummy type in -std=gnu++11 mode. This is needed to parse libstdc++ 4.7's type_traits, see PR13530. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184476 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index 830a956ca9..ebbf6c99e6 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -196,6 +196,9 @@ class ASTContext : public RefCountedBase { /// \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/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 1873ef02e9..cf1e6dc3ac 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/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>; diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index f45b089e04..f0bcc40155 100644 --- a/include/clang/Sema/Sema.h +++ b/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/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index c76ed5fdb9..870e09cc67 100644 --- a/lib/AST/ASTContext.cpp +++ b/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(*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/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index e55524b106..954091d617 100644 --- a/lib/Sema/Sema.cpp +++ b/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/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index c70367691f..6ae040ffd7 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/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/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index 279a6e3482..f5a28966f8 100644 --- a/lib/Sema/SemaType.cpp +++ b/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/test/Sema/128bitfloat.cc b/test/Sema/128bitfloat.cc new file mode 100644 index 0000000000..077e61a51d --- /dev/null +++ b/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 struct __is_floating_point_helper {}; +template<> struct __is_floating_point_helper<__float128> {}; +#else +__float128 f; // expected-error {{unknown type name '__float128'}} +template struct __is_floating_point_helper {}; +template<> struct __is_floating_point_helper<__float128> {}; // expected-error {{use of undeclared identifier '__float128'}} +#endif