[PATCH] D119209: Implement -mctor_dtor_return_this ABI option.
scw created this revision. Herald added subscribers: dexonsmith, dang, kristof.beyls. scw requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits. This option forces constructors and non-deleting destructors to return `this` pointer. This is similar to ARM32, Apple ARM64, or Fuchsia C++ ABI, but can be applied to any target triple. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D119209 Files: clang/include/clang/Basic/CodeGenOptions.def clang/include/clang/Driver/Options.td clang/lib/CodeGen/CGCXXABI.h clang/lib/CodeGen/ItaniumCXXABI.cpp clang/lib/Driver/ToolChains/Clang.cpp clang/test/CodeGenCXX/constructor-destructor-return-this.cpp Index: clang/test/CodeGenCXX/constructor-destructor-return-this.cpp === --- clang/test/CodeGenCXX/constructor-destructor-return-this.cpp +++ clang/test/CodeGenCXX/constructor-destructor-return-this.cpp @@ -6,6 +6,8 @@ //RUN: %clang_cc1 %s -emit-llvm -o - -triple=x86_64-unknown-fuchsia | FileCheck --check-prefix=CHECKFUCHSIA %s //RUN: %clang_cc1 %s -emit-llvm -o - -triple=aarch64-unknown-fuchsia | FileCheck --check-prefix=CHECKFUCHSIA %s //RUN: %clang_cc1 %s -emit-llvm -o - -triple=i386-pc-win32 -fno-rtti | FileCheck --check-prefix=CHECKMS %s +//RUN: %clang_cc1 %s -emit-llvm -o - -triple=i686-unknown-linux-gnu -mctor-dtor-return-this | FileCheck --check-prefix=CHECKI686RET %s +//RUN: %clang_cc1 %s -emit-llvm -o - -triple=aarch64-unknown-linux-gnu -mctor-dtor-return-this | FileCheck --check-prefix=CHECKAARCH64 %s // FIXME: these tests crash on the bots when run with -triple=x86_64-pc-win32 // Make sure we attach the 'returned' attribute to the 'this' parameter of @@ -37,10 +39,15 @@ // CHECKGEN-LABEL: define{{.*}} void @_ZN1BD2Ev(%class.B* {{[^,]*}} %this) // CHECKGEN-LABEL: define{{.*}} void @_ZN1BD1Ev(%class.B* {{[^,]*}} %this) -// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i) -// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i) -// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BD2Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this) -// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BD1Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this) +// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} %this, i32* noundef %i) +// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} %this, i32* noundef %i) +// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BD2Ev(%class.B* {{[^,]*}} %this) +// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BD1Ev(%class.B* {{[^,]*}} %this) + +// CHECKARM-LABEL,CHECKAARCH64-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i) +// CHECKARM-LABEL,CHECKAARCH64-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i) +// CHECKARM-LABEL,CHECKAARCH64-LABEL: define{{.*}} %class.B* @_ZN1BD2Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this) +// CHECKARM-LABEL,CHECKAARCH64-LABEL: define{{.*}} %class.B* @_ZN1BD1Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this) // CHECKIOS5-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} %this, i32* noundef %i) // CHECKIOS5-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} %this, i32* noundef %i) @@ -74,13 +81,23 @@ // CHECKGEN-LABEL: define{{.*}} void @_ZN1CD0Ev(%class.C* {{[^,]*}} %this) // CHECKGEN-LABEL: define{{.*}} void @_ZThn8_N1CD0Ev(%class.C* noundef %this) -// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CC2EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c) -// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CC1EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c) -// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CD2Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this) -// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CD1Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this) +// CHECKI686RET-LABEL: define{{.*}} %class.C* @_ZN1CC2EPiPc(%class.C* {{[^,]*}} %this, i32* noundef %i, i8* noundef %c) +// CHECKI686RET-LABEL: define{{.*}} %class.C* @_ZN1CC1EPiPc(%class.C* {{[^,]*}} %this, i32* noundef %i, i8* noundef %c) +// CHECKI686RET-LABEL: define{{.*}} %class.C* @_ZN1CD2Ev(%class.C* {{[^,]*}} %this) +// CHECKI686RET-LABEL: define{{.*}} %class.C* @_ZN1CD1Ev(%class.C* {{[^,]*}} %this) +// CHECKI686RET-LABEL: define{{.*}} %class.C* @_ZThn8_N1CD1Ev(%class.C* noundef %this) +// CHECKI686RET-LABEL: define{{.*}} void @_ZN1CD0Ev(%class.C* {{[^,]*}} %this) +// CHECKI686RET-LABEL: define{{.*}} void @_ZThn8_N1CD0Ev(%class.C* noundef %this) + +// CHECKARM-LABEL,CHECKAARCH64-LABEL: define{{.*}} %class.C* @_ZN1CC2EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c) +// CHECKARM-LABEL,CHECKAARCH64-LABEL: define{{.*}} %cla
[PATCH] D119209: Implement -mctor_dtor_return_this ABI option.
scw updated this revision to Diff 463722. scw edited the summary of this revision. scw added a comment. Herald added a subscriber: MaskRay. Herald added a project: All. Rebased and updated comments and option explain text to only affect Itanium C++ ABI. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D119209/new/ https://reviews.llvm.org/D119209 Files: clang/include/clang/Basic/CodeGenOptions.def clang/include/clang/Driver/Options.td clang/lib/CodeGen/CGCXXABI.h clang/lib/CodeGen/ItaniumCXXABI.cpp clang/lib/Driver/ToolChains/Clang.cpp clang/test/CodeGenCXX/constructor-destructor-return-this.cpp Index: clang/test/CodeGenCXX/constructor-destructor-return-this.cpp === --- clang/test/CodeGenCXX/constructor-destructor-return-this.cpp +++ clang/test/CodeGenCXX/constructor-destructor-return-this.cpp @@ -6,6 +6,8 @@ //RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=x86_64-unknown-fuchsia | FileCheck --check-prefix=CHECKFUCHSIA %s //RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=aarch64-unknown-fuchsia | FileCheck --check-prefix=CHECKFUCHSIA %s //RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=i386-pc-win32 -fno-rtti | FileCheck --check-prefix=CHECKMS %s +//RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=i686-unknown-linux-gnu -mctor-dtor-return-this | FileCheck --check-prefix=CHECKI686RET %s +//RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=aarch64-unknown-linux-gnu -mctor-dtor-return-this | FileCheck --check-prefix=CHECKAARCH64RET %s // FIXME: these tests crash on the bots when run with -triple=x86_64-pc-win32 // Make sure we attach the 'returned' attribute to the 'this' parameter of @@ -37,10 +39,15 @@ // CHECKGEN-LABEL: define{{.*}} void @_ZN1BD2Ev(%class.B* {{[^,]*}} %this) // CHECKGEN-LABEL: define{{.*}} void @_ZN1BD1Ev(%class.B* {{[^,]*}} %this) -// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i) -// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i) -// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BD2Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this) -// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BD1Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.B* @_ZN1BD2Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.B* @_ZN1BD1Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this) + +// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} %this, i32* noundef %i) +// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} %this, i32* noundef %i) +// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BD2Ev(%class.B* {{[^,]*}} %this) +// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BD1Ev(%class.B* {{[^,]*}} %this) // CHECKIOS5-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} %this, i32* noundef %i) // CHECKIOS5-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} %this, i32* noundef %i) @@ -74,13 +81,23 @@ // CHECKGEN-LABEL: define{{.*}} void @_ZN1CD0Ev(%class.C* {{[^,]*}} %this) // CHECKGEN-LABEL: define{{.*}} void @_ZThn8_N1CD0Ev(%class.C* noundef %this) -// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CC2EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c) -// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CC1EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c) -// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CD2Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this) -// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CD1Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZN1CC2EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZN1CC1EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZN1CD2Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZN1CD1Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this) // CHECKARM-LABEL: define{{.*}} %class.C* @_ZThn8_N1CD1Ev(%class.C* noundef %this) -// CHECKARM-LABEL: define{{.*}} void @_ZN1CD0Ev(%class.C* {{[^,]*}} %this) +// CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZThn16_N1CD1Ev(%class.C* noundef %this) +// CHECKARM-LABEL,CHECKA
[PATCH] D119209: Implement -fctor_dtor_return_this ABI option.
scw updated this revision to Diff 464793. scw retitled this revision from "Implement -mctor_dtor_return_this ABI option. " to "Implement -fctor_dtor_return_this ABI option.". scw edited the summary of this revision. scw added a comment. - Made the option cc1-only (invoke through -Xclang). - Changed the name to -f... from -m... - Remove mentioning of Itanium ABI--it applies to all C++ ABIs but is overridden by the Microsoft one. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D119209/new/ https://reviews.llvm.org/D119209 Files: clang/include/clang/Basic/CodeGenOptions.def clang/include/clang/Driver/Options.td clang/lib/CodeGen/CGCXXABI.h clang/lib/CodeGen/ItaniumCXXABI.cpp clang/lib/Driver/ToolChains/Clang.cpp clang/test/CodeGenCXX/constructor-destructor-return-this.cpp Index: clang/test/CodeGenCXX/constructor-destructor-return-this.cpp === --- clang/test/CodeGenCXX/constructor-destructor-return-this.cpp +++ clang/test/CodeGenCXX/constructor-destructor-return-this.cpp @@ -6,6 +6,8 @@ //RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=x86_64-unknown-fuchsia | FileCheck --check-prefix=CHECKFUCHSIA %s //RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=aarch64-unknown-fuchsia | FileCheck --check-prefix=CHECKFUCHSIA %s //RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=i386-pc-win32 -fno-rtti | FileCheck --check-prefix=CHECKMS %s +//RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=i686-unknown-linux-gnu -fctor-dtor-return-this | FileCheck --check-prefix=CHECKI686RET %s +//RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=aarch64-unknown-linux-gnu -fctor-dtor-return-this | FileCheck --check-prefix=CHECKAARCH64RET %s // FIXME: these tests crash on the bots when run with -triple=x86_64-pc-win32 // Make sure we attach the 'returned' attribute to the 'this' parameter of @@ -37,10 +39,15 @@ // CHECKGEN-LABEL: define{{.*}} void @_ZN1BD2Ev(%class.B* {{[^,]*}} %this) // CHECKGEN-LABEL: define{{.*}} void @_ZN1BD1Ev(%class.B* {{[^,]*}} %this) -// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i) -// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i) -// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BD2Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this) -// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BD1Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.B* @_ZN1BD2Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.B* @_ZN1BD1Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this) + +// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} %this, i32* noundef %i) +// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} %this, i32* noundef %i) +// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BD2Ev(%class.B* {{[^,]*}} %this) +// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BD1Ev(%class.B* {{[^,]*}} %this) // CHECKIOS5-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} %this, i32* noundef %i) // CHECKIOS5-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} %this, i32* noundef %i) @@ -74,13 +81,23 @@ // CHECKGEN-LABEL: define{{.*}} void @_ZN1CD0Ev(%class.C* {{[^,]*}} %this) // CHECKGEN-LABEL: define{{.*}} void @_ZThn8_N1CD0Ev(%class.C* noundef %this) -// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CC2EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c) -// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CC1EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c) -// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CD2Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this) -// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CD1Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZN1CC2EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZN1CC1EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZN1CD2Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZN1CD1Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this) // CHECKARM-LABEL: define{{.*}} %class.C* @_ZThn8_N1CD1Ev(%c
[PATCH] D119209: Implement -fctor_dtor_return_this ABI option.
scw updated this revision to Diff 464801. scw added a comment. Remove unnecessary curly braces. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D119209/new/ https://reviews.llvm.org/D119209 Files: clang/include/clang/Basic/CodeGenOptions.def clang/include/clang/Driver/Options.td clang/lib/CodeGen/CGCXXABI.h clang/lib/CodeGen/ItaniumCXXABI.cpp clang/lib/Driver/ToolChains/Clang.cpp clang/test/CodeGenCXX/constructor-destructor-return-this.cpp Index: clang/test/CodeGenCXX/constructor-destructor-return-this.cpp === --- clang/test/CodeGenCXX/constructor-destructor-return-this.cpp +++ clang/test/CodeGenCXX/constructor-destructor-return-this.cpp @@ -6,6 +6,8 @@ //RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=x86_64-unknown-fuchsia | FileCheck --check-prefix=CHECKFUCHSIA %s //RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=aarch64-unknown-fuchsia | FileCheck --check-prefix=CHECKFUCHSIA %s //RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=i386-pc-win32 -fno-rtti | FileCheck --check-prefix=CHECKMS %s +//RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=i686-unknown-linux-gnu -fctor-dtor-return-this | FileCheck --check-prefix=CHECKI686RET %s +//RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=aarch64-unknown-linux-gnu -fctor-dtor-return-this | FileCheck --check-prefix=CHECKAARCH64RET %s // FIXME: these tests crash on the bots when run with -triple=x86_64-pc-win32 // Make sure we attach the 'returned' attribute to the 'this' parameter of @@ -37,10 +39,15 @@ // CHECKGEN-LABEL: define{{.*}} void @_ZN1BD2Ev(%class.B* {{[^,]*}} %this) // CHECKGEN-LABEL: define{{.*}} void @_ZN1BD1Ev(%class.B* {{[^,]*}} %this) -// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i) -// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i) -// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BD2Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this) -// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BD1Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.B* @_ZN1BD2Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.B* @_ZN1BD1Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this) + +// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} %this, i32* noundef %i) +// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} %this, i32* noundef %i) +// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BD2Ev(%class.B* {{[^,]*}} %this) +// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BD1Ev(%class.B* {{[^,]*}} %this) // CHECKIOS5-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} %this, i32* noundef %i) // CHECKIOS5-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} %this, i32* noundef %i) @@ -74,13 +81,23 @@ // CHECKGEN-LABEL: define{{.*}} void @_ZN1CD0Ev(%class.C* {{[^,]*}} %this) // CHECKGEN-LABEL: define{{.*}} void @_ZThn8_N1CD0Ev(%class.C* noundef %this) -// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CC2EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c) -// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CC1EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c) -// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CD2Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this) -// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CD1Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZN1CC2EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZN1CC1EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZN1CD2Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZN1CD1Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this) // CHECKARM-LABEL: define{{.*}} %class.C* @_ZThn8_N1CD1Ev(%class.C* noundef %this) -// CHECKARM-LABEL: define{{.*}} void @_ZN1CD0Ev(%class.C* {{[^,]*}} %this) +// CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZThn16_N1CD1Ev(%class.C* noundef %this) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} void @_ZN1CD0Ev(%class.C* {{[^,]*}} %this) // CHECKARM-LABEL: define{{.*}} void @_ZThn8_N1CD0Ev(%class.C* noundef %this) +// CHE
[PATCH] D119209: [clang] Add cc1 option -fctor-dtor-return-this
scw updated this revision to Diff 464809. scw marked 2 inline comments as done. scw retitled this revision from "Implement -fctor_dtor_return_this ABI option." to "[clang] Add cc1 option -fctor-dtor-return-this". Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D119209/new/ https://reviews.llvm.org/D119209 Files: clang/include/clang/Basic/CodeGenOptions.def clang/include/clang/Driver/Options.td clang/lib/CodeGen/CGCXXABI.h clang/lib/CodeGen/ItaniumCXXABI.cpp clang/test/CodeGenCXX/constructor-destructor-return-this.cpp Index: clang/test/CodeGenCXX/constructor-destructor-return-this.cpp === --- clang/test/CodeGenCXX/constructor-destructor-return-this.cpp +++ clang/test/CodeGenCXX/constructor-destructor-return-this.cpp @@ -6,6 +6,8 @@ //RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=x86_64-unknown-fuchsia | FileCheck --check-prefix=CHECKFUCHSIA %s //RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=aarch64-unknown-fuchsia | FileCheck --check-prefix=CHECKFUCHSIA %s //RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=i386-pc-win32 -fno-rtti | FileCheck --check-prefix=CHECKMS %s +//RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=i686-unknown-linux-gnu -fctor-dtor-return-this | FileCheck --check-prefix=CHECKI686RET %s +//RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=aarch64-unknown-linux-gnu -fctor-dtor-return-this | FileCheck --check-prefix=CHECKAARCH64RET %s // FIXME: these tests crash on the bots when run with -triple=x86_64-pc-win32 // Make sure we attach the 'returned' attribute to the 'this' parameter of @@ -37,10 +39,15 @@ // CHECKGEN-LABEL: define{{.*}} void @_ZN1BD2Ev(%class.B* {{[^,]*}} %this) // CHECKGEN-LABEL: define{{.*}} void @_ZN1BD1Ev(%class.B* {{[^,]*}} %this) -// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i) -// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i) -// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BD2Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this) -// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BD1Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.B* @_ZN1BD2Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.B* @_ZN1BD1Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this) + +// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} %this, i32* noundef %i) +// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} %this, i32* noundef %i) +// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BD2Ev(%class.B* {{[^,]*}} %this) +// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BD1Ev(%class.B* {{[^,]*}} %this) // CHECKIOS5-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} %this, i32* noundef %i) // CHECKIOS5-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} %this, i32* noundef %i) @@ -74,13 +81,23 @@ // CHECKGEN-LABEL: define{{.*}} void @_ZN1CD0Ev(%class.C* {{[^,]*}} %this) // CHECKGEN-LABEL: define{{.*}} void @_ZThn8_N1CD0Ev(%class.C* noundef %this) -// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CC2EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c) -// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CC1EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c) -// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CD2Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this) -// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CD1Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZN1CC2EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZN1CC1EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZN1CD2Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZN1CD1Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this) // CHECKARM-LABEL: define{{.*}} %class.C* @_ZThn8_N1CD1Ev(%class.C* noundef %this) -// CHECKARM-LABEL: define{{.*}} void @_ZN1CD0Ev(%class.C* {{[^,]*}} %this) +// CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZThn16_N1CD1Ev(%class.C* noundef %this) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} void @_ZN1CD0Ev(%class.C* {{[^,]*}} %this) // CHECKA
[PATCH] D119209: [clang] Add cc1 option -fctor-dtor-return-this
scw marked an inline comment as done. scw added inline comments. Comment at: clang/include/clang/Driver/Options.td:5608 +def fctor_dtor_return_this : Flag<["-"], "fctor-dtor-return-this">, + HelpText<"Change the C++ ABI to returning `this` pointer from constructors " + "and non-deleting destructors. (No effect on Microsoft ABI.)">, MaskRay wrote: > If you use Itanium C++ ABI, it's clear it doesn't change Microsoft ABI. > > The convention for HelpText is to omit the trailing period. I was gonna do that but realized the change actually apply to all C++ ABIs (I changed CGCXXABI). It's just Microsoft overrides the same method I changed making it a no-op. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D119209/new/ https://reviews.llvm.org/D119209 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D119209: [clang] Add cc1 option -fctor-dtor-return-this
This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG3933c43d9008: [clang] Add cc1 option -fctor-dtor-return-this (authored by scw). Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D119209/new/ https://reviews.llvm.org/D119209 Files: clang/include/clang/Basic/CodeGenOptions.def clang/include/clang/Driver/Options.td clang/lib/CodeGen/CGCXXABI.h clang/lib/CodeGen/ItaniumCXXABI.cpp clang/test/CodeGenCXX/constructor-destructor-return-this.cpp Index: clang/test/CodeGenCXX/constructor-destructor-return-this.cpp === --- clang/test/CodeGenCXX/constructor-destructor-return-this.cpp +++ clang/test/CodeGenCXX/constructor-destructor-return-this.cpp @@ -6,6 +6,8 @@ //RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=x86_64-unknown-fuchsia | FileCheck --check-prefix=CHECKFUCHSIA %s //RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=aarch64-unknown-fuchsia | FileCheck --check-prefix=CHECKFUCHSIA %s //RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=i386-pc-win32 -fno-rtti | FileCheck --check-prefix=CHECKMS %s +//RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=i686-unknown-linux-gnu -fctor-dtor-return-this | FileCheck --check-prefix=CHECKI686RET %s +//RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=aarch64-unknown-linux-gnu -fctor-dtor-return-this | FileCheck --check-prefix=CHECKAARCH64RET %s // FIXME: these tests crash on the bots when run with -triple=x86_64-pc-win32 // Make sure we attach the 'returned' attribute to the 'this' parameter of @@ -37,10 +39,15 @@ // CHECKGEN-LABEL: define{{.*}} void @_ZN1BD2Ev(%class.B* {{[^,]*}} %this) // CHECKGEN-LABEL: define{{.*}} void @_ZN1BD1Ev(%class.B* {{[^,]*}} %this) -// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i) -// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i) -// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BD2Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this) -// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BD1Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.B* @_ZN1BD2Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.B* @_ZN1BD1Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this) + +// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} %this, i32* noundef %i) +// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} %this, i32* noundef %i) +// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BD2Ev(%class.B* {{[^,]*}} %this) +// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BD1Ev(%class.B* {{[^,]*}} %this) // CHECKIOS5-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} %this, i32* noundef %i) // CHECKIOS5-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} %this, i32* noundef %i) @@ -74,13 +81,23 @@ // CHECKGEN-LABEL: define{{.*}} void @_ZN1CD0Ev(%class.C* {{[^,]*}} %this) // CHECKGEN-LABEL: define{{.*}} void @_ZThn8_N1CD0Ev(%class.C* noundef %this) -// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CC2EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c) -// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CC1EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c) -// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CD2Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this) -// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CD1Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZN1CC2EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZN1CC1EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZN1CD2Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZN1CD1Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this) // CHECKARM-LABEL: define{{.*}} %class.C* @_ZThn8_N1CD1Ev(%class.C* noundef %this) -// CHECKARM-LABEL: define{{.*}} void @_ZN1CD0Ev(%class.C* {{[^,]*}} %this) +// CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZThn16_N1CD1Ev(%class.C* noundef %this) +// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} void @_ZN1CD0Ev(%class.C* {{[^,]*}} %
[PATCH] D100450: [libTooling] Add smart pointer support to the `access` Stencil
scw created this revision. scw requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits. This extends smart pointer support beyond the existing `maybeDeref` and `maybeAddressOf`. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D100450 Files: clang/lib/Tooling/Transformer/Stencil.cpp clang/unittests/Tooling/StencilTest.cpp Index: clang/unittests/Tooling/StencilTest.cpp === --- clang/unittests/Tooling/StencilTest.cpp +++ clang/unittests/Tooling/StencilTest.cpp @@ -392,6 +392,37 @@ testExpr(Id, Snippet, access(Id, "field"), "x->field"); } +TEST_F(StencilTest, AccessOpSmartPointer) { + StringRef Snippet = R"cc( +Smart x; +x; + )cc"; + StringRef Id = "id"; + testExpr(Id, Snippet, access(Id, "field"), "x->field"); +} + +TEST_F(StencilTest, AccessOpSmartPointerDereference) { + StringRef Snippet = R"cc( +Smart x; +*x; + )cc"; + StringRef Id = "id"; + testExpr(Id, Snippet, access(Id, "field"), "(*x).field"); +} + +TEST_F(StencilTest, AccessOpSmartPointerMemberCall) { + StringRef Snippet = R"cc( +Smart x; +x->Field; + )cc"; + StringRef Id = "id"; + auto StmtMatch = + matchStmt(Snippet, memberExpr(hasObjectExpression(expr().bind(Id; + ASSERT_TRUE(StmtMatch); + EXPECT_THAT_EXPECTED(access(Id, "field")->eval(StmtMatch->Result), + HasValue("x->field")); +} + TEST_F(StencilTest, AccessOpExplicitThis) { using clang::ast_matchers::hasObjectExpression; using clang::ast_matchers::memberExpr; Index: clang/lib/Tooling/Transformer/Stencil.cpp === --- clang/lib/Tooling/Transformer/Stencil.cpp +++ clang/lib/Tooling/Transformer/Stencil.cpp @@ -323,10 +323,23 @@ return llvm::make_error(errc::invalid_argument, "Id not bound: " + Data.BaseId); if (!E->isImplicitCXXThis()) { -if (llvm::Optional S = -E->getType()->isAnyPointerType() -? tooling::buildArrow(*E, *Match.Context) -: tooling::buildDot(*E, *Match.Context)) +llvm::Optional S; +if (E->getType()->isAnyPointerType() || +isSmartPointerType(E->getType(), *Match.Context)) { + // Strip off any operator->. This can only occur inside an actual arrow + // member access, so we treat it as equivalent to an actual object + // expression. + if (const auto *OpCall = dyn_cast(E)) { +if (OpCall->getOperator() == clang::OO_Arrow && +OpCall->getNumArgs() == 1) { + E = OpCall->getArg(0); +} + } + S = tooling::buildArrow(*E, *Match.Context); +} else { + S = tooling::buildDot(*E, *Match.Context); +} +if (S.hasValue()) *Result += *S; else return llvm::make_error( Index: clang/unittests/Tooling/StencilTest.cpp === --- clang/unittests/Tooling/StencilTest.cpp +++ clang/unittests/Tooling/StencilTest.cpp @@ -392,6 +392,37 @@ testExpr(Id, Snippet, access(Id, "field"), "x->field"); } +TEST_F(StencilTest, AccessOpSmartPointer) { + StringRef Snippet = R"cc( +Smart x; +x; + )cc"; + StringRef Id = "id"; + testExpr(Id, Snippet, access(Id, "field"), "x->field"); +} + +TEST_F(StencilTest, AccessOpSmartPointerDereference) { + StringRef Snippet = R"cc( +Smart x; +*x; + )cc"; + StringRef Id = "id"; + testExpr(Id, Snippet, access(Id, "field"), "(*x).field"); +} + +TEST_F(StencilTest, AccessOpSmartPointerMemberCall) { + StringRef Snippet = R"cc( +Smart x; +x->Field; + )cc"; + StringRef Id = "id"; + auto StmtMatch = + matchStmt(Snippet, memberExpr(hasObjectExpression(expr().bind(Id; + ASSERT_TRUE(StmtMatch); + EXPECT_THAT_EXPECTED(access(Id, "field")->eval(StmtMatch->Result), + HasValue("x->field")); +} + TEST_F(StencilTest, AccessOpExplicitThis) { using clang::ast_matchers::hasObjectExpression; using clang::ast_matchers::memberExpr; Index: clang/lib/Tooling/Transformer/Stencil.cpp === --- clang/lib/Tooling/Transformer/Stencil.cpp +++ clang/lib/Tooling/Transformer/Stencil.cpp @@ -323,10 +323,23 @@ return llvm::make_error(errc::invalid_argument, "Id not bound: " + Data.BaseId); if (!E->isImplicitCXXThis()) { -if (llvm::Optional S = -E->getType()->isAnyPointerType() -? tooling::buildArrow(*E, *Match.Context) -: tooling::buildDot(*E, *Match.Context)) +llvm::Optional S; +if (E->getType()->isAnyPointerType() || +isSmartPointerType(E->getType(), *Match.Context)) { + // Strip off any operator->. This can only occur inside an actual arrow + // member access, so we treat it as equivalent to an actual object
[PATCH] D100450: [libTooling] Add smart pointer support to the `access` Stencil
This revision was automatically updated to reflect the committed changes. Closed by commit rG1c5717225e89: [libTooling] Add smart pointer support to the `access` Stencil (authored by scw). Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D100450/new/ https://reviews.llvm.org/D100450 Files: clang/lib/Tooling/Transformer/Stencil.cpp clang/unittests/Tooling/StencilTest.cpp Index: clang/unittests/Tooling/StencilTest.cpp === --- clang/unittests/Tooling/StencilTest.cpp +++ clang/unittests/Tooling/StencilTest.cpp @@ -392,6 +392,37 @@ testExpr(Id, Snippet, access(Id, "field"), "x->field"); } +TEST_F(StencilTest, AccessOpSmartPointer) { + StringRef Snippet = R"cc( +Smart x; +x; + )cc"; + StringRef Id = "id"; + testExpr(Id, Snippet, access(Id, "field"), "x->field"); +} + +TEST_F(StencilTest, AccessOpSmartPointerDereference) { + StringRef Snippet = R"cc( +Smart x; +*x; + )cc"; + StringRef Id = "id"; + testExpr(Id, Snippet, access(Id, "field"), "(*x).field"); +} + +TEST_F(StencilTest, AccessOpSmartPointerMemberCall) { + StringRef Snippet = R"cc( +Smart x; +x->Field; + )cc"; + StringRef Id = "id"; + auto StmtMatch = + matchStmt(Snippet, memberExpr(hasObjectExpression(expr().bind(Id; + ASSERT_TRUE(StmtMatch); + EXPECT_THAT_EXPECTED(access(Id, "field")->eval(StmtMatch->Result), + HasValue("x->field")); +} + TEST_F(StencilTest, AccessOpExplicitThis) { using clang::ast_matchers::hasObjectExpression; using clang::ast_matchers::memberExpr; Index: clang/lib/Tooling/Transformer/Stencil.cpp === --- clang/lib/Tooling/Transformer/Stencil.cpp +++ clang/lib/Tooling/Transformer/Stencil.cpp @@ -323,10 +323,23 @@ return llvm::make_error(errc::invalid_argument, "Id not bound: " + Data.BaseId); if (!E->isImplicitCXXThis()) { -if (llvm::Optional S = -E->getType()->isAnyPointerType() -? tooling::buildArrow(*E, *Match.Context) -: tooling::buildDot(*E, *Match.Context)) +llvm::Optional S; +if (E->getType()->isAnyPointerType() || +isSmartPointerType(E->getType(), *Match.Context)) { + // Strip off any operator->. This can only occur inside an actual arrow + // member access, so we treat it as equivalent to an actual object + // expression. + if (const auto *OpCall = dyn_cast(E)) { +if (OpCall->getOperator() == clang::OO_Arrow && +OpCall->getNumArgs() == 1) { + E = OpCall->getArg(0); +} + } + S = tooling::buildArrow(*E, *Match.Context); +} else { + S = tooling::buildDot(*E, *Match.Context); +} +if (S.hasValue()) *Result += *S; else return llvm::make_error( Index: clang/unittests/Tooling/StencilTest.cpp === --- clang/unittests/Tooling/StencilTest.cpp +++ clang/unittests/Tooling/StencilTest.cpp @@ -392,6 +392,37 @@ testExpr(Id, Snippet, access(Id, "field"), "x->field"); } +TEST_F(StencilTest, AccessOpSmartPointer) { + StringRef Snippet = R"cc( +Smart x; +x; + )cc"; + StringRef Id = "id"; + testExpr(Id, Snippet, access(Id, "field"), "x->field"); +} + +TEST_F(StencilTest, AccessOpSmartPointerDereference) { + StringRef Snippet = R"cc( +Smart x; +*x; + )cc"; + StringRef Id = "id"; + testExpr(Id, Snippet, access(Id, "field"), "(*x).field"); +} + +TEST_F(StencilTest, AccessOpSmartPointerMemberCall) { + StringRef Snippet = R"cc( +Smart x; +x->Field; + )cc"; + StringRef Id = "id"; + auto StmtMatch = + matchStmt(Snippet, memberExpr(hasObjectExpression(expr().bind(Id; + ASSERT_TRUE(StmtMatch); + EXPECT_THAT_EXPECTED(access(Id, "field")->eval(StmtMatch->Result), + HasValue("x->field")); +} + TEST_F(StencilTest, AccessOpExplicitThis) { using clang::ast_matchers::hasObjectExpression; using clang::ast_matchers::memberExpr; Index: clang/lib/Tooling/Transformer/Stencil.cpp === --- clang/lib/Tooling/Transformer/Stencil.cpp +++ clang/lib/Tooling/Transformer/Stencil.cpp @@ -323,10 +323,23 @@ return llvm::make_error(errc::invalid_argument, "Id not bound: " + Data.BaseId); if (!E->isImplicitCXXThis()) { -if (llvm::Optional S = -E->getType()->isAnyPointerType() -? tooling::buildArrow(*E, *Match.Context) -: tooling::buildDot(*E, *Match.Context)) +llvm::Optional S; +if (E->getType()->isAnyPointerType() || +isSmartPointerType(E->getType(), *Match.Context)) { + // Strip off any operator->. This can only occur inside an actual arrow + // member access, so we treat it as eq
[PATCH] D100450: [libTooling] Add smart pointer support to the `access` Stencil
scw added inline comments. Comment at: clang/unittests/Tooling/StencilTest.cpp:410 + StringRef Id = "id"; + testExpr(Id, Snippet, access(Id, "field"), "(*x).field"); +} ymandel wrote: > Hmm. Looks like we could use smart pointer support in tooling::buildAddressOf > as well. If you're interested, the code is at > clang/lib/Tooling/Transformer/SourceCodeBuilders.cpp line 94 > but I understand if you want to stop here. :) I don't think this particular output "(*x).field" is from `buildAddressOf`. Instead, it's in `buildDot` where `*x` is `x.operator*()` instead of `UO_Deref`. Yes, there's potential improvement but at least it's correct output comparing to this change which fixes "x->->field" so I'm leaving it along just adding the test case to highlight the potential. As for `buildAddressOf`, we shouldn't change `&*x` to `x` when `x` is a smart pointer -- the types don't match and may result in ill-typed expressions. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D100450/new/ https://reviews.llvm.org/D100450 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits