From mboxrd@z Thu Jan 1 00:00:00 1970 From: Luc Van Oostenryck Subject: [PATCH v4 35/63] llvm: fix pointer/float mixup in comparisons Date: Tue, 21 Mar 2017 01:15:39 +0100 Message-ID: <20170321001607.75169-36-luc.vanoostenryck@gmail.com> References: <20170321001607.75169-1-luc.vanoostenryck@gmail.com> Return-path: Received: from mail-wr0-f194.google.com ([209.85.128.194]:36583 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755954AbdCUAQ6 (ORCPT ); Mon, 20 Mar 2017 20:16:58 -0400 Received: by mail-wr0-f194.google.com with SMTP id l37so20368016wrc.3 for ; Mon, 20 Mar 2017 17:16:57 -0700 (PDT) In-Reply-To: <20170321001607.75169-1-luc.vanoostenryck@gmail.com> Sender: linux-sparse-owner@vger.kernel.org List-Id: linux-sparse@vger.kernel.org To: linux-sparse@vger.kernel.org Cc: Christopher Li , Dibyendu Majumdar , Jeff Garzik , Pekka Enberg , Luc Van Oostenryck In output_op_compare() everything that is not of interger type is treated as floats. Pointers disagree. Fix this by rearranging the code and treat pointers like integers as required for LLVM's icmp. Reported-by: Dibyendu Majumdar Signed-off-by: Luc Van Oostenryck --- sparse-llvm.c | 17 +++++++++++++++-- validation/backend/pointer-cmp.c | 9 +++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 validation/backend/pointer-cmp.c diff --git a/sparse-llvm.c b/sparse-llvm.c index e6134af29..8c9b6a7ba 100644 --- a/sparse-llvm.c +++ b/sparse-llvm.c @@ -596,14 +596,27 @@ static void output_op_compare(struct function *fn, struct instruction *insn) LLVMTypeRef dst_type = insn_symbol_type(insn); - if (LLVMGetTypeKind(LLVMTypeOf(lhs)) == LLVMIntegerTypeKind) { + switch (LLVMGetTypeKind(LLVMTypeOf(lhs))) { + case LLVMPointerTypeKind: + case LLVMIntegerTypeKind: { LLVMIntPredicate op = translate_op(insn->opcode); target = LLVMBuildICmp(fn->builder, op, lhs, rhs, target_name); - } else { + break; + } + case LLVMHalfTypeKind: + case LLVMFloatTypeKind: + case LLVMDoubleTypeKind: + case LLVMX86_FP80TypeKind: + case LLVMFP128TypeKind: + case LLVMPPC_FP128TypeKind: { LLVMRealPredicate op = translate_fop(insn->opcode); target = LLVMBuildFCmp(fn->builder, op, lhs, rhs, target_name); + break; + } + default: + assert(0); } target = LLVMBuildZExt(fn->builder, target, dst_type, target_name); diff --git a/validation/backend/pointer-cmp.c b/validation/backend/pointer-cmp.c new file mode 100644 index 000000000..fa76d1b57 --- /dev/null +++ b/validation/backend/pointer-cmp.c @@ -0,0 +1,9 @@ +int cmpint( int x, int y) { return x == y; } +int cmpflt( float x, float y) { return x == y; } +int cmpvptr(void *x, void *y) { return x == y; } +int cmpiptr(int *x, int *y) { return x == y; } + +/* + * check-name: pointer comparison + * check-command: ./sparsec -Wno-decl -c $file -o tmp.o + */ -- 2.12.0