summaryrefslogtreecommitdiffstats
path: root/test/PCH
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2016-12-09 17:14:05 +0000
committerReid Kleckner <rnk@google.com>2016-12-09 17:14:05 +0000
commit3a67a19e28fc3380fb836a5ff9a33a55cf197547 (patch)
tree8954b85fc3617925f8a70e846bc3542e3c5b8780 /test/PCH
parent153c995100ac3869ce54e68baa8ece8f97270ea4 (diff)
Store decls in prototypes on the declarator instead of in the AST
This saves two pointers from FunctionDecl that were being used for some rare and questionable C-only functionality. The DeclsInPrototypeScope ArrayRef was added in r151712 in order to parse this kind of C code: enum e {x, y}; int f(enum {y, x} n) { return x; // should return 1, not 0 } The challenge is that we parse 'int f(enum {y, x} n)' it its own function prototype scope that gets popped before we build the FunctionDecl for 'f'. The original change was doing two questionable things: 1. Saving all tag decls introduced in prototype scope on a TU-global Sema variable. This is problematic when you have cases like this, where 'x' and 'y' shouldn't be visible in 'f': void f(void (*fp)(enum { x, y } e)) { /* no x */ } This patch fixes that, so now 'f' can't see 'x', which is consistent with GCC. 2. Storing the decls in FunctionDecl in ActOnFunctionDeclarator so that they could be used in ActOnStartOfFunctionDef. This is just an inefficient way to move information around. The AST lives forever, but the list of non-parameter decls in prototype scope is short lived. Moving these things to the Declarator solves both of these issues. Reviewers: rsmith Subscribers: jmolloy, cfe-commits Differential Revision: https://reviews.llvm.org/D27279 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@289225 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/PCH')
-rw-r--r--test/PCH/decl-in-prototype.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/PCH/decl-in-prototype.c b/test/PCH/decl-in-prototype.c
new file mode 100644
index 0000000000..6ee4b3d5eb
--- /dev/null
+++ b/test/PCH/decl-in-prototype.c
@@ -0,0 +1,27 @@
+// Test that we serialize the enum decl in the function prototype somehow.
+// These decls aren't serialized quite the same way as parameters.
+
+// Test this without pch.
+// RUN: %clang_cc1 -include %s -emit-llvm -o - %s | FileCheck %s
+
+// Test with pch.
+// RUN: %clang_cc1 -emit-pch -o %t %s
+// RUN: %clang_cc1 -include-pch %t -emit-llvm -o - %s | FileCheck %s
+
+// CHECK-LABEL: define i32 @main()
+// CHECK: ret i32 1
+
+#ifndef HEADER
+#define HEADER
+
+static inline __attribute__((always_inline)) f(enum { x, y } p) {
+ return y;
+}
+
+#else
+
+int main() {
+ return f(0);
+}
+
+#endif