Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(239)

Side by Side Diff: base/tools_sanity_unittest.cc

Issue 7931006: Prevent clang from optimizing away 2 variables. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comment Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/atomicops.h" 5 #include "base/atomicops.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 7 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
8 #include "base/threading/thread.h" 8 #include "base/threading/thread.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 MakeSomeErrors(foo, 10); 77 MakeSomeErrors(foo, 10);
78 free(foo); 78 free(foo);
79 foo[5] = 0; // Use after free. This won't break anything under Valgrind. 79 foo[5] = 0; // Use after free. This won't break anything under Valgrind.
80 } 80 }
81 81
82 TEST(ToolsSanityTest, ArrayDeletedWithoutBraces) { 82 TEST(ToolsSanityTest, ArrayDeletedWithoutBraces) {
83 // This test may corrupt memory if not run under Valgrind. 83 // This test may corrupt memory if not run under Valgrind.
84 if (!RunningOnValgrind()) 84 if (!RunningOnValgrind())
85 return; 85 return;
86 86
87 int *foo = new int[10]; 87 // Without the |volatile|, clang optimizes away the next two lines.
88 int* volatile foo = new int[10];
88 delete foo; 89 delete foo;
89 } 90 }
90 91
91 TEST(ToolsSanityTest, SingleElementDeletedWithBraces) { 92 TEST(ToolsSanityTest, SingleElementDeletedWithBraces) {
92 // This test may corrupt memory if not run under Valgrind. 93 // This test may corrupt memory if not run under Valgrind.
93 if (!RunningOnValgrind()) 94 if (!RunningOnValgrind())
94 return; 95 return;
95 96
96 int *foo = new int; 97 // Without the |volatile|, clang optimizes away the next two lines.
98 int* volatile foo = new int;
97 delete [] foo; 99 delete [] foo;
98 } 100 }
99 101
100 102
101 namespace { 103 namespace {
102 104
103 // We use caps here just to ensure that the method name doesn't interfere with 105 // We use caps here just to ensure that the method name doesn't interfere with
104 // the wildcarded suppressions. 106 // the wildcarded suppressions.
105 class TOOLS_SANITY_TEST_CONCURRENT_THREAD : public PlatformThread::Delegate { 107 class TOOLS_SANITY_TEST_CONCURRENT_THREAD : public PlatformThread::Delegate {
106 public: 108 public:
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 178
177 TEST(ToolsSanityTest, AtomicsAreIgnored) { 179 TEST(ToolsSanityTest, AtomicsAreIgnored) {
178 base::subtle::Atomic32 shared = 0; 180 base::subtle::Atomic32 shared = 0;
179 ReleaseStoreThread thread1(&shared); 181 ReleaseStoreThread thread1(&shared);
180 AcquireLoadThread thread2(&shared); 182 AcquireLoadThread thread2(&shared);
181 RunInParallel(&thread1, &thread2); 183 RunInParallel(&thread1, &thread2);
182 EXPECT_EQ(kMagicValue, shared); 184 EXPECT_EQ(kMagicValue, shared);
183 } 185 }
184 186
185 } // namespace base 187 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698