[llvm-bugs] [Bug 36476] New: [InstCombine] Instcombine deletes call of 'new' function that has side effects after r325630

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Feb 22 09:03:23 PST 2018


https://bugs.llvm.org/show_bug.cgi?id=36476

            Bug ID: 36476
           Summary: [InstCombine] Instcombine deletes call of 'new'
                    function that has side effects after r325630
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: ilia.taraban at intel.com
                CC: llvm-bugs at lists.llvm.org

This test fails at with wrong result after r325630:

================= nice.cpp ============
#include <stdlib.h>
#include <stdio.h>

extern void *operator new(size_t size)
{
    printf("Happy ending\n");
    exit(0);
    return malloc(size);
}


struct S { int a;};

int main ()
{
    S *s = new S;
    printf("Bad ending\n");
    printf("%x\n", s -> a);
    return 0;
}
=======================================


>>> clang -v
clang version 7.0.0 (trunk 325762)
Target: x86_64-unknown-linux-gnu
Thread model: posix
...

>>> clang -o nice.exe nice.cpp -O0
>>> ./nice.exe
Happy ending

>>> clang -o nice.exe nice.cpp -O1
>>> ./nice.exe
Bad ending
Illegal instruction (core dumped)


>>> clang -o nice.exe nice.cpp -mllvm -opt-bisect-limit :

BISECT: running pass (15) Simplify the CFG on function (_Znwm)       
-> Happy ending
BISECT: running pass (16) Combine redundant instructions on function (main)
-> Bad ending

============ nice-before.ll ===========
...
; Function Attrs: nobuiltin uwtable
define dso_local noalias i8* @_Znwm(i64) local_unnamed_addr #0 {
  %2 = call i32 @puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @str,
i64 0, i64 0))
  call void @exit(i32 0) #5
  unreachable
}


; Function Attrs: norecurse uwtable
define dso_local i32 @main() local_unnamed_addr #3 {
  %1 = call i8* @_Znwm(i64 undef) #6
  %2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x
i8]* @.str.1, i32 0, i32 0))
  %3 = getelementptr inbounds %struct.S, %struct.S* undef, i32 0, i32 0
  %4 = load i32, i32* %3, align 4, !tbaa !2
  %5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x
i8]* @.str.2, i32 0, i32 0), i32 %4)
  ret i32 0
}
...

=======================================

>>> opt nice-before.ll -instcombine -o nice-after.ll -S

============ nice-after.ll ===========
...
; Function Attrs: norecurse uwtable
define dso_local i32 @main() local_unnamed_addr #3 {
  %puts = call i32 @puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]*
@str.1, i64 0, i64 0))
  store i32 undef, i32* null, align 536870912
  %1 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x
i8]* @.str.2, i64 0, i64 0), i32 undef)
  ret i32 0
}

...

=======================================

This started giving wrong behavior after r325630
[https://reviews.llvm.org/rL325630]
---------------------------------------
r325630 | d0k | 2018-02-20 23:00:33 +0100 (Tue, 20 Feb 2018) | 5 lines

[MemoryBuiltins] Check nobuiltin status when identifying calls to free.

This is usually not a problem because this code's main purpose is
eliminating unused new/delete pairs. We got deletes of nullptr or
nobuiltin deletes of builtin new wrong though.
---------------------------------------

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180222/d5f3fecd/attachment.html>


More information about the llvm-bugs mailing list