From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 120450 invoked by alias); 18 Sep 2018 12:22:30 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 119219 invoked by uid 89); 18 Sep 2018 12:22:29 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.1 required=5.0 tests=BAYES_00,FREEMAIL_FROM,HTML_MESSAGE,MIME_BOUND_DIGITS_15,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=no version=3.3.2 spammy=H*c:alternative X-HELO: mail-ed1-f46.google.com Received: from mail-ed1-f46.google.com (HELO mail-ed1-f46.google.com) (209.85.208.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 18 Sep 2018 12:22:23 +0000 Received: by mail-ed1-f46.google.com with SMTP id a20-v6so1734051edd.4 for ; Tue, 18 Sep 2018 05:22:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=V8x5dWw+DWw4bQqcPkMr77R3Mcw6KIDdf1lODY1UfxE=; b=Pp3bflXIhCHYx0a3HAEMFFBERIfGC53CHH4iPePNE8XbunarLyu7wo50gY1Z1W5XBe loNn2/dBc8uDDPxP0XBoFe6Z/65FYG4Myf4pxIQo41+Au9ykZiSd1VKAu39FQRKUBNqo DbS9u/1Se2RbGKvWla2Ip1Myk/Cr6TT4RlzbjdzYTdbs/u6jtmvsmnccB5QBDaO49mDD JQ1ehJBex75ReUERU3jg6I4UT703kd4/fEWNnhE3DRgQxGqiPur5JSrFjJ9iYyZ6xEi/ Eu0Bskeh7Ima0UrWcjLry+jc1S7dQO3H4KoEYiYPjIJPINbvpX8Wu6flBmmLFeT0wfb7 CoCg== MIME-Version: 1.0 From: Neha Gowda Date: Tue, 18 Sep 2018 12:22:00 -0000 Message-ID: Subject: Should rand() return a RAND_MAX value for 32 bit target? To: gcc-help@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" X-SW-Source: 2018-09/txt/msg00049.txt.bz2 Hi, I am trying to run the following testcase for Random Number Generator function. The testcase returns true when generated number is RAND_MAX and returns false when its not generated. Command :- gcc -m32 -O2 test.c ====================================================== #include #include int main() { unsigned int i; float f; srand(0); for (i = 0; i <= RAND_MAX; i++) { f = rand(); if (f == RAND_MAX) { printf("True\n"); return 0; } } printf("False\n"); return 1; } ====================================================== Tried them on the latest source and observed that the RAND_MAX is generated when the optimization is not enabled. When optimization is enabled for 32 bit target RAND_MAX is not being generated. However, 64 bit generates RAND_MAX with or without optimization. On further investigation, I found that the expand phase is optimizing the following and hence the RAND_MAX value is not being generated. ========================================= Replacing Expressions f_10 replace with --> f_10 = (float) _1; ========================================= Can you please let me know if its the expected behavior or some bug? Thanks, Neha