[llvm-bugs] [Bug 43075] New: Missing return statement causes wrong branch to be taken
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Aug 21 07:11:02 PDT 2019
https://bugs.llvm.org/show_bug.cgi?id=43075
Bug ID: 43075
Summary: Missing return statement causes wrong branch to be
taken
Product: clang
Version: 7.0
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: doughera at lafayette.edu
CC: blitzrakete at gmail.com, dgregor at apple.com,
erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
richard-llvm at metafoo.co.uk
Created attachment 22409
--> https://bugs.llvm.org/attachment.cgi?id=22409&action=edit
Program to show odd effect of missing return statement
In the following function,
int checkit(void)
{
int rtn = 0;
if (rtn != 0) {
printf("In rtn != 0 branch with rtn = %d\n", rtn);
printf("Not Ok.\n");
exit(1);
}
}
the missing return statement causes clang++ -O1 to take the "Not Ok" branch,
even though 'rtn' is correctly reported to be zero. A complete test case is
attached.
clang++ correctly reports the error:
warning: control may reach end of non-void function [-Wreturn-type]
and I gather that omitting the return statement in C++ leads to undefined
behavior, but taking the rtn !=0 branch is still rather surprising.
This occurred in a C program inside Perl's Configure that a user wishes to
compile with clang++. We have already fixed the Configure code to work
correctly. It seems to be similar to
https://bugs.llvm.org/show_bug.cgi?id=42897, but I thought the behavior
sufficiently odd to merit reporting.
Steps to reproduce:
Compile the attached program with
clang++ -O1 -o try try.c && ./try; echo $?
clang++ will correctly warn about 'control may reach end of non-void function'.
Expected output:
The expected output is "Ok", with an exit status of 0.
Actual output:
a. With clang++-7 (clang version 7.0.1-8 (tags/RELEASE_701/final),
distributed with current Debian stable), the output is
In rtn != 0 branch with rtn = 0
Not Ok.
Exit status is 1.
b. With a recent git checkout, clang version 10.0.0
(https://github.com/llvm/llvm-project.git
928071ae4ef5e2e6342afb126518a79fde81cf8b) the output is
empty (nothing is printed) and the exit status is 0.
Build date and hardware:
2019-08-19, x86_64-pc-linux-gnu
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190821/be49849f/attachment-0001.html>
More information about the llvm-bugs
mailing list