ZarkoCA created this revision. ZarkoCA added reviewers: bmahjour, nemanjai, jsji, PowerPC. Herald added subscribers: shchenz, kbarton. ZarkoCA requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
LLVM (llc) will crash when a user specifies a number out of the allowed range (0-31) for b. This patch provides a clang diagnostic so we error out gracefully and point out the user error. Further documentation for the builtins can be found here: https://www.ibm.com/docs/en/xl-c-and-cpp-linux/16.1.0?topic=functions-vec-ctf https://www.ibm.com/docs/en/xl-c-and-cpp-linux/16.1.0?topic=functions-vec-cts Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D106409 Files: clang/lib/Sema/SemaChecking.cpp clang/test/CodeGen/builtins-ppc-error.c Index: clang/test/CodeGen/builtins-ppc-error.c =================================================================== --- clang/test/CodeGen/builtins-ppc-error.c +++ clang/test/CodeGen/builtins-ppc-error.c @@ -50,6 +50,7 @@ void testCTF(int index) { vec_ctf(vsi, index); //expected-error {{argument to '__builtin_altivec_vcfsx' must be a constant integer}} expected-error {{argument to '__builtin_altivec_vcfux' must be a constant integer}} vec_ctf(vui, index); //expected-error {{argument to '__builtin_altivec_vcfsx' must be a constant integer}} expected-error {{argument to '__builtin_altivec_vcfux' must be a constant integer}} + vec_ctf(vsi, 32); //expected-error 1+ {{argument value 32 is outside the valid range [0, 31]}} } void testVCFSX(int index) { @@ -62,7 +63,7 @@ void testCTS(int index) { vec_cts(vf, index); //expected-error {{argument to '__builtin_altivec_vctsxs' must be a constant integer}} - + vec_cts(vf, 32); //expected-error {{argument value 32 is outside the valid range [0, 31]}} } void testVCTSXS(int index) { @@ -71,7 +72,7 @@ void testCTU(int index) { vec_ctu(vf, index); //expected-error {{argument to '__builtin_altivec_vctuxs' must be a constant integer}} - + vec_ctu(vf, 32); //expected-error {{argument value 32 is outside the valid range [0, 31]}} } void testVCTUXS(int index) { Index: clang/lib/Sema/SemaChecking.cpp =================================================================== --- clang/lib/Sema/SemaChecking.cpp +++ clang/lib/Sema/SemaChecking.cpp @@ -3351,6 +3351,11 @@ case PPC::BI__builtin_tabortdci: return SemaBuiltinConstantArgRange(TheCall, 0, 0, 31) || SemaBuiltinConstantArgRange(TheCall, 2, 0, 31); + case PPC::BI__builtin_altivec_vctsxs: + case PPC::BI__builtin_altivec_vctuxs: + case PPC::BI__builtin_altivec_vcfsx: + case PPC::BI__builtin_altivec_vcfux: + return SemaBuiltinConstantArgRange(TheCall, 1, 0, 31); case PPC::BI__builtin_altivec_dst: case PPC::BI__builtin_altivec_dstt: case PPC::BI__builtin_altivec_dstst:
Index: clang/test/CodeGen/builtins-ppc-error.c =================================================================== --- clang/test/CodeGen/builtins-ppc-error.c +++ clang/test/CodeGen/builtins-ppc-error.c @@ -50,6 +50,7 @@ void testCTF(int index) { vec_ctf(vsi, index); //expected-error {{argument to '__builtin_altivec_vcfsx' must be a constant integer}} expected-error {{argument to '__builtin_altivec_vcfux' must be a constant integer}} vec_ctf(vui, index); //expected-error {{argument to '__builtin_altivec_vcfsx' must be a constant integer}} expected-error {{argument to '__builtin_altivec_vcfux' must be a constant integer}} + vec_ctf(vsi, 32); //expected-error 1+ {{argument value 32 is outside the valid range [0, 31]}} } void testVCFSX(int index) { @@ -62,7 +63,7 @@ void testCTS(int index) { vec_cts(vf, index); //expected-error {{argument to '__builtin_altivec_vctsxs' must be a constant integer}} - + vec_cts(vf, 32); //expected-error {{argument value 32 is outside the valid range [0, 31]}} } void testVCTSXS(int index) { @@ -71,7 +72,7 @@ void testCTU(int index) { vec_ctu(vf, index); //expected-error {{argument to '__builtin_altivec_vctuxs' must be a constant integer}} - + vec_ctu(vf, 32); //expected-error {{argument value 32 is outside the valid range [0, 31]}} } void testVCTUXS(int index) { Index: clang/lib/Sema/SemaChecking.cpp =================================================================== --- clang/lib/Sema/SemaChecking.cpp +++ clang/lib/Sema/SemaChecking.cpp @@ -3351,6 +3351,11 @@ case PPC::BI__builtin_tabortdci: return SemaBuiltinConstantArgRange(TheCall, 0, 0, 31) || SemaBuiltinConstantArgRange(TheCall, 2, 0, 31); + case PPC::BI__builtin_altivec_vctsxs: + case PPC::BI__builtin_altivec_vctuxs: + case PPC::BI__builtin_altivec_vcfsx: + case PPC::BI__builtin_altivec_vcfux: + return SemaBuiltinConstantArgRange(TheCall, 1, 0, 31); case PPC::BI__builtin_altivec_dst: case PPC::BI__builtin_altivec_dstt: case PPC::BI__builtin_altivec_dstst:
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits