wlei added a comment.

In D109386#2990504 <https://reviews.llvm.org/D109386#2990504>, @rnk wrote:

> This seems incorrect: a weak VH won't have the same semantics, it will just 
> drop the comdat associativity when the underlying global changes type.

@rnk Thanks. Here I tried to use `WeakTrackingVH` working together with 
`replaceAllUsesWith` which is already there (in CodeGenModule.cpp:3904), my 
debugging dump showed like:

  GlobalCtors = [..,OldPtr];
  OldPtr->replaceAllUsesWith(NewPtr);
  GlobalCtors = [..,NewPtr];

I think this is what we desire. Do you think this can cause other issues or 
anything I missed?

> BTW, can this be tested, or is this only possible when clang is being used as 
> a library, perhaps as in swift?

Not swift, it seems this use-after-free needs a large program to repro, I tried 
to simplify it but failed to expose it by small program.



================
Comment at: clang/lib/CodeGen/CodeGenModule.cpp:3904
           llvm::ConstantExpr::getBitCast(GV, Entry->getType());
       Entry->replaceAllUsesWith(NewPtrForOldDecl);
     }
----------------
Here is the `replaceAllUsesWith` .


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109386/new/

https://reviews.llvm.org/D109386

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to