[test-suite] r373486 - MultiSource/Applications/d: applying zero offset to null pointer is UB in C

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 2 09:37:13 PDT 2019


Author: lebedevri
Date: Wed Oct  2 09:37:13 2019
New Revision: 373486

URL: http://llvm.org/viewvc/llvm-project?rev=373486&view=rev
Log:
MultiSource/Applications/d: applying zero offset to null pointer is UB in C

Caught by https://reviews.llvm.org/D67122

Address of the zero-th element of an array is identical
to the address of the array base pointer (&a[0] == a),
so let's just not apply zero offset.

llvm-test-suite/MultiSource/Applications/d/parse.c:1588:20: runtime error: applying zero offset to null pointer
    #0 0x251be9 in commit_tree (/builddirs/build-test-suite-old/MultiSource/Applications/d/make_dparser+0x251be9)
    #1 0x2515b4 in commit_tree (/builddirs/build-test-suite-old/MultiSource/Applications/d/make_dparser+0x2515b4)
    #2 0x2515b4 in commit_tree (/builddirs/build-test-suite-old/MultiSource/Applications/d/make_dparser+0x2515b4)
    #3 0x2515b4 in commit_tree (/builddirs/build-test-suite-old/MultiSource/Applications/d/make_dparser+0x2515b4)
    #4 0x2515b4 in commit_tree (/builddirs/build-test-suite-old/MultiSource/Applications/d/make_dparser+0x2515b4)
    #5 0x2515b4 in commit_tree (/builddirs/build-test-suite-old/MultiSource/Applications/d/make_dparser+0x2515b4)
    #6 0x2515b4 in commit_tree (/builddirs/build-test-suite-old/MultiSource/Applications/d/make_dparser+0x2515b4)
    #7 0x2515b4 in commit_tree (/builddirs/build-test-suite-old/MultiSource/Applications/d/make_dparser+0x2515b4)
    #8 0x2515b4 in commit_tree (/builddirs/build-test-suite-old/MultiSource/Applications/d/make_dparser+0x2515b4)
    #9 0x2515b4 in commit_tree (/builddirs/build-test-suite-old/MultiSource/Applications/d/make_dparser+0x2515b4)
    #10 0x2515b4 in commit_tree (/builddirs/build-test-suite-old/MultiSource/Applications/d/make_dparser+0x2515b4)
    #11 0x2515b4 in commit_tree (/builddirs/build-test-suite-old/MultiSource/Applications/d/make_dparser+0x2515b4)
    #12 0x2515b4 in commit_tree (/builddirs/build-test-suite-old/MultiSource/Applications/d/make_dparser+0x2515b4)
    #13 0x253e87 in commit_stack (/builddirs/build-test-suite-old/MultiSource/Applications/d/make_dparser+0x253e87)
    #14 0x253e44 in commit_stack (/builddirs/build-test-suite-old/MultiSource/Applications/d/make_dparser+0x253e44)
    #15 0x250ef1 in exhaustive_parse (/builddirs/build-test-suite-old/MultiSource/Applications/d/make_dparser+0x250ef1)
    #16 0x24facd in dparse (/builddirs/build-test-suite-old/MultiSource/Applications/d/make_dparser+0x24facd)
    #17 0x2441b0 in parse_grammar (/builddirs/build-test-suite-old/MultiSource/Applications/d/make_dparser+0x2441b0)
    #18 0x23a270 in main (/builddirs/build-test-suite-old/MultiSource/Applications/d/make_dparser+0x23a270)
    #19 0x7fac77faebba in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x26bba)
    #20 0x21aeb9 in _start (/builddirs/build-test-suite-old/MultiSource/Applications/d/make_dparser+0x21aeb9)

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /repositories/llvm-test-suite/MultiSource/Applications/d/parse.c:1588:20 in

Modified:
    test-suite/trunk/MultiSource/Applications/d/parse.c

Modified: test-suite/trunk/MultiSource/Applications/d/parse.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Applications/d/parse.c?rev=373486&r1=373485&r2=373486&view=diff
==============================================================================
--- test-suite/trunk/MultiSource/Applications/d/parse.c (original)
+++ test-suite/trunk/MultiSource/Applications/d/parse.c Wed Oct  2 09:37:13 2019
@@ -1585,7 +1585,7 @@ commit_tree(Parser *p, PNode *pn) {
   }
   if (pn->reduction && pn->reduction->final_code)
     pn->reduction->final_code(
-      pn, (void**)&pn->children.v[0], pn->children.n,
+      pn, (void**)pn->children.v, pn->children.n,
       (int)&((PNode*)(NULL))->parse_node, (D_Parser*)p);
   if (pn->evaluated) {
     if (!p->user.save_parse_tree && !internal)




More information about the llvm-commits mailing list