duktape: Errors when compiling with -fsanitize=undefined

Using Duktape 1.5.0 and GCC 6.1.0 on OSX:

duk_hthread_builtins.c:313:3: runtime error: left shift of 31 by 27 places cannot be represented in type 'int'
duk_hobject_props.c:829:14: runtime error: load of misaligned address 0x7fe62c013f8f for type 'duk_uint32_t', which requires 4 byte alignment
0x7fe62c013f8f: note: pointer points here
 ff ff ff ff ff  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  ff ff ff
             ^
duk_hobject_props.c:831:15: runtime error: store to misaligned address 0x7fe62c013f8f for type 'duk_uint32_t', which requires 4 byte alignment
0x7fe62c013f8f: note: pointer points here
 ff ff ff ff ff  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  ff ff ff
             ^
duk_hobject_props.c:1298:17: runtime error: load of misaligned address 0x7fe62c013fd3 for type 'duk_uint32_t', which requires 4 byte alignment
0x7fe62c013fd3: note: pointer points here
 ff  ff ff ff 17 00 00 00 14  00 00 00 ff ff ff ff 03  00 00 00 1a 00 00 00 ff  ff ff ff 0d 00 00 00
              ^
duk_hobject_props.c:1306:15: runtime error: store to misaligned address 0x7fe62c01400b for type 'duk_uint32_t', which requires 4 byte alignment
0x7fe62c01400b: note: pointer points here
 13  00 00 00 ff ff ff ff 04  00 00 00 07 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00
              ^
duk_hobject_props.c:1160:6: runtime error: load of misaligned address 0x7fe62c013fa7 for type 'duk_uint32_t', which requires 4 byte alignment
0x7fe62c013fa7: note: pointer points here
 0b 00 00 00 05  00 00 00 0a 00 00 00 1c  00 00 00 ff ff ff ff 0c  00 00 00 ff ff ff ff ff  ff ff ff
             ^
duk_hobject_props.c:775:4: runtime error: member access within misaligned address 0x7fe62bd14ec2 for type 'struct duk_tval', which requires 8 byte alignment
0x7fe62bd14ec2: note: pointer points here
 00 00  01 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00
              ^
duk_hobject_props.c:3958:3: runtime error: store to misaligned address 0x7fe62bd14ec2 for type 'struct duk_tval', which requires 8 byte alignment
0x7fe62bd14ec2: note: pointer points here
 00 00  01 00 07 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 07 00 00 00 00 00  00 00 00 00 00 00
              ^
duk_hobject_props.c:3959:3: runtime error: member access within misaligned address 0x7fe62bd14ec2 for type 'struct duk_tval', which requires 8 byte alignment
0x7fe62bd14ec2: note: pointer points here
 00 00  01 00 08 00 00 00 e6 7f  00 00 80 4d d1 2b e6 7f  00 00 07 00 00 00 00 00  00 00 00 00 00 00
              ^
duk_hobject_props.c:3959:3: runtime error: member access within misaligned address 0x7fe62bd14ec2 for type 'struct duk_tval', which requires 8 byte alignment
0x7fe62bd14ec2: note: pointer points here
 00 00  01 00 08 00 00 00 e6 7f  00 00 80 4d d1 2b e6 7f  00 00 07 00 00 00 00 00  00 00 00 00 00 00
              ^
duk_hobject_props.c:2092:2: runtime error: member access within misaligned address 0x7fe62bd14ed2 for type 'struct duk_tval', which requires 8 byte alignment
0x7fe62bd14ed2: note: pointer points here
 e6 7f  00 00 07 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00
              ^
duk_hobject_props.c:2092:2: runtime error: store to misaligned address 0x7fe62bd14ed2 for type 'struct duk_tval', which requires 8 byte alignment
0x7fe62bd14ed2: note: pointer points here
 e6 7f  00 00 07 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00
              ^
duk_js_ops.c:582:39: runtime error: member access within misaligned address 0x7fe62bd15242 for type 'struct duk_tval', which requires 8 byte alignment
0x7fe62bd15242: note: pointer points here
 00 00  01 00 08 00 00 00 fe ff  ff ff 60 00 c0 2b e6 7f  00 00 07 00 00 00 00 00  00 00 00 00 00 00
              ^
duk_js_ops.c:597:41: runtime error: member access within misaligned address 0x7fe62bd15242 for type 'struct duk_tval', which requires 8 byte alignment
0x7fe62bd15242: note: pointer points here
 00 00  01 00 08 00 00 00 fe ff  ff ff 60 00 c0 2b e6 7f  00 00 07 00 00 00 00 00  00 00 00 00 00 00
              ^
duk_hobject_props.c:3001:4: runtime error: load of misaligned address 0x7fe62bd154e2 for type 'struct duk_tval', which requires 8 byte alignment
0x7fe62bd154e2: note: pointer points here
 e6 7f  00 00 08 00 00 00 ff 7f  00 00 f0 09 c0 2b e6 7f  00 00 00 00 00 00 00 00  00 00 00 00 00 00
              ^
duk_hobject_props.c:3001:4: runtime error: member access within misaligned address 0x7fe62bd154e2 for type 'struct duk_tval', which requires 8 byte alignment
0x7fe62bd154e2: note: pointer points here
 e6 7f  00 00 08 00 00 00 ff 7f  00 00 f0 09 c0 2b e6 7f  00 00 00 00 00 00 00 00  00 00 00 00 00 00
              ^
duk_hobject_props.c:2027:7: runtime error: member access within misaligned address 0x7fe62bd152d2 for type 'struct duk_tval', which requires 8 byte alignment
0x7fe62bd152d2: note: pointer points here
 00 00  01 00 08 00 00 00 00 00  00 00 e0 0e c0 2b e6 7f  00 00 08 00 00 00 39 00  00 00 10 13 c0 2b
              ^
duk_api_stack.c:2971:2: runtime error: load of misaligned address 0x7fe62bd152d2 for type 'struct duk_tval', which requires 8 byte alignment
0x7fe62bd152d2: note: pointer points here
 00 00  01 00 08 00 00 00 00 00  00 00 e0 0e c0 2b e6 7f  00 00 08 00 00 00 39 00  00 00 10 13 c0 2b
              ^
duk_api_stack.c:2972:2: runtime error: member access within misaligned address 0x7fe62bd152d2 for type 'struct duk_tval', which requires 8 byte alignment
0x7fe62bd152d2: note: pointer points here
 00 00  01 00 08 00 00 00 00 00  00 00 e0 0e c0 2b e6 7f  00 00 08 00 00 00 39 00  00 00 10 13 c0 2b
              ^
duk_api_stack.c:2972:2: runtime error: member access within misaligned address 0x7fe62bd152d2 for type 'struct duk_tval', which requires 8 byte alignment
0x7fe62bd152d2: note: pointer points here
 00 00  01 00 08 00 00 00 00 00  00 00 e0 0e c0 2b e6 7f  00 00 08 00 00 00 39 00  00 00 10 13 c0 2b
              ^
duk_js_compiler.c:744:3: runtime error: load of misaligned address 0x7fe62bd15472 for type 'struct duk_tval', which requires 8 byte alignment
0x7fe62bd15472: note: pointer points here
 00 00  01 00 08 00 00 00 fe ff  ff ff 60 00 c0 2b e6 7f  00 00 08 00 00 00 ff 7f  00 00 60 09 c0 2b
              ^
duk_js_compiler.c:746:3: runtime error: member access within misaligned address 0x7fe62bd15472 for type 'struct duk_tval', which requires 8 byte alignment
0x7fe62bd15472: note: pointer points here
 00 00  01 00 08 00 00 00 fe ff  ff ff 60 00 c0 2b e6 7f  00 00 08 00 00 00 ff 7f  00 00 60 09 c0 2b
              ^
duk_js_compiler.c:746:3: runtime error: member access within misaligned address 0x7fe62bd15472 for type 'struct duk_tval', which requires 8 byte alignment
0x7fe62bd15472: note: pointer points here
 00 00  01 00 08 00 00 00 fe ff  ff ff 60 00 c0 2b e6 7f  00 00 08 00 00 00 ff 7f  00 00 60 09 c0 2b
              ^
duk_heap_refcount.c:522:6: runtime error: member access within misaligned address 0x7fe62bd15472 for type 'struct duk_tval', which requires 8 byte alignment
0x7fe62bd15472: note: pointer points here
 00 00  01 00 08 00 00 00 fe ff  ff ff 60 00 c0 2b e6 7f  00 00 08 00 00 00 ff 7f  00 00 60 09 c0 2b
              ^
duk_heap_refcount.c:523:16: runtime error: member access within misaligned address 0x7fe62bd15472 for type 'struct duk_tval', which requires 8 byte alignment
0x7fe62bd15472: note: pointer points here
 00 00  01 00 08 00 00 00 fe ff  ff ff 60 00 c0 2b e6 7f  00 00 08 00 00 00 ff 7f  00 00 60 09 c0 2b
              ^
duk_js_compiler.c:759:5: runtime error: member access within misaligned address 0x7fe62bc02f82 for type 'struct duk_tval', which requires 8 byte alignment
0x7fe62bc02f82: note: pointer points here
 00 00  01 00 09 00 00 00 e6 7f  00 00 d0 2c c0 2b e6 7f  00 00 00 00 00 00 e6 7f  00 00 00 00 00 00
              ^
duk_js_ops.c:571:34: runtime error: member access within misaligned address 0x7fe62bc0d4e2 for type 'struct duk_tval', which requires 8 byte alignment
0x7fe62bc0d4e2: note: pointer points here
 00 00  01 00 08 00 00 00 e6 7f  00 00 a0 83 c0 2b e6 7f  00 00 08 00 00 00 e6 7f  00 00 e0 0e c0 2b
              ^
duk_js_ops.c:575:11: runtime error: member access within misaligned address 0x7fe62bc0ecd2 for type 'struct duk_tval', which requires 8 byte alignment
0x7fe62bc0ecd2: note: pointer points here
 e6 7f  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 40 00 00 00 00 00 00  00 00 00 00 00 00
              ^
duk_heap_markandsweep.c:191:6: runtime error: member access within misaligned address 0x7fe62bc089d2 for type 'struct duk_tval', which requires 8 byte alignment
0x7fe62bc089d2: note: pointer points here
 00 00  01 00 09 00 00 00 ff 7f  00 00 90 86 c0 2b e6 7f  00 00 00 00 00 00 e6 7f  00 00 00 00 00 00
              ^
duk_heap_markandsweep.c:192:3: runtime error: member access within misaligned address 0x7fe62bc089d2 for type 'struct duk_tval', which requires 8 byte alignment
0x7fe62bc089d2: note: pointer points here
 00 00  01 00 09 00 00 00 ff 7f  00 00 90 86 c0 2b e6 7f  00 00 00 00 00 00 e6 7f  00 00 00 00 00 00
              ^
duk_regexp_compiler.c:1040:2: runtime error: left shift of 31 by 27 places cannot be represented in type 'int'
duk_hobject_props.c:4657:3: runtime error: member access within misaligned address 0x7fe62bc3b792 for type 'struct duk_tval', which requires 8 byte alignment
0x7fe62bc3b792: note: pointer points here
 00 00  01 00 07 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 07 00 00 00 00 00  00 00 00 00 00 00
              ^
duk_hobject_props.c:4657:3: runtime error: store to misaligned address 0x7fe62bc3b792 for type 'struct duk_tval', which requires 8 byte alignment
0x7fe62bc3b792: note: pointer points here
 00 00  01 00 07 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 07 00 00 00 00 00  00 00 00 00 00 00
              ^
duk_hobject_props.c:1625:9: runtime error: member access within misaligned address 0x7fe62bf0cf72 for type 'struct duk_tval', which requires 8 byte alignment
0x7fe62bf0cf72: note: pointer points here
 00 00  01 00 07 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00
              ^
duk_js_executor.c:352:11: runtime error: left shift of 327675 by 16 places cannot be represented in type 'int'
duk_hobject_props.c:4210:23: runtime error: store to misaligned address 0x7fe62c027269 for type 'duk_uint32_t', which requires 4 byte alignment
0x7fe62c027269: note: pointer points here
 61 00 00  00 01 00 00 00 be 00 00  00 cf 00 00 00 d2 00 00  00 d0 00 00 00 bf 00 00  00 cb 00 00 00
              ^

About this issue

  • Original URL
  • State: open
  • Created 8 years ago
  • Comments: 74 (53 by maintainers)

Commits related to this issue

Most upvoted comments

@tavianator Regarding this example:

double x = ...;
int n = (int)x;
if (n != x) {
  // This can only happen if d was out of range, so the compiler might
  // delete this entire block as unreachable!
  report_error("double was out of range!");
}

This particular case couldn’t happen here, because the comparison is also used and relevant for in-range inputs (and comes out both true and false for them too). But I get your point, and it would be of course easy to write a compiler that specifically sabotaged the out-of-range case, and similar behavior may turn out unexpectedly when doing enough optimizations, combining optimizations, etc.

Even in this case, while the branch cannot be eliminated entirely, the taken branch of the if-clause could be compiled with knowledge of the range of the values, which incorporated the assumption that the undefined behavior case is not possible. And that might then cause something interesting depending on what’s done in the branch.