Skip to contentSkip to conversation

sparse-llvm: avoid SIGSEGV for function prototypes

PATCH Superseded Azat Khuzhin 3 participants 9 messages May 16, 2015 – Jun 12, 2015 Sparse checker

lore
Share & tools
lore
#0 lore raw

cover sparse-llvm: avoid SIGSEGV for function prototypes

Description is in the first patch, and the second patch contains regression.

Thanks!

Azat Khuzhin (2):
sparse, llvm: compile: skip function prototypes to avoid SIGSEGV validation/prototype: regression for skipping prototypes

 sparse-llvm.c          | 11 +++++++++++
 validation/prototype.c |  6 ++++++
 2 files changed, 17 insertions(+)
 create mode 100644 validation/prototype.c
Signature · 1 line
2.1.4
#1 lore raw

PATCH 1/2 sparse, llvm: compile: skip function prototypes to avoid SIGSEGV

You can't pass function to LLVMConstNull(), according to Constant::getNullValue, and sparse-llvm already handle functions differently (i.e. there will be no call to LLVMConstNull(), but this is not true for function prototypes, because of how linearize_fn() works:

```
static struct entrypoint *linearize_fn(...)
{
  ...
  if (!base_type->stmt)
    return NULL;
  ...
}
```
```
Constant *Constant::getNullValue(Type *Ty) {
  switch (Ty->getTypeID()) {
  ...
  default:
    // Function, Label, or Opaque type?
    llvm_unreachable("Cannot create a null constant of that type!");
  }
}
```
---
 sparse-llvm.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
sparse-llvm.c +11 -0
index ecb5b28..6b41afd 100644
@@ -1070,6 +1070,13 @@ static LLVMValueRef output_data(LLVMModuleRef module, struct symbol *sym)
 	return data;
 }
 
+static int is_prototype(struct symbol *sym)
+{
+	if (sym->type == SYM_NODE)
+		sym = sym->ctype.base_type;
+	return sym && sym->type == SYM_FN && !sym->stmt;
+}
+
 static int compile(LLVMModuleRef module, struct symbol_list *list)
 {
 	struct symbol *sym;
@@ -1077,6 +1084,10 @@ static int compile(LLVMModuleRef module, struct symbol_list *list)
 	FOR_EACH_PTR(list, sym) {
 		struct entrypoint *ep;
 		expand_symbol(sym);
+
+		if (is_prototype(sym))
+			continue;
+
 		ep = linearize_symbol(sym);
 		if (ep)
 			output_fn(module, ep);
Signature · 1 line
2.1.4
maintainer
#2 lore raw

Re: [PATCH 1/2] sparse, llvm: compile: skip function prototypes to avoid SIGSEGV

Quoted 4 lines · Azat Khuzhin

You can't pass function to LLVMConstNull(), according to Constant::getNullValue, and sparse-llvm already handle functions differently (i.e. there will be no call to LLVMConstNull(), but this is not true for

The patch looks good. I am applying it. However I just notice that you did not provide the signed-off-by line.

Can you resend both patch with the signed off line?

Thanks

Chris

#3 lore raw

Re: [PATCH 1/2] sparse, llvm: compile: skip function prototypes to avoid SIGSEGV

Quoted 11 lines · Christopher Li
Quoted 4 lines · Azat Khuzhin

You can't pass function to LLVMConstNull(), according to Constant::getNullValue, and sparse-llvm already handle functions differently (i.e. there will be no call to LLVMConstNull(), but this is not true for

The patch looks good. I am applying it. However I just notice that you did not provide the signed-off-by line.

Can you resend both patch with the signed off line?

Sure, I'm doing this right now!

Thanks,
Azat.

#4 lore raw

PATCH 2/2 validation/prototype: regression for skipping prototypes

In reply to Azat Khuzhin
---
 validation/prototype.c | 6 ++++++
 1 file changed, 6 insertions(+)
 create mode 100644 validation/prototype.c
validation/prototype.c new file +6 -0
new file mode 100644
index 0000000..481cc93
@@ -0,0 +1,6 @@
+static int prototype(void);
+
+/*
+ * check-name: Compile skip function prototype
+ * check-command: ./sparsec -c $file -o tmp.o
+ */
Signature · 1 line
2.1.4
#5 lore raw

Re: [PATCH 2/2] validation/prototype: regression for skipping prototypes

Quoted 1 line

Subject: [PATCH 2/2] validation/prototype: regression for skipping prototypes

This is not a regression, but a regression test.

A regression means that previously working functionality breaks, and regression tests can detect regressions by testing that certain functionality still works.

Best regards,
Jonathan

#6 lore raw

Re: [PATCH 2/2] validation/prototype: regression for skipping prototypes

Quoted 3 lines · Jonathan Neuschäfer
Quoted 1 line

Subject: [PATCH 2/2] validation/prototype: regression for skipping prototypes

This is not a regression, but a regression test.

Yep, it is a regression test, thanks!
By some reason, I though that "validation" prefix will be enough. --
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#7 lore raw

PATCH v2 1/2 sparse, llvm: compile: skip function prototypes to avoid SIGSEGV

In reply to Azat Khuzhin

You can't pass function to LLVMConstNull(), according to Constant::getNullValue, and sparse-llvm already handle functions differently (i.e. there will be no call to LLVMConstNull(), but this is not true for function prototypes, because of how linearize_fn() works:

```
static struct entrypoint *linearize_fn(...)
{
  ...
  if (!base_type->stmt)
    return NULL;
  ...
}
```
```
Constant *Constant::getNullValue(Type *Ty) {
  switch (Ty->getTypeID()) {
  ...
  default:
    // Function, Label, or Opaque type?
    llvm_unreachable("Cannot create a null constant of that type!");
  }
}
```

---
v2: Add SOF.

 sparse-llvm.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
sparse-llvm.c +11 -0
index ecb5b28..6b41afd 100644
@@ -1070,6 +1070,13 @@ static LLVMValueRef output_data(LLVMModuleRef module, struct symbol *sym)
 	return data;
 }
 
+static int is_prototype(struct symbol *sym)
+{
+	if (sym->type == SYM_NODE)
+		sym = sym->ctype.base_type;
+	return sym && sym->type == SYM_FN && !sym->stmt;
+}
+
 static int compile(LLVMModuleRef module, struct symbol_list *list)
 {
 	struct symbol *sym;
@@ -1077,6 +1084,10 @@ static int compile(LLVMModuleRef module, struct symbol_list *list)
 	FOR_EACH_PTR(list, sym) {
 		struct entrypoint *ep;
 		expand_symbol(sym);
+
+		if (is_prototype(sym))
+			continue;
+
 		ep = linearize_symbol(sym);
 		if (ep)
 			output_fn(module, ep);
Signature · 1 line
2.1.4
#8 lore raw

PATCH v2 2/2 validation/prototype: regression for skipping prototypes

---
v2: Add SOF.

 validation/prototype.c | 6 ++++++
 1 file changed, 6 insertions(+)
 create mode 100644 validation/prototype.c
validation/prototype.c new file +6 -0
new file mode 100644
index 0000000..481cc93
@@ -0,0 +1,6 @@
+static int prototype(void);
+
+/*
+ * check-name: Compile skip function prototype
+ * check-command: ./sparsec -c $file -o tmp.o
+ */
Signature · 1 line
2.1.4