[llvm-bugs] [Bug 37408] New: Regression since SVN r331889, [InstCombine] snprintf optimizations, Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.

via llvm-bugs llvm-bugs at lists.llvm.org
Thu May 10 11:51:47 PDT 2018


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

            Bug ID: 37408
           Summary: Regression since SVN r331889, [InstCombine] snprintf
                    optimizations, Assertion `isa<X>(Val) && "cast<Ty>()
                    argument of incompatible type!"' failed.
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Transformation Utilities
          Assignee: unassignedbugs at nondot.org
          Reporter: martin at martin.st
                CC: llvm-bugs at lists.llvm.org

Created attachment 20284
  --> https://bugs.llvm.org/attachment.cgi?id=20284&action=edit
Reproduction sample

The optimization in SVN r331889, [InstCombine] snprintf optimization, seems to
trigger assertion failures in cases where the snprintf function prototype
doesn't exactly match the expected. I can reproduce it with the following
minimal snippet:

$ cat snprintf1.c
void snprintf(char *buf, int size, const char *fmt, ...);
void func(char *buf) { snprintf(buf, 1, ""); }
$ clang -target x86_64-linux-gnu -c -O2 snprintf1.c 
manual.c:1:6: warning: incompatible redeclaration of library function
'snprintf' [-Wincompatible-library-redeclaration]
void snprintf(char *buf, int size, const char *fmt, ...);
     ^
manual.c:1:6: note: 'snprintf' is a builtin with type 'int (char *, unsigned
long, const char *, ...)'
clang-7: ../include/llvm/Support/Casting.h:255: typename llvm::cast_retty<X,
Y*>::ret_type llvm::cast(Y*) [with X = llvm::IntegerType; Y = llvm::Type;
typename llvm::cast_retty<X, Y*>::ret_type = llvm::IntegerType*]: Assertion
`isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
Stack dump:
0.      Program arguments: /home/martin/clang-nightly/bin/clang-7 -cc1 -triple
x86_64--linux-gnu -emit-obj -disable-free -main-file-name manual.c
-mrelocation-model static -mthread-model posix -fmath-errno -masm-verbose
-mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64
-dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer
-coverage-notes-file /home/martin/code/reduce-snprintf/manual.gcno
-resource-dir /home/martin/clang-nightly/lib/clang/7.0.0 -internal-isystem
/usr/local/include -internal-isystem
/home/martin/clang-nightly/lib/clang/7.0.0/include -internal-externc-isystem
/usr/include/x86_64-linux-gnu -internal-externc-isystem /include
-internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir
/home/martin/code/reduce-snprintf -ferror-limit 19 -fmessage-length 0
-fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -o
manual.o -x c manual.c 
1.      <eof> parser at end of file
2.      Per-module optimization passes
3.      Running pass 'Function Pass Manager' on module 'manual.c'.
4.      Running pass 'Combine redundant instructions' on function '@func'
/home/martin/clang-nightly/bin/clang-7(_ZN4llvm3sys15PrintStackTraceERNS_11raw_ostreamE+0x2a)[0x19c994a]
/home/martin/clang-nightly/bin/clang-7(_ZN4llvm3sys17RunSignalHandlersEv+0x3e)[0x19c76ee]
/home/martin/clang-nightly/bin/clang-7[0x19c7862]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x11390)[0x7f233e90c390]
/lib/x86_64-linux-gnu/libc.so.6(gsignal+0x38)[0x7f233d67e428]
/lib/x86_64-linux-gnu/libc.so.6(abort+0x16a)[0x7f233d68002a]
/lib/x86_64-linux-gnu/libc.so.6(+0x2dbd7)[0x7f233d676bd7]
/lib/x86_64-linux-gnu/libc.so.6(+0x2dc82)[0x7f233d676c82]
/home/martin/clang-nightly/bin/clang-7(_ZN4llvm11ConstantInt3getEPNS_4TypeEmb+0x71)[0x148b241]
/home/martin/clang-nightly/bin/clang-7(_ZN4llvm17LibCallSimplifier22optimizeSnPrintFStringEPNS_8CallInstERNS_9IRBuilderINS_14ConstantFolderENS_24IRBuilderDefaultInserterEEE+0x180)[0x1abe440]
/home/martin/clang-nightly/bin/clang-7(_ZN4llvm17LibCallSimplifier12optimizeCallEPNS_8CallInstE+0x77a)[0x1ac0dba]


Similarly with the attached file, with "clang -target x86_64-w64-mingw32 -c -O2
snprintf2.c"

-- 
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/20180510/856d9a60/attachment-0001.html>


More information about the llvm-bugs mailing list