@@ -694,7 +694,36 @@ def SuspiciousMemaccess : DiagGroup<"suspicious-memaccess",
694
694
NonTrivialMemaccess, MemsetTransposedArgs, SuspiciousBzero]>;
695
695
def StaticInInline : DiagGroup<"static-in-inline">;
696
696
def StaticLocalInInline : DiagGroup<"static-local-in-inline">;
697
- def UniqueObjectDuplication : DiagGroup<"unique-object-duplication">;
697
+ def UniqueObjectDuplication : DiagGroup<"unique-object-duplication"> {
698
+ code Documentation = [{
699
+ Warns when objects which are supposed to be globally unique might get duplicated
700
+ when built into a shared library.
701
+
702
+ If an object with hidden visibility is built into a shared library, each instance
703
+ of the library will get its own copy. This can cause very subtle bugs if there was
704
+ only supposed to be one copy of the object in question: singletons aren't single,
705
+ changes to one object won't affect the others, the object's initializer will run
706
+ once per copy, etc.
707
+
708
+ Specifically, this warning fires when it detects an object which:
709
+ 1. Appears in a header file (so it might get compiled into multiple libaries), and
710
+ 2. Has external linkage (otherwise it's supposed to be duplicated), and
711
+ 3. Has hidden visibility.
712
+
713
+ As well as one of the following:
714
+ 1. The object is mutable, or
715
+ 2. The object's initializer definitely has side effects.
716
+
717
+ The warning is best resolved by making the object ``const`` (if possible), or by explicitly
718
+ giving the object non-hidden visibility, e.g. using ``__attribute((visibility("default")))``.
719
+ Note that all levels of a pointer variable must be constant; ``const int*`` will
720
+ trigger the warning because the pointer itself is mutable.
721
+
722
+ This warning is currently disabled on Windows since it uses import/export rules
723
+ instead of visibility.
724
+ }];
725
+ }
726
+
698
727
def GNUStaticFloatInit : DiagGroup<"gnu-static-float-init">;
699
728
def StaticFloatInit : DiagGroup<"static-float-init", [GNUStaticFloatInit]>;
700
729
// Allow differentiation between GNU statement expressions in a macro versus
0 commit comments