Closed Bug 494960 Opened 15 years ago Closed 11 years ago

Implement treehydra for C

Categories

(Developer Infrastructure :: Source Code Analysis, defect)

x86
Linux
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED WONTFIX

People

(Reporter: benjamin, Assigned: taras.mozilla)

References

Details

Attachments

(3 files, 3 obsolete files)

I tried using treehydra on C code for bug 493996, but it turns out that most of the callbacks don't fire for C code. I want in particular:

process_tree_decl
process_tree

I'd like process_tree_type but it's less important.

I'm currently working against GCC 4.3.0 but I'd be willing to try GCC 4.5 as that's the working target for most of this.
pushed http://hg.mozilla.org/users/tglek_mozilla.com/dehydra-gcc/rev/2d0f97ed909a fixes 

Now process_tree works on 4.[35]

How badly do you want process_tree_decl?
Well... I guess it's not essential. I was using it to verify that attributes were being applied correctly, but it's not part of the actual code-body analysis.
Attached patch decl callback support for hydras (obsolete) — Splinter Review
There is a new gcc patch, so you'll need to update your mq for gcc4.3
Blocks: 437502
Attached patch gcc 4.5 patchSplinter Review
Tried the patches (on gcc 4.5 / trunk). Still getting problems include Internal Compiler Error.

Converted the unit test harness to be capable of running tests with gcc (cc1) and g++ (cc1plus). Some tests only make sense with g++ (e.g. those that use C++ features), some work fine with gcc and g++, and some look like they should work with both gcc and g++, but blow up on gcc.
Hopefully the change is fairly self explanatory.

Basically:

1. Pass the compiler options (e.g. "-quiet -O1 -ftest-coverage")
to the test harness instead of the compiler execution line
(e.g. "/path/to/gcc-build/gcc/cc1plus -quiet -O1 -ftest-coverage")

2. Add another parameter to the test files:
 -// { 'test': 'treehydra', 'input': 'empty.cc', 'output': 'stderr_has("TypeError", "/gcc_compat.js")' }
+// { 'test': 'treehydra', 'input': 'empty.cc', 'output': 'stderr_has("TypeError", "/gcc_compat.js")', 'lang': 'c,c++' }
Note that not all files have been done. Anything that doesn't have a 'lang':
entry is something that I think should work with gcc, but doesn't.

3. Update the unit test harness to match, including a default of 'c++'

4. Renamed "ccfile" member variable to be "srcfile", to make it generic.

This version of the patch is essentially infrastructure. It doesn't add any new failing tests. As we work to provide C support, some of those tests need to be turned on. Alternatively, just change the default to be 'c,c++'.
Comment on attachment 381929 [details] [diff] [review]
Enable testing of gcc (as well as g++) for dehydra and treehydra

> function process_tree (function_decl) {
>   var b = DECL_SAVED_TREE (function_decl)
>diff -r 2c8a52735374 test/unit_test_harness.py
>--- a/test/unit_test_harness.py    Thu Jun 04 15:19:33 2009 -0700
>+++ b/test/unit_test_harness.py    Sat Jun 06 19:38:40 2009 +1000
>@@ -4,12 +4,14 @@
> Specify a test by a JS file in this directory with the first line
> like this:
> 
>-// { 'test': 'treehydra', 'input': 'onefunc.cc', 'output': 'unit_test' }
>+// { 'test': 'dehydra', 'input': 'empty.cc', 'output': 'unit_test', 'lang': 'c'}
> 
>   test:   comma-separated list of plugins to test, dehydra or treehydra
>   input:  C++ input file to use for test
>   output: eval'd in this script to yield a checker function applied
>           to the output. See checkers, below.
>+  lang:   comma-separated list of languages to test, c or c++. defaults to c++
>+
> """

This is all pretty good and pretty much how I imagined it, thanks for implementing this so quickly.
> 
> import os, re, sys
>@@ -18,9 +20,10 @@
> 
> class PluginTestCase(TestCase):
>     """Test case for running Treehydra and checking output."""
>-    def __init__(self, plugin, jsfile, ccfile, checker, checker_str):
>+    def __init__(self, plugin, lang, jsfile, ccfile, checker, checker_str):
>         super(PluginTestCase, self).__init__()
>         self.plugin = plugin
>+        self.lang = lang
>         self.jsfile = jsfile
>         self.ccfile = ccfile
>         self.checker = checker
>@@ -33,7 +36,14 @@
>         self.checker(self, 0, out, err)
> 
>     def getCommand(self):
>-        command = CC1PLUS + " -fplugin=../gcc_" + self.plugin + ".so -o /dev/null"
>+        if (self.lang == 'c'):
>+            command = config_opts["GCCBUILDDIR"] + "/gcc/cc1"
>+        elif (self.lang == 'c++'):
>+            command = config_opts["GCCBUILDDIR"] + "/gcc/cc1plus"
>+        else:
>+            raise TestSpecException(filename, "invalid language %s"%self.lang)

These should actually check for CC(not implemented yet) and CXX variables in config.mk. I think we should also move away from using the gcc build directory for running tests. Instead we should use CC/CXX as passed to configure from installed compilers.


While we are implementing C support there should also be a way to turn off C testing as it will be broken for a little while. So configure will add a TEST_LANGS=c,c++ variable where the "c" part would be enabled with --enable-c. This will also be handy for testing obj c/c++ later.
(In reply to comment #5)
> Tried the patches (on gcc 4.5 / trunk). Still getting problems include Internal
> Compiler Error.
> 
> Converted the unit test harness to be capable of running tests with gcc (cc1)
> and g++ (cc1plus). Some tests only make sense with g++ (e.g. those that use C++
> features), some work fine with gcc and g++, and some look like they should work
> with both gcc and g++, but blow up on gcc.

I don't see any testcases failing with C(after applying you c testsuite patch), do you have a testcase that fails?
This fixes the trivial crashes. I think I forgot to qref the patch before uploading it, also fixed a couple of other bugs. This seems to get through compiling nspr, so it's good enough for testing.
Attachment #380162 - Attachment is obsolete: true
I wrote the testsuite patch to pass. So the default (i.e. if 'lang' is not specified in the test case) is to only run "c++" tests. 

I looked for tests that worked with both gcc and g++ and explicitly encoded those as 'lang': 'c,c++'

I looked for tests that appeared to use C++ features (e.g. declared classes), and explicitly encoded those as 'lang': 'c++'

Anything that isn't encoded is something I missed, or looks like it should work but fails.

So if you change the default (in unit_test_harness.py) to be "c,c++", you'll get all of the failures.
Here is the current dehydra test failures with a default of "c,c++':

[bradh@conferta dehydra-gcc]$ make check
make -C test check
make[1]: Entering directory `/home/bradh/devel/taras-stuff/dehydra-gcc/test'
python unit_test_harness.py dehydra "-quiet -O1 -ftest-coverage"
......x.x...x....x.x.x..x....x............x.x.......x.x.x.x.x.x.x.
Test Failure: 
    Test command: /home/bradh/devel/gcc-build/gcc/cc1 -quiet -O1 -ftest-coverage -fplugin=../gcc_dehydra.so -o /dev/null -fplugin-arg-gcc_dehydra-=test_incdec.js incdec.cc
    Failure msg: Expected 'OK' output; Errors:
 incdec.cc:5:1: error: Must be 1 tests run, instead ran 0

Test Failure: 
    Test command: /home/bradh/devel/gcc-build/gcc/cc1 -quiet -O1 -ftest-coverage -fplugin=../gcc_dehydra.so -o /dev/null -fplugin-arg-gcc_dehydra-=test_process_decl.js decl.cc
    Failure msg: Expected 'OK' output; got '({name:"forward_func_decl", shortName:"forward_func_decl", isExtern:true, isFunction:true, parameters:[], type:{type:{name:"void"}, parameters:[]}, loc:{_source_location:2255, file:"decl.cc", line:18, column:6}})'
Test Failure: 
    Test command: /home/bradh/devel/gcc-build/gcc/cc1 -quiet -O1 -ftest-coverage -fplugin=../gcc_dehydra.so -o /dev/null -fplugin-arg-gcc_dehydra-=test_typedef_const.js typedef.cc
    Failure msg: Expected 'OK' output; Errors:
 typedef.cc:6:7: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘s’
typedef.cc:14:11: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘stype’
*** WARNING *** there are active plugins, do not report this as a bug unless you can reproduce it without enabling any plugins.
Event			Plugins
PLUGIN_FINISH_TYPE	gcc_dehydra 
PLUGIN_FINISH_UNIT	gcc_dehydra 
PLUGIN_CXX_CP_PRE_GENERICIZE	gcc_dehydra 
PLUGIN_FINISH	gcc_dehydra 
PLUGIN_EVENT_LAST	gcc_dehydra 
plugin_init	gcc_dehydra 
typedef.cc:16:1: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

Test Failure: 
    Test command: /home/bradh/devel/gcc-build/gcc/cc1 -quiet -O1 -ftest-coverage -fplugin=../gcc_dehydra.so -o /dev/null -fplugin-arg-gcc_dehydra-=test_intlit.js intlit.cc
    Failure msg: Expected 'OK' output; Errors:
 intlit.cc:20:1: error: Must be 18 tests run, instead ran 0

Test Failure: 
    Test command: /home/bradh/devel/gcc-build/gcc/cc1 -quiet -O1 -ftest-coverage -fplugin=../gcc_dehydra.so -o /dev/null -fplugin-arg-gcc_dehydra-=test_dehydra_location.js location.cc
    Failure msg: Expected 'OK' output; got empty stdout, stderr
Test Failure: 
    Test command: /home/bradh/devel/gcc-build/gcc/cc1 -quiet -O1 -ftest-coverage -fplugin=../gcc_dehydra.so -o /dev/null -fplugin-arg-gcc_dehydra-=test_enum.js enum.cc
    Failure msg: Expected 'OK' output; got 'ERR  TestCase   TypeError: type.members is undefined'
Test Failure: 
    Test command: /home/bradh/devel/gcc-build/gcc/cc1 -quiet -O1 -ftest-coverage -fplugin=../gcc_dehydra.so -o /dev/null -fplugin-arg-gcc_dehydra-=test_treehydra_dehydra_types.js access.cc
    Failure msg: Expected 'OK' output; Errors:
 access.cc:1:7: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘A’
access.cc:13:7: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘B’
access.cc:20:7: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘C’
access.cc:25:7: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘D’
access.cc:30:2: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
access.cc:35:2: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
access.cc:40:3: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
access.cc:45:3: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token

Test Failure: 
    Test command: /home/bradh/devel/gcc-build/gcc/cc1 -quiet -O1 -ftest-coverage -fplugin=../gcc_dehydra.so -o /dev/null -fplugin-arg-gcc_dehydra-=test_const.js const.cc
    Failure msg: Expected 'OK' output; Errors:
 const.cc:1:7: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘C’
const.cc:4:9: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token

Test Failure: 
    Test command: /home/bradh/devel/gcc-build/gcc/cc1 -quiet -O1 -ftest-coverage -fplugin=../gcc_dehydra.so -o /dev/null -fplugin-arg-gcc_dehydra-=test_bitfields.js bitfields.cc
    Failure msg: Expected 'OK' output; Errors:
 bitfields.cc:7:1: error: Must be 17 tests run, instead ran 0

Test Failure: 
    Test command: /home/bradh/devel/gcc-build/gcc/cc1 -quiet -O1 -ftest-coverage -fplugin=../gcc_dehydra.so -o /dev/null -fplugin-arg-gcc_dehydra-=test_parameters.js parameters.cc
    Failure msg: Expected 'OK' output; got 'ERR  TestCase   TypeError: this.decl.parameters[0] is undefined'
Test Failure: 
    Test command: /home/bradh/devel/gcc-build/gcc/cc1 -quiet -O1 -ftest-coverage -fplugin=../gcc_dehydra.so -o /dev/null -fplugin-arg-gcc_dehydra-=test_type_decl_distinction.js numinfo.cc
    Failure msg: Expected 'OK' output; Errors:
 numinfo.cc:14:6: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘boolvar’
numinfo.cc:19:7: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘enumvar’
numinfo.cc:21:7: error: expected identifier or ‘(’ before ‘&’ token
numinfo.cc:22:21: error: ‘enumvar’ undeclared here (not in a function)
*** WARNING *** there are active plugins, do not report this as a bug unless you can reproduce it without enabling any plugins.
Event			Plugins
PLUGIN_FINISH_TYPE	gcc_dehydra 
PLUGIN_FINISH_UNIT	gcc_dehydra 
PLUGIN_CXX_CP_PRE_GENERICIZE	gcc_dehydra 
PLUGIN_FINISH	gcc_dehydra 
PLUGIN_EVENT_LAST	gcc_dehydra 
plugin_init	gcc_dehydra 
numinfo.cc:22:1: internal compiler error: tree check: expected class ‘type’, have ‘exceptional’ (error_mark) in process_type, at dehydra_plugin.c:139
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

Test Failure: 
    Test command: /home/bradh/devel/gcc-build/gcc/cc1 -quiet -O1 -ftest-coverage -fplugin=../gcc_dehydra.so -o /dev/null -fplugin-arg-gcc_dehydra-=test_static_func.js test_static_func.cc
    Failure msg: Expected 'OK' output; Errors:
 test_static_func.cc:2:3: error: expected specifier-qualifier-list before ‘static’
test_static_func.cc:10:11: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token

Test Failure: 
    Test command: /home/bradh/devel/gcc-build/gcc/cc1 -quiet -O1 -ftest-coverage -fplugin=../gcc_dehydra.so -o /dev/null -fplugin-arg-gcc_dehydra-=test_numinfo.js numinfo.cc
    Failure msg: Expected 'OK' output; Errors:
 numinfo.cc:14:6: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘boolvar’
numinfo.cc:19:7: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘enumvar’
numinfo.cc:21:7: error: expected identifier or ‘(’ before ‘&’ token
numinfo.cc:22:21: error: ‘enumvar’ undeclared here (not in a function)
*** WARNING *** there are active plugins, do not report this as a bug unless you can reproduce it without enabling any plugins.
Event			Plugins
PLUGIN_FINISH_TYPE	gcc_dehydra 
PLUGIN_FINISH_UNIT	gcc_dehydra 
PLUGIN_CXX_CP_PRE_GENERICIZE	gcc_dehydra 
PLUGIN_FINISH	gcc_dehydra 
PLUGIN_EVENT_LAST	gcc_dehydra 
plugin_init	gcc_dehydra 
numinfo.cc:22:1: internal compiler error: tree check: expected class ‘type’, have ‘exceptional’ (error_mark) in process_type, at dehydra_plugin.c:139
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

Test Failure: 
    Test command: /home/bradh/devel/gcc-build/gcc/cc1 -quiet -O1 -ftest-coverage -fplugin=../gcc_dehydra.so -o /dev/null -fplugin-arg-gcc_dehydra-=test_csttype.js csttype.cc
    Failure msg: Expected 'OK' output; Errors:
 csttype.cc:7:1: error: Must be 5 tests run, instead ran 0

Test Failure: 
    Test command: /home/bradh/devel/gcc-build/gcc/cc1 -quiet -O1 -ftest-coverage -fplugin=../gcc_dehydra.so -o /dev/null -fplugin-arg-gcc_dehydra-=test_isExtern.js isExtern.cc
    Failure msg: Expected 'OK' output; Errors:
 isExtern.cc:4:3: error: expected specifier-qualifier-list before ‘static’
isExtern.cc:10:6: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘:’ token
isExtern.cc:11:7: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘:’ token

Test Failure: 
    Test command: /home/bradh/devel/gcc-build/gcc/cc1 -quiet -O1 -ftest-coverage -fplugin=../gcc_dehydra.so -o /dev/null -fplugin-arg-gcc_dehydra-=test_strict.js onefunc.cc
    Failure msg: Expected 'OK' output; got empty stdout, stderr
Test Failure: 
    Test command: /home/bradh/devel/gcc-build/gcc/cc1 -quiet -O1 -ftest-coverage -fplugin=../gcc_dehydra.so -o /dev/null -fplugin-arg-gcc_dehydra-=test_diag_loc.js onefunc.cc
    Failure msg: Expected ':1:' in error output; not found. stderr:

Unit Test Suite Summary:
     49 passed
     17 failed
      0 error(s)
make[1]: *** [check_dehydra] Error 1
make[1]: Leaving directory `/home/bradh/devel/taras-stuff/dehydra-gcc/test'
make: *** [check] Error 2
Brad, that last bug highlighted by your testsuite change was just a problem due to parse errors prior to the decl. Fixed that case, things should be perfect now :)
Attachment #382163 - Attachment is obsolete: true
Updated the testsuite patch.

I've turned on c and c++ by default in this version.

I haven't fixed the CC / CXX stuff yet. I'd like to look at that as part of a general migration to being able to build against an installed gcc 4.5 (not needing source and build trees).
Attachment #381929 - Attachment is obsolete: true
Attachment #382478 - Flags: review?(tglek)
With that version of the patch, I get these errors:

[bradh@conferta dehydra-gcc]$ make check
make -C test check
make[1]: Entering directory `/home/bradh/devel/taras-stuff/dehydra-gcc/test'
python unit_test_harness.py dehydra "-quiet -O1 -ftest-coverage"
......x........x.x.x..................x.x............x..x.x.
Test Failure: 
    Test command: /home/bradh/devel/gcc-build/gcc/cc1 -quiet -O1 -ftest-coverage -fplugin=../gcc_dehydra.so -o /dev/null -fplugin-arg-gcc_dehydra-=test_incdec.js incdec.cc
    Failure msg: Expected 'OK' output; Errors:
 incdec.cc:5:1: error: Must be 1 tests run, instead ran 0

Test Failure: 
    Test command: /home/bradh/devel/gcc-build/gcc/cc1 -quiet -O1 -ftest-coverage -fplugin=../gcc_dehydra.so -o /dev/null -fplugin-arg-gcc_dehydra-=test_intlit.js intlit.cc
    Failure msg: Expected 'OK' output; Errors:
 intlit.cc:20:1: error: Must be 18 tests run, instead ran 0

Test Failure: 
    Test command: /home/bradh/devel/gcc-build/gcc/cc1 -quiet -O1 -ftest-coverage -fplugin=../gcc_dehydra.so -o /dev/null -fplugin-arg-gcc_dehydra-=test_dehydra_location.js location.cc
    Failure msg: Expected 'OK' output; got empty stdout, stderr
Test Failure: 
    Test command: /home/bradh/devel/gcc-build/gcc/cc1 -quiet -O1 -ftest-coverage -fplugin=../gcc_dehydra.so -o /dev/null -fplugin-arg-gcc_dehydra-=test_enum.js enum.cc
    Failure msg: Expected 'OK' output; got 'ERR  TestCase   TypeError: type.members is undefined'
Test Failure: 
    Test command: /home/bradh/devel/gcc-build/gcc/cc1 -quiet -O1 -ftest-coverage -fplugin=../gcc_dehydra.so -o /dev/null -fplugin-arg-gcc_dehydra-=test_bitfields.js bitfields.cc
    Failure msg: Expected 'OK' output; Errors:
 bitfields.cc:7:1: error: Must be 17 tests run, instead ran 0

Test Failure: 
    Test command: /home/bradh/devel/gcc-build/gcc/cc1 -quiet -O1 -ftest-coverage -fplugin=../gcc_dehydra.so -o /dev/null -fplugin-arg-gcc_dehydra-=test_parameters.js parameters.cc
    Failure msg: Expected 'OK' output; got 'ERR  TestCase   TypeError: this.decl.parameters[0] is undefined'
Test Failure: 
    Test command: /home/bradh/devel/gcc-build/gcc/cc1 -quiet -O1 -ftest-coverage -fplugin=../gcc_dehydra.so -o /dev/null -fplugin-arg-gcc_dehydra-=test_csttype.js csttype.cc
    Failure msg: Expected 'OK' output; Errors:
 csttype.cc:7:1: error: Must be 5 tests run, instead ran 0

Test Failure: 
    Test command: /home/bradh/devel/gcc-build/gcc/cc1 -quiet -O1 -ftest-coverage -fplugin=../gcc_dehydra.so -o /dev/null -fplugin-arg-gcc_dehydra-=test_strict.js onefunc.cc
    Failure msg: Expected 'OK' output; got empty stdout, stderr
Test Failure: 
    Test command: /home/bradh/devel/gcc-build/gcc/cc1 -quiet -O1 -ftest-coverage -fplugin=../gcc_dehydra.so -o /dev/null -fplugin-arg-gcc_dehydra-=test_diag_loc.js onefunc.cc
    Failure msg: Expected ':1:' in error output; not found. stderr:

Unit Test Suite Summary:
     51 passed
      9 failed
      0 error(s)
make[1]: *** [check_dehydra] Error 1
make[1]: Leaving directory `/home/bradh/devel/taras-stuff/dehydra-gcc/test'
make: *** [check] Error 2
Pushed Brad's testsuite changes + some hackery. http://hg.mozilla.org/rewriting-and-analysis/dehydra/rev/045722bf1282
Attachment #382478 - Flags: review?(tglek) → review+
Dehydra and treehydra are no longer maintained by Mozilla.
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → WONTFIX
Product: Core → Firefox Build System
Product: Firefox Build System → Developer Infrastructure
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: