Fix pointer constraint in bn_mul.h

Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
diff --git a/library/bn_mul.h b/library/bn_mul.h
index c5994f7..0af7ecd 100644
--- a/library/bn_mul.h
+++ b/library/bn_mul.h
@@ -265,7 +265,10 @@
         "str x5, [%1], #8   \n\t"
 
 #define MULADDC_X1_STOP                                                 \
-         : "+r" (c),  "+r" (d), "+r" (s), "+m" (*(uint64_t (*)[16]) d)  \
+         : "+r" (c),                                                    \
+           "+" MBEDTLS_ASM_AARCH64_PTR_CONSTRAINT (d),                  \
+           "+" MBEDTLS_ASM_AARCH64_PTR_CONSTRAINT (s),                  \
+           "+m" (*(uint64_t (*)[16]) d)                                 \
          : "r" (b), "m" (*(const uint64_t (*)[16]) s)                   \
          : "x4", "x5", "x6", "x7", "cc"                                 \
     );
diff --git a/library/common.h b/library/common.h
index b48a1fc..4ee183a 100644
--- a/library/common.h
+++ b/library/common.h
@@ -169,6 +169,24 @@
 #endif
 /* *INDENT-ON* */
 
+/*
+ * Define the constraint used for pointer operands to asm.
+ *
+ * This is normally the usual "r", but for aarch64_32 (aka ILP32,
+ * as found in watchos), "p" is required to avoid warnings from clang.
+ */
+#if defined(__aarch64__) && defined(MBEDTLS_HAVE_ASM)
+#if UINTPTR_MAX == 0xfffffffful
+/* ILP32: Specify the pointer operand slightly differently, as per #7787. */
+#define MBEDTLS_ASM_AARCH64_PTR_CONSTRAINT "p"
+#elif UINTPTR_MAX == 0xfffffffffffffffful
+/* Normal case (64-bit pointers): use "r" as the constraint for pointer operands to asm */
+#define MBEDTLS_ASM_AARCH64_PTR_CONSTRAINT "r"
+#else
+#error Unrecognised pointer size for aarch64
+#endif
+#endif
+
 /* Always provide a static assert macro, so it can be used unconditionally.
  * It will expand to nothing on some systems.
  * Can be used outside functions (but don't add a trailing ';' in that case:
diff --git a/library/constant_time.c b/library/constant_time.c
index 5ed087c..c62ec13 100644
--- a/library/constant_time.c
+++ b/library/constant_time.c
@@ -83,13 +83,7 @@
 #if defined(__arm__) || defined(__thumb__) || defined(__thumb2__)
     asm volatile ("ldr %0, [%1]" : "=r" (r) : "r" (p) :);
 #elif defined(__aarch64__)
-#if (UINTPTR_MAX == 0xfffffffful)
-    /* ILP32: Specify the pointer operand slightly differently, as per #7787. */
-    asm volatile ("ldr %w0, [%1]" : "=r" (r) : "p" (p) :);
-#elif (UINTPTR_MAX == 0xffffffffffffffffull)
-    /* aarch64 with 64-bit pointers */
-    asm volatile ("ldr %w0, [%1]" : "=r" (r) : "r" (p) :);
-#endif
+    asm volatile ("ldr %w0, [%1]" : "=r" (r) : MBEDTLS_ASM_AARCH64_PTR_CONSTRAINT (p) :);
 #endif
     return r;
 }