Author: gordon Date: Mon Dec 24 20:31:26 2007 New Revision: 45350 URL: http://llvm.org/viewvc/llvm-project?rev=45350&view=rev Log: Noting and enforcing that GC intrinsics are valid only within a function with GC.
This will catch the error when the inliner inlines a function with GC into a caller with no GC. Added: llvm/trunk/test/CodeGen/Generic/GC/outside.ll Modified: llvm/trunk/docs/LangRef.html llvm/trunk/lib/VMCore/Verifier.cpp llvm/trunk/test/CodeGen/Generic/GC/lower_gcroot.ll Modified: llvm/trunk/docs/LangRef.html URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/LangRef.html?rev=45350&r1=45349&r2=45350&view=diff ============================================================================== --- llvm/trunk/docs/LangRef.html (original) +++ llvm/trunk/docs/LangRef.html Mon Dec 24 20:31:26 2007 @@ -3995,8 +3995,9 @@ <p>At runtime, a call to this intrinsics stores a null pointer into the "ptrloc" location. At compile-time, the code generator generates information to allow -the runtime to find the pointer at GC safe points. -</p> +the runtime to find the pointer at GC safe points. The '<tt>llvm.gcroot</tt>' +intrinsic may only be used in a function which <a href="#gc">specifies a GC +algorithm</a>.</p> </div> @@ -4031,7 +4032,9 @@ <p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load instruction, but may be replaced with substantially more complex code by the -garbage collector runtime, as needed.</p> +garbage collector runtime, as needed. The '<tt>llvm.gcread</tt>' intrinsic +may only be used in a function which <a href="#gc">specifies a GC +algorithm</a>.</p> </div> @@ -4066,7 +4069,9 @@ <p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store instruction, but may be replaced with substantially more complex code by the -garbage collector runtime, as needed.</p> +garbage collector runtime, as needed. The '<tt>llvm.gcwrite</tt>' intrinsic +may only be used in a function which <a href="#gc">specifies a GC +algorithm</a>.</p> </div> Modified: llvm/trunk/lib/VMCore/Verifier.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Verifier.cpp?rev=45350&r1=45349&r2=45350&view=diff ============================================================================== --- llvm/trunk/lib/VMCore/Verifier.cpp (original) +++ llvm/trunk/lib/VMCore/Verifier.cpp Mon Dec 24 20:31:26 2007 @@ -1167,37 +1167,45 @@ switch (ID) { default: break; - case Intrinsic::gcroot: { - Type *PtrTy = PointerType::getUnqual(Type::Int8Ty), - *PtrPtrTy = PointerType::getUnqual(PtrTy); - Assert1(CI.getOperand(1)->getType() == PtrPtrTy, - "Intrinsic parameter #1 is not i8**.", &CI); - Assert1(CI.getOperand(2)->getType() == PtrTy, - "Intrinsic parameter #2 is not i8*.", &CI); - Assert1( - isa<AllocaInst>(IntrinsicInst::StripPointerCasts(CI.getOperand(1))), - "llvm.gcroot parameter #1 must be an alloca.", - &CI); - Assert1(isa<Constant>(CI.getOperand(2)), - "llvm.gcroot parameter #2 must be a constant.", &CI); - } break; - case Intrinsic::gcwrite: { - Type *PtrTy = PointerType::getUnqual(Type::Int8Ty), - *PtrPtrTy = PointerType::getUnqual(PtrTy); - Assert1(CI.getOperand(1)->getType() == PtrTy, - "Intrinsic parameter #1 is not a i8*.", &CI); - Assert1(CI.getOperand(2)->getType() == PtrTy, - "Intrinsic parameter #2 is not a i8*.", &CI); - Assert1(CI.getOperand(3)->getType() == PtrPtrTy, - "Intrinsic parameter #3 is not a i8**.", &CI); - } break; + case Intrinsic::gcroot: + case Intrinsic::gcwrite: case Intrinsic::gcread: { Type *PtrTy = PointerType::getUnqual(Type::Int8Ty), *PtrPtrTy = PointerType::getUnqual(PtrTy); - Assert1(CI.getOperand(1)->getType() == PtrTy, - "Intrinsic parameter #1 is not a i8*.", &CI); - Assert1(CI.getOperand(2)->getType() == PtrPtrTy, - "Intrinsic parameter #2 is not a i8**.", &CI); + + switch (ID) { + default: + break; + case Intrinsic::gcroot: + Assert1(CI.getOperand(1)->getType() == PtrPtrTy, + "Intrinsic parameter #1 is not i8**.", &CI); + Assert1(CI.getOperand(2)->getType() == PtrTy, + "Intrinsic parameter #2 is not i8*.", &CI); + Assert1(isa<AllocaInst>( + IntrinsicInst::StripPointerCasts(CI.getOperand(1))), + "llvm.gcroot parameter #1 must be an alloca.", &CI); + Assert1(isa<Constant>(CI.getOperand(2)), + "llvm.gcroot parameter #2 must be a constant.", &CI); + break; + case Intrinsic::gcwrite: + Assert1(CI.getOperand(1)->getType() == PtrTy, + "Intrinsic parameter #1 is not a i8*.", &CI); + Assert1(CI.getOperand(2)->getType() == PtrTy, + "Intrinsic parameter #2 is not a i8*.", &CI); + Assert1(CI.getOperand(3)->getType() == PtrPtrTy, + "Intrinsic parameter #3 is not a i8**.", &CI); + break; + case Intrinsic::gcread: + Assert1(CI.getOperand(1)->getType() == PtrTy, + "Intrinsic parameter #1 is not a i8*.", &CI); + Assert1(CI.getOperand(2)->getType() == PtrPtrTy, + "Intrinsic parameter #2 is not a i8**.", &CI); + break; + } + + Assert1(CI.getParent()->getParent()->hasCollector(), + "Enclosing function does not specify a collector algorithm.", + &CI); } break; case Intrinsic::init_trampoline: Assert1(isa<Function>(IntrinsicInst::StripPointerCasts(CI.getOperand(2))), Modified: llvm/trunk/test/CodeGen/Generic/GC/lower_gcroot.ll URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Generic/GC/lower_gcroot.ll?rev=45350&r1=45349&r2=45350&view=diff ============================================================================== --- llvm/trunk/test/CodeGen/Generic/GC/lower_gcroot.ll (original) +++ llvm/trunk/test/CodeGen/Generic/GC/lower_gcroot.ll Mon Dec 24 20:31:26 2007 @@ -2,7 +2,7 @@ %Env = type i8* -define void @.main(%Env) { +define void @.main(%Env) gc "shadow-stack" { %Root = alloca %Env call void @llvm.gcroot( %Env* %Root, %Env null ) unreachable Added: llvm/trunk/test/CodeGen/Generic/GC/outside.ll URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Generic/GC/outside.ll?rev=45350&view=auto ============================================================================== --- llvm/trunk/test/CodeGen/Generic/GC/outside.ll (added) +++ llvm/trunk/test/CodeGen/Generic/GC/outside.ll Mon Dec 24 20:31:26 2007 @@ -0,0 +1,10 @@ +; RUN: not llvm-as < %s + +declare void @llvm.gcroot(i8**, i8*) + +define void @f(i8* %x) { + %root = alloca i8* + call void @llvm.gcroot(i8** %root, i8* null) + store i8* %x, i8** %root + ret void +} _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits