r243206 - [CodeGen] Don't UBSan-ize the argument to __builtin_frame_address

Richard Smith richard at metafoo.co.uk
Wed Jul 29 20:59:37 PDT 2015


Aye.

On Tue, Jul 28, 2015 at 5:57 PM, Hans Wennborg <hans at chromium.org> wrote:

> Sure. Richard, what say you?
>
> On Tue, Jul 28, 2015 at 3:54 PM, Pieb, Wolfgang
> <Wolfgang_Pieb at playstation.sony.com> wrote:
> > Hi, would it be possible to put this fix into the 3.7 branch?
> >
> > Thanks
> >
> >> -----Original Message-----
> >> From: cfe-commits-bounces at cs.uiuc.edu [mailto:cfe-commits-
> >> bounces at cs.uiuc.edu] On Behalf Of David Majnemer
> >> Sent: Friday, July 24, 2015 10:57 PM
> >> To: cfe-commits at cs.uiuc.edu
> >> Subject: r243206 - [CodeGen] Don't UBSan-ize the argument to
> >> __builtin_frame_address
> >>
> >> Author: majnemer
> >> Date: Sat Jul 25 00:57:24 2015
> >> New Revision: 243206
> >>
> >> URL: http://llvm.org/viewvc/llvm-project?rev=243206&view=rev
> >> Log:
> >> [CodeGen] Don't UBSan-ize the argument to __builtin_frame_address
> >>
> >> __builtin_frame_address requires its argument to be a constant
> >> expression which already implies that it cannot have undefined
> >> behavior.
> >> However, we used EmitScalarExpr to emit the argument causing UBSan to
> >> try to check for overflow.
> >>
> >> Instead, use the constant expression emission system.
> >>
> >> This fixes PR24256.
> >>
> >> Modified:
> >>     cfe/trunk/lib/CodeGen/CGBuiltin.cpp
> >>     cfe/trunk/test/CodeGen/integer-overflow.c
> >>
> >> Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
> >> URL: http://llvm.org/viewvc/llvm-
> >> project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=243206&r1=243205&r2=243
> >> 206&view=diff
> >> =======================================================================
> >> =======
> >> --- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
> >> +++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Sat Jul 25 00:57:24 2015
> >> @@ -866,14 +866,14 @@ RValue CodeGenFunction::EmitBuiltinExpr(
> >>                                        llvm::ConstantInt::get(Int32Ty,
> >> Offset)));
> >>    }
> >>    case Builtin::BI__builtin_return_address: {
> >> -    Value *Depth = EmitScalarExpr(E->getArg(0));
> >> -    Depth = Builder.CreateIntCast(Depth, Int32Ty, false);
> >> +    Value *Depth =
> >> +        CGM.EmitConstantExpr(E->getArg(0), getContext().UnsignedIntTy,
> >> + this);
> >>      Value *F = CGM.getIntrinsic(Intrinsic::returnaddress);
> >>      return RValue::get(Builder.CreateCall(F, Depth));
> >>    }
> >>    case Builtin::BI__builtin_frame_address: {
> >> -    Value *Depth = EmitScalarExpr(E->getArg(0));
> >> -    Depth = Builder.CreateIntCast(Depth, Int32Ty, false);
> >> +    Value *Depth =
> >> +        CGM.EmitConstantExpr(E->getArg(0), getContext().UnsignedIntTy,
> >> + this);
> >>      Value *F = CGM.getIntrinsic(Intrinsic::frameaddress);
> >>      return RValue::get(Builder.CreateCall(F, Depth));
> >>    }
> >>
> >> Modified: cfe/trunk/test/CodeGen/integer-overflow.c
> >> URL: http://llvm.org/viewvc/llvm-
> >> project/cfe/trunk/test/CodeGen/integer-
> >> overflow.c?rev=243206&r1=243205&r2=243206&view=diff
> >> =======================================================================
> >> =======
> >> --- cfe/trunk/test/CodeGen/integer-overflow.c (original)
> >> +++ cfe/trunk/test/CodeGen/integer-overflow.c Sat Jul 25 00:57:24 2015
> >> @@ -72,4 +72,11 @@ void test1() {
> >>    // TRAPV: add i8 {{.*}}, 1
> >>    // CATCH_UB: add i8 {{.*}}, 1
> >>    ++PR9350;
> >> +
> >> +  // PR24256: don't instrument __builtin_frame_address.
> >> +  __builtin_frame_address(0 + 0);
> >> +  // DEFAULT:  call i8* @llvm.frameaddress(i32 0)
> >> +  // WRAPV:    call i8* @llvm.frameaddress(i32 0)
> >> +  // TRAPV:    call i8* @llvm.frameaddress(i32 0)
> >> +  // CATCH_UB: call i8* @llvm.frameaddress(i32 0)
> >>  }
> >>
> >>
> >> _______________________________________________
> >> cfe-commits mailing list
> >> cfe-commits at cs.uiuc.edu
> >> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150729/ad9a3e42/attachment.html>


More information about the cfe-commits mailing list