[Bug rtl-optimization/85745] variable with asm register assignment allocated in wrong reg

2018-05-14 Thread bernd.edlinger at hotmail dot de
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85745

--- Comment #3 from Bernd Edlinger  ---
just in case someone runs into the same issue, this would
be the linux patch that Jakub suggested:

commit 20dfb4d2eb648bd947adbb729d963f78df75ffee
Author: Bernd Edlinger 
Date:   Fri May 11 18:51:03 2018 +0200

Fix compilation with gcc-8

diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
index 74b17d0..dc64fa2 100644
--- a/arch/arm/include/asm/uaccess.h
+++ b/arch/arm/include/asm/uaccess.h
@@ -220,7 +220,7 @@ extern int __put_user_8(void *, unsigned long long);
({  \
unsigned long __limit = current_thread_info()->addr_limit - 1;
\
const typeof(*(p)) __user *__tmp_p = (p);   \
-   register const typeof(*(p)) __r2 asm("r2") = (x);   \
+   register typeof(*(p)) __r2 asm("r2") = (x); \
register const typeof(*(p)) __user *__p asm("r0") = __tmp_p; \
register unsigned long __l asm("r1") = __limit; \
register int __e asm("r0"); \

[Bug rtl-optimization/85745] variable with asm register assignment allocated in wrong reg

2018-05-11 Thread bernd.edlinger at hotmail dot de
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85745

Bernd Edlinger  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |INVALID

--- Comment #2 from Bernd Edlinger  ---
Removing const fixes the build for me.
Thanks for investigating!

[Bug rtl-optimization/85745] variable with asm register assignment allocated in wrong reg

2018-05-11 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85745

Jakub Jelinek  changed:

   What|Removed |Added

 CC||jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek  ---
The reason this happens is that the register variable is marked const.  Don't
do that.  If it is const, the compiler optimizes it more aggressively - it will
happily fold uses of the variable to the constant ininitializer, so the inline
asm becomes "r" (110) instead of "r" (__r2) and thus it can use any register.
This is how C++ behaved for years and how C in GCC behaves since the folding
improvements.
--- gcc/c/c-fold.c  2018-05-10 19:39:13.750529734 +0200
+++ gcc/c/c-fold.c  2018-05-11 17:57:12.941957170 +0200
@@ -165,7 +165,10 @@ c_fully_fold_internal (tree expr, bool i
   if (!IS_EXPR_CODE_CLASS (kind) || kind == tcc_statement)
 {
   /* Except for variables which we can optimize to its initializer.  */
-  if (VAR_P (expr) && !lval && (optimize || in_init))
+  if (VAR_P (expr)
+ && !lval
+ && (optimize || in_init)
+ && !DECL_HARD_REGISTER (expr))
{
  if (in_init)
ret = decl_constant_value_1 (expr, true);
would be a workaround for this, but not really sure if we want to use it.