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

Side by Side Diff: base/tools_sanity_unittest.cc

Issue 2131423002: Implement use_cfi_cast to optionally enable cast checks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: make sure it could not be devirtualized Created 4 years, 5 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
« no previous file with comments | « no previous file | build/common.gypi » ('j') | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // This file contains intentional memory errors, some of which may lead to 5 // This file contains intentional memory errors, some of which may lead to
6 // crashes if the test is ran without special memory testing tools. We use these 6 // crashes if the test is ran without special memory testing tools. We use these
7 // errors to verify the sanity of the tools. 7 // errors to verify the sanity of the tools.
8 8
9 #include <stddef.h> 9 #include <stddef.h>
10 10
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 336
337 TEST(ToolsSanityTest, AtomicsAreIgnored) { 337 TEST(ToolsSanityTest, AtomicsAreIgnored) {
338 base::subtle::Atomic32 shared = 0; 338 base::subtle::Atomic32 shared = 0;
339 ReleaseStoreThread thread1(&shared); 339 ReleaseStoreThread thread1(&shared);
340 AcquireLoadThread thread2(&shared); 340 AcquireLoadThread thread2(&shared);
341 RunInParallel(&thread1, &thread2); 341 RunInParallel(&thread1, &thread2);
342 EXPECT_EQ(kMagicValue, shared); 342 EXPECT_EQ(kMagicValue, shared);
343 } 343 }
344 344
345 #if defined(CFI_ENFORCEMENT) 345 #if defined(CFI_ENFORCEMENT)
346 // TODO(krasin): remove CFI_CAST_CHECK, see https://crbug.com/626794.
347 #if defined(CFI_CAST_CHECK)
346 TEST(ToolsSanityTest, BadCast) { 348 TEST(ToolsSanityTest, BadCast) {
347 class A { 349 class A {
348 virtual void f() {} 350 virtual void f() {}
349 }; 351 };
350 352
351 class B { 353 class B {
352 virtual void f() {} 354 virtual void f() {}
353 }; 355 };
354 356
355 A a; 357 A a;
356 EXPECT_DEATH((void)(B*)&a, "ILL_ILLOPN"); 358 EXPECT_DEATH((void)(B*)&a, "ILL_ILLOPN");
357 } 359 }
358 #endif 360 #endif // CFI_CAST_CHECK
361
362 class A {
363 public:
364 A(): n_(0) {}
365 virtual void f() { n_++; }
366 protected:
367 int n_;
368 };
369
370 class B: public A {
371 public:
372 void f() override { n_--; }
373 };
374
375 __attribute__((noinline)) void KillVptrAndCall(A *obj) {
pcc1 2016/07/12 18:54:28 Use NOINLINE macro here.
krasin1 2016/07/12 20:30:05 Done.
376 *reinterpret_cast<void **>(obj) = 0;
377 obj->f();
378 }
379
380 TEST(ToolsSanityTest, BadVirtualCall) {
381 A a;
382 B b;
383 EXPECT_DEATH({ KillVptrAndCall(&a); KillVptrAndCall(&b); }, "ILL_ILLOPN");
384 }
385
386 #endif // CFI_ENFORCEMENT
359 387
360 } // namespace base 388 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | build/common.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698