<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Regression since SVN r331889, [InstCombine] snprintf optimizations, Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed."
href="https://bugs.llvm.org/show_bug.cgi?id=37408">37408</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Regression since SVN r331889, [InstCombine] snprintf optimizations, Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Transformation Utilities
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>martin@martin.st
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=20284" name="attach_20284" title="Reproduction sample">attachment 20284</a> <a href="attachment.cgi?id=20284&action=edit" title="Reproduction sample">[details]</a></span>
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"</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>