diff options
author | Ian Lance Taylor <iant@google.com> | 2007-11-14 01:03:01 +0000 |
---|---|---|
committer | Ian Lance Taylor <iant@google.com> | 2007-11-14 01:03:01 +0000 |
commit | a55ce7febfaa52670ce3d9c236d3033de80ac091 (patch) | |
tree | 5955950569cfe09f083ba0e217a1a8085a844103 /gold/testsuite | |
parent | b3c8c50a8f21a913e6c5dc91ff843cd4e924b01a (diff) | |
download | gdb-a55ce7febfaa52670ce3d9c236d3033de80ac091.zip gdb-a55ce7febfaa52670ce3d9c236d3033de80ac091.tar.gz gdb-a55ce7febfaa52670ce3d9c236d3033de80ac091.tar.bz2 |
From Craig Silverstein: Rework debug info code a bit, add option for
ODR violations, add test case.
Diffstat (limited to 'gold/testsuite')
-rw-r--r-- | gold/testsuite/Makefile.am | 8 | ||||
-rw-r--r-- | gold/testsuite/Makefile.in | 8 | ||||
-rw-r--r-- | gold/testsuite/debug_msg.cc | 12 | ||||
-rwxr-xr-x | gold/testsuite/debug_msg.sh | 5 | ||||
-rw-r--r-- | gold/testsuite/odr_violation1.cc | 12 | ||||
-rw-r--r-- | gold/testsuite/odr_violation2.cc | 14 |
6 files changed, 55 insertions, 4 deletions
diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am index 4ac2e5c..e193fc5 100644 --- a/gold/testsuite/Makefile.am +++ b/gold/testsuite/Makefile.am @@ -118,8 +118,12 @@ if GCC debug_msg.o: debug_msg.cc $(CXXCOMPILE) -O0 -g -c -w -o $@ $(srcdir)/debug_msg.cc -debug_msg.err: debug_msg.o - if $(CXXLINK) -Bgcctestdir/ -o debug_msg debug_msg.o 2>$@; \ +odr_violation1.o: odr_violation1.cc + $(CXXCOMPILE) -O0 -g -c -w -o $@ $(srcdir)/odr_violation1.cc +odr_violation2.o: odr_violation2.cc + $(CXXCOMPILE) -O0 -g -c -w -o $@ $(srcdir)/odr_violation2.cc +debug_msg.err: debug_msg.o odr_violation1.o odr_violation2.o + if $(CXXLINK) -Bgcctestdir/ -Wl,--detect-odr-violations -o debug_msg debug_msg.o odr_violation1.o odr_violation2.o 2>$@; \ then \ echo 2>&1 "Link of debug_msg.o should have failed"; \ exit 1; \ diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in index 44214f1..dcbbf52 100644 --- a/gold/testsuite/Makefile.in +++ b/gold/testsuite/Makefile.in @@ -1206,8 +1206,12 @@ uninstall-am: uninstall-info-am @GCC_TRUE@debug_msg.o: debug_msg.cc @GCC_TRUE@ $(CXXCOMPILE) -O0 -g -c -w -o $@ $(srcdir)/debug_msg.cc -@GCC_TRUE@debug_msg.err: debug_msg.o -@GCC_TRUE@ if $(CXXLINK) -Bgcctestdir/ -o debug_msg debug_msg.o 2>$@; \ +@GCC_TRUE@odr_violation1.o: odr_violation1.cc +@GCC_TRUE@ $(CXXCOMPILE) -O0 -g -c -w -o $@ $(srcdir)/odr_violation1.cc +@GCC_TRUE@odr_violation2.o: odr_violation2.cc +@GCC_TRUE@ $(CXXCOMPILE) -O0 -g -c -w -o $@ $(srcdir)/odr_violation2.cc +@GCC_TRUE@debug_msg.err: debug_msg.o odr_violation1.o odr_violation2.o +@GCC_TRUE@ if $(CXXLINK) -Bgcctestdir/ -Wl,--detect-odr-violations -o debug_msg debug_msg.o odr_violation1.o odr_violation2.o 2>$@; \ @GCC_TRUE@ then \ @GCC_TRUE@ echo 2>&1 "Link of debug_msg.o should have failed"; \ @GCC_TRUE@ exit 1; \ diff --git a/gold/testsuite/debug_msg.cc b/gold/testsuite/debug_msg.cc index ab73a8d..45a0be6 100644 --- a/gold/testsuite/debug_msg.cc +++ b/gold/testsuite/debug_msg.cc @@ -55,6 +55,10 @@ class Derived : public Base virtual void virtfn() { undef_fn2(); } }; +// This tests One Definition Rule (ODR) violations. +void SortAscending(int array[], int size); // in odr_violation1.cc +void SortDescending(int array[], int size); // in odr_violation2.cc + int main() { testfn(5); @@ -63,5 +67,13 @@ int main() Base b; Derived d; + int kInput1[] = {1, 6, 9, 7, 3, 4, 2, 10, 5, 8}; + int kSize1 = sizeof(kInput1) / sizeof(int); + SortAscending(kInput1, kSize1); + + int kInput2[] = {1, 6, 9, 7, 3, 4, 2, 10, 5, 8}; + int kSize2 = sizeof(kInput2) / sizeof(int); + SortDescending(kInput2, kSize2); + return 0; } diff --git a/gold/testsuite/debug_msg.sh b/gold/testsuite/debug_msg.sh index 53e9d88..26c8ded 100755 --- a/gold/testsuite/debug_msg.sh +++ b/gold/testsuite/debug_msg.sh @@ -55,4 +55,9 @@ check "debug_msg.o: in function int testfn<double>(double):${srcdir}/debug_msg.c check "debug_msg.o: in function int testfn<double>(double):${srcdir}/debug_msg.cc:44: undefined reference to 'undef_fn2()'" check "debug_msg.o: in function int testfn<double>(double):${srcdir}/debug_msg.cc:45: undefined reference to 'undef_int'" +# Check we detected the ODR (One Definition Rule) violation. +check "warning: symbol Ordering::operator()(int, int) *defined in multiple places (possible ODR violation):" +check "odr_violation1.cc:5" +check "odr_violation2.cc:5" + exit 0 diff --git a/gold/testsuite/odr_violation1.cc b/gold/testsuite/odr_violation1.cc new file mode 100644 index 0000000..7f6f6d9 --- /dev/null +++ b/gold/testsuite/odr_violation1.cc @@ -0,0 +1,12 @@ +#include <algorithm> + +class Ordering { + public: + bool operator()(int a, int b) { + return a < b; + } +}; + +void SortAscending(int array[], int size) { + std::sort(array, array + size, Ordering()); +} diff --git a/gold/testsuite/odr_violation2.cc b/gold/testsuite/odr_violation2.cc new file mode 100644 index 0000000..d569279 --- /dev/null +++ b/gold/testsuite/odr_violation2.cc @@ -0,0 +1,14 @@ +#include <algorithm> + +class Ordering { + public: + bool operator()(int a, int b) { + // We need the "+ 1" here to force this operator() to be a + // different size than the one in odr_violation1.cc. + return a + 1 > b + 1; + } +}; + +void SortDescending(int array[], int size) { + std::sort(array, array + size, Ordering()); +} |