Confusion caused by use of -fpermissive in AVR and megaAVR compilation recipes
- Dominant language
- Java
- Stars
- 14.6k
- Forks
- 7k
- PR merge metrics
- No merged PRs in 30d
Description
Hi.
There is the problem.
=============================================================
```
void setup() {
Serial.begin(9600);
Serial.println("Start");
}
void loop() {
char ch = Serial.read();
switch(ch){
case '1':
Serial.println("Block 1 starts executing");
// Some block 1
break;
case '2':
Serial.println("Block 2 starts executing");
byte b;
b = 0; // It's OK.
// Some block 2
break;
case '3':
Serial.println("Block 3 starts executing");
// Some block 3
break;
case '4':
Serial.println("Block 4 starts executing");
// Some block 4
break;
}
}
```
Sketch uses 1668 bytes (5%) of program storage space…
Global variables use 294 bytes (14%) of dynamic memory…
=============================================================
```
void setup() {
Serial.begin(9600);
Serial.println("Start");
}
void loop() {
char ch = Serial.read();
switch(ch){
case '1':
Serial.println("Block 1 starts executing");
// Some block 1
break;
case '2':
Serial.println("Block 2 starts executing");
byte b = 0; // This causes the problem! All blocks below the 2nd are never executed !!!
// However, the value of the local variable in the 2nd block remains correct!
// Some block 2
break;
case '3':
Serial.println("Block 3 starts executing");
// Some block 3
break;
case '4':
Serial.println("Block 4 starts executing");
// Some block 4
break;
}
}
```
Sketch uses 1596 bytes (4%) of program storage space…
Global variables use 244 bytes (11%) of dynamic memory…
=============================================================
Note the noticeably smaller code size in the second case.
Moreover, this does not depend on the number of blocks below the second one!
It looks like the linker just doesn't include them in the final code!
### Additional context
#### Additional reports
- https://github.com/arduino/Arduino/issues/11402
- https://github.com/arduino/Arduino/issues/11639
Contributor guide
Research direction
Start with the AVR and megaAVR compilation recipes and inspect how -fpermissive is applied. Reproduce the two switch examples, then compare the generated behavior and code-size reports with the additional reports in issues 11402 and 11639. Done means the cause is established and the compilation behavior no longer silently omits later switch blocks.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- build-system, compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100