Author: Nemanja Ivanovic Date: 2021-09-30T05:58:22-05:00 New Revision: fad14a17a490b1825b0c7c40ace7e83c91af4b8a
URL: https://github.com/llvm/llvm-project/commit/fad14a17a490b1825b0c7c40ace7e83c91af4b8a DIFF: https://github.com/llvm/llvm-project/commit/fad14a17a490b1825b0c7c40ace7e83c91af4b8a.diff LOG: [PowerPC] Truncate element index for vec_insert in altivec.h When a user specifies an out-of-range index for vec_insert, we just produce IR that has undefined behaviour even though the documentation states that modulo arithmetic is used. This patch just truncates the value to a valid index. Added: Modified: clang/lib/Headers/altivec.h Removed: ################################################################################ diff --git a/clang/lib/Headers/altivec.h b/clang/lib/Headers/altivec.h index 0ccd63af8791a..6a179d86d71f9 100644 --- a/clang/lib/Headers/altivec.h +++ b/clang/lib/Headers/altivec.h @@ -13571,82 +13571,82 @@ vec_extract_fp32_from_shortl(vector unsigned short __a) { static __inline__ vector signed char __ATTRS_o_ai vec_insert(signed char __a, vector signed char __b, int __c) { - __b[__c] = __a; + __b[__c & 0xF] = __a; return __b; } static __inline__ vector unsigned char __ATTRS_o_ai vec_insert(unsigned char __a, vector unsigned char __b, int __c) { - __b[__c] = __a; + __b[__c & 0xF] = __a; return __b; } static __inline__ vector bool char __ATTRS_o_ai vec_insert(unsigned char __a, vector bool char __b, int __c) { - __b[__c] = __a; + __b[__c & 0xF] = __a; return __b; } static __inline__ vector signed short __ATTRS_o_ai vec_insert(signed short __a, vector signed short __b, int __c) { - __b[__c] = __a; + __b[__c & 0x7] = __a; return __b; } static __inline__ vector unsigned short __ATTRS_o_ai vec_insert(unsigned short __a, vector unsigned short __b, int __c) { - __b[__c] = __a; + __b[__c & 0x7] = __a; return __b; } static __inline__ vector bool short __ATTRS_o_ai vec_insert(unsigned short __a, vector bool short __b, int __c) { - __b[__c] = __a; + __b[__c & 0x7] = __a; return __b; } static __inline__ vector signed int __ATTRS_o_ai vec_insert(signed int __a, vector signed int __b, int __c) { - __b[__c] = __a; + __b[__c & 0x3] = __a; return __b; } static __inline__ vector unsigned int __ATTRS_o_ai vec_insert(unsigned int __a, vector unsigned int __b, int __c) { - __b[__c] = __a; + __b[__c & 0x3] = __a; return __b; } static __inline__ vector bool int __ATTRS_o_ai vec_insert(unsigned int __a, vector bool int __b, int __c) { - __b[__c] = __a; + __b[__c & 0x3] = __a; return __b; } #ifdef __VSX__ static __inline__ vector signed long long __ATTRS_o_ai vec_insert(signed long long __a, vector signed long long __b, int __c) { - __b[__c] = __a; + __b[__c & 0x1] = __a; return __b; } static __inline__ vector unsigned long long __ATTRS_o_ai vec_insert(unsigned long long __a, vector unsigned long long __b, int __c) { - __b[__c] = __a; + __b[__c & 0x1] = __a; return __b; } static __inline__ vector bool long long __ATTRS_o_ai vec_insert(unsigned long long __a, vector bool long long __b, int __c) { - __b[__c] = __a; + __b[__c & 0x1] = __a; return __b; } static __inline__ vector double __ATTRS_o_ai vec_insert(double __a, vector double __b, int __c) { - __b[__c] = __a; + __b[__c & 0x1] = __a; return __b; } #endif @@ -13654,7 +13654,7 @@ static __inline__ vector double __ATTRS_o_ai vec_insert(double __a, static __inline__ vector float __ATTRS_o_ai vec_insert(float __a, vector float __b, int __c) { - __b[__c] = __a; + __b[__c & 0x3] = __a; return __b; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits