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,
27312731 llvm::AttributeSet::get (getLLVMContext (), Attrs);
27322732 }
27332733
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.
27362736 // FIXME: fix this properly, https://reviews.llvm.org/D100388
27372737 if (FI.isInstanceMethod () && !IRFunctionArgs.hasInallocaArg () &&
27382738 !FI.arg_begin ()->type ->isVoidPointerType () && !IsThunk) {
@@ -2744,6 +2744,11 @@ void CodeGenModule::ConstructAttributeList(StringRef Name,
27442744
27452745 QualType ThisTy = FI.arg_begin ()->type .getTypePtr ()->getPointeeType ();
27462746
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+
27472752 if (!CodeGenOpts.NullPointerIsValid &&
27482753 getTypes ().getTargetAddressSpace (FI.arg_begin ()->type ) == 0 ) {
27492754 Attrs.addAttribute (llvm::Attribute::NonNull);
You can’t perform that action at this time.
0 commit comments