Browse Source

Restrict `#no_capture` to pointer-like types only

gingerBill 1 year ago
parent
commit
3533094cc2
2 changed files with 4 additions and 6 deletions
  1. 1 5
      src/check_type.cpp
  2. 3 1
      src/llvm_backend_proc.cpp

+ 1 - 5
src/check_type.cpp

@@ -2071,13 +2071,9 @@ gb_internal Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_para
 					} else {
 					} else {
 						if (is_type_internally_pointer_like(type)) {
 						if (is_type_internally_pointer_like(type)) {
 							// okay
 							// okay
-						} else if (is_type_slice(type) || is_type_string(type)) {
-							// okay
-						} else if (is_type_dynamic_array(type)) {
-							// okay
 						} else {
 						} else {
 							ERROR_BLOCK();
 							ERROR_BLOCK();
-							error(name, "'#no_capture' can only be applied to pointer-like types, slices, strings, and dynamic arrays");
+							error(name, "'#no_capture' can only be applied to pointer-like types");
 							error_line("\t'#no_capture' does not currently do anything useful\n");
 							error_line("\t'#no_capture' does not currently do anything useful\n");
 							p->flags &= ~FieldFlag_no_capture;
 							p->flags &= ~FieldFlag_no_capture;
 						}
 						}

+ 3 - 1
src/llvm_backend_proc.cpp

@@ -254,7 +254,9 @@ gb_internal lbProcedure *lb_create_procedure(lbModule *m, Entity *entity, bool i
 				lb_add_proc_attribute_at_index(p, offset+parameter_index, "noalias");
 				lb_add_proc_attribute_at_index(p, offset+parameter_index, "noalias");
 			}
 			}
 			if (e->flags&EntityFlag_NoCapture) {
 			if (e->flags&EntityFlag_NoCapture) {
-				lb_add_proc_attribute_at_index(p, offset+parameter_index, "nocapture");
+				if (is_type_internally_pointer_like(e->type)) {
+					lb_add_proc_attribute_at_index(p, offset+parameter_index, "nocapture");
+				}
 			}
 			}
 			parameter_index += 1;
 			parameter_index += 1;
 		}
 		}