<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 - CMake config checks lead to invalid output wasm"
   href="https://bugs.llvm.org/show_bug.cgi?id=40470">40470</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>CMake config checks lead to invalid output wasm
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>lld
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </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>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>alonzakai@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, peter.smith@linaro.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Testcase:
===
#ifdef CHECK_FUNCTION_EXISTS

#ifdef __cplusplus
extern "C"
#endif
  char
  CHECK_FUNCTION_EXISTS(void);
#ifdef __CLASSIC_C__
int main()
{
  int ac;
  char* av[];
#else
int main(int ac, char* av[])
{
#endif
  CHECK_FUNCTION_EXISTS();
  if (ac > 1000) {
    return *av[0];
  }
  return 0;
}

#else /* CHECK_FUNCTION_EXISTS */

#error "CHECK_FUNCTION_EXISTS has to specify the function"

#endif /* CHECK_FUNCTION_EXISTS */
===

Build with

emcc a.c -DCHECK_FUNCTION_EXISTS=strtod

Output is
===
redeclaration of library function 'strtod'
[-Wincompatible-library-redeclaration]
  CHECK_FUNCTION_EXISTS(void);
  ^
<command line>:9:31: note: expanded from here
#define CHECK_FUNCTION_EXISTS strtod
                              ^
a.c:7:3: note: 'strtod' is a builtin with type 'double (const char *, char **)'
<command line>:9:31: note: expanded from here
#define CHECK_FUNCTION_EXISTS strtod
                              ^
1 warning generated.
Ddef __stack_pointer
wasm-ld: warning: function signature mismatch: strtod
<span class="quote">>>> defined as () -> i32 in /tmp/emscripten_temp_OvrAvc/a_0.o
>>> defined as (i32, i32) -> f64 in /home/azakai/.emscripten_cache/wasm_o/libc.a(strtod_94cb6386.c.o)</span >
===

It complains correctly about the invalid signature. However, the wasm-ld stage
emitted a wasm, which is invalid. wabt errors with

/tmp/emscripten_temp/a.out.wasm:00001f9: error: type mismatch in call, expected
[i32, i32] but got []

and as emcc continues on to run wasm-emscripten-finalize that fails with

[parse exception: attempted pop from empty stack / beyond block start boundary
at 505 (at 0:505)]</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>