r264930 - [Clang][ARM] __va_list declaration is not saved in ASTContext causing compilation error or crash
Oleg Ranevskyy via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 30 14:30:30 PDT 2016
Author: oleg
Date: Wed Mar 30 16:30:30 2016
New Revision: 264930
URL: http://llvm.org/viewvc/llvm-project?rev=264930&view=rev
Log:
[Clang][ARM] __va_list declaration is not saved in ASTContext causing compilation error or crash
Summary:
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
```
Reviewers: logan, rsmith
Subscribers: cfe-commits, asl, aemerson, rengolin
Differential Revision: http://reviews.llvm.org/D18557
Added:
cfe/trunk/test/PCH/Inputs/__va_list_tag-typedef.h
cfe/trunk/test/PCH/__va_list_tag-typedef.c
Modified:
cfe/trunk/lib/AST/ASTContext.cpp
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=264930&r1=264929&r2=264930&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Wed Mar 30 16:30:30 2016
@@ -6389,6 +6389,7 @@ CreateAAPCSABIBuiltinVaListDecl(const AS
// };
VaListDecl->completeDefinition();
+ Context->VaListTagDecl = VaListDecl;
// typedef struct __va_list __builtin_va_list;
QualType T = Context->getRecordType(VaListDecl);
Added: cfe/trunk/test/PCH/Inputs/__va_list_tag-typedef.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/Inputs/__va_list_tag-typedef.h?rev=264930&view=auto
==============================================================================
--- cfe/trunk/test/PCH/Inputs/__va_list_tag-typedef.h (added)
+++ cfe/trunk/test/PCH/Inputs/__va_list_tag-typedef.h Wed Mar 30 16:30:30 2016
@@ -0,0 +1,4 @@
+// Header for PCH test __va_list_tag-typedef.c
+
+#include <stdarg.h>
+typedef va_list va_list_1;
Added: cfe/trunk/test/PCH/__va_list_tag-typedef.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/__va_list_tag-typedef.c?rev=264930&view=auto
==============================================================================
--- cfe/trunk/test/PCH/__va_list_tag-typedef.c (added)
+++ cfe/trunk/test/PCH/__va_list_tag-typedef.c Wed Mar 30 16:30:30 2016
@@ -0,0 +1,14 @@
+// This test checks the patch for the compilation error / crash described in D18557.
+
+// Test as a C source
+// RUN: %clang_cc1 -emit-pch -x c-header -o %t %S/Inputs/__va_list_tag-typedef.h
+// RUN: %clang_cc1 -fsyntax-only -include-pch %t %s
+
+// Test as a C++ source
+// RUN: %clang_cc1 -emit-pch -x c++-header -o %t %S/Inputs/__va_list_tag-typedef.h
+// RUN: %clang_cc1 -x c++ -fsyntax-only -include-pch %t %s
+
+// expected-no-diagnostics
+
+typedef __builtin_va_list va_list_2;
+void test(const char* format, ...) { va_list args; va_start( args, format ); }
More information about the cfe-commits
mailing list