aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/hipe/hipe_bif0.c
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2016-05-26 14:36:52 +0200
committerSverker Eriksson <[email protected]>2016-05-26 14:36:52 +0200
commit89adc0eec23c1a3ac552650004863de4cf82422e (patch)
tree141a582f3f52290cb07cfd797d8295fc2f094d58 /erts/emulator/hipe/hipe_bif0.c
parent4d7b24dcb8f10ea8ddaa002601916fb389f0e87e (diff)
parent8914b835d26cc3b513eaef0a19cd9b39d1d2ccae (diff)
downloadotp-89adc0eec23c1a3ac552650004863de4cf82422e.tar.gz
otp-89adc0eec23c1a3ac552650004863de4cf82422e.tar.bz2
otp-89adc0eec23c1a3ac552650004863de4cf82422e.zip
Merge branch 'margnus1/llvm-compatibility/PR-1057/OTP-13626'
Diffstat (limited to 'erts/emulator/hipe/hipe_bif0.c')
-rw-r--r--erts/emulator/hipe/hipe_bif0.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/erts/emulator/hipe/hipe_bif0.c b/erts/emulator/hipe/hipe_bif0.c
index 4063cbf306..58b5be3906 100644
--- a/erts/emulator/hipe/hipe_bif0.c
+++ b/erts/emulator/hipe/hipe_bif0.c
@@ -418,6 +418,8 @@ BIF_RETTYPE hipe_bifs_enter_code_2(BIF_ALIST_2)
BIF_RET(make_tuple(hp));
}
+#define IS_POWER_OF_TWO(Val) (((Val) > 0) && (((Val) & ((Val)-1)) == 0))
+
/*
* Allocate memory for arbitrary non-Erlang data.
*/
@@ -427,16 +429,18 @@ BIF_RETTYPE hipe_bifs_alloc_data_2(BIF_ALIST_2)
void *block;
if (is_not_small(BIF_ARG_1) || is_not_small(BIF_ARG_2) ||
- (align = unsigned_val(BIF_ARG_1),
- align != sizeof(long) && align != sizeof(double)))
+ (align = unsigned_val(BIF_ARG_1), !IS_POWER_OF_TWO(align)))
BIF_ERROR(BIF_P, BADARG);
nrbytes = unsigned_val(BIF_ARG_2);
if (nrbytes == 0)
BIF_RET(make_small(0));
block = erts_alloc(ERTS_ALC_T_HIPE, nrbytes);
- if ((unsigned long)block & (align-1))
+ if ((unsigned long)block & (align-1)) {
fprintf(stderr, "%s: erts_alloc(%lu) returned %p which is not %lu-byte aligned\r\n",
__FUNCTION__, (unsigned long)nrbytes, block, (unsigned long)align);
+ erts_free(ERTS_ALC_T_HIPE, block);
+ BIF_ERROR(BIF_P, EXC_NOTSUP);
+ }
BIF_RET(address_to_term(block, BIF_P));
}