[PATCH] D71317: [clang][IFS] Prevent Clang-IFS from Leaking symbols from inside a block.
Puyan Lotfi via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 10 16:55:29 PST 2019
plotfi created this revision.
plotfi added reviewers: compnerd, cishida.
Herald added subscribers: cfe-commits, dexonsmith.
Herald added a project: clang.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D71317
Files:
clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
clang/test/InterfaceStubs/blocks.c
clang/test/InterfaceStubs/lambda.cpp
Index: clang/test/InterfaceStubs/lambda.cpp
===================================================================
--- /dev/null
+++ 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; };
Index: clang/test/InterfaceStubs/blocks.c
===================================================================
--- /dev/null
+++ 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; };
Index: clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
===================================================================
--- clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
+++ clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
@@ -52,6 +52,14 @@
if (!isVisible(ND))
return true;
+ if (const VarDecl *VD = dyn_cast<VarDecl>(ND))
+ if (const auto *Parent = VD->getParentFunctionOrMethod()) {
+ if (const auto *BD = dyn_cast_or_null<BlockDecl>(Parent))
+ return true;
+ if (const auto *MD = dyn_cast_or_null<CXXMethodDecl>(Parent))
+ return true;
+ }
+
if (const VarDecl *VD = dyn_cast<VarDecl>(ND))
if ((VD->getStorageClass() == StorageClass::SC_Extern) ||
(VD->getStorageClass() == StorageClass::SC_Static &&
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71317.233228.patch
Type: text/x-patch
Size: 1828 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191211/874e3510/attachment.bin>
More information about the cfe-commits
mailing list