<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">It looks like turning it to an assert wouldn’t be correct, I’ll probably just remove it.<div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On May 2, 2016, at 3:12 PM, Akira Hatanaka via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" class="">cfe-commits@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I see. Perhaps this should be an assert?<div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On May 2, 2016, at 3:05 PM, Richard Smith <<a href="mailto:richard@metafoo.co.uk" class="">richard@metafoo.co.uk</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="gmail_extra"><div class="gmail_quote">On Mon, May 2, 2016 at 2:52 PM, Akira Hatanaka via cfe-commits<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank" class="">cfe-commits@lists.llvm.org</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;">Author: ahatanak<br class="">Date: Mon May  2 16:52:57 2016<br class="">New Revision: 268314<br class=""><br class="">URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project?rev=268314&view=rev" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project?rev=268314&view=rev</a><br class="">Log:<br class="">[CodeGenObjCXX] Don't rematerialize default arguments of function<br class="">parameters in the body of a block.<br class=""><br class="">This fixes a bug where clang would materialize the default argument<br class="">inside the body of a block instead of passing the value via the block<br class="">descriptor.<br class=""><br class="">For example, in the code below, foo1 would always print 42 regardless<br class="">of the value of argument "a" passed to foo1.<br class=""><br class="">void foo1(const int a = 42 ) {<br class=""> <span class="Apple-converted-space"> </span>auto block = ^{<br class="">   <span class="Apple-converted-space"> </span>printf("%d\n", a);<br class=""> <span class="Apple-converted-space"> </span>};<br class=""> <span class="Apple-converted-space"> </span>block();<br class="">}<br class=""><br class=""><a href="rdar://problem/24449235" class="">rdar://problem/24449235</a><br class=""><br class="">Added:<br class="">   <span class="Apple-converted-space"> </span>cfe/trunk/test/CodeGenObjCXX/<a href="http://block-default-arg.mm/" rel="noreferrer" target="_blank" class="">block-default-arg.mm</a><br class="">Modified:<br class="">   <span class="Apple-converted-space"> </span>cfe/trunk/lib/CodeGen/CGBlocks.cpp<br class=""><br class="">Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp<br class="">URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=268314&r1=268313&r2=268314&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=268314&r1=268313&r2=268314&view=diff</a><br class="">==============================================================================<br class="">--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)<br class="">+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Mon May  2 16:52:57 2016<br class="">@@ -262,6 +262,11 @@ static bool isSafeForCXXConstantCapture(<br class=""> static llvm::Constant *tryCaptureAsConstant(CodeGenModule &CGM,<br class="">                                             CodeGenFunction *CGF,<br class="">                                             const VarDecl *var) {<br class="">+  // Don't rematerialize default arguments of function parameters.<br class="">+  if (auto *PD = dyn_cast<ParmVarDecl>(var))<br class="">+    if (PD->hasDefaultArg())<br class=""></blockquote><div class=""><br class=""></div><div class="">I don't think you need this test, and I think it somewhat confuses the intent here. (A reader would wonder why you want to keep going for ParmVarDecls that don't have default arguments.)</div><div class=""> </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;">+      return nullptr;<br class="">+<br class="">   QualType type = var->getType();<br class=""><br class="">   // We can only do this if the variable is const.<br class=""><br class="">Added: cfe/trunk/test/CodeGenObjCXX/<a href="http://block-default-arg.mm/" rel="noreferrer" target="_blank" class="">block-default-arg.mm</a><br class="">URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/block-default-arg.mm?rev=268314&view=auto" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/block-default-arg.mm?rev=268314&view=auto</a><br class="">==============================================================================<br class="">--- cfe/trunk/test/CodeGenObjCXX/<a href="http://block-default-arg.mm/" rel="noreferrer" target="_blank" class="">block-default-arg.mm</a><span class="Apple-converted-space"> </span>(added)<br class="">+++ cfe/trunk/test/CodeGenObjCXX/<a href="http://block-default-arg.mm/" rel="noreferrer" target="_blank" class="">block-default-arg.mm</a><span class="Apple-converted-space"> </span>Mon May  2 16:52:57 2016<br class="">@@ -0,0 +1,16 @@<br class="">+// RUN: %clang_cc1 -triple x86_64-apple-darwin10.0.0 -emit-llvm -o - %s -std=c++11 -fblocks -fobjc-arc | FileCheck  %s<br class="">+<br class="">+// CHECK: define internal void @___Z16test_default_argi_block_invoke(i8* %[[BLOCK_DESCRIPTOR:.*]])<br class="">+// CHECK: %[[BLOCK:.*]] = bitcast i8* %[[BLOCK_DESCRIPTOR]] to <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i32 }>*<br class="">+// CHECK: %[[BLOCK_CAPTURE_ADDR:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i32 }>, <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i32 }>* %[[BLOCK]], i32 0, i32 5<br class="">+// CHECK: %[[V0:.*]] = load i32, i32* %[[BLOCK_CAPTURE_ADDR]]<br class="">+// CHECK: call void @_Z4foo1i(i32 %[[V0]])<br class="">+<br class="">+void foo1(int);<br class="">+<br class="">+void test_default_arg(const int a = 42) {<br class="">+  auto block = ^{<br class="">+    foo1(a);<br class="">+  };<br class="">+  block();<br class="">+}<br class=""><br class=""><br class="">_______________________________________________<br class="">cfe-commits mailing list<br class=""><a href="mailto:cfe-commits@lists.llvm.org" class="">cfe-commits@lists.llvm.org</a><br class=""><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a></blockquote></div></div></div></div></blockquote></div><br class=""></div></div>_______________________________________________<br class="">cfe-commits mailing list<br class=""><a href="mailto:cfe-commits@lists.llvm.org" class="">cfe-commits@lists.llvm.org</a><br class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits<br class=""></div></blockquote></div><br class=""></div></body></html>