Work around MSan false positives for Reactor routine parameters

Passing more than four parameters to a Reactor routine sporadically
causes a MemorySanitizer error. This happens even when passing in
constant values. Note that for the AMD64 calling convention, the first
four parameters are passed using registers, while the rest is passed on
the stack.

For function parameters, the 'shadow' memory which tracks which bits are
uninitialized is provided by the __msan_param_tls[] array, which is
thread-local. Calling __msan_unpoison_param() clears it.

This change effectively disables all MemorySanitizer checks for
parameters. While it suppresses the false positives (for which the root
cause is yet unknown), it allows for false negatives to occur. Thus this
change should be reverted once the bug has been fixed.

Bug: b/228253151
Change-Id: I68808ae9da37593cb751d9c61eaecb467a36f0ca
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/64789
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
diff --git a/src/Reactor/Routine.hpp b/src/Reactor/Routine.hpp
index 14fa116..f9994ab 100644
--- a/src/Reactor/Routine.hpp
+++ b/src/Reactor/Routine.hpp
@@ -15,6 +15,16 @@
 #ifndef rr_Routine_hpp
 #define rr_Routine_hpp
 
+// A Clang extension to determine compiler features.
+// We use it to detect Sanitizer builds (e.g. -fsanitize=memory).
+#ifndef __has_feature
+#	define __has_feature(x) 0
+#endif
+
+#if __has_feature(memory_sanitizer)
+#	include "sanitizer/msan_interface.h"
+#endif
+
 #include <memory>
 
 namespace rr {
@@ -57,6 +67,11 @@
 	template<typename... Args>
 	Return operator()(Args... args) const
 	{
+#if __has_feature(memory_sanitizer)
+		// TODO(b/228253151): Fix support for detecting uninitialized parameters.
+		__msan_unpoison_param(sizeof...(args));
+#endif
+
 		return function(args...);
 	}