From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- js/src/devtools/rootAnalysis/t/types/source.cpp | 167 ++++++++++++++++++++++++ js/src/devtools/rootAnalysis/t/types/test.py | 16 +++ 2 files changed, 183 insertions(+) create mode 100644 js/src/devtools/rootAnalysis/t/types/source.cpp create mode 100644 js/src/devtools/rootAnalysis/t/types/test.py (limited to 'js/src/devtools/rootAnalysis/t/types') diff --git a/js/src/devtools/rootAnalysis/t/types/source.cpp b/js/src/devtools/rootAnalysis/t/types/source.cpp new file mode 100644 index 0000000000..c8a2d4aa73 --- /dev/null +++ b/js/src/devtools/rootAnalysis/t/types/source.cpp @@ -0,0 +1,167 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include +#include + +#define ANNOTATE(property) __attribute__((annotate(property))) + +struct Cell { + int f; +} ANNOTATE("GC Thing"); + +namespace World { +namespace NS { +struct Unsafe { + int g; + ~Unsafe() { asm(""); } +} ANNOTATE("Invalidated by GC") ANNOTATE("GC Pointer or Reference"); +} // namespace NS +} // namespace World + +extern void GC() ANNOTATE("GC Call"); +extern void invisible(); + +void GC() { + // If the implementation is too trivial, the function body won't be emitted at + // all. + asm(""); + invisible(); +} + +struct GCOnDestruction { + ~GCOnDestruction() { GC(); } +}; + +struct NoGCOnDestruction { + ~NoGCOnDestruction() { asm(""); } +}; + +extern void usecell(Cell*); + +Cell* cell() { + static Cell c; + return &c; +} + +template +struct SimpleTemplate { + int member; +}; + +template +class ANNOTATE("moz_inherit_type_annotations_from_template_args") Container { + public: + template + void foo(V& v, W& w) { + class InnerClass {}; + InnerClass xxx; + return; + } + + struct Entry { + T t; + U u; + }* ent; +}; + +Cell* f() { + Container c1; + Container, SimpleTemplate> c2; + Container, Container> c3; + Container, float>, + Container>> + c4; + + return nullptr; +} + +// Define a set of classes for verifying that there is no infinite loop +// when a class contains itself via mozilla::UniquePtr. + +namespace mozilla { + +template +struct JustAField { + A field; + + // Hack to allow UniquePtr and SimpleUniquePtr to be swapped. + A& operator->() { return field; } +}; + +template +struct UniquePtr { + JustAField holder; +}; + +// This did not trigger the infinite loop, because the pointer here +// caused the UniquePtr special handling to be skipped. It requires +// the above definition to be triggered, which matches the actual +// implementation (JustAField maps to CompactPair, more or less). +// The bugfix for the infinite loop also drops this requirement, so +// now this *would* trigger the bug if it weren't fixed in the same +// commit. +template +struct SimpleUniquePtr { + T* holder; +}; + +} // namespace mozilla + +class Recursive { + public: + using EntryMap = Container; + mozilla::UniquePtr entries; +}; + +void rvalue_ref(World::NS::Unsafe&& arg1) { GC(); } + +void ref(const World::NS::Unsafe& arg2) { + Recursive* foo; + // Must actually use a type for the compiler to instantiate the + // template specializations. + foo->entries.holder->ent; + GC(); + static int use = arg2.g; +} + +// A function that consumes a parameter, but only if passed by rvalue reference. +extern void eat(World::NS::Unsafe&&); +extern void eat(World::NS::Unsafe&); + +void rvalue_ref_ok() { + World::NS::Unsafe unsafe1; + eat(std::move(unsafe1)); + GC(); +} + +void rvalue_ref_not_ok() { + World::NS::Unsafe unsafe2; + eat(unsafe2); + GC(); +} + +void rvalue_ref_arg_ok(World::NS::Unsafe&& unsafe3) { + eat(std::move(unsafe3)); + GC(); +} + +void rvalue_ref_arg_not_ok(World::NS::Unsafe&& unsafe4) { + eat(unsafe4); + GC(); +} + +void shared_ptr_hazard() { + Cell* unsafe5 = f(); + { auto p = std::make_shared(); } + usecell(unsafe5); +} + +void shared_ptr_no_hazard() { + Cell* safe6 = f(); + { auto p = std::make_shared(); } + usecell(safe6); +} diff --git a/js/src/devtools/rootAnalysis/t/types/test.py b/js/src/devtools/rootAnalysis/t/types/test.py new file mode 100644 index 0000000000..4a2b985abf --- /dev/null +++ b/js/src/devtools/rootAnalysis/t/types/test.py @@ -0,0 +1,16 @@ +# flake8: noqa: F821 + +from collections import defaultdict + +test.compile("source.cpp") +test.run_analysis_script() +hazards = test.load_hazards() +hazmap = {haz.variable: haz for haz in hazards} +assert "arg1" in hazmap +assert "arg2" in hazmap +assert "unsafe1" not in hazmap +assert "unsafe2" in hazmap +assert "unsafe3" not in hazmap +assert "unsafe4" in hazmap +assert "unsafe5" in hazmap +assert "safe6" not in hazmap -- cgit v1.2.3