Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc835c7f

Browse files
committed
llvmjit: Work around bug in LLVM 3.9 causing crashes after7255943.
Unfortunately in LLVM 3.9 LLVMGetAttributeCountAtIndex(func, index)crashes when called with an index that has 0 attributes. Since there'sno way to work around this in the C API, add a small C++ wrapper doingso.The only reason this didn't fail before7255943 is that therealways are function attributes...Author: Andres Freund <andres@anarazel.de>Discussion:https://postgr.es/m/20201016001254.w2nfj7gd74jmb5in@alap3.anarazel.deBackpatch: 11-, like7255943
1 parent0ab7ca9 commitc835c7f

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

‎src/backend/jit/llvm/llvmjit.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,14 @@ llvm_copy_attributes_at_index(LLVMValueRef v_from, LLVMValueRef v_to, uint32 ind
339339
intnum_attributes;
340340
LLVMAttributeRef*attrs;
341341

342-
num_attributes=LLVMGetAttributeCountAtIndex(v_from,index);
342+
num_attributes=LLVMGetAttributeCountAtIndexPG(v_from,index);
343+
344+
/*
345+
* Not just for efficiency: LLVM <= 3.9 crashes when
346+
* LLVMGetAttributesAtIndex() is called for an index with 0 attributes.
347+
*/
348+
if (num_attributes==0)
349+
return;
343350

344351
attrs=palloc(sizeof(LLVMAttributeRef)*num_attributes);
345352
LLVMGetAttributesAtIndex(v_from,index,attrs);

‎src/backend/jit/llvm/llvmjit_wrap.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ extern "C"
1616
#include"postgres.h"
1717
}
1818

19+
#include<llvm-c/Core.h>
20+
21+
/* Avoid macro clash with LLVM's C++ headers*/
22+
#undef Min
23+
24+
#include<llvm/IR/Attributes.h>
25+
#include<llvm/IR/Function.h>
1926
#include<llvm/MC/SubtargetFeature.h>
2027
#include<llvm/Support/Host.h>
2128

@@ -44,3 +51,28 @@ char *LLVMGetHostCPUFeatures(void) {
4451
returnstrdup(Features.getString().c_str());
4552
}
4653
#endif
54+
55+
/*
56+
* Like LLVM's LLVMGetAttributeCountAtIndex(), works around a bug in LLVM 3.9.
57+
*
58+
* In LLVM <= 3.9, LLVMGetAttributeCountAtIndex() segfaults if there are no
59+
* attributes at an index (fixed in LLVM commit ce9bb1097dc2).
60+
*/
61+
unsigned
62+
LLVMGetAttributeCountAtIndexPG(LLVMValueRef F, uint32 Idx)
63+
{
64+
/*
65+
* This is more expensive, so only do when using a problematic LLVM
66+
* version.
67+
*/
68+
#if LLVM_VERSION_MAJOR < 4
69+
if (!llvm::unwrap<llvm::Function>(F)->getAttributes().hasAttributes(Idx))
70+
return0;
71+
#endif
72+
73+
/*
74+
* There is no nice public API to determine the count nicely, so just
75+
* always fall back to LLVM's C API.
76+
*/
77+
returnLLVMGetAttributeCountAtIndex(F, Idx);
78+
}

‎src/include/jit/llvmjit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ extern char *LLVMGetHostCPUName(void);
138138
externchar*LLVMGetHostCPUFeatures(void);
139139
#endif
140140

141+
externunsignedLLVMGetAttributeCountAtIndexPG(LLVMValueRefF,uint32Idx);
142+
141143
#ifdef__cplusplus
142144
}/* extern "C" */
143145
#endif

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp