When I compile a C++ program that uses assembly (using Visual Studio 2022), some of the assembly code appears to be adjusted or at least optimized away (but I have optimizations disabled).
Does anyone know what's going on and how I can make it not do this?
The purpose behind this code (at least the non-summarized version) is to create a wrapper class for another class defined in a DLL that I do not have the source for. Essentially, I am calling the constructor of the DLL class which requires ECX to be an address in the stack that points to 0 (an empty pointer).
SampleClass.h
class SampleClass
{
public:
    SampleClass();
private:
    uintptr_t value1;
};
SampleClass.cpp
SampleClass::SampleClass() : 
    value1(0)
{
    __asm {
        // When I compile this converts to LEA ECX, 0...
        // I want it to hold the value for the address of value1.
        LEA ECX, DWORD PTR SS : [value1]
    }
}
If I adjust the function to this, it doesn't remove/change the code... but crashes at the end of the function saying that the stack data around value2 is corrupt.
SampleClass::SampleClass() : 
    value1(0)
{
    uintptr_t value2;
    __asm {
        LEA ECX, DWORD PTR SS : [value2]
    }
    value1 = value2;
    // Crashes here...
}
 
    