From ae7f1426ff3b4076a910a772e0cf15290505655e Mon Sep 17 00:00:00 2001 From: liuxinyi Date: Wed, 19 Mar 2025 10:36:41 +0800 Subject: [PATCH 1/2] [FatPtr] optimization and bugfix of fat ptr 1. Add compiliation option -fat-ptr-check=value to replace -enable-fat-ptr, value can be none(default)/both/version/offset. 2. bugfix of coredump when use -Wall 3. CHECKED can also be used for global variable whose type is struct which has constant array fields. 4. add error report for expr `&fat arr[n]` when arr is variable array type 5. bugfix of coredump when use checked_malloc without enable-fat-ptr 6. when checked_free a fat ptr cast from raw ptr, also report error 7. when checked_free a fat ptr, only memset 8 bytes of allocation header(lock_version and size) to 0 to reduce time cost --- clang/docs/BiShengCLanguageUserManual.md | 19 +++++----- .../clang/Basic/BSC/DiagnosticBSCSemaKinds.td | 2 ++ clang/include/clang/Basic/LangOptions.def | 2 +- clang/include/clang/Basic/LangOptions.h | 9 ++++- clang/include/clang/Driver/BSC/BSCOptions.td | 7 ++-- clang/lib/AST/DeclPrinter.cpp | 3 +- clang/lib/AST/ExprConstant.cpp | 14 +++++--- clang/lib/AST/StmtPrinter.cpp | 9 +++-- clang/lib/CodeGen/CGExprAgg.cpp | 3 +- clang/lib/Driver/ToolChains/Clang.cpp | 11 ++++-- clang/lib/Frontend/InitPreprocessor.cpp | 3 ++ clang/lib/Frontend/Rewrite/RewriteBSC.cpp | 4 +-- clang/lib/Headers/bsc_include/bsc_fat_ptr.hbs | 23 +++++++++--- clang/lib/Parse/ParseDecl.cpp | 8 ++--- clang/lib/Sema/BSC/SemaBSCDestructor.cpp | 1 + clang/lib/Sema/BSC/SemaBSCFatPtr.cpp | 33 +++++++++++++++-- clang/lib/Sema/BSC/SemaDeclBSC.cpp | 2 +- clang/lib/Sema/SemaDecl.cpp | 6 ++-- clang/lib/Sema/SemaDeclAttr.cpp | 15 +++++++- clang/lib/Sema/SemaExpr.cpp | 33 +++++++++++------ clang/lib/Sema/SemaExprCXX.cpp | 3 +- clang/lib/Sema/SemaExprMember.cpp | 9 +++-- clang/lib/Sema/SemaOverload.cpp | 2 +- clang/test/BSC/Negative/FatPtr/addr_fat.cbs | 18 ++++++++++ .../global_array/array_out_of_bounds1.cbs | 21 ++++++++--- .../global_array/array_out_of_bounds2.cbs | 21 ++++++++--- .../global_array/array_out_of_bounds3.cbs | 33 +++++++++++++++++ .../heap/array_out_of_bounds1.cbs | 22 +++++++++--- .../heap/array_out_of_bounds10.cbs | 21 ++++++++--- .../heap/array_out_of_bounds11.cbs | 21 ++++++++--- .../heap/array_out_of_bounds12.cbs | 21 ++++++++--- .../heap/array_out_of_bounds13.cbs | 21 ++++++++--- .../heap/array_out_of_bounds14.cbs | 21 ++++++++--- .../heap/array_out_of_bounds15.cbs | 21 ++++++++--- .../heap/array_out_of_bounds16.cbs | 21 ++++++++--- .../heap/array_out_of_bounds17.cbs | 21 ++++++++--- .../heap/array_out_of_bounds18.cbs | 21 ++++++++--- .../heap/array_out_of_bounds19.cbs | 21 ++++++++--- .../heap/array_out_of_bounds2.cbs | 21 ++++++++--- .../heap/array_out_of_bounds20.cbs | 21 ++++++++--- .../heap/array_out_of_bounds21.cbs | 21 ++++++++--- .../heap/array_out_of_bounds22.cbs | 21 ++++++++--- .../heap/array_out_of_bounds23.cbs | 21 ++++++++--- .../heap/array_out_of_bounds24.cbs | 21 ++++++++--- .../heap/array_out_of_bounds3.cbs | 21 ++++++++--- .../heap/array_out_of_bounds4.cbs | 21 ++++++++--- .../heap/array_out_of_bounds5.cbs | 21 ++++++++--- .../heap/array_out_of_bounds6.cbs | 21 ++++++++--- .../heap/array_out_of_bounds7.cbs | 21 ++++++++--- .../heap/array_out_of_bounds8.cbs | 21 ++++++++--- .../heap/array_out_of_bounds9.cbs | 21 ++++++++--- .../heap/buffer_overflow.cbs | 21 ++++++++--- .../heap/checked_free_fat_from_raw.cbs | 35 +++++++++++++++++++ .../heap/double_free1.cbs | 23 +++++++++--- .../heap/double_free2.cbs | 23 +++++++++--- .../heap/double_free3.cbs | 23 +++++++++--- .../heap/double_free4.cbs | 23 +++++++++--- .../heap/use_after_free1.cbs | 21 ++++++++--- .../heap/use_after_free2.cbs | 21 ++++++++--- .../heap/use_after_free3.cbs | 21 ++++++++--- .../heap/use_after_free4.cbs | 21 ++++++++--- .../heap/use_after_free5.cbs | 21 ++++++++--- .../heap/use_after_free6.cbs | 21 ++++++++--- .../heap/use_after_free7.cbs | 21 ++++++++--- .../heap/use_after_free8.cbs | 21 ++++++++--- .../stack/array_out_of_bounds1.cbs | 21 ++++++++--- .../stack/array_out_of_bounds2.cbs | 21 ++++++++--- .../stack/array_out_of_bounds3.cbs | 21 ++++++++--- .../stack/array_out_of_bounds4.cbs | 21 ++++++++--- .../stack/buffer_overflow.cbs | 21 ++++++++--- .../stack/return_local_address.cbs | 21 ++++++++--- .../test/BSC/Positive/FatPtr/global_array.cbs | 4 +-- clang/test/BSC/Positive/FatPtr/heap.cbs | 4 +-- .../Positive/FatPtr/multi_level_pointer.cbs | 4 +-- .../FatPtr/nullptr_cast/nullptr_cast.cbs | 4 +-- .../FatPtr/redundant_check/func_call.cbs | 4 +-- .../FatPtr/redundant_check/if_stmt.cbs | 4 +-- .../FatPtr/redundant_check/member_visit.cbs | 4 +-- clang/test/BSC/Positive/FatPtr/stack.cbs | 4 +-- .../BSC/Positive/FatPtr/string_literal.cbs | 4 +-- 80 files changed, 995 insertions(+), 302 deletions(-) create mode 100644 clang/test/BSC/Negative/FatPtr/version_and_offset_check/global_array/array_out_of_bounds3.cbs create mode 100644 clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/checked_free_fat_from_raw.cbs diff --git a/clang/docs/BiShengCLanguageUserManual.md b/clang/docs/BiShengCLanguageUserManual.md index 33b6f5967e23..ef18845dfb3e 100644 --- a/clang/docs/BiShengCLanguageUserManual.md +++ b/clang/docs/BiShengCLanguageUserManual.md @@ -4413,7 +4413,11 @@ void point_to_global_var() { *p = 20; } ``` -在编译使用了胖指针特性的 cbs 文件时,必须使用`-enable-fat-ptr`这一编译选项来使能胖指针特性,否则毕昇 C 编译器会将胖指针当作裸指针来编译,无法起到检测内存安全问题的功能。 +在编译使用了胖指针特性的 cbs 文件时,可以通过`-fat-ptr-check=value`这一编译选项来控制胖指针特性的开启,其中`value`是一个枚举值,有4种选项`none`, `both`, `version`, `offset`: +1. `value`的默认值为`none`,此时毕昇 C 编译器会将胖指针当作裸指针来编译,无法起到检测内存安全问题的功能;当不指定该编译选项时,等同于`-fat-ptr-check=none` +2. `value`值为`both`时,将同时开启时间类和空间类内存安全问题检查 +3. `value`值为`version`时,将只开启时间类内存安全问题检查 +4. `value`值为`offset`时,将只开启空间类内存安全问题检查 ### 胖指针在运行时检测内存安全问题 胖指针特性可以检测的**时间类**内存安全问题包括: @@ -4425,7 +4429,6 @@ void point_to_global_var() { 1. Buffer overflow 2. Out of bounds - #### Double free ```C // double_free.cbs @@ -4440,7 +4443,7 @@ int main(int argc, char **argv) { ``` 编译 double_free.cbs 并运行: ``` -$ clang double_free.cbs -enable-fat-ptr +$ clang double_free.cbs -fat-ptr-check=both $ ./a.out 1 ``` 这一用例会触发胖指针的运行时报错机制: @@ -4463,7 +4466,7 @@ int main(int argc, char **argv) { ``` 编译 use_after_free.cbs 并运行: ``` -$ clang use_after_free.cbs -enable-fat-ptr +$ clang use_after_free.cbs -fat-ptr-check=both $ ./a.out 1 ``` 这一用例会触发胖指针的运行时报错机制: @@ -4495,7 +4498,7 @@ int main(int argc, char **argv) { ``` 编译 use_after_return.cbs 并运行: ``` -$ clang use_after_return.cbs -enable-fat-ptr +$ clang use_after_return.cbs -fat-ptr-check=both $ ./a.out 1 ``` 这一用例会触发胖指针的运行时报错机制: @@ -4543,8 +4546,8 @@ After overflow: secret = 26478 // 不同目标平台,具体值可能变化 若开启胖指针编译选项,再次编译运行,这一用例会触发胖指针的运行时报错机制: ``` -$ clang buffer_overflow.cbs -enable-fat-ptr -$ ./a.out lonstring +$ clang buffer_overflow.cbs -fat-ptr-check=both +$ ./a.out longstring ``` 此时,运行时报错信息如下: ``` @@ -4569,7 +4572,7 @@ int main() { ``` 编译 out_of_bounds.cbs 并运行: ``` -$ clang out_of_bounds.cbs -enable-fat-ptr +$ clang out_of_bounds.cbs -fat-ptr-check=both $ ./a.out ``` 这一用例会触发胖指针的运行时报错机制: diff --git a/clang/include/clang/Basic/BSC/DiagnosticBSCSemaKinds.td b/clang/include/clang/Basic/BSC/DiagnosticBSCSemaKinds.td index c70e09f31e8b..fb24841fdbeb 100644 --- a/clang/include/clang/Basic/BSC/DiagnosticBSCSemaKinds.td +++ b/clang/include/clang/Basic/BSC/DiagnosticBSCSemaKinds.td @@ -285,6 +285,8 @@ def err_fat_funcPtr_incompatible : Error< "incompatible fat function pointer types, cannot cast %0 to %1">; def err_addr_fat_on_no_fat_pointer : Error< "'&fat' on member of no-fat pointer is not allowed">; +def err_addr_fat_on_variable_array : Error< + "'&fat' on member of variable array is not allowed">; def err_addr_fat_on_global_var_without_checked : Error< "'&fat' on global variables without fat_ptr_checked attribute is not allowed">; def err_fat_ptr_type_not_found : Error< diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index 01b65d0b44a6..9f817cacb8d4 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -260,9 +260,9 @@ LANGOPT(RenderScript , 1, 0, "RenderScript") LANGOPT(HLSL, 1, 0, "HLSL") #if ENABLE_BSC LANGOPT(BSC, 1, 0, "BSC") -LANGOPT(EnableFatPtr, 1, 0, "enable fat ptr") LANGOPT(DisableOwnershipCheck, 1, 0, "disable ownership check") ENUM_LANGOPT(NullabilityCheck, NullCheckZone, 2, NC_SAFE, "nullability check") +ENUM_LANGOPT(FatPtrCheck, FatPtrCheckKind, 2, FPC_None, "fat ptr check") #endif ENUM_LANGOPT(HLSLVersion, HLSLLangStd, 16, HLSL_Unset, "HLSL Version") diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h index 9204c000dfd9..b5f56b14602d 100644 --- a/clang/include/clang/Basic/LangOptions.h +++ b/clang/include/clang/Basic/LangOptions.h @@ -81,11 +81,18 @@ public: using RoundingMode = llvm::RoundingMode; #if ENABLE_BSC - enum NullCheckZone { + enum NullCheckZone { NC_NONE, NC_SAFE, NC_ALL }; + + enum FatPtrCheckKind { + FPC_None, + FPC_Both, + FPC_Version, + FPC_Offset + }; #endif enum GCMode { NonGC, GCOnly, HybridGC }; diff --git a/clang/include/clang/Driver/BSC/BSCOptions.td b/clang/include/clang/Driver/BSC/BSCOptions.td index 9c6266b558e8..51ba2b8b856b 100644 --- a/clang/include/clang/Driver/BSC/BSCOptions.td +++ b/clang/include/clang/Driver/BSC/BSCOptions.td @@ -4,8 +4,6 @@ def rewrite_bsc : Flag<["-"], "rewrite-bsc">, Flags<[CC1Option]>, Group; def rewrite_bsc_line : Flag<["-"], "line">, Flags<[CC1Option]>, HelpText<"Insert line info when rewrite BSC">; -def enable_fat_ptr : Flag<["-"], "enable-fat-ptr">, Flags<[CC1Option]>, - HelpText<"Enable fat ptr">, MarshallingInfoFlag>; def disable_ownership_check : Flag<["-"], "disable-ownership-check">, Flags<[CC1Option]>, HelpText<"Disable ownership check">, MarshallingInfoFlag>; def nullability_check : Joined<["-"], "nullability-check=">, Flags<[CC1Option]>, @@ -13,6 +11,11 @@ def nullability_check : Joined<["-"], "nullability-check=">, Flags<[CC1Option]>, Values<"none,safeonly,all">, NormalizedValuesScope<"LangOptions">, NormalizedValues<["NC_NONE", "NC_SAFE", "NC_ALL"]>, MarshallingInfoEnum, "NC_SAFE">; +def fat_ptr_check : Joined<["-"], "fat-ptr-check=">, Flags<[CC1Option]>, + HelpText<"Select Fat Ptr Check Kind">, + Values<"none,both,version,offset">, NormalizedValuesScope<"LangOptions">, + NormalizedValues<["FPC_None", "FPC_Both", "FPC_Version", "FPC_Offset"]>, + MarshallingInfoEnum, "FPC_None">; def E_Group : OptionGroup<"">, Group, DocFlatten; def E_value_Group : OptionGroup<"">, Group, DocFlatten; diff --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp index ee62eb74de5f..48f74c597628 100644 --- a/clang/lib/AST/DeclPrinter.cpp +++ b/clang/lib/AST/DeclPrinter.cpp @@ -1058,7 +1058,8 @@ void DeclPrinter::VisitVarDecl(VarDecl *D) { ? D->getTypeSourceInfo()->getType() : D->getASTContext().getUnqualifiedObjCPointerType(D->getType()); #if ENABLE_BSC - if (Policy.RewriteBSC && Context.getLangOpts().EnableFatPtr && + if (Policy.RewriteBSC && + Context.getLangOpts().getFatPtrCheck() != LangOptions::FPC_None && T.isFatPtrType()) { T = D->getType(); } diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index c46223656371..371289482d4b 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -8039,7 +8039,7 @@ public: if (E->isArrow()) { #if ENABLE_BSC if (this->Info.getLangOpts().BSC && - this->Info.getLangOpts().EnableFatPtr && + this->Info.getLangOpts().getFatPtrCheck() != LangOptions::FPC_None && E->getBase()->getType().isFatPtrRecordType()) { EvalOK = true; BaseTy = E->getBase()->getType().getFatPtrPointeeType(); @@ -8483,7 +8483,8 @@ bool LValueExprEvaluator::VisitArraySubscriptExpr(const ArraySubscriptExpr *E) { // side is the base. for (const Expr *SubExpr : {E->getLHS(), E->getRHS()}) { #if ENABLE_BSC - if (Info.getLangOpts().BSC && Info.getLangOpts().EnableFatPtr && + if (Info.getLangOpts().BSC && + Info.getLangOpts().getFatPtrCheck() != LangOptions::FPC_None && SubExpr->getType().isFatPtrRecordType()) return true; #endif @@ -8501,7 +8502,8 @@ bool LValueExprEvaluator::VisitArraySubscriptExpr(const ArraySubscriptExpr *E) { bool LValueExprEvaluator::VisitUnaryDeref(const UnaryOperator *E) { #if ENABLE_BSC - if (Info.getLangOpts().BSC && Info.getLangOpts().EnableFatPtr && + if (Info.getLangOpts().BSC && + Info.getLangOpts().getFatPtrCheck() != LangOptions::FPC_None && E->getSubExpr()->getType().isFatPtrRecordType()) return true; #endif @@ -8840,7 +8842,8 @@ bool PointerExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) { E->getOpcode() != BO_Sub) return ExprEvaluatorBaseTy::VisitBinaryOperator(E); #if ENABLE_BSC - if (Info.getLangOpts().BSC && Info.getLangOpts().EnableFatPtr && + if (Info.getLangOpts().BSC && + Info.getLangOpts().getFatPtrCheck() != LangOptions::FPC_None && E->getLHS()->getType().isFatPtrRecordType()) return true; #endif @@ -14852,7 +14855,8 @@ static bool Evaluate(APValue &Result, EvalInfo &Info, const Expr *E) { APValue &Value = Info.CurrentCall->createTemporary(E, T, ScopeKind::FullExpression, LV); #if ENABLE_BSC - if (!(Info.getLangOpts().BSC && Info.getLangOpts().EnableFatPtr && + if (!(Info.getLangOpts().BSC && + Info.getLangOpts().getFatPtrCheck() != LangOptions::FPC_None && T.isFatPtrRecordType())) #endif if (!EvaluateRecord(E, LV, Value, Info)) diff --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp index 6fcdaaac38c1..9e886e141f5a 100644 --- a/clang/lib/AST/StmtPrinter.cpp +++ b/clang/lib/AST/StmtPrinter.cpp @@ -1662,7 +1662,8 @@ void StmtPrinter::VisitOMPIteratorExpr(OMPIteratorExpr *Node) { void StmtPrinter::PrintCallArgs(CallExpr *Call) { #if ENABLE_BSC - if (Policy.RewriteBSC && Context->getLangOpts().EnableFatPtr) { + if (Policy.RewriteBSC && + Context->getLangOpts().getFatPtrCheck() != LangOptions::FPC_None) { if (auto FD = dyn_cast(Call->getCalleeDecl())) { if (FD->getNameAsString() == "_check_version") { for (unsigned i = 0; i < 3; ++i) { @@ -1789,7 +1790,8 @@ void StmtPrinter::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) { void StmtPrinter::VisitCStyleCastExpr(CStyleCastExpr *Node) { OS << '('; #if ENABLE_BSC - if (Policy.RewriteBSC && Context->getLangOpts().EnableFatPtr && + if (Policy.RewriteBSC && + Context->getLangOpts().getFatPtrCheck() != LangOptions::FPC_None && Node->getType().hasFat()) Node->getType().print(OS, Policy); else @@ -1884,7 +1886,8 @@ void StmtPrinter::VisitConvertVectorExpr(ConvertVectorExpr *Node) { void StmtPrinter::VisitInitListExpr(InitListExpr* Node) { if (Node->getSyntacticForm()) { #if ENABLE_BSC - if (!(Policy.RewriteBSC && Context->getLangOpts().EnableFatPtr)) { + if (!(Policy.RewriteBSC && + Context->getLangOpts().getFatPtrCheck() != LangOptions::FPC_None)) { #endif Visit(Node->getSyntacticForm()); return; diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp index c9d21233d4ea..fcd4ff87c03d 100644 --- a/clang/lib/CodeGen/CGExprAgg.cpp +++ b/clang/lib/CodeGen/CGExprAgg.cpp @@ -1167,7 +1167,8 @@ void AggExprEmitter::VisitBinAssign(const BinaryOperator *E) { // For an assignment to work, the value on the right has // to be compatible with the value on the left. #if ENABLE_BSC - if (!(CGF.getLangOpts().BSC && CGF.getLangOpts().EnableFatPtr && + if (!(CGF.getLangOpts().BSC && + CGF.getLangOpts().getFatPtrCheck() != LangOptions::FPC_None && E->getLHS()->getType().isFatPtrRecordType() && E->getRHS()->getType().isFatPtrRecordType())) #endif diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index ca169a639f95..dc99758bc619 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -4818,8 +4818,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, #if ENABLE_BSC if (Args.getLastArg(options::OPT_opt_string)) Args.AddLastArg(CmdArgs, options::OPT_opt_string); - if (Args.hasArg(options::OPT_enable_fat_ptr)) - CmdArgs.push_back("-enable-fat-ptr"); if (Args.hasArg(options::OPT_disable_ownership_check)) CmdArgs.push_back("-disable-ownership-check"); if (Args.hasArg(options::OPT_nullability_check)) { @@ -4830,7 +4828,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, else CmdArgs.push_back(Args.MakeArgString("-nullability-check=" + v)); } - + if (Args.hasArg(options::OPT_fat_ptr_check)) { + Arg *A = Args.getLastArg(options::OPT_fat_ptr_check); + StringRef v = A->getValue(); + if (v.empty()) + D.Diag(diag::err_drv_missing_argument) << A->getSpelling() << 1; + else + CmdArgs.push_back(Args.MakeArgString("-fat-ptr-check=" + v)); + } #endif auto *MemProfArg = Args.getLastArg(options::OPT_fmemory_profile, diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index c8800c857751..93acb89b347e 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -1291,6 +1291,9 @@ static void InitializePredefinedMacros(const TargetInfo &TI, #if ENABLE_BSC if (LangOpts.BSC) { Builder.defineMacro("__bishengc"); + if (LangOpts.getFatPtrCheck() != LangOptions::FPC_None) { + Builder.defineMacro("__bsc_fat_ptr"); + } } #endif diff --git a/clang/lib/Frontend/Rewrite/RewriteBSC.cpp b/clang/lib/Frontend/Rewrite/RewriteBSC.cpp index 9513f424dcab..dc1929116135 100644 --- a/clang/lib/Frontend/Rewrite/RewriteBSC.cpp +++ b/clang/lib/Frontend/Rewrite/RewriteBSC.cpp @@ -553,7 +553,7 @@ void RewriteBSC::RewriteDecls() { // For decls with bsc feature, we use pretty printer. // For decls without bsc feature, we use original string text. if (DeclsWithoutBSCFeature.find(D) == DeclsWithoutBSCFeature.end()) { - if (Context->getLangOpts().EnableFatPtr) + if (Context->getLangOpts().getFatPtrCheck() != LangOptions::FPC_None) if (auto CTSD = dyn_cast(D)) if (CTSD->getNameAsString() == "_FatPtr") continue; @@ -619,7 +619,7 @@ void RewriteBSC::RewriteRecordDeclaration(std::vector &DeclList) { break; } } - if (Context->getLangOpts().EnableFatPtr && + if (Context->getLangOpts().getFatPtrCheck() != LangOptions::FPC_None && CTD->getNameAsString() == "_FatPtr") { RewriteFatPtrRecord(CTD); break; diff --git a/clang/lib/Headers/bsc_include/bsc_fat_ptr.hbs b/clang/lib/Headers/bsc_include/bsc_fat_ptr.hbs index 9cf3488305d6..05a7398b2a73 100644 --- a/clang/lib/Headers/bsc_include/bsc_fat_ptr.hbs +++ b/clang/lib/Headers/bsc_include/bsc_fat_ptr.hbs @@ -34,6 +34,7 @@ struct _AllocationUnit { enum _FatPtrErrorKind { AllocateZero = 0, FreeNotHeadPointer, + FreeRawPointer, DoubleFree, UseAfterFree, OutOfBoundsAccess, @@ -47,6 +48,9 @@ static void _report_error(enum _FatPtrErrorKind kind, char *file_name, case AllocateZero: msg = "Allocated size cannot be ZERO"; break; + case FreeRawPointer: + msg = "Free a fat pointer cast from a raw pointer"; + break; case FreeNotHeadPointer: msg = "Cannot free this pointer because it does not point to the head of an allocation"; break; @@ -84,6 +88,7 @@ static uint32_t _new_version_number() { return atomic_load(&uuid); } +#ifdef __bsc_fat_ptr static _FatPtr checked_malloc(size_t payload_bytes) { if (payload_bytes == 0) _report_error(AllocateZero, 0, 0, 0); @@ -100,10 +105,8 @@ static _FatPtr checked_malloc(size_t payload_bytes) { static void checked_free(_FatPtr ptr) { if (ptr.raw_ptr == nullptr) return; - if (ptr.key_version == 0) { - free((uint8_t*)ptr.raw_ptr - 8); - return; - } + if (ptr.key_version == 0) + _report_error(FreeRawPointer, 0, 0, 0); uint8_t* head = (uint8_t*)ptr.raw_ptr - ptr.offset - 8; struct _AllocationUnit* phead = (struct _AllocationUnit *)head; if (ptr.key_version != 0 && ptr.key_version != phead->lock_version) { @@ -111,9 +114,19 @@ static void checked_free(_FatPtr ptr) { } if (ptr.offset != 0) _report_error(FreeNotHeadPointer, 0, 0, 0); - memset(phead, 0, phead->size + 8); + // Only memset Allocation header(lock_version and size) to 0. + memset(phead, 0, 8); free(phead); } +#else +static void *fat checked_malloc(size_t payload_bytes) { + return (void *fat)malloc(payload_bytes); +} + +static void checked_free(void *fat ptr) { + free((void *)ptr); +} +#endif static __always_inline void _check_version( void *raw_ptr, uint32_t key_version, int32_t offset, diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index a577b8ff8cc1..786020f37df1 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -2235,7 +2235,7 @@ Parser::DeclGroupPtrTy Parser::ParseDeclGroup(ParsingDeclSpec &DS, #if ENABLE_BSC if (getLangOpts().BSC && FirstDecl) { if (FunctionDecl *FD = dyn_cast_or_null(FirstDecl)) { - if (getLangOpts().EnableFatPtr) + if (getLangOpts().getFatPtrCheck() != LangOptions::FPC_None) Actions.DesugarFunctionDeclWithFatPtr(FD); if (FD->isAsyncSpecified()) { SmallVector Decls = Actions.ActOnAsyncFunctionDeclaration(FD); @@ -2244,10 +2244,10 @@ Parser::DeclGroupPtrTy Parser::ParseDeclGroup(ParsingDeclSpec &DS, } } } else if (VarDecl *VD = dyn_cast_or_null(FirstDecl)) { - if (getLangOpts().EnableFatPtr && VD->hasGlobalStorage()) { + if (getLangOpts().getFatPtrCheck() != LangOptions::FPC_None && + VD->hasGlobalStorage()) { QualType QT = VD->getType().getCanonicalType(); - if (VD->hasAttr() && - QT->isConstantArrayType()) { + if (VD->hasAttr()) { std::pair Decls = Actions.BuildAllocationUnitForGlobalArrayVar(VD); DeclsInGroup.push_back(Decls.first); diff --git a/clang/lib/Sema/BSC/SemaBSCDestructor.cpp b/clang/lib/Sema/BSC/SemaBSCDestructor.cpp index 7ab37e21fc0d..46974ed12af5 100644 --- a/clang/lib/Sema/BSC/SemaBSCDestructor.cpp +++ b/clang/lib/Sema/BSC/SemaBSCDestructor.cpp @@ -313,6 +313,7 @@ public: VarDecl::Create(SemaRef.Context, FD, D->getLocation(), D->getLocation(), &(SemaRef.Context.Idents).get(IName), SemaRef.Context.BoolTy, nullptr, SC_None); + FD->addDecl(VD); llvm::APInt Zero(SemaRef.Context.getTypeSize(SemaRef.Context.IntTy), 0); Expr *IInit = IntegerLiteral::Create( SemaRef.Context, Zero, SemaRef.Context.IntTy, SourceLocation()); diff --git a/clang/lib/Sema/BSC/SemaBSCFatPtr.cpp b/clang/lib/Sema/BSC/SemaBSCFatPtr.cpp index 7a752ee200ab..46268977eb19 100644 --- a/clang/lib/Sema/BSC/SemaBSCFatPtr.cpp +++ b/clang/lib/Sema/BSC/SemaBSCFatPtr.cpp @@ -462,6 +462,7 @@ ImplicitCastExpr *FatPtrPreprocessor::ReplaceWithTemporaryVarDecl(Expr *E) { &SemaRef.Context.Idents.get(Name), QT, nullptr, SC_None); VD->setInit(CE); VD->markUsed(SemaRef.Context); + FD->addDecl(VD); DeclStmt *DS = new (SemaRef.Context) DeclStmt(DeclGroupRef(VD), SLoc, SLoc); CurrStmts.push_back(DS); DeclRefExpr *DRE = @@ -751,6 +752,7 @@ TransformFatPtr::BuildAllocationUnitHeaderForLocalNoArrayVars( UInt32Ty, nullptr, SC_None); llvm::SmallVector Args; LockVersionVD->setInit(BuildFatPtrCall(SLoc, "_new_version_number", Args)); + FD->addDecl(LockVersionVD); DeclStmt *LockVersionDS = new (SemaRef.Context) DeclStmt(DeclGroupRef(LockVersionVD), SLoc, SLoc); LocalLockVersionVD = LockVersionVD; @@ -761,6 +763,7 @@ TransformFatPtr::BuildAllocationUnitHeaderForLocalNoArrayVars( UInt32Ty, nullptr, SC_None); SizeVD->setInit(IntegerLiteral::Create(SemaRef.Context, llvm::APInt(32, 0), UInt32Ty, SLoc)); + FD->addDecl(SizeVD); DeclStmt *SizeDS = new (SemaRef.Context) DeclStmt(DeclGroupRef(SizeVD), SLoc, SLoc); @@ -834,6 +837,7 @@ TransformFatPtr::BuildAllocationUnitForLocalArrayVar(VarDecl *VD) { Expr *ILE = SemaRef.BuildInitList(SLoc, Inits, SLoc).get(); ILE->setType(QualType(RD->getTypeForDecl(), 0)); NewVD->setInit(ILE); + FD->addDecl(NewVD); AllocationUnitForLocalArrayVarMap[VD] = std::make_pair(RD, NewVD); DeclStmt *RDDS = new (SemaRef.Context) DeclStmt(DeclGroupRef(RD), SLoc, SLoc); DeclStmt *NewVDDS = new (SemaRef.Context) DeclStmt(DeclGroupRef(NewVD), SLoc, SLoc); @@ -1136,12 +1140,22 @@ TransformFatPtr::HandlePEFromPreprocessedSelfIncOrDecExpr(ParenExpr *PE) { auto BO = dyn_cast(PE->getSubExpr()); assert(BO->getOpcode() == BO_Comma); DesugarToMemberPtr = false; + if (SemaRef.Context.getLangOpts().getFatPtrCheck() == LangOptions::FPC_Offset) + InsertCheckVersionCall = false; + if (SemaRef.Context.getLangOpts().getFatPtrCheck() == LangOptions::FPC_Version) { + InsertCheckOffsetCall.first = false; + InsertCheckOffsetCall.second = nullptr; + } if (!InsertCheckVersionCall && !InsertCheckOffsetCall.first) { BO->setLHS(BaseTransform::TransformExpr(BO->getLHS()).get()); BO->setRHS(BaseTransform::TransformExpr(BO->getRHS()).get()); PE->setSubExpr(BO); } else { - llvm::SmallVector Args{InsertCheckOffsetCall.second}; + bool ShouldInsertCheckVersion = InsertCheckVersionCall; + bool ShouldInsertCheckOffset = InsertCheckOffsetCall.first; + llvm::SmallVector Args; + if (ShouldInsertCheckOffset) + Args.push_back(InsertCheckOffsetCall.second); InsertCheckOffsetCall.first = false; InsertCheckVersionCall = false; Expr *FirstE = BaseTransform::TransformExpr(BO->getLHS()).get(); @@ -1161,7 +1175,13 @@ TransformFatPtr::HandlePEFromPreprocessedSelfIncOrDecExpr(ParenExpr *PE) { auto ILE = dyn_cast(CLE->getInitializer()); for (unsigned i = 0; i < ILE->getNumInits(); i++) Args.push_back(ILE->getInit(i)); - SecondE = BuildFatPtrCall(SLoc, "_check_version_and_offset", Args, true); + if (ShouldInsertCheckVersion && ShouldInsertCheckOffset) { + SecondE = BuildFatPtrCall(SLoc, "_check_version_and_offset", Args, true); + } else if (ShouldInsertCheckVersion) { + SecondE = BuildFatPtrCall(SLoc, "_check_version", Args, true); + } else if (ShouldInsertCheckOffset) { + SecondE = BuildFatPtrCall(SLoc, "_check_offset", Args, true); + } } else if (auto ICE = dyn_cast(ThirdE)) { // `*++p` has been preprocessed to `*(p = p + 1, p)`, // here we desugar it to @@ -2105,11 +2125,18 @@ MemberExpr *TransformFatPtr::BuildMemberRawPtrAndInsertCheckCallForFatPtr( if (FatPtrCheckedStatus == 1 || FatPtrCheckedStatus == 3) { InsertCheckVersionCall = false; } - if (FatPtrCheckedStatus == 2 || FatPtrCheckedStatus == 3) { + if (FatPtrCheckedStatus == 2 || FatPtrCheckedStatus == 3 || + SemaRef.Context.getLangOpts().getFatPtrCheck() == LangOptions::FPC_Version) { InsertCheckOffsetCall.first = false; InsertCheckOffsetCall.second = nullptr; } } + if (SemaRef.Context.getLangOpts().getFatPtrCheck() == LangOptions::FPC_Offset) + InsertCheckVersionCall = false; + if (SemaRef.Context.getLangOpts().getFatPtrCheck() == LangOptions::FPC_Version) { + InsertCheckOffsetCall.first = false; + InsertCheckOffsetCall.second = nullptr; + } if (InsertCheckOffsetCall.first && InsertCheckVersionCall) { // Build CallExpr to check version and offset. llvm::SmallVector Args{InsertCheckOffsetCall.second, FatPtrBaseE}; diff --git a/clang/lib/Sema/BSC/SemaDeclBSC.cpp b/clang/lib/Sema/BSC/SemaDeclBSC.cpp index fe82b6f447c6..608639df63f9 100644 --- a/clang/lib/Sema/BSC/SemaDeclBSC.cpp +++ b/clang/lib/Sema/BSC/SemaDeclBSC.cpp @@ -222,7 +222,7 @@ void Sema::BSCDataflowAnalysis(const FunctionDecl *FD, } // TODO: add RequireFatPtrReduntantCheck according to whether // current function contains fat ptr feature - if (getLangOpts().EnableFatPtr && FD && AC.getCFG()) { + if (getLangOpts().getFatPtrCheck() != LangOptions::FPC_None && FD && AC.getCFG()) { runFatPtrReduntantCheck(*FD, *AC.getCFG(), AC, Context); } } diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index a3848d8a1f5d..c6ef181347b1 100755 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -6897,7 +6897,7 @@ Sema::ActOnTypedefNameDecl(Scope *S, DeclContext *DC, TypedefNameDecl *NewTD, } #if ENABLE_BSC - if (getLangOpts().BSC && getLangOpts().EnableFatPtr) + if (getLangOpts().BSC && getLangOpts().getFatPtrCheck() != LangOptions::FPC_None) DesugarTypedefNameDeclWithFatPtr(NewTD); #endif @@ -16036,7 +16036,7 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body, } // Desugar BSC Function. DesugarDestructorCall(FD); - if (getLangOpts().EnableFatPtr) + if (getLangOpts().getFatPtrCheck() != LangOptions::FPC_None) DesugarFunctionDeclWithFatPtr(FD); } } @@ -19041,7 +19041,7 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl, Record->completeDefinition(); #if ENABLE_BSC - if (getLangOpts().BSC && getLangOpts().EnableFatPtr) + if (getLangOpts().BSC && getLangOpts().getFatPtrCheck() != LangOptions::FPC_None) DesugarRecordDeclWithFatPtr(Record); #endif diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index dd35eac8f173..498069394949 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -8689,9 +8689,22 @@ static void handleOperatorAttr(Sema &S, Decl *D, const ParsedAttr &Attrs) { S.Context, Attrs, Attrs.getOperatorTypeBuffer().Kind)); } +static bool hasConstantArrayInType(QualType QT) { + QT = QT.getCanonicalType(); + if (QT->isConstantArrayType()) + return true; + else if (auto RT = dyn_cast(QT)) { + if (auto RD = dyn_cast(RT->getDecl())) + for (auto *FD : RD->fields()) + if (hasConstantArrayInType(FD->getType())) + return true; + } + return false; +} + static void handleFatPtrCheckedAttr(Sema &S, Decl *D, const ParsedAttr &Attrs) { if (auto VD = dyn_cast(D)) { - if (VD->hasGlobalStorage() && VD->getType()->isConstantArrayType()) { + if (VD->hasGlobalStorage() && hasConstantArrayInType(VD->getType())) { D->addAttr(::new (S.Context) FatPtrCheckedAttr(S.Context, Attrs)); return; } diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index fc83d60569f9..1e8b008a53f9 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -5897,7 +5897,8 @@ Sema::CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc, IndexExpr = RHSExp; ResultType = PTy->getPointeeType(); #if ENABLE_BSC - } else if (getLangOpts().BSC && getLangOpts().EnableFatPtr && + } else if (getLangOpts().BSC && + getLangOpts().getFatPtrCheck() != LangOptions::FPC_None && LHSTy.isFatPtrRecordType()) { BaseExpr = LHSExp; IndexExpr = RHSExp; @@ -8664,7 +8665,8 @@ static bool checkCondition(Sema &S, Expr *Cond, SourceLocation QuestionLoc) { if (CondTy->isScalarType()) return false; #if ENABLE_BSC - if (S.getLangOpts().BSC && S.getLangOpts().EnableFatPtr && + if (S.getLangOpts().BSC && + S.getLangOpts().getFatPtrCheck() != LangOptions::FPC_None && CondTy.isFatPtrRecordType()) return false; #endif @@ -9248,7 +9250,8 @@ QualType Sema::CheckConditionalOperands(ExprResult &Cond, ExprResult &LHS, if (!checkConditionalNullPointer(*this, RHS, LHSTy)) return LHSTy; if (!checkConditionalNullPointer(*this, LHS, RHSTy)) return RHSTy; #if ENABLE_BSC - if (getLangOpts().BSC && getLangOpts().EnableFatPtr) { + if (getLangOpts().BSC && + getLangOpts().getFatPtrCheck() != LangOptions::FPC_None) { if (RHS.get()->isNullExpr(Context) && LHSTy.isFatPtrType()) return LHSTy; if (LHS.get()->isNullExpr(Context) && RHSTy.isFatPtrType()) @@ -10033,7 +10036,8 @@ Sema::CheckAssignmentConstraints(QualType LHSType, ExprResult &RHS, QualType OrigLHSType = LHSType; #if ENABLE_BSC - if (getLangOpts().BSC && getLangOpts().EnableFatPtr && + if (getLangOpts().BSC && + getLangOpts().getFatPtrCheck() != LangOptions::FPC_None && Context.hasSameFatPtrType(LHSType, RHSType)) { Kind = CK_NoOp; return Compatible; @@ -14031,7 +14035,8 @@ inline QualType Sema::CheckLogicalOperands(ExprResult &LHS, ExprResult &RHS, if (RHS.isInvalid()) return QualType(); #if ENABLE_BSC - if (getLangOpts().BSC && getLangOpts().EnableFatPtr) { + if (getLangOpts().BSC && + getLangOpts().getFatPtrCheck() != LangOptions::FPC_None) { QualType LT = LHS.get()->getType(); QualType RT = RHS.get()->getType(); if ((LT->isScalarType() || LT.isFatPtrType()) && @@ -15025,7 +15030,8 @@ QualType Sema::GetBSCAddressOperandQualType(QualType resultType, } else if (Opc == UO_AddrFat && !resultType.isNull()) { if (auto ME = dyn_cast(InputExpr)) { // if p is no-fat pointer, `&fat p->a` is not allowed. - if (ME->isArrow() && !ME->getBase()->getType().isFatQualified()) + QualType BaseQT = ME->getBase()->getType(); + if (BaseQT->isPointerType() && !BaseQT.isFatQualified()) Diag(OpLoc, diag::err_addr_fat_on_no_fat_pointer) << InputExpr->getSourceRange(); InputExpr = ME->getBase()->IgnoreImpCasts(); @@ -15035,6 +15041,9 @@ QualType Sema::GetBSCAddressOperandQualType(QualType resultType, if (BaseQT->isPointerType() && !BaseQT.isFatQualified()) Diag(OpLoc, diag::err_addr_fat_on_no_fat_pointer) << InputExpr->getSourceRange(); + if (BaseQT->isVariableArrayType()) + Diag(OpLoc, diag::err_addr_fat_on_variable_array) + << InputExpr->getSourceRange(); InputExpr = ASE->getBase()->IgnoreImpCasts(); } if (auto DRE = dyn_cast(InputExpr)) { @@ -15318,7 +15327,8 @@ static QualType CheckIndirectionOperand(Sema &S, Expr *Op, ExprValueKind &VK, OpTy->getAs()) Result = OPT->getPointeeType(); #if ENABLE_BSC - else if (S.getLangOpts().BSC && S.getLangOpts().EnableFatPtr && + else if (S.getLangOpts().BSC && + S.getLangOpts().getFatPtrCheck() != LangOptions::FPC_None && OpTy.isFatPtrRecordType()) Result = OpTy.getFatPtrPointeeType(); #endif @@ -15710,7 +15720,8 @@ ExprResult Sema::CreateBuiltinBinOp(SourceLocation OpLoc, checkTypeSupport(LHSExpr->getType(), OpLoc, /*ValueDecl*/ nullptr); checkTypeSupport(RHSExpr->getType(), OpLoc, /*ValueDecl*/ nullptr); #if ENABLE_BSC - if (getLangOpts().BSC && getLangOpts().EnableFatPtr && + if (getLangOpts().BSC && + getLangOpts().getFatPtrCheck() != LangOptions::FPC_None && LHSExpr->getType().isFatPtrRecordType() && (Opc == BO_Add || Opc == BO_Sub)) { ResultTy = @@ -16575,7 +16586,8 @@ ExprResult Sema::CreateBuiltinUnaryOp(SourceLocation OpLoc, if (resultType->isDependentType()) break; #if ENABLE_BSC - if (getLangOpts().BSC && getLangOpts().EnableFatPtr && + if (getLangOpts().BSC && + getLangOpts().getFatPtrCheck() != LangOptions::FPC_None && resultType.isFatPtrRecordType()) resultType = Context.getPointerType(resultType.getFatPtrPointeeType()); #endif @@ -20984,7 +20996,8 @@ ExprResult Sema::CheckBooleanCondition(SourceLocation Loc, Expr *E, QualType T = E->getType(); #if ENABLE_BSC - if (getLangOpts().BSC && getLangOpts().EnableFatPtr && + if (getLangOpts().BSC && + getLangOpts().getFatPtrCheck() != LangOptions::FPC_None && T.isFatPtrRecordType()) return E; #endif diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index a97fd9eaefde..0bba085e3d74 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -7560,7 +7560,8 @@ ExprResult Sema::ActOnStartCXXMemberReference(Scope *S, Expr *Base, while (BaseType->isRecordType()) { #if ENABLE_BSC - if (getLangOpts().BSC && getLangOpts().EnableFatPtr && + if (getLangOpts().BSC && + getLangOpts().getFatPtrCheck() != LangOptions::FPC_None && BaseType.isFatPtrRecordType()) { BaseType = BaseType.getFatPtrPointeeType(); break; diff --git a/clang/lib/Sema/SemaExprMember.cpp b/clang/lib/Sema/SemaExprMember.cpp index 1615ed62b836..3c5085629be4 100644 --- a/clang/lib/Sema/SemaExprMember.cpp +++ b/clang/lib/Sema/SemaExprMember.cpp @@ -1076,7 +1076,8 @@ Sema::BuildMemberReferenceExpr(Expr *BaseExpr, QualType BaseExprType, QualType BaseType = BaseExprType; if (IsArrow) { #if ENABLE_BSC - if (getLangOpts().BSC && getLangOpts().EnableFatPtr && + if (getLangOpts().BSC && + getLangOpts().getFatPtrCheck() != LangOptions::FPC_None && BaseType.isFatPtrRecordType()) BaseType = BaseType.getFatPtrPointeeType(); else { @@ -1506,7 +1507,8 @@ static ExprResult LookupMemberExpr(Sema &S, LookupResult &R, = BaseType->getAs()) BaseType = Ptr->getPointeeType(); # if ENABLE_BSC - else if (S.getLangOpts().BSC && S.getLangOpts().EnableFatPtr && + else if (S.getLangOpts().BSC && + S.getLangOpts().getFatPtrCheck() != LangOptions::FPC_None && BaseType.isFatPtrRecordType()) BaseType = BaseType.getFatPtrPointeeType(); # endif @@ -2123,7 +2125,8 @@ Sema::BuildFieldReferenceExpr(Expr *BaseExpr, bool IsArrow, if (IsArrow) # if ENABLE_BSC { - if (getLangOpts().BSC && getLangOpts().EnableFatPtr && + if (getLangOpts().BSC && + getLangOpts().getFatPtrCheck() != LangOptions::FPC_None && BaseType.isFatPtrRecordType()) BaseType = BaseType.getFatPtrPointeeType(); else diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index 2cfb27547633..d7140ddb721f 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -2017,7 +2017,7 @@ static bool IsStandardConversion(Sema &S, Expr* From, QualType ToType, if (TD == S.TryDesugarTrait(FromType)) return true; } - if (S.getLangOpts().EnableFatPtr) { + if (S.getLangOpts().getFatPtrCheck() != LangOptions::FPC_None) { if (FromType.isFatPtrType() && ToType.isFatPtrType() && S.Context.hasSameType(FromType.getFatPtrPointeeType(), ToType.getFatPtrPointeeType())) { diff --git a/clang/test/BSC/Negative/FatPtr/addr_fat.cbs b/clang/test/BSC/Negative/FatPtr/addr_fat.cbs index c9c3f31b38d8..0c5c0dad4945 100644 --- a/clang/test/BSC/Negative/FatPtr/addr_fat.cbs +++ b/clang/test/BSC/Negative/FatPtr/addr_fat.cbs @@ -55,4 +55,22 @@ void test3() { __attribute__((fat_ptr_checked)) static int x1 = 10; // expected-error {{fat_ptr_checked attribute can only used for global or static array variables}} static int x2 = 10; int *fat p4 = &fat x2; // expected-error {{'&fat' on global variables without fat_ptr_checked attribute is not allowed}} +} + +struct S1 { + int a; +}; +struct S2 { + int arr[3]; +}; +__attribute__((fat_ptr_checked)) struct S1 s1; // expected-error {{fat_ptr_checked attribute can only used for global or static array variables}} +__attribute__((fat_ptr_checked)) struct S2 s2; +void test4() { + int *fat p1 = &fat s2.arr[2]; +} + +void test5() { + int x = 10; + int arr[x]; + int *fat p = &fat arr[2];// expected-error {{'&fat' on member of variable array is not allowed}} } \ No newline at end of file diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/global_array/array_out_of_bounds1.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/global_array/array_out_of_bounds1.cbs index 808528c68ccb..b0ae6a2689bd 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/global_array/array_out_of_bounds1.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/global_array/array_out_of_bounds1.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/global_array/array_out_of_bounds2.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/global_array/array_out_of_bounds2.cbs index 87932c20abc4..0a4bfd4f3787 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/global_array/array_out_of_bounds2.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/global_array/array_out_of_bounds2.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/global_array/array_out_of_bounds3.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/global_array/array_out_of_bounds3.cbs new file mode 100644 index 000000000000..1a70fc9d10cf --- /dev/null +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/global_array/array_out_of_bounds3.cbs @@ -0,0 +1,33 @@ +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output + +#include +struct S { + int arr[3]; +}; +__attribute__((fat_ptr_checked)) struct S s = { {1, 2, 3} }; + +int main() { + int *fat p = &fat s.arr[2]; + int *fat p1 = p + 1; + *p1 = 10; + return 0; +} +// CHECK: Error: Pointer offset exceeds the allocation size! +// CHECK-NEXT: Error at: {{[^ ]*}}clang/test/BSC/Negative/FatPtr/version_and_offset_check/global_array/array_out_of_bounds3.cbs:[[@LINE-4]] in main + +// CHECK_REWRITE: Error: Pointer offset exceeds the allocation size! \ No newline at end of file diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds1.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds1.cbs index 5a33310bb120..c11c6bdc81b1 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds1.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds1.cbs @@ -1,8 +1,20 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output + #include int main() { diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds10.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds10.cbs index d17365dc3916..13a1243ac57f 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds10.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds10.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds11.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds11.cbs index 6ccbfaf5f9dd..57c5c136486f 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds11.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds11.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds12.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds12.cbs index adcf493632ca..b7291e9a0048 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds12.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds12.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds13.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds13.cbs index 678efe61c9e4..f930156be638 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds13.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds13.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds14.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds14.cbs index 0596724fb1a6..1f6564dcea5f 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds14.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds14.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds15.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds15.cbs index ff9a588c37a0..c74371c9603e 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds15.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds15.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds16.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds16.cbs index c73e2c7e3b94..c47bfc309244 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds16.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds16.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds17.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds17.cbs index ffff7ed5b15d..5ddbc2333857 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds17.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds17.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds18.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds18.cbs index 0c5de151e3da..e87184baf258 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds18.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds18.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds19.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds19.cbs index 3fe6c1756968..f78274398e42 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds19.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds19.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds2.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds2.cbs index 250a016ccd9a..84946018cda2 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds2.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds2.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include struct S { int *fat p; }; diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds20.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds20.cbs index b2b85fc016b0..ec82fe84209d 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds20.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds20.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include int *fat return_fat() { diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds21.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds21.cbs index dab1a0677c53..6ec4b6d581c1 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds21.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds21.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds22.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds22.cbs index 06026faef3f1..ae8c7ae44992 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds22.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds22.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds23.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds23.cbs index 5121f47f5c43..3ea2df5ab583 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds23.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds23.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds24.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds24.cbs index 139155ec5d30..c12748bb510e 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds24.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds24.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds3.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds3.cbs index 7257cf7677e1..cd0da15f3833 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds3.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds3.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds4.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds4.cbs index 9a04b5bb800f..085153ae346b 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds4.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds4.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds5.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds5.cbs index f5bae62d9392..c295fcccc3bd 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds5.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds5.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds6.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds6.cbs index c4108deaa7e4..611b0a107bbf 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds6.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds6.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds7.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds7.cbs index 918ef42f5ef8..56c9f7e11f54 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds7.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds7.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds8.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds8.cbs index 8bd93d146702..c0de1b75a2f1 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds8.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds8.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds9.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds9.cbs index 29682bed1f40..802d7068f910 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds9.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/array_out_of_bounds9.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/buffer_overflow.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/buffer_overflow.cbs index e84c92934dd0..49f24743896f 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/buffer_overflow.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/buffer_overflow.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output longstring 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output longstring 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output longstring 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output longstring 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output longstring 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output longstring 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include #define BUFSIZE 8 diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/checked_free_fat_from_raw.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/checked_free_fat_from_raw.cbs new file mode 100644 index 000000000000..eeef0f6ca823 --- /dev/null +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/checked_free_fat_from_raw.cbs @@ -0,0 +1,35 @@ +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: not %t-version.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output 2>&1 | FileCheck %s +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: not %t-version-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output + +#include + +int *fat test() { + int *p = malloc(sizeof(int)); + return (int *fat)p; +} + +int main() { + int *fat p = test(); + checked_free((void *fat)p); + return 0; +} + +// CHECK: Error: Free a fat pointer cast from a raw pointer! + +// CHECK_REWRITE: Error: Free a fat pointer cast from a raw pointer! \ No newline at end of file diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/double_free1.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/double_free1.cbs index 990b0694b5b5..03818dc448d0 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/double_free1.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/double_free1.cbs @@ -1,8 +1,21 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: not %t-version.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output 2>&1 | FileCheck %s +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: not %t-version-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/double_free2.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/double_free2.cbs index 10a74377018f..de376419110d 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/double_free2.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/double_free2.cbs @@ -1,8 +1,21 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: not %t-version.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output 2>&1 | FileCheck %s +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: not %t-version-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/double_free3.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/double_free3.cbs index ec5603d9cab6..102b8278f929 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/double_free3.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/double_free3.cbs @@ -1,8 +1,21 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: not %t-version.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output 2>&1 | FileCheck %s +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: not %t-version-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/double_free4.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/double_free4.cbs index 4fead9d6cb42..c94ba5c71bf5 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/double_free4.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/double_free4.cbs @@ -1,8 +1,21 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: not %t-version.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output 2>&1 | FileCheck %s +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: not %t-version-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/use_after_free1.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/use_after_free1.cbs index fa819d279390..29fd1231d5d5 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/use_after_free1.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/use_after_free1.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: not %t-version.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: not %t-version-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/use_after_free2.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/use_after_free2.cbs index 81a61e4a3b99..19c00cec84db 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/use_after_free2.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/use_after_free2.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: not %t-version.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: not %t-version-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/use_after_free3.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/use_after_free3.cbs index 9b0b9e4a1e1a..8f923e66e65c 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/use_after_free3.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/use_after_free3.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: not %t-version.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: not %t-version-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/use_after_free4.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/use_after_free4.cbs index 0f05fd96231e..a915e64fb9a2 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/use_after_free4.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/use_after_free4.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: not %t-version.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: not %t-version-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/use_after_free5.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/use_after_free5.cbs index 8de15ede94da..e769714cc36e 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/use_after_free5.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/use_after_free5.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: not %t-version.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: not %t-version-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include #define BUFSIZE 32 diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/use_after_free6.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/use_after_free6.cbs index e5bfcd027159..01bc38c24917 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/use_after_free6.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/use_after_free6.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: not %t-version.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: not %t-version-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/use_after_free7.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/use_after_free7.cbs index 6a4fe7029e6c..8f47117e5319 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/use_after_free7.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/use_after_free7.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: not %t-version.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: not %t-version-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/use_after_free8.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/use_after_free8.cbs index 0ea01d4e2dfb..26242cf08a96 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/use_after_free8.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/heap/use_after_free8.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: not %t-version.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: not %t-version-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/array_out_of_bounds1.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/array_out_of_bounds1.cbs index 95626b015062..2d3479b3a893 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/array_out_of_bounds1.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/array_out_of_bounds1.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/array_out_of_bounds2.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/array_out_of_bounds2.cbs index 402aa037db0f..b84bfdbb9630 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/array_out_of_bounds2.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/array_out_of_bounds2.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/array_out_of_bounds3.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/array_out_of_bounds3.cbs index dea1a8b0a909..af10311a4f08 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/array_out_of_bounds3.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/array_out_of_bounds3.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/array_out_of_bounds4.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/array_out_of_bounds4.cbs index 8f3465267eb0..8421fde00d8d 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/array_out_of_bounds4.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/array_out_of_bounds4.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/buffer_overflow.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/buffer_overflow.cbs index 582df755ea21..16500858057a 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/buffer_overflow.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/buffer_overflow.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output longstring 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output longstring 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output longstring 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: not %t-offset.output longstring 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output longstring 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: not %t-offset-rw.output longstring 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include #define BUFSIZE 8 diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/return_local_address.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/return_local_address.cbs index 7f36b4c1932a..4860e8dad2ce 100644 --- a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/return_local_address.cbs +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/return_local_address.cbs @@ -1,8 +1,19 @@ -// RUN: %clang -enable-fat-ptr %s -o %t.output -// RUN: not %t.output 2>&1 | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c -// RUN: %clang %t-rw.c -o %t-rw.output -// RUN: not %t-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: not %t-version.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: not %t-version-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output #include diff --git a/clang/test/BSC/Positive/FatPtr/global_array.cbs b/clang/test/BSC/Positive/FatPtr/global_array.cbs index 9c77c2999d8a..b465a4281556 100644 --- a/clang/test/BSC/Positive/FatPtr/global_array.cbs +++ b/clang/test/BSC/Positive/FatPtr/global_array.cbs @@ -1,6 +1,6 @@ -// RUN: %clang %s -enable-fat-ptr -o %t.output +// RUN: %clang %s -fat-ptr-check=both -Wall -o %t.output // RUN: %t.output -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-rw.c // RUN: %clang %t-rw.c -o %t-rw.output // RUN: %t-rw.output // expected-no-diagnostics diff --git a/clang/test/BSC/Positive/FatPtr/heap.cbs b/clang/test/BSC/Positive/FatPtr/heap.cbs index 3a02ff54c677..74d168a88478 100644 --- a/clang/test/BSC/Positive/FatPtr/heap.cbs +++ b/clang/test/BSC/Positive/FatPtr/heap.cbs @@ -1,6 +1,6 @@ -// RUN: %clang %s -enable-fat-ptr -o %t.output +// RUN: %clang %s -fat-ptr-check=both -Wall -o %t.output // RUN: %t.output -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-rw.c // RUN: %clang %t-rw.c -o %t-rw.output // RUN: %t-rw.output // expected-no-diagnostics diff --git a/clang/test/BSC/Positive/FatPtr/multi_level_pointer.cbs b/clang/test/BSC/Positive/FatPtr/multi_level_pointer.cbs index 182dfc7a432c..20491c7fbd8d 100644 --- a/clang/test/BSC/Positive/FatPtr/multi_level_pointer.cbs +++ b/clang/test/BSC/Positive/FatPtr/multi_level_pointer.cbs @@ -1,6 +1,6 @@ -// RUN: %clang %s -enable-fat-ptr -o %t.output +// RUN: %clang %s -fat-ptr-check=both -Wall -o %t.output // RUN: %t.output | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-rw.c // RUN: %clang %t-rw.c -o %t-rw.output // RUN: %t-rw.output | FileCheck %s // expected-no-diagnostics diff --git a/clang/test/BSC/Positive/FatPtr/nullptr_cast/nullptr_cast.cbs b/clang/test/BSC/Positive/FatPtr/nullptr_cast/nullptr_cast.cbs index f835dc7a158a..78f9fc5b1e74 100644 --- a/clang/test/BSC/Positive/FatPtr/nullptr_cast/nullptr_cast.cbs +++ b/clang/test/BSC/Positive/FatPtr/nullptr_cast/nullptr_cast.cbs @@ -1,6 +1,6 @@ -// RUN: %clang %s -enable-fat-ptr -o %t.output +// RUN: %clang %s -fat-ptr-check=both -o %t.output // RUN: %t.output -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-rw.c // RUN: %clang %t-rw.c -o %t-rw.output // RUN: %t-rw.output // expected-no-diagnostics diff --git a/clang/test/BSC/Positive/FatPtr/redundant_check/func_call.cbs b/clang/test/BSC/Positive/FatPtr/redundant_check/func_call.cbs index 929d2a344982..0514f17b71e9 100644 --- a/clang/test/BSC/Positive/FatPtr/redundant_check/func_call.cbs +++ b/clang/test/BSC/Positive/FatPtr/redundant_check/func_call.cbs @@ -1,6 +1,6 @@ -// RUN: %clang %s -enable-fat-ptr -c -Xclang -ast-dump \ +// RUN: %clang %s -fat-ptr-check=both -c -Xclang -ast-dump \ // RUN: | FileCheck --strict-whitespace %s -// RUN: %clang %s -enable-fat-ptr -o %test.output +// RUN: %clang %s -fat-ptr-check=both -o %test.output #include diff --git a/clang/test/BSC/Positive/FatPtr/redundant_check/if_stmt.cbs b/clang/test/BSC/Positive/FatPtr/redundant_check/if_stmt.cbs index 4d9a6383aa67..d379a775dabe 100644 --- a/clang/test/BSC/Positive/FatPtr/redundant_check/if_stmt.cbs +++ b/clang/test/BSC/Positive/FatPtr/redundant_check/if_stmt.cbs @@ -1,6 +1,6 @@ -// RUN: %clang %s -enable-fat-ptr -c -Xclang -ast-dump \ +// RUN: %clang %s -fat-ptr-check=both -c -Xclang -ast-dump \ // RUN: | FileCheck --strict-whitespace %s -// RUN: %clang %s -enable-fat-ptr -o %test.output +// RUN: %clang %s -fat-ptr-check=both -o %test.output #include diff --git a/clang/test/BSC/Positive/FatPtr/redundant_check/member_visit.cbs b/clang/test/BSC/Positive/FatPtr/redundant_check/member_visit.cbs index 0ac958d9d6ac..fa499c880f65 100644 --- a/clang/test/BSC/Positive/FatPtr/redundant_check/member_visit.cbs +++ b/clang/test/BSC/Positive/FatPtr/redundant_check/member_visit.cbs @@ -1,6 +1,6 @@ -// RUN: %clang %s -enable-fat-ptr -c -Xclang -ast-dump \ +// RUN: %clang %s -fat-ptr-check=both -c -Xclang -ast-dump \ // RUN: | FileCheck --strict-whitespace %s -// RUN: %clang %s -enable-fat-ptr -o %test.output +// RUN: %clang %s -fat-ptr-check=both -o %test.output #include diff --git a/clang/test/BSC/Positive/FatPtr/stack.cbs b/clang/test/BSC/Positive/FatPtr/stack.cbs index b7a13ea08243..5d021a5af940 100644 --- a/clang/test/BSC/Positive/FatPtr/stack.cbs +++ b/clang/test/BSC/Positive/FatPtr/stack.cbs @@ -1,6 +1,6 @@ -// RUN: %clang %s -enable-fat-ptr -o %t.output +// RUN: %clang %s -fat-ptr-check=both -Wall -o %t.output // RUN: %t.output -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-rw.c // RUN: %clang %t-rw.c -o %t-rw.output // RUN: %t-rw.output // expected-no-diagnostics diff --git a/clang/test/BSC/Positive/FatPtr/string_literal.cbs b/clang/test/BSC/Positive/FatPtr/string_literal.cbs index 237200bff930..da22ab469e3d 100644 --- a/clang/test/BSC/Positive/FatPtr/string_literal.cbs +++ b/clang/test/BSC/Positive/FatPtr/string_literal.cbs @@ -1,6 +1,6 @@ -// RUN: %clang %s -enable-fat-ptr -o %t.output +// RUN: %clang %s -fat-ptr-check=both -Wall -o %t.output // RUN: %t.output | FileCheck %s -// RUN: %clang %s -enable-fat-ptr -rewrite-bsc -o %t-rw.c +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-rw.c // RUN: %clang %t-rw.c -o %t-rw.output // RUN: %t-rw.output | FileCheck %s // expected-no-diagnostics -- Gitee From c6daa285a6303761814d8258de8862a5504dfc9a Mon Sep 17 00:00:00 2001 From: liuxinyi Date: Wed, 19 Mar 2025 10:46:32 +0800 Subject: [PATCH 2/2] [FatPtr]build lock_version for every block and set all lock_version = 0 when block is over --- clang/lib/Sema/BSC/SemaBSCFatPtr.cpp | 220 +++++++++++++----- .../stack/use_after_scope1.cbs | 32 +++ .../stack/use_after_scope2.cbs | 32 +++ .../stack/use_after_scope3.cbs | 34 +++ .../stack/use_after_scope4.cbs | 34 +++ .../stack/use_after_scope5.cbs | 33 +++ 6 files changed, 328 insertions(+), 57 deletions(-) create mode 100644 clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/use_after_scope1.cbs create mode 100644 clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/use_after_scope2.cbs create mode 100644 clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/use_after_scope3.cbs create mode 100644 clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/use_after_scope4.cbs create mode 100644 clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/use_after_scope5.cbs diff --git a/clang/lib/Sema/BSC/SemaBSCFatPtr.cpp b/clang/lib/Sema/BSC/SemaBSCFatPtr.cpp index 46268977eb19..4fd37a094535 100644 --- a/clang/lib/Sema/BSC/SemaBSCFatPtr.cpp +++ b/clang/lib/Sema/BSC/SemaBSCFatPtr.cpp @@ -52,10 +52,15 @@ enum AddrFatExprBaseKind { class AddressFatTakenFinder : public StmtVisitor { bool IsVisitingAddrFatExpr = false; Expr *CurrentAddrFatExpr = nullptr; + CompoundStmt *CurrentCompoundStmt = nullptr; public: - bool LocalNoArrayVarAddressIsFatTaken = false; - llvm::SmallSet LocalArrayVarsSet; + llvm::DenseMap> + LocalNoArrayVarsAddressFatTaken; + llvm::DenseMap> + LocalArrayVarsAddressFatTaken; + llvm::DenseMap AllLocalNoArrayVars; + llvm::DenseMap AllLocalArrayVars; // Map of AddrFatExpr and its base expr and base kind: // key is AddrFatExpr, value is its base expr and kind. @@ -63,10 +68,12 @@ public: // 1. &fat p->a` where p is fat ptr // 2. &fat arr[5]` where arr is local array variable // 3. &fat g.arr[5]` where g is global variable whose type has array field + // 4. &fat s.a` where s is local variable whose type has no array field // the map will be: // &fat p->a : (FatPtr, p) // &fat arr[5] : (LocalArrayVar, arr) // &fat g.arr[5] : (GlobalArrayVar, g) + // &fat s.a : (LocalNoArrayVar, s) llvm::DenseMap> AddrFatExprAndBaseMap; @@ -89,6 +96,29 @@ public: Visit(C); } + void VisitCompoundStmt(CompoundStmt *CS) { + for (auto *C : CS->body()) { + CurrentCompoundStmt = CS; + if (C) + Visit(C); + } + } + + void VisitDeclStmt(DeclStmt *DS) { + assert(DS->isSingleDecl() && "DeclStmt can only contain a Decl here"); + if (VarDecl *VD = dyn_cast(DS->getSingleDecl())) { + QualType QT = VD->getType(); + if (hasConstantArray(QT)) { + AllLocalArrayVars[VD] = CurrentCompoundStmt; + } else { + AllLocalNoArrayVars[VD] = CurrentCompoundStmt; + } + } + for (auto *C : DS->children()) + if (C) + Visit(C); + } + void VisitUnaryOperator(UnaryOperator *UO) { if (UO->getOpcode() == UO_AddrFat) { IsVisitingAddrFatExpr = true; @@ -139,11 +169,12 @@ public: AddrFatExprAndBaseMap[CurrentAddrFatExpr].first = AddrFatExprBaseKind::LocalArrayVar; AddrFatExprAndBaseMap[CurrentAddrFatExpr].second = DRE; - LocalArrayVarsSet.insert(VD); + LocalArrayVarsAddressFatTaken[AllLocalArrayVars[VD]].insert(VD); } else { AddrFatExprAndBaseMap[CurrentAddrFatExpr].first = AddrFatExprBaseKind::LocalNoArrayVar; - LocalNoArrayVarAddressIsFatTaken = true; + AddrFatExprAndBaseMap[CurrentAddrFatExpr].second = DRE; + LocalNoArrayVarsAddressFatTaken[AllLocalNoArrayVars[VD]].insert(VD); } } else if (VD->hasGlobalStorage() && hasConstantArray(QT)) { AddrFatExprAndBaseMap[CurrentAddrFatExpr].first = @@ -482,7 +513,7 @@ class TransformFatPtr : public TreeTransform { ClassTemplateDecl *FatPtrTD = nullptr; AddressFatTakenFinder Finder; - VarDecl *LocalLockVersionVD = nullptr; + llvm::DenseMap LockVersionForLocalNoArrayVarMap; llvm::DenseMap> AllocationUnitForLocalArrayVarMap; @@ -573,19 +604,24 @@ public: ExprResult TransformUnaryOperator(UnaryOperator *UO); ExprResult HandleUODerefFatPtr(UnaryOperator *UO); ExprResult HandleUOAddrFatOnExprWithFatPtrBase(UnaryOperator *UO, Expr *FatPtrBaseE); - ExprResult HandleUOAddrFatOnLocalNoArrayVar(UnaryOperator *UO); + ExprResult HandleUOAddrFatOnLocalNoArrayVar(UnaryOperator *UO, + Expr *VarBaseE); ExprResult HandleUOAddrFatOnArrayVar(UnaryOperator *UO, Expr *VarBaseE); private: // Handle allocation unit for local vars whose address is taken by &fat. CompoundStmt *HandleLocalAllocationUnit(CompoundStmt *CS, - bool IsTopLevelCompoundStmt); + unsigned &CompoundStmtID); std::pair - BuildAllocationUnitHeaderForLocalNoArrayVars(SourceLocation SLoc); - - Expr *BuildLockVersionAssignmentForLocalNoArrayVars(SourceLocation SLoc); - + BuildAllocationUnitHeaderForLocalNoArrayVars(SourceLocation SLoc, + unsigned CompoundStmtID, + VarDecl *&LocalLockVersionVD); + Expr * + BuildLockVersionAssignmentForLocalNoArrayVars(SourceLocation SLoc, + VarDecl *LocalLockVersionVD); + Expr *BuildLockVersionAssignmentForLocalArrayVar(SourceLocation SLoc, + VarDecl *ArrayVar); std::pair BuildAllocationUnitForLocalArrayVar(VarDecl *VD); @@ -631,11 +667,12 @@ void TransformFatPtr::TransformFunctionDecl() { PreprocessedSelfIncOrDecExpr = Preprocessor.PreprocessedSelfIncOrDecExpr; // Second traversal: // find local vars whose address is taken by `&fat` expr. - Finder.VisitStmt(FD->getBody()); + Finder.VisitCompoundStmt(dyn_cast(FD->getBody())); // Third traversal - CompoundStmt *NewCS = - HandleLocalAllocationUnit(dyn_cast(FD->getBody()), true); + unsigned CompoundStmtID = 0; + CompoundStmt *NewCS = HandleLocalAllocationUnit( + dyn_cast(FD->getBody()), CompoundStmtID); // the last traversal: desugar stmt and expr of function body. FD->setBody(TransformStmt(NewCS).get()); @@ -677,42 +714,52 @@ void TransformFatPtr::TransformTypedefNameDecl(TypedefNameDecl *TND) { TND->setTypeSourceInfo(SemaRef.Context.getTrivialTypeSourceInfo(QT)); } -// 1. For all local vars whose type has no array and address is -// taken by &fat, we think they are packed in an allocation unit -// in stack and share a lock_version, so we build 2 VarDecl -// `_local_lock_version` and `_local_size` as allocation unit -// header and insert them to the beginning of function body. -// 2. Before function return, `_local_lock_version` should be set to -// 0, so we build assignment statement before return stmt and in the +// 1. For all local vars whose type has no array and address is taken by +// &fat in the same block, we think they share a lock_version, so we +// build 2 VarDecl `_local_lock_version_{block_id}` and +// `_local_size_{block_id}` as allocation unit +// header and insert them to the beginning of the block. +// 2. Before every block exit, `_local_lock_version_{block_id}` should be +// set to 0, so we build assignment statement before return/ stmt and in the // end of function body. // 3. For local var whose type has array and address is taken by &fat, // because every array have its own size, so we pack every var into // a struct as allocation unit. CompoundStmt * TransformFatPtr::HandleLocalAllocationUnit(CompoundStmt *CS, - bool IsTopLevelCompoundStmt) { - if (CS == nullptr || (!Finder.LocalNoArrayVarAddressIsFatTaken && - Finder.LocalArrayVarsSet.size() == 0)) + unsigned &CompoundStmtID) { + if (CS == nullptr) return CS; llvm::SmallVector Statements; - if (IsTopLevelCompoundStmt && Finder.LocalNoArrayVarAddressIsFatTaken) { + VarDecl *LocalLockVersionVD = nullptr; + if (Finder.LocalNoArrayVarsAddressFatTaken[CS].size() != 0) { std::pair Headers = - BuildAllocationUnitHeaderForLocalNoArrayVars(CS->getBeginLoc()); + BuildAllocationUnitHeaderForLocalNoArrayVars( + CS->getBeginLoc(), CompoundStmtID, LocalLockVersionVD); Statements.push_back(Headers.second); Statements.push_back(Headers.first); + for (auto LocalNoArrayVar : Finder.LocalNoArrayVarsAddressFatTaken[CS]) + LockVersionForLocalNoArrayVarMap[LocalNoArrayVar] = LocalLockVersionVD; } for (auto *B : CS->body()) { if (auto ChildCS = dyn_cast(B)) { - Statements.push_back(HandleLocalAllocationUnit(ChildCS, false)); - } else if (isa(B) && Finder.LocalNoArrayVarAddressIsFatTaken) { - Statements.push_back( - BuildLockVersionAssignmentForLocalNoArrayVars(B->getBeginLoc())); + CompoundStmtID += 1; + Statements.push_back(HandleLocalAllocationUnit(ChildCS, CompoundStmtID)); + } else if (isa(B)) { + if (LocalLockVersionVD) { + Statements.push_back(BuildLockVersionAssignmentForLocalNoArrayVars( + B->getBeginLoc(), LocalLockVersionVD)); + } + for (auto ArrayVar : Finder.LocalArrayVarsAddressFatTaken[CS]) { + Statements.push_back(BuildLockVersionAssignmentForLocalArrayVar( + B->getBeginLoc(), ArrayVar)); + } Statements.push_back(B); } else if (auto DS = dyn_cast(B)) { assert(DS->isSingleDecl() && "DeclStmt can only contain a Decl here"); bool NeedToReplace = false; if (VarDecl *VD = dyn_cast(DS->getSingleDecl())) { - if (Finder.LocalArrayVarsSet.count(VD)) { + if (Finder.LocalArrayVarsAddressFatTaken[CS].count(VD)) { std::pair Decls = BuildAllocationUnitForLocalArrayVar(VD); Statements.push_back(Decls.first); @@ -722,17 +769,48 @@ TransformFatPtr::HandleLocalAllocationUnit(CompoundStmt *CS, } if (!NeedToReplace) Statements.push_back(B); + } else if (auto IS = dyn_cast(B)) { + CompoundStmtID += 1; + IS->setThen(HandleLocalAllocationUnit( + dyn_cast(IS->getThen()), CompoundStmtID)); + CompoundStmtID += 1; + if (IS->getElse()) { + IS->setElse(HandleLocalAllocationUnit( + dyn_cast(IS->getElse()), CompoundStmtID)); + } + Statements.push_back(B); + } else if (auto WS = dyn_cast(B)) { + CompoundStmtID += 1; + WS->setBody(HandleLocalAllocationUnit( + dyn_cast(WS->getBody()), CompoundStmtID)); + Statements.push_back(B); + } else if (auto DS = dyn_cast(B)) { + CompoundStmtID += 1; + DS->setBody(HandleLocalAllocationUnit( + dyn_cast(DS->getBody()), CompoundStmtID)); + Statements.push_back(B); + } else if (auto FS = dyn_cast(B)) { + FS->setBody(HandleLocalAllocationUnit( + dyn_cast(FS->getBody()), CompoundStmtID)); + Statements.push_back(B); } else { Statements.push_back(B); } } - if (IsTopLevelCompoundStmt && Finder.LocalNoArrayVarAddressIsFatTaken) - Statements.push_back( - BuildLockVersionAssignmentForLocalNoArrayVars(CS->getEndLoc())); + if (LocalLockVersionVD) { + Statements.push_back(BuildLockVersionAssignmentForLocalNoArrayVars( + CS->getEndLoc(), LocalLockVersionVD)); + } + for (auto LocalArrayVar : Finder.LocalArrayVarsAddressFatTaken[CS]) { + Statements.push_back(BuildLockVersionAssignmentForLocalArrayVar( + CS->getEndLoc(), LocalArrayVar)); + } Sema::CompoundScopeRAII CompoundScope(SemaRef); - StmtResult NewCS = BaseTransform::RebuildCompoundStmt( - CS->getLBracLoc(), Statements, CS->getRBracLoc(), false); - return NewCS.getAs(); + CompoundStmt *NewCS = + BaseTransform::RebuildCompoundStmt(CS->getLBracLoc(), Statements, + CS->getRBracLoc(), false) + .getAs(); + return NewCS; } // Build allocation unit header for all local vars whose @@ -743,13 +821,16 @@ TransformFatPtr::HandleLocalAllocationUnit(CompoundStmt *CS, // @endcode std::pair TransformFatPtr::BuildAllocationUnitHeaderForLocalNoArrayVars( - SourceLocation SLoc) { + SourceLocation SLoc, unsigned CompoundStmtID, + VarDecl *&LocalLockVersionVD) { QualType UInt32Ty = SemaRef.Context.getIntTypeForBitwidth(32, false); // Build VarDecl: uint32_t _local_lock_version = _new_version_number(); + std::string LockVersionVDName = + "_local_lock_version_" + std::to_string(CompoundStmtID); VarDecl *LockVersionVD = VarDecl::Create(SemaRef.Context, FD, SLoc, SLoc, - &SemaRef.Context.Idents.get("_local_lock_version"), - UInt32Ty, nullptr, SC_None); + &SemaRef.Context.Idents.get(LockVersionVDName), UInt32Ty, + nullptr, SC_None); llvm::SmallVector Args; LockVersionVD->setInit(BuildFatPtrCall(SLoc, "_new_version_number", Args)); FD->addDecl(LockVersionVD); @@ -758,8 +839,9 @@ TransformFatPtr::BuildAllocationUnitHeaderForLocalNoArrayVars( LocalLockVersionVD = LockVersionVD; // Build VarDecl: uint32_t _local_size = 0; + std::string SizeVDName = "_local_size_" + std::to_string(CompoundStmtID); VarDecl *SizeVD = VarDecl::Create(SemaRef.Context, FD, SLoc, SLoc, - &SemaRef.Context.Idents.get("_local_size"), + &SemaRef.Context.Idents.get(SizeVDName), UInt32Ty, nullptr, SC_None); SizeVD->setInit(IntegerLiteral::Create(SemaRef.Context, llvm::APInt(32, 0), UInt32Ty, SLoc)); @@ -844,18 +926,36 @@ TransformFatPtr::BuildAllocationUnitForLocalArrayVar(VarDecl *VD) { return std::make_pair(RDDS, NewVDDS); } -// Build assignment expr: _local_lock_version = 0; +// Build assignment expr: _local_lock_version_{block_id} = 0; Expr *TransformFatPtr::BuildLockVersionAssignmentForLocalNoArrayVars( - SourceLocation SLoc) { - if (LocalLockVersionVD) { - QualType VQT = LocalLockVersionVD->getType(); - Expr *LHS = - SemaRef.BuildDeclRefExpr(LocalLockVersionVD, VQT, VK_LValue, SLoc); - Expr *RHS = - IntegerLiteral::Create(SemaRef.Context, llvm::APInt(32, 0), VQT, SLoc); - return SemaRef.CreateBuiltinBinOp(SLoc, BO_Assign, LHS, RHS).get(); - } - return nullptr; + SourceLocation SLoc, VarDecl *LocalLockVersionVD) { + QualType VQT = LocalLockVersionVD->getType(); + Expr *LHS = + SemaRef.BuildDeclRefExpr(LocalLockVersionVD, VQT, VK_LValue, SLoc); + Expr *RHS = + IntegerLiteral::Create(SemaRef.Context, llvm::APInt(32, 0), VQT, SLoc); + return SemaRef.CreateBuiltinBinOp(SLoc, BO_Assign, LHS, RHS).get(); +} + +// Build assignment expr: _arr.lock_version = 0; +Expr * +TransformFatPtr::BuildLockVersionAssignmentForLocalArrayVar(SourceLocation SLoc, + VarDecl *ArrayVar) { + RecordDecl *AllocationUnitRD = + AllocationUnitForLocalArrayVarMap[ArrayVar].first; + VarDecl *AllocationUnitVD = + AllocationUnitForLocalArrayVarMap[ArrayVar].second; + FieldDecl *LockVersionFD = *(AllocationUnitRD->field_begin()); + Expr *AllocationUnitVDRef = SemaRef.BuildDeclRefExpr( + AllocationUnitVD, AllocationUnitVD->getType(), VK_LValue, SLoc); + Expr *LHS = SemaRef.BuildMemberExpr( + AllocationUnitVDRef, false, SLoc, NestedNameSpecifierLoc(), + SourceLocation(), LockVersionFD, + DeclAccessPair::make(AllocationUnitRD, LockVersionFD->getAccess()), false, + DeclarationNameInfo(), LockVersionFD->getType(), VK_LValue, OK_Ordinary); + Expr *RHS = IntegerLiteral::Create(SemaRef.Context, llvm::APInt(32, 0), + LockVersionFD->getType(), SLoc); + return SemaRef.CreateBuiltinBinOp(SLoc, BO_Assign, LHS, RHS).get(); } StmtResult TransformFatPtr::TransformCompoundStmt(CompoundStmt *CS) { @@ -1613,10 +1713,13 @@ ExprResult TransformFatPtr::TransformUnaryOperator(UnaryOperator *UO) { UO, Finder.AddrFatExprAndBaseMap[UO].second); case AddrFatExprBaseKind::LocalNoArrayVar: if (MemberRawPtr) { - MemberRawPtr->setBase(HandleUOAddrFatOnLocalNoArrayVar(UO).get()); + MemberRawPtr->setBase(HandleUOAddrFatOnLocalNoArrayVar( + UO, Finder.AddrFatExprAndBaseMap[UO].second) + .get()); return MemberRawPtr; } - return HandleUOAddrFatOnLocalNoArrayVar(UO); + return HandleUOAddrFatOnLocalNoArrayVar( + UO, Finder.AddrFatExprAndBaseMap[UO].second); case AddrFatExprBaseKind::LocalArrayVar: case AddrFatExprBaseKind::GlobalArrayVar: if (MemberRawPtr) { @@ -1731,16 +1834,19 @@ ExprResult TransformFatPtr::HandleUOAddrFatOnExprWithFatPtrBase( // _FatPtr p = (_FatPtr) { &s.a, _local_lock_version, // (int32_t)((uint8_t *)&s.a - (uint8_t *)&_local_lock_version) - 8 };` // @endcode -ExprResult -TransformFatPtr::HandleUOAddrFatOnLocalNoArrayVar(UnaryOperator *UO) { +ExprResult TransformFatPtr::HandleUOAddrFatOnLocalNoArrayVar(UnaryOperator *UO, + Expr *VarBaseE) { SourceLocation SLoc = UO->getBeginLoc(); QualType QT = UO->getType(); Expr *SubE = BaseTransform::TransformExpr(UO->getSubExpr()).get(); // Build first init expr: &a Expr *FirstInitE = SemaRef.CreateBuiltinUnaryOp(SLoc, UO_AddrOf, SubE).get(); // Build second init expr: _local_version_lock + auto DRE = dyn_cast(VarBaseE); + auto VD = dyn_cast(DRE->getDecl()); Expr *SecondInitE = SemaRef.BuildDeclRefExpr( - LocalLockVersionVD, LocalLockVersionVD->getType(), VK_LValue, SLoc); + LockVersionForLocalNoArrayVarMap[VD], + LockVersionForLocalNoArrayVarMap[VD]->getType(), VK_LValue, SLoc); // Build third init expr: // `(int32_t)((uint8_t *)&a - (uint8_t *)&_local_lock_version) - 8` QualType UInt8PointerTy = SemaRef.Context.getPointerType( diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/use_after_scope1.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/use_after_scope1.cbs new file mode 100644 index 000000000000..9c48e9e5ae65 --- /dev/null +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/use_after_scope1.cbs @@ -0,0 +1,32 @@ +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: not %t-version.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: not %t-version-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output + +#include + +int main() { + int *fat p = nullptr; + { + int b = 20; + p = &fat b; + } + *p = 10; + return 0; +} +// CHECK: Error: Cannot use this pointer because the allocation may have been freed or reseored! +// CHECK-NEXT: Error at: {{[^ ]*}}clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/use_after_scope1.cbs:[[@LINE-4]] in main + +// CHECK_REWRITE: Error: Cannot use this pointer because the allocation may have been freed or reseored! \ No newline at end of file diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/use_after_scope2.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/use_after_scope2.cbs new file mode 100644 index 000000000000..fed8a180fdb9 --- /dev/null +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/use_after_scope2.cbs @@ -0,0 +1,32 @@ +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: not %t-version.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: not %t-version-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output + +#include + +int main(){ + int *fat p; + { + int arr[3]; + p = &fat arr[0]; + } + *p = 10; + return 0; +} +// CHECK: Error: Cannot use this pointer because the allocation may have been freed or reseored! +// CHECK-NEXT: Error at: {{[^ ]*}}clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/use_after_scope2.cbs:[[@LINE-4]] in main + +// CHECK_REWRITE: Error: Cannot use this pointer because the allocation may have been freed or reseored! \ No newline at end of file diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/use_after_scope3.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/use_after_scope3.cbs new file mode 100644 index 000000000000..d0a2c1e027f6 --- /dev/null +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/use_after_scope3.cbs @@ -0,0 +1,34 @@ +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: not %t-version.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: not %t-version-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output + +#include +struct S { + int arr[3]; +}; +int main(){ + int *fat p; + { + struct S s; + p = &fat s.arr[0]; + } + *p = 10; + return 0; +} +// CHECK: Error: Cannot use this pointer because the allocation may have been freed or reseored! +// CHECK-NEXT: Error at: {{[^ ]*}}clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/use_after_scope3.cbs:[[@LINE-4]] in main + +// CHECK_REWRITE: Error: Cannot use this pointer because the allocation may have been freed or reseored! \ No newline at end of file diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/use_after_scope4.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/use_after_scope4.cbs new file mode 100644 index 000000000000..663446452e1e --- /dev/null +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/use_after_scope4.cbs @@ -0,0 +1,34 @@ +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: not %t-version.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: not %t-version-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output + +#include +struct S { + int a; +}; +int main(){ + int *fat p; + { + struct S s; + p = &fat s.a; + } + *p = 10; + return 0; +} +// CHECK: Error: Cannot use this pointer because the allocation may have been freed or reseored! +// CHECK-NEXT: Error at: {{[^ ]*}}clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/use_after_scope4.cbs:[[@LINE-4]] in main + +// CHECK_REWRITE: Error: Cannot use this pointer because the allocation may have been freed or reseored! \ No newline at end of file diff --git a/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/use_after_scope5.cbs b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/use_after_scope5.cbs new file mode 100644 index 000000000000..c61091dc6c9e --- /dev/null +++ b/clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/use_after_scope5.cbs @@ -0,0 +1,33 @@ +// RUN: %clang -fat-ptr-check=both %s -o %t-both.output +// RUN: not %t-both.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=version %s -o %t-version.output +// RUN: not %t-version.output 2>&1 | FileCheck %s +// RUN: %clang -fat-ptr-check=offset %s -o %t-offset.output +// RUN: %clang %s -o %t-none.output +// RUN: %clang %s -fat-ptr-check=both -rewrite-bsc -o %t-both-rw.c +// RUN: %clang %t-both-rw.c -o %t-both-rw.output +// RUN: not %t-both-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=version -rewrite-bsc -o %t-version-rw.c +// RUN: %clang %t-version-rw.c -o %t-version-rw.output +// RUN: not %t-version-rw.output 2>&1 | FileCheck %s --check-prefix=CHECK_REWRITE +// RUN: %clang %s -fat-ptr-check=offset -rewrite-bsc -o %t-offset-rw.c +// RUN: %clang %t-offset-rw.c -o %t-offset-rw.output +// RUN: %clang %s -rewrite-bsc -o %t-none-rw.c +// RUN: %clang %t-none-rw.c -o %t-none-rw.output + +#include + +int main(){ + int a = 10; + int *fat p = &fat a;; + if (*p > 0) { + int b = 20; + p = &fat b; + } + *p = 30; + return 0; +} +// CHECK: Error: Cannot use this pointer because the allocation may have been freed or reseored! +// CHECK-NEXT: Error at: {{[^ ]*}}clang/test/BSC/Negative/FatPtr/version_and_offset_check/stack/use_after_scope5.cbs:[[@LINE-4]] in main + +// CHECK_REWRITE: Error: Cannot use this pointer because the allocation may have been freed or reseored! \ No newline at end of file -- Gitee