llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.11k stars 11.6k forks source link

clang on windows (VS 2022) provides unhelpful error message when attempting to use alloca #91357

Open msprotz opened 4 months ago

msprotz commented 4 months ago
c:\Users\protz\Desktop\hacl-packages>clang --version
clang version 17.0.3
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\Llvm\x64\bin

c:\Users\protz\Desktop\hacl-packages>clang test.c
test.c:5:12: error: call to undeclared library function 'alloca' with type 'void *(unsigned long long)'; ISO C99 and
      later do not support implicit function declarations [-Wimplicit-function-declaration]
    5 |   int *x = alloca(sizeof(int));
      |            ^
test.c:5:12: note: include the header <stdlib.h> or explicitly provide a declaration for 'alloca'
1 error generated.

c:\Users\protz\Desktop\hacl-packages>type test.c
#include <string.h>
#include <stdlib.h>

int main() {
  int *x = alloca(sizeof(int));
  memset(x, 0, sizeof(int));
  return x[0];
}

the recommendation to use stdlib.h, as provided in the error message, is incorrect, since what I need for this particular toolchain is malloc.h

asl commented 4 months ago

This likely to be reported to vcpp issue tracker