[prev in list] [next in list] [prev in thread] [next in thread]
List: cfe-commits
Subject: RE: [PATCH] RE: [cfe-dev] missing return statement for non-void functions in C++
From: Sjoerd Meijer via cfe-commits <cfe-commits () lists ! llvm ! org>
Date: 2015-08-17 12:33:51
Message-ID: 1C23526A7C42DB45BBF55B662C7C530E4E654C7B87 () BUNGLE ! Emea ! Arm ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
[Attachment #4 (text/plain)]
Agreed, let's get that right first.
The attached patch causes the program to trap for all optimizations levels, except \
when optimizing for size.
Sjoerd.
From: dosreis@gmail.com [mailto:dosreis@gmail.com] On Behalf Of Gabriel Dos Reis
Sent: 13 August 2015 21:51
To: Richard Smith
Cc: Sjoerd Meijer; Marshall Clow; cfe-commits
Subject: Re: [PATCH] RE: [cfe-dev] missing return statement for non-void functions in \
C++
Please make such programs crash early and often. They are a nightmare to maintain. \
Make them blow in the face of the original authors; not after they are gone.
-- Gaby
-- IMPORTANT NOTICE: The contents of this email and any attachments are confidential \
and may also be privileged. If you are not the intended recipient, please notify the \
sender immediately and do not disclose the contents to any other person, use it for \
any purpose, or store or copy the information in any medium. Thank you.
ARM Limited, Registered office 110 Fulbourn Road, Cambridge CB1 9NJ, Registered in \
England & Wales, Company No: 2557590 ARM Holdings plc, Registered office 110 Fulbourn \
Road, Cambridge CB1 9NJ, Registered in England & Wales, Company No: 2548782
[Attachment #5 (text/html)]
<html xmlns:v="urn:schemas-microsoft-com:vml" \
xmlns:o="urn:schemas-microsoft-com:office:office" \
xmlns:w="urn:schemas-microsoft-com:office:word" \
xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" \
xmlns="http://www.w3.org/TR/REC-html40"> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p
{mso-style-priority:99;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
{mso-style-priority:99;
mso-style-link:"Balloon Text Char";
margin:0cm;
margin-bottom:.0001pt;
font-size:8.0pt;
font-family:"Tahoma","sans-serif";}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
span.BalloonTextChar
{mso-style-name:"Balloon Text Char";
mso-style-priority:99;
mso-style-link:"Balloon Text";
font-family:"Tahoma","sans-serif";
mso-fareast-language:EN-GB;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";
mso-fareast-language:EN-US;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Agreed, \
let's get that right first.<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">The \
attached patch causes the program to trap for all optimizations levels, except when \
optimizing for size.<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Sjoerd.<o:p></o:p></span></p>
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span lang="EN-US" \
style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span \
lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> \
dosreis@gmail.com [mailto:dosreis@gmail.com] <b>On Behalf Of </b>Gabriel Dos Reis<br>
<b>Sent:</b> 13 August 2015 21:51<br>
<b>To:</b> Richard Smith<br>
<b>Cc:</b> Sjoerd Meijer; Marshall Clow; cfe-commits<br>
<b>Subject:</b> Re: [PATCH] RE: [cfe-dev] missing return statement for non-void \
functions in C++<o:p></o:p></span></p> <p \
class="MsoNormal"><o:p> </o:p></p> <div>
<p class="MsoNormal">Please make such programs crash early and often. They are \
a nightmare to maintain. Make them blow in the face of the original authors; \
not after they are gone.<o:p></o:p></p> <div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">-- Gaby<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</div>
<br>
<font face="Arial" color="Black" size="2">-- IMPORTANT NOTICE: The contents of this \
email and any attachments are confidential and may also be privileged. If you are not \
the intended recipient, please notify the sender immediately and do not disclose the \
contents to any other person, use it for any purpose, or store or copy the \
information in any medium. Thank you.<br> <br>
ARM Limited, Registered office 110 Fulbourn Road, Cambridge CB1 9NJ, Registered in \
England & Wales, Company No: 2557590<br> ARM Holdings plc, Registered office 110 \
Fulbourn Road, Cambridge CB1 9NJ, Registered in England & Wales, Company No: \
2548782<br> </font>
</body>
</html>
["0001-Always-trap-for-missing-return-statements-except-whe.patch" (application/octet-stream)]
From 0ee50b3f8d7f247af358b75d0e0741308af647e9 Mon Sep 17 00:00:00 2001
From: Sjoerd Meijer <sjoerd.meijer@arm.com>
Date: Mon, 17 Aug 2015 11:38:35 +0100
Subject: [PATCH] Always trap for missing return statements, except when
optimizing for size.
---
lib/CodeGen/CodeGenFunction.cpp | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp
index 9bf4161..3135c1a 100644
--- a/lib/CodeGen/CodeGenFunction.cpp
+++ b/lib/CodeGen/CodeGenFunction.cpp
@@ -926,7 +926,14 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn,
EmitCheck(std::make_pair(IsFalse, SanitizerKind::Return),
"missing_return", EmitCheckSourceLocation(FD->getLocation()),
None);
- } else if (CGM.getCodeGenOpts().OptimizationLevel == 0) {
+ }
+
+ // A missing return statement provides opportunities for optimizing away
+ // unreachable control flow, i.e it is a code-size optimization opportunity.
+ // However, not returning from a function is potentially unsafe and also not
+ // so user-friendly. Therefore, we trap for all optimizations levels, except
+ // when optimizing for size.
+ if (!CGM.getCodeGenOpts().OptimizeSize) {
EmitTrapCall(llvm::Intrinsic::trap);
}
Builder.CreateUnreachable();
--
1.9.1
[Attachment #7 (text/plain)]
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic