Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with int function which doesn't return a value #8421

Closed
thierry7100 opened this issue Dec 24, 2021 · 4 comments
Closed

Problem with int function which doesn't return a value #8421

thierry7100 opened this issue Dec 24, 2021 · 4 comments

Comments

@thierry7100
Copy link

----------------------------- Delete below -----------------------------

If your issue is a general question, starts similar to "How do I..", is related to 3rd party libs, or is related to hardware, please discuss at a community forum like esp8266.com.

INSTRUCTIONS

If you do not follow these instructions, your issue may be dismissed.

  1. Follow the checklist under Basic Infos and fill in the [ ] spaces with an X.
  2. Fill in all the fields under Platform and Settings in IDE marked with [ ] (pick the correct option for you in each case, delete the others).
  3. If you haven't already done so, test your issue against current master branch (aka latest git), because it may have been already fixed.
  4. Describe your problem.
  5. If you have a STACK DUMP decode it:

https://arduino-esp8266.readthedocs.io/en/latest/Troubleshooting/stack_dump.html

  1. Include a Minimal Complete Reproducible Example sketch that shows your issue. Do not include your entire project, or a huge piece of code.
  2. Include debug messages:

https://arduino-esp8266.readthedocs.io/en/latest/Troubleshooting/debugging.html

  1. Use markup (buttons above) and the Preview tab to check what the issue will look like.
  2. Delete these instructions from the above to the below marker lines before submitting this issue.

----------------------------- Delete above -----------------------------

Basic Infos

  • [ X] This issue complies with the issue POLICY doc.
  • [ ]X I have read the documentation at readthedocs and the issue is not addressed there.
  • [ X] I have tested that the issue is present in current master branch (aka latest git).
  • [ X] I have searched the issue tracker for a similar issue.
  • [ X] If there is a stack dump, I have decoded it.
  • [ X] I have filled out all fields below.

Platform

  • Hardware: [ESP-12]
  • Core Version: [3.0.2]
  • Development Env: [Arduino IDE]
  • Operating System: [Ubuntu]

Settings in IDE

  • Module: [Wemos D1 mini r2]
  • Flash Mode: [?]
  • Flash Size: [4MB]
  • lwip Variant: [v2 Lower Memory]
  • Reset Method: [nodemcu]
  • Flash Frequency: [40Mhz]
  • CPU Frequency: [80Mhz]
  • Upload Using: [SERIAL]
  • Upload Speed: [115200] (serial upload only)

Problem Description

I have build a function returning an int but I forgot to return a value. This error is NOT detected by the IDE and worse the function doesn't not exist properly. In fact, the function doesn't exit and resume the loop (see below)

In the simple example provided, I got an exception, but in the complete program, nothing at all, the loop doesn't stop running after the limit was reached without error on the console.

MCVE Sketch

int TestFunction()
{
long int val = 1;
for ( int r = 0; r < 10; r++ )
{
for ( int c = 0; c < 10; c++)
{
val = val + 5;
}
}
}

void setup() {

Serial.begin(115200);
delay(500);
Serial.println("Starting and calling TestFunction");
TestFunction();
Serial.println("Done.\n");

}

void loop() {
// put your main code here, to run repeatedly:

}

Debug Messages

ets Jan 8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 3460, room 16
tail 4
chksum 0xcc
load 0x3fff20b8, len 40, room 4
tail 4
chksum 0xc9
csum 0xc9
v00042760
~ld

SDK:2.2.2-dev(38a443e)/Core:3.0.2=30002000/lwIP:STABLE-2_1_2_RELEASE/glue:1.2-48-g7421258/BearSSL:6105635
Starting and calling TestFunction
Fatal exception 9(LoadStoreAlignmentCause):
epc1=0x40201050, epc2=0x00000000, epc3=0x00000000, excvaddr=0x0000003b, depc=0x00000000

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Exception (9):
epc1=0x40201050 epc2=0x00000000 epc3=0x00000000 excvaddr=0x0000003b depc=0x00000000

stack>>>

ctx: cont
sp: 3ffffe00 end: 3fffffc0 offset: 0190
3fffff90: 3fffdad0 00000000 3ffee568 40201050
3fffffa0: feefeffe feefeffe 3ffee5bc 40201cb4
3fffffb0: feefeffe feefeffe 3ffe85d8 40100ea9
<<<stack<<<

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

@mcspr
Copy link
Collaborator

mcspr commented Dec 24, 2021

should be a fatal error since #8165 via -Werror=return-type

Arduino/platform.txt

Lines 24 to 28 in b5f3d1d

compiler.warning_flags=-w -Werror=return-type
compiler.warning_flags.none=-w -Werror=return-type
compiler.warning_flags.default=-Werror=return-type
compiler.warning_flags.more=-Wall -Werror=return-type
compiler.warning_flags.all=-Wall -Wextra -Werror=return-type

Core Version: [3.0.2]

you should not be able to build the binary, can you check that the verbose build logs for .ino.cpp compilation actually have the flag above?

@mcspr mcspr closed this as completed Dec 24, 2021
@mcspr mcspr reopened this Dec 24, 2021
@mcspr
Copy link
Collaborator

mcspr commented Dec 24, 2021

...but, there's still an issue with the g++ arguments in 'no warnings' mode, -w takes precedence over -Werror=...

$ g++ -v
...
gcc version 11.2.1 20210728 (Red Hat 11.2.1-1) (GCC)
$ g++ -w -Werror=return-type -o /dev/null no-return.cpp
$ cat no-return.cpp
int test() {
}

int main() {
    test();
}

but I'm not sure whether we can do something about it

@thierry7100
Copy link
Author

thierry7100 commented Dec 24, 2021 via email

@mcspr
Copy link
Collaborator

mcspr commented Dec 24, 2021 via email

@mcspr mcspr closed this as completed Feb 20, 2022
mcspr added a commit that referenced this issue Feb 22, 2022
per #8421 and #8475
after checking HW, suggest to check SW as well by at least by enabling some or all compiler warnings
(and also note of the IDE weirdest defaults causing issues we expected to stay solved)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants