[PATCH] D18557: [Clang][ARM] __va_list declaration is not saved in ASTContext causing compilation error or crash

Oleg Ranevskyy via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 29 08:42:49 PDT 2016


iid_iunknown created this revision.
iid_iunknown added a reviewer: logan.
iid_iunknown added subscribers: llvm-commits, asl.
iid_iunknown set the repository for this revision to rL LLVM.
Herald added subscribers: rengolin, aemerson.

When the code is compiled for arm32 and the builtin `__va_list` declaration is created by `CreateAAPCSABIBuiltinVaListDecl`, the declaration is not saved in the `ASTContext` which may lead to a compilation error or crash.

Minimal reproducer I was able to find:
**header.h**
```
#include <stdarg.h>
typedef va_list va_list_1;
```

**test.cpp**
```
typedef __builtin_va_list va_list_2;
void foo(const char* format, ...) { va_list args; va_start( args, format ); }
```

Steps to reproduce:
```
clang -x c++-header --target=armv7l-linux-eabihf header.h
clang -c -include header.h --target=armv7l-linux-eabihf test.cpp
```

Compilation error:
```
error: non-const lvalue reference to type '__builtin_va_list'
      cannot bind to a value of unrelated type 'va_list' (aka '__builtin_va_list')
```

Compiling the same code as a C source leads to a crash:
```
clang --target=armv7l-linux-eabihf header.h
clang -c -x c -include header.h --target=armv7l-linux-eabihf test.cpp
```

Repository:
  rL LLVM

http://reviews.llvm.org/D18557

Files:
  lib/AST/ASTContext.cpp

Index: lib/AST/ASTContext.cpp
===================================================================
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -6389,6 +6389,7 @@
 
   // };
   VaListDecl->completeDefinition();
+  Context->VaListTagDecl = VaListDecl;
 
   // typedef struct __va_list __builtin_va_list;
   QualType T = Context->getRecordType(VaListDecl);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18557.51923.patch
Type: text/x-patch
Size: 373 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160329/0b9a96a5/attachment.bin>


More information about the llvm-commits mailing list