From mboxrd@z Thu Jan 1 00:00:00 1970 From: Luc Van Oostenryck Subject: [PATCH v3 25/30] llvm: fix pointer/float mixup in comparisons Date: Sun, 19 Mar 2017 02:42:22 +0100 Message-ID: <20170319014227.8833-26-luc.vanoostenryck@gmail.com> References: <20170319014227.8833-1-luc.vanoostenryck@gmail.com> Return-path: Received: from mail-wr0-f196.google.com ([209.85.128.196]:34316 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751424AbdCSBnE (ORCPT ); Sat, 18 Mar 2017 21:43:04 -0400 Received: by mail-wr0-f196.google.com with SMTP id u48so13843215wrc.1 for ; Sat, 18 Mar 2017 18:43:03 -0700 (PDT) In-Reply-To: <20170319014227.8833-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 , 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 833fb20df..55843950d 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