Closed Bug 1569681 Opened 5 years ago Closed 5 years ago

Add attributes to support static local classes

Categories

(Developer Infrastructure :: Source Code Analysis, task)

task
Not set
normal

Tracking

(firefox70 fixed)

RESOLVED FIXED
mozilla70
Tracking Status
firefox70 --- fixed

People

(Reporter: bugzilla, Assigned: bugzilla)

Details

Attachments

(3 files)

I've been talking to Nathan about adding a variant of Static{Auto,Ref}Ptr for use as static locals, taking advantage of C++11 "magic statics" such that we can lazily initialize those variables in a thread-safe way.

In support of those classes, I'd like to add two new attributes:

  • moz_static_local_class to ensure that any instantiations of that class only occur as static local variables;
  • moz_trivial_dtor to ensure that these classes do not implicitly call atexit and add a whole bunch of shutdown crap.

This patch is in support of adding a variant of Static{Auto,Ref}Ptr for use as
static locals, taking advantage of C++11 "magic statics" such that we can lazily
initialize those variables in a thread-safe way.

In support of those classes, this patch adds two new attributes:

  • moz_static_local_class to ensure that any instantiations of that class only
    occur as static local variables;
  • moz_trivial_dtor to ensure that these classes do not implicitly call atexit
    and add a whole bunch of shutdown crap.

moz_static_local_class works similarly to moz_global_class, except that its
object must only instantiate as static locals.

TrivialDtorChecker is based on TrivialCtorDtorChecker, with the ctor-specific
bits removed.

These tests are based on moz_global_class and moz_trivial_ctor_dtor tests,
respectively, but adapted for the semantics of the new attributes.

Depends on D39717

I did not add a separate macro for MOZ_TRIVIAL_DTOR as I could not really
think of a use case for it. Let me know if you prefer that I add it as a
distinct macro.

Depends on D39718

Pushed by aklotz@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/21ea6fea046e
Part 1 - Add support for moz_static_local_class and moz_trivial_dtor to clang-plugin; r=Ehsan
https://hg.mozilla.org/integration/autoland/rev/2c543b239808
Part 2 - Add new clang-plugin tests for moz_static_local_class and moz_trivial_destructor attributes; r=Ehsan
https://hg.mozilla.org/integration/autoland/rev/075b818a46fe
Part 3 - Update mfbt/Attributes.h with new MOZ_STATIC_LOCAL_CLASS macro; r=Ehsan

Backed out 3 changesets for causing build bustages.

Backout link: https://hg.mozilla.org/integration/autoland/rev/cc011478e0d0a618ea29d7fda2ef8e9427c14a86

Push with failures: https://treeherder.mozilla.org/#/jobs?repo=autoland&resultStatus=testfailed%2Cbusted%2Cexception&revision=075b818a46fe76181c3f78a9817707230a53bf54&selectedJob=258857826

Failure logs:

[task 2019-07-29T19:51:44.493Z] 19:51:44 INFO - /builds/worker/workspace/build/src/sccache/sccache /builds/worker/workspace/build/src/clang/bin/clang++ -o TestStaticLocalClass.o -c -DNDEBUG=1 -DTRIMMED=1 -I/builds/worker/workspace/build/src/build/clang-plugin/tests -I/builds/worker/workspace/build/src/obj-firefox/build/clang-plugin/tests -I/builds/worker/workspace/build/src/obj-firefox/dist/include -I/builds/worker/workspace/build/src/obj-firefox/dist/include/nspr -I/builds/worker/workspace/build/src/obj-firefox/dist/include/nss -fPIC -DMOZILLA_CLIENT -include /builds/worker/workspace/build/src/obj-firefox/mozilla-config.h -Qunused-arguments -U_FORTIFY_SOURCE -fno-common -Qunused-arguments -D_GLIBCXX_USE_CXX11_ABI=0 -fno-sized-deallocation -fsanitize=bool,bounds,vla-bound -fno-sanitize-recover=bool,bounds,vla-bound -fsanitize-blacklist=/builds/worker/workspace/build/src/obj-firefox/ubsan_blacklist.txt -fsanitize=address -fcrash-diagnostics-dir=/builds/worker/artifacts -U_FORTIFY_SOURCE -fno-common -fno-exceptions -fno-strict-aliasing -fno-rtti -ffunction-sections -fdata-sections -fno-exceptions -fno-math-errno -pthread -pipe -fsyntax-only -Xclang -verify -ferror-limit=0 -Wno-invalid-noreturn -g -Xclang -load -Xclang /builds/worker/workspace/build/src/obj-firefox/build/clang-plugin/libclang-plugin.so -Xclang -add-plugin -Xclang moz-check -O2 -gline-tables-only -fno-omit-frame-pointer -funwind-tables -Werror -MD -MP -MF .deps/TestStaticLocalClass.o.pp /builds/worker/workspace/build/src/build/clang-plugin/tests/TestStaticLocalClass.cpp
[task 2019-07-29T19:51:44.493Z] 19:51:44 INFO - error: 'note' diagnostics expected but not seen:
[task 2019-07-29T19:51:44.493Z] 19:51:44 INFO - File /builds/worker/workspace/build/src/build/clang-plugin/tests/TestStaticLocalClass.cpp Line 19: 'StaticLocal [2]' is a static local type because it is an array of static local type 'StaticLocal'
[task 2019-07-29T19:51:44.494Z] 19:51:44 INFO - File /builds/worker/workspace/build/src/build/clang-plugin/tests/TestStaticLocalClass.cpp Line 39: 'RandomClass' is a static local type because member 'nonstaticMember' is a static local type 'StaticLocal'
[task 2019-07-29T19:51:44.494Z] 19:51:44 INFO - File /builds/worker/workspace/build/src/build/clang-plugin/tests/TestStaticLocalClass.cpp Line 48: 'BadInherit' is a static local type because it inherits from a static local type 'StaticLocal'
[task 2019-07-29T19:51:44.494Z] 19:51:44 INFO - error: 'note' diagnostics seen but not expected:
[task 2019-07-29T19:51:44.494Z] 19:51:44 INFO - File /builds/worker/workspace/build/src/build/clang-plugin/tests/TestStaticLocalClass.cpp Line 19: 'StaticLocal [2]' is a static-local type because it is an array of static-local type 'StaticLocal'
[task 2019-07-29T19:51:44.495Z] 19:51:44 INFO - File /builds/worker/workspace/build/src/build/clang-plugin/tests/TestStaticLocalClass.cpp Line 48: 'BadInherit' is a static-local type because it inherits from a static-local type 'StaticLocal'
[task 2019-07-29T19:51:44.495Z] 19:51:44 INFO - File /builds/worker/workspace/build/src/build/clang-plugin/tests/TestStaticLocalClass.cpp Line 39: 'RandomClass' is a static-local type because member 'nonstaticMember' is a static-local type 'StaticLocal'
[task 2019-07-29T19:51:44.495Z] 19:51:44 INFO - 6 errors generated.
[task 2019-07-29T19:51:44.495Z] 19:51:44 INFO - /builds/worker/workspace/build/src/config/rules.mk:786: recipe for target 'TestStaticLocalClass.o' failed
[task 2019-07-29T19:51:44.495Z] 19:51:44 ERROR - make[4]: *** [TestStaticLocalClass.o] Error 1
[task 2019-07-29T19:51:44.495Z] 19:51:44 INFO - make[4]: Leaving directory '/builds/worker/workspace/build/src/obj-firefox/build/clang-plugin/tests'
[task 2019-07-29T19:51:44.495Z] 19:51:44 INFO - make[4]: *** Waiting for unfinished jobs....

Flags: needinfo?(aklotz)

Doh. Forgot to update the tests when I addressed the nit in part 1.

Flags: needinfo?(aklotz)
Pushed by aklotz@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/be9e5f8f00d0
Part 1 - Add support for moz_static_local_class and moz_trivial_dtor to clang-plugin; r=Ehsan
https://hg.mozilla.org/integration/autoland/rev/4d0a7b968eb0
Part 2 - Add new clang-plugin tests for moz_static_local_class and moz_trivial_destructor attributes; r=Ehsan
https://hg.mozilla.org/integration/autoland/rev/292cc6853e82
Part 3 - Update mfbt/Attributes.h with new MOZ_STATIC_LOCAL_CLASS macro; r=Ehsan

Backed out 3 changesets for causing build bustages.

Backout link: https://hg.mozilla.org/integration/autoland/rev/c9f70b17e09affb7d2d28e31e6ea7427d1618905

Push with failures: https://treeherder.mozilla.org/#/jobs?repo=autoland&resultStatus=testfailed%2Cbusted%2Cexception&revision=292cc6853e82d36232784d0d46409370d42da528

Failure log: https://treeherder.mozilla.org/logviewer.html#/jobs?job_id=258863023&repo=autoland&lineNumber=4559

[task 2019-07-29T20:19:50.819Z] 20:19:50 INFO - File /builds/worker/workspace/build/src/build/clang-plugin/tests/TestTrivialDtor.cpp Line 46: class 'BadNonTrivialDtorInMember' must have a trivial destructor
[task 2019-07-29T20:19:50.820Z] 20:19:50 INFO - 5 errors generated.
[task 2019-07-29T20:19:50.820Z] 20:19:50 INFO - /builds/worker/workspace/build/src/config/rules.mk:786: recipe for target 'TestTrivialDtor.o' failed
[task 2019-07-29T20:19:50.820Z] 20:19:50 ERROR - make[4]: *** [TestTrivialDtor.o] Error 1
[task 2019-07-29T20:19:50.820Z] 20:19:50 INFO - make[4]: Leaving directory '/builds/worker/workspace/build/src/obj-firefox/build/clang-plugin/tests'
[task 2019-07-29T20:19:50.820Z] 20:19:50 INFO - make[4]: *** Waiting for unfinished jobs....
[task 2019-07-29T20:19:50.820Z] 20:19:50 INFO - make[4]: Entering directory '/builds/worker/workspace/build/src/obj-firefox/build/clang-plugin/tests'
[task 2019-07-29T20:19:50.821Z] 20:19:50 INFO - /builds/worker/workspace/build/src/sccache/sccache /builds/worker/workspace/build/src/clang/bin/clang++ -o TestStaticLocalClass.o -c -DNDEBUG=1 -DTRIMMED=1 -I/builds/worker/workspace/build/src/build/clang-plugin/tests -I/builds/worker/workspace/build/src/obj-firefox/build/clang-plugin/tests -I/builds/worker/workspace/build/src/obj-firefox/dist/include -I/builds/worker/workspace/build/src/obj-firefox/dist/include/nspr -I/builds/worker/workspace/build/src/obj-firefox/dist/include/nss -fPIC -DMOZILLA_CLIENT -include /builds/worker/workspace/build/src/obj-firefox/mozilla-config.h -Qunused-arguments -U_FORTIFY_SOURCE -fno-common -Qunused-arguments -D_GLIBCXX_USE_CXX11_ABI=0 -fno-sized-deallocation -fsanitize=bool,bounds,vla-bound -fno-sanitize-recover=bool,bounds,vla-bound -fsanitize-blacklist=/builds/worker/workspace/build/src/obj-firefox/ubsan_blacklist.txt -fsanitize=address -fcrash-diagnostics-dir=/builds/worker/artifacts -U_FORTIFY_SOURCE -fno-common -fno-exceptions -fno-strict-aliasing -fno-rtti -ffunction-sections -fdata-sections -fno-exceptions -fno-math-errno -pthread -pipe -fsyntax-only -Xclang -verify -ferror-limit=0 -Wno-invalid-noreturn -g -Xclang -load -Xclang /builds/worker/workspace/build/src/obj-firefox/build/clang-plugin/libclang-plugin.so -Xclang -add-plugin -Xclang moz-check -O2 -gline-tables-only -fno-omit-frame-pointer -funwind-tables -Werror -MD -MP -MF .deps/TestStaticLocalClass.o.pp /builds/worker/workspace/build/src/build/clang-plugin/tests/TestStaticLocalClass.cpp
[task 2019-07-29T20:19:50.821Z] 20:19:50 INFO - error: 'error' diagnostics expected but not seen:
[task 2019-07-29T20:19:50.821Z] 20:19:50 INFO - File /builds/worker/workspace/build/src/build/clang-plugin/tests/TestStaticLocalClass.cpp Line 18: variable of type 'StaticLocal' is only valid as a static-local
[task 2019-07-29T20:19:50.822Z] 20:19:50 INFO - File /builds/worker/workspace/build/src/build/clang-plugin/tests/TestStaticLocalClass.cpp Line 19: variable of type 'StaticLocal [2]' is only valid as a static-local
[task 2019-07-29T20:19:50.822Z] 20:19:50 INFO - File /builds/worker/workspace/build/src/build/clang-plugin/tests/TestStaticLocalClass.cpp Line 27: variable of type 'StaticLocal' is only valid as a static-local
[task 2019-07-29T20:19:50.822Z] 20:19:50 INFO - File /builds/worker/workspace/build/src/build/clang-plugin/tests/TestStaticLocalClass.cpp Line 28: variable of type 'StaticLocal' is only valid as a static-local
[task 2019-07-29T20:19:50.822Z] 20:19:50 INFO - File /builds/worker/workspace/build/src/build/clang-plugin/tests/TestStaticLocalClass.cpp Line 29: variable of type 'TemplateClass<int>' is only valid as a static-local

Flags: needinfo?(aklotz)
Pushed by aklotz@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/44c35b8ac3df
Part 1 - Add support for moz_static_local_class and moz_trivial_dtor to clang-plugin; r=Ehsan
https://hg.mozilla.org/integration/autoland/rev/7778a85e7ff0
Part 2 - Add new clang-plugin tests for moz_static_local_class and moz_trivial_destructor attributes; r=Ehsan
https://hg.mozilla.org/integration/autoland/rev/d32d8c2b9710
Part 3 - Update mfbt/Attributes.h with new MOZ_STATIC_LOCAL_CLASS macro; r=Ehsan
Flags: needinfo?(aklotz)
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: