memory: make is_writable() always true if there are no global constants
MODIFY
ir/globals.cpp
ir/globals.cpp
@@ -14,6 +14,7 @@ unsigned bits_size_t;
unsigned bits_byte;
bool little_endian;
bool nullptr_is_used;
+bool has_global_const;
bool has_int2ptr;
bool has_ptr2int;
bool has_malloc;

MODIFY
ir/globals.h
ir/globals.h
@@ -31,6 +31,8 @@ extern bool little_endian;
/// Whether the null pointer is used in either function
extern bool nullptr_is_used;
+extern bool has_global_const;
+
/// Whether int2ptr or ptr2int are used in either function
extern bool has_int2ptr;
extern bool has_ptr2int;

MODIFY
ir/memory.cpp
ir/memory.cpp
@@ -533,6 +533,8 @@ expr Pointer::block_refined(const Pointer &other) const {
}
expr Pointer::is_writable() const {
+ if (!has_global_const)
+ return true;
return get_value("blk_writable", FunctionExpr(true), m.non_local_blk_writable,
true);
}
@@ -813,6 +815,7 @@ expr Memory::alloc(const expr &size, unsigned align, BlockKind blockKind,
local_avail_space);
} else {
+ assert(has_global_const || blockKind != CONSTGLOBAL);
state->addAxiom(blockKind == CONSTGLOBAL ? !p.is_writable()
: p.is_writable());
non_local_block_liveness

MODIFY
tests/alive-tv/memory-opt/bwiden-calloc.src.ll
tests/alive-tv/memory-opt/bwiden-calloc.src.ll
-; TEST-ARGS: -disable-undef-input -dbg
-; -disable-undef-input was given to address timeout.
+; TEST-ARGS: -dbg
define i32 @calloc_init(i32 %x) {
%ptr0 = call noalias i8* @calloc(i64 1, i64 4)

MODIFY
tests/alive-tv/memory/gep-struct2.src.ll
tests/alive-tv/memory/gep-struct2.src.ll
-; TEST-ARGS: -smt-to=2000
target datalayout = "e-i32:32-i128:32-i8:8"
%0 = type [10 x { i32, i128, [5 x { i32, i8, i8 }] }]

MODIFY
tests/alive-tv/memory/pre-bigendian.src.ll
tests/alive-tv/memory/pre-bigendian.src.ll
; This was excerpted from GVN/PRE/rle.ll
-; TEST-ARGS: -smt-to=2000
target datalayout = "E-p:32:32:32-p1:16:16:16-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-n32"
define i8 @coerce_mustalias_pre0(i16* %P, i1 %cond) {

MODIFY
tests/alive-tv/memory/punning-floatint.src.ll
tests/alive-tv/memory/punning-floatint.src.ll
-; TEST-ARGS: -smt-to=9000
-
define float @float_int_punning(float %f) {
%ptr = alloca i32
%if = bitcast float %f to i32

MODIFY
tests/alive-tv/memory/punning-intptr.src.ll
tests/alive-tv/memory/punning-intptr.src.ll
-; TEST-ARGS: -smt-to=9000 -disable-undef-input
-
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
define i8* @int_ptr_punning(i8* %ptr, i64 %n) {

MODIFY
tests/alive-tv/memory/punning-ptrint.src.ll
tests/alive-tv/memory/punning-ptrint.src.ll
-; TEST-ARGS: -disable-undef-input -smt-to=10000
-
define i8 @ptr_int_punning(i8** %pptr, i64 %n) {
%ptr = alloca i8
store i8* %ptr, i8** %pptr

MODIFY
tools/transform.cpp
tools/transform.cpp
@@ -464,6 +464,7 @@ static void calculateAndInitConstants(Transform &t) {
num_locals = max(num_locals_src, num_locals_tgt);
nullptr_is_used = false;
+ has_global_const = false;
has_int2ptr = false;
has_ptr2int = false;
has_malloc = false;
@@ -474,6 +475,12 @@ static void calculateAndInitConstants(Transform &t) {
bool does_mem_access = false;
for (auto fn : { &t.src, &t.tgt }) {
+ for (auto &c : fn->getConstants()) {
+ if (auto gv = dynamic_cast<const GlobalVariable*>(&c)) {
+ has_global_const |= gv->isConst();
+ }
+ }
+
for (auto BB : fn->getBBs()) {
for (auto &I : BB->instrs()) {
for (auto op : I.operands()) {

memory: make is_writable() always true if there are no global constants