From 47c86d46a329ee2c4c26a82b29edd40bb4b4c35c Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Mon, 6 May 2019 17:26:08 +0200 Subject: Check for alignment of command-line switches. Add a check for alignment on command-line switches `-falign-*`. The check is similar to the one for the alignment attribute and ensures that only powers of two can be specified. --- doc/ccomp.1 | 6 +++--- driver/Driver.ml | 10 +++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/doc/ccomp.1 b/doc/ccomp.1 index 374bd2e7..36fe4e7b 100644 --- a/doc/ccomp.1 +++ b/doc/ccomp.1 @@ -191,12 +191,12 @@ Code Generation Options (PowerPC) .TP .B \-falign\-branch\-targets Set alignment of branch targets to bytes. -The default alignment is 0 bytes, which deactivates alignment of branch targets. +By default alignment of branch targets is deactivated. . .TP .B \-falign\-cond\-branches -Set alignment of conditional branches to bytes. -The default alignment is 0 bytes, which deactivates alignment of conditional branch targets. +Set alignment of conditional branch instructions to bytes. +By default alignment of conditional branches is deactivated. . .SS Code Generation Options (PowerPC with Diab Backend) diff --git a/driver/Driver.ml b/driver/Driver.ml index 8ab8557c..5f7d0b20 100644 --- a/driver/Driver.ml +++ b/driver/Driver.ml @@ -262,6 +262,10 @@ let num_input_files = ref 0 let cmdline_actions = let f_opt name ref = [Exact("-f" ^ name), Set ref; Exact("-fno-" ^ name), Unset ref] in + let check_align n = + if n <= 0 || ((n land (n - 1)) <> 0) then + error no_loc "requested alignment %d is not a power of 2" n + in [ (* Getting help *) Exact "-help", Unit print_usage_and_exit; @@ -297,9 +301,9 @@ let cmdline_actions = Exact "-fsmall-data", Integer(fun n -> option_small_data := n); Exact "-fsmall-const", Integer(fun n -> option_small_const := n); Exact "-ffloat-const-prop", Integer(fun n -> option_ffloatconstprop := n); - Exact "-falign-functions", Integer(fun n -> option_falignfunctions := Some n); - Exact "-falign-branch-targets", Integer(fun n -> option_falignbranchtargets := n); - Exact "-falign-cond-branches", Integer(fun n -> option_faligncondbranchs := n);] @ + Exact "-falign-functions", Integer(fun n -> check_align n; option_falignfunctions := Some n); + Exact "-falign-branch-targets", Integer(fun n -> check_align n; option_falignbranchtargets := n); + Exact "-falign-cond-branches", Integer(fun n -> check_align n; option_faligncondbranchs := n);] @ (* Target processor options *) (if Configuration.arch = "arm" then if Configuration.model = "armv6" then -- cgit