diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index c90de65de12..d8fb25aaf71 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -14303,6 +14303,22 @@ initialize_aarch64_code_model (struct gcc_options *opts)
      }
    else
      aarch64_cmodel = opts->x_aarch64_cmodel_var;
+
+   if (opts->x_aarch64_abi == TARGET_ILP32)
+     {
+       switch (opts->x_aarch64_cmodel_var)
+	 {
+	 case AARCH64_CMODEL_TINY:
+	   break;
+	 case AARCH64_CMODEL_SMALL:
+	   break;
+	 case AARCH64_CMODEL_LARGE:
+	   sorry ("code model large not supported in ilp32 mode");
+	   break;
+	 default:
+	   gcc_unreachable ();
+	 }
+     }
 }
 
 /* Implement TARGET_OPTION_SAVE.  */
diff --git a/gcc/testsuite/gcc.target/aarch64/pr94577.c b/gcc/testsuite/gcc.target/aarch64/pr94577.c
new file mode 100644
index 00000000000..6be489cecb1
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/pr94577.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-mcmodel=large -mabi=ilp32" } */
+
+void
+foo ()
+{
+  // Do nothing
+}
+
+/* { dg-message "sorry, unimplemented: code model large not supported in ilp32 mode"  "" { target *-*-* } 0 } */
