This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by iid_iunknown on Mar 29 2016, 8:42 AM.

Details

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

Diff Detail

Repository
rL LLVM

Event Timeline

iid_iunknown retitled this revision from to [Clang][ARM] __va_list declaration is not saved in ASTContext causing compilation error or crash.
iid_iunknown updated this object.
iid_iunknown added a reviewer: logan.
iid_iunknown set the repository for this revision to rL LLVM.
iid_iunknown added subscribers: llvm-commits, asl.
iid_iunknown edited subscribers, added: cfe-commits; removed: llvm-commits.Mar 29 2016, 12:57 PM
rsmith edited edge metadata.Mar 29 2016, 3:40 PM

Thanks, the change itself LGTM, but please add your testcase, perhaps to test/PCH/__va_list_tag.c

iid_iunknown edited edge metadata.

Test case added.

Thank you for your remark, Richard.
I added the test. Could you check if the patch is good now, please?

rsmith added inline comments.Mar 30 2016, 12:41 PM
test/PCH/arm-__va_list_tag.c
1–7 ↗(On Diff #52092)

Can we remove the triple from this test, and instead test it on the default target for each bot? That should give us broader coverage, and let us find out if the same bug exists for other targets too.

The test enabled for all targets.

iid_iunknown marked an inline comment as done.Mar 30 2016, 1:33 PM
iid_iunknown added inline comments.
test/PCH/arm-__va_list_tag.c
1–7 ↗(On Diff #52092)

Yes, that's a nice idea.
I've updated the test.
Thanks!

rsmith accepted this revision.Mar 30 2016, 1:34 PM
rsmith edited edge metadata.

LGTM, do you need someone to commit this for you?

This revision is now accepted and ready to land.Mar 30 2016, 1:34 PM
iid_iunknown marked an inline comment as done.Mar 30 2016, 2:31 PM

I have commit access.
Thank you for your help with the patch!

iid_iunknown closed this revision.Mar 30 2016, 2:35 PM