Bug 1259850 - Test for sixgill exception handling + analysis constructor/destructor matching, r=terrence

MozReview-Commit-ID: H5NZlyS2rx5

--HG--
rename : js/src/devtools/rootAnalysis/t/suppression/source.cpp => js/src/devtools/rootAnalysis/t/exceptions/source.cpp
rename : js/src/devtools/rootAnalysis/t/suppression/test.py => js/src/devtools/rootAnalysis/t/exceptions/test.py
extra : rebase_source : c4f173bd51bf2a19b1805da5f71370c455ad12ca
This commit is contained in:
Steve Fink 2016-04-28 15:05:09 -07:00
parent 169685f973
commit f651a379e8
6 changed files with 69 additions and 7 deletions

View File

@ -29,7 +29,7 @@ var batch = (scriptArgs[5]|0) || 1;
var numBatches = (scriptArgs[6]|0) || 1;
var tmpfile = scriptArgs[7] || "tmp.txt";
GCSuppressionTypes = loadTypeInfo(typeInfoFile)["Suppress GC"];
GCSuppressionTypes = loadTypeInfo(typeInfoFile)["Suppress GC"] || [];
var gcFunctions = {};
var text = snarf("gcFunctions.lst").split("\n");

View File

@ -308,7 +308,7 @@ function processBody(functionName, body)
}
}
GCSuppressionTypes = loadTypeInfo(typeInfo_filename)["Suppress GC"];
GCSuppressionTypes = loadTypeInfo(typeInfo_filename)["Suppress GC"] || [];
var xdb = xdbLibrary();
xdb.open("src_comp.xdb");

View File

@ -40,7 +40,7 @@ parser.add_argument(
'--verbose', '-v', action='store_true',
help='Display verbose output, including commands executed')
parser.add_argument(
'tests', nargs='*', default=['sixgill-tree', 'suppression', 'hazards'],
'tests', nargs='*', default=['sixgill-tree', 'suppression', 'hazards', 'exceptions'],
help='tests to run')
cfg = parser.parse_args()

View File

@ -0,0 +1,42 @@
#define ANNOTATE(property) __attribute__((tag(property)))
struct Cell { int f; } ANNOTATE("GC Thing");
extern void GC() ANNOTATE("GC Call");
void GC()
{
// If the implementation is too trivial, the function body won't be emitted at all.
asm("");
}
class RAII_GC {
public:
RAII_GC() {}
~RAII_GC() { GC(); }
};
// ~AutoSomething calls GC because of the RAII_GC field. The constructor,
// though, should *not* GC -- unless it throws an exception. Which is not
// possible when compiled with -fno-exceptions.
class AutoSomething {
RAII_GC gc;
public:
AutoSomething() : gc() {
asm(""); // Ooh, scary, this might throw an exception
}
~AutoSomething() {
asm("");
}
};
extern void usevar(Cell* cell);
void f() {
Cell* thing = nullptr; // Live range starts here
{
AutoSomething smth; // Constructor can GC only if exceptions are enabled
usevar(thing); // Live range ends here
} // In particular, 'thing' is dead at the destructor, so no hazard
}

View File

@ -0,0 +1,19 @@
test.compile("source.cpp", '-fno-exceptions')
test.run_analysis_script('gcTypes')
hazards = test.load_hazards()
assert(len(hazards) == 0)
# If we compile with exceptions, then there *should* be a hazard because
# AutoSomething::AutoSomething might throw an exception, which would cause the
# partially-constructed value to be torn down, which will call ~RAII_GC.
test.compile("source.cpp", '-fexceptions')
test.run_analysis_script('gcTypes')
hazards = test.load_hazards()
assert(len(hazards) == 1)
hazard = hazards[0]
assert(hazard.function == 'void f()')
assert(hazard.variable == 'thing')
assert("AutoSomething::AutoSomething" in hazard.GCFunction)

View File

@ -31,10 +31,11 @@ class Test(object):
def binpath(self, prog):
return os.path.join(self.cfg.sixgill_bin, prog)
def compile(self, source):
cmd = "{CXX} -c {source} -O3 -std=c++11 -fplugin={sixgill} -fplugin-arg-xgill-mangle=1".format(
def compile(self, source, options = ''):
cmd = "{CXX} -c {source} -O3 -std=c++11 -fplugin={sixgill} -fplugin-arg-xgill-mangle=1 {options}".format(
source=self.infile(source),
CXX=self.cfg.cxx, sixgill=self.cfg.sixgill_plugin)
CXX=self.cfg.cxx, sixgill=self.cfg.sixgill_plugin,
options=options)
if self.cfg.verbose:
print("Running %s" % cmd)
subprocess.check_call(["sh", "-c", cmd])
@ -75,7 +76,7 @@ sixgill_bin = '{bindir}'
self.run_analysis_script("gcTypes", upto="gcTypes")
def computeHazards(self):
self.run_analysis_script("callgraph")
self.run_analysis_script("gcTypes")
def load_text_file(self, filename, extract=lambda l: l):
fullpath = os.path.join(self.outdir, filename)