aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Schommer <bernhardschommer@gmail.com>2019-05-06 17:26:08 +0200
committerXavier Leroy <xavierleroy@users.noreply.github.com>2019-05-10 14:27:22 +0200
commit47c86d46a329ee2c4c26a82b29edd40bb4b4c35c (patch)
tree54877aacf7effd308faab225320bfcfc9ecd3af3
parent46e5d165e6277d7502fe4a45e8765526a1117414 (diff)
downloadcompcert-47c86d46a329ee2c4c26a82b29edd40bb4b4c35c.tar.gz
compcert-47c86d46a329ee2c4c26a82b29edd40bb4b4c35c.zip
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.
-rw-r--r--doc/ccomp.16
-rw-r--r--driver/Driver.ml10
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 <n>
Set alignment of branch targets to <n> 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 <n>
-Set alignment of conditional branches to <n> bytes.
-The default alignment is 0 bytes, which deactivates alignment of conditional branch targets.
+Set alignment of conditional branch instructions to <n> 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