arduino / arduino/ArduinoCore-avr
wrong processing of uint64
- Dominant language
- C
- Stars
- 1.5k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
When manipulating uint64_t, variables declared in a class in a translation unit, the results of operations are wrong if there is an access to other same class variables.
3 files were used for the purpose of showing this in the same arduino sketch:
issue.ino:
``` c++
#include "Arduino.h"
#include "tu.h"
#define ISSUE_HAPPENS
void setup()
{
Serial.begin(115200);
}
void loop()
{
foo.baz = 2;
#if defined(ISSUE_HAPPENS)
if( (foo.bar & (1ULL << 9)) && (foo.bar & (1ULL << 10)) )
Serial.println("right");
else
Serial.println("wrong");
#else
uint64_t a = 0x8000000010000602;
uint64_t b = 0x8000000010000602;
if( (a & (1ULL << 9)) && (b & (1ULL << 10)) )
Serial.println("right");
else
Serial.println("wrong");
#endif
delay(1000);
}
```
tu.cpp:
```c++
#include "tu.h"
Foo foo;
```
tu.h
```c++
#include
#pragma once
class Foo
{
public:
uint64_t bar = 0x8000000010000602;
uint8_t baz = 4;
};
extern Foo foo;
```
The output, when `#define ISSUE_HAPPENS` is uncommented, is `wrong`. When it is commented it is `right` as it is supposed to be.
This happens in arduino 1.8.8 but not in arduino 1.8.5. Using a different tool, sloeber arduino plugin for eclipse, it happens when the toolchain has gcc version 5.4.0 but not when it has the version 4.9.2.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with issue.ino, tu.cpp, and tu.h, reproducing the sketch under the Arduino 1.8.8 and 1.8.5 toolchains described in the report. Compare the uint64_t class-member case with the local-variable case and identify whether the behavior belongs to the AVR core or compiler toolchain. Done means the reported expression produces the expected result with a regression test or reproducible verification.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers, embedded-iot
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100