environment: mac os 14.2.1 (23C71)
3.2 GHz 六核Intel Core i7
Mac mini 2018
Xcode-15.2.0
our application has errors after update xCode from 14 to 15, minimal reproducible code is as follows:
-
- use Xcode-15.2.0 create a c++ command-line program
-
- paste the code into main.cpp
#include<iostream>
using namespace std;
void test(int var){
uint64_t value = var;
int size = sizeof(uint64_t);
int mostSignificantBit = size * 8;
// uint64_t var2 = value & (1 << (mostSignificantBit - 1)); // using this is ok
uint64_t var2 = value & (1 << (mostSignificantBit )); // using this results in program error
if(var2 > 0){
std::cout<<value<<std::endl;
}
std::cout<<var2<<std::endl;
}
int main(){
test(32);
return 0;
}
- 3 set the program into Release mode then build and run, then that corrupt stack shows an assemble instruction **ud2 (undefine) **
affect
uint64_t var2 = value & (1 << (mostSignificantBit ));
Perhaps the expression 1 << mostSignificantBit causes an overflow, leading the compiler to generate a "ud2" instruction in release mode. In our actual program, it resulted in a "brk #0x1" instruction, also causing a crash.
The most concerning aspect of this issue is that we didn't make any changes to our code; we simply upgraded from Xcode 14 to version 15. The compilation process went smoothly without any errors, then the testing team didn't notice any significant changes during their simple tests. Consequently, the program ran well, until it encountered these erroneous lines of code after the application was released online, leading to widespread crashes.