[PATCH] D47142: [x86] invpcid intrinsic
craig.topper added inline comments. Comment at: lib/Headers/cpuid.h:158 #define bit_BMI20x0100 +#define bit_INVCPID 0x0400 #define bit_ENH_MOVSB 0x0200 this should be below ENH_MOVSB to keep the bits in order Comment at: lib/Headers/intrin.h:196 + */ void __cdecl _invpcid(unsigned int, void *); +#endif @rnk, what's the right thing to do here? Repository: rC Clang https://reviews.llvm.org/D47142 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D47125: [X86] Remove masking from pternlog llvm intrinsics and use a select instruction instead.
craig.topper added a comment. Because the builtins take one of the arguments as an immediate, they must be implemented as macros. This was the frontend can verify that it's an imediate or a constant expression. Repository: rC Clang https://reviews.llvm.org/D47125 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D43281: [AMDGPU] fixes for lds f32 builtins
This revision was automatically updated to reflect the committed changes. Closed by commit rC332848: [AMDGPU] fixes for lds f32 builtins (authored by dfukalov, committed by ). Changed prior to commit: https://reviews.llvm.org/D43281?vs=142412=147801#toc Repository: rC Clang https://reviews.llvm.org/D43281 Files: include/clang/Basic/BuiltinsAMDGPU.def lib/CodeGen/CGBuiltin.cpp test/CodeGenOpenCL/builtins-amdgcn-vi.cl test/SemaOpenCL/builtins-amdgcn-error.cl Index: lib/CodeGen/CGBuiltin.cpp === --- lib/CodeGen/CGBuiltin.cpp +++ lib/CodeGen/CGBuiltin.cpp @@ -10088,6 +10088,49 @@ CI->setConvergent(); return CI; } + case AMDGPU::BI__builtin_amdgcn_ds_faddf: + case AMDGPU::BI__builtin_amdgcn_ds_fminf: + case AMDGPU::BI__builtin_amdgcn_ds_fmaxf: { +llvm::SmallVector Args; +for (unsigned I = 0; I != 5; ++I) + Args.push_back(EmitScalarExpr(E->getArg(I))); +const llvm::Type *PtrTy = Args[0]->getType(); +// check pointer parameter +if (!PtrTy->isPointerTy() || +E->getArg(0) +->getType() +->getPointeeType() +.getQualifiers() +.getAddressSpace() != LangAS::opencl_local || +!PtrTy->getPointerElementType()->isFloatTy()) { + CGM.Error(E->getArg(0)->getLocStart(), +"parameter should have type \"local float*\""); + return nullptr; +} +// check float parameter +if (!Args[1]->getType()->isFloatTy()) { + CGM.Error(E->getArg(1)->getLocStart(), +"parameter should have type \"float\""); + return nullptr; +} + +Intrinsic::ID ID; +switch (BuiltinID) { +case AMDGPU::BI__builtin_amdgcn_ds_faddf: + ID = Intrinsic::amdgcn_ds_fadd; + break; +case AMDGPU::BI__builtin_amdgcn_ds_fminf: + ID = Intrinsic::amdgcn_ds_fmin; + break; +case AMDGPU::BI__builtin_amdgcn_ds_fmaxf: + ID = Intrinsic::amdgcn_ds_fmax; + break; +default: + llvm_unreachable("Unknown BuiltinID"); +} +Value *F = CGM.getIntrinsic(ID); +return Builder.CreateCall(F, Args); + } // amdgcn workitem case AMDGPU::BI__builtin_amdgcn_workitem_id_x: Index: include/clang/Basic/BuiltinsAMDGPU.def === --- include/clang/Basic/BuiltinsAMDGPU.def +++ include/clang/Basic/BuiltinsAMDGPU.def @@ -93,9 +93,9 @@ BUILTIN(__builtin_amdgcn_readfirstlane, "ii", "nc") BUILTIN(__builtin_amdgcn_readlane, "iii", "nc") BUILTIN(__builtin_amdgcn_fmed3f, "", "nc") -BUILTIN(__builtin_amdgcn_ds_fadd, "ff*3fiib", "n") -BUILTIN(__builtin_amdgcn_ds_fmin, "ff*3fiib", "n") -BUILTIN(__builtin_amdgcn_ds_fmax, "ff*3fiib", "n") +BUILTIN(__builtin_amdgcn_ds_faddf, "ff*fIiIiIb", "n") +BUILTIN(__builtin_amdgcn_ds_fminf, "ff*fIiIiIb", "n") +BUILTIN(__builtin_amdgcn_ds_fmaxf, "ff*fIiIiIb", "n") //===--===// // VI+ only builtins. Index: test/CodeGenOpenCL/builtins-amdgcn-vi.cl === --- test/CodeGenOpenCL/builtins-amdgcn-vi.cl +++ test/CodeGenOpenCL/builtins-amdgcn-vi.cl @@ -91,18 +91,18 @@ // CHECK-LABEL: @test_ds_fadd // CHECK: call float @llvm.amdgcn.ds.fadd(float addrspace(3)* %out, float %src, i32 0, i32 0, i1 false) -void test_ds_fadd(__attribute__((address_space(3))) float *out, float src) { - *out = __builtin_amdgcn_ds_fadd(out, src, 0, 0, false); +void test_ds_faddf(local float *out, float src) { + *out = __builtin_amdgcn_ds_faddf(out, src, 0, 0, false); } // CHECK-LABEL: @test_ds_fmin // CHECK: call float @llvm.amdgcn.ds.fmin(float addrspace(3)* %out, float %src, i32 0, i32 0, i1 false) -void test_ds_fmin(__attribute__((address_space(3))) float *out, float src) { - *out = __builtin_amdgcn_ds_fmin(out, src, 0, 0, false); +void test_ds_fminf(local float *out, float src) { + *out = __builtin_amdgcn_ds_fminf(out, src, 0, 0, false); } // CHECK-LABEL: @test_ds_fmax // CHECK: call float @llvm.amdgcn.ds.fmax(float addrspace(3)* %out, float %src, i32 0, i32 0, i1 false) -void test_ds_fmax(__attribute__((address_space(3))) float *out, float src) { - *out = __builtin_amdgcn_ds_fmax(out, src, 0, 0, false); +void test_ds_fmaxf(local float *out, float src) { + *out = __builtin_amdgcn_ds_fmaxf(out, src, 0, 0, false); } Index: test/SemaOpenCL/builtins-amdgcn-error.cl === --- test/SemaOpenCL/builtins-amdgcn-error.cl +++ test/SemaOpenCL/builtins-amdgcn-error.cl @@ -102,3 +102,20 @@ *out = __builtin_amdgcn_mov_dpp(a, 0, 0, 0, e); // expected-error {{argument to '__builtin_amdgcn_mov_dpp' must be a constant integer}} } +void test_ds_faddf(local float *out, float src, int a) { + *out = __builtin_amdgcn_ds_faddf(out, src, a, 0, false); // expected-error {{argument to '__builtin_amdgcn_ds_faddf' must
[PATCH] D46241: [CodeGen] Recognize more cases of zero initialization
This revision was automatically updated to reflect the committed changes. Closed by commit rC332847: [CodeGen] Recognize more cases of zero initialization (authored by sepavloff, committed by ). Changed prior to commit: https://reviews.llvm.org/D46241?vs=146091=147798#toc Repository: rC Clang https://reviews.llvm.org/D46241 Files: include/clang/AST/Expr.h lib/AST/ExprConstant.cpp lib/CodeGen/CGExprConstant.cpp test/CodeGen/const-init.c test/CodeGen/designated-initializers.c test/CodeGen/union-init2.c test/CodeGenCXX/cxx11-initializer-aggregate.cpp test/CodeGenCXX/cxx1z-initializer-aggregate.cpp test/SemaCXX/large-array-init.cpp Index: lib/CodeGen/CGExprConstant.cpp === --- lib/CodeGen/CGExprConstant.cpp +++ lib/CodeGen/CGExprConstant.cpp @@ -1392,20 +1392,40 @@ return type; } +/// Checks if the specified initializer is equivalent to zero initialization. +static bool isZeroInitializer(ConstantEmitter , const Expr *Init) { + if (auto *E = dyn_cast_or_null(Init)) { +CXXConstructorDecl *CD = E->getConstructor(); +return CD->isDefaultConstructor() && CD->isTrivial(); + } + + if (auto *IL = dyn_cast_or_null(Init)) { +for (auto I : IL->inits()) + if (!isZeroInitializer(CE, I)) +return false; +if (const Expr *Filler = IL->getArrayFiller()) + return isZeroInitializer(CE, Filler); +return true; + } + + QualType InitTy = Init->getType(); + if (InitTy->isIntegralOrEnumerationType() || InitTy->isPointerType()) { +Expr::EvalResult Result; +if (Init->EvaluateAsRValue(Result, CE.CGM.getContext()) && +!Result.hasUnacceptableSideEffect(Expr::SE_NoSideEffects)) + return (Result.Val.isInt() && Result.Val.getInt().isNullValue()) || + (Result.Val.isLValue() && Result.Val.isNullPointer()); + } + + return false; +} + llvm::Constant *ConstantEmitter::tryEmitPrivateForVarInit(const VarDecl ) { // Make a quick check if variable can be default NULL initialized // and avoid going through rest of code which may do, for c++11, // initialization of memory to all NULLs. - if (!D.hasLocalStorage()) { -QualType Ty = CGM.getContext().getBaseElementType(D.getType()); -if (Ty->isRecordType()) - if (const CXXConstructExpr *E = - dyn_cast_or_null(D.getInit())) { -const CXXConstructorDecl *CD = E->getConstructor(); -if (CD->isTrivial() && CD->isDefaultConstructor()) - return CGM.EmitNullConstant(D.getType()); - } - } + if (!D.hasLocalStorage() && isZeroInitializer(*this, D.getInit())) +return CGM.EmitNullConstant(D.getType()); QualType destType = D.getType(); Index: lib/AST/ExprConstant.cpp === --- lib/AST/ExprConstant.cpp +++ lib/AST/ExprConstant.cpp @@ -10312,20 +10312,14 @@ HandleConversionToBool(Scratch.Val, Result); } -static bool hasUnacceptableSideEffect(Expr::EvalStatus , - Expr::SideEffectsKind SEK) { - return (SEK < Expr::SE_AllowSideEffects && Result.HasSideEffects) || - (SEK < Expr::SE_AllowUndefinedBehavior && Result.HasUndefinedBehavior); -} - bool Expr::EvaluateAsInt(APSInt , const ASTContext , SideEffectsKind AllowSideEffects) const { if (!getType()->isIntegralOrEnumerationType()) return false; EvalResult ExprResult; if (!EvaluateAsRValue(ExprResult, Ctx) || !ExprResult.Val.isInt() || - hasUnacceptableSideEffect(ExprResult, AllowSideEffects)) + ExprResult.hasUnacceptableSideEffect(AllowSideEffects)) return false; Result = ExprResult.Val.getInt(); @@ -10339,7 +10333,7 @@ EvalResult ExprResult; if (!EvaluateAsRValue(ExprResult, Ctx) || !ExprResult.Val.isFloat() || - hasUnacceptableSideEffect(ExprResult, AllowSideEffects)) + ExprResult.hasUnacceptableSideEffect(AllowSideEffects)) return false; Result = ExprResult.Val.getFloat(); @@ -10417,7 +10411,7 @@ bool Expr::isEvaluatable(const ASTContext , SideEffectsKind SEK) const { EvalResult Result; return EvaluateAsRValue(Result, Ctx) && - !hasUnacceptableSideEffect(Result, SEK); + !Result.hasUnacceptableSideEffect(SEK); } APSInt Expr::EvaluateKnownConstInt(const ASTContext , Index: include/clang/AST/Expr.h === --- include/clang/AST/Expr.h +++ include/clang/AST/Expr.h @@ -537,6 +537,13 @@ bool isConstantInitializer(ASTContext , bool ForRef, const Expr **Culprit = nullptr) const; + enum SideEffectsKind { +SE_NoSideEffects, ///< Strictly evaluate the expression. +SE_AllowUndefinedBehavior, ///< Allow UB that we can give a value, but not + ///< arbitrary unmodeled side effects. +SE_AllowSideEffects///< Allow any unmodeled side effect. + }; + ///
[PATCH] D47137: [Sparc] Add floating-point register names
jrtc27 added a comment. What about the V9 `dX` and `qX` aliases and `f32` to `f63`? Repository: rC Clang https://reviews.llvm.org/D47137 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r332847 - [CodeGen] Recognize more cases of zero initialization
Author: sepavloff Date: Mon May 21 09:09:54 2018 New Revision: 332847 URL: http://llvm.org/viewvc/llvm-project?rev=332847=rev Log: [CodeGen] Recognize more cases of zero initialization If a variable has an initializer, codegen tries to build its value. If the variable is large in size, building its value requires substantial resources. It causes strange behavior from user viewpoint: compilation of huge zero initialized arrays like: char data_1[2147483648u] = { 0 }; consumes enormous amount of time and memory. With this change codegen tries to determine if variable initializer is equivalent to zero initializer. In this case variable value is not constructed. This change fixes PR18978. Differential Revision: https://reviews.llvm.org/D46241 Removed: cfe/trunk/test/SemaCXX/large-array-init.cpp Modified: cfe/trunk/include/clang/AST/Expr.h cfe/trunk/lib/AST/ExprConstant.cpp cfe/trunk/lib/CodeGen/CGExprConstant.cpp cfe/trunk/test/CodeGen/const-init.c cfe/trunk/test/CodeGen/designated-initializers.c cfe/trunk/test/CodeGen/union-init2.c cfe/trunk/test/CodeGenCXX/cxx11-initializer-aggregate.cpp cfe/trunk/test/CodeGenCXX/cxx1z-initializer-aggregate.cpp Modified: cfe/trunk/include/clang/AST/Expr.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=332847=332846=332847=diff == --- cfe/trunk/include/clang/AST/Expr.h (original) +++ cfe/trunk/include/clang/AST/Expr.h Mon May 21 09:09:54 2018 @@ -537,6 +537,13 @@ public: bool isConstantInitializer(ASTContext , bool ForRef, const Expr **Culprit = nullptr) const; + enum SideEffectsKind { +SE_NoSideEffects, ///< Strictly evaluate the expression. +SE_AllowUndefinedBehavior, ///< Allow UB that we can give a value, but not + ///< arbitrary unmodeled side effects. +SE_AllowSideEffects///< Allow any unmodeled side effect. + }; + /// EvalStatus is a struct with detailed info about an evaluation in progress. struct EvalStatus { /// Whether the evaluated expression has side effects. @@ -565,6 +572,11 @@ public: bool hasSideEffects() const { return HasSideEffects; } + +bool hasUnacceptableSideEffect(SideEffectsKind SEK) { + return (SEK < SE_AllowSideEffects && HasSideEffects) || + (SEK < SE_AllowUndefinedBehavior && HasUndefinedBehavior); +} }; /// EvalResult is a struct with detailed info about an evaluated expression. @@ -591,13 +603,6 @@ public: /// side-effects. bool EvaluateAsBooleanCondition(bool , const ASTContext ) const; - enum SideEffectsKind { -SE_NoSideEffects, ///< Strictly evaluate the expression. -SE_AllowUndefinedBehavior, ///< Allow UB that we can give a value, but not - ///< arbitrary unmodeled side effects. -SE_AllowSideEffects///< Allow any unmodeled side effect. - }; - /// EvaluateAsInt - Return true if this is a constant which we can fold and /// convert to an integer, using any crazy technique that we want to. bool EvaluateAsInt(llvm::APSInt , const ASTContext , Modified: cfe/trunk/lib/AST/ExprConstant.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=332847=332846=332847=diff == --- cfe/trunk/lib/AST/ExprConstant.cpp (original) +++ cfe/trunk/lib/AST/ExprConstant.cpp Mon May 21 09:09:54 2018 @@ -10312,12 +10312,6 @@ bool Expr::EvaluateAsBooleanCondition(bo HandleConversionToBool(Scratch.Val, Result); } -static bool hasUnacceptableSideEffect(Expr::EvalStatus , - Expr::SideEffectsKind SEK) { - return (SEK < Expr::SE_AllowSideEffects && Result.HasSideEffects) || - (SEK < Expr::SE_AllowUndefinedBehavior && Result.HasUndefinedBehavior); -} - bool Expr::EvaluateAsInt(APSInt , const ASTContext , SideEffectsKind AllowSideEffects) const { if (!getType()->isIntegralOrEnumerationType()) @@ -10325,7 +10319,7 @@ bool Expr::EvaluateAsInt(APSInt , EvalResult ExprResult; if (!EvaluateAsRValue(ExprResult, Ctx) || !ExprResult.Val.isInt() || - hasUnacceptableSideEffect(ExprResult, AllowSideEffects)) + ExprResult.hasUnacceptableSideEffect(AllowSideEffects)) return false; Result = ExprResult.Val.getInt(); @@ -10339,7 +10333,7 @@ bool Expr::EvaluateAsFloat(APFloat EvalResult ExprResult; if (!EvaluateAsRValue(ExprResult, Ctx) || !ExprResult.Val.isFloat() || - hasUnacceptableSideEffect(ExprResult, AllowSideEffects)) + ExprResult.hasUnacceptableSideEffect(AllowSideEffects)) return false; Result = ExprResult.Val.getFloat(); @@ -10417,7 +10411,7 @@ bool Expr::EvaluateAsInitializer(APValue bool Expr::isEvaluatable(const ASTContext , SideEffectsKind
[PATCH] D47138: [Sparc] Use the leon arch for Leon3's when using an external assembler
jyknight added a comment. There are more leon-based v8 CPUs listed in clang/lib/Basic/Targets/Sparc.cpp, which need to be listed here, also. Separately, I think it'd be a good idea to refactor to put this info into the SparcCPUInfo struct, so that it's harder for them to get out of sync. Repository: rC Clang https://reviews.llvm.org/D47138 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D47142: [x86] invpcid intrinsic
GBuella created this revision. GBuella added a reviewer: craig.topper. Herald added subscribers: cfe-commits, mgorny. An intrinsic for an old instruction, as described in the Intel SDM. Repository: rC Clang https://reviews.llvm.org/D47142 Files: include/clang/Basic/BuiltinsX86.def include/clang/Driver/Options.td lib/Basic/Targets/X86.cpp lib/Basic/Targets/X86.h lib/Headers/CMakeLists.txt lib/Headers/cpuid.h lib/Headers/intrin.h lib/Headers/invpcidintrin.h lib/Headers/module.modulemap lib/Headers/x86intrin.h test/CodeGen/invpcid.c test/Driver/x86-target-features.c test/Preprocessor/predefined-arch-macros.c Index: test/Preprocessor/predefined-arch-macros.c === --- test/Preprocessor/predefined-arch-macros.c +++ test/Preprocessor/predefined-arch-macros.c @@ -526,6 +526,7 @@ // CHECK_CORE_AVX2_M32: #define __BMI__ 1 // CHECK_CORE_AVX2_M32: #define __F16C__ 1 // CHECK_CORE_AVX2_M32: #define __FMA__ 1 +// CHECK_CORE_AVX2_M32: #define __INVPCID__ 1 // CHECK_CORE_AVX2_M32: #define __LZCNT__ 1 // CHECK_CORE_AVX2_M32: #define __MMX__ 1 // CHECK_CORE_AVX2_M32: #define __PCLMUL__ 1 @@ -556,6 +557,7 @@ // CHECK_CORE_AVX2_M64: #define __BMI__ 1 // CHECK_CORE_AVX2_M64: #define __F16C__ 1 // CHECK_CORE_AVX2_M64: #define __FMA__ 1 +// CHECK_CORE_AVX2_M64: #define __INVPCID__ 1 // CHECK_CORE_AVX2_M64: #define __LZCNT__ 1 // CHECK_CORE_AVX2_M64: #define __MMX__ 1 // CHECK_CORE_AVX2_M64: #define __PCLMUL__ 1 @@ -590,6 +592,7 @@ // CHECK_BROADWELL_M32: #define __BMI__ 1 // CHECK_BROADWELL_M32: #define __F16C__ 1 // CHECK_BROADWELL_M32: #define __FMA__ 1 +// CHECK_BROADWELL_M32: #define __INVPCID__ 1 // CHECK_BROADWELL_M32: #define __LZCNT__ 1 // CHECK_BROADWELL_M32: #define __MMX__ 1 // CHECK_BROADWELL_M32: #define __PCLMUL__ 1 @@ -623,6 +626,7 @@ // CHECK_BROADWELL_M64: #define __BMI__ 1 // CHECK_BROADWELL_M64: #define __F16C__ 1 // CHECK_BROADWELL_M64: #define __FMA__ 1 +// CHECK_BROADWELL_M64: #define __INVPCID__ 1 // CHECK_BROADWELL_M64: #define __LZCNT__ 1 // CHECK_BROADWELL_M64: #define __MMX__ 1 // CHECK_BROADWELL_M64: #define __PCLMUL__ 1 @@ -660,6 +664,7 @@ // CHECK_SKL_M32: #define __CLFLUSHOPT__ 1 // CHECK_SKL_M32: #define __F16C__ 1 // CHECK_SKL_M32: #define __FMA__ 1 +// CHECK_SKL_M32: #define __INVPCID__ 1 // CHECK_SKL_M32: #define __LZCNT__ 1 // CHECK_SKL_M32: #define __MMX__ 1 // CHECK_SKL_M32: #define __MPX__ 1 @@ -694,6 +699,7 @@ // CHECK_SKL_M64: #define __CLFLUSHOPT__ 1 // CHECK_SKL_M64: #define __F16C__ 1 // CHECK_SKL_M64: #define __FMA__ 1 +// CHECK_SKL_M64: #define __INVPCID__ 1 // CHECK_SKL_M64: #define __LZCNT__ 1 // CHECK_SKL_M64: #define __MMX__ 1 // CHECK_SKL_M64: #define __MPX__ 1 @@ -888,6 +894,7 @@ // CHECK_SKX_M32: #define __CLWB__ 1 // CHECK_SKX_M32: #define __F16C__ 1 // CHECK_SKX_M32: #define __FMA__ 1 +// CHECK_SKX_M32: #define __INVPCID__ 1 // CHECK_SKX_M32: #define __LZCNT__ 1 // CHECK_SKX_M32: #define __MMX__ 1 // CHECK_SKX_M32: #define __MPX__ 1 @@ -933,6 +940,7 @@ // CHECK_SKX_M64: #define __CLWB__ 1 // CHECK_SKX_M64: #define __F16C__ 1 // CHECK_SKX_M64: #define __FMA__ 1 +// CHECK_SKX_M64: #define __INVPCID__ 1 // CHECK_SKX_M64: #define __LZCNT__ 1 // CHECK_SKX_M64: #define __MMX__ 1 // CHECK_SKX_M64: #define __MPX__ 1 @@ -983,6 +991,7 @@ // CHECK_CNL_M32-NOT: #define __CLWB__ 1 // CHECK_CNL_M32: #define __F16C__ 1 // CHECK_CNL_M32: #define __FMA__ 1 +// CHECK_CNL_M32: #define __INVPCID__ 1 // CHECK_CNL_M32: #define __LZCNT__ 1 // CHECK_CNL_M32: #define __MMX__ 1 // CHECK_CNL_M32: #define __MPX__ 1 @@ -1031,6 +1040,7 @@ // CHECK_CNL_M64-NOT: #define __CLWB__ 1 // CHECK_CNL_M64: #define __F16C__ 1 // CHECK_CNL_M64: #define __FMA__ 1 +// CHECK_CNL_M64: #define __INVPCID__ 1 // CHECK_CNL_M64: #define __LZCNT__ 1 // CHECK_CNL_M64: #define __MMX__ 1 // CHECK_CNL_M64: #define __MPX__ 1 @@ -1085,6 +1095,7 @@ // CHECK_ICL_M32: #define __F16C__ 1 // CHECK_ICL_M32: #define __FMA__ 1 // CHECK_ICL_M32: #define __GFNI__ 1 +// CHECK_ICL_M32: #define __INVPCID__ 1 // CHECK_ICL_M32: #define __LZCNT__ 1 // CHECK_ICL_M32: #define __MMX__ 1 // CHECK_ICL_M32: #define __MPX__ 1 @@ -1142,6 +1153,7 @@ // CHECK_ICL_M64: #define __F16C__ 1 // CHECK_ICL_M64: #define __FMA__ 1 // CHECK_ICL_M64: #define __GFNI__ 1 +// CHECK_ICL_M64: #define __INVPCID__ 1 // CHECK_ICL_M64: #define __LZCNT__ 1 // CHECK_ICL_M64: #define __MMX__ 1 // CHECK_ICL_M64: #define __MPX__ 1 @@ -1200,6 +1212,7 @@ // CHECK_ICX_M32: #define __F16C__ 1 // CHECK_ICX_M32: #define __FMA__ 1 // CHECK_ICX_M32: #define __GFNI__ 1 +// CHECK_ICX_M32: #define __INVPCID__ 1 // CHECK_ICX_M32: #define __LZCNT__ 1 // CHECK_ICX_M32: #define __MMX__ 1 // CHECK_ICX_M32: #define __MPX__ 1 @@ -1258,6 +1271,7 @@ // CHECK_ICX_M64: #define __F16C__ 1 // CHECK_ICX_M64: #define __FMA__ 1 // CHECK_ICX_M64: #define __GFNI__ 1 +// CHECK_ICX_M64: #define __INVPCID__ 1 // CHECK_ICX_M64: #define
[PATCH] D45783: [DEBUGINFO, NVPTX] Render `-no-cuda-debug` LLVM option when required.
ABataev added a comment. In https://reviews.llvm.org/D45783#1106019, @echristo wrote: > So, I'd really prefer not to set options via the backend option path. From > here I think we should aim to take all of the options we added and having the > asm printer in the backend know how to set them depending on the target. We > could also add things to the IR metadata if necessary, but I'd like to avoid > that if possible. > > Thoughts? This patch is outdated a bit, I have a patch https://reviews.llvm.org/D46061 that does it in a different way, via `MCOption` Repository: rC Clang https://reviews.llvm.org/D45783 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D47122: [clang-tidy] SimplifyBoolenExpr doesn't add parens if unary negotiation is of ExprWithCleanups type
aaron.ballman accepted this revision. aaron.ballman added a comment. This revision is now accepted and ready to land. LGTM, with a small nit. Comment at: clang-tidy/readability/SimplifyBooleanExprCheck.cpp:78 E = E->IgnoreImpCasts(); + if (auto *EC = dyn_cast(E)) +E = EC->getSubExpr(); `const auto *`, please. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D47122 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D47137: [Sparc] Add floating-point register names
jyknight added a comment. Can you add a test that we support this? clang/test/CodeGen/sparcv8-inline-asm.c would be a good place to add a test case similar to that in clang/test/CodeGen/aarch64-inline-asm.c : test_gcc_registers. Repository: rC Clang https://reviews.llvm.org/D47137 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46439: [Sema] Fix incorrect packed aligned structure layout
This revision was automatically updated to reflect the committed changes. Closed by commit rC332843: [Sema] Fix incorrect packed aligned structure layout (authored by chill, committed by ). Changed prior to commit: https://reviews.llvm.org/D46439?vs=145687=147781#toc Repository: rC Clang https://reviews.llvm.org/D46439 Files: lib/Sema/SemaDecl.cpp test/Layout/itanium-pack-and-align.cpp Index: test/Layout/itanium-pack-and-align.cpp === --- test/Layout/itanium-pack-and-align.cpp +++ test/Layout/itanium-pack-and-align.cpp @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm-only -fdump-record-layouts %s \ +// RUN:| FileCheck %s + +struct S { + char x; + int y; +} __attribute__((packed, aligned(8))); + +struct alignas(8) T { + char x; + int y; +} __attribute__((packed)); + +S s; +T t; +// CHECK: 0 | struct T +// CHECK-NEXT: 0 | char x +// CHECK-NEXT: 1 | int y +// CHECK-NEXT:| [sizeof=8, dsize=8, align=8, +// CHECK-NEXT:| nvsize=8, nvalign=8] + +// CHECK: 0 | struct S +// CHECK-NEXT: 0 | char x +// CHECK-NEXT: 1 | int y +// CHECK-NEXT:| [sizeof=8, dsize=8, align=8, +// CHECK-NETX:| nvsize=8, nvalign=8] Index: lib/Sema/SemaDecl.cpp === --- lib/Sema/SemaDecl.cpp +++ lib/Sema/SemaDecl.cpp @@ -15594,6 +15594,10 @@ if (!Completed) Record->completeDefinition(); +// Handle attributes before checking the layout. +if (Attr) + ProcessDeclAttributeList(S, Record, Attr); + // We may have deferred checking for a deleted destructor. Check now. if (CXXRecordDecl *CXXRecord = dyn_cast(Record)) { auto *Dtor = CXXRecord->getDestructor(); @@ -15724,9 +15728,6 @@ CDecl->setIvarRBraceLoc(RBrac); } } - - if (Attr) -ProcessDeclAttributeList(S, Record, Attr); } /// Determine whether the given integral value is representable within Index: test/Layout/itanium-pack-and-align.cpp === --- test/Layout/itanium-pack-and-align.cpp +++ test/Layout/itanium-pack-and-align.cpp @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm-only -fdump-record-layouts %s \ +// RUN:| FileCheck %s + +struct S { + char x; + int y; +} __attribute__((packed, aligned(8))); + +struct alignas(8) T { + char x; + int y; +} __attribute__((packed)); + +S s; +T t; +// CHECK: 0 | struct T +// CHECK-NEXT: 0 | char x +// CHECK-NEXT: 1 | int y +// CHECK-NEXT:| [sizeof=8, dsize=8, align=8, +// CHECK-NEXT:| nvsize=8, nvalign=8] + +// CHECK: 0 | struct S +// CHECK-NEXT: 0 | char x +// CHECK-NEXT: 1 | int y +// CHECK-NEXT:| [sizeof=8, dsize=8, align=8, +// CHECK-NETX:| nvsize=8, nvalign=8] Index: lib/Sema/SemaDecl.cpp === --- lib/Sema/SemaDecl.cpp +++ lib/Sema/SemaDecl.cpp @@ -15594,6 +15594,10 @@ if (!Completed) Record->completeDefinition(); +// Handle attributes before checking the layout. +if (Attr) + ProcessDeclAttributeList(S, Record, Attr); + // We may have deferred checking for a deleted destructor. Check now. if (CXXRecordDecl *CXXRecord = dyn_cast(Record)) { auto *Dtor = CXXRecord->getDestructor(); @@ -15724,9 +15728,6 @@ CDecl->setIvarRBraceLoc(RBrac); } } - - if (Attr) -ProcessDeclAttributeList(S, Record, Attr); } /// Determine whether the given integral value is representable within ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r332843 - [Sema] Fix incorrect packed aligned structure layout
Author: chill Date: Mon May 21 07:28:43 2018 New Revision: 332843 URL: http://llvm.org/viewvc/llvm-project?rev=332843=rev Log: [Sema] Fix incorrect packed aligned structure layout Handle attributes before checking the record layout (e.g. underalignment check during `alignas` processing), as layout may be cached without taking into account attributes that may affect it. Differential Revision: https://reviews.llvm.org/D46439 Added: cfe/trunk/test/Layout/itanium-pack-and-align.cpp Modified: cfe/trunk/lib/Sema/SemaDecl.cpp Modified: cfe/trunk/lib/Sema/SemaDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=332843=332842=332843=diff == --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon May 21 07:28:43 2018 @@ -15594,6 +15594,10 @@ void Sema::ActOnFields(Scope *S, SourceL if (!Completed) Record->completeDefinition(); +// Handle attributes before checking the layout. +if (Attr) + ProcessDeclAttributeList(S, Record, Attr); + // We may have deferred checking for a deleted destructor. Check now. if (CXXRecordDecl *CXXRecord = dyn_cast(Record)) { auto *Dtor = CXXRecord->getDestructor(); @@ -15724,9 +15728,6 @@ void Sema::ActOnFields(Scope *S, SourceL CDecl->setIvarRBraceLoc(RBrac); } } - - if (Attr) -ProcessDeclAttributeList(S, Record, Attr); } /// Determine whether the given integral value is representable within Added: cfe/trunk/test/Layout/itanium-pack-and-align.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Layout/itanium-pack-and-align.cpp?rev=332843=auto == --- cfe/trunk/test/Layout/itanium-pack-and-align.cpp (added) +++ cfe/trunk/test/Layout/itanium-pack-and-align.cpp Mon May 21 07:28:43 2018 @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm-only -fdump-record-layouts %s \ +// RUN:| FileCheck %s + +struct S { + char x; + int y; +} __attribute__((packed, aligned(8))); + +struct alignas(8) T { + char x; + int y; +} __attribute__((packed)); + +S s; +T t; +// CHECK: 0 | struct T +// CHECK-NEXT: 0 | char x +// CHECK-NEXT: 1 | int y +// CHECK-NEXT:| [sizeof=8, dsize=8, align=8, +// CHECK-NEXT:| nvsize=8, nvalign=8] + +// CHECK: 0 | struct S +// CHECK-NEXT: 0 | char x +// CHECK-NEXT: 1 | int y +// CHECK-NEXT:| [sizeof=8, dsize=8, align=8, +// CHECK-NETX:| nvsize=8, nvalign=8] ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46439: [Sema] Fix incorrect packed aligned structure layout
chill added a comment. Thanks a lot! https://reviews.llvm.org/D46439 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D44539: [Sema][Objective-C] Add check to warn when property of objc type has assign attribute
QF5690 added inline comments. Comment at: include/clang/Basic/DiagnosticSemaKinds.td:1018 +def warn_objc_property_assign_on_object : Warning< + "'assign' attribute must not be of object type, use 'unsafe_unretained' instead">, + InGroup, DefaultIgnore; rjmccall wrote: > "must" is rather strong for a warning. Maybe something more like "'assign' > attribute on property of object type could be 'unsafe_unretained'"? But "could be" is rather weak :) May be "Prefer using explicit 'unsafe_unretained' attribute instead of 'assign' for object types", or "Using explicit 'unsafe_unretained' attribute instead of 'assign' for object types is preferred" (if passive voice is preferred) Repository: rC Clang https://reviews.llvm.org/D44539 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D45835: Add new driver mode for dumping compiler options
aaron.ballman added a comment. Ping. https://reviews.llvm.org/D45835 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D44539: [Sema][Objective-C] Add check to warn when property of objc type has assign attribute
aaron.ballman added a comment. In https://reviews.llvm.org/D44539#1106152, @rjmccall wrote: > This was approved by the Objective-C language group as a default-off warning. We usually do not expose new default-off warnings because experience shows that they rarely ever get enabled by users. If the ObjC group doesn't think this should be on by default, I wonder if it should be included in Clang at all. Repository: rC Clang https://reviews.llvm.org/D44539 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D47138: [Sparc] Use the leon arch for Leon3's when using an external assembler
dcederman created this revision. dcederman added a reviewer: jyknight. Herald added subscribers: cfe-commits, jrtc27, fedor.sergeev. This allows the use of the casa instruction available in most Leon3's. Repository: rC Clang https://reviews.llvm.org/D47138 Files: lib/Driver/ToolChains/Arch/Sparc.cpp Index: lib/Driver/ToolChains/Arch/Sparc.cpp === --- lib/Driver/ToolChains/Arch/Sparc.cpp +++ lib/Driver/ToolChains/Arch/Sparc.cpp @@ -48,11 +48,11 @@ .Case("leon2", "-Av8") .Case("at697e", "-Av8") .Case("at697f", "-Av8") -.Case("leon3", "-Av8") +.Case("leon3", "-Aleon") .Case("ut699", "-Av8") -.Case("gr712rc", "-Av8") -.Case("leon4", "-Av8") -.Case("gr740", "-Av8") +.Case("gr712rc", "-Aleon") +.Case("leon4", "-Aleon") +.Case("gr740", "-Aleon") .Default("-Av8"); } } Index: lib/Driver/ToolChains/Arch/Sparc.cpp === --- lib/Driver/ToolChains/Arch/Sparc.cpp +++ lib/Driver/ToolChains/Arch/Sparc.cpp @@ -48,11 +48,11 @@ .Case("leon2", "-Av8") .Case("at697e", "-Av8") .Case("at697f", "-Av8") -.Case("leon3", "-Av8") +.Case("leon3", "-Aleon") .Case("ut699", "-Av8") -.Case("gr712rc", "-Av8") -.Case("leon4", "-Av8") -.Case("gr740", "-Av8") +.Case("gr712rc", "-Aleon") +.Case("leon4", "-Aleon") +.Case("gr740", "-Aleon") .Default("-Av8"); } } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D47137: [Sparc] Add floating-point register names
dcederman created this revision. dcederman added a reviewer: jyknight. Herald added subscribers: cfe-commits, jrtc27, fedor.sergeev. Repository: rC Clang https://reviews.llvm.org/D47137 Files: lib/Basic/Targets/Sparc.cpp Index: lib/Basic/Targets/Sparc.cpp === --- lib/Basic/Targets/Sparc.cpp +++ lib/Basic/Targets/Sparc.cpp @@ -22,7 +22,10 @@ const char *const SparcTargetInfo::GCCRegNames[] = { "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", "r16", "r17", "r18", "r19", "r20", "r21", -"r22", "r23", "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31" +"r22", "r23", "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31", +"f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", +"f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18", "f19", "f20", "f21", +"f22", "f23", "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31" }; ArrayRef SparcTargetInfo::getGCCRegNames() const { Index: lib/Basic/Targets/Sparc.cpp === --- lib/Basic/Targets/Sparc.cpp +++ lib/Basic/Targets/Sparc.cpp @@ -22,7 +22,10 @@ const char *const SparcTargetInfo::GCCRegNames[] = { "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", "r16", "r17", "r18", "r19", "r20", "r21", -"r22", "r23", "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31" +"r22", "r23", "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31", +"f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", +"f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18", "f19", "f20", "f21", +"f22", "f23", "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31" }; ArrayRef SparcTargetInfo::getGCCRegNames() const { ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46472: [HIP] Support offloading by linker script
yaxunl added inline comments. Comment at: cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp:1371-1388 + // machines. + LksStream << "/*\n"; + LksStream << " HIP Offload Linker Script\n"; + LksStream << " *** Automatically generated by Clang ***\n"; + LksStream << "*/\n"; + LksStream << "TARGET(binary)\n"; + LksStream << "INPUT(" << BundleFileName << ")\n"; pcc wrote: > tra wrote: > > Using this linker script may present a problem. > > > > INSERT BEFORE is not going to work with ld.gold. > > https://sourceware.org/bugzilla/show_bug.cgi?id=15373 > > > > LLD also does not handle it particularly well -- INSERT BEFORE can only be > > used to override explicitly specified external linker script and virtually > > nobody uses linker scripts with LLD. > > See tests in https://reviews.llvm.org/D44380 > > > If you're just trying to embed a file it may be better to use MC to write an > ELF with something like: > ``` > .section .hip_fatbin > .align 16 > .globl __hip_fatbin > __hip_fatbin: > .incbin "BundleFileName" > ``` > and add that to the link. In https://reviews.llvm.org/D45212 we specified to use lld for linking. Since this is an explicit linker script, it works. We have tested this approach with many HIP applications that it works well. Similar approach has also been used by OpenMP for embedding device binary. Comment at: cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp:1371-1388 + // machines. + LksStream << "/*\n"; + LksStream << " HIP Offload Linker Script\n"; + LksStream << " *** Automatically generated by Clang ***\n"; + LksStream << "*/\n"; + LksStream << "TARGET(binary)\n"; + LksStream << "INPUT(" << BundleFileName << ")\n"; yaxunl wrote: > pcc wrote: > > tra wrote: > > > Using this linker script may present a problem. > > > > > > INSERT BEFORE is not going to work with ld.gold. > > > https://sourceware.org/bugzilla/show_bug.cgi?id=15373 > > > > > > LLD also does not handle it particularly well -- INSERT BEFORE can only > > > be used to override explicitly specified external linker script and > > > virtually nobody uses linker scripts with LLD. > > > See tests in https://reviews.llvm.org/D44380 > > > > > If you're just trying to embed a file it may be better to use MC to write > > an ELF with something like: > > ``` > > .section .hip_fatbin > > .align 16 > > .globl __hip_fatbin > > __hip_fatbin: > > .incbin "BundleFileName" > > ``` > > and add that to the link. > In https://reviews.llvm.org/D45212 we specified to use lld for linking. Since > this is an explicit linker script, it works. We have tested this approach > with many HIP applications that it works well. > > Similar approach has also been used by OpenMP for embedding device binary. Thanks for your suggestion. We will consider using MC if we see issues arise due to linker script. Repository: rL LLVM https://reviews.llvm.org/D46472 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D47135: [analyzer][WIP] A checker for dangling string pointers in C++
MTC added inline comments. Comment at: lib/StaticAnalyzer/Checkers/DanglingStringPointerChecker.cpp:59 + QualType RegType = TypedR->getValueType(); + if (RegType.getAsString() != "std::string") +return; A little tip, there are other string types besides `std::string`, like `std::wstring`, which can be added in the future. See [[ http://en.cppreference.com/w/cpp/string/basic_string | basic_string ]]. Comment at: lib/StaticAnalyzer/Checkers/DanglingStringPointerChecker.cpp:71 + + if (dyn_cast(ICall)) { +if (State->contains(TypedR)) { `CXXDestructorCall::classof(const CallEvent *CA)` can also be used here. Comment at: lib/StaticAnalyzer/Checkers/MallocChecker.cpp:3002 + // FIXME: This might not be the best allocation family for this purpose. + AllocationFamily Family = AF_CXXNew; + return State->set(Sym, RefState::getReleased(Family, Origin)); In addition to `std::string`, `std::vector::data()` in C++11 and `std::string_view` in C++17 may have similar problems. If these are all supported, a new `AllocationFamily` may be needed, like `AF_StdLibContainers` or something like that. Comment at: lib/StaticAnalyzer/Checkers/RegionState.h:18 + +namespace region_state { + I'm not sure whether `region_state` follows the naming conventions of LLVM coding standards. Can someone answer this question? Repository: rC Clang https://reviews.llvm.org/D47135 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46541: [CodeGen] Improve diagnostics related to target attributes
GBuella updated this revision to Diff 147775. GBuella added a comment. Fixed a horrible bug in the patch. Adding a ref to temporary string is not a wise thing to do, so I had to remove this line: ReqFeatures.push_back(F.substr(1)); Now the ReqFeatures vector can also refer to strings starting with '+' Also, added a few tests and comments. https://reviews.llvm.org/D46541 Files: lib/CodeGen/CodeGenFunction.cpp lib/CodeGen/CodeGenModule.cpp lib/CodeGen/CodeGenModule.h test/CodeGen/target-features-error-2.c test/CodeGen/target-features-error.c Index: test/CodeGen/target-features-error.c === --- test/CodeGen/target-features-error.c +++ test/CodeGen/target-features-error.c @@ -3,6 +3,5 @@ return a + 4; } int bar() { - return foo(4); // expected-error {{always_inline function 'foo' requires target feature 'sse4.2', but would be inlined into function 'bar' that is compiled without support for 'sse4.2'}} + return foo(4); // expected-error {{always_inline function 'foo' requires target feature 'avx', but would be inlined into function 'bar' that is compiled without support for 'avx'}} } - Index: test/CodeGen/target-features-error-2.c === --- test/CodeGen/target-features-error-2.c +++ test/CodeGen/target-features-error-2.c @@ -1,38 +1,67 @@ -// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -S -verify -o - -D NEED_SSE42 // RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -S -verify -o - -D NEED_AVX_1 // RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -S -verify -o - -D NEED_AVX_2 // RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -S -verify -o - -D NEED_AVX_3 // RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -S -verify -o - -D NEED_AVX_4 +// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -S -verify -o - -D NEED_AVX_5 +// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -S -verify -o - -D NEED_AVX512f +// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -target-feature +movdir64b -S -verify -o - -D NEED_MOVDIRI +// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -target-feature +avx512vnni -target-feature +movdiri -S -verify -o - -D NEED_CLWB #define __MM_MALLOC_H #include -#if NEED_SSE42 +#if NEED_AVX_1 int baz(__m256i a) { - return _mm256_extract_epi32(a, 3); // expected-error {{always_inline function '_mm256_extract_epi32' requires target feature 'sse4.2', but would be inlined into function 'baz' that is compiled without support for 'sse4.2'}} + return _mm256_extract_epi32(a, 3); // expected-error {{always_inline function '_mm256_extract_epi32' requires target feature 'avx', but would be inlined into function 'baz' that is compiled without support for 'avx'}} } #endif -#if NEED_AVX_1 +#if NEED_AVX_2 __m128 need_avx(__m128 a, __m128 b) { return _mm_cmp_ps(a, b, 0); // expected-error {{'__builtin_ia32_cmpps' needs target feature avx}} } #endif -#if NEED_AVX_2 +#if NEED_AVX_3 __m128 need_avx(__m128 a, __m128 b) { return _mm_cmp_ss(a, b, 0); // expected-error {{'__builtin_ia32_cmpss' needs target feature avx}} } #endif -#if NEED_AVX_3 +#if NEED_AVX_4 __m128d need_avx(__m128d a, __m128d b) { return _mm_cmp_pd(a, b, 0); // expected-error {{'__builtin_ia32_cmppd' needs target feature avx}} } #endif -#if NEED_AVX_4 +#if NEED_AVX_5 __m128d need_avx(__m128d a, __m128d b) { return _mm_cmp_sd(a, b, 0); // expected-error {{'__builtin_ia32_cmpsd' needs target feature avx}} } #endif + +#if NEED_AVX512f +unsigned short need_avx512f(unsigned short a, unsigned short b) { + return __builtin_ia32_korhi(a, b); // expected-error {{'__builtin_ia32_korhi' needs target feature avx512f}} +} +#endif + +#if NEED_MOVDIRI +void need_movdiri(unsigned int *a, unsigned int b) { + __builtin_ia32_directstore_u32(a, b); // expected-error {{'__builtin_ia32_directstore_u32' needs target feature movdiri}} +} +#endif + +#if NEED_CLWB +static __inline__ void + __attribute__((__always_inline__, __nodebug__, __target__("avx512vnni,clwb,movdiri,movdir64b"))) + func(unsigned int *a, unsigned int b) +{ + __builtin_ia32_directstore_u32(a, b); +} + +void need_clwb(unsigned int *a, unsigned int b) { + func(a, b); // expected-error {{always_inline function 'func' requires target feature 'clwb', but would be inlined into function 'need_clwb' that is compiled without support for 'clwb'}} + +} +#endif Index: lib/CodeGen/CodeGenModule.h === --- lib/CodeGen/CodeGenModule.h +++ lib/CodeGen/CodeGenModule.h @@ -1089,6 +1089,10 @@ /// It's up to you to ensure that this is safe. void AddDefaultFnAttrs(llvm::Function ); + /// Parses the target attributes passed in, and returns only the ones that are + /// valid feature names. + TargetAttr::ParsedTargetAttr filterFunctionTargetAttrs(const TargetAttr *TD); + // Fills in the supplied string map with the set of target features for the // passed in function. void
[PATCH] D46805: If some platforms do not support an attribute, we should exclude the platform
HLJ2009 updated this revision to Diff 147773. HLJ2009 added a comment. Herald added a subscriber: aheejin. listing the object formats that *do* support aliases seems reasonable Repository: rC Clang https://reviews.llvm.org/D46805 Files: include/clang/Basic/Attr.td test/Sema/attr-alias-has.c Index: test/Sema/attr-alias-has.c === --- /dev/null +++ test/Sema/attr-alias-has.c @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple i686-unknown-windows-msvc -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple wasm32-unknown-unknown -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple wasm64-unknown-unknown -fsyntax-only -verify %s + +#if __has_attribute(alias) + +void g() {} + +void f() __attribute__((alias("g"))); //expected-no-diagnostics + +#else + +//expected-no-diagnostics + +#endif Index: include/clang/Basic/Attr.td === --- include/clang/Basic/Attr.td +++ include/clang/Basic/Attr.td @@ -318,6 +318,9 @@ def TargetELF : TargetSpec { let ObjectFormats = ["ELF"]; } +def TargetSupportsAlias : TargetSpec { + let ObjectFormats = ["COFF", "ELF", "Wasm"]; +} // Attribute subject match rules that are used for #pragma clang attribute. // @@ -554,7 +557,7 @@ let Documentation = [Undocumented]; } -def Alias : Attr { +def Alias : Attr, TargetSpecificAttr { let Spellings = [GCC<"alias">]; let Args = [StringArgument<"Aliasee">]; let Subjects = SubjectList<[Function, GlobalVar], ErrorDiag>; Index: test/Sema/attr-alias-has.c === --- /dev/null +++ test/Sema/attr-alias-has.c @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple i686-unknown-windows-msvc -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple wasm32-unknown-unknown -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple wasm64-unknown-unknown -fsyntax-only -verify %s + +#if __has_attribute(alias) + +void g() {} + +void f() __attribute__((alias("g"))); //expected-no-diagnostics + +#else + +//expected-no-diagnostics + +#endif Index: include/clang/Basic/Attr.td === --- include/clang/Basic/Attr.td +++ include/clang/Basic/Attr.td @@ -318,6 +318,9 @@ def TargetELF : TargetSpec { let ObjectFormats = ["ELF"]; } +def TargetSupportsAlias : TargetSpec { + let ObjectFormats = ["COFF", "ELF", "Wasm"]; +} // Attribute subject match rules that are used for #pragma clang attribute. // @@ -554,7 +557,7 @@ let Documentation = [Undocumented]; } -def Alias : Attr { +def Alias : Attr, TargetSpecificAttr { let Spellings = [GCC<"alias">]; let Args = [StringArgument<"Aliasee">]; let Subjects = SubjectList<[Function, GlobalVar], ErrorDiag>; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D45616: [X86] Lower _mm[256|512]_cmp[.]_mask intrinsics to native llvm IR
GBuella added a comment. Ping @efriedma Repository: rC Clang https://reviews.llvm.org/D45616 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D47108: Add -fforce-emit-vtables
amharc requested changes to this revision. amharc added a comment. This revision now requires changes to proceed. This is not sound: sometimes the forcefully emitted vtable is incorrect due to destructor aliasing. This happens e.g. in the Bullet benchmark from the llvm test suite. A simplified example follows. For a translation unit: struct Base { virtual int foo() { return 42; } virtual ~Base() { } }; struct Derived : Base { Derived(); }; int foo() { Derived *der = new Derived(); return der->foo(); } it emits: ; Function Attrs: nounwind declare dso_local void @_ZN7DerivedD1Ev(%struct.Derived*) unnamed_addr #6 ; Function Attrs: nounwind declare dso_local void @_ZN7DerivedD0Ev(%struct.Derived*) unnamed_addr #6 @_ZTV7Derived = linkonce_odr dso_local unnamed_addr constant { [5 x i8*] } { [5 x i8*] [i8* null, i8* bitcast ({ i8*, i8*, i8* }* @_ZTI7Derived to i8*), i8* bitcast (i32 (%struct.Base*)* @_ZN4Base3fooEv to i8*), i8* bitcast (void (%struct.Derived*)* @_ZN7DerivedD1Ev to i8*), i8* bitcast (void (%struct.Derived*)* @_ZN7DerivedD0Ev to i8*)] }, comdat, align 8 whereas for TU: struct Base { virtual int foo() { return 42; } virtual ~Base() { } }; struct Derived : Base { Derived(); }; Derived::Derived() { } which emits the whole vtable (even without this patch): @_ZTV7Derived = linkonce_odr dso_local unnamed_addr constant { [5 x i8*] } { [5 x i8*] [i8* null, i8* bitcast ({ i8*, i8*, i8* }* @_ZTI7Derived to i8*), i8* bitcast (i32 (%struct.Base*)* @_ZN4Base3fooEv to i8*), i8* bitcast (void (%struct.Base*)* @_ZN4BaseD2Ev to i8*), i8* bitcast (void (%struct.Derived*)* @_ZN7DerivedD0Ev to i8*)] }, comdat, align 8 Please note that the complete object destructor `@_ZN7DerivedD1Ev` has been RAUWed with the base object destructor `@_ZN4BaseD2Ev`. Since this triggers the RAUW case (as opposed to the Alias case) in `ItaniumCXXABI::emitCXXStructor`, the complete object destructor is **not** emitted at all. Because `Derived` lacks a key function, the vtable is `linkonce_odr` and any of those definitions can be picked. Hence, this code can stop linking at the whim of the linker. :( Repository: rL LLVM https://reviews.llvm.org/D47108 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46685: [CodeGen] Disable structor optimizations at -O0
This revision was not accepted when it landed; it landed in state "Needs Review". This revision was automatically updated to reflect the committed changes. Closed by commit rC332839: [CodeGen] Disable aggressive structor optimizations at -O0, take 2 (authored by labath, committed by ). Changed prior to commit: https://reviews.llvm.org/D46685?vs=147315=147765#toc Repository: rC Clang https://reviews.llvm.org/D46685 Files: lib/CodeGen/ItaniumCXXABI.cpp test/CodeGenCXX/ctor-dtor-alias.cpp test/CodeGenCXX/float16-declarations.cpp Index: test/CodeGenCXX/ctor-dtor-alias.cpp === --- test/CodeGenCXX/ctor-dtor-alias.cpp +++ test/CodeGenCXX/ctor-dtor-alias.cpp @@ -1,5 +1,7 @@ -// RUN: %clang_cc1 %s -triple i686-linux -emit-llvm -o - -mconstructor-aliases | FileCheck --check-prefix=NOOPT %s - +// RUN: %clang_cc1 %s -triple i686-linux -emit-llvm -o - -mconstructor-aliases > %t +// RUN: FileCheck --check-prefix=NOOPT1 --input-file=%t %s +// RUN: FileCheck --check-prefix=NOOPT2 --input-file=%t %s +// RUN: FileCheck --check-prefix=NOOPT3 --input-file=%t %s // RUN: %clang_cc1 %s -triple i686-linux -emit-llvm -o - -mconstructor-aliases -O1 -disable-llvm-passes > %t // RUN: FileCheck --check-prefix=CHECK1 --input-file=%t %s // RUN: FileCheck --check-prefix=CHECK2 --input-file=%t %s @@ -21,6 +23,13 @@ // CHECK1: define weak_odr void @_ZN5test16foobarIvED0Ev({{.*}} comdat($_ZN5test16foobarIvED5Ev) // CHECK1-NOT: comdat +// This should happen regardless of the opt level. +// NOOPT1: @_ZN5test16foobarIvEC1Ev = weak_odr alias void {{.*}} @_ZN5test16foobarIvEC2Ev +// NOOPT1: @_ZN5test16foobarIvED1Ev = weak_odr alias void (%"struct.test1::foobar"*), void (%"struct.test1::foobar"*)* @_ZN5test16foobarIvED2Ev +// NOOPT1: define weak_odr void @_ZN5test16foobarIvEC2Ev({{.*}} comdat($_ZN5test16foobarIvEC5Ev) +// NOOPT1: define weak_odr void @_ZN5test16foobarIvED2Ev({{.*}} comdat($_ZN5test16foobarIvED5Ev) +// NOOPT1: define weak_odr void @_ZN5test16foobarIvED0Ev({{.*}} comdat($_ZN5test16foobarIvED5Ev) + // COFF doesn't support comdats with arbitrary names (C5/D5). // COFF: define weak_odr {{.*}} void @_ZN5test16foobarIvEC2Ev({{.*}} comdat align // COFF: define weak_odr {{.*}} void @_ZN5test16foobarIvEC1Ev({{.*}} comdat align @@ -37,12 +46,17 @@ } namespace test2 { -// test that when the destrucor is linkonce_odr we just replace every use of +// test that when the destructor is linkonce_odr we just replace every use of // C1 with C2. // CHECK1: define internal void @__cxx_global_var_init() // CHECK1: call void @_ZN5test26foobarIvEC2Ev // CHECK1: define linkonce_odr void @_ZN5test26foobarIvEC2Ev({{.*}} comdat align + +// At -O0, we should still emit the complete constructor. +// NOOPT1: define internal void @__cxx_global_var_init() +// NOOPT1: call void @_ZN5test26foobarIvEC1Ev +// NOOPT1: define linkonce_odr void @_ZN5test26foobarIvEC1Ev({{.*}} comdat align void g(); template struct foobar { foobar() { g(); } @@ -57,6 +71,11 @@ // CHECK1: define internal void @__cxx_global_var_init.1() // CHECK1: call i32 @__cxa_atexit{{.*}}_ZN5test312_GLOBAL__N_11AD2Ev // CHECK1: define internal void @_ZN5test312_GLOBAL__N_11AD2Ev( + +// We can use an alias for internal symbols at -O0. +// NOOPT2: _ZN5test312_GLOBAL__N_11BD1Ev = internal alias void {{.*}} @_ZN5test312_GLOBAL__N_11BD2Ev +// NOOPT2: define internal void @__cxx_global_var_init.1() +// NOOPT2: call i32 @__cxa_atexit{{.*}}_ZN5test312_GLOBAL__N_11BD1Ev namespace { struct A { ~A() {} @@ -77,11 +96,12 @@ // CHECK1: call i32 @__cxa_atexit{{.*}}_ZN5test41AD2Ev // CHECK1: define linkonce_odr void @_ZN5test41AD2Ev({{.*}} comdat align - // test that we don't do this optimization at -O0 so that the debugger can - // see both destructors. - // NOOPT: define internal void @__cxx_global_var_init.2() - // NOOPT: call i32 @__cxa_atexit{{.*}}@_ZN5test41BD2Ev - // NOOPT: define linkonce_odr void @_ZN5test41BD2Ev({{.*}} comdat align + // Test that we don't do this optimization at -O0 and call the complete + // destructor for B instead. This enables the debugger to see both + // destructors. + // NOOPT2: define internal void @__cxx_global_var_init.2() + // NOOPT2: call i32 @__cxa_atexit{{.*}}@_ZN5test41BD1Ev + // NOOPT2: define linkonce_odr void @_ZN5test41BD1Ev({{.*}} comdat align struct A { virtual ~A() {} }; @@ -129,6 +149,11 @@ // out if we should). // pr17875. // CHECK3: define void @_ZN5test71BD2Ev + + // At -O0, we should emit both destructors, the complete can be an alias to + // the base one. + // NOOPT3: @_ZN5test71BD1Ev = alias void {{.*}} @_ZN5test71BD2Ev + // NOOPT3: define void @_ZN5test71BD2Ev template struct A { ~A() {} }; Index: test/CodeGenCXX/float16-declarations.cpp === --- test/CodeGenCXX/float16-declarations.cpp +++ test/CodeGenCXX/float16-declarations.cpp
r332839 - [CodeGen] Disable aggressive structor optimizations at -O0, take 2
Author: labath Date: Mon May 21 04:47:45 2018 New Revision: 332839 URL: http://llvm.org/viewvc/llvm-project?rev=332839=rev Log: [CodeGen] Disable aggressive structor optimizations at -O0, take 2 The first version of the patch (r332228) was flawed because it was putting structors into C5/D5 comdats very eagerly. This is correct only if we can ensure the comdat contains all required versions of the structor (which wasn't the case). This version uses a more nuanced approach: - for local structor symbols we use an alias because we don't have to worry about comdats or other compilation units. - linkonce symbols are emitted separately, as we cannot guarantee we will have all symbols we need to form a comdat (they are emitted lazily, only when referenced). - available_externally symbols are also emitted separately, as the code seemed to be worried about emitting an alias in this case. - other linkage types are not affected by the optimization level. They either get put into a comdat (weak) or get aliased (external). Reviewers: rjmccall, aprantl Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D46685 Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp cfe/trunk/test/CodeGenCXX/float16-declarations.cpp Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=332839=332838=332839=diff == --- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original) +++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Mon May 21 04:47:45 2018 @@ -3628,12 +3628,22 @@ static StructorCodegen getCodegenToUse(C } llvm::GlobalValue::LinkageTypes Linkage = CGM.getFunctionLinkage(AliasDecl); - if (llvm::GlobalValue::isDiscardableIfUnused(Linkage)) -return StructorCodegen::RAUW; + // All discardable structors can be RAUWed, but we don't want to do that in + // unoptimized code, as that makes complete structor symbol disappear + // completely, which degrades debugging experience. + // Symbols with private linkage can be safely aliased, so we special case them + // here. + if (llvm::GlobalValue::isLocalLinkage(Linkage)) +return CGM.getCodeGenOpts().OptimizationLevel > 0 ? StructorCodegen::RAUW + : StructorCodegen::Alias; + // Linkonce structors cannot be aliased nor placed in a comdat, so these need + // to be emitted separately. // FIXME: Should we allow available_externally aliases? - if (!llvm::GlobalAlias::isValidLinkage(Linkage)) -return StructorCodegen::RAUW; + if (llvm::GlobalValue::isDiscardableIfUnused(Linkage) || + !llvm::GlobalAlias::isValidLinkage(Linkage)) +return CGM.getCodeGenOpts().OptimizationLevel > 0 ? StructorCodegen::RAUW + : StructorCodegen::Emit; if (llvm::GlobalValue::isWeakForLinker(Linkage)) { // Only ELF and wasm support COMDATs with arbitrary names (C5/D5). Modified: cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp?rev=332839=332838=332839=diff == --- cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp (original) +++ cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp Mon May 21 04:47:45 2018 @@ -1,5 +1,7 @@ -// RUN: %clang_cc1 %s -triple i686-linux -emit-llvm -o - -mconstructor-aliases | FileCheck --check-prefix=NOOPT %s - +// RUN: %clang_cc1 %s -triple i686-linux -emit-llvm -o - -mconstructor-aliases > %t +// RUN: FileCheck --check-prefix=NOOPT1 --input-file=%t %s +// RUN: FileCheck --check-prefix=NOOPT2 --input-file=%t %s +// RUN: FileCheck --check-prefix=NOOPT3 --input-file=%t %s // RUN: %clang_cc1 %s -triple i686-linux -emit-llvm -o - -mconstructor-aliases -O1 -disable-llvm-passes > %t // RUN: FileCheck --check-prefix=CHECK1 --input-file=%t %s // RUN: FileCheck --check-prefix=CHECK2 --input-file=%t %s @@ -21,6 +23,13 @@ namespace test1 { // CHECK1: define weak_odr void @_ZN5test16foobarIvED0Ev({{.*}} comdat($_ZN5test16foobarIvED5Ev) // CHECK1-NOT: comdat +// This should happen regardless of the opt level. +// NOOPT1: @_ZN5test16foobarIvEC1Ev = weak_odr alias void {{.*}} @_ZN5test16foobarIvEC2Ev +// NOOPT1: @_ZN5test16foobarIvED1Ev = weak_odr alias void (%"struct.test1::foobar"*), void (%"struct.test1::foobar"*)* @_ZN5test16foobarIvED2Ev +// NOOPT1: define weak_odr void @_ZN5test16foobarIvEC2Ev({{.*}} comdat($_ZN5test16foobarIvEC5Ev) +// NOOPT1: define weak_odr void @_ZN5test16foobarIvED2Ev({{.*}} comdat($_ZN5test16foobarIvED5Ev) +// NOOPT1: define weak_odr void @_ZN5test16foobarIvED0Ev({{.*}} comdat($_ZN5test16foobarIvED5Ev) + // COFF doesn't support comdats with arbitrary names (C5/D5). // COFF: define weak_odr {{.*}} void @_ZN5test16foobarIvEC2Ev({{.*}}
[PATCH] D47135: [analyzer][WIP] A checker for dangling string pointers in C++
rnkovacs created this revision. rnkovacs added reviewers: NoQ, xazax.hun, george.karpenkov. Herald added subscribers: a.sidorin, dkrupp, szepet, baloghadamsoftware, whisperity, mgorny. This check marks a raw pointer to a C++ string object's inner buffer "released" when the object itself is destroyed. This information can be used by MallocChecker to warn for use-after-free problems. Test cases using mocks are to be added. Until then, the following file is used for testing purposes: <>. Repository: rC Clang https://reviews.llvm.org/D47135 Files: include/clang/StaticAnalyzer/Checkers/Checkers.td lib/StaticAnalyzer/Checkers/CMakeLists.txt lib/StaticAnalyzer/Checkers/DanglingStringPointerChecker.cpp lib/StaticAnalyzer/Checkers/MallocChecker.cpp lib/StaticAnalyzer/Checkers/RegionState.h Index: lib/StaticAnalyzer/Checkers/RegionState.h === --- /dev/null +++ lib/StaticAnalyzer/Checkers/RegionState.h @@ -0,0 +1,28 @@ +//===--- RegionState.h - *- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// + +#ifndef LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_REGIONSTATE_H +#define LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_REGIONSTATE_H + +#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h" + +namespace clang { +namespace ento { + +namespace region_state { + +ProgramStateRef markReleased(ProgramStateRef State, SymbolRef Sym, + const Expr *Origin); + +} // end namespace region_state + +} // end namespace ento +} // end namespace clang + +#endif Index: lib/StaticAnalyzer/Checkers/MallocChecker.cpp === --- lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ lib/StaticAnalyzer/Checkers/MallocChecker.cpp @@ -30,6 +30,7 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringExtras.h" +#include "RegionState.h" #include #include @@ -2991,6 +2992,21 @@ } } +namespace clang { +namespace ento { +namespace region_state { + +ProgramStateRef +markReleased(ProgramStateRef State, SymbolRef Sym, const Expr *Origin) { + // FIXME: This might not be the best allocation family for this purpose. + AllocationFamily Family = AF_CXXNew; + return State->set(Sym, RefState::getReleased(Family, Origin)); +} + +} // end namespace region_state +} // end namespace ento +} // end namespace clang + void ento::registerNewDeleteLeaksChecker(CheckerManager ) { registerCStringCheckerBasic(mgr); MallocChecker *checker = mgr.registerChecker(); Index: lib/StaticAnalyzer/Checkers/DanglingStringPointerChecker.cpp === --- /dev/null +++ lib/StaticAnalyzer/Checkers/DanglingStringPointerChecker.cpp @@ -0,0 +1,85 @@ +//=== DanglingStringPointerChecker.cpp *- C++ -*--// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// +// +// This file defines a check that marks a raw pointer to a C++ string object's +// inner buffer released when the object is destroyed. This information can +// then be used by MallocChecker to detect further use-after-free problems. +// +//===--===// + +#include "ClangSACheckers.h" +#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h" +#include "clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h" +#include "clang/StaticAnalyzer/Core/Checker.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h" +#include "RegionState.h" + +using namespace clang; +using namespace ento; + +namespace { + +class DanglingStringPointerChecker : public Checker { + CallDescription CStrFn; + +public: + DanglingStringPointerChecker() : CStrFn("c_str") {} + + /// Record the connection between the symbol returned by c_str() and the + /// corresponding string object region in the ProgramState. Mark the symbol + /// released if the string object is destroyed. + void checkPostCall(const CallEvent , CheckerContext ) const; +}; + +} // end anonymous namespace + +// FIXME: c_str() may be called on a string object many times, so it should +// have a list of symbols associated with it. +REGISTER_MAP_WITH_PROGRAMSTATE(RawPtrMap, const MemRegion *, SymbolRef) + +void DanglingStringPointerChecker::checkPostCall(const CallEvent , + CheckerContext ) const { + const auto
[PATCH] D46910: [Support] Avoid normalization in sys::getDefaultTargetTriple
thakis added a comment. > Sorry about the breakage, I wasn't aware of that test failure and never got > any email (probably because the bot has been red before). I'll try to fix > make_itanium_abi_triple and test it on my Windows box tomorrow before > resubmitting. Thanks, sounds good. Reading the history of the review a bit, it sounds like Reid did try to test this on Windows. My guess is that he didn't create a completely new build directory, and that cmake's cache made it so that he didn't see all the changes that are in here. (Our bots always blow away the cmake cache on each build for this reason.) So make sure to create a fresh build dir for each local iteration of the patch when you test this. > The change was made through monorepo and submitted via `git llvm push` which > allows changing multiple projects in one commit. Is there some toggle necessary to make it so that all parts of the patch show up on phab? For this issue, phab only displays the clang bit, which confused me for a while. Repository: rC Clang https://reviews.llvm.org/D46910 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46541: [CodeGen] Improve diagnostics related to target attributes
echristo added a comment. I think this will work, one inline comment. Might also be good to get a few different test cases, e.g. one where we're not seeing the alphabetically first as the minimum :) Comment at: lib/CodeGen/CodeGenModule.h:1085 + TargetAttr::ParsedTargetAttr filterFunctionTargetAttrs(const TargetAttr *TD); + Needs a block comment saying what it does :) https://reviews.llvm.org/D46541 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D44888: [RISCV] Add -mrelax/-mno-relax flags to enable/disable RISCV linker relaxation
shiva0217 updated this revision to Diff 147739. shiva0217 retitled this revision from "[RISCV] Default enable linker relaxation and add -mrelax, -mno-relax flags" to "[RISCV] Add -mrelax/-mno-relax flags to enable/disable RISCV linker relaxation". shiva0217 edited the summary of this revision. Repository: rL LLVM https://reviews.llvm.org/D44888 Files: include/clang/Driver/Options.td lib/Driver/ToolChains/Arch/RISCV.cpp test/Driver/riscv-features.c Index: test/Driver/riscv-features.c === --- test/Driver/riscv-features.c +++ test/Driver/riscv-features.c @@ -2,3 +2,9 @@ // RUN: %clang -target riscv64-unknown-elf -### %s -fsyntax-only 2>&1 | FileCheck %s // CHECK: fno-signed-char + +// RUN: %clang -target riscv32-unknown-elf -### %s -mrelax 2>&1 | FileCheck %s -check-prefix=RELAX +// RUN: %clang -target riscv32-unknown-elf -### %s -mno-relax 2>&1 | FileCheck %s -check-prefix=NO-RELAX + +// RELAX: "-target-feature" "+relax" +// NO-RELAX: "-target-feature" "-relax" Index: lib/Driver/ToolChains/Arch/RISCV.cpp === --- lib/Driver/ToolChains/Arch/RISCV.cpp +++ lib/Driver/ToolChains/Arch/RISCV.cpp @@ -15,6 +15,7 @@ #include "llvm/Option/ArgList.h" #include "llvm/Support/TargetParser.h" #include "llvm/Support/raw_ostream.h" +#include "ToolChains/CommonArgs.h" using namespace clang::driver; using namespace clang::driver::tools; @@ -363,6 +364,10 @@ // Handle all other types of extensions. getExtensionFeatures(D, Args, Features, MArch, OtherExts); } + + // Now add any that the user explicitly requested on the command line, + // which may override the defaults. + handleTargetFeaturesGroup(Args, Features, options::OPT_m_riscv_Features_Group); } StringRef riscv::getRISCVABI(const ArgList , const llvm::Triple ) { Index: include/clang/Driver/Options.td === --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -151,6 +151,8 @@ Group, DocName<"WebAssembly">; def m_x86_Features_Group : OptionGroup<"">, Group, Flags<[CoreOption]>, DocName<"X86">; +def m_riscv_Features_Group : OptionGroup<"">, + Group, DocName<"RISCV">; def m_libc_Group : OptionGroup<"">, Group, Flags<[HelpHidden]>; @@ -1952,6 +1954,11 @@ def mno_soft_float : Flag<["-"], "mno-soft-float">, Group; def mno_stackrealign : Flag<["-"], "mno-stackrealign">, Group; +def mrelax : Flag<["-"], "mrelax">, Group, + HelpText<"Enable linker relaxation">; +def mno_relax : Flag<["-"], "mno-relax">, Group, + HelpText<"Disable linker relaxation">; + def munaligned_access : Flag<["-"], "munaligned-access">, Group, HelpText<"Allow memory accesses to be unaligned (AArch32/AArch64 only)">; def mno_unaligned_access : Flag<["-"], "mno-unaligned-access">, Group, Index: test/Driver/riscv-features.c === --- test/Driver/riscv-features.c +++ test/Driver/riscv-features.c @@ -2,3 +2,9 @@ // RUN: %clang -target riscv64-unknown-elf -### %s -fsyntax-only 2>&1 | FileCheck %s // CHECK: fno-signed-char + +// RUN: %clang -target riscv32-unknown-elf -### %s -mrelax 2>&1 | FileCheck %s -check-prefix=RELAX +// RUN: %clang -target riscv32-unknown-elf -### %s -mno-relax 2>&1 | FileCheck %s -check-prefix=NO-RELAX + +// RELAX: "-target-feature" "+relax" +// NO-RELAX: "-target-feature" "-relax" Index: lib/Driver/ToolChains/Arch/RISCV.cpp === --- lib/Driver/ToolChains/Arch/RISCV.cpp +++ lib/Driver/ToolChains/Arch/RISCV.cpp @@ -15,6 +15,7 @@ #include "llvm/Option/ArgList.h" #include "llvm/Support/TargetParser.h" #include "llvm/Support/raw_ostream.h" +#include "ToolChains/CommonArgs.h" using namespace clang::driver; using namespace clang::driver::tools; @@ -363,6 +364,10 @@ // Handle all other types of extensions. getExtensionFeatures(D, Args, Features, MArch, OtherExts); } + + // Now add any that the user explicitly requested on the command line, + // which may override the defaults. + handleTargetFeaturesGroup(Args, Features, options::OPT_m_riscv_Features_Group); } StringRef riscv::getRISCVABI(const ArgList , const llvm::Triple ) { Index: include/clang/Driver/Options.td === --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -151,6 +151,8 @@ Group, DocName<"WebAssembly">; def m_x86_Features_Group : OptionGroup<"">, Group, Flags<[CoreOption]>, DocName<"X86">; +def m_riscv_Features_Group : OptionGroup<"">, + Group, DocName<"RISCV">; def m_libc_Group : OptionGroup<"">, Group,
[PATCH] D47125: [X86] Remove masking from pternlog llvm intrinsics and use a select instruction instead.
GBuella added a comment. So do these really need to be implemented as macros? Repository: rC Clang https://reviews.llvm.org/D47125 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46944: [analyzer] Use sufficiently large types for index/size calculation.
ebevhan updated this revision to Diff 147738. ebevhan edited the summary of this revision. ebevhan added a comment. Made ArrayIndexTy into ssize_t, consolidated the tests and fixed the test that was failing. https://reviews.llvm.org/D46944 Files: include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h lib/StaticAnalyzer/Core/ProgramState.cpp lib/StaticAnalyzer/Core/RegionStore.cpp test/Analysis/index-type.c Index: test/Analysis/index-type.c === --- test/Analysis/index-type.c +++ test/Analysis/index-type.c @@ -6,15 +6,34 @@ #ifdef M32 -#define X86_ARRAY_SIZE (UINT_MAX/2 + 4) +#define X86_ARRAY_SIZE (UINT_MAX/4 + 4) void testIndexTooBig() { char arr[X86_ARRAY_SIZE]; - char *ptr = arr + UINT_MAX/2; + char *ptr = arr + UINT_MAX/4; ptr += 2; // index shouldn't overflow *ptr = 42; // no-warning } +#define SIZE 4294967296 + +static unsigned size; +static void * addr; +static unsigned buf[SIZE]; + +void testOutOfBounds() { + // not out of bounds + buf[SIZE-1] = 1; // no-warning +} + +void testOutOfBoundsCopy1() { + memcpy(buf, addr, size); // no-warning +} + +void testOutOfBoundsCopy2() { + memcpy(addr, buf, size); // no-warning +} + #else // 64-bit tests #define ARRAY_SIZE 0x1 Index: lib/StaticAnalyzer/Core/RegionStore.cpp === --- lib/StaticAnalyzer/Core/RegionStore.cpp +++ lib/StaticAnalyzer/Core/RegionStore.cpp @@ -1341,7 +1341,8 @@ // If a variable is reinterpreted as a type that doesn't fit into a larger // type evenly, round it down. // This is a signed value, since it's used in arithmetic with signed indices. - return svalBuilder.makeIntVal(RegionSize / EleSize, false); + return svalBuilder.makeIntVal(RegionSize / EleSize, +svalBuilder.getArrayIndexType()); } //===--===// Index: lib/StaticAnalyzer/Core/ProgramState.cpp === --- lib/StaticAnalyzer/Core/ProgramState.cpp +++ lib/StaticAnalyzer/Core/ProgramState.cpp @@ -336,9 +336,8 @@ // Get the offset: the minimum value of the array index type. BasicValueFactory = svalBuilder.getBasicValueFactory(); - // FIXME: This should be using ValueManager::ArrayindexTy...somehow. if (indexTy.isNull()) -indexTy = Ctx.IntTy; +indexTy = svalBuilder.getArrayIndexType(); nonloc::ConcreteInt Min(BVF.getMinValue(indexTy)); // Adjust the index. Index: include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h === --- include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h +++ include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h @@ -86,7 +86,7 @@ ProgramStateManager ) : Context(context), BasicVals(context, alloc), SymMgr(context, BasicVals, alloc), MemMgr(context, alloc), -StateMgr(stateMgr), ArrayIndexTy(context.LongLongTy), +StateMgr(stateMgr), ArrayIndexTy(context.getSignedSizeType()), ArrayIndexWidth(context.getTypeSize(ArrayIndexTy)) {} virtual ~SValBuilder() = default; Index: test/Analysis/index-type.c === --- test/Analysis/index-type.c +++ test/Analysis/index-type.c @@ -6,15 +6,34 @@ #ifdef M32 -#define X86_ARRAY_SIZE (UINT_MAX/2 + 4) +#define X86_ARRAY_SIZE (UINT_MAX/4 + 4) void testIndexTooBig() { char arr[X86_ARRAY_SIZE]; - char *ptr = arr + UINT_MAX/2; + char *ptr = arr + UINT_MAX/4; ptr += 2; // index shouldn't overflow *ptr = 42; // no-warning } +#define SIZE 4294967296 + +static unsigned size; +static void * addr; +static unsigned buf[SIZE]; + +void testOutOfBounds() { + // not out of bounds + buf[SIZE-1] = 1; // no-warning +} + +void testOutOfBoundsCopy1() { + memcpy(buf, addr, size); // no-warning +} + +void testOutOfBoundsCopy2() { + memcpy(addr, buf, size); // no-warning +} + #else // 64-bit tests #define ARRAY_SIZE 0x1 Index: lib/StaticAnalyzer/Core/RegionStore.cpp === --- lib/StaticAnalyzer/Core/RegionStore.cpp +++ lib/StaticAnalyzer/Core/RegionStore.cpp @@ -1341,7 +1341,8 @@ // If a variable is reinterpreted as a type that doesn't fit into a larger // type evenly, round it down. // This is a signed value, since it's used in arithmetic with signed indices. - return svalBuilder.makeIntVal(RegionSize / EleSize, false); + return svalBuilder.makeIntVal(RegionSize / EleSize, +svalBuilder.getArrayIndexType()); } //===--===// Index: lib/StaticAnalyzer/Core/ProgramState.cpp === ---
[PATCH] D44539: [Sema][Objective-C] Add check to warn when property of objc type has assign attribute
rjmccall added a comment. This was approved by the Objective-C language group as a default-off warning. Comment at: include/clang/Basic/DiagnosticSemaKinds.td:1018 +def warn_objc_property_assign_on_object : Warning< + "'assign' attribute must not be of object type, use 'unsafe_unretained' instead">, + InGroup, DefaultIgnore; "must" is rather strong for a warning. Maybe something more like "'assign' attribute on property of object type could be 'unsafe_unretained'"? Repository: rC Clang https://reviews.llvm.org/D44539 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D40988: Clang-format: add finer-grained options for putting all arguments on one line
djasper added inline comments. Comment at: lib/Format/ContinuationIndenter.cpp:760 (!Style.AllowAllParametersOfDeclarationOnNextLine && State.Line->MustBeDeclaration) || +(!Style.AllowAllArgumentsOnNextLine && This still looks suspicious to me. State.Line->MustBeDeclaration is either true or false meaning that AllowAllParametersOfDeclarationOnNextLine or AllowAllArgumentsOnNextLine can always affect the behavior here, leading to BreakBeforeParameter to be set to true, even if we are in the case for PreviousIsBreakingCtorInitializerColon being true. So, my guess would be that if you set one of AllowAllArgumentsOnNextLine and AllowAllParametersOfDeclarationOnNextLine to false, then AllowAllConstructorInitializersOnNextLine doesn't have an effect anymore. Please verify, and if this is true, please fix and add tests. I think this might be easier to understand if you pulled the one if statement apart. https://reviews.llvm.org/D40988 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D47029: [X86] Remove some preprocessor feature checks from intrinsic headers
This revision was automatically updated to reflect the committed changes. Closed by commit rC332830: [X86] Remove some preprocessor feature checks from intrinsic headers (authored by ctopper, committed by ). Repository: rC Clang https://reviews.llvm.org/D47029 Files: lib/Headers/prfchwintrin.h lib/Headers/smmintrin.h Index: lib/Headers/smmintrin.h === --- lib/Headers/smmintrin.h +++ lib/Headers/smmintrin.h @@ -2458,8 +2458,6 @@ #undef __DEFAULT_FN_ATTRS -#ifdef __POPCNT__ #include -#endif #endif /* __SMMINTRIN_H */ Index: lib/Headers/prfchwintrin.h === --- lib/Headers/prfchwintrin.h +++ lib/Headers/prfchwintrin.h @@ -28,7 +28,6 @@ #ifndef __PRFCHWINTRIN_H #define __PRFCHWINTRIN_H -#if defined(__PRFCHW__) || defined(__3dNOW__) /// Loads a memory sequence containing the specified memory address into ///all data cache levels. The cache-coherency state is set to exclusive. ///Data can be read from and written to the cache line without additional @@ -66,6 +65,5 @@ { __builtin_prefetch (__P, 1, 3 /* _MM_HINT_T0 */); } -#endif #endif /* __PRFCHWINTRIN_H */ Index: lib/Headers/smmintrin.h === --- lib/Headers/smmintrin.h +++ lib/Headers/smmintrin.h @@ -2458,8 +2458,6 @@ #undef __DEFAULT_FN_ATTRS -#ifdef __POPCNT__ #include -#endif #endif /* __SMMINTRIN_H */ Index: lib/Headers/prfchwintrin.h === --- lib/Headers/prfchwintrin.h +++ lib/Headers/prfchwintrin.h @@ -28,7 +28,6 @@ #ifndef __PRFCHWINTRIN_H #define __PRFCHWINTRIN_H -#if defined(__PRFCHW__) || defined(__3dNOW__) /// Loads a memory sequence containing the specified memory address into ///all data cache levels. The cache-coherency state is set to exclusive. ///Data can be read from and written to the cache line without additional @@ -66,6 +65,5 @@ { __builtin_prefetch (__P, 1, 3 /* _MM_HINT_T0 */); } -#endif #endif /* __PRFCHWINTRIN_H */ ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r332830 - [X86] Remove some preprocessor feature checks from intrinsic headers
Author: ctopper Date: Sun May 20 23:07:49 2018 New Revision: 332830 URL: http://llvm.org/viewvc/llvm-project?rev=332830=rev Log: [X86] Remove some preprocessor feature checks from intrinsic headers Summary: These look to be a couple things that weren't removed when we switched to target attribute. The popcnt makes including just smmintrin.h also include popcntintrin.h. The popcnt file itself already contains target attrributes. The prefetch ones are just wrappers around __builtin_prefetch which we have graceful fallbacks for in the backend if the exact instruction isn't available. So there's no reason to hide them. And it makes them available in functions that have the write target attribute but not a -march command line flag. Reviewers: echristo, RKSimon, spatel, DavidKreitzer Reviewed By: echristo Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D47029 Modified: cfe/trunk/lib/Headers/prfchwintrin.h cfe/trunk/lib/Headers/smmintrin.h Modified: cfe/trunk/lib/Headers/prfchwintrin.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/prfchwintrin.h?rev=332830=332829=332830=diff == --- cfe/trunk/lib/Headers/prfchwintrin.h (original) +++ cfe/trunk/lib/Headers/prfchwintrin.h Sun May 20 23:07:49 2018 @@ -28,7 +28,6 @@ #ifndef __PRFCHWINTRIN_H #define __PRFCHWINTRIN_H -#if defined(__PRFCHW__) || defined(__3dNOW__) /// Loads a memory sequence containing the specified memory address into ///all data cache levels. The cache-coherency state is set to exclusive. ///Data can be read from and written to the cache line without additional @@ -66,6 +65,5 @@ _m_prefetchw(void *__P) { __builtin_prefetch (__P, 1, 3 /* _MM_HINT_T0 */); } -#endif #endif /* __PRFCHWINTRIN_H */ Modified: cfe/trunk/lib/Headers/smmintrin.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/smmintrin.h?rev=332830=332829=332830=diff == --- cfe/trunk/lib/Headers/smmintrin.h (original) +++ cfe/trunk/lib/Headers/smmintrin.h Sun May 20 23:07:49 2018 @@ -2458,8 +2458,6 @@ _mm_crc32_u64(unsigned long long __C, un #undef __DEFAULT_FN_ATTRS -#ifdef __POPCNT__ #include -#endif #endif /* __SMMINTRIN_H */ ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits