1 /* Pass to detect and issue warnings for violations of the restrict
3 Copyright (C) 2017-2020 Free Software Foundation, Inc.
4 Contributed by Martin Sebor <msebor@redhat.com>.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
24 #include "coretypes.h"
29 #include "tree-pass.h"
32 #include "gimple-pretty-print.h"
33 #include "gimple-ssa-warn-restrict.h"
34 #include "diagnostic-core.h"
35 #include "fold-const.h"
36 #include "gimple-iterator.h"
40 #include "tree-object-size.h"
47 const pass_data pass_data_wrestrict
= {
52 PROP_cfg
, /* Properties_required. */
53 0, /* properties_provided. */
54 0, /* properties_destroyed. */
55 0, /* properties_start */
56 0, /* properties_finish */
59 /* Pass to detect violations of strict aliasing requirements in calls
60 to built-in string and raw memory functions. */
61 class pass_wrestrict
: public gimple_opt_pass
64 pass_wrestrict (gcc::context
*ctxt
)
65 : gimple_opt_pass (pass_data_wrestrict
, ctxt
)
68 opt_pass
*clone () { return new pass_wrestrict (m_ctxt
); }
70 virtual bool gate (function
*);
71 virtual unsigned int execute (function
*);
75 pass_wrestrict::gate (function
*fun ATTRIBUTE_UNUSED
)
77 return warn_array_bounds
|| warn_restrict
|| warn_stringop_overflow
;
80 /* Class to walk the basic blocks of a function in dominator order. */
81 class wrestrict_dom_walker
: public dom_walker
84 wrestrict_dom_walker () : dom_walker (CDI_DOMINATORS
) {}
86 edge
before_dom_children (basic_block
) FINAL OVERRIDE
;
87 bool handle_gimple_call (gimple_stmt_iterator
*);
90 void check_call (gimple
*);
94 wrestrict_dom_walker::before_dom_children (basic_block bb
)
96 /* Iterate over statements, looking for function calls. */
97 for (gimple_stmt_iterator si
= gsi_start_bb (bb
); !gsi_end_p (si
);
100 gimple
*stmt
= gsi_stmt (si
);
101 if (!is_gimple_call (stmt
))
110 /* Execute the pass for function FUN, walking in dominator order. */
113 pass_wrestrict::execute (function
*fun
)
115 calculate_dominance_info (CDI_DOMINATORS
);
117 wrestrict_dom_walker walker
;
118 walker
.walk (ENTRY_BLOCK_PTR_FOR_FN (fun
));
123 /* Description of a memory reference by a built-in function. This
124 is similar to ao_ref but made especially suitable for -Wrestrict
125 and not for optimization. */
129 /* The original pointer argument to the built-in function. */
131 /* The referenced subobject or NULL if not available, and the base
132 object of the memory reference or NULL. */
136 /* The size of the BASE object, PTRDIFF_MAX if indeterminate,
137 and negative until (possibly lazily) initialized. */
139 /* Same for the subobject. */
142 /* The non-negative offset of the referenced subobject. Used to avoid
143 warnings for (apparently) possibly but not definitively overlapping
144 accesses to member arrays. Negative when unknown/invalid. */
147 /* The offset range relative to the base. */
148 offset_int offrange
[2];
149 /* The size range of the access to this reference. */
150 offset_int sizrange
[2];
152 /* Cached result of get_max_objsize(). */
153 const offset_int maxobjsize
;
155 /* True for "bounded" string functions like strncat, and strncpy
156 and their variants that specify either an exact or upper bound
157 on the size of the accesses they perform. For strncat both
158 the source and destination references are bounded. For strncpy
159 only the destination reference is. */
162 builtin_memref (tree
, tree
);
164 tree
offset_out_of_bounds (int, offset_int
[3]) const;
168 /* Ctor helper to set or extend OFFRANGE based on argument. */
169 void extend_offset_range (tree
);
171 /* Ctor helper to determine BASE and OFFRANGE from argument. */
172 void set_base_and_offset (tree
);
175 /* Description of a memory access by a raw memory or string built-in
176 function involving a pair of builtin_memref's. */
180 /* Destination and source memory reference. */
181 builtin_memref
* const dstref
;
182 builtin_memref
* const srcref
;
183 /* The size range of the access. It's the greater of the accesses
184 to the two references. */
185 HOST_WIDE_INT sizrange
[2];
187 /* The minimum and maximum offset of an overlap of the access
188 (if it does, in fact, overlap), and the size of the overlap. */
189 HOST_WIDE_INT ovloff
[2];
190 HOST_WIDE_INT ovlsiz
[2];
192 /* True to consider valid only accesses to the smallest subobject
193 and false for raw memory functions. */
196 return (detect_overlap
!= &builtin_access::generic_overlap
197 && detect_overlap
!= &builtin_access::no_overlap
);
200 builtin_access (gimple
*, builtin_memref
&, builtin_memref
&);
202 /* Entry point to determine overlap. */
205 offset_int
write_off (tree
) const;
207 void dump (FILE *) const;
210 /* Implementation functions used to determine overlap. */
211 bool generic_overlap ();
212 bool strcat_overlap ();
213 bool strcpy_overlap ();
220 offset_int
overlap_size (const offset_int
[2], const offset_int
[2],
224 /* Temporaries used to compute the final result. */
225 offset_int dstoff
[2];
226 offset_int srcoff
[2];
227 offset_int dstsiz
[2];
228 offset_int srcsiz
[2];
230 /* Pointer to a member function to call to determine overlap. */
231 bool (builtin_access::*detect_overlap
) ();
234 /* Initialize a memory reference representation from a pointer EXPR and
235 a size SIZE in bytes. If SIZE is NULL_TREE then the size is assumed
238 builtin_memref::builtin_memref (tree expr
, tree size
)
244 refoff (HOST_WIDE_INT_MIN
),
247 maxobjsize (tree_to_shwi (max_object_size ())),
250 /* Unfortunately, wide_int default ctor is a no-op so array members
251 of the type must be set individually. */
252 offrange
[0] = offrange
[1] = 0;
253 sizrange
[0] = sizrange
[1] = 0;
258 /* Find the BASE object or pointer referenced by EXPR and set
259 the offset range OFFRANGE in the process. */
260 set_base_and_offset (expr
);
265 /* Determine the size range, allowing for the result to be [0, 0]
266 for SIZE in the anti-range ~[0, N] where N >= PTRDIFF_MAX. */
267 get_size_range (size
, range
, true);
268 sizrange
[0] = wi::to_offset (range
[0]);
269 sizrange
[1] = wi::to_offset (range
[1]);
270 /* get_size_range returns SIZE_MAX for the maximum size.
271 Constrain it to the real maximum of PTRDIFF_MAX. */
272 if (sizrange
[0] <= maxobjsize
&& sizrange
[1] > maxobjsize
)
273 sizrange
[1] = maxobjsize
;
276 sizrange
[1] = maxobjsize
;
281 /* If the offset could be in the range of the referenced object
282 constrain its bounds so neither exceeds those of the object. */
283 if (offrange
[0] < 0 && offrange
[1] > 0)
286 offset_int maxoff
= maxobjsize
;
287 tree basetype
= TREE_TYPE (base
);
288 if (TREE_CODE (basetype
) == ARRAY_TYPE
)
290 if (ref
&& array_at_struct_end_p (ref
))
291 ; /* Use the maximum possible offset for last member arrays. */
292 else if (tree basesize
= TYPE_SIZE_UNIT (basetype
))
293 if (TREE_CODE (basesize
) == INTEGER_CST
)
294 /* Size could be non-constant for a variable-length type such
295 as a struct with a VLA member (a GCC extension). */
296 maxoff
= wi::to_offset (basesize
);
299 if (offrange
[0] >= 0)
302 offrange
[1] = offrange
[0] <= maxoff
? maxoff
: maxobjsize
;
303 else if (offrange
[0] <= maxoff
&& offrange
[1] > maxoff
)
304 offrange
[1] = maxoff
;
308 /* Based on the initial length of the destination STARTLEN, returns
309 the offset of the first write access from the beginning of
310 the destination. Nonzero only for strcat-type of calls. */
312 offset_int
builtin_access::write_off (tree startlen
) const
314 if (detect_overlap
!= &builtin_access::strcat_overlap
315 || !startlen
|| TREE_CODE (startlen
) != INTEGER_CST
)
318 return wi::to_offset (startlen
);
321 /* Ctor helper to set or extend OFFRANGE based on the OFFSET argument.
322 Pointer offsets are represented as unsigned sizetype but must be
323 treated as signed. */
326 builtin_memref::extend_offset_range (tree offset
)
328 if (TREE_CODE (offset
) == INTEGER_CST
)
330 offset_int off
= int_cst_value (offset
);
339 if (TREE_CODE (offset
) == SSA_NAME
)
341 /* A pointer offset is represented as sizetype but treated
344 value_range_kind rng
= get_range_info (offset
, &min
, &max
);
345 if (rng
== VR_ANTI_RANGE
&& wi::lts_p (max
, min
))
347 /* Convert an anti-range whose upper bound is less than
348 its lower bound to a signed range. */
349 offrange
[0] += offset_int::from (max
+ 1, SIGNED
);
350 offrange
[1] += offset_int::from (min
- 1, SIGNED
);
355 && (DECL_P (base
) || wi::lts_p (min
, max
)))
357 /* Preserve the bounds of the range for an offset into
358 a known object (it may be adjusted later relative to
359 a constant offset from its beginning). Otherwise use
360 the bounds only when they are ascending when treated
362 offrange
[0] += offset_int::from (min
, SIGNED
);
363 offrange
[1] += offset_int::from (max
, SIGNED
);
367 /* Handle an anti-range the same as no range at all. */
368 gimple
*stmt
= SSA_NAME_DEF_STMT (offset
);
370 if (is_gimple_assign (stmt
)
371 && (type
= TREE_TYPE (gimple_assign_rhs1 (stmt
)))
372 && INTEGRAL_TYPE_P (type
))
374 tree_code code
= gimple_assign_rhs_code (stmt
);
375 if (code
== NOP_EXPR
)
377 /* Use the bounds of the type of the NOP_EXPR operand
378 even if it's signed. The result doesn't trigger
379 warnings but makes their output more readable. */
380 offrange
[0] += wi::to_offset (TYPE_MIN_VALUE (type
));
381 offrange
[1] += wi::to_offset (TYPE_MAX_VALUE (type
));
387 const offset_int maxoff
= tree_to_shwi (max_object_size ()) >> 1;
388 const offset_int minoff
= -maxoff
- 1;
390 offrange
[0] += minoff
;
391 offrange
[1] += maxoff
;
394 /* Determines the base object or pointer of the reference EXPR
395 and the offset range from the beginning of the base. */
398 builtin_memref::set_base_and_offset (tree expr
)
400 tree offset
= NULL_TREE
;
402 if (TREE_CODE (expr
) == SSA_NAME
)
404 /* Try to tease the offset out of the pointer. */
405 gimple
*stmt
= SSA_NAME_DEF_STMT (expr
);
407 && gimple_assign_single_p (stmt
)
408 && gimple_assign_rhs_code (stmt
) == ADDR_EXPR
)
409 expr
= gimple_assign_rhs1 (stmt
);
410 else if (is_gimple_assign (stmt
))
412 tree_code code
= gimple_assign_rhs_code (stmt
);
413 if (code
== NOP_EXPR
)
415 tree rhs
= gimple_assign_rhs1 (stmt
);
416 if (POINTER_TYPE_P (TREE_TYPE (rhs
)))
417 expr
= gimple_assign_rhs1 (stmt
);
424 else if (code
== POINTER_PLUS_EXPR
)
426 expr
= gimple_assign_rhs1 (stmt
);
427 offset
= gimple_assign_rhs2 (stmt
);
437 /* FIXME: Handle PHI nodes in case like:
438 _12 = &MEM[(void *)&a + 2B] + _10;
440 <bb> [local count: 1073741824]:
441 # prephitmp_13 = PHI <_12, &MEM[(void *)&a + 2B]>
442 memcpy (prephitmp_13, p_7(D), 6); */
448 if (TREE_CODE (expr
) == ADDR_EXPR
)
449 expr
= TREE_OPERAND (expr
, 0);
451 /* Stash the reference for offset validation. */
454 poly_int64 bitsize
, bitpos
;
457 int sign
, reverse
, vol
;
459 /* Determine the base object or pointer of the reference and
460 the constant bit offset from the beginning of the base.
461 If the offset has a non-constant component, it will be in
462 VAR_OFF. MODE, SIGN, REVERSE, and VOL are write only and
464 base
= get_inner_reference (expr
, &bitsize
, &bitpos
, &var_off
,
465 &mode
, &sign
, &reverse
, &vol
);
467 /* get_inner_reference is not expected to return null. */
468 gcc_assert (base
!= NULL
);
471 extend_offset_range (offset
);
473 poly_int64 bytepos
= exact_div (bitpos
, BITS_PER_UNIT
);
475 /* Convert the poly_int64 offset to offset_int. The offset
476 should be constant but be prepared for it not to be just in
479 if (bytepos
.is_constant (&cstoff
))
481 offrange
[0] += cstoff
;
482 offrange
[1] += cstoff
;
484 /* Besides the reference saved above, also stash the offset
486 if (TREE_CODE (expr
) == COMPONENT_REF
)
490 offrange
[1] += maxobjsize
;
494 if (TREE_CODE (var_off
) == INTEGER_CST
)
496 cstoff
= wi::to_offset (var_off
);
497 offrange
[0] += cstoff
;
498 offrange
[1] += cstoff
;
501 offrange
[1] += maxobjsize
;
504 if (TREE_CODE (base
) == MEM_REF
)
506 tree memrefoff
= fold_convert (ptrdiff_type_node
, TREE_OPERAND (base
, 1));
507 extend_offset_range (memrefoff
);
508 base
= TREE_OPERAND (base
, 0);
510 if (refoff
!= HOST_WIDE_INT_MIN
511 && TREE_CODE (expr
) == COMPONENT_REF
)
513 /* Bump up the offset of the referenced subobject to reflect
514 the offset to the enclosing object. For example, so that
516 struct S { char a, b[3]; } s[2];
517 strcpy (s[1].b, "1234");
518 REFOFF is set to s[1].b - (char*)s. */
519 offset_int off
= tree_to_shwi (memrefoff
);
523 if (!integer_zerop (memrefoff
))
524 /* A non-zero offset into an array of struct with flexible array
525 members implies that the array is empty because there is no
526 way to initialize such a member when it belongs to an array.
527 This must be some sort of a bug. */
531 if (TREE_CODE (ref
) == COMPONENT_REF
)
532 if (tree size
= component_ref_size (ref
))
533 if (TREE_CODE (size
) == INTEGER_CST
)
534 refsize
= wi::to_offset (size
);
536 if (TREE_CODE (base
) == SSA_NAME
)
537 set_base_and_offset (base
);
540 /* Return error_mark_node if the signed offset exceeds the bounds
541 of the address space (PTRDIFF_MAX). Otherwise, return either BASE
542 or REF when the offset exceeds the bounds of the BASE or REF object,
543 and set OOBOFF to the past-the-end offset formed by the reference,
544 including its size. OOBOFF is initially setto the range of offsets,
545 and OOBOFF[2] to the offset of the first write access (nonzero for
546 the strcat family). When STRICT is nonzero use REF size, when
547 available, otherwise use BASE size. When STRICT is greater than 1,
548 use the size of the last array member as the bound, otherwise treat
549 such a member as a flexible array member. Return NULL when the offset
553 builtin_memref::offset_out_of_bounds (int strict
, offset_int ooboff
[3]) const
558 /* The offset of the first write access or zero. */
559 offset_int wroff
= ooboff
[2];
561 /* A temporary, possibly adjusted, copy of the offset range. */
562 offset_int offrng
[2] = { ooboff
[0], ooboff
[1] };
564 if (DECL_P (base
) && TREE_CODE (TREE_TYPE (base
)) == ARRAY_TYPE
)
566 /* Check for offset in an anti-range with a negative lower bound.
567 For such a range, consider only the non-negative subrange. */
568 if (offrng
[1] < offrng
[0] && offrng
[1] < 0)
569 offrng
[1] = maxobjsize
;
572 /* Conservative offset of the last byte of the referenced object. */
575 /* The bounds need not be ordered. Set HIB to use as the index
576 of the larger of the bounds and LOB as the opposite. */
577 bool hib
= wi::les_p (offrng
[0], offrng
[1]);
580 /* Set to the size remaining in the object after subtracting
581 REFOFF. It may become negative as a result of negative indices
582 into the enclosing object, such as in:
583 extern struct S { char a[4], b[3], c[1]; } *p;
584 strcpy (p[-3].b, "123"); */
585 offset_int size
= basesize
;
588 const bool decl_p
= DECL_P (obj
);
592 endoff
= offrng
[lob
] + (sizrange
[0] - wroff
);
594 /* For a reference through a pointer to an object of unknown size
595 all initial offsets are considered valid, positive as well as
596 negative, since the pointer itself can point past the beginning
597 of the object. However, the sum of the lower bound of the offset
598 and that of the size must be less than or equal than PTRDIFF_MAX. */
599 if (endoff
> maxobjsize
)
600 return error_mark_node
;
602 /* When the referenced subobject is known, the end offset must be
603 within its bounds. Otherwise there is nothing to do. */
608 && TREE_CODE (ref
) == COMPONENT_REF
)
610 /* If REFOFF is negative, SIZE will become negative here. */
611 size
= refoff
+ refsize
;
618 /* A reference to an object of known size must be within the bounds
619 of either the base object or the subobject (see above for when
620 a subobject can be used). */
621 if ((decl_p
&& offrng
[hib
] < 0) || offrng
[lob
] > size
)
624 /* The extent of the reference must also be within the bounds of
625 the base object (if known) or the subobject or the maximum object
627 endoff
= offrng
[lob
] + sizrange
[0];
628 if (endoff
> maxobjsize
)
629 return error_mark_node
;
635 && TREE_CODE (ref
) == COMPONENT_REF
)
637 /* If the reference is to a member subobject of a declared object,
638 the offset must be within the bounds of the subobject. */
639 size
= refoff
+ refsize
;
646 /* Set the out-of-bounds offset range to be one greater than
647 that delimited by the reference including its size. */
650 if (endoff
> ooboff
[lob
])
651 ooboff
[hib
] = endoff
- 1;
653 ooboff
[hib
] = offrng
[lob
] + sizrange
[1];
658 /* Create an association between the memory references DST and SRC
659 for access by a call EXPR to a memory or string built-in funtion. */
661 builtin_access::builtin_access (gimple
*call
, builtin_memref
&dst
,
663 : dstref (&dst
), srcref (&src
), sizrange (), ovloff (), ovlsiz (),
664 dstoff (), srcoff (), dstsiz (), srcsiz ()
666 dstoff
[0] = dst
.offrange
[0];
667 dstoff
[1] = dst
.offrange
[1];
669 /* Zero out since the offset_int ctors invoked above are no-op. */
670 srcoff
[0] = srcoff
[1] = 0;
671 dstsiz
[0] = dstsiz
[1] = 0;
672 srcsiz
[0] = srcsiz
[1] = 0;
674 /* Object Size Type to use to determine the size of the destination
675 and source objects. Overridden below for raw memory functions. */
678 /* True when the size of one reference depends on the offset of
679 itself or the other. */
680 bool depends_p
= true;
682 /* True when the size of the destination reference DSTREF has been
683 determined from SRCREF and so needs to be adjusted by the latter's
684 offset. Only meaningful for bounded string functions like strncpy. */
685 bool dstadjust_p
= false;
687 /* The size argument number (depends on the built-in). */
688 unsigned sizeargno
= 2;
690 tree func
= gimple_call_fndecl (call
);
691 switch (DECL_FUNCTION_CODE (func
))
693 case BUILT_IN_MEMCPY
:
694 case BUILT_IN_MEMCPY_CHK
:
695 case BUILT_IN_MEMPCPY
:
696 case BUILT_IN_MEMPCPY_CHK
:
699 detect_overlap
= &builtin_access::generic_overlap
;
702 case BUILT_IN_MEMMOVE
:
703 case BUILT_IN_MEMMOVE_CHK
:
704 /* For memmove there is never any overlap to check for. */
707 detect_overlap
= &builtin_access::no_overlap
;
710 case BUILT_IN_MEMSET
:
711 case BUILT_IN_MEMSET_CHK
:
712 /* For memset there is never any overlap to check for. */
715 detect_overlap
= &builtin_access::no_overlap
;
718 case BUILT_IN_STPNCPY
:
719 case BUILT_IN_STPNCPY_CHK
:
720 case BUILT_IN_STRNCPY
:
721 case BUILT_IN_STRNCPY_CHK
:
722 dstref
->strbounded_p
= true;
723 detect_overlap
= &builtin_access::strcpy_overlap
;
726 case BUILT_IN_STPCPY
:
727 case BUILT_IN_STPCPY_CHK
:
728 case BUILT_IN_STRCPY
:
729 case BUILT_IN_STRCPY_CHK
:
730 detect_overlap
= &builtin_access::strcpy_overlap
;
733 case BUILT_IN_STRCAT
:
734 case BUILT_IN_STRCAT_CHK
:
735 detect_overlap
= &builtin_access::strcat_overlap
;
738 case BUILT_IN_STRNCAT
:
739 case BUILT_IN_STRNCAT_CHK
:
740 dstref
->strbounded_p
= true;
741 srcref
->strbounded_p
= true;
742 detect_overlap
= &builtin_access::strcat_overlap
;
746 /* Handle other string functions here whose access may need
747 to be validated for in-bounds offsets and non-overlapping
752 const offset_int maxobjsize
= dst
.maxobjsize
;
754 /* Try to determine the size of the base object. compute_objsize
755 expects a pointer so create one if BASE is a non-pointer object. */
757 if (dst
.basesize
< 0)
760 if (!POINTER_TYPE_P (TREE_TYPE (addr
)))
761 addr
= build1 (ADDR_EXPR
, (TREE_TYPE (addr
)), addr
);
763 if (tree dstsize
= compute_objsize (addr
, ostype
))
764 dst
.basesize
= wi::to_offset (dstsize
);
765 else if (POINTER_TYPE_P (TREE_TYPE (addr
)))
766 dst
.basesize
= HOST_WIDE_INT_MIN
;
768 dst
.basesize
= maxobjsize
;
771 if (src
.base
&& src
.basesize
< 0)
774 if (!POINTER_TYPE_P (TREE_TYPE (addr
)))
775 addr
= build1 (ADDR_EXPR
, (TREE_TYPE (addr
)), addr
);
777 if (tree srcsize
= compute_objsize (addr
, ostype
))
778 src
.basesize
= wi::to_offset (srcsize
);
779 else if (POINTER_TYPE_P (TREE_TYPE (addr
)))
780 src
.basesize
= HOST_WIDE_INT_MIN
;
782 src
.basesize
= maxobjsize
;
785 /* Make adjustments for references to the same object by string
786 built-in functions to reflect the constraints imposed by
789 /* For bounded string functions determine the range of the bound
790 on the access. For others, the range stays unbounded. */
791 offset_int bounds
[2] = { maxobjsize
, maxobjsize
};
792 if (dstref
->strbounded_p
)
794 unsigned nargs
= gimple_call_num_args (call
);
795 if (nargs
<= sizeargno
)
798 tree size
= gimple_call_arg (call
, sizeargno
);
800 if (get_size_range (size
, range
, true))
802 bounds
[0] = wi::to_offset (range
[0]);
803 bounds
[1] = wi::to_offset (range
[1]);
806 /* If both references' size ranges are indeterminate use the last
807 (size) argument from the function call as a substitute. This
808 may only be necessary for strncpy (but not for memcpy where
809 the size range would have been already determined this way). */
810 if (dstref
->sizrange
[0] == 0 && dstref
->sizrange
[1] == maxobjsize
811 && srcref
->sizrange
[0] == 0 && srcref
->sizrange
[1] == maxobjsize
)
813 dstref
->sizrange
[0] = bounds
[0];
814 dstref
->sizrange
[1] = bounds
[1];
818 bool dstsize_set
= false;
819 /* The size range of one reference involving the same base object
820 can be determined from the size range of the other reference.
821 This makes it possible to compute accurate offsets for warnings
822 involving functions like strcpy where the length of just one of
823 the two arguments is known (determined by tree-ssa-strlen). */
824 if (dstref
->sizrange
[0] == 0 && dstref
->sizrange
[1] == maxobjsize
)
826 /* When the destination size is unknown set it to the size of
828 dstref
->sizrange
[0] = srcref
->sizrange
[0];
829 dstref
->sizrange
[1] = srcref
->sizrange
[1];
832 else if (srcref
->sizrange
[0] == 0 && srcref
->sizrange
[1] == maxobjsize
)
834 /* When the size of the source access is unknown set it to the size
835 of the destination first and adjust it later if necessary. */
836 srcref
->sizrange
[0] = dstref
->sizrange
[0];
837 srcref
->sizrange
[1] = dstref
->sizrange
[1];
841 if (dstref
->strbounded_p
)
843 /* Read access by strncpy is constrained by the third
844 argument but except for a zero bound is at least one. */
845 srcref
->sizrange
[0] = bounds
[1] > 0 ? 1 : 0;
846 offset_int bound
= wi::umin (srcref
->basesize
, bounds
[1]);
847 if (bound
< srcref
->sizrange
[1])
848 srcref
->sizrange
[1] = bound
;
850 /* For string functions, adjust the size range of the source
851 reference by the inverse boundaries of the offset (because
852 the higher the offset into the string the shorter its
854 if (srcref
->offrange
[1] >= 0
855 && srcref
->offrange
[1] < srcref
->sizrange
[0])
856 srcref
->sizrange
[0] -= srcref
->offrange
[1];
858 srcref
->sizrange
[0] = 1;
860 if (srcref
->offrange
[0] > 0)
862 if (srcref
->offrange
[0] < srcref
->sizrange
[1])
863 srcref
->sizrange
[1] -= srcref
->offrange
[0];
865 srcref
->sizrange
[1] = 0;
872 if (detect_overlap
== &builtin_access::generic_overlap
)
874 if (dstref
->strbounded_p
)
876 dstref
->sizrange
[0] = bounds
[0];
877 dstref
->sizrange
[1] = bounds
[1];
879 if (dstref
->sizrange
[0] < srcref
->sizrange
[0])
880 srcref
->sizrange
[0] = dstref
->sizrange
[0];
882 if (dstref
->sizrange
[1] < srcref
->sizrange
[1])
883 srcref
->sizrange
[1] = dstref
->sizrange
[1];
886 else if (detect_overlap
== &builtin_access::strcpy_overlap
)
888 if (!dstref
->strbounded_p
)
890 /* For strcpy, adjust the destination size range to match that
891 of the source computed above. */
892 if (depends_p
&& dstadjust_p
)
894 dstref
->sizrange
[0] = srcref
->sizrange
[0];
895 dstref
->sizrange
[1] = srcref
->sizrange
[1];
899 else if (!dstsize_set
&& detect_overlap
== &builtin_access::strcat_overlap
)
901 dstref
->sizrange
[0] += srcref
->sizrange
[0] - 1;
902 dstref
->sizrange
[1] += srcref
->sizrange
[1] - 1;
905 if (dstref
->strbounded_p
)
907 /* For strncpy, adjust the destination size range to match that
908 of the source computed above. */
909 dstref
->sizrange
[0] = bounds
[0];
910 dstref
->sizrange
[1] = bounds
[1];
912 if (bounds
[0] < srcref
->sizrange
[0])
913 srcref
->sizrange
[0] = bounds
[0];
915 if (bounds
[1] < srcref
->sizrange
[1])
916 srcref
->sizrange
[1] = bounds
[1];
921 builtin_access::overlap_size (const offset_int a
[2], const offset_int b
[2],
924 const offset_int
*p
= a
;
925 const offset_int
*q
= b
;
927 /* Point P at the bigger of the two ranges and Q at the smaller. */
928 if (wi::lts_p (a
[1] - a
[0], b
[1] - b
[0]))
940 return wi::smin (p
[1], q
[1]) - q
[0];
950 /* Return true if the bounded mempry (memcpy amd similar) or string function
951 access (strncpy and similar) ACS overlaps. */
954 builtin_access::generic_overlap ()
956 builtin_access
&acs
= *this;
957 const builtin_memref
*dstref
= acs
.dstref
;
958 const builtin_memref
*srcref
= acs
.srcref
;
960 gcc_assert (dstref
->base
== srcref
->base
);
962 const offset_int maxobjsize
= acs
.dstref
->maxobjsize
;
964 offset_int maxsize
= dstref
->basesize
< 0 ? maxobjsize
: dstref
->basesize
;
966 /* Adjust the larger bounds of the offsets (which may be the first
967 element if the lower bound is larger than the upper bound) to
968 make them valid for the smallest access (if possible) but no smaller
969 than the smaller bounds. */
970 gcc_assert (wi::les_p (acs
.dstoff
[0], acs
.dstoff
[1]));
972 if (maxsize
< acs
.dstoff
[1] + acs
.dstsiz
[0])
973 acs
.dstoff
[1] = maxsize
- acs
.dstsiz
[0];
974 if (acs
.dstoff
[1] < acs
.dstoff
[0])
975 acs
.dstoff
[1] = acs
.dstoff
[0];
977 gcc_assert (wi::les_p (acs
.srcoff
[0], acs
.srcoff
[1]));
979 if (maxsize
< acs
.srcoff
[1] + acs
.srcsiz
[0])
980 acs
.srcoff
[1] = maxsize
- acs
.srcsiz
[0];
981 if (acs
.srcoff
[1] < acs
.srcoff
[0])
982 acs
.srcoff
[1] = acs
.srcoff
[0];
984 /* Determine the minimum and maximum space for the access given
987 space
[0] = wi::abs (acs
.dstoff
[0] - acs
.srcoff
[0]);
990 offset_int d
= wi::abs (acs
.dstoff
[0] - acs
.srcoff
[1]);
991 if (acs
.srcsiz
[0] > 0)
1000 space
[1] = acs
.dstsiz
[1];
1002 d
= wi::abs (acs
.dstoff
[1] - acs
.srcoff
[0]);
1009 /* Treat raw memory functions both of whose references are bounded
1010 as special and permit uncertain overlaps to go undetected. For
1011 all kinds of constant offset and constant size accesses, if
1012 overlap isn't certain it is not possible. */
1013 bool overlap_possible
= space
[0] < acs
.dstsiz
[1];
1014 if (!overlap_possible
)
1017 bool overlap_certain
= space
[1] < acs
.dstsiz
[0];
1019 /* True when the size of one reference depends on the offset of
1021 bool depends_p
= detect_overlap
!= &builtin_access::generic_overlap
;
1023 if (!overlap_certain
)
1025 if (!dstref
->strbounded_p
&& !depends_p
)
1026 /* Memcpy only considers certain overlap. */
1029 /* There's no way to distinguish an access to the same member
1030 of a structure from one to two distinct members of the same
1031 structure. Give up to avoid excessive false positives. */
1032 tree basetype
= TREE_TYPE (dstref
->base
);
1034 if (POINTER_TYPE_P (basetype
))
1035 basetype
= TREE_TYPE (basetype
);
1037 while (TREE_CODE (basetype
) == ARRAY_TYPE
)
1038 basetype
= TREE_TYPE (basetype
);
1040 if (RECORD_OR_UNION_TYPE_P (basetype
))
1044 /* True for stpcpy and strcpy. */
1045 bool stxcpy_p
= (!dstref
->strbounded_p
1046 && detect_overlap
== &builtin_access::strcpy_overlap
);
1048 if (dstref
->refoff
>= 0
1049 && srcref
->refoff
>= 0
1050 && dstref
->refoff
!= srcref
->refoff
1051 && (stxcpy_p
|| dstref
->strbounded_p
|| srcref
->strbounded_p
))
1054 offset_int siz
[2] = { maxobjsize
+ 1, 0 };
1056 ovloff
[0] = HOST_WIDE_INT_MAX
;
1057 ovloff
[1] = HOST_WIDE_INT_MIN
;
1061 /* Iterate over the extreme locations (on the horizontal axis formed
1062 by their offsets) and sizes of two regions and find their smallest
1063 and largest overlap and the corresponding offsets. */
1064 for (unsigned i
= 0; i
!= 2; ++i
)
1066 const offset_int a
[2] = {
1067 acs
.dstoff
[i
], acs
.dstoff
[i
] + acs
.dstsiz
[!i
]
1070 const offset_int b
[2] = {
1071 acs
.srcoff
[i
], acs
.srcoff
[i
] + acs
.srcsiz
[!i
]
1075 offset_int sz
= overlap_size (a
, b
, &off
);
1084 if (wi::lts_p (off
, ovloff
[0]))
1085 ovloff
[0] = off
.to_shwi ();
1086 if (wi::lts_p (ovloff
[1], off
))
1087 ovloff
[1] = off
.to_shwi ();
1093 /* Iterate over the extreme locations (on the horizontal axis
1094 formed by their offsets) and sizes of the two regions and
1095 find their smallest and largest overlap and the corresponding
1098 for (unsigned io
= 0; io
!= 2; ++io
)
1099 for (unsigned is
= 0; is
!= 2; ++is
)
1101 const offset_int a
[2] = {
1102 acs
.dstoff
[io
], acs
.dstoff
[io
] + acs
.dstsiz
[is
]
1105 for (unsigned jo
= 0; jo
!= 2; ++jo
)
1106 for (unsigned js
= 0; js
!= 2; ++js
)
1108 const offset_int b
[2] = {
1109 acs
.srcoff
[jo
], acs
.srcoff
[jo
] + acs
.srcsiz
[js
]
1113 offset_int sz
= overlap_size (a
, b
, &off
);
1122 if (wi::lts_p (off
, ovloff
[0]))
1123 ovloff
[0] = off
.to_shwi ();
1124 if (wi::lts_p (ovloff
[1], off
))
1125 ovloff
[1] = off
.to_shwi ();
1131 ovlsiz
[0] = siz
[0].to_shwi ();
1132 ovlsiz
[1] = siz
[1].to_shwi ();
1134 /* Adjust the overlap offset range to reflect the overlap size range. */
1135 if (ovlsiz
[0] == 0 && ovlsiz
[1] > 1)
1136 ovloff
[1] = ovloff
[0] + ovlsiz
[1] - 1;
1141 /* Return true if the strcat-like access overlaps. */
1144 builtin_access::strcat_overlap ()
1146 builtin_access
&acs
= *this;
1147 const builtin_memref
*dstref
= acs
.dstref
;
1148 const builtin_memref
*srcref
= acs
.srcref
;
1150 gcc_assert (dstref
->base
== srcref
->base
);
1152 const offset_int maxobjsize
= acs
.dstref
->maxobjsize
;
1154 gcc_assert (dstref
->base
&& dstref
->base
== srcref
->base
);
1156 /* Adjust for strcat-like accesses. */
1158 /* As a special case for strcat, set the DSTREF offsets to the length
1159 of the destination string since the function starts writing over
1160 its terminating nul, and set the destination size to 1 for the length
1162 acs
.dstoff
[0] += dstsiz
[0] - srcref
->sizrange
[0];
1163 acs
.dstoff
[1] += dstsiz
[1] - srcref
->sizrange
[1];
1165 bool strfunc_unknown_args
= acs
.dstsiz
[0] == 0 && acs
.dstsiz
[1] != 0;
1167 /* The lower bound is zero when the size is unknown because then
1168 overlap is not certain. */
1169 acs
.dstsiz
[0] = strfunc_unknown_args
? 0 : 1;
1172 offset_int maxsize
= dstref
->basesize
< 0 ? maxobjsize
: dstref
->basesize
;
1174 /* For references to the same base object, determine if there's a pair
1175 of valid offsets into the two references such that access between
1176 them doesn't overlap. Adjust both upper bounds to be valid for
1177 the smaller size (i.e., at most MAXSIZE - SIZE). */
1179 if (maxsize
< acs
.dstoff
[1] + acs
.dstsiz
[0])
1180 acs
.dstoff
[1] = maxsize
- acs
.dstsiz
[0];
1182 if (maxsize
< acs
.srcoff
[1] + acs
.srcsiz
[0])
1183 acs
.srcoff
[1] = maxsize
- acs
.srcsiz
[0];
1185 /* Check to see if there's enough space for both accesses without
1186 overlap. Determine the optimistic (maximum) amount of available
1189 if (acs
.dstoff
[0] <= acs
.srcoff
[0])
1191 if (acs
.dstoff
[1] < acs
.srcoff
[1])
1192 space
= acs
.srcoff
[1] + acs
.srcsiz
[0] - acs
.dstoff
[0];
1194 space
= acs
.dstoff
[1] + acs
.dstsiz
[0] - acs
.srcoff
[0];
1197 space
= acs
.dstoff
[1] + acs
.dstsiz
[0] - acs
.srcoff
[0];
1199 /* Overlap is certain if the distance between the farthest offsets
1200 of the opposite accesses is less than the sum of the lower bounds
1201 of the sizes of the two accesses. */
1202 bool overlap_certain
= space
< acs
.dstsiz
[0] + acs
.srcsiz
[0];
1204 /* For a constant-offset, constant size access, consider the largest
1205 distance between the offset bounds and the lower bound of the access
1206 size. If the overlap isn't certain return success. */
1207 if (!overlap_certain
1208 && acs
.dstoff
[0] == acs
.dstoff
[1]
1209 && acs
.srcoff
[0] == acs
.srcoff
[1]
1210 && acs
.dstsiz
[0] == acs
.dstsiz
[1]
1211 && acs
.srcsiz
[0] == acs
.srcsiz
[1])
1214 /* Overlap is not certain but may be possible. */
1216 offset_int access_min
= acs
.dstsiz
[0] + acs
.srcsiz
[0];
1218 /* Determine the conservative (minimum) amount of space. */
1219 space
= wi::abs (acs
.dstoff
[0] - acs
.srcoff
[0]);
1220 offset_int d
= wi::abs (acs
.dstoff
[0] - acs
.srcoff
[1]);
1223 d
= wi::abs (acs
.dstoff
[1] - acs
.srcoff
[0]);
1227 /* For a strict test (used for strcpy and similar with unknown or
1228 variable bounds or sizes), consider the smallest distance between
1229 the offset bounds and either the upper bound of the access size
1230 if known, or the lower bound otherwise. */
1231 if (access_min
<= space
&& (access_min
!= 0 || !strfunc_unknown_args
))
1234 /* When strcat overlap is certain it is always a single byte:
1235 the terminating NUL, regardless of offsets and sizes. When
1236 overlap is only possible its range is [0, 1]. */
1237 acs
.ovlsiz
[0] = dstref
->sizrange
[0] == dstref
->sizrange
[1] ? 1 : 0;
1241 = dstref
->offrange
[0] + (dstref
->sizrange
[0] - srcref
->sizrange
[0]);
1242 if (endoff
<= srcref
->offrange
[0])
1243 acs
.ovloff
[0] = wi::smin (maxobjsize
, srcref
->offrange
[0]).to_shwi ();
1245 acs
.ovloff
[0] = wi::smin (maxobjsize
, endoff
).to_shwi ();
1247 acs
.sizrange
[0] = wi::smax (wi::abs (endoff
- srcref
->offrange
[0]) + 1,
1248 srcref
->sizrange
[0]).to_shwi ();
1249 if (dstref
->offrange
[0] == dstref
->offrange
[1])
1251 if (srcref
->offrange
[0] == srcref
->offrange
[1])
1252 acs
.ovloff
[1] = acs
.ovloff
[0];
1255 = wi::smin (maxobjsize
,
1256 srcref
->offrange
[1] + srcref
->sizrange
[1]).to_shwi ();
1260 = wi::smin (maxobjsize
,
1261 dstref
->offrange
[1] + dstref
->sizrange
[1]).to_shwi ();
1263 if (acs
.sizrange
[0] == 0)
1264 acs
.sizrange
[0] = 1;
1265 acs
.sizrange
[1] = wi::smax (acs
.dstsiz
[1], srcref
->sizrange
[1]).to_shwi ();
1269 /* Return true if the strcpy-like access overlaps. */
1272 builtin_access::strcpy_overlap ()
1274 return generic_overlap ();
1278 /* Return true if DSTREF and SRCREF describe accesses that either overlap
1279 one another or that, in order not to overlap, would imply that the size
1280 of the referenced object(s) exceeds the maximum size of an object. Set
1281 Otherwise, if DSTREF and SRCREF do not definitely overlap (even though
1282 they may overlap in a way that's not apparent from the available data),
1286 builtin_access::overlap ()
1288 builtin_access
&acs
= *this;
1290 const offset_int maxobjsize
= dstref
->maxobjsize
;
1292 acs
.sizrange
[0] = wi::smax (dstref
->sizrange
[0],
1293 srcref
->sizrange
[0]).to_shwi ();
1294 acs
.sizrange
[1] = wi::smax (dstref
->sizrange
[1],
1295 srcref
->sizrange
[1]).to_shwi ();
1297 /* Check to see if the two references refer to regions that are
1298 too large not to overlap in the address space (whose maximum
1299 size is PTRDIFF_MAX). */
1300 offset_int size
= dstref
->sizrange
[0] + srcref
->sizrange
[0];
1301 if (maxobjsize
< size
)
1303 acs
.ovloff
[0] = (maxobjsize
- dstref
->sizrange
[0]).to_shwi ();
1304 acs
.ovlsiz
[0] = (size
- maxobjsize
).to_shwi ();
1308 /* If both base objects aren't known return the maximum possible
1309 offset that would make them not overlap. */
1310 if (!dstref
->base
|| !srcref
->base
)
1313 /* If the base object is an array adjust the bounds of the offset
1314 to be non-negative and within the bounds of the array if possible. */
1316 && TREE_CODE (TREE_TYPE (dstref
->base
)) == ARRAY_TYPE
)
1318 if (acs
.dstoff
[0] < 0 && acs
.dstoff
[1] >= 0)
1321 if (acs
.dstoff
[1] < acs
.dstoff
[0])
1323 if (tree size
= TYPE_SIZE_UNIT (TREE_TYPE (dstref
->base
)))
1324 acs
.dstoff
[1] = wi::umin (acs
.dstoff
[1], wi::to_offset (size
));
1326 acs
.dstoff
[1] = wi::umin (acs
.dstoff
[1], maxobjsize
);
1330 acs
.srcoff
[0] = srcref
->offrange
[0];
1331 acs
.srcoff
[1] = srcref
->offrange
[1];
1334 && TREE_CODE (TREE_TYPE (srcref
->base
)) == ARRAY_TYPE
)
1336 if (acs
.srcoff
[0] < 0 && acs
.srcoff
[1] >= 0)
1339 if (tree size
= TYPE_SIZE_UNIT (TREE_TYPE (srcref
->base
)))
1340 acs
.srcoff
[1] = wi::umin (acs
.srcoff
[1], wi::to_offset (size
));
1341 else if (acs
.srcoff
[1] < acs
.srcoff
[0])
1342 acs
.srcoff
[1] = wi::umin (acs
.srcoff
[1], maxobjsize
);
1345 /* When the upper bound of the offset is less than the lower bound
1346 the former is the result of a negative offset being represented
1347 as a large positive value or vice versa. The resulting range is
1348 a union of two subranges: [MIN, UB] and [LB, MAX]. Since such
1349 a union is not representable using the current data structure
1350 replace it with the full range of offsets. */
1351 if (acs
.dstoff
[1] < acs
.dstoff
[0])
1353 acs
.dstoff
[0] = -maxobjsize
- 1;
1354 acs
.dstoff
[1] = maxobjsize
;
1357 /* Validate the offset and size of each reference on its own first.
1358 This is independent of whether or not the base objects are the
1359 same. Normally, this would have already been detected and
1360 diagnosed by -Warray-bounds, unless it has been disabled. */
1361 offset_int maxoff
= acs
.dstoff
[0] + dstref
->sizrange
[0];
1362 if (maxobjsize
< maxoff
)
1364 acs
.ovlsiz
[0] = (maxoff
- maxobjsize
).to_shwi ();
1365 acs
.ovloff
[0] = acs
.dstoff
[0].to_shwi () - acs
.ovlsiz
[0];
1369 /* Repeat the same as above but for the source offsets. */
1370 if (acs
.srcoff
[1] < acs
.srcoff
[0])
1372 acs
.srcoff
[0] = -maxobjsize
- 1;
1373 acs
.srcoff
[1] = maxobjsize
;
1376 maxoff
= acs
.srcoff
[0] + srcref
->sizrange
[0];
1377 if (maxobjsize
< maxoff
)
1379 acs
.ovlsiz
[0] = (maxoff
- maxobjsize
).to_shwi ();
1380 acs
.ovlsiz
[1] = (acs
.srcoff
[0] + srcref
->sizrange
[1]
1381 - maxobjsize
).to_shwi ();
1382 acs
.ovloff
[0] = acs
.srcoff
[0].to_shwi () - acs
.ovlsiz
[0];
1386 if (dstref
->base
!= srcref
->base
)
1389 acs
.dstsiz
[0] = dstref
->sizrange
[0];
1390 acs
.dstsiz
[1] = dstref
->sizrange
[1];
1392 acs
.srcsiz
[0] = srcref
->sizrange
[0];
1393 acs
.srcsiz
[1] = srcref
->sizrange
[1];
1395 /* Call the appropriate function to determine the overlap. */
1396 if ((this->*detect_overlap
) ())
1400 /* Unless the access size range has already been set, do so here. */
1401 sizrange
[0] = wi::smax (acs
.dstsiz
[0], srcref
->sizrange
[0]).to_shwi ();
1402 sizrange
[1] = wi::smax (acs
.dstsiz
[1], srcref
->sizrange
[1]).to_shwi ();
1410 /* Attempt to detect and diagnose an overlapping copy in a call expression
1411 EXPR involving an access ACS to a built-in memory or string function.
1412 Return true when one has been detected, false otherwise. */
1415 maybe_diag_overlap (location_t loc
, gimple
*call
, builtin_access
&acs
)
1417 if (!acs
.overlap ())
1420 if (gimple_no_warning_p (call
))
1423 /* For convenience. */
1424 const builtin_memref
&dstref
= *acs
.dstref
;
1425 const builtin_memref
&srcref
= *acs
.srcref
;
1427 /* Determine the range of offsets and sizes of the overlap if it
1428 exists and issue diagnostics. */
1429 HOST_WIDE_INT
*ovloff
= acs
.ovloff
;
1430 HOST_WIDE_INT
*ovlsiz
= acs
.ovlsiz
;
1431 HOST_WIDE_INT
*sizrange
= acs
.sizrange
;
1433 tree func
= gimple_call_fndecl (call
);
1435 /* To avoid a combinatorial explosion of diagnostics format the offsets
1436 or their ranges as strings and use them in the warning calls below. */
1439 if (dstref
.offrange
[0] == dstref
.offrange
[1]
1440 || dstref
.offrange
[1] > HOST_WIDE_INT_MAX
)
1441 sprintf (offstr
[0], HOST_WIDE_INT_PRINT_DEC
,
1442 dstref
.offrange
[0].to_shwi ());
1445 "[" HOST_WIDE_INT_PRINT_DEC
", " HOST_WIDE_INT_PRINT_DEC
"]",
1446 dstref
.offrange
[0].to_shwi (),
1447 dstref
.offrange
[1].to_shwi ());
1449 if (srcref
.offrange
[0] == srcref
.offrange
[1]
1450 || srcref
.offrange
[1] > HOST_WIDE_INT_MAX
)
1452 HOST_WIDE_INT_PRINT_DEC
,
1453 srcref
.offrange
[0].to_shwi ());
1456 "[" HOST_WIDE_INT_PRINT_DEC
", " HOST_WIDE_INT_PRINT_DEC
"]",
1457 srcref
.offrange
[0].to_shwi (),
1458 srcref
.offrange
[1].to_shwi ());
1460 if (ovloff
[0] == ovloff
[1] || !ovloff
[1])
1461 sprintf (offstr
[2], HOST_WIDE_INT_PRINT_DEC
, ovloff
[0]);
1464 "[" HOST_WIDE_INT_PRINT_DEC
", " HOST_WIDE_INT_PRINT_DEC
"]",
1465 ovloff
[0], ovloff
[1]);
1467 const offset_int maxobjsize
= dstref
.maxobjsize
;
1468 bool must_overlap
= ovlsiz
[0] > 0;
1471 ovlsiz
[1] = ovlsiz
[0];
1475 /* Issue definitive "overlaps" diagnostic in this block. */
1477 if (sizrange
[0] == sizrange
[1])
1479 if (ovlsiz
[0] == ovlsiz
[1])
1480 warning_at (loc
, OPT_Wrestrict
,
1483 ? G_("%G%qD accessing %wu byte at offsets %s "
1484 "and %s overlaps %wu byte at offset %s")
1485 : G_("%G%qD accessing %wu byte at offsets %s "
1486 "and %s overlaps %wu bytes at offset "
1489 ? G_("%G%qD accessing %wu bytes at offsets %s "
1490 "and %s overlaps %wu byte at offset %s")
1491 : G_("%G%qD accessing %wu bytes at offsets %s "
1492 "and %s overlaps %wu bytes at offset "
1494 call
, func
, sizrange
[0],
1495 offstr
[0], offstr
[1], ovlsiz
[0], offstr
[2]);
1496 else if (ovlsiz
[1] >= 0 && ovlsiz
[1] < maxobjsize
.to_shwi ())
1497 warning_n (loc
, OPT_Wrestrict
, sizrange
[0],
1498 "%G%qD accessing %wu byte at offsets %s "
1499 "and %s overlaps between %wu and %wu bytes "
1501 "%G%qD accessing %wu bytes at offsets %s "
1502 "and %s overlaps between %wu and %wu bytes "
1504 call
, func
, sizrange
[0], offstr
[0], offstr
[1],
1505 ovlsiz
[0], ovlsiz
[1], offstr
[2]);
1507 warning_n (loc
, OPT_Wrestrict
, sizrange
[0],
1508 "%G%qD accessing %wu byte at offsets %s and "
1509 "%s overlaps %wu or more bytes at offset %s",
1510 "%G%qD accessing %wu bytes at offsets %s and "
1511 "%s overlaps %wu or more bytes at offset %s",
1512 call
, func
, sizrange
[0],
1513 offstr
[0], offstr
[1], ovlsiz
[0], offstr
[2]);
1517 if (sizrange
[1] >= 0 && sizrange
[1] < maxobjsize
.to_shwi ())
1519 if (ovlsiz
[0] == ovlsiz
[1])
1520 warning_n (loc
, OPT_Wrestrict
, ovlsiz
[0],
1521 "%G%qD accessing between %wu and %wu bytes "
1522 "at offsets %s and %s overlaps %wu byte at "
1524 "%G%qD accessing between %wu and %wu bytes "
1525 "at offsets %s and %s overlaps %wu bytes "
1527 call
, func
, sizrange
[0], sizrange
[1],
1528 offstr
[0], offstr
[1], ovlsiz
[0], offstr
[2]);
1529 else if (ovlsiz
[1] >= 0 && ovlsiz
[1] < maxobjsize
.to_shwi ())
1530 warning_at (loc
, OPT_Wrestrict
,
1531 "%G%qD accessing between %wu and %wu bytes at "
1532 "offsets %s and %s overlaps between %wu and %wu "
1533 "bytes at offset %s",
1534 call
, func
, sizrange
[0], sizrange
[1],
1535 offstr
[0], offstr
[1], ovlsiz
[0], ovlsiz
[1],
1538 warning_at (loc
, OPT_Wrestrict
,
1539 "%G%qD accessing between %wu and %wu bytes at "
1540 "offsets %s and %s overlaps %wu or more bytes "
1542 call
, func
, sizrange
[0], sizrange
[1],
1543 offstr
[0], offstr
[1], ovlsiz
[0], offstr
[2]);
1547 if (ovlsiz
[0] != ovlsiz
[1])
1548 ovlsiz
[1] = maxobjsize
.to_shwi ();
1550 if (ovlsiz
[0] == ovlsiz
[1])
1551 warning_n (loc
, OPT_Wrestrict
, ovlsiz
[0],
1552 "%G%qD accessing %wu or more bytes at offsets "
1553 "%s and %s overlaps %wu byte at offset %s",
1554 "%G%qD accessing %wu or more bytes at offsets "
1555 "%s and %s overlaps %wu bytes at offset %s",
1556 call
, func
, sizrange
[0], offstr
[0], offstr
[1],
1557 ovlsiz
[0], offstr
[2]);
1558 else if (ovlsiz
[1] >= 0 && ovlsiz
[1] < maxobjsize
.to_shwi ())
1559 warning_at (loc
, OPT_Wrestrict
,
1560 "%G%qD accessing %wu or more bytes at offsets %s "
1561 "and %s overlaps between %wu and %wu bytes "
1563 call
, func
, sizrange
[0], offstr
[0], offstr
[1],
1564 ovlsiz
[0], ovlsiz
[1], offstr
[2]);
1566 warning_at (loc
, OPT_Wrestrict
,
1567 "%G%qD accessing %wu or more bytes at offsets %s "
1568 "and %s overlaps %wu or more bytes at offset %s",
1569 call
, func
, sizrange
[0], offstr
[0], offstr
[1],
1570 ovlsiz
[0], offstr
[2]);
1574 /* Use more concise wording when one of the offsets is unbounded
1575 to avoid confusing the user with large and mostly meaningless
1578 if (DECL_P (dstref
.base
) && TREE_CODE (TREE_TYPE (dstref
.base
)) == ARRAY_TYPE
)
1579 open_range
= ((dstref
.offrange
[0] == 0
1580 && dstref
.offrange
[1] == maxobjsize
)
1581 || (srcref
.offrange
[0] == 0
1582 && srcref
.offrange
[1] == maxobjsize
));
1584 open_range
= ((dstref
.offrange
[0] == -maxobjsize
- 1
1585 && dstref
.offrange
[1] == maxobjsize
)
1586 || (srcref
.offrange
[0] == -maxobjsize
- 1
1587 && srcref
.offrange
[1] == maxobjsize
));
1589 if (sizrange
[0] == sizrange
[1] || sizrange
[1] == 1)
1594 warning_n (loc
, OPT_Wrestrict
, sizrange
[1],
1595 "%G%qD accessing %wu byte may overlap "
1597 "%G%qD accessing %wu bytes may overlap "
1599 call
, func
, sizrange
[1], ovlsiz
[1]);
1601 warning_n (loc
, OPT_Wrestrict
, sizrange
[1],
1602 "%G%qD accessing %wu byte at offsets %s "
1603 "and %s may overlap %wu byte at offset %s",
1604 "%G%qD accessing %wu bytes at offsets %s "
1605 "and %s may overlap %wu byte at offset %s",
1606 call
, func
, sizrange
[1], offstr
[0], offstr
[1],
1607 ovlsiz
[1], offstr
[2]);
1612 warning_n (loc
, OPT_Wrestrict
, sizrange
[1],
1613 "%G%qD accessing %wu byte may overlap "
1615 "%G%qD accessing %wu bytes may overlap "
1617 call
, func
, sizrange
[1], ovlsiz
[1]);
1619 warning_n (loc
, OPT_Wrestrict
, sizrange
[1],
1620 "%G%qD accessing %wu byte at offsets %s and "
1621 "%s may overlap up to %wu bytes at offset %s",
1622 "%G%qD accessing %wu bytes at offsets %s and "
1623 "%s may overlap up to %wu bytes at offset %s",
1624 call
, func
, sizrange
[1], offstr
[0], offstr
[1],
1625 ovlsiz
[1], offstr
[2]);
1629 if (sizrange
[1] >= 0 && sizrange
[1] < maxobjsize
.to_shwi ())
1632 warning_n (loc
, OPT_Wrestrict
, ovlsiz
[1],
1633 "%G%qD accessing between %wu and %wu bytes "
1634 "may overlap %wu byte",
1635 "%G%qD accessing between %wu and %wu bytes "
1636 "may overlap up to %wu bytes",
1637 call
, func
, sizrange
[0], sizrange
[1], ovlsiz
[1]);
1639 warning_n (loc
, OPT_Wrestrict
, ovlsiz
[1],
1640 "%G%qD accessing between %wu and %wu bytes "
1641 "at offsets %s and %s may overlap %wu byte "
1643 "%G%qD accessing between %wu and %wu bytes "
1644 "at offsets %s and %s may overlap up to %wu "
1645 "bytes at offset %s",
1646 call
, func
, sizrange
[0], sizrange
[1],
1647 offstr
[0], offstr
[1], ovlsiz
[1], offstr
[2]);
1651 warning_n (loc
, OPT_Wrestrict
, ovlsiz
[1],
1652 "%G%qD accessing %wu or more bytes at offsets %s "
1653 "and %s may overlap %wu byte at offset %s",
1654 "%G%qD accessing %wu or more bytes at offsets %s "
1655 "and %s may overlap up to %wu bytes at offset %s",
1656 call
, func
, sizrange
[0], offstr
[0], offstr
[1],
1657 ovlsiz
[1], offstr
[2]);
1662 /* Validate REF size and offsets in an expression passed as an argument
1663 to a CALL to a built-in function FUNC to make sure they are within
1664 the bounds of the referenced object if its size is known, or
1665 PTRDIFF_MAX otherwise. DO_WARN is true when a diagnostic should
1666 be issued, false otherwise.
1667 Both initial values of the offsets and their final value computed
1668 by the function by incrementing the initial value by the size are
1669 validated. Return true if the offsets are not valid and a diagnostic
1670 has been issued, or would have been issued if DO_WARN had been true. */
1673 maybe_diag_access_bounds (gimple
*call
, tree func
, int strict
,
1674 const builtin_memref
&ref
, offset_int wroff
,
1677 location_t loc
= gimple_or_expr_nonartificial_location (call
, ref
.ptr
);
1678 const offset_int maxobjsize
= ref
.maxobjsize
;
1680 /* Check for excessive size first and regardless of warning options
1681 since the result is used to make codegen decisions. */
1682 if (ref
.sizrange
[0] > maxobjsize
)
1684 /* Return true without issuing a warning. */
1688 if (ref
.ref
&& TREE_NO_WARNING (ref
.ref
))
1691 if (warn_stringop_overflow
)
1693 if (ref
.sizrange
[0] == ref
.sizrange
[1])
1694 return warning_at (loc
, OPT_Wstringop_overflow_
,
1695 "%G%qD specified bound %wu "
1696 "exceeds maximum object size %wu",
1697 call
, func
, ref
.sizrange
[0].to_uhwi (),
1698 maxobjsize
.to_uhwi ());
1700 return warning_at (loc
, OPT_Wstringop_overflow_
,
1701 "%G%qD specified bound between %wu and %wu "
1702 "exceeds maximum object size %wu",
1703 call
, func
, ref
.sizrange
[0].to_uhwi (),
1704 ref
.sizrange
[1].to_uhwi (),
1705 maxobjsize
.to_uhwi ());
1709 /* Check for out-bounds pointers regardless of warning options since
1710 the result is used to make codegen decisions. An excessive WROFF
1711 can only come up as a result of an invalid strncat bound and is
1712 diagnosed separately using a more meaningful warning. */
1713 if (maxobjsize
< wroff
)
1715 offset_int ooboff
[] = { ref
.offrange
[0], ref
.offrange
[1], wroff
};
1716 tree oobref
= ref
.offset_out_of_bounds (strict
, ooboff
);
1720 /* Return true without issuing a warning. */
1724 if (!warn_array_bounds
)
1727 if (TREE_NO_WARNING (ref
.ptr
)
1728 || (ref
.ref
&& TREE_NO_WARNING (ref
.ref
)))
1731 char rangestr
[2][64];
1732 if (ooboff
[0] == ooboff
[1]
1733 || (ooboff
[0] != ref
.offrange
[0]
1734 && ooboff
[0].to_shwi () >= ooboff
[1].to_shwi ()))
1735 sprintf (rangestr
[0], "%lli", (long long) ooboff
[0].to_shwi ());
1737 sprintf (rangestr
[0], "[%lli, %lli]",
1738 (long long) ooboff
[0].to_shwi (),
1739 (long long) ooboff
[1].to_shwi ());
1741 bool warned
= false;
1743 if (oobref
== error_mark_node
)
1745 if (ref
.sizrange
[0] == ref
.sizrange
[1])
1746 sprintf (rangestr
[1], "%llu",
1747 (unsigned long long) ref
.sizrange
[0].to_shwi ());
1749 sprintf (rangestr
[1], "[%lli, %lli]",
1750 (unsigned long long) ref
.sizrange
[0].to_uhwi (),
1751 (unsigned long long) ref
.sizrange
[1].to_uhwi ());
1755 if (DECL_P (ref
.base
)
1756 && TREE_CODE (type
= TREE_TYPE (ref
.base
)) == ARRAY_TYPE
)
1758 auto_diagnostic_group d
;
1759 if (warning_at (loc
, OPT_Warray_bounds
,
1760 "%G%qD pointer overflow between offset %s "
1761 "and size %s accessing array %qD with type %qT",
1762 call
, func
, rangestr
[0], rangestr
[1], ref
.base
, type
))
1764 inform (DECL_SOURCE_LOCATION (ref
.base
),
1765 "array %qD declared here", ref
.base
);
1769 warned
= warning_at (loc
, OPT_Warray_bounds
,
1770 "%G%qD pointer overflow between offset %s "
1772 call
, func
, rangestr
[0], rangestr
[1]);
1775 warned
= warning_at (loc
, OPT_Warray_bounds
,
1776 "%G%qD pointer overflow between offset %s "
1778 call
, func
, rangestr
[0], rangestr
[1]);
1780 else if (oobref
== ref
.base
)
1782 /* True when the offset formed by an access to the reference
1783 is out of bounds, rather than the initial offset wich is
1784 in bounds. This implies access past the end. */
1785 bool form
= ooboff
[0] != ref
.offrange
[0];
1787 if (DECL_P (ref
.base
))
1789 auto_diagnostic_group d
;
1790 if ((ref
.basesize
< maxobjsize
1791 && warning_at (loc
, OPT_Warray_bounds
,
1793 ? G_("%G%qD forming offset %s is out of "
1794 "the bounds [0, %wu] of object %qD with "
1796 : G_("%G%qD offset %s is out of the bounds "
1797 "[0, %wu] of object %qD with type %qT"),
1798 call
, func
, rangestr
[0], ref
.basesize
.to_uhwi (),
1799 ref
.base
, TREE_TYPE (ref
.base
)))
1800 || warning_at (loc
, OPT_Warray_bounds
,
1802 ? G_("%G%qD forming offset %s is out of "
1803 "the bounds of object %qD with type %qT")
1804 : G_("%G%qD offset %s is out of the bounds "
1805 "of object %qD with type %qT"),
1806 call
, func
, rangestr
[0],
1807 ref
.base
, TREE_TYPE (ref
.base
)))
1809 inform (DECL_SOURCE_LOCATION (ref
.base
),
1810 "%qD declared here", ref
.base
);
1814 else if (ref
.basesize
< maxobjsize
)
1815 warned
= warning_at (loc
, OPT_Warray_bounds
,
1817 ? G_("%G%qD forming offset %s is out "
1818 "of the bounds [0, %wu]")
1819 : G_("%G%qD offset %s is out "
1820 "of the bounds [0, %wu]"),
1821 call
, func
, rangestr
[0], ref
.basesize
.to_uhwi ());
1823 warned
= warning_at (loc
, OPT_Warray_bounds
,
1825 ? G_("%G%qD forming offset %s is out of bounds")
1826 : G_("%G%qD offset %s is out of bounds"),
1827 call
, func
, rangestr
[0]);
1829 else if (TREE_CODE (ref
.ref
) == MEM_REF
)
1831 tree refop
= TREE_OPERAND (ref
.ref
, 0);
1832 tree type
= TREE_TYPE (refop
);
1833 if (POINTER_TYPE_P (type
))
1834 type
= TREE_TYPE (type
);
1835 type
= TYPE_MAIN_VARIANT (type
);
1837 if (warning_at (loc
, OPT_Warray_bounds
,
1838 "%G%qD offset %s from the object at %qE is out "
1839 "of the bounds of %qT",
1840 call
, func
, rangestr
[0], ref
.base
, type
))
1842 if (TREE_CODE (ref
.ref
) == COMPONENT_REF
)
1843 refop
= TREE_OPERAND (ref
.ref
, 1);
1845 inform (DECL_SOURCE_LOCATION (refop
),
1846 "subobject %qD declared here", refop
);
1852 tree refop
= TREE_OPERAND (ref
.ref
, 0);
1853 tree type
= TYPE_MAIN_VARIANT (TREE_TYPE (ref
.ref
));
1855 if (warning_at (loc
, OPT_Warray_bounds
,
1856 "%G%qD offset %s from the object at %qE is out "
1857 "of the bounds of referenced subobject %qD with "
1858 "type %qT at offset %wi",
1859 call
, func
, rangestr
[0], ref
.base
,
1860 TREE_OPERAND (ref
.ref
, 1), type
,
1861 ref
.refoff
.to_shwi ()))
1863 if (TREE_CODE (ref
.ref
) == COMPONENT_REF
)
1864 refop
= TREE_OPERAND (ref
.ref
, 1);
1866 inform (DECL_SOURCE_LOCATION (refop
),
1867 "subobject %qD declared here", refop
);
1875 /* Check a CALL statement for restrict-violations and issue warnings
1876 if/when appropriate. */
1879 wrestrict_dom_walker::check_call (gimple
*call
)
1881 /* Avoid checking the call if it has already been diagnosed for
1883 if (gimple_no_warning_p (call
))
1886 tree func
= gimple_call_fndecl (call
);
1887 if (!func
|| !fndecl_built_in_p (func
, BUILT_IN_NORMAL
))
1890 /* Argument number to extract from the call (depends on the built-in
1892 unsigned dst_idx
= -1;
1893 unsigned src_idx
= -1;
1894 unsigned bnd_idx
= -1;
1896 /* Is this CALL to a string function (as opposed to one to a raw
1897 memory function). */
1900 switch (DECL_FUNCTION_CODE (func
))
1902 case BUILT_IN_MEMCPY
:
1903 case BUILT_IN_MEMCPY_CHK
:
1904 case BUILT_IN_MEMPCPY
:
1905 case BUILT_IN_MEMPCPY_CHK
:
1906 case BUILT_IN_MEMMOVE
:
1907 case BUILT_IN_MEMMOVE_CHK
:
1911 case BUILT_IN_STPNCPY
:
1912 case BUILT_IN_STPNCPY_CHK
:
1913 case BUILT_IN_STRNCAT
:
1914 case BUILT_IN_STRNCAT_CHK
:
1915 case BUILT_IN_STRNCPY
:
1916 case BUILT_IN_STRNCPY_CHK
:
1922 case BUILT_IN_MEMSET
:
1923 case BUILT_IN_MEMSET_CHK
:
1928 case BUILT_IN_STPCPY
:
1929 case BUILT_IN_STPCPY_CHK
:
1930 case BUILT_IN_STRCPY
:
1931 case BUILT_IN_STRCPY_CHK
:
1932 case BUILT_IN_STRCAT
:
1933 case BUILT_IN_STRCAT_CHK
:
1939 /* Handle other string functions here whose access may need
1940 to be validated for in-bounds offsets and non-overlapping
1945 unsigned nargs
= gimple_call_num_args (call
);
1947 tree dst
= dst_idx
< nargs
? gimple_call_arg (call
, dst_idx
) : NULL_TREE
;
1948 tree src
= src_idx
< nargs
? gimple_call_arg (call
, src_idx
) : NULL_TREE
;
1949 tree dstwr
= bnd_idx
< nargs
? gimple_call_arg (call
, bnd_idx
) : NULL_TREE
;
1951 /* For string functions with an unspecified or unknown bound,
1952 assume the size of the access is one. */
1953 if (!dstwr
&& strfun
)
1954 dstwr
= size_one_node
;
1956 /* DST and SRC can be null for a call with an insufficient number
1957 of arguments to a built-in function declared without a protype. */
1958 if (!dst
|| (src_idx
< nargs
&& !src
))
1961 /* DST, SRC, or DSTWR can also have the wrong type in a call to
1962 a function declared without a prototype. Avoid checking such
1964 if (TREE_CODE (TREE_TYPE (dst
)) != POINTER_TYPE
1965 || (src
&& TREE_CODE (TREE_TYPE (src
)) != POINTER_TYPE
)
1966 || (dstwr
&& !INTEGRAL_TYPE_P (TREE_TYPE (dstwr
))))
1969 if (!check_bounds_or_overlap (call
, dst
, src
, dstwr
, NULL_TREE
))
1972 /* Avoid diagnosing the call again. */
1973 gimple_set_no_warning (call
, true);
1976 } /* anonymous namespace */
1978 /* Attempt to detect and diagnose invalid offset bounds and (except for
1979 memmove) overlapping copy in a call expression EXPR from SRC to DST
1980 and DSTSIZE and SRCSIZE bytes, respectively. Both DSTSIZE and
1981 SRCSIZE may be NULL. DO_WARN is false to detect either problem
1982 without issue a warning. Return the OPT_Wxxx constant corresponding
1983 to the warning if one has been detected and zero otherwise. */
1986 check_bounds_or_overlap (gimple
*call
, tree dst
, tree src
, tree dstsize
,
1987 tree srcsize
, bool bounds_only
/* = false */,
1988 bool do_warn
/* = true */)
1990 tree func
= gimple_call_fndecl (call
);
1992 builtin_memref
dstref (dst
, dstsize
);
1993 builtin_memref
srcref (src
, srcsize
);
1995 /* Create a descriptor of the access. This may adjust both DSTREF
1996 and SRCREF based on one another and the kind of the access. */
1997 builtin_access
acs (call
, dstref
, srcref
);
1999 /* Set STRICT to the value of the -Warray-bounds=N argument for
2000 string functions or when N > 1. */
2001 int strict
= (acs
.strict () || warn_array_bounds
> 1 ? warn_array_bounds
: 0);
2003 /* The starting offset of the destination write access. Nonzero only
2004 for the strcat family of functions. */
2005 offset_int wroff
= acs
.write_off (dstsize
);
2007 /* Validate offsets to each reference before the access first to make
2008 sure they are within the bounds of the destination object if its
2009 size is known, or PTRDIFF_MAX otherwise. */
2010 if (maybe_diag_access_bounds (call
, func
, strict
, dstref
, wroff
, do_warn
)
2011 || maybe_diag_access_bounds (call
, func
, strict
, srcref
, 0, do_warn
))
2014 gimple_set_no_warning (call
, true);
2015 return OPT_Warray_bounds
;
2018 if (!warn_restrict
|| bounds_only
|| !src
)
2023 switch (DECL_FUNCTION_CODE (func
))
2025 case BUILT_IN_MEMMOVE
:
2026 case BUILT_IN_MEMMOVE_CHK
:
2027 case BUILT_IN_MEMSET
:
2028 case BUILT_IN_MEMSET_CHK
:
2035 location_t loc
= gimple_or_expr_nonartificial_location (call
, dst
);
2036 if (operand_equal_p (dst
, src
, 0))
2038 /* Issue -Wrestrict unless the pointers are null (those do
2039 not point to objects and so do not indicate an overlap;
2040 such calls could be the result of sanitization and jump
2042 if (!integer_zerop (dst
) && !gimple_no_warning_p (call
))
2044 warning_at (loc
, OPT_Wrestrict
,
2045 "%G%qD source argument is the same as destination",
2047 gimple_set_no_warning (call
, true);
2048 return OPT_Wrestrict
;
2054 /* Return false when overlap has been detected. */
2055 if (maybe_diag_overlap (loc
, call
, acs
))
2057 gimple_set_no_warning (call
, true);
2058 return OPT_Wrestrict
;
2065 make_pass_warn_restrict (gcc::context
*ctxt
)
2067 return new pass_wrestrict (ctxt
);
2071 dump_builtin_memref (FILE *fp
, const builtin_memref
&ref
)
2073 fprintf (fp
, "\n ptr = ");
2074 print_generic_expr (fp
, ref
.ptr
, TDF_LINENO
);
2075 fprintf (fp
, "\n ref = ");
2077 print_generic_expr (fp
, ref
.ref
, TDF_LINENO
);
2080 fprintf (fp
, "\n base = ");
2081 print_generic_expr (fp
, ref
.base
, TDF_LINENO
);
2083 "\n basesize = %lli"
2086 "\n offrange = [%lli, %lli]"
2087 "\n sizrange = [%lli, %lli]"
2088 "\n strbounded_p = %s\n",
2089 (long long)ref
.basesize
.to_shwi (),
2090 (long long)ref
.refsize
.to_shwi (),
2091 (long long)ref
.refoff
.to_shwi (),
2092 (long long)ref
.offrange
[0].to_shwi (),
2093 (long long)ref
.offrange
[1].to_shwi (),
2094 (long long)ref
.sizrange
[0].to_shwi (),
2095 (long long)ref
.sizrange
[1].to_shwi (),
2096 ref
.strbounded_p
? "true" : "false");
2100 builtin_access::dump (FILE *fp
) const
2102 fprintf (fp
, " dstref:");
2103 dump_builtin_memref (fp
, *dstref
);
2104 fprintf (fp
, "\n srcref:");
2105 dump_builtin_memref (fp
, *srcref
);
2108 " sizrange = [%lli, %lli]\n"
2109 " ovloff = [%lli, %lli]\n"
2110 " ovlsiz = [%lli, %lli]\n"
2111 " dstoff = [%lli, %lli]\n"
2112 " dstsiz = [%lli, %lli]\n"
2113 " srcoff = [%lli, %lli]\n"
2114 " srcsiz = [%lli, %lli]\n",
2115 (long long)sizrange
[0], (long long)sizrange
[1],
2116 (long long)ovloff
[0], (long long)ovloff
[1],
2117 (long long)ovlsiz
[0], (long long)ovlsiz
[1],
2118 (long long)dstoff
[0].to_shwi (), (long long)dstoff
[1].to_shwi (),
2119 (long long)dstsiz
[0].to_shwi (), (long long)dstsiz
[1].to_shwi (),
2120 (long long)srcoff
[0].to_shwi (), (long long)srcoff
[1].to_shwi (),
2121 (long long)srcsiz
[0].to_shwi (), (long long)srcsiz
[1].to_shwi ());
2125 dump_builtin_access (FILE *fp
, gimple
*stmt
, const builtin_access
&acs
)
2129 fprintf (fp
, "\nDumping builtin_access for ");
2130 print_gimple_expr (fp
, stmt
, TDF_LINENO
);
2138 debug (gimple
*stmt
, const builtin_access
&acs
)
2140 dump_builtin_access (stdout
, stmt
, acs
);