Mercurial > hg > CbC > CbC_gcc
comparison gcc/cp/cp-ubsan.c @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | 04ced10e8804 |
children | 1830386684a0 |
comparison
equal
deleted
inserted
replaced
111:04ced10e8804 | 131:84e7813d76e9 |
---|---|
1 /* UndefinedBehaviorSanitizer, undefined behavior detector. | 1 /* UndefinedBehaviorSanitizer, undefined behavior detector. |
2 Copyright (C) 2014-2017 Free Software Foundation, Inc. | 2 Copyright (C) 2014-2018 Free Software Foundation, Inc. |
3 Contributed by Jakub Jelinek <jakub@redhat.com> | 3 Contributed by Jakub Jelinek <jakub@redhat.com> |
4 | 4 |
5 This file is part of GCC. | 5 This file is part of GCC. |
6 | 6 |
7 GCC is free software; you can redistribute it and/or modify it under | 7 GCC is free software; you can redistribute it and/or modify it under |
119 if (call_expr_nargs (stmt) == 0) | 119 if (call_expr_nargs (stmt) == 0) |
120 return; | 120 return; |
121 tree *opp = &CALL_EXPR_ARG (stmt, 0); | 121 tree *opp = &CALL_EXPR_ARG (stmt, 0); |
122 tree op = *opp; | 122 tree op = *opp; |
123 if (op == error_mark_node | 123 if (op == error_mark_node |
124 || !POINTER_TYPE_P (TREE_TYPE (op))) | 124 || !INDIRECT_TYPE_P (TREE_TYPE (op))) |
125 return; | 125 return; |
126 while (TREE_CODE (op) == COMPOUND_EXPR) | 126 while (TREE_CODE (op) == COMPOUND_EXPR) |
127 { | 127 { |
128 opp = &TREE_OPERAND (op, 1); | 128 opp = &TREE_OPERAND (op, 1); |
129 op = *opp; | 129 op = *opp; |
203 case INDIRECT_REF: | 203 case INDIRECT_REF: |
204 t = TREE_OPERAND (stmt, 0); | 204 t = TREE_OPERAND (stmt, 0); |
205 if (TREE_CODE (t) == ADDR_EXPR) | 205 if (TREE_CODE (t) == ADDR_EXPR) |
206 { | 206 { |
207 *walk_subtrees = 0; | 207 *walk_subtrees = 0; |
208 t = TREE_OPERAND (stmt, 0); | 208 t = TREE_OPERAND (t, 0); |
209 cp_walk_tree (&t, cp_ubsan_check_member_access_r, data, ucmd->pset); | 209 cp_walk_tree (&t, cp_ubsan_check_member_access_r, data, ucmd->pset); |
210 } | 210 } |
211 break; | 211 break; |
212 case COMPONENT_REF: | 212 case COMPONENT_REF: |
213 if (!ucmd->is_addr && cp_ubsan_maybe_instrument_member_access (stmt, ucmd)) | 213 if (!ucmd->is_addr && cp_ubsan_maybe_instrument_member_access (stmt, ucmd)) |
255 | 255 |
256 tree | 256 tree |
257 cp_ubsan_maybe_instrument_downcast (location_t loc, tree type, | 257 cp_ubsan_maybe_instrument_downcast (location_t loc, tree type, |
258 tree intype, tree op) | 258 tree intype, tree op) |
259 { | 259 { |
260 if (!POINTER_TYPE_P (type) | 260 if (!INDIRECT_TYPE_P (type) |
261 || !POINTER_TYPE_P (intype) | 261 || !INDIRECT_TYPE_P (intype) |
262 || !POINTER_TYPE_P (TREE_TYPE (op)) | 262 || !INDIRECT_TYPE_P (TREE_TYPE (op)) |
263 || !CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (op))) | 263 || !CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (op))) |
264 || !is_properly_derived_from (TREE_TYPE (type), TREE_TYPE (intype))) | 264 || !is_properly_derived_from (TREE_TYPE (type), TREE_TYPE (intype))) |
265 return NULL_TREE; | 265 return NULL_TREE; |
266 | 266 |
267 return cp_ubsan_maybe_instrument_vptr (loc, op, TREE_TYPE (type), true, | 267 return cp_ubsan_maybe_instrument_vptr (loc, op, TREE_TYPE (type), true, |
268 TREE_CODE (type) == POINTER_TYPE | 268 TYPE_PTR_P (type) |
269 ? UBSAN_DOWNCAST_POINTER | 269 ? UBSAN_DOWNCAST_POINTER |
270 : UBSAN_DOWNCAST_REFERENCE); | 270 : UBSAN_DOWNCAST_REFERENCE); |
271 } | 271 } |
272 | 272 |
273 /* Instrument cast to virtual base. */ | 273 /* Instrument cast to virtual base. */ |
296 base_ptr = build_base_path (PLUS_EXPR, base_ptr, binfo, /*nonnull=*/1, | 296 base_ptr = build_base_path (PLUS_EXPR, base_ptr, binfo, /*nonnull=*/1, |
297 tf_warning_or_error); | 297 tf_warning_or_error); |
298 | 298 |
299 /* Compute the location of the vtpr. */ | 299 /* Compute the location of the vtpr. */ |
300 tree vtbl_ptr | 300 tree vtbl_ptr |
301 = build_vfield_ref (cp_build_indirect_ref (base_ptr, RO_NULL, | 301 = build_vfield_ref (cp_build_fold_indirect_ref (base_ptr), |
302 tf_warning_or_error), | |
303 TREE_TYPE (binfo)); | 302 TREE_TYPE (binfo)); |
304 gcc_assert (vtbl_ptr != error_mark_node); | 303 gcc_assert (vtbl_ptr != error_mark_node); |
305 | 304 |
306 /* Assign NULL to the vptr. */ | 305 /* Assign NULL to the vptr. */ |
307 tree vtbl = build_zero_cst (TREE_TYPE (vtbl_ptr)); | 306 tree vtbl = build_zero_cst (TREE_TYPE (vtbl_ptr)); |