gcc/gcc/ubsan.c

2073 lines
64 KiB
C
Raw Permalink Normal View History

/* UndefinedBehaviorSanitizer, undefined behavior detector.
Copyright (C) 2013-2017 Free Software Foundation, Inc.
Contributed by Marek Polacek <polacek@redhat.com>
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/>. */
#include "config.h"
#include "system.h"
#include "coretypes.h"
tree-core.h: Include symtab.h. 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * tree-core.h: Include symtab.h. * rtl.h: Include hard-reg-set.h but not flags.h. (HARD_CONST): Remove condition compilation involving HARD_CONST since hard-reg-set.h is always included. * regs.h: Don't include hard-reg-set.h or rtl.h. * cfg.h: Include dominance.h. * gimple.h: Include tree-ssa-alias.h and gimple-expr.h. * backend.h: New. Aggregate commonly used backend header files. * gimple-ssa.h: Don't include tree-hasher.h. * ssa.h: New. Aggregate commonly used SSA header files. * regset.h: Remove bitmap.h and hard-reg-set.h #includes. * sel-sched-ir.h: Flatten includes. * lra-int.h: Flatten completely. * sel-sched-dump.h: Flatten includes. * ira-int.h: Flatten includes. * gimple-streamer.h: Remove all includes. * cfgloop.h: Remove all #includes except cfgloopmanip.h. * resource.h: Flatten hard-reg-set.h and df.h. * sched-int.h: Flatten insn-arrt.h and df.h. * valtrack.h: flatten bitmap.h, df.h, and rtl.h * df.h: Flatten includes, leaving regset.h, alloc-pool.h and timevar.h. * genattrtab.c (write_header): Adjust generated includes. * genautomata.c (main): Likewise. * genconditions.c (write-header): Likewise. * genemit.c (main): Likewise. * gengtype.c (open_base_files): Likewise. * genopinit.c (main): Likewise. * genoutput.c (output_prologue): Likewise. * genpeep.c (main): Likewise. * genpreds.c (write_insn_preds_c): Likewise. * genrecog.c (write_header): Likewise. * alias.c: Adjust includes. * asan.c: Likewise. * attribs.c: Likewise. * auto-inc-dec.c: Likewise. * auto-profile.c: Likewise. * bb-reorder.c: Likewise. * bt-load.c: Likewise. * builtins.c: Likewise. * caller-save.c: Likewise. * calls.c: Likewise. * ccmp.c: Likewise. * cfg.c: Likewise. * cfganal.c: Likewise. * cfgbuild.c: Likewise. * cfgcleanup.c: Likewise. * cfgexpand.c: Likewise. * cfghooks.c: Likewise. * cfgloop.c: Likewise. * cfgloopanal.c: Likewise. * cfgloopmanip.c: Likewise. * cfgrtl.c: Likewise. * cgraph.c: Likewise. * cgraphbuild.c: Likewise. * cgraphclones.c: Likewise. * cgraphunit.c: Likewise. * cilk-common.c: Likewise. * combine-stack-adj.c: Likewise. * combine.c: Likewise. * compare-elim.c: Likewise. * convert.c: Likewise. * coverage.c: Likewise. * cppbuiltin.c: Likewise. * cprop.c: Likewise. * cse.c: Likewise. * cselib.c: Likewise. * data-streamer-in.c: Likewise. * data-streamer-out.c: Likewise. * data-streamer.c: Likewise. * dbxout.c: Likewise. * dce.c: Likewise. * ddg.c: Likewise. * debug.c: Likewise. * df-core.c: Likewise. * df-problems.c: Likewise. * df-scan.c: Likewise. * dfp.c: Likewise. * dojump.c: Likewise. * dominance.c: Likewise. * domwalk.c: Likewise. * double-int.c: Likewise. * dse.c: Likewise. * dumpfile.c: Likewise. * dwarf2asm.c: Likewise. * dwarf2cfi.c: Likewise. * dwarf2out.c: Likewise. * emit-rtl.c: Likewise. * et-forest.c: Likewise. * except.c: Likewise. * explow.c: Likewise. * expmed.c: Likewise. * expr.c: Likewise. * final.c: Likewise. * fixed-value.c: Likewise. * fold-const.c: Likewise. * function.c: Likewise. * fwprop.c: Likewise. * gcc-plugin.h: Likewise. * gcse-common.c: Likewise. * gcse.c: Likewise. * generic-match-head.c: Likewise. * ggc-page.c: Likewise. * gimple-builder.c: Likewise. * gimple-expr.c: Likewise. * gimple-fold.c: Likewise. * gimple-iterator.c: Likewise. * gimple-low.c: Likewise. * gimple-match-head.c: Likewise. * gimple-pretty-print.c: Likewise. * gimple-ssa-isolate-paths.c: Likewise. * gimple-ssa-strength-reduction.c: Likewise. * gimple-streamer-in.c: Likewise. * gimple-streamer-out.c: Likewise. * gimple-walk.c: Likewise. * gimple.c: Likewise. * gimplify-me.c: Likewise. * gimplify.c: Likewise. * godump.c: Likewise. * graph.c: Likewise. * graphite-blocking.c: Likewise. * graphite-dependences.c: Likewise. * graphite-interchange.c: Likewise. * graphite-isl-ast-to-gimple.c: Likewise. * graphite-optimize-isl.c: Likewise. * graphite-poly.c: Likewise. * graphite-scop-detection.c: Likewise. * graphite-sese-to-poly.c: Likewise. * graphite.c: Likewise. * haifa-sched.c: Likewise. * hw-doloop.c: Likewise. * ifcvt.c: Likewise. * init-regs.c: Likewise. * internal-fn.c: Likewise. * ipa-chkp.c: Likewise. * ipa-comdats.c: Likewise. * ipa-cp.c: Likewise. * ipa-devirt.c: Likewise. * ipa-icf-gimple.c: Likewise. * ipa-icf.c: Likewise. * ipa-inline-analysis.c: Likewise. * ipa-inline-transform.c: Likewise. * ipa-inline.c: Likewise. * ipa-polymorphic-call.c: Likewise. * ipa-profile.c: Likewise. * ipa-prop.c: Likewise. * ipa-pure-const.c: Likewise. * ipa-ref.c: Likewise. * ipa-reference.c: Likewise. * ipa-split.c: Likewise. * ipa-utils.c: Likewise. * ipa-visibility.c: Likewise. * ipa.c: Likewise. * ira-build.c: Likewise. * ira-color.c: Likewise. * ira-conflicts.c: Likewise. * ira-costs.c: Likewise. * ira-emit.c: Likewise. * ira-lives.c: Likewise. * ira.c: Likewise. * jump.c: Likewise. * langhooks.c: Likewise. * lcm.c: Likewise. * loop-doloop.c: Likewise. * loop-init.c: Likewise. * loop-invariant.c: Likewise. * loop-iv.c: Likewise. * loop-unroll.c: Likewise. * lower-subreg.c: Likewise. * lra-assigns.c: Likewise. * lra-coalesce.c: Likewise. * lra-constraints.c: Likewise. * lra-eliminations.c: Likewise. * lra-lives.c: Likewise. * lra-remat.c: Likewise. * lra-spills.c: Likewise. * lra.c: Likewise. * lto-cgraph.c: Likewise. * lto-compress.c: Likewise. * lto-opts.c: Likewise. * lto-section-in.c: Likewise. * lto-section-out.c: Likewise. * lto-streamer-in.c: Likewise. * lto-streamer-out.c: Likewise. * lto-streamer.c: Likewise. * mcf.c: Likewise. * mode-switching.c: Likewise. * modulo-sched.c: Likewise. * omega.c: Likewise. * omp-low.c: Likewise. * optabs.c: Likewise. * opts-global.c: Likewise. * passes.c: Likewise. * plugin.c: Likewise. * postreload-gcse.c: Likewise. * postreload.c: Likewise. * predict.c: Likewise. * print-rtl.c: Likewise. * print-tree.c: Likewise. * profile.c: Likewise. * real.c: Likewise. * realmpfr.c: Likewise. * recog.c: Likewise. * ree.c: Likewise. * reg-stack.c: Likewise. * regcprop.c: Likewise. * reginfo.c: Likewise. * regrename.c: Likewise. * regstat.c: Likewise. * reload.c: Likewise. * reload1.c: Likewise. * reorg.c: Likewise. * resource.c: Likewise. * rtl-chkp.c: Likewise. * rtlanal.c: Likewise. * rtlhooks.c: Likewise. * sanopt.c: Likewise. * sched-deps.c: Likewise. * sched-ebb.c: Likewise. * sched-rgn.c: Likewise. * sched-vis.c: Likewise. * sdbout.c: Likewise. * sel-sched-dump.c: Likewise. * sel-sched-ir.c: Likewise. * sel-sched.c: Likewise. * sese.c: Likewise. * shrink-wrap.c: Likewise. * simplify-rtx.c: Likewise. * stack-ptr-mod.c: Likewise. * stmt.c: Likewise. * stor-layout.c: Likewise. * store-motion.c: Likewise. * stringpool.c: Likewise. * symtab.c: Likewise. * target-globals.c: Likewise. * targhooks.c: Likewise. * toplev.c: Likewise. * tracer.c: Likewise. * trans-mem.c: Likewise. * tree-affine.c: Likewise. * tree-browser.c: Likewise. * tree-call-cdce.c: Likewise. * tree-cfg.c: Likewise. * tree-cfgcleanup.c: Likewise. * tree-chkp-opt.c: Likewise. * tree-chkp.c: Likewise. * tree-chrec.c: Likewise. * tree-complex.c: Likewise. * tree-data-ref.c: Likewise. * tree-dfa.c: Likewise. * tree-diagnostic.c: Likewise. * tree-dump.c: Likewise. * tree-eh.c: Likewise. * tree-emutls.c: Likewise. * tree-if-conv.c: Likewise. * tree-inline.c: Likewise. * tree-into-ssa.c: Likewise. * tree-iterator.c: Likewise. * tree-loop-distribution.c: Likewise. * tree-nested.c: Likewise. * tree-nrv.c: Likewise. * tree-object-size.c: Likewise. * tree-outof-ssa.c: Likewise. * tree-parloops.c: Likewise. * tree-phinodes.c: Likewise. * tree-predcom.c: Likewise. * tree-pretty-print.c: Likewise. * tree-profile.c: Likewise. * tree-scalar-evolution.c: Likewise. * tree-sra.c: Likewise. * tree-ssa-address.c: Likewise. * tree-ssa-alias.c: Likewise. * tree-ssa-ccp.c: Likewise. * tree-ssa-coalesce.c: Likewise. * tree-ssa-copy.c: Likewise. * tree-ssa-copyrename.c: Likewise. * tree-ssa-dce.c: Likewise. * tree-ssa-dom.c: Likewise. * tree-ssa-dse.c: Likewise. * tree-ssa-forwprop.c: Likewise. * tree-ssa-ifcombine.c: Likewise. * tree-ssa-live.c: Likewise. * tree-ssa-loop-ch.c: Likewise. * tree-ssa-loop-im.c: Likewise. * tree-ssa-loop-ivcanon.c: Likewise. * tree-ssa-loop-ivopts.c: Likewise. * tree-ssa-loop-manip.c: Likewise. * tree-ssa-loop-niter.c: Likewise. * tree-ssa-loop-prefetch.c: Likewise. * tree-ssa-loop-unswitch.c: Likewise. * tree-ssa-loop.c: Likewise. * tree-ssa-math-opts.c: Likewise. * tree-ssa-operands.c: Likewise. * tree-ssa-phiopt.c: Likewise. * tree-ssa-phiprop.c: Likewise. * tree-ssa-pre.c: Likewise. * tree-ssa-propagate.c: Likewise. * tree-ssa-reassoc.c: Likewise. * tree-ssa-sccvn.c: Likewise. * tree-ssa-scopedtables.c: Likewise. * tree-ssa-sink.c: Likewise. * tree-ssa-strlen.c: Likewise. * tree-ssa-structalias.c: Likewise. * tree-ssa-tail-merge.c: Likewise. * tree-ssa-ter.c: Likewise. * tree-ssa-threadedge.c: Likewise. * tree-ssa-threadupdate.c: Likewise. * tree-ssa-uncprop.c: Likewise. * tree-ssa-uninit.c: Likewise. * tree-ssa.c: Likewise. * tree-ssanames.c: Likewise. * tree-stdarg.c: Likewise. * tree-streamer-in.c: Likewise. * tree-streamer-out.c: Likewise. * tree-streamer.c: Likewise. * tree-switch-conversion.c: Likewise. * tree-tailcall.c: Likewise. * tree-vect-data-refs.c: Likewise. * tree-vect-generic.c: Likewise. * tree-vect-loop-manip.c: Likewise. * tree-vect-loop.c: Likewise. * tree-vect-patterns.c: Likewise. * tree-vect-slp.c: Likewise. * tree-vect-stmts.c: Likewise. * tree-vectorizer.c: Likewise. * tree-vrp.c: Likewise. * tree.c: Likewise. * tsan.c: Likewise. * ubsan.c: Likewise. * valtrack.c: Likewise. * value-prof.c: Likewise. * var-tracking.c: Likewise. * varasm.c: Likewise. * varpool.c: Likewise. * vmsdbgout.c: Likewise. * vtable-verify.c: Likewise. * web.c: Likewise. * wide-int.cc: Likewise. * xcoffout.c: Likewise. * config/aarch64/aarch64-builtins.c: Likewise. * config/aarch64/aarch64.c: Likewise. * config/aarch64/cortex-a57-fma-steering.c: Likewise. * config/alpha/alpha.c: Likewise. * config/arc/arc.c: Likewise. * config/arm/aarch-common.c: Likewise. * config/arm/arm-builtins.c: Likewise. * config/arm/arm-c.c: Likewise. * config/arm/arm.c: Likewise. * config/avr/avr-c.c: Likewise. * config/avr/avr-log.c: Likewise. * config/avr/avr.c: Likewise. * config/bfin/bfin.c: Likewise. * config/c6x/c6x.c: Likewise. * config/cr16/cr16.c: Likewise. * config/cris/cris.c: Likewise. * config/darwin-c.c: Likewise. * config/darwin.c: Likewise. * config/epiphany/epiphany.c: Likewise. * config/epiphany/mode-switch-use.c: Likewise. * config/epiphany/resolve-sw-modes.c: Likewise. * config/fr30/fr30.c: Likewise. * config/frv/frv.c: Likewise. * config/ft32/ft32.c: Likewise. * config/h8300/h8300.c: Likewise. * config/i386/i386-c.c: Likewise. * config/i386/i386.c: Likewise. * config/i386/msformat-c.c: Likewise. * config/i386/winnt-cxx.c: Likewise. * config/i386/winnt-stubs.c: Likewise. * config/i386/winnt.c: Likewise. * config/ia64/ia64-c.c: Likewise. * config/ia64/ia64.c: Likewise. * config/iq2000/iq2000.c: Likewise. * config/lm32/lm32.c: Likewise. * config/m32c/m32c-pragma.c: Likewise. * config/m32c/m32c.c: Likewise. * config/m32r/m32r.c: Likewise. * config/m68k/m68k.c: Likewise. * config/mcore/mcore.c: Likewise. * config/mep/mep-pragma.c: Likewise. * config/mep/mep.c: Likewise. * config/microblaze/microblaze-c.c: Likewise. * config/microblaze/microblaze.c: Likewise. * config/mips/mips.c: Likewise. * config/mmix/mmix.c: Likewise. * config/mn10300/mn10300.c: Likewise. * config/moxie/moxie.c: Likewise. * config/msp430/msp430-c.c: Likewise. * config/msp430/msp430.c: Likewise. * config/nds32/nds32-cost.c: Likewise. * config/nds32/nds32-fp-as-gp.c: Likewise. * config/nds32/nds32-intrinsic.c: Likewise. * config/nds32/nds32-isr.c: Likewise. * config/nds32/nds32-md-auxiliary.c: Likewise. * config/nds32/nds32-memory-manipulation.c: Likewise. * config/nds32/nds32-pipelines-auxiliary.c: Likewise. * config/nds32/nds32-predicates.c: Likewise. * config/nds32/nds32.c: Likewise. * config/nios2/nios2.c: Likewise. * config/nvptx/nvptx.c: Likewise. * config/pa/pa.c: Likewise. * config/pdp11/pdp11.c: Likewise. * config/rl78/rl78-c.c: Likewise. * config/rl78/rl78.c: Likewise. * config/rs6000/rs6000-c.c: Likewise. * config/rs6000/rs6000.c: Likewise. * config/rx/rx.c: Likewise. * config/s390/s390-c.c: Likewise. * config/s390/s390.c: Likewise. * config/sh/sh-c.c: Likewise. * config/sh/sh-mem.cc: Likewise. * config/sh/sh.c: Likewise. * config/sh/sh_optimize_sett_clrt.cc: Likewise. * config/sh/sh_treg_combine.cc: Likewise. * config/sol2-c.c: Likewise. * config/sol2-cxx.c: Likewise. * config/sol2-stubs.c: Likewise. * config/sol2.c: Likewise. * config/sparc/sparc-c.c: Likewise. * config/sparc/sparc.c: Likewise. * config/spu/spu-c.c: Likewise. * config/spu/spu.c: Likewise. * config/stormy16/stormy16.c: Likewise. * config/tilegx/mul-tables.c: Likewise. * config/tilegx/tilegx-c.c: Likewise. * config/tilegx/tilegx.c: Likewise. * config/tilepro/mul-tables.c: Likewise. * config/tilepro/tilepro-c.c: Likewise. * config/tilepro/tilepro.c: Likewise. * config/v850/v850-c.c: Likewise. * config/v850/v850.c: Likewise. * config/vax/vax.c: Likewise. * config/visium/visium.c: Likewise. * config/vms/vms-c.c: Likewise. * config/vms/vms.c: Likewise. * config/vxworks.c: Likewise. * config/xtensa/xtensa.c: Likewise. ada 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * gcc-interface/cuintp.c: Adjust includes. * gcc-interface/decl.c: Likewise. * gcc-interface/misc.c: Likewise. * gcc-interface/targtyps.c: Likewise. * gcc-interface/trans.c: Likewise. * gcc-interface/utils.c: Likewise. * gcc-interface/utils2.c: Likewise. c 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * c-array-notation.c: Adjust includes. * c-aux-info.c: Likewise. * c-convert.c: Likewise. * c-decl.c: Likewise. * c-errors.c: Likewise. * c-lang.c: Likewise. * c-objc-common.c: Likewise. * c-parser.c: Likewise. * c-typeck.c: Likewise. c-family 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * array-notation-common.c: Adjust includes. * c-ada-spec.c: Likewise. * c-cilkplus.c: Likewise. * c-common.h: Likewise. * c-cppbuiltin.c: Likewise. * c-dump.c: Likewise. * c-format.c: Likewise. * c-gimplify.c: Likewise. * c-indentation.c: Likewise. * c-lex.c: Likewise. * c-omp.c: Likewise. * c-opts.c: Likewise. * c-pch.c: Likewise. * c-ppoutput.c: Likewise. * c-pragma.c: Likewise. * c-pretty-print.c: Likewise. * c-semantics.c: Likewise. * c-ubsan.c: Likewise. * cilk.c: Likewise. * stub-objc.c: Likewise. cp 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * call.c: Adjust includes. * class.c: Likewise. * constexpr.c: Likewise. * cp-array-notation.c: Likewise. * cp-gimplify.c: Likewise. * cp-lang.c: Likewise. * cp-objcp-common.c: Likewise. * cp-ubsan.c: Likewise. * cvt.c: Likewise. * decl.c: Likewise. * decl2.c: Likewise. * dump.c: Likewise. * error.c: Likewise. * except.c: Likewise. * expr.c: Likewise. * friend.c: Likewise. * init.c: Likewise. * lambda.c: Likewise. * lex.c: Likewise. * mangle.c: Likewise. * method.c: Likewise. * name-lookup.c: Likewise. * optimize.c: Likewise. * parser.c: Likewise. * pt.c: Likewise. * ptree.c: Likewise. * repo.c: Likewise. * rtti.c: Likewise. * search.c: Likewise. * semantics.c: Likewise. * tree.c: Likewise. * typeck.c: Likewise. * typeck2.c: Likewise. fortran 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * convert.c: Adjust includes. * cpp.c: Likewise. * decl.c: Likewise. * f95-lang.c: Likewise. * iresolve.c: Likewise. * match.c: Likewise. * module.c: Likewise. * options.c: Likewise. * target-memory.c: Likewise. * trans-array.c: Likewise. * trans-common.c: Likewise. * trans-const.c: Likewise. * trans-decl.c: Likewise. * trans-expr.c: Likewise. * trans-intrinsic.c: Likewise. * trans-io.c: Likewise. * trans-openmp.c: Likewise. * trans-stmt.c: Likewise. * trans-types.c: Likewise. * trans.c: Likewise. go 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * go-backend.c: Adjust includes. * go-gcc.cc: Likewise. * go-lang.c: Likewise. java 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * boehm.c: Adjust includes. * builtins.c: Likewise. * class.c: Likewise. * constants.c: Likewise. * decl.c: Likewise. * except.c: Likewise. * expr.c: Likewise. * java-gimplify.c: Likewise. * jcf-dump.c: Likewise. * jcf-io.c: Likewise. * jcf-parse.c: Likewise. * jvgenmain.c: Likewise. * lang.c: Likewise. * mangle.c: Likewise. * mangle_name.c: Likewise. * resource.c: Likewise. * typeck.c: Likewise. * verify-glue.c: Likewise. jit 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * dummy-frontend.c: Adjust includes. * jit-common.h: Likewise. * jit-playback.c: Likewise. lto 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * lto-lang.c: Adjust includes. * lto-object.c: Likewise. * lto-partition.c: Likewise. * lto-symtab.c: Likewise. * lto.c: Likewise. objc 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * objc-act.c: Adjust includes. * objc-encoding.c: Likewise. * objc-gnu-runtime-abi-01.c: Likewise. * objc-lang.c: Likewise. * objc-map.c: Likewise. * objc-next-runtime-abi-01.c: Likewise. * objc-next-runtime-abi-02.c: Likewise. * objc-runtime-shared-support.c: Likewise. objcp 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * objcp-decl.c: Adjust includes. * objcp-lang.c: Likewise. From-SVN: r225531
2015-07-08 02:53:03 +02:00
#include "backend.h"
alias.c: Reorder #include statements and remove duplicates. 2015-10-29 Andrew MacLeod <amacleod@redhat.com> * alias.c: Reorder #include statements and remove duplicates. * asan.c: Likewise. * attribs.c: Likewise. * auto-inc-dec.c: Likewise. * auto-profile.c: Likewise. * bb-reorder.c: Likewise. * bt-load.c: Likewise. * builtins.c: Likewise. * caller-save.c: Likewise. * calls.c: Likewise. * ccmp.c: Likewise. * cfg.c: Likewise. * cfganal.c: Likewise. * cfgbuild.c: Likewise. * cfgcleanup.c: Likewise. * cfgexpand.c: Likewise. * cfghooks.c: Likewise. * cfgloop.c: Likewise. * cfgloopanal.c: Likewise. * cfgloopmanip.c: Likewise. * cfgrtl.c: Likewise. * cgraph.c: Likewise. * cgraphbuild.c: Likewise. * cgraphclones.c: Likewise. * cgraphunit.c: Likewise. * cilk-common.c: Likewise. * combine-stack-adj.c: Likewise. * combine.c: Likewise. * compare-elim.c: Likewise. * convert.c: Likewise. * coverage.c: Likewise. * cppbuiltin.c: Likewise. * cprop.c: Likewise. * cse.c: Likewise. * cselib.c: Likewise. * data-streamer-in.c: Likewise. * data-streamer-out.c: Likewise. * data-streamer.c: Likewise. * dbxout.c: Likewise. * dce.c: Likewise. * ddg.c: Likewise. * debug.c: Likewise. * df-core.c: Likewise. * df-problems.c: Likewise. * df-scan.c: Likewise. * dfp.c: Likewise. * dojump.c: Likewise. * dominance.c: Likewise. * double-int.c: Likewise. * dse.c: Likewise. * dumpfile.c: Likewise. * dwarf2asm.c: Likewise. * dwarf2cfi.c: Likewise. * dwarf2out.c: Likewise. * emit-rtl.c: Likewise. * except.c: Likewise. * explow.c: Likewise. * expmed.c: Likewise. * expr.c: Likewise. * final.c: Likewise. * fixed-value.c: Likewise. * fold-const.c: Likewise. * function.c: Likewise. * fwprop.c: Likewise. * gcse.c: Likewise. * generic-match-head.c: Likewise. * ggc-common.c: Likewise. * gimple-builder.c: Likewise. * gimple-expr.c: Likewise. * gimple-fold.c: Likewise. * gimple-iterator.c: Likewise. * gimple-low.c: Likewise. * gimple-match-head.c: Likewise. * gimple-pretty-print.c: Likewise. * gimple-ssa-isolate-paths.c: Likewise. * gimple-ssa-strength-reduction.c: Likewise. * gimple-streamer-in.c: Likewise. * gimple-streamer-out.c: Likewise. * gimple-walk.c: Likewise. * gimple.c: Likewise. * gimplify-me.c: Likewise. * gimplify.c: Likewise. * godump.c: Likewise. * graph.c: Likewise. * graphite-poly.c: Likewise. * haifa-sched.c: Likewise. * hw-doloop.c: Likewise. * ifcvt.c: Likewise. * incpath.c: Likewise. * init-regs.c: Likewise. * internal-fn.c: Likewise. * ipa-chkp.c: Likewise. * ipa-comdats.c: Likewise. * ipa-cp.c: Likewise. * ipa-devirt.c: Likewise. * ipa-icf-gimple.c: Likewise. * ipa-icf.c: Likewise. * ipa-inline-analysis.c: Likewise. * ipa-inline-transform.c: Likewise. * ipa-inline.c: Likewise. * ipa-polymorphic-call.c: Likewise. * ipa-profile.c: Likewise. * ipa-prop.c: Likewise. * ipa-pure-const.c: Likewise. * ipa-ref.c: Likewise. * ipa-reference.c: Likewise. * ipa-split.c: Likewise. * ipa-utils.c: Likewise. * ipa-visibility.c: Likewise. * ipa.c: Likewise. * ira-build.c: Likewise. * ira-color.c: Likewise. * ira-conflicts.c: Likewise. * ira-costs.c: Likewise. * ira-emit.c: Likewise. * ira-lives.c: Likewise. * ira.c: Likewise. * jump.c: Likewise. * langhooks.c: Likewise. * lcm.c: Likewise. * lists.c: Likewise. * loop-doloop.c: Likewise. * loop-init.c: Likewise. * loop-invariant.c: Likewise. * loop-iv.c: Likewise. * loop-unroll.c: Likewise. * lower-subreg.c: Likewise. * lra-assigns.c: Likewise. * lra-coalesce.c: Likewise. * lra-constraints.c: Likewise. * lra-eliminations.c: Likewise. * lra-lives.c: Likewise. * lra-remat.c: Likewise. * lra-spills.c: Likewise. * lra.c: Likewise. * lto-cgraph.c: Likewise. * lto-compress.c: Likewise. * lto-opts.c: Likewise. * lto-section-in.c: Likewise. * lto-section-out.c: Likewise. * lto-streamer-in.c: Likewise. * lto-streamer-out.c: Likewise. * lto-streamer.c: Likewise. * mode-switching.c: Likewise. * modulo-sched.c: Likewise. * omp-low.c: Likewise. * optabs.c: Likewise. * opts-global.c: Likewise. * passes.c: Likewise. * plugin.c: Likewise. * postreload-gcse.c: Likewise. * postreload.c: Likewise. * predict.c: Likewise. * print-tree.c: Likewise. * profile.c: Likewise. * real.c: Likewise. * realmpfr.c: Likewise. * recog.c: Likewise. * ree.c: Likewise. * reg-stack.c: Likewise. * regcprop.c: Likewise. * reginfo.c: Likewise. * regrename.c: Likewise. * regstat.c: Likewise. * reload.c: Likewise. * reload1.c: Likewise. * reorg.c: Likewise. * resource.c: Likewise. * rtl-chkp.c: Likewise. * rtl-error.c: Likewise. * rtlanal.c: Likewise. * rtlhooks.c: Likewise. * sanopt.c: Likewise. * sched-deps.c: Likewise. * sched-ebb.c: Likewise. * sched-rgn.c: Likewise. * sese.c: Likewise. * shrink-wrap.c: Likewise. * simplify-rtx.c: Likewise. * stack-ptr-mod.c: Likewise. * statistics.c: Likewise. * stmt.c: Likewise. * stor-layout.c: Likewise. * store-motion.c: Likewise. * stringpool.c: Likewise. * symtab.c: Likewise. * target-globals.c: Likewise. * targhooks.c: Likewise. * toplev.c: Likewise. * tracer.c: Likewise. * trans-mem.c: Likewise. * tree-affine.c: Likewise. * tree-call-cdce.c: Likewise. * tree-cfg.c: Likewise. * tree-cfgcleanup.c: Likewise. * tree-chkp-opt.c: Likewise. * tree-chkp.c: Likewise. * tree-chrec.c: Likewise. * tree-complex.c: Likewise. * tree-data-ref.c: Likewise. * tree-dfa.c: Likewise. * tree-diagnostic.c: Likewise. * tree-dump.c: Likewise. * tree-eh.c: Likewise. * tree-emutls.c: Likewise. * tree-if-conv.c: Likewise. * tree-inline.c: Likewise. * tree-into-ssa.c: Likewise. * tree-iterator.c: Likewise. * tree-loop-distribution.c: Likewise. * tree-nested.c: Likewise. * tree-nrv.c: Likewise. * tree-object-size.c: Likewise. * tree-outof-ssa.c: Likewise. * tree-parloops.c: Likewise. * tree-phinodes.c: Likewise. * tree-predcom.c: Likewise. * tree-pretty-print.c: Likewise. * tree-profile.c: Likewise. * tree-scalar-evolution.c: Likewise. * tree-sra.c: Likewise. * tree-ssa-address.c: Likewise. * tree-ssa-alias.c: Likewise. * tree-ssa-ccp.c: Likewise. * tree-ssa-coalesce.c: Likewise. * tree-ssa-copy.c: Likewise. * tree-ssa-dce.c: Likewise. * tree-ssa-dom.c: Likewise. * tree-ssa-dse.c: Likewise. * tree-ssa-forwprop.c: Likewise. * tree-ssa-ifcombine.c: Likewise. * tree-ssa-live.c: Likewise. * tree-ssa-loop-ch.c: Likewise. * tree-ssa-loop-im.c: Likewise. * tree-ssa-loop-ivcanon.c: Likewise. * tree-ssa-loop-ivopts.c: Likewise. * tree-ssa-loop-manip.c: Likewise. * tree-ssa-loop-niter.c: Likewise. * tree-ssa-loop-prefetch.c: Likewise. * tree-ssa-loop-unswitch.c: Likewise. * tree-ssa-loop.c: Likewise. * tree-ssa-math-opts.c: Likewise. * tree-ssa-operands.c: Likewise. * tree-ssa-phiopt.c: Likewise. * tree-ssa-phiprop.c: Likewise. * tree-ssa-pre.c: Likewise. * tree-ssa-propagate.c: Likewise. * tree-ssa-reassoc.c: Likewise. * tree-ssa-sccvn.c: Likewise. * tree-ssa-scopedtables.c: Likewise. * tree-ssa-sink.c: Likewise. * tree-ssa-strlen.c: Likewise. * tree-ssa-structalias.c: Likewise. * tree-ssa-tail-merge.c: Likewise. * tree-ssa-ter.c: Likewise. * tree-ssa-threadedge.c: Likewise. * tree-ssa-threadupdate.c: Likewise. * tree-ssa-uncprop.c: Likewise. * tree-ssa-uninit.c: Likewise. * tree-ssa.c: Likewise. * tree-ssanames.c: Likewise. * tree-stdarg.c: Likewise. * tree-streamer-in.c: Likewise. * tree-streamer-out.c: Likewise. * tree-streamer.c: Likewise. * tree-switch-conversion.c: Likewise. * tree-tailcall.c: Likewise. * tree-vect-data-refs.c: Likewise. * tree-vect-generic.c: Likewise. * tree-vect-loop-manip.c: Likewise. * tree-vect-loop.c: Likewise. * tree-vect-patterns.c: Likewise. * tree-vect-slp.c: Likewise. * tree-vect-stmts.c: Likewise. * tree-vectorizer.c: Likewise. * tree-vrp.c: Likewise. * tree.c: Likewise. * tsan.c: Likewise. * ubsan.c: Likewise. * value-prof.c: Likewise. * var-tracking.c: Likewise. * varasm.c: Likewise. * varpool.c: Likewise. * vtable-verify.c: Likewise. * web.c: Likewise. * wide-int-print.cc: Likewise. * wide-int.cc: Likewise. * xcoffout.c: Likewise. From-SVN: r229526
2015-10-29 14:57:32 +01:00
#include "rtl.h"
#include "c-family/c-common.h"
tree-core.h: Include symtab.h. 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * tree-core.h: Include symtab.h. * rtl.h: Include hard-reg-set.h but not flags.h. (HARD_CONST): Remove condition compilation involving HARD_CONST since hard-reg-set.h is always included. * regs.h: Don't include hard-reg-set.h or rtl.h. * cfg.h: Include dominance.h. * gimple.h: Include tree-ssa-alias.h and gimple-expr.h. * backend.h: New. Aggregate commonly used backend header files. * gimple-ssa.h: Don't include tree-hasher.h. * ssa.h: New. Aggregate commonly used SSA header files. * regset.h: Remove bitmap.h and hard-reg-set.h #includes. * sel-sched-ir.h: Flatten includes. * lra-int.h: Flatten completely. * sel-sched-dump.h: Flatten includes. * ira-int.h: Flatten includes. * gimple-streamer.h: Remove all includes. * cfgloop.h: Remove all #includes except cfgloopmanip.h. * resource.h: Flatten hard-reg-set.h and df.h. * sched-int.h: Flatten insn-arrt.h and df.h. * valtrack.h: flatten bitmap.h, df.h, and rtl.h * df.h: Flatten includes, leaving regset.h, alloc-pool.h and timevar.h. * genattrtab.c (write_header): Adjust generated includes. * genautomata.c (main): Likewise. * genconditions.c (write-header): Likewise. * genemit.c (main): Likewise. * gengtype.c (open_base_files): Likewise. * genopinit.c (main): Likewise. * genoutput.c (output_prologue): Likewise. * genpeep.c (main): Likewise. * genpreds.c (write_insn_preds_c): Likewise. * genrecog.c (write_header): Likewise. * alias.c: Adjust includes. * asan.c: Likewise. * attribs.c: Likewise. * auto-inc-dec.c: Likewise. * auto-profile.c: Likewise. * bb-reorder.c: Likewise. * bt-load.c: Likewise. * builtins.c: Likewise. * caller-save.c: Likewise. * calls.c: Likewise. * ccmp.c: Likewise. * cfg.c: Likewise. * cfganal.c: Likewise. * cfgbuild.c: Likewise. * cfgcleanup.c: Likewise. * cfgexpand.c: Likewise. * cfghooks.c: Likewise. * cfgloop.c: Likewise. * cfgloopanal.c: Likewise. * cfgloopmanip.c: Likewise. * cfgrtl.c: Likewise. * cgraph.c: Likewise. * cgraphbuild.c: Likewise. * cgraphclones.c: Likewise. * cgraphunit.c: Likewise. * cilk-common.c: Likewise. * combine-stack-adj.c: Likewise. * combine.c: Likewise. * compare-elim.c: Likewise. * convert.c: Likewise. * coverage.c: Likewise. * cppbuiltin.c: Likewise. * cprop.c: Likewise. * cse.c: Likewise. * cselib.c: Likewise. * data-streamer-in.c: Likewise. * data-streamer-out.c: Likewise. * data-streamer.c: Likewise. * dbxout.c: Likewise. * dce.c: Likewise. * ddg.c: Likewise. * debug.c: Likewise. * df-core.c: Likewise. * df-problems.c: Likewise. * df-scan.c: Likewise. * dfp.c: Likewise. * dojump.c: Likewise. * dominance.c: Likewise. * domwalk.c: Likewise. * double-int.c: Likewise. * dse.c: Likewise. * dumpfile.c: Likewise. * dwarf2asm.c: Likewise. * dwarf2cfi.c: Likewise. * dwarf2out.c: Likewise. * emit-rtl.c: Likewise. * et-forest.c: Likewise. * except.c: Likewise. * explow.c: Likewise. * expmed.c: Likewise. * expr.c: Likewise. * final.c: Likewise. * fixed-value.c: Likewise. * fold-const.c: Likewise. * function.c: Likewise. * fwprop.c: Likewise. * gcc-plugin.h: Likewise. * gcse-common.c: Likewise. * gcse.c: Likewise. * generic-match-head.c: Likewise. * ggc-page.c: Likewise. * gimple-builder.c: Likewise. * gimple-expr.c: Likewise. * gimple-fold.c: Likewise. * gimple-iterator.c: Likewise. * gimple-low.c: Likewise. * gimple-match-head.c: Likewise. * gimple-pretty-print.c: Likewise. * gimple-ssa-isolate-paths.c: Likewise. * gimple-ssa-strength-reduction.c: Likewise. * gimple-streamer-in.c: Likewise. * gimple-streamer-out.c: Likewise. * gimple-walk.c: Likewise. * gimple.c: Likewise. * gimplify-me.c: Likewise. * gimplify.c: Likewise. * godump.c: Likewise. * graph.c: Likewise. * graphite-blocking.c: Likewise. * graphite-dependences.c: Likewise. * graphite-interchange.c: Likewise. * graphite-isl-ast-to-gimple.c: Likewise. * graphite-optimize-isl.c: Likewise. * graphite-poly.c: Likewise. * graphite-scop-detection.c: Likewise. * graphite-sese-to-poly.c: Likewise. * graphite.c: Likewise. * haifa-sched.c: Likewise. * hw-doloop.c: Likewise. * ifcvt.c: Likewise. * init-regs.c: Likewise. * internal-fn.c: Likewise. * ipa-chkp.c: Likewise. * ipa-comdats.c: Likewise. * ipa-cp.c: Likewise. * ipa-devirt.c: Likewise. * ipa-icf-gimple.c: Likewise. * ipa-icf.c: Likewise. * ipa-inline-analysis.c: Likewise. * ipa-inline-transform.c: Likewise. * ipa-inline.c: Likewise. * ipa-polymorphic-call.c: Likewise. * ipa-profile.c: Likewise. * ipa-prop.c: Likewise. * ipa-pure-const.c: Likewise. * ipa-ref.c: Likewise. * ipa-reference.c: Likewise. * ipa-split.c: Likewise. * ipa-utils.c: Likewise. * ipa-visibility.c: Likewise. * ipa.c: Likewise. * ira-build.c: Likewise. * ira-color.c: Likewise. * ira-conflicts.c: Likewise. * ira-costs.c: Likewise. * ira-emit.c: Likewise. * ira-lives.c: Likewise. * ira.c: Likewise. * jump.c: Likewise. * langhooks.c: Likewise. * lcm.c: Likewise. * loop-doloop.c: Likewise. * loop-init.c: Likewise. * loop-invariant.c: Likewise. * loop-iv.c: Likewise. * loop-unroll.c: Likewise. * lower-subreg.c: Likewise. * lra-assigns.c: Likewise. * lra-coalesce.c: Likewise. * lra-constraints.c: Likewise. * lra-eliminations.c: Likewise. * lra-lives.c: Likewise. * lra-remat.c: Likewise. * lra-spills.c: Likewise. * lra.c: Likewise. * lto-cgraph.c: Likewise. * lto-compress.c: Likewise. * lto-opts.c: Likewise. * lto-section-in.c: Likewise. * lto-section-out.c: Likewise. * lto-streamer-in.c: Likewise. * lto-streamer-out.c: Likewise. * lto-streamer.c: Likewise. * mcf.c: Likewise. * mode-switching.c: Likewise. * modulo-sched.c: Likewise. * omega.c: Likewise. * omp-low.c: Likewise. * optabs.c: Likewise. * opts-global.c: Likewise. * passes.c: Likewise. * plugin.c: Likewise. * postreload-gcse.c: Likewise. * postreload.c: Likewise. * predict.c: Likewise. * print-rtl.c: Likewise. * print-tree.c: Likewise. * profile.c: Likewise. * real.c: Likewise. * realmpfr.c: Likewise. * recog.c: Likewise. * ree.c: Likewise. * reg-stack.c: Likewise. * regcprop.c: Likewise. * reginfo.c: Likewise. * regrename.c: Likewise. * regstat.c: Likewise. * reload.c: Likewise. * reload1.c: Likewise. * reorg.c: Likewise. * resource.c: Likewise. * rtl-chkp.c: Likewise. * rtlanal.c: Likewise. * rtlhooks.c: Likewise. * sanopt.c: Likewise. * sched-deps.c: Likewise. * sched-ebb.c: Likewise. * sched-rgn.c: Likewise. * sched-vis.c: Likewise. * sdbout.c: Likewise. * sel-sched-dump.c: Likewise. * sel-sched-ir.c: Likewise. * sel-sched.c: Likewise. * sese.c: Likewise. * shrink-wrap.c: Likewise. * simplify-rtx.c: Likewise. * stack-ptr-mod.c: Likewise. * stmt.c: Likewise. * stor-layout.c: Likewise. * store-motion.c: Likewise. * stringpool.c: Likewise. * symtab.c: Likewise. * target-globals.c: Likewise. * targhooks.c: Likewise. * toplev.c: Likewise. * tracer.c: Likewise. * trans-mem.c: Likewise. * tree-affine.c: Likewise. * tree-browser.c: Likewise. * tree-call-cdce.c: Likewise. * tree-cfg.c: Likewise. * tree-cfgcleanup.c: Likewise. * tree-chkp-opt.c: Likewise. * tree-chkp.c: Likewise. * tree-chrec.c: Likewise. * tree-complex.c: Likewise. * tree-data-ref.c: Likewise. * tree-dfa.c: Likewise. * tree-diagnostic.c: Likewise. * tree-dump.c: Likewise. * tree-eh.c: Likewise. * tree-emutls.c: Likewise. * tree-if-conv.c: Likewise. * tree-inline.c: Likewise. * tree-into-ssa.c: Likewise. * tree-iterator.c: Likewise. * tree-loop-distribution.c: Likewise. * tree-nested.c: Likewise. * tree-nrv.c: Likewise. * tree-object-size.c: Likewise. * tree-outof-ssa.c: Likewise. * tree-parloops.c: Likewise. * tree-phinodes.c: Likewise. * tree-predcom.c: Likewise. * tree-pretty-print.c: Likewise. * tree-profile.c: Likewise. * tree-scalar-evolution.c: Likewise. * tree-sra.c: Likewise. * tree-ssa-address.c: Likewise. * tree-ssa-alias.c: Likewise. * tree-ssa-ccp.c: Likewise. * tree-ssa-coalesce.c: Likewise. * tree-ssa-copy.c: Likewise. * tree-ssa-copyrename.c: Likewise. * tree-ssa-dce.c: Likewise. * tree-ssa-dom.c: Likewise. * tree-ssa-dse.c: Likewise. * tree-ssa-forwprop.c: Likewise. * tree-ssa-ifcombine.c: Likewise. * tree-ssa-live.c: Likewise. * tree-ssa-loop-ch.c: Likewise. * tree-ssa-loop-im.c: Likewise. * tree-ssa-loop-ivcanon.c: Likewise. * tree-ssa-loop-ivopts.c: Likewise. * tree-ssa-loop-manip.c: Likewise. * tree-ssa-loop-niter.c: Likewise. * tree-ssa-loop-prefetch.c: Likewise. * tree-ssa-loop-unswitch.c: Likewise. * tree-ssa-loop.c: Likewise. * tree-ssa-math-opts.c: Likewise. * tree-ssa-operands.c: Likewise. * tree-ssa-phiopt.c: Likewise. * tree-ssa-phiprop.c: Likewise. * tree-ssa-pre.c: Likewise. * tree-ssa-propagate.c: Likewise. * tree-ssa-reassoc.c: Likewise. * tree-ssa-sccvn.c: Likewise. * tree-ssa-scopedtables.c: Likewise. * tree-ssa-sink.c: Likewise. * tree-ssa-strlen.c: Likewise. * tree-ssa-structalias.c: Likewise. * tree-ssa-tail-merge.c: Likewise. * tree-ssa-ter.c: Likewise. * tree-ssa-threadedge.c: Likewise. * tree-ssa-threadupdate.c: Likewise. * tree-ssa-uncprop.c: Likewise. * tree-ssa-uninit.c: Likewise. * tree-ssa.c: Likewise. * tree-ssanames.c: Likewise. * tree-stdarg.c: Likewise. * tree-streamer-in.c: Likewise. * tree-streamer-out.c: Likewise. * tree-streamer.c: Likewise. * tree-switch-conversion.c: Likewise. * tree-tailcall.c: Likewise. * tree-vect-data-refs.c: Likewise. * tree-vect-generic.c: Likewise. * tree-vect-loop-manip.c: Likewise. * tree-vect-loop.c: Likewise. * tree-vect-patterns.c: Likewise. * tree-vect-slp.c: Likewise. * tree-vect-stmts.c: Likewise. * tree-vectorizer.c: Likewise. * tree-vrp.c: Likewise. * tree.c: Likewise. * tsan.c: Likewise. * ubsan.c: Likewise. * valtrack.c: Likewise. * value-prof.c: Likewise. * var-tracking.c: Likewise. * varasm.c: Likewise. * varpool.c: Likewise. * vmsdbgout.c: Likewise. * vtable-verify.c: Likewise. * web.c: Likewise. * wide-int.cc: Likewise. * xcoffout.c: Likewise. * config/aarch64/aarch64-builtins.c: Likewise. * config/aarch64/aarch64.c: Likewise. * config/aarch64/cortex-a57-fma-steering.c: Likewise. * config/alpha/alpha.c: Likewise. * config/arc/arc.c: Likewise. * config/arm/aarch-common.c: Likewise. * config/arm/arm-builtins.c: Likewise. * config/arm/arm-c.c: Likewise. * config/arm/arm.c: Likewise. * config/avr/avr-c.c: Likewise. * config/avr/avr-log.c: Likewise. * config/avr/avr.c: Likewise. * config/bfin/bfin.c: Likewise. * config/c6x/c6x.c: Likewise. * config/cr16/cr16.c: Likewise. * config/cris/cris.c: Likewise. * config/darwin-c.c: Likewise. * config/darwin.c: Likewise. * config/epiphany/epiphany.c: Likewise. * config/epiphany/mode-switch-use.c: Likewise. * config/epiphany/resolve-sw-modes.c: Likewise. * config/fr30/fr30.c: Likewise. * config/frv/frv.c: Likewise. * config/ft32/ft32.c: Likewise. * config/h8300/h8300.c: Likewise. * config/i386/i386-c.c: Likewise. * config/i386/i386.c: Likewise. * config/i386/msformat-c.c: Likewise. * config/i386/winnt-cxx.c: Likewise. * config/i386/winnt-stubs.c: Likewise. * config/i386/winnt.c: Likewise. * config/ia64/ia64-c.c: Likewise. * config/ia64/ia64.c: Likewise. * config/iq2000/iq2000.c: Likewise. * config/lm32/lm32.c: Likewise. * config/m32c/m32c-pragma.c: Likewise. * config/m32c/m32c.c: Likewise. * config/m32r/m32r.c: Likewise. * config/m68k/m68k.c: Likewise. * config/mcore/mcore.c: Likewise. * config/mep/mep-pragma.c: Likewise. * config/mep/mep.c: Likewise. * config/microblaze/microblaze-c.c: Likewise. * config/microblaze/microblaze.c: Likewise. * config/mips/mips.c: Likewise. * config/mmix/mmix.c: Likewise. * config/mn10300/mn10300.c: Likewise. * config/moxie/moxie.c: Likewise. * config/msp430/msp430-c.c: Likewise. * config/msp430/msp430.c: Likewise. * config/nds32/nds32-cost.c: Likewise. * config/nds32/nds32-fp-as-gp.c: Likewise. * config/nds32/nds32-intrinsic.c: Likewise. * config/nds32/nds32-isr.c: Likewise. * config/nds32/nds32-md-auxiliary.c: Likewise. * config/nds32/nds32-memory-manipulation.c: Likewise. * config/nds32/nds32-pipelines-auxiliary.c: Likewise. * config/nds32/nds32-predicates.c: Likewise. * config/nds32/nds32.c: Likewise. * config/nios2/nios2.c: Likewise. * config/nvptx/nvptx.c: Likewise. * config/pa/pa.c: Likewise. * config/pdp11/pdp11.c: Likewise. * config/rl78/rl78-c.c: Likewise. * config/rl78/rl78.c: Likewise. * config/rs6000/rs6000-c.c: Likewise. * config/rs6000/rs6000.c: Likewise. * config/rx/rx.c: Likewise. * config/s390/s390-c.c: Likewise. * config/s390/s390.c: Likewise. * config/sh/sh-c.c: Likewise. * config/sh/sh-mem.cc: Likewise. * config/sh/sh.c: Likewise. * config/sh/sh_optimize_sett_clrt.cc: Likewise. * config/sh/sh_treg_combine.cc: Likewise. * config/sol2-c.c: Likewise. * config/sol2-cxx.c: Likewise. * config/sol2-stubs.c: Likewise. * config/sol2.c: Likewise. * config/sparc/sparc-c.c: Likewise. * config/sparc/sparc.c: Likewise. * config/spu/spu-c.c: Likewise. * config/spu/spu.c: Likewise. * config/stormy16/stormy16.c: Likewise. * config/tilegx/mul-tables.c: Likewise. * config/tilegx/tilegx-c.c: Likewise. * config/tilegx/tilegx.c: Likewise. * config/tilepro/mul-tables.c: Likewise. * config/tilepro/tilepro-c.c: Likewise. * config/tilepro/tilepro.c: Likewise. * config/v850/v850-c.c: Likewise. * config/v850/v850.c: Likewise. * config/vax/vax.c: Likewise. * config/visium/visium.c: Likewise. * config/vms/vms-c.c: Likewise. * config/vms/vms.c: Likewise. * config/vxworks.c: Likewise. * config/xtensa/xtensa.c: Likewise. ada 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * gcc-interface/cuintp.c: Adjust includes. * gcc-interface/decl.c: Likewise. * gcc-interface/misc.c: Likewise. * gcc-interface/targtyps.c: Likewise. * gcc-interface/trans.c: Likewise. * gcc-interface/utils.c: Likewise. * gcc-interface/utils2.c: Likewise. c 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * c-array-notation.c: Adjust includes. * c-aux-info.c: Likewise. * c-convert.c: Likewise. * c-decl.c: Likewise. * c-errors.c: Likewise. * c-lang.c: Likewise. * c-objc-common.c: Likewise. * c-parser.c: Likewise. * c-typeck.c: Likewise. c-family 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * array-notation-common.c: Adjust includes. * c-ada-spec.c: Likewise. * c-cilkplus.c: Likewise. * c-common.h: Likewise. * c-cppbuiltin.c: Likewise. * c-dump.c: Likewise. * c-format.c: Likewise. * c-gimplify.c: Likewise. * c-indentation.c: Likewise. * c-lex.c: Likewise. * c-omp.c: Likewise. * c-opts.c: Likewise. * c-pch.c: Likewise. * c-ppoutput.c: Likewise. * c-pragma.c: Likewise. * c-pretty-print.c: Likewise. * c-semantics.c: Likewise. * c-ubsan.c: Likewise. * cilk.c: Likewise. * stub-objc.c: Likewise. cp 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * call.c: Adjust includes. * class.c: Likewise. * constexpr.c: Likewise. * cp-array-notation.c: Likewise. * cp-gimplify.c: Likewise. * cp-lang.c: Likewise. * cp-objcp-common.c: Likewise. * cp-ubsan.c: Likewise. * cvt.c: Likewise. * decl.c: Likewise. * decl2.c: Likewise. * dump.c: Likewise. * error.c: Likewise. * except.c: Likewise. * expr.c: Likewise. * friend.c: Likewise. * init.c: Likewise. * lambda.c: Likewise. * lex.c: Likewise. * mangle.c: Likewise. * method.c: Likewise. * name-lookup.c: Likewise. * optimize.c: Likewise. * parser.c: Likewise. * pt.c: Likewise. * ptree.c: Likewise. * repo.c: Likewise. * rtti.c: Likewise. * search.c: Likewise. * semantics.c: Likewise. * tree.c: Likewise. * typeck.c: Likewise. * typeck2.c: Likewise. fortran 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * convert.c: Adjust includes. * cpp.c: Likewise. * decl.c: Likewise. * f95-lang.c: Likewise. * iresolve.c: Likewise. * match.c: Likewise. * module.c: Likewise. * options.c: Likewise. * target-memory.c: Likewise. * trans-array.c: Likewise. * trans-common.c: Likewise. * trans-const.c: Likewise. * trans-decl.c: Likewise. * trans-expr.c: Likewise. * trans-intrinsic.c: Likewise. * trans-io.c: Likewise. * trans-openmp.c: Likewise. * trans-stmt.c: Likewise. * trans-types.c: Likewise. * trans.c: Likewise. go 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * go-backend.c: Adjust includes. * go-gcc.cc: Likewise. * go-lang.c: Likewise. java 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * boehm.c: Adjust includes. * builtins.c: Likewise. * class.c: Likewise. * constants.c: Likewise. * decl.c: Likewise. * except.c: Likewise. * expr.c: Likewise. * java-gimplify.c: Likewise. * jcf-dump.c: Likewise. * jcf-io.c: Likewise. * jcf-parse.c: Likewise. * jvgenmain.c: Likewise. * lang.c: Likewise. * mangle.c: Likewise. * mangle_name.c: Likewise. * resource.c: Likewise. * typeck.c: Likewise. * verify-glue.c: Likewise. jit 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * dummy-frontend.c: Adjust includes. * jit-common.h: Likewise. * jit-playback.c: Likewise. lto 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * lto-lang.c: Adjust includes. * lto-object.c: Likewise. * lto-partition.c: Likewise. * lto-symtab.c: Likewise. * lto.c: Likewise. objc 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * objc-act.c: Adjust includes. * objc-encoding.c: Likewise. * objc-gnu-runtime-abi-01.c: Likewise. * objc-lang.c: Likewise. * objc-map.c: Likewise. * objc-next-runtime-abi-01.c: Likewise. * objc-next-runtime-abi-02.c: Likewise. * objc-runtime-shared-support.c: Likewise. objcp 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * objcp-decl.c: Adjust includes. * objcp-lang.c: Likewise. From-SVN: r225531
2015-07-08 02:53:03 +02:00
#include "gimple.h"
alias.c: Reorder #include statements and remove duplicates. 2015-10-29 Andrew MacLeod <amacleod@redhat.com> * alias.c: Reorder #include statements and remove duplicates. * asan.c: Likewise. * attribs.c: Likewise. * auto-inc-dec.c: Likewise. * auto-profile.c: Likewise. * bb-reorder.c: Likewise. * bt-load.c: Likewise. * builtins.c: Likewise. * caller-save.c: Likewise. * calls.c: Likewise. * ccmp.c: Likewise. * cfg.c: Likewise. * cfganal.c: Likewise. * cfgbuild.c: Likewise. * cfgcleanup.c: Likewise. * cfgexpand.c: Likewise. * cfghooks.c: Likewise. * cfgloop.c: Likewise. * cfgloopanal.c: Likewise. * cfgloopmanip.c: Likewise. * cfgrtl.c: Likewise. * cgraph.c: Likewise. * cgraphbuild.c: Likewise. * cgraphclones.c: Likewise. * cgraphunit.c: Likewise. * cilk-common.c: Likewise. * combine-stack-adj.c: Likewise. * combine.c: Likewise. * compare-elim.c: Likewise. * convert.c: Likewise. * coverage.c: Likewise. * cppbuiltin.c: Likewise. * cprop.c: Likewise. * cse.c: Likewise. * cselib.c: Likewise. * data-streamer-in.c: Likewise. * data-streamer-out.c: Likewise. * data-streamer.c: Likewise. * dbxout.c: Likewise. * dce.c: Likewise. * ddg.c: Likewise. * debug.c: Likewise. * df-core.c: Likewise. * df-problems.c: Likewise. * df-scan.c: Likewise. * dfp.c: Likewise. * dojump.c: Likewise. * dominance.c: Likewise. * double-int.c: Likewise. * dse.c: Likewise. * dumpfile.c: Likewise. * dwarf2asm.c: Likewise. * dwarf2cfi.c: Likewise. * dwarf2out.c: Likewise. * emit-rtl.c: Likewise. * except.c: Likewise. * explow.c: Likewise. * expmed.c: Likewise. * expr.c: Likewise. * final.c: Likewise. * fixed-value.c: Likewise. * fold-const.c: Likewise. * function.c: Likewise. * fwprop.c: Likewise. * gcse.c: Likewise. * generic-match-head.c: Likewise. * ggc-common.c: Likewise. * gimple-builder.c: Likewise. * gimple-expr.c: Likewise. * gimple-fold.c: Likewise. * gimple-iterator.c: Likewise. * gimple-low.c: Likewise. * gimple-match-head.c: Likewise. * gimple-pretty-print.c: Likewise. * gimple-ssa-isolate-paths.c: Likewise. * gimple-ssa-strength-reduction.c: Likewise. * gimple-streamer-in.c: Likewise. * gimple-streamer-out.c: Likewise. * gimple-walk.c: Likewise. * gimple.c: Likewise. * gimplify-me.c: Likewise. * gimplify.c: Likewise. * godump.c: Likewise. * graph.c: Likewise. * graphite-poly.c: Likewise. * haifa-sched.c: Likewise. * hw-doloop.c: Likewise. * ifcvt.c: Likewise. * incpath.c: Likewise. * init-regs.c: Likewise. * internal-fn.c: Likewise. * ipa-chkp.c: Likewise. * ipa-comdats.c: Likewise. * ipa-cp.c: Likewise. * ipa-devirt.c: Likewise. * ipa-icf-gimple.c: Likewise. * ipa-icf.c: Likewise. * ipa-inline-analysis.c: Likewise. * ipa-inline-transform.c: Likewise. * ipa-inline.c: Likewise. * ipa-polymorphic-call.c: Likewise. * ipa-profile.c: Likewise. * ipa-prop.c: Likewise. * ipa-pure-const.c: Likewise. * ipa-ref.c: Likewise. * ipa-reference.c: Likewise. * ipa-split.c: Likewise. * ipa-utils.c: Likewise. * ipa-visibility.c: Likewise. * ipa.c: Likewise. * ira-build.c: Likewise. * ira-color.c: Likewise. * ira-conflicts.c: Likewise. * ira-costs.c: Likewise. * ira-emit.c: Likewise. * ira-lives.c: Likewise. * ira.c: Likewise. * jump.c: Likewise. * langhooks.c: Likewise. * lcm.c: Likewise. * lists.c: Likewise. * loop-doloop.c: Likewise. * loop-init.c: Likewise. * loop-invariant.c: Likewise. * loop-iv.c: Likewise. * loop-unroll.c: Likewise. * lower-subreg.c: Likewise. * lra-assigns.c: Likewise. * lra-coalesce.c: Likewise. * lra-constraints.c: Likewise. * lra-eliminations.c: Likewise. * lra-lives.c: Likewise. * lra-remat.c: Likewise. * lra-spills.c: Likewise. * lra.c: Likewise. * lto-cgraph.c: Likewise. * lto-compress.c: Likewise. * lto-opts.c: Likewise. * lto-section-in.c: Likewise. * lto-section-out.c: Likewise. * lto-streamer-in.c: Likewise. * lto-streamer-out.c: Likewise. * lto-streamer.c: Likewise. * mode-switching.c: Likewise. * modulo-sched.c: Likewise. * omp-low.c: Likewise. * optabs.c: Likewise. * opts-global.c: Likewise. * passes.c: Likewise. * plugin.c: Likewise. * postreload-gcse.c: Likewise. * postreload.c: Likewise. * predict.c: Likewise. * print-tree.c: Likewise. * profile.c: Likewise. * real.c: Likewise. * realmpfr.c: Likewise. * recog.c: Likewise. * ree.c: Likewise. * reg-stack.c: Likewise. * regcprop.c: Likewise. * reginfo.c: Likewise. * regrename.c: Likewise. * regstat.c: Likewise. * reload.c: Likewise. * reload1.c: Likewise. * reorg.c: Likewise. * resource.c: Likewise. * rtl-chkp.c: Likewise. * rtl-error.c: Likewise. * rtlanal.c: Likewise. * rtlhooks.c: Likewise. * sanopt.c: Likewise. * sched-deps.c: Likewise. * sched-ebb.c: Likewise. * sched-rgn.c: Likewise. * sese.c: Likewise. * shrink-wrap.c: Likewise. * simplify-rtx.c: Likewise. * stack-ptr-mod.c: Likewise. * statistics.c: Likewise. * stmt.c: Likewise. * stor-layout.c: Likewise. * store-motion.c: Likewise. * stringpool.c: Likewise. * symtab.c: Likewise. * target-globals.c: Likewise. * targhooks.c: Likewise. * toplev.c: Likewise. * tracer.c: Likewise. * trans-mem.c: Likewise. * tree-affine.c: Likewise. * tree-call-cdce.c: Likewise. * tree-cfg.c: Likewise. * tree-cfgcleanup.c: Likewise. * tree-chkp-opt.c: Likewise. * tree-chkp.c: Likewise. * tree-chrec.c: Likewise. * tree-complex.c: Likewise. * tree-data-ref.c: Likewise. * tree-dfa.c: Likewise. * tree-diagnostic.c: Likewise. * tree-dump.c: Likewise. * tree-eh.c: Likewise. * tree-emutls.c: Likewise. * tree-if-conv.c: Likewise. * tree-inline.c: Likewise. * tree-into-ssa.c: Likewise. * tree-iterator.c: Likewise. * tree-loop-distribution.c: Likewise. * tree-nested.c: Likewise. * tree-nrv.c: Likewise. * tree-object-size.c: Likewise. * tree-outof-ssa.c: Likewise. * tree-parloops.c: Likewise. * tree-phinodes.c: Likewise. * tree-predcom.c: Likewise. * tree-pretty-print.c: Likewise. * tree-profile.c: Likewise. * tree-scalar-evolution.c: Likewise. * tree-sra.c: Likewise. * tree-ssa-address.c: Likewise. * tree-ssa-alias.c: Likewise. * tree-ssa-ccp.c: Likewise. * tree-ssa-coalesce.c: Likewise. * tree-ssa-copy.c: Likewise. * tree-ssa-dce.c: Likewise. * tree-ssa-dom.c: Likewise. * tree-ssa-dse.c: Likewise. * tree-ssa-forwprop.c: Likewise. * tree-ssa-ifcombine.c: Likewise. * tree-ssa-live.c: Likewise. * tree-ssa-loop-ch.c: Likewise. * tree-ssa-loop-im.c: Likewise. * tree-ssa-loop-ivcanon.c: Likewise. * tree-ssa-loop-ivopts.c: Likewise. * tree-ssa-loop-manip.c: Likewise. * tree-ssa-loop-niter.c: Likewise. * tree-ssa-loop-prefetch.c: Likewise. * tree-ssa-loop-unswitch.c: Likewise. * tree-ssa-loop.c: Likewise. * tree-ssa-math-opts.c: Likewise. * tree-ssa-operands.c: Likewise. * tree-ssa-phiopt.c: Likewise. * tree-ssa-phiprop.c: Likewise. * tree-ssa-pre.c: Likewise. * tree-ssa-propagate.c: Likewise. * tree-ssa-reassoc.c: Likewise. * tree-ssa-sccvn.c: Likewise. * tree-ssa-scopedtables.c: Likewise. * tree-ssa-sink.c: Likewise. * tree-ssa-strlen.c: Likewise. * tree-ssa-structalias.c: Likewise. * tree-ssa-tail-merge.c: Likewise. * tree-ssa-ter.c: Likewise. * tree-ssa-threadedge.c: Likewise. * tree-ssa-threadupdate.c: Likewise. * tree-ssa-uncprop.c: Likewise. * tree-ssa-uninit.c: Likewise. * tree-ssa.c: Likewise. * tree-ssanames.c: Likewise. * tree-stdarg.c: Likewise. * tree-streamer-in.c: Likewise. * tree-streamer-out.c: Likewise. * tree-streamer.c: Likewise. * tree-switch-conversion.c: Likewise. * tree-tailcall.c: Likewise. * tree-vect-data-refs.c: Likewise. * tree-vect-generic.c: Likewise. * tree-vect-loop-manip.c: Likewise. * tree-vect-loop.c: Likewise. * tree-vect-patterns.c: Likewise. * tree-vect-slp.c: Likewise. * tree-vect-stmts.c: Likewise. * tree-vectorizer.c: Likewise. * tree-vrp.c: Likewise. * tree.c: Likewise. * tsan.c: Likewise. * ubsan.c: Likewise. * value-prof.c: Likewise. * var-tracking.c: Likewise. * varasm.c: Likewise. * varpool.c: Likewise. * vtable-verify.c: Likewise. * web.c: Likewise. * wide-int-print.cc: Likewise. * wide-int.cc: Likewise. * xcoffout.c: Likewise. From-SVN: r229526
2015-10-29 14:57:32 +01:00
#include "cfghooks.h"
#include "tree-pass.h"
Move MEMMODEL_* from coretypes.h to memmodel.h 2016-10-13 Thomas Preud'homme <thomas.preudhomme@arm.com> gcc/ * coretypes.h: Move MEMMODEL_* macros and enum memmodel definition into ... * memmodel.h: This file. * alias.c, asan.c, auto-inc-dec.c, bb-reorder.c, bt-load.c, caller-save.c, calls.c, ccmp.c, cfgbuild.c, cfgcleanup.c, cfgexpand.c, cfgloopanal.c, cfgrtl.c, cilk-common.c, combine.c, combine-stack-adj.c, common/config/aarch64/aarch64-common.c, common/config/arm/arm-common.c, common/config/bfin/bfin-common.c, common/config/c6x/c6x-common.c, common/config/i386/i386-common.c, common/config/ia64/ia64-common.c, common/config/nvptx/nvptx-common.c, compare-elim.c, config/aarch64/aarch64-builtins.c, config/aarch64/aarch64-c.c, config/aarch64/cortex-a57-fma-steering.c, config/arc/arc.c, config/arc/arc-c.c, config/arm/arm-builtins.c, config/arm/arm-c.c, config/avr/avr.c, config/avr/avr-c.c, config/avr/avr-log.c, config/bfin/bfin.c, config/c6x/c6x.c, config/cr16/cr16.c, config/cris/cris.c, config/darwin-c.c, config/darwin.c, config/epiphany/epiphany.c, config/epiphany/mode-switch-use.c, config/epiphany/resolve-sw-modes.c, config/fr30/fr30.c, config/frv/frv.c, config/ft32/ft32.c, config/h8300/h8300.c, config/i386/i386-c.c, config/i386/winnt.c, config/iq2000/iq2000.c, config/lm32/lm32.c, config/m32c/m32c.c, config/m32r/m32r.c, config/m68k/m68k.c, config/mcore/mcore.c, config/microblaze/microblaze.c, config/mmix/mmix.c, config/mn10300/mn10300.c, config/moxie/moxie.c, config/msp430/msp430.c, config/nds32/nds32-cost.c, config/nds32/nds32-intrinsic.c, config/nds32/nds32-md-auxiliary.c, config/nds32/nds32-memory-manipulation.c, config/nds32/nds32-predicates.c, config/nds32/nds32.c, config/nios2/nios2.c, config/nvptx/nvptx.c, config/pa/pa.c, config/pdp11/pdp11.c, config/rl78/rl78.c, config/rs6000/rs6000-c.c, config/rx/rx.c, config/s390/s390-c.c, config/s390/s390.c, config/sh/sh.c, config/sh/sh-c.c, config/sh/sh-mem.cc, config/sh/sh_treg_combine.cc, config/sol2.c, config/spu/spu.c, config/stormy16/stormy16.c, config/tilegx/tilegx.c, config/tilepro/tilepro.c, config/v850/v850.c, config/vax/vax.c, config/visium/visium.c, config/vms/vms-c.c, config/xtensa/xtensa.c, coverage.c, cppbuiltin.c, cprop.c, cse.c, cselib.c, dbxout.c, dce.c, df-core.c, df-problems.c, df-scan.c, dojump.c, dse.c, dwarf2asm.c, dwarf2cfi.c, dwarf2out.c, emit-rtl.c, except.c, explow.c, expmed.c, expr.c, final.c, fold-const.c, function.c, fwprop.c, gcse.c, ggc-page.c, haifa-sched.c, hsa-brig.c, hsa-gen.c, hw-doloop.c, ifcvt.c, init-regs.c, internal-fn.c, ira-build.c, ira-color.c, ira-conflicts.c, ira-costs.c, ira-emit.c, ira-lives.c, ira.c, jump.c, loop-doloop.c, loop-invariant.c, loop-iv.c, loop-unroll.c, lower-subreg.c, lra.c, lra-assigns.c, lra-coalesce.c, lra-constraints.c, lra-eliminations.c, lra-lives.c, lra-remat.c, lra-spills.c, mode-switching.c, modulo-sched.c, omp-low.c, passes.c, postreload-gcse.c, postreload.c, predict.c, print-rtl-function.c, recog.c, ree.c, reg-stack.c, regcprop.c, reginfo.c, regrename.c, reload.c, reload1.c, reorg.c, resource.c, rtl-chkp.c, rtl-tests.c, rtlanal.c, rtlhooks.c, sched-deps.c, sched-rgn.c, sdbout.c, sel-sched-ir.c, sel-sched.c, shrink-wrap.c, simplify-rtx.c, stack-ptr-mod.c, stmt.c, stor-layout.c, target-globals.c, targhooks.c, toplev.c, tree-nested.c, tree-outof-ssa.c, tree-profile.c, tree-ssa-coalesce.c, tree-ssa-ifcombine.c, tree-ssa-loop-ivopts.c, tree-ssa-loop.c, tree-ssa-reassoc.c, tree-ssa-sccvn.c, tree-vect-data-refs.c, ubsan.c, valtrack.c, var-tracking.c, varasm.c: Include memmodel.h. * genattrtab.c (write_header): Include memmodel.h in generated file. * genautomata.c (main): Likewise. * gengtype.c (open_base_files): Likewise. * genopinit.c (main): Likewise. * genconditions.c (write_header): Include memmodel.h earlier in generated file. * genemit.c (main): Likewise. * genoutput.c (output_prologue): Likewise. * genpeep.c (main): Likewise. * genpreds.c (write_insn_preds_c): Likewise. * genrecog.c (write_header): Likewise. * Makefile.in (PLUGIN_HEADERS): Include memmodel.h gcc/ada/ * gcc-interface/utils2.c: Include memmodel.h. gcc/c-family/ * c-cppbuiltin.c: Include memmodel.h. * c-opts.c: Likewise. * c-pragma.c: Likewise. * c-warn.c: Likewise. gcc/c/ * c-typeck.c: Include memmodel.h. gcc/cp/ * decl2.c: Include memmodel.h. * rtti.c: Likewise. gcc/fortran/ * trans-intrinsic.c: Include memmodel.h. gcc/go/ * go-backend.c: Include memmodel.h. libgcc/ * libgcov-profiler.c: Replace MEMMODEL_* macros by their __ATOMIC_* equivalent. * config/tilepro/atomic.c: Likewise and stop casting model to enum memmodel. From-SVN: r241121
2016-10-13 16:17:52 +02:00
#include "memmodel.h"
alias.c: Reorder #include statements and remove duplicates. 2015-10-29 Andrew MacLeod <amacleod@redhat.com> * alias.c: Reorder #include statements and remove duplicates. * asan.c: Likewise. * attribs.c: Likewise. * auto-inc-dec.c: Likewise. * auto-profile.c: Likewise. * bb-reorder.c: Likewise. * bt-load.c: Likewise. * builtins.c: Likewise. * caller-save.c: Likewise. * calls.c: Likewise. * ccmp.c: Likewise. * cfg.c: Likewise. * cfganal.c: Likewise. * cfgbuild.c: Likewise. * cfgcleanup.c: Likewise. * cfgexpand.c: Likewise. * cfghooks.c: Likewise. * cfgloop.c: Likewise. * cfgloopanal.c: Likewise. * cfgloopmanip.c: Likewise. * cfgrtl.c: Likewise. * cgraph.c: Likewise. * cgraphbuild.c: Likewise. * cgraphclones.c: Likewise. * cgraphunit.c: Likewise. * cilk-common.c: Likewise. * combine-stack-adj.c: Likewise. * combine.c: Likewise. * compare-elim.c: Likewise. * convert.c: Likewise. * coverage.c: Likewise. * cppbuiltin.c: Likewise. * cprop.c: Likewise. * cse.c: Likewise. * cselib.c: Likewise. * data-streamer-in.c: Likewise. * data-streamer-out.c: Likewise. * data-streamer.c: Likewise. * dbxout.c: Likewise. * dce.c: Likewise. * ddg.c: Likewise. * debug.c: Likewise. * df-core.c: Likewise. * df-problems.c: Likewise. * df-scan.c: Likewise. * dfp.c: Likewise. * dojump.c: Likewise. * dominance.c: Likewise. * double-int.c: Likewise. * dse.c: Likewise. * dumpfile.c: Likewise. * dwarf2asm.c: Likewise. * dwarf2cfi.c: Likewise. * dwarf2out.c: Likewise. * emit-rtl.c: Likewise. * except.c: Likewise. * explow.c: Likewise. * expmed.c: Likewise. * expr.c: Likewise. * final.c: Likewise. * fixed-value.c: Likewise. * fold-const.c: Likewise. * function.c: Likewise. * fwprop.c: Likewise. * gcse.c: Likewise. * generic-match-head.c: Likewise. * ggc-common.c: Likewise. * gimple-builder.c: Likewise. * gimple-expr.c: Likewise. * gimple-fold.c: Likewise. * gimple-iterator.c: Likewise. * gimple-low.c: Likewise. * gimple-match-head.c: Likewise. * gimple-pretty-print.c: Likewise. * gimple-ssa-isolate-paths.c: Likewise. * gimple-ssa-strength-reduction.c: Likewise. * gimple-streamer-in.c: Likewise. * gimple-streamer-out.c: Likewise. * gimple-walk.c: Likewise. * gimple.c: Likewise. * gimplify-me.c: Likewise. * gimplify.c: Likewise. * godump.c: Likewise. * graph.c: Likewise. * graphite-poly.c: Likewise. * haifa-sched.c: Likewise. * hw-doloop.c: Likewise. * ifcvt.c: Likewise. * incpath.c: Likewise. * init-regs.c: Likewise. * internal-fn.c: Likewise. * ipa-chkp.c: Likewise. * ipa-comdats.c: Likewise. * ipa-cp.c: Likewise. * ipa-devirt.c: Likewise. * ipa-icf-gimple.c: Likewise. * ipa-icf.c: Likewise. * ipa-inline-analysis.c: Likewise. * ipa-inline-transform.c: Likewise. * ipa-inline.c: Likewise. * ipa-polymorphic-call.c: Likewise. * ipa-profile.c: Likewise. * ipa-prop.c: Likewise. * ipa-pure-const.c: Likewise. * ipa-ref.c: Likewise. * ipa-reference.c: Likewise. * ipa-split.c: Likewise. * ipa-utils.c: Likewise. * ipa-visibility.c: Likewise. * ipa.c: Likewise. * ira-build.c: Likewise. * ira-color.c: Likewise. * ira-conflicts.c: Likewise. * ira-costs.c: Likewise. * ira-emit.c: Likewise. * ira-lives.c: Likewise. * ira.c: Likewise. * jump.c: Likewise. * langhooks.c: Likewise. * lcm.c: Likewise. * lists.c: Likewise. * loop-doloop.c: Likewise. * loop-init.c: Likewise. * loop-invariant.c: Likewise. * loop-iv.c: Likewise. * loop-unroll.c: Likewise. * lower-subreg.c: Likewise. * lra-assigns.c: Likewise. * lra-coalesce.c: Likewise. * lra-constraints.c: Likewise. * lra-eliminations.c: Likewise. * lra-lives.c: Likewise. * lra-remat.c: Likewise. * lra-spills.c: Likewise. * lra.c: Likewise. * lto-cgraph.c: Likewise. * lto-compress.c: Likewise. * lto-opts.c: Likewise. * lto-section-in.c: Likewise. * lto-section-out.c: Likewise. * lto-streamer-in.c: Likewise. * lto-streamer-out.c: Likewise. * lto-streamer.c: Likewise. * mode-switching.c: Likewise. * modulo-sched.c: Likewise. * omp-low.c: Likewise. * optabs.c: Likewise. * opts-global.c: Likewise. * passes.c: Likewise. * plugin.c: Likewise. * postreload-gcse.c: Likewise. * postreload.c: Likewise. * predict.c: Likewise. * print-tree.c: Likewise. * profile.c: Likewise. * real.c: Likewise. * realmpfr.c: Likewise. * recog.c: Likewise. * ree.c: Likewise. * reg-stack.c: Likewise. * regcprop.c: Likewise. * reginfo.c: Likewise. * regrename.c: Likewise. * regstat.c: Likewise. * reload.c: Likewise. * reload1.c: Likewise. * reorg.c: Likewise. * resource.c: Likewise. * rtl-chkp.c: Likewise. * rtl-error.c: Likewise. * rtlanal.c: Likewise. * rtlhooks.c: Likewise. * sanopt.c: Likewise. * sched-deps.c: Likewise. * sched-ebb.c: Likewise. * sched-rgn.c: Likewise. * sese.c: Likewise. * shrink-wrap.c: Likewise. * simplify-rtx.c: Likewise. * stack-ptr-mod.c: Likewise. * statistics.c: Likewise. * stmt.c: Likewise. * stor-layout.c: Likewise. * store-motion.c: Likewise. * stringpool.c: Likewise. * symtab.c: Likewise. * target-globals.c: Likewise. * targhooks.c: Likewise. * toplev.c: Likewise. * tracer.c: Likewise. * trans-mem.c: Likewise. * tree-affine.c: Likewise. * tree-call-cdce.c: Likewise. * tree-cfg.c: Likewise. * tree-cfgcleanup.c: Likewise. * tree-chkp-opt.c: Likewise. * tree-chkp.c: Likewise. * tree-chrec.c: Likewise. * tree-complex.c: Likewise. * tree-data-ref.c: Likewise. * tree-dfa.c: Likewise. * tree-diagnostic.c: Likewise. * tree-dump.c: Likewise. * tree-eh.c: Likewise. * tree-emutls.c: Likewise. * tree-if-conv.c: Likewise. * tree-inline.c: Likewise. * tree-into-ssa.c: Likewise. * tree-iterator.c: Likewise. * tree-loop-distribution.c: Likewise. * tree-nested.c: Likewise. * tree-nrv.c: Likewise. * tree-object-size.c: Likewise. * tree-outof-ssa.c: Likewise. * tree-parloops.c: Likewise. * tree-phinodes.c: Likewise. * tree-predcom.c: Likewise. * tree-pretty-print.c: Likewise. * tree-profile.c: Likewise. * tree-scalar-evolution.c: Likewise. * tree-sra.c: Likewise. * tree-ssa-address.c: Likewise. * tree-ssa-alias.c: Likewise. * tree-ssa-ccp.c: Likewise. * tree-ssa-coalesce.c: Likewise. * tree-ssa-copy.c: Likewise. * tree-ssa-dce.c: Likewise. * tree-ssa-dom.c: Likewise. * tree-ssa-dse.c: Likewise. * tree-ssa-forwprop.c: Likewise. * tree-ssa-ifcombine.c: Likewise. * tree-ssa-live.c: Likewise. * tree-ssa-loop-ch.c: Likewise. * tree-ssa-loop-im.c: Likewise. * tree-ssa-loop-ivcanon.c: Likewise. * tree-ssa-loop-ivopts.c: Likewise. * tree-ssa-loop-manip.c: Likewise. * tree-ssa-loop-niter.c: Likewise. * tree-ssa-loop-prefetch.c: Likewise. * tree-ssa-loop-unswitch.c: Likewise. * tree-ssa-loop.c: Likewise. * tree-ssa-math-opts.c: Likewise. * tree-ssa-operands.c: Likewise. * tree-ssa-phiopt.c: Likewise. * tree-ssa-phiprop.c: Likewise. * tree-ssa-pre.c: Likewise. * tree-ssa-propagate.c: Likewise. * tree-ssa-reassoc.c: Likewise. * tree-ssa-sccvn.c: Likewise. * tree-ssa-scopedtables.c: Likewise. * tree-ssa-sink.c: Likewise. * tree-ssa-strlen.c: Likewise. * tree-ssa-structalias.c: Likewise. * tree-ssa-tail-merge.c: Likewise. * tree-ssa-ter.c: Likewise. * tree-ssa-threadedge.c: Likewise. * tree-ssa-threadupdate.c: Likewise. * tree-ssa-uncprop.c: Likewise. * tree-ssa-uninit.c: Likewise. * tree-ssa.c: Likewise. * tree-ssanames.c: Likewise. * tree-stdarg.c: Likewise. * tree-streamer-in.c: Likewise. * tree-streamer-out.c: Likewise. * tree-streamer.c: Likewise. * tree-switch-conversion.c: Likewise. * tree-tailcall.c: Likewise. * tree-vect-data-refs.c: Likewise. * tree-vect-generic.c: Likewise. * tree-vect-loop-manip.c: Likewise. * tree-vect-loop.c: Likewise. * tree-vect-patterns.c: Likewise. * tree-vect-slp.c: Likewise. * tree-vect-stmts.c: Likewise. * tree-vectorizer.c: Likewise. * tree-vrp.c: Likewise. * tree.c: Likewise. * tsan.c: Likewise. * ubsan.c: Likewise. * value-prof.c: Likewise. * var-tracking.c: Likewise. * varasm.c: Likewise. * varpool.c: Likewise. * vtable-verify.c: Likewise. * web.c: Likewise. * wide-int-print.cc: Likewise. * wide-int.cc: Likewise. * xcoffout.c: Likewise. From-SVN: r229526
2015-10-29 14:57:32 +01:00
#include "tm_p.h"
tree-core.h: Include symtab.h. 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * tree-core.h: Include symtab.h. * rtl.h: Include hard-reg-set.h but not flags.h. (HARD_CONST): Remove condition compilation involving HARD_CONST since hard-reg-set.h is always included. * regs.h: Don't include hard-reg-set.h or rtl.h. * cfg.h: Include dominance.h. * gimple.h: Include tree-ssa-alias.h and gimple-expr.h. * backend.h: New. Aggregate commonly used backend header files. * gimple-ssa.h: Don't include tree-hasher.h. * ssa.h: New. Aggregate commonly used SSA header files. * regset.h: Remove bitmap.h and hard-reg-set.h #includes. * sel-sched-ir.h: Flatten includes. * lra-int.h: Flatten completely. * sel-sched-dump.h: Flatten includes. * ira-int.h: Flatten includes. * gimple-streamer.h: Remove all includes. * cfgloop.h: Remove all #includes except cfgloopmanip.h. * resource.h: Flatten hard-reg-set.h and df.h. * sched-int.h: Flatten insn-arrt.h and df.h. * valtrack.h: flatten bitmap.h, df.h, and rtl.h * df.h: Flatten includes, leaving regset.h, alloc-pool.h and timevar.h. * genattrtab.c (write_header): Adjust generated includes. * genautomata.c (main): Likewise. * genconditions.c (write-header): Likewise. * genemit.c (main): Likewise. * gengtype.c (open_base_files): Likewise. * genopinit.c (main): Likewise. * genoutput.c (output_prologue): Likewise. * genpeep.c (main): Likewise. * genpreds.c (write_insn_preds_c): Likewise. * genrecog.c (write_header): Likewise. * alias.c: Adjust includes. * asan.c: Likewise. * attribs.c: Likewise. * auto-inc-dec.c: Likewise. * auto-profile.c: Likewise. * bb-reorder.c: Likewise. * bt-load.c: Likewise. * builtins.c: Likewise. * caller-save.c: Likewise. * calls.c: Likewise. * ccmp.c: Likewise. * cfg.c: Likewise. * cfganal.c: Likewise. * cfgbuild.c: Likewise. * cfgcleanup.c: Likewise. * cfgexpand.c: Likewise. * cfghooks.c: Likewise. * cfgloop.c: Likewise. * cfgloopanal.c: Likewise. * cfgloopmanip.c: Likewise. * cfgrtl.c: Likewise. * cgraph.c: Likewise. * cgraphbuild.c: Likewise. * cgraphclones.c: Likewise. * cgraphunit.c: Likewise. * cilk-common.c: Likewise. * combine-stack-adj.c: Likewise. * combine.c: Likewise. * compare-elim.c: Likewise. * convert.c: Likewise. * coverage.c: Likewise. * cppbuiltin.c: Likewise. * cprop.c: Likewise. * cse.c: Likewise. * cselib.c: Likewise. * data-streamer-in.c: Likewise. * data-streamer-out.c: Likewise. * data-streamer.c: Likewise. * dbxout.c: Likewise. * dce.c: Likewise. * ddg.c: Likewise. * debug.c: Likewise. * df-core.c: Likewise. * df-problems.c: Likewise. * df-scan.c: Likewise. * dfp.c: Likewise. * dojump.c: Likewise. * dominance.c: Likewise. * domwalk.c: Likewise. * double-int.c: Likewise. * dse.c: Likewise. * dumpfile.c: Likewise. * dwarf2asm.c: Likewise. * dwarf2cfi.c: Likewise. * dwarf2out.c: Likewise. * emit-rtl.c: Likewise. * et-forest.c: Likewise. * except.c: Likewise. * explow.c: Likewise. * expmed.c: Likewise. * expr.c: Likewise. * final.c: Likewise. * fixed-value.c: Likewise. * fold-const.c: Likewise. * function.c: Likewise. * fwprop.c: Likewise. * gcc-plugin.h: Likewise. * gcse-common.c: Likewise. * gcse.c: Likewise. * generic-match-head.c: Likewise. * ggc-page.c: Likewise. * gimple-builder.c: Likewise. * gimple-expr.c: Likewise. * gimple-fold.c: Likewise. * gimple-iterator.c: Likewise. * gimple-low.c: Likewise. * gimple-match-head.c: Likewise. * gimple-pretty-print.c: Likewise. * gimple-ssa-isolate-paths.c: Likewise. * gimple-ssa-strength-reduction.c: Likewise. * gimple-streamer-in.c: Likewise. * gimple-streamer-out.c: Likewise. * gimple-walk.c: Likewise. * gimple.c: Likewise. * gimplify-me.c: Likewise. * gimplify.c: Likewise. * godump.c: Likewise. * graph.c: Likewise. * graphite-blocking.c: Likewise. * graphite-dependences.c: Likewise. * graphite-interchange.c: Likewise. * graphite-isl-ast-to-gimple.c: Likewise. * graphite-optimize-isl.c: Likewise. * graphite-poly.c: Likewise. * graphite-scop-detection.c: Likewise. * graphite-sese-to-poly.c: Likewise. * graphite.c: Likewise. * haifa-sched.c: Likewise. * hw-doloop.c: Likewise. * ifcvt.c: Likewise. * init-regs.c: Likewise. * internal-fn.c: Likewise. * ipa-chkp.c: Likewise. * ipa-comdats.c: Likewise. * ipa-cp.c: Likewise. * ipa-devirt.c: Likewise. * ipa-icf-gimple.c: Likewise. * ipa-icf.c: Likewise. * ipa-inline-analysis.c: Likewise. * ipa-inline-transform.c: Likewise. * ipa-inline.c: Likewise. * ipa-polymorphic-call.c: Likewise. * ipa-profile.c: Likewise. * ipa-prop.c: Likewise. * ipa-pure-const.c: Likewise. * ipa-ref.c: Likewise. * ipa-reference.c: Likewise. * ipa-split.c: Likewise. * ipa-utils.c: Likewise. * ipa-visibility.c: Likewise. * ipa.c: Likewise. * ira-build.c: Likewise. * ira-color.c: Likewise. * ira-conflicts.c: Likewise. * ira-costs.c: Likewise. * ira-emit.c: Likewise. * ira-lives.c: Likewise. * ira.c: Likewise. * jump.c: Likewise. * langhooks.c: Likewise. * lcm.c: Likewise. * loop-doloop.c: Likewise. * loop-init.c: Likewise. * loop-invariant.c: Likewise. * loop-iv.c: Likewise. * loop-unroll.c: Likewise. * lower-subreg.c: Likewise. * lra-assigns.c: Likewise. * lra-coalesce.c: Likewise. * lra-constraints.c: Likewise. * lra-eliminations.c: Likewise. * lra-lives.c: Likewise. * lra-remat.c: Likewise. * lra-spills.c: Likewise. * lra.c: Likewise. * lto-cgraph.c: Likewise. * lto-compress.c: Likewise. * lto-opts.c: Likewise. * lto-section-in.c: Likewise. * lto-section-out.c: Likewise. * lto-streamer-in.c: Likewise. * lto-streamer-out.c: Likewise. * lto-streamer.c: Likewise. * mcf.c: Likewise. * mode-switching.c: Likewise. * modulo-sched.c: Likewise. * omega.c: Likewise. * omp-low.c: Likewise. * optabs.c: Likewise. * opts-global.c: Likewise. * passes.c: Likewise. * plugin.c: Likewise. * postreload-gcse.c: Likewise. * postreload.c: Likewise. * predict.c: Likewise. * print-rtl.c: Likewise. * print-tree.c: Likewise. * profile.c: Likewise. * real.c: Likewise. * realmpfr.c: Likewise. * recog.c: Likewise. * ree.c: Likewise. * reg-stack.c: Likewise. * regcprop.c: Likewise. * reginfo.c: Likewise. * regrename.c: Likewise. * regstat.c: Likewise. * reload.c: Likewise. * reload1.c: Likewise. * reorg.c: Likewise. * resource.c: Likewise. * rtl-chkp.c: Likewise. * rtlanal.c: Likewise. * rtlhooks.c: Likewise. * sanopt.c: Likewise. * sched-deps.c: Likewise. * sched-ebb.c: Likewise. * sched-rgn.c: Likewise. * sched-vis.c: Likewise. * sdbout.c: Likewise. * sel-sched-dump.c: Likewise. * sel-sched-ir.c: Likewise. * sel-sched.c: Likewise. * sese.c: Likewise. * shrink-wrap.c: Likewise. * simplify-rtx.c: Likewise. * stack-ptr-mod.c: Likewise. * stmt.c: Likewise. * stor-layout.c: Likewise. * store-motion.c: Likewise. * stringpool.c: Likewise. * symtab.c: Likewise. * target-globals.c: Likewise. * targhooks.c: Likewise. * toplev.c: Likewise. * tracer.c: Likewise. * trans-mem.c: Likewise. * tree-affine.c: Likewise. * tree-browser.c: Likewise. * tree-call-cdce.c: Likewise. * tree-cfg.c: Likewise. * tree-cfgcleanup.c: Likewise. * tree-chkp-opt.c: Likewise. * tree-chkp.c: Likewise. * tree-chrec.c: Likewise. * tree-complex.c: Likewise. * tree-data-ref.c: Likewise. * tree-dfa.c: Likewise. * tree-diagnostic.c: Likewise. * tree-dump.c: Likewise. * tree-eh.c: Likewise. * tree-emutls.c: Likewise. * tree-if-conv.c: Likewise. * tree-inline.c: Likewise. * tree-into-ssa.c: Likewise. * tree-iterator.c: Likewise. * tree-loop-distribution.c: Likewise. * tree-nested.c: Likewise. * tree-nrv.c: Likewise. * tree-object-size.c: Likewise. * tree-outof-ssa.c: Likewise. * tree-parloops.c: Likewise. * tree-phinodes.c: Likewise. * tree-predcom.c: Likewise. * tree-pretty-print.c: Likewise. * tree-profile.c: Likewise. * tree-scalar-evolution.c: Likewise. * tree-sra.c: Likewise. * tree-ssa-address.c: Likewise. * tree-ssa-alias.c: Likewise. * tree-ssa-ccp.c: Likewise. * tree-ssa-coalesce.c: Likewise. * tree-ssa-copy.c: Likewise. * tree-ssa-copyrename.c: Likewise. * tree-ssa-dce.c: Likewise. * tree-ssa-dom.c: Likewise. * tree-ssa-dse.c: Likewise. * tree-ssa-forwprop.c: Likewise. * tree-ssa-ifcombine.c: Likewise. * tree-ssa-live.c: Likewise. * tree-ssa-loop-ch.c: Likewise. * tree-ssa-loop-im.c: Likewise. * tree-ssa-loop-ivcanon.c: Likewise. * tree-ssa-loop-ivopts.c: Likewise. * tree-ssa-loop-manip.c: Likewise. * tree-ssa-loop-niter.c: Likewise. * tree-ssa-loop-prefetch.c: Likewise. * tree-ssa-loop-unswitch.c: Likewise. * tree-ssa-loop.c: Likewise. * tree-ssa-math-opts.c: Likewise. * tree-ssa-operands.c: Likewise. * tree-ssa-phiopt.c: Likewise. * tree-ssa-phiprop.c: Likewise. * tree-ssa-pre.c: Likewise. * tree-ssa-propagate.c: Likewise. * tree-ssa-reassoc.c: Likewise. * tree-ssa-sccvn.c: Likewise. * tree-ssa-scopedtables.c: Likewise. * tree-ssa-sink.c: Likewise. * tree-ssa-strlen.c: Likewise. * tree-ssa-structalias.c: Likewise. * tree-ssa-tail-merge.c: Likewise. * tree-ssa-ter.c: Likewise. * tree-ssa-threadedge.c: Likewise. * tree-ssa-threadupdate.c: Likewise. * tree-ssa-uncprop.c: Likewise. * tree-ssa-uninit.c: Likewise. * tree-ssa.c: Likewise. * tree-ssanames.c: Likewise. * tree-stdarg.c: Likewise. * tree-streamer-in.c: Likewise. * tree-streamer-out.c: Likewise. * tree-streamer.c: Likewise. * tree-switch-conversion.c: Likewise. * tree-tailcall.c: Likewise. * tree-vect-data-refs.c: Likewise. * tree-vect-generic.c: Likewise. * tree-vect-loop-manip.c: Likewise. * tree-vect-loop.c: Likewise. * tree-vect-patterns.c: Likewise. * tree-vect-slp.c: Likewise. * tree-vect-stmts.c: Likewise. * tree-vectorizer.c: Likewise. * tree-vrp.c: Likewise. * tree.c: Likewise. * tsan.c: Likewise. * ubsan.c: Likewise. * valtrack.c: Likewise. * value-prof.c: Likewise. * var-tracking.c: Likewise. * varasm.c: Likewise. * varpool.c: Likewise. * vmsdbgout.c: Likewise. * vtable-verify.c: Likewise. * web.c: Likewise. * wide-int.cc: Likewise. * xcoffout.c: Likewise. * config/aarch64/aarch64-builtins.c: Likewise. * config/aarch64/aarch64.c: Likewise. * config/aarch64/cortex-a57-fma-steering.c: Likewise. * config/alpha/alpha.c: Likewise. * config/arc/arc.c: Likewise. * config/arm/aarch-common.c: Likewise. * config/arm/arm-builtins.c: Likewise. * config/arm/arm-c.c: Likewise. * config/arm/arm.c: Likewise. * config/avr/avr-c.c: Likewise. * config/avr/avr-log.c: Likewise. * config/avr/avr.c: Likewise. * config/bfin/bfin.c: Likewise. * config/c6x/c6x.c: Likewise. * config/cr16/cr16.c: Likewise. * config/cris/cris.c: Likewise. * config/darwin-c.c: Likewise. * config/darwin.c: Likewise. * config/epiphany/epiphany.c: Likewise. * config/epiphany/mode-switch-use.c: Likewise. * config/epiphany/resolve-sw-modes.c: Likewise. * config/fr30/fr30.c: Likewise. * config/frv/frv.c: Likewise. * config/ft32/ft32.c: Likewise. * config/h8300/h8300.c: Likewise. * config/i386/i386-c.c: Likewise. * config/i386/i386.c: Likewise. * config/i386/msformat-c.c: Likewise. * config/i386/winnt-cxx.c: Likewise. * config/i386/winnt-stubs.c: Likewise. * config/i386/winnt.c: Likewise. * config/ia64/ia64-c.c: Likewise. * config/ia64/ia64.c: Likewise. * config/iq2000/iq2000.c: Likewise. * config/lm32/lm32.c: Likewise. * config/m32c/m32c-pragma.c: Likewise. * config/m32c/m32c.c: Likewise. * config/m32r/m32r.c: Likewise. * config/m68k/m68k.c: Likewise. * config/mcore/mcore.c: Likewise. * config/mep/mep-pragma.c: Likewise. * config/mep/mep.c: Likewise. * config/microblaze/microblaze-c.c: Likewise. * config/microblaze/microblaze.c: Likewise. * config/mips/mips.c: Likewise. * config/mmix/mmix.c: Likewise. * config/mn10300/mn10300.c: Likewise. * config/moxie/moxie.c: Likewise. * config/msp430/msp430-c.c: Likewise. * config/msp430/msp430.c: Likewise. * config/nds32/nds32-cost.c: Likewise. * config/nds32/nds32-fp-as-gp.c: Likewise. * config/nds32/nds32-intrinsic.c: Likewise. * config/nds32/nds32-isr.c: Likewise. * config/nds32/nds32-md-auxiliary.c: Likewise. * config/nds32/nds32-memory-manipulation.c: Likewise. * config/nds32/nds32-pipelines-auxiliary.c: Likewise. * config/nds32/nds32-predicates.c: Likewise. * config/nds32/nds32.c: Likewise. * config/nios2/nios2.c: Likewise. * config/nvptx/nvptx.c: Likewise. * config/pa/pa.c: Likewise. * config/pdp11/pdp11.c: Likewise. * config/rl78/rl78-c.c: Likewise. * config/rl78/rl78.c: Likewise. * config/rs6000/rs6000-c.c: Likewise. * config/rs6000/rs6000.c: Likewise. * config/rx/rx.c: Likewise. * config/s390/s390-c.c: Likewise. * config/s390/s390.c: Likewise. * config/sh/sh-c.c: Likewise. * config/sh/sh-mem.cc: Likewise. * config/sh/sh.c: Likewise. * config/sh/sh_optimize_sett_clrt.cc: Likewise. * config/sh/sh_treg_combine.cc: Likewise. * config/sol2-c.c: Likewise. * config/sol2-cxx.c: Likewise. * config/sol2-stubs.c: Likewise. * config/sol2.c: Likewise. * config/sparc/sparc-c.c: Likewise. * config/sparc/sparc.c: Likewise. * config/spu/spu-c.c: Likewise. * config/spu/spu.c: Likewise. * config/stormy16/stormy16.c: Likewise. * config/tilegx/mul-tables.c: Likewise. * config/tilegx/tilegx-c.c: Likewise. * config/tilegx/tilegx.c: Likewise. * config/tilepro/mul-tables.c: Likewise. * config/tilepro/tilepro-c.c: Likewise. * config/tilepro/tilepro.c: Likewise. * config/v850/v850-c.c: Likewise. * config/v850/v850.c: Likewise. * config/vax/vax.c: Likewise. * config/visium/visium.c: Likewise. * config/vms/vms-c.c: Likewise. * config/vms/vms.c: Likewise. * config/vxworks.c: Likewise. * config/xtensa/xtensa.c: Likewise. ada 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * gcc-interface/cuintp.c: Adjust includes. * gcc-interface/decl.c: Likewise. * gcc-interface/misc.c: Likewise. * gcc-interface/targtyps.c: Likewise. * gcc-interface/trans.c: Likewise. * gcc-interface/utils.c: Likewise. * gcc-interface/utils2.c: Likewise. c 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * c-array-notation.c: Adjust includes. * c-aux-info.c: Likewise. * c-convert.c: Likewise. * c-decl.c: Likewise. * c-errors.c: Likewise. * c-lang.c: Likewise. * c-objc-common.c: Likewise. * c-parser.c: Likewise. * c-typeck.c: Likewise. c-family 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * array-notation-common.c: Adjust includes. * c-ada-spec.c: Likewise. * c-cilkplus.c: Likewise. * c-common.h: Likewise. * c-cppbuiltin.c: Likewise. * c-dump.c: Likewise. * c-format.c: Likewise. * c-gimplify.c: Likewise. * c-indentation.c: Likewise. * c-lex.c: Likewise. * c-omp.c: Likewise. * c-opts.c: Likewise. * c-pch.c: Likewise. * c-ppoutput.c: Likewise. * c-pragma.c: Likewise. * c-pretty-print.c: Likewise. * c-semantics.c: Likewise. * c-ubsan.c: Likewise. * cilk.c: Likewise. * stub-objc.c: Likewise. cp 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * call.c: Adjust includes. * class.c: Likewise. * constexpr.c: Likewise. * cp-array-notation.c: Likewise. * cp-gimplify.c: Likewise. * cp-lang.c: Likewise. * cp-objcp-common.c: Likewise. * cp-ubsan.c: Likewise. * cvt.c: Likewise. * decl.c: Likewise. * decl2.c: Likewise. * dump.c: Likewise. * error.c: Likewise. * except.c: Likewise. * expr.c: Likewise. * friend.c: Likewise. * init.c: Likewise. * lambda.c: Likewise. * lex.c: Likewise. * mangle.c: Likewise. * method.c: Likewise. * name-lookup.c: Likewise. * optimize.c: Likewise. * parser.c: Likewise. * pt.c: Likewise. * ptree.c: Likewise. * repo.c: Likewise. * rtti.c: Likewise. * search.c: Likewise. * semantics.c: Likewise. * tree.c: Likewise. * typeck.c: Likewise. * typeck2.c: Likewise. fortran 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * convert.c: Adjust includes. * cpp.c: Likewise. * decl.c: Likewise. * f95-lang.c: Likewise. * iresolve.c: Likewise. * match.c: Likewise. * module.c: Likewise. * options.c: Likewise. * target-memory.c: Likewise. * trans-array.c: Likewise. * trans-common.c: Likewise. * trans-const.c: Likewise. * trans-decl.c: Likewise. * trans-expr.c: Likewise. * trans-intrinsic.c: Likewise. * trans-io.c: Likewise. * trans-openmp.c: Likewise. * trans-stmt.c: Likewise. * trans-types.c: Likewise. * trans.c: Likewise. go 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * go-backend.c: Adjust includes. * go-gcc.cc: Likewise. * go-lang.c: Likewise. java 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * boehm.c: Adjust includes. * builtins.c: Likewise. * class.c: Likewise. * constants.c: Likewise. * decl.c: Likewise. * except.c: Likewise. * expr.c: Likewise. * java-gimplify.c: Likewise. * jcf-dump.c: Likewise. * jcf-io.c: Likewise. * jcf-parse.c: Likewise. * jvgenmain.c: Likewise. * lang.c: Likewise. * mangle.c: Likewise. * mangle_name.c: Likewise. * resource.c: Likewise. * typeck.c: Likewise. * verify-glue.c: Likewise. jit 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * dummy-frontend.c: Adjust includes. * jit-common.h: Likewise. * jit-playback.c: Likewise. lto 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * lto-lang.c: Adjust includes. * lto-object.c: Likewise. * lto-partition.c: Likewise. * lto-symtab.c: Likewise. * lto.c: Likewise. objc 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * objc-act.c: Adjust includes. * objc-encoding.c: Likewise. * objc-gnu-runtime-abi-01.c: Likewise. * objc-lang.c: Likewise. * objc-map.c: Likewise. * objc-next-runtime-abi-01.c: Likewise. * objc-next-runtime-abi-02.c: Likewise. * objc-runtime-shared-support.c: Likewise. objcp 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * objcp-decl.c: Adjust includes. * objcp-lang.c: Likewise. From-SVN: r225531
2015-07-08 02:53:03 +02:00
#include "ssa.h"
#include "cgraph.h"
#include "tree-pretty-print.h"
alias.c: Reorder #include statements and remove duplicates. 2015-10-29 Andrew MacLeod <amacleod@redhat.com> * alias.c: Reorder #include statements and remove duplicates. * asan.c: Likewise. * attribs.c: Likewise. * auto-inc-dec.c: Likewise. * auto-profile.c: Likewise. * bb-reorder.c: Likewise. * bt-load.c: Likewise. * builtins.c: Likewise. * caller-save.c: Likewise. * calls.c: Likewise. * ccmp.c: Likewise. * cfg.c: Likewise. * cfganal.c: Likewise. * cfgbuild.c: Likewise. * cfgcleanup.c: Likewise. * cfgexpand.c: Likewise. * cfghooks.c: Likewise. * cfgloop.c: Likewise. * cfgloopanal.c: Likewise. * cfgloopmanip.c: Likewise. * cfgrtl.c: Likewise. * cgraph.c: Likewise. * cgraphbuild.c: Likewise. * cgraphclones.c: Likewise. * cgraphunit.c: Likewise. * cilk-common.c: Likewise. * combine-stack-adj.c: Likewise. * combine.c: Likewise. * compare-elim.c: Likewise. * convert.c: Likewise. * coverage.c: Likewise. * cppbuiltin.c: Likewise. * cprop.c: Likewise. * cse.c: Likewise. * cselib.c: Likewise. * data-streamer-in.c: Likewise. * data-streamer-out.c: Likewise. * data-streamer.c: Likewise. * dbxout.c: Likewise. * dce.c: Likewise. * ddg.c: Likewise. * debug.c: Likewise. * df-core.c: Likewise. * df-problems.c: Likewise. * df-scan.c: Likewise. * dfp.c: Likewise. * dojump.c: Likewise. * dominance.c: Likewise. * double-int.c: Likewise. * dse.c: Likewise. * dumpfile.c: Likewise. * dwarf2asm.c: Likewise. * dwarf2cfi.c: Likewise. * dwarf2out.c: Likewise. * emit-rtl.c: Likewise. * except.c: Likewise. * explow.c: Likewise. * expmed.c: Likewise. * expr.c: Likewise. * final.c: Likewise. * fixed-value.c: Likewise. * fold-const.c: Likewise. * function.c: Likewise. * fwprop.c: Likewise. * gcse.c: Likewise. * generic-match-head.c: Likewise. * ggc-common.c: Likewise. * gimple-builder.c: Likewise. * gimple-expr.c: Likewise. * gimple-fold.c: Likewise. * gimple-iterator.c: Likewise. * gimple-low.c: Likewise. * gimple-match-head.c: Likewise. * gimple-pretty-print.c: Likewise. * gimple-ssa-isolate-paths.c: Likewise. * gimple-ssa-strength-reduction.c: Likewise. * gimple-streamer-in.c: Likewise. * gimple-streamer-out.c: Likewise. * gimple-walk.c: Likewise. * gimple.c: Likewise. * gimplify-me.c: Likewise. * gimplify.c: Likewise. * godump.c: Likewise. * graph.c: Likewise. * graphite-poly.c: Likewise. * haifa-sched.c: Likewise. * hw-doloop.c: Likewise. * ifcvt.c: Likewise. * incpath.c: Likewise. * init-regs.c: Likewise. * internal-fn.c: Likewise. * ipa-chkp.c: Likewise. * ipa-comdats.c: Likewise. * ipa-cp.c: Likewise. * ipa-devirt.c: Likewise. * ipa-icf-gimple.c: Likewise. * ipa-icf.c: Likewise. * ipa-inline-analysis.c: Likewise. * ipa-inline-transform.c: Likewise. * ipa-inline.c: Likewise. * ipa-polymorphic-call.c: Likewise. * ipa-profile.c: Likewise. * ipa-prop.c: Likewise. * ipa-pure-const.c: Likewise. * ipa-ref.c: Likewise. * ipa-reference.c: Likewise. * ipa-split.c: Likewise. * ipa-utils.c: Likewise. * ipa-visibility.c: Likewise. * ipa.c: Likewise. * ira-build.c: Likewise. * ira-color.c: Likewise. * ira-conflicts.c: Likewise. * ira-costs.c: Likewise. * ira-emit.c: Likewise. * ira-lives.c: Likewise. * ira.c: Likewise. * jump.c: Likewise. * langhooks.c: Likewise. * lcm.c: Likewise. * lists.c: Likewise. * loop-doloop.c: Likewise. * loop-init.c: Likewise. * loop-invariant.c: Likewise. * loop-iv.c: Likewise. * loop-unroll.c: Likewise. * lower-subreg.c: Likewise. * lra-assigns.c: Likewise. * lra-coalesce.c: Likewise. * lra-constraints.c: Likewise. * lra-eliminations.c: Likewise. * lra-lives.c: Likewise. * lra-remat.c: Likewise. * lra-spills.c: Likewise. * lra.c: Likewise. * lto-cgraph.c: Likewise. * lto-compress.c: Likewise. * lto-opts.c: Likewise. * lto-section-in.c: Likewise. * lto-section-out.c: Likewise. * lto-streamer-in.c: Likewise. * lto-streamer-out.c: Likewise. * lto-streamer.c: Likewise. * mode-switching.c: Likewise. * modulo-sched.c: Likewise. * omp-low.c: Likewise. * optabs.c: Likewise. * opts-global.c: Likewise. * passes.c: Likewise. * plugin.c: Likewise. * postreload-gcse.c: Likewise. * postreload.c: Likewise. * predict.c: Likewise. * print-tree.c: Likewise. * profile.c: Likewise. * real.c: Likewise. * realmpfr.c: Likewise. * recog.c: Likewise. * ree.c: Likewise. * reg-stack.c: Likewise. * regcprop.c: Likewise. * reginfo.c: Likewise. * regrename.c: Likewise. * regstat.c: Likewise. * reload.c: Likewise. * reload1.c: Likewise. * reorg.c: Likewise. * resource.c: Likewise. * rtl-chkp.c: Likewise. * rtl-error.c: Likewise. * rtlanal.c: Likewise. * rtlhooks.c: Likewise. * sanopt.c: Likewise. * sched-deps.c: Likewise. * sched-ebb.c: Likewise. * sched-rgn.c: Likewise. * sese.c: Likewise. * shrink-wrap.c: Likewise. * simplify-rtx.c: Likewise. * stack-ptr-mod.c: Likewise. * statistics.c: Likewise. * stmt.c: Likewise. * stor-layout.c: Likewise. * store-motion.c: Likewise. * stringpool.c: Likewise. * symtab.c: Likewise. * target-globals.c: Likewise. * targhooks.c: Likewise. * toplev.c: Likewise. * tracer.c: Likewise. * trans-mem.c: Likewise. * tree-affine.c: Likewise. * tree-call-cdce.c: Likewise. * tree-cfg.c: Likewise. * tree-cfgcleanup.c: Likewise. * tree-chkp-opt.c: Likewise. * tree-chkp.c: Likewise. * tree-chrec.c: Likewise. * tree-complex.c: Likewise. * tree-data-ref.c: Likewise. * tree-dfa.c: Likewise. * tree-diagnostic.c: Likewise. * tree-dump.c: Likewise. * tree-eh.c: Likewise. * tree-emutls.c: Likewise. * tree-if-conv.c: Likewise. * tree-inline.c: Likewise. * tree-into-ssa.c: Likewise. * tree-iterator.c: Likewise. * tree-loop-distribution.c: Likewise. * tree-nested.c: Likewise. * tree-nrv.c: Likewise. * tree-object-size.c: Likewise. * tree-outof-ssa.c: Likewise. * tree-parloops.c: Likewise. * tree-phinodes.c: Likewise. * tree-predcom.c: Likewise. * tree-pretty-print.c: Likewise. * tree-profile.c: Likewise. * tree-scalar-evolution.c: Likewise. * tree-sra.c: Likewise. * tree-ssa-address.c: Likewise. * tree-ssa-alias.c: Likewise. * tree-ssa-ccp.c: Likewise. * tree-ssa-coalesce.c: Likewise. * tree-ssa-copy.c: Likewise. * tree-ssa-dce.c: Likewise. * tree-ssa-dom.c: Likewise. * tree-ssa-dse.c: Likewise. * tree-ssa-forwprop.c: Likewise. * tree-ssa-ifcombine.c: Likewise. * tree-ssa-live.c: Likewise. * tree-ssa-loop-ch.c: Likewise. * tree-ssa-loop-im.c: Likewise. * tree-ssa-loop-ivcanon.c: Likewise. * tree-ssa-loop-ivopts.c: Likewise. * tree-ssa-loop-manip.c: Likewise. * tree-ssa-loop-niter.c: Likewise. * tree-ssa-loop-prefetch.c: Likewise. * tree-ssa-loop-unswitch.c: Likewise. * tree-ssa-loop.c: Likewise. * tree-ssa-math-opts.c: Likewise. * tree-ssa-operands.c: Likewise. * tree-ssa-phiopt.c: Likewise. * tree-ssa-phiprop.c: Likewise. * tree-ssa-pre.c: Likewise. * tree-ssa-propagate.c: Likewise. * tree-ssa-reassoc.c: Likewise. * tree-ssa-sccvn.c: Likewise. * tree-ssa-scopedtables.c: Likewise. * tree-ssa-sink.c: Likewise. * tree-ssa-strlen.c: Likewise. * tree-ssa-structalias.c: Likewise. * tree-ssa-tail-merge.c: Likewise. * tree-ssa-ter.c: Likewise. * tree-ssa-threadedge.c: Likewise. * tree-ssa-threadupdate.c: Likewise. * tree-ssa-uncprop.c: Likewise. * tree-ssa-uninit.c: Likewise. * tree-ssa.c: Likewise. * tree-ssanames.c: Likewise. * tree-stdarg.c: Likewise. * tree-streamer-in.c: Likewise. * tree-streamer-out.c: Likewise. * tree-streamer.c: Likewise. * tree-switch-conversion.c: Likewise. * tree-tailcall.c: Likewise. * tree-vect-data-refs.c: Likewise. * tree-vect-generic.c: Likewise. * tree-vect-loop-manip.c: Likewise. * tree-vect-loop.c: Likewise. * tree-vect-patterns.c: Likewise. * tree-vect-slp.c: Likewise. * tree-vect-stmts.c: Likewise. * tree-vectorizer.c: Likewise. * tree-vrp.c: Likewise. * tree.c: Likewise. * tsan.c: Likewise. * ubsan.c: Likewise. * value-prof.c: Likewise. * var-tracking.c: Likewise. * varasm.c: Likewise. * varpool.c: Likewise. * vtable-verify.c: Likewise. * web.c: Likewise. * wide-int-print.cc: Likewise. * wide-int.cc: Likewise. * xcoffout.c: Likewise. From-SVN: r229526
2015-10-29 14:57:32 +01:00
#include "stor-layout.h"
#include "cfganal.h"
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
#include "gimple-iterator.h"
#include "output.h"
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
#include "cfgloop.h"
#include "ubsan.h"
#include "expr.h"
#include "asan.h"
#include "gimplify-me.h"
builtins.def: Change SANITIZE_FLOAT_DIVIDE to SANITIZE_NONDEFAULT. * builtins.def: Change SANITIZE_FLOAT_DIVIDE to SANITIZE_NONDEFAULT. * gcc.c (sanitize_spec_function): Likewise. * convert.c (convert_to_integer): Include "ubsan.h". Add floating-point to integer instrumentation. * doc/invoke.texi: Document -fsanitize=float-cast-overflow. * flag-types.h (enum sanitize_code): Add SANITIZE_FLOAT_CAST and SANITIZE_NONDEFAULT. * opts.c (common_handle_option): Handle -fsanitize=float-cast-overflow. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_FLOAT_CAST_OVERFLOW, BUILT_IN_UBSAN_HANDLE_FLOAT_CAST_OVERFLOW_ABORT): Add. * ubsan.c: Include "realmpfr.h" and "dfp.h". (get_ubsan_type_info_for_type): Handle REAL_TYPEs. (ubsan_type_descriptor): Set tkind to 0xffff for types other than float/double/long double. (ubsan_instrument_float_cast): New function. * ubsan.h (ubsan_instrument_float_cast): Declare. testsuite/ * c-c++-common/ubsan/float-cast-overflow-1.c: New test. * c-c++-common/ubsan/float-cast-overflow-10.c: New test. * c-c++-common/ubsan/float-cast-overflow-2.c: New test. * c-c++-common/ubsan/float-cast-overflow-3.c: New test. * c-c++-common/ubsan/float-cast-overflow-4.c: New test. * c-c++-common/ubsan/float-cast-overflow-5.c: New test. * c-c++-common/ubsan/float-cast-overflow-6.c: New test. * c-c++-common/ubsan/float-cast-overflow-7.c: New test. * c-c++-common/ubsan/float-cast-overflow-7.h: New file. * c-c++-common/ubsan/float-cast-overflow-8.c: New test. * c-c++-common/ubsan/float-cast-overflow-9.c: New test. * c-c++-common/ubsan/float-cast.h: New file. * g++.dg/ubsan/float-cast-overflow-bf.C: New test. * gcc.dg/ubsan/float-cast-overflow-bf.c: New test. libsanitizer/ * ubsan/ubsan_value.cc (getFloatValue): Handle 96-bit floating-point types. Co-Authored-By: Jakub Jelinek <jakub@redhat.com> From-SVN: r210862
2014-05-23 16:44:42 +02:00
#include "dfp.h"
opts.c (common_handle_option): Handle -fsanitize=alignment. * opts.c (common_handle_option): Handle -fsanitize=alignment. * ubsan.h (enum ubsan_null_ckind): Add UBSAN_CTOR_CALL. (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn): Change return type to bool. * stor-layout.h (min_align_of_type): New prototype. * asan.c (pass_sanopt::execute): Don't perform gsi_next if ubsan_expand* told us not to do it. Remove the extra gsi_end_p check. * ubsan.c: Include builtins.h. (ubsan_expand_bounds_ifn): Change return type to bool, always return true. (ubsan_expand_null_ifn): Change return type to bool, change argument to gimple_stmt_iterator *. Handle both null and alignment sanitization, take type from ckind argument's type rather than first argument. (instrument_member_call): Removed. (instrument_mem_ref): Remove t argument, add mem and base arguments. Handle both null and alignment sanitization, don't say whole struct access is member access. Build 3 argument IFN_UBSAN_NULL call instead of 2 argument. (instrument_null): Adjust instrument_mem_ref caller. Don't instrument calls here. (pass_ubsan::gate, pass_ubsan::execute): Handle SANITIZE_ALIGNMENT like SANITIZE_NULL. * stor-layout.c (min_align_of_type): New function. * flag-types.h (enum sanitize_code): Add SANITIZE_ALIGNMENT. Or it into SANITIZE_UNDEFINED. * doc/invoke.texi (-fsanitize=alignment): Document. cp/ * cp-gimplify.c (cp_genericize_r): For -fsanitize=null and/or -fsanitize=alignment call ubsan_maybe_instrument_reference for casts to REFERENCE_TYPE and ubsan_maybe_instrument_member_call for calls to member functions. c-family/ * c-common.h (min_align_of_type): Removed prototype. * c-common.c (min_align_of_type): Removed. * c-ubsan.h (ubsan_maybe_instrument_reference, ubsan_maybe_instrument_member_call): New prototypes. * c-ubsan.c: Include stor-layout.h and builtins.h. (ubsan_maybe_instrument_reference_or_call, ubsan_maybe_instrument_reference, ubsan_maybe_instrument_call): New functions. testsuite/ * c-c++-common/ubsan/align-1.c: New test. * c-c++-common/ubsan/align-2.c: New test. * c-c++-common/ubsan/align-3.c: New test. * c-c++-common/ubsan/align-4.c: New test. * c-c++-common/ubsan/align-5.c: New test. * c-c++-common/ubsan/attrib-4.c: New test. * g++.dg/ubsan/align-1.C: New test. * g++.dg/ubsan/align-2.C: New test. * g++.dg/ubsan/align-3.C: New test. * g++.dg/ubsan/attrib-1.C: New test. * g++.dg/ubsan/null-1.C: New test. * g++.dg/ubsan/null-2.C: New test. From-SVN: r213406
2014-08-01 09:52:43 +02:00
#include "builtins.h"
#include "tree-object-size.h"
#include "tree-cfg.h"
/* Map from a tree to a VAR_DECL tree. */
struct GTY((for_user)) tree_type_map {
struct tree_map_base type;
tree decl;
};
struct tree_type_map_cache_hasher : ggc_cache_ptr_hash<tree_type_map>
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
{
static inline hashval_t
hash (tree_type_map *t)
{
return TYPE_UID (t->type.from);
}
static inline bool
equal (tree_type_map *a, tree_type_map *b)
{
return a->type.from == b->type.from;
}
2015-06-25 19:05:47 +02:00
static int
keep_cache_entry (tree_type_map *&m)
{
2015-06-25 19:05:47 +02:00
return ggc_marked_p (m->type.from);
}
};
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
static GTY ((cache))
hash_table<tree_type_map_cache_hasher> *decl_tree_for_type;
/* Lookup a VAR_DECL for TYPE, and return it if we find one. */
static tree
decl_for_type_lookup (tree type)
{
/* If the hash table is not initialized yet, create it now. */
if (decl_tree_for_type == NULL)
{
decl_tree_for_type
= hash_table<tree_type_map_cache_hasher>::create_ggc (10);
/* That also means we don't have to bother with the lookup. */
return NULL_TREE;
}
struct tree_type_map *h, in;
in.type.from = type;
h = decl_tree_for_type->find_with_hash (&in, TYPE_UID (type));
return h ? h->decl : NULL_TREE;
}
/* Insert a mapping TYPE->DECL in the VAR_DECL for type hashtable. */
static void
decl_for_type_insert (tree type, tree decl)
{
struct tree_type_map *h;
use templates instead of gengtype for typed allocation functions gcc/ChangeLog: * alias.c (record_alias_subset): Adjust. * bitmap.c (bitmap_element_allocate): Likewise. (bitmap_gc_alloc_stat): Likewise. * cfg.c (init_flow): Likewise. (alloc_block): Likewise. (unchecked_make_edge): Likewise. * cfgloop.c (alloc_loop): Likewise. (flow_loops_find): Likewise. (rescan_loop_exit): Likewise. * cfgrtl.c (init_rtl_bb_info): Likewise. * cgraph.c (insert_new_cgraph_node_version): Likewise. (cgraph_allocate_node): Likewise. (cgraph_create_edge_1): Likewise. (cgraph_allocate_init_indirect_info): Likewise. * cgraphclones.c (cgraph_clone_edge): Likewise. * cgraphunit.c (add_asm_node): Likewise. (init_lowered_empty_function): Likewise. * config/aarch64/aarch64.c (aarch64_init_machine_status): Likewise. * config/alpha/alpha.c (alpha_init_machine_status): Likewise. (alpha_use_linkage): Likewise. * config/arc/arc.c (arc_init_machine_status): Likewise. * config/arm/arm.c (arm_init_machine_status): Likewise. * config/avr/avr.c (avr_init_machine_status): Likewise. * config/bfin/bfin.c (bfin_init_machine_status): Likewise. * config/c6x/c6x.c (c6x_init_machine_status): Likewise. * config/cris/cris.c (cris_init_machine_status): Likewise. * config/darwin.c (machopic_indirection_name): Likewise. (darwin_build_constant_cfstring): Likewise. (darwin_enter_string_into_cfstring_table): Likewise. * config/epiphany/epiphany.c (epiphany_init_machine_status): * Likewise. * config/frv/frv.c (frv_init_machine_status): Likewise. * config/i386/i386.c (get_dllimport_decl): Likewise. (ix86_init_machine_status): Likewise. (assign_386_stack_local): Likewise. * config/i386/winnt.c (i386_pe_record_external_function): Likewise. (i386_pe_maybe_record_exported_symbol): Likewise. (i386_pe_record_stub): Likewise. * config/ia64/ia64.c (ia64_init_machine_status): Likewise. * config/iq2000/iq2000.c (iq2000_init_machine_status): Likewise. * config/m32c/m32c.c (m32c_init_machine_status): Likewise. (m32c_note_pragma_address): Likewise. * config/mep/mep.c (mep_init_machine_status): Likewise. (mep_note_pragma_flag): Likewise. * config/mips/mips.c (mflip_mips16_use_mips16_p): Likewise. (mips16_local_alias): Likewise. (mips_init_machine_status): Likewise. * config/mmix/mmix.c (mmix_init_machine_status): Likewise. * config/moxie/moxie.c (moxie_init_machine_status): Likewise. * config/msp430/msp430.c (msp430_init_machine_status): Likewise. * config/nds32/nds32.c (nds32_init_machine_status): Likewise. * config/nios2/nios2.c (nios2_init_machine_status): Likewise. * config/pa/pa.c (pa_init_machine_status): Likewise. (pa_get_deferred_plabel): Likewise. * config/rl78/rl78.c (rl78_init_machine_status): Likewise. * config/rs6000/rs6000.c (builtin_function_type): Likewise. (rs6000_init_machine_status): Likewise. (output_toc): Likewise. * config/s390/s390.c (s390_init_machine_status): Likewise. * config/score/score.c (score_output_external): Likewise. * config/sparc/sparc.c (sparc_init_machine_status): Likewise. * config/spu/spu.c (spu_init_machine_status): Likewise. * config/tilegx/tilegx.c (tilegx_init_machine_status): Likewise. * config/tilepro/tilepro.c (tilepro_init_machine_status): * Likewise. * config/xtensa/xtensa.c (xtensa_init_machine_status): Likewise. * coverage.c (coverage_end_function): Likewise. * dbxout.c (dbxout_init): Likewise. * doc/gty.texi: Don't mention variable_size attribute. * dwarf2cfi.c (new_cfi): Adjust. (new_cfi_row): Likewise. (copy_cfi_row): Likewise. (create_cie_data): Likewise. * dwarf2out.c (dwarf2out_alloc_current_fde): Likewise. (new_loc_descr): Likewise. (find_AT_string_in_table): Likewise. (add_addr_table_entry): Likewise. (new_die): Likewise. (add_var_loc_to_decl): Likewise. (clone_die): Likewise. (clone_as_declaration): Likewise. (break_out_comdat_types): Likewise. (new_loc_list): Likewise. (add_loc_descr_to_each): Likewise. (add_location_or_const_value_attribute): Likewise. (add_linkage_name): Likewise. (lookup_filename): Likewise. (dwarf2out_var_location): Likewise. (new_line_info_table): Likewise. (dwarf2out_init): Likewise. (mem_loc_descriptor): Likewise. (loc_descriptor): Likewise. (add_const_value_attribute): Likewise. (tree_add_const_value_attribute): Likewise. (comp_dir_string): Likewise. (dwarf2out_vms_debug_main_pointer): Likewise. (string_cst_pool_decl): Likewise. * emit-rtl.c (set_mem_attrs): Likewise. (get_reg_attrs): Likewise. (start_sequence): Likewise. (init_emit): Likewise. (init_emit_regs): Likewise. * except.c (init_eh_for_function): Likewise. (gen_eh_region): Likewise. (gen_eh_region_catch): Likewise. (gen_eh_landing_pad): Likewise. (add_call_site): Likewise. * function.c (add_frame_space): Likewise. (insert_temp_slot_address): Likewise. (assign_stack_temp_for_type): Likewise. (get_hard_reg_initial_val): Likewise. (allocate_struct_function): Likewise. (prepare_function_start): Likewise. (types_used_by_var_decl_insert): Likewise. * gengtype.c (variable_size_p): Remove function. (enum alloc_quantity): Remove enum. (write_typed_alloc_def): Remove function. (write_typed_struct_alloc_def): Likewise. (write_typed_typedef_alloc_def): Likewise. (write_typed_alloc_defns): Likewise. (main): Adjust. * ggc-common.c (ggc_cleared_alloc_htab_ignore_args): Adjust. (ggc_cleared_alloc_ptr_array_two_args): Likewise. * ggc.h (ggc_alloc): new function. (ggc_cleared_alloc): Likewise. (ggc_vec_alloc): Template on type of vector element, and remove element size argument. (ggc_cleared_vec_alloc): Likewise. * gimple.c (gimple_build_omp_for): Adjust. (gimple_copy): Likewise. * ipa-cp.c (get_replacement_map): Likewise. (find_aggregate_values_for_callers_subset): Likewise. (known_aggs_to_agg_replacement_list): Likewise. * ipa-devirt.c (get_odr_type): Likewise. * ipa-prop.c (ipa_node_duplication_hook): Likewise. (read_agg_replacement_chain): Likewise. * loop-iv.c (get_simple_loop_desc): Likewise. * lto-cgraph.c (input_node_opt_summary): Likewise. * lto-section-in.c (lto_new_in_decl_state): Likewise. * lto-streamer-in.c (lto_input_eh_catch_list): Likewise. (input_eh_region): Likewise. (input_eh_lp): Likewise. (input_cfg): Likewise. * optabs.c (set_optab_libfunc): Likewise. (init_tree_optimization_optabs): Likewise. (set_conv_libfunc): Likewise. * passes.c (do_per_function_toporder): Likewise. * rtl.h: Don't use variable_size gty attribute. * sese.c (if_region_set_false_region): Adjust. * stringpool.c (gt_pch_save_stringpool): Likewise. * target-globals.c (save_target_globals): Likewise. * toplev.c (general_init): Likewise. * trans-mem.c (record_tm_replacement): Likewise. (split_bb_make_tm_edge): Likewise. * tree-cfg.c (move_sese_region_to_fn): Likewise. * tree-data-ref.h (lambda_vector_new): Likewise. * tree-eh.c (add_stmt_to_eh_lp_fn): Likewise. * tree-iterator.c (tsi_link_before): Likewise. (tsi_link_after): Likewise. * tree-scalar-evolution.c (new_scev_info_str): Likewise. * tree-ssa-loop-niter.c (record_estimate): Likewise. * tree-ssa-operands.c (ssa_operand_alloc): Likewise. * tree-ssa-operands.h: Don't use variable_size gty attribute. * tree-ssa.c (init_tree_ssa): Adjust. * tree-ssanames.c (set_range_info): Likewise. (get_ptr_info): Likewise. (duplicate_ssa_name_ptr_info): Likewise. (duplicate_ssa_name_range_info): Likewise. * tree-streamer-in.c (unpack_ts_real_cst_value_fields): Likewise. (unpack_ts_fixed_cst_value_fields): Likewise. * tree.c (build_fixed): Likewise. (build_real): Likewise. (build_string): Likewise. (decl_priority_info): Likewise. (decl_debug_expr_insert): Likewise. (decl_value_expr_insert): Likewise. (decl_debug_args_insert): Likewise. (type_hash_add): Likewise. (build_omp_clause): Likewise. * ubsan.c (decl_for_type_insert): Likewise. * varasm.c (get_unnamed_section): Likewise. (get_noswitch_section): Likewise. (get_section): Likewise. (get_block_for_section): Likewise. (create_block_symbol): Likewise. (build_constant_desc): Likewise. (create_constant_pool): Likewise. (force_const_mem): Likewise. (record_tm_clone_pair): Likewise. * varpool.c (varpool_create_empty_node): Likewise. gcc/c/ChangeLog: * c-decl.c (finish_struct): Adjust. (finish_enum): Likewise. (bind): Adjust. (record_inline_static): Likewise. (push_scope): Likewise. (make_label): Likewise. (lookup_label_for_goto): Likewise. (finish_struct): Likewise. (finish_enum): Likewise. (store_parm_decls): Likewise. (c_push_function_context): Likewise. * c-lang.h: Remove usage of variable_size gty attribute. * c-parser.c (c_parse_init): Adjust. (c_parse_file): Likewise. gcc/java/ChangeLog: * class.c (add_method_1): Adjust. (java_treetreehash_new): Likewise. * constants.c (set_constant_entry): Likewise. (cpool_for_class): Likewise. * decl.c (make_binding_level): Likewise. (java_dup_lang_specific_decl): Likewise. * expr.c (add_type_assertion): Likewise. * java-tree.h (MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC): Likewise. (lang_decl): don't use variable_size gty attribute. (MAYBE_CREATE_TYPE_TYPE_LANG_SPECIFIC): Adjust. (lang_type): Don't use variable_size gty attribute. * jcf-parse.c (java_parse_file): Adjust. (process_zip_dir): Likewise. * jcf.h: Remove usage of variable_size gty attribute. * jcf-reader.c (jcf_parse_constant_pool): Adjust. (jcf_parse_bootstrap_methods): Likewise. gcc/objc/ChangeLog: * objc-act.c (objc_build_string_object): Adjust. (continue_class): Likewise. * objc-act.h (ALLOC_OBJC_TYPE_LANG_SPECIFIC): Likewise. * objc-map.c (objc_map_alloc_ggc): Likewise. (objc_map_private_resize): Likewise. * objc-next-runtime-abi-02.c (objc_next_runtime_abi_02_init): Likewise. (hash_name_enter): Likewise. gcc/cp/ChangeLog: * class.c (sorted_fields_type_new): Adjust. * cp-cilkplus.c (cilk_install_body_with_frame_cleanup): Likewise. * cp-objcp-common.c (decl_shadowed_for_var_insert): Likewise. * cp-tree.h: Remove usage of variable_size gty attribute. * decl.c (make_label_decl): Adjust. (check_goto): Likewise. (start_preparsed_function): Likewise. (save_function_data): Likewise. * lex.c (init_reswords): Likewise. (retrofit_lang_decl): Likewise. (cxx_dup_lang_specific_decl): Likewise. (copy_lang_type): Likewise. (cxx_make_type): Likewise. * name-lookup.c (binding_entry_make): Likewise. (binding_table_construct): Likewise. (binding_table_new): Likewise. (cxx_binding_make): Likewise. (pushdecl_maybe_friend_1): Likewise. (begin_scope): Likewise. (push_to_top_level): Likewise. * parser.c (cp_lexer_alloc): Likewise. (cp_lexer_new_from_tokens): Likewise. (cp_token_cache_new): Likewise. (cp_parser_context_new): Likewise. (cp_parser_new): Likewise. (cp_parser_nested_name_specifier_opt): Likewise. (cp_parser_template_id): Likewise. * pt.c (maybe_process_partial_specialization): Likewise. (register_specialization): Likewise. (add_pending_template): Likewise. (lookup_template_class_1): Likewise. (push_tinst_level): Likewise. * semantics.c (register_constexpr_fundef): Likewise. (cxx_eval_call_expression): Likewise. * typeck2.c (abstract_virtuals_error_sfinae): Likewise. gcc/fortran/ChangeLog: * f95-lang.c (pushlevel): Adjust. * trans-decl.c (gfc_allocate_lang_decl): Adjust. (gfc_find_module): Likewise. * trans-types.c (gfc_get_nodesc_array_type): Likewise. (gfc_get_array_type_bounds): Likewise. (gfc_nonrestricted_type): Likewise. * trans.h: Don't use variable_size gty attribute. gcc/ada/ChangeLog: * gcc-interface/ada-tree.h: Remove usage of variable_size gty annotation. * gcc-interface/decl.c (annotate_value): Adjust. * gcc-interface/trans.c (Attribute_to_gnu): Likewise. (push_range_check_info): Likewise. (Loop_Statement_to_gnu): Likewise. (Subprogram_Body_to_gnu): Likewise. (Compilation_Unit_to_gnu): Likewise. (start_stmt_group): Likewise. * gcc-interface/utils.c (init_gnat_utils): Likewise. (gnat_pushlevel): Likewise. (maybe_pad_type): Likewise. gcc/go/ChangeLog: * go-lang.c (struct GTY): Don't use variable_size gty attribute. gcc/c-family/ChangeLog: * c-common.h (sorted_fields_type): Remove variable_size GTY attribute. * c-pragma.c (push_alignment): Adjust. (handle_pragma_push_options): Likewise. gcc/lto/ChangeLog: * lto-tree.h: Don't use variable_size gty attribute. * lto.c (lto_read_in_decl_state): Adjust. (create_subid_section_table): Likewise. (lto_flatten_files): Likewise. (read_cgraph_and_symbols): Likewise. gcc/objcp/ChangeLog: * objcp-decl.h: Adjust. From-SVN: r210566
2014-05-18 01:07:23 +02:00
h = ggc_alloc<tree_type_map> ();
h->type.from = type;
h->decl = decl;
*decl_tree_for_type->find_slot_with_hash (h, TYPE_UID (type), INSERT) = h;
}
/* Helper routine, which encodes a value in the pointer_sized_int_node.
Arguments with precision <= POINTER_SIZE are passed directly,
the rest is passed by reference. T is a value we are to encode.
PHASE determines when this function is called. */
tree
ubsan_encode_value (tree t, enum ubsan_encode_value_phase phase)
{
tree type = TREE_TYPE (t);
const unsigned int bitsize = GET_MODE_BITSIZE (TYPE_MODE (type));
if (bitsize <= POINTER_SIZE)
switch (TREE_CODE (type))
{
case BOOLEAN_TYPE:
case ENUMERAL_TYPE:
case INTEGER_TYPE:
return fold_build1 (NOP_EXPR, pointer_sized_int_node, t);
case REAL_TYPE:
{
tree itype = build_nonstandard_integer_type (bitsize, true);
t = fold_build1 (VIEW_CONVERT_EXPR, itype, t);
return fold_convert (pointer_sized_int_node, t);
}
default:
gcc_unreachable ();
}
else
{
if (!DECL_P (t) || !TREE_ADDRESSABLE (t))
{
/* The reason for this is that we don't want to pessimize
code by making vars unnecessarily addressable. */
tree var;
if (phase != UBSAN_ENCODE_VALUE_GENERIC)
{
var = create_tmp_var (type);
mark_addressable (var);
}
else
{
var = create_tmp_var_raw (type);
TREE_ADDRESSABLE (var) = 1;
DECL_CONTEXT (var) = current_function_decl;
}
if (phase == UBSAN_ENCODE_VALUE_RTL)
{
rtx mem
= assign_stack_temp_for_type (TYPE_MODE (type),
GET_MODE_SIZE (TYPE_MODE (type)),
type);
SET_DECL_RTL (var, mem);
expand_assignment (var, t, false);
return build_fold_addr_expr (var);
}
if (phase != UBSAN_ENCODE_VALUE_GENERIC)
{
tree tem = build2 (MODIFY_EXPR, void_type_node, var, t);
t = build_fold_addr_expr (var);
return build2 (COMPOUND_EXPR, TREE_TYPE (t), tem, t);
}
else
{
var = build4 (TARGET_EXPR, type, var, t, NULL_TREE, NULL_TREE);
return build_fold_addr_expr (var);
}
}
else
return build_fold_addr_expr (t);
}
}
/* Cached ubsan_get_type_descriptor_type () return value. */
static GTY(()) tree ubsan_type_descriptor_type;
/* Build
struct __ubsan_type_descriptor
{
unsigned short __typekind;
unsigned short __typeinfo;
char __typename[];
}
type. */
static tree
ubsan_get_type_descriptor_type (void)
{
static const char *field_names[3]
= { "__typekind", "__typeinfo", "__typename" };
tree fields[3], ret;
if (ubsan_type_descriptor_type)
return ubsan_type_descriptor_type;
tree itype = build_range_type (sizetype, size_zero_node, NULL_TREE);
tree flex_arr_type = build_array_type (char_type_node, itype);
ret = make_node (RECORD_TYPE);
for (int i = 0; i < 3; i++)
{
fields[i] = build_decl (UNKNOWN_LOCATION, FIELD_DECL,
get_identifier (field_names[i]),
(i == 2) ? flex_arr_type
: short_unsigned_type_node);
DECL_CONTEXT (fields[i]) = ret;
if (i)
DECL_CHAIN (fields[i - 1]) = fields[i];
}
tree type_decl = build_decl (input_location, TYPE_DECL,
get_identifier ("__ubsan_type_descriptor"),
ret);
DECL_IGNORED_P (type_decl) = 1;
DECL_ARTIFICIAL (type_decl) = 1;
TYPE_FIELDS (ret) = fields[0];
TYPE_NAME (ret) = type_decl;
TYPE_STUB_DECL (ret) = type_decl;
layout_type (ret);
ubsan_type_descriptor_type = ret;
return ret;
}
/* Cached ubsan_get_source_location_type () return value. */
static GTY(()) tree ubsan_source_location_type;
/* Build
struct __ubsan_source_location
{
const char *__filename;
unsigned int __line;
unsigned int __column;
}
type. */
tree
ubsan_get_source_location_type (void)
{
static const char *field_names[3]
= { "__filename", "__line", "__column" };
tree fields[3], ret;
if (ubsan_source_location_type)
return ubsan_source_location_type;
tree const_char_type = build_qualified_type (char_type_node,
TYPE_QUAL_CONST);
ret = make_node (RECORD_TYPE);
for (int i = 0; i < 3; i++)
{
fields[i] = build_decl (UNKNOWN_LOCATION, FIELD_DECL,
get_identifier (field_names[i]),
(i == 0) ? build_pointer_type (const_char_type)
: unsigned_type_node);
DECL_CONTEXT (fields[i]) = ret;
if (i)
DECL_CHAIN (fields[i - 1]) = fields[i];
}
tree type_decl = build_decl (input_location, TYPE_DECL,
get_identifier ("__ubsan_source_location"),
ret);
DECL_IGNORED_P (type_decl) = 1;
DECL_ARTIFICIAL (type_decl) = 1;
TYPE_FIELDS (ret) = fields[0];
TYPE_NAME (ret) = type_decl;
TYPE_STUB_DECL (ret) = type_decl;
layout_type (ret);
ubsan_source_location_type = ret;
return ret;
}
/* Helper routine that returns a CONSTRUCTOR of __ubsan_source_location
type with its fields filled from a location_t LOC. */
static tree
ubsan_source_location (location_t loc)
{
expanded_location xloc;
tree type = ubsan_get_source_location_type ();
xloc = expand_location (loc);
tree str;
if (xloc.file == NULL)
{
str = build_int_cst (ptr_type_node, 0);
xloc.line = 0;
xloc.column = 0;
}
else
{
/* Fill in the values from LOC. */
size_t len = strlen (xloc.file) + 1;
str = build_string (len, xloc.file);
TREE_TYPE (str) = build_array_type_nelts (char_type_node, len);
TREE_READONLY (str) = 1;
TREE_STATIC (str) = 1;
str = build_fold_addr_expr (str);
}
tree ctor = build_constructor_va (type, 3, NULL_TREE, str, NULL_TREE,
build_int_cst (unsigned_type_node,
xloc.line), NULL_TREE,
build_int_cst (unsigned_type_node,
xloc.column));
TREE_CONSTANT (ctor) = 1;
TREE_STATIC (ctor) = 1;
return ctor;
}
/* This routine returns a magic number for TYPE. */
static unsigned short
get_ubsan_type_info_for_type (tree type)
{
builtins.def: Change SANITIZE_FLOAT_DIVIDE to SANITIZE_NONDEFAULT. * builtins.def: Change SANITIZE_FLOAT_DIVIDE to SANITIZE_NONDEFAULT. * gcc.c (sanitize_spec_function): Likewise. * convert.c (convert_to_integer): Include "ubsan.h". Add floating-point to integer instrumentation. * doc/invoke.texi: Document -fsanitize=float-cast-overflow. * flag-types.h (enum sanitize_code): Add SANITIZE_FLOAT_CAST and SANITIZE_NONDEFAULT. * opts.c (common_handle_option): Handle -fsanitize=float-cast-overflow. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_FLOAT_CAST_OVERFLOW, BUILT_IN_UBSAN_HANDLE_FLOAT_CAST_OVERFLOW_ABORT): Add. * ubsan.c: Include "realmpfr.h" and "dfp.h". (get_ubsan_type_info_for_type): Handle REAL_TYPEs. (ubsan_type_descriptor): Set tkind to 0xffff for types other than float/double/long double. (ubsan_instrument_float_cast): New function. * ubsan.h (ubsan_instrument_float_cast): Declare. testsuite/ * c-c++-common/ubsan/float-cast-overflow-1.c: New test. * c-c++-common/ubsan/float-cast-overflow-10.c: New test. * c-c++-common/ubsan/float-cast-overflow-2.c: New test. * c-c++-common/ubsan/float-cast-overflow-3.c: New test. * c-c++-common/ubsan/float-cast-overflow-4.c: New test. * c-c++-common/ubsan/float-cast-overflow-5.c: New test. * c-c++-common/ubsan/float-cast-overflow-6.c: New test. * c-c++-common/ubsan/float-cast-overflow-7.c: New test. * c-c++-common/ubsan/float-cast-overflow-7.h: New file. * c-c++-common/ubsan/float-cast-overflow-8.c: New test. * c-c++-common/ubsan/float-cast-overflow-9.c: New test. * c-c++-common/ubsan/float-cast.h: New file. * g++.dg/ubsan/float-cast-overflow-bf.C: New test. * gcc.dg/ubsan/float-cast-overflow-bf.c: New test. libsanitizer/ * ubsan/ubsan_value.cc (getFloatValue): Handle 96-bit floating-point types. Co-Authored-By: Jakub Jelinek <jakub@redhat.com> From-SVN: r210862
2014-05-23 16:44:42 +02:00
if (TREE_CODE (type) == REAL_TYPE)
return tree_to_uhwi (TYPE_SIZE (type));
asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * flag-types.h (enum sanitize_code): Add SANITIZE_BOUNDS and or it into SANITIZE_UNDEFINED. * doc/invoke.texi: Describe -fsanitize=bounds. * gimplify.c (gimplify_call_expr): Add gimplification of internal functions created in the FEs. * internal-fn.c: Move "internal-fn.h" after "tree.h". (expand_UBSAN_BOUNDS): New function. * internal-fn.def (UBSAN_BOUNDS): New internal function. * internal-fn.h: Don't define internal functions here. * opts.c (common_handle_option): Add -fsanitize=bounds. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS, BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS_ABORT): Add. * tree-core.h: Define internal functions here. (struct tree_base): Add ifn field. * tree-pretty-print.c: Include "internal-fn.h". (dump_generic_node): Handle functions without CALL_EXPR_FN. * tree.c (get_callee_fndecl): Likewise. (build_call_expr_internal_loc): New function. * tree.def (CALL_EXPR): Update description. * tree.h (CALL_EXPR_IFN): Define. (build_call_expr_internal_loc): Declare. * ubsan.c (get_ubsan_type_info_for_type): Return 0 for non-arithmetic types. (ubsan_type_descriptor): Change bool parameter to enum ubsan_print_style. Adjust the code. Add handling of UBSAN_PRINT_ARRAY. (ubsan_expand_bounds_ifn): New function. (ubsan_expand_null_ifn): Adjust ubsan_type_descriptor call. (ubsan_build_overflow_builtin): Likewise. (instrument_bool_enum_load): Likewise. (ubsan_instrument_float_cast): Likewise. * ubsan.h (enum ubsan_print_style): New enum. (ubsan_expand_bounds_ifn): Declare. (ubsan_type_descriptor): Adjust declaration. Use a default parameter. c-family/ * c-gimplify.c: Include "c-ubsan.h" and "pointer-set.h". (ubsan_walk_array_refs_r): New function. (c_genericize): Instrument array bounds. * c-ubsan.c: Include "internal-fn.h". (ubsan_instrument_division): Mark instrumented arrays as having side effects. Adjust ubsan_type_descriptor call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Adjust ubsan_type_descriptor call. (ubsan_instrument_bounds): New function. (ubsan_array_ref_instrumented_p): New function. (ubsan_maybe_instrument_array_ref): New function. * c-ubsan.h (ubsan_instrument_bounds): Declare. (ubsan_array_ref_instrumented_p): Declare. (ubsan_maybe_instrument_array_ref): Declare. testsuite/ * c-c++-common/ubsan/bounds-1.c: New test. * c-c++-common/ubsan/bounds-2.c: New test. * c-c++-common/ubsan/bounds-3.c: New test. * c-c++-common/ubsan/bounds-4.c: New test. * c-c++-common/ubsan/bounds-5.c: New test. * c-c++-common/ubsan/bounds-6.c: New test. From-SVN: r211859
2014-06-20 23:20:51 +02:00
else if (INTEGRAL_TYPE_P (type))
builtins.def: Change SANITIZE_FLOAT_DIVIDE to SANITIZE_NONDEFAULT. * builtins.def: Change SANITIZE_FLOAT_DIVIDE to SANITIZE_NONDEFAULT. * gcc.c (sanitize_spec_function): Likewise. * convert.c (convert_to_integer): Include "ubsan.h". Add floating-point to integer instrumentation. * doc/invoke.texi: Document -fsanitize=float-cast-overflow. * flag-types.h (enum sanitize_code): Add SANITIZE_FLOAT_CAST and SANITIZE_NONDEFAULT. * opts.c (common_handle_option): Handle -fsanitize=float-cast-overflow. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_FLOAT_CAST_OVERFLOW, BUILT_IN_UBSAN_HANDLE_FLOAT_CAST_OVERFLOW_ABORT): Add. * ubsan.c: Include "realmpfr.h" and "dfp.h". (get_ubsan_type_info_for_type): Handle REAL_TYPEs. (ubsan_type_descriptor): Set tkind to 0xffff for types other than float/double/long double. (ubsan_instrument_float_cast): New function. * ubsan.h (ubsan_instrument_float_cast): Declare. testsuite/ * c-c++-common/ubsan/float-cast-overflow-1.c: New test. * c-c++-common/ubsan/float-cast-overflow-10.c: New test. * c-c++-common/ubsan/float-cast-overflow-2.c: New test. * c-c++-common/ubsan/float-cast-overflow-3.c: New test. * c-c++-common/ubsan/float-cast-overflow-4.c: New test. * c-c++-common/ubsan/float-cast-overflow-5.c: New test. * c-c++-common/ubsan/float-cast-overflow-6.c: New test. * c-c++-common/ubsan/float-cast-overflow-7.c: New test. * c-c++-common/ubsan/float-cast-overflow-7.h: New file. * c-c++-common/ubsan/float-cast-overflow-8.c: New test. * c-c++-common/ubsan/float-cast-overflow-9.c: New test. * c-c++-common/ubsan/float-cast.h: New file. * g++.dg/ubsan/float-cast-overflow-bf.C: New test. * gcc.dg/ubsan/float-cast-overflow-bf.c: New test. libsanitizer/ * ubsan/ubsan_value.cc (getFloatValue): Handle 96-bit floating-point types. Co-Authored-By: Jakub Jelinek <jakub@redhat.com> From-SVN: r210862
2014-05-23 16:44:42 +02:00
{
int prec = exact_log2 (tree_to_uhwi (TYPE_SIZE (type)));
gcc_assert (prec != -1);
return (prec << 1) | !TYPE_UNSIGNED (type);
}
asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * flag-types.h (enum sanitize_code): Add SANITIZE_BOUNDS and or it into SANITIZE_UNDEFINED. * doc/invoke.texi: Describe -fsanitize=bounds. * gimplify.c (gimplify_call_expr): Add gimplification of internal functions created in the FEs. * internal-fn.c: Move "internal-fn.h" after "tree.h". (expand_UBSAN_BOUNDS): New function. * internal-fn.def (UBSAN_BOUNDS): New internal function. * internal-fn.h: Don't define internal functions here. * opts.c (common_handle_option): Add -fsanitize=bounds. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS, BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS_ABORT): Add. * tree-core.h: Define internal functions here. (struct tree_base): Add ifn field. * tree-pretty-print.c: Include "internal-fn.h". (dump_generic_node): Handle functions without CALL_EXPR_FN. * tree.c (get_callee_fndecl): Likewise. (build_call_expr_internal_loc): New function. * tree.def (CALL_EXPR): Update description. * tree.h (CALL_EXPR_IFN): Define. (build_call_expr_internal_loc): Declare. * ubsan.c (get_ubsan_type_info_for_type): Return 0 for non-arithmetic types. (ubsan_type_descriptor): Change bool parameter to enum ubsan_print_style. Adjust the code. Add handling of UBSAN_PRINT_ARRAY. (ubsan_expand_bounds_ifn): New function. (ubsan_expand_null_ifn): Adjust ubsan_type_descriptor call. (ubsan_build_overflow_builtin): Likewise. (instrument_bool_enum_load): Likewise. (ubsan_instrument_float_cast): Likewise. * ubsan.h (enum ubsan_print_style): New enum. (ubsan_expand_bounds_ifn): Declare. (ubsan_type_descriptor): Adjust declaration. Use a default parameter. c-family/ * c-gimplify.c: Include "c-ubsan.h" and "pointer-set.h". (ubsan_walk_array_refs_r): New function. (c_genericize): Instrument array bounds. * c-ubsan.c: Include "internal-fn.h". (ubsan_instrument_division): Mark instrumented arrays as having side effects. Adjust ubsan_type_descriptor call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Adjust ubsan_type_descriptor call. (ubsan_instrument_bounds): New function. (ubsan_array_ref_instrumented_p): New function. (ubsan_maybe_instrument_array_ref): New function. * c-ubsan.h (ubsan_instrument_bounds): Declare. (ubsan_array_ref_instrumented_p): Declare. (ubsan_maybe_instrument_array_ref): Declare. testsuite/ * c-c++-common/ubsan/bounds-1.c: New test. * c-c++-common/ubsan/bounds-2.c: New test. * c-c++-common/ubsan/bounds-3.c: New test. * c-c++-common/ubsan/bounds-4.c: New test. * c-c++-common/ubsan/bounds-5.c: New test. * c-c++-common/ubsan/bounds-6.c: New test. From-SVN: r211859
2014-06-20 23:20:51 +02:00
else
return 0;
}
/* Counters for internal labels. ubsan_ids[0] for Lubsan_type,
ubsan_ids[1] for Lubsan_data labels. */
static GTY(()) unsigned int ubsan_ids[2];
/* Helper routine that returns ADDR_EXPR of a VAR_DECL of a type
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
descriptor. It first looks into the hash table; if not found,
create the VAR_DECL, put it into the hash table and return the
asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * flag-types.h (enum sanitize_code): Add SANITIZE_BOUNDS and or it into SANITIZE_UNDEFINED. * doc/invoke.texi: Describe -fsanitize=bounds. * gimplify.c (gimplify_call_expr): Add gimplification of internal functions created in the FEs. * internal-fn.c: Move "internal-fn.h" after "tree.h". (expand_UBSAN_BOUNDS): New function. * internal-fn.def (UBSAN_BOUNDS): New internal function. * internal-fn.h: Don't define internal functions here. * opts.c (common_handle_option): Add -fsanitize=bounds. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS, BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS_ABORT): Add. * tree-core.h: Define internal functions here. (struct tree_base): Add ifn field. * tree-pretty-print.c: Include "internal-fn.h". (dump_generic_node): Handle functions without CALL_EXPR_FN. * tree.c (get_callee_fndecl): Likewise. (build_call_expr_internal_loc): New function. * tree.def (CALL_EXPR): Update description. * tree.h (CALL_EXPR_IFN): Define. (build_call_expr_internal_loc): Declare. * ubsan.c (get_ubsan_type_info_for_type): Return 0 for non-arithmetic types. (ubsan_type_descriptor): Change bool parameter to enum ubsan_print_style. Adjust the code. Add handling of UBSAN_PRINT_ARRAY. (ubsan_expand_bounds_ifn): New function. (ubsan_expand_null_ifn): Adjust ubsan_type_descriptor call. (ubsan_build_overflow_builtin): Likewise. (instrument_bool_enum_load): Likewise. (ubsan_instrument_float_cast): Likewise. * ubsan.h (enum ubsan_print_style): New enum. (ubsan_expand_bounds_ifn): Declare. (ubsan_type_descriptor): Adjust declaration. Use a default parameter. c-family/ * c-gimplify.c: Include "c-ubsan.h" and "pointer-set.h". (ubsan_walk_array_refs_r): New function. (c_genericize): Instrument array bounds. * c-ubsan.c: Include "internal-fn.h". (ubsan_instrument_division): Mark instrumented arrays as having side effects. Adjust ubsan_type_descriptor call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Adjust ubsan_type_descriptor call. (ubsan_instrument_bounds): New function. (ubsan_array_ref_instrumented_p): New function. (ubsan_maybe_instrument_array_ref): New function. * c-ubsan.h (ubsan_instrument_bounds): Declare. (ubsan_array_ref_instrumented_p): Declare. (ubsan_maybe_instrument_array_ref): Declare. testsuite/ * c-c++-common/ubsan/bounds-1.c: New test. * c-c++-common/ubsan/bounds-2.c: New test. * c-c++-common/ubsan/bounds-3.c: New test. * c-c++-common/ubsan/bounds-4.c: New test. * c-c++-common/ubsan/bounds-5.c: New test. * c-c++-common/ubsan/bounds-6.c: New test. From-SVN: r211859
2014-06-20 23:20:51 +02:00
ADDR_EXPR of it. TYPE describes a particular type. PSTYLE is
an enum controlling how we want to print the type. */
tree
asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * flag-types.h (enum sanitize_code): Add SANITIZE_BOUNDS and or it into SANITIZE_UNDEFINED. * doc/invoke.texi: Describe -fsanitize=bounds. * gimplify.c (gimplify_call_expr): Add gimplification of internal functions created in the FEs. * internal-fn.c: Move "internal-fn.h" after "tree.h". (expand_UBSAN_BOUNDS): New function. * internal-fn.def (UBSAN_BOUNDS): New internal function. * internal-fn.h: Don't define internal functions here. * opts.c (common_handle_option): Add -fsanitize=bounds. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS, BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS_ABORT): Add. * tree-core.h: Define internal functions here. (struct tree_base): Add ifn field. * tree-pretty-print.c: Include "internal-fn.h". (dump_generic_node): Handle functions without CALL_EXPR_FN. * tree.c (get_callee_fndecl): Likewise. (build_call_expr_internal_loc): New function. * tree.def (CALL_EXPR): Update description. * tree.h (CALL_EXPR_IFN): Define. (build_call_expr_internal_loc): Declare. * ubsan.c (get_ubsan_type_info_for_type): Return 0 for non-arithmetic types. (ubsan_type_descriptor): Change bool parameter to enum ubsan_print_style. Adjust the code. Add handling of UBSAN_PRINT_ARRAY. (ubsan_expand_bounds_ifn): New function. (ubsan_expand_null_ifn): Adjust ubsan_type_descriptor call. (ubsan_build_overflow_builtin): Likewise. (instrument_bool_enum_load): Likewise. (ubsan_instrument_float_cast): Likewise. * ubsan.h (enum ubsan_print_style): New enum. (ubsan_expand_bounds_ifn): Declare. (ubsan_type_descriptor): Adjust declaration. Use a default parameter. c-family/ * c-gimplify.c: Include "c-ubsan.h" and "pointer-set.h". (ubsan_walk_array_refs_r): New function. (c_genericize): Instrument array bounds. * c-ubsan.c: Include "internal-fn.h". (ubsan_instrument_division): Mark instrumented arrays as having side effects. Adjust ubsan_type_descriptor call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Adjust ubsan_type_descriptor call. (ubsan_instrument_bounds): New function. (ubsan_array_ref_instrumented_p): New function. (ubsan_maybe_instrument_array_ref): New function. * c-ubsan.h (ubsan_instrument_bounds): Declare. (ubsan_array_ref_instrumented_p): Declare. (ubsan_maybe_instrument_array_ref): Declare. testsuite/ * c-c++-common/ubsan/bounds-1.c: New test. * c-c++-common/ubsan/bounds-2.c: New test. * c-c++-common/ubsan/bounds-3.c: New test. * c-c++-common/ubsan/bounds-4.c: New test. * c-c++-common/ubsan/bounds-5.c: New test. * c-c++-common/ubsan/bounds-6.c: New test. From-SVN: r211859
2014-06-20 23:20:51 +02:00
ubsan_type_descriptor (tree type, enum ubsan_print_style pstyle)
{
/* See through any typedefs. */
type = TYPE_MAIN_VARIANT (type);
tree decl = decl_for_type_lookup (type);
/* It is possible that some of the earlier created DECLs were found
IPA C++ refactoring 2/N * cgraph.h (varpool_node): (availability get_availability (void)): created from cgraph_variable_initializer_availability (inline varpool_node *ultimate_alias_target (availability *availability = NULL) creted from: cgraph_variable_initializer_availability (inline varpool_node *get_alias_target (void)): created from varpool_alias_target (void finalize_named_section_flags (void)): created from varpool_finalize_named_section_flags (bool assemble_decl (void)): created from varpool_assemble_decl (void analyze (void)): created from varpool_analyze_node (bool call_for_node_and_aliases (bool (*callback) (varpool_node *, void *), void *data, bool include_overwritable)): created fromvarpool_for_node_and_aliases (void remove_initializer (void)): created from varpool_remove_initializer (tree get_constructor (void)): created from varpool_get_constructor (bool externally_visible_p (void)): created from varpool_externally_visible_p (bool ctor_useable_for_folding_p (void)): created from varpool_ctor_useable_for_folding_p (inline bool all_refs_explicit_p ()): created from varpool_all_refs_explicit_p (inline bool can_remove_if_no_refs_p (void)): created from varpool_can_remove_if_no_refs (static inline varpool_node *get (const_tree decl)): created from varpool_get_node (static void finalize_decl (tree decl)): created from varpool_finalize_decl (static bool output_variables (void)): created from varpool_output_variables (static varpool_node * create_extra_name_alias (tree alias, tree decl)): created from varpool_extra_name_alias (static varpool_node * create_alias (tree, tree)): created from varpool_create_variable_alias (static void dump_varpool (FILE *f)): created from dump_varpool (static void DEBUG_FUNCTION debug_varpool (void)): created from debug_varpool (static varpool_node *create_empty (void)): created from varpool_create_empty_node (static varpool_node *get_create (tree decl)): created from varpool_node_for_decl (static varpool_node *get_for_asmname (tree asmname)): created from varpool_node_for_asm (void assemble_aliases (void)): created from assemble_aliases From-SVN: r212984
2014-07-24 14:25:27 +02:00
unused, in that case they weren't emitted and varpool_node::get
returns NULL node on them. But now we really need them. Thus,
renew them here. */
IPA C++ refactoring 2/N * cgraph.h (varpool_node): (availability get_availability (void)): created from cgraph_variable_initializer_availability (inline varpool_node *ultimate_alias_target (availability *availability = NULL) creted from: cgraph_variable_initializer_availability (inline varpool_node *get_alias_target (void)): created from varpool_alias_target (void finalize_named_section_flags (void)): created from varpool_finalize_named_section_flags (bool assemble_decl (void)): created from varpool_assemble_decl (void analyze (void)): created from varpool_analyze_node (bool call_for_node_and_aliases (bool (*callback) (varpool_node *, void *), void *data, bool include_overwritable)): created fromvarpool_for_node_and_aliases (void remove_initializer (void)): created from varpool_remove_initializer (tree get_constructor (void)): created from varpool_get_constructor (bool externally_visible_p (void)): created from varpool_externally_visible_p (bool ctor_useable_for_folding_p (void)): created from varpool_ctor_useable_for_folding_p (inline bool all_refs_explicit_p ()): created from varpool_all_refs_explicit_p (inline bool can_remove_if_no_refs_p (void)): created from varpool_can_remove_if_no_refs (static inline varpool_node *get (const_tree decl)): created from varpool_get_node (static void finalize_decl (tree decl)): created from varpool_finalize_decl (static bool output_variables (void)): created from varpool_output_variables (static varpool_node * create_extra_name_alias (tree alias, tree decl)): created from varpool_extra_name_alias (static varpool_node * create_alias (tree, tree)): created from varpool_create_variable_alias (static void dump_varpool (FILE *f)): created from dump_varpool (static void DEBUG_FUNCTION debug_varpool (void)): created from debug_varpool (static varpool_node *create_empty (void)): created from varpool_create_empty_node (static varpool_node *get_create (tree decl)): created from varpool_node_for_decl (static varpool_node *get_for_asmname (tree asmname)): created from varpool_node_for_asm (void assemble_aliases (void)): created from assemble_aliases From-SVN: r212984
2014-07-24 14:25:27 +02:00
if (decl != NULL_TREE && varpool_node::get (decl))
return build_fold_addr_expr (decl);
tree dtype = ubsan_get_type_descriptor_type ();
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
tree type2 = type;
const char *tname = NULL;
pretty_printer pretty_name;
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
unsigned char deref_depth = 0;
unsigned short tkind, tinfo;
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
/* Get the name of the type, or the name of the pointer type. */
asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * flag-types.h (enum sanitize_code): Add SANITIZE_BOUNDS and or it into SANITIZE_UNDEFINED. * doc/invoke.texi: Describe -fsanitize=bounds. * gimplify.c (gimplify_call_expr): Add gimplification of internal functions created in the FEs. * internal-fn.c: Move "internal-fn.h" after "tree.h". (expand_UBSAN_BOUNDS): New function. * internal-fn.def (UBSAN_BOUNDS): New internal function. * internal-fn.h: Don't define internal functions here. * opts.c (common_handle_option): Add -fsanitize=bounds. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS, BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS_ABORT): Add. * tree-core.h: Define internal functions here. (struct tree_base): Add ifn field. * tree-pretty-print.c: Include "internal-fn.h". (dump_generic_node): Handle functions without CALL_EXPR_FN. * tree.c (get_callee_fndecl): Likewise. (build_call_expr_internal_loc): New function. * tree.def (CALL_EXPR): Update description. * tree.h (CALL_EXPR_IFN): Define. (build_call_expr_internal_loc): Declare. * ubsan.c (get_ubsan_type_info_for_type): Return 0 for non-arithmetic types. (ubsan_type_descriptor): Change bool parameter to enum ubsan_print_style. Adjust the code. Add handling of UBSAN_PRINT_ARRAY. (ubsan_expand_bounds_ifn): New function. (ubsan_expand_null_ifn): Adjust ubsan_type_descriptor call. (ubsan_build_overflow_builtin): Likewise. (instrument_bool_enum_load): Likewise. (ubsan_instrument_float_cast): Likewise. * ubsan.h (enum ubsan_print_style): New enum. (ubsan_expand_bounds_ifn): Declare. (ubsan_type_descriptor): Adjust declaration. Use a default parameter. c-family/ * c-gimplify.c: Include "c-ubsan.h" and "pointer-set.h". (ubsan_walk_array_refs_r): New function. (c_genericize): Instrument array bounds. * c-ubsan.c: Include "internal-fn.h". (ubsan_instrument_division): Mark instrumented arrays as having side effects. Adjust ubsan_type_descriptor call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Adjust ubsan_type_descriptor call. (ubsan_instrument_bounds): New function. (ubsan_array_ref_instrumented_p): New function. (ubsan_maybe_instrument_array_ref): New function. * c-ubsan.h (ubsan_instrument_bounds): Declare. (ubsan_array_ref_instrumented_p): Declare. (ubsan_maybe_instrument_array_ref): Declare. testsuite/ * c-c++-common/ubsan/bounds-1.c: New test. * c-c++-common/ubsan/bounds-2.c: New test. * c-c++-common/ubsan/bounds-3.c: New test. * c-c++-common/ubsan/bounds-4.c: New test. * c-c++-common/ubsan/bounds-5.c: New test. * c-c++-common/ubsan/bounds-6.c: New test. From-SVN: r211859
2014-06-20 23:20:51 +02:00
if (pstyle == UBSAN_PRINT_POINTER)
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
{
gcc_assert (POINTER_TYPE_P (type));
type2 = TREE_TYPE (type);
/* Remove any '*' operators from TYPE. */
while (POINTER_TYPE_P (type2))
deref_depth++, type2 = TREE_TYPE (type2);
if (TREE_CODE (type2) == METHOD_TYPE)
type2 = TYPE_METHOD_BASETYPE (type2);
}
/* If an array, get its type. */
type2 = strip_array_types (type2);
asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * flag-types.h (enum sanitize_code): Add SANITIZE_BOUNDS and or it into SANITIZE_UNDEFINED. * doc/invoke.texi: Describe -fsanitize=bounds. * gimplify.c (gimplify_call_expr): Add gimplification of internal functions created in the FEs. * internal-fn.c: Move "internal-fn.h" after "tree.h". (expand_UBSAN_BOUNDS): New function. * internal-fn.def (UBSAN_BOUNDS): New internal function. * internal-fn.h: Don't define internal functions here. * opts.c (common_handle_option): Add -fsanitize=bounds. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS, BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS_ABORT): Add. * tree-core.h: Define internal functions here. (struct tree_base): Add ifn field. * tree-pretty-print.c: Include "internal-fn.h". (dump_generic_node): Handle functions without CALL_EXPR_FN. * tree.c (get_callee_fndecl): Likewise. (build_call_expr_internal_loc): New function. * tree.def (CALL_EXPR): Update description. * tree.h (CALL_EXPR_IFN): Define. (build_call_expr_internal_loc): Declare. * ubsan.c (get_ubsan_type_info_for_type): Return 0 for non-arithmetic types. (ubsan_type_descriptor): Change bool parameter to enum ubsan_print_style. Adjust the code. Add handling of UBSAN_PRINT_ARRAY. (ubsan_expand_bounds_ifn): New function. (ubsan_expand_null_ifn): Adjust ubsan_type_descriptor call. (ubsan_build_overflow_builtin): Likewise. (instrument_bool_enum_load): Likewise. (ubsan_instrument_float_cast): Likewise. * ubsan.h (enum ubsan_print_style): New enum. (ubsan_expand_bounds_ifn): Declare. (ubsan_type_descriptor): Adjust declaration. Use a default parameter. c-family/ * c-gimplify.c: Include "c-ubsan.h" and "pointer-set.h". (ubsan_walk_array_refs_r): New function. (c_genericize): Instrument array bounds. * c-ubsan.c: Include "internal-fn.h". (ubsan_instrument_division): Mark instrumented arrays as having side effects. Adjust ubsan_type_descriptor call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Adjust ubsan_type_descriptor call. (ubsan_instrument_bounds): New function. (ubsan_array_ref_instrumented_p): New function. (ubsan_maybe_instrument_array_ref): New function. * c-ubsan.h (ubsan_instrument_bounds): Declare. (ubsan_array_ref_instrumented_p): Declare. (ubsan_maybe_instrument_array_ref): Declare. testsuite/ * c-c++-common/ubsan/bounds-1.c: New test. * c-c++-common/ubsan/bounds-2.c: New test. * c-c++-common/ubsan/bounds-3.c: New test. * c-c++-common/ubsan/bounds-4.c: New test. * c-c++-common/ubsan/bounds-5.c: New test. * c-c++-common/ubsan/bounds-6.c: New test. From-SVN: r211859
2014-06-20 23:20:51 +02:00
if (pstyle == UBSAN_PRINT_ARRAY)
{
while (POINTER_TYPE_P (type2))
deref_depth++, type2 = TREE_TYPE (type2);
}
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
if (TYPE_NAME (type2) != NULL)
{
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
if (TREE_CODE (TYPE_NAME (type2)) == IDENTIFIER_NODE)
tname = IDENTIFIER_POINTER (TYPE_NAME (type2));
else if (DECL_NAME (TYPE_NAME (type2)) != NULL)
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
tname = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type2)));
}
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
if (tname == NULL)
/* We weren't able to determine the type name. */
tname = "<unknown>";
tree eltype = type;
asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * flag-types.h (enum sanitize_code): Add SANITIZE_BOUNDS and or it into SANITIZE_UNDEFINED. * doc/invoke.texi: Describe -fsanitize=bounds. * gimplify.c (gimplify_call_expr): Add gimplification of internal functions created in the FEs. * internal-fn.c: Move "internal-fn.h" after "tree.h". (expand_UBSAN_BOUNDS): New function. * internal-fn.def (UBSAN_BOUNDS): New internal function. * internal-fn.h: Don't define internal functions here. * opts.c (common_handle_option): Add -fsanitize=bounds. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS, BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS_ABORT): Add. * tree-core.h: Define internal functions here. (struct tree_base): Add ifn field. * tree-pretty-print.c: Include "internal-fn.h". (dump_generic_node): Handle functions without CALL_EXPR_FN. * tree.c (get_callee_fndecl): Likewise. (build_call_expr_internal_loc): New function. * tree.def (CALL_EXPR): Update description. * tree.h (CALL_EXPR_IFN): Define. (build_call_expr_internal_loc): Declare. * ubsan.c (get_ubsan_type_info_for_type): Return 0 for non-arithmetic types. (ubsan_type_descriptor): Change bool parameter to enum ubsan_print_style. Adjust the code. Add handling of UBSAN_PRINT_ARRAY. (ubsan_expand_bounds_ifn): New function. (ubsan_expand_null_ifn): Adjust ubsan_type_descriptor call. (ubsan_build_overflow_builtin): Likewise. (instrument_bool_enum_load): Likewise. (ubsan_instrument_float_cast): Likewise. * ubsan.h (enum ubsan_print_style): New enum. (ubsan_expand_bounds_ifn): Declare. (ubsan_type_descriptor): Adjust declaration. Use a default parameter. c-family/ * c-gimplify.c: Include "c-ubsan.h" and "pointer-set.h". (ubsan_walk_array_refs_r): New function. (c_genericize): Instrument array bounds. * c-ubsan.c: Include "internal-fn.h". (ubsan_instrument_division): Mark instrumented arrays as having side effects. Adjust ubsan_type_descriptor call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Adjust ubsan_type_descriptor call. (ubsan_instrument_bounds): New function. (ubsan_array_ref_instrumented_p): New function. (ubsan_maybe_instrument_array_ref): New function. * c-ubsan.h (ubsan_instrument_bounds): Declare. (ubsan_array_ref_instrumented_p): Declare. (ubsan_maybe_instrument_array_ref): Declare. testsuite/ * c-c++-common/ubsan/bounds-1.c: New test. * c-c++-common/ubsan/bounds-2.c: New test. * c-c++-common/ubsan/bounds-3.c: New test. * c-c++-common/ubsan/bounds-4.c: New test. * c-c++-common/ubsan/bounds-5.c: New test. * c-c++-common/ubsan/bounds-6.c: New test. From-SVN: r211859
2014-06-20 23:20:51 +02:00
if (pstyle == UBSAN_PRINT_POINTER)
{
pp_printf (&pretty_name, "'%s%s%s%s%s%s%s",
TYPE_VOLATILE (type2) ? "volatile " : "",
TYPE_READONLY (type2) ? "const " : "",
TYPE_RESTRICT (type2) ? "restrict " : "",
TYPE_ATOMIC (type2) ? "_Atomic " : "",
TREE_CODE (type2) == RECORD_TYPE
? "struct "
: TREE_CODE (type2) == UNION_TYPE
? "union " : "", tname,
deref_depth == 0 ? "" : " ");
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
while (deref_depth-- > 0)
pp_star (&pretty_name);
pp_quote (&pretty_name);
}
asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * flag-types.h (enum sanitize_code): Add SANITIZE_BOUNDS and or it into SANITIZE_UNDEFINED. * doc/invoke.texi: Describe -fsanitize=bounds. * gimplify.c (gimplify_call_expr): Add gimplification of internal functions created in the FEs. * internal-fn.c: Move "internal-fn.h" after "tree.h". (expand_UBSAN_BOUNDS): New function. * internal-fn.def (UBSAN_BOUNDS): New internal function. * internal-fn.h: Don't define internal functions here. * opts.c (common_handle_option): Add -fsanitize=bounds. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS, BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS_ABORT): Add. * tree-core.h: Define internal functions here. (struct tree_base): Add ifn field. * tree-pretty-print.c: Include "internal-fn.h". (dump_generic_node): Handle functions without CALL_EXPR_FN. * tree.c (get_callee_fndecl): Likewise. (build_call_expr_internal_loc): New function. * tree.def (CALL_EXPR): Update description. * tree.h (CALL_EXPR_IFN): Define. (build_call_expr_internal_loc): Declare. * ubsan.c (get_ubsan_type_info_for_type): Return 0 for non-arithmetic types. (ubsan_type_descriptor): Change bool parameter to enum ubsan_print_style. Adjust the code. Add handling of UBSAN_PRINT_ARRAY. (ubsan_expand_bounds_ifn): New function. (ubsan_expand_null_ifn): Adjust ubsan_type_descriptor call. (ubsan_build_overflow_builtin): Likewise. (instrument_bool_enum_load): Likewise. (ubsan_instrument_float_cast): Likewise. * ubsan.h (enum ubsan_print_style): New enum. (ubsan_expand_bounds_ifn): Declare. (ubsan_type_descriptor): Adjust declaration. Use a default parameter. c-family/ * c-gimplify.c: Include "c-ubsan.h" and "pointer-set.h". (ubsan_walk_array_refs_r): New function. (c_genericize): Instrument array bounds. * c-ubsan.c: Include "internal-fn.h". (ubsan_instrument_division): Mark instrumented arrays as having side effects. Adjust ubsan_type_descriptor call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Adjust ubsan_type_descriptor call. (ubsan_instrument_bounds): New function. (ubsan_array_ref_instrumented_p): New function. (ubsan_maybe_instrument_array_ref): New function. * c-ubsan.h (ubsan_instrument_bounds): Declare. (ubsan_array_ref_instrumented_p): Declare. (ubsan_maybe_instrument_array_ref): Declare. testsuite/ * c-c++-common/ubsan/bounds-1.c: New test. * c-c++-common/ubsan/bounds-2.c: New test. * c-c++-common/ubsan/bounds-3.c: New test. * c-c++-common/ubsan/bounds-4.c: New test. * c-c++-common/ubsan/bounds-5.c: New test. * c-c++-common/ubsan/bounds-6.c: New test. From-SVN: r211859
2014-06-20 23:20:51 +02:00
else if (pstyle == UBSAN_PRINT_ARRAY)
{
/* Pretty print the array dimensions. */
gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
tree t = type;
pp_printf (&pretty_name, "'%s ", tname);
asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * flag-types.h (enum sanitize_code): Add SANITIZE_BOUNDS and or it into SANITIZE_UNDEFINED. * doc/invoke.texi: Describe -fsanitize=bounds. * gimplify.c (gimplify_call_expr): Add gimplification of internal functions created in the FEs. * internal-fn.c: Move "internal-fn.h" after "tree.h". (expand_UBSAN_BOUNDS): New function. * internal-fn.def (UBSAN_BOUNDS): New internal function. * internal-fn.h: Don't define internal functions here. * opts.c (common_handle_option): Add -fsanitize=bounds. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS, BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS_ABORT): Add. * tree-core.h: Define internal functions here. (struct tree_base): Add ifn field. * tree-pretty-print.c: Include "internal-fn.h". (dump_generic_node): Handle functions without CALL_EXPR_FN. * tree.c (get_callee_fndecl): Likewise. (build_call_expr_internal_loc): New function. * tree.def (CALL_EXPR): Update description. * tree.h (CALL_EXPR_IFN): Define. (build_call_expr_internal_loc): Declare. * ubsan.c (get_ubsan_type_info_for_type): Return 0 for non-arithmetic types. (ubsan_type_descriptor): Change bool parameter to enum ubsan_print_style. Adjust the code. Add handling of UBSAN_PRINT_ARRAY. (ubsan_expand_bounds_ifn): New function. (ubsan_expand_null_ifn): Adjust ubsan_type_descriptor call. (ubsan_build_overflow_builtin): Likewise. (instrument_bool_enum_load): Likewise. (ubsan_instrument_float_cast): Likewise. * ubsan.h (enum ubsan_print_style): New enum. (ubsan_expand_bounds_ifn): Declare. (ubsan_type_descriptor): Adjust declaration. Use a default parameter. c-family/ * c-gimplify.c: Include "c-ubsan.h" and "pointer-set.h". (ubsan_walk_array_refs_r): New function. (c_genericize): Instrument array bounds. * c-ubsan.c: Include "internal-fn.h". (ubsan_instrument_division): Mark instrumented arrays as having side effects. Adjust ubsan_type_descriptor call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Adjust ubsan_type_descriptor call. (ubsan_instrument_bounds): New function. (ubsan_array_ref_instrumented_p): New function. (ubsan_maybe_instrument_array_ref): New function. * c-ubsan.h (ubsan_instrument_bounds): Declare. (ubsan_array_ref_instrumented_p): Declare. (ubsan_maybe_instrument_array_ref): Declare. testsuite/ * c-c++-common/ubsan/bounds-1.c: New test. * c-c++-common/ubsan/bounds-2.c: New test. * c-c++-common/ubsan/bounds-3.c: New test. * c-c++-common/ubsan/bounds-4.c: New test. * c-c++-common/ubsan/bounds-5.c: New test. * c-c++-common/ubsan/bounds-6.c: New test. From-SVN: r211859
2014-06-20 23:20:51 +02:00
while (deref_depth-- > 0)
pp_star (&pretty_name);
asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * flag-types.h (enum sanitize_code): Add SANITIZE_BOUNDS and or it into SANITIZE_UNDEFINED. * doc/invoke.texi: Describe -fsanitize=bounds. * gimplify.c (gimplify_call_expr): Add gimplification of internal functions created in the FEs. * internal-fn.c: Move "internal-fn.h" after "tree.h". (expand_UBSAN_BOUNDS): New function. * internal-fn.def (UBSAN_BOUNDS): New internal function. * internal-fn.h: Don't define internal functions here. * opts.c (common_handle_option): Add -fsanitize=bounds. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS, BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS_ABORT): Add. * tree-core.h: Define internal functions here. (struct tree_base): Add ifn field. * tree-pretty-print.c: Include "internal-fn.h". (dump_generic_node): Handle functions without CALL_EXPR_FN. * tree.c (get_callee_fndecl): Likewise. (build_call_expr_internal_loc): New function. * tree.def (CALL_EXPR): Update description. * tree.h (CALL_EXPR_IFN): Define. (build_call_expr_internal_loc): Declare. * ubsan.c (get_ubsan_type_info_for_type): Return 0 for non-arithmetic types. (ubsan_type_descriptor): Change bool parameter to enum ubsan_print_style. Adjust the code. Add handling of UBSAN_PRINT_ARRAY. (ubsan_expand_bounds_ifn): New function. (ubsan_expand_null_ifn): Adjust ubsan_type_descriptor call. (ubsan_build_overflow_builtin): Likewise. (instrument_bool_enum_load): Likewise. (ubsan_instrument_float_cast): Likewise. * ubsan.h (enum ubsan_print_style): New enum. (ubsan_expand_bounds_ifn): Declare. (ubsan_type_descriptor): Adjust declaration. Use a default parameter. c-family/ * c-gimplify.c: Include "c-ubsan.h" and "pointer-set.h". (ubsan_walk_array_refs_r): New function. (c_genericize): Instrument array bounds. * c-ubsan.c: Include "internal-fn.h". (ubsan_instrument_division): Mark instrumented arrays as having side effects. Adjust ubsan_type_descriptor call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Adjust ubsan_type_descriptor call. (ubsan_instrument_bounds): New function. (ubsan_array_ref_instrumented_p): New function. (ubsan_maybe_instrument_array_ref): New function. * c-ubsan.h (ubsan_instrument_bounds): Declare. (ubsan_array_ref_instrumented_p): Declare. (ubsan_maybe_instrument_array_ref): Declare. testsuite/ * c-c++-common/ubsan/bounds-1.c: New test. * c-c++-common/ubsan/bounds-2.c: New test. * c-c++-common/ubsan/bounds-3.c: New test. * c-c++-common/ubsan/bounds-4.c: New test. * c-c++-common/ubsan/bounds-5.c: New test. * c-c++-common/ubsan/bounds-6.c: New test. From-SVN: r211859
2014-06-20 23:20:51 +02:00
while (TREE_CODE (t) == ARRAY_TYPE)
{
pp_left_bracket (&pretty_name);
asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * flag-types.h (enum sanitize_code): Add SANITIZE_BOUNDS and or it into SANITIZE_UNDEFINED. * doc/invoke.texi: Describe -fsanitize=bounds. * gimplify.c (gimplify_call_expr): Add gimplification of internal functions created in the FEs. * internal-fn.c: Move "internal-fn.h" after "tree.h". (expand_UBSAN_BOUNDS): New function. * internal-fn.def (UBSAN_BOUNDS): New internal function. * internal-fn.h: Don't define internal functions here. * opts.c (common_handle_option): Add -fsanitize=bounds. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS, BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS_ABORT): Add. * tree-core.h: Define internal functions here. (struct tree_base): Add ifn field. * tree-pretty-print.c: Include "internal-fn.h". (dump_generic_node): Handle functions without CALL_EXPR_FN. * tree.c (get_callee_fndecl): Likewise. (build_call_expr_internal_loc): New function. * tree.def (CALL_EXPR): Update description. * tree.h (CALL_EXPR_IFN): Define. (build_call_expr_internal_loc): Declare. * ubsan.c (get_ubsan_type_info_for_type): Return 0 for non-arithmetic types. (ubsan_type_descriptor): Change bool parameter to enum ubsan_print_style. Adjust the code. Add handling of UBSAN_PRINT_ARRAY. (ubsan_expand_bounds_ifn): New function. (ubsan_expand_null_ifn): Adjust ubsan_type_descriptor call. (ubsan_build_overflow_builtin): Likewise. (instrument_bool_enum_load): Likewise. (ubsan_instrument_float_cast): Likewise. * ubsan.h (enum ubsan_print_style): New enum. (ubsan_expand_bounds_ifn): Declare. (ubsan_type_descriptor): Adjust declaration. Use a default parameter. c-family/ * c-gimplify.c: Include "c-ubsan.h" and "pointer-set.h". (ubsan_walk_array_refs_r): New function. (c_genericize): Instrument array bounds. * c-ubsan.c: Include "internal-fn.h". (ubsan_instrument_division): Mark instrumented arrays as having side effects. Adjust ubsan_type_descriptor call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Adjust ubsan_type_descriptor call. (ubsan_instrument_bounds): New function. (ubsan_array_ref_instrumented_p): New function. (ubsan_maybe_instrument_array_ref): New function. * c-ubsan.h (ubsan_instrument_bounds): Declare. (ubsan_array_ref_instrumented_p): Declare. (ubsan_maybe_instrument_array_ref): Declare. testsuite/ * c-c++-common/ubsan/bounds-1.c: New test. * c-c++-common/ubsan/bounds-2.c: New test. * c-c++-common/ubsan/bounds-3.c: New test. * c-c++-common/ubsan/bounds-4.c: New test. * c-c++-common/ubsan/bounds-5.c: New test. * c-c++-common/ubsan/bounds-6.c: New test. From-SVN: r211859
2014-06-20 23:20:51 +02:00
tree dom = TYPE_DOMAIN (t);
if (dom != NULL_TREE
&& TYPE_MAX_VALUE (dom) != NULL_TREE
&& TREE_CODE (TYPE_MAX_VALUE (dom)) == INTEGER_CST)
{
unsigned HOST_WIDE_INT m;
if (tree_fits_uhwi_p (TYPE_MAX_VALUE (dom))
&& (m = tree_to_uhwi (TYPE_MAX_VALUE (dom))) + 1 != 0)
pp_unsigned_wide_integer (&pretty_name, m + 1);
else
pp_wide_int (&pretty_name,
wi::add (wi::to_widest (TYPE_MAX_VALUE (dom)), 1),
TYPE_SIGN (TREE_TYPE (dom)));
}
asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * flag-types.h (enum sanitize_code): Add SANITIZE_BOUNDS and or it into SANITIZE_UNDEFINED. * doc/invoke.texi: Describe -fsanitize=bounds. * gimplify.c (gimplify_call_expr): Add gimplification of internal functions created in the FEs. * internal-fn.c: Move "internal-fn.h" after "tree.h". (expand_UBSAN_BOUNDS): New function. * internal-fn.def (UBSAN_BOUNDS): New internal function. * internal-fn.h: Don't define internal functions here. * opts.c (common_handle_option): Add -fsanitize=bounds. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS, BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS_ABORT): Add. * tree-core.h: Define internal functions here. (struct tree_base): Add ifn field. * tree-pretty-print.c: Include "internal-fn.h". (dump_generic_node): Handle functions without CALL_EXPR_FN. * tree.c (get_callee_fndecl): Likewise. (build_call_expr_internal_loc): New function. * tree.def (CALL_EXPR): Update description. * tree.h (CALL_EXPR_IFN): Define. (build_call_expr_internal_loc): Declare. * ubsan.c (get_ubsan_type_info_for_type): Return 0 for non-arithmetic types. (ubsan_type_descriptor): Change bool parameter to enum ubsan_print_style. Adjust the code. Add handling of UBSAN_PRINT_ARRAY. (ubsan_expand_bounds_ifn): New function. (ubsan_expand_null_ifn): Adjust ubsan_type_descriptor call. (ubsan_build_overflow_builtin): Likewise. (instrument_bool_enum_load): Likewise. (ubsan_instrument_float_cast): Likewise. * ubsan.h (enum ubsan_print_style): New enum. (ubsan_expand_bounds_ifn): Declare. (ubsan_type_descriptor): Adjust declaration. Use a default parameter. c-family/ * c-gimplify.c: Include "c-ubsan.h" and "pointer-set.h". (ubsan_walk_array_refs_r): New function. (c_genericize): Instrument array bounds. * c-ubsan.c: Include "internal-fn.h". (ubsan_instrument_division): Mark instrumented arrays as having side effects. Adjust ubsan_type_descriptor call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Adjust ubsan_type_descriptor call. (ubsan_instrument_bounds): New function. (ubsan_array_ref_instrumented_p): New function. (ubsan_maybe_instrument_array_ref): New function. * c-ubsan.h (ubsan_instrument_bounds): Declare. (ubsan_array_ref_instrumented_p): Declare. (ubsan_maybe_instrument_array_ref): Declare. testsuite/ * c-c++-common/ubsan/bounds-1.c: New test. * c-c++-common/ubsan/bounds-2.c: New test. * c-c++-common/ubsan/bounds-3.c: New test. * c-c++-common/ubsan/bounds-4.c: New test. * c-c++-common/ubsan/bounds-5.c: New test. * c-c++-common/ubsan/bounds-6.c: New test. From-SVN: r211859
2014-06-20 23:20:51 +02:00
else
/* ??? We can't determine the variable name; print VLA unspec. */
pp_star (&pretty_name);
pp_right_bracket (&pretty_name);
asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * flag-types.h (enum sanitize_code): Add SANITIZE_BOUNDS and or it into SANITIZE_UNDEFINED. * doc/invoke.texi: Describe -fsanitize=bounds. * gimplify.c (gimplify_call_expr): Add gimplification of internal functions created in the FEs. * internal-fn.c: Move "internal-fn.h" after "tree.h". (expand_UBSAN_BOUNDS): New function. * internal-fn.def (UBSAN_BOUNDS): New internal function. * internal-fn.h: Don't define internal functions here. * opts.c (common_handle_option): Add -fsanitize=bounds. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS, BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS_ABORT): Add. * tree-core.h: Define internal functions here. (struct tree_base): Add ifn field. * tree-pretty-print.c: Include "internal-fn.h". (dump_generic_node): Handle functions without CALL_EXPR_FN. * tree.c (get_callee_fndecl): Likewise. (build_call_expr_internal_loc): New function. * tree.def (CALL_EXPR): Update description. * tree.h (CALL_EXPR_IFN): Define. (build_call_expr_internal_loc): Declare. * ubsan.c (get_ubsan_type_info_for_type): Return 0 for non-arithmetic types. (ubsan_type_descriptor): Change bool parameter to enum ubsan_print_style. Adjust the code. Add handling of UBSAN_PRINT_ARRAY. (ubsan_expand_bounds_ifn): New function. (ubsan_expand_null_ifn): Adjust ubsan_type_descriptor call. (ubsan_build_overflow_builtin): Likewise. (instrument_bool_enum_load): Likewise. (ubsan_instrument_float_cast): Likewise. * ubsan.h (enum ubsan_print_style): New enum. (ubsan_expand_bounds_ifn): Declare. (ubsan_type_descriptor): Adjust declaration. Use a default parameter. c-family/ * c-gimplify.c: Include "c-ubsan.h" and "pointer-set.h". (ubsan_walk_array_refs_r): New function. (c_genericize): Instrument array bounds. * c-ubsan.c: Include "internal-fn.h". (ubsan_instrument_division): Mark instrumented arrays as having side effects. Adjust ubsan_type_descriptor call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Adjust ubsan_type_descriptor call. (ubsan_instrument_bounds): New function. (ubsan_array_ref_instrumented_p): New function. (ubsan_maybe_instrument_array_ref): New function. * c-ubsan.h (ubsan_instrument_bounds): Declare. (ubsan_array_ref_instrumented_p): Declare. (ubsan_maybe_instrument_array_ref): Declare. testsuite/ * c-c++-common/ubsan/bounds-1.c: New test. * c-c++-common/ubsan/bounds-2.c: New test. * c-c++-common/ubsan/bounds-3.c: New test. * c-c++-common/ubsan/bounds-4.c: New test. * c-c++-common/ubsan/bounds-5.c: New test. * c-c++-common/ubsan/bounds-6.c: New test. From-SVN: r211859
2014-06-20 23:20:51 +02:00
t = TREE_TYPE (t);
}
pp_quote (&pretty_name);
asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * flag-types.h (enum sanitize_code): Add SANITIZE_BOUNDS and or it into SANITIZE_UNDEFINED. * doc/invoke.texi: Describe -fsanitize=bounds. * gimplify.c (gimplify_call_expr): Add gimplification of internal functions created in the FEs. * internal-fn.c: Move "internal-fn.h" after "tree.h". (expand_UBSAN_BOUNDS): New function. * internal-fn.def (UBSAN_BOUNDS): New internal function. * internal-fn.h: Don't define internal functions here. * opts.c (common_handle_option): Add -fsanitize=bounds. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS, BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS_ABORT): Add. * tree-core.h: Define internal functions here. (struct tree_base): Add ifn field. * tree-pretty-print.c: Include "internal-fn.h". (dump_generic_node): Handle functions without CALL_EXPR_FN. * tree.c (get_callee_fndecl): Likewise. (build_call_expr_internal_loc): New function. * tree.def (CALL_EXPR): Update description. * tree.h (CALL_EXPR_IFN): Define. (build_call_expr_internal_loc): Declare. * ubsan.c (get_ubsan_type_info_for_type): Return 0 for non-arithmetic types. (ubsan_type_descriptor): Change bool parameter to enum ubsan_print_style. Adjust the code. Add handling of UBSAN_PRINT_ARRAY. (ubsan_expand_bounds_ifn): New function. (ubsan_expand_null_ifn): Adjust ubsan_type_descriptor call. (ubsan_build_overflow_builtin): Likewise. (instrument_bool_enum_load): Likewise. (ubsan_instrument_float_cast): Likewise. * ubsan.h (enum ubsan_print_style): New enum. (ubsan_expand_bounds_ifn): Declare. (ubsan_type_descriptor): Adjust declaration. Use a default parameter. c-family/ * c-gimplify.c: Include "c-ubsan.h" and "pointer-set.h". (ubsan_walk_array_refs_r): New function. (c_genericize): Instrument array bounds. * c-ubsan.c: Include "internal-fn.h". (ubsan_instrument_division): Mark instrumented arrays as having side effects. Adjust ubsan_type_descriptor call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Adjust ubsan_type_descriptor call. (ubsan_instrument_bounds): New function. (ubsan_array_ref_instrumented_p): New function. (ubsan_maybe_instrument_array_ref): New function. * c-ubsan.h (ubsan_instrument_bounds): Declare. (ubsan_array_ref_instrumented_p): Declare. (ubsan_maybe_instrument_array_ref): Declare. testsuite/ * c-c++-common/ubsan/bounds-1.c: New test. * c-c++-common/ubsan/bounds-2.c: New test. * c-c++-common/ubsan/bounds-3.c: New test. * c-c++-common/ubsan/bounds-4.c: New test. * c-c++-common/ubsan/bounds-5.c: New test. * c-c++-common/ubsan/bounds-6.c: New test. From-SVN: r211859
2014-06-20 23:20:51 +02:00
/* Save the tree with stripped types. */
eltype = t;
asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * flag-types.h (enum sanitize_code): Add SANITIZE_BOUNDS and or it into SANITIZE_UNDEFINED. * doc/invoke.texi: Describe -fsanitize=bounds. * gimplify.c (gimplify_call_expr): Add gimplification of internal functions created in the FEs. * internal-fn.c: Move "internal-fn.h" after "tree.h". (expand_UBSAN_BOUNDS): New function. * internal-fn.def (UBSAN_BOUNDS): New internal function. * internal-fn.h: Don't define internal functions here. * opts.c (common_handle_option): Add -fsanitize=bounds. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS, BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS_ABORT): Add. * tree-core.h: Define internal functions here. (struct tree_base): Add ifn field. * tree-pretty-print.c: Include "internal-fn.h". (dump_generic_node): Handle functions without CALL_EXPR_FN. * tree.c (get_callee_fndecl): Likewise. (build_call_expr_internal_loc): New function. * tree.def (CALL_EXPR): Update description. * tree.h (CALL_EXPR_IFN): Define. (build_call_expr_internal_loc): Declare. * ubsan.c (get_ubsan_type_info_for_type): Return 0 for non-arithmetic types. (ubsan_type_descriptor): Change bool parameter to enum ubsan_print_style. Adjust the code. Add handling of UBSAN_PRINT_ARRAY. (ubsan_expand_bounds_ifn): New function. (ubsan_expand_null_ifn): Adjust ubsan_type_descriptor call. (ubsan_build_overflow_builtin): Likewise. (instrument_bool_enum_load): Likewise. (ubsan_instrument_float_cast): Likewise. * ubsan.h (enum ubsan_print_style): New enum. (ubsan_expand_bounds_ifn): Declare. (ubsan_type_descriptor): Adjust declaration. Use a default parameter. c-family/ * c-gimplify.c: Include "c-ubsan.h" and "pointer-set.h". (ubsan_walk_array_refs_r): New function. (c_genericize): Instrument array bounds. * c-ubsan.c: Include "internal-fn.h". (ubsan_instrument_division): Mark instrumented arrays as having side effects. Adjust ubsan_type_descriptor call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Adjust ubsan_type_descriptor call. (ubsan_instrument_bounds): New function. (ubsan_array_ref_instrumented_p): New function. (ubsan_maybe_instrument_array_ref): New function. * c-ubsan.h (ubsan_instrument_bounds): Declare. (ubsan_array_ref_instrumented_p): Declare. (ubsan_maybe_instrument_array_ref): Declare. testsuite/ * c-c++-common/ubsan/bounds-1.c: New test. * c-c++-common/ubsan/bounds-2.c: New test. * c-c++-common/ubsan/bounds-3.c: New test. * c-c++-common/ubsan/bounds-4.c: New test. * c-c++-common/ubsan/bounds-5.c: New test. * c-c++-common/ubsan/bounds-6.c: New test. From-SVN: r211859
2014-06-20 23:20:51 +02:00
}
else
pp_printf (&pretty_name, "'%s'", tname);
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
switch (TREE_CODE (eltype))
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
{
case BOOLEAN_TYPE:
case ENUMERAL_TYPE:
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
case INTEGER_TYPE:
tkind = 0x0000;
break;
case REAL_TYPE:
builtins.def: Change SANITIZE_FLOAT_DIVIDE to SANITIZE_NONDEFAULT. * builtins.def: Change SANITIZE_FLOAT_DIVIDE to SANITIZE_NONDEFAULT. * gcc.c (sanitize_spec_function): Likewise. * convert.c (convert_to_integer): Include "ubsan.h". Add floating-point to integer instrumentation. * doc/invoke.texi: Document -fsanitize=float-cast-overflow. * flag-types.h (enum sanitize_code): Add SANITIZE_FLOAT_CAST and SANITIZE_NONDEFAULT. * opts.c (common_handle_option): Handle -fsanitize=float-cast-overflow. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_FLOAT_CAST_OVERFLOW, BUILT_IN_UBSAN_HANDLE_FLOAT_CAST_OVERFLOW_ABORT): Add. * ubsan.c: Include "realmpfr.h" and "dfp.h". (get_ubsan_type_info_for_type): Handle REAL_TYPEs. (ubsan_type_descriptor): Set tkind to 0xffff for types other than float/double/long double. (ubsan_instrument_float_cast): New function. * ubsan.h (ubsan_instrument_float_cast): Declare. testsuite/ * c-c++-common/ubsan/float-cast-overflow-1.c: New test. * c-c++-common/ubsan/float-cast-overflow-10.c: New test. * c-c++-common/ubsan/float-cast-overflow-2.c: New test. * c-c++-common/ubsan/float-cast-overflow-3.c: New test. * c-c++-common/ubsan/float-cast-overflow-4.c: New test. * c-c++-common/ubsan/float-cast-overflow-5.c: New test. * c-c++-common/ubsan/float-cast-overflow-6.c: New test. * c-c++-common/ubsan/float-cast-overflow-7.c: New test. * c-c++-common/ubsan/float-cast-overflow-7.h: New file. * c-c++-common/ubsan/float-cast-overflow-8.c: New test. * c-c++-common/ubsan/float-cast-overflow-9.c: New test. * c-c++-common/ubsan/float-cast.h: New file. * g++.dg/ubsan/float-cast-overflow-bf.C: New test. * gcc.dg/ubsan/float-cast-overflow-bf.c: New test. libsanitizer/ * ubsan/ubsan_value.cc (getFloatValue): Handle 96-bit floating-point types. Co-Authored-By: Jakub Jelinek <jakub@redhat.com> From-SVN: r210862
2014-05-23 16:44:42 +02:00
/* FIXME: libubsan right now only supports float, double and
long double type formats. */
if (TYPE_MODE (eltype) == TYPE_MODE (float_type_node)
|| TYPE_MODE (eltype) == TYPE_MODE (double_type_node)
|| TYPE_MODE (eltype) == TYPE_MODE (long_double_type_node))
builtins.def: Change SANITIZE_FLOAT_DIVIDE to SANITIZE_NONDEFAULT. * builtins.def: Change SANITIZE_FLOAT_DIVIDE to SANITIZE_NONDEFAULT. * gcc.c (sanitize_spec_function): Likewise. * convert.c (convert_to_integer): Include "ubsan.h". Add floating-point to integer instrumentation. * doc/invoke.texi: Document -fsanitize=float-cast-overflow. * flag-types.h (enum sanitize_code): Add SANITIZE_FLOAT_CAST and SANITIZE_NONDEFAULT. * opts.c (common_handle_option): Handle -fsanitize=float-cast-overflow. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_FLOAT_CAST_OVERFLOW, BUILT_IN_UBSAN_HANDLE_FLOAT_CAST_OVERFLOW_ABORT): Add. * ubsan.c: Include "realmpfr.h" and "dfp.h". (get_ubsan_type_info_for_type): Handle REAL_TYPEs. (ubsan_type_descriptor): Set tkind to 0xffff for types other than float/double/long double. (ubsan_instrument_float_cast): New function. * ubsan.h (ubsan_instrument_float_cast): Declare. testsuite/ * c-c++-common/ubsan/float-cast-overflow-1.c: New test. * c-c++-common/ubsan/float-cast-overflow-10.c: New test. * c-c++-common/ubsan/float-cast-overflow-2.c: New test. * c-c++-common/ubsan/float-cast-overflow-3.c: New test. * c-c++-common/ubsan/float-cast-overflow-4.c: New test. * c-c++-common/ubsan/float-cast-overflow-5.c: New test. * c-c++-common/ubsan/float-cast-overflow-6.c: New test. * c-c++-common/ubsan/float-cast-overflow-7.c: New test. * c-c++-common/ubsan/float-cast-overflow-7.h: New file. * c-c++-common/ubsan/float-cast-overflow-8.c: New test. * c-c++-common/ubsan/float-cast-overflow-9.c: New test. * c-c++-common/ubsan/float-cast.h: New file. * g++.dg/ubsan/float-cast-overflow-bf.C: New test. * gcc.dg/ubsan/float-cast-overflow-bf.c: New test. libsanitizer/ * ubsan/ubsan_value.cc (getFloatValue): Handle 96-bit floating-point types. Co-Authored-By: Jakub Jelinek <jakub@redhat.com> From-SVN: r210862
2014-05-23 16:44:42 +02:00
tkind = 0x0001;
else
tkind = 0xffff;
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
break;
default:
tkind = 0xffff;
break;
}
tinfo = get_ubsan_type_info_for_type (eltype);
/* Create a new VAR_DECL of type descriptor. */
const char *tmp = pp_formatted_text (&pretty_name);
size_t len = strlen (tmp) + 1;
tree str = build_string (len, tmp);
TREE_TYPE (str) = build_array_type_nelts (char_type_node, len);
TREE_READONLY (str) = 1;
TREE_STATIC (str) = 1;
char tmp_name[32];
ASM_GENERATE_INTERNAL_LABEL (tmp_name, "Lubsan_type", ubsan_ids[0]++);
decl = build_decl (UNKNOWN_LOCATION, VAR_DECL, get_identifier (tmp_name),
dtype);
TREE_STATIC (decl) = 1;
TREE_PUBLIC (decl) = 0;
DECL_ARTIFICIAL (decl) = 1;
DECL_IGNORED_P (decl) = 1;
DECL_EXTERNAL (decl) = 0;
DECL_SIZE (decl)
= size_binop (PLUS_EXPR, DECL_SIZE (decl), TYPE_SIZE (TREE_TYPE (str)));
DECL_SIZE_UNIT (decl)
= size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl),
TYPE_SIZE_UNIT (TREE_TYPE (str)));
tree ctor = build_constructor_va (dtype, 3, NULL_TREE,
build_int_cst (short_unsigned_type_node,
tkind), NULL_TREE,
build_int_cst (short_unsigned_type_node,
tinfo), NULL_TREE, str);
TREE_CONSTANT (ctor) = 1;
TREE_STATIC (ctor) = 1;
DECL_INITIAL (decl) = ctor;
IPA C++ refactoring 2/N * cgraph.h (varpool_node): (availability get_availability (void)): created from cgraph_variable_initializer_availability (inline varpool_node *ultimate_alias_target (availability *availability = NULL) creted from: cgraph_variable_initializer_availability (inline varpool_node *get_alias_target (void)): created from varpool_alias_target (void finalize_named_section_flags (void)): created from varpool_finalize_named_section_flags (bool assemble_decl (void)): created from varpool_assemble_decl (void analyze (void)): created from varpool_analyze_node (bool call_for_node_and_aliases (bool (*callback) (varpool_node *, void *), void *data, bool include_overwritable)): created fromvarpool_for_node_and_aliases (void remove_initializer (void)): created from varpool_remove_initializer (tree get_constructor (void)): created from varpool_get_constructor (bool externally_visible_p (void)): created from varpool_externally_visible_p (bool ctor_useable_for_folding_p (void)): created from varpool_ctor_useable_for_folding_p (inline bool all_refs_explicit_p ()): created from varpool_all_refs_explicit_p (inline bool can_remove_if_no_refs_p (void)): created from varpool_can_remove_if_no_refs (static inline varpool_node *get (const_tree decl)): created from varpool_get_node (static void finalize_decl (tree decl)): created from varpool_finalize_decl (static bool output_variables (void)): created from varpool_output_variables (static varpool_node * create_extra_name_alias (tree alias, tree decl)): created from varpool_extra_name_alias (static varpool_node * create_alias (tree, tree)): created from varpool_create_variable_alias (static void dump_varpool (FILE *f)): created from dump_varpool (static void DEBUG_FUNCTION debug_varpool (void)): created from debug_varpool (static varpool_node *create_empty (void)): created from varpool_create_empty_node (static varpool_node *get_create (tree decl)): created from varpool_node_for_decl (static varpool_node *get_for_asmname (tree asmname)): created from varpool_node_for_asm (void assemble_aliases (void)): created from assemble_aliases From-SVN: r212984
2014-07-24 14:25:27 +02:00
varpool_node::finalize_decl (decl);
/* Save the VAR_DECL into the hash table. */
decl_for_type_insert (type, decl);
return build_fold_addr_expr (decl);
}
/* Create a structure for the ubsan library. NAME is a name of the new
structure. LOCCNT is number of locations, PLOC points to array of
locations. The arguments in ... are of __ubsan_type_descriptor type
and there are at most two of them, followed by NULL_TREE, followed
by optional extra arguments and another NULL_TREE. */
tree
ubsan_create_data (const char *name, int loccnt, const location_t *ploc, ...)
{
va_list args;
tree ret, t;
tree fields[6];
vec<tree, va_gc> *saved_args = NULL;
size_t i = 0;
int j;
/* It is possible that PCH zapped table with definitions of sanitizer
builtins. Reinitialize them if needed. */
initialize_sanitizer_builtins ();
/* Firstly, create a pointer to type descriptor type. */
tree td_type = ubsan_get_type_descriptor_type ();
td_type = build_pointer_type (td_type);
/* Create the structure type. */
ret = make_node (RECORD_TYPE);
for (j = 0; j < loccnt; j++)
{
gcc_checking_assert (i < 2);
fields[i] = build_decl (UNKNOWN_LOCATION, FIELD_DECL, NULL_TREE,
ubsan_get_source_location_type ());
DECL_CONTEXT (fields[i]) = ret;
if (i)
DECL_CHAIN (fields[i - 1]) = fields[i];
i++;
}
va_start (args, ploc);
for (t = va_arg (args, tree); t != NULL_TREE;
i++, t = va_arg (args, tree))
{
gcc_checking_assert (i < 4);
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
/* Save the tree arguments for later use. */
vec_safe_push (saved_args, t);
fields[i] = build_decl (UNKNOWN_LOCATION, FIELD_DECL, NULL_TREE,
td_type);
DECL_CONTEXT (fields[i]) = ret;
if (i)
DECL_CHAIN (fields[i - 1]) = fields[i];
}
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
for (t = va_arg (args, tree); t != NULL_TREE;
i++, t = va_arg (args, tree))
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
{
gcc_checking_assert (i < 6);
/* Save the tree arguments for later use. */
vec_safe_push (saved_args, t);
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
fields[i] = build_decl (UNKNOWN_LOCATION, FIELD_DECL, NULL_TREE,
TREE_TYPE (t));
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
DECL_CONTEXT (fields[i]) = ret;
if (i)
DECL_CHAIN (fields[i - 1]) = fields[i];
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
}
va_end (args);
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
tree type_decl = build_decl (input_location, TYPE_DECL,
get_identifier (name), ret);
DECL_IGNORED_P (type_decl) = 1;
DECL_ARTIFICIAL (type_decl) = 1;
TYPE_FIELDS (ret) = fields[0];
TYPE_NAME (ret) = type_decl;
TYPE_STUB_DECL (ret) = type_decl;
layout_type (ret);
/* Now, fill in the type. */
char tmp_name[32];
ASM_GENERATE_INTERNAL_LABEL (tmp_name, "Lubsan_data", ubsan_ids[1]++);
tree var = build_decl (UNKNOWN_LOCATION, VAR_DECL, get_identifier (tmp_name),
ret);
TREE_STATIC (var) = 1;
TREE_PUBLIC (var) = 0;
DECL_ARTIFICIAL (var) = 1;
DECL_IGNORED_P (var) = 1;
DECL_EXTERNAL (var) = 0;
vec<constructor_elt, va_gc> *v;
vec_alloc (v, i);
tree ctor = build_constructor (ret, v);
/* If desirable, set the __ubsan_source_location element. */
for (j = 0; j < loccnt; j++)
{
location_t loc = LOCATION_LOCUS (ploc[j]);
CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, ubsan_source_location (loc));
}
size_t nelts = vec_safe_length (saved_args);
for (i = 0; i < nelts; i++)
{
t = (*saved_args)[i];
CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, t);
}
TREE_CONSTANT (ctor) = 1;
TREE_STATIC (ctor) = 1;
DECL_INITIAL (var) = ctor;
IPA C++ refactoring 2/N * cgraph.h (varpool_node): (availability get_availability (void)): created from cgraph_variable_initializer_availability (inline varpool_node *ultimate_alias_target (availability *availability = NULL) creted from: cgraph_variable_initializer_availability (inline varpool_node *get_alias_target (void)): created from varpool_alias_target (void finalize_named_section_flags (void)): created from varpool_finalize_named_section_flags (bool assemble_decl (void)): created from varpool_assemble_decl (void analyze (void)): created from varpool_analyze_node (bool call_for_node_and_aliases (bool (*callback) (varpool_node *, void *), void *data, bool include_overwritable)): created fromvarpool_for_node_and_aliases (void remove_initializer (void)): created from varpool_remove_initializer (tree get_constructor (void)): created from varpool_get_constructor (bool externally_visible_p (void)): created from varpool_externally_visible_p (bool ctor_useable_for_folding_p (void)): created from varpool_ctor_useable_for_folding_p (inline bool all_refs_explicit_p ()): created from varpool_all_refs_explicit_p (inline bool can_remove_if_no_refs_p (void)): created from varpool_can_remove_if_no_refs (static inline varpool_node *get (const_tree decl)): created from varpool_get_node (static void finalize_decl (tree decl)): created from varpool_finalize_decl (static bool output_variables (void)): created from varpool_output_variables (static varpool_node * create_extra_name_alias (tree alias, tree decl)): created from varpool_extra_name_alias (static varpool_node * create_alias (tree, tree)): created from varpool_create_variable_alias (static void dump_varpool (FILE *f)): created from dump_varpool (static void DEBUG_FUNCTION debug_varpool (void)): created from debug_varpool (static varpool_node *create_empty (void)): created from varpool_create_empty_node (static varpool_node *get_create (tree decl)): created from varpool_node_for_decl (static varpool_node *get_for_asmname (tree asmname)): created from varpool_node_for_asm (void assemble_aliases (void)): created from assemble_aliases From-SVN: r212984
2014-07-24 14:25:27 +02:00
varpool_node::finalize_decl (var);
return var;
}
/* Instrument the __builtin_unreachable call. We just call the libubsan
routine instead. */
bool
ubsan_instrument_unreachable (gimple_stmt_iterator *gsi)
{
gimple *g;
location_t loc = gimple_location (gsi_stmt (*gsi));
re PR sanitizer/60275 ([UBSAN] Add -f[no-]sanitize-recover/-fsanitize-undefined-trap-on-error to make UBSAN's runtime errors fatal) PR sanitizer/60275 * common.opt (fsanitize-recover, fsanitize-undefined-trap-on-error): New options. * gcc.c (sanitize_spec_function): Don't return "" for "undefined" if flag_sanitize_undefined_trap_on_error. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_DIVREM_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_SHIFT_OUT_OF_BOUNDS_ABORT, BUILT_IN_UBSAN_HANDLE_VLA_BOUND_NOT_POSITIVE_ABORT, BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT, BUILT_IN_UBSAN_HANDLE_ADD_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_SUB_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_MUL_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_NEGATE_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_LOAD_INVALID_VALUE_ABORT): New builtins. * ubsan.c (ubsan_instrument_unreachable): Return __builtin_trap () if flag_sanitize_undefined_trap_on_error. (ubsan_expand_null_ifn): Emit __builtin_trap () if flag_sanitize_undefined_trap_on_error and __ubsan_handle_type_mismatch_abort if !flag_sanitize_recover. (ubsan_expand_null_ifn, ubsan_build_overflow_builtin, instrument_bool_enum_load): Emit __builtin_trap () if flag_sanitize_undefined_trap_on_error and __builtin_handle_*_abort () if !flag_sanitize_recover. * doc/invoke.texi (-fsanitize-recover, -fsanitize-undefined-trap-on-error): Document. c-family/ * c-ubsan.c (ubsan_instrument_return): Return __builtin_trap () if flag_sanitize_undefined_trap_on_error. (ubsan_instrument_division, ubsan_instrument_shift, ubsan_instrument_vla): Likewise. Use __ubsan_handle_*_abort () if !flag_sanitize_recover. testsuite/ * g++.dg/ubsan/return-2.C: Revert 2014-03-24 changes, add -fno-sanitize-recover to dg-options. * g++.dg/ubsan/cxx11-shift-1.C: Remove c++11 target restriction, add -std=c++11 to dg-options. * g++.dg/ubsan/cxx11-shift-2.C: Likewise. * g++.dg/ubsan/cxx1y-vla.C: Remove c++1y target restriction, add -std=c++1y to dg-options. * c-c++-common/ubsan/undefined-1.c: Revert 2014-03-24 changes, add -fno-sanitize-recover to dg-options. * c-c++-common/ubsan/overflow-sub-1.c: Likewise. * c-c++-common/ubsan/vla-4.c: Likewise. * c-c++-common/ubsan/pr59503.c: Likewise. * c-c++-common/ubsan/vla-3.c: Likewise. * c-c++-common/ubsan/save-expr-1.c: Likewise. * c-c++-common/ubsan/overflow-add-1.c: Likewise. * c-c++-common/ubsan/shift-3.c: Likewise. * c-c++-common/ubsan/overflow-1.c: Likewise. * c-c++-common/ubsan/overflow-negate-2.c: Likewise. * c-c++-common/ubsan/vla-2.c: Likewise. * c-c++-common/ubsan/overflow-mul-1.c: Likewise. * c-c++-common/ubsan/pr60613-1.c: Likewise. * c-c++-common/ubsan/shift-6.c: Likewise. * c-c++-common/ubsan/overflow-mul-3.c: Likewise. * c-c++-common/ubsan/overflow-add-3.c: New test. * c-c++-common/ubsan/overflow-add-4.c: New test. * c-c++-common/ubsan/div-by-zero-6.c: New test. * c-c++-common/ubsan/div-by-zero-7.c: New test. From-SVN: r209672
2014-04-23 10:20:12 +02:00
if (flag_sanitize_undefined_trap_on_error)
g = gimple_build_call (builtin_decl_explicit (BUILT_IN_TRAP), 0);
else
{
tree data = ubsan_create_data ("__ubsan_unreachable_data", 1, &loc,
NULL_TREE, NULL_TREE);
data = build_fold_addr_expr_loc (loc, data);
tree fn
= builtin_decl_explicit (BUILT_IN_UBSAN_HANDLE_BUILTIN_UNREACHABLE);
g = gimple_build_call (fn, 1, data);
}
gimple_set_location (g, loc);
gsi_replace (gsi, g, false);
return false;
}
/* Return true if T is a call to a libubsan routine. */
bool
is_ubsan_builtin_p (tree t)
{
return TREE_CODE (t) == FUNCTION_DECL
&& DECL_BUILT_IN_CLASS (t) == BUILT_IN_NORMAL
&& strncmp (IDENTIFIER_POINTER (DECL_NAME (t)),
"__builtin___ubsan_", 18) == 0;
}
/* Create a callgraph edge for statement STMT. */
static void
ubsan_create_edge (gimple *stmt)
{
gcall *call_stmt = dyn_cast <gcall *> (stmt);
basic_block bb = gimple_bb (stmt);
int freq = compute_call_stmt_bb_frequency (current_function_decl, bb);
cgraph_node *node = cgraph_node::get (current_function_decl);
tree decl = gimple_call_fndecl (call_stmt);
if (decl)
node->create_edge (cgraph_node::get_create (decl), call_stmt, bb->count,
freq);
}
asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * flag-types.h (enum sanitize_code): Add SANITIZE_BOUNDS and or it into SANITIZE_UNDEFINED. * doc/invoke.texi: Describe -fsanitize=bounds. * gimplify.c (gimplify_call_expr): Add gimplification of internal functions created in the FEs. * internal-fn.c: Move "internal-fn.h" after "tree.h". (expand_UBSAN_BOUNDS): New function. * internal-fn.def (UBSAN_BOUNDS): New internal function. * internal-fn.h: Don't define internal functions here. * opts.c (common_handle_option): Add -fsanitize=bounds. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS, BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS_ABORT): Add. * tree-core.h: Define internal functions here. (struct tree_base): Add ifn field. * tree-pretty-print.c: Include "internal-fn.h". (dump_generic_node): Handle functions without CALL_EXPR_FN. * tree.c (get_callee_fndecl): Likewise. (build_call_expr_internal_loc): New function. * tree.def (CALL_EXPR): Update description. * tree.h (CALL_EXPR_IFN): Define. (build_call_expr_internal_loc): Declare. * ubsan.c (get_ubsan_type_info_for_type): Return 0 for non-arithmetic types. (ubsan_type_descriptor): Change bool parameter to enum ubsan_print_style. Adjust the code. Add handling of UBSAN_PRINT_ARRAY. (ubsan_expand_bounds_ifn): New function. (ubsan_expand_null_ifn): Adjust ubsan_type_descriptor call. (ubsan_build_overflow_builtin): Likewise. (instrument_bool_enum_load): Likewise. (ubsan_instrument_float_cast): Likewise. * ubsan.h (enum ubsan_print_style): New enum. (ubsan_expand_bounds_ifn): Declare. (ubsan_type_descriptor): Adjust declaration. Use a default parameter. c-family/ * c-gimplify.c: Include "c-ubsan.h" and "pointer-set.h". (ubsan_walk_array_refs_r): New function. (c_genericize): Instrument array bounds. * c-ubsan.c: Include "internal-fn.h". (ubsan_instrument_division): Mark instrumented arrays as having side effects. Adjust ubsan_type_descriptor call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Adjust ubsan_type_descriptor call. (ubsan_instrument_bounds): New function. (ubsan_array_ref_instrumented_p): New function. (ubsan_maybe_instrument_array_ref): New function. * c-ubsan.h (ubsan_instrument_bounds): Declare. (ubsan_array_ref_instrumented_p): Declare. (ubsan_maybe_instrument_array_ref): Declare. testsuite/ * c-c++-common/ubsan/bounds-1.c: New test. * c-c++-common/ubsan/bounds-2.c: New test. * c-c++-common/ubsan/bounds-3.c: New test. * c-c++-common/ubsan/bounds-4.c: New test. * c-c++-common/ubsan/bounds-5.c: New test. * c-c++-common/ubsan/bounds-6.c: New test. From-SVN: r211859
2014-06-20 23:20:51 +02:00
/* Expand the UBSAN_BOUNDS special builtin function. */
opts.c (common_handle_option): Handle -fsanitize=alignment. * opts.c (common_handle_option): Handle -fsanitize=alignment. * ubsan.h (enum ubsan_null_ckind): Add UBSAN_CTOR_CALL. (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn): Change return type to bool. * stor-layout.h (min_align_of_type): New prototype. * asan.c (pass_sanopt::execute): Don't perform gsi_next if ubsan_expand* told us not to do it. Remove the extra gsi_end_p check. * ubsan.c: Include builtins.h. (ubsan_expand_bounds_ifn): Change return type to bool, always return true. (ubsan_expand_null_ifn): Change return type to bool, change argument to gimple_stmt_iterator *. Handle both null and alignment sanitization, take type from ckind argument's type rather than first argument. (instrument_member_call): Removed. (instrument_mem_ref): Remove t argument, add mem and base arguments. Handle both null and alignment sanitization, don't say whole struct access is member access. Build 3 argument IFN_UBSAN_NULL call instead of 2 argument. (instrument_null): Adjust instrument_mem_ref caller. Don't instrument calls here. (pass_ubsan::gate, pass_ubsan::execute): Handle SANITIZE_ALIGNMENT like SANITIZE_NULL. * stor-layout.c (min_align_of_type): New function. * flag-types.h (enum sanitize_code): Add SANITIZE_ALIGNMENT. Or it into SANITIZE_UNDEFINED. * doc/invoke.texi (-fsanitize=alignment): Document. cp/ * cp-gimplify.c (cp_genericize_r): For -fsanitize=null and/or -fsanitize=alignment call ubsan_maybe_instrument_reference for casts to REFERENCE_TYPE and ubsan_maybe_instrument_member_call for calls to member functions. c-family/ * c-common.h (min_align_of_type): Removed prototype. * c-common.c (min_align_of_type): Removed. * c-ubsan.h (ubsan_maybe_instrument_reference, ubsan_maybe_instrument_member_call): New prototypes. * c-ubsan.c: Include stor-layout.h and builtins.h. (ubsan_maybe_instrument_reference_or_call, ubsan_maybe_instrument_reference, ubsan_maybe_instrument_call): New functions. testsuite/ * c-c++-common/ubsan/align-1.c: New test. * c-c++-common/ubsan/align-2.c: New test. * c-c++-common/ubsan/align-3.c: New test. * c-c++-common/ubsan/align-4.c: New test. * c-c++-common/ubsan/align-5.c: New test. * c-c++-common/ubsan/attrib-4.c: New test. * g++.dg/ubsan/align-1.C: New test. * g++.dg/ubsan/align-2.C: New test. * g++.dg/ubsan/align-3.C: New test. * g++.dg/ubsan/attrib-1.C: New test. * g++.dg/ubsan/null-1.C: New test. * g++.dg/ubsan/null-2.C: New test. From-SVN: r213406
2014-08-01 09:52:43 +02:00
bool
asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * flag-types.h (enum sanitize_code): Add SANITIZE_BOUNDS and or it into SANITIZE_UNDEFINED. * doc/invoke.texi: Describe -fsanitize=bounds. * gimplify.c (gimplify_call_expr): Add gimplification of internal functions created in the FEs. * internal-fn.c: Move "internal-fn.h" after "tree.h". (expand_UBSAN_BOUNDS): New function. * internal-fn.def (UBSAN_BOUNDS): New internal function. * internal-fn.h: Don't define internal functions here. * opts.c (common_handle_option): Add -fsanitize=bounds. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS, BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS_ABORT): Add. * tree-core.h: Define internal functions here. (struct tree_base): Add ifn field. * tree-pretty-print.c: Include "internal-fn.h". (dump_generic_node): Handle functions without CALL_EXPR_FN. * tree.c (get_callee_fndecl): Likewise. (build_call_expr_internal_loc): New function. * tree.def (CALL_EXPR): Update description. * tree.h (CALL_EXPR_IFN): Define. (build_call_expr_internal_loc): Declare. * ubsan.c (get_ubsan_type_info_for_type): Return 0 for non-arithmetic types. (ubsan_type_descriptor): Change bool parameter to enum ubsan_print_style. Adjust the code. Add handling of UBSAN_PRINT_ARRAY. (ubsan_expand_bounds_ifn): New function. (ubsan_expand_null_ifn): Adjust ubsan_type_descriptor call. (ubsan_build_overflow_builtin): Likewise. (instrument_bool_enum_load): Likewise. (ubsan_instrument_float_cast): Likewise. * ubsan.h (enum ubsan_print_style): New enum. (ubsan_expand_bounds_ifn): Declare. (ubsan_type_descriptor): Adjust declaration. Use a default parameter. c-family/ * c-gimplify.c: Include "c-ubsan.h" and "pointer-set.h". (ubsan_walk_array_refs_r): New function. (c_genericize): Instrument array bounds. * c-ubsan.c: Include "internal-fn.h". (ubsan_instrument_division): Mark instrumented arrays as having side effects. Adjust ubsan_type_descriptor call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Adjust ubsan_type_descriptor call. (ubsan_instrument_bounds): New function. (ubsan_array_ref_instrumented_p): New function. (ubsan_maybe_instrument_array_ref): New function. * c-ubsan.h (ubsan_instrument_bounds): Declare. (ubsan_array_ref_instrumented_p): Declare. (ubsan_maybe_instrument_array_ref): Declare. testsuite/ * c-c++-common/ubsan/bounds-1.c: New test. * c-c++-common/ubsan/bounds-2.c: New test. * c-c++-common/ubsan/bounds-3.c: New test. * c-c++-common/ubsan/bounds-4.c: New test. * c-c++-common/ubsan/bounds-5.c: New test. * c-c++-common/ubsan/bounds-6.c: New test. From-SVN: r211859
2014-06-20 23:20:51 +02:00
ubsan_expand_bounds_ifn (gimple_stmt_iterator *gsi)
{
gimple *stmt = gsi_stmt (*gsi);
asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * flag-types.h (enum sanitize_code): Add SANITIZE_BOUNDS and or it into SANITIZE_UNDEFINED. * doc/invoke.texi: Describe -fsanitize=bounds. * gimplify.c (gimplify_call_expr): Add gimplification of internal functions created in the FEs. * internal-fn.c: Move "internal-fn.h" after "tree.h". (expand_UBSAN_BOUNDS): New function. * internal-fn.def (UBSAN_BOUNDS): New internal function. * internal-fn.h: Don't define internal functions here. * opts.c (common_handle_option): Add -fsanitize=bounds. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS, BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS_ABORT): Add. * tree-core.h: Define internal functions here. (struct tree_base): Add ifn field. * tree-pretty-print.c: Include "internal-fn.h". (dump_generic_node): Handle functions without CALL_EXPR_FN. * tree.c (get_callee_fndecl): Likewise. (build_call_expr_internal_loc): New function. * tree.def (CALL_EXPR): Update description. * tree.h (CALL_EXPR_IFN): Define. (build_call_expr_internal_loc): Declare. * ubsan.c (get_ubsan_type_info_for_type): Return 0 for non-arithmetic types. (ubsan_type_descriptor): Change bool parameter to enum ubsan_print_style. Adjust the code. Add handling of UBSAN_PRINT_ARRAY. (ubsan_expand_bounds_ifn): New function. (ubsan_expand_null_ifn): Adjust ubsan_type_descriptor call. (ubsan_build_overflow_builtin): Likewise. (instrument_bool_enum_load): Likewise. (ubsan_instrument_float_cast): Likewise. * ubsan.h (enum ubsan_print_style): New enum. (ubsan_expand_bounds_ifn): Declare. (ubsan_type_descriptor): Adjust declaration. Use a default parameter. c-family/ * c-gimplify.c: Include "c-ubsan.h" and "pointer-set.h". (ubsan_walk_array_refs_r): New function. (c_genericize): Instrument array bounds. * c-ubsan.c: Include "internal-fn.h". (ubsan_instrument_division): Mark instrumented arrays as having side effects. Adjust ubsan_type_descriptor call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Adjust ubsan_type_descriptor call. (ubsan_instrument_bounds): New function. (ubsan_array_ref_instrumented_p): New function. (ubsan_maybe_instrument_array_ref): New function. * c-ubsan.h (ubsan_instrument_bounds): Declare. (ubsan_array_ref_instrumented_p): Declare. (ubsan_maybe_instrument_array_ref): Declare. testsuite/ * c-c++-common/ubsan/bounds-1.c: New test. * c-c++-common/ubsan/bounds-2.c: New test. * c-c++-common/ubsan/bounds-3.c: New test. * c-c++-common/ubsan/bounds-4.c: New test. * c-c++-common/ubsan/bounds-5.c: New test. * c-c++-common/ubsan/bounds-6.c: New test. From-SVN: r211859
2014-06-20 23:20:51 +02:00
location_t loc = gimple_location (stmt);
gcc_assert (gimple_call_num_args (stmt) == 3);
/* Pick up the arguments of the UBSAN_BOUNDS call. */
tree type = TREE_TYPE (TREE_TYPE (gimple_call_arg (stmt, 0)));
tree index = gimple_call_arg (stmt, 1);
tree orig_index = index;
asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * flag-types.h (enum sanitize_code): Add SANITIZE_BOUNDS and or it into SANITIZE_UNDEFINED. * doc/invoke.texi: Describe -fsanitize=bounds. * gimplify.c (gimplify_call_expr): Add gimplification of internal functions created in the FEs. * internal-fn.c: Move "internal-fn.h" after "tree.h". (expand_UBSAN_BOUNDS): New function. * internal-fn.def (UBSAN_BOUNDS): New internal function. * internal-fn.h: Don't define internal functions here. * opts.c (common_handle_option): Add -fsanitize=bounds. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS, BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS_ABORT): Add. * tree-core.h: Define internal functions here. (struct tree_base): Add ifn field. * tree-pretty-print.c: Include "internal-fn.h". (dump_generic_node): Handle functions without CALL_EXPR_FN. * tree.c (get_callee_fndecl): Likewise. (build_call_expr_internal_loc): New function. * tree.def (CALL_EXPR): Update description. * tree.h (CALL_EXPR_IFN): Define. (build_call_expr_internal_loc): Declare. * ubsan.c (get_ubsan_type_info_for_type): Return 0 for non-arithmetic types. (ubsan_type_descriptor): Change bool parameter to enum ubsan_print_style. Adjust the code. Add handling of UBSAN_PRINT_ARRAY. (ubsan_expand_bounds_ifn): New function. (ubsan_expand_null_ifn): Adjust ubsan_type_descriptor call. (ubsan_build_overflow_builtin): Likewise. (instrument_bool_enum_load): Likewise. (ubsan_instrument_float_cast): Likewise. * ubsan.h (enum ubsan_print_style): New enum. (ubsan_expand_bounds_ifn): Declare. (ubsan_type_descriptor): Adjust declaration. Use a default parameter. c-family/ * c-gimplify.c: Include "c-ubsan.h" and "pointer-set.h". (ubsan_walk_array_refs_r): New function. (c_genericize): Instrument array bounds. * c-ubsan.c: Include "internal-fn.h". (ubsan_instrument_division): Mark instrumented arrays as having side effects. Adjust ubsan_type_descriptor call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Adjust ubsan_type_descriptor call. (ubsan_instrument_bounds): New function. (ubsan_array_ref_instrumented_p): New function. (ubsan_maybe_instrument_array_ref): New function. * c-ubsan.h (ubsan_instrument_bounds): Declare. (ubsan_array_ref_instrumented_p): Declare. (ubsan_maybe_instrument_array_ref): Declare. testsuite/ * c-c++-common/ubsan/bounds-1.c: New test. * c-c++-common/ubsan/bounds-2.c: New test. * c-c++-common/ubsan/bounds-3.c: New test. * c-c++-common/ubsan/bounds-4.c: New test. * c-c++-common/ubsan/bounds-5.c: New test. * c-c++-common/ubsan/bounds-6.c: New test. From-SVN: r211859
2014-06-20 23:20:51 +02:00
tree bound = gimple_call_arg (stmt, 2);
gimple_stmt_iterator gsi_orig = *gsi;
/* Create condition "if (index > bound)". */
basic_block then_bb, fallthru_bb;
gimple_stmt_iterator cond_insert_point
= create_cond_insert_point (gsi, false, false, true,
asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * flag-types.h (enum sanitize_code): Add SANITIZE_BOUNDS and or it into SANITIZE_UNDEFINED. * doc/invoke.texi: Describe -fsanitize=bounds. * gimplify.c (gimplify_call_expr): Add gimplification of internal functions created in the FEs. * internal-fn.c: Move "internal-fn.h" after "tree.h". (expand_UBSAN_BOUNDS): New function. * internal-fn.def (UBSAN_BOUNDS): New internal function. * internal-fn.h: Don't define internal functions here. * opts.c (common_handle_option): Add -fsanitize=bounds. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS, BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS_ABORT): Add. * tree-core.h: Define internal functions here. (struct tree_base): Add ifn field. * tree-pretty-print.c: Include "internal-fn.h". (dump_generic_node): Handle functions without CALL_EXPR_FN. * tree.c (get_callee_fndecl): Likewise. (build_call_expr_internal_loc): New function. * tree.def (CALL_EXPR): Update description. * tree.h (CALL_EXPR_IFN): Define. (build_call_expr_internal_loc): Declare. * ubsan.c (get_ubsan_type_info_for_type): Return 0 for non-arithmetic types. (ubsan_type_descriptor): Change bool parameter to enum ubsan_print_style. Adjust the code. Add handling of UBSAN_PRINT_ARRAY. (ubsan_expand_bounds_ifn): New function. (ubsan_expand_null_ifn): Adjust ubsan_type_descriptor call. (ubsan_build_overflow_builtin): Likewise. (instrument_bool_enum_load): Likewise. (ubsan_instrument_float_cast): Likewise. * ubsan.h (enum ubsan_print_style): New enum. (ubsan_expand_bounds_ifn): Declare. (ubsan_type_descriptor): Adjust declaration. Use a default parameter. c-family/ * c-gimplify.c: Include "c-ubsan.h" and "pointer-set.h". (ubsan_walk_array_refs_r): New function. (c_genericize): Instrument array bounds. * c-ubsan.c: Include "internal-fn.h". (ubsan_instrument_division): Mark instrumented arrays as having side effects. Adjust ubsan_type_descriptor call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Adjust ubsan_type_descriptor call. (ubsan_instrument_bounds): New function. (ubsan_array_ref_instrumented_p): New function. (ubsan_maybe_instrument_array_ref): New function. * c-ubsan.h (ubsan_instrument_bounds): Declare. (ubsan_array_ref_instrumented_p): Declare. (ubsan_maybe_instrument_array_ref): Declare. testsuite/ * c-c++-common/ubsan/bounds-1.c: New test. * c-c++-common/ubsan/bounds-2.c: New test. * c-c++-common/ubsan/bounds-3.c: New test. * c-c++-common/ubsan/bounds-4.c: New test. * c-c++-common/ubsan/bounds-5.c: New test. * c-c++-common/ubsan/bounds-6.c: New test. From-SVN: r211859
2014-06-20 23:20:51 +02:00
&then_bb, &fallthru_bb);
index = fold_convert (TREE_TYPE (bound), index);
index = force_gimple_operand_gsi (&cond_insert_point, index,
true, NULL_TREE,
false, GSI_NEW_STMT);
gimple *g = gimple_build_cond (GT_EXPR, index, bound, NULL_TREE, NULL_TREE);
asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * flag-types.h (enum sanitize_code): Add SANITIZE_BOUNDS and or it into SANITIZE_UNDEFINED. * doc/invoke.texi: Describe -fsanitize=bounds. * gimplify.c (gimplify_call_expr): Add gimplification of internal functions created in the FEs. * internal-fn.c: Move "internal-fn.h" after "tree.h". (expand_UBSAN_BOUNDS): New function. * internal-fn.def (UBSAN_BOUNDS): New internal function. * internal-fn.h: Don't define internal functions here. * opts.c (common_handle_option): Add -fsanitize=bounds. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS, BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS_ABORT): Add. * tree-core.h: Define internal functions here. (struct tree_base): Add ifn field. * tree-pretty-print.c: Include "internal-fn.h". (dump_generic_node): Handle functions without CALL_EXPR_FN. * tree.c (get_callee_fndecl): Likewise. (build_call_expr_internal_loc): New function. * tree.def (CALL_EXPR): Update description. * tree.h (CALL_EXPR_IFN): Define. (build_call_expr_internal_loc): Declare. * ubsan.c (get_ubsan_type_info_for_type): Return 0 for non-arithmetic types. (ubsan_type_descriptor): Change bool parameter to enum ubsan_print_style. Adjust the code. Add handling of UBSAN_PRINT_ARRAY. (ubsan_expand_bounds_ifn): New function. (ubsan_expand_null_ifn): Adjust ubsan_type_descriptor call. (ubsan_build_overflow_builtin): Likewise. (instrument_bool_enum_load): Likewise. (ubsan_instrument_float_cast): Likewise. * ubsan.h (enum ubsan_print_style): New enum. (ubsan_expand_bounds_ifn): Declare. (ubsan_type_descriptor): Adjust declaration. Use a default parameter. c-family/ * c-gimplify.c: Include "c-ubsan.h" and "pointer-set.h". (ubsan_walk_array_refs_r): New function. (c_genericize): Instrument array bounds. * c-ubsan.c: Include "internal-fn.h". (ubsan_instrument_division): Mark instrumented arrays as having side effects. Adjust ubsan_type_descriptor call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Adjust ubsan_type_descriptor call. (ubsan_instrument_bounds): New function. (ubsan_array_ref_instrumented_p): New function. (ubsan_maybe_instrument_array_ref): New function. * c-ubsan.h (ubsan_instrument_bounds): Declare. (ubsan_array_ref_instrumented_p): Declare. (ubsan_maybe_instrument_array_ref): Declare. testsuite/ * c-c++-common/ubsan/bounds-1.c: New test. * c-c++-common/ubsan/bounds-2.c: New test. * c-c++-common/ubsan/bounds-3.c: New test. * c-c++-common/ubsan/bounds-4.c: New test. * c-c++-common/ubsan/bounds-5.c: New test. * c-c++-common/ubsan/bounds-6.c: New test. From-SVN: r211859
2014-06-20 23:20:51 +02:00
gimple_set_location (g, loc);
gsi_insert_after (&cond_insert_point, g, GSI_NEW_STMT);
/* Generate __ubsan_handle_out_of_bounds call. */
*gsi = gsi_after_labels (then_bb);
if (flag_sanitize_undefined_trap_on_error)
g = gimple_build_call (builtin_decl_explicit (BUILT_IN_TRAP), 0);
else
{
tree data
= ubsan_create_data ("__ubsan_out_of_bounds_data", 1, &loc,
asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * flag-types.h (enum sanitize_code): Add SANITIZE_BOUNDS and or it into SANITIZE_UNDEFINED. * doc/invoke.texi: Describe -fsanitize=bounds. * gimplify.c (gimplify_call_expr): Add gimplification of internal functions created in the FEs. * internal-fn.c: Move "internal-fn.h" after "tree.h". (expand_UBSAN_BOUNDS): New function. * internal-fn.def (UBSAN_BOUNDS): New internal function. * internal-fn.h: Don't define internal functions here. * opts.c (common_handle_option): Add -fsanitize=bounds. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS, BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS_ABORT): Add. * tree-core.h: Define internal functions here. (struct tree_base): Add ifn field. * tree-pretty-print.c: Include "internal-fn.h". (dump_generic_node): Handle functions without CALL_EXPR_FN. * tree.c (get_callee_fndecl): Likewise. (build_call_expr_internal_loc): New function. * tree.def (CALL_EXPR): Update description. * tree.h (CALL_EXPR_IFN): Define. (build_call_expr_internal_loc): Declare. * ubsan.c (get_ubsan_type_info_for_type): Return 0 for non-arithmetic types. (ubsan_type_descriptor): Change bool parameter to enum ubsan_print_style. Adjust the code. Add handling of UBSAN_PRINT_ARRAY. (ubsan_expand_bounds_ifn): New function. (ubsan_expand_null_ifn): Adjust ubsan_type_descriptor call. (ubsan_build_overflow_builtin): Likewise. (instrument_bool_enum_load): Likewise. (ubsan_instrument_float_cast): Likewise. * ubsan.h (enum ubsan_print_style): New enum. (ubsan_expand_bounds_ifn): Declare. (ubsan_type_descriptor): Adjust declaration. Use a default parameter. c-family/ * c-gimplify.c: Include "c-ubsan.h" and "pointer-set.h". (ubsan_walk_array_refs_r): New function. (c_genericize): Instrument array bounds. * c-ubsan.c: Include "internal-fn.h". (ubsan_instrument_division): Mark instrumented arrays as having side effects. Adjust ubsan_type_descriptor call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Adjust ubsan_type_descriptor call. (ubsan_instrument_bounds): New function. (ubsan_array_ref_instrumented_p): New function. (ubsan_maybe_instrument_array_ref): New function. * c-ubsan.h (ubsan_instrument_bounds): Declare. (ubsan_array_ref_instrumented_p): Declare. (ubsan_maybe_instrument_array_ref): Declare. testsuite/ * c-c++-common/ubsan/bounds-1.c: New test. * c-c++-common/ubsan/bounds-2.c: New test. * c-c++-common/ubsan/bounds-3.c: New test. * c-c++-common/ubsan/bounds-4.c: New test. * c-c++-common/ubsan/bounds-5.c: New test. * c-c++-common/ubsan/bounds-6.c: New test. From-SVN: r211859
2014-06-20 23:20:51 +02:00
ubsan_type_descriptor (type, UBSAN_PRINT_ARRAY),
ubsan_type_descriptor (TREE_TYPE (orig_index)),
NULL_TREE, NULL_TREE);
asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * flag-types.h (enum sanitize_code): Add SANITIZE_BOUNDS and or it into SANITIZE_UNDEFINED. * doc/invoke.texi: Describe -fsanitize=bounds. * gimplify.c (gimplify_call_expr): Add gimplification of internal functions created in the FEs. * internal-fn.c: Move "internal-fn.h" after "tree.h". (expand_UBSAN_BOUNDS): New function. * internal-fn.def (UBSAN_BOUNDS): New internal function. * internal-fn.h: Don't define internal functions here. * opts.c (common_handle_option): Add -fsanitize=bounds. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS, BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS_ABORT): Add. * tree-core.h: Define internal functions here. (struct tree_base): Add ifn field. * tree-pretty-print.c: Include "internal-fn.h". (dump_generic_node): Handle functions without CALL_EXPR_FN. * tree.c (get_callee_fndecl): Likewise. (build_call_expr_internal_loc): New function. * tree.def (CALL_EXPR): Update description. * tree.h (CALL_EXPR_IFN): Define. (build_call_expr_internal_loc): Declare. * ubsan.c (get_ubsan_type_info_for_type): Return 0 for non-arithmetic types. (ubsan_type_descriptor): Change bool parameter to enum ubsan_print_style. Adjust the code. Add handling of UBSAN_PRINT_ARRAY. (ubsan_expand_bounds_ifn): New function. (ubsan_expand_null_ifn): Adjust ubsan_type_descriptor call. (ubsan_build_overflow_builtin): Likewise. (instrument_bool_enum_load): Likewise. (ubsan_instrument_float_cast): Likewise. * ubsan.h (enum ubsan_print_style): New enum. (ubsan_expand_bounds_ifn): Declare. (ubsan_type_descriptor): Adjust declaration. Use a default parameter. c-family/ * c-gimplify.c: Include "c-ubsan.h" and "pointer-set.h". (ubsan_walk_array_refs_r): New function. (c_genericize): Instrument array bounds. * c-ubsan.c: Include "internal-fn.h". (ubsan_instrument_division): Mark instrumented arrays as having side effects. Adjust ubsan_type_descriptor call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Adjust ubsan_type_descriptor call. (ubsan_instrument_bounds): New function. (ubsan_array_ref_instrumented_p): New function. (ubsan_maybe_instrument_array_ref): New function. * c-ubsan.h (ubsan_instrument_bounds): Declare. (ubsan_array_ref_instrumented_p): Declare. (ubsan_maybe_instrument_array_ref): Declare. testsuite/ * c-c++-common/ubsan/bounds-1.c: New test. * c-c++-common/ubsan/bounds-2.c: New test. * c-c++-common/ubsan/bounds-3.c: New test. * c-c++-common/ubsan/bounds-4.c: New test. * c-c++-common/ubsan/bounds-5.c: New test. * c-c++-common/ubsan/bounds-6.c: New test. From-SVN: r211859
2014-06-20 23:20:51 +02:00
data = build_fold_addr_expr_loc (loc, data);
enum built_in_function bcode
New syntax for -fsanitize-recover. 2014-10-22 Jakub Jelinek <jakub@redhat.com> Yury Gribov <y.gribov@samsung.com> gcc/ * common.opt (flag_sanitize_recover): New variable. (fsanitize-recover): Remove Var/Init, deprecate. (fsanitize-recover=): New option. * doc/invoke.texi (fsanitize-recover): Update docs. * opts.c (finish_options): Use opts->x_flag_sanitize instead of flag_sanitize. Prohibit -fsanitize-recover for anything besides UBSan. Formatting. (common_handle_option): Handle OPT_fsanitize_recover_ and OPT_fsanitize_recover. Use opts->x_flag_sanitize instead of flag_sanitize. * asan.c (pass_sanopt::execute): Fix up formatting. * ubsan.c (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn, ubsan_expand_objsize_ifn, ubsan_build_overflow_builtin, instrument_bool_enum_load, ubsan_instrument_float_cast, instrument_nonnull_arg, instrument_nonnull_return): Check bits in flag_sanitize_recover bitmask instead of flag_sanitize_recover as bool flag. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division, ubsan_instrument_shift, ubsan_instrument_vla): Check bits in flag_sanitize_recover bitmask instead of flag_sanitize_recover as bool flag. gcc/testsuite/ * c-c++-common/ubsan/align-1.c: Update cmdline options. * c-c++-common/ubsan/align-3.c: Likewise. * c-c++-common/ubsan/bounds-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-7.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-10.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-7.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-8.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-9.c: Likewise. * c-c++-common/ubsan/nonnull-2.c: Likewise. * c-c++-common/ubsan/nonnull-3.c: Likewise. * c-c++-common/ubsan/object-size-3.c: Likewise. * c-c++-common/ubsan/overflow-1.c: Likewise. * c-c++-common/ubsan/overflow-add-1.c: Likewise. * c-c++-common/ubsan/overflow-add-3.c: Likewise. * c-c++-common/ubsan/overflow-mul-1.c: Likewise. * c-c++-common/ubsan/overflow-mul-3.c: Likewise. * c-c++-common/ubsan/overflow-negate-2.c: Likewise. * c-c++-common/ubsan/overflow-sub-1.c: Likewise. * c-c++-common/ubsan/pr59503.c: Likewise. * c-c++-common/ubsan/pr60613-1.c: Likewise. * c-c++-common/ubsan/save-expr-1.c: Likewise. * c-c++-common/ubsan/shift-3.c: Likewise. * c-c++-common/ubsan/shift-6.c: Likewise. * c-c++-common/ubsan/undefined-1.c: Likewise. * c-c++-common/ubsan/vla-2.c: Likewise. * c-c++-common/ubsan/vla-3.c: Likewise. * c-c++-common/ubsan/vla-4.c: Likewise. * g++.dg/ubsan/cxx11-shift-1.C: Likewise. * g++.dg/ubsan/return-2.C: Likewise. * c-c++-common/ubsan/recovery-1.c: New test. * c-c++-common/ubsan/recovery-2.c: New test. * c-c++-common/ubsan/recovery-3.c: New test. * c-c++-common/ubsan/recovery-common.inc: New file. Co-Authored-By: Yury Gribov <y.gribov@samsung.com> From-SVN: r216552
2014-10-22 13:07:10 +02:00
= (flag_sanitize_recover & SANITIZE_BOUNDS)
asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * flag-types.h (enum sanitize_code): Add SANITIZE_BOUNDS and or it into SANITIZE_UNDEFINED. * doc/invoke.texi: Describe -fsanitize=bounds. * gimplify.c (gimplify_call_expr): Add gimplification of internal functions created in the FEs. * internal-fn.c: Move "internal-fn.h" after "tree.h". (expand_UBSAN_BOUNDS): New function. * internal-fn.def (UBSAN_BOUNDS): New internal function. * internal-fn.h: Don't define internal functions here. * opts.c (common_handle_option): Add -fsanitize=bounds. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS, BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS_ABORT): Add. * tree-core.h: Define internal functions here. (struct tree_base): Add ifn field. * tree-pretty-print.c: Include "internal-fn.h". (dump_generic_node): Handle functions without CALL_EXPR_FN. * tree.c (get_callee_fndecl): Likewise. (build_call_expr_internal_loc): New function. * tree.def (CALL_EXPR): Update description. * tree.h (CALL_EXPR_IFN): Define. (build_call_expr_internal_loc): Declare. * ubsan.c (get_ubsan_type_info_for_type): Return 0 for non-arithmetic types. (ubsan_type_descriptor): Change bool parameter to enum ubsan_print_style. Adjust the code. Add handling of UBSAN_PRINT_ARRAY. (ubsan_expand_bounds_ifn): New function. (ubsan_expand_null_ifn): Adjust ubsan_type_descriptor call. (ubsan_build_overflow_builtin): Likewise. (instrument_bool_enum_load): Likewise. (ubsan_instrument_float_cast): Likewise. * ubsan.h (enum ubsan_print_style): New enum. (ubsan_expand_bounds_ifn): Declare. (ubsan_type_descriptor): Adjust declaration. Use a default parameter. c-family/ * c-gimplify.c: Include "c-ubsan.h" and "pointer-set.h". (ubsan_walk_array_refs_r): New function. (c_genericize): Instrument array bounds. * c-ubsan.c: Include "internal-fn.h". (ubsan_instrument_division): Mark instrumented arrays as having side effects. Adjust ubsan_type_descriptor call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Adjust ubsan_type_descriptor call. (ubsan_instrument_bounds): New function. (ubsan_array_ref_instrumented_p): New function. (ubsan_maybe_instrument_array_ref): New function. * c-ubsan.h (ubsan_instrument_bounds): Declare. (ubsan_array_ref_instrumented_p): Declare. (ubsan_maybe_instrument_array_ref): Declare. testsuite/ * c-c++-common/ubsan/bounds-1.c: New test. * c-c++-common/ubsan/bounds-2.c: New test. * c-c++-common/ubsan/bounds-3.c: New test. * c-c++-common/ubsan/bounds-4.c: New test. * c-c++-common/ubsan/bounds-5.c: New test. * c-c++-common/ubsan/bounds-6.c: New test. From-SVN: r211859
2014-06-20 23:20:51 +02:00
? BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS
: BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS_ABORT;
tree fn = builtin_decl_explicit (bcode);
tree val = ubsan_encode_value (orig_index, UBSAN_ENCODE_VALUE_GIMPLE);
val = force_gimple_operand_gsi (gsi, val, true, NULL_TREE, true,
GSI_SAME_STMT);
asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * flag-types.h (enum sanitize_code): Add SANITIZE_BOUNDS and or it into SANITIZE_UNDEFINED. * doc/invoke.texi: Describe -fsanitize=bounds. * gimplify.c (gimplify_call_expr): Add gimplification of internal functions created in the FEs. * internal-fn.c: Move "internal-fn.h" after "tree.h". (expand_UBSAN_BOUNDS): New function. * internal-fn.def (UBSAN_BOUNDS): New internal function. * internal-fn.h: Don't define internal functions here. * opts.c (common_handle_option): Add -fsanitize=bounds. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS, BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS_ABORT): Add. * tree-core.h: Define internal functions here. (struct tree_base): Add ifn field. * tree-pretty-print.c: Include "internal-fn.h". (dump_generic_node): Handle functions without CALL_EXPR_FN. * tree.c (get_callee_fndecl): Likewise. (build_call_expr_internal_loc): New function. * tree.def (CALL_EXPR): Update description. * tree.h (CALL_EXPR_IFN): Define. (build_call_expr_internal_loc): Declare. * ubsan.c (get_ubsan_type_info_for_type): Return 0 for non-arithmetic types. (ubsan_type_descriptor): Change bool parameter to enum ubsan_print_style. Adjust the code. Add handling of UBSAN_PRINT_ARRAY. (ubsan_expand_bounds_ifn): New function. (ubsan_expand_null_ifn): Adjust ubsan_type_descriptor call. (ubsan_build_overflow_builtin): Likewise. (instrument_bool_enum_load): Likewise. (ubsan_instrument_float_cast): Likewise. * ubsan.h (enum ubsan_print_style): New enum. (ubsan_expand_bounds_ifn): Declare. (ubsan_type_descriptor): Adjust declaration. Use a default parameter. c-family/ * c-gimplify.c: Include "c-ubsan.h" and "pointer-set.h". (ubsan_walk_array_refs_r): New function. (c_genericize): Instrument array bounds. * c-ubsan.c: Include "internal-fn.h". (ubsan_instrument_division): Mark instrumented arrays as having side effects. Adjust ubsan_type_descriptor call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Adjust ubsan_type_descriptor call. (ubsan_instrument_bounds): New function. (ubsan_array_ref_instrumented_p): New function. (ubsan_maybe_instrument_array_ref): New function. * c-ubsan.h (ubsan_instrument_bounds): Declare. (ubsan_array_ref_instrumented_p): Declare. (ubsan_maybe_instrument_array_ref): Declare. testsuite/ * c-c++-common/ubsan/bounds-1.c: New test. * c-c++-common/ubsan/bounds-2.c: New test. * c-c++-common/ubsan/bounds-3.c: New test. * c-c++-common/ubsan/bounds-4.c: New test. * c-c++-common/ubsan/bounds-5.c: New test. * c-c++-common/ubsan/bounds-6.c: New test. From-SVN: r211859
2014-06-20 23:20:51 +02:00
g = gimple_build_call (fn, 2, data, val);
}
gimple_set_location (g, loc);
gsi_insert_before (gsi, g, GSI_SAME_STMT);
/* Get rid of the UBSAN_BOUNDS call from the IR. */
unlink_stmt_vdef (stmt);
gsi_remove (&gsi_orig, true);
/* Point GSI to next logical statement. */
*gsi = gsi_start_bb (fallthru_bb);
opts.c (common_handle_option): Handle -fsanitize=alignment. * opts.c (common_handle_option): Handle -fsanitize=alignment. * ubsan.h (enum ubsan_null_ckind): Add UBSAN_CTOR_CALL. (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn): Change return type to bool. * stor-layout.h (min_align_of_type): New prototype. * asan.c (pass_sanopt::execute): Don't perform gsi_next if ubsan_expand* told us not to do it. Remove the extra gsi_end_p check. * ubsan.c: Include builtins.h. (ubsan_expand_bounds_ifn): Change return type to bool, always return true. (ubsan_expand_null_ifn): Change return type to bool, change argument to gimple_stmt_iterator *. Handle both null and alignment sanitization, take type from ckind argument's type rather than first argument. (instrument_member_call): Removed. (instrument_mem_ref): Remove t argument, add mem and base arguments. Handle both null and alignment sanitization, don't say whole struct access is member access. Build 3 argument IFN_UBSAN_NULL call instead of 2 argument. (instrument_null): Adjust instrument_mem_ref caller. Don't instrument calls here. (pass_ubsan::gate, pass_ubsan::execute): Handle SANITIZE_ALIGNMENT like SANITIZE_NULL. * stor-layout.c (min_align_of_type): New function. * flag-types.h (enum sanitize_code): Add SANITIZE_ALIGNMENT. Or it into SANITIZE_UNDEFINED. * doc/invoke.texi (-fsanitize=alignment): Document. cp/ * cp-gimplify.c (cp_genericize_r): For -fsanitize=null and/or -fsanitize=alignment call ubsan_maybe_instrument_reference for casts to REFERENCE_TYPE and ubsan_maybe_instrument_member_call for calls to member functions. c-family/ * c-common.h (min_align_of_type): Removed prototype. * c-common.c (min_align_of_type): Removed. * c-ubsan.h (ubsan_maybe_instrument_reference, ubsan_maybe_instrument_member_call): New prototypes. * c-ubsan.c: Include stor-layout.h and builtins.h. (ubsan_maybe_instrument_reference_or_call, ubsan_maybe_instrument_reference, ubsan_maybe_instrument_call): New functions. testsuite/ * c-c++-common/ubsan/align-1.c: New test. * c-c++-common/ubsan/align-2.c: New test. * c-c++-common/ubsan/align-3.c: New test. * c-c++-common/ubsan/align-4.c: New test. * c-c++-common/ubsan/align-5.c: New test. * c-c++-common/ubsan/attrib-4.c: New test. * g++.dg/ubsan/align-1.C: New test. * g++.dg/ubsan/align-2.C: New test. * g++.dg/ubsan/align-3.C: New test. * g++.dg/ubsan/attrib-1.C: New test. * g++.dg/ubsan/null-1.C: New test. * g++.dg/ubsan/null-2.C: New test. From-SVN: r213406
2014-08-01 09:52:43 +02:00
return true;
asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * flag-types.h (enum sanitize_code): Add SANITIZE_BOUNDS and or it into SANITIZE_UNDEFINED. * doc/invoke.texi: Describe -fsanitize=bounds. * gimplify.c (gimplify_call_expr): Add gimplification of internal functions created in the FEs. * internal-fn.c: Move "internal-fn.h" after "tree.h". (expand_UBSAN_BOUNDS): New function. * internal-fn.def (UBSAN_BOUNDS): New internal function. * internal-fn.h: Don't define internal functions here. * opts.c (common_handle_option): Add -fsanitize=bounds. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS, BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS_ABORT): Add. * tree-core.h: Define internal functions here. (struct tree_base): Add ifn field. * tree-pretty-print.c: Include "internal-fn.h". (dump_generic_node): Handle functions without CALL_EXPR_FN. * tree.c (get_callee_fndecl): Likewise. (build_call_expr_internal_loc): New function. * tree.def (CALL_EXPR): Update description. * tree.h (CALL_EXPR_IFN): Define. (build_call_expr_internal_loc): Declare. * ubsan.c (get_ubsan_type_info_for_type): Return 0 for non-arithmetic types. (ubsan_type_descriptor): Change bool parameter to enum ubsan_print_style. Adjust the code. Add handling of UBSAN_PRINT_ARRAY. (ubsan_expand_bounds_ifn): New function. (ubsan_expand_null_ifn): Adjust ubsan_type_descriptor call. (ubsan_build_overflow_builtin): Likewise. (instrument_bool_enum_load): Likewise. (ubsan_instrument_float_cast): Likewise. * ubsan.h (enum ubsan_print_style): New enum. (ubsan_expand_bounds_ifn): Declare. (ubsan_type_descriptor): Adjust declaration. Use a default parameter. c-family/ * c-gimplify.c: Include "c-ubsan.h" and "pointer-set.h". (ubsan_walk_array_refs_r): New function. (c_genericize): Instrument array bounds. * c-ubsan.c: Include "internal-fn.h". (ubsan_instrument_division): Mark instrumented arrays as having side effects. Adjust ubsan_type_descriptor call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Adjust ubsan_type_descriptor call. (ubsan_instrument_bounds): New function. (ubsan_array_ref_instrumented_p): New function. (ubsan_maybe_instrument_array_ref): New function. * c-ubsan.h (ubsan_instrument_bounds): Declare. (ubsan_array_ref_instrumented_p): Declare. (ubsan_maybe_instrument_array_ref): Declare. testsuite/ * c-c++-common/ubsan/bounds-1.c: New test. * c-c++-common/ubsan/bounds-2.c: New test. * c-c++-common/ubsan/bounds-3.c: New test. * c-c++-common/ubsan/bounds-4.c: New test. * c-c++-common/ubsan/bounds-5.c: New test. * c-c++-common/ubsan/bounds-6.c: New test. From-SVN: r211859
2014-06-20 23:20:51 +02:00
}
opts.c (common_handle_option): Handle -fsanitize=alignment. * opts.c (common_handle_option): Handle -fsanitize=alignment. * ubsan.h (enum ubsan_null_ckind): Add UBSAN_CTOR_CALL. (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn): Change return type to bool. * stor-layout.h (min_align_of_type): New prototype. * asan.c (pass_sanopt::execute): Don't perform gsi_next if ubsan_expand* told us not to do it. Remove the extra gsi_end_p check. * ubsan.c: Include builtins.h. (ubsan_expand_bounds_ifn): Change return type to bool, always return true. (ubsan_expand_null_ifn): Change return type to bool, change argument to gimple_stmt_iterator *. Handle both null and alignment sanitization, take type from ckind argument's type rather than first argument. (instrument_member_call): Removed. (instrument_mem_ref): Remove t argument, add mem and base arguments. Handle both null and alignment sanitization, don't say whole struct access is member access. Build 3 argument IFN_UBSAN_NULL call instead of 2 argument. (instrument_null): Adjust instrument_mem_ref caller. Don't instrument calls here. (pass_ubsan::gate, pass_ubsan::execute): Handle SANITIZE_ALIGNMENT like SANITIZE_NULL. * stor-layout.c (min_align_of_type): New function. * flag-types.h (enum sanitize_code): Add SANITIZE_ALIGNMENT. Or it into SANITIZE_UNDEFINED. * doc/invoke.texi (-fsanitize=alignment): Document. cp/ * cp-gimplify.c (cp_genericize_r): For -fsanitize=null and/or -fsanitize=alignment call ubsan_maybe_instrument_reference for casts to REFERENCE_TYPE and ubsan_maybe_instrument_member_call for calls to member functions. c-family/ * c-common.h (min_align_of_type): Removed prototype. * c-common.c (min_align_of_type): Removed. * c-ubsan.h (ubsan_maybe_instrument_reference, ubsan_maybe_instrument_member_call): New prototypes. * c-ubsan.c: Include stor-layout.h and builtins.h. (ubsan_maybe_instrument_reference_or_call, ubsan_maybe_instrument_reference, ubsan_maybe_instrument_call): New functions. testsuite/ * c-c++-common/ubsan/align-1.c: New test. * c-c++-common/ubsan/align-2.c: New test. * c-c++-common/ubsan/align-3.c: New test. * c-c++-common/ubsan/align-4.c: New test. * c-c++-common/ubsan/align-5.c: New test. * c-c++-common/ubsan/attrib-4.c: New test. * g++.dg/ubsan/align-1.C: New test. * g++.dg/ubsan/align-2.C: New test. * g++.dg/ubsan/align-3.C: New test. * g++.dg/ubsan/attrib-1.C: New test. * g++.dg/ubsan/null-1.C: New test. * g++.dg/ubsan/null-2.C: New test. From-SVN: r213406
2014-08-01 09:52:43 +02:00
/* Expand UBSAN_NULL internal call. The type is kept on the ckind
argument which is a constant, because the middle-end treats pointer
conversions as useless and therefore the type of the first argument
could be changed to any other pointer type. */
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
opts.c (common_handle_option): Handle -fsanitize=alignment. * opts.c (common_handle_option): Handle -fsanitize=alignment. * ubsan.h (enum ubsan_null_ckind): Add UBSAN_CTOR_CALL. (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn): Change return type to bool. * stor-layout.h (min_align_of_type): New prototype. * asan.c (pass_sanopt::execute): Don't perform gsi_next if ubsan_expand* told us not to do it. Remove the extra gsi_end_p check. * ubsan.c: Include builtins.h. (ubsan_expand_bounds_ifn): Change return type to bool, always return true. (ubsan_expand_null_ifn): Change return type to bool, change argument to gimple_stmt_iterator *. Handle both null and alignment sanitization, take type from ckind argument's type rather than first argument. (instrument_member_call): Removed. (instrument_mem_ref): Remove t argument, add mem and base arguments. Handle both null and alignment sanitization, don't say whole struct access is member access. Build 3 argument IFN_UBSAN_NULL call instead of 2 argument. (instrument_null): Adjust instrument_mem_ref caller. Don't instrument calls here. (pass_ubsan::gate, pass_ubsan::execute): Handle SANITIZE_ALIGNMENT like SANITIZE_NULL. * stor-layout.c (min_align_of_type): New function. * flag-types.h (enum sanitize_code): Add SANITIZE_ALIGNMENT. Or it into SANITIZE_UNDEFINED. * doc/invoke.texi (-fsanitize=alignment): Document. cp/ * cp-gimplify.c (cp_genericize_r): For -fsanitize=null and/or -fsanitize=alignment call ubsan_maybe_instrument_reference for casts to REFERENCE_TYPE and ubsan_maybe_instrument_member_call for calls to member functions. c-family/ * c-common.h (min_align_of_type): Removed prototype. * c-common.c (min_align_of_type): Removed. * c-ubsan.h (ubsan_maybe_instrument_reference, ubsan_maybe_instrument_member_call): New prototypes. * c-ubsan.c: Include stor-layout.h and builtins.h. (ubsan_maybe_instrument_reference_or_call, ubsan_maybe_instrument_reference, ubsan_maybe_instrument_call): New functions. testsuite/ * c-c++-common/ubsan/align-1.c: New test. * c-c++-common/ubsan/align-2.c: New test. * c-c++-common/ubsan/align-3.c: New test. * c-c++-common/ubsan/align-4.c: New test. * c-c++-common/ubsan/align-5.c: New test. * c-c++-common/ubsan/attrib-4.c: New test. * g++.dg/ubsan/align-1.C: New test. * g++.dg/ubsan/align-2.C: New test. * g++.dg/ubsan/align-3.C: New test. * g++.dg/ubsan/attrib-1.C: New test. * g++.dg/ubsan/null-1.C: New test. * g++.dg/ubsan/null-2.C: New test. From-SVN: r213406
2014-08-01 09:52:43 +02:00
bool
ubsan_expand_null_ifn (gimple_stmt_iterator *gsip)
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
{
opts.c (common_handle_option): Handle -fsanitize=alignment. * opts.c (common_handle_option): Handle -fsanitize=alignment. * ubsan.h (enum ubsan_null_ckind): Add UBSAN_CTOR_CALL. (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn): Change return type to bool. * stor-layout.h (min_align_of_type): New prototype. * asan.c (pass_sanopt::execute): Don't perform gsi_next if ubsan_expand* told us not to do it. Remove the extra gsi_end_p check. * ubsan.c: Include builtins.h. (ubsan_expand_bounds_ifn): Change return type to bool, always return true. (ubsan_expand_null_ifn): Change return type to bool, change argument to gimple_stmt_iterator *. Handle both null and alignment sanitization, take type from ckind argument's type rather than first argument. (instrument_member_call): Removed. (instrument_mem_ref): Remove t argument, add mem and base arguments. Handle both null and alignment sanitization, don't say whole struct access is member access. Build 3 argument IFN_UBSAN_NULL call instead of 2 argument. (instrument_null): Adjust instrument_mem_ref caller. Don't instrument calls here. (pass_ubsan::gate, pass_ubsan::execute): Handle SANITIZE_ALIGNMENT like SANITIZE_NULL. * stor-layout.c (min_align_of_type): New function. * flag-types.h (enum sanitize_code): Add SANITIZE_ALIGNMENT. Or it into SANITIZE_UNDEFINED. * doc/invoke.texi (-fsanitize=alignment): Document. cp/ * cp-gimplify.c (cp_genericize_r): For -fsanitize=null and/or -fsanitize=alignment call ubsan_maybe_instrument_reference for casts to REFERENCE_TYPE and ubsan_maybe_instrument_member_call for calls to member functions. c-family/ * c-common.h (min_align_of_type): Removed prototype. * c-common.c (min_align_of_type): Removed. * c-ubsan.h (ubsan_maybe_instrument_reference, ubsan_maybe_instrument_member_call): New prototypes. * c-ubsan.c: Include stor-layout.h and builtins.h. (ubsan_maybe_instrument_reference_or_call, ubsan_maybe_instrument_reference, ubsan_maybe_instrument_call): New functions. testsuite/ * c-c++-common/ubsan/align-1.c: New test. * c-c++-common/ubsan/align-2.c: New test. * c-c++-common/ubsan/align-3.c: New test. * c-c++-common/ubsan/align-4.c: New test. * c-c++-common/ubsan/align-5.c: New test. * c-c++-common/ubsan/attrib-4.c: New test. * g++.dg/ubsan/align-1.C: New test. * g++.dg/ubsan/align-2.C: New test. * g++.dg/ubsan/align-3.C: New test. * g++.dg/ubsan/attrib-1.C: New test. * g++.dg/ubsan/null-1.C: New test. * g++.dg/ubsan/null-2.C: New test. From-SVN: r213406
2014-08-01 09:52:43 +02:00
gimple_stmt_iterator gsi = *gsip;
gimple *stmt = gsi_stmt (gsi);
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
location_t loc = gimple_location (stmt);
opts.c (common_handle_option): Handle -fsanitize=alignment. * opts.c (common_handle_option): Handle -fsanitize=alignment. * ubsan.h (enum ubsan_null_ckind): Add UBSAN_CTOR_CALL. (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn): Change return type to bool. * stor-layout.h (min_align_of_type): New prototype. * asan.c (pass_sanopt::execute): Don't perform gsi_next if ubsan_expand* told us not to do it. Remove the extra gsi_end_p check. * ubsan.c: Include builtins.h. (ubsan_expand_bounds_ifn): Change return type to bool, always return true. (ubsan_expand_null_ifn): Change return type to bool, change argument to gimple_stmt_iterator *. Handle both null and alignment sanitization, take type from ckind argument's type rather than first argument. (instrument_member_call): Removed. (instrument_mem_ref): Remove t argument, add mem and base arguments. Handle both null and alignment sanitization, don't say whole struct access is member access. Build 3 argument IFN_UBSAN_NULL call instead of 2 argument. (instrument_null): Adjust instrument_mem_ref caller. Don't instrument calls here. (pass_ubsan::gate, pass_ubsan::execute): Handle SANITIZE_ALIGNMENT like SANITIZE_NULL. * stor-layout.c (min_align_of_type): New function. * flag-types.h (enum sanitize_code): Add SANITIZE_ALIGNMENT. Or it into SANITIZE_UNDEFINED. * doc/invoke.texi (-fsanitize=alignment): Document. cp/ * cp-gimplify.c (cp_genericize_r): For -fsanitize=null and/or -fsanitize=alignment call ubsan_maybe_instrument_reference for casts to REFERENCE_TYPE and ubsan_maybe_instrument_member_call for calls to member functions. c-family/ * c-common.h (min_align_of_type): Removed prototype. * c-common.c (min_align_of_type): Removed. * c-ubsan.h (ubsan_maybe_instrument_reference, ubsan_maybe_instrument_member_call): New prototypes. * c-ubsan.c: Include stor-layout.h and builtins.h. (ubsan_maybe_instrument_reference_or_call, ubsan_maybe_instrument_reference, ubsan_maybe_instrument_call): New functions. testsuite/ * c-c++-common/ubsan/align-1.c: New test. * c-c++-common/ubsan/align-2.c: New test. * c-c++-common/ubsan/align-3.c: New test. * c-c++-common/ubsan/align-4.c: New test. * c-c++-common/ubsan/align-5.c: New test. * c-c++-common/ubsan/attrib-4.c: New test. * g++.dg/ubsan/align-1.C: New test. * g++.dg/ubsan/align-2.C: New test. * g++.dg/ubsan/align-3.C: New test. * g++.dg/ubsan/attrib-1.C: New test. * g++.dg/ubsan/null-1.C: New test. * g++.dg/ubsan/null-2.C: New test. From-SVN: r213406
2014-08-01 09:52:43 +02:00
gcc_assert (gimple_call_num_args (stmt) == 3);
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
tree ptr = gimple_call_arg (stmt, 0);
tree ckind = gimple_call_arg (stmt, 1);
opts.c (common_handle_option): Handle -fsanitize=alignment. * opts.c (common_handle_option): Handle -fsanitize=alignment. * ubsan.h (enum ubsan_null_ckind): Add UBSAN_CTOR_CALL. (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn): Change return type to bool. * stor-layout.h (min_align_of_type): New prototype. * asan.c (pass_sanopt::execute): Don't perform gsi_next if ubsan_expand* told us not to do it. Remove the extra gsi_end_p check. * ubsan.c: Include builtins.h. (ubsan_expand_bounds_ifn): Change return type to bool, always return true. (ubsan_expand_null_ifn): Change return type to bool, change argument to gimple_stmt_iterator *. Handle both null and alignment sanitization, take type from ckind argument's type rather than first argument. (instrument_member_call): Removed. (instrument_mem_ref): Remove t argument, add mem and base arguments. Handle both null and alignment sanitization, don't say whole struct access is member access. Build 3 argument IFN_UBSAN_NULL call instead of 2 argument. (instrument_null): Adjust instrument_mem_ref caller. Don't instrument calls here. (pass_ubsan::gate, pass_ubsan::execute): Handle SANITIZE_ALIGNMENT like SANITIZE_NULL. * stor-layout.c (min_align_of_type): New function. * flag-types.h (enum sanitize_code): Add SANITIZE_ALIGNMENT. Or it into SANITIZE_UNDEFINED. * doc/invoke.texi (-fsanitize=alignment): Document. cp/ * cp-gimplify.c (cp_genericize_r): For -fsanitize=null and/or -fsanitize=alignment call ubsan_maybe_instrument_reference for casts to REFERENCE_TYPE and ubsan_maybe_instrument_member_call for calls to member functions. c-family/ * c-common.h (min_align_of_type): Removed prototype. * c-common.c (min_align_of_type): Removed. * c-ubsan.h (ubsan_maybe_instrument_reference, ubsan_maybe_instrument_member_call): New prototypes. * c-ubsan.c: Include stor-layout.h and builtins.h. (ubsan_maybe_instrument_reference_or_call, ubsan_maybe_instrument_reference, ubsan_maybe_instrument_call): New functions. testsuite/ * c-c++-common/ubsan/align-1.c: New test. * c-c++-common/ubsan/align-2.c: New test. * c-c++-common/ubsan/align-3.c: New test. * c-c++-common/ubsan/align-4.c: New test. * c-c++-common/ubsan/align-5.c: New test. * c-c++-common/ubsan/attrib-4.c: New test. * g++.dg/ubsan/align-1.C: New test. * g++.dg/ubsan/align-2.C: New test. * g++.dg/ubsan/align-3.C: New test. * g++.dg/ubsan/attrib-1.C: New test. * g++.dg/ubsan/null-1.C: New test. * g++.dg/ubsan/null-2.C: New test. From-SVN: r213406
2014-08-01 09:52:43 +02:00
tree align = gimple_call_arg (stmt, 2);
tree check_align = NULL_TREE;
bool check_null;
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
basic_block cur_bb = gsi_bb (gsi);
gimple *g;
opts.c (common_handle_option): Handle -fsanitize=alignment. * opts.c (common_handle_option): Handle -fsanitize=alignment. * ubsan.h (enum ubsan_null_ckind): Add UBSAN_CTOR_CALL. (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn): Change return type to bool. * stor-layout.h (min_align_of_type): New prototype. * asan.c (pass_sanopt::execute): Don't perform gsi_next if ubsan_expand* told us not to do it. Remove the extra gsi_end_p check. * ubsan.c: Include builtins.h. (ubsan_expand_bounds_ifn): Change return type to bool, always return true. (ubsan_expand_null_ifn): Change return type to bool, change argument to gimple_stmt_iterator *. Handle both null and alignment sanitization, take type from ckind argument's type rather than first argument. (instrument_member_call): Removed. (instrument_mem_ref): Remove t argument, add mem and base arguments. Handle both null and alignment sanitization, don't say whole struct access is member access. Build 3 argument IFN_UBSAN_NULL call instead of 2 argument. (instrument_null): Adjust instrument_mem_ref caller. Don't instrument calls here. (pass_ubsan::gate, pass_ubsan::execute): Handle SANITIZE_ALIGNMENT like SANITIZE_NULL. * stor-layout.c (min_align_of_type): New function. * flag-types.h (enum sanitize_code): Add SANITIZE_ALIGNMENT. Or it into SANITIZE_UNDEFINED. * doc/invoke.texi (-fsanitize=alignment): Document. cp/ * cp-gimplify.c (cp_genericize_r): For -fsanitize=null and/or -fsanitize=alignment call ubsan_maybe_instrument_reference for casts to REFERENCE_TYPE and ubsan_maybe_instrument_member_call for calls to member functions. c-family/ * c-common.h (min_align_of_type): Removed prototype. * c-common.c (min_align_of_type): Removed. * c-ubsan.h (ubsan_maybe_instrument_reference, ubsan_maybe_instrument_member_call): New prototypes. * c-ubsan.c: Include stor-layout.h and builtins.h. (ubsan_maybe_instrument_reference_or_call, ubsan_maybe_instrument_reference, ubsan_maybe_instrument_call): New functions. testsuite/ * c-c++-common/ubsan/align-1.c: New test. * c-c++-common/ubsan/align-2.c: New test. * c-c++-common/ubsan/align-3.c: New test. * c-c++-common/ubsan/align-4.c: New test. * c-c++-common/ubsan/align-5.c: New test. * c-c++-common/ubsan/attrib-4.c: New test. * g++.dg/ubsan/align-1.C: New test. * g++.dg/ubsan/align-2.C: New test. * g++.dg/ubsan/align-3.C: New test. * g++.dg/ubsan/attrib-1.C: New test. * g++.dg/ubsan/null-1.C: New test. * g++.dg/ubsan/null-2.C: New test. From-SVN: r213406
2014-08-01 09:52:43 +02:00
if (!integer_zerop (align))
{
unsigned int ptralign = get_pointer_alignment (ptr) / BITS_PER_UNIT;
if (compare_tree_int (align, ptralign) == 1)
{
gimple-expr.h (create_tmp_var_raw, [...]): Add default NULL value to last argument. * gimple-expr.h (create_tmp_var_raw, create_tmp_var, create_tmp_reg): Add default NULL value to last argument. * tree-ssanames.h (make_ssa_name, copy_ssa_name): Likewise. * gimple-low.c (lower_builtin_posix_memalign): Remove NULL last argument from create_tmp_var_raw, create_tmp_var, create_tmp_reg, make_ssa_name and copy_ssa_name calls. * tree-ssa-strlen.c (get_string_length): Likewise. * tree-emutls.c (gen_emutls_addr, lower_emutls_1): Likewise. * tree-ssa-phiprop.c (phiprop_insert_phi): Likewise. * tree-vect-slp.c (vect_get_constant_vectors): Likewise. * ipa-prop.c (ipa_modify_call_arguments): Likewise. * tree-ssa-forwprop.c (simplify_rotate): Likewise. * tree-ssa-ccp.c (fold_builtin_alloca_with_align): Likewise. * asan.c (build_shadow_mem_access, maybe_create_ssa_name, maybe_cast_to_ptrmode, asan_expand_check_ifn): Likewise. * tsan.c (instrument_expr, instrument_builtin_call, instrument_func_entry): Likewise. * varpool.c (add_new_static_var): Likewise. * tree-loop-distribution.c (generate_memset_builtin): Likewise. * gimplify.c (internal_get_tmp_var, gimplify_return_expr, gimplify_modify_expr_to_memcpy, gimplify_modify_expr_to_memset, gimplify_init_ctor_eval_range, gimplify_init_constructor, gimplify_omp_atomic, gimplify_expr): Likewise. * gimple-builder.c (build_assign, build_type_cast): Likewise. * tree-vect-loop-manip.c (slpeel_update_phi_nodes_for_guard1, slpeel_update_phi_nodes_for_guard2, slpeel_tree_peel_loop_to_edge, vect_loop_versioning): Likewise. * tree-if-conv.c (version_loop_for_if_conversion): Likewise. * gimple-match-head.c (maybe_push_res_to_seq): Likewise. * tree-vect-patterns.c (vect_handle_widen_op_by_const, vect_recog_widen_mult_pattern, vect_operation_fits_smaller_type, vect_recog_over_widening_pattern): Likewise. * tree-sra.c (build_ref_for_offset, create_access_replacement): Likewise. * tree-cfg.c (make_blocks): Likewise. * tree-eh.c (lower_eh_constructs_2, lower_resx, lower_eh_dispatch): Likewise. * tree-ssa-propagate.c (update_call_from_tree): Likewise. * tree-complex.c (get_component_ssa_name, expand_complex_div_wide): Likewise. * tree-ssa-math-opts.c (build_and_insert_cast): Likewise. * tree-tailcall.c (update_accumulator_with_ops): Likewise. * tree-predcom.c (initialize_root_vars, initialize_root_vars_lm, execute_load_motion, reassociate_to_the_same_stmt): Likewise. * tree-ssa-reassoc.c (build_and_add_sum, optimize_range_tests_to_bit_test, update_ops, maybe_optimize_range_tests, rewrite_expr_tree, linearize_expr, negate_value, repropagate_negates): Likewise. * tree-vect-loop.c (vect_is_simple_reduction_1, vect_create_epilog_for_reduction): Likewise. * ipa-split.c (split_function): Likewise. * tree-inline.c (remap_ssa_name, setup_one_parameter, declare_return_variable, tree_function_versioning): Likewise. * tree-cfgcleanup.c (fixup_noreturn_call): Likewise. * cfgexpand.c (update_alias_info_with_stack_vars, expand_used_vars): Likewise. * tree-ssa-phiopt.c (conditional_replacement, abs_replacement, neg_replacement): Likewise. * gimplify-me.c (force_gimple_operand_1, gimple_regimplify_operands): Likewise. * tree-vrp.c (simplify_truth_ops_using_ranges, simplify_float_conversion_using_ranges, simplify_internal_call_using_ranges): Likewise. * tree-switch-conversion.c (emit_case_bit_tests, build_one_array, build_arrays, gen_def_assigns): Likewise. * gimple-fold.c (gimple_fold_builtin_memory_op, gimple_fold_builtin_strcat, gimple_fold_call, gimple_build): Likewise. * tree-vect-generic.c (expand_vector_divmod, optimize_vector_constructor): Likewise. * ubsan.c (ubsan_encode_value, ubsan_expand_null_ifn, ubsan_expand_objsize_ifn, instrument_si_overflow, instrument_bool_enum_load, instrument_nonnull_arg): Likewise. * tree-outof-ssa.c (insert_backedge_copies): Likewise. * tree-ssa-loop-manip.c (create_iv, tree_transform_and_unroll_loop): Likewise. * omp-low.c (scan_omp_parallel, lower_rec_simd_input_clauses, lower_rec_input_clauses, lower_lastprivate_clauses, expand_parallel_call, expand_omp_for_static_chunk, expand_omp_atomic_pipeline, expand_omp_target, maybe_add_implicit_barrier_cancel, lower_omp_single_simple, lower_omp_critical, lower_omp_for, task_copyfn_copy_decl, lower_depend_clauses, lower_omp_target, lower_omp_1, ipa_simd_modify_stmt_ops, simd_clone_adjust): Likewise. * tree-parloops.c (take_address_of, create_phi_for_local_result, create_call_for_reduction_1, separate_decls_in_region, create_parallel_loop): Likewise. * graphite-sese-to-poly.c (rewrite_cross_bb_scalar_dependence, handle_scalar_deps_crossing_scop_limits): Likewise. * trans-mem.c (lower_transaction, build_tm_load, build_tm_store, expand_assign_tm, expand_call_tm, expand_transaction, ipa_tm_insert_gettmclone_call): Likewise. * tree-vect-data-refs.c (bump_vector_ptr, vect_setup_realignment): Likewise. * tree-vect-stmts.c (vect_init_vector, vectorizable_mask_load_store, vectorizable_call, vectorizable_simd_clone_call, vectorizable_conversion, vectorizable_store, permute_vec_elements, vectorizable_load): Likewise. c/ * c-typeck.c (convert_lvalue_to_rvalue, build_atomic_assign, c_finish_stmt_expr): Remove NULL last argument from create_tmp_var_raw and create_tmp_var calls. * c-array-notation.c (fix_builtin_array_notation_fn, build_array_notation_expr, fix_conditional_array_notations_1, fix_array_notation_expr, fix_array_notation_call_expr): Likewise. cp/ * cp-gimplify.c (cxx_omp_clause_apply_fn): Remove NULL last argument from create_tmp_var calls. c-family/ * c-common.c (convert_vector_to_pointer_for_subscript): Remove NULL last argument from create_tmp_var_raw and create_tmp_var calls. * cilk.c (gimplify_cilk_spawn): Likewise. * c-omp.c (c_finish_omp_atomic): Likewise. fortran/ * trans-openmp.c (gfc_omp_finish_clause, gfc_trans_omp_array_reduction_or_udr, gfc_trans_omp_atomic): Remove NULL last argument from create_tmp_var_raw and create_tmp_var calls. From-SVN: r218181
2014-11-29 12:35:30 +01:00
check_align = make_ssa_name (pointer_sized_int_node);
gimple.h (gimple_build_assign_stat): Remove prototype. * gimple.h (gimple_build_assign_stat): Remove prototype. (gimple_build_assign): Remove define. Add overload prototypes with tree lhs and either a tree rhs, or enum tree_code and 1, 2 or 3 tree operands. * gimple.c (gimple_build_assign_stat): Renamed to... (gimple_build_assign): ... this. Add overloads with enum tree_code and 1, 2 or 3 tree operands. (gimple_build_assign_with_ops): Remove 1 and 2 operand overloads. Rename the 3 operand overload to ... (gimple_build_assign_1): ... this. Make it static inline. * tree-ssa-strlen.c (get_string_length): Use gimple_build_assign instead of gimple_build_assign_with_ops, swap the order of first two arguments and adjust formatting where necessary. * tree-vect-slp.c (vect_get_constant_vectors, vect_create_mask_and_perm): Likewise. * tree-ssa-forwprop.c (simplify_rotate): Likewise. * asan.c (build_shadow_mem_access, maybe_create_ssa_name, maybe_cast_to_ptrmode, asan_expand_check_ifn): Likewise. * tsan.c (instrument_builtin_call): Likewise. * tree-chkp.c (chkp_compute_bounds_for_assignment, chkp_generate_extern_var_bounds): Likewise. * tree-loop-distribution.c (generate_memset_builtin): Likewise. * tree-ssa-loop-im.c (rewrite_reciprocal): Likewise. * gimple-builder.c (build_assign, build_type_cast): Likewise. * tree-vect-loop-manip.c (vect_create_cond_for_align_checks): Likewise. * value-prof.c (gimple_divmod_fixed_value, gimple_mod_pow2, gimple_mod_subtract): Likewise. * gimple-match-head.c (maybe_push_res_to_seq): Likewise. * tree-vect-patterns.c (vect_recog_dot_prod_pattern, vect_recog_sad_pattern, vect_handle_widen_op_by_const, vect_recog_widen_mult_pattern, vect_recog_pow_pattern, vect_recog_widen_sum_pattern, vect_operation_fits_smaller_type, vect_recog_over_widening_pattern, vect_recog_widen_shift_pattern, vect_recog_rotate_pattern, vect_recog_vector_vector_shift_pattern, vect_recog_divmod_pattern, vect_recog_mixed_size_cond_pattern, adjust_bool_pattern_cast, adjust_bool_pattern, vect_recog_bool_pattern): Likewise. * gimple-ssa-strength-reduction.c (create_add_on_incoming_edge, insert_initializers, introduce_cast_before_cand, replace_one_candidate): Likewise. * tree-ssa-math-opts.c (insert_reciprocals, powi_as_mults_1, powi_as_mults, build_and_insert_binop, build_and_insert_cast, pass_cse_sincos::execute, bswap_replace, convert_mult_to_fma): Likewise. * tree-tailcall.c (adjust_return_value_with_ops, update_accumulator_with_ops): Likewise. * tree-predcom.c (reassociate_to_the_same_stmt): Likewise. * tree-ssa-reassoc.c (build_and_add_sum, optimize_range_tests_to_bit_test, update_ops, maybe_optimize_range_tests, rewrite_expr_tree, linearize_expr, negate_value, repropagate_negates, attempt_builtin_powi, reassociate_bb): Likewise. * tree-vect-loop.c (vect_is_simple_reduction_1, get_initial_def_for_induction, vect_create_epilog_for_reduction): Likewise. * ipa-split.c (split_function): Likewise. * tree-ssa-phiopt.c (conditional_replacement, minmax_replacement, abs_replacement, neg_replacement): Likewise. * tree-profile.c (gimple_gen_edge_profiler): Likewise. * tree-vrp.c (simplify_truth_ops_using_ranges, simplify_float_conversion_using_ranges, simplify_internal_call_using_ranges): Likewise. * gimple-fold.c (rewrite_to_defined_overflow, gimple_build): Likewise. * tree-vect-generic.c (expand_vector_divmod, optimize_vector_constructor): Likewise. * ubsan.c (ubsan_expand_null_ifn, ubsan_expand_objsize_ifn, instrument_bool_enum_load): Likewise. * tree-ssa-loop-manip.c (create_iv): Likewise. * omp-low.c (lower_rec_input_clauses, expand_omp_for_generic, expand_omp_for_static_nochunk, expand_omp_for_static_chunk, expand_cilk_for, simd_clone_adjust): Likewise. * trans-mem.c (expand_transaction): Likewise. * tree-vect-data-refs.c (bump_vector_ptr, vect_permute_store_chain, vect_setup_realignment, vect_permute_load_chain, vect_shift_permute_load_chain): Likewise. * tree-vect-stmts.c (vect_init_vector, vectorizable_mask_load_store, vectorizable_simd_clone_call, vect_gen_widened_results_half, vect_create_vectorized_demotion_stmts, vectorizable_conversion, vectorizable_shift, vectorizable_operation, vectorizable_store, permute_vec_elements, vectorizable_load): Likewise. From-SVN: r218216
2014-12-01 14:58:10 +01:00
g = gimple_build_assign (check_align, NOP_EXPR, ptr);
opts.c (common_handle_option): Handle -fsanitize=alignment. * opts.c (common_handle_option): Handle -fsanitize=alignment. * ubsan.h (enum ubsan_null_ckind): Add UBSAN_CTOR_CALL. (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn): Change return type to bool. * stor-layout.h (min_align_of_type): New prototype. * asan.c (pass_sanopt::execute): Don't perform gsi_next if ubsan_expand* told us not to do it. Remove the extra gsi_end_p check. * ubsan.c: Include builtins.h. (ubsan_expand_bounds_ifn): Change return type to bool, always return true. (ubsan_expand_null_ifn): Change return type to bool, change argument to gimple_stmt_iterator *. Handle both null and alignment sanitization, take type from ckind argument's type rather than first argument. (instrument_member_call): Removed. (instrument_mem_ref): Remove t argument, add mem and base arguments. Handle both null and alignment sanitization, don't say whole struct access is member access. Build 3 argument IFN_UBSAN_NULL call instead of 2 argument. (instrument_null): Adjust instrument_mem_ref caller. Don't instrument calls here. (pass_ubsan::gate, pass_ubsan::execute): Handle SANITIZE_ALIGNMENT like SANITIZE_NULL. * stor-layout.c (min_align_of_type): New function. * flag-types.h (enum sanitize_code): Add SANITIZE_ALIGNMENT. Or it into SANITIZE_UNDEFINED. * doc/invoke.texi (-fsanitize=alignment): Document. cp/ * cp-gimplify.c (cp_genericize_r): For -fsanitize=null and/or -fsanitize=alignment call ubsan_maybe_instrument_reference for casts to REFERENCE_TYPE and ubsan_maybe_instrument_member_call for calls to member functions. c-family/ * c-common.h (min_align_of_type): Removed prototype. * c-common.c (min_align_of_type): Removed. * c-ubsan.h (ubsan_maybe_instrument_reference, ubsan_maybe_instrument_member_call): New prototypes. * c-ubsan.c: Include stor-layout.h and builtins.h. (ubsan_maybe_instrument_reference_or_call, ubsan_maybe_instrument_reference, ubsan_maybe_instrument_call): New functions. testsuite/ * c-c++-common/ubsan/align-1.c: New test. * c-c++-common/ubsan/align-2.c: New test. * c-c++-common/ubsan/align-3.c: New test. * c-c++-common/ubsan/align-4.c: New test. * c-c++-common/ubsan/align-5.c: New test. * c-c++-common/ubsan/attrib-4.c: New test. * g++.dg/ubsan/align-1.C: New test. * g++.dg/ubsan/align-2.C: New test. * g++.dg/ubsan/align-3.C: New test. * g++.dg/ubsan/attrib-1.C: New test. * g++.dg/ubsan/null-1.C: New test. * g++.dg/ubsan/null-2.C: New test. From-SVN: r213406
2014-08-01 09:52:43 +02:00
gimple_set_location (g, loc);
gsi_insert_before (&gsi, g, GSI_SAME_STMT);
}
}
check_null = (flag_sanitize & SANITIZE_NULL) != 0;
if (check_align == NULL_TREE && !check_null)
{
gsi_remove (gsip, true);
/* Unlink the UBSAN_NULLs vops before replacing it. */
unlink_stmt_vdef (stmt);
return true;
}
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
/* Split the original block holding the pointer dereference. */
edge e = split_block (cur_bb, stmt);
/* Get a hold on the 'condition block', the 'then block' and the
'else block'. */
basic_block cond_bb = e->src;
basic_block fallthru_bb = e->dest;
basic_block then_bb = create_empty_bb (cond_bb);
cfgexpand.c (expand_gimple_cond): Remove check for current_loops. 2014-06-06 Richard Biener <rguenther@suse.de> * cfgexpand.c (expand_gimple_cond): Remove check for current_loops. (construct_init_block): Likewise. (construct_exit_block): Likewise. (pass_expand::execute): Likewise. * graphite.c (graphite_transforms): Replace check for current_loops with a check for > 1 loops. (pass_graphite_transforms::execute): Adjust. * ipa-split.c (split_function): Remove check for current_loops. * omp-low.c (expand_parallel_call): Likewise. (expand_omp_for_init_counts): Likewise. (extract_omp_for_update_vars): Likewise. (expand_omp_for_generic): Likewise. (expand_omp_sections): Likewise. (expand_omp_target): Likewise. * tracer.c (tail_duplicate): Likewise. (pass_tracer::execute): Likewise. * trans-mem.c (expand_transaction): Likewise. * tree-complex.c (expand_complex_div_wide): Likewise. * tree-eh.c (lower_resx): Likewise. (cleanup_empty_eh_merge_phis): Likewise. * tree-predcom.c (run_tree_predictive_commoning): Replace check for current_loops with a check for > 1 loops. (pass_predcom::execute): Adjust. * tree-scalar-evolution.c (scev_reset): Remove check for current_loops. * tree-ssa-copy.c (copy_prop_visit_phi_node): Likewise. * tree-ssa-dom.c (pass_phi_only_cprop::execute): Likewise. * tree-ssa-tail-merge.c (tail_merge_optimize): Likewise. * tree-ssa-threadupdate.c (thread_through_all_blocks): Likewise. * tree-switch-conversion.c (process_switch): Likewise. * tree-tailcall.c (tree_optimize_tail_calls_1): Likewise. * tree-vrp.c (vrp_visit_phi_node): Likewise. (execute_vrp): Likewise. * ubsan.c (ubsan_expand_null_ifn): Likewise. From-SVN: r211306
2014-06-06 09:38:07 +02:00
add_bb_to_loop (then_bb, cond_bb->loop_father);
loops_state_set (LOOPS_NEED_FIXUP);
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
/* Make an edge coming from the 'cond block' into the 'then block';
this edge is unlikely taken, so set up the probability accordingly. */
e = make_edge (cond_bb, then_bb, EDGE_TRUE_VALUE);
e->probability = PROB_VERY_UNLIKELY;
/* Connect 'then block' with the 'else block'. This is needed
as the ubsan routines we call in the 'then block' are not noreturn.
The 'then block' only has one outcoming edge. */
make_single_succ_edge (then_bb, fallthru_bb, EDGE_FALLTHRU);
/* Set up the fallthrough basic block. */
e = find_edge (cond_bb, fallthru_bb);
e->flags = EDGE_FALSE_VALUE;
e->count = cond_bb->count;
e->probability = REG_BR_PROB_BASE - PROB_VERY_UNLIKELY;
/* Update dominance info for the newly created then_bb; note that
fallthru_bb's dominance info has already been updated by
opts.c (common_handle_option): Handle -fsanitize=alignment. * opts.c (common_handle_option): Handle -fsanitize=alignment. * ubsan.h (enum ubsan_null_ckind): Add UBSAN_CTOR_CALL. (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn): Change return type to bool. * stor-layout.h (min_align_of_type): New prototype. * asan.c (pass_sanopt::execute): Don't perform gsi_next if ubsan_expand* told us not to do it. Remove the extra gsi_end_p check. * ubsan.c: Include builtins.h. (ubsan_expand_bounds_ifn): Change return type to bool, always return true. (ubsan_expand_null_ifn): Change return type to bool, change argument to gimple_stmt_iterator *. Handle both null and alignment sanitization, take type from ckind argument's type rather than first argument. (instrument_member_call): Removed. (instrument_mem_ref): Remove t argument, add mem and base arguments. Handle both null and alignment sanitization, don't say whole struct access is member access. Build 3 argument IFN_UBSAN_NULL call instead of 2 argument. (instrument_null): Adjust instrument_mem_ref caller. Don't instrument calls here. (pass_ubsan::gate, pass_ubsan::execute): Handle SANITIZE_ALIGNMENT like SANITIZE_NULL. * stor-layout.c (min_align_of_type): New function. * flag-types.h (enum sanitize_code): Add SANITIZE_ALIGNMENT. Or it into SANITIZE_UNDEFINED. * doc/invoke.texi (-fsanitize=alignment): Document. cp/ * cp-gimplify.c (cp_genericize_r): For -fsanitize=null and/or -fsanitize=alignment call ubsan_maybe_instrument_reference for casts to REFERENCE_TYPE and ubsan_maybe_instrument_member_call for calls to member functions. c-family/ * c-common.h (min_align_of_type): Removed prototype. * c-common.c (min_align_of_type): Removed. * c-ubsan.h (ubsan_maybe_instrument_reference, ubsan_maybe_instrument_member_call): New prototypes. * c-ubsan.c: Include stor-layout.h and builtins.h. (ubsan_maybe_instrument_reference_or_call, ubsan_maybe_instrument_reference, ubsan_maybe_instrument_call): New functions. testsuite/ * c-c++-common/ubsan/align-1.c: New test. * c-c++-common/ubsan/align-2.c: New test. * c-c++-common/ubsan/align-3.c: New test. * c-c++-common/ubsan/align-4.c: New test. * c-c++-common/ubsan/align-5.c: New test. * c-c++-common/ubsan/attrib-4.c: New test. * g++.dg/ubsan/align-1.C: New test. * g++.dg/ubsan/align-2.C: New test. * g++.dg/ubsan/align-3.C: New test. * g++.dg/ubsan/attrib-1.C: New test. * g++.dg/ubsan/null-1.C: New test. * g++.dg/ubsan/null-2.C: New test. From-SVN: r213406
2014-08-01 09:52:43 +02:00
split_block. */
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
if (dom_info_available_p (CDI_DOMINATORS))
set_immediate_dominator (CDI_DOMINATORS, then_bb, cond_bb);
/* Put the ubsan builtin call into the newly created BB. */
re PR sanitizer/60275 ([UBSAN] Add -f[no-]sanitize-recover/-fsanitize-undefined-trap-on-error to make UBSAN's runtime errors fatal) PR sanitizer/60275 * common.opt (fsanitize-recover, fsanitize-undefined-trap-on-error): New options. * gcc.c (sanitize_spec_function): Don't return "" for "undefined" if flag_sanitize_undefined_trap_on_error. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_DIVREM_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_SHIFT_OUT_OF_BOUNDS_ABORT, BUILT_IN_UBSAN_HANDLE_VLA_BOUND_NOT_POSITIVE_ABORT, BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT, BUILT_IN_UBSAN_HANDLE_ADD_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_SUB_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_MUL_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_NEGATE_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_LOAD_INVALID_VALUE_ABORT): New builtins. * ubsan.c (ubsan_instrument_unreachable): Return __builtin_trap () if flag_sanitize_undefined_trap_on_error. (ubsan_expand_null_ifn): Emit __builtin_trap () if flag_sanitize_undefined_trap_on_error and __ubsan_handle_type_mismatch_abort if !flag_sanitize_recover. (ubsan_expand_null_ifn, ubsan_build_overflow_builtin, instrument_bool_enum_load): Emit __builtin_trap () if flag_sanitize_undefined_trap_on_error and __builtin_handle_*_abort () if !flag_sanitize_recover. * doc/invoke.texi (-fsanitize-recover, -fsanitize-undefined-trap-on-error): Document. c-family/ * c-ubsan.c (ubsan_instrument_return): Return __builtin_trap () if flag_sanitize_undefined_trap_on_error. (ubsan_instrument_division, ubsan_instrument_shift, ubsan_instrument_vla): Likewise. Use __ubsan_handle_*_abort () if !flag_sanitize_recover. testsuite/ * g++.dg/ubsan/return-2.C: Revert 2014-03-24 changes, add -fno-sanitize-recover to dg-options. * g++.dg/ubsan/cxx11-shift-1.C: Remove c++11 target restriction, add -std=c++11 to dg-options. * g++.dg/ubsan/cxx11-shift-2.C: Likewise. * g++.dg/ubsan/cxx1y-vla.C: Remove c++1y target restriction, add -std=c++1y to dg-options. * c-c++-common/ubsan/undefined-1.c: Revert 2014-03-24 changes, add -fno-sanitize-recover to dg-options. * c-c++-common/ubsan/overflow-sub-1.c: Likewise. * c-c++-common/ubsan/vla-4.c: Likewise. * c-c++-common/ubsan/pr59503.c: Likewise. * c-c++-common/ubsan/vla-3.c: Likewise. * c-c++-common/ubsan/save-expr-1.c: Likewise. * c-c++-common/ubsan/overflow-add-1.c: Likewise. * c-c++-common/ubsan/shift-3.c: Likewise. * c-c++-common/ubsan/overflow-1.c: Likewise. * c-c++-common/ubsan/overflow-negate-2.c: Likewise. * c-c++-common/ubsan/vla-2.c: Likewise. * c-c++-common/ubsan/overflow-mul-1.c: Likewise. * c-c++-common/ubsan/pr60613-1.c: Likewise. * c-c++-common/ubsan/shift-6.c: Likewise. * c-c++-common/ubsan/overflow-mul-3.c: Likewise. * c-c++-common/ubsan/overflow-add-3.c: New test. * c-c++-common/ubsan/overflow-add-4.c: New test. * c-c++-common/ubsan/div-by-zero-6.c: New test. * c-c++-common/ubsan/div-by-zero-7.c: New test. From-SVN: r209672
2014-04-23 10:20:12 +02:00
if (flag_sanitize_undefined_trap_on_error)
g = gimple_build_call (builtin_decl_implicit (BUILT_IN_TRAP), 0);
else
{
enum built_in_function bcode
New syntax for -fsanitize-recover. 2014-10-22 Jakub Jelinek <jakub@redhat.com> Yury Gribov <y.gribov@samsung.com> gcc/ * common.opt (flag_sanitize_recover): New variable. (fsanitize-recover): Remove Var/Init, deprecate. (fsanitize-recover=): New option. * doc/invoke.texi (fsanitize-recover): Update docs. * opts.c (finish_options): Use opts->x_flag_sanitize instead of flag_sanitize. Prohibit -fsanitize-recover for anything besides UBSan. Formatting. (common_handle_option): Handle OPT_fsanitize_recover_ and OPT_fsanitize_recover. Use opts->x_flag_sanitize instead of flag_sanitize. * asan.c (pass_sanopt::execute): Fix up formatting. * ubsan.c (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn, ubsan_expand_objsize_ifn, ubsan_build_overflow_builtin, instrument_bool_enum_load, ubsan_instrument_float_cast, instrument_nonnull_arg, instrument_nonnull_return): Check bits in flag_sanitize_recover bitmask instead of flag_sanitize_recover as bool flag. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division, ubsan_instrument_shift, ubsan_instrument_vla): Check bits in flag_sanitize_recover bitmask instead of flag_sanitize_recover as bool flag. gcc/testsuite/ * c-c++-common/ubsan/align-1.c: Update cmdline options. * c-c++-common/ubsan/align-3.c: Likewise. * c-c++-common/ubsan/bounds-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-7.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-10.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-7.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-8.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-9.c: Likewise. * c-c++-common/ubsan/nonnull-2.c: Likewise. * c-c++-common/ubsan/nonnull-3.c: Likewise. * c-c++-common/ubsan/object-size-3.c: Likewise. * c-c++-common/ubsan/overflow-1.c: Likewise. * c-c++-common/ubsan/overflow-add-1.c: Likewise. * c-c++-common/ubsan/overflow-add-3.c: Likewise. * c-c++-common/ubsan/overflow-mul-1.c: Likewise. * c-c++-common/ubsan/overflow-mul-3.c: Likewise. * c-c++-common/ubsan/overflow-negate-2.c: Likewise. * c-c++-common/ubsan/overflow-sub-1.c: Likewise. * c-c++-common/ubsan/pr59503.c: Likewise. * c-c++-common/ubsan/pr60613-1.c: Likewise. * c-c++-common/ubsan/save-expr-1.c: Likewise. * c-c++-common/ubsan/shift-3.c: Likewise. * c-c++-common/ubsan/shift-6.c: Likewise. * c-c++-common/ubsan/undefined-1.c: Likewise. * c-c++-common/ubsan/vla-2.c: Likewise. * c-c++-common/ubsan/vla-3.c: Likewise. * c-c++-common/ubsan/vla-4.c: Likewise. * g++.dg/ubsan/cxx11-shift-1.C: Likewise. * g++.dg/ubsan/return-2.C: Likewise. * c-c++-common/ubsan/recovery-1.c: New test. * c-c++-common/ubsan/recovery-2.c: New test. * c-c++-common/ubsan/recovery-3.c: New test. * c-c++-common/ubsan/recovery-common.inc: New file. Co-Authored-By: Yury Gribov <y.gribov@samsung.com> From-SVN: r216552
2014-10-22 13:07:10 +02:00
= (flag_sanitize_recover & ((check_align ? SANITIZE_ALIGNMENT : 0)
| (check_null ? SANITIZE_NULL : 0)))
re PR sanitizer/60275 ([UBSAN] Add -f[no-]sanitize-recover/-fsanitize-undefined-trap-on-error to make UBSAN's runtime errors fatal) PR sanitizer/60275 * common.opt (fsanitize-recover, fsanitize-undefined-trap-on-error): New options. * gcc.c (sanitize_spec_function): Don't return "" for "undefined" if flag_sanitize_undefined_trap_on_error. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_DIVREM_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_SHIFT_OUT_OF_BOUNDS_ABORT, BUILT_IN_UBSAN_HANDLE_VLA_BOUND_NOT_POSITIVE_ABORT, BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT, BUILT_IN_UBSAN_HANDLE_ADD_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_SUB_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_MUL_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_NEGATE_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_LOAD_INVALID_VALUE_ABORT): New builtins. * ubsan.c (ubsan_instrument_unreachable): Return __builtin_trap () if flag_sanitize_undefined_trap_on_error. (ubsan_expand_null_ifn): Emit __builtin_trap () if flag_sanitize_undefined_trap_on_error and __ubsan_handle_type_mismatch_abort if !flag_sanitize_recover. (ubsan_expand_null_ifn, ubsan_build_overflow_builtin, instrument_bool_enum_load): Emit __builtin_trap () if flag_sanitize_undefined_trap_on_error and __builtin_handle_*_abort () if !flag_sanitize_recover. * doc/invoke.texi (-fsanitize-recover, -fsanitize-undefined-trap-on-error): Document. c-family/ * c-ubsan.c (ubsan_instrument_return): Return __builtin_trap () if flag_sanitize_undefined_trap_on_error. (ubsan_instrument_division, ubsan_instrument_shift, ubsan_instrument_vla): Likewise. Use __ubsan_handle_*_abort () if !flag_sanitize_recover. testsuite/ * g++.dg/ubsan/return-2.C: Revert 2014-03-24 changes, add -fno-sanitize-recover to dg-options. * g++.dg/ubsan/cxx11-shift-1.C: Remove c++11 target restriction, add -std=c++11 to dg-options. * g++.dg/ubsan/cxx11-shift-2.C: Likewise. * g++.dg/ubsan/cxx1y-vla.C: Remove c++1y target restriction, add -std=c++1y to dg-options. * c-c++-common/ubsan/undefined-1.c: Revert 2014-03-24 changes, add -fno-sanitize-recover to dg-options. * c-c++-common/ubsan/overflow-sub-1.c: Likewise. * c-c++-common/ubsan/vla-4.c: Likewise. * c-c++-common/ubsan/pr59503.c: Likewise. * c-c++-common/ubsan/vla-3.c: Likewise. * c-c++-common/ubsan/save-expr-1.c: Likewise. * c-c++-common/ubsan/overflow-add-1.c: Likewise. * c-c++-common/ubsan/shift-3.c: Likewise. * c-c++-common/ubsan/overflow-1.c: Likewise. * c-c++-common/ubsan/overflow-negate-2.c: Likewise. * c-c++-common/ubsan/vla-2.c: Likewise. * c-c++-common/ubsan/overflow-mul-1.c: Likewise. * c-c++-common/ubsan/pr60613-1.c: Likewise. * c-c++-common/ubsan/shift-6.c: Likewise. * c-c++-common/ubsan/overflow-mul-3.c: Likewise. * c-c++-common/ubsan/overflow-add-3.c: New test. * c-c++-common/ubsan/overflow-add-4.c: New test. * c-c++-common/ubsan/div-by-zero-6.c: New test. * c-c++-common/ubsan/div-by-zero-7.c: New test. From-SVN: r209672
2014-04-23 10:20:12 +02:00
? BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH
: BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT;
tree fn = builtin_decl_implicit (bcode);
asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * flag-types.h (enum sanitize_code): Add SANITIZE_BOUNDS and or it into SANITIZE_UNDEFINED. * doc/invoke.texi: Describe -fsanitize=bounds. * gimplify.c (gimplify_call_expr): Add gimplification of internal functions created in the FEs. * internal-fn.c: Move "internal-fn.h" after "tree.h". (expand_UBSAN_BOUNDS): New function. * internal-fn.def (UBSAN_BOUNDS): New internal function. * internal-fn.h: Don't define internal functions here. * opts.c (common_handle_option): Add -fsanitize=bounds. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS, BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS_ABORT): Add. * tree-core.h: Define internal functions here. (struct tree_base): Add ifn field. * tree-pretty-print.c: Include "internal-fn.h". (dump_generic_node): Handle functions without CALL_EXPR_FN. * tree.c (get_callee_fndecl): Likewise. (build_call_expr_internal_loc): New function. * tree.def (CALL_EXPR): Update description. * tree.h (CALL_EXPR_IFN): Define. (build_call_expr_internal_loc): Declare. * ubsan.c (get_ubsan_type_info_for_type): Return 0 for non-arithmetic types. (ubsan_type_descriptor): Change bool parameter to enum ubsan_print_style. Adjust the code. Add handling of UBSAN_PRINT_ARRAY. (ubsan_expand_bounds_ifn): New function. (ubsan_expand_null_ifn): Adjust ubsan_type_descriptor call. (ubsan_build_overflow_builtin): Likewise. (instrument_bool_enum_load): Likewise. (ubsan_instrument_float_cast): Likewise. * ubsan.h (enum ubsan_print_style): New enum. (ubsan_expand_bounds_ifn): Declare. (ubsan_type_descriptor): Adjust declaration. Use a default parameter. c-family/ * c-gimplify.c: Include "c-ubsan.h" and "pointer-set.h". (ubsan_walk_array_refs_r): New function. (c_genericize): Instrument array bounds. * c-ubsan.c: Include "internal-fn.h". (ubsan_instrument_division): Mark instrumented arrays as having side effects. Adjust ubsan_type_descriptor call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Adjust ubsan_type_descriptor call. (ubsan_instrument_bounds): New function. (ubsan_array_ref_instrumented_p): New function. (ubsan_maybe_instrument_array_ref): New function. * c-ubsan.h (ubsan_instrument_bounds): Declare. (ubsan_array_ref_instrumented_p): Declare. (ubsan_maybe_instrument_array_ref): Declare. testsuite/ * c-c++-common/ubsan/bounds-1.c: New test. * c-c++-common/ubsan/bounds-2.c: New test. * c-c++-common/ubsan/bounds-3.c: New test. * c-c++-common/ubsan/bounds-4.c: New test. * c-c++-common/ubsan/bounds-5.c: New test. * c-c++-common/ubsan/bounds-6.c: New test. From-SVN: r211859
2014-06-20 23:20:51 +02:00
tree data
= ubsan_create_data ("__ubsan_null_data", 1, &loc,
opts.c (common_handle_option): Handle -fsanitize=alignment. * opts.c (common_handle_option): Handle -fsanitize=alignment. * ubsan.h (enum ubsan_null_ckind): Add UBSAN_CTOR_CALL. (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn): Change return type to bool. * stor-layout.h (min_align_of_type): New prototype. * asan.c (pass_sanopt::execute): Don't perform gsi_next if ubsan_expand* told us not to do it. Remove the extra gsi_end_p check. * ubsan.c: Include builtins.h. (ubsan_expand_bounds_ifn): Change return type to bool, always return true. (ubsan_expand_null_ifn): Change return type to bool, change argument to gimple_stmt_iterator *. Handle both null and alignment sanitization, take type from ckind argument's type rather than first argument. (instrument_member_call): Removed. (instrument_mem_ref): Remove t argument, add mem and base arguments. Handle both null and alignment sanitization, don't say whole struct access is member access. Build 3 argument IFN_UBSAN_NULL call instead of 2 argument. (instrument_null): Adjust instrument_mem_ref caller. Don't instrument calls here. (pass_ubsan::gate, pass_ubsan::execute): Handle SANITIZE_ALIGNMENT like SANITIZE_NULL. * stor-layout.c (min_align_of_type): New function. * flag-types.h (enum sanitize_code): Add SANITIZE_ALIGNMENT. Or it into SANITIZE_UNDEFINED. * doc/invoke.texi (-fsanitize=alignment): Document. cp/ * cp-gimplify.c (cp_genericize_r): For -fsanitize=null and/or -fsanitize=alignment call ubsan_maybe_instrument_reference for casts to REFERENCE_TYPE and ubsan_maybe_instrument_member_call for calls to member functions. c-family/ * c-common.h (min_align_of_type): Removed prototype. * c-common.c (min_align_of_type): Removed. * c-ubsan.h (ubsan_maybe_instrument_reference, ubsan_maybe_instrument_member_call): New prototypes. * c-ubsan.c: Include stor-layout.h and builtins.h. (ubsan_maybe_instrument_reference_or_call, ubsan_maybe_instrument_reference, ubsan_maybe_instrument_call): New functions. testsuite/ * c-c++-common/ubsan/align-1.c: New test. * c-c++-common/ubsan/align-2.c: New test. * c-c++-common/ubsan/align-3.c: New test. * c-c++-common/ubsan/align-4.c: New test. * c-c++-common/ubsan/align-5.c: New test. * c-c++-common/ubsan/attrib-4.c: New test. * g++.dg/ubsan/align-1.C: New test. * g++.dg/ubsan/align-2.C: New test. * g++.dg/ubsan/align-3.C: New test. * g++.dg/ubsan/attrib-1.C: New test. * g++.dg/ubsan/null-1.C: New test. * g++.dg/ubsan/null-2.C: New test. From-SVN: r213406
2014-08-01 09:52:43 +02:00
ubsan_type_descriptor (TREE_TYPE (ckind),
asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * flag-types.h (enum sanitize_code): Add SANITIZE_BOUNDS and or it into SANITIZE_UNDEFINED. * doc/invoke.texi: Describe -fsanitize=bounds. * gimplify.c (gimplify_call_expr): Add gimplification of internal functions created in the FEs. * internal-fn.c: Move "internal-fn.h" after "tree.h". (expand_UBSAN_BOUNDS): New function. * internal-fn.def (UBSAN_BOUNDS): New internal function. * internal-fn.h: Don't define internal functions here. * opts.c (common_handle_option): Add -fsanitize=bounds. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS, BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS_ABORT): Add. * tree-core.h: Define internal functions here. (struct tree_base): Add ifn field. * tree-pretty-print.c: Include "internal-fn.h". (dump_generic_node): Handle functions without CALL_EXPR_FN. * tree.c (get_callee_fndecl): Likewise. (build_call_expr_internal_loc): New function. * tree.def (CALL_EXPR): Update description. * tree.h (CALL_EXPR_IFN): Define. (build_call_expr_internal_loc): Declare. * ubsan.c (get_ubsan_type_info_for_type): Return 0 for non-arithmetic types. (ubsan_type_descriptor): Change bool parameter to enum ubsan_print_style. Adjust the code. Add handling of UBSAN_PRINT_ARRAY. (ubsan_expand_bounds_ifn): New function. (ubsan_expand_null_ifn): Adjust ubsan_type_descriptor call. (ubsan_build_overflow_builtin): Likewise. (instrument_bool_enum_load): Likewise. (ubsan_instrument_float_cast): Likewise. * ubsan.h (enum ubsan_print_style): New enum. (ubsan_expand_bounds_ifn): Declare. (ubsan_type_descriptor): Adjust declaration. Use a default parameter. c-family/ * c-gimplify.c: Include "c-ubsan.h" and "pointer-set.h". (ubsan_walk_array_refs_r): New function. (c_genericize): Instrument array bounds. * c-ubsan.c: Include "internal-fn.h". (ubsan_instrument_division): Mark instrumented arrays as having side effects. Adjust ubsan_type_descriptor call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Adjust ubsan_type_descriptor call. (ubsan_instrument_bounds): New function. (ubsan_array_ref_instrumented_p): New function. (ubsan_maybe_instrument_array_ref): New function. * c-ubsan.h (ubsan_instrument_bounds): Declare. (ubsan_array_ref_instrumented_p): Declare. (ubsan_maybe_instrument_array_ref): Declare. testsuite/ * c-c++-common/ubsan/bounds-1.c: New test. * c-c++-common/ubsan/bounds-2.c: New test. * c-c++-common/ubsan/bounds-3.c: New test. * c-c++-common/ubsan/bounds-4.c: New test. * c-c++-common/ubsan/bounds-5.c: New test. * c-c++-common/ubsan/bounds-6.c: New test. From-SVN: r211859
2014-06-20 23:20:51 +02:00
UBSAN_PRINT_POINTER),
NULL_TREE,
align,
fold_convert (unsigned_char_type_node, ckind),
asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * asan.c (pass_sanopt::execute): Handle IFN_UBSAN_BOUNDS. * flag-types.h (enum sanitize_code): Add SANITIZE_BOUNDS and or it into SANITIZE_UNDEFINED. * doc/invoke.texi: Describe -fsanitize=bounds. * gimplify.c (gimplify_call_expr): Add gimplification of internal functions created in the FEs. * internal-fn.c: Move "internal-fn.h" after "tree.h". (expand_UBSAN_BOUNDS): New function. * internal-fn.def (UBSAN_BOUNDS): New internal function. * internal-fn.h: Don't define internal functions here. * opts.c (common_handle_option): Add -fsanitize=bounds. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS, BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS_ABORT): Add. * tree-core.h: Define internal functions here. (struct tree_base): Add ifn field. * tree-pretty-print.c: Include "internal-fn.h". (dump_generic_node): Handle functions without CALL_EXPR_FN. * tree.c (get_callee_fndecl): Likewise. (build_call_expr_internal_loc): New function. * tree.def (CALL_EXPR): Update description. * tree.h (CALL_EXPR_IFN): Define. (build_call_expr_internal_loc): Declare. * ubsan.c (get_ubsan_type_info_for_type): Return 0 for non-arithmetic types. (ubsan_type_descriptor): Change bool parameter to enum ubsan_print_style. Adjust the code. Add handling of UBSAN_PRINT_ARRAY. (ubsan_expand_bounds_ifn): New function. (ubsan_expand_null_ifn): Adjust ubsan_type_descriptor call. (ubsan_build_overflow_builtin): Likewise. (instrument_bool_enum_load): Likewise. (ubsan_instrument_float_cast): Likewise. * ubsan.h (enum ubsan_print_style): New enum. (ubsan_expand_bounds_ifn): Declare. (ubsan_type_descriptor): Adjust declaration. Use a default parameter. c-family/ * c-gimplify.c: Include "c-ubsan.h" and "pointer-set.h". (ubsan_walk_array_refs_r): New function. (c_genericize): Instrument array bounds. * c-ubsan.c: Include "internal-fn.h". (ubsan_instrument_division): Mark instrumented arrays as having side effects. Adjust ubsan_type_descriptor call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Adjust ubsan_type_descriptor call. (ubsan_instrument_bounds): New function. (ubsan_array_ref_instrumented_p): New function. (ubsan_maybe_instrument_array_ref): New function. * c-ubsan.h (ubsan_instrument_bounds): Declare. (ubsan_array_ref_instrumented_p): Declare. (ubsan_maybe_instrument_array_ref): Declare. testsuite/ * c-c++-common/ubsan/bounds-1.c: New test. * c-c++-common/ubsan/bounds-2.c: New test. * c-c++-common/ubsan/bounds-3.c: New test. * c-c++-common/ubsan/bounds-4.c: New test. * c-c++-common/ubsan/bounds-5.c: New test. * c-c++-common/ubsan/bounds-6.c: New test. From-SVN: r211859
2014-06-20 23:20:51 +02:00
NULL_TREE);
re PR sanitizer/60275 ([UBSAN] Add -f[no-]sanitize-recover/-fsanitize-undefined-trap-on-error to make UBSAN's runtime errors fatal) PR sanitizer/60275 * common.opt (fsanitize-recover, fsanitize-undefined-trap-on-error): New options. * gcc.c (sanitize_spec_function): Don't return "" for "undefined" if flag_sanitize_undefined_trap_on_error. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_DIVREM_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_SHIFT_OUT_OF_BOUNDS_ABORT, BUILT_IN_UBSAN_HANDLE_VLA_BOUND_NOT_POSITIVE_ABORT, BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT, BUILT_IN_UBSAN_HANDLE_ADD_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_SUB_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_MUL_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_NEGATE_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_LOAD_INVALID_VALUE_ABORT): New builtins. * ubsan.c (ubsan_instrument_unreachable): Return __builtin_trap () if flag_sanitize_undefined_trap_on_error. (ubsan_expand_null_ifn): Emit __builtin_trap () if flag_sanitize_undefined_trap_on_error and __ubsan_handle_type_mismatch_abort if !flag_sanitize_recover. (ubsan_expand_null_ifn, ubsan_build_overflow_builtin, instrument_bool_enum_load): Emit __builtin_trap () if flag_sanitize_undefined_trap_on_error and __builtin_handle_*_abort () if !flag_sanitize_recover. * doc/invoke.texi (-fsanitize-recover, -fsanitize-undefined-trap-on-error): Document. c-family/ * c-ubsan.c (ubsan_instrument_return): Return __builtin_trap () if flag_sanitize_undefined_trap_on_error. (ubsan_instrument_division, ubsan_instrument_shift, ubsan_instrument_vla): Likewise. Use __ubsan_handle_*_abort () if !flag_sanitize_recover. testsuite/ * g++.dg/ubsan/return-2.C: Revert 2014-03-24 changes, add -fno-sanitize-recover to dg-options. * g++.dg/ubsan/cxx11-shift-1.C: Remove c++11 target restriction, add -std=c++11 to dg-options. * g++.dg/ubsan/cxx11-shift-2.C: Likewise. * g++.dg/ubsan/cxx1y-vla.C: Remove c++1y target restriction, add -std=c++1y to dg-options. * c-c++-common/ubsan/undefined-1.c: Revert 2014-03-24 changes, add -fno-sanitize-recover to dg-options. * c-c++-common/ubsan/overflow-sub-1.c: Likewise. * c-c++-common/ubsan/vla-4.c: Likewise. * c-c++-common/ubsan/pr59503.c: Likewise. * c-c++-common/ubsan/vla-3.c: Likewise. * c-c++-common/ubsan/save-expr-1.c: Likewise. * c-c++-common/ubsan/overflow-add-1.c: Likewise. * c-c++-common/ubsan/shift-3.c: Likewise. * c-c++-common/ubsan/overflow-1.c: Likewise. * c-c++-common/ubsan/overflow-negate-2.c: Likewise. * c-c++-common/ubsan/vla-2.c: Likewise. * c-c++-common/ubsan/overflow-mul-1.c: Likewise. * c-c++-common/ubsan/pr60613-1.c: Likewise. * c-c++-common/ubsan/shift-6.c: Likewise. * c-c++-common/ubsan/overflow-mul-3.c: Likewise. * c-c++-common/ubsan/overflow-add-3.c: New test. * c-c++-common/ubsan/overflow-add-4.c: New test. * c-c++-common/ubsan/div-by-zero-6.c: New test. * c-c++-common/ubsan/div-by-zero-7.c: New test. From-SVN: r209672
2014-04-23 10:20:12 +02:00
data = build_fold_addr_expr_loc (loc, data);
g = gimple_build_call (fn, 2, data,
opts.c (common_handle_option): Handle -fsanitize=alignment. * opts.c (common_handle_option): Handle -fsanitize=alignment. * ubsan.h (enum ubsan_null_ckind): Add UBSAN_CTOR_CALL. (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn): Change return type to bool. * stor-layout.h (min_align_of_type): New prototype. * asan.c (pass_sanopt::execute): Don't perform gsi_next if ubsan_expand* told us not to do it. Remove the extra gsi_end_p check. * ubsan.c: Include builtins.h. (ubsan_expand_bounds_ifn): Change return type to bool, always return true. (ubsan_expand_null_ifn): Change return type to bool, change argument to gimple_stmt_iterator *. Handle both null and alignment sanitization, take type from ckind argument's type rather than first argument. (instrument_member_call): Removed. (instrument_mem_ref): Remove t argument, add mem and base arguments. Handle both null and alignment sanitization, don't say whole struct access is member access. Build 3 argument IFN_UBSAN_NULL call instead of 2 argument. (instrument_null): Adjust instrument_mem_ref caller. Don't instrument calls here. (pass_ubsan::gate, pass_ubsan::execute): Handle SANITIZE_ALIGNMENT like SANITIZE_NULL. * stor-layout.c (min_align_of_type): New function. * flag-types.h (enum sanitize_code): Add SANITIZE_ALIGNMENT. Or it into SANITIZE_UNDEFINED. * doc/invoke.texi (-fsanitize=alignment): Document. cp/ * cp-gimplify.c (cp_genericize_r): For -fsanitize=null and/or -fsanitize=alignment call ubsan_maybe_instrument_reference for casts to REFERENCE_TYPE and ubsan_maybe_instrument_member_call for calls to member functions. c-family/ * c-common.h (min_align_of_type): Removed prototype. * c-common.c (min_align_of_type): Removed. * c-ubsan.h (ubsan_maybe_instrument_reference, ubsan_maybe_instrument_member_call): New prototypes. * c-ubsan.c: Include stor-layout.h and builtins.h. (ubsan_maybe_instrument_reference_or_call, ubsan_maybe_instrument_reference, ubsan_maybe_instrument_call): New functions. testsuite/ * c-c++-common/ubsan/align-1.c: New test. * c-c++-common/ubsan/align-2.c: New test. * c-c++-common/ubsan/align-3.c: New test. * c-c++-common/ubsan/align-4.c: New test. * c-c++-common/ubsan/align-5.c: New test. * c-c++-common/ubsan/attrib-4.c: New test. * g++.dg/ubsan/align-1.C: New test. * g++.dg/ubsan/align-2.C: New test. * g++.dg/ubsan/align-3.C: New test. * g++.dg/ubsan/attrib-1.C: New test. * g++.dg/ubsan/null-1.C: New test. * g++.dg/ubsan/null-2.C: New test. From-SVN: r213406
2014-08-01 09:52:43 +02:00
check_align ? check_align
: build_zero_cst (pointer_sized_int_node));
re PR sanitizer/60275 ([UBSAN] Add -f[no-]sanitize-recover/-fsanitize-undefined-trap-on-error to make UBSAN's runtime errors fatal) PR sanitizer/60275 * common.opt (fsanitize-recover, fsanitize-undefined-trap-on-error): New options. * gcc.c (sanitize_spec_function): Don't return "" for "undefined" if flag_sanitize_undefined_trap_on_error. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_DIVREM_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_SHIFT_OUT_OF_BOUNDS_ABORT, BUILT_IN_UBSAN_HANDLE_VLA_BOUND_NOT_POSITIVE_ABORT, BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT, BUILT_IN_UBSAN_HANDLE_ADD_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_SUB_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_MUL_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_NEGATE_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_LOAD_INVALID_VALUE_ABORT): New builtins. * ubsan.c (ubsan_instrument_unreachable): Return __builtin_trap () if flag_sanitize_undefined_trap_on_error. (ubsan_expand_null_ifn): Emit __builtin_trap () if flag_sanitize_undefined_trap_on_error and __ubsan_handle_type_mismatch_abort if !flag_sanitize_recover. (ubsan_expand_null_ifn, ubsan_build_overflow_builtin, instrument_bool_enum_load): Emit __builtin_trap () if flag_sanitize_undefined_trap_on_error and __builtin_handle_*_abort () if !flag_sanitize_recover. * doc/invoke.texi (-fsanitize-recover, -fsanitize-undefined-trap-on-error): Document. c-family/ * c-ubsan.c (ubsan_instrument_return): Return __builtin_trap () if flag_sanitize_undefined_trap_on_error. (ubsan_instrument_division, ubsan_instrument_shift, ubsan_instrument_vla): Likewise. Use __ubsan_handle_*_abort () if !flag_sanitize_recover. testsuite/ * g++.dg/ubsan/return-2.C: Revert 2014-03-24 changes, add -fno-sanitize-recover to dg-options. * g++.dg/ubsan/cxx11-shift-1.C: Remove c++11 target restriction, add -std=c++11 to dg-options. * g++.dg/ubsan/cxx11-shift-2.C: Likewise. * g++.dg/ubsan/cxx1y-vla.C: Remove c++1y target restriction, add -std=c++1y to dg-options. * c-c++-common/ubsan/undefined-1.c: Revert 2014-03-24 changes, add -fno-sanitize-recover to dg-options. * c-c++-common/ubsan/overflow-sub-1.c: Likewise. * c-c++-common/ubsan/vla-4.c: Likewise. * c-c++-common/ubsan/pr59503.c: Likewise. * c-c++-common/ubsan/vla-3.c: Likewise. * c-c++-common/ubsan/save-expr-1.c: Likewise. * c-c++-common/ubsan/overflow-add-1.c: Likewise. * c-c++-common/ubsan/shift-3.c: Likewise. * c-c++-common/ubsan/overflow-1.c: Likewise. * c-c++-common/ubsan/overflow-negate-2.c: Likewise. * c-c++-common/ubsan/vla-2.c: Likewise. * c-c++-common/ubsan/overflow-mul-1.c: Likewise. * c-c++-common/ubsan/pr60613-1.c: Likewise. * c-c++-common/ubsan/shift-6.c: Likewise. * c-c++-common/ubsan/overflow-mul-3.c: Likewise. * c-c++-common/ubsan/overflow-add-3.c: New test. * c-c++-common/ubsan/overflow-add-4.c: New test. * c-c++-common/ubsan/div-by-zero-6.c: New test. * c-c++-common/ubsan/div-by-zero-7.c: New test. From-SVN: r209672
2014-04-23 10:20:12 +02:00
}
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
gimple_stmt_iterator gsi2 = gsi_start_bb (then_bb);
opts.c (common_handle_option): Handle -fsanitize=alignment. * opts.c (common_handle_option): Handle -fsanitize=alignment. * ubsan.h (enum ubsan_null_ckind): Add UBSAN_CTOR_CALL. (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn): Change return type to bool. * stor-layout.h (min_align_of_type): New prototype. * asan.c (pass_sanopt::execute): Don't perform gsi_next if ubsan_expand* told us not to do it. Remove the extra gsi_end_p check. * ubsan.c: Include builtins.h. (ubsan_expand_bounds_ifn): Change return type to bool, always return true. (ubsan_expand_null_ifn): Change return type to bool, change argument to gimple_stmt_iterator *. Handle both null and alignment sanitization, take type from ckind argument's type rather than first argument. (instrument_member_call): Removed. (instrument_mem_ref): Remove t argument, add mem and base arguments. Handle both null and alignment sanitization, don't say whole struct access is member access. Build 3 argument IFN_UBSAN_NULL call instead of 2 argument. (instrument_null): Adjust instrument_mem_ref caller. Don't instrument calls here. (pass_ubsan::gate, pass_ubsan::execute): Handle SANITIZE_ALIGNMENT like SANITIZE_NULL. * stor-layout.c (min_align_of_type): New function. * flag-types.h (enum sanitize_code): Add SANITIZE_ALIGNMENT. Or it into SANITIZE_UNDEFINED. * doc/invoke.texi (-fsanitize=alignment): Document. cp/ * cp-gimplify.c (cp_genericize_r): For -fsanitize=null and/or -fsanitize=alignment call ubsan_maybe_instrument_reference for casts to REFERENCE_TYPE and ubsan_maybe_instrument_member_call for calls to member functions. c-family/ * c-common.h (min_align_of_type): Removed prototype. * c-common.c (min_align_of_type): Removed. * c-ubsan.h (ubsan_maybe_instrument_reference, ubsan_maybe_instrument_member_call): New prototypes. * c-ubsan.c: Include stor-layout.h and builtins.h. (ubsan_maybe_instrument_reference_or_call, ubsan_maybe_instrument_reference, ubsan_maybe_instrument_call): New functions. testsuite/ * c-c++-common/ubsan/align-1.c: New test. * c-c++-common/ubsan/align-2.c: New test. * c-c++-common/ubsan/align-3.c: New test. * c-c++-common/ubsan/align-4.c: New test. * c-c++-common/ubsan/align-5.c: New test. * c-c++-common/ubsan/attrib-4.c: New test. * g++.dg/ubsan/align-1.C: New test. * g++.dg/ubsan/align-2.C: New test. * g++.dg/ubsan/align-3.C: New test. * g++.dg/ubsan/attrib-1.C: New test. * g++.dg/ubsan/null-1.C: New test. * g++.dg/ubsan/null-2.C: New test. From-SVN: r213406
2014-08-01 09:52:43 +02:00
gimple_set_location (g, loc);
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
gsi_insert_after (&gsi2, g, GSI_NEW_STMT);
/* Unlink the UBSAN_NULLs vops before replacing it. */
unlink_stmt_vdef (stmt);
opts.c (common_handle_option): Handle -fsanitize=alignment. * opts.c (common_handle_option): Handle -fsanitize=alignment. * ubsan.h (enum ubsan_null_ckind): Add UBSAN_CTOR_CALL. (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn): Change return type to bool. * stor-layout.h (min_align_of_type): New prototype. * asan.c (pass_sanopt::execute): Don't perform gsi_next if ubsan_expand* told us not to do it. Remove the extra gsi_end_p check. * ubsan.c: Include builtins.h. (ubsan_expand_bounds_ifn): Change return type to bool, always return true. (ubsan_expand_null_ifn): Change return type to bool, change argument to gimple_stmt_iterator *. Handle both null and alignment sanitization, take type from ckind argument's type rather than first argument. (instrument_member_call): Removed. (instrument_mem_ref): Remove t argument, add mem and base arguments. Handle both null and alignment sanitization, don't say whole struct access is member access. Build 3 argument IFN_UBSAN_NULL call instead of 2 argument. (instrument_null): Adjust instrument_mem_ref caller. Don't instrument calls here. (pass_ubsan::gate, pass_ubsan::execute): Handle SANITIZE_ALIGNMENT like SANITIZE_NULL. * stor-layout.c (min_align_of_type): New function. * flag-types.h (enum sanitize_code): Add SANITIZE_ALIGNMENT. Or it into SANITIZE_UNDEFINED. * doc/invoke.texi (-fsanitize=alignment): Document. cp/ * cp-gimplify.c (cp_genericize_r): For -fsanitize=null and/or -fsanitize=alignment call ubsan_maybe_instrument_reference for casts to REFERENCE_TYPE and ubsan_maybe_instrument_member_call for calls to member functions. c-family/ * c-common.h (min_align_of_type): Removed prototype. * c-common.c (min_align_of_type): Removed. * c-ubsan.h (ubsan_maybe_instrument_reference, ubsan_maybe_instrument_member_call): New prototypes. * c-ubsan.c: Include stor-layout.h and builtins.h. (ubsan_maybe_instrument_reference_or_call, ubsan_maybe_instrument_reference, ubsan_maybe_instrument_call): New functions. testsuite/ * c-c++-common/ubsan/align-1.c: New test. * c-c++-common/ubsan/align-2.c: New test. * c-c++-common/ubsan/align-3.c: New test. * c-c++-common/ubsan/align-4.c: New test. * c-c++-common/ubsan/align-5.c: New test. * c-c++-common/ubsan/attrib-4.c: New test. * g++.dg/ubsan/align-1.C: New test. * g++.dg/ubsan/align-2.C: New test. * g++.dg/ubsan/align-3.C: New test. * g++.dg/ubsan/attrib-1.C: New test. * g++.dg/ubsan/null-1.C: New test. * g++.dg/ubsan/null-2.C: New test. From-SVN: r213406
2014-08-01 09:52:43 +02:00
if (check_null)
{
g = gimple_build_cond (EQ_EXPR, ptr, build_int_cst (TREE_TYPE (ptr), 0),
NULL_TREE, NULL_TREE);
gimple_set_location (g, loc);
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
opts.c (common_handle_option): Handle -fsanitize=alignment. * opts.c (common_handle_option): Handle -fsanitize=alignment. * ubsan.h (enum ubsan_null_ckind): Add UBSAN_CTOR_CALL. (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn): Change return type to bool. * stor-layout.h (min_align_of_type): New prototype. * asan.c (pass_sanopt::execute): Don't perform gsi_next if ubsan_expand* told us not to do it. Remove the extra gsi_end_p check. * ubsan.c: Include builtins.h. (ubsan_expand_bounds_ifn): Change return type to bool, always return true. (ubsan_expand_null_ifn): Change return type to bool, change argument to gimple_stmt_iterator *. Handle both null and alignment sanitization, take type from ckind argument's type rather than first argument. (instrument_member_call): Removed. (instrument_mem_ref): Remove t argument, add mem and base arguments. Handle both null and alignment sanitization, don't say whole struct access is member access. Build 3 argument IFN_UBSAN_NULL call instead of 2 argument. (instrument_null): Adjust instrument_mem_ref caller. Don't instrument calls here. (pass_ubsan::gate, pass_ubsan::execute): Handle SANITIZE_ALIGNMENT like SANITIZE_NULL. * stor-layout.c (min_align_of_type): New function. * flag-types.h (enum sanitize_code): Add SANITIZE_ALIGNMENT. Or it into SANITIZE_UNDEFINED. * doc/invoke.texi (-fsanitize=alignment): Document. cp/ * cp-gimplify.c (cp_genericize_r): For -fsanitize=null and/or -fsanitize=alignment call ubsan_maybe_instrument_reference for casts to REFERENCE_TYPE and ubsan_maybe_instrument_member_call for calls to member functions. c-family/ * c-common.h (min_align_of_type): Removed prototype. * c-common.c (min_align_of_type): Removed. * c-ubsan.h (ubsan_maybe_instrument_reference, ubsan_maybe_instrument_member_call): New prototypes. * c-ubsan.c: Include stor-layout.h and builtins.h. (ubsan_maybe_instrument_reference_or_call, ubsan_maybe_instrument_reference, ubsan_maybe_instrument_call): New functions. testsuite/ * c-c++-common/ubsan/align-1.c: New test. * c-c++-common/ubsan/align-2.c: New test. * c-c++-common/ubsan/align-3.c: New test. * c-c++-common/ubsan/align-4.c: New test. * c-c++-common/ubsan/align-5.c: New test. * c-c++-common/ubsan/attrib-4.c: New test. * g++.dg/ubsan/align-1.C: New test. * g++.dg/ubsan/align-2.C: New test. * g++.dg/ubsan/align-3.C: New test. * g++.dg/ubsan/attrib-1.C: New test. * g++.dg/ubsan/null-1.C: New test. * g++.dg/ubsan/null-2.C: New test. From-SVN: r213406
2014-08-01 09:52:43 +02:00
/* Replace the UBSAN_NULL with a GIMPLE_COND stmt. */
gsi_replace (&gsi, g, false);
stmt = g;
opts.c (common_handle_option): Handle -fsanitize=alignment. * opts.c (common_handle_option): Handle -fsanitize=alignment. * ubsan.h (enum ubsan_null_ckind): Add UBSAN_CTOR_CALL. (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn): Change return type to bool. * stor-layout.h (min_align_of_type): New prototype. * asan.c (pass_sanopt::execute): Don't perform gsi_next if ubsan_expand* told us not to do it. Remove the extra gsi_end_p check. * ubsan.c: Include builtins.h. (ubsan_expand_bounds_ifn): Change return type to bool, always return true. (ubsan_expand_null_ifn): Change return type to bool, change argument to gimple_stmt_iterator *. Handle both null and alignment sanitization, take type from ckind argument's type rather than first argument. (instrument_member_call): Removed. (instrument_mem_ref): Remove t argument, add mem and base arguments. Handle both null and alignment sanitization, don't say whole struct access is member access. Build 3 argument IFN_UBSAN_NULL call instead of 2 argument. (instrument_null): Adjust instrument_mem_ref caller. Don't instrument calls here. (pass_ubsan::gate, pass_ubsan::execute): Handle SANITIZE_ALIGNMENT like SANITIZE_NULL. * stor-layout.c (min_align_of_type): New function. * flag-types.h (enum sanitize_code): Add SANITIZE_ALIGNMENT. Or it into SANITIZE_UNDEFINED. * doc/invoke.texi (-fsanitize=alignment): Document. cp/ * cp-gimplify.c (cp_genericize_r): For -fsanitize=null and/or -fsanitize=alignment call ubsan_maybe_instrument_reference for casts to REFERENCE_TYPE and ubsan_maybe_instrument_member_call for calls to member functions. c-family/ * c-common.h (min_align_of_type): Removed prototype. * c-common.c (min_align_of_type): Removed. * c-ubsan.h (ubsan_maybe_instrument_reference, ubsan_maybe_instrument_member_call): New prototypes. * c-ubsan.c: Include stor-layout.h and builtins.h. (ubsan_maybe_instrument_reference_or_call, ubsan_maybe_instrument_reference, ubsan_maybe_instrument_call): New functions. testsuite/ * c-c++-common/ubsan/align-1.c: New test. * c-c++-common/ubsan/align-2.c: New test. * c-c++-common/ubsan/align-3.c: New test. * c-c++-common/ubsan/align-4.c: New test. * c-c++-common/ubsan/align-5.c: New test. * c-c++-common/ubsan/attrib-4.c: New test. * g++.dg/ubsan/align-1.C: New test. * g++.dg/ubsan/align-2.C: New test. * g++.dg/ubsan/align-3.C: New test. * g++.dg/ubsan/attrib-1.C: New test. * g++.dg/ubsan/null-1.C: New test. * g++.dg/ubsan/null-2.C: New test. From-SVN: r213406
2014-08-01 09:52:43 +02:00
}
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
opts.c (common_handle_option): Handle -fsanitize=alignment. * opts.c (common_handle_option): Handle -fsanitize=alignment. * ubsan.h (enum ubsan_null_ckind): Add UBSAN_CTOR_CALL. (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn): Change return type to bool. * stor-layout.h (min_align_of_type): New prototype. * asan.c (pass_sanopt::execute): Don't perform gsi_next if ubsan_expand* told us not to do it. Remove the extra gsi_end_p check. * ubsan.c: Include builtins.h. (ubsan_expand_bounds_ifn): Change return type to bool, always return true. (ubsan_expand_null_ifn): Change return type to bool, change argument to gimple_stmt_iterator *. Handle both null and alignment sanitization, take type from ckind argument's type rather than first argument. (instrument_member_call): Removed. (instrument_mem_ref): Remove t argument, add mem and base arguments. Handle both null and alignment sanitization, don't say whole struct access is member access. Build 3 argument IFN_UBSAN_NULL call instead of 2 argument. (instrument_null): Adjust instrument_mem_ref caller. Don't instrument calls here. (pass_ubsan::gate, pass_ubsan::execute): Handle SANITIZE_ALIGNMENT like SANITIZE_NULL. * stor-layout.c (min_align_of_type): New function. * flag-types.h (enum sanitize_code): Add SANITIZE_ALIGNMENT. Or it into SANITIZE_UNDEFINED. * doc/invoke.texi (-fsanitize=alignment): Document. cp/ * cp-gimplify.c (cp_genericize_r): For -fsanitize=null and/or -fsanitize=alignment call ubsan_maybe_instrument_reference for casts to REFERENCE_TYPE and ubsan_maybe_instrument_member_call for calls to member functions. c-family/ * c-common.h (min_align_of_type): Removed prototype. * c-common.c (min_align_of_type): Removed. * c-ubsan.h (ubsan_maybe_instrument_reference, ubsan_maybe_instrument_member_call): New prototypes. * c-ubsan.c: Include stor-layout.h and builtins.h. (ubsan_maybe_instrument_reference_or_call, ubsan_maybe_instrument_reference, ubsan_maybe_instrument_call): New functions. testsuite/ * c-c++-common/ubsan/align-1.c: New test. * c-c++-common/ubsan/align-2.c: New test. * c-c++-common/ubsan/align-3.c: New test. * c-c++-common/ubsan/align-4.c: New test. * c-c++-common/ubsan/align-5.c: New test. * c-c++-common/ubsan/attrib-4.c: New test. * g++.dg/ubsan/align-1.C: New test. * g++.dg/ubsan/align-2.C: New test. * g++.dg/ubsan/align-3.C: New test. * g++.dg/ubsan/attrib-1.C: New test. * g++.dg/ubsan/null-1.C: New test. * g++.dg/ubsan/null-2.C: New test. From-SVN: r213406
2014-08-01 09:52:43 +02:00
if (check_align)
{
if (check_null)
{
/* Split the block with the condition again. */
e = split_block (cond_bb, stmt);
basic_block cond1_bb = e->src;
basic_block cond2_bb = e->dest;
/* Make an edge coming from the 'cond1 block' into the 'then block';
this edge is unlikely taken, so set up the probability
accordingly. */
e = make_edge (cond1_bb, then_bb, EDGE_TRUE_VALUE);
e->probability = PROB_VERY_UNLIKELY;
/* Set up the fallthrough basic block. */
e = find_edge (cond1_bb, cond2_bb);
e->flags = EDGE_FALSE_VALUE;
e->count = cond1_bb->count;
e->probability = REG_BR_PROB_BASE - PROB_VERY_UNLIKELY;
/* Update dominance info. */
if (dom_info_available_p (CDI_DOMINATORS))
{
set_immediate_dominator (CDI_DOMINATORS, fallthru_bb, cond1_bb);
set_immediate_dominator (CDI_DOMINATORS, then_bb, cond1_bb);
}
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
opts.c (common_handle_option): Handle -fsanitize=alignment. * opts.c (common_handle_option): Handle -fsanitize=alignment. * ubsan.h (enum ubsan_null_ckind): Add UBSAN_CTOR_CALL. (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn): Change return type to bool. * stor-layout.h (min_align_of_type): New prototype. * asan.c (pass_sanopt::execute): Don't perform gsi_next if ubsan_expand* told us not to do it. Remove the extra gsi_end_p check. * ubsan.c: Include builtins.h. (ubsan_expand_bounds_ifn): Change return type to bool, always return true. (ubsan_expand_null_ifn): Change return type to bool, change argument to gimple_stmt_iterator *. Handle both null and alignment sanitization, take type from ckind argument's type rather than first argument. (instrument_member_call): Removed. (instrument_mem_ref): Remove t argument, add mem and base arguments. Handle both null and alignment sanitization, don't say whole struct access is member access. Build 3 argument IFN_UBSAN_NULL call instead of 2 argument. (instrument_null): Adjust instrument_mem_ref caller. Don't instrument calls here. (pass_ubsan::gate, pass_ubsan::execute): Handle SANITIZE_ALIGNMENT like SANITIZE_NULL. * stor-layout.c (min_align_of_type): New function. * flag-types.h (enum sanitize_code): Add SANITIZE_ALIGNMENT. Or it into SANITIZE_UNDEFINED. * doc/invoke.texi (-fsanitize=alignment): Document. cp/ * cp-gimplify.c (cp_genericize_r): For -fsanitize=null and/or -fsanitize=alignment call ubsan_maybe_instrument_reference for casts to REFERENCE_TYPE and ubsan_maybe_instrument_member_call for calls to member functions. c-family/ * c-common.h (min_align_of_type): Removed prototype. * c-common.c (min_align_of_type): Removed. * c-ubsan.h (ubsan_maybe_instrument_reference, ubsan_maybe_instrument_member_call): New prototypes. * c-ubsan.c: Include stor-layout.h and builtins.h. (ubsan_maybe_instrument_reference_or_call, ubsan_maybe_instrument_reference, ubsan_maybe_instrument_call): New functions. testsuite/ * c-c++-common/ubsan/align-1.c: New test. * c-c++-common/ubsan/align-2.c: New test. * c-c++-common/ubsan/align-3.c: New test. * c-c++-common/ubsan/align-4.c: New test. * c-c++-common/ubsan/align-5.c: New test. * c-c++-common/ubsan/attrib-4.c: New test. * g++.dg/ubsan/align-1.C: New test. * g++.dg/ubsan/align-2.C: New test. * g++.dg/ubsan/align-3.C: New test. * g++.dg/ubsan/attrib-1.C: New test. * g++.dg/ubsan/null-1.C: New test. * g++.dg/ubsan/null-2.C: New test. From-SVN: r213406
2014-08-01 09:52:43 +02:00
gsi2 = gsi_start_bb (cond2_bb);
}
tree mask = build_int_cst (pointer_sized_int_node,
tree_to_uhwi (align) - 1);
gimple.h (gimple_build_assign_stat): Remove prototype. * gimple.h (gimple_build_assign_stat): Remove prototype. (gimple_build_assign): Remove define. Add overload prototypes with tree lhs and either a tree rhs, or enum tree_code and 1, 2 or 3 tree operands. * gimple.c (gimple_build_assign_stat): Renamed to... (gimple_build_assign): ... this. Add overloads with enum tree_code and 1, 2 or 3 tree operands. (gimple_build_assign_with_ops): Remove 1 and 2 operand overloads. Rename the 3 operand overload to ... (gimple_build_assign_1): ... this. Make it static inline. * tree-ssa-strlen.c (get_string_length): Use gimple_build_assign instead of gimple_build_assign_with_ops, swap the order of first two arguments and adjust formatting where necessary. * tree-vect-slp.c (vect_get_constant_vectors, vect_create_mask_and_perm): Likewise. * tree-ssa-forwprop.c (simplify_rotate): Likewise. * asan.c (build_shadow_mem_access, maybe_create_ssa_name, maybe_cast_to_ptrmode, asan_expand_check_ifn): Likewise. * tsan.c (instrument_builtin_call): Likewise. * tree-chkp.c (chkp_compute_bounds_for_assignment, chkp_generate_extern_var_bounds): Likewise. * tree-loop-distribution.c (generate_memset_builtin): Likewise. * tree-ssa-loop-im.c (rewrite_reciprocal): Likewise. * gimple-builder.c (build_assign, build_type_cast): Likewise. * tree-vect-loop-manip.c (vect_create_cond_for_align_checks): Likewise. * value-prof.c (gimple_divmod_fixed_value, gimple_mod_pow2, gimple_mod_subtract): Likewise. * gimple-match-head.c (maybe_push_res_to_seq): Likewise. * tree-vect-patterns.c (vect_recog_dot_prod_pattern, vect_recog_sad_pattern, vect_handle_widen_op_by_const, vect_recog_widen_mult_pattern, vect_recog_pow_pattern, vect_recog_widen_sum_pattern, vect_operation_fits_smaller_type, vect_recog_over_widening_pattern, vect_recog_widen_shift_pattern, vect_recog_rotate_pattern, vect_recog_vector_vector_shift_pattern, vect_recog_divmod_pattern, vect_recog_mixed_size_cond_pattern, adjust_bool_pattern_cast, adjust_bool_pattern, vect_recog_bool_pattern): Likewise. * gimple-ssa-strength-reduction.c (create_add_on_incoming_edge, insert_initializers, introduce_cast_before_cand, replace_one_candidate): Likewise. * tree-ssa-math-opts.c (insert_reciprocals, powi_as_mults_1, powi_as_mults, build_and_insert_binop, build_and_insert_cast, pass_cse_sincos::execute, bswap_replace, convert_mult_to_fma): Likewise. * tree-tailcall.c (adjust_return_value_with_ops, update_accumulator_with_ops): Likewise. * tree-predcom.c (reassociate_to_the_same_stmt): Likewise. * tree-ssa-reassoc.c (build_and_add_sum, optimize_range_tests_to_bit_test, update_ops, maybe_optimize_range_tests, rewrite_expr_tree, linearize_expr, negate_value, repropagate_negates, attempt_builtin_powi, reassociate_bb): Likewise. * tree-vect-loop.c (vect_is_simple_reduction_1, get_initial_def_for_induction, vect_create_epilog_for_reduction): Likewise. * ipa-split.c (split_function): Likewise. * tree-ssa-phiopt.c (conditional_replacement, minmax_replacement, abs_replacement, neg_replacement): Likewise. * tree-profile.c (gimple_gen_edge_profiler): Likewise. * tree-vrp.c (simplify_truth_ops_using_ranges, simplify_float_conversion_using_ranges, simplify_internal_call_using_ranges): Likewise. * gimple-fold.c (rewrite_to_defined_overflow, gimple_build): Likewise. * tree-vect-generic.c (expand_vector_divmod, optimize_vector_constructor): Likewise. * ubsan.c (ubsan_expand_null_ifn, ubsan_expand_objsize_ifn, instrument_bool_enum_load): Likewise. * tree-ssa-loop-manip.c (create_iv): Likewise. * omp-low.c (lower_rec_input_clauses, expand_omp_for_generic, expand_omp_for_static_nochunk, expand_omp_for_static_chunk, expand_cilk_for, simd_clone_adjust): Likewise. * trans-mem.c (expand_transaction): Likewise. * tree-vect-data-refs.c (bump_vector_ptr, vect_permute_store_chain, vect_setup_realignment, vect_permute_load_chain, vect_shift_permute_load_chain): Likewise. * tree-vect-stmts.c (vect_init_vector, vectorizable_mask_load_store, vectorizable_simd_clone_call, vect_gen_widened_results_half, vect_create_vectorized_demotion_stmts, vectorizable_conversion, vectorizable_shift, vectorizable_operation, vectorizable_store, permute_vec_elements, vectorizable_load): Likewise. From-SVN: r218216
2014-12-01 14:58:10 +01:00
g = gimple_build_assign (make_ssa_name (pointer_sized_int_node),
BIT_AND_EXPR, check_align, mask);
opts.c (common_handle_option): Handle -fsanitize=alignment. * opts.c (common_handle_option): Handle -fsanitize=alignment. * ubsan.h (enum ubsan_null_ckind): Add UBSAN_CTOR_CALL. (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn): Change return type to bool. * stor-layout.h (min_align_of_type): New prototype. * asan.c (pass_sanopt::execute): Don't perform gsi_next if ubsan_expand* told us not to do it. Remove the extra gsi_end_p check. * ubsan.c: Include builtins.h. (ubsan_expand_bounds_ifn): Change return type to bool, always return true. (ubsan_expand_null_ifn): Change return type to bool, change argument to gimple_stmt_iterator *. Handle both null and alignment sanitization, take type from ckind argument's type rather than first argument. (instrument_member_call): Removed. (instrument_mem_ref): Remove t argument, add mem and base arguments. Handle both null and alignment sanitization, don't say whole struct access is member access. Build 3 argument IFN_UBSAN_NULL call instead of 2 argument. (instrument_null): Adjust instrument_mem_ref caller. Don't instrument calls here. (pass_ubsan::gate, pass_ubsan::execute): Handle SANITIZE_ALIGNMENT like SANITIZE_NULL. * stor-layout.c (min_align_of_type): New function. * flag-types.h (enum sanitize_code): Add SANITIZE_ALIGNMENT. Or it into SANITIZE_UNDEFINED. * doc/invoke.texi (-fsanitize=alignment): Document. cp/ * cp-gimplify.c (cp_genericize_r): For -fsanitize=null and/or -fsanitize=alignment call ubsan_maybe_instrument_reference for casts to REFERENCE_TYPE and ubsan_maybe_instrument_member_call for calls to member functions. c-family/ * c-common.h (min_align_of_type): Removed prototype. * c-common.c (min_align_of_type): Removed. * c-ubsan.h (ubsan_maybe_instrument_reference, ubsan_maybe_instrument_member_call): New prototypes. * c-ubsan.c: Include stor-layout.h and builtins.h. (ubsan_maybe_instrument_reference_or_call, ubsan_maybe_instrument_reference, ubsan_maybe_instrument_call): New functions. testsuite/ * c-c++-common/ubsan/align-1.c: New test. * c-c++-common/ubsan/align-2.c: New test. * c-c++-common/ubsan/align-3.c: New test. * c-c++-common/ubsan/align-4.c: New test. * c-c++-common/ubsan/align-5.c: New test. * c-c++-common/ubsan/attrib-4.c: New test. * g++.dg/ubsan/align-1.C: New test. * g++.dg/ubsan/align-2.C: New test. * g++.dg/ubsan/align-3.C: New test. * g++.dg/ubsan/attrib-1.C: New test. * g++.dg/ubsan/null-1.C: New test. * g++.dg/ubsan/null-2.C: New test. From-SVN: r213406
2014-08-01 09:52:43 +02:00
gimple_set_location (g, loc);
if (check_null)
gsi_insert_after (&gsi2, g, GSI_NEW_STMT);
else
gsi_insert_before (&gsi, g, GSI_SAME_STMT);
g = gimple_build_cond (NE_EXPR, gimple_assign_lhs (g),
build_int_cst (pointer_sized_int_node, 0),
NULL_TREE, NULL_TREE);
gimple_set_location (g, loc);
if (check_null)
gsi_insert_after (&gsi2, g, GSI_NEW_STMT);
else
/* Replace the UBSAN_NULL with a GIMPLE_COND stmt. */
gsi_replace (&gsi, g, false);
}
return false;
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
}
#define OBJSZ_MAX_OFFSET (1024 * 16)
/* Expand UBSAN_OBJECT_SIZE internal call. */
bool
ubsan_expand_objsize_ifn (gimple_stmt_iterator *gsi)
{
gimple *stmt = gsi_stmt (*gsi);
location_t loc = gimple_location (stmt);
gcc_assert (gimple_call_num_args (stmt) == 4);
tree ptr = gimple_call_arg (stmt, 0);
tree offset = gimple_call_arg (stmt, 1);
tree size = gimple_call_arg (stmt, 2);
tree ckind = gimple_call_arg (stmt, 3);
gimple_stmt_iterator gsi_orig = *gsi;
gimple *g;
/* See if we can discard the check. */
if (TREE_CODE (size) != INTEGER_CST
|| integer_all_onesp (size))
/* Yes, __builtin_object_size couldn't determine the
object size. */;
else if (TREE_CODE (offset) == INTEGER_CST
Support <, <=, > and >= for offset_int and widest_int offset_int and widest_int are supposed to be at least one bit wider than all the values they need to represent, with the extra bits being signs. Thus offset_int is effectively int128_t and widest_int is effectively intNNN_t, for target-dependent NNN. Because the types are signed, there's not really any need to specify a sign for operations like comparison. I think things would be clearer if we supported <, <=, > and >= for them (but not for wide_int, which doesn't have a sign). Tested on x86_64-linux-gnu and aarch64-linux-gnu. gcc/ * wide-int.h: Update offset_int and widest_int documentation. (WI_SIGNED_BINARY_PREDICATE_RESULT): New macro. (wi::binary_traits): Allow ordered comparisons between offset_int and offset_int, between widest_int and widest_int, and between either of these types and basic C types. (operator <, <=, >, >=): Define for the same combinations. * tree.h (tree_int_cst_lt): Use comparison operators instead of wi:: comparisons. (tree_int_cst_le): Likewise. * gimple-fold.c (fold_array_ctor_reference): Likewise. (fold_nonarray_ctor_reference): Likewise. * gimple-ssa-strength-reduction.c (record_increment): Likewise. * tree-affine.c (aff_comb_cannot_overlap_p): Likewise. * tree-parloops.c (try_transform_to_exit_first_loop_alt): Likewise. * tree-sra.c (completely_scalarize): Likewise. * tree-ssa-alias.c (stmt_kills_ref_p): Likewise. * tree-ssa-reassoc.c (extract_bit_test_mask): Likewise. * tree-vrp.c (extract_range_from_binary_expr_1): Likewise. (check_for_binary_op_overflow): Likewise. (search_for_addr_array): Likewise. * ubsan.c (ubsan_expand_objsize_ifn): Likewise. From-SVN: r235719
2016-05-02 11:39:09 +02:00
&& wi::to_widest (offset) >= -OBJSZ_MAX_OFFSET
&& wi::to_widest (offset) <= -1)
/* The offset is in range [-16K, -1]. */;
else
{
/* if (offset > objsize) */
basic_block then_bb, fallthru_bb;
gimple_stmt_iterator cond_insert_point
= create_cond_insert_point (gsi, false, false, true,
&then_bb, &fallthru_bb);
g = gimple_build_cond (GT_EXPR, offset, size, NULL_TREE, NULL_TREE);
gimple_set_location (g, loc);
gsi_insert_after (&cond_insert_point, g, GSI_NEW_STMT);
/* If the offset is small enough, we don't need the second
run-time check. */
if (TREE_CODE (offset) == INTEGER_CST
Support <, <=, > and >= for offset_int and widest_int offset_int and widest_int are supposed to be at least one bit wider than all the values they need to represent, with the extra bits being signs. Thus offset_int is effectively int128_t and widest_int is effectively intNNN_t, for target-dependent NNN. Because the types are signed, there's not really any need to specify a sign for operations like comparison. I think things would be clearer if we supported <, <=, > and >= for them (but not for wide_int, which doesn't have a sign). Tested on x86_64-linux-gnu and aarch64-linux-gnu. gcc/ * wide-int.h: Update offset_int and widest_int documentation. (WI_SIGNED_BINARY_PREDICATE_RESULT): New macro. (wi::binary_traits): Allow ordered comparisons between offset_int and offset_int, between widest_int and widest_int, and between either of these types and basic C types. (operator <, <=, >, >=): Define for the same combinations. * tree.h (tree_int_cst_lt): Use comparison operators instead of wi:: comparisons. (tree_int_cst_le): Likewise. * gimple-fold.c (fold_array_ctor_reference): Likewise. (fold_nonarray_ctor_reference): Likewise. * gimple-ssa-strength-reduction.c (record_increment): Likewise. * tree-affine.c (aff_comb_cannot_overlap_p): Likewise. * tree-parloops.c (try_transform_to_exit_first_loop_alt): Likewise. * tree-sra.c (completely_scalarize): Likewise. * tree-ssa-alias.c (stmt_kills_ref_p): Likewise. * tree-ssa-reassoc.c (extract_bit_test_mask): Likewise. * tree-vrp.c (extract_range_from_binary_expr_1): Likewise. (check_for_binary_op_overflow): Likewise. (search_for_addr_array): Likewise. * ubsan.c (ubsan_expand_objsize_ifn): Likewise. From-SVN: r235719
2016-05-02 11:39:09 +02:00
&& wi::to_widest (offset) >= 0
&& wi::to_widest (offset) <= OBJSZ_MAX_OFFSET)
*gsi = gsi_after_labels (then_bb);
else
{
/* Don't issue run-time error if (ptr > ptr + offset). That
may happen when computing a POINTER_PLUS_EXPR. */
basic_block then2_bb, fallthru2_bb;
gimple_stmt_iterator gsi2 = gsi_after_labels (then_bb);
cond_insert_point = create_cond_insert_point (&gsi2, false, false,
true, &then2_bb,
&fallthru2_bb);
/* Convert the pointer to an integer type. */
tree p = make_ssa_name (pointer_sized_int_node);
g = gimple_build_assign (p, NOP_EXPR, ptr);
gimple_set_location (g, loc);
gsi_insert_before (&cond_insert_point, g, GSI_NEW_STMT);
p = gimple_assign_lhs (g);
/* Compute ptr + offset. */
g = gimple_build_assign (make_ssa_name (pointer_sized_int_node),
PLUS_EXPR, p, offset);
gimple_set_location (g, loc);
gsi_insert_after (&cond_insert_point, g, GSI_NEW_STMT);
/* Now build the conditional and put it into the IR. */
g = gimple_build_cond (LE_EXPR, p, gimple_assign_lhs (g),
NULL_TREE, NULL_TREE);
gimple_set_location (g, loc);
gsi_insert_after (&cond_insert_point, g, GSI_NEW_STMT);
*gsi = gsi_after_labels (then2_bb);
}
/* Generate __ubsan_handle_type_mismatch call. */
if (flag_sanitize_undefined_trap_on_error)
g = gimple_build_call (builtin_decl_explicit (BUILT_IN_TRAP), 0);
else
{
tree data
= ubsan_create_data ("__ubsan_objsz_data", 1, &loc,
ubsan_type_descriptor (TREE_TYPE (ptr),
UBSAN_PRINT_POINTER),
NULL_TREE,
build_zero_cst (pointer_sized_int_node),
ckind,
NULL_TREE);
data = build_fold_addr_expr_loc (loc, data);
enum built_in_function bcode
New syntax for -fsanitize-recover. 2014-10-22 Jakub Jelinek <jakub@redhat.com> Yury Gribov <y.gribov@samsung.com> gcc/ * common.opt (flag_sanitize_recover): New variable. (fsanitize-recover): Remove Var/Init, deprecate. (fsanitize-recover=): New option. * doc/invoke.texi (fsanitize-recover): Update docs. * opts.c (finish_options): Use opts->x_flag_sanitize instead of flag_sanitize. Prohibit -fsanitize-recover for anything besides UBSan. Formatting. (common_handle_option): Handle OPT_fsanitize_recover_ and OPT_fsanitize_recover. Use opts->x_flag_sanitize instead of flag_sanitize. * asan.c (pass_sanopt::execute): Fix up formatting. * ubsan.c (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn, ubsan_expand_objsize_ifn, ubsan_build_overflow_builtin, instrument_bool_enum_load, ubsan_instrument_float_cast, instrument_nonnull_arg, instrument_nonnull_return): Check bits in flag_sanitize_recover bitmask instead of flag_sanitize_recover as bool flag. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division, ubsan_instrument_shift, ubsan_instrument_vla): Check bits in flag_sanitize_recover bitmask instead of flag_sanitize_recover as bool flag. gcc/testsuite/ * c-c++-common/ubsan/align-1.c: Update cmdline options. * c-c++-common/ubsan/align-3.c: Likewise. * c-c++-common/ubsan/bounds-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-7.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-10.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-7.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-8.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-9.c: Likewise. * c-c++-common/ubsan/nonnull-2.c: Likewise. * c-c++-common/ubsan/nonnull-3.c: Likewise. * c-c++-common/ubsan/object-size-3.c: Likewise. * c-c++-common/ubsan/overflow-1.c: Likewise. * c-c++-common/ubsan/overflow-add-1.c: Likewise. * c-c++-common/ubsan/overflow-add-3.c: Likewise. * c-c++-common/ubsan/overflow-mul-1.c: Likewise. * c-c++-common/ubsan/overflow-mul-3.c: Likewise. * c-c++-common/ubsan/overflow-negate-2.c: Likewise. * c-c++-common/ubsan/overflow-sub-1.c: Likewise. * c-c++-common/ubsan/pr59503.c: Likewise. * c-c++-common/ubsan/pr60613-1.c: Likewise. * c-c++-common/ubsan/save-expr-1.c: Likewise. * c-c++-common/ubsan/shift-3.c: Likewise. * c-c++-common/ubsan/shift-6.c: Likewise. * c-c++-common/ubsan/undefined-1.c: Likewise. * c-c++-common/ubsan/vla-2.c: Likewise. * c-c++-common/ubsan/vla-3.c: Likewise. * c-c++-common/ubsan/vla-4.c: Likewise. * g++.dg/ubsan/cxx11-shift-1.C: Likewise. * g++.dg/ubsan/return-2.C: Likewise. * c-c++-common/ubsan/recovery-1.c: New test. * c-c++-common/ubsan/recovery-2.c: New test. * c-c++-common/ubsan/recovery-3.c: New test. * c-c++-common/ubsan/recovery-common.inc: New file. Co-Authored-By: Yury Gribov <y.gribov@samsung.com> From-SVN: r216552
2014-10-22 13:07:10 +02:00
= (flag_sanitize_recover & SANITIZE_OBJECT_SIZE)
? BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH
: BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT;
gimple-expr.h (create_tmp_var_raw, [...]): Add default NULL value to last argument. * gimple-expr.h (create_tmp_var_raw, create_tmp_var, create_tmp_reg): Add default NULL value to last argument. * tree-ssanames.h (make_ssa_name, copy_ssa_name): Likewise. * gimple-low.c (lower_builtin_posix_memalign): Remove NULL last argument from create_tmp_var_raw, create_tmp_var, create_tmp_reg, make_ssa_name and copy_ssa_name calls. * tree-ssa-strlen.c (get_string_length): Likewise. * tree-emutls.c (gen_emutls_addr, lower_emutls_1): Likewise. * tree-ssa-phiprop.c (phiprop_insert_phi): Likewise. * tree-vect-slp.c (vect_get_constant_vectors): Likewise. * ipa-prop.c (ipa_modify_call_arguments): Likewise. * tree-ssa-forwprop.c (simplify_rotate): Likewise. * tree-ssa-ccp.c (fold_builtin_alloca_with_align): Likewise. * asan.c (build_shadow_mem_access, maybe_create_ssa_name, maybe_cast_to_ptrmode, asan_expand_check_ifn): Likewise. * tsan.c (instrument_expr, instrument_builtin_call, instrument_func_entry): Likewise. * varpool.c (add_new_static_var): Likewise. * tree-loop-distribution.c (generate_memset_builtin): Likewise. * gimplify.c (internal_get_tmp_var, gimplify_return_expr, gimplify_modify_expr_to_memcpy, gimplify_modify_expr_to_memset, gimplify_init_ctor_eval_range, gimplify_init_constructor, gimplify_omp_atomic, gimplify_expr): Likewise. * gimple-builder.c (build_assign, build_type_cast): Likewise. * tree-vect-loop-manip.c (slpeel_update_phi_nodes_for_guard1, slpeel_update_phi_nodes_for_guard2, slpeel_tree_peel_loop_to_edge, vect_loop_versioning): Likewise. * tree-if-conv.c (version_loop_for_if_conversion): Likewise. * gimple-match-head.c (maybe_push_res_to_seq): Likewise. * tree-vect-patterns.c (vect_handle_widen_op_by_const, vect_recog_widen_mult_pattern, vect_operation_fits_smaller_type, vect_recog_over_widening_pattern): Likewise. * tree-sra.c (build_ref_for_offset, create_access_replacement): Likewise. * tree-cfg.c (make_blocks): Likewise. * tree-eh.c (lower_eh_constructs_2, lower_resx, lower_eh_dispatch): Likewise. * tree-ssa-propagate.c (update_call_from_tree): Likewise. * tree-complex.c (get_component_ssa_name, expand_complex_div_wide): Likewise. * tree-ssa-math-opts.c (build_and_insert_cast): Likewise. * tree-tailcall.c (update_accumulator_with_ops): Likewise. * tree-predcom.c (initialize_root_vars, initialize_root_vars_lm, execute_load_motion, reassociate_to_the_same_stmt): Likewise. * tree-ssa-reassoc.c (build_and_add_sum, optimize_range_tests_to_bit_test, update_ops, maybe_optimize_range_tests, rewrite_expr_tree, linearize_expr, negate_value, repropagate_negates): Likewise. * tree-vect-loop.c (vect_is_simple_reduction_1, vect_create_epilog_for_reduction): Likewise. * ipa-split.c (split_function): Likewise. * tree-inline.c (remap_ssa_name, setup_one_parameter, declare_return_variable, tree_function_versioning): Likewise. * tree-cfgcleanup.c (fixup_noreturn_call): Likewise. * cfgexpand.c (update_alias_info_with_stack_vars, expand_used_vars): Likewise. * tree-ssa-phiopt.c (conditional_replacement, abs_replacement, neg_replacement): Likewise. * gimplify-me.c (force_gimple_operand_1, gimple_regimplify_operands): Likewise. * tree-vrp.c (simplify_truth_ops_using_ranges, simplify_float_conversion_using_ranges, simplify_internal_call_using_ranges): Likewise. * tree-switch-conversion.c (emit_case_bit_tests, build_one_array, build_arrays, gen_def_assigns): Likewise. * gimple-fold.c (gimple_fold_builtin_memory_op, gimple_fold_builtin_strcat, gimple_fold_call, gimple_build): Likewise. * tree-vect-generic.c (expand_vector_divmod, optimize_vector_constructor): Likewise. * ubsan.c (ubsan_encode_value, ubsan_expand_null_ifn, ubsan_expand_objsize_ifn, instrument_si_overflow, instrument_bool_enum_load, instrument_nonnull_arg): Likewise. * tree-outof-ssa.c (insert_backedge_copies): Likewise. * tree-ssa-loop-manip.c (create_iv, tree_transform_and_unroll_loop): Likewise. * omp-low.c (scan_omp_parallel, lower_rec_simd_input_clauses, lower_rec_input_clauses, lower_lastprivate_clauses, expand_parallel_call, expand_omp_for_static_chunk, expand_omp_atomic_pipeline, expand_omp_target, maybe_add_implicit_barrier_cancel, lower_omp_single_simple, lower_omp_critical, lower_omp_for, task_copyfn_copy_decl, lower_depend_clauses, lower_omp_target, lower_omp_1, ipa_simd_modify_stmt_ops, simd_clone_adjust): Likewise. * tree-parloops.c (take_address_of, create_phi_for_local_result, create_call_for_reduction_1, separate_decls_in_region, create_parallel_loop): Likewise. * graphite-sese-to-poly.c (rewrite_cross_bb_scalar_dependence, handle_scalar_deps_crossing_scop_limits): Likewise. * trans-mem.c (lower_transaction, build_tm_load, build_tm_store, expand_assign_tm, expand_call_tm, expand_transaction, ipa_tm_insert_gettmclone_call): Likewise. * tree-vect-data-refs.c (bump_vector_ptr, vect_setup_realignment): Likewise. * tree-vect-stmts.c (vect_init_vector, vectorizable_mask_load_store, vectorizable_call, vectorizable_simd_clone_call, vectorizable_conversion, vectorizable_store, permute_vec_elements, vectorizable_load): Likewise. c/ * c-typeck.c (convert_lvalue_to_rvalue, build_atomic_assign, c_finish_stmt_expr): Remove NULL last argument from create_tmp_var_raw and create_tmp_var calls. * c-array-notation.c (fix_builtin_array_notation_fn, build_array_notation_expr, fix_conditional_array_notations_1, fix_array_notation_expr, fix_array_notation_call_expr): Likewise. cp/ * cp-gimplify.c (cxx_omp_clause_apply_fn): Remove NULL last argument from create_tmp_var calls. c-family/ * c-common.c (convert_vector_to_pointer_for_subscript): Remove NULL last argument from create_tmp_var_raw and create_tmp_var calls. * cilk.c (gimplify_cilk_spawn): Likewise. * c-omp.c (c_finish_omp_atomic): Likewise. fortran/ * trans-openmp.c (gfc_omp_finish_clause, gfc_trans_omp_array_reduction_or_udr, gfc_trans_omp_atomic): Remove NULL last argument from create_tmp_var_raw and create_tmp_var calls. From-SVN: r218181
2014-11-29 12:35:30 +01:00
tree p = make_ssa_name (pointer_sized_int_node);
gimple.h (gimple_build_assign_stat): Remove prototype. * gimple.h (gimple_build_assign_stat): Remove prototype. (gimple_build_assign): Remove define. Add overload prototypes with tree lhs and either a tree rhs, or enum tree_code and 1, 2 or 3 tree operands. * gimple.c (gimple_build_assign_stat): Renamed to... (gimple_build_assign): ... this. Add overloads with enum tree_code and 1, 2 or 3 tree operands. (gimple_build_assign_with_ops): Remove 1 and 2 operand overloads. Rename the 3 operand overload to ... (gimple_build_assign_1): ... this. Make it static inline. * tree-ssa-strlen.c (get_string_length): Use gimple_build_assign instead of gimple_build_assign_with_ops, swap the order of first two arguments and adjust formatting where necessary. * tree-vect-slp.c (vect_get_constant_vectors, vect_create_mask_and_perm): Likewise. * tree-ssa-forwprop.c (simplify_rotate): Likewise. * asan.c (build_shadow_mem_access, maybe_create_ssa_name, maybe_cast_to_ptrmode, asan_expand_check_ifn): Likewise. * tsan.c (instrument_builtin_call): Likewise. * tree-chkp.c (chkp_compute_bounds_for_assignment, chkp_generate_extern_var_bounds): Likewise. * tree-loop-distribution.c (generate_memset_builtin): Likewise. * tree-ssa-loop-im.c (rewrite_reciprocal): Likewise. * gimple-builder.c (build_assign, build_type_cast): Likewise. * tree-vect-loop-manip.c (vect_create_cond_for_align_checks): Likewise. * value-prof.c (gimple_divmod_fixed_value, gimple_mod_pow2, gimple_mod_subtract): Likewise. * gimple-match-head.c (maybe_push_res_to_seq): Likewise. * tree-vect-patterns.c (vect_recog_dot_prod_pattern, vect_recog_sad_pattern, vect_handle_widen_op_by_const, vect_recog_widen_mult_pattern, vect_recog_pow_pattern, vect_recog_widen_sum_pattern, vect_operation_fits_smaller_type, vect_recog_over_widening_pattern, vect_recog_widen_shift_pattern, vect_recog_rotate_pattern, vect_recog_vector_vector_shift_pattern, vect_recog_divmod_pattern, vect_recog_mixed_size_cond_pattern, adjust_bool_pattern_cast, adjust_bool_pattern, vect_recog_bool_pattern): Likewise. * gimple-ssa-strength-reduction.c (create_add_on_incoming_edge, insert_initializers, introduce_cast_before_cand, replace_one_candidate): Likewise. * tree-ssa-math-opts.c (insert_reciprocals, powi_as_mults_1, powi_as_mults, build_and_insert_binop, build_and_insert_cast, pass_cse_sincos::execute, bswap_replace, convert_mult_to_fma): Likewise. * tree-tailcall.c (adjust_return_value_with_ops, update_accumulator_with_ops): Likewise. * tree-predcom.c (reassociate_to_the_same_stmt): Likewise. * tree-ssa-reassoc.c (build_and_add_sum, optimize_range_tests_to_bit_test, update_ops, maybe_optimize_range_tests, rewrite_expr_tree, linearize_expr, negate_value, repropagate_negates, attempt_builtin_powi, reassociate_bb): Likewise. * tree-vect-loop.c (vect_is_simple_reduction_1, get_initial_def_for_induction, vect_create_epilog_for_reduction): Likewise. * ipa-split.c (split_function): Likewise. * tree-ssa-phiopt.c (conditional_replacement, minmax_replacement, abs_replacement, neg_replacement): Likewise. * tree-profile.c (gimple_gen_edge_profiler): Likewise. * tree-vrp.c (simplify_truth_ops_using_ranges, simplify_float_conversion_using_ranges, simplify_internal_call_using_ranges): Likewise. * gimple-fold.c (rewrite_to_defined_overflow, gimple_build): Likewise. * tree-vect-generic.c (expand_vector_divmod, optimize_vector_constructor): Likewise. * ubsan.c (ubsan_expand_null_ifn, ubsan_expand_objsize_ifn, instrument_bool_enum_load): Likewise. * tree-ssa-loop-manip.c (create_iv): Likewise. * omp-low.c (lower_rec_input_clauses, expand_omp_for_generic, expand_omp_for_static_nochunk, expand_omp_for_static_chunk, expand_cilk_for, simd_clone_adjust): Likewise. * trans-mem.c (expand_transaction): Likewise. * tree-vect-data-refs.c (bump_vector_ptr, vect_permute_store_chain, vect_setup_realignment, vect_permute_load_chain, vect_shift_permute_load_chain): Likewise. * tree-vect-stmts.c (vect_init_vector, vectorizable_mask_load_store, vectorizable_simd_clone_call, vect_gen_widened_results_half, vect_create_vectorized_demotion_stmts, vectorizable_conversion, vectorizable_shift, vectorizable_operation, vectorizable_store, permute_vec_elements, vectorizable_load): Likewise. From-SVN: r218216
2014-12-01 14:58:10 +01:00
g = gimple_build_assign (p, NOP_EXPR, ptr);
gimple_set_location (g, loc);
gsi_insert_before (gsi, g, GSI_SAME_STMT);
g = gimple_build_call (builtin_decl_explicit (bcode), 2, data, p);
}
gimple_set_location (g, loc);
gsi_insert_before (gsi, g, GSI_SAME_STMT);
/* Point GSI to next logical statement. */
*gsi = gsi_start_bb (fallthru_bb);
/* Get rid of the UBSAN_OBJECT_SIZE call from the IR. */
unlink_stmt_vdef (stmt);
gsi_remove (&gsi_orig, true);
return true;
}
/* Get rid of the UBSAN_OBJECT_SIZE call from the IR. */
unlink_stmt_vdef (stmt);
gsi_remove (gsi, true);
return true;
}
flag-types.h (enum sanitize_code): Add SANITIZE_VPTR, include SANITIZE_VPTR in SANITIZE_UNDEFINED. * flag-types.h (enum sanitize_code): Add SANITIZE_VPTR, include SANITIZE_VPTR in SANITIZE_UNDEFINED. * opts.c (common_handle_option): Add -fsanitize=vptr. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_DYNAMIC_TYPE_CACHE_MISS, BUILT_IN_UBSAN_HANDLE_DYNAMIC_TYPE_CACHE_MISS_ABORT): New. * ubsan.h (enum ubsan_null_ckind): Add UBSAN_DOWNCAST_POINTER, UBSAN_DOWNCAST_REFERENCE, UBSAN_UPCAST and UBSAN_CAST_TO_VBASE. (ubsan_expand_vptr_ifn): New prototype. * internal-fn.c (expand_ANNOTATE, expand_GOMP_SIMD_LANE, expand_GOMP_SIMD_VF, expand_GOMP_SIMD_LAST_LANE, expand_UBSAN_NULL, expand_UBSAN_BOUNDS, expand_UBSAN_OBJECT_SIZE, expand_ASAN_CHECK, expand_LOOP_VECTORIZED): Make argument nameless, remove ATTRIBUTE_UNUSED. (expand_UBSAN_VPTR): New function. * internal-fn.def (UBSAN_NULL, ASAN_CHECK): Use R instead of W in fn spec. (UBSAN_VPTR): New internal function. * sanopt.c (tree_map_traits): Renamed to ... (sanopt_tree_map_traits): ... this. (sanopt_tree_triplet, sanopt_tree_triplet_map_traits): New classes. (sanopt_ctx): Adjust asan_check_map type for tree_map_traits to sanopt_tree_map_traits renaming. Add vptr_check_map field. (maybe_optimize_ubsan_vptr_ifn): New function. (sanopt_optimize_walker): Handle IFN_UBSAN_VPTR. (pass_sanopt::execute): Likewise. Call sanopt_optimize even for -fsanitize=vptr. * tree-ssa-alias.c (call_may_clobber_ref_p_1): Handle certain internal calls like pure functions for aliasing, even when they have other side-effects that prevent making them ECF_PURE. * ubsan.c (ubsan_vptr_type_cache_decl): New variable. (ubsan_expand_vptr_ifn): New function. cp/ * cp-gimplify.c (cp_genericize_r): Call cp_ubsan_maybe_instrument_member_call for member calls. (cp_ubsan_check_member_access_r): New function. (cp_genericize_tree): Call cp_ubsan_instrument_member_accesses. * cp-tree.h (cp_ubsan_maybe_instrument_member_call, cp_ubsan_instrument_member_accesses, cp_ubsan_maybe_instrument_downcast, cp_ubsan_maybe_instrument_cast_to_vbase): New prototypes. * cp-ubsan.c: New file. * Make-lang.in (CXX_AND_OBJCXX_OBJS): Add cp/cp-ubsan.o. * constexpr.c (cxx_eval_call_expression): Return void_node for IFN_UBSAN_VPTR. (potential_constant_expression_1): Return true for UBSAN_NULL, UBSAN_BOUNDS and UBSAN_VPTR internal calls. * typeck.c (build_class_member_access_expr): Provide locus for COMPONENT_REFs. (build_static_cast_1): Instrument downcasts. * class.c (build_base_path): For -fsanitize=vptr and !fixed_type_p add ubsan instrumentation for virtual_access. * call.c: Include internal-fn.h. (set_flags_from_callee): Handle internal calls. gcc/testsuite/ * g++.dg/ubsan/vptr-1.C: New test. * g++.dg/ubsan/vptr-2.C: New test. * g++.dg/ubsan/vptr-3.C: New test. * g++.dg/ubsan/vptr-4.C: New test. * g++.dg/ubsan/vptr-5.C: New test. * g++.dg/ubsan/vptr-6.C: New test. * g++.dg/ubsan/vptr-7.C: New test. * g++.dg/ubsan/vptr-8.C: New test. * g++.dg/ubsan/vptr-9.C: New test. From-SVN: r219695
2015-01-15 23:58:42 +01:00
/* Cached __ubsan_vptr_type_cache decl. */
static GTY(()) tree ubsan_vptr_type_cache_decl;
/* Expand UBSAN_VPTR internal call. The type is kept on the ckind
argument which is a constant, because the middle-end treats pointer
conversions as useless and therefore the type of the first argument
could be changed to any other pointer type. */
bool
ubsan_expand_vptr_ifn (gimple_stmt_iterator *gsip)
{
gimple_stmt_iterator gsi = *gsip;
gimple *stmt = gsi_stmt (gsi);
flag-types.h (enum sanitize_code): Add SANITIZE_VPTR, include SANITIZE_VPTR in SANITIZE_UNDEFINED. * flag-types.h (enum sanitize_code): Add SANITIZE_VPTR, include SANITIZE_VPTR in SANITIZE_UNDEFINED. * opts.c (common_handle_option): Add -fsanitize=vptr. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_DYNAMIC_TYPE_CACHE_MISS, BUILT_IN_UBSAN_HANDLE_DYNAMIC_TYPE_CACHE_MISS_ABORT): New. * ubsan.h (enum ubsan_null_ckind): Add UBSAN_DOWNCAST_POINTER, UBSAN_DOWNCAST_REFERENCE, UBSAN_UPCAST and UBSAN_CAST_TO_VBASE. (ubsan_expand_vptr_ifn): New prototype. * internal-fn.c (expand_ANNOTATE, expand_GOMP_SIMD_LANE, expand_GOMP_SIMD_VF, expand_GOMP_SIMD_LAST_LANE, expand_UBSAN_NULL, expand_UBSAN_BOUNDS, expand_UBSAN_OBJECT_SIZE, expand_ASAN_CHECK, expand_LOOP_VECTORIZED): Make argument nameless, remove ATTRIBUTE_UNUSED. (expand_UBSAN_VPTR): New function. * internal-fn.def (UBSAN_NULL, ASAN_CHECK): Use R instead of W in fn spec. (UBSAN_VPTR): New internal function. * sanopt.c (tree_map_traits): Renamed to ... (sanopt_tree_map_traits): ... this. (sanopt_tree_triplet, sanopt_tree_triplet_map_traits): New classes. (sanopt_ctx): Adjust asan_check_map type for tree_map_traits to sanopt_tree_map_traits renaming. Add vptr_check_map field. (maybe_optimize_ubsan_vptr_ifn): New function. (sanopt_optimize_walker): Handle IFN_UBSAN_VPTR. (pass_sanopt::execute): Likewise. Call sanopt_optimize even for -fsanitize=vptr. * tree-ssa-alias.c (call_may_clobber_ref_p_1): Handle certain internal calls like pure functions for aliasing, even when they have other side-effects that prevent making them ECF_PURE. * ubsan.c (ubsan_vptr_type_cache_decl): New variable. (ubsan_expand_vptr_ifn): New function. cp/ * cp-gimplify.c (cp_genericize_r): Call cp_ubsan_maybe_instrument_member_call for member calls. (cp_ubsan_check_member_access_r): New function. (cp_genericize_tree): Call cp_ubsan_instrument_member_accesses. * cp-tree.h (cp_ubsan_maybe_instrument_member_call, cp_ubsan_instrument_member_accesses, cp_ubsan_maybe_instrument_downcast, cp_ubsan_maybe_instrument_cast_to_vbase): New prototypes. * cp-ubsan.c: New file. * Make-lang.in (CXX_AND_OBJCXX_OBJS): Add cp/cp-ubsan.o. * constexpr.c (cxx_eval_call_expression): Return void_node for IFN_UBSAN_VPTR. (potential_constant_expression_1): Return true for UBSAN_NULL, UBSAN_BOUNDS and UBSAN_VPTR internal calls. * typeck.c (build_class_member_access_expr): Provide locus for COMPONENT_REFs. (build_static_cast_1): Instrument downcasts. * class.c (build_base_path): For -fsanitize=vptr and !fixed_type_p add ubsan instrumentation for virtual_access. * call.c: Include internal-fn.h. (set_flags_from_callee): Handle internal calls. gcc/testsuite/ * g++.dg/ubsan/vptr-1.C: New test. * g++.dg/ubsan/vptr-2.C: New test. * g++.dg/ubsan/vptr-3.C: New test. * g++.dg/ubsan/vptr-4.C: New test. * g++.dg/ubsan/vptr-5.C: New test. * g++.dg/ubsan/vptr-6.C: New test. * g++.dg/ubsan/vptr-7.C: New test. * g++.dg/ubsan/vptr-8.C: New test. * g++.dg/ubsan/vptr-9.C: New test. From-SVN: r219695
2015-01-15 23:58:42 +01:00
location_t loc = gimple_location (stmt);
gcc_assert (gimple_call_num_args (stmt) == 5);
tree op = gimple_call_arg (stmt, 0);
tree vptr = gimple_call_arg (stmt, 1);
tree str_hash = gimple_call_arg (stmt, 2);
tree ti_decl_addr = gimple_call_arg (stmt, 3);
tree ckind_tree = gimple_call_arg (stmt, 4);
ubsan_null_ckind ckind = (ubsan_null_ckind) tree_to_uhwi (ckind_tree);
tree type = TREE_TYPE (TREE_TYPE (ckind_tree));
gimple *g;
flag-types.h (enum sanitize_code): Add SANITIZE_VPTR, include SANITIZE_VPTR in SANITIZE_UNDEFINED. * flag-types.h (enum sanitize_code): Add SANITIZE_VPTR, include SANITIZE_VPTR in SANITIZE_UNDEFINED. * opts.c (common_handle_option): Add -fsanitize=vptr. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_DYNAMIC_TYPE_CACHE_MISS, BUILT_IN_UBSAN_HANDLE_DYNAMIC_TYPE_CACHE_MISS_ABORT): New. * ubsan.h (enum ubsan_null_ckind): Add UBSAN_DOWNCAST_POINTER, UBSAN_DOWNCAST_REFERENCE, UBSAN_UPCAST and UBSAN_CAST_TO_VBASE. (ubsan_expand_vptr_ifn): New prototype. * internal-fn.c (expand_ANNOTATE, expand_GOMP_SIMD_LANE, expand_GOMP_SIMD_VF, expand_GOMP_SIMD_LAST_LANE, expand_UBSAN_NULL, expand_UBSAN_BOUNDS, expand_UBSAN_OBJECT_SIZE, expand_ASAN_CHECK, expand_LOOP_VECTORIZED): Make argument nameless, remove ATTRIBUTE_UNUSED. (expand_UBSAN_VPTR): New function. * internal-fn.def (UBSAN_NULL, ASAN_CHECK): Use R instead of W in fn spec. (UBSAN_VPTR): New internal function. * sanopt.c (tree_map_traits): Renamed to ... (sanopt_tree_map_traits): ... this. (sanopt_tree_triplet, sanopt_tree_triplet_map_traits): New classes. (sanopt_ctx): Adjust asan_check_map type for tree_map_traits to sanopt_tree_map_traits renaming. Add vptr_check_map field. (maybe_optimize_ubsan_vptr_ifn): New function. (sanopt_optimize_walker): Handle IFN_UBSAN_VPTR. (pass_sanopt::execute): Likewise. Call sanopt_optimize even for -fsanitize=vptr. * tree-ssa-alias.c (call_may_clobber_ref_p_1): Handle certain internal calls like pure functions for aliasing, even when they have other side-effects that prevent making them ECF_PURE. * ubsan.c (ubsan_vptr_type_cache_decl): New variable. (ubsan_expand_vptr_ifn): New function. cp/ * cp-gimplify.c (cp_genericize_r): Call cp_ubsan_maybe_instrument_member_call for member calls. (cp_ubsan_check_member_access_r): New function. (cp_genericize_tree): Call cp_ubsan_instrument_member_accesses. * cp-tree.h (cp_ubsan_maybe_instrument_member_call, cp_ubsan_instrument_member_accesses, cp_ubsan_maybe_instrument_downcast, cp_ubsan_maybe_instrument_cast_to_vbase): New prototypes. * cp-ubsan.c: New file. * Make-lang.in (CXX_AND_OBJCXX_OBJS): Add cp/cp-ubsan.o. * constexpr.c (cxx_eval_call_expression): Return void_node for IFN_UBSAN_VPTR. (potential_constant_expression_1): Return true for UBSAN_NULL, UBSAN_BOUNDS and UBSAN_VPTR internal calls. * typeck.c (build_class_member_access_expr): Provide locus for COMPONENT_REFs. (build_static_cast_1): Instrument downcasts. * class.c (build_base_path): For -fsanitize=vptr and !fixed_type_p add ubsan instrumentation for virtual_access. * call.c: Include internal-fn.h. (set_flags_from_callee): Handle internal calls. gcc/testsuite/ * g++.dg/ubsan/vptr-1.C: New test. * g++.dg/ubsan/vptr-2.C: New test. * g++.dg/ubsan/vptr-3.C: New test. * g++.dg/ubsan/vptr-4.C: New test. * g++.dg/ubsan/vptr-5.C: New test. * g++.dg/ubsan/vptr-6.C: New test. * g++.dg/ubsan/vptr-7.C: New test. * g++.dg/ubsan/vptr-8.C: New test. * g++.dg/ubsan/vptr-9.C: New test. From-SVN: r219695
2015-01-15 23:58:42 +01:00
basic_block fallthru_bb = NULL;
if (ckind == UBSAN_DOWNCAST_POINTER)
{
/* Guard everything with if (op != NULL) { ... }. */
basic_block then_bb;
gimple_stmt_iterator cond_insert_point
= create_cond_insert_point (gsip, false, false, true,
&then_bb, &fallthru_bb);
g = gimple_build_cond (NE_EXPR, op, build_zero_cst (TREE_TYPE (op)),
NULL_TREE, NULL_TREE);
gimple_set_location (g, loc);
gsi_insert_after (&cond_insert_point, g, GSI_NEW_STMT);
*gsip = gsi_after_labels (then_bb);
gsi_remove (&gsi, false);
gsi_insert_before (gsip, stmt, GSI_NEW_STMT);
gsi = *gsip;
}
tree htype = TREE_TYPE (str_hash);
tree cst = wide_int_to_tree (htype,
wi::uhwi (((uint64_t) 0x9ddfea08 << 32)
| 0xeb382d69, 64));
g = gimple_build_assign (make_ssa_name (htype), BIT_XOR_EXPR,
vptr, str_hash);
gimple_set_location (g, loc);
gsi_insert_before (gsip, g, GSI_SAME_STMT);
g = gimple_build_assign (make_ssa_name (htype), MULT_EXPR,
gimple_assign_lhs (g), cst);
gimple_set_location (g, loc);
gsi_insert_before (gsip, g, GSI_SAME_STMT);
tree t1 = gimple_assign_lhs (g);
g = gimple_build_assign (make_ssa_name (htype), LSHIFT_EXPR,
t1, build_int_cst (integer_type_node, 47));
gimple_set_location (g, loc);
tree t2 = gimple_assign_lhs (g);
gsi_insert_before (gsip, g, GSI_SAME_STMT);
g = gimple_build_assign (make_ssa_name (htype), BIT_XOR_EXPR,
vptr, t1);
gimple_set_location (g, loc);
gsi_insert_before (gsip, g, GSI_SAME_STMT);
g = gimple_build_assign (make_ssa_name (htype), BIT_XOR_EXPR,
t2, gimple_assign_lhs (g));
gimple_set_location (g, loc);
gsi_insert_before (gsip, g, GSI_SAME_STMT);
g = gimple_build_assign (make_ssa_name (htype), MULT_EXPR,
gimple_assign_lhs (g), cst);
gimple_set_location (g, loc);
gsi_insert_before (gsip, g, GSI_SAME_STMT);
tree t3 = gimple_assign_lhs (g);
g = gimple_build_assign (make_ssa_name (htype), LSHIFT_EXPR,
t3, build_int_cst (integer_type_node, 47));
gimple_set_location (g, loc);
gsi_insert_before (gsip, g, GSI_SAME_STMT);
g = gimple_build_assign (make_ssa_name (htype), BIT_XOR_EXPR,
t3, gimple_assign_lhs (g));
gimple_set_location (g, loc);
gsi_insert_before (gsip, g, GSI_SAME_STMT);
g = gimple_build_assign (make_ssa_name (htype), MULT_EXPR,
gimple_assign_lhs (g), cst);
gimple_set_location (g, loc);
gsi_insert_before (gsip, g, GSI_SAME_STMT);
if (!useless_type_conversion_p (pointer_sized_int_node, htype))
{
g = gimple_build_assign (make_ssa_name (pointer_sized_int_node),
NOP_EXPR, gimple_assign_lhs (g));
gimple_set_location (g, loc);
gsi_insert_before (gsip, g, GSI_SAME_STMT);
}
tree hash = gimple_assign_lhs (g);
if (ubsan_vptr_type_cache_decl == NULL_TREE)
{
tree atype = build_array_type_nelts (pointer_sized_int_node, 128);
tree array = build_decl (UNKNOWN_LOCATION, VAR_DECL,
get_identifier ("__ubsan_vptr_type_cache"),
atype);
DECL_ARTIFICIAL (array) = 1;
DECL_IGNORED_P (array) = 1;
TREE_PUBLIC (array) = 1;
TREE_STATIC (array) = 1;
DECL_EXTERNAL (array) = 1;
DECL_VISIBILITY (array) = VISIBILITY_DEFAULT;
DECL_VISIBILITY_SPECIFIED (array) = 1;
varpool_node::finalize_decl (array);
ubsan_vptr_type_cache_decl = array;
}
g = gimple_build_assign (make_ssa_name (pointer_sized_int_node),
BIT_AND_EXPR, hash,
build_int_cst (pointer_sized_int_node, 127));
gimple_set_location (g, loc);
gsi_insert_before (gsip, g, GSI_SAME_STMT);
tree c = build4_loc (loc, ARRAY_REF, pointer_sized_int_node,
ubsan_vptr_type_cache_decl, gimple_assign_lhs (g),
NULL_TREE, NULL_TREE);
g = gimple_build_assign (make_ssa_name (pointer_sized_int_node),
ARRAY_REF, c);
gimple_set_location (g, loc);
gsi_insert_before (gsip, g, GSI_SAME_STMT);
basic_block then_bb, fallthru2_bb;
gimple_stmt_iterator cond_insert_point
= create_cond_insert_point (gsip, false, false, true,
&then_bb, &fallthru2_bb);
g = gimple_build_cond (NE_EXPR, gimple_assign_lhs (g), hash,
NULL_TREE, NULL_TREE);
gimple_set_location (g, loc);
gsi_insert_after (&cond_insert_point, g, GSI_NEW_STMT);
*gsip = gsi_after_labels (then_bb);
if (fallthru_bb == NULL)
fallthru_bb = fallthru2_bb;
tree data
= ubsan_create_data ("__ubsan_vptr_data", 1, &loc,
ubsan_type_descriptor (type), NULL_TREE, ti_decl_addr,
build_int_cst (unsigned_char_type_node, ckind),
NULL_TREE);
data = build_fold_addr_expr_loc (loc, data);
enum built_in_function bcode
= (flag_sanitize_recover & SANITIZE_VPTR)
? BUILT_IN_UBSAN_HANDLE_DYNAMIC_TYPE_CACHE_MISS
: BUILT_IN_UBSAN_HANDLE_DYNAMIC_TYPE_CACHE_MISS_ABORT;
g = gimple_build_call (builtin_decl_explicit (bcode), 3, data, op, hash);
gimple_set_location (g, loc);
gsi_insert_before (gsip, g, GSI_SAME_STMT);
/* Point GSI to next logical statement. */
*gsip = gsi_start_bb (fallthru_bb);
/* Get rid of the UBSAN_VPTR call from the IR. */
unlink_stmt_vdef (stmt);
gsi_remove (&gsi, true);
return true;
flag-types.h (enum sanitize_code): Add SANITIZE_VPTR, include SANITIZE_VPTR in SANITIZE_UNDEFINED. * flag-types.h (enum sanitize_code): Add SANITIZE_VPTR, include SANITIZE_VPTR in SANITIZE_UNDEFINED. * opts.c (common_handle_option): Add -fsanitize=vptr. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_DYNAMIC_TYPE_CACHE_MISS, BUILT_IN_UBSAN_HANDLE_DYNAMIC_TYPE_CACHE_MISS_ABORT): New. * ubsan.h (enum ubsan_null_ckind): Add UBSAN_DOWNCAST_POINTER, UBSAN_DOWNCAST_REFERENCE, UBSAN_UPCAST and UBSAN_CAST_TO_VBASE. (ubsan_expand_vptr_ifn): New prototype. * internal-fn.c (expand_ANNOTATE, expand_GOMP_SIMD_LANE, expand_GOMP_SIMD_VF, expand_GOMP_SIMD_LAST_LANE, expand_UBSAN_NULL, expand_UBSAN_BOUNDS, expand_UBSAN_OBJECT_SIZE, expand_ASAN_CHECK, expand_LOOP_VECTORIZED): Make argument nameless, remove ATTRIBUTE_UNUSED. (expand_UBSAN_VPTR): New function. * internal-fn.def (UBSAN_NULL, ASAN_CHECK): Use R instead of W in fn spec. (UBSAN_VPTR): New internal function. * sanopt.c (tree_map_traits): Renamed to ... (sanopt_tree_map_traits): ... this. (sanopt_tree_triplet, sanopt_tree_triplet_map_traits): New classes. (sanopt_ctx): Adjust asan_check_map type for tree_map_traits to sanopt_tree_map_traits renaming. Add vptr_check_map field. (maybe_optimize_ubsan_vptr_ifn): New function. (sanopt_optimize_walker): Handle IFN_UBSAN_VPTR. (pass_sanopt::execute): Likewise. Call sanopt_optimize even for -fsanitize=vptr. * tree-ssa-alias.c (call_may_clobber_ref_p_1): Handle certain internal calls like pure functions for aliasing, even when they have other side-effects that prevent making them ECF_PURE. * ubsan.c (ubsan_vptr_type_cache_decl): New variable. (ubsan_expand_vptr_ifn): New function. cp/ * cp-gimplify.c (cp_genericize_r): Call cp_ubsan_maybe_instrument_member_call for member calls. (cp_ubsan_check_member_access_r): New function. (cp_genericize_tree): Call cp_ubsan_instrument_member_accesses. * cp-tree.h (cp_ubsan_maybe_instrument_member_call, cp_ubsan_instrument_member_accesses, cp_ubsan_maybe_instrument_downcast, cp_ubsan_maybe_instrument_cast_to_vbase): New prototypes. * cp-ubsan.c: New file. * Make-lang.in (CXX_AND_OBJCXX_OBJS): Add cp/cp-ubsan.o. * constexpr.c (cxx_eval_call_expression): Return void_node for IFN_UBSAN_VPTR. (potential_constant_expression_1): Return true for UBSAN_NULL, UBSAN_BOUNDS and UBSAN_VPTR internal calls. * typeck.c (build_class_member_access_expr): Provide locus for COMPONENT_REFs. (build_static_cast_1): Instrument downcasts. * class.c (build_base_path): For -fsanitize=vptr and !fixed_type_p add ubsan instrumentation for virtual_access. * call.c: Include internal-fn.h. (set_flags_from_callee): Handle internal calls. gcc/testsuite/ * g++.dg/ubsan/vptr-1.C: New test. * g++.dg/ubsan/vptr-2.C: New test. * g++.dg/ubsan/vptr-3.C: New test. * g++.dg/ubsan/vptr-4.C: New test. * g++.dg/ubsan/vptr-5.C: New test. * g++.dg/ubsan/vptr-6.C: New test. * g++.dg/ubsan/vptr-7.C: New test. * g++.dg/ubsan/vptr-8.C: New test. * g++.dg/ubsan/vptr-9.C: New test. From-SVN: r219695
2015-01-15 23:58:42 +01:00
}
opts.c (common_handle_option): Handle -fsanitize=alignment. * opts.c (common_handle_option): Handle -fsanitize=alignment. * ubsan.h (enum ubsan_null_ckind): Add UBSAN_CTOR_CALL. (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn): Change return type to bool. * stor-layout.h (min_align_of_type): New prototype. * asan.c (pass_sanopt::execute): Don't perform gsi_next if ubsan_expand* told us not to do it. Remove the extra gsi_end_p check. * ubsan.c: Include builtins.h. (ubsan_expand_bounds_ifn): Change return type to bool, always return true. (ubsan_expand_null_ifn): Change return type to bool, change argument to gimple_stmt_iterator *. Handle both null and alignment sanitization, take type from ckind argument's type rather than first argument. (instrument_member_call): Removed. (instrument_mem_ref): Remove t argument, add mem and base arguments. Handle both null and alignment sanitization, don't say whole struct access is member access. Build 3 argument IFN_UBSAN_NULL call instead of 2 argument. (instrument_null): Adjust instrument_mem_ref caller. Don't instrument calls here. (pass_ubsan::gate, pass_ubsan::execute): Handle SANITIZE_ALIGNMENT like SANITIZE_NULL. * stor-layout.c (min_align_of_type): New function. * flag-types.h (enum sanitize_code): Add SANITIZE_ALIGNMENT. Or it into SANITIZE_UNDEFINED. * doc/invoke.texi (-fsanitize=alignment): Document. cp/ * cp-gimplify.c (cp_genericize_r): For -fsanitize=null and/or -fsanitize=alignment call ubsan_maybe_instrument_reference for casts to REFERENCE_TYPE and ubsan_maybe_instrument_member_call for calls to member functions. c-family/ * c-common.h (min_align_of_type): Removed prototype. * c-common.c (min_align_of_type): Removed. * c-ubsan.h (ubsan_maybe_instrument_reference, ubsan_maybe_instrument_member_call): New prototypes. * c-ubsan.c: Include stor-layout.h and builtins.h. (ubsan_maybe_instrument_reference_or_call, ubsan_maybe_instrument_reference, ubsan_maybe_instrument_call): New functions. testsuite/ * c-c++-common/ubsan/align-1.c: New test. * c-c++-common/ubsan/align-2.c: New test. * c-c++-common/ubsan/align-3.c: New test. * c-c++-common/ubsan/align-4.c: New test. * c-c++-common/ubsan/align-5.c: New test. * c-c++-common/ubsan/attrib-4.c: New test. * g++.dg/ubsan/align-1.C: New test. * g++.dg/ubsan/align-2.C: New test. * g++.dg/ubsan/align-3.C: New test. * g++.dg/ubsan/attrib-1.C: New test. * g++.dg/ubsan/null-1.C: New test. * g++.dg/ubsan/null-2.C: New test. From-SVN: r213406
2014-08-01 09:52:43 +02:00
/* Instrument a memory reference. BASE is the base of MEM, IS_LHS says
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
whether the pointer is on the left hand side of the assignment. */
static void
opts.c (common_handle_option): Handle -fsanitize=alignment. * opts.c (common_handle_option): Handle -fsanitize=alignment. * ubsan.h (enum ubsan_null_ckind): Add UBSAN_CTOR_CALL. (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn): Change return type to bool. * stor-layout.h (min_align_of_type): New prototype. * asan.c (pass_sanopt::execute): Don't perform gsi_next if ubsan_expand* told us not to do it. Remove the extra gsi_end_p check. * ubsan.c: Include builtins.h. (ubsan_expand_bounds_ifn): Change return type to bool, always return true. (ubsan_expand_null_ifn): Change return type to bool, change argument to gimple_stmt_iterator *. Handle both null and alignment sanitization, take type from ckind argument's type rather than first argument. (instrument_member_call): Removed. (instrument_mem_ref): Remove t argument, add mem and base arguments. Handle both null and alignment sanitization, don't say whole struct access is member access. Build 3 argument IFN_UBSAN_NULL call instead of 2 argument. (instrument_null): Adjust instrument_mem_ref caller. Don't instrument calls here. (pass_ubsan::gate, pass_ubsan::execute): Handle SANITIZE_ALIGNMENT like SANITIZE_NULL. * stor-layout.c (min_align_of_type): New function. * flag-types.h (enum sanitize_code): Add SANITIZE_ALIGNMENT. Or it into SANITIZE_UNDEFINED. * doc/invoke.texi (-fsanitize=alignment): Document. cp/ * cp-gimplify.c (cp_genericize_r): For -fsanitize=null and/or -fsanitize=alignment call ubsan_maybe_instrument_reference for casts to REFERENCE_TYPE and ubsan_maybe_instrument_member_call for calls to member functions. c-family/ * c-common.h (min_align_of_type): Removed prototype. * c-common.c (min_align_of_type): Removed. * c-ubsan.h (ubsan_maybe_instrument_reference, ubsan_maybe_instrument_member_call): New prototypes. * c-ubsan.c: Include stor-layout.h and builtins.h. (ubsan_maybe_instrument_reference_or_call, ubsan_maybe_instrument_reference, ubsan_maybe_instrument_call): New functions. testsuite/ * c-c++-common/ubsan/align-1.c: New test. * c-c++-common/ubsan/align-2.c: New test. * c-c++-common/ubsan/align-3.c: New test. * c-c++-common/ubsan/align-4.c: New test. * c-c++-common/ubsan/align-5.c: New test. * c-c++-common/ubsan/attrib-4.c: New test. * g++.dg/ubsan/align-1.C: New test. * g++.dg/ubsan/align-2.C: New test. * g++.dg/ubsan/align-3.C: New test. * g++.dg/ubsan/attrib-1.C: New test. * g++.dg/ubsan/null-1.C: New test. * g++.dg/ubsan/null-2.C: New test. From-SVN: r213406
2014-08-01 09:52:43 +02:00
instrument_mem_ref (tree mem, tree base, gimple_stmt_iterator *iter,
bool is_lhs)
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
{
enum ubsan_null_ckind ikind = is_lhs ? UBSAN_STORE_OF : UBSAN_LOAD_OF;
opts.c (common_handle_option): Handle -fsanitize=alignment. * opts.c (common_handle_option): Handle -fsanitize=alignment. * ubsan.h (enum ubsan_null_ckind): Add UBSAN_CTOR_CALL. (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn): Change return type to bool. * stor-layout.h (min_align_of_type): New prototype. * asan.c (pass_sanopt::execute): Don't perform gsi_next if ubsan_expand* told us not to do it. Remove the extra gsi_end_p check. * ubsan.c: Include builtins.h. (ubsan_expand_bounds_ifn): Change return type to bool, always return true. (ubsan_expand_null_ifn): Change return type to bool, change argument to gimple_stmt_iterator *. Handle both null and alignment sanitization, take type from ckind argument's type rather than first argument. (instrument_member_call): Removed. (instrument_mem_ref): Remove t argument, add mem and base arguments. Handle both null and alignment sanitization, don't say whole struct access is member access. Build 3 argument IFN_UBSAN_NULL call instead of 2 argument. (instrument_null): Adjust instrument_mem_ref caller. Don't instrument calls here. (pass_ubsan::gate, pass_ubsan::execute): Handle SANITIZE_ALIGNMENT like SANITIZE_NULL. * stor-layout.c (min_align_of_type): New function. * flag-types.h (enum sanitize_code): Add SANITIZE_ALIGNMENT. Or it into SANITIZE_UNDEFINED. * doc/invoke.texi (-fsanitize=alignment): Document. cp/ * cp-gimplify.c (cp_genericize_r): For -fsanitize=null and/or -fsanitize=alignment call ubsan_maybe_instrument_reference for casts to REFERENCE_TYPE and ubsan_maybe_instrument_member_call for calls to member functions. c-family/ * c-common.h (min_align_of_type): Removed prototype. * c-common.c (min_align_of_type): Removed. * c-ubsan.h (ubsan_maybe_instrument_reference, ubsan_maybe_instrument_member_call): New prototypes. * c-ubsan.c: Include stor-layout.h and builtins.h. (ubsan_maybe_instrument_reference_or_call, ubsan_maybe_instrument_reference, ubsan_maybe_instrument_call): New functions. testsuite/ * c-c++-common/ubsan/align-1.c: New test. * c-c++-common/ubsan/align-2.c: New test. * c-c++-common/ubsan/align-3.c: New test. * c-c++-common/ubsan/align-4.c: New test. * c-c++-common/ubsan/align-5.c: New test. * c-c++-common/ubsan/attrib-4.c: New test. * g++.dg/ubsan/align-1.C: New test. * g++.dg/ubsan/align-2.C: New test. * g++.dg/ubsan/align-3.C: New test. * g++.dg/ubsan/attrib-1.C: New test. * g++.dg/ubsan/null-1.C: New test. * g++.dg/ubsan/null-2.C: New test. From-SVN: r213406
2014-08-01 09:52:43 +02:00
unsigned int align = 0;
if (flag_sanitize & SANITIZE_ALIGNMENT)
{
align = min_align_of_type (TREE_TYPE (base));
if (align <= 1)
align = 0;
}
if (align == 0 && (flag_sanitize & SANITIZE_NULL) == 0)
return;
tree t = TREE_OPERAND (base, 0);
if (!POINTER_TYPE_P (TREE_TYPE (t)))
return;
if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (base)) && mem != base)
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
ikind = UBSAN_MEMBER_ACCESS;
tree kind = build_int_cst (build_pointer_type (TREE_TYPE (base)), ikind);
opts.c (common_handle_option): Handle -fsanitize=alignment. * opts.c (common_handle_option): Handle -fsanitize=alignment. * ubsan.h (enum ubsan_null_ckind): Add UBSAN_CTOR_CALL. (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn): Change return type to bool. * stor-layout.h (min_align_of_type): New prototype. * asan.c (pass_sanopt::execute): Don't perform gsi_next if ubsan_expand* told us not to do it. Remove the extra gsi_end_p check. * ubsan.c: Include builtins.h. (ubsan_expand_bounds_ifn): Change return type to bool, always return true. (ubsan_expand_null_ifn): Change return type to bool, change argument to gimple_stmt_iterator *. Handle both null and alignment sanitization, take type from ckind argument's type rather than first argument. (instrument_member_call): Removed. (instrument_mem_ref): Remove t argument, add mem and base arguments. Handle both null and alignment sanitization, don't say whole struct access is member access. Build 3 argument IFN_UBSAN_NULL call instead of 2 argument. (instrument_null): Adjust instrument_mem_ref caller. Don't instrument calls here. (pass_ubsan::gate, pass_ubsan::execute): Handle SANITIZE_ALIGNMENT like SANITIZE_NULL. * stor-layout.c (min_align_of_type): New function. * flag-types.h (enum sanitize_code): Add SANITIZE_ALIGNMENT. Or it into SANITIZE_UNDEFINED. * doc/invoke.texi (-fsanitize=alignment): Document. cp/ * cp-gimplify.c (cp_genericize_r): For -fsanitize=null and/or -fsanitize=alignment call ubsan_maybe_instrument_reference for casts to REFERENCE_TYPE and ubsan_maybe_instrument_member_call for calls to member functions. c-family/ * c-common.h (min_align_of_type): Removed prototype. * c-common.c (min_align_of_type): Removed. * c-ubsan.h (ubsan_maybe_instrument_reference, ubsan_maybe_instrument_member_call): New prototypes. * c-ubsan.c: Include stor-layout.h and builtins.h. (ubsan_maybe_instrument_reference_or_call, ubsan_maybe_instrument_reference, ubsan_maybe_instrument_call): New functions. testsuite/ * c-c++-common/ubsan/align-1.c: New test. * c-c++-common/ubsan/align-2.c: New test. * c-c++-common/ubsan/align-3.c: New test. * c-c++-common/ubsan/align-4.c: New test. * c-c++-common/ubsan/align-5.c: New test. * c-c++-common/ubsan/attrib-4.c: New test. * g++.dg/ubsan/align-1.C: New test. * g++.dg/ubsan/align-2.C: New test. * g++.dg/ubsan/align-3.C: New test. * g++.dg/ubsan/attrib-1.C: New test. * g++.dg/ubsan/null-1.C: New test. * g++.dg/ubsan/null-2.C: New test. From-SVN: r213406
2014-08-01 09:52:43 +02:00
tree alignt = build_int_cst (pointer_sized_int_node, align);
Merger of git branch "gimple-classes-v2-option-3" gcc/ChangeLog: Merger of git branch "gimple-classes-v2-option-3". * ChangeLog.gimple-classes: New. * coretypes.h (struct gcond): Add forward decl. (struct gdebug): Likewise. (struct ggoto): Likewise. (struct glabel): Likewise. (struct gswitch): Likewise. (struct gassign): Likewise. (struct gasm): Likewise. (struct gcall): Likewise. (struct gtransaction): Likewise. (struct greturn): Likewise. (struct gbind): Likewise. (struct gcatch): Likewise. (struct geh_filter): Likewise. (struct geh_mnt): Likewise. (struct geh_else): Likewise. (struct gresx): Likewise. (struct geh_dispatch): Likewise. (struct gphi): Likewise. (struct gtry): Likewise. (struct gomp_atomic_load): Likewise. (struct gomp_atomic_store): Likewise. (struct gomp_continue): Likewise. (struct gomp_critical): Likewise. (struct gomp_for): Likewise. (struct gomp_parallel): Likewise. (struct gomp_task): Likewise. (struct gomp_sections): Likewise. (struct gomp_single): Likewise. (struct gomp_target): Likewise. (struct gomp_teams): Likewise. * doc/gimple.texi (Class hierarchy of GIMPLE statements): Update for renaming of gimple subclasses. * gdbhooks.py: Update. * gimple-iterator.c (gsi_for_phi): New. (gsi_start_phis): Strengthen return type from gimple_stmt_iterator to gphi_iterator. * gimple-iterator.h (struct gphi_iterator): New subclass of gimple_stmt_iterator. (gsi_for_phi): New prototype. (gsi_start_phis): Strengthen return type from gimple_stmt_iterator to gphi_iterator. (gsi_next_nonvirtual_phi): Strengthen param from gimple_stmt_iterator * to gphi_iterator *, and local "phi" from gimple to gphi *. * gsstruct.def: Update for renamings of classes. * gimple.c (gimple_build_return): Strengthen return type from gimple to greturn *. (gimple_call_reset_alias_info): Strengthen param to gcall *. (gimple_build_call_1): Strengthen return type from gimple to gcall *. (gimple_build_call_vec): Likewise. (gimple_build_call): Likewise. (gimple_build_call_valist): Likewise. (gimple_build_call_internal_1): Likewise. (gimple_build_call_internal): Likewise. (gimple_build_call_internal_vec): Likewise. (gimple_build_call_from_tree): Likewise. (gimple_build_assign_stat): Strengthen return type from gimple to gassign *. (gimple_build_assign_with_ops): Likewise. (gimple_build_assign_with_ops): Likewise. (gimple_build_cond): Strengthen return type from gimple to gcond *. (gimple_build_cond_from_tree): Likewise. (gimple_cond_set_condition_from_tree): Require a gcond *. (gimple_build_label): Strengthen return type from gimple to glabel *. (gimple_build_goto): Strengthen return type from gimple to ggoto *. (gimple_build_bind): Strengthen return type from gimple to gbind *. (gimple_build_asm_1): Strengthen return type from gimple to gasm *. (gimple_build_asm_vec): Likewise. (gimple_build_catch): Strengthen return type from gimple to gcatch *. (gimple_build_eh_filter): Strengthen return type from gimple to geh_filter *. (gimple_build_eh_must_not_throw): Strengthen return type from gimple to geh_mnt *. (gimple_build_eh_else): Strengthen return type from gimple to geh_else *. (gimple_build_try): Update for renaming of gimple_statement_try to gtry. (gimple_build_resx): Strengthen return type from gimple to gresx *. (gimple_build_switch_nlabels): Strengthen return type from gimple to gswitch *. (gimple_build_switch): Likewise. (gimple_build_eh_dispatch): Strengthen return type from gimple to geh_dispatch *. (gimple_build_debug_bind_stat): Strengthen return type from gimple to gdebug *. (gimple_build_debug_source_bind_stat): Strengthen return type from gimple to gdebug *. (gimple_build_omp_critical): Strengthen return type from gimple to gomp_critical *. (gimple_build_omp_for): Strengthen return type from gimple to gomp_for *. (gimple_build_omp_parallel): Strengthen return type from gimple to gomp_parallel *. (gimple_build_omp_task): Strengthen return type from gimple to gomp_task *. (gimple_build_omp_continue): Strengthen return type from gimple to gomp_continue *. (gimple_build_omp_sections): Strengthen return type from gimple to gomp_sections *. (gimple_build_omp_single): Strengthen return type from gimple to gomp_single *. (gimple_build_omp_target): Strengthen return type from gimple to gomp_target *. (gimple_build_omp_teams): Strengthen return type from gimple to gomp_teams *. (gimple_build_omp_atomic_load): Strengthen return type from gimple to gomp_atomic_load *. (gimple_build_omp_atomic_store): Strengthen return type from gimple to gomp_atomic_store *. (gimple_build_transaction): Strengthen return type from gimple to gtransaction *. (empty_stmt_p): Replace check for GIMPLE_BIND with a dyn_cast. (gimple_call_fnspec): Require a const gcall *. (gimple_call_arg_flags): Likewise. (gimple_call_return_flags): Likewise. (gimple_set_bb): Add a checked cast. (gimple_copy): Within the cases, add locals of the appropriate subclass and use in place of "stmt" and "copy" for typesafety. (gimple_has_side_effects): Add a checked cast. (gimple_could_trap_p_1): Likewise. (gimple_call_copy_skip_args): Require a gcall *, and return one. (gimple_asm_clobbers_memory_p): Require a const gasm *. (infer_nonnull_range): Replace a check for GIMPLE_RETURN with a dyn_cast, introducing local "return_stmt" and using ti in place of "stmt". * gimple.h (gimple_vec): Eliminate this typedef. (struct gimple_statement_call): Rename to... (struct gcall): ...this. (struct gimple_statement_bind): Rename to... (struct gbind): ...this. (struct gimple_statement_catch): Rename to... (struct gcatch): ...this. (struct gimple_statement_eh_filter): Rename to... (struct geh_filter): ...this. (struct gimple_statement_eh_else): Rename to... (struct geh_else): ...this. (struct gimple_statement_eh_mnt): Rename to... (struct geh_mnt): ...this. (struct gimple_statement_phi): Rename to... (struct gphi): ...this. (struct gimple_statement_resx): Rename to... (struct gresx): ...this. (struct gimple_statement_eh_dispatch): Rename to... (struct geh_dispatch): ...this. (struct gimple_statement_try): Rename to... (struct gtry): ...this. (struct gimple_statement_asm): Rename to... (struct gasm): ...this. (struct gimple_statement_omp_critical): Rename to... (struct gomp_critical): ...this. (struct gimple_statement_omp_for): Rename to... (struct gomp_for): ...this. (struct gimple_statement_omp_parallel): Rename to... (struct gomp_parallel): ...this. (struct gimple_statement_omp_target): Rename to... (struct gomp_target): ...this. (struct gimple_statement_omp_task): Rename to... (struct gomp_task): ...this. (struct gimple_statement_omp_sections): Rename to... (struct gomp_sections): ...this. (struct gimple_statement_omp_continue): Rename to... (struct gomp_continue): ...this. (struct gimple_statement_omp_single): Rename to... (struct gomp_single): ...this. (struct gimple_statement_omp_teams): Rename to... (struct gomp_teams): ...this. (struct gimple_statement_omp_atomic_load): Rename to... (struct gomp_atomic_load): ...this. (struct gimple_statement_omp_atomic_store :): Rename to... (struct gomp_atomic_store :): ...this. (struct gimple_statement_transaction): Rename to... (struct gtransaction): ...this. (struct gcond): New subclass. (struct gdebug): New subclass. (struct ggoto): New subclass. (struct glabel): New subclass. (struct gswitch): New subclass. (struct gassign): New subclass. (struct greturn): New subclass. (is_a_helper <gimple_statement_asm *>::test): Rename to... (is_a_helper <gasm *>::test): ...this. (is_a_helper <gimple_statement_bind *>::test): Rename to... (is_a_helper <gbind *>::test): ...this. (is_a_helper <gassign *>::test): New. (is_a_helper <gimple_statement_call *>::test): Rename to... (is_a_helper <gcall *>::test): ...this. (is_a_helper <gimple_statement_catch *>::test): Rename to... (is_a_helper <gcatch *>::test): ...this. (is_a_helper <gimple_statement_resx *>::test): Rename to... (is_a_helper <gresx *>::test): ...this. (is_a_helper <gcond *>::test): New. (is_a_helper <gdebug *>::test): New. (is_a_helper <ggoto *>::test): New. (is_a_helper <glabel *>::test): New. (is_a_helper <gimple_statement_eh_dispatch *>::test): Rename to... (is_a_helper <geh_dispatch *>::test): ...this. (is_a_helper <gimple_statement_eh_else *>::test): Rename to... (is_a_helper <geh_else *>::test): ...this. (is_a_helper <gimple_statement_eh_filter *>::test): Rename to... (is_a_helper <geh_filter *>::test): ...this. (is_a_helper <gimple_statement_eh_mnt *>::test): Rename to... (is_a_helper <geh_mnt *>::test): ...this. (is_a_helper <gimple_statement_omp_atomic_load *>::test): Rename to... (is_a_helper <gomp_atomic_load *>::test): ...this. (is_a_helper <gimple_statement_omp_atomic_store *>::test): Rename to... (is_a_helper <gomp_atomic_store *>::test): ...this. (is_a_helper <gimple_statement_omp_continue *>::test): Rename to... (is_a_helper <gomp_continue *>::test): ...this. (is_a_helper <gimple_statement_omp_critical *>::test): Rename to... (is_a_helper <gomp_critical *>::test): ...this. (is_a_helper <gimple_statement_omp_for *>::test): Rename to... (is_a_helper <gomp_for *>::test): ...this. (is_a_helper <gimple_statement_omp_parallel *>::test): Rename to... (is_a_helper <gomp_parallel *>::test): ...this. (is_a_helper <gimple_statement_omp_target *>::test): Rename to... (is_a_helper <gomp_target *>::test): ...this. (is_a_helper <gimple_statement_omp_sections *>::test): Rename to... (is_a_helper <gomp_sections *>::test): ...this. (is_a_helper <gimple_statement_omp_single *>::test): Rename to... (is_a_helper <gomp_single *>::test): ...this. (is_a_helper <gimple_statement_omp_teams *>::test): Rename to... (is_a_helper <gomp_teams *>::test): ...this. (is_a_helper <gimple_statement_omp_task *>::test): Rename to... (is_a_helper <gomp_task *>::test): ...this. (is_a_helper <gimple_statement_phi *>::test): Rename to... (is_a_helper <gphi *>::test): ...this. (is_a_helper <gimple_statement_transaction *>::test): Rename to... (is_a_helper <gtransaction *>::test): ...this. (is_a_helper <greturn *>::test): New. (is_a_helper <gswitch *>::test): New. (is_a_helper <gimple_statement_try *>::test): Rename to... (is_a_helper <gtry *>::test): ...this. (is_a_helper <const gimple_statement_asm *>::test): Rename to... (is_a_helper <const gasm *>::test): ...this. (is_a_helper <const gimple_statement_bind *>::test): Rename to... (is_a_helper <const gbind *>::test): ...this. (is_a_helper <const gimple_statement_call *>::test): Rename to... (is_a_helper <const gcall *>::test): ...this. (is_a_helper <const gimple_statement_catch *>::test): Rename to... (is_a_helper <const gcatch *>::test): ...this. (is_a_helper <const gimple_statement_resx *>::test): Rename to... (is_a_helper <const gresx *>::test): ...this. (is_a_helper <const gimple_statement_eh_dispatch *>::test): Rename to... (is_a_helper <const geh_dispatch *>::test): ...this. (is_a_helper <const gimple_statement_eh_filter *>::test): Rename to... (is_a_helper <const geh_filter *>::test): ...this. (is_a_helper <const gimple_statement_omp_atomic_load *>::test): Rename to... (is_a_helper <const gomp_atomic_load *>::test): ...this. (is_a_helper <const gimple_statement_omp_atomic_store *>::test): Rename to... (is_a_helper <const gomp_atomic_store *>::test): ...this. (is_a_helper <const gimple_statement_omp_continue *>::test): Rename to... (is_a_helper <const gomp_continue *>::test): ...this. (is_a_helper <const gimple_statement_omp_critical *>::test): Rename to... (is_a_helper <const gomp_critical *>::test): ...this. (is_a_helper <const gimple_statement_omp_for *>::test): Rename to... (is_a_helper <const gomp_for *>::test): ...this. (is_a_helper <const gimple_statement_omp_parallel *>::test): Rename to... (is_a_helper <const gomp_parallel *>::test): ...this. (is_a_helper <const gimple_statement_omp_target *>::test): Rename to... (is_a_helper <const gomp_target *>::test): ...this. (is_a_helper <const gimple_statement_omp_sections *>::test): Rename to... (is_a_helper <const gomp_sections *>::test): ...this. (is_a_helper <const gimple_statement_omp_single *>::test): Rename to... (is_a_helper <const gomp_single *>::test): ...this. (is_a_helper <const gimple_statement_omp_teams *>::test): Rename to... (is_a_helper <const gomp_teams *>::test): ...this. (is_a_helper <const gimple_statement_omp_task *>::test): Rename to... (is_a_helper <const gomp_task *>::test): ...this. (is_a_helper <const gimple_statement_phi *>::test): Rename to... (is_a_helper <const gphi *>::test): ...this. (is_a_helper <const gimple_statement_transaction *>::test): Rename to... (is_a_helper <const gtransaction *>::test): ...this. (gimple_build_return): Strengthen return type to greturn *. (gimple_call_reset_alias_info): Require a gcall *. (gimple_build_call_vec): Return a gcall *. (gimple_build_call): Likewise. (gimple_build_call_valist): Likewise. (gimple_build_call_internal): Likewise. (gimple_build_call_internal_vec): Likewise. (gimple_build_call_from_tree): Likewise. (gimple_build_assign_stat): Return a gassign *. (gimple_build_assign_with_ops): Likewise. (gimple_build_cond): Return a gcond *. (gimple_build_cond_from_tree): Likewise. (gimple_cond_set_condition_from_tree): Require a gcond *. (gimple_build_label): Return a glabel *. (gimple_build_goto): Return a ggoto *. (gimple_build_bind): Return a gbind *. (gimple_build_asm_vec): Return a gasm *. (gimple_build_catch): Return a gcatch *. (gimple_build_eh_filter): Return a geh_filter *. (gimple_build_eh_must_not_throw): Return a geh_mnt *. (gimple_build_eh_else): Return a geh_else *. (gimple_build_try): Return a gtry *. (gimple_build_resx): Return a gresx *. (gimple_build_switch_nlabels): Return a gswitch *. (gimple_build_switch): Return a gswitch *. (gimple_build_eh_dispatch): Return a geh_dispatch *. (gimple_build_debug_bind_stat): Return a gdebug *. (gimple_build_debug_source_bind_stat): Return a gdebug *. (gimple_build_omp_critical): Return a gomp_critical *. (gimple_build_omp_for): Return a gomp_for *. (gimple_build_omp_parallel): Return a gomp_parallel *. (gimple_build_omp_task): Return a gomp_task *. (gimple_build_omp_continue): Return a gomp_continue *. (gimple_build_omp_sections): Return a gomp_sections *. (gimple_build_omp_single): Return a gomp_single *. (gimple_build_omp_target): Return a gomp_target *. (gimple_build_omp_teams): Return a gomp_teams *. (gimple_build_omp_atomic_load): Return a gomp_atomic_load *. (gimple_build_omp_atomic_store): Return a gomp_atomic_store *. (gimple_build_transaction): Return a gtransaction *. (gimple_call_arg_flags): Require a const gcall *. (gimple_call_return_flags): Likewise. (gimple_call_copy_skip_args): Require and return a gcall *. (gimple_asm_clobbers_memory_p): Require a const gasm *. (gimple_seq_first_stmt_as_a_bind): New. (gimple_assign_nontemporal_move_p): Require a const gassign * rather than a const_gimple. (gimple_call_internal_fn): Update for renaming to gcall. (gimple_call_fntype): Likewise. (gimple_call_set_fntype): Require a gcall * rather than a gimple. (gimple_call_set_fn): Likewise. (gimple_call_set_internal_fn): Likewise. (gimple_call_set_chain): Likewise. (gimple_call_set_tail): Likewise. (gimple_call_tail_p): Likewise. (gimple_call_set_return_slot_opt): Likewise. (gimple_call_return_slot_opt_p): Likewise. (gimple_call_set_from_thunk): Likewise. (gimple_call_from_thunk_p): Likewise. (gimple_call_set_va_arg_pack): Likewise. (gimple_call_va_arg_pack_p): Likewise. (gimple_call_set_nothrow): Likewise. (gimple_call_nothrow_p): Likewise. (gimple_call_set_alloca_for_var): Likewise. (gimple_call_alloca_for_var_p): Likewise. (gimple_call_use_set): Likewise. (gimple_call_clobber_set): Likewise. (gimple_call_return_type): Require a const gcall * rather than a const_gimple. (gimple_call_chain_ptr): Likewise. (gimple_call_copy_flags): Require a pair of gcall *. (gimple_cond_set_code): Require a gcond * rather than a gimple (gimple_cond_set_lhs): Likewise. (gimple_cond_set_rhs): Likewise. (gimple_cond_set_true_label): Likewise. (gimple_cond_set_false_label): Likewise. (gimple_cond_make_false): Likewise. (gimple_cond_make_true): Likewise. (gimple_cond_lhs_ptr): Require a const gcond * rather than a const_gimple. (gimple_cond_rhs_ptr): Likewise. (gimple_cond_true_label): Likewise. (gimple_cond_false_label): Likewise. (gimple_cond_true_p): Likewise. (gimple_cond_false_p): Likewise. (gimple_cond_set_condition): Likewise. (gimple_label_label): Require a const glabel *. (gimple_label_set_label): Require a glabel *. (gimple_goto_set_dest): Require a ggoto *. (gimple_bind_vars): Require a const gbind *. (gimple_bind_block): Likewise. (gimple_bind_set_vars): Require a gbind *. (gimple_bind_append_vars): Likewise. (gimple_bind_body_ptr): Likewise. (gimple_bind_body): Likewise. (gimple_bind_set_body): Likewise. (gimple_bind_add_stmt): Likewise. (gimple_bind_add_seq): Likewise. (gimple_bind_set_block): Likewise. (gimple_asm_ninputs): Require a const gasm *. (gimple_asm_noutputs): Likewise. (gimple_asm_nclobbers): Likewise. (gimple_asm_nlabels): Likewise. (gimple_asm_input_op): Likewise. (gimple_asm_input_op_ptr): Likewise. (gimple_asm_output_op): Likewise. (gimple_asm_output_op_ptr): Likewise. (gimple_asm_clobber_op): Likewise. (gimple_asm_label_op): Likewise. (gimple_asm_string): Likewise. (gimple_asm_volatile_p): Likewise. (gimple_asm_input_p): Likewise. (gimple_asm_set_input_op): Require a gasm *. (gimple_asm_set_output_op): Likewise. (gimple_asm_set_clobber_op): Likewise. (gimple_asm_set_label_op): Likewise. (gimple_asm_set_volatile): Likewise. (gimple_asm_set_input): Likewise. (gimple_catch_types): Require a const gcatch *. (gimple_catch_types_ptr): Require a gcatch *. (gimple_catch_handler_ptr): Likewise. (gimple_catch_handler): Likewise. (gimple_catch_set_types): Likewise. (gimple_catch_set_handler): Likewise. (gimple_eh_filter_types): Update for renaming of subclass to geh_filter. (gimple_eh_filter_types_ptr): Likewise. (gimple_eh_filter_failure_ptr): Likewise. (gimple_eh_filter_set_types): Require a geh_filter *. (gimple_eh_filter_set_failure): Likewise. (gimple_eh_must_not_throw_fndecl): Require a geh_mnt *. (gimple_eh_must_not_throw_set_fndecl): Likewise. (gimple_eh_else_n_body_ptr): Require a geh_else *. (gimple_eh_else_n_body): Likewise. (gimple_eh_else_e_body_ptr): Likewise. (gimple_eh_else_e_body): Likewise. (gimple_eh_else_set_n_body): Likewise. (gimple_eh_else_set_e_body): Likewise. (gimple_try_set_kind): Require a gtry *. (gimple_try_set_catch_is_cleanup): Likewise. (gimple_try_set_eval): Likewise. (gimple_try_set_cleanup): Likewise. (gimple_try_eval_ptr): Update for renaming of subclass to gtry. (gimple_try_cleanup_ptr): Likewise. (gimple_phi_capacity): Update for renaming of subclass to gphi. (gimple_phi_num_args): Likewise. (gimple_phi_result): Likewise. (gimple_phi_result_ptr): Likewise. (gimple_phi_arg): Likewise. (gimple_phi_set_result): Require a gphi *. (gimple_phi_set_arg): Likewise. (gimple_phi_arg_def_ptr): Likewise. (gimple_phi_arg_edge): Likewise. (gimple_phi_arg_location): Likewise. (gimple_phi_arg_location_from_edge): Likewise. (gimple_phi_arg_set_location): Likewise. (gimple_phi_arg_has_location): Likewise. (gimple_resx_region): Require a const gresx *. (gimple_resx_set_region): Require a gresx *. (gimple_eh_dispatch_region): Require a const geh_dispatch *. (gimple_eh_dispatch_set_region): Require a geh_dispatch *. (gimple_switch_num_labels): Require a const gswitch *. (gimple_switch_set_num_labels): Likewise. (gimple_switch_index): Likewise. (gimple_switch_index_ptr): Likewise. (gimple_switch_label): Likewise. (gimple_switch_default_label): Likewise. (gimple_switch_set_index): Require a gswitch *. (gimple_switch_set_label): Likewise. (gimple_switch_set_default_label): Likewise. (gimple_omp_critical_name): Require a const gomp_critical *. (gimple_omp_critical_name_ptr): Require a gomp_critical *. (gimple_omp_critical_set_name): Likewise. (gimple_omp_for_set_kind): Require a gomp_for *. (gimple_omp_for_set_combined_p): Likewise. (gimple_omp_for_set_combined_into_p): Likewise. (gimple_omp_for_clauses): Update for renaming of subclass to gomp_for. (gimple_omp_for_clauses_ptr): Likewise. (gimple_omp_for_set_clauses): Likewise. (gimple_omp_for_collapse): Likewise. (gimple_omp_for_index): Likewise. (gimple_omp_for_index_ptr): Likewise. (gimple_omp_for_set_index): Likewise. (gimple_omp_for_initial): Likewise. (gimple_omp_for_initial_ptr): Likewise. (gimple_omp_for_set_initial): Likewise. (gimple_omp_for_final): Likewise. (gimple_omp_for_final_ptr): Likewise. (gimple_omp_for_set_final): Likewise. (gimple_omp_for_incr): Likewise. (gimple_omp_for_incr_ptr): Likewise. (gimple_omp_for_set_incr): Likewise. (gimple_omp_for_pre_body): Likewise. (gimple_omp_for_set_pre_body): Likewise. (gimple_omp_parallel_clauses): Update for renaming of subclass to gomp_parallel. (gimple_omp_parallel_clauses_ptr): Require a gomp_parallel *. (gimple_omp_parallel_set_clauses): Likewise. (gimple_omp_parallel_child_fn_ptr): Likewise. (gimple_omp_parallel_set_child_fn): Likewise. (gimple_omp_parallel_data_arg_ptr): Likewise. (gimple_omp_parallel_set_data_arg): Likewise. (gimple_omp_parallel_child_fn): Require a const gomp_parallel *. (gimple_omp_parallel_data_arg): Likewise. (gimple_omp_task_clauses): Update for renaming of subclass to gomp_task. (gimple_omp_task_clauses_ptr): Likewise. (gimple_omp_task_set_clauses): Likewise. (gimple_omp_task_child_fn): Likewise. (gimple_omp_task_child_fn_ptr): Likewise. (gimple_omp_task_set_child_fn): Likewise. (gimple_omp_task_data_arg): Likewise. (gimple_omp_task_data_arg_ptr): Likewise. (gimple_omp_task_set_data_arg): Likewise. (gimple_omp_taskreg_clauses): Whitespace fixes. (gimple_omp_taskreg_clauses_ptr): Likewise. (gimple_omp_taskreg_set_clauses): Likewise. (gimple_omp_taskreg_child_fn): Likewise. (gimple_omp_taskreg_child_fn_ptr): Likewise. (gimple_omp_taskreg_set_child_fn): Likewise. (gimple_omp_taskreg_data_arg): Likewise. (gimple_omp_taskreg_data_arg_ptr): Likewise. (gimple_omp_taskreg_set_data_arg): Likewise. (gimple_omp_task_copy_fn): Update for renaming of subclass to gomp_task. (gimple_omp_task_copy_fn_ptr): Likewise. (gimple_omp_task_set_copy_fn): Likewise. (gimple_omp_task_arg_size): Likewise. (gimple_omp_task_arg_size_ptr): Likewise. (gimple_omp_task_set_arg_size): Likewise. (gimple_omp_task_arg_align): Likewise. (gimple_omp_task_arg_align_ptr): Likewise. (gimple_omp_task_set_arg_align): Likewise. (gimple_omp_single_clauses): Update for renaming of subclass to gomp_single. (gimple_omp_single_clauses_ptr): Likewise. (gimple_omp_single_set_clauses): Likewise. (gimple_omp_target_clauses): Update for renaming of subclass to gomp_target. (gimple_omp_target_clauses_ptr): Likewise. (gimple_omp_target_set_clauses): Require a gomp_target *. (gimple_omp_target_set_kind): Likewise. (gimple_omp_target_child_fn_ptr): Likewise. (gimple_omp_target_set_child_fn): Likewise. (gimple_omp_target_data_arg_ptr): Likewise. (gimple_omp_target_set_data_arg): Likewise. (gimple_omp_target_child_fn): Require a const gomp_target *. (gimple_omp_target_data_arg): Likewise. (gimple_omp_teams_clauses): Update for renaming of subclass to gomp_teams. (gimple_omp_teams_clauses_ptr): Likewise. (gimple_omp_teams_set_clauses): Require a gomp_teams *. (gimple_omp_sections_clauses): Update for renaming of subclass to gomp_sections. (gimple_omp_sections_clauses_ptr): Likewise. (gimple_omp_sections_set_clauses): Likewise. (gimple_omp_sections_control): Likewise. (gimple_omp_sections_control_ptr): Likewise. (gimple_omp_sections_set_control): Likewise. (gimple_omp_for_set_cond): Likewise. (gimple_omp_for_cond): Likewise. (gimple_omp_atomic_store_set_val): Require a gomp_atomic_store *. (gimple_omp_atomic_store_val_ptr): Likewise. (gimple_omp_atomic_load_set_lhs): Likewise. (gimple_omp_atomic_store_val): Require a const gomp_atomic_store *. (gimple_omp_atomic_load_lhs): Likewise. (gimple_omp_atomic_load_rhs): Likewise. (gimple_omp_atomic_load_lhs_ptr): Require a gomp_atomic_load *. (gimple_omp_atomic_load_set_rhs): Likewise. (gimple_omp_atomic_load_rhs_ptr): Likewise. (gimple_omp_continue_control_def): Require a const gomp_continue *. (gimple_omp_continue_control_use): Likewise. (gimple_omp_continue_control_def_ptr): Require a gomp_continue *. (gimple_omp_continue_set_control_def): Likewise. (gimple_omp_continue_control_use_ptr): Likewise. (gimple_omp_continue_set_control_use): Likewise. (gimple_transaction_body_ptr): Require a gtransaction *. (gimple_transaction_body): Likewise. (gimple_transaction_label_ptr): Likewise. (gimple_transaction_label): Require a const gtransaction *. (gimple_transaction_subcode): Likewise. (gimple_transaction_set_body): Require a gtransaction *. (gimple_transaction_set_label): Likewise. (gimple_transaction_set_subcode): Likewise. (gimple_return_retval_ptr): Require a const greturn *. (gimple_return_retval): Likewise. (gimple_return_set_retval): Require a greturn *. (gimple_expr_type): Introduce local "call_stmt" and use in place of "stmt" for typesafety. * asan.c: Use gimple subclasses. * auto-profile.c: Likewise. * builtins.c: Likewise. * builtins.h: Likewise. * cfgexpand.c: Likewise. * cfgloop.c: Likewise. * cfgloopmanip.c: Likewise. * cgraph.c: Likewise. * cgraph.h: Likewise. * cgraphbuild.c: Likewise. * cgraphclones.c: Likewise. * cgraphunit.c: Likewise. * expr.h: Likewise. * gimple-builder.c: Likewise. * gimple-builder.h: Likewise. * gimple-fold.c: Likewise. * gimple-low.c: Likewise. * gimple-pretty-print.c: Likewise. * gimple-ssa-isolate-paths.c: Likewise. * gimple-ssa-strength-reduction.c: Likewise. * gimple-streamer-in.c: Likewise. * gimple-streamer-out.c: Likewise. * gimple-walk.c: Likewise. * gimplify-me.c: Likewise. * gimplify.c: Likewise. * gimplify.h: Likewise. * graphite-scop-detection.c: Likewise. * graphite-sese-to-poly.c: Likewise. * internal-fn.c: Likewise. * internal-fn.def:: Likewise. * internal-fn.h: Likewise. * ipa-icf-gimple.c: Likewise. * ipa-icf-gimple.h: Likewise. * ipa-icf.c: Likewise. * ipa-inline-analysis.c: Likewise. * ipa-prop.c: Likewise. * ipa-prop.h: Likewise. * ipa-pure-const.c: Likewise. * ipa-split.c: Likewise. * lto-streamer-in.c: Likewise. * lto-streamer-out.c: Likewise. * omp-low.c: Likewise. * predict.c: Likewise. * sanopt.c: Likewise. * sese.c: Likewise. * ssa-iterators.h: Likewise. * stmt.c: Likewise. * trans-mem.c: Likewise. * tree-call-cdce.c: Likewise. * tree-cfg.c: Likewise. * tree-cfg.h: Likewise. * tree-cfgcleanup.c: Likewise. * tree-chkp.c: Likewise. * tree-chkp.h: Likewise. * tree-complex.c: Likewise. * tree-data-ref.c: Likewise. * tree-dfa.c: Likewise. * tree-eh.c: Likewise. * tree-eh.h: Likewise. * tree-emutls.c: Likewise. * tree-if-conv.c: Likewise. * tree-inline.c: Likewise. * tree-inline.h: Likewise. * tree-into-ssa.c: Likewise. * tree-into-ssa.h: Likewise. * tree-loop-distribution.c: Likewise. * tree-nrv.c: Likewise. * tree-object-size.c: Likewise. * tree-outof-ssa.c: Likewise. * tree-parloops.c: Likewise. * tree-phinodes.c: Likewise. * tree-phinodes.h: Likewise. * tree-predcom.c: Likewise. * tree-profile.c: Likewise. * tree-scalar-evolution.c: Likewise. * tree-scalar-evolution.h * tree-sra.cn_function): * tree-ssa-alias.c: Likewise. * tree-ssa-alias.h: Likewise. * tree-ssa-ccp.c: Likewise. * tree-ssa-coalesce.c: Likewise. * tree-ssa-copy.c: Likewise. * tree-ssa-copyrename.c: Likewise. * tree-ssa-dce.c: Likewise. * tree-ssa-dom.c: Likewise. * tree-ssa-forwprop.c: Likewise. * tree-ssa-ifcombine.c: Likewise. * tree-ssa-live.c: Likewise. * tree-ssa-loop-im.c: Likewise. * tree-ssa-loop-ivcanon.c: Likewise. * tree-ssa-loop-ivopts.c: Likewise. * tree-ssa-loop-manip.c: Likewise. * tree-ssa-loop-niter.c: Likewise. * tree-ssa-loop-prefetch.c: Likewise. * tree-ssa-loop-unswitch.c: Likewise. * tree-ssa-math-opts.c: Likewise. * tree-ssa-operands.c: Likewise. * tree-ssa-phiopt.c: Likewise. * tree-ssa-phiprop.c: Likewise. * tree-ssa-pre.c: Likewise. * tree-ssa-propagate.c: Likewise. * tree-ssa-propagate.h: Likewise. * tree-ssa-reassoc.c: Likewise. * tree-ssa-sccvn.c: Likewise. * tree-ssa-sccvn.h: Likewise. * tree-ssa-sink.c: Likewise. * tree-ssa-strlen.c * tree-ssa-structalias.c * tree-ssa-tail-merge.c: Likewise. * tree-ssa-ter.c: Likewise. * tree-ssa-threadedge.c: Likewise. * tree-ssa-threadedge.h: Likewise. * tree-ssa-threadupdate.c: Likewise. * tree-ssa-uncprop.c: Likewise. * tree-ssa-uninit.c: Likewise. * tree-ssa.c: Likewise. * tree-stdarg.c: Likewise. * tree-switch-conversion.c: Likewise. * tree-tailcall.c: Likewise. * tree-vect-data-refs.c: Likewise. * tree-vect-generic.c: Likewise. * tree-vect-loop-manip.c: Likewise. * tree-vect-loop.c: Likewise. * tree-vect-patterns.c: Likewise. * tree-vect-slp.c: Likewise. * tree-vect-stmts.c: Likewise. * tree-vectorizer.h: Likewise. * tree-vrp.c: Likewise. * tree.c: Likewise. * ubsan.c: Likewise. * value-prof.c: Likewise. * value-prof.h: Likewise. * vtable-verify.c: Likewise. gcc/c-family/ChangeLog: Merger of git branch "gimple-classes-v2-option-3". * ChangeLog.gimple-classes: New. * c-gimplify.c (add_block_to_enclosing): Strengthen local "stack" from being just a vec<gimple> to a vec<gbind *>. gcc/java/ChangeLog: Merger of git branch "gimple-classes-v2-option-3". * ChangeLog.gimple-classes: New. * java-gimplify.c (java_gimplify_block): Strengthen local "outer" from gimple to gbind *. From-SVN: r217787
2014-11-19 18:00:54 +01:00
gcall *g = gimple_build_call_internal (IFN_UBSAN_NULL, 3, t, kind, alignt);
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
gimple_set_location (g, gimple_location (gsi_stmt (*iter)));
gsi_insert_before (iter, g, GSI_SAME_STMT);
}
/* Perform the pointer instrumentation. */
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
static void
instrument_null (gimple_stmt_iterator gsi, bool is_lhs)
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
{
gimple *stmt = gsi_stmt (gsi);
tree t = is_lhs ? gimple_get_lhs (stmt) : gimple_assign_rhs1 (stmt);
opts.c (common_handle_option): Handle -fsanitize=alignment. * opts.c (common_handle_option): Handle -fsanitize=alignment. * ubsan.h (enum ubsan_null_ckind): Add UBSAN_CTOR_CALL. (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn): Change return type to bool. * stor-layout.h (min_align_of_type): New prototype. * asan.c (pass_sanopt::execute): Don't perform gsi_next if ubsan_expand* told us not to do it. Remove the extra gsi_end_p check. * ubsan.c: Include builtins.h. (ubsan_expand_bounds_ifn): Change return type to bool, always return true. (ubsan_expand_null_ifn): Change return type to bool, change argument to gimple_stmt_iterator *. Handle both null and alignment sanitization, take type from ckind argument's type rather than first argument. (instrument_member_call): Removed. (instrument_mem_ref): Remove t argument, add mem and base arguments. Handle both null and alignment sanitization, don't say whole struct access is member access. Build 3 argument IFN_UBSAN_NULL call instead of 2 argument. (instrument_null): Adjust instrument_mem_ref caller. Don't instrument calls here. (pass_ubsan::gate, pass_ubsan::execute): Handle SANITIZE_ALIGNMENT like SANITIZE_NULL. * stor-layout.c (min_align_of_type): New function. * flag-types.h (enum sanitize_code): Add SANITIZE_ALIGNMENT. Or it into SANITIZE_UNDEFINED. * doc/invoke.texi (-fsanitize=alignment): Document. cp/ * cp-gimplify.c (cp_genericize_r): For -fsanitize=null and/or -fsanitize=alignment call ubsan_maybe_instrument_reference for casts to REFERENCE_TYPE and ubsan_maybe_instrument_member_call for calls to member functions. c-family/ * c-common.h (min_align_of_type): Removed prototype. * c-common.c (min_align_of_type): Removed. * c-ubsan.h (ubsan_maybe_instrument_reference, ubsan_maybe_instrument_member_call): New prototypes. * c-ubsan.c: Include stor-layout.h and builtins.h. (ubsan_maybe_instrument_reference_or_call, ubsan_maybe_instrument_reference, ubsan_maybe_instrument_call): New functions. testsuite/ * c-c++-common/ubsan/align-1.c: New test. * c-c++-common/ubsan/align-2.c: New test. * c-c++-common/ubsan/align-3.c: New test. * c-c++-common/ubsan/align-4.c: New test. * c-c++-common/ubsan/align-5.c: New test. * c-c++-common/ubsan/attrib-4.c: New test. * g++.dg/ubsan/align-1.C: New test. * g++.dg/ubsan/align-2.C: New test. * g++.dg/ubsan/align-3.C: New test. * g++.dg/ubsan/attrib-1.C: New test. * g++.dg/ubsan/null-1.C: New test. * g++.dg/ubsan/null-2.C: New test. From-SVN: r213406
2014-08-01 09:52:43 +02:00
tree base = get_base_address (t);
const enum tree_code code = TREE_CODE (base);
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
if (code == MEM_REF
opts.c (common_handle_option): Handle -fsanitize=alignment. * opts.c (common_handle_option): Handle -fsanitize=alignment. * ubsan.h (enum ubsan_null_ckind): Add UBSAN_CTOR_CALL. (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn): Change return type to bool. * stor-layout.h (min_align_of_type): New prototype. * asan.c (pass_sanopt::execute): Don't perform gsi_next if ubsan_expand* told us not to do it. Remove the extra gsi_end_p check. * ubsan.c: Include builtins.h. (ubsan_expand_bounds_ifn): Change return type to bool, always return true. (ubsan_expand_null_ifn): Change return type to bool, change argument to gimple_stmt_iterator *. Handle both null and alignment sanitization, take type from ckind argument's type rather than first argument. (instrument_member_call): Removed. (instrument_mem_ref): Remove t argument, add mem and base arguments. Handle both null and alignment sanitization, don't say whole struct access is member access. Build 3 argument IFN_UBSAN_NULL call instead of 2 argument. (instrument_null): Adjust instrument_mem_ref caller. Don't instrument calls here. (pass_ubsan::gate, pass_ubsan::execute): Handle SANITIZE_ALIGNMENT like SANITIZE_NULL. * stor-layout.c (min_align_of_type): New function. * flag-types.h (enum sanitize_code): Add SANITIZE_ALIGNMENT. Or it into SANITIZE_UNDEFINED. * doc/invoke.texi (-fsanitize=alignment): Document. cp/ * cp-gimplify.c (cp_genericize_r): For -fsanitize=null and/or -fsanitize=alignment call ubsan_maybe_instrument_reference for casts to REFERENCE_TYPE and ubsan_maybe_instrument_member_call for calls to member functions. c-family/ * c-common.h (min_align_of_type): Removed prototype. * c-common.c (min_align_of_type): Removed. * c-ubsan.h (ubsan_maybe_instrument_reference, ubsan_maybe_instrument_member_call): New prototypes. * c-ubsan.c: Include stor-layout.h and builtins.h. (ubsan_maybe_instrument_reference_or_call, ubsan_maybe_instrument_reference, ubsan_maybe_instrument_call): New functions. testsuite/ * c-c++-common/ubsan/align-1.c: New test. * c-c++-common/ubsan/align-2.c: New test. * c-c++-common/ubsan/align-3.c: New test. * c-c++-common/ubsan/align-4.c: New test. * c-c++-common/ubsan/align-5.c: New test. * c-c++-common/ubsan/attrib-4.c: New test. * g++.dg/ubsan/align-1.C: New test. * g++.dg/ubsan/align-2.C: New test. * g++.dg/ubsan/align-3.C: New test. * g++.dg/ubsan/attrib-1.C: New test. * g++.dg/ubsan/null-1.C: New test. * g++.dg/ubsan/null-2.C: New test. From-SVN: r213406
2014-08-01 09:52:43 +02:00
&& TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME)
instrument_mem_ref (t, base, &gsi, is_lhs);
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
}
/* Build an ubsan builtin call for the signed-integer-overflow
sanitization. CODE says what kind of builtin are we building,
LOC is a location, LHSTYPE is the type of LHS, OP0 and OP1
are operands of the binary operation. */
tree
ubsan_build_overflow_builtin (tree_code code, location_t loc, tree lhstype,
tree op0, tree op1, tree *datap)
{
re PR sanitizer/60275 ([UBSAN] Add -f[no-]sanitize-recover/-fsanitize-undefined-trap-on-error to make UBSAN's runtime errors fatal) PR sanitizer/60275 * common.opt (fsanitize-recover, fsanitize-undefined-trap-on-error): New options. * gcc.c (sanitize_spec_function): Don't return "" for "undefined" if flag_sanitize_undefined_trap_on_error. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_DIVREM_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_SHIFT_OUT_OF_BOUNDS_ABORT, BUILT_IN_UBSAN_HANDLE_VLA_BOUND_NOT_POSITIVE_ABORT, BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT, BUILT_IN_UBSAN_HANDLE_ADD_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_SUB_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_MUL_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_NEGATE_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_LOAD_INVALID_VALUE_ABORT): New builtins. * ubsan.c (ubsan_instrument_unreachable): Return __builtin_trap () if flag_sanitize_undefined_trap_on_error. (ubsan_expand_null_ifn): Emit __builtin_trap () if flag_sanitize_undefined_trap_on_error and __ubsan_handle_type_mismatch_abort if !flag_sanitize_recover. (ubsan_expand_null_ifn, ubsan_build_overflow_builtin, instrument_bool_enum_load): Emit __builtin_trap () if flag_sanitize_undefined_trap_on_error and __builtin_handle_*_abort () if !flag_sanitize_recover. * doc/invoke.texi (-fsanitize-recover, -fsanitize-undefined-trap-on-error): Document. c-family/ * c-ubsan.c (ubsan_instrument_return): Return __builtin_trap () if flag_sanitize_undefined_trap_on_error. (ubsan_instrument_division, ubsan_instrument_shift, ubsan_instrument_vla): Likewise. Use __ubsan_handle_*_abort () if !flag_sanitize_recover. testsuite/ * g++.dg/ubsan/return-2.C: Revert 2014-03-24 changes, add -fno-sanitize-recover to dg-options. * g++.dg/ubsan/cxx11-shift-1.C: Remove c++11 target restriction, add -std=c++11 to dg-options. * g++.dg/ubsan/cxx11-shift-2.C: Likewise. * g++.dg/ubsan/cxx1y-vla.C: Remove c++1y target restriction, add -std=c++1y to dg-options. * c-c++-common/ubsan/undefined-1.c: Revert 2014-03-24 changes, add -fno-sanitize-recover to dg-options. * c-c++-common/ubsan/overflow-sub-1.c: Likewise. * c-c++-common/ubsan/vla-4.c: Likewise. * c-c++-common/ubsan/pr59503.c: Likewise. * c-c++-common/ubsan/vla-3.c: Likewise. * c-c++-common/ubsan/save-expr-1.c: Likewise. * c-c++-common/ubsan/overflow-add-1.c: Likewise. * c-c++-common/ubsan/shift-3.c: Likewise. * c-c++-common/ubsan/overflow-1.c: Likewise. * c-c++-common/ubsan/overflow-negate-2.c: Likewise. * c-c++-common/ubsan/vla-2.c: Likewise. * c-c++-common/ubsan/overflow-mul-1.c: Likewise. * c-c++-common/ubsan/pr60613-1.c: Likewise. * c-c++-common/ubsan/shift-6.c: Likewise. * c-c++-common/ubsan/overflow-mul-3.c: Likewise. * c-c++-common/ubsan/overflow-add-3.c: New test. * c-c++-common/ubsan/overflow-add-4.c: New test. * c-c++-common/ubsan/div-by-zero-6.c: New test. * c-c++-common/ubsan/div-by-zero-7.c: New test. From-SVN: r209672
2014-04-23 10:20:12 +02:00
if (flag_sanitize_undefined_trap_on_error)
return build_call_expr_loc (loc, builtin_decl_explicit (BUILT_IN_TRAP), 0);
tree data;
if (datap && *datap)
data = *datap;
else
data = ubsan_create_data ("__ubsan_overflow_data", 1, &loc,
ubsan_type_descriptor (lhstype), NULL_TREE,
NULL_TREE);
if (datap)
*datap = data;
enum built_in_function fn_code;
switch (code)
{
case PLUS_EXPR:
New syntax for -fsanitize-recover. 2014-10-22 Jakub Jelinek <jakub@redhat.com> Yury Gribov <y.gribov@samsung.com> gcc/ * common.opt (flag_sanitize_recover): New variable. (fsanitize-recover): Remove Var/Init, deprecate. (fsanitize-recover=): New option. * doc/invoke.texi (fsanitize-recover): Update docs. * opts.c (finish_options): Use opts->x_flag_sanitize instead of flag_sanitize. Prohibit -fsanitize-recover for anything besides UBSan. Formatting. (common_handle_option): Handle OPT_fsanitize_recover_ and OPT_fsanitize_recover. Use opts->x_flag_sanitize instead of flag_sanitize. * asan.c (pass_sanopt::execute): Fix up formatting. * ubsan.c (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn, ubsan_expand_objsize_ifn, ubsan_build_overflow_builtin, instrument_bool_enum_load, ubsan_instrument_float_cast, instrument_nonnull_arg, instrument_nonnull_return): Check bits in flag_sanitize_recover bitmask instead of flag_sanitize_recover as bool flag. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division, ubsan_instrument_shift, ubsan_instrument_vla): Check bits in flag_sanitize_recover bitmask instead of flag_sanitize_recover as bool flag. gcc/testsuite/ * c-c++-common/ubsan/align-1.c: Update cmdline options. * c-c++-common/ubsan/align-3.c: Likewise. * c-c++-common/ubsan/bounds-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-7.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-10.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-7.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-8.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-9.c: Likewise. * c-c++-common/ubsan/nonnull-2.c: Likewise. * c-c++-common/ubsan/nonnull-3.c: Likewise. * c-c++-common/ubsan/object-size-3.c: Likewise. * c-c++-common/ubsan/overflow-1.c: Likewise. * c-c++-common/ubsan/overflow-add-1.c: Likewise. * c-c++-common/ubsan/overflow-add-3.c: Likewise. * c-c++-common/ubsan/overflow-mul-1.c: Likewise. * c-c++-common/ubsan/overflow-mul-3.c: Likewise. * c-c++-common/ubsan/overflow-negate-2.c: Likewise. * c-c++-common/ubsan/overflow-sub-1.c: Likewise. * c-c++-common/ubsan/pr59503.c: Likewise. * c-c++-common/ubsan/pr60613-1.c: Likewise. * c-c++-common/ubsan/save-expr-1.c: Likewise. * c-c++-common/ubsan/shift-3.c: Likewise. * c-c++-common/ubsan/shift-6.c: Likewise. * c-c++-common/ubsan/undefined-1.c: Likewise. * c-c++-common/ubsan/vla-2.c: Likewise. * c-c++-common/ubsan/vla-3.c: Likewise. * c-c++-common/ubsan/vla-4.c: Likewise. * g++.dg/ubsan/cxx11-shift-1.C: Likewise. * g++.dg/ubsan/return-2.C: Likewise. * c-c++-common/ubsan/recovery-1.c: New test. * c-c++-common/ubsan/recovery-2.c: New test. * c-c++-common/ubsan/recovery-3.c: New test. * c-c++-common/ubsan/recovery-common.inc: New file. Co-Authored-By: Yury Gribov <y.gribov@samsung.com> From-SVN: r216552
2014-10-22 13:07:10 +02:00
fn_code = (flag_sanitize_recover & SANITIZE_SI_OVERFLOW)
re PR sanitizer/60275 ([UBSAN] Add -f[no-]sanitize-recover/-fsanitize-undefined-trap-on-error to make UBSAN's runtime errors fatal) PR sanitizer/60275 * common.opt (fsanitize-recover, fsanitize-undefined-trap-on-error): New options. * gcc.c (sanitize_spec_function): Don't return "" for "undefined" if flag_sanitize_undefined_trap_on_error. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_DIVREM_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_SHIFT_OUT_OF_BOUNDS_ABORT, BUILT_IN_UBSAN_HANDLE_VLA_BOUND_NOT_POSITIVE_ABORT, BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT, BUILT_IN_UBSAN_HANDLE_ADD_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_SUB_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_MUL_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_NEGATE_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_LOAD_INVALID_VALUE_ABORT): New builtins. * ubsan.c (ubsan_instrument_unreachable): Return __builtin_trap () if flag_sanitize_undefined_trap_on_error. (ubsan_expand_null_ifn): Emit __builtin_trap () if flag_sanitize_undefined_trap_on_error and __ubsan_handle_type_mismatch_abort if !flag_sanitize_recover. (ubsan_expand_null_ifn, ubsan_build_overflow_builtin, instrument_bool_enum_load): Emit __builtin_trap () if flag_sanitize_undefined_trap_on_error and __builtin_handle_*_abort () if !flag_sanitize_recover. * doc/invoke.texi (-fsanitize-recover, -fsanitize-undefined-trap-on-error): Document. c-family/ * c-ubsan.c (ubsan_instrument_return): Return __builtin_trap () if flag_sanitize_undefined_trap_on_error. (ubsan_instrument_division, ubsan_instrument_shift, ubsan_instrument_vla): Likewise. Use __ubsan_handle_*_abort () if !flag_sanitize_recover. testsuite/ * g++.dg/ubsan/return-2.C: Revert 2014-03-24 changes, add -fno-sanitize-recover to dg-options. * g++.dg/ubsan/cxx11-shift-1.C: Remove c++11 target restriction, add -std=c++11 to dg-options. * g++.dg/ubsan/cxx11-shift-2.C: Likewise. * g++.dg/ubsan/cxx1y-vla.C: Remove c++1y target restriction, add -std=c++1y to dg-options. * c-c++-common/ubsan/undefined-1.c: Revert 2014-03-24 changes, add -fno-sanitize-recover to dg-options. * c-c++-common/ubsan/overflow-sub-1.c: Likewise. * c-c++-common/ubsan/vla-4.c: Likewise. * c-c++-common/ubsan/pr59503.c: Likewise. * c-c++-common/ubsan/vla-3.c: Likewise. * c-c++-common/ubsan/save-expr-1.c: Likewise. * c-c++-common/ubsan/overflow-add-1.c: Likewise. * c-c++-common/ubsan/shift-3.c: Likewise. * c-c++-common/ubsan/overflow-1.c: Likewise. * c-c++-common/ubsan/overflow-negate-2.c: Likewise. * c-c++-common/ubsan/vla-2.c: Likewise. * c-c++-common/ubsan/overflow-mul-1.c: Likewise. * c-c++-common/ubsan/pr60613-1.c: Likewise. * c-c++-common/ubsan/shift-6.c: Likewise. * c-c++-common/ubsan/overflow-mul-3.c: Likewise. * c-c++-common/ubsan/overflow-add-3.c: New test. * c-c++-common/ubsan/overflow-add-4.c: New test. * c-c++-common/ubsan/div-by-zero-6.c: New test. * c-c++-common/ubsan/div-by-zero-7.c: New test. From-SVN: r209672
2014-04-23 10:20:12 +02:00
? BUILT_IN_UBSAN_HANDLE_ADD_OVERFLOW
: BUILT_IN_UBSAN_HANDLE_ADD_OVERFLOW_ABORT;
break;
case MINUS_EXPR:
New syntax for -fsanitize-recover. 2014-10-22 Jakub Jelinek <jakub@redhat.com> Yury Gribov <y.gribov@samsung.com> gcc/ * common.opt (flag_sanitize_recover): New variable. (fsanitize-recover): Remove Var/Init, deprecate. (fsanitize-recover=): New option. * doc/invoke.texi (fsanitize-recover): Update docs. * opts.c (finish_options): Use opts->x_flag_sanitize instead of flag_sanitize. Prohibit -fsanitize-recover for anything besides UBSan. Formatting. (common_handle_option): Handle OPT_fsanitize_recover_ and OPT_fsanitize_recover. Use opts->x_flag_sanitize instead of flag_sanitize. * asan.c (pass_sanopt::execute): Fix up formatting. * ubsan.c (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn, ubsan_expand_objsize_ifn, ubsan_build_overflow_builtin, instrument_bool_enum_load, ubsan_instrument_float_cast, instrument_nonnull_arg, instrument_nonnull_return): Check bits in flag_sanitize_recover bitmask instead of flag_sanitize_recover as bool flag. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division, ubsan_instrument_shift, ubsan_instrument_vla): Check bits in flag_sanitize_recover bitmask instead of flag_sanitize_recover as bool flag. gcc/testsuite/ * c-c++-common/ubsan/align-1.c: Update cmdline options. * c-c++-common/ubsan/align-3.c: Likewise. * c-c++-common/ubsan/bounds-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-7.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-10.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-7.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-8.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-9.c: Likewise. * c-c++-common/ubsan/nonnull-2.c: Likewise. * c-c++-common/ubsan/nonnull-3.c: Likewise. * c-c++-common/ubsan/object-size-3.c: Likewise. * c-c++-common/ubsan/overflow-1.c: Likewise. * c-c++-common/ubsan/overflow-add-1.c: Likewise. * c-c++-common/ubsan/overflow-add-3.c: Likewise. * c-c++-common/ubsan/overflow-mul-1.c: Likewise. * c-c++-common/ubsan/overflow-mul-3.c: Likewise. * c-c++-common/ubsan/overflow-negate-2.c: Likewise. * c-c++-common/ubsan/overflow-sub-1.c: Likewise. * c-c++-common/ubsan/pr59503.c: Likewise. * c-c++-common/ubsan/pr60613-1.c: Likewise. * c-c++-common/ubsan/save-expr-1.c: Likewise. * c-c++-common/ubsan/shift-3.c: Likewise. * c-c++-common/ubsan/shift-6.c: Likewise. * c-c++-common/ubsan/undefined-1.c: Likewise. * c-c++-common/ubsan/vla-2.c: Likewise. * c-c++-common/ubsan/vla-3.c: Likewise. * c-c++-common/ubsan/vla-4.c: Likewise. * g++.dg/ubsan/cxx11-shift-1.C: Likewise. * g++.dg/ubsan/return-2.C: Likewise. * c-c++-common/ubsan/recovery-1.c: New test. * c-c++-common/ubsan/recovery-2.c: New test. * c-c++-common/ubsan/recovery-3.c: New test. * c-c++-common/ubsan/recovery-common.inc: New file. Co-Authored-By: Yury Gribov <y.gribov@samsung.com> From-SVN: r216552
2014-10-22 13:07:10 +02:00
fn_code = (flag_sanitize_recover & SANITIZE_SI_OVERFLOW)
re PR sanitizer/60275 ([UBSAN] Add -f[no-]sanitize-recover/-fsanitize-undefined-trap-on-error to make UBSAN's runtime errors fatal) PR sanitizer/60275 * common.opt (fsanitize-recover, fsanitize-undefined-trap-on-error): New options. * gcc.c (sanitize_spec_function): Don't return "" for "undefined" if flag_sanitize_undefined_trap_on_error. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_DIVREM_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_SHIFT_OUT_OF_BOUNDS_ABORT, BUILT_IN_UBSAN_HANDLE_VLA_BOUND_NOT_POSITIVE_ABORT, BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT, BUILT_IN_UBSAN_HANDLE_ADD_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_SUB_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_MUL_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_NEGATE_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_LOAD_INVALID_VALUE_ABORT): New builtins. * ubsan.c (ubsan_instrument_unreachable): Return __builtin_trap () if flag_sanitize_undefined_trap_on_error. (ubsan_expand_null_ifn): Emit __builtin_trap () if flag_sanitize_undefined_trap_on_error and __ubsan_handle_type_mismatch_abort if !flag_sanitize_recover. (ubsan_expand_null_ifn, ubsan_build_overflow_builtin, instrument_bool_enum_load): Emit __builtin_trap () if flag_sanitize_undefined_trap_on_error and __builtin_handle_*_abort () if !flag_sanitize_recover. * doc/invoke.texi (-fsanitize-recover, -fsanitize-undefined-trap-on-error): Document. c-family/ * c-ubsan.c (ubsan_instrument_return): Return __builtin_trap () if flag_sanitize_undefined_trap_on_error. (ubsan_instrument_division, ubsan_instrument_shift, ubsan_instrument_vla): Likewise. Use __ubsan_handle_*_abort () if !flag_sanitize_recover. testsuite/ * g++.dg/ubsan/return-2.C: Revert 2014-03-24 changes, add -fno-sanitize-recover to dg-options. * g++.dg/ubsan/cxx11-shift-1.C: Remove c++11 target restriction, add -std=c++11 to dg-options. * g++.dg/ubsan/cxx11-shift-2.C: Likewise. * g++.dg/ubsan/cxx1y-vla.C: Remove c++1y target restriction, add -std=c++1y to dg-options. * c-c++-common/ubsan/undefined-1.c: Revert 2014-03-24 changes, add -fno-sanitize-recover to dg-options. * c-c++-common/ubsan/overflow-sub-1.c: Likewise. * c-c++-common/ubsan/vla-4.c: Likewise. * c-c++-common/ubsan/pr59503.c: Likewise. * c-c++-common/ubsan/vla-3.c: Likewise. * c-c++-common/ubsan/save-expr-1.c: Likewise. * c-c++-common/ubsan/overflow-add-1.c: Likewise. * c-c++-common/ubsan/shift-3.c: Likewise. * c-c++-common/ubsan/overflow-1.c: Likewise. * c-c++-common/ubsan/overflow-negate-2.c: Likewise. * c-c++-common/ubsan/vla-2.c: Likewise. * c-c++-common/ubsan/overflow-mul-1.c: Likewise. * c-c++-common/ubsan/pr60613-1.c: Likewise. * c-c++-common/ubsan/shift-6.c: Likewise. * c-c++-common/ubsan/overflow-mul-3.c: Likewise. * c-c++-common/ubsan/overflow-add-3.c: New test. * c-c++-common/ubsan/overflow-add-4.c: New test. * c-c++-common/ubsan/div-by-zero-6.c: New test. * c-c++-common/ubsan/div-by-zero-7.c: New test. From-SVN: r209672
2014-04-23 10:20:12 +02:00
? BUILT_IN_UBSAN_HANDLE_SUB_OVERFLOW
: BUILT_IN_UBSAN_HANDLE_SUB_OVERFLOW_ABORT;
break;
case MULT_EXPR:
New syntax for -fsanitize-recover. 2014-10-22 Jakub Jelinek <jakub@redhat.com> Yury Gribov <y.gribov@samsung.com> gcc/ * common.opt (flag_sanitize_recover): New variable. (fsanitize-recover): Remove Var/Init, deprecate. (fsanitize-recover=): New option. * doc/invoke.texi (fsanitize-recover): Update docs. * opts.c (finish_options): Use opts->x_flag_sanitize instead of flag_sanitize. Prohibit -fsanitize-recover for anything besides UBSan. Formatting. (common_handle_option): Handle OPT_fsanitize_recover_ and OPT_fsanitize_recover. Use opts->x_flag_sanitize instead of flag_sanitize. * asan.c (pass_sanopt::execute): Fix up formatting. * ubsan.c (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn, ubsan_expand_objsize_ifn, ubsan_build_overflow_builtin, instrument_bool_enum_load, ubsan_instrument_float_cast, instrument_nonnull_arg, instrument_nonnull_return): Check bits in flag_sanitize_recover bitmask instead of flag_sanitize_recover as bool flag. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division, ubsan_instrument_shift, ubsan_instrument_vla): Check bits in flag_sanitize_recover bitmask instead of flag_sanitize_recover as bool flag. gcc/testsuite/ * c-c++-common/ubsan/align-1.c: Update cmdline options. * c-c++-common/ubsan/align-3.c: Likewise. * c-c++-common/ubsan/bounds-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-7.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-10.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-7.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-8.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-9.c: Likewise. * c-c++-common/ubsan/nonnull-2.c: Likewise. * c-c++-common/ubsan/nonnull-3.c: Likewise. * c-c++-common/ubsan/object-size-3.c: Likewise. * c-c++-common/ubsan/overflow-1.c: Likewise. * c-c++-common/ubsan/overflow-add-1.c: Likewise. * c-c++-common/ubsan/overflow-add-3.c: Likewise. * c-c++-common/ubsan/overflow-mul-1.c: Likewise. * c-c++-common/ubsan/overflow-mul-3.c: Likewise. * c-c++-common/ubsan/overflow-negate-2.c: Likewise. * c-c++-common/ubsan/overflow-sub-1.c: Likewise. * c-c++-common/ubsan/pr59503.c: Likewise. * c-c++-common/ubsan/pr60613-1.c: Likewise. * c-c++-common/ubsan/save-expr-1.c: Likewise. * c-c++-common/ubsan/shift-3.c: Likewise. * c-c++-common/ubsan/shift-6.c: Likewise. * c-c++-common/ubsan/undefined-1.c: Likewise. * c-c++-common/ubsan/vla-2.c: Likewise. * c-c++-common/ubsan/vla-3.c: Likewise. * c-c++-common/ubsan/vla-4.c: Likewise. * g++.dg/ubsan/cxx11-shift-1.C: Likewise. * g++.dg/ubsan/return-2.C: Likewise. * c-c++-common/ubsan/recovery-1.c: New test. * c-c++-common/ubsan/recovery-2.c: New test. * c-c++-common/ubsan/recovery-3.c: New test. * c-c++-common/ubsan/recovery-common.inc: New file. Co-Authored-By: Yury Gribov <y.gribov@samsung.com> From-SVN: r216552
2014-10-22 13:07:10 +02:00
fn_code = (flag_sanitize_recover & SANITIZE_SI_OVERFLOW)
re PR sanitizer/60275 ([UBSAN] Add -f[no-]sanitize-recover/-fsanitize-undefined-trap-on-error to make UBSAN's runtime errors fatal) PR sanitizer/60275 * common.opt (fsanitize-recover, fsanitize-undefined-trap-on-error): New options. * gcc.c (sanitize_spec_function): Don't return "" for "undefined" if flag_sanitize_undefined_trap_on_error. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_DIVREM_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_SHIFT_OUT_OF_BOUNDS_ABORT, BUILT_IN_UBSAN_HANDLE_VLA_BOUND_NOT_POSITIVE_ABORT, BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT, BUILT_IN_UBSAN_HANDLE_ADD_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_SUB_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_MUL_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_NEGATE_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_LOAD_INVALID_VALUE_ABORT): New builtins. * ubsan.c (ubsan_instrument_unreachable): Return __builtin_trap () if flag_sanitize_undefined_trap_on_error. (ubsan_expand_null_ifn): Emit __builtin_trap () if flag_sanitize_undefined_trap_on_error and __ubsan_handle_type_mismatch_abort if !flag_sanitize_recover. (ubsan_expand_null_ifn, ubsan_build_overflow_builtin, instrument_bool_enum_load): Emit __builtin_trap () if flag_sanitize_undefined_trap_on_error and __builtin_handle_*_abort () if !flag_sanitize_recover. * doc/invoke.texi (-fsanitize-recover, -fsanitize-undefined-trap-on-error): Document. c-family/ * c-ubsan.c (ubsan_instrument_return): Return __builtin_trap () if flag_sanitize_undefined_trap_on_error. (ubsan_instrument_division, ubsan_instrument_shift, ubsan_instrument_vla): Likewise. Use __ubsan_handle_*_abort () if !flag_sanitize_recover. testsuite/ * g++.dg/ubsan/return-2.C: Revert 2014-03-24 changes, add -fno-sanitize-recover to dg-options. * g++.dg/ubsan/cxx11-shift-1.C: Remove c++11 target restriction, add -std=c++11 to dg-options. * g++.dg/ubsan/cxx11-shift-2.C: Likewise. * g++.dg/ubsan/cxx1y-vla.C: Remove c++1y target restriction, add -std=c++1y to dg-options. * c-c++-common/ubsan/undefined-1.c: Revert 2014-03-24 changes, add -fno-sanitize-recover to dg-options. * c-c++-common/ubsan/overflow-sub-1.c: Likewise. * c-c++-common/ubsan/vla-4.c: Likewise. * c-c++-common/ubsan/pr59503.c: Likewise. * c-c++-common/ubsan/vla-3.c: Likewise. * c-c++-common/ubsan/save-expr-1.c: Likewise. * c-c++-common/ubsan/overflow-add-1.c: Likewise. * c-c++-common/ubsan/shift-3.c: Likewise. * c-c++-common/ubsan/overflow-1.c: Likewise. * c-c++-common/ubsan/overflow-negate-2.c: Likewise. * c-c++-common/ubsan/vla-2.c: Likewise. * c-c++-common/ubsan/overflow-mul-1.c: Likewise. * c-c++-common/ubsan/pr60613-1.c: Likewise. * c-c++-common/ubsan/shift-6.c: Likewise. * c-c++-common/ubsan/overflow-mul-3.c: Likewise. * c-c++-common/ubsan/overflow-add-3.c: New test. * c-c++-common/ubsan/overflow-add-4.c: New test. * c-c++-common/ubsan/div-by-zero-6.c: New test. * c-c++-common/ubsan/div-by-zero-7.c: New test. From-SVN: r209672
2014-04-23 10:20:12 +02:00
? BUILT_IN_UBSAN_HANDLE_MUL_OVERFLOW
: BUILT_IN_UBSAN_HANDLE_MUL_OVERFLOW_ABORT;
break;
case NEGATE_EXPR:
New syntax for -fsanitize-recover. 2014-10-22 Jakub Jelinek <jakub@redhat.com> Yury Gribov <y.gribov@samsung.com> gcc/ * common.opt (flag_sanitize_recover): New variable. (fsanitize-recover): Remove Var/Init, deprecate. (fsanitize-recover=): New option. * doc/invoke.texi (fsanitize-recover): Update docs. * opts.c (finish_options): Use opts->x_flag_sanitize instead of flag_sanitize. Prohibit -fsanitize-recover for anything besides UBSan. Formatting. (common_handle_option): Handle OPT_fsanitize_recover_ and OPT_fsanitize_recover. Use opts->x_flag_sanitize instead of flag_sanitize. * asan.c (pass_sanopt::execute): Fix up formatting. * ubsan.c (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn, ubsan_expand_objsize_ifn, ubsan_build_overflow_builtin, instrument_bool_enum_load, ubsan_instrument_float_cast, instrument_nonnull_arg, instrument_nonnull_return): Check bits in flag_sanitize_recover bitmask instead of flag_sanitize_recover as bool flag. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division, ubsan_instrument_shift, ubsan_instrument_vla): Check bits in flag_sanitize_recover bitmask instead of flag_sanitize_recover as bool flag. gcc/testsuite/ * c-c++-common/ubsan/align-1.c: Update cmdline options. * c-c++-common/ubsan/align-3.c: Likewise. * c-c++-common/ubsan/bounds-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-7.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-10.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-7.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-8.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-9.c: Likewise. * c-c++-common/ubsan/nonnull-2.c: Likewise. * c-c++-common/ubsan/nonnull-3.c: Likewise. * c-c++-common/ubsan/object-size-3.c: Likewise. * c-c++-common/ubsan/overflow-1.c: Likewise. * c-c++-common/ubsan/overflow-add-1.c: Likewise. * c-c++-common/ubsan/overflow-add-3.c: Likewise. * c-c++-common/ubsan/overflow-mul-1.c: Likewise. * c-c++-common/ubsan/overflow-mul-3.c: Likewise. * c-c++-common/ubsan/overflow-negate-2.c: Likewise. * c-c++-common/ubsan/overflow-sub-1.c: Likewise. * c-c++-common/ubsan/pr59503.c: Likewise. * c-c++-common/ubsan/pr60613-1.c: Likewise. * c-c++-common/ubsan/save-expr-1.c: Likewise. * c-c++-common/ubsan/shift-3.c: Likewise. * c-c++-common/ubsan/shift-6.c: Likewise. * c-c++-common/ubsan/undefined-1.c: Likewise. * c-c++-common/ubsan/vla-2.c: Likewise. * c-c++-common/ubsan/vla-3.c: Likewise. * c-c++-common/ubsan/vla-4.c: Likewise. * g++.dg/ubsan/cxx11-shift-1.C: Likewise. * g++.dg/ubsan/return-2.C: Likewise. * c-c++-common/ubsan/recovery-1.c: New test. * c-c++-common/ubsan/recovery-2.c: New test. * c-c++-common/ubsan/recovery-3.c: New test. * c-c++-common/ubsan/recovery-common.inc: New file. Co-Authored-By: Yury Gribov <y.gribov@samsung.com> From-SVN: r216552
2014-10-22 13:07:10 +02:00
fn_code = (flag_sanitize_recover & SANITIZE_SI_OVERFLOW)
re PR sanitizer/60275 ([UBSAN] Add -f[no-]sanitize-recover/-fsanitize-undefined-trap-on-error to make UBSAN's runtime errors fatal) PR sanitizer/60275 * common.opt (fsanitize-recover, fsanitize-undefined-trap-on-error): New options. * gcc.c (sanitize_spec_function): Don't return "" for "undefined" if flag_sanitize_undefined_trap_on_error. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_DIVREM_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_SHIFT_OUT_OF_BOUNDS_ABORT, BUILT_IN_UBSAN_HANDLE_VLA_BOUND_NOT_POSITIVE_ABORT, BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT, BUILT_IN_UBSAN_HANDLE_ADD_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_SUB_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_MUL_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_NEGATE_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_LOAD_INVALID_VALUE_ABORT): New builtins. * ubsan.c (ubsan_instrument_unreachable): Return __builtin_trap () if flag_sanitize_undefined_trap_on_error. (ubsan_expand_null_ifn): Emit __builtin_trap () if flag_sanitize_undefined_trap_on_error and __ubsan_handle_type_mismatch_abort if !flag_sanitize_recover. (ubsan_expand_null_ifn, ubsan_build_overflow_builtin, instrument_bool_enum_load): Emit __builtin_trap () if flag_sanitize_undefined_trap_on_error and __builtin_handle_*_abort () if !flag_sanitize_recover. * doc/invoke.texi (-fsanitize-recover, -fsanitize-undefined-trap-on-error): Document. c-family/ * c-ubsan.c (ubsan_instrument_return): Return __builtin_trap () if flag_sanitize_undefined_trap_on_error. (ubsan_instrument_division, ubsan_instrument_shift, ubsan_instrument_vla): Likewise. Use __ubsan_handle_*_abort () if !flag_sanitize_recover. testsuite/ * g++.dg/ubsan/return-2.C: Revert 2014-03-24 changes, add -fno-sanitize-recover to dg-options. * g++.dg/ubsan/cxx11-shift-1.C: Remove c++11 target restriction, add -std=c++11 to dg-options. * g++.dg/ubsan/cxx11-shift-2.C: Likewise. * g++.dg/ubsan/cxx1y-vla.C: Remove c++1y target restriction, add -std=c++1y to dg-options. * c-c++-common/ubsan/undefined-1.c: Revert 2014-03-24 changes, add -fno-sanitize-recover to dg-options. * c-c++-common/ubsan/overflow-sub-1.c: Likewise. * c-c++-common/ubsan/vla-4.c: Likewise. * c-c++-common/ubsan/pr59503.c: Likewise. * c-c++-common/ubsan/vla-3.c: Likewise. * c-c++-common/ubsan/save-expr-1.c: Likewise. * c-c++-common/ubsan/overflow-add-1.c: Likewise. * c-c++-common/ubsan/shift-3.c: Likewise. * c-c++-common/ubsan/overflow-1.c: Likewise. * c-c++-common/ubsan/overflow-negate-2.c: Likewise. * c-c++-common/ubsan/vla-2.c: Likewise. * c-c++-common/ubsan/overflow-mul-1.c: Likewise. * c-c++-common/ubsan/pr60613-1.c: Likewise. * c-c++-common/ubsan/shift-6.c: Likewise. * c-c++-common/ubsan/overflow-mul-3.c: Likewise. * c-c++-common/ubsan/overflow-add-3.c: New test. * c-c++-common/ubsan/overflow-add-4.c: New test. * c-c++-common/ubsan/div-by-zero-6.c: New test. * c-c++-common/ubsan/div-by-zero-7.c: New test. From-SVN: r209672
2014-04-23 10:20:12 +02:00
? BUILT_IN_UBSAN_HANDLE_NEGATE_OVERFLOW
: BUILT_IN_UBSAN_HANDLE_NEGATE_OVERFLOW_ABORT;
break;
default:
gcc_unreachable ();
}
tree fn = builtin_decl_explicit (fn_code);
return build_call_expr_loc (loc, fn, 2 + (code != NEGATE_EXPR),
build_fold_addr_expr_loc (loc, data),
ubsan_encode_value (op0, UBSAN_ENCODE_VALUE_RTL),
op1
? ubsan_encode_value (op1,
UBSAN_ENCODE_VALUE_RTL)
: NULL_TREE);
}
/* Perform the signed integer instrumentation. GSI is the iterator
pointing at statement we are trying to instrument. */
static void
instrument_si_overflow (gimple_stmt_iterator gsi)
{
gimple *stmt = gsi_stmt (gsi);
tree_code code = gimple_assign_rhs_code (stmt);
tree lhs = gimple_assign_lhs (stmt);
tree lhstype = TREE_TYPE (lhs);
tree lhsinner = VECTOR_TYPE_P (lhstype) ? TREE_TYPE (lhstype) : lhstype;
tree a, b;
gimple *g;
/* If this is not a signed operation, don't instrument anything here.
Also punt on bit-fields. */
if (!INTEGRAL_TYPE_P (lhsinner)
|| TYPE_OVERFLOW_WRAPS (lhsinner)
|| GET_MODE_BITSIZE (TYPE_MODE (lhsinner)) != TYPE_PRECISION (lhsinner))
return;
switch (code)
{
case MINUS_EXPR:
case PLUS_EXPR:
case MULT_EXPR:
/* Transform
i = u {+,-,*} 5;
into
i = UBSAN_CHECK_{ADD,SUB,MUL} (u, 5); */
a = gimple_assign_rhs1 (stmt);
b = gimple_assign_rhs2 (stmt);
g = gimple_build_call_internal (code == PLUS_EXPR
? IFN_UBSAN_CHECK_ADD
: code == MINUS_EXPR
? IFN_UBSAN_CHECK_SUB
: IFN_UBSAN_CHECK_MUL, 2, a, b);
gimple_call_set_lhs (g, lhs);
gsi_replace (&gsi, g, true);
break;
case NEGATE_EXPR:
/* Represent i = -u;
as
i = UBSAN_CHECK_SUB (0, u); */
a = build_zero_cst (lhstype);
b = gimple_assign_rhs1 (stmt);
g = gimple_build_call_internal (IFN_UBSAN_CHECK_SUB, 2, a, b);
gimple_call_set_lhs (g, lhs);
gsi_replace (&gsi, g, true);
break;
case ABS_EXPR:
/* Transform i = ABS_EXPR<u>;
into
_N = UBSAN_CHECK_SUB (0, u);
i = ABS_EXPR<_N>; */
a = build_zero_cst (lhstype);
b = gimple_assign_rhs1 (stmt);
g = gimple_build_call_internal (IFN_UBSAN_CHECK_SUB, 2, a, b);
gimple-expr.h (create_tmp_var_raw, [...]): Add default NULL value to last argument. * gimple-expr.h (create_tmp_var_raw, create_tmp_var, create_tmp_reg): Add default NULL value to last argument. * tree-ssanames.h (make_ssa_name, copy_ssa_name): Likewise. * gimple-low.c (lower_builtin_posix_memalign): Remove NULL last argument from create_tmp_var_raw, create_tmp_var, create_tmp_reg, make_ssa_name and copy_ssa_name calls. * tree-ssa-strlen.c (get_string_length): Likewise. * tree-emutls.c (gen_emutls_addr, lower_emutls_1): Likewise. * tree-ssa-phiprop.c (phiprop_insert_phi): Likewise. * tree-vect-slp.c (vect_get_constant_vectors): Likewise. * ipa-prop.c (ipa_modify_call_arguments): Likewise. * tree-ssa-forwprop.c (simplify_rotate): Likewise. * tree-ssa-ccp.c (fold_builtin_alloca_with_align): Likewise. * asan.c (build_shadow_mem_access, maybe_create_ssa_name, maybe_cast_to_ptrmode, asan_expand_check_ifn): Likewise. * tsan.c (instrument_expr, instrument_builtin_call, instrument_func_entry): Likewise. * varpool.c (add_new_static_var): Likewise. * tree-loop-distribution.c (generate_memset_builtin): Likewise. * gimplify.c (internal_get_tmp_var, gimplify_return_expr, gimplify_modify_expr_to_memcpy, gimplify_modify_expr_to_memset, gimplify_init_ctor_eval_range, gimplify_init_constructor, gimplify_omp_atomic, gimplify_expr): Likewise. * gimple-builder.c (build_assign, build_type_cast): Likewise. * tree-vect-loop-manip.c (slpeel_update_phi_nodes_for_guard1, slpeel_update_phi_nodes_for_guard2, slpeel_tree_peel_loop_to_edge, vect_loop_versioning): Likewise. * tree-if-conv.c (version_loop_for_if_conversion): Likewise. * gimple-match-head.c (maybe_push_res_to_seq): Likewise. * tree-vect-patterns.c (vect_handle_widen_op_by_const, vect_recog_widen_mult_pattern, vect_operation_fits_smaller_type, vect_recog_over_widening_pattern): Likewise. * tree-sra.c (build_ref_for_offset, create_access_replacement): Likewise. * tree-cfg.c (make_blocks): Likewise. * tree-eh.c (lower_eh_constructs_2, lower_resx, lower_eh_dispatch): Likewise. * tree-ssa-propagate.c (update_call_from_tree): Likewise. * tree-complex.c (get_component_ssa_name, expand_complex_div_wide): Likewise. * tree-ssa-math-opts.c (build_and_insert_cast): Likewise. * tree-tailcall.c (update_accumulator_with_ops): Likewise. * tree-predcom.c (initialize_root_vars, initialize_root_vars_lm, execute_load_motion, reassociate_to_the_same_stmt): Likewise. * tree-ssa-reassoc.c (build_and_add_sum, optimize_range_tests_to_bit_test, update_ops, maybe_optimize_range_tests, rewrite_expr_tree, linearize_expr, negate_value, repropagate_negates): Likewise. * tree-vect-loop.c (vect_is_simple_reduction_1, vect_create_epilog_for_reduction): Likewise. * ipa-split.c (split_function): Likewise. * tree-inline.c (remap_ssa_name, setup_one_parameter, declare_return_variable, tree_function_versioning): Likewise. * tree-cfgcleanup.c (fixup_noreturn_call): Likewise. * cfgexpand.c (update_alias_info_with_stack_vars, expand_used_vars): Likewise. * tree-ssa-phiopt.c (conditional_replacement, abs_replacement, neg_replacement): Likewise. * gimplify-me.c (force_gimple_operand_1, gimple_regimplify_operands): Likewise. * tree-vrp.c (simplify_truth_ops_using_ranges, simplify_float_conversion_using_ranges, simplify_internal_call_using_ranges): Likewise. * tree-switch-conversion.c (emit_case_bit_tests, build_one_array, build_arrays, gen_def_assigns): Likewise. * gimple-fold.c (gimple_fold_builtin_memory_op, gimple_fold_builtin_strcat, gimple_fold_call, gimple_build): Likewise. * tree-vect-generic.c (expand_vector_divmod, optimize_vector_constructor): Likewise. * ubsan.c (ubsan_encode_value, ubsan_expand_null_ifn, ubsan_expand_objsize_ifn, instrument_si_overflow, instrument_bool_enum_load, instrument_nonnull_arg): Likewise. * tree-outof-ssa.c (insert_backedge_copies): Likewise. * tree-ssa-loop-manip.c (create_iv, tree_transform_and_unroll_loop): Likewise. * omp-low.c (scan_omp_parallel, lower_rec_simd_input_clauses, lower_rec_input_clauses, lower_lastprivate_clauses, expand_parallel_call, expand_omp_for_static_chunk, expand_omp_atomic_pipeline, expand_omp_target, maybe_add_implicit_barrier_cancel, lower_omp_single_simple, lower_omp_critical, lower_omp_for, task_copyfn_copy_decl, lower_depend_clauses, lower_omp_target, lower_omp_1, ipa_simd_modify_stmt_ops, simd_clone_adjust): Likewise. * tree-parloops.c (take_address_of, create_phi_for_local_result, create_call_for_reduction_1, separate_decls_in_region, create_parallel_loop): Likewise. * graphite-sese-to-poly.c (rewrite_cross_bb_scalar_dependence, handle_scalar_deps_crossing_scop_limits): Likewise. * trans-mem.c (lower_transaction, build_tm_load, build_tm_store, expand_assign_tm, expand_call_tm, expand_transaction, ipa_tm_insert_gettmclone_call): Likewise. * tree-vect-data-refs.c (bump_vector_ptr, vect_setup_realignment): Likewise. * tree-vect-stmts.c (vect_init_vector, vectorizable_mask_load_store, vectorizable_call, vectorizable_simd_clone_call, vectorizable_conversion, vectorizable_store, permute_vec_elements, vectorizable_load): Likewise. c/ * c-typeck.c (convert_lvalue_to_rvalue, build_atomic_assign, c_finish_stmt_expr): Remove NULL last argument from create_tmp_var_raw and create_tmp_var calls. * c-array-notation.c (fix_builtin_array_notation_fn, build_array_notation_expr, fix_conditional_array_notations_1, fix_array_notation_expr, fix_array_notation_call_expr): Likewise. cp/ * cp-gimplify.c (cxx_omp_clause_apply_fn): Remove NULL last argument from create_tmp_var calls. c-family/ * c-common.c (convert_vector_to_pointer_for_subscript): Remove NULL last argument from create_tmp_var_raw and create_tmp_var calls. * cilk.c (gimplify_cilk_spawn): Likewise. * c-omp.c (c_finish_omp_atomic): Likewise. fortran/ * trans-openmp.c (gfc_omp_finish_clause, gfc_trans_omp_array_reduction_or_udr, gfc_trans_omp_atomic): Remove NULL last argument from create_tmp_var_raw and create_tmp_var calls. From-SVN: r218181
2014-11-29 12:35:30 +01:00
a = make_ssa_name (lhstype);
gimple_call_set_lhs (g, a);
gimple_set_location (g, gimple_location (stmt));
gsi_insert_before (&gsi, g, GSI_SAME_STMT);
gimple_assign_set_rhs1 (stmt, a);
update_stmt (stmt);
break;
default:
break;
}
}
/* Instrument loads from (non-bitfield) bool and C++ enum values
to check if the memory value is outside of the range of the valid
type values. */
static void
instrument_bool_enum_load (gimple_stmt_iterator *gsi)
{
gimple *stmt = gsi_stmt (*gsi);
tree rhs = gimple_assign_rhs1 (stmt);
tree type = TREE_TYPE (rhs);
tree minv = NULL_TREE, maxv = NULL_TREE;
if (TREE_CODE (type) == BOOLEAN_TYPE && (flag_sanitize & SANITIZE_BOOL))
{
minv = boolean_false_node;
maxv = boolean_true_node;
}
else if (TREE_CODE (type) == ENUMERAL_TYPE
&& (flag_sanitize & SANITIZE_ENUM)
&& TREE_TYPE (type) != NULL_TREE
&& TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE
&& (TYPE_PRECISION (TREE_TYPE (type))
< GET_MODE_PRECISION (TYPE_MODE (type))))
{
minv = TYPE_MIN_VALUE (TREE_TYPE (type));
maxv = TYPE_MAX_VALUE (TREE_TYPE (type));
}
else
return;
int modebitsize = GET_MODE_BITSIZE (TYPE_MODE (type));
HOST_WIDE_INT bitsize, bitpos;
tree offset;
decl.c, [...]: Remove redundant enum from machine_mode. gcc/ada/ * gcc-interface/decl.c, gcc-interface/gigi.h, gcc-interface/misc.c, gcc-interface/trans.c, gcc-interface/utils.c, gcc-interface/utils2.c: Remove redundant enum from machine_mode. gcc/c-family/ * c-common.c, c-common.h, c-cppbuiltin.c, c-lex.c: Remove redundant enum from machine_mode. gcc/c/ * c-decl.c, c-tree.h, c-typeck.c: Remove redundant enum from machine_mode. gcc/cp/ * constexpr.c: Remove redundant enum from machine_mode. gcc/fortran/ * trans-types.c, trans-types.h: Remove redundant enum from machine_mode. gcc/go/ * go-lang.c: Remove redundant enum from machine_mode. gcc/java/ * builtins.c, java-tree.h, typeck.c: Remove redundant enum from machine_mode. gcc/lto/ * lto-lang.c: Remove redundant enum from machine_mode. gcc/ * addresses.h, alias.c, asan.c, auto-inc-dec.c, bt-load.c, builtins.c, builtins.h, caller-save.c, calls.c, calls.h, cfgexpand.c, cfgloop.h, cfgrtl.c, combine.c, compare-elim.c, config/aarch64/aarch64-builtins.c, config/aarch64/aarch64-protos.h, config/aarch64/aarch64-simd.md, config/aarch64/aarch64.c, config/aarch64/aarch64.h, config/aarch64/aarch64.md, config/alpha/alpha-protos.h, config/alpha/alpha.c, config/arc/arc-protos.h, config/arc/arc.c, config/arc/arc.h, config/arc/predicates.md, config/arm/aarch-common-protos.h, config/arm/aarch-common.c, config/arm/arm-protos.h, config/arm/arm.c, config/arm/arm.h, config/arm/arm.md, config/arm/neon.md, config/arm/thumb2.md, config/avr/avr-log.c, config/avr/avr-protos.h, config/avr/avr.c, config/avr/avr.md, config/bfin/bfin-protos.h, config/bfin/bfin.c, config/c6x/c6x-protos.h, config/c6x/c6x.c, config/c6x/c6x.md, config/cr16/cr16-protos.h, config/cr16/cr16.c, config/cris/cris-protos.h, config/cris/cris.c, config/cris/cris.md, config/darwin-protos.h, config/darwin.c, config/epiphany/epiphany-protos.h, config/epiphany/epiphany.c, config/epiphany/epiphany.md, config/fr30/fr30.c, config/frv/frv-protos.h, config/frv/frv.c, config/frv/predicates.md, config/h8300/h8300-protos.h, config/h8300/h8300.c, config/i386/i386-builtin-types.awk, config/i386/i386-protos.h, config/i386/i386.c, config/i386/i386.md, config/i386/predicates.md, config/i386/sse.md, config/i386/sync.md, config/ia64/ia64-protos.h, config/ia64/ia64.c, config/iq2000/iq2000-protos.h, config/iq2000/iq2000.c, config/iq2000/iq2000.md, config/lm32/lm32-protos.h, config/lm32/lm32.c, config/m32c/m32c-protos.h, config/m32c/m32c.c, config/m32r/m32r-protos.h, config/m32r/m32r.c, config/m68k/m68k-protos.h, config/m68k/m68k.c, config/mcore/mcore-protos.h, config/mcore/mcore.c, config/mcore/mcore.md, config/mep/mep-protos.h, config/mep/mep.c, config/microblaze/microblaze-protos.h, config/microblaze/microblaze.c, config/mips/mips-protos.h, config/mips/mips.c, config/mmix/mmix-protos.h, config/mmix/mmix.c, config/mn10300/mn10300-protos.h, config/mn10300/mn10300.c, config/moxie/moxie.c, config/msp430/msp430-protos.h, config/msp430/msp430.c, config/nds32/nds32-cost.c, config/nds32/nds32-intrinsic.c, config/nds32/nds32-md-auxiliary.c, config/nds32/nds32-protos.h, config/nds32/nds32.c, config/nios2/nios2-protos.h, config/nios2/nios2.c, config/pa/pa-protos.h, config/pa/pa.c, config/pdp11/pdp11-protos.h, config/pdp11/pdp11.c, config/rl78/rl78-protos.h, config/rl78/rl78.c, config/rs6000/altivec.md, config/rs6000/rs6000-c.c, config/rs6000/rs6000-protos.h, config/rs6000/rs6000.c, config/rs6000/rs6000.h, config/rx/rx-protos.h, config/rx/rx.c, config/s390/predicates.md, config/s390/s390-protos.h, config/s390/s390.c, config/s390/s390.h, config/s390/s390.md, config/sh/predicates.md, config/sh/sh-protos.h, config/sh/sh.c, config/sh/sh.md, config/sparc/predicates.md, config/sparc/sparc-protos.h, config/sparc/sparc.c, config/sparc/sparc.md, config/spu/spu-protos.h, config/spu/spu.c, config/stormy16/stormy16-protos.h, config/stormy16/stormy16.c, config/tilegx/tilegx-protos.h, config/tilegx/tilegx.c, config/tilegx/tilegx.md, config/tilepro/tilepro-protos.h, config/tilepro/tilepro.c, config/v850/v850-protos.h, config/v850/v850.c, config/v850/v850.md, config/vax/vax-protos.h, config/vax/vax.c, config/vms/vms-c.c, config/xtensa/xtensa-protos.h, config/xtensa/xtensa.c, coverage.c, cprop.c, cse.c, cselib.c, cselib.h, dbxout.c, ddg.c, df-problems.c, dfp.c, dfp.h, doc/md.texi, doc/rtl.texi, doc/tm.texi, doc/tm.texi.in, dojump.c, dse.c, dwarf2cfi.c, dwarf2out.c, dwarf2out.h, emit-rtl.c, emit-rtl.h, except.c, explow.c, expmed.c, expmed.h, expr.c, expr.h, final.c, fixed-value.c, fixed-value.h, fold-const.c, function.c, function.h, fwprop.c, gcse.c, gengenrtl.c, genmodes.c, genopinit.c, genoutput.c, genpreds.c, genrecog.c, gensupport.c, gimple-ssa-strength-reduction.c, graphite-clast-to-gimple.c, haifa-sched.c, hooks.c, hooks.h, ifcvt.c, internal-fn.c, ira-build.c, ira-color.c, ira-conflicts.c, ira-costs.c, ira-emit.c, ira-int.h, ira-lives.c, ira.c, ira.h, jump.c, langhooks.h, libfuncs.h, lists.c, loop-doloop.c, loop-invariant.c, loop-iv.c, loop-unroll.c, lower-subreg.c, lower-subreg.h, lra-assigns.c, lra-constraints.c, lra-eliminations.c, lra-int.h, lra-lives.c, lra-spills.c, lra.c, lra.h, machmode.h, omp-low.c, optabs.c, optabs.h, output.h, postreload.c, print-tree.c, read-rtl.c, real.c, real.h, recog.c, recog.h, ree.c, reg-stack.c, regcprop.c, reginfo.c, regrename.c, regs.h, reload.c, reload.h, reload1.c, rtl.c, rtl.h, rtlanal.c, rtlhash.c, rtlhooks-def.h, rtlhooks.c, sched-deps.c, sel-sched-dump.c, sel-sched-ir.c, sel-sched-ir.h, sel-sched.c, simplify-rtx.c, stmt.c, stor-layout.c, stor-layout.h, target.def, targhooks.c, targhooks.h, tree-affine.c, tree-call-cdce.c, tree-complex.c, tree-data-ref.c, tree-dfa.c, tree-if-conv.c, tree-inline.c, tree-outof-ssa.c, tree-scalar-evolution.c, tree-ssa-address.c, tree-ssa-ccp.c, tree-ssa-loop-ivopts.c, tree-ssa-loop-ivopts.h, tree-ssa-loop-manip.c, tree-ssa-loop-prefetch.c, tree-ssa-math-opts.c, tree-ssa-reassoc.c, tree-ssa-sccvn.c, tree-streamer-in.c, tree-switch-conversion.c, tree-vect-data-refs.c, tree-vect-generic.c, tree-vect-loop.c, tree-vect-patterns.c, tree-vect-slp.c, tree-vect-stmts.c, tree-vrp.c, tree.c, tree.h, tsan.c, ubsan.c, valtrack.c, var-tracking.c, varasm.c: Remove redundant enum from machine_mode. gcc/ * gengtype.c (main): Treat machine_mode as a scalar typedef. * genmodes.c (emit_insn_modes_h): Hide inline functions if USED_FOR_TARGET. From-SVN: r216834
2014-10-29 13:02:45 +01:00
machine_mode mode;
int volatilep = 0, reversep, unsignedp = 0;
tree base = get_inner_reference (rhs, &bitsize, &bitpos, &offset, &mode,
Convert TYPE_ALIGN_OK to a TYPE_LANG_FLAG. 2016-07-11 Bernd Edlinger <bernd.edlinger@hotmail.de> Convert TYPE_ALIGN_OK to a TYPE_LANG_FLAG. * tree-core.h (tree_base::nothrow_flag): Adjust comment. (tree_type_common::lang_flag_7): New. (tree_type_common::spare): Reduce size. * tree.h (TYPE_ALIGN_OK): Remove. (TYPE_LANG_FLAG_7): New. (get_inner_reference): Adjust header. * print-tree.c (print_node): Adjust. * expr.c (get_inner_reference): Remove parameter keep_aligning. (get_bit_range, expand_assignment, expand_expr_addr_expr_1): Adjust calls to get_inner_reference. (expand_expr_real_1): Adjust call to get_inner_reference. Remove handling of TYPE_ALIGN_OK. * builtins.c (get_object_alignment_2): Adjust call to get_inner_reference. Remove handling of VIEW_CONVERT_EXPR. * emit-rtl.c (set_mem_attributes_minus_bitpos): Remove handling of TYPE_ALIGN_OK. * asan.c (instrument_derefs): Adjust calls to get_inner_reference. * cfgexpand.c (expand_debug_expr): Likewise. * dbxout.c (dbxout_expand_expr): Likewise. * dwarf2out.c (loc_list_for_address_of_addr_expr_of_indirect_ref, loc_list_from_tree, fortran_common): Likewise. * fold-const.c (optimize_bit_field_compare, decode_field_reference, fold_unary_loc, fold_comparison, split_address_to_core_and_offset): Likewise. * gimple-laddress.c (execute): Likewise. * gimple-ssa-strength-reduction.c (slsr_process_ref): Likewise. * gimplify.c (gimplify_scan_omp_clauses): Likewise. * hsa-gen.c (gen_hsa_addr): Likewise. * simplifx-rtx.c (delegitimize_mem_from_attrs): Likewise. * tsan.c (instrument_expr): Likewise. * ubsan.c (instrument_bool_enum_load, instrument_object_size): Likewise. * tree.c (verify_type_variant): Remove handling of TYPE_ALIGN_OK. * tree-affine.c (tree_to_aff_combination, get_inner_reference_aff): Adjust calls to get_inner_reference. * tree-data-ref.c (split_constant_offset_1, dr_analyze_innermost): Likewise. * tree-scalar-evolution.c (interpret_rhs_expr): Likewise. * tree-sra.c (ipa_sra_check_caller): Likewise. * tree-ssa-loop-ivopts.c (split_address_cost): Likewise. * tree-ssa-math-opts.c (find_bswap_or_nop_load, bswap_replace): Likewise. * tree-vect-data-refs.c (vect_check_gather, vect_analyze_data_refs): Likewise. * config/mips/mips.c (r10k_safe_mem_expr_p): Likewise. * config/pa/pa.c (pa_emit_move_sequence): Remove handling of TYPE_ALIGN_OK. ada: 2016-07-11 Bernd Edlinger <bernd.edlinger@hotmail.de> Convert TYPE_ALIGN_OK to a TYPE_LANG_FLAG. * gcc-interface/ada-tree.h (TYPE_ALIGN_OK): Define. * gcc-interface/trans.c (Attribute_to_gnu): Adjust call to get_inner_reference. * gcc-interface/utils2.c (build_unary_op): Likewise. From-SVN: r238210
2016-07-11 17:02:12 +02:00
&unsignedp, &reversep, &volatilep);
tree utype = build_nonstandard_integer_type (modebitsize, 1);
tree-ssa.c (target_for_debug_bind, [...]): Use VAR_P and/or VAR_OR_FUNCTION_DECL_P macros. * tree-ssa.c (target_for_debug_bind, verify_phi_args, ssa_undefined_value_p, maybe_optimize_var): Use VAR_P and/or VAR_OR_FUNCTION_DECL_P macros. * tree-chkp.c (chkp_register_var_initializer, chkp_make_static_bounds, chkp_get_bounds_for_decl_addr, chkp_parse_array_and_component_ref, chkp_find_bounds_1): Likewise. * ipa-polymorphic-call.c (decl_maybe_in_construction_p): Likewise. * hsa-gen.c (get_symbol_for_decl): Likewise. * cgraphunit.c (check_global_declaration, analyze_functions, handle_alias_pairs, thunk_adjust, cgraph_node::expand_thunk): Likewise. * gimple-fold.c (can_refer_decl_in_current_unit_p, canonicalize_constructor_val, gimple_get_virt_method_for_vtable): Likewise. * tree.c (set_decl_section_name, copy_node_stat, need_assembler_name_p, free_lang_data_in_decl, find_decls_types_r, merge_dllimport_decl_attributes, handle_dll_attribute, decl_init_priority_insert, auto_var_in_fn_p, array_at_struct_end_p, verify_type): Likewise. * gimple-ssa-isolate-paths.c (find_implicit_erroneous_behavior, find_explicit_erroneous_behavior): Likewise. * sdbout.c (sdbout_toplevel_data, sdbout_late_global_decl): Likewise. * ipa.c (process_references): Likewise. * tree-chkp-opt.c (chkp_get_check_result): Likewise. * varasm.c (get_block_for_decl, use_blocks_for_decl_p, make_decl_rtl, notice_global_symbol, assemble_variable, mark_decl_referenced, build_constant_desc, output_constant_def_contents, do_assemble_alias, make_decl_one_only, default_section_type_flags, categorize_decl_for_section, default_encode_section_info): Likewise. * trans-mem.c (requires_barrier): Likewise. * gimple-expr.c (mark_addressable): Likewise. * cfgexpand.c (add_scope_conflicts_1, expand_one_var, expand_used_vars_for_block, clear_tree_used, stack_protect_decl_p, expand_debug_expr): Likewise. * tree-dump.c (dequeue_and_dump): Likewise. * ubsan.c (instrument_bool_enum_load): Likewise. * tree-pretty-print.c (print_declaration): Likewise. * simplify-rtx.c (delegitimize_mem_from_attrs): Likewise. * tree-ssa-uninit.c (warn_uninitialized_vars): Likewise. * asan.c (asan_protect_global, instrument_derefs): Likewise. * tree-into-ssa.c (rewrite_stmt, maybe_register_def, pass_build_ssa::execute): Likewise. * var-tracking.c (var_debug_decl, track_expr_p): Likewise. * tree-ssa-loop-ivopts.c (force_expr_to_var_cost, split_address_cost): Likewise. * ipa-split.c (test_nonssa_use, consider_split, mark_nonssa_use): Likewise. * tree-inline.c (insert_debug_decl_map, remap_ssa_name, can_be_nonlocal, remap_decls, copy_debug_stmt, initialize_inlined_parameters, add_local_variables, reset_debug_binding, replace_locals_op): Likewise. * dse.c (can_escape): Likewise. * ipa-devirt.c (compare_virtual_tables, referenced_from_vtable_p): Likewise. * tree-diagnostic.c (default_tree_printer): Likewise. * tree-streamer-in.c (unpack_ts_decl_common_value_fields, unpack_ts_decl_with_vis_value_fields, lto_input_ts_decl_common_tree_pointers): Likewise. * builtins.c (builtin_save_expr, fold_builtin_expect, readonly_data_expr): Likewise. * tree-ssa-structalias.c (new_var_info, get_constraint_for_ssa_var, create_variable_info_for, set_uids_in_ptset, visit_loadstore): Likewise. * gimple-streamer-out.c (output_gimple_stmt): Likewise. * gimplify.c (force_constant_size, gimplify_bind_expr, gimplify_decl_expr, gimplify_var_or_parm_decl, gimplify_compound_lval, gimplify_init_constructor, gimplify_modify_expr, gimplify_asm_expr, gimplify_oacc_declare, gimplify_type_sizes): Likewise. * cgraphbuild.c (record_reference, record_type_list, mark_address, mark_load, mark_store, pass_build_cgraph_edges::execute): Likewise. * tree-ssa-live.c (mark_all_vars_used_1, remove_unused_scope_block_p, remove_unused_locals): Likewise. * tree-ssa-alias.c (ptr_deref_may_alias_decl_p, ptrs_compare_unequal, ref_maybe_used_by_call_p_1, call_may_clobber_ref_p_1): Likewise. * function.c (instantiate_expr, instantiate_decls_1, setjmp_vars_warning, add_local_decl): Likewise. * alias.c (ao_ref_from_mem, get_alias_set, compare_base_symbol_refs): Likewise. * tree-stdarg.c (find_va_list_reference, va_list_counter_struct_op, va_list_ptr_read, va_list_ptr_write, check_all_va_list_escapes, optimize_va_list_gpr_fpr_size): Likewise. * tree-nrv.c (pass_nrv::execute): Likewise. * tsan.c (instrument_expr): Likewise. * tree-ssa-dce.c (remove_dead_stmt): Likewise. * vtable-verify.c (verify_bb_vtables): Likewise. * tree-dfa.c (ssa_default_def, set_ssa_default_def, get_ref_base_and_extent): Likewise. * toplev.c (wrapup_global_declaration_1, wrapup_global_declaration_2): Likewise. * tree-sra.c (static bool constant_decl_p, find_var_candidates, analyze_all_variable_accesses): Likewise. * tree-nested.c (get_nonlocal_debug_decl, convert_nonlocal_omp_clauses, note_nonlocal_vla_type, note_nonlocal_block_vlas, convert_nonlocal_reference_stmt, get_local_debug_decl, convert_local_omp_clauses, convert_local_reference_stmt, nesting_copy_decl, remap_vla_decls): Likewise. * tree-vect-data-refs.c (vect_can_force_dr_alignment_p): Likewise. * stmt.c (decl_overlaps_hard_reg_set_p): Likewise. * dbxout.c (dbxout_late_global_decl, dbxout_type_fields, dbxout_symbol, dbxout_common_check): Likewise. * expr.c (expand_assignment, expand_expr_real_2, expand_expr_real_1, string_constant): Likewise. * hsa.c (hsa_get_declaration_name): Likewise. * passes.c (rest_of_decl_compilation): Likewise. * tree-ssanames.c (make_ssa_name_fn): Likewise. * tree-streamer-out.c (pack_ts_decl_common_value_fields, pack_ts_decl_with_vis_value_fields, write_ts_decl_common_tree_pointers): Likewise. * stor-layout.c (place_field): Likewise. * symtab.c (symtab_node::maybe_create_reference, symtab_node::verify_base, symtab_node::make_decl_local, symtab_node::copy_visibility_from, symtab_node::can_increase_alignment_p): Likewise. * dwarf2out.c (add_var_loc_to_decl, tls_mem_loc_descriptor, decl_by_reference_p, reference_to_unused, rtl_for_decl_location, fortran_common, add_location_or_const_value_attribute, add_scalar_info, add_linkage_name, set_block_abstract_flags, local_function_static, gen_variable_die, dwarf2out_late_global_decl, optimize_one_addr_into_implicit_ptr, optimize_location_into_implicit_ptr): Likewise. * gimple-low.c (record_vars_into): Likewise. * ipa-visibility.c (update_vtable_references): Likewise. * tree-ssa-address.c (fixed_address_object_p, copy_ref_info): Likewise. * lto-streamer-out.c (tree_is_indexable, get_symbol_initial_value, DFS::DFS_write_tree_body, write_symbol): Likewise. * langhooks.c (lhd_warn_unused_global_decl, lhd_set_decl_assembler_name): Likewise. * attribs.c (decl_attributes): Likewise. * except.c (output_ttype): Likewise. * varpool.c (varpool_node::get_create, ctor_for_folding, varpool_node::assemble_decl, varpool_node::create_alias): Likewise. * fold-const.c (fold_unary_loc): Likewise. * ipa-prop.c (ipa_compute_jump_functions_for_edge, ipa_find_agg_cst_from_init): Likewise. * omp-low.c (expand_omp_regimplify_p, expand_omp_taskreg, expand_omp_target, lower_omp_regimplify_p, grid_reg_assignment_to_local_var_p, grid_remap_prebody_decls, find_link_var_op): Likewise. * tree-chrec.c (chrec_contains_symbols): Likewise. * tree-cfg.c (verify_address, verify_expr, verify_expr_location_1, gimple_duplicate_bb, move_stmt_op, replace_block_vars_by_duplicates, execute_fixup_cfg): Likewise. From-SVN: r240900
2016-10-09 13:19:48 +02:00
if ((VAR_P (base) && DECL_HARD_REGISTER (base))
|| (bitpos % modebitsize) != 0
|| bitsize != modebitsize
|| GET_MODE_BITSIZE (TYPE_MODE (utype)) != modebitsize
|| TREE_CODE (gimple_assign_lhs (stmt)) != SSA_NAME)
return;
bool ends_bb = stmt_ends_bb_p (stmt);
location_t loc = gimple_location (stmt);
tree lhs = gimple_assign_lhs (stmt);
tree ptype = build_pointer_type (TREE_TYPE (rhs));
tree atype = reference_alias_ptr_type (rhs);
gimple *g = gimple_build_assign (make_ssa_name (ptype),
build_fold_addr_expr (rhs));
gimple_set_location (g, loc);
gsi_insert_before (gsi, g, GSI_SAME_STMT);
tree mem = build2 (MEM_REF, utype, gimple_assign_lhs (g),
build_int_cst (atype, 0));
gimple-expr.h (create_tmp_var_raw, [...]): Add default NULL value to last argument. * gimple-expr.h (create_tmp_var_raw, create_tmp_var, create_tmp_reg): Add default NULL value to last argument. * tree-ssanames.h (make_ssa_name, copy_ssa_name): Likewise. * gimple-low.c (lower_builtin_posix_memalign): Remove NULL last argument from create_tmp_var_raw, create_tmp_var, create_tmp_reg, make_ssa_name and copy_ssa_name calls. * tree-ssa-strlen.c (get_string_length): Likewise. * tree-emutls.c (gen_emutls_addr, lower_emutls_1): Likewise. * tree-ssa-phiprop.c (phiprop_insert_phi): Likewise. * tree-vect-slp.c (vect_get_constant_vectors): Likewise. * ipa-prop.c (ipa_modify_call_arguments): Likewise. * tree-ssa-forwprop.c (simplify_rotate): Likewise. * tree-ssa-ccp.c (fold_builtin_alloca_with_align): Likewise. * asan.c (build_shadow_mem_access, maybe_create_ssa_name, maybe_cast_to_ptrmode, asan_expand_check_ifn): Likewise. * tsan.c (instrument_expr, instrument_builtin_call, instrument_func_entry): Likewise. * varpool.c (add_new_static_var): Likewise. * tree-loop-distribution.c (generate_memset_builtin): Likewise. * gimplify.c (internal_get_tmp_var, gimplify_return_expr, gimplify_modify_expr_to_memcpy, gimplify_modify_expr_to_memset, gimplify_init_ctor_eval_range, gimplify_init_constructor, gimplify_omp_atomic, gimplify_expr): Likewise. * gimple-builder.c (build_assign, build_type_cast): Likewise. * tree-vect-loop-manip.c (slpeel_update_phi_nodes_for_guard1, slpeel_update_phi_nodes_for_guard2, slpeel_tree_peel_loop_to_edge, vect_loop_versioning): Likewise. * tree-if-conv.c (version_loop_for_if_conversion): Likewise. * gimple-match-head.c (maybe_push_res_to_seq): Likewise. * tree-vect-patterns.c (vect_handle_widen_op_by_const, vect_recog_widen_mult_pattern, vect_operation_fits_smaller_type, vect_recog_over_widening_pattern): Likewise. * tree-sra.c (build_ref_for_offset, create_access_replacement): Likewise. * tree-cfg.c (make_blocks): Likewise. * tree-eh.c (lower_eh_constructs_2, lower_resx, lower_eh_dispatch): Likewise. * tree-ssa-propagate.c (update_call_from_tree): Likewise. * tree-complex.c (get_component_ssa_name, expand_complex_div_wide): Likewise. * tree-ssa-math-opts.c (build_and_insert_cast): Likewise. * tree-tailcall.c (update_accumulator_with_ops): Likewise. * tree-predcom.c (initialize_root_vars, initialize_root_vars_lm, execute_load_motion, reassociate_to_the_same_stmt): Likewise. * tree-ssa-reassoc.c (build_and_add_sum, optimize_range_tests_to_bit_test, update_ops, maybe_optimize_range_tests, rewrite_expr_tree, linearize_expr, negate_value, repropagate_negates): Likewise. * tree-vect-loop.c (vect_is_simple_reduction_1, vect_create_epilog_for_reduction): Likewise. * ipa-split.c (split_function): Likewise. * tree-inline.c (remap_ssa_name, setup_one_parameter, declare_return_variable, tree_function_versioning): Likewise. * tree-cfgcleanup.c (fixup_noreturn_call): Likewise. * cfgexpand.c (update_alias_info_with_stack_vars, expand_used_vars): Likewise. * tree-ssa-phiopt.c (conditional_replacement, abs_replacement, neg_replacement): Likewise. * gimplify-me.c (force_gimple_operand_1, gimple_regimplify_operands): Likewise. * tree-vrp.c (simplify_truth_ops_using_ranges, simplify_float_conversion_using_ranges, simplify_internal_call_using_ranges): Likewise. * tree-switch-conversion.c (emit_case_bit_tests, build_one_array, build_arrays, gen_def_assigns): Likewise. * gimple-fold.c (gimple_fold_builtin_memory_op, gimple_fold_builtin_strcat, gimple_fold_call, gimple_build): Likewise. * tree-vect-generic.c (expand_vector_divmod, optimize_vector_constructor): Likewise. * ubsan.c (ubsan_encode_value, ubsan_expand_null_ifn, ubsan_expand_objsize_ifn, instrument_si_overflow, instrument_bool_enum_load, instrument_nonnull_arg): Likewise. * tree-outof-ssa.c (insert_backedge_copies): Likewise. * tree-ssa-loop-manip.c (create_iv, tree_transform_and_unroll_loop): Likewise. * omp-low.c (scan_omp_parallel, lower_rec_simd_input_clauses, lower_rec_input_clauses, lower_lastprivate_clauses, expand_parallel_call, expand_omp_for_static_chunk, expand_omp_atomic_pipeline, expand_omp_target, maybe_add_implicit_barrier_cancel, lower_omp_single_simple, lower_omp_critical, lower_omp_for, task_copyfn_copy_decl, lower_depend_clauses, lower_omp_target, lower_omp_1, ipa_simd_modify_stmt_ops, simd_clone_adjust): Likewise. * tree-parloops.c (take_address_of, create_phi_for_local_result, create_call_for_reduction_1, separate_decls_in_region, create_parallel_loop): Likewise. * graphite-sese-to-poly.c (rewrite_cross_bb_scalar_dependence, handle_scalar_deps_crossing_scop_limits): Likewise. * trans-mem.c (lower_transaction, build_tm_load, build_tm_store, expand_assign_tm, expand_call_tm, expand_transaction, ipa_tm_insert_gettmclone_call): Likewise. * tree-vect-data-refs.c (bump_vector_ptr, vect_setup_realignment): Likewise. * tree-vect-stmts.c (vect_init_vector, vectorizable_mask_load_store, vectorizable_call, vectorizable_simd_clone_call, vectorizable_conversion, vectorizable_store, permute_vec_elements, vectorizable_load): Likewise. c/ * c-typeck.c (convert_lvalue_to_rvalue, build_atomic_assign, c_finish_stmt_expr): Remove NULL last argument from create_tmp_var_raw and create_tmp_var calls. * c-array-notation.c (fix_builtin_array_notation_fn, build_array_notation_expr, fix_conditional_array_notations_1, fix_array_notation_expr, fix_array_notation_call_expr): Likewise. cp/ * cp-gimplify.c (cxx_omp_clause_apply_fn): Remove NULL last argument from create_tmp_var calls. c-family/ * c-common.c (convert_vector_to_pointer_for_subscript): Remove NULL last argument from create_tmp_var_raw and create_tmp_var calls. * cilk.c (gimplify_cilk_spawn): Likewise. * c-omp.c (c_finish_omp_atomic): Likewise. fortran/ * trans-openmp.c (gfc_omp_finish_clause, gfc_trans_omp_array_reduction_or_udr, gfc_trans_omp_atomic): Remove NULL last argument from create_tmp_var_raw and create_tmp_var calls. From-SVN: r218181
2014-11-29 12:35:30 +01:00
tree urhs = make_ssa_name (utype);
if (ends_bb)
{
gimple_assign_set_lhs (stmt, urhs);
gimple.h (gimple_build_assign_stat): Remove prototype. * gimple.h (gimple_build_assign_stat): Remove prototype. (gimple_build_assign): Remove define. Add overload prototypes with tree lhs and either a tree rhs, or enum tree_code and 1, 2 or 3 tree operands. * gimple.c (gimple_build_assign_stat): Renamed to... (gimple_build_assign): ... this. Add overloads with enum tree_code and 1, 2 or 3 tree operands. (gimple_build_assign_with_ops): Remove 1 and 2 operand overloads. Rename the 3 operand overload to ... (gimple_build_assign_1): ... this. Make it static inline. * tree-ssa-strlen.c (get_string_length): Use gimple_build_assign instead of gimple_build_assign_with_ops, swap the order of first two arguments and adjust formatting where necessary. * tree-vect-slp.c (vect_get_constant_vectors, vect_create_mask_and_perm): Likewise. * tree-ssa-forwprop.c (simplify_rotate): Likewise. * asan.c (build_shadow_mem_access, maybe_create_ssa_name, maybe_cast_to_ptrmode, asan_expand_check_ifn): Likewise. * tsan.c (instrument_builtin_call): Likewise. * tree-chkp.c (chkp_compute_bounds_for_assignment, chkp_generate_extern_var_bounds): Likewise. * tree-loop-distribution.c (generate_memset_builtin): Likewise. * tree-ssa-loop-im.c (rewrite_reciprocal): Likewise. * gimple-builder.c (build_assign, build_type_cast): Likewise. * tree-vect-loop-manip.c (vect_create_cond_for_align_checks): Likewise. * value-prof.c (gimple_divmod_fixed_value, gimple_mod_pow2, gimple_mod_subtract): Likewise. * gimple-match-head.c (maybe_push_res_to_seq): Likewise. * tree-vect-patterns.c (vect_recog_dot_prod_pattern, vect_recog_sad_pattern, vect_handle_widen_op_by_const, vect_recog_widen_mult_pattern, vect_recog_pow_pattern, vect_recog_widen_sum_pattern, vect_operation_fits_smaller_type, vect_recog_over_widening_pattern, vect_recog_widen_shift_pattern, vect_recog_rotate_pattern, vect_recog_vector_vector_shift_pattern, vect_recog_divmod_pattern, vect_recog_mixed_size_cond_pattern, adjust_bool_pattern_cast, adjust_bool_pattern, vect_recog_bool_pattern): Likewise. * gimple-ssa-strength-reduction.c (create_add_on_incoming_edge, insert_initializers, introduce_cast_before_cand, replace_one_candidate): Likewise. * tree-ssa-math-opts.c (insert_reciprocals, powi_as_mults_1, powi_as_mults, build_and_insert_binop, build_and_insert_cast, pass_cse_sincos::execute, bswap_replace, convert_mult_to_fma): Likewise. * tree-tailcall.c (adjust_return_value_with_ops, update_accumulator_with_ops): Likewise. * tree-predcom.c (reassociate_to_the_same_stmt): Likewise. * tree-ssa-reassoc.c (build_and_add_sum, optimize_range_tests_to_bit_test, update_ops, maybe_optimize_range_tests, rewrite_expr_tree, linearize_expr, negate_value, repropagate_negates, attempt_builtin_powi, reassociate_bb): Likewise. * tree-vect-loop.c (vect_is_simple_reduction_1, get_initial_def_for_induction, vect_create_epilog_for_reduction): Likewise. * ipa-split.c (split_function): Likewise. * tree-ssa-phiopt.c (conditional_replacement, minmax_replacement, abs_replacement, neg_replacement): Likewise. * tree-profile.c (gimple_gen_edge_profiler): Likewise. * tree-vrp.c (simplify_truth_ops_using_ranges, simplify_float_conversion_using_ranges, simplify_internal_call_using_ranges): Likewise. * gimple-fold.c (rewrite_to_defined_overflow, gimple_build): Likewise. * tree-vect-generic.c (expand_vector_divmod, optimize_vector_constructor): Likewise. * ubsan.c (ubsan_expand_null_ifn, ubsan_expand_objsize_ifn, instrument_bool_enum_load): Likewise. * tree-ssa-loop-manip.c (create_iv): Likewise. * omp-low.c (lower_rec_input_clauses, expand_omp_for_generic, expand_omp_for_static_nochunk, expand_omp_for_static_chunk, expand_cilk_for, simd_clone_adjust): Likewise. * trans-mem.c (expand_transaction): Likewise. * tree-vect-data-refs.c (bump_vector_ptr, vect_permute_store_chain, vect_setup_realignment, vect_permute_load_chain, vect_shift_permute_load_chain): Likewise. * tree-vect-stmts.c (vect_init_vector, vectorizable_mask_load_store, vectorizable_simd_clone_call, vect_gen_widened_results_half, vect_create_vectorized_demotion_stmts, vectorizable_conversion, vectorizable_shift, vectorizable_operation, vectorizable_store, permute_vec_elements, vectorizable_load): Likewise. From-SVN: r218216
2014-12-01 14:58:10 +01:00
g = gimple_build_assign (lhs, NOP_EXPR, urhs);
gimple_set_location (g, loc);
edge e = find_fallthru_edge (gimple_bb (stmt)->succs);
gsi_insert_on_edge_immediate (e, g);
gimple_assign_set_rhs_from_tree (gsi, mem);
update_stmt (stmt);
*gsi = gsi_for_stmt (g);
g = stmt;
}
else
{
g = gimple_build_assign (urhs, mem);
gimple_set_location (g, loc);
gsi_insert_before (gsi, g, GSI_SAME_STMT);
}
minv = fold_convert (utype, minv);
maxv = fold_convert (utype, maxv);
if (!integer_zerop (minv))
{
gimple.h (gimple_build_assign_stat): Remove prototype. * gimple.h (gimple_build_assign_stat): Remove prototype. (gimple_build_assign): Remove define. Add overload prototypes with tree lhs and either a tree rhs, or enum tree_code and 1, 2 or 3 tree operands. * gimple.c (gimple_build_assign_stat): Renamed to... (gimple_build_assign): ... this. Add overloads with enum tree_code and 1, 2 or 3 tree operands. (gimple_build_assign_with_ops): Remove 1 and 2 operand overloads. Rename the 3 operand overload to ... (gimple_build_assign_1): ... this. Make it static inline. * tree-ssa-strlen.c (get_string_length): Use gimple_build_assign instead of gimple_build_assign_with_ops, swap the order of first two arguments and adjust formatting where necessary. * tree-vect-slp.c (vect_get_constant_vectors, vect_create_mask_and_perm): Likewise. * tree-ssa-forwprop.c (simplify_rotate): Likewise. * asan.c (build_shadow_mem_access, maybe_create_ssa_name, maybe_cast_to_ptrmode, asan_expand_check_ifn): Likewise. * tsan.c (instrument_builtin_call): Likewise. * tree-chkp.c (chkp_compute_bounds_for_assignment, chkp_generate_extern_var_bounds): Likewise. * tree-loop-distribution.c (generate_memset_builtin): Likewise. * tree-ssa-loop-im.c (rewrite_reciprocal): Likewise. * gimple-builder.c (build_assign, build_type_cast): Likewise. * tree-vect-loop-manip.c (vect_create_cond_for_align_checks): Likewise. * value-prof.c (gimple_divmod_fixed_value, gimple_mod_pow2, gimple_mod_subtract): Likewise. * gimple-match-head.c (maybe_push_res_to_seq): Likewise. * tree-vect-patterns.c (vect_recog_dot_prod_pattern, vect_recog_sad_pattern, vect_handle_widen_op_by_const, vect_recog_widen_mult_pattern, vect_recog_pow_pattern, vect_recog_widen_sum_pattern, vect_operation_fits_smaller_type, vect_recog_over_widening_pattern, vect_recog_widen_shift_pattern, vect_recog_rotate_pattern, vect_recog_vector_vector_shift_pattern, vect_recog_divmod_pattern, vect_recog_mixed_size_cond_pattern, adjust_bool_pattern_cast, adjust_bool_pattern, vect_recog_bool_pattern): Likewise. * gimple-ssa-strength-reduction.c (create_add_on_incoming_edge, insert_initializers, introduce_cast_before_cand, replace_one_candidate): Likewise. * tree-ssa-math-opts.c (insert_reciprocals, powi_as_mults_1, powi_as_mults, build_and_insert_binop, build_and_insert_cast, pass_cse_sincos::execute, bswap_replace, convert_mult_to_fma): Likewise. * tree-tailcall.c (adjust_return_value_with_ops, update_accumulator_with_ops): Likewise. * tree-predcom.c (reassociate_to_the_same_stmt): Likewise. * tree-ssa-reassoc.c (build_and_add_sum, optimize_range_tests_to_bit_test, update_ops, maybe_optimize_range_tests, rewrite_expr_tree, linearize_expr, negate_value, repropagate_negates, attempt_builtin_powi, reassociate_bb): Likewise. * tree-vect-loop.c (vect_is_simple_reduction_1, get_initial_def_for_induction, vect_create_epilog_for_reduction): Likewise. * ipa-split.c (split_function): Likewise. * tree-ssa-phiopt.c (conditional_replacement, minmax_replacement, abs_replacement, neg_replacement): Likewise. * tree-profile.c (gimple_gen_edge_profiler): Likewise. * tree-vrp.c (simplify_truth_ops_using_ranges, simplify_float_conversion_using_ranges, simplify_internal_call_using_ranges): Likewise. * gimple-fold.c (rewrite_to_defined_overflow, gimple_build): Likewise. * tree-vect-generic.c (expand_vector_divmod, optimize_vector_constructor): Likewise. * ubsan.c (ubsan_expand_null_ifn, ubsan_expand_objsize_ifn, instrument_bool_enum_load): Likewise. * tree-ssa-loop-manip.c (create_iv): Likewise. * omp-low.c (lower_rec_input_clauses, expand_omp_for_generic, expand_omp_for_static_nochunk, expand_omp_for_static_chunk, expand_cilk_for, simd_clone_adjust): Likewise. * trans-mem.c (expand_transaction): Likewise. * tree-vect-data-refs.c (bump_vector_ptr, vect_permute_store_chain, vect_setup_realignment, vect_permute_load_chain, vect_shift_permute_load_chain): Likewise. * tree-vect-stmts.c (vect_init_vector, vectorizable_mask_load_store, vectorizable_simd_clone_call, vect_gen_widened_results_half, vect_create_vectorized_demotion_stmts, vectorizable_conversion, vectorizable_shift, vectorizable_operation, vectorizable_store, permute_vec_elements, vectorizable_load): Likewise. From-SVN: r218216
2014-12-01 14:58:10 +01:00
g = gimple_build_assign (make_ssa_name (utype), MINUS_EXPR, urhs, minv);
gimple_set_location (g, loc);
gsi_insert_before (gsi, g, GSI_SAME_STMT);
}
gimple_stmt_iterator gsi2 = *gsi;
basic_block then_bb, fallthru_bb;
*gsi = create_cond_insert_point (gsi, true, false, true,
&then_bb, &fallthru_bb);
g = gimple_build_cond (GT_EXPR, gimple_assign_lhs (g),
int_const_binop (MINUS_EXPR, maxv, minv),
NULL_TREE, NULL_TREE);
gimple_set_location (g, loc);
gsi_insert_after (gsi, g, GSI_NEW_STMT);
if (!ends_bb)
{
gimple.h (gimple_build_assign_with_ops): Add unary arg overload. * gimple.h (gimple_build_assign_with_ops): Add unary arg overload. (gimple_assign_set_rhs_with_ops_1): Renamed to ... (gimple_assign_set_rhs_with_ops): ... this. Adjust binary arg inline overload to use it. Add unary arg overload. * gimple.c (gimple_build_assign_with_ops): New unary arg overload. (gimple_assign_set_rhs_from_tree): Use gimple_assign_set_rhs_with_ops instead of gimple_assign_set_rhs_with_ops_1. (gimple_assign_set_rhs_with_ops_1): Renamed to ... (gimple_assign_set_rhs_with_ops): ... this. * ipa-split.c (split_function): Remove last NULL argument from gimple_build_assign_with_ops call. * tree-ssa-loop-im.c (move_computations_dom_walker::before_dom_children): Likewise. * tsan.c (instrument_builtin_call): Likewise. * tree-vect-stmts.c (vect_init_vector, vectorizable_mask_load_store, vectorizable_conversion, vectorizable_load): Likewise. * tree-vect-loop.c (vect_is_simple_reduction_1, get_initial_def_for_induction): Likewise. * tree-loop-distribution.c (generate_memset_builtin): Likewise. * tree-vect-patterns.c (vect_handle_widen_op_by_const, vect_recog_widen_mult_pattern, vect_operation_fits_smaller_type, vect_recog_over_widening_pattern, vect_recog_rotate_pattern, vect_recog_vector_vector_shift_pattern, vect_recog_divmod_pattern, vect_recog_mixed_size_cond_pattern, adjust_bool_pattern_cast, adjust_bool_pattern, vect_recog_bool_pattern): Likewise. * tree-ssa-phiopt.c (conditional_replacement, abs_replacement, neg_replacement): Likewise. * asan.c (build_shadow_mem_access, maybe_create_ssa_name, maybe_cast_to_ptrmode, asan_expand_check_ifn): Likewise. * tree-vect-slp.c (vect_get_constant_vectors): Likewise. * omp-low.c (lower_rec_input_clauses, expand_omp_for_generic, expand_omp_for_static_nochunk, expand_omp_for_static_chunk, simd_clone_adjust): Likewise. * tree-vect-loop-manip.c (vect_create_cond_for_align_checks): Likewise. * gimple-ssa-strength-reduction.c (introduce_cast_before_cand, replace_one_candidate): Likewise. * gimple-builder.c (build_type_cast): Likewise. * tree-ssa-forwprop.c (simplify_rotate): Likewise. (forward_propagate_addr_expr_1): Remove last NULL argument from gimple_assign_set_rhs_with_ops call. (simplify_vector_constructor): Use gimple_assign_set_rhs_with_ops instead of gimple_assign_set_rhs_with_ops_1. * tree-ssa-reassoc.c (maybe_optimize_range_tests): Remove last NULL argument from gimple_build_assign_with_ops call. (repropagate_negates): Remove last NULL argument from gimple_assign_set_rhs_with_ops call. * ubsan.c (ubsan_expand_null_ifn, ubsan_expand_objsize_ifn): Remove last NULL argument from gimple_build_assign_with_ops call. (instrument_bool_enum_load): Likewise. Remove last NULL argument from gimple_assign_set_rhs_with_ops call. * tree-ssa-math-opts.c (build_and_insert_cast, convert_mult_to_fma): Remove last NULL argument from gimple_build_assign_with_ops call. (bswap_replace): Likewise. Use gimple_assign_set_rhs_with_ops instead of gimple_assign_set_rhs_with_ops_1. (convert_plusminus_to_widen): Use gimple_assign_set_rhs_with_ops instead of gimple_assign_set_rhs_with_ops_1. * gimple-fold.c (replace_stmt_with_simplification): Likewise. (rewrite_to_defined_overflow, gimple_build): Remove last NULL argument from gimple_build_assign_with_ops call. * tree-ssa-strlen.c (handle_pointer_plus): Remove last NULL argument from gimple_assign_set_rhs_with_ops call. * tree-vrp.c (simplify_truth_ops_using_ranges, simplify_bit_ops_using_ranges): Remove last NULL argument from gimple_assign_set_rhs_with_ops call. (simplify_float_conversion_using_ranges, simplify_internal_call_using_ranges): Remove last NULL argument from gimple_build_assign_with_ops call. From-SVN: r217781
2014-11-19 15:43:02 +01:00
gimple_assign_set_rhs_with_ops (&gsi2, NOP_EXPR, urhs);
update_stmt (stmt);
}
gsi2 = gsi_after_labels (then_bb);
re PR sanitizer/60275 ([UBSAN] Add -f[no-]sanitize-recover/-fsanitize-undefined-trap-on-error to make UBSAN's runtime errors fatal) PR sanitizer/60275 * common.opt (fsanitize-recover, fsanitize-undefined-trap-on-error): New options. * gcc.c (sanitize_spec_function): Don't return "" for "undefined" if flag_sanitize_undefined_trap_on_error. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_DIVREM_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_SHIFT_OUT_OF_BOUNDS_ABORT, BUILT_IN_UBSAN_HANDLE_VLA_BOUND_NOT_POSITIVE_ABORT, BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT, BUILT_IN_UBSAN_HANDLE_ADD_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_SUB_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_MUL_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_NEGATE_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_LOAD_INVALID_VALUE_ABORT): New builtins. * ubsan.c (ubsan_instrument_unreachable): Return __builtin_trap () if flag_sanitize_undefined_trap_on_error. (ubsan_expand_null_ifn): Emit __builtin_trap () if flag_sanitize_undefined_trap_on_error and __ubsan_handle_type_mismatch_abort if !flag_sanitize_recover. (ubsan_expand_null_ifn, ubsan_build_overflow_builtin, instrument_bool_enum_load): Emit __builtin_trap () if flag_sanitize_undefined_trap_on_error and __builtin_handle_*_abort () if !flag_sanitize_recover. * doc/invoke.texi (-fsanitize-recover, -fsanitize-undefined-trap-on-error): Document. c-family/ * c-ubsan.c (ubsan_instrument_return): Return __builtin_trap () if flag_sanitize_undefined_trap_on_error. (ubsan_instrument_division, ubsan_instrument_shift, ubsan_instrument_vla): Likewise. Use __ubsan_handle_*_abort () if !flag_sanitize_recover. testsuite/ * g++.dg/ubsan/return-2.C: Revert 2014-03-24 changes, add -fno-sanitize-recover to dg-options. * g++.dg/ubsan/cxx11-shift-1.C: Remove c++11 target restriction, add -std=c++11 to dg-options. * g++.dg/ubsan/cxx11-shift-2.C: Likewise. * g++.dg/ubsan/cxx1y-vla.C: Remove c++1y target restriction, add -std=c++1y to dg-options. * c-c++-common/ubsan/undefined-1.c: Revert 2014-03-24 changes, add -fno-sanitize-recover to dg-options. * c-c++-common/ubsan/overflow-sub-1.c: Likewise. * c-c++-common/ubsan/vla-4.c: Likewise. * c-c++-common/ubsan/pr59503.c: Likewise. * c-c++-common/ubsan/vla-3.c: Likewise. * c-c++-common/ubsan/save-expr-1.c: Likewise. * c-c++-common/ubsan/overflow-add-1.c: Likewise. * c-c++-common/ubsan/shift-3.c: Likewise. * c-c++-common/ubsan/overflow-1.c: Likewise. * c-c++-common/ubsan/overflow-negate-2.c: Likewise. * c-c++-common/ubsan/vla-2.c: Likewise. * c-c++-common/ubsan/overflow-mul-1.c: Likewise. * c-c++-common/ubsan/pr60613-1.c: Likewise. * c-c++-common/ubsan/shift-6.c: Likewise. * c-c++-common/ubsan/overflow-mul-3.c: Likewise. * c-c++-common/ubsan/overflow-add-3.c: New test. * c-c++-common/ubsan/overflow-add-4.c: New test. * c-c++-common/ubsan/div-by-zero-6.c: New test. * c-c++-common/ubsan/div-by-zero-7.c: New test. From-SVN: r209672
2014-04-23 10:20:12 +02:00
if (flag_sanitize_undefined_trap_on_error)
g = gimple_build_call (builtin_decl_explicit (BUILT_IN_TRAP), 0);
else
{
tree data = ubsan_create_data ("__ubsan_invalid_value_data", 1, &loc,
ubsan_type_descriptor (type), NULL_TREE,
NULL_TREE);
re PR sanitizer/60275 ([UBSAN] Add -f[no-]sanitize-recover/-fsanitize-undefined-trap-on-error to make UBSAN's runtime errors fatal) PR sanitizer/60275 * common.opt (fsanitize-recover, fsanitize-undefined-trap-on-error): New options. * gcc.c (sanitize_spec_function): Don't return "" for "undefined" if flag_sanitize_undefined_trap_on_error. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_DIVREM_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_SHIFT_OUT_OF_BOUNDS_ABORT, BUILT_IN_UBSAN_HANDLE_VLA_BOUND_NOT_POSITIVE_ABORT, BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT, BUILT_IN_UBSAN_HANDLE_ADD_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_SUB_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_MUL_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_NEGATE_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_LOAD_INVALID_VALUE_ABORT): New builtins. * ubsan.c (ubsan_instrument_unreachable): Return __builtin_trap () if flag_sanitize_undefined_trap_on_error. (ubsan_expand_null_ifn): Emit __builtin_trap () if flag_sanitize_undefined_trap_on_error and __ubsan_handle_type_mismatch_abort if !flag_sanitize_recover. (ubsan_expand_null_ifn, ubsan_build_overflow_builtin, instrument_bool_enum_load): Emit __builtin_trap () if flag_sanitize_undefined_trap_on_error and __builtin_handle_*_abort () if !flag_sanitize_recover. * doc/invoke.texi (-fsanitize-recover, -fsanitize-undefined-trap-on-error): Document. c-family/ * c-ubsan.c (ubsan_instrument_return): Return __builtin_trap () if flag_sanitize_undefined_trap_on_error. (ubsan_instrument_division, ubsan_instrument_shift, ubsan_instrument_vla): Likewise. Use __ubsan_handle_*_abort () if !flag_sanitize_recover. testsuite/ * g++.dg/ubsan/return-2.C: Revert 2014-03-24 changes, add -fno-sanitize-recover to dg-options. * g++.dg/ubsan/cxx11-shift-1.C: Remove c++11 target restriction, add -std=c++11 to dg-options. * g++.dg/ubsan/cxx11-shift-2.C: Likewise. * g++.dg/ubsan/cxx1y-vla.C: Remove c++1y target restriction, add -std=c++1y to dg-options. * c-c++-common/ubsan/undefined-1.c: Revert 2014-03-24 changes, add -fno-sanitize-recover to dg-options. * c-c++-common/ubsan/overflow-sub-1.c: Likewise. * c-c++-common/ubsan/vla-4.c: Likewise. * c-c++-common/ubsan/pr59503.c: Likewise. * c-c++-common/ubsan/vla-3.c: Likewise. * c-c++-common/ubsan/save-expr-1.c: Likewise. * c-c++-common/ubsan/overflow-add-1.c: Likewise. * c-c++-common/ubsan/shift-3.c: Likewise. * c-c++-common/ubsan/overflow-1.c: Likewise. * c-c++-common/ubsan/overflow-negate-2.c: Likewise. * c-c++-common/ubsan/vla-2.c: Likewise. * c-c++-common/ubsan/overflow-mul-1.c: Likewise. * c-c++-common/ubsan/pr60613-1.c: Likewise. * c-c++-common/ubsan/shift-6.c: Likewise. * c-c++-common/ubsan/overflow-mul-3.c: Likewise. * c-c++-common/ubsan/overflow-add-3.c: New test. * c-c++-common/ubsan/overflow-add-4.c: New test. * c-c++-common/ubsan/div-by-zero-6.c: New test. * c-c++-common/ubsan/div-by-zero-7.c: New test. From-SVN: r209672
2014-04-23 10:20:12 +02:00
data = build_fold_addr_expr_loc (loc, data);
enum built_in_function bcode
New syntax for -fsanitize-recover. 2014-10-22 Jakub Jelinek <jakub@redhat.com> Yury Gribov <y.gribov@samsung.com> gcc/ * common.opt (flag_sanitize_recover): New variable. (fsanitize-recover): Remove Var/Init, deprecate. (fsanitize-recover=): New option. * doc/invoke.texi (fsanitize-recover): Update docs. * opts.c (finish_options): Use opts->x_flag_sanitize instead of flag_sanitize. Prohibit -fsanitize-recover for anything besides UBSan. Formatting. (common_handle_option): Handle OPT_fsanitize_recover_ and OPT_fsanitize_recover. Use opts->x_flag_sanitize instead of flag_sanitize. * asan.c (pass_sanopt::execute): Fix up formatting. * ubsan.c (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn, ubsan_expand_objsize_ifn, ubsan_build_overflow_builtin, instrument_bool_enum_load, ubsan_instrument_float_cast, instrument_nonnull_arg, instrument_nonnull_return): Check bits in flag_sanitize_recover bitmask instead of flag_sanitize_recover as bool flag. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division, ubsan_instrument_shift, ubsan_instrument_vla): Check bits in flag_sanitize_recover bitmask instead of flag_sanitize_recover as bool flag. gcc/testsuite/ * c-c++-common/ubsan/align-1.c: Update cmdline options. * c-c++-common/ubsan/align-3.c: Likewise. * c-c++-common/ubsan/bounds-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-7.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-10.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-7.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-8.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-9.c: Likewise. * c-c++-common/ubsan/nonnull-2.c: Likewise. * c-c++-common/ubsan/nonnull-3.c: Likewise. * c-c++-common/ubsan/object-size-3.c: Likewise. * c-c++-common/ubsan/overflow-1.c: Likewise. * c-c++-common/ubsan/overflow-add-1.c: Likewise. * c-c++-common/ubsan/overflow-add-3.c: Likewise. * c-c++-common/ubsan/overflow-mul-1.c: Likewise. * c-c++-common/ubsan/overflow-mul-3.c: Likewise. * c-c++-common/ubsan/overflow-negate-2.c: Likewise. * c-c++-common/ubsan/overflow-sub-1.c: Likewise. * c-c++-common/ubsan/pr59503.c: Likewise. * c-c++-common/ubsan/pr60613-1.c: Likewise. * c-c++-common/ubsan/save-expr-1.c: Likewise. * c-c++-common/ubsan/shift-3.c: Likewise. * c-c++-common/ubsan/shift-6.c: Likewise. * c-c++-common/ubsan/undefined-1.c: Likewise. * c-c++-common/ubsan/vla-2.c: Likewise. * c-c++-common/ubsan/vla-3.c: Likewise. * c-c++-common/ubsan/vla-4.c: Likewise. * g++.dg/ubsan/cxx11-shift-1.C: Likewise. * g++.dg/ubsan/return-2.C: Likewise. * c-c++-common/ubsan/recovery-1.c: New test. * c-c++-common/ubsan/recovery-2.c: New test. * c-c++-common/ubsan/recovery-3.c: New test. * c-c++-common/ubsan/recovery-common.inc: New file. Co-Authored-By: Yury Gribov <y.gribov@samsung.com> From-SVN: r216552
2014-10-22 13:07:10 +02:00
= (flag_sanitize_recover & (TREE_CODE (type) == BOOLEAN_TYPE
? SANITIZE_BOOL : SANITIZE_ENUM))
re PR sanitizer/60275 ([UBSAN] Add -f[no-]sanitize-recover/-fsanitize-undefined-trap-on-error to make UBSAN's runtime errors fatal) PR sanitizer/60275 * common.opt (fsanitize-recover, fsanitize-undefined-trap-on-error): New options. * gcc.c (sanitize_spec_function): Don't return "" for "undefined" if flag_sanitize_undefined_trap_on_error. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_DIVREM_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_SHIFT_OUT_OF_BOUNDS_ABORT, BUILT_IN_UBSAN_HANDLE_VLA_BOUND_NOT_POSITIVE_ABORT, BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT, BUILT_IN_UBSAN_HANDLE_ADD_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_SUB_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_MUL_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_NEGATE_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_LOAD_INVALID_VALUE_ABORT): New builtins. * ubsan.c (ubsan_instrument_unreachable): Return __builtin_trap () if flag_sanitize_undefined_trap_on_error. (ubsan_expand_null_ifn): Emit __builtin_trap () if flag_sanitize_undefined_trap_on_error and __ubsan_handle_type_mismatch_abort if !flag_sanitize_recover. (ubsan_expand_null_ifn, ubsan_build_overflow_builtin, instrument_bool_enum_load): Emit __builtin_trap () if flag_sanitize_undefined_trap_on_error and __builtin_handle_*_abort () if !flag_sanitize_recover. * doc/invoke.texi (-fsanitize-recover, -fsanitize-undefined-trap-on-error): Document. c-family/ * c-ubsan.c (ubsan_instrument_return): Return __builtin_trap () if flag_sanitize_undefined_trap_on_error. (ubsan_instrument_division, ubsan_instrument_shift, ubsan_instrument_vla): Likewise. Use __ubsan_handle_*_abort () if !flag_sanitize_recover. testsuite/ * g++.dg/ubsan/return-2.C: Revert 2014-03-24 changes, add -fno-sanitize-recover to dg-options. * g++.dg/ubsan/cxx11-shift-1.C: Remove c++11 target restriction, add -std=c++11 to dg-options. * g++.dg/ubsan/cxx11-shift-2.C: Likewise. * g++.dg/ubsan/cxx1y-vla.C: Remove c++1y target restriction, add -std=c++1y to dg-options. * c-c++-common/ubsan/undefined-1.c: Revert 2014-03-24 changes, add -fno-sanitize-recover to dg-options. * c-c++-common/ubsan/overflow-sub-1.c: Likewise. * c-c++-common/ubsan/vla-4.c: Likewise. * c-c++-common/ubsan/pr59503.c: Likewise. * c-c++-common/ubsan/vla-3.c: Likewise. * c-c++-common/ubsan/save-expr-1.c: Likewise. * c-c++-common/ubsan/overflow-add-1.c: Likewise. * c-c++-common/ubsan/shift-3.c: Likewise. * c-c++-common/ubsan/overflow-1.c: Likewise. * c-c++-common/ubsan/overflow-negate-2.c: Likewise. * c-c++-common/ubsan/vla-2.c: Likewise. * c-c++-common/ubsan/overflow-mul-1.c: Likewise. * c-c++-common/ubsan/pr60613-1.c: Likewise. * c-c++-common/ubsan/shift-6.c: Likewise. * c-c++-common/ubsan/overflow-mul-3.c: Likewise. * c-c++-common/ubsan/overflow-add-3.c: New test. * c-c++-common/ubsan/overflow-add-4.c: New test. * c-c++-common/ubsan/div-by-zero-6.c: New test. * c-c++-common/ubsan/div-by-zero-7.c: New test. From-SVN: r209672
2014-04-23 10:20:12 +02:00
? BUILT_IN_UBSAN_HANDLE_LOAD_INVALID_VALUE
: BUILT_IN_UBSAN_HANDLE_LOAD_INVALID_VALUE_ABORT;
tree fn = builtin_decl_explicit (bcode);
tree val = ubsan_encode_value (urhs, UBSAN_ENCODE_VALUE_GIMPLE);
val = force_gimple_operand_gsi (&gsi2, val, true, NULL_TREE, true,
GSI_SAME_STMT);
re PR sanitizer/60275 ([UBSAN] Add -f[no-]sanitize-recover/-fsanitize-undefined-trap-on-error to make UBSAN's runtime errors fatal) PR sanitizer/60275 * common.opt (fsanitize-recover, fsanitize-undefined-trap-on-error): New options. * gcc.c (sanitize_spec_function): Don't return "" for "undefined" if flag_sanitize_undefined_trap_on_error. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_DIVREM_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_SHIFT_OUT_OF_BOUNDS_ABORT, BUILT_IN_UBSAN_HANDLE_VLA_BOUND_NOT_POSITIVE_ABORT, BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT, BUILT_IN_UBSAN_HANDLE_ADD_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_SUB_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_MUL_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_NEGATE_OVERFLOW_ABORT, BUILT_IN_UBSAN_HANDLE_LOAD_INVALID_VALUE_ABORT): New builtins. * ubsan.c (ubsan_instrument_unreachable): Return __builtin_trap () if flag_sanitize_undefined_trap_on_error. (ubsan_expand_null_ifn): Emit __builtin_trap () if flag_sanitize_undefined_trap_on_error and __ubsan_handle_type_mismatch_abort if !flag_sanitize_recover. (ubsan_expand_null_ifn, ubsan_build_overflow_builtin, instrument_bool_enum_load): Emit __builtin_trap () if flag_sanitize_undefined_trap_on_error and __builtin_handle_*_abort () if !flag_sanitize_recover. * doc/invoke.texi (-fsanitize-recover, -fsanitize-undefined-trap-on-error): Document. c-family/ * c-ubsan.c (ubsan_instrument_return): Return __builtin_trap () if flag_sanitize_undefined_trap_on_error. (ubsan_instrument_division, ubsan_instrument_shift, ubsan_instrument_vla): Likewise. Use __ubsan_handle_*_abort () if !flag_sanitize_recover. testsuite/ * g++.dg/ubsan/return-2.C: Revert 2014-03-24 changes, add -fno-sanitize-recover to dg-options. * g++.dg/ubsan/cxx11-shift-1.C: Remove c++11 target restriction, add -std=c++11 to dg-options. * g++.dg/ubsan/cxx11-shift-2.C: Likewise. * g++.dg/ubsan/cxx1y-vla.C: Remove c++1y target restriction, add -std=c++1y to dg-options. * c-c++-common/ubsan/undefined-1.c: Revert 2014-03-24 changes, add -fno-sanitize-recover to dg-options. * c-c++-common/ubsan/overflow-sub-1.c: Likewise. * c-c++-common/ubsan/vla-4.c: Likewise. * c-c++-common/ubsan/pr59503.c: Likewise. * c-c++-common/ubsan/vla-3.c: Likewise. * c-c++-common/ubsan/save-expr-1.c: Likewise. * c-c++-common/ubsan/overflow-add-1.c: Likewise. * c-c++-common/ubsan/shift-3.c: Likewise. * c-c++-common/ubsan/overflow-1.c: Likewise. * c-c++-common/ubsan/overflow-negate-2.c: Likewise. * c-c++-common/ubsan/vla-2.c: Likewise. * c-c++-common/ubsan/overflow-mul-1.c: Likewise. * c-c++-common/ubsan/pr60613-1.c: Likewise. * c-c++-common/ubsan/shift-6.c: Likewise. * c-c++-common/ubsan/overflow-mul-3.c: Likewise. * c-c++-common/ubsan/overflow-add-3.c: New test. * c-c++-common/ubsan/overflow-add-4.c: New test. * c-c++-common/ubsan/div-by-zero-6.c: New test. * c-c++-common/ubsan/div-by-zero-7.c: New test. From-SVN: r209672
2014-04-23 10:20:12 +02:00
g = gimple_build_call (fn, 2, data, val);
}
gimple_set_location (g, loc);
gsi_insert_before (&gsi2, g, GSI_SAME_STMT);
ubsan_create_edge (g);
*gsi = gsi_for_stmt (stmt);
}
/* Determine if we can propagate given LOCATION to ubsan_data descriptor to use
new style handlers. Libubsan uses heuristics to destinguish between old and
new styles and relies on these properties for filename:
a) Location's filename must not be NULL.
b) Location's filename must not be equal to "".
c) Location's filename must not be equal to "\1".
d) First two bytes of filename must not contain '\xff' symbol. */
static bool
ubsan_use_new_style_p (location_t loc)
{
if (loc == UNKNOWN_LOCATION)
return false;
expanded_location xloc = expand_location (loc);
if (xloc.file == NULL || strncmp (xloc.file, "\1", 2) == 0
|| xloc.file[0] == '\0' || xloc.file[0] == '\xff'
|| xloc.file[1] == '\xff')
return false;
return true;
}
builtins.def: Change SANITIZE_FLOAT_DIVIDE to SANITIZE_NONDEFAULT. * builtins.def: Change SANITIZE_FLOAT_DIVIDE to SANITIZE_NONDEFAULT. * gcc.c (sanitize_spec_function): Likewise. * convert.c (convert_to_integer): Include "ubsan.h". Add floating-point to integer instrumentation. * doc/invoke.texi: Document -fsanitize=float-cast-overflow. * flag-types.h (enum sanitize_code): Add SANITIZE_FLOAT_CAST and SANITIZE_NONDEFAULT. * opts.c (common_handle_option): Handle -fsanitize=float-cast-overflow. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_FLOAT_CAST_OVERFLOW, BUILT_IN_UBSAN_HANDLE_FLOAT_CAST_OVERFLOW_ABORT): Add. * ubsan.c: Include "realmpfr.h" and "dfp.h". (get_ubsan_type_info_for_type): Handle REAL_TYPEs. (ubsan_type_descriptor): Set tkind to 0xffff for types other than float/double/long double. (ubsan_instrument_float_cast): New function. * ubsan.h (ubsan_instrument_float_cast): Declare. testsuite/ * c-c++-common/ubsan/float-cast-overflow-1.c: New test. * c-c++-common/ubsan/float-cast-overflow-10.c: New test. * c-c++-common/ubsan/float-cast-overflow-2.c: New test. * c-c++-common/ubsan/float-cast-overflow-3.c: New test. * c-c++-common/ubsan/float-cast-overflow-4.c: New test. * c-c++-common/ubsan/float-cast-overflow-5.c: New test. * c-c++-common/ubsan/float-cast-overflow-6.c: New test. * c-c++-common/ubsan/float-cast-overflow-7.c: New test. * c-c++-common/ubsan/float-cast-overflow-7.h: New file. * c-c++-common/ubsan/float-cast-overflow-8.c: New test. * c-c++-common/ubsan/float-cast-overflow-9.c: New test. * c-c++-common/ubsan/float-cast.h: New file. * g++.dg/ubsan/float-cast-overflow-bf.C: New test. * gcc.dg/ubsan/float-cast-overflow-bf.c: New test. libsanitizer/ * ubsan/ubsan_value.cc (getFloatValue): Handle 96-bit floating-point types. Co-Authored-By: Jakub Jelinek <jakub@redhat.com> From-SVN: r210862
2014-05-23 16:44:42 +02:00
/* Instrument float point-to-integer conversion. TYPE is an integer type of
destination, EXPR is floating-point expression. */
builtins.def: Change SANITIZE_FLOAT_DIVIDE to SANITIZE_NONDEFAULT. * builtins.def: Change SANITIZE_FLOAT_DIVIDE to SANITIZE_NONDEFAULT. * gcc.c (sanitize_spec_function): Likewise. * convert.c (convert_to_integer): Include "ubsan.h". Add floating-point to integer instrumentation. * doc/invoke.texi: Document -fsanitize=float-cast-overflow. * flag-types.h (enum sanitize_code): Add SANITIZE_FLOAT_CAST and SANITIZE_NONDEFAULT. * opts.c (common_handle_option): Handle -fsanitize=float-cast-overflow. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_FLOAT_CAST_OVERFLOW, BUILT_IN_UBSAN_HANDLE_FLOAT_CAST_OVERFLOW_ABORT): Add. * ubsan.c: Include "realmpfr.h" and "dfp.h". (get_ubsan_type_info_for_type): Handle REAL_TYPEs. (ubsan_type_descriptor): Set tkind to 0xffff for types other than float/double/long double. (ubsan_instrument_float_cast): New function. * ubsan.h (ubsan_instrument_float_cast): Declare. testsuite/ * c-c++-common/ubsan/float-cast-overflow-1.c: New test. * c-c++-common/ubsan/float-cast-overflow-10.c: New test. * c-c++-common/ubsan/float-cast-overflow-2.c: New test. * c-c++-common/ubsan/float-cast-overflow-3.c: New test. * c-c++-common/ubsan/float-cast-overflow-4.c: New test. * c-c++-common/ubsan/float-cast-overflow-5.c: New test. * c-c++-common/ubsan/float-cast-overflow-6.c: New test. * c-c++-common/ubsan/float-cast-overflow-7.c: New test. * c-c++-common/ubsan/float-cast-overflow-7.h: New file. * c-c++-common/ubsan/float-cast-overflow-8.c: New test. * c-c++-common/ubsan/float-cast-overflow-9.c: New test. * c-c++-common/ubsan/float-cast.h: New file. * g++.dg/ubsan/float-cast-overflow-bf.C: New test. * gcc.dg/ubsan/float-cast-overflow-bf.c: New test. libsanitizer/ * ubsan/ubsan_value.cc (getFloatValue): Handle 96-bit floating-point types. Co-Authored-By: Jakub Jelinek <jakub@redhat.com> From-SVN: r210862
2014-05-23 16:44:42 +02:00
tree
ubsan_instrument_float_cast (location_t loc, tree type, tree expr)
builtins.def: Change SANITIZE_FLOAT_DIVIDE to SANITIZE_NONDEFAULT. * builtins.def: Change SANITIZE_FLOAT_DIVIDE to SANITIZE_NONDEFAULT. * gcc.c (sanitize_spec_function): Likewise. * convert.c (convert_to_integer): Include "ubsan.h". Add floating-point to integer instrumentation. * doc/invoke.texi: Document -fsanitize=float-cast-overflow. * flag-types.h (enum sanitize_code): Add SANITIZE_FLOAT_CAST and SANITIZE_NONDEFAULT. * opts.c (common_handle_option): Handle -fsanitize=float-cast-overflow. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_FLOAT_CAST_OVERFLOW, BUILT_IN_UBSAN_HANDLE_FLOAT_CAST_OVERFLOW_ABORT): Add. * ubsan.c: Include "realmpfr.h" and "dfp.h". (get_ubsan_type_info_for_type): Handle REAL_TYPEs. (ubsan_type_descriptor): Set tkind to 0xffff for types other than float/double/long double. (ubsan_instrument_float_cast): New function. * ubsan.h (ubsan_instrument_float_cast): Declare. testsuite/ * c-c++-common/ubsan/float-cast-overflow-1.c: New test. * c-c++-common/ubsan/float-cast-overflow-10.c: New test. * c-c++-common/ubsan/float-cast-overflow-2.c: New test. * c-c++-common/ubsan/float-cast-overflow-3.c: New test. * c-c++-common/ubsan/float-cast-overflow-4.c: New test. * c-c++-common/ubsan/float-cast-overflow-5.c: New test. * c-c++-common/ubsan/float-cast-overflow-6.c: New test. * c-c++-common/ubsan/float-cast-overflow-7.c: New test. * c-c++-common/ubsan/float-cast-overflow-7.h: New file. * c-c++-common/ubsan/float-cast-overflow-8.c: New test. * c-c++-common/ubsan/float-cast-overflow-9.c: New test. * c-c++-common/ubsan/float-cast.h: New file. * g++.dg/ubsan/float-cast-overflow-bf.C: New test. * gcc.dg/ubsan/float-cast-overflow-bf.c: New test. libsanitizer/ * ubsan/ubsan_value.cc (getFloatValue): Handle 96-bit floating-point types. Co-Authored-By: Jakub Jelinek <jakub@redhat.com> From-SVN: r210862
2014-05-23 16:44:42 +02:00
{
tree expr_type = TREE_TYPE (expr);
tree t, tt, fn, min, max;
decl.c, [...]: Remove redundant enum from machine_mode. gcc/ada/ * gcc-interface/decl.c, gcc-interface/gigi.h, gcc-interface/misc.c, gcc-interface/trans.c, gcc-interface/utils.c, gcc-interface/utils2.c: Remove redundant enum from machine_mode. gcc/c-family/ * c-common.c, c-common.h, c-cppbuiltin.c, c-lex.c: Remove redundant enum from machine_mode. gcc/c/ * c-decl.c, c-tree.h, c-typeck.c: Remove redundant enum from machine_mode. gcc/cp/ * constexpr.c: Remove redundant enum from machine_mode. gcc/fortran/ * trans-types.c, trans-types.h: Remove redundant enum from machine_mode. gcc/go/ * go-lang.c: Remove redundant enum from machine_mode. gcc/java/ * builtins.c, java-tree.h, typeck.c: Remove redundant enum from machine_mode. gcc/lto/ * lto-lang.c: Remove redundant enum from machine_mode. gcc/ * addresses.h, alias.c, asan.c, auto-inc-dec.c, bt-load.c, builtins.c, builtins.h, caller-save.c, calls.c, calls.h, cfgexpand.c, cfgloop.h, cfgrtl.c, combine.c, compare-elim.c, config/aarch64/aarch64-builtins.c, config/aarch64/aarch64-protos.h, config/aarch64/aarch64-simd.md, config/aarch64/aarch64.c, config/aarch64/aarch64.h, config/aarch64/aarch64.md, config/alpha/alpha-protos.h, config/alpha/alpha.c, config/arc/arc-protos.h, config/arc/arc.c, config/arc/arc.h, config/arc/predicates.md, config/arm/aarch-common-protos.h, config/arm/aarch-common.c, config/arm/arm-protos.h, config/arm/arm.c, config/arm/arm.h, config/arm/arm.md, config/arm/neon.md, config/arm/thumb2.md, config/avr/avr-log.c, config/avr/avr-protos.h, config/avr/avr.c, config/avr/avr.md, config/bfin/bfin-protos.h, config/bfin/bfin.c, config/c6x/c6x-protos.h, config/c6x/c6x.c, config/c6x/c6x.md, config/cr16/cr16-protos.h, config/cr16/cr16.c, config/cris/cris-protos.h, config/cris/cris.c, config/cris/cris.md, config/darwin-protos.h, config/darwin.c, config/epiphany/epiphany-protos.h, config/epiphany/epiphany.c, config/epiphany/epiphany.md, config/fr30/fr30.c, config/frv/frv-protos.h, config/frv/frv.c, config/frv/predicates.md, config/h8300/h8300-protos.h, config/h8300/h8300.c, config/i386/i386-builtin-types.awk, config/i386/i386-protos.h, config/i386/i386.c, config/i386/i386.md, config/i386/predicates.md, config/i386/sse.md, config/i386/sync.md, config/ia64/ia64-protos.h, config/ia64/ia64.c, config/iq2000/iq2000-protos.h, config/iq2000/iq2000.c, config/iq2000/iq2000.md, config/lm32/lm32-protos.h, config/lm32/lm32.c, config/m32c/m32c-protos.h, config/m32c/m32c.c, config/m32r/m32r-protos.h, config/m32r/m32r.c, config/m68k/m68k-protos.h, config/m68k/m68k.c, config/mcore/mcore-protos.h, config/mcore/mcore.c, config/mcore/mcore.md, config/mep/mep-protos.h, config/mep/mep.c, config/microblaze/microblaze-protos.h, config/microblaze/microblaze.c, config/mips/mips-protos.h, config/mips/mips.c, config/mmix/mmix-protos.h, config/mmix/mmix.c, config/mn10300/mn10300-protos.h, config/mn10300/mn10300.c, config/moxie/moxie.c, config/msp430/msp430-protos.h, config/msp430/msp430.c, config/nds32/nds32-cost.c, config/nds32/nds32-intrinsic.c, config/nds32/nds32-md-auxiliary.c, config/nds32/nds32-protos.h, config/nds32/nds32.c, config/nios2/nios2-protos.h, config/nios2/nios2.c, config/pa/pa-protos.h, config/pa/pa.c, config/pdp11/pdp11-protos.h, config/pdp11/pdp11.c, config/rl78/rl78-protos.h, config/rl78/rl78.c, config/rs6000/altivec.md, config/rs6000/rs6000-c.c, config/rs6000/rs6000-protos.h, config/rs6000/rs6000.c, config/rs6000/rs6000.h, config/rx/rx-protos.h, config/rx/rx.c, config/s390/predicates.md, config/s390/s390-protos.h, config/s390/s390.c, config/s390/s390.h, config/s390/s390.md, config/sh/predicates.md, config/sh/sh-protos.h, config/sh/sh.c, config/sh/sh.md, config/sparc/predicates.md, config/sparc/sparc-protos.h, config/sparc/sparc.c, config/sparc/sparc.md, config/spu/spu-protos.h, config/spu/spu.c, config/stormy16/stormy16-protos.h, config/stormy16/stormy16.c, config/tilegx/tilegx-protos.h, config/tilegx/tilegx.c, config/tilegx/tilegx.md, config/tilepro/tilepro-protos.h, config/tilepro/tilepro.c, config/v850/v850-protos.h, config/v850/v850.c, config/v850/v850.md, config/vax/vax-protos.h, config/vax/vax.c, config/vms/vms-c.c, config/xtensa/xtensa-protos.h, config/xtensa/xtensa.c, coverage.c, cprop.c, cse.c, cselib.c, cselib.h, dbxout.c, ddg.c, df-problems.c, dfp.c, dfp.h, doc/md.texi, doc/rtl.texi, doc/tm.texi, doc/tm.texi.in, dojump.c, dse.c, dwarf2cfi.c, dwarf2out.c, dwarf2out.h, emit-rtl.c, emit-rtl.h, except.c, explow.c, expmed.c, expmed.h, expr.c, expr.h, final.c, fixed-value.c, fixed-value.h, fold-const.c, function.c, function.h, fwprop.c, gcse.c, gengenrtl.c, genmodes.c, genopinit.c, genoutput.c, genpreds.c, genrecog.c, gensupport.c, gimple-ssa-strength-reduction.c, graphite-clast-to-gimple.c, haifa-sched.c, hooks.c, hooks.h, ifcvt.c, internal-fn.c, ira-build.c, ira-color.c, ira-conflicts.c, ira-costs.c, ira-emit.c, ira-int.h, ira-lives.c, ira.c, ira.h, jump.c, langhooks.h, libfuncs.h, lists.c, loop-doloop.c, loop-invariant.c, loop-iv.c, loop-unroll.c, lower-subreg.c, lower-subreg.h, lra-assigns.c, lra-constraints.c, lra-eliminations.c, lra-int.h, lra-lives.c, lra-spills.c, lra.c, lra.h, machmode.h, omp-low.c, optabs.c, optabs.h, output.h, postreload.c, print-tree.c, read-rtl.c, real.c, real.h, recog.c, recog.h, ree.c, reg-stack.c, regcprop.c, reginfo.c, regrename.c, regs.h, reload.c, reload.h, reload1.c, rtl.c, rtl.h, rtlanal.c, rtlhash.c, rtlhooks-def.h, rtlhooks.c, sched-deps.c, sel-sched-dump.c, sel-sched-ir.c, sel-sched-ir.h, sel-sched.c, simplify-rtx.c, stmt.c, stor-layout.c, stor-layout.h, target.def, targhooks.c, targhooks.h, tree-affine.c, tree-call-cdce.c, tree-complex.c, tree-data-ref.c, tree-dfa.c, tree-if-conv.c, tree-inline.c, tree-outof-ssa.c, tree-scalar-evolution.c, tree-ssa-address.c, tree-ssa-ccp.c, tree-ssa-loop-ivopts.c, tree-ssa-loop-ivopts.h, tree-ssa-loop-manip.c, tree-ssa-loop-prefetch.c, tree-ssa-math-opts.c, tree-ssa-reassoc.c, tree-ssa-sccvn.c, tree-streamer-in.c, tree-switch-conversion.c, tree-vect-data-refs.c, tree-vect-generic.c, tree-vect-loop.c, tree-vect-patterns.c, tree-vect-slp.c, tree-vect-stmts.c, tree-vrp.c, tree.c, tree.h, tsan.c, ubsan.c, valtrack.c, var-tracking.c, varasm.c: Remove redundant enum from machine_mode. gcc/ * gengtype.c (main): Treat machine_mode as a scalar typedef. * genmodes.c (emit_insn_modes_h): Hide inline functions if USED_FOR_TARGET. From-SVN: r216834
2014-10-29 13:02:45 +01:00
machine_mode mode = TYPE_MODE (expr_type);
builtins.def: Change SANITIZE_FLOAT_DIVIDE to SANITIZE_NONDEFAULT. * builtins.def: Change SANITIZE_FLOAT_DIVIDE to SANITIZE_NONDEFAULT. * gcc.c (sanitize_spec_function): Likewise. * convert.c (convert_to_integer): Include "ubsan.h". Add floating-point to integer instrumentation. * doc/invoke.texi: Document -fsanitize=float-cast-overflow. * flag-types.h (enum sanitize_code): Add SANITIZE_FLOAT_CAST and SANITIZE_NONDEFAULT. * opts.c (common_handle_option): Handle -fsanitize=float-cast-overflow. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_FLOAT_CAST_OVERFLOW, BUILT_IN_UBSAN_HANDLE_FLOAT_CAST_OVERFLOW_ABORT): Add. * ubsan.c: Include "realmpfr.h" and "dfp.h". (get_ubsan_type_info_for_type): Handle REAL_TYPEs. (ubsan_type_descriptor): Set tkind to 0xffff for types other than float/double/long double. (ubsan_instrument_float_cast): New function. * ubsan.h (ubsan_instrument_float_cast): Declare. testsuite/ * c-c++-common/ubsan/float-cast-overflow-1.c: New test. * c-c++-common/ubsan/float-cast-overflow-10.c: New test. * c-c++-common/ubsan/float-cast-overflow-2.c: New test. * c-c++-common/ubsan/float-cast-overflow-3.c: New test. * c-c++-common/ubsan/float-cast-overflow-4.c: New test. * c-c++-common/ubsan/float-cast-overflow-5.c: New test. * c-c++-common/ubsan/float-cast-overflow-6.c: New test. * c-c++-common/ubsan/float-cast-overflow-7.c: New test. * c-c++-common/ubsan/float-cast-overflow-7.h: New file. * c-c++-common/ubsan/float-cast-overflow-8.c: New test. * c-c++-common/ubsan/float-cast-overflow-9.c: New test. * c-c++-common/ubsan/float-cast.h: New file. * g++.dg/ubsan/float-cast-overflow-bf.C: New test. * gcc.dg/ubsan/float-cast-overflow-bf.c: New test. libsanitizer/ * ubsan/ubsan_value.cc (getFloatValue): Handle 96-bit floating-point types. Co-Authored-By: Jakub Jelinek <jakub@redhat.com> From-SVN: r210862
2014-05-23 16:44:42 +02:00
int prec = TYPE_PRECISION (type);
bool uns_p = TYPE_UNSIGNED (type);
if (loc == UNKNOWN_LOCATION)
loc = input_location;
builtins.def: Change SANITIZE_FLOAT_DIVIDE to SANITIZE_NONDEFAULT. * builtins.def: Change SANITIZE_FLOAT_DIVIDE to SANITIZE_NONDEFAULT. * gcc.c (sanitize_spec_function): Likewise. * convert.c (convert_to_integer): Include "ubsan.h". Add floating-point to integer instrumentation. * doc/invoke.texi: Document -fsanitize=float-cast-overflow. * flag-types.h (enum sanitize_code): Add SANITIZE_FLOAT_CAST and SANITIZE_NONDEFAULT. * opts.c (common_handle_option): Handle -fsanitize=float-cast-overflow. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_FLOAT_CAST_OVERFLOW, BUILT_IN_UBSAN_HANDLE_FLOAT_CAST_OVERFLOW_ABORT): Add. * ubsan.c: Include "realmpfr.h" and "dfp.h". (get_ubsan_type_info_for_type): Handle REAL_TYPEs. (ubsan_type_descriptor): Set tkind to 0xffff for types other than float/double/long double. (ubsan_instrument_float_cast): New function. * ubsan.h (ubsan_instrument_float_cast): Declare. testsuite/ * c-c++-common/ubsan/float-cast-overflow-1.c: New test. * c-c++-common/ubsan/float-cast-overflow-10.c: New test. * c-c++-common/ubsan/float-cast-overflow-2.c: New test. * c-c++-common/ubsan/float-cast-overflow-3.c: New test. * c-c++-common/ubsan/float-cast-overflow-4.c: New test. * c-c++-common/ubsan/float-cast-overflow-5.c: New test. * c-c++-common/ubsan/float-cast-overflow-6.c: New test. * c-c++-common/ubsan/float-cast-overflow-7.c: New test. * c-c++-common/ubsan/float-cast-overflow-7.h: New file. * c-c++-common/ubsan/float-cast-overflow-8.c: New test. * c-c++-common/ubsan/float-cast-overflow-9.c: New test. * c-c++-common/ubsan/float-cast.h: New file. * g++.dg/ubsan/float-cast-overflow-bf.C: New test. * gcc.dg/ubsan/float-cast-overflow-bf.c: New test. libsanitizer/ * ubsan/ubsan_value.cc (getFloatValue): Handle 96-bit floating-point types. Co-Authored-By: Jakub Jelinek <jakub@redhat.com> From-SVN: r210862
2014-05-23 16:44:42 +02:00
/* Float to integer conversion first truncates toward zero, so
even signed char c = 127.875f; is not problematic.
Therefore, we should complain only if EXPR is unordered or smaller
or equal than TYPE_MIN_VALUE - 1.0 or greater or equal than
TYPE_MAX_VALUE + 1.0. */
if (REAL_MODE_FORMAT (mode)->b == 2)
{
/* For maximum, TYPE_MAX_VALUE might not be representable
in EXPR_TYPE, e.g. if TYPE is 64-bit long long and
EXPR_TYPE is IEEE single float, but TYPE_MAX_VALUE + 1.0 is
either representable or infinity. */
REAL_VALUE_TYPE maxval = dconst1;
SET_REAL_EXP (&maxval, REAL_EXP (&maxval) + prec - !uns_p);
real_convert (&maxval, mode, &maxval);
max = build_real (expr_type, maxval);
/* For unsigned, assume -1.0 is always representable. */
if (uns_p)
min = build_minus_one_cst (expr_type);
else
{
/* TYPE_MIN_VALUE is generally representable (or -inf),
but TYPE_MIN_VALUE - 1.0 might not be. */
REAL_VALUE_TYPE minval = dconstm1, minval2;
SET_REAL_EXP (&minval, REAL_EXP (&minval) + prec - 1);
real_convert (&minval, mode, &minval);
real_arithmetic (&minval2, MINUS_EXPR, &minval, &dconst1);
real_convert (&minval2, mode, &minval2);
if (real_compare (EQ_EXPR, &minval, &minval2)
&& !real_isinf (&minval))
{
/* If TYPE_MIN_VALUE - 1.0 is not representable and
rounds to TYPE_MIN_VALUE, we need to subtract
more. As REAL_MODE_FORMAT (mode)->p is the number
of base digits, we want to subtract a number that
will be 1 << (REAL_MODE_FORMAT (mode)->p - 1)
times smaller than minval. */
minval2 = dconst1;
gcc_assert (prec > REAL_MODE_FORMAT (mode)->p);
SET_REAL_EXP (&minval2,
REAL_EXP (&minval2) + prec - 1
- REAL_MODE_FORMAT (mode)->p + 1);
real_arithmetic (&minval2, MINUS_EXPR, &minval, &minval2);
real_convert (&minval2, mode, &minval2);
}
min = build_real (expr_type, minval2);
}
}
else if (REAL_MODE_FORMAT (mode)->b == 10)
{
/* For _Decimal128 up to 34 decimal digits, - sign,
dot, e, exponent. */
char buf[64];
mpfr_t m;
int p = REAL_MODE_FORMAT (mode)->p;
REAL_VALUE_TYPE maxval, minval;
/* Use mpfr_snprintf rounding to compute the smallest
representable decimal number greater or equal than
1 << (prec - !uns_p). */
mpfr_init2 (m, prec + 2);
mpfr_set_ui_2exp (m, 1, prec - !uns_p, GMP_RNDN);
mpfr_snprintf (buf, sizeof buf, "%.*RUe", p - 1, m);
decimal_real_from_string (&maxval, buf);
max = build_real (expr_type, maxval);
/* For unsigned, assume -1.0 is always representable. */
if (uns_p)
min = build_minus_one_cst (expr_type);
else
{
/* Use mpfr_snprintf rounding to compute the largest
representable decimal number less or equal than
(-1 << (prec - 1)) - 1. */
mpfr_set_si_2exp (m, -1, prec - 1, GMP_RNDN);
mpfr_sub_ui (m, m, 1, GMP_RNDN);
mpfr_snprintf (buf, sizeof buf, "%.*RDe", p - 1, m);
decimal_real_from_string (&minval, buf);
min = build_real (expr_type, minval);
}
mpfr_clear (m);
}
else
return NULL_TREE;
t = fold_build2 (UNLE_EXPR, boolean_type_node, expr, min);
tt = fold_build2 (UNGE_EXPR, boolean_type_node, expr, max);
t = fold_build2 (TRUTH_OR_EXPR, boolean_type_node, t, tt);
if (integer_zerop (t))
return NULL_TREE;
builtins.def: Change SANITIZE_FLOAT_DIVIDE to SANITIZE_NONDEFAULT. * builtins.def: Change SANITIZE_FLOAT_DIVIDE to SANITIZE_NONDEFAULT. * gcc.c (sanitize_spec_function): Likewise. * convert.c (convert_to_integer): Include "ubsan.h". Add floating-point to integer instrumentation. * doc/invoke.texi: Document -fsanitize=float-cast-overflow. * flag-types.h (enum sanitize_code): Add SANITIZE_FLOAT_CAST and SANITIZE_NONDEFAULT. * opts.c (common_handle_option): Handle -fsanitize=float-cast-overflow. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_FLOAT_CAST_OVERFLOW, BUILT_IN_UBSAN_HANDLE_FLOAT_CAST_OVERFLOW_ABORT): Add. * ubsan.c: Include "realmpfr.h" and "dfp.h". (get_ubsan_type_info_for_type): Handle REAL_TYPEs. (ubsan_type_descriptor): Set tkind to 0xffff for types other than float/double/long double. (ubsan_instrument_float_cast): New function. * ubsan.h (ubsan_instrument_float_cast): Declare. testsuite/ * c-c++-common/ubsan/float-cast-overflow-1.c: New test. * c-c++-common/ubsan/float-cast-overflow-10.c: New test. * c-c++-common/ubsan/float-cast-overflow-2.c: New test. * c-c++-common/ubsan/float-cast-overflow-3.c: New test. * c-c++-common/ubsan/float-cast-overflow-4.c: New test. * c-c++-common/ubsan/float-cast-overflow-5.c: New test. * c-c++-common/ubsan/float-cast-overflow-6.c: New test. * c-c++-common/ubsan/float-cast-overflow-7.c: New test. * c-c++-common/ubsan/float-cast-overflow-7.h: New file. * c-c++-common/ubsan/float-cast-overflow-8.c: New test. * c-c++-common/ubsan/float-cast-overflow-9.c: New test. * c-c++-common/ubsan/float-cast.h: New file. * g++.dg/ubsan/float-cast-overflow-bf.C: New test. * gcc.dg/ubsan/float-cast-overflow-bf.c: New test. libsanitizer/ * ubsan/ubsan_value.cc (getFloatValue): Handle 96-bit floating-point types. Co-Authored-By: Jakub Jelinek <jakub@redhat.com> From-SVN: r210862
2014-05-23 16:44:42 +02:00
if (flag_sanitize_undefined_trap_on_error)
fn = build_call_expr_loc (loc, builtin_decl_explicit (BUILT_IN_TRAP), 0);
else
{
location_t *loc_ptr = NULL;
unsigned num_locations = 0;
/* Figure out if we can propagate location to ubsan_data and use new
style handlers in libubsan. */
if (ubsan_use_new_style_p (loc))
{
loc_ptr = &loc;
num_locations = 1;
}
builtins.def: Change SANITIZE_FLOAT_DIVIDE to SANITIZE_NONDEFAULT. * builtins.def: Change SANITIZE_FLOAT_DIVIDE to SANITIZE_NONDEFAULT. * gcc.c (sanitize_spec_function): Likewise. * convert.c (convert_to_integer): Include "ubsan.h". Add floating-point to integer instrumentation. * doc/invoke.texi: Document -fsanitize=float-cast-overflow. * flag-types.h (enum sanitize_code): Add SANITIZE_FLOAT_CAST and SANITIZE_NONDEFAULT. * opts.c (common_handle_option): Handle -fsanitize=float-cast-overflow. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_FLOAT_CAST_OVERFLOW, BUILT_IN_UBSAN_HANDLE_FLOAT_CAST_OVERFLOW_ABORT): Add. * ubsan.c: Include "realmpfr.h" and "dfp.h". (get_ubsan_type_info_for_type): Handle REAL_TYPEs. (ubsan_type_descriptor): Set tkind to 0xffff for types other than float/double/long double. (ubsan_instrument_float_cast): New function. * ubsan.h (ubsan_instrument_float_cast): Declare. testsuite/ * c-c++-common/ubsan/float-cast-overflow-1.c: New test. * c-c++-common/ubsan/float-cast-overflow-10.c: New test. * c-c++-common/ubsan/float-cast-overflow-2.c: New test. * c-c++-common/ubsan/float-cast-overflow-3.c: New test. * c-c++-common/ubsan/float-cast-overflow-4.c: New test. * c-c++-common/ubsan/float-cast-overflow-5.c: New test. * c-c++-common/ubsan/float-cast-overflow-6.c: New test. * c-c++-common/ubsan/float-cast-overflow-7.c: New test. * c-c++-common/ubsan/float-cast-overflow-7.h: New file. * c-c++-common/ubsan/float-cast-overflow-8.c: New test. * c-c++-common/ubsan/float-cast-overflow-9.c: New test. * c-c++-common/ubsan/float-cast.h: New file. * g++.dg/ubsan/float-cast-overflow-bf.C: New test. * gcc.dg/ubsan/float-cast-overflow-bf.c: New test. libsanitizer/ * ubsan/ubsan_value.cc (getFloatValue): Handle 96-bit floating-point types. Co-Authored-By: Jakub Jelinek <jakub@redhat.com> From-SVN: r210862
2014-05-23 16:44:42 +02:00
/* Create the __ubsan_handle_float_cast_overflow fn call. */
tree data = ubsan_create_data ("__ubsan_float_cast_overflow_data",
num_locations, loc_ptr,
ubsan_type_descriptor (expr_type),
ubsan_type_descriptor (type), NULL_TREE,
NULL_TREE);
builtins.def: Change SANITIZE_FLOAT_DIVIDE to SANITIZE_NONDEFAULT. * builtins.def: Change SANITIZE_FLOAT_DIVIDE to SANITIZE_NONDEFAULT. * gcc.c (sanitize_spec_function): Likewise. * convert.c (convert_to_integer): Include "ubsan.h". Add floating-point to integer instrumentation. * doc/invoke.texi: Document -fsanitize=float-cast-overflow. * flag-types.h (enum sanitize_code): Add SANITIZE_FLOAT_CAST and SANITIZE_NONDEFAULT. * opts.c (common_handle_option): Handle -fsanitize=float-cast-overflow. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_FLOAT_CAST_OVERFLOW, BUILT_IN_UBSAN_HANDLE_FLOAT_CAST_OVERFLOW_ABORT): Add. * ubsan.c: Include "realmpfr.h" and "dfp.h". (get_ubsan_type_info_for_type): Handle REAL_TYPEs. (ubsan_type_descriptor): Set tkind to 0xffff for types other than float/double/long double. (ubsan_instrument_float_cast): New function. * ubsan.h (ubsan_instrument_float_cast): Declare. testsuite/ * c-c++-common/ubsan/float-cast-overflow-1.c: New test. * c-c++-common/ubsan/float-cast-overflow-10.c: New test. * c-c++-common/ubsan/float-cast-overflow-2.c: New test. * c-c++-common/ubsan/float-cast-overflow-3.c: New test. * c-c++-common/ubsan/float-cast-overflow-4.c: New test. * c-c++-common/ubsan/float-cast-overflow-5.c: New test. * c-c++-common/ubsan/float-cast-overflow-6.c: New test. * c-c++-common/ubsan/float-cast-overflow-7.c: New test. * c-c++-common/ubsan/float-cast-overflow-7.h: New file. * c-c++-common/ubsan/float-cast-overflow-8.c: New test. * c-c++-common/ubsan/float-cast-overflow-9.c: New test. * c-c++-common/ubsan/float-cast.h: New file. * g++.dg/ubsan/float-cast-overflow-bf.C: New test. * gcc.dg/ubsan/float-cast-overflow-bf.c: New test. libsanitizer/ * ubsan/ubsan_value.cc (getFloatValue): Handle 96-bit floating-point types. Co-Authored-By: Jakub Jelinek <jakub@redhat.com> From-SVN: r210862
2014-05-23 16:44:42 +02:00
enum built_in_function bcode
New syntax for -fsanitize-recover. 2014-10-22 Jakub Jelinek <jakub@redhat.com> Yury Gribov <y.gribov@samsung.com> gcc/ * common.opt (flag_sanitize_recover): New variable. (fsanitize-recover): Remove Var/Init, deprecate. (fsanitize-recover=): New option. * doc/invoke.texi (fsanitize-recover): Update docs. * opts.c (finish_options): Use opts->x_flag_sanitize instead of flag_sanitize. Prohibit -fsanitize-recover for anything besides UBSan. Formatting. (common_handle_option): Handle OPT_fsanitize_recover_ and OPT_fsanitize_recover. Use opts->x_flag_sanitize instead of flag_sanitize. * asan.c (pass_sanopt::execute): Fix up formatting. * ubsan.c (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn, ubsan_expand_objsize_ifn, ubsan_build_overflow_builtin, instrument_bool_enum_load, ubsan_instrument_float_cast, instrument_nonnull_arg, instrument_nonnull_return): Check bits in flag_sanitize_recover bitmask instead of flag_sanitize_recover as bool flag. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division, ubsan_instrument_shift, ubsan_instrument_vla): Check bits in flag_sanitize_recover bitmask instead of flag_sanitize_recover as bool flag. gcc/testsuite/ * c-c++-common/ubsan/align-1.c: Update cmdline options. * c-c++-common/ubsan/align-3.c: Likewise. * c-c++-common/ubsan/bounds-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-7.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-10.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-7.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-8.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-9.c: Likewise. * c-c++-common/ubsan/nonnull-2.c: Likewise. * c-c++-common/ubsan/nonnull-3.c: Likewise. * c-c++-common/ubsan/object-size-3.c: Likewise. * c-c++-common/ubsan/overflow-1.c: Likewise. * c-c++-common/ubsan/overflow-add-1.c: Likewise. * c-c++-common/ubsan/overflow-add-3.c: Likewise. * c-c++-common/ubsan/overflow-mul-1.c: Likewise. * c-c++-common/ubsan/overflow-mul-3.c: Likewise. * c-c++-common/ubsan/overflow-negate-2.c: Likewise. * c-c++-common/ubsan/overflow-sub-1.c: Likewise. * c-c++-common/ubsan/pr59503.c: Likewise. * c-c++-common/ubsan/pr60613-1.c: Likewise. * c-c++-common/ubsan/save-expr-1.c: Likewise. * c-c++-common/ubsan/shift-3.c: Likewise. * c-c++-common/ubsan/shift-6.c: Likewise. * c-c++-common/ubsan/undefined-1.c: Likewise. * c-c++-common/ubsan/vla-2.c: Likewise. * c-c++-common/ubsan/vla-3.c: Likewise. * c-c++-common/ubsan/vla-4.c: Likewise. * g++.dg/ubsan/cxx11-shift-1.C: Likewise. * g++.dg/ubsan/return-2.C: Likewise. * c-c++-common/ubsan/recovery-1.c: New test. * c-c++-common/ubsan/recovery-2.c: New test. * c-c++-common/ubsan/recovery-3.c: New test. * c-c++-common/ubsan/recovery-common.inc: New file. Co-Authored-By: Yury Gribov <y.gribov@samsung.com> From-SVN: r216552
2014-10-22 13:07:10 +02:00
= (flag_sanitize_recover & SANITIZE_FLOAT_CAST)
builtins.def: Change SANITIZE_FLOAT_DIVIDE to SANITIZE_NONDEFAULT. * builtins.def: Change SANITIZE_FLOAT_DIVIDE to SANITIZE_NONDEFAULT. * gcc.c (sanitize_spec_function): Likewise. * convert.c (convert_to_integer): Include "ubsan.h". Add floating-point to integer instrumentation. * doc/invoke.texi: Document -fsanitize=float-cast-overflow. * flag-types.h (enum sanitize_code): Add SANITIZE_FLOAT_CAST and SANITIZE_NONDEFAULT. * opts.c (common_handle_option): Handle -fsanitize=float-cast-overflow. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_FLOAT_CAST_OVERFLOW, BUILT_IN_UBSAN_HANDLE_FLOAT_CAST_OVERFLOW_ABORT): Add. * ubsan.c: Include "realmpfr.h" and "dfp.h". (get_ubsan_type_info_for_type): Handle REAL_TYPEs. (ubsan_type_descriptor): Set tkind to 0xffff for types other than float/double/long double. (ubsan_instrument_float_cast): New function. * ubsan.h (ubsan_instrument_float_cast): Declare. testsuite/ * c-c++-common/ubsan/float-cast-overflow-1.c: New test. * c-c++-common/ubsan/float-cast-overflow-10.c: New test. * c-c++-common/ubsan/float-cast-overflow-2.c: New test. * c-c++-common/ubsan/float-cast-overflow-3.c: New test. * c-c++-common/ubsan/float-cast-overflow-4.c: New test. * c-c++-common/ubsan/float-cast-overflow-5.c: New test. * c-c++-common/ubsan/float-cast-overflow-6.c: New test. * c-c++-common/ubsan/float-cast-overflow-7.c: New test. * c-c++-common/ubsan/float-cast-overflow-7.h: New file. * c-c++-common/ubsan/float-cast-overflow-8.c: New test. * c-c++-common/ubsan/float-cast-overflow-9.c: New test. * c-c++-common/ubsan/float-cast.h: New file. * g++.dg/ubsan/float-cast-overflow-bf.C: New test. * gcc.dg/ubsan/float-cast-overflow-bf.c: New test. libsanitizer/ * ubsan/ubsan_value.cc (getFloatValue): Handle 96-bit floating-point types. Co-Authored-By: Jakub Jelinek <jakub@redhat.com> From-SVN: r210862
2014-05-23 16:44:42 +02:00
? BUILT_IN_UBSAN_HANDLE_FLOAT_CAST_OVERFLOW
: BUILT_IN_UBSAN_HANDLE_FLOAT_CAST_OVERFLOW_ABORT;
fn = builtin_decl_explicit (bcode);
fn = build_call_expr_loc (loc, fn, 2,
build_fold_addr_expr_loc (loc, data),
ubsan_encode_value (expr));
builtins.def: Change SANITIZE_FLOAT_DIVIDE to SANITIZE_NONDEFAULT. * builtins.def: Change SANITIZE_FLOAT_DIVIDE to SANITIZE_NONDEFAULT. * gcc.c (sanitize_spec_function): Likewise. * convert.c (convert_to_integer): Include "ubsan.h". Add floating-point to integer instrumentation. * doc/invoke.texi: Document -fsanitize=float-cast-overflow. * flag-types.h (enum sanitize_code): Add SANITIZE_FLOAT_CAST and SANITIZE_NONDEFAULT. * opts.c (common_handle_option): Handle -fsanitize=float-cast-overflow. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_FLOAT_CAST_OVERFLOW, BUILT_IN_UBSAN_HANDLE_FLOAT_CAST_OVERFLOW_ABORT): Add. * ubsan.c: Include "realmpfr.h" and "dfp.h". (get_ubsan_type_info_for_type): Handle REAL_TYPEs. (ubsan_type_descriptor): Set tkind to 0xffff for types other than float/double/long double. (ubsan_instrument_float_cast): New function. * ubsan.h (ubsan_instrument_float_cast): Declare. testsuite/ * c-c++-common/ubsan/float-cast-overflow-1.c: New test. * c-c++-common/ubsan/float-cast-overflow-10.c: New test. * c-c++-common/ubsan/float-cast-overflow-2.c: New test. * c-c++-common/ubsan/float-cast-overflow-3.c: New test. * c-c++-common/ubsan/float-cast-overflow-4.c: New test. * c-c++-common/ubsan/float-cast-overflow-5.c: New test. * c-c++-common/ubsan/float-cast-overflow-6.c: New test. * c-c++-common/ubsan/float-cast-overflow-7.c: New test. * c-c++-common/ubsan/float-cast-overflow-7.h: New file. * c-c++-common/ubsan/float-cast-overflow-8.c: New test. * c-c++-common/ubsan/float-cast-overflow-9.c: New test. * c-c++-common/ubsan/float-cast.h: New file. * g++.dg/ubsan/float-cast-overflow-bf.C: New test. * gcc.dg/ubsan/float-cast-overflow-bf.c: New test. libsanitizer/ * ubsan/ubsan_value.cc (getFloatValue): Handle 96-bit floating-point types. Co-Authored-By: Jakub Jelinek <jakub@redhat.com> From-SVN: r210862
2014-05-23 16:44:42 +02:00
}
return fold_build3 (COND_EXPR, void_type_node, t, fn, integer_zero_node);
builtins.def: Change SANITIZE_FLOAT_DIVIDE to SANITIZE_NONDEFAULT. * builtins.def: Change SANITIZE_FLOAT_DIVIDE to SANITIZE_NONDEFAULT. * gcc.c (sanitize_spec_function): Likewise. * convert.c (convert_to_integer): Include "ubsan.h". Add floating-point to integer instrumentation. * doc/invoke.texi: Document -fsanitize=float-cast-overflow. * flag-types.h (enum sanitize_code): Add SANITIZE_FLOAT_CAST and SANITIZE_NONDEFAULT. * opts.c (common_handle_option): Handle -fsanitize=float-cast-overflow. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_FLOAT_CAST_OVERFLOW, BUILT_IN_UBSAN_HANDLE_FLOAT_CAST_OVERFLOW_ABORT): Add. * ubsan.c: Include "realmpfr.h" and "dfp.h". (get_ubsan_type_info_for_type): Handle REAL_TYPEs. (ubsan_type_descriptor): Set tkind to 0xffff for types other than float/double/long double. (ubsan_instrument_float_cast): New function. * ubsan.h (ubsan_instrument_float_cast): Declare. testsuite/ * c-c++-common/ubsan/float-cast-overflow-1.c: New test. * c-c++-common/ubsan/float-cast-overflow-10.c: New test. * c-c++-common/ubsan/float-cast-overflow-2.c: New test. * c-c++-common/ubsan/float-cast-overflow-3.c: New test. * c-c++-common/ubsan/float-cast-overflow-4.c: New test. * c-c++-common/ubsan/float-cast-overflow-5.c: New test. * c-c++-common/ubsan/float-cast-overflow-6.c: New test. * c-c++-common/ubsan/float-cast-overflow-7.c: New test. * c-c++-common/ubsan/float-cast-overflow-7.h: New file. * c-c++-common/ubsan/float-cast-overflow-8.c: New test. * c-c++-common/ubsan/float-cast-overflow-9.c: New test. * c-c++-common/ubsan/float-cast.h: New file. * g++.dg/ubsan/float-cast-overflow-bf.C: New test. * gcc.dg/ubsan/float-cast-overflow-bf.c: New test. libsanitizer/ * ubsan/ubsan_value.cc (getFloatValue): Handle 96-bit floating-point types. Co-Authored-By: Jakub Jelinek <jakub@redhat.com> From-SVN: r210862
2014-05-23 16:44:42 +02:00
}
/* Instrument values passed to function arguments with nonnull attribute. */
static void
instrument_nonnull_arg (gimple_stmt_iterator *gsi)
{
gimple *stmt = gsi_stmt (*gsi);
location_t loc[2];
/* infer_nonnull_range needs flag_delete_null_pointer_checks set,
while for nonnull sanitization it is clear. */
int save_flag_delete_null_pointer_checks = flag_delete_null_pointer_checks;
flag_delete_null_pointer_checks = 1;
loc[0] = gimple_location (stmt);
loc[1] = UNKNOWN_LOCATION;
for (unsigned int i = 0; i < gimple_call_num_args (stmt); i++)
{
tree arg = gimple_call_arg (stmt, i);
if (POINTER_TYPE_P (TREE_TYPE (arg))
&& infer_nonnull_range_by_attribute (stmt, arg))
{
gimple *g;
if (!is_gimple_val (arg))
{
gimple-expr.h (create_tmp_var_raw, [...]): Add default NULL value to last argument. * gimple-expr.h (create_tmp_var_raw, create_tmp_var, create_tmp_reg): Add default NULL value to last argument. * tree-ssanames.h (make_ssa_name, copy_ssa_name): Likewise. * gimple-low.c (lower_builtin_posix_memalign): Remove NULL last argument from create_tmp_var_raw, create_tmp_var, create_tmp_reg, make_ssa_name and copy_ssa_name calls. * tree-ssa-strlen.c (get_string_length): Likewise. * tree-emutls.c (gen_emutls_addr, lower_emutls_1): Likewise. * tree-ssa-phiprop.c (phiprop_insert_phi): Likewise. * tree-vect-slp.c (vect_get_constant_vectors): Likewise. * ipa-prop.c (ipa_modify_call_arguments): Likewise. * tree-ssa-forwprop.c (simplify_rotate): Likewise. * tree-ssa-ccp.c (fold_builtin_alloca_with_align): Likewise. * asan.c (build_shadow_mem_access, maybe_create_ssa_name, maybe_cast_to_ptrmode, asan_expand_check_ifn): Likewise. * tsan.c (instrument_expr, instrument_builtin_call, instrument_func_entry): Likewise. * varpool.c (add_new_static_var): Likewise. * tree-loop-distribution.c (generate_memset_builtin): Likewise. * gimplify.c (internal_get_tmp_var, gimplify_return_expr, gimplify_modify_expr_to_memcpy, gimplify_modify_expr_to_memset, gimplify_init_ctor_eval_range, gimplify_init_constructor, gimplify_omp_atomic, gimplify_expr): Likewise. * gimple-builder.c (build_assign, build_type_cast): Likewise. * tree-vect-loop-manip.c (slpeel_update_phi_nodes_for_guard1, slpeel_update_phi_nodes_for_guard2, slpeel_tree_peel_loop_to_edge, vect_loop_versioning): Likewise. * tree-if-conv.c (version_loop_for_if_conversion): Likewise. * gimple-match-head.c (maybe_push_res_to_seq): Likewise. * tree-vect-patterns.c (vect_handle_widen_op_by_const, vect_recog_widen_mult_pattern, vect_operation_fits_smaller_type, vect_recog_over_widening_pattern): Likewise. * tree-sra.c (build_ref_for_offset, create_access_replacement): Likewise. * tree-cfg.c (make_blocks): Likewise. * tree-eh.c (lower_eh_constructs_2, lower_resx, lower_eh_dispatch): Likewise. * tree-ssa-propagate.c (update_call_from_tree): Likewise. * tree-complex.c (get_component_ssa_name, expand_complex_div_wide): Likewise. * tree-ssa-math-opts.c (build_and_insert_cast): Likewise. * tree-tailcall.c (update_accumulator_with_ops): Likewise. * tree-predcom.c (initialize_root_vars, initialize_root_vars_lm, execute_load_motion, reassociate_to_the_same_stmt): Likewise. * tree-ssa-reassoc.c (build_and_add_sum, optimize_range_tests_to_bit_test, update_ops, maybe_optimize_range_tests, rewrite_expr_tree, linearize_expr, negate_value, repropagate_negates): Likewise. * tree-vect-loop.c (vect_is_simple_reduction_1, vect_create_epilog_for_reduction): Likewise. * ipa-split.c (split_function): Likewise. * tree-inline.c (remap_ssa_name, setup_one_parameter, declare_return_variable, tree_function_versioning): Likewise. * tree-cfgcleanup.c (fixup_noreturn_call): Likewise. * cfgexpand.c (update_alias_info_with_stack_vars, expand_used_vars): Likewise. * tree-ssa-phiopt.c (conditional_replacement, abs_replacement, neg_replacement): Likewise. * gimplify-me.c (force_gimple_operand_1, gimple_regimplify_operands): Likewise. * tree-vrp.c (simplify_truth_ops_using_ranges, simplify_float_conversion_using_ranges, simplify_internal_call_using_ranges): Likewise. * tree-switch-conversion.c (emit_case_bit_tests, build_one_array, build_arrays, gen_def_assigns): Likewise. * gimple-fold.c (gimple_fold_builtin_memory_op, gimple_fold_builtin_strcat, gimple_fold_call, gimple_build): Likewise. * tree-vect-generic.c (expand_vector_divmod, optimize_vector_constructor): Likewise. * ubsan.c (ubsan_encode_value, ubsan_expand_null_ifn, ubsan_expand_objsize_ifn, instrument_si_overflow, instrument_bool_enum_load, instrument_nonnull_arg): Likewise. * tree-outof-ssa.c (insert_backedge_copies): Likewise. * tree-ssa-loop-manip.c (create_iv, tree_transform_and_unroll_loop): Likewise. * omp-low.c (scan_omp_parallel, lower_rec_simd_input_clauses, lower_rec_input_clauses, lower_lastprivate_clauses, expand_parallel_call, expand_omp_for_static_chunk, expand_omp_atomic_pipeline, expand_omp_target, maybe_add_implicit_barrier_cancel, lower_omp_single_simple, lower_omp_critical, lower_omp_for, task_copyfn_copy_decl, lower_depend_clauses, lower_omp_target, lower_omp_1, ipa_simd_modify_stmt_ops, simd_clone_adjust): Likewise. * tree-parloops.c (take_address_of, create_phi_for_local_result, create_call_for_reduction_1, separate_decls_in_region, create_parallel_loop): Likewise. * graphite-sese-to-poly.c (rewrite_cross_bb_scalar_dependence, handle_scalar_deps_crossing_scop_limits): Likewise. * trans-mem.c (lower_transaction, build_tm_load, build_tm_store, expand_assign_tm, expand_call_tm, expand_transaction, ipa_tm_insert_gettmclone_call): Likewise. * tree-vect-data-refs.c (bump_vector_ptr, vect_setup_realignment): Likewise. * tree-vect-stmts.c (vect_init_vector, vectorizable_mask_load_store, vectorizable_call, vectorizable_simd_clone_call, vectorizable_conversion, vectorizable_store, permute_vec_elements, vectorizable_load): Likewise. c/ * c-typeck.c (convert_lvalue_to_rvalue, build_atomic_assign, c_finish_stmt_expr): Remove NULL last argument from create_tmp_var_raw and create_tmp_var calls. * c-array-notation.c (fix_builtin_array_notation_fn, build_array_notation_expr, fix_conditional_array_notations_1, fix_array_notation_expr, fix_array_notation_call_expr): Likewise. cp/ * cp-gimplify.c (cxx_omp_clause_apply_fn): Remove NULL last argument from create_tmp_var calls. c-family/ * c-common.c (convert_vector_to_pointer_for_subscript): Remove NULL last argument from create_tmp_var_raw and create_tmp_var calls. * cilk.c (gimplify_cilk_spawn): Likewise. * c-omp.c (c_finish_omp_atomic): Likewise. fortran/ * trans-openmp.c (gfc_omp_finish_clause, gfc_trans_omp_array_reduction_or_udr, gfc_trans_omp_atomic): Remove NULL last argument from create_tmp_var_raw and create_tmp_var calls. From-SVN: r218181
2014-11-29 12:35:30 +01:00
g = gimple_build_assign (make_ssa_name (TREE_TYPE (arg)), arg);
gimple_set_location (g, loc[0]);
gsi_insert_before (gsi, g, GSI_SAME_STMT);
arg = gimple_assign_lhs (g);
}
basic_block then_bb, fallthru_bb;
*gsi = create_cond_insert_point (gsi, true, false, true,
&then_bb, &fallthru_bb);
g = gimple_build_cond (EQ_EXPR, arg,
build_zero_cst (TREE_TYPE (arg)),
NULL_TREE, NULL_TREE);
gimple_set_location (g, loc[0]);
gsi_insert_after (gsi, g, GSI_NEW_STMT);
*gsi = gsi_after_labels (then_bb);
if (flag_sanitize_undefined_trap_on_error)
g = gimple_build_call (builtin_decl_explicit (BUILT_IN_TRAP), 0);
else
{
tree data = ubsan_create_data ("__ubsan_nonnull_arg_data",
2, loc, NULL_TREE,
build_int_cst (integer_type_node,
i + 1),
NULL_TREE);
data = build_fold_addr_expr_loc (loc[0], data);
enum built_in_function bcode
New syntax for -fsanitize-recover. 2014-10-22 Jakub Jelinek <jakub@redhat.com> Yury Gribov <y.gribov@samsung.com> gcc/ * common.opt (flag_sanitize_recover): New variable. (fsanitize-recover): Remove Var/Init, deprecate. (fsanitize-recover=): New option. * doc/invoke.texi (fsanitize-recover): Update docs. * opts.c (finish_options): Use opts->x_flag_sanitize instead of flag_sanitize. Prohibit -fsanitize-recover for anything besides UBSan. Formatting. (common_handle_option): Handle OPT_fsanitize_recover_ and OPT_fsanitize_recover. Use opts->x_flag_sanitize instead of flag_sanitize. * asan.c (pass_sanopt::execute): Fix up formatting. * ubsan.c (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn, ubsan_expand_objsize_ifn, ubsan_build_overflow_builtin, instrument_bool_enum_load, ubsan_instrument_float_cast, instrument_nonnull_arg, instrument_nonnull_return): Check bits in flag_sanitize_recover bitmask instead of flag_sanitize_recover as bool flag. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division, ubsan_instrument_shift, ubsan_instrument_vla): Check bits in flag_sanitize_recover bitmask instead of flag_sanitize_recover as bool flag. gcc/testsuite/ * c-c++-common/ubsan/align-1.c: Update cmdline options. * c-c++-common/ubsan/align-3.c: Likewise. * c-c++-common/ubsan/bounds-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-7.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-10.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-7.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-8.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-9.c: Likewise. * c-c++-common/ubsan/nonnull-2.c: Likewise. * c-c++-common/ubsan/nonnull-3.c: Likewise. * c-c++-common/ubsan/object-size-3.c: Likewise. * c-c++-common/ubsan/overflow-1.c: Likewise. * c-c++-common/ubsan/overflow-add-1.c: Likewise. * c-c++-common/ubsan/overflow-add-3.c: Likewise. * c-c++-common/ubsan/overflow-mul-1.c: Likewise. * c-c++-common/ubsan/overflow-mul-3.c: Likewise. * c-c++-common/ubsan/overflow-negate-2.c: Likewise. * c-c++-common/ubsan/overflow-sub-1.c: Likewise. * c-c++-common/ubsan/pr59503.c: Likewise. * c-c++-common/ubsan/pr60613-1.c: Likewise. * c-c++-common/ubsan/save-expr-1.c: Likewise. * c-c++-common/ubsan/shift-3.c: Likewise. * c-c++-common/ubsan/shift-6.c: Likewise. * c-c++-common/ubsan/undefined-1.c: Likewise. * c-c++-common/ubsan/vla-2.c: Likewise. * c-c++-common/ubsan/vla-3.c: Likewise. * c-c++-common/ubsan/vla-4.c: Likewise. * g++.dg/ubsan/cxx11-shift-1.C: Likewise. * g++.dg/ubsan/return-2.C: Likewise. * c-c++-common/ubsan/recovery-1.c: New test. * c-c++-common/ubsan/recovery-2.c: New test. * c-c++-common/ubsan/recovery-3.c: New test. * c-c++-common/ubsan/recovery-common.inc: New file. Co-Authored-By: Yury Gribov <y.gribov@samsung.com> From-SVN: r216552
2014-10-22 13:07:10 +02:00
= (flag_sanitize_recover & SANITIZE_NONNULL_ATTRIBUTE)
? BUILT_IN_UBSAN_HANDLE_NONNULL_ARG
: BUILT_IN_UBSAN_HANDLE_NONNULL_ARG_ABORT;
tree fn = builtin_decl_explicit (bcode);
g = gimple_build_call (fn, 1, data);
}
gimple_set_location (g, loc[0]);
gsi_insert_before (gsi, g, GSI_SAME_STMT);
ubsan_create_edge (g);
}
*gsi = gsi_for_stmt (stmt);
}
flag_delete_null_pointer_checks = save_flag_delete_null_pointer_checks;
}
/* Instrument returns in functions with returns_nonnull attribute. */
static void
instrument_nonnull_return (gimple_stmt_iterator *gsi)
{
Merger of git branch "gimple-classes-v2-option-3" gcc/ChangeLog: Merger of git branch "gimple-classes-v2-option-3". * ChangeLog.gimple-classes: New. * coretypes.h (struct gcond): Add forward decl. (struct gdebug): Likewise. (struct ggoto): Likewise. (struct glabel): Likewise. (struct gswitch): Likewise. (struct gassign): Likewise. (struct gasm): Likewise. (struct gcall): Likewise. (struct gtransaction): Likewise. (struct greturn): Likewise. (struct gbind): Likewise. (struct gcatch): Likewise. (struct geh_filter): Likewise. (struct geh_mnt): Likewise. (struct geh_else): Likewise. (struct gresx): Likewise. (struct geh_dispatch): Likewise. (struct gphi): Likewise. (struct gtry): Likewise. (struct gomp_atomic_load): Likewise. (struct gomp_atomic_store): Likewise. (struct gomp_continue): Likewise. (struct gomp_critical): Likewise. (struct gomp_for): Likewise. (struct gomp_parallel): Likewise. (struct gomp_task): Likewise. (struct gomp_sections): Likewise. (struct gomp_single): Likewise. (struct gomp_target): Likewise. (struct gomp_teams): Likewise. * doc/gimple.texi (Class hierarchy of GIMPLE statements): Update for renaming of gimple subclasses. * gdbhooks.py: Update. * gimple-iterator.c (gsi_for_phi): New. (gsi_start_phis): Strengthen return type from gimple_stmt_iterator to gphi_iterator. * gimple-iterator.h (struct gphi_iterator): New subclass of gimple_stmt_iterator. (gsi_for_phi): New prototype. (gsi_start_phis): Strengthen return type from gimple_stmt_iterator to gphi_iterator. (gsi_next_nonvirtual_phi): Strengthen param from gimple_stmt_iterator * to gphi_iterator *, and local "phi" from gimple to gphi *. * gsstruct.def: Update for renamings of classes. * gimple.c (gimple_build_return): Strengthen return type from gimple to greturn *. (gimple_call_reset_alias_info): Strengthen param to gcall *. (gimple_build_call_1): Strengthen return type from gimple to gcall *. (gimple_build_call_vec): Likewise. (gimple_build_call): Likewise. (gimple_build_call_valist): Likewise. (gimple_build_call_internal_1): Likewise. (gimple_build_call_internal): Likewise. (gimple_build_call_internal_vec): Likewise. (gimple_build_call_from_tree): Likewise. (gimple_build_assign_stat): Strengthen return type from gimple to gassign *. (gimple_build_assign_with_ops): Likewise. (gimple_build_assign_with_ops): Likewise. (gimple_build_cond): Strengthen return type from gimple to gcond *. (gimple_build_cond_from_tree): Likewise. (gimple_cond_set_condition_from_tree): Require a gcond *. (gimple_build_label): Strengthen return type from gimple to glabel *. (gimple_build_goto): Strengthen return type from gimple to ggoto *. (gimple_build_bind): Strengthen return type from gimple to gbind *. (gimple_build_asm_1): Strengthen return type from gimple to gasm *. (gimple_build_asm_vec): Likewise. (gimple_build_catch): Strengthen return type from gimple to gcatch *. (gimple_build_eh_filter): Strengthen return type from gimple to geh_filter *. (gimple_build_eh_must_not_throw): Strengthen return type from gimple to geh_mnt *. (gimple_build_eh_else): Strengthen return type from gimple to geh_else *. (gimple_build_try): Update for renaming of gimple_statement_try to gtry. (gimple_build_resx): Strengthen return type from gimple to gresx *. (gimple_build_switch_nlabels): Strengthen return type from gimple to gswitch *. (gimple_build_switch): Likewise. (gimple_build_eh_dispatch): Strengthen return type from gimple to geh_dispatch *. (gimple_build_debug_bind_stat): Strengthen return type from gimple to gdebug *. (gimple_build_debug_source_bind_stat): Strengthen return type from gimple to gdebug *. (gimple_build_omp_critical): Strengthen return type from gimple to gomp_critical *. (gimple_build_omp_for): Strengthen return type from gimple to gomp_for *. (gimple_build_omp_parallel): Strengthen return type from gimple to gomp_parallel *. (gimple_build_omp_task): Strengthen return type from gimple to gomp_task *. (gimple_build_omp_continue): Strengthen return type from gimple to gomp_continue *. (gimple_build_omp_sections): Strengthen return type from gimple to gomp_sections *. (gimple_build_omp_single): Strengthen return type from gimple to gomp_single *. (gimple_build_omp_target): Strengthen return type from gimple to gomp_target *. (gimple_build_omp_teams): Strengthen return type from gimple to gomp_teams *. (gimple_build_omp_atomic_load): Strengthen return type from gimple to gomp_atomic_load *. (gimple_build_omp_atomic_store): Strengthen return type from gimple to gomp_atomic_store *. (gimple_build_transaction): Strengthen return type from gimple to gtransaction *. (empty_stmt_p): Replace check for GIMPLE_BIND with a dyn_cast. (gimple_call_fnspec): Require a const gcall *. (gimple_call_arg_flags): Likewise. (gimple_call_return_flags): Likewise. (gimple_set_bb): Add a checked cast. (gimple_copy): Within the cases, add locals of the appropriate subclass and use in place of "stmt" and "copy" for typesafety. (gimple_has_side_effects): Add a checked cast. (gimple_could_trap_p_1): Likewise. (gimple_call_copy_skip_args): Require a gcall *, and return one. (gimple_asm_clobbers_memory_p): Require a const gasm *. (infer_nonnull_range): Replace a check for GIMPLE_RETURN with a dyn_cast, introducing local "return_stmt" and using ti in place of "stmt". * gimple.h (gimple_vec): Eliminate this typedef. (struct gimple_statement_call): Rename to... (struct gcall): ...this. (struct gimple_statement_bind): Rename to... (struct gbind): ...this. (struct gimple_statement_catch): Rename to... (struct gcatch): ...this. (struct gimple_statement_eh_filter): Rename to... (struct geh_filter): ...this. (struct gimple_statement_eh_else): Rename to... (struct geh_else): ...this. (struct gimple_statement_eh_mnt): Rename to... (struct geh_mnt): ...this. (struct gimple_statement_phi): Rename to... (struct gphi): ...this. (struct gimple_statement_resx): Rename to... (struct gresx): ...this. (struct gimple_statement_eh_dispatch): Rename to... (struct geh_dispatch): ...this. (struct gimple_statement_try): Rename to... (struct gtry): ...this. (struct gimple_statement_asm): Rename to... (struct gasm): ...this. (struct gimple_statement_omp_critical): Rename to... (struct gomp_critical): ...this. (struct gimple_statement_omp_for): Rename to... (struct gomp_for): ...this. (struct gimple_statement_omp_parallel): Rename to... (struct gomp_parallel): ...this. (struct gimple_statement_omp_target): Rename to... (struct gomp_target): ...this. (struct gimple_statement_omp_task): Rename to... (struct gomp_task): ...this. (struct gimple_statement_omp_sections): Rename to... (struct gomp_sections): ...this. (struct gimple_statement_omp_continue): Rename to... (struct gomp_continue): ...this. (struct gimple_statement_omp_single): Rename to... (struct gomp_single): ...this. (struct gimple_statement_omp_teams): Rename to... (struct gomp_teams): ...this. (struct gimple_statement_omp_atomic_load): Rename to... (struct gomp_atomic_load): ...this. (struct gimple_statement_omp_atomic_store :): Rename to... (struct gomp_atomic_store :): ...this. (struct gimple_statement_transaction): Rename to... (struct gtransaction): ...this. (struct gcond): New subclass. (struct gdebug): New subclass. (struct ggoto): New subclass. (struct glabel): New subclass. (struct gswitch): New subclass. (struct gassign): New subclass. (struct greturn): New subclass. (is_a_helper <gimple_statement_asm *>::test): Rename to... (is_a_helper <gasm *>::test): ...this. (is_a_helper <gimple_statement_bind *>::test): Rename to... (is_a_helper <gbind *>::test): ...this. (is_a_helper <gassign *>::test): New. (is_a_helper <gimple_statement_call *>::test): Rename to... (is_a_helper <gcall *>::test): ...this. (is_a_helper <gimple_statement_catch *>::test): Rename to... (is_a_helper <gcatch *>::test): ...this. (is_a_helper <gimple_statement_resx *>::test): Rename to... (is_a_helper <gresx *>::test): ...this. (is_a_helper <gcond *>::test): New. (is_a_helper <gdebug *>::test): New. (is_a_helper <ggoto *>::test): New. (is_a_helper <glabel *>::test): New. (is_a_helper <gimple_statement_eh_dispatch *>::test): Rename to... (is_a_helper <geh_dispatch *>::test): ...this. (is_a_helper <gimple_statement_eh_else *>::test): Rename to... (is_a_helper <geh_else *>::test): ...this. (is_a_helper <gimple_statement_eh_filter *>::test): Rename to... (is_a_helper <geh_filter *>::test): ...this. (is_a_helper <gimple_statement_eh_mnt *>::test): Rename to... (is_a_helper <geh_mnt *>::test): ...this. (is_a_helper <gimple_statement_omp_atomic_load *>::test): Rename to... (is_a_helper <gomp_atomic_load *>::test): ...this. (is_a_helper <gimple_statement_omp_atomic_store *>::test): Rename to... (is_a_helper <gomp_atomic_store *>::test): ...this. (is_a_helper <gimple_statement_omp_continue *>::test): Rename to... (is_a_helper <gomp_continue *>::test): ...this. (is_a_helper <gimple_statement_omp_critical *>::test): Rename to... (is_a_helper <gomp_critical *>::test): ...this. (is_a_helper <gimple_statement_omp_for *>::test): Rename to... (is_a_helper <gomp_for *>::test): ...this. (is_a_helper <gimple_statement_omp_parallel *>::test): Rename to... (is_a_helper <gomp_parallel *>::test): ...this. (is_a_helper <gimple_statement_omp_target *>::test): Rename to... (is_a_helper <gomp_target *>::test): ...this. (is_a_helper <gimple_statement_omp_sections *>::test): Rename to... (is_a_helper <gomp_sections *>::test): ...this. (is_a_helper <gimple_statement_omp_single *>::test): Rename to... (is_a_helper <gomp_single *>::test): ...this. (is_a_helper <gimple_statement_omp_teams *>::test): Rename to... (is_a_helper <gomp_teams *>::test): ...this. (is_a_helper <gimple_statement_omp_task *>::test): Rename to... (is_a_helper <gomp_task *>::test): ...this. (is_a_helper <gimple_statement_phi *>::test): Rename to... (is_a_helper <gphi *>::test): ...this. (is_a_helper <gimple_statement_transaction *>::test): Rename to... (is_a_helper <gtransaction *>::test): ...this. (is_a_helper <greturn *>::test): New. (is_a_helper <gswitch *>::test): New. (is_a_helper <gimple_statement_try *>::test): Rename to... (is_a_helper <gtry *>::test): ...this. (is_a_helper <const gimple_statement_asm *>::test): Rename to... (is_a_helper <const gasm *>::test): ...this. (is_a_helper <const gimple_statement_bind *>::test): Rename to... (is_a_helper <const gbind *>::test): ...this. (is_a_helper <const gimple_statement_call *>::test): Rename to... (is_a_helper <const gcall *>::test): ...this. (is_a_helper <const gimple_statement_catch *>::test): Rename to... (is_a_helper <const gcatch *>::test): ...this. (is_a_helper <const gimple_statement_resx *>::test): Rename to... (is_a_helper <const gresx *>::test): ...this. (is_a_helper <const gimple_statement_eh_dispatch *>::test): Rename to... (is_a_helper <const geh_dispatch *>::test): ...this. (is_a_helper <const gimple_statement_eh_filter *>::test): Rename to... (is_a_helper <const geh_filter *>::test): ...this. (is_a_helper <const gimple_statement_omp_atomic_load *>::test): Rename to... (is_a_helper <const gomp_atomic_load *>::test): ...this. (is_a_helper <const gimple_statement_omp_atomic_store *>::test): Rename to... (is_a_helper <const gomp_atomic_store *>::test): ...this. (is_a_helper <const gimple_statement_omp_continue *>::test): Rename to... (is_a_helper <const gomp_continue *>::test): ...this. (is_a_helper <const gimple_statement_omp_critical *>::test): Rename to... (is_a_helper <const gomp_critical *>::test): ...this. (is_a_helper <const gimple_statement_omp_for *>::test): Rename to... (is_a_helper <const gomp_for *>::test): ...this. (is_a_helper <const gimple_statement_omp_parallel *>::test): Rename to... (is_a_helper <const gomp_parallel *>::test): ...this. (is_a_helper <const gimple_statement_omp_target *>::test): Rename to... (is_a_helper <const gomp_target *>::test): ...this. (is_a_helper <const gimple_statement_omp_sections *>::test): Rename to... (is_a_helper <const gomp_sections *>::test): ...this. (is_a_helper <const gimple_statement_omp_single *>::test): Rename to... (is_a_helper <const gomp_single *>::test): ...this. (is_a_helper <const gimple_statement_omp_teams *>::test): Rename to... (is_a_helper <const gomp_teams *>::test): ...this. (is_a_helper <const gimple_statement_omp_task *>::test): Rename to... (is_a_helper <const gomp_task *>::test): ...this. (is_a_helper <const gimple_statement_phi *>::test): Rename to... (is_a_helper <const gphi *>::test): ...this. (is_a_helper <const gimple_statement_transaction *>::test): Rename to... (is_a_helper <const gtransaction *>::test): ...this. (gimple_build_return): Strengthen return type to greturn *. (gimple_call_reset_alias_info): Require a gcall *. (gimple_build_call_vec): Return a gcall *. (gimple_build_call): Likewise. (gimple_build_call_valist): Likewise. (gimple_build_call_internal): Likewise. (gimple_build_call_internal_vec): Likewise. (gimple_build_call_from_tree): Likewise. (gimple_build_assign_stat): Return a gassign *. (gimple_build_assign_with_ops): Likewise. (gimple_build_cond): Return a gcond *. (gimple_build_cond_from_tree): Likewise. (gimple_cond_set_condition_from_tree): Require a gcond *. (gimple_build_label): Return a glabel *. (gimple_build_goto): Return a ggoto *. (gimple_build_bind): Return a gbind *. (gimple_build_asm_vec): Return a gasm *. (gimple_build_catch): Return a gcatch *. (gimple_build_eh_filter): Return a geh_filter *. (gimple_build_eh_must_not_throw): Return a geh_mnt *. (gimple_build_eh_else): Return a geh_else *. (gimple_build_try): Return a gtry *. (gimple_build_resx): Return a gresx *. (gimple_build_switch_nlabels): Return a gswitch *. (gimple_build_switch): Return a gswitch *. (gimple_build_eh_dispatch): Return a geh_dispatch *. (gimple_build_debug_bind_stat): Return a gdebug *. (gimple_build_debug_source_bind_stat): Return a gdebug *. (gimple_build_omp_critical): Return a gomp_critical *. (gimple_build_omp_for): Return a gomp_for *. (gimple_build_omp_parallel): Return a gomp_parallel *. (gimple_build_omp_task): Return a gomp_task *. (gimple_build_omp_continue): Return a gomp_continue *. (gimple_build_omp_sections): Return a gomp_sections *. (gimple_build_omp_single): Return a gomp_single *. (gimple_build_omp_target): Return a gomp_target *. (gimple_build_omp_teams): Return a gomp_teams *. (gimple_build_omp_atomic_load): Return a gomp_atomic_load *. (gimple_build_omp_atomic_store): Return a gomp_atomic_store *. (gimple_build_transaction): Return a gtransaction *. (gimple_call_arg_flags): Require a const gcall *. (gimple_call_return_flags): Likewise. (gimple_call_copy_skip_args): Require and return a gcall *. (gimple_asm_clobbers_memory_p): Require a const gasm *. (gimple_seq_first_stmt_as_a_bind): New. (gimple_assign_nontemporal_move_p): Require a const gassign * rather than a const_gimple. (gimple_call_internal_fn): Update for renaming to gcall. (gimple_call_fntype): Likewise. (gimple_call_set_fntype): Require a gcall * rather than a gimple. (gimple_call_set_fn): Likewise. (gimple_call_set_internal_fn): Likewise. (gimple_call_set_chain): Likewise. (gimple_call_set_tail): Likewise. (gimple_call_tail_p): Likewise. (gimple_call_set_return_slot_opt): Likewise. (gimple_call_return_slot_opt_p): Likewise. (gimple_call_set_from_thunk): Likewise. (gimple_call_from_thunk_p): Likewise. (gimple_call_set_va_arg_pack): Likewise. (gimple_call_va_arg_pack_p): Likewise. (gimple_call_set_nothrow): Likewise. (gimple_call_nothrow_p): Likewise. (gimple_call_set_alloca_for_var): Likewise. (gimple_call_alloca_for_var_p): Likewise. (gimple_call_use_set): Likewise. (gimple_call_clobber_set): Likewise. (gimple_call_return_type): Require a const gcall * rather than a const_gimple. (gimple_call_chain_ptr): Likewise. (gimple_call_copy_flags): Require a pair of gcall *. (gimple_cond_set_code): Require a gcond * rather than a gimple (gimple_cond_set_lhs): Likewise. (gimple_cond_set_rhs): Likewise. (gimple_cond_set_true_label): Likewise. (gimple_cond_set_false_label): Likewise. (gimple_cond_make_false): Likewise. (gimple_cond_make_true): Likewise. (gimple_cond_lhs_ptr): Require a const gcond * rather than a const_gimple. (gimple_cond_rhs_ptr): Likewise. (gimple_cond_true_label): Likewise. (gimple_cond_false_label): Likewise. (gimple_cond_true_p): Likewise. (gimple_cond_false_p): Likewise. (gimple_cond_set_condition): Likewise. (gimple_label_label): Require a const glabel *. (gimple_label_set_label): Require a glabel *. (gimple_goto_set_dest): Require a ggoto *. (gimple_bind_vars): Require a const gbind *. (gimple_bind_block): Likewise. (gimple_bind_set_vars): Require a gbind *. (gimple_bind_append_vars): Likewise. (gimple_bind_body_ptr): Likewise. (gimple_bind_body): Likewise. (gimple_bind_set_body): Likewise. (gimple_bind_add_stmt): Likewise. (gimple_bind_add_seq): Likewise. (gimple_bind_set_block): Likewise. (gimple_asm_ninputs): Require a const gasm *. (gimple_asm_noutputs): Likewise. (gimple_asm_nclobbers): Likewise. (gimple_asm_nlabels): Likewise. (gimple_asm_input_op): Likewise. (gimple_asm_input_op_ptr): Likewise. (gimple_asm_output_op): Likewise. (gimple_asm_output_op_ptr): Likewise. (gimple_asm_clobber_op): Likewise. (gimple_asm_label_op): Likewise. (gimple_asm_string): Likewise. (gimple_asm_volatile_p): Likewise. (gimple_asm_input_p): Likewise. (gimple_asm_set_input_op): Require a gasm *. (gimple_asm_set_output_op): Likewise. (gimple_asm_set_clobber_op): Likewise. (gimple_asm_set_label_op): Likewise. (gimple_asm_set_volatile): Likewise. (gimple_asm_set_input): Likewise. (gimple_catch_types): Require a const gcatch *. (gimple_catch_types_ptr): Require a gcatch *. (gimple_catch_handler_ptr): Likewise. (gimple_catch_handler): Likewise. (gimple_catch_set_types): Likewise. (gimple_catch_set_handler): Likewise. (gimple_eh_filter_types): Update for renaming of subclass to geh_filter. (gimple_eh_filter_types_ptr): Likewise. (gimple_eh_filter_failure_ptr): Likewise. (gimple_eh_filter_set_types): Require a geh_filter *. (gimple_eh_filter_set_failure): Likewise. (gimple_eh_must_not_throw_fndecl): Require a geh_mnt *. (gimple_eh_must_not_throw_set_fndecl): Likewise. (gimple_eh_else_n_body_ptr): Require a geh_else *. (gimple_eh_else_n_body): Likewise. (gimple_eh_else_e_body_ptr): Likewise. (gimple_eh_else_e_body): Likewise. (gimple_eh_else_set_n_body): Likewise. (gimple_eh_else_set_e_body): Likewise. (gimple_try_set_kind): Require a gtry *. (gimple_try_set_catch_is_cleanup): Likewise. (gimple_try_set_eval): Likewise. (gimple_try_set_cleanup): Likewise. (gimple_try_eval_ptr): Update for renaming of subclass to gtry. (gimple_try_cleanup_ptr): Likewise. (gimple_phi_capacity): Update for renaming of subclass to gphi. (gimple_phi_num_args): Likewise. (gimple_phi_result): Likewise. (gimple_phi_result_ptr): Likewise. (gimple_phi_arg): Likewise. (gimple_phi_set_result): Require a gphi *. (gimple_phi_set_arg): Likewise. (gimple_phi_arg_def_ptr): Likewise. (gimple_phi_arg_edge): Likewise. (gimple_phi_arg_location): Likewise. (gimple_phi_arg_location_from_edge): Likewise. (gimple_phi_arg_set_location): Likewise. (gimple_phi_arg_has_location): Likewise. (gimple_resx_region): Require a const gresx *. (gimple_resx_set_region): Require a gresx *. (gimple_eh_dispatch_region): Require a const geh_dispatch *. (gimple_eh_dispatch_set_region): Require a geh_dispatch *. (gimple_switch_num_labels): Require a const gswitch *. (gimple_switch_set_num_labels): Likewise. (gimple_switch_index): Likewise. (gimple_switch_index_ptr): Likewise. (gimple_switch_label): Likewise. (gimple_switch_default_label): Likewise. (gimple_switch_set_index): Require a gswitch *. (gimple_switch_set_label): Likewise. (gimple_switch_set_default_label): Likewise. (gimple_omp_critical_name): Require a const gomp_critical *. (gimple_omp_critical_name_ptr): Require a gomp_critical *. (gimple_omp_critical_set_name): Likewise. (gimple_omp_for_set_kind): Require a gomp_for *. (gimple_omp_for_set_combined_p): Likewise. (gimple_omp_for_set_combined_into_p): Likewise. (gimple_omp_for_clauses): Update for renaming of subclass to gomp_for. (gimple_omp_for_clauses_ptr): Likewise. (gimple_omp_for_set_clauses): Likewise. (gimple_omp_for_collapse): Likewise. (gimple_omp_for_index): Likewise. (gimple_omp_for_index_ptr): Likewise. (gimple_omp_for_set_index): Likewise. (gimple_omp_for_initial): Likewise. (gimple_omp_for_initial_ptr): Likewise. (gimple_omp_for_set_initial): Likewise. (gimple_omp_for_final): Likewise. (gimple_omp_for_final_ptr): Likewise. (gimple_omp_for_set_final): Likewise. (gimple_omp_for_incr): Likewise. (gimple_omp_for_incr_ptr): Likewise. (gimple_omp_for_set_incr): Likewise. (gimple_omp_for_pre_body): Likewise. (gimple_omp_for_set_pre_body): Likewise. (gimple_omp_parallel_clauses): Update for renaming of subclass to gomp_parallel. (gimple_omp_parallel_clauses_ptr): Require a gomp_parallel *. (gimple_omp_parallel_set_clauses): Likewise. (gimple_omp_parallel_child_fn_ptr): Likewise. (gimple_omp_parallel_set_child_fn): Likewise. (gimple_omp_parallel_data_arg_ptr): Likewise. (gimple_omp_parallel_set_data_arg): Likewise. (gimple_omp_parallel_child_fn): Require a const gomp_parallel *. (gimple_omp_parallel_data_arg): Likewise. (gimple_omp_task_clauses): Update for renaming of subclass to gomp_task. (gimple_omp_task_clauses_ptr): Likewise. (gimple_omp_task_set_clauses): Likewise. (gimple_omp_task_child_fn): Likewise. (gimple_omp_task_child_fn_ptr): Likewise. (gimple_omp_task_set_child_fn): Likewise. (gimple_omp_task_data_arg): Likewise. (gimple_omp_task_data_arg_ptr): Likewise. (gimple_omp_task_set_data_arg): Likewise. (gimple_omp_taskreg_clauses): Whitespace fixes. (gimple_omp_taskreg_clauses_ptr): Likewise. (gimple_omp_taskreg_set_clauses): Likewise. (gimple_omp_taskreg_child_fn): Likewise. (gimple_omp_taskreg_child_fn_ptr): Likewise. (gimple_omp_taskreg_set_child_fn): Likewise. (gimple_omp_taskreg_data_arg): Likewise. (gimple_omp_taskreg_data_arg_ptr): Likewise. (gimple_omp_taskreg_set_data_arg): Likewise. (gimple_omp_task_copy_fn): Update for renaming of subclass to gomp_task. (gimple_omp_task_copy_fn_ptr): Likewise. (gimple_omp_task_set_copy_fn): Likewise. (gimple_omp_task_arg_size): Likewise. (gimple_omp_task_arg_size_ptr): Likewise. (gimple_omp_task_set_arg_size): Likewise. (gimple_omp_task_arg_align): Likewise. (gimple_omp_task_arg_align_ptr): Likewise. (gimple_omp_task_set_arg_align): Likewise. (gimple_omp_single_clauses): Update for renaming of subclass to gomp_single. (gimple_omp_single_clauses_ptr): Likewise. (gimple_omp_single_set_clauses): Likewise. (gimple_omp_target_clauses): Update for renaming of subclass to gomp_target. (gimple_omp_target_clauses_ptr): Likewise. (gimple_omp_target_set_clauses): Require a gomp_target *. (gimple_omp_target_set_kind): Likewise. (gimple_omp_target_child_fn_ptr): Likewise. (gimple_omp_target_set_child_fn): Likewise. (gimple_omp_target_data_arg_ptr): Likewise. (gimple_omp_target_set_data_arg): Likewise. (gimple_omp_target_child_fn): Require a const gomp_target *. (gimple_omp_target_data_arg): Likewise. (gimple_omp_teams_clauses): Update for renaming of subclass to gomp_teams. (gimple_omp_teams_clauses_ptr): Likewise. (gimple_omp_teams_set_clauses): Require a gomp_teams *. (gimple_omp_sections_clauses): Update for renaming of subclass to gomp_sections. (gimple_omp_sections_clauses_ptr): Likewise. (gimple_omp_sections_set_clauses): Likewise. (gimple_omp_sections_control): Likewise. (gimple_omp_sections_control_ptr): Likewise. (gimple_omp_sections_set_control): Likewise. (gimple_omp_for_set_cond): Likewise. (gimple_omp_for_cond): Likewise. (gimple_omp_atomic_store_set_val): Require a gomp_atomic_store *. (gimple_omp_atomic_store_val_ptr): Likewise. (gimple_omp_atomic_load_set_lhs): Likewise. (gimple_omp_atomic_store_val): Require a const gomp_atomic_store *. (gimple_omp_atomic_load_lhs): Likewise. (gimple_omp_atomic_load_rhs): Likewise. (gimple_omp_atomic_load_lhs_ptr): Require a gomp_atomic_load *. (gimple_omp_atomic_load_set_rhs): Likewise. (gimple_omp_atomic_load_rhs_ptr): Likewise. (gimple_omp_continue_control_def): Require a const gomp_continue *. (gimple_omp_continue_control_use): Likewise. (gimple_omp_continue_control_def_ptr): Require a gomp_continue *. (gimple_omp_continue_set_control_def): Likewise. (gimple_omp_continue_control_use_ptr): Likewise. (gimple_omp_continue_set_control_use): Likewise. (gimple_transaction_body_ptr): Require a gtransaction *. (gimple_transaction_body): Likewise. (gimple_transaction_label_ptr): Likewise. (gimple_transaction_label): Require a const gtransaction *. (gimple_transaction_subcode): Likewise. (gimple_transaction_set_body): Require a gtransaction *. (gimple_transaction_set_label): Likewise. (gimple_transaction_set_subcode): Likewise. (gimple_return_retval_ptr): Require a const greturn *. (gimple_return_retval): Likewise. (gimple_return_set_retval): Require a greturn *. (gimple_expr_type): Introduce local "call_stmt" and use in place of "stmt" for typesafety. * asan.c: Use gimple subclasses. * auto-profile.c: Likewise. * builtins.c: Likewise. * builtins.h: Likewise. * cfgexpand.c: Likewise. * cfgloop.c: Likewise. * cfgloopmanip.c: Likewise. * cgraph.c: Likewise. * cgraph.h: Likewise. * cgraphbuild.c: Likewise. * cgraphclones.c: Likewise. * cgraphunit.c: Likewise. * expr.h: Likewise. * gimple-builder.c: Likewise. * gimple-builder.h: Likewise. * gimple-fold.c: Likewise. * gimple-low.c: Likewise. * gimple-pretty-print.c: Likewise. * gimple-ssa-isolate-paths.c: Likewise. * gimple-ssa-strength-reduction.c: Likewise. * gimple-streamer-in.c: Likewise. * gimple-streamer-out.c: Likewise. * gimple-walk.c: Likewise. * gimplify-me.c: Likewise. * gimplify.c: Likewise. * gimplify.h: Likewise. * graphite-scop-detection.c: Likewise. * graphite-sese-to-poly.c: Likewise. * internal-fn.c: Likewise. * internal-fn.def:: Likewise. * internal-fn.h: Likewise. * ipa-icf-gimple.c: Likewise. * ipa-icf-gimple.h: Likewise. * ipa-icf.c: Likewise. * ipa-inline-analysis.c: Likewise. * ipa-prop.c: Likewise. * ipa-prop.h: Likewise. * ipa-pure-const.c: Likewise. * ipa-split.c: Likewise. * lto-streamer-in.c: Likewise. * lto-streamer-out.c: Likewise. * omp-low.c: Likewise. * predict.c: Likewise. * sanopt.c: Likewise. * sese.c: Likewise. * ssa-iterators.h: Likewise. * stmt.c: Likewise. * trans-mem.c: Likewise. * tree-call-cdce.c: Likewise. * tree-cfg.c: Likewise. * tree-cfg.h: Likewise. * tree-cfgcleanup.c: Likewise. * tree-chkp.c: Likewise. * tree-chkp.h: Likewise. * tree-complex.c: Likewise. * tree-data-ref.c: Likewise. * tree-dfa.c: Likewise. * tree-eh.c: Likewise. * tree-eh.h: Likewise. * tree-emutls.c: Likewise. * tree-if-conv.c: Likewise. * tree-inline.c: Likewise. * tree-inline.h: Likewise. * tree-into-ssa.c: Likewise. * tree-into-ssa.h: Likewise. * tree-loop-distribution.c: Likewise. * tree-nrv.c: Likewise. * tree-object-size.c: Likewise. * tree-outof-ssa.c: Likewise. * tree-parloops.c: Likewise. * tree-phinodes.c: Likewise. * tree-phinodes.h: Likewise. * tree-predcom.c: Likewise. * tree-profile.c: Likewise. * tree-scalar-evolution.c: Likewise. * tree-scalar-evolution.h * tree-sra.cn_function): * tree-ssa-alias.c: Likewise. * tree-ssa-alias.h: Likewise. * tree-ssa-ccp.c: Likewise. * tree-ssa-coalesce.c: Likewise. * tree-ssa-copy.c: Likewise. * tree-ssa-copyrename.c: Likewise. * tree-ssa-dce.c: Likewise. * tree-ssa-dom.c: Likewise. * tree-ssa-forwprop.c: Likewise. * tree-ssa-ifcombine.c: Likewise. * tree-ssa-live.c: Likewise. * tree-ssa-loop-im.c: Likewise. * tree-ssa-loop-ivcanon.c: Likewise. * tree-ssa-loop-ivopts.c: Likewise. * tree-ssa-loop-manip.c: Likewise. * tree-ssa-loop-niter.c: Likewise. * tree-ssa-loop-prefetch.c: Likewise. * tree-ssa-loop-unswitch.c: Likewise. * tree-ssa-math-opts.c: Likewise. * tree-ssa-operands.c: Likewise. * tree-ssa-phiopt.c: Likewise. * tree-ssa-phiprop.c: Likewise. * tree-ssa-pre.c: Likewise. * tree-ssa-propagate.c: Likewise. * tree-ssa-propagate.h: Likewise. * tree-ssa-reassoc.c: Likewise. * tree-ssa-sccvn.c: Likewise. * tree-ssa-sccvn.h: Likewise. * tree-ssa-sink.c: Likewise. * tree-ssa-strlen.c * tree-ssa-structalias.c * tree-ssa-tail-merge.c: Likewise. * tree-ssa-ter.c: Likewise. * tree-ssa-threadedge.c: Likewise. * tree-ssa-threadedge.h: Likewise. * tree-ssa-threadupdate.c: Likewise. * tree-ssa-uncprop.c: Likewise. * tree-ssa-uninit.c: Likewise. * tree-ssa.c: Likewise. * tree-stdarg.c: Likewise. * tree-switch-conversion.c: Likewise. * tree-tailcall.c: Likewise. * tree-vect-data-refs.c: Likewise. * tree-vect-generic.c: Likewise. * tree-vect-loop-manip.c: Likewise. * tree-vect-loop.c: Likewise. * tree-vect-patterns.c: Likewise. * tree-vect-slp.c: Likewise. * tree-vect-stmts.c: Likewise. * tree-vectorizer.h: Likewise. * tree-vrp.c: Likewise. * tree.c: Likewise. * ubsan.c: Likewise. * value-prof.c: Likewise. * value-prof.h: Likewise. * vtable-verify.c: Likewise. gcc/c-family/ChangeLog: Merger of git branch "gimple-classes-v2-option-3". * ChangeLog.gimple-classes: New. * c-gimplify.c (add_block_to_enclosing): Strengthen local "stack" from being just a vec<gimple> to a vec<gbind *>. gcc/java/ChangeLog: Merger of git branch "gimple-classes-v2-option-3". * ChangeLog.gimple-classes: New. * java-gimplify.c (java_gimplify_block): Strengthen local "outer" from gimple to gbind *. From-SVN: r217787
2014-11-19 18:00:54 +01:00
greturn *stmt = as_a <greturn *> (gsi_stmt (*gsi));
location_t loc[2];
tree arg = gimple_return_retval (stmt);
/* infer_nonnull_range needs flag_delete_null_pointer_checks set,
while for nonnull return sanitization it is clear. */
int save_flag_delete_null_pointer_checks = flag_delete_null_pointer_checks;
flag_delete_null_pointer_checks = 1;
loc[0] = gimple_location (stmt);
loc[1] = UNKNOWN_LOCATION;
if (arg
&& POINTER_TYPE_P (TREE_TYPE (arg))
&& is_gimple_val (arg)
&& infer_nonnull_range_by_attribute (stmt, arg))
{
basic_block then_bb, fallthru_bb;
*gsi = create_cond_insert_point (gsi, true, false, true,
&then_bb, &fallthru_bb);
gimple *g = gimple_build_cond (EQ_EXPR, arg,
build_zero_cst (TREE_TYPE (arg)),
NULL_TREE, NULL_TREE);
gimple_set_location (g, loc[0]);
gsi_insert_after (gsi, g, GSI_NEW_STMT);
*gsi = gsi_after_labels (then_bb);
if (flag_sanitize_undefined_trap_on_error)
g = gimple_build_call (builtin_decl_explicit (BUILT_IN_TRAP), 0);
else
{
tree data = ubsan_create_data ("__ubsan_nonnull_return_data",
2, loc, NULL_TREE, NULL_TREE);
data = build_fold_addr_expr_loc (loc[0], data);
enum built_in_function bcode
New syntax for -fsanitize-recover. 2014-10-22 Jakub Jelinek <jakub@redhat.com> Yury Gribov <y.gribov@samsung.com> gcc/ * common.opt (flag_sanitize_recover): New variable. (fsanitize-recover): Remove Var/Init, deprecate. (fsanitize-recover=): New option. * doc/invoke.texi (fsanitize-recover): Update docs. * opts.c (finish_options): Use opts->x_flag_sanitize instead of flag_sanitize. Prohibit -fsanitize-recover for anything besides UBSan. Formatting. (common_handle_option): Handle OPT_fsanitize_recover_ and OPT_fsanitize_recover. Use opts->x_flag_sanitize instead of flag_sanitize. * asan.c (pass_sanopt::execute): Fix up formatting. * ubsan.c (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn, ubsan_expand_objsize_ifn, ubsan_build_overflow_builtin, instrument_bool_enum_load, ubsan_instrument_float_cast, instrument_nonnull_arg, instrument_nonnull_return): Check bits in flag_sanitize_recover bitmask instead of flag_sanitize_recover as bool flag. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division, ubsan_instrument_shift, ubsan_instrument_vla): Check bits in flag_sanitize_recover bitmask instead of flag_sanitize_recover as bool flag. gcc/testsuite/ * c-c++-common/ubsan/align-1.c: Update cmdline options. * c-c++-common/ubsan/align-3.c: Likewise. * c-c++-common/ubsan/bounds-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-7.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-10.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-7.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-8.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-9.c: Likewise. * c-c++-common/ubsan/nonnull-2.c: Likewise. * c-c++-common/ubsan/nonnull-3.c: Likewise. * c-c++-common/ubsan/object-size-3.c: Likewise. * c-c++-common/ubsan/overflow-1.c: Likewise. * c-c++-common/ubsan/overflow-add-1.c: Likewise. * c-c++-common/ubsan/overflow-add-3.c: Likewise. * c-c++-common/ubsan/overflow-mul-1.c: Likewise. * c-c++-common/ubsan/overflow-mul-3.c: Likewise. * c-c++-common/ubsan/overflow-negate-2.c: Likewise. * c-c++-common/ubsan/overflow-sub-1.c: Likewise. * c-c++-common/ubsan/pr59503.c: Likewise. * c-c++-common/ubsan/pr60613-1.c: Likewise. * c-c++-common/ubsan/save-expr-1.c: Likewise. * c-c++-common/ubsan/shift-3.c: Likewise. * c-c++-common/ubsan/shift-6.c: Likewise. * c-c++-common/ubsan/undefined-1.c: Likewise. * c-c++-common/ubsan/vla-2.c: Likewise. * c-c++-common/ubsan/vla-3.c: Likewise. * c-c++-common/ubsan/vla-4.c: Likewise. * g++.dg/ubsan/cxx11-shift-1.C: Likewise. * g++.dg/ubsan/return-2.C: Likewise. * c-c++-common/ubsan/recovery-1.c: New test. * c-c++-common/ubsan/recovery-2.c: New test. * c-c++-common/ubsan/recovery-3.c: New test. * c-c++-common/ubsan/recovery-common.inc: New file. Co-Authored-By: Yury Gribov <y.gribov@samsung.com> From-SVN: r216552
2014-10-22 13:07:10 +02:00
= (flag_sanitize_recover & SANITIZE_RETURNS_NONNULL_ATTRIBUTE)
? BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN
: BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT;
tree fn = builtin_decl_explicit (bcode);
g = gimple_build_call (fn, 1, data);
}
gimple_set_location (g, loc[0]);
gsi_insert_before (gsi, g, GSI_SAME_STMT);
ubsan_create_edge (g);
*gsi = gsi_for_stmt (stmt);
}
flag_delete_null_pointer_checks = save_flag_delete_null_pointer_checks;
}
/* Instrument memory references. Here we check whether the pointer
points to an out-of-bounds location. */
static void
instrument_object_size (gimple_stmt_iterator *gsi, bool is_lhs)
{
gimple *stmt = gsi_stmt (*gsi);
location_t loc = gimple_location (stmt);
tree t = is_lhs ? gimple_get_lhs (stmt) : gimple_assign_rhs1 (stmt);
tree type;
tree index = NULL_TREE;
HOST_WIDE_INT size_in_bytes;
type = TREE_TYPE (t);
if (VOID_TYPE_P (type))
return;
switch (TREE_CODE (t))
{
case COMPONENT_REF:
if (TREE_CODE (t) == COMPONENT_REF
&& DECL_BIT_FIELD_REPRESENTATIVE (TREE_OPERAND (t, 1)) != NULL_TREE)
{
tree repr = DECL_BIT_FIELD_REPRESENTATIVE (TREE_OPERAND (t, 1));
t = build3 (COMPONENT_REF, TREE_TYPE (repr), TREE_OPERAND (t, 0),
repr, TREE_OPERAND (t, 2));
}
break;
case ARRAY_REF:
index = TREE_OPERAND (t, 1);
break;
case INDIRECT_REF:
case MEM_REF:
case VAR_DECL:
case PARM_DECL:
case RESULT_DECL:
break;
default:
return;
}
size_in_bytes = int_size_in_bytes (type);
if (size_in_bytes <= 0)
return;
HOST_WIDE_INT bitsize, bitpos;
tree offset;
decl.c, [...]: Remove redundant enum from machine_mode. gcc/ada/ * gcc-interface/decl.c, gcc-interface/gigi.h, gcc-interface/misc.c, gcc-interface/trans.c, gcc-interface/utils.c, gcc-interface/utils2.c: Remove redundant enum from machine_mode. gcc/c-family/ * c-common.c, c-common.h, c-cppbuiltin.c, c-lex.c: Remove redundant enum from machine_mode. gcc/c/ * c-decl.c, c-tree.h, c-typeck.c: Remove redundant enum from machine_mode. gcc/cp/ * constexpr.c: Remove redundant enum from machine_mode. gcc/fortran/ * trans-types.c, trans-types.h: Remove redundant enum from machine_mode. gcc/go/ * go-lang.c: Remove redundant enum from machine_mode. gcc/java/ * builtins.c, java-tree.h, typeck.c: Remove redundant enum from machine_mode. gcc/lto/ * lto-lang.c: Remove redundant enum from machine_mode. gcc/ * addresses.h, alias.c, asan.c, auto-inc-dec.c, bt-load.c, builtins.c, builtins.h, caller-save.c, calls.c, calls.h, cfgexpand.c, cfgloop.h, cfgrtl.c, combine.c, compare-elim.c, config/aarch64/aarch64-builtins.c, config/aarch64/aarch64-protos.h, config/aarch64/aarch64-simd.md, config/aarch64/aarch64.c, config/aarch64/aarch64.h, config/aarch64/aarch64.md, config/alpha/alpha-protos.h, config/alpha/alpha.c, config/arc/arc-protos.h, config/arc/arc.c, config/arc/arc.h, config/arc/predicates.md, config/arm/aarch-common-protos.h, config/arm/aarch-common.c, config/arm/arm-protos.h, config/arm/arm.c, config/arm/arm.h, config/arm/arm.md, config/arm/neon.md, config/arm/thumb2.md, config/avr/avr-log.c, config/avr/avr-protos.h, config/avr/avr.c, config/avr/avr.md, config/bfin/bfin-protos.h, config/bfin/bfin.c, config/c6x/c6x-protos.h, config/c6x/c6x.c, config/c6x/c6x.md, config/cr16/cr16-protos.h, config/cr16/cr16.c, config/cris/cris-protos.h, config/cris/cris.c, config/cris/cris.md, config/darwin-protos.h, config/darwin.c, config/epiphany/epiphany-protos.h, config/epiphany/epiphany.c, config/epiphany/epiphany.md, config/fr30/fr30.c, config/frv/frv-protos.h, config/frv/frv.c, config/frv/predicates.md, config/h8300/h8300-protos.h, config/h8300/h8300.c, config/i386/i386-builtin-types.awk, config/i386/i386-protos.h, config/i386/i386.c, config/i386/i386.md, config/i386/predicates.md, config/i386/sse.md, config/i386/sync.md, config/ia64/ia64-protos.h, config/ia64/ia64.c, config/iq2000/iq2000-protos.h, config/iq2000/iq2000.c, config/iq2000/iq2000.md, config/lm32/lm32-protos.h, config/lm32/lm32.c, config/m32c/m32c-protos.h, config/m32c/m32c.c, config/m32r/m32r-protos.h, config/m32r/m32r.c, config/m68k/m68k-protos.h, config/m68k/m68k.c, config/mcore/mcore-protos.h, config/mcore/mcore.c, config/mcore/mcore.md, config/mep/mep-protos.h, config/mep/mep.c, config/microblaze/microblaze-protos.h, config/microblaze/microblaze.c, config/mips/mips-protos.h, config/mips/mips.c, config/mmix/mmix-protos.h, config/mmix/mmix.c, config/mn10300/mn10300-protos.h, config/mn10300/mn10300.c, config/moxie/moxie.c, config/msp430/msp430-protos.h, config/msp430/msp430.c, config/nds32/nds32-cost.c, config/nds32/nds32-intrinsic.c, config/nds32/nds32-md-auxiliary.c, config/nds32/nds32-protos.h, config/nds32/nds32.c, config/nios2/nios2-protos.h, config/nios2/nios2.c, config/pa/pa-protos.h, config/pa/pa.c, config/pdp11/pdp11-protos.h, config/pdp11/pdp11.c, config/rl78/rl78-protos.h, config/rl78/rl78.c, config/rs6000/altivec.md, config/rs6000/rs6000-c.c, config/rs6000/rs6000-protos.h, config/rs6000/rs6000.c, config/rs6000/rs6000.h, config/rx/rx-protos.h, config/rx/rx.c, config/s390/predicates.md, config/s390/s390-protos.h, config/s390/s390.c, config/s390/s390.h, config/s390/s390.md, config/sh/predicates.md, config/sh/sh-protos.h, config/sh/sh.c, config/sh/sh.md, config/sparc/predicates.md, config/sparc/sparc-protos.h, config/sparc/sparc.c, config/sparc/sparc.md, config/spu/spu-protos.h, config/spu/spu.c, config/stormy16/stormy16-protos.h, config/stormy16/stormy16.c, config/tilegx/tilegx-protos.h, config/tilegx/tilegx.c, config/tilegx/tilegx.md, config/tilepro/tilepro-protos.h, config/tilepro/tilepro.c, config/v850/v850-protos.h, config/v850/v850.c, config/v850/v850.md, config/vax/vax-protos.h, config/vax/vax.c, config/vms/vms-c.c, config/xtensa/xtensa-protos.h, config/xtensa/xtensa.c, coverage.c, cprop.c, cse.c, cselib.c, cselib.h, dbxout.c, ddg.c, df-problems.c, dfp.c, dfp.h, doc/md.texi, doc/rtl.texi, doc/tm.texi, doc/tm.texi.in, dojump.c, dse.c, dwarf2cfi.c, dwarf2out.c, dwarf2out.h, emit-rtl.c, emit-rtl.h, except.c, explow.c, expmed.c, expmed.h, expr.c, expr.h, final.c, fixed-value.c, fixed-value.h, fold-const.c, function.c, function.h, fwprop.c, gcse.c, gengenrtl.c, genmodes.c, genopinit.c, genoutput.c, genpreds.c, genrecog.c, gensupport.c, gimple-ssa-strength-reduction.c, graphite-clast-to-gimple.c, haifa-sched.c, hooks.c, hooks.h, ifcvt.c, internal-fn.c, ira-build.c, ira-color.c, ira-conflicts.c, ira-costs.c, ira-emit.c, ira-int.h, ira-lives.c, ira.c, ira.h, jump.c, langhooks.h, libfuncs.h, lists.c, loop-doloop.c, loop-invariant.c, loop-iv.c, loop-unroll.c, lower-subreg.c, lower-subreg.h, lra-assigns.c, lra-constraints.c, lra-eliminations.c, lra-int.h, lra-lives.c, lra-spills.c, lra.c, lra.h, machmode.h, omp-low.c, optabs.c, optabs.h, output.h, postreload.c, print-tree.c, read-rtl.c, real.c, real.h, recog.c, recog.h, ree.c, reg-stack.c, regcprop.c, reginfo.c, regrename.c, regs.h, reload.c, reload.h, reload1.c, rtl.c, rtl.h, rtlanal.c, rtlhash.c, rtlhooks-def.h, rtlhooks.c, sched-deps.c, sel-sched-dump.c, sel-sched-ir.c, sel-sched-ir.h, sel-sched.c, simplify-rtx.c, stmt.c, stor-layout.c, stor-layout.h, target.def, targhooks.c, targhooks.h, tree-affine.c, tree-call-cdce.c, tree-complex.c, tree-data-ref.c, tree-dfa.c, tree-if-conv.c, tree-inline.c, tree-outof-ssa.c, tree-scalar-evolution.c, tree-ssa-address.c, tree-ssa-ccp.c, tree-ssa-loop-ivopts.c, tree-ssa-loop-ivopts.h, tree-ssa-loop-manip.c, tree-ssa-loop-prefetch.c, tree-ssa-math-opts.c, tree-ssa-reassoc.c, tree-ssa-sccvn.c, tree-streamer-in.c, tree-switch-conversion.c, tree-vect-data-refs.c, tree-vect-generic.c, tree-vect-loop.c, tree-vect-patterns.c, tree-vect-slp.c, tree-vect-stmts.c, tree-vrp.c, tree.c, tree.h, tsan.c, ubsan.c, valtrack.c, var-tracking.c, varasm.c: Remove redundant enum from machine_mode. gcc/ * gengtype.c (main): Treat machine_mode as a scalar typedef. * genmodes.c (emit_insn_modes_h): Hide inline functions if USED_FOR_TARGET. From-SVN: r216834
2014-10-29 13:02:45 +01:00
machine_mode mode;
int volatilep = 0, reversep, unsignedp = 0;
tree inner = get_inner_reference (t, &bitsize, &bitpos, &offset, &mode,
Convert TYPE_ALIGN_OK to a TYPE_LANG_FLAG. 2016-07-11 Bernd Edlinger <bernd.edlinger@hotmail.de> Convert TYPE_ALIGN_OK to a TYPE_LANG_FLAG. * tree-core.h (tree_base::nothrow_flag): Adjust comment. (tree_type_common::lang_flag_7): New. (tree_type_common::spare): Reduce size. * tree.h (TYPE_ALIGN_OK): Remove. (TYPE_LANG_FLAG_7): New. (get_inner_reference): Adjust header. * print-tree.c (print_node): Adjust. * expr.c (get_inner_reference): Remove parameter keep_aligning. (get_bit_range, expand_assignment, expand_expr_addr_expr_1): Adjust calls to get_inner_reference. (expand_expr_real_1): Adjust call to get_inner_reference. Remove handling of TYPE_ALIGN_OK. * builtins.c (get_object_alignment_2): Adjust call to get_inner_reference. Remove handling of VIEW_CONVERT_EXPR. * emit-rtl.c (set_mem_attributes_minus_bitpos): Remove handling of TYPE_ALIGN_OK. * asan.c (instrument_derefs): Adjust calls to get_inner_reference. * cfgexpand.c (expand_debug_expr): Likewise. * dbxout.c (dbxout_expand_expr): Likewise. * dwarf2out.c (loc_list_for_address_of_addr_expr_of_indirect_ref, loc_list_from_tree, fortran_common): Likewise. * fold-const.c (optimize_bit_field_compare, decode_field_reference, fold_unary_loc, fold_comparison, split_address_to_core_and_offset): Likewise. * gimple-laddress.c (execute): Likewise. * gimple-ssa-strength-reduction.c (slsr_process_ref): Likewise. * gimplify.c (gimplify_scan_omp_clauses): Likewise. * hsa-gen.c (gen_hsa_addr): Likewise. * simplifx-rtx.c (delegitimize_mem_from_attrs): Likewise. * tsan.c (instrument_expr): Likewise. * ubsan.c (instrument_bool_enum_load, instrument_object_size): Likewise. * tree.c (verify_type_variant): Remove handling of TYPE_ALIGN_OK. * tree-affine.c (tree_to_aff_combination, get_inner_reference_aff): Adjust calls to get_inner_reference. * tree-data-ref.c (split_constant_offset_1, dr_analyze_innermost): Likewise. * tree-scalar-evolution.c (interpret_rhs_expr): Likewise. * tree-sra.c (ipa_sra_check_caller): Likewise. * tree-ssa-loop-ivopts.c (split_address_cost): Likewise. * tree-ssa-math-opts.c (find_bswap_or_nop_load, bswap_replace): Likewise. * tree-vect-data-refs.c (vect_check_gather, vect_analyze_data_refs): Likewise. * config/mips/mips.c (r10k_safe_mem_expr_p): Likewise. * config/pa/pa.c (pa_emit_move_sequence): Remove handling of TYPE_ALIGN_OK. ada: 2016-07-11 Bernd Edlinger <bernd.edlinger@hotmail.de> Convert TYPE_ALIGN_OK to a TYPE_LANG_FLAG. * gcc-interface/ada-tree.h (TYPE_ALIGN_OK): Define. * gcc-interface/trans.c (Attribute_to_gnu): Adjust call to get_inner_reference. * gcc-interface/utils2.c (build_unary_op): Likewise. From-SVN: r238210
2016-07-11 17:02:12 +02:00
&unsignedp, &reversep, &volatilep);
if (bitpos % BITS_PER_UNIT != 0
|| bitsize != size_in_bytes * BITS_PER_UNIT)
return;
bool decl_p = DECL_P (inner);
tree base;
if (decl_p)
{
if (DECL_REGISTER (inner))
return;
base = inner;
}
else if (TREE_CODE (inner) == MEM_REF)
base = TREE_OPERAND (inner, 0);
else
return;
tree ptr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (t)), t);
while (TREE_CODE (base) == SSA_NAME)
{
gimple *def_stmt = SSA_NAME_DEF_STMT (base);
if (gimple_assign_ssa_name_copy_p (def_stmt)
|| (gimple_assign_cast_p (def_stmt)
&& POINTER_TYPE_P (TREE_TYPE (gimple_assign_rhs1 (def_stmt))))
|| (is_gimple_assign (def_stmt)
&& gimple_assign_rhs_code (def_stmt) == POINTER_PLUS_EXPR))
{
tree rhs1 = gimple_assign_rhs1 (def_stmt);
if (TREE_CODE (rhs1) == SSA_NAME
&& SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs1))
break;
else
base = rhs1;
}
else
break;
}
if (!POINTER_TYPE_P (TREE_TYPE (base)) && !DECL_P (base))
return;
tree sizet;
tree base_addr = base;
gimple *bos_stmt = NULL;
if (decl_p)
base_addr = build1 (ADDR_EXPR,
build_pointer_type (TREE_TYPE (base)), base);
unsigned HOST_WIDE_INT size;
if (compute_builtin_object_size (base_addr, 0, &size))
sizet = build_int_cst (sizetype, size);
else if (optimize)
{
if (LOCATION_LOCUS (loc) == UNKNOWN_LOCATION)
loc = input_location;
/* Generate __builtin_object_size call. */
sizet = builtin_decl_explicit (BUILT_IN_OBJECT_SIZE);
sizet = build_call_expr_loc (loc, sizet, 2, base_addr,
integer_zero_node);
sizet = force_gimple_operand_gsi (gsi, sizet, false, NULL_TREE, true,
GSI_SAME_STMT);
/* If the call above didn't end up being an integer constant, go one
statement back and get the __builtin_object_size stmt. Save it,
we might need it later. */
if (SSA_VAR_P (sizet))
{
gsi_prev (gsi);
bos_stmt = gsi_stmt (*gsi);
/* Move on to where we were. */
gsi_next (gsi);
}
}
else
return;
/* Generate UBSAN_OBJECT_SIZE (ptr, ptr+sizeof(*ptr)-base, objsize, ckind)
call. */
/* ptr + sizeof (*ptr) - base */
t = fold_build2 (MINUS_EXPR, sizetype,
fold_convert (pointer_sized_int_node, ptr),
fold_convert (pointer_sized_int_node, base_addr));
t = fold_build2 (PLUS_EXPR, sizetype, t, TYPE_SIZE_UNIT (type));
/* Perhaps we can omit the check. */
if (TREE_CODE (t) == INTEGER_CST
&& TREE_CODE (sizet) == INTEGER_CST
&& tree_int_cst_le (t, sizet))
return;
if (index != NULL_TREE
&& TREE_CODE (index) == SSA_NAME
&& TREE_CODE (sizet) == INTEGER_CST)
{
gimple *def = SSA_NAME_DEF_STMT (index);
if (is_gimple_assign (def)
&& gimple_assign_rhs_code (def) == BIT_AND_EXPR
&& TREE_CODE (gimple_assign_rhs2 (def)) == INTEGER_CST)
{
tree cst = gimple_assign_rhs2 (def);
tree sz = fold_build2 (EXACT_DIV_EXPR, sizetype, sizet,
TYPE_SIZE_UNIT (type));
if (tree_int_cst_sgn (cst) >= 0
&& tree_int_cst_lt (cst, sz))
return;
}
}
if (bos_stmt && gimple_call_builtin_p (bos_stmt, BUILT_IN_OBJECT_SIZE))
ubsan_create_edge (bos_stmt);
/* We have to emit the check. */
t = force_gimple_operand_gsi (gsi, t, true, NULL_TREE, true,
GSI_SAME_STMT);
ptr = force_gimple_operand_gsi (gsi, ptr, true, NULL_TREE, true,
GSI_SAME_STMT);
tree ckind = build_int_cst (unsigned_char_type_node,
is_lhs ? UBSAN_STORE_OF : UBSAN_LOAD_OF);
gimple *g = gimple_build_call_internal (IFN_UBSAN_OBJECT_SIZE, 4,
ptr, t, sizet, ckind);
gimple_set_location (g, loc);
gsi_insert_before (gsi, g, GSI_SAME_STMT);
}
/* True if we want to play UBSan games in the current function. */
bool
do_ubsan_in_current_function ()
{
return (current_function_decl != NULL_TREE
&& !lookup_attribute ("no_sanitize_undefined",
DECL_ATTRIBUTES (current_function_decl)));
}
namespace {
const pass_data pass_data_ubsan =
pass cfun to pass::execute gcc/ * passes.c (opt_pass::execute): Adjust. (pass_manager::execute_pass_mode_switching): Likewise. (early_local_passes::execute): Likewise. (execute_one_pass): Pass cfun to the pass's execute method. * tree-pass.h (opt_pass::execute): Add function * argument. * asan.c, auto-inc-dec.c, bb-reorder.c, bt-load.c, cfgcleanup.c, cfgexpand.c, cfgrtl.c, cgraphbuild.c, combine-stack-adj.c, combine.c, compare-elim.c, config/arc/arc.c, config/epiphany/mode-switch-use.c, config/epiphany/resolve-sw-modes.c, config/i386/i386.c, config/mips/mips.c, config/rl78/rl78.c, config/s390/s390.c, config/sparc/sparc.c, cprop.c, dce.c, df-core.c, dse.c, dwarf2cfi.c, except.c, final.c, function.c, fwprop.c, gcse.c, gimple-low.c, gimple-ssa-isolate-paths.c, gimple-ssa-strength-reduction.c, graphite.c, ifcvt.c, init-regs.c, ipa-cp.c, ipa-devirt.c, ipa-inline-analysis.c, ipa-inline.c, ipa-profile.c, ipa-pure-const.c, ipa-reference.c, ipa-split.c, ipa.c, ira.c, jump.c, loop-init.c, lower-subreg.c, mode-switching.c, omp-low.c, postreload-gcse.c, postreload.c, predict.c, recog.c, ree.c, reg-stack.c, regcprop.c, reginfo.c, regrename.c, reorg.c, sched-rgn.c, stack-ptr-mod.c, store-motion.c, tracer.c, trans-mem.c, tree-call-cdce.c, tree-cfg.c, tree-cfgcleanup.c, tree-complex.c, tree-eh.c, tree-emutls.c, tree-if-conv.c, tree-into-ssa.c, tree-loop-distribution.c, tree-nrv.c, tree-object-size.c, tree-parloops.c, tree-predcom.c, tree-ssa-ccp.c, tree-ssa-copy.c, tree-ssa-copyrename.c, tree-ssa-dce.c, tree-ssa-dom.c, tree-ssa-dse.c, tree-ssa-forwprop.c, tree-ssa-ifcombine.c, tree-ssa-loop-ch.c, tree-ssa-loop-im.c, tree-ssa-loop-ivcanon.c, tree-ssa-loop-prefetch.c, tree-ssa-loop-unswitch.c, tree-ssa-loop.c, tree-ssa-math-opts.c, tree-ssa-phiopt.c, tree-ssa-phiprop.c, tree-ssa-pre.c, tree-ssa-reassoc.c, tree-ssa-sink.c, tree-ssa-strlen.c, tree-ssa-structalias.c, tree-ssa-uncprop.c, tree-ssa-uninit.c, tree-ssa.c, tree-ssanames.c, tree-stdarg.c, tree-switch-conversion.c, tree-tailcall.c, tree-vect-generic.c, tree-vectorizer.c, tree-vrp.c, tree.c, tsan.c, ubsan.c, var-tracking.c, vtable-verify.c, web.c: Adjust. From-SVN: r209482
2014-04-17 14:37:34 +02:00
{
GIMPLE_PASS, /* type */
"ubsan", /* name */
OPTGROUP_NONE, /* optinfo_flags */
TV_TREE_UBSAN, /* tv_id */
( PROP_cfg | PROP_ssa ), /* properties_required */
0, /* properties_provided */
0, /* properties_destroyed */
0, /* todo_flags_start */
TODO_update_ssa, /* todo_flags_finish */
};
class pass_ubsan : public gimple_opt_pass
pass cfun to pass::execute gcc/ * passes.c (opt_pass::execute): Adjust. (pass_manager::execute_pass_mode_switching): Likewise. (early_local_passes::execute): Likewise. (execute_one_pass): Pass cfun to the pass's execute method. * tree-pass.h (opt_pass::execute): Add function * argument. * asan.c, auto-inc-dec.c, bb-reorder.c, bt-load.c, cfgcleanup.c, cfgexpand.c, cfgrtl.c, cgraphbuild.c, combine-stack-adj.c, combine.c, compare-elim.c, config/arc/arc.c, config/epiphany/mode-switch-use.c, config/epiphany/resolve-sw-modes.c, config/i386/i386.c, config/mips/mips.c, config/rl78/rl78.c, config/s390/s390.c, config/sparc/sparc.c, cprop.c, dce.c, df-core.c, dse.c, dwarf2cfi.c, except.c, final.c, function.c, fwprop.c, gcse.c, gimple-low.c, gimple-ssa-isolate-paths.c, gimple-ssa-strength-reduction.c, graphite.c, ifcvt.c, init-regs.c, ipa-cp.c, ipa-devirt.c, ipa-inline-analysis.c, ipa-inline.c, ipa-profile.c, ipa-pure-const.c, ipa-reference.c, ipa-split.c, ipa.c, ira.c, jump.c, loop-init.c, lower-subreg.c, mode-switching.c, omp-low.c, postreload-gcse.c, postreload.c, predict.c, recog.c, ree.c, reg-stack.c, regcprop.c, reginfo.c, regrename.c, reorg.c, sched-rgn.c, stack-ptr-mod.c, store-motion.c, tracer.c, trans-mem.c, tree-call-cdce.c, tree-cfg.c, tree-cfgcleanup.c, tree-complex.c, tree-eh.c, tree-emutls.c, tree-if-conv.c, tree-into-ssa.c, tree-loop-distribution.c, tree-nrv.c, tree-object-size.c, tree-parloops.c, tree-predcom.c, tree-ssa-ccp.c, tree-ssa-copy.c, tree-ssa-copyrename.c, tree-ssa-dce.c, tree-ssa-dom.c, tree-ssa-dse.c, tree-ssa-forwprop.c, tree-ssa-ifcombine.c, tree-ssa-loop-ch.c, tree-ssa-loop-im.c, tree-ssa-loop-ivcanon.c, tree-ssa-loop-prefetch.c, tree-ssa-loop-unswitch.c, tree-ssa-loop.c, tree-ssa-math-opts.c, tree-ssa-phiopt.c, tree-ssa-phiprop.c, tree-ssa-pre.c, tree-ssa-reassoc.c, tree-ssa-sink.c, tree-ssa-strlen.c, tree-ssa-structalias.c, tree-ssa-uncprop.c, tree-ssa-uninit.c, tree-ssa.c, tree-ssanames.c, tree-stdarg.c, tree-switch-conversion.c, tree-tailcall.c, tree-vect-generic.c, tree-vectorizer.c, tree-vrp.c, tree.c, tsan.c, ubsan.c, var-tracking.c, vtable-verify.c, web.c: Adjust. From-SVN: r209482
2014-04-17 14:37:34 +02:00
{
public:
pass_ubsan (gcc::context *ctxt)
: gimple_opt_pass (pass_data_ubsan, ctxt)
{}
/* opt_pass methods: */
virtual bool gate (function *)
{
return flag_sanitize & (SANITIZE_NULL | SANITIZE_SI_OVERFLOW
opts.c (common_handle_option): Handle -fsanitize=alignment. * opts.c (common_handle_option): Handle -fsanitize=alignment. * ubsan.h (enum ubsan_null_ckind): Add UBSAN_CTOR_CALL. (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn): Change return type to bool. * stor-layout.h (min_align_of_type): New prototype. * asan.c (pass_sanopt::execute): Don't perform gsi_next if ubsan_expand* told us not to do it. Remove the extra gsi_end_p check. * ubsan.c: Include builtins.h. (ubsan_expand_bounds_ifn): Change return type to bool, always return true. (ubsan_expand_null_ifn): Change return type to bool, change argument to gimple_stmt_iterator *. Handle both null and alignment sanitization, take type from ckind argument's type rather than first argument. (instrument_member_call): Removed. (instrument_mem_ref): Remove t argument, add mem and base arguments. Handle both null and alignment sanitization, don't say whole struct access is member access. Build 3 argument IFN_UBSAN_NULL call instead of 2 argument. (instrument_null): Adjust instrument_mem_ref caller. Don't instrument calls here. (pass_ubsan::gate, pass_ubsan::execute): Handle SANITIZE_ALIGNMENT like SANITIZE_NULL. * stor-layout.c (min_align_of_type): New function. * flag-types.h (enum sanitize_code): Add SANITIZE_ALIGNMENT. Or it into SANITIZE_UNDEFINED. * doc/invoke.texi (-fsanitize=alignment): Document. cp/ * cp-gimplify.c (cp_genericize_r): For -fsanitize=null and/or -fsanitize=alignment call ubsan_maybe_instrument_reference for casts to REFERENCE_TYPE and ubsan_maybe_instrument_member_call for calls to member functions. c-family/ * c-common.h (min_align_of_type): Removed prototype. * c-common.c (min_align_of_type): Removed. * c-ubsan.h (ubsan_maybe_instrument_reference, ubsan_maybe_instrument_member_call): New prototypes. * c-ubsan.c: Include stor-layout.h and builtins.h. (ubsan_maybe_instrument_reference_or_call, ubsan_maybe_instrument_reference, ubsan_maybe_instrument_call): New functions. testsuite/ * c-c++-common/ubsan/align-1.c: New test. * c-c++-common/ubsan/align-2.c: New test. * c-c++-common/ubsan/align-3.c: New test. * c-c++-common/ubsan/align-4.c: New test. * c-c++-common/ubsan/align-5.c: New test. * c-c++-common/ubsan/attrib-4.c: New test. * g++.dg/ubsan/align-1.C: New test. * g++.dg/ubsan/align-2.C: New test. * g++.dg/ubsan/align-3.C: New test. * g++.dg/ubsan/attrib-1.C: New test. * g++.dg/ubsan/null-1.C: New test. * g++.dg/ubsan/null-2.C: New test. From-SVN: r213406
2014-08-01 09:52:43 +02:00
| SANITIZE_BOOL | SANITIZE_ENUM
| SANITIZE_ALIGNMENT
| SANITIZE_NONNULL_ATTRIBUTE
| SANITIZE_RETURNS_NONNULL_ATTRIBUTE
| SANITIZE_OBJECT_SIZE)
&& do_ubsan_in_current_function ();
pass cfun to pass::execute gcc/ * passes.c (opt_pass::execute): Adjust. (pass_manager::execute_pass_mode_switching): Likewise. (early_local_passes::execute): Likewise. (execute_one_pass): Pass cfun to the pass's execute method. * tree-pass.h (opt_pass::execute): Add function * argument. * asan.c, auto-inc-dec.c, bb-reorder.c, bt-load.c, cfgcleanup.c, cfgexpand.c, cfgrtl.c, cgraphbuild.c, combine-stack-adj.c, combine.c, compare-elim.c, config/arc/arc.c, config/epiphany/mode-switch-use.c, config/epiphany/resolve-sw-modes.c, config/i386/i386.c, config/mips/mips.c, config/rl78/rl78.c, config/s390/s390.c, config/sparc/sparc.c, cprop.c, dce.c, df-core.c, dse.c, dwarf2cfi.c, except.c, final.c, function.c, fwprop.c, gcse.c, gimple-low.c, gimple-ssa-isolate-paths.c, gimple-ssa-strength-reduction.c, graphite.c, ifcvt.c, init-regs.c, ipa-cp.c, ipa-devirt.c, ipa-inline-analysis.c, ipa-inline.c, ipa-profile.c, ipa-pure-const.c, ipa-reference.c, ipa-split.c, ipa.c, ira.c, jump.c, loop-init.c, lower-subreg.c, mode-switching.c, omp-low.c, postreload-gcse.c, postreload.c, predict.c, recog.c, ree.c, reg-stack.c, regcprop.c, reginfo.c, regrename.c, reorg.c, sched-rgn.c, stack-ptr-mod.c, store-motion.c, tracer.c, trans-mem.c, tree-call-cdce.c, tree-cfg.c, tree-cfgcleanup.c, tree-complex.c, tree-eh.c, tree-emutls.c, tree-if-conv.c, tree-into-ssa.c, tree-loop-distribution.c, tree-nrv.c, tree-object-size.c, tree-parloops.c, tree-predcom.c, tree-ssa-ccp.c, tree-ssa-copy.c, tree-ssa-copyrename.c, tree-ssa-dce.c, tree-ssa-dom.c, tree-ssa-dse.c, tree-ssa-forwprop.c, tree-ssa-ifcombine.c, tree-ssa-loop-ch.c, tree-ssa-loop-im.c, tree-ssa-loop-ivcanon.c, tree-ssa-loop-prefetch.c, tree-ssa-loop-unswitch.c, tree-ssa-loop.c, tree-ssa-math-opts.c, tree-ssa-phiopt.c, tree-ssa-phiprop.c, tree-ssa-pre.c, tree-ssa-reassoc.c, tree-ssa-sink.c, tree-ssa-strlen.c, tree-ssa-structalias.c, tree-ssa-uncprop.c, tree-ssa-uninit.c, tree-ssa.c, tree-ssanames.c, tree-stdarg.c, tree-switch-conversion.c, tree-tailcall.c, tree-vect-generic.c, tree-vectorizer.c, tree-vrp.c, tree.c, tsan.c, ubsan.c, var-tracking.c, vtable-verify.c, web.c: Adjust. From-SVN: r209482
2014-04-17 14:37:34 +02:00
}
virtual unsigned int execute (function *);
}; // class pass_ubsan
unsigned int
pass_ubsan::execute (function *fun)
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
{
basic_block bb;
gimple_stmt_iterator gsi;
unsigned int ret = 0;
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
initialize_sanitizer_builtins ();
pass cfun to pass::execute gcc/ * passes.c (opt_pass::execute): Adjust. (pass_manager::execute_pass_mode_switching): Likewise. (early_local_passes::execute): Likewise. (execute_one_pass): Pass cfun to the pass's execute method. * tree-pass.h (opt_pass::execute): Add function * argument. * asan.c, auto-inc-dec.c, bb-reorder.c, bt-load.c, cfgcleanup.c, cfgexpand.c, cfgrtl.c, cgraphbuild.c, combine-stack-adj.c, combine.c, compare-elim.c, config/arc/arc.c, config/epiphany/mode-switch-use.c, config/epiphany/resolve-sw-modes.c, config/i386/i386.c, config/mips/mips.c, config/rl78/rl78.c, config/s390/s390.c, config/sparc/sparc.c, cprop.c, dce.c, df-core.c, dse.c, dwarf2cfi.c, except.c, final.c, function.c, fwprop.c, gcse.c, gimple-low.c, gimple-ssa-isolate-paths.c, gimple-ssa-strength-reduction.c, graphite.c, ifcvt.c, init-regs.c, ipa-cp.c, ipa-devirt.c, ipa-inline-analysis.c, ipa-inline.c, ipa-profile.c, ipa-pure-const.c, ipa-reference.c, ipa-split.c, ipa.c, ira.c, jump.c, loop-init.c, lower-subreg.c, mode-switching.c, omp-low.c, postreload-gcse.c, postreload.c, predict.c, recog.c, ree.c, reg-stack.c, regcprop.c, reginfo.c, regrename.c, reorg.c, sched-rgn.c, stack-ptr-mod.c, store-motion.c, tracer.c, trans-mem.c, tree-call-cdce.c, tree-cfg.c, tree-cfgcleanup.c, tree-complex.c, tree-eh.c, tree-emutls.c, tree-if-conv.c, tree-into-ssa.c, tree-loop-distribution.c, tree-nrv.c, tree-object-size.c, tree-parloops.c, tree-predcom.c, tree-ssa-ccp.c, tree-ssa-copy.c, tree-ssa-copyrename.c, tree-ssa-dce.c, tree-ssa-dom.c, tree-ssa-dse.c, tree-ssa-forwprop.c, tree-ssa-ifcombine.c, tree-ssa-loop-ch.c, tree-ssa-loop-im.c, tree-ssa-loop-ivcanon.c, tree-ssa-loop-prefetch.c, tree-ssa-loop-unswitch.c, tree-ssa-loop.c, tree-ssa-math-opts.c, tree-ssa-phiopt.c, tree-ssa-phiprop.c, tree-ssa-pre.c, tree-ssa-reassoc.c, tree-ssa-sink.c, tree-ssa-strlen.c, tree-ssa-structalias.c, tree-ssa-uncprop.c, tree-ssa-uninit.c, tree-ssa.c, tree-ssanames.c, tree-stdarg.c, tree-switch-conversion.c, tree-tailcall.c, tree-vect-generic.c, tree-vectorizer.c, tree-vrp.c, tree.c, tsan.c, ubsan.c, var-tracking.c, vtable-verify.c, web.c: Adjust. From-SVN: r209482
2014-04-17 14:37:34 +02:00
FOR_EACH_BB_FN (bb, fun)
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
{
for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi);)
{
gimple *stmt = gsi_stmt (gsi);
if (is_gimple_debug (stmt) || gimple_clobber_p (stmt))
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
{
gsi_next (&gsi);
continue;
}
if ((flag_sanitize & SANITIZE_SI_OVERFLOW)
&& is_gimple_assign (stmt))
instrument_si_overflow (gsi);
opts.c (common_handle_option): Handle -fsanitize=alignment. * opts.c (common_handle_option): Handle -fsanitize=alignment. * ubsan.h (enum ubsan_null_ckind): Add UBSAN_CTOR_CALL. (ubsan_expand_bounds_ifn, ubsan_expand_null_ifn): Change return type to bool. * stor-layout.h (min_align_of_type): New prototype. * asan.c (pass_sanopt::execute): Don't perform gsi_next if ubsan_expand* told us not to do it. Remove the extra gsi_end_p check. * ubsan.c: Include builtins.h. (ubsan_expand_bounds_ifn): Change return type to bool, always return true. (ubsan_expand_null_ifn): Change return type to bool, change argument to gimple_stmt_iterator *. Handle both null and alignment sanitization, take type from ckind argument's type rather than first argument. (instrument_member_call): Removed. (instrument_mem_ref): Remove t argument, add mem and base arguments. Handle both null and alignment sanitization, don't say whole struct access is member access. Build 3 argument IFN_UBSAN_NULL call instead of 2 argument. (instrument_null): Adjust instrument_mem_ref caller. Don't instrument calls here. (pass_ubsan::gate, pass_ubsan::execute): Handle SANITIZE_ALIGNMENT like SANITIZE_NULL. * stor-layout.c (min_align_of_type): New function. * flag-types.h (enum sanitize_code): Add SANITIZE_ALIGNMENT. Or it into SANITIZE_UNDEFINED. * doc/invoke.texi (-fsanitize=alignment): Document. cp/ * cp-gimplify.c (cp_genericize_r): For -fsanitize=null and/or -fsanitize=alignment call ubsan_maybe_instrument_reference for casts to REFERENCE_TYPE and ubsan_maybe_instrument_member_call for calls to member functions. c-family/ * c-common.h (min_align_of_type): Removed prototype. * c-common.c (min_align_of_type): Removed. * c-ubsan.h (ubsan_maybe_instrument_reference, ubsan_maybe_instrument_member_call): New prototypes. * c-ubsan.c: Include stor-layout.h and builtins.h. (ubsan_maybe_instrument_reference_or_call, ubsan_maybe_instrument_reference, ubsan_maybe_instrument_call): New functions. testsuite/ * c-c++-common/ubsan/align-1.c: New test. * c-c++-common/ubsan/align-2.c: New test. * c-c++-common/ubsan/align-3.c: New test. * c-c++-common/ubsan/align-4.c: New test. * c-c++-common/ubsan/align-5.c: New test. * c-c++-common/ubsan/attrib-4.c: New test. * g++.dg/ubsan/align-1.C: New test. * g++.dg/ubsan/align-2.C: New test. * g++.dg/ubsan/align-3.C: New test. * g++.dg/ubsan/attrib-1.C: New test. * g++.dg/ubsan/null-1.C: New test. * g++.dg/ubsan/null-2.C: New test. From-SVN: r213406
2014-08-01 09:52:43 +02:00
if (flag_sanitize & (SANITIZE_NULL | SANITIZE_ALIGNMENT))
{
if (gimple_store_p (stmt))
instrument_null (gsi, true);
if (gimple_assign_load_p (stmt))
instrument_null (gsi, false);
}
if (flag_sanitize & (SANITIZE_BOOL | SANITIZE_ENUM)
&& gimple_assign_load_p (stmt))
{
instrument_bool_enum_load (&gsi);
bb = gimple_bb (stmt);
}
if ((flag_sanitize & SANITIZE_NONNULL_ATTRIBUTE)
&& is_gimple_call (stmt)
&& !gimple_call_internal_p (stmt))
{
instrument_nonnull_arg (&gsi);
bb = gimple_bb (stmt);
}
if ((flag_sanitize & SANITIZE_RETURNS_NONNULL_ATTRIBUTE)
&& gimple_code (stmt) == GIMPLE_RETURN)
{
instrument_nonnull_return (&gsi);
bb = gimple_bb (stmt);
}
if (flag_sanitize & SANITIZE_OBJECT_SIZE)
{
if (gimple_store_p (stmt))
instrument_object_size (&gsi, true);
if (gimple_assign_load_p (stmt))
instrument_object_size (&gsi, false);
}
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
gsi_next (&gsi);
}
if (gimple_purge_dead_eh_edges (bb))
ret = TODO_cleanup_cfg;
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
}
return ret;
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
}
} // anon namespace
bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. config/ * bootstrap-ubsan.mk (POSTSTAGE1_LDFLAGS): Add -ldl. gcc/c-family/ * c-ubsan.c (ubsan_instrument_division): Adjust ubsan_create_data call. (ubsan_instrument_shift): Likewise. (ubsan_instrument_vla): Likewise. gcc/ * opts.c (common_handle_option): Add -fsanitize=null option. Turn off -fdelete-null-pointer-checks option when doing the NULL pointer checking. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH): Add. * tree-pass.h (make_pass_ubsan): Declare. (make_pass_sanopt): Declare. * timevar.def (TV_TREE_UBSAN): New timevar. * passes.def: Add pass_sanopt and pass_ubsan. * ubsan.h (ubsan_null_ckind): New enum. (ubsan_mismatch_data): New struct. (ubsan_expand_null_ifn): Declare. (ubsan_create_data): Adjust declaration. (ubsan_type_descriptor): Likewise. * asan.c: Include "ubsan.h". (pass_data_sanopt): New pass. (execute_sanopt): New function. (gate_sanopt): Likewise. (make_pass_sanopt): Likewise. (class pass_sanopt): New class. * ubsan.c: Include tree-pass.h, gimple-ssa.h, gimple-walk.h, gimple-iterator.h and cfgloop.h. (PROB_VERY_UNLIKELY): Define. (tree_type_map_hash): New function. (ubsan_type_descriptor): Add new parameter. Improve type name generation. (ubsan_create_data): Add new parameter. Add pointer data into ubsan structure. (ubsan_expand_null_ifn): New function. (instrument_member_call): Likewise. (instrument_mem_ref): Likewise. (instrument_null): Likewise. (ubsan_pass): Likewise. (gate_ubsan): Likewise. (make_pass_ubsan): Likewise. (ubsan_instrument_unreachable): Adjust ubsan_create_data call. (class pass_ubsan): New class. (pass_data_ubsan): New pass. * flag-types.h (enum sanitize_code): Add SANITIZE_NULL. * internal-fn.c (expand_UBSAN_NULL): New function. * cgraphunit.c (varpool_finalize_decl): Call varpool_assemble_decl even when !flag_toplevel_reorder. * internal-fn.def (UBSAN_NULL): New. gcc/testsuite/ * c-c++-common/ubsan/null-1.c: New test. * c-c++-common/ubsan/null-2.c: New test. * c-c++-common/ubsan/null-3.c: New test. * c-c++-common/ubsan/null-4.c: New test. * c-c++-common/ubsan/null-5.c: New test. * c-c++-common/ubsan/null-6.c: New test. * c-c++-common/ubsan/null-7.c: New test. * c-c++-common/ubsan/null-8.c: New test. * c-c++-common/ubsan/null-9.c: New test. * c-c++-common/ubsan/null-10.c: New test. * c-c++-common/ubsan/null-11.c: New test. * gcc.dg/ubsan/c99-shift-2.c: Adjust dg-output. * c-c++-common/ubsan/shift-1.c: Likewise. * c-c++-common/ubsan/div-by-zero-3.c: Likewise. From-SVN: r205021
2013-11-19 12:45:15 +01:00
gimple_opt_pass *
make_pass_ubsan (gcc::context *ctxt)
{
return new pass_ubsan (ctxt);
}
#include "gt-ubsan.h"