llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[analyzer] Invalidate the object in opaque ctor calls regardless if an arg refers to it

Open steakhal opened this issue 10 months ago • 4 comments

The conservative call invalidation logic is a bit complicated, and would deserve some refactoring.

When a call has some arguments, we escape them. Except, if its a pointer to constant storage - because we assume that the program honors const-correctness.

In that case, it puts it in the "Preserved" list to keep its contents. However, if we had a constructor call that's job is to initialize an object had a const pointer/reference parameter then the invalidation didn't take place.

This meant that if the object was on the stack, that we start warning about uninitialized fields when accessed. (See the example) Similar could be achieved on the heap of course.

We should have honored the fact that the constructor should initialize the pointee of "this", thus escape that region regardless (in other words, don't put it on the "preserved" list).

This doesn't fix the root cause, but cures a symptom. Ideally, we should redesign the argument invalidation from the ground up. See the attached FIXME test case.

rdar://156942972 (cherry picked from commit efa32e36323e0c92b33c34aea61009026c164686)

steakhal avatar Jan 14 '26 12:01 steakhal

@swift-ci please test llvm

steakhal avatar Jan 15 '26 09:01 steakhal

@swift-ci please test

steakhal avatar Jan 15 '26 09:01 steakhal

@swift-ci please test macOS

steakhal avatar Jan 16 '26 08:01 steakhal

@swift-ci please test macOS

steakhal avatar Jan 16 '26 16:01 steakhal

@swift-ci please test macOS

steakhal avatar Jan 17 '26 08:01 steakhal

This is getting really ridiculous. 5th time the charm. @swift-ci please test macOS

steakhal avatar Jan 18 '26 11:01 steakhal

Maybe the lucky 6 will work. That's the highest you can roll on a usual cube. @swift-ci please test macOS

steakhal avatar Jan 20 '26 15:01 steakhal

02:28:20    Clang :: Modules/pch-config-macros.c
02:28:20    LLVM :: Transforms/IndVarSimplify/unreachable-exit.ll

These two are known failures.

ziqingluo-90 avatar Jan 21 '26 21:01 ziqingluo-90

@swift-ci please test macOS

steakhal avatar Jan 22 '26 09:01 steakhal