Index: lib/CodeGen/CGDecl.cpp =================================================================== --- lib/CodeGen/CGDecl.cpp +++ lib/CodeGen/CGDecl.cpp @@ -1885,4 +1885,7 @@ if (D.hasAttr()) EmitVarAnnotations(&D, DeclPtr.getPointer()); + + MarkWriteOnceWritten MWO(*this, D, + DeclPtr.isValid() ? DeclPtr.getPointer() : nullptr); } Index: test/CodeGenCXX/const-invariant.cpp =================================================================== --- test/CodeGenCXX/const-invariant.cpp +++ test/CodeGenCXX/const-invariant.cpp @@ -361,6 +361,18 @@ // CHECK-L-CO: call {{.*}}@llvm.invariant.end({{.*}}, i64 {{[0-9]+}}, i8* } +#ifdef LOCAL +void ex1_parms(Const Type i) { +// CHECK: @_Z9ex1_parms1A( + // CHECK-L-CO: store {{.*}} %i + // CHECK-L-CO: call {{.*}}@llvm.invariant.start( + bar(i); + foo(&i); // May change i. + bar(i); + // CHECK-L-CO: call {{.*}}@llvm.invariant.end( +} +#endif + // CHECK-G-CO-OBJ: call {{.*}}@llvm.invariant.start(i64 {{[0-9]+}}, i8* bitcast ({{.*}} @_ZL1j to i8*)) // CHECK-G-CO-INT: store {{.*}}, {{.*}}* @_ZL1j