diff mbox

[MPX,2/X] Pointers Checker [2/25] Builtins

Message ID 20131021114918.GB37888@msticlxl57.ims.intel.com
State New
Headers show

Commit Message

Ilya Enkovich Oct. 21, 2013, 11:49 a.m. UTC
Hi,

This patch introduces built-in functions used by Pointers Checker and flag to enable Pointers Checker. Builtins available for user are expanded in expand_builtin. All other builtins are not allowed in expand until generic version of Pointers Cheker is implemented.

Bootstrapped and tested on linux-x86_64.

Thanks,
Ilya
--

gcc/

2013-10-04  Ilya Enkovich  <ilya.enkovich@intel.com>

	* builtin-types.def (BT_FN_VOID_CONST_PTR): New.
	(BT_FN_PTR_CONST_PTR): New.
	(BT_FN_CONST_PTR_CONST_PTR): New.
	(BT_FN_PTR_CONST_PTR_SIZE): New.
	(BT_FN_PTR_CONST_PTR_CONST_PTR): New.
	(BT_FN_VOID_PTRPTR_CONST_PTR): New.
	(BT_FN_VOID_CONST_PTR_SIZE): New.
	(BT_FN_PTR_CONST_PTR_CONST_PTR_SIZE): New.
	* chkp-builtins.def: New.
	* builtins.def: include chkp-builtins.def.
	(DEF_CHKP_BUILTIN): New.
	* builtins.c (expand_builtin): Support BUILT_IN_CHKP_INIT_PTR_BOUNDS,
	BUILT_IN_CHKP_NULL_PTR_BOUNDS, BUILT_IN_CHKP_COPY_PTR_BOUNDS,
	BUILT_IN_CHKP_CHECK_PTR_LBOUNDS, BUILT_IN_CHKP_CHECK_PTR_UBOUNDS,
	BUILT_IN_CHKP_CHECK_PTR_BOUNDS, BUILT_IN_CHKP_SET_PTR_BOUNDS,
	BUILT_IN_CHKP_NARROW_PTR_BOUNDS, BUILT_IN_CHKP_STORE_PTR_BOUNDS,
	BUILT_IN_CHKP_GET_PTR_LBOUND, BUILT_IN_CHKP_GET_PTR_UBOUND,
	BUILT_IN_CHKP_BNDMK, BUILT_IN_CHKP_BNDSTX, BUILT_IN_CHKP_BNDCL,
	BUILT_IN_CHKP_BNDCU, BUILT_IN_CHKP_BNDLDX, BUILT_IN_CHKP_BNDRET,
	BUILT_IN_CHKP_INTERSECT, BUILT_IN_CHKP_ARG_BND, BUILT_IN_CHKP_NARROW,
	BUILT_IN_CHKP_EXTRACT_LOWER, BUILT_IN_CHKP_EXTRACT_UPPER.
	* common.opt (fcheck-pointers): New.
	* toplev.c (process_options): Check Pointers Checker is supported.
	* doc/extend.texi: Document Pointers Checker built-in functions.

Comments

Joseph Myers Oct. 21, 2013, 12:08 p.m. UTC | #1
On Mon, 21 Oct 2013, Ilya Enkovich wrote:

> +  if (flag_check_pointers)
> +    {
> +      if (flag_lto)
> +	sorry ("Pointers checker is not yet fully supported for link-time optimization");

That sounds wrong.  It suggests some bug somewhere in your patch series 
failing to allow for LTO, which should be fixed.  At least give a more 
detailed explanation in a comment of what would need to change to remove 
this call to sorry ().

> +      if (targetm.chkp_bound_mode () == VOIDmode)
> +	error ("-fcheck-pointers is not supported for this target.");

Also note GNU Coding Standards for diagnostics.  They should not start 
with uppercase letters or end with ".".
Ilya Enkovich Oct. 21, 2013, 3:11 p.m. UTC | #2
On 21 Oct 12:08, Joseph S. Myers wrote:
> On Mon, 21 Oct 2013, Ilya Enkovich wrote:
> 
> > +  if (flag_check_pointers)
> > +    {
> > +      if (flag_lto)
> > +	sorry ("Pointers checker is not yet fully supported for link-time optimization");
> 
> That sounds wrong.  It suggests some bug somewhere in your patch series 
> failing to allow for LTO, which should be fixed.  At least give a more 
> detailed explanation in a comment of what would need to change to remove 
> this call to sorry ().

It has been a while since I saw problem with LTO (some functions appeared to miss instrumentation; it seemed compilation flags for checker were not handled correctly for some reason).  When I made this branch public I put this guard to prevent users from falling into this problem.  Actually I do not know what is the current status of that issue.  A lot of things has changed including checker flags definition.  I'll try mpx testsuite with LTO and be back with the result.

> 
> > +      if (targetm.chkp_bound_mode () == VOIDmode)
> > +	error ("-fcheck-pointers is not supported for this target.");
> 
> Also note GNU Coding Standards for diagnostics.  They should not start 
> with uppercase letters or end with ".".

Thanks for input! I'll fix it.

Thanks,
Ilya

> 
> -- 
> Joseph S. Myers
> joseph@codesourcery.com
Jeff Law Oct. 23, 2013, 9:41 p.m. UTC | #3
On 10/21/13 05:49, Ilya Enkovich wrote:
> Hi,
>
> This patch introduces built-in functions used by Pointers Checker and flag to enable Pointers Checker. Builtins available for user are expanded in expand_builtin. All other builtins are not allowed in expand until generic version of Pointers Cheker is implemented.
>
> Bootstrapped and tested on linux-x86_64.
>
> Thanks,
> Ilya
> --
>
> gcc/
>
> 2013-10-04  Ilya Enkovich  <ilya.enkovich@intel.com>
>
> 	* builtin-types.def (BT_FN_VOID_CONST_PTR): New.
> 	(BT_FN_PTR_CONST_PTR): New.
> 	(BT_FN_CONST_PTR_CONST_PTR): New.
> 	(BT_FN_PTR_CONST_PTR_SIZE): New.
> 	(BT_FN_PTR_CONST_PTR_CONST_PTR): New.
> 	(BT_FN_VOID_PTRPTR_CONST_PTR): New.
> 	(BT_FN_VOID_CONST_PTR_SIZE): New.
> 	(BT_FN_PTR_CONST_PTR_CONST_PTR_SIZE): New.
> 	* chkp-builtins.def: New.
> 	* builtins.def: include chkp-builtins.def.
> 	(DEF_CHKP_BUILTIN): New.
> 	* builtins.c (expand_builtin): Support BUILT_IN_CHKP_INIT_PTR_BOUNDS,
> 	BUILT_IN_CHKP_NULL_PTR_BOUNDS, BUILT_IN_CHKP_COPY_PTR_BOUNDS,
> 	BUILT_IN_CHKP_CHECK_PTR_LBOUNDS, BUILT_IN_CHKP_CHECK_PTR_UBOUNDS,
> 	BUILT_IN_CHKP_CHECK_PTR_BOUNDS, BUILT_IN_CHKP_SET_PTR_BOUNDS,
> 	BUILT_IN_CHKP_NARROW_PTR_BOUNDS, BUILT_IN_CHKP_STORE_PTR_BOUNDS,
> 	BUILT_IN_CHKP_GET_PTR_LBOUND, BUILT_IN_CHKP_GET_PTR_UBOUND,
> 	BUILT_IN_CHKP_BNDMK, BUILT_IN_CHKP_BNDSTX, BUILT_IN_CHKP_BNDCL,
> 	BUILT_IN_CHKP_BNDCU, BUILT_IN_CHKP_BNDLDX, BUILT_IN_CHKP_BNDRET,
> 	BUILT_IN_CHKP_INTERSECT, BUILT_IN_CHKP_ARG_BND, BUILT_IN_CHKP_NARROW,
> 	BUILT_IN_CHKP_EXTRACT_LOWER, BUILT_IN_CHKP_EXTRACT_UPPER.
> 	* common.opt (fcheck-pointers): New.
> 	* toplev.c (process_options): Check Pointers Checker is supported.
> 	* doc/extend.texi: Document Pointers Checker built-in functions.
Out of curiosity, did you consider and/or discuss with Richard whether 
or not to make these target-dependent or target-independent builtins?  I 
realize it's a bit problematic with Richard being involved during the 
NDA portion and someone else during the review/integration portion, but 
that's unfortunately where we are.

I don't think we've generally encouraged target-independent builtins 
which are only implemented on one target, though I can see the 
possibility that these may need enough support code in gimple and beyond 
that they may need to be target-independent.

I also find myself wondering if mudflap can/should be reimplemented on 
top of these hooks (or perhaps we should remove it, I'm not aware of 
anyone using it in the real world).

Anyway, like with the first patch, I'm trying to get a sense of some 
design decisions as they're important for the review process.

Jeff
Richard Henderson Oct. 23, 2013, 10:31 p.m. UTC | #4
On 10/23/2013 02:41 PM, Jeff Law wrote:
> Out of curiosity, did you consider and/or discuss with Richard whether or not
> to make these target-dependent or target-independent builtins?  I realize it's
> a bit problematic with Richard being involved during the NDA portion and
> someone else during the review/integration portion, but that's unfortunately
> where we are.

I suggested that they be target independent.

I suggested that there was nothing in MPX that couldn't be
done generically, if slower, on non-MPX hardware.

E.g. there's no reason why bounds couldn't be packed into a
double-word integer, and the checking builtins completely
outlined into a runtime library.

I suggested that the optimization done on the bound type
would help a generic mudflap replacement.


r~
Ilya Enkovich Oct. 24, 2013, 8:36 a.m. UTC | #5
2013/10/24 Richard Henderson <rth@redhat.com>:
> On 10/23/2013 02:41 PM, Jeff Law wrote:
>> Out of curiosity, did you consider and/or discuss with Richard whether or not
>> to make these target-dependent or target-independent builtins?  I realize it's
>> a bit problematic with Richard being involved during the NDA portion and
>> someone else during the review/integration portion, but that's unfortunately
>> where we are.
>
> I suggested that they be target independent.
>
> I suggested that there was nothing in MPX that couldn't be
> done generically, if slower, on non-MPX hardware.
>
> E.g. there's no reason why bounds couldn't be packed into a
> double-word integer, and the checking builtins completely
> outlined into a runtime library.
>
> I suggested that the optimization done on the bound type
> would help a generic mudflap replacement.

Right. The design implies generic support of Pointers Checker without
MPX support on hardware. This series does not include generic support.
We are currently examining priority of this task. Suppose generic
support of Pointers Checker may replace Mudflap. Do not know yet if
Pointers Checker may borrow some stuff from Mudflap.

Ilya

>
>
> r~
Jeff Law Oct. 24, 2013, 6:18 p.m. UTC | #6
On 10/23/13 16:31, Richard Henderson wrote:
> On 10/23/2013 02:41 PM, Jeff Law wrote:
>> Out of curiosity, did you consider and/or discuss with Richard whether or not
>> to make these target-dependent or target-independent builtins?  I realize it's
>> a bit problematic with Richard being involved during the NDA portion and
>> someone else during the review/integration portion, but that's unfortunately
>> where we are.
>
> I suggested that they be target independent.
>
> I suggested that there was nothing in MPX that couldn't be
> done generically, if slower, on non-MPX hardware.
The primary concern is that while we have some builtins that are 
disabled for a subset of targets, I think this is the first significant 
class of builtins that are only available on a single target.

It's a bit of a slippery slope as we clearly don't want to move to a 
model were we're regularly allowing classes of builtins that are only 
implemented for a single target.

What saves the say with this stuff is from what I can gather (and which 
you've confirmed), someone ought to be able to build a pointer bounds 
checking implementation on top of this w/o using MPX hardware.

Ironically removal of mudflap came up in a different thread yesterday :-)

Jeff
Jeff Law Oct. 25, 2013, 5:23 a.m. UTC | #7
On 10/24/13 02:36, Ilya Enkovich wrote:
> 2013/10/24 Richard Henderson <rth@redhat.com>:
>> On 10/23/2013 02:41 PM, Jeff Law wrote:
>>> Out of curiosity, did you consider and/or discuss with Richard whether or not
>>> to make these target-dependent or target-independent builtins?  I realize it's
>>> a bit problematic with Richard being involved during the NDA portion and
>>> someone else during the review/integration portion, but that's unfortunately
>>> where we are.
>>
>> I suggested that they be target independent.
>>
>> I suggested that there was nothing in MPX that couldn't be
>> done generically, if slower, on non-MPX hardware.
>>
>> E.g. there's no reason why bounds couldn't be packed into a
>> double-word integer, and the checking builtins completely
>> outlined into a runtime library.
>>
>> I suggested that the optimization done on the bound type
>> would help a generic mudflap replacement.
>
> Right. The design implies generic support of Pointers Checker without
> MPX support on hardware. This series does not include generic support.
> We are currently examining priority of this task. Suppose generic
> support of Pointers Checker may replace Mudflap. Do not know yet if
> Pointers Checker may borrow some stuff from Mudflap.
OK.  Thanks for the clarifications.

jeff
Jeff Law Oct. 25, 2013, 5:30 a.m. UTC | #8
On 10/21/13 05:49, Ilya Enkovich wrote:
> Hi,
>
> This patch introduces built-in functions used by Pointers Checker and flag to enable Pointers Checker. Builtins available for user are expanded in expand_builtin. All other builtins are not allowed in expand until generic version of Pointers Cheker is implemented.
>
> Bootstrapped and tested on linux-x86_64.
>
> Thanks,
> Ilya
> --
>
> gcc/
>
> 2013-10-04  Ilya Enkovich  <ilya.enkovich@intel.com>
>
> 	* builtin-types.def (BT_FN_VOID_CONST_PTR): New.
> 	(BT_FN_PTR_CONST_PTR): New.
> 	(BT_FN_CONST_PTR_CONST_PTR): New.
> 	(BT_FN_PTR_CONST_PTR_SIZE): New.
> 	(BT_FN_PTR_CONST_PTR_CONST_PTR): New.
> 	(BT_FN_VOID_PTRPTR_CONST_PTR): New.
> 	(BT_FN_VOID_CONST_PTR_SIZE): New.
> 	(BT_FN_PTR_CONST_PTR_CONST_PTR_SIZE): New.
> 	* chkp-builtins.def: New.
> 	* builtins.def: include chkp-builtins.def.
> 	(DEF_CHKP_BUILTIN): New.
> 	* builtins.c (expand_builtin): Support BUILT_IN_CHKP_INIT_PTR_BOUNDS,
> 	BUILT_IN_CHKP_NULL_PTR_BOUNDS, BUILT_IN_CHKP_COPY_PTR_BOUNDS,
> 	BUILT_IN_CHKP_CHECK_PTR_LBOUNDS, BUILT_IN_CHKP_CHECK_PTR_UBOUNDS,
> 	BUILT_IN_CHKP_CHECK_PTR_BOUNDS, BUILT_IN_CHKP_SET_PTR_BOUNDS,
> 	BUILT_IN_CHKP_NARROW_PTR_BOUNDS, BUILT_IN_CHKP_STORE_PTR_BOUNDS,
> 	BUILT_IN_CHKP_GET_PTR_LBOUND, BUILT_IN_CHKP_GET_PTR_UBOUND,
> 	BUILT_IN_CHKP_BNDMK, BUILT_IN_CHKP_BNDSTX, BUILT_IN_CHKP_BNDCL,
> 	BUILT_IN_CHKP_BNDCU, BUILT_IN_CHKP_BNDLDX, BUILT_IN_CHKP_BNDRET,
> 	BUILT_IN_CHKP_INTERSECT, BUILT_IN_CHKP_ARG_BND, BUILT_IN_CHKP_NARROW,
> 	BUILT_IN_CHKP_EXTRACT_LOWER, BUILT_IN_CHKP_EXTRACT_UPPER.
> 	* common.opt (fcheck-pointers): New.
> 	* toplev.c (process_options): Check Pointers Checker is supported.
> 	* doc/extend.texi: Document Pointers Checker built-in functions.
Just a few minor comments.

> --- a/gcc/common.opt
> +++ b/gcc/common.opt
> @@ -874,6 +874,11 @@ fbounds-check
>   Common Report Var(flag_bounds_check)
>   Generate code to check bounds before indexing arrays
>
> +fcheck-pointers
> +Common Report Var(flag_check_pointers)
> +Add pointers checker instrumentation.  fchkp-* flags are used to
> +control instrumentation.  Currently available for C, C++ and ObjC.
> +
I'd probably use "pointer bounds checking" rather than "pointers 
checker".  It's a nit, but most folks have heard the term "pointer 
bounds checking", but few probabaly use "pointers checker".

I think you make several references to "pointers checker" that are 
probably best reworded slightly to use "pointer bounds checker"


> diff --git a/gcc/toplev.c b/gcc/toplev.c
> index feba051..285b36d 100644
> --- a/gcc/toplev.c
> +++ b/gcc/toplev.c
> @@ -1290,6 +1290,18 @@ process_options (void)
>     if (flag_mudflap && flag_lto)
>       sorry ("mudflap cannot be used together with link-time optimization");
>
> +  if (flag_check_pointers)
> +    {
> +      if (flag_lto)
> +	sorry ("Pointers checker is not yet fully supported for link-time optimization");
What was the final resolution of this?  Like jsm, this seems to me to be 
papering over a problem elsewhere.

I'll pre-approve this patch with the terminology change and the flag_lto 
hack removed.

jeff
Ilya Enkovich Oct. 25, 2013, 5:57 p.m. UTC | #9
2013/10/25 Jeff Law <law@redhat.com>:
> On 10/21/13 05:49, Ilya Enkovich wrote:
>>
>> Hi,
>>
>> This patch introduces built-in functions used by Pointers Checker and flag
>> to enable Pointers Checker. Builtins available for user are expanded in
>> expand_builtin. All other builtins are not allowed in expand until generic
>> version of Pointers Cheker is implemented.
>>
>> Bootstrapped and tested on linux-x86_64.
>>
>> Thanks,
>> Ilya
>> --
>>
>> gcc/
>>
>> 2013-10-04  Ilya Enkovich  <ilya.enkovich@intel.com>
>>
>>         * builtin-types.def (BT_FN_VOID_CONST_PTR): New.
>>         (BT_FN_PTR_CONST_PTR): New.
>>         (BT_FN_CONST_PTR_CONST_PTR): New.
>>         (BT_FN_PTR_CONST_PTR_SIZE): New.
>>         (BT_FN_PTR_CONST_PTR_CONST_PTR): New.
>>         (BT_FN_VOID_PTRPTR_CONST_PTR): New.
>>         (BT_FN_VOID_CONST_PTR_SIZE): New.
>>         (BT_FN_PTR_CONST_PTR_CONST_PTR_SIZE): New.
>>         * chkp-builtins.def: New.
>>         * builtins.def: include chkp-builtins.def.
>>         (DEF_CHKP_BUILTIN): New.
>>         * builtins.c (expand_builtin): Support
>> BUILT_IN_CHKP_INIT_PTR_BOUNDS,
>>         BUILT_IN_CHKP_NULL_PTR_BOUNDS, BUILT_IN_CHKP_COPY_PTR_BOUNDS,
>>         BUILT_IN_CHKP_CHECK_PTR_LBOUNDS, BUILT_IN_CHKP_CHECK_PTR_UBOUNDS,
>>         BUILT_IN_CHKP_CHECK_PTR_BOUNDS, BUILT_IN_CHKP_SET_PTR_BOUNDS,
>>         BUILT_IN_CHKP_NARROW_PTR_BOUNDS, BUILT_IN_CHKP_STORE_PTR_BOUNDS,
>>         BUILT_IN_CHKP_GET_PTR_LBOUND, BUILT_IN_CHKP_GET_PTR_UBOUND,
>>         BUILT_IN_CHKP_BNDMK, BUILT_IN_CHKP_BNDSTX, BUILT_IN_CHKP_BNDCL,
>>         BUILT_IN_CHKP_BNDCU, BUILT_IN_CHKP_BNDLDX, BUILT_IN_CHKP_BNDRET,
>>         BUILT_IN_CHKP_INTERSECT, BUILT_IN_CHKP_ARG_BND,
>> BUILT_IN_CHKP_NARROW,
>>         BUILT_IN_CHKP_EXTRACT_LOWER, BUILT_IN_CHKP_EXTRACT_UPPER.
>>         * common.opt (fcheck-pointers): New.
>>         * toplev.c (process_options): Check Pointers Checker is supported.
>>         * doc/extend.texi: Document Pointers Checker built-in functions.
>
> Just a few minor comments.
>
>
>> --- a/gcc/common.opt
>> +++ b/gcc/common.opt
>> @@ -874,6 +874,11 @@ fbounds-check
>>   Common Report Var(flag_bounds_check)
>>   Generate code to check bounds before indexing arrays
>>
>> +fcheck-pointers
>> +Common Report Var(flag_check_pointers)
>> +Add pointers checker instrumentation.  fchkp-* flags are used to
>> +control instrumentation.  Currently available for C, C++ and ObjC.
>> +
>
> I'd probably use "pointer bounds checking" rather than "pointers checker".
> It's a nit, but most folks have heard the term "pointer bounds checking",
> but few probabaly use "pointers checker".
>
> I think you make several references to "pointers checker" that are probably
> best reworded slightly to use "pointer bounds checker"
>
>
>
>> diff --git a/gcc/toplev.c b/gcc/toplev.c
>> index feba051..285b36d 100644
>> --- a/gcc/toplev.c
>> +++ b/gcc/toplev.c
>> @@ -1290,6 +1290,18 @@ process_options (void)
>>     if (flag_mudflap && flag_lto)
>>       sorry ("mudflap cannot be used together with link-time
>> optimization");
>>
>> +  if (flag_check_pointers)
>> +    {
>> +      if (flag_lto)
>> +       sorry ("Pointers checker is not yet fully supported for link-time
>> optimization");
>
> What was the final resolution of this?  Like jsm, this seems to me to be
> papering over a problem elsewhere.
>
> I'll pre-approve this patch with the terminology change and the flag_lto
> hack removed.
>
> jeff
>

There are currently two known issues with LTO. The first one is ICE in
LTO streamer when it reads instrumented code. The second one is
unitialized flag_check_pointers when code is compiled by lto1 (do you
know why it may happen BTW?). It also causes ICE beacause instrumented
code is met when not expected. Of course, I'll fix these problems
anyway, but I was going to allow '-fcheck-pointers -flto' only when
checker testsuite has 100% pass rate with lto.

Ilya
Jeff Law Oct. 28, 2013, 9:21 p.m. UTC | #10
On 10/25/13 11:57, Ilya Enkovich wrote:

>
> There are currently two known issues with LTO. The first one is ICE in
> LTO streamer when it reads instrumented code. The second one is
> unitialized flag_check_pointers when code is compiled by lto1 (do you
> know why it may happen BTW?). It also causes ICE beacause instrumented
> code is met when not expected. Of course, I'll fix these problems
> anyway, but I was going to allow '-fcheck-pointers -flto' only when
> checker testsuite has 100% pass rate with lto.
No idea about why LTO would be failing in this way -- my experience with 
LTO is virtually nil.

I'm OK with the restriction as a temporary measure.  But we really 
dislike this kidn of stuff, so I need a commitment from you to dive into 
these problems and sort out what's really going on.


>
> Ilya
>
Richard Biener Oct. 29, 2013, 10:17 a.m. UTC | #11
On Mon, Oct 28, 2013 at 10:21 PM, Jeff Law <law@redhat.com> wrote:
> On 10/25/13 11:57, Ilya Enkovich wrote:
>
>>
>> There are currently two known issues with LTO. The first one is ICE in
>> LTO streamer when it reads instrumented code. The second one is
>> unitialized flag_check_pointers when code is compiled by lto1 (do you
>> know why it may happen BTW?). It also causes ICE beacause instrumented
>> code is met when not expected. Of course, I'll fix these problems
>> anyway, but I was going to allow '-fcheck-pointers -flto' only when
>> checker testsuite has 100% pass rate with lto.
>
> No idea about why LTO would be failing in this way -- my experience with LTO
> is virtually nil.
>
> I'm OK with the restriction as a temporary measure.  But we really dislike
> this kidn of stuff, so I need a commitment from you to dive into these
> problems and sort out what's really going on.

I'm not ok with adding such arbitrary restrictions.  LTO support should
be trivial.

Richard.

>
>>
>> Ilya
>>
>
Jeff Law Oct. 29, 2013, 12:59 p.m. UTC | #12
On 10/29/13 04:17, Richard Biener wrote:
> On Mon, Oct 28, 2013 at 10:21 PM, Jeff Law <law@redhat.com> wrote:
>> On 10/25/13 11:57, Ilya Enkovich wrote:
>>
>>>
>>> There are currently two known issues with LTO. The first one is ICE in
>>> LTO streamer when it reads instrumented code. The second one is
>>> unitialized flag_check_pointers when code is compiled by lto1 (do you
>>> know why it may happen BTW?). It also causes ICE beacause instrumented
>>> code is met when not expected. Of course, I'll fix these problems
>>> anyway, but I was going to allow '-fcheck-pointers -flto' only when
>>> checker testsuite has 100% pass rate with lto.
>>
>> No idea about why LTO would be failing in this way -- my experience with LTO
>> is virtually nil.
>>
>> I'm OK with the restriction as a temporary measure.  But we really dislike
>> this kidn of stuff, so I need a commitment from you to dive into these
>> problems and sort out what's really going on.
>
> I'm not ok with adding such arbitrary restrictions.  LTO support should
> be trivial.
In  that case, Ilya, you've got to resolve the LTO issues before this 
can move forward.

jeff
diff mbox

Patch

diff --git a/gcc/builtin-types.def b/gcc/builtin-types.def
index 2634ecc..c6c5e5c 100644
--- a/gcc/builtin-types.def
+++ b/gcc/builtin-types.def
@@ -224,12 +224,15 @@  DEF_FUNCTION_TYPE_1 (BT_FN_DFLOAT64_DFLOAT64, BT_DFLOAT64, BT_DFLOAT64)
 DEF_FUNCTION_TYPE_1 (BT_FN_DFLOAT128_DFLOAT128, BT_DFLOAT128, BT_DFLOAT128)
 DEF_FUNCTION_TYPE_1 (BT_FN_VOID_VPTR, BT_VOID, BT_VOLATILE_PTR)
 DEF_FUNCTION_TYPE_1 (BT_FN_VOID_PTRPTR, BT_VOID, BT_PTR_PTR)
+DEF_FUNCTION_TYPE_1 (BT_FN_VOID_CONST_PTR, BT_VOID, BT_CONST_PTR)
 DEF_FUNCTION_TYPE_1 (BT_FN_UINT_UINT, BT_UINT, BT_UINT)
 DEF_FUNCTION_TYPE_1 (BT_FN_ULONG_ULONG, BT_ULONG, BT_ULONG)
 DEF_FUNCTION_TYPE_1 (BT_FN_ULONGLONG_ULONGLONG, BT_ULONGLONG, BT_ULONGLONG)
 DEF_FUNCTION_TYPE_1 (BT_FN_UINT16_UINT16, BT_UINT16, BT_UINT16)
 DEF_FUNCTION_TYPE_1 (BT_FN_UINT32_UINT32, BT_UINT32, BT_UINT32)
 DEF_FUNCTION_TYPE_1 (BT_FN_UINT64_UINT64, BT_UINT64, BT_UINT64)
+DEF_FUNCTION_TYPE_1 (BT_FN_PTR_CONST_PTR, BT_PTR, BT_CONST_PTR)
+DEF_FUNCTION_TYPE_1 (BT_FN_CONST_PTR_CONST_PTR, BT_CONST_PTR, BT_CONST_PTR)
 
 DEF_POINTER_TYPE (BT_PTR_FN_VOID_PTR, BT_FN_VOID_PTR)
 
@@ -341,6 +344,10 @@  DEF_FUNCTION_TYPE_2 (BT_FN_VOID_VPTR_INT, BT_VOID, BT_VOLATILE_PTR, BT_INT)
 DEF_FUNCTION_TYPE_2 (BT_FN_BOOL_VPTR_INT, BT_BOOL, BT_VOLATILE_PTR, BT_INT)
 DEF_FUNCTION_TYPE_2 (BT_FN_BOOL_SIZE_CONST_VPTR, BT_BOOL, BT_SIZE,
 		     BT_CONST_VOLATILE_PTR)
+DEF_FUNCTION_TYPE_2 (BT_FN_PTR_CONST_PTR_SIZE, BT_PTR, BT_CONST_PTR, BT_SIZE)
+DEF_FUNCTION_TYPE_2 (BT_FN_PTR_CONST_PTR_CONST_PTR, BT_PTR, BT_CONST_PTR, BT_CONST_PTR)
+DEF_FUNCTION_TYPE_2 (BT_FN_VOID_PTRPTR_CONST_PTR, BT_VOID, BT_PTR_PTR, BT_CONST_PTR)
+DEF_FUNCTION_TYPE_2 (BT_FN_VOID_CONST_PTR_SIZE, BT_VOID, BT_CONST_PTR, BT_SIZE)
 
 DEF_POINTER_TYPE (BT_PTR_FN_VOID_PTR_PTR, BT_FN_VOID_PTR_PTR)
 
@@ -425,6 +432,7 @@  DEF_FUNCTION_TYPE_3 (BT_FN_VOID_VPTR_I2_INT, BT_VOID, BT_VOLATILE_PTR, BT_I2, BT
 DEF_FUNCTION_TYPE_3 (BT_FN_VOID_VPTR_I4_INT, BT_VOID, BT_VOLATILE_PTR, BT_I4, BT_INT)
 DEF_FUNCTION_TYPE_3 (BT_FN_VOID_VPTR_I8_INT, BT_VOID, BT_VOLATILE_PTR, BT_I8, BT_INT)
 DEF_FUNCTION_TYPE_3 (BT_FN_VOID_VPTR_I16_INT, BT_VOID, BT_VOLATILE_PTR, BT_I16, BT_INT)
+DEF_FUNCTION_TYPE_3 (BT_FN_PTR_CONST_PTR_CONST_PTR_SIZE, BT_PTR, BT_CONST_PTR, BT_CONST_PTR, BT_SIZE)
 
 DEF_FUNCTION_TYPE_4 (BT_FN_SIZE_CONST_PTR_SIZE_SIZE_FILEPTR,
 		     BT_SIZE, BT_CONST_PTR, BT_SIZE, BT_SIZE, BT_FILEPTR)
diff --git a/gcc/builtins.c b/gcc/builtins.c
index 3b16d59..b8dec3f 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -5861,7 +5861,18 @@  expand_builtin (tree exp, rtx target, rtx subtarget, enum machine_mode mode,
       && fcode != BUILT_IN_EXECVE
       && fcode != BUILT_IN_ALLOCA
       && fcode != BUILT_IN_ALLOCA_WITH_ALIGN
-      && fcode != BUILT_IN_FREE)
+      && fcode != BUILT_IN_FREE
+      && fcode != BUILT_IN_CHKP_SET_PTR_BOUNDS
+      && fcode != BUILT_IN_CHKP_INIT_PTR_BOUNDS
+      && fcode != BUILT_IN_CHKP_NULL_PTR_BOUNDS
+      && fcode != BUILT_IN_CHKP_COPY_PTR_BOUNDS
+      && fcode != BUILT_IN_CHKP_NARROW_PTR_BOUNDS
+      && fcode != BUILT_IN_CHKP_STORE_PTR_BOUNDS
+      && fcode != BUILT_IN_CHKP_CHECK_PTR_LBOUNDS
+      && fcode != BUILT_IN_CHKP_CHECK_PTR_UBOUNDS
+      && fcode != BUILT_IN_CHKP_CHECK_PTR_BOUNDS
+      && fcode != BUILT_IN_CHKP_GET_PTR_LBOUND
+      && fcode != BUILT_IN_CHKP_GET_PTR_UBOUND)
     return expand_call (exp, target, ignore);
 
   /* The built-in function expanders test for target == const0_rtx
@@ -6905,6 +6916,50 @@  expand_builtin (tree exp, rtx target, rtx subtarget, enum machine_mode mode,
       expand_builtin_set_thread_pointer (exp);
       return const0_rtx;
 
+    case BUILT_IN_CHKP_INIT_PTR_BOUNDS:
+    case BUILT_IN_CHKP_NULL_PTR_BOUNDS:
+    case BUILT_IN_CHKP_COPY_PTR_BOUNDS:
+      return expand_normal (CALL_EXPR_ARG (exp, 0));
+
+    case BUILT_IN_CHKP_CHECK_PTR_LBOUNDS:
+    case BUILT_IN_CHKP_CHECK_PTR_UBOUNDS:
+    case BUILT_IN_CHKP_CHECK_PTR_BOUNDS:
+    case BUILT_IN_CHKP_SET_PTR_BOUNDS:
+    case BUILT_IN_CHKP_NARROW_PTR_BOUNDS:
+    case BUILT_IN_CHKP_STORE_PTR_BOUNDS:
+    case BUILT_IN_CHKP_GET_PTR_LBOUND:
+    case BUILT_IN_CHKP_GET_PTR_UBOUND:
+      /* We allow user CHKP builtins if checker is off.  */
+      if (!flag_check_pointers)
+	{
+	  if (fcode == BUILT_IN_CHKP_SET_PTR_BOUNDS
+	      || fcode == BUILT_IN_CHKP_NARROW_PTR_BOUNDS)
+	    return expand_normal (CALL_EXPR_ARG (exp, 0));
+	  else if (fcode == BUILT_IN_CHKP_GET_PTR_LBOUND)
+	    return expand_normal (size_zero_node);
+	  else if (fcode == BUILT_IN_CHKP_GET_PTR_UBOUND)
+	    return expand_normal (size_int (-1));
+	  else
+	    return const0_rtx;
+	}
+      /* FALLTHROUGH */
+
+    case BUILT_IN_CHKP_BNDMK:
+    case BUILT_IN_CHKP_BNDSTX:
+    case BUILT_IN_CHKP_BNDCL:
+    case BUILT_IN_CHKP_BNDCU:
+    case BUILT_IN_CHKP_BNDLDX:
+    case BUILT_IN_CHKP_BNDRET:
+    case BUILT_IN_CHKP_INTERSECT:
+    case BUILT_IN_CHKP_ARG_BND:
+    case BUILT_IN_CHKP_NARROW:
+    case BUILT_IN_CHKP_EXTRACT_LOWER:
+    case BUILT_IN_CHKP_EXTRACT_UPPER:
+      /* Software implementation of pointers checker is NYI.
+	 Target support is required.  */
+      error ("Your target platform does not support -fcheck-pointers");
+      break;
+
     default:	/* just do library call, if unknown builtin */
       break;
     }
diff --git a/gcc/builtins.def b/gcc/builtins.def
index 8ccf3ae..0150d85 100644
--- a/gcc/builtins.def
+++ b/gcc/builtins.def
@@ -169,6 +169,12 @@  along with GCC; see the file COPYING3.  If not see
   DEF_BUILTIN (ENUM, NAME, BUILT_IN_NORMAL, BT_FN_INT_VAR, BT_LAST, \
   	       false, false, false, ATTRS, false, flag_enable_cilkplus) 
 
+/* Builtin used by the implementation of pointers checker.  */
+#undef DEF_CHKP_BUILTIN
+#define DEF_CHKP_BUILTIN(ENUM, NAME, TYPE, ATTRS) \
+  DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE,    \
+	       true, true, false, ATTRS, true, true)
+
 /* Define an attribute list for math functions that are normally
    "impure" because some of them may write into global memory for
    `errno'.  If !flag_errno_math they are instead "const".  */
@@ -854,3 +860,6 @@  DEF_GCC_BUILTIN (BUILT_IN_LINE, "LINE", BT_FN_INT, ATTR_NOTHROW_LEAF_LIST)
 
 /* Cilk Plus builtins.  */
 #include "cilkplus.def"
+
+/* Pointers checker builtins.  */
+#include "chkp-builtins.def"
diff --git a/gcc/chkp-builtins.def b/gcc/chkp-builtins.def
new file mode 100644
index 0000000..82c9243
--- /dev/null
+++ b/gcc/chkp-builtins.def
@@ -0,0 +1,72 @@ 
+/* This file contains the definitions and documentation for the
+   builtins used in the GNU compiler.
+   Copyright (C) 2013 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+/* Before including this file, you should define macros:
+
+      DEF_BUILTIN_STUB(ENUM, NAME)
+      DEF_CHKP_BUILTIN(ENUM, NAME, TYPE, ATTRS)
+
+   See builtins.def for details.  */
+
+/* Following builtins are used by compiler for pointers checker
+   instrumentation.  Currently these generic builtins are not
+   inplemented and target has to provide his own version.  */
+DEF_BUILTIN_STUB (BUILT_IN_CHKP_BNDMK, "__chkp_bndmk")
+DEF_BUILTIN_STUB (BUILT_IN_CHKP_BNDSTX, "__chkp_bndstx")
+DEF_BUILTIN_STUB (BUILT_IN_CHKP_BNDCL, "__chkp_bndcl")
+DEF_BUILTIN_STUB (BUILT_IN_CHKP_BNDCU, "__chkp_bndcu")
+DEF_BUILTIN_STUB (BUILT_IN_CHKP_BNDLDX, "__chkp_bndldx")
+DEF_BUILTIN_STUB (BUILT_IN_CHKP_BNDRET, "__chkp_bndret")
+DEF_BUILTIN_STUB (BUILT_IN_CHKP_INTERSECT, "__chkp_intersect")
+DEF_BUILTIN_STUB (BUILT_IN_CHKP_ARG_BND, "__chkp_arg_bnd")
+DEF_BUILTIN_STUB (BUILT_IN_CHKP_SIZEOF, "__chkp_sizeof")
+DEF_BUILTIN_STUB (BUILT_IN_CHKP_EXTRACT_LOWER, "__chkp_extract_lower")
+DEF_BUILTIN_STUB (BUILT_IN_CHKP_EXTRACT_UPPER, "__chkp_extract_upper")
+DEF_BUILTIN_STUB (BUILT_IN_CHKP_NARROW, "__chkp_narrow")
+
+/* Pointers checker builtins for users.  Only
+   BUILT_IN_CHKP_SET_PTR_BOUNDS may be redefined
+   by target.  Other builtins calls are expanded
+   in the pointers checker pass.  */
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_SET_PTR_BOUNDS, "__bnd_set_ptr_bounds", BT_FN_PTR_CONST_PTR_SIZE, ATTR_CONST_NOTHROW_LEAF_LIST)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_INIT_PTR_BOUNDS, "__bnd_init_ptr_bounds", BT_FN_PTR_CONST_PTR, ATTR_CONST_NOTHROW_LEAF_LIST)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_NULL_PTR_BOUNDS, "__bnd_null_ptr_bounds", BT_FN_PTR_CONST_PTR, ATTR_CONST_NOTHROW_LEAF_LIST)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_COPY_PTR_BOUNDS, "__bnd_copy_ptr_bounds", BT_FN_PTR_CONST_PTR_CONST_PTR, ATTR_CONST_NOTHROW_LEAF_LIST)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_NARROW_PTR_BOUNDS, "__bnd_narrow_ptr_bounds", BT_FN_PTR_CONST_PTR_CONST_PTR_SIZE, ATTR_CONST_NOTHROW_LEAF_LIST)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_STORE_PTR_BOUNDS, "__bnd_store_ptr_bounds", BT_FN_VOID_PTRPTR_CONST_PTR, ATTR_NOTHROW_LEAF_LIST)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_CHECK_PTR_LBOUNDS, "__bnd_chk_ptr_lbounds", BT_FN_VOID_CONST_PTR, ATTR_NOTHROW_LEAF_LIST)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_CHECK_PTR_UBOUNDS, "__bnd_chk_ptr_ubounds", BT_FN_VOID_CONST_PTR, ATTR_NOTHROW_LEAF_LIST)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_CHECK_PTR_BOUNDS, "__bnd_chk_ptr_bounds", BT_FN_VOID_CONST_PTR_SIZE, ATTR_NOTHROW_LEAF_LIST)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_GET_PTR_LBOUND, "__bnd_get_ptr_lbound", BT_FN_CONST_PTR_CONST_PTR, ATTR_CONST_NOTHROW_LEAF_LIST)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_GET_PTR_UBOUND, "__bnd_get_ptr_ubound", BT_FN_CONST_PTR_CONST_PTR, ATTR_CONST_NOTHROW_LEAF_LIST)
+
+/* Pointers checker specific versions of string functions.  */
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_MEMCPY_NOBND, "chkp_memcpy_nobnd", BT_FN_PTR_PTR_CONST_PTR_SIZE, ATTR_RET1_NOTHROW_NONNULL_LEAF)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_MEMCPY_NOCHK, "chkp_memcpy_nochk", BT_FN_PTR_PTR_CONST_PTR_SIZE, ATTR_RET1_NOTHROW_NONNULL_LEAF)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_MEMCPY_NOBND_NOCHK, "chkp_memcpy_nobnd_nochk", BT_FN_PTR_PTR_CONST_PTR_SIZE, ATTR_RET1_NOTHROW_NONNULL_LEAF)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_MEMMOVE_NOBND, "chkp_memmove_nobnd", BT_FN_PTR_PTR_CONST_PTR_SIZE, ATTR_RET1_NOTHROW_NONNULL_LEAF)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_MEMMOVE_NOCHK, "chkp_memmove_nochk", BT_FN_PTR_PTR_CONST_PTR_SIZE, ATTR_RET1_NOTHROW_NONNULL_LEAF)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_MEMMOVE_NOBND_NOCHK, "chkp_memmove_nobnd_nochk", BT_FN_PTR_PTR_CONST_PTR_SIZE, ATTR_RET1_NOTHROW_NONNULL_LEAF)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_MEMPCPY_NOBND, "chkp_mempcpy_nobnd", BT_FN_PTR_PTR_CONST_PTR_SIZE, ATTR_NOTHROW_NONNULL_LEAF)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_MEMPCPY_NOCHK, "chkp_mempcpy_nochk", BT_FN_PTR_PTR_CONST_PTR_SIZE, ATTR_NOTHROW_NONNULL_LEAF)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_MEMPCPY_NOBND_NOCHK, "chkp_mempcpy_nobnd_nochk", BT_FN_PTR_PTR_CONST_PTR_SIZE, ATTR_NOTHROW_NONNULL_LEAF)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_MEMSET_NOBND, "chkp_memset_nobnd", BT_FN_PTR_PTR_INT_SIZE, ATTR_RET1_NOTHROW_NONNULL_LEAF)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_MEMSET_NOCHK, "chkp_memset_nochk", BT_FN_PTR_PTR_INT_SIZE, ATTR_RET1_NOTHROW_NONNULL_LEAF)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_MEMSET_NOBND_NOCHK, "chkp_memset_nobnd_nochk", BT_FN_PTR_PTR_INT_SIZE, ATTR_RET1_NOTHROW_NONNULL_LEAF)
diff --git a/gcc/common.opt b/gcc/common.opt
index c2b3d35..4e91b8d 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -874,6 +874,11 @@  fbounds-check
 Common Report Var(flag_bounds_check)
 Generate code to check bounds before indexing arrays
 
+fcheck-pointers
+Common Report Var(flag_check_pointers)
+Add pointers checker instrumentation.  fchkp-* flags are used to
+control instrumentation.  Currently available for C, C++ and ObjC.
+
 fbranch-count-reg
 Common Report Var(flag_branch_on_count_reg) Init(1) Optimization
 Replace add, compare, branch with branch on count register
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index edf0e28..ef422ad 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -82,6 +82,7 @@  extensions, accepted by GCC in C90 mode and in C++.
 * x86 specific memory model extensions for transactional memory:: x86 memory models.
 * Object Size Checking:: Built-in functions for limited buffer overflow
                         checking.
+* Pointers Checker builtins:: Built-in functions for Pointers Checker.
 * Cilk Plus Builtins::  Built-in functions for the Cilk Plus language extension.
 * Other Builtins::      Other built-in functions.
 * Target Builtins::     Built-in functions specific to particular targets.
@@ -7711,6 +7712,173 @@  format string @var{fmt}.  If the compiler is able to optimize them to
 @code{fputc} etc.@: functions, it does, otherwise the checking function
 is called and the @var{flag} argument passed to it.
 
+@node Pointers Checker builtins
+@section Pointers Checker Built-in Functions
+@findex __builtin___bnd_set_ptr_bounds
+@findex __builtin___bnd_narrow_ptr_bounds
+@findex __builtin___bnd_copy_ptr_bounds
+@findex __builtin___bnd_init_ptr_bounds
+@findex __builtin___bnd_null_ptr_bounds
+@findex __builtin___bnd_store_ptr_bounds
+@findex __builtin___bnd_chk_ptr_lbounds
+@findex __builtin___bnd_chk_ptr_ubounds
+@findex __builtin___bnd_chk_ptr_bounds
+@findex __builtin___bnd_get_ptr_lbound
+@findex __builtin___bnd_get_ptr_ubound
+
+GCC provides a set of built-in functions to control Pointers Checker
+instrumentation.  Note that all Pointers Checker builtins are allowed
+to use even if you compile with Pointers Checker off.  But functions
+behavior may differ in such case.
+
+@deftypefn {Built-in Function} void * __builtin___bnd_set_ptr_bounds (const void * @var{q}, size_t @var{size})
+
+This built-in function returns a new pointer with the value of @var{q}, and
+associate it with the bounds [@var{q}, @var{q}+@var{size}-1].  With Pointers
+Checker off built-in function just returns the first argument.
+
+@smallexample
+extern void *__wrap_malloc (size_t n)
+@{
+  void *p = (void *)__real_malloc (n);
+  if (!p) return __builtin___bnd_null_ptr_bounds (p);
+  return __builtin___bnd_set_ptr_bounds (p, n);
+@}
+@end smallexample
+
+@end deftypefn
+
+@deftypefn {Built-in Function} void * __builtin___bnd_narrow_ptr_bounds (const void * @var{p}, const void * @var{q}, size_t  @var{size})
+
+This built-in function returns a new pointer with the value of @var{p}
+and associate it with the narrowed bounds formed by the intersection
+of bounds associated with @var{q} and the [@var{p}, @var{p} + @var{size} - 1].
+With Pointers Checker off built-in function just returns the first argument.
+
+@smallexample
+void init_objects (object *objs, size_t size)
+@{
+  size_t i;
+  /* Initialize objects one-by-one passing pointers with bounds of an object,
+     not the full array of objects.  */
+  for (i = 0; i < size; i++)
+    init_object (__builtin___bnd_narrow_ptr_bounds (objs + i, objs, sizeof(object)));
+@}
+@end smallexample
+
+@end deftypefn
+
+@deftypefn {Built-in Function} void * __builtin___bnd_copy_ptr_bounds (const void * @var{q}, const void * @var{r})
+
+This built-in function returns a new pointer with the value of @var{q},
+and associate it with the bounds already associated with pointer @var{r}.
+With Pointers Checker off built-in function just returns the first argument.
+
+@smallexample
+/* Here is a way to get pointer to object's field but
+   still with the full object's bounds.  */
+int *field_ptr = __builtin___bnd_copy_ptr_bounds (&objptr->int_filed, objptr);
+@end smallexample
+
+@end deftypefn
+
+@deftypefn {Built-in Function} void * __builtin___bnd_init_ptr_bounds (const void * @var{q})
+
+This built-in function returns a new pointer with the value of @var{q}, and
+associate it with INIT (allowing full memory access) bounds. With Pointers
+Checker off built-in function just returns the first argument.
+
+@end deftypefn
+
+@deftypefn {Built-in Function} void * __builtin___bnd_null_ptr_bounds (const void * @var{q})
+
+This built-in function returns a new pointer with the value of @var{q}, and
+associate it with NULL (allowing no memory access) bounds. With Pointers
+Checker off built-in function just returns the first argument.
+
+@end deftypefn
+
+@deftypefn {Built-in Function} void __builtin___bnd_store_ptr_bounds (const void ** @var{ptr_addr}, const void * @var{ptr_val})
+
+This built-in function stores the bounds associated with pointer @var{ptr_val}
+and location @var{ptr_addr} into Bounds Table.  This can be useful to propagate
+bounds from legacy code without touching the associated pointer's memory when
+pointers were copied as integers.  With Pointers Checker off built-in function
+call is ignored.
+
+@end deftypefn
+
+@deftypefn {Built-in Function} void __builtin___bnd_chk_ptr_lbounds (const void * @var{q})
+
+This built-in function checks if the pointer @var{q} is within the lower
+bound of its associated bounds.  With Pointers Checker off built-in function
+call is ignored.
+
+@smallexample
+extern void *__wrap_memset (void *dst, int c, size_t len)
+@{
+  if (len > 0)
+    @{
+      __builtin___bnd_chk_ptr_lbounds (dst);
+      __builtin___bnd_chk_ptr_ubounds ((char *)dst + len - 1);
+      __real_memset (dst, c, len);
+    @}
+  return dst;
+@}
+@end smallexample
+
+@end deftypefn
+
+@deftypefn {Built-in Function} void __builtin___bnd_chk_ptr_ubounds (const void * @var{q})
+
+This built-in function checks if the pointer @var{q} is within the upper
+bound of its associated bounds.  With Pointers Checker off built-in function
+call is ignored.
+
+@end deftypefn
+
+@deftypefn {Built-in Function} void __builtin___bnd_chk_ptr_bounds (const void * @var{q}, size_t @var{size})
+
+This built-in function checks if [@var{q}, @var{q} + @var{size} - 1] is within
+the lower and upper bounds associated with @var{q}.  With Pointers Checker off
+built-in function call is ignored.
+
+@smallexample
+extern void *__wrap_memcpy (void *dst, const void *src, size_t n)
+@{
+  if (n > 0)
+    @{
+      __bnd_chk_ptr_bounds (dst, n);
+      __bnd_chk_ptr_bounds (src, n);
+      __real_memcpy (dst, src, n);
+    @}
+  return dst;
+@}
+@end smallexample
+
+@end deftypefn
+
+@deftypefn {Built-in Function} const void * __builtin___bnd_get_ptr_lbound (const void * @var{q})
+
+This built-in function returns the lower bound (which is a pointer) associated
+with the pointer @var{q}.  This is at least useful for debugging using printf.
+With Pointers Checker off built-in function returns 0.
+
+@smallexample
+void *lb = __builtin___bnd_get_ptr_lbound (q);
+void *ub = __builtin___bnd_get_ptr_ubound (q);
+printf ("q = %p  lb(q) = %p  ub(q) = %p", q, lb, ub);
+@end smallexample
+
+@end deftypefn
+
+@deftypefn {Built-in Function} const void * __builtin___bnd_get_ptr_ubound (const void * @var{q})
+
+This built-in function returns the upper bound (which is a pointer) associated
+with the pointer @var{q}.  With Pointers Checker off built-in function returns -1.
+
+@end deftypefn
+
 @node Other Builtins
 @section Other Built-in Functions Provided by GCC
 @cindex built-in functions
diff --git a/gcc/toplev.c b/gcc/toplev.c
index feba051..285b36d 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -1290,6 +1290,18 @@  process_options (void)
   if (flag_mudflap && flag_lto)
     sorry ("mudflap cannot be used together with link-time optimization");
 
+  if (flag_check_pointers)
+    {
+      if (flag_lto)
+	sorry ("Pointers checker is not yet fully supported for link-time optimization");
+
+      if (targetm.chkp_bound_mode () == VOIDmode)
+	error ("-fcheck-pointers is not supported for this target.");
+
+      if (!lang_hooks.chkp_supported)
+	flag_check_pointers = 0;
+    }
+
   /* One region RA really helps to decrease the code size.  */
   if (flag_ira_region == IRA_REGION_AUTODETECT)
     flag_ira_region