linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Azat Khuzhin <a3at.mail@gmail.com>
To: Sparse ML <linux-sparse@vger.kernel.org>
Cc: Azat Khuzhin <a3at.mail@gmail.com>
Subject: [PATCH 1/2] sparse, llvm: compile: skip function prototypes to avoid SIGSEGV
Date: Sun, 17 May 2015 01:32:24 +0300	[thread overview]
Message-ID: <1431815545-21250-2-git-send-email-a3at.mail@gmail.com> (raw)
In-Reply-To: <1431815545-21250-1-git-send-email-a3at.mail@gmail.com>

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(+)

diff --git a/sparse-llvm.c b/sparse-llvm.c
index ecb5b28..6b41afd 100644
--- a/sparse-llvm.c
+++ b/sparse-llvm.c
@@ -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);
-- 
2.1.4


  reply	other threads:[~2015-05-16 22:32 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-16 22:32 [PATCH 0/2] sparse-llvm: avoid SIGSEGV for function prototypes Azat Khuzhin
2015-05-16 22:32 ` Azat Khuzhin [this message]
2015-06-12  0:50   ` [PATCH 1/2] sparse, llvm: compile: skip function prototypes to avoid SIGSEGV Christopher Li
2015-06-12  5:18     ` Azat Khuzhin
2015-05-16 22:32 ` [PATCH 2/2] validation/prototype: regression for skipping prototypes Azat Khuzhin
2015-05-17 18:40   ` Jonathan Neuschäfer
2015-05-17 18:53     ` Azat Khuzhin
2015-06-12  5:20 ` [PATCH 1/2 v2] sparse, llvm: compile: skip function prototypes to avoid SIGSEGV Azat Khuzhin
2015-06-12  5:20   ` [PATCH 2/2 v2] validation/prototype: regression for skipping prototypes Azat Khuzhin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1431815545-21250-2-git-send-email-a3at.mail@gmail.com \
    --to=a3at.mail@gmail.com \
    --cc=linux-sparse@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).