[PATCH] D62645: [Sema] Resolve placeholder types before type deduction to silence spurious `-Warc-repeated-use-of-weak` warnings
Akira Hatanaka via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed May 29 21:58:53 PDT 2019
ahatanak created this revision.
ahatanak added reviewers: rsmith, rjmccall.
ahatanak added a project: clang.
Herald added subscribers: dexonsmith, jkorous.
The spurious `-Warc-repeated-use-of-weak` warnings are issued when an initializer expression uses a weak ObjC pointer.
My first attempt to silence the warnings (r350917) caused clang to reject code that is legal in C++17. The patch is based on the feedback I received from Richard when the patch was reverted.
http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20190422/268945.html
http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20190422/268943.html
Repository:
rC Clang
https://reviews.llvm.org/D62645
Files:
lib/Sema/SemaDecl.cpp
lib/Sema/SemaExpr.cpp
lib/Sema/SemaExprCXX.cpp
test/SemaObjC/arc-repeated-weak.mm
Index: test/SemaObjC/arc-repeated-weak.mm
===================================================================
--- test/SemaObjC/arc-repeated-weak.mm
+++ test/SemaObjC/arc-repeated-weak.mm
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -fsyntax-only -fobjc-runtime-has-weak -fobjc-arc -fblocks -Wno-objc-root-class -std=c++11 -Warc-repeated-use-of-weak -verify %s
-// RUN: %clang_cc1 -fsyntax-only -fobjc-runtime-has-weak -fobjc-weak -fblocks -Wno-objc-root-class -std=c++11 -Warc-repeated-use-of-weak -verify %s
+// RUN: %clang_cc1 -fsyntax-only -fobjc-runtime-has-weak -fobjc-arc -fblocks -Wno-objc-root-class -std=c++14 -Warc-repeated-use-of-weak -verify %s
+// RUN: %clang_cc1 -fsyntax-only -fobjc-runtime-has-weak -fobjc-weak -fblocks -Wno-objc-root-class -std=c++14 -Warc-repeated-use-of-weak -verify %s
@interface Test {
@public
@@ -467,6 +467,18 @@
__typeof__(NSBundle2.foo2.weakProp) t5;
}
+void testAuto() {
+ auto __weak wp = NSBundle2.foo2.weakProp;
+}
+
+void testLambdaCaptureInit() {
+ [capture(NSBundle2.foo2.weakProp)] {} ();
+}
+
+void testAutoNew() {
+ auto p = new auto(NSBundle2.foo2.weakProp);
+}
+
// This used to crash in the constructor of WeakObjectProfileTy when a
// DeclRefExpr was passed that didn't reference a VarDecl.
Index: lib/Sema/SemaExprCXX.cpp
===================================================================
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -1826,6 +1826,15 @@
NumInits = List->getNumExprs();
}
+ for (unsigned I = 0, E = NumInits; I != E; ++I)
+ if (auto *PlaceholderType = Inits[I]->getType()->getAsPlaceholderType())
+ if (PlaceholderType->getKind() == BuiltinType::PseudoObject) {
+ ExprResult Result = CheckPlaceholderExpr(Inits[I]);
+ if (!Result.isUsable())
+ return ExprError();
+ Inits[I] = Result.get();
+ }
+
// C++11 [expr.new]p15:
// A new-expression that creates an object of type T initializes that
// object as follows:
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -6623,6 +6623,15 @@
ExprResult Sema::ActOnParenListExpr(SourceLocation L,
SourceLocation R,
MultiExprArg Val) {
+ for (size_t I = 0, E = Val.size(); I != E; ++I)
+ if (auto *PlaceholderType = Val[I]->getType()->getAsPlaceholderType())
+ if (PlaceholderType->getKind() == BuiltinType::PseudoObject) {
+ ExprResult Result = CheckPlaceholderExpr(Val[I]);
+ if (!Result.isUsable())
+ return ExprError();
+ Val[I] = Result.get();
+ }
+
return ParenListExpr::Create(Context, L, Val, R);
}
Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -11096,6 +11096,15 @@
}
Init = Res.get();
+ if (!Init->getType().isNull())
+ if (auto *placeholderType = Init->getType()->getAsPlaceholderType())
+ if (placeholderType->getKind() == BuiltinType::PseudoObject) {
+ Res = CheckPlaceholderExpr(Init).get();
+ if (!Res.isUsable())
+ return;
+ Init = Res.get();
+ }
+
if (DeduceVariableDeclarationType(VDecl, DirectInit, Init))
return;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62645.202115.patch
Type: text/x-patch
Size: 3360 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190530/08f891ab/attachment.bin>
More information about the cfe-commits
mailing list