[PATCH] Add function to get the number of DFSan labels allocated.

Peter Collingbourne peter at pcc.me.uk
Mon Mar 24 11:30:54 PDT 2014


  One approach that I've seen for maintaining multiple translation units in a single file is to control which translation unit is output using preprocessor macros. For example, you could have something like:

      // RUN: %clang_dfsan -DLIB -o lib.o this_file.cc && \
      // RUN: %clang_dfsan -o main.o this_file.cc && \
      // ...

      int add(int x, int y);

      #ifdef LIB
      int add(int x, int y) { definition here }
      #else
      int main() { main function definition here }
      #endif


================
Comment at: lib/dfsan/dfsan.cc:233
@@ -232,1 +232,3 @@
 
+extern "C" SANITIZER_INTERFACE_ATTRIBUTE int
+dfsan_get_label_count(void) {
----------------
Sam Kerner wrote:
> Peter Collingbourne wrote:
> > Is "int" the right return type for this function? I'd imagine it should be "dfsan_label", especially if we ever extend dfsan_label to 32 bits in the future.
> I initially avoided using dfsan_label as the return type because the fact that the label is an integer (of any specific size) is an implementation detail.  On the other hand, it is a detail that seems unlikely to change.
> 
> I created a new type dfsan_label_count_t .  I can't decide if it is a better choice than returning dfsan_label, so I will leave the choice to you.
> 
Yes, that is a good point. Can you make this function return a value of type size_t (external) / uptr (internal)?

================
Comment at: test/dfsan/lib/other_transactional_unit.h:1
@@ +1,2 @@
+// Functions used in tests which must be in a separate transactional unit.
+// This prevents the compiler from optimizing code in a way that removes
----------------
Nit: "translation unit" (here and elsewhere).


http://llvm-reviews.chandlerc.com/D3109



More information about the llvm-commits mailing list