From patchwork Fri Sep 7 18:05:38 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 182431 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id C528E2C0086 for ; Sat, 8 Sep 2012 04:06:02 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1347645963; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=M0CJhIC 2evnyjf3bT9CNCvOhWnY=; b=GxmWwKh1ZwMfxgvANmE8FrNnfdRcpF13HhSsEAw CurekkksD3N/pKL0Xa0BQ34tLgnEdoMwy0vg/v0KcgMS0d13lAmNithmYN7lPeJW FosQ9yjlqRAYYDJZdjMy4lwCpO22Cogh3Uy3bZnHvoHbekCK/ZDMNkmM92ncPOfZ WJRQ= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=EhCB0KfMVs7qB9/h//9S9rs4RVDZSdPNt3AhGmfZ+2Hg2Iq1V83Abg5jl8N3QQ BjGusB2h7Ovh1eBTwCpPTn0OfzPG0M/pUn3VrVWGnhSiQ1NH/pIOCSF7Kb6Iu3MG XV9n7VfGMfETNw8p4T9rHWbHzTSl4PCWJhGaiOnSLij68=; Received: (qmail 12736 invoked by alias); 7 Sep 2012 18:05:58 -0000 Received: (qmail 12723 invoked by uid 22791); 7 Sep 2012 18:05:57 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 07 Sep 2012 18:05:40 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q87I5d74023509 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 7 Sep 2012 14:05:39 -0400 Received: from houston.quesejoda.com (vpn-9-63.rdu.redhat.com [10.11.9.63]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q87I5cta025651; Fri, 7 Sep 2012 14:05:39 -0400 Message-ID: <504A3772.40307@redhat.com> Date: Fri, 07 Sep 2012 13:05:38 -0500 From: Aldy Hernandez User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120828 Thunderbird/15.0 MIME-Version: 1.0 To: Richard Guenther , gcc-patches CC: Andrew MacLeod Subject: [patch] rewrite another failing data race test (gcc.dg/pr52558-2.c) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This is the same thing as gcc.dg/pr52558-1.c, but in this case I had to tweak the testcase a bit because optimization passes after LIM are smart enough to remove the condition altogether, thus never triggering the test. Interestingly, GCC can figure out what's going on when the condition is "l < 1234", but not when it is "l != 4". Luckily, the original PR (PR52558) was testing "l != 4", so now the test looks exactly as the what the PR writer had. Tested on x86-64 Linux by running with and without --param allow-store-data-races=0, and by visual inspection of the assembly. OK? testsuite/ * gcc.dg/pr52558-2.c: Delete. * gcc.dg/simulate-thread/speculative-store-3.c: New. diff --git a/gcc/testsuite/gcc.dg/pr52558-2.c b/gcc/testsuite/gcc.dg/pr52558-2.c deleted file mode 100644 index 6d5f51c..0000000 --- a/gcc/testsuite/gcc.dg/pr52558-2.c +++ /dev/null @@ -1,23 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "--param allow-store-data-races=0 -O2 -fdump-tree-lim1" } */ - -/* Test that g_2 is not written to unless !g_1. */ - -int g_1 = 1; -int g_2 = 0; - -int func_1(void) -{ - int l; - for (l = 0; l < 1234; l++) - { - if (g_1) - return l; - else - g_2 = 0; - } - return 999; -} - -/* { dg-final { scan-tree-dump-times "MEM.*g_2_lsm_flag" 1 "lim1" } } */ -/* { dg-final { cleanup-tree-dump "lim1" } } */ diff --git a/gcc/testsuite/gcc.dg/simulate-thread/speculative-store-3.c b/gcc/testsuite/gcc.dg/simulate-thread/speculative-store-3.c new file mode 100644 index 0000000..203c026 --- /dev/null +++ b/gcc/testsuite/gcc.dg/simulate-thread/speculative-store-3.c @@ -0,0 +1,71 @@ +/* { dg-do link } */ +/* { dg-options "--param allow-store-data-races=0 -O2" } */ +/* { dg-final { simulate-thread } } */ + +#include +#include + +#include "simulate-thread.h" + +/* Test distilled from PR52558. */ + +int g_1 = 1; +int g_2 = 0, insns = 0; +int f; + +/* Test that g_2 is not written to unless !g_1. */ + +__attribute__((noinline)) +int funky() +{ + int l; + for (l = 0; l != 4; l++) + { + if (g_1) + { + /* g_1 is globally true so we should always execute here, + thus never writing to g_2 under any circumstance in this + code path. */ + return l; + } + for (g_2 = 0; g_2 >= 26; ++g_2) + ; + } + return 999; +} + +int simulate_thread_final_verify () +{ + /* If g_2 != insns, someone must have cached `g_2' and stored a + racy value into it. */ + if (g_2 != insns) + { + printf("FAIL: g_2 was incorrectly cached\n"); + return 1; + } + return 0; +} + +void simulate_thread_other_threads () +{ + ++insns; + ++g_2; +} + +int simulate_thread_step_verify () +{ + return 0; +} + +__attribute__((noinline)) +void simulate_thread_main() +{ + f = funky(); +} + +int main() +{ + simulate_thread_main (); + simulate_thread_done (); + return 0; +}