[clang] bd8c882 - [clang][IFS] Prevent Clang-IFS from Leaking symbols from inside a block.
Puyan Lotfi via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 13 13:04:52 PST 2020
Author: Puyan Lotfi
Date: 2020-01-13T16:04:27-05:00
New Revision: bd8c8827d96f09be502f0da6897c1aef89e45c30
URL: https://github.com/llvm/llvm-project/commit/bd8c8827d96f09be502f0da6897c1aef89e45c30
DIFF: https://github.com/llvm/llvm-project/commit/bd8c8827d96f09be502f0da6897c1aef89e45c30.diff
LOG: [clang][IFS] Prevent Clang-IFS from Leaking symbols from inside a block.
Built libdispatch with clang interface stubs. Ran into some block
related issues. Basically VarDecl symbols can leak out because I wasn't
checking the case where a VarDecl is contained inside a BlockDecl
(versus a method or function).
This patch checks that a VarDecl is not a child decl of a BlockDecl.
This patch also does something very similar for c++ lambdas as well.
Differential Revision: https://reviews.llvm.org/D71301
Added:
clang/test/InterfaceStubs/blocks.c
clang/test/InterfaceStubs/lambda.cpp
Modified:
clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
Removed:
################################################################################
diff --git a/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp b/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
index e7d6fee5ac67..7241081d6cc0 100644
--- a/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
+++ b/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
@@ -53,6 +53,10 @@ class InterfaceStubFunctionsConsumer : public ASTConsumer {
return true;
if (const VarDecl *VD = dyn_cast<VarDecl>(ND)) {
+ if (const auto *Parent = VD->getParentFunctionOrMethod())
+ if (isa<BlockDecl>(Parent) || isa<CXXMethodDecl>(Parent))
+ return true;
+
if ((VD->getStorageClass() == StorageClass::SC_Extern) ||
(VD->getStorageClass() == StorageClass::SC_Static &&
VD->getParentFunctionOrMethod() == nullptr))
diff --git a/clang/test/InterfaceStubs/blocks.c b/clang/test/InterfaceStubs/blocks.c
new file mode 100644
index 000000000000..927f2bf28869
--- /dev/null
+++ b/clang/test/InterfaceStubs/blocks.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -emit-interface-stubs -fblocks -o - %s | FileCheck %s
+
+// CHECK: --- !experimental-ifs-v1
+// CHECK-NEXT: IfsVersion: 1.0
+// CHECK-NEXT: Triple:
+// CHECK-NEXT: ObjectFileFormat: ELF
+// CHECK-NEXT: Symbols:
+// CHECK-NEXT: ...
+static void (^f)(void*) = ^(void* data) { int i; };
diff --git a/clang/test/InterfaceStubs/lambda.cpp b/clang/test/InterfaceStubs/lambda.cpp
new file mode 100644
index 000000000000..f56aeeaab012
--- /dev/null
+++ b/clang/test/InterfaceStubs/lambda.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -emit-interface-stubs -o - %s | FileCheck %s
+
+// CHECK: --- !experimental-ifs-v1
+// CHECK-NEXT: IfsVersion: 1.0
+// CHECK-NEXT: Triple:
+// CHECK-NEXT: ObjectFileFormat: ELF
+// CHECK-NEXT: Symbols:
+// CHECK-NEXT: "f" : { Type: Object, Size: 1 }
+// CHECK-NEXT: ...
+auto f = [](void* data) { int i; };
More information about the cfe-commits
mailing list