diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Basic/Builtins.cpp | 25 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGBuiltin.cpp | 84 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.h | 4 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDeclAttr.cpp | 29 |
4 files changed, 0 insertions, 142 deletions
diff --git a/clang/lib/Basic/Builtins.cpp b/clang/lib/Basic/Builtins.cpp index 4d4c2ff..f04bc1f 100644 --- a/clang/lib/Basic/Builtins.cpp +++ b/clang/lib/Basic/Builtins.cpp @@ -188,28 +188,3 @@ bool Builtin::Context::canBeRedeclared(unsigned ID) const { (!hasReferenceArgsOrResult(ID) && !hasCustomTypechecking(ID)); } - -unsigned Builtin::getFortifiedVariantFunction(unsigned BuiltinID) { - switch (BuiltinID) { - case Builtin::BImemcpy: return Builtin::BI__builtin___memcpy_chk; - case Builtin::BImemmove: return Builtin::BI__builtin___memmove_chk; - case Builtin::BImemset: return Builtin::BI__builtin___memset_chk; - case Builtin::BIstpcpy: return Builtin::BI__builtin___stpcpy_chk; - case Builtin::BIstrcat: return Builtin::BI__builtin___strcat_chk; - case Builtin::BIstrcpy: return Builtin::BI__builtin___strcpy_chk; - case Builtin::BIstrlcat: return Builtin::BI__builtin___strlcat_chk; - case Builtin::BIstrlcpy: return Builtin::BI__builtin___strlcpy_chk; - case Builtin::BIstrncat: return Builtin::BI__builtin___strncat_chk; - case Builtin::BIstrncpy: return Builtin::BI__builtin___strncpy_chk; - case Builtin::BIstpncpy: return Builtin::BI__builtin___stpncpy_chk; - case Builtin::BIsnprintf: return Builtin::BI__builtin___snprintf_chk; - case Builtin::BIvsnprintf: return Builtin::BI__builtin___vsnprintf_chk; - case Builtin::BIsprintf: return Builtin::BI__builtin___sprintf_chk; - case Builtin::BIvsprintf: return Builtin::BI__builtin___vsprintf_chk; - case Builtin::BIfprintf: return Builtin::BI__builtin___fprintf_chk; - case Builtin::BIvfprintf: return Builtin::BI__builtin___vfprintf_chk; - case Builtin::BIprintf: return Builtin::BI__builtin___printf_chk; - case Builtin::BIvprintf: return Builtin::BI__builtin___vprintf_chk; - default: return 0; - } -} diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 43c8020..9628972 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -1474,86 +1474,6 @@ RValue CodeGenFunction::emitRotate(const CallExpr *E, bool IsRotateRight) { return RValue::get(Builder.CreateCall(F, { Src, Src, ShiftAmt })); } -/// For a call to a builtin C standard library function, emit a call to a -/// fortified variant using __builtin_object_size. For instance, instead of -/// emitting `sprintf(buf, "%d", 32)`, this function would emit -/// `__sprintf_chk(buf, Flag, __builtin_object_size(buf, 0), "%d", 32)`. -RValue CodeGenFunction::emitFortifiedStdLibCall(CodeGenFunction &CGF, - const CallExpr *CE, - unsigned BuiltinID, - unsigned BOSType, - unsigned Flag) { - SmallVector<llvm::Value *, 8> ArgVals; - for (const Expr *Arg : CE->arguments()) - ArgVals.push_back(EmitScalarExpr(Arg)); - - llvm::Value *FlagVal = llvm::ConstantInt::get(IntTy, Flag); - auto emitObjSize = [&]() { - return evaluateOrEmitBuiltinObjectSize(CE->getArg(0), BOSType, SizeTy, - ArgVals[0], false); - }; - - unsigned FortifiedVariantID = Builtin::getFortifiedVariantFunction(BuiltinID); - assert(FortifiedVariantID != 0 && "Should be diagnosed in Sema"); - - // Adjust ArgVals to include a __builtin_object_size(n) or flag argument at - // the right position. Variadic printf-like functions take a flag and object - // size (if they're printing to a string) before the format string, and all - // other functions just take the object size as their last argument. The - // object size, if present, always corresponds to the first argument. - switch (BuiltinID) { - case Builtin::BImemcpy: - case Builtin::BImemmove: - case Builtin::BImemset: - case Builtin::BIstpcpy: - case Builtin::BIstrcat: - case Builtin::BIstrcpy: - case Builtin::BIstrlcat: - case Builtin::BIstrlcpy: - case Builtin::BIstrncat: - case Builtin::BIstrncpy: - case Builtin::BIstpncpy: - ArgVals.push_back(emitObjSize()); - break; - - case Builtin::BIsnprintf: - case Builtin::BIvsnprintf: - ArgVals.insert(ArgVals.begin() + 2, FlagVal); - ArgVals.insert(ArgVals.begin() + 3, emitObjSize()); - break; - - case Builtin::BIsprintf: - case Builtin::BIvsprintf: - ArgVals.insert(ArgVals.begin() + 1, FlagVal); - ArgVals.insert(ArgVals.begin() + 2, emitObjSize()); - break; - - case Builtin::BIfprintf: - case Builtin::BIvfprintf: - ArgVals.insert(ArgVals.begin() + 1, FlagVal); - break; - - case Builtin::BIprintf: - case Builtin::BIvprintf: - ArgVals.insert(ArgVals.begin(), FlagVal); - break; - - default: - llvm_unreachable("Unknown fortified builtin?"); - } - - ASTContext::GetBuiltinTypeError Err; - QualType VariantTy = getContext().GetBuiltinType(FortifiedVariantID, Err); - assert(Err == ASTContext::GE_None && "Should not codegen an error"); - auto *LLVMVariantTy = cast<llvm::FunctionType>(ConvertType(VariantTy)); - StringRef VariantName = getContext().BuiltinInfo.getName(FortifiedVariantID) + - strlen("__builtin_"); - - llvm::Value *V = Builder.CreateCall( - CGM.CreateRuntimeFunction(LLVMVariantTy, VariantName), ArgVals); - return RValue::get(V); -} - RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, const CallExpr *E, ReturnValueSlot ReturnValue) { @@ -1570,10 +1490,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, Result.Val.getFloat())); } - if (const auto *FortifyAttr = FD->getAttr<FortifyStdLibAttr>()) - return emitFortifiedStdLibCall(*this, E, BuiltinID, FortifyAttr->getType(), - FortifyAttr->getFlag()); - // There are LLVM math intrinsics/instructions corresponding to math library // functions except the LLVM op will never set errno while the math library // might. Also, math builtins have the same semantics as their math library diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index 37b6247..e8ab734 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -3697,10 +3697,6 @@ public: RValue EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, const CallExpr *E, ReturnValueSlot ReturnValue); - RValue emitFortifiedStdLibCall(CodeGenFunction &CGF, const CallExpr *CE, - unsigned BuiltinID, unsigned BOSType, - unsigned Flag); - RValue emitRotate(const CallExpr *E, bool IsRotateRight); /// Emit IR for __builtin_os_log_format. diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index c97d0bc..f16b6e9 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -6524,31 +6524,6 @@ static void handleObjCExternallyRetainedAttr(Sema &S, Decl *D, handleSimpleAttribute<ObjCExternallyRetainedAttr>(S, D, AL); } -static void handleFortifyStdLib(Sema &S, Decl *D, const ParsedAttr &AL) { - auto *FD = cast<FunctionDecl>(D); - unsigned VariantID = Builtin::getFortifiedVariantFunction(FD->getBuiltinID()); - if (VariantID == 0) { - S.Diag(D->getLocation(), diag::err_fortify_std_lib_bad_decl); - return; - } - - uint32_t BOSType, Flag; - if (!checkUInt32Argument(S, AL, AL.getArgAsExpr(0), BOSType, 0, true) || - !checkUInt32Argument(S, AL, AL.getArgAsExpr(1), Flag, 1, true)) - return; - - if (BOSType > 3) { - S.Diag(AL.getArgAsExpr(0)->getBeginLoc(), - diag::err_attribute_argument_out_of_range) - << AL << 0 << 3; - return; - } - - D->addAttr(::new (S.getASTContext()) FortifyStdLibAttr( - AL.getLoc(), S.getASTContext(), BOSType, Flag, - AL.getAttributeSpellingListIndex())); -} - static void handleMIGServerRoutineAttr(Sema &S, Decl *D, const ParsedAttr &AL) { // Check that the return type is a `typedef int kern_return_t` or a typedef // around it, because otherwise MIG convention checks make no sense. @@ -7301,10 +7276,6 @@ static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, handleObjCExternallyRetainedAttr(S, D, AL); break; - case ParsedAttr::AT_FortifyStdLib: - handleFortifyStdLib(S, D, AL); - break; - case ParsedAttr::AT_MIGServerRoutine: handleMIGServerRoutineAttr(S, D, AL); break; |