<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </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 --- - Assertion failed: (OldFn->isDeclaration() && "Shouldn't replace non-declaration") with asm body"
   href="http://llvm.org/bugs/show_bug.cgi?id=16441">16441</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Assertion failed: (OldFn->isDeclaration() && "Shouldn't replace non-declaration") with asm body
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.3
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Frontend
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>achristensen@clcbio.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=10755" name="attach_10755" title="Examples and run scripts">attachment 10755</a> <a href="attachment.cgi?id=10755&action=edit" title="Examples and run scripts">[details]</a></span>
Examples and run scripts

When compiling the code

#define _FILE_OFFSET_BITS 64
#define _LARGEFILE_SOURCE
#define _LARGEFILE64_SOURCE

#include <sys/stat.h>

with -O1 or higher, I get the exception

clang:
/home/achristensen/llvm-3.3.src/llvm/tools/clang/lib/CodeGen/CodeGenModule.cpp:2086:
void
clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl):
Assertion `OldFn->isDeclaration() && "Shouldn't replace non-declaration"'
failed.
0  clang 0x0a5fadd0 llvm::sys::PrintStackTrace(_IO_FILE*) + 48


I reduced the code down to

struct stat { int dummy; };
struct stat64 { int dummy; };

extern int
stat (__const char *__restrict __file, struct stat *__restrict __buf) __asm__
("" "stat64");

extern int
stat64 (__const char *__restrict __file, struct stat64 *__restrict __buf);


extern __inline__ int
stat (__const char *__path, struct stat *__statbuf)
{
  return 1;
}

extern __inline__ int
stat64 (__const char *__path, struct stat64 *__restrict __buf)
{
  return 2;
}

for which the full dump is:

clang:
/home/achristensen/llvm-3.3.src/llvm/tools/clang/lib/CodeGen/CodeGenModule.cpp:2086:
void
clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl):
Assertion `OldFn->isDeclaration() && "Shouldn't replace non-declaration"'
failed.
0  clang 0x0a5fadd0 llvm::sys::PrintStackTrace(_IO_FILE*) + 48
Stack dump:
0.      Program arguments:
/home/achristensen/llvm-3.3.src/build-linux32/Release+Asserts/bin/clang -cc1
-triple i386-pc-linux-gnu -emit-obj -mrelax-all -disable-free -main-file-name
crashtest4.c -mrelocation-model static -mdisable-fp-elim -fmath-errno
-masm-verbose -mconstructor-aliases -target-cpu pentium4 -target-linker-version
2.17.50.0.6 -resource-dir
/home/achristensen/llvm-3.3.src/build-linux32/Release+Asserts/bin/../lib/clang/3.3
-internal-isystem /usr/local/include -internal-isystem
/home/achristensen/llvm-3.3.src/build-linux32/Release+Asserts/bin/../lib/clang/3.3/include
-internal-externc-isystem /include -internal-externc-isystem /usr/include
-fdebug-compilation-dir /home/achristensen/hpc/c_code/c_module -ferror-limit 19
-fmessage-length 172 -mstackrealign -fobjc-runtime=gcc
-fobjc-default-synthesize-properties -fdiagnostics-show-option
-fcolor-diagnostics -backend-option -vectorize-loops -o
/tmp/crashtest4-BloQ8J.o -x c crashtest4.c
1.      <eof> parser at end of file
2.      crashtest4.c:18:1: LLVM IR generation of declaration 'stat64'
3.      crashtest4.c:18:1: Generating code for declaration 'stat64'
clang: error: unable to execute command: Aborted
clang: error: clang frontend command failed due to signal (use -v to see
invocation)
clang version 3.3 (tags/RELEASE_33/final)
Target: i386-pc-linux-gnu
Thread model: posix


If I remove the second parameter of the functions...

extern int
stat (__const char *__restrict __file) __asm__ ("" "stat64");

extern int
stat64 (__const char *__restrict __file);


extern __inline__ int
stat (__const char *__path)
{
  return 1;
}

extern __inline__ int
stat64 (__const char *__path)
{
  return 2;
}

I get a different assertion:

clang:
/home/achristensen/llvm-3.3.src/llvm/tools/clang/lib/CodeGen/CodeGenFunction.cpp:490:
void clang::CodeGen::CodeGenFunction::StartFunction(clang::GlobalDecl,
clang::QualType, llvm::Function*, const clang::CodeGen::CGFunctionInfo&, const
clang::CodeGen::FunctionArgList&, clang::SourceLocation): Assertion
`CurFn->isDeclaration() && "Function already has body?"' failed.
0  clang 0x0a5fadd0 llvm::sys::PrintStackTrace(_IO_FILE*) + 48
Stack dump:
0.      Program arguments:
/home/achristensen/llvm-3.3.src/build-linux32/Release+Asserts/bin/clang -cc1
-triple i386-pc-linux-gnu -emit-obj -mrelax-all -disable-free -main-file-name
crashtest3.c -mrelocation-model static -mdisable-fp-elim -fmath-errno
-masm-verbose -mconstructor-aliases -target-cpu pentium4 -target-linker-version
2.17.50.0.6 -resource-dir
/home/achristensen/llvm-3.3.src/build-linux32/Release+Asserts/bin/../lib/clang/3.3
-internal-isystem /usr/local/include -internal-isystem
/home/achristensen/llvm-3.3.src/build-linux32/Release+Asserts/bin/../lib/clang/3.3/include
-internal-externc-isystem /include -internal-externc-isystem /usr/include
-fdebug-compilation-dir /home/achristensen/hpc/c_code/c_module -ferror-limit 19
-fmessage-length 172 -mstackrealign -fobjc-runtime=gcc
-fobjc-default-synthesize-properties -fdiagnostics-show-option
-fcolor-diagnostics -backend-option -vectorize-loops -o
/tmp/crashtest3-xYbifP.o -x c crashtest3.c
1.      <eof> parser at end of file
2.      crashtest3.c:16:1: LLVM IR generation of declaration 'stat64'
3.      crashtest3.c:16:1: Generating code for declaration 'stat64'
clang: error: unable to execute command: Aborted
clang: error: clang frontend command failed due to signal (use -v to see
invocation)
clang version 3.3 (tags/RELEASE_33/final)
Target: i386-pc-linux-gnu
Thread model: posix


I built clang from the 3.3 final sources on 32-bit Linux (CentOS 5.9) using gcc
4.1.2 with these configuration options:

../llvm/configure --enable-optimized --enable-jit=NO
--enable-targets=x86,x86_64
--with-python=/home/achristensen/Python-linux32/python</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>