diff --git a/src/builtin_functions.c b/src/builtin_functions.c
index 24d1751a93e747f4e3379297cb82999dfe2f91d5..3cdc997c0c8319b66d85d0a16f55485e2f444f75 100644
--- a/src/builtin_functions.c
+++ b/src/builtin_functions.c
@@ -4516,7 +4516,11 @@ node *optimize_replace(node *n)
      */
     node **arg1 = my_get_arg(&_CDR(n), 1);
     node **arg2 = my_get_arg(&_CDR(n), 2);
-    struct program *replace_compiler = NULL;
+
+    /* This variable is modified in between setjmp and longjmp,
+     * so it needs to be volatile to prevent it from being globbered.
+     */
+    struct program * volatile replace_compiler = NULL;
 
     if (arg1 && ((pike_types_le((*arg1)->type, array_type_string) &&
 		  arg2 &&
diff --git a/src/program.c b/src/program.c
index c73878f86e1e18ff652fe7c55c011fa8ce7de13e..7c3e36ed464bfcba47a4d123b510afb673339b46 100644
--- a/src/program.c
+++ b/src/program.c
@@ -1781,8 +1781,11 @@ int low_find_shared_string_identifier(struct pike_string *name,
 
 static struct node_s *index_modules(struct pike_string *ident,
 				    struct mapping **module_index_cache,
-				    int num_used_modules,
+				    const int num_used_modules,
 				    struct svalue *modules)
+  /* num_used_modules is declared const here to convince the compiler that it is not
+   * modified in between setjmp() and longjmp(). This prevents -Wglobbered warnings.
+   */
 {
   if(*module_index_cache)
   {