]> granicus.if.org Git - clang/commitdiff
implement support for __builtin_eh_return_data_regno on x86-32 and x86-64.
authorChris Lattner <sabre@nondot.org>
Wed, 23 Sep 2009 06:06:36 +0000 (06:06 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 23 Sep 2009 06:06:36 +0000 (06:06 +0000)
This implements PR5034 and rdar://6836445.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82614 91177308-0d34-0410-b5e6-96231b3b80d8

clang.xcodeproj/project.pbxproj
include/clang/Basic/Builtins.def
include/clang/Basic/TargetInfo.h
lib/AST/ExprConstant.cpp
lib/Basic/Targets.cpp
lib/Sema/Sema.h
lib/Sema/SemaChecking.cpp
test/Sema/builtins.c

index 8a5bdbfe4649510b8fcbd66392356cd9f9cda117..cf8bec008550e624d487cb1f14a0aca17d1cafb6 100644 (file)
                DEB076CF0F3A222200F5A2BE /* DeclTemplate.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DEB076CE0F3A222200F5A2BE /* DeclTemplate.cpp */; };
                DEB077990F44F97800F5A2BE /* TokenConcatenation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DEB077980F44F97800F5A2BE /* TokenConcatenation.cpp */; };
                DEB07AC80F4A427E00F5A2BE /* SemaAttr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DEB07AC70F4A427E00F5A2BE /* SemaAttr.cpp */; };
-               DEC63B1C0C7B940600DBF169 /* CFG.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DEC63B1B0C7B940600DBF169 /* CFG.h */; };
                DEC8D9910A9433CD00353FCA /* Decl.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DEC8D9900A9433CD00353FCA /* Decl.h */; };
                DEC8D9A40A94346E00353FCA /* AST.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DEC8D9A30A94346E00353FCA /* AST.h */; };
                DECAB0D00DB3C84200E13CCB /* RewriteRope.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DECAB0CF0DB3C84200E13CCB /* RewriteRope.cpp */; };
                                DE6951C70C4D1F5D00A5826B /* RecordLayout.h in CopyFiles */,
                                DE6954640C5121BD00A5826B /* Token.h in CopyFiles */,
                                DEF2E95F0C5FBD74000C4259 /* InternalsManual.html in CopyFiles */,
-                               DEC63B1C0C7B940600DBF169 /* CFG.h in CopyFiles */,
                                DEF7D9F70C9C8B1A0001F598 /* Rewriter.h in CopyFiles */,
                                84AF36A10CB17A3B00C820A5 /* DeclObjC.h in CopyFiles */,
                                DE3986F00CB8D4B300223765 /* IdentifierTable.h in CopyFiles */,
                DEB077980F44F97800F5A2BE /* TokenConcatenation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TokenConcatenation.cpp; sourceTree = "<group>"; };
                DEB07AC70F4A427E00F5A2BE /* SemaAttr.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = SemaAttr.cpp; path = lib/Sema/SemaAttr.cpp; sourceTree = "<group>"; tabWidth = 2; };
                DEB089EE0F12F1D900522C07 /* TypeTraits.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TypeTraits.h; sourceTree = "<group>"; };
-               DEC63B1B0C7B940600DBF169 /* CFG.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 2; lastKnownFileType = sourcecode.c.h; name = CFG.h; path = clang/AST/CFG.h; sourceTree = "<group>"; tabWidth = 2; };
                DEC8D9900A9433CD00353FCA /* Decl.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 2; lastKnownFileType = sourcecode.c.h; name = Decl.h; path = clang/AST/Decl.h; sourceTree = "<group>"; tabWidth = 2; };
                DEC8D9A30A94346E00353FCA /* AST.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 2; lastKnownFileType = sourcecode.c.h; name = AST.h; path = clang/AST/AST.h; sourceTree = "<group>"; tabWidth = 2; };
                DECAB0CF0DB3C84200E13CCB /* RewriteRope.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RewriteRope.cpp; path = lib/Rewrite/RewriteRope.cpp; sourceTree = "<group>"; };
                                90FB99DE0F98FB1D008F9415 /* DeclContextInternals.h */,
                                90FB99DF0F98FB1D008F9415 /* DeclVisitor.h */,
                                90FB99E00F98FB1D008F9415 /* ExternalASTSource.h */,
-                               DEC63B1B0C7B940600DBF169 /* CFG.h */,
                                DEC8D9900A9433CD00353FCA /* Decl.h */,
                                3538FDB60ED24A2C005EC283 /* DeclarationName.h */,
                                035611470DA6A45C00D2EF2A /* DeclBase.h */,
index da0906b77b3e5ea7668f4ac88400bb069aa04207..502bbd24d9cbacb076f488931fe6b97ee1b83673 100644 (file)
@@ -247,6 +247,7 @@ BUILTIN(__builtin_flt_rounds, "i", "nc")
 BUILTIN(__builtin_setjmp, "iv**", "")
 BUILTIN(__builtin_longjmp, "vv**i", "")
 BUILTIN(__builtin_unwind_init, "v", "")
+BUILTIN(__builtin_eh_return_data_regno, "ii", "nc")
 
 // GCC Object size checking builtins
 BUILTIN(__builtin_object_size, "zv*i", "n")
index 1f61e3fccc2c07a6035afd97294349cae209c57d..8ce85cf6bb9a06ac31c4377c7650a0ffd4c39846 100644 (file)
@@ -384,10 +384,17 @@ public:
     return RegParmMax;
   }
 
-  // isTLSSupported - Whether the target supports thread-local storage
+  /// isTLSSupported - Whether the target supports thread-local storage.
   bool isTLSSupported() const {
     return TLSSupported;
   }
+  
+  /// getEHDataRegisterNumber - Return the register number that
+  /// __builtin_eh_return_regno would return with the specified argument.
+  virtual int getEHDataRegisterNumber(unsigned RegNo) const {
+    return -1; 
+  }
+  
 
 protected:
   virtual uint64_t getPointerWidthV(unsigned AddrSpace) const {
index 9c34547db1adc04b7dfd5cb6ef878c1f3aabdd1e..5123aaa7ca79fd69b4be4495bca65ede17bbe6bc 100644 (file)
@@ -870,6 +870,12 @@ bool IntExprEvaluator::VisitCallExpr(const CallExpr *E) {
     // __builtin_constant_p always has one operand: it returns true if that
     // operand can be folded, false otherwise.
     return Success(E->getArg(0)->isEvaluatable(Info.Ctx), E);
+      
+  case Builtin::BI__builtin_eh_return_data_regno: {
+    int Operand = E->getArg(0)->EvaluateAsInt(Info.Ctx).getZExtValue();
+    Operand = Info.Ctx.Target.getEHDataRegisterNumber(Operand);
+    return Success(Operand, E);
+  }
   }
 }
 
index f620581cb494596d1b7784804ef3097faa565983..8c31dcb7c666b1f344b6a8d8c1ffcac093d6cf90 100644 (file)
@@ -900,6 +900,12 @@ public:
   virtual const char *getVAListDeclaration() const {
     return "typedef char* __builtin_va_list;";
   }
+  
+  int getEHDataRegisterNumber(unsigned RegNo) const {
+    if (RegNo == 0) return 0;
+    if (RegNo == 1) return 2;
+    return -1;
+  }
 };
 } // end anonymous namespace
 
@@ -990,6 +996,12 @@ public:
            "} __va_list_tag;"
            "typedef __va_list_tag __builtin_va_list[1];";
   }
+  
+  int getEHDataRegisterNumber(unsigned RegNo) const {
+    if (RegNo == 0) return 0;
+    if (RegNo == 1) return 1;
+    return -1;
+  }
 };
 } // end anonymous namespace
 
index 193d99288129eb834279fe209c0826be8dbad802..875da1a1d92e39eef1db6234bc8430edc13b3387 100644 (file)
@@ -3700,6 +3700,7 @@ private:
   bool SemaBuiltinObjectSize(CallExpr *TheCall);
   bool SemaBuiltinLongjmp(CallExpr *TheCall);
   bool SemaBuiltinAtomicOverloaded(CallExpr *TheCall);
+  bool SemaBuiltinEHReturnDataRegNo(CallExpr *TheCall);
   bool SemaCheckStringLiteral(const Expr *E, const CallExpr *TheCall,
                               bool HasVAListArg, unsigned format_idx,
                               unsigned firstDataArg);
index 1e26c3507bbf5f1aeefa69e727a1c640af755db5..18a997998a599bfc88f061a2703c652050112234 100644 (file)
@@ -138,6 +138,10 @@ Sema::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
     if (SemaBuiltinStackAddress(TheCall))
       return ExprError();
     break;
+  case Builtin::BI__builtin_eh_return_data_regno:
+    if (SemaBuiltinEHReturnDataRegNo(TheCall))
+      return ExprError();
+    break;
   case Builtin::BI__builtin_shufflevector:
     return SemaBuiltinShuffleVector(TheCall);
     // TheCall will be freed by the smart pointer here, but that's fine, since
@@ -698,7 +702,7 @@ bool Sema::SemaBuiltinPrefetch(CallExpr *TheCall) {
     llvm::APSInt Result;
     if (!BT || BT->getKind() != BuiltinType::Int)
       return Diag(TheCall->getLocStart(), diag::err_prefetch_invalid_argument)
-              << SourceRange(Arg->getLocStart(), Arg->getLocEnd());
+              << Arg->getSourceRange();
 
     if (Arg->isValueDependent())
       continue;
@@ -713,17 +717,29 @@ bool Sema::SemaBuiltinPrefetch(CallExpr *TheCall) {
     if (i == 1) {
       if (Result.getSExtValue() < 0 || Result.getSExtValue() > 1)
         return Diag(TheCall->getLocStart(), diag::err_argument_invalid_range)
-             << "0" << "1" << SourceRange(Arg->getLocStart(), Arg->getLocEnd());
+             << "0" << "1" << Arg->getSourceRange();
     } else {
       if (Result.getSExtValue() < 0 || Result.getSExtValue() > 3)
         return Diag(TheCall->getLocStart(), diag::err_argument_invalid_range)
-            << "0" << "3" << SourceRange(Arg->getLocStart(), Arg->getLocEnd());
+            << "0" << "3" << Arg->getSourceRange();
     }
   }
 
   return false;
 }
 
+/// SemaBuiltinEHReturnDataRegNo - Handle __builtin_eh_return_data_regno, the
+/// operand must be an integer constant.
+bool Sema::SemaBuiltinEHReturnDataRegNo(CallExpr *TheCall) {
+  llvm::APSInt Result;
+  if (!TheCall->getArg(0)->isIntegerConstantExpr(Result, Context))
+    return Diag(TheCall->getLocStart(), diag::err_expr_not_ice)
+      << TheCall->getArg(0)->getSourceRange();
+  
+  return false;
+}
+
+
 /// SemaBuiltinObjectSize - Handle __builtin_object_size(void *ptr,
 /// int type). This simply type checks that type is one of the defined
 /// constants (0-3).
index c3daa667d8a4649bda3d82603ffcf3ab718319d4..04a56bd5ed1012b2192593842698cda73f5eed64 100644 (file)
@@ -52,3 +52,13 @@ void test10(void) {
  
   // No warning about falling off the end of a noreturn function.
 }
+
+void test11(int X) {
+  switch (X) {  
+  case __builtin_eh_return_data_regno(0):  // constant foldable.
+    break;
+  }
+
+  __builtin_eh_return_data_regno(X);  // expected-error {{not an integer constant expression}}
+}
+