<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    Hi,<br>
    <br>
    The reason this happens is that Wasm functions can take a predefined
    number of parameters only, they cannot be truly variadic. Variadic
    functions are emulated by putting the extra arguments in memory and
    passing a pointer ("memory index" in wasm) to the first one instead
    of `...` part of the argument list. That's why printf takes two
    arguments - first one is format string, the second is the pointer to
    the rest of the arguments.<br>
    <br>
    Best,<br>
    Petr
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 12/19/21 02:48, shankusu2017 via
      llvm-dev wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CABC4HC9ra2hVkfKTNfGEimHQjUY6BtrAoNnyFN4sg85z32y-wA@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr"><br>
        <br>
        <div class="gmail_quote">
          <div dir="ltr" class="gmail_attr">---------- Forwarded message
            ---------<br>
            发件人: <strong class="gmail_sendername" dir="auto">shankusu2017</strong>
            <span dir="auto"><<a href="mailto:shankusu2017@gmail.com"
                moz-do-not-send="true" class="moz-txt-link-freetext">shankusu2017@gmail.com</a>></span><br>
            Date: 2021年12月19日周日 18:17<br>
            Subject: Fwd: about clang compile c to wasm lost argument<br>
            To: <<a href="mailto:llvm-admin@lists.llvm.org"
              moz-do-not-send="true" class="moz-txt-link-freetext">llvm-admin@lists.llvm.org</a>><br>
          </div>
          <br>
          <br>
          <div dir="ltr"><br>
            <br>
            <div class="gmail_quote">
              <div dir="ltr" class="gmail_attr">---------- Forwarded
                message ---------<br>
                发件人: <strong class="gmail_sendername" dir="auto">shankusu2017</strong>
                <span dir="auto"><<a
                    href="mailto:shankusu2017@gmail.com" target="_blank"
                    moz-do-not-send="true" class="moz-txt-link-freetext">shankusu2017@gmail.com</a>></span><br>
                Date: 2021年12月19日周日 18:15<br>
                Subject: about clang compile c to wasm lost argument<br>
                To: <<a href="mailto:surma@surma.dev" target="_blank"
                  moz-do-not-send="true" class="moz-txt-link-freetext">surma@surma.dev</a>><br>
              </div>
              <br>
              <br>
              <div dir="ltr">hi:
                <div>   I use clang to compile the c code into wasm, and
                  I found that clang13/14 regards the variable reference
                  in the c language as a parameter, such as the "..."
                  part in int printf(const char *format, ...); In this
                  way, when I implemented my own printf function in the
                  host environment, wasm only passed 2 parameters to the
                  host when calling prinf, but I actually passed more
                  than 2 parameters. This will cause the printf function
                  I implemented by myself to receive only 2 parameters,
                  and thus lose one parameter. The attachment contains
                  my original c code and compiled wasm and wat codes.
                  The green box part shows that the printf function only
                  accepts 2 input parameters. I don't know how to make
                  clang understand that the number of parameters
                  received by printf is uncertain. Is there any
                  solution?</div>
                <div>   follow build cmd:</div>
                <div>clang -I ../../src/ --target=wasm32 -nostdlib
                   -Wl,--no-entry -Wl,--export-all -Wl,--allow-undefined
                  --sysroot=/usr printf.c -o ../.././build/printf.wasm<br>
                </div>
                <div>wabt</div>
                <div><br>
                </div>
                <div>wasm2wat printf.wasm -o printf.wat<br>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <br>
      <fieldset class="moz-mime-attachment-header"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
    </blockquote>
  </body>
</html>