]> granicus.if.org Git - clang/commitdiff
Lazily provide a __float128 dummy type in -std=gnu++11 mode.
authorNico Weber <nicolasweber@gmx.de>
Thu, 20 Jun 2013 21:44:55 +0000 (21:44 +0000)
committerNico Weber <nicolasweber@gmx.de>
Thu, 20 Jun 2013 21:44:55 +0000 (21:44 +0000)
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

include/clang/AST/ASTContext.h
include/clang/Basic/DiagnosticSemaKinds.td
include/clang/Sema/Sema.h
lib/AST/ASTContext.cpp
lib/Sema/Sema.cpp
lib/Sema/SemaLookup.cpp
lib/Sema/SemaType.cpp
test/Sema/128bitfloat.cc [new file with mode: 0644]

index 830a956ca96cd04dd01689b6c6c107d050e0c250..ebbf6c99e66fd14f2b2defb8210aa6ab51f4b294 100644 (file)
@@ -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
index 1873ef02e9c6f1c6786df4bb21d37cffb0c99304..cf1e6dc3ac8029dace82841f95a7ea924f40a5da 100644 (file)
@@ -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">>;
index f45b089e044670fcccf7b69ea383885c0721337f..f0bcc4015528062c40092dd46498751e8261144a 100644 (file)
@@ -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;
 
index c76ed5fdb98025635479e4a34c051888bcb02366..870e09cc674ab8c7802d3aa1631d6df14c5625ac 100644 (file)
@@ -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));
index e55524b1062cec087a82b54da6805eb5cf395f1a..954091d61779715caccc891786a6bcb70082cdb1 100644 (file)
@@ -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,
index c70367691f32e50fe4b470c230499932292399ae..6ae040ffd7d017b969c78601c02305907951dccc 100644 (file)
@@ -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
index 279a6e348232fc9987e40fa5ee9820b7c4c48abf..f5a28966f868dde7e910211ccb05b64214cf1468 100644 (file)
@@ -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 (file)
index 0000000..077e61a
--- /dev/null
@@ -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