File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -2731,8 +2731,8 @@ void CodeGenModule::ConstructAttributeList(StringRef Name,
2731
2731
llvm::AttributeSet::get (getLLVMContext (), Attrs);
2732
2732
}
2733
2733
2734
- // Apply `nonnull`, `dereferenceable(N)` and `align N` to the `this` argument,
2735
- // unless this is a thunk function.
2734
+ // Apply `nonnull`, `dereferenceable(N)`, `align N` (and `noalias` for
2735
+ // constructors) to the `this` argument, unless this is a thunk function.
2736
2736
// FIXME: fix this properly, https://reviews.llvm.org/D100388
2737
2737
if (FI.isInstanceMethod () && !IRFunctionArgs.hasInallocaArg () &&
2738
2738
!FI.arg_begin ()->type ->isVoidPointerType () && !IsThunk) {
@@ -2744,6 +2744,11 @@ void CodeGenModule::ConstructAttributeList(StringRef Name,
2744
2744
2745
2745
QualType ThisTy = FI.arg_begin ()->type .getTypePtr ()->getPointeeType ();
2746
2746
2747
+ // According to [class.cdtor]/2, the value of the object is unspecified if
2748
+ // its elements are accessed not through `this`.
2749
+ if (isa_and_nonnull<CXXConstructorDecl>(TargetDecl))
2750
+ Attrs.addAttribute (llvm::Attribute::NoAlias);
2751
+
2747
2752
if (!CodeGenOpts.NullPointerIsValid &&
2748
2753
getTypes ().getTargetAddressSpace (FI.arg_begin ()->type ) == 0 ) {
2749
2754
Attrs.addAttribute (llvm::Attribute::NonNull);
You can’t perform that action at this time.
0 commit comments